From kromag@nsacom.net  Tue May  1 00:06:53 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Mon, 30 Apr 2001 16:06:53 -0700 (PDT)
Subject: [Tutor] Breaking threads
Message-ID: <200104302306.f3UN6r802577@pop.nsacom.net>

Howdy,

I am working my way through "Programming Python" from the begining (I have 
asked too many silly questions! :-). Here is a non-silly question:

When I run the following:

----------begin stuff------------------------------

import thread, time 

glarf=open('\windows\desktop\goat.txt', 'w')

def counter(myId, count):
    for i in range(count):
	mutex.acquire()
#	time.sleep(1)
	glarf.write('[%s]=> %s' % (myId, i))
	mutex.release()
		
mutex = thread.allocate_lock()
for i in range(10000):
	thread.start_new_thread(counter, (i, 3))
	
time.sleep(6)
print "Your greasy granny's got holes in her panties. And your main thread is 
exiting...."

--------end stuff---------------

It starts to write 10,000 counts to goat.txt, then dies with the following:


Traceback (most recent call last):
  File "cornfedbeef.py", line 14, in ?
    thread.start_new_thread(counter, (i, 3))
thread.error: can't start new thread

It works fine in iterations of 10, 100 and 1000. Why does it puke at the 
10000 mark?


Wow!

d



From arcege@speakeasy.net  Tue May  1 00:23:34 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Mon, 30 Apr 2001 19:23:34 -0400 (EDT)
Subject: [Tutor] Displaying image in scrolled canvas
In-Reply-To: <200104301740.f3UHec821609@pop.nsacom.net> from "kromag@nsacom.net" at Apr 30, 2001 10:40:38 AM
Message-ID: <200104302323.f3UNNYf11155@dsl092-074-184.bos1.dsl.speakeasy.net>

kromag@nsacom.net wrote
> 
> I am attempting to place a large .gif file into a scrolled canvas. I am 
> working from the examples in programming python (in case the code looked 
> slightly familiar :-)
> 
> To wit:

Try these changes :

> from Tkinter import * 
> class ScrolledCanvas(Frame):
>     def __init__(self, parent=None, color='white'):
>         Frame.__init__(self, parent)
>         self.pack(expand=YES, fill=BOTH)                  
>         photo=PhotoImage(file='\windows\desktop\wacky3.gif')
          self.photo=PhotoImage(file='\\window\\desktop\\wacky3.gif')

>         canv = Canvas(self, bg=color, relief=SUNKEN)
>         canv.config(width=1010, height=745)                
>         canv.config(scrollregion=(0,0,300, 1000))         
>         canv.create_image(10,10, image=photo, anchor=NW)
          canv.create_image(10,10, image=self.photo, anchor=NW)

>         sbar = Scrollbar(self)
>         sbar.config(command=canv.yview)                   
>         canv.config(yscrollcommand=sbar.set)              
>         sbar.pack(side=RIGHT, fill=Y)                     
>         canv.pack(side=LEFT, expand=YES, fill=BOTH)      
> if __name__ == '__main__': ScrolledCanvas().mainloop()
> 
> results in the properly-sized frame and scrollbar, but for some reason the 
> image does not pop to life. What am I missing here?

Image objects in Tkinter need to have the reference kept.  Because of a
interaction between Tk and Tkinter, when the actual object is destroyed
the Tk image is destroyed as well.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From julieta_rangel@hotmail.com  Tue May  1 00:47:53 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Mon, 30 Apr 2001 18:47:53 -0500
Subject: [Tutor] deciphering code
Message-ID: <F246beUzmRf6Ci6nx8d0000a3ad@hotmail.com>

Can anyone help me decipher the following code?  I know it is to create a 
polynomial and calculate its derivative, but I would like to know what the 
lines do, in other words, figure out the purpose for those lines.

import string
class Poly:
    def __init__ ( self, v = 'x', c = [0]):
        """__init__():
        Initializes a polynomial
        Default variable is x
        Default polynomial is zero"""
        self.var = v
        self.coef = c
        self.deg = len(c)-1
    def __str__ (self):
        """__str__():
        Converts a polynomial into a string"""
        x = `self.coef[0]`
        for i in range (1, self.deg+1):
            x = x + " + " + `self.coef[i]` + self.var + "^" + `i`
        return x

def Derivative(p):
    """Input: an instance of a polynomial
    Output: a polynomial that is the derivative of the input polynomial
    Side Effects: None"""
    pv=p.var
    pc=[]
    if p.deg==0:
        return Poly (v=pv,c=[0])
    else:
        for i in range(0,p.deg):
            d=(i+1)*p.coef[i+1]
            pc.append(d)
        return Poly (v=pv,c=pc)
****************************************************************
  I'll appreciate any kind of help.  Also, what modifications should I make 
to this code so that a user can input a polynomial and the computer 
calculates the derivative and displays the answer?

Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From julieta_rangel@hotmail.com  Tue May  1 01:02:40 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Mon, 30 Apr 2001 19:02:40 -0500
Subject: [Tutor] creating a matrix of unknown dimensions(dimensions depend on input)
Message-ID: <F109vKRNZSPGNkY5Tet0000d8fa@hotmail.com>

Right now I'm trying to come up with a program that given a set of elements 
(at most 30), the computer will determine whether the set is a group or not. 
  (for a set to be a group, the set must be closed under the binary 
operation in use; the elements of the set must be associative, that is 
a*(b*c) = (a*b)*c; the set must contain an identity element e such that for 
any element a on the set, a*e = e*a = a
and finally, every element on the set must contain an inverse such that 
a*a^-1 = e).  To do this I want the computer to offer the user a table set 
up, so that the user can enter the table.  Here is where the matrix comes 
into place.  Since I don't know how many elements the set being tested will 
have, I need to make sure the computer asks the user how many elements the 
set has, so that the computer can create the matrix, which must be filled 
out by the user.  All the computer has to do know is to check the table 
(matrix) for all the properties to determine whether the set is a group or 
not.  Does this sound too confusing, anyway, at this point I'm maninly 
interested on how to create an n x n matrix based on any given input (up to 
30elements)

Again, any kind of help you can offer will be truly appreciated.

Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From julieta_rangel@hotmail.com  Tue May  1 01:43:38 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Mon, 30 Apr 2001 19:43:38 -0500
Subject: [Tutor] Having Python figure out whether a set is a group
Message-ID: <F308esqN0zYE3SADezu0000a534@hotmail.com>

Given the following table, how can I make the computer verify whether the 
following set is a group or not?  The set is G = {e,a,b,ab)
The table under the binary operation * with the elements of the set looks 
like:

         *_|     e    a    b    ab
         ---------------------------
          e|     e    a    b    ab
          a|     a    e    ab   b
          b|     b    ab   e    a
         ab|     ab   b    a    e

The computer would have to check the 4 properties of groups (closure, 
associativity, identity element, and inverse element).  By the way, the set 
G is in fact a group. It is closed under the binary operation (a * b = ab, 
and ab is in G, b * ab =a and a is in G, etc), it is associative (a * (b * 
ab) = (a * b) * ab; e * (a * b) = (e * a) * b, etc), it has an identity 
element e (a * e = a, b * e = b, ab * e = ab, e * e = e), and every element 
is an inverse of itself (Note: a*a = e, b*b = e, ab*ab = e, and e*e = e).How 
could the computer check for closure?  I'm assuming the computer would have 
to go through the elements in the table and compare them with the original 
set.  How could this be done?  This problem requires some thinking.  Does 
anyone want to help or do you know where I can go for help?

Julieta

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From arcege@speakeasy.net  Tue May  1 02:16:05 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Mon, 30 Apr 2001 21:16:05 -0400 (EDT)
Subject: [Tutor] creating a matrix of unknown dimensions(dimensions depend on input)
In-Reply-To: <F109vKRNZSPGNkY5Tet0000d8fa@hotmail.com> from "Julieta Rangel" at Apr 30, 2001 07:02:40 PM
Message-ID: <200105010116.f411G5A16411@dsl092-074-184.bos1.dsl.speakeasy.net>

Julieta Rangel wrote
> 
> Right now I'm trying to come up with a program that given a set of elements 
> (at most 30), the computer will determine whether the set is a group or not. 
>   (for a set to be a group, the set must be closed under the binary 
> operation in use; the elements of the set must be associative, that is 
> a*(b*c) = (a*b)*c; the set must contain an identity element e such that for 
> any element a on the set, a*e = e*a = a
> and finally, every element on the set must contain an inverse such that 
> a*a^-1 = e).  To do this I want the computer to offer the user a table set 
> up, so that the user can enter the table.  Here is where the matrix comes 
> into place.  Since I don't know how many elements the set being tested will 
> have, I need to make sure the computer asks the user how many elements the 
> set has, so that the computer can create the matrix, which must be filled 
> out by the user.  All the computer has to do know is to check the table 
> (matrix) for all the properties to determine whether the set is a group or 
> not.  Does this sound too confusing, anyway, at this point I'm maninly 
> interested on how to create an n x n matrix based on any given input (up to 
> 30elements)
> 
> Again, any kind of help you can offer will be truly appreciated.

If you are just looking for a generic matrix object, then how about:

class Matrix:
  def __init__(self, rows, cols):
    self.rows = rows
    self.cols = cols
    self.table = [0] * (rows * cols)
  def _getindex(self, x, y):
    return x + (self.rows * y)
  def __str__(self):
    s = '[ '
    for j in range(self.cols):
      base_column = self.rows * j
      s = s + '[' + str(self.table[base_column])
      for i in range(1, self.rows):
        s = s + ' ' + str(self.table[base_column + i])
      s = s + '] '
    return s + ']'
  def __getitem__(self, (x, y)):
    # make sure that we aren't going beyond our bounds
    if not (0 <= x < self.rows) or not (0 <= y < self.cols):
      raise IndexError((x, y))
    return self.table[self._getindex(x, y)]
  def __setitem__(self, (x, y), value):
    # make sure that we aren't going beyond our bounds
    if not (0 <= x < self.rows) or not (0 <= y < self.cols):
      raise IndexError((x, y))
    self.table[self._getindex(x, y)] = value

while 1:
  try:
    (x, y) = input('Enter the dimensions of the matrix (r, c): ')
  except:
    pass
  else:
    break
m = Matrix(x, y)
for j in range(m.cols):
  for i in range(m.rows):
    m[i, j] = i + j
print m

More can be added to the class, but it gives you what you seem to be
asking for.

If you are looking into more complicated mathematics, then I suggest
looking into NumPy (Numeric Python) which has a lot of built-in
constructs, algorithms and mechanisms.

You might also want to look at the numerous math related modules in
the Vaults of Parnassus (<URL: http://www.vex.net/parnassus/>).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From dyoo@hkn.eecs.berkeley.edu  Tue May  1 02:30:34 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 30 Apr 2001 18:30:34 -0700 (PDT)
Subject: [Tutor] creating a matrix of unknown dimensions(dimensions depend
 on input)
In-Reply-To: <F109vKRNZSPGNkY5Tet0000d8fa@hotmail.com>
Message-ID: <Pine.LNX.4.21.0104301813540.3768-100000@hkn.eecs.berkeley.edu>

On Mon, 30 Apr 2001, Julieta Rangel wrote:

> Right now I'm trying to come up with a program that given a set of elements 
> (at most 30), the computer will determine whether the set is a group or not. 

> a*a^-1 = e).  To do this I want the computer to offer the user a table set 
> up, so that the user can enter the table.  Here is where the matrix comes 
> into place.  Since I don't know how many elements the set being tested will 
> have, I need to make sure the computer asks the user how many elements the 
> set has, so that the computer can create the matrix, which must be filled 
> out by the user.  All the computer has to do know is to check the table 
> (matrix) for all the properties to determine whether the set is a group or 
> not.  Does this sound too confusing, anyway, at this point I'm maninly 

No, this makes sense; so you're making a program that makes it easy to
enter in the table that tells us how the operator works on a pair of the
group elements.  This sounds reasonable.


> interested on how to create an n x n matrix based on any given input (up to 
> 30elements)
> 
> Again, any kind of help you can offer will be truly appreciated.

There are a couple of ways to go about this.  One way that you might like
is the "dictionary" approach.  It sounds like we're trying to write
something that maps 2-tuples (2 elements) to some element.  Whenever
we're storing a "mapping", we're thinking of a Python dictionary:

###
>>> mytable = {}               ## Initially, an empty dictionary
>>> mytable[0, 0] = 42         ## Filling in an entry
>>> mytable[0, 0]              ## Looking up an entry
42
###

(For those who are curious, we're depending on Python's implicit knowledge
that by saying "0, 0", we actually mean the tuple "(0, 0)".)

This is even nicer than a two-dimensional array, because there isn't any
fixed size to the dictionary; you don't even need to preallocate the
dimensions.  Just start plugging your table values in.


Another operation that dictionaries support is telling us which entries we
filled in.  We do this by asking a dictionary what keys() it has:

###
>>> mytable.keys()
[(0, 0)]
>>> mytable[0, 1] = 3.1415
>>> mytable[1, 0] = 2.718
>>> mytable[1, 1] = 1.61
>>> mytable.keys()
[(0, 1), (0, 0), (1, 0), (1, 1)]
###

Another really useful thing we can ask a dictionary is a list of it's
items():

###
>>> mytable.items()
[((0, 1), 3.1415), ((0, 0), 42), ((1, 0), 2.718), ((1, 1), 1.61)]
###


Dictionaries are a very good data structure; there's some more information
on them here:

http://www.python.org/doc/current/tut/node7.html#SECTION007400000000000000000


Hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Tue May  1 02:42:25 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 30 Apr 2001 18:42:25 -0700 (PDT)
Subject: [Tutor] Having Python figure out whether a set is a group
In-Reply-To: <F308esqN0zYE3SADezu0000a534@hotmail.com>
Message-ID: <Pine.LNX.4.21.0104301831180.3768-100000@hkn.eecs.berkeley.edu>

On Mon, 30 Apr 2001, Julieta Rangel wrote:

> Given the following table, how can I make the computer verify whether the 
> following set is a group or not?  The set is G = {e,a,b,ab)
> The table under the binary operation * with the elements of the set looks 
> like:
> 
>          *_|     e    a    b    ab
>          ---------------------------
>           e|     e    a    b    ab
>           a|     a    e    ab   b
>           b|     b    ab   e    a
>          ab|     ab   b    a    e
> 
> The computer would have to check the 4 properties of groups (closure, 
> associativity, identity element, and inverse element).  By the way, the set 
> G is in fact a group. It is closed under the binary operation (a * b = ab, 
> and ab is in G, b * ab =a and a is in G, etc), it is associative (a * (b * 
> ab) = (a * b) * ab; e * (a * b) = (e * a) * b, etc), it has an identity 
> element e (a * e = a, b * e = b, ab * e = ab, e * e = e), and every element 
> is an inverse of itself (Note: a*a = e, b*b = e, ab*ab = e, and e*e = e).How 
> could the computer check for closure?  I'm assuming the computer would have 
> to go through the elements in the table and compare them with the original 
> set.  How could this be done?  This problem requires some thinking.  Does 
> anyone want to help or do you know where I can go for help?

Let's assume that we have this table all set up, and that it's fairly easy
to look up a table element if we're given the row and column.

What do we need to check closure, in the mathematical sense?  We need to
see that, for every pair of elements (a, b) in our table, that the entry
in there is within our set G.  If any of these table elements aren't in G,
then there no point to check the rest: we don't have closure.  Otherwise,
the group must be closed.

The pseudocode for this sounds like:

###
a definition for closure of the set G:
    for all the (row, column) pairs in our binary-operator table:
        if the element at (row, column) is not in our set G:
            let's report that this G isn't a group
    if we haven't reported failure, then all the table elements are good,
    so let's report success
###

The Python code that corresponds to this isn't that much different.  How
far have you gotten though Alan Gauld's tutorial?

    http://www.crosswinds.net/~agauld/

The parts that will help you express these ideas are under the topics of
"Sequences" and "Branching".


Good luck to you.



From dyoo@hkn.eecs.berkeley.edu  Tue May  1 03:12:35 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 30 Apr 2001 19:12:35 -0700 (PDT)
Subject: [Tutor] deciphering code
In-Reply-To: <F246beUzmRf6Ci6nx8d0000a3ad@hotmail.com>
Message-ID: <Pine.LNX.4.21.0104301842460.3768-100000@hkn.eecs.berkeley.edu>

On Mon, 30 Apr 2001, Julieta Rangel wrote:

> Can anyone help me decipher the following code?  I know it is to create a 
> polynomial and calculate its derivative, but I would like to know what the 
> lines do, in other words, figure out the purpose for those lines.

Ok, no problem.  [warning: this is long, and in some excruciating detail.  
You asked for it.  *grin*]


> import string

This is called an import statement.  What it says is that we need some of
the functionality that a module called "string" provides us.  Many of the
functions that Python provides have been off-loaded into packaged modules,
just to keep things clean and managable for us.  When we find that we need
these functions, we can "import" them, and then use them.

Once we import string, we can use the functions described here:

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

There's a somewhat overwhelming list of modules here:

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

but you don't need to know about all of them.  The most useful ones, I've
found, are:

    sys     --- working with system resources
    string  --- string manipulation
    re      --- more complicated and powerful string manipulation

but that's just because I do a lot of string manipulation.  As you learn
Python, you'll start to get familiar with the modules that you reach for.



> class Poly:

We're defining a class, a description that tells Python what we mean when
we say "Poly".  The rest of these lines explain the operations that
polynomials can do.  For example:

>     def __init__ ( self, v = 'x', c = [0]):

corresponds to initializing a new Poly, and

>     def __str__ (self):

tells Python what to do if we ever want to "print" a Poly to the user.  
("str" stands for "string"ing).  The double underscores are part of the
name.



###

Let's look at one of the definitions in a Poly:

>     def __init__ ( self, v = 'x', c = [0]):
>         """__init__():
>         Initializes a polynomial
>         Default variable is x
>         Default polynomial is zero"""
>         self.var = v
>         self.coef = c
>         self.deg = len(c)-1

The first line:

>     def __init__ ( self, v = 'x', c = [0]):

says that when we're trying to make a Poly, we're given the option of
feeding in a 'v' ("variable"), and "c" (coefficient list).  The programmer
has chosen to give "defaults" to these variables: if the user doesn't tell
us what the variable name or the coefficents are, then it will choose "x"
and [0] by default.

The next couple of lines:

>         """__init__():
>         Initializes a polynomial
>         Default variable is x
>         Default polynomial is zero"""

are just a description of what the procedure does: it's meant for people
to read.  This is called a documentation string, or more tersely, a
"docstring".  Docstrings are optional when we're defining a function.


>         self.var = v
>         self.coef = c
>         self.deg = len(c)-1

In order for a polynomial to keep an identity that's distinct from other
Poly's, it needs to know what variable, coefficient, and degree it
contains.  These assignment lines store this information into it"self".


Later on, we can lookup this information by asking for "self.var" or
"self.coef", and in fact, we do so in the next definition:

>     def __str__ (self):
>         """__str__():
>         Converts a polynomial into a string"""
>         x = `self.coef[0]`
>         for i in range (1, self.deg+1):
>             x = x + " + " + `self.coef[i]` + self.var + "^" + `i`
>         return x

When we're defining __str__, we're telling Python what a "string"
representation of a Polynomial would be.  Without this function, Python
has no idea what it should print out.  Let's look at a few of the lines:

>         x = `self.coef[0]`

This says: "Let's define the name 'x' to have the string representation of
self.coef[0]."  self.coef, as we remember, was the coefficient list, so
self.coef[0] is looking up the first element in the list.  Those
backquotes are intentional: they tell Python that we want a string, not
just a number.

Python keeps track of the "type" of something: like mathematics, it's a
label that helps us know what kind of operations are valid, and how these
operations work.  For example:

###
>>> 5 + 4
9
>>> "5" + "4"
'54' 
###

return different values because the "addition" operation really does
depend on what we're working with.  Let's look at a few more lines:

>         for i in range (1, self.deg+1):
>             x = x + " + " + `self.coef[i]` + self.var + "^" + `i`

What this says is that we'd like to look at every element within the
range[1, self.deg+1].  That is, for each element within such a list, we'll
be doing whatever's in the "body" of this loop.  Here's the body:

>             x = x + " + " + `self.coef[i]` + self.var + "^" + `i`

Within the body, 'i' will take the value of the elements within range(1,
self.deg+1).  The idea is that as we're going through the loop, we slowly
build up a string that represents what the polynomial looks like.

Here's an example of using for loops:

###
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
>>> for x in range(0, 10):
...     print x, x**2, x**3
...
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
###

range() itself is a utility function that can build lists of consecutive
integers conveniently.


The last line:

>         return x

says that the return value --- what we want the function to give back ---
should be this string x.


Whew!



From sheila@thinkspot.net  Tue May  1 04:58:16 2001
From: sheila@thinkspot.net (Sheila King)
Date: Mon, 30 Apr 2001 20:58:16 -0700
Subject: [Tutor] Having Python figure out whether a set is a group
In-Reply-To: <F308esqN0zYE3SADezu0000a534@hotmail.com>
References: <F308esqN0zYE3SADezu0000a534@hotmail.com>
Message-ID: <332C878579E@kserver.org>

On Mon, 30 Apr 2001 19:43:38 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com>  wrote about [Tutor] Having Python figure out
whether a set is a group:

:Given the following table, how can I make the computer verify whether the 
:following set is a group or not?  The set is G = {e,a,b,ab)
:The table under the binary operation * with the elements of the set looks 
:like:
:
:         *_|     e    a    b    ab
:         ---------------------------
:          e|     e    a    b    ab
:          a|     a    e    ab   b
:          b|     b    ab   e    a
:         ab|     ab   b    a    e
:
:The computer would have to check the 4 properties of groups (closure, 
:associativity, identity element, and inverse element).  By the way, the set 
:G is in fact a group. It is closed under the binary operation (a * b = ab, 
:and ab is in G, b * ab =a and a is in G, etc), it is associative (a * (b * 
:ab) = (a * b) * ab; e * (a * b) = (e * a) * b, etc), it has an identity 
:element e (a * e = a, b * e = b, ab * e = ab, e * e = e), and every element 
:is an inverse of itself (Note: a*a = e, b*b = e, ab*ab = e, and e*e = e).How 
:could the computer check for closure?  I'm assuming the computer would have 
:to go through the elements in the table and compare them with the original 
:set.  How could this be done?  This problem requires some thinking.  Does 
:anyone want to help or do you know where I can go for help?

How about storing your table as a dictionary? Here is a partial idea:

>>> e='e'
>>> a='a'
>>> b='b'
>>> ab='ab'
>>> table ={}
>>> table[(e,e)]=e
>>> table[(e,a)]=a
>>> table[(e,b)]=b
>>> print table
{('e', 'e'): 'e', ('e', 'b'): 'b', ('e', 'a'): 'a'}
>>> 

To check for closure, have a list of the set values. I constructed a list from
the table (after I finished entering all the values for the table) as follows:

>>> set = []
>>> for elt in table.keys():
... 	if elt[0] not in set:
... 		set.append(elt[0])
... 		
>>> print set
['a', 'ab', 'b', 'e']
>>> 

Now, to check for closure, just test to see whether each item in
tables.values() is in the set. If not, then it is not closed.

To check for associativity, for example,
find the value of (a,b) and then take that value (which we know is ab) and
cross it with another element (let's say, e) and see if (ab, e) is equivalent
to
a crossed with the result of (b, e)

To test for an identity element, you could check whether there is an item in
the set, where (item, whatever) == whatever, for each whatever in the set, and
also check whether (whatever, item) == whatever.

And, to check for inverses...once you've confirmed the existence of an
identity element, check for each element in the set, whether there is a pair
such that (element, something) == identity element.

Actually, I think I really like this idea of storing the table off as a
dictionary. The table really is a function (mathematically speaking), which is
a mapping, which is what a dictionary represents.

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



From julieta_rangel@hotmail.com  Tue May  1 05:52:08 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Mon, 30 Apr 2001 23:52:08 -0500
Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI
Message-ID: <F1580sca0ZkfzDskqC50000d887@hotmail.com>

Thanks for your suggestions.  I have a question.  Is it possible to have the 
user enter the table's contents in GUI format; that is, set up a really nice 
table in which the user can move freely up and down and across and enter the 
table's contents, and at the same time store all of the table's input into a 
dictionary like you suggested?


>From: Sheila King <sheila@thinkspot.net>
>To: "Julieta Rangel" <julieta_rangel@hotmail.com>
>CC: tutor@python.org
>Subject: Re: [Tutor] Having Python figure out whether a set is a group
>Date: Mon, 30 Apr 2001 20:58:16 -0700
>
>On Mon, 30 Apr 2001 19:43:38 -0500, "Julieta Rangel"
><julieta_rangel@hotmail.com>  wrote about [Tutor] Having Python figure out
>whether a set is a group:
>
>:Given the following table, how can I make the computer verify whether the
>:following set is a group or not?  The set is G = {e,a,b,ab)
>:The table under the binary operation * with the elements of the set looks
>:like:
>:
>:         *_|     e    a    b    ab
>:         ---------------------------
>:          e|     e    a    b    ab
>:          a|     a    e    ab   b
>:          b|     b    ab   e    a
>:         ab|     ab   b    a    e
>:
>:The computer would have to check the 4 properties of groups (closure,
>:associativity, identity element, and inverse element).  By the way, the 
>set
>:G is in fact a group. It is closed under the binary operation (a * b = ab,
>:and ab is in G, b * ab =a and a is in G, etc), it is associative (a * (b *
>:ab) = (a * b) * ab; e * (a * b) = (e * a) * b, etc), it has an identity
>:element e (a * e = a, b * e = b, ab * e = ab, e * e = e), and every 
>element
>:is an inverse of itself (Note: a*a = e, b*b = e, ab*ab = e, and e*e = 
>e).How
>:could the computer check for closure?  I'm assuming the computer would 
>have
>:to go through the elements in the table and compare them with the original
>:set.  How could this be done?  This problem requires some thinking.  Does
>:anyone want to help or do you know where I can go for help?
>
>How about storing your table as a dictionary? Here is a partial idea:
>
> >>> e='e'
> >>> a='a'
> >>> b='b'
> >>> ab='ab'
> >>> table ={}
> >>> table[(e,e)]=e
> >>> table[(e,a)]=a
> >>> table[(e,b)]=b
> >>> print table
>{('e', 'e'): 'e', ('e', 'b'): 'b', ('e', 'a'): 'a'}
> >>>
>
>To check for closure, have a list of the set values. I constructed a list 
>from
>the table (after I finished entering all the values for the table) as 
>follows:
>
> >>> set = []
> >>> for elt in table.keys():
>... 	if elt[0] not in set:
>... 		set.append(elt[0])
>...
> >>> print set
>['a', 'ab', 'b', 'e']
> >>>
>
>Now, to check for closure, just test to see whether each item in
>tables.values() is in the set. If not, then it is not closed.
>
>To check for associativity, for example,
>find the value of (a,b) and then take that value (which we know is ab) and
>cross it with another element (let's say, e) and see if (ab, e) is 
>equivalent
>to
>a crossed with the result of (b, e)
>
>To test for an identity element, you could check whether there is an item 
>in
>the set, where (item, whatever) == whatever, for each whatever in the set, 
>and
>also check whether (whatever, item) == whatever.
>
>And, to check for inverses...once you've confirmed the existence of an
>identity element, check for each element in the set, whether there is a 
>pair
>such that (element, something) == identity element.
>
>Actually, I think I really like this idea of storing the table off as a
>dictionary. The table really is a function (mathematically speaking), which 
>is
>a mapping, which is what a dictionary represents.
>
>--
>Sheila King
>http://www.thinkspot.net/sheila/
>http://www.k12groups.org/
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From sheila@thinkspot.net  Tue May  1 05:54:38 2001
From: sheila@thinkspot.net (Sheila King)
Date: Mon, 30 Apr 2001 21:54:38 -0700
Subject: [Tutor] Having Python figure out whether a set is a group
In-Reply-To: <332C878579E@kserver.org>
References: <F308esqN0zYE3SADezu0000a534@hotmail.com> <332C878579E@kserver.org>
Message-ID: <35DBF741486@kserver.org>

On Mon, 30 Apr 2001 20:58:16 -0700, Sheila King <sheila@thinkspot.net>  wrote
about Re: [Tutor] Having Python figure out whether a set is a group:

:To check for associativity, for example,
:find the value of (a,b) and then take that value (which we know is ab) and
:cross it with another element (let's say, e) and see if (ab, e) is equivalent
:to
:a crossed with the result of (b, e)

I was thinking about this a bit more.
I guess you could do this:

if ( table[(table[(a,b)],e)] == table[(a, table[(b,e)])] ):
    whatever happens if associativity holds

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



From sheila@thinkspot.net  Tue May  1 05:58:24 2001
From: sheila@thinkspot.net (Sheila King)
Date: Mon, 30 Apr 2001 21:58:24 -0700
Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI
In-Reply-To: <F1580sca0ZkfzDskqC50000d887@hotmail.com>
References: <F1580sca0ZkfzDskqC50000d887@hotmail.com>
Message-ID: <36144533ABE@kserver.org>

On Mon, 30 Apr 2001 23:52:08 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com>  wrote about Re: [Tutor]-Python figuring out
groups--setting up a table in GUI:

:Thanks for your suggestions.  I have a question.  Is it possible to have the 
:user enter the table's contents in GUI format; that is, set up a really nice 
:table in which the user can move freely up and down and across and enter the 
:table's contents, and at the same time store all of the table's input into a 
:dictionary like you suggested?

Yes, but I would learn how to do it at the command line first and move on to
GUI programming after a bit. (I don't even know GUI programming yet, really,
and I've been teaching programming for a couple of years now--C++. I mean, I
could do Visual Basic or C++ Builder, but there isn't anything like that,
quite yet, for Python.)

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



From sale_profil@gmx.co.uk  Tue May  1 09:09:21 2001
From: sale_profil@gmx.co.uk (Sergey)
Date: Tue, 1 May 2001 01:09:21 -0700 (PDT)
Subject: [Tutor] PROFIL DLA GKL
Message-ID: <200105010809.f4189La75476@addr21.addr.com>

PEhUTUw+PEhFQUQ+PFRJVExFPjwvVElUTEU+PC9IRUFEPjxCT0RZPjxQUkU+DQrP8O706Ov8
IOTr/yDDyssuICAgPGEgaHJlZj0iaHR0cDovL3Byb2ZpbHkuYWRkci5jb20iPmh0dHA6Ly9w
cm9maWx5LmFkZHIuY29tPC9hPg0KDQrP8OXk6+Dj4P4g8e4g8err4OTgIOIgzO7x6uLlICju
8uPw8+fq4CDq7u3y5ent5fDgLCDk7vHy4OLq4CDgL/IpOg0KCQkJCQkJDQrP8O706Ov8IM/R
LTIgKDUw9TUwIOzsKQkJNDgg7C7vLu/g9+rgCTE0LDAwIPDz4S/sLu8uDQrP8O706Ov8IM/N
LTIgKDUw9TQwIOzsKQkJNDgg7C7vLu/g9+rgCTExLDYwIPDz4S/sLu8uDQrP8O706Ov8IM/R
LTQgKDc19TUwIOzsKSAJMzYg7C7vLu/g9+rgCTE2LDQwIPDz4S/sLu8uDQrP8O706Ov8IM/N
LTQgKDc19TQwIOzsKSAJMzYg7C7vLu/g9+rgCTE0LDMwIPDz4S/sLu8uDQrP8O706Ov8IM/P
ICggNjD1Mjfs7CkgCQk0OCDsLu8u7+D36uAJMTAsODAg8PPhL+wu7y4NCs/w7vTo6/wgz80g
KDI49TI3IOzsKQkJODQg7C7vLu/g9+rgCTcsNjAgIPDz4S/sLu8uDQrT4+7r7uog5+D56PLt
++kg7+Xw9C4JCTMwIOwu7y7v4Pfq4Ak2LDQwICDw8+Ev7C7vLiANCg0KzvLk5evq4C4NCsrw
4PHq4CD04PHg5O3g/yDr4PLl6vHt4P8gKyDq7uvl8O7i4O3o5Swg4/Dz7fLu4urgIODq8Ojr
7uLg/yANClRpZWZncnVkIExGIEQxNCwg4u7k7uTo8e/l8PHo7u3t++Ug6vDg8eroIOTr/yDi
7fPy8OXt7ej1IPDg4e7yIA0KKyDq7uvl8O7i4O3o5Swg6uvl6CDk6/8g7+vo8uroLCDx8ujw
7u/u8OAuDQoozu/y7uL75SDx6ujk6uggKyDk6Ovl8PHq6Okg5O7j7uLu8CDxIO/w7ujn4u7k
6PLl6+XsKQ0KDQrU4O3l8OAg0O7x8ejp8eru4+4g7/Du6Ofi7uTx8uLgICju7/IgKyDw7uft
6PbgKS4NCg0Kyujx8ugg7ODr//Dt++Ug7/Du9OXx8eju7eDr/O375SDoIOH78u7i++UgKPLu
6/zq7iDu7/Lu7CAtIO3o5uUg9uXtIO3l8iEpDQoNCs/u5PDu5+Xy7ejqICj96+Xq8vDu8/Hy
4O3u4u737eD/IOru8O7h6uApIA0K5Ov/IOHl8u7t4Cwg5Ov/IOPo7/Hu6uDw8u7t4CAyLzMg
8PPhLi/48i4NCg0K8uXrLiAwOTUgOTcwLTA4LTc4DQoNCjwvUFJFPjwvYm9keT48L2h0bWw+
DQoNCg==


From wheelege@tsn.cc  Tue May  1 10:12:18 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Tue, 1 May 2001 19:12:18 +1000
Subject: [Tutor] Program not accessing while loops
References: <OE433mPqsoWGaaDi3dQ00004c17@hotmail.com>
Message-ID: <010301c0d21e$d3308c80$0200a8c0@ACE>

This is a multi-part message in MIME format.

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

<snip snip snip>
    mainmen =3D raw_input(">")
    while mainmen =3D=3D 1:
<snip snip snip>

  Your getting a string here, and not an integer.  So, 'while mainmen =
=3D=3D 1' will never, ever be true.  Ever.
  So, what you want is to convert it to an integer...with something like =
:-

  mainmen =3D int(raw_input(">"))

  To account for something other than an integer, and to make sure it =
doesn't crash when the user writes something like 'go away!', wrap it in =
a try-except block.

  try:
      mainmen =3D int(raw_input(">"))
  except:
      print 'Please enter an integer'

  Hope that helped,
  Glen.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&lt;snip snip snip&gt;<BR><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;=20
mainmen =3D raw_input("&gt;")<BR>&nbsp;&nbsp;&nbsp; while mainmen =3D=3D =

1:</FONT><BR>&lt;snip snip snip&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Your getting a string here, and not an integer.&nbsp; So, =
'while=20
mainmen =3D=3D 1' will never, ever be true.&nbsp; Ever.</DIV>
<DIV>&nbsp; So, what you want is to convert it to an integer...with =
something=20
like :-</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; mainmen =3D int(raw_input("&gt;"))</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; To account for something other than an integer, and to make =
sure it=20
doesn't crash when the user writes something like 'go away!', wrap it in =
a=20
try-except block.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; try:</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mainmen =3D =
int(raw_input("&gt;"))</DIV>
<DIV>&nbsp;&nbsp;except:</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Please enter an =
integer'</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Hope that helped,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_0100_01C0D272.A3F1A040--



From alan.gauld@bt.com  Tue May  1 10:06:11 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 1 May 2001 10:06:11 +0100
Subject: [Tutor] deciphering code
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D72C@mbtlipnt02.btlabs.bt.co.uk>

> Can anyone help me decipher the following code?  

Nope, not me - too lazy!
But it seems that several of your questions are answered
(in Scheme) in the book "Structure and Interpretation of 
Computer Programs" by Abelman and Sussman(s). It might 
be useful to find a copy (in a local college library maybe?)

Specifically chapter two covers symbolic algebra including 
addition, multiplication and derivation of polynomials...

Alan G.


From alan.gauld@bt.com  Tue May  1 10:30:07 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 1 May 2001 10:30:07 +0100
Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table
 in GUI
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D72F@mbtlipnt02.btlabs.bt.co.uk>

> I mean, I could do Visual Basic or C++ Builder, but there isn't 
> anything like that, quite yet, for Python.)

We're not too far off:

Glade - for GTk?
Blackadder - for Qt?
SpecTcl (with SpecPython addin) - for Tkinter(*)

I think I've seen a wxPython one somewhere too?
And Kdeveloper might handle Python too - I can't remember...

They don't have all the bells and whistles of VB or Delphi 
yet but they do all build a GUI visually.

Alan G

(*)SpecTcl is no longer supported so the Tkinter code
it generates uses a depricated style of widget configuration 
- but it's very easy to convert, in fact If I was lazy &
determined enough I'd write a script :-)


From alan.gauld@bt.com  Tue May  1 10:36:09 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 1 May 2001 10:36:09 +0100
Subject: [Tutor] Program not accessing while loops
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D730@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C0D222.26EA8A80
Content-type: text/plain; charset="iso-8859-1"

keep running and asking for input, but it won't call on the loop.
 
    mainmen = raw_input(">")
    while mainmen == 1:
 

raw_input returns a string, you are testing for a number. 
You need to convert mainmen to an int:
 
mainmen= int(mainmen)
 
OR you need to test for a string:
 
while mainmen n== "1"
 
BUT do you really want a while loop here?
It will loop forever printing 
 

         print "This function is under construction"

Surely an if statement would be sufficient?
 
Specifically an if/elif set:
 
if mainmenu == 1: print...
elif mainmenu == 2: print...
elif mainmenu == 3: 
   # do the exit stuff here
 
just a thought,
 
Alan G.

------_=_NextPart_001_01C0D222.26EA8A80
Content-type: text/html; charset="iso-8859-1"

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


<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><FONT face=Arial size=2>keep running and asking for input, but it won't 
  call on the loop.</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; mainmen = 
  raw_input("&gt;")<BR>&nbsp;&nbsp;&nbsp; while mainmen == 1:<BR><SPAN 
  class=970153809-01052001><FONT 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=970153809-01052001>raw_input returns a string, you are testing for a 
number. </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>You 
need to convert mainmen to an int:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=970153809-01052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=970153809-01052001>mainmen= int(mainmen)</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=970153809-01052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>OR you 
need to test for a string:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=970153809-01052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>while 
mainmen n== "1"</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=970153809-01052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>BUT do 
you really want a while loop here?</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=970153809-01052001>It 
will loop forever printing </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=970153809-01052001></SPAN></FONT>&nbsp;</DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><FONT size=2><FONT face=Arial><SPAN 
  class=970153809-01052001>&nbsp;</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  print "This function is under construction"</FONT></FONT></DIV></BLOCKQUOTE>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001>Surely an if statement would be 
sufficient?</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001>Specifically an if/elif set:</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001>if mainmenu == 1: print...</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001>elif mainmenu == 2: print...</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001>elif mainmenu == 3: </SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001>&nbsp;&nbsp; # do the exit stuff 
here</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001>just a thought,</SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2><FONT color=#0000ff face=Arial><SPAN 
class=970153809-01052001>Alan G.</SPAN></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C0D222.26EA8A80--


From sheila@thinkspot.net  Tue May  1 12:30:31 2001
From: sheila@thinkspot.net (Sheila King)
Date: Tue, 01 May 2001 04:30:31 -0700
Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D72F@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D72F@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <4C506775CBB@kserver.org>

On Tue, 1 May 2001 10:30:07 +0100, alan.gauld@bt.com  wrote about RE: [Tutor]
Re: [Tutor]-Python figuring out groups--setting up a table in GUI:

:> I mean, I could do Visual Basic or C++ Builder, but there isn't 
:> anything like that, quite yet, for Python.)
:
:We're not too far off:

That's why I said "quite yet". My understanding, is that they are all
alpha/beta quality. I wouldn't recommend them to a newbie who's just starting
out learning GUI. They would have a devil of a time figuring out what were
their own coding mistakes, and what were bugs in the RAD software they were
using.
:
:Glade - for GTk?
:Blackadder - for Qt?
:SpecTcl (with SpecPython addin) - for Tkinter(*)
:
:I think I've seen a wxPython one somewhere too?

Boa Constructor?

:And Kdeveloper might handle Python too - I can't remember...
:
:They don't have all the bells and whistles of VB or Delphi 
:yet but they do all build a GUI visually.

But, like I said above, they are buggy at this time, right? Not "release
quality" software? Or, am I mistaken?

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



From bill_tolbert@bigfoot.com  Tue May  1 13:49:15 2001
From: bill_tolbert@bigfoot.com (Bill Tolbert)
Date: Tue, 1 May 2001 08:49:15 -0400 (EDT)
Subject: [Tutor] Need a file browser dialog
Message-ID: <Pine.GSO.4.21L1.0105010844010.9629-100000@sunny>

Hi folks. First, a quick note of thanks for the kind help you guys
provide. This tutor list is great.

I've looked in the usual places and can't find anything that allows me to
do a File/open operation in Tkinter and get a file browse dialog. I
noticed that this is an open question on python.faqts.com in the Tkinter
folder. I promise to give an answer when I get it straight myself!

Thanks,

Bill



From alan.gauld@bt.com  Tue May  1 12:33:56 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 1 May 2001 12:33:56 +0100
Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table
 in GUI
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D736@mbtlipnt02.btlabs.bt.co.uk>

> That's why I said "quite yet". My understanding, is that they are all
> alpha/beta quality. I wouldn't recommend them to a newbie 
> who's just starting out learning GUI. 

I've only used SpecTCL but it is product quality - it was 
commercial for a short while. Its never died on me yet but 
the code it produces is a little idiosyncratic. But once 
you get used to it its certainly workable for complex GUIs.
(And it will generate Perl, Tcl and Java code too...)

As for Blackadder it is a commercial product but I don't 
know how useful the GUI builder support is. (I'm not even 
100% sure it has any!)

> They would have a devil of a time figuring 
> out what were their own coding mistakes, 

I suspect just figuring out what the code is supposed to 
be doing is the tricky bit. Thats why learningh to craft 
it by hand first is a good idea - I found that true of 
C++/MFC in Windows too FWIW. VB is the only GUI builder 
where you really don't need to know anyting about the 
code produced - which is just as well IMHO!


> :I think I've seen a wxPython one somewhere too?
> Boa Constructor?

Thats the one :-)

> Not "release quality" software? Or, am I mistaken?

SpecTcl and BlackAdder are both release quality but 
the former is getting a bit too old.

As for the others, I've heard good reports of Glade 
even though it is still officially beta(or even alpha?).

Alan g.


From rick@niof.net  Tue May  1 14:02:24 2001
From: rick@niof.net (Rick Pasotto)
Date: Tue, 1 May 2001 09:02:24 -0400
Subject: [Tutor] Need a file browser dialog
In-Reply-To: <Pine.GSO.4.21L1.0105010844010.9629-100000@sunny>; from bill_tolbert@bigfoot.com on Tue, May 01, 2001 at 08:49:15AM -0400
References: <Pine.GSO.4.21L1.0105010844010.9629-100000@sunny>
Message-ID: <20010501090224.D23289@tc.niof.net>

On Tue, May 01, 2001 at 08:49:15AM -0400, Bill Tolbert wrote:
> Hi folks. First, a quick note of thanks for the kind help you guys
> provide. This tutor list is great.
> 
> I've looked in the usual places and can't find anything that allows me to
> do a File/open operation in Tkinter and get a file browse dialog. I
> noticed that this is an open question on python.faqts.com in the Tkinter
> folder. I promise to give an answer when I get it straight myself!

I asked this some time ago and never got a response. After writing my
own I discovered that it was there all the time, right under your nose,
just kinda hidden:

>>> from FileDialog import FileDialog
>>> print FileDialog.__doc__
Standard file selection dialog -- no checks on selected file.

    Usage:

        d = FileDialog(master)
        file = d.go(dir_or_file, pattern, default, key)
        if file is None: ...canceled...
        else: ...open file...

    All arguments to go() are optional.

    The 'key' argument specifies a key in the global dictionary
    'dialogstates', which keeps track of the values for the directory
    and pattern arguments, overriding the values passed in (it does
    not keep track of the default argument!).  If no key is specified,
    the dialog keeps no memory of previous state.  Note that memory is
    kept even when the dialog is cancelled.  (All this emulates the
    behavior of the Macintosh file selection dialogs.)


>>>


-- 
"FIJA is not a double-edged sword --- it is a shield against the sword of
government."
        --- Tom Glass
		   Rick Pasotto email: rickp@telocity.com


From lsloan@umich.edu  Tue May  1 14:09:01 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Tue, 01 May 2001 09:09:01 -0400
Subject: [Tutor] FieldStorage solution summary
Message-ID: <200105011309.JAA17875@birds.us.itd.umich.edu>

I want to say thanks to Daniel Yoo and others (sorry, I seem to have
misplaced some of the messages I received) for answering my questions
about converting a FieldStorage object into a dictionary.  I think the
best way I could thank them and help others is to contribute the
solution to my problem back to the list.

The problem was that I'm using FieldStorage objects from the cgi module
and the DocumentTemplate module (pried out of Zope) to write some
CGIs.  The DocumentTemplate functions can use a dictionary to fill in
blanks in the templates by name.  In many cases, I wanted the CGIs to
print what the user had just submitted, which is in a FieldStorage
object and that's not quite like a dictionary.  Sometimes I might also
have one or more other dictionaries with values that I want printed
along with the values from FieldStorage.

With the suggestions I had gotten about converting FieldStorage to a
dictionary, I came up with this function, dictcat, that will take any
number of dictionaries or FieldStorage objects and concatenate them
into a single dictionary.  When you run this as-is, it will print out
the results of the examples:

    import cgi

    def dictcat(*dicts):
        """
    Concatenate any number of dictionary or FieldStorage objects
    together, ignoring non-dictionaries.  If the objects have
    conflicting keys, the last one wins.  If a FieldStorage object
    has multiple values for a key, they are stored in the resulting
    dictionary as a list.
        """

        if len(dicts) == 0:
            return(None)
        all = {}
        for d in dicts:
            if (isinstance(d, cgi.FieldStorage)):
                for k in d.keys():
                    # use getvalue here in case multiple fields with same name
                    all[k] = d.getvalue(k)
            if (type(d) == type({})):
                all.update(d)
        if (all == {}):
            return(None)
        else:
            return(all)

    # Examples...
    if (__name__ == '__main__'):
        import os

        x = {'a': 'xa', 'b': 'xb'}
        y = {'a': 'ya', 'c': 'yc', 'd': 'yd'}

        print x
        print y

        # order matters when there are duplicate keys
        # the last one wins
        print dictcat(x, y)
        print dictcat(y, x)

        # more than two are allowed
        print dictcat(vars(), x, y)

        # non-dictionaries are ignored
        print dictcat(x, 5)
        print dictcat(y, dir())
        print dictcat('lsloan', 10)

        # an empty argument list is handled gracefully, too
        print dictcat()

        # simulate some CGI input
        os.environ['QUERY_STRING'] = 'years=5&name=George&name=Jerry'
        f = cgi.FieldStorage()
        print f
        print dictcat(f, x)

Hope this helps other Python newbies.  I would also appreciate
critiques/suggestions from Python experts if they think I should be
doing this differently or if they know a better way.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From virketis@fas.harvard.edu  Tue May  1 15:17:57 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Tue, 01 May 2001 10:17:57 -0400
Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up
 a table in GUI
Message-ID: <200105011413.KAA11625@smtp3.fas.harvard.edu>

Hi Julieta,

well, I don't have the knowledge of some of the gurus on this list, but
here goes ...

>Is it possible to have the 
>user enter the table's contents in GUI format; that is, set up a really nice 
>table in which the user can move freely up and down and across and enter the 
>table's contents, and at the same time store all of the table's input into a 
>dictionary like you suggested?

I have been grappling with a python module called Tkinter (<from Tkinter
import *>, a good tutorial an overview at
http://www.pythonware.com/library/tkinter/introduction/ by Fredrik Lundh),
which produces GUIs. In principle, your table entry frame would just be a
combination of Entry widgets and Label widgets. Entry widgets let you enter
information, and Labels would just display the margins of the table. To
achieve the right placement, you can use the convenient grid() method,
which lets you array your GUI widgets in a matrix on the frame. You can
move among the cells with a Tab and mouse, but I am sure keyboard control
can be somehow implemented.

As for storing the input, python interacts with Tk via StringVar() objects.
You set some variable to a stringvar and then Entry widgets can access it
to enter information, and python can access it to retrieve it. Storing them
all in a dictionary would just be a question of storing a bunch of strings
in a dictionary: straightforward. 

I hope this helps,

Pijus
----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis.


From britt_green@hotmail.com  Tue May  1 17:27:10 2001
From: britt_green@hotmail.com (Britt Green)
Date: Tue, 01 May 2001 09:27:10 -0700
Subject: [Tutor] SSH Client?
Message-ID: <F170RkIM7XANazafa6r00002459@hotmail.com>

Might anyone know if there is an SSH client written in python anywhere?
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From deirdre@deirdre.net  Tue May  1 17:40:43 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Tue, 1 May 2001 09:40:43 -0700
Subject: [Tutor] SSH Client?
In-Reply-To: <F170RkIM7XANazafa6r00002459@hotmail.com>
References: <F170RkIM7XANazafa6r00002459@hotmail.com>
Message-ID: <a0510030ab714976de0ef@[10.0.1.39]>

>Might anyone know if there is an SSH client written in python anywhere?

I don't know of one.

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From sales@naisnet.com  Tue May  1 17:45:54 2001
From: sales@naisnet.com (North Atlantic Information Systems)
Date: Tue, 01 May 2001 12:45:54 -0400
Subject: [Tutor] Components Price List - May 2001
Message-ID: <E14udHe-0003Vb-00@mail.python.org>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0034)http://www.naisnet.com/newsletter/ -->
<HTML><HEAD><TITLE>North Atlantic Information Systems Price List</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META content="MSHTML 5.00.3211.1700" name=GENERATOR><LINK 
href="http://www.naisnet.com/newsletter/THEME.css" rel=stylesheet type=text/css 
VI6.0THEME="Blueprint"><LINK href="http://www.naisnet.com/newsletter/GRAPH0.css" rel=stylesheet 
type=text/css VI6.0THEME="Blueprint"><LINK href="http://www.naisnet.com/newsletter/COLOR0.css" 
rel=stylesheet type=text/css VI6.0THEME="Blueprint"><LINK 
href="http://www.naisnet.com/newsletter/CUSTOM.css" rel=stylesheet type=text/css 
VI6.0THEME="Blueprint"></HEAD>
<BODY>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="100%" 
valign="top">
  <TBODY>
  <TR>
    <TD vAlign=top width="30%"><IMG alt=NAIS src="http://www.naisnet.com/newsletter/nlogo.gif"> 
</TD>
    <TD align=right width="70%">
      <P><STRONG>North Atlantic Information Systems<BR><FONT size=2>One Colonie 
      Street<BR>Albany, New York 12207<BR>Phone (518) 434-0493<BR>Fax (518) 
      434-0925<BR>Email </FONT><A href="mailto:sales@naisnet.com"><FONT 
      size=2>sales@naisnet.com</FONT></A><FONT size=2> <BR></FONT></STRONG><A 
      href="http://www.albanycomputers.com/"><STRONG><FONT 
      size=2>http://www.albanycomputers.com</FONT></STRONG></A><BR>&nbsp;</P></TD></TR></TBODY></TABLE>
<HR>

<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="100%" 
valign="top">
  <TBODY>
  <TR>
    <TD align=middle><STRONG>Email Price List May&nbsp;2001</STRONG> 
  </TD></TR></TBODY></TABLE>
<HR>

<TABLE align=center border=1 cellPadding=5 cellSpacing=5 width="100%" 
valign="top">
  <TBODY>
  <TR>
    <TD align=middle vAlign=top width="50%">
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=3"><STRONG>Pentium 
            III Processors</STRONG> </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=34&amp;category=3">Intel 
            Pentium III 677EB (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$153.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=33&amp;category=3">Intel 
            Pentium III 650E (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$176.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=35&amp;category=3">Intel 
            Pentium III 700E (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$188.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=36&amp;category=3">Intel 
            Pentium III 733EB (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$213.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=37&amp;category=3">Intel 
            Pentium III 800E (FC-PGA)</A></FONT></TD>

          <TD align=left><FONT size=1>$220.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=38&amp;category=3">Intel 
            Pentium III 800EB (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$220.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=39&amp;category=3">Intel 
            Pentium III 850E (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$236.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=40&amp;category=3">Intel 
            Pentium III 866EB (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$257.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=41&amp;category=3">Intel 
            Pentium III 933EB (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$308.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=42&amp;category=3">Intel 
            Pentium III 1000EB (FC-PGA)</A></FONT></TD>
          <TD align=left><FONT size=1>$382.95</FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=17"><STRONG>Celeron 
            Processors</STRONG> </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=24&amp;category=17">Intel 
            Celeron 566mhz</A></FONT></TD>
          <TD align=left><FONT size=1>$81.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=26&amp;category=17">Intel 
            Celeron 633mhz</A></FONT></TD>
          <TD align=left><FONT size=1>$87.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=25&amp;category=17">Intel 
            Celeron 600mhz</A></FONT></TD>
          <TD align=left><FONT size=1>$88.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=27&amp;category=17">Intel 
            Celeron 677mhz</A></FONT></TD>
          <TD align=left><FONT size=1>$102.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=28&amp;category=17">Intel 
            Celeron 700mhz</A></FONT></TD>
          <TD align=left><FONT size=1>$110.95</FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=18"><STRONG>AMD 
            Processors</STRONG> </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=16&amp;category=18">AMD 
            Duron Socket 650 SOC</A></FONT></TD>
          <TD align=left><FONT size=1>$70.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=17&amp;category=18">AMD 
            Duron Socket 700 SOC</A></FONT></TD>
          <TD align=left><FONT size=1>$70.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=19&amp;category=18">AMD 
            Althon Socket K7 750</A></FONT></TD>
          <TD align=left><FONT size=1>$104.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=18&amp;category=18">AMD 
            Duron Socket 800 SOC</A></FONT></TD>
          <TD align=left><FONT size=1>$106.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=13&amp;category=18">AMD 
            Althon Slot A K7 700</A></FONT></TD>
          <TD align=left><FONT size=1>$110.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=14&amp;category=18">AMD 
            Althon Slot A K7 750</A></FONT></TD>
          <TD align=left><FONT size=1>$110.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=15&amp;category=18">AMD 
            Althon Slot A K7 800</A></FONT></TD>
          <TD align=left><FONT size=1>$136.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=20&amp;category=18">AMD 
            Althon Socket K7 850</A></FONT></TD>
          <TD align=left><FONT size=1>$137.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=21&amp;category=18">AMD 
            Althon Socket K7 900</A></FONT></TD>
          <TD align=left><FONT size=1>$174.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=22&amp;category=18">AMD 
            Althon Socket K7 1000</A></FONT></TD>
          <TD align=left><FONT size=1>$245.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=23&amp;category=18">AMD 
            Althon Socket K7 1100</A></FONT></TD>
          <TD align=left><FONT size=1>$296.95</FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=5"><STRONG>IDE 
            Drives</STRONG> </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=47&amp;category=18">Fujitsu 
            10.2gb ATA/66 7200rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$129.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=48&amp;category=18">Fujitsu 
            10.2gb ATA/100 5400rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$121.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=49&amp;category=18">Fujitsu 
            10.2gb ATA/100 7200rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$129.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=46&amp;category=18">Fujitsu 
            10.2gb ATA/66 5400rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$121.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=51&amp;category=18">Fujitsu 
            20.4gb ATA/100 5400rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$134.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=52&amp;category=18">Fujitsu 
            20.4gb ATA/100 7200rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$160.95</FONT></TD></TR>
        <
TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=50&amp;category=18">Fujitsu 
            20.4gb ATA/66 5400rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$136.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=53&amp;category=18">Fujitsu 
            30.7gb ATA100 5400rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$153.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=54&amp;category=18">Fujitsu 
            40.9gb ATA100 5400rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$189.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=55&amp;category=18">IBM 
            15gb ATA/100 7200rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$149.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=56&amp;category=18">IBM 
            20gb ATA/100 5400rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$149.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=57&amp;category=18">IBM 
            30gb ATA/100 7200rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$195.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=58&amp;category=18">IBM 
            45gb ATA/100 7200rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$208.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=59&amp;category=18">IBM 
            65gb ATA/100 7200rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$318.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=60&amp;category=18">IBM 
            75gb ATA/100 7200rpm</A></FONT></TD>
          <TD align=left><FONT size=1>$435.95</FONT></TD></TR></TBODY></TABLE></TD>
    <TD align=middle vAlign=top width="50%">
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=8"><STRONG>Memory</STRONG> 
            </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=79&amp;category=8">32mb 
            SDRAM DIMM PC100</A></FONT></TD>
          <TD align=left><FONT size=1>$18.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=80&amp;category=8">64mb 
            SDRAM DIMM PC100</A></FONT></TD>
          <TD align=left><FONT size=1>$30.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=81&amp;category=8">64mb 
            SDRAM DIMM PC133</A></FONT></TD>
          <TD align=left><FONT size=1>$30.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=82&amp;category=8">128mb 
            SDRAM DIMM PC100</A></FONT></TD>
          <TD align=left><FONT size=1>$56.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=83&amp;category=8">128mb 
            SDRAM DIMM PC133</A></FONT></TD>
          <TD align=left><FONT size=1>$56.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=84&amp;category=8">256mb 
            SDRAM DIMM PC100</A></FONT></TD>
          <TD align=left><FONT size=1>$108.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=85&amp;category=8">256mb 
            SDRAM DIMM PC133</A></FONT></TD>
          <TD align=left><FONT size=1>$108.95</FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=19"><STRONG>Motherboards</STRONG> 
            </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=101&amp;category=19">Abit 
            BE6 II Pentium III Motherboard (Slot 1)</A></FONT></TD>
          <TD align=left><FONT size=1>$153.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=104&amp;category=19">Abit 
            BX133 RAID Pentium III Motherboard (Socket 370)</A></FONT></TD>
          <TD align=left><FONT size=1>$153.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=97&amp;category=19">Abit 
            KT7 Athlon/Duron Motherboard (Socket A)</A></FONT></TD>
          <TD align=left><FONT size=1>$170.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=99&amp;category=19">Abit 
            KT7A Athlon/Duron Motherboard (Socket A)</A></FONT></TD>
          <TD align=left><FONT size=1>$182.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=100&amp;category=19">Abit 
            KT7A-RAID Athlon/Duron Motherboard (Socket A)</A></FONT></TD>
          <TD align=left><FONT size=1>$201.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=98&amp;category=19">Abit 
            KT7-RAID Athlon/Duron Motherboard (Socket A)</A></FONT></TD>
          <TD align=left><FONT size=1>$195.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=103&amp;category=19">Abit 
            SA6R Pentium III Motherboard (Socket 370)</A></FONT></TD>
          <TD align=left><FONT size=1>$193.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=102&amp;category=19">Abit 
            SE6 Pentium II/III Motherboard (Socket 370)</A></FONT></TD>
          <TD align=left><FONT size=1>$167.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=106&amp;category=19">Abit 
            VH6 II Pentium III Motherboard (Socket 370)</A></FONT></TD>
          <TD align=left><FONT size=1>$127.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=105&amp;category=19">Ab
it 
            VH6 Pentium III Motherboard (Socket 370)</A></FONT></TD>
          <TD align=left><FONT size=1>$122.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=107&amp;category=19">Abit 
            VL6 Pentium III Motherboard (Socket 370)</A></FONT></TD>
          <TD align=left><FONT size=1>$105.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=108&amp;category=19">Abit 
            VP6 Pentium III Motherboard (Socket 370)</A></FONT></TD>
          <TD align=left><FONT size=1>$196.95</FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=12"><STRONG>Network</STRONG> 
            </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=109&amp;category=12">3com 
            3CR990TX95 10/100 Network Card</A></FONT></TD>
          <TD align=left><FONT size=1>$116.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=110&amp;category=12">3com 
            OfficeConnect 10/100 16 Port Hub</A></FONT></TD>
          <TD align=left><FONT size=1>$258.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=113&amp;category=12">Patch 
            Cable - 10 Foot</A></FONT></TD>
          <TD align=left><FONT size=1>$4.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=114&amp;category=12">Patch 
            Cable - 14 Foot</A></FONT></TD>
          <TD align=left><FONT size=1>$5.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=115&amp;category=12">Patch 
            Cable - 25 Foot</A></FONT></TD>
          <TD align=left><FONT size=1>$9.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=111&amp;category=12">Patch 
            Cable - 3 Foot</A></FONT></TD>
          <TD align=left><FONT size=1>$2.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=116&amp;category=12">Patch 
            Cable - 50 Foot</A></FONT></TD>
          <TD align=left><FONT size=1>$14.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=112&amp;category=12">Patch 
            Cable - 7 Foot</A></FONT></TD>
          <TD align=left><FONT size=1>$3.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=120&amp;category=12">WiseCom 
            10/100 16 Port Hub</A></FONT></TD>
          <TD align=left><FONT size=1>$188.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=119&amp;category=12">WiseCom 
            10/100 8 Port Hub</A></FONT></TD>
          <TD align=left><FONT size=1>$71.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=117&amp;category=12">WiseCom 
            10/100 PCI Network Card</A></FONT></TD>
          <TD align=left><FONT size=1>$14.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=118&amp;category=12">WiseCom 
            8 Port 10baseT Hub</A></FONT></TD>
          <TD align=left><FONT size=1>$26.95</FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=7"><STRONG>Keyboards</STRONG> 
            </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=73&amp;category=7">Logitech 
            Dexxa 107Key Keyboard PS/2</A></FONT></TD>
          <TD align=left><FONT size=1>$11.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=74&amp;category=7">Logitech 
            Dexxa Internet Keyboard PS/2</A></FONT></TD>
          <TD align=left><FONT size=1>$22.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=77&amp;category=7">Microsoft 
            Natural Keyboard Elite</A></FONT></TD>
          <TD align=left><FONT size=1>$40.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=78&amp;category=7">Microsoft 
            Natural Keyboard Pro</A></FONT></TD>
          <TD align=left><FONT size=1>$72.95</FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top><FONT size=2><A 
            href="http://www.naisnet.com/listperipherals.asp?category=29"><STRONG>Mice</STRONG> 
            </A></FONT></TD></TR></TBODY></TABLE>
      <TABLE align=center border=1 cellPadding=2 cellSpacing=0 width="100%" 
      valign="top">
        <TBODY>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=71&amp;category=29">Logitech 
            Dexxa 2BTN PS/2 w/ser adpt Mouse</A></FONT></TD>
          <TD align=left><FONT size=1>$3.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=70&amp;category=29">Logitech 
            Dexxa 2BTN Wheel Mouse PS/2</A></FONT></TD>
          <TD align=left><FONT size=1>$7.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=72&amp;category=29">Logitech 
            Dexxa Optical Mouse PS/2</A></FONT></TD>
          <TD align=left><FONT size=1>$25.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=75&amp;category=29">Microsoft 
            062-00003 Wheel Mouse</A></FONT></TD>
          <TD align=left><FONT size=1>$19.95</FONT></TD></TR>
        <TR>
          <TD align=left><FONT size=1><A 
            href="http://www.naisnet.com/peripheraldetail.asp?product=76&amp;category=29">Microsoft 
            D58-00002 Intellimouse Optical</A></FONT></TD>
          <TD align=left><FONT 
  size=1>$56.95</FONT></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<HR>

<TABLE align=center border=0 cellPadding=10 cellSpacing=0 width="100%">
  <TBODY>
  <TR>
    <TD align=right width="50%"><IMG alt="BookPC Image" 
      src="http://www.naisnet.com/newsletter/bookpc.jpg"> </TD>
    <TD align=left width="50%"><A 
      href="http://www.naisnet.com/bookpc3.asp">Build your own Pentium III Book 
      PC</A> </TD></TR></TBODY></TABLE>
<HR>

<TABLE align=center border=0 cellPadding=10 cellSpacing=0 width="100%">
  <TBODY>
  <TR>
    <TD align=middle><A href="http://www.naisnet.com/sb2-1.asp">Build Your Own 
      System Online!</A> </TD></TR></TBODY></TABLE>
<HR>

<P align=center><FONT size=1>Our Email price list is never sent unsolicited, and 
is available by subscription only.&nbsp; If you have received this price list in 
error and wish <BR>to be removed,&nbsp;simply&nbsp;go to <A 
href="http://www.naisnet.com/newsletter/remove.asp">http://www.naisnet.com/newsletter/remove.asp</A> 
&nbsp;</FONT>&nbsp;</P></BODY></HTML>




From cwebster@nevada.edu  Tue May  1 18:17:37 2001
From: cwebster@nevada.edu (Corran Webster)
Date: Tue, 1 May 2001 10:17:37 -0700
Subject: [Tutor] determining whether a set is a group
In-Reply-To: <3AEC3A7E.1868590F@seatech.fau.edu>
References: <Pine.LNX.4.21.0104282350400.17256-100000@hkn.eecs.berkeley.edu>
 <3AEC3A7E.1868590F@seatech.fau.edu>
Message-ID: <f05100c01b714974069b5@[192.168.0.4]>

>Daniel Yoo wrote:
>
>>  On Sat, 28 Apr 2001, Sheila King wrote:
>>
>>  > The axioms (basic rules) for a group are:
>>  > ( where the dot (•) symbolizes some operation...)
>>  >
>>  >    1.CLOSURE: If a and b are in the group then a • b is also in the group.
>>  >    2.ASSOCIATIVITY: If a, b and c are in the group then (a • b) 
>>• c = a • (b •
>>  > c).
>>  >    3.IDENTITY: There is an element e of the group such that for 
>>any element a
>>  > of the group
>>  >      a • e = e • a = a.
>>  >    4.INVERSES: For any element a of the group there is an 
>>element a^(-1) such
>>  > that
>>  >           a • a^(-1) = e
>>  >           and
>>  >           a^(-1) • a = e
>>
>
>The pb is that my computer can't handle very well infinite sets... how does a
>program like Mapple handle this kind of things ?

Programs like Mathematica and Maple handle infinite sets either by 
approximation (eg. for real numbers) or by dealing with a finite 
subset and hoping it doesn't get too big.  This is much the same as 
the way that python handles the potentially infinite, with floating 
point numbers and long integers.  Indeed it's universal for all 
computers without unlimited memory  ;)

Programs and routines in Maple for dealing with infinite groups 
almost certainly assume that the operations that you supply are valid 
group operations.

>How can i implement something whose cardinal is Cantor something 
>(ie. infinite) ?

In Python you could go a long way by defining a class to represent 
the elements of the set and using the __mul__, __div__ etc. special 
methods to implement the group operations.  This would allow you to 
work with a finite number of elements at a time, but taken from an 
infinite group.

You couldn't solve Julieta's problem for an infinite group using this 
sort of thing, however.

As far as I can see, the best solution to the original problem (given 
a finite set and the Cayley matrix of an operation on the set, is it 
a group?) is a brute force checking of the axioms.  For efficiency 
it's probably best use a dictionary to represent the matrix, rather 
than a list of lists, and for generality it's probably better to have 
the algortihm work with the operation as a function, rather than 
directly with the matrix, but I could be wrong.

Eg. (untested code)

def cayleyToOp(set, cayley):
   """Given a set and a Cayley matrix, returns a function which 
performs the operation on two elements."""
   matrix = {}
   for a in range(len(set)):
     for b in range(len(set)):
       matrix[(set[a], set[b])] = cayley[a][b]
   return lambda a, b, matrix=matrix: matrix[(a,b)]

Z3 = [0, 1, 2]
Z3Cayley = [[0,1,2], [1,2,0], [2,0,1]]
Z3op = cayleyToOp(Z3, Z3Cayley)

print Z3op(1,1)
#should print 2

of course Z3op could be more efficiently implimented as

def Z3op(a, b):
   return (a+b) % 3

which is why the group checking stuff will be more flexible if you 
allow functions.

>Although i remember what a group is , i don't remember what groups are useful
>for....... any math teachers?

As it so happens, I teach math at UNLV.  Groups typically come up in 
situations where there is symmetry of some sort and so can be used to 
describe the symmetry which is present.  Knowing symmetries can help 
you find and classify solutions to concrete problems.

They are also one of the fundamental building blocks of abstract 
algebra and most interesting algebraic systems involve some sort of 
group structure.  The standard addition of numbers is an example of a 
group.

Regards,
Corran


From bdupire@seatech.fau.edu  Tue May  1 20:25:55 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Tue, 01 May 2001 15:25:55 -0400
Subject: [Tutor] determining whether a set is a group
References: <Pine.LNX.4.21.0104282350400.17256-100000@hkn.eecs.berkeley.edu>
 <3AEC3A7E.1868590F@seatech.fau.edu> <f05100c01b714974069b5@[192.168.0.4]>
Message-ID: <3AEF0DC3.3152E111@seatech.fau.edu>

Thank you for your answer.

A few years ago, iwas only doing mathematics and physics and the kind of exercice to
practice we got was like the following one:
a * b = a+b - a x b
is (Z, *) a group ?
Yes ? no ?
If no how can i modify it to make it a group ?

It would be interesting to make a computer program to solve this kinds of pb.
As you suggest it, i would use a subset, lets say -10 ; 10  (because 0, 1 are often
worth to try as a general rule ) and additionnally i would build a function, that
takes a variable and checks if it belongs to Z


Answer:
if b= 1,   a * b = a+ b - a x b = a + 1 - a x 1 = 1
so a * 1 = 1 whatever 'a' is. so 1 has no inverse, i have to remove it from Z to
have a group....

But to make a  computer think like that is not so easy... :o)
Benoit


Corran Webster wrote:

>
>
> As far as I can see, the best solution to the original problem (given
> a finite set and the Cayley matrix of an operation on the set, is it
> a group?) is a brute force checking of the axioms.  For efficiency
> it's probably best use a dictionary to represent the matrix, rather
> than a list of lists, and for generality it's probably better to have
> the algortihm work with the operation as a function, rather than
> directly with the matrix, but I could be wrong.
>
> Eg. (untested code)
>
> def cayleyToOp(set, cayley):
>    """Given a set and a Cayley matrix, returns a function which
> performs the operation on two elements."""
>    matrix = {}
>    for a in range(len(set)):
>      for b in range(len(set)):
>        matrix[(set[a], set[b])] = cayley[a][b]
>    return lambda a, b, matrix=matrix: matrix[(a,b)]
>
> Z3 = [0, 1, 2]
> Z3Cayley = [[0,1,2], [1,2,0], [2,0,1]]
> Z3op = cayleyToOp(Z3, Z3Cayley)
>
> print Z3op(1,1)
> #should print 2
>
> of course Z3op could be more efficiently implimented as
>
> def Z3op(a, b):
>    return (a+b) % 3
>
> which is why the group checking stuff will be more flexible if you
> allow functions.
>
> >Although i remember what a group is , i don't remember what groups are useful
> >for....... any math teachers?
>
> As it so happens, I teach math at UNLV.  Groups typically come up in
> situations where there is symmetry of some sort and so can be used to
> describe the symmetry which is present.  Knowing symmetries can help
> you find and classify solutions to concrete problems.
>
> They are also one of the fundamental building blocks of abstract
> algebra and most interesting algebraic systems involve some sort of
> group structure.  The standard addition of numbers is an example of a
> group.
>
> Regards,
> Corran
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From dyoo@hkn.eecs.berkeley.edu  Wed May  2 03:17:34 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 1 May 2001 19:17:34 -0700 (PDT)
Subject: [Tutor] SSH Client?
In-Reply-To: <F170RkIM7XANazafa6r00002459@hotmail.com>
Message-ID: <Pine.LNX.4.21.0105011910550.27181-100000@hkn.eecs.berkeley.edu>

On Tue, 1 May 2001, Britt Green wrote:

> Might anyone know if there is an SSH client written in python anywhere?

I couldn't find an ssh client in Python, sorry.  I wonder if it would be
difficult to write wrappers for the openssh stuff at:

    http://www.openssh.org


I did find cryptography stuff here:

    http://www.post1.com/home/ngps/m2/

M2Crypto implements a Python wrapper for OpenSSL, but it might not be
relevant with what you want.



From julieta_rangel@hotmail.com  Wed May  2 04:17:19 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Tue, 01 May 2001 22:17:19 -0500
Subject: [Tutor] converting unkown amount of input into strings
Message-ID: <F128UiaxcAaEDxMGy150000eb05@hotmail.com>

I have a dumb question.  I'm trying to write a program which differentiates 
polynomials.  In this program, the user enters the degree of the polynomial, 
and then is asked for the coefficients of the polynomial.  How can I store 
these coefficients into a list or into a string so that I can use them later 
in the following line:

r = Poly (c=[])

This is what I have so far:
import string
class Poly:
    def __init__ ( self, v = 'x', c = [0]):
        """__init__():
        Initializes a polynomial
        Default variable is x
        Default polynomial is zero"""
        self.var = v
        self.coef = c
        self.deg = len(c)-1
    def __str__ (self):
        """__str__():
        Converts a polynomial into a string"""
        x = `self.coef[0]`
        for i in range (1, self.deg+1):
            x = x + " + " + `self.coef[i]` + self.var + "^" + `i`
        return x

def Derivative(p):
    """Input: an instance of a polynomial
    Output: a polynomial that is the derivative of the input polynomial
    Side Effects: None"""
    pv=p.var
    pc=[]
    if p.deg==0:
        return Poly (v=pv,c=[0])
    else:
        for i in range(0,p.deg):
            d=(i+1)*p.coef[i+1]
            pc.append(d)
        return Poly (v=pv,c=pc)

I want the input (the coefficients)from the following line to be stored on a 
string, or list so that I can use them later on (keep scrolling until you 
find the place where I want to insert the coefficients entered)
a = input ("Enter the degree of your polynomial  ")

i = 1
while i<=a+1:

    b=a
    while b>=0:

    	w = input("Enter coefficient of x^ %s." % (b) )
        b=b-1
        i = i + 1
r = Poly (c=[w]) #  This is where I want to insert the coefficients.

Once the person enters the coefficients, how can I
# insert them inside the brackets.  The way I have it right now the program 
only considers the last coefficient entered, but I want the program to 
calculate the derivative of the entire input

p = Poly (c = [-1,1,2])
q = Poly (v = 'y', c = [-1,0,2,0,4,3])
m = Derivative(p)
n = Derivative(q)
o = Derivative(r)
print "The derivative of %s is: \n %s" % (p,m)
print " "
print "The derivative of %s is: \n %s" % (q,n)
print " "
print "The derivative of %s is: \n %s" % (r,o)
print " "

Again, any help will be greatly appreciated.

Julieta

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From bdupire@seatech.fau.edu  Wed May  2 04:25:18 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Tue, 01 May 2001 23:25:18 -0400
Subject: [Tutor] converting unkown amount of input into strings
References: <F128UiaxcAaEDxMGy150000eb05@hotmail.com>
Message-ID: <3AEF7E1E.FEE7CF49@seatech.fau.edu>

This should do what you need...
coeff is the list of coefficient
coeff[0] is coeff for x^0
coeff[1] is coeff for x...
etc...


degree=raw_input('degree ?')
coeff=[]
for i in range (0, eval(degree)+1):
    coefficient = raw_input('coeff for x^ %i  ? ' %i)
    coeff.append(coefficient)


Julieta Rangel wrote:

> I have a dumb question.  I'm trying to write a program which differentiates
> polynomials.  In this program, the user enters the degree of the polynomial,
> and then is asked for the coefficients of the polynomial.  How can I store
> these coefficients into a list or into a string so that I can use them later
> in the following line:
>
> r = Poly (c=[])
>
> This is what I have so far:
> import string
> class Poly:
>     def __init__ ( self, v = 'x', c = [0]):
>         """__init__():
>         Initializes a polynomial
>         Default variable is x
>         Default polynomial is zero"""
>         self.var = v
>         self.coef = c
>         self.deg = len(c)-1
>     def __str__ (self):
>         """__str__():
>         Converts a polynomial into a string"""
>         x = `self.coef[0]`
>         for i in range (1, self.deg+1):
>             x = x + " + " + `self.coef[i]` + self.var + "^" + `i`
>         return x
>
> def Derivative(p):
>     """Input: an instance of a polynomial
>     Output: a polynomial that is the derivative of the input polynomial
>     Side Effects: None"""
>     pv=p.var
>     pc=[]
>     if p.deg==0:
>         return Poly (v=pv,c=[0])
>     else:
>         for i in range(0,p.deg):
>             d=(i+1)*p.coef[i+1]
>             pc.append(d)
>         return Poly (v=pv,c=pc)
>
> I want the input (the coefficients)from the following line to be stored on a
> string, or list so that I can use them later on (keep scrolling until you
> find the place where I want to insert the coefficients entered)
> a = input ("Enter the degree of your polynomial  ")
>
> i = 1
> while i<=a+1:
>
>     b=a
>     while b>=0:
>
>         w = input("Enter coefficient of x^ %s." % (b) )
>         b=b-1
>         i = i + 1
> r = Poly (c=[w]) #  This is where I want to insert the coefficients.
>
> Once the person enters the coefficients, how can I
> # insert them inside the brackets.  The way I have it right now the program
> only considers the last coefficient entered, but I want the program to
> calculate the derivative of the entire input
>
> p = Poly (c = [-1,1,2])
> q = Poly (v = 'y', c = [-1,0,2,0,4,3])
> m = Derivative(p)
> n = Derivative(q)
> o = Derivative(r)
> print "The derivative of %s is: \n %s" % (p,m)
> print " "
> print "The derivative of %s is: \n %s" % (q,n)
> print " "
> print "The derivative of %s is: \n %s" % (r,o)
> print " "
>
> Again, any help will be greatly appreciated.
>
> Julieta
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From bdupire@seatech.fau.edu  Wed May  2 05:04:00 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Wed, 02 May 2001 00:04:00 -0400
Subject: [Tutor] converting unkown amount of input into strings
References: <F128UiaxcAaEDxMGy150000eb05@hotmail.com>
Message-ID: <3AEF8730.718EE54@seatech.fau.edu>

Julieta,

oups... i sent my answer too quickly

The debugged program is


degree=input('degree ?')
coeff=[]
for i in range (0, degree+1):
    coefficient = input('coeff for x^ %i  ? ' %i)
    coeff.append(coefficient)
print coeff


these are the explanations.....

I saw you wanted to use 'while' to loop over the coefficients...
Use 'for' instead  because you know exactly the number of iterations you want to
perform.
If the user enters degree= 3, you know you want to perform 4 times the loop
(don't forget coeff 0) --> that's degree+1!

"while <condition>" is to be used when you don't know when <condition> gonna be
false, and therefore don't know how many loops you want to perform.

ex:
while a>=1:
    a=input("enter a number..")

You really don't know when the user will enter a number less than 1
This can loop forever ! or just once...

range(0,n) is an instruction that generates a sequence [0, 1, 2, .. n-1]
I loop over this sequence to get the coefficients...
for i in range(0, degree+1):
will affect  the value 0 to i, run the loop
then i=1, run the loop...
so on, till i= degree


you can now use your program like this

myPoly = Poly('x', coeff)
or
myPoly = Poly(c= coeff)

Poly(<arguments here>) creates a new Poly object, and call the __init__ method
with the arguments..(the first argument being a reference to the object just
created).
It returns your Polynome object....

benoit










From julieta_rangel@hotmail.com  Wed May  2 06:35:05 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Wed, 02 May 2001 00:35:05 -0500
Subject: [Tutor] integration of polynomials in Python
Message-ID: <F49qORloJOXQQfeNADT00013b9c@hotmail.com>

I finally finished the differentiation program.  What changes should I make 
so that instead of differentiating, my program integrates polynomials.  Can 
anyone help?  Here you have my finished program.  It is not the best program 
you'll ever see :) but I'm very proud of it.  It took me forever to put it 
together, eventhough I had to ask you guys for help in writing every line. 
Thanks a lot! :) Anyway, here you have the program.  What can I do to make 
it integrate?

import string
class Poly:
    def __init__ ( self, v = 'x', c = [0]):
        """__init__():
        Initializes a polynomial
        Default variable is x
        Default polynomial is zero"""
        self.var = v
        self.coef = c
        self.deg = len(c)-1
    def __str__ (self):
        """__str__():
        Converts a polynomial into a string"""
        x = `self.coef[0]`
        for i in range (1, self.deg+1):
            x = x + " + " + `self.coef[i]` + self.var + "^" + `i`
        return x

def Derivative(p):
    """Input: an instance of a polynomial
    Output: a polynomial that is the derivative of the input polynomial
    Side Effects: None"""
    pv=p.var
    pc=[]
    if p.deg==0:
        return Poly (v=pv,c=[0])
    else:
        for i in range(0,p.deg):
            d=(i+1) * p.coef[i+1]
            pc.append(d)
        return Poly (v=pv,c=pc)
degree = input('Enter the degree of your polynomial')
coef=[]
for i in range (0,degree+1):
    coefficient = input('Enter the coefficient for x^ %i ? ' %i)
    coef.append(coefficient)

r = Poly (c = coef)
o = Derivative(r)
print "The derivative of %s is: \n %s" % (r,o)
print " "

# This is some code to test new functions
t = Integrate(p)
u = Multiply(p,q)
print "The intgral of %s is: \n %s" % (p,t)
print " "
print "The product of %s and \n %s is: \n %s" % (p,q,u)
print " "

Any help is truly appreciated.

Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From deirdre@deirdre.net  Wed May  2 07:20:42 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Tue, 1 May 2001 23:20:42 -0700
Subject: [Tutor] integration of polynomials in Python
In-Reply-To: <F49qORloJOXQQfeNADT00013b9c@hotmail.com>
References: <F49qORloJOXQQfeNADT00013b9c@hotmail.com>
Message-ID: <a0510030cb71555f3a0c1@[10.0.1.41]>

>  What can I do to make it integrate?


Oh geez, I had calculus in 1976. If I get it wrong, don't yell too loudly. :)


A simple integral is simply the reverse of the differential.

So, given the equation:

2x^2 + 4x + 3 = 0

The differential would be:

4x + 4

For that equation, the process would be something like:

The first exponent coefficient (you call this 'deg') is 1; it will be 
increased 1 to 2;
You also divide by the new coefficient:

Thus:

  (4/2)x^2 + (4/1)x + k = 2x^2 + 4x + k

There's always a k (because that x^0 component drops off when you do 
the differential).
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From cooler12001@yahoo.com  Wed May  2 07:45:13 2001
From: cooler12001@yahoo.com (Matthews James)
Date: Tue, 1 May 2001 23:45:13 -0700 (PDT)
Subject: [Tutor] python and html
Message-ID: <20010502064513.32865.qmail@web11401.mail.yahoo.com>

can you use python in html

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/


From cooler12001@yahoo.com  Wed May  2 07:49:15 2001
From: cooler12001@yahoo.com (Matthews James)
Date: Tue, 1 May 2001 23:49:15 -0700 (PDT)
Subject: [Tutor] help turningTkinter programs in to exe
Message-ID: <20010502064915.79578.qmail@web11402.mail.yahoo.com>

does anyone know how to turn a program that has
Tkinter in it into a exe one. Py2exe will not
have anything to do with them 

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/


From dyoo@hkn.eecs.berkeley.edu  Wed May  2 08:24:51 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 2 May 2001 00:24:51 -0700 (PDT)
Subject: [Tutor] integration of polynomials in Python  [And SICP for
 free!]
In-Reply-To: <F49qORloJOXQQfeNADT00013b9c@hotmail.com>
Message-ID: <Pine.LNX.4.21.0105020012520.32601-100000@hkn.eecs.berkeley.edu>

On Wed, 2 May 2001, Julieta Rangel wrote:

> I finally finished the differentiation program.  What changes should I make 
> so that instead of differentiating, my program integrates polynomials.  Can 
> anyone help?  Here you have my finished program.  It is not the best program 
> you'll ever see :) but I'm very proud of it.  It took me forever to put it 
> together, eventhough I had to ask you guys for help in writing every line. 
> Thanks a lot! :) Anyway, here you have the program.  What can I do to make 
> it integrate?

Let's have this placed in Useless Python.  If you ever write a script that
you're happy with, feel free to contribute it to the Useless Python
repository.  It's at:

    http://www.lowerstandard.com/python/pythonsource.html

You program looks good; I'm happy that the differentiation works ok.


Integration is actually not too bad either; think about what happens when
we integrate polynomials:

    f(x) = 1x^3 + 2x^2 + 3x + 4

or, if we reverse the order of the coefficients:

    f(x) = 4 + 3x + 2x^2 + 1x^3

If we integrate this, we end up with the polynomial:

    f(x) = 4        3   2     2   3     1   4
           - x   +  - x^   +  - x^   +  - x^
           1        2         3         4


If you try a few examples by hand, I think you'll figure out a way to
fiddle with your list of coefficients to get things working.


Also, I second Alan's recommendation on Structure and Interpretation of
Computer Programs: it's one of the best CS books I've read.  You seem to
have a mathy slant, and I think you'll enjoy this book a LOT.  The authors
are really generous folk: the book is actually published online as well!

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

So you don't even need to leave the house... although that's not quite a
good thing.  Take a nice walk first; you'll need to keep your head clear
while reading this stuff.  *grin*  If you like the book, buy it; it has a
nice feel.


Good luck!



From dyoo@hkn.eecs.berkeley.edu  Wed May  2 08:26:55 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 2 May 2001 00:26:55 -0700 (PDT)
Subject: [Tutor] help turningTkinter programs in to exe
In-Reply-To: <20010502064915.79578.qmail@web11402.mail.yahoo.com>
Message-ID: <Pine.LNX.4.21.0105020025150.32601-100000@hkn.eecs.berkeley.edu>

On Tue, 1 May 2001, Matthews James wrote:

> does anyone know how to turn a program that has
> Tkinter in it into a exe one. Py2exe will not
> have anything to do with them 

Gordon MacMillian's Python Installer is supposed to be more powerful than
py2exe.  You can find it here:

    http://www.mcmillan-inc.com/install1.html

A few people on tutor have been playing around with Installer, so you're
in good company.



From dyoo@hkn.eecs.berkeley.edu  Wed May  2 08:50:14 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 2 May 2001 00:50:14 -0700 (PDT)
Subject: [Tutor] FieldStorage solution summary
In-Reply-To: <200105011309.JAA17875@birds.us.itd.umich.edu>
Message-ID: <Pine.LNX.4.21.0105020044080.32601-100000@hkn.eecs.berkeley.edu>

On Tue, 1 May 2001, Lance E Sloan wrote:

> With the suggestions I had gotten about converting FieldStorage to a
> dictionary, I came up with this function, dictcat, that will take any
> number of dictionaries or FieldStorage objects and concatenate them
> into a single dictionary.  When you run this as-is, it will print out
> the results of the examples:

The code looks good.  The only thing I could argue for is:

>             if (type(d) == type({})):

which might be better off as types.DictType, but they, we've had a lot of
religious argument about this.


I'm not sure if dictcat() should have to worry about non-dictionaries; it
might be better off giving a message that dictcat() needs to take a
dictonary-like object; otherwise, it might obscure some errors that the
programmer might forget to check.



From dyoo@hkn.eecs.berkeley.edu  Wed May  2 08:55:36 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 2 May 2001 00:55:36 -0700 (PDT)
Subject: [Tutor] FieldStorage solution summary
In-Reply-To: <Pine.LNX.4.21.0105020044080.32601-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.21.0105020052230.32601-100000@hkn.eecs.berkeley.edu>

On Wed, 2 May 2001, Daniel Yoo wrote:

> which might be better off as types.DictType, but they, we've had a lot of
                                                   ^^^^
Umm... meant to say "then".


> dictonary-like object; otherwise, it might obscure some errors that the
  ^^^^^^^^^

... and "dictionary".  Apologies; I just took some Themo-Flu, and the
stuff is making me drowsy and stupid.



From wheelege@tsn.cc  Wed May  2 09:57:13 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 2 May 2001 18:57:13 +1000
Subject: [Tutor] help turningTkinter programs in to exe
References: <20010502064915.79578.qmail@web11402.mail.yahoo.com>
Message-ID: <03dd01c0d2e5$e1f2bfa0$0200a8c0@ACE>

> does anyone know how to turn a program that has
> Tkinter in it into a exe one. Py2exe will not
> have anything to do with them
>

  Are you sure?  Do you have python 2.0 with the latest version of py2exe?
I have made plenty of tkinter programs into standalone distributions using
py2exe.
  Give me more detail on what you are doing, and I'll see if I can find out
what it is your doing wrong.

  Glen.



From alan.gauld@bt.com  Wed May  2 10:34:09 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 2 May 2001 10:34:09 +0100
Subject: [Tutor] python and html
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D73D@mbtlipnt02.btlabs.bt.co.uk>

> can you use python in html

yes, look at PSP, Zope, PMZ, Active Scripting etc
See the CGI special interest group/topic too.

Now what do you actually want to do?

Alan G.


From lsloan@umich.edu  Wed May  2 13:38:28 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Wed, 02 May 2001 08:38:28 -0400
Subject: [Tutor] FieldStorage solution summary
In-Reply-To: Your message of "Wed, 02 May 2001 00:50:14 PDT."
 <Pine.LNX.4.21.0105020044080.32601-100000@hkn.eecs.berkeley.edu>
Message-ID: <200105021238.IAA03791@birds.us.itd.umich.edu>

Daniel Yoo wrote:
> I'm not sure if dictcat() should have to worry about non-dictionaries; it
> might be better off giving a message that dictcat() needs to take a
> dictonary-like object; otherwise, it might obscure some errors that the
> programmer might forget to check.

I admit the name of the function might be misleading, but its
primary purpose in life is to convert FieldStorage to dictionary.
Do you mean that I should split this into two functions, one for
converting FieldStorage and the other for concatenating dictionaries?
Or do you mean that I should have the function throw an exception
if it is passed an argument that's not a dictionary or FieldStorage?

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From Vladimir.Denis@olsinc.net  Wed May  2 15:07:26 2001
From: Vladimir.Denis@olsinc.net (Vladimir.Denis@olsinc.net)
Date: Wed, 2 May 2001 10:07:26 -0400
Subject: [Tutor] searching a file for a specific word
Message-ID: <OF2D0062C1.315C3ED4-ON85256A40.004C8CB7@olsinc.net>

Hello everyone, this is my first attempt at programming and I have chosen
python because I was told that it's easy to learn.  In any event I thought
that for my first script I would write a program that would be able to find
a word or words in a file.  The problem is I'm stuck.  Below you will find
what I have done so far and any advice will be appreciated.  As you will
note, I have figured out how to get the file name, the words to be searched
for, but I don't know how to actually search for the words.  The only thing
I could think of so far is to use the os module and use the grep command
but I'm sure there's another way and I can't figure it out.  Since I'm new
to programming I am not too familiar with strings (and I'm sure this is
probably part of the solution).

#/usr/bin/python

# this script will print specific words from a file
# (most likely a log file) to desktop

import os, string, sys

names = []
logf = sys.argv[-1]

###############################################################
## opens the /var/log/messages file by default or other file ##
###############################################################


if (logf[0:1] == "/"]
     filename = logf
     names.append(sys.argv[1:-1]
     found = open("filename","r")



else:
     filename = "/var/log/messages"
     names.append(sys.argv[1:-1]





From bdupire@seatech.fau.edu  Wed May  2 15:10:01 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Wed, 02 May 2001 10:10:01 -0400
Subject: [Tutor] searching a file for a specific word
References: <OF2D0062C1.315C3ED4-ON85256A40.004C8CB7@olsinc.net>
Message-ID: <3AF01539.708FB7D0@seatech.fau.edu>

The following function does something similar....
It looks for a word in a web page (it was post by Remco a few weeks ago)

You can transpose it to your problem
The open function returns a file object you can read from...
page is actually all the text in the file... (here the webpage)

 use string.find... it's a convenient function for your problem...:o)


def find_word(url, word):
    import urllib, string
    page = urllib.URLopener().open(url).read()
    if string.find(page, word) != -1:
       return 1
    else:
       return 0



Benoit (tks Remco.. :o) )

Vladimir.Denis@olsinc.net wrote:

> Hello everyone, this is my first attempt at programming and I have chosen
> python because I was told that it's easy to learn.  In any event I thought
> that for my first script I would write a program that would be able to find
> a word or words in a file.  The problem is I'm stuck.  Below you will find
> what I have done so far and any advice will be appreciated.  As you will
> note, I have figured out how to get the file name, the words to be searched
> for, but I don't know how to actually search for the words.  The only thing
> I could think of so far is to use the os module and use the grep command
> but I'm sure there's another way and I can't figure it out.  Since I'm new
> to programming I am not too familiar with strings (and I'm sure this is
> probably part of the solution).
>
> #/usr/bin/python
>
> # this script will print specific words from a file
> # (most likely a log file) to desktop
>
> import os, string, sys
>
> names = []
> logf = sys.argv[-1]
>
> ###############################################################
> ## opens the /var/log/messages file by default or other file ##
> ###############################################################
>
> if (logf[0:1] == "/"]
>      filename = logf
>      names.append(sys.argv[1:-1]
>      found = open("filename","r")
>
> else:
>      filename = "/var/log/messages"
>      names.append(sys.argv[1:-1]
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From julieta_rangel@hotmail.com  Wed May  2 17:58:22 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Wed, 02 May 2001 11:58:22 -0500
Subject: [Tutor] rational number representation in Python
Message-ID: <F150vJo9iiy6hBySBzC0000f53a@hotmail.com>

To integrate a polynomial, say 3x^2+7x+4, we have to add one to the exponent 
and then divide the coefficient by this result.  For example, in our 
polynomial above, we would have to add 1 to our exponent so that we get 
3.Then we divide our coefficient by this result (3/3=1), so our new 
coefficient is going to be one.  We do the same thing to the next term; we 
add one to our exponent, which will give us 2, and then divide the 
coefficient by 2 (7/2).  And finally we add one to the exponent of x^0, so 
this will give us 1 and we divide 4 by 1.  So that we get apolynomial 
looking like this: (3/3)x^3 + (7/2)x^2 + (4/1)x  or better yet, x^3 + 
(7/2)x^2 + 4x.  My problem is, once I know the degree of my polynomial and 
the coefficients of my polynomial, how can I do all these operations?  My 
problem is representing rational numbers, ie,(7/2).  Because my result of 
this division is not an integer, I don't want Python to divide.  I want 
(3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left alone. 
  How can I do this?  Can anyone help?

Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From iamgod@st.jyu.fi  Wed May  2 18:11:11 2001
From: iamgod@st.jyu.fi (Risto Peranen)
Date: Wed, 2 May 2001 20:11:11 +0300 (EEST)
Subject: [Tutor] Dynamic web-pages and protected attributes
In-Reply-To: <E14ucaW-0002jF-00@mail.python.org>
Message-ID: <Pine.LNX.4.33.0105022005570.9041-100000@silmu.st.jyu.fi>

Well, I just a beginner in python.

Is it possible to make dynamic web-pages with python?
I have really had enough so called "hard" and "real" programming
and personally I think Java is nice but far too slow.

I'm also wondering is there any way to protect attributes in
python's classes. It would be nice to make safe classes for python.

class MyClass:
protected:
	#something nice and not so interesting for other users
public:
	#somethin public



Risto Peranen
040 756 94 12
iamgod@st.jyu.fi

"ihminen on lihaa, heikko ja katoavainen"
	- moos:6:3



From sheila@thinkspot.net  Wed May  2 18:17:37 2001
From: sheila@thinkspot.net (Sheila King)
Date: Wed, 02 May 2001 10:17:37 -0700
Subject: [Tutor] rational number representation in Python
In-Reply-To: <F150vJo9iiy6hBySBzC0000f53a@hotmail.com>
References: <F150vJo9iiy6hBySBzC0000f53a@hotmail.com>
Message-ID: <5B6B5744C4A@kserver.org>

On Wed, 02 May 2001 11:58:22 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com>  wrote about [Tutor] rational number
representation in Python:

:Because my result of 
:this division is not an integer, I don't want Python to divide.  I want 
:(3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left alone. 
:  How can I do this?  Can anyone help?

In comp.lang.python, there has been talk about an experimental number class
that includes rational numbers. (I don't remember the details right now.) You
could possibly use something like that.

Or, it might be instructive to write your own rational number class. For
reducing fractions, like 3/3 or even 9/3, etc... a useful algorithm is called
Euclid's Algorithm. You should be able to find the algorithm in a book on
algorithms fairly easily. It will find the GCF for you, then you can divide it
out of the numerator and denominator.

I would make a test, that whenever the denominator is 1, to just stop printing
it, and let the number be output as 4 instead of 4/1.

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



From kromag@nsacom.net  Wed May  2 22:43:20 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Wed, 2 May 2001 14:43:20 -0700 (PDT)
Subject: [Tutor] starting a tkinter window maximized
Message-ID: <200105022143.f42LhKo22431@pop.nsacom.net>

The subject pretty much says it all! How does one tell a tkinter window to 
start maximized in windows or X? 


From NHYTRO@compuserve.com  Wed May  2 23:33:11 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Wed, 2 May 2001 18:33:11 -0400
Subject: [Tutor] List problem
Message-ID: <200105021833_MC2-CEB3-D925@compuserve.com>

Hi all!

from my database per CGI I get this list:

allrows =3D [(1, 'sharriff', 'sh1', 'sharriff', 'admin',
'c:\\minics\\db\\users\\aina', 'template2', 'Aina Inc.', 'Gutenbergstr.
42', '41564', 'Kaarst', 'NRW', 'Germany', '02131- 3839- 412',
'02131-3839-599', '0177-12345678', 'sa@med-iq.de', '10.104.98.70', 'Mr.
Sharriff Aina', 'Aina', 'Home,Aktuelles,None')] =


I=B4ve coded a login script (CGI) that does a very simple comparism of fi=
elds
from the database with data captured from a form


### code start ###

 fields =3D allrows[0]
 if fields[3] =3D=3D usernamevalue and fields[4] =3D=3D passwordvalue :
.... print block1, # blocks of HTML code
.... print fields[18],
.... print block2
.... print usernamevalue,
 ....print block3
elif fields[3] !=3D usernamevalue and fields[4] !=3D passwordvalue :
 ....print errorpage

#### code end ####

the problem is, when correct values are entered in the form everything
works fine as soon as one enters a false password or false username I get=

this error

"Traceback (most recent call last):
  File "cgi-bin/login.cgi", line 119, in ?
    fields =3D allrows[0]
IndexError: list index out of range

If its out of range why does it work corretly when the data filled in is
correct? the mid boggling  X-files part of it is that it works when I
simulate this code in the Python console!!

Have I overlooked something? I thought it was due to fatigue yesterday, b=
ut
I couldn=B4t get it to budge today, its worn me out. =


Could someone throw me a life jacket? I=B4m just drifting here..


Thanks

Sharriff


From vlindberg@verio.net  Wed May  2 23:54:58 2001
From: vlindberg@verio.net (VanL)
Date: Wed, 02 May 2001 16:54:58 -0600
Subject: [Tutor] Moving email between servers
Message-ID: <3AF09042.8DCDF8E7@verio.net>

Hello,

I have got what is pretty simple problem conceptually, but I don't know
how to implement it.  I know that some of the semantics aren't quite
right -- that is OK.  I will note where the problems are.

(Pseudocode)

M1 = poplib.POP3('server1')
M2 = imaplib.IMAP4('server2')

M1.login(user,pass)
M2.login(user,pass)

folders = M1.listfolders()
^^^^^^^^^^^^^^^^^^^^^^^^^^
# Get a list of a folders
PROBLEM: I can't find out how to get the contents of anything but the
inbox.

for folder in folders:
	# create the folder on the new server
	M2.create(folder)

	# get all messages, move them to the new server
	numMsgs = len(M1.list()[1])
	for i in range(numMsgs):
		for j in M1.retr(i+1)[1]:
			M2.append(j)

M1.close()
M2.close()



Essentially, I want to recursively copy all mailfolders and messages
from one server to another.  I only have POP3 access to the first
server.

Any ideas?  I have looked at the poplib module, but I can't figure out
how to do it.

Thanks,

VanL


From julieta_rangel@hotmail.com  Thu May  3 01:17:11 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Wed, 02 May 2001 19:17:11 -0500
Subject: [Tutor] attaching the first element in a list to a string
Message-ID: <F271xqDCZx4FR0rmTIV0000c890@hotmail.com>

I have this problem.  I'm trying to write a program that calculates the 
integral of a polynomial.  This is what I have so far:

import string
class Poly:
    def __init__ ( self, v='x' , c = [0]):
        """__init__():
        Initializes a polynomial
        Default variable is x
        Default polynomial is zero"""
        self.var = v
        self.coef = c
        self.deg = len(c)-1
        self.length = len(c)
    def __str__ (self):
        """__str__():
        Converts a polynomial into a string"""
        x = `self.coef[0]`
        for i in range (1, self.deg+1):
            x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
        return x

class Poly2:
    def __init__ (self, v='x' , c = [0]):
        """__init__():
        Initializes a polynomial
        Default variable is x
        Default polynomial is zero"""
        self.var = v
        self.pc = c
        self.deg =len(c)-1
        self.length = len(c)
    def __str__(self):
        """__str__():
        Converts a second polynomial into a string"""
        x = `self.pc[0]`
        for i in range (0, self.deg+1):
            x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2`
        return x

def Integrate(p):
    """Input:  an instance of a polynommial
    Output: a polynomial that is the integral of the input polynomial
    Side Effects: None"""
    pv=p.var
    pc=[]
    for i in range(0,p.deg):
     	I=p.coef[i+1]/float(i+2)
      	pc.append(I)
    return Poly2 (v=pv,c=pc)


degree = input('Enter the degree of your polynomial')
coef=[]
for i in range (0,degree + 1):
    coefficient = input('Enter the coefficient for x^ %i ? ' %i)
    coef.append(coefficient)#attach the coefficient entered to the end of 
the
    #list named coef.


s= Poly (c = coef)
t= Integrate(s)
# This is some code to test new functions

print "The integral of %s is: \n %s" % (s,t)
print " "

My problem is that when I run it I get this:

>>>reload(poly1)
Enter the degree of your polynomial3
Enter the coefficient for x^ 0 ? 2
Enter the coefficient for x^ 1 ? 5
Enter the coefficient for x^ 2 ? 6
Enter the coefficient for x^ 3 ? 1
The integral of 2+5x^1+6x^2+1x^3 is:
2.5+2.5x^2+2.0x^3+0.25x^4

As you can see, the answer would be right if it weren't for the first term 
in the polynomial.  The first term should be a 2x, so the answer should look 
like this:  2x^1+2.5x^2+2x^3+0.25x^4.  Can anyone help me fix this problem?  
I think that I need to find a way to have the first term on the list labeled 
pc, which is 2 to be taken into consideration on the string representing the 
polynomial.  Am I right?  If so, How can I accomplish this?  Also, I need to 
find a way so that when the coefficient of x^0 ==0 , the output should 
display a constant c along with the result, so that the answer looks like 
c+2.5x^2+2x^3+0.23x^4.
Can anyone guide me in the right direction?  All inputs or comments about my 
program are welcomed and appreciated.

Julieta

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From vlindberg@verio.net  Thu May  3 01:28:29 2001
From: vlindberg@verio.net (VanL)
Date: Wed, 02 May 2001 18:28:29 -0600
Subject: [Tutor] Moving email between servers
References: <3AF09042.8DCDF8E7@verio.net>
Message-ID: <3AF0A62D.AF87F6E4@verio.net>

OK, after a little more research, the question has changed.

Evidently, there is no such thing as a POP3 "folder".  They are, as far
as the mail client is concerned, just a named local message store. 
Applications which support POP3 folders actually download the file, sort
it and store it locally.

However, the mail that I am interested in is still on a server.  (One
that supports "folders".)  Is there any way to specify which mailbox to
open?

Thanks,

VanL


From dyoo@hkn.eecs.berkeley.edu  Thu May  3 02:12:02 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 2 May 2001 18:12:02 -0700 (PDT)
Subject: [Tutor] List problem
In-Reply-To: <200105021833_MC2-CEB3-D925@compuserve.com>
Message-ID: <Pine.LNX.4.21.0105021734410.20865-100000@hkn.eecs.berkeley.edu>

On Wed, 2 May 2001, Sharriff Aina wrote:

> ### code start ###
> 
>  fields = allrows[0]
>  if fields[3] == usernamevalue and fields[4] == passwordvalue :
> .... print block1, # blocks of HTML code
> .... print fields[18],
> .... print block2
> .... print usernamevalue,
>  ....print block3
> elif fields[3] != usernamevalue and fields[4] != passwordvalue :
>  ....print errorpage
> 
> #### code end ####

It looks like this is code that you typed at the interpreter.  Is this the
same code you're using within the CGI script?



> the problem is, when correct values are entered in the form everything
> works fine as soon as one enters a false password or false username I get
> this error
> 
> "Traceback (most recent call last):
>   File "cgi-bin/login.cgi", line 119, in ?
>     fields = allrows[0]
> IndexError: list index out of range

I'm guessing that if they enter in a bad password or username, that the
allrows list is empty.  Can you show us the code that grabs allrows?  It
looks like you're doing a "SELECT" sql command to grab all the columns.  
However, if it can't find a person within the database, it should probably
return no rows at all.



> If its out of range why does it work corretly when the data filled in is
> correct? the mid boggling  X-files part of it is that it works when I
> simulate this code in the Python console!!

We'll need to see how you're assigning allrows. If the username/password's
misspelled, it looks like it won't be able to fetch any rows.  You code
probably needs to take care of this case; it can't immediately fetch the
first element of allrows.

Hope this helps!



From tbaruch@mindless.com  Thu May  3 02:30:08 2001
From: tbaruch@mindless.com (Timothy M. Brauch)
Date: Wed, 02 May 2001 21:30:08 -0400
Subject: [Tutor] Processor Simulator
Message-ID: <3AF0B4A0.7DC0E1B2@mindless.com>

I have a project for my comp-sci class.  I have to design a simulator
for a processor, and I've decided to use Python.  So, my question is,
does anyone have any suggestions as to how to go about doing this? 
Also, I have to write simple files and load them into my simulator.

My initial thoughts are to create a class with a bunch of function
definitions for different processes.  Such as add() and sub() and mul(),
etc.

I also have to have a display window showing register enteries, which
that I think I can do fairly easily.  I was thinking of using the latest
VPython which has a text function (I am doing this mostly because I have
no experience with TK, otherwise I would use it, but right now I don't
have the time to learn it).

As for the files, I would use something like readlines and string.split
to break up my commands kept in the external file.  I think I can handle
that as well.

If anyone has any suggestions or can offer any help, let me know.  I
feel like this might be one of the biggest projects I have undertaken so
far.

 - Tim


From bdupire@seatech.fau.edu  Thu May  3 02:33:02 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Wed, 02 May 2001 21:33:02 -0400
Subject: [Tutor] attaching the first element in a list to a string
References: <F271xqDCZx4FR0rmTIV0000c890@hotmail.com>
Message-ID: <3AF0B54E.EB0D53DC@seatech.fau.edu>

I modified your program in this way:

class Poly:
    def __init__ ( self, v='x' , c = [0]):
        """__init__():
        Initializes a polynomial
        Default variable is x
        Default polynomial is zero"""
        self.var = v
        self.coef = c
        self.deg = len(c)-1
        self.length = len(c)
    def __str__ (self):
        """__str__():
        Converts a polynomial into a string"""
        x = `self.coef[0]`
        for i in range (1, self.deg+1):
            x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
        return x


    def integrate(self):
        """Input:  an instance of a polynommial
        Output: a polynomial that is the integral of the input polynomial
        Side Effects: None"""

        coef=[0]
        self.deg= self.deg +1
        for i in range(0,self.deg):
            coef.append(self.coef[i]/float(i+1))
        self.coef= coef


degree = input('Enter the degree of your polynomial')
coef=[]
for i in range (0,degree + 1):
    coefficient = input('Enter the coefficient for x^ %i ? ' %i)
    coef.append(coefficient)

s= Poly (c = coef)




The result is now the good one:
>>> reload(poly)
Enter the degree of your polynomial3
Enter the coefficient for x^ 0 ? 2
Enter the coefficient for x^ 1 ? 5
Enter the coefficient for x^ 2 ? 6
Enter the coefficient for x^ 3 ? 1
<module 'poly' from 'C:\Python20\poly.py'>
>>> poly.s.integrate()
>>> print poly.s
0+2.0x^1+2.5x^2+2.0x^3+0.25x^4


What are the difference with your program?

integrate is now a method of the class Poly
so i can use it like this...

s= Poly( c=[1 5 6])            # here, we use __init__
print s                                # here we use __str__
s.integrate()                        # guess what ?

So the first argument of integrate() is now 'self' (the polynome itself)
I first increment the degree (because that's the definition of the integration
of a polynom)
The first coeff should normally be 'k', we need an initial condition to set it,
so for now i put 0
next coeff = coeff (degree 0) / (0+1)
next coeff = coeff (degree 1)/ (1+1)
etc...
When i have the new list of  coeff, i set it for the current polynom (
self.coef= coef)

You can also add your derivation function as a method, and use it like
s.derivate()

Benoit







Julieta Rangel wrote:

> I have this problem.  I'm trying to write a program that calculates the
> integral of a polynomial.  This is what I have so far:
>
> import string
> class Poly:
>     def __init__ ( self, v='x' , c = [0]):
>         """__init__():
>         Initializes a polynomial
>         Default variable is x
>         Default polynomial is zero"""
>         self.var = v
>         self.coef = c
>         self.deg = len(c)-1
>         self.length = len(c)
>     def __str__ (self):
>         """__str__():
>         Converts a polynomial into a string"""
>         x = `self.coef[0]`
>         for i in range (1, self.deg+1):
>             x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
>         return x
>
> class Poly2:
>     def __init__ (self, v='x' , c = [0]):
>         """__init__():
>         Initializes a polynomial
>         Default variable is x
>         Default polynomial is zero"""
>         self.var = v
>         self.pc = c
>         self.deg =len(c)-1
>         self.length = len(c)
>     def __str__(self):
>         """__str__():
>         Converts a second polynomial into a string"""
>         x = `self.pc[0]`
>         for i in range (0, self.deg+1):
>             x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2`
>         return x
>
> def Integrate(p):
>     """Input:  an instance of a polynommial
>     Output: a polynomial that is the integral of the input polynomial
>     Side Effects: None"""
>     pv=p.var
>     pc=[]
>     for i in range(0,p.deg):
>         I=p.coef[i+1]/float(i+2)
>         pc.append(I)
>     return Poly2 (v=pv,c=pc)
>
> degree = input('Enter the degree of your polynomial')
> coef=[]
> for i in range (0,degree + 1):
>     coefficient = input('Enter the coefficient for x^ %i ? ' %i)
>     coef.append(coefficient)#attach the coefficient entered to the end of
> the
>     #list named coef.
>
> s= Poly (c = coef)
> t= Integrate(s)
> # This is some code to test new functions
>
> print "The integral of %s is: \n %s" % (s,t)
> print " "
>
> My problem is that when I run it I get this:
>
> >>>reload(poly1)
> Enter the degree of your polynomial3
> Enter the coefficient for x^ 0 ? 2
> Enter the coefficient for x^ 1 ? 5
> Enter the coefficient for x^ 2 ? 6
> Enter the coefficient for x^ 3 ? 1
> The integral of 2+5x^1+6x^2+1x^3 is:
> 2.5+2.5x^2+2.0x^3+0.25x^4
>
> As you can see, the answer would be right if it weren't for the first term
> in the polynomial.  The first term should be a 2x, so the answer should look
> like this:  2x^1+2.5x^2+2x^3+0.25x^4.  Can anyone help me fix this problem?
> I think that I need to find a way to have the first term on the list labeled
> pc, which is 2 to be taken into consideration on the string representing the
> polynomial.  Am I right?  If so, How can I accomplish this?  Also, I need to
> find a way so that when the coefficient of x^0 ==0 , the output should
> display a constant c along with the result, so that the answer looks like
> c+2.5x^2+2x^3+0.23x^4.
> Can anyone guide me in the right direction?  All inputs or comments about my
> program are welcomed and appreciated.
>
> Julieta
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From sheila@thinkspot.net  Thu May  3 02:42:04 2001
From: sheila@thinkspot.net (Sheila King)
Date: Wed, 02 May 2001 18:42:04 -0700
Subject: [Tutor] attaching the first element in a list to a string
In-Reply-To: <F271xqDCZx4FR0rmTIV0000c890@hotmail.com>
References: <F271xqDCZx4FR0rmTIV0000c890@hotmail.com>
Message-ID: <17D48B13DC4@kserver.org>

On Wed, 02 May 2001 19:17:11 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com>  wrote about [Tutor] attaching the first element
in a list to a string:

:The integral of 2+5x^1+6x^2+1x^3 is:
:2.5+2.5x^2+2.0x^3+0.25x^4
:
:As you can see, the answer would be right if it weren't for the first term 
:in the polynomial.  The first term should be a 2x, so the answer should look 
:like this:  2x^1+2.5x^2+2x^3+0.25x^4.  Can anyone help me fix this problem?  
:I think that I need to find a way to have the first term on the list labeled 
:pc, which is 2 to be taken into consideration on the string representing the 
:polynomial.  Am I right?  If so, How can I accomplish this?  Also, I need to 
:find a way so that when the coefficient of x^0 ==0 , the output should 
:display a constant c along with the result, so that the answer looks like 
:c+2.5x^2+2x^3+0.23x^4.

I won't respond to the programming issues, since Benoit has already responded.
I'll wait and see if his help solves your problems.

But I'd like to address a math issue:
Shouldn't you have a +c constant added to your integral in *every* case? NOT
just when the coefficient of x^0 is equal to 0.

(BTW: the question is rhetorical. I KNOW that you *should* have it
there...typed the calculus teacher...)

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




From arazak@kansai.com.my  Thu May  3 04:07:54 2001
From: arazak@kansai.com.my (Mr. Razak)
Date: Thu, 3 May 2001 11:07:54 +0800
Subject: [Tutor] Few simple question.
Message-ID: <001501c0d37e$424a9ce0$6a01a8c0@com.my>

This is a multi-part message in MIME format.

------=_NextPart_000_0012_01C0D3C1.4D8B5660
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Actually I'm new in this language, so I really sorry if I'm asking a =
stupid question.

1). I want to know how to change colour, i mean how to used colour in =
python language.

2). How to used coordinate system, or may be there is a module i can =
used to help me. For example on the computer screen at a location =
row=3D5, column 35, I want to print 'Hello world'. How to do that.

3). How to create box and how place it on the computer screen on the =
desirerable location.

Thank's.

------=_NextPart_000_0012_01C0D3C1.4D8B5660
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D3>Actually I'm new in this language, so I =
really=20
sorry if I'm asking a stupid question.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D3>1). I want to know how to change =
colour, i mean how=20
to used colour in python language.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D3>2). How to used coordinate system, or =
may be there=20
is a module i can used to help me. For example on the computer screen at =
a=20
location row=3D5, column 35, I want to print 'Hello world'. How to do=20
that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D3>3). How to create box and how place it =
on the=20
computer screen on the desirerable location.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial>Thank's.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0012_01C0D3C1.4D8B5660--



From virketis@fas.harvard.edu  Thu May  3 04:43:21 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Wed, 02 May 2001 23:43:21 -0400
Subject: [Tutor] bizare Tkinter error
In-Reply-To: <E14uz3z-0004Zd-00@mail.python.org>
Message-ID: <200105030339.f433dFQ31313@smtp4.fas.harvard.edu>

I am writing a class assignment right now, and I have run into a most
peculiar bug. I know where it is, but I have absolutely no clue why it
occurs. Here is the relevant bit of my code:

class EditFrame:
    def __init__(self, master):
      ### Set up prompt frame, list frame, edit frame
        p_f = l_f = e_f = Frame(master)
                   <----- I assign all three frames simultaneously. This
will prove to be the 
        for f in [p_f, l_f, e_f]:						   <------ problematic bit.			
            f.pack()
     
##
Irrelevant stuff
##

	# Data entry loop : set up StringVars
        	self.name = self.wage_rate = self.ptd = StringVar()
        	Vars = [self.name, self.wage_rate, self.ptd]
        	Ques = ["Name: ", "Wage rate: ", "Amount paid to date: "]
        	Entries = []
        	# Data loop
          for position in range(len(Ques)):
            self.prompt = Label(e_f, text = Ques[position], font = "Arial
15", justify = "right")
            self.entry = Entry(e_f, width=20, font = "Arial 15",
textvariable = Vars[position])
            # Store Entry widgets in a list for future reference; nothing
else needs to be manipulated and thus is not saved
            Entries.append(self.entry)
            # Grid the the data loop widgets 
            self.prompt.grid(row = (position+1), column = 0)
            self.entry.grid(row = (position+1), column = 1)

If I run the code as is, the program crashes after cycling through the Data
loop (last loop in the snip). If I go back to the beginning, and explicitly
say

e_f  = Frame(master)

then the loop goes through just fine and does what it's supposed to do. For
the life of me, I cannot understand, why assigning the third frame together
with the first two would do this ... Perhaps I am missing something here?
BTW, I am using Python 2.1 with the latest Tkinter.

Thank you,  

Pijus


----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis.


From virketis@fas.harvard.edu  Thu May  3 05:06:23 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Thu, 03 May 2001 00:06:23 -0400
Subject: [Tutor] Few simple question
Message-ID: <200105030402.f4342IQ24037@smtp4.fas.harvard.edu>

--=====================_204520498==_.ALT
Content-Type: text/plain; charset="us-ascii"

All the tasks you described can be accomplished with a GUI creation module
called Tkinter, which interfaces to the Tk GUI library. A tutorial can by
found
here: http://www.pythonware.com/library/tkinter/introduction/. 

>1) I want to know how to change colour, i mean how to used colour in 
>python language.

Most Tkinter widgets take a argument  background or foreground. As in: 

label = Label(root, text="It's just an example", background = "red")

This will create a red field with the black letters "It's just an example" on
it.

>2). How to used coordinate system, or may be there is a module i can =
>used to help me. For example on the computer screen at a location =
>row=3D5, column 35, I want to print 'Hello world'. How to do that.

A widget called Canvas handles all the drawing in Tk. Here's the passage from
the tutorial about the coordinate system there:

"The Canvas widget uses two coordinate systems; the window coordinate system
(with (0, 0) in the upper left corner), and a canvas coordinate system in
which
the items are drawn. By scrolling the canvas, you can specify which part of
the
canvas coordinate system to show in the window."

If you just want to print things out on a screen, that's a bit different. You
can simple use the Label widget, as shown above, and then grid() it to your
needed location. So:

label = Label(root, text="Hello world", background = "red", font="Times 20")
label.grid(row=35, column=35)

>3). How to create box and how place it on the computer screen on the =
>desirerable location.

If you want to create a box, first you need to initialise a root window and
pack a Canvas widget in it:

root = Tk()
c = Canvas(root)
c.pack()

and then you can just create a box in your canvas:

c.create_rectangle(10,10,200,200, fill="red")

This will create a red rectange within the "box" of the specified size. In our
case, the rectangle and box are equivalent. But if you were creating an oval
shape, then the "box" would bound the oval's dimensions. 

Hope this helps.

Pijus 





----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis. 
--=====================_204520498==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
All the tasks you described can be accomplished with a GUI creation
module called Tkinter, which interfaces to the Tk GUI library. A tutorial
can by found here:
<a href="http://www.pythonware.com/library/tkinter/introduction/" eudora="autourl">http://www.pythonware.com/library/tkinter/introduction/</a>.
<br>
<br>
&gt;1) I want to know how to change colour, i mean how to used colour in
<br>
&gt;python language.<br>
<br>
Most Tkinter widgets take a argument&nbsp;
<font face="Courier New, Courier">background
</font>or<font face="Courier New, Courier"> foreground. </font>As
in:<font face="Courier New, Courier"> <br>
<br>
</font>label = Label(root, text=&quot;It's just an example&quot;,
background = &quot;red&quot;)<br>
<br>
This will create a red field with the black letters &quot;It's just an
example&quot; on it.<br>
<br>
&gt;2). How to used coordinate system, or may be there is a module i can
=<br>
&gt;used to help me. For example on the computer screen at a location
=<br>
&gt;row=3D5, column 35, I want to print 'Hello world'. How to do
that.<br>
<br>
A widget called Canvas handles all the drawing in Tk. Here's the passage
from the tutorial about the coordinate system there:<br>
<br>
&quot;The <font face="Courier New, Courier">Canvas widget uses two
coordinate systems; the window coordinate system (with (0, 0) in the
upper left corner), and a canvas coordinate system in which the items are
drawn. By scrolling the canvas, you can specify which part of the canvas
coordinate system to show in the window.</font>&quot;<br>
<br>
If you just want to print things out on a screen, that's a bit different.
You can simple use the Label widget, as shown above, and then grid() it
to your needed location. So:<br>
<br>
label = Label(root, text=&quot;Hello world&quot;, background =
&quot;red&quot;, font=&quot;Times 20&quot;)<br>
label.grid(row=35, column=35)<br>
<br>
&gt;3). How to create box and how place it on the computer screen on the
=<br>
&gt;desirerable location.<br>
<br>
If you want to create a box, first you need to initialise a root window
and pack a Canvas widget in it:<br>
<br>
root = Tk()<br>
c = Canvas(root)<br>
c.pack()<br>
<br>
and then you can just create a box in your canvas:<br>
<br>
c.create_rectangle(10,10,200,200, fill=&quot;red&quot;)<br>
<br>
This will create a red rectange within the &quot;box&quot; of the
specified size. In our case, the rectangle and box are equivalent. But if
you were creating an oval shape, then the &quot;box&quot; would bound the
oval's dimensions. <br>
<br>
Hope this helps.<br>
<br>
Pijus <br>
<br>
<br>
<br>
<br>
<br>
<div>-----------------------------------------------------------------------------------------------</div>
Please have a look at my weblog at
<a href="http://www.fas.harvard.edu/~virketis" EUDORA=AUTOURL>www.fas.harvard.edu/~virketis</a>.
</html>

--=====================_204520498==_.ALT--



From julieta_rangel@hotmail.com  Thu May  3 05:08:42 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Wed, 02 May 2001 23:08:42 -0500
Subject: [Tutor] attaching the first element in a list to a string
Message-ID: <F11U2gOHpM2yqOX9kOS0000074a@hotmail.com>

This modification to the program works well in calculating the integral, but 
it does not print it out when running the program.  When you inputed 
poly.s.integrate() followed by print poly.s (In Python Shell), the integral 
is printed.  What command should we include in the program to make it print 
out automatically while running it.  If I include these commands in the 
actual program, they don't work as they do in Python Shell.

Thanks for your help.

Julieta


>From: Benoit Dupire <bdupire@seatech.fau.edu>
>To: Julieta Rangel <julieta_rangel@hotmail.com>
>CC: tutor@python.org
>Subject: Re: [Tutor] attaching the first element in a list to a string
>Date: Wed, 02 May 2001 21:33:02 -0400
>
>I modified your program in this way:
>
>class Poly:
>     def __init__ ( self, v='x' , c = [0]):
>         """__init__():
>         Initializes a polynomial
>         Default variable is x
>         Default polynomial is zero"""
>         self.var = v
>         self.coef = c
>         self.deg = len(c)-1
>         self.length = len(c)
>     def __str__ (self):
>         """__str__():
>         Converts a polynomial into a string"""
>         x = `self.coef[0]`
>         for i in range (1, self.deg+1):
>             x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
>         return x
>
>
>     def integrate(self):
>         """Input:  an instance of a polynommial
>         Output: a polynomial that is the integral of the input polynomial
>         Side Effects: None"""
>
>         coef=[0]
>         self.deg= self.deg +1
>         for i in range(0,self.deg):
>             coef.append(self.coef[i]/float(i+1))
>         self.coef= coef
>
>
>degree = input('Enter the degree of your polynomial')
>coef=[]
>for i in range (0,degree + 1):
>     coefficient = input('Enter the coefficient for x^ %i ? ' %i)
>     coef.append(coefficient)
>
>s= Poly (c = coef)
>
>
>
>
>The result is now the good one:
> >>> reload(poly)
>Enter the degree of your polynomial3
>Enter the coefficient for x^ 0 ? 2
>Enter the coefficient for x^ 1 ? 5
>Enter the coefficient for x^ 2 ? 6
>Enter the coefficient for x^ 3 ? 1
><module 'poly' from 'C:\Python20\poly.py'>
> >>> poly.s.integrate()
> >>> print poly.s
>0+2.0x^1+2.5x^2+2.0x^3+0.25x^4
>
>
>What are the difference with your program?
>
>integrate is now a method of the class Poly
>so i can use it like this...
>
>s= Poly( c=[1 5 6])            # here, we use __init__
>print s                                # here we use __str__
>s.integrate()                        # guess what ?
>
>So the first argument of integrate() is now 'self' (the polynome itself)
>I first increment the degree (because that's the definition of the 
>integration
>of a polynom)
>The first coeff should normally be 'k', we need an initial condition to set 
>it,
>so for now i put 0
>next coeff = coeff (degree 0) / (0+1)
>next coeff = coeff (degree 1)/ (1+1)
>etc...
>When i have the new list of  coeff, i set it for the current polynom (
>self.coef= coef)
>
>You can also add your derivation function as a method, and use it like
>s.derivate()
>
>Benoit
>
>
>
>
>
>
>
>Julieta Rangel wrote:
>
> > I have this problem.  I'm trying to write a program that calculates the
> > integral of a polynomial.  This is what I have so far:
> >
> > import string
> > class Poly:
> >     def __init__ ( self, v='x' , c = [0]):
> >         """__init__():
> >         Initializes a polynomial
> >         Default variable is x
> >         Default polynomial is zero"""
> >         self.var = v
> >         self.coef = c
> >         self.deg = len(c)-1
> >         self.length = len(c)
> >     def __str__ (self):
> >         """__str__():
> >         Converts a polynomial into a string"""
> >         x = `self.coef[0]`
> >         for i in range (1, self.deg+1):
> >             x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
> >         return x
> >
> > class Poly2:
> >     def __init__ (self, v='x' , c = [0]):
> >         """__init__():
> >         Initializes a polynomial
> >         Default variable is x
> >         Default polynomial is zero"""
> >         self.var = v
> >         self.pc = c
> >         self.deg =len(c)-1
> >         self.length = len(c)
> >     def __str__(self):
> >         """__str__():
> >         Converts a second polynomial into a string"""
> >         x = `self.pc[0]`
> >         for i in range (0, self.deg+1):
> >             x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2`
> >         return x
> >
> > def Integrate(p):
> >     """Input:  an instance of a polynommial
> >     Output: a polynomial that is the integral of the input polynomial
> >     Side Effects: None"""
> >     pv=p.var
> >     pc=[]
> >     for i in range(0,p.deg):
> >         I=p.coef[i+1]/float(i+2)
> >         pc.append(I)
> >     return Poly2 (v=pv,c=pc)
> >
> > degree = input('Enter the degree of your polynomial')
> > coef=[]
> > for i in range (0,degree + 1):
> >     coefficient = input('Enter the coefficient for x^ %i ? ' %i)
> >     coef.append(coefficient)#attach the coefficient entered to the end 
>of
> > the
> >     #list named coef.
> >
> > s= Poly (c = coef)
> > t= Integrate(s)
> > # This is some code to test new functions
> >
> > print "The integral of %s is: \n %s" % (s,t)
> > print " "
> >
> > My problem is that when I run it I get this:
> >
> > >>>reload(poly1)
> > Enter the degree of your polynomial3
> > Enter the coefficient for x^ 0 ? 2
> > Enter the coefficient for x^ 1 ? 5
> > Enter the coefficient for x^ 2 ? 6
> > Enter the coefficient for x^ 3 ? 1
> > The integral of 2+5x^1+6x^2+1x^3 is:
> > 2.5+2.5x^2+2.0x^3+0.25x^4
> >
> > As you can see, the answer would be right if it weren't for the first 
>term
> > in the polynomial.  The first term should be a 2x, so the answer should 
>look
> > like this:  2x^1+2.5x^2+2x^3+0.25x^4.  Can anyone help me fix this 
>problem?
> > I think that I need to find a way to have the first term on the list 
>labeled
> > pc, which is 2 to be taken into consideration on the string representing 
>the
> > polynomial.  Am I right?  If so, How can I accomplish this?  Also, I 
>need to
> > find a way so that when the coefficient of x^0 ==0 , the output should
> > display a constant c along with the result, so that the answer looks 
>like
> > c+2.5x^2+2x^3+0.23x^4.
> > Can anyone guide me in the right direction?  All inputs or comments 
>about my
> > program are welcomed and appreciated.
> >
> > Julieta
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at http://explorer.msn.com
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>--
>Benoit Dupire
>Graduate Student
>----------------
>I'd like to buy a new Boomerang. How can i get rid of the old one?
>
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From bdupire@seatech.fau.edu  Thu May  3 05:44:25 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Thu, 03 May 2001 00:44:25 -0400
Subject: [Tutor] attaching the first element in a list to a string
References: <F11U2gOHpM2yqOX9kOS0000074a@hotmail.com>
Message-ID: <3AF0E228.B2D89B02@seatech.fau.edu>


Julieta Rangel wrote:

> This modification to the program works well in calculating the integral, but
> it does not print it out when running the program.  When you inputed
> poly.s.integrate() followed by print poly.s (In Python Shell), the integral
> is printed.  What command should we include in the program to make it print
> out automatically while running it.  If I include these commands in the
> actual program, they don't work as they do in Python Shell.

s is a Poly object defined in the 'poly' module, and s has a method called
'integrate'.
so to access s.integrate()  from the interpreter, i input
import poly                # this executes all the code in poly.py, and
therefore creates 's'
poly.s.integrate()
I do not need the 'poly.' part  if i want to refer the object from  the module
it lives in.


read my previous message carefully. The answer to your question was in there...

>integrate is now a method of the class Poly
>so i can use it like this...
>
>s= Poly( c=[1 5 6])            # here, we use __init__
>print s                                # here we use __str__
>s.integrate()                        # guess what ?

I advise you to read the Python tutorial (especially the part dealing with
modules) and/or the book called 'Learning Python', so that you can progress more
rapidly in Python.

Benoit



>
>
> Thanks for your help.
>
> Julieta
>
> >From: Benoit Dupire <bdupire@seatech.fau.edu>
> >To: Julieta Rangel <julieta_rangel@hotmail.com>
> >CC: tutor@python.org
> >Subject: Re: [Tutor] attaching the first element in a list to a string
> >Date: Wed, 02 May 2001 21:33:02 -0400
> >
> >I modified your program in this way:
> >
> >class Poly:
> >     def __init__ ( self, v='x' , c = [0]):
> >         """__init__():
> >         Initializes a polynomial
> >         Default variable is x
> >         Default polynomial is zero"""
> >         self.var = v
> >         self.coef = c
> >         self.deg = len(c)-1
> >         self.length = len(c)
> >     def __str__ (self):
> >         """__str__():
> >         Converts a polynomial into a string"""
> >         x = `self.coef[0]`
> >         for i in range (1, self.deg+1):
> >             x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
> >         return x
> >
> >
> >     def integrate(self):
> >         """Input:  an instance of a polynommial
> >         Output: a polynomial that is the integral of the input polynomial
> >         Side Effects: None"""
> >
> >         coef=[0]
> >         self.deg= self.deg +1
> >         for i in range(0,self.deg):
> >             coef.append(self.coef[i]/float(i+1))
> >         self.coef= coef
> >
> >
> >degree = input('Enter the degree of your polynomial')
> >coef=[]
> >for i in range (0,degree + 1):
> >     coefficient = input('Enter the coefficient for x^ %i ? ' %i)
> >     coef.append(coefficient)
> >
> >s= Poly (c = coef)
> >
> >
> >
> >
> >The result is now the good one:
> > >>> reload(poly)
> >Enter the degree of your polynomial3
> >Enter the coefficient for x^ 0 ? 2
> >Enter the coefficient for x^ 1 ? 5
> >Enter the coefficient for x^ 2 ? 6
> >Enter the coefficient for x^ 3 ? 1
> ><module 'poly' from 'C:\Python20\poly.py'>
> > >>> poly.s.integrate()
> > >>> print poly.s
> >0+2.0x^1+2.5x^2+2.0x^3+0.25x^4
> >
> >
> >What are the difference with your program?
> >
> >integrate is now a method of the class Poly
> >so i can use it like this...
> >
> >s= Poly( c=[1 5 6])            # here, we use __init__
> >print s                                # here we use __str__
> >s.integrate()                        # guess what ?
> >
> >So the first argument of integrate() is now 'self' (the polynome itself)
> >I first increment the degree (because that's the definition of the
> >integration
> >of a polynom)
> >The first coeff should normally be 'k', we need an initial condition to set
> >it,
> >so for now i put 0
> >next coeff = coeff (degree 0) / (0+1)
> >next coeff = coeff (degree 1)/ (1+1)
> >etc...
> >When i have the new list of  coeff, i set it for the current polynom (
> >self.coef= coef)
> >
> >You can also add your derivation function as a method, and use it like
> >s.derivate()
> >
> >Benoit
> >
> >
> >
> >
> >
> >
> >
> >Julieta Rangel wrote:
> >
> > > I have this problem.  I'm trying to write a program that calculates the
> > > integral of a polynomial.  This is what I have so far:
> > >
> > > import string
> > > class Poly:
> > >     def __init__ ( self, v='x' , c = [0]):
> > >         """__init__():
> > >         Initializes a polynomial
> > >         Default variable is x
> > >         Default polynomial is zero"""
> > >         self.var = v
> > >         self.coef = c
> > >         self.deg = len(c)-1
> > >         self.length = len(c)
> > >     def __str__ (self):
> > >         """__str__():
> > >         Converts a polynomial into a string"""
> > >         x = `self.coef[0]`
> > >         for i in range (1, self.deg+1):
> > >             x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
> > >         return x
> > >
> > > class Poly2:
> > >     def __init__ (self, v='x' , c = [0]):
> > >         """__init__():
> > >         Initializes a polynomial
> > >         Default variable is x
> > >         Default polynomial is zero"""
> > >         self.var = v
> > >         self.pc = c
> > >         self.deg =len(c)-1
> > >         self.length = len(c)
> > >     def __str__(self):
> > >         """__str__():
> > >         Converts a second polynomial into a string"""
> > >         x = `self.pc[0]`
> > >         for i in range (0, self.deg+1):
> > >             x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2`
> > >         return x
> > >
> > > def Integrate(p):
> > >     """Input:  an instance of a polynommial
> > >     Output: a polynomial that is the integral of the input polynomial
> > >     Side Effects: None"""
> > >     pv=p.var
> > >     pc=[]
> > >     for i in range(0,p.deg):
> > >         I=p.coef[i+1]/float(i+2)
> > >         pc.append(I)
> > >     return Poly2 (v=pv,c=pc)
> > >
> > > degree = input('Enter the degree of your polynomial')
> > > coef=[]
> > > for i in range (0,degree + 1):
> > >     coefficient = input('Enter the coefficient for x^ %i ? ' %i)
> > >     coef.append(coefficient)#attach the coefficient entered to the end
> >of
> > > the
> > >     #list named coef.
> > >
> > > s= Poly (c = coef)
> > > t= Integrate(s)
> > > # This is some code to test new functions
> > >
> > > print "The integral of %s is: \n %s" % (s,t)
> > > print " "
> > >
> > > My problem is that when I run it I get this:
> > >
> > > >>>reload(poly1)
> > > Enter the degree of your polynomial3
> > > Enter the coefficient for x^ 0 ? 2
> > > Enter the coefficient for x^ 1 ? 5
> > > Enter the coefficient for x^ 2 ? 6
> > > Enter the coefficient for x^ 3 ? 1
> > > The integral of 2+5x^1+6x^2+1x^3 is:
> > > 2.5+2.5x^2+2.0x^3+0.25x^4
> > >
> > > As you can see, the answer would be right if it weren't for the first
> >term
> > > in the polynomial.  The first term should be a 2x, so the answer should
> >look
> > > like this:  2x^1+2.5x^2+2x^3+0.25x^4.  Can anyone help me fix this
> >problem?
> > > I think that I need to find a way to have the first term on the list
> >labeled
> > > pc, which is 2 to be taken into consideration on the string representing
> >the
> > > polynomial.  Am I right?  If so, How can I accomplish this?  Also, I
> >need to
> > > find a way so that when the coefficient of x^0 ==0 , the output should
> > > display a constant c along with the result, so that the answer looks
> >like
> > > c+2.5x^2+2x^3+0.23x^4.
> > > Can anyone guide me in the right direction?  All inputs or comments
> >about my
> > > program are welcomed and appreciated.
> > >
> > > Julieta
> > >
> > > _________________________________________________________________
> > > Get your FREE download of MSN Explorer at http://explorer.msn.com
> > >
> > > _______________________________________________
> > > Tutor maillist  -  Tutor@python.org
> > > http://mail.python.org/mailman/listinfo/tutor
> >
> >--
> >Benoit Dupire
> >Graduate Student
> >----------------
> >I'd like to buy a new Boomerang. How can i get rid of the old one?
> >
> >
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From bsass@freenet.edmonton.ab.ca  Thu May  3 07:03:25 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Thu, 3 May 2001 00:03:25 -0600 (MDT)
Subject: [Tutor] Few simple question.
In-Reply-To: <001501c0d37e$424a9ce0$6a01a8c0@com.my>
Message-ID: <Pine.LNX.4.33.0105022332350.831-100000@bms>

On Thu, 3 May 2001, Mr. Razak wrote:

> Actually I'm new in this language, so I really sorry if I'm asking a stupid question.

Python itself does not include commands for this sorta thing, but
there are a lot of modules to handle whatever type of display you
need.

> 1). I want to know how to change colour, i mean how to used colour in python language.
>
> 2). How to used coordinate system, or may be there is a module i can used to help me. For example on the computer screen at a location row=5, column 35, I want to print 'Hello world'. How to do that.
>
> 3). How to create box and how place it on the computer screen on the desirerable location.

Hmmm, are you referring to a text display?
If so,
you can get python bindings for S-LANG...
http://packages.debian.org/unstable/interpreters/python-slang.html
...newt...
http://packages.debian.org/unstable/interpreters/python-newt.html
...and ncurses...
http://packages.debian.org/unstable/interpreters/pyncurses.html

These URLs will take you the Debian package pages, which contain links
to the original source tarballs.  I'm pointing you to "unstable",
refers only to Debian's binary packages, because that should be the
most recent source releases; you could use "testing" or "stable",
which may get you older releases of the source.

S-LANG is good for unix and win32, I'm not sure about the others.
ncurses is packaged with the most recent Python release (2.1).

HTH


- Bruce



From julieta_rangel@hotmail.com  Thu May  3 07:14:54 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Thu, 03 May 2001 01:14:54 -0500
Subject: [Tutor] attaching the first element in a list to a string
Message-ID: <F6xLDp7mvjkO22ZhCl800000867@hotmail.com>

I feel like an idiot.  Either I'm really tired, or there's something wrong 
with me.  I've been staring at the reply to my question and I still don't 
see what you are talking about.  At the end of the program, am I supposed to 
write
import poly
s.integrate()
print s   ??

I am thankful for all your help.

Julieta


>From: Benoit Dupire <bdupire@seatech.fau.edu>
>To: Julieta Rangel <julieta_rangel@hotmail.com>
>CC: tutor@python.org
>Subject: Re: [Tutor] attaching the first element in a list to a string
>Date: Thu, 03 May 2001 00:44:25 -0400
>
>
>
>Julieta Rangel wrote:
>
> > This modification to the program works well in calculating the integral, 
>but
> > it does not print it out when running the program.  When you inputed
> > poly.s.integrate() followed by print poly.s (In Python Shell), the 
>integral
> > is printed.  What command should we include in the program to make it 
>print
> > out automatically while running it.  If I include these commands in the
> > actual program, they don't work as they do in Python Shell.
>
>s is a Poly object defined in the 'poly' module, and s has a method called
>'integrate'.
>so to access s.integrate()  from the interpreter, i input
>import poly                # this executes all the code in poly.py, and
>therefore creates 's'
>poly.s.integrate()
>I do not need the 'poly.' part  if i want to refer the object from  the 
>module
>it lives in.
>
>
>read my previous message carefully. The answer to your question was in 
>there...
>
> >integrate is now a method of the class Poly
> >so i can use it like this...
> >
> >s= Poly( c=[1 5 6])            # here, we use __init__
> >print s                                # here we use __str__
> >s.integrate()                        # guess what ?
>
>I advise you to read the Python tutorial (especially the part dealing with
>modules) and/or the book called 'Learning Python', so that you can progress 
>more
>rapidly in Python.
>
>Benoit
>
>
>
> >
> >
> > Thanks for your help.
> >
> > Julieta
> >
> > >From: Benoit Dupire <bdupire@seatech.fau.edu>
> > >To: Julieta Rangel <julieta_rangel@hotmail.com>
> > >CC: tutor@python.org
> > >Subject: Re: [Tutor] attaching the first element in a list to a string
> > >Date: Wed, 02 May 2001 21:33:02 -0400
> > >
> > >I modified your program in this way:
> > >
> > >class Poly:
> > >     def __init__ ( self, v='x' , c = [0]):
> > >         """__init__():
> > >         Initializes a polynomial
> > >         Default variable is x
> > >         Default polynomial is zero"""
> > >         self.var = v
> > >         self.coef = c
> > >         self.deg = len(c)-1
> > >         self.length = len(c)
> > >     def __str__ (self):
> > >         """__str__():
> > >         Converts a polynomial into a string"""
> > >         x = `self.coef[0]`
> > >         for i in range (1, self.deg+1):
> > >             x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
> > >         return x
> > >
> > >
> > >     def integrate(self):
> > >         """Input:  an instance of a polynommial
> > >         Output: a polynomial that is the integral of the input 
>polynomial
> > >         Side Effects: None"""
> > >
> > >         coef=[0]
> > >         self.deg= self.deg +1
> > >         for i in range(0,self.deg):
> > >             coef.append(self.coef[i]/float(i+1))
> > >         self.coef= coef
> > >
> > >
> > >degree = input('Enter the degree of your polynomial')
> > >coef=[]
> > >for i in range (0,degree + 1):
> > >     coefficient = input('Enter the coefficient for x^ %i ? ' %i)
> > >     coef.append(coefficient)
> > >
> > >s= Poly (c = coef)
> > >
> > >
> > >
> > >
> > >The result is now the good one:
> > > >>> reload(poly)
> > >Enter the degree of your polynomial3
> > >Enter the coefficient for x^ 0 ? 2
> > >Enter the coefficient for x^ 1 ? 5
> > >Enter the coefficient for x^ 2 ? 6
> > >Enter the coefficient for x^ 3 ? 1
> > ><module 'poly' from 'C:\Python20\poly.py'>
> > > >>> poly.s.integrate()
> > > >>> print poly.s
> > >0+2.0x^1+2.5x^2+2.0x^3+0.25x^4
> > >
> > >
> > >What are the difference with your program?
> > >
> > >integrate is now a method of the class Poly
> > >so i can use it like this...
> > >
> > >s= Poly( c=[1 5 6])            # here, we use __init__
> > >print s                                # here we use __str__
> > >s.integrate()                        # guess what ?
> > >
> > >So the first argument of integrate() is now 'self' (the polynome 
>itself)
> > >I first increment the degree (because that's the definition of the
> > >integration
> > >of a polynom)
> > >The first coeff should normally be 'k', we need an initial condition to 
>set
> > >it,
> > >so for now i put 0
> > >next coeff = coeff (degree 0) / (0+1)
> > >next coeff = coeff (degree 1)/ (1+1)
> > >etc...
> > >When i have the new list of  coeff, i set it for the current polynom (
> > >self.coef= coef)
> > >
> > >You can also add your derivation function as a method, and use it like
> > >s.derivate()
> > >
> > >Benoit
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >Julieta Rangel wrote:
> > >
> > > > I have this problem.  I'm trying to write a program that calculates 
>the
> > > > integral of a polynomial.  This is what I have so far:
> > > >
> > > > import string
> > > > class Poly:
> > > >     def __init__ ( self, v='x' , c = [0]):
> > > >         """__init__():
> > > >         Initializes a polynomial
> > > >         Default variable is x
> > > >         Default polynomial is zero"""
> > > >         self.var = v
> > > >         self.coef = c
> > > >         self.deg = len(c)-1
> > > >         self.length = len(c)
> > > >     def __str__ (self):
> > > >         """__str__():
> > > >         Converts a polynomial into a string"""
> > > >         x = `self.coef[0]`
> > > >         for i in range (1, self.deg+1):
> > > >             x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
> > > >         return x
> > > >
> > > > class Poly2:
> > > >     def __init__ (self, v='x' , c = [0]):
> > > >         """__init__():
> > > >         Initializes a polynomial
> > > >         Default variable is x
> > > >         Default polynomial is zero"""
> > > >         self.var = v
> > > >         self.pc = c
> > > >         self.deg =len(c)-1
> > > >         self.length = len(c)
> > > >     def __str__(self):
> > > >         """__str__():
> > > >         Converts a second polynomial into a string"""
> > > >         x = `self.pc[0]`
> > > >         for i in range (0, self.deg+1):
> > > >             x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2`
> > > >         return x
> > > >
> > > > def Integrate(p):
> > > >     """Input:  an instance of a polynommial
> > > >     Output: a polynomial that is the integral of the input 
>polynomial
> > > >     Side Effects: None"""
> > > >     pv=p.var
> > > >     pc=[]
> > > >     for i in range(0,p.deg):
> > > >         I=p.coef[i+1]/float(i+2)
> > > >         pc.append(I)
> > > >     return Poly2 (v=pv,c=pc)
> > > >
> > > > degree = input('Enter the degree of your polynomial')
> > > > coef=[]
> > > > for i in range (0,degree + 1):
> > > >     coefficient = input('Enter the coefficient for x^ %i ? ' %i)
> > > >     coef.append(coefficient)#attach the coefficient entered to the 
>end
> > >of
> > > > the
> > > >     #list named coef.
> > > >
> > > > s= Poly (c = coef)
> > > > t= Integrate(s)
> > > > # This is some code to test new functions
> > > >
> > > > print "The integral of %s is: \n %s" % (s,t)
> > > > print " "
> > > >
> > > > My problem is that when I run it I get this:
> > > >
> > > > >>>reload(poly1)
> > > > Enter the degree of your polynomial3
> > > > Enter the coefficient for x^ 0 ? 2
> > > > Enter the coefficient for x^ 1 ? 5
> > > > Enter the coefficient for x^ 2 ? 6
> > > > Enter the coefficient for x^ 3 ? 1
> > > > The integral of 2+5x^1+6x^2+1x^3 is:
> > > > 2.5+2.5x^2+2.0x^3+0.25x^4
> > > >
> > > > As you can see, the answer would be right if it weren't for the 
>first
> > >term
> > > > in the polynomial.  The first term should be a 2x, so the answer 
>should
> > >look
> > > > like this:  2x^1+2.5x^2+2x^3+0.25x^4.  Can anyone help me fix this
> > >problem?
> > > > I think that I need to find a way to have the first term on the list
> > >labeled
> > > > pc, which is 2 to be taken into consideration on the string 
>representing
> > >the
> > > > polynomial.  Am I right?  If so, How can I accomplish this?  Also, I
> > >need to
> > > > find a way so that when the coefficient of x^0 ==0 , the output 
>should
> > > > display a constant c along with the result, so that the answer looks
> > >like
> > > > c+2.5x^2+2x^3+0.23x^4.
> > > > Can anyone guide me in the right direction?  All inputs or comments
> > >about my
> > > > program are welcomed and appreciated.
> > > >
> > > > Julieta
> > > >
> > > > _________________________________________________________________
> > > > Get your FREE download of MSN Explorer at http://explorer.msn.com
> > > >
> > > > _______________________________________________
> > > > Tutor maillist  -  Tutor@python.org
> > > > http://mail.python.org/mailman/listinfo/tutor
> > >
> > >--
> > >Benoit Dupire
> > >Graduate Student
> > >----------------
> > >I'd like to buy a new Boomerang. How can i get rid of the old one?
> > >
> > >
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at http://explorer.msn.com
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>--
>Benoit Dupire
>Graduate Student
>----------------
>I'd like to buy a new Boomerang. How can i get rid of the old one?
>
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From dyoo@hkn.eecs.berkeley.edu  Thu May  3 08:57:36 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 3 May 2001 00:57:36 -0700 (PDT)
Subject: [Tutor] List problem
In-Reply-To: <200105030339_MC2-CEC3-743D@compuserve.com>
Message-ID: <Pine.LNX.4.21.0105030046570.26492-100000@hkn.eecs.berkeley.edu>

On Thu, 3 May 2001, Sharriff Aina wrote:

> Thanks Mr. Yoo for replying

You don't need to call me Mr. Yoo; just Danny is fine for me.  (Plus, if
you saw me, I'm definitely not a "Mr." quite yet.  *grin*)


> connection = odbc.odbc('minicms')
> cur = connection.cursor()
> cur.execute("select * from users where username='%s' and userpwd='%s'"
> %(usernamevalue,passwordvalue))
> allrows = cur.fetchall()

Ah!  But what happens if the user DID misspell either their username or
password?  In SQL, this means that the result set should be of length 0,
because it can't find a user with those qualities.  Let's check the
documentation:

    http://python.org/topics/database/DatabaseAPI-2.0.html

According to the docs:

    "fetchall(): Fetch all (remaining) rows of a query result, returning
    them as a sequence of sequences (e.g. a list of tuples). Note that the
    cursor's arraysize attribute can affect the performance of this
    operation.

    An Error (or subclass) exception is raised if the previous call to
    executeXXX() did not produce any result set or no call was issued
    yet."

Since we aren't getting an exception out of the system, we'll need to
assume that we got an empty result set from the fetchall() instead.  It
appears that the database found no matches for the query, so it assigned

     allrows = []

Can you verify this?  You might want to add a check like:

###
    if allrows == []:
        # output something about "Incorrect password or username.  Try
        # again"
    else:
        # now it's ok to start indicing allrows[0].
###

right before you start indexing your allrows; we can't be certain that
allrows[0] works until we check to see that we have at least one tuple in
the list.  Afterwards, it should be ok to check for allrows[0].

Try it out, and see if this is the bug that you're running into.  If so,
it should be fairly easy to fix.

Good luck!



From julieta_rangel@hotmail.com  Thu May  3 08:59:00 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Thu, 03 May 2001 02:59:00 -0500
Subject: [Tutor] multiplication of polynomials in Python
Message-ID: <F242HvoFOAmEaJswFCH00000401@hotmail.com>

I got the integration and differentiation programs to work.  Right now I'm 
working on multiplication of polynomials.  This is what I have so far:
class Poly:
    def __init__ ( self, v=m , c = [0]):
        """__init__():
        Initializes a polynomial
        variable is m
        Default polynomial is zero"""
        self.var = v
        self.coef = c
        self.deg = len(c)-1
        self.length = len(c)
    def __str__ (self):
        """__str__():
        Converts a polynomial into a string"""
        x = `self.coef[0]`
        for i in range (1, self.deg+1):
            x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
        return x

    def Multiply(self):
    """Input: two instances of a polynomial
    Output: a polynomial that is the product of the input polynomials
    Side Effects: None"""
    coef=[0]
    coef2=[0]
    self.deg = self.deg +1
    for i in range(0,self.deg +1):
        coef.append(


m = input('Enter the variable for polynomial1')
degree = input('Enter the degree of polynomial 1')
coef=[]
for i in range (0,degree + 1):
    coefficient = input('Enter the coefficient for %s \n ^ %i ? ' %(m,i)
    coef.append(coefficient)


m = input('Enter the variable for polynomial 2')
degree = input('Enter the degree of polynomial 2')
coef2=[]
for i in range (0,degree + 1):
    coefficient = input('Enter the coefficient for %s \n ^ %i ? ' %(m,i)
    coef.append(coefficient)

Am I headed in the right direction?  What do you think about what I have so 
far?  I'm trying to come up with the definition of multiply, but I'm stuck.  
Can anyone help?  If you have any comments or suggestions I'm all ears.  By 
the way, thank you everyone for all the help I've received from all of you.  
Eventhough I still have a VERY LONG way to go, I feel I've learned so much 
from you.  Thank you for sharing your knowledge :)

Julieta

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From dyoo@hkn.eecs.berkeley.edu  Thu May  3 09:09:32 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 3 May 2001 01:09:32 -0700 (PDT)
Subject: [Tutor] FieldStorage solution summary
In-Reply-To: <200105021238.IAA03791@birds.us.itd.umich.edu>
Message-ID: <Pine.LNX.4.21.0105030100130.26492-100000@hkn.eecs.berkeley.edu>

On Wed, 2 May 2001, Lance E Sloan wrote:

> Daniel Yoo wrote:
> > I'm not sure if dictcat() should have to worry about non-dictionaries; it
> > might be better off giving a message that dictcat() needs to take a
> > dictonary-like object; otherwise, it might obscure some errors that the
> > programmer might forget to check.
> 
> I admit the name of the function might be misleading, but its
> primary purpose in life is to convert FieldStorage to dictionary.
> Do you mean that I should split this into two functions, one for
> converting FieldStorage and the other for concatenating dictionaries?
> Or do you mean that I should have the function throw an exception
> if it is passed an argument that's not a dictionary or FieldStorage?


This is nothing big; I'm just trying to interpret what it means to:

    dictcat("hello world").

*grin* I think it's a great idea to merge dictionaries and FieldStorages,
since they both serve the same purpose of mapping names to things; I just
thought it was unusual that one of your test cases stuffs weird things
like numbers and strings into the argument list of your dictcat().



From glingl@mail.rg16.asn-wien.ac.at  Thu May  3 09:26:35 2001
From: glingl@mail.rg16.asn-wien.ac.at (Gregor Lingl)
Date: Thu, 03 May 2001 10:26:35 +0200
Subject: [Tutor] rational number representation in Python
References: <F150vJo9iiy6hBySBzC0000f53a@hotmail.com> <5B6B5744C4A@kserver.org>
Message-ID: <3AF1163B.C7214FE0@rg16.asn-wien.ac.at>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
As code for Euclid's algorithm mentioned below you could use:
<p><tt>def gcd(a,b):</tt>
<br><tt>&nbsp;&nbsp;&nbsp; "returns greates common divisor of positive
integers a and b"</tt>
<br><tt>&nbsp;&nbsp;&nbsp; while b:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a, b = b, a%b</tt>
<br><tt>&nbsp;&nbsp;&nbsp; return a</tt><tt></tt>
<p><tt>G.L.</tt>
<br><tt></tt>&nbsp;
<br>&nbsp;
<p>Sheila King schrieb:
<blockquote TYPE=CITE>On Wed, 02 May 2001 11:58:22 -0500, "Julieta Rangel"
<br>&lt;julieta_rangel@hotmail.com>&nbsp; wrote about [Tutor] rational
number
<br>representation in Python:
<p>:Because my result of
<br>:this division is not an integer, I don't want Python to divide.&nbsp;
I want
<br>:(3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left
alone.
<br>:&nbsp; How can I do this?&nbsp; Can anyone help?
<p>In comp.lang.python, there has been talk about an experimental number
class
<br>that includes rational numbers. (I don't remember the details right
now.) You
<br>could possibly use something like that.
<p>Or, it might be instructive to write your own rational number class.
For
<br>reducing fractions, like 3/3 or even 9/3, etc... a useful algorithm
is called
<br>Euclid's Algorithm. You should be able to find the algorithm in a book
on
<br>algorithms fairly easily. It will find the GCF for you, then you can
divide it
<br>out of the numerator and denominator.
<p>I would make a test, that whenever the denominator is 1, to just stop
printing
<br>it, and let the number be output as 4 instead of 4/1.
<p>--
<br>Sheila King
<br><a href="http://www.thinkspot.net/sheila/">http://www.thinkspot.net/sheila/</a>
<br><a href="http://www.k12groups.org/">http://www.k12groups.org/</a>
<p>_______________________________________________
<br>Tutor maillist&nbsp; -&nbsp; Tutor@python.org
<br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a></blockquote>
</html>



From dyoo@hkn.eecs.berkeley.edu  Thu May  3 09:43:14 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 3 May 2001 01:43:14 -0700 (PDT)
Subject: [Tutor] bizare Tkinter error
In-Reply-To: <200105030339.f433dFQ31313@smtp4.fas.harvard.edu>
Message-ID: <Pine.LNX.4.21.0105022153240.26492-100000@hkn.eecs.berkeley.edu>

On Wed, 2 May 2001, Pijus Virketis wrote:

> I am writing a class assignment right now, and I have run into a most
> peculiar bug. I know where it is, but I have absolutely no clue why it
> occurs. Here is the relevant bit of my code:
> 
> class EditFrame:
>     def __init__(self, master):
>       ### Set up prompt frame, list frame, edit frame
>         p_f = l_f = e_f = Frame(master)


There's a part here that worries me.  p_f, l_f, and e_f all are names for
the same Frame; that is, they're just different names for the same object.

I'm assuming that you want all three names to refer to distinct things; if
so, you'll need this instead:

     p_f, l_f, e_f = Frame(master), Frame(master), Frame(master)

Every time we say "Frame(...)", we make a new Frame, distinct from the
others.  What you had before appears to only make one frame, so that might
be affecting the rest of your code.

A similar thing happens when we deal with lists:

###
>>> x = y = [1, 2, 3, 4]
>>> x
[1, 2, 3, 4]
>>> y
[1, 2, 3, 4]
>>> y[4:] = [5, 6, 7]
>>> y
[1, 2, 3, 4, 5, 6, 7]
>>> x
[1, 2, 3, 4, 5, 6, 7]        
###

We explain this by saying that 'x' and 'y' are both directed at the same
list; this is a problem if we want to treat the two independently.  There
are several ways to fix this, but one of the simpler ways of doing this is
with the copy module:

###
>>> import copy
>>> y = [1, 2, 3, 4]
>>> x = copy.copy(y)
>>> y[4:] = [5, 6, 7]
>>> y
[1, 2, 3, 4, 5, 6, 7]
>>> x
[1, 2, 3, 4] 
###

Unfortunately, copy.copy() isn't smart enough to work for Frames.  

This reference/object stuff is a somewhat advanced topic, so if it's a
little confusing, feel free to ask us more about it, and we'll see if we
can cook up a good explanation.

Hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Thu May  3 10:00:20 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 3 May 2001 02:00:20 -0700 (PDT)
Subject: [Tutor] List problem
In-Reply-To: <200105030437_MC2-CECC-15C9@compuserve.com>
Message-ID: <Pine.LNX.4.21.0105030143320.26492-100000@hkn.eecs.berkeley.edu>

On Thu, 3 May 2001, Sharriff Aina wrote:

> I tried it ou, heres one variation:
> ### code 
> 
> if allrows[0] == []:


There's a large difference between:

    if allrows[0] == []

and

    if allrows == []

It's only three characters, but to Python, it makes a world of difference.  
Here's an example that might make things clearer:

###
>>> l1 = [()]   # a list whose first element is an empty tuple
>>> l2 = []     # the empty list.
>>> l1[0] == []
0
>>> l2[0] == []
Traceback (innermost last):
  File "<stdin>", line 1, in ?
IndexError: list index out of range
>>> l1 == []
0
>>> l2 == []
1       
###

Let's make a somewhat silly analogy... hmm...

    [()]:  "a honey jar that contains a deflated balloon."
    []  :  "the empty honey jar."

We need to check that allrows isn't an empty honey jar; otherwise, our
hands would get sticky for no good reason.


(Could you make sure you're selecting the "reply to all" option when you
respond to our email?  It's usually better to do this because the other
tutors can load-balance.  Thanks!)



From NHYTRO@compuserve.com  Thu May  3 13:09:47 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Thu, 3 May 2001 08:09:47 -0400
Subject: [Tutor] If loop not executing completely
Message-ID: <200105030810_MC2-CEC9-ABC@compuserve.com>

Hi guys, I coded a CGI script with database access:

## code ##
#------------------------------------------------------------------------=
--
-----
connection =3D odbc.odbc('minicms')
cur =3D connection.cursor()
cur.execute("select templatetype from userpages where username =3D'%s'"
%(usernamevalue))
usertemplate =3D cur.fetchall()
cur.close()
connection.close()
# cleanup and choose css
#
-------------------------------------------------------------------------=
--
---
tempusertemplate =3D usertemplate[0]
usertemplate =3D tempusertemplate[0]
if usertemplate =3D=3D 'template1':
....htmlhead =3D string.replace(htmlhead, '<usercss>', templatedir + =

'template1.css')
elif usertemplate =3D=3D 'template2':
.... htmlhead =3D string.replace(htmlhead, '<usercss>', templatedir +
'template2.css')
.... # and so on #

since I=B4m adding images too:

## code
if usertemplate =3D=3D 'template1':
    htmlhead =3D string.replace(htmlhead, '<topbar>', templatedir + =

'template1.jpg')
elif usertemplate =3D=3D 'template2':
    htmlhead =3D string.replace(htmlhead, '<topbar>', templatedir + =

'template2.jpg')
.... # and so on...

I decided to couple both actions together

#   final code ##
tempusertemplate =3D usertemplate[0]
usertemplate =3D tempusertemplate[0]
if usertemplate =3D=3D 'template1':
....htmlhead =3D string.replace(htmlhead, '<usercss>', templatedir + =

'template1.css')
....htmlhead =3D string.replace(htmlhead, '<topbar>', templatedir + =

'template1.jpg')
elif usertemplate =3D=3D 'template2':
.... htmlhead =3D string.replace(htmlhead, '<usercss>', templatedir +
'template2.css')
.... htmlhead =3D string.replace(htmlhead, '<topbar>', templatedir + =

'template2.jpg')


this promptly causes a "list out of range error" !!??? I switched back to=

chugging along the string to be replaced separately. =


Sorry to nag you guys


Thanks

Sharriff


From arcege@speakeasy.net  Thu May  3 12:59:50 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 3 May 2001 07:59:50 -0400 (EDT)
Subject: [Tutor] Processor Simulator
In-Reply-To: <3AF0B4A0.7DC0E1B2@mindless.com> from "Timothy M. Brauch" at May 02, 2001 09:30:08 PM
Message-ID: <200105031159.f43BxoV04374@dsl092-074-184.bos1.dsl.speakeasy.net>

Timothy M. Brauch wrote
> I have a project for my comp-sci class.  I have to design a simulator
> for a processor, and I've decided to use Python.  So, my question is,
> does anyone have any suggestions as to how to go about doing this? 
> Also, I have to write simple files and load them into my simulator.
> 
> My initial thoughts are to create a class with a bunch of function
> definitions for different processes.  Such as add() and sub() and mul(),
> etc.

I would try to break different components into separate classes.
For example, a class for an ALU, another for external memory (maybe with
methods for "read" and "write", especially if you are simulating a RISC
type processor ;)), maybe one for a pipeline (later).  Then you could have
the one "processor" class as the control mechanisms for the components.

But above all.. keep it simple.  This seems oxymoronic, but as I suggest
above, instead of making some big list to simulate possibly megabytes of
RAM, just make read/write methods (there will be comparable load/store
commands anyway).  Don't introduce a cache or special features at first;
as attractive as it might be to code, doing so might distract from the
"real" features.

> I also have to have a display window showing register enteries, which
> that I think I can do fairly easily.  I was thinking of using the latest
> VPython which has a text function (I am doing this mostly because I have
> no experience with TK, otherwise I would use it, but right now I don't
> have the time to learn it).

At first, I would just concentrate on the class(es) for the processor
and worry about a user interface later.  The project is not a graphical
program; keep display in mind while you are designing your program,
but keep the focus on the goal.

> As for the files, I would use something like readlines and string.split
> to break up my commands kept in the external file.  I think I can handle
> that as well.

That sounds fine, especially at first.  Also look at string.strip to
"nicely" get rid of the whitespace (including the line terminator).

Good luck! :)

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From lsloan@umich.edu  Thu May  3 13:41:42 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 03 May 2001 08:41:42 -0400
Subject: [Tutor] Re: Tutor digest, Vol 1 #763 - 13 msgs
In-Reply-To: Your message of "Wed, 02 May 2001 23:02:01 EDT."
 <E14v9NR-0006eb-00@mail.python.org>
Message-ID: <200105031241.IAA20178@birds.us.itd.umich.edu>

"Julieta Rangel" <julieta_rangel@hotmail.com> wrote:
> problem is representing rational numbers, ie,(7/2).  Because my result of 
> this division is not an integer, I don't want Python to divide.  I want 
> (3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left alone. 
> How can I do this?  Can anyone help?

Instead of letting Python divide those numbers, you could store them in
a tuple, (numerator, denominator).  Of course, reduce the fraction
first before storing it in the tuple.  I suppose that instead of
storing fractions with one as the denominator, (n, 1), in a tuple, you
could just store them as the number itself.  That's optional.

Either way, if you have a function that prints the polynomial, you
could make it work with the original or integrated versions, just by
checking the type of coefficient.  Here's what I would do:

	if (type(coeff[i]) == types.TupleType):
		(num, den) = coeff[i]
		if (den == 1):
			print num
		else:
			print '%d/%d' % (num, den)
	else:
		print coeff[i]

Of course, making or finding a rational number class, as Ms. King
suggested, would probably be best.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From bill_tolbert@bigfoot.com  Thu May  3 15:13:45 2001
From: bill_tolbert@bigfoot.com (Bill Tolbert)
Date: Thu, 3 May 2001 10:13:45 -0400 (EDT)
Subject: [Tutor] any serial gurus available?
Message-ID: <Pine.A41.4.21L1.0105030920060.13274-100000@login4.isis.unc.edu>

If you folks help me pull this off it'll be a major Python coup for
me. Someone at another location is working on this problem in VB and I'd
like to nail it down with Python, but I'm a bit stuck at the moment.

I need to read data from a small medical device over a serial port (it's a
spirometer; measures lung function). I'm using Roger Burnham's Serial
package, Python 2.0 on Win98.

According to the documentation (yes, I have some!) the "transmission shall
be initiated when the PB100 sends a start of header character (0xa5)." I
can open the port and ask for the first byte (line 5 below). I indeed
receive the header character, so I know something is happening (line 6
prints '0xa5' to stdout). The docs say the device will wait on the PC for
an acknowledgement. I believe this is working. Line 9 causes the device
to beep. 

First question: From the docs, "Valid acknowledge signals shall be one
byte values in the range of 0x01 to 0xFE." So, is line nine the way to
send a valid 0x01? I assume yes (why else would it beep? <grin>)

(Side note: The acknowledge value is used to determine the subsequent baud
rate. This is a bit confusing. I had to start the conversation with a baud
of 4800. The subsequent baud is determined by 52083.3 / acknowledge value.
This can range from 52,083.3 (when using 1) to 205 (when using 254). I've
tried 1, as below, but also tried 11 which gets me pretty close to 4800.
Same behavior.)

The device waits 200 milliseconds to adjust the baud rate, then sends
either a 1 or a 2. Here's where I get really confused. How do I get the
next value? Line 10 begins a for loop. I read 1 byte from the port,
looping 10 times. I would expect to see either a 1 or a 2, but instead I
usually get a series of 0's.

My read of the docs is that it will just dump bytes at this point, then
wait on a checksum. I don't think I'm getting anything to calculate a
checksum on!

My COM1 buffers are set to the minimum, so I don't think I'm losing data
in there. Is there something about my read method that isn't correct?

Thanks a 0xf4240,

Bill
==============================

(port setup stuff above...)
...
 1    #read some data
 2    try:
 3        # read the first byte; should be 0xa5 in hex
 4        # delivered as an octal
 5        header = port.read(1, timed=1)
 6        print hex(ord(header[0]))
 7        if '0xa5' == hex(ord(header[0])):
 8            # send an achnowlegement. now what?
 9            port.write(hex(1))
10            for i in range(1,11):
11                byte = port.read(1, timed=1)
12                blocks.append(byte)
13        print blocks
14        port.close()
15    except:
16        port.close()
17        traceback.print_exc()
18        return None



From lsloan@umich.edu  Thu May  3 15:22:41 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 03 May 2001 10:22:41 -0400
Subject: [Tutor] FieldStorage solution summary
In-Reply-To: Your message of "Thu, 03 May 2001 01:09:32 PDT."
 <Pine.LNX.4.21.0105030100130.26492-100000@hkn.eecs.berkeley.edu>
Message-ID: <200105031422.KAA21341@birds.us.itd.umich.edu>

Daniel Yoo wrote:
> This is nothing big; I'm just trying to interpret what it means to:
> 
> dictcat("hello world").
> 
> *grin* I think it's a great idea to merge dictionaries and FieldStorages,
> since they both serve the same purpose of mapping names to things; I just
> thought it was unusual that one of your test cases stuffs weird things
> like numbers and strings into the argument list of your dictcat().

Oh, I see what you mean.  I wrote the function to operate on
FieldStorage and dictionary objects and it just happened that it
"ignores" other types.  I suppose it would be better to throw an
exception when those types are passed to it.  I'll probably add that
soon, then.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From lsloan@umich.edu  Thu May  3 16:14:08 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 03 May 2001 11:14:08 -0400
Subject: [Tutor] #include in DocumentTemplate?
Message-ID: <200105031514.LAA21935@birds.us.itd.umich.edu>

One of the things that frustrates me about learning Python is the lack
of documentation.  At least, what I want to know isn't documented or
it's hard to find.  Perhaps the reason it's so hard to find is that
such a feature doesn't exist yet.

As I mentioned in one of my previous messages, I've copied the
DocumentTemplate module out of Zope to use with some CGIs that I'm
writing.  It works well and I like it, but I'd like to have one DTML
file include another rather than having my program parse several of
them in a row.

Right now, I have code that looks like this:

	tmpl = DocumentTemplate.HTMLFile('../templates/header.dtml')
	print tmpl(title = 'Specify Your Unvailability Date')

	tmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml')
	print tmpl(mapping = vars())

	tmpl = DocumentTemplate.HTMLFile('../templates/footer.dtml')
	print tmpl(year = year)

What I'd like my code to look like is:

	tmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml')
	print tmpl(mapping = vars())

(Just assume I'm doing the right thing with the arguments to tmpl().)
And unavailcal.dtml would have something like this:

	<!--#include header.dtml -->

	[body stuff here]

	<!--#include footer.dtml -->

Is this possible?  I've tried it and it doesn't seem to work.  Would I
have to write a new DTML tag/function to do this for me?  Has anybody
already done this?

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From arcege@speakeasy.net  Thu May  3 16:26:28 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 3 May 2001 11:26:28 -0400 (EDT)
Subject: [Tutor] any serial gurus available?
In-Reply-To: <Pine.A41.4.21L1.0105030920060.13274-100000@login4.isis.unc.edu> from "Bill Tolbert" at May 03, 2001 10:13:45 AM
Message-ID: <200105031526.f43FQSS04621@dsl092-074-184.bos1.dsl.speakeasy.net>

Bill Tolbert wrote
> I need to read data from a small medical device over a serial port (it's a
> spirometer; measures lung function). I'm using Roger Burnham's Serial
> package, Python 2.0 on Win98.
> 
> According to the documentation (yes, I have some!) the "transmission shall
> be initiated when the PB100 sends a start of header character (0xa5)." I
> can open the port and ask for the first byte (line 5 below). I indeed
> receive the header character, so I know something is happening (line 6
> prints '0xa5' to stdout). The docs say the device will wait on the PC for
> an acknowledgement. I believe this is working. Line 9 causes the device
> to beep. 
> 
> First question: From the docs, "Valid acknowledge signals shall be one
> byte values in the range of 0x01 to 0xFE." So, is line nine the way to
> send a valid 0x01? I assume yes (why else would it beep? <grin>)

Below you are sending the hex() of a number, which results in a multi-
byte(character) ASCII string, not a single byte binary string to be sent.
You might be getting the beep because the first byte written is 48, not 1.

The difference is that hex(1) gives a string of three bytes '0'(48),
'x'(120), '1'(49).  But the single byte string is '\001'(1).  The number
in parenthises is the ASCII (ISO-8859-1) value returned by ord().

Python provides a chr() function that creates the ASCII character for
a given value.

>>> chr(1)   # the binary 1, ASCII SOA
'\001'
>>> chr(32)  # space
' '
>>> chr(48)  # the ASCII zero numeral, but not the integer 0
'0'

> The device waits 200 milliseconds to adjust the baud rate, then sends
> either a 1 or a 2. Here's where I get really confused. How do I get the
> next value? Line 10 begins a for loop. I read 1 byte from the port,
> looping 10 times. I would expect to see either a 1 or a 2, but instead I
> usually get a series of 0's.

You can sleep for a number of milliseconds by using a float with the
"sleep" function in the "time" module.

>>> import time
>>> sleep_howlong = 0.200 # seconds, or 200 milliseconds
>>> time.sleep(sleep_howlong)

> My read of the docs is that it will just dump bytes at this point, then
> wait on a checksum. I don't think I'm getting anything to calculate a
> checksum on!
> 
> My COM1 buffers are set to the minimum, so I don't think I'm losing data
> in there. Is there something about my read method that isn't correct?
> 
> Thanks a 0xf4240,
> 
> Bill
> ==============================
> 
> (port setup stuff above...)
> ...
>  1    #read some data
>  2    try:
>  3        # read the first byte; should be 0xa5 in hex
>  4        # delivered as an octal
>  5        header = port.read(1, timed=1)
>  6        print hex(ord(header[0]))
>  7        if '0xa5' == hex(ord(header[0])):
#Just test with (use the hex character ('\xa5' with Python 2.1):
            if '\245' == header[0]:  # the octal value of 0xa5

>  8            # send an achnowlegement. now what?
>  9            port.write(hex(1))
#Use the binary character instead:
                port.write(chr(1))

> 10            for i in range(1,11):
> 11                byte = port.read(1, timed=1)
> 12                blocks.append(byte)
#Sleep here, then read ten bytes:
                time.sleep(0.2) # sleep for 200 milliseconds
                bytes = port.read(10, timed=1)
                blocks = list(bytes)

> 13        print blocks
> 14        port.close()
> 15    except:
> 16        port.close()
> 17        traceback.print_exc()
> 18        return None

Good luck - I can't test any of this of course, I don't have a device
to test it on or the "serial" module you speak of (or the OS).  But if
it doesn't work, I'm sure someone will correct me. :)

  -Arcege


-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From lsloan@umich.edu  Thu May  3 16:30:50 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 03 May 2001 11:30:50 -0400
Subject: [Tutor] preventing KeyError from "%"
Message-ID: <200105031530.LAA22131@birds.us.itd.umich.edu>

I use the "%" operator with strings a lot.  One of the things I
commonly do is set a dictionary from values submitted via a web page
form or read from a database.  It's not uncommon that some fields may
be empty and there wouldn't be a key for that field in the dictionary.
When I use that dictionary with "%" and the format string calls for
that key, I get this exception:

	KeyError: x

How can I get "%" to not throw an exception, but instead skip over that
key and move on to the next substitution?  For example, if I have
this:

	lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'}
	monty = {'first': 'Monty', 'last': 'Python'}

	print '%(first)s %(mi)s %(last)s\n' % lance
	print '%(first)s %(mi)s %(last)s\n' % monty

it would produce:

	Lance E Sloan
	Monty  Python

instead of throwing an exception for the "% monty" line.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From lsloan@umich.edu  Thu May  3 16:37:43 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 03 May 2001 11:37:43 -0400
Subject: [Tutor] Sorry!
Message-ID: <200105031537.LAA22308@birds.us.itd.umich.edu>

When I responded to a previous message, I *meant* to change the subject
from "Re: Tutor digest, Vol 1 #763 - 13 msgs" to "Re: rational number
representation in Python".  I had the new subject in my cut & paste
buffer, but I forgot all about it once I started composing my message.

I'm very sorry.  Of course, it will be me that looks like a foolish
net-newbie in the list archives.  That'll teach me.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From bdupire@seatech.fau.edu  Thu May  3 16:42:13 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Thu, 03 May 2001 11:42:13 -0400
Subject: [Tutor] attaching the first element in a list to a string
References: <F6xLDp7mvjkO22ZhCl800000867@hotmail.com>
Message-ID: <3AF17C55.FC37C45B@seatech.fau.edu>

Let's start by the beginning

To create a python module, you need to store some code in a .py file.
In that .py file, you define some functions, some classes, some objects, some
variables, whatever....

ex:
# this is  toto.py

def foo(value):            # a function
    return value +3

a = 2                           # a integer variable

class Poly:                    # a class
    def __init__():
            pass            # add your code
    def __str__():
            pass            # add your code
    def integrate():
            pass            # add your code

myPoly = Poly()            # an object
print myPoly                  # i call a method of the object..
myPoly.integrate()
print myPoly
_______________

>From the interpreter if i want to use the code which is in toto.py, i input

import toto            # i need to access toto...
toto.a                    # this accesses variable 'a' in toto, and therefore
returns 2
toto.foo(5)            # this accesses function 'foo' in toto, and returns 8
print toto.myPoly   # when i imported toto, myPoly was created...  access it,
and print it.


In the example i print myPoly  either from the interpreter or from the module
itself.
Notice the difference in the syntax....
>From the interpreter, i have to tell Python in which module the object myPoly
lives....
Variables in toto.py lives in the toto namespace...

See my comment below



Julieta Rangel wrote:

>   At the end of the program, am I supposed to
> write
> import poly

            #### No, don't import the same module within your module.
    You only need this line if you want to use your module from another module
(ie. the interpreter)
    So skip this line
    Read the tutorial about Modules and the import function, please!

Benoit

>
> s.integrate()            # ok !
> print s   ??                # ok
>
> I am thankful for all your help.
>
> Julieta
>
> >From: Benoit Dupire <bdupire@seatech.fau.edu>
> >To: Julieta Rangel <julieta_rangel@hotmail.com>
> >CC: tutor@python.org
> >Subject: Re: [Tutor] attaching the first element in a list to a string
> >Date: Thu, 03 May 2001 00:44:25 -0400
> >
> >
> >
> >Julieta Rangel wrote:
> >
> > > This modification to the program works well in calculating the integral,
> >but
> > > it does not print it out when running the program.  When you inputed
> > > poly.s.integrate() followed by print poly.s (In Python Shell), the
> >integral
> > > is printed.  What command should we include in the program to make it
> >print
> > > out automatically while running it.  If I include these commands in the
> > > actual program, they don't work as they do in Python Shell.
> >
> >s is a Poly object defined in the 'poly' module, and s has a method called
> >'integrate'.
> >so to access s.integrate()  from the interpreter, i input
> >import poly                # this executes all the code in poly.py, and
> >therefore creates 's'
> >poly.s.integrate()
> >I do not need the 'poly.' part  if i want to refer the object from  the
> >module
> >it lives in.
> >
> >
> >read my previous message carefully. The answer to your question was in
> >there...
> >
> > >integrate is now a method of the class Poly
> > >so i can use it like this...
> > >
> > >s= Poly( c=[1 5 6])            # here, we use __init__
> > >print s                                # here we use __str__
> > >s.integrate()                        # guess what ?
> >
> >I advise you to read the Python tutorial (especially the part dealing with
> >modules) and/or the book called 'Learning Python', so that you can progress
> >more
> >rapidly in Python.
> >
> >Benoit
> >
> >



From arcege@speakeasy.net  Thu May  3 16:55:04 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 3 May 2001 11:55:04 -0400 (EDT)
Subject: [Tutor] #include in DocumentTemplate?
In-Reply-To: <200105031514.LAA21935@birds.us.itd.umich.edu> from "Lance E Sloan" at May 03, 2001 11:14:08 AM
Message-ID: <200105031555.f43Ft5O04662@dsl092-074-184.bos1.dsl.speakeasy.net>

Lance E Sloan wrote
> 
> 
> One of the things that frustrates me about learning Python is the lack
> of documentation.  At least, what I want to know isn't documented or
> it's hard to find.  Perhaps the reason it's so hard to find is that
> such a feature doesn't exist yet.
> 
> As I mentioned in one of my previous messages, I've copied the
> DocumentTemplate module out of Zope to use with some CGIs that I'm
> writing.  It works well and I like it, but I'd like to have one DTML
> file include another rather than having my program parse several of
> them in a row.

This isn't a Zope list, there is one there where you can probably get
a much better answer.

There's plenty of documentation on Zope and its components; have you
looked at <URL: http://www.zope.org/Documentation>?

> Right now, I have code that looks like this:
> 
> ^Itmpl = DocumentTemplate.HTMLFile('../templates/header.dtml')
> ^Iprint tmpl(title = 'Specify Your Unvailability Date')
> 
> ^Itmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml')
> ^Iprint tmpl(mapping = vars())
> 
> ^Itmpl = DocumentTemplate.HTMLFile('../templates/footer.dtml')
> ^Iprint tmpl(year = year)
> 
> What I'd like my code to look like is:
> 
> ^Itmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml')
> ^Iprint tmpl(mapping = vars())
> 
> (Just assume I'm doing the right thing with the arguments to tmpl().)
> And unavailcal.dtml would have something like this:
> 
> ^I<!--#include header.dtml -->
> 
> ^I[body stuff here]
> 
> ^I<!--#include footer.dtml -->
> 
> Is this possible?  I've tried it and it doesn't seem to work.  Would I
> have to write a new DTML tag/function to do this for me?  Has anybody
> already done this?

I'd say, off hand, that DTML is not going to process standard server-side
includes.  That would be up to whatever server you have that handles them.
But me-thinks that it would definately be after the DTML is processes
by Python.

The DT_HTML.HTML class will handle some of its own server-side includes.
It may be that you are to make a subclass to make your own handling
of these.

I don't know how many ppl here are Zope-ites; it might be better for you
to repost your question on the zope mailing list <URL: mailto:zope@zope.org>
there is also an IRC channel (according to the website): #zope on the
server irc.zope.net:6667 (seemingly an Open Source IRC network, there is
even a #python channel).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From scarblac@pino.selwerd.nl  Thu May  3 16:53:11 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 3 May 2001 17:53:11 +0200
Subject: [Tutor] preventing KeyError from "%"
In-Reply-To: <200105031530.LAA22131@birds.us.itd.umich.edu>; from lsloan@umich.edu on Thu, May 03, 2001 at 11:30:50AM -0400
References: <200105031530.LAA22131@birds.us.itd.umich.edu>
Message-ID: <20010503175311.A17555@pino.selwerd.nl>

On  0, Lance E Sloan <lsloan@umich.edu> wrote:
> I use the "%" operator with strings a lot.  One of the things I
> commonly do is set a dictionary from values submitted via a web page
> form or read from a database.  It's not uncommon that some fields may
> be empty and there wouldn't be a key for that field in the dictionary.
> When I use that dictionary with "%" and the format string calls for
> that key, I get this exception:
> 
> 	KeyError: x
> 
> How can I get "%" to not throw an exception, but instead skip over that
> key and move on to the next substitution?  For example, if I have
> this:
> 
> 	lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'}
> 	monty = {'first': 'Monty', 'last': 'Python'}
> 
> 	print '%(first)s %(mi)s %(last)s\n' % lance
> 	print '%(first)s %(mi)s %(last)s\n' % monty
> 
> it would produce:
> 
> 	Lance E Sloan
> 	Monty  Python
> 
> instead of throwing an exception for the "% monty" line.

You can't do that with the standard dictionary, so you have to roll your
own, inherited from UserDict, i.e.:

from UserDict import UserDict

class MyDict(UserDict):
   def __getitem__(self, arg):
      # Returns "" for any arg that's not in the underlying dictionary
      if self.data.has_key(arg):
         return self.data[arg]
      else:
         return ""

print '%(first)s %(mi)s %(last)s\n' % MyDict(lance)

-- 
Remco Gerlich


From bdupire@seatech.fau.edu  Thu May  3 17:00:26 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Thu, 03 May 2001 12:00:26 -0400
Subject: [Tutor] preventing KeyError from "%"
References: <200105031530.LAA22131@birds.us.itd.umich.edu>
Message-ID: <3AF1809A.7120D77E@seatech.fau.edu>

if don't know if it's what you are looking for, but the following wouldn't
do what you want ?


monty = {'first': 'Monty', 'last': 'Python'}


for key in ['first', 'mi', 'last']"
    if not lance.has_key(key):
        monty[key]=''

print '%(first)s %(mi)s %(last)s\n' % monty




It just add the keys that don't exist...
Benoit

Lance E Sloan wrote:

> I use the "%" operator with strings a lot.  One of the things I
> commonly do is set a dictionary from values submitted via a web page
> form or read from a database.  It's not uncommon that some fields may
> be empty and there wouldn't be a key for that field in the dictionary.
> When I use that dictionary with "%" and the format string calls for
> that key, I get this exception:
>
>         KeyError: x
>
> How can I get "%" to not throw an exception, but instead skip over that
> key and move on to the next substitution?  For example, if I have
> this:
>
>         lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'}
>         monty = {'first': 'Monty', 'last': 'Python'}
>
>         print '%(first)s %(mi)s %(last)s\n' % lance
>         print '%(first)s %(mi)s %(last)s\n' % monty
>
> it would produce:
>
>         Lance E Sloan
>         Monty  Python
>
> instead of throwing an exception for the "% monty" line.
>
> --
> Lance E Sloan
> Web Services, Univ. of Michigan: Full-service Web and database design,
> development, and hosting.  Specializing in Perl & Python CGIs.
> http://websvcs.itd.umich.edu/ - "Putting U on the Web"
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From bdupire@seatech.fau.edu  Thu May  3 17:04:06 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Thu, 03 May 2001 12:04:06 -0400
Subject: [Tutor] preventing KeyError from "%"
References: <200105031530.LAA22131@birds.us.itd.umich.edu>
Message-ID: <3AF18176.B705084C@seatech.fau.edu>

Oh oh oh !
I ve just seen Remco's answer (which is far better than mine, because field
names are not hard-coded )...

The idea is about the same though...

Benoit.


Lance E Sloan wrote:

> I use the "%" operator with strings a lot.  One of the things I
> commonly do is set a dictionary from values submitted via a web page
> form or read from a database.  It's not uncommon that some fields may
> be empty and there wouldn't be a key for that field in the dictionary.
> When I use that dictionary with "%" and the format string calls for
> that key, I get this exception:
>
>         KeyError: x
>
> How can I get "%" to not throw an exception, but instead skip over that
> key and move on to the next substitution?  For example, if I have
> this:
>
>         lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'}
>         monty = {'first': 'Monty', 'last': 'Python'}
>
>         print '%(first)s %(mi)s %(last)s\n' % lance
>         print '%(first)s %(mi)s %(last)s\n' % monty
>
> it would produce:
>
>         Lance E Sloan
>         Monty  Python
>
> instead of throwing an exception for the "% monty" line.
>
> --
> Lance E Sloan
> Web Services, Univ. of Michigan: Full-service Web and database design,
> development, and hosting.  Specializing in Perl & Python CGIs.
> http://websvcs.itd.umich.edu/ - "Putting U on the Web"
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From DOUGS@oceanic.com  Thu May  3 17:07:04 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Thu, 3 May 2001 06:07:04 -1000
Subject: [Tutor] preventing KeyError from "%"
Message-ID: <8457258D741DD411BD3D0050DA62365907A7CD@huina.oceanic.com>

[Lance E Sloan asked:]
> I use the "%" operator with strings a lot.  One of the things I
> commonly do is set a dictionary from values submitted via a web page
> form or read from a database.  It's not uncommon that some fields may
> be empty and there wouldn't be a key for that field in the dictionary.
> When I use that dictionary with "%" and the format string calls for
> that key, I get this exception:
> 
> 	KeyError: x
> 
> How can I get "%" to not throw an exception, but instead skip 
> over that
> key and move on to the next substitution?  

Look into the 'update' method of dictionaries.  As an example, you might
start with a template dictionary:
Python 1.5.2 (#1, Apr 18 1999, 16:03:16)  [GCC pgcc-2.91.60 19981201
(egcs-1.1.1  on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> temp_dict = {'first': '', 'mi': '', 'last': ''}
>>> lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'}
>>> temp_dict.update(lance)
>>> temp_dict
{'first': 'Lance', 'mi': 'E', 'last': 'Sloan'}
>>> temp_dict = {'first': '', 'mi': '', 'last': ''}
>>> monty = {'first': 'Monty', 'last': 'Python'}
>>> temp_dict.update(monty)
>>> temp_dict
{'first': 'Monty', 'last': 'Python', 'mi': ''}
>>>

HTH

-Doug-


From ium@micromuse.com  Thu May  3 17:06:26 2001
From: ium@micromuse.com (ibraheem umaru-mohammed)
Date: Thu, 3 May 2001 17:06:26 +0100
Subject: [Tutor] Sorry!
In-Reply-To: <200105031537.LAA22308@birds.us.itd.umich.edu>; from lsloan@umich.edu on Thu, May 03, 2001 at 11:37:43AM -0400
References: <200105031537.LAA22308@birds.us.itd.umich.edu>
Message-ID: <20010503170626.B9282@ignoramus>

Hi,

[Lance E Sloan wrote...]
-| 
-| When I responded to a previous message, I *meant* to change the subject
-| from "Re: Tutor digest, Vol 1 #763 - 13 msgs" to "Re: rational number
-| representation in Python".  I had the new subject in my cut & paste
-| buffer, but I forgot all about it once I started composing my message.
-| 

I don't know what mail client or operating system you use, but if you
are using *nix, then you might find the formail command useful with
digested messages.

man formail

For example, under mutt, I can do the following in the command prompt
when the digest file is selected in my inbox: 

	:formail +1 -ds >> mailbox

this will un-digest the message from a single one, to multiple, of which you
can reply to each individually as opposed to changing any of the
subject headers, and inadvertently breaking any message threads.

Hope that helps,

	--ibs.

-- 
One meets his destiny often on the road he takes to avoid it.


From arcege@speakeasy.net  Thu May  3 17:08:18 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 3 May 2001 12:08:18 -0400 (EDT)
Subject: [Tutor] preventing KeyError from "%"
In-Reply-To: <200105031530.LAA22131@birds.us.itd.umich.edu> from "Lance E Sloan" at May 03, 2001 11:30:50 AM
Message-ID: <200105031608.f43G8IC04693@dsl092-074-184.bos1.dsl.speakeasy.net>

Lance E Sloan wrote
> 
> 
> I use the "%" operator with strings a lot.  One of the things I
> commonly do is set a dictionary from values submitted via a web page
> form or read from a database.  It's not uncommon that some fields may
> be empty and there wouldn't be a key for that field in the dictionary.
> When I use that dictionary with "%" and the format string calls for
> that key, I get this exception:
> 
> ^IKeyError: x
> 
> How can I get "%" to not throw an exception, but instead skip over that
> key and move on to the next substitution?  For example, if I have
> this:
> 
> ^Ilance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'}
> ^Imonty = {'first': 'Monty', 'last': 'Python'}
> 
> ^Iprint '%(first)s %(mi)s %(last)s\n' % lance
> ^Iprint '%(first)s %(mi)s %(last)s\n' % monty
> 
> it would produce:
> 
> ^ILance E Sloan
> ^IMonty  Python
> 
> instead of throwing an exception for the "% monty" line.

Sorry, but no.  All values must exist in the dictionary.
>From the Python Library Reference Manual:
   If the right argument is a dictionary (or any kind of mapping), then
   the formats in the string _must_ have a parenthesized key into that
   dictionary inserted immediately after the "%" character, and each
   format formats the corresponding entry from the mapping.
<URL: http://www.python.org/doc/current/lib/typesseq-strings.html>

You could make sure that all values are an empty string at first.
Create a dictionary with empty strings first, and populate it with
the values afterward.  Or go thru the dictionary and find the missing
fields and populate the dictionary that way.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From lsloan@umich.edu  Thu May  3 17:11:57 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 03 May 2001 12:11:57 -0400
Subject: [Tutor] preventing KeyError from "%"
In-Reply-To: Your message of "Thu, 03 May 2001 17:53:11 +0200."
 <20010503175311.A17555@pino.selwerd.nl>
Message-ID: <200105031611.MAA22705@birds.us.itd.umich.edu>

Remco Gerlich wrote:
> You can't do that with the standard dictionary, so you have to roll your
> own, inherited from UserDict, i.e.:

Thank you very much.  After I sent my question to the list, I realized
that KeyError is an exception thrown by the dictionary object and not
necessarily a "%" problem.  I thought the solution might be something
like that, but I didn't know quite how to do it.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From deirdre@deirdre.net  Thu May  3 17:23:58 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Thu, 3 May 2001 09:23:58 -0700
Subject: [Tutor] If loop not executing completely
In-Reply-To: <200105030810_MC2-CEC9-ABC@compuserve.com>
References: <200105030810_MC2-CEC9-ABC@compuserve.com>
Message-ID: <a05100301b717365cd33c@[10.0.1.45]>

>this promptly causes a "list out of range error" !!??? I switched back to
>chugging along the string to be replaced separately.


Can you post the *actual* traceback?


-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From randrews@planhouse.com  Thu May  3 18:24:39 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Thu, 3 May 2001 12:24:39 -0500
Subject: [Tutor] Guido and ESR post to Useless Python
Message-ID: <000a01c0d3f5$ef481220$de00a8c0@planhouse5>

I'll get the code posted tonight, but wanted to go ahead and spread a little
glee. Guido van Rossum and Eric S. Raymond (Open Source programming deity)
have both submitted code to be posted on Useless Python today.

Eric S. Raymond's script reports on upgrades needed to use a particular
kernel, Guido van Rossum's scripts analyze access_log files and ftp
logfiles, respectively.

Delighted,
Rob

Useless Python
http://www.lowerstandard.com/python/pythonsource.html



From julieta_rangel@hotmail.com  Thu May  3 18:37:35 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Thu, 03 May 2001 12:37:35 -0500
Subject: [Tutor] inserting items into a list
Message-ID: <F84YLowspDKicUbvBDx00000d7e@hotmail.com>

I'm trying to come up with a definition for multiplication of polynomials. 
Say I want to multiply (2 + 3x + x^2 + 2x^3) times (1+0x+2x^2), so I created 
two lists of coefficients. List 1 =[2,3,1,2] and list 2= [1,0,2].  To 
multiply these two I need to take each element from list 1 and multiply it 
by all of the elements of list 2, and create a new list for each result.  
For example, by multiplying the first element of list 1 by all of the 
elemens of list 2 I would get [2,0,4], from the second #, I would get 
[3,0,6], then [1,0,2] and finally [2,0,4].  I need to find a way to insert 3 
zeroes at the end of list [2,0,4]; 1 zero at the beginning and two at the 
end of [3,0,6]; 2 zeroes a the beginning and one at the end of [1,0,2], and 
finally 3 zeroes at the beginning of [2,0,4].  This way the new lists would 
look like:

[2,0,4,0,0,0]
[0,3,0,6,0,0]
[0,0,1,0,2,0]
[0,0,0,2,0,4]

and it would be just a matter of adding those lists to figure out the 
result:  2 + 3x + 5x^2 + 8x^3 + 2x^4 + 4x^5.  As you can see from the 
subject, my problem is inserting those zeroes at the specific locations.  
Can you help me?

Julieta

If you notice, there is a little pattern
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From deirdre@deirdre.net  Thu May  3 18:49:07 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Thu, 3 May 2001 10:49:07 -0700
Subject: [Tutor] Guido and ESR post to Useless Python
In-Reply-To: <000a01c0d3f5$ef481220$de00a8c0@planhouse5>
References: <000a01c0d3f5$ef481220$de00a8c0@planhouse5>
Message-ID: <a05100304b7174a679ff5@[10.0.1.45]>

>I'll get the code posted tonight, but wanted to go ahead and spread a little
>glee. Guido van Rossum and Eric S. Raymond (Open Source programming deity)
>have both submitted code to be posted on Useless Python today.

Woohoo! You've hit the major league now. I think you ought to write 
Larry Wall and Rasmus Lerdorf and see if they have any potential 
entries. :)

>Eric S. Raymond's script reports on upgrades needed to use a particular
>kernel, Guido van Rossum's scripts analyze access_log files and ftp
>logfiles, respectively.

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From gibbs05@flash.net  Thu May  3 18:53:46 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Thu, 3 May 2001 12:53:46 -0500
Subject: [Tutor] starting a tkinter window maximized
References: <200105022143.f42LhKo22431@pop.nsacom.net>
Message-ID: <00f501c0d3fa$45da6800$09dd3040@gibbs05>

> The subject pretty much says it all! How does one tell a tkinter window to
> start maximized in windows or X?

I didn't see an answer to this one yet, so I'll give it a shot.

wm_state('zoomed') should maximize on Windows.  For example:

    >>> import os
    >>> from Tkinter import *
    >>> class MaxWin(Tk):
    ...        def __init__(self):
    ...            Tk.__init__(self)
    ...            Label(self, text = "Test Zoom").pack()
    ...            if os.name == 'nt':
    ...                self.wm_state('zoomed')
    ...
    >>> test = MaxWin()
    >>> test.mainloop()

This produced a full size window with a label.

Zoomed isn't valid for Unix so, as far a I know, you'd have to calculate
screen width & height and set your window size accordingly.  I don't suggest
you do this though, because I've had some Unix users tell me maximizing an
app is very rude.

Good luck,
Sam




From randrews@planhouse.com  Thu May  3 18:58:51 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Thu, 3 May 2001 12:58:51 -0500
Subject: [Tutor] Guido and ESR post to Useless Python
In-Reply-To: <a05100304b7174a679ff5@[10.0.1.45]>
Message-ID: <000b01c0d3fa$b6e639c0$de00a8c0@planhouse5>

hehe... I've already thought of asking Larry Wall, who just might do it on
general principle. This all gives me a good excuse to tighten up the site
again this weekend, breaking it up into several smaller pages. Any Tutor
folk who would like to make suggestions on how the site *should* be are
welcome to email me (privately if it's not appropriate on the list).

Rob

-----Original Message-----
From: Deirdre Saoirse Moen [mailto:deirdre@deirdre.net]
Sent: Thursday, May 03, 2001 12:49 PM
To: randrews@planhouse.com; tutor@python.org
Subject: Re: [Tutor] Guido and ESR post to Useless Python


>I'll get the code posted tonight, but wanted to go ahead and spread a
little
>glee. Guido van Rossum and Eric S. Raymond (Open Source programming deity)
>have both submitted code to be posted on Useless Python today.

Woohoo! You've hit the major league now. I think you ought to write
Larry Wall and Rasmus Lerdorf and see if they have any potential
entries. :)

>Eric S. Raymond's script reports on upgrades needed to use a particular
>kernel, Guido van Rossum's scripts analyze access_log files and ftp
>logfiles, respectively.

--
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams



From vlindberg@verio.net  Thu May  3 20:44:13 2001
From: vlindberg@verio.net (VanL)
Date: Thu, 03 May 2001 13:44:13 -0600
Subject: [Tutor] Moving email redux, and scripting browsers
Message-ID: <3AF1B50D.D013E000@verio.net>

Hello,

In mentioning my moving email problem yesterday, I neglected to mention
that there is a web-based interface ... and after some work, it appears
that it will probably be necessary to use the web interface to move the
email from the different "folders" to the inbox, where I can pop it off
using poplib.

Considering I still want to script this thing, though, I want to script
a browser.  I figure that I can do this one of two ways: either using
com with ie in windows, or using the python bindings to konqueror in
linux or FreeBSD.

Has anyone had any experience with any of these?  Can anyone recommend
one of these options (or even another?  Does anyone know where I could
get more information?

What I would want to do is parse and submit several forms, including a
login form.

Thanks,

VanL


From kromag@nsacom.net  Fri May  4 00:08:24 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Thu, 3 May 2001 16:08:24 -0700 (PDT)
Subject: [Tutor] Cackling with Maniac Laughter (was: starting a tkinter window maximized)
Message-ID: <200105032308.f43N8Oo06988@pop.nsacom.net>



> wm_state('zoomed') should maximize on Windows.  For example:
> 
>     >>> import os
>     >>> from Tkinter import *
>     >>> class MaxWin(Tk):
>     ...        def __init__(self):
>     ...            Tk.__init__(self)
>     ...            Label(self, text = "Test Zoom").pack()
>     ...            if os.name == 'nt':
>     ...                self.wm_state('zoomed')
>     ...
>     >>> test = MaxWin()
>     >>> test.mainloop()
> 
> This produced a full size window with a label.

Thanks! I'll try it!

The only problem I can see is that I already have a class declared to put in 
a ScrolledCanvas (maybe I should have mentioned that. Sorry.)

To wit:

#!/usr/bin/python
from Tkinter import *
class ScrolledCanvas(Frame):
	def __init__(self, parent=None, color='white'):
		Frame.__init__(self, parent)
		self.pack(expand=YES, fill=BOTH)
		self.photo=PhotoImage
(file="\windows\desktop\screensaver\wacky3.gif")
		
		canv=Canvas(self, bg=color, relief=SUNKEN)
		canv.config(width=1000, height=700)
		canv.config(scrollregion=(0,0, 300, 1000))
		canv.create_image(10,10, image=self.photo, anchor=NW)

		sbar=Scrollbar(self)
		sbar.config(command=canv.yview)
		canv.config(yscrollcommand=sbar.set)
		sbar.pack(side=RIGHT, fill=Y)
		canv.pack(side=LEFT, expand=YES, fill=BOTH)
		Button(text="quit", command=self.quit).pack(fill=X)
if __name__ == '__main__':ScrolledCanvas().mainloop()

 <stuff removed>

> I don't suggest
> you do this though, because I've had some Unix users tell me maximizing an
> app is very rude.

Good heavens yes it is rude. Unfortunately I am stuck with Win9x for this 
particular experiment! :-) 

What I am trying to do is pop up a window as a screen saverish app that 
displays information rather than a cute bouncing whatsis. I 'compiled' the 
program with py2exe (a wonderful program!) then switched it's extention 
to .scr. Walla! A badly-behaved screensaver! 

I cackled with Maniac Laughter as as my little script popped up after 60 
seconds! :-)

Now all I have to do is come up with code that will only allow one instance 
of the program to run at a time (I know I saw something to the effect in one 
of my Python books, so no one answer this till I give up! ;-)

Of the five parts of the windows screensaver API, I need:

1. provide a description of itself 
2. distinguish between active mode and configuration mode 
3. disallow multiple copies of itself to run 

I just got "Python Programming for Win32", so I hope the answers lie therin. 
(If I can keep from playing with the cool accounting examples he is starting 
us out with. I never thought that stuff would be this interesting....)

Thanks so much!

d

> 
> Good luck,
> Sam
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




From xinch@bigfoot.com  Thu May  3 21:59:09 2001
From: xinch@bigfoot.com (KIU Shueng Chuan)
Date: Thu, 3 May 2001 22:59:09 +0200
Subject: [Tutor] multiplication of polynomials in Python
In-Reply-To: <F242HvoFOAmEaJswFCH00000401@hotmail.com>
Message-ID: <3AF1E2BD.30573.A752372@localhost>

On 3 May 2001, at 2:59, Julieta Rangel wrote:

> I got the integration and differentiation programs to work.  Right now I'm 
> working on multiplication of polynomials.  This is what I have so far:

How about doing addition first?

an example:
(ax^2 + bx + c) * ( dx^2 + ex + f)
= ax^2 * (dx^2 + ex + f) + bx * (dx^2 + ex + f) + c * (dx^2 + ex + f)

Take the first polynomial, split into its separate components and 
multiply each component into the second polynomial. Then at the 
end add them up.

using your representation:
ax^2 * (dx^2 + ex + f) would be the multiplication between
[0,0,a] 
and
[f,e,d] 
which equals
[0,0,a*f, a*e, a*d]
 


From xinch@free.fr  Thu May  3 22:12:56 2001
From: xinch@free.fr (KIU Shueng Chuan)
Date: Thu, 3 May 2001 23:12:56 +0200
Subject: (Fwd) Re: [Tutor] multiplication of polynomials in Python
Message-ID: <3AF1E5F8.25886.A81C23F@localhost>

(I sent this previously with the wrong email addx, apologies if two 
copies get sent)

On 3 May 2001, at 2:59, Julieta Rangel wrote:

> I got the integration and differentiation programs to work.  Right now I'm 
> working on multiplication of polynomials.  This is what I have so far:

How about doing addition first?

an example:
(ax^2 + bx + c) * ( dx^2 + ex + f)
= ax^2 * (dx^2 + ex + f) + bx * (dx^2 + ex + f) + c * (dx^2 + ex + f)

Take the first polynomial, split into its separate components and 
multiply each component into the second polynomial. Then at the 
end add them up.

using your representation:
ax^2 * (dx^2 + ex + f) would be the multiplication between
[0,0,a] 
and
[f,e,d] 
which equals
[0,0,a*f, a*e, a*d]
 



From arcege@speakeasy.net  Thu May  3 22:31:10 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 3 May 2001 17:31:10 -0400 (EDT)
Subject: [Tutor] Cackling with Maniac Laughter (was: starting a tkinter window maximized)
In-Reply-To: <200105032308.f43N8Oo06988@pop.nsacom.net> from "kromag@nsacom.net" at May 03, 2001 04:08:24 PM
Message-ID: <200105032131.f43LVAg05015@dsl092-074-184.bos1.dsl.speakeasy.net>

kromag@nsacom.net wrote

[snipped]
> Good heavens yes it is rude. Unfortunately I am stuck with Win9x for this 
> particular experiment! :-) 
> 
> What I am trying to do is pop up a window as a screen saverish app that 
> displays information rather than a cute bouncing whatsis. I 'compiled' the 
> program with py2exe (a wonderful program!) then switched it's extention 
> to .scr. Walla! A badly-behaved screensaver! 
> 
> I cackled with Maniac Laughter as as my little script popped up after 60 
> seconds! :-)
> 
> Now all I have to do is come up with code that will only allow one instance 
> of the program to run at a time (I know I saw something to the effect in one 
> of my Python books, so no one answer this till I give up! ;-)
> 
> Of the five parts of the windows screensaver API, I need:
> 
> 1. provide a description of itself 
> 2. distinguish between active mode and configuration mode 
> 3. disallow multiple copies of itself to run 
> 
> I just got "Python Programming for Win32", so I hope the answers lie therin. 
> (If I can keep from playing with the cool accounting examples he is starting 
> us out with. I never thought that stuff would be this interesting....)

You might also want to get rid of the window manager's decorations with
wm_transient() and making it on top (focus_set, grab_set_global, tkraise).
Just provide a way of making a way of stopping it (moving mouse, key
press, etc.).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From iamgod@st.jyu.fi  Thu May  3 22:36:33 2001
From: iamgod@st.jyu.fi (Risto Peranen)
Date: Fri, 4 May 2001 00:36:33 +0300 (EEST)
Subject: [Tutor] Python and web-pages?
In-Reply-To: <E14vLXS-0000Ec-00@mail.python.org>
Message-ID: <Pine.LNX.4.33.0105040012130.31259-100000@silmu.st.jyu.fi>

I wrote before 'can you make dynamic web-pages with python?'
and I realized my question was terrible wrong.
What MENT was something like
'How do you make web-service for your page?'

I am working on game-project and I want to make web pages,
where my co-coders can make AI-scripts with graphical tools.
(It something dull and boring, I don't bother you with details.)
I want make python script that receives data from page, and translate
it into form the game-AI-gore can use it.
here is drawing: (page will be written in Java )
_________________
| My web pages	|----> text_file for py-script
|_______________|		/
			      /
			    /
			  /
		________/_____				 ____________
		| my py-script|->binary file for gore -> | AI-gore  |
		|_____________| 			 |__________|
Sure I could do ALL task in Java but it's not the tool I'm looking
for. Prosessing of the text-files is (too) easy to do with
python. Sure I could build text-prosessor straithly to AI-gore,
but the AI-scripts would have to be prosessed every time when starting
then game which would cost lots and lots of valuable time. (Besides
gore is huge enough without any decorations)
Can someone help me?

That all folks. Good night
Risto Peranen



From sheila@thinkspot.net  Fri May  4 00:27:00 2001
From: sheila@thinkspot.net (Sheila King)
Date: Thu, 03 May 2001 16:27:00 -0700
Subject: [Tutor] inserting items into a list
In-Reply-To: <F84YLowspDKicUbvBDx00000d7e@hotmail.com>
References: <F84YLowspDKicUbvBDx00000d7e@hotmail.com>
Message-ID: <6245C1B04BC@kserver.org>

Julieta,

I really wouldn't go about this, quite that way. It isn't necessary to
generate separate lists, filled with zeros, and then sum those to get your
result. I will repeat here, something that I posted a few days back. Perhaps
you missed it, because there was so much new stuff for you to learn at that
point.

Posted on April 29th:

SK> In order to multiply two polynomials, you would need to take each 
SK> coefficient in the one list and multiply it be each coefficient in the 
SK> other list.
SK> 
SK> So, your suggested problem
SK> (2x^3 + x^2 + 3x + 2) * (x^2 + 1)
SK> 
SK> might look like this:
SK> p1 = [2, 3, 1, 2]
SK> p2 = [1, 0, 1]
SK> 
SK> I would note, that since you are multiplying a 3rd degree polynomial by a 
SK> 2nd degree one, that your result should be fifth degree. You could find 
SK> this out by doing len(p1)-1  added to len(p2)-1 then create a new
SK> list to store the results of your multiplication. Give it length of
SK> 5 and initialize all spots to zero. Let's call this new list for the
SK> result, p3.
SK> 
SK> Now create a loop to go through each element of p1. 
SK> Start with p1[0] and multiply it by p2[0] and add the result to p3[0].
SK> Now multiply p1[0] with p2[1] and add the result to p3[1].
SK> Now multiply p1[0] with p2[2] and add the result to p3[2].
SK> 
SK> All done with p1[0]. Now the loop moves to p1[1].
SK> Multiply p1[1] with p2[0] and add the result to p3[1].
SK> Now multiply p1[1] with p2[1] and add the result to p3[2].
SK> Now multiply p1[1] with p2[2] and add the result to p3[3].
SK> 
SK> Note, that the indices indicate the exponent on your variable. So, p1[1] 
SK> is an x^1 coefficient and p2[2] is an x^2 coefficient, so the result needs
SK> to be an x^3 coefficient, so add that result to p3[3].
SK> 
SK> Proceed on to p1[2] and p1[3] in the same manner. So, you have a loop on 
SK> p1, and inside that loop is another loop that iterates over all the 
SK> indices in p2.
SK> 
SK> I hope this is helpful.

If what I wrote above isn't clear, please ask and I will try to explain it
better.

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

On Thu, 03 May 2001 12:37:35 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com>  wrote about [Tutor] inserting items into a list:

:I'm trying to come up with a definition for multiplication of polynomials. 
:Say I want to multiply (2 + 3x + x^2 + 2x^3) times (1+0x+2x^2), so I created 
:two lists of coefficients. List 1 =[2,3,1,2] and list 2= [1,0,2].  To 
:multiply these two I need to take each element from list 1 and multiply it 
:by all of the elements of list 2, and create a new list for each result.  
:For example, by multiplying the first element of list 1 by all of the 
:elemens of list 2 I would get [2,0,4], from the second #, I would get 
:[3,0,6], then [1,0,2] and finally [2,0,4].  I need to find a way to insert 3 
:zeroes at the end of list [2,0,4]; 1 zero at the beginning and two at the 
:end of [3,0,6]; 2 zeroes a the beginning and one at the end of [1,0,2], and 
:finally 3 zeroes at the beginning of [2,0,4].  This way the new lists would 
:look like:
:
:[2,0,4,0,0,0]
:[0,3,0,6,0,0]
:[0,0,1,0,2,0]
:[0,0,0,2,0,4]
:
:and it would be just a matter of adding those lists to figure out the 
:result:  2 + 3x + 5x^2 + 8x^3 + 2x^4 + 4x^5.  As you can see from the 
:subject, my problem is inserting those zeroes at the specific locations.  
:Can you help me?
:
:Julieta
:
:If you notice, there is a little pattern
:_________________________________________________________________
:Get your FREE download of MSN Explorer at http://explorer.msn.com
:
:
:_______________________________________________
:Tutor maillist  -  Tutor@python.org
:http://mail.python.org/mailman/listinfo/tutor



From julieta_rangel@hotmail.com  Fri May  4 00:27:25 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Thu, 03 May 2001 18:27:25 -0500
Subject: [Tutor] range
Message-ID: <F10bHbU0wOcVqws1QJK000015fd@hotmail.com>

I have the following program but when I run it it only runs half-ways.  It 
displays a message of out of range.  Can you tell me what I'm doing wrong?

class Poly:
    def __init__ ( self, v='x' , c = [0]):
        """__init__():
        Initializes a polynomial
        Default variable is x
        Default polynomial is zero"""
        self.var = v
        self.coef = c
        self.deg = len(c)-1
        self.length = len(c)
    def __str__ (self):
        """__str__():
        Converts a polynomial into a string"""
        x = `self.coef[0]`
        for i in range (1,self.deg+1):
            x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
        return x


    def integrate(self):
        """Input:  an instance of a polynommial
        Output: a polynomial that is the integral of the input      
polynomial
        Side Effects: None"""

    	coef=[0]
        self.deg= self.deg +1
        for i in range(0,self.deg):
            coef.append(self.coef[i]/float(i+1))
        self.coef= coef

    def Derivative(self):
        """Input: an instance of a polynomial
    	Output: a polynomial that is the derivative of the input polynomial
        side Effects: None"""
    	coef=[1]
    	self.deg= self.deg +1
    	if self.deg==0:
     	   coef=[0]
    	else:
           for i in range(0,self.deg-1):
              coef.append((i+1)*self.coef[i+1])
        self.coef= coef


degree = input('Enter the degree of your polynomial')
coef=[]
for i in range (0,degree + 1):
    coefficient = input('Enter the coefficient for x^ %i ? ' %i)
    coef.append(coefficient)

s= Poly (c = coef)
m= Poly (c = coef)
s.integrate()
m.Derivative()
print "the integral of your polynomial is:"
print "c +",s
print "the derivative of your polynomial is:",m

Julieta



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From kromag@nsacom.net  Fri May  4 04:53:32 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Thu, 3 May 2001 20:53:32 -0700 (PDT)
Subject: [Tutor] starting a tkinter window maximized
Message-ID: <200105040353.f443rWo07415@pop.nsacom.net>

Harry Kattz <gibbs05@flash.net> said: 

> wm_state('zoomed') should maximize on Windows.  For example:
> 
>     >>> import os
>     >>> from Tkinter import *
>     >>> class MaxWin(Tk):
>     ...        def __init__(self):
>     ...            Tk.__init__(self)
>     ...            Label(self, text = "Test Zoom").pack()
>     ...            if os.name == 'nt':
>     ...                self.wm_state('zoomed')
>     ...
>     >>> test = MaxWin()
>     >>> test.mainloop()
> 
> This produced a full size window with a label.
> 

Hrm.. Does this work in win9x as opposed to NT? This does not appear to work 
on my 95 and 98 boxes.

d


From tbaruch@mindless.com  Fri May  4 02:45:34 2001
From: tbaruch@mindless.com (Timothy M. Brauch)
Date: Thu, 03 May 2001 21:45:34 -0400
Subject: [Tutor] Linux Programs
Message-ID: <3AF209BE.6BE4C132@mindless.com>

Okay, I'm slowly making a move from Windows to (Red Hat 7.0) Linux, but
there are somethings in Linux that I just can't figure out how to do. 
One of these things is using Python.

I can open the Python interpreter (by typing 'python' in the terminal
window).  I can even open Idle when I am running xWindows (I just type
'idle' in the terminal).  And, I can write and run programs in Idle.

But, the problem comes after that.  I can't get my programs to run
outside of Idle.  I know I have to add a line at the beginning of each
python file, but I don't know what that line is.  When I wrote Python
files for a class on the (Mandrake) Linux machines, the line was:

#!/usr/bin/python

This line doesn't work on my computer.  All I get is the file openned in
a text editor.  I have Python installed in /usr/lib/python1.5/ because
that is where it was installed when I installed Linux.  /usr/bin/python
and /usr/bin/python1.5 both exist, but putting '#!/usr/bin/python' or
'#!/usr/bin/python1.5' still opens the files in a text editor, even if I
saved the file as 'test.py'

Can anyone help me?  I need to be able to write Python programs so I can
start my assignment of creating the Processor Simulator.

 - Tim


From kauphlyn@speakeasy.org  Fri May  4 03:22:39 2001
From: kauphlyn@speakeasy.org (Daniel Coughlin)
Date: Thu, 3 May 2001 19:22:39 -0700 (PDT)
Subject: [Tutor] Linux Programs
In-Reply-To: <3AF209BE.6BE4C132@mindless.com>
Message-ID: <Pine.LNX.4.33L2.0105031910150.19172-100000@grace.speakeasy.net>

I am guessing you have permissions set up correctly, but if not
type in
man chmod
at the command prompt to figure out how to get the permissions set correctly.

secondly and most likely the directory youre running test.py out of probably
isnt
in your path.
you can check this by typing
echo $PATH
at the command prompt
to add the directory to your path you can type
export PATH=$PATH: /home/myuserdirecory/mypython
or whatever your directory is.
you should also be able to run your python program by typing
./test.py
at the command prompt even if you dont change your path.

hope this helps

Daniel

On Thu, 3 May 2001, Timothy M. Brauch wrote:

> Okay, I'm slowly making a move from Windows to (Red Hat 7.0) Linux, but
> there are somethings in Linux that I just can't figure out how to do.
> One of these things is using Python.
>
> I can open the Python interpreter (by typing 'python' in the terminal
> window).  I can even open Idle when I am running xWindows (I just type
> 'idle' in the terminal).  And, I can write and run programs in Idle.
>
> But, the problem comes after that.  I can't get my programs to run
> outside of Idle.  I know I have to add a line at the beginning of each
> python file, but I don't know what that line is.  When I wrote Python
> files for a class on the (Mandrake) Linux machines, the line was:
>
> #!/usr/bin/python
>
> This line doesn't work on my computer.  All I get is the file openned in
> a text editor.  I have Python installed in /usr/lib/python1.5/ because
> that is where it was installed when I installed Linux.  /usr/bin/python
> and /usr/bin/python1.5 both exist, but putting '#!/usr/bin/python' or
> '#!/usr/bin/python1.5' still opens the files in a text editor, even if I
> saved the file as 'test.py'
>
> Can anyone help me?  I need to be able to write Python programs so I can
> start my assignment of creating the Processor Simulator.
>
>  - Tim
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From arcege@speakeasy.net  Fri May  4 03:30:17 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 3 May 2001 22:30:17 -0400 (EDT)
Subject: [Tutor] range
In-Reply-To: <F10bHbU0wOcVqws1QJK000015fd@hotmail.com> from "Julieta Rangel" at May 03, 2001 06:27:25 PM
Message-ID: <200105040230.f442UHk01024@dsl092-074-184.bos1.dsl.speakeasy.net>

Julieta Rangel wrote
> 
> I have the following program but when I run it it only runs half-ways.  It 
> displays a message of out of range.  Can you tell me what I'm doing wrong?
> 
> class Poly:
>     def __init__ ( self, v='x' , c = [0]):
>         """__init__():
>         Initializes a polynomial
>         Default variable is x
>         Default polynomial is zero"""
>         self.var = v
>         self.coef = c
>         self.deg = len(c)-1
>         self.length = len(c)
>     def __str__ (self):
>         """__str__():
>         Converts a polynomial into a string"""
>         x = `self.coef[0]`
>         for i in range (1,self.deg+1):
>             x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
>         return x

All sequences in Python start at 0 and go up to len(seq)-1 for indices.
Your range starts at 1 and goes to len(seq).  The last index doesn't
exist in the sequence.  Try changing the range to (1, self.deg).

>     def integrate(self):
>         """Input:  an instance of a polynommial
>         Output: a polynomial that is the integral of the input      
> polynomial
>         Side Effects: None"""
> 
>     	coef=[0]
>         self.deg= self.deg +1
>         for i in range(0,self.deg):
>             coef.append(self.coef[i]/float(i+1))
>         self.coef= coef
> 
>     def Derivative(self):
>         """Input: an instance of a polynomial
>     	Output: a polynomial that is the derivative of the input polynomial
>         side Effects: None"""
>     	coef=[1]
>     	self.deg= self.deg +1
>     	if self.deg==0:
>      	   coef=[0]
>     	else:
>            for i in range(0,self.deg-1):
>               coef.append((i+1)*self.coef[i+1])
>         self.coef= coef

I think this is the problem.  You increment self.deg, but don't add as
many values as necessary.  Try decrementing self.deg.

>From pdb:
(Pdb) cont
the integral of your polynomial is:
c +  1
2
0+1.0x^1+1.0x^2
the derivative of your polynomial is:  1
2
IndexError: 'list index out of range'
> <string>(1)?()->2
(Pdb) where
> <string>(1)?()->2
  /tmp/try.py(93)?()->2
-> print "the derivative of your polynomial is:",m
  /tmp/try.py(53)__str__()
-> x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
(Pdb) down
> /tmp/try.py(93)?()->2
-> print "the derivative of your polynomial is:",m
(Pdb) down
> /tmp/try.py(53)__str__()
-> x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
(Pdb) print self.coef
[1, 2]
(Pdb) print i
2
(Pdb) print self.deg
2
(Pdb)

> degree = input('Enter the degree of your polynomial')
> coef=[]
> for i in range (0,degree + 1):
>     coefficient = input('Enter the coefficient for x^ %i ? ' %i)
>     coef.append(coefficient)
> 
> s= Poly (c = coef)
> m= Poly (c = coef)
> s.integrate()
> m.Derivative()
> print "the integral of your polynomial is:"
> print "c +",s
> print "the derivative of your polynomial is:",m

Also, think about changing things such that the integrate and derivative
methods return _new_ Poly objects and to _not_ modify 'self'.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From wall@adinet.com.uy  Fri May  4 03:41:50 2001
From: wall@adinet.com.uy (Walter Moreira)
Date: Thu, 3 May 2001 23:41:50 -0300
Subject: [Tutor] Few simple question.
In-Reply-To: <001501c0d37e$424a9ce0$6a01a8c0@com.my>; from arazak@kansai.com.my on Thu, May 03, 2001 at 11:07:54AM +0800
References: <001501c0d37e$424a9ce0$6a01a8c0@com.my>
Message-ID: <20010503234150.B23778@casa.parque>

On Thu, May 03, 2001 at 11:07:54AM +0800, Mr. Razak wrote:
> 
> 1). I want to know how to change colour, i mean how to used colour in python language.
> 
> 2). How to used coordinate system, or may be there is a module i can used to help me. For example on the computer screen at a location row=5, column 35, I want to print 'Hello world'. How to do that.
> 
> 3). How to create box and how place it on the computer screen on the desirerable location.

You can take a look at the Demo/curses directory of the Python
distribution. There are examples for using color and boxes and printing in
coordinates.

You can use the curses module just with

  >>> import curses

But, if you are looking for graphical windows, then look in Doc/tkinter. I
think curses is easier.
Hope it helps:
			-- Walter

-- 
--------------
Walter Moreira  <> Centro de Matematica  <> Universidad de la Republica
email: walterm@cmat.edu.uy <> HomePage: http://www.cmat.edu.uy/~walterm
                 +-----------------------------------------------------
        /OD\_    |   Contrary to popular belief, Unix is user friendly.
 O o . |_o_o_)   |   It just happens to be very selective about who its
                 |   friends are.                         -- Kyle Hearn
               --+--


From rick@niof.net  Fri May  4 04:05:17 2001
From: rick@niof.net (Rick Pasotto)
Date: Thu, 3 May 2001 23:05:17 -0400
Subject: [Tutor] Linux Programs
In-Reply-To: <3AF209BE.6BE4C132@mindless.com>; from tbaruch@mindless.com on Thu, May 03, 2001 at 09:45:34PM -0400
References: <3AF209BE.6BE4C132@mindless.com>
Message-ID: <20010503230517.E13123@tc.niof.net>

On Thu, May 03, 2001 at 09:45:34PM -0400, Timothy M. Brauch wrote:
> Okay, I'm slowly making a move from Windows to (Red Hat 7.0) Linux, but
> there are somethings in Linux that I just can't figure out how to do. 
> One of these things is using Python.
> 
> I can open the Python interpreter (by typing 'python' in the terminal
> window).  I can even open Idle when I am running xWindows (I just type
> 'idle' in the terminal).  And, I can write and run programs in Idle.
> 
> But, the problem comes after that.  I can't get my programs to run
> outside of Idle.  I know I have to add a line at the beginning of each
> python file, but I don't know what that line is.  When I wrote Python
> files for a class on the (Mandrake) Linux machines, the line was:
> 
> #!/usr/bin/python

I think the prefered way is:

#!/usr/bin/env python

This should find the appropriate python no matter where it's located.

> This line doesn't work on my computer.  All I get is the file openned in
> a text editor.

Huh? This doesn't make sense to me. In unix you don't get an editor
unless you *ask* for an editor.

How are you trying to run the file?  What is your command line? Or are
you in X and clicking on an icon?

Even without the '#!' line and regardless of the permissions (well, you
do need 'read' permission) you can run your program by entering:

python test.py

-- 
"The financial policy of the welfare state requires that there be no
way for the owners of wealth to protect themselves.  This is the
shabby secret of the welfare statists' tirades against gold.   Deficit
spending is simply a scheme for the 'hidden' confiscation of wealth.
Gold stands in the way of this insidious process.   It stands as a
protector of property rights."
		-- Alan Greenspan
		   Rick Pasotto email: rickp@telocity.com


From tbaruch@mindless.com  Fri May  4 04:48:33 2001
From: tbaruch@mindless.com (Timothy M. Brauch)
Date: Thu, 03 May 2001 23:48:33 -0400
Subject: [Tutor] Linux Programs
References: <3AF209BE.6BE4C132@mindless.com> <20010503230517.E13123@tc.niof.net>
Message-ID: <3AF22691.50E57499@mindless.com>

Rick Pasotto wrote:
> 
> I think the prefered way is:
> 
> #!/usr/bin/env python
> 
> This should find the appropriate python no matter where it's located.
> 
> > This line doesn't work on my computer.  All I get is the file openned in
> > a text editor.
> 
> Huh? This doesn't make sense to me. In unix you don't get an editor
> unless you *ask* for an editor.
> 
> How are you trying to run the file?  What is your command line? Or are
> you in X and clicking on an icon?
> 
> Even without the '#!' line and regardless of the permissions (well, you
> do need 'read' permission) you can run your program by entering:
> 
> python test.py

Yeah, I realized that right after I sent this, I probably wouldn't be
able to just click on an icon in X, like I was used to in Windows.  But,
I am also having problems using command line.  Still, I can run the
program using 'python test.py' if I am in the folder 'test.py' is
stored.  I am still wondering if it is possible to just type 'test.py'
(as long as I am in the folder, or preferrably, anywhere).  I tried
using 'export PATH=$PATH: /home/tbrauch/python_files' but I get the
following error message

bash: export: `/home/tbrauch/python_files': not a valid identifier

I'm not trying to turn this into a Linux tutorial, I just hope to get
Python working on my new computer...

 - Tim


From dyoo@hkn.eecs.berkeley.edu  Fri May  4 06:11:34 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 3 May 2001 22:11:34 -0700 (PDT)
Subject: [Tutor] Cackling with Maniac Laughter (was: starting a tkinter
 window maximized)
In-Reply-To: <200105032308.f43N8Oo06988@pop.nsacom.net>
Message-ID: <Pine.LNX.4.21.0105032210350.21621-100000@hkn.eecs.berkeley.edu>

> Good heavens yes it is rude. Unfortunately I am stuck with Win9x for this 
> particular experiment! :-) 
> 
> What I am trying to do is pop up a window as a screen saverish app that 
> displays information rather than a cute bouncing whatsis. I 'compiled' the 
> program with py2exe (a wonderful program!) then switched it's extention 
> to .scr. Walla! A badly-behaved screensaver! 

If you're interested in doing animation/game stuff in Python, you might be
interested in pygame:

    http://pygame.seul.org/

It should work on Windows as well, though I haven't tried yet.



From dyoo@hkn.eecs.berkeley.edu  Fri May  4 06:15:15 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 3 May 2001 22:15:15 -0700 (PDT)
Subject: [Tutor] Linux Programs
In-Reply-To: <3AF209BE.6BE4C132@mindless.com>
Message-ID: <Pine.LNX.4.21.0105032212320.21621-100000@hkn.eecs.berkeley.edu>

On Thu, 3 May 2001, Timothy M. Brauch wrote:
> 
> But, the problem comes after that.  I can't get my programs to run
> outside of Idle.  I know I have to add a line at the beginning of each
> python file, but I don't know what that line is.  When I wrote Python
> files for a class on the (Mandrake) Linux machines, the line was:
> 
> #!/usr/bin/python
> 
> This line doesn't work on my computer.  All I get is the file openned in
> a text editor.  I have Python installed in /usr/lib/python1.5/ because
> that is where it was installed when I installed Linux.  /usr/bin/python
> and /usr/bin/python1.5 both exist, but putting '#!/usr/bin/python' or
> '#!/usr/bin/python1.5' still opens the files in a text editor, even if I
> saved the file as 'test.py'
> 
> Can anyone help me?  I need to be able to write Python programs so I can
> start my assignment of creating the Processor Simulator.

One other thing you might need to do is make the file "executable" ---
that is, you need to flag it so that Linux knows that it's supposed to be
run as a program.  At the moment, Mandrake's file manager probably still
thinks that it should be treated as a text document.


If you know about the command line shell, try this:

   $ chmod +x test.py

which tells the system to flag the "eXecutable" bit on a file.  This
flagging, combined with the magic line "#!/usr/bin/python", should do the
trick.



From dyoo@hkn.eecs.berkeley.edu  Fri May  4 06:33:31 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 3 May 2001 22:33:31 -0700 (PDT)
Subject: [Tutor] Guido and ESR post to Useless Python
In-Reply-To: <000a01c0d3f5$ef481220$de00a8c0@planhouse5>
Message-ID: <Pine.LNX.4.21.0105032233120.22429-100000@hkn.eecs.berkeley.edu>

On Thu, 3 May 2001, Rob Andrews wrote:

> I'll get the code posted tonight, but wanted to go ahead and spread a little
> glee. Guido van Rossum and Eric S. Raymond (Open Source programming deity)
> have both submitted code to be posted on Useless Python today.

Congratulations!  This is very cool.



From dyoo@hkn.eecs.berkeley.edu  Fri May  4 06:41:33 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 3 May 2001 22:41:33 -0700 (PDT)
Subject: [Tutor] inserting items into a list
In-Reply-To: <F84YLowspDKicUbvBDx00000d7e@hotmail.com>
Message-ID: <Pine.LNX.4.21.0105032233410.22429-100000@hkn.eecs.berkeley.edu>

On Thu, 3 May 2001, Julieta Rangel wrote:

> [3,0,6], then [1,0,2] and finally [2,0,4].  I need to find a way to insert 3 
> zeroes at the end of list [2,0,4]; 1 zero at the beginning and two at the 
> end of [3,0,6]; 2 zeroes a the beginning and one at the end of [1,0,2], and 
> finally 3 zeroes at the beginning of [2,0,4].  This way the new lists would 
> look like:
> 
> [2,0,4,0,0,0]
> [0,3,0,6,0,0]
> [0,0,1,0,2,0]
> [0,0,0,2,0,4]
> 
> and it would be just a matter of adding those lists to figure out the 
> result:  2 + 3x + 5x^2 + 8x^3 + 2x^4 + 4x^5.  As you can see from the 
> subject, my problem is inserting those zeroes at the specific locations.  
> Can you help me?


How about something like this?

###
def makeZeroPaddedList(mylist, position, length):
    """This function should take mylist, and splice it into
       a list of zeros at a specific location."""
    newlist = [0] * length
    newlist[position:position + len(mylist)] = mylist
    return newlist
###


Let's test it out on the interpreter:

###
>>> makeZeroPaddedList([1, 2, 3], 0, 10)
[1, 2, 3, 0, 0, 0, 0, 0, 0, 0]
>>> makeZeroPaddedList([1, 2, 3], 1, 10)
[0, 1, 2, 3, 0, 0, 0, 0, 0, 0]
>>> makeZeroPaddedList([1, 2, 3], 2, 10)
[0, 0, 1, 2, 3, 0, 0, 0, 0, 0]
>>> makeZeroPaddedList([1, 2, 3], 3, 10)
[0, 0, 0, 1, 2, 3, 0, 0, 0, 0]
>>> makeZeroPaddedList([1, 2, 3], 4, 10)
[0, 0, 0, 0, 1, 2, 3, 0, 0, 0]
###


The idea is to make up a list that's filled only with zeros, and then plop
our original list into it.  We can control both the position of the
plopping, and the length of the resulting list.

Hope this helps!



From bsass@freenet.edmonton.ab.ca  Fri May  4 06:42:33 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Thu, 3 May 2001 23:42:33 -0600 (MDT)
Subject: [Tutor] Linux Programs
In-Reply-To: <3AF22691.50E57499@mindless.com>
Message-ID: <Pine.LNX.4.33.0105032301020.7992-100000@bms>

On Thu, 3 May 2001, Timothy M. Brauch wrote:

> Rick Pasotto wrote:
> >
> > I think the prefered way is:
> >
> > #!/usr/bin/env python
> >
> > This should find the appropriate python no matter where it's located.

Ya.  /usr/bin/env should exist on every(?) unix-like system, it will
find the interpreter, which could be in /usr/bin, /usr/local/bin,
etc.

I recommend using: "#!/usr/bin/env pythonX.Y", if the script will only
work with python version X.Y - you may only have one version of python
installed, I have three.

> > > This line doesn't work on my computer.  All I get is the file openned in
> > > a text editor.
> >
> > Huh? This doesn't make sense to me. In unix you don't get an editor
> > unless you *ask* for an editor.
> >
> > How are you trying to run the file?  What is your command line? Or are
> > you in X and clicking on an icon?
> >
> > Even without the '#!' line and regardless of the permissions (well, you
> > do need 'read' permission) you can run your program by entering:
> >
> > python test.py
>
> Yeah, I realized that right after I sent this, I probably wouldn't be
> able to just click on an icon in X, like I was used to in Windows.  But,

That will depend on which window manager/desktop you are using.
I'm using KDE and can get an icon to do pretty much anything when
clicked on (expect to fiddle a bit, downside of not having a central
controling authority that dictates what is "right").

> I am also having problems using command line.  Still, I can run the
> program using 'python test.py' if I am in the folder 'test.py' is
> stored.  I am still wondering if it is possible to just type 'test.py'

A period (".") is defined as the current working directory.  So you
can do "./test.py" to run something in the dir you are in (resist the
temptation to add "." to your PATH).  Otherwise you use the full path,
or put (or symlink) the programs in a dir on your path (/usr/local/bin
is a good choice, and adding a bin dir to your home dir is fairly
common).

> (as long as I am in the folder, or preferrably, anywhere).  I tried
> using 'export PATH=$PATH: /home/tbrauch/python_files' but I get the
> following error message
>
> bash: export: `/home/tbrauch/python_files': not a valid identifier

try: "export PATH=$PATH:/home/tbrauch/bin"
instead (or python_files, whatever turns your crank).
i.e., drop the space and the single quotes, bash sees the /home/...
bit as an environment var to be exported.

> I'm not trying to turn this into a Linux tutorial, I just hope to get
> Python working on my new computer...

<shrug> :)


- Bruce



From sheila@thinkspot.net  Fri May  4 06:48:41 2001
From: sheila@thinkspot.net (Sheila King)
Date: Thu, 03 May 2001 22:48:41 -0700
Subject: [Tutor] inserting items into a list
In-Reply-To: <6245C1B04BC@kserver.org>
References: <F84YLowspDKicUbvBDx00000d7e@hotmail.com> <6245C1B04BC@kserver.org>
Message-ID: <9839C343BF@kserver.org>

On Thu, 03 May 2001 16:27:00 -0700, Sheila King <sheila@thinkspot.net>  wrote
about Re: [Tutor] inserting items into a list:

:SK> I would note, that since you are multiplying a 3rd degree polynomial by a 
:SK> 2nd degree one, that your result should be fifth degree. You could find 
:SK> this out by doing len(p1)-1  added to len(p2)-1 then create a new
:SK> list to store the results of your multiplication. Give it length of
:SK> 5 and initialize all spots to zero. Let's call this new list for the
:SK> result, p3.

Er... there's an error in what I suggest above. (Maybe you caught it already?)
Multiplying a 3rd degree poly by a 2nd degree poly does indeed give a 5th
degree poly.

HOWEVER, for the resulting 5th deg poly, you need to create a list of length
6, NOT length 5.

Doh!

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



From jsc_lists@rock-tnsc.com  Fri May  4 23:12:55 2001
From: jsc_lists@rock-tnsc.com (Jethro Cramp)
Date: Fri, 4 May 2001 14:12:55 -0800
Subject: [Tutor] Unpickling a Pickled Object
Message-ID: <01050414125502.00931@jsclaptop>

When a pickled object is unpickled does __init__  get called. I can 
think of half a dozen reasons why it shouldn't, but just thought I'd ask.

TIA,

Jethro


From learnpython@hotmail.com  Fri May  4 07:28:06 2001
From: learnpython@hotmail.com (Learn Python)
Date: Fri, 04 May 2001 06:28:06 -0000
Subject: [Tutor] Python book suggestion please
Message-ID: <F247PdHfKsp3MSi6xzm00000537@hotmail.com>

hi all,

i'm new to python and i do java @ work.
I'm looking to buy a good / probably the best reference
book available right now in the market. I checked out
a few titles and arrived at the follwing titles:

1. Programming Python 2nd edition (orielly)
2. Python programmer's refernce (Insider Press)..by Beazely ( this is not 
uptodate i guess since it does'nt cover 2.0)

C'd someone please suggest a good buy. Any thoughts?

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



From sburr@mac.com  Fri May  4 07:58:03 2001
From: sburr@mac.com (Steven Burr)
Date: Thu, 3 May 2001 23:58:03 -0700
Subject: [Tutor] Cackling with Maniac Laughter (was: starting a tkinter window maximized)
In-Reply-To: <200105032308.f43N8Oo06988@pop.nsacom.net>
Message-ID: <20010504065723.LWVD18489.femail17.sdc1.sfba.home.com@localhost>

On Thursday, May 3, 2001, at 04:08 PM, <kromag@nsacom.net> wrote:

> I cackled with Maniac Laughter as as my little script popped up after 60
> seconds! :-)

Show of hands.  Who else would like to see "Mr. Yoo" substitute 
*cackling with maniac laughter* for *grin*?

Sorry, but I wrote what seemed like 100 e-mails at work today, and I 
can't seem to stop.  I'll go bother someone else now.


From toodles@yifan.net  Fri May  4 09:10:26 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Fri, 4 May 2001 16:10:26 +0800
Subject: [Tutor] Unpickling a Pickled Object
In-Reply-To: <01050414125502.00931@jsclaptop>
Message-ID: <FPEHJJPEEOIPMAHOADBKAEDKCDAA.toodles@yifan.net>

Hi Jethro,

I'll just post what it says in the documentation:

"""
When a pickled class instance is unpickled, its __init__() method is
normally not invoked. Note: This is a deviation from previous versions of
this module; the change was introduced in Python 1.5b2. The reason for the
change is that in many cases it is desirable to have a constructor that
requires arguments; it is a (minor) nuisance to have to provide a
__getinitargs__() method.

If it is desirable that the __init__() method be called on unpickling, a
class can define a method __getinitargs__(), which should return a tuple
containing the arguments to be passed to the class constructor (__init__()).
This method is called at pickle time; the tuple it returns is incorporated
in the pickle for the instance.
"""

I hope that helps =)

Andrew

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Jethro Cramp
> Sent: Saturday, 5 May 2001 6:13 AM
> To: Tutor@python.org
> Subject: [Tutor] Unpickling a Pickled Object
>
>
> When a pickled object is unpickled does __init__  get called. I can
> think of half a dozen reasons why it shouldn't, but just thought I'd ask.
>
> TIA,
>
> Jethro
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From learnpython@hotmail.com  Fri May  4 09:19:18 2001
From: learnpython@hotmail.com (Learn Python)
Date: Fri, 04 May 2001 08:19:18 -0000
Subject: [Tutor] Unpickling a Pickled Object
Message-ID: <F46ecm9t0CI76rOJhKP00009564@hotmail.com>

hi Jethro,

c'd you please tell why you think the __init__ s'd'nt be called?
If i'm doing some initialisation in __init__
whch in turn will be used by other methods then the unpickling w'd'nt
be of much use right?
my code might fail bcos certain things did'nt get initialized.
Do we have a
private void readObject() java equivalent in python? which w'd automatically 
get called when we "deserialize" the object / in this case "unpickle". Then 
we can probably initialize some stuff there?

karthik




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



From rwilkins@bigpond.net.au  Fri May  4 10:04:39 2001
From: rwilkins@bigpond.net.au (Richard Wilkins)
Date: Fri, 4 May 2001 17:04:39 +0800
Subject: [Tutor] Sort of non-related...but in a way, related too...*grins*
Message-ID: <FPEHJJPEEOIPMAHOADBKAEDLCDAA.rwilkins@bigpond.net.au>

Hi folks,

I'm releasing my MUD server package to Useless, the main framework is
set...it runs fairly smoothly
(as far as I'm concerned!)

What I need to know is, what is the most commonly used archiving
file-type...tarballs? I'm coming from a completely Windows background, so I
just use zip. If someone would kindly tell me which one to use, if it
actually matters, then I'll submit it...

Thanks,

Andrew




From dyoo@hkn.eecs.berkeley.edu  Fri May  4 10:03:56 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Fri, 4 May 2001 02:03:56 -0700 (PDT)
Subject: [Tutor] Python book suggestion please
In-Reply-To: <F247PdHfKsp3MSi6xzm00000537@hotmail.com>
Message-ID: <Pine.LNX.4.21.0105040144310.26188-100000@hkn.eecs.berkeley.edu>

On Fri, 4 May 2001, Learn Python wrote:

> i'm new to python and i do java @ work.

Nice to meet you!


> I'm looking to buy a good / probably the best reference
> book available right now in the market. I checked out
> a few titles and arrived at the follwing titles:
> 
> 1. Programming Python 2nd edition (orielly)
> 2. Python programmer's refernce (Insider Press)..by Beazely ( this is not 
> uptodate i guess since it does'nt cover 2.0)

The following is just my opinions, so please take it with a grain of salt:

    1.  Programming Python is big and heavy.  Usually, this is a good
thing because it allows the author to be comprehensive.  It's also an
advantage if you want to improve your hand grip.  The book seems a bit too
spread out, so it might not be useful as a reference.  It's good reading,
but if you're in a hurry, this might not be your first choice.

    2.  "Learning Python" by Mark Lutz is a good book if you're already
familiar with a computer language.  It's not too heavy, unlike Programming
Python, and it hits the core features of Python very quickly.  I highly
recommend it.

    3.  David Beazley's "Python Essential Reference" is amazingly well
organized.  I find myself looking at it if I can't get at online
documentation. However, it is also targeted on Python 1.52, so I hope that
Beazley updates it soon.  It's a very good reference, and easy to find
things, very informative, and condensed.

    4.  Wesley Chun has just written "Core Python Programming", and since
he's one of the tutor@python.org list operators, it would be simply
criminal not to mention his book.  (Ahem.)  I've heard good things about
it, but haven't had the chance to buy it yet.


However, you might not even need to buy a book: check out the Python
tutorial:

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

Its intended audience are those who already know how to program in a
language like C, C++, Perl, or Java, so it should be very useful for you.
You may be able to learn (or at least, see) the core of Python in an hour
by going through the tutorial.

Also, the library reference is downloadable from here:

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

so you can always keep a local copy on your computer.


If you have any questions, feel free to ask us on tutor.  Good luck to
you.



From rob@jam.rr.com  Fri May  4 11:53:08 2001
From: rob@jam.rr.com (rob@jam.rr.com)
Date: Fri, 04 May 2001 05:53:08 -0500
Subject: [Tutor] Python book suggestion please
References: <F247PdHfKsp3MSi6xzm00000537@hotmail.com>
Message-ID: <3AF28A14.2A492739@jam.rr.com>

I know you asked for a book recommendation, but there is a good bit of
online reference material available, such as the good list found at:

http://www.lowerstandard.com/python/howtolinks.html

Rob

Learn Python wrote:
> 
> hi all,
> 
> i'm new to python and i do java @ work.
> I'm looking to buy a good / probably the best reference
> book available right now in the market. I checked out
> a few titles and arrived at the follwing titles:
> 
> 1. Programming Python 2nd edition (orielly)
> 2. Python programmer's refernce (Insider Press)..by Beazely ( this is not
> uptodate i guess since it does'nt cover 2.0)
> 
> C'd someone please suggest a good buy. Any thoughts?
> 
> thanks,
> karthik.
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From LloydJ@missouri.edu  Fri May  4 12:01:39 2001
From: LloydJ@missouri.edu (Lloyd, Jamie)
Date: Fri, 4 May 2001 06:01:39 -0500
Subject: [Tutor] how to input a name
Message-ID: <44D2ED0AC0121146BF01366481060EBE607146@umc-mail02.missouri.edu>

I would like to make a program that would ask for a person's name, then say
" Hello (persons name)!"

this is what I thought would work...

#!/usr/local/bin/env python

name = input("What is your name?")
print name


But as you can guess this does not work, any suggestions?


Jamie Lloyd
Data Center Tech
IATS/UCSOperations
University of Missouri



From rob@jam.rr.com  Fri May  4 12:05:22 2001
From: rob@jam.rr.com (rob@jam.rr.com)
Date: Fri, 04 May 2001 06:05:22 -0500
Subject: [Tutor] Sort of non-related...but in a way, related too...*grins*
References: <FPEHJJPEEOIPMAHOADBKAEDLCDAA.rwilkins@bigpond.net.au>
Message-ID: <3AF28CF2.44A97A7A@jam.rr.com>

So far, a few people have submitted tarballs and zip files, and either
is fine. If I receive a tarball, I'm likely to post a copy in .zip
format for those windows users who are unfamiliar with tarballs. If you
just send a zip archive, I'll likely leave it as it is unless someone
complains.

Thanks for remembering Useless,
Rob

Richard Wilkins wrote:
> 
> Hi folks,
> 
> I'm releasing my MUD server package to Useless, the main framework is
> set...it runs fairly smoothly
> (as far as I'm concerned!)
> 
> What I need to know is, what is the most commonly used archiving
> file-type...tarballs? I'm coming from a completely Windows background, so I
> just use zip. If someone would kindly tell me which one to use, if it
> actually matters, then I'll submit it...
> 
> Thanks,
> 
> Andrew
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From rob@jam.rr.com  Fri May  4 12:06:42 2001
From: rob@jam.rr.com (rob@jam.rr.com)
Date: Fri, 04 May 2001 06:06:42 -0500
Subject: [Tutor] Python book suggestion please
References: <F247PdHfKsp3MSi6xzm00000537@hotmail.com>
Message-ID: <3AF28D42.2B43B70F@jam.rr.com>

I know you asked for a book recommendation, but there is a good bit of
online reference material available, such as the good list found at:

http://www.lowerstandard.com/python/howtolinks.html

Rob

Learn Python wrote:
> 
> hi all,
> 
> i'm new to python and i do java @ work.
> I'm looking to buy a good / probably the best reference
> book available right now in the market. I checked out
> a few titles and arrived at the follwing titles:
> 
> 1. Programming Python 2nd edition (orielly)
> 2. Python programmer's refernce (Insider Press)..by Beazely ( this is not
> uptodate i guess since it does'nt cover 2.0)
> 
> C'd someone please suggest a good buy. Any thoughts?
> 
> thanks,
> karthik.

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From learnpython@hotmail.com  Fri May  4 12:14:11 2001
From: learnpython@hotmail.com (Learn Python)
Date: Fri, 04 May 2001 11:14:11 -0000
Subject: [Tutor] how to input a name
Message-ID: <F61UwWpSWerOc0Ne0Pa00009729@hotmail.com>

name=raw_input("name??")
print name
will work.
I guess the problem is that input() expects a python data type
so supplying 'yourname' w'd've worked since it's a string wheareas
just yourname w/o "'"
is'nt one.
raw_input aceepts anything you supply.

karthik.


>From: "Lloyd, Jamie" <LloydJ@missouri.edu>
>To: "Tutor@Python. Org (E-mail)" <tutor@python.org>
>Subject: [Tutor] how to input a name
>Date: Fri, 4 May 2001 06:01:39 -0500
>
>I would like to make a program that would ask for a person's name, then say
>" Hello (persons name)!"
>
>this is what I thought would work...
>
>#!/usr/local/bin/env python
>
>name = input("What is your name?")
>print name
>
>
>But as you can guess this does not work, any suggestions?
>
>
>Jamie Lloyd
>Data Center Tech
>IATS/UCSOperations
>University of Missouri
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

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



From toodles@yifan.net  Fri May  4 12:19:33 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Fri, 4 May 2001 19:19:33 +0800
Subject: [Tutor] how to input a name
In-Reply-To: <44D2ED0AC0121146BF01366481060EBE607147@umc-mail02.missouri.edu>
Message-ID: <FPEHJJPEEOIPMAHOADBKAEDPCDAA.toodles@yifan.net>

> OMG.. thanks so much.. !  If it were not for people like you, my
> life would
> not be much fun.
> Again, thanks for the info!

No problems! Sorry for sending that reply directly to you, it was meant to
go to the list...

Andrew




From wilson@visi.com  Fri May  4 13:09:43 2001
From: wilson@visi.com (Timothy Wilson)
Date: Fri, 4 May 2001 07:09:43 -0500 (CDT)
Subject: [Tutor] Python book suggestion please
In-Reply-To: <Pine.LNX.4.21.0105040144310.26188-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.GSO.4.21.0105040706440.2099-100000@isis.visi.com>

On Fri, 4 May 2001, Daniel Yoo wrote:

>     4.  Wesley Chun has just written "Core Python Programming", and since
> he's one of the tutor@python.org list operators, it would be simply
> criminal not to mention his book.  (Ahem.)  I've heard good things about
> it, but haven't had the chance to buy it yet.

Well I've had the chance to buy and read most of it. It's
excellent. Wesley's book is probably the best I've read so far. I like the
mix of basic and more advanced topics at the end. The exercises in the back
of the chapter are the best I've seen. (I plan to steal liberally from them
next year when I teach my Python class :-)

-Tim

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



From lonetwin@yahoo.com  Fri May  4 13:31:28 2001
From: lonetwin@yahoo.com (steve)
Date: Fri, 4 May 2001 18:01:28 +0530
Subject: [Tutor] Regular-ex to parse man files
Message-ID: <01050418012800.02176@mercury.in.cqsl.com>

Hi all,
 Here's a lil' prob. I'm facing, for a script I'm writing, I need to pars=
e=20
man files (the unix manual files) and get the DESCRIPTION part from 'em .=
=2E..I=20
tried to do this by reading the man file directly and doing a regular-ex=20
search for .SH DESCRIPTION and reading from then on......now I'm just=20
learning python and I'm not too comfy with regex as yet, any suggestions =
on=20
how I could get this done ??
 Plz. don't blame me for not trying, I've written here after going thru' =
the=20
regex howto, reading code snippets from various places and wasting a day=20
experimenting.....I've just come close to getting it done....but as u kno=
w,=20
there's a big diffrence between getting close to doing it, and doing it !=
! :)

Thanx in advance,
Peace
Steve
--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
"Unfortunately, those people who have nothing better to do than post on t=
he
Internet all day long are rarely the ones who have the most insights."
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From Mark A. Tobin" <mtobin@bigfoot.com  Fri May  4 16:32:08 2001
From: Mark A. Tobin" <mtobin@bigfoot.com (Mark A. Tobin)
Date: Fri, 4 May 2001 11:32:08 -0400
Subject: [Tutor] urlretrieve
Message-ID: <000901c0d4af$648cfaa0$e9b8c28e@anonymous>

Hi again,
first I want to thank everybody who helped explain the whole self thing as
it has to do with classes, I think I'm slowly getting the idea.
second I'm having a problem with urlretrieve() and I'm not even sure where
the problem resides.  Maybe some of you python/windows people out there
might be able to help.
I'm running two systems both Win95, one runs 1.5.2, and one 2.0.  Both
systems are similarly configured, at least as far as I know to look.  When I
do this:
>>>from urllib import urlretrieve
>>>urlretrieve("http://www.ihrg.com/nssnet/default.htm", "test.htm")
('test.htm', <mimetools.Message instance at 007EABDC>)
it looks like it worked right?
well on the system using 1.5.2 it does work, I get that webpage, intact,
saved in the appropriate file.  However, on the other system (running python
2.0) I get a webpage giving me a standard Proxy authorization required
message instead of the page I'm looking for:
Proxy authorization required
Username authentication is required for using this proxy.  Either your
browser does not perform proxy authorization, or your authorization has
failed.

I wondered whether it was that specific server so I tried with python.org
and got the same message.
Both systems use the same dialup ISP connection, and as far as I know there
certainly is no Proxy associated with either system.  I have never had to do
anything proxy associated during any setup process, and when I grab that
file with IE5 it works like a charm.

Any suggestions?  I wasn't really sure what info might be relevant, so I may
not have provided everything a diagnostician might need.  I don't even
really know where to look....

Looking for help (again... sigh),

Mark



From randrews@planhouse.com  Fri May  4 16:45:50 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Fri, 4 May 2001 10:45:50 -0500
Subject: [Tutor] urlretrieve
In-Reply-To: <000901c0d4af$648cfaa0$e9b8c28e@anonymous>
Message-ID: <001701c0d4b1$4c11aaa0$de00a8c0@planhouse5>

Are you using Netscape when you encounter the problem? If so, look under
Edit>Preferences. I think that under this you will find Advanced>Proxies and
may find that it expects a proxy now for some reason. There are a number of
somewhat rare reasons this can happen. If it is the case, you can easily
enough set it straight from there.

Rob

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Mark A. Tobin
Sent: Friday, May 04, 2001 10:32 AM
To: tutor@python.org
Subject: [Tutor] urlretrieve


Hi again,
first I want to thank everybody who helped explain the whole self thing as
it has to do with classes, I think I'm slowly getting the idea.
second I'm having a problem with urlretrieve() and I'm not even sure where
the problem resides.  Maybe some of you python/windows people out there
might be able to help.
I'm running two systems both Win95, one runs 1.5.2, and one 2.0.  Both
systems are similarly configured, at least as far as I know to look.  When I
do this:
>>>from urllib import urlretrieve
>>>urlretrieve("http://www.ihrg.com/nssnet/default.htm", "test.htm")
('test.htm', <mimetools.Message instance at 007EABDC>)
it looks like it worked right?
well on the system using 1.5.2 it does work, I get that webpage, intact,
saved in the appropriate file.  However, on the other system (running python
2.0) I get a webpage giving me a standard Proxy authorization required
message instead of the page I'm looking for:
Proxy authorization required
Username authentication is required for using this proxy.  Either your
browser does not perform proxy authorization, or your authorization has
failed.

I wondered whether it was that specific server so I tried with python.org
and got the same message.
Both systems use the same dialup ISP connection, and as far as I know there
certainly is no Proxy associated with either system.  I have never had to do
anything proxy associated during any setup process, and when I grab that
file with IE5 it works like a charm.

Any suggestions?  I wasn't really sure what info might be relevant, so I may
not have provided everything a diagnostician might need.  I don't even
really know where to look....

Looking for help (again... sigh),

Mark


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



From Mark A. Tobin" <mtobin@bigfoot.com  Fri May  4 17:19:33 2001
From: Mark A. Tobin" <mtobin@bigfoot.com (Mark A. Tobin)
Date: Fri, 4 May 2001 12:19:33 -0400
Subject: [Tutor] urlretrieve
References: <001701c0d4b1$4c11aaa0$de00a8c0@planhouse5>
Message-ID: <004101c0d4b6$0314b900$e9b8c28e@anonymous>

Rob, thanks for your prompt reply. I don't have Netscape installed on that
system, however I took the advice anyway and checked the Internet Options
that IE5 employs.  Other than thinking it was connected using a LAN it was
setup fine.  All the proxy options were cleared.  Just to be safe I changed
the LAN to dialup and retested with the same result.  Do the options in
there affect how python connects to servers?  Wouldn't they affect IE5's
ability to grab the page as well?  Any other ideas?  I'm completely at a
loss...

Mark
----- Original Message -----
From: "Rob Andrews" <randrews@planhouse.com>
To: "'Mark A. Tobin'" <mtobin@bigfoot.com>; <tutor@python.org>
Sent: Friday, May 04, 2001 11:45 AM
Subject: RE: [Tutor] urlretrieve


> Are you using Netscape when you encounter the problem? If so, look under
> Edit>Preferences. I think that under this you will find Advanced>Proxies
and
> may find that it expects a proxy now for some reason. There are a number
of
> somewhat rare reasons this can happen. If it is the case, you can easily
> enough set it straight from there.
>
> Rob
>
> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Mark A. Tobin
> Sent: Friday, May 04, 2001 10:32 AM
> To: tutor@python.org
> Subject: [Tutor] urlretrieve
>
>
> Hi again,
> first I want to thank everybody who helped explain the whole self thing as
> it has to do with classes, I think I'm slowly getting the idea.
> second I'm having a problem with urlretrieve() and I'm not even sure where
> the problem resides.  Maybe some of you python/windows people out there
> might be able to help.
> I'm running two systems both Win95, one runs 1.5.2, and one 2.0.  Both
> systems are similarly configured, at least as far as I know to look.  When
I
> do this:
> >>>from urllib import urlretrieve
> >>>urlretrieve("http://www.ihrg.com/nssnet/default.htm", "test.htm")
> ('test.htm', <mimetools.Message instance at 007EABDC>)
> it looks like it worked right?
> well on the system using 1.5.2 it does work, I get that webpage, intact,
> saved in the appropriate file.  However, on the other system (running
python
> 2.0) I get a webpage giving me a standard Proxy authorization required
> message instead of the page I'm looking for:
> Proxy authorization required
> Username authentication is required for using this proxy.  Either your
> browser does not perform proxy authorization, or your authorization has
> failed.
>
> I wondered whether it was that specific server so I tried with python.org
> and got the same message.
> Both systems use the same dialup ISP connection, and as far as I know
there
> certainly is no Proxy associated with either system.  I have never had to
do
> anything proxy associated during any setup process, and when I grab that
> file with IE5 it works like a charm.
>
> Any suggestions?  I wasn't really sure what info might be relevant, so I
may
> not have provided everything a diagnostician might need.  I don't even
> really know where to look....
>
> Looking for help (again... sigh),
>
> Mark
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From randrews@planhouse.com  Fri May  4 17:36:50 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Fri, 4 May 2001 11:36:50 -0500
Subject: [Tutor] urlretrieve
In-Reply-To: <004101c0d4b6$0314b900$e9b8c28e@anonymous>
Message-ID: <001801c0d4b8$6b9d0f20$de00a8c0@planhouse5>

I've been trying to reproduce your error on the most similar machine I can
find, which is running 98SE and Python 2.1. So far, it works like a breeze
here.

Rob

-----Original Message-----
From: Mark A. Tobin [mailto:mtobin@attcanada.net]
Sent: Friday, May 04, 2001 11:20 AM
To: randrews@planhouse.com
Cc: tutor@python.org
Subject: Re: [Tutor] urlretrieve


Rob, thanks for your prompt reply. I don't have Netscape installed on that
system, however I took the advice anyway and checked the Internet Options
that IE5 employs.  Other than thinking it was connected using a LAN it was
setup fine.  All the proxy options were cleared.  Just to be safe I changed
the LAN to dialup and retested with the same result.  Do the options in
there affect how python connects to servers?  Wouldn't they affect IE5's
ability to grab the page as well?  Any other ideas?  I'm completely at a
loss...

Mark
----- Original Message -----
From: "Rob Andrews" <randrews@planhouse.com>
To: "'Mark A. Tobin'" <mtobin@bigfoot.com>; <tutor@python.org>
Sent: Friday, May 04, 2001 11:45 AM
Subject: RE: [Tutor] urlretrieve


> Are you using Netscape when you encounter the problem? If so, look under
> Edit>Preferences. I think that under this you will find Advanced>Proxies
and
> may find that it expects a proxy now for some reason. There are a number
of
> somewhat rare reasons this can happen. If it is the case, you can easily
> enough set it straight from there.
>
> Rob
>
> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Mark A. Tobin
> Sent: Friday, May 04, 2001 10:32 AM
> To: tutor@python.org
> Subject: [Tutor] urlretrieve
>
>
> Hi again,
> first I want to thank everybody who helped explain the whole self thing as
> it has to do with classes, I think I'm slowly getting the idea.
> second I'm having a problem with urlretrieve() and I'm not even sure where
> the problem resides.  Maybe some of you python/windows people out there
> might be able to help.
> I'm running two systems both Win95, one runs 1.5.2, and one 2.0.  Both
> systems are similarly configured, at least as far as I know to look.  When
I
> do this:
> >>>from urllib import urlretrieve
> >>>urlretrieve("http://www.ihrg.com/nssnet/default.htm", "test.htm")
> ('test.htm', <mimetools.Message instance at 007EABDC>)
> it looks like it worked right?
> well on the system using 1.5.2 it does work, I get that webpage, intact,
> saved in the appropriate file.  However, on the other system (running
python
> 2.0) I get a webpage giving me a standard Proxy authorization required
> message instead of the page I'm looking for:
> Proxy authorization required
> Username authentication is required for using this proxy.  Either your
> browser does not perform proxy authorization, or your authorization has
> failed.
>
> I wondered whether it was that specific server so I tried with python.org
> and got the same message.
> Both systems use the same dialup ISP connection, and as far as I know
there
> certainly is no Proxy associated with either system.  I have never had to
do
> anything proxy associated during any setup process, and when I grab that
> file with IE5 it works like a charm.
>
> Any suggestions?  I wasn't really sure what info might be relevant, so I
may
> not have provided everything a diagnostician might need.  I don't even
> really know where to look....
>
> Looking for help (again... sigh),
>
> Mark
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From bsass@freenet.edmonton.ab.ca  Fri May  4 18:33:56 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Fri, 4 May 2001 11:33:56 -0600 (MDT)
Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a
 table         in GUI
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D736@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.33.0105020217330.9640-100000@bms>

from the forgotten in postponed-msgs file...

On Tue, 1 May 2001 alan.gauld@bt.com wrote:
> As for Blackadder it is a commercial product but I don't
> know how useful the GUI builder support is. (I'm not even
> 100% sure it has any!)

I would imagine ('cause I've only looked at the unix PyQt, free) you
would at least get Qt-Designer and pyuic (to generate PyQt code, uic
generates C++).

<subjective>
Qt-Designer "feels right" and works well, the python produced by pyuic
is clean and readable.
</subjective>


- Bruce





From virketis@fas.harvard.edu  Fri May  4 19:56:55 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Fri, 04 May 2001 14:56:55 -0400
Subject: [Tutor] an executable for Macs
In-Reply-To: <E14vi18-00017c-00@mail.python.org>
Message-ID: <200105041852.f44IqS715690@smtp4.fas.harvard.edu>

Hi,

I've writen a little script for statistical analysis of tree phylogeny
data. Unfortunately, the guys who'll be using it are card-carrying
computer-ignorant descriptive botanists who love Macs. So, I need to
convert the script to an executable. Does the py2exe.py module, which
somebody had mentioned a few emails ago, work for this task? Do I need
something special for Macs?

Thank you!

Pijus
----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis.


From johnp@reportlab.com  Fri May  4 20:02:19 2001
From: johnp@reportlab.com (John Precedo)
Date: Fri, 4 May 2001 20:02:19 +0100
Subject: [Tutor] an executable for Macs
In-Reply-To: <200105041852.f44IqS715690@smtp4.fas.harvard.edu>
Message-ID: <GBEDIFFLINCAGNCJCLIFCELMCDAA.johnp@reportlab.com>

> Hi,

Howdy!

> I've written a little script for statistical analysis of tree phylogeny
> data....I need to convert the script to an executable....Do I need
> something special for Macs?

If you can get your hands on a Mac equipped with Python, it comes with a
utility called 'Build Application'. It should be in the same folder as the
main Python Interpretor and Python IDE programs.

Copy your script file onto the Mac, drop it onto the 'build application'
icon and voila! Short period while a window pops up, loads of text churns
out and you see another icon on your desktop - your new application.

One caveat - I have no idea how well this works for serious scripts. The
only times I have used it are on simple stuff not much more complex than
'hello world'. Another caveat - my Mac stays at home while I have to go out
to work, so this has been from memory.

Hope this helps.

John

--
John Precedo   (johnp@reportlab.com)       Junior Developer
Reportlab, Inc (http://www.reportlab.com)





From deirdre@deirdre.net  Fri May  4 21:11:31 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Fri, 4 May 2001 13:11:31 -0700
Subject: [Tutor] an executable for Macs
In-Reply-To: <200105041852.f44IqS715690@smtp4.fas.harvard.edu>
References: <200105041852.f44IqS715690@smtp4.fas.harvard.edu>
Message-ID: <a0510030fb718bd25cd48@[10.0.1.48]>

>I've writen a little script for statistical analysis of tree phylogeny
>data. Unfortunately, the guys who'll be using it are card-carrying
>computer-ignorant descriptive botanists who love Macs. So, I need to
>convert the script to an executable. Does the py2exe.py module, which
>somebody had mentioned a few emails ago, work for this task? Do I need
>something special for Macs?


What John said -- there's an analogous process, but a different tool.

And be careful what you say about us Mac folks, 'kay? :)

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From vlindberg@verio.net  Sat May  5 01:11:09 2001
From: vlindberg@verio.net (VanL)
Date: Fri, 04 May 2001 18:11:09 -0600
Subject: [Tutor] Most efficient representation of a tree?
Message-ID: <3AF3451D.BCBAF3F3@verio.net>

Hello,

What would be the most efficient representation of a tree? 
In this tree, each node could have an arbitrary number of children.
I also wanted to be able to order the children so I can traverse the
trees in different ways (preorder, postorder, etc).  Anyway, at least a
leftmost-child, right-sibling ordering.

I was considering two options:

1. A modification of Guido's adjacency-list implementation of a graph
(see http://www.python.org/doc/essays/graphs.html).  After all, this
sort of tree is just special case sparse graph.

2. A node class with a parent link and a list of links to each child --
essentially a generalization of the linked list class that I posted here
a month ago.

Any other options?

Does anyone have any idea how these would compare in terms of speed and
execution resources?

Thanks,

VanL


From julieta_rangel@hotmail.com  Sat May  5 01:14:22 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Fri, 04 May 2001 19:14:22 -0500
Subject: [Tutor] inserting items into a list
Message-ID: <F273bbbJXncnm5c4GnO00000f2b@hotmail.com>

Daniel,

Great suggestion!  Everyday I learn something new about programming.  I had 
no idea I could do it.  I only thought about it because it would be easy for 
me not having to combine like terms in the multiplication of polynomials.  I 
knew that if I did it this way I would not have to combine like terms, which 
would take me at least a day to figure out how to do it [you know what a 
slow poke I am at this :)].


>From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: Julieta Rangel <julieta_rangel@hotmail.com>
>CC: tutor@python.org
>Subject: Re: [Tutor] inserting items into a list
>Date: Thu, 3 May 2001 22:41:33 -0700 (PDT)
>
>On Thu, 3 May 2001, Julieta Rangel wrote:
>
> > [3,0,6], then [1,0,2] and finally [2,0,4].  I need to find a way to 
>insert 3
> > zeroes at the end of list [2,0,4]; 1 zero at the beginning and two at 
>the
> > end of [3,0,6]; 2 zeroes a the beginning and one at the end of [1,0,2], 
>and
> > finally 3 zeroes at the beginning of [2,0,4].  This way the new lists 
>would
> > look like:
> >
> > [2,0,4,0,0,0]
> > [0,3,0,6,0,0]
> > [0,0,1,0,2,0]
> > [0,0,0,2,0,4]
> >
> > and it would be just a matter of adding those lists to figure out the
> > result:  2 + 3x + 5x^2 + 8x^3 + 2x^4 + 4x^5.  As you can see from the
> > subject, my problem is inserting those zeroes at the specific locations.
> > Can you help me?
>
>
>How about something like this?
>
>###
>def makeZeroPaddedList(mylist, position, length):
>     """This function should take mylist, and splice it into
>        a list of zeros at a specific location."""
>     newlist = [0] * length
>     newlist[position:position + len(mylist)] = mylist
>     return newlist
>###
>
>
>Let's test it out on the interpreter:
>
>###
> >>> makeZeroPaddedList([1, 2, 3], 0, 10)
>[1, 2, 3, 0, 0, 0, 0, 0, 0, 0]
> >>> makeZeroPaddedList([1, 2, 3], 1, 10)
>[0, 1, 2, 3, 0, 0, 0, 0, 0, 0]
> >>> makeZeroPaddedList([1, 2, 3], 2, 10)
>[0, 0, 1, 2, 3, 0, 0, 0, 0, 0]
> >>> makeZeroPaddedList([1, 2, 3], 3, 10)
>[0, 0, 0, 1, 2, 3, 0, 0, 0, 0]
> >>> makeZeroPaddedList([1, 2, 3], 4, 10)
>[0, 0, 0, 0, 1, 2, 3, 0, 0, 0]
>###
>
>
>The idea is to make up a list that's filled only with zeros, and then plop
>our original list into it.  We can control both the position of the
>plopping, and the length of the resulting list.
>
>Hope this helps!
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From sheila@thinkspot.net  Sat May  5 04:27:27 2001
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 04 May 2001 20:27:27 -0700
Subject: [Tutor] Python book suggestion please
In-Reply-To: <F247PdHfKsp3MSi6xzm00000537@hotmail.com>
References: <F247PdHfKsp3MSi6xzm00000537@hotmail.com>
Message-ID: <3065B5B7339@kserver.org>

On Fri, 04 May 2001 06:28:06 -0000, "Learn Python" <learnpython@hotmail.com>
wrote about [Tutor] Python book suggestion please:

:I'm looking to buy a good / probably the best reference
:book available right now in the market. I checked out
:a few titles and arrived at the follwing titles:
:
:1. Programming Python 2nd edition (orielly)
:2. Python programmer's refernce (Insider Press)..by Beazely ( this is not 
:uptodate i guess since it does'nt cover 2.0)

I have these three Python books:

Programming Python, 2nd ed. Mark Lutz. Assumes that you already know Python.
If you felt really comfortable after working through the Tutorial that comes
with the standard distribution, and were already up and writing scripts, this
might be a good book. Not concise. But, has an index. Lots of examples. Lots.
Huge book.

Core Python Programming. Wesley Chun. Assumes you already know some other high
level programming language. Starts with a nice overview chapter, and then has
a chapter on each topic which goes into more detail. My favorite of the three
I have. Not as big as Programming Python, 2nd ed, and the print is larger.
Lighter to read. Many examples.

Quick Python. Daryl Harms and Kenneth McDonald. An extremely concise overview
for someone who already knows how to program in another language. Small and
compact. I haven't looked at this one quite as much. A fair number of
examples. Most examples are snippets, rather than full programs.

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



From LloydJ@missouri.edu  Sat May  5 04:56:42 2001
From: LloydJ@missouri.edu (Lloyd, Jamie)
Date: Fri, 4 May 2001 22:56:42 -0500
Subject: [Tutor] problem with cgi
Message-ID: <44D2ED0AC0121146BF01366481060EBE60714D@umc-mail02.missouri.edu>

#!/usr/local/bin/env python

print "Content-type: text/html\n\n"
print "<html><head></head>"
print "<body>"
print "Thank you for using my first python/cgi program!"
print "Just enter your name in the text field."
print "</body></html>"

this is what I have so far, but it's giving me an 500 Internal server error.
Could someone please tell me what is wrong?  I could have swore that this
would work?!?!?




From sheila@thinkspot.net  Sat May  5 05:04:29 2001
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 04 May 2001 21:04:29 -0700
Subject: [Tutor] problem with cgi
In-Reply-To: <44D2ED0AC0121146BF01366481060EBE60714D@umc-mail02.missouri.edu>
References: <44D2ED0AC0121146BF01366481060EBE60714D@umc-mail02.missouri.edu>
Message-ID: <32824986A94@kserver.org>

On Fri, 4 May 2001 22:56:42 -0500, "Lloyd, Jamie" <LloydJ@missouri.edu>  wrote
about [Tutor] problem with cgi:

:#!/usr/local/bin/env python
:
:print "Content-type: text/html\n\n"
:print "<html><head></head>"
:print "<body>"
:print "Thank you for using my first python/cgi program!"
:print "Just enter your name in the text field."
:print "</body></html>"
:
:this is what I have so far, but it's giving me an 500 Internal server error.
:Could someone please tell me what is wrong?  I could have swore that this
:would work?!?!?

Your Python script looks fine. Are you sure you have the permissions set
correctly? What type of operating system are you running this on? Is the web
server configured to run python scripts? If it is a Linux/Unix type server,
are the permissions set so that it is an executable file? Did you upload it in
ASCII mode to the server?

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



From Mark A. Tobin" <mtobin@bigfoot.com  Sat May  5 05:15:06 2001
From: Mark A. Tobin" <mtobin@bigfoot.com (Mark A. Tobin)
Date: Sat, 5 May 2001 00:15:06 -0400
Subject: [Tutor] urlretrieve
References: <001801c0d4b8$6b9d0f20$de00a8c0@planhouse5>
Message-ID: <005c01c0d519$f9155f40$e9b8c28e@anonymous>

All evening I've been puzzling over this little problem.  I really wanted to
know where the root of the problem was.  Python? My system? My ISP?
So I uninstalled Python 2.0 from the suspect system and installed 1.5.2 onto
it just to see what would happen.  Lo and behold it works!  No more Proxy
authentication error!
So from my point of view everything is fine, I can probably load 2.1 and
things will be fine, or if not I have no big problem with sticking with
1.5.2.  However I would like any suggestions as to why this problem could
be.  It seems rather odd that 2.0's urllib.urlretrieve() method would cause
a problem where 1.5.2's seems to work perfectly....

Mark
----- Original Message -----
From: "Rob Andrews" <randrews@planhouse.com>
To: "'Mark A. Tobin'" <mtobin@bigfoot.com>; <randrews@planhouse.com>
Cc: <tutor@python.org>
Sent: Friday, May 04, 2001 12:36 PM
Subject: RE: [Tutor] urlretrieve


> I've been trying to reproduce your error on the most similar machine I can
> find, which is running 98SE and Python 2.1. So far, it works like a breeze
> here.
>
> Rob
>



From jsc@rock-tnsc.com  Sat May  5 21:21:10 2001
From: jsc@rock-tnsc.com (Jethro Cramp)
Date: Sat, 5 May 2001 12:21:10 -0800
Subject: [Tutor] Unpickling a Pickled Object
In-Reply-To: <F46ecm9t0CI76rOJhKP00009564@hotmail.com>
References: <F46ecm9t0CI76rOJhKP00009564@hotmail.com>
Message-ID: <01050512211000.00932@jsclaptop>

On Friday 04 May 2001 12:19 am, Learn Python wrote:
> hi Jethro,
>
> c'd you please tell why you think the __init__ s'd'nt be called?
> If i'm doing some initialisation in __init__
> whch in turn will be used by other methods then the unpickling w'd'nt
> be of much use right?
> my code might fail bcos certain things did'nt get initialized.
> Do we have a
> private void readObject() java equivalent in python? which w'd
> automatically get called when we "deserialize" the object / in this case
> "unpickle". Then we can probably initialize some stuff there?
>
> karthik
>
Dear Karthik,

As I understand it when you pickle an object you are infact saving the 
object's state. The reason I asked (and hoped that _init_ isn't called when I 
unpickle an object) is that in the class I was designing I want to set an 
IsValid property to false (because when the class is instantiated it will be 
in an invalid state) and a list of properties that are an invalid state. When 
the object gets serialized it can either be in a valid or invalid state, and 
a list of the properties that are still invalid are serialized with it.  When 
the object is unpickled (in my mind) it should be in the same state as when 
it was pickled. Running __init__ when it is unserialised might change that. 
I didn't want to write code in __init__ to check for validity. Not a big deal 
to implement, but I am LAZY, after all ;). 

Sorry I don't know anything about JAVA and I'm not much of a programmer so I 
can't answer your question about readObject().  Maybe someone wiser on this 
list can give you an answer

Jethro


From bdupire@seatech.fau.edu  Sat May  5 05:40:37 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Sat, 05 May 2001 00:40:37 -0400
Subject: [Tutor] Most efficient representation of a tree?
References: <3AF3451D.BCBAF3F3@verio.net>
Message-ID: <3AF38445.9652A09A@seatech.fau.edu>


I have to answer this one, as i am doing something very similar for my
project...
What i chose is kind of between Guido's implementation and yours...

I have a node class with a parent link and a list of links to each child, as
you did.
But the node objects are stored in a dictionnary. key = <name of the node>,
like Guido did.

Actually, at the beginning, i have a node class with a parent variable
(which indicates the name of the parent) and with a list of the children
names....
I can't have a list of links to each child at the beginning since the node
objects are not created simultaneously in my system. When all the nodes are
created, i am doing a 'second pass' and i replace every node's name by its
reference.
(I hope you still follow me...i implement what is called a tree-dictionary.)



In term of speed now, storing references to the nodes is quicker, because in
the dictionary approach, Python has to compute the key of the hash table,
from the name of the node to find this reference.

Now on the 'resource side', it's not too bad. References are shorter than
names.
The reason why i use an object (instead of a tuple containing  parent link
and a list of links to each child), is that i need to store a lot more in my
node, and i need methods too...
My 'node' class is actually called a 'state' class.

Now looking at the memory side. Actually when you run the Python interpreter
(a Python process) on your computer it takes ...600 k- a few meg (depending
on your program)... so you only care about memory if you want to create a
LOT of  nodes. If it's less than , let's say 100, really, you don't have to
worry.

A dictionary takes 24 bytes + 12* 2^n bytes where n= log2(n items) + 1
A class instance = 16 bytes + a dictionary
A list = 16 bytes + 4 bytes for each item
A tuple = list


You  are only concerned about memory, if, like me, you are running 10-20
python processes at a time, which are all dealing with nodes.... this begins
to suck RAM...but anyway, buying memory is not so expensive now.../ or you
can use MicroThreads...

I am very concerned about time in my system, not about the number of nodes,
which is low in my project (<50),  so i think my approach is good :o).
I lose time at first, fetching all these references in my dictionary, but
this is done once, and not everytime at run-time, so it's much faster.

If you want both.. memory and speed, do not implement nodes as objects, but
as nested tuples, and store references to the next node, not names.

If you want to know what i am using a Tree dictionary for, you can go to
http://www.python9.org/p9-cdrom/22/index.htm
BUT there's no code there... (too long..)

Benoit




VanL wrote:

> Hello,
>
> What would be the most efficient representation of a tree?
> In this tree, each node could have an arbitrary number of children.
> I also wanted to be able to order the children so I can traverse the
> trees in different ways (preorder, postorder, etc).  Anyway, at least a
> leftmost-child, right-sibling ordering.
>
> I was considering two options:
>
> 1. A modification of Guido's adjacency-list implementation of a graph
> (see http://www.python.org/doc/essays/graphs.html).  After all, this
> sort of tree is just special case sparse graph.
>
> 2. A node class with a parent link and a list of links to each child --
> essentially a generalization of the linked list class that I posted here
> a month ago.
>
> Any other options?
>
> Does anyone have any idea how these would compare in terms of speed and
> execution resources?
>
> Thanks,
>
> VanL
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From julieta_rangel@hotmail.com  Sat May  5 06:25:15 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sat, 05 May 2001 00:25:15 -0500
Subject: [Tutor] tables and dictionaries
Message-ID: <F223AkK5LqN33HFnwpG0000115a@hotmail.com>

I'm trying to write a program that given a finite set (say, up to 30 
elements) and a table,the program figures out whether the set is a group.  I 
need to have the user enter the elements on the set and store them on a 
list.  Once on this list, I want the user to enter a table, but for this, I 
need for python to pair each element with every element on the list so I can 
ask for the table.  Let's say that the set consists of elements [e,a,b,ab].  
I need to ask the user

e*e=?        a*e=?         b*e=?              ab*e=?
e*a=?        a*a=?         b*a=?              ab*a=?
e*b=?        a*b=?         b*b=?              ab*b=?
e*ab=?       a*ab=?        b*ab=?             ab*ab=?

Since I don't know what the set will consist of, I need to find a way so 
that once the user enters the set, the computer pairs the elements together 
as I did above, asks for the required input and stores it in a dictionary. 
Can this be done?  If so, how?  If this can be done, it would be easier to 
check for the four properties of a group[closure under binary operation, 
associativity : a*(a*b)=(a*a)*b; identity and inverses).  I know it is a 
tedious task, but for now I'm interested in finding out whether it is 
possible to have the computer pair up the elements in the set, and if so, 
how?  Any suggestions or help?

Julieta

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From sheila@thinkspot.net  Sat May  5 06:48:35 2001
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 04 May 2001 22:48:35 -0700
Subject: [Tutor] tables and dictionaries
In-Reply-To: <F223AkK5LqN33HFnwpG0000115a@hotmail.com>
References: <F223AkK5LqN33HFnwpG0000115a@hotmail.com>
Message-ID: <38757F21A42@kserver.org>

On Sat, 05 May 2001 00:25:15 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com>  wrote about [Tutor] tables and dictionaries:

:I need to find a way so 
:that once the user enters the set, the computer pairs the elements together 
:as I did above, asks for the required input and stores it in a dictionary. 
:Can this be done?  If so, how?

Yes, this can be done.

if you have the following objects already defined...

list = [e,a,b,ab]
table = {}

(Note: e, a, b, and ab have to already be objects. It might be easiest to let
them be strings and define them as e = 'e' and so forth...)

I suggest a nested loop structure, like this...

for firstElt in list:
    for secondElt in list:
        table[ (firstElt, secondElt) ] = None

What the above code does is, select an element in list. For example, e. Then,
holding 'e' constant as the first Element (the first "for" loop), it goes into
a second for loop on the second Element. So, while "e" is held fixed as the
first element, it will go through the list for the second element, and create
the following tuples:
(e, e)
(e, a)
(e, b)
(e, ab)

After it has done that, it will switch to another element in  the list for the
firstElement. Possibly 'a'. It will hold 'a' fixed on the first for-loop and
on the second for loop, go through all the elements in the list to get the
second element, getting these tuples:
(a, e)
(a, a)
(a, b)
(a, ab)

and so on. The first for-loop will also go through b and ab as the first
element.

The statement

table[ firstElt, secondElt ] = None

puts a key in the dictionary "table", that is a tuple (like one of the example
tuples listed above), and assigns it the value "None", which is a special
value in Python, meaning "no value". I think this is the best value you can
assign in the dictionary "table", while you are generating the ordered pairs,
since you plan on asking the user to input the values for the table later.


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




From tutor@python.org  Sat May  5 06:56:11 2001
From: tutor@python.org (Tim Peters)
Date: Sat, 5 May 2001 01:56:11 -0400
Subject: [Tutor] tables and dictionaries
In-Reply-To: <F223AkK5LqN33HFnwpG0000115a@hotmail.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCAEGHKAAA.tim.one@home.com>

[Julieta Rangel]
> I'm trying to write a program that given a finite set (say, up to 30
> elements) and a table, the program figures out whether the set is a
> group.  I need to have the user enter the elements on the set and
> store them on a list.  Once on this list, I want the user to enter
> a table, but for this, I need for python to pair each element with
> every element on the list so I can ask for the table.

Hmm!  For a set with 30 elements, that's 30*30 == 900 "products".  So you may
want to read this information from a file instead.

> Let's say that the set consists of elements
> [e,a,b,ab].  I need to ask the user
>
> e*e=?        a*e=?         b*e=?              ab*e=?
> e*a=?        a*a=?         b*a=?              ab*a=?
> e*b=?        a*b=?         b*b=?              ab*b=?
> e*ab=?       a*ab=?        b*ab=?             ab*ab=?
>
> Since I don't know what the set will consist of, I need to find a way
> so that once the user enters the set, the computer pairs the elements
> together as I did above, asks for the required input and stores it in
> a dictionary.  Can this be done?

Yes, and quite easily (if you know how <wink>) -- I'll attach a small
program.  Here's a sample run, where to *try* to make it clearer I've
artificially added "<>" brackets around the input I typed in; everything else
is program output:

Enter comma-separated list of elements, like a,b,c: <a,b>
a*a=? <a>
a*b=? <b>
b*a=? <c>
Oops! c is not in ['a', 'b'] -- try again.
b*a=? <b>
b*b=? <a>
a * a = a
a * b = b
b * a = b
b * b = a

> If so, how?  If this can be done, it would be easier to check for
> the four properties of a group[closure under binary operation,

Note that the program above rejected my attempt to enter c, so the *input*
routine ensures closure.

> associativity : a*(a*b)=(a*a)*b; identity and inverses).
> ...

These are, of course, harder to check.  I wouldn't call it "tedious", though!
It seems like a very nice exercise for learning how to use loops and logic.

oh-ok-it's-tedious<wink>-ly y'rs  - tim

import string

elts = raw_input("Enter comma-separated list of elements, like a,b,c: ")
elts = string.split(elts, ",")

product = {}
for x in elts:
    for y in elts:
        prompt = "%s*%s=? " % (x, y)
        need_good_result = 1
        while need_good_result:
            z = raw_input(prompt)
            if z in elts:
                need_good_result = 0
            else:
                print "Oops!", z, "is not in", elts, "-- try again."
        product[x, y] = z

# Display the table.
items = product.items()
items.sort()
for (x, y), z in items:
    print x, "*", y, "=", z



From sheila@thinkspot.net  Sat May  5 07:05:51 2001
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 04 May 2001 23:05:51 -0700
Subject: [Tutor] tables and dictionaries
In-Reply-To: <38757F21A42@kserver.org>
References: <F223AkK5LqN33HFnwpG0000115a@hotmail.com> <38757F21A42@kserver.org>
Message-ID: <397222C3DEA@kserver.org>

On Fri, 04 May 2001 22:48:35 -0700, Sheila King <sheila@thinkspot.net>  wrote
about Re: [Tutor] tables and dictionaries:

:
:I suggest a nested loop structure, like this...
:
:for firstElt in list:
:    for secondElt in list:
:        table[ (firstElt, secondElt) ] = None

Here's a thought:

To help you better see what is going on in a nested looping structure like the
one above (where one loop is inside another), try this piece of code, and see
what it does:

>>> for firstNum in range(2,5):
... 	for secondNum in range(11,16):
... 		print firstNum, ' + ', secondNum, ' = ', firstNum + secondNum
... 	print "inside loop ended"
... 

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




From julieta_rangel@hotmail.com  Sat May  5 07:39:09 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sat, 05 May 2001 01:39:09 -0500
Subject: [Tutor] tables and dictionaries
Message-ID: <F37OtprR0E6faZWZaen000011e5@hotmail.com>

Thanks for your suggestion and your program.  As you might remember, I'm new 
at programming, and eventhough I have a good reference book, it is not easy 
to do it all alone.  Sometimes I can read a section from the book until I'm 
blue in the face and still not understand it.  The thing is that I'm a hands 
on learner, so I learn by example, and eventhough the book has examples to 
go along with the explanations, it is still difficult because sometimes the 
examples are not relevant or meaningful to me or might not answer all of my 
questions.  Since I don't have anyone to show me in an example what the book 
is trying to say, it is very difficult for me to learn it.  With the example 
you gave me I learned more than I would have learnt if I had spend an entire 
day reading about nested loops.  Thank you so very much.

Julieta


>From: Sheila King <sheila@thinkspot.net>
>To: tutor@python.org
>CC: "Julieta Rangel" <julieta_rangel@hotmail.com>
>Subject: Re: [Tutor] tables and dictionaries
>Date: Fri, 04 May 2001 23:05:51 -0700
>
>On Fri, 04 May 2001 22:48:35 -0700, Sheila King <sheila@thinkspot.net>  
>wrote
>about Re: [Tutor] tables and dictionaries:
>
>:
>:I suggest a nested loop structure, like this...
>:
>:for firstElt in list:
>:    for secondElt in list:
>:        table[ (firstElt, secondElt) ] = None
>
>Here's a thought:
>
>To help you better see what is going on in a nested looping structure like 
>the
>one above (where one loop is inside another), try this piece of code, and 
>see
>what it does:
>
> >>> for firstNum in range(2,5):
>... 	for secondNum in range(11,16):
>... 		print firstNum, ' + ', secondNum, ' = ', firstNum + secondNum
>... 	print "inside loop ended"
>...
>
>--
>Sheila King
>http://www.thinkspot.net/sheila/
>http://www.k12groups.org/
>
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From deirdre@deirdre.net  Sat May  5 08:34:35 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Sat, 5 May 2001 00:34:35 -0700
Subject: Fwd: [Tutor] tables and dictionaries
In-Reply-To: <b9.dd7e4c9.28250455@aol.com>
References: <b9.dd7e4c9.28250455@aol.com>
Message-ID: <a0510031fb7195cf695bc@[10.0.1.48]>

>In a message dated 5/5/01 12:41:19 AM Mountain Daylight Time,
>julieta_rangel@hotmail.com writes:
>
>>tutor-admin@python.org
>>
>
>
>
>take me of this ....

Sorry about that...the violation of TOS has been reported to AOL and the offender's posts have been held. While he was told that every email contained unsubscribe instructions, his response was simple vulgarity.

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                         - Douglas Adams


From LloydJ@missouri.edu  Sat May  5 09:41:36 2001
From: LloydJ@missouri.edu (Lloyd, Jamie)
Date: Sat, 5 May 2001 03:41:36 -0500
Subject: [Tutor] how to add multiple strings..
Message-ID: <44D2ED0AC0121146BF01366481060EBE607152@umc-mail02.missouri.edu>

Here is my beginning html code..

<html><head><title>Jamie's hello program</title></head>
<body bgcolor="#888888">
<center>
Jamie's hello program
<p>
<form action="http://oper-test.telecom.missouri.edu/cgi-bin/jamie/hello.cgi"

method="post">
<input type="radio" name="sir" value="Mr">Mr
<input type="radio" name="sir" value="Ms">Ms
<p>
Please enter your name:<br>
<input size=25 name="name" value="">
<p>
<input type="submit" name="submit" value="submit">
<input type=reset value="Clear">
</form>
</center>
</body></html>

and this is my python script for doing it..

#!/usr/bin/python

import cgi, os, sys

print "Content-type: text/html\n\n"
print "<html><head><title></title></head><body>"
form = cgi.FieldStorage()
name = form["name"].value
sir = form["sir"].value
if not form.has_key("name") or form["name"].value == ""
  print "<a
href=""http://oper-test.telecom.missouri.edu/hello_jam.html"">You did not
enter your name, click to go back!</a>"
else:
   print "<H1>Hello " + sir + ". " + name + "</h1>"

print "</body></html>"

The script prints the name, but it does not print Mr. or Ms. before the name
even though you select the bullet in the html code?  Could someone please
help me?

Thanks in advance!
Jamie






From kauphlyn@speakeasy.org  Sat May  5 12:56:54 2001
From: kauphlyn@speakeasy.org (Daniel Coughlin)
Date: Sat, 5 May 2001 04:56:54 -0700 (PDT)
Subject: [Tutor] how to add multiple strings..
In-Reply-To: <44D2ED0AC0121146BF01366481060EBE607152@umc-mail02.missouri.edu>
Message-ID: <Pine.LNX.4.33L2.0105050450090.10086-100000@grace.speakeasy.net>


html snipped --

> and this is my python script for doing it..
>
> #!/usr/bin/python
>
> import cgi, os, sys
>
> print "Content-type: text/html\n\n"
> print "<html><head><title></title></head><body>"
> form = cgi.FieldStorage()
> name = form["name"].value
> sir = form["sir"].value
> if not form.has_key("name") or form["name"].value == ""

aside from not including the colon here                  ^ (:)

your script works fine on my computer. I am running this on win2k ie 5.5.
perhaps you need to refresh your browser or empty the cache? as i ve found
sometimes tweaks i make to dont get updated unless i clear the cache.

Hope this helps.

Daniel




From learnpython@hotmail.com  Sat May  5 14:46:24 2001
From: learnpython@hotmail.com (Learn Python)
Date: Sat, 05 May 2001 13:46:24 -0000
Subject: [Tutor] Unpickling a Pickled Object
Message-ID: <F62SaFMwr9y4cp51dyZ0000a8c8@hotmail.com>

hi jethor,

Okay according to your requirements it w'd be
a problem if init() gets called.
As someone has already posted __init__() does'nt get called
in python 2.0...it does'nt get called in Java either.

rgds,
karthik.


>From: Jethro Cramp <jsc@rock-tnsc.com>
>Reply-To: jsc@rock-tnsc.com
>To: "Learn Python" <learnpython@hotmail.com>
>CC: tutor@python.org
>Subject: Re: [Tutor] Unpickling a Pickled Object
>Date: Sat, 5 May 2001 12:21:10 -0800
>
>On Friday 04 May 2001 12:19 am, Learn Python wrote:
> > hi Jethro,
> >
> > c'd you please tell why you think the __init__ s'd'nt be called?
> > If i'm doing some initialisation in __init__
> > whch in turn will be used by other methods then the unpickling w'd'nt
> > be of much use right?
> > my code might fail bcos certain things did'nt get initialized.
> > Do we have a
> > private void readObject() java equivalent in python? which w'd
> > automatically get called when we "deserialize" the object / in this case
> > "unpickle". Then we can probably initialize some stuff there?
> >
> > karthik
> >
>Dear Karthik,
>
>As I understand it when you pickle an object you are infact saving the
>object's state. The reason I asked (and hoped that _init_ isn't called when 
>I
>unpickle an object) is that in the class I was designing I want to set an
>IsValid property to false (because when the class is instantiated it will 
>be
>in an invalid state) and a list of properties that are an invalid state. 
>When
>the object gets serialized it can either be in a valid or invalid state, 
>and
>a list of the properties that are still invalid are serialized with it.  
>When
>the object is unpickled (in my mind) it should be in the same state as when
>it was pickled. Running __init__ when it is unserialised might change that.
>I didn't want to write code in __init__ to check for validity. Not a big 
>deal
>to implement, but I am LAZY, after all ;).
>
>Sorry I don't know anything about JAVA and I'm not much of a programmer so 
>I
>can't answer your question about readObject().  Maybe someone wiser on this
>list can give you an answer
>
>Jethro

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



From learnpython@hotmail.com  Sat May  5 14:53:22 2001
From: learnpython@hotmail.com (Learn Python)
Date: Sat, 05 May 2001 13:53:22 -0000
Subject: [Tutor] Python book suggestion please
Message-ID: <F199cUzARUsHvahJPAa00009349@hotmail.com>

thanks,

i w'd probably try Core python progarmming.

karthik.


>Programming Python, 2nd ed. Mark Lutz. Assumes that you already know 
>Python.
>If you felt really comfortable after working through the Tutorial that 
>comes
>with the standard distribution, and were already up and writing scripts, 
>this
>might be a good book. Not concise. But, has an index. Lots of examples. 
>Lots.
>Huge book.
>
>Core Python Programming. Wesley Chun. Assumes you already know some other 
>high
>level programming language. Starts with a nice overview chapter, and then 
>has
>a chapter on each topic which goes into more detail. My favorite of the 
>three
>I have. Not as big as Programming Python, 2nd ed, and the print is larger.
>Lighter to read. Many examples.
>
>Quick Python. Daryl Harms and Kenneth McDonald. An extremely concise 
>overview
>for someone who already knows how to program in another language. Small and
>compact. I haven't looked at this one quite as much. A fair number of
>examples. Most examples are snippets, rather than full programs.
>
>--
>Sheila King
>http://www.thinkspot.net/sheila/
>http://www.k12groups.org/
>

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



From julieta_rangel@hotmail.com  Sat May  5 20:28:09 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sat, 05 May 2001 14:28:09 -0500
Subject: [Tutor] stopping a loop
Message-ID: <F47bLAX3cf3ednHM3SO00001703@hotmail.com>

Hello,

Here I am, bugging you guys ...AGAIN!.  As some of you might remember, I'm 
trying to write a program that determines whether a set is a group or not.  
That is, given a finite set and a table, check for closure, associativity, 
and make sure all elements in set have inverses and identity elements.  This 
is what I have so far:

import string
set = raw_input("Enter the elements of the set separated by a comma,ie, 
a,b,c: ")
set = string.split(set, ",")
op = raw_input("Enter the binary operator sign, ie, * : ")
product = {}

for x in set:
    for y in set:
       prompt ="%s %s %s = ? "%(x,op,y)
       z= raw_input(prompt)

       product[x,y] = z
    print " "

#Display the table
items = product.items()
items.sort()
for(x,y),z in items:
   print x,op,y, " = ",z

I figure that if the user enters an element (when asked for the table 
values), that is not in the set, there is no point in having the computer 
ask for the remainder of the table because the set is not a group.  I tried 
inserting an "if" clause saying that if "z" is not in the set, print "The 
set is not a group", and break the loop. The if clause worked well, if I 
entered an element (when asked for the table values) that was not in the 
set, the computer would inform me that the set is not a group because 
closure fails; however, the result was not what I was looking for, the 
computer would keep asking me for the rest of the table values.  I read that 
to break a loop I must insert a break statement, but I could not figure out 
where to place it.  I tried placing it in different places, but it wouldn't 
work.  Can anyone help me stop the loop as soon as a table value that is not 
in the set is entered?  The section in my book about breaking loops is not 
very clear, at least not to me, so that's why you have me here, asking dumb 
questions ...AGAIN.

julieta

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From dyoo@hkn.eecs.berkeley.edu  Sat May  5 21:37:37 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sat, 5 May 2001 13:37:37 -0700 (PDT)
Subject: [Tutor] stopping a loop
In-Reply-To: <F47bLAX3cf3ednHM3SO00001703@hotmail.com>
Message-ID: <Pine.LNX.4.21.0105051252180.27016-100000@hkn.eecs.berkeley.edu>

On Sat, 5 May 2001, Julieta Rangel wrote:

> Here I am, bugging you guys ...AGAIN!.  As some of you might remember, I'm 

Don't worry about it; we're tough, we can handle it.  *grin* 

Seriously, you don't need to apologize about asking questions; just have
fun, play around with Python, and talk to us when things look weird.  
We're all here voluntarily, so if it makes you feel better, we should be
apologizing to you for writing such boring, long sentences about feeling
unjustifiably embarrased about hurting our feelings about a difficult
subject that's quite enormously unintuitive at the beginning but gets
easier as you learn more about it.


> for x in set:
>     for y in set:
>        prompt ="%s %s %s = ? "%(x,op,y)
>        z= raw_input(prompt)
> 
>        product[x,y] = z
>     print " "


> set, the computer would inform me that the set is not a group because 
> closure fails; however, the result was not what I was looking for, the 
> computer would keep asking me for the rest of the table values.  I read that 
> to break a loop I must insert a break statement, but I could not figure out 
> where to place it.  I tried placing it in different places, but it wouldn't 

Using break is the right idea; however, break will pull us out of any
innermost loop: because we're in a nested loop though, we're still within
the body of the outside loop when we do a break.  Here's an example that
shows this behavior:

###
>>> for x in range(5):
...     for y in range(5):
...         print x,y
...         if y == 0: break
...
0 0
1 0
2 0
3 0
4 0
###

So even though we did a break, we didn't break out of the outermost loop.  
If we want to break out of the whole loop, one approach we can use is to
"cascade" the break, so that we continue breaking until we're out.

###
>>> unsuccess = 0
>>> for x in range(5):
...     for y in range(5):
...         print x, y
...         if y == 0:
...             unsuccess = 1
...             break
...     if unsuccess == 1:
...         break
...
0 0
###

Domino effect.  Another way to organize this is to have your Cayley table
input routine be itself a small function.  For example, we can write a
small helper function like this:

###
def getCayleyTable(op, set):
    product = {}
    for x in set:
        for y in set:
            prompt ="%s %s %s = ? "%(x,op,y)
            z= raw_input(prompt)
            product[x,y] = z
            if z not in set:
                return product     # jump out entirely from the function
        print
    return product
###


Writing a helper function might be good because it allows us to
concentrate on a small part of your program.  Because it's a complete
function, we can do testing on it, even if we're not done with the rest of
the program yet.  For example, if we have the getCayleyTable function
written above, we might be curious to see if it works at all:

###
>>> mytable = getCayleyTable('+', [0, 1, 2])
0 + 0 = ? 0
>>> mytable
{(0, 0): '0'}
>>> mytable = getCayleyTable('+', ['0', '1', '2'])
0 + 0 = ? 0
0 + 1 = ? 1
0 + 2 = ? 2

1 + 0 = ? 1
1 + 1 = ? 2
1 + 2 = ? 0

2 + 0 = ? 2
2 + 1 = ? 0
2 + 2 = ? 1

>>> mytable
{('1', '0'): '1', ('1', '1'): '2', ('1', '2'): '0',
 ('0', '0'): '0', ('0', '2'): '2', ('2', '1'): '0',
 ('0', '1'): '1', ('2', '0'): '2', ('2', '2'): '1'}
###

Our first run through getCayleyTable shows us that we need to make sure
our set elements are strings.  This sort of testing becomes difficult when
our programs balloon to larger sizes, so it's a good idea to get in the
habit of organizing conceptually simple tasks into helper functions.


Again, feel free to ask questions.  Hope this helps!



From julieta_rangel@hotmail.com  Sun May  6 00:43:34 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sat, 05 May 2001 18:43:34 -0500
Subject: [Tutor] stopping a loop
Message-ID: <F31Ki3s1wsXZZTHfyQg0000188a@hotmail.com>

>>On Sat, 5 May 2001, Julieta Rangel wrote:
>
> > Here I am, bugging you guys ...AGAIN!.  As some of you might remember, 
>I'm
>
>Don't worry about it; we're tough, we can handle it.  *grin*
>
Thanks, I don't feel that awful anymore about being such a pest


I followed your advice and did the following:

import string
def getCayleyTable(op,set):
    product = {}
    for x in set:
        for y in set:
            prompt = "%s %s %s = ? "%(x,op,y)
            print " "
            z = raw_input(prompt)
            product [x,y] = z
            if z not in set:
                print " "
                print "No need to go any further:  your set is not a group"
          	return product
   		print " "
    items = product.items()
    items.sort()
    print " "
    print "your table is:"
    for(x,y),z in items:
        print " "
        print x,op,y, " = ",z
    print " "
    return product
    print " "

set = raw_input("Enter the elements of the set separated by a comma,ie, 
a,b,c: ")
set = string.split(set, ",")
print " "
op = raw_input("Enter the binary operator sign, ie, * : ")

s = getCayleyTable( op,set )
print " "
print s


As you can see, my program runs the way I wanted it.  Thanks for being so 
helpful (This includes everyone who has helped me all this time).  Now I 
have to check for associativity, and I'm trying to figure out how I can do 
that.  The idea is that given a set, say {e,a,b,ab}, and the table

e*e=e        a*e=a         b*e=b              ab*e=ab
e*a=a        a*a=e         b*a=ab             ab*a=b
e*b=b        a*b=ab        b*b=e              ab*b=a
e*ab=ab      a*ab=b        b*ab=a             ab*ab=e

we can look for associativity by making all the possible combinations.
That is, verify that e*(e*e)=(e*e)*e, a*(e*e)=(a*e)*e, and so on. To do this 
we would have to ask our dictionary for the table values and apply them to 
the elements on the set.  What I mean is, say I want to verify that 
a*(a*ab)= (a*a)*ab I need to take every item (or the definition of my item) 
from my dictionary and combine it with every item on my set.  We would need 
to consult our dictionary for the value of (a*ab) and (a*a).  Once we get 
our values (b, and e respectively), then we would consult our dictionary 
once again to figure out what a*b equals to and what e*ab equals to so we 
can compare.  As we can see, a*b=ab and e*ab= ab, therefore this particular 
combination works and we can move to the next one.  So you can see it 
better, scroll down:

  a*(a*ab)     and    (a*a)*ab
= a*( b )            =( e )*ab
= ab                 = ab


I know it is confusing, and maybe my wording is not explicit enough.  If you 
don't understand what I'm trying to say e-mail me.  Anyway, I'm working on 
this, and I'm assuming I will have to make another nested loop with my table 
values and my set.  I have no idea if I'm on the right track.  All I can do 
for now is think about how I could tell the computer to do this.  Do you 
have any suggestions, comments, or why not, an answer ;-), e-mail me.
>>>
Julieta
> >
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From tutor@python.org  Sun May  6 00:55:11 2001
From: tutor@python.org (Tim Peters)
Date: Sat, 5 May 2001 19:55:11 -0400
Subject: [Tutor] stopping a loop
In-Reply-To: <F31Ki3s1wsXZZTHfyQg0000188a@hotmail.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCIEHKKAAA.tim.one@home.com>

[Julieta Rangel]
> ...
> Now I  have to check for associativity, and I'm trying to figure out
> how I can do that.
> ...
> we can look for associativity by making all the possible combinations.
> That is, verify that e*(e*e)=(e*e)*e, a*(e*e)=(a*e)*e, and so on.

Here's a hint:  you want to verify that x*(y*z) == (x*y)*z for all x, y and z
in your set.  Earlier you wanted to build a table for all x and y in your
set.  The latter involved two variables and was solved with a doubly-nested
loop.  So the former, involving three variables, might be approached how?

One more hint:  If x, y and z are elements of your set, then the result of
x*(y*z) is spelled how?  Start with y*z:  that's

    product[y, z]

So x*(y*z) is

    product[x, product[y, z]]

and (x*y)*z is ...?

you're-closer-than-you-know<wink>-ly y'rs  - tim



From julieta_rangel@hotmail.com  Sun May  6 02:24:52 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sat, 05 May 2001 20:24:52 -0500
Subject: [Tutor] stopping a loop
Message-ID: <F95BXEHt3V5g2oHzGkz000018a7@hotmail.com>

Are you implying a tripple nested loop?  meaning
for x in set:
    for y in set:
        for z in set:
           if ['x',('y','z')] == [('x','y'),'z']:
              return associativity holds

Is this what you mean?  If I give the computer those commands, will it look 
for the definition on my dictionary?  You see, I'm not sure how I'm supposed 
to tell the computer to look in the dictionary for these values and compare 
them.  Any more hints, ideas, suggestions, comments, questions?

Julieta

>From: "Tim Peters" <tim.one@home.com>
>Reply-To: <tutor@python.org>
>To: "Julieta Rangel" <julieta_rangel@hotmail.com>
>CC: <tutor@python.org>
>Subject: RE: [Tutor] stopping a loop
>Date: Sat, 5 May 2001 19:55:11 -0400
>
>[Julieta Rangel]
> > ...
> > Now I  have to check for associativity, and I'm trying to figure out
> > how I can do that.
> > ...
> > we can look for associativity by making all the possible combinations.
> > That is, verify that e*(e*e)=(e*e)*e, a*(e*e)=(a*e)*e, and so on.
>
>Here's a hint:  you want to verify that x*(y*z) == (x*y)*z for all x, y and 
>z
>in your set.  Earlier you wanted to build a table for all x and y in your
>set.  The latter involved two variables and was solved with a doubly-nested
>loop.  So the former, involving three variables, might be approached how?
>
>One more hint:  If x, y and z are elements of your set, then the result of
>x*(y*z) is spelled how?  Start with y*z:  that's
>
>     product[y, z]
>
>So x*(y*z) is
>
>     product[x, product[y, z]]
>
>and (x*y)*z is ...?
>
>you're-closer-than-you-know<wink>-ly y'rs  - tim
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From sheila@thinkspot.net  Sun May  6 04:14:10 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sat, 05 May 2001 20:14:10 -0700
Subject: [Tutor] stopping a loop
In-Reply-To: <F95BXEHt3V5g2oHzGkz000018a7@hotmail.com>
References: <F95BXEHt3V5g2oHzGkz000018a7@hotmail.com>
Message-ID: <11BDBDF5CF9@kserver.org>

On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" <julieta_rangel@hotmail.com>
wrote about RE: [Tutor] stopping a loop:

:Are you implying a tripple nested loop?  meaning
:for x in set:
:    for y in set:
:        for z in set:
:           if ['x',('y','z')] == [('x','y'),'z']:
:              return associativity holds
:
:Is this what you mean?  If I give the computer those commands, will it look 
:for the definition on my dictionary?  You see, I'm not sure how I'm supposed 
:to tell the computer to look in the dictionary for these values and compare 
:them.  Any more hints, ideas, suggestions, comments, questions?
:
:Julieta

I'm not sure if Tim was implying a triply-nested loop, or not. It sounded kind of
like it to me, too. However, a double-nested loop will do fine.

The key is, you need to use your dictionary to look up the values of the operations.
That is the key. That is why you built the dictionary in the first place.

Note that dictionaries have keys and values.
For example:

>>> dict = {}
>>> dict['a']='apple'
>>> dict['b']='banana'
>>> dict['c']='cat'
>>> print dict.keys()
['b', 'c', 'a']
>>> print dict.values()
['banana', 'cat', 'apple']
>>> 

I can use a loop on a dictionary as follows:

>>> for key in dict.keys():
... 	print dict[key], " starts with ", key, "."
... 	
banana  starts with  b .
cat  starts with  c .
apple  starts with  a .

[Notice that it doesn't necessarily put them in order.]

Anyhow, for your situation, You are getting your table and storing it in the variable
s.

So, you should try this:

print s.keys()
print s.values()

for pair in s.keys():
	print pair " maps to ", s[pair]

Try this also:

for pair in s.keys():
	for elt in set:
		if s[pair]==elt:
			print pair, " maps to ", elt
		else:
			print pair, " does not map to ", elt


I don't think you will want to use any of those in your actual program, but playing
with those and watching them run should prove insightful (I hope).

OK, I've since decided, that Tim is probably right. I bet you do want a triply nested
loop. Hm. Interesting.

Here is what you asked about:


:Are you implying a tripple nested loop?  meaning
:for x in set:
:    for y in set:
:        for z in set:
:           if ['x',('y','z')] == [('x','y'),'z']:
:              return associativity holds

This is close. But, I think you need to apply your table mapping. You called the
table s, so:

for x in set:
    for y in set:
        for z in set:
            if s[(x, s(y,z))] == s[(s[(x,y)],z)]
                print "for ", str(s[(x, s(y,z))]), " and ", str(s[(s[(x,y)],z)])
		print "associativity holds\n"

Well, this will (I hope) get you closer to where you want to go. You're not there
yet, but you're getting there.

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



From tescoil@irtc.net  Sun May  6 06:17:41 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Sun, 06 May 2001 00:17:41 -0500
Subject: [Tutor] Possible Useless Python Challenge.
Message-ID: <3AF4DE75.770921E8@irtc.net>

Wondering about this as a possible Useless Python
Challenge.  I'd feel a little guilty suggesting it,
as I'm uncertain how difficult a task it is, but
really, Gilbert Roulot is moreso to blame. ;)

Roulot is the author of the Foks Linux KiSS viewer.
On the homepage, http://perso.wanadoo.fr/issarlk/Foks/
Roulot lists among "Features and technical stuff" that
Foks is "written in the GNU Sather language. The best
language there is to write KiSS viewers (IMNSHO)!"

It doesn't appear this has ever been demonstrated
incorrect by a better KiSS viewer being written 
in Python--for that matter, any KiSS viewer being 
written in Python.  

A KiSS viewer could prove a somewhat larger app than
would be considered "Useless Python," but it probably
qualifies in that one would be writing it perhaps more
to have it done in Python than need for the utility of
Yet Another program with which to play paperdolls...

KiSS data sets are bundled using LZH compression,
if there's a module for that, I haven't located it.  
I suppose that a cel file decoder could be cooked up
using Python Imaging Library, but I've no experience
in that department at all.  Other than that, I guess
one is up against reading .cnf files generated by a
variety of editors and sometimes written by hand.

More introduction & file specs can be found at
http://www2s.biglobe.ne.jp/~yav/kiss/indexe.html



From dyoo@hkn.eecs.berkeley.edu  Sun May  6 10:10:20 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sun, 6 May 2001 02:10:20 -0700 (PDT)
Subject: [Tutor] stopping a loop  [cross product instead of nested loops]
In-Reply-To: <11BDBDF5CF9@kserver.org>
Message-ID: <Pine.LNX.4.21.0105060151230.1756-100000@hkn.eecs.berkeley.edu>

On Sat, 5 May 2001, Sheila King wrote:

> On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" <julieta_rangel@hotmail.com>
> wrote about RE: [Tutor] stopping a loop:
> 
> :Are you implying a tripple nested loop?  meaning
> :for x in set:
> :    for y in set:
> :        for z in set:
> :           if ['x',('y','z')] == [('x','y'),'z']:
> :              return associativity holds
> :
> :Is this what you mean?  If I give the computer those commands, will it look 
> :for the definition on my dictionary?  You see, I'm not sure how I'm supposed 
> :to tell the computer to look in the dictionary for these values and compare 
> :them.  Any more hints, ideas, suggestions, comments, questions?
> :
> :Julieta
> 
> I'm not sure if Tim was implying a triply-nested loop, or not. It sounded kind of
> like it to me, too. However, a double-nested loop will do fine.
> 
> The key is, you need to use your dictionary to look up the values of the operations.
> That is the key. That is why you built the dictionary in the first place.


You might find the following definition useful: it's a way of producing
the "cross" product of two lists:

###
def cross(set1, set2):
    resulting_set = []
    for s1 in set1:
        for s2 in set2:
            resulting_set.append( (s1, s2) )
    return resulting_set
###


One reason why the cross product is so useful is because, given any two
lists, it can give back to us all possible pairs of those two lists, all
in a nice list:

###
>>> cross([1, 2, 3, 4], [1, 2, 3, 4])
[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1),
(3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)]
###

Or, more evocatively:

###
>>> numbers = ['1', '2']
>>> cross(numbers, cross(numbers, numbers))
[('1', ('1', '1')), ('1', ('1', '2')), ('1', ('2', '1')),
 ('1', ('2', '2')), ('2', ('1', '1')), ('2', ('1', '2')),
 ('2', ('2', '1')), ('2', ('2', '2'))] 
###

By using the function above, you might not even need any nested loops in
your own code.


Hope this helps!



From ppathiyi@cisco.com  Sun May  6 10:29:13 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Sun, 6 May 2001 14:59:13 +0530
Subject: [Tutor] stopping a loop
Message-ID: <063c01c0d60f$037e3470$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

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

Hi,
        I had one doubt while seeing the discussion about "stopping a =
loop".
        Don't we have a "goto" statement in python ?

Thanks,
Praveen.

------=_NextPart_000_0639_01C0D63D.1D1E0670
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I had=20
one doubt while seeing the discussion about "stopping a =
loop".</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
Don't we have=20
a "goto" statement in python ?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0639_01C0D63D.1D1E0670--



From dyoo@hkn.eecs.berkeley.edu  Sun May  6 11:23:09 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sun, 6 May 2001 03:23:09 -0700 (PDT)
Subject: [Tutor] stopping a loop
In-Reply-To: <063c01c0d60f$037e3470$37ef87c0@ppathiyipc>
Message-ID: <Pine.LNX.4.21.0105060311320.1756-100000@hkn.eecs.berkeley.edu>

On Sun, 6 May 2001, Praveen Pathiyil wrote:

>         I had one doubt while seeing the discussion about "stopping a loop".
>         Don't we have a "goto" statement in python ?


There is no goto.


However, it appears that the exception-handling model in Python can be
abused toward a similar effect:

    http://www.python.org/doc/FAQ.html#6.26

It's arguable if the idea of a goto is really "evil", but it does
complicate matters enough that it's not a feature in Python.


For amusement, here's a link to Edsgar Dijkstra's famous paper, "Goto's
Considered Harmful":

    http://www.acm.org/classics/oct95/

It's quite short, and pretty nice to see that something written in 1968
still has staying power.



From tim@johnsons-web.com  Sun May  6 18:11:49 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 6 May 2001 09:11:49 -0800
Subject: [Tutor] How Do I enable TKinter
Message-ID: <01050609170000.12427@bart.johnson.com>

Hello All:
	I recently installed Python 2.0 on RH Linux 6.0
I compiled from "scratch".
When I attempt to run a Python Module using TKinter:
I get the following error Message:
 File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ?
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
It appears to this 'ol c-dog that I haven't compiled in the tkinter module.

If this is the problem, what config switch should I be using? 
<duh>I can't seem to find any reference to tkinter in configure....</duh>
TIA
Tim


From rob@jam.rr.com  Sun May  6 17:34:35 2001
From: rob@jam.rr.com (rob@jam.rr.com)
Date: Sun, 06 May 2001 11:34:35 -0500
Subject: [Tutor] How Do I enable TKinter
References: <01050609170000.12427@bart.johnson.com>
Message-ID: <3AF57D1B.D01136A@jam.rr.com>

This may be considered blasphemous, depending on your perspective, but
since it's a RedHat system, have you tried using RPM installation?

Rob

Tim Johnson wrote:
> 
> Hello All:
>         I recently installed Python 2.0 on RH Linux 6.0
> I compiled from "scratch".
> When I attempt to run a Python Module using TKinter:
> I get the following error Message:
>  File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ?
>     import _tkinter # If this fails your Python may not be configured for Tk
> ImportError: No module named _tkinter
> It appears to this 'ol c-dog that I haven't compiled in the tkinter module.
> 
> If this is the problem, what config switch should I be using?
> <duh>I can't seem to find any reference to tkinter in configure....</duh>
> TIA
> Tim
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From kalle@gnupung.net  Sun May  6 18:06:58 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Sun, 6 May 2001 19:06:58 +0200
Subject: [Tutor] How Do I enable TKinter
In-Reply-To: <01050609170000.12427@bart.johnson.com>; from tim@johnsons-web.com on Sun, May 06, 2001 at 09:11:49AM -0800
References: <01050609170000.12427@bart.johnson.com>
Message-ID: <20010506190658.A12383@apone.network.loc>

Sez Tim Johnson:
> ImportError: No module named _tkinter
> It appears to this 'ol c-dog that I haven't compiled in the tkinter module.
> 
> If this is the problem, what config switch should I be using? 
> <duh>I can't seem to find any reference to tkinter in configure....</duh>

No wonder, there is none...  The Python 2.0 build process is IMHO slightly
less than optimal.  This is a lot better in 2.1, though.
Anyway, what you want is the Modules/Setup file.
Run configure, then copy Modules/Setup.in (or Modules/Setup.dist?  use the one
that exists. :) to Modules/Setup and edit it.  Then make and make install,
as usual.
All this is IIRC, it's been a while since I compiled 2.0.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From tim@johnsons-web.com  Sun May  6 21:46:52 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 6 May 2001 12:46:52 -0800
Subject: [Tutor] How Do I enable TKinter
References: <3AF57D1B.D01136A@jam.rr.com>
Message-ID: <01050612493301.12427@bart.johnson.com>

Hi Rob:
On Sun, 06 May 2001, rob@jam.rr.com wrote:
> This may be considered blasphemous, depending on your perspective, but
> since it's a RedHat system, have you tried using RPM installation?
Using RPMs doesn't conflict at all with my religious views. I guess I was
just compiler-happy that particular day. :>)
Actually, I am now in the process of getting the RPM. I'm hoping the package is
compatible with rpm on rh 6.0 - that is not always the case, I have found -
but we shall see. If not, I'm gonna upgrade to later RH soon.
Thanks
tj
> Rob
> 
> Tim Johnson wrote:
> > 
> > Hello All:
> >         I recently installed Python 2.0 on RH Linux 6.0
> > I compiled from "scratch".
> > When I attempt to run a Python Module using TKinter:
> > I get the following error Message:
> >  File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ?
> >     import _tkinter # If this fails your Python may not be configured for Tk
> > ImportError: No module named _tkinter
> > It appears to this 'ol c-dog that I haven't compiled in the tkinter module.
> > 
> > If this is the problem, what config switch should I be using?
> > <duh>I can't seem to find any reference to tkinter in configure....</duh>
> > TIA
> > Tim
> > 
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> 
> -- 
> 
> Useless Python!
> If your Python is this useless, we need you.
> http://www.lowerstandard.com/python/pythonsource.html


From julieta_rangel@hotmail.com  Mon May  7 01:34:50 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sun, 06 May 2001 19:34:50 -0500
Subject: [Tutor] [cross product instead of nested loops]
Message-ID: <F141l8aii08N8yxdZjf00002247@hotmail.com>

I've been playing with the cross product definition you gave me. It makes a 
lot of sense, and I'm sure it will make it a lot easier for me to prove 
associativity; however, I'm doing something wrong because when I run it, I 
don't get the result I thought I would.  Would you take a look and tell me 
what I'm doing wrong?


def cross(set1,set2):
    resulting_set = []
    for s1 in set1:
        for s2 in set2:
            resulting_set.append( (s1, s2) )
            return resulting_set

set = ['e','a','b', 'ab']
print set

s = cross(set,cross(set,set))
print s


When I run it, I get the following:

['e', 'a', 'b', 'ab']
[('e', ('e', 'e'))]  #Shouldn't I get 64 pairs here instead of one?

I thought that a loop would do the trick, but I couldn't figure out how to 
do it.  Can you help?  I want to get the entire 64 pairs on my printout.

Julieta

>From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: Sheila King <sheila@thinkspot.net>
>CC: Julieta Rangel <julieta_rangel@hotmail.com>, tutor@python.org
>Subject: Re: [Tutor] stopping a loop  [cross product instead of nested 
>loops]
>Date: Sun, 6 May 2001 02:10:20 -0700 (PDT)
>
>On Sat, 5 May 2001, Sheila King wrote:
>
> > On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" 
><julieta_rangel@hotmail.com>
> > wrote about RE: [Tutor] stopping a loop:
> >
> > :Are you implying a tripple nested loop?  meaning
> > :for x in set:
> > :    for y in set:
> > :        for z in set:
> > :           if ['x',('y','z')] == [('x','y'),'z']:
> > :              return associativity holds
> > :
> > :Is this what you mean?  If I give the computer those commands, will it 
>look
> > :for the definition on my dictionary?  You see, I'm not sure how I'm 
>supposed
> > :to tell the computer to look in the dictionary for these values and 
>compare
> > :them.  Any more hints, ideas, suggestions, comments, questions?
> > :
> > :Julieta
> >
> > I'm not sure if Tim was implying a triply-nested loop, or not. It 
>sounded kind of
> > like it to me, too. However, a double-nested loop will do fine.
> >
> > The key is, you need to use your dictionary to look up the values of the 
>operations.
> > That is the key. That is why you built the dictionary in the first 
>place.
>
>
>You might find the following definition useful: it's a way of producing
>the "cross" product of two lists:
>
>###
>def cross(set1, set2):
>     resulting_set = []
>     for s1 in set1:
>         for s2 in set2:
>             resulting_set.append( (s1, s2) )
>     return resulting_set
>###
>
>
>One reason why the cross product is so useful is because, given any two
>lists, it can give back to us all possible pairs of those two lists, all
>in a nice list:
>
>###
> >>> cross([1, 2, 3, 4], [1, 2, 3, 4])
>[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1),
>(3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)]
>###
>
>Or, more evocatively:
>
>###
> >>> numbers = ['1', '2']
> >>> cross(numbers, cross(numbers, numbers))
>[('1', ('1', '1')), ('1', ('1', '2')), ('1', ('2', '1')),
>  ('1', ('2', '2')), ('2', ('1', '1')), ('2', ('1', '2')),
>  ('2', ('2', '1')), ('2', ('2', '2'))]
>###
>
>By using the function above, you might not even need any nested loops in
>your own code.
>
>
>Hope this helps!
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From julieta_rangel@hotmail.com  Mon May  7 02:06:27 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sun, 06 May 2001 20:06:27 -0500
Subject: [Tutor] stopping a loop [cross product instead of nested loops]
Message-ID: <F203bXCH5n00zepDI8N000023a6@hotmail.com>

I've been playing with the cross product definition you gave me. It makes a
lot of sense, and I'm sure it will make it a lot easier for me to prove
associativity; however, I'm doing something wrong because when I run it, I
don't get the result I thought I would.  Would you take a look and tell me
what I'm doing wrong?


def cross(set1,set2):
    resulting_set = []
    for s1 in set1:
        for s2 in set2:
            resulting_set.append( (s1, s2) )
            return resulting_set

set = ['e','a','b', 'ab']
print set

s = cross(set,cross(set,set))
print s


When I run it, I get the following:

['e', 'a', 'b', 'ab']
[('e', ('e', 'e'))]  #Shouldn't I get 64 pairs here instead of one?

I thought that a loop would do the trick, but I couldn't figure out how to
do it.  Can you help?  I want to get the entire 64 pairs on my printout.

Julieta




>From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: Sheila King <sheila@thinkspot.net>
>CC: Julieta Rangel <julieta_rangel@hotmail.com>, tutor@python.org
>Subject: Re: [Tutor] stopping a loop  [cross product instead of nested 
>loops]
>Date: Sun, 6 May 2001 02:10:20 -0700 (PDT)
>
>On Sat, 5 May 2001, Sheila King wrote:
>
> > On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" 
><julieta_rangel@hotmail.com>
> > wrote about RE: [Tutor] stopping a loop:
> >
> > :Are you implying a tripple nested loop?  meaning
> > :for x in set:
> > :    for y in set:
> > :        for z in set:
> > :           if ['x',('y','z')] == [('x','y'),'z']:
> > :              return associativity holds
> > :
> > :Is this what you mean?  If I give the computer those commands, will it 
>look
> > :for the definition on my dictionary?  You see, I'm not sure how I'm 
>supposed
> > :to tell the computer to look in the dictionary for these values and 
>compare
> > :them.  Any more hints, ideas, suggestions, comments, questions?
> > :
> > :Julieta
> >
> > I'm not sure if Tim was implying a triply-nested loop, or not. It 
>sounded kind of
> > like it to me, too. However, a double-nested loop will do fine.
> >
> > The key is, you need to use your dictionary to look up the values of the 
>operations.
> > That is the key. That is why you built the dictionary in the first 
>place.
>
>
>You might find the following definition useful: it's a way of producing
>the "cross" product of two lists:
>
>###
>def cross(set1, set2):
>     resulting_set = []
>     for s1 in set1:
>         for s2 in set2:
>             resulting_set.append( (s1, s2) )
>     return resulting_set
>###
>
>
>One reason why the cross product is so useful is because, given any two
>lists, it can give back to us all possible pairs of those two lists, all
>in a nice list:
>
>###
> >>> cross([1, 2, 3, 4], [1, 2, 3, 4])
>[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1),
>(3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)]
>###
>
>Or, more evocatively:
>
>###
> >>> numbers = ['1', '2']
> >>> cross(numbers, cross(numbers, numbers))
>[('1', ('1', '1')), ('1', ('1', '2')), ('1', ('2', '1')),
>  ('1', ('2', '2')), ('2', ('1', '1')), ('2', ('1', '2')),
>  ('2', ('2', '1')), ('2', ('2', '2'))]
>###
>
>By using the function above, you might not even need any nested loops in
>your own code.
>
>
>Hope this helps!
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From julieta_rangel@hotmail.com  Mon May  7 03:07:47 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sun, 06 May 2001 21:07:47 -0500
Subject: [Tutor] stopping a loop [cross product instead of nested loops]
Message-ID: <F114oY99EXxt5BBBVhy00002354@hotmail.com>

I've been playing with the cross product definition you gave me. It makes a
lot of sense, and I'm sure it will make it a lot easier for me to prove
associativity; however, I'm doing something wrong because when I run it, I
don't get the result I thought I would.  Would you take a look and tell me
what I'm doing wrong?


def cross(set1,set2):
    resulting_set = []
    for s1 in set1:
        for s2 in set2:
            resulting_set.append( (s1, s2) )
            return resulting_set

set = ['e','a','b', 'ab']
print set

s = cross(set,cross(set,set))
print s


When I run it, I get the following:

['e', 'a', 'b', 'ab']
[('e', ('e', 'e'))]  #Shouldn't I get 64 pairs here instead of one?

I thought that a loop would do the trick, but I couldn't figure out how to
do it.  Can you help?  I want to get the entire 64 pairs on my printout.

Julieta




>From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: Sheila King <sheila@thinkspot.net>
>CC: Julieta Rangel <julieta_rangel@hotmail.com>, tutor@python.org
>Subject: Re: [Tutor] stopping a loop  [cross product instead of nested 
>loops]
>Date: Sun, 6 May 2001 02:10:20 -0700 (PDT)
>
>On Sat, 5 May 2001, Sheila King wrote:
>
> > On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" 
><julieta_rangel@hotmail.com>
> > wrote about RE: [Tutor] stopping a loop:
> >
> > :Are you implying a tripple nested loop?  meaning
> > :for x in set:
> > :    for y in set:
> > :        for z in set:
> > :           if ['x',('y','z')] == [('x','y'),'z']:
> > :              return associativity holds
> > :
> > :Is this what you mean?  If I give the computer those commands, will it 
>look
> > :for the definition on my dictionary?  You see, I'm not sure how I'm 
>supposed
> > :to tell the computer to look in the dictionary for these values and 
>compare
> > :them.  Any more hints, ideas, suggestions, comments, questions?
> > :
> > :Julieta
> >
> > I'm not sure if Tim was implying a triply-nested loop, or not. It 
>sounded kind of
> > like it to me, too. However, a double-nested loop will do fine.
> >
> > The key is, you need to use your dictionary to look up the values of the 
>operations.
> > That is the key. That is why you built the dictionary in the first 
>place.
>
>
>You might find the following definition useful: it's a way of producing
>the "cross" product of two lists:
>
>###
>def cross(set1, set2):
>     resulting_set = []
>     for s1 in set1:
>         for s2 in set2:
>             resulting_set.append( (s1, s2) )
>     return resulting_set
>###
>
>
>One reason why the cross product is so useful is because, given any two
>lists, it can give back to us all possible pairs of those two lists, all
>in a nice list:
>
>###
> >>> cross([1, 2, 3, 4], [1, 2, 3, 4])
>[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1),
>(3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)]
>###
>
>Or, more evocatively:
>
>###
> >>> numbers = ['1', '2']
> >>> cross(numbers, cross(numbers, numbers))
>[('1', ('1', '1')), ('1', ('1', '2')), ('1', ('2', '1')),
>  ('1', ('2', '2')), ('2', ('1', '1')), ('2', ('1', '2')),
>  ('2', ('2', '1')), ('2', ('2', '2'))]
>###
>
>By using the function above, you might not even need any nested loops in
>your own code.
>
>
>Hope this helps!
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From rob@jam.rr.com  Mon May  7 03:30:11 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Sun, 06 May 2001 21:30:11 -0500
Subject: [Tutor] Re: Possible Useless Python Challenge.
References: <3AF4DE75.770921E8@irtc.net>
Message-ID: <3AF608B3.BC998B57@jam.rr.com>

Thanks for the suggestion. As soon as I can think of the right way to
present it, I'll be glad to post it with the other challenges. If anyone
has no idea what we're talking about, please forgive. The Useless
Challenges are on the Useless Python site, and basically give you the
chance to suggest ideas for applications for the general public to
decide whether to try and code.

Rob

Tesla Coil wrote:
> 
> Wondering about this as a possible Useless Python
> Challenge.  I'd feel a little guilty suggesting it,
> as I'm uncertain how difficult a task it is, but
> really, Gilbert Roulot is moreso to blame. ;)
> 
> Roulot is the author of the Foks Linux KiSS viewer.
> On the homepage, http://perso.wanadoo.fr/issarlk/Foks/
> Roulot lists among "Features and technical stuff" that
> Foks is "written in the GNU Sather language. The best
> language there is to write KiSS viewers (IMNSHO)!"
> 
> It doesn't appear this has ever been demonstrated
> incorrect by a better KiSS viewer being written
> in Python--for that matter, any KiSS viewer being
> written in Python.
> 
> A KiSS viewer could prove a somewhat larger app than
> would be considered "Useless Python," but it probably
> qualifies in that one would be writing it perhaps more
> to have it done in Python than need for the utility of
> Yet Another program with which to play paperdolls...
> 
> KiSS data sets are bundled using LZH compression,
> if there's a module for that, I haven't located it.
> I suppose that a cel file decoder could be cooked up
> using Python Imaging Library, but I've no experience
> in that department at all.  Other than that, I guess
> one is up against reading .cnf files generated by a
> variety of editors and sometimes written by hand.
> 
> More introduction & file specs can be found at
> http://www2s.biglobe.ne.jp/~yav/kiss/indexe.html

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From dyoo@hkn.eecs.berkeley.edu  Mon May  7 03:55:06 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sun, 6 May 2001 19:55:06 -0700 (PDT)
Subject: [Tutor] [cross product instead of nested loops]
In-Reply-To: <F141l8aii08N8yxdZjf00002247@hotmail.com>
Message-ID: <Pine.LNX.4.21.0105061949010.3702-100000@hkn.eecs.berkeley.edu>

On Sun, 6 May 2001, Julieta Rangel wrote:

> I've been playing with the cross product definition you gave me. It makes a 
> lot of sense, and I'm sure it will make it a lot easier for me to prove 
> associativity; however, I'm doing something wrong because when I run it, I 
> don't get the result I thought I would.  Would you take a look and tell me 
> what I'm doing wrong?
> 
> 
> def cross(set1,set2):
>     resulting_set = []
>     for s1 in set1:
>         for s2 in set2:
>             resulting_set.append( (s1, s2) )
>             return resulting_set                 ## <-- bug!

There's a bug here: we want to return the resulting_set only after we
finish going through both for loops.  That is:

###
def cross(set1,set2):
    resulting_set = []
    for s1 in set1:
        for s2 in set2:
            resulting_set.append( (s1, s2) )
    return resulting_set
###

The difference is in indentation, but the idea is that the request about
returning a result should be outside of the looping.  After fixing this,
the program should work ok.



From julieta_rangel@hotmail.com  Mon May  7 03:56:35 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sun, 06 May 2001 21:56:35 -0500
Subject: [Tutor] cross product
Message-ID: <F87dyDd3OJXsNQptgFr000023a1@hotmail.com>

I've been playing with the cross product definition Daniel gave me. It makes 
a
lot of sense, and I'm sure it will make it a lot easier for me to prove
associativity; however, I'm doing something wrong because when I run it, I
don't get the result I thought I would.  Would you take a look and tell me
what I'm doing wrong?


def cross(set1,set2):
    resulting_set = []
    for s1 in set1:
        for s2 in set2:
            resulting_set.append( (s1, s2) )
            return resulting_set

set = ['e','a','b', 'ab']
print set

s = cross(set,cross(set,set))
print s


When I run it, I get the following:

['e', 'a', 'b', 'ab']
[('e', ('e', 'e'))]  #Shouldn't I get 64 pairs here instead of one?

I thought that a loop would do the trick, but I couldn't figure out how to
do it.  Can you help?  I want to get the entire 64 pairs on my printout.

Julieta


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From julieta_rangel@hotmail.com  Mon May  7 04:29:24 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sun, 06 May 2001 22:29:24 -0500
Subject: [Tutor] [cross product instead of nested loops]
Message-ID: <F1134kDn9cvKluevz170000249b@hotmail.com>

Thank you.  Now it makes sense.  By the way, I want to apologize in case you 
received this message over and over.  What happened is that every time I 
tried to send it I received a message that the e-mail could not be 
delivered, so I would send it again, and again.  Obviously this message 
could be delivered.  I must have been annoying posting the message over and 
over.  Sorry!

Julieta


>From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: Julieta Rangel <julieta_rangel@hotmail.com>
>CC: sheila@thinkspot.net, tutor@python.org
>Subject: Re: [Tutor] [cross product instead of nested loops]
>Date: Sun, 6 May 2001 19:55:06 -0700 (PDT)
>
>On Sun, 6 May 2001, Julieta Rangel wrote:
>
> > I've been playing with the cross product definition you gave me. It 
>makes a
> > lot of sense, and I'm sure it will make it a lot easier for me to prove
> > associativity; however, I'm doing something wrong because when I run it, 
>I
> > don't get the result I thought I would.  Would you take a look and tell 
>me
> > what I'm doing wrong?
> >
> >
> > def cross(set1,set2):
> >     resulting_set = []
> >     for s1 in set1:
> >         for s2 in set2:
> >             resulting_set.append( (s1, s2) )
> >             return resulting_set                 ## <-- bug!
>
>There's a bug here: we want to return the resulting_set only after we
>finish going through both for loops.  That is:
>
>###
>def cross(set1,set2):
>     resulting_set = []
>     for s1 in set1:
>         for s2 in set2:
>             resulting_set.append( (s1, s2) )
>     return resulting_set
>###
>
>The difference is in indentation, but the idea is that the request about
>returning a result should be outside of the looping.  After fixing this,
>the program should work ok.
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From julieta_rangel@hotmail.com  Mon May  7 04:40:50 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Sun, 06 May 2001 22:40:50 -0500
Subject: [Tutor] obtaining values from a dictionary
Message-ID: <F24Np7vXee4fDGCl9Fo000024d5@hotmail.com>

I have a list that looks like:
c = [('a', ('a', 'a')), ('a', ('a', 'b')), ('a', ('b', 'a')), ('a', ('b', 
'b')), ('b', ('a', 'a')), ('b', ('a', 'b')), ('b', ('b', 'a')), ('b', ('b', 
'b'))]

and I have a dictionary that looks like:
d ={('b', 'a'): 'a', ('a', 'a'): 'a', ('a', 'b'): 'b', ('b', 'b'): 'b'}

I want to replace the elements in my list according to my dictionary values. 
  In other words, I want to go element by element on my list and ask the 
computer to give me the corresponding value, according to the dictionary.  
For example, if I want to get the value of my second element in my list 
('a',('a','b')), according to my dictionary, this is equal to ('a','b'), 
which is equal to b.  Can this be done?

Julieta

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From daniel@longbeach.goldinc.com  Mon May  7 05:38:06 2001
From: daniel@longbeach.goldinc.com (Daniel)
Date: Sun, 6 May 2001 23:38:06 -0500 (CDT)
Subject: [Tutor] obtaining values from a dictionary
In-Reply-To: <F24Np7vXee4fDGCl9Fo000024d5@hotmail.com>
Message-ID: <Pine.LNX.3.93.1010506233352.7092A-100000@longbeach.goldinc.com>

Hello Julieta,   

I think this is the answer to your question  *shrug*   :)

count = 0
for element in c:
    if d.has_key(c[count][1]) == 1:
        print "got it => ",
        print "dic value is ", d[c[count][1]]
        c[count] = d[c[count][1]]
    else:
        print "nope"
    count += 1

print "new list is", c


--
Daniel, AIM=davignes


On Sun, 6 May 2001, Julieta Rangel wrote:

> I have a list that looks like:
> c = [('a', ('a', 'a')), ('a', ('a', 'b')), ('a', ('b', 'a')), ('a', ('b', 
> 'b')), ('b', ('a', 'a')), ('b', ('a', 'b')), ('b', ('b', 'a')), ('b', ('b', 
> 'b'))]
> 
> and I have a dictionary that looks like:
> d ={('b', 'a'): 'a', ('a', 'a'): 'a', ('a', 'b'): 'b', ('b', 'b'): 'b'}
> 
> I want to replace the elements in my list according to my dictionary values. 
>   In other words, I want to go element by element on my list and ask the 
> computer to give me the corresponding value, according to the dictionary.  
> For example, if I want to get the value of my second element in my list 
> ('a',('a','b')), according to my dictionary, this is equal to ('a','b'), 
> which is equal to b.  Can this be done?
> 
> Julieta
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



From bdupire@seatech.fau.edu  Mon May  7 05:39:34 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Mon, 07 May 2001 00:39:34 -0400
Subject: [Tutor] obtaining values from a dictionary
References: <F24Np7vXee4fDGCl9Fo000024d5@hotmail.com>
Message-ID: <3AF62706.7FB6AB3@seatech.fau.edu>

This is my try...
I did not read all of the previous messages so i don't know very well the
context of your question...
I assume the question is well formulated.

This should do what you want:

for  i in range(len(c)):            # for each element of your list c
    item1, item2 = c[i]               # this element is a tuple --> break it
into 2 parts.
    if d.has_key(item2):               # if the 2nd part  of the item is in the
dictionary d
            c[i][1]= d[item2]            # replace the 2nd part of the  tuple
with the entry in the dict
            if d.has_key(c[i]):                    # now there is a new tuple,
so we have to check whether it is or not, once again, in the dictionary
                    c[i] = d[c[i]]                    # if yes, we replace the
tuple with the entry in the dictionary.



A common pitfall for this algorithm is to do it like this:

for item1, item2 in c:               # This does exactly like my first 2 lines.
It take an element of c, and breaks it into 2 parts.1
        if d.has_key(item2):               # if the 2nd part of the item is in
the d ictionary d
            item2= d[item2]            #     replace the 2nd part of the tuple
------> Trap !!!!  this line does not change the list, but the variable item2

See the difference..?  i have to do something like c[index] to really change the
list.... IOW to refer to it explicitly.

Benoit



Julieta Rangel wrote:

> I have a list that looks like:
> c = [('a', ('a', 'a')), ('a', ('a', 'b')), ('a', ('b', 'a')), ('a', ('b',
> 'b')), ('b', ('a', 'a')), ('b', ('a', 'b')), ('b', ('b', 'a')), ('b', ('b',
> 'b'))]
>
> and I have a dictionary that looks like:
> d ={('b', 'a'): 'a', ('a', 'a'): 'a', ('a', 'b'): 'b', ('b', 'b'): 'b'}
>
> I want to replace the elements in my list according to my dictionary values.
>   In other words, I want to go element by element on my list and ask the
> computer to give me the corresponding value, according to the dictionary.
> For example, if I want to get the value of my second element in my list
> ('a',('a','b')), according to my dictionary, this is equal to ('a','b'),
> which is equal to b.  Can this be done?
>
> Julieta
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From julieta_rangel@hotmail.com  Mon May  7 08:21:01 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Mon, 07 May 2001 02:21:01 -0500
Subject: [Tutor] checking within a table for identity
Message-ID: <F270jtX5igRFHzFHG4v00002691@hotmail.com>

As some of you might remember, I was trying to figure out how to check for 
associativity within a set.  By taking bits and pieces from you all's 
advice, I put together the following:

import string
def getCayleyTable(op,set):
    product = {}
    for x in set:
        for y in set:
            prompt = "%s %s %s = ? "%(x,op,y)
            print " "
            z = raw_input(prompt)
            product [x,y] = z
            if z not in set:
                print " "
                print "No need to go any further:  your set is not a group"
          	return product
   		print " "
    items = product.items()
    items.sort()

    return product

    print " "

def cross(set1,set2):
    resulting_set = []
    for s1 in set1:
        for s2 in set2:
            resulting_set.append( (s1, s2) )
    return resulting_set

set = raw_input("Enter the elements of the set separated by a comma,ie, 
a,b,c: ")
set = string.split(set, ",")

print " "
op = raw_input("Enter the binary operator sign, ie, * : ")

d = getCayleyTable( op,set )
print " "

m=cross(set,set)
v=[]
for x in m:
    v.append(d[x])
print v

for x in set:
    c= cross(set,v)
    e= cross(v,set)
l=[]
for x in c:
    l.append(d[x])

k=[]
for x in e:
    k.append(d[x])

if l!=k: print "your set is not a group"

As you can see, I don't have experience in programming, but considering I 
started learning about a month ago, my program is not that awful.  Now I 
want to figure out how to check for identity on a set.  By identity I mean, 
given a set, there is an element in the set(let's call it e) such that for 
all elements x, x*e= e*x =x.  For example, let's say I have the set 
{e,a,b,ab}, which is accompanied by the following table:

>e*e=e        a*e=a         b*e=b              ab*e=ab
>e*a=a        a*a=e         b*a=ab             ab*a=b
>e*b=b        a*b=ab        b*b=e              ab*b=a
>e*ab=ab      a*ab=b        b*ab=a             ab*ab=e

As you might see, the set {e,a,b,ab} has an identity element, which is e. If 
you check, e*a=a and a*e=a, so e is the identity element of the set. As you 
can see, you have to do this for every element within the set.  What I need 
to do is to "check whether there is an item in the set, where (item, 
whatever)== whatever, for each whatever in the set, and also check whether 
(whatever, item) == whatever."  (I'm quoting from one of you guys, I believe 
it is from Ms. King).  Does anyone have any suggestions?

Julieta
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From ppathiyi@cisco.com  Mon May  7 11:53:13 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Mon, 7 May 2001 16:23:13 +0530
Subject: [Tutor] Converting a list to a string
Message-ID: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

------=_NextPart_000_012D_01C0D712.038317C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

If i have a list=20
status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
is there a single command which will give me a string=20
tftp> Sent 1943 bytes in 0.0 seconds

OR do i have to do=20

stat_str =3D ''
for elt in status:
    stat_str =3D stat_str + ' ' + elt

TIA,
Praveen.

------=_NextPart_000_012D_01C0D712.038317C0
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>If i have a list </FONT><FONT =
face=3DArial=20
size=3D2></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>status =3D ['tftp&gt;', 'Sent', '1943', =
'bytes',=20
'in', '0.0', 'seconds'],</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>is there a single command which will =
give me a=20
string </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>tftp&gt; Sent 1943 bytes in 0.0=20
seconds</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>OR <FONT face=3DArial size=3D2>do i =
have to do=20
</FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>stat_str =3D ''</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>for elt in status:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; <FONT face=3DArial =
size=3D2>stat_str=20
=3D <FONT face=3DArial size=3D2>stat_str + ' ' + =
elt</FONT></FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV></BODY></HTML>

------=_NextPart_000_012D_01C0D712.038317C0--



From scarblac@pino.selwerd.nl  Mon May  7 11:58:42 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 7 May 2001 12:58:42 +0200
Subject: [Tutor] Converting a list to a string
In-Reply-To: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc>; from ppathiyi@cisco.com on Mon, May 07, 2001 at 04:23:13PM +0530
References: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc>
Message-ID: <20010507125842.A31257@pino.selwerd.nl>

On  0, Praveen Pathiyil <ppathiyi@cisco.com> wrote:
> Hi all,
> 
> If i have a list 
> status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
> is there a single command which will give me a string 
> tftp> Sent 1943 bytes in 0.0 seconds
> 
> OR do i have to do 
> 
> stat_str = ''
> for elt in status:
>     stat_str = stat_str + ' ' + elt

import string
print string.join(status)    # If you want something other than a space,
                             # give it as second argument.

In new versions you can also spell that

" ".join(status)       # Join list 'status' with spaces in between

-- 
Remco Gerlich


From wheelege@tsn.cc  Mon May  7 11:59:15 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Mon, 7 May 2001 20:59:15 +1000
Subject: [Tutor] Converting a list to a string
References: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc>
Message-ID: <020501c0d6e4$cf904500$0200a8c0@ACE>

This is a multi-part message in MIME format.

------=_NextPart_000_0202_01C0D738.935167A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


  I think you want to have a look at string.join().

  For example...

>>> import string
>>> x =3D ['I', 'am', 'a', 'string']
>>> string.join(x)
'I am a string'

  You can also specify the separating character as well, with a second =
argument.  Like...

>>> x =3D ['W', 'o', 'r', 'd']
>>> string.join(x, '')
'Word'

  Hope that helps,
  Glen.

  ----- Original Message -----=20
  From: Praveen Pathiyil=20
  To: tutor@python.org=20
  Sent: Monday, May 07, 2001 8:53 PM
  Subject: [Tutor] Converting a list to a string


  Hi all,

  If i have a list=20
  status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
  is there a single command which will give me a string=20
  tftp> Sent 1943 bytes in 0.0 seconds

  OR do i have to do=20

  stat_str =3D ''
  for elt in status:
      stat_str =3D stat_str + ' ' + elt

  TIA,
  Praveen.

------=_NextPart_000_0202_01C0D738.935167A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; I think you want to have a look at string.join().</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; For example...</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&gt;&gt; import string</DIV>
<DIV>&gt;&gt;&gt; x =3D ['I', 'am', 'a', 'string']<BR>&gt;&gt;&gt;=20
string.join(x)<BR>'I am a string'</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; You can also specify the separating character as well, with =
a second=20
argument.&nbsp; Like...</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&gt;&gt; x =3D ['W', 'o', 'r', 'd']<BR>&gt;&gt;&gt; =
string.join(x,=20
'')<BR>'Word'</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Hope that helps,</DIV>
<DIV>&nbsp; Glen.</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dppathiyi@cisco.com =
href=3D"mailto:ppathiyi@cisco.com">Praveen=20
  Pathiyil</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, May 07, 2001 8:53 =
PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Converting a =
list to a=20
  string</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>If i have a list </FONT><FONT =
face=3DArial=20
  size=3D2></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>status =3D ['tftp&gt;', 'Sent', =
'1943', 'bytes',=20
  'in', '0.0', 'seconds'],</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>is there a single command which will =
give me a=20
  string </FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>tftp&gt; Sent 1943 bytes in 0.0=20
  seconds</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>OR <FONT face=3DArial size=3D2>do i =
have to do=20
  </FONT></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>stat_str =3D ''</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>for elt in status:</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; <FONT face=3DArial =

  size=3D2>stat_str =3D <FONT face=3DArial size=3D2>stat_str + ' ' +=20
  elt</FONT></FONT></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>Praveen.</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0202_01C0D738.935167A0--



From ppathiyi@cisco.com  Mon May  7 12:10:34 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Mon, 7 May 2001 16:40:34 +0530
Subject: [Tutor] Converting a list to a string
References: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc> <020501c0d6e4$cf904500$0200a8c0@ACE>
Message-ID: <016c01c0d6e6$567f0140$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

------=_NextPart_000_0169_01C0D714.7021E080
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks Glen and Remco.
That would definitely serve my purpose.

Regards,
Praveen.
  ----- Original Message -----=20
  From: Glen Wheeler=20
  To: Praveen Pathiyil ; tutor@python.org=20
  Sent: Monday, May 07, 2001 4:29 PM
  Subject: Re: [Tutor] Converting a list to a string



    I think you want to have a look at string.join().

    For example...

  >>> import string
  >>> x =3D ['I', 'am', 'a', 'string']
  >>> string.join(x)
  'I am a string'

    You can also specify the separating character as well, with a second =
argument.  Like...

  >>> x =3D ['W', 'o', 'r', 'd']
  >>> string.join(x, '')
  'Word'

    Hope that helps,
    Glen.

    ----- Original Message -----=20
    From: Praveen Pathiyil=20
    To: tutor@python.org=20
    Sent: Monday, May 07, 2001 8:53 PM
    Subject: [Tutor] Converting a list to a string


    Hi all,
    =20
    If i have a list=20
    status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', =
'seconds'],
    is there a single command which will give me a string=20
    tftp> Sent 1943 bytes in 0.0 seconds

    OR do i have to do=20

    stat_str =3D ''
    for elt in status:
        stat_str =3D stat_str + ' ' + elt

    TIA,
    Praveen.

------=_NextPart_000_0169_01C0D714.7021E080
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Thanks Glen and Remco.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>That would definitely serve my=20
purpose.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:wheelege@tsn.cc" title=3Dwheelege@tsn.cc>Glen =
Wheeler</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:ppathiyi@cisco.com"=20
  title=3Dppathiyi@cisco.com>Praveen Pathiyil</A> ; <A=20
  href=3D"mailto:tutor@python.org" =
title=3Dtutor@python.org>tutor@python.org</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, May 07, 2001 4:29 =
PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [Tutor] Converting =
a list to=20
  a string</DIV>
  <DIV><BR></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp; I think you want to have a look at string.join().</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp; For example...</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&gt;&gt;&gt; import string</DIV>
  <DIV>&gt;&gt;&gt; x =3D ['I', 'am', 'a', 'string']<BR>&gt;&gt;&gt;=20
  string.join(x)<BR>'I am a string'</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp; You can also specify the separating character as well, =
with a=20
  second argument.&nbsp; Like...</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&gt;&gt;&gt; x =3D ['W', 'o', 'r', 'd']<BR>&gt;&gt;&gt; =
string.join(x,=20
  '')<BR>'Word'</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp; Hope that helps,</DIV>
  <DIV>&nbsp; Glen.</DIV>
  <DIV>&nbsp;</DIV>
  <BLOCKQUOTE dir=3Dltr=20
  style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; =
MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
    <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
    <DIV=20
    style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
    <A href=3D"mailto:ppathiyi@cisco.com" =
title=3Dppathiyi@cisco.com>Praveen=20
    Pathiyil</A> </DIV>
    <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:tutor@python.org"=20
    title=3Dtutor@python.org>tutor@python.org</A> </DIV>
    <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, May 07, 2001 =
8:53=20
PM</DIV>
    <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Converting a =
list to a=20
    string</DIV>
    <DIV><BR></DIV>
    <DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>If i have a list </FONT><FONT =
face=3DArial=20
    size=3D2></FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>status =3D ['tftp&gt;', 'Sent', =
'1943', 'bytes',=20
    'in', '0.0', 'seconds'],</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>is there a single command which =
will give me a=20
    string </FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>tftp&gt; Sent 1943 bytes in 0.0=20
    seconds</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>OR <FONT face=3DArial size=3D2>do i =
have to do=20
    </FONT></FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>stat_str =3D ''</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>for elt in status:</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; <FONT =
face=3DArial=20
    size=3D2>stat_str =3D <FONT face=3DArial size=3D2>stat_str + ' ' +=20
    elt</FONT></FONT></FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
    <DIV><FONT face=3DArial=20
size=3D2>Praveen.</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0169_01C0D714.7021E080--



From arcege@speakeasy.net  Mon May  7 12:15:41 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Mon, 7 May 2001 07:15:41 -0400 (EDT)
Subject: [Tutor] Converting a list to a string
In-Reply-To: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc> from "Praveen Pathiyil" at May 07, 2001 04:23:13 PM
Message-ID: <200105071115.f47BFfS01582@dsl092-074-184.bos1.dsl.speakeasy.net>

Praveen Pathiyil wrote
> Hi all,
> 
> If i have a list=20
> status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
> is there a single command which will give me a string=20
> tftp> Sent 1943 bytes in 0.0 seconds
> 
> OR do i have to do=20
> 
> stat_str =3D ''
> for elt in status:
>     stat_str =3D stat_str + ' ' + elt

You don't _have_ to do that; in fact, concatenating strings that way is
very inefficient (the left hand of the '+' is copied each time through the
loop).  There is a join function/method for strings to do this for you.

In Python 2.0 and higher, you can use string methods, but on the joiner
(in this case the space):
  stat_str = ' '.join(status)

In earlier releases, use the join function in the string module:
  import string
  stat_str = string.join(status)

Also, if you use the loop above, you'll have an extra space in the
front of the resulting string.  You won't get that with the join
routines.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From sheila@thinkspot.net  Mon May  7 14:04:46 2001
From: sheila@thinkspot.net (Sheila King)
Date: Mon, 07 May 2001 06:04:46 -0700
Subject: [Tutor] checking within a table for identity
In-Reply-To: <F270jtX5igRFHzFHG4v00002691@hotmail.com>
References: <F270jtX5igRFHzFHG4v00002691@hotmail.com>
Message-ID: <28386736E4B@kserver.org>

On Mon, 07 May 2001 02:21:01 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com>  wrote about [Tutor] checking within a table for
identity:

:
:As you might see, the set {e,a,b,ab} has an identity element, which is e. If 
:you check, e*a=a and a*e=a, so e is the identity element of the set. As you 
:can see, you have to do this for every element within the set.  What I need 
:to do is to "check whether there is an item in the set, where (item, 
:whatever)== whatever, for each whatever in the set, and also check whether 
:(whatever, item) == whatever."  (I'm quoting from one of you guys, I believe 
:it is from Ms. King).  Does anyone have any suggestions?

I would probably write a function

IsIdentityElement(elt, set)

Where the function would take the element, and check for each item in the set if

(elt, item) == item
and 
(item, elt) == item

This would require a loop. (Sometime like for item in set: )

I would have IsIdentity Element return a 1 if the elt turned out to be the
Identity Element, and have it return 0, otherwise.

Probably I'd have it test for
not (elt, item) == item

and

not (item, elt) == item

And if it came out to be the case, that it was not the identity element, return
0 immediately (which would make it break out of the loop. If I made it through
all the loops without breaking out and returning a zero, have it return 1,
because it passed all the tests and must be the identity element.

When you call it in your script's main body, you need a loop there, too, to
check for all the items in the set, whether any one of them might be the
identity element.

for elt in set:
    if IsIdentityElement(elt, set):
        print "found the identity element. It is ", elt
        break


Well, maybe that will give you a starting idea?

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




From NHYTRO@compuserve.com  Mon May  7 14:38:21 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Mon, 7 May 2001 09:38:21 -0400
Subject: [Tutor] Python CGI-HTML editor
Message-ID: <200105070938_MC2-D005-A842@compuserve.com>

Hi List!

I have coded an HTML online editor with the help of several Python CGI
scripts. I=B4m now faced woth the problem of image insertion, I know how =
to
upload files per CGI-Python to a server, but I still have 1 complicated
hurdle:

1. Is it possilbe to start a file upload AND send text data from a HTML
form at the same time?

I know this question is not 100% python related, I was=B4nt sure where I
should start looking for information. Does one have a URL for me where HT=
ML
based online text editors are described?


Best regards


Sharriff

P.S thanks to all that have helped me in the last few weeks.  =



From dyoo@hkn.eecs.berkeley.edu  Mon May  7 16:33:16 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 7 May 2001 08:33:16 -0700 (PDT)
Subject: [Tutor] Converting a list to a string
In-Reply-To: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc>
Message-ID: <Pine.LNX.4.21.0105070831190.18093-100000@hkn.eecs.berkeley.edu>

On Mon, 7 May 2001, Praveen Pathiyil wrote:

> If i have a list 
> status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
> is there a single command which will give me a string 
> tftp> Sent 1943 bytes in 0.0 seconds
> 
> OR do i have to do 
> 
> stat_str = ''
> for elt in status:
>     stat_str = stat_str + ' ' + elt

People have suggested using string.join(), which is how I'd approach this
problem.

However, if you already know how many elements are in your status list,
you can also use string interpolation toward the cause.

    stat_str = "%s %s %s %s %s %s %s %s" % tuple(status)

would work, assuming that status is an 8-element list.

Good luck!



From pdiaz88@terra.es  Mon May  7 19:18:08 2001
From: pdiaz88@terra.es (Pedro Diaz Jimenez)
Date: Mon, 7 May 2001 18:18:08 +0000
Subject: [Tutor] Converting a list to a string
In-Reply-To: <200105071115.f47BFfS01582@dsl092-074-184.bos1.dsl.speakeasy.net>
References: <200105071115.f47BFfS01582@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <01050718180800.01701@duero>

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

On Monday 07 May 2001 11:15, Michael P. Reilly wrote:
> Praveen Pathiyil wrote
>
> > Hi all,
> >
> > If i have a list=20
> > status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
> > is there a single command which will give me a string=20
> > tftp> Sent 1943 bytes in 0.0 seconds
> >
> > OR do i have to do=20
> >
> > stat_str =3D ''
> > for elt in status:
> >     stat_str =3D stat_str + ' ' + elt
>
> You don't _have_ to do that; in fact, concatenating strings that way is
> very inefficient (the left hand of the '+' is copied each time through the
> loop).  There is a join function/method for strings to do this for you.
>
> In Python 2.0 and higher, you can use string methods, but on the joiner
> (in this case the space):
>   stat_str = ' '.join(status)
>
> In earlier releases, use the join function in the string module:
>   import string
>   stat_str = string.join(status)
>
> Also, if you use the loop above, you'll have an extra space in the
> front of the resulting string.  You won't get that with the join
> routines.
>
>   -Arcege

Python 1.5.2 (#0, Dec 27 2000, 13:59:38)  [GCC 2.95.2 20000220 (Debian 
GNU/Linux)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> A=['a','b','c','d','e']
>>> reduce( lambda x,y:x+y, A )
'abcde'
>>> reduce( lambda x,y:x+" "+y,A
... )
'a b c d e'
>>>

Just my 0.02

Cheers
Pedro

- -- 

/*
 * Pedro Diaz Jimenez
 * pdiaz88@terra.es 
 * pdiaz@acm.asoc.fi.upm.es
 *
 * Wanna see how 100000! looks like?:
 * http://acm.asoc.fi.upm.es/~pdiaz/fact_100.000
 * 
 * La sabiduria me persigue, pero yo soy mas rapido
 */
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE69ubhnu53feEYxlERAswoAKDYUvpGFAUcBr/bOdpiw+YO2/K6xgCeKYaH
BatcOi4FoBG1LWai9BRh7bs=
=zt1L
-----END PGP SIGNATURE-----


From sheila@thinkspot.net  Mon May  7 17:45:16 2001
From: sheila@thinkspot.net (Sheila King)
Date: Mon, 7 May 2001 09:45:16 -0700
Subject: [Tutor] checking within a table for identity
Message-ID: <jUsT.aNoTheR.mEsSaGe.iD.98925281231741@www.thinkspot.net>

Previously, I suggested using code something like this:

I would probably write a function

IsIdentityElement(elt, set)

Later I thought, you probably need to pass the table/dictionary you 
made, as well, because you will need it to find the value of things 
like
(elt, identity)

You need to look those values up in the table.

So probably you need to start the function off like this:

IsIdentityElement(elt, set, table)

My other remarks are just a hint at how you might do the problem.
I typed it off really quickly this morning, before leaving for work.
It is incomplete.


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











From stevej@parlant.com  Mon May  7 17:47:37 2001
From: stevej@parlant.com (Steve Jibson)
Date: Mon, 07 May 2001 10:47:37 -0600
Subject: [Tutor] Tkinter app and the windows system tray
Message-ID: <3AF6D1A9.F80D4D27@parlant.com>

I have writtne a small tkinter app (for windows) and I want it to run on
system startup and put a little icon in the windows system tray (you
know, like off of those other lame programs with icons on the right side
of the start bar).  Anyway, I'm not sure where to even look for info on
how to interact with the system tray.  Can someone give me some info or
point me to some?

Thanks,

Steve Jibson
steve@jibson.com


From arcege@speakeasy.net  Mon May  7 18:58:48 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Mon, 7 May 2001 13:58:48 -0400 (EDT)
Subject: [Tutor] Converting a list to a string
In-Reply-To: <Pine.LNX.4.21.0105070831190.18093-100000@hkn.eecs.berkeley.edu> from "Daniel Yoo" at May 07, 2001 08:33:16 AM
Message-ID: <200105071758.f47HwmG02006@dsl092-074-184.bos1.dsl.speakeasy.net>

Daniel Yoo wrote
> 
> On Mon, 7 May 2001, Praveen Pathiyil wrote:
> 
> > If i have a list 
> > status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
> > is there a single command which will give me a string 
> > tftp> Sent 1943 bytes in 0.0 seconds
> > 
> > OR do i have to do 
> > 
> > stat_str = ''
> > for elt in status:
> >     stat_str = stat_str + ' ' + elt
> 
> People have suggested using string.join(), which is how I'd approach this
> problem.
> 
> However, if you already know how many elements are in your status list,
> you can also use string interpolation toward the cause.
> 
>     stat_str = "%s %s %s %s %s %s %s %s" % tuple(status)
> 
> would work, assuming that status is an 8-element list.

Likewise, if you don't know how many:
>>> if status:  # there's at least one
...   spam_str = '%s' + ' %s' * (len(status)-1)
...   stat_str = spam_str % tuple(status)
... else:
...   stat_str = ''
...

But I think join is faster than this. ;)

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From julieta_rangel@hotmail.com  Mon May  7 20:29:39 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Mon, 07 May 2001 14:29:39 -0500
Subject: [Tutor] checking within a table for identity
Message-ID: <F201FnwpGR881Np7vXe0000311a@hotmail.com>

As you might recall, I'm trying to figure out a way to check whether a set 
is a group or not (group: closed, associative, identity, inverse).  I have 
the closure and associativity parts.  Now I'm checking for an identity 
element within a set.  The following is what I have so far:

import string
def getCayleyTable(op,set):
    product = {}
    for x in set:
        for y in set:
            prompt = "%s %s %s = ? "%(x,op,y)
            print " "
            z = raw_input(prompt)
            product [x,y] = z
            if z not in set:
                print " "
                print "No need to go any further:  your set is not a group. 
"
                print "Your set is not closed under \" %s \"" %op
                return product
   	        break
   	        print " "

    items = product.items()
    items.sort()

    return product

    print " "

def cross(set1,set2):
    resulting_set = []
    for s1 in set1:
        for s2 in set2:
            resulting_set.append( (s1, s2) )
    return resulting_set

def IsIdentityElement(x, set,d):
    unsuccess=0
    for x in set:
      if d[(x, y)]==x and d[(y,x)]==x:
         return y
      if not d[(x,y)]==x and not d[(y,x)]==x:
         unsuccess=1
         break
      if unsuccess ==1:
     	 print "there is no identity element for your set"
	 break

set = raw_input("Enter the elements of the set separated by a comma,ie, 
a,b,c: ")
set = string.split(set, ",")

print " "
op = raw_input("Enter the binary operator sign, ie, * : ")

d = getCayleyTable( op,set )
print " "
print d
m=cross(set,set)
print m
n=[]
for x in m:
   n.append(d[x])
print n
for x in set:
    c= cross(set,n)
    e= cross(n,set)

print c
print e

l=[]
for x in c:
    l.append(d[x])
print l

k=[]
for x in e:
    k.append(d[x])
print k
if l!=k: print "your set is not a group, associativity fails"
else:  print "closure and associativity hold"


for elt in set:
    if IsIdentityElement(x, set,d):
        print "the identity element is " ,y
        break

I'm doing something wrong, but I can't figure out what it is.  If I run the 
program with a set that has an identity, it runs, but does not display any 
messages.  I want it to tell me what the identity element is, but I don't 
know how to tell the computer to do this.  If I run the program with a set 
in which closure and associativity hold, but there is no identity element, I 
get an error message.  Again, I would like the computer to display a message 
telling me that the set has no identity, therefore it is not a group, but 
again, I don't know how.  Can you help me?  If you know what I'm doing wrong 
and have any suggestions.  By the way, the following is what I get when the 
set has an identity:

Enter the elements of the set separated by a comma,ie, a,b,c: e,a,b,ab

Enter the binary operator sign, ie, * : *

e * e = ? e

e * a = ? a

e * b = ? b

e * ab = ? ab

a * e = ? a

a * a = ? e

a * b = ? ab

a * ab = ? b

b * e = ? b

b * a = ? ab

b * b = ? e

b * ab = ? a

ab * e = ? ab

ab * a = ? b

ab * b = ? a

ab * ab = ? e

{('a', 'e'): 'a', ('ab', 'e'): 'ab', ('a', 'a'): 'e', ('a', 'ab'): 'b', 
('b', 'ab'): 'a', ('a', 'b'): 'ab', ('ab', 'ab'): 'e', ('ab', 'a'): 'b', 
('b', 'e'): 'b', ('e', 'a'): 'a', ('e', 'b'): 'b', ('e', 'ab'): 'ab', ('b', 
'a'): 'ab', ('e', 'e'): 'e', ('ab', 'b'): 'a', ('b', 'b'): 'e'}

[('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), ('a', 'e'), ('a', 'a'), 
('a', 'b'), ('a', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), 
('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab')]

['e', 'a', 'b', 'ab', 'a', 'e', 'ab', 'b', 'b', 'ab', 'e', 'a', 'ab', 'b', 
'a', 'e']

[('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), ('e', 'a'), ('e', 'e'), 
('e', 'ab'), ('e', 'b'), ('e', 'b'), ('e', 'ab'), ('e', 'e'), ('e', 'a'), 
('e', 'ab'), ('e', 'b'), ('e', 'a'), ('e', 'e'), ('a', 'e'), ('a', 'a'), 
('a', 'b'), ('a', 'ab'), ('a', 'a'), ('a', 'e'), ('a', 'ab'), ('a', 'b'), 
('a', 'b'), ('a', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'ab'), ('a', 'b'), 
('a', 'a'), ('a', 'e'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), 
('b', 'a'), ('b', 'e'), ('b', 'ab'), ('b', 'b'), ('b', 'b'), ('b', 'ab'), 
('b', 'e'), ('b', 'a'), ('b', 'ab'), ('b', 'b'), ('b', 'a'), ('b', 'e'), 
('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('ab', 'a'), ('ab', 
'e'), ('ab', 'ab'), ('ab', 'b'), ('ab', 'b'), ('ab', 'ab'), ('ab', 'e'), 
('ab', 'a'), ('ab', 'ab'), ('ab', 'b'), ('ab', 'a'), ('ab', 'e')]

[('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), ('a', 'e'), ('a', 'a'), 
('a', 'b'), ('a', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), 
('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('a', 'e'), ('a', 'a'), 
('a', 'b'), ('a', 'ab'), ('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), 
('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('b', 'e'), ('b', 'a'), 
('b', 'b'), ('b', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), 
('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('e', 'e'), ('e', 'a'), 
('e', 'b'), ('e', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'b'), ('a', 'ab'), 
('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('b', 'e'), ('b', 'a'), 
('b', 'b'), ('b', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'b'), ('a', 'ab'), 
('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab')]

['e', 'a', 'b', 'ab', 'a', 'e', 'ab', 'b', 'b', 'ab', 'e', 'a', 'ab', 'b', 
'a', 'e', 'a', 'e', 'ab', 'b', 'e', 'a', 'b', 'ab', 'ab', 'b', 'a', 'e', 
'b', 'ab', 'e', 'a', 'b', 'ab', 'e', 'a', 'ab', 'b', 'a', 'e', 'e', 'a', 
'b', 'ab', 'a', 'e', 'ab', 'b', 'ab', 'b', 'a', 'e', 'b', 'ab', 'e', 'a', 
'a', 'e', 'ab', 'b', 'e', 'a', 'b', 'ab']

['e', 'a', 'b', 'ab', 'a', 'e', 'ab', 'b', 'b', 'ab', 'e', 'a', 'ab', 'b', 
'a', 'e', 'a', 'e', 'ab', 'b', 'e', 'a', 'b', 'ab', 'ab', 'b', 'a', 'e', 
'b', 'ab', 'e', 'a', 'b', 'ab', 'e', 'a', 'ab', 'b', 'a', 'e', 'e', 'a', 
'b', 'ab', 'a', 'e', 'ab', 'b', 'ab', 'b', 'a', 'e', 'b', 'ab', 'e', 'a', 
'a', 'e', 'ab', 'b', 'e', 'a', 'b', 'ab']

closure and associativity hold
<module 'seta' from 'C:\Program Files\Python\seta.pyc'>

And the following is what I get if the set has no identity:

Enter the elements of the set separated by a comma,ie, a,b,c: 0,2,4

Enter the binary operator sign, ie, * : *

0 * 0 = ? 0

0 * 2 = ? 0

0 * 4 = ? 0

2 * 0 = ? 0

2 * 2 = ? 4

2 * 4 = ? 0

4 * 0 = ? 0

4 * 2 = ? 0

4 * 4 = ? 0

{('4', '2'): '0', ('0', '4'): '0', ('0', '2'): '0', ('0', '0'): '0', ('2', 
'4'): '0', ('4', '4'): '0', ('4', '0'): '0', ('2', '0'): '0', ('2', '2'): 
'4'}

[('0', '0'), ('0', '2'), ('0', '4'), ('2', '0'), ('2', '2'), ('2', '4'), 
('4', '0'), ('4', '2'), ('4', '4')]

['0', '0', '0', '0', '4', '0', '0', '0', '0']

[('0', '0'), ('0', '0'), ('0', '0'), ('0', '0'), ('0', '4'), ('0', '0'), 
('0', '0'), ('0', '0'), ('0', '0'), ('2', '0'), ('2', '0'), ('2', '0'), 
('2', '0'), ('2', '4'), ('2', '0'), ('2', '0'), ('2', '0'), ('2', '0'), 
('4', '0'), ('4', '0'), ('4', '0'), ('4', '0'), ('4', '4'), ('4', '0'), 
('4', '0'), ('4', '0'), ('4', '0')]

[('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4'), 
('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4'), 
('4', '0'), ('4', '2'), ('4', '4'), ('0', '0'), ('0', '2'), ('0', '4'), 
('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4'), 
('0', '0'), ('0', '2'), ('0', '4')]

['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']

['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']

Traceback (innermost last):
  File "<pyshell#68>", line 1, in ?
    reload(seta)
  File "C:\Program Files\Python\seta.py", line 76, in ?
    if IsIdentityElement(elt, set,d):
  File "C:\Program Files\Python\seta.py", line 35, in IsIdentityElement
    if d[(x, y)]==x and d[(y,x)]==x:
KeyError: ('0', 'b')


The lists I have displayed every time I run the program are just for me to 
figure out what is going on.  I'll get rid of them when the program is 
complete.




>From: Sheila King <sheila@thinkspot.net>
>Reply-To: sheila@thinkspot.net
>To: tutor@python.org
>CC: julieta_rangel@hotmail.com
>Subject: Re: [Tutor] checking within a table for identity
>Date: Mon, 7 May 2001 09:45:16 -0700
>
>Previously, I suggested using code something like this:
>
>I would probably write a function
>
>IsIdentityElement(elt, set)
>
>Later I thought, you probably need to pass the table/dictionary you
>made, as well, because you will need it to find the value of things
>like
>(elt, identity)
>
>You need to look those values up in the table.
>
>So probably you need to start the function off like this:
>
>IsIdentityElement(elt, set, table)
>
>My other remarks are just a hint at how you might do the problem.
>I typed it off really quickly this morning, before leaving for work.
>It is incomplete.
>
>
>--
>Sheila King
>http://www.thinkspot.net/sheila/
>http://www.k12groups.org/
>
>
>
>
>
>
>
>
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From glingl@aon.at  Mon May  7 22:34:44 2001
From: glingl@aon.at (Gregor Lingl)
Date: Mon, 07 May 2001 23:34:44 +0200
Subject: [Tutor] Converting a list to a string
References: <Pine.LNX.4.21.0105070831190.18093-100000@hkn.eecs.berkeley.edu>
Message-ID: <3AF714F4.C421E2A4@aon.at>


Daniel Yoo schrieb:

> On Mon, 7 May 2001, Praveen Pathiyil wrote:
>
> > If i have a list
> > status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
> > is there a single command which will give me a string
> > tftp> Sent 1943 bytes in 0.0 seconds
> >
> > OR do i have to do
> >
> > stat_str = ''
> > for elt in status:
> >     stat_str = stat_str + ' ' + elt
>
> People have suggested using string.join(), which is how I'd approach this
> problem.
>
> However, if you already know how many elements are in your status list,
> you can also use string interpolation toward the cause.
>
>     stat_str = "%s %s %s %s %s %s %s %s" % tuple(status)
>
> would work, assuming that status is an 8-element list.

... or if you don't know the lenght of the list, you may use:

      stat_str = len(status) * "%s " % tuple(status)

which however is definitly neither nicer nor more compact than

      stat_str = " ".join(status)

which is possible since (Python 1.6)

Gregor L.



From jenca@email.com  Tue May  8 02:06:31 2001
From: jenca@email.com (Jenkins)
Date: Mon, 7 May 2001 18:06:31 -0700
Subject: [Tutor] What i should do?
Message-ID: <000801c0d75b$20534de0$0100000a@server>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C0D720.72B713E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

After I write the code for my program how can I make it to work, how can =
I create the program

------=_NextPart_000_0005_01C0D720.72B713E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>After I write the code for my program =
how can I=20
make it to work, how can I create the program</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C0D720.72B713E0--




From bdupire@seatech.fau.edu  Mon May  7 23:15:25 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Mon, 07 May 2001 18:15:25 -0400
Subject: [Tutor] What i should do?
References: <000801c0d75b$20534de0$0100000a@server>
Message-ID: <3AF71E7D.2C624A6D@seatech.fau.edu>

You need to create a new file in your editor, to put the code in it and
save it as a file with a .py extension, like "my_program.py"
You've just created a new python module.

If you're running Windows,  click on the Python icon, to start the
Python interpreter and you can then import your module, just typing:

import my_program


You can learn about this at:
http://www.python.org/doc/current/tut/node8.html

The Python tutorial is at:
http://www.python.org/doc/current/tut/tut.html

Benoit

Jenkins wrote:

> After I write the code for my program how can I make it to work, how
> can I create the program

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From julieta_rangel@hotmail.com  Mon May  7 23:18:05 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Mon, 07 May 2001 17:18:05 -0500
Subject: [Tutor] checking if all items in a list are the same
Message-ID: <F34eAzdfTVSxzW234xO000034d6@hotmail.com>

If I have a list, how can I compare all of the elements to check if they are 
the same?  Say that I have the following list:

[e,e,e,e,e]

How can I tell the computer to go item by item in the list and compare them. 
  If they are the same, I want the computer to tell me that it has found the 
identity element, and if they are not the same, I want the computer to tell 
me that there is no identity element. Can anyone help?

Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From shaleh@valinux.com  Mon May  7 23:30:50 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Mon, 07 May 2001 15:30:50 -0700 (PDT)
Subject: [Tutor] checking if all items in a list are the same
In-Reply-To: <F34eAzdfTVSxzW234xO000034d6@hotmail.com>
Message-ID: <XFMail.20010507153050.shaleh@valinux.com>

On 07-May-2001 Julieta Rangel wrote:
> If I have a list, how can I compare all of the elements to check if they are 
> the same?  Say that I have the following list:
> 
> [e,e,e,e,e]
> 
> How can I tell the computer to go item by item in the list and compare them. 
>   If they are the same, I want the computer to tell me that it has found the 
> identity element, and if they are not the same, I want the computer to tell 
> me that there is no identity element. Can anyone help?
> 

Often times it helps to consider the problem as a person would the very
first time.

"How do I tell if a bunch of things are the same?"  Hmm, I would take an item
and then look at another item and decide if they are the same.  Then while
still holding that first item in mind, I would look at all of the items.  Along
the way I might notice that some items are like others but not the first item I
chose.

Sure, this may not be the best way, but it is always more important to get
something working, then make it work at maxmimum efficiency.


From deirdre@deirdre.net  Mon May  7 23:27:28 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Mon, 7 May 2001 15:27:28 -0700
Subject: [Tutor] checking if all items in a list are the same
In-Reply-To: <F34eAzdfTVSxzW234xO000034d6@hotmail.com>
References: <F34eAzdfTVSxzW234xO000034d6@hotmail.com>
Message-ID: <a05100300b71cd0c78f24@[10.0.1.2]>

>If I have a list, how can I compare all of the elements to check if 
>they are the same?  Say that I have the following list:
>
>[e,e,e,e,e]
>
>How can I tell the computer to go item by item in the list and 
>compare them.  If they are the same, I want the computer to tell me 
>that it has found the identity element, and if they are not the 
>same, I want the computer to tell me that there is no identity 
>element. Can anyone help?


If you return a -1 from a function when there's no match, or a zero 
when there's a match.

This assumes ALL items in the list are identical to the match item:


def listMatch(aList, itemToMatch)

	for i in aList:
		if i != itemToMatch:
			return -1
	return 0


-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From babyboy@oninet.pt  Tue May  8 00:08:23 2001
From: babyboy@oninet.pt (wilson edgar)
Date: Tue, 8 May 2001 00:08:23 +0100
Subject: [Tutor] What i should do?
References: <000801c0d75b$20534de0$0100000a@server>
Message-ID: <001a01c0d74a$9e4d6d40$1a083ad5@a7u4r2>

Esta é uma mensagem com várias partes em formato MIME.

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

well, if you have the system varibles set correctly, you just have to go =
to you prompt and type:

ex:
c:\>python nameOfTheProgram.py

This means that after writting the code you have to save in a .py and =
the execute it.
here you have some very good starting points
=20
http://www.python.org/doc/current/tut/tut.html

http://www.crosswinds.net/~agauld/

hth
wilson edgar

  After I write the code for my program how can I make it to work, how =
can I create the program

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>well, if you have the system varibles =
set=20
correctly, you just have to go to you prompt and type:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>ex:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>c:\&gt;python =
nameOfTheProgram.py</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This means that after writting the code =
you have to=20
save in a .py and the execute it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>here you have some very good starting=20
points</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><A=20
href=3D"http://www.python.org/doc/current/tut/tut.html">http://www.python=
.org/doc/current/tut/tut.html</A></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><A=20
href=3D"http://www.crosswinds.net/~agauld/">http://www.crosswinds.net/~ag=
auld/</A></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>hth</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>wilson edgar</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>After I write the code for my program =
how can I=20
  make it to work, how can I create the=20
program</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0017_01C0D752.FF519280--



From kstoner@netins.net  Tue May  8 00:12:50 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Mon, 7 May 2001 18:12:50 -0500
Subject: [Tutor] meaning
Message-ID: <000e01c0d74b$3d261980$7752b1cf@oemcomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_000B_01C0D721.53C0A2C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

Would someone be so kind as to explain what this bit of code means line =
by line.
Mostly I would like to know what the first four lines mean.
Thanks,
-Cameron

#!/usr/local/bin/python
def spam(n, l =3D[] ) :
    l.append(n)
    return l

x =3D spam(42)
print x
y =3D spam(39)
print y
z =3D spam(9999, y)
print x, y, z

------=_NextPart_000_000B_01C0D721.53C0A2C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Would someone be so kind as to explain =
what this=20
bit of code means line by line.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Mostly I would like to know what the =
first four=20
lines mean.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>-Cameron</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#!/usr/local/bin/python</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>def spam(n, l =3D[] ) :</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
l.append(n)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; return =
l</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>x =3D spam(42)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>print x</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>y =3D spam(39)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>print y</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>z =3D spam(9999, y)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>print x, y, =
z</FONT></DIV></BODY></HTML>

------=_NextPart_000_000B_01C0D721.53C0A2C0--



From scarblac@pino.selwerd.nl  Tue May  8 00:22:44 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 8 May 2001 01:22:44 +0200
Subject: [Tutor] meaning
In-Reply-To: <000e01c0d74b$3d261980$7752b1cf@oemcomputer>; from kstoner@netins.net on Mon, May 07, 2001 at 06:12:50PM -0500
References: <000e01c0d74b$3d261980$7752b1cf@oemcomputer>
Message-ID: <20010508012244.A20127@pino.selwerd.nl>

On  0, Katharine Stoner <kstoner@netins.net> wrote:
> Hi all,
> 
> Would someone be so kind as to explain what this bit of code means line by line.
> Mostly I would like to know what the first four lines mean.
> Thanks,
> -Cameron
> 
> #!/usr/local/bin/python

This line tells the system that it's a Python file (on Unix/Linux).

> def spam(n, l =[] ) :
>     l.append(n)
>     return l

This creates a function called spam. It takes two arguments, n and l.

The second is optional. If it isn't given, l is set to a list that is
initially []. It will be the same list object every time the function is
called.

Then, n is appended to the list l, and l is returned as the result of the
function.

> x = spam(42)

Spam is called with n=42 and no l. So l is the list [], 42 is appended, so
[42] is returned, and x now refers to the list.

> print x

So this prints [42].

> y = spam(39)

Same story, n=39, l was [42] (remember, it's the same list all the time!)
and becomes [42, 39].

> print y

Prints [42, 39].

> z = spam(9999, y)

Now n=9999, and l=y. Since y was the result of the previous call, and it's
still that same list as always, l=[42, 39] and becomes [42, 39, 9999].

> print x, y, z

They're all the same list, the one that was made when the def: statement was
run. So this prints
[42, 39, 9999] [42, 39, 9999] [42, 39, 9999]

-- 
Remco Gerlich


From bdupire@seatech.fau.edu  Tue May  8 00:29:09 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Mon, 07 May 2001 19:29:09 -0400
Subject: [Tutor] meaning
References: <000e01c0d74b$3d261980$7752b1cf@oemcomputer>
Message-ID: <3AF72FC4.EA59E85F@seatech.fau.edu>

This piece of code illustrates the fact that default arguments in  a
function are only evaluated once.
I ve just seen Remco answered your question... so read his message !
:o)

Benoit


Katharine Stoner wrote:

> Hi all, Would someone be so kind as to explain what this bit of code
> means line by line.Mostly I would like to know what the first four
> lines mean.Thanks,-Cameron #!/usr/local/bin/pythondef spam(n, l =[] )
> :    l.append(n)    return l x = spam(42)print xy = spam(39)print yz =
> spam(9999, y)print x, y, z

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From bsass@freenet.edmonton.ab.ca  Tue May  8 00:58:06 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Mon, 7 May 2001 17:58:06 -0600 (MDT)
Subject: [Tutor] meaning
In-Reply-To: <000e01c0d74b$3d261980$7752b1cf@oemcomputer>
Message-ID: <Pine.LNX.4.33.0105071738010.7453-100000@bms>

On Mon, 7 May 2001, Cameron wrote:

> Hi all,
>
> Would someone be so kind as to explain what this bit of code means line by line.
> Mostly I would like to know what the first four lines mean.
> Thanks,
> -Cameron
>
> #!/usr/local/bin/python

Tells the shell to hand the file off to the python interpreter at
/usr/local/bin/python, probably a hardlink to python1.5|2.0|2.1

> def spam(n, l =[] ) :

Defines a function named "spam" with two parameters, one is required
the other defaults to being an empty list the first time the function
is used.  This is what you usually want...

	def spam(n, l = None):
	    if l == None:
	        l = []

This way you create a new list object each time you don't pass a
second argument, instead of creating one only when the function gets
compiled.

>     l.append(n)

appends n to l; n can be anything, l can be anything with an
"append" method

>     return l

returns the object "l" as the result

> x = spam(42)
> print x
> y = spam(39)
> print y
> z = spam(9999, y)
> print x, y, z

print id(x), id(y), id(z)


- Bruce



From dyoo@hkn.eecs.berkeley.edu  Tue May  8 01:53:41 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 7 May 2001 17:53:41 -0700 (PDT)
Subject: [Tutor] Tkinter app and the windows system tray
In-Reply-To: <3AF6D1A9.F80D4D27@parlant.com>
Message-ID: <Pine.LNX.4.21.0105071749510.31420-100000@hkn.eecs.berkeley.edu>

On Mon, 7 May 2001, Steve Jibson wrote:

> 
> I have writtne a small tkinter app (for windows) and I want it to run on
> system startup and put a little icon in the windows system tray (you
> know, like off of those other lame programs with icons on the right side
> of the start bar).  Anyway, I'm not sure where to even look for info on

You might find the following program useful for putting stuff in your
system tray:

    http://www.davecentral.com/13293.html

It's called Watchcat, and it lets you put any programs on the system tray.  

You might also want to ask people on comp.lang.python: people there might
have experience with doing Windowish stuff there.


> how to interact with the system tray.  Can someone give me some info or
> point me to some?

It sounds like you might also be interested in py2exe, which will help
package your Tkinter program so that you'll be able to share it with your
friends:

    http://py2exe.sourceforge.net


Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Tue May  8 02:39:24 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 7 May 2001 18:39:24 -0700 (PDT)
Subject: [Tutor] Most efficient representation of a tree?  [a list
 representation]
In-Reply-To: <3AF3451D.BCBAF3F3@verio.net>
Message-ID: <Pine.LNX.4.21.0105071814120.31420-100000@hkn.eecs.berkeley.edu>

On Fri, 4 May 2001, VanL wrote:

> What would be the most efficient representation of a tree? 
> In this tree, each node could have an arbitrary number of children.
> I also wanted to be able to order the children so I can traverse the
> trees in different ways (preorder, postorder, etc).  Anyway, at least a
> leftmost-child, right-sibling ordering.
> 
> I was considering two options:
> 
> 1. A modification of Guido's adjacency-list implementation of a graph
> (see http://www.python.org/doc/essays/graphs.html).  After all, this
> sort of tree is just special case sparse graph.
> 
> 2. A node class with a parent link and a list of links to each child --
> essentially a generalization of the linked list class that I posted here
> a month ago.
> 
> Any other options?

Apologies for the late reply!  


I'm choosing option two: it's fairly easy to work with.  I can put up
sample code that implements this as soon as I get home.


There's another way to do this, of course.  There's a representation of
binary trees that uses flat lists, and this is one is especially cute:

###
def left(index):
    return 2 * index + 1

def right(index):
    return 2 * index + 2

def parent(index):
    return index / 2

def inorder(tree, index):
    """Here's a sample algorithm that uses this tree
       representation.  Inorder traversal."""
    if index >= len(tree):
        return
    inorder(tree, left(index))
    print tree[index]
    inorder(tree, right(index))

def preorder(tree, index):
    if index >= len(tree): return
    print tree[index]
    preorder(tree, left(index))
    preorder(tree, right(index))

if __name__ == '__main__':
    mytree = [1, 2, 3, 4, 5, 6, 7, 8]
    print "Here's an inorder traversal of our mytree."
    inorder(mytree, 0)   ## Start an inorder traversal at the root at 0.
    print
    print "Here's a preorder traversal:"
    preorder(mytree, 0)
###

The idea is to store our data in a list, and to jump around in our tree by
index number.  Getting at our left or right child is simple: we just do a
little arithmetic on our current position.
  
What's particularly interesting is that this representation allows us to
grab the parent of the node really easily.  All of this is done without
explicitily storing left/right references: it's all done with indices, so
it also saves some space, if you're into space efficiency.

Binary trees can represent general trees, so this should be enough to make
a good general tree.


Hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Tue May  8 02:42:44 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 7 May 2001 18:42:44 -0700 (PDT)
Subject: [Tutor] Possible Useless Python Challenge.
In-Reply-To: <3AF4DE75.770921E8@irtc.net>
Message-ID: <Pine.LNX.4.21.0105071839360.31420-100000@hkn.eecs.berkeley.edu>

On Sun, 6 May 2001, Tesla Coil wrote:

> KiSS data sets are bundled using LZH compression,
> if there's a module for that, I haven't located it.  

I haven't found an LZH decompressor for Python.  In fact, the GnomeKISS
people are depending on a separate LHA extraction program, so perhaps a
Python KISS program should delegate the handling of LZH compression to the
LHA utility.


> I suppose that a cel file decoder could be cooked up using Python
> Imaging Library, but I've no experience in that department at all.  
> Other than that, I guess one is up against reading .cnf files
> generated by a variety of editors and sometimes written by hand.

Hmmm... this actually sounds like a lot of fun!  I'll start looking at
this... *grin*



From deirdre@deirdre.net  Tue May  8 02:50:48 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Mon, 7 May 2001 18:50:48 -0700
Subject: [Tutor] Possible Useless Python Challenge.
In-Reply-To: <Pine.LNX.4.21.0105071839360.31420-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105071839360.31420-100000@hkn.eecs.berkeley.edu>
Message-ID: <a05100e07b71d0058d63f@[10.0.1.7]>

>On Sun, 6 May 2001, Tesla Coil wrote:
>
>>  KiSS data sets are bundled using LZH compression,
>>  if there's a module for that, I haven't located it. 
>
>I haven't found an LZH decompressor for Python.  In fact, the GnomeKISS
>people are depending on a separate LHA extraction program, so perhaps a
>Python KISS program should delegate the handling of LZH compression to the
>LHA utility.


I've written both Lempel-Ziv and Huffman compressors and 
decompressors, but not LZH per se and not in Python. Given that 
Python has all the requisite bitwise operators, it would be possible, 
but it'd probably be better to write a wrapper for an existing set of 
C functions.

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From rob@jam.rr.com  Tue May  8 04:38:00 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Mon, 07 May 2001 22:38:00 -0500
Subject: [Tutor] Possible Useless Python Challenge.
References: <Pine.LNX.4.21.0105071839360.31420-100000@hkn.eecs.berkeley.edu> <a05100e07b71d0058d63f@[10.0.1.7]>
Message-ID: <3AF76A18.DD866F80@jam.rr.com>

Sometimes I barely understand a word of what's currently being discussed
and still think it sounds nifty. This is such a time.

hehe,
Rob

Deirdre Saoirse Moen wrote:
> 
> >On Sun, 6 May 2001, Tesla Coil wrote:
> >
> >>  KiSS data sets are bundled using LZH compression,
> >>  if there's a module for that, I haven't located it.
> >
> >I haven't found an LZH decompressor for Python.  In fact, the GnomeKISS
> >people are depending on a separate LHA extraction program, so perhaps a
> >Python KISS program should delegate the handling of LZH compression to the
> >LHA utility.
> 
> I've written both Lempel-Ziv and Huffman compressors and
> decompressors, but not LZH per se and not in Python. Given that
> Python has all the requisite bitwise operators, it would be possible,
> but it'd probably be better to write a wrapper for an existing set of
> C functions.
> 
> --
> _Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
> "I love deadlines. I like the whooshing sound they make as they fly by."
>                                                           - Douglas Adams
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From julieta_rangel@hotmail.com  Tue May  8 05:11:46 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Mon, 07 May 2001 23:11:46 -0500
Subject: [Tutor] obtaining an item from a list
Message-ID: <F263SOlbpH71yEXUIEA00000290@hotmail.com>

If I have a list, say l=[e,e,e,e], how can I give the first item in my list 
a name and print it?

Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From bdupire@seatech.fau.edu  Tue May  8 05:21:50 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Tue, 08 May 2001 00:21:50 -0400
Subject: [Tutor] obtaining an item from a list
References: <F263SOlbpH71yEXUIEA00000290@hotmail.com>
Message-ID: <3AF7745D.DD730F18@seatech.fau.edu>

Is your list  [e, e, e, e] or  ['e','e','e','e'] ?
A list can't be [e, e, e, e]. If you initialize it in this way, then - e -  is
replaced by its value...

If you list is really [e, e, e, e] , let's say [10, 10, 10, 10], you can use
either str(list[0]) or repr(list[0]).

If i consider the second possibility, then you can use the string as a name -->
list[0] is a string, right ?

Hope this helps,
Benoit


Julieta Rangel wrote:

> If I have a list, say l=[e,e,e,e], how can I give the first item in my list
> a name and print it?
>
> Julieta
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From deirdre@deirdre.net  Tue May  8 06:00:17 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Mon, 7 May 2001 22:00:17 -0700
Subject: [Tutor] Possible Useless Python Challenge.
In-Reply-To: <3AF76A18.DD866F80@jam.rr.com>
References: <Pine.LNX.4.21.0105071839360.31420-100000@hkn.eecs.berkeley.edu>
 <a05100e07b71d0058d63f@[10.0.1.7]> <3AF76A18.DD866F80@jam.rr.com>
Message-ID: <a05100e09b71d288f2f43@[10.0.1.7]>

At 10:38 PM -0500 5/7/01, Rob Andrews wrote:
>Sometimes I barely understand a word of what's currently being discussed
>and still think it sounds nifty. This is such a time.

Well, to grossly simplify the two types of compression:

Huffman uses a variable number of bits to represent characters -- 
more common letters are represented by fewer bits; less common by 
more bits, on the theory that, on average, you'll save lots of bits. 
In its simplest form (but not a very common implementation these 
days), it uses three bits to store tree depth and the remaining bits 
to store tree location, i.e., for characters "etaion" appearing in 
descending of frequency:

000				e
                               /   \
001                         t       a
                           /   \    /
010                      i     o   n

So, e = 000, t = 0011, a = 0010, i = 01011, o = 01010, n = 01001

In this form, you have to store the dictionary (i.e. the tree 
diagram) as a part of the compressed document, so the doc has to be 
fairly long (a few K) for the compression to be effective.

Other forms use two trees and/or a known dictionary.

Lempel-Ziv is compression based on pairs of characters that appear 
together commonly.

http://www.faqs.org/faqs/compression-faq/part2/section-1.html


>  > I've written both Lempel-Ziv and Huffman compressors and
>  > decompressors, but not LZH per se and not in Python. Given that
>>  Python has all the requisite bitwise operators, it would be possible,
>>  but it'd probably be better to write a wrapper for an existing set of
>  > C functions.

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From dyoo@hkn.eecs.berkeley.edu  Tue May  8 06:05:26 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 7 May 2001 22:05:26 -0700 (PDT)
Subject: [Tutor] Possible Useless Python Challenge.  [huffman encoding]
In-Reply-To: <3AF76A18.DD866F80@jam.rr.com>
Message-ID: <Pine.LNX.4.21.0105072049130.5754-200000@hkn.eecs.berkeley.edu>

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--545289610-654942913-989298326=:5754
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Mon, 7 May 2001, Rob Andrews wrote:

> Sometimes I barely understand a word of what's currently being discussed
> and still think it sounds nifty. This is such a time.
>
> Deirdre Saoirse Moen wrote:
> > 
> > >On Sun, 6 May 2001, Tesla Coil wrote:
> > >
> > >>  KiSS data sets are bundled using LZH compression,
> > >>  if there's a module for that, I haven't located it.
> > >
> > >I haven't found an LZH decompressor for Python.  In fact, the GnomeKISS
> > >people are depending on a separate LHA extraction program, so perhaps a
> > >Python KISS program should delegate the handling of LZH compression to the
> > >LHA utility.
> > 
> > I've written both Lempel-Ziv and Huffman compressors and
> > decompressors, but not LZH per se and not in Python. Given that
> > Python has all the requisite bitwise operators, it would be possible,
> > but it'd probably be better to write a wrapper for an existing set of
> > C functions.


*laugh* I have a little bit of code that almost implements Huffman
encoding.  (VanL, this uses some of the tree code I mentioned earlier.)  
I was writing this during the afternoon.  Coincidence, huh?

I'll try to give the flavor of what Huffman encoding is.  We need to give
a little background though.  [note, this is LONG.]

When we represent letters --- one character strings --- Python (and mostly
every other computer language) internally uses a numeric code called
ASCII: American Standard Code for Information Interchange, to encode each
character.

Our computers are bit crunchers, so this means that every character we
store needs to be saved as a number.  For example, we could look at the
string:

    "hello world"

as a list of ASCII numbers:

###
>>> map(ord, 'hello world')
[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] 
###

but this is still one step removed from how computers REALLY represent
characters; they represent them, not just in numeric form, but in crude,
binary, base-two!  Ones and zeros, and that's really weird when we first
see it.  Here's a small program that will try to reveal what's underneath:

###
>>> def binaryStringHelper(n):
...     if n == 0: return ''
...     else: return binaryStringHelper(n >> 1) + str(n % 2)
...
>>> def toBinaryString(n):
...     if n == 0: return string.zfill(0, 8)
...     return string.zfill(int(binaryStringHelper(n)), 8)
...
>>> pprint.pprint(map(toBinaryString, range(10)))
['00000000',          ## ...stands for 0
 '00000001',          ## ...stands for 1
 '00000010',          ##               2
 '00000011',          ##               3
 '00000100',          ##             ...
 '00000101',
 '00000110',
 '00000111',
 '00001000',          ##               8
 '00001001']          ##               9
###

This is doing some hacky bit manipulation which isn't really important:
the important thing is that this program above allows us to visualize all
those one's and zero's that the computer actually uses to represent a
character.  We can apply this on our string:


###
>>> pprint.pprint(map(toBinaryString, map(ord, 'hello world')))
['01101000',
 '01100101',
 '01101100',
 '01101100',
 '01101111',
 '00100000',
 '01110111',
 '01101111',
 '01110010',
 '01101100',
 '01100100']
###

and this is how computers today truly store 'hello world' in its memory,
as streams of ones and zeros.  Every character is eight bits, so any
string of length 'n' will take up '8*n' bits.  Our small sentence, 'hello
world', takes up 88 bits!


Ok, this doesn't sound as world-threatening as we're making it out to be,
but what is neat about Huffman encoding is that we can usually do much
better than 88 bits.

What Huffman realized is that we're not taking advantage of a certain
curious property about human language: we use certain words over and over,
certain letters over and over, and our language is fraught with
repetitious repetition. What if we don't always represent a character by 8
bits, but by something that depends on how frequently the letter occurs in
our language?  Instead of having every letter be represented by eight
bits, we can make a "variable length" encoding.  That is, perhaps we can
use the following code:

    'h' ===> 0000
    'w' ===> 0001
    'd' ===> 0010
    'e' ===> 0011
    'o' ===> 01
    'r' ===> 100
    ' ' ===> 101
    'l' ===> 11

That is, instead of using all eight bits on every letter, we can use a
shorter binary sequence for really frequent characters, and longer codes
for letters that we don't use as often.  For letters that don't occur at
all, we don't even need to give them a code.  Huffman's encoding gives us
a way of figuring out really good codes that do this for us.  What this
means is, that, instead of representing 'hello world' as:

###
>>> string.join(map(toBinaryString, map(ord, 'hello world')), '')
'0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100'
###


we can do it like this:

###
>>> code = {'h' : '0000', 'w' : '0001', 'd' : '0010', 'e' : '0011',
            'o' : '01',   'r' : '101',  ' ' : '101',  'l' : '11'}
>>> string.join(map(lambda c: code[c], 'hello world'), '')
'00000011111101101000101101110010'
####

which is a heck of a lot shorter than what we had previously.  This is the
heart of Huffman encoding: to find a binary representation for each number
so that a message doesn't take so much space to store.

Of course this is handwavy, because whoever wants to read our message
needs to have a copy of the dictionary!  They need to be able to convert
our binary message back into something readable, so we usually send off
the dictionary alongside the encoded text.  When a message gets large
enough, though, that overhead becomes negigible compared to the amount of
space we save.

Finally, the code itself needs to guarantee that, given a bit string,
there's only one way to rehydrate it back to it's nice spongy, wordy form.  
Not coinciently, Huffman encoding guarantees this for us.  Really smart
guy, and really neat algorithm.

Does this make sense?  I get the feeling I talked too much on this one
already.  *grin*


The incomplete code to do Huffman encoding should be attached to this
message.  As soon as I get it in a nicer form, I'll send it off to Useless
Python.

--545289610-654942913-989298326=:5754
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="huffman.py"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.21.0105072205260.5754@hkn.eecs.berkeley.edu>
Content-Description: 
Content-Disposition: attachment; filename="huffman.py"

IyEvdXNyL2Jpbi9lbnYgcHl0aG9uDQoNCiIiIlRyZWVzLCBCaW5hcnkgVHJl
ZXMsIGFuZCBIdWZmbWFuIEVuY29kaW5nDQoNCkRhbm55IFlvbyAoZHlvb0Bo
a24uZWVjcy5iZXJrZWxleS5lZHUpDQoNClRoZXNlIGNsYXNzZXMgZXhwbG9y
ZSB0cmVlIHN0cnVjdHVyZXMgdXNlZCB0byBjcmVhdGUgSHVmZm1hbiB0cmVl
cywgYQ0Kc3RhcGxlIG9mIGluZm9ybWF0aW9uIHRoZW9yeSBhbmQgY29tcHJl
c3Npb24uICBQZXJoYXBzIEkgY2FuIHVzZSB0aGVzZQ0KY2xhc3NlcyBsYXRl
ciB0byBwbGF5IGFyb3VuZCB3aXRoIHN1ZmZpeCB0cmVlcy4iIiINCg0KDQpj
bGFzcyBUcmVlOg0KICAgICIiIkhlcmUncyBvbmUgd2F5IHRvIHJlcHJlc2Vu
dCBnZW5lcmFsaXplZCB0cmVlcy4gIEEgdHJlZSBpcyBhDQogICAgc3RydWN0
dXJlIHRoYXQgaGFzIGEgZGF0dW0sIGFuZCBhbnkgbnVtYmVyIG9mIGNoaWxk
cmVuLiIiIg0KICAgIGRlZiBfX2luaXRfXyhzZWxmLCBkYXR1bSwgY2hpbGRy
ZW4gPSBOb25lKToNCiAgICAgICAgc2VsZi5fZGF0dW0gPSBkYXR1bQ0KICAg
ICAgICBpZiBjaGlsZHJlbjoNCiAgICAgICAgICAgIHNlbGYuX2NoaWxkcmVu
ID0gY2hpbGRyZW4NCiAgICAgICAgZWxzZToNCiAgICAgICAgICAgIHNlbGYu
X2NoaWxkcmVuID0gW10NCg0KICAgIGRlZiBnZXREYXR1bShzZWxmKTogcmV0
dXJuIHNlbGYuX2RhdHVtDQoNCiAgICBkZWYgZ2V0Q2hpbGRyZW4oc2VsZik6
IHJldHVybiBzZWxmLl9jaGlsZHJlbg0KDQogICAgZGVmIGlzTGVhZihzZWxm
KTogcmV0dXJuIGxlbihzZWxmLl9jaGlsZHJlbikgPT0gMA0KDQogICAgZGVm
IGFkZENoaWxkKHNlbGYsIGNoaWxkKToNCiAgICAgICAgc2VsZi5fY2hpbGRy
ZW4uYXBwZW5kKGNoaWxkKQ0KDQogICAgZGVmIF9fc3RyX18oc2VsZik6DQog
ICAgICAgIHJldHVybiBzdHIoc2VsZi5fZGF0dW0pDQoNCiAgICBkZWYgX19y
ZXByX18oc2VsZik6DQogICAgICAgIHJldHVybiAnVHJlZSglcywgJXMpJyAl
IChyZXByKHNlbGYuX2RhdHVtKSwgcmVwcihzZWxmLl9jaGlsZHJlbikpDQoN
Cg0KY2xhc3MgQmluYXJ5VHJlZToNCiAgICAiIiJBbiBpbXBsZW1lbnRhdGlv
biBvZiBhIGJpbmFyeSB0cmVlLCBhIHN0cnVjdHVyZSB0aGF0IGhhcyBhDQog
ICAgZGF0dW0sIGFuZCBhIGxlZnQgYW5kIHJpZ2h0IHN1YnRyZWUuIiIiDQog
ICAgZGVmIF9faW5pdF9fKHNlbGYsIGRhdHVtLCBsZWZ0ID0gTm9uZSwgcmln
aHQgPSBOb25lKToNCiAgICAgICAgc2VsZi5fZGF0dW0gPSBkYXR1bQ0KICAg
ICAgICBzZWxmLl9sZWZ0LCBzZWxmLl9yaWdodCA9IGxlZnQsIHJpZ2h0DQoN
CiAgICBkZWYgZ2V0RGF0dW0oc2VsZik6IHJldHVybiBzZWxmLl9kYXR1bQ0K
DQogICAgZGVmIGdldExlZnQoc2VsZik6IHJldHVybiBzZWxmLl9sZWZ0DQoN
CiAgICBkZWYgZ2V0UmlnaHQoc2VsZik6IHJldHVybiBzZWxmLl9yaWdodA0K
ICAgIA0KICAgIGRlZiBpc0xlYWYoc2VsZik6DQogICAgICAgIHJldHVybiBz
ZWxmLl9sZWZ0ID09IE5vbmUgYW5kIHNlbGYuX3JpZ2h0ID09IE5vbmUNCg0K
ICAgIGRlZiBfX3N0cl9fKHNlbGYpOg0KICAgICAgICByZXR1cm4gc3RyKHNl
bGYuX2RhdHVtKQ0KDQogICAgZGVmIF9fcmVwcl9fKHNlbGYpOg0KICAgICAg
ICByZXR1cm4gJ0JpbmFyeVRyZWUoJXMsICVzLCAlcyknICUgXA0KICAgICAg
ICAgICAgICAgdHVwbGUobWFwKHJlcHIsIFtzZWxmLl9kYXR1bSwgc2VsZi5f
bGVmdCwgc2VsZi5fcmlnaHRdKSkNCg0KDQpkZWYgZ2V0SHVmZm1hblRyZWUo
ZWxlbWVudHMpOg0KICAgICIiIkdpdmVuIGEgbGlzdCBvZiBlbGVtZW50cywg
bGV0J3MgY29uc3RydWN0IGEgaHVmZm1hbiB0cmVlIHRoYXQNCiAgICBjYW4g
YmUgdXNlZCB0byBwcm9kdWNlIGFuIG9wdGltYWwgYmluYXJ5IGNvZGUuIiIi
DQogICAgZm9yZXN0ID0gZ2V0Rm9yZXN0RnJvbUVsZW1lbnRzKGVsZW1lbnRz
KQ0KICAgIHdoaWxlIGxlbihmb3Jlc3QpID4gMToNCiAgICAgICAgdDEsIHQy
ID0gZ2V0TWluaW1hbFR3b0VsZW1lbnRzKGZvcmVzdCkNCiAgICAgICAgZm9y
ZXN0LnJlbW92ZSh0MSkNCiAgICAgICAgZm9yZXN0LnJlbW92ZSh0MikNCiAg
ICAgICAgZm9yZXN0LmFwcGVuZChodWZmbWFuTWVyZ2VUcmVlcyh0MSwgdDIp
KQ0KICAgIHJldHVybiBmb3Jlc3RbMF0NCg0KIyMjIyMjIyMjIyMjIyMjIyMj
IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMj
IyMjIyMjIw0KIyMgVGhlIGZvbGxvd2luZyBhcmUgaGVscGVyIGZ1bmN0aW9u
cyBmb3IgZ2V0SHVmZm1hblRyZWUoKToNCg0KIyMgVGhlIGRhdHVtIG9mIGEg
aHVmZm1hbiBub2RlIGNvbnNpc3RzIG9mIGEgbGFiZWwgYW5kIGl0cyB0b3Rh
bA0KIyMgZnJlcXVlbmN5Lg0KZGVmIGRhdHVtTGFiZWwoZGF0dW0pOiByZXR1
cm4gZGF0dW1bMF0NCmRlZiBkYXR1bUZyZXEoZGF0dW0pOiByZXR1cm4gZGF0
dW1bMV0NCmRlZiBtYWtlRGF0dW0obGFiZWwsIGZyZXEpOiByZXR1cm4gKGxh
YmVsLCBmcmVxKQ0KDQoNCiMjIFBlcmhhcHMgSSBzaG91bGQgZ2VuZXJhbGl6
ZSB0aGlzOyBpdCBpcyBwcmV0dHkgZGFybiB1c2VmdWwsIGlmIGENCiMjIGxp
dHRsZSB1Z2x5Lg0KZGVmIGdldE1pbmltYWxUd29FbGVtZW50cyhmb3Jlc3Qp
Og0KICAgICIiIlJldHVybiB0aGUgbGVhc3QgZnJlcXVlbnQgdHdvIGVsZW1l
bnRzIG9mIGEgaHVmZm1hbiBmb3Jlc3QuIiIiDQogICAgbWluMSwgbWluMiA9
IGZvcmVzdFswOjJdDQogICAgaWYgZGF0dW1GcmVxKG1pbjIuZ2V0RGF0dW0o
KSkgPiBkYXR1bUZyZXEobWluMS5nZXREYXR1bSgpKSA6DQogICAgICAgIG1p
bjEsIG1pbjIgPSBtaW4yLCBtaW4xDQogICAgZm9yIHQgaW4gZm9yZXN0WzI6
XToNCiAgICAgICAgaWYgZGF0dW1GcmVxKHQuZ2V0RGF0dW0oKSkgPCBkYXR1
bUZyZXEobWluMS5nZXREYXR1bSgpKToNCiAgICAgICAgICAgIG1pbjEsIG1p
bjIgPSB0LCBtaW4xDQogICAgICAgIGVsaWYgZGF0dW1GcmVxKHQuZ2V0RGF0
dW0oKSkgPCBkYXR1bUZyZXEobWluMi5nZXREYXR1bSgpKToNCiAgICAgICAg
ICAgIG1pbjIgPSB0DQogICAgcmV0dXJuIG1pbjEsIG1pbjINCg0KDQpkZWYg
aHVmZm1hbk1lcmdlVHJlZXModHJlZTEsIHRyZWUyKToNCiAgICAiIiJNZXJn
ZSB0d28gaHVmZm1hbiB0cmVlcyBpbnRvIGEgbGFyZ2VyIHRyZWUuIiIiDQog
ICAgbGFiZWwgPSBkYXR1bUxhYmVsKHRyZWUxLmdldERhdHVtKCkpICsgZGF0
dW1MYWJlbCh0cmVlMi5nZXREYXR1bSgpKQ0KICAgIGZyZXEgPSBkYXR1bUZy
ZXEodHJlZTEuZ2V0RGF0dW0oKSkgKyBkYXR1bUZyZXEodHJlZTIuZ2V0RGF0
dW0oKSkNCiAgICByZXR1cm4gQmluYXJ5VHJlZShtYWtlRGF0dW0obGFiZWws
IGZyZXEpLCB0cmVlMSwgdHJlZTIpDQoNCg0KZGVmIGdldEZvcmVzdEZyb21F
bGVtZW50cyhlbGVtZW50cyk6DQogICAgIiIiR2l2ZXMgdXMgYSBmb3Jlc3Qg
b2YgbGVhdmVzIHdob3NlIGRhdHVtcyBjb250YWluIGFuIGVsZW1lbnQgYW5k
DQogICAgaXRzIGZyZXF1ZW5jeS4iIiINCiAgICBjb3VudHMgPSB7fQ0KICAg
IGZvciBlIGluIGVsZW1lbnRzOg0KICAgICAgICBjb3VudHNbZV0gPSBjb3Vu
dHMuZ2V0KGUsIDApICsgMQ0KICAgIGZvcmVzdCA9IFtdDQogICAgZm9yIGxl
dHRlciwgZnJlcXVlbmN5IGluIGNvdW50cy5pdGVtcygpOg0KICAgICAgICBk
YXR1bSA9IG1ha2VEYXR1bShbbGV0dGVyXSwgZnJlcXVlbmN5KQ0KICAgICAg
ICBmb3Jlc3QuYXBwZW5kKEJpbmFyeVRyZWUoZGF0dW0sIE5vbmUsIE5vbmUp
KQ0KICAgIHJldHVybiBmb3Jlc3QNCg0KDQojIyBIb3cgZG8gd2UgZHJhdyB0
cmVlcyBncmFwaGljYWxseT8gIEFuZCBuaWNlbHk/DQo=
--545289610-654942913-989298326=:5754--


From juno@gamefire.com  Tue May  8 06:56:14 2001
From: juno@gamefire.com (juno@gamefire.com)
Date: Mon, 7 May 2001 22:56:14 -0700
Subject: [Tutor] Possible Useless Python Challenge.  [huffman encoding]
In-Reply-To: <Pine.LNX.4.21.0105072049130.5754-200000@hkn.eecs.berkeley.edu>
Message-ID: <DEEGIKBPAICAIOPICOHKKEFLCBAA.juno@gamefire.com>

Daniel,
You rock! I thought that LZH and LHA was an old dead compression algorithm
that only hackers still used  ;)

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Daniel Yoo
Sent: Monday, May 07, 2001 10:05 PM
To: Rob Andrews
Cc: Deirdre Saoirse Moen; tutor@python.org
Subject: Re: [Tutor] Possible Useless Python Challenge. [huffman encoding]

On Mon, 7 May 2001, Rob Andrews wrote:

> Sometimes I barely understand a word of what's currently being discussed
> and still think it sounds nifty. This is such a time.
>
> Deirdre Saoirse Moen wrote:
> >
> > >On Sun, 6 May 2001, Tesla Coil wrote:
> > >
> > >>  KiSS data sets are bundled using LZH compression,
> > >>  if there's a module for that, I haven't located it.
> > >
> > >I haven't found an LZH decompressor for Python.  In fact, the GnomeKISS
> > >people are depending on a separate LHA extraction program, so perhaps a
> > >Python KISS program should delegate the handling of LZH compression to
the
> > >LHA utility.
> >
> > I've written both Lempel-Ziv and Huffman compressors and
> > decompressors, but not LZH per se and not in Python. Given that
> > Python has all the requisite bitwise operators, it would be possible,
> > but it'd probably be better to write a wrapper for an existing set of
> > C functions.


*laugh* I have a little bit of code that almost implements Huffman
encoding.  (VanL, this uses some of the tree code I mentioned earlier.)
I was writing this during the afternoon.  Coincidence, huh?

I'll try to give the flavor of what Huffman encoding is.  We need to give
a little background though.  [note, this is LONG.]

When we represent letters --- one character strings --- Python (and mostly
every other computer language) internally uses a numeric code called
ASCII: American Standard Code for Information Interchange, to encode each
character.

Our computers are bit crunchers, so this means that every character we
store needs to be saved as a number.  For example, we could look at the
string:

    "hello world"

as a list of ASCII numbers:

###
>>> map(ord, 'hello world')
[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
###

but this is still one step removed from how computers REALLY represent
characters; they represent them, not just in numeric form, but in crude,
binary, base-two!  Ones and zeros, and that's really weird when we first
see it.  Here's a small program that will try to reveal what's underneath:

###
>>> def binaryStringHelper(n):
...     if n == 0: return ''
...     else: return binaryStringHelper(n >> 1) + str(n % 2)
...
>>> def toBinaryString(n):
...     if n == 0: return string.zfill(0, 8)
...     return string.zfill(int(binaryStringHelper(n)), 8)
...
>>> pprint.pprint(map(toBinaryString, range(10)))
['00000000',          ## ...stands for 0
 '00000001',          ## ...stands for 1
 '00000010',          ##               2
 '00000011',          ##               3
 '00000100',          ##             ...
 '00000101',
 '00000110',
 '00000111',
 '00001000',          ##               8
 '00001001']          ##               9
###

This is doing some hacky bit manipulation which isn't really important:
the important thing is that this program above allows us to visualize all
those one's and zero's that the computer actually uses to represent a
character.  We can apply this on our string:


###
>>> pprint.pprint(map(toBinaryString, map(ord, 'hello world')))
['01101000',
 '01100101',
 '01101100',
 '01101100',
 '01101111',
 '00100000',
 '01110111',
 '01101111',
 '01110010',
 '01101100',
 '01100100']
###

and this is how computers today truly store 'hello world' in its memory,
as streams of ones and zeros.  Every character is eight bits, so any
string of length 'n' will take up '8*n' bits.  Our small sentence, 'hello
world', takes up 88 bits!


Ok, this doesn't sound as world-threatening as we're making it out to be,
but what is neat about Huffman encoding is that we can usually do much
better than 88 bits.

What Huffman realized is that we're not taking advantage of a certain
curious property about human language: we use certain words over and over,
certain letters over and over, and our language is fraught with
repetitious repetition. What if we don't always represent a character by 8
bits, but by something that depends on how frequently the letter occurs in
our language?  Instead of having every letter be represented by eight
bits, we can make a "variable length" encoding.  That is, perhaps we can
use the following code:

    'h' ===> 0000
    'w' ===> 0001
    'd' ===> 0010
    'e' ===> 0011
    'o' ===> 01
    'r' ===> 100
    ' ' ===> 101
    'l' ===> 11

That is, instead of using all eight bits on every letter, we can use a
shorter binary sequence for really frequent characters, and longer codes
for letters that we don't use as often.  For letters that don't occur at
all, we don't even need to give them a code.  Huffman's encoding gives us
a way of figuring out really good codes that do this for us.  What this
means is, that, instead of representing 'hello world' as:

###
>>> string.join(map(toBinaryString, map(ord, 'hello world')), '')
'011010000110010101101100011011000110111100100000011101110110111101110010011
0110001100100'
###


we can do it like this:

###
>>> code = {'h' : '0000', 'w' : '0001', 'd' : '0010', 'e' : '0011',
            'o' : '01',   'r' : '101',  ' ' : '101',  'l' : '11'}
>>> string.join(map(lambda c: code[c], 'hello world'), '')
'00000011111101101000101101110010'
####

which is a heck of a lot shorter than what we had previously.  This is the
heart of Huffman encoding: to find a binary representation for each number
so that a message doesn't take so much space to store.

Of course this is handwavy, because whoever wants to read our message
needs to have a copy of the dictionary!  They need to be able to convert
our binary message back into something readable, so we usually send off
the dictionary alongside the encoded text.  When a message gets large
enough, though, that overhead becomes negigible compared to the amount of
space we save.

Finally, the code itself needs to guarantee that, given a bit string,
there's only one way to rehydrate it back to it's nice spongy, wordy form.
Not coinciently, Huffman encoding guarantees this for us.  Really smart
guy, and really neat algorithm.

Does this make sense?  I get the feeling I talked too much on this one
already.  *grin*


The incomplete code to do Huffman encoding should be attached to this
message.  As soon as I get it in a nicer form, I'll send it off to Useless
Python.



From ppathiyi@cisco.com  Tue May  8 09:00:06 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Tue, 8 May 2001 13:30:06 +0530
Subject: [Tutor] Python availability on VxWorks
Message-ID: <032a01c0d794$e834a5f0$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

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

HI,
        Is python interpreter available for VxWorks ? I have seen =
mentions about python on Unix, Windows and MAC OSs. But not on VxWorks. =
Can anybody throw some light on this ?

TIA,
Praveen.

------=_NextPart_000_0327_01C0D7C2.FE99BF50
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>HI,</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Is=20
python interpreter available for VxWorks ? I have seen mentions about =
python on=20
Unix, Windows and MAC OSs. But not on VxWorks. Can anybody throw some =
light on=20
this ?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0327_01C0D7C2.FE99BF50--



From deirdre@deirdre.net  Tue May  8 09:12:50 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Tue, 8 May 2001 01:12:50 -0700
Subject: [Tutor] Python availability on VxWorks
In-Reply-To: <032a01c0d794$e834a5f0$37ef87c0@ppathiyipc>
References: <032a01c0d794$e834a5f0$37ef87c0@ppathiyipc>
Message-ID: <a05100e04b71d5ad1f6c0@[10.0.1.8]>

--============_-1222812916==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

>HI,
>Is python interpreter available for VxWorks ? I have seen mentions 
>about python on Unix, Windows and MAC OSs. But not on VxWorks. Can 
>anybody throw some light on this ?

vxWorks is a Unix derivative. That said, I don't know a whole lot about it.

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams
--============_-1222812916==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>Re: [Tutor] Python availability on
VxWorks</title></head><body>
<blockquote type="cite" cite><font face="Arial"
size="-1">HI,</font></blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">Is python
interpreter available for VxWorks ? I have seen mentions about python
on Unix, Windows and MAC OSs. But not on VxWorks. Can anybody throw
some light on this ?</font></blockquote>
<div><br></div>
<div>vxWorks is a Unix derivative. That said, I don't know a whole lot
about it.</div>
</body>
</html>
--============_-1222812916==_ma============--


From lonetwin@yahoo.com  Tue May  8 09:50:43 2001
From: lonetwin@yahoo.com (steve)
Date: Tue, 8 May 2001 14:20:43 +0530
Subject: [Tutor] Possible Useless Python Challenge. [huffman encoding]
In-Reply-To: <Pine.LNX.4.21.0105072049130.5754-200000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105072049130.5754-200000@hkn.eecs.berkeley.edu>
Message-ID: <01050814204300.02674@mercury.in.cqsl.com>

Hey Dan,
 Thanx, Every day I learn something new, an' I just finished today's quot=
a !!!

Peace
Steve

P.S: U pretty good at xplainin' stuff, did n e body ever tell u that ???


On Tuesday 08 May 2001 10:35, you wrote:

> > On Mon, 7 May 2001, Rob Andrews wrote:
> > Sometimes I barely understand a word of what's currently being discus=
sed
> > and still think it sounds nifty. This is such a time.
> >
> > Deirdre Saoirse Moen wrote:
> > > >On Sun, 6 May 2001, Tesla Coil wrote:
> > > >>  KiSS data sets are bundled using LZH compression,
> > > >>  if there's a module for that, I haven't located it.
> > > >
> > > >I haven't found an LZH decompressor for Python.  In fact, the
> > > > GnomeKISS people are depending on a separate LHA extraction progr=
am,
> > > > so perhaps a Python KISS program should delegate the handling of =
LZH
> > > > compression to the LHA utility.
> > >
> > > I've written both Lempel-Ziv and Huffman compressors and
> > > decompressors, but not LZH per se and not in Python. Given that
> > > Python has all the requisite bitwise operators, it would be possibl=
e,
> > > but it'd probably be better to write a wrapper for an existing set =
of
> > > C functions.
>
> *laugh* I have a little bit of code that almost implements Huffman
> encoding.  (VanL, this uses some of the tree code I mentioned earlier.)
> I was writing this during the afternoon.  Coincidence, huh?
>
> I'll try to give the flavor of what Huffman encoding is.  We need to gi=
ve
> a little background though.  [note, this is LONG.]
>
> When we represent letters --- one character strings --- Python (and mos=
tly
> every other computer language) internally uses a numeric code called
> ASCII: American Standard Code for Information Interchange, to encode ea=
ch
> character.
>
> Our computers are bit crunchers, so this means that every character we
> store needs to be saved as a number.  For example, we could look at the
> string:
>
>     "hello world"
>
> as a list of ASCII numbers:
>
> ###
>
> >>> map(ord, 'hello world')
>
> [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
> ###
>
> but this is still one step removed from how computers REALLY represent
> characters; they represent them, not just in numeric form, but in crude=
,
> binary, base-two!  Ones and zeros, and that's really weird when we firs=
t
> see it.  Here's a small program that will try to reveal what's undernea=
th:
>
> ###
>
> >>> def binaryStringHelper(n):
>
> ...     if n =3D=3D 0: return ''
> ...     else: return binaryStringHelper(n >> 1) + str(n % 2)
> ...
>
> >>> def toBinaryString(n):
>
> ...     if n =3D=3D 0: return string.zfill(0, 8)
> ...     return string.zfill(int(binaryStringHelper(n)), 8)
> ...
>
> >>> pprint.pprint(map(toBinaryString, range(10)))
>
> ['00000000',          ## ...stands for 0
>  '00000001',          ## ...stands for 1
>  '00000010',          ##               2
>  '00000011',          ##               3
>  '00000100',          ##             ...
>  '00000101',
>  '00000110',
>  '00000111',
>  '00001000',          ##               8
>  '00001001']          ##               9
> ###
>
> This is doing some hacky bit manipulation which isn't really important:
> the important thing is that this program above allows us to visualize a=
ll
> those one's and zero's that the computer actually uses to represent a
> character.  We can apply this on our string:
>
>
> ###
>
> >>> pprint.pprint(map(toBinaryString, map(ord, 'hello world')))
>
> ['01101000',
>  '01100101',
>  '01101100',
>  '01101100',
>  '01101111',
>  '00100000',
>  '01110111',
>  '01101111',
>  '01110010',
>  '01101100',
>  '01100100']
> ###
>
> and this is how computers today truly store 'hello world' in its memory=
,
> as streams of ones and zeros.  Every character is eight bits, so any
> string of length 'n' will take up '8*n' bits.  Our small sentence, 'hel=
lo
> world', takes up 88 bits!
>
>
> Ok, this doesn't sound as world-threatening as we're making it out to b=
e,
> but what is neat about Huffman encoding is that we can usually do much
> better than 88 bits.
>
> What Huffman realized is that we're not taking advantage of a certain
> curious property about human language: we use certain words over and ov=
er,
> certain letters over and over, and our language is fraught with
> repetitious repetition. What if we don't always represent a character b=
y 8
> bits, but by something that depends on how frequently the letter occurs=
 in
> our language?  Instead of having every letter be represented by eight
> bits, we can make a "variable length" encoding.  That is, perhaps we ca=
n
> use the following code:
>
>     'h' =3D=3D=3D> 0000
>     'w' =3D=3D=3D> 0001
>     'd' =3D=3D=3D> 0010
>     'e' =3D=3D=3D> 0011
>     'o' =3D=3D=3D> 01
>     'r' =3D=3D=3D> 100
>     ' ' =3D=3D=3D> 101
>     'l' =3D=3D=3D> 11
>
> That is, instead of using all eight bits on every letter, we can use a
> shorter binary sequence for really frequent characters, and longer code=
s
> for letters that we don't use as often.  For letters that don't occur a=
t
> all, we don't even need to give them a code.  Huffman's encoding gives =
us
> a way of figuring out really good codes that do this for us.  What this
> means is, that, instead of representing 'hello world' as:
>
> ###
>
> >>> string.join(map(toBinaryString, map(ord, 'hello world')), '')
>
> '0110100001100101011011000110110001101111001000000111011101101111011100=
1001
>10110001100100' ###
>
>
> we can do it like this:
>
> ###
>
> >>> code =3D {'h' : '0000', 'w' : '0001', 'd' : '0010', 'e' : '0011',
>
>             'o' : '01',   'r' : '101',  ' ' : '101',  'l' : '11'}
>
> >>> string.join(map(lambda c: code[c], 'hello world'), '')
>
> '00000011111101101000101101110010'
> ####
>
> which is a heck of a lot shorter than what we had previously.  This is =
the
> heart of Huffman encoding: to find a binary representation for each num=
ber
> so that a message doesn't take so much space to store.
>
> Of course this is handwavy, because whoever wants to read our message
> needs to have a copy of the dictionary!  They need to be able to conver=
t
> our binary message back into something readable, so we usually send off
> the dictionary alongside the encoded text.  When a message gets large
> enough, though, that overhead becomes negigible compared to the amount =
of
> space we save.
>
> Finally, the code itself needs to guarantee that, given a bit string,
> there's only one way to rehydrate it back to it's nice spongy, wordy fo=
rm.
> Not coinciently, Huffman encoding guarantees this for us.  Really smart
> guy, and really neat algorithm.
>
> Does this make sense?  I get the feeling I talked too much on this one
> already.  *grin*
>
>
> The incomplete code to do Huffman encoding should be attached to this
> message.  As soon as I get it in a nicer form, I'll send it off to Usel=
ess
> Python.

----------------------------------------
Content-Type: TEXT/PLAIN; charset=3D"US-ASCII"; name=3D"huffman.py"
Content-Transfer-Encoding: BASE64
Content-Description:=20
----------------------------------------

--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
"Unfortunately, those people who have nothing better to do than post on t=
he
Internet all day long are rarely the ones who have the most insights."
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From cooler12001@yahoo.com  Tue May  8 10:25:35 2001
From: cooler12001@yahoo.com (Matthews James)
Date: Tue, 8 May 2001 02:25:35 -0700 (PDT)
Subject: [Tutor] help with files
Message-ID: <20010508092535.2976.qmail@web11405.mail.yahoo.com>

Ok I have a .txt file that is something like this:

#####################################################
[backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace]wds[backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace]\w\des\s
jumper eat the ball
[backspace][backspace][backspace][backspace]jumper
#######################################################

I am want help with changing the looks of it. like at
a [backspace] im wanting to have a '\n' after it so
that it will change lines. and the letters or words im
wanting to stay on the same line. Can anyone help me? 

I know how to open a file in python but not change it 

I know that anyone that looks at this question is
gonna say  huh? 

this is all i know about this stuff:
####################################################
openfile = open(filename,'{what do i put here}')
####################################################


Thanx and Thanx to all of you who helped me out on my
other lame questions.

James

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/


From wheelege@tsn.cc  Tue May  8 12:06:29 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Tue, 8 May 2001 21:06:29 +1000
Subject: [Tutor] Python CGI-HTML editor
References: <200105070938_MC2-D005-A842@compuserve.com>
Message-ID: <00dd01c0d7ae$f3f6e820$0200a8c0@ACE>

>I have coded an HTML online editor with the help of several Python CGI
>scripts. I´m now faced woth the problem of image insertion, I know how to
>upload files per CGI-Python to a server, but I still have 1 complicated
>hurdle:
>
>1. Is it possilbe to start a file upload AND send text data from a HTML
>form at the same time?

  Well, I don't know if anybody else has answered you yet, but you could
take a look at threading.  Something like...

import thread
<code>
def UploadStuff(file, form, server):
    thread.start_new_thread(UploadFile, (file, server))
    thread.start_new_thread(UploadForm, (form, server))
def UploadFile(file, server):
    <upload file to server...>
def UploadForm(file, server):
    <upload form to server...>

  As you can probably tell, I am not fluent in CGI - yet.  But I think this
should work if the server supports multiple connections from the same IP
address.

  Hope that helps,
  Glen.



From rob@jam.rr.com  Tue May  8 12:19:32 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Tue, 08 May 2001 06:19:32 -0500
Subject: [Tutor] Possible Useless Python Challenge.  [huffman encoding]
References: <Pine.LNX.4.21.0105072049130.5754-200000@hkn.eecs.berkeley.edu>
Message-ID: <3AF7D644.6219F546@jam.rr.com>

I'm so glad Danny Yoo became involved in programming instead of
competing on the karaoke circuit or something. Thanks to Danny and
Deirdre both for bringing the subject more into the light.

Rob

Daniel Yoo wrote:
> 
> On Mon, 7 May 2001, Rob Andrews wrote:
> 
> > Sometimes I barely understand a word of what's currently being discussed
> > and still think it sounds nifty. This is such a time.
> >
> > Deirdre Saoirse Moen wrote:
> > >
> > > >On Sun, 6 May 2001, Tesla Coil wrote:
> > > >
> > > >>  KiSS data sets are bundled using LZH compression,
> > > >>  if there's a module for that, I haven't located it.
> > > >
> > > >I haven't found an LZH decompressor for Python.  In fact, the GnomeKISS
> > > >people are depending on a separate LHA extraction program, so perhaps a
> > > >Python KISS program should delegate the handling of LZH compression to the
> > > >LHA utility.
> > >
> > > I've written both Lempel-Ziv and Huffman compressors and
> > > decompressors, but not LZH per se and not in Python. Given that
> > > Python has all the requisite bitwise operators, it would be possible,
> > > but it'd probably be better to write a wrapper for an existing set of
> > > C functions.
> 
> *laugh* I have a little bit of code that almost implements Huffman
> encoding.  (VanL, this uses some of the tree code I mentioned earlier.)
> I was writing this during the afternoon.  Coincidence, huh?
> 
> I'll try to give the flavor of what Huffman encoding is.  We need to give
> a little background though.  [note, this is LONG.]
> 
> When we represent letters --- one character strings --- Python (and mostly
> every other computer language) internally uses a numeric code called
> ASCII: American Standard Code for Information Interchange, to encode each
> character.
> 
> Our computers are bit crunchers, so this means that every character we
> store needs to be saved as a number.  For example, we could look at the
> string:
> 
>     "hello world"
> 
> as a list of ASCII numbers:
> 
> ###
> >>> map(ord, 'hello world')
> [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
> ###
> 
> but this is still one step removed from how computers REALLY represent
> characters; they represent them, not just in numeric form, but in crude,
> binary, base-two!  Ones and zeros, and that's really weird when we first
> see it.  Here's a small program that will try to reveal what's underneath:
> 
> ###
> >>> def binaryStringHelper(n):
> ...     if n == 0: return ''
> ...     else: return binaryStringHelper(n >> 1) + str(n % 2)
> ...
> >>> def toBinaryString(n):
> ...     if n == 0: return string.zfill(0, 8)
> ...     return string.zfill(int(binaryStringHelper(n)), 8)
> ...
> >>> pprint.pprint(map(toBinaryString, range(10)))
> ['00000000',          ## ...stands for 0
>  '00000001',          ## ...stands for 1
>  '00000010',          ##               2
>  '00000011',          ##               3
>  '00000100',          ##             ...
>  '00000101',
>  '00000110',
>  '00000111',
>  '00001000',          ##               8
>  '00001001']          ##               9
> ###
> 
> This is doing some hacky bit manipulation which isn't really important:
> the important thing is that this program above allows us to visualize all
> those one's and zero's that the computer actually uses to represent a
> character.  We can apply this on our string:
> 
> ###
> >>> pprint.pprint(map(toBinaryString, map(ord, 'hello world')))
> ['01101000',
>  '01100101',
>  '01101100',
>  '01101100',
>  '01101111',
>  '00100000',
>  '01110111',
>  '01101111',
>  '01110010',
>  '01101100',
>  '01100100']
> ###
> 
> and this is how computers today truly store 'hello world' in its memory,
> as streams of ones and zeros.  Every character is eight bits, so any
> string of length 'n' will take up '8*n' bits.  Our small sentence, 'hello
> world', takes up 88 bits!
> 
> Ok, this doesn't sound as world-threatening as we're making it out to be,
> but what is neat about Huffman encoding is that we can usually do much
> better than 88 bits.
> 
> What Huffman realized is that we're not taking advantage of a certain
> curious property about human language: we use certain words over and over,
> certain letters over and over, and our language is fraught with
> repetitious repetition. What if we don't always represent a character by 8
> bits, but by something that depends on how frequently the letter occurs in
> our language?  Instead of having every letter be represented by eight
> bits, we can make a "variable length" encoding.  That is, perhaps we can
> use the following code:
> 
>     'h' ===> 0000
>     'w' ===> 0001
>     'd' ===> 0010
>     'e' ===> 0011
>     'o' ===> 01
>     'r' ===> 100
>     ' ' ===> 101
>     'l' ===> 11
> 
> That is, instead of using all eight bits on every letter, we can use a
> shorter binary sequence for really frequent characters, and longer codes
> for letters that we don't use as often.  For letters that don't occur at
> all, we don't even need to give them a code.  Huffman's encoding gives us
> a way of figuring out really good codes that do this for us.  What this
> means is, that, instead of representing 'hello world' as:
> 
> ###
> >>> string.join(map(toBinaryString, map(ord, 'hello world')), '')
> '0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100'
> ###
> 
> we can do it like this:
> 
> ###
> >>> code = {'h' : '0000', 'w' : '0001', 'd' : '0010', 'e' : '0011',
>             'o' : '01',   'r' : '101',  ' ' : '101',  'l' : '11'}
> >>> string.join(map(lambda c: code[c], 'hello world'), '')
> '00000011111101101000101101110010'
> ####
> 
> which is a heck of a lot shorter than what we had previously.  This is the
> heart of Huffman encoding: to find a binary representation for each number
> so that a message doesn't take so much space to store.
> 
> Of course this is handwavy, because whoever wants to read our message
> needs to have a copy of the dictionary!  They need to be able to convert
> our binary message back into something readable, so we usually send off
> the dictionary alongside the encoded text.  When a message gets large
> enough, though, that overhead becomes negigible compared to the amount of
> space we save.
> 
> Finally, the code itself needs to guarantee that, given a bit string,
> there's only one way to rehydrate it back to it's nice spongy, wordy form.
> Not coinciently, Huffman encoding guarantees this for us.  Really smart
> guy, and really neat algorithm.
> 
> Does this make sense?  I get the feeling I talked too much on this one
> already.  *grin*
> 
> The incomplete code to do Huffman encoding should be attached to this
> message.  As soon as I get it in a nicer form, I'll send it off to Useless
> Python.
> 
>   ------------------------------------------------------------------------
>                  Name: huffman.py
>    huffman.py    Type: Plain Text (TEXT/PLAIN)
>              Encoding: BASE64

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From wheelege@tsn.cc  Tue May  8 13:09:08 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Tue, 8 May 2001 22:09:08 +1000
Subject: [Tutor] com...?
Message-ID: <01c501c0d7b7$afe9dc60$0200a8c0@ACE>

This is a multi-part message in MIME format.

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

  Hey all,

  Ok, maybe I'm just really unco at finding documentation, but this =
mythical com module for win32...I can't find it for the life of me.  I =
am planning on controlling internet explorer using it (from within a =
python script).
  A link to some documentation would be nice.

  Thanks,
  Glen.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Hey all,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Ok, maybe I'm just really unco at finding documentation, but =
this=20
mythical com module for win32...I can't find it for the life of =
me.&nbsp; I am=20
planning on controlling internet explorer using it (from within a python =

script).</DIV>
<DIV>&nbsp; A link to some documentation would be nice.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_01C2_01C0D80B.81080440--



From parth.malwankar@wipro.com  Tue May  8 13:18:49 2001
From: parth.malwankar@wipro.com (Parth Malwankar)
Date: Tue, 8 May 2001 17:48:49 +0530
Subject: [Tutor] Python availability on VxWorks
In-Reply-To: <a05100e04b71d5ad1f6c0@[10.0.1.8]>; from Deirdre Saoirse Moen on Tue, May 08, 2001 at 01:12:50AM -0700
References: <032a01c0d794$e834a5f0$37ef87c0@ppathiyipc> <a05100e04b71d5ad1f6c0@[10.0.1.8]>
Message-ID: <20010508174849.C4304@wipro.wipsys.sequent.com>

http://daikon.tuc.noao.edu/python/
Contains info about building python for vxWorks. I havent tried it though.
Regards,
Parth

On Tue, May 08, 2001 at 01:12:50AM -0700, Deirdre Saoirse Moen wrote:
>>HI,
>>Is python interpreter available for VxWorks ? I have seen mentions 
>>about python on Unix, Windows and MAC OSs. But not on VxWorks. Can 
>>anybody throw some light on this ?
>
>vxWorks is a Unix derivative. That said, I don't know a whole lot about it.
>
>-- 
>_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
>"I love deadlines. I like the whooshing sound they make as they fly by."
>                                                          - Douglas Adams


From scarblac@pino.selwerd.nl  Tue May  8 13:25:01 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 8 May 2001 14:25:01 +0200
Subject: [Tutor] com...?
In-Reply-To: <01c501c0d7b7$afe9dc60$0200a8c0@ACE>; from wheelege@tsn.cc on Tue, May 08, 2001 at 10:09:08PM +1000
References: <01c501c0d7b7$afe9dc60$0200a8c0@ACE>
Message-ID: <20010508142501.A7353@pino.selwerd.nl>

On  0, Glen Wheeler <wheelege@tsn.cc> wrote:
>   Ok, maybe I'm just really unco at finding documentation, but this mythical com module for win32...I can't find it for the life of me.  I am planning on controlling internet explorer using it (from within a python script).
>   A link to some documentation would be nice.

You need the Windows extensions, they're not in the standard Python
distribution. See
http://aspn.activestate.com/ASPN/Downloads/ActivePython/Extensions/Win32all

ActiveState also has their own Python distribution that includes the Windows
things, if you like that better.

I don't know where good online information is (I don't do Windows), but the
book "Python Programming on Win32" is supposed to be pretty good at
explaining COM with Python.

-- 
Remco Gerlich


From julieta_rangel@hotmail.com  Tue May  8 13:33:08 2001
From: julieta_rangel@hotmail.com (Julieta Rangel)
Date: Tue, 08 May 2001 07:33:08 -0500
Subject: [Tutor] selecting specific items from a list
Message-ID: <F703ednHM3SOlbpH71y0000066a@hotmail.com>

Let's say I have the following list:

[(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)]

How can I tell the computer to return to me only those items in the list for 
which x==y.  That is, [(3,3), (5,5), (1,1), (a,a), (b,b)].

It's a dumb question, but somebody's got to ask it :)

Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From ppathiyi@cisco.com  Tue May  8 13:44:04 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Tue, 8 May 2001 18:14:04 +0530
Subject: [Tutor] selecting specific items from a list
References: <F703ednHM3SOlbpH71y0000066a@hotmail.com>
Message-ID: <03b601c0d7bc$90e7aea0$37ef87c0@ppathiyipc>

I feel that the following should do the job for you...

list1 = [(3,3),(2,0),(5,5), (1,1), (4,5), ('a','a'), ('a','e'), ('b','b'),
('c','d')]
eq_list = []

for (x,y) in list1:
    if x==y:
        eq_list.append(x,y)

Regards,
Praveen.


----- Original Message -----
From: "Julieta Rangel" <julieta_rangel@hotmail.com>
To: <tutor@python.org>
Sent: Tuesday, May 08, 2001 6:03 PM
Subject: [Tutor] selecting specific items from a list


> Let's say I have the following list:
>
> [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)]
>
> How can I tell the computer to return to me only those items in the list
for
> which x==y.  That is, [(3,3), (5,5), (1,1), (a,a), (b,b)].
>
> It's a dumb question, but somebody's got to ask it :)
>
> Julieta
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From scarblac@pino.selwerd.nl  Tue May  8 13:49:59 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 8 May 2001 14:49:59 +0200
Subject: [Tutor] selecting specific items from a list
In-Reply-To: <F703ednHM3SOlbpH71y0000066a@hotmail.com>; from julieta_rangel@hotmail.com on Tue, May 08, 2001 at 07:33:08AM -0500
References: <F703ednHM3SOlbpH71y0000066a@hotmail.com>
Message-ID: <20010508144958.A7908@pino.selwerd.nl>

On  0, Julieta Rangel <julieta_rangel@hotmail.com> wrote:
> Let's say I have the following list:
> 
> [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)]
> 
> How can I tell the computer to return to me only those items in the list for 
> which x==y.  That is, [(3,3), (5,5), (1,1), (a,a), (b,b)].
> 
> It's a dumb question, but somebody's got to ask it :)

It's easiest with list comprehensions, but they're new in 2.0:
(I'm calling your list 'tuplist')

result = [tup for tup in tuplist if tup[0] == tup[1]]

That is, the list of tups, taken from tuplist, where tup[0] equals tup[1].
(the list comprehension notation was originally inspired by set notation in
math).

In older versions, you'd use filter. First you define a function that's true
for the tuples you want, then you filter the list using it:

def test_tuple(tup): 
   return tup[0] == tup[1]
result = filter(test_tuple, tuplist)

Some people would use a lambda to write that, so there's no need to name the
temporary function, and it becomes one line again:

result = filter(lambda tup: tup[0] == tup[1], tuplist)

-- 
Remco Gerlich


From bdupire@seatech.fau.edu  Tue May  8 15:11:38 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Tue, 08 May 2001 10:11:38 -0400
Subject: [Tutor] Python internals.
Message-ID: <3AF7FE99.5B4FF279@seatech.fau.edu>

it's up to me to ask something to the Python gurus out there...

One of the BIG difference between Python and C++, except for speed, is
that Python is dynamic and C++ static.

Thus, i can define in Python new functions on the fly and take advantage
of features such as
myString= 'a=19+3'
exec(myString)

But myString could also be a new function.

My question is the following: how does Python internally create a new
function dynamically, although it's implemented in C, where such
features are not allowed (static) ?
How are Python functions implemented in C?
My question might have no sense, i know. . .

Anyway.. i am just curious...

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From tescoil@irtc.net  Tue May  8 15:45:01 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Tue, 08 May 2001 09:45:01 -0500
Subject: [Tutor] Possible Useless Python Challenge.
References: <Pine.LNX.4.21.0105071839360.31420-100000@hkn.eecs.berkeley.edu>
Message-ID: <3AF8066D.33C13F3E@irtc.net>

On 7 May 2001, Daniel Yoo wrote:
> I haven't found an LZH decompressor for Python.  In fact,
> the GnomeKISS people are depending on a separate LHA 
> extraction program, so perhaps a Python KISS program 
> should delegate the handling of LZH compression to the
> LHA utility.

I was going to mention LHA, but the TODO file included
with GnomeKiss source lists to "do LZH natively, and
generally support it better"--from which I infer it's
been judged not the best approach.  

A C extension module to handle LZH might assist the
Python World Domination campaign in Japan.  Doesn't
look like Ruby has a library for it yet either.

>> I suppose that a cel file decoder could be cooked up 
>> using Python Imaging Library, but I've no experience
>> in that department at all.  Other than that, I guess
>> one is up against reading .cnf files generated by a
>> variety of editors and sometimes written by hand.
>
> Hmmm... this actually sounds like a lot of fun!  I'll
> start looking at this... *grin*

I begin to get the feeling if I'd posted the message 
to c.l.py, there'd be PyKiss v0.2 by Friday... :}




From randrews@planhouse.com  Tue May  8 16:03:19 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Tue, 8 May 2001 10:03:19 -0500
Subject: [Tutor] Possible Useless Python Challenge.
In-Reply-To: <3AF8066D.33C13F3E@irtc.net>
Message-ID: <001101c0d7d0$04eec460$de00a8c0@planhouse5>

> I begin to get the feeling if I'd posted the message
> to c.l.py, there'd be PyKiss v0.2 by Friday... :}

But the Python Tutor list is where the real action is! This is the best
resource I've seen yet for newbies to see why Python's so exciting.

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



From tescoil@irtc.net  Tue May  8 16:20:01 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Tue, 08 May 2001 10:20:01 -0500
Subject: [Tutor] Possible Useless Python Challenge.  [huffman encoding]
References: <Pine.LNX.4.21.0105072049130.5754-200000@hkn.eecs.berkeley.edu>
Message-ID: <3AF80EA1.A86D5028@irtc.net>

On 7 May 2001, Daniel Yoo wrote:
> What Huffman realized is that we're not taking advantage
> of a certain curious property about human language: we=20
> use certain words over and over, certain letters over=20
> and over, and our language is fraught with repetitious
> repetition.  What if we don't always represent a=20
> character by 8 bits, but by something that depends
> on how frequently the letter occurs in our language?
> Instead of having every letter be represented by=20
> eight bits, we can make a "variable length" encoding.
> That is, perhaps we can use the following code:
>
>    'h' =3D=3D=3D> 0000
>    'w' =3D=3D=3D> 0001
>    'd' =3D=3D=3D> 0010
>    'e' =3D=3D=3D> 0011
>    'o' =3D=3D=3D> 01
>    'r' =3D=3D=3D> 100
>    ' ' =3D=3D=3D> 101
>    'l' =3D=3D=3D> 11

Incidentally, same principle used by an early
binary compression scheme known as Morse code:

'h' =3D=3D=3D> 0000
'w' =3D=3D=3D> 011
'd' =3D=3D=3D> 100
'e' =3D=3D=3D> 0
'o' =3D=3D=3D> 111
'r' =3D=3D=3D> 010
' ' =3D=3D=3D>
'l' =3D=3D=3D> 0100

"Plus =E7a change...," I guess.



From alan.gauld@bt.com  Tue May  8 17:19:03 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 May 2001 17:19:03 +0100
Subject: [Tutor] com...?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D74D@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C0D7DA.98E2B2D0
Content-type: text/plain; charset="iso-8859-1"

  Ok, maybe I'm just really unco at finding documentation, but this mythical
com module for win32...I can't find it for the life of me.  I am planning on
controlling internet explorer using it  
 

Assuming you have BeOpen Python 2 and installed winall in the same place you
should 
have folders called:
 
win32
win32com
win32comext
 
and within those there are demos etc.
 
There is also a help file of dubious value to a beginner. The best asource
is 
Mark Hammond's O'Reilly book tho'
 
Activestate probably install it in the same place but I don't know...
 
Alan G

 


------_=_NextPart_001_01C0D7DA.98E2B2D0
Content-type: text/html; charset="iso-8859-1"

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


<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV>&nbsp; Ok, maybe I'm just really unco at finding documentation, but this 
  mythical com module for win32...I can't find it for the life of me.&nbsp; I am 
  planning on controlling internet explorer using it&nbsp;<SPAN 
  class=110062316-08052001><FONT color=#0000ff face=Arial 
  size=2>&nbsp;</FONT></SPAN></DIV>
  <DIV><SPAN class=110062316-08052001></SPAN>&nbsp;</DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001>Assuming you have BeOpen Python 2 and installed winall 
in the same place you should </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=110062316-08052001>have 
folders called:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001>win32</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001>win32com</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001>win32comext</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=110062316-08052001>and 
within those there are demos etc.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=110062316-08052001>There 
is also a help file of dubious value to a beginner. The best asource is 
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=110062316-08052001>Mark 
Hammond's O'Reilly book tho'</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001>Activestate probably install it in the same place but I 
don't know...</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=110062316-08052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=110062316-08052001>Alan 
G</SPAN></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C0D7DA.98E2B2D0--


From alan.gauld@bt.com  Tue May  8 17:23:06 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 May 2001 17:23:06 +0100
Subject: [Tutor] selecting specific items from a list
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D74E@mbtlipnt02.btlabs.bt.co.uk>

> Let's say I have the following list:
> 
> [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)]
> 
> How can I tell the computer to return to me only those items 
> in the list for 
> which x==y.  That is, [(3,3), (5,5), (1,1), (a,a), (b,b)].

Thats exactly what reduce() is for.

def sames(t): return t[0] == t[1]  # test an element
newlist = reduce(sames, juliettelist) #use the test as an argument

Take a look at my Functional Programming for an intro to these
types of functions:

http://www.crosswinds.net/~agauld/tutfctnl.htm

Alan G


From bdupire@seatech.fau.edu  Tue May  8 17:32:20 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Tue, 08 May 2001 12:32:20 -0400
Subject: [Tutor] selecting specific items from a list
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D74E@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3AF81F94.1765214C@seatech.fau.edu>


alan.gauld@bt.com wrote:

> > Let's say I have the following list:
> >
> > [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)]
> >
> > How can I tell the computer to return to me only those items
> > in the list for
> > which x==y.  That is, [(3,3), (5,5), (1,1), (a,a), (b,b)].
>
> Thats exactly what reduce() is for.

you mean filter(), uh?

>
>
> def sames(t): return t[0] == t[1]  # test an element
> newlist = reduce(sames, juliettelist) #use the test as an argument

>
>
> Take a look at my Functional Programming for an intro to these
> types of functions:
>
> http://www.crosswinds.net/~agauld/tutfctnl.htm
>
> Alan G
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From python.tutorial@jarava.org  Tue May  8 17:34:40 2001
From: python.tutorial@jarava.org (Javier JJ)
Date: Tue, 8 May 2001 18:34:40 +0200
Subject: [Tutor] XML-RPC, ActiveState 2.1 and Linux??
Message-ID: <00cf01c0d7dc$cfcb5480$0124a8c0@uno>

Hi all!!

Been "toying" with Python for a while, and got used to ActiveState
"packaging" of it...  Now i've installed a copy of Linux under VMWare to do
some testing of a c/s app (no second PC, I'm afraid), and I need to use
xmlrpc for that. If I remember correctly, the xmlrpclib came with
ActiveState 2.0 under windows, but I've intalled the RPMs for both 2.0 and
2.1 under linux, and no xmlrpc present...

Am I missing something? Should I just go ahead an grab it from windows? It's
not that it's a problem to install, but that I'm worried about another
unexpeceted "differences".


TIA

    Javier

----

Portable: survives system reboot.





From maritza_rodz@hotmail.com  Tue May  8 17:49:03 2001
From: maritza_rodz@hotmail.com (Maritza Rodriguez)
Date: Tue, 08 May 2001 11:49:03 -0500
Subject: [Tutor] 15 puzzle
Message-ID: <F162fiPcQVjriLdElsB00000d31@hotmail.com>

I've been working with Glen Barnett on my program for the 15 puzzle.  He 
came up with this program which gives us the 4x4 matrix with the numbers 
1-15 in order from left to right and a blank space after the 15.  Also, it 
gives two additional buttons under the matrix, one that reads "SCRAMBLE" and 
another that reads "DONE".  We have not been able to figure out how to move 
the buttons so that if a button is clicked on (one that is next to the blank 
space, of course), it will automatically just pop into the blank spot.  Does 
anyone have any suggestions?

Maritza

from Tkinter import *
import sys

root = Tk()
root.title("15 PUZZLE")

frame = Frame(root)
frame["height"]=100
frame["width"]=100
frame["borderwidth"]=4
frame["relief"]=RAISED
frame.grid(row=0,column=0,sticky=E+W+N+S)

frame2 = Frame(root)
frame2["height"]=10
frame2["width"]=80
frame2["borderwidth"]=4
frame2["relief"]=RAISED
frame2.grid(row=1,column=0,sticky=E+W+N+S)



names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"]

n=0
for i in range (4):
    for j in range(4):
        if n!=15:
         item=Button(frame,text=names[n])
         item.grid(row=i,column=j,sticky=E+W+N+S)
         n=n+1

quit = Button(root,text="DONE")
quit.grid(row=2,column=0,sticky=E+W+N+S)
scramble = Button(root,text="SCRAMBLE")
scramble.grid(row=3,column=0,sticky=E+W+N+S)


root.mainloop()

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From alan.gauld@bt.com  Tue May  8 17:50:52 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 May 2001 17:50:52 +0100
Subject: [Tutor] selecting specific items from a list
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D74F@mbtlipnt02.btlabs.bt.co.uk>

> alan.gauld@bt.com wrote:
> > Thats exactly what reduce() is for.
> 
> you mean filter(), uh?

Blush! Yes I meant filter - I should read my own tutor mebbe :-?
[FWIW reduce() combines elements of a list into a single element, 
filter returns those passing the test function criteria...]

Apologies

Alan G



From cooler12001@yahoo.com  Tue May  8 18:21:19 2001
From: cooler12001@yahoo.com (Matthews James)
Date: Tue, 8 May 2001 10:21:19 -0700 (PDT)
Subject: [Tutor] question about renaming a file
Message-ID: <20010508172119.54879.qmail@web11405.mail.yahoo.com>

ok i figured out my last question.
but i ran into another one that i really can't 
do anything with

MY CODE:
####################################################
months =
{'01':'JAN.','02':'FEB.','03':'MAR.','04':'APR.','05':'MAY.',\
         
'06':'JUN.','07':'JUL.','08':'AUG.','09':'SEP.','10':'OCT.',\
          '11':'NOV.','12':'DEC.'}


def stamp(filename):
    times = filename
    time = times[0:2]+'.'+times[2:4]
    month = times[4:6]
    day = times[6:8]
    year = times[9:11]

    print time,
    if months.has_key(month):
        mon = months[month]
        print months[month],
    print day,
    print year
####################################################

this is suppose to open a file that is named by the
date in which the file was made:

12220508.01 

[1222] = 12:12   == time
[05]   = May     == month
[08]   = Tuesday == day
[01]   = 2001    == year

the program then converts this info to something
better like:

12.12 MAY. TUE. 01

Im want to change the other file's name to this

Can anyone help?

Thanx James


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/


From maritza_rodz@hotmail.com  Tue May  8 18:55:05 2001
From: maritza_rodz@hotmail.com (Maritza Rodriguez)
Date: Tue, 08 May 2001 12:55:05 -0500
Subject: [Tutor] 15 puzzle
Message-ID: <F2071h1jYhAOylhgnFZ00000d5e@hotmail.com>

This is what I have so far.  The program now exits the program by pressing 
the "DONE" button, which is great.  But, what I also want that button to do 
is tell you whether or not you have a solution to the puzzle, just before it 
exits.  Of course, first I have to figure out how to scramble the buttons in 
order to have an actual game going.  Any suggestions?

Maritza

import sys
from Tkinter import *

def die(event=0):
    sys.exit(0)

class Puzzle:
    def __init__(self,w):
        names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14",
        "15"," "]
        n = 0
        for i in range(4):
            for j in range(4):
                item1=Button(w,text=names[n])
                item1.grid(row=i,column=j,sticky=E+W+N+S)

                item2=Button(w,text=names[n])
                item2.grid(row=i,column=j,sticky=E+W+N+S)

                item3=Button(w,text=names[n])
                item3.grid(row=i,column=j,sticky=E+W+N+S)

                item4=Button(w,text=names[n])
                item4.grid(row=i,column=j,sticky=E+W+N+S)

                item5=Button(w,text=names[n])
                item5.grid(row=i,column=j,sticky=E+W+N+S)

                item6=Button(w,text=names[n])
                item6.grid(row=i,column=j,sticky=E+W+N+S)

                item7=Button(w,text=names[n])
                item7.grid(row=i,column=j,sticky=E+W+N+S)

                item8=Button(w,text=names[n])
                item8.grid(row=i,column=j,sticky=E+W+N+S)

                item9=Button(w,text=names[n])
                item9.grid(row=i,column=j,sticky=E+W+N+S)

                item10=Button(w,text=names[n])
                item10.grid(row=i,column=j,sticky=E+W+N+S)

                item11=Button(w,text=names[n])
                item11.grid(row=i,column=j,sticky=E+W+N+S)

                item12=Button(w,text=names[n])
                item12.grid(row=i,column=j,sticky=E+W+N+S)

                item13=Button(w,text=names[n])
                item13.grid(row=i,column=j,sticky=E+W+N+S)

                item14=Button(w,text=names[n])
                item14.grid(row=i,column=j,sticky=E+W+N+S)

                item15=Button(w,text=names[n])
                item15.grid(row=i,column=j,sticky=E+W+N+S)
                n = n+1


	f = Frame(w)
        b1=Button(f,text="SCRAMBLE")
        b2=Button(f,text="DONE")
        if "DONE":
            b2["command"] = die
        b1.pack(side=LEFT)
        b2.pack(side=RIGHT)
        f.grid(row=4,column=0,columnspan=4)



root=Tk()


gr=Toplevel(root)
gr.title("15-PUZZLE")
grc = Puzzle (gr)


root.withdraw()
root.mainloop()


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From arcege@speakeasy.net  Tue May  8 19:13:23 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Tue, 8 May 2001 14:13:23 -0400 (EDT)
Subject: [Tutor] Python internals.
In-Reply-To: <3AF7FE99.5B4FF279@seatech.fau.edu> from "Benoit Dupire" at May 08, 2001 10:11:38 AM
Message-ID: <200105081813.f48IDNi01720@dsl092-074-184.bos1.dsl.speakeasy.net>

Benoit Dupire wrote
> it's up to me to ask something to the Python gurus out there...
> 
> One of the BIG difference between Python and C++, except for speed, is
> that Python is dynamic and C++ static.
> 
> Thus, i can define in Python new functions on the fly and take advantage
> of features such as
> myString= 'a=19+3'
> exec(myString)
> 
> But myString could also be a new function.
> 
> My question is the following: how does Python internally create a new
> function dynamically, although it's implemented in C, where such
> features are not allowed (static) ?
> How are Python functions implemented in C?
> My question might have no sense, i know. . .

First, remember that everything in Python is translated into bytecode, not
directly into C.  The byte-code is then evaluated by C routines.  So to
look at the function, you can disassemble that with the "dis" module.

When a function/method/class, etc. gets byte-compiled into a separate
"code" object.

Python 1.5.2 (#1, Aug 25 2000, 09:33:37)  [GCC 2.96 20000731 (experimental)] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import dis
>>> def f():
...   i = 0
...   i = i + 1
...   return i
...
>>> f.func_code          # the Python "code" object associated with f
<code object f at 80dd1e0, file "<stdin>", line 1>
>>> f.func_code.co_code  # this is the byte-code itself
'\177\001\000\177\002\000d\001\000}\000\000\177\003\000|\000\000d\002\000\027}\0
00\000\177\004\000|\000\000Sd\000\000S'
>>> dis.dis(f.func_code) # now we look at it through the disassembler
          0 SET_LINENO          1

          3 SET_LINENO          2
          6 LOAD_CONST          1 (0)
          9 STORE_FAST          0 (i)

         12 SET_LINENO          3
         15 LOAD_FAST           0 (i)
         18 LOAD_CONST          2 (1)
         21 BINARY_ADD
         22 STORE_FAST          0 (i)

         25 SET_LINENO          4
         28 LOAD_FAST           0 (i)
         31 RETURN_VALUE
         32 LOAD_CONST          0 (None)
         35 RETURN_VALUE
>>>

Each of these individual operations (called "opcodes") are then coded
in C (or Java for JPython) as cases for a big switch statement (see the
function "eval_code2()" in Python/ceval.c).  The system uses a traditional
operation stack to process the byte code (pushing values on the stack,
popping values as you need them and execute the operation).  The opcodes
deal with data being placed on the stack and things happening so that
Python statements look like something intelligent.

You can make your own code segments too:
>>> g = compile('f()', '<stdin>', 'exec')
>>> g
<code object ? at 80de298, file "<stdin>", line 0>
>>> dis.dis(g)
          0 SET_LINENO          0

          3 SET_LINENO          1
          6 LOAD_NAME           0 (f)
          9 CALL_FUNCTION       0
         12 POP_TOP
         13 LOAD_CONST          0 (None)
         16 RETURN_VALUE
>>> exec g # call 'f()'

Most of the time you don't have to worry about all this, but it is
cool to know about.  You might also want to look into the "parser"
and related modules (symbol, token, etc.) which take Python sources and
generates byte-code.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From arcege@speakeasy.net  Tue May  8 20:58:40 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Tue, 8 May 2001 15:58:40 -0400 (EDT)
Subject: [Tutor] 15 puzzle
In-Reply-To: <F2071h1jYhAOylhgnFZ00000d5e@hotmail.com> from "Maritza Rodriguez" at May 08, 2001 12:55:05 PM
Message-ID: <200105081958.f48JwfC01793@dsl092-074-184.bos1.dsl.speakeasy.net>

Maritza Rodriguez wrote
> 
> This is what I have so far.  The program now exits the program by pressing 
> the "DONE" button, which is great.  But, what I also want that button to do 
> is tell you whether or not you have a solution to the puzzle, just before it 
> exits.  Of course, first I have to figure out how to scramble the buttons in 
> order to have an actual game going.  Any suggestions?
> 
> Maritza
> 
> import sys
> from Tkinter import *
> 
> def die(event=0):
>     sys.exit(0)
> 
> class Puzzle:
>     def __init__(self,w):
>         names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14",
>         "15"," "]
>         n = 0
>         for i in range(4):
>             for j in range(4):
>                 item1=Button(w,text=names[n])
>                 item1.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item2=Button(w,text=names[n])
>                 item2.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item3=Button(w,text=names[n])
>                 item3.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item4=Button(w,text=names[n])
>                 item4.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item5=Button(w,text=names[n])
>                 item5.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item6=Button(w,text=names[n])
>                 item6.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item7=Button(w,text=names[n])
>                 item7.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item8=Button(w,text=names[n])
>                 item8.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item9=Button(w,text=names[n])
>                 item9.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item10=Button(w,text=names[n])
>                 item10.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item11=Button(w,text=names[n])
>                 item11.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item12=Button(w,text=names[n])
>                 item12.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item13=Button(w,text=names[n])
>                 item13.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item14=Button(w,text=names[n])
>                 item14.grid(row=i,column=j,sticky=E+W+N+S)
> 
>                 item15=Button(w,text=names[n])
>                 item15.grid(row=i,column=j,sticky=E+W+N+S)
>                 n = n+1
> 
> 
> 	f = Frame(w)
>         b1=Button(f,text="SCRAMBLE")
>         b2=Button(f,text="DONE")
>         if "DONE":
>             b2["command"] = die
>         b1.pack(side=LEFT)
>         b2.pack(side=RIGHT)
>         f.grid(row=4,column=0,columnspan=4)

Add a new method to check the table against the "solution".

    solution = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
      "12", "13", "14", "15", " "]
    # I would even make 'self.names = self.solution[:]' in __init__

    def solved(self):
        return self.names == self.solution

Then make a method to handle the button presses:
    def is_it_really_solved(self):
        import Dialog
        if self.solved:
          Dialog.Dialog(self, {'title': 'Congratulations',
                         'text': 'You solved the puzzle!',
                         'bitmap': Dialog.DIALOG_ICON,
                         'default': 0,
                         'strings': ('Ok',))
          self.quit()  # stop Tkinter
        else:
          Dialog.Dialog(self, {'title': 'Sorry',
                               'text': 'Keep trying',
                               'bitmap': Dialog.DIALOG_ICON,
                               'default': 0,
                               'strings': ('Ok',))
[There are better dialog widgets, but this is one I remember without much
reference material right now... and it works]

Then for the blocks, you just need to keep track of the buttons, and
make commands for them:
    def makebuttons(self, w):
        self.buttons = [None] * 16
        for i in range(4):
            for j in range(4):
                pos = i + j * 4
                name = self.names[pos]
                b = Button(w, text=name,
                    command=lambda self=self, pos=(i, j): self.buttonpress)
                self.buttons[pos] = b

    def buttonpress(self, position):
        (i, j) = pos
        # find which surrounding button is "blank" and change around
        # self.names and the text label for the proper buttons in
        # self.buttons
        # [Leave this as an exercise for you :)]

> 
> root=Tk()
> 
> 
> gr=Toplevel(root)
> gr.title("15-PUZZLE")
> grc = Puzzle (gr)
> 
> 
> root.withdraw()
> root.mainloop()
> 
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From phil.bertram@clear.net.nz  Tue May  8 21:50:17 2001
From: phil.bertram@clear.net.nz (Phil Bertram)
Date: Wed, 9 May 2001 08:50:17 +1200
Subject: [Tutor] com...?
Message-ID: <001a01c0d802$5103c670$b43661cb@pf05nt.bayernz.co.nz>

This is a multi-part message in MIME format.

------=_NextPart_000_0012_01C0D865.1262B850
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

A starting point for the I Explorer component object model is here

http://msdn.microsoft.com/workshop/browser/overview/overview.asp

-----Original Message-----
From: Glen Wheeler <wheelege@tsn.cc>
To: tutor@python.org <tutor@python.org>
Date: Wednesday, 9 May 2001 12:17=20
Subject: [Tutor] com...?


    Hey all,

    Ok, maybe I'm just really unco at finding documentation, but this =
mythical com module for win32...I can't find it for the life of me.  I =
am planning on controlling internet explorer using it (from within a =
python script).
    A link to some documentation would be nice.

    Thanks,
    Glen.

------=_NextPart_000_0012_01C0D865.1262B850
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>A starting point for the I Explorer component object =
model is=20
here</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><STRONG><FONT size=3D2><A=20
href=3D"http://msdn.microsoft.com/workshop/browser/overview/overview.asp"=
>http://msdn.microsoft.com/workshop/browser/overview/overview.asp</FONT><=
/STRONG></A><FONT=20
face=3DArial><FONT size=3D2><B></B></FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><B></B></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT size=3D2><B>-----Original =
Message-----</B><BR><B>From:=20
</B>Glen Wheeler &lt;</FONT><A href=3D"mailto:wheelege@tsn.cc"><FONT=20
size=3D2>wheelege@tsn.cc</FONT></A><FONT size=3D2>&gt;<BR><B>To: =
</B></FONT><A=20
href=3D"mailto:tutor@python.org"><FONT =
size=3D2>tutor@python.org</FONT></A><FONT=20
size=3D2> &lt;</FONT><A href=3D"mailto:tutor@python.org"><FONT=20
size=3D2>tutor@python.org</FONT></A><FONT size=3D2>&gt;<BR><B>Date: =
</B>Wednesday, 9=20
May 2001 12:17 <BR><B>Subject: </B>[Tutor] com...?<BR><BR></DIV></FONT>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px =
solid; MARGIN-RIGHT: 0px"></FONT>
  <DIV>&nbsp; Hey all,</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp; Ok, maybe I'm just really unco at finding documentation, =
but this=20
  mythical com module for win32...I can't find it for the life of =
me.&nbsp; I am=20
  planning on controlling internet explorer using it (from within a =
python=20
  script).</DIV>
  <DIV>&nbsp; A link to some documentation would be nice.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp; Thanks,</DIV>
  <DIV>&nbsp; Glen.</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0012_01C0D865.1262B850--



From maritza_rodz@hotmail.com  Tue May  8 22:17:28 2001
From: maritza_rodz@hotmail.com (Maritza Rodriguez)
Date: Tue, 08 May 2001 16:17:28 -0500
Subject: [Tutor] 15 puzzle
Message-ID: <F95WiGtXsL1c00goZol000000ac@hotmail.com>

Thank you for responding.  I am confused, though.  I understand the first 
part about adding a new method to check the table against the solution.  
"Solution = ..." : this of,course goes under the class, right?  Now we 
define solved(self); that makes sense.  OK when we define 
is_it_really_solved(self), we are simply saying that if the puzzle is solved 
it will return the dialog stated and if it is not solved it will return the 
other dialog stated, right?  The next definition is where I got confused.  
"makebuttons(self,w)"; what is this part of the program saying?  What do you 
mean by blocks and keeping track of the buttons and making commands for 
them?  Are you referring to the number buttons?  What does this do to them?  
Is this the part that moves these buttons?
Please excuse me for asking so many questions.  I am totally new to 
programming, especially python.  Please help.

Maritza


>From: "Michael P. Reilly" <arcege@dsl092-074-184.bos1.dsl.speakeasy.net>
>Reply-To: arcege@speakeasy.net
>To: maritza_rodz@hotmail.com (Maritza Rodriguez)
>CC: tutor@python.org
>Subject: Re: [Tutor] 15 puzzle
>Date: Tue, 8 May 2001 15:58:40 -0400 (EDT)
>
>Maritza Rodriguez wrote
> >
> > This is what I have so far.  The program now exits the program by 
>pressing
> > the "DONE" button, which is great.  But, what I also want that button to 
>do
> > is tell you whether or not you have a solution to the puzzle, just 
>before it
> > exits.  Of course, first I have to figure out how to scramble the 
>buttons in
> > order to have an actual game going.  Any suggestions?
> >
> > Maritza
> >
> > import sys
> > from Tkinter import *
> >
> > def die(event=0):
> >     sys.exit(0)
> >
> > class Puzzle:
> >     def __init__(self,w):
> >         
>names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14",
> >         "15"," "]
> >         n = 0
> >         for i in range(4):
> >             for j in range(4):
> >                 item1=Button(w,text=names[n])
> >                 item1.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item2=Button(w,text=names[n])
> >                 item2.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item3=Button(w,text=names[n])
> >                 item3.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item4=Button(w,text=names[n])
> >                 item4.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item5=Button(w,text=names[n])
> >                 item5.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item6=Button(w,text=names[n])
> >                 item6.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item7=Button(w,text=names[n])
> >                 item7.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item8=Button(w,text=names[n])
> >                 item8.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item9=Button(w,text=names[n])
> >                 item9.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item10=Button(w,text=names[n])
> >                 item10.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item11=Button(w,text=names[n])
> >                 item11.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item12=Button(w,text=names[n])
> >                 item12.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item13=Button(w,text=names[n])
> >                 item13.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item14=Button(w,text=names[n])
> >                 item14.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item15=Button(w,text=names[n])
> >                 item15.grid(row=i,column=j,sticky=E+W+N+S)
> >                 n = n+1
> >
> >
> > 	f = Frame(w)
> >         b1=Button(f,text="SCRAMBLE")
> >         b2=Button(f,text="DONE")
> >         if "DONE":
> >             b2["command"] = die
> >         b1.pack(side=LEFT)
> >         b2.pack(side=RIGHT)
> >         f.grid(row=4,column=0,columnspan=4)
>
>Add a new method to check the table against the "solution".
>
>     solution = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
>       "12", "13", "14", "15", " "]
>     # I would even make 'self.names = self.solution[:]' in __init__
>
>     def solved(self):
>         return self.names == self.solution
>
>Then make a method to handle the button presses:
>     def is_it_really_solved(self):
>         import Dialog
>         if self.solved:
>           Dialog.Dialog(self, {'title': 'Congratulations',
>                          'text': 'You solved the puzzle!',
>                          'bitmap': Dialog.DIALOG_ICON,
>                          'default': 0,
>                          'strings': ('Ok',))
>           self.quit()  # stop Tkinter
>         else:
>           Dialog.Dialog(self, {'title': 'Sorry',
>                                'text': 'Keep trying',
>                                'bitmap': Dialog.DIALOG_ICON,
>                                'default': 0,
>                                'strings': ('Ok',))
>[There are better dialog widgets, but this is one I remember without much
>reference material right now... and it works]
>
>Then for the blocks, you just need to keep track of the buttons, and
>make commands for them:
>     def makebuttons(self, w):
>         self.buttons = [None] * 16
>         for i in range(4):
>             for j in range(4):
>                 pos = i + j * 4
>                 name = self.names[pos]
>                 b = Button(w, text=name,
>                     command=lambda self=self, pos=(i, j): 
>self.buttonpress)
>                 self.buttons[pos] = b
>
>     def buttonpress(self, position):
>         (i, j) = pos
>         # find which surrounding button is "blank" and change around
>         # self.names and the text label for the proper buttons in
>         # self.buttons
>         # [Leave this as an exercise for you :)]
>
> >
> > root=Tk()
> >
> >
> > gr=Toplevel(root)
> > gr.title("15-PUZZLE")
> > grc = Puzzle (gr)
> >
> >
> > root.withdraw()
> > root.mainloop()
> >
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at http://explorer.msn.com
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
>--
>+----------------------------------+-----------------------------------+
>| Michael P. Reilly                | arcege@speakeasy.net              |
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From maritza_rodz@hotmail.com  Tue May  8 22:18:05 2001
From: maritza_rodz@hotmail.com (Maritza Rodriguez)
Date: Tue, 08 May 2001 16:18:05 -0500
Subject: [Tutor] 15 puzzle
Message-ID: <F226Ln5U9T3TGJ2TUSz000000b8@hotmail.com>

Thank you for responding.  I am confused, though.  I understand the first 
part about adding a new method to check the table against the solution.  
"Solution = ..." : this of,course goes under the class, right?  Now we 
define solved(self); that makes sense.  OK when we define 
is_it_really_solved(self), we are simply saying that if the puzzle is solved 
it will return the dialog stated and if it is not solved it will return the 
other dialog stated, right?  The next definition is where I got confused.  
"makebuttons(self,w)"; what is this part of the program saying?  What do you 
mean by blocks and keeping track of the buttons and making commands for 
them?  Are you referring to the number buttons?  What does this do to them?  
Is this the part that moves these buttons?
Please excuse me for asking so many questions.  I am totally new to 
programming, especially python.  Please help.

Maritza


>From: "Michael P. Reilly" <arcege@dsl092-074-184.bos1.dsl.speakeasy.net>
>Reply-To: arcege@speakeasy.net
>To: maritza_rodz@hotmail.com (Maritza Rodriguez)
>CC: tutor@python.org
>Subject: Re: [Tutor] 15 puzzle
>Date: Tue, 8 May 2001 15:58:40 -0400 (EDT)
>
>Maritza Rodriguez wrote
> >
> > This is what I have so far.  The program now exits the program by 
>pressing
> > the "DONE" button, which is great.  But, what I also want that button to 
>do
> > is tell you whether or not you have a solution to the puzzle, just 
>before it
> > exits.  Of course, first I have to figure out how to scramble the 
>buttons in
> > order to have an actual game going.  Any suggestions?
> >
> > Maritza
> >
> > import sys
> > from Tkinter import *
> >
> > def die(event=0):
> >     sys.exit(0)
> >
> > class Puzzle:
> >     def __init__(self,w):
> >         
>names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14",
> >         "15"," "]
> >         n = 0
> >         for i in range(4):
> >             for j in range(4):
> >                 item1=Button(w,text=names[n])
> >                 item1.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item2=Button(w,text=names[n])
> >                 item2.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item3=Button(w,text=names[n])
> >                 item3.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item4=Button(w,text=names[n])
> >                 item4.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item5=Button(w,text=names[n])
> >                 item5.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item6=Button(w,text=names[n])
> >                 item6.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item7=Button(w,text=names[n])
> >                 item7.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item8=Button(w,text=names[n])
> >                 item8.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item9=Button(w,text=names[n])
> >                 item9.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item10=Button(w,text=names[n])
> >                 item10.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item11=Button(w,text=names[n])
> >                 item11.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item12=Button(w,text=names[n])
> >                 item12.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item13=Button(w,text=names[n])
> >                 item13.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item14=Button(w,text=names[n])
> >                 item14.grid(row=i,column=j,sticky=E+W+N+S)
> >
> >                 item15=Button(w,text=names[n])
> >                 item15.grid(row=i,column=j,sticky=E+W+N+S)
> >                 n = n+1
> >
> >
> > 	f = Frame(w)
> >         b1=Button(f,text="SCRAMBLE")
> >         b2=Button(f,text="DONE")
> >         if "DONE":
> >             b2["command"] = die
> >         b1.pack(side=LEFT)
> >         b2.pack(side=RIGHT)
> >         f.grid(row=4,column=0,columnspan=4)
>
>Add a new method to check the table against the "solution".
>
>     solution = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
>       "12", "13", "14", "15", " "]
>     # I would even make 'self.names = self.solution[:]' in __init__
>
>     def solved(self):
>         return self.names == self.solution
>
>Then make a method to handle the button presses:
>     def is_it_really_solved(self):
>         import Dialog
>         if self.solved:
>           Dialog.Dialog(self, {'title': 'Congratulations',
>                          'text': 'You solved the puzzle!',
>                          'bitmap': Dialog.DIALOG_ICON,
>                          'default': 0,
>                          'strings': ('Ok',))
>           self.quit()  # stop Tkinter
>         else:
>           Dialog.Dialog(self, {'title': 'Sorry',
>                                'text': 'Keep trying',
>                                'bitmap': Dialog.DIALOG_ICON,
>                                'default': 0,
>                                'strings': ('Ok',))
>[There are better dialog widgets, but this is one I remember without much
>reference material right now... and it works]
>
>Then for the blocks, you just need to keep track of the buttons, and
>make commands for them:
>     def makebuttons(self, w):
>         self.buttons = [None] * 16
>         for i in range(4):
>             for j in range(4):
>                 pos = i + j * 4
>                 name = self.names[pos]
>                 b = Button(w, text=name,
>                     command=lambda self=self, pos=(i, j): 
>self.buttonpress)
>                 self.buttons[pos] = b
>
>     def buttonpress(self, position):
>         (i, j) = pos
>         # find which surrounding button is "blank" and change around
>         # self.names and the text label for the proper buttons in
>         # self.buttons
>         # [Leave this as an exercise for you :)]
>
> >
> > root=Tk()
> >
> >
> > gr=Toplevel(root)
> > gr.title("15-PUZZLE")
> > grc = Puzzle (gr)
> >
> >
> > root.withdraw()
> > root.mainloop()
> >
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at http://explorer.msn.com
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
>--
>+----------------------------------+-----------------------------------+
>| Michael P. Reilly                | arcege@speakeasy.net              |
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From cooler12001@yahoo.com  Tue May  8 23:37:32 2001
From: cooler12001@yahoo.com (Matthews James)
Date: Tue, 8 May 2001 15:37:32 -0700 (PDT)
Subject: [Tutor] having trouble with files!!!please help
Message-ID: <20010508223732.25086.qmail@web11407.mail.yahoo.com>

I am haveing some trouble with trying toget every file
that end's with .01w and then renaming them 
accordingly.

example
16460508.01w

which means 
16:46 for the time
may for the month
08 for the day
01 for the year

i have these things all in one folder,
and i have wrote a program that lets me rename them
like so for the example above
[16:46][MAY][08][01]

but the problem is that i'm want to not have to type
them in but, just tell the program what folder they
are in, then it will do the rest

here is the code
#####################################################
import os

months =
{'01':'[JAN]','02':'[FEB]','03':'[MAR]','04':'[APR]','05':'[MAY]',\
         
'06':'[JUN]','07':'[JUL]','08':'[AUG]','09':'[SEP]','10':'[OCT]',\
          '11':'[NOV]','12':'[DEC]'}


def mk_keylog(filename):
    '''(filename)-=> name of the keylog! file
    This Function will rename and move the keylog!
    files to a closer temp folder'''
    times = filename

    time = '['+times[0:2]+'.'+times[2:4]+']'
    month = times[4:6]
    day = '['+times[6:8]+']'
    year = '['+times[9:11]+']'
    mon = months[month]

    print time,
    print months[month],
    print day,
    print year

    if not os.path.isdir('C:\\TEMP\\sys.admir'):
        os.mkdir('C:\\TEMP\\sys.admir')
   
os.rename('C:\\WINDOWS\\TEMP\\'+filename,'C:\\TEMP\\sys.admir\\'+time+mon+day+year)


print '-'*40
print ' '*13,'keylog!Partner',' '*13
print '-'*40
print
print
print
filename=raw_input('File Name:')
mk_keylog(filename)
#####################################################

thank you

James

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/


From maritza_rodz@hotmail.com  Tue May  8 23:48:56 2001
From: maritza_rodz@hotmail.com (Maritza Rodriguez)
Date: Tue, 08 May 2001 17:48:56 -0500
Subject: [Tutor] 15 puzzle
Message-ID: <F41blZz02H67yRLVbND000001af@hotmail.com>

Here is what I have for my "15 Puzzle" program.  The "EXIT" button quits the 
game completely.  The "DONE" button prints the messages that I want 
(although I don't know if it will work once I figure out how to Scramble and 
play the game).  I tried to add a definition for "Scramble", but it is not 
working.  Can anyone help me figure out if I am close or just totally way 
off?  Also, I just cannot figure out how to move the buttons to the blank 
spot.

Maritza

#Sets up the matrix and "DONE", "SCRAMBLE" and "EXIT" buttons
#Quits with "EXIT" button
#DONE button prints "solution" or "nosolution"

import sys
from Tkinter import *
import string
import copy
import whrandom
#import msvcrt
#import array
#from Numeric import*

def die(event=0):
    sys.exit(0)

def solution(f):
    print "Great!  You found a solution!!"

def nosolution(f):
    print "Sorry!  No Solution!!"

names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14",
      "15"," "]
blankrow=3
blankcol=3

def Scramble(f):
    pass
    acpy = list(names)
    for x in range(1,16):
        sizeofacpy = len(acpy)-1
        location = whrandom.randint(0,sizeofacpy)
        names[x] = acpy[location]
        del acpy[location]
    offs = names.index(" ")
    blankrow=offs/4
    blankcol=offs%4

def __init__(self,w):
    n = 0
    for i in range(4):
        for j in range(4):
            item1=Button(w,text=names[n])
            item1.grid(row=i,column=j,sticky=E+W+N+S)

            item2=Button(w,text=names[n])
            item2.grid(row=i,column=j,sticky=E+W+N+S)

            item3=Button(w,text=names[n])
            item3.grid(row=i,column=j,sticky=E+W+N+S)

            item4=Button(w,text=names[n])
            item4.grid(row=i,column=j,sticky=E+W+N+S)

            item5=Button(w,text=names[n])
            item5.grid(row=i,column=j,sticky=E+W+N+S)

            item6=Button(w,text=names[n])
            item6.grid(row=i,column=j,sticky=E+W+N+S)

            item7=Button(w,text=names[n])
            item7.grid(row=i,column=j,sticky=E+W+N+S)

            item8=Button(w,text=names[n])
            item8.grid(row=i,column=j,sticky=E+W+N+S)

            item9=Button(w,text=names[n])
            item9.grid(row=i,column=j,sticky=E+W+N+S)

            item10=Button(w,text=names[n])
            item10.grid(row=i,column=j,sticky=E+W+N+S)

            item11=Button(w,text=names[n])
            item11.grid(row=i,column=j,sticky=E+W+N+S)

            item12=Button(w,text=names[n])
            item12.grid(row=i,column=j,sticky=E+W+N+S)

            item13=Button(w,text=names[n])
            item13.grid(row=i,column=j,sticky=E+W+N+S)

            item14=Button(w,text=names[n])
            item14.grid(row=i,column=j,sticky=E+W+N+S)

            item15=Button(w,text=names[n])
            item15.grid(row=i,column=j,sticky=E+W+N+S)
            n = n+1

    f = Frame(w)
    b1=Button(f,text="SCRAMBLE")
    b1.bind("<Button>", Scramble)
    b2=Button(f,text="DONE")
    if names == 
["1","2","3","4","5","6","7","8","9","10","11","12","13","14",
    "15"," "]: b2.bind("<Button>", solution)
    else:  b2.bind("<Button>", nosolution)
    b1.pack(side=LEFT)
    b2.pack(side=RIGHT)
    f.grid(row=4,column=0,columnspan=4)

    g = Frame(w)
    b3=Button(g,text="EXIT")
    if "EXIT":
        b3["command"] = die
    b3.pack(side=LEFT)
    g.grid(row=5,column=0,columnspan=5)

root=Tk()


gr=Toplevel(root)
gr.title("15-PUZZLE")
grc = Puzzle (gr)

root.withdraw()
root.mainloop()


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



From toodles@yifan.net  Wed May  9 01:25:12 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Wed, 9 May 2001 08:25:12 +0800
Subject: [Tutor] having trouble with files!!!please help
In-Reply-To: <20010508223732.25086.qmail@web11407.mail.yahoo.com>
Message-ID: <FPEHJJPEEOIPMAHOADBKAEFECDAA.toodles@yifan.net>

Hi James,

This should be what you're looking for:

import os

>     if not os.path.isdir('C:\\TEMP\\sys.admir'):
>         os.mkdir('C:\\TEMP\\sys.admir')

files=os.listdir('C:\\TEMP\\')	#get list of files
for file in files:
	if file[-4:]=='.01w':	#test whether it ends in .01w
	> os.rename('C:\\WINDOWS\\TEMP\\'+file,'C:\\TEMP\\sys.admir\\'+	#do the
rest
	> time+mon+day+year)

Obviously this isn't going to work, you need to put in the appropriate
place. I'm a bit rushed, I hope I didn't make any errors, gotta go to
school!

Hope it helps,

Andrew

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Matthews James
> Sent: Wednesday, 9 May 2001 6:38 AM
> To: tutor@python.org
> Subject: [Tutor] having trouble with files!!!please help
>
>
> I am haveing some trouble with trying toget every file
> that end's with .01w and then renaming them
> accordingly.
>
> example
> 16460508.01w
>
> which means
> 16:46 for the time
> may for the month
> 08 for the day
> 01 for the year
>
> i have these things all in one folder,
> and i have wrote a program that lets me rename them
> like so for the example above
> [16:46][MAY][08][01]
>
> but the problem is that i'm want to not have to type
> them in but, just tell the program what folder they
> are in, then it will do the rest
>
> here is the code
> #####################################################
> import os
>
> months =
> {'01':'[JAN]','02':'[FEB]','03':'[MAR]','04':'[APR]','05':'[MAY]',\
>
> '06':'[JUN]','07':'[JUL]','08':'[AUG]','09':'[SEP]','10':'[OCT]',\
>           '11':'[NOV]','12':'[DEC]'}
>
>
> def mk_keylog(filename):
>     '''(filename)-=> name of the keylog! file
>     This Function will rename and move the keylog!
>     files to a closer temp folder'''
>     times = filename
>
>     time = '['+times[0:2]+'.'+times[2:4]+']'
>     month = times[4:6]
>     day = '['+times[6:8]+']'
>     year = '['+times[9:11]+']'
>     mon = months[month]
>
>     print time,
>     print months[month],
>     print day,
>     print year
>
>     if not os.path.isdir('C:\\TEMP\\sys.admir'):
>         os.mkdir('C:\\TEMP\\sys.admir')
>
> os.rename('C:\\WINDOWS\\TEMP\\'+filename,'C:\\TEMP\\sys.admir\\'+t
> ime+mon+day+year)
>
>
> print '-'*40
> print ' '*13,'keylog!Partner',' '*13
> print '-'*40
> print
> print
> print
> filename=raw_input('File Name:')
> mk_keylog(filename)
> #####################################################
>
> thank you
>
> James
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From kstoner@netins.net  Wed May  9 01:26:46 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Tue, 8 May 2001 19:26:46 -0500
Subject: [Tutor] special methods
Message-ID: <000c01c0d81e$bbc8ee60$5552b1cf@oemcomputer>

This is a multi-part message in MIME format.

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

Hi all,

In plain English, what are special methods?

-Cameron

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>In plain English, what are special=20
methods?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-Cameron</FONT></DIV></BODY></HTML>

------=_NextPart_000_0009_01C0D7F4.D23BCB60--



From arcege@speakeasy.net  Wed May  9 02:37:06 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Tue, 8 May 2001 21:37:06 -0400 (EDT)
Subject: [Tutor] special methodsy
In-Reply-To: <000c01c0d81e$bbc8ee60$5552b1cf@oemcomputer> from "Katharine Stoner" at May 08, 2001 07:26:46 PM
Message-ID: <200105090137.f491b6T01003@dsl092-074-184.bos1.dsl.speakeasy.net>

Katharine Stoner wrote
> In plain English, what are special methods?
> 
> -Cameron

Methods that are not called directly, but by other means.  Many are called
by operators in the language, but there are others as well.  They are all
surrounded by double underscores.  The most used is probably "__init__".

>>> class A:
...   def __init__(self, num):  # called by the instance constructor
...     self.num = num
...   def __repr__(self):       # called by `inst` and repr(s)
...     return `self.num`
...   def __str__(self):        # called by str() and print s
...     return str(self.num)
...   def __sub__(self, other): # called by A(n) - 3
...     return A(self.num - other)
...   def __rsub__(self, other): # called by 3 - A(n) [being deprecated]
...     return A(other - self.num)
...   def __cmp__(self, other):
...     return cmp(self.num, other)
...

The last one is called by all the comparison operators (==, !=, <>, <,
<=, >, >=).  In Python 2.1, they now have new special methods for each
of these.

  -Arcege

References:
Python Language Reference, 3.3 Special method names
  <URL: http://www.python.org/doc/current/ref/specialnames.html>

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From joker@aol.com  Wed May  9 04:03:51 2001
From: joker@aol.com (joker@aol.com)
Date: Tue, 8 May 2001 23:03:51 -0400 (EDT)
Subject: [Tutor] Hi
Message-ID: <200105090303.XAA06961@mclean.mail.mindspring.net>

Hi


From joker@aol.com  Wed May  9 08:55:17 2001
From: joker@aol.com (joker@aol.com)
Date: Wed, 9 May 2001 03:55:17 -0400 (EDT)
Subject: [Tutor] Hi
Message-ID: <200105090755.DAA05070@smtp6.mindspring.com>

Hi


From NHYTRO@compuserve.com  Wed May  9 09:07:05 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Wed, 9 May 2001 04:07:05 -0400
Subject: [Tutor] Expression matching
Message-ID: <200105090407_MC2-D049-670E@compuserve.com>

Hi! could someone help me with my Regular expression? I=B4m trying to mat=
ch
all occurring instances of the "<img>" tag in a big chunk of HTML.

## my code
import re
aa =3D '<span>ff<td><img src>sasa<b><img src=3D"ksksk.jpg">nn<br>blah<img=

src=3D"C:\\test\test.jpg>"'
imagematch =3D re.compile('<img src=3D".*>')
print imagematch.match(aa)  ###  results in 'None'
## another try
testmatch =3D re.compile('<img?\s+.*>')
print testmatch.match(aa) ### results also in 'None'
#
### end code ###

I=B4ve read the docs on RegExs on the Python Site, it was a bit terse for=
 me,
there were=B4nt too many real-life examples there.


Thanks


Sharriff



From scarblac@pino.selwerd.nl  Wed May  9 09:09:11 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 10:09:11 +0200
Subject: [Tutor] Hi
In-Reply-To: <200105090755.DAA05070@smtp6.mindspring.com>; from joker@aol.com on Wed, May 09, 2001 at 03:55:17AM -0400
References: <200105090755.DAA05070@smtp6.mindspring.com>
Message-ID: <20010509100911.A4942@pino.selwerd.nl>

On  0, joker@aol.com wrote:
> 
> Hi

Hi. Your message arrived to the Tutor list. Twice.
But it didn't contain much...

(sending this back to you and to the list, so you'll get two copies)

-- 
Remco Gerlich


From dyoo@hkn.eecs.berkeley.edu  Wed May  9 09:34:48 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 9 May 2001 01:34:48 -0700 (PDT)
Subject: [Tutor] Expression matching
In-Reply-To: <200105090407_MC2-D049-670E@compuserve.com>
Message-ID: <Pine.LNX.4.21.0105090132120.12076-100000@hkn.eecs.berkeley.edu>

On Wed, 9 May 2001, Sharriff Aina wrote:

> Hi! could someone help me with my Regular expression? I=B4m trying to mat=
ch
> all occurring instances of the "<img>" tag in a big chunk of HTML.
>=20
> ## my code
> import re
> aa =3D '<span>ff<td><img src>sasa<b><img src=3D"ksksk.jpg">nn<br>blah<img
> src=3D"C:\\test\test.jpg>"'
> imagematch =3D re.compile('<img src=3D".*>')
> print imagematch.match(aa)  ###  results in 'None'
> ## another try
> testmatch =3D re.compile('<img?\s+.*>')
> print testmatch.match(aa) ### results also in 'None'

Try using testmatch.search(): there's a difference!

    1.  Matching can only work if what we're looking for is at the very
beginning.

    2.  Searching can start anywhere within the string.

The documentation mentions this briefly here:

    http://python.org/doc/current/lib/matching-searching.html

but it's always a gotcha when you start off with Python regular
expressions.  Try search(), and you should get better results.




From NHYTRO@compuserve.com  Wed May  9 09:44:41 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Wed, 9 May 2001 04:44:41 -0400
Subject: [Tutor] Expression matching, Thanks Danny!
Message-ID: <200105090444_MC2-D040-3B18@compuserve.com>

Best regards



Sharriff


From lonetwin@yahoo.com  Wed May  9 10:08:18 2001
From: lonetwin@yahoo.com (steve)
Date: Wed, 9 May 2001 14:38:18 +0530
Subject: [Tutor] Expression matching
In-Reply-To: <Pine.LNX.4.21.0105090132120.12076-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105090132120.12076-100000@hkn.eecs.berkeley.edu>
Message-ID: <01050914381801.07097@mercury.in.cqsl.com>

Hi there,
 Just a comment, since Daniel already has answered u r question

did U have a look at the regular ex. HOWTO? - it helped me a lot, and yes=
 I=20
too think the re-module doc in the std. module reference is terse.

Peace
Steve

On Wednesday 09 May 2001 14:04, you wrote:
> On Wed, 9 May 2001, Sharriff Aina wrote:
> > Hi! could someone help me with my Regular expression? I=B4m trying to=
 match
> > all occurring instances of the "<img>" tag in a big chunk of HTML.
> >
> > ## my code
> > import re
> > aa =3D '<span>ff<td><img src>sasa<b><img src=3D"ksksk.jpg">nn<br>blah=
<img
> > src=3D"C:\\test\test.jpg>"'
> > imagematch =3D re.compile('<img src=3D".*>')
> > print imagematch.match(aa)  ###  results in 'None'
> > ## another try
> > testmatch =3D re.compile('<img?\s+.*>')
> > print testmatch.match(aa) ### results also in 'None'
>
> Try using testmatch.search(): there's a difference!
>
>     1.  Matching can only work if what we're looking for is at the very
> beginning.
>
>     2.  Searching can start anywhere within the string.
>
> The documentation mentions this briefly here:
>
>     http://python.org/doc/current/lib/matching-searching.html
>
> but it's always a gotcha when you start off with Python regular
> expressions.  Try search(), and you should get better results.
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
"Unfortunately, those people who have nothing better to do than post on t=
he
Internet all day long are rarely the ones who have the most insights."
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From scarblac@pino.selwerd.nl  Wed May  9 10:05:07 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 11:05:07 +0200
Subject: [Tutor] Expression matching
In-Reply-To: <200105090407_MC2-D049-670E@compuserve.com>; from NHYTRO@compuserve.com on Wed, May 09, 2001 at 04:07:05AM -0400
References: <200105090407_MC2-D049-670E@compuserve.com>
Message-ID: <20010509110507.A5944@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:
> Hi! could someone help me with my Regular expression? I´m trying to match
> all occurring instances of the "<img>" tag in a big chunk of HTML.

Danny already showed you one problem (you also forgot to escape the \ in the
second one, should be \\), but parsing HTML with regexen is always a mess.
What if there's a > in the filename, or in the alt tag? Also, you must make
sure your expression doesn't match greedily, otherwise it will match the
whole string between <img src= and the *last* > of the string. I forgot how
to do that, I manage to avoid regular expressions almost all the time :).

If you're going to parse HTML, use htmllib. This snippet should find all
img tags:

import htmllib

class ImgFinder(htmllib.HTMLParser):
   def __init__(self):
      # Normal HTMLParser takes a 'formatter' argument but we don't need it
      htmllib.HTMLParser.__init__(self, None)
   def handle_image(self, source, alt, *args):
      # *args holds "ismap", "align", "width" and "height", if available,
      # but we ignore those here
      print "Found an image!"
      print "Source =", source, "Alt =", alt

finder = ImgFinder()
finder.feed(aa)   # Feed in the string, it should find the images

-- 
Remco Gerlich


From alan.gauld@bt.com  Wed May  9 10:28:54 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 9 May 2001 10:28:54 +0100
Subject: [Tutor] 15 puzzle
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D752@mbtlipnt02.btlabs.bt.co.uk>

> 1-15 in order from left to right and a blank space after the 
> 15.  

It would probably be easier to use a blank button instead. 
Choose a siunken relief too.

Then to "move" a tile you just swap the text attributes 
and relief settings.

swap(blankTile, movingTile):
   blankTile.configure(text=movingTile['text'], relief=SUNKEN)
   movingTile.configure(text=" ", relief=RAISED)

I might have the wrong relief settings but something 
like that should work.

Alan G.


From alan.gauld@bt.com  Wed May  9 10:35:37 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 9 May 2001 10:35:37 +0100
Subject: [Tutor] 15 puzzle
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D753@mbtlipnt02.btlabs.bt.co.uk>

> Of course, first I have to figure out how to scramble 
> the buttons in order to have an actual game going.  

Create a list of numbers
generate a random index into the list using randint()
move that number into a new list and delete from the original.

Something like:

baselist = newList = []
for i in range(15): baseList.append(str(i))
length = len(vbaseList)

def scramble:
  index = randint(length)
  newlist.append(baseList[index])
  del baselist[index]
  length = length - 1

Alan G


From scarblac@pino.selwerd.nl  Wed May  9 10:50:22 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 11:50:22 +0200
Subject: [Tutor] 15 puzzle
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D753@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Wed, May 09, 2001 at 10:35:37AM +0100
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D753@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20010509115022.A7517@pino.selwerd.nl>

On  0, alan.gauld@bt.com wrote:
> > Of course, first I have to figure out how to scramble 
> > the buttons in order to have an actual game going.  
> 
> Create a list of numbers
> generate a random index into the list using randint()
> move that number into a new list and delete from the original.
> 
> Something like:
> 
> baselist = newList = []

Oops. Assign by reference, remember?

> for i in range(15): baseList.append(str(i))

So this appends to both. (And later on as well).

Use random.shuffle, i.e.

import random
buttons = range(15)
random.shuffle(buttons)
print buttons

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Wed May  9 11:02:09 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 12:02:09 +0200
Subject: [Tutor] 15 puzzle
In-Reply-To: <20010509115022.A7517@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Wed, May 09, 2001 at 11:50:22AM +0200
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D753@mbtlipnt02.btlabs.bt.co.uk> <20010509115022.A7517@pino.selwerd.nl>
Message-ID: <20010509120209.A7853@pino.selwerd.nl>

On  0, Remco Gerlich <scarblac@pino.selwerd.nl> wrote:
> On  0, alan.gauld@bt.com wrote:
> > baselist = newList = []
> 
> Oops. Assign by reference, remember?
> 
> > for i in range(15): baseList.append(str(i))
> 
> So this appends to both. (And later on as well).

Actually, it does still work, since the numbers are added to the end and
then ignored. But it's very confusing, and probably not intended :)

(I forgot to turn the numbers into strings, so should be

buttons = map(str, range(15))
random.shuffle(buttons)
)
-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Wed May  9 11:12:33 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 12:12:33 +0200
Subject: [Tutor] Expression matching
In-Reply-To: <200105090602_MC2-D04C-78AE@compuserve.com>; from NHYTRO@compuserve.com on Wed, May 09, 2001 at 06:02:01AM -0400
References: <200105090602_MC2-D04C-78AE@compuserve.com>
Message-ID: <20010509121233.A8055@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:
> this code matches non-greedily, my problem is, strings like "c:\ten\ten"
> are matched and returned as :
> '"c:\011en\011en.jpg"'
> how can I get rid of the cryptical urls?

That's just the way you enter the string - \t means a tab character, and
\011 is another way to spell it.

Try in the interpreter:
>>> print "bla\tbla"
bla     bla

If you want to enter a \ in a string, you must write is at \\.

Another option is to use raw strings, they start with an r, and don't need
escaped backslashes:

>>> print r"bla\tbla"
bla\tbla

You also needed \\s in the second regex that you had in the first post of
the thread, for the same reason.

All of this won't be a problem if you read in the HTML from some file,
instead of writing it as a literal string in Python.

-- 
Remco Gerlich


From ppathiyi@cisco.com  Wed May  9 11:34:16 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Wed, 9 May 2001 16:04:16 +0530
Subject: [Tutor] Number of lines in a file
Message-ID: <06f501c0d873$98cb41b0$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

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

Hi,

    How do i find the number of lines in a file (On UNIX)?

    tell() returns the position in terms of characters, right ?

TIA,
Praveen.
  =20

------=_NextPart_000_06F2_01C0D8A1.B2637290
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; How do i find the =
number of=20
lines in a file (On UNIX)?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;tell() returns =
the position=20
in terms of characters, right ?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;</FONT></DIV></BODY></HTML>

------=_NextPart_000_06F2_01C0D8A1.B2637290--



From scarblac@pino.selwerd.nl  Wed May  9 11:52:32 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 12:52:32 +0200
Subject: [Tutor] Number of lines in a file
In-Reply-To: <06f501c0d873$98cb41b0$37ef87c0@ppathiyipc>; from ppathiyi@cisco.com on Wed, May 09, 2001 at 04:04:16PM +0530
References: <06f501c0d873$98cb41b0$37ef87c0@ppathiyipc>
Message-ID: <20010509125232.A9098@pino.selwerd.nl>

On  0, Praveen Pathiyil <ppathiyi@cisco.com> wrote:
>     How do i find the number of lines in a file (On UNIX)?

You need to read the whole file and count the number of \n in it. 
A file is just a stream of bytes, UNIX doesn't know what a line is.

wholefile = f.read()
lines = wholefile.count("\n")
if wholefile[-1] != "\n":
    lines = lines+1     # If the file doesn't end with \n, add one

Or, equivalently,
lines = len(f.readlines())

If you don't want to have the whole file in memory at the same time,
use fileinput, readlines with a sizehint, or get Python 2.1 and use
lines = len(f.xreadlines())

>     tell() returns the position in terms of characters, right ?

Yes, your current position.

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Wed May  9 12:46:49 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 13:46:49 +0200
Subject: [Tutor] Expression matching
In-Reply-To: <200105090612_MC2-D04C-793C@compuserve.com>; from NHYTRO@compuserve.com on Wed, May 09, 2001 at 06:12:07AM -0400
References: <200105090612_MC2-D04C-793C@compuserve.com>
Message-ID: <20010509134648.A10336@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:
> I would like to modify the links of the images and substitute them in the
> HTML block, the original links are passed onto a loop that tries to upload
> the images to an FTP server( Whew), that means I would have to store the
> found image links somehow, I have´nt found a function that might help me in
> this direction, any ideas? I know how to FTP the images, its tying all up
> together thats getting to me ( this is gonna be one real resource killer
> CGI script)

Ok, now I've had time to actually try out some thing instead of write from
the top of my head... Forget formatters, they're too complicated, should be
used when you want to get HTML into some writable form.

You want to do three things:
- Find all the image links (specifically, the source attributes)
- Store them
- Output a HTML text with modified image links

The easiest seems to use the parser to find the links, then simply use
.replace() on the strings to change them. I have no idea in what way you
need to modify the strings.

Something like this:

import htmllib, formatter

def modify_link(s):
   # No idea what to do here, I change 'jpg' to 'SPAM' as an example
   return s.replace("jpg","SPAM")

class ImgFinder(htmllib.HTMLParser):
   def __init__(self):
      # Turns out we need at least a dummy formatter anyway
      htmllib.HTMLParser.__init__(self, formatter.NullFormatter)
      self.linklist = [] # We're going to store them in this
   def handle_image(self, source, *rest_of_args):
      self.linklist.append(source)
   def change_html(self, html):
      # Use the linklist and the modify_link function to return new html
      for link in linklist:
         html = html.replace(link, modify_link(link))
      return html


# Use it like this; 'aa' is a string holding a html file

finder = ImgFinder()
finder.feed(aa)

print "Changed html:", finder.change_html(aa)

for link in finder.linklist:
   print "Do something here with", link


-- 
Remco Gerlich


From NHYTRO@compuserve.com  Wed May  9 12:56:03 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Wed, 9 May 2001 07:56:03 -0400
Subject: [Tutor] Expression matching
Message-ID: <200105090756_MC2-D04F-2204@compuserve.com>

Message text written by Remco Gerlich
>You also needed \\s in the second regex that you had in the first post o=
f
the thread, for the same reason.


Thanks Remco! I tried that too, but alas:


import re

htmlblock =3D '<span>ff<td><img src>sasa<b><img src=3D"ksksk.jpg">nn<br>j=
h<img
src=3D"c:\ten\ten">'
imageexpr =3D re.compile('<img?\\s+.*?>') # non-greedy
allimagetags =3D imageexpr.findall(htmlblock)
print allimagetags
>>>['<img src>', '<img src=3D"ksksk.jpg">', '<img src=3D"c:\011en\011en">=
']
## ???


>All of this won't be a problem if you read in the HTML from some file,
instead of writing it as a literal string in Python.
<
Yes I know, a pain, the problem is I=B4m fetching the HTML from an HTML
textfield per CGI in realtime, I=B4ll continue exploring


Sharriff

Thanks


From arcege@speakeasy.net  Wed May  9 13:01:39 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 9 May 2001 08:01:39 -0400 (EDT)
Subject: [Tutor] 15 puzzle
In-Reply-To: <F95WiGtXsL1c00goZol000000ac@hotmail.com> from "Maritza Rodriguez" at May 08, 2001 04:17:28 PM
Message-ID: <200105091201.f49C1dM01636@dsl092-074-184.bos1.dsl.speakeasy.net>

Maritza Rodriguez wrote
> 
> Thank you for responding.  I am confused, though.  I understand the first 
> part about adding a new method to check the table against the solution.  
> "Solution = ..." : this of,course goes under the class, right?  Now we 
> define solved(self); that makes sense.  OK when we define 
> is_it_really_solved(self), we are simply saying that if the puzzle is solved 
> it will return the dialog stated and if it is not solved it will return the 
> other dialog stated, right?  The next definition is where I got confused.  
> "makebuttons(self,w)"; what is this part of the program saying?  What do you 
> mean by blocks and keeping track of the buttons and making commands for 
> them?  Are you referring to the number buttons?  What does this do to them?  
> Is this the part that moves these buttons?
> Please excuse me for asking so many questions.  I am totally new to 
> programming, especially python.  Please help.
> 
> Maritza

Hi, I didn't want to spoil your fun by solving the problem for you, so
I didn't try to fill things out for you.

You are correct, the "is_it_really_solved" routine is to give some
feedback to the user: did I win or not.  It is better to put the actual
test in a separate method in case you need to change how you determine how
it is solved later (or change how self.names is used).  The "solution"
variable because what is called a "class member", it is shared by
all instances, so it is rarely modified in these types of programs.
All these here are defined within the class.

One common way of writing Tkinter programs is to have a method that
creates all the Tk widgets used in the class.  My makebuttons method is
doing that, passing the enclosing widget, w, to place the new ones in.

By keeping track of the "blocks" (buttons), you can modify their text
attributes as they get pressed instead of trying to move them.  But
either way, moving them or changing them, you need to keep track of
the button widgets created so you can do that.

Also, I added (incorrectly I noticed, sorry) a "callback" to the buttons.
A callback is a part of your program called by some library routine that
is not under you control.  In this case, when the button is pressed,
the lambda function is called.. not by any part of your code.

In essence, create buttons with the text from the "names" ("1",
"2", etc.).  Each button registers another method which gets called
when the user presses that button.  The method checks to see if it is
next to the blank space.  If it is, swaps the text in those buttons,
and in the "names" list.  This "simulates" the buttons moving without
going through all the coding.

  -Arcege


-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From scarblac@pino.selwerd.nl  Wed May  9 13:07:09 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 14:07:09 +0200
Subject: [Tutor] Expression matching
In-Reply-To: <200105090756_MC2-D04F-2204@compuserve.com>; from NHYTRO@compuserve.com on Wed, May 09, 2001 at 07:56:03AM -0400
References: <200105090756_MC2-D04F-2204@compuserve.com>
Message-ID: <20010509140709.A11156@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:
> htmlblock = '<span>ff<td><img src>sasa<b><img src="ksksk.jpg">nn<br>jh<img
> src="c:\ten\ten">'
       ^^^^^^^^^^

Those \t's should be \\t. Now they're tab characters.

-- 
Remco Gerlich


From arcege@speakeasy.net  Wed May  9 13:07:09 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 9 May 2001 08:07:09 -0400 (EDT)
Subject: [Tutor] 15 puzzle
In-Reply-To: <20010509115022.A7517@pino.selwerd.nl> from "Remco Gerlich" at May 09, 2001 11:50:22 AM
Message-ID: <200105091207.f49C79001650@dsl092-074-184.bos1.dsl.speakeasy.net>

Remco Gerlich wrote
> Use random.shuffle, i.e.
> 
> import random
> buttons = range(15)
> random.shuffle(buttons)
> print buttons

Which does not exist before Python 2.0.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From alan.gauld@bt.com  Wed May  9 13:16:14 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 9 May 2001 13:16:14 +0100
Subject: [Tutor] 15 puzzle
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D756@mbtlipnt02.btlabs.bt.co.uk>

Remco wrote:
> > Something like:
> > 
> > baselist = newList = []
>
> Oops. Assign by reference, remember?

Oops indeed, good catch.

> Use random.shuffle, i.e.
>
> import random
> buttons = range(15)
> random.shuffle(buttons)

One of the things I love about Python is that I keep discoovering 
new neat features. :-)

One of the things that I hate about Python is I usually discover those 
features *after* I've already reinvented the wheel :-(

Alan G.


From ryanbooz@alumni.psu.edu  Wed May  9 14:05:38 2001
From: ryanbooz@alumni.psu.edu (Ryan Booz)
Date: Wed, 09 May 2001 09:05:38 -0400
Subject: [Tutor] Dates?
Message-ID: <3AF940A2.B5A2D81A@alumni.psu.edu>

Hello all...

I'm trying to get Python to write (in files) and examine dates and times
in programs.  Say for a logging program or to have it parse logs and
write particular output based on dates (or even delete stuff based on
dates).

Anyway, I've tried to work with the time module some and have read
through the "Time access and conversions" in the Python library
reference.  But I can't get any "real" dates to "appear".  I can use the
time() function and get the seconds since epoch... but not matter what I
try to do to get a "readable" date from Python, I get the beginning of
epoch (Dec. 31 1969).  So, my question is, how do I start getting some
real dates that I can use in my programs that are "real"?

Thanks in advance...
Ryan Booz
Tech Coordinator
Belleville Mennonite School



From NHYTRO@compuserve.com  Wed May  9 14:49:29 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Wed, 9 May 2001 09:49:29 -0400
Subject: [Tutor] Expression matching
Message-ID: <200105090949_MC2-D069-740E@compuserve.com>

Thanks a lot Remco! I=B4m pointing  my browser directly to the docs on
htmllib, I=B4ll need the extra know-how to unsderstand your code fully =



Best regards


Sharriff



Message text written by Remco Gerlich
>The easiest seems to use the parser to find the links, then simply use
.replace() on the strings to change them.<



From ppathiyi@cisco.com  Wed May  9 15:13:56 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Wed, 9 May 2001 19:43:56 +0530
Subject: [Tutor] Dates?
References: <3AF940A2.B5A2D81A@alumni.psu.edu>
Message-ID: <075a01c0d892$48f34060$37ef87c0@ppathiyipc>

HI,

You can try the following.

import time

time_log = time.asctime(time.localtime(time.time()))

print time_log 

This will give you  --->
'Wed May  9 09:46:18 2001'

Regards,
Praveen.

----- Original Message ----- 
From: "Ryan Booz" <ryanbooz@alumni.psu.edu>
To: <tutor@python.org>
Sent: Wednesday, May 09, 2001 6:35 PM
Subject: [Tutor] Dates?


> Hello all...
> 
> I'm trying to get Python to write (in files) and examine dates and times
> in programs.  Say for a logging program or to have it parse logs and
> write particular output based on dates (or even delete stuff based on
> dates).
> 
> Anyway, I've tried to work with the time module some and have read
> through the "Time access and conversions" in the Python library
> reference.  But I can't get any "real" dates to "appear".  I can use the
> time() function and get the seconds since epoch... but not matter what I
> try to do to get a "readable" date from Python, I get the beginning of
> epoch (Dec. 31 1969).  So, my question is, how do I start getting some
> real dates that I can use in my programs that are "real"?
> 
> Thanks in advance...
> Ryan Booz
> Tech Coordinator
> Belleville Mennonite School
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



From randrews@planhouse.com  Wed May  9 16:01:02 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Wed, 9 May 2001 10:01:02 -0500
Subject: [Tutor] how to add a comma to the end of each line in a file
Message-ID: <000001c0d898$ddbaa840$de00a8c0@planhouse5>

I feel almost embarassed having to ask this, but I've got several files that
need a comma added to each line, and I'm not sure what the best way to go
about it is. Any suggestions?

Rob



From rick@niof.net  Wed May  9 16:00:49 2001
From: rick@niof.net (Rick Pasotto)
Date: Wed, 9 May 2001 11:00:49 -0400
Subject: [Tutor] 15 puzzle
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D756@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Wed, May 09, 2001 at 01:16:14PM +0100
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D756@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20010509110049.A13769@tc.niof.net>

On Wed, May 09, 2001 at 01:16:14PM +0100, alan.gauld@bt.com wrote:
> Remco wrote:
> 
> > Use random.shuffle, i.e.
> >
> > import random
> > buttons = range(15)
> > random.shuffle(buttons)
> 
> One of the things I love about Python is that I keep discoovering 
> new neat features. :-)
> 
> One of the things that I hate about Python is I usually discover those 
> features *after* I've already reinvented the wheel :-(

random.shuffle() is new. It was not in 1.5.2.

When it is suggested that a new feature be used, it might be a good idea
to mention the fact that it's a new feature. Or is 1.5.2 considered to
be so old now that no one should be using it?

-- 
Thus, there is not a single ill afflicting the nation for which
the government has not voluntarily made itself responsible. Is it
astonishing, then, that each little twinge should be a cause of
revolution?
	-- Frédéric Bastiat (1801-1850)
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From shaleh@valinux.com  Wed May  9 16:08:10 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Wed, 09 May 2001 08:08:10 -0700 (PDT)
Subject: [Tutor] how to add a comma to the end of each line in a file
In-Reply-To: <000001c0d898$ddbaa840$de00a8c0@planhouse5>
Message-ID: <XFMail.20010509080810.shaleh@valinux.com>

On 09-May-2001 Rob Andrews wrote:
> I feel almost embarassed having to ask this, but I've got several files that
> need a comma added to each line, and I'm not sure what the best way to go
> about it is. Any suggestions?
> 

check out the 'fileinput' module.


From scarblac@pino.selwerd.nl  Wed May  9 16:12:53 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 9 May 2001 17:12:53 +0200
Subject: [Tutor] 15 puzzle
In-Reply-To: <20010509110049.A13769@tc.niof.net>; from rick@niof.net on Wed, May 09, 2001 at 11:00:49AM -0400
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D756@mbtlipnt02.btlabs.bt.co.uk> <20010509110049.A13769@tc.niof.net>
Message-ID: <20010509171253.A15834@pino.selwerd.nl>

On  0, Rick Pasotto <rick@niof.net> wrote:
> random.shuffle() is new. It was not in 1.5.2.
> 
> When it is suggested that a new feature be used, it might be a good idea
> to mention the fact that it's a new feature. Or is 1.5.2 considered to
> be so old now that no one should be using it?

Well, I didn't know it was new, I also found out about it only recently.

How old is 2.0 now? 8 months? We can't keep giving 1.5.2 solutions forever
when the 2.x series has so much cool and useful stuff...

We should have some sort of consensus on it on the Tutor list though.
For now I usually mention the old way to do it, but in a few months I'll
probably stop that, unless people explicitly mention it...

-- 
Remco Gerlich


From bsass@freenet.edmonton.ab.ca  Wed May  9 17:16:31 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Wed, 9 May 2001 10:16:31 -0600 (MDT)
Subject: [Tutor] Number of lines in a file
In-Reply-To: <06f501c0d873$98cb41b0$37ef87c0@ppathiyipc>
Message-ID: <Pine.LNX.4.33.0105090935580.13306-100000@bms>

On Wed, 9 May 2001, Praveen Pathiyil wrote:

> Hi,
>
>     How do i find the number of lines in a file (On UNIX)?

unix:
You could open the file and count the number of lines yourself, or use
a standard unix utility (wc), e.g.,

>>> import os
>>> fname = ".xsession-errors"
>>> fo = os.popen("wc -l " + fname)
>>> outp = fo.readlines()
>>> outp
['     88 .xsession-errors\n']
>>> fo.close()

If you are looking into a small number of small files, and want to be
portable without doing special cases for each platform, doing it
yourself may be best.

If you have lots or large files to look into, or want more than just a
line count, using "wc" and parsing the output is probably the way to
go.


-Bruce



From arcege@speakeasy.net  Wed May  9 17:25:24 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 9 May 2001 12:25:24 -0400 (EDT)
Subject: [Tutor] 15 puzzle
In-Reply-To: <20010509171253.A15834@pino.selwerd.nl> from "Remco Gerlich" at May 09, 2001 05:12:53 PM
Message-ID: <200105091625.f49GPPb02728@dsl092-074-184.bos1.dsl.speakeasy.net>

Remco Gerlich wrote
> 
> On  0, Rick Pasotto <rick@niof.net> wrote:
> > random.shuffle() is new. It was not in 1.5.2.
> > 
> > When it is suggested that a new feature be used, it might be a good idea
> > to mention the fact that it's a new feature. Or is 1.5.2 considered to
> > be so old now that no one should be using it?
> 
> Well, I didn't know it was new, I also found out about it only recently.

Some of the things in 2.x are fairly subtle.  For example, the __rcmp__
special method is no longer supported in 2.1; which means that "self"
might not be what you think it is in __cmp__(self, other).  This is
likely going to break some code, but...

> How old is 2.0 now? 8 months? We can't keep giving 1.5.2 solutions forever
> when the 2.x series has so much cool and useful stuff...

Considering the following:
* that companies ARE using Python (and we want them to) and many are
  using it within products (mine is for example);
* that entities are not going to changed releases of "vendor" software
  simply because a new release comes about, that the companies with
  products out there with older releases can only be replaced when the
  customer wishes;
* that a lot of the user systems (the new RedHat 7.1 still ships with
  Python 1.5.2), web hosting sites and other services that non-commercial
  users here on the tutor list are likely to be using are going to have
  installed 1.x releases;
* that some are still using 1.4 (especially for a pure DOS version
  that was out there).  And one person here in this list in the last
  couple of month was saying they were using 1.3 (which is from '95-'96
  time-frame).

This will be the case for likely the next 6-18 months (which is typical
for such open, grass-roots software development).

> We should have some sort of consensus on it on the Tutor list though.
> For now I usually mention the old way to do it, but in a few months I'll
> probably stop that, unless people explicitly mention it...

Speaking for myself, I think the mentors should be giving out the
information that is the best common denominator, with alternatives for
the others (things only in 2.x or only 1.x, things broken in one (like
os.path.walk broken in 2.0, fixed in 2.1).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From bill_tolbert@bigfoot.com  Wed May  9 18:20:00 2001
From: bill_tolbert@bigfoot.com (Bill Tolbert)
Date: Wed, 9 May 2001 13:20:00 -0400 (EDT)
Subject: [Tutor] exception handling
Message-ID: <Pine.A41.4.21L1.0105091246500.68912-100000@login8.isis.unc.edu>

Thanks for the help on my serial connection problem. Things are working
great now.

I'm confused about exception handling. I'd like to wrap up some functions
with a generic catch-all handler. In the pseudo code below, I handle
specific errors in dosomething and dosomethingelse. How do I avoid falling
into the except for unhandled errors? 

for file in filelist:
  try:
    dosomething(file) 		#errors handled 
    doseomthingelse(file) 	#errors handled
  except:			#avoid this unless it really is unhandled
    print "unhandled error"
    traceback.print_exc()
  file.close()


Thanks,

Bil



From bsass@freenet.edmonton.ab.ca  Wed May  9 19:51:42 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Wed, 9 May 2001 12:51:42 -0600 (MDT)
Subject: [Tutor] Dates?
In-Reply-To: <075a01c0d892$48f34060$37ef87c0@ppathiyipc>
Message-ID: <Pine.LNX.4.33.0105091246570.13306-100000@bms>

On Wed, 9 May 2001, Praveen Pathiyil wrote:
> You can try the following.
>
> import time
>
> time_log = time.asctime(time.localtime(time.time()))
>
> print time_log
>
> This will give you  --->
> 'Wed May  9 09:46:18 2001'

[dedicated to Remco :) ]

With python 2.1...
>>> import time
>>> time.ctime()
'Wed May  9 12:36:34 2001'


- Bruce



From dyoo@hkn.eecs.berkeley.edu  Wed May  9 21:59:44 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 9 May 2001 13:59:44 -0700 (PDT)
Subject: [Tutor] how to add a comma to the end of each line in a file
In-Reply-To: <000001c0d898$ddbaa840$de00a8c0@planhouse5>
Message-ID: <Pine.LNX.4.21.0105091356050.23492-100000@hkn.eecs.berkeley.edu>

On Wed, 9 May 2001, Rob Andrews wrote:

> I feel almost embarassed having to ask this, but I've got several files that
> need a comma added to each line, and I'm not sure what the best way to go
> about it is. Any suggestions?

One funny way we can do this is to suck the whole string in from each
file, and replace the '\n' newline sequence with ',\n' instead.  
string.replace() should work well for this purpose.  So, it might look
something like:

    for each filename in our list of files:
        let's suck the contents out with read(),
        replace all newlines with the comma-newline combination
        and rewrite our new file

Hope this helps!



From tbrauch@mindless.com  Tue May  8 23:37:16 2001
From: tbrauch@mindless.com (Timothy M. Brauch)
Date: Tue, 08 May 2001 18:37:16 -0400
Subject: [Tutor] Calling functions
Message-ID: <3AF8751C.36E72957@mindless.com>

This might seem weird, but I swear, I have a purpose in this...

Is there a way to define a function and then use a raw_input to call the
function?

Here's a little example of what I mean

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

def func_0():
	do something here

def func_1():
	do something else here

dummy=raw_input('Which function do you want to execute? ')

dummy <---- I want that to do what ever was entered into the raw_input

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

Well, that obviously doesn't work, but that is the basic idea.  I just
want to know if this is possible, and how I could go about doing it.

 - Tim


From walterv@jps.net  Wed May  9 23:49:41 2001
From: walterv@jps.net (Walter Vannini)
Date: Wed, 09 May 2001 15:49:41 -0700
Subject: [Tutor] Expression matching
References: <200105090612_MC2-D04C-793C@compuserve.com>
 <20010509134648.A10336@pino.selwerd.nl>
Message-ID: <3AF9C985.B89DE458@jps.net>

Remco,

Shouldn't it be
    htmllib.HTMLParser.__init__(self,
formatter.NullFormatter())
instead of
    htmllib.HTMLParser.__init__(self,
formatter.NullFormatter)

(and "self.linklist" instead of "linklist" in:
    def change_html(self, html):
       # Use the linklist and the modify_link function to
return new html
       for link in linklist:
          html = html.replace(link, modify_link(link))
       return html
)?

Walter


From deirdre@deirdre.net  Wed May  9 23:49:42 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Wed, 9 May 2001 15:49:42 -0700
Subject: [Tutor] Calling functions
In-Reply-To: <3AF8751C.36E72957@mindless.com>
References: <3AF8751C.36E72957@mindless.com>
Message-ID: <a05100e0eb71f79f27566@[10.0.1.14]>

>This might seem weird, but I swear, I have a purpose in this...
>
>Is there a way to define a function and then use a raw_input to call the
>function?

why not just use input?

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From pdiaz88@terra.es  Thu May 10 01:49:52 2001
From: pdiaz88@terra.es (Pedro Diaz Jimenez)
Date: Thu, 10 May 2001 00:49:52 +0000
Subject: [Tutor] Calling functions
In-Reply-To: <3AF8751C.36E72957@mindless.com>
References: <3AF8751C.36E72957@mindless.com>
Message-ID: <0105100049520B.02224@duero>

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


I guess you need to exec'fy the string

pdiaz@duero:~$ python
Python 1.5.2 (#0, Dec 27 2000, 13:59:38)  [GCC 2.95.2 20000220 (Debian 
GNU/Linux)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> def say_hi ():
...     print "Hi!"
...
>>> def say_bye():
...     print "Bye!"
...
>>> exec_str=raw_input()
say_bye()
>>> exec(exec_str)
Bye!
>>>

Hope this helps

Cheers
Pedro



On Tuesday 08 May 2001 22:37, Timothy M. Brauch wrote:
> This might seem weird, but I swear, I have a purpose in this...
>
> Is there a way to define a function and then use a raw_input to call the
> function?
>
> Here's a little example of what I mean
>
> ####################################################################
>
> def func_0():
> 	do something here
>
> def func_1():
> 	do something else here
>
> dummy=raw_input('Which function do you want to execute? ')
>
> dummy <---- I want that to do what ever was entered into the raw_input
>
> ####################################################################
>
> Well, that obviously doesn't work, but that is the basic idea.  I just
> want to know if this is possible, and how I could go about doing it.
>
>  - Tim
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

- -- 

/*
 * Pedro Diaz Jimenez
 * pdiaz88@terra.es 
 * pdiaz@acm.asoc.fi.upm.es
 *
 * Wanna see how 100000! looks like?:
 * http://acm.asoc.fi.upm.es/~pdiaz/fact_100.000
 * 
 * La sabiduria me persigue, pero yo soy mas rapido
 */
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE6+eWwnu53feEYxlERAri2AJ91pWu0mpYBuoGmggAuePFfyVRyJwCgmzzQ
uNbaJmi7Tcu/QhHrrDBl63o=
=Nq2/
-----END PGP SIGNATURE-----


From dyoo@hkn.eecs.berkeley.edu  Thu May 10 00:41:54 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 9 May 2001 16:41:54 -0700 (PDT)
Subject: [Tutor] Calling functions
In-Reply-To: <3AF8751C.36E72957@mindless.com>
Message-ID: <Pine.LNX.4.21.0105091636290.27918-100000@hkn.eecs.berkeley.edu>

On Tue, 8 May 2001, Timothy M. Brauch wrote:

> Is there a way to define a function and then use a raw_input to call
> the function?

Yes, you can use a dictionary that maps the name of a function to the
function itself.


> def func_0():
> 	do something here
> 
> def func_1():
> 	do something else here
> 
> dummy=raw_input('Which function do you want to execute? ')


Here's a little bit more code to make this work:

###
function_dict = {'func_0': func_0,
                 'func_1': func_1}
dummy = function_dict[
           raw_input('Which function do you want to execute? ')]
dummy()
###


We can make this a little more bulletproof by checking to see if the
dictionary actually has the method we're looking for with has_key():

###
if function_dict.has_key(...):
    # Then it's safe to call the function.
else:
    # Let's force them to redo their input.
###

Hope this helps!



From dallam_@hotmail.com  Thu May 10 00:54:58 2001
From: dallam_@hotmail.com (Dallam Wych)
Date: Wed, 09 May 2001 23:54:58 -0000
Subject: [Tutor] gui for python
Message-ID: <F242BJHsxPCFj2AhGwE00001b44@hotmail.com>

Hi all,
I am new to linux and want to learn python. I have python installed on my 
system, but would like a gui. I would like to try Tkinter, but I don't have 
the required module. I am kind of in a bind here as I don't know what to do 
now. Could anyone give me some assistance so I can get started learning 
python?
Thanks,
Dallam

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



From dyoo@hkn.eecs.berkeley.edu  Thu May 10 01:56:42 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 9 May 2001 17:56:42 -0700 (PDT)
Subject: [Tutor] gui for python
In-Reply-To: <F242BJHsxPCFj2AhGwE00001b44@hotmail.com>
Message-ID: <Pine.LNX.4.21.0105091755450.29220-100000@hkn.eecs.berkeley.edu>

On Wed, 9 May 2001, Dallam Wych wrote:

> I am new to linux and want to learn python. I have python installed on my 
> system, but would like a gui. I would like to try Tkinter, but I don't have 
> the required module. I am kind of in a bind here as I don't know what to do 
> now. Could anyone give me some assistance so I can get started learning 
> python?

Sure!  What version of Python did you install; was it installed already
for you?  Tell us some more information, and we'll try to lead you in the
right direction.

Good luck!



From scarblac@pino.selwerd.nl  Thu May 10 02:14:45 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 10 May 2001 03:14:45 +0200
Subject: [Tutor] Expression matching
In-Reply-To: <3AF9C985.B89DE458@jps.net>; from walterv@jps.net on Wed, May 09, 2001 at 03:49:41PM -0700
References: <200105090612_MC2-D04C-793C@compuserve.com> <20010509134648.A10336@pino.selwerd.nl> <3AF9C985.B89DE458@jps.net>
Message-ID: <20010510031445.A30765@pino.selwerd.nl>

On  0, Walter Vannini <walterv@jps.net> wrote:
> Remco,
> 
> Shouldn't it be
>     htmllib.HTMLParser.__init__(self,
> formatter.NullFormatter())
> instead of
>     htmllib.HTMLParser.__init__(self,
> formatter.NullFormatter)
> 
> (and "self.linklist" instead of "linklist" in:
>     def change_html(self, html):
>        # Use the linklist and the modify_link function to
> return new html
>        for link in linklist:
>           html = html.replace(link, modify_link(link))
>        return html
> )?

Correct in both cases. I tend to just write things into the mail editor
thinking it'll be alright, I'll have to invent some macro in jed that tests
it as well, it's getting embarassing.


(Off topic - I'm drunk, and just returned from the first night of the
four-day party - and I've been kissing *the wrong girl*. Complications are
far more staggering than you'll ever see in programming).

-- 
Remco Gerlich


From brett42@flex.com  Thu May 10 02:58:20 2001
From: brett42@flex.com (Brett)
Date: Wed, 09 May 2001 15:58:20 -1000
Subject: [Tutor] tkinter buttons giving me problems
Message-ID: <4.3.2.7.0.20010509154948.00abba50@mail.flex.com>

I'm trying to figure out Tkinter, but I'm having trouble with 
buttons.  When if set a button's command, it calls the command  without 
being clicked.  The following is an idle transcript:

 >>> from Tkinter import *
 >>> x=0
 >>> def func():
	global x
	x=1

 >>> root=Tk()
 >>> x
0
 >>> button=Button(root,command=func(),text='button').pack()
 >>> x
1

Is this supposed to happen?  Is there a way to bind a button to a command 
without executing the command?
When Schrodinger's cat's away,
the mice may or may not play,
no one can tell.



From rick@niof.net  Thu May 10 04:22:13 2001
From: rick@niof.net (Rick Pasotto)
Date: Wed, 9 May 2001 23:22:13 -0400
Subject: [Tutor] tkinter buttons giving me problems
In-Reply-To: <4.3.2.7.0.20010509154948.00abba50@mail.flex.com>; from brett42@flex.com on Wed, May 09, 2001 at 03:58:20PM -1000
References: <4.3.2.7.0.20010509154948.00abba50@mail.flex.com>
Message-ID: <20010509232213.B13769@tc.niof.net>

On Wed, May 09, 2001 at 03:58:20PM -1000, Brett wrote:
> I'm trying to figure out Tkinter, but I'm having trouble with 
> buttons.  When if set a button's command, it calls the command  without 
> being clicked.  The following is an idle transcript:
> 
>  >>> from Tkinter import *
>  >>> x=0
>  >>> def func():
> 	global x
> 	x=1
> 
>  >>> root=Tk()
>  >>> x
> 0
>  >>> button=Button(root,command=func(),text='button').pack()
>  >>> x
> 1
> 
> Is this supposed to happen?  Is there a way to bind a button to a command 
> without executing the command?

'command=' takes the *name* of a function, not a function call.

Drop the parentheses and all should be well. What you want is:

>>> button=Button(root,command=func,text='button')
>>> button.pack()

The change to the pack() is because what you had results in the return
value of pack() being stored in the 'button' variable. I suspect you'd
rather have a reference to the button itself.

-- 
Certain nations seem particularly liable to fall prey to
governmental plunder. They are those in which men, lacking faith
in their own dignity and capability, would feel themselves lost if
they were not governed and administered every step of the way.
	-- Frédéric Bastiat (1801-1850)
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From rick@niof.net  Thu May 10 04:26:39 2001
From: rick@niof.net (Rick Pasotto)
Date: Wed, 9 May 2001 23:26:39 -0400
Subject: [Tutor] gui for python
In-Reply-To: <F242BJHsxPCFj2AhGwE00001b44@hotmail.com>; from dallam_@hotmail.com on Wed, May 09, 2001 at 11:54:58PM -0000
References: <F242BJHsxPCFj2AhGwE00001b44@hotmail.com>
Message-ID: <20010509232639.C13769@tc.niof.net>

On Wed, May 09, 2001 at 11:54:58PM -0000, Dallam Wych wrote:
> Hi all,
> I am new to linux and want to learn python. I have python installed on my 
> system, but would like a gui. I would like to try Tkinter, but I don't have 
> the required module. I am kind of in a bind here as I don't know what to do 
> now. Could anyone give me some assistance so I can get started learning 
> python?

What linux distribution?

-- 
[The socialists say that society, left to itself, heads inevitably
for destruction because its instincts are perverse. They demand
the power to stop mankind from sliding down this fatal declivity
and to impose a better direction on it. If, then, they have
received from heaven intelligence and virtues that place them
beyond and above mankind, let them show their credentials. They
want to be shepherds, and they want us to be their sheep. This
arrangement presupposes in them a natural superiority, a claim
that we have every right to require them to establish before we go
any further.
	-- Frédéric Bastiat (1801-1850)
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From kstoner@netins.net  Thu May 10 04:26:27 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Wed, 9 May 2001 22:26:27 -0500
Subject: [Tutor] self parameter
Message-ID: <001001c0d901$004e4ca0$5e52b1cf@oemcomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_000D_01C0D8D7.16AEDA20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am trying to understand how special methods work.
Ex:
class now:
def _init_(self):
    self.t =3D time.time()
    self.year, \
    self.month, \
    self.day, \
    self.hour, \
    self.minute, \
    self.second, \
    self.dow, \
    self.doy, \
    self.dst =3D time.localtime(self.t)
I don't know if I got it right, but I think the function is passing data =
to each variable, t; year; month; etc.  It's unpacking the tuple.  I'm =
not sure I understand how this bit of code is working.  The self =
arguement is allowing the function to pass data right?
I'd much appreciate any assistance.
-Cameron

------=_NextPart_000_000D_01C0D8D7.16AEDA20
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am trying to understand how special =
methods=20
work.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Ex:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>class now:<BR>def=20
_init_(self):<BR>&nbsp;&nbsp;&nbsp; self.t =3D =
time.time()<BR>&nbsp;&nbsp;&nbsp;=20
self.year, \<BR>&nbsp;&nbsp;&nbsp; self.month, \<BR>&nbsp;&nbsp;&nbsp; =
self.day,=20
\<BR>&nbsp;&nbsp;&nbsp; self.hour, \<BR>&nbsp;&nbsp;&nbsp; self.minute,=20
\<BR>&nbsp;&nbsp;&nbsp; self.second, \<BR>&nbsp;&nbsp;&nbsp; self.dow,=20
\<BR>&nbsp;&nbsp;&nbsp; self.doy, \<BR>&nbsp;&nbsp;&nbsp; self.dst =3D=20
time.localtime(self.t)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I don't know if I got it right, but I =
think the=20
function is passing data to each variable, t; year; month; etc.&nbsp; =
It's=20
unpacking the tuple.&nbsp; I'm not sure I understand how this bit of =
code is=20
working.&nbsp; The self arguement is allowing the function to pass data=20
right?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I'd much appreciate any =
assistance.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>-Cameron</FONT></DIV></BODY></HTML>

------=_NextPart_000_000D_01C0D8D7.16AEDA20--



From bdupire@seatech.fau.edu  Thu May 10 05:00:23 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Thu, 10 May 2001 00:00:23 -0400
Subject: [Tutor] self parameter
References: <001001c0d901$004e4ca0$5e52b1cf@oemcomputer>
Message-ID: <3AFA1257.DE5AF05F@seatech.fau.edu>

Quite.
time.localtime() returns a tuple, so yes you are unpacking the tuple.
But there is no 'real' function in this code.

You are defining a class.
>From this class you will be able to instanciate objects.
Objects have a set of operations you can call, which are called methods.

__init__ is therefore a method.
It's like a function, but this function can only operate on objects of
the same class.
When you define __init__ you don't know on which object ( in other words

on which instance of the class now) it will operate.
The __init__ method is said to be unbound.
To let it know on which object it gonna operate, we pass to it a
parameter, which is the object itself (to be accurate, a reference to
this object).

So when you are doing something like : self.foo = 5
then you create a new instance variable (a variable within your object)
which is called foo.

Python knows in which object it has to create foo, because self is a
reference to this object.


I know, there is quite a bit of OO terminology here... :o)
Hope this helps....
Benoit



Katharine Stoner wrote:

> I am trying to understand how special methods work.Ex:class now:
> def _init_(self):
>     self.t = time.time()
>     self.year, \
>     self.month, \
>     self.day, \
>     self.hour, \
>     self.minute, \
>     self.second, \
>     self.dow, \
>     self.doy, \
>     self.dst = time.localtime(self.t)I don't know if I got it right,
> but I think the function is passing data to each variable, t; year;
> month; etc.  It's unpacking the tuple.  I'm not sure I understand how
> this bit of code is working.  The self arguement is allowing the
> function to pass data right?I'd much appreciate any
> assistance.-Cameron

--
Benoit Dupire
Graduate Student




From margaret@retriever.com.au  Thu May 10 04:58:19 2001
From: margaret@retriever.com.au (Margaret Brierton)
Date: Thu, 10 May 2001 13:58:19 +1000
Subject: [Tutor] telnet
Message-ID: <3AFA11DB.FDDB36B6@retriever.com.au>

hi

can anyone can me if there are any discussions about telnet?

cheers



From deirdre@deirdre.net  Thu May 10 05:06:12 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Wed, 9 May 2001 21:06:12 -0700
Subject: [Tutor] telnet
In-Reply-To: <3AFA11DB.FDDB36B6@retriever.com.au>
References: <3AFA11DB.FDDB36B6@retriever.com.au>
Message-ID: <a05100e00b71fc41f00cb@[10.0.1.14]>

>can anyone can me if there are any discussions about telnet?

No, but what would you like to discuss?
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From bdupire@seatech.fau.edu  Thu May 10 05:14:43 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Thu, 10 May 2001 00:14:43 -0400
Subject: [Tutor] self parameter
References: <001001c0d901$004e4ca0$5e52b1cf@oemcomputer>
Message-ID: <3AFA15B3.63803E3@seatech.fau.edu>

By the way, __init__ is a very special method, because it is
automatically called when you create a new object.

To create a new object ( whose class is 'now') you have to do

a= now()

This creates a new object and calls the __init__ method, to initialize
the instance variables (ie. the variables within the object 'a', ie.
self.year, self.month, etc..)

usually , if you want to call a method you have to do:

<name of the object>.<name of the method> ( <parameters>)

so here it would be:
a.__init__( )

Note that  this calls the __init__ method substituting  'self' (the
first parameter of the method) with 'a'.


Now on the 'design point-of-view', there is little interest in having a
class 'now'. Why do you want to do objects ?
I think a simple function should do the job, storing your time values in
a list.

Benoit


Katharine Stoner wrote:

> I am trying to understand how special methods work.Ex:class now:
> def _init_(self):
>     self.t = time.time()
>     self.year, \
>     self.month, \
>     self.day, \
>     self.hour, \
>     self.minute, \
>     self.second, \
>     self.dow, \
>     self.doy, \
>     self.dst = time.localtime(self.t)I don't know if I got it right,
> but I think the function is passing data to each variable, t; year;
> month; etc.  It's unpacking the tuple.  I'm not sure I understand how
> this bit of code is working.  The self arguement is allowing the
> function to pass data right?I'd much appreciate any
> assistance.-Cameron

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From ppathiyi@cisco.com  Thu May 10 06:29:12 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Thu, 10 May 2001 10:59:12 +0530
Subject: [Tutor] telnet
References: <3AFA11DB.FDDB36B6@retriever.com.au>
Message-ID: <080901c0d912$25476ad0$37ef87c0@ppathiyipc>

Hi,
        If you are trying out telnet related stuff, this may be useful.

http://www.scit.wlv.ac.uk/~jphb/comms/telnet.html

Rgds,
Praveen.

----- Original Message ----- 
From: "Margaret Brierton" <margaret@retriever.com.au>
To: <tutor@python.org>
Sent: Thursday, May 10, 2001 9:28 AM
Subject: [Tutor] telnet


> hi
> 
> can anyone can me if there are any discussions about telnet?
> 
> cheers
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



From lonetwin@yahoo.com  Thu May 10 08:43:28 2001
From: lonetwin@yahoo.com (steve)
Date: Thu, 10 May 2001 13:13:28 +0530
Subject: [Tutor] Finding uniq. in lists
Message-ID: <01051013132800.12728@mercury.in.cqsl.com>

Hi all ye good people,
 Ques: Is there a nice ( read good+clean+efficient ) way to do this:
I have a list p =3D ['foo', 'bar', 'foo-bar', 'foo', 'foo-bar' ]
I want the list to contain only single instances of elements, ie:I want t=
o=20
filter out all the duplicate entries. This is the first thing that came t=
o my=20
mind :
=09q =3D [ p[i] for i in range(len(p)) if p[i] not in p[(i+1):] ]
 Prob. is I do not like it !! :) ...so either give me a better solu. or=20
convince me that the solu. I have is not bad :)
 N E Ways, I'm pretty sure 101 ways for doing this nicely must have alrea=
dy=20
been documented and talked 'bout on this list, but I'm just too lazy ( at=
=20
least for sumtin' as 'piddu-sa'(small/dumb: hindi slang) as this ) so fee=
l=20
free to ignore me :)

Thanx
Peace
Steve

--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
"Unfortunately, those people who have nothing better to do than post on t=
he
Internet all day long are rarely the ones who have the most insights."
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From arazak@kansai.com.my  Thu May 10 08:40:55 2001
From: arazak@kansai.com.my (Mr. Razak)
Date: Thu, 10 May 2001 15:40:55 +0800
Subject: [Tutor] python module
Message-ID: <001101c0d924$8f4cd0c0$6a01a8c0@com.my>

This is a multi-part message in MIME format.

------=_NextPart_000_000E_01C0D967.99C5A660
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

1. I want to know how's the module work and how to used them.
2. How to set path during programming.
3. How to print, how to activate printer, how to set them on and off and =
is it user friendly.

------=_NextPart_000_000E_01C0D967.99C5A660
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial>1. I want to know how's the module work and how =
to used=20
them.</FONT></DIV>
<DIV><FONT face=3DArial>2. How to set path during =
programming.</FONT></DIV>
<DIV><FONT face=3DArial>3. How to print, how to activate printer, how to =
set them=20
on and off and is it user friendly.</FONT></DIV></BODY></HTML>

------=_NextPart_000_000E_01C0D967.99C5A660--



From arazak@kansai.com.my  Thu May 10 08:43:25 2001
From: arazak@kansai.com.my (Mr. Razak)
Date: Thu, 10 May 2001 15:43:25 +0800
Subject: [Tutor] Visual Python
Message-ID: <001a01c0d924$e7dacc60$6a01a8c0@com.my>

This is a multi-part message in MIME format.

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

I heard that the beta version of visual python already produced. I want =
to know what is the difference and advantages of using visual python.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I heard that the beta version of visual =
python=20
already produced. I want to know what is the difference and advantages =
of using=20
visual python.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0017_01C0D967.F3B41C60--



From sburr@home.com  Thu May 10 08:38:49 2001
From: sburr@home.com (Steven Burr)
Date: Thu, 10 May 2001 00:38:49 -0700
Subject: [Tutor] (no subject)
Message-ID: <20010510073800.FQXF98.femail19.sdc1.sfba.home.com@localhost>

The discussion on the random.shuffle() function reminded me of a 
question I had about shuffling.  As an exercise, I've been
working on a module containing classes that could be used in text-based 
card games.   In my "Deck" class (which inherits from "Cards," which 
inherits from "UserList"), I included the following shuffle method:

	def shuffle(self):
      		d = []
      		for i in range(len(self) - 1, -1, -1):
      			d.append(self.pop(self.index(random.choice(self.data))))
      		self.data = d

In effect, the method popped random cards out of a list of cards and 
appended them to a new list until the original list was exhausted.  The 
new list then replaced the old in the Cards object.  It seemed to work 
fine.

I later read a tutorial that included a card game example (How to Think 
Like a Computer Scientist, Java version).  The shuffle method in the 
example switched each card in the array with another randomly chosen 
card from the same array.  When the Python random.shuffle function was 
mentioned, I took a look at the module, apparently written by the BDFL, 
and saw that Guido used essentially the same switching method (although 
it looks a lot better in Python than in Java : ).   Naturally, I 
promptly rewrote my shuffle method:

	def shuffle(self):  random.shuffle(self.data)

Still I'm curious.  Is there a clear advantage to the switching method 
as opposed to the pop and append method?


From walterv@jps.net  Thu May 10 08:47:49 2001
From: walterv@jps.net (Walter Vannini)
Date: Thu, 10 May 2001 00:47:49 -0700
Subject: [Tutor] self parameter
References: <001001c0d901$004e4ca0$5e52b1cf@oemcomputer>
Message-ID: <3AFA47A5.5F400590@jps.net>

Here's one approach to understanding what's going on.
Read documentation, look at examples, and then try rewriting the
problem code in ways that SHOULD be equivalent.
Here's my attempt at a rewrite of the original code:

class now:
    def __init__(self):
        localfloat = time.time() 
        # localfloat references the float returned by time.time()
        localtuple = time.localtime(localfloat) 
        # localtuple references a 9 element tuple
        # returned by time.localtime
        self.t = localfloat 
        # create an attribute t that references the
        # same float referenced by localfloat
        (self.year, self.month, self.day, self.hour, self.minute, \
        self.second, self.dow, self.doy, self.dst) \
            = localtuple 
        # 9 new attributes are created, and assigned values
        # via the 9 element tuple returned by time.localtime

By simply getting rid of the local variables
localfloat and localtuple, and rewriting the very explicit
"(a,b) = c" assignment of self.year, self.month, etc
as "a,b = c", you get the original method.
Also, "_init_" should probably be changed to "__init__".

Hope that helps,

Walter.
	
> I am trying to understand how special methods work.
> Ex:
> class now:
> def _init_(self):
>     self.t = time.time()
>     self.year, \
>     self.month, \
>     self.day, \
>     self.hour, \
>     self.minute, \
>     self.second, \
>     self.dow, \
>     self.doy, \
>     self.dst = time.localtime(self.t)
> I don't know if I got it right, but I think the function is passing
> data to each variable, t; year; month; etc.  It's unpacking the
> tuple.  I'm not sure I understand how this bit of code is working.
> The self arguement is allowing the function to pass data right?
> I'd much appreciate any assistance.
> -Cameron


From scarblac@pino.selwerd.nl  Thu May 10 08:45:17 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 10 May 2001 09:45:17 +0200
Subject: [Tutor] Finding uniq. in lists
In-Reply-To: <01051013132800.12728@mercury.in.cqsl.com>; from lonetwin@yahoo.com on Thu, May 10, 2001 at 01:13:28PM +0530
References: <01051013132800.12728@mercury.in.cqsl.com>
Message-ID: <20010510094517.A8139@pino.selwerd.nl>

On  0, steve <lonetwin@yahoo.com> wrote:
> Hi all ye good people,
>  Ques: Is there a nice ( read good+clean+efficient ) way to do this:
> I have a list p = ['foo', 'bar', 'foo-bar', 'foo', 'foo-bar' ]
> I want the list to contain only single instances of elements, ie:I want to 
> filter out all the duplicate entries. This is the first thing that came to my 
> mind :
> 	q = [ p[i] for i in range(len(p)) if p[i] not in p[(i+1):] ]
>  Prob. is I do not like it !! :) ...so either give me a better solu. or 
> convince me that the solu. I have is not bad :)

That will be too slow. Use a dictionary, it's the fastest way:

def uniq(q):
   dict = {}
   for s in q:
      dict[s] = 1
   return dict.keys()

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Thu May 10 08:47:09 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 10 May 2001 09:47:09 +0200
Subject: [Tutor] self parameter
In-Reply-To: <001001c0d901$004e4ca0$5e52b1cf@oemcomputer>; from kstoner@netins.net on Wed, May 09, 2001 at 10:26:27PM -0500
References: <001001c0d901$004e4ca0$5e52b1cf@oemcomputer>
Message-ID: <20010510094709.B8139@pino.selwerd.nl>

On  0, Katharine Stoner <kstoner@netins.net> wrote:
> I am trying to understand how special methods work.
> Ex:
> class now:
> def _init_(self):

Note: double underscores, so __init__, not _init_.

-- 
Remco Gerlich


From deirdre@deirdre.net  Thu May 10 08:48:38 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Thu, 10 May 2001 00:48:38 -0700
Subject: [Tutor] python module
In-Reply-To: <001101c0d924$8f4cd0c0$6a01a8c0@com.my>
References: <001101c0d924$8f4cd0c0$6a01a8c0@com.my>
Message-ID: <a05100e09b71ff8192f71@[10.0.1.15]>

--============_-1222641457==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

>1. I want to know how's the module work and how to used them.
>2. How to set path during programming.
>3. How to print, how to activate printer, how to set them on and off 
>and is it user friendly.

As I will say many, many times....what platform?

Many of the answers are platform dependent.

As for the answer to question #1, please see the tutorial on the 
python.org site; if you have *specific* questions, we'd be happy to 
help.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams
--============_-1222641457==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>Re: [Tutor] python module</title></head><body>
<blockquote type="cite" cite><font face="Arial">1. I want to know
how's the module work and how to used them.</font></blockquote>
<blockquote type="cite" cite><font face="Arial">2. How to set path
during programming.</font></blockquote>
<blockquote type="cite" cite><font face="Arial">3. How to print, how
to activate printer, how to set them on and off and is it user
friendly.</font></blockquote>
<div><br></div>
<div>As I will say many, many times....what platform?</div>
<div><br></div>
<div>Many of the answers are platform dependent.</div>
<div><br></div>
<div>As for the answer to question #1, please see the tutorial on the
python.org site; if you have *specific* questions, we'd be happy to
help.</div>
</body>
</html>
--============_-1222641457==_ma============--


From NHYTRO@compuserve.com  Thu May 10 10:01:58 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Thu, 10 May 2001 05:01:58 -0400
Subject: [Tutor] escaping slashes in filenames..
Message-ID: <200105100502_MC2-D07F-785F@compuserve.com>

Hi guys!

given:

aa =3D 'c:\ten\ten\ten\ten.jpg
aa2 =3D string.replace(aa, '\t', '\\')  # this results in
'c:\\en\\en\\en\\en.jpg'
aa3 =3D string.replace(aa,'\', '\\\\') # 'c:\\\\en\\\\......

My question is: how do I notify Python that the slashes are part of a
filename and not an escaped character? using r'c:\test'; raw string  is n=
ot
an option because I=B4ve got to take care of a bunch of filenames in a li=
st
or Tuple


Thanks


Sharriff =



From alan.gauld@bt.com  Thu May 10 10:10:10 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 May 2001 10:10:10 +0100
Subject: [Tutor] 15 puzzle
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D757@mbtlipnt02.btlabs.bt.co.uk>

> How old is 2.0 now? 8 months? We can't keep giving 1.5.2 
> solutions forever

Normal commercial vendor arrangements is to support the last 
2 versions thus on the next major release(ie 2.2?) we could 
drop "support" for 1.5 (assuming 1.6 doesn't count!)

OTOH Many companies including mine will not upgrade more than 
once per year and then only to the (current - 1) version. Thus 
the most recent version of Python I can use is 1.5.1 and we won't 
upgrade till July, probably to 2.0...

So on that basis we should offer support for at least 1 
calander year after a version is superceded.

Given the pace of change in open source software I'd favour 
the later option.

Just my two cents,

Alan G


From alan.gauld@bt.com  Thu May 10 10:30:13 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 May 2001 10:30:13 +0100
Subject: [Tutor] self parameter
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D758@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C0D933.D0DC4570
Content-type: text/plain; charset="iso-8859-1"

Explanations of self abound in past postings but I'll try a slightly
different approach.
 
Think of a class like a module.
When you create a new instance of the class you create a new "module"
thus 
class Spam:
   def eat(s):...
   def cook(s):..
 
food = Spam()   # create a new instance of Spam
meat = Spam()   # create another instance
 
is rather like saying:
 
import food,meat
 
where spam and meat are copies of the same module file.
 
Thus to access methods in those modules you must prepend the module name
 
meat.cook()
food.eat()
 
However since they are actually the same module (the Spam class) we need
some 
way inside the Spam 'module' (or class definition) to determine which
version of the 
module we are working with. Thats where self comes in. When you create an 
instance of Spam the self variable in that copy of the module is
automatically set to
the current modules name(meat or food).
 
Now within the methods of Spam when we use 
 
self.pork = 0.5
 
the self will refer to meat for the meat.cook() call and to food for the
food.eat() call.
 
But there is only one version of each function defined within Spam.
 
OK, Thats an alternative explanation. I don't know if it helps!
If not try the more conventional explation in my web tutor:
 
http://www.crosswinds.net/~agauld <http://www.crosswinds.net/~agauld> 
 
Under OOP and 'Whats in a Name'
 
Alan G

 


------_=_NextPart_001_01C0D933.D0DC4570
Content-type: text/html; charset="iso-8859-1"

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


<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>Explanations of self abound in past postings but I'll 
try a slightly different approach.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>Think 
of a class like a module.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>When 
you create a new instance of the class you create a new 
"module"</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>thus 
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>class 
Spam:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>&nbsp;&nbsp; def eat(s):...</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>&nbsp;&nbsp; def cook(s):..</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>food&nbsp;= Spam()&nbsp;&nbsp; # create a new instance 
of Spam</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>meat = 
Spam()&nbsp;&nbsp; # create another instance</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>is 
rather like saying:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>import 
food,meat</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>where 
spam and meat are copies of the same module file.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>Thus 
to access methods in those modules you must prepend the module 
name</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>meat.cook()</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>food.eat()</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>However since they are actually the same module (the 
Spam class) we need some </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>way 
inside the Spam 'module' (or class definition) to determine which version of the 
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>module 
we are working with. Thats where self comes in. When you create an 
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>instance of Spam the self variable in that copy of the 
module is automatically set to</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>the 
current modules name(meat or food).</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>Now 
within the methods of Spam when we use </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001>self.pork = 0.5</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>the 
self will refer to meat for the meat.cook() call and to food for the food.eat() 
call.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>But 
there is only one version of each function defined within 
Spam.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>OK, 
Thats an alternative explanation. I don't know if it helps!</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>If not 
try the more conventional explation in my web tutor:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001><A 
href="http://www.crosswinds.net/~agauld">http://www.crosswinds.net/~agauld</A></SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>Under 
OOP and 'Whats in a Name'</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=910142109-10052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=910142109-10052001>Alan 
G</SPAN></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C0D933.D0DC4570--


From babyboy@oninet.pt  Thu May 10 10:45:36 2001
From: babyboy@oninet.pt (wilson edgar pinto)
Date: Thu, 10 May 2001 10:45:36 +0100
Subject: [Tutor] gui for python
Message-ID: <0c7401c0d935$f6c00f90$4802a8c0@oninet.pt>


hiya,=20
case you don't have a programming these are very good places to start.

http://www.python.org/doc/current/tut/tut.html
and=20
http://www.crosswinds.net/~agauld/

hth

-----Original Message-----
From:	"tutor-admin@python.org" <tutor-admin@python.org> on behalf of	=
"Dallam Wych" <dallam_@hotmail.com>
Sent:	Wed, 09 May 2001 23:54:58 -0000
To:	"tutor@python.org" <tutor@python.org>
Subject:	[Tutor] gui for python

Hi all,
I am new to linux and want to learn python. I have python installed on =
my=20
system, but would like a gui. I would like to try Tkinter, but I don't =
have=20
the required module. I am kind of in a bind here as I don't know what to =
do=20
now. Could anyone give me some assistance so I can get started learning=20
python?
Thanks,
Dallam

_________________________________________________________________________=

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


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


From alan.gauld@bt.com  Thu May 10 10:50:23 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 May 2001 10:50:23 +0100
Subject: [Tutor] python module
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D759@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C0D936.A1EFC2C0
Content-type: text/plain; charset="iso-8859-1"

1. I want to know how's the module work and how to used them. 
 
Assuming you can already program in another language check the officual
tutor and reference docum,entation that came with Python or at
www.python.org <http://www.python.org> .
 
If you are new to programing check my web tutor at
 
http://www.crosswinds.net/~agauld <http://www.crosswinds.net/~agauld> 
 
in the Functionas and Modules section
 
2. How to set path during programming.
 
Which path? There are 2 to consider: the OS path and the PYTHONPATH
Both are settable, one via os(?) module (getenv()?) setemnv()?) the other
via 
the sys module. 
 
 
 3. How to print, how to activate printer, how to set them on and off  
 and is it user friendly. 
 
How user friendly will epend on hopw you program it. It definitely is not
programmer 
friendly and dependfs entirely on your operating system. There is a PDF
generating 
module available which makes nice output at least slightly more platform
independant
or you can generate HTML and use IE or Netscape to print it for you. In all
cases 
the actual printing to paper is system dependant tho'.
 
HTH
 
Alan G
 


------_=_NextPart_001_01C0D936.A1EFC2C0
Content-type: text/html; charset="iso-8859-1"

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


<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><FONT face=Arial>1. I want to know how's the module work and how to used 
  them.<FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>&nbsp;</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>Assuming you can already program in another language 
  check the officual tutor and reference docum,entation that came with Python or 
  at <A 
  href="http://www.python.org">www.python.org</A>.</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>If you are new to programing check my web tutor 
  at</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001><A 
  href="http://www.crosswinds.net/~agauld">http://www.crosswinds.net/~agauld</A></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>in the Functionas and 
  Modules&nbsp;section</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>&nbsp;</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial>2. How to set path during programming.</FONT></DIV>
  <DIV><FONT face=Arial><SPAN class=350204909-10052001><FONT color=#0000ff 
  size=2></FONT></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial><SPAN class=350204909-10052001><FONT color=#0000ff 
  size=2>Which path? There are 2 to consider: the OS path and the 
  PYTHONPATH</FONT></SPAN></FONT></DIV>
  <DIV><FONT face=Arial><SPAN class=350204909-10052001><FONT color=#0000ff 
  size=2>Both are settable, one via&nbsp;os(?) module (getenv()?) setemnv()?) 
  the other via </FONT></SPAN></FONT></DIV>
  <DIV><FONT face=Arial><SPAN class=350204909-10052001><FONT color=#0000ff 
  size=2>the sys module.</FONT>&nbsp;</SPAN></FONT></DIV>
  <DIV><FONT face=Arial><SPAN 
class=350204909-10052001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial><SPAN 
class=350204909-10052001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial><SPAN class=350204909-10052001>&nbsp;</SPAN>3. How to 
  print, how to activate printer, how to set them on and off&nbsp;<SPAN 
  class=350204909-10052001><FONT color=#0000ff 
  size=2>&nbsp;</FONT></SPAN></FONT></DIV>
  <DIV><FONT face=Arial><SPAN class=350204909-10052001>&nbsp;</SPAN>and is it 
  user friendly.<FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>&nbsp;</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>How user friendly will epend on hopw you program it. 
  It definitely is not programmer </SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>friendly and dependfs entirely on your operating 
  system.&nbsp;There is a PDF generating </SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>module available which makes nice output at least 
  slightly more platform independant</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>or you can generate HTML and use IE or Netscape to 
  print it for you. In all cases </SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001>the actual printing to paper is system dependant 
  tho'.</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff size=2><SPAN 
  class=350204909-10052001></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT color=#0000ff face=Arial size=2><SPAN 
  class=350204909-10052001>HTH</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff face=Arial size=2><SPAN 
  class=350204909-10052001></SPAN></FONT>&nbsp;</DIV>
  <DIV><FONT color=#0000ff face=Arial size=2><SPAN class=350204909-10052001>Alan 
  G</SPAN></FONT></DIV>
  <DIV><FONT color=#0000ff face=Arial size=2><SPAN 
  class=350204909-10052001></SPAN></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C0D936.A1EFC2C0--


From dyoo@hkn.eecs.berkeley.edu  Thu May 10 11:20:05 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 10 May 2001 03:20:05 -0700 (PDT)
Subject: [Tutor] Re: Multiple Assignments...
In-Reply-To: <08a301c0d936$25012fb0$37ef87c0@ppathiyipc>
Message-ID: <Pine.LNX.4.21.0105100250470.7902-100000@hkn.eecs.berkeley.edu>

On Thu, 10 May 2001, Praveen Pathiyil wrote:

>         Can you tell me how the multiple assignments in python work in
> case of swapping (may be from interpreter point of view) ? I found the
> below assignment strange given the conventional way of storing in temp
> and all.

Sure!  Let me forward this to the tutor@python.org mailing list too, since
this is an issue that other people might want to know about.


> a, b = b, a

Python needs to figure out the value at the right of the assignment.  
Let's call this value the "right hand side"; Python will ignore the left
hand side of the equation for the moment.

Let's stare more at the right hand side. The expression:

    b, a

is the tuple

   (b, a)

in disguise; with those commas, Python infers that we mean a "tuple".  So
what's on the right hand side is the tuple that contains the values of 'b'
and 'a'.  You can imagine that what we have, now, looks something like:

    a, b = some_right_hand_side_value

This is the part that might seem weird, just because when we see the
equals sign '=', we might think that everything happens simultaneously,
like some math equation.  However, what we don't see is that there's an
intermediate step, where it needs to first grab the value of the right
hand, and then it proceeds with the assignment.


On a related note, this temporary evaluation of the right hand side is
what allows us to write things like:

   a = a + 1

without violating the laws of nature. the roles of variables are different
depending on which side they straddle the equal '=' sign.  When they're on
the right we're trying to load the values contained in them.  On the left,
we're storing into these variables.


Let's go back to the tuple assignment question.  Now that we have this
situation:

    a, b = some_right_hand_side_value

Python can easily assign 'a' to the first value in some right hand side
value, and 'b' to the second element.




>         Also i guess that most of the things i am following are those
> in python 1.5.2. We haven't yet installed python 2.1 version. Thats
> the latest and stable one, right ? Where do i get the documentation
> which says which all modules are changed in 2.1 and which all are the
> new facilities in that ?

Andrew Kuchling has written the document "What's New in Python 2.1", and
it summarizes the really big differences between 2.1 and 2.0:

    http://www.amk.ca/python/2.1/

Likewise, the "What's New in Python 2.0" document talks about the
differences between 2.0 and 1.52.

    http://python.org/2.0/new-python.html


>         Is "Core Python Programming" by Wesley Chun the best book to
> buy to learn python more deeply ?

I hope Wesley can forgive me: I haven't read his book yet.  But according
to what people have said on tutor, it's a great book.

To learn Python deeply, answer and ask questions, and write programs.  It
might also be useful to look at different languages, to get a sense of how
different all these rules can be, yet have the same effects.  There's a
famous quote that says that someone understands the Lisp language a lot
better after learning Python.  I think the equality goes both ways, unlike
assignment.  *grin*


Good luck to you.



From dyoo@hkn.eecs.berkeley.edu  Thu May 10 11:23:58 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 10 May 2001 03:23:58 -0700 (PDT)
Subject: [Tutor] Finding uniq. in lists
In-Reply-To: <20010510094517.A8139@pino.selwerd.nl>
Message-ID: <Pine.LNX.4.21.0105100321400.7902-100000@hkn.eecs.berkeley.edu>

On Thu, 10 May 2001, Remco Gerlich wrote:

> On  0, steve <lonetwin@yahoo.com> wrote:
> > Hi all ye good people,
> >  Ques: Is there a nice ( read good+clean+efficient ) way to do this:
> > I have a list p = ['foo', 'bar', 'foo-bar', 'foo', 'foo-bar' ]
> > I want the list to contain only single instances of elements, ie:I want to 
> > filter out all the duplicate entries. This is the first thing that came to my 
> > mind :
> > 	q = [ p[i] for i in range(len(p)) if p[i] not in p[(i+1):] ]
> >  Prob. is I do not like it !! :) ...so either give me a better solu. or 
> > convince me that the solu. I have is not bad :)
> That will be too slow. Use a dictionary, it's the fastest way:
> 
> def uniq(q):
>    dict = {}
>    for s in q:
>       dict[s] = 1
>    return dict.keys()


Here's a hint of an alternative method.  If you have the list

    p = ['foo', 'bar', 'foo-bar', 'foo', 'foo-bar' ]

would your problem be easier if you rearranged the elements like this?

    p_arranged = ['bar', 'foo', 'foo', 'foo-bar', 'foo-bar']



From tutor@python.org  Thu May 10 09:16:35 2001
From: tutor@python.org (Tim Peters)
Date: Thu, 10 May 2001 04:16:35 -0400
Subject: [Tutor] Finding uniq. in lists
In-Reply-To: <01051013132800.12728@mercury.in.cqsl.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCCEFAKBAA.tim.one@home.com>

[steve]
>  Ques: Is there a nice ( read good+clean+efficient ) way to do this:
> I have a list p = ['foo', 'bar', 'foo-bar', 'foo', 'foo-bar' ]
> I want the list to contain only single instances of elements, ie:I
> want to filter out all the duplicate entries.

Take a peek at:

    http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52560

The most appropriate good+clean+efficient method depens on what assumptions
we can make about the elements of your list.  That's all explained there,
though, so I won't repeat it here <wink>.



From dyoo@hkn.eecs.berkeley.edu  Thu May 10 11:40:06 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 10 May 2001 03:40:06 -0700 (PDT)
Subject: [Tutor] escaping slashes in filenames..
In-Reply-To: <200105100502_MC2-D07F-785F@compuserve.com>
Message-ID: <Pine.LNX.4.21.0105100332590.7902-100000@hkn.eecs.berkeley.edu>

On Thu, 10 May 2001, Sharriff Aina wrote:

> aa =3D 'c:\ten\ten\ten\ten.jpg
> aa2 =3D string.replace(aa, '\t', '\\')  # this results in
> 'c:\\en\\en\\en\\en.jpg'
> aa3 =3D string.replace(aa,'\', '\\\\') # 'c:\\\\en\\\\......
>=20
> My question is: how do I notify Python that the slashes are part of a
> filename and not an escaped character? using r'c:\test'; raw string  is n=
ot


You can double up the backslashes.  An escaped backslash is a backslash. =
=20
Er, what I mean is:

###
>>> backslash =3D '\\'
>>> backslash
'\\'
>>> print backslash
\
###

So one way to write out your path would be:

    aa =3D 'c:\\ten\\ten\\ten\\ten.jpg

which would avoid the problem of accidently escaping the t's into tab
characters.


> filename and not an escaped character? using r'c:\test'; raw string  is n=
ot
> an option because I=B4ve got to take care of a bunch of filenames in a li=
st
> or Tuple

I'm not quite sure I understand; can you show us what prevents the use of
raw strings?  Perhaps there might be a way to get it to work.

For example, as long as there aren't any spaces in your filenames, you
could do something like:

###
long_list =3D r'''c:\test.txt,
                c:\arm\and\a\leg.txt
                c:\one\ring\to\rule\them\all.com'''.split()
###

which has the nice effect of using the split to break it into a 3-element
list.  This is almost equivalent to Perl's "quoteword" function qw().


Hope this helps!



From wheelege@tsn.cc  Thu May 10 11:36:01 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Thu, 10 May 2001 20:36:01 +1000
Subject: [Tutor] escaping slashes in filenames..
References: <200105100502_MC2-D07F-785F@compuserve.com>
Message-ID: <01e601c0d93d$034d3d80$0200a8c0@ACE>

>given:
>
>aa = 'c:\ten\ten\ten\ten.jpg
>aa2 = string.replace(aa, '\t', '\\')  # this results in
>'c:\\en\\en\\en\\en.jpg'
>aa3 = string.replace(aa,'\', '\\\\') # 'c:\\\\en\\\\......
>
>My question is: how do I notify Python that the slashes are part of a
>filename and not an escaped character? using r'c:\test'; raw string  is not
>an option because I´ve got to take care of a bunch of filenames in a list
>or Tuple

  Why not?  I don't really see how putting an r in front of the string when
it is assigned cannot be a solution when dealing with lists.
  Since...

>>> a = r'c:\whatever'
>>> b = r'c:\something else'
>>> c = r'c:\another thing'
>>> l = [a,b,c]
>>> l
['c:\\whatever', 'c:\\something else', 'c:\\another thing']

  If you are acquiring the string from a path command, it should already
have escaped all the backslashes.  <assumption>Fact is, after making a
string with escape characters in it, I don't think you can really get them
out without searching and replacing for every escape code...which is tedious
and evil</assumption>.
  If you explain in more detail how using r when assigning the filenames is
not possible, then I/we can help further,

  Glen.
  (I am seriously not anywhere experienced enough to have any weight to my
words...so wait for Remco (after he recovers) or Danny if I am just
confusing)



From dyoo@hkn.eecs.berkeley.edu  Thu May 10 11:43:53 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 10 May 2001 03:43:53 -0700 (PDT)
Subject: [Tutor] python module
In-Reply-To: <001101c0d924$8f4cd0c0$6a01a8c0@com.my>
Message-ID: <Pine.LNX.4.21.0105100340210.7902-100000@hkn.eecs.berkeley.edu>

On Thu, 10 May 2001, Mr. Razak wrote:

> 1. I want to know how's the module work and how to used them.

Modules are usually themselves written in Python.  Each Python script can
be seen as a module, which is nice because it's very casual.


> 2. How to set path during programming.

I'm not quite sure I understand what you mean.  Can you explain how you'll
use this?


> 3. How to print, how to activate printer, how to set them on and off
> and is it user friendly.

If you mean "printing" as in printing to a laser/inkjet printer, this
isn't too hard, but you'll need to learn some Python to have it print out
nice documents.  If you mean "printing" as in printing text to your
screen, this is much easier:

###
print "hello world"
###

is enough to put the words "hello world" on your screen.


Good luck to you.




From dyoo@hkn.eecs.berkeley.edu  Thu May 10 11:47:44 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 10 May 2001 03:47:44 -0700 (PDT)
Subject: [Tutor] Visual Python
In-Reply-To: <001a01c0d924$e7dacc60$6a01a8c0@com.my>
Message-ID: <Pine.LNX.4.21.0105100343560.7902-100000@hkn.eecs.berkeley.edu>

On Thu, 10 May 2001, Mr. Razak wrote:

> I heard that the beta version of visual python already produced. I
> want to know what is the difference and advantages of using visual
> python.


Visual Python is a module that extends Python's power to work with OpenGL
3d graphics.  It allows the programmer to write programs that play around
with graphics without having to worry about issues like threads, or event
loops.  I've also heard that it also handles a lot of physics and vector
calculations, so that someone can do experiments with moving bodies with
ease.

You can find more about VPython here:

    http://virtualphoton.pc.cc.cmu.edu/projects/visual/




From wheelege@tsn.cc  Thu May 10 11:43:16 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Thu, 10 May 2001 20:43:16 +1000
Subject: [Tutor] Re: Multiple Assignments...
References: <Pine.LNX.4.21.0105100250470.7902-100000@hkn.eecs.berkeley.edu>
Message-ID: <022501c0d93e$05ddde00$0200a8c0@ACE>

> <snip the Danbot's words of wisdom>
>
> To learn Python deeply, answer and ask questions, and write programs.  It
> might also be useful to look at different languages, to get a sense of how
> different all these rules can be, yet have the same effects.  There's a
> famous quote that says that someone understands the Lisp language a lot
> better after learning Python.  I think the equality goes both ways, unlike
> assignment.  *grin*
>

  I'll just chuck this link in here...

http://www.norvig.com/python-lisp.html

  'Python for lisp programmers'.  A very itneresting read, and I know I
found it helpful...

  Glen.



From ppathiyi@cisco.com  Thu May 10 11:50:09 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Thu, 10 May 2001 16:20:09 +0530
Subject: [Tutor] Re: Multiple Assignments...
References: <Pine.LNX.4.21.0105100250470.7902-100000@hkn.eecs.berkeley.edu>
Message-ID: <08e201c0d93e$fb725df0$37ef87c0@ppathiyipc>

Hi Danny,
        Thx for the explanation. I am just prolonging the discussion.....

a,b = b,a

In your words, this would be
a, b = some_right_hand_side_value

I was wondering abt the sequence after that.
say a = 'A' and b = 'B' initially.

If the assignment a = 'B' happens first, then won't the assignment for b
will be 'B' itself as the value referenced by "a" on the RHS will be changed
?

Or is it that all the objects on the RHS are replaced by their values before
the assignment happen ?

i.e, a, b = 'B', 'A'

Just making sure !!!

Rgds,
Praveen.

----- Original Message -----
From: "Daniel Yoo" <dyoo@hkn.eecs.berkeley.edu>
To: "Praveen Pathiyil" <ppathiyi@cisco.com>
Cc: <tutor@python.org>
Sent: Thursday, May 10, 2001 3:50 PM
Subject: Re: Multiple Assignments...


> On Thu, 10 May 2001, Praveen Pathiyil wrote:
>
> >         Can you tell me how the multiple assignments in python work in
> > case of swapping (may be from interpreter point of view) ? I found the
> > below assignment strange given the conventional way of storing in temp
> > and all.
>
> Sure!  Let me forward this to the tutor@python.org mailing list too, since
> this is an issue that other people might want to know about.
>
>
> > a, b = b, a
>
> Python needs to figure out the value at the right of the assignment.
> Let's call this value the "right hand side"; Python will ignore the left
> hand side of the equation for the moment.
>
> Let's stare more at the right hand side. The expression:
>
>     b, a
>
> is the tuple
>
>    (b, a)
>
> in disguise; with those commas, Python infers that we mean a "tuple".  So
> what's on the right hand side is the tuple that contains the values of 'b'
> and 'a'.  You can imagine that what we have, now, looks something like:
>
>     a, b = some_right_hand_side_value
>
> This is the part that might seem weird, just because when we see the
> equals sign '=', we might think that everything happens simultaneously,
> like some math equation.  However, what we don't see is that there's an
> intermediate step, where it needs to first grab the value of the right
> hand, and then it proceeds with the assignment.
>
>
> On a related note, this temporary evaluation of the right hand side is
> what allows us to write things like:
>
>    a = a + 1
>
> without violating the laws of nature. the roles of variables are different
> depending on which side they straddle the equal '=' sign.  When they're on
> the right we're trying to load the values contained in them.  On the left,
> we're storing into these variables.
>
>
> Let's go back to the tuple assignment question.  Now that we have this
> situation:
>
>     a, b = some_right_hand_side_value
>
> Python can easily assign 'a' to the first value in some right hand side
> value, and 'b' to the second element.
>
>
>




From dyoo@hkn.eecs.berkeley.edu  Thu May 10 12:01:35 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 10 May 2001 04:01:35 -0700 (PDT)
Subject: [Tutor] (no subject)
In-Reply-To: <20010510073800.FQXF98.femail19.sdc1.sfba.home.com@localhost>
Message-ID: <Pine.LNX.4.21.0105100347480.7902-100000@hkn.eecs.berkeley.edu>

On Thu, 10 May 2001, Steven Burr wrote:

> The discussion on the random.shuffle() function reminded me of a 
> question I had about shuffling.  As an exercise, I've been
> working on a module containing classes that could be used in text-based 
> card games.   In my "Deck" class (which inherits from "Cards," which 
> inherits from "UserList"), I included the following shuffle method:
> 
> 	def shuffle(self):
>       		d = []
>       		for i in range(len(self) - 1, -1, -1):
>       			d.append(self.pop(self.index(random.choice(self.data))))
>       		self.data = d
> 
> In effect, the method popped random cards out of a list of cards and 
> appended them to a new list until the original list was exhausted.  The 
> new list then replaced the old in the Cards object.  It seemed to work 
> fine.
> 
> I later read a tutorial that included a card game example (How to Think 
> Like a Computer Scientist, Java version).  The shuffle method in the 
> example switched each card in the array with another randomly chosen 
> card from the same array.  When the Python random.shuffle function was 
> mentioned, I took a look at the module, apparently written by the BDFL, 
> and saw that Guido used essentially the same switching method (although 
> it looks a lot better in Python than in Java : ).   Naturally, I 
> promptly rewrote my shuffle method:
> 
> 	def shuffle(self):  random.shuffle(self.data)
> 
> Still I'm curious.  Is there a clear advantage to the switching method 
> as opposed to the pop and append method?


The switching method can go horribly wrong if we make a slight mistake.  
*grin*

    http://mail.python.org/pipermail/edu-sig/2000-November/000771.html
    http://mail.python.org/pipermail/edu-sig/2000-November/000772.html
    http://mail.python.org/pipermail/edu-sig/2000-November/000784.html
    http://mail.python.org/pipermail/edu-sig/2000-November/000785.html
    http://mail.python.org/pipermail/edu-sig/2000-November/000786.html

... hmmm... in fact, most of November's edu-sig articles might be
interesting.

    http://mail.python.org/pipermail/edu-sig/2000-November/thread.html


Switching appears to use less memory than the card-pulling method because
it doesn't require making new lists or expanding old ones.  The
card-pulling, on the other hand, needs to shrink the deck and expand it
again.  

We can do some benchmarks by using the time.time() function.  time.time()
gives us back the number of seconds since the Epoch, so if we use it like
a stopwatch:

###
start = time.time()
## Do expensive operation
stop = time.time()
print "It took", start-stop, "econds to finish this operation."
###

we can empirically see how the two methods compare.


Hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Thu May 10 12:13:31 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 10 May 2001 04:13:31 -0700 (PDT)
Subject: [Tutor] Re: Multiple Assignments...
In-Reply-To: <08e201c0d93e$fb725df0$37ef87c0@ppathiyipc>
Message-ID: <Pine.LNX.4.21.0105100408001.10169-100000@hkn.eecs.berkeley.edu>

On Thu, 10 May 2001, Praveen Pathiyil wrote:

>         Thx for the explanation. I am just prolonging the
> discussion.....

No problem.


> I was wondering abt the sequence after that.
> say a = 'A' and b = 'B' initially.
> 
> If the assignment a = 'B' happens first, then won't the assignment for b
> will be 'B' itself as the value referenced by "a" on the RHS will be changed
> ?
> 
> Or is it that all the objects on the RHS are replaced by their values before
> the assignment happen ?
> 
> i.e, a, b = 'B', 'A'


Let's try an experiment, just to be sure:

###
>>> a = 'X'
>>> b = 'Y'
>>> def f1():
...     global a, b
...     print "(a, b) == (%s, %s)" % (a, b)
...     return 1
... 
>>> def f2():
...     global a, b
...     print "(a, b) == (%s, %s)" % (a, b)
...     return 2
... 
>>> a, b = f1(), f2()
(a, b) == (X, Y)
(a, b) == (X, Y)
>>> print a, b
1 2
###

So although global variables are usually "evil", here's one reason we
might want to use them, to check to see how tuple assignment actually
works.

Hope this helps!



From wheelege@tsn.cc  Thu May 10 13:52:04 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Thu, 10 May 2001 22:52:04 +1000
Subject: [Tutor] escaping slashes in filenames..
References: <200105100707_MC2-D074-32A6@compuserve.com>
Message-ID: <025101c0d950$040632a0$0200a8c0@ACE>

(just cc-ing this to the tutor list)
>
>Hi Glen!
>

Hi :)

>Message text written by "Glen Wheeler"
>>which is tedious
>and evil</assumption>.<
>
>on the dot, actually a search and replace works, but it fails when it
>encounters substrings with "escaped like characters" example:
>
>C:\good\image.jpg # this works
>
>c:\bad\image.jpg # this does´nt because Python thinks beforehand that a
>'\b' charater is in the string. this follows for  other escaped charaters
>too.
>
>Using raw strings is not an option because the list of paths are generated
>dynamically. I would have loved to turn them all into raw strings and write
>them back in the list but all my functions failed.

  Alright, then perhaps the function in question needs a look at.  For
example, say your generating the path using a script like this...

------------
## generate a random path made up of a C: at the start, and a variable
number of directories made up of upper and lowercase letters
import string, random
def makepath():
    path = r'C:'           ## not sure if this is important, but I did it
anyway
    somechars = list(string.letters)
    slashes = range(int(random.random()*9))   ## perhaps this should be a
bigger number
    for x in slashes:
     for y in range(int(random.random()*27)): ## same here
      l = random.choice(somechars)
      path = path + l
     if x != slashes[-1]:
      path = path + '\\'   ## this is crucial
     else:
      return path
apath = makepath()
print apath
------------(could contain errors...  I'm tired, didn't check it... :)

  Now that I've written that.... it would be better to use
random.choice([1,2,3,4,5,6,7]) for the directory names...bah, it's not meant
to be useful, just illustrate how you would pre-escape a generated path.
  If you are using a built-in function to get the path, it should already be
a string with escaped backslashes.  If not, I hope we can help you modify
your existing function to return nice useable paths :)

  Glen.



From tron@submatrix.com  Thu May 10 15:27:23 2001
From: tron@submatrix.com (Tron)
Date: Thu, 10 May 2001 07:27:23 -0700
Subject: [Tutor] Text Editor?
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE>
Message-ID: <000f01c0d95d$54f37080$01000001@praxis>

What text editor would you guys recommend using?

Thanks,
Tron



From szz@philoslabs.com  Thu May 10 15:57:12 2001
From: szz@philoslabs.com (Zoltan Szalay)
Date: Thu, 10 May 2001 16:57:12 +0200
Subject: [Tutor] Text Editor?
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE> <000f01c0d95d$54f37080$01000001@praxis>
Message-ID: <3AFAAC48.543EE4AB@philoslabs.com>

My favourite is SciTE...
http://www.scintilla.org/SciTE.html

Tron wrote:

> What text editor would you guys recommend using?
>
> Thanks,
> Tron
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From kojo@hal-pc.org  Thu May 10 15:42:06 2001
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Thu, 10 May 2001 09:42:06 -0500
Subject: [Tutor] Text Editor?
In-Reply-To: <000f01c0d95d$54f37080$01000001@praxis>
References: <200105100707_MC2-D074-32A6@compuserve.com>
 <025101c0d950$040632a0$0200a8c0@ACE>
Message-ID: <5.0.2.1.0.20010510094045.01f53180@Pop3.norton.antivirus>

WARNING!!  Potential Holy War!!

Duck.
;-)

At 07:27 AM 5/10/2001 -0700, Tron wrote:
>What text editor would you guys recommend using?
>
>Thanks,
>Tron
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

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

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



From ium@micromuse.com  Thu May 10 15:49:33 2001
From: ium@micromuse.com (ibraheem umaru-mohammed)
Date: Thu, 10 May 2001 15:49:33 +0100
Subject: [Tutor] Text Editor?
In-Reply-To: <000f01c0d95d$54f37080$01000001@praxis>; from tron@submatrix.com on Thu, May 10, 2001 at 07:27:23AM -0700
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE> <000f01c0d95d$54f37080$01000001@praxis>
Message-ID: <20010510154932.G22289@micromuse.com>

[Tron wrote...]
-| What text editor would you guys recommend using?
-| 

i would recommend Vim. Very powerful. Some people
might recommend Emacs, but then again I have also heard people say 
that Emacs is an Operating System that just happens to have a text editor....

Vim sticks to what it does best, and calls upon other applications to do
what they do best...

Kindest regards,

	--ibs.

-- 
It's hard to drive at the limit, but it's harder to know where the limits are.
		-- Stirling Moss


From rick@niof.net  Thu May 10 15:56:21 2001
From: rick@niof.net (Rick Pasotto)
Date: Thu, 10 May 2001 10:56:21 -0400
Subject: [Tutor] 15 puzzle
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D757@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Thu, May 10, 2001 at 10:10:10AM +0100
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D757@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20010510105621.D13769@tc.niof.net>

On Thu, May 10, 2001 at 10:10:10AM +0100, alan.gauld@bt.com wrote:
> > How old is 2.0 now? 8 months? We can't keep giving 1.5.2 solutions
> > forever
> 
> Normal commercial vendor arrangements is to support the last 2
> versions thus on the next major release(ie 2.2?) we could drop
> "support" for 1.5 (assuming 1.6 doesn't count!)
> 
> OTOH Many companies including mine will not upgrade more than once per
> year and then only to the (current - 1) version. Thus the most recent
> version of Python I can use is 1.5.1 and we won't upgrade till July,
> probably to 2.0...
> 
> So on that basis we should offer support for at least 1 calander year
> after a version is superceded.
> 
> Given the pace of change in open source software I'd favour the later
> option.

This works for me.

I run debian linux and debian is very meticulous about making sure that
everything in a release works together and consequently debian releases
are relatively rare.

I can easily install the 2.0 python itself from the debian unstable but
the corresponding Tkinter requires the new X and that requires lots of
other new stuff. Not an easy or safe upgrade.

-- 
And why do the political parties aspire to take over the direction
of education? Because they know the saying of Leibnitz: "Make me
the master of Education by governmental power, and I will
undertake to change the world". Education by governmental power,
then, is education by a political party, by a sect momentarily
triumphant; it is education on behalf of one idea, of one system,
to the exclusion of all others.
	-- Frédéric Bastiat (1801-1850)
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From randrews@planhouse.com  Thu May 10 16:26:14 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Thu, 10 May 2001 10:26:14 -0500
Subject: [Tutor] after string.split()
Message-ID: <000001c0d965$8cef6f40$de00a8c0@planhouse5>

I've got another question on doing stuff to each line in a file. I've got a
number of comma-delimited files exported from an Access database, and I need
to mangle them in a number of ways. If I fileinput.input() and
string.split() them, they don't seem to mind being mangled. But I trip over
a few points. This is how I initially tackle the file:

>>> for line in fileinput.input("mangleme.txt"):
	words = string.split(line, ",")

And this is an abbreviated version of file contents:

"Primary Key","Name","Company","Address1","Address2","City","State","Zip"
1,"John Q. Public","ACME Widgets","P.O. Box 12345",,"Auburn","AL","36831"

I need to remove the Primary Key field, for instance, while leaving the rest
of the file's contents intact. Can anyone recommend resources where I can
find out what I can do to the split "parts"?

Rob



From lumbricus@gmx.net  Thu May 10 16:06:04 2001
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Thu, 10 May 2001 17:06:04 +0200
Subject: [Tutor] Text Editor?
In-Reply-To: <000f01c0d95d$54f37080$01000001@praxis>; from tron@submatrix.com on Thu, May 10, 2001 at 07:27:23AM -0700
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE> <000f01c0d95d$54f37080$01000001@praxis>
Message-ID: <20010510170604.A8010@Laplace.localdomain>

On Thu, May 10, 2001 at 07:27:23AM -0700, Tron wrote:
> What text editor would you guys recommend using?
vim
jed
emacs is a handy OS but lacks a good editor ;-)

> Thanks,
> Tron

BTW Tron is DEAD for a long time now.
> 
> 
greetings jö
> 

-- 
Love your neighbour, yet don't pull down your hedge.
		-- Benjamin Franklin


From bdupire@seatech.fau.edu  Thu May 10 16:38:52 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Thu, 10 May 2001 11:38:52 -0400
Subject: [Tutor] Text Editor?
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE> <000f01c0d95d$54f37080$01000001@praxis> <3AFAAC48.543EE4AB@philoslabs.com>
Message-ID: <3AFAB60C.94905B6C@seatech.fau.edu>

i did not know SciTE. The screenShot on the website looks great.
I am using UltraEdit, which is not bad either....

Benoit...

Zoltan Szalay wrote:

> My favourite is SciTE...
> http://www.scintilla.org/SciTE.html
>
> Tron wrote:
>
> > What text editor would you guys recommend using?
> >
> > Thanks,
> > Tron
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From tim@johnsons-web.com  Thu May 10 17:31:35 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Thu, 10 May 2001 08:31:35 -0800
Subject: [Tutor] Text Editor?
In-Reply-To: <000f01c0d95d$54f37080$01000001@praxis>; from tron@submatrix.com on Thu, May 10, 2001 at 07:27:23AM -0700
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE> <000f01c0d95d$54f37080$01000001@praxis>
Message-ID: <20010510083135.A7640@johnsons-web.com>

On Thu, May 10, 2001 at 07:27:23AM -0700, Tron wrote:
> What text editor would you guys recommend using?
I use vim mostly: it is portable across multiple platforms
including Linux, Mac and Windows. www.vim.org
Some consider vim difficult to learn and an acquired
taste.

There is also emacs/xemacs available at www.xemacs.org,
I see ports for Windows,Mac,Unix,Linux there.

Those above are both open-source and free.

For Windows only, there is also Boxer. Available at
www.boxersoftware.com. It is Shareware, not free,
but is IMHO, the best combination of flexibility
and ease of use in the Windows environment.
-- 
Tim Johnson <tim@johnsons-web.com>
       http://www.johnsons-web.com
  "My shroe, my shroe, my dingkom for a shroe!"
  --TheManWhoSpeaksInAnagrams (Monty Python)


From szz@philoslabs.com  Thu May 10 17:18:39 2001
From: szz@philoslabs.com (Zoltan Szalay)
Date: Thu, 10 May 2001 18:18:39 +0200
Subject: [Tutor] Text Editor?
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE> <000f01c0d95d$54f37080$01000001@praxis> <3AFAAC48.543EE4AB@philoslabs.com> <3AFAB60C.94905B6C@seatech.fau.edu>
Message-ID: <3AFABF5F.FF69D7BB@philoslabs.com>

I do recommend trying SciTE.
It runs on Windows,Linux. It is eye-catching, versatile and yet very
fast (at least compared to others which use GTK or Gnome and are
available on Linux (and of course that I know of ...)).
One feature that can be very useful (and the web site doesn't mention I
think): autocompletition of functions (or keywords) showing
parameterlist as a tooltip. This needs an external file (so called
'api-file') containing "function-prototypes", and some setup in the
config. Different 'api-file' can be defined for every language. It is
ideal when you are not yet familiar using a language...

Zoltan Szalay

Benoit Dupire wrote:

> i did not know SciTE. The screenShot on the website looks great.
> I am using UltraEdit, which is not bad either....
>
> Benoit...
>
> Zoltan Szalay wrote:
>
> > My favourite is SciTE...
> > http://www.scintilla.org/SciTE.html
> >
> > Tron wrote:
> >
> > > What text editor would you guys recommend using?
> > >
> > > Thanks,
> > > Tron
> > >
> > > _______________________________________________
> > > Tutor maillist  -  Tutor@python.org
> > > http://mail.python.org/mailman/listinfo/tutor
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> --
> Benoit Dupire
> Graduate Student
> ----------------
> I'd like to buy a new Boomerang. How can i get rid of the old one?



From virketis@fas.harvard.edu  Thu May 10 17:26:55 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Thu, 10 May 2001 12:26:55 -0400
Subject: [Tutor] Text Editor?
Message-ID: <01051012265501.05151@virketis>

I am not sure why no one has mentioned the IDLE yet (is there some reason of 
which I, in my newbieism, am not aware of? :)). Check it out at 
http://www.python.org/idle/. It is cross-platform, obviously designed to work 
with Python, written by Guido and generaly quite nice. The only problem, of 
course, that it's still in development (current version with 2.0 is 0.6, and 
with 2.1 I think it's 0.8?): so you could get some exotic errors once in a 
while.

Pijus


From alan.gauld@bt.com  Thu May 10 17:13:45 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 May 2001 17:13:45 +0100
Subject: [Tutor] Text Editor?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D75B@mbtlipnt02.btlabs.bt.co.uk>

> What text editor would you guys recommend using?

The best one.

I use about 3 or 4 editors every day according to the job I'm doing.
For editting python code, which I assume is what you are asking 
us about I use:

IDLE - for quick prototyping

PythonWin for its folding capabilities(SciTE will have 
those too coz its built into scintilla...)

vim for seriously long editing sessions

ntnot(aka notgnu) a lightweight emacs clone for creating 
seriously long new files.
(I prefer emacs to vi for creating text but vi to emacs 
for editing existing text...)

Otherwise I use:

For email on unix I use xjove(another lightweight emacs with 
better OS integration)

For email on Windows I use Eudora at home and Outlook at work

For HTML documents I use vim or Homesite as the mood takes me

And for tty access to emote unix boxes I use ed.

I like them all for the things I use them for.

I repeat use the best tool for the job. For editing Python code 
use anything that can do syntax highlighting, indent/exdent 
of regions and good searching is always useful.

Otherwise play with a few and use the one that suits you best.
The only editors I didn't like were teco and Openwindow's 
textedit(I don't know why...)

Alan g


From arcege@speakeasy.net  Thu May 10 18:07:00 2001
From: arcege@speakeasy.net (Michael Reilly)
Date: Thu, 10 May 2001 13:07:00 -0400 (EDT)
Subject: [Tutor] Text Editor?
In-Reply-To: <01051012265501.05151@virketis>
Message-ID: <Pine.LNX.4.33L2.0105101249240.10490-100000@grace.speakeasy.net>


On Thu, 10 May 2001, Pijus Virketis wrote:

> I am not sure why no one has mentioned the IDLE yet (is there some reason of
> which I, in my newbieism, am not aware of? :)). Check it out at
> http://www.python.org/idle/. It is cross-platform, obviously designed to work
> with Python, written by Guido and generaly quite nice. The only problem, of
> course, that it's still in development (current version with 2.0 is 0.6, and
> with 2.1 I think it's 0.8?): so you could get some exotic errors once in a
> while.

Two simple reasons for myself.  I do a lot of different types of file
editing, Python included.  For this reason, it is a lot better for my to
use one common editor (using vi or vim).  The other reason is that idle
hasn't been all that configurable or that well documented.  One peeve I
have about it is the amount of indentation introduced.

But that is just me.  Choice of editors is usually very personal.

  -Arcege



From ium@micromuse.com  Thu May 10 18:51:45 2001
From: ium@micromuse.com (ibraheem umaru-mohammed)
Date: Thu, 10 May 2001 18:51:45 +0100
Subject: [Tutor] after string.split()
In-Reply-To: <000001c0d965$8cef6f40$de00a8c0@planhouse5>; from randrews@planhouse.com on Thu, May 10, 2001 at 10:26:14AM -0500
References: <000001c0d965$8cef6f40$de00a8c0@planhouse5>
Message-ID: <20010510185145.H22289@micromuse.com>

[Rob Andrews wrote...]
<snip>
-| a few points. This is how I initially tackle the file:
-| 
-| >>> for line in fileinput.input("mangleme.txt"):
-| 	words = string.split(line, ",")
-| 
-| And this is an abbreviated version of file contents:
-| 
-| "Primary Key","Name","Company","Address1","Address2","City","State","Zip"
-| 1,"John Q. Public","ACME Widgets","P.O. Box 12345",,"Auburn","AL","36831"
-| 
-| I need to remove the Primary Key field, for instance, while leaving the rest
-| of the file's contents intact. Can anyone recommend resources where I can
-| find out what I can do to the split "parts"?
-| 

Well, since no-one seems to have replied, here is my attempt:

--- cut here ---

#!/usr/bin/env python

import fileinput
import string
import sys

def process(line):
	line=string.join(string.split(line,",")[1:],",")
	sys.stdout.write(line)

for line in fileinput.input(sys.argv[1:], inplace=1, backup='.old'):
	process(line)

--- cut here ---

You can then use this as follows:

	$./remove_first_field.py file1 file2

And this should leave you with a backup of the original file (.old).

Hope that helps,

Kindest regards,

	--ibs.

-- 
Sometimes you get an almost irresistible urge to go on living.


From kromag@nsacom.net  Thu May 10 21:21:03 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Thu, 10 May 2001 13:21:03 -0700 (PDT)
Subject: [Tutor] .gifs and .bmps with PhotoImage()
Message-ID: <200105102021.f4AKL3o16400@pop.nsacom.net>

I have a need to display a .bmp image as a label in a Tkinter window.

Two-fold question: Can one use windows .bmp files with PhotoImage()?

If not, I know there is bound to be a library or suite for conversion! :-) 

What would be the best method to do said conversion?

Thanks!

d


From randrews@planhouse.com  Thu May 10 19:18:12 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Thu, 10 May 2001 13:18:12 -0500
Subject: [Tutor] after string.split()
In-Reply-To: <20010510185145.H22289@micromuse.com>
Message-ID: <000201c0d97d$935a9360$de00a8c0@planhouse5>

Thanks! I've been hacking something together, but it's definitely a hack and
has *undocumented features* to prove it. And yours has brevity and elegance
in comparison with mine, as well.

Would you object if I posted your code along with mine on Useless Python to
show the difference between a program and a hack?

Rob

Well, since no-one seems to have replied, here is my attempt:

--- cut here ---

#!/usr/bin/env python

import fileinput
import string
import sys

def process(line):
	line=string.join(string.split(line,",")[1:],",")
	sys.stdout.write(line)

for line in fileinput.input(sys.argv[1:], inplace=1, backup='.old'):
	process(line)

--- cut here ---

You can then use this as follows:

	$./remove_first_field.py file1 file2

And this should leave you with a backup of the original file (.old).

Hope that helps,

Kindest regards,

	--ibs.

--
Sometimes you get an almost irresistible urge to go on living.

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



From lsloan@umich.edu  Thu May 10 19:25:54 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 10 May 2001 14:25:54 -0400
Subject: [Tutor] Text Editor?
In-Reply-To: Your message of "Thu, 10 May 2001 09:42:06 CDT."
 <5.0.2.1.0.20010510094045.01f53180@Pop3.norton.antivirus>
Message-ID: <200105101825.OAA18352@birds.us.itd.umich.edu>

Kojo Idrissa wrote:
> Duck.

Hmm...  I've never heard of that editor before.  :)

I've never needed more than vi, however, I might consider vim.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From ium@micromuse.com  Thu May 10 19:30:18 2001
From: ium@micromuse.com (ibraheem umaru-mohammed)
Date: Thu, 10 May 2001 19:30:18 +0100
Subject: [Tutor] after string.split()
In-Reply-To: <000201c0d97d$935a9360$de00a8c0@planhouse5>; from randrews@planhouse.com on Thu, May 10, 2001 at 01:18:12PM -0500
References: <20010510185145.H22289@micromuse.com> <000201c0d97d$935a9360$de00a8c0@planhouse5>
Message-ID: <20010510193018.A929@micromuse.com>

[Rob Andrews wrote...]
-| 
-| Would you object if I posted your code along with mine on Useless Python to
-| show the difference between a program and a hack?
-| 

sure. i would be *honoured*.
i wouldn't post it too early though, there's probably an even better hack
due from one of the resident "gurus".

kindest regards,

	--ibs.

-- 
For fast-acting relief, try slowing down.


From virketis@fas.harvard.edu  Thu May 10 22:00:43 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Thu, 10 May 2001 17:00:43 -0400
Subject: [Tutor] checking for a condition across all members of a list
 simultaneously
In-Reply-To: <E14xssa-0005BI-00@mail.python.org>
Message-ID: <200105102056.QAA02124@smtp2.fas.harvard.edu>

Hi!

I am writing a little crosses-and-naughts game. At its heart is a n*m
matrix of Cells, instances of a class that represents the states of a
single cell (i.e. "-", "x" and "o"). I can set_state() and return_state().
Now I need to implement victory checks. So, for instance, the horizontal
check would in principle go something like this:

def check_horizontal(Matrix):
	for row in Matrix:
		if row[0].return_state() == row[1].return_state() == row[2].return_state(): 
			print "victory!"

Except that I, perhaps out of stubbornness, really don't want to build in
the dimensions of my matrix into the code (what if someone wants to try out
a 5*5 x-o game? :)). What's a nice way of going across the whole row (or
down a column, in the next step)?

Thanks!

Pijus
----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis.


From kromag@nsacom.net  Fri May 11 00:14:56 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Thu, 10 May 2001 16:14:56 -0700 (PDT)
Subject: [Tutor] Resizing .gif images with resize() from PIL
Message-ID: <200105102314.f4ANEuo03607@pop.nsacom.net>

I am getting some rather confusing output from PIL. It does an excellent job 
of converting one format to another(in this case BMP to GIF). However 
resizing has been problematic for me.

when I attempt 

import Image
# import os, sys
im=Image.open("\windows\desktop\johnny_rotten.bmp")
#image starts out at 1449, 961. Too big!
im.resize(900, 412)
im.save("\windows\desktop\jah_wobble.gif", "GIF") 

I get

Traceback (most recent call last):
  File "flip-flop-testing.py", line 4, in ?
    im.resize(900, 412)
  File "c:python20pilImage.py", line 632, in resize
    raise ValueError, "unknown resampling filter"
ValueError: unknown resampling filter

Which error I have searched for to no avail.

When I try the thumbnail call:

import Image
# import os, sys
im=Image.open("\windows\desktop\johnny_rotten.bmp")
im.thumbnail(900, 412)
im.save("\windows\desktop\jah_wobble.gif", "GIF") 

Traceback (most recent call last):
  File "flip-flop-testing.py", line 4, in ?
    im.thumbnail(900, 412)
TypeError: too many arguments; expected 2, got 3

Yow! Back to the drawing board.

import Image
# import os, sys
im=Image.open("\windows\desktop\album.bmp")
im.thumbnail((900, 412))
im.save("\windows\desktop\anger_is_an_energy.gif", "GIF") 

Works, except the image is horribly blurry and blocky. It looks like 
something converted from JPG to GIF under an old version of photoshop! :-)

Is thumbnail for jpegs only? And why is resize croaking? I must admit 
confusion.

d



From dyoo@hkn.eecs.berkeley.edu  Thu May 10 23:05:30 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 10 May 2001 15:05:30 -0700 (PDT)
Subject: [Tutor] Simple line drawing in Python
Message-ID: <Pine.LNX.4.21.0105101457280.19917-300000@hkn.eecs.berkeley.edu>

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--545289610-1584610050-989532330=:19917
Content-Type: TEXT/PLAIN; charset=US-ASCII

Hiya everyone,

I've written a small wrapper around a Tkinter Canvas which lets people
play around with line drawing.  Once loaded, graphics.py makes a 400x400
canvas and provides global functions to meddle with it.

The graphics.py module is meant to be "from graphics import *"'ed; once
you the import, the following functions become available:

    clearGraphics()
    positionPen(x, y)
    drawLineTo(x, y)
    drawLine(x1, y1, x2, y2)
    drawPoint(x, y)
    clearPoint(x, y)
    graphicsText(text, x, y)
    setRGBColor(r, g, b)

and the included circle.py demonstrates how to use graphics.py's features.  
What's neat about this is that if the user accidently closes the Canvas,
calling any of the above functions should magically sprout a new Canvas
without prompting.

I'd like some suggestions on this; I want to make sure that this thing is
useful for people.

--545289610-1584610050-989532330=:19917
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="circle.py"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.21.0105101505300.19917@hkn.eecs.berkeley.edu>
Content-Description: 
Content-Disposition: attachment; filename="circle.py"

IyMgVGhpcyBwaWVjZSBvZiBjb2RlIGdpdmVzIHVzIG9uZSB3YXkgdG8gZHJh
dyBhIGNpcmNsZSBpbiBQeXRob24uDQojIyBJdCdzIG5vdCBwYXJ0aWN1bGFy
bHkgZWZmaWNpZW50LCBidXQgaXQncyBjdXRlLg0KIyMNCiMjIGR5b29AaGtu
LmVlY3MuYmVya2VsZXkuZWR1DQojIw0KIyMgTGV0J3Mgc2F5IHRoYXQgd2Ug
d3JpdGUgYSBwcm9ncmFtIHRvIGRyYXcgcmVndWxhciBwb2x5Z29ucyBvZiBu
DQojIyBwb2ludHMuICBGb3IgZXhhbXBsZSwgZm9yIG49Mywgd2UgZ2V0IGEg
dHJpYW5nbGUuICBGb3Igbj00LCB3ZSBoYXZlDQojIyBhIHNxdWFyZSwgYW5k
IHNvIG9uLiAgV2hhdCBoYXBwZW5zIHdoZW4gbiBnZXRzIGxhcmdlciBhbmQg
bGFyZ2VyPw0KIyMNCiMjIE9uZSBpZGVhIGZvciBkcmF3aW5nIGEgY2lyY2xl
IGlzIHRvIGRyYXcgb3VyIHBvbHlnb24gd2l0aCBsYXJnZXINCiMjIGFuZCBs
YXJnZXIgbiwgdW50aWwgd2UgZ2V0IHNvbWV0aGluZyBzYXRpc2ZhY3Rvcnku
ICBUaGlzIHByb2dyYW0NCiMjIHNob3dzIGEgdmlzdWFsIGRlc2NyaXB0aW9u
cyBvZiB0aGlzIHByb2Nlc3MuICBUaGUgbWFpbiBwcm9ncmFtIGlzDQojIyB0
ZXN0LWNpcmNsZXMsIHdoaWNoIGRlbW9uc3RyYXRlcyBob3cgYSBwb2x5Z29u
IG1hZGUgb2Ygc3RyYWlnaHQNCiMjIGxpbmVzIGNhbiBjb252ZXJnZSB0byBh
IGNpcmNsZS4NCg0KZnJvbSBncmFwaGljcyBpbXBvcnQgKg0KZnJvbSB0aW1l
IGltcG9ydCBzbGVlcA0KZnJvbSBtYXRoIGltcG9ydCBwaSwgY29zLCBzaW4N
Cg0KIyMgVHJ5IHJ1bm5pbmcgdGVzdENpcmNsZXMgd2l0aCBuPTQwIGFuZCBk
ZWxheT0uNSBmb3IgYSBuaWNlIGFuaW1hdGluZw0KIyMgZWZmZWN0Lg0KZGVm
IHRlc3RDaXJjbGVzKG4sIGRlbGF5KToNCiAgICBjaXJjbGVfcmFkaXVzID0g
MTcwDQogICAgZm9yIG4gaW4gcmFuZ2UoMywgbiszKToNCiAgICAgICAgY2xl
YXJHcmFwaGljcygpDQogICAgICAgIGRyYXdDbG9zZWRQb2x5Z29uKG1ha2VO
UG9seWdvbihjaXJjbGVfcmFkaXVzLCBuKSkNCiAgICAgICAgc2xlZXAoZGVs
YXkpDQoNCiMjIEhlcmUncyB0aGUgaGVhcnQgb2YgdGhlIHByb2dyYW06IGdp
dmVuIHJhZGl1cyBhbmQgbiwgcmV0dXJucyBiYWNrDQojIyB0byB1cyBhIGxp
c3Qgb2YgcG9pbnRzIHRoYXQgc2hvdWxkIGNvbnN0cnVjdCBhIHJlZ3VsYXIg
bi1wb2x5Z29uDQojIyB3aG9zZSBwb2ludHMgYXJlIGFsbCByZWxhdGl2ZSB0
byAoMCwgMCkuDQpkZWYgbWFrZU5Qb2x5Z29uKHJhZGl1cywgbik6DQogICBk
ZWdyZWVzID0gZGl2aWRlVXAzNjBJbnRvRGVncmVlcyhuKQ0KICAgdGhldGFz
ID0gbWFwKGRlZ1RvUmFkLCBkZWdyZWVzKQ0KICAgcmV0dXJuIFtwb2xhclRv
UmVjdChyYWRpdXMsIHQpIGZvciB0IGluIHRoZXRhc10NCg0KDQojIyBEcmF3
cyBhIGNsb3NlZCBwb2x5Z29uIG9mIHBvaW50cy4gIEZvciBleGFtcGxlOg0K
IyMgICAgZHJhd0Nsb3NlZFBvbHlnb24oWygxMDAgMCksICgxMDAgMTAwKSwg
KDAgMCldKQ0KIyMgc2hvdWxkIGRyYXcgYSBzbWFsbCB0cmlhbmdsZS4NCmRl
ZiBkcmF3Q2xvc2VkUG9seWdvbihwb2ludHMpOg0KICAgIHBvaW50cyA9IHBv
aW50cyArIFtwb2ludHNbMF1dDQogICAgZm9yIGkgaW4gcmFuZ2UobGVuKHBv
aW50cykgLSAxKToNCiAgICAgICAgKCh4MSwgeTEpLCAoeDIsIHkyKSkgPSAo
cG9pbnRzW2ldLCBwb2ludHNbaSsxXSkNCiAgICAgICAgZHJhd0xpbmUoeDEs
IHkxLCB4MiwgeTIpDQoNCg0KIyMgVGFrZXMgaW4gYSByYWRpdXMgYW5kIGFu
IHRoZXRhIGluIHJhZGlhbnMsIGdpdmVzIGJhY2sgdG8gdXMgdGhlDQojIyBw
YXJ0aWN1bGFyICh4LHkpIGNvb3JkaW5hdGUgdGhhdCBtYXRjaGVzIHRoaXMg
ZGVzY3JpcHRpb24uDQpkZWYgcG9sYXJUb1JlY3QocmFkaXVzLCB0aGV0YSk6
DQogICAgcmV0dXJuIChyYWRpdXMgKiBjb3ModGhldGEpLCByYWRpdXMgKiBz
aW4odGhldGEpKQ0KDQoNCiMjIGRlZ1RvUmFkIGFuZCByYWRUb0RlZyBjb252
ZXJ0IGJldHdlZW4gcmFkaWFucyBhbmQgZGVncmVlcyBhY2NvcmRpbmcNCiMj
IHRvIHRoZSBlcXVhbGl0eTogMSBkZWdyZWUgPSAocGkvMTgwKSByYWRpYW5z
LiAgV2UnbGwgbmVlZCB0aGlzDQojIyBiZWNhdXNlIFB5dGhvbidzIHRyaWdv
bm9tZXRyaWMgZnVuY3Rpb25zIGRlYWwgZW50aXJlbHkgd2l0aA0KIyMgcmFk
aWFucywgd2hpbGUgaHVtYW5zIHVzdWFsbHkgYXJlIG1vcmUgY29tZm9ydGFi
bGUgd2l0aCBkZWdyZWVzLg0KZGVmIGRlZ1RvUmFkKGRlZ3JlZXMpOiByZXR1
cm4gZGVncmVlcyAqIHBpIC8gMTgwDQpkZWYgcmFkVG9EZWcocmFkaWFucyk6
IHJldHVybiAoMTgwICogcmFkaWFucykgLyBwaQ0KDQoNCiMjIEdpdmVuIG4s
IHJldHVybnMgYSBsaXN0IG9mIGRlZ3JlZXMgdGhhdCBlcXVhbGx5IGRpdmlk
ZSAzNjAgZGVncmVlcy4NCiMjIEZvciBleGFtcGxlLCBhIHRyaWFuZ2xlIGNl
bnRlcmVkIGF0IHRoZSBvcmlnaW4gaGFzIHZlcnRpY2VzIG9yaWVudGVkDQoj
IyBhdCAwLCAxMjAsIGFuZCAyNDAgYW5nbGVzLg0KZGVmIGRpdmlkZVVwMzYw
SW50b0RlZ3JlZXMobik6DQogICAgYW5nbGUgPSAzNjAuMCAvIG4NCiAgICBy
ZXR1cm4gW2FuZ2xlICogeCBmb3IgeCBpbiByYW5nZShuKV0NCg0KDQo=
--545289610-1584610050-989532330=:19917
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="graphics.py"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.21.0105101505301.19917@hkn.eecs.berkeley.edu>
Content-Description: 
Content-Disposition: attachment; filename="graphics.py"

IiIiVGhpcyBpcyBhIHNtYWxsIGdyYXBoaWNzIG1vZHVsZSB0aGF0IG1pbWlj
cyBzb21lIHRoZSBmdW5jdGlvbmFsaXR5DQpvZiB3aGF0IHRoZSBDUzMgc3R1
ZGVudHMgdXNlIHRvIGRvIGZyYWN0YWwgZ3JhcGhpY3MuICBJdCdzIHNpbXBs
aWZpZWQNCmJlY2F1c2UgdGhlIGNvb3JkaW5hdGVzIGFyZSBjZW50ZXJlZCBh
dCAoMCwgMCkgaW4gdGhlIG1pZGRsZSBvZiB0aGUNCnNjcmVlbiBhbmQgaXQg
dXNlcyBmYW1pbGlhciBjb29yZGluYXRlIG9yaWVudGF0aW9uLiIiIg0KDQoj
IEknbSB0cnlpbmcgdG8gbWFrZSB0aGlzIGltcG9ydCBzYWZlLg0KDQppbXBv
cnQgVGtpbnRlcg0KaW1wb3J0IHN0cmluZw0KDQpjbGFzcyBHcmFwaGljczoN
CiAgICBkZWYgX19pbml0X18oc2VsZiwgcm9vdCk6DQogICAgICAgIHNlbGYu
X3Jvb3QgPSByb290DQogICAgICAgIHNlbGYuX3hwb3MsIHNlbGYuX3lwb3Mg
PSAwLCAwDQogICAgICAgIHNlbGYuX3dpZHRoID0gNDAwDQogICAgICAgIHNl
bGYuX2hlaWdodCA9IDQwMA0KICAgICAgICBzZWxmLl9yZ2IgPSAnIzAwMDAw
MCcgICMgRGVmYXVsdCBzaG91bGQgYmUgYmxhY2sNCiAgICAgICAgc2VsZi5f
Y2FudmFzID0gVGtpbnRlci5DYW52YXMoc2VsZi5fcm9vdCwgd2lkdGg9c2Vs
Zi5fd2lkdGgsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgIGhlaWdodD1zZWxmLl9oZWlnaHQsIGJnPSd3aGl0ZScpDQogICAgICAg
IHNlbGYuX2NhbnZhcy5wYWNrKCkNCiAgICAgICAgc2VsZi5jbGVhckdyYXBo
aWNzKCkNCg0KICAgIGRlZiBjbGVhckdyYXBoaWNzKHNlbGYpOg0KICAgICAg
ICAiIiJDbGVhciB0aGUgc2NyZWVuIG9mIGFsbCBkcmF3aW5ncy4iIiINCiAg
ICAgICAgZm9yIGlkIGluIHNlbGYuX2NhbnZhcy5maW5kX2FsbCgpOg0KICAg
ICAgICAgICAgc2VsZi5fY2FudmFzLmRlbGV0ZShpZCkNCg0KICAgIGRlZiBw
b3NpdGlvblBlbihzZWxmLCB4LCB5KToNCiAgICAgICAgIiIiTW92ZSB0aGUg
cGVuIHRvIHRoZSBzcGVjaWZpYyBwb3NpdGlvbi4iIiINCiAgICAgICAgc2Vs
Zi5feHBvcywgc2VsZi5feXBvcyA9IHgsIHkNCg0KICAgIGRlZiBkcmF3TGlu
ZVRvKHNlbGYsIHgsIHkpOg0KICAgICAgICAiIiJEcmF3IHRoZSBsaW5lIGZy
b20gdGhlIGN1cnJlbnQgcG9zaXRpb24gdG8gKHgsIHkpLg0KICAgICAgICBB
cyBhIHNpZGUgZWZmZWN0LCB0aGUgY3VycmVudCBwb3NpdGlvbiBiZWNvbWVz
ICh4LCB5KS4iIiINCiAgICAgICAgeDEsIHkxID0gc2VsZi5jb252ZXJ0Q29v
cmQoc2VsZi5feHBvcywgc2VsZi5feXBvcykNCiAgICAgICAgeDIsIHkyID0g
c2VsZi5jb252ZXJ0Q29vcmQoeCwgeSkNCiAgICAgICAgc2VsZi5fY2FudmFz
LmNyZWF0ZV9saW5lKHgxLCB5MSwgeDIsIHkyLCBmaWxsPXNlbGYuX3JnYikN
CiAgICAgICAgc2VsZi5fY2FudmFzLnVwZGF0ZSgpDQogICAgICAgIHNlbGYu
cG9zaXRpb25QZW4oeCwgeSkNCg0KICAgIGRlZiBkcmF3TGluZShzZWxmLCB4
MSwgeTEsIHgyLCB5Mik6DQogICAgICAgICIiIkRyYXcgYSBsaW5lIGZyb20g
KHgxLCB5MSkgdG8gKHgyLCB5MikuICBBcyBhIHNpZGUgZWZmZWN0LA0KICAg
ICAgICB0aGUgY3VycmVudCBwb3NpdGlvbiBiZWNvbWVzICh4MiwgeTIpLiIi
Ig0KICAgICAgICBzZWxmLnBvc2l0aW9uUGVuKHgxLCB5MSkNCiAgICAgICAg
c2VsZi5kcmF3TGluZVRvKHgyLCB5MikNCg0KICAgIGRlZiBkcmF3UG9pbnQo
c2VsZiwgeCwgeSk6DQogICAgICAgICIiIkRyYXcgYSBzaW5nbGUgcG9pbnQg
YXQgKHgsIHkpLiAgQXMgYSBzaWRlIGVmZmVjdCwNCiAgICAgICAgdGhlIGN1
cnJlbnQgcG9zaXRpb24gYmVjb21lcyAoeCwgeSkuIiIiDQogICAgICAgIHNl
bGYucG9zaXRpb25QZW4oeDEsIHkxKQ0KICAgICAgICB4MSwgeTEgPSBzZWxm
LmNvbnZlcnRDb29yZCh4LCB5KQ0KICAgICAgICBzZWxmLl9jYW52YXMuY3Jl
YXRlX292YWwoeDEsIHkxLCB4MSwgeTEsIG91dGxpbmU9c2VsZi5fcmdiKQ0K
ICAgICAgICBzZWxmLl9jYW52YXMudXBkYXRlKCkNCg0KICAgIGRlZiBjbGVh
clBvaW50KHNlbGYsIHgsIHkpOg0KICAgICAgICAiIiJDbGVhcnMgYSBzaW5n
bGUgcG9pbnQgYXQgKHgsIHkpLiAgQXMgYSBzaWRlIGVmZmVjdCwNCiAgICAg
ICAgdGhlIGN1cnJlbnQgcG9zaXRpb24gYmVjb21lcyAoeCwgeSkuIiIiDQog
ICAgICAgIHNlbGYucG9zaXRpb25QZW4oeDEsIHkxKQ0KICAgICAgICBiZ2Nv
bG9yID0gc2VsZi5fY2FudmFzLmNnZXQoJ2JnJykNCiAgICAgICAgeDEsIHkx
ID0gc2VsZi5jb252ZXJ0Q29vcmQoeCwgeSkNCiAgICAgICAgc2VsZi5fY2Fu
dmFzLmNyZWF0ZV9vdmFsKHgxLCB5MSwgeDEsIHkxLCBvdXRsaW5lPWJnY29s
b3IpDQogICAgICAgIHNlbGYuX2NhbnZhcy51cGRhdGUoKQ0KICAgIA0KICAg
IGRlZiBncmFwaGljc1RleHQoc2VsZiwgbXNnLCB4LCB5KToNCiAgICAgICAg
IiIiV3JpdGVzIGEgbGluZSBvZiB0ZXh0LCBsZWZ0IGp1c3RpZmVkIGZyb20g
KHgsIHkpLiIiIg0KICAgICAgICB4MSwgeTEgPSBzZWxmLmNvbnZlcnRDb29y
ZCh4LCB5KQ0KICAgICAgICBzZWxmLl9jYW52YXMuY3JlYXRlX3RleHQoeDEs
IHkxLCB0ZXh0PW1zZywgZmlsbD1zZWxmLl9yZ2IpDQogICAgICAgIHNlbGYu
X2NhbnZhcy51cGRhdGUoKQ0KICAgIA0KICAgIGRlZiBzZXRSR0JDb2xvcihz
ZWxmLCByLCBnLCBiKToNCiAgICAgICAgIiIiQ2hhbmdlcyB0aGUgY3VycmVu
dCBjb2xvciB0byAociwgZywgYiksIHdoZXJlDQogICAgICAgIGVhY2ggY29t
cG9uZW50IGlzIGEgdmFsdWUgYmV0d2VlbiAwIGFuZCAyNTUuIiIiDQogICAg
ICAgIHNlbGYuX3JnYiA9ICcjJTAyWCUwMlglMDJYJyAlIChyLCBnLCBiKQ0K
DQogICAgZGVmIGNvbnZlcnRDb29yZChzZWxmLCB4LCB5KToNCiAgICAgICAg
bmV3eCA9IHNlbGYuX3dpZHRoLzIgKyB4DQogICAgICAgIG5ld3kgPSBzZWxm
Ll9oZWlnaHQvMiAtIHkNCiAgICAgICAgcmV0dXJuIG5ld3gsIG5ld3kNCg0K
DQoNCiIiIkhlcmUgYXJlIHNvbWUgZ2xvYmFsIGZ1bmN0aW9ucyBhbmQgdmFy
aWFibGVzIHRvIG1ha2UgdGhpbmdzIGVhc2llcg0KZm9yIGEgYmVnaW5uZXIg
dW5hY2N1c3RvbWVkIHRvIE9PUC4gIE5vdGU6IHRoaXMgaXMgdWdseSBiZWNh
dXNlIHdlDQpuZWVkIGFuIGV4dHJhIGxldmVsIG9mIGluZGlyZWN0aW9uIGhl
cmU6IHdlIHdhbnQgdG8gbWFrZSAiZnJvbQ0KZ3JhcGhpY3MgaW1wb3J0ICoi
IHdvcmssIGJ1dCB0aGlzIHRha2VzIHNvbWUgc2lsbGluZXNzIHRvIGdldCBp
dA0Kd29ya2luZyB3ZWxsLiAgTWlzZXJ5IG9mIHRoZSBmZXcgZm9yIHRoZSBq
b3kgb2YgdGhlIG1hbnkuICAqZ3JpbioiIiINCg0KDQoiIiJPdXIgZ2xvYmFs
IGdyYXBoaWNzIG9iamVjdC4iIiINCl9fZ3JhcGhpY3MgPSBOb25lDQoNCg0K
IiIiRm9yIGVhY2ggb2YgdGhlIGludGVyZXN0aW5nIG1lbWJlciBmdW5jdGlv
bnMgd2l0aGluIGEgR3JhcGhpY3MNCm9iamVjdCwgd2UnbGwgbWFrZSBhIGNv
cnJlc3BvbmRpbmcgZ2xvYmFsIGZ1bmN0aW9uIHRoYXQgd29ya3Mgb24gYQ0K
ZGVmYXVsdCB0b3BsZXZlbCB3aW5kb3cuICBUaGUgdHJpY2t5IHBhcnQgaXMg
dG8gYWNjb3VudCBmb3Igd2hhdA0KaGFwcGVucyB3aGVuIHRoZSB1c2VyIGRl
c3Ryb3lzIHRoZSB3aW5kb3c6IHdlIG5lZWQgdG8gZHluYW1pY2FsbHkNCnJl
Y3JlYXRlIGFuZCBob29rIHRoZSBmdW5jdGlvbnMgYmFjayB1cCB0byBhIG5l
dyBpbnN0YW5jZSBvZg0KR3JhcGhpY3MuICBUaGlzIGNvZGUgaXMgc3VidGxl
IGFuZCBuZWVkcyBzb21lIGV4cGxhbmF0aW9uOg0KDQpXZSBleHBvc2UgdG8g
dGhlIHVzZXIgdGhlIGxpc3Qgb2YgX193cmFwcGVkRnVuY3Rpb25zLiAgVW5k
ZXJuZWF0aCwNCnRob3NlIGZ1bmN0aW9uIGFyZSBhY3R1YWxseSB3cmFwcGVy
cyBhcm91bmQgdGhlIGFjdHVhbA0KaW1wbGVtZW50YXRpb25zLiAgRm9yIGV4
YW1wbGUsIHBvc2l0aW9uUGVuKCkgaXMganVzdCBhIHdyYXBwZXIgYXJvdW5k
DQpfX3Bvc2l0aW9uUGVuKCkuDQoNCldoZW5ldmVyIG91ciBHcmFwaGljcyBv
YmplY3QgaXMgZGVzdHJveWVkLCB3ZSBuZWVkIHRvIHJlaW5pdGlhbGl6ZSB0
aGUNCmltcGxlbWVudGF0aW9uIGZ1bmN0aW9ucyBhdCB0aGUgbWVtYmVycyBv
ZiBfX2dyYXBoaWNzLiAgVGhpcyBpcyB3aGF0DQpfX3Jlc2V0R3JhcGhpY3Mo
KSBkb2VzLiIiIg0KDQoNCg0KX193cmFwcGVkRnVuY3Rpb25zID0gc3RyaW5n
LnNwbGl0KCIiInBvc2l0aW9uUGVuIGRyYXdMaW5lVG8gZHJhd0xpbmUNCmRy
YXdQb2ludCBjbGVhclBvaW50IGdyYXBoaWNzVGV4dCBzZXRSR0JDb2xvciIi
IikNCg0KDQoiIiJUaGUgZm9sbG93aW5nIGNyZWF0ZXMgYWxsIHRoZSBuaWNl
IHdyYXBwZXIgZnVuY3Rpb25zLiIiIg0KX193cmFwcGVyVGVtcGxhdGUgPSAi
IiINCmRlZiAlKGZ1bmN0aW9uX25hbWUpcygqYXJncyk6DQogICAgdHJ5OiBh
cHBseShfXyUoZnVuY3Rpb25fbmFtZSlzLCBhcmdzKQ0KICAgIGV4Y2VwdCBU
a2ludGVyLlRjbEVycm9yOg0KICAgICAgICBjbGVhckdyYXBoaWNzKCkNCiAg
ICAgICAgYXBwbHkoX18lKGZ1bmN0aW9uX25hbWUpcywgYXJncykNCl9fJShm
dW5jdGlvbl9uYW1lKXMgPSBOb25lDQoiIiINCmZvciBmdW5jdGlvbl9uYW1l
IGluIF9fd3JhcHBlZEZ1bmN0aW9uczoNCiAgICBleGVjIF9fd3JhcHBlclRl
bXBsYXRlICUgeydmdW5jdGlvbl9uYW1lJyA6IGZ1bmN0aW9uX25hbWV9DQoN
Cg0KZGVmIGNsZWFyR3JhcGhpY3MoKToNCiAgICBfX3Jlc2V0R3JhcGhpY3Mo
KQ0KICAgIF9fcmVzZXRGdW5jdGlvbnMoKQ0KICAgIF9fZ3JhcGhpY3MuY2xl
YXJHcmFwaGljcygpDQoNCg0KZGVmIF9fcmVzZXRHcmFwaGljcygpOg0KICAg
IGdsb2JhbCBfX2dyYXBoaWNzDQogICAgaWYgVGtpbnRlci5fZGVmYXVsdF9y
b290ID09IE5vbmU6DQogICAgICAgIFRraW50ZXIuX2RlZmF1bHRfcm9vdCA9
IFRraW50ZXIuVGsoKQ0KICAgICAgICBfX2dyYXBoaWNzID0gTm9uZQ0KICAg
IGlmIF9fZ3JhcGhpY3MgPT0gTm9uZToNCiAgICAgICAgX19ncmFwaGljcyA9
IEdyYXBoaWNzKFRraW50ZXIuX2RlZmF1bHRfcm9vdCkNCg0KDQpkZWYgX19y
ZXNldEZ1bmN0aW9ucygpOg0KICAgIHRlbXBsYXRlID0gJycnDQpnbG9iYWwg
X18lKGZ1bmN0aW9uX25hbWUpcw0KX18lKGZ1bmN0aW9uX25hbWUpcyA9IF9f
Z3JhcGhpY3MuJShmdW5jdGlvbl9uYW1lKXMNCicnJw0KICAgIGZvciBmdW5j
dGlvbl9uYW1lIGluIF9fd3JhcHBlZEZ1bmN0aW9uczoNCiAgICAgICAgZXhl
YyB0ZW1wbGF0ZSAlIHsnZnVuY3Rpb25fbmFtZScgOiBmdW5jdGlvbl9uYW1l
fQ0KDQoNCiMjIExldCdzIHN0YXJ0IHRoZSBtYWdpYy4NCmNsZWFyR3JhcGhp
Y3MoKQ0KDQo=
--545289610-1584610050-989532330=:19917--


From wall@adinet.com.uy  Thu May 10 23:05:19 2001
From: wall@adinet.com.uy (Walter Moreira)
Date: Thu, 10 May 2001 19:05:19 -0300
Subject: [Tutor] Text Editor?
In-Reply-To: <000f01c0d95d$54f37080$01000001@praxis>; from tron@submatrix.com on Thu, May 10, 2001 at 07:27:23AM -0700
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE> <000f01c0d95d$54f37080$01000001@praxis>
Message-ID: <20010510190519.C32756@casa.parque>

On Thu, May 10, 2001 at 07:27:23AM -0700, Tron wrote:
> What text editor would you guys recommend using?

So far, vim is winning. But I would like to say that emacs is also a very good
choice. The *python-mode.el* is excelent. It can interact with the debugger
showing step-by-step the place where you are in the source code, this is a lot
better than executing pdb in the console.

Perhaps emacs is an OS, but at least you need not to reboot to use it :-)
Just my $0.02

-- Walter

-- 
--------------
Walter Moreira  <> Centro de Matematica  <> Universidad de la Republica
email: walterm@cmat.edu.uy <> HomePage: http://www.cmat.edu.uy/~walterm
                 +-----------------------------------------------------
        /OD\_    |   Contrary to popular belief, Unix is user friendly.
 O o . |_o_o_)   |   It just happens to be very selective about who its
                 |   friends are.                         -- Kyle Hearn
               --+--


From wheelege@tsn.cc  Thu May 10 23:07:23 2001
From: wheelege@tsn.cc (wheelege)
Date: Fri, 11 May 2001 08:07:23 +1000
Subject: [Tutor] Text Editor?
References: <200105100707_MC2-D074-32A6@compuserve.com> <025101c0d950$040632a0$0200a8c0@ACE> <000f01c0d95d$54f37080$01000001@praxis>
Message-ID: <00c501c0d99d$97939ba0$0200a8c0@ACE>


> What text editor would you guys recommend using?
>

  For python I use Pythonwin - it can handle threads properly, and IDLE has
some other stress problems (both known bugs, check the sourceforge site).
  For other languages I usually use joe...but man, I need to upgrade.

  Glen.



From walterv@jps.net  Thu May 10 23:47:14 2001
From: walterv@jps.net (Walter Vannini)
Date: Thu, 10 May 2001 15:47:14 -0700
Subject: [Tutor] Resizing .gif images with resize() from PIL
References: <200105102314.f4ANEuo03607@pop.nsacom.net>
Message-ID: <3AFB1A72.2A9349E2@jps.net>

There are two major problems with the use of resize here.
The first is that the size (900 by 412 in this example)
has to passed in as a single variable (for example, as a tuple
like (900,412) ).
The second is that the return value has to be used
for saving.
The original image object is not changed. Instead, a new image
object that is a resized version of the original is returned.

The code snippet
 im.resize(900, 412)
 im.save("\windows\desktop\jah_wobble.gif", "GIF")

should be changed to something like
 newim = im.resize( (900,412) )
 newim.save(r"\windows\desktop\jah_wobble.gif", "GIF")

Walter.

> I am getting some rather confusing output from PIL. It does an excellent job
> of converting one format to another(in this case BMP to GIF). However
> resizing has been problematic for me.
> 
> when I attempt
> 
> import Image
> # import os, sys
> im=Image.open("\windows\desktop\johnny_rotten.bmp")
> #image starts out at 1449, 961. Too big!
> im.resize(900, 412)
> im.save("\windows\desktop\jah_wobble.gif", "GIF")
> 
> I get
> 
> Traceback (most recent call last):
>   File "flip-flop-testing.py", line 4, in ?
>     im.resize(900, 412)
>   File "c:python20pilImage.py", line 632, in resize
>     raise ValueError, "unknown resampling filter"
> ValueError: unknown resampling filter
> 
> Which error I have searched for to no avail.
...
> why is resize croaking? I must admit
> confusion.


From kojo@hal-pc.org  Fri May 11 01:03:05 2001
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Thu, 10 May 2001 19:03:05 -0500
Subject: [Tutor] software design
In-Reply-To: <000801c0a4ca$158bb3c0$bf52b1cf@oemcomputer>
Message-ID: <5.0.2.1.0.20010510185812.020ec568@Pop3.norton.antivirus>

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

Cameron,

I was going back through the archive a couple of days ago and noticed this 
question you asked.  A couple of minutes ago I came across this link from a 
local (to me) university.
<http://www.cs.rice.edu/CS/PLT/Teaching/Lectures/Released/>
It's for a presentation called..."How to Design Programs".

Hope this is helpful.  I didn't feel like going through every response, so 
I'm not sure if someone's already sent this to you.

BTW, you have a lot of interesting questions.  What method are you using to 
teach yourself Python?  It seems to be working for you, and I'd like to be 
able to add it to my list of suggested methods for other people who 
want/need to learn to program.  You may have told us before, but I missed 
it.  I'm just coming out of lurk mode.


At 10:42 AM 3/4/2001 -0600, Katharine Stoner wrote:
>Hi all,
>
>Does anyone know of a good scource on how to design programs before you 
>start programming?
>
>-Cameron Stoner

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

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************
--=====================_195088222==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
Cameron,<br>
<br>
I was going back through the archive a couple of days ago and noticed
this question you asked.&nbsp; A couple of minutes ago I came across this
link from a local (to me) university.<br>
&lt;<a href="http://www.cs.rice.edu/CS/PLT/Teaching/Lectures/Released/" eudora="autourl">http://www.cs.rice.edu/CS/PLT/Teaching/Lectures/Released/</a>&gt;<br>
It's for a presentation called...&quot;How to Design 
Programs&quot;.<br>
<br>
Hope this is helpful.&nbsp; I didn't feel like going through every
response, so I'm not sure if someone's already sent this to you.<br>
<br>
BTW, you have a lot of interesting questions.&nbsp; What method are you
using to teach yourself Python?&nbsp; It seems to be working for you, and
I'd like to be able to add it to my list of suggested methods for other
people who want/need to learn to program.&nbsp; You may have told us
before, but I missed it.&nbsp; I'm just coming out of lurk mode.<br>
<br>
<br>
At 10:42 AM 3/4/2001 -0600, Katharine Stoner wrote:<br>
<blockquote type=cite class=cite cite><font face="arial" size=2>Hi
all,</font><br>
&nbsp;<br>
<font face="arial" size=2>Does anyone know of a good scource on how to
design programs before you start programming?</font><br>
&nbsp;<br>
<font face="arial" size=2>-Cameron Stoner</font></blockquote>
<x-sigsep><p></x-sigsep>
**************************** <br>
Kojo Idrissa <br>
&nbsp; <br>
kojo@hal-pc.org<br>
<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http</a>://www.hal-pc.org<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">/~kojo/</a><br>
****************************</html>

--=====================_195088222==_.ALT--



From arazak@kansai.com.my  Fri May 11 01:59:18 2001
From: arazak@kansai.com.my (Mr. Razak)
Date: Fri, 11 May 2001 08:59:18 +0800
Subject: [Tutor] Step by step tutorials
Message-ID: <004801c0d9b5$cc7065c0$6a01a8c0@com.my>

This is a multi-part message in MIME format.

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

I have already study python language for more than one month. But until =
now I still cannot catch-up with the language.=20
I already read the tutorial in the web but not much help.
Before this I used pascal and foxpro language but it not support OOP. =
That why I learn python.=20

I need some help in learning this language step by step in details. =
Where can I get it...

I'm using windows flat form. For your info. I cannot find any python =
books in my country. Over here a lot of people using perl.=20

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I have already study python language =
for more than=20
one month. But until now I still cannot catch-up with the language.=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I already read the tutorial in the web =
but not much=20
help.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Before this&nbsp;I used&nbsp;pascal and =
foxpro=20
language but it not support OOP. That why I learn python. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I need some help in learning this =
language step by=20
step in details. Where can I get it...</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'm using windows flat form. For your =
info.&nbsp;I=20
cannot find any python books in my country. Over here a lot of people =
using=20
perl. </FONT></DIV></BODY></HTML>

------=_NextPart_000_0045_01C0D9F8.A991DF00--



From deirdre@deirdre.net  Fri May 11 02:11:21 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Thu, 10 May 2001 18:11:21 -0700
Subject: [Tutor] Step by step tutorials
In-Reply-To: <004801c0d9b5$cc7065c0$6a01a8c0@com.my>
References: <004801c0d9b5$cc7065c0$6a01a8c0@com.my>
Message-ID: <a05100e1fb720ec8fa178@[10.0.1.15]>

--============_-1222579005==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

At 8:59 AM +0800 5/11/01, Mr. Razak wrote:
>I have already study python language for more than one month. But 
>until now I still cannot catch-up with the language.
>I already read the tutorial in the web but not much help.
>Before this I used pascal and foxpro language but it not support 
>OOP. That why I learn python.
>
>I need some help in learning this language step by step in details. 
>Where can I get it...
>
>I'm using windows flat form. For your info. I cannot find any python 
>books in my country. Over here a lot of people using perl.

There's a tutorial at http://www.python.org/doc/

If you have specific questions, we can help. With a question as 
general as "help me learn python" we don't know where to begin.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams
--============_-1222579005==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>Re: [Tutor] Step by step
tutorials</title></head><body>
<div>At 8:59 AM +0800 5/11/01, Mr. Razak wrote:</div>
<blockquote type="cite" cite><font face="Arial" size="-1">I have
already study python language for more than one month. But until now I
still cannot catch-up with the language.</font></blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">I already
read the tutorial in the web but not much help.</font></blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">Before
this&nbsp;I used&nbsp;pascal and foxpro language but it not support
OOP. That why I learn python.</font></blockquote>
<blockquote type="cite" cite>&nbsp;</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">I need some
help in learning this language step by step in details. Where can I
get it...</font></blockquote>
<blockquote type="cite" cite>&nbsp;</blockquote>
<blockquote type="cite" cite><font face="Arial" size="-1">I'm using
windows flat form. For your info.&nbsp;I cannot find any python books
in my country. Over here a lot of people using
perl.</font></blockquote>
<div><br></div>
<div>There's a tutorial at http://www.python.org/doc/</div>
<div><br></div>
<div>If you have specific questions, we can help. With a question as
general as &quot;help me learn python&quot; we don't know where to
begin.</div>
</body>
</html>
--============_-1222579005==_ma============--


From tbrauch@mindless.com  Fri May 11 01:22:20 2001
From: tbrauch@mindless.com (Timothy M. Brauch)
Date: Thu, 10 May 2001 20:22:20 -0400 (EDT)
Subject: [Tutor] Installing 2.1 on RHL7.0
Message-ID: <2482.208.219.125.33.989540540.squirrel@titan.centre.edu>

I'm trying to install Python 2.1 on my Red Hat Linux 7.0 machine using the
*.tgz file (yes, I know the rpm files exist, but I figured I'd try the tgz
as I am new to linux and thought the practice would be good).

I ran tar and ./configure and everything was fine.  But, when I ran make, I
got the following message:

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

[root@brauch Python-2.1]# make
gcc -c -g -02 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -o
Modules/python.o Modules/python.c
In file included from Include/Python.h:54
	from Modules/python.c:3:
Include/pyport.h:422:2: #error "LONG_BIT definition appears wrong for
platform (bad gcc/glibc config?)."
make: *** [Modules/python.o] Error 1

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

Any ideas?  Also, should I ditch the *.tgz file and use the rpm's instead,
should I install all the rpm's:
  - python2-2.1-4.i386.rpm
  - python2-tkinter-2.1-4.i386.rpm
  - python2-devel-2.1-4.i386.rpm
  - python2-tools-2.1-4.i386.rpm
I actually tried using these first, but tools gave me an error that it
conflicted with Python1.5.2, already installed,  Or, what is the deal with
the source rpms?

 - Tim



From kojo@hal-pc.org  Fri May 11 02:54:37 2001
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Thu, 10 May 2001 20:54:37 -0500
Subject: [Tutor] Step by step tutorials
In-Reply-To: <004801c0d9b5$cc7065c0$6a01a8c0@com.my>
Message-ID: <5.0.2.1.0.20010510204623.00afced8@Pop3.norton.antivirus>

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

Razak,

I'm not sure what you're trying to do, but these are a couple of popular 
tutorials.  The first is by our very own Alan Gauld and is quite 
popular.  It's even been made into a book.
<http://www.crosswinds.net/~agauld/>

The second is "How to Think Like a Computer Scientist".  If you have a 
Comp. Sci. background, this may be redundant.
<http://www.ibiblio.org/obp/thinkCSpy/>

Hmm...as I've just left an Accounting PhD program to get a BS in Comp. 
Sci., I might want to pay more attention to that second one myself...

Hope this helps,

At 08:59 AM 5/11/2001 +0800, Mr. Razak wrote:
>I have already study python language for more than one month. But until 
>now I still cannot catch-up with the language.
>I already read the tutorial in the web but not much help.
>Before this I used pascal and foxpro language but it not support OOP. That 
>why I learn python.
>
>I need some help in learning this language step by step in details. Where 
>can I get it...
>
>I'm using windows flat form. For your info. I cannot find any python books 
>in my country. Over here a lot of people using perl.

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

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************
--=====================_201639131==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
Razak,<br>
<br>
I'm not sure what you're trying to do, but these are a couple of popular
tutorials.&nbsp; The first is by our very own Alan Gauld and is quite
popular.&nbsp; It's even been made into a book.<br>
&lt;<a href="http://www.crosswinds.net/~agauld/" eudora="autourl">http://www.crosswinds.net/~agauld/</a>&gt;<br>
<br>
The second is &quot;How to Think Like a Computer Scientist&quot;.&nbsp;
If you have a Comp. Sci. background, this may be redundant.<br>
&lt;<a href="http://www.ibiblio.org/obp/thinkCSpy/" eudora="autourl">http://www.ibiblio.org/obp/thinkCSpy/</a>&gt;<br>
<br>
Hmm...as I've just left an Accounting PhD program to get a BS in Comp.
Sci., I might want to pay more attention to that second one
myself...<br>
<br>
Hope this helps,<br>
<br>
At 08:59 AM 5/11/2001 +0800, Mr. Razak wrote:<br>
<blockquote type=cite class=cite cite><font face="arial" size=2>I have
already study python language for more than one month. But until now I
still cannot catch-up with the language. </font><br>
<font face="arial" size=2>I already read the tutorial in the web but not
much help.</font><br>
<font face="arial" size=2>Before this I used pascal and foxpro language
but it not support OOP. That why I learn python. </font><br>
&nbsp;<br>
<font face="arial" size=2>I need some help in learning this language step
by step in details. Where can I get it...</font><br>
&nbsp;<br>
<font face="arial" size=2>I'm using windows flat form. For your info. I
cannot find any python books in my country. Over here a lot of people
using perl. </font></blockquote>
<x-sigsep><p></x-sigsep>
**************************** <br>
Kojo Idrissa <br>
&nbsp; <br>
kojo@hal-pc.org<br>
<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http</a>://www.hal-pc.org<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">/~kojo/</a><br>
****************************</html>

--=====================_201639131==_.ALT--



From rob@jam.rr.com  Fri May 11 03:17:11 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Thu, 10 May 2001 21:17:11 -0500
Subject: [Tutor] Step by step tutorials
References: <004801c0d9b5$cc7065c0$6a01a8c0@com.my>
Message-ID: <3AFB4BA7.A197D799@jam.rr.com>

We will be glad to try and help you find good answers to any questions
you post. You may find a healthy collection of Python source code and
links on the Useless Python website, which the Tutor list members
contribute to:

http://www.lowerstandard.com/python/pythonsource.html

Rob

> "Mr. Razak" wrote:
> 
> I have already study python language for more than one month. But
> until now I still cannot catch-up with the language.
> I already read the tutorial in the web but not much help.
> Before this I used pascal and foxpro language but it not support OOP.
> That why I learn python.
> 
> I need some help in learning this language step by step in details.
> Where can I get it...
> 
> I'm using windows flat form. For your info. I cannot find any python
> books in my country. Over here a lot of people using perl.

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From samus@feudalkingdoms.tzo.org  Fri May 11 03:59:14 2001
From: samus@feudalkingdoms.tzo.org (Sam Corder)
Date: Thu, 10 May 2001 22:59:14 -0400
Subject: [Tutor] Installing 2.1 on RHL7.0
In-Reply-To: <2482.208.219.125.33.989540540.squirrel@titan.centre.edu>
Message-ID: <NDBBINOGOLMIDEBJNECIKEMDCBAA.samus@feudalkingdoms.tzo.org>

You should proably uninstall 1.5 before you try to rpm in the new one.  If
it complains about dependencies then you can try -U to upgrade or just
use --nodeps when you are uninstalling.  The src rpms will allow you to
compile the program and recreate the .rpm.  If you are on a different system
like mandrake it can be useful so that you get the pentium optimizations.

I've never built python from source so I'm not sure what your specific error
means.  Though if you have the 1.5-devel package installed it may be picking
up a header file from the wrong place.  It could also be that your compiler
is buggy.  Redhat 7.0 shipped with a non-release "preview" version of gcc
that won't be compatible with the next released version.  They like to do
these kinds of breakages in their .0 releases.

-Sam

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Timothy M. Brauch
Sent: Thursday, May 10, 2001 8:22 PM
To: tutor@python.org
Subject: [Tutor] Installing 2.1 on RHL7.0


I'm trying to install Python 2.1 on my Red Hat Linux 7.0 machine using the
*.tgz file (yes, I know the rpm files exist, but I figured I'd try the tgz
as I am new to linux and thought the practice would be good).

I ran tar and ./configure and everything was fine.  But, when I ran make, I
got the following message:

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

[root@brauch Python-2.1]# make
gcc -c -g -02 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -o
Modules/python.o Modules/python.c
In file included from Include/Python.h:54
	from Modules/python.c:3:
Include/pyport.h:422:2: #error "LONG_BIT definition appears wrong for
platform (bad gcc/glibc config?)."
make: *** [Modules/python.o] Error 1

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

Any ideas?  Also, should I ditch the *.tgz file and use the rpm's instead,
should I install all the rpm's:
  - python2-2.1-4.i386.rpm
  - python2-tkinter-2.1-4.i386.rpm
  - python2-devel-2.1-4.i386.rpm
  - python2-tools-2.1-4.i386.rpm
I actually tried using these first, but tools gave me an error that it
conflicted with Python1.5.2, already installed,  Or, what is the deal with
the source rpms?

 - Tim


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



From sarnold@earthling.net  Fri May 11 07:40:25 2001
From: sarnold@earthling.net (Stephen L Arnold)
Date: Thu, 10 May 2001 23:40:25 -0700
Subject: [Tutor] Re: Installing 2.1 on RHL7.0
In-Reply-To: <2482.208.219.125.33.989540540.squirrel@titan.centre.edu>
Message-ID: <20010511064026.42B851F664@shiva.arnolds.bogus>

On 10 May 01, at 20:22, Timothy M. Brauch wrote:

> Any ideas?  Also, should I ditch the *.tgz file and use the rpm's instead,
> should I install all the rpm's:
>   - python2-2.1-4.i386.rpm
>   - python2-tkinter-2.1-4.i386.rpm
>   - python2-devel-2.1-4.i386.rpm
>   - python2-tools-2.1-4.i386.rpm
> I actually tried using these first, but tools gave me an error that it
> conflicted with Python1.5.2, already installed,  Or, what is the deal with
> the source rpms?

I think the first guy is probably correct (it looks like a version 
conflict in the header files.  In general, you should try to use 
source rpms if they are available; you'll find enough stuff to play 
with along the way.  The source rpm for python will produce all the 
above binary rpms for your system.  Try dropping the .srpm file in 
/usr/src/redhat/SRPMS and type:

rpm --rebuild <filename>.src.rpm

If all goes well, it will unpack the the source, run configure, 
make, etc, and place the rpm files in /usr/src/redhat/RPMS/i386 (or 
noarch, or whatever).  It seems to default to i386 for processor 
type, even though I have an Athlon now.  I've never looked into it, 
but I suppose rpm must have a config file to set that somewhere...

There are several RedHat packages that use Python (which I suppose 
is why they're still at version 1.52 of Python) so it will probably 
complain about dependencies when you try to install the binaries, 
whether you use the upgrade switch or not.  You can run:

rpm -q python-devel

(and the others) to see which packages are installed.  You should 
install all of them, and for any that complain about a straight 
upgrade, do this do this:

rpm -Uvh --nodeps <filename>.rpm

which will upgrade (but ignore package dependencies).

Have fun, Steve

*************************************************************
Steve Arnold                          sarnold@arnolds.dhs.org
Assoc. Faculty, Dept of Geography, Allan Hancock College
           http://arnolds.dhs.org/geography.html

Linux:  It's not just for nerds anymore...


From lonetwin@yahoo.com  Fri May 11 08:02:34 2001
From: lonetwin@yahoo.com (steve)
Date: Fri, 11 May 2001 12:32:34 +0530
Subject: [Tutor] Calling functions
In-Reply-To: <Pine.LNX.4.21.0105091636290.27918-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105091636290.27918-100000@hkn.eecs.berkeley.edu>
Message-ID: <01051112280701.04810@mercury.in.cqsl.com>

Hi there,
 Correct me if I'm wrong:

>>> def x():
=2E..     print 'hi'
=2E..=20
>>> def y():
=2E..     print 'bye'
=2E..=20
>>> input('?')()
?x
hi

 Hope that helps

Peace
Steve

Original msg. :

Is there a way to define a function and then use a raw_input to call the
function?

Here's a little example of what I mean

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

def func_0():
         do something here

def func_1():
         do something else here

dummy=3Draw_input('Which function do you want to execute? ')

dummy <---- I want that to do what ever was entered into the raw_input

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

Well, that obviously doesn't work, but that is the basic idea.  I just
want to know if this is possible, and how I could go about doing it
--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
"Unfortunately, those people who have nothing better to do than post on t=
he
Internet all day long are rarely the ones who have the most insights."
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From lonetwin@yahoo.com  Fri May 11 08:08:55 2001
From: lonetwin@yahoo.com (steve)
Date: Fri, 11 May 2001 12:38:55 +0530
Subject: [Tutor] Finding uniq. in lists
In-Reply-To: <20010510094517.A8139@pino.selwerd.nl>
References: <01051013132800.12728@mercury.in.cqsl.com> <20010510094517.A8139@pino.selwerd.nl>
Message-ID: <01051112385501.05127@mercury.in.cqsl.com>

Thanx all ye good people*

My mail server was down, so I got the replies only now, haven't yet taken=
 a=20
look (Tim, Daniel) nor have I tried that out (Remco).

Peace=20
Steve

*good people : Remco, Tim, Daniel

--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
"Unfortunately, those people who have nothing better to do than post on t=
he
Internet all day long are rarely the ones who have the most insights."
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From lonetwin@yahoo.com  Fri May 11 09:30:55 2001
From: lonetwin@yahoo.com (steve)
Date: Fri, 11 May 2001 14:00:55 +0530
Subject: [Tutor] Installing 2.1 on RHL7.0
In-Reply-To: <NDBBINOGOLMIDEBJNECIKEMDCBAA.samus@feudalkingdoms.tzo.org>
References: <NDBBINOGOLMIDEBJNECIKEMDCBAA.samus@feudalkingdoms.tzo.org>
Message-ID: <01051114005503.05127@mercury.in.cqsl.com>

Hey there,
 Check for a couple of thing "always" b'fore building tar-gz packages:
1) Read the README/INSTALL
2) Make the neccessary changes to the files mentioned in these files to s=
uit =20
   u r enviorment, (read on...I'll get python specific soon)
3) run ./configure with the option --prefix=3D<where u'd like the pkg to =
goto>
4) Then run the ./configure/ make / make install

Ok now, Python specific:
1) Read the Readme.....for RedHat7.0 Linux nothing useful in there....but=
 it=20
good to get u into the habit !!! :)
2) Open up Modules/Setup and uncomment all the modules U'd like to build,=
=20
<NOTE: some of the modules (like readline) may need some specific libs=20
installed (like libreadline ...surprise, surprise !!! :)). N E Ways U'd c=
ome=20
to know 'bout this when u try to build u r package>
3) LISTEN CLOSELY: Run the ./configure script with the option=20
--prefix=3D/usr/local ...now this is my choice of where I install all my=20
downloaded tgz'ed packages....the reason I'm stressing this here is b'cos=
 I=20
"think" (don't know 4 sure) python is by default installed under /usr whe=
n u=20
use the rpm packages, here's what I mean
Normal (RPM's)
/usr
 |-bin/
 |  |-python-<ver> <--------the binary
 |-lib/
 |  |-Python-<version>
 |           |-<ALL the modules>

TGZ (if --prefix=3D/usr/local)
/usr
 |-local/
 |  |-bin/
 |  |  |-python-<ver> <------the binary
 |  |-lib/
 |  |  |-Python-<version>
 |  |          |-<All the modules>

N E Ways, if u still do want to install python under /usr u might want to=
=20
uninstall python first (rpm -e python).
 After doing a make install make sure the /usr/bin/python points to the=20
correct binary.

As an ending note, I'll encourage u to use tgz's whenever possible, simpl=
y=20
b'cos U can customize u r package ""exactly"" to u r needs....unlike rpms=
=20
where u have to be satisfied by the configuration of the provider...the e=
asy=20
of install of course is a tradeoff

N E Ways...lemme know what happened
Peace
Steve

--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
"Unfortunately, those people who have nothing better to do than post on t=
he
Internet all day long are rarely the ones who have the most insights."
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From NHYTRO@compuserve.com  Fri May 11 10:47:08 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Fri, 11 May 2001 05:47:08 -0400
Subject: [Tutor] List iteration
Message-ID: <200105110547_MC2-D0AA-E23E@compuserve.com>

Hi guys!

I would like to do some list iteration, is there a way to do something li=
ke
this:


# code start
list_a =3D ['a', 'b', 'c']
list_b =3D ['d', 'e', 'f']

for x, y in [list_a, list_b]:
....print  x + y          # hypo, this FAILS!! since the iterators length=

is shorter than the number of elements in list_a or list_b

Any ideas?


Cheers Sharriff


P.S. got a new python book, I hope to stop irritating you guys very soon
:-))



From ium@micromuse.com  Fri May 11 11:46:18 2001
From: ium@micromuse.com (ibraheem umaru-mohammed)
Date: Fri, 11 May 2001 11:46:18 +0100
Subject: [Tutor] List iteration
In-Reply-To: <200105110547_MC2-D0AA-E23E@compuserve.com>; from NHYTRO@compuserve.com on Fri, May 11, 2001 at 05:47:08AM -0400
References: <200105110547_MC2-D0AA-E23E@compuserve.com>
Message-ID: <20010511114617.B929@micromuse.com>

[Sharriff Aina wrote...]
<snip>
-| I would like to do some list iteration, is there a way to do something like
-| this:
-| 
-| 
-| # code start
-| list_a = ['a', 'b', 'c']
-| list_b = ['d', 'e', 'f']
-| 
-| for x, y in [list_a, list_b]:
-| ....print  x + y          # hypo, this FAILS!! since the iterators length
-| is shorter than the number of elements in list_a or list_b
-| 
-| Any ideas?
-| 
<\snip>

Since, no one has replied yet, here is my attempt.

<interactive session>

	ibraheem@ignoramus:$ python
	Python 2.1 (#1, Apr 20 2001, 17:50:32)
	[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
	Type "copyright", "credits" or "license" for more information.
	>>> list1=['a','b','c']
	>>> list2=['d','e','f']
	>>> do_it=lambda x,y: x + y
	>>> for i in map(do_it,list1,list2):
	...     print i
	...
	ad
	be
	cf
	>>>    

<\interactive session>

-| 
-| Cheers Sharriff
-| 

Hope that helps a little.

kindest regards,

	--ibs.

-- 
For good, return good.
For evil, return justice.


From SBrunning@trisystems.co.uk  Fri May 11 11:22:08 2001
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Fri, 11 May 2001 11:22:08 +0100
Subject: [Tutor] List iteration
Message-ID: <31575A892FF6D1118F5800600846864D78BBD0@intrepid>

> I would like to do some list iteration, is there a way to do something
> like
> this:
> 
> 
> # code start
> list_a = ['a', 'b', 'c']
> list_b = ['d', 'e', 'f']
> 
> for x, y in [list_a, list_b]:
> ....print  x + y          # hypo, this FAILS!! since the iterators length
> is shorter than the number of elements in list_a or list_b
 
If you are doing what I *think* you are doing, then the zip builtin might
help. Try:

for x, y in zip(list_a, list_b):
    print x + y

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 SBrunning@trisystems.co.uk  Fri May 11 12:16:03 2001
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Fri, 11 May 2001 12:16:03 +0100
Subject: [Tutor] List iteration
Message-ID: <31575A892FF6D1118F5800600846864D78BBD1@intrepid>

> I would like to do some list iteration, is there a way to do something
> like
> this:
> 
> 
> # code start
> list_a = ['a', 'b', 'c']
> list_b = ['d', 'e', 'f']
> 
> for x, y in [list_a, list_b]:
> ....print  x + y          # hypo, this FAILS!! since the iterators length
> is shorter than the number of elements in list_a or list_b
 
If you are doing what I *think* you are doing, then the zip builtin might
help. Try:

for x, y in zip(list_a, list_b):
    print x + y

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 arcege@speakeasy.net  Fri May 11 12:53:38 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Fri, 11 May 2001 07:53:38 -0400 (EDT)
Subject: [Tutor] List iteration
In-Reply-To: <31575A892FF6D1118F5800600846864D78BBD1@intrepid> from "Simon Brunning" at May 11, 2001 12:16:03 PM
Message-ID: <200105111153.f4BBrcT01783@dsl092-074-184.bos1.dsl.speakeasy.net>

Simon Brunning wrote
> 
> > I would like to do some list iteration, is there a way to do something
> > like
> > this:
> > 
> > 
> > # code start
> > list_a = ['a', 'b', 'c']
> > list_b = ['d', 'e', 'f']
> > 
> > for x, y in [list_a, list_b]:
> > ....print  x + y          # hypo, this FAILS!! since the iterators length
> > is shorter than the number of elements in list_a or list_b
>  
> If you are doing what I *think* you are doing, then the zip builtin might
> help. Try:
> 
> for x, y in zip(list_a, list_b):
>     print x + y

Again... this function does not exist on release of Python before 2.0.
The common idiom is 'map(None, list1, list2, ...)'.

for (x, y) in map(None, list_a, list_b):
  print x + y

This is also fairly important: zip truncates to the shortest list,
map(None) will go out to the longer lists adding None as needed.
This could mean a serious lost of information is you aren't careful.

>>> a = [1, 2, 3]
>>> b = [4, 5]
>>> for t in map(None, a, b): print t
...
(1, 4)
(2, 5)
(3, None)
>>> for t in zip(a, b): print t
...
(1, 4)
(2, 5)
>>>

If you know that the two lists are equal (and compatible for addition),
then you can use the operator module.

>>> import operator
>>> for silly_walk in map(operator.add, list_a, list_b):
...   print silly_walk
...

If the two lists aren't of equal length, then you'll get an error trying
to add None to some value. ;)

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From lsloan@umich.edu  Fri May 11 13:33:04 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Fri, 11 May 2001 08:33:04 -0400
Subject: [Tutor] getting *just* pydoc?
Message-ID: <200105111233.IAA00886@birds.us.itd.umich.edu>

I understand that Python 2.1 includes pydoc.  That's something I wish I
had in Python 2.0 that I'm currently using.  I and the other developers
here are in the middle of a project using Python.  They would prefer it
if I didn't disrupt our environment at the moment by upgrading to 2.1,
but I would really like to get pydoc.  Can I get it separately
somewhere and will it work with pre-2.1 versions of Python?

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From cooler12001@yahoo.com  Fri May 11 13:36:31 2001
From: cooler12001@yahoo.com (Matthews James)
Date: Fri, 11 May 2001 05:36:31 -0700 (PDT)
Subject: [Tutor] Need Advice About Saving Files that Already Exist.
Message-ID: <20010511123631.33296.qmail@web11406.mail.yahoo.com>

#START PROGRAM
import os

months =
{'01':'[JAN]','02':'[FEB]','03':'[MAR]','04':'[APR]','05':'[MAY]',\
         
'06':'[JUN]','07':'[JUL]','08':'[AUG]','09':'[SEP]','10':'[OCT]',\
          '11':'[NOV]','12':'[DEC]'}



def mk_newfile(folder):
    '''(folder)-> name of the keylog! folder
    This Function will rename and move all the keylog!
    files to a closer temp folder'''

    print 'Checking Folder For .01W Files'
    files = os.listdir(folder)
    for file in files:
        if file[-4:] == '.01W':
            print file
            
            time = '['+file[0:2]+'.'+file[2:4]+']'
            month = file[4:6]
            day = '['+file[6:8]+']'
            year = '['+file[9:11]+']'
            mon = months[month]

            print time,
            print months[month],
            print day,
            print year
            
           
try:os.rename('C:\\WINDOWS\\TEMP\\'+file,'C:\\TEMP\\sys.admir\\'+time+mon+day+year)
            except OSError: print 'File Already Exist'
                                
#THIS IS THE USER INTERFACE
print '-'*40
print ' '*13,'.01W FILES'
print '-'*40
print
print
print
folder=raw_input('Folder: ')
mk_newfile(folder)
#END OF USER INTERFACE
#END OF PROGRAM

I run Windows ME

This is a program i made to rename the keylog files on
my computer it works but, I use this often in one day
which means that that day all keylog files will be the
same i'v tried to figure it out on my own but i failed
as you can tell.

example of todays files
07360511.01W          #this is keylogs file

[07.36][MAY][11][01]  #this what my program
                      #renames it

I want help on how to get the program to check if
there is a file named that already and if there is
rename it to something else like:
[07.36][MAY][11][01]1
and if there is a filenamed that try again to
something like this:
[07:36][MAY][11][01]2

THANK YOU 
James


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/


From kalle@gnupung.net  Fri May 11 14:58:19 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Fri, 11 May 2001 15:58:19 +0200
Subject: [Tutor] Installing 2.1 on RHL7.0
In-Reply-To: <2482.208.219.125.33.989540540.squirrel@titan.centre.edu>; from tbrauch@mindless.com on Thu, May 10, 2001 at 08:22:20PM -0400
References: <2482.208.219.125.33.989540540.squirrel@titan.centre.edu>
Message-ID: <20010511155819.A20070@father>

Sez Timothy M. Brauch:
> I'm trying to install Python 2.1 on my Red Hat Linux 7.0 machine using the
> *.tgz file (yes, I know the rpm files exist, but I figured I'd try the tgz
> as I am new to linux and thought the practice would be good).
> 
> I ran tar and ./configure and everything was fine.  But, when I ran make, I
> got the following message:
> 
> ########################################################################
> 
> [root@brauch Python-2.1]# make
> gcc -c -g -02 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -o
> Modules/python.o Modules/python.c
> In file included from Include/Python.h:54
> 	from Modules/python.c:3:
> Include/pyport.h:422:2: #error "LONG_BIT definition appears wrong for
> platform (bad gcc/glibc config?)."
> make: *** [Modules/python.o] Error 1
> 
> ########################################################################

This is a known problem with the gcc/glibc combination on Red Hat 7.0.
There are updated gcc and glibc RPMs available in the updates directory of
your favourite Red Hat FTP mirror.  Install these and try again.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From scarblac@pino.selwerd.nl  Fri May 11 15:05:07 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Fri, 11 May 2001 16:05:07 +0200
Subject: [Tutor] Step by step tutorials
In-Reply-To: <004801c0d9b5$cc7065c0$6a01a8c0@com.my>; from arazak@kansai.com.my on Fri, May 11, 2001 at 08:59:18AM +0800
References: <004801c0d9b5$cc7065c0$6a01a8c0@com.my>
Message-ID: <20010511160507.A21184@pino.selwerd.nl>

On  0, "Mr. Razak" <arazak@kansai.com.my> wrote:

> I have already study python language for more than one month. But until
> now I still cannot catch-up with the language.
>
> I already read the tutorial in the web but not much help.

There are a few other tutorials, mostly for non-programmers, e.g.
http://www.crosswinds.net/~agauld/ 

There are more links on the Python (www.python.org), under "Documentation",
then "Introductions". 

> Before this I used pascal and foxpro language but it not support OOP. That
> why I learn python.
> 
> I need some help in learning this language step by step in details. Where
> can I get it...

Well, here. But we can't really explain it better than the existing
tutorials, without knowing what you have trouble with. We can answer
questions. So we need information, what's the problem?

What are you trying to make, where are you stuck?

-- 
Remco Gerlich


From randrews@planhouse.com  Fri May 11 16:44:06 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Fri, 11 May 2001 10:44:06 -0500
Subject: [Tutor] Programming Python (the book)
Message-ID: <000401c0da31$36232720$de00a8c0@planhouse5>

I just got a copy of Programming Python 2nd Edition by Mark Lutz (a Useless
Python contributor). My initial impression is that it's going to be an
outstanding text for learning more advanced use of Python. If anyone has
gotten the gist of the language itself, I recommend it. It seems to be more
*advanced tutorial* than reference book, is 1300 pages long, and comes with
a CD of relatively current source files.

I can no longer complain about the dearth of info available for Python web
programming.

Rob



From rear@sirius.com  Fri May 11 16:54:14 2001
From: rear@sirius.com (Bob Rea)
Date: Fri, 11 May 2001 08:54:14 -0700
Subject: [Tutor] Programming Python (the book)
In-Reply-To: <000401c0da31$36232720$de00a8c0@planhouse5>
References: <000401c0da31$36232720$de00a8c0@planhouse5>
Message-ID: <01051108541400.01258@gandalf>

On Friday 11 May 2001 08:44 am, Rob Andrews wrote:
> I just got a copy of Programming Python 2nd Edition by Mark Lutz (a
> Useless Python contributor). My initial impression is that it's
> going to be an outstanding text for learning more advanced use of
> Python. If anyone has gotten the gist of the language itself, I
> recommend it. It seems to be more *advanced tutorial* than
> reference book, is 1300 pages long, and comes with a CD of
> relatively current source files.

I am just learning Python. I looked at this book and it is indeed 
advanced. I am reading the first edition and it is very fine at 
teaching Python. I hope they keep it in print. It is too good to 
lose. And I wish it could be updated as well.



From arcege@speakeasy.net  Fri May 11 17:22:25 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Fri, 11 May 2001 12:22:25 -0400 (EDT)
Subject: [Tutor] Programming Python (the book)
In-Reply-To: <01051108541400.01258@gandalf> from "Bob Rea" at May 11, 2001 08:54:14 AM
Message-ID: <200105111622.f4BGMPK02208@dsl092-074-184.bos1.dsl.speakeasy.net>

Bob Rea wrote
> 
> On Friday 11 May 2001 08:44 am, Rob Andrews wrote:
> > I just got a copy of Programming Python 2nd Edition by Mark Lutz (a
> > Useless Python contributor). My initial impression is that it's
> > going to be an outstanding text for learning more advanced use of
> > Python. If anyone has gotten the gist of the language itself, I
> > recommend it. It seems to be more *advanced tutorial* than
> > reference book, is 1300 pages long, and comes with a CD of
> > relatively current source files.
> 
> I am just learning Python. I looked at this book and it is indeed 
> advanced. I am reading the first edition and it is very fine at 
> teaching Python. I hope they keep it in print. It is too good to 
> lose. And I wish it could be updated as well.

There are a few different books that might be being discussed here. :)

Programming Python (1st ed., 900+ pp) came out around 1995; it was a BIG
book mostly because it didn't seem like there would be a lot of Python
books in the near future (and there weren't).  It covered a lot of ground
and wasn't really a reference book.  Many thought it was too... involved
for newcomers.  (I liked it, but then I was introduced to Python soon
after the book came out.. in fact, it was this book that got me involved.)

Learning Python (360+ pp) came out four years later as much for of an
introduction to Python.  A lot of people newer to Python liked it more.
It is still geared toward people who have some experience programming
(even scripting languages like Tcl and *shudder* Perl), altho I guess
some savy non-programmers could pick up the concepts well enough from
the book.

Programming Python (2nd ed., 1250+ pp) is a recent reworking of the
first (all three by Mark Lutz).  It is more geared to showing that ppl
(including newbies) can be developing larger projects with Python fairly
quickly ("quickly" being a relative term).  It has a lot of nice projects
and some useful apps coming out of it.

Up until I got Beazley's _Python Essential Reference_, I was using
Programming Python (1st ed.) as my major reference book (with a lot
of page-tabs).  It is still a very good book.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From shaleh@valinux.com  Fri May 11 17:26:16 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Fri, 11 May 2001 09:26:16 -0700 (PDT)
Subject: [Tutor] checking for a condition across all members of a lis
In-Reply-To: <200105102056.QAA02124@smtp2.fas.harvard.edu>
Message-ID: <XFMail.20010511092616.shaleh@valinux.com>

On 10-May-2001 Pijus Virketis wrote:
> Hi!
> 
> I am writing a little crosses-and-naughts game. At its heart is a n*m
> matrix of Cells, instances of a class that represents the states of a
> single cell (i.e. "-", "x" and "o"). I can set_state() and return_state().
> Now I need to implement victory checks. So, for instance, the horizontal
> check would in principle go something like this:
> 
> def check_horizontal(Matrix):
>       for row in Matrix:
>               if row[0].return_state() == row[1].return_state() ==
row[2].return_state():
>                       print "victory!"
> 
> Except that I, perhaps out of stubbornness, really don't want to build in
> the dimensions of my matrix into the code (what if someone wants to try out
> a 5*5 x-o game? :)). What's a nice way of going across the whole row (or
> down a column, in the next step)?
> 

pass the x * y to the function.


From BConley@PreVisionMarketing.com  Fri May 11 18:44:58 2001
From: BConley@PreVisionMarketing.com (Brian Conley)
Date: Fri, 11 May 2001 13:44:58 -0400
Subject: [Tutor] getting *just* pydoc?
Message-ID: <B21958504D50D311A80A00A0C9E594AA01DEF582@PM-SVR03>

You can try this website:
http://www.orgmf.com.ar/condor/pytstuff.html

There you can get the Python Shelf.  It's pretty cool.

-----Original Message-----
From: Lance E Sloan [mailto:lsloan@umich.edu]
Sent: Friday, May 11, 2001 8:33 AM
To: tutor@python.org
Subject: [Tutor] getting *just* pydoc?



I understand that Python 2.1 includes pydoc.  That's something I wish I
had in Python 2.0 that I'm currently using.  I and the other developers
here are in the middle of a project using Python.  They would prefer it
if I didn't disrupt our environment at the moment by upgrading to 2.1,
but I would really like to get pydoc.  Can I get it separately
somewhere and will it work with pre-2.1 versions of Python?

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"

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


From NHYTRO@compuserve.com  Fri May 11 19:00:13 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Fri, 11 May 2001 14:00:13 -0400
Subject: [Tutor] Iterating on two lists.....Thanks guys
Message-ID: <200105111400_MC2-D0B6-83DC@compuserve.com>

Thanks Ibraheem, Simon and Arcege! I=B4m very grateful for your tips


Best regards



Sharriff Aina


From lsloan@umich.edu  Fri May 11 19:22:04 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Fri, 11 May 2001 14:22:04 -0400
Subject: [Tutor] my solution to #include in DocumentTemplate
Message-ID: <200105111822.OAA04788@birds.us.itd.umich.edu>

Just in case anybody is interested (rather unlikely) I thought
I'd let everybody know how I resolved my quest for #include-like
behavior in DocumentTemplate.  Of course, a very good way would
have been to actually create a "dtml-include" tag by following
the suggestions at zope.org.

Being a Python newbie, a Zope not-even-newbie-yet, and under a
tight deadline, I didn't go that route.  Instead, I happened
to stumble across this method.  What I was looking for was
something like:

	<!--#include file="../path/to/filename.dtml" -->

in a DTML file to include another DTML file, recursively.  I
ended up doing this:

	<!--#with "_(incDoc = DocumentTemplate.HTMLFile('../path/to/file.dtml'))"
	-->
	<!--#var expr="incDoc(x = x)" -->
	<!--#/with -->

It works well.  The only problem is that for every object I want
to pass to the included document must be specified individually
(x = x).  I tried these but they didn't work:

	<!--#var expr="incDoc(mapping = vars())" -->
	<!--#var expr="incDoc(mapping = mapping)" -->

For now, this is not too much of a problem, as I'm only including
a header or a footer that's common to all my DTML pages and they
don't require many arguments.

BTW, I think DocumentTemplate is excellent and it should be added to
the standard Python distribution.  For those that don't know my
weird history with this module, I've borrowed DocumentTemplate from
Zope to write some CGIs in Python.  They're coming along nicely,
but I admit that I'm somewhat sloppy.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From daniel@longbeach.goldinc.com  Fri May 11 20:07:45 2001
From: daniel@longbeach.goldinc.com (Daniel)
Date: Fri, 11 May 2001 14:07:45 -0500 (CDT)
Subject: [Tutor] Need Advice About Saving Files that Already Exist.
In-Reply-To: <20010511123631.33296.qmail@web11406.mail.yahoo.com>
Message-ID: <Pine.LNX.3.93.1010511135737.3606A-100000@longbeach.goldinc.com>

Hey James,

I'll give it a shot.  This might help you out.

Here is an example from my pc.  The dir I use is /tmp.   and the filename 
that I use I give as an argument. .. it seems work work ok. heh  :-)

(dev.bart.~): ls /tmp/
lost+found/  mysql.sock=  screens/  uscreens/

(dev.bart.~): python movefiles.py bla
then no one has our filename and we can write to it

(dev.bart.~): touch /tmp/bla

(dev.bart.~): ls /tmp/
bla  lost+found/  mysql.sock=  screens/  uscreens/

(dev.bart.~): python movefiles.py bla
old file is [** bla **] new file is [** bla.1 **]

(dev.bart.~): ls /tmp/
bla  bla.1  lost+found/  mysql.sock=  screens/  uscreens/

(dev.bart.~): python movefiles.py bla
old file is [** bla.1 **] new file is [** bla.2 **]

(dev.bart.~): python movefiles.py bla
old file is [** bla.2 **] new file is [** bla.3 **]

(dev.bart.~): python movefiles.py bla
old file is [** bla.3 **] new file is [** bla.4 **]

(dev.bart.~): ls /tmp/
bla  bla.1  bla.2  bla.3  bla.4  lost+found/  mysql.sock=  screens/
uscreens/


#BEGIN CODE PASTE
import os, string, sys, shutil

DIR = '/tmp'
mynewfile = sys.argv[1]
dir_listing = os.listdir(DIR)
HEH = []

#for each file in our directory
for i in dir_listing:
    if os.path.isfile("%s/%s" %(DIR, i)) == 1: #if it's a file and not a
                                               #directory
        file = string.split(i, '.')  #split it by .

        if file[0] == mynewfile:  HEH.append(file)
        #for all the files in our dir that have a prefix of the file we
        #want append them to the HEH list

if len(HEH) == 0:
    print "then no one has our filename and we can write to it"
    #enter in file writing here for the first time
    sys.exit(0)

for i in HEH:  #for each line in our HEH list
    try:
        #try to find the next suffix,  if that fails then (see next)
        newfooter = int(file[1])+1
        firstpart = file[0]
        newfile = "%s.%s" %(firstpart, newfooter)
        oldfile = "%s.%s" %(firstpart, file[1])
    except:
        # then it doesn't have a suffix
        firstpart = file[0]
        newfooter = 1  #so we give it the first one
        newfile = "%s.%s" %(firstpart, newfooter)
        oldfile = "%s" %(firstpart)

shutil.copyfile("%s/%s" % (DIR, oldfile), "%s/%s" % (DIR, newfile))
#this is the end,  I'm copying here b/c I want the file numbers to get
#larger for example reasons, you would put your write to file statement
here with the new 
#file to write to being the var newfile

print "old file is [**",oldfile,"**] new file is [**",newfile,"**]"

#END CODE PASTE





--
Daniel




From bsass@freenet.edmonton.ab.ca  Fri May 11 21:00:48 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Fri, 11 May 2001 14:00:48 -0600 (MDT)
Subject: [Tutor] (no subject)
In-Reply-To: <20010510073800.FQXF98.femail19.sdc1.sfba.home.com@localhost>
Message-ID: <Pine.LNX.4.33.0105111227530.20630-100000@bms>

On Thu, 10 May 2001, Steven Burr wrote:
<...>
> Still I'm curious.  Is there a clear advantage to the switching method
> as opposed to the pop and append method?

There is also the simulaton method...
 - split the deck in two
 - interleave the two halves in small groups

for example (optimized for readability, maybe ;)...

def shuffle(deck):
    import random
    ri = random.randint
    half = len(deck)/2
    part1 = deck[:half]
    part2 = deck[half:]
    result = []
    mingrp = 1
    maxgrp = 4
    while part1 or part2:
        if part1:
            for i in range(ri(mingrp, min(maxgrp, len(part1)))):
                result.append(part1.pop())
        if part2:
            for i in range(ri(mingrp, min(maxgrp, len(part2)))):
                result.append(part2.pop())
    return result

The advantages with this are:
 - you get to control the thouroughness of the shuffle by adjusting
   the size of the "small groups" (a sloppy shuffler uses larger groups)
 - randomness can be eliminated for testing, (e.g.,
   ri = lambda x,y: return 1), and you still get a good shuffle
 - it just "feels" more like a real deck
 - more fun to program


- Bruce




From tutor@python.org  Fri May 11 21:39:26 2001
From: tutor@python.org (Tim Peters)
Date: Fri, 11 May 2001 16:39:26 -0400
Subject: [Tutor] (no subject)
In-Reply-To: <20010510073800.FQXF98.femail19.sdc1.sfba.home.com@localhost>
Message-ID: <LNBBLJKPBEHFEDALKOLCMEKEKBAA.tim.one@home.com>

[Steven Burr]
> The discussion on the random.shuffle() function reminded me of a
> question I had about shuffling.  As an exercise, I've been
> working on a module containing classes that could be used in text-based
> card games.   In my "Deck" class (which inherits from "Cards," which
> inherits from "UserList"), I included the following shuffle method:
>
> def shuffle(self):
>     d = []
>     for i in range(len(self) - 1, -1, -1):
>         d.append(self.pop(self.index(random.choice(self.data))))
>     self.data = d

Please be aware that hard tab characters display differently in different
mail readers; I fiddled the above by hand to get rid of all the hard tab
characters, and convert them to 4-space idents.

Note that since you never use i, there's no point to such an elaborate "for"
loop.  For example,

    for i in range(len(self)):

would work as well, although it's unclear why this isn't taking the length of
self.data instead.

> In effect, the method popped random cards out of a list of cards and
> appended them to a new list until the original list was exhausted.
> The new list then replaced the old in the Cards object.  It seemed
> to work fine.

Yup, it should.  You could make it a good deal more efficient via, e.g.,

    for i in range(len(self)):
        d.append(self.pop(random.randrange(len(self.data))))

but each self.pop(i) still takes time proportional to the size of the list
it's popping from, so this is overall a quadratic-time algorithm.

> I later read a tutorial that included a card game example (How to Think
> Like a Computer Scientist, Java version).  The shuffle method in the
> example switched each card in the array with another randomly chosen
> card from the same array.

The algorithm as described does not produce a random permutation, so would be
a terrible shuffle method.  The actual method in the essay is:

    for (int i=0; i<deck.cards.length; i++) {
      // choose a random number between i and deck.cards.length
      // swap the ith card and the randomly-chosen card
    }

"Between i and deck.card.length" is a crucial detail.  If you pick *any* card
at random on each step, the algorithm is severely biased in the permutations
it can produce (no, this isn't obvious!  you have to try it to believe it
<wink>).

> When the Python random.shuffle function was  mentioned, I took a
> look at the module, apparently written by the BDFL,

'Twas actually me, although people confuse us all the time <wink>.  I wrote
it because people *usually* write a shuffle method that's incorrect, and
indeed by virtue of missing the "between i and length" detail.

> and saw that Guido used essentially the same switching method
> (although  it looks a lot better in Python than in Java : ).
> Naturally, I promptly rewrote my shuffle method:
>
> 	def shuffle(self):  random.shuffle(self.data)
>
> Still I'm curious.  Is there a clear advantage to the switching method
> as opposed to the pop and append method?

The swap method is the most efficient method known for this task.  Time it
versus the pop+append method over many lists of many sizes, and you'll
discover that the pop+append method is much slower.  But the pop+append
method is easier to prove correct, so if it's fast enough for you, stick with
it.




From bsass@freenet.edmonton.ab.ca  Fri May 11 21:46:29 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Fri, 11 May 2001 14:46:29 -0600 (MDT)
Subject: [Tutor] 15 puzzle
In-Reply-To: <20010510105621.D13769@tc.niof.net>
Message-ID: <Pine.LNX.4.33.0105111412550.20630-100000@bms>

On Thu, 10 May 2001, Rick Pasotto wrote:
<...>
> I run debian linux and debian is very meticulous about making sure that
> everything in a release works together and consequently debian releases
> are relatively rare.

I wouldn't count on that in the long term (or maybe even beyond the
next Debian release).  The "package pools" setup should increase the
realease frequency; it is already getting harder to pin down a Debian
system because it is easy to "apt-get install"
package/{unstable,testing,stable}, or even specify that "python"
should come out of stable and "python2" should come from testing or
unstable.

point:

It must be really tough to standardize a working environment when
there are multiple overlapping software and OS releases to contend
with... I don't envy you who have to put up with/make the decisions.

> I can easily install the 2.0 python itself from the debian unstable but
> the corresponding Tkinter requires the new X and that requires lots of
> other new stuff. Not an easy or safe upgrade.

It is very easy, and usually safe.

Of course you need to be somewhat more aware of the little bits of the
OS (the stuff that usually just works) when tracking any
unstable/testing distribution.


- Bruce



From tim.one@home.com  Fri May 11 22:06:39 2001
From: tim.one@home.com (Tim Peters)
Date: Fri, 11 May 2001 17:06:39 -0400
Subject: [Tutor] 15 puzzle
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D757@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <LNBBLJKPBEHFEDALKOLCOEKIKBAA.tim.one@home.com>

[alan.gauld@bt.com]
> ...
> So on that basis we should offer support for at least 1
> calander year after a version is superceded.

Who is "we"?

> Given the pace of change in open source software I'd favour
> the later option.
>
> Just my two cents,

Which is a lot more than the Python developers charged you <wink>.  As far as
Guido is concerned, support for a version ends the instant the next version
is released.  This isn't to be difficult, it's a necessary compromise with
the reality of finite time clashing with unbounded demands.

IOW, the "we" above won't include PythonLabs; even bugfix updates for the
current release will have to be done by volunteers or not at all.  Moshe
Zadka kindly volunteered to produce a bugfix release for 2.0, and Thomas
Wouters for 2.1, but no such release has yet happened so it's too soon to say
whether this will suffice.

could-be-there's-a-business-opportunity-here-but-if-so-it-will-
    require-a-business-to-pursue-it<wink>-ly y'rs  - tim



From arcege@speakeasy.net  Fri May 11 22:15:54 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Fri, 11 May 2001 17:15:54 -0400 (EDT)
Subject: [Tutor] 15 puzzle
In-Reply-To: <LNBBLJKPBEHFEDALKOLCOEKIKBAA.tim.one@home.com> from "Tim Peters" at May 11, 2001 05:06:39 PM
Message-ID: <200105112115.f4BLFs202525@dsl092-074-184.bos1.dsl.speakeasy.net>

Tim Peters wrote
> 
> [alan.gauld@bt.com]
> > ...
> > So on that basis we should offer support for at least 1
> > calander year after a version is superceded.
> 
> Who is "we"?

The discussion is more in terms of the tutor mailing list, not the
software itself.  The "we" here is probably the people doling out advice
and help on this list. :)

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From bsass@freenet.edmonton.ab.ca  Fri May 11 22:33:24 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Fri, 11 May 2001 15:33:24 -0600 (MDT)
Subject: [Tutor] Re: Multiple Assignments...
In-Reply-To: <08e201c0d93e$fb725df0$37ef87c0@ppathiyipc>
Message-ID: <Pine.LNX.4.33.0105111456220.20630-100000@bms>

On Thu, 10 May 2001, Praveen Pathiyil wrote:

> Hi Danny,
>         Thx for the explanation. I am just prolonging the discussion.....
>
> a,b = b,a
>
> In your words, this would be
> a, b = some_right_hand_side_value
>
> I was wondering abt the sequence after that.
> say a = 'A' and b = 'B' initially.
>
> If the assignment a = 'B' happens first, then won't the assignment for b
> will be 'B' itself as the value referenced by "a" on the RHS will be changed
> ?
>
> Or is it that all the objects on the RHS are replaced by their values before
> the assignment happen ?
>
> i.e, a, b = 'B', 'A'
>
> Just making sure !!!

When you recognize that this (below), and what Danny wrote, are
really saying the same thing, you got it...

Doing "a,b = 0,1" sets things up so that:

	a --> 0
	b --> 1

a and b are labels, 0 and 1 are objects

Doing "a, b = b, a" has the language going through this process:
(where *0 and *1 are pointers to the 0 and 1 objects)

	b, a --> (*1, *0)	# tupple packing

	(*1, *0) --> a, b	# tupple un-packing

which results in:

	a --\  /--> 0
	     \/
	     /\
	b --/  \--> 1

The RHS results in a new tuple (the temp, if you like), which is then
assigned to the LHS -- much different from a serial "a = b ; b = a",
you had in mind, eh.


- Bruce



From van@lindbergs.org  Sat May 12 00:52:12 2001
From: van@lindbergs.org (VanL)
Date: Fri, 11 May 2001 17:52:12 -0600
Subject: [Tutor] Restricting the type of passed-in objects
Message-ID: <3AFC7B2C.8090105@lindbergs.org>

Hello all,

I am working on implementing a tree. 

First I am going to do it as a class.  A tree would be defined as one or 
more treenodes.

My constructor looks like this:

class TreeNode:

   def __init__(self, name=None, data=None, objparent=None, 
childobjects=[]):
       if name: self.__label = name
       if data: self.__data = data
       if objparent: self.__parentlink = objparent
       if childobjects: self.__childrenlist = childobjects


Now here is my quandry:  I think that I would want to restrict the type 
of passed-in childobjects.  In my way of thinking, anyone who wanted a 
tree could either use the vanilla class or they could subclass 
TreeNode.  Ideally, then, the only objects passed in (as parents or 
children, with the possible exception of the parent to the root node) 
would be TreeNode instances (or whatever the subclass is).

However, what is to stop someone from saying:

 >>> mytree = Tree.TreeNode('myname', 'mydata', 'myparent', 'mychildren')

All the children (and the parent too, in this case) would be set to 
strings.   Some methods of  TreeNode might fail because they assume too 
much about the nature of the children.

Now, I could do a bunch of testing on the children before calling them, 
but that seems inelegant.  I looked at the module 'types', but that 
didn't seem to solve the problem:

 >>> type(mytree)
<type 'instance'>

Any instance of any class would pass that test.

What can I do?

Alternatively, am I thinking about this in the wrong way?  Do I *really* 
want to restrict the accepted types?  If I do, how can I structure this 
thing?

Thanks,

Van




From arcege@speakeasy.net  Sat May 12 01:03:35 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Fri, 11 May 2001 20:03:35 -0400 (EDT)
Subject: [Tutor] Restricting the type of passed-in objects
In-Reply-To: <3AFC7B2C.8090105@lindbergs.org> from "VanL" at May 11, 2001 05:52:12 PM
Message-ID: <200105120003.f4C03Zt02678@dsl092-074-184.bos1.dsl.speakeasy.net>

VanL wrote
> 
> Hello all,
> 
> I am working on implementing a tree. 
> 
> First I am going to do it as a class.  A tree would be defined as one or 
> more treenodes.
> 
> My constructor looks like this:
> 
> class TreeNode:
> 
>    def __init__(self, name=None, data=None, objparent=None, 
> childobjects=[]):
>        if name: self.__label = name
>        if data: self.__data = data
>        if objparent: self.__parentlink = objparent
>        if childobjects: self.__childrenlist = childobjects

As an aside before I answer the question, I would not use [] as the
default value for childobjects.  Set it to None and in __init__ create
a new list object if childobject is None.
  def __init__(self, ..., childobjects=None):
    if childobjects is None:
      childobjects = []

> Now here is my quandry:  I think that I would want to restrict the type 
> of passed-in childobjects.  In my way of thinking, anyone who wanted a 
> tree could either use the vanilla class or they could subclass 
> TreeNode.  Ideally, then, the only objects passed in (as parents or 
> children, with the possible exception of the parent to the root node) 
> would be TreeNode instances (or whatever the subclass is).

How about:
  isTreeNode = lambda inst, cls=TreeNode: not isinstanct(inst, cls)
  if filter(isTreeNode, childobjects):
    raise ValueError("objects in children are not TreeNodes")

If the result of filter is a non-empty list, there are elements that
are not instances of TreeNode... or of subclasses of TreeNode.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From kalle@gnupung.net  Sat May 12 01:41:35 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Sat, 12 May 2001 02:41:35 +0200
Subject: [Tutor] Restricting the type of passed-in objects
In-Reply-To: <3AFC7B2C.8090105@lindbergs.org>; from van@lindbergs.org on Fri, May 11, 2001 at 05:52:12PM -0600
References: <3AFC7B2C.8090105@lindbergs.org>
Message-ID: <20010512024135.A1205@apone.network.loc>

Sez VanL:
[wants to stop people from passing bad data to his methods]
> What can I do?

Use isinstance().

> Alternatively, am I thinking about this in the wrong way?  Do I *really* 
> want to restrict the accepted types?  If I do, how can I structure this 
> thing?

Assume that the passed objects are TreeNodes and catch AttributeErrors?

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From van@lindbergs.org  Sat May 12 01:53:24 2001
From: van@lindbergs.org (VanL)
Date: Fri, 11 May 2001 18:53:24 -0600
Subject: [Tutor] One other =?ISO-8859-1?Q?thing=B7=2E=2E=2E?=
References: <3AFC7B2C.8090105@lindbergs.org>
Message-ID: <3AFC8984.9070103@lindbergs.org>

One of the other things I was considering was extending this tree class 
to implement different types of trees.

(Start imaginary python session)

 >>>  from Tree import BinaryTree, AVLTree
 >>> a1 = AVLTree('data1')
 >>> a2 = AVLTree('data2')
 >>> b1 = BinaryTree('root')
 >>> b2 = BinaryTree('left')
 >>> a1.treetype()
'AVL'
 >>> b1.treetype()
'binary'
 >>> a1 = a1 + a2
 >>> b

That last operation would test that the two types were compatible, and, 
where applicable, perform the tree merge.  All this stuff would be hard 
to do, if not impossible, if I can't figure out what I've got when I am 
passed in an object.

Van



From van@lindbergs.org  Sat May 12 01:56:34 2001
From: van@lindbergs.org (VanL)
Date: Fri, 11 May 2001 18:56:34 -0600
Subject: [Tutor] Restricting the type of passed-in objects
References: <3AFC7B2C.8090105@lindbergs.org>
Message-ID: <3AFC8A42.8080403@lindbergs.org>

Thanks for the quick answers! 
 

That solved my problem even before I was done completely formulating it!


Van



From lsloan@umich.edu  Sat May 12 01:25:29 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Fri, 11 May 2001 20:25:29 -0400
Subject: [Tutor] getting *just* pydoc?
In-Reply-To: Your message of "Fri, 11 May 2001 13:44:58 EDT."
 <B21958504D50D311A80A00A0C9E594AA01DEF582@PM-SVR03>
Message-ID: <200105120025.UAA08946@birds.us.itd.umich.edu>

Brian Conley wrote:
> You can try this website:
> http://www.orgmf.com.ar/condor/pytstuff.html
> 
> There you can get the Python Shelf.  It's pretty cool.

Thanks, I'll consider it.  I just looked at that page and
I noticed it said it's for Windows.  I use Macs and UNIX
almost exclusively, so I'm not sure how much it will help
me.  I'll give it a look anyway.

Thanks!

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From tbrauch@mindless.com  Sat May 12 02:21:20 2001
From: tbrauch@mindless.com (Timothy M. Brauch)
Date: Fri, 11 May 2001 21:21:20 -0400
Subject: [Tutor] Binary
Message-ID: <3AFC9010.54F04B1D@mindless.com>

Okay, I know hex(x) will display x in hexadecimal and oct(x) will
display x in octal, but how do I display x in binary?  I've tried
seraching the python docs, but a search on binary turns up more on
binary distributions and a search on base turns up stuff about base
classes.

And another (hopefully) quick question, if & is a bit-wsie and, what
does the command 'and' do?

 - Tim


From kalle@gnupung.net  Sat May 12 02:53:19 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Sat, 12 May 2001 03:53:19 +0200
Subject: [Tutor] Binary
In-Reply-To: <3AFC9010.54F04B1D@mindless.com>; from tbrauch@mindless.com on Fri, May 11, 2001 at 09:21:20PM -0400
References: <3AFC9010.54F04B1D@mindless.com>
Message-ID: <20010512035319.B1205@apone.network.loc>

Sez Timothy M. Brauch:
> Okay, I know hex(x) will display x in hexadecimal and oct(x) will
> display x in octal, but how do I display x in binary?  I've tried
> seraching the python docs, but a search on binary turns up more on
> binary distributions and a search on base turns up stuff about base
> classes.

No standard function.  Quick, untested, probably bad code, please improve:

def binary(i):
    ret = []
    while i:
        ret.append(i & 1)
	i = i >> 1
    ret.reverse()
    return "".join(map(str, ret))

> And another (hopefully) quick question, if & is a bit-wsie and, what
> does the command 'and' do?

Logical and.  'x and y' is true iff x is true and y is true.  y is not
evaluated if x is false.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From arcege@speakeasy.net  Sat May 12 03:10:42 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Fri, 11 May 2001 22:10:42 -0400 (EDT)
Subject: [Tutor] Binary
In-Reply-To: <3AFC9010.54F04B1D@mindless.com> from "Timothy M. Brauch" at May 11, 2001 09:21:20 PM
Message-ID: <200105120210.f4C2AgA02802@dsl092-074-184.bos1.dsl.speakeasy.net>

Timothy M. Brauch wrote
> 
> Okay, I know hex(x) will display x in hexadecimal and oct(x) will
> display x in octal, but how do I display x in binary?  I've tried
> seraching the python docs, but a search on binary turns up more on
> binary distributions and a search on base turns up stuff about base
> classes.

There isn't one really.  You have to whip up your own.

def bin(n):
  """Return a bit string representing the number, right-justified."""
  s = ''
  while n:
    if n & 01:
      s = '1' + s
    else:
      s = '0' + s
    n = n >> 1
  return s

> And another (hopefully) quick question, if & is a bit-wsie and, what
> does the command 'and' do?

It is called in some areas the "logical and".  It compares boolean values
instead of binary values, but otherwise it is the same.  With boolean
values the whole value is either true or false, instead of just one bit
in a number.

a = ''   # a is false
b = 'a'  # b is true
c = []   # c is false (length is zero)
d = [b]  # d is true  (length is not zero)
e = [a]  # e is true  (length is not zero, even tho a is false)
f = 0    # f is false
g = 1    # g is true
h = -1   # g is true (non-zero)

Using these booleans, logical "and" just extends the bit-wise "and".

  logical                            binary
a (false) and b (true) == false    0 (0000) & 1 (0001) == 0 (0000)
b (true)  and d (true) == true     1 (0001) & 1 (0001) == 1 (0001)
4 (true)  and 5 (true) == true     4 (0100) & 5 (0101) == 4 (0100)

This goes the same for logical "or" and logical "not" as well.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From sheila@thinkspot.net  Sat May 12 03:49:59 2001
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 11 May 2001 19:49:59 -0700
Subject: [Tutor] Binary
In-Reply-To: <200105120210.f4C2AgA02802@dsl092-074-184.bos1.dsl.speakeasy.net>
References: <3AFC9010.54F04B1D@mindless.com> <200105120210.f4C2AgA02802@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <2C235235315@kserver.org>

On Fri, 11 May 2001 22:10:42 -0400 (EDT), "Michael P. Reilly"
<arcege@dsl092-074-184.bos1.dsl.speakeasy.net>  wrote about Re: [Tutor] Binary:

:def bin(n):
:  """Return a bit string representing the number, right-justified."""
:  s = ''
:  while n:
:    if n & 01:
:      s = '1' + s
:    else:
:      s = '0' + s
:    n = n >> 1
:  return s

OK, I tried this out, and it works, apparently.
But I don't understand the code.

What does this line do?

if n & 01:

and what about this line?

n = n >> 1

I thought, for a minute, someone was using C or C++ to "extend" Python, until I
looked more carefully.

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



From sheila@thinkspot.net  Sat May 12 04:20:16 2001
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 11 May 2001 20:20:16 -0700
Subject: [Tutor] IDLE is broken ??
Message-ID: <2DDA4F00DAE@kserver.org>

I'm running Windows 98. I had installed Python 2.0 probably back in January. It
came with IDLE 0.6. Great.

Recently I got the idea to install the Win32all extensions from Active State. I
installed Build 138, for BeOpen Python 2.0.

Now, some time later, I notice that I only have IDLE 0.5 on my system. ???
Furthermore, it seems to be broken. It runs in interactive mode, but when I open
a script file and try to run it in IDLE I get this error message:
"Program disconnected".

I'm completely baffled by this, and not sure how to remedy it. How can I get
IDLE 0.6 back on my system again? (I'm uncertain how to proceed.)

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

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


From sheila@thinkspot.net  Sat May 12 05:32:42 2001
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 11 May 2001 21:32:42 -0700
Subject: [Tutor] IDLE is broken ??
In-Reply-To: <2DDA4F00DAE@kserver.org>
References: <2DDA4F00DAE@kserver.org>
Message-ID: <31FBEBC68C8@kserver.org>

Actually, it occurs to me after posting this, that it may have been due to
installing VPython. :(

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


On Fri, 11 May 2001 20:20:16 -0700, Sheila King <sheila@thinkspot.net>  wrote
about [Tutor] IDLE is broken ??:

:I'm running Windows 98. I had installed Python 2.0 probably back in January. It
:came with IDLE 0.6. Great.
:
:Recently I got the idea to install the Win32all extensions from Active State. I
:installed Build 138, for BeOpen Python 2.0.
:
:Now, some time later, I notice that I only have IDLE 0.5 on my system. ???
:Furthermore, it seems to be broken. It runs in interactive mode, but when I open
:a script file and try to run it in IDLE I get this error message:
:"Program disconnected".
:
:I'm completely baffled by this, and not sure how to remedy it. How can I get
:IDLE 0.6 back on my system again? (I'm uncertain how to proceed.)
:
:--
:Sheila King
:http://www.thinkspot.net/sheila/
:http://www.k12groups.org/



From scarblac@pino.selwerd.nl  Sat May 12 05:38:20 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sat, 12 May 2001 06:38:20 +0200
Subject: [Tutor] Binary
In-Reply-To: <3AFC9010.54F04B1D@mindless.com>; from tbrauch@mindless.com on Fri, May 11, 2001 at 09:21:20PM -0400
References: <3AFC9010.54F04B1D@mindless.com>
Message-ID: <20010512063820.A10601@pino.selwerd.nl>

On  0, "Timothy M. Brauch" <tbrauch@mindless.com> wrote:
> Okay, I know hex(x) will display x in hexadecimal and oct(x) will
> display x in octal, but how do I display x in binary?  I've tried
> seraching the python docs, but a search on binary turns up more on
> binary distributions and a search on base turns up stuff about base
> classes.

I like this method. It does keep some leading 0s:

_bindict = {
   '0': '0000',
   '1': '0001',
   '2': '0010',
   '3': '0011',
   '4': '0100',
   '5': '0101',
   '6': '0110',
   '7': '0111',
   '8': '1000',
   '9': '1001',
   'a': '1010',
   'b': '1011',
   'c': '1100',
   'd': '1101',
   'e': '1110',
   'f': '1111'
   }
   

def bin(x):
    import string
    h = hex(x)[2:] # Skip the '0x' bit
    string.join(map(_bindict.get, h), "")
 


From toodles@yifan.net  Sat May 12 06:19:34 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Sat, 12 May 2001 13:19:34 +0800
Subject: [Tutor] Re: Binary
Message-ID: <FPEHJJPEEOIPMAHOADBKAEGOCDAA.toodles@yifan.net>

I sent this directly to Sheila the first time (sorry!)

Hi Sheila,

I'll take a shot at interpreting it, but the others will probably do a
better job of it, I'm young and foolish =)

>
> :def bin(n):
> :  """Return a bit string representing the number, right-justified."""
> :  s = ''

Firstly, s is a string representing the 0's and 1's.

> :  while n:

While the decimal value n is not 0, loop through, we'll see how it is
decremented later.

> :    if n & 01:

This is a bitwise and: it checks to see whether the first bit (right
aligned) is 1.
For example, 3 decimal in binary is 0000011,  1 decimal in binary is 1
(i'm not treating you as if you don't know, this is just an example)

& returns a decimal represtation of the the binary number with bits set
where the bits in the first two operands were the same. (I can hardly
understand my own logic, I hope you can)

> :      s = '1' + s

So if the number's first bit is set, add a '1' to s.

> :    else:
> :      s = '0' + s

Else, a '0'

> :    n = n >> 1

This is a bitwise shift of 1 in the right direction.
eg. 00000011 >> 1 = 00000001 = 1 decimal
eg. 00000011 << 1 = 00000110 = 6 decimal

I hope that helps...at least a little bit! =)

Andrew




From dyoo@hkn.eecs.berkeley.edu  Sat May 12 08:46:12 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sat, 12 May 2001 00:46:12 -0700 (PDT)
Subject: [Tutor] List iteration
In-Reply-To: <200105110547_MC2-D0AA-E23E@compuserve.com>
Message-ID: <Pine.LNX.4.21.0105120038450.25186-100000@hkn.eecs.berkeley.edu>

On Fri, 11 May 2001, Sharriff Aina wrote:

> Hi guys!
> 
> I would like to do some list iteration, is there a way to do something like
> this:
> 
> 
> # code start
> list_a = ['a', 'b', 'c']
> list_b = ['d', 'e', 'f']
> 
> for x, y in [list_a, list_b]:
> ....print  x + y          # hypo, this FAILS!! since the iterators length
> is shorter than the number of elements in list_a or list_b

What would you like to come out?  There are two potential kinds of outputs
I can see coming out of this:

### POTENTIAL OUTPUT 1
###
ad
be
cf
###

which is the map/zip() solution that Ibraheem and Simon showed.  In Mathy
terms, this is the idea of the standard dot product, to take corresponding
pair elements, and put them together.


### POTENTIAL OUTPUT 2
###
ad
ae
af
bd
be
bf
cd
ce
cf
###

which is more like the "cross" product, which takes every possible
combination, where one part comes from the first list, and the other from
the second.

Can you tell us which output you expect to come out?




From kalle@gnupung.net  Sat May 12 12:18:59 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Sat, 12 May 2001 13:18:59 +0200
Subject: [Tutor] Binary
In-Reply-To: <2C235235315@kserver.org>; from sheila@thinkspot.net on Fri, May 11, 2001 at 07:49:59PM -0700
References: <3AFC9010.54F04B1D@mindless.com> <200105120210.f4C2AgA02802@dsl092-074-184.bos1.dsl.speakeasy.net> <2C235235315@kserver.org>
Message-ID: <20010512131859.A371@apone.network.loc>

Sez Sheila King:
> On Fri, 11 May 2001 22:10:42 -0400 (EDT), "Michael P. Reilly"
> <arcege@dsl092-074-184.bos1.dsl.speakeasy.net>  wrote about Re: [Tutor] Binary:
> 
> :def bin(n):
> :  """Return a bit string representing the number, right-justified."""
> :  s = ''
> :  while n:
> :    if n & 01:
> :      s = '1' + s
> :    else:
> :      s = '0' + s
> :    n = n >> 1
> :  return s
> 
> OK, I tried this out, and it works, apparently.
> But I don't understand the code.
> 
> What does this line do?
> 
> if n & 01:

n & 01 is the bitwise and of n and 1.  This is 1 if the least significant
bit of n is 1, else 0.

> and what about this line?
> 
> n = n >> 1

All the bits in n are shifted one step to the right:
>>> bin(13)
'1101'
>>> bin(13 >> 1)
'110'
>>> bin(13 >> 2)
'11'
>>> bin(13 >> 3)
'1'
>>> bin(13 >> 4)
''

> I thought, for a minute, someone was using C or C++ to "extend" Python, until I
> looked more carefully.

You could replace
if n & 01:
with
if n % 2:
and
n = n >> 1
with
n = n / 2
but that would be slower.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From r.b.rigilink@chello.nl  Sat May 12 13:58:42 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Sat, 12 May 2001 14:58:42 +0200
Subject: [Tutor] Restricting the type of passed-in objects
Message-ID: <3AFD3382.AF5626D9@chello.nl>

VanL wrote:

> I am working on implementing a tree. 
> 
> First I am going to do it as a class.  A tree would be defined as one or 
> more treenodes.
> 
> My constructor looks like this:
> 
> class TreeNode:
>
>   def __init__(self, name=None, data=None, objparent=None, childobjects=[]):
>       if name: self.__label = name
>       if data: self.__data = data
>       if objparent: self.__parentlink = objparent
>       if childobjects: self.__childrenlist = childobjects
>
>
> Now here is my quandry:  I think that I would want to restrict the type 
> of passed-in childobjects.  In my way of thinking, anyone who wanted a 
> tree could either use the vanilla class or they could subclass 
> TreeNode.  Ideally, then, the only objects passed in (as parents or 
> children, with the possible exception of the parent to the root node) 
> would be TreeNode instances (or whatever the subclass is).
>

[..snip..]

> Alternatively, am I thinking about this in the wrong way?  Do I *really* 
> want to restrict the accepted types?  If I do, how can I structure this 
> thing?

I think an important question to ask here is how you want your clients
to use the Tree.

Are clients going to add Nodes by calling the constructor of TreeNode
directly?

Apart from worrying about the types of the children (which can be
checked with isinstance(object, class), but see below) you then have
to worry about some more difficult problems. For instance:

self in self.__parentlink.__childrenlist 

should always be true, except for the root object, which has no
parentlink

Suppose on the other hand that clients add a treenode with:

class TreeNode:
    ...
    def add_node(self, name, data):
        newnode = TreeNode(name=name, data=data, objparent=self)
	self.__childrenlist.append(newnode)
        return newnode

Then you don't have to worry at all about clients creating
TreeNodes with bogus parents and children.

So, how do you go about designing your Tree interface?

It depends on what you're going to use the tree for.

I can think of several different answers.

o The tree is going to be the underlying data structure for a
  sequence.  For example, an AVL-tree to implement a sorted list

o The tree is going to be the underlying data structure for a
  mapping. To make a UserDict with sorted keys for instance.
  
In these cases the interface to your tree is pretty much determined
by the interface to your sequence or mapping respectively.

Another possibility is that you want to be able to inherit
a particular class from a tree. For example:

class FileSystem(Tree):
    pass

In this case the fact that the object is a tree seems central to the use
of the object (while in the previous cases, it was an implementation
detail). 

Writing a general Tree object (or even defining an abstract interface)
usable in all these cases is very difficult (I'm not smart enough to
confidently use the word impossible).  Note, for example, that in the
'data-structure' cases, it is essential that the tree decides where a
new node is inserted, while in the FileSystem case the user decides
where a new node is inserted. E.g. In an AVL tree you add values to
the tree in a FileSystem you add nodes to a TreeNode (Directory)

If you want to write a Tree class that you can provitably use for both

class FileSystem(Tree):

and 

class AVLTree(Tree):

a possible route might be to first write FileSystem and AVLTree
classes and then see what code they have in common.

A note on typechecking in Python:

Checking whether an object is an instance of a given class in general
doesn't buy you much in terms of safety, and may cost you in terms of
usability.

For example:

def doit(obj):
    if isinstance(obj, DoableClass):
        return obj.dosomething()
    else:
        print "Sorry, can't do it"

There are two problems here.

Suppose somebody did:

obj = DoableClass()
obj.dosomething = None
doit(obj):

you will get an exception, despite your test.
On the other hand:

class AlsoDoable:
    def dosomething(self):
        ...
obj = AlsoDoable()
doit(obj)

will result in "Sorry can't do it", even if AlsoDoable.dosomething()
pefectly matches what you expect an obj passed to doit() to be able to
do. You loose polymorphism.

An alternative is:

def doit(obj):
    try:
        return obj.dosomething()
    except:
        print "Sorry, can't do it"

The "It's easier to ask forgiveness than permission"-idiom

Alex Martelli has written extensively on comp.lang.python on this
subject (Polymorphism). If you insist on doing checks then have a look
at:

http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52291

for a "Look before you leap"-idiom that's polymorphic


Hope this helps,

Roeland Rengelink


From bsass@freenet.edmonton.ab.ca  Sat May 12 19:09:02 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Sat, 12 May 2001 12:09:02 -0600 (MDT)
Subject: [Tutor] One other =?ISO-8859-1?Q?thing=B7=2E=2E=2E?=
In-Reply-To: <3AFC8984.9070103@lindbergs.org>
Message-ID: <Pine.LNX.4.33.0105121102360.26633-100000@bms>

On Fri, 11 May 2001, VanL wrote:

> One of the other things I was considering was extending this tree class
> to implement different types of trees.
>
> (Start imaginary python session)
>
>  >>>  from Tree import BinaryTree, AVLTree
>  >>> a1 = AVLTree('data1')
>  >>> a2 = AVLTree('data2')
>  >>> b1 = BinaryTree('root')
>  >>> b2 = BinaryTree('left')
>  >>> a1.treetype()
> 'AVL'
>  >>> b1.treetype()
> 'binary'
>  >>> a1 = a1 + a2
>  >>> b
>
> That last operation would test that the two types were compatible, and,
> where applicable, perform the tree merge.  All this stuff would be hard
> to do, if not impossible, if I can't figure out what I've got when I am
> passed in an object.

Hmmm, could it be that you, "can't see the forest for the trees"
(sorry).

The two ends of the spectrum are efficiency and portability;
at the portability extreme...

Does it really matter how a tree is
implemented, or is it enough to be able to get the data out.  I mean,
why do you need to know the internals of the tree (what class it is)
to do...

	newtree.insert(tree.inorder())

Ok, you probably want to test that "tree" has an "inorder" method (or
preorder, or postorder, or tranverse, whatever, especially if you are
inserting into a basic binary tree ;), but it would be best to test
for the method that does what you want -- just in case some class you
have never heard of comes along (maybe FasterAVLTree).

from an efficiency p.o.v...
You start off with "from Tree import BinaryTree, AVLTree", want to
operate on trees as a whole (+'em), and expect a treetype method, that
tells me you are the coder and can implement them anyway you want.  So
why not have a base node class that defines a data/key attribute,
common to all types of trees, you can then check:

	isinstance(tree, BasicNodeClass)

'cause:
>>> class A:
...    pass
...
>>> class B(A):
...    pass
...
>>> b = B()
>>> isinstance(b, A)
1

...and if you made it this far, you can access the data directly
(since you wrote BasicNodeClass).  If you are going to break the ADT,
you may as well go all the way.

Either way (efficient or portable), it is not necessary to know
whether you have an AVLTree or a BinaryTree instance, just how to get
at the contents of the tree.


- Bruce



From st_hickey@hotmail.com  Sat May 12 22:18:08 2001
From: st_hickey@hotmail.com (Stevenson Hickey)
Date: Sat, 12 May 2001 14:18:08 -0700
Subject: [Tutor] DBZ files
References: <E14y6mQ-0000XK-00@mail.python.org>
Message-ID: <OE40idW8CHjhezylN8I000018dc@hotmail.com>

HI!

A friend of mine just asked me to decode some DBZ files for her.  I was able
to find some info about the DBZ database storage file, but not enough to see
how to decode it.  Does anyone have any information about the structure of
the DBZ file?  I thought that I should be able to open the file and read out
the data in some order so that I could match the fields and pass this to
another file.  It seemed to me that Python was ideal for this type of thing.

Thanks for any help,

Stevenson Hickey


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.252 / Virus Database: 125 - Release Date: 5/9/2001


From alan.gauld@bt.com  Sun May 13 00:15:13 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 13 May 2001 00:15:13 +0100
Subject: [Tutor] 15 puzzle
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D760@mbtlipnt02.btlabs.bt.co.uk>

> Who is "we"?

The python tutor list community.

> > Just my two cents,
> 
> Which is a lot more than the Python developers charged you 

Which is why I don't expect them to support even the current version!
But this list is comprised people who have volunteered to support 
newbies so "we" should offer support for, say, 1 year after a 
release before saying just "get the new version" - which may 
not be a realistic option for anyone learning in a corporate 
environment. (I had to learn Python on V1.3 even tho' 1.5.1 
was just out - our upgrade cycle hadn't got there yet...)

> IOW, 

IOW? Thats a new one on me?

> the "we" above won't include PythonLabs

I wouldn't expect it to, but I would plead for the tutor list 
to accept users of older versions.

Alan G


From alan.gauld@bt.com  Sun May 13 00:21:31 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 13 May 2001 00:21:31 +0100
Subject: [Tutor] Restricting the type of passed-in objects
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D761@mbtlipnt02.btlabs.bt.co.uk>

> First I am going to do it as a class.  A tree would be 
> defined as one or more treenodes.


The classic way to do this as defined by the GoF is to create 
a structure with an abstract superclass (TreeElement say) which 
has 2 subclasses TreeNode, TreeItem say. The first is an empty 
node simply pointing to other TreeElements and the latter is an 
actual data item within the tree.

If they all have the same methods you can treat them all the 
same.
This is described in the Patterms book under the "composite pattern"

If you do that your tree code can be independant of the actual 
data. Of course the consumer of the data still has to worry 
about its type but thats not your tree's worry!


Alan G


From alan.gauld@bt.com  Sun May 13 00:05:21 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 13 May 2001 00:05:21 +0100
Subject: [Tutor] List iteration
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D75F@mbtlipnt02.btlabs.bt.co.uk>

> I would like to do some list iteration, is there a way to do 
> something like
> this:

In general when doing things with lists its worth checking the 
so called functional programming features:

map, filter, reduce and list comprehension(in V2)

In this case amp will do what you want provided the 
lists are of equal length (you can get around that 
as I'll show later):

> list_a = ['a', 'b', 'c']
> list_b = ['d', 'e', 'f']

result = map(lambda x,y:x+y, list_a, list_b)

If you need error checking for different lengths(map will use 
None by default) write a fuunction first:

def add2(x,y):
   if x == None: x = 0
   if y == None: y = 0
   return x+y

result = map(add2, list_a, list_b)

My online tutor has a page on functional programming which 
describes these functions(except list comprehensions).

Alan G
http://www.crosswinds.net/~agauld


From sarnold@earthling.net  Sun May 13 01:30:37 2001
From: sarnold@earthling.net (Stephen L Arnold)
Date: Sat, 12 May 2001 17:30:37 -0700
Subject: [Tutor] =?ISO-8859-1?Q?Re:_One_other_thing=B7..._=28and_more=29?=
In-Reply-To: <Pine.LNX.4.33.0105121102360.26633-100000@bms>
References: <3AFC8984.9070103@lindbergs.org>
Message-ID: <20010513003039.59F631F664@shiva.arnolds.bogus>

On 12 May 01, at 12:09, Bruce Sass wrote:

> On Fri, 11 May 2001, VanL wrote:
> 
[snip]
> > That last operation would test that the two types were compatible, and,
> > where applicable, perform the tree merge.  All this stuff would be hard
> > to do, if not impossible, if I can't figure out what I've got when I am
> > passed in an object.
> 
> Hmmm, could it be that you, "can't see the forest for the trees"
> (sorry).
[snip]

I'm just starting with Python, so I'd also like to know how this 
works too.  Sorry it's kinda long, but I inserted some example code 
from a binary search tree.  I'd like to know (in general) how this 
kind of thing works in Python.  The syntax of the code below is 
very readable (though a bit more verbose than Python).  Comments 
are preceded by two dashes.

Whether you want to think in terms of objects and methods or 
generic packages and generic formal parameters (it least that's the 
way I understand it) there must be some way to define the set of 
valid operations, arguments, etc.  In Ada, this is defined in the 
package specification.  You don't need (or want) to know how the 
code in the package body is implemented, unless of course, you're 
the one doing the implementing (it just needs to conform to the 
spec).

Using the binary search tree example, in the package spec I would 
define the data types, overloaded operators, and the first 
procedure like this:

-- This is the package spec --
generic
   type Element_Type is private;
   type Key_Type     is private;
   with function Key(Item : in Element_Type) return Key_Type;
   with function "="(Left, Right : in Key_Type) return Boolean is <>;
   with function "<"(Left, Right : in Key_Type) return Boolean is <>;

package Binary_Search_Tree is

   type BST is limited private;
   type Traversal is (In_Order, Pre_Order, Post_Order);

   Overflow     :  exception;  -- Raised when tree space runs out.
   Key_Error    :  exception;  -- Raised for bogus key operations.
   State_Error  :  exception;  -- Raised for more than one concurrent
                               -- traversal, or state change during
                               -- a traversal.

   -------------------------------------------------------------------------
   procedure Insert(Item : in Element_Type; Tree : in out BST);

   -- Adds Item to Tree.

   -- Exceptions:
   --   Overflow      Item could not be added to Tree.
   --   Key_Error     Key(Item) already exists.
   --   State_Error   Tree is in a traversal.
   -------------------------------------------------------------------------

The above tells you all you need to know about data types, valid 
operators, and procedures/functions and their arguments (of course, 
there are more than just Insert).  It even tells you which kinds of 
exceptions to expect from each function or procedure.  If I were 
writing this package (or just curious) I might find something like 
this implementation in the package body:

-- This is the package body --
with Ada.Exceptions ;
with Ada.Unchecked_Deallocation ;

package body Binary_Search_Tree is

   procedure Free is new Ada.Unchecked_Deallocation(Tree_Node, Tree_Node_Ptr);

   -------------------------------------------------------------------------
   procedure Insert(Item : in Element_Type; Tree : in out BST) is

   -- Adds Item to Tree.

   -- Exceptions:
   --   Overflow      Item could not be added to Tree.
   --   Key_Error     Key(Item) already exists.
   --   State_Error   Tree is in a traversal.

      New_item : Tree_Node_Ptr := null;
      Parent   : Tree_Node_Ptr := null;
      Target   : Tree_Node_Ptr := Tree.Root;

   begin -- Insert

      if Tree.Traversing then
         Ada.Exceptions.Raise_Exception (State_Error'identity,
                         "Error using Insert.  Tree is already in a traversal.");
      end if;

      -- Find the insert spot.
      while Target /= null loop
         Parent := Target;
         if Key(Item) = Key(Target.Data) then
            Ada.Exceptions.Raise_Exception (Key_Error'identity,
                            "Error using Insert.  Key already exists.");
         elsif Key(Item) < Key(Target.Data) then
            Target := Target.Child(Left);
         else
            Target := Target.Child(Right);
         end if;
      end loop;

      begin
         New_Item := new Tree_Node'(Item, (others => null));
      exception
         when Storage_Error =>
            Ada.Exceptions.Raise_Exception (Overflow'identity,
                         "Error using Insert.  Not enough free memory.");
      end;

      -- Insert new item
      if Parent = null then
         Tree.Root := New_Item;
      elsif Key(Item) < Key(Parent.Data) then
         Parent.Child(Left) := New_Item;
      else
         Parent.Child(Right) := New_Item;
      end if;
      Tree.Count := Natural'Succ(Tree.Count);
   end Insert;

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

But I still can't do anything with it unless I 'with' this package 
in some other code (such as a test driver).  Part of such a driver 
might look like this:

-- First I have to 'with' my bst package (and a few others)
   with Ada.Text_IO;                        use Ada.Text_IO;
   with Ada.Integer_Text_IO;                use Ada.Integer_Text_IO;
   with Ada.Exceptions;                     use Ada.Exceptions;
   with Ada.Numerics.Discrete_Random;
   with Ada.Unchecked_Deallocation;

   with Binary_Search_Tree;

-- Then I can instantiate a tree like this:
   procedure BST_Test is

      package BT is new Binary_Search_Tree(Integer, Integer, Identity, "=","<");    use BT;
      package Boolean_IO is new Ada.Text_IO.Enumeration_IO (enum => Boolean);

-- and create some trees and integers to fill them:
      A, B, C, D : aliased BST;
      m : Integer := 0;
      ns : array(1..8) of Integer := (11, 8, 10, 17, 3, 1, 4, 13);
      na : array(1..8) of Integer := (12, 9, 11, 16, 5, 18, 7, 14);

I hope that's enough to give a fairly clear picture of what's going 
on (and isn't too confusing).  The rest of the code is available on 
my webserver (it's just the homework problems from the data 
structures class I took last year):

http://arnolds.dhs.org/cgi-bin/viewcvs.cgi/Ada/CS-152/

How does this kind of thing work in Python?  I guess you would 
define a binary_search_tree class, with methods like insert, 
delete, etc, exceptions, what parameters can be passed to the 
methods, any overloaded operators, etc.  You would also have to 
specify (perhaps when you instantiate a tree object) what types are 
contained in the tree.  As a user of the tree class library, how do 
I find out what methods/parameters are valid, what the exception 
names are, etc?

Any one care to give it a go?  (sorry about the Ada code, but I 
can't do it in Python yet...)

Steve

*************************************************************
Steve Arnold                           http://arnolds.dhs.org

Things go better with Linux and King Crimson.


From doc_pepin@yahoo.com  Sun May 13 04:21:03 2001
From: doc_pepin@yahoo.com (doc pepin)
Date: Sat, 12 May 2001 20:21:03 -0700 (PDT)
Subject: [Tutor] Learning Python or Programming Python
Message-ID: <20010513032103.33617.qmail@web13903.mail.yahoo.com>

for a newbie programmer which book you'll recommend
"learning python" or "programming python"

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/


From rob@jam.rr.com  Sun May 13 04:29:19 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Sat, 12 May 2001 22:29:19 -0500
Subject: [Tutor] Learning Python or Programming Python
References: <20010513032103.33617.qmail@web13903.mail.yahoo.com>
Message-ID: <3AFDFF8F.C24E4030@jam.rr.com>

If you are new to Python but have experience with any recent programming
language, *Learning Python* is great. *Programming Python* makes more
sense after you are familiar with language basics as presented in books
such as Learning Python.

If Python is your first language, you might like Learn to Program Using
Python by Alan Gauld. His website also presents plenty of good material.
Teach Yourself Python in 24 Hours by Ivan Van Laningham is also pretty
decent. There are others as well.

Rob

doc pepin wrote:
> 
> for a newbie programmer which book you'll recommend
> "learning python" or "programming python"
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From sheila@thinkspot.net  Sun May 13 04:30:15 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sat, 12 May 2001 20:30:15 -0700
Subject: [Tutor] Learning Python or Programming Python
In-Reply-To: <20010513032103.33617.qmail@web13903.mail.yahoo.com>
References: <20010513032103.33617.qmail@web13903.mail.yahoo.com>
Message-ID: <6696A97E19@kserver.org>

On Sat, 12 May 2001 20:21:03 -0700 (PDT), doc pepin <doc_pepin@yahoo.com>  wrote
about [Tutor] Learning Python or Programming Python:

:for a newbie programmer which book you'll recommend
:"learning python" or "programming python"

Definitely not "Programming Python". This is a 1300 page tome for someone who
already knows a bit of Python and is looking to go more in depth.

I've not seen "Learning Python", although I've seen others recommend it. Also,
consider "Core Python Programming". I have that one, and it is pretty good.

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



From dyoo@hkn.eecs.berkeley.edu  Sun May 13 04:54:04 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sat, 12 May 2001 20:54:04 -0700 (PDT)
Subject: [Tutor] List iteration
In-Reply-To: <200105122227_MC2-D0BF-935E@compuserve.com>
Message-ID: <Pine.LNX.4.21.0105122050080.13993-100000@hkn.eecs.berkeley.edu>

On Sat, 12 May 2001, Sharriff Aina wrote:

> Nachricht geschrieben von Daniel Yoo
> >an you tell us which output you expect to come out?
> 
> actually, all I needed was a way to to snatch image paths from HTML image
> tags, store them, modify the paths, insert the paths back in the image tags
> and stor them again.
> 
> I had extracted the image tags with a reg ex, further also the paths, so
> ended up with two lists. I wanted then a way to replace the the paths in
> the image tag list with a list of the modified paths at the same time.
> 
> The zip solution solved my problem.


If you're planning to do more HTML parsing, you might be interested in the
htmllib module:

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

It has a HTMLParser object that removes the need to work with regular
expressions.  Not that regular expressions aren't fun, but all those
pattern-matching symbols can be a little tedious.  htmllib tries to
make things easier.

I'm glad things are working for you!



From bdupire@seatech.fau.edu  Sun May 13 05:06:41 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Sun, 13 May 2001 00:06:41 -0400
Subject: [Tutor] faq
References: <20010513032103.33617.qmail@web13903.mail.yahoo.com>
Message-ID: <3AFE0851.6BA13943@seatech.fau.edu>

 doc pepin wrote:

> for a newbie programmer which book you'll recommend
> "learning python" or "programming python" ?





From dyoo@hkn.eecs.berkeley.edu  Sun May 13 05:11:12 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sat, 12 May 2001 21:11:12 -0700 (PDT)
Subject: [Tutor] Learning Python or Programming Python
In-Reply-To: <3AFDFF8F.C24E4030@jam.rr.com>
Message-ID: <Pine.LNX.4.21.0105122107320.13993-100000@hkn.eecs.berkeley.edu>

On Sat, 12 May 2001, Rob Andrews wrote:

> If Python is your first language, you might like Learn to Program Using
> Python by Alan Gauld. His website also presents plenty of good material.
> Teach Yourself Python in 24 Hours by Ivan Van Laningham is also pretty
> decent. There are others as well.

Here's the link to Alan's web site:

    http://www.crosswinds.net/~agauld/


There are a bunch of other tutorials on the python.org web site here:

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

and you can pick and choose to see which approach you like the best.


If you have any questions about learning Python, feel free to ask us.



From bdupire@seatech.fau.edu  Sun May 13 05:14:21 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Sun, 13 May 2001 00:14:21 -0400
Subject: [Tutor] faq
References: <20010513032103.33617.qmail@web13903.mail.yahoo.com> <3AFE0851.6BA13943@seatech.fau.edu>
Message-ID: <3AFE0A1D.AB98A824@seatech.fau.edu>


Benoit Dupire wrote:

>  doc pepin wrote:
>
> > for a newbie programmer which book you'll recommend
> > "learning python" or "programming python" ?
>

Just to mention that there should be a FAQ dedicated to this Tutor
Mailing List to answer such questions...

I love this mailing list and some answers are of very good quality and
it is a shame that there's nothing in the archives  to say ' HEP! this
is a very neat
post with a very nice explanation, just read me'...
Or sometimes a good summary of  a particular long thread would be a very
good thing to add to this FAQ....

As a matter of fact, I saw that there was such a website at:
http://www.faqts.com/knowledge_base/index.phtml/fid/199/

but i haven't seen this URL mentionned in the tutor mailing list
before???
Anyway, IMHO, it looks great !!

Benoit



From sheila@thinkspot.net  Sun May 13 05:44:47 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sat, 12 May 2001 21:44:47 -0700
Subject: [Tutor] faq
In-Reply-To: <3AFE0A1D.AB98A824@seatech.fau.edu>
References: <20010513032103.33617.qmail@web13903.mail.yahoo.com> <3AFE0851.6BA13943@seatech.fau.edu> <3AFE0A1D.AB98A824@seatech.fau.edu>
Message-ID: <AAD0D939CC@kserver.org>

On Sun, 13 May 2001 00:14:21 -0400, Benoit Dupire <bdupire@seatech.fau.edu>
wrote about Re: [Tutor] faq:

:As a matter of fact, I saw that there was such a website at:
:http://www.faqts.com/knowledge_base/index.phtml/fid/199/

For an even shorter version of that URL, try:
http://python.faqts.com

It redirects to the same website, and is easier to remember.

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



From dyoo@hkn.eecs.berkeley.edu  Sun May 13 06:09:55 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sat, 12 May 2001 22:09:55 -0700 (PDT)
Subject: [Tutor] 15 puzzle  [language compatibility]
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D760@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.21.0105122122260.13993-100000@hkn.eecs.berkeley.edu>

On Sun, 13 May 2001 alan.gauld@bt.com wrote:

> > the "we" above won't include PythonLabs
> 
> I wouldn't expect it to, but I would plead for the tutor list 
> to accept users of older versions.

I agree; we certainly don't expect people to automatically adopt new words
when a new edition of an English dictionary arrives: human language is
alive and spoken.  Although people gradually adopt new words and idioms,
the process takes time, and I think the same approach should apply when
we're tutoring Python.

If people ask something that has multiple solutions, let's show how it's
done in Python 2.1, and then, if the 1.52 approach is reasonable, show how
to do it in that fashion.  If the "old" way of doing something is just
unreasonable and kludgy, perhaps it will be appropriate to warn people
away from it if they can.  But the main point is that we're here to serve
the community of Python learners, not Python itself.  Perhaps this is
heresy.  *grin*



From tutor@python.org  Sun May 13 09:18:39 2001
From: tutor@python.org (Tim Peters)
Date: Sun, 13 May 2001 04:18:39 -0400
Subject: [Tutor] =?iso-8859-1?Q?RE:_=5BTutor=5D_Re:_One_other_thing=B7..._=28and_more=29?=
In-Reply-To: <20010513003039.59F631F664@shiva.arnolds.bogus>
Message-ID: <LNBBLJKPBEHFEDALKOLCEEOBKBAA.tim.one@home.com>

[Stephen L Arnold]
> I'm just starting with Python, so I'd also like to know how this
> works too.  Sorry it's kinda long, but I inserted some example code
> from a binary search tree.  I'd like to know (in general) how this
> kind of thing works in Python.  The syntax of the code below is
> very readable (though a bit more verbose than Python).  Comments
> are preceded by two dashes.
>
> Whether you want to think in terms of objects and methods or
> generic packages and generic formal parameters (it least that's the
> way I understand it) there must be some way to define the set of
> valid operations, arguments, etc.  In Ada, this is defined in the
> package specification.  You don't need (or want) to know how the
> code in the package body is implemented, unless of course, you're
> the one doing the implementing (it just needs to conform to the
> spec).

In Python this is a matter of convention and documentation:  there are no
formal means for defining interfaces or protocols.  For example, if a name in
a module begins with an underscore, by convention it's private to the module
and you should leave it alone -- unless you want to live dangerously, in
which case Python isn't going to stop you.  Guido likens Python's notion of
protection to bicycle locks in Amsterdam:  they're advisory <wink>.

>    Overflow     :  exception;  -- Raised when tree space runs out.

Python always raises MemoryError when it runs out of memory, so nobody ever
documents that.  OverflowError is reserved for numeric operations whose
results "don't fit" in the target numeric type.

>    Key_Error    :  exception;  -- Raised for bogus key operations.
>    State_Error  :  exception;  -- Raised for more than one concurrent
>                                -- traversal, or state change during
>                                -- a traversal.

You can define all the exception classes you like.  Note that here you can
only explain them via comments; in Python you can also give classes
"docstrings" (ditto for functions and methods), and introspective tools can
obtain docstrings at runtime.

Without explanation, I'll just present a Python BST class; say this is in
file BST.py:

# BSTs use _Nodes under the covers.
class _Node:
    def __init__(self, value, left=None, right=None):
        self.value = value
        self.left = left
        self.right = right

class BST:
    """Binary Search Tree."""

    def __init__(self):
        self.root = _Node(None)

    # private helper
    # Search for value.
    # If found, return (1, p) where p.value == value.
    # Else return (0, p), where p is the last non-null node examined,
    # i.e. the node under which value should be inserted.
    def __find(self, value):
        p = self.root
        while p is not None: a
            parent = p
            c = cmp(value, p.value)
            if c < 0:
                p = p.left
            elif c > 0:
                p = p.right
            else:
                return 1, p
        return 0, parent

    def contains(self, value):
        "Return true if value in the tree, else false."
        found, p = self.__find(value)
        return found

    def insert(self, value):
        """Insert value into the tree.

        Raise KeyError if value is already in the tree.
        """

        found, p = self.__find(value)
        if found:
            raise KeyError("value %r aleady in tree" % value)
        new = _Node(value)
        if value < p.value:
            p.left = new
        else:
            p.right = new

    def traverse(self, visitor):
        """Do an in-order traversal of the tree.

        visitor is a one-argument function, called with each value
        as it's reached.
        """

        self.__inorder(self.root.left, visitor)
        self.__inorder(self.root.right, visitor)

    def __inorder(self, p, visitor):
        if p is not None:
            self.__inorder(p.left, visitor)
            visitor(p.value)
            self.__inorder(p.right, visitor)

That's a complete implementation, covering membership testing, insertion, and
inorder traversal using a visitor pattern.  Now let's say this is file
test.py:

import random
from BST import BST

t = BST()
for i in range(50):
    element = random.randrange(100)
    try:
        t.insert(element)
    except KeyError, msg:
        print "Oops!", msg

def printone(value):
    print value,
t.traverse(printone)
print

Running that will produce different results each time due to the use of the
"random" module; here's what a typical run prints:

Oops! value 24 aleady in tree
Oops! value 15 aleady in tree
Oops! value 91 aleady in tree
Oops! value 34 aleady in tree
Oops! value 30 aleady in tree
Oops! value 48 aleady in tree
Oops! value 25 aleady in tree
Oops! value 75 aleady in tree
1 5 6 9 15 16 17 21 22 24 25 27 29 30 32 34 36 41 42 43 47 48
 49 52 55 56 57 61 62 65 72 73 74 75 79 82 83 86 89 91 92 99

> I hope that's enough to give a fairly clear picture of what's going
> on (and isn't too confusing).

Not at all!  Ada is quite readable indeed.

> ...
> How does this kind of thing work in Python?  I guess you would
> define a binary_search_tree class, with methods like insert,
> delete, etc,

Bingo.

> exceptions,

Yes.  Here's an exception class:

class YourException(Exception):
    pass

The "(Execption)" business says YourException is a subclass of the builtin
Exception class, so inherits all the latter's behaviors.  "pass" is a
do-nothing placeholder, and in this context just means I don't want to
modify, add to, or override any of the normal Exception behavior.

> what parameters can be passed to the methods,

That's usually left to docstrings.  Various tools can be used to
auto-generate class docs from those (for example, pydoc in 2.1 does a nice
job of generating HTML docs from a module's docstrings).

> any overloaded operators, etc.  You would also have to specify
> (perhaps when you instantiate a tree object) what types are
> contained in the tree.

This is going to be hard for you to get used to:  Python couldn't care less.
I happened to build a BST with integer values above, but exactly the same
code works fine for BSTs with string values, or floating-point values, or
tuples, or arbitrary mixtures of floats, ints and strings, plus anything else
whatsoever Python knows how to compare; e.g., as an extreme example, the code
above works fine for a BST with function or class values (although
comparisons of those kinds of values return more-than-less meaningless
results!).

Types aren't very important in Python.  Rather than ask what type an object
is, you're far more often interested in "which methods it responds to".  For
example, many places in the standard Python library are documented as
accepting "a file" argument.  But, in practice, you can usually pass them any
object whatsoever that has a method named "write" or "read".  Until you get
comfortable enough with that to delight in exploiting it, you may be using
Python syntax but you'll still be coding in Ada <wink>.  You can, if you
like, document that values passed to a BST must enjoy a consistent total
ordering -- but everyone knows that already anyway <wink>.

> As a user of the tree class library, how do I find out what
> methods/parameters are valid, what the exception names are, etc?

Read the docs and the docstrings.  Even without a fancy doc auto-generation
tool, you do this "by hand" from an interactive command prompt:

>>> from BST import BST
>>> dir(BST)
['_BST__find', '_BST__inorder', '__doc__', '__init__', '__module__',
'contains', 'insert', 'traverse']
>>> print BST.contains.__doc__
Return true if value in the tree, else false.
>>>

Now I spent no more than 10 minutes writing the whole BST module, and I
certainly could have done a better job on the docs.  But because Python was
*designed* to be introspective, you can still find out a lot just by using
the builtin dir() function and trying to print docstrings for the things
dir() reveals.  The doc generation tools (like pydoc) are much more
convenient when modules get large and complicated, though.

brevity-is-a-virtue-ly y'rs  - tim



From dyoo@hkn.eecs.berkeley.edu  Sun May 13 11:05:01 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sun, 13 May 2001 03:05:01 -0700 (PDT)
Subject: [Tutor] Embedding Python in C
In-Reply-To: <386D4819.4635FB1B@t-online.de>
Message-ID: <Pine.LNX.4.21.0105130258390.21961-100000@hkn.eecs.berkeley.edu>

On Sat, 1 Jan 2000, KonradRawlik wrote:

> I have the following problem and hope that somebody can help me with it.
> 
> I was trying to run simple statement strings from a C programm, by
> PyRun_SimpleString() . But it wouldn't even compile cause I got the link
> error
> ' cannot open file "python21_d.lib" '. Now the problem is, there is no
> such lib with the Python 2.1 pack I downloaded, so why isn't it there
> and where can I get it, or am I making something completly wrong? I'm
> using MSVC 6.0.

I sounds like it's looking for the debug version of the Python library.  
However, instead of getting the debug library, you might want to turn off
MSCV's debug mode off altogether: from what I've heard, it's not useful at
all when writing Python extensions.

The Python web site has the following written about it:  
"Python-2.1-Debug.zip is a set of DLLs for Windows developers compiled in
debug mode; it contains nothing of value for regular Python users."


Still, if you need it, you can download it here:

    http://python.org/ftp/python/2.1/Python-2.1-Debug.zip



From sarnold@earthling.net  Sun May 13 19:32:12 2001
From: sarnold@earthling.net (Stephen L Arnold)
Date: Sun, 13 May 2001 11:32:12 -0700
Subject: [Tutor] =?ISO-8859-1?Q?Re:_[Tutor]_RE:_[Tutor]_Re:_One_other_thing=B7..._=28and_more=29?=
In-Reply-To: <LNBBLJKPBEHFEDALKOLCEEOBKBAA.tim.one@home.com>
References: <20010513003039.59F631F664@shiva.arnolds.bogus>
Message-ID: <20010513183213.191881F664@shiva.arnolds.bogus>

On 13 May 01, at 4:18, Tim Peters wrote:

> In Python this is a matter of convention and documentation: 
[snip]

Cool; nice answer.  I think you answered some of the original 
poster's questions as well.  I'm sure I'll have more questions as I 
work through the Alan Gauld book and the tutorials.  I just have to 
finish some grading, make and give the final, and turn in my 
grades...  I even have a nice film for the last day of class this 
week :)

Thanks, Steve

*************************************************************
Steve Arnold                          sarnold@arnolds.dhs.org
Assoc. Faculty, Dept of Geography, Allan Hancock College
           http://arnolds.dhs.org/geography.html

Linux:  It's not just for nerds anymore...


From walterv@jps.net  Sun May 13 22:07:29 2001
From: walterv@jps.net (Walter Vannini)
Date: Sun, 13 May 2001 14:07:29 -0700
Subject: [Tutor] Embedding Python in C
References: <Pine.LNX.4.21.0105130258390.21961-100000@hkn.eecs.berkeley.edu>
Message-ID: <3AFEF791.708B662C@jps.net>

I ran into the same problem with python 2.0.
I didn't want to turn off debug mode, so instead I modified config.h.
(and of course kept a backup of the original).
Line 432 was changed from:
#pragma comment(lib,"python20_d.lib")
to
#pragma comment(lib,"python20.lib")

I would expect that a similar fix will work for 2.1.

The lines near 432 were
431 #ifdef _DEBUG
432 #pragma comment(lib,"python20_d.lib")
433 #else
434 #pragma comment(lib,"python20.lib")
435 #endif

Incidentally, instead of hardcoding the linking of the python library
in source code via Microsoft pragmas, one could simply link explicitly.
In that case, lines 431 to 435 of config.h should be commented out.

Walter.

Daniel Yoo wrote:
> 
> On Sat, 1 Jan 2000, KonradRawlik wrote:
> 
> > I have the following problem and hope that somebody can help me with it.
> >
> > I was trying to run simple statement strings from a C programm, by
> > PyRun_SimpleString() . But it wouldn't even compile cause I got the link
> > error
> > ' cannot open file "python21_d.lib" '. Now the problem is, there is no
> > such lib with the Python 2.1 pack I downloaded, so why isn't it there
> > and where can I get it, or am I making something completly wrong? I'm
> > using MSVC 6.0.
> 
> I sounds like it's looking for the debug version of the Python library.
> However, instead of getting the debug library, you might want to turn off
> MSCV's debug mode off altogether: from what I've heard, it's not useful at
> all when writing Python extensions.
> 
> The Python web site has the following written about it:
> "Python-2.1-Debug.zip is a set of DLLs for Windows developers compiled in
> debug mode; it contains nothing of value for regular Python users."
> 
> Still, if you need it, you can download it here:
> 
>     http://python.org/ftp/python/2.1/Python-2.1-Debug.zip


From van@lindbergs.org  Sun May 13 23:56:34 2001
From: van@lindbergs.org (VanL)
Date: Sun, 13 May 2001 16:56:34 -0600
Subject: [Tutor] Restricting the type of passed-in objects
References: <3AFD3382.AF5626D9@chello.nl>
Message-ID: <3AFF1122.C0D7C825@lindbergs.org>

Roeland Rengelink wrote:

So, how do you go about designing your Tree interface?

>
> It depends on what you're going to use the tree for.
>
> I can think of several different answers.
>
> o The tree is going to be the underlying data structure for a
>   sequence.  For example, an AVL-tree to implement a sorted list
>
> o The tree is going to be the underlying data structure for a
>   mapping. To make a UserDict with sorted keys for instance.
>
> In these cases the interface to your tree is pretty much determined
> by the interface to your sequence or mapping respectively.
>
> Another possibility is that you want to be able to inherit
> a particular class from a tree. For example:
>
> class FileSystem(Tree):
>     pass
>
> In this case the fact that the object is a tree seems central to the use
> of the object (while in the previous cases, it was an implementation
> detail).
>

Here is how I came to this project:

I was thinking about writing a faq generator and maintainer for my work.  While
thinking about the problem, it occurred to me that a faq could be easily
represented by a tree of faqEntry objects.  Then I could also build into each
entry the knowledge of how to render itself in various formats (html, text,
whatever).  Then I could just call faq.render() on the root of the tree and it
would recursively call itself to render the whole thing, including all the numbers

and hyperlinks (because the relationships would be defined by each entry's
position in the tree).

After I started to work on that problem (and being a data structures junkie -- I
just think they are cool) it seemed to me that it would be much better to write a
general tree class and inherit from it.  Then, I started to think how I could make

that tree class be as general as possible, so that I could use it in the future to

represent different types of trees.

And thus we are here.  If my faq-o-matic works like I hope, I think it would be a
pretty cool little hack -- It would be the first thing I would consider neat
enough to submit to Useless Python.

Van



From alan.gauld@freenet.co.uk  Mon May 14 00:53:35 2001
From: alan.gauld@freenet.co.uk (Alan Gauld)
Date: Sun, 13 May 2001 23:53:35 +0000
Subject: [Tutor] Linux help required
Message-ID: <3.0.1.32.20010513235335.0125a98c@mail.freenet.co.uk>

Hi gang,

I've just been contacted by a user of my web tutor complaining 
that the zip file can't be opened by gunzip under Linux. I have 
now used cygwin(*) to create a tgz file and would like a volunteer 
with Linux to test it for me. 

Any takers?

Alan g

(*)My Linux box is in the midst of being rebuilt as an ADSL 
 firewall/router at the moment...




From dsh8290@rit.edu  Mon May 14 00:10:36 2001
From: dsh8290@rit.edu (D-Man)
Date: Sun, 13 May 2001 19:10:36 -0400
Subject: [Tutor] Linux help required
In-Reply-To: <3.0.1.32.20010513235335.0125a98c@mail.freenet.co.uk>; from alan.gauld@freenet.co.uk on Sun, May 13, 2001 at 11:53:35PM +0000
References: <3.0.1.32.20010513235335.0125a98c@mail.freenet.co.uk>
Message-ID: <20010513191036.A6855@harmony.cs.rit.edu>

On Sun, May 13, 2001 at 11:53:35PM +0000, Alan Gauld wrote:
| I've just been contacted by a user of my web tutor complaining 
| that the zip file can't be opened by gunzip under Linux. I have 

That is expected -- zip and gzip are two different compression
formats.

Also, I think tar/gzip check the extension of the file they are run
on.  I have generally found the .tar.gz extension to work better than
the .tgz extension.

| now used cygwin(*) to create a tgz file and would like a volunteer 
| with Linux to test it for me. 

Did you use gzip or zip?  If you used gzip it should be just fine.  I
use cygwin all the time at work (I couldn't work without it).

Also, linux has "zip" and "unzip" commands for handling zip archives.

| Any takers?

I am willing to test it.  Where is the file?

I referred a friend to your tutorial recently and it would be really
helpful to him if he could download a copy and browse it while
offline.  I didn't notice a downloadable version from a quick glance.
Is this the file you are asking about?  If not I think it would be
great if you could provide a tarball/zip archive of your tutorial.

-D


PS. BTW I am back from my trip now :-).  Time and sever space
    permitting I hope to have pictures available on the web in the
    next several weeks.


From kalle@gnupung.net  Mon May 14 00:20:55 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Mon, 14 May 2001 01:20:55 +0200
Subject: [Tutor] Linux help required
In-Reply-To: <20010513191036.A6855@harmony.cs.rit.edu>; from dsh8290@rit.edu on Sun, May 13, 2001 at 07:10:36PM -0400
References: <3.0.1.32.20010513235335.0125a98c@mail.freenet.co.uk> <20010513191036.A6855@harmony.cs.rit.edu>
Message-ID: <20010514012055.B653@apone.network.loc>

Sez D-Man:
> On Sun, May 13, 2001 at 11:53:35PM +0000, Alan Gauld wrote:
[tar/gzip version of tutorial]
> Also, linux has "zip" and "unzip" commands for handling zip archives.

Yes, but unzip is in non-free in debian and thus unavailable to me and all
other fanatics.  I believe the reason is some patent problem, but I'm not
sure.  Why unzip is non-free and zip is free beats me, but it is annoying.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From scarblac@pino.selwerd.nl  Mon May 14 00:37:26 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 01:37:26 +0200
Subject: [Tutor] Restricting the type of passed-in objects
In-Reply-To: <3AFF1122.C0D7C825@lindbergs.org>; from van@lindbergs.org on Sun, May 13, 2001 at 04:56:34PM -0600
References: <3AFD3382.AF5626D9@chello.nl> <3AFF1122.C0D7C825@lindbergs.org>
Message-ID: <20010514013726.A1048@pino.selwerd.nl>

On  0, VanL <van@lindbergs.org> wrote:
> Here is how I came to this project:
> 
> I was thinking about writing a faq generator and maintainer for my work.  While
> thinking about the problem, it occurred to me that a faq could be easily
> represented by a tree of faqEntry objects. 

Wait wait wait - *why* did this occur to you? Is the FAQ itself a hierarchy?

> Then I could also build into each
> entry the knowledge of how to render itself in various formats (html, text,
> whatever).

That's totally independent of the structure being a tree, a hash table, or
whatever. And you might want to have, instead, a HTMLRenderer object or so
that takes the text version of the FAQ. That seems more logical to me, or at
least also worth considering.

> Then I could just call faq.render() on the root of the tree and it
> would recursively call itself to render the whole thing, including all the numbers

Again, that would work for other structures as well, right?

> and hyperlinks (because the relationships would be defined by each entry's
> position in the tree).

Hmmmmm. I think hyperlinks between documents are a lot more complicated than
that. Are you sure you only link between siblings, and between parent/child
pairs?

> After I started to work on that problem (and being a data structures junkie -- I
> just think they are cool) it seemed to me that it would be much better to write a
> general tree class and inherit from it.  Then, I started to think how I could make
> 
> that tree class be as general as possible, so that I could use it in the future to
> 
> represent different types of trees.
> 
> And thus we are here.  If my faq-o-matic works like I hope, I think it would be a
> pretty cool little hack -- It would be the first thing I would consider neat
> enough to submit to Useless Python.

There's no neatness requirement for Useless Python - if you have something
you made and that actually works, it's neat enough.

I don't think a tree is all that natural for a FAQ. I'd go for a dictionary
- each FAQ entry has its own keyword or title, and that's the dictionary
key. Hyperlinks are trivial (they point to another keyword). This goes along
with the first rule of data structures in Python - "Use a dictionary".
Alternatively you might want a list, or some object wrapping either of the
two.

But what's so tree-like about FAQs? They're organized into chapters, but
besides that they're mostly a list of questions...

-- 
Remco Gerlich


From arcege@speakeasy.net  Mon May 14 00:47:28 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Sun, 13 May 2001 19:47:28 -0400 (EDT)
Subject: [Tutor] Linux help required
In-Reply-To: <20010514012055.B653@apone.network.loc> from "Kalle Svensson" at May 14, 2001 01:20:55 AM
Message-ID: <200105132347.f4DNlSI09436@dsl092-074-184.bos1.dsl.speakeasy.net>

Kalle Svensson wrote
> 
> Sez D-Man:
> > On Sun, May 13, 2001 at 11:53:35PM +0000, Alan Gauld wrote:
> [tar/gzip version of tutorial]
> > Also, linux has "zip" and "unzip" commands for handling zip archives.
> 
> Yes, but unzip is in non-free in debian and thus unavailable to me and all
> other fanatics.  I believe the reason is some patent problem, but I'm not
> sure.  Why unzip is non-free and zip is free beats me, but it is annoying.

You can get a free, compatible (to PKZIP*) copy from Info-Zip, both the
compression and decompression utilities (which are separate).

<URL: http://www.info-zip.org/pub/infozip/>

  -Arcege

* Considering that technically, PKZIP and WinZIP are shareware, and
that Info-ZIP is free...  And runs on more platforms (including VMS,
CMS, WinCE, Mac).

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From kalle@gnupung.net  Mon May 14 00:57:44 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Mon, 14 May 2001 01:57:44 +0200
Subject: [Tutor] Linux help required
In-Reply-To: <200105132347.f4DNlSI09436@dsl092-074-184.bos1.dsl.speakeasy.net>; from arcege@dsl092-074-184.bos1.dsl.speakeasy.net on Sun, May 13, 2001 at 07:47:28PM -0400
References: <20010514012055.B653@apone.network.loc> <200105132347.f4DNlSI09436@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <20010514015744.B28928@father>

Sez Michael P. Reilly:
> Kalle Svensson wrote
> > 
> > Sez D-Man:
> > > On Sun, May 13, 2001 at 11:53:35PM +0000, Alan Gauld wrote:
> > [tar/gzip version of tutorial]
> > > Also, linux has "zip" and "unzip" commands for handling zip archives.
> > 
> > Yes, but unzip is in non-free in debian and thus unavailable to me and all
> > other fanatics.  I believe the reason is some patent problem, but I'm not
> > sure.  Why unzip is non-free and zip is free beats me, but it is annoying.
> 
> You can get a free, compatible (to PKZIP*) copy from Info-Zip, both the
> compression and decompression utilities (which are separate).

I was referring to free as in freedom.  I'm one of those hippie communist
hacker guys. <wink>

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From scarblac@pino.selwerd.nl  Mon May 14 00:59:58 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 01:59:58 +0200
Subject: [Tutor] Linux help required
In-Reply-To: <20010514015744.B28928@father>; from kalle@gnupung.net on Mon, May 14, 2001 at 01:57:44AM +0200
References: <20010514012055.B653@apone.network.loc> <200105132347.f4DNlSI09436@dsl092-074-184.bos1.dsl.speakeasy.net> <20010514015744.B28928@father>
Message-ID: <20010514015957.A1132@pino.selwerd.nl>

On  0, Kalle Svensson <kalle@gnupung.net> wrote:
> I was referring to free as in freedom.  I'm one of those hippie communist
> hacker guys. <wink>

You're not the only one. I run a linux-from-scratch box, *almost* everything
compiled by hand (including the C compiler I built the C compiler with).

It's *my* hobby, I waste my time on what I want :).

-- 
Remco Gerlich


From gibbs05@flash.net  Mon May 14 01:38:29 2001
From: gibbs05@flash.net (Harry Kattz)
Date: Sun, 13 May 2001 19:38:29 -0500
Subject: [Tutor] Linux help required
References: <20010514012055.B653@apone.network.loc> <200105132347.f4DNlSI09436@dsl092-074-184.bos1.dsl.speakeasy.net> <20010514015744.B28928@father>
Message-ID: <002c01c0dc0e$3de75ec0$c9f763d8@gibbs05>

Isn't the zipfile module in Python free?  Couldn't you sidestep the issue by
writing your own 'unzip' utility in Python?

Sam


----- Original Message -----
From: "Kalle Svensson" <kalle@gnupung.net>
To: <tutor@python.org>
Sent: Sunday, May 13, 2001 6:57 PM
Subject: Re: [Tutor] Linux help required


> Sez Michael P. Reilly:
> > Kalle Svensson wrote
> > >
> > > Sez D-Man:
> > > > On Sun, May 13, 2001 at 11:53:35PM +0000, Alan Gauld wrote:
> > > [tar/gzip version of tutorial]
> > > > Also, linux has "zip" and "unzip" commands for handling zip
archives.
> > >
> > > Yes, but unzip is in non-free in debian and thus unavailable to me and
all
> > > other fanatics.  I believe the reason is some patent problem, but I'm
not
> > > sure.  Why unzip is non-free and zip is free beats me, but it is
annoying.
> >
> > You can get a free, compatible (to PKZIP*) copy from Info-Zip, both the
> > compression and decompression utilities (which are separate).
>
> I was referring to free as in freedom.  I'm one of those hippie communist
> hacker guys. <wink>
>
> Peace,
>   Kalle
> --
> Email: kalle@gnupung.net     | You can tune a filesystem, but you
> Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
> PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
>  [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From sheila@thinkspot.net  Mon May 14 02:35:36 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 13 May 2001 18:35:36 -0700
Subject: [Tutor] Re: [Edu-sig] IDLE and VPython
In-Reply-To: <14.140ccb5e.282f65cf@aol.com>
References: <14.140ccb5e.282f65cf@aol.com>
Message-ID: <1A7D5505B58@kserver.org>

On Sun, 13 May 2001 00:21:35 EDT, Arthinator@aol.com  wrote about [Edu-sig] IDLE
and VPython:

:Noting Sheila's problem discussed on the Python list and here re: VPython
:installation breaking stuff for her;

Yes, I'm going to show it to my students on Monday. If any are interested, I
will install it for them, but I don't relish having to re-install the Python 2.0
IDLE again, afterwards.


:Finally, not understanding what of significance running in its own Process
:Space brings to the table for standard IDLE, and certainly feeling that other
:than that single issue the VPython forked IDLE adds nothing essential to 
:VPython's use for educational purposes.

When I run a script using Tkinter or VPython in IDLE 0.6, and then exit the
script, my IDLE session ends also. This doesn't happen with the version of IDLE
that comes with VPython. Also, rather than having the output of my script come
up in the interactive shell, VPython's IDLE sends the output to a separate
window.

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



From sheila@thinkspot.net  Mon May 14 02:39:18 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 13 May 2001 18:39:18 -0700
Subject: [Tutor] Re: [Edu-sig] IDLE and VPython
In-Reply-To: <1A7D5505B58@kserver.org>
References: <14.140ccb5e.282f65cf@aol.com> <1A7D5505B58@kserver.org>
Message-ID: <1AB344F2FC7@kserver.org>

Oops. I goofed. Sent that one to the wrong list!

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



From virketis@fas.harvard.edu  Mon May 14 02:50:39 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Sun, 13 May 2001 21:50:39 -0400
Subject: [Tutor] checking for a condition across a list
In-Reply-To: <E14yyJB-0002zv-00@mail.python.org>
Message-ID: <200105140145.VAA21009@smtp2.fas.harvard.edu>

Hi,

I know I posted this question already, but the list has been very busy, so
I hope it's not too obnoxious if I bring it up again ... Hopefully, there
is an obvious way I am missing. Here goes. Let's say I have a list: 

>>>myList = [1, 0, 1, 0, 0, 1, 1] 

How can I check for some condition across all the members of a list
simultaneously? In other words, how do I this say  more neatly: 

>>> if myList[0] == myList[1] == ... == myList[6] == 1: print "They're all
ones!" 

Thank you! 

Pijus
----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis.


From tutor@python.org  Mon May 14 03:24:50 2001
From: tutor@python.org (Tim Peters)
Date: Sun, 13 May 2001 22:24:50 -0400
Subject: [Tutor] checking for a condition across a list
In-Reply-To: <200105140145.VAA21009@smtp2.fas.harvard.edu>
Message-ID: <LNBBLJKPBEHFEDALKOLCEEPNKBAA.tim.one@home.com>

[Pijus Virketis]
> ...
> Let's say I have a list:
>
> >>>myList = [1, 0, 1, 0, 0, 1, 1]
>
> How can I check for some condition across all the members of a list
> simultaneously? In other words, how do I this say  more neatly:
>
> >>> if myList[0] == myList[1] == ... == myList[6] == 1:
> ...     print "They're all ones!"

The simple and obvious way is just to write a reusable function:

def alltrue(x, pred):
    "Return true iff pred(y) is true for all y in x."
    for y in x:
        if not pred(y):
            return 0
    return 1

Then, e.g.,

>>> def isone(x):
...     return x == 1
...
>>> alltrue(isone, [1,1,1,1])
1
>>> alltrue(isone, [1,1,0,1])
0
>>>

Of course there are *silly* ways to do it too, but you'll be better off
pretending I didn't show these <wink>:

>>> map(lambda x: x == 1, [1,1,1,1]) == [1]*len([1,1,1,1])
1
>>> map(lambda x: x == 1, [1,1,0,1]) == [1]*len([1,1,0,1])
0
>>> reduce(lambda x, y: x and y==1, [1,1,1,1], 1)
1
>>> reduce(lambda x, y: x and y==1, [1,1,0,1], 1)
0
>>> len(filter(lambda x: x==1, [1,1,1,1])) == len([1,1,1,1])
1
>>> len(filter(lambda x: x==1, [1,1,0,1])) == len([1,1,0,1])
0
>>>



From walterv@jps.net  Mon May 14 04:20:22 2001
From: walterv@jps.net (Walter Vannini)
Date: Sun, 13 May 2001 20:20:22 -0700
Subject: [Tutor] checking for a condition across a list
References: <200105140145.VAA21009@smtp2.fas.harvard.edu>
Message-ID: <3AFF4EF6.56C4451B@jps.net>

Let the original code be:

myList = [1, 0, 1, 0, 0, 1, 1]
#if myList[0] == myList[1] == ... == myList[6] == 1:
if myList[0] == myList[1] == myList[2] == myList[3] == myList[4] == \
        myList[5] == myList[6] == 1:
    print "They're all ones!"
else:
    print "They're not all ones!"

One possible replacement is:

myList = [1, 0, 1, 0, 0, 1, 1]
if reduce(lambda x,y: x and y, map(lambda x: x==1, myList) ):
    print "They're all ones!"
else:
    print "They're not all ones!"

or, as a minor variation:

myList = [1, 0, 1, 0, 0, 1, 1]
def theCondition(x):
    return x==1
if reduce(lambda x,y: x and y, map(theCondition, myList) ):
    print "They're all ones!"
else:
    print "They're not all ones!"

These are not as efficient as the original,
since there is no short circuiting.
If you want that, a loop with a break is the only thing
I can think of.

Walter

Pijus Virketis wrote:
> 
> Hi,
> 
> I know I posted this question already, but the list has been very busy, so
> I hope it's not too obnoxious if I bring it up again ... Hopefully, there
> is an obvious way I am missing. Here goes. Let's say I have a list:
> 
> >>>myList = [1, 0, 1, 0, 0, 1, 1]
> 
> How can I check for some condition across all the members of a list
> simultaneously? In other words, how do I this say  more neatly:
> 
> >>> if myList[0] == myList[1] == ... == myList[6] == 1: print "They're all
> ones!"
> 
> Thank you!
> 
> Pijus
> ----------------------------------------------------------------------------
> -------------------
> Please have a look at my weblog at www.fas.harvard.edu/~virketis.


From deirdre@deirdre.net  Mon May 14 04:21:38 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Sun, 13 May 2001 20:21:38 -0700
Subject: [Tutor] Linux help required
In-Reply-To: <3.0.1.32.20010513235335.0125a98c@mail.freenet.co.uk>
References: <3.0.1.32.20010513235335.0125a98c@mail.freenet.co.uk>
Message-ID: <a05100e06b724ff281010@[10.0.1.21]>

>I've just been contacted by a user of my web tutor complaining
>that the zip file can't be opened by gunzip under Linux. I have
>now used cygwin(*) to create a tgz file and would like a volunteer
>with Linux to test it for me.

zip files should be opened with unzip, not gunzip. This is "works as 
designed" and anyone confused needs to read the man pages. :)

Gunzip can create and extract single-file zip archives, but they 
aren't compatible with the typical zip archives that contain multiple 
files.

Basically, tar is the archiver of choice for Unix and Compress or 
gzip is the compressor. On Windows, *both* are done with zip 
utilities.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From deirdre@deirdre.net  Mon May 14 04:32:09 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Sun, 13 May 2001 20:32:09 -0700
Subject: [Tutor] Linux help required
In-Reply-To: <20010514015957.A1132@pino.selwerd.nl>
References: <20010514012055.B653@apone.network.loc>
 <200105132347.f4DNlSI09436@dsl092-074-184.bos1.dsl.speakeasy.net>
 <20010514015744.B28928@father> <20010514015957.A1132@pino.selwerd.nl>
Message-ID: <a05100e08b72501f0b6df@[10.0.1.21]>

>On  0, Kalle Svensson <kalle@gnupung.net> wrote:
>>  I was referring to free as in freedom.  I'm one of those hippie communist
>>  hacker guys. <wink>
>
>You're not the only one. I run a linux-from-scratch box, *almost* everything
>compiled by hand (including the C compiler I built the C compiler with).
>
>It's *my* hobby, I waste my time on what I want :).

Hey, I'm one of those hippie communist hacker chix, but I still 
prefer Eudora for email. I run it on a free (as in freedom, but not 
as in beer) OS, but the Linux boxen's in the other room.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From sheila@thinkspot.net  Mon May 14 05:37:04 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 13 May 2001 21:37:04 -0700
Subject: [Tutor] Timing a loop: How to interrupt ?
Message-ID: <24E02396B97@kserver.org>

I'm writing a portion of a Boggle game for my students who are learning Python
right now. I'm going to let them extend it and finish it up. Right now, it just
rolls up the 16 dice and places them randomly in the tray, displays the tray and
lets you type in words that you see, until the time is over two minutes.

[There is currently no dictionary checking, no scoring, etc... I'm leaving that
for the students.]

I've included my script below.

The problem is this:

When the board is initialized, and just before it is displayed, the timer
starts. Then the board is displayed. I have a while loop, that checks whether
the time is over two minutes. If it is not, it asks for the player to enter a
word. After a word is entered, the time is checked. If time is still under two
minutes, it enters the loop again, and waits for the user to input a word.

The problem is, if the time is at 1:58 and goes into the loop, the player may
not enter another word until quite a bit after two minutes is up. So the game
doesn't strictly enforce the two minute limit.

Is there an easy way for me to check for the time, without letting the game go
over two minutes?

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



From sheila@thinkspot.net  Mon May 14 05:46:46 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 13 May 2001 21:46:46 -0700
Subject: [Tutor] Re: Timing a loop: How to interrupt ?
Message-ID: <256C44642CE@kserver.org>

On Sun, 13 May 2001 21:37:04 -0700, Sheila King <sheila@thinkspot.net>  wrote
about Timing a loop: How to interrupt ?:

:I'm writing a portion of a Boggle game for my students who are learning Python
:right now. I'm going to let them extend it and finish it up. Right now, it just
:rolls up the 16 dice and places them randomly in the tray, displays the tray and
:lets you type in words that you see, until the time is over two minutes.
:
:[There is currently no dictionary checking, no scoring, etc... I'm leaving that
:for the students.]
:
:I've included my script below.

Oh, uh, I forgot to include the code. Duh.

See below.

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

# So far, this game rolls the sixteen dice, and places them in
# random locations in the game board, and displays the game board.
# it times for two minutes of display, and then prints "GAME OVER"

import time
import random

diceList = [ ('A', 'A', 'C', 'O', 'T', 'I'), \
            ('M', 'A', 'S', 'O', 'H', 'R'), \
            ('Y', 'H', 'I', 'F', 'E', 'E'), \
            ('V', 'A', 'N', 'D', 'E', 'Z'), \
            ('A', 'Y', 'B', 'T', 'L', 'I'), \
            ('B', 'I', 'R', 'O', 'F', 'X'), \
            ('A', 'P', 'D', 'C', 'M', 'E'), \
            ('P', 'I', 'S', 'E', 'H', 'N'), \
            ('R', 'U', 'W', 'I', 'L', 'G'), \
            ('U', 'K', 'G', 'E', 'L', 'Y'), \
            ('I', 'V', 'G', 'N', 'T', 'E'), \
            ('D', 'E', 'W', 'O', 'N', 'S'), \
            ('C', 'L', 'A', 'R', 'E', 'S'), \
            ('L', 'E', 'T', 'S', 'U', 'P'), \
            ('J', 'O', 'M', 'A', 'B', 'QU'), \
            ('D', 'T', 'O', 'K', 'N', 'U')]

class BoggleGame:

    def __init__(self):
        self.board = {}
        diceCount = 0
        for row in range(1,5):
            for col in range(1,5):
                self.board[(row,col)]= None
        for loc in range(0, 16):
            while (1):
                row = random.randrange(1, 5)
                col = random.randrange(1, 5)
                if self.board[(row, col)] == None:
                    break
            letter = random.choice(diceList[loc])
            self.board[(row, col)] = letter

    def chooseRandomLoc(self):
        rows = (1, 2, 3, 4)
        return (random.choice(rows), random.choice(rows))

    def displayBoard(self):
        print # start board display on a newline
        for row in range(1,5):
            for col in range(1,5):
                print self.board[(row,col)], " ",  # extra ending comma
                                                   # prevents newline
            print # empty line print

if __name__ == '__main__':
    testGame = BoggleGame()
    submittedwordlist = []
    print "The two minute time begins NOW!\n"
    starttime = time.clock()
    testGame.displayBoard()
    while (time.clock() - starttime < 2* 60):
        submittedwordlist.append(raw_input("Enter words:\n"))
    print
    print "Time's Up."
    print "Here are the words you entered:\n"
    for word in submittedwordlist:
        print word




From ppathiyi@cisco.com  Mon May 14 06:22:09 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Mon, 14 May 2001 10:52:09 +0530
Subject: [Tutor] Clearing the screen
Message-ID: <010f01c0dc35$d3003f00$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

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

Hi,
        Is there any command in python to clear the screen ?=20
   =20
        I am printing lot of lines to the screen (stdout). If at any =
point of time, i want to clear the screen, is there any command which =
will help me do this ? [ Other than os.system('clear') ]

TIA,
Praveen.

------=_NextPart_000_010C_01C0DC63.ECA47DD0
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
Is there any=20
command in python to clear the screen ? </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; I =
am printing=20
lot of lines to the screen (stdout). If at any point of time, i want to =
clear=20
the screen, is there any command which will help me do this ? [ Other =
than=20
os.system('clear') ]</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV></BODY></HTML>

------=_NextPart_000_010C_01C0DC63.ECA47DD0--



From sheila@thinkspot.net  Mon May 14 06:25:38 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 13 May 2001 22:25:38 -0700
Subject: [Tutor] Timing a loop: How to interrupt ?
In-Reply-To: <24E02396B97@kserver.org>
References: <24E02396B97@kserver.org>
Message-ID: <27A64E62122@kserver.org>

On Sun, 13 May 2001 21:37:04 -0700, Sheila King <sheila@thinkspot.net>  wrote
about [Tutor] Timing a loop: How to interrupt ?:

:The problem is, if the time is at 1:58 and goes into the loop, the player may
:not enter another word until quite a bit after two minutes is up. So the game
:doesn't strictly enforce the two minute limit.
:
:Is there an easy way for me to check for the time, without letting the game go
:over two minutes?

I think I see what I need to do...I'm looking at the signal module. I should've
found that on my own before posting here. I think I can work this out on my own.

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



From sheila@thinkspot.net  Mon May 14 06:47:21 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 13 May 2001 22:47:21 -0700
Subject: [Tutor] Help with signals, please?
Message-ID: <28E3B4E2753@kserver.org>

OK, I'm not sure why this isn't working. I've copied exactly from the example in
the 2.0 documentation, here:
http://www.python.org/doc/2.0/lib/Signal_Example.html

At the top of my script I have:

import signal

then, before the main script, I have:

def timesUp(signum, frame):
    print
    print "Time's Up!"


And then, inside the main program, I have:

   signal.signal(signal.SIGALRM, timesUp)
    print "The two minute time begins NOW!\n"
    signal.alarm(2*60)
    testGame.displayBoard()
    while (1):
        submittedwordlist.append(raw_input("Enter words:\n"))
    signal.alarm(0)
 

It won't run. It gives the following error message:

Traceback (most recent call last):
  File "E:\Python\Python20\Pythonwin\pywin\framework\scriptutils.py", line 301,
in RunScript
    exec codeObject in __main__.__dict__
  File "E:\Python\Python20\testprograms\Boggle.py", line 64, in ?
    signal.signal(signal.SIGALRM, timesUp)
AttributeError: SIGALRM

There is even an example like this in Mark Lutz' _Programming Python_ on p. 124.

I'm stumped.

Just in case, I've pasted the full code below. But it was running fine, before I
tried to work with the signals.

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


# So far, this game rolls the sixteen dice, and places them in
# random locations in the game board, and displays the game board.
# it times for two minutes of display, and then prints "GAME OVER"
# suggested extensions:
#   1. Add scoring, so that the player gets a score
#   2. Using a dictionary file, check the submitted words against
#        the dictionary. Only permit words in the dictionary to
#        count. Allow the user the option to add words to the dictionary.
#   3. Have the computer check the board, finding ALL words that are
#        in the table and in the dictionary. Have the computer display
#        this list after giving the player their score. Total the
#        the computer's score, also.

import time, random, signal

diceList = [ ('A', 'A', 'C', 'O', 'T', 'I'), \
            ('M', 'A', 'S', 'O', 'H', 'R'), \
            ('Y', 'H', 'I', 'F', 'E', 'E'), \
            ('V', 'A', 'N', 'D', 'E', 'Z'), \
            ('A', 'Y', 'B', 'T', 'L', 'I'), \
            ('B', 'I', 'R', 'O', 'F', 'X'), \
            ('A', 'P', 'D', 'C', 'M', 'E'), \
            ('P', 'I', 'S', 'E', 'H', 'N'), \
            ('R', 'U', 'W', 'I', 'L', 'G'), \
            ('U', 'K', 'G', 'E', 'L', 'Y'), \
            ('I', 'V', 'G', 'N', 'T', 'E'), \
            ('D', 'E', 'W', 'O', 'N', 'S'), \
            ('C', 'L', 'A', 'R', 'E', 'S'), \
            ('L', 'E', 'T', 'S', 'U', 'P'), \
            ('J', 'O', 'M', 'A', 'B', 'QU'), \
            ('D', 'T', 'O', 'K', 'N', 'U')]

class BoggleGame:

    def __init__(self):
        self.board = {}
        for row in range(1,5):
            for col in range(1,5):
                self.board[(row,col)]= None
        for loc in range(0, 16):
            while (1):
                row = random.randrange(1, 5)
                col = random.randrange(1, 5)
                if self.board[(row, col)] == None:
                    break
            letter = random.choice(diceList[loc])
            self.board[(row, col)] = letter

    def displayBoard(self):
        print # start board display on a newline
        for row in range(1,5):
            for col in range(1,5):
                print self.board[(row,col)], " ",  # extra ending comma
                                                   # prevents newline
            print # empty line print

def timesUp(signum, frame):
    print
    print "Time's Up!"

if __name__ == '__main__':
    testGame = BoggleGame()
    submittedwordlist = []
    signal.signal(signal.SIGALRM, timesUp)
    print "The two minute time begins NOW!\n"
    signal.alarm(2*60)
    testGame.displayBoard()
    while (1):
        submittedwordlist.append(raw_input("Enter words:\n"))
    signal.alarm(0)
    print "Here are the words you entered:\n"
    for word in submittedwordlist:
        print word


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


From virketis@fas.harvard.edu  Mon May 14 06:57:15 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Mon, 14 May 2001 01:57:15 -0400
Subject: [Tutor] checking for a condition across a list
In-Reply-To: <LNBBLJKPBEHFEDALKOLCEEPNKBAA.tim.one@home.com>
References: <200105140145.VAA21009@smtp2.fas.harvard.edu>
Message-ID: <200105140552.BAA15414@smtp3.fas.harvard.edu>

>The simple and obvious way is just to write a reusable function:
>
>def alltrue(x, pred):
>    "Return true iff pred(y) is true for all y in x."
>    for y in x:
>        if not pred(y):
>            return 0
>    return 1
>
>Then, e.g.,
>
>>>> def isone(x):
>...     return x == 1
>...
>>>> alltrue(isone, [1,1,1,1])
>1

Thanks so much! Just one small note: the way you've written the function,
the usage should be:
>>> alltrue([1,1,1,1], isone) <-- inputs the other way around...

Oh, and one more thing. I've never before encountered the "return x ==1"
statement before. What exactly does it do?

Thank you again.

Pijus
----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis.


From sheila@thinkspot.net  Mon May 14 07:01:01 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 13 May 2001 23:01:01 -0700
Subject: [Tutor] checking for a condition across a list
In-Reply-To: <200105140552.BAA15414@smtp3.fas.harvard.edu>
References: <200105140145.VAA21009@smtp2.fas.harvard.edu> <LNBBLJKPBEHFEDALKOLCEEPNKBAA.tim.one@home.com> <200105140552.BAA15414@smtp3.fas.harvard.edu>
Message-ID: <29ACFF30B42@kserver.org>

On Mon, 14 May 2001 01:57:15 -0400, Pijus Virketis <virketis@fas.harvard.edu>
wrote about RE: [Tutor] checking for a condition across a list:

:Oh, and one more thing. I've never before encountered the "return x ==1"
:statement before. What exactly does it do?

x == 1

is a boolean condition. Either it is true or false.
If x is one, then the statement is true. If x is not one, then it is false.
The operator == checks if the two values are equal. If yes, then true, else
false.

It returns, therefore, a zero if false, and a one if true.

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



From sheila@thinkspot.net  Mon May 14 07:17:59 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 13 May 2001 23:17:59 -0700
Subject: [Tutor] Help with signals, please?
In-Reply-To: <28E3B4E2753@kserver.org>
References: <28E3B4E2753@kserver.org>
Message-ID: <2AA413D315E@kserver.org>

Apparently, this is one of those "platform" issues. I just uploaded the script
to my webhost, who runs a Linux server, and ran it in my Telnet account. It ran
just fine.

How can I get this effect in Windows?

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


On Mon, 14 May 2001 05:46:05 GMT, Sheila King <sheila@spamcop.net> wrote:

:It won't run. It gives the following error message:
:
:Traceback (most recent call last):
:  File "E:\Python\Python20\Pythonwin\pywin\framework\scriptutils.py", line 301,
:in RunScript
:    exec codeObject in __main__.__dict__
:  File "E:\Python\Python20\testprograms\Boggle.py", line 64, in ?
:    signal.signal(signal.SIGALRM, timesUp)
:AttributeError: SIGALRM
:
:There is even an example like this in Mark Lutz' _Programming Python_ on p. 124.
:
:I'm stumped.

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


From NHYTRO@compuserve.com  Mon May 14 07:23:21 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Mon, 14 May 2001 02:23:21 -0400
Subject: [Tutor] Values being skipped-Iteration
Message-ID: <200105140223_MC2-D0D2-2B21@compuserve.com>

Hi guys!

I=B4m retrieving values from a databse:

## code start ##
# database access for side navigation for individual editors
## ------------------------------------------------------
connection =3D odbc.odbc('minicms')
cur =3D connection.cursor()
cur.execute("select navlinks from users where username =3D'%s'"
%(usernamevalue))
alllinks =3D cur.fetchall()
cur.close()
connection.close()
###

I generate chunks of HTML depending on what I get from these values:

### code start ###
templinks =3D alllinks[0]
links =3D string.split(templinks[0],",")
for x in links[:]:
        if x =3D=3D "Home":         =

            counter =3D counter + 1
            print '<td><img src=3D"check-blank.jpg" name=3D"homestatus"><=
/td>'
            print '<td bgcolor=3D"#F7DF89">',
            print x
            print """
            &nbsp;</td>
            <td><input type=3D"button" onclick=3D"edithome(),homechecked(=
);"
value=3D"edit"</td>
            </tr>
            <tr>
            """ =

        elif x =3D=3D "Aktuelles":         =

            counter =3D counter + 1
            print '<td><img src=3D"check-blank.jpg"
name=3D"aktuellesstatus"></td>' =

            print '<td bgcolor=3D"#F7DF89">',
            print x
            print """
            &nbsp;</td>
            <td><input type=3D"button"
onclick=3D"editaktuelles(),aktuelleschecked();" value=3D"edit"</td>
            </tr>
            <tr>
..."""
##
-------------------------------------------------------------------------=
--
----------
## this goes on for all the ten checkboxes on the HTML form
##
-------------------------------------------------------------------------=
--
-------------


my problem is very embarassing, the loop skips values it always generates=

the first chunk it gets, but if values are skipped on the form (example:
choosing checkbox 1, 2 ,6) the HTML chinks 1 and 2 would be printed but n=
ot
6!! if one chooses all of the checkboxes without any gaps the loop works.=


I thought that getting rid of the 'Nones's in the database fields would
help, nogo, I have re-written the above loop at least 6 times but I still=

cant get the" hiccups" out.


Could someone give me a helping hand?


Thanks


Sharriff
         =



From tutor@python.org  Mon May 14 07:25:27 2001
From: tutor@python.org (Tim Peters)
Date: Mon, 14 May 2001 02:25:27 -0400
Subject: [Tutor] checking for a condition across a list
In-Reply-To: <200105140552.BAA15414@smtp3.fas.harvard.edu>
Message-ID: <LNBBLJKPBEHFEDALKOLCEEAGKCAA.tim.one@home.com>

[Pijus Virketis]
> Thanks so much! Just one small note: the way you've written the
> function, the usage should be:
> >>> alltrue([1,1,1,1], isone) <-- inputs the other way around...

Wish I could say I was testing you, but, na, I screwed up -- cut 'n paste
error.  Good eye!

> Oh, and one more thing. I've never before encountered the
> "return x ==1" statement before. What exactly does it do?

Hmm.

    return expression

returns the value of expression from a function, where "expression" is any
expression.  "x == y" is a specific expression that yields 1 if x == y, else
0.  All the comparison operators work that way:

>>> 2 == 3
0
>>> 2 == 2
1
>>> 2 < 3
1
>>> 2 > 3
0
>>> 2 <= 3
1
>>> 2 >= 3
0
>>> 2 is 3
0
>>> 2 is not 3
1
>>> 'a' in 'abc'
1
>>> 'a' not in 'abc'
0
>>>

So

    return x == 1

returns 1 as the value of the function if x equals 1, and returns 0 as the
value of the function if x does not equal 1.  Clear?  Clear!



From r.b.rigilink@chello.nl  Mon May 14 08:04:14 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Mon, 14 May 2001 09:04:14 +0200
Subject: [Tutor] Restricting the type of passed-in objects
References: <3AFD3382.AF5626D9@chello.nl> <3AFF1122.C0D7C825@lindbergs.org>
Message-ID: <3AFF836E.DD9B9551@chello.nl>

VanL wrote:
> 
> Roeland Rengelink wrote:
> 

[snipped some of my own ramblings]

> 
> Here is how I came to this project:
> 
> I was thinking about writing a faq generator and maintainer for my work.  While
> thinking about the problem, it occurred to me that a faq could be easily
> represented by a tree of faqEntry objects.  Then I could also build into each
> entry the knowledge of how to render itself in various formats (html, text,
> whatever).  Then I could just call faq.render() on the root of the tree and it
> would recursively call itself to render the whole thing, including all the numbers
> 
> and hyperlinks (because the relationships would be defined by each entry's
> position in the tree).
> 
> After I started to work on that problem (and being a data structures junkie -- I
> just think they are cool) it seemed to me that it would be much better to write a
> general tree class and inherit from it.  Then, I started to think how I could make
> 

Being a data structure junkie myself I can sympathize. And there is
definitely something elegant about trees, especially about the way you
can implement various operations by recursive decent.

Trees are also very frustrating to implement in Python. Not because it
is difficult, but because it's so easy to do the same thing more
efficiently with lists or dictionaries.

For example. In a related thread Tim showed a simple BST tree with two
operations
insert() and traverse(). A far more efficient implementation of that
tree is:

import bisect
class BST_tree:
    def __init__(self):
        self.data = []

    def insert(self, value):
        index = bisect.bisect_left(self.data, value)
        if index < len(self.data) and value == self.data[index]:
            raise KeyError("%r allready in tree" % value)
        self.data.insert(index, value)

    def traverse(self, visitor):
        for value in self.data:
            visitor(value)

i.e. just a list under the hoods.

> that tree class be as general as possible, so that I could use it in the future to
> 
> represent different types of trees.

I think this may be a common beginners mistake in OO design. I certainly
frequently made (make) it myself. It seems `natural' to make your base
class as general as possible so you can easily inherit from it when you
want a special version of that base class. However, it is much more
fruitful to think of inheritance in terms of 

1. extending common functionality
The base class provides the implementation of those operations that all
child classes have in common. Such a base class will in general be small
and may be quite useless by itself.

2. implementing the common interface
The base class defines the inteface, and the chilren provide various
implementations
of that interface. Such a base class will be useless by itself, but the
fact that something inherits from it provides valuable information to
the user

Trying to predict in what way a base class will be usable for its
children is what makes it so incredibly hard to design reusable class
hierarchies top-down.

I.e. it is not clear to me whether your faqTree is going to be
- an instance of some general tree object
- a child class extending the functionality of a more abstract tree
- something that just uses a tree for internal representation.

> And thus we are here.  If my faq-o-matic works like I hope, I think it would be a
> pretty cool little hack -- It would be the first thing I would consider neat
> enough to submit to Useless Python.
> 

I don't want to discourage you from investigating abstract data
structures in Python.
It's fun and a great way to learn about one aspect of programming. Maybe
a fruitfull approach may be to first write a FaqTree class:

class FaqTree:
    ...

my_faq = FaqTree(...)
..test that all faq operations work on the my_faq object..

and then try to move tree-like functionality from FaqTree to some more
abstract Tree class

class Tree:
    ...
class FaqTree(Tree):
    ...

my_faq = FaqTree(...)
..test that all faq operations work on the my_faq object..

or, maybe

class Tree:
    ...
class Faq:
    def __init__(...)
        self.data = Tree()

my_faq = Faq(...)
..test that all faq operations work on the my_faq object..

It would be great if, by writing a Faq class, you end up with both a Faq
class and a Tree 
class. But even if you don't get the Tree, you would still have the Faq.

Hope this helps,

Roeland

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

-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From van@lindbergs.org  Mon May 14 08:09:45 2001
From: van@lindbergs.org (VanL)
Date: Mon, 14 May 2001 01:09:45 -0600
Subject: [Tutor] A Faq can be a tree (long)
References: <3AFD3382.AF5626D9@chello.nl> <3AFF1122.C0D7C825@lindbergs.org> <20010514013726.A1048@pino.selwerd.nl>
Message-ID: <3AFF84B9.6AF3277A@lindbergs.org>


Remco Gerlich wrote:

> On  0, VanL <van@lindbergs.org> wrote:
> > Here is how I came to this project:
> >
> > I was thinking about writing a faq generator and maintainer for my work.  While
> > thinking about the problem, it occurred to me that a faq could be easily
> > represented by a tree of faqEntry objects.
>
> Wait wait wait - *why* did this occur to you? Is the FAQ itself a hierarchy?
>

[snip]

>
>
> I don't think a tree is all that natural for a FAQ. I'd go for a dictionary
> - each FAQ entry has its own keyword or title, and that's the dictionary
> key. Hyperlinks are trivial (they point to another keyword). This goes along
> with the first rule of data structures in Python - "Use a dictionary".
> Alternatively you might want a list, or some object wrapping either of the
> two.
>
> But what's so tree-like about FAQs? They're organized into chapters, but
> besides that they're mostly a list of questions...

Imagine a faq as being described by the following grammar:

<faq> := <faqentry>
<faqentry> := <data>|<data><subsection>
<subsection> := <subfaq>|<subfaq><subsection>
<subfaq> := <faqentry>
<data> := <question><answer>|<heading>
<heading> := <title><head>
<title> := string
<head> := string
<question> := string
<answer> := string


I don't guarantee that this grammer is unambiguous, but it should be clear enough to
show the idea.
This grammar allows the entire faq to be represented by a tree -- the parse tree for
this grammar.

To be more concrete, take the following faq.

[start imaginary faq]

Faq about faqtrees

This is a faq about faqtrees.  It is also an illustration of why a tree representation
could be useful.

1. Q: What are trees?
     A:  Plants.

2. Q: What are FAQs?
    A:  Just the facts.

3. Q: What is question number 6?
    A: There is no question number 6.

The parse tree for this FAQ would be:

                                                        FAQ
                                                            |
                                                        Faqentry
                                                            /\
                                                          /    \
                                                        /        \
                                                Data        Subsection
                                                /|                    |  \
                                             /   \                   |     \
                                          Title Head      subfaq  subsection
                                            |         |               |
|      \
                                        string   string     faqentry      subfaq
subsection
                                                                      |
|                |
                                                                Data
faqentry      subfaq
                                                                /   |
/                   \
                                            Tree Question Ans       Data
faqentry
                                                                                /
\                     \
                                                                 FAQ question
answer        Data

/\

6  question answer


The data structure implementing this faq would be:

Root faqentry (members: title, head, children)
The childrenlist would point to:
1. faqentry (members: tree question, answer children=None)
2. faqentry (members: FAQ question, answer, children=None)
3. faqentry (members: Question 6, answer, children=None)

Anyway, in this way, the faq could have an arbitrary number of subsections that would
all "know" their relationship to the parent structure by their place in the tree.  The
advantage of this over the dictionary implementation that you propose is:
        1. No namespace collision for child entries (ok, you would need a really large
faq to actually run into this problem)
        2.  Inserting a new question/answer would automatically renumber anything
necessary, which would be a big time win for large complicated faqs.



If you still think I'm on drugs for thinking that I should implement a faq as a tree,
tell me.  That was just my thinking.

Van









From ppathiyi@cisco.com  Mon May 14 08:04:25 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Mon, 14 May 2001 12:34:25 +0530
Subject: [Tutor] Data Structures in Python
Message-ID: <022b01c0dc44$1bfac500$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

------=_NextPart_000_0228_01C0DC72.359DA440
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

        Where will i get some material on Data Structure implementations =
in python .. Trees, Graphs etc ?

Thanks and Regards,
Praveen.

------=_NextPart_000_0228_01C0DC72.359DA440
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
Where will i=20
get some material on Data Structure implementations in python .. Trees, =
Graphs=20
etc ?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks and Regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0228_01C0DC72.359DA440--



From scarblac@pino.selwerd.nl  Mon May 14 08:33:22 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 09:33:22 +0200
Subject: [Tutor] A Faq can be a tree (long)
In-Reply-To: <3AFF84B9.6AF3277A@lindbergs.org>; from van@lindbergs.org on Mon, May 14, 2001 at 01:09:45AM -0600
References: <3AFD3382.AF5626D9@chello.nl> <3AFF1122.C0D7C825@lindbergs.org> <20010514013726.A1048@pino.selwerd.nl> <3AFF84B9.6AF3277A@lindbergs.org>
Message-ID: <20010514093322.A1636@pino.selwerd.nl>

On  0, VanL <van@lindbergs.org> wrote:
> The data structure implementing this faq would be:
> 
> Root faqentry (members: title, head, children)
> The childrenlist would point to:
> 1. faqentry (members: tree question, answer children=None)
> 2. faqentry (members: FAQ question, answer, children=None)
> 3. faqentry (members: Question 6, answer, children=None)
> 
> Anyway, in this way, the faq could have an arbitrary number of subsections that would
> all "know" their relationship to the parent structure by their place in the tree.  The
> advantage of this over the dictionary implementation that you propose is:
>         1. No namespace collision for child entries (ok, you would need a really large
> faq to actually run into this problem)
>         2.  Inserting a new question/answer would automatically renumber anything
> necessary, which would be a big time win for large complicated faqs.

But when you renumber, would the hyperlinks still work? Oh right, you could
update all the contents of all the leaves.

But people refer to your FAQ from other places as well. Renumbering existing
items gives problems anyway.

I never meant a tree was a wrong way to go about it, just that your
reasoning "I want a FAQ - hey I could do this with a tree - let's make a
tree!" was a bit shallow :). You know have great detail on *how* you would
do it, but still not all that much reasoning *why*, and only about a single
data structure. Luckily, this is Python, so implementing it is pretty
trivial, and you can try two or three others afterwards to see if you like
them better :).

> If you still think I'm on drugs for thinking that I should implement a faq as a tree,
> tell me.  That was just my thinking.

Not at all. It's certainly possible. It just wasn't clear to me that it was
the best way.

-- 
Remco Gerlich


From arazak@kansai.com.my  Mon May 14 09:09:56 2001
From: arazak@kansai.com.my (Mr. Razak)
Date: Mon, 14 May 2001 16:09:56 +0800
Subject: [Tutor] Create simple dbf files
Message-ID: <000c01c0dc4d$44f3e140$6a01a8c0@com.my>

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C0DC90.517CAB20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

1. How to create simple dbf files.
    Field    "part name", "part number","quantity order"
    Type    "String","String","Numeric"

2. How to differenciate between txt files and dbf files in python.

Thanks.

------=_NextPart_000_0009_01C0DC90.517CAB20
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D3>1. How to create simple dbf =
files.</FONT></DIV>
<DIV><FONT face=3DArial size=3D3>&nbsp;&nbsp;&nbsp; =
Field&nbsp;&nbsp;&nbsp; "part=20
name", "part number","quantity order"</FONT></DIV>
<DIV><FONT face=3DArial size=3D3>&nbsp;&nbsp;&nbsp; =
Type&nbsp;&nbsp;&nbsp;=20
"String","String","Numeric"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D3>2. How to differenciate between txt =
files and dbf=20
files in python.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial>Thanks.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0009_01C0DC90.517CAB20--



From tim.one@home.com  Mon May 14 09:12:21 2001
From: tim.one@home.com (Tim Peters)
Date: Mon, 14 May 2001 04:12:21 -0400
Subject: [Tutor] Restricting the type of passed-in objects
In-Reply-To: <3AFF836E.DD9B9551@chello.nl>
Message-ID: <LNBBLJKPBEHFEDALKOLCKEALKCAA.tim.one@home.com>

[Roeland Rengelink]
> Being a data structure junkie myself I can sympathize. And there is
> definitely something elegant about trees, especially about the way you
> can implement various operations by recursive decent.
>
> Trees are also very frustrating to implement in Python. Not because it
> is difficult, but because it's so easy to do the same thing more
> efficiently with lists or dictionaries.

Testify, brother!  You're right, of course.  Python dicts are very hard to
beat speedwise, for any problem where they suffice and the data fits in
memory.  Tree approaches usually don't win until the data is so large it
needs to spill to disk, and then trees *designed* for out-of-RAM storage are
the way to go (like B-tree variants, not binary trees).

Historical tidbit:  Guido worked on the implementation of the ABC language
before Python.  ABC used balanced (AVL) binary trees under the covers for
almost everything, with provable log-time worst-case behavior.  In actual
practice, ABC ran very slowly, mostly because the overhead of balanced tree
operations swamps all other considerations until the trees grow quite large.
So Python uses contiguous vectors to implement lists, and simple hash tables
to implement dicts, and so on:  very low overhead even for tiny sizes.  dicts
are faster than trees for huges RAM-like sizes too, but you can definitely
get into real speed trouble using a plain list if it grows large and you
insert or delete "in the middle".

> For example. In a related thread Tim showed a simple BST tree with two
> operations insert() and traverse().

Also contains(), but it's a trivial variation on insert().

> A far more efficient implementation of that tree is:
>
> import bisect
> class BST_tree:

Oops!  Stop right there.  In Python *practice*, I confess I usually use
bisect directly, not bothering to wrap it in a class.  Note that bisect does
take O(len(x)) time for an insert into x, and when len(x) is greater than a
few hundred that can be a real problem.  But it can't be beat for small
len(x).

Similarly there's mounds and mounds of Python code out there that uses dicts
directly to implement sets:

small_primes = {2:1, 3:1, 5:1, 7:1, 11:1}
small_evens = {2:1, 4:1, 6:1, 8:1, 10:1}

union = small_primes.copy()
union.update(small_evens)

and so forth.

For all the rest, "do the simplest thing that could possibly work" is
especially good advice in Python:  once you get the hang of it, it's so easy
to refactor Python code that there's no *need* to try to out-guess every
possibility in advance.  The last thing the world needs is yet another
prefectly general framework *so* perfectly general nobody can figure out how
to apply it to a specific problem <wink>.

Python's os.path.walk() is a minor but good example of that:  newbies have
been known to scratch their heads over the walk() docs for hours before
figuring out how to use it.  It's much simpler to just write the obvious
loop, using list.append() and list.pop() to maintain an explicit stack of
directories to visit.

most-small-abstractions-aren't-worth-the-bother-of-abstracting-ly
    y'rs  - tim



From dyoo@hkn.eecs.berkeley.edu  Mon May 14 09:32:00 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 14 May 2001 01:32:00 -0700 (PDT)
Subject: [Tutor] Help with signals, please?
In-Reply-To: <2AA413D315E@kserver.org>
Message-ID: <Pine.LNX.4.21.0105140108300.16450-100000@hkn.eecs.berkeley.edu>

On Sun, 13 May 2001, Sheila King wrote:

> Apparently, this is one of those "platform" issues. I just uploaded
> the script to my webhost, who runs a Linux server, and ran it in my
> Telnet account. It ran just fine.
> 
> How can I get this effect in Windows?

Platform specific stuff stinks.  *sigh*

    http://mail.python.org/pipermail/python-list/2001-January/025066.html

mentions that SIGALRM isn't available on Windows.  Their recommendation is
to use the more platform-independent asyncore module.  I have no
experience with asyncore though; perhaps someone can help us with this.


Is it possible to rewrite your program with threads?  It might be easier
to do this kind of timeout-alarm with a thread, because they're fairly
well supported on both Windows and Linux:

###
from threading import Thread
import time

class DelayedFunction(Thread):
    def __init__(self, function, delay):
        Thread.__init__(self)
        self.function, self.delay = function, delay

    def run(self):
        time.sleep(self.delay)
        self.function()


def timesUp():
    print "Time's up!"


def test():
    print "The 10 second time begins NOW!\n"
    my_thread = DelayedFunction(timesUp, 10)
    my_thread.start()
    while 1:
        time.sleep(1)
        print "A second passes..."
###

This might give you the sort of timeout-alarm control that you're looking
for.  Hope this helps!



From alan.gauld@bt.com  Mon May 14 09:57:08 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 May 2001 09:57:08 +0100
Subject: [Tutor] Linux help required
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D762@mbtlipnt02.btlabs.bt.co.uk>

> | that the zip file can't be opened by gunzip under Linux. I have 

Thanks to Deirdre for pointing out that gunzip only works on 
single files, I hadn't realised that - I've only used in on 
Unix up til now where tgz is the norm...

> Also, I think tar/gzip check the extension of the file they are run
> on.  I have generally found the .tar.gz extension to work better than
> the .tgz extension.

I've use tgz and tested it with winzip.
I will probably standardize on this since it works for both Linux 
and Windoze. And I've now got a batch file to build it faster 
than using the winzip gui...

> | now used cygwin(*) to create a tgz file and would like a volunteer 
> | with Linux to test it for me. 

Kalle volunteered first so I've sent a copy to him.

If anyone else feels curious I've actually put it on the 
web site, theres a link at the bottom of the contents page
at:

http://www.crosswinds.net/~agauld/

> Did you use gzip or zip?  

gzip.

> I referred a friend to your tutorial recently and it would be really
> helpful to him if he could download a copy and browse it while
> offline.  I didn't notice a downloadable version from a quick glance.

The link is right at the bottom of the contents frame, I should 
probably move it somewhere more obvious. In the early days the 
contents fit on a single screen! :-)

> Is this the file you are asking about?  If not I think it would be
> great if you could provide a tarball/zip archive of your tutorial.

Yes, the zip version has been there since day 1, but I had assumed 
Linux could read it... Its only this week I've discovered that it 
couldn't(although with zip maybe it cann...)

Alan g


From alan.gauld@bt.com  Mon May 14 10:05:43 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 May 2001 10:05:43 +0100
Subject: [Tutor] Clearing the screen
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D763@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C0DC55.0E76C710
Content-type: text/plain; charset="iso-8859-1"

I am printing lot of lines to the screen (stdout). If at any point of time,
i want to clear the screen,  
is there any command which will help me do this ? [ Other than
os.system('clear') ]  

os.system("clear") is probably the best bet because clearing the screen is
very 
terminal specific.
 
You could write a function to lookup terminfo/termcap and send the
appropriate 
control sequences, but that's just duplicating what clear does!
 
Alan G.

------_=_NextPart_001_01C0DC55.0E76C710
Content-type: text/html; charset="iso-8859-1"

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


<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV><FONT face=Arial size=2>I am printing lot of lines to the screen 
  (stdout). If at any point of time, i want to clear the screen,&nbsp;<SPAN 
  class=280220509-14052001><FONT color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV>
  <DIV><FONT size=2><FONT face=Arial>is there any command which will help me do 
  this ? [ Other than os.system('clear') ]<FONT color=#0000ff><SPAN 
  class=280220509-14052001>&nbsp;</SPAN></FONT></FONT></FONT><FONT size=2><FONT 
  face=Arial><FONT color=#0000ff><SPAN 
  class=280220509-14052001>&nbsp;</SPAN></FONT></FONT></FONT></DIV></BLOCKQUOTE>
<DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN 
class=280220509-14052001>os.system("clear") is probably the best bet because 
clearing the screen is very </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN 
class=280220509-14052001>terminal specific.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN 
class=280220509-14052001></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN 
class=280220509-14052001>You could write a function to lookup terminfo/termcap 
and send the appropriate </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN 
class=280220509-14052001>control sequences, </SPAN></FONT></FONT></FONT><FONT 
size=2><FONT face=Arial><FONT color=#0000ff><SPAN class=280220509-14052001>but 
that's just duplicating what clear does!</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN 
class=280220509-14052001></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2><FONT face=Arial><FONT color=#0000ff><SPAN 
class=280220509-14052001>Alan G.</SPAN></FONT></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C0DC55.0E76C710--


From scarblac@pino.selwerd.nl  Mon May 14 10:23:36 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 11:23:36 +0200
Subject: [Tutor] Linux help required
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D762@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Mon, May 14, 2001 at 09:57:08AM +0100
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D762@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20010514112336.A2311@pino.selwerd.nl>

On  0, alan.gauld@bt.com wrote:
> > | that the zip file can't be opened by gunzip under Linux. I have 
> 
> Thanks to Deirdre for pointing out that gunzip only works on 
> single files, I hadn't realised that - I've only used in on 
> Unix up til now where tgz is the norm...

It's exactly the same on Unix and Linux. .tgz even means tar/GNU zip.

A .tgz is usually called .tar.gz. That is, you make an archive out of a
bunch of files, the .tar, then you gzip that, and it's called .tar.gz,
sometimes abbreviated .tgz for people using DOS or similar systems.

That's two commands to make a compress archive, although GNU tar has an
option to combine the two, so it's one command again.

But you were talking about a zip file, which isn't the same as a gzip file
at all.

> > Also, I think tar/gzip check the extension of the file they are run
> > on.  I have generally found the .tar.gz extension to work better than
> > the .tgz extension.

On Unix, extensions are irrelevant.

> > Did you use gzip or zip?  
> 
> gzip.

Ah, so ignore all the talk about unzip given earlier, that has to do with
zip files :)

> > Is this the file you are asking about?  If not I think it would be
> > great if you could provide a tarball/zip archive of your tutorial.
> 
> Yes, the zip version has been there since day 1, but I had assumed 
> Linux could read it... Its only this week I've discovered that it 
> couldn't(although with zip maybe it cann...)

Most distributions do have zip/unzip commands. Someone was talking about
Debian, maybe it's those pedants whining about 'Free' again ;-)

gzip is GNU zip, or as Free as it gets, anyway.


PS bzip2 is a lot better, of course. <grin, duck and run>
-- 
Remco Gerlich


From alan.gauld@bt.com  Mon May 14 10:28:41 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 May 2001 10:28:41 +0100
Subject: [Tutor] Linux help required
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D764@mbtlipnt02.btlabs.bt.co.uk>

> It's exactly the same on Unix and Linux. .tgz even means tar/GNU zip.

Sure, I use both but had never tried unzipping a winzip 
file under *nix. I've unzipped lots of tgz files under winzip
so just assumed gzip could do the same tricks, but never 
actually tried it...

> But you were talking about a zip file, which isn't the same 
> as a gzip file at all.

So I've discovered! :-)

Alan G


From r.b.rigilink@chello.nl  Mon May 14 10:47:30 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Mon, 14 May 2001 11:47:30 +0200
Subject: [Tutor] Restricting the type of passed-in objects
References: <LNBBLJKPBEHFEDALKOLCKEALKCAA.tim.one@home.com>
Message-ID: <3AFFA9B2.54C6D727@chello.nl>

Tim Peters wrote:
> 
> [Roeland Rengelink]

[snip]

> > For example. In a related thread Tim showed a simple BST tree with two
> > operations insert() and traverse().
> 
> Also contains(), but it's a trivial variation on insert().
> 
> > A far more efficient implementation of that tree is:
> >
> > import bisect
> > class BST_tree:
> 
> Oops!  Stop right there.  In Python *practice*, I confess I usually use
> bisect directly, not bothering to wrap it in a class.  Note that bisect does
> take O(len(x)) time for an insert into x, and when len(x) is greater than a
> few hundred that can be a real problem.  But it can't be beat for small
> len(x).
> 

I knew I should have qualified "far more efficient than Tim" far better
than I did ;)

On the other hand I was tempted to write the insert as:

def insert(self, value):
    if value in self.data:
        raise KeyError
    else:
        self.data.append(value)
        self.data.sort()

even though that'd have been O(n) for the contains test and O(nlogn) for
the sort,
just to point out that even the most naive implementation is more
efficient.

(Before Tim points this out, I _think_ in this case the sort is O(n),
because sort special cases on data that is already mostly sorted)

> 
> Python's os.path.walk() is a minor but good example of that:  newbies have
> been known to scratch their heads over the walk() docs for hours before
> figuring out how to use it.  It's much simpler to just write the obvious
> loop, using list.append() and list.pop() to maintain an explicit stack of
> directories to visit.
> 

I can still remember scratching.

Apart from the ease of just writing it yourself, I think this also has
something to do with the fact that the visitor pattern may not be
obvious (at least it wasn't to me before it had been spelled out to me).
That is probably because passing functions around is not something that
comes naturally. Well, maybe it does in Python, but...you get my point.
(BTW Somebody ought to write the Python companion to Design Patterns
(the martellibot?) I have a nagging suspicion that it will be very
thin.)

Another example would be the simple mistake beginners will make at least
once when
assigning callbacks to Buttons in Tkinter, writing:

b = Button(.. command = mycommand()) 
 
in stead of

b = Button(.. command = mycommand)


Also, why does os.path.walk visit directories and not individual files?


Roeland
-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From hermit@erie.net  Mon May 14 10:43:12 2001
From: hermit@erie.net (Hermit)
Date: Mon, 14 May 2001 05:43:12 -0400 (EDT)
Subject: [Tutor] Manuals/books
Message-ID: <Pine.LNX.4.33.0105140537130.880-100000@hermit.erie.net>

I am new to this mailing list and have interest in learning Python.  I am
a Linux user (Red Hat distro), and would appreciate the advice from
the seasoned Python programmers on this list as to which book to buy so I
can have a learning tool as I attempt to learn Python.

I have been a fan of the O'Reilly books for some time now, but also noted
"Learn to Program Using Python" by Alan Gauld.  I get the impression that
Mr. Gauld is the local Python guru around here.

I am a beginner, and seek the recommendations of those who would recommend
a good starter book.

Regards,

Dick Williams



From NHYTRO@compuserve.com  Mon May 14 11:01:52 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Mon, 14 May 2001 06:01:52 -0400
Subject: [Tutor] Ftp question
Message-ID: <200105140602_MC2-D0D1-C416@compuserve.com>

Hi!

1. using the ftplib to upload images onto a remote server per CGI, I
noticed that after a fie upload, the connection closes, is there a way to=

keep this connection open till I finish iterating thru a a list of files =
to
upload? I found nothing addressing this at Python.org.

2. Some files don=B4t get completely transfered, only gibberish is writte=
n. I
noticed this happens to bigger files. I increased the Buffer to 8192 but
that did=B4nt help, is there a way to address this problem? I=B4ll be upl=
oading
very big image files.


Cheers


Sharriff


From scarblac@pino.selwerd.nl  Mon May 14 11:19:58 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 12:19:58 +0200
Subject: [Tutor] Values being skipped-Iteration
In-Reply-To: <200105140223_MC2-D0D2-2B21@compuserve.com>; from NHYTRO@compuserve.com on Mon, May 14, 2001 at 02:23:21AM -0400
References: <200105140223_MC2-D0D2-2B21@compuserve.com>
Message-ID: <20010514121958.A2404@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:

(snip)

> for x in links[:]:
>         if x == "Home":         
>             counter = counter + 1
>             print '<td><img src="check-blank.jpg" name="homestatus"></td>'
>             print '<td bgcolor="#F7DF89">',
>             print x
>             print """
>             &nbsp;</td>
>             <td><input type="button" onclick="edithome(),homechecked();"
> value="edit"</td>

             ^^ missing >

(snip)

> my problem is very embarassing, the loop skips values it always generates
> the first chunk it gets, but if values are skipped on the form (example:
> choosing checkbox 1, 2 ,6) the HTML chinks 1 and 2 would be printed but not
> 6!! if one chooses all of the checkboxes without any gaps the loop works.
> 
> I thought that getting rid of the 'Nones's in the database fields would
> help, nogo, I have re-written the above loop at least 6 times but I still
> cant get the" hiccups" out.
> 
> 
> Could someone give me a helping hand?

>From this code, I can't tell what the problem could be. Possibly something
is spelled wrong in one of the lower 'if' clauses. Or maybe 'links' doesn't
always contain what you expect? Maybe you should print it out before the
loop, to check.

In all of those if: clauses, all you do is: 1) increase counter, 2) print
some html, 3) print x, 4) print some more html, right? Wouldn't it be easier
to put all of that in a dictionary and print the appropriate string, instead
of using a lot of ifs?

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Mon May 14 11:28:04 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 12:28:04 +0200
Subject: [Tutor] Data Structures in Python
In-Reply-To: <022b01c0dc44$1bfac500$37ef87c0@ppathiyipc>; from ppathiyi@cisco.com on Mon, May 14, 2001 at 12:34:25PM +0530
References: <022b01c0dc44$1bfac500$37ef87c0@ppathiyipc>
Message-ID: <20010514122804.A2438@pino.selwerd.nl>

On  0, Praveen Pathiyil <ppathiyi@cisco.com> wrote:
> Where will i get some material on Data Structure implementations in python
> .. Trees, Graphs etc ?

Go to the Vaults of Parnassus, lots of links. 
http://www.vex.net/parnassus/
http://www.vex.net/parnassus/apyllo.py?find=tree
http://www.vex.net/parnassus/apyllo.py?find=graph

They both give lots of false hits, of course, but for instance there's
"Graph Library 1.0.1" which does graphs.

In general, when writing Python, it's *much* easier to just use a list or
dictionary. Dictionaries are fast, very easy to use, and the greatest thing
since sliced bread. It's a high level language, use it.

It's amazing how many hard things (hard in C or Pascal) become trivial if
you have first class dicts - see the solutions to ACM programming contest
problems at Useless Python,
http://www.lowerstandard.com/python/ACMsolutions.html .

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Mon May 14 11:43:03 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 12:43:03 +0200
Subject: [Tutor] Create simple dbf files
In-Reply-To: <000c01c0dc4d$44f3e140$6a01a8c0@com.my>; from arazak@kansai.com.my on Mon, May 14, 2001 at 04:09:56PM +0800
References: <000c01c0dc4d$44f3e140$6a01a8c0@com.my>
Message-ID: <20010514124303.B2438@pino.selwerd.nl>

On  0, "Mr. Razak" <arazak@kansai.com.my> wrote:
> 1. How to create simple dbf files.
>     Field    "part name", "part number","quantity order"
>     Type    "String","String","Numeric"

Simple? Use shelves. Types aren't very relevant in Python, of course.

import shelve

d = shelve.open(filename)

# Store items by part number
d[2343] = ("Piece of string", 35543)
d[2344] = ("Can of spam", 10)

d.close() # That's all, it's stored

# Now read them in
d = shelve.open(filename)
for partnumber in d.keys():
   print ("Partnumber: %d Part name: %s Quantity: %d" %
          (partnumber, d[partnumber][0], d[partnumber][1]))
d.close()

Storing them like tuples like this is pretty simple, a dictionary works
as well, or a class instance. You need some key (like the part number) to
use as an index, but you need that anyway.

Shelve is a layer over anydbm, which works the same way, but can only store
strings as values. Shelve converts your data to strings and then puts those
in the dbm. In effect the shelve works just like a persistent dictionary in
which you put data. Simplicity.

> 2. How to differenciate between txt files and dbf files in python.

You could use whichdb.whichdb(filename), which returns the empty string ('')
if the file's format can't be guessed, in which case it's not a dbm Python
recognizes. Returns None when the file can't be opened.

Now go read the library reference for shelve, anydbm and whichdb before you
use them :-)

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Mon May 14 12:04:38 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 13:04:38 +0200
Subject: [Tutor] Manuals/books
In-Reply-To: <Pine.LNX.4.33.0105140537130.880-100000@hermit.erie.net>; from hermit@erie.net on Mon, May 14, 2001 at 05:43:12AM -0400
References: <Pine.LNX.4.33.0105140537130.880-100000@hermit.erie.net>
Message-ID: <20010514130438.C2438@pino.selwerd.nl>

On  0, Hermit <hermit@erie.net> wrote:
> I am new to this mailing list and have interest in learning Python.  I am
> a Linux user (Red Hat distro), and would appreciate the advice from
> the seasoned Python programmers on this list as to which book to buy so I
> can have a learning tool as I attempt to learn Python.

> I have been a fan of the O'Reilly books for some time now, but also noted
> "Learn to Program Using Python" by Alan Gauld.  I get the impression that
> Mr. Gauld is the local Python guru around here.

He's one of many Python experts around here. I'd call Tim Peters the guru :)

> I am a beginner, and seek the recommendations of those who would recommend
> a good starter book.

So, never programmed before, Linux user.

"Learn to Program Using Python" teaches programming concepts for the
complete beginner. Most of what's in the book is also on his website
(http://www.crosswinds.net/~agauld/) so even if you prefer paper books you
can look there first to see if you like the content.

However, what do you want to use Python for? If you want to write scripts to
automate things for you in the shell, for instance, Alan's book has no
examples on that. It's a programming course, not a sysadminning book :).
I like "Learning Python", it has examples at the end for all kinds of small
file tasks, Internet things, and so on - but it may well be hard if you
don't have any programming experience.

There are other books, the Quick Python Book, Teach Yourself Python in 24
Hours, Core Python Programming - I haven't read them. A pretty complete list
of Python books with reviews and links to sample chapters etc is at
http://www.amk.ca/bookstore/python.html .

So if you're a complete newbie and it's no problem to buy a few other books
later on as well, just go for Learn to program using Python. If you don't
want many books are have programming experience already, it's probably best
to look through several online tutorials, see if you have problems and what
you want to do, and then buy a book.

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Mon May 14 12:11:35 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 13:11:35 +0200
Subject: [Tutor] Ftp question
In-Reply-To: <200105140602_MC2-D0D1-C416@compuserve.com>; from NHYTRO@compuserve.com on Mon, May 14, 2001 at 06:01:52AM -0400
References: <200105140602_MC2-D0D1-C416@compuserve.com>
Message-ID: <20010514131135.D2438@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:
> 1. using the ftplib to upload images onto a remote server per CGI, I
> noticed that after a fie upload, the connection closes, is there a way to
> keep this connection open till I finish iterating thru a a list of files to
> upload? I found nothing addressing this at Python.org.

It shouldn't do that, as far as I know. It would help if you could post a
snippet of your code. Can you test the program from the command line instead
of in CGI? Does it make a difference? (that's just blind guesswork)

> 2. Some files don´t get completely transfered, only gibberish is written. I
> noticed this happens to bigger files. I increased the Buffer to 8192 but
> that did´nt help, is there a way to address this problem? I´ll be uploading
> very big image files.

Hmm. Are you on Windows but opening the files in ASCII form?
Use open(filename, "rb"), not just "r".

By default, files are opened as ASCII, and on Windows, a ^Z byte means end
of file. In a binary file like an image, that byte may occur anywhere.
Opening the file in binary mode works.

-- 
Remco Gerlich


From rob@jam.rr.com  Mon May 14 12:19:57 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Mon, 14 May 2001 06:19:57 -0500
Subject: [Tutor] Manuals/books
References: <Pine.LNX.4.33.0105140537130.880-100000@hermit.erie.net>
Message-ID: <3AFFBF5D.ED8CBC1F@jam.rr.com>

Remco's response to your question seemed good to me as far as finding
the right books. I approached Python after having taken a really basic
Pascal class ten years previous. Although it wasn't exactly a CS degree,
I knew what variables and "if" statements were and the difference
between a stack and a queue.

Armed with this info and the tutorial that shipped with Python, I opened
IDLE and started playing. I've since made use of a few beginner Python
books and the host of tutorials on the web and posted questions to the
Tutor List here. After about a year of just experimenting and trying to
figure out what people were talking about, I think I seem to understand
what's being discussed in the new (somewhat more advanced) Programming
Python. I'd imagine that most people could advance with Python faster
than I have, since I can usually only experiment between work and Board
meetings. (Maintaining Useless Python doesn't take too much time.)

If you try some things you find in tutorials and ask questions here when
you get stumped, just about any beginner book should do fine. Here's a
link to my page of all the tutorial sites I've found:

http://www.lowerstandard.com/python/howtolinks.html

Rob

Hermit wrote:
> 
> I am new to this mailing list and have interest in learning Python.  I am
> a Linux user (Red Hat distro), and would appreciate the advice from
> the seasoned Python programmers on this list as to which book to buy so I
> can have a learning tool as I attempt to learn Python.
> 
> I have been a fan of the O'Reilly books for some time now, but also noted
> "Learn to Program Using Python" by Alan Gauld.  I get the impression that
> Mr. Gauld is the local Python guru around here.
> 
> I am a beginner, and seek the recommendations of those who would recommend
> a good starter book.
> 
> Regards,
> 
> Dick Williams
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html


From scarblac@pino.selwerd.nl  Mon May 14 12:35:16 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 13:35:16 +0200
Subject: [Tutor] Values being skipped-Iteration
In-Reply-To: <200105140728_MC2-D0DE-EE12@compuserve.com>; from NHYTRO@compuserve.com on Mon, May 14, 2001 at 07:28:00AM -0400
References: <200105140728_MC2-D0DE-EE12@compuserve.com>
Message-ID: <20010514133516.A2600@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:
> Message text written by Remco Gerlich
> >In all of those if: clauses, all you do is: 1) increase counter, 2) print
> some html, 3) print x, 4) print some more html, right? Wouldn't it be
> easier
> to put all of that in a dictionary and print the appropriate string,
> instead
> of using a lot of ifs?<
> 
> It would have been easier, the problem is  that  I´m dynamically adding
> value "x" to the HTML, that means I would stll have to use ifs sinc
> Dictionaries have only one value per label :-(

But 
1) The x you add in the HTML is also the x you test for in the if. So it's
   always the same, in that if block.

2) You can put '%s' in the html template, and do something like 
   template_dict[x] % x
   later on to have it filled in.

The problem with skipping options is still strange though. Probably
something missing in 'links', or you made a mistake somewhere.

-- 
Remco Gerlich


From NHYTRO@compuserve.com  Mon May 14 13:28:53 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Mon, 14 May 2001 08:28:53 -0400
Subject: [Tutor] RE: Ftp question
Message-ID: <200105140829_MC2-D0E4-40DB@compuserve.com>

Remco Gehrlich wrote:
>It shouldn't do that, as far as I know. It would help if you could post =
a
>snippet of your code. Can you test the program from the command line
instead
>of in CGI? Does it make a difference? (that's just blind guesswork)

Yes, actually I havent tried running it as a CGI script at all:

###  Pythonwin session ###
>>> ftp =3D FTP('zeus')
>>> ftp.login('sharriff', 'golem'
'230 User sharriff logged-in'
>>> ftp.storbinary('stor page2b.jpg', open('c:\\page2b.jpg', 'rb'), 8192)=

'226 Closing data connection'

## end session ##

this stores an unreadable JPG file on my test server, even with 'rb'     =
  =

heres the code that I plan to use in my CGI script:

### code snippet from CGI script
#
# Iterate thru imageurls,use 'image'( single url) to upload images to
server
for each imageurl in imageurls:
....tempimagename =3D os.path.split(imageurl)
....imagename =3D tempimagename[1]    =

....ftp =3D FTP(serverip) # connect, serverip is the host name extracted =
from
database
....ftplogin(usernamevalue, userpasswordvalue)
....#ftp.connect(usernamevalue, userpasswordvalue)# crashes ??
....ftp.strorbinary("stor %s" %(imagename), open(imageurl, 'rb'), 1024)
ftp.quit
ftp.close()
# -----------------------------
######## CGI script snippet end ###


Text files get transfered fine, I have=B4nt tried it with other file type=
s.


Thanks for your help!


Sharriff



From arcege@speakeasy.net  Mon May 14 13:59:56 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Mon, 14 May 2001 08:59:56 -0400 (EDT)
Subject: [Tutor] RE: Ftp question
In-Reply-To: <200105140829_MC2-D0E4-40DB@compuserve.com> from "Sharriff Aina" at May 14, 2001 08:28:53 AM
Message-ID: <200105141259.f4ECxuW10321@dsl092-074-184.bos1.dsl.speakeasy.net>

Sharriff Aina wrote
>=20
> Remco Gehrlich wrote:
> >It shouldn't do that, as far as I know. It would help if you could pos=
t a
> >snippet of your code. Can you test the program from the command line
> instead
> >of in CGI? Does it make a difference? (that's just blind guesswork)
>=20
> Yes, actually I havent tried running it as a CGI script at all:
>=20
> ###  Pythonwin session ###
> >>> ftp =3D FTP('zeus')
> >>> ftp.login('sharriff', 'golem'
> '230 User sharriff logged-in'
> >>> ftp.storbinary('stor page2b.jpg', open('c:\\page2b.jpg', 'rb'), 819=
2)
> '226 Closing data connection'
>=20
> ## end session ##
>=20
> this stores an unreadable JPG file on my test server, even with 'rb'   =
   =20
> heres the code that I plan to use in my CGI script:
>=20
> ### code snippet from CGI script
> #
> # Iterate thru imageurls,use 'image'( single url) to upload images to
> server
> for each imageurl in imageurls:
> ....tempimagename =3D os.path.split(imageurl)
> ....imagename =3D tempimagename[1]   =20
> ....ftp =3D FTP(serverip) # connect, serverip is the host name extracte=
d from
> database
> ....ftplogin(usernamevalue, userpasswordvalue)
> ....#ftp.connect(usernamevalue, userpasswordvalue)# crashes ??
> ....ftp.strorbinary("stor %s" %(imagename), open(imageurl, 'rb'), 1024)
> ftp.quit
> ftp.close()
> # -----------------------------
> ######## CGI script snippet end ###
>=20
>=20
> Text files get transfered fine, I have=B4nt tried it with other file ty=
pes.

I've noticed the same thing (corruption of binary files after a certain
point) on WinNT when I was writing a FTP server a couple of months ago.
My problem is on the other end (receiving, instead of transmitting).
I think that I had tracked it down to the socket data handling.
Unfortunately, I haven't had time to track it down to something specific.
If I find something more concrete I will let the list know.

One suggestion I have is:  create a large binary file with a specific
pattern to it, say 0xa5 (10100101) repeating, and find out where the
pattern starts to get corrupted.  You could even "simulate" the large
file.  Instead of passing an open file, pass a class instead with a read
method that generates the pattern.  I assume that you can see the file
once it is on the other side.

class PattFile:
  def read(self, size=3D-1):
    if size <=3D 0:
      return ''
    return chr(0xa5) * size

Warning: as is, this is an infinite length file (unless size is zero
or less). ;)

  -Arcege

--=20
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From scarblac@pino.selwerd.nl  Mon May 14 14:11:07 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 14 May 2001 15:11:07 +0200
Subject: [Tutor] RE: Ftp question
In-Reply-To: <200105140829_MC2-D0E4-40DB@compuserve.com>; from NHYTRO@compuserve.com on Mon, May 14, 2001 at 08:28:53AM -0400
References: <200105140829_MC2-D0E4-40DB@compuserve.com>
Message-ID: <20010514151107.A2755@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:
> Remco Gehrlich wrote:
> >It shouldn't do that, as far as I know. It would help if you could post a
> >snippet of your code. Can you test the program from the command line
> instead
> >of in CGI? Does it make a difference? (that's just blind guesswork)
> 
> Yes, actually I havent tried running it as a CGI script at all:
> 
> ###  Pythonwin session ###
> >>> ftp = FTP('zeus')
> >>> ftp.login('sharriff', 'golem'
> '230 User sharriff logged-in'
> >>> ftp.storbinary('stor page2b.jpg', open('c:\\page2b.jpg', 'rb'), 8192)
> '226 Closing data connection'

Actually, this doesn't close your ftp connection, does it? It only closes
the data connection that was setup for that file. It should be possible to
do another storbinary command immediately.

I don't understand why it doesn't work, it works fine here :(.

> this stores an unreadable JPG file on my test server, even with 'rb'

Weird weird weird. Are you sure the original is still good? Are the file
sizes different?

> heres the code that I plan to use in my CGI script:
> 
> ### code snippet from CGI script
> #
> # Iterate thru imageurls,use 'image'( single url) to upload images to
> server
> for each imageurl in imageurls:
> ....tempimagename = os.path.split(imageurl)
> ....imagename = tempimagename[1]    
> ....ftp = FTP(serverip) # connect, serverip is the host name extracted from
> database
> ....ftplogin(usernamevalue, userpasswordvalue)

forgot the .

> ....#ftp.connect(usernamevalue, userpasswordvalue)# crashes ??
> ....ftp.strorbinary("stor %s" %(imagename), open(imageurl, 'rb'), 1024)
> ftp.quit

Don't forget the ()!

> ftp.close()
> # -----------------------------
> ######## CGI script snippet end ###

Something like that should work fine, I would do, I think

import ftplib, os
ftp = ftplib.FTP(serverip)
ftp.login(username, password)
for each imagefile in imagefiles: # They're not exactly urls, just filenames
   ftp.storbinary('STOR '+os.path.basename(imagefile), open(imagefile,'rb'),
                  8192)
ftp.quit()

Still need to find out why the file is mangled on the other side.

-- 
Remco Gerlich


From alan.gauld@bt.com  Mon May 14 14:02:51 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 May 2001 14:02:51 +0100
Subject: [Tutor] Manuals/books
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D767@mbtlipnt02.btlabs.bt.co.uk>

> "Learn to Program Using Python" by Alan Gauld.  I get the 
> impression that Mr. Gauld is the local Python guru around here.

Oh, if only, but have to defer to several other contributers 
on that score. But OTOH I do participate on the list which 
is more than the other Python book authors do (Wesley being 
the obvious exception!).

I also maintain a web page of errata and reply to mail
sent from that web page to me poersonally.

Whichever book you buy someone on this list probably has 
read it, and even if they haven't we will try to answer 
questions.

Alan G.


From AnthonyBeaman@trginc.com  Mon May 14 14:48:27 2001
From: AnthonyBeaman@trginc.com (Anthony Beaman)
Date: Mon, 14 May 2001 09:48:27 -0400
Subject: [Tutor] Total Programming Newbie
Message-ID: <6D19AB695BA8D311A8420008C7CF285A020A8CA3@trgmail>

Hi! I'm beginning to learn programming via Python. I'm using the Windows
version along with the "24 Hours" book. Do you have any tips on learning
programming? I've searched the net for general programming tips and I've
found just a few. From what I've read, I should use a book (material), study
the code of others (copy? Make changes? Improvise?), and do lots of
practice. If this is correct, how do I go about this? For example, I can put
in 2-3 hours a day (more on the weekends). How should I use my time? Should
I use the book for an hour or so and then use the remaining time to code?
Should I look over existing code later after I've gone through some books
and gotten more knowledge? How should I use my practice sessions? Right now,
I'm merely going over my exercises and examples and making changes to them
(incorporating what I know; sorta like improvising). Is this ok? Thanks! 


From randrews@planhouse.com  Mon May 14 15:00:16 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Mon, 14 May 2001 09:00:16 -0500
Subject: [Tutor] Total Programming Newbie
In-Reply-To: <6D19AB695BA8D311A8420008C7CF285A020A8CA3@trgmail>
Message-ID: <000a01c0dc7e$34c52820$de00a8c0@planhouse5>

You seem to have the right idea. Keep looking over the material in any books
and tutorials you can find, play with the code of others, and make use of
the Python Tutor email list by looking at the archives and asking questions
on the list here.

It's not necessary to wait until after you feel like you've mastered any
given book before spending some time coding. Try and write any scripts you
can now, and as you piece them together, you can use the books/tutorials for
ideas and to help figure out how to do whatever it is you're trying at the
moment.

Rob
Useless Python
http://www.lowerstandard.com/python/pythonsource.html

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Anthony Beaman
Sent: Monday, May 14, 2001 8:48 AM
To: 'tutor@python.org'
Subject: [Tutor] Total Programming Newbie


Hi! I'm beginning to learn programming via Python. I'm using the Windows
version along with the "24 Hours" book. Do you have any tips on learning
programming? I've searched the net for general programming tips and I've
found just a few. From what I've read, I should use a book (material), study
the code of others (copy? Make changes? Improvise?), and do lots of
practice. If this is correct, how do I go about this? For example, I can put
in 2-3 hours a day (more on the weekends). How should I use my time? Should
I use the book for an hour or so and then use the remaining time to code?
Should I look over existing code later after I've gone through some books
and gotten more knowledge? How should I use my practice sessions? Right now,
I'm merely going over my exercises and examples and making changes to them
(incorporating what I know; sorta like improvising). Is this ok? Thanks!

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



From kalle@gnupung.net  Mon May 14 15:31:43 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Mon, 14 May 2001 16:31:43 +0200
Subject: [Tutor] Linux help required
In-Reply-To: <002c01c0dc0e$3de75ec0$c9f763d8@gibbs05>; from gibbs05@flash.net on Sun, May 13, 2001 at 07:38:29PM -0500
References: <20010514012055.B653@apone.network.loc> <200105132347.f4DNlSI09436@dsl092-074-184.bos1.dsl.speakeasy.net> <20010514015744.B28928@father> <002c01c0dc0e$3de75ec0$c9f763d8@gibbs05>
Message-ID: <20010514163143.A32029@father>

Sez Harry Kattz:
[unzip in non-free]
> Isn't the zipfile module in Python free?  Couldn't you sidestep the issue by
> writing your own 'unzip' utility in Python?

Yes, you might be right.  But it still seems weird.  I'll do some research
and see what I find.  At the moment, it doesn't even seem like unzip is in
nonfree anymore.  Arh arh, this is too much for me.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From arcege@speakeasy.net  Mon May 14 15:45:56 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Mon, 14 May 2001 10:45:56 -0400 (EDT)
Subject: [Tutor] Total Programming Newbie
In-Reply-To: <000a01c0dc7e$34c52820$de00a8c0@planhouse5> from "Rob Andrews" at May 14, 2001 09:00:16 AM
Message-ID: <200105141445.f4EEjuY10536@dsl092-074-184.bos1.dsl.speakeasy.net>

Rob Andrews wrote
> You seem to have the right idea. Keep looking over the material in any books
> and tutorials you can find, play with the code of others, and make use of
> the Python Tutor email list by looking at the archives and asking questions
> on the list here.
> 
> It's not necessary to wait until after you feel like you've mastered any
> given book before spending some time coding. Try and write any scripts you
> can now, and as you piece them together, you can use the books/tutorials for
> ideas and to help figure out how to do whatever it is you're trying at the
> moment.
> 
> Rob

Good advice, Rob.

To this I'll add since I (and probably we) see it with most people new to
computers.  Don't be afraid of breaking something (software-wise, although
I've broken my keyboard with my skull at times...).  New programmers
are often too afraid of "doing it wrong" that they fail to learn why
things are wrong.  More often than not you'll learn far more by your
own failures than by other's examples and teachings.

Way back when (... 1200 baud was fast and TTYs had paper), I learned far
more trying to write an "add user" program by wiping the entire password
database than I would have if I had written it correctly the first time.

Don't worry if you have to reboot your machine because you created an
"endless loop" or something.  Just remember to "save early, save often",
to have fun, and to always have a boot disk(-ette) handy. *1/2-wink*

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From kromag@nsacom.net  Mon May 14 18:04:34 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Mon, 14 May 2001 10:04:34 -0700 (PDT)
Subject: [Tutor] Save me from this horrible kludge! (long)
Message-ID: <200105141704.f4EH4YA26792@pop.nsacom.net>

I have been dinking around with Flognat's AutoScrollbar.py. (I found it at: 
http://www.fukt.hk-r.se/~flognat/hacks/)

I basically want to use it to squirt a big image onto the screen, no big 
deal. However, I want only one instance of the program running at a time. I 
have solved this before by using a temporary file as a lock.

To wit:
----------------------------snip----------------------

import glob
import os
whoa= glob.glob('\tmp\holdit.lck')
if whoa == ['\tmp\holdit.lck']:
    print "locked! I'm quitting!n", 
else:
        lock_file=open('\tmp\holdit.lck','w')
        lock_file.close()

------------much is removed-------
        root.button=Button(root, text="Close", fg="red" 
command=root.quit).pack(side=LEFT, fill=X, expand=YES)
	root.mainloop()

	if root.quit:
            os.remove('\tmp\holdit.lck')

----------------------------snip----------------------

Now this works fine in a simple script with no classes. However you may see 
my problem when attempting to add this loop to Flognat's code below:


Momma said:

----------------------------snip----------------------

import sys
import string
import glob
import os
whoa=glob.glob('\tmp\holdit.lck')
if whoa ==['\tmp\holdit.lck']:
    print "Locked! I'm quitting!n",
else:
    lock_file=open('\tmp\holdit.lck','w')
    lock_file.close()

    from Tkinter import *
    class AutoScrollbar(Frame):
        def __init__(self, master, widget, widgcnf={}, sbcnf={}):
            Frame.__init__(self, master)
            self.pack(expand=YES, fill=BOTH)

            hsbcnf=vsbcnf=sbcnf
            vsbcnf['orient']='vertical'
            hsbcnf['orient']='horizontal'
            
            # Houses vertical scrollbar and widget
            self._upperframe=Frame(self)
            self._upperframe.pack(side=TOP, expand=YES, fill=BOTH)
            
            # Houses horizontal scrollbar and fill-out padding
            self._bottomframe=Frame(self)
            self._bottomframe.pack(side=BOTTOM, fill=X)

            self._widget=widget(self._upperframe, widgcnf)
            self._widget.pack(side=LEFT, expand=YES, fill=BOTH)
                
            self._vscrollbar=Scrollbar(self._upperframe, orient='vertical')
            self._vscrollbar.forget()
            self._widget['yscrollcommand'] = self._vscrollbar.set
            self._vscrollbar['command'] = self._widget.yview

            self._hscrollbar=Scrollbar(self._bottomframe, orient='horizontal')
            self._hscrollbar.forget()
            self._widget['xscrollcommand'] = self._hscrollbar.set
            self._hscrollbar['command'] = self._widget.xview

            self._fillout=Frame(self._bottomframe, width=self._vscrollbar
['width'])
            self._fillout.forget()

            # to avoid race-conditions I fear can happen..
            self._resizing=0
            self._vscroll = self._hscroll = self._fill = 0

        def getBBox(self):
            "Return the bounding box of the data contained in the widget"
            pass 
            
        def refresh(self, event=None):
            if self._resizing:
                print "Hey I am working"
                return

            self._resizing=1

            x1, y1, x2, y2=self.getBBox()
            
            # I am lazy.. lets remove the scrollbars..
            if self._hscroll:
                self._hscrollbar.forget()
                self._hscroll=0
                
            if self._vscroll:
                self._vscrollbar.forget()
                self._vscroll=0
            
            if self._fill:
                self._fillout.forget()
                self._fill=0

            cheight=string.atoi(self._widget['height'])
            cwidth=string.atoi(self._widget['width'])

            while (cwidth < x2 and not self._hscroll) 
                  or (cheight < y2 and not self._vscroll):

                if cwidth < x2 and not self._hscroll:
                    self._hscrollbar.pack(side=LEFT, fill=X, expand=YES)
                    self._hscroll=1

                if cheight < y2 and not self._vscroll:
                    self._vscrollbar.pack(side=RIGHT, fill=Y)
                    self._vscroll=1
                    
                cheight=string.atoi(self._widget['height'])
                cwidth=string.atoi(self._widget['width'])

            if self._hscrollbar and self._vscrollbar:
                self._fill=1
                self._fillout.pack(side=RIGHT, expand=NO)

            self._resizing=1

    class CanvasWithAutoScroll(AutoScrollbar):
        def __init__(self, master=None, padding=10, canvascnf={}, sbcnf={}):
            AutoScrollbar.__init__(self, master, Canvas, canvascnf, sbcnf)
            self.padding=padding
            self.canvas=self._widget
            
        def getBBox(self):
            bbox=self.canvas.bbox("all")
            if bbox==None:
                #empty
                x1 = y1 = -self.padding
                x2 = y2 = self.padding
            else:
                x1, y1, x2, y2 = bbox
                x1 = x1 - self.padding
                y1 = y1 - self.padding
                x2 = x2 + self.padding
                y2 = y2 + self.padding

            return x1, y1, x2, y2

        def refresh(self, event=None):
            self.canvas.configure(scrollregion=self.getBBox())
            AutoScrollbar.refresh(self, event=None)

    class TestApp(Frame):
        def __init__(self, master=None):
            Frame.__init__(self, master)
            self._dimensions=range(1000)

            self.cnv=CanvasWithAutoScroll(self,10, {'bg' : 'white'})
            self.canvas=self.cnv.canvas

            # Begin Horrible Kludge
            # import the image
            self.photo=PhotoImage(file="\\netthang\gif.gif")
            self.canvas.create_image(10,10, image=self.photo, anchor=NW)
            self.cnv.refresh()
            btn1=Button(self, text='Quit', command=self.quit)
            btn1.pack(side=BOTTOM, fill=X )
            self.pack()
            
    def test():
        testapp=TestApp()
        testapp.pack(expand=YES, fill=BOTH)
        testapp.mainloop()
        
    if __name__=='__main__':
        test()
    
----------------------------snip----------------------

There are two things I would like to know:

Is there a better way to detect if a program is already running? I don't like 
the lockfile as it may not be easy to clean up if the program terminates 
abnormally!

Is there a way to pack more than two commands into the "command=foo" argument 
in the Tkinter button?

I fully admit that I don't know what I am doing here, Usually I learn best by 
mangling someone elses code until it works like I want it to. I have read 
Chapter 6 of Learning Python to tatters! :-)

Thanks!

d




From scott@zenplex.com  Mon May 14 16:11:07 2001
From: scott@zenplex.com (Scott Ralph Comboni)
Date: 14 May 2001 11:11:07 -0400
Subject: [Tutor] PyXML Help?
Message-ID: <989853068.2645.0.camel@scoot>

I have a need to work with XML files mainly parsing.  Can anybody point
me to some examples on the web above and beyond the HowTO?
Thanks Scott


-- 
http://www.zenplex.com
http://www.zenplex.org
http://tambora.zenplex.org



From scott@zenplex.com  Mon May 14 16:11:16 2001
From: scott@zenplex.com (Scott Ralph Comboni)
Date: 14 May 2001 11:11:16 -0400
Subject: [Tutor] PyXML Help?
Message-ID: <989853080.2644.1.camel@scoot>

I have a need to work with XML files mainly parsing.  Can anybody point
me to some examples on the web above and beyond the HowTO?
Thanks Scott


-- 
http://www.zenplex.com
http://www.zenplex.org
http://tambora.zenplex.org



From scott@zenplex.com  Mon May 14 16:12:37 2001
From: scott@zenplex.com (Scott Ralph Comboni)
Date: 14 May 2001 11:12:37 -0400
Subject: [Tutor] PyXML Help?
Message-ID: <989853159.2643.2.camel@scoot>

I have a need to work with XML files mainly parsing.  Can anybody point
me to some examples on the web above and beyond the HowTO?
Thanks Scott


-- 
    http://www.zenplex.com
http://www.zenplex.org
http://tambora.zenplex.org



From markah@tality.com  Mon May 14 16:45:58 2001
From: markah@tality.com (Mark A. Hernandez)
Date: Mon, 14 May 2001 11:45:58 -0400
Subject: [Tutor] build erors
Message-ID: <3AFFFDB6.885BE18C@tality.com>

--------------533BDB4792A3F3A47AB3E214
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Heelo All,
 I hope someone can help here is my problem:

i am trying to install python 2.1 on Sun OS 5.7
Here is the screen output of configure followed by the errors after
"make":


./configure --prefix=/user/markah/Python
creating cache ./config.cache
checking MACHDEP... sunos5
checking for --without-gcc... no
checking for --with-cxx=<compiler>... no
checking for c++... c++
checking whether the C++ compiler (c++  ) works... yes
checking whether the C++ compiler (c++  ) is a cross-compiler... no
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for Cygwin environment... no
checking for mingw32 environment... no
checking for executable suffix... no
checking for --with-suffix...
checking LIBRARY... libpython$(VERSION).a
checking LINKCC... $(PURIFY) $(CC)
checking LDLIBRARY... libpython$(VERSION).a
checking for ranlib... ranlib
checking for ar... ar
checking for a BSD compatible install... ./install-sh -c
checking how to run the C preprocessor... gcc -E
checking for AIX... no
checking for minix/config.h... no
checking whether gcc accepts -OPT:Olimit=0... no
checking whether gcc accepts -Olimit 1500... no
checking for ANSI C header files... yes
checking for dlfcn.h... yes
checking for fcntl.h... yes
checking for limits.h... yes
checking for locale.h... yes
checking for ncurses.h... no
checking for poll.h... yes
checking for pthread.h... yes
checking for signal.h... yes
checking for stdarg.h... yes
checking for stddef.h... yes
checking for stdlib.h... yes
checking for thread.h... yes
checking for unistd.h... yes
checking for utime.h... yes
checking for termios.h... yes
checking for sys/audioio.h... yes
checking for sys/file.h... no
checking for sys/lock.h... yes
checking for db_185.h... no
checking for db.h... no
checking for sys/param.h... no
checking for sys/select.h... yes
checking for sys/socket.h... yes
checking for sys/time.h... yes
checking for sys/times.h... yes
checking for sys/un.h... yes
checking for sys/utsname.h... yes
checking for sys/wait.h... yes
checking for pty.h... no
checking for libutil.h... no
checking for ndbm.h... yes
checking for db1/ndbm.h... no
checking for gdbm/ndbm.h... no
checking for dirent.h that defines DIR... no
checking for sys/ndir.h that defines DIR... no
checking for sys/dir.h that defines DIR... no
checking for ndir.h that defines DIR... no
checking for opendir in -lx... no
checking for clock_t in time.h... yes
checking for mode_t... yes
checking for off_t... yes
checking for pid_t... yes
checking return type of signal handlers... int
checking for size_t... yes
checking for uid_t in sys/types.h... yes
checking size of int... 4
checking size of long... 4
checking size of void *... 4
checking size of char... 1
checking size of short... 2
checking size of float... 4
checking size of double... 8
checking size of fpos_t... 4
checking for long long support... yes
checking size of long long... 8
checking for uintptr_t support... no
checking size of off_t... 0
checking whether to enable large file support... no
checking size of time_t... 0
checking for pthread_t... no
checking for --with-next-framework... no
checking for --with-dyld... no
checking SO... .so
checking LDSHARED... $(CC) -shared
checking CCSHARED... -fPIC
checking LINKFORSHARED...
checking CFLAGSFORSHARED...
checking for dlopen in -ldl... yes
checking for shl_load in -ldld... no
checking for --with-pydebug... no
checking for t_open in -lnsl... yes
checking for socket in -lsocket... yes
checking for --with-libs... no
checking for --with-signal-module... yes
checking for --with-dec-threads... no
checking for --with-threads... yes
checking for mach/cthreads.h... no
checking for --with-pth... no
checking for pthread_create in -lpthread... yes
checking for usconfig in -lmpc... no
checking for thr_create in -lthread... yes
checking for --with-cycle-gc... yes
checking for --with-pymalloc... no
checking for --with-wctype-functions... no
checking for --with-sgi-dl... no
checking for --with-dl-dld... no
checking for dlopen... yes
checking DYNLOADFILE... dynload_shlib.o
checking for alarm... yes
checking for chown... yes
checking for clock... yes
checking for confstr... yes
checking for ctermid... yes
checking for ctermid_r... yes
checking for execv... yes
checking for flock... no
checking for fork... yes
checking for fsync... yes
checking for fdatasync... no
checking for fpathconf... yes
checking for ftime... yes
checking for ftruncate... yes
checking for getgroups... yes
checking for getlogin... yes
checking for getpeername... yes
checking for getpid... yes
checking for getpwent... yes
checking for getwd... yes
checking for kill... yes
checking for link... yes
checking for lstat... yes
checking for mkfifo... yes
checking for mktime... yes
checking for mremap... no
checking for nice... yes
checking for pathconf... yes
checking for pause... yes
checking for plock... yes
checking for poll... yes
checking for pthread_init... no
checking for putenv... yes
checking for readlink... yes
checking for select... yes
checking for setegid... yes
checking for seteuid... yes
checking for setgid... yes
checking for setlocale... yes
checking for setregid... yes
checking for setreuid... yes
checking for setsid... yes
checking for setpgid... yes
checking for setuid... yes
checking for setvbuf... yes
checking for sigaction... yes
checking for siginterrupt... yes
checking for sigrelse... yes
checking for strftime... yes
checking for strptime... yes
checking for symlink... yes
checking for sysconf... yes
checking for tcgetpgrp... yes
checking for tcsetpgrp... yes
checking for tempnam... yes
checking for timegm... no
checking for times... yes
checking for tmpfile... yes
checking for tmpnam... yes
checking for tmpnam_r... yes
checking for truncate... yes
checking for uname... yes
checking for waitpid... yes
checking for _getpty... no
checking for openpty... no
checking for openpty in -lutil... no
checking for forkpty... no
checking for forkpty in -lutil... no
checking for fseek64... no
checking for fseeko... yes
checking for fstatvfs... yes
checking for ftell64... no
checking for ftello... yes
checking for statvfs... yes
checking for dup2... yes
checking for getcwd... yes
checking for strdup... yes
checking for strerror... yes
checking for memmove... yes
checking for getpgrp... yes
checking for setpgrp... yes
checking for gettimeofday... yes
checking whether time.h and sys/time.h may both be included... no
checking whether struct tm is in sys/time.h or time.h... sys/time.h
checking for tm_zone in struct tm... no
checking for tzname... no
checking for time.h that defines altzone... no
checking whether sys/select.h and sys/time.h may both be included... no
checking whether char is unsigned... no
checking for working const... yes
checking for working volatile... yes
checking for working signed char... yes
checking for prototypes... yes
checking for variable length prototypes and stdarg.h... yes
checking for bad exec* prototypes... yes
checking for bad static forward... no
checking whether va_list is an array... no
checking for gethostbyname_r... yes
checking gethostbyname_r with 6 args... no
checking gethostbyname_r with 5 args... no
checking gethostbyname_r with 3 args... no
checking for __fpu_control... no
checking for __fpu_control in -lieee... no
checking for --with-fpectl... no
checking for --with-libm=STRING... default LIBM="-lm"
checking for --with-libc=STRING... default LIBC=""
checking for hypot... yes
checking what malloc(0) returns... nonnull
checking for wchar.h... yes
checking for usable wchar_t... no
checking whether byte ordering is bigendian... yes
checking whether right shift extends the sign bit... yes
checking for getc_unlocked() and friends... yes
checking for socklen_t... yes
checking for build directories... done
updating cache ./config.cache
creating ./config.status
creating Makefile.pre
creating Modules/Setup.config
creating config.h
creating Setup
creating Setup.local
creating Makefile


Make errors:

make
gcc -c -g -O2 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H
-o Modules/python.o Modules/python.c
In file included from
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2/include/time.h:90,
                 from /usr/include/sys/time.h:405,
                 from /usr/include/sys/select.h:17,
                 from
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2/include/sys/types.h:278,

                 from /usr/include/sys/wait.h:20,
                 from
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2/include/stdlib.h:17,
                 from Include/Python.h:50,
                 from Modules/python.c:3:
/usr/include/sys/siginfo.h:74: parse error before `pthread_attr_t'
/usr/include/sys/siginfo.h:74: warning: no semicolon at end of struct or
union
/usr/include/sys/siginfo.h:76: parse error before `}'
*** Error code 1
make: Fatal error: Command failed for target `Modules/python.o'


I hope this helps

Thanks
Mark

--
Mark Hernandez                          email: markah@tality.com
Tality, LP                              Phone: 919.481.6819
Digital IC                              FAX:   919.380.3903
200 Regency Forest Drive
Suite 260
Cary, NC 27511



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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Heelo All,
<br>&nbsp;I hope someone can help here is my problem:
<p>i am trying to install python 2.1 on Sun OS 5.7
<br>Here is the screen output of configure followed by the errors after
"make":
<br>&nbsp;
<p>./configure --prefix=/user/markah/Python
<br>creating cache ./config.cache
<br>checking MACHDEP... sunos5
<br>checking for --without-gcc... no
<br>checking for --with-cxx=&lt;compiler>... no
<br>checking for c++... c++
<br>checking whether the C++ compiler (c++&nbsp; ) works... yes
<br>checking whether the C++ compiler (c++&nbsp; ) is a cross-compiler...
no
<br>checking for gcc... gcc
<br>checking whether the C compiler (gcc&nbsp; ) works... yes
<br>checking whether the C compiler (gcc&nbsp; ) is a cross-compiler...
no
<br>checking whether we are using GNU C... yes
<br>checking whether gcc accepts -g... yes
<br>checking for Cygwin environment... no
<br>checking for mingw32 environment... no
<br>checking for executable suffix... no
<br>checking for --with-suffix...
<br>checking LIBRARY... libpython$(VERSION).a
<br>checking LINKCC... $(PURIFY) $(CC)
<br>checking LDLIBRARY... libpython$(VERSION).a
<br>checking for ranlib... ranlib
<br>checking for ar... ar
<br>checking for a BSD compatible install... ./install-sh -c
<br>checking how to run the C preprocessor... gcc -E
<br>checking for AIX... no
<br>checking for minix/config.h... no
<br>checking whether gcc accepts -OPT:Olimit=0... no
<br>checking whether gcc accepts -Olimit 1500... no
<br>checking for ANSI C header files... yes
<br>checking for dlfcn.h... yes
<br>checking for fcntl.h... yes
<br>checking for limits.h... yes
<br>checking for locale.h... yes
<br>checking for ncurses.h... no
<br>checking for poll.h... yes
<br>checking for pthread.h... yes
<br>checking for signal.h... yes
<br>checking for stdarg.h... yes
<br>checking for stddef.h... yes
<br>checking for stdlib.h... yes
<br>checking for thread.h... yes
<br>checking for unistd.h... yes
<br>checking for utime.h... yes
<br>checking for termios.h... yes
<br>checking for sys/audioio.h... yes
<br>checking for sys/file.h... no
<br>checking for sys/lock.h... yes
<br>checking for db_185.h... no
<br>checking for db.h... no
<br>checking for sys/param.h... no
<br>checking for sys/select.h... yes
<br>checking for sys/socket.h... yes
<br>checking for sys/time.h... yes
<br>checking for sys/times.h... yes
<br>checking for sys/un.h... yes
<br>checking for sys/utsname.h... yes
<br>checking for sys/wait.h... yes
<br>checking for pty.h... no
<br>checking for libutil.h... no
<br>checking for ndbm.h... yes
<br>checking for db1/ndbm.h... no
<br>checking for gdbm/ndbm.h... no
<br>checking for dirent.h that defines DIR... no
<br>checking for sys/ndir.h that defines DIR... no
<br>checking for sys/dir.h that defines DIR... no
<br>checking for ndir.h that defines DIR... no
<br>checking for opendir in -lx... no
<br>checking for clock_t in time.h... yes
<br>checking for mode_t... yes
<br>checking for off_t... yes
<br>checking for pid_t... yes
<br>checking return type of signal handlers... int
<br>checking for size_t... yes
<br>checking for uid_t in sys/types.h... yes
<br>checking size of int... 4
<br>checking size of long... 4
<br>checking size of void *... 4
<br>checking size of char... 1
<br>checking size of short... 2
<br>checking size of float... 4
<br>checking size of double... 8
<br>checking size of fpos_t... 4
<br>checking for long long support... yes
<br>checking size of long long... 8
<br>checking for uintptr_t support... no
<br>checking size of off_t... 0
<br>checking whether to enable large file support... no
<br>checking size of time_t... 0
<br>checking for pthread_t... no
<br>checking for --with-next-framework... no
<br>checking for --with-dyld... no
<br>checking SO... .so
<br>checking LDSHARED... $(CC) -shared
<br>checking CCSHARED... -fPIC
<br>checking LINKFORSHARED...
<br>checking CFLAGSFORSHARED...
<br>checking for dlopen in -ldl... yes
<br>checking for shl_load in -ldld... no
<br>checking for --with-pydebug... no
<br>checking for t_open in -lnsl... yes
<br>checking for socket in -lsocket... yes
<br>checking for --with-libs... no
<br>checking for --with-signal-module... yes
<br>checking for --with-dec-threads... no
<br>checking for --with-threads... yes
<br>checking for mach/cthreads.h... no
<br>checking for --with-pth... no
<br>checking for pthread_create in -lpthread... yes
<br>checking for usconfig in -lmpc... no
<br>checking for thr_create in -lthread... yes
<br>checking for --with-cycle-gc... yes
<br>checking for --with-pymalloc... no
<br>checking for --with-wctype-functions... no
<br>checking for --with-sgi-dl... no
<br>checking for --with-dl-dld... no
<br>checking for dlopen... yes
<br>checking DYNLOADFILE... dynload_shlib.o
<br>checking for alarm... yes
<br>checking for chown... yes
<br>checking for clock... yes
<br>checking for confstr... yes
<br>checking for ctermid... yes
<br>checking for ctermid_r... yes
<br>checking for execv... yes
<br>checking for flock... no
<br>checking for fork... yes
<br>checking for fsync... yes
<br>checking for fdatasync... no
<br>checking for fpathconf... yes
<br>checking for ftime... yes
<br>checking for ftruncate... yes
<br>checking for getgroups... yes
<br>checking for getlogin... yes
<br>checking for getpeername... yes
<br>checking for getpid... yes
<br>checking for getpwent... yes
<br>checking for getwd... yes
<br>checking for kill... yes
<br>checking for link... yes
<br>checking for lstat... yes
<br>checking for mkfifo... yes
<br>checking for mktime... yes
<br>checking for mremap... no
<br>checking for nice... yes
<br>checking for pathconf... yes
<br>checking for pause... yes
<br>checking for plock... yes
<br>checking for poll... yes
<br>checking for pthread_init... no
<br>checking for putenv... yes
<br>checking for readlink... yes
<br>checking for select... yes
<br>checking for setegid... yes
<br>checking for seteuid... yes
<br>checking for setgid... yes
<br>checking for setlocale... yes
<br>checking for setregid... yes
<br>checking for setreuid... yes
<br>checking for setsid... yes
<br>checking for setpgid... yes
<br>checking for setuid... yes
<br>checking for setvbuf... yes
<br>checking for sigaction... yes
<br>checking for siginterrupt... yes
<br>checking for sigrelse... yes
<br>checking for strftime... yes
<br>checking for strptime... yes
<br>checking for symlink... yes
<br>checking for sysconf... yes
<br>checking for tcgetpgrp... yes
<br>checking for tcsetpgrp... yes
<br>checking for tempnam... yes
<br>checking for timegm... no
<br>checking for times... yes
<br>checking for tmpfile... yes
<br>checking for tmpnam... yes
<br>checking for tmpnam_r... yes
<br>checking for truncate... yes
<br>checking for uname... yes
<br>checking for waitpid... yes
<br>checking for _getpty... no
<br>checking for openpty... no
<br>checking for openpty in -lutil... no
<br>checking for forkpty... no
<br>checking for forkpty in -lutil... no
<br>checking for fseek64... no
<br>checking for fseeko... yes
<br>checking for fstatvfs... yes
<br>checking for ftell64... no
<br>checking for ftello... yes
<br>checking for statvfs... yes
<br>checking for dup2... yes
<br>checking for getcwd... yes
<br>checking for strdup... yes
<br>checking for strerror... yes
<br>checking for memmove... yes
<br>checking for getpgrp... yes
<br>checking for setpgrp... yes
<br>checking for gettimeofday... yes
<br>checking whether time.h and sys/time.h may both be included... no
<br>checking whether struct tm is in sys/time.h or time.h... sys/time.h
<br>checking for tm_zone in struct tm... no
<br>checking for tzname... no
<br>checking for time.h that defines altzone... no
<br>checking whether sys/select.h and sys/time.h may both be included...
no
<br>checking whether char is unsigned... no
<br>checking for working const... yes
<br>checking for working volatile... yes
<br>checking for working signed char... yes
<br>checking for prototypes... yes
<br>checking for variable length prototypes and stdarg.h... yes
<br>checking for bad exec* prototypes... yes
<br>checking for bad static forward... no
<br>checking whether va_list is an array... no
<br>checking for gethostbyname_r... yes
<br>checking gethostbyname_r with 6 args... no
<br>checking gethostbyname_r with 5 args... no
<br>checking gethostbyname_r with 3 args... no
<br>checking for __fpu_control... no
<br>checking for __fpu_control in -lieee... no
<br>checking for --with-fpectl... no
<br>checking for --with-libm=STRING... default LIBM="-lm"
<br>checking for --with-libc=STRING... default LIBC=""
<br>checking for hypot... yes
<br>checking what malloc(0) returns... nonnull
<br>checking for wchar.h... yes
<br>checking for usable wchar_t... no
<br>checking whether byte ordering is bigendian... yes
<br>checking whether right shift extends the sign bit... yes
<br>checking for getc_unlocked() and friends... yes
<br>checking for socklen_t... yes
<br>checking for build directories... done
<br>updating cache ./config.cache
<br>creating ./config.status
<br>creating Makefile.pre
<br>creating Modules/Setup.config
<br>creating config.h
<br>creating Setup
<br>creating Setup.local
<br>creating Makefile
<br>&nbsp;
<p>Make errors:
<p>make
<br>gcc -c -g -O2 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H&nbsp;
-o Modules/python.o Modules/python.c
<br>In file included from /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2/include/time.h:90,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from /usr/include/sys/time.h:405,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from /usr/include/sys/select.h:17,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2/include/sys/types.h:278,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from /usr/include/sys/wait.h:20,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2/include/stdlib.h:17,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from Include/Python.h:50,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from Modules/python.c:3:
<br>/usr/include/sys/siginfo.h:74: parse error before `pthread_attr_t'
<br>/usr/include/sys/siginfo.h:74: warning: no semicolon at end of struct
or union
<br>/usr/include/sys/siginfo.h:76: parse error before `}'
<br>*** Error code 1
<br>make: Fatal error: Command failed for target `Modules/python.o'
<br>&nbsp;
<p>I hope this helps
<p>Thanks
<br>Mark
<pre>--&nbsp;
Mark Hernandez&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; email: markah@tality.com
Tality, LP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Phone: 919.481.6819
Digital IC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FAX:&nbsp;&nbsp; 919.380.3903
200 Regency Forest Drive&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Suite 260&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Cary, NC 27511</pre>
&nbsp;</html>

--------------533BDB4792A3F3A47AB3E214--



From alan.gauld@bt.com  Mon May 14 16:59:48 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 May 2001 16:59:48 +0100
Subject: [Tutor] Total Programming Newbie
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D76B@mbtlipnt02.btlabs.bt.co.uk>

> ... From what I've read, I should use a book, study
> the code of others (copy? Make changes? Improvise?), 
> and do lots of practice. 

That's about it, yes. Personally I find the best way to 
take the examples in the book(s) and extend them - initially 
just change a value or two, print a message somewhere, 
then as you learn more make the changes bigger. Try to 
make the programs interactive, or more reliable by checking 
for error conditions etc...

> in 2-3 hours a day (more on the weekends)

2-3 hours hands on is probably about right. Going too fast 
can be a bad thing. You need time to let the underlying concepts 
sink in.

> I use the book for an hour or so and then use the remaining 
> time to code?

Yes thats probably OK. Personally I read a bit, code a bit, 
read a bit more, code a bit... Let your curiosity take over, 
if you wonder "what if" try it... Don't get bogged down if 
something doesn't work after 2 or 3 attempts, move on and 
come back to the problem later.

> I'm merely going over my exercises and examples and making 
> changes to them (incorporating what I know; sorta like 
> improvising). Is this ok?

Yes. IMHO its the berst way of doing it.
I also like to see alternative explanations. Since you have 
Ivan's book try taking a look at the equivalent topics on 
my web tutor for a different way of saying the same thing
(and some other programming ideas). It will also show you 
the same concepts in 2 other languages, which I personally 
believe helps reinforce the underlying principles.

http://www.crosswinds.net/~agauld

HTH,

Alan G


From alan.gauld@bt.com  Mon May 14 17:07:05 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 May 2001 17:07:05 +0100
Subject: [Tutor] Save me from this horrible kludge! (long)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D76C@mbtlipnt02.btlabs.bt.co.uk>

> deal. However, I want only one instance of the program 
> running at a time. I have solved this before by using 
> a temporary file as a lock.

Thats probably as good a way as any! Depending on your 
platform there are several issues/methods of doing this.

Windows (16 bit) makes it easy through the API but 32 
bit windows makes it much harder. You basically have to 
search for a program of the same name...

In Unix its harder still since more than one user might 
be on the machine and you might want to run one copy per 
user - in which case your lock-file is the easiest 
solution!

This was discussed on comp.lang.python newsgroup recently, 
you  might want to do a search on the archives (at Google 
say)

> the lockfile as it may not be easy to clean up if the program 
> terminates abnormally!

That's what try/finally is for ;-)
Not bulletproof but pretty reliable!

Alan G


From lsloan@umich.edu  Mon May 14 18:23:01 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Mon, 14 May 2001 13:23:01 -0400
Subject: [Tutor] Save me from this horrible kludge! (long)
In-Reply-To: Your message of "Mon, 14 May 2001 10:04:34 PDT."
 <200105141704.f4EH4YA26792@pop.nsacom.net>
Message-ID: <200105141723.NAA22155@birds.us.itd.umich.edu>

kromag@nsacom.net wrote:
> Is there a better way to detect if a program is already running? I
> don't like the lockfile as it may not be easy to clean up if the
> program terminates abnormally!

Depending on how it terminates abnormally, couldn't you put
"everything" inside a "try" and catch the terminating exception with
"except"?  In the "except" part, you could then delete the lockfile.

I don't think that the lockfile is such a bad idea.  Depending on your
OS, you could make it better, though.  If you're running this under
UNIX, write the current process ID number (from os.getpid(), also
available under Windows) to the lockfile when you make it.  When you
start a another copy of your program (a new process), if it finds a
lockfile, it should read the PID from that file and see if that process
is still running (and probably if the process has the correct name).
If it's not running, make a new lockfile, otherwise, complain and die.

I don't know how to find out if a process is running with Python,
though.  Under UNIX, you may be able to use os.kill() or os.waitpid().
waitpid() says it's only for chilren of the current process, though.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From bsass@freenet.edmonton.ab.ca  Mon May 14 19:05:51 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Mon, 14 May 2001 12:05:51 -0600 (MDT)
Subject: [Tutor] Linux help required
In-Reply-To: <20010514112336.A2311@pino.selwerd.nl>
Message-ID: <Pine.LNX.4.33.0105141123390.956-100000@bms>

On Mon, 14 May 2001, Remco Gerlich wrote:

> On  0, alan.gauld@bt.com wrote:
> > > | that the zip file can't be opened by gunzip under Linux. I have
> >
> > Thanks to Deirdre for pointing out that gunzip only works on
> > single files, I hadn't realised that - I've only used in on
> > Unix up til now where tgz is the norm...
>
> It's exactly the same on Unix and Linux. .tgz even means tar/GNU zip.
>
> A .tgz is usually called .tar.gz. That is, you make an archive out of a
> bunch of files, the .tar, then you gzip that, and it's called .tar.gz,
> sometimes abbreviated .tgz for people using DOS or similar systems.
>
> That's two commands to make a compress archive, although GNU tar has an
> option to combine the two, so it's one command again.

I don't really want to muddy the waters, but this should be
mentioned...

"tar -cz" vs "tar | gzip"
I recall hearing about a problem between unix variants where the
result of the GNU tar's combined command could not be processed by
some non-GNU tar + gz commands.  So, two command versions were the
recommended way of making a portable tarball.

It is hearsay, and may be a historical footnote, but it has me doing:
"tar -cz" --> .tgz	and	"tar | gz" --> .tar.gz
just so's I have a clue if something strange happens with tarballs.


<...>
> Most distributions do have zip/unzip commands. Someone was talking about
> Debian, maybe it's those pedants whining about 'Free' again ;-)
>
> gzip is GNU zip, or as Free as it gets, anyway.

There is no freedom in Terms and Conditions.


> PS bzip2 is a lot better, of course. <grin, duck and run>

just look'n for trouble today, eh :)

.bz2 is nice for archiving, where space is most important; but sucks
for downloads 'cause it takes longer to un-compress the savings than
it does to download a not so compressed scheme -- very noticeable on a
slow system.


- Bruce



From deirdre@deirdre.net  Mon May 14 19:08:08 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Mon, 14 May 2001 11:08:08 -0700
Subject: [Tutor] Manuals/books
In-Reply-To: <20010514130438.C2438@pino.selwerd.nl>
References: <Pine.LNX.4.33.0105140537130.880-100000@hermit.erie.net>
 <20010514130438.C2438@pino.selwerd.nl>
Message-ID: <a05100e0cb725cd33727d@[10.0.1.21]>

>On  0, Hermit <hermit@erie.net> wrote:
>  > I have been a fan of the O'Reilly books for some time now, but also noted
>>  "Learn to Program Using Python" by Alan Gauld.  I get the impression that
>>  Mr. Gauld is the local Python guru around here.
>
>He's one of many Python experts around here. I'd call Tim Peters the guru :)

There's several experts, but Tim's our resident guru, except when, on 
rare occasions, Guido posts.

Somehow, speaking of which, I was just insulted by a recruiter from 
Google the other day. They're looking for people with Linux, python, 
and search engine experience, but had, said the recruiter, passed 
over my resume. I said, "I have Linux experience, I have python 
experience and search engine experience. In fact, I have search 
engine experience IN python ON Linux. In Mountain View even. How much 
more of a match could you want?"

The recruiter said that the VP of Engineering felt I wasn't a match 
because my undergraduate field wasn't in one related to computers, 
but my MS in CS (in progress) is. Naturally, the fact that a 
regionally-accredited MS program had felt my background was 
sufficient wasn't a factor....

Idiots.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From r.b.rigilink@chello.nl  Mon May 14 19:45:40 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Mon, 14 May 2001 20:45:40 +0200
Subject: [Tutor] Total Programming Newbie
References: <6D19AB695BA8D311A8420008C7CF285A020A8CA3@trgmail>
Message-ID: <3B0027D4.2D2C8412@chello.nl>

Anthony Beaman wrote:
> 
> Hi! I'm beginning to learn programming via Python. I'm using the Windows
> version along with the "24 Hours" book. Do you have any tips on learning
> programming? I've searched the net for general programming tips and I've
> found just a few. From what I've read, I should use a book (material), study
> the code of others (copy? Make changes? Improvise?), and do lots of
> practice. If this is correct, how do I go about this? For example, I can put
> in 2-3 hours a day (more on the weekends). How should I use my time? Should
> I use the book for an hour or so and then use the remaining time to code?
> Should I look over existing code later after I've gone through some books
> and gotten more knowledge? How should I use my practice sessions? Right now,
> I'm merely going over my exercises and examples and making changes to them
> (incorporating what I know; sorta like improvising). Is this ok? Thanks!
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Hi Anthony,

Welcome, 

As others have indicated you have started of on the right track, and
off-hand I can't think of anything in paticular to suggest in addition
to what you're doing now. Just don't worry to much about setting
yourself a detailed agenda. If, in a couple of weeks you find you
haven't been carried away by some particular idea or problem or just by
the plain fun you're having, take a step back, and wonder why you're
doing this.

In stead, let me come back with a question to you. Why do you want to
learn to program?

Two reasons to ask that question.

1. I've recently subscribed to the tutor mailing list myself, mostly
because I'm interested in teaching Python. I've been programming myself
for 15+ years, 3 years in Python now, and for the past 2 years somebody
has been actually paying me to this. As a budding paedagogue with an
interest in CP4E (Guido's somewhat dormant Computer Programming for
Everybody initiative) I have a feeling that "why people would want to
program" tells me something important in how I should approach teaching
them. I've no idea yet _what_ it tells me though. Consider yourself my
first subject in an informal survey.

2. The other reason may be somewhat more to your benefit. I can imagine
that you have some particular applications in mind that you would want
to write. Maybe we can give you some practical pointers in the general
direction.

Some advice after all. 

Follow the comp.lang.python newsgroup. Noteworthy (and frequent) posters
to pay particular attention to are Tim Peters and Frederick Lundh for
quick practical advice on everything Pythonic and Alex Martelli for long
insightful musings on various aspects of object oriented programming.

The library reference is your friend. First use it to find solutions for
problems that you don't know how to solve. Later use it to find better
solutions for problems that you do know how to solve.

Try to get an understanding of the notion of namespaces and the way they
are related to dictionaries. Also try to understand the diffferences and
similarities between modules and class. You don't need these concepts
yet, just remember that they are important when you first run across
them.

Write difficult algorithms with pen and paper first. Don't be afraid to
make mistakes. If you have an idea you think coudn't possibly work, try
it anyway. Odds are you were right, but then you _know_ it doesn't work.
Remember the KISS priciple. Don't be afraid to start from scratch, even
if it means throwing away working code. 

If you're stuck, don't be afraid to ask. There is no such thing as a
stupid question.

And if you ever run across the following quote from Tim Peters

    "You write a great program, regardless of language, by redoing it
over & over & over & over, until your fingers bleed and your soul is
drained. But if you tell newbies that, they might decide to go off and
do something sensible, like bomb defusing<wink>"

simply ignore it.

Enjoy the ride,

Roeland
-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From phil.bertram@clear.net.nz  Mon May 14 21:08:59 2001
From: phil.bertram@clear.net.nz (Phil Bertram)
Date: Tue, 15 May 2001 08:08:59 +1200
Subject: [Tutor] Simplicity vs. Speed
Message-ID: <009f01c0dcb1$cf9aba80$d394a7cb@pf05nt.bayernz.co.nz>

This is a multi-part message in MIME format.

------=_NextPart_000_009C_01C0DD16.4BB18CC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

I have a program that tracks scores and the results from a sports =
competition. Points are given for people who pick the winning team.

The data is held classes that have attributes that are lists of lists of =
lists etc.

I did it this way because I imagined that it would be faster as I would =
only have to iterate through 10 items rather than 100=20

eg.=20

Week1 =3D ['Game1', ........ 'Game10']
Week2 =3D ['Game11',.........'Game20] etc etc

The above example is very simplified, data levels go 3 or 4 deep and so =
things sometimes become a little unclear.

I'm now thinking that it is better to keep data in just a single list =
and filter the list each time I need to do an operation.

eg

Games =3D ['Game1',..................'Game100']:
    for game in games:
        if game.week =3D=3D 'Week1':
            do something

Or would using the 'filter' function be more or less efficient ?

Would you suggest that a new programmer just keep things simple so as to =
get the code working bug free, and not worry at all about speed ?

With new speed demon 600 mHz +++ chips are speed issues important =
anymore ?

Phil B






------=_NextPart_000_009C_01C0DD16.4BB18CC0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR></HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi all,</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I have a program that tracks scores and the results =
from a=20
sports competition. Points are given for people who pick the winning=20
team.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The data is held classes that have attributes that=20
are&nbsp;lists of lists of lists etc.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I did it this way because I imagined that it would =
be faster=20
as I would only have to iterate through 10 items rather than=20
100</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>eg. </FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Week1 =3D ['Game1', ........ 'Game10']</FONT></DIV>
<DIV><FONT size=3D2>Week2 =3D ['Game11',.........'Game20] etc =
etc</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The above example is very simplified, data levels go =
3 or 4=20
deep and so things sometimes become a little unclear.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I'm now thinking that it is better to keep data in =
just a=20
single list and filter the list each time I need to do an=20
operation.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>eg</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Games =3D =
['Game1',..................'Game100']:</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; for game in games:</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if game.week =
=3D=3D=20
'Week1':</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; do=20
something</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Or would using the 'filter' function be more or less =
efficient=20
?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Would you suggest that a new programmer just keep =
things=20
simple so as to get the code working bug free, and not worry at all =
about speed=20
?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>With new speed demon 600 mHz +++ chips are speed =
issues=20
important anymore ?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Phil B</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_009C_01C0DD16.4BB18CC0--



From hermit@erie.net  Mon May 14 21:50:31 2001
From: hermit@erie.net (Hermit)
Date: Mon, 14 May 2001 16:50:31 -0400 (EDT)
Subject: [Tutor] Books/Thankyou!
Message-ID: <Pine.LNX.4.33.0105141643390.959-100000@hermit.erie.net>

Good evening -

I would like to take this opportunity to thank Remco, Rob, Alan, and
Dierdre for responding to my query regarding Python book recommendations.
I certainly appreciate the in-depth responses I received; indicative of
people willing to share their time and expertise, and in today's world
that is really refreshing.  I've been around computers for quite awhile
(about 14 years), and not all mailing lists are so friendly.  I will
purchase both books, Alan's and the O'Reilly's - over the years I
accumulated quite a collection, but they are invaluable for learning.

Again, thanks for your replies!

Regards,

Dick Williams




From arthur.watts@gbst.com  Mon May 14 23:05:02 2001
From: arthur.watts@gbst.com (Arthur Watts)
Date: Tue, 15 May 2001 08:05:02 +1000
Subject: [Tutor] Manuals/books
Message-ID: <1CDB101F0CB6D311882F0000F8063924036151C9@aquarius.bne.star.com.au>

Guys,

	Having read the initial enquiry from Hermit and replies from Alan,
Remco and Rob, I thought I'd throw my two cents worth in. 

	Over the last 18 or so months, I have purchased each of these books
:
	
	Teach Yourself Python in 24 Hours
	Learning Python
	Programming Python
	Python Essential Reference
	Core Python Programming
	Python Annotated Archives

	I admit that the sheer novelty of seeing new Python books on the
shelves may have promoted some of these purchases.  I also have an extensive
library of other programming / IT titles, so I like to think I can tell a
good book from one which has been cobbled together just to cash in on a
language's popularity (just browse thru some of the Java titles out there
today ...). Of the titles I have listed, my favourites are the Essential
Reference and Core Python Programming. Learning Python is also very well
written, but I tend to be of the 'quickly show me the principle and a short
example and I'll take it from here' breed, and the other two are very good
for this. Reading books is no substitute for writing code and internalising
the results for yourself (a lot of Python's subtleties aren't evident from
simply scanning someone else's code ..), but they do give you a good basis
to work from. I have been forced to revisit the theory in Mark Lutz's books
on a couple of occasions when my impatience has gotten me onto trouble with
my implementation of a Python construct .. 

	Regardless of which book you buy, it is unlikely to cover everything
you need. What I would like to see is a Python version of the Perl Cookbook.
This is a fantastic example of a book written for practical, real-world
tasks, and I know it's the most heavily borrowed of any of my books. Given
that Perl has 'more than one way to do something', whilst Python usually
streamlines this to a single solution, our Cookbook should be somewhat
smaller :} I'd like to see a significant section of it dedicated to SysAdmin
type tasks : automating manual tasks is a big part of my day-to-day work.
Python network programming is another area of interest, and I'm sure that
other people on the list could suggest areas they'd like to see covered.
Perhaps ours would *NOT* be smaller than the Perl version after all !

	Finally, get Active Python. It ships with electronic reference doco,
and you can either search for a term or scan the index to cross-reference
material from the Global Module Index, the Language reference and other
Python doco. This won't teach you how to write Python code, but it will
minimise the time you spend scanning thru books in search of that elusive
Python implementation of your favourite C / Perl / whatever function.  	

Regards,

Arthur

Arthur Watts
Software Engineer GBST Automation
Global Banking & Securities Transactions

Telephone + 61 7 3331 5555
mailto: arthur.watts@gbst.com
www.gbst.com




	 
	


From kalle@gnupung.net  Mon May 14 23:27:22 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Tue, 15 May 2001 00:27:22 +0200
Subject: [Tutor] build erors
In-Reply-To: <3AFFFDB6.885BE18C@tality.com>; from markah@tality.com on Mon, May 14, 2001 at 11:45:58AM -0400
References: <3AFFFDB6.885BE18C@tality.com>
Message-ID: <20010515002722.A371@apone.network.loc>

Sez Mark A. Hernandez:
> Heelo All,
>  I hope someone can help here is my problem:
> 
> i am trying to install python 2.1 on Sun OS 5.7
> Here is the screen output of configure followed by the errors after
> "make":
[snip]

I'm sorry, but I have no idea.  I think it would be a good idea to post this
to python-list@python.org, the main Python list.  There it will reach a
larger audience and hopefully someone there knows how to solve this problem.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From scarblac@pino.selwerd.nl  Mon May 14 23:49:27 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 15 May 2001 00:49:27 +0200
Subject: [Tutor] Simplicity vs. Speed
In-Reply-To: <009f01c0dcb1$cf9aba80$d394a7cb@pf05nt.bayernz.co.nz>; from phil.bertram@clear.net.nz on Tue, May 15, 2001 at 08:08:59AM +1200
References: <009f01c0dcb1$cf9aba80$d394a7cb@pf05nt.bayernz.co.nz>
Message-ID: <20010515004927.B3466@pino.selwerd.nl>

On  0, Phil Bertram <phil.bertram@clear.net.nz> wrote:
> Would you suggest that a new programmer just keep things simple so as to
> get the code working bug free, and not worry at all about speed ?

Programmers, even very experienced ones, have misguided intuitions about
where the bottlenecks in their programs are. Besides, sometimes you spent
ages optimizing the snot out of a program, until you decide you want to
redesign it completely, throwing all that work out of the window.

In my opinion, it should work like this in most cases:
- Make the simplest thing that could possibly work.
- *If* this turns out to be too slow, *find out what slows it down*.
- Try to find out a better algorithm.
- Repeat.

Only when you know your algorithm is optimal, and it's still too
slow to use, can you go looking for low level optimizations - but usually
that means finding out what uses most of the time (with the profiler) and
implementing that in C. Personally I've never needed to do this yet.

So worry about speed only once you know speed is a problem.

-- 
Remco Gerlich


From lha2@columbia.edu  Mon May 14 23:54:08 2001
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Mon, 14 May 2001 18:54:08 -0400
Subject: [Tutor] re: zip stuff
References: <E14zKbh-0006fT-00@mail.python.org>
Message-ID: <3B006210.C1130722@mail.verizon.net>

Can't remember whether the .zip question was from a Windows person or a
Linux person; I'm guessing it was a Windows person.

I try not to pirate since having grown up from my Apple ][+, and have
found a free zip program called "freezip", which is available on Tucows.
Not to be confused with "freezip!". Doesn't seem to have infected me
with any nasties (yet).

-LHA


From s349929@student.uq.edu.au  Tue May 15 00:26:39 2001
From: s349929@student.uq.edu.au (Suzanne Little)
Date: Tue, 15 May 2001 09:26:39 +1000 (GMT+1000)
Subject: [Tutor] setting environment variables in apache
Message-ID: <Pine.OSF.4.30.0105150917250.29497-100000@student.uq.edu.au>

Hello,

I'm still working on a problem that I posted here a few weeks back.
Briefly I can't import the MySQLdb module when the script is put on the
apache web server.
I'm pretty sure that the problem is setting my LD_LIBRARY_HOME path but
can't manage to do this for the server. At the end is the test script
I'm running to try and get the module to import correctly and the errors
I'm getting.

I know that it's using the right version of python (2.0) and that it's the
right module and the paths are correct. I can log onto the machine that's
running the server and import MySQLdb from a command line no problems.
According to the faqts site I'm setting the environment variables
correctly so I don't know what else to do.

How do I set the environment variable for the script in apache?

Thanks,
Suzanne

-----------------------------------------
#!/usr/local/bin/python2.0

def wisp():
    import os
    print "Content-Type: text/html"
    print
    print '<html>'
    os.environ['LD_LIBRARY_PATH'] = '/opt/local/lib:/opt/local/lib/mysql'
    print os.environ['LD_LIBRARY_PATH']
    print '<br>'
    import MySQLdb
    print dir(MySQLdb)
    print '<br>DONE'
    print '</html>'

if __name__ == '__main__':
    wisp()
----
Traceback (most recent call last):
  File
"/.../bootup3.py", line
17, in ?
    wisp()
  File
"/.../bootup3.py", line
11, in wisp
    import MySQLdb
  File "/usr/local/lib/python2.0/site-packages/MySQLdb.py", line 19, in ?
    import _mysql
ImportError: ld.so.1: /usr/local/bin/python2.0: fatal:
libmysqlclient.so.6: open failed: No such file or directory


--------------------------------------------------------------------------
"Contrariwise," continued Tweedledee, "If it was so, it might be; and if
it were so, it would be; but as it isn't, it ain't.  That's logic"
                             -Lewis Carroll
--------------------------------------------------------------------------




From r.b.rigilink@chello.nl  Tue May 15 00:52:45 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Tue, 15 May 2001 01:52:45 +0200
Subject: [Tutor] Simplicity vs. Speed
References: <009f01c0dcb1$cf9aba80$d394a7cb@pf05nt.bayernz.co.nz>
Message-ID: <3B006FCD.FA1124BE@chello.nl>

Hi Phil,

> Phil Bertram wrote:
> 
> Hi all,
> 
> I have a program that tracks scores and the results from a sports
> competition. Points are given for people who pick the winning team.
> 
> The data is held classes that have attributes that are lists of lists
> of lists etc.
> 
> I did it this way because I imagined that it would be faster as I
> would only have to iterate through 10 items rather than 100
> 
> eg.
> 
> Week1 = ['Game1', ........ 'Game10']
> Week2 = ['Game11',.........'Game20] etc etc
> 
> The above example is very simplified, data levels go 3 or 4 deep and
> so things sometimes become a little unclear.
> 
> I'm now thinking that it is better to keep data in just a single list
> and filter the list each time I need to do an operation.
> 
> eg
> 
> Games = ['Game1',..................'Game100']:
>     for game in games:
>         if game.week == 'Week1':
>             do something
> 
> Or would using the 'filter' function be more or less efficient ?
> 

I really don't know. I can guess, of course, but my guess is less
reliable than your measurement. 

>
> Would you suggest that a new programmer just keep things simple so as
> to get the code working bug free, and not worry at all about speed ?
> 

Yes! 

Especially since simplest is usually also fastest.

First get it working.
Does it work fast enough?
(fast enough is totally subjective and the only relevant criterium)
if yes:
    leave well enough alone
if no:
    profile!
    (measurement is the only objective criterium)
    optimize the parts you _know_ are slow.
    	- optimize by redisigning your algorithms
        - keep measuring
    if your best algorithm is still too slow
	- rewrite in C

In my experience slow code falls in one of three categories.

1. slow, but not slow enough to be worth the trouble
   - I don't care if something runs in 0.1 second rather than 1 second
2. so slow that it's not worth the trouble.
   - I don't care if something runs in 1 hour rather than 10 hours
3. Hmm, maybe
   - I may care if something runs in 1 second rather than 10 seconds

3 is, of course, the rarest category.

Having made the obligatory point about only rewriting for optimization
iff:
1. you are sure it is necessary, and
2. you have reaon to believe it may help

let me add that a nagging feeling that another approach would be more
elegant/shorter/neater or simply feel better is a perfectly good reason
to rewrite your code. The nice thing is that if your feeling happens to
be right, your code will usually become faster too.

Hope this helps,


-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From ramas@retriever.com.au  Tue May 15 11:26:25 2001
From: ramas@retriever.com.au (Rams Subramonian)
Date: Tue, 15 May 2001 20:26:25 +1000
Subject: [Tutor] [Fwd: Python -Telnet problem]
Message-ID: <3B010451.25D89EB3@retriever.com.au>

This is a multi-part message in MIME format.
--------------DCD14D4903F3C0886D749E48
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

The following script sometimes doesn't work in Python scripting; It does

not go past the login  command  but seems to work interactively  with a
manual telnet session.
Any suggestions ?


 !/usr/bin/env python

import sys
import telnetlib


tn = telnetlib.Telnet("xxx", 4333)              # works ok

tn.set_debuglevel(30)
s=tn.read_eager()                                       #not ok
print s                                                           # not
ok
s=tn.read_eager()                                       # not ok
print s
tn.write("login xx cccc" + "\r\n")               # ok

s=tn.read_eager()                                        # not ok
print s                                                             #not
ok
tn.write("send xx  hello" + "\r\n")               #not ok
s=tn.read_eager()                                        #not ok
print s
tn.write("bye" + "\r\n")

tn.read_eager()
tn.read_eager()





--------------DCD14D4903F3C0886D749E48
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

X-Mozilla-Status2: 00000000
Message-ID: <3AFF65D6.1E39A53D@retriever.com.au>
Date: Mon, 14 May 2001 14:57:58 +1000
From: Rams Subramonian <ramas@retriever.com.au>
Reply-To: ramas@retriever.com.au
Organization: Retriever communications
X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0 i686)
X-Accept-Language: en
MIME-Version: 1.0
To: python-help@python.org
Subject: Python -Telnet problem 
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

The following script sometimes doesn't work in Python scripting; It does
not go past the telnet constructor(localhost) command but seems to work
interactively  with a manual telnet session.
Any suggestions ?

#!/usr/bin/env python
#
import os
import sys
import telnetlib
import string


tn = telnetlib.Telnet("localhost")
tn.set_debuglevel(30)
s   = tn.read_until('login:')
tn.write("help" + "\r\n")
s=tn.read_all()
print "got %s" % s

tn.close()
exit


--------------DCD14D4903F3C0886D749E48--



From s349929@student.uq.edu.au  Tue May 15 01:27:40 2001
From: s349929@student.uq.edu.au (Suzanne Little)
Date: Tue, 15 May 2001 10:27:40 +1000 (GMT+1000)
Subject: [Tutor] setting environment variables in apache
In-Reply-To: <Pine.OSF.4.30.0105150917250.29497-100000@student.uq.edu.au>
Message-ID: <Pine.OSF.4.30.0105151024290.14516-100000@student.uq.edu.au>

Phew! Sorry should have finished reading the deja search results before I
posted. I've written a little wrapper script to set the variable, as
below, which appears to have solved the problem. Apparently either doing
this or using some thing in apache called SetEnv is the only way to do
this.

Thanks,
Suzanne

Wrapper script
----------------------------------------------------------------------
#!/usr/local/bin/bash
LD_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/mysql
export LD_LIBRARY_PATH
/.../bootup3.py


--------------------------------------------------------------------------
"Contrariwise," continued Tweedledee, "If it was so, it might be; and if
it were so, it would be; but as it isn't, it ain't.  That's logic"
                             -Lewis Carroll
--------------------------------------------------------------------------



From tbrauch@mindless.com  Tue May 15 03:59:24 2001
From: tbrauch@mindless.com (Timothy M. Brauch)
Date: Mon, 14 May 2001 22:59:24 -0400
Subject: [Tutor] Classes
Message-ID: <3B009B8C.59DDF0AA@mindless.com>

Right now in a program I am writing, I have one huge class that does many things.  I was thinking of
breaking it up into smaller, specialized classes.  However, I have a dictionary that holds values
that the functions need.  How can I have all my specialized classes read from and write to the same
dictionary?  Can it be done?

A very simple example (my real code is fast approaching 750 lines):

class Big_Class:

    self.dictionary={'val_0':0, 'val_1':0, 'val_2':0, 'val_3':0}

    def func_0(self,destination,source):
        self.dictionary[destination]=self.dictionary[source]

    def func_1(self,destionation,integer):
        self.dictionary[destination]=integer

    def func_2(self,destination,source_0,source_1)
        self.dictionary[destination]=self.dictionary[source_0]+self.dictionary[source_1]

What I would like to do is break each of those functions (but pretend each function is really about
30 functions) up into a seperate class, all which read and write to the same dictionary.  My real
code has about 200 functions, that can be split into 5 or 6 general categories and my dictionary has
about 50 enteries, all of which are used in each smaller process.

 - Tim


From dyoo@hkn.eecs.berkeley.edu  Tue May 15 04:31:53 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 14 May 2001 20:31:53 -0700 (PDT)
Subject: [Tutor] build erors
In-Reply-To: <3AFFFDB6.885BE18C@tality.com>
Message-ID: <Pine.LNX.4.21.0105142030070.5630-100000@hkn.eecs.berkeley.edu>

On Mon, 14 May 2001, Mark A. Hernandez wrote:

> Heelo All,
>  I hope someone can help here is my problem:
> 
> i am trying to install python 2.1 on Sun OS 5.7
> Here is the screen output of configure followed by the errors after
> "make":

Hiya Mark,

Not quite sure if we can help with build errors.  You'll probably get much
better help if you ask the comp.lang.python newsgroup about this.  Send
them the same information you gave us, and someone there should be able to
help you get Python installed on your system.

Best of luck to you.




From dyoo@hkn.eecs.berkeley.edu  Tue May 15 05:00:26 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 14 May 2001 21:00:26 -0700 (PDT)
Subject: [Tutor] Manuals/books
In-Reply-To: <a05100e0cb725cd33727d@[10.0.1.21]>
Message-ID: <Pine.LNX.4.21.0105142048420.5630-100000@hkn.eecs.berkeley.edu>

On Mon, 14 May 2001, Deirdre Saoirse Moen wrote:

> >He's one of many Python experts around here. I'd call Tim Peters the guru :)
> 
> There's several experts, but Tim's our resident guru, except when, on 
> rare occasions, Guido posts.
> 
> Somehow, speaking of which, I was just insulted by a recruiter from
> Google the other day. They're looking for people with Linux, python,
> and search engine experience, but had, said the recruiter, passed over
> my resume. I said, "I have Linux experience, I have python experience
> and search engine experience. In fact, I have search engine experience
> IN python ON Linux. In Mountain View even. How much more of a match
> could you want?"
> 
> The recruiter said that the VP of Engineering felt I wasn't a match
> because my undergraduate field wasn't in one related to computers,

I thought the people at Google were supposed to be more intelligent than
that.  I know of undergrads from other majors who could kick the butt out
of many other CS undergrads here.

I'm sorry, it just makes me mad to hear about this.  We'll be rooting for
you.  Don't despair!



From deirdre@deirdre.net  Tue May 15 05:19:27 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Mon, 14 May 2001 21:19:27 -0700
Subject: [Tutor] Manuals/books
In-Reply-To: <Pine.LNX.4.21.0105142048420.5630-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105142048420.5630-100000@hkn.eecs.berkeley.edu>
Message-ID: <a05100e01b7265e58772b@[10.0.1.23]>

At 9:00 PM -0700 5/14/01, Daniel Yoo wrote:
>  > The recruiter said that the VP of Engineering felt I wasn't a match
>>  because my undergraduate field wasn't in one related to computers,
>
>I thought the people at Google were supposed to be more intelligent than
>that.  I know of undergrads from other majors who could kick the butt out
>of many other CS undergrads here.
>
>I'm sorry, it just makes me mad to hear about this.  We'll be rooting for
>you.  Don't despair!

Well, my father (a Ph.D. in Physics; all my family has advanced 
degrees) said that a liberal arts undergraduate degree "broadened his 
perspective on problems to solve" while his graduate work focused him 
on a specific problem. He argued, and I agree, that both were 
necessary.

I've seen academic snobbery before and it's never pretty. The point, 
as you say, is the result.

And the best coder *I* know of has his BA in Philosophy.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From jsc@rock-tnsc.com  Tue May 15 23:22:23 2001
From: jsc@rock-tnsc.com (Jethro Cramp)
Date: Tue, 15 May 2001 14:22:23 -0800
Subject: [Tutor] PyXML Help?
In-Reply-To: <989853159.2643.2.camel@scoot>
References: <989853159.2643.2.camel@scoot>
Message-ID: <01051514222301.02537@jsclaptop>

On Monday 14 May 2001  7:12 am, Scott Ralph Comboni wrote:
> I have a need to work with XML files mainly parsing.  Can anybody point
> me to some examples on the web above and beyond the HowTO?
> Thanks Scott

Try the book "XML Processing with Python" by Sean Mcgrath. See the site 
www.pyxie.org for details.

Jethro


From r.b.rigilink@chello.nl  Tue May 15 08:51:52 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Tue, 15 May 2001 09:51:52 +0200
Subject: [Tutor] Classes
References: <3B009B8C.59DDF0AA@mindless.com>
Message-ID: <3B00E018.14D6241F@chello.nl>

Hi Tim,

"Timothy M. Brauch" wrote:
> 
> Right now in a program I am writing, I have one huge class that does many things.  I was thinking of
> breaking it up into smaller, specialized classes.  However, I have a dictionary that holds values
> that the functions need.  How can I have all my specialized classes read from and write to the same
> dictionary?  Can it be done?
> 

Sure, 

How about telling your instances what dictionary to use at instantiation
Something like:

class A:
    def __init__(self, dict):
        self.dictionary = dict

class B
    def __init__(self, dict):
        self.dictionary = dict

the_dict = {}
a = A(the_dict)
b = B(the_dict)

a and b are now using the same dictionary. Every modifiction made by a
will be visible to b. What I don't like about this solution is that I
have to tell everybody about this dictionary now. Moreover, the user
must now call some operations on a and other operations on b. A solution
might be:

class Facade:
    def __init__(self):
        the_dict = {}
        self.a = A(the_dict)
        self.b = B(the_dict)
    def func_0(self, arg1, arg2):
        self.a.func_0(self, arg1, arg2)
    def func_1(self, arg1, arg2, arg3):
        self.b.func_0(self, arg1, arg2, arg3)

The user just sees one class again

> A very simple example (my real code is fast approaching 750 lines):
> 
> class Big_Class:
> 
>     self.dictionary={'val_0':0, 'val_1':0, 'val_2':0, 'val_3':0}
> 
>     def func_0(self,destination,source):
>         self.dictionary[destination]=self.dictionary[source]
> 
>     def func_1(self,destionation,integer):
>         self.dictionary[destination]=integer
> 
>     def func_2(self,destination,source_0,source_1)
>         self.dictionary[destination]=self.dictionary[source_0]+self.dictionary[source_1]
> 
> What I would like to do is break each of those functions (but pretend each function is really about
> 30 functions) up into a seperate class, all which read and write to the same dictionary.  My real
> code has about 200 functions, that can be split into 5 or 6 general categories and my dictionary has
> about 50 enteries, all of which are used in each smaller process.
> 

Hmm,

Different categories may suggest different classes, one dict suggests
one class.
Difficult to give additional suggestions without knowing more.

Hope this helps,

Roeland

-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From brett42@flex.com  Tue May 15 09:48:14 2001
From: brett42@flex.com (Brett)
Date: Mon, 14 May 2001 22:48:14 -1000
Subject: [Tutor] anyone know how to get installer to work?
In-Reply-To: <E14zRD4-0003jf-00@mail.python.org>
Message-ID: <4.3.2.7.0.20010514224201.00ab9da0@mail.flex.com>

I'm trying to learn how to use Tkinter, so I'm doing a project for my math 
class using python.  I spent like 10 hours writing like 200 lines of code(I 
had no idea what I was doing when I started)  and got ready to turn it into 
an executable I can turn in.  Now, 2 hours later, I can't get standalone.py 
to work.  It makes a dist_project, but when I try to run it it gives me a

traceback...:
file c:\python\lib\impututil.py...
No module named time.

I have no clue what this means.  I already uninstalled python and 
reinstalled python 2.0 and Installer installer20_3i.  Can anyone help, or 
do I have to turn in the 10 meg python installation with my script?
When Schrodinger's cat's away,
the mice may or may not play,
no one can tell.



From ppathiyi@cisco.com  Tue May 15 09:55:12 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Tue, 15 May 2001 14:25:12 +0530
Subject: [Tutor] Tcl path for Tkinter
Message-ID: <048701c0dd1c$c0b45380$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

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

 Hi all,
    I am trying to run my first GUI program in python using the Tkinter. =
But when i am running the code, iam getting an error...

**********************************************************************
   top =3D Tkinter.Tk()
  File "/sw/packages/python/1.5.2/lib/python1.5/lib-tk/Tkinter.py", line =
886, in __init__
    self.tk =3D _tkinter.create(screenName, baseName, className)
TclError: Can't find a usable init.tcl in the following directories:
./share/tcl8.0 /users/ppathiyi/share/tcl8.0 ./tcl8.0/library ./library



This probably means that Tcl wasn't installed properly.
**********************************************************************

But Tcl is infact installed in our system. So is there any place where i =
should specify the path for the Tcl executable ?

TIA,
Praveen.

------=_NextPart_000_0484_01C0DD4A.DA5732C0
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>&nbsp;Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; I am trying to run =
my=20
first&nbsp;GUI program in python using the Tkinter. But when i am =
running the=20
code, iam getting an error...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>****************************************************************=
******</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; top =3D =
Tkinter.Tk()<BR>&nbsp; File=20
"/sw/packages/python/1.5.2/lib/python1.5/lib-tk/Tkinter.py", line 886, =
in=20
__init__<BR>&nbsp;&nbsp;&nbsp; self.tk =3D _tkinter.create(screenName, =
baseName,=20
className)<BR>TclError: Can't find a usable init.tcl in the following=20
directories:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>./share/tcl8.0 =
/users/ppathiyi/share/tcl8.0=20
./tcl8.0/library ./library</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This probably means that Tcl wasn't =
installed=20
properly.<BR>************************************************************=
**********</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But Tcl is infact installed in our =
system. So is=20
there any place where i should specify the path for the Tcl executable=20
?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0484_01C0DD4A.DA5732C0--



From lonetwin@yahoo.com  Tue May 15 10:33:55 2001
From: lonetwin@yahoo.com (steve)
Date: Tue, 15 May 2001 15:03:55 +0530
Subject: [Tutor] Simplicity vs. Speed
In-Reply-To: <009f01c0dcb1$cf9aba80$d394a7cb@pf05nt.bayernz.co.nz>
References: <009f01c0dcb1$cf9aba80$d394a7cb@pf05nt.bayernz.co.nz>
Message-ID: <01051515035502.06358@mercury.in.cqsl.com>

Greetings Phil,
 As I read thru' ur mail, I realised exactly what u must be thinking/feel=
ing=20
right now after doing all that work....I've felt it scroes of times b'for=
e,=20
although through my experience as a progarmmer (not too much of it BTW) I=
've=20
learnt to keep the frequency with which these event occur few and so I=20
thought I might just share it with every.....click del all ye who art alr=
eady=20
bored :)...

ok, firstly, when I choose to program in a particular language I choose t=
he=20
language not only b'cos I know how to program in it, or b'cos that's y=20
progamming languages are for - to slove probles....but b'cos the language=
=20
lends itself towards solving the problem, what I mean is it offers featur=
es=20
that help me express the problem and it's solution clearly and elegantly=20
=2E..now what the heck does THAT ^^^^^^^ sh** mean...well lets take an=20
example...U R problem...it isn't quite clear (to me at least !! I'm slow =
;))
from u r mail, what exactly u r trying to achive but whatever it is ....s=
ince=20
u r using python...wud one particular feature of python ( dictionaries )=20
which is not available a the programmer of other languages (general comme=
nt=20
=2E.think C/C++..da..de..dum) be helpful in u r design ??
sumtin' like...
 dict =3D { 'Week1' : game1to10,
=09  'Week2' : .....
        }
 think in those terms....in terms of what the language offers...
I think I'm still not clear, so I'll say it as tho' u were sitting here i=
n=20
front of me...
<wildly gesturing>
 A programming language, is a proogramming language, is a progamming=20
language....variables, conditionals, iterators/loops, branching, classes=20
=2E.that's all.....what makes python different from perl=20
?<sincker>readability</snicker> python different from shell <thoughtful> =
data=20
structures ?? object orientation ? enhanced re's, tons if libs=20
</thoughtful>....stuff like that..
</wildly gesturing>

 N E WAYS first point is : Look at the language features

secondly, ram into u r head, the most simple/elegant/clean way to do sumt=
in'=20
is also ^^Always^^ the fastest way to do it .....if and only if, u design=
=20
well....don't ask me to justify that.....the only justification I can off=
er=20
is that, that's the case with me always...the cleanest turns out to be th=
e=20
fastest.....conversely, the fastest is bound to be elegant....if it ain't=
=20
then u designed wrong....<--------------------------------------\
                                                                |
I cud go on....tell u all that I learned....but I guess at this point
I'm way past n e 1's patience levels....so I'll bid u good luck and shut =
the=20
$%^# up right here
               |
Peace          |
Steve <--------|
--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
"Unfortunately, those people who have nothing better to do than post on t=
he
Internet all day long are rarely the ones who have the most insights."

=2E...now did this mail seem sumtin' like that??
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From SBrunning@trisystems.co.uk  Tue May 15 11:14:51 2001
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Tue, 15 May 2001 11:14:51 +0100
Subject: [Tutor] anyone know how to get installer to work?
Message-ID: <31575A892FF6D1118F5800600846864D78BBEC@intrepid>

> I'm trying to learn how to use Tkinter, so I'm doing a project for my math
> 
> class using python.  I spent like 10 hours writing like 200 lines of
> code(I 
> had no idea what I was doing when I started)  and got ready to turn it
> into 
> an executable I can turn in.  Now, 2 hours later, I can't get
> standalone.py 
> to work.  It makes a dist_project, but when I try to run it it gives me a
> 
> traceback...:
> file c:\python\lib\impututil.py...
> No module named time.
> 
> I have no clue what this means.  I already uninstalled python and 
> reinstalled python 2.0 and Installer installer20_3i.  Can anyone help, or 
> do I have to turn in the 10 meg python installation with my script?
 
Well, I don't know about installer, but I'd had no problems with py3exe -
<http://starship.python.net/crew/theller/py2exe/>. Have a bash with this...

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 alan.gauld@bt.com  Tue May 15 11:18:43 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 15 May 2001 11:18:43 +0100
Subject: [Tutor] Simplicity vs. Speed
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D770@mbtlipnt02.btlabs.bt.co.uk>

> From: Remco Gerlich [mailto:scarblac@pino.selwerd.nl]
> On  0, Phil Bertram <phil.bertram@clear.net.nz> wrote:
> > get the code working bug free, and not worry at all about speed ?
> 
> Programmers, even very experienced ones, have misguided 
> intuitions about where the bottlenecks in their programs are. 

This is soooo true.
In fact on large systems the bottlenecks are usually in the 
database or network, not the code at all!

> In my opinion, it should work like this in most cases:
> - Make the simplest thing that could possibly work.
> - *If* this turns out to be too slow, *find out what slows it down*.
> - Try to find out a better algorithm.
> - Repeat.

I agree with Remco's comments except I would add that as well 
as the algorithm consider your data structures - very often 
they will force the algorithm and if they are inappropriate 
no amount of algorithm tweaking can fix it. eg. Using a 
dictionary is often much faster than looping thru' a list 
for example. Could you change your top level lists into 
dictionaries (keyed by date mebbe?)

But first get the code working. Then if, and only if, its too 
slow (based on what? User feedback?) locate the hot spots 
and fix them.

Alan G



From alan.gauld@bt.com  Tue May 15 11:24:24 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 15 May 2001 11:24:24 +0100
Subject: [Tutor] Simplicity vs. Speed
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D771@mbtlipnt02.btlabs.bt.co.uk>

> Especially since simplest is usually also fastest.

Sorry I've got to disagree with that one. Simple algorithms are 
often fast enough but they are rarely optimal. (Consider bubble 
sort, or the shuffle discussion recently). So keep it simple 
by all means but better(ie faster!) algorithms usually carry 
the cost of increased complexity...

Everything else in your post I agree with BTW. Especially the 
3 way categorisation of slowness.

Alan g.


From alan.gauld@bt.com  Tue May 15 11:34:24 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 15 May 2001 11:34:24 +0100
Subject: [Tutor] Classes
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D772@mbtlipnt02.btlabs.bt.co.uk>

> Right now in a program I am writing, I have one huge class 
> that does many things.  I was thinking of
> breaking it up into smaller, specialized classes.  

Probably a good decision. But...

> However, I have a dictionary that holds values
> that the functions need.  

All of thevfunctions use all of the dictionaries?
In that case your single class approach must be right!
Since a class is the data plus the functions that operate 
on that data.

But more likely you could restructure how the data 
is stored by moving values into a different collection 
and find that groups of functions now only work with 
one collection. So take that collection and those 
functions and make that a class. And while you are at 
it consider taking the data out of the collection and 
turn it into instance variables.

> How can I have all my specialized 
> classes read from and write to the same
> dictionary?  Can it be done?

The simple answer is pass the dictionary to the classes 
as an argument - eoither to the constructor or to each 
method. Pedagogically you could put the dictionaries in 
a global class which could implement sdome sanity 
checking around access to the underlying data - but 
either way its not a good design IMHO.

> 30 functions) up into a seperate class, all which read and 
> write to the same dictionary.  

That's really not a good OO approach. We should be aiming 
to hide the data and keep it within a class not expose 
it to the masses...

> general categories and my dictionary has
> about 50 enteries, all of which are used in each smaller process.

Thats the bit that worries me. If you have all of those 
processes (aka functions?) all accessing *all* of the data 
then something smells wrong somewhere.

Objects-should-do-it-to-themselves-ly yrs

Alan G.


From rob@jam.rr.com  Tue May 15 12:11:05 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Tue, 15 May 2001 06:11:05 -0500
Subject: [Tutor] anyone know how to get installer to work?
References: <4.3.2.7.0.20010514224201.00ab9da0@mail.flex.com>
Message-ID: <3B010EC9.D28F28D9@jam.rr.com>

There is a Python module named *time*. Perhaps you have a reference to
it or one of its functions. Take a look at the time documentation in the
docs that came with your Python install or on the python.org website and
see if anything looks familiar.

When in doubt, you might want to scan your code for the term time or
similar.

Rob

Brett wrote:
> 
> I'm trying to learn how to use Tkinter, so I'm doing a project for my math
> class using python.  I spent like 10 hours writing like 200 lines of code(I
> had no idea what I was doing when I started)  and got ready to turn it into
> an executable I can turn in.  Now, 2 hours later, I can't get standalone.py
> to work.  It makes a dist_project, but when I try to run it it gives me a
> 
> traceback...:
> file c:\python\lib\impututil.py...
> No module named time.
> 
> I have no clue what this means.  I already uninstalled python and
> reinstalled python 2.0 and Installer installer20_3i.  Can anyone help, or
> do I have to turn in the 10 meg python installation with my script?
> When Schrodinger's cat's away,
> the mice may or may not play,
> no one can tell.
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From arcege@speakeasy.net  Tue May 15 12:25:17 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Tue, 15 May 2001 07:25:17 -0400 (EDT)
Subject: [Tutor] PyXML Help?
In-Reply-To: <01051514222301.02537@jsclaptop> from "Jethro Cramp" at May 15, 2001 02:22:23 PM
Message-ID: <200105151125.f4FBPHc11691@dsl092-074-184.bos1.dsl.speakeasy.net>

Jethro Cramp wrote
> 
> On Monday 14 May 2001  7:12 am, Scott Ralph Comboni wrote:
> > I have a need to work with XML files mainly parsing.  Can anybody point
> > me to some examples on the web above and beyond the HowTO?
> > Thanks Scott
> 
> Try the book "XML Processing with Python" by Sean Mcgrath. See the site 
> www.pyxie.org for details.
> 
> Jethro

I got the book because I didn't know XML well.  The book added nothing
to my XML knowledge - and nothing to the usage Python's XML librarys.
The (even proclaimed) purpose of book is to promote the author's own
Python package, not Python's standard xmllib or other's (I think he
has one chapter on standard xml package).  The introduction declares
that the reader should have a through knowledge of XML and the book
does not even give a good cursory overview.  While that's not a sin,
it is certainly misleading.

I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML" and
reading the Python documentation and XML-SIG.  You'd be better off IMO.
(At least the O'Reilly has the definition of XML components and DTD to
refer to if you need them.)

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From scarblac@pino.selwerd.nl  Tue May 15 12:30:48 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 15 May 2001 13:30:48 +0200
Subject: [Tutor] PyXML Help?
In-Reply-To: <200105151125.f4FBPHc11691@dsl092-074-184.bos1.dsl.speakeasy.net>; from arcege@dsl092-074-184.bos1.dsl.speakeasy.net on Tue, May 15, 2001 at 07:25:17AM -0400
References: <01051514222301.02537@jsclaptop> <200105151125.f4FBPHc11691@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <20010515133048.A5213@pino.selwerd.nl>

On  0, "Michael P. Reilly" <arcege@dsl092-074-184.bos1.dsl.speakeasy.net> wrote:
> I got the book because I didn't know XML well.  The book added nothing
> to my XML knowledge - and nothing to the usage Python's XML librarys.
> The (even proclaimed) purpose of book is to promote the author's own
> Python package, not Python's standard xmllib or other's (I think he
> has one chapter on standard xml package).  The introduction declares
> that the reader should have a through knowledge of XML and the book
> does not even give a good cursory overview.  While that's not a sin,
> it is certainly misleading.
> 
> I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML" and
> reading the Python documentation and XML-SIG.  You'd be better off IMO.
> (At least the O'Reilly has the definition of XML components and DTD to
> refer to if you need them.)

I agree completely. I knew Python, bought the book hoping it would teach me
about XML and how to use the Python xmllibs with it. Instead it assumes you
know about XML, has a Python tutorial with lots of errors, and promotes
another package. Never used the book much.

-- 
Remco Gerlich


From arcege@speakeasy.net  Tue May 15 13:19:29 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Tue, 15 May 2001 08:19:29 -0400 (EDT)
Subject: [Tutor] Classes
In-Reply-To: <3B009B8C.59DDF0AA@mindless.com> from "Timothy M. Brauch" at May 14, 2001 10:59:24 PM
Message-ID: <200105151219.f4FCJTD11763@dsl092-074-184.bos1.dsl.speakeasy.net>

Timothy M. Brauch wrote
> 
> Right now in a program I am writing, I have one huge class that does many things.  I was thinking of
> breaking it up into smaller, specialized classes.  However, I have a dictionary that holds values
> that the functions need.  How can I have all my specialized classes read from and write to the same
> dictionary?  Can it be done?
> 
> A very simple example (my real code is fast approaching 750 lines):
> 
> class Big_Class:
> 
>     self.dictionary={'val_0':0, 'val_1':0, 'val_2':0, 'val_3':0}
> 
>     def func_0(self,destination,source):
>         self.dictionary[destination]=self.dictionary[source]
> 
>     def func_1(self,destionation,integer):
>         self.dictionary[destination]=integer
> 
>     def func_2(self,destination,source_0,source_1)
>         self.dictionary[destination]=self.dictionary[source_0]+self.dictionary[source_1]
> 
> What I would like to do is break each of those functions (but pretend each function is really about
> 30 functions) up into a seperate class, all which read and write to the same dictionary.  My real
> code has about 200 functions, that can be split into 5 or 6 general categories and my dictionary has
> about 50 enteries, all of which are used in each smaller process.

You can do one of two things, but I suggest the second.

1.  You can move the functions (especially into your categories) into
"mix-ins", then the final class would include those as subclasses.

class Category_0:
  def func_0(self, destination, source):
    self.dictionary[destination] = self.dictionary[source]
class Category_1:
  def func_1(self, destination, integer):
    self.dictionary[destination] = integer
class Category_2:
  def func_2(self, destination, source_0, source_1):
    self.dictionary[destination] = self.dictionary[source_0] +
      self.dictinary[source_1]

class Less_Big_Class(Category_0, Category_1, Category_2):
  def __init__(self, ...):
    self.dictionary = ...

2.  The second one is to simplify the access to the dictionary.

class Category_0:
  def func_0(self, dest, src):
    self[dest] = self[src]
class Category_1:
  ...
class Other_Big_Class(Category_0, ...):
  def __init__(self, ...):
    self.dictionary = ...
  def __getitem__(self, index):
    return self.dictionary[index]
  def __setitem__(self, index, value):
    self.dictionary[index] = value
  def __delitem__(self, index):
    del self.dictionary[index]

This lets you define the other functions that are not dependant on
the dictionary itself, but on logical access to the instance.

If you needed/wanted to, you could put the "category" mix-in classes in
different modules.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From kstoner@netins.net  Tue May 15 13:30:50 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Tue, 15 May 2001 07:30:50 -0500
Subject: [Tutor] where to start
Message-ID: <001601c0dd3a$e0818480$1752b1cf@oemcomputer>

This is a multi-part message in MIME format.

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

I wanted to know how do you go about starting a large program.  Where do =
you start on it?  The ideas I have involve making windows, but I don't =
know how to start them.  I'm still researching the widgets and making =
windows.  Should I just plow on through or what?

thanks

-Cameron

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I wanted to know how do you go about =
starting a=20
large program.&nbsp; Where do you start on it?&nbsp; The ideas I have =
involve=20
making windows, but I don't know how to start them.&nbsp; I'm still =
researching=20
the widgets and making windows.&nbsp; Should I just plow on through or=20
what?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>thanks</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-Cameron</FONT></DIV></BODY></HTML>

------=_NextPart_000_0013_01C0DD10.F7146CA0--



From scarblac@pino.selwerd.nl  Tue May 15 13:45:35 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 15 May 2001 14:45:35 +0200
Subject: [Tutor] where to start
In-Reply-To: <001601c0dd3a$e0818480$1752b1cf@oemcomputer>; from kstoner@netins.net on Tue, May 15, 2001 at 07:30:50AM -0500
References: <001601c0dd3a$e0818480$1752b1cf@oemcomputer>
Message-ID: <20010515144535.A5420@pino.selwerd.nl>

On  0, Katharine Stoner <kstoner@netins.net> wrote:
> I wanted to know how do you go about starting a large program.  Where do
> you start on it?  The ideas I have involve making windows, but I don't know
> how to start them.  I'm still researching the widgets and making windows.
> Should I just plow on through or what?

The user interface is not the most central thing, except for pretty small
applications. You want to be thinking about your data.

What will your program have to do? Does it consist of several parts? What
sort of data will it have to keep track of? What will it do with the data?
What would be the way to organize it? Try to think of a natural way to
divide your data in classes.

The GUI also needs to be designed, but it's not what you program first. It
should be as independent as possible from the rest of the program (I've seen
programs where the main business logic was in the function that decided
whether a certain radio buttion could be clicked - it was *not pretty*).
You want to be able to make changes to your data model without changing the
GUI, and vice versa.

You should be able to test your data structures from the Python interpreter,
ideally. Then you build a simple GUI that can interact with them, adding
more and more features.

This is of course oversimplified and still pretty much hackery, but there's
sooo much written on Software Design, and I don't even know what you're
trying to make :)

-- 
Remco Gerlich


From kalle@gnupung.net  Tue May 15 14:10:13 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Tue, 15 May 2001 15:10:13 +0200
Subject: [Tutor] PyXML Help?
In-Reply-To: <200105151125.f4FBPHc11691@dsl092-074-184.bos1.dsl.speakeasy.net>; from arcege@dsl092-074-184.bos1.dsl.speakeasy.net on Tue, May 15, 2001 at 07:25:17AM -0400
References: <01051514222301.02537@jsclaptop> <200105151125.f4FBPHc11691@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <20010515151013.A4792@father>

Sez Michael P. Reilly [about XML Processing with Python]:
> I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML" and
> reading the Python documentation and XML-SIG.  You'd be better off IMO.
> (At least the O'Reilly has the definition of XML components and DTD to
> refer to if you need them.)

I recently bought "XML in a Nutshell", also from O'Reilly.  I thoroughly
recommend it for anyone with some experience with HTML or SGML and
programming (in python or otherwise).  It was quite sufficient for me to
learn XML from, and has a good reference section.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From randrews@planhouse.com  Tue May 15 14:18:42 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Tue, 15 May 2001 08:18:42 -0500
Subject: [Tutor] PyXML Help?
In-Reply-To: <20010515151013.A4792@father>
Message-ID: <000201c0dd41$90832360$de00a8c0@planhouse5>

I found XML itself simple enough to figure out from a
http://www.w3schools.com/ tutorial, and I can also highly recommend
O'Reilly's "Learning XML". It's a fine book. I've yet to figure out how to
use Python with it, but I'm sure my mojo will rise soon.

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Kalle Svensson
Sent: Tuesday, May 15, 2001 8:10 AM
To: tutor@python.org
Subject: Re: [Tutor] PyXML Help?


Sez Michael P. Reilly [about XML Processing with Python]:
> I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML" and
> reading the Python documentation and XML-SIG.  You'd be better off IMO.
> (At least the O'Reilly has the definition of XML components and DTD to
> refer to if you need them.)

I recently bought "XML in a Nutshell", also from O'Reilly.  I thoroughly
recommend it for anyone with some experience with HTML or SGML and
programming (in python or otherwise).  It was quite sufficient for me to
learn XML from, and has a good reference section.

Peace,
  Kalle
--
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]

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



From scott@zenplex.com  Tue May 15 14:40:15 2001
From: scott@zenplex.com (Scott Ralph Comboni)
Date: 15 May 2001 09:40:15 -0400
Subject: [Tutor] PyXML Help?
In-Reply-To: <000201c0dd41$90832360$de00a8c0@planhouse5>
References: <000201c0dd41$90832360$de00a8c0@planhouse5>
Message-ID: <989934016.1253.2.camel@scoot>

I guess thats were I'm at.  XML I have an understanding of but using
Python to parse XML is were Im having trouble.  Been using the xmllib
module with some luck.  But I was really hoping to find some more
detailed examples.  Which is really the best way I learn.  The XML
Processing with PYTHON book by Sean McGrath I have and found out very
quickly as mentioned early that his focus is not on xmllib but his own
Pyxie.  I'd rather stick with the core Lib.
Thanks
Scott

On 15 May 2001 08:18:42 -0500, Rob Andrews wrote:
> I found XML itself simple enough to figure out from a
> http://www.w3schools.com/ tutorial, and I can also highly recommend
> O'Reilly's "Learning XML". It's a fine book. I've yet to figure out how to
> use Python with it, but I'm sure my mojo will rise soon.
> 
> Rob
> 
> Got Python?
> http://www.lowerstandard.com/python/pythonsource.html
> 
> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Kalle Svensson
> Sent: Tuesday, May 15, 2001 8:10 AM
> To: tutor@python.org
> Subject: Re: [Tutor] PyXML Help?
> 
> 
> Sez Michael P. Reilly [about XML Processing with Python]:
> > I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML" and
> > reading the Python documentation and XML-SIG.  You'd be better off IMO.
> > (At least the O'Reilly has the definition of XML components and DTD to
> > refer to if you need them.)
> 
> I recently bought "XML in a Nutshell", also from O'Reilly.  I thoroughly
> recommend it for anyone with some experience with HTML or SGML and
> programming (in python or otherwise).  It was quite sufficient for me to
> learn XML from, and has a good reference section.
> 
> Peace,
>   Kalle
> --
> Email: kalle@gnupung.net     | You can tune a filesystem, but you
> Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
> PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
>  [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Scott Ralph Comboni
Zenplex, Inc.
317 Madison Ave.
Suite 1500
New York NY, 10017
212.499.0668 ext2219
http://www.zenplex.com
http://www.zenplex.org
http://tambora.zenplex.org



From kojo@hal-pc.org  Tue May 15 16:10:37 2001
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Tue, 15 May 2001 10:10:37 -0500
Subject: [Tutor] PyXML Help?
In-Reply-To: <000201c0dd41$90832360$de00a8c0@planhouse5>
References: <20010515151013.A4792@father>
Message-ID: <5.0.2.1.0.20010515100834.00afd200@Pop3.norton.antivirus>

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

Rob, thanks for the w3schools link.  Very cool.  This could save me some 
money on books.  It's horrible being a computer nerd and a 
bibliophile...never enough money, time or space.
:-)

At 08:18 AM 5/15/2001 -0500, Rob Andrews wrote:
>I found XML itself simple enough to figure out from a
>http://www.w3schools.com/ tutorial, and I can also highly recommend
>O'Reilly's "Learning XML". It's a fine book. I've yet to figure out how to
>use Python with it, but I'm sure my mojo will rise soon.
>
>Rob
>
>Got Python?
>http://www.lowerstandard.com/python/pythonsource.html
>
>-----Original Message-----
>From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
>Kalle Svensson
>Sent: Tuesday, May 15, 2001 8:10 AM
>To: tutor@python.org
>Subject: Re: [Tutor] PyXML Help?
>
>
>Sez Michael P. Reilly [about XML Processing with Python]:
> > I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML" and
> > reading the Python documentation and XML-SIG.  You'd be better off IMO.
> > (At least the O'Reilly has the definition of XML components and DTD to
> > refer to if you need them.)
>
>I recently bought "XML in a Nutshell", also from O'Reilly.  I thoroughly
>recommend it for anyone with some experience with HTML or SGML and
>programming (in python or otherwise).  It was quite sufficient for me to
>learn XML from, and has a good reference section.
>
>Peace,
>   Kalle
>--
>Email: kalle@gnupung.net     | You can tune a filesystem, but you
>Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
>PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
>  [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

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

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************
--=====================_595239168==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
Rob, thanks for the w3schools link.&nbsp; Very cool.&nbsp; This could
save me some money on books.&nbsp; It's horrible being a computer nerd
<b>and</b> a bibliophile...never enough money, time  or space.<br>
:-)<br>
<br>
At 08:18 AM 5/15/2001 -0500, Rob Andrews wrote:<br>
<blockquote type=cite class=cite cite>I found XML itself simple enough to
figure out from a<br>
<a href="http://www.w3schools.com/" eudora="autourl">http://www.w3schools.com/</a>
tutorial, and I can also highly recommend<br>
O'Reilly's &quot;Learning XML&quot;. It's a fine book. I've yet to figure out how to<br>
use Python with it, but I'm sure my mojo will rise soon.<br>
<br>
Rob<br>
<br>
Got Python?<br>
<a href="http://www.lowerstandard.com/python/pythonsource.html" eudora="autourl">http://www.lowerstandard.com/python/pythonsource.html</a><br>
<br>
-----Original Message-----<br>
From: tutor-admin@python.org [<a href="mailto:tutor-admin@python.org" eudora="autourl">mailto:tutor-admin@python.org</a>]On Behalf Of<br>
Kalle Svensson<br>
Sent: Tuesday, May 15, 2001 8:10 AM<br>
To: tutor@python.org<br>
Subject: Re: [Tutor] PyXML Help?<br>
<br>
<br>
Sez Michael P. Reilly [about XML Processing with Python]:<br>
&gt; I'd never recommend that book.&nbsp; I'd suggest O'Reilly's &quot;Learning XML&quot; and<br>
&gt; reading the Python documentation and XML-SIG.&nbsp; You'd be better off IMO.<br>
&gt; (At least the O'Reilly has the definition of XML components and DTD to<br>
&gt; refer to if you need them.)<br>
<br>
I recently bought &quot;XML in a Nutshell&quot;, also from O'Reilly.&nbsp; I thoroughly<br>
recommend it for anyone with some experience with HTML or SGML and<br>
programming (in python or otherwise).&nbsp; It was quite sufficient for me to<br>
learn XML from, and has a good reference section.<br>
<br>
Peace,<br>
&nbsp; Kalle<br>
--<br>
Email: kalle@gnupung.net&nbsp;&nbsp;&nbsp;&nbsp; | You can tune a filesystem, but you<br>
Web: <a href="http://www.gnupung.net/" eudora="autourl">http://www.gnupung.net/</a> | can't tune a fish. -- man tunefs(8)<br>
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD<br>
&nbsp;[ Not signed due to lossage.&nbsp; Blame Microsoft Outlook Express. ]<br>
<br>
_______________________________________________<br>
Tutor maillist&nbsp; -&nbsp; Tutor@python.org<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" eudora="autourl">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br>
<br>
_______________________________________________<br>
Tutor maillist&nbsp; -&nbsp; Tutor@python.org<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" eudora="autourl">http://mail.python.org/mailman/listinfo/tutor</a></blockquote>
<x-sigsep><p></x-sigsep>
**************************** <br>
Kojo Idrissa <br>
&nbsp; <br>
kojo@hal-pc.org<br>
<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http</a>://www.hal-pc.org<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">/~kojo/</a><br>
****************************</html>

--=====================_595239168==_.ALT--



From deirdre@deirdre.net  Tue May 15 17:44:59 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Tue, 15 May 2001 09:44:59 -0700
Subject: [Tutor] where to start
In-Reply-To: <001601c0dd3a$e0818480$1752b1cf@oemcomputer>
References: <001601c0dd3a$e0818480$1752b1cf@oemcomputer>
Message-ID: <a05100e03b7270d5bac48@[10.0.1.24]>

--============_-1222177389==_ma============
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

>I wanted to know how do you go about starting a large program. 
>Where do you start on it?  The ideas I have involve making windows, 
>but I don't know how to start them.  I'm still researching the 
>widgets and making windows.  Should I just plow on through or what?

Just start somewhere. Usually I start with the pieces I know I can do.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams
--============_-1222177389==_ma============
Content-Type: text/html; charset="us-ascii"

<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>Re: [Tutor] where to start</title></head><body>
<blockquote type="cite" cite><font face="Arial" size="-1">I wanted to
know how do you go about starting a large program.&nbsp; Where do you
start on it?&nbsp; The ideas I have involve making windows, but I
don't know how to start them.&nbsp; I'm still researching the widgets
and making windows.&nbsp; Should I just plow on through or
what?</font></blockquote>
<div><br></div>
<div>Just start somewhere. Usually I start with the pieces I know I
can do.</div>
</body>
</html>
--============_-1222177389==_ma============--


From vns@coconutmail.com  Tue May 15 17:59:24 2001
From: vns@coconutmail.com (vnsampath)
Date: Wed, 16 May 2001 00:59:24 +0800
Subject: [Tutor] help
Message-ID: <200105160059.AA1001586928@coconutmail.com>

remove



---------- Original Message ----------------------------------
From: tutor-request@python.org
Reply-to: tutor@python.org
Date: Tue, 15 May 2001 12:01:06 -0400

>Send Tutor mailing list submissions to
>	tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>	http://mail.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. RE: PyXML Help? (Kojo Idrissa)
>
>--__--__--
>
>Message: 1
>Date: Tue, 15 May 2001 10:10:37 -0500
>To: <tutor@python.org>
>From: Kojo Idrissa <kojo@hal-pc.org>
>Subject: RE: [Tutor] PyXML Help?
>
>--=====================_595239168==_.ALT
>Content-Type: text/plain; charset="us-ascii"; format=flowed
>
>Rob, thanks for the w3schools link.  Very cool.  This could save me some 
>money on books.  It's horrible being a computer nerd and a 
>bibliophile...never enough money, time or space.
>:-)
>
>At 08:18 AM 5/15/2001 -0500, Rob Andrews wrote:
>>I found XML itself simple enough to figure out from a
>>http://www.w3schools.com/ tutorial, and I can also highly recommend
>>O'Reilly's "Learning XML". It's a fine book. I've yet to figure out how to
>>use Python with it, but I'm sure my mojo will rise soon.
>>
>>Rob
>>
>>Got Python?
>>http://www.lowerstandard.com/python/pythonsource.html
>>
>>-----Original Message-----
>>From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
>>Kalle Svensson
>>Sent: Tuesday, May 15, 2001 8:10 AM
>>To: tutor@python.org
>>Subject: Re: [Tutor] PyXML Help?
>>
>>
>>Sez Michael P. Reilly [about XML Processing with Python]:
>> > I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML" and
>> > reading the Python documentation and XML-SIG.  You'd be better off IMO.
>> > (At least the O'Reilly has the definition of XML components and DTD to
>> > refer to if you need them.)
>>
>>I recently bought "XML in a Nutshell", also from O'Reilly.  I thoroughly
>>recommend it for anyone with some experience with HTML or SGML and
>>programming (in python or otherwise).  It was quite sufficient for me to
>>learn XML from, and has a good reference section.
>>
>>Peace,
>>   Kalle
>>--
>>Email: kalle@gnupung.net     | You can tune a filesystem, but you
>>Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
>>PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
>>  [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>
>****************************
>Kojo Idrissa
>
>kojo@hal-pc.org
>http://www.hal-pc.org/~kojo/
>****************************
>--=====================_595239168==_.ALT
>Content-Type: text/html; charset="us-ascii"
>
><html>
>Rob, thanks for the w3schools link.  Very cool.  This could
>save me some money on books.  It's horrible being a computer nerd
><b>and</b> a bibliophile...never enough money, time  or space.<br>
>:-)<br>
><br>
>At 08:18 AM 5/15/2001 -0500, Rob Andrews wrote:<br>
><blockquote type=cite class=cite cite>I found XML itself simple enough to
>figure out from a<br>
><a href="http://www.w3schools.com/" eudora="autourl">http://www.w3schools.com/</a>
>tutorial, and I can also highly recommend<br>
>O'Reilly's "Learning XML". It's a fine book. I've yet to figure out how to<br>
>use Python with it, but I'm sure my mojo will rise soon.<br>
><br>
>Rob<br>
><br>
>Got Python?<br>
><a href="http://www.lowerstandard.com/python/pythonsource.html" eudora="autourl">http://www.lowerstandard.com/python/pythonsource.html</a><br>
><br>
>-----Original Message-----<br>
>From: tutor-admin@python.org [<a href="mailto:tutor-admin@python.org" eudora="autourl">mailto:tutor-admin@python.org</a>]On Behalf Of<br>
>Kalle Svensson<br>
>Sent: Tuesday, May 15, 2001 8:10 AM<br>
>To: tutor@python.org<br>
>Subject: Re: [Tutor] PyXML Help?<br>
><br>
><br>
>Sez Michael P. Reilly [about XML Processing with Python]:<br>
>> I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML" and<br>
>> reading the Python documentation and XML-SIG.  You'd be better off IMO.<br>
>> (At least the O'Reilly has the definition of XML components and DTD to<br>
>> refer to if you need them.)<br>
><br>
>I recently bought "XML in a Nutshell", also from O'Reilly.  I thoroughly<br>
>recommend it for anyone with some experience with HTML or SGML and<br>
>programming (in python or otherwise).  It was quite sufficient for me to<br>
>learn XML from, and has a good reference section.<br>
><br>
>Peace,<br>
>  Kalle<br>
>--<br>
>Email: kalle@gnupung.net     | You can tune a filesystem, but you<br>
>Web: <a href="http://www.gnupung.net/" eudora="autourl">http://www.gnupung.net/</a> | can't tune a fish. -- man tunefs(8)<br>
>PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD<br>
> [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]<br>
><br>
>_______________________________________________<br>
>Tutor maillist  -  Tutor@python.org<br>
><a href="http://mail.python.org/mailman/listinfo/tutor" eudora="autourl">http://mail.python.org/mailman/listinfo/tutor</a><br>
><br>
><br>
>_______________________________________________<br>
>Tutor maillist  -  Tutor@python.org<br>
><a href="http://mail.python.org/mailman/listinfo/tutor" eudora="autourl">http://mail.python.org/mailman/listinfo/tutor</a></blockquote>
><x-sigsep><p></x-sigsep>
>**************************** <br>
>Kojo Idrissa <br>
>  <br>
>kojo@hal-pc.org<br>
><a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http</a>://www.hal-pc.org<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">/~kojo/</a><br>
>****************************</html>
>
>--=====================_595239168==_.ALT--
>
>
>
>
>--__--__--
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>End of Tutor Digest
>

_________________________________________________________
FREE Corporate Web-hosting, 20MB space, 30 Email accounts
Get Your Own Domain at http://www.iRepublics.com


From randrews@planhouse.com  Tue May 15 18:13:21 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Tue, 15 May 2001 12:13:21 -0500
Subject: [Tutor] help
In-Reply-To: <200105160059.AA1001586928@coconutmail.com>
Message-ID: <000601c0dd62$5836e520$de00a8c0@planhouse5>

Have you tried to remove yourself from the list using this method?

To subscribe or unsubscribe via the World Wide Web, visit
>	http://mail.python.org/mailman/listinfo/tutor

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
vnsampath
Sent: Tuesday, May 15, 2001 11:59 AM
To: tutor@python.org
Subject: [Tutor] help



remove



---------- Original Message ----------------------------------
From: tutor-request@python.org
Reply-to: tutor@python.org
Date: Tue, 15 May 2001 12:01:06 -0400

>Send Tutor mailing list submissions to
>	tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>	http://mail.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. RE: PyXML Help? (Kojo Idrissa)
>
>--__--__--
>
>Message: 1
>Date: Tue, 15 May 2001 10:10:37 -0500
>To: <tutor@python.org>
>From: Kojo Idrissa <kojo@hal-pc.org>
>Subject: RE: [Tutor] PyXML Help?
>
>--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D_595239=
168=3D=3D_.ALT
>Content-Type: text/plain; charset=3D"us-ascii"; format=3Dflowed
>
>Rob, thanks for the w3schools link.  Very cool.  This could save me some
>money on books.  It's horrible being a computer nerd and a
>bibliophile...never enough money, time or space.
>:-)
>
>At 08:18 AM 5/15/2001 -0500, Rob Andrews wrote:
>>I found XML itself simple enough to figure out from a
>>http://www.w3schools.com/ tutorial, and I can also highly recommend
>>O'Reilly's "Learning XML". It's a fine book. I've yet to figure out how=
 to
>>use Python with it, but I'm sure my mojo will rise soon.
>>
>>Rob
>>
>>Got Python?
>>http://www.lowerstandard.com/python/pythonsource.html
>>
>>-----Original Message-----
>>From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf O=
f
>>Kalle Svensson
>>Sent: Tuesday, May 15, 2001 8:10 AM
>>To: tutor@python.org
>>Subject: Re: [Tutor] PyXML Help?
>>
>>
>>Sez Michael P. Reilly [about XML Processing with Python]:
>> > I'd never recommend that book.  I'd suggest O'Reilly's "Learning XML=
"
and
>> > reading the Python documentation and XML-SIG.  You'd be better off I=
MO.
>> > (At least the O'Reilly has the definition of XML components and DTD =
to
>> > refer to if you need them.)
>>
>>I recently bought "XML in a Nutshell", also from O'Reilly.  I thoroughl=
y
>>recommend it for anyone with some experience with HTML or SGML and
>>programming (in python or otherwise).  It was quite sufficient for me t=
o
>>learn XML from, and has a good reference section.
>>
>>Peace,
>>   Kalle
>>--
>>Email: kalle@gnupung.net     | You can tune a filesystem, but you
>>Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
>>PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
>>  [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>
>****************************
>Kojo Idrissa
>
>kojo@hal-pc.org
>http://www.hal-pc.org/~kojo/
>****************************
>--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D_595239=
168=3D=3D_.ALT
>Content-Type: text/html; charset=3D"us-ascii"
>
><html>
>Rob, thanks for the w3schools link.=A0 Very cool.=A0 This could
>save me some money on books.=A0 It's horrible being a computer nerd
><b>and</b> a bibliophile...never enough money, time  or space.<br>
>:-)<br>
><br>
>At 08:18 AM 5/15/2001 -0500, Rob Andrews wrote:<br>
><blockquote type=3Dcite class=3Dcite cite>I found XML itself simple enou=
gh to
>figure out from a<br>
><a href=3D"http://www.w3schools.com/"
eudora=3D"autourl">http://www.w3schools.com/</a>
>tutorial, and I can also highly recommend<br>
>O'Reilly's "Learning XML". It's a fine book. I've yet to figure out how
to<br>
>use Python with it, but I'm sure my mojo will rise soon.<br>
><br>
>Rob<br>
><br>
>Got Python?<br>
><a href=3D"http://www.lowerstandard.com/python/pythonsource.html"
eudora=3D"autourl">http://www.lowerstandard.com/python/pythonsource.html<=
/a><b
r>
><br>
>-----Original Message-----<br>
>From: tutor-admin@python.org [<a href=3D"mailto:tutor-admin@python.org"
eudora=3D"autourl">mailto:tutor-admin@python.org</a>]On Behalf Of<br>
>Kalle Svensson<br>
>Sent: Tuesday, May 15, 2001 8:10 AM<br>
>To: tutor@python.org<br>
>Subject: Re: [Tutor] PyXML Help?<br>
><br>
><br>
>Sez Michael P. Reilly [about XML Processing with Python]:<br>
>> I'd never recommend that book.=A0 I'd suggest O'Reilly's "Learning XML=
"
and<br>
>> reading the Python documentation and XML-SIG.=A0 You'd be better off
IMO.<br>
>> (At least the O'Reilly has the definition of XML components and DTD
to<br>
>> refer to if you need them.)<br>
><br>
>I recently bought "XML in a Nutshell", also from O'Reilly.=A0 I
thoroughly<br>
>recommend it for anyone with some experience with HTML or SGML and<br>
>programming (in python or otherwise).=A0 It was quite sufficient for me
to<br>
>learn XML from, and has a good reference section.<br>
><br>
>Peace,<br>
>=A0 Kalle<br>
>--<br>
>Email: kalle@gnupung.net=A0=A0=A0=A0 | You can tune a filesystem, but yo=
u<br>
>Web: <a href=3D"http://www.gnupung.net/"
eudora=3D"autourl">http://www.gnupung.net/</a> | can't tune a fish. -- ma=
n
tunefs(8)<br>
>PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD<br>
>=A0[ Not signed due to lossage.=A0 Blame Microsoft Outlook Express. ]<br=
>
><br>
>_______________________________________________<br>
>Tutor maillist=A0 -=A0 Tutor@python.org<br>
><a href=3D"http://mail.python.org/mailman/listinfo/tutor"
eudora=3D"autourl">http://mail.python.org/mailman/listinfo/tutor</a><br>
><br>
><br>
>_______________________________________________<br>
>Tutor maillist=A0 -=A0 Tutor@python.org<br>
><a href=3D"http://mail.python.org/mailman/listinfo/tutor"
eudora=3D"autourl">http://mail.python.org/mailman/listinfo/tutor</a></blo=
ckquo
te>
><x-sigsep><p></x-sigsep>
>**************************** <br>
>Kojo Idrissa <br>
>=A0 <br>
>kojo@hal-pc.org<br>
><a href=3D"http://www.hal-pc.org/~kojo/"
eudora=3D"autourl">http</a>://www.hal-pc.org<a
href=3D"http://www.hal-pc.org/~kojo/" eudora=3D"autourl">/~kojo/</a><br>
>****************************</html>
>
>--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D_595239=
168=3D=3D_.ALT--
>
>
>
>
>--__--__--
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>End of Tutor Digest
>

_________________________________________________________
FREE Corporate Web-hosting, 20MB space, 30 Email accounts
Get Your Own Domain at http://www.iRepublics.com

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



From r.b.rigilink@chello.nl  Tue May 15 18:45:24 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Tue, 15 May 2001 19:45:24 +0200
Subject: [Tutor] Simplicity vs. Speed
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D771@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3B016B34.EF885B77@chello.nl>

alan.gauld@bt.com wrote:
> 
> > Especially since simplest is usually also fastest.
> 
> Sorry I've got to disagree with that one. Simple algorithms are
> often fast enough but they are rarely optimal. (Consider bubble
> sort, or the shuffle discussion recently). So keep it simple
> by all means but better(ie faster!) algorithms usually carry
> the cost of increased complexity...
> 

Hmm,

I thought about this a bit.

First, you are of course right. My statement was a one sentence
assertion about programming in general. I would say that any meaningful
one-sentence assertion about a sufficiently complicated subject is
either tautological or hogwash.
This one wasn't tautological.

Having said that, I was thinking more about program units (modules,
classes) that perform several functions than about algorithms that
perform one function. 

However, the context was optimization, which is an algorithm issue. And
you are right the fastest algorithm is not necessarily the simplest.
Moreover, even the fastest algorithm can often be made faster by
special-casing, at even more cost to simplicity.

> Everything else in your post I agree with BTW. Especially the
> 3 way categorisation of slowness.
> 
> Alan g.

Roeland

-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From lsloan@umich.edu  Tue May 15 19:29:00 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Tue, 15 May 2001 14:29:00 -0400
Subject: [Tutor] setting environment variables in apache
In-Reply-To: Your message of "Tue, 15 May 2001 10:27:40 +1000."
 <Pine.OSF.4.30.0105151024290.14516-100000@student.uq.edu.au>
Message-ID: <200105151829.OAA08901@birds.us.itd.umich.edu>

Suzanne Little wrote:
> Phew! Sorry should have finished reading the deja search results before I
> posted. I've written a little wrapper script to set the variable, as
> below, which appears to have solved the problem. Apparently either doing
> this or using some thing in apache called SetEnv is the only way to do
> this.
>
> #!/usr/local/bin/bash
> LD_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/mysql
> export LD_LIBRARY_PATH
> /.../bootup3.py

Yes, you're right.  The error comes from Python not being able to
find the shared library it needs.  It's too late to fix it from
within a Python script.  I had problems like this right after I
built Python (and Perl, too).  What I ended up doing is relinking
Python using the "-R" option and giving the path to the library it
was looking for.  That option sets the "RPATH" in the executable,
which is used in addition to the path in the "LD_LIBRARY_PATH"
environment variable.

You won't need a wrapper after that.  I think you could also set
"LD_LIBRARY_PATH" in Apache's config, but that's not the best way
to hand the problem, either.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From phil.bertram@clear.net.nz  Tue May 15 20:50:18 2001
From: phil.bertram@clear.net.nz (Phil Bertram)
Date: Wed, 16 May 2001 07:50:18 +1200
Subject: [Tutor] Simplicity vs. Speed
Message-ID: <00b601c0dd7a$57df8970$873661cb@pf05nt.bayernz.co.nz>

-----Original Message-----
From: Roeland Rengelink <r.b.rigilink@chello.nl>
To: Phil Bertram <phil.bertram@clear.net.nz>
Cc: tutor@python.org <tutor@python.org>
Date: Tuesday, 15 May 2001 11:42
Subject: Re: [Tutor] Simplicity vs. Speed


[snip]
>
>let me add that a nagging feeling that another approach would be more
>elegant/shorter/neater or simply feel better is a perfectly good reason
>to rewrite your code. The nice thing is that if your feeling happens to
>be right, your code will usually become faster too.
>

And of course by re-writing my code I can learn more about programming
Learning programming is after all what I am trying to acheive !

I will rid myself of this idea that code MUST be fast.

You are 100% correct when you say, 'It is of little concern if code takes
1.5 secs compared with 1.0'



From phil.bertram@clear.net.nz  Tue May 15 21:03:55 2001
From: phil.bertram@clear.net.nz (Phil Bertram)
Date: Wed, 16 May 2001 08:03:55 +1200
Subject: [Tutor] where to start
Message-ID: <00b701c0dd7a$58be9ed0$873661cb@pf05nt.bayernz.co.nz>

This is a multi-part message in MIME format.

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

My experience is one of spending days and days playing around with the =
GUI part until my brain ceased to function. At the end I had acheived =
little.

I then just coded every thing as a command-line program until it was =
pretty good.

It was a lot easier to then just build a simple functional GUI that =
simply called methods in my command-line module's code. I did not worry =
about how my GUI looked as long as it was working.

I did find it useful to use a text window in the GUI to print little =
debugging statements into eg. a Tkinter.Text object.

When I was happy all was OK I removed my 'debugging' window and played =
around with my GUI to make it look better.

Phil B
  -----Original Message-----
  From: Katharine Stoner <kstoner@netins.net>
  To: python tutor <tutor@python.org>
  Date: Wednesday, 16 May 2001 12:34=20
  Subject: [Tutor] where to start


  I wanted to know how do you go about starting a large program.  Where =
do you start on it?  The ideas I have involve making windows, but I =
don't know how to start them.  I'm still researching the widgets and =
making windows.  Should I just plow on through or what?

  thanks

  -Cameron


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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>My experience is one of spending days and days =
playing around=20
with the GUI part until my brain ceased to function. At the end I had =
acheived=20
little.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I then just coded every thing as a command-line =
program until=20
it was pretty good.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>It was a lot easier to then just build a simple =
functional GUI=20
that simply called methods in my command-line module's code. I did not =
worry=20
about how my GUI looked as long as it was working.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I did find it useful to use a text window in the GUI =
to print=20
little debugging statements into&nbsp;eg. a Tkinter.Text =
object.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>When I was happy all was OK I removed my 'debugging' =
window=20
and played around with my GUI to make it look better.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Phil B</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px =
solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2><B>-----Original =
Message-----</B><BR><B>From:=20
  </B>Katharine Stoner &lt;<A=20
  =
href=3D"mailto:kstoner@netins.net">kstoner@netins.net</A>&gt;<BR><B>To:=20
  </B>python tutor &lt;<A=20
  href=3D"mailto:tutor@python.org">tutor@python.org</A>&gt;<BR><B>Date:=20
  </B>Wednesday, 16 May 2001 12:34 <BR><B>Subject: </B>[Tutor] where to=20
  start<BR><BR></DIV></FONT>
  <DIV><FONT face=3DArial size=3D2>I wanted to know how do you go about =
starting a=20
  large program.&nbsp; Where do you start on it?&nbsp; The ideas I have =
involve=20
  making windows, but I don't know how to start them.&nbsp; I'm still=20
  researching the widgets and making windows.&nbsp; Should I just plow =
on=20
  through or what?</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>thanks</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>-Cameron</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_00AF_01C0DDDE.C12130F0--



From scarblac@pino.selwerd.nl  Tue May 15 23:01:49 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 16 May 2001 00:01:49 +0200
Subject: [Tutor] Simplicity vs. Speed
In-Reply-To: <00b601c0dd7a$57df8970$873661cb@pf05nt.bayernz.co.nz>; from phil.bertram@clear.net.nz on Wed, May 16, 2001 at 07:50:18AM +1200
References: <00b601c0dd7a$57df8970$873661cb@pf05nt.bayernz.co.nz>
Message-ID: <20010516000149.A6379@pino.selwerd.nl>

On  0, Phil Bertram <phil.bertram@clear.net.nz> wrote:
> I will rid myself of this idea that code MUST be fast.
> 
> You are 100% correct when you say, 'It is of little concern if code takes
> 1.5 secs compared with 1.0'

"We should forget about small efficiencies, say about 97% of the time:
premature optimization is the root of all evil." -- Donald Knuth

To find the exact quote, I did a quick Google search for "premature
optimization". One of the hits was this cool little rant:
http://billharlan.com/pub/papers/A_Tirade_Against_the_Cult_of_Performance.html

Which has the following cool quotes as well:
   "Anyway, most optimization is local. Design is global."
   "It is easier to optimize correct code than to correct optimized code."
   
-- 
Remco Gerlich


From arthur.watts@gbst.com  Tue May 15 23:06:30 2001
From: arthur.watts@gbst.com (Arthur Watts)
Date: Wed, 16 May 2001 08:06:30 +1000
Subject: [Tutor] Education vs Employment
Message-ID: <1CDB101F0CB6D311882F0000F8063924036151DD@aquarius.bne.star.com.au>

Guys,

	Having read the recent posts regarding the penchant that US
employers seem to have for hiring only those with specific degrees, I'd have
to say that this is very much the case here in Oz. When I returned to Uni in
'92 as a mature-age student, I had to decide between a Computing degree and
an Arts degree. It came down to 3 years of student poverty either way, and I
reasoned that I would have some chance of earning more than $30,000 pa if I
chose I.T. It was just a fact of life - the only people who seem to hire
fresh Arts graduates are Government agencies, and they aren't known for
their fiscal generosity. 

	I agree with everything previously mentioned re the advantages of a
(Liberal) Arts background, but the sad fact is that IT employers (including
mine) have a 'tick sheet'. They use this to shortlist as few candidates as
possible for each position - 'Drivers License - Tick; IT Degree : Tick' etc.
Sadly, some employers have now adopted the headhunter strategy of including
flavour-of-the-month languages in their tick sheet : '5 years Java
experience : Tick' (I think that means they want James Gosling..) and so on.
Academia has fared no better : some of the best lecturers I had at Uni were
told that they would need to upgade their Masters degrees to Doctorates if
they wished to continue lecturing. If your lecturers were like mine, the
title 'Dr' before a lecturers name provided no indication of their ability
to actually impart wisdom. Many belonged behind closed (locked, if possible)
doors !

	Finally, the fact that people like Guido and Larry (Wall) don't come
from 'pure IT' backgrounds should be enough to convince the majority of us
that it's not the piece of paper, its the person. This doesn't help those of
you who don't get shortlisted for an interview because of the almighty 'tick
sheet', so I can only suggest that you try to contribute toward an Open
Source project  / write doco for same etc. Not only will this provide
practical evidence of your skills, but it will provide contacts who may be
able to get you an interview with their employer or, at the very least,
provide a written reference to testify to your skills. I believe that an
increasingly large part of IT projects are *not* about coding (is
architecture about bricklaying ?), and the wit and ability to communicate
shown by the regulars on this list tells me that the industry needs more
people like you guys. If that means reversing the 'vocational education'
revolution which swept thru Oz in the 80's, then so be it !

Regards,

Arthur


From deirdre@deirdre.net  Tue May 15 23:27:09 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Tue, 15 May 2001 15:27:09 -0700
Subject: [Tutor] Education vs Employment
In-Reply-To: <1CDB101F0CB6D311882F0000F8063924036151DD@aquarius.bne.star.com.au>
References: <1CDB101F0CB6D311882F0000F8063924036151DD@aquarius.bne.star.com.au>
Message-ID: <a05100e16b7275cd8bc4e@[10.0.1.24]>

>	I agree with everything previously mentioned re the advantages of a
>(Liberal) Arts background, but the sad fact is that IT employers (including
>mine) have a 'tick sheet'. They use this to shortlist as few candidates as
>possible for each position - 'Drivers License - Tick; IT Degree : Tick' etc.

Well, I think I can most concisely say why I value my liberal arts 
degree in the following manner:

I learned more about the business of being a coder from Machiavelli 
than from Knuth.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From dyoo@hkn.eecs.berkeley.edu  Tue May 15 23:37:04 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 15 May 2001 15:37:04 -0700 (PDT)
Subject: [Tutor] anyone know how to get installer to work?
In-Reply-To: <4.3.2.7.0.20010514224201.00ab9da0@mail.flex.com>
Message-ID: <Pine.LNX.4.21.0105151530580.25187-100000@hkn.eecs.berkeley.edu>

On Mon, 14 May 2001, Brett wrote:

> I'm trying to learn how to use Tkinter, so I'm doing a project for my math 
> class using python.  I spent like 10 hours writing like 200 lines of code(I 
> had no idea what I was doing when I started)  and got ready to turn it into 
> an executable I can turn in.  Now, 2 hours later, I can't get standalone.py 
> to work.  It makes a dist_project, but when I try to run it it gives me a

Just wondering, how are you turning it into an executable?  Are you using
McMillian's Installer program?

> I have no clue what this means.  I already uninstalled python and 
> reinstalled python 2.0 and Installer installer20_3i.  Can anyone help, or 

Ah, ok, so it appears that you're using McMillian's Installer program.  
Have you tried py2exe?  I've heard that it's a lot easier to work
with.  py2exe can be found here:

    http://py2exe.sourceforge.net/


> traceback...:
> file c:\python\lib\impututil.py...
> No module named time.

I have not been able to find this file as part of the standard module
library; does anyone know what impututil.py does?  The closest I've found
to it is "imputil.py".  And even then, I don't see a reference to time
within that file either.

Try out py2exe first, and tell us if that works for you.  Good luck!



From dyoo@hkn.eecs.berkeley.edu  Wed May 16 00:26:06 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 15 May 2001 16:26:06 -0700 (PDT)
Subject: [Tutor] Values being skipped-Iteration
In-Reply-To: <200105140223_MC2-D0D2-2B21@compuserve.com>
Message-ID: <Pine.LNX.4.21.0105151617040.25187-100000@hkn.eecs.berkeley.edu>

On Mon, 14 May 2001, Sharriff Aina wrote:

> Hi guys!
>=20
> I=B4m retrieving values from a databse:

Has anyone responded to your question yet?  Just want to make sure that
we haven't ignored your question or anything.


> my problem is very embarassing, the loop skips values it always generates
> the first chunk it gets, but if values are skipped on the form (example:
> choosing checkbox 1, 2 ,6) the HTML chinks 1 and 2 would be printed but n=
ot
> 6!! if one chooses all of the checkboxes without any gaps the loop works.



> I generate chunks of HTML depending on what I get from these values:
>=20
> ### code start ###
> templinks =3D alllinks[0]
> links =3D string.split(templinks[0],",")

It might be helpful to print out what templinks[0] contains.  If this
string contains all your checkbox values, it will be a safe thing to make
sure that we're getting those values correctly.  I'm assuming that
templinks[0] has the following structure:

    "Home,Aktuelles,..."

but it would be safer just to see that we're reading the checkbox values
properly.  Let's try to isolate where the problem is beginning; I don't
see anything wrong in your for loop so far, so it must be something
else.


Is it possible that, if the person doesn't include a checkbox like the
first one, that we get a templinks[0] string like this?

    ",Aktuelles,..."

What happens in the "else:" clause of your conditions, if the link name
doesn't fit with any of the values you expected?  I'm just spouting a
bunch of "What if?"'s, because there still some incomplete knowledge here.

Tell us a little more about what templinks[0] looks like if you don't
check a few of those boxes.  From there, we should be able to figure out
what's happening.

Good luck!



From kojo@hal-pc.org  Wed May 16 00:57:56 2001
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Tue, 15 May 2001 18:57:56 -0500
Subject: [Tutor] Education vs Employment
In-Reply-To: <1CDB101F0CB6D311882F0000F8063924036151DD@aquarius.bne.star
 .com.au>
Message-ID: <5.0.2.1.0.20010515185109.00af2c18@Pop3.norton.antivirus>

Ok, I'd avoided posting this to the list because it was a bit off-topic, 
but since we seem to be having a related discussion...

I have an Accounting BBA, and I just left an Accounting PhD program to come 
back to my undergrad institution and start work on a BS in Comp Sci. in the 
fall.  A little more detail about why a BS, not an MS is at the link below.

<http://www.hal-pc.org/~kojo/what.html#noMS>

Point #2 listed there is probably closest to what Deirdre and Arthur have 
commented on .   Taking that into account, I just wanted to get the group's 
opinion on my reasoning.

BTW, I choose Comp Sci because it's what I've wanted to do for quite some 
time...it just took me awhile to figure that out.

TIA,


At 08:06 AM 5/16/2001 +1000, Arthur Watts wrote:
>Guys,

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

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



From brett42@flex.com  Wed May 16 01:46:03 2001
From: brett42@flex.com (Brett)
Date: Tue, 15 May 2001 14:46:03 -1000
Subject: [Tutor] Re Installer problems: thanks
In-Reply-To: <E14zmwB-0000jE-00@mail.python.org>
Message-ID: <4.3.2.7.0.20010515144500.00aa9f00@mail.flex.com>

I still can't get installer to work, but py2exe works fine.  Thanks for 
recommending it.
When Schrodinger's cat's away,
the mice may or may not play,
no one can tell.



From kstoner@netins.net  Wed May 16 03:14:17 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Tue, 15 May 2001 21:14:17 -0500
Subject: [Tutor] sending data
Message-ID: <000a01c0ddad$e9ced1a0$aa52b1cf@oemcomputer>

This is a multi-part message in MIME format.

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

How do you send data from one class to another and can you make one =
string equal another and it still make sense?  Send me in the right =
direction and I can take it from there.

ex:

"A" =3D "1"
"B" =3D "2"

Thanks for the help.

Cameron

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>How do you send data from one class to =
another and=20
can you make one string equal another&nbsp;and it still make =
sense?&nbsp; Send=20
me in the right direction and I can take it from there.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>ex:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"A" =3D "1"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>"B" =3D "2"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks for the help.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron</FONT></DIV></BODY></HTML>

------=_NextPart_000_0007_01C0DD84.00402800--



From dyoo@hkn.eecs.berkeley.edu  Wed May 16 03:25:52 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 15 May 2001 19:25:52 -0700 (PDT)
Subject: [Tutor] Turtle graphics?
Message-ID: <Pine.LNX.4.21.0105151923510.31635-100000@hkn.eecs.berkeley.edu>

I remember hearing about turtle graphics a bit.  Does anyone have a
recommendation on a good turtle graphics module?  I'm beginning to read a
book about fractals, and apparently, it's very possible to draw fractals
really easily if one thinks of oneself as a turtle.

I know that the Python distribution comes with a sample turtle module.  
Can anyone suggest others?  Thanks!



From deirdre@deirdre.net  Wed May 16 03:31:56 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Tue, 15 May 2001 19:31:56 -0700
Subject: [Tutor] Turtle graphics?
In-Reply-To: <Pine.LNX.4.21.0105151923510.31635-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105151923510.31635-100000@hkn.eecs.berkeley.edu>
Message-ID: <a05100e2cb72796fd5d1d@[10.0.1.24]>

At 7:25 PM -0700 5/15/01, Daniel Yoo wrote:
>I remember hearing about turtle graphics a bit.  Does anyone have a
>recommendation on a good turtle graphics module?  I'm beginning to read a
>book about fractals, and apparently, it's very possible to draw fractals
>really easily if one thinks of oneself as a turtle.

Really? How *very* cool

>I know that the Python distribution comes with a sample turtle module.
>Can anyone suggest others?  Thanks!

No, but I'm fascinated by the concept.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From rob@jam.rr.com  Wed May 16 03:35:08 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Tue, 15 May 2001 21:35:08 -0500
Subject: [Tutor] sending data
References: <000a01c0ddad$e9ced1a0$aa52b1cf@oemcomputer>
Message-ID: <3B01E75C.F609C0A1@jam.rr.com>

You might find the Python Tutorial helpful here. The URL is:
http://www.python.org/doc/current/tut/tut.html but it's quite likely you
have a copy of the tutorial on your computer installed with Python.

Rob

> Katharine Stoner wrote:
> 
> How do you send data from one class to another and can you make one
> string equal another and it still make sense?  Send me in the right
> direction and I can take it from there.
> 
> ex:
> 
> "A" = "1"
> "B" = "2"
> 
> Thanks for the help.
> 
> Cameron

-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From tsaritsino@newacropol.ru  Wed May 16 04:26:21 2001
From: tsaritsino@newacropol.ru (tsaritsino@newacropol.ru)
Date: 16 May 2001 03:26:21 -0000
Subject: [Tutor] ðïíïçéôå òåûéôø ðòïâìåíõ üëïìïçéé ÷ ãáòéãùîï!
Message-ID: <20010516032621.48284.qmail@mu.pair.com>

This is a MIME encoded message.

--b102382cbf1c8fe2a562c783c479a9df4
Content-Type: text/html ;	charset="windows-1251"
Content-Transfer-Encoding: base64

PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIj4NCg0KPGh0bWw+DQo8aGVhZD4NCgk8dGl0bGU+zcUg1c7XxdLR3yDB29LcINDAws3OxNPY
zdvMPC90aXRsZT4NCjwvaGVhZD4NCg0KPGJvZHk+DQo8ZGl2IGFsaWduPSJDRU5URVIiPjxmb250
IGZhY2U9IiIgY29sb3I9IkJsdWUiPjxoMj7NxSDVztfF0tHfIMHb0twg0MDCzc7E09jN28w8L2gy
PjwvZm9udD48L2Rpdj4NCiZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwOyZuYnNwO8ru4+Tg
IOz7IPHr+/jo7CDx6+7i7iAi/eru6+7j6P8iLCDy7iDk8+zg5ewsIPfy7iD98u4g4+TlLfLuIOTg
6+Xq7jogwPDg6/zx6u7lIOzu8OUsIMHg6erg6ywg7eX08v/t++Ug6uDy4PHy8O70+4UgzuTt4Oru
IP3q7uvu4+j35fHq6OUg7/Du4evl7Psg7urw8+bg/vIg7eDxIO/u4vHl5O3l4u3uLiDKIOzz8e7w
8yDoIOPw/+foIOLu6vDz4yDs+yDz5uUg5ODi7e4g7/Do4vvq6+gsIOgg5ODm5SDt5SDi5fDo8vH/
LCD38u4g4u7n7O7m7e4g9/LuLfLuIOjn7OXt6PL8LiDP4PDq6CDoIOzl8fLgIO7y5Pv14CDv7vDu
6SDt4O/u7Ojt4P7yIOzz8e7w7fvlIPHi4Ovq6C4gwvHlIOzl7fz45SDx8uDt7uLo8vH/IOzl8fIs
IOPk5SDv8Oj/8u3uIO/w7uLl8fLoIOL79e7k7e7pIOTl7fwuPGJyPg0KJm5ic3A7Jm5ic3A7Jm5i
c3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7ze4g8ejy8+D26P8g7eUg4eXn7eDk5ebt4CEgzuH65eTo7eXt
7fvlIPPx6Ovo/yDr/uTl6Swg6u7y7vD75SDw5eDr/O3uIPXu8v/yIPfy7i3y7iDo5+zl7ejy/Cwg
8e/u8e7h7fsg8uLu8Ojy/CD38+Tl8eAuINLg6iwgMjkg4O/w5ev/IDIwMDEg4+7k4CDt4CD96u7r
7uPo9+Xx6u7pIODq9ujoIOIg7+Dw6uUgPGEgaHJlZj0iaHR0cDovL3d3dy5uZXdhY3JvcG9sLnJ1
L21haW4wXzBfMC5waHAzP2lkMT10c2FyaXRzaW5vX2hpc3QiPiLW4PDo9vvt7iI8L2E+IOIgzO7x
6uLlLCDu8OPg7ejn7uLg7e3u6SDoIO/w7uLl5OXt7e7pIMrz6/zy8/Dt++wg9uXt8vDu7CA8YSBo
cmVmPSJodHRwOi8vd3d3Lm5ld2Fjcm9wb2wucnUgIj4ize7i++kgwOrw7u/u6/wiPC9hPiwg4fvr
7iDx7uHw4O3uIOHu6+XlIDE1LfLoIPLu7e0g7PPx7vDgIDxhIGhyZWY9Imh0dHA6Ly93d3cucGhv
dG90YXNzLnJ1L25ld3NfaW5mby5hc3A/bmV3c19pZD0xMTg2MDEgIj4o/fLuIOHu6+XlIDkwMCDx
8u7r6PLw7uL79SDs5fjq7uIpPC9hPi4gyiAyNTAg9+vl7eDsIMrz6/zy8/Dt7uPuIPbl7fLw4CDv
8Ojx7uXk6O3o6+7x/CA8YSBocmVmPSJodHRwOi8vd3d3LnBob3RvdGFzcy5ydS9uZXdzX2luZm8u
YXNwP25ld3NfaWQ9MTE4NjAzIj4g7uru6+4gMTUwIO/u8eXy6PLl6+XpPC9hPiAg7+Dw6uAuINHr
8/fg6e375SDv8O717ubo5SDy4Orm5SDt5SDu8fLg6+jx/CDiIPHy7vDu7eUuPGJyPg0KJm5ic3A7
Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7zuTt4OruIO7k6O0g8ODnIO736PHy6PL8IO/g
8Oog7ODr7iAtIOzz8e7wIO/u/+Lo8vH/IOLt7uL8LiDCICLW4PDo9vvt7iIsIOjx8u7w6Pfl8eru
7CA8YSBocmVmPSJodHRwOi8vd3d3LnBob3RvdGFzcy5ydS9uZXdzX2luZm8uYXNwP25ld3NfaWQ9
MTE4NjAwIj7v4PDq5S3z8eDk/OHlPC9hPiAsIP3r5ezl7fLg8O3uIO3l8iDz8O0sIOgg7+798u7s
8yDiIPXu5OUg4Or26Ogg4fvr6CDz8fLg7e7i6+Xt+yDv5fDi++UgMTAg8/DtLCDw4Ofw4OHu8uDt
7fvlIO/uIPHv5fbo4Ov87e7s8yDv8O7l6vLzICjv7uTw7uHt5eUg8ezu8vDo8uUgPGEgaHJlZj0i
aHR0cDovL3d3dy5uZXdhY3JvcG9sLnJ1L21haW4wXzBfMC5waHAzP2lkMT10c2FyaXRzaW5vX2lu
ZiI+5+Tl8fw8L2E+KSDoIOL77+7r7eXt7fvlIOIg4PD16PLl6vLz8O3u7CDx8ujr5SDv4PDq4C4g
wvHl4+4g7+Dw6vMg8vDl4fPl8vH/IOHu6+XlIDUwLfLoIPLg6uj1IPPw7SDoIPHy4Pbo7u3g8O37
5SDq7u3y5ent5fD7IOTr/yDx4e7w4CDs8/Hu8OAuIDxicj4NCsrz6/zy8/Dt++kg9uXt8vAgIs3u
4vvpIMDq8O7v7uv8IiDj7vLu4iDi5//y/CDt4CDx5eH/IOjn4+7y7uLr5e3o5SDz8O0g6CDk5ebz
8PHy4u4g7+4g8eHu8PMg6CDi++Lu5/Mg7PPx7vDgIOjnIO/g8OrgLCDt7iDt5SDs7ubl8iD06O3g
7fHo8O7i4PL8IP3y8yDk5f/y5ev87e7x8vwuIM/w6Ozl8O3g/yDx7OXy7eD/IPHy7ujs7vHy/CDv
8OXk8fLu//no9SDw4OHu8joNCg0KPHRhYmxlIGJnY29sb3I9ImJsYWNrIiBib3JkZXI9IjAiIGNl
bGxwYWRkaW5nPSI1IiBjZWxsc3BhY2luZz0iMSI+DQo8dHIgYmdjb2xvcj0id2hpdGUiPg0KCTx0
ZD48L3RkPg0KCTx0ZD7W5e3gLCDw8+EuPC90ZD4NCgk8dGQgYWxpZ249IlJJR0hUIj7K7ust4u48
L3RkPg0KCTx0ZD7R8+zs4Cwg8PPhLjwvdGQ+DQo8L3RyPg0KPHRyIGJnY29sb3I9IndoaXRlIj4N
Cgk8dGQ+yOfj7vLu4uvl7ejlIPPw7fssIPDg5+7i7jwvdGQ+DQoJPHRkIGFsaWduPSJSSUdIVCI+
ODUwPC90ZD4NCgk8dGQgYWxpZ249IkNFTlRFUiI+NTA8L3RkPg0KCTx0ZCBhbGlnbj0iUklHSFQi
PjQyIDUwMDwvdGQ+DQo8L3RyPg0KPHRyIGJnY29sb3I9IndoaXRlIj4NCgk8dGQ+z+7q8+/q4CDq
7u3y5ent5fDgLCDw4Ofu4u48L3RkPg0KCTx0ZCBhbGlnbj0iUklHSFQiPjggMDAwPC90ZD4NCgk8
dGQgYWxpZ249IkNFTlRFUiI+MjwvdGQ+DQoJPHRkIGFsaWduPSJSSUdIVCI+MTYgMDAwPC90ZD4N
CjwvdHI+DQo8dHIgYmdjb2xvcj0id2hpdGUiPg0KCTx0ZD7C++Lu5yDs8/Hu8OAsIOIg7OXx//Yg
KOfg6uDnIOru7fLl6e3l8OApPC90ZD4NCgk8dGQgYWxpZ249IlJJR0hUIj4xIDUwMDwvdGQ+DQoJ
PHRkIGFsaWduPSJDRU5URVIiPjI8L3RkPg0KCTx0ZCBhbGlnbj0iUklHSFQiPjMgMDAwPC90ZD4N
CjwvdHI+DQo8dHIgYmdjb2xvcj0id2hpdGUiPg0KCTx0ZD7M8/Hu8O375SDv4Orl8vssIOIg7OXx
//Y8L3RkPg0KCTx0ZCBhbGlnbj0iUklHSFQiPjI8L3RkPg0KCTx0ZCBhbGlnbj0iQ0VOVEVSIj42
NTA8L3RkPg0KCTx0ZCBhbGlnbj0iUklHSFQiPjEgMzAwPC90ZD4NCjwvdHI+DQo8dHIgYmdjb2xv
cj0id2hpdGUiPg0KCTx0ZCBjb2xzcGFuPSIzIj7I8u7j7iwg8ODn7uLuIO3l7uH17uTo7O48L3Rk
Pg0KCQ0KCTx0ZCBhbGlnbj0iUklHSFQiPjU4IDUwMDwvdGQ+DQo8L3RyPg0KPHRyIGJnY29sb3I9
IndoaXRlIj4NCgk8dGQgY29sc3Bhbj0iMyI+xebl7OXx//ft++Ug8ODx9e7k+yDx7vHy4OL/8jwv
dGQ+DQoJDQoJPHRkIGFsaWduPSJSSUdIVCI+NCAzMDA8L3RkPg0KPC90cj4NCjwvdGFibGU+DQo8
YnI+DQo8Zm9udCBmYWNlPSIiIHNpemU9IisxIiBjb2xvcj0iUmVkIj4NCiZuYnNwOyZuYnNwOyZu
YnNwOyZuYnNwOyZuYnNwOyZuYnNwO8z7IO7h8OD54OXs8f8g6u4g4vHl7Cwg6u7s8yDt5eHl5/Dg
5+vo9+37IPfo8fLu8uAg6CDv7vD/5O7qIOIg7eD45ewg4+7w7uTlLCDxIDxhIGhyZWY9Imh0dHA6
Ly93d3cubmV3YWNyb3BvbC5ydS9tYWluMF8wXzAucGhwMz9pZDE9dHNhcml0c2lub19pbmYiPu/w
7vH84e7pICDuIPTo7eDt8e7i7ukg7+7s7vnoPC9hPi4gwfPk5ewg7/Do5+3g8uXr/O37IOfgIOv+
4fP+IPHz7OzzLCDv5fDl9+jx6+Xt7fP+IO3gIPHr5eTz/vno6SDx9+XyOjwvZm9udD48YnI+PGJy
Pg0KDQo8Yj7AyiAizO7x6u7i8ero6SDM8+3o9ujv4Ov87fvpIMHg7eogLSDB4O3qIMzu8eri+yIg
4y7M7vHq4uA8YnI+DQrByMogMDQ0NTI1MjE5PGJyPg0K6u7w8C4g8ffl8iAzMDEwMTgxMDUwMDAw
MDAwMDIxOTxicj4NCvDg8fcuIPH35fIgNDA3MDM4MTAwMzgwNjAxMDAzNzQ8YnI+DQrP7uvz9+Dy
5ev8OiDNzyDK1iAgIs3u4vvpIMDq8O7v7uv8Ijxicj4NCsjNzSA3NzM3MTE2MjMyPGJyPg0KzeDn
7eD35e3o5SDv6+Dy5ebgOiDt4CDz6/P3+OXt6OUg/eru6+7j6Ogg7+Dw6uAgItbg8Oj2++3uIjwv
Yj48YnI+PGJyPg0KDQombmJzcDsmbmJzcDsmbmJzcDsmbmJzcDsmbmJzcDsmbmJzcDvM+yDj7vLu
4vsg7/Dl5O7x8uDi6//y/CDu8vfl8vsg7iDw4PH17uTu4uDt6Ogg7+7x8vPv6OL46PUg7eAg8ffl
8iDx8OXk8fLiLiDE6/8g/fLu4+4g7/Du8fzh4CDv4PDg6+vl6/zt7iDx7u7h+eDy/CDuIO/l8OX3
6PHr5e3o6CDk5e3l4yDt4CDg5PDl8SA8YSBocmVmPSJtYWlsdG86dHNhcml0c2lub0BuZXdhY3Jv
cG9sLnJ1Ij50c2FyaXRzaW5vQG5ld2Fjcm9wb2wucnU8L2E+IOjr6CDv7iDy5evl9O7t4Owg4iDM
7vHq4uU6PGJyPjxicj4NCjxiPjxkaXYgYWxpZ249IkNFTlRFUiI+MzkxLTE4LTA0LCAzOTEtMTgt
MTQ8L2Rpdj48L2I+PGJyPg0KCQ0KJm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7
wvHl7CDx7+7t8e7w4Owg4fPk8/Ig7/Dl5O7x8uDi6+Xt+yDh6+Dj7uTg8PHy4uXt7fvlIO/o8fzs
4CDu8iDK8+v88vPw7e7j7iD25e3y8OAg6CDg5Ozo7ejx8vDg9ujoIO/g8OrgLfPx4OT84fsuIMz7
IOPu8u7i+yDu4fHz5Ojy/CDr/uH75SDo7fvlIPTu8Oz7IPHu8vDz5O3o9+Xx8uLgLCDq7vLu8Pvl
IOzu4/PyIPHv7vHu4fHy4u7i4PL8IPDl+OXt6P4g/eru6+7j6Pfl8ero9SDv8O7h6+XsIO/g8Org
Ljxicj48YnI+PGJyPjxicj48YnI+DQo8Zm9udCBzaXplPSItMSI+Jm5ic3A7Jm5ic3A7Jm5ic3A7
Jm5ic3A7Jm5ic3A7Jm5ic3A70+Hl5Ojy5ev87e4g7/Du8ejsIO3lIPH36PLg8vwg5ODt7e7lIO/o
8fzs7iDt5fHg7er26O7t6PDu4uDt7e7pIPDg8fH76+ru6Swg8uDqIOrg6iDl4+4g9uXr/P4g7eUg
/+Lr/+Xy8f8g6Ofi6+X35e3o5SDq4Oru6S3r6OHuIOL74+7k+yDk6/8g7eDxLiDC4Pgg4OTw5fEg
4fvrIO/u6/P35e0g6Ocg7vTo9ujg6/zt7uPuIOjx8u737ejq4CDoLCDiIOv+4e7sIPHr8/fg5Swg
7+7i8u7w7fv1IO/o8eXsIO3lIOHz5OXyLiA8L2ZvbnQ+DQoNCjwvYm9keT4NCjwvaHRtbD4NCg==

--b102382cbf1c8fe2a562c783c479a9df4--





From wheelege@tsn.cc  Wed May 16 05:06:34 2001
From: wheelege@tsn.cc (wheelege)
Date: Wed, 16 May 2001 14:06:34 +1000
Subject: [Tutor] Turtle graphics?
References: <Pine.LNX.4.21.0105151923510.31635-100000@hkn.eecs.berkeley.edu> <a05100e2cb72796fd5d1d@[10.0.1.24]>
Message-ID: <008c01c0ddbd$99996be0$0200a8c0@ACE>

> >I know that the Python distribution comes with a sample turtle module.
> >Can anyone suggest others?  Thanks!
>
> No, but I'm fascinated by the concept.

  Indeed...logo is a language where you are a turtle drawing lines...it's
not that complex - perhaps some of the structures could be borrowed from
that and implemented in python?



From wheelege@tsn.cc  Wed May 16 05:16:07 2001
From: wheelege@tsn.cc (wheelege)
Date: Wed, 16 May 2001 14:16:07 +1000
Subject: [Tutor] sending data
References: <000a01c0ddad$e9ced1a0$aa52b1cf@oemcomputer>
Message-ID: <00dc01c0ddbe$eefda960$0200a8c0@ACE>

This is a multi-part message in MIME format.

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


  Well, saying...

"A" =3D "1" # or
"B" =3D "2"

  Is like trying to tell python that it's running on an orange, or that =
it's stored on roadkill.  It just isn't true.  One piece of data, cannot =
be assigned to another piece of data.  That is what variables are for...

A =3D '1' # or
A =3D "1" # or
A =3D 1

  Are all fine.  This stores the string '1' (and in the last case, the =
integer 1) into the variable A.  Now, to pass this onto a class method, =
just include it in the argument list.

class Jim:
  def printarg(self, arg):
    print arg

  As the class definition, then you would write...

guy =3D Jim()
guy.printarg(A)  # calls method printarg and passes the variable A to it =
(called arg in the definition)

  Hope that helped,
  Glen.



  How do you send data from one class to another and can you make one =
string equal another and it still make sense?  Send me in the right =
direction and I can take it from there.

  ex:

  "A" =3D "1"
  "B" =3D "2"

  Thanks for the help.

  Cameron

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Well, saying...</DIV>
<DIV>&nbsp;</DIV>
<DIV>"A" =3D "1" # or</DIV>
<DIV>"B" =3D "2"</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Is like trying to tell python that it's running on an =
orange, or=20
that it's stored on roadkill.&nbsp; It just isn't true.&nbsp; One piece =
of data,=20
cannot be assigned to another piece of data.&nbsp; That is what =
variables are=20
for...</DIV>
<DIV>&nbsp;</DIV>
<DIV>A =3D '1' # or</DIV>
<DIV>A =3D "1" # or</DIV>
<DIV>A =3D 1</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Are all fine.&nbsp; This stores the string '1' (and in the =
last=20
case, the integer 1) into the variable A.&nbsp; Now, to pass this onto a =
class=20
method, just include it in the argument list.</DIV>
<DIV>&nbsp;</DIV>
<DIV>class Jim:</DIV>
<DIV>&nbsp; def printarg(self, arg):</DIV>
<DIV>&nbsp;&nbsp;&nbsp; print arg</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; As the class definition, then you would write...</DIV>
<DIV>&nbsp;</DIV>
<DIV>guy =3D Jim()</DIV>
<DIV>guy.printarg(A)&nbsp; # calls method printarg and passes the =
variable A to=20
it (called arg in the definition)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Hope that helped,</DIV>
<DIV>&nbsp; Glen.</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>How do you send data from one class =
to another=20
  and can you make one string equal another&nbsp;and it still make =
sense?&nbsp;=20
  Send me in the right direction and I can take it from =
there.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>ex:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>"A" =3D "1"</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>"B" =3D "2"</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Thanks for the help.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial =
size=3D2>Cameron</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_00D9_01C0DE12.C00B0860--



From sheila@thinkspot.net  Wed May 16 05:36:23 2001
From: sheila@thinkspot.net (Sheila King)
Date: Tue, 15 May 2001 21:36:23 -0700
Subject: [Tutor] sending data
In-Reply-To: <00dc01c0ddbe$eefda960$0200a8c0@ACE>
References: <000a01c0ddad$e9ced1a0$aa52b1cf@oemcomputer> <00dc01c0ddbe$eefda960$0200a8c0@ACE>
Message-ID: <595FCD0A66@kserver.org>

On Wed, 16 May 2001 14:16:07 +1000, "wheelege" <wheelege@tsn.cc>  wrote about
Re: [Tutor] sending data:

:
:A = '1' # or
:A = "1" # or
:A = 1
:
:  Are all fine.  This stores the string '1' (and in the last case, the integer 1) into the variable A.  Now, to pass this onto a class method, just include it in the argument list.

I think it is very dangerous, in Python, to think that the data is being "stored
in a variable name", and can lead to future difficulties. While this is what
happens in other programming languages (such as Pascal, and C) this is not what
happens in Python.

In Python the variable is set to point to the object.

At least, that is how I have come to understand it. This was a very difficult
thing for me to finally get through my head (since I come from a
Pascal/C++/Basic/Fortran background, where it is as described in the quote
above). Anyhow, until I got this straight, I was very confused about how some
things work in Python.

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




From r.b.rigilink@chello.nl  Wed May 16 07:58:21 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Wed, 16 May 2001 08:58:21 +0200
Subject: [Tutor] where to start
References: <001601c0dd3a$e0818480$1752b1cf@oemcomputer>
Message-ID: <3B02250D.9642D83B@chello.nl>

> Katharine Stoner wrote:
> 
> I wanted to know how do you go about starting a large program.  Where
> do you start on it?  The ideas I have involve making windows, but I
> don't know how to start them.  I'm still researching the widgets and
> making windows.  Should I just plow on through or what?
> 
> thanks
> 
> -Cameron

Hi Cameron,

On the assumption that you allready know how to start a _small_ program,
here's my suggestion:

Every large program contains a number of small programs, struggling to
get out (Hint: the GUI is not one of them). Find those, write them, and
you're well on your way to writing the large program.

The hard question is: How do you find the small programs? Here's what I
do:

1. I get away from my computer. I'm not going to code. I'm going to
think.

2. I get a blank piece of paper and start doodling. I write down
keywords, draw arrows between related concepts. draw boxes around things
that look like a bunch of data that I do stuff with. If I'm lucky at
some point one of these boxes jumps out at me and says 'I'm a small
program, write me!'

3. No, I don't jump up and write it. I take a new blank piece of paper
and start the process over for this supposedly small program. One of two
things will happen. Either, an even smaller program will jump out at me,
or things become concrete enough that I may have an actual module or
class _that I know how to write_. Only in the latter case do I get up
and start coding again.

If I called it a design method I could write a book on it and get rich.

Hope this helps,

Roeland
-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From dyoo@hkn.eecs.berkeley.edu  Wed May 16 11:00:34 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 16 May 2001 03:00:34 -0700 (PDT)
Subject: [Tutor] where to start
In-Reply-To: <3B02250D.9642D83B@chello.nl>
Message-ID: <Pine.LNX.4.21.0105160239390.6667-100000@hkn.eecs.berkeley.edu>

On Wed, 16 May 2001, Roeland Rengelink wrote:
> The hard question is: How do you find the small programs? Here's what
> I do:
> 
> 1. I get away from my computer. I'm not going to code. I'm going to
> think.
>
> 2. I get a blank piece of paper and start doodling. I write down
> keywords, draw arrows between related concepts. draw boxes around
> things that look like a bunch of data that I do stuff with. If I'm
> lucky at some point one of these boxes jumps out at me and says 'I'm a
> small program, write me!'
>
> 3. No, I don't jump up and write it. I take a new blank piece of paper
> and start the process over for this supposedly small program. One of
> two things will happen. Either, an even smaller program will jump out
> at me, or things become concrete enough that I may have an actual
> module or class _that I know how to write_. Only in the latter case do
> I get up and start coding again.

Roeland's advice sounds like a "top-down" approach to writing a program.  
I'll play Devil's advocate for a moment.  *grin*


An opposing view: sometimes, the program that you're trying to write might
not be easy to break down at first.  This happens a lot in the kind of
ambiguous problems that people always deal with --- in this case, planning
the code is ok, but it might not be enough.  Even our understanding of a
problem might not be really "there" until we actually try coding and
running into the roadblocks.

There's another approach toward writing programs called "bottom up".  
"Bottom up" emphases writing small, working functions that you can play
around with and test as you explore the problem.  In this case, though,
the emphasis is on writing small utilities that expand our control over
the problem, until we reach the top.  So, this is sorta backwards from
Roeland's advice: "bottom up" does encourage jumping right into the deep
end of the problem.  *grin*

For example, if we're writing a web robot, a bottom-up thing would be to
try writing a function that pulls all the urls out of a string.  Such a
fragment would definitely be useful, short, and simple to test.  And we'd
gradually fill out the program as we go along.  Maybe we could also write
a function that takes in a list of urls and gives us back a list of
pages...

Both of us agree in small "functional" programs because we understand our
own humanity: sometimes, a program is just too large to hold in one's
head.  Small functions help us to handle the complexity of large problems
without mental stress.

The moderate approach, doing both "top-down" and "bottom-up" is probably
the better approach though.



From anu@gupta.co.uk  Wed May 16 12:10:14 2001
From: anu@gupta.co.uk (anu gupta)
Date: Wed, 16 May 2001 12:10:14 +0100
Subject: [Tutor] Using poplib and rfc822
In-Reply-To: <E14zspz-0002gb-00@mail.python.org>
Message-ID: <CPENJIEDGOBEBHNCOAPLIEBACDAA.anu@gupta.co.uk>

Hi all,

I'm trying to write a python pop3 client (seems like a good way for me to
learn python), and just wanted a quick piece of advice...

I can use poplib to communicate with a pop3 server, and I can use rfc822 to
parse message headers. So it would seem natural to use them together...

But, poplib brings back mesgs as (I guess) lists, and rfc822 expects file
objects (or something that has a readline method).

So, do I need to convert my messages into files, and then create rfc822
objects with these files ? I can see this would work, but it just seems a
bit clunky and inefficient - I would rather parse the message headers myself
in that case, but it seems a shame to reinvent this !

Or am I missing out on some kind of "memory based" file object that I can
use, which would eliminate the need to read/write to disk in this
intermediate step ?

Hope this makes sense !

thanks

anu



From scarblac@pino.selwerd.nl  Wed May 16 12:25:51 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 16 May 2001 13:25:51 +0200
Subject: [Tutor] Using poplib and rfc822
In-Reply-To: <CPENJIEDGOBEBHNCOAPLIEBACDAA.anu@gupta.co.uk>; from anu@gupta.co.uk on Wed, May 16, 2001 at 12:10:14PM +0100
References: <E14zspz-0002gb-00@mail.python.org> <CPENJIEDGOBEBHNCOAPLIEBACDAA.anu@gupta.co.uk>
Message-ID: <20010516132551.A7839@pino.selwerd.nl>

On  0, anu gupta <anu@gupta.co.uk> wrote:
> I'm trying to write a python pop3 client (seems like a good way for me to
> learn python), and just wanted a quick piece of advice...
> 
> I can use poplib to communicate with a pop3 server, and I can use rfc822 to
> parse message headers. So it would seem natural to use them together...
> 
> But, poplib brings back mesgs as (I guess) lists, and rfc822 expects file
> objects (or something that has a readline method).
> 
> So, do I need to convert my messages into files, and then create rfc822
> objects with these files ? I can see this would work, but it just seems a
> bit clunky and inefficient - I would rather parse the message headers myself
> in that case, but it seems a shame to reinvent this !
> 
> Or am I missing out on some kind of "memory based" file object that I can
> use, which would eliminate the need to read/write to disk in this
> intermediate step ?

Yes, the latter. It's called StringIO. In fact, there's a fast C
implementation of it called cStringIO, that's what you'd usually use.
StringIO is slower but can be subclassed.

You initialize the object with a string, and then the object can be used as
an open file with that string in it, e.g.

import cStringIO, string, rfc822

lines = ... # Get lines with poplib
buffer = cStringIO.StringIO(string.join(lines, ""))
message = rfc822.Message(buffer)

Alternatively you could have made your own little class that holds the list
of lines, and returns them one by one each time its method readline() is
called. But StringIO was made for this sort of thing.

-- 
Remco Gerlich


From arcege@speakeasy.net  Wed May 16 12:43:29 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 16 May 2001 07:43:29 -0400 (EDT)
Subject: [Tutor] Using poplib and rfc822
In-Reply-To: <CPENJIEDGOBEBHNCOAPLIEBACDAA.anu@gupta.co.uk> from "anu gupta" at May 16, 2001 12:10:14 PM
Message-ID: <200105161143.f4GBhTu12938@dsl092-074-184.bos1.dsl.speakeasy.net>

anu gupta wrote
> I'm trying to write a python pop3 client (seems like a good way for me to
> learn python), and just wanted a quick piece of advice...
> 
> I can use poplib to communicate with a pop3 server, and I can use rfc822 to
> parse message headers. So it would seem natural to use them together...
> 
> But, poplib brings back mesgs as (I guess) lists, and rfc822 expects file
> objects (or something that has a readline method).
> 
> So, do I need to convert my messages into files, and then create rfc822
> objects with these files ? I can see this would work, but it just seems a
> bit clunky and inefficient - I would rather parse the message headers myself
> in that case, but it seems a shame to reinvent this !
> 
> Or am I missing out on some kind of "memory based" file object that I can
> use, which would eliminate the need to read/write to disk in this
> intermediate step ?

Yup, you can use the StringIO module (or cStringIO, a faster C module).

# get the StringIO class, preferably the C implementation
try:
  from cStringIO import StringIO
except ImportError:
  from StringIO import StringIO

popsvr = poplib.POP(...)
rspc, lines, octets = popsvr.retr(msgn)
file = StringIO()
for line in lines:
  file.write(line + '\n') # popsvr strips off the EOLN character
file.seek(0)
msg = rfc822.Message(file)

The StringIO uses memory for the storage.  But be careful of large
messages, a megabyte e-mail will be stored in memory with the rest of
your program data.

Good luck,
  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From kent@springfed.com  Wed May 16 13:03:30 2001
From: kent@springfed.com (Kent Tenney)
Date: Wed, 16 May 2001 07:03:30 -0500
Subject: [Tutor] Using Python instead of VB in ASP with IIS
Message-ID: <200105161407.HAA01098@svc1.netwk-innov.net>

Howdy,

Is there a convenient source of info on the
configuration required to allow server side
ASP pages to employ Python code?

Thanks,
Kent
-- Kent Tenney, kent@springfed.com on 05/16/2001



From lsloan@umich.edu  Wed May 16 14:44:38 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Wed, 16 May 2001 09:44:38 -0400
Subject: [Tutor] Education vs Employment
In-Reply-To: Your message of "Tue, 15 May 2001 18:57:56 CDT."
 <5.0.2.1.0.20010515185109.00af2c18@Pop3.norton.antivirus>
Message-ID: <200105161344.JAA22018@birds.us.itd.umich.edu>

Kojo Idrissa wrote:
> Point #2 listed there is probably closest to what Deirdre and Arthur have 
> commented on .   Taking that into account, I just wanted to get the group's 
> opinion on my reasoning.

Basically, if you can't beat 'em, join 'em, right?  You can't change
every employer's mind that a CS degree is required, so you might as
well meet the requirement if you want the jobs.  Of course, you run
the risk of working for an employer that's closed-minded, but when you
need a job, you need a job.

Reminds me of the funny looks I get when I tell people that hackers are
the good guys.

I do have a BS CS degree and it's the only one I have.  I've considered
going for a MS, but in Library Science.  However, if I ever get around
to it, I may decide that it should be a CS in Library Science.  Who
knows?

I really do sympathize for good programmers who are discriminated
against for their non-CS education.  I know several good programmers
and sysadmins who have arts, Linguistics, and English degrees.  I even
know one person who has no college degree at all who is doing quite
well.  (But I swear he must have studied nothing but Machiavelli, which
lends some credence to what Deirdre wrote earlier.)

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From lsloan@umich.edu  Wed May 16 15:05:20 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Wed, 16 May 2001 10:05:20 -0400
Subject: [Tutor] Turtle graphics?
In-Reply-To: Your message of "Tue, 15 May 2001 19:25:52 PDT."
 <Pine.LNX.4.21.0105151923510.31635-100000@hkn.eecs.berkeley.edu>
Message-ID: <200105161405.KAA22370@birds.us.itd.umich.edu>

Daniel Yoo wrote:
> I know that the Python distribution comes with a sample turtle module.  
> Can anyone suggest others?  Thanks!

I'll let you know if I find any.  Turtle graphics has fond memories for
me.  It was the first computer "programming" I ever learned.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From bdupire@seatech.fau.edu  Wed May 16 15:26:32 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Wed, 16 May 2001 10:26:32 -0400
Subject: [Tutor] singleton pattern
Message-ID: <3B028E18.98B0B23B@seatech.fau.edu>

--------------82EB25BA2AB6BFFC2AB4A1E5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I would like to implement a  class dubbed "Factory " with the singleton
pattern, so that i only have a single "factory" object, that
instantiates some shared objects (pretty much in the same way than in
the Flyweight pattern)

This works

class Factory:
    def __init__(self):
        # Do something
        pass
    def __call__(self):
        return self

Factory = Factory()

which is a nice solution (not from me ! :o) )
The problem is that i already have a __call__ method implemented in my
Factory class.
Python unfortunately does not support overriding...
Solution 1 is to rename my previous __call__ method...
Solution 2 is to find another implementation

I wrote the following, but static methods do not seem to exist in Python

class Factory:
    _instance = None
    def getInstance():
        if Factory._instance== None:
            Factory._instance= Foo()
        return Factory._instance
    def setA(self, a):
        self.a = a
    def getA(self):
        return self.a

>>> b= Factory.getInstance()
Traceback (innermost last):
  File "<pyshell#77>", line 1, in ?
    b= Factory.getInstance()
TypeError: unbound method must be called with class instance 1st
argument

Do i have to implement it as a separate function ?
I think something like what is below would do the job.. but is there a
way to implement static methods ?

class Factory:
    _instance = None
    <bla - bla >

def getFactory:
    if Factory._instance ==None:
        Factory.__instance = Factory()
    return Factory.__instance



benoit




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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I would like to implement a&nbsp; class dubbed "Factory " with the singleton
pattern, so that i only have a single "factory" object, that instantiates
some shared objects (pretty much in the same way than in the Flyweight
pattern)<b></b>
<p>This works<b></b>
<p><tt>class Factory:</tt>
<br><tt>&nbsp;&nbsp;&nbsp; def __init__(self):</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Do something</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass</tt>
<br><tt>&nbsp;&nbsp;&nbsp; def __call__(self):</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self</tt><tt></tt>
<p><tt>Factory = Factory()</tt><b></b>
<p>which is a nice solution (not from me ! :o) )
<br>The problem is that i already have a __call__ method implemented in
my Factory class.
<br>Python unfortunately does not support overriding...
<br>Solution 1 is to rename my previous __call__ method...
<br>Solution 2 is to find another implementation
<p>I wrote the following, but static methods do not seem to exist in Python
<p><tt>class Factory:</tt>
<br><tt>&nbsp;&nbsp;&nbsp; _instance = None</tt>
<br><tt>&nbsp;&nbsp;&nbsp; def getInstance():</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if Factory._instance==
None:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Factory._instance= Foo()</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Factory._instance</tt>
<br><tt>&nbsp;&nbsp;&nbsp; def setA(self, a):</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.a = a</tt>
<br><tt>&nbsp;&nbsp;&nbsp; def getA(self):</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.a</tt><tt></tt>
<p><tt>>>> b= Factory.getInstance()</tt>
<br><tt>Traceback (innermost last):</tt>
<br><tt>&nbsp; File "&lt;pyshell#77>", line 1, in ?</tt>
<br><tt>&nbsp;&nbsp;&nbsp; b= Factory.getInstance()</tt>
<br><tt>TypeError: unbound method must be called with class instance 1st
argument</tt>
<p>Do i have to implement it as a separate function ?
<br>I think something like what is below would do the job.. but is there
a way to implement static methods ?
<p><tt>class Factory:</tt>
<br><tt>&nbsp;&nbsp;&nbsp; _instance = None</tt>
<br><tt>&nbsp;&nbsp;&nbsp; &lt;bla - bla ></tt><tt></tt>
<p><tt>def getFactory:</tt>
<br><tt>&nbsp;&nbsp;&nbsp; if Factory._instance ==None:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Factory.__instance =
Factory()</tt>
<br><tt>&nbsp;&nbsp;&nbsp; return Factory.__instance</tt>
<br><tt></tt>&nbsp;
<br><tt></tt>&nbsp;<tt></tt>
<p><tt>benoit</tt>
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;</html>

--------------82EB25BA2AB6BFFC2AB4A1E5--



From shaleh@valinux.com  Wed May 16 16:03:17 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Wed, 16 May 2001 08:03:17 -0700 (PDT)
Subject: [Tutor] singleton pattern
In-Reply-To: <3B028E18.98B0B23B@seatech.fau.edu>
Message-ID: <XFMail.20010516080317.shaleh@valinux.com>

On 16-May-2001 Benoit Dupire wrote:
> I would like to implement a  class dubbed "Factory " with the singleton
> pattern, so that i only have a single "factory" object, that
> instantiates some shared objects (pretty much in the same way than in
> the Flyweight pattern)
> 

search the main python list archives, this subject has been talked about
numerous times.


From dsh8290@rit.edu  Wed May 16 16:36:15 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 16 May 2001 11:36:15 -0400
Subject: [Tutor] singleton pattern
In-Reply-To: <3B028E18.98B0B23B@seatech.fau.edu>; from bdupire@seatech.fau.edu on Wed, May 16, 2001 at 10:26:32AM -0400
References: <3B028E18.98B0B23B@seatech.fau.edu>
Message-ID: <20010516113615.A22465@harmony.cs.rit.edu>

On Wed, May 16, 2001 at 10:26:32AM -0400, Benoit Dupire wrote:

The thing to remember about Python is that unlike Java you are not
forced to put everything inside a class.  Somethings don't really
belong inside a class.  Static methods are one of those things.  They
belong in a module instead.  There is no way to have static methods in
a class in python, but you have modules instead. 

<...>
| which is a nice solution (not from me ! :o) )

It is a nice solution -- you can only have one instance of that class
and it is stored in the module.

| The problem is that i already have a __call__ method implemented in my
| Factory class.

How is this a problem?  Your __call__ method works on an _instance_ of
the class, not the class itself.

| Python unfortunately does not support overriding...

It does.  It doesn't support overloading.



Here are a couple ways to implement the singleton pattern:

######## Factory.py -- the "Factory" module ##########

class _Factory :
    def create_object( self ) :
        pass

factory_instance = _Factory()
del _Factory # optional,  alternatively use the same name as in the
             # above example then the name will be rebound

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

 From the client side one would use the following code :

import Factory

an_object = Factory.factory_instance.create_object()
print an_object



Here is an alternative to use if you are a fan of functions and would
rather not use public module variables :

######## Factory.py ##########

class _Factory :
    def create_object( self ) :
        pass

_instance = None

def get_instance() :
    if _instance is None :
        _instance = _Factory()
    return _instance

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

The client would look like :

import Factory

an_object = Factory.get_instance().create_object()
print an_object



Don't be afraid to use modules when they are more apropriate than a
class <grin>.  (I know -- it is a different way of thinking.  It has
taken me a while to get used to it having learned from class-based OO
lanauages first.)

-D



From arcege@speakeasy.net  Wed May 16 16:50:30 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 16 May 2001 11:50:30 -0400 (EDT)
Subject: [Tutor] singleton pattern
In-Reply-To: <20010516113615.A22465@harmony.cs.rit.edu> from "D-Man" at May 16, 2001 11:36:15 AM
Message-ID: <200105161550.f4GFoUN13192@dsl092-074-184.bos1.dsl.speakeasy.net>

D-Man wrote
> ######## Factory.py ##########
> 
> class _Factory :
>     def create_object( self ) :
>         pass
> 
> _instance = None
> 
> def get_instance() :
>     if _instance is None :
>         _instance = _Factory()
>     return _instance

Just to be safe, you'll want to qualify the _instance as a global since
you have an assignment in the function and it will be taken as a local
(or you'll get an UnboundLocalError exception in later releases).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From dsh8290@rit.edu  Wed May 16 16:57:24 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 16 May 2001 11:57:24 -0400
Subject: [Tutor] singleton pattern
In-Reply-To: <200105161550.f4GFoUN13192@dsl092-074-184.bos1.dsl.speakeasy.net>; from arcege@dsl092-074-184.bos1.dsl.speakeasy.net on Wed, May 16, 2001 at 11:50:30AM -0400
References: <20010516113615.A22465@harmony.cs.rit.edu> <200105161550.f4GFoUN13192@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <20010516115724.A14324@buddy.cs.rit.edu>

On Wed, May 16, 2001 at 11:50:30AM -0400, Michael P. Reilly wrote:
| D-Man wrote
| > ######## Factory.py ##########
| > 
| > class _Factory :
| >     def create_object( self ) :
| >         pass
| > 
| > _instance = None
| > 
| > def get_instance() :
| >     if _instance is None :
| >         _instance = _Factory()
| >     return _instance
| 
| Just to be safe, you'll want to qualify the _instance as a global since
| you have an assignment in the function and it will be taken as a local
| (or you'll get an UnboundLocalError exception in later releases).

Uhh...right.  Doh!  I forgot the 'global' declaration.  In current releases,
the effect is to get a new _Factory instance for each invocation of
the function.  Not quite what was intended ;-).

-D



From bdupire@seatech.fau.edu  Wed May 16 17:17:44 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Wed, 16 May 2001 12:17:44 -0400
Subject: [Tutor] singleton pattern
References: <3B028E18.98B0B23B@seatech.fau.edu> <20010516113615.A22465@harmony.cs.rit.edu>
Message-ID: <3B02A828.3968132F@seatech.fau.edu>


D-Man wrote:

> On Wed, May 16, 2001 at 10:26:32AM -0400, Benoit Dupire wrote:
>
> The thing to remember about Python is that unlike Java you are not
> forced to put everything inside a class.  Somethings don't really
> belong inside a class.  Static methods are one of those things.  They
> belong in a module instead.  There is no way to have static methods in
> a class in python, but you have modules instead.
>

yep.. i think it's hard for me to get used to the idea, which means (IMHO)
combining 2 paradigms..
I think we already discussed that, not so long ago, in this mailing-list uh
? :o) !!
One day... i'll get used to this idea ...


>
>
> | Python unfortunately does not support overriding...
>
> It does.  It doesn't support overloading.

uuuuuuh!!! oops ! yes. That's what i meant...

>
>
> Here is an alternative to use if you are a fan of functions and would
> rather not use public module variables :

<snip>
plenty of choice !
<snip>
thanks a lot !
<snip!!>

Here is what i found in the Python mailing list, if you are a fan of
classes...(like me!)


class MySingleton:
        class _my_dummy: pass
        _dummy=_my_dummy()
        _initialized=0
        def __init__(self, ....):
                if initialized: return
                ......
        def __getattr__(self, attr):
                return _dummy.__dict__[attr]

        def __setattr__(self, attr, val):
                _dummy.__dict__[attr]=val


It's from Moshe, but yes! i'd rather combine my class with a function than
using this more complex solution.....

Thank your for all the replies....
--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From kent@springfed.com  Wed May 16 17:59:41 2001
From: kent@springfed.com (Kent Tenney)
Date: Wed, 16 May 2001 11:59:41 -0500
Subject: [Tutor] Using Python instead of VB in ASP with IIS
In-Reply-To: <200105161304.GAA19711@lyra.hurrah.com>
Message-ID: <200105161903.MAA11998@svc1.netwk-innov.net>

My situation is:
1) running Win2K Advanced Server
2) installed ActiveState distribution
3) ran python\win32comext\axscript\client\pyscript.py
4) pages with <script language=3D"Python">=A0(i.e., client-side=
 Python) run
correctly in IE
5) ASP pages with <%@ Language=3DPython %>=A0always fail with error=
 500 Server
Error
6) ASP pages with <SCRIPT RunAt=3DServer Language=3DPython>=A0blocks=
 always fail
with error 500 Server Error

-Sam

kent@springfed.com, tutor@python.org wrote:
>
>Howdy,
>Is there a convenient source of info on the
>configuration required to allow server side
>ASP pages to employ Python code?
>Thanks,
>Kent
>-- Kent Tenney, kent@springfed.com on 05/16/2001
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
-- Kent Tenney, kent@springfed.com on 05/16/2001



From samus@feudalkingdoms.tzo.org  Wed May 16 18:56:37 2001
From: samus@feudalkingdoms.tzo.org (Sam Corder)
Date: Wed, 16 May 2001 17:56:37 +0000
Subject: [Tutor] Using Python instead of VB in ASP with IIS
Message-ID: <E1505ZD-0003GD-00@mail.python.org>

It sounds like Python is registered as an active scripting language since they run 
in IE.  Here is a very simple example script for asp.
<%@ LANGUAGE = Python%>
<%
Response.Write('Hi')
%>

You may want to turn off friendly error messages in IE.  Also if the simple script 
above works then it may be your code.  Turning off the friendly error messages 
should show you what actually blew up.  Another gotcha for python/asp is that code 
embedding like
<%
if something == 1:%>
this is a para with <%=    myvar%> code
<%
else:
    pass
%>
this is a para without embedded code.

Won't work because the asp engine doesn't transmit the white space in <%= %>to 
python.  I guess this has the advantage of keeping most of your code outside of the 
html.  I have a couple more complex examples if you want them.  We mainly use 
python and the Reportlab package to generate pdf reports and stream them down to 
the browser.

-Sam

kent@springfed.com, tutor@python.org wrote:
>
>My situation is:
>1) running Win2K Advanced Server
>2) installed ActiveState distribution
>3) ran python\win32comext\axscript\client\pyscript.py
>4) pages with <script language=3D"Python">=A0(i.e., client-side=
> Python) run
>correctly in IE
>5) ASP pages with <%@ Language=3DPython %>=A0always fail with error=
> 500 Server
>Error
>6) ASP pages with <SCRIPT RunAt=3DServer Language=3DPython>=A0blocks=
> always fail
>with error 500 Server Error
>-Sam
>kent@springfed.com, tutor@python.org wrote:
>>
>>Howdy,
>>Is there a convenient source of info on the
>>configuration required to allow server side
>>ASP pages to employ Python code?
>>Thanks,
>>Kent
>>-- Kent Tenney, kent@springfed.com on 05/16/2001
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>-- Kent Tenney, kent@springfed.com on 05/16/2001
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


From lsloan@umich.edu  Wed May 16 19:38:10 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Wed, 16 May 2001 14:38:10 -0400
Subject: [Tutor] advice: making dictionary from two lists?
Message-ID: <200105161838.OAA25560@birds.us.itd.umich.edu>

I've got a couple lists, one is of labels and the other is values.
They have a one-to-one correspondence.  Currently, I'm using this
method to make them into a dictionary:

    labels = ('name', 'age', 'salary')
	values = ('Monty', 42, 5)

    # make a dictionary from two lists/tuples
    theDict = {} # or whatever you want to call it
    for (key, value) in map(None, labels, values):
        theDict[key] = value

This works fine, but I just wondered if there was a better (or
"cooler") way to do this.  I wish that dictionaries had an inverse of
the items() method.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From r.b.rigilink@chello.nl  Wed May 16 19:57:44 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Wed, 16 May 2001 20:57:44 +0200
Subject: [Tutor] where to start
References: <Pine.LNX.4.21.0105160239390.6667-100000@hkn.eecs.berkeley.edu>
Message-ID: <3B02CDA8.C97CB123@chello.nl>

Daniel Yoo wrote:
> 
> On Wed, 16 May 2001, Roeland Rengelink wrote:
>

[snipped my 'top-down' approach]

> 
> Roeland's advice sounds like a "top-down" approach to writing a program.
> I'll play Devil's advocate for a moment.  *grin*
> 

Advocates have this tendency to suggest conflict where none is there ;)

Actually I was trying to illustrate my approach for getting  from a
'top-down' problem statement to a 'bottom-up' solution approach, by
homing in ASAP to a piece of functionality (I don't really care which)
at the bottom that I do know how to implement

I find that generally it doesn't really matter if your program is
specified by some vague notion of what it might sort of do, or a 200
page User Requirement Specification. Neither will tell you how to
actually implement the damn thing.

But then again, they are the only thing you have to start your search
for a solution.

> An opposing view: sometimes, the program that you're trying to write might
> not be easy to break down at first.  This happens a lot in the kind of
> ambiguous problems that people always deal with --- in this case, planning
> the code is ok, but it might not be enough.  Even our understanding of a
> problem might not be really "there" until we actually try coding and
> running into the roadblocks.
> 

I agree completely.

You don't understand a problem until you've actually solved it. Working
code is the only solution worthy of that name

> There's another approach toward writing programs called "bottom up".
> "Bottom up" emphases writing small, working functions that you can play
> around with and test as you explore the problem.  In this case, though,
> the emphasis is on writing small utilities that expand our control over
> the problem, until we reach the top.  So, this is sorta backwards from
> Roeland's advice: "bottom up" does encourage jumping right into the deep
> end of the problem.  *grin*
> 

Yep, you have to get into the water.

I think I was trying to explain how I first measure the water
temperature and probe its depth for a nice comfortable spot where I can
gently decent in the reassuring knowledge that I will neither drown,
break my neck, boil or freeze to death.

I may loose out on sheer exhilaration though.

(I'm also taking this metaphor way beyond it's breaking point)


[snip]

Roeland
-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From bdupire@seatech.fau.edu  Wed May 16 20:12:16 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Wed, 16 May 2001 15:12:16 -0400
Subject: [Tutor] advice: making dictionary from two lists?
References: <200105161838.OAA25560@birds.us.itd.umich.edu>
Message-ID: <3B02D110.420582BA@seatech.fau.edu>

in the Python doc at
http://www.python.org/doc/current/lib/module-operator.html
there is a similar problem...

For your problem, it will give
import operator
d = {}
labels = ('name', 'age', 'salary')
values = ('Monty', 42, 5)
map(operator.setitem, [d]*len(labels), labels, values)

>>>d
{'age': 42, 'name': 'Monty', 'salary': 5}

___________________
setitem(a, b, c)
__setitem__(a, b, c)
     Set the value of a at index b to c.
______________________

I don't know if it is better....

Benoit



Lance E Sloan wrote:

> I've got a couple lists, one is of labels and the other is values.
> They have a one-to-one correspondence.  Currently, I'm using this
> method to make them into a dictionary:
>
>     labels = ('name', 'age', 'salary')
>         values = ('Monty', 42, 5)
>
>     # make a dictionary from two lists/tuples
>     theDict = {} # or whatever you want to call it
>     for (key, value) in map(None, labels, values):
>         theDict[key] = value
>
> This works fine, but I just wondered if there was a better (or
> "cooler") way to do this.  I wish that dictionaries had an inverse of
> the items() method.
>
> --
> Lance E Sloan
> Web Services, Univ. of Michigan: Full-service Web and database design,
> development, and hosting.  Specializing in Perl & Python CGIs.
> http://websvcs.itd.umich.edu/ - "Putting U on the Web"
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From r.b.rigilink@chello.nl  Wed May 16 20:28:16 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Wed, 16 May 2001 21:28:16 +0200
Subject: [Tutor] advice: making dictionary from two lists?
References: <200105161838.OAA25560@birds.us.itd.umich.edu>
Message-ID: <3B02D4D0.C9FB0B49@chello.nl>

Lance E Sloan wrote:
> 
> I've got a couple lists, one is of labels and the other is values.
> They have a one-to-one correspondence.  Currently, I'm using this
> method to make them into a dictionary:
> 
>     labels = ('name', 'age', 'salary')
>         values = ('Monty', 42, 5)
> 
>     # make a dictionary from two lists/tuples
>     theDict = {} # or whatever you want to call it
>     for (key, value) in map(None, labels, values):
>         theDict[key] = value
> 
> This works fine, but I just wondered if there was a better (or
> "cooler") way to do this.  I wish that dictionaries had an inverse of
> the items() method.
> 

Hi Lance,

I can't think of a better way (which doesn't mean that much)

I wouldn't call it cool, and there are plenty reasons not to go here.
But, your wish is my command

from UserDict import UserDict

class genie_dict(UserDict):
    def inverse_of_items(self, item_list):
        for key, value in item_list:
            self.data[key] = value
    
g = genie_dict()
g.inverse_of_items(zip(('name', 'age', 'salary'), ('Joe', 42, 6000)))
print g

will result in:

{'age': 42, 'name': 'Joe', 'salary': 6000}


On a more serious note:

Your dict looks suspiciously like an employee record, which might
indicate
an EmployeeRecord class

Hope this helps,

Roeland

-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From jozlaurie@yahoo.co.uk  Wed May 16 20:21:05 2001
From: jozlaurie@yahoo.co.uk (=?iso-8859-1?q?joseph=20laurie?=)
Date: Wed, 16 May 2001 20:21:05 +0100 (BST)
Subject: [Tutor] confirm 924372
Message-ID: <20010516192105.94019.qmail@web14208.mail.yahoo.com>

confirm 924372


____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie


From deirdre@deirdre.net  Wed May 16 20:28:49 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Wed, 16 May 2001 12:28:49 -0700
Subject: [Tutor] where to start
In-Reply-To: <Pine.LNX.4.21.0105160239390.6667-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105160239390.6667-100000@hkn.eecs.berkeley.edu>
Message-ID: <a05100e3db72884c6535f@[10.0.1.24]>

At 3:00 AM -0700 5/16/01, Daniel Yoo wrote:
>Roeland's advice sounds like a "top-down" approach to writing a program.
>I'll play Devil's advocate for a moment.  *grin*

Last night I had a series of nightmares involving last night's Angel 
episode (how could they kill the Host! He was my favorite character!) 
and the Objective-C library I'm trying to learn. It was very strange.

When I woke up, I'd solved one of my design problems. Nevertheless, I 
don't recommend sleep as a design tool.

>Both of us agree in small "functional" programs because we understand our
>own humanity: sometimes, a program is just too large to hold in one's
>head.  Small functions help us to handle the complexity of large problems
>without mental stress.
>
>The moderate approach, doing both "top-down" and "bottom-up" is probably
>the better approach though.

And, always remember Fred Brooks' advice: plan on throwin one away.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From bdupire@seatech.fau.edu  Wed May 16 20:42:28 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Wed, 16 May 2001 15:42:28 -0400
Subject: [Tutor] advice: making dictionary from two lists?
References: <200105161838.OAA25560@birds.us.itd.umich.edu> <3B02D4D0.C9FB0B49@chello.nl>
Message-ID: <3B02D824.72350F1A@seatech.fau.edu>


Roeland Rengelink wrote:

> from UserDict import UserDict
>
> class genie_dict(UserDict):
>     def inverse_of_items(self, item_list):
>         for key, value in item_list:
>             self.data[key] = value

Nice!!!!!!!!
so, using your idea:

class superDict(UserDict):
    def __init__(self, list1=[], list2=[]):
        self.data={}
        foo =map(operator.setitem, [self.data]*len(list1), list1, list2)

not tested, but that should work....

I was interested to see what the result is, if list2 is shorter than list1

>>> labels = ('name', 'age', 'salary')
>>>values = ('Monty', 42)
>>> map(operator.setitem, [d]*len(labels), labels, values)

Result...

>>> d
{'age': 42, 'name': 'Monty', 'salary': None}


Ouaaaa!!!! Nice !!!!


Benoit




From deirdre@deirdre.net  Wed May 16 20:46:05 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Wed, 16 May 2001 12:46:05 -0700
Subject: [Tutor] Using Python instead of VB in ASP with IIS
In-Reply-To: <200105161903.MAA11998@svc1.netwk-innov.net>
References: <200105161903.MAA11998@svc1.netwk-innov.net>
Message-ID: <a05100e41b728894f6364@[10.0.1.24]>

Given that this is a pretty specific setup, better to ask this on the 
general python list -- this isn't really about learning the language 
per se.

>My situation is:
>1) running Win2K Advanced Server
>2) installed ActiveState distribution
>3) ran python\win32comext\axscript\client\pyscript.py
>4) pages with <script language="Python"> (i.e., client-side Python) run
>correctly in IE
>5) ASP pages with <%@ Language=Python %> always fail with error 500 Server
>Error
>6) ASP pages with <SCRIPT RunAt=Server Language=Python> blocks always fail
>with error 500 Server Error

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From AnthonyBeaman@trginc.com  Wed May 16 21:01:17 2001
From: AnthonyBeaman@trginc.com (Anthony Beaman)
Date: Wed, 16 May 2001 16:01:17 -0400
Subject: FW: [Tutor] Total Programming Newbie
Message-ID: <6D19AB695BA8D311A8420008C7CF285A020A8CF3@trgmail>

Oops! I responded to Roeland's response to his email address only. Any
additional comments? Thanks! Also, thanks for all of the responses that I've
gotten so far. I'm still plugging away! Thanks again. 

-----Original Message-----
From:	Roeland Rengelink [mailto:r.b.rigilink@chello.nl]
<mailto:[mailto:r.b.rigilink@chello.nl]> 
Sent:	Monday, May 14, 2001 6:03 PM
To:	Anthony Beaman
Subject:	Re: [Tutor] Total Programming Newbie

Hi Anthony,

Since you didn't send a copy of your mail to the tutor list, I'm answering
by private e-mail only. Feel free to forward this exchange to the list
though.
Anthony Beaman wrote:
	> 
	> Wow! What a response! That's some great advice. About your
questions...
	> My background is in networking and hardware. I'm a MCSE and a
Novell C.N.A.
	> and I'm currently doing tech support. The reason that I want to
program is
	> that I want to know how computers work (under the hood), how
programs and
	> software packages work ("I don't like that about this software
package; how
	> can I change it?" or "COOL! How'd they do that??"), and to better
understand
	> networking (I'm sure you believe, as I do, that MCSE's are merely
"advanced
	> point and clickers"). I've read that the languages that I should
know to
	> achieve the first goal are C, Assembly, and Perl; the second goal
C++, Java,
	> VB, etc.; and C and Perl for the latter goal. The problem is that
the other
	> languages seem to be a bit too hard (I keep starting but stopping.
I start
	> to feel overwhelmed and unsure about how to proceed or if I'm
using the
	> right language to start). I saw that Eric Raymond recommends
Python as a
	> first language. I was starting to learn Qbasic (using "Qbasic By
Example"
	> since BASIC seems to reputed as the perfect language for
beginners) but I
	> thought I'd give this a shot. I feel that one of the reasons that
I've
	> failed so far is that I got too involved in planning out what I
wanted to
	> learn instead of learning it. Then I got sick of it after awhile
and I had
	> no desire to learn the language I had set the goal of learning.
Then I went
	> to the next language and the same thing happened (shall I check
myself into
	> a mental hospital?). For example, I decided to learn C. I got the
"21 Days"
	> book, "Practical C", and "K&R". I started and stopped; started and
stopped.
	> Then I went to Perl (same cycle: 3 books, got sick of it, on to
Assembly),
	> etc.
	> As for your second question (still awake?), I'm not sure what
applications I
	> want to write. I guess "any and all". I hope I helped out in your
survey.
	> Any advice for my questions/ problems or general advice? Thanks!
	> 

Let me first say that you sell yourself short with 'Total Newbie'. 
I'm trying to imagine what it is like to be confronted with Python or C or
Perl (or even ASM) as a total newbie. I started programming 18(?) years ago
in BASIC on a sinclair QL. At that time I could at least see how an
extension of my meager efforts could lead, in priciple, to the word
processor or the speadsheet that came bundled with that machine. In the
years after that I didn't do much programming (I'm technically an
astronomer, not a programmer), and computers developed rapidly. When I
started programming full time again, I realized that despite (or maybe even
because of) years of experience writing software in my particular domain, I
was in some sense further away from writing a full scale App than I was in
those early days, simply because the scale of software development had grown
so rapidly in the mean time.
What I'm trying to say is that I would imagine that the task of writing
software would be almost impossibly daunting to a newbie. I don't know
if I should feel envy or sorry for these kids that want to learn C++ so
they can write something 'just like Quake'
Your aims sound more modest though. Any attempt at programming will give you
a feel of how computers and software work. Moreover, using a high-level
language like Python, should give you a fighting chance to learn how to
modify or add to existing programs.
Yet, what you describe of your attempts and failures resemebles what I'd
imagine I would experience as a newbie, especially 'feeling overwhelmed
and unsure how to proceed'
So what would be good advice.
First of all, you already took the best advice I could give. Use Python.
This language gave me the feeling _again_ that I could do anything I wanted
with a computer. Not that I actually _can_ in practice, mind you, just that
I could in priciple. Python may not make difficult thing easy, but at least
it will not make easy things difficult.
Having said that, a programming language is just that, a language. It's
first and foremost a vehicle for the expression of ideas. In the end a
language is only worth learning if you want to communicate/express/explore
ideas (be it to computers or other people). 
So, maybe you got stumped by a lack of ideas you felt you could explore with
your current knowledge of programming languages. I can imagine that this
could result from the conceptual "distance" between what you know now about
programming, and the multi-million line applications that you work with as a
professional.
Let me therefore rephrase my original question: What ideas would you like to
explore?
Remember, programming is only a means to an end. Despite the enormous
satifaction that the process of creating software may bring; sometimes
something so tentalizingly close to art, sometimes an expression of pure
abstract reasoning.
				Hope this helps,

				Roeland


From kent@springfed.com  Wed May 16 21:08:23 2001
From: kent@springfed.com (Kent Tenney)
Date: Wed, 16 May 2001 15:08:23 -0500
Subject: [Tutor] Using Python instead of VB in ASP with IIS
In-Reply-To: <E1505ZD-0003GD-00@mail.python.org>
Message-ID: <200105162212.PAA19508@svc1.netwk-innov.net>

Even an ASP consisting of just the single line
<%@ LANGUAGE =3D Python%>
 
blows up with 500 Server Error ...

Kent


On Wed, 16 May 2001 17:56:37 +0000, Sam Corder wrote:
It sounds like Python is registered as an active scripting=
 language since they run 
in IE.  Here is a very simple example script for asp.
<%@ LANGUAGE =3D Python%>
<%
Response.Write('Hi')
%>

You may want to turn off friendly error messages in IE.  Also if=
 the simple script 
above works then it may be your code.  Turning off the friendly=
 error messages 
should show you what actually blew up.  Another gotcha for=
 python/asp is that code 
embedding like
<%
if something =3D=3D 1:%>
this is a para with <%=3D    myvar%> code
<%
else:
    pass
%>
this is a para without embedded code.

Won't work because the asp engine doesn't transmit the white=
 space in <%=3D %>to 
python.  I guess this has the advantage of keeping most of your=
 code outside of the 
html.  I have a couple more complex examples if you want them. =
 We mainly use 
python and the Reportlab package to generate pdf reports and=
 stream them down to 
the browser.

-Sam

kent@springfed.com, tutor@python.org wrote:
>
>My situation is:
>1) running Win2K Advanced Server
>2) installed ActiveState distribution
>3) ran python\win32comext\axscript\client\pyscript.py
>4) pages with <script language=3D3D"Python">=3DA0(i.e.,=
 client-side=3D
> Python) run
>correctly in IE
>5) ASP pages with <%@ Language=3D3DPython %>=3DA0always fail with=
 error=3D
> 500 Server
>Error
>6) ASP pages with <SCRIPT RunAt=3D3DServer=
 Language=3D3DPython>=3DA0blocks=3D
> always fail
>with error 500 Server Error
>-Sam
>kent@springfed.com, tutor@python.org wrote:
>>
>>Howdy,
>>Is there a convenient source of info on the
>>configuration required to allow server side
>>ASP pages to employ Python code?
>>Thanks,
>>Kent
>>-- Kent Tenney, kent@springfed.com on 05/16/2001
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>-- Kent Tenney, kent@springfed.com on 05/16/2001
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
-- Kent Tenney, kent@springfed.com on 05/16/2001



From arcege@speakeasy.net  Wed May 16 21:23:43 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 16 May 2001 16:23:43 -0400 (EDT)
Subject: [Tutor] advice: making dictionary from two lists?
In-Reply-To: <3B02D824.72350F1A@seatech.fau.edu> from "Benoit Dupire" at May 16, 2001 03:42:28 PM
Message-ID: <200105162023.f4GKNhb13467@dsl092-074-184.bos1.dsl.speakeasy.net>

Benoit Dupire wrote
> Nice!!!!!!!!
> so, using your idea:
> 
> class superDict(UserDict):
>     def __init__(self, list1=[], list2=[]):
>         self.data={}
>         foo =map(operator.setitem, [self.data]*len(list1), list1, list2)
> 
> not tested, but that should work....
> 
> I was interested to see what the result is, if list2 is shorter than list1
> 
> >>> labels = ('name', 'age', 'salary')
> >>>values = ('Monty', 42)
> >>> map(operator.setitem, [d]*len(labels), labels, values)
> 
> Result...
> 
> >>> d
> {'age': 42, 'name': 'Monty', 'salary': None}

This is nice, but realize that the for loop as been fairly well optimized
and the above will create an unnecessary list.  And it doesn't give you
the control you might need.

You already see that it extends the second list with None values.
But if the second list is longer than the first, you'll get a key of
None with the last value in the second list:
>>> d = {}
>>> l1 = ['eggs', 'spam', 'toast', 'ham']
>>> l2 = [1, 2, 3, 4, 5, 6]
>>> import operator
>>> for (n, v) in map(None, l1, l2):
...   d[n] = v
...
>>> d
{'spam': 2, 'ham': 4, None: 6, 'eggs': 1, 'toast': 3}
>>> d[None]
6
>>>

The for loop lets you control this better than the operator.setitem
solution would.  This is where the new (to 2.x) zip() might be useful.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From samus@feudalkingdoms.tzo.org  Wed May 16 21:49:11 2001
From: samus@feudalkingdoms.tzo.org (Sam Corder)
Date: Wed, 16 May 2001 20:49:11 +0000
Subject: [Tutor] Using Python instead of VB in ASP with IIS
Message-ID: <E1508GM-000172-00@mail.python.org>

I'm wondering if you have a permissions problem.  Verify that the iusr account has 
access to the python directories and everything.  You can also check your NT logs 
for any hints there.  Others in c.l.python may be able to help as well.

-Sam

kent@springfed.com, samus@feudalkingdoms.tzo.org wrote:
>
>Even an ASP consisting of just the single line
><%@ LANGUAGE =3D Python%>
>
>blows up with 500 Server Error ...
>Kent
>On Wed, 16 May 2001 17:56:37 +0000, Sam Corder wrote:
>It sounds like Python is registered as an active scripting=
> language since they run
>in IE.  Here is a very simple example script for asp.
><%@ LANGUAGE =3D Python%>
><%
&gt;Response.Write('Hi')
&gt;%>
>You may want to turn off friendly error messages in IE.  Also if=
> the simple script
>above works then it may be your code.  Turning off the friendly=
> error messages
>should show you what actually blew up.  Another gotcha for=
> python/asp is that code
>embedding like
><%
&gt;if something =3D=3D 1:%>
>this is a para with <%=3D    myvar%> code
><%
&gt;else:
&gt;    pass
&gt;%>
>this is a para without embedded code.
>Won't work because the asp engine doesn't transmit the white=
> space in <%=3D %>to
>python.  I guess this has the advantage of keeping most of your=
> code outside of the
>html.  I have a couple more complex examples if you want them. =
> We mainly use
>python and the Reportlab package to generate pdf reports and=
> stream them down to
>the browser.
>-Sam
>kent@springfed.com, tutor@python.org wrote:
>>
>>My situation is:
>>1) running Win2K Advanced Server
>>2) installed ActiveState distribution
>>3) ran python\win32comext\axscript\client\pyscript.py
>>4) pages with <script language=3D3D"Python">=3DA0(i.e.,=
> client-side=3D
>> Python) run
>>correctly in IE
>>5) ASP pages with <%@ Language=3D3DPython %>=3DA0always fail with=
> error=3D
>> 500 Server
>>Error
>>6) ASP pages with <SCRIPT RunAt=3D3DServer=
> Language=3D3DPython>=3DA0blocks=3D
>> always fail
>>with error 500 Server Error
>>-Sam
>>kent@springfed.com, tutor@python.org wrote:
>>>
>>>Howdy,
>>>Is there a convenient source of info on the
>>>configuration required to allow server side
>>>ASP pages to employ Python code?
>>>Thanks,
>>>Kent
>>>-- Kent Tenney, kent@springfed.com on 05/16/2001
>>>_______________________________________________
>>>Tutor maillist  -  Tutor@python.org
>>>http://mail.python.org/mailman/listinfo/tutor
>>-- Kent Tenney, kent@springfed.com on 05/16/2001
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>-- Kent Tenney, kent@springfed.com on 05/16/2001


From bdupire@seatech.fau.edu  Wed May 16 22:04:30 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Wed, 16 May 2001 17:04:30 -0400
Subject: [Tutor] advice: making dictionary from two lists?
References: <200105162023.f4GKNhb13467@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <3B02EB5E.7A06EB8A@seatech.fau.edu>


"Michael P. Reilly" wrote:

> Benoit Dupire wrote
> > >>> labels = ('name', 'age', 'salary')
> > >>>values = ('Monty', 42)
> > >>> map(operator.setitem, [d]*len(labels), labels, values)
> > >>> d
> > {'age': 42, 'name': 'Monty', 'salary': None}
>
> This is nice, but realize that the for loop as been fairly well optimized
> and the above will create an unnecessary list.  And it doesn't give you
> the control you might need.
>

I agree with you. I would also add that the operator.setitem makes it much more
difficult to understand the algorithm. it's not very readable...

>
> You already see that it extends the second list with None values.
> But if the second list is longer than the first, you'll get a key of
> None with the last value in the second list:

Actually Python returns an exception if list1 is shorter than list2 with the
other solution (operator.setitem).  This is IMHO better than creating a key of
None.

-----------
>>> labels = ('name', 'age')
>>> values = ('Monty', 42, 5)
>>> d={}
>>> map(operator.setitem, [d]*len(labels), labels, values)
Traceback (innermost last):
  File "<pyshell#165>", line 1, in ?
    map(operator.setitem, [d]*len(labels), labels, values)
TypeError: object does not support item assignment
-------------

But, as you mentionned it, zip is even better

>>> labels = ('name', 'age')
>>> values = ('Monty', 42, 5)
>>> zip(values, labels)
[('Monty', 'name'), (42, 'age')]


Benoit



From rortega@cfl.rr.com  Wed May 16 22:14:16 2001
From: rortega@cfl.rr.com (Ricardo Ortega)
Date: Wed, 16 May 2001 17:14:16 -0400
Subject: [Tutor] question about were to go
Message-ID: <000f01c0de4d$2a3be3f0$93601a18@node1>

This is a multi-part message in MIME format.

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

Hi I am new to programing and am having a great deal off fun learning =
Python. I have read up on a few tutorials and purchased the book =
"Learning Python" by Mark Lutz & David Ascher. I am almost done reading =
this great book but what I wanted to know is if there are any web sites =
that have exercises or small programing projects for begginers so I can =
start coding. I would like to start putting some of what I am learning =
into practice but I just cant think of anything to do. Thank you.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi I am new to programing and am having =
a great=20
deal off fun learning Python. I have read up on a few tutorials and =
purchased=20
the book "Learning Python" by Mark Lutz &amp; David Ascher. I am almost =
done=20
reading this great book but what I wanted to know is if there are any =
web sites=20
that have exercises or small programing projects for begginers so&nbsp;I =
can=20
start coding. I would like to start putting some of what I am learning =
into=20
practice but I just cant think of anything to do. Thank=20
you.</FONT></DIV></BODY></HTML>

------=_NextPart_000_000C_01C0DE2B.A2FACF80--



From dsh8290@rit.edu  Wed May 16 22:46:38 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 16 May 2001 17:46:38 -0400
Subject: [Tutor] singleton pattern
In-Reply-To: <3B02A828.3968132F@seatech.fau.edu>; from bdupire@seatech.fau.edu on Wed, May 16, 2001 at 12:17:44PM -0400
References: <3B028E18.98B0B23B@seatech.fau.edu> <20010516113615.A22465@harmony.cs.rit.edu> <3B02A828.3968132F@seatech.fau.edu>
Message-ID: <20010516174638.A25842@harmony.cs.rit.edu>

On Wed, May 16, 2001 at 12:17:44PM -0400, Benoit Dupire wrote:
| D-Man wrote:
| > The thing to remember about Python is that unlike Java you are not
| > forced to put everything inside a class.  Somethings don't really
| > belong inside a class.  Static methods are one of those things.  They
| > belong in a module instead.  There is no way to have static methods in
| > a class in python, but you have modules instead.
| 
| yep.. i think it's hard for me to get used to the idea, which means (IMHO)
| combining 2 paradigms..
| I think we already discussed that, not so long ago, in this mailing-list uh
| ? :o) !!
| One day... i'll get used to this idea ...

Yes, we discussed whether putting everything in a class was more (or
less) OO than allowing somethings to exist at module level.  :-).
 
| Thank your for all the replies....

You're welcome.

-D



From alan.gauld@bt.com  Wed May 16 22:24:53 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 May 2001 22:24:53 +0100
Subject: [Tutor] Re: Turtle Graphics thread
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D77C@mbtlipnt02.btlabs.bt.co.uk>

The digest gor scrambled but Danny was asking about turtle graphics and
someone said:

>> >I know that the Python distribution comes with a sample turtle module.
>> >Can anyone suggest others?  Thanks!
>>
>> No, but I'm fascinated by the concept.
>
>  Indeed...logo is a language where you are a turtle drawing 
>lines...it's not that complex - perhaps some of the structures 
>could be borrowed from that and implemented in python?

Logo was first with turtle graphics but they are available
in most languages now. Certainly Turbo Pascal, Smalltalk, 
C++, Lisp etc all have turtle modules. Python does too but 
I couldn't get it to work - can't recall what the problem was.

Incidentally Logo is a list processing language rather like 
Lisp but with fewer parentheses. Modern versions have full 
OO facilities and you can even write windows programs if 
you really want! Worth a look for the language curious :-)

Alan g



From rob@jam.rr.com  Wed May 16 22:54:39 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Wed, 16 May 2001 16:54:39 -0500
Subject: [Tutor] question about were to go
References: <000f01c0de4d$2a3be3f0$93601a18@node1>
Message-ID: <001701c0de52$cefdd4c0$de00a8c0@planhouse5>

This is a multi-part message in MIME format.

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

Forgive me, folks, if you receive two messages like this one. I sent my =
first reply from a linux box I had just set up, and may not have set it =
all up *just right*.

Take a look at Useless Python, a collection of source code for beginners =
(and anyone else) to play with:

http://www.lowerstandard.com/python/pythonsource.html

Some of the fine people on the Python Tutor email list have been kind =
enough to contribute, and there are links to other interesting =
resources.

Rob
  ----- Original Message -----=20
  From: Ricardo Ortega=20
  To: tutor@python.org=20
  Sent: Wednesday, May 16, 2001 4:14 PM
  Subject: [Tutor] question about were to go


  Hi I am new to programing and am having a great deal off fun learning =
Python. I have read up on a few tutorials and purchased the book =
"Learning Python" by Mark Lutz & David Ascher. I am almost done reading =
this great book but what I wanted to know is if there are any web sites =
that have exercises or small programing projects for begginers so I can =
start coding. I would like to start putting some of what I am learning =
into practice but I just cant think of anything to do. Thank you.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Forgive me, folks, if you receive two =
messages like=20
this one. I sent my first reply from a linux box I had just set up, and =
may not=20
have set it all up *just right*.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Take a look at Useless Python, a =
collection of=20
source code for beginners (and anyone else) to play with:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><A=20
href=3D"http://www.lowerstandard.com/python/pythonsource.html">http://www=
.lowerstandard.com/python/pythonsource.html</A></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Some of the fine people on the Python =
Tutor email=20
list have been kind enough to contribute, and there are links to other=20
interesting resources.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Rob</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Drortega@cfl.rr.com =
href=3D"mailto:rortega@cfl.rr.com">Ricardo=20
  Ortega</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, May 16, 2001 =
4:14=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] question about =
were to=20
  go</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>Hi I am new to programing and am =
having a great=20
  deal off fun learning Python. I have read up on a few tutorials and =
purchased=20
  the book "Learning Python" by Mark Lutz &amp; David Ascher. I am =
almost done=20
  reading this great book but what I wanted to know is if there are any =
web=20
  sites that have exercises or small programing projects for begginers =
so&nbsp;I=20
  can start coding. I would like to start putting some of what I am =
learning=20
  into practice but I just cant think of anything to do. Thank=20
you.</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0014_01C0DE28.E5B3D540--



From rob@jam.rr.com  Wed May 16 22:32:15 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Wed, 16 May 2001 16:32:15 -0500
Subject: [Tutor] question about were to go
In-Reply-To: <000f01c0de4d$2a3be3f0$93601a18@node1>
References: <000f01c0de4d$2a3be3f0$93601a18@node1>
Message-ID: <01051616321500.19766@SQLdev>

Well, you're in luck. There are a few sites out there featuring different 
projects, but check out Useless Python, which some of the people on this list 
have been kind enough to contribute to. It features quite a few small 
applications ranging from the silly to the quite interesting. The site also 
has links to other handy sites.

http://www.lowerstandard.com/python/pythonsource.html

Rob

On Wednesday 16 May 2001 04:14 pm, Ricardo Ortega wrote:
> Hi I am new to programing and am having a great deal off fun learning
> Python. I have read up on a few tutorials and purchased the book "Learning
> Python" by Mark Lutz & David Ascher. I am almost done reading this great
> book but what I wanted to know is if there are any web sites that have
> exercises or small programing projects for begginers so I can start coding.
> I would like to start putting some of what I am learning into practice but
> I just cant think of anything to do. Thank you.


From alan.gauld@bt.com  Wed May 16 23:18:59 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 May 2001 23:18:59 +0100
Subject: [Tutor] singleton pattern
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D77E@mbtlipnt02.btlabs.bt.co.uk>

Speculative code warning - I haven't tried this, consider it pseudo code...

Couldn't you do this:


class Factory:
   instance = None # class variable
   def __init__(self,class):
      if Factory.instance is None:
         Factory.instance = self
      else: self = Factory.instance
      self.class = class

   def makeInstance(self):
      return self.class()


Now reassigning self is normally a very bad thing 
to do but it might work for this case?
The original second instance would now be garbage 
collected... maybe? I don't like module level things 
being used to fake class responsibilities - I have to
do it in Delphi too often and it can cause problems.

I need a python prompt...

Alan G.



From scarblac@pino.selwerd.nl  Wed May 16 23:32:05 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 17 May 2001 00:32:05 +0200
Subject: [Tutor] singleton pattern
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D77E@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Wed, May 16, 2001 at 11:18:59PM +0100
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D77E@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20010517003205.A9512@pino.selwerd.nl>

On  0, alan.gauld@bt.com wrote:
> Speculative code warning - I haven't tried this, consider it pseudo code...
> 
> Couldn't you do this:
> 
> class Factory:
>    instance = None # class variable
>    def __init__(self,class):
>       if Factory.instance is None:
>          Factory.instance = self
>       else: self = Factory.instance
>       self.class = class
> 
>    def makeInstance(self):
>       return self.class()
> 
> Now reassigning self is normally a very bad thing 
> to do but it might work for this case?

It doesn't actually do anything. You can rebind the local variable 'self' to
some other object, but that doesn't magically turn the new instance into
something else. Whatever was referring to the new instance before is still
referring to it. At the end of __init__, the self variable is forgotten
again. 

> I need a python prompt...

Besides, 'class' is a reserved word :)

-- 
Remco Gerlich


From r.b.rigilink@chello.nl  Thu May 17 01:40:45 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Thu, 17 May 2001 02:40:45 +0200
Subject: [Tutor] singleton pattern
References: <3B028E18.98B0B23B@seatech.fau.edu> <20010516113615.A22465@harmony.cs.rit.edu> <3B02A828.3968132F@seatech.fau.edu>
Message-ID: <3B031E0D.8208BC91@chello.nl>

Benoit Dupire wrote:
> 
> D-Man wrote:
> 
> > On Wed, May 16, 2001 at 10:26:32AM -0400, Benoit Dupire wrote:
> >
> > The thing to remember about Python is that unlike Java you are not
> > forced to put everything inside a class.  Somethings don't really
> > belong inside a class.  Static methods are one of those things.  They
> > belong in a module instead.  There is no way to have static methods in
> > a class in python, but you have modules instead.
> >
> 
> yep.. i think it's hard for me to get used to the idea, which means (IMHO)
> combining 2 paradigms..
> I think we already discussed that, not so long ago, in this mailing-list uh
> ? :o) !!
> One day... i'll get used to this idea ...
>

I probably wasn't here then yet.

Something that worked for me was to think of classes and modules (and
instances) in terms namespaces. You just need a single paradigm.
 
So, what's a namespace? Abstractly it's a context that gives a
particular name a particular meaning. In general the same name will have
different meanings, if any, in different namespaces (contexts). 

Python has three basic kinds of namespaces: modules, classes and
instances
(plus local and builtin, but forget about that for now)

The meaning of a name is basically the same in all of them, it is the
object the name refers to in that context. I.e a namespace is a
particular mapping from names to objects. It may come as no suprise then
that Python uses dictionaries
to store that mapping, and indeed all these namespaces have a magic
attribute __dict__ that stores a mapping from name to object.

Consider:

import AModule                 # import a namespace called AModule
AModule.__dict__['attr'] = 1   # define 'attr' in AModule
print AModule.attr             # look up attr in AModule

class AClass                   # create a namespace called AClass
    pass
AClass.__dict__['attr'] = 2    # define 'attr' in AClass
print AClass.attr              # look up attr in AClass


AInstance = AClass()           # create a namespace AInstance
AInstance.__dict__['attr'] = 3 # define 'attr' in AInstance
print AInstance.attr           # look up attr in AInstance

(That doesn't look like 2 (3) paradigms, does it)

I used the .__dict__['attr'] notation as an alternative to the .attr
notation
to show you what goes on under the hood. I could have written:

import AModule
AModule.attr = 1
print AModule.__dict__['attr']

etc.

Well, not quite

Having shown in what way modules, classes and instances are basically
the same, let's discuss in what way they are different.

o Attribute lookup

print AModule.attr 		

tries to do an attribute look-up in AModule.__dict__. If 'attr' is not
in the dictionary (a KeyError) an AttributeError is raised.

print AClass.attr

first tries to do an attribute look-up in AClass.__dict__. If 'attr' is
not in the dictionary, then the attribute lookup is tried (recursively)
in all of AClass's bases. Only if that fails an AttributeError is
raised.

print AInstance.attr

first tries to do an attribute look-up in AInstance.__dict__. If 'attr'
is not in the dictionary, then the attribute lookup is tried in the
class that instatiated the Instance, using the lookup rule for
AClass.attr.

Suprisingly, in terms of attribute lookup, there is no difference
between

AInstance = Class()

and

class AInstance(Class):
    pass

I tend to think of classes as inheritable modules. Inheritance beeing
implemented as recursive attribute lookup

So, what distinguishes classes from instances

o Functions and methods

You already noticed that Python doesn't have static methods. That is
because 
methods require instance of their class as first arguments. And that's
basically the difference between a class and an instance: An attribut
lookup on an instance 
returning a function object,  will result in a bound method, while the
same
attribute lookup instigated on a class will result in an unbound method. 

Hence, Given:

AClass:
    def func(self)

AInstance = Class()

AInstance.func()
Class.func(AInstance)
Class.__dict__['func'](AInstance)

will all give the same result, while

AInstance.func
Class.func
Class.__dict__['func']

gives a bound method, an unbound method and function object
respectively.
This is an example of different context (namespace) giving different
meanings to the same Class.__dict__['func']

Phew,

All this to show you that there is a single paradigm (namespaces), that
unifies classes and modules.

Now I would argue (but not in this post), that namespace (modularity,
data hiding, data-operation grouping) is the root concept of object
oriented programming. Modules just add encapsulation (names referring to
other namespaces), and classes just add inheritance (extension of
namespaces)



> >
> >
> > | Python unfortunately does not support overriding...
> >
> > It does.  It doesn't support overloading.
> 
> uuuuuuh!!! oops ! yes. That's what i meant...
> 

The python idiom for overloading is

class A:
    def func(arg1, arg2, arg3=None):
	if arg3 is None:
            if type(arg2) = type('')
                return two_arg_function1(arg1, arg2)
            else:
                ...do something...
		return
        else:
            return three_arg_function(arg1, arg2, arg3)

i.e. dispatch based on signature (number/type of arguments)

[snip]

Hop[e this helps,

-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From tmbrau00@centre.edu  Thu May 17 04:54:51 2001
From: tmbrau00@centre.edu (Timothy M. Brauch)
Date: Wed, 16 May 2001 23:54:51 -0400
Subject: [Tutor] Tkinter Help
Message-ID: <3B034B8B.2B9E1C35@centre.edu>

I have no experience with Tkinter, but I am planning on learning.  I've
got <http://www.pythonware.com/library/tkinter/introduction/index.htm>
bookmarked, at least.  But, I have what I hope will be a quick question
that I didn't find when I looked through the Intro site.

If I have a dictionary full of keys and values, what would be a simple
way to print those keys and values in a Tkinter widget.  Also, if the
values change, I would need to update the displayed values.

Quick example:

dict={'key_0':0, 'key_1':1, 'key_2':2, 'key_3':3, 'key_4':4, 'key_5':5}

I would like an output of something like:

---------------------------
| key_0 = 0     key_3 = 3 |
| key_1 = 1     key_4 = 4 |
| key_2 = 2     key_5 = 5 |
---------------------------

But, if I do dict['key_0']=6, I would really love it if I could update
it, by calling a function or something, to:

---------------------------
| key_0 = 6     key_3 = 3 |
| key_1 = 1     key_4 = 4 |
| key_2 = 2     key_5 = 5 |
---------------------------

I hope this isn't too hard to do.  Also, are there books that cover
Tkinter, especially for Python, that stick out in anyone's mind?  Hasn't
Alan Gauld written something covering Tkinter recently?

 - Tim


From howard.brydle@i3dimensions.com  Thu May 17 05:46:43 2001
From: howard.brydle@i3dimensions.com (Howard Brydle)
Date: Wed, 16 May 2001 21:46:43 -0700
Subject: [Tutor] input() doesn't work in IDLE?
Message-ID: <EDCBFB26F309EB42819D500D78540A4E01FB6D@r2d2.i3dimensions.com>

Python 1.5.2 for Windows: The input() function (and raw_input) does not
see the <return> that I type in the output window to end my input
string, and does not proceed to the next statement in my script, when I
am running the script in IDLE. It does work in Pythonwin.=20


From hbrydle@hotmail.com  Thu May 17 05:54:05 2001
From: hbrydle@hotmail.com (Howard Brydle)
Date: Wed, 16 May 2001 21:54:05 -0700
Subject: [Tutor] input() does not see <RETURN>
Message-ID: <F10157YEUm49S6OpRIL00001d69@hotmail.com>

<html><DIV><FONT size=2>
<P>Python 1.5.2 for Windows: The input() function (and raw_input) does not see the &lt;return&gt; that I type in the output window to end my input string, and does not proceed to the next statement in my script, when I am running the script in IDLE. It does work in Pythonwin. </P></FONT></DIV><br clear=all><hr>Get Your Private, Free E-mail from MSN Hotmail at <a href="http://www.hotmail.com">http://www.hotmail.com</a>.<br></p></html>


From NHYTRO@compuserve.com  Thu May 17 07:48:07 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Thu, 17 May 2001 02:48:07 -0400
Subject: [Tutor] Tutor digest, Vol 1 #809 - 12 msgs
Message-ID: <200105170248_MC2-D150-AC92@compuserve.com>

Message text written by INTERNET:tutor@python.org
>
Won't work because the asp engine doesn't transmit the white space in <%=3D=

%>to =

python.  I guess this has the advantage of keeping most of your code
outside of the =

html.  I have a couple more complex examples if you want them.  We mainly=

use =

python and the Reportlab package to generate pdf reports and stream them
down to =

the browser.

-Sam<

Hi Sam! can I have some of these complex examples too? I had started of
writing ASP code in Python, but I got bogged down because I had to check
even 2 -3 liners to see what went wrong, I gave up and went back to CGI.


Thanks

Sharriff =



From alan.gauld@bt.com  Thu May 17 10:44:07 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 May 2001 10:44:07 +0100
Subject: [Tutor] singleton pattern
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D781@mbtlipnt02.btlabs.bt.co.uk>

> > Speculative code warning - I haven't tried this, 

I did warn you :-)

> >    def __init__(self,class):
> > ...
> >       else: self = Factory.instance
> >       self.class = class

> It doesn't actually do anything...
> ... Whatever was referring to the new instance before 
> is still referring to it. 

Ah yes, of course. Silly me.
So the best I could do would be throw an exception
if self.instance is not None... But that doesn't 
really help me get a handle to the singleton instance.
Unless the SingltetonClass exception object contained
a reference to the instance - now that might work.

Then we could do:

class SingletonClass(Exception):
  def __init__(self, obj):
     self.instance = obj

class Factory:
  instance = None
  def __init__(self, producedClass):
      self.producedClass = producedClass     
      if Factory.instance is None:
        Factory.instance = self
      else: raise SingletonClass(self.instance)
      
  def makeInstance(self):
      return self.producedClass()

class Baz: pass
     
for i in range(3):
   try: f = Factory(Baz)
   except SingletonClass, s: f = s.instance
   print f

baz = f.makeInstance()
print baz


Which produced(I have a python installation now)
>>> <__main__.Factory instance at 019DCE0C>
<__main__.Factory instance at 019DCE0C>
<__main__.Factory instance at 019DCE0C>
<__main__.Baz instance at 019EE12C>

Which seems to work!

> Besides, 'class' is a reserved word :)

Ok, is producedClass any better :-)

Alan g.


From dyoo@hkn.eecs.berkeley.edu  Thu May 17 11:35:14 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 17 May 2001 03:35:14 -0700 (PDT)
Subject: [Tutor] Re: Turtle Graphics thread
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D77C@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.21.0105170322080.2006-100000@hkn.eecs.berkeley.edu>

On Wed, 16 May 2001 alan.gauld@bt.com wrote:

> The digest gor scrambled but Danny was asking about turtle graphics and
> someone said:
> 
> >> >I know that the Python distribution comes with a sample turtle module.
> >> >Can anyone suggest others?  Thanks!
> >>
> >> No, but I'm fascinated by the concept.
> >
> >  Indeed...logo is a language where you are a turtle drawing 
> >lines...it's not that complex - perhaps some of the structures 
> >could be borrowed from that and implemented in python?
> 
> Logo was first with turtle graphics but they are available
> in most languages now. Certainly Turbo Pascal, Smalltalk, 
> C++, Lisp etc all have turtle modules. Python does too but 
> I couldn't get it to work - can't recall what the problem was.

What would be really nice is to have a turtle module as part of the
standard library, or at least have good support for Guido's module.  The
overall feeling that I'm getting is that turtle graphics are nice, but an
afterthought in the Python community.  But if we're going to seriously
consider Python in education (CP4E and all), there probably needs to be a
really good turtle-graphics module to make graphics programming more
appealing.

Gosh, I'm starting to sound like I'm in edu-sig.  Maybe we can write a
turtle module interactively on tutor, and have it beat the heck out of
Guido's module... *grin*


I've found out more about the fractals using turtle graphics, and it seems
really neat.  The idea of "L-systems" from Biology can be used, to control
the turtle to draw really intricate graphics.  As soon as I have time,
I'll see if I can write a simple example to show this.


> Incidentally Logo is a list processing language rather like 
> Lisp but with fewer parentheses. Modern versions have full 
> OO facilities and you can even write windows programs if 
> you really want! Worth a look for the language curious :-)

I know that Brian Harvey's written a series of CS books using Logo as the
primary language.  His series of books are called "Computer Science Logo
Style", and they're really cool stuff.

    http://www-mitpress.mit.edu/book-home.tcl?isbn=0262581515

What surprised me is that Harvey doesn't use Logo's turtle graphics at all
in his presentation of CS concepts, showing that Logo is more than just
turtle graphics --- its list-manipulation features are very impressive.



From NHYTRO@compuserve.com  Thu May 17 12:00:34 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Thu, 17 May 2001 07:00:34 -0400
Subject: [Tutor] FTP image path question...
Message-ID: <200105170700_MC2-D148-2CA2@compuserve.com>

Hi guys!


My FTP upload snippet works fine, a user can edit a page and add an Image=

to his/her text in a textarea in an HTML form, I then upload the users
text, and the image-paths from this form per CGI. My problem is that the
FTP part of my script refers to image paths on the server and not the
client anymore.

Details:

1. User adds 'c:\temp\test.jp' to his edited HTML block
2. HTML is parsed and modifed and saved to a remote directory on the serv=
er
3. The original path, 'c:\temp\test' to the image are passed to FTP uploa=
d
snippet
4.  Server tries to upload image, but from a directory also named
'c:\temp\test.jpg' on a local directory.
5. FTP snippet fails

How do I inform the server  that the FTP upload is from the clients syste=
m
and not a local directory on the server.


Thanks


Sharriff


From alan.gauld@bt.com  Thu May 17 11:47:18 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 May 2001 11:47:18 +0100
Subject: [Tutor] Re: Turtle Graphics thread
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D787@mbtlipnt02.btlabs.bt.co.uk>

> I know that Brian Harvey's written a series of CS books using 
> Logo as the primary language.  

Yes, If I hadn't been pointed at Python my intro to programming 
would probably have been done in Logo...

> What surprised me is that Harvey doesn't use Logo's turtle 
> graphics at all in his presentation of CS concepts, 

Yes, Logo is associated with turtles but is a powerful 
language in it's own right. I used it on an old CP/M 
machine where the language choices were Microsioft Basic
(single letter variables etc) or Logo - no contest really! 
The only snag was that Logoi was even slower than Basic 
- and on a 1MHz 8 bit CPU the differences were important. 
I wrote a text editor but it took about a second to delete 
a line! And could only handle 16K long files... 

It would be fun to dig out the code and try running it 
on a modern PC version of Logo.

Ah, nostalgia :-)

Alan G.


From kalle@gnupung.net  Thu May 17 12:42:53 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Thu, 17 May 2001 13:42:53 +0200
Subject: [Tutor] input() doesn't work in IDLE?
In-Reply-To: <EDCBFB26F309EB42819D500D78540A4E01FB6D@r2d2.i3dimensions.com>; from howard.brydle@i3dimensions.com on Wed, May 16, 2001 at 09:46:43PM -0700
References: <EDCBFB26F309EB42819D500D78540A4E01FB6D@r2d2.i3dimensions.com>
Message-ID: <20010517134252.A22346@father>

Sez Howard Brydle:
> Python 1.5.2 for Windows: The input() function (and raw_input) does not
> see the <return> that I type in the output window to end my input
> string, and does not proceed to the next statement in my script, when I
> am running the script in IDLE. It does work in Pythonwin. 

This is a known bug in the version of IDLE in Python 1.5.2.  It is fixed in
later versions, released with Python 1.6, 2.0 and 2.1.
I'm not sure if these new versions work with Python 1.5.2, you'll have to
test.  Anyway, I recommend upgrading to 2.1 if it's possible.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From arcege@speakeasy.net  Thu May 17 12:40:04 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 17 May 2001 07:40:04 -0400 (EDT)
Subject: [Tutor] singleton pattern
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D781@mbtlipnt02.btlabs.bt.co.uk> from "alan.gauld@bt.com" at May 17, 2001 10:44:07 AM
Message-ID: <200105171140.f4HBe5K14376@dsl092-074-184.bos1.dsl.speakeasy.net>

alan.gauld@bt.com wrote
> Then we could do:
> 
> class SingletonClass(Exception):
>   def __init__(self, obj):
>      self.instance = obj

How about trying not to fake out the mechanisms and just using Python
classes?

class SingletonInstance:
  instance = None  # class member for the singleton instance
  def __init__(self, klass):
    if self.__class__.instance is None:
      self.__class__.instance = klass() # make the instance
  # attribute methods to access the singleton instance
  def __getattr__(self, attr):
    return getattr(self.__class__.instance, attr)
  def __setattr__(self, attr, value):
    return setattr(self.__class__.instance, attr, value)
  def __delattr__(self, attr):
    delattr(self.__class__.instance, attr)

def Factory(klass):
  return SingletonInstance(klass)

Guido once also suggested that replacing __class__ (which is something I
believe Alan was attempting to do) is not a good thing (thought it work).

All this has already been discussed at length in the c.l.p newsgroup a few
years ago.  IMO, Factory classes are not something that new programmers
(reading the tutor list to learn) should be grappling.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From pursang@interact.net.au  Fri May 18 00:04:08 2001
From: pursang@interact.net.au (John Murray)
Date: Thu, 17 May 2001 23:04:08 +0000
Subject: [Tutor] Redirecting output
Message-ID: <01051723040800.01845@localhost.localdomain>

I'm building a tkinter front end for an existing command line program. When 
this is started from the cl it prints out a couple of lines of text to 
indicate that it has started OK etc. I'd like to redirect this to a label 
widget or similar in the front end. However, when I start it from the cl with 
stdout or stderr (or both) redirected to a text file, the output doesn't 
appear on screen (this is normal) but the file created remains empty. Where 
is the output going? Redirecting stdout from shell commands works normally. 
A bit off-topic I know but hoping someone can help.
                         Cheers
                            John


From samus@feudalkingdoms.tzo.org  Thu May 17 15:48:09 2001
From: samus@feudalkingdoms.tzo.org (Sam Corder)
Date: Thu, 17 May 2001 14:48:09 +0000
Subject: [Tutor] Re: ASP examples
Message-ID: <E150P6N-0002rN-00@mail.python.org>


NHYTRO@compuserve.com wrote:
>
>Message text written by INTERNET:samus@feudalkingdoms.tzo.org
>>Are there any specific types of examples you would like to see?  I'll po=
>st
>what I =
>can to the tutor list when I get your reply.  I have code that uses ado,
>the =
>session object and a couple of the other asp objects.  Most of the stuff =
>I
>write in =
>asp interacts with specific classes and com components that I have writte=
>n.
> The =
>asp is just the bare bones presentation logic.
>-Sam<
>Thanks Sam for replying!
>I really would like to see the use of ADO, Sessions and IE manipulation.
>best regards
>Sharriff

Heres a quick example of ADO.  If you want to call stored procs then you will need 
the line cmd.CommandType = constants.adCmdStoredProc somewhere before rs.Open.  The 
default is adCmdText.

import win32com.client
constants = win32com.client.constants

cmd = win32com.client.Dispatch('ADODB.Command')
rs = win32com.client.Dispatch('ADODB.Recordset')

cmd.ActiveConnection = connectstr
cmd.CommandText = sql
rs.Open(cmd, CursorType = constants.adOpenForwardOnly, LockType = 
constants.adLockReadOnly)

You can also do rs=cmd.Execute() and pass any optional parameters.  Execute may 
return things in a tuple.  I forget since I don't use it often in Python.  You can 
take a look at http://groups.google.com/groups?
hl=en&lr=lang_en&newwindow=1&safe=off&ic=1&th=c9f66eafa42195a1,4&seekm=CPEKKMGLLILAJ
EKJNAPDAEEBCBAA.scorder%40incigna.com#p for a basic python class that has the 
startings of an encapsulation of this stuff.  I never went very far with this class 
because we usually use a vb dll that has business and security logic in it to 
access our databases.  Its still pretty similar.  The Python code just gets 
shorter.  Heres a code fragment that illustrates this.
        sacsApp = win32com.client.Dispatch('SACS.Application')
        sacsApp.Initialize("sacsowner")
        sr = sacsApp.Reports
        rs = win32com.client.Dispatch('ADODB.Recordset')
        rs = sr.StateFilingStatus(CompanyList, StateList, EditionDate, FormNumber, 
Plancode, FormType, FormUserList)

The first rs = is probably not necessary because the last method returns a 
recordset.  For your vb dlls make sure that the parameters passed in are declared 
as byval.  Default is byref which for com means its an in/out parameter and python 
will return a tuple back to you.

Here is getting some data out by using GetRows.  GetRows returns stuff back weirdly 
so we have to rotate the rows around.  
        rows = rs.GetRows(1000)        
        #First rotate the cols to rows and rows to cols
        rows = zip(rows[0],rows[1],rows[2],rows[3],rows[4],rows[5],rows[6],rows
[7],rows[8],rows[9],rows[10],rows[11])

If you just want to spit out a table or something then I would suggest using 
GetString and then regular expressions to format the the table nicer.  Its much 
faster than looping through a result set and doing Response.write(blahblahblah)

Here are some asp object uses.

This code writes out a session variable
Response.Write(Session.Contents.Item("UserName"))

Thats about the jist of it all.  The main thing that gets me all the time is the 
lack of "shortcuts" that vbscript has.  These are the default methods of objects.  
Python doesn't pay any attention to them.  I.E in vbscript the same session 
expression above would be session("UserName").  You can find these by using a com 
object browser or looking at the platform sdk documentation on msdn.microsoft.com

As for IE manipulations thats best done in javascript on the client side.  One 
thing we do is based on a page and a persons access writes we will generate some 
form validation javascript that gets called in an onSubmit event of a form.  For 
you to do IE manipulation in python the client browser will need the python stuff 
installed and configured.  Hope all this helps.

-Sam


From arcege@speakeasy.net  Thu May 17 18:15:36 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 17 May 2001 13:15:36 -0400 (EDT)
Subject: [Tutor] Re: Turtle Graphics thread
In-Reply-To: <Pine.LNX.4.21.0105170322080.2006-100000@hkn.eecs.berkeley.edu> from "Daniel Yoo" at May 17, 2001 03:35:14 AM
Message-ID: <200105171715.f4HHFaj14592@dsl092-074-184.bos1.dsl.speakeasy.net>

Daniel Yoo wrote
> What would be really nice is to have a turtle module as part of the
> standard library, or at least have good support for Guido's module.  The
> overall feeling that I'm getting is that turtle graphics are nice, but an
> afterthought in the Python community.  But if we're going to seriously
> consider Python in education (CP4E and all), there probably needs to be a
> really good turtle-graphics module to make graphics programming more
> appealing.

There is a turtle module that is part of the standard library.  Like many
in the standard library, it's undocumented.  In 1.5.2, it is in the
lib directory, and later releases in lib/lib-tk.  There is a little
demo in there and seems to have all the same bells as the logo version
(from what little I remember).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From virketis@fas.harvard.edu  Thu May 17 18:44:34 2001
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Thu, 17 May 2001 13:44:34 -0400
Subject: [Tutor] Tkinter Help
Message-ID: <200105171739.f4HHdg726815@smtp4.fas.harvard.edu>

Hi Tim.

This is a quick take on your problem before I rush off to have lunch.:) I
bet the real masters of the art will find much to fault with my solution.
Here goes anyway. Note that if you put the code into a function, you'll
have a procedure which can be used to update the GUI to the state of the
list, just make sure to kill the old frame beforehand.

########################### code ############################
from Tkinter import *

root = Tk()
frame = Frame(root)
frame.pack()

dict={'key_0':0, 'key_1':1, 'key_2':2, 'key_3':3, 'key_4':4, 'key_5':5}

# establish sequence in a list
key_list = dict.keys()
key_list.sort()

# if ... else lets us split the list into two columns
for position in range(len(key_list)):
	if position < (len(key_list)/2):
		label = Label(frame,
text=(key_list[position]+"="+repr(dict[key_list[position]])))
		label.grid(row = position, col = 0) # first column
	else: 
		label = Label(frame,
text=(key_list[position]+"="+repr(dict[key_list[position]])))
		label.grid(row=(position-len(key_list)/2), col = 1) # second column

########################## end of code ##########################

I hope this helps.

Pijus
----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis.


From alan.gauld@bt.com  Thu May 17 18:38:17 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 May 2001 18:38:17 +0100
Subject: [Tutor] Tkinter Help
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D78F@mbtlipnt02.btlabs.bt.co.uk>

> Quick example:
> 
> dict={'key_0':0, 'key_1':1, 'key_2':2, 'key_3':3, 'key_4':4, 
> 'key_5':5}
> 
> I would like an output of something like:
> 
> ---------------------------
> | key_0 = 0     key_3 = 3 |
> | key_1 = 1     key_4 = 4 |
> | key_2 = 2     key_5 = 5 |
> ---------------------------

You could create a loop which for each key created a label 
and text field and packed them into a containing frame.

Try downloading my games framework from Useless Python
(or buy my book ;-) and see a somewhat similar idea creating 
a grid of buttons. Its in the hmgui.py file, in the 
displayStart method of the hmGUI class.

To get dynamic update you need to create an IntVar 
or StrVar object and associate it with the text entry 
(I think you can do that!)

Not trivial but far from impossible....

> Alan Gauld written something covering Tkinter recently?

Yes, 

http://www.crosswinds.net/~agauld/tutgui.htm

but it's not that detailed. Better is F/'s reference/tutor
and the sample code mentioned above.

Alan g.


From alan.gauld@bt.com  Thu May 17 18:41:56 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 May 2001 18:41:56 +0100
Subject: [Tutor] input() doesn't work in IDLE?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D790@mbtlipnt02.btlabs.bt.co.uk>

> This is a known bug in the version of IDLE in Python 1.5.2.  
> It is fixed in later versions, 

> I'm not sure if these new versions work with Python 1.5.2, 


There is an IDLE0.6 version you can download as standalone.
Basically unpack the new IDLE files into a new folder then 
swap names with the existing IDLE folder and it will work 
OK with 1.5.2

Anyone with my book will find the updated IDLE on the CD 
along with a more detailed text file describing how to 
install it....


Alan G


> you'll have to
> test.  Anyway, I recommend upgrading to 2.1 if it's possible.
> 
> Peace,
>   Kalle
> -- 
> Email: kalle@gnupung.net     | You can tune a filesystem, but you
> Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
> PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
>  [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
> 
> 


From alan.gauld@bt.com  Thu May 17 18:45:55 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 May 2001 18:45:55 +0100
Subject: [Tutor] singleton pattern
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D791@mbtlipnt02.btlabs.bt.co.uk>

> How about trying not to fake out the mechanisms and just using Python
> classes?
> 
> class SingletonInstance:
>   instance = None  # class member for the singleton instance
>   def __init__(self, klass):
>     if self.__class__.instance is None:

Hmm, I need to do some digging. I've never played with 
Python's object model at that level...

Alan G.
> Guido once also suggested that replacing __class__ (which is 
> something I believe Alan was attempting to do) 

I wasn't replacing class just returning a pointer to the 
original instance as an attribute of the Exception.

But the magic methods might provide a better solution, 
I'll take a look over the weekend.

Alan G.


From arcege@speakeasy.net  Thu May 17 19:47:47 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 17 May 2001 14:47:47 -0400 (EDT)
Subject: [Tutor] singleton pattern
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D791@mbtlipnt02.btlabs.bt.co.uk> from "alan.gauld@bt.com" at May 17, 2001 06:45:55 PM
Message-ID: <200105171847.f4HIllv14690@dsl092-074-184.bos1.dsl.speakeasy.net>

alan.gauld@bt.com wrote
> Alan G.
> > Guido once also suggested that replacing __class__ (which is 
> > something I believe Alan was attempting to do) 
> 
> I wasn't replacing class just returning a pointer to the 
> original instance as an attribute of the Exception.

This was in an earlier email you had sent out (something about
"self.class = ..." within the __init__ method).

It was something more like:

class FactInst:
  pass
class Factory:
  def __init__(self, klass):
    self.klass = klass
  def __call__(self, *args, **kws)
    # create a dummy instance
    inst = FactInst()
    # change its class
    inst.__class__ = self.klass
    # call the initialization routine
    apply(inst.__init__, args, kws)
    # return the re-class-fied instance
    return inst

class Spam:
  def __init__(self, msg):
    self.msg = msg
  def __str__(self):
    return msg
FactSpam = Factory(Spam)  # a new factory instance to be used like a class
brkfast = FactSpam("spam, spam, eggs & spam")  # a new "Spam" instance
print brkfast

It's been a few years since I read that thread, and I probably don't have
things exactly right, but the idea is to replace some of the "important"
bindings within an instance with other class info altogether.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From kromag@nsacom.net  Thu May 17 22:43:05 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Thu, 17 May 2001 14:43:05 -0700 (PDT)
Subject: [Tutor] lockfiles and timestamps and nested if's!
Message-ID: <200105172143.f4HLh5j14550@pop.nsacom.net>

I am attempting a silly thing. I wish to make a script that will:

1. Check for the existence of a lockfile.
2. Check the age of the lockfile.
 
Then either:
Delete the lockfile if it is too old and continue, 
or
exit gracefully.

I have managed to get myself into a dither here. The script for some reason 
always writes a new lock file and updates the timestamp. Can someone clue me 
in? My brain is full.

import glob
import time
import string
import os
import socket

now=time.time()
mybox=socket.gethostname()+'.txt'
whoa=glob.glob('\tmp\*')
if whoa==['\tmp\'+mybox]:
	lockfile=open('\tmp\'+mybox, 'r')
	timestamp=lockfile.readline()
	print timestamp
	lockfile.close()
	if timestamp > time.time()-10:
		print 'old lockfile ok',
	else:
		os.remove('\tmp\'+mybox)
		
else:
	lockfile=open('\tmp\'+mybox, 'w')
	lockfile.write(`now`)
	print 'new lockfile'
	print 'and contiue with the rest of this balderdash!






From arcege@speakeasy.net  Thu May 17 21:05:56 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 17 May 2001 16:05:56 -0400 (EDT)
Subject: [Tutor] lockfiles and timestamps and nested if's!
In-Reply-To: <200105172143.f4HLh5j14550@pop.nsacom.net> from "kromag@nsacom.net" at May 17, 2001 02:43:05 PM
Message-ID: <200105172005.f4HK5uY14773@dsl092-074-184.bos1.dsl.speakeasy.net>

kromag@nsacom.net wrote
> 
> I am attempting a silly thing. I wish to make a script that will:
> 
> 1. Check for the existence of a lockfile.
> 2. Check the age of the lockfile.
>  
> Then either:
> Delete the lockfile if it is too old and continue, 
> or
> exit gracefully.
> 
> I have managed to get myself into a dither here. The script for some reason 
> always writes a new lock file and updates the timestamp. Can someone clue me 
> in? My brain is full.
> 
> import glob
> import time
> import string
> import os
> import socket
> 
> now=time.time()
> mybox=socket.gethostname()+'.txt'
> whoa=glob.glob('\tmp\*')
> if whoa==['\tmp\'+mybox]:
> 	lockfile=open('\tmp\'+mybox, 'r')
> 	timestamp=lockfile.readline()
> 	print timestamp
> 	lockfile.close()
> 	if timestamp > time.time()-10:
> 		print 'old lockfile ok',
> 	else:
> 		os.remove('\tmp\'+mybox)
> 		
> else:
> 	lockfile=open('\tmp\'+mybox, 'w')
> 	lockfile.write(`now`)
> 	print 'new lockfile'
> 	print 'and contiue with the rest of this balderdash!

Off hand, I would say (ignoring the quoting problem), that \tmp\ has
more than just that lockfile in it.  I would check with os.path.exists
instead of glob.glob.

Also beware of race conditions; your form of locking isn't necessarily
"safe".  On Win32, I believe that os.mkdir() is safe in terms of
guaranteeing who owns the lock.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From bdupire@seatech.fau.edu  Thu May 17 21:06:24 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Thu, 17 May 2001 16:06:24 -0400
Subject: [Tutor] lockfiles and timestamps and nested if's!
References: <200105172143.f4HLh5j14550@pop.nsacom.net>
Message-ID: <3B042F3F.DF1C9757@seatech.fau.edu>


kromag@nsacom.net wrote:

> I am attempting a silly thing. I wish to make a script that will:
>
> 1. Check for the existence of a lockfile.
> 2. Check the age of the lockfile.
>
> Then either:
> Delete the lockfile if it is too old and continue,
> or
> exit gracefully.
>
> I have managed to get myself into a dither here. The script for some reason
> always writes a new lock file and updates the timestamp. Can someone clue me
> in? My brain is full.
>
> import glob
> import time
> import string
> import os
> import socket
>
> now=time.time()
> mybox=socket.gethostname()+'.txt'
> whoa=glob.glob('\tmp\*')
> if whoa==['\tmp\'+mybox]:

maybe that here is the pitfall: you are comparing 2 lists......which are not
equal so the else clause is executed.
To make sure, just print whoa and look at what it looks like.

It would be better to replace this comparison, with something like:

lockfilename='\tmp\'+mybox
if  lockfilename in  glob.glob('\tmp\*'):
        <bla bla>

which is a string-object comparison, which i think is what you are trying to
do....

But i am not sure i understand what you wanted to do.
Hope that helps,

Benoit


>
>         lockfile=open('\tmp\'+mybox, 'r')
>         timestamp=lockfile.readline()
>         print timestamp
>         lockfile.close()
>         if timestamp > time.time()-10:
>                 print 'old lockfile ok',
>         else:
>                 os.remove('\tmp\'+mybox)
>
> else:
>         lockfile=open('\tmp\'+mybox, 'w')
>         lockfile.write(`now`)
>         print 'new lockfile'
>         print 'and contiue with the rest of this balderdash!
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?




From dsh8290@rit.edu  Thu May 17 21:10:21 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 17 May 2001 16:10:21 -0400
Subject: [Tutor] lockfiles and timestamps and nested if's!
In-Reply-To: <200105172143.f4HLh5j14550@pop.nsacom.net>; from kromag@nsacom.net on Thu, May 17, 2001 at 02:43:05PM -0700
References: <200105172143.f4HLh5j14550@pop.nsacom.net>
Message-ID: <20010517161021.A5078@harmony.cs.rit.edu>

On Thu, May 17, 2001 at 02:43:05PM -0700, kromag@nsacom.net wrote:
| I have managed to get myself into a dither here. The script for some reason 
| always writes a new lock file and updates the timestamp. Can someone clue me 
| in? My brain is full.
| 
| import glob
| import time
| import string
| import os
| import socket
| 
| now=time.time()
| mybox=socket.gethostname()+'.txt'
| whoa=glob.glob('\tmp\*')

Right here insert the line

print whoa

I bet it isn't what you think it is.

| if whoa==['\tmp\'+mybox]:
| 	lockfile=open('\tmp\'+mybox, 'r')
| 	timestamp=lockfile.readline()
| 	print timestamp
| 	lockfile.close()
| 	if timestamp > time.time()-10:
| 		print 'old lockfile ok',
| 	else:
| 		os.remove('\tmp\'+mybox)
| 		
| else:
| 	lockfile=open('\tmp\'+mybox, 'w')
| 	lockfile.write(`now`)
| 	print 'new lockfile'
| 	print 'and contiue with the rest of this balderdash!

| whoa=glob.glob('\tmp\*')
| if whoa==['\tmp\'+mybox]:

I notice you used backslashes here (\).  I think you meant to use
forward slashes (/).  The \t gets expanded to a tab character.

-D



From sheila@thinkspot.net  Thu May 17 21:22:50 2001
From: sheila@thinkspot.net (Sheila King)
Date: Thu, 17 May 2001 13:22:50 -0700
Subject: [Tutor] URL redirect cgi script
Message-ID: <8E27EA97C4B@kserver.org>

OK, this is something I thought I knew how to do. I have no idea why my script
isn't work correctly.

I have an IP number that I want to prohibit from my website. Basically, I want
to redirect any HTTP requests from this IP number to some other web address
(possibly within my own site, or maybe not. That's not the important thing.)

This script, called 403.py, is supposed to be my 403 error document on an Apache
web server.

Here is the document:

---------------------------------------------------------
#!/big/dom/xthinkspot/bin/python2.0

import os, httplib

denyList =['127.0.0.1', '128.158.104.168']

if str(os.environ["REMOTE_ADDR"]) in denyList:
    print r"Location: http://www.futurequest.net"
    print
    print
else:
    print r"Location: http://www.k12groups.org/403.html"
    print
    print
---------------------------------------------------------

Now, the 127.0.0.1 I had replaced with my own IP address, and I have a .htaccess
document on the website, and I also put my IP address in there, to deny. (I have
to test this somehow, right?)

When I went to the website, I can tell that the script is being called. I
checked it in Sam Spade, and here is the output of the HTTP request:

---------------------------------------------------------
05/17/01 13:17:44 Browsing http://www.k12groups.org
Fetching http://www.k12groups.org/ ...
GET / HTTP/1.1

Host: www.k12groups.org
Connection: close
User-Agent: Sam Spade 1.14


HTTP/1.1 403 Forbidden
Date: Thu, 17 May 2001 20:18:07 GMT
Server: Apache/1.3.17 (Unix) mod_macro/1.1.1 PHP/4.0.4pl1
Location: http://www.futurequest.net
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain

1  


0

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

So, the script is being called. However, it is not redirecting to the URL in the
Location: header. It basically stays at my site, with a completely blank page
(since no HTML code is being sent). Matter of fact, I'm surprised that the
Content-Type: text/plain is being sent. I've tried with fewer print statements.
(I thought I should need only two print statements: (1) to send the Location
header, and (2) to send a blank line to indicate the end of the headers.) But
when I take out the second blank print statement, I get a "document contained no
data" error message.

I've gone round and round on this, and I'm tearing my hair out over it.

If anyone has any ideas, I'd sure appreciate a tip.

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



From scarblac@pino.selwerd.nl  Thu May 17 22:49:18 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 17 May 2001 23:49:18 +0200
Subject: [Tutor] Redirecting output
In-Reply-To: <01051723040800.01845@localhost.localdomain>; from pursang@interact.net.au on Thu, May 17, 2001 at 11:04:08PM +0000
References: <01051723040800.01845@localhost.localdomain>
Message-ID: <20010517234918.A11381@pino.selwerd.nl>

On  0, John Murray <pursang@interact.net.au> wrote:
> I'm building a tkinter front end for an existing command line program. When 
> this is started from the cl it prints out a couple of lines of text to 
> indicate that it has started OK etc. I'd like to redirect this to a label 
> widget or similar in the front end. However, when I start it from the cl with 
> stdout or stderr (or both) redirected to a text file, the output doesn't 
> appear on screen (this is normal) but the file created remains empty. Where 
> is the output going? Redirecting stdout from shell commands works normally. 
> A bit off-topic I know but hoping someone can help.

I have no idea, really. If this is Windows, there are problems with
redirecting, maybe this is part of that, I don't know.

However, you can also redirect output from Python, by setting sys.stdout to
some other file like object (like an object you made that has a write()
method that puts the text in the label).

import sys

class MyOutput:
   def write(self, s):
       # Add s to label here
       pass

try:
   sys.stdout = MyOutput()
   # Call the rest of the program here
finally:
   # It's good practice to restore stdout even if there was an exception
   sys.stdout = sys._stdout

-- 
Remco Gerlich


From rob@jam.rr.com  Thu May 17 22:55:32 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Thu, 17 May 2001 16:55:32 -0500
Subject: [Tutor] How to print the version of Python?
Message-ID: <01051716553201.01201@SQLdev>

I droop my head in shame at having to ask this one, but how can I instruct my 
script to print the version of Python running it?

Rob


From arcege@speakeasy.net  Thu May 17 23:09:58 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 17 May 2001 18:09:58 -0400 (EDT)
Subject: [Tutor] How to print the version of Python?
In-Reply-To: <01051716553201.01201@SQLdev> from "Rob Andrews" at May 17, 2001 04:55:32 PM
Message-ID: <200105172209.f4HM9wI14874@dsl092-074-184.bos1.dsl.speakeasy.net>

Rob Andrews wrote
> I droop my head in shame at having to ask this one, but how can I instruct my 
> script to print the version of Python running it?

>>> import sys
>>> print sys.version
1.5.2 (#1, Aug 25 2000, 09:33:37)  [GCC 2.96 20000731 (experimental)]
>>>

>>> import sys
>>> print sys.version
2.0 (#3, Dec 18 2000, 02:47:55)
[GCC 2.96 20000731 (Red Hat Linux 7.0)]
>>>

It was once suggested that the first three characters of the version
string is used for the printed release number.

>>> print sys.version[:3]

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From pdiaz88@terra.es  Fri May 18 01:11:42 2001
From: pdiaz88@terra.es (Pedro Diaz Jimenez)
Date: Fri, 18 May 2001 00:11:42 +0000
Subject: [Tutor] How to print the version of Python?
In-Reply-To: <01051716553201.01201@SQLdev>
References: <01051716553201.01201@SQLdev>
Message-ID: <01051800114200.07543@duero>

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

sys.version is the string you are looking for

On Thursday 17 May 2001 21:55, Rob Andrews wrote:
> I droop my head in shame at having to ask this one, but how can I instruct
> my script to print the version of Python running it?
>
> Rob
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

- -- 

/*
 * Pedro Diaz Jimenez
 * pdiaz88@terra.es 
 * pdiaz@acm.asoc.fi.upm.es
 *
 * Wanna see how 100000! looks like?:
 * http://acm.asoc.fi.upm.es/~pdiaz/fact_100.000
 * 
 * La sabiduria me persigue, pero yo soy mas rapido
 *
 */

Random quote:
- -------------

Don't kiss an elephant on the lips today.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7BGjPnu53feEYxlERAnU2AKDSufjr5oqUzOAliOOYjRVpwObIVgCfSZrU
6GMaqkcfB/BLXRA9ySUqu4g=
=XJgd
-----END PGP SIGNATURE-----


From rob@jam.rr.com  Thu May 17 23:18:29 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Thu, 17 May 2001 17:18:29 -0500
Subject: [Tutor] How to print the version of Python?
In-Reply-To: <200105172209.f4HM9wI14874@dsl092-074-184.bos1.dsl.speakeasy.net>
References: <200105172209.f4HM9wI14874@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <01051717182902.01201@SQLdev>

Thanks. I just downloaded the .tgz of Python 2.1 to install on my linux box. 
I tried upgrading from the 1.5.2 that came installed on the system using the 
RPM, but ran into a slew of dependency issues.

I'm now trying to figure out how to take it from here. (I've already opened 
the .tgz, which usually trips me for some reason.)

Rob

On Thursday 17 May 2001 05:09 pm, Michael P. Reilly wrote:
> Rob Andrews wrote
>
> > I droop my head in shame at having to ask this one, but how can I
> > instruct my script to print the version of Python running it?
> >
> >>> import sys
> >>> print sys.version
>
> 1.5.2 (#1, Aug 25 2000, 09:33:37)  [GCC 2.96 20000731 (experimental)]
>
> >>> import sys
> >>> print sys.version
>
> 2.0 (#3, Dec 18 2000, 02:47:55)
> [GCC 2.96 20000731 (Red Hat Linux 7.0)]
>
>
> It was once suggested that the first three characters of the version
> string is used for the printed release number.
>
> >>> print sys.version[:3]
>
>   -Arcege


From r.b.rigilink@chello.nl  Thu May 17 23:51:37 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Fri, 18 May 2001 00:51:37 +0200
Subject: [Tutor] lockfiles and timestamps and nested if's!
References: <200105172143.f4HLh5j14550@pop.nsacom.net>
Message-ID: <3B0455F9.A887336E@chello.nl>

kromag@nsacom.net wrote:
> 
> I am attempting a silly thing. I wish to make a script that will:
> 


> 1. Check for the existence of a lockfile.
> 2. Check the age of the lockfile.
> 
> Then either:
> Delete the lockfile if it is too old and continue,
> or
> exit gracefully.
> 
> I have managed to get myself into a dither here. The script for some reason
> always writes a new lock file and updates the timestamp. Can someone clue me
> in? My brain is full.
> 
> import glob
> import time
> import string
> import os
> import socket
> 
> now=time.time()
> mybox=socket.gethostname()+'.txt'
> whoa=glob.glob('\tmp\*')

print whoa here, to see if the next test makes sense.
use os.listdir in stead of glob

> if whoa==['\tmp\'+mybox]:
>         lockfile=open('\tmp\'+mybox, 'r')
>         timestamp=lockfile.readline()
>         print timestamp
>         lockfile.close()
>         if timestamp > time.time()-10:

You are comparing the string timestamp with the float time.time
Are you sure you want to delete lockfiles older than 10 seconds?

>                 print 'old lockfile ok',
>         else:
>                 os.remove('\tmp\'+mybox)
> 

Are you sure the lockfile shouldn't be recreated now?

> else:

The easiest way to end up here is if there's more than one file in \tmp\

>         lockfile=open('\tmp\'+mybox, 'w')
>         lockfile.write(`now`)
>         print 'new lockfile'
>         print 'and contiue with the rest of this balderdash!
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

OK here's what I understand you want to do:

import time, os, socket, 
import string

now = time.time()
lockfilename = socket.gethostname()+'.txt'

if lockfilename in os.listdir('/tmp'):
    contents = open('/tmp/'+lockfilename,'r').readline()
    timestamp = float(string.strip(contents))
    # use contents.strip() in Python2.0

    if timestamp < now-10:
	# the timestamp is old, we have to rewrite the file
	# I'm not sure if this is actually what you want to do here
        f = open('/tmp/'+lockfilename,'w')
        f.write(str(now)+'\n')
else:
    # the file doesn't exist at all, we have to write it
    f = open('/tmp/'+lockfilename,'w')
    f.write(str(now)+'\n')
   
Hmm. two code blocks doing the same thing is ugly

Maybe
- put lockfile creation and lockfile checking in functions ?
- use exceptions ?

Ah, this works anyway.

Hope this helps,

Roeland

-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From lsloan@umich.edu  Fri May 18 00:07:16 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 17 May 2001 19:07:16 -0400
Subject: [Tutor] lockfiles and timestamps and nested if's!
In-Reply-To: Your message of "Thu, 17 May 2001 14:43:05 PDT."
 <200105172143.f4HLh5j14550@pop.nsacom.net>
Message-ID: <200105172307.TAA15244@birds.us.itd.umich.edu>

kromag@nsacom.net wrote:
>     lockfile=open('\tmp\'+mybox, 'r')
>     timestamp=lockfile.readline()
>     print timestamp
>     lockfile.close()
>     if timestamp > time.time()-10:

This is probably not the cause of your problem, and it may not be a
problem at all.  It might just be me being a Python newbie.

Anyway, in the second line that I quoted above, wouldn't timestamp be a
string?  If so, what will happen when the string is compared with a
number on the fifth line?

I suspect that the condition will always fail or always pass because
timestamp is a string (probably with a trailing CR and/or LF) and is
very different from the float returned by time.time().  Whether it will
be pass or fail, I don't know.  I'm not sure how Python would compare
those two datatypes.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From alan.gauld@bt.com  Fri May 18 11:43:38 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 18 May 2001 11:43:38 +0100
Subject: [Tutor] singleton pattern
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D793@mbtlipnt02.btlabs.bt.co.uk>

Acerge wrote:
> class SingletonInstance:
>   instance = None  # class member for the singleton instance
>   def __init__(self, klass):
>     if self.__class__.instance is None:

OK, I've now read the docs and had a play.

This is solving a slightly different problem, I think.
The self.__class__.instance is only a convoluted way of writing
SingletonInstance.instance - I think the latter is clearer.

>       self.__class__.instance = klass() # make the instance

This is setting the instance attribute of the SingletonInstance
class to an instance of the manufactured class. I'm not sure how 
this gives us a singleton structure? It will ensure that 
calls to SingletonInstance produce a new instance of klass
and assign it to the class variable, but for a singleton we 
want to ensure that calls to the constructor return a pointer 
to *the same* instance.

Thus:
foo = SingletonInstance(MyFileClass)

and

bar = SingletonInstance(MySocketClass)

should make foo and bar reference the same instance (but, 
in this case,  set the internal instance variable 
to a new class reference)

Whereas what we seem to have is foo referncing an instance 
of SingletonInstance with a reference to MyFileClass and able 
to access the attributes of MyFileClass instance via foo. 
And bar referencing a different instance of SingletonInstance
with a reference to MySocketClass. But does the class variable 
of both foo and bar now reference MySocketClass. In which case 
foo is going to exhibit some weird behaviour! 

This is interesting but I'm not sure its either a Factory 
or a Singleton. I think I'm maybe missing something?

> years ago.  IMO, Factory classes are not something that new 
> programmers(reading the tutor list to learn) should be grappling.

Depends on whether they are new programmers or new Pythoneers. 
If the latter they may have experience of Factories and 
Singletons from C++, ObjectiveC, Smalltalk etc. 

Alan G.


From din22@home.com  Fri May 18 12:41:22 2001
From: din22@home.com (sheri)
Date: Fri, 18 May 2001 06:41:22 -0500
Subject: [Tutor] removing digits from a file
Message-ID: <000a01c0df8f$76ac61e0$134d0141@dstn1.fl.home.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C0DF65.8D7945C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hello, i am trying to write a script to remove digits from a list of =
spelling words.=20
i have a file like this:
1. that 2. cat 3. rat 4. etc...

i want to do something like this=20
 =20
if char (is a digit)
   delete char

so that the output file is like this:
 that cat rat etc...

any help would be appreciated. thanks!

------=_NextPart_000_0007_01C0DF65.8D7945C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>hello, i am trying to write a script to =
remove=20
digits from a list of spelling words. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>i have a file like this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>1. that 2. cat 3. rat 4. =
etc...</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>i want to do something like this =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if char (is a digit)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; delete char</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>so that the output file is like =
this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;that cat rat etc...</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>any help would be appreciated.=20
thanks!</FONT></DIV></BODY></HTML>

------=_NextPart_000_0007_01C0DF65.8D7945C0--



From bdupire@seatech.fau.edu  Fri May 18 13:31:34 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Fri, 18 May 2001 08:31:34 -0400
Subject: [Tutor] removing digits from a file
References: <000a01c0df8f$76ac61e0$134d0141@dstn1.fl.home.com>
Message-ID: <3B051626.DBA2282D@seatech.fau.edu>

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

if there are space between words and numbers, and assuming each number
is folllowed by a word.. you can use string.split()

import string
mystring = "1. that 2. cat 3. rat 4. etc"
number=[]
tokens= string.split(mystring)

for i in (range(0, len(tokens), 2)):
    number.append(int(tokens[i][:-1]))     # the slicing removes the
dot.



Benoit

sheri wrote:

> hello, i am trying to write a script to remove digits from a list of
> spelling words.i have a file like this:1. that 2. cat 3. rat 4.
> etc... i want to do something like this if char (is a digit)   delete
> char so that the output file is like this: that cat rat etc... any
> help would be appreciated. thanks!

--
Benoit Dupire
Graduate Student


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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body bgcolor="#FFFFFF">
if there are space between words and numbers, and assuming each number
is folllowed by a word.. you can use string.split()
<p><font face="Arial"><font size=-1>import string</font></font>
<br><font face="Arial"><font size=-1>mystring = "1. that 2. cat 3. rat
4. etc"</font></font>
<br><font face="Arial"><font size=-1>number=[]</font></font>
<br><font face="Arial"><font size=-1>tokens= string.split(mystring)</font></font><font face="Arial"><font size=-1></font></font>
<p><font face="Arial"><font size=-1>for i in (range(0, len(tokens), 2)):</font></font>
<br><font face="Arial"><font size=-1>&nbsp;&nbsp;&nbsp; number.append(int(tokens[i][:-1]))&nbsp;&nbsp;&nbsp;&nbsp;
# the slicing removes the dot.</font></font>
<br><font face="Arial"><font size=-1></font></font>&nbsp;
<br><font face="Arial"><font size=-1></font></font>&nbsp;<font face="Arial"><font size=-1></font></font>
<p><font face="Arial"><font size=-1>Benoit</font></font>
<p>sheri wrote:
<blockquote TYPE=CITE><style></style>
<font face="Arial"><font size=-1>hello,
i am trying to write a script to remove digits from a list of spelling
words.</font></font><font face="Arial"><font size=-1>i have a file like
this:</font></font><font face="Arial"><font size=-1>1. that 2. cat 3. rat
4. etc...</font></font>&nbsp;<font face="Arial"><font size=-1>i want to
do something like this</font></font>&nbsp;<font face="Arial"><font size=-1>if
char (is a digit)</font></font><font face="Arial"><font size=-1>&nbsp;&nbsp;
delete char</font></font>&nbsp;<font face="Arial"><font size=-1>so that
the output file is like this:</font></font><font face="Arial"><font size=-1>&nbsp;that
cat rat etc...</font></font>&nbsp;<font face="Arial"><font size=-1>any
help would be appreciated. thanks!</font></font></blockquote>

<p>--
<br>Benoit Dupire
<br>Graduate Student
<br>&nbsp;
</body>
</html>

--------------BB01A215290D508C9148A112--



From bdupire@seatech.fau.edu  Fri May 18 13:37:44 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Fri, 18 May 2001 08:37:44 -0400
Subject: [Tutor] removing digits from a file
Message-ID: <3B051798.6AF19A1D@seatech.fau.edu>

ooops! you wanted to remove the dots....

So the program becomes:

import string
mystring = "1. that 2. cat 3. rat 4. etc"
number=[]
tokens= string.split(mystring)

index=0
for i in range(len(tokens)/2):
    del tokens[index]
    index= index+1

finalstring= string.join(tokens, ' ')


which outputs:

'that cat rat etc'





From r.b.rigilink@chello.nl  Fri May 18 14:08:28 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Fri, 18 May 2001 15:08:28 +0200
Subject: [Tutor] removing digits from a file
References: <000a01c0df8f$76ac61e0$134d0141@dstn1.fl.home.com>
Message-ID: <3B051ECC.EB91B0F9@chello.nl>

> sheri wrote:
> 
> hello, i am trying to write a script to remove digits from a list of
> spelling words.
> i have a file like this:
> 1. that 2. cat 3. rat 4. etc...
> 
> i want to do something like this
> 
> if char (is a digit)
>    delete char
> 
> so that the output file is like this:
>  that cat rat etc...
> 
> any help would be appreciated. thanks!

Hi Sheri,

I'm going to assume two things.
- you're using Python2.0 or later
- in your file is each line is layed-out as follows
  number whitespace word whitespace number ... 

If either one is not true, this will not work

The tricky thing in the following code is the function that tests if
a word is a number. Feel free to ask for further explanation.


def isnumber(word):
    '''A function that returns 1 (true) if word is a number, else 0
(false)
    A number is defined a something that can be converted to a float'''

    try:
        a = float(word)
        return 1    # got here, so float(word) didn't raise an error
    except ValueError:
        return 0    # float(word) raised an error

infile = open('input_filename', 'r')
outfile = open('output_filename', 'w')

while 1:
    line = infile.readline()
    if not line:    
        #reached end of file
        break       

    word_list = line.split()
    out_list = []    

    for word in word_list:
        if not isnumber(word):
            #it's not a number, so it must be a real word
            out_list.append(word)

    # make a line from the words in out_list and write it
    out_line = ' '.join(out_list)+'\n'
    outfile.write(out_line)


Hope this helps,

Roeland
_
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From r.b.rigilink@chello.nl  Fri May 18 16:06:02 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Fri, 18 May 2001 17:06:02 +0200
Subject: [Tutor] singleton pattern
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D793@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3B053A5A.8574F6EC@chello.nl>

alan.gauld@bt.com wrote:

Hi Alan, 

I snipped most of this, because I wanted to start over from here:

> .... but for a singleton we
> want to ensure that calls to the constructor return a pointer
> to *the same* instance.
> 

This is the essence of the Singleton pattern, We use it when we want to
ensure there's only one instance of a class. Let's call this class
Singleton

Now, Python (or C++ for that matter) doesn't return a pointer from the
constructor. The object reference (pointer) has allready been created by
the time we execute the constructor (the self in __init__(self)). So
there is absolutely
nothing we can do about the definition of class Singleton that will
magically
cause

>>> x = Singleton()
>>> y = Singleton()
>>> id(x) == id(y)
1

(Not without completely unpythonic namespace hackery)

So, there are two alternative approaches.

* the SingletonWrapper

class SingletonWrapper:
    singleton = None:
    def __init__(self):
	if SingletonWrapper.singleton is None:
            SingletonWrapper.singleton = Singleton()

    def __getattr__(self, attr):
        return getattr(SingletonWrapper.singleton, attr)
    def __setattr__(self, attr, value):
	setattr(SingletonWrapper.singleton, attr, value)
        
SingletonWrapper is not itself a singleton, but of Singleton there will
be only one instance, so:

>>> x = SingletonWrapper()
>>> y = SingletonWrapper()
>>> id(x) == id(y)
0
>>> x.__class__
<SingletonWrapper...>

i.e., x and y refer to different objects, but, x and y _behave_ as if
they are referring to the same object (the single Singleton instance),
So

>>> x.attr == y.attr

is always true. Arguably this is the important property of the singleton
pattern. 

Another way to implent this is in Singleton itself, by redirecting all
attribute
assignment to Singleton.__dict__.

class Singleton:
    ...
    def __setattr__(self, attr, val):
	self.__class__.__dict__[attr] == val        

This may be used as a Mixin to give a class singleton behaviour
The user may then have differen instance of Singleton that behave as
if they are all referring to the same object

* the SingletonFactory

class SingletonFactory:
    singleton = None
    def __call__(self):
        if SingletonFactory.singleton is None:
            SingletonFactory.singleton = Singleton()
        return SingletonFactory.singleton

SingletonFactory is also not itself a singleton, but of Singleton there
will again be only one instance, so:

>>> SF = SingletonFactory()
>>> x = SF()
>>> y = SF()
>>> id(x) == id(y)
1
>>> x.__class__ 
<Singleton ...>


There are endless variations on these two themes, of course.

One of the nice things you can do is store a reference to the Singleton
class
in either your SingletonWrapper or SingletonFactory, and then rename
SingletonWrapper or an instance of SingletonFactory to Singleton, so
when the user does x = Singleton(), she gets duped into believing that
she's calling the constructor of Singleton() directly, while she
actually calls the constructor of SingletonWrapper or __call__ of
SingletonFactory

The nice thing is that this prevents the user from constructing
Singleton() directly. However, I think this trickery may be the cause of
some of the confusion that has crept in this thread.

One point to take home from this post though, is that any attempt to
change SingletonWrapper or SingletonFactory themselves into singletons,
will lead rather soon into infinite regress.

Hope this helps,

Roeland
-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From dsh8290@rit.edu  Fri May 18 16:38:42 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 18 May 2001 11:38:42 -0400
Subject: [Tutor] singleton pattern
In-Reply-To: <3B053A5A.8574F6EC@chello.nl>; from r.b.rigilink@chello.nl on Fri, May 18, 2001 at 05:06:02PM +0200
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D793@mbtlipnt02.btlabs.bt.co.uk> <3B053A5A.8574F6EC@chello.nl>
Message-ID: <20010518113842.F6585@harmony.cs.rit.edu>

 
I have just one comment to make regarding this.  (BTW I didn't read
the whole thing,  it's a little too long right now)

On Fri, May 18, 2001 at 05:06:02PM +0200, Roeland Rengelink wrote:
| 
| class SingletonWrapper:
|     singleton = None:
|     def __init__(self):
| 	if SingletonWrapper.singleton is None:
|             SingletonWrapper.singleton = Singleton()
| 
|     def __getattr__(self, attr):
|         return getattr(SingletonWrapper.singleton, attr)
|     def __setattr__(self, attr, value):
| 	setattr(SingletonWrapper.singleton, attr, value)
|         
| SingletonWrapper is not itself a singleton, but of Singleton there will
| be only one instance, so:

Alex Martelli calls this SingletonWrapper a "Flyweight Proxy".  This
pattern was discussed quite a bit on c.l.py about 3 weeks ago (shortly
before my international trip).  The flyweight instances have no state
of their own, but share state across instances (in this case the
single instance of the singleton class).  They also follow the proxy
pattern -- they delegate all of their responsibility to a different
object (in this case the single instance of the singleton class).

This is a cool example of how Python allows the proxy stuff to be
delegated with very little code.  In, say, Java or C++ each
method/function would need to be written out to explicitly delegate to
the method with the same signature in the proxied class.

For those interested in seriously pursuing software development I
highly recommend the book "Design Patterns: Elements of Reusable
Object Oriented Software" by the so-called Gang of Four (Gamma, Helm,
Johnson, Vlissides).  The ISBN number is 0-201-63361-2.  It is a
hard-cover book and costs ~$50.  This book is not for beginners,
however, and all the example code is in C++ or Smalltalk.  The
patterns are really good to know and are not language specific.

-D



From alan.gauld@bt.com  Fri May 18 16:13:31 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 18 May 2001 16:13:31 +0100
Subject: [Tutor] singleton pattern
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D79B@mbtlipnt02.btlabs.bt.co.uk>

> Now, Python (or C++ for that matter) doesn't return 
> a pointer from the constructor. 

Correct thats why my pdseudo code attempt was broken.

> (Not without completely unpythonic namespace hackery)

And we don't wanna go there :-)

> * the SingletonWrapper
> 
> class SingletonWrapper:
>     singleton = None:
>     def __init__(self):
> 	if SingletonWrapper.singleton is None:
>             SingletonWrapper.singleton = Singleton()

Which I think is what Michael was trying to do but 
failing(I think) because instead of assigning 
Singleton() he was assigning a class passed in 
to the constructor... Thus multiple instances of 
different classes would result.

> SingletonWrapper is not itself a singleton, but of Singleton 
> there will be only one instance, so:
> 

Correct.
> * the SingletonFactory
> 
> class SingletonFactory:
>     singleton = None
>     def __call__(self):
>         if SingletonFactory.singleton is None:
>             SingletonFactory.singleton = Singleton()
>         return SingletonFactory.singleton

And this is what I was doing in my second post except 
that I was allowing multiple Factories to be created 
each one managing a singleton instance of the class 
specified in the ctor. But I then moved the actual 
construction of the singleton into the makeInstance 
method and used an exception to pass back the actual 
singleton instance rather than fake access thru' 
the Factory class.

> >>> SF = SingletonFactory()
> >>> x = SF()
> >>> y = SF()
> >>> id(x) == id(y)
> 1

I guess my question is whether it wouyld be easier to
assign the instance attribute directly to x,y:

>>> x = SF().instance
>>> y = SF().instance

And also what happens using this model if we create more than one
SignletonFactory instance:

SF = SingletonFactorty()
MF = SingletonFactorty()
x = MF()
y = SF()

are x and y now pointing at the same object?

[ Boy, I hope I get my own PC back soon, being without 
  a python install at work is killing me! :-) ]

> change SingletonWrapper or SingletonFactory themselves into 
> singletons, will lead rather soon into infinite regress.

Correct, you need a factory somewhere, whether it be a 
callable class or a specific factory is the decision.

Alan g.


From arcege@speakeasy.net  Fri May 18 17:14:11 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Fri, 18 May 2001 12:14:11 -0400 (EDT)
Subject: [Tutor] singleton pattern
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D793@mbtlipnt02.btlabs.bt.co.uk> from "alan.gauld@bt.com" at May 18, 2001 11:43:38 AM
Message-ID: <200105181614.f4IGECj16127@dsl092-074-184.bos1.dsl.speakeasy.net>

alan.gauld@bt.com wrote
> 
> Acerge wrote:
> > class SingletonInstance:
> >   instance = None  # class member for the singleton instance
> >   def __init__(self, klass):
> >     if self.__class__.instance is None:
> 
> OK, I've now read the docs and had a play.
> 
> This is solving a slightly different problem, I think.
> The self.__class__.instance is only a convoluted way of writing
> SingletonInstance.instance - I think the latter is clearer.

Except that self.__class__.instance works with subclasses of
SingletonInstance but SingletonInstance.instance does not.  The class I
gave was geared more to subclasses for the individual singleton classes
(which addressed your different class issue below).  But since I had
already specified that there had been lengthy discussions in more
appropriate forums, I wasn't going to go further.

> >       self.__class__.instance = klass() # make the instance
> 
> This is setting the instance attribute of the SingletonInstance
> class to an instance of the manufactured class. I'm not sure how 
> this gives us a singleton structure? It will ensure that 
> calls to SingletonInstance produce a new instance of klass
> and assign it to the class variable, but for a singleton we 
> want to ensure that calls to the constructor return a pointer 
> to *the same* instance.

Pointing to the same instance is not a necessary condition for the
the problem of a singleton class.  It might be how you think it should
work, but nothing in the functionality defined even hints to "Class()
is Class()" as a tautology.

The above does not "ensure that calls to SingletonInstance produce a new
instance of klass".  It ensures that SingletonInstance instances will
always reference ONE instance (created by SingletonInstance) of klass.

With:
>>> aspam = SingletonInstance(Spam)
>>> bspam = SingletonInstance(Spam)
>>> aspam.__class__.instance is bspam.__class__.instance
1
>>> 

I assert that for any two instances of a call to the SingletonInstance
class, the 'instance' class member will always be the first instance
of the klass given in the first call and that the two instances behave
identically.

The goal, and requirement, of a singleton class is that an instance
from a class _behaves identically_ to any other instance of that class,
not that only one instance can be created.  In Python, there is no
way for a Python class constructor to return anything other than a new
instance.  For that you might want to create the factory and use __call__.
This solution allows for any instance to always access the data in the
first instance created.  Other more involved solutions would be to always
use the class members, never instance members.  The point is that object
identity is not a condition of singleton classes.

> Thus:
> foo = SingletonInstance(MyFileClass)
> 
> and
> 
> bar = SingletonInstance(MySocketClass)
> 
> should make foo and bar reference the same instance (but, 
> in this case,  set the internal instance variable 
> to a new class reference)
[Here, functionally, I would hope that MyFileClass would want a
different singleton instance than MySocketClass since they are different
classes, but it was also mentioned above that here there should be two
subclasses of SingletonInstance to solve that.]

Commonly idioms to this have already been put out, and ppl just need
to look at the multitude of modules in the standard library that
implement them.  Mine was not the answer to the original question and
I didn't attempt to make it such, but more of a method of dealing with
overly-complicated, abortive method at instance creation.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From alan.gauld@bt.com  Fri May 18 17:32:37 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 18 May 2001 17:32:37 +0100
Subject: [Tutor] singleton pattern
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D79C@mbtlipnt02.btlabs.bt.co.uk>

> > Acerge wrote:
> Except that self.__class__.instance works with subclasses of
> SingletonInstance but SingletonInstance.instance does not.  

OK, fair point.
I was making a single factory class that could generate 
singletons of any type but you are making a class which 
can be subclassed, fair enough.

> > >       self.__class__.instance = klass() # make the instance
> ... 
> Pointing to the same instance is not a necessary condition for the
> the problem of a singleton class.  It might be how you think 
> it should work, but nothing in the functionality defined 
> even hints to "Class() is Class()" as a tautology.

Indeed, but surely "instance is instance" is?

> The above does not "ensure that calls to SingletonInstance 
> produce a new instance of klass".  

Yes, looking again I see that in fact if you try to pass 
a different class in subsequent calls it will be ignored. 
(In fact its ignored regardless of what you pass in!)

> >>> aspam = SingletonInstance(Spam)
> >>> bspam = SingletonInstance(Spam)
> >>> aspam.__class__.instance is bspam.__class__.instance
> 1

> the 'instance' class member will always be the first instance
> of the klass given in the first call 

Exactly so, that was the bit I missed first time around.

> and that the two instances behave identically.

Since they delegate everything to the underlying 
singleton instance, correct. This is the tie in 
to Roelands post about the two techniques for 
generating singleton behaviour. I was trying 
to build a generic singleton factory, you are 
building a singleton wrapper. Because the ctors 
looked similar I tried to apply a factory metaphor 
to your wrapper class....
 
> The goal, and requirement, of a singleton class 
> is that an instance from a class _behaves identically_ 
> to any other instance of that class,

Agreed.

> not that only one instance can be created.  

Agreed, one instance is only one way of implementing that 
behaviour.

> Mine was not the answer to the original question and
> I didn't attempt to make it such, 

I think thats what confused me. I assumed it was an attempt 
to answer the original question.

> overly-complicated, abortive method at instance creation.

That'd be my original pseudo-code then :-)

Alan g


From ryanbooz@alumni.psu.edu  Fri May 18 17:55:53 2001
From: ryanbooz@alumni.psu.edu (Ryan Booz)
Date: Fri, 18 May 2001 12:55:53 -0400
Subject: [Tutor] Large scope CGI & DB problem... where to start?
Message-ID: <3B055419.CE333A21@alumni.psu.edu>

Hello all...

I'd like to ask some questions about a CGI program I'm trying to write
(well, just trying to do the planning right now) and see if I can get
some starting points.  I'm still on the low end of the learning curve
with Python (learning and teaching at the same time), but I'm getting
ready to leave this school at the end of the year, and want to leave
some useful web-based management programs here for the guy that is going
to take over.  Of course, it's also giving me a chance to get more
programming experience.  I know that I'm asking a question that probably
has many other better solutions (PHP for instance, maybe ZOPE) but I
figure I'll get a start here and explore the other options as I have
time to learn those tools.

The first program I'm working on is a weekly computer lab schedule that
can be updated to show (ala calendar type table) the periods for the
desired week, what classes are in the lab, and how many computers are
open during each period.  If there is an "open" period (or open
computers) a teacher can schedule that period for their class.

So, getting the table drawn is simple enough with a CGI script.  But,
I really don't have a good sense how to start thinking about storing the
data.  Separate file for each week of school (this seems terribly
inefficient)? One large file with dictionaries or shelving? Would it be
easier to set up a MySQL DB and interface with that (yeah, I'm just
trying to start the DB learning curve also.... ahhhh!).

I know this is a pretty large scope question.  And, depending on how I
store the data, would determine how I retrieve the data for each given
week.  So... I'm new and inexperienced.  Any suggestions, even "you're
going about this all wrong - use _______ instead", would be greatly
appreciated.

Thanks for the advice and help,
Ryan Booz
Tech Coordinator
Belleville Mennonite School



From r.b.rigilink@chello.nl  Fri May 18 18:43:09 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Fri, 18 May 2001 19:43:09 +0200
Subject: [Tutor] singleton pattern
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D79B@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3B055F2D.D1A0A30E@chello.nl>

alan.gauld@bt.com wrote:
> 

[snip]

> > * the SingletonFactory
> >
> > class SingletonFactory:
> >     singleton = None
> >     def __call__(self):
> >         if SingletonFactory.singleton is None:
> >             SingletonFactory.singleton = Singleton()
> >         return SingletonFactory.singleton
> 
> And this is what I was doing in my second post except
> that I was allowing multiple Factories to be created
> each one managing a singleton instance of the class
> specified in the ctor. But I then moved the actual
> construction of the singleton into the makeInstance
> method and used an exception to pass back the actual
> singleton instance rather than fake access thru'
> the Factory class.
> 
> > >>> SF = SingletonFactory()
> > >>> x = SF()
> > >>> y = SF()
> > >>> id(x) == id(y)
> > 1
> 
> I guess my question is whether it wouyld be easier to
> assign the instance attribute directly to x,y:
> 
> >>> x = SF().instance
> >>> y = SF().instance
> 

that's what 

>>> x = SF()
>>> y = SF()

allready do

Remember SF is an instance of SingletonFactory, SF().instance makes no
sense

x = SF()

is equivalent to

x = SF.__call__()

which is equivalent to

x = SF.singleton    # if SF.singleton != None)

or

SF.singleton = Singleton() # if SF.singleton == None
x = SF.singleton

> And also what happens using this model if we create more than one
> SignletonFactory instance:
> 
> SF = SingletonFactorty()
> MF = SingletonFactorty()
> x = MF()
> y = SF()
> 

SF.singleton == MF.singleton

That's why I assigned to SingletonFactory.singleton, rather than
self.singleton

SingletonFactory in this sense behaves like a singleton itself (i.e.
different ids, but identical state)

> are x and y now pointing at the same object?
> 

yes


Have fun,

Roeland

-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From r.b.rigilink@chello.nl  Fri May 18 18:59:14 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Fri, 18 May 2001 19:59:14 +0200
Subject: [Tutor] singleton pattern
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D793@mbtlipnt02.btlabs.bt.co.uk> <3B053A5A.8574F6EC@chello.nl> <20010518113842.F6585@harmony.cs.rit.edu>
Message-ID: <3B0562F2.8D647619@chello.nl>

D-Man wrote:
> 
> For those interested in seriously pursuing software development I
> highly recommend the book "Design Patterns: Elements of Reusable
> Object Oriented Software" by the so-called Gang of Four (Gamma, Helm,
> Johnson, Vlissides).  The ISBN number is 0-201-63361-2.  It is a
> hard-cover book and costs ~$50.  This book is not for beginners,
> however, and all the example code is in C++ or Smalltalk.  The
> patterns are really good to know and are not language specific.
> 

I'd like to second that.

One of the purposes of the book --which makes it interesting even for
those who cannot yet fully grasp the implementation issues addressed--
is to provide a design vocabulary by naming common design idioms.

For example, this thread would have long ago degenerated into complete
gibberish, if this book hadn't defined the term 'singleton', giving us a
single word for 'a class of which there is, at any time, only one
instance.'

Well, maybe it did degenerate into complete gibberish long ago. Just
imagine, it could have even worse.

Roeland
-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From dsh8290@rit.edu  Fri May 18 18:53:10 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 18 May 2001 13:53:10 -0400
Subject: [Tutor] singleton pattern
In-Reply-To: <3B055F2D.D1A0A30E@chello.nl>; from r.b.rigilink@chello.nl on Fri, May 18, 2001 at 07:43:09PM +0200
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D79B@mbtlipnt02.btlabs.bt.co.uk> <3B055F2D.D1A0A30E@chello.nl>
Message-ID: <20010518135310.A7950@harmony.cs.rit.edu>

On Fri, May 18, 2001 at 07:43:09PM +0200, Roeland Rengelink wrote:
| SingletonFactory in this sense behaves like a singleton itself (i.e.
| different ids, but identical state)

Flyweight, not Singleton.  :-).  (There is more than one instance, but
they share state)

-D



From dyoo@hkn.eecs.berkeley.edu  Fri May 18 23:43:42 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Fri, 18 May 2001 15:43:42 -0700 (PDT)
Subject: [Tutor] removing digits from a file
In-Reply-To: <000a01c0df8f$76ac61e0$134d0141@dstn1.fl.home.com>
Message-ID: <Pine.LNX.4.21.0105181535130.5942-100000@hkn.eecs.berkeley.edu>

On Fri, 18 May 2001, sheri wrote:

> i want to do something like this 
>   
> if char (is a digit)
>    delete char

To do this, we can write a small "isDigit()" function that tells us if a
character is a digit.

###
def isDigit(mychar):
    return mychar == '0' or mychar == '1' or mychar == '2' or ...
###

But we can see that this is a really dull way of writing this.  An easier
way to do this is to take advantage of a list structure: doing this will
allow us to say: "Go though each one of these digits, and see if it
matches with mychar."

###
def isDigit(mychar):
    numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    for n in numbers:
        if n == mychar: return 1
    return 0
###

We're being careful to put those numbers in quotes, because we want to
make sure we're making comparisons between two characters.  Python's a
little strict about this:

###
>>> 1 == '1'
0
###

so we need to be aware of the trap of comparing between apples and
oranges.



This version of isDigit() works, but there are small idioms we can use to
make this even nicer.

One idiom is to use the 'in' operation on our list of numbers.  We can say
that if our mychar is 'in' the numbers, we're ok:

###
def isDigit(mychar):
    numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    return mychar in numbers
###


One other cute trick we can use is to express the characters from '0' to
'9' like this:


###
def isDigit(mychar):
    numbers = map(str, range(10))
    return mychar in numbers
###

which means: "Let's allows numbers to stand for the list that contains the
range from 0 through 9.  By the way, we're making all those digits into
strings first."



From tutor@python.org  Sat May 19 00:00:00 2001
From: tutor@python.org (Tim Peters)
Date: Fri, 18 May 2001 19:00:00 -0400
Subject: [Tutor] removing digits from a file
In-Reply-To: <000a01c0df8f$76ac61e0$134d0141@dstn1.fl.home.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCGECKKDAA.tim.one@home.com>

[sheri]
> hello, i am trying to write a script to remove digits from a list of
> spelling words.
> i have a file like this:
> 1. that 2. cat 3. rat 4. etc...
>
> i want to do something like this
>
> if char (is a digit)
>   delete char
>
> so that the output file is like this:
> that cat rat etc...

Hmm.  Since I see you got 4 replies that didn't mention the obvious solution
yet, maybe it's not really that obvious <wink>.

The string module has a translate() function that can both substitute
characters and delete them.  You don't want any substitutions here, so the
code needed to turn substituting off gets in the way a bit:

import string
dont_substitute_anything = string.maketrans("", "")

def sheri(a_string):
    return string.translate(a_string,
                            dont_substitute_anything,
                            "0123456789.") # characters to delete

Then, for example,

>>> sheri("1. that 2. cat 3. rat 4. etc...")
' that  cat  rat  etc'
>>>



From toodles@yifan.net  Sat May 19 03:37:46 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Sat, 19 May 2001 10:37:46 +0800
Subject: [Tutor] wxPython & distribution
Message-ID: <FPEHJJPEEOIPMAHOADBKCEJDCDAA.toodles@yifan.net>

Howdy folks,

I'm trying to make an .exe distribution of a script that uses wxPython. I've
tried using Gordon McMillan's installer scripts. They build everything okay,
but when i execute the file, it does absolutely nothing: it simply exits.
Has anyone had similar troubles, or are you all using Tkinter? :o)

TIA,
Andrew




From toodles@yifan.net  Sat May 19 04:53:17 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Sat, 19 May 2001 11:53:17 +0800
Subject: [Tutor] wxPython & distribution
In-Reply-To: <FPEHJJPEEOIPMAHOADBKCEJDCDAA.toodles@yifan.net>
Message-ID: <FPEHJJPEEOIPMAHOADBKIEJDCDAA.toodles@yifan.net>

Actually it's nothing to do with wxPython...

I made a new file, a.py with one line "print 1", and that did nothing
either. It might be because I'm using python 2.1, I'll check it out later!

Andrew

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Andrew Wilkins
> Sent: Saturday, 19 May 2001 10:38 AM
> To: tutor@python.org
> Subject: [Tutor] wxPython & distribution
>
>
> Howdy folks,
>
> I'm trying to make an .exe distribution of a script that uses
> wxPython. I've
> tried using Gordon McMillan's installer scripts. They build
> everything okay,
> but when i execute the file, it does absolutely nothing: it simply exits.
> Has anyone had similar troubles, or are you all using Tkinter? :o)
>
> TIA,
> Andrew
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From arazak@kansai.com.my  Sat May 19 02:50:50 2001
From: arazak@kansai.com.my (Mr. Razak)
Date: Sat, 19 May 2001 09:50:50 +0800
Subject: [Tutor] Setting Path From Python Shell (IDLE 0.8)
Message-ID: <000001c0e01c$05f93c60$6a01a8c0@com.my>

This is a multi-part message in MIME format.

------=_NextPart_000_000F_01C0E049.2FF69EE0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I want to know, how can i change directory while working inside python =
shell.
Let say i want to save my python program in C:\PY_PRG directory and i =
want to set default to this directory. How to do that.

FYI I'm using window98 flat form.

Thank.

------=_NextPart_000_000F_01C0E049.2FF69EE0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D3>I want to know, how can i change =
directory while=20
working inside python shell.</FONT></DIV>
<DIV><FONT face=3DArial size=3D3>Let say i want to save my python =
program in=20
C:\PY_PRG directory&nbsp;and&nbsp;i want to set default to this =
directory. How=20
to do that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D3>FYI I'm using window98 flat =
form.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D3><FONT=20
size=3D3>Thank</FONT>.</FONT></DIV></BODY></HTML>

------=_NextPart_000_000F_01C0E049.2FF69EE0--



From russianvideo@yahoo.com  Sat May 19 12:53:40 2001
From: russianvideo@yahoo.com (×ÅÐÍÛÉ ÔÐÀÅÐ)
Date: Sat, 19 May 2001 14:53:40 +0300
Subject: [Tutor] Cìîòðèòå íà âèäåî "×ÅÐÍÛÉ ÔÐÀÅÐ"
Message-ID: <082de3256101351SERVER@server>

                                                         Ñìîòðèòå íà âèäåî
                                           ñêàíäàëüíûé  ðîññèéñêèé ôèëüì:

                                                         ×ÅÐÍÛÉ ÔÐÀÅÐ

Ýòî ôèëüì ñíÿòûé   â ñîâåðøåííî íîâîì ñòèëå. Æåñòîêèé áîåâèê ñîåäèíÿåòñÿ ñ óìîðèòåëüíîé êîìåäèåé,
áàíäèòñêèå ðàçáîðêè ñìåíÿþòñÿ ïàðîäèåé íà êóëüòîâûå êàðòèíû: Áðàò, Èãëà,  Àññà.
È ãëàâíîå, çäåñü åñòü Íîâûé Ãåðîé, æåñòîêèé  è ðîìàíòè÷åñêèé.


From kalle@gnupung.net  Sat May 19 14:47:59 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Sat, 19 May 2001 15:47:59 +0200
Subject: [Tutor] Setting Path From Python Shell (IDLE 0.8)
In-Reply-To: <000001c0e01c$05f93c60$6a01a8c0@com.my>; from arazak@kansai.com.my on Sat, May 19, 2001 at 09:50:50AM +0800
References: <000001c0e01c$05f93c60$6a01a8c0@com.my>
Message-ID: <20010519154759.A32443@father>

Sez Mr. Razak:
> I want to know, how can i change directory while working inside python shell.

Use os.chdir() - http://www.python.org/doc/current/lib/os-file-dir.html

> Let say i want to save my python program in C:\PY_PRG directory and i want
> to set default to this directory. How to do that.

I suppose the above could help, but I don't know IDLE very well.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From robnospam@jam.rr.com  Sat May 19 18:42:36 2001
From: robnospam@jam.rr.com (Rob Andrews)
Date: Sat, 19 May 2001 12:42:36 -0500
Subject: [Tutor] Re: Possible Useless Python Challenge.
References: <3AF4DE75.770921E8@irtc.net>
Message-ID: <3B06B08C.E3C70B0E@jam.rr.com>

I finally added the KISS viewer idea to the Useless Python Challenge
page, with a link to the Tutor archive of the first suggestion of it.
Andrew Wilkins has also sent in the first Challenge solution in the form
of a chat application featuring a GUI and modest encryption.

Rob

Tesla Coil wrote:
> 
> Wondering about this as a possible Useless Python
> Challenge.  I'd feel a little guilty suggesting it,
> as I'm uncertain how difficult a task it is, but
> really, Gilbert Roulot is moreso to blame. ;)
> 
> Roulot is the author of the Foks Linux KiSS viewer.
> On the homepage, http://perso.wanadoo.fr/issarlk/Foks/
> Roulot lists among "Features and technical stuff" that
> Foks is "written in the GNU Sather language. The best
> language there is to write KiSS viewers (IMNSHO)!"
> 
> It doesn't appear this has ever been demonstrated
> incorrect by a better KiSS viewer being written
> in Python--for that matter, any KiSS viewer being
> written in Python.
> 
> A KiSS viewer could prove a somewhat larger app than
> would be considered "Useless Python," but it probably
> qualifies in that one would be writing it perhaps more
> to have it done in Python than need for the utility of
> Yet Another program with which to play paperdolls...
> 
> KiSS data sets are bundled using LZH compression,
> if there's a module for that, I haven't located it.
> I suppose that a cel file decoder could be cooked up
> using Python Imaging Library, but I've no experience
> in that department at all.  Other than that, I guess
> one is up against reading .cnf files generated by a
> variety of editors and sometimes written by hand.
> 
> More introduction & file specs can be found at
> http://www2s.biglobe.ne.jp/~yav/kiss/indexe.html

-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From bsass@freenet.edmonton.ab.ca  Sat May 19 19:16:11 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Sat, 19 May 2001 12:16:11 -0600 (MDT)
Subject: [Tutor] Setting Path From Python Shell (IDLE 0.8)
In-Reply-To: <000001c0e01c$05f93c60$6a01a8c0@com.my>
Message-ID: <Pine.LNX.4.33.0105191129320.4946-100000@bms>

On Sat, 19 May 2001, Mr. Razak wrote:

> I want to know, how can i change directory while working inside python shell.
> Let say i want to save my python program in C:\PY_PRG directory and
i want to set default to this directory. How to do that.

The following sequence should help...

Python 2.1 (#4, Apr 25 2001, 03:51:07)
[GCC 2.95.4 20010319 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import os
>>> import sys
>>> sys.executable
'/usr/local/bin/python2.1'
>>> os.path.dirname(sys.executable)
'/usr/local/bin'
>>> os.getcwd()
'/home/bsass'
>>> os.chdir(os.path.dirname(sys.executable))
>>> os.getcwd()
'/home/usr/local/bin'

NOTE: /usr/local is a symlink to /home/usr/local on this box
(just one of the things to keep in mind when playing with paths).

So, you can use ``os.chdir("C:\some\path")'' manually from the "Python
Shell" prompt; or you can have PY_PRG set its own current working
directory based on sys.argv[0] (I used sys.executable because sys.argv
only makes sense while a program is running).


- Bruce



From spotfreerinse@home.com  Sat May 19 23:30:38 2001
From: spotfreerinse@home.com (Colin Day)
Date: Sat, 19 May 2001 17:30:38 -0500
Subject: [Tutor] complete newbie tuple question
Message-ID: <000f01c0e0b3$5462c1e0$a9f1b618@mason1.ia.home.com>

Hello all, I just starting trying to learn to Program and I was reading
Alan's very helpful website when I came across the section on indexing and
tuples:

aTuple = (1,3,5)
>>> print aTuple[1]    # use indexing like a list
3

now this confuses me (like a lot of things so far :) ) because the way it
seems to me is that

    print aTuple[1] would refer to the first charachter in the tuple, in
this case "1", but it doesn't.

could someone help clear this up for me?

thanks

Colin



From spotfreerinse@home.com  Sat May 19 23:36:04 2001
From: spotfreerinse@home.com (Colin Day)
Date: Sat, 19 May 2001 17:36:04 -0500
Subject: [Tutor] complete newbie tuple question
References: <000f01c0e0b3$5462c1e0$a9f1b618@mason1.ia.home.com>
Message-ID: <001c01c0e0b4$16d0ed60$a9f1b618@mason1.ia.home.com>

hmm upon reflection is it perhaps because the numbering in a list or tuple
begins with "0"?



From bdupire@seatech.fau.edu  Sat May 19 23:18:23 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Sat, 19 May 2001 18:18:23 -0400
Subject: [Tutor] complete newbie tuple question
References: <000f01c0e0b3$5462c1e0$a9f1b618@mason1.ia.home.com> <001c01c0e0b4$16d0ed60$a9f1b618@mason1.ia.home.com>
Message-ID: <3B06F12F.94962E93@seatech.fau.edu>


Colin Day wrote:

> hmm upon reflection is it perhaps because the numbering in a list or tuple
> begins with "0"?
>

you are right.

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

--
Benoit Dupire
Graduate Student




From kojo@hal-pc.org  Sun May 20 02:02:19 2001
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Sat, 19 May 2001 20:02:19 -0500
Subject: [Tutor] complete newbie tuple question
In-Reply-To: <3B06F12F.94962E93@seatech.fau.edu>
References: <000f01c0e0b3$5462c1e0$a9f1b618@mason1.ia.home.com>
 <001c01c0e0b4$16d0ed60$a9f1b618@mason1.ia.home.com>
Message-ID: <5.0.2.1.0.20010519200029.00adb7f0@Pop3.norton.antivirus>

Darn!  A question I could have actually answered, and I'm beaten to 
it.  I'll have to do one of two things:  Learn more Python, or spend more 
time monitoring the list...

<...goes to learn more Python...>

At 06:18 PM 5/19/2001 -0400, Benoit wrote:


>Colin Day wrote:
>
> > hmm upon reflection is it perhaps because the numbering in a list or tuple
> > begins with "0"?
> >
>
>you are right.
>
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>--
>Benoit Dupire
>Graduate Student
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

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

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



From toodles@yifan.net  Sun May 20 07:09:37 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Sun, 20 May 2001 14:09:37 +0800
Subject: [Tutor] inspect
Message-ID: <FPEHJJPEEOIPMAHOADBKMEJHCDAA.toodles@yifan.net>

Hi,

I'm making a module to take a class and convert it to an XML representation.
I've been fiddling with the inspect module from Python 2.1, and more
specifically, at the getargspec function, which returns the arguments to be
used with a given function. What I want to know, is whether there is some
way of doing this with a method object.

TIA,
Andrew Wilkins




From toodles@yifan.net  Sun May 20 07:17:44 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Sun, 20 May 2001 14:17:44 +0800
Subject: [Tutor] inspect
In-Reply-To: <FPEHJJPEEOIPMAHOADBKMEJHCDAA.toodles@yifan.net>
Message-ID: <FPEHJJPEEOIPMAHOADBKCEJICDAA.toodles@yifan.net>

Shortly after I posted, I had the idea of looking at inspect.py =)
Sorry folks, I have the answer now...

Andrew

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Andrew Wilkins
> Sent: Sunday, 20 May 2001 2:10 PM
> To: tutor@python.org
> Subject: [Tutor] inspect
>
>
> Hi,
>
> I'm making a module to take a class and convert it to an XML
> representation.
> I've been fiddling with the inspect module from Python 2.1, and more
> specifically, at the getargspec function, which returns the
> arguments to be
> used with a given function. What I want to know, is whether there is some
> way of doing this with a method object.
>
> TIA,
> Andrew Wilkins
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From vns@coconutmail.com  Sun May 20 11:53:08 2001
From: vns@coconutmail.com (vnsampath)
Date: Sun, 20 May 2001 18:53:08 +0800
Subject: [Tutor] help
Message-ID: <200105201853.AA148504906@coconutmail.com>






---------- Original Message ----------------------------------
From: tutor-request@python.org
Reply-to: tutor@python.org
Date: Sat, 19 May 2001 12:01:09 -0400

>Send Tutor mailing list submissions to
>	tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>	http://mail.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. Re: singleton pattern (Michael P. Reilly)
>   2. RE: singleton pattern (alan.gauld@bt.com)
>   3. Large scope CGI & DB problem... where to start? (Ryan Booz)
>   4. Re: singleton pattern (Roeland Rengelink)
>   5. Re: singleton pattern (Roeland Rengelink)
>   6. Re: singleton pattern (D-Man)
>   7. Re: removing digits from a file (Daniel Yoo)
>   8. RE: removing digits from a file (Tim Peters)
>   9. wxPython & distribution (Andrew Wilkins)
>  10. RE: wxPython & distribution (Andrew Wilkins)
>  11. Setting Path From Python Shell (IDLE 0.8) (Mr. Razak)
>  12. C=EC=EE=F2=F0=E8=F2=E5 =ED=E0 =E2=E8=E4=E5=EE "=D7=C5=D0=CD=DB=C9 =
=D4=D0=C0=C5=D0" (=D7=C5=D0=CD=DB=C9 =D4=D0=C0=C5=D0)
>  13. Re: Setting Path From Python Shell (IDLE 0.8) (Kalle Svensson)
>
>--__--__--
>
>Message: 1
>From: "Michael P. Reilly" <arcege@dsl092-074-184.bos1.dsl.speakeasy.net>
>Subject: Re: [Tutor] singleton pattern
>To: alan.gauld@bt.com
>Date: Fri, 18 May 2001 12:14:11 -0400 (EDT)
>Cc: tutor@python.org
>Reply-To: arcege@speakeasy.net
>
>alan.gauld@bt.com wrote
>> 
>> Acerge wrote:
>> > class SingletonInstance:
>> >   instance =3D None  # class member for the singleton instance
>> >   def __init__(self, klass):
>> >     if self.__class__.instance is None:
>> 
>> OK, I've now read the docs and had a play.
>> 
>> This is solving a slightly different problem, I think.
>> The self.__class__.instance is only a convoluted way of writing
>> SingletonInstance.instance - I think the latter is clearer.
>
>Except that self.__class__.instance works with subclasses of
>SingletonInstance but SingletonInstance.instance does not.  The class I
>gave was geared more to subclasses for the individual singleton classes
>(which addressed your different class issue below).  But since I had
>already specified that there had been lengthy discussions in more
>appropriate forums, I wasn't going to go further.
>
>> >       self.__class__.instance =3D klass() # make the instance
>> 
>> This is setting the instance attribute of the SingletonInstance
>> class to an instance of the manufactured class. I'm not sure how 
>> this gives us a singleton structure? It will ensure that 
>> calls to SingletonInstance produce a new instance of klass
>> and assign it to the class variable, but for a singleton we 
>> want to ensure that calls to the constructor return a pointer 
>> to *the same* instance.
>
>Pointing to the same instance is not a necessary condition for the
>the problem of a singleton class.  It might be how you think it should
>work, but nothing in the functionality defined even hints to "Class()
>is Class()" as a tautology.
>
>The above does not "ensure that calls to SingletonInstance produce a new
>instance of klass".  It ensures that SingletonInstance instances will
>always reference ONE instance (created by SingletonInstance) of klass.
>
>With:
>>>> aspam =3D SingletonInstance(Spam)
>>>> bspam =3D SingletonInstance(Spam)
>>>> aspam.__class__.instance is bspam.__class__.instance
>1
>>>> 
>
>I assert that for any two instances of a call to the SingletonInstance
>class, the 'instance' class member will always be the first instance
>of the klass given in the first call and that the two instances behave
>identically.
>
>The goal, and requirement, of a singleton class is that an instance
>from a class _behaves identically_ to any other instance of that class,
>not that only one instance can be created.  In Python, there is no
>way for a Python class constructor to return anything other than a new
>instance.  For that you might want to create the factory and use __call__.=

>This solution allows for any instance to always access the data in the
>first instance created.  Other more involved solutions would be to always
>use the class members, never instance members.  The point is that object
>identity is not a condition of singleton classes.
>
>> Thus:
>> foo =3D SingletonInstance(MyFileClass)
>> 
>> and
>> 
>> bar =3D SingletonInstance(MySocketClass)
>> 
>> should make foo and bar reference the same instance (but, 
>> in this case,  set the internal instance variable 
>> to a new class reference)
>[Here, functionally, I would hope that MyFileClass would want a
>different singleton instance than MySocketClass since they are different
>classes, but it was also mentioned above that here there should be two
>subclasses of SingletonInstance to solve that.]
>
>Commonly idioms to this have already been put out, and ppl just need
>to look at the multitude of modules in the standard library that
>implement them.  Mine was not the answer to the original question and
>I didn't attempt to make it such, but more of a method of dealing with
>overly-complicated, abortive method at instance creation.
>
>  -Arcege
>
>-- 
>+----------------------------------+-----------------------------------+
>| Michael P. Reilly                | arcege@speakeasy.net              |
>
>
>--__--__--
>
>Message: 2
>From: alan.gauld@bt.com
>To: arcege@speakeasy.net, alan.gauld@bt.com
>Cc: tutor@python.org
>Subject: RE: [Tutor] singleton pattern
>Date: Fri, 18 May 2001 17:32:37 +0100
>
>> > Acerge wrote:
>> Except that self.__class__.instance works with subclasses of
>> SingletonInstance but SingletonInstance.instance does not.  
>
>OK, fair point.
>I was making a single factory class that could generate 
>singletons of any type but you are making a class which 
>can be subclassed, fair enough.
>
>> > >       self.__class__.instance =3D klass() # make the instance
>> ... 
>> Pointing to the same instance is not a necessary condition for the
>> the problem of a singleton class.  It might be how you think 
>> it should work, but nothing in the functionality defined 
>> even hints to "Class() is Class()" as a tautology.
>
>Indeed, but surely "instance is instance" is?
>
>> The above does not "ensure that calls to SingletonInstance 
>> produce a new instance of klass".  
>
>Yes, looking again I see that in fact if you try to pass 
>a different class in subsequent calls it will be ignored. 
>(In fact its ignored regardless of what you pass in!)
>
>> >>> aspam =3D SingletonInstance(Spam)
>> >>> bspam =3D SingletonInstance(Spam)
>> >>> aspam.__class__.instance is bspam.__class__.instance
>> 1
>
>> the 'instance' class member will always be the first instance
>> of the klass given in the first call 
>
>Exactly so, that was the bit I missed first time around.
>
>> and that the two instances behave identically.
>
>Since they delegate everything to the underlying 
>singleton instance, correct. This is the tie in 
>to Roelands post about the two techniques for 
>generating singleton behaviour. I was trying 
>to build a generic singleton factory, you are 
>building a singleton wrapper. Because the ctors 
>looked similar I tried to apply a factory metaphor 
>to your wrapper class....
> 
>> The goal, and requirement, of a singleton class 
>> is that an instance from a class _behaves identically_ 
>> to any other instance of that class,
>
>Agreed.
>
>> not that only one instance can be created.  
>
>Agreed, one instance is only one way of implementing that 
>behaviour.
>
>> Mine was not the answer to the original question and
>> I didn't attempt to make it such, 
>
>I think thats what confused me. I assumed it was an attempt 
>to answer the original question.
>
>> overly-complicated, abortive method at instance creation.
>
>That'd be my original pseudo-code then :-)
>
>Alan g
>
>
>--__--__--
>
>Message: 3
>Date: Fri, 18 May 2001 12:55:53 -0400
>From: Ryan Booz <ryanbooz@alumni.psu.edu>
>To: tutor@python.org
>Subject: [Tutor] Large scope CGI & DB problem... where to start?
>
>Hello all...
>
>I'd like to ask some questions about a CGI program I'm trying to write
>(well, just trying to do the planning right now) and see if I can get
>some starting points.  I'm still on the low end of the learning curve
>with Python (learning and teaching at the same time), but I'm getting
>ready to leave this school at the end of the year, and want to leave
>some useful web-based management programs here for the guy that is going
>to take over.  Of course, it's also giving me a chance to get more
>programming experience.  I know that I'm asking a question that probably
>has many other better solutions (PHP for instance, maybe ZOPE) but I
>figure I'll get a start here and explore the other options as I have
>time to learn those tools.
>
>The first program I'm working on is a weekly computer lab schedule that
>can be updated to show (ala calendar type table) the periods for the
>desired week, what classes are in the lab, and how many computers are
>open during each period.  If there is an "open" period (or open
>computers) a teacher can schedule that period for their class.
>
>So, getting the table drawn is simple enough with a CGI script.  But,
>I really don't have a good sense how to start thinking about storing the
>data.  Separate file for each week of school (this seems terribly
>inefficient)? One large file with dictionaries or shelving? Would it be
>easier to set up a MySQL DB and interface with that (yeah, I'm just
>trying to start the DB learning curve also.... ahhhh!).
>
>I know this is a pretty large scope question.  And, depending on how I
>store the data, would determine how I retrieve the data for each given
>week.  So... I'm new and inexperienced.  Any suggestions, even "you're
>going about this all wrong - use _______ instead", would be greatly
>appreciated.
>
>Thanks for the advice and help,
>Ryan Booz
>Tech Coordinator
>Belleville Mennonite School
>
>
>
>--__--__--
>
>Message: 4
>Date: Fri, 18 May 2001 19:43:09 +0200
>From: Roeland Rengelink <r.b.rigilink@chello.nl>
>To: tutor@python.org
>Subject: Re: [Tutor] singleton pattern
>
>alan.gauld@bt.com wrote:
>> 
>
>[snip]
>
>> > * the SingletonFactory
>> >
>> > class SingletonFactory:
>> >     singleton =3D None
>> >     def __call__(self):
>> >         if SingletonFactory.singleton is None:
>> >             SingletonFactory.singleton =3D Singleton()
>> >         return SingletonFactory.singleton
>> 
>> And this is what I was doing in my second post except
>> that I was allowing multiple Factories to be created
>> each one managing a singleton instance of the class
>> specified in the ctor. But I then moved the actual
>> construction of the singleton into the makeInstance
>> method and used an exception to pass back the actual
>> singleton instance rather than fake access thru'
>> the Factory class.
>> 
>> > >>> SF =3D SingletonFactory()
>> > >>> x =3D SF()
>> > >>> y =3D SF()
>> > >>> id(x) =3D=3D id(y)
>> > 1
>> 
>> I guess my question is whether it wouyld be easier to
>> assign the instance attribute directly to x,y:
>> 
>> >>> x =3D SF().instance
>> >>> y =3D SF().instance
>> 
>
>that's what 
>
>>>> x =3D SF()
>>>> y =3D SF()
>
>allready do
>
>Remember SF is an instance of SingletonFactory, SF().instance makes no
>sense
>
>x =3D SF()
>
>is equivalent to
>
>x =3D SF.__call__()
>
>which is equivalent to
>
>x =3D SF.singleton    # if SF.singleton !=3D None)
>
>or
>
>SF.singleton =3D Singleton() # if SF.singleton =3D=3D None
>x =3D SF.singleton
>
>> And also what happens using this model if we create more than one
>> SignletonFactory instance:
>> 
>> SF =3D SingletonFactorty()
>> MF =3D SingletonFactorty()
>> x =3D MF()
>> y =3D SF()
>> 
>
>SF.singleton =3D=3D MF.singleton
>
>That's why I assigned to SingletonFactory.singleton, rather than
>self.singleton
>
>SingletonFactory in this sense behaves like a singleton itself (i.e.
>different ids, but identical state)
>
>> are x and y now pointing at the same object?
>> 
>
>yes
>
>
>Have fun,
>
>Roeland
>
>-- 
>r.b.rigilink@chello.nl
>
>"Half of what I say is nonsense. Unfortunately I don't know which half"
>
>
>--__--__--
>
>Message: 5
>Date: Fri, 18 May 2001 19:59:14 +0200
>From: Roeland Rengelink <r.b.rigilink@chello.nl>
>To: tutor@python.org
>Subject: Re: [Tutor] singleton pattern
>
>D-Man wrote:
>> 
>> For those interested in seriously pursuing software development I
>> highly recommend the book "Design Patterns: Elements of Reusable
>> Object Oriented Software" by the so-called Gang of Four (Gamma, Helm,
>> Johnson, Vlissides).  The ISBN number is 0-201-63361-2.  It is a
>> hard-cover book and costs ~$50.  This book is not for beginners,
>> however, and all the example code is in C++ or Smalltalk.  The
>> patterns are really good to know and are not language specific.
>> 
>
>I'd like to second that.
>
>One of the purposes of the book --which makes it interesting even for
>those who cannot yet fully grasp the implementation issues addressed--
>is to provide a design vocabulary by naming common design idioms.
>
>For example, this thread would have long ago degenerated into complete
>gibberish, if this book hadn't defined the term 'singleton', giving us a
>single word for 'a class of which there is, at any time, only one
>instance.'
>
>Well, maybe it did degenerate into complete gibberish long ago. Just
>imagine, it could have even worse.
>
>Roeland
>-- 
>r.b.rigilink@chello.nl
>
>"Half of what I say is nonsense. Unfortunately I don't know which half"
>
>
>--__--__--
>
>Message: 6
>Date: Fri, 18 May 2001 13:53:10 -0400
>From: D-Man <dsh8290@rit.edu>
>To: tutor@python.org
>Subject: Re: [Tutor] singleton pattern
>
>On Fri, May 18, 2001 at 07:43:09PM +0200, Roeland Rengelink wrote:
>| SingletonFactory in this sense behaves like a singleton itself (i.e.
>| different ids, but identical state)
>
>Flyweight, not Singleton.  :-).  (There is more than one instance, but
>they share state)
>
>-D
>
>
>
>--__--__--
>
>Message: 7
>Date: Fri, 18 May 2001 15:43:42 -0700 (PDT)
>From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: sheri <din22@home.com>
>cc: tutor@python.org
>Subject: Re: [Tutor] removing digits from a file
>
>On Fri, 18 May 2001, sheri wrote:
>
>> i want to do something like this 
>>   
>> if char (is a digit)
>>    delete char
>
>To do this, we can write a small "isDigit()" function that tells us if a
>character is a digit.
>
>###
>def isDigit(mychar):
>    return mychar =3D=3D '0' or mychar =3D=3D '1' or mychar =3D=3D '2' or =
...
>###
>
>But we can see that this is a really dull way of writing this.  An easier
>way to do this is to take advantage of a list structure: doing this will
>allow us to say: "Go though each one of these digits, and see if it
>matches with mychar."
>
>###
>def isDigit(mychar):
>    numbers =3D ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>    for n in numbers:
>        if n =3D=3D mychar: return 1
>    return 0
>###
>
>We're being careful to put those numbers in quotes, because we want to
>make sure we're making comparisons between two characters.  Python's a
>little strict about this:
>
>###
>>>> 1 =3D=3D '1'
>0
>###
>
>so we need to be aware of the trap of comparing between apples and
>oranges.
>
>
>
>This version of isDigit() works, but there are small idioms we can use to
>make this even nicer.
>
>One idiom is to use the 'in' operation on our list of numbers.  We can say=

>that if our mychar is 'in' the numbers, we're ok:
>
>###
>def isDigit(mychar):
>    numbers =3D ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>    return mychar in numbers
>###
>
>
>One other cute trick we can use is to express the characters from '0' to
>'9' like this:
>
>
>###
>def isDigit(mychar):
>    numbers =3D map(str, range(10))
>    return mychar in numbers
>###
>
>which means: "Let's allows numbers to stand for the list that contains the=

>range from 0 through 9.  By the way, we're making all those digits into
>strings first."
>
>
>
>--__--__--
>
>Message: 8
>Reply-To: <tutor@python.org>
>From: "Tim Peters" <tim.one@home.com>
>To: "sheri" <din22@home.com>
>Cc: <tutor@python.org>
>Subject: RE: [Tutor] removing digits from a file
>Date: Fri, 18 May 2001 19:00:00 -0400
>
>[sheri]
>> hello, i am trying to write a script to remove digits from a list of
>> spelling words.
>> i have a file like this:
>> 1. that 2. cat 3. rat 4. etc...
>>
>> i want to do something like this
>>
>> if char (is a digit)
>>   delete char
>>
>> so that the output file is like this:
>> that cat rat etc...
>
>Hmm.  Since I see you got 4 replies that didn't mention the obvious soluti=
on
>yet, maybe it's not really that obvious <wink>.
>
>The string module has a translate() function that can both substitute
>characters and delete them.  You don't want any substitutions here, so the=

>code needed to turn substituting off gets in the way a bit:
>
>import string
>dont_substitute_anything =3D string.maketrans("", "")
>
>def sheri(a_string):
>    return string.translate(a_string,
>                            dont_substitute_anything,
>                            "0123456789.") # characters to delete
>
>Then, for example,
>
>>>> sheri("1. that 2. cat 3. rat 4. etc...")
>' that  cat  rat  etc'
>>>>
>
>
>
>--__--__--
>
>Message: 9
>From: "Andrew Wilkins" <toodles@yifan.net>
>To: <tutor@python.org>
>Date: Sat, 19 May 2001 10:37:46 +0800
>Subject: [Tutor] wxPython & distribution
>
>Howdy folks,
>
>I'm trying to make an .exe distribution of a script that uses wxPython. I'=
ve
>tried using Gordon McMillan's installer scripts. They build everything oka=
y,
>but when i execute the file, it does absolutely nothing: it simply exits.
>Has anyone had similar troubles, or are you all using Tkinter? :o)
>
>TIA,
>Andrew
>
>
>
>
>--__--__--
>
>Message: 10
>From: "Andrew Wilkins" <toodles@yifan.net>
>To: <tutor@python.org>
>Subject: RE: [Tutor] wxPython & distribution
>Date: Sat, 19 May 2001 11:53:17 +0800
>
>Actually it's nothing to do with wxPython...
>
>I made a new file, a.py with one line "print 1", and that did nothing
>either. It might be because I'm using python 2.1, I'll check it out later!=

>
>Andrew
>
>> -----Original Message-----
>> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of=

>> Andrew Wilkins
>> Sent: Saturday, 19 May 2001 10:38 AM
>> To: tutor@python.org
>> Subject: [Tutor] wxPython & distribution
>>
>>
>> Howdy folks,
>>
>> I'm trying to make an .exe distribution of a script that uses
>> wxPython. I've
>> tried using Gordon McMillan's installer scripts. They build
>> everything okay,
>> but when i execute the file, it does absolutely nothing: it simply exits=
.
>> Has anyone had similar troubles, or are you all using Tkinter? :o)
>>
>> TIA,
>> Andrew
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
>
>--__--__--
>
>Message: 11
>From: "Mr. Razak" <arazak@kansai.com.my>
>To: <tutor@python.org>
>Date: Sat, 19 May 2001 09:50:50 +0800
>Subject: [Tutor] Setting Path From Python Shell (IDLE 0.8)
>
>This is a multi-part message in MIME format.
>
>------=3D_NextPart_000_000F_01C0E049.2FF69EE0
>Content-Type: text/plain;
>	charset=3D"iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
>I want to know, how can i change directory while working inside python =
=3D
>shell.
>Let say i want to save my python program in C:\PY_PRG directory and i =3D
>want to set default to this directory. How to do that.
>
>FYI I'm using window98 flat form.
>
>Thank.
>
>------=3D_NextPart_000_000F_01C0E049.2FF69EE0
>Content-Type: text/html;
>	charset=3D"iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
><HTML><HEAD>
><META content=3D3D"text/html; charset=3D3Diso-8859-1" =3D
>http-equiv=3D3DContent-Type>
><META content=3D3D"MSHTML 5.00.2614.3500" name=3D3DGENERATOR>
><STYLE></STYLE>
></HEAD>
><BODY bgColor=3D3D#ffffff>
><DIV><FONT face=3D3DArial size=3D3D3>I want to know, how can i change =3D
>directory while=3D20
>working inside python shell.</FONT></DIV>
><DIV><FONT face=3D3DArial size=3D3D3>Let say i want to save my python =3D
>program in=3D20
>C:\PY_PRG directory=A0and=A0i want to set default to this =3D
>directory. How=3D20
>to do that.</FONT></DIV>
><DIV>=A0</DIV>
><DIV><FONT face=3D3DArial size=3D3D3>FYI I'm using window98 flat =3D
>form.</FONT></DIV>
><DIV>=A0</DIV>
><DIV><FONT face=3D3DArial size=3D3D3><FONT=3D20
>size=3D3D3>Thank</FONT>.</FONT></DIV></BODY></HTML>
>
>------=3D_NextPart_000_000F_01C0E049.2FF69EE0--
>
>
>
>--__--__--
>
>Message: 12
>From: =D7=C5=D0=CD=DB=C9 =D4=D0=C0=C5=D0<russianvideo@yahoo.com>
>To: tutor@python.org
>Reply-To: russianvideo@yahoo.com
>Date: Sat, 19 May 2001 14:53:40 +0300
>Subject: [Tutor] C=EC=EE=F2=F0=E8=F2=E5 =ED=E0 =E2=E8=E4=E5=EE "=D7=C5=D0=
=CD=DB=C9 =D4=D0=C0=C5=D0"
>
>
>                                                         =D1=EC=EE=F2=F0=
=E8=F2=E5 =ED=E0 =E2=E8=E4=E5=EE
>                                           =F1=EA=E0=ED=E4=E0=EB=FC=ED=FB=
=E9  =F0=EE=F1=F1=E8=E9=F1=EA=E8=E9 =F4=E8=EB=FC=EC:
>
>                                                         =D7=C5=D0=CD=DB=
=C9 =D4=D0=C0=C5=D0
>
>=DD=F2=EE =F4=E8=EB=FC=EC =F1=ED=FF=F2=FB=E9   =E2 =F1=EE=E2=E5=F0=F8=E5=
=ED=ED=EE =ED=EE=E2=EE=EC =F1=F2=E8=EB=E5. =C6=E5=F1=F2=EE=EA=E8=E9 =E1=EE=
=E5=E2=E8=EA =F1=EE=E5=E4=E8=ED=FF=E5=F2=F1=FF =F1 =F3=EC=EE=F0=E8=F2=E5=
=EB=FC=ED=EE=E9 =EA=EE=EC=E5=E4=E8=E5=E9,
>=E1=E0=ED=E4=E8=F2=F1=EA=E8=E5 =F0=E0=E7=E1=EE=F0=EA=E8 =F1=EC=E5=ED=FF=
=FE=F2=F1=FF =EF=E0=F0=EE=E4=E8=E5=E9 =ED=E0 =EA=F3=EB=FC=F2=EE=E2=FB=E5 =
=EA=E0=F0=F2=E8=ED=FB: =C1=F0=E0=F2, =C8=E3=EB=E0,  =C0=F1=F1=E0.
>=C8 =E3=EB=E0=E2=ED=EE=E5, =E7=E4=E5=F1=FC =E5=F1=F2=FC =CD=EE=E2=FB=E9 =
=C3=E5=F0=EE=E9, =E6=E5=F1=F2=EE=EA=E8=E9  =E8 =F0=EE=EC=E0=ED=F2=E8=F7=E5=
=F1=EA=E8=E9.
>
>
>--__--__--
>
>Message: 13
>Date: Sat, 19 May 2001 15:47:59 +0200
>From: Kalle Svensson <kalle@gnupung.net>
>To: tutor@python.org
>Subject: Re: [Tutor] Setting Path From Python Shell (IDLE 0.8)
>
>Sez Mr. Razak:
>> I want to know, how can i change directory while working inside python s=
hell.
>
>Use os.chdir() - http://www.python.org/doc/current/lib/os-file-dir.html
>
>> Let say i want to save my python program in C:\PY_PRG directory and i wa=
nt
>> to set default to this directory. How to do that.
>
>I suppose the above could help, but I don't know IDLE very well.
>
>Peace,
>  Kalle
>-- 
>Email: kalle@gnupung.net     | You can tune a filesystem, but you
>Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
>PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
> [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
>
>
>
>--__--__--
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>End of Tutor Digest
>


_________________________________________________________
FREE Corporate Web-hosting, 20MB space, 30 Email accounts
Get Your Own Domain at http://www.iRepublics.com


From vns@coconutmail.com  Sun May 20 12:01:15 2001
From: vns@coconutmail.com (vnsampath)
Date: Sun, 20 May 2001 19:01:15 +0800
Subject: [Tutor] help
Message-ID: <200105201901.AA521863482@coconutmail.com>





---------- Original Message ----------------------------------
From: tutor-request@python.org
Reply-to: tutor@python.org
Date: Sun, 20 May 2001 06:56:02 -0400

>Send Tutor mailing list submissions to
>	tutor@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>	http://mail.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. Re: Possible Useless Python Challenge. (Rob Andrews)
>   2. Re: Setting Path From Python Shell (IDLE 0.8) (Bruce Sass)
>   3. complete newbie tuple question (Colin Day)
>   4. Re: complete newbie tuple question (Colin Day)
>   5. Re: complete newbie tuple question (Benoit Dupire)
>   6. Re: complete newbie tuple question (Kojo Idrissa)
>   7. inspect (Andrew Wilkins)
>   8. RE: inspect (Andrew Wilkins)
>   9. help (vnsampath)
>
>--__--__--
>
>Message: 1
>Date: Sat, 19 May 2001 12:42:36 -0500
>From: Rob Andrews <robnospam@jam.rr.com>
>Organization: Useless Python
>To: Tesla Coil <tescoil@irtc.net>
>CC: tescoil@irtc.net, tutor@python.org
>Subject: [Tutor] Re: Possible Useless Python Challenge.
>
>I finally added the KISS viewer idea to the Useless Python Challenge
>page, with a link to the Tutor archive of the first suggestion of it.
>Andrew Wilkins has also sent in the first Challenge solution in the form
>of a chat application featuring a GUI and modest encryption.
>
>Rob
>
>Tesla Coil wrote:
>> 
>> Wondering about this as a possible Useless Python
>> Challenge.  I'd feel a little guilty suggesting it,
>> as I'm uncertain how difficult a task it is, but
>> really, Gilbert Roulot is moreso to blame. ;)
>> 
>> Roulot is the author of the Foks Linux KiSS viewer.
>> On the homepage, http://perso.wanadoo.fr/issarlk/Foks/
>> Roulot lists among "Features and technical stuff" that
>> Foks is "written in the GNU Sather language. The best
>> language there is to write KiSS viewers (IMNSHO)!"
>> 
>> It doesn't appear this has ever been demonstrated
>> incorrect by a better KiSS viewer being written
>> in Python--for that matter, any KiSS viewer being
>> written in Python.
>> 
>> A KiSS viewer could prove a somewhat larger app than
>> would be considered "Useless Python," but it probably
>> qualifies in that one would be writing it perhaps more
>> to have it done in Python than need for the utility of
>> Yet Another program with which to play paperdolls...
>> 
>> KiSS data sets are bundled using LZH compression,
>> if there's a module for that, I haven't located it.
>> I suppose that a cel file decoder could be cooked up
>> using Python Imaging Library, but I've no experience
>> in that department at all.  Other than that, I guess
>> one is up against reading .cnf files generated by a
>> variety of editors and sometimes written by hand.
>> 
>> More introduction & file specs can be found at
>> http://www2s.biglobe.ne.jp/~yav/kiss/indexe.html
>
>-- 
>
>You should have listened when your mother warned you about
>Useless Python!
>http://www.lowerstandard.com/python/pythonsource.html
>
>
>--__--__--
>
>Message: 2
>Date: Sat, 19 May 2001 12:16:11 -0600 (MDT)
>From: Bruce Sass <bsass@freenet.edmonton.ab.ca>
>To: "Mr. Razak" <arazak@kansai.com.my>
>cc: <tutor@python.org>
>Subject: Re: [Tutor] Setting Path From Python Shell (IDLE 0.8)
>
>On Sat, 19 May 2001, Mr. Razak wrote:
>
>> I want to know, how can i change directory while working inside python shell.
>> Let say i want to save my python program in C:\PY_PRG directory and
>i want to set default to this directory. How to do that.
>
>The following sequence should help...
>
>Python 2.1 (#4, Apr 25 2001, 03:51:07)
>[GCC 2.95.4 20010319 (Debian prerelease)] on linux2
>Type "copyright", "credits" or "license" for more information.
>IDLE 0.8 -- press F1 for help
>>>> import os
>>>> import sys
>>>> sys.executable
>'/usr/local/bin/python2.1'
>>>> os.path.dirname(sys.executable)
>'/usr/local/bin'
>>>> os.getcwd()
>'/home/bsass'
>>>> os.chdir(os.path.dirname(sys.executable))
>>>> os.getcwd()
>'/home/usr/local/bin'
>
>NOTE: /usr/local is a symlink to /home/usr/local on this box
>(just one of the things to keep in mind when playing with paths).
>
>So, you can use ``os.chdir("C:\some\path")'' manually from the "Python
>Shell" prompt; or you can have PY_PRG set its own current working
>directory based on sys.argv[0] (I used sys.executable because sys.argv
>only makes sense while a program is running).
>
>
>- Bruce
>
>
>
>--__--__--
>
>Message: 3
>From: "Colin Day" <spotfreerinse@home.com>
>To: <tutor@python.org>
>Date: Sat, 19 May 2001 17:30:38 -0500
>Subject: [Tutor] complete newbie tuple question
>
>Hello all, I just starting trying to learn to Program and I was reading
>Alan's very helpful website when I came across the section on indexing and
>tuples:
>
>aTuple = (1,3,5)
>>>> print aTuple[1]    # use indexing like a list
>3
>
>now this confuses me (like a lot of things so far :) ) because the way it
>seems to me is that
>
>    print aTuple[1] would refer to the first charachter in the tuple, in
>this case "1", but it doesn't.
>
>could someone help clear this up for me?
>
>thanks
>
>Colin
>
>
>
>--__--__--
>
>Message: 4
>From: "Colin Day" <spotfreerinse@home.com>
>To: <tutor@python.org>
>Subject: Re: [Tutor] complete newbie tuple question
>Date: Sat, 19 May 2001 17:36:04 -0500
>
>hmm upon reflection is it perhaps because the numbering in a list or tuple
>begins with "0"?
>
>
>
>--__--__--
>
>Message: 5
>Date: Sat, 19 May 2001 18:18:23 -0400
>From: Benoit Dupire <bdupire@seatech.fau.edu>
>Organization: Florida Atlantic University
>To: Colin Day <spotfreerinse@home.com>
>CC: tutor@python.org
>Subject: Re: [Tutor] complete newbie tuple question
>
>
>
>Colin Day wrote:
>
>> hmm upon reflection is it perhaps because the numbering in a list or tuple
>> begins with "0"?
>>
>
>you are right.
>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>--
>Benoit Dupire
>Graduate Student
>
>
>
>
>--__--__--
>
>Message: 6
>Date: Sat, 19 May 2001 20:02:19 -0500
>To: tutor@python.org
>From: Kojo Idrissa <kojo@hal-pc.org>
>Subject: Re: [Tutor] complete newbie tuple question
>
>Darn!  A question I could have actually answered, and I'm beaten to 
>it.  I'll have to do one of two things:  Learn more Python, or spend more 
>time monitoring the list...
>
><...goes to learn more Python...>
>
>At 06:18 PM 5/19/2001 -0400, Benoit wrote:
>
>
>>Colin Day wrote:
>>
>> > hmm upon reflection is it perhaps because the numbering in a list or tuple
>> > begins with "0"?
>> >
>>
>>you are right.
>>
>> >
>> > _______________________________________________
>> > Tutor maillist  -  Tutor@python.org
>> > http://mail.python.org/mailman/listinfo/tutor
>>
>>--
>>Benoit Dupire
>>Graduate Student
>>
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>
>****************************
>Kojo Idrissa
>
>kojo@hal-pc.org
>http://www.hal-pc.org/~kojo/
>****************************
>
>
>
>--__--__--
>
>Message: 7
>From: "Andrew Wilkins" <toodles@yifan.net>
>To: <tutor@python.org>
>Date: Sun, 20 May 2001 14:09:37 +0800
>Subject: [Tutor] inspect
>
>Hi,
>
>I'm making a module to take a class and convert it to an XML representation.
>I've been fiddling with the inspect module from Python 2.1, and more
>specifically, at the getargspec function, which returns the arguments to be
>used with a given function. What I want to know, is whether there is some
>way of doing this with a method object.
>
>TIA,
>Andrew Wilkins
>
>
>
>
>--__--__--
>
>Message: 8
>From: "Andrew Wilkins" <toodles@yifan.net>
>To: <tutor@python.org>
>Subject: RE: [Tutor] inspect
>Date: Sun, 20 May 2001 14:17:44 +0800
>
>Shortly after I posted, I had the idea of looking at inspect.py =)
>Sorry folks, I have the answer now...
>
>Andrew
>
>> -----Original Message-----
>> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
>> Andrew Wilkins
>> Sent: Sunday, 20 May 2001 2:10 PM
>> To: tutor@python.org
>> Subject: [Tutor] inspect
>>
>>
>> Hi,
>>
>> I'm making a module to take a class and convert it to an XML
>> representation.
>> I've been fiddling with the inspect module from Python 2.1, and more
>> specifically, at the getargspec function, which returns the
>> arguments to be
>> used with a given function. What I want to know, is whether there is some
>> way of doing this with a method object.
>>
>> TIA,
>> Andrew Wilkins
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
>
>--__--__--
>
>Message: 9
>Date: Sun, 20 May 2001 18:53:08 +0800
>From: "vnsampath" <vns@coconutmail.com>
>Reply-To: <vns@coconutmail.com>
>To: <tutor@python.org>
>Subject: [Tutor] help
>
>
>
>
>
>
>
>---------- Original Message ----------------------------------
>From: tutor-request@python.org
>Reply-to: tutor@python.org
>Date: Sat, 19 May 2001 12:01:09 -0400
>
>>Send Tutor mailing list submissions to
>>	tutor@python.org
>>
>>To subscribe or unsubscribe via the World Wide Web, visit
>>	http://mail.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. Re: singleton pattern (Michael P. Reilly)
>>   2. RE: singleton pattern (alan.gauld@bt.com)
>>   3. Large scope CGI & DB problem... where to start? (Ryan Booz)
>>   4. Re: singleton pattern (Roeland Rengelink)
>>   5. Re: singleton pattern (Roeland Rengelink)
>>   6. Re: singleton pattern (D-Man)
>>   7. Re: removing digits from a file (Daniel Yoo)
>>   8. RE: removing digits from a file (Tim Peters)
>>   9. wxPython & distribution (Andrew Wilkins)
>>  10. RE: wxPython & distribution (Andrew Wilkins)
>>  11. Setting Path From Python Shell (IDLE 0.8) (Mr. Razak)
>>  12. C=EC=EE=F2=F0=E8=F2=E5 =ED=E0 =E2=E8=E4=E5=EE "=D7=C5=D0=CD=DB=C9 =
>=D4=D0=C0=C5=D0" (=D7=C5=D0=CD=DB=C9 =D4=D0=C0=C5=D0)
>>  13. Re: Setting Path From Python Shell (IDLE 0.8) (Kalle Svensson)
>>
>>-- __--__-- 
>>
>>Message: 1
>>From: "Michael P. Reilly" <arcege@dsl092-074-184.bos1.dsl.speakeasy.net>
>>Subject: Re: [Tutor] singleton pattern
>>To: alan.gauld@bt.com
>>Date: Fri, 18 May 2001 12:14:11 -0400 (EDT)
>>Cc: tutor@python.org
>>Reply-To: arcege@speakeasy.net
>>
>>alan.gauld@bt.com wrote
>>> 
>>> Acerge wrote:
>>> > class SingletonInstance:
>>> >   instance =3D None  # class member for the singleton instance
>>> >   def __init__(self, klass):
>>> >     if self.__class__.instance is None:
>>> 
>>> OK, I've now read the docs and had a play.
>>> 
>>> This is solving a slightly different problem, I think.
>>> The self.__class__.instance is only a convoluted way of writing
>>> SingletonInstance.instance - I think the latter is clearer.
>>
>>Except that self.__class__.instance works with subclasses of
>>SingletonInstance but SingletonInstance.instance does not.  The class I
>>gave was geared more to subclasses for the individual singleton classes
>>(which addressed your different class issue below).  But since I had
>>already specified that there had been lengthy discussions in more
>>appropriate forums, I wasn't going to go further.
>>
>>> >       self.__class__.instance =3D klass() # make the instance
>>> 
>>> This is setting the instance attribute of the SingletonInstance
>>> class to an instance of the manufactured class. I'm not sure how 
>>> this gives us a singleton structure? It will ensure that 
>>> calls to SingletonInstance produce a new instance of klass
>>> and assign it to the class variable, but for a singleton we 
>>> want to ensure that calls to the constructor return a pointer 
>>> to *the same* instance.
>>
>>Pointing to the same instance is not a necessary condition for the
>>the problem of a singleton class.  It might be how you think it should
>>work, but nothing in the functionality defined even hints to "Class()
>>is Class()" as a tautology.
>>
>>The above does not "ensure that calls to SingletonInstance produce a new
>>instance of klass".  It ensures that SingletonInstance instances will
>>always reference ONE instance (created by SingletonInstance) of klass.
>>
>>With:
>>>>> aspam =3D SingletonInstance(Spam)
>>>>> bspam =3D SingletonInstance(Spam)
>>>>> aspam.__class__.instance is bspam.__class__.instance
>>1
>>>>> 
>>
>>I assert that for any two instances of a call to the SingletonInstance
>>class, the 'instance' class member will always be the first instance
>>of the klass given in the first call and that the two instances behave
>>identically.
>>
>>The goal, and requirement, of a singleton class is that an instance
>>from a class _behaves identically_ to any other instance of that class,
>>not that only one instance can be created.  In Python, there is no
>>way for a Python class constructor to return anything other than a new
>>instance.  For that you might want to create the factory and use __call__.=
>
>>This solution allows for any instance to always access the data in the
>>first instance created.  Other more involved solutions would be to always
>>use the class members, never instance members.  The point is that object
>>identity is not a condition of singleton classes.
>>
>>> Thus:
>>> foo =3D SingletonInstance(MyFileClass)
>>> 
>>> and
>>> 
>>> bar =3D SingletonInstance(MySocketClass)
>>> 
>>> should make foo and bar reference the same instance (but, 
>>> in this case,  set the internal instance variable 
>>> to a new class reference)
>>[Here, functionally, I would hope that MyFileClass would want a
>>different singleton instance than MySocketClass since they are different
>>classes, but it was also mentioned above that here there should be two
>>subclasses of SingletonInstance to solve that.]
>>
>>Commonly idioms to this have already been put out, and ppl just need
>>to look at the multitude of modules in the standard library that
>>implement them.  Mine was not the answer to the original question and
>>I didn't attempt to make it such, but more of a method of dealing with
>>overly-complicated, abortive method at instance creation.
>>
>>  -Arcege
>>
>>-- 
>>+----------------------------------+-----------------------------------+
>>| Michael P. Reilly                | arcege@speakeasy.net              |
>>
>>
>>-- __--__-- 
>>
>>Message: 2
>>From: alan.gauld@bt.com
>>To: arcege@speakeasy.net, alan.gauld@bt.com
>>Cc: tutor@python.org
>>Subject: RE: [Tutor] singleton pattern
>>Date: Fri, 18 May 2001 17:32:37 +0100
>>
>>> > Acerge wrote:
>>> Except that self.__class__.instance works with subclasses of
>>> SingletonInstance but SingletonInstance.instance does not.  
>>
>>OK, fair point.
>>I was making a single factory class that could generate 
>>singletons of any type but you are making a class which 
>>can be subclassed, fair enough.
>>
>>> > >       self.__class__.instance =3D klass() # make the instance
>>> ... 
>>> Pointing to the same instance is not a necessary condition for the
>>> the problem of a singleton class.  It might be how you think 
>>> it should work, but nothing in the functionality defined 
>>> even hints to "Class() is Class()" as a tautology.
>>
>>Indeed, but surely "instance is instance" is?
>>
>>> The above does not "ensure that calls to SingletonInstance 
>>> produce a new instance of klass".  
>>
>>Yes, looking again I see that in fact if you try to pass 
>>a different class in subsequent calls it will be ignored. 
>>(In fact its ignored regardless of what you pass in!)
>>
>>> >>> aspam =3D SingletonInstance(Spam)
>>> >>> bspam =3D SingletonInstance(Spam)
>>> >>> aspam.__class__.instance is bspam.__class__.instance
>>> 1
>>
>>> the 'instance' class member will always be the first instance
>>> of the klass given in the first call 
>>
>>Exactly so, that was the bit I missed first time around.
>>
>>> and that the two instances behave identically.
>>
>>Since they delegate everything to the underlying 
>>singleton instance, correct. This is the tie in 
>>to Roelands post about the two techniques for 
>>generating singleton behaviour. I was trying 
>>to build a generic singleton factory, you are 
>>building a singleton wrapper. Because the ctors 
>>looked similar I tried to apply a factory metaphor 
>>to your wrapper class....
>> 
>>> The goal, and requirement, of a singleton class 
>>> is that an instance from a class _behaves identically_ 
>>> to any other instance of that class,
>>
>>Agreed.
>>
>>> not that only one instance can be created.  
>>
>>Agreed, one instance is only one way of implementing that 
>>behaviour.
>>
>>> Mine was not the answer to the original question and
>>> I didn't attempt to make it such, 
>>
>>I think thats what confused me. I assumed it was an attempt 
>>to answer the original question.
>>
>>> overly-complicated, abortive method at instance creation.
>>
>>That'd be my original pseudo-code then :-)
>>
>>Alan g
>>
>>
>>-- __--__-- 
>>
>>Message: 3
>>Date: Fri, 18 May 2001 12:55:53 -0400
>>From: Ryan Booz <ryanbooz@alumni.psu.edu>
>>To: tutor@python.org
>>Subject: [Tutor] Large scope CGI & DB problem... where to start?
>>
>>Hello all...
>>
>>I'd like to ask some questions about a CGI program I'm trying to write
>>(well, just trying to do the planning right now) and see if I can get
>>some starting points.  I'm still on the low end of the learning curve
>>with Python (learning and teaching at the same time), but I'm getting
>>ready to leave this school at the end of the year, and want to leave
>>some useful web-based management programs here for the guy that is going
>>to take over.  Of course, it's also giving me a chance to get more
>>programming experience.  I know that I'm asking a question that probably
>>has many other better solutions (PHP for instance, maybe ZOPE) but I
>>figure I'll get a start here and explore the other options as I have
>>time to learn those tools.
>>
>>The first program I'm working on is a weekly computer lab schedule that
>>can be updated to show (ala calendar type table) the periods for the
>>desired week, what classes are in the lab, and how many computers are
>>open during each period.  If there is an "open" period (or open
>>computers) a teacher can schedule that period for their class.
>>
>>So, getting the table drawn is simple enough with a CGI script.  But,
>>I really don't have a good sense how to start thinking about storing the
>>data.  Separate file for each week of school (this seems terribly
>>inefficient)? One large file with dictionaries or shelving? Would it be
>>easier to set up a MySQL DB and interface with that (yeah, I'm just
>>trying to start the DB learning curve also.... ahhhh!).
>>
>>I know this is a pretty large scope question.  And, depending on how I
>>store the data, would determine how I retrieve the data for each given
>>week.  So... I'm new and inexperienced.  Any suggestions, even "you're
>>going about this all wrong - use _______ instead", would be greatly
>>appreciated.
>>
>>Thanks for the advice and help,
>>Ryan Booz
>>Tech Coordinator
>>Belleville Mennonite School
>>
>>
>>
>>-- __--__-- 
>>
>>Message: 4
>>Date: Fri, 18 May 2001 19:43:09 +0200
>>From: Roeland Rengelink <r.b.rigilink@chello.nl>
>>To: tutor@python.org
>>Subject: Re: [Tutor] singleton pattern
>>
>>alan.gauld@bt.com wrote:
>>> 
>>
>>[snip]
>>
>>> > * the SingletonFactory
>>> >
>>> > class SingletonFactory:
>>> >     singleton =3D None
>>> >     def __call__(self):
>>> >         if SingletonFactory.singleton is None:
>>> >             SingletonFactory.singleton =3D Singleton()
>>> >         return SingletonFactory.singleton
>>> 
>>> And this is what I was doing in my second post except
>>> that I was allowing multiple Factories to be created
>>> each one managing a singleton instance of the class
>>> specified in the ctor. But I then moved the actual
>>> construction of the singleton into the makeInstance
>>> method and used an exception to pass back the actual
>>> singleton instance rather than fake access thru'
>>> the Factory class.
>>> 
>>> > >>> SF =3D SingletonFactory()
>>> > >>> x =3D SF()
>>> > >>> y =3D SF()
>>> > >>> id(x) =3D=3D id(y)
>>> > 1
>>> 
>>> I guess my question is whether it wouyld be easier to
>>> assign the instance attribute directly to x,y:
>>> 
>>> >>> x =3D SF().instance
>>> >>> y =3D SF().instance
>>> 
>>
>>that's what 
>>
>>>>> x =3D SF()
>>>>> y =3D SF()
>>
>>allready do
>>
>>Remember SF is an instance of SingletonFactory, SF().instance makes no
>>sense
>>
>>x =3D SF()
>>
>>is equivalent to
>>
>>x =3D SF.__call__()
>>
>>which is equivalent to
>>
>>x =3D SF.singleton    # if SF.singleton !=3D None)
>>
>>or
>>
>>SF.singleton =3D Singleton() # if SF.singleton =3D=3D None
>>x =3D SF.singleton
>>
>>> And also what happens using this model if we create more than one
>>> SignletonFactory instance:
>>> 
>>> SF =3D SingletonFactorty()
>>> MF =3D SingletonFactorty()
>>> x =3D MF()
>>> y =3D SF()
>>> 
>>
>>SF.singleton =3D=3D MF.singleton
>>
>>That's why I assigned to SingletonFactory.singleton, rather than
>>self.singleton
>>
>>SingletonFactory in this sense behaves like a singleton itself (i.e.
>>different ids, but identical state)
>>
>>> are x and y now pointing at the same object?
>>> 
>>
>>yes
>>
>>
>>Have fun,
>>
>>Roeland
>>
>>-- 
>>r.b.rigilink@chello.nl
>>
>>"Half of what I say is nonsense. Unfortunately I don't know which half"
>>
>>
>>-- __--__-- 
>>
>>Message: 5
>>Date: Fri, 18 May 2001 19:59:14 +0200
>>From: Roeland Rengelink <r.b.rigilink@chello.nl>
>>To: tutor@python.org
>>Subject: Re: [Tutor] singleton pattern
>>
>>D-Man wrote:
>>> 
>>> For those interested in seriously pursuing software development I
>>> highly recommend the book "Design Patterns: Elements of Reusable
>>> Object Oriented Software" by the so-called Gang of Four (Gamma, Helm,
>>> Johnson, Vlissides).  The ISBN number is 0-201-63361-2.  It is a
>>> hard-cover book and costs ~$50.  This book is not for beginners,
>>> however, and all the example code is in C++ or Smalltalk.  The
>>> patterns are really good to know and are not language specific.
>>> 
>>
>>I'd like to second that.
>>
>>One of the purposes of the book --which makes it interesting even for
>>those who cannot yet fully grasp the implementation issues addressed--
>>is to provide a design vocabulary by naming common design idioms.
>>
>>For example, this thread would have long ago degenerated into complete
>>gibberish, if this book hadn't defined the term 'singleton', giving us a
>>single word for 'a class of which there is, at any time, only one
>>instance.'
>>
>>Well, maybe it did degenerate into complete gibberish long ago. Just
>>imagine, it could have even worse.
>>
>>Roeland
>>-- 
>>r.b.rigilink@chello.nl
>>
>>"Half of what I say is nonsense. Unfortunately I don't know which half"
>>
>>
>>-- __--__-- 
>>
>>Message: 6
>>Date: Fri, 18 May 2001 13:53:10 -0400
>>From: D-Man <dsh8290@rit.edu>
>>To: tutor@python.org
>>Subject: Re: [Tutor] singleton pattern
>>
>>On Fri, May 18, 2001 at 07:43:09PM +0200, Roeland Rengelink wrote:
>>| SingletonFactory in this sense behaves like a singleton itself (i.e.
>>| different ids, but identical state)
>>
>>Flyweight, not Singleton.  :-).  (There is more than one instance, but
>>they share state)
>>
>>-D
>>
>>
>>
>>-- __--__-- 
>>
>>Message: 7
>>Date: Fri, 18 May 2001 15:43:42 -0700 (PDT)
>>From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
>>To: sheri <din22@home.com>
>>cc: tutor@python.org
>>Subject: Re: [Tutor] removing digits from a file
>>
>>On Fri, 18 May 2001, sheri wrote:
>>
>>> i want to do something like this 
>>>   
>>> if char (is a digit)
>>>    delete char
>>
>>To do this, we can write a small "isDigit()" function that tells us if a
>>character is a digit.
>>
>>###
>>def isDigit(mychar):
>>    return mychar =3D=3D '0' or mychar =3D=3D '1' or mychar =3D=3D '2' or =
>...
>>###
>>
>>But we can see that this is a really dull way of writing this.  An easier
>>way to do this is to take advantage of a list structure: doing this will
>>allow us to say: "Go though each one of these digits, and see if it
>>matches with mychar."
>>
>>###
>>def isDigit(mychar):
>>    numbers =3D ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>>    for n in numbers:
>>        if n =3D=3D mychar: return 1
>>    return 0
>>###
>>
>>We're being careful to put those numbers in quotes, because we want to
>>make sure we're making comparisons between two characters.  Python's a
>>little strict about this:
>>
>>###
>>>>> 1 =3D=3D '1'
>>0
>>###
>>
>>so we need to be aware of the trap of comparing between apples and
>>oranges.
>>
>>
>>
>>This version of isDigit() works, but there are small idioms we can use to
>>make this even nicer.
>>
>>One idiom is to use the 'in' operation on our list of numbers.  We can say=
>
>>that if our mychar is 'in' the numbers, we're ok:
>>
>>###
>>def isDigit(mychar):
>>    numbers =3D ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>>    return mychar in numbers
>>###
>>
>>
>>One other cute trick we can use is to express the characters from '0' to
>>'9' like this:
>>
>>
>>###
>>def isDigit(mychar):
>>    numbers =3D map(str, range(10))
>>    return mychar in numbers
>>###
>>
>>which means: "Let's allows numbers to stand for the list that contains the=
>
>>range from 0 through 9.  By the way, we're making all those digits into
>>strings first."
>>
>>
>>
>>-- __--__-- 
>>
>>Message: 8
>>Reply-To: <tutor@python.org>
>>From: "Tim Peters" <tim.one@home.com>
>>To: "sheri" <din22@home.com>
>>Cc: <tutor@python.org>
>>Subject: RE: [Tutor] removing digits from a file
>>Date: Fri, 18 May 2001 19:00:00 -0400
>>
>>[sheri]
>>> hello, i am trying to write a script to remove digits from a list of
>>> spelling words.
>>> i have a file like this:
>>> 1. that 2. cat 3. rat 4. etc...
>>>
>>> i want to do something like this
>>>
>>> if char (is a digit)
>>>   delete char
>>>
>>> so that the output file is like this:
>>> that cat rat etc...
>>
>>Hmm.  Since I see you got 4 replies that didn't mention the obvious soluti=
>on
>>yet, maybe it's not really that obvious <wink>.
>>
>>The string module has a translate() function that can both substitute
>>characters and delete them.  You don't want any substitutions here, so the=
>
>>code needed to turn substituting off gets in the way a bit:
>>
>>import string
>>dont_substitute_anything =3D string.maketrans("", "")
>>
>>def sheri(a_string):
>>    return string.translate(a_string,
>>                            dont_substitute_anything,
>>                            "0123456789.") # characters to delete
>>
>>Then, for example,
>>
>>>>> sheri("1. that 2. cat 3. rat 4. etc...")
>>' that  cat  rat  etc'
>>>>>
>>
>>
>>
>>-- __--__-- 
>>
>>Message: 9
>>From: "Andrew Wilkins" <toodles@yifan.net>
>>To: <tutor@python.org>
>>Date: Sat, 19 May 2001 10:37:46 +0800
>>Subject: [Tutor] wxPython & distribution
>>
>>Howdy folks,
>>
>>I'm trying to make an .exe distribution of a script that uses wxPython. I'=
>ve
>>tried using Gordon McMillan's installer scripts. They build everything oka=
>y,
>>but when i execute the file, it does absolutely nothing: it simply exits.
>>Has anyone had similar troubles, or are you all using Tkinter? :o)
>>
>>TIA,
>>Andrew
>>
>>
>>
>>
>>-- __--__-- 
>>
>>Message: 10
>>From: "Andrew Wilkins" <toodles@yifan.net>
>>To: <tutor@python.org>
>>Subject: RE: [Tutor] wxPython & distribution
>>Date: Sat, 19 May 2001 11:53:17 +0800
>>
>>Actually it's nothing to do with wxPython...
>>
>>I made a new file, a.py with one line "print 1", and that did nothing
>>either. It might be because I'm using python 2.1, I'll check it out later!=
>
>>
>>Andrew
>>
>>> -----Original Message-----
>>> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of=
>
>>> Andrew Wilkins
>>> Sent: Saturday, 19 May 2001 10:38 AM
>>> To: tutor@python.org
>>> Subject: [Tutor] wxPython & distribution
>>>
>>>
>>> Howdy folks,
>>>
>>> I'm trying to make an .exe distribution of a script that uses
>>> wxPython. I've
>>> tried using Gordon McMillan's installer scripts. They build
>>> everything okay,
>>> but when i execute the file, it does absolutely nothing: it simply exits=
>.
>>> Has anyone had similar troubles, or are you all using Tkinter? :o)
>>>
>>> TIA,
>>> Andrew
>>>
>>>
>>>
>>> _______________________________________________
>>> Tutor maillist  -  Tutor@python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>>
>>
>>
>>-- __--__-- 
>>
>>Message: 11
>>From: "Mr. Razak" <arazak@kansai.com.my>
>>To: <tutor@python.org>
>>Date: Sat, 19 May 2001 09:50:50 +0800
>>Subject: [Tutor] Setting Path From Python Shell (IDLE 0.8)
>>
>>This is a multi-part message in MIME format.
>>
>>------=3D_NextPart_000_000F_01C0E049.2FF69EE0
>>Content-Type: text/plain;
>>	charset=3D"iso-8859-1"
>>Content-Transfer-Encoding: quoted-printable
>>
>>I want to know, how can i change directory while working inside python =
>=3D
>>shell.
>>Let say i want to save my python program in C:\PY_PRG directory and i =3D
>>want to set default to this directory. How to do that.
>>
>>FYI I'm using window98 flat form.
>>
>>Thank.
>>
>>------=3D_NextPart_000_000F_01C0E049.2FF69EE0
>>Content-Type: text/html;
>>	charset=3D"iso-8859-1"
>>Content-Transfer-Encoding: quoted-printable
>>
>><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>><HTML><HEAD>
>><META content=3D3D"text/html; charset=3D3Diso-8859-1" =3D
>>http-equiv=3D3DContent-Type>
>><META content=3D3D"MSHTML 5.00.2614.3500" name=3D3DGENERATOR>
>><STYLE></STYLE>
>></HEAD>
>><BODY bgColor=3D3D#ffffff>
>><DIV><FONT face=3D3DArial size=3D3D3>I want to know, how can i change =3D
>>directory while=3D20
>>working inside python shell.</FONT></DIV>
>><DIV><FONT face=3D3DArial size=3D3D3>Let say i want to save my python =3D
>>program in=3D20
>>C:\PY_PRG directory=A0and=A0i want to set default to this =3D
>>directory. How=3D20
>>to do that.</FONT></DIV>
>><DIV>=A0</DIV>
>><DIV><FONT face=3D3DArial size=3D3D3>FYI I'm using window98 flat =3D
>>form.</FONT></DIV>
>><DIV>=A0</DIV>
>><DIV><FONT face=3D3DArial size=3D3D3><FONT=3D20
>>size=3D3D3>Thank</FONT>.</FONT></DIV></BODY></HTML>
>>
>>------=3D_NextPart_000_000F_01C0E049.2FF69EE0--
>>
>>
>>
>>-- __--__-- 
>>
>>Message: 12
>>From: =D7=C5=D0=CD=DB=C9 =D4=D0=C0=C5=D0<russianvideo@yahoo.com>
>>To: tutor@python.org
>>Reply-To: russianvideo@yahoo.com
>>Date: Sat, 19 May 2001 14:53:40 +0300
>>Subject: [Tutor] C=EC=EE=F2=F0=E8=F2=E5 =ED=E0 =E2=E8=E4=E5=EE "=D7=C5=D0=
>=CD=DB=C9 =D4=D0=C0=C5=D0"
>>
>>
>>                                                         =D1=EC=EE=F2=F0=
>=E8=F2=E5 =ED=E0 =E2=E8=E4=E5=EE
>>                                           =F1=EA=E0=ED=E4=E0=EB=FC=ED=FB=
>=E9  =F0=EE=F1=F1=E8=E9=F1=EA=E8=E9 =F4=E8=EB=FC=EC:
>>
>>                                                         =D7=C5=D0=CD=DB=
>=C9 =D4=D0=C0=C5=D0
>>
>>=DD=F2=EE =F4=E8=EB=FC=EC =F1=ED=FF=F2=FB=E9   =E2 =F1=EE=E2=E5=F0=F8=E5=
>=ED=ED=EE =ED=EE=E2=EE=EC =F1=F2=E8=EB=E5. =C6=E5=F1=F2=EE=EA=E8=E9 =E1=EE=
>=E5=E2=E8=EA =F1=EE=E5=E4=E8=ED=FF=E5=F2=F1=FF =F1 =F3=EC=EE=F0=E8=F2=E5=
>=EB=FC=ED=EE=E9 =EA=EE=EC=E5=E4=E8=E5=E9,
>>=E1=E0=ED=E4=E8=F2=F1=EA=E8=E5 =F0=E0=E7=E1=EE=F0=EA=E8 =F1=EC=E5=ED=FF=
>=FE=F2=F1=FF =EF=E0=F0=EE=E4=E8=E5=E9 =ED=E0 =EA=F3=EB=FC=F2=EE=E2=FB=E5 =
>=EA=E0=F0=F2=E8=ED=FB: =C1=F0=E0=F2, =C8=E3=EB=E0,  =C0=F1=F1=E0.
>>=C8 =E3=EB=E0=E2=ED=EE=E5, =E7=E4=E5=F1=FC =E5=F1=F2=FC =CD=EE=E2=FB=E9 =
>=C3=E5=F0=EE=E9, =E6=E5=F1=F2=EE=EA=E8=E9  =E8 =F0=EE=EC=E0=ED=F2=E8=F7=E5=
>=F1=EA=E8=E9.
>>
>>
>>-- __--__-- 
>>
>>Message: 13
>>Date: Sat, 19 May 2001 15:47:59 +0200
>>From: Kalle Svensson <kalle@gnupung.net>
>>To: tutor@python.org
>>Subject: Re: [Tutor] Setting Path From Python Shell (IDLE 0.8)
>>
>>Sez Mr. Razak:
>>> I want to know, how can i change directory while working inside python s=
>hell.
>>
>>Use os.chdir() - http://www.python.org/doc/current/lib/os-file-dir.html
>>
>>> Let say i want to save my python program in C:\PY_PRG directory and i wa=
>nt
>>> to set default to this directory. How to do that.
>>
>>I suppose the above could help, but I don't know IDLE very well.
>>
>>Peace,
>>  Kalle
>>-- 
>>Email: kalle@gnupung.net     | You can tune a filesystem, but you
>>Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
>>PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
>> [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
>>
>>
>>
>>-- __--__-- 
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>End of Tutor Digest
>>
>
>
>_________________________________________________________
>FREE Corporate Web-hosting, 20MB space, 30 Email accounts
>Get Your Own Domain at http://www.iRepublics.com
>
>
>
>--__--__--
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>End of Tutor Digest
>

_________________________________________________________
FREE Corporate Web-hosting, 20MB space, 30 Email accounts
Get Your Own Domain at http://www.iRepublics.com


From arcege@speakeasy.net  Sun May 20 13:16:33 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Sun, 20 May 2001 08:16:33 -0400 (EDT)
Subject: [Tutor] complete newbie tuple question
In-Reply-To: <001c01c0e0b4$16d0ed60$a9f1b618@mason1.ia.home.com> from "Colin Day" at May 19, 2001 05:36:04 PM
Message-ID: <200105201216.f4KCGXs08114@dsl092-074-184.bos1.dsl.speakeasy.net>

Colin Day wrote
> 
> hmm upon reflection is it perhaps because the numbering in a list or tuple
> begins with "0"?

You might want to read the Python Tutorial; section 3.1.4 explains this.
It might clear up other confusions for you.

  -Arcege

<URL: http://www.python.org/doc/current/tut/tut.html>

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From alan.gauld@bt.com  Sun May 20 23:59:03 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 20 May 2001 23:59:03 +0100
Subject: [Tutor] singleton pattern
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D79D@mbtlipnt02.btlabs.bt.co.uk>

> > > class SingletonFactory:
> > >     singleton = None
> > >     def __call__(self):
> x = SF()
> 
> is equivalent to
> 
> x = SF.__call__()


Ah! I have misunderstood the semantics of __call__().
I thought it applied to instances thus x()
would be equivalent to SingletonFactory.__call__()

I see now. I'm not sure I like it, but at least 
I understand it ;-)

Alan G


From alan.gauld@bt.com  Mon May 21 00:05:33 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 May 2001 00:05:33 +0100
Subject: [Tutor] removing digits from a file
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D79E@mbtlipnt02.btlabs.bt.co.uk>

> def isDigit(mychar):
      return mychar in string.digits

Should do the job?

Alan G


From kstoner@netins.net  Mon May 21 00:50:54 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Sun, 20 May 2001 18:50:54 -0500
Subject: [Tutor] special translations
Message-ID: <002401c0e187$b620a080$fe52b1cf@oemcomputer>

This is a multi-part message in MIME format.

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

Hi to all Python people,

I wanted to know if anyone knows how to tell python to take a space you =
left and turn it into a character.

ex:
if ltter =3D=3D 'space':
        print '~'
When Ieave a space in the above space part in the code it gives me an =
error.  How can you tell python that the space is okay and for it to =
print the symbol.

-Cameron

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi to all Python people,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I wanted to know if anyone knows how to =
tell python=20
to take a space you left and turn it into a character.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>ex:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if ltter =3D=3D=20
'space':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
'~'</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>When Ieave a space in the above space =
part in the=20
code it gives me an error.&nbsp; How can you tell python that the space =
is okay=20
and for it to print the symbol.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-Cameron</FONT></DIV></BODY></HTML>

------=_NextPart_000_0021_01C0E15D.CC9B1EA0--



From robnospam@jam.rr.com  Mon May 21 02:12:09 2001
From: robnospam@jam.rr.com (Rob Andrews)
Date: Sun, 20 May 2001 20:12:09 -0500
Subject: [Tutor] special translations
References: <002401c0e187$b620a080$fe52b1cf@oemcomputer>
Message-ID: <3B086B69.6A51270E@jam.rr.com>

Can you provide a bit more detail on what you're trying to do? I'm not
sure I get it yet.

Rob

> Katharine Stoner wrote:
> 
> Hi to all Python people,
> 
> I wanted to know if anyone knows how to tell python to take a space
> you left and turn it into a character.
> 
> ex:
> if ltter == 'space':
>         print '~'
> When Ieave a space in the above space part in the code it gives me an
> error.  How can you tell python that the space is okay and for it to
> print the symbol.
> 
> -Cameron

-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From toodles@yifan.net  Mon May 21 08:39:28 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Mon, 21 May 2001 15:39:28 +0800
Subject: [Tutor] special translations
In-Reply-To: <002401c0e187$b620a080$fe52b1cf@oemcomputer>
Message-ID: <FPEHJJPEEOIPMAHOADBKMEJKCDAA.toodles@yifan.net>

This is a multi-part message in MIME format.

------=_NextPart_000_0002_01C0E20C.38C08580
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: base64

SSBndWVzcyB0aGlzIGlzIHdoYXQgeW91IHdhbnQgdG8gZG86IGdvIHRocm91Z2ggYSBzdHJpbmcg
YW5kIHJlcGxhY2UgZWFjaCBzcGFjZSBjaGFyYWN0ZXIgd2l0aCBhICd+Jz8NCkknbSBub3QgcXVp
dGUgc3VyZSB3aGF0IHRoZSBxdWVzdGlvbiB3YXMgX2V4YWN0bHlfLg0KDQpUaGlzIGlzIHByb2Jh
Ymx5IHRoZSBzaW1wbGVzdCBzb2x1dGlvbi4uLnRoYXQgSSBrbm93IG9mIQ0KDQpleGFtcGxlX3N0
cmluZz0nYWJjIGRlZiBnaGkgamtsJw0KZXhhbXBsZV9zdHJpbmc9ZXhhbXBsZV9zdHJpbmcucmVw
bGFjZSgnICcsJ34nKQ0KDQpBbmRyZXcgV2lsa2lucw0KDQogIC0tLS0tT3JpZ2luYWwgTWVzc2Fn
ZS0tLS0tDQogIEZyb206IHR1dG9yLWFkbWluQHB5dGhvbi5vcmcgW21haWx0bzp0dXRvci1hZG1p
bkBweXRob24ub3JnXU9uIEJlaGFsZiBPZiBLYXRoYXJpbmUgU3RvbmVyDQogIFNlbnQ6IE1vbmRh
eSwgMjEgTWF5IDIwMDEgNzo1MSBBTQ0KICBUbzogcHl0aG9uIHR1dG9yDQogIFN1YmplY3Q6IFtU
dXRvcl0gc3BlY2lhbCB0cmFuc2xhdGlvbnMNCg0KDQogIEhpIHRvIGFsbCBQeXRob24gcGVvcGxl
LA0KDQogIEkgd2FudGVkIHRvIGtub3cgaWYgYW55b25lIGtub3dzIGhvdyB0byB0ZWxsIHB5dGhv
biB0byB0YWtlIGEgc3BhY2UgeW91IGxlZnQgYW5kIHR1cm4gaXQgaW50byBhIGNoYXJhY3Rlci4N
Cg0KICBleDoNCiAgaWYgbHR0ZXIgPT0gJ3NwYWNlJzoNCiAgICAgICAgICBwcmludCAnficNCiAg
V2hlbiBJZWF2ZSBhIHNwYWNlIGluIHRoZSBhYm92ZSBzcGFjZSBwYXJ0IGluIHRoZSBjb2RlIGl0
IGdpdmVzIG1lIGFuIGVycm9yLiAgSG93IGNhbiB5b3UgdGVsbCBweXRob24gdGhhdCB0aGUgc3Bh
Y2UgaXMgb2theSBhbmQgZm9yIGl0IHRvIHByaW50IHRoZSBzeW1ib2wuDQoNCiAgLUNhbWVyb24N
Cg==

------=_NextPart_000_0002_01C0E20C.38C08580
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: base64

PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIj4NCjxIVE1MPjxIRUFEPg0KPE1FVEEgaHR0cC1lcXVpdj1Db250ZW50LVR5cGUgY29udGVu
dD0idGV4dC9odG1sOyBjaGFyc2V0PWlzby04ODU5LTEiPg0KPE1FVEEgY29udGVudD0iTVNIVE1M
IDUuNTAuNDYxMy4xNzAwIiBuYW1lPUdFTkVSQVRPUj4NCjxTVFlMRT48L1NUWUxFPg0KPC9IRUFE
Pg0KPEJPRFkgYmdDb2xvcj0jZmZmZmZmPg0KPERJVj48U1BBTiBjbGFzcz05OTAzNzI5MDctMjEw
NTIwMDE+PEZPTlQgZmFjZT1UYWhvbWEgY29sb3I9IzAwMDBmZiBzaXplPTI+SSANCmd1ZXNzIHRo
aXMgaXMgd2hhdCB5b3Ugd2FudCB0byBkbzogZ28gdGhyb3VnaCBhIHN0cmluZyBhbmQgcmVwbGFj
ZSBlYWNoIHNwYWNlIA0KY2hhcmFjdGVyIHdpdGggYSAnfic/PC9GT05UPjwvU1BBTj48L0RJVj4N
CjxESVY+PFNQQU4gY2xhc3M9OTkwMzcyOTA3LTIxMDUyMDAxPjxGT05UIGZhY2U9VGFob21hIGNv
bG9yPSMwMDAwZmYgc2l6ZT0yPkknbSANCm5vdCBxdWl0ZSBzdXJlIHdoYXQgdGhlIHF1ZXN0aW9u
IHdhcyBfZXhhY3RseV8uPC9GT05UPjwvU1BBTj48L0RJVj4NCjxESVY+PFNQQU4gY2xhc3M9OTkw
MzcyOTA3LTIxMDUyMDAxPjxGT05UIGZhY2U9VGFob21hIGNvbG9yPSMwMDAwZmYgDQpzaXplPTI+
PC9GT05UPjwvU1BBTj4mbmJzcDs8L0RJVj4NCjxESVY+PFNQQU4gY2xhc3M9OTkwMzcyOTA3LTIx
MDUyMDAxPjxGT05UIGZhY2U9VGFob21hIGNvbG9yPSMwMDAwZmYgc2l6ZT0yPlRoaXMgDQppcyBw
cm9iYWJseSB0aGUgc2ltcGxlc3Qgc29sdXRpb24uLi50aGF0IEkga25vdyBvZiE8L0ZPTlQ+PC9T
UEFOPjwvRElWPg0KPERJVj48U1BBTiBjbGFzcz05OTAzNzI5MDctMjEwNTIwMDE+PEZPTlQgZmFj
ZT1UYWhvbWEgY29sb3I9IzAwMDBmZiANCnNpemU9Mj48L0ZPTlQ+PC9TUEFOPiZuYnNwOzwvRElW
Pg0KPERJVj48U1BBTiBjbGFzcz05OTAzNzI5MDctMjEwNTIwMDE+PEZPTlQgZmFjZT1UYWhvbWEg
Y29sb3I9IzAwMDBmZiANCnNpemU9Mj5leGFtcGxlX3N0cmluZz0nYWJjIGRlZiBnaGkgamtsJzwv
Rk9OVD48L1NQQU4+PC9ESVY+DQo8RElWPjxTUEFOIGNsYXNzPTk5MDM3MjkwNy0yMTA1MjAwMT48
Rk9OVCBmYWNlPVRhaG9tYSBjb2xvcj0jMDAwMGZmIA0Kc2l6ZT0yPmV4YW1wbGVfc3RyaW5nPWV4
YW1wbGVfc3RyaW5nLnJlcGxhY2UoJyAnLCd+Jyk8L0ZPTlQ+PC9TUEFOPjwvRElWPg0KPERJVj48
U1BBTiBjbGFzcz05OTAzNzI5MDctMjEwNTIwMDE+PEZPTlQgZmFjZT1UYWhvbWEgY29sb3I9IzAw
MDBmZiANCnNpemU9Mj48L0ZPTlQ+PC9TUEFOPiZuYnNwOzwvRElWPg0KPERJVj48U1BBTiBjbGFz
cz05OTAzNzI5MDctMjEwNTIwMDE+PEZPTlQgZmFjZT1UYWhvbWEgY29sb3I9IzAwMDBmZiANCnNp
emU9Mj5BbmRyZXcgV2lsa2luczwvRk9OVD48L1NQQU4+PC9ESVY+DQo8RElWPjxTUEFOIGNsYXNz
PTk5MDM3MjkwNy0yMTA1MjAwMT48Rk9OVCBmYWNlPVRhaG9tYSBjb2xvcj0jMDAwMGZmIA0Kc2l6
ZT0yPjwvRk9OVD48L1NQQU4+Jm5ic3A7PC9ESVY+DQo8QkxPQ0tRVU9URSBkaXI9bHRyIA0Kc3R5
bGU9IlBBRERJTkctTEVGVDogNXB4OyBNQVJHSU4tTEVGVDogNXB4OyBCT1JERVItTEVGVDogIzAw
MDBmZiAycHggc29saWQ7IE1BUkdJTi1SSUdIVDogMHB4Ij4NCiAgPERJViBjbGFzcz1PdXRsb29r
TWVzc2FnZUhlYWRlciBkaXI9bHRyIGFsaWduPWxlZnQ+PEZPTlQgZmFjZT1UYWhvbWEgDQogIHNp
emU9Mj4tLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLTxCUj48Qj5Gcm9tOjwvQj4gdHV0b3ItYWRt
aW5AcHl0aG9uLm9yZyANCiAgW21haWx0bzp0dXRvci1hZG1pbkBweXRob24ub3JnXTxCPk9uIEJl
aGFsZiBPZiA8L0I+S2F0aGFyaW5lIA0KICBTdG9uZXI8QlI+PEI+U2VudDo8L0I+IE1vbmRheSwg
MjEgTWF5IDIwMDEgNzo1MSBBTTxCUj48Qj5Ubzo8L0I+IHB5dGhvbiANCiAgdHV0b3I8QlI+PEI+
U3ViamVjdDo8L0I+IFtUdXRvcl0gc3BlY2lhbCB0cmFuc2xhdGlvbnM8QlI+PEJSPjwvRk9OVD48
L0RJVj4NCiAgPERJVj48Rk9OVCBmYWNlPUFyaWFsIHNpemU9Mj5IaSB0byBhbGwgUHl0aG9uIHBl
b3BsZSw8L0ZPTlQ+PC9ESVY+DQogIDxESVY+Jm5ic3A7PC9ESVY+DQogIDxESVY+PEZPTlQgZmFj
ZT1BcmlhbCBzaXplPTI+SSB3YW50ZWQgdG8ga25vdyBpZiBhbnlvbmUga25vd3MgaG93IHRvIHRl
bGwgDQogIHB5dGhvbiB0byB0YWtlIGEgc3BhY2UgeW91IGxlZnQgYW5kIHR1cm4gaXQgaW50byBh
IGNoYXJhY3Rlci48L0ZPTlQ+PC9ESVY+DQogIDxESVY+Jm5ic3A7PC9ESVY+DQogIDxESVY+PEZP
TlQgZmFjZT1BcmlhbCBzaXplPTI+ZXg6PC9GT05UPjwvRElWPg0KICA8RElWPjxGT05UIGZhY2U9
QXJpYWwgc2l6ZT0yPmlmIGx0dGVyID09IA0KICAnc3BhY2UnOjxCUj4mbmJzcDsmbmJzcDsmbmJz
cDsmbmJzcDsmbmJzcDsmbmJzcDsmbmJzcDsgcHJpbnQgJ34nPC9GT05UPjwvRElWPg0KICA8RElW
PjxGT05UIGZhY2U9QXJpYWwgc2l6ZT0yPldoZW4gSWVhdmUgYSBzcGFjZSBpbiB0aGUgYWJvdmUg
c3BhY2UgcGFydCBpbiB0aGUgDQogIGNvZGUgaXQgZ2l2ZXMgbWUgYW4gZXJyb3IuJm5ic3A7IEhv
dyBjYW4geW91IHRlbGwgcHl0aG9uIHRoYXQgdGhlIHNwYWNlIGlzIA0KICBva2F5IGFuZCBmb3Ig
aXQgdG8gcHJpbnQgdGhlIHN5bWJvbC48L0ZPTlQ+PC9ESVY+DQogIDxESVY+Jm5ic3A7PC9ESVY+
DQogIDxESVY+PEZPTlQgZmFjZT1BcmlhbCBzaXplPTI+LUNhbWVyb248L0ZPTlQ+PC9ESVY+PC9C
TE9DS1FVT1RFPjwvQk9EWT48L0hUTUw+DQo=

------=_NextPart_000_0002_01C0E20C.38C08580--



From kojo@hal-pc.org  Mon May 21 09:32:00 2001
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Mon, 21 May 2001 03:32:00 -0500
Subject: [Tutor] special translations
In-Reply-To: <002401c0e187$b620a080$fe52b1cf@oemcomputer>
Message-ID: <5.0.2.1.0.20010521025607.00af7d40@Pop3.norton.antivirus>

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

Cameron,

Are you trying to actually replace the space in the string with a '~', or 
do you just want to print a '~' in place of the space when the string is 
printed, but leave the string with the spaces in place?

I seem to have written a minor tongue-twister...

If you want to replace the space (alter the actual string), Andrew's 
suggestion makes the most sense.

If you want to keep the string full of spaces, but print '~' in their 
place, (which is what it sounds like you're trying to do) there would seem 
to be a couple of options (at least at 3am...):
1.  Use replace.string to create copies of the strings for printing
         example_string='abc def ghi jkl'
         print_string=example_string.replace(' ','~')
         print print_string
2. Iterate through the strings element by element and determine if the 
character in question is a space or not.  If not, print it, if so, print 
'~'.  NB: what follows is intended to be Psuedo-Code.

         x=0
         while example_string:
             if example_string[x] != '~':
               print example_string[x]
               x=x+1
         else:
           print '~'
           x=x+1

Without knowing more about what you're trying to do, I'm not sure which 
would be more efficient.  Actually, even if I did know what you were doing, 
I might not know.  I will defer to the expertise of those who know more 
than I.  (That means just about everyone on the list.)
:-)

Am I on the right track as far as what you're trying to do?

Hope this helps,


At 06:50 PM 5/20/2001 -0500, you wrote:
>Hi to all Python people,
>
>I wanted to know if anyone knows how to tell python to take a space you 
>left and turn it into a character.
>
>ex:
>if ltter == 'space':
>         print '~'
>When Ieave a space in the above space part in the code it gives me an 
>error.  How can you tell python that the space is okay and for it to print 
>the symbol.
>
>-Cameron

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

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************
--=====================_164306==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
Cameron,<br>
<br>
Are you trying to actually replace the space in the string with a '~',
<b>or </b>do you just want to print a '~' in place of the space when the
string is printed, but leave the string with the spaces in place?<br>
<br>
I seem to have written a minor tongue-twister...<br>
<br>
If you want to replace the space (alter the actual string), Andrew's
suggestion makes the most sense.&nbsp; <br>
<br>
If you want to keep the string full of spaces, but print '~' in their
place, (which is what it sounds like you're trying to do) there would
seem to be a couple of options (at least at 3am...):<br>
1.&nbsp; Use replace.string to create copies of the strings for
printing<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><font face="tahoma" size=2>example_string='abc
def ghi jkl'<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>print_string=example_string.replace('
','~')<br>
</font><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>print
<font face="tahoma" size=2>print_string<br>
</font>2. Iterate through the strings element by element and determine if
the character in question is a space or not.&nbsp; If not, print it, if
so, print '~'.&nbsp; NB: what follows is intended to be 
Psuedo-Code.<br>
<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>x=0<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>while
example_string:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;&nbsp;&nbsp;
if example_string[x] != '~':<br>
&nbsp;
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
print example_string[x]<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
x=x+1<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>else:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;
print '~'<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;
x=x+1<br>
<br>
Without knowing more about what you're trying to do, I'm not sure which
would be more efficient.&nbsp; Actually, even if I did know what you were
doing, I might not know.&nbsp; I will defer to the expertise of those who
know more than I.&nbsp; (That means just about everyone on the
list.)<br>
:-)<br>
<br>
Am I on the right track as far as what you're trying to do?<br>
<br>
Hope this helps,<br>
<br>
<br>
At 06:50 PM 5/20/2001 -0500, you wrote:<br>
<blockquote type=cite class=cite cite><font face="arial" size=2>Hi to all
Python people,</font><br>
&nbsp;<br>
<font face="arial" size=2>I wanted to know if anyone knows how to tell
python to take a space you left and turn it into a 
character.</font><br>
&nbsp;<br>
<font face="arial" size=2>ex:</font><br>
<font face="arial" size=2>if ltter == 'space':<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print '~'</font><br>
<font face="arial" size=2>When Ieave a space in the above space part in
the code it gives me an error.&nbsp; How can you tell python that the
space is okay and for it to print the symbol.</font><br>
&nbsp;<br>
<font face="arial" size=2>-Cameron</font></blockquote>
<x-sigsep><p></x-sigsep>
**************************** <br>
Kojo Idrissa <br>
&nbsp; <br>
kojo@hal-pc.org<br>
<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http</a>://www.hal-pc.org<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">/~kojo/</a><br>
****************************</html>
--=====================_164306==_.ALT--



From karimy@nipltd.com  Mon May 21 11:43:31 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Mon, 21 May 2001 11:43:31 +0100
Subject: [Tutor] is there an equivalent to the 'commands' module for Win32 platforms (95,98,NT)?
Message-ID: <007e01c0e1e2$e0c2dfa0$a5020a0a@private.nipltd.com>

Hi there,
I'd like to run some python scripts from another a script. I was looking at
the documentation this morning, and I found the 'command's module which
,unfortunately, runs only on POSIX platforms. how can run commands in a
Win98 environment? Has anyone tried to do the same?

There is also  a module called 'nt', no documentation available on this one
;-(...I don't see any difference between this module and 'system', do you?

Thank you for your help.

Cheers,
Karim



From scarblac@pino.selwerd.nl  Mon May 21 11:56:29 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 21 May 2001 12:56:29 +0200
Subject: [Tutor] is there an equivalent to the 'commands' module for Win32 platforms (95,98,NT)?
In-Reply-To: <007e01c0e1e2$e0c2dfa0$a5020a0a@private.nipltd.com>; from karimy@nipltd.com on Mon, May 21, 2001 at 11:43:31AM +0100
References: <007e01c0e1e2$e0c2dfa0$a5020a0a@private.nipltd.com>
Message-ID: <20010521125629.A17910@pino.selwerd.nl>

On  0, Karim Yaici <karimy@nipltd.com> wrote:
> Hi there,
> I'd like to run some python scripts from another a script. I was looking at
> the documentation this morning, and I found the 'command's module which
> ,unfortunately, runs only on POSIX platforms. how can run commands in a
> Win98 environment? Has anyone tried to do the same?

The commands module is mostly just a wrapper around os.popen, as far as I
know. You should be able to use os.system() to start a command, and
os.popen() to get output from the command. That last thing may be a bit
dodgy on Windows, I don't know about that.

> There is also  a module called 'nt', no documentation available on this one
> ;-(...I don't see any difference between this module and 'system', do you?

You mean 'os'. 'nt' shouldn't be used directly, it's basically the same as
'os' - on Windows. 'os' is a wrapper around whatever platform-specific
module should be used.

Try
>>> import os
>>> print os.name

That should print 'nt' for you, meaning that the functions are taken from
the nt module - on my Linux system, it print posix, taking its functions
from there.

-- 
Remco Gerlich


From karimy@nipltd.com  Mon May 21 12:45:01 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Mon, 21 May 2001 12:45:01 +0100
Subject: [Tutor] is there an equivalent to the 'commands' module for Win32 platforms (95,98,NT)?
References: <007e01c0e1e2$e0c2dfa0$a5020a0a@private.nipltd.com> <20010521125629.A17910@pino.selwerd.nl>
Message-ID: <009501c0e1eb$78787be0$a5020a0a@private.nipltd.com>

Thanks fot your help.
It does actually work. Here is the synatx I used:

----hellowin.py----
print "Windows sucks!"
-----------------

# To execute a command....
>>> import os
>>> os.system('python hellowin.py')
Windows sucks!
0
# I think that the zero is the status code -correct me if i'm wrong-, which
is always 0 in Windows

# To capture the output...
>>>output = os.popen('python hellowin.py').read()
>>>output
'Windows sucks!'

Cheers,

Karim
----- Original Message -----
From: "Remco Gerlich" <scarblac@pino.selwerd.nl>
To: <tutor@python.org>
Sent: Monday, May 21, 2001 11:56 AM
Subject: Re: [Tutor] is there an equivalent to the 'commands' module for
Win32 platforms (95,98,NT)?


> On  0, Karim Yaici <karimy@nipltd.com> wrote:
> > Hi there,
> > I'd like to run some python scripts from another a script. I was looking
at
> > the documentation this morning, and I found the 'command's module which
> > ,unfortunately, runs only on POSIX platforms. how can run commands in a
> > Win98 environment? Has anyone tried to do the same?
>
> The commands module is mostly just a wrapper around os.popen, as far as I
> know. You should be able to use os.system() to start a command, and
> os.popen() to get output from the command. That last thing may be a bit
> dodgy on Windows, I don't know about that.
>
> > There is also  a module called 'nt', no documentation available on this
one
> > ;-(...I don't see any difference between this module and 'system', do
you?
>
> You mean 'os'. 'nt' shouldn't be used directly, it's basically the same as
> 'os' - on Windows. 'os' is a wrapper around whatever platform-specific
> module should be used.
>
> Try
> >>> import os
> >>> print os.name
>
> That should print 'nt' for you, meaning that the functions are taken from
> the nt module - on my Linux system, it print posix, taking its functions
> from there.
>
> --
> Remco Gerlich
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From SBrunning@trisystems.co.uk  Mon May 21 13:53:01 2001
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Mon, 21 May 2001 13:53:01 +0100
Subject: [Tutor] removing digits from a file
Message-ID: <31575A892FF6D1118F5800600846864D78BC45@intrepid>

> From:	Daniel Yoo [SMTP:dyoo@hkn.eecs.berkeley.edu]
> To do this, we can write a small "isDigit()" function that tells us if a
> character is a digit.
 
String objects already have a method for this:

>>> spam = 'a'
>>> spam.isdigit()
0
>>> spam = '1'
>>> spam.isdigit()
1

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 ppathiyi@cisco.com  Mon May 21 13:58:41 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Mon, 21 May 2001 18:28:41 +0530
Subject: [Tutor] Making the binary when more than a single file is involved
Message-ID: <03ff01c0e1f5$c2dd3d10$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

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

Hi,
        My python application consists of two files config.py and =
Server.py.
        The config.py file consists of some configurable parameters and =
a single function call main(), which is defined in Server.py. I do a =
"vi" of the config.py to change the values in that.

config.py looks like ----

### CONFIGURABLE PARAMETERS START ####

---- parameters ----

#### CONFIGURABLE PARAMETERS END ####

from Server import *

main()


where Server is the one and only class defined in Server.py.

But when i made the binary of these two files using freeze.py and tried =
to run the same, i got an error saying that the module "Server" was not =
found.

Any suggestions on this ?

TIA,
Praveen.

------=_NextPart_000_03FC_01C0E223.DC1FD3E0
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
My python=20
application consists of two files config.py and Server.py.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
The config.py=20
file consists of some configurable parameters and a single function call =
main(),=20
which is defined in Server.py. I do a "vi" of the config.py to change =
the values=20
in that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>config.py looks like ----</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>### CONFIGURABLE PARAMETERS START =
####</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>---- parameters ----</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#### CONFIGURABLE PARAMETERS END =
####</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>from Server import *</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>main()</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>where Server is the one and only class =
defined in=20
Server.py.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But when i made the binary of these two =
files using=20
freeze.py and tried to run the same, i got an error saying that the =
module=20
"Server" was not found.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Any suggestions on this ?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV></BODY></HTML>

------=_NextPart_000_03FC_01C0E223.DC1FD3E0--



From karimy@nipltd.com  Mon May 21 14:46:47 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Mon, 21 May 2001 14:46:47 +0100
Subject: [Tutor] is there an equivalent to the 'commands' module for Win32 platforms (95,98,NT)?
References: <007e01c0e1e2$e0c2dfa0$a5020a0a@private.nipltd.com> <20010521125629.A17910@pino.selwerd.nl> <009501c0e1eb$78787be0$a5020a0a@private.nipltd.com>
Message-ID: <00ab01c0e1fc$7b2b0900$a5020a0a@private.nipltd.com>

Another try with popen....
Because we a live in  a non-perfect world, I wanted to see what will happen
when you try to run a python script with 'os.popen' that is not valid.

First, I tried:
>>>print os.popen('python c:\\mydoc\\foo.py).read() #foo.py does not exist
BTW.
Here are the results:
-> With Python 2.0 (ActiveState version), I get nothing, empty string.
-> With Python 2.0 (on Linux), I get:
    python: can't open file 'foo.py'
-> With Python 1.5.2 (installed with Zope), I get:
C:\PROGRA~1\ZOPE\23~1.2\BIN\PYTHON.EXE: can't open file 'foo.py'

Next, I tried with a valid path but a non-valid code. So  'hellowin.py'
becomes:
-------------------------------
print "Windows sucks!" bla, bla
------------------------------

..which should raise NameError. However this does not work on ActivePython
(V2.0).

So, do I really need to a see a doctor, or you guys, know what it is all
about.

Cheers,
Karim
----- Original Message -----
From: "Karim Yaici" <karimy@nipltd.com>
To: "Remco Gerlich" <scarblac@pino.selwerd.nl>; <tutor@python.org>
Sent: Monday, May 21, 2001 12:45 PM
Subject: Re: [Tutor] is there an equivalent to the 'commands' module for
Win32 platforms (95,98,NT)?


> Thanks fot your help.
> It does actually work. Here is the synatx I used:
>
> ----hellowin.py----
> print "Windows sucks!"
> -----------------
>
> # To execute a command....
> >>> import os
> >>> os.system('python hellowin.py')
> Windows sucks!
> 0
> # I think that the zero is the status code -correct me if i'm wrong-,
which
> is always 0 in Windows
>
> # To capture the output...
> >>>output = os.popen('python hellowin.py').read()
> >>>output
> 'Windows sucks!'
>
> Cheers,
>
> Karim
> ----- Original Message -----
> From: "Remco Gerlich" <scarblac@pino.selwerd.nl>
> To: <tutor@python.org>
> Sent: Monday, May 21, 2001 11:56 AM
> Subject: Re: [Tutor] is there an equivalent to the 'commands' module for
> Win32 platforms (95,98,NT)?
>
>
> > On  0, Karim Yaici <karimy@nipltd.com> wrote:
> > > Hi there,
> > > I'd like to run some python scripts from another a script. I was
looking
> at
> > > the documentation this morning, and I found the 'command's module
which
> > > ,unfortunately, runs only on POSIX platforms. how can run commands in
a
> > > Win98 environment? Has anyone tried to do the same?
> >
> > The commands module is mostly just a wrapper around os.popen, as far as
I
> > know. You should be able to use os.system() to start a command, and
> > os.popen() to get output from the command. That last thing may be a bit
> > dodgy on Windows, I don't know about that.
> >
> > > There is also  a module called 'nt', no documentation available on
this
> one
> > > ;-(...I don't see any difference between this module and 'system', do
> you?
> >
> > You mean 'os'. 'nt' shouldn't be used directly, it's basically the same
as
> > 'os' - on Windows. 'os' is a wrapper around whatever platform-specific
> > module should be used.
> >
> > Try
> > >>> import os
> > >>> print os.name
> >
> > That should print 'nt' for you, meaning that the functions are taken
from
> > the nt module - on my Linux system, it print posix, taking its functions
> > from there.
> >
> > --
> > Remco Gerlich
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From Eugene.Leitl@lrz.uni-muenchen.de  Mon May 21 16:34:52 2001
From: Eugene.Leitl@lrz.uni-muenchen.de (Eugene Leitl)
Date: Mon, 21 May 2001 17:34:52 +0200 (MET DST)
Subject: [Tutor] pipes
Message-ID: <Pine.SOL.4.33.0105211728370.2125-100000@sun1.lrz-muenchen.de>

I'm trying to write the unix commandline idiom of

$ prog1 123 | prog2

bash-2.01$ cat rxid2png
#!/usr/local/bin/bash

echo "Content-type: image/png"
echo ""
./webdsp1 15 | ./dispreact





In Python, calling above as

import os
os.system('rxid2png')


does what I want. I want to get rid of the shell
by using pipes.


How do I hook up the output of below to the second program?

import os, sys

pipe = os.popen('webdsp1')
print pipe.read()


Sorry for being terse, I'm using pine over ssh over a loaded link.

TIA



From dsh8290@rit.edu  Mon May 21 16:40:55 2001
From: dsh8290@rit.edu (D-Man)
Date: Mon, 21 May 2001 11:40:55 -0400
Subject: [Tutor] pipes
In-Reply-To: <Pine.SOL.4.33.0105211728370.2125-100000@sun1.lrz-muenchen.de>; from Eugene.Leitl@lrz.uni-muenchen.de on Mon, May 21, 2001 at 05:34:52PM +0200
References: <Pine.SOL.4.33.0105211728370.2125-100000@sun1.lrz-muenchen.de>
Message-ID: <20010521114055.B16848@harmony.cs.rit.edu>

On Mon, May 21, 2001 at 05:34:52PM +0200, Eugene Leitl wrote:

<trying to use pipes with python instead of the shell>

| In Python, calling above as
| 
| import os
| os.system('rxid2png')
| 
| does what I want. I want to get rid of the shell
| by using pipes.

os.system is a thin wrapper around the C system function.  The C
system function (at least on unix) embodies the most common fork-exec
idiom to reduce repititive code where security is not of utmost
concern.

| How do I hook up the output of below to the second program?
| 
| import os, sys
| 
| pipe = os.popen('webdsp1')
| print pipe.read()

The popen family of functions opens a pipe to the specified process.
popen() gives a handle to the output pipe from the process (for you to
read).  popen2() gives handles to both the input and output pipes.
There is also (IIRC) popen3 and popen4 though I don't remember what
they do.  (popen3 probably gives stderr as well as stdout and stdin
handles)

HTH,
-D



From scarblac@pino.selwerd.nl  Mon May 21 16:39:05 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 21 May 2001 17:39:05 +0200
Subject: [Tutor] pipes
In-Reply-To: <Pine.SOL.4.33.0105211728370.2125-100000@sun1.lrz-muenchen.de>; from Eugene.Leitl@lrz.uni-muenchen.de on Mon, May 21, 2001 at 05:34:52PM +0200
References: <Pine.SOL.4.33.0105211728370.2125-100000@sun1.lrz-muenchen.de>
Message-ID: <20010521173905.A18673@pino.selwerd.nl>

On  0, Eugene Leitl <Eugene.Leitl@lrz.uni-muenchen.de> wrote:
> How do I hook up the output of below to the second program?
> 
> import os, sys
> 
> pipe = os.popen('webdsp1')
> print pipe.read()

You can also write to programs opened with os.popen:

program1 = os.popen('webdsp1', 'r')
program2 = os.popen('dispreact', 'w')
program2.write(program1.read())

Done this way, the programs don't run at the same time: first Python reads
in all the output from program1, then it passes it all to program2. If that
isn't good enough you can read from program1 in smaller chunks and pass
those to program2, in a loop.

-- 
Remco Gerlich


From patrick@kirks.net  Mon May 21 16:56:42 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Mon, 21 May 2001 16:56:42 +0100
Subject: [Tutor] New to programming
Message-ID: <006501c0e20e$a12722d0$1900a8c0@pod>

Hi all,

I'm learning to program and in my enthusiasm rushed out and bought Visual
C++ and a beginners guide.  Its OK but I've read several articles warning
that C and C++ are poor first languages.  Python is widely commented on as
an ideal first language.

So I've downloaded Python and a tutorial called "How to think like a
computer scientist by Allen B. Downey and Jeffrey Elkner"

So far so good.  "Hello World" is a lot more compact in Python than in C++.

Without starting an advocacy thread, why is Python so well spoken of as a
first language?  Obviously knowing what makes it good makes learning it even
more useful...


--
Patrick Kirk
GSM: +44 7712 184 480
ICQ: 42219699

Wise Chinese Proverb:  "If tired of computer winning at real time strategy
games, try it at kick-boxing instead"


--
Patrick Kirk
GSM: +44 7712 184 480
ICQ: 42219699

Wise Chinese Proverb:  "If tired of computer winning at real time strategy
games, try it at kick-boxing instead"



From randrews@planhouse.com  Mon May 21 17:14:11 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Mon, 21 May 2001 11:14:11 -0500
Subject: [Tutor] New to programming
In-Reply-To: <006501c0e20e$a12722d0$1900a8c0@pod>
Message-ID: <000f01c0e211$12ba6220$de00a8c0@planhouse5>

Ah, a question easy enough for even me to answer!

Python is really easy to read, even if you wrote the program weeks ago or it
was written by someone else. That alone makes it good. It also comes "with
batteries included", referring to the over 200 built-in modules included to
handle common tasks (even some fairly deep stuff).

People tend to learn Python very quickly in comparison with other languages.
It's enough like C and similar languages that you aren't learning a bunch of
things that will seriously trip you up when you start moving into other
languages (despite some esoteric arguments I've heard). There's also the
GREAT community of Python users out there who are happy to help answer
questions and solve problems. And, unlike some other good first languages,
Python is a general-purpose language, so it can be used to code a wide
variety of programs instead of specializing in something like Regular
Expressions or Database Access. Oh, and if you want to learn Object-Oriented
programming, Python is fantastic for making the process of learning it just
about painless.

I could go on and on, but there's plenty of time for that.

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html

-----Original Message-----

Hi all,

I'm learning to program and in my enthusiasm rushed out and bought Visual
C++ and a beginners guide.  Its OK but I've read several articles warning
that C and C++ are poor first languages.  Python is widely commented on as
an ideal first language.

So I've downloaded Python and a tutorial called "How to think like a
computer scientist by Allen B. Downey and Jeffrey Elkner"

So far so good.  "Hello World" is a lot more compact in Python than in C++.

Without starting an advocacy thread, why is Python so well spoken of as a
first language?  Obviously knowing what makes it good makes learning it even
more useful...


--
Patrick Kirk
GSM: +44 7712 184 480
ICQ: 42219699

Wise Chinese Proverb:  "If tired of computer winning at real time strategy
games, try it at kick-boxing instead"


--
Patrick Kirk
GSM: +44 7712 184 480
ICQ: 42219699

Wise Chinese Proverb:  "If tired of computer winning at real time strategy
games, try it at kick-boxing instead"


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



From scarblac@pino.selwerd.nl  Mon May 21 17:22:57 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 21 May 2001 18:22:57 +0200
Subject: [Tutor] New to programming
In-Reply-To: <006501c0e20e$a12722d0$1900a8c0@pod>; from patrick@kirks.net on Mon, May 21, 2001 at 04:56:42PM +0100
References: <006501c0e20e$a12722d0$1900a8c0@pod>
Message-ID: <20010521182257.A18765@pino.selwerd.nl>

On  0, Patrick Kirk <patrick@kirks.net> wrote:
> Without starting an advocacy thread, why is Python so well spoken of as a
> first language?  Obviously knowing what makes it good makes learning it even
> more useful...

Some reasons:

- Python is fun to program in.

- It's a very clear language. Easy to read. Using indentation for block
  structure and often using words where other languages use punctuation marks
  makes it clear, even when complicated things are happening. Code is read
  much more often than it is written. This is very important.

- It scales well to very small problems. As you noted, writing "Hello World"
  is 1 line that doesn't take much explaining. In Java it would be something
  like
  
  class helloworld {
     public static void main(String args[]) {
        System.out.println("Hello world!")
     }
  }
  
  Look at all that cruft that has to explained to a newbie ("public static
  void main"? Huh?) even though it's not relevant to printing hello world.
  
- With those two combined, it's easy to teach someone *how to program*, 
  instead of teaching them how to program *in language x*. The syntactic
  cruft isn't relevant to programming in general.

- The interactive interpreter is ideal for trying things out.

- What sort of thing is a newbie likely to want to program? Make a few
  scripts for moving files around? Get mail from a mailbox? Automate something
  with Word? Generate HTML from some text files for a webpage? Make a small
  game with a GUI? For all of that, Python is an excellent choice.

- Python is actually very useful. You can do a lot more with it than make
  small beginners' programs.
  
- Python has a Tutor list and a cool community in general ;-)


Python isn't perfect - it's pretty slow, I wouldn't use it for low level
things like device drivers, you'll be spoiled if you are ever forced to use
another language - but that's not that important for a beginner :).

So in my opinion no other language comes close for a beginners' language.
That said, it doesn't hurt at all to try to learn a few (like Alan's
tutorial, it also shows examples in Tcl and BASIC - it's the idea that's
important, not the specific incantation).

-- 
Remco Gerlich


From lep@aber.ac.uk  Mon May 21 17:46:25 2001
From: lep@aber.ac.uk (Leighton Pritchard)
Date: Mon, 21 May 2001 17:46:25 +0100
Subject: [Tutor] New to programming
In-Reply-To: <000f01c0e211$12ba6220$de00a8c0@planhouse5>
References: <006501c0e20e$a12722d0$1900a8c0@pod>
Message-ID: <5.1.0.14.0.20010521172046.00b1d830@pophost.aber.ac.uk>

At 11:14 21/05/01, you wrote:
>Ah, a question easy enough for even me to answer!

Ditto. As a newbie to Python myself I'm quite familiar with the process of 
learning the language first hand :). Everything Rob said is true, but 
speaking purely from my own experience...

(Not counting Sinclair and Q basics) I started to learn 'proper' 
programming with C, which was initially a bit of a struggle, but becomes 
much easier with practice (even though I'm still not much good :( ). Though 
I wasn't a complete newbie to programming, and knew enough about control 
structures and other things to work through Lutz & Ascher's 'Learning 
Python' quite quickly [an excellent book to learn from, by the way], there 
were some things about Python that accelerated the learning process. The 
advantages I found over C/C++ for learning were:

Using IDLE/the interactive prompt meant that I could try out ideas and 
extend my understanding of  the (excellent, copious) library functions and 
the way the language behaves 'on the fly' without recompiling at 
practically every step. That speed of turnaround encouraged me to learn and 
experiment more.

The error messages aren't as obscure. As you might have noticed in C/C++ (I 
know I did!) that even simple syntax errors can result in an error message 
that points you to a part of the program well away from where your error 
occurred. Starting out I spent a lot of time trying to work out where the 
heck I'd made a mistake when my code wasn't even compiling. Python tends 
not to do that to me (very often :) ).

Many of the libraries make it very easy to do complicated things (e.g. 
download a webpage) quickly and easily without the need for a thorough 
understanding of what's going on at a low level. This gave me an early buzz 
of (unearned?) achievement and encouraged me to learn more.

As a beginner, you don't *need* to know some important, but distracting 
things (like the number of bits in a floating-point variable, or how to 
take care of memory allocation, or to remember not to count for more 
entries than there are in an array) before you can write a highly 
functional and powerful program. The operations listed in brackets are 
pretty important in C/C++ and continue to be the source of most of my 
errors :).

Oh, yeah, and I've not found any pointers in Python, yet :)

Aside from that there's a friendly user community and good documentation 
when you need help.

Have fun,

>Python is really easy to read, even if you wrote the program weeks ago or it
>was written by someone else. That alone makes it good. It also comes "with
>batteries included", referring to the over 200 built-in modules included to
>handle common tasks (even some fairly deep stuff).
>
>People tend to learn Python very quickly in comparison with other languages.
>It's enough like C and similar languages that you aren't learning a bunch of
>things that will seriously trip you up when you start moving into other
>languages (despite some esoteric arguments I've heard). There's also the
>GREAT community of Python users out there who are happy to help answer
>questions and solve problems. And, unlike some other good first languages,
>Python is a general-purpose language, so it can be used to code a wide
>variety of programs instead of specializing in something like Regular
>Expressions or Database Access. Oh, and if you want to learn Object-Oriented
>programming, Python is fantastic for making the process of learning it just
>about painless.
>
>I could go on and on, but there's plenty of time for that.
>
>Rob
>
>Got Python?
>http://www.lowerstandard.com/python/pythonsource.html
>
>-----Original Message-----
>
>Hi all,
>
>I'm learning to program and in my enthusiasm rushed out and bought Visual
>C++ and a beginners guide.  Its OK but I've read several articles warning
>that C and C++ are poor first languages.  Python is widely commented on as
>an ideal first language.
>
>So I've downloaded Python and a tutorial called "How to think like a
>computer scientist by Allen B. Downey and Jeffrey Elkner"
>
>So far so good.  "Hello World" is a lot more compact in Python than in C++.
>
>Without starting an advocacy thread, why is Python so well spoken of as a
>first language?  Obviously knowing what makes it good makes learning it even
>more useful...

-- 
Dr Leighton Pritchard GRSC
T44, Cledwyn Building
Institute of Biological Sciences
University of Wales, Aberystwyth, SY23 3DD
Tel 01970 622353    ext. 2353
PGP public key - http://www.keyserver.net (0x47B4A485)



From kalle@gnupung.net  Mon May 21 17:48:25 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Mon, 21 May 2001 18:48:25 +0200
Subject: [Tutor] New to programming
In-Reply-To: <006501c0e20e$a12722d0$1900a8c0@pod>; from patrick@kirks.net on Mon, May 21, 2001 at 04:56:42PM +0100
References: <006501c0e20e$a12722d0$1900a8c0@pod>
Message-ID: <20010521184825.A6426@father>

Sez Patrick Kirk:
> Hi all,

Hello!

> Without starting an advocacy thread, why is Python so well spoken of as a
> first language?  Obviously knowing what makes it good makes learning it even
> more useful...

Well, that's a good question!  Here are my opinions:

Python is a clean, well designed language.  Most of the time, there is one
obvious way to do something.  It encourages well structured and readable
code.

It's interpreted and dynamic, reducing the time needed to make a change or
try a new thing.  This is to make sure you don't get bored.

It has got a good, large, well-documented standard library.  This makes
it easy to develop more interesting applications from the start.

It also supports many different programming paradigms, which makes it easier
to learn another language after having learned Python.

Another thing which I consider quite important, is that the Python community
is friendly and (mostly) helpful.  Especially this list is very nice, but
even the major python list and #python on IRC have a good atmosphere.

When I'm at it:  Check out the Useless Python site
(http://www.lowerstandard.com/python/pythonsource.html).  It has quite a few
challenges and examples, gathered by Rob Andrews, a regular on this list.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From patrick@kirks.net  Mon May 21 20:44:49 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Mon, 21 May 2001 20:44:49 +0100
Subject: [Tutor] New to programming
References: <006501c0e20e$a12722d0$1900a8c0@pod>
Message-ID: <013901c0e22e$7f4ab7b0$1900a8c0@pod>

Thanks.  I wading through thwo tutorials at the moment.  This while space
stuff causes problems but no doubt you'll become aware of these as I
progress to more basic questions.



From Eugene.Leitl@lrz.uni-muenchen.de  Mon May 21 23:48:20 2001
From: Eugene.Leitl@lrz.uni-muenchen.de (Eugene.Leitl@lrz.uni-muenchen.de)
Date: Tue, 22 May 2001 00:48:20 +0200
Subject: [Tutor] pipes
References: <Pine.SOL.4.33.0105211728370.2125-100000@sun1.lrz-muenchen.de> <20010521173905.A18673@pino.selwerd.nl>
Message-ID: <3B099B34.A4DDBA8A@lrz.uni-muenchen.de>

Remco Gerlich wrote:

> program1 = os.popen('webdsp1', 'r')
> program2 = os.popen('dispreact', 'w')
> program2.write(program1.read())
> 
> Done this way, the programs don't run at the same time: first Python reads
> in all the output from program1, then it passes it all to program2. If that
> isn't good enough you can read from program1 in smaller chunks and pass
> those to program2, in a loop.

Thanks a lot. I'll try that tomorrow. Lack of concurrency is actually 
an advantage, since the total output is small (few kBytes), and it should
be able to run as many platforms as possible without having to tweak
anything.

If it wasn't for time constraints I'd avoid calling any external
binaries, and rather use gdmodule instead (I know PIL would have
been probably better, but current app has been using GD for time 
immemorial, and via GD.pm, so remapping that into Python wouldn't
have cost me as much as doing it in C (I don't know C either)).


From din22@home.com  Mon May 21 22:07:15 2001
From: din22@home.com (sheri)
Date: Mon, 21 May 2001 16:07:15 -0500
Subject: [Tutor] thanks for all the help!
References: <E151pKw-0005Pn-00@mail.python.org>
Message-ID: <001401c0e23a$03b75160$134d0141@dstn1.fl.home.com>




From robnospam@jam.rr.com  Tue May 22 04:06:38 2001
From: robnospam@jam.rr.com (Rob Andrews)
Date: Mon, 21 May 2001 22:06:38 -0500
Subject: [Tutor] New to programming
References: <006501c0e20e$a12722d0$1900a8c0@pod> <013901c0e22e$7f4ab7b0$1900a8c0@pod>
Message-ID: <3B09D7BE.F5BB5190@jam.rr.com>

You may find that the white space becomes A Good Thing as you get used
to it. I know I have. Curly braces are for dictionaries!

Rob

Patrick Kirk wrote:
> 
> Thanks.  I wading through thwo tutorials at the moment.  This while space
> stuff causes problems but no doubt you'll become aware of these as I
> progress to more basic questions.
> 
-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From alan.gauld@bt.com  Tue May 22 09:42:08 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 22 May 2001 09:42:08 +0100
Subject: [Tutor] New to programming
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7AC@mbtlipnt02.btlabs.bt.co.uk>

> Without starting an advocacy thread, why is Python so well 
> spoken of as a first language?  

Some of this is covered in the intro to my tutor

http://www.crosswinds.net/~agauld

But a quick bullet list would include:

- Its free
- Its higher level than C++ (fewer statements to do the same job)
- Its dynamically typed(means you don't need to worry 
   about details too soon)
- It supports many programming styles so you can grow as you learn
- It doesn't use many weird symbols or characters 
	(eg C based languages us || for OR  and && for AND 
	whereas python uses 'or' and 'and' - easy eh?!
- It has a friendly and generally patient user community who 
	are keen to help.

Other languages can claim the same(Lisp/Scheme, Logo, 
Smalltalk to name 3) but Python does seems to work well in practice.

Alan g


From ppathiyi@cisco.com  Tue May 22 09:51:43 2001
From: ppathiyi@cisco.com (Praveen Pathiyil)
Date: Tue, 22 May 2001 14:21:43 +0530
Subject: [Tutor] operator and function call
Message-ID: <050701c0e29c$6d04f1b0$37ef87c0@ppathiyipc>

This is a multi-part message in MIME format.

------=_NextPart_000_0504_01C0E2CA.866DAE20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

        What is the rationale in implementing some functionalities both =
as an operator and as a function call ?

E.g: 2 raised to the power of 3 can be computed as=20

2 ** 3 and as pow(2,3)

Similarly a - b and operator.sub(a,b)

Any specific reasons for such an approach ?

Regards,
Praveen.

------=_NextPart_000_0504_01C0E2CA.866DAE20
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.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
What is the=20
rationale in implementing some functionalities both as an operator =
and&nbsp;as a=20
function call ?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>E.g: 2 raised to the power of 3 can be =
computed as=20
</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2 ** 3 and as pow(2,3)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Similarly a - b and =
operator.sub(a,b)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Any specific reasons for such an =
approach=20
?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0504_01C0E2CA.866DAE20--



From joe@magiclantern.co.uk  Tue May 22 09:56:36 2001
From: joe@magiclantern.co.uk (Joe Ditoro)
Date: Tue, 22 May 2001 09:56:36 +0100
Subject: [Tutor] on line courses?
Message-ID: <E1FFCDB218D0D411A13B00010212DB418DF3@animal.magiclantern.co.uk>

I know there are lots of tutorials out there and I have done a few of them
already, but I was wondering if there are on-line courses that are taught by
humans.  Something with tasks, home work, and some direction.

If you know of anything, please let me know,

thanksm

joe


From scarblac@pino.selwerd.nl  Tue May 22 10:01:34 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 22 May 2001 11:01:34 +0200
Subject: [Tutor] operator and function call
In-Reply-To: <050701c0e29c$6d04f1b0$37ef87c0@ppathiyipc>; from ppathiyi@cisco.com on Tue, May 22, 2001 at 02:21:43PM +0530
References: <050701c0e29c$6d04f1b0$37ef87c0@ppathiyipc>
Message-ID: <20010522110134.A19943@pino.selwerd.nl>

On  0, Praveen Pathiyil <ppathiyi@cisco.com> wrote:
> What is the rationale in implementing some functionalities both as an operator and as a function call ?
> 
> E.g: 2 raised to the power of 3 can be computed as 
> 
> 2 ** 3 and as pow(2,3)
> 
> Similarly a - b and operator.sub(a,b)
> 
> Any specific reasons for such an approach ?

Useful in practice?

In expressions you want to be able to write it using the operator, because
it's shorter easier to read.

But sometimes you want to pass around functions to other functions, and
though you could always write sub out yourself (sub = lambda x, y: x-y), the
existing ones in operator are faster because they're in C. You may want to
subtract all elements in list M from list L, for instance: 
map(operator.sub, L, M).

Also, the builtin pow() takes an optional third argument that the operator
can't take (and that I've never used, but that's something else...).

Why there is both a builtin pow() and a math.pow() with slightly different
behavior is a mystery. It probably just turned out that way.

-- 
Remco Gerlich


From tutor@python.org  Tue May 22 11:28:36 2001
From: tutor@python.org (Tim Peters)
Date: Tue, 22 May 2001 06:28:36 -0400
Subject: [Tutor] operator and function call
In-Reply-To: <050701c0e29c$6d04f1b0$37ef87c0@ppathiyipc>
Message-ID: <LNBBLJKPBEHFEDALKOLCCELHKDAA.tim.one@home.com>

[Praveen Pathiyil]
> What is the rationale in implementing some functionalities both as
> an operator and as a function call ?

It varies from case to case.

> E.g: 2 raised to the power of 3 can be computed as
> 2 ** 3 and as pow(2,3)

2**3 is preferred.  The primary use for the pow() function is the
three-argument form pow(a, b, c), which computes (a**b) % c but very much
faster than the latter when b is large and c is small.  "modular pow" is an
important operation in, for example, number theory and cryptography.

You're also missing math.pow(), which is yet a third version of pow.  It's
not like either of the others, but the difference is subtle (math.pow() does
exactly whatever the function named "pow" in your local C library does).

> Similarly a - b and operator.sub(a,b)

Different case entirely.  a-b is preferred.  The operator module is rarely
used and you can safely ignore it for the rest of your life <wink>.  If you
ever *wanted* to, say, pass a two-argument subtraction function as an
argument to another routine, then

    another_routine(a-b)

would pass the *result* of a-b, but

    another_routine(operator.sub)

does the right thing and runs faster than the equivalent

    def sub(a, b):
        return a - b

    another_routine(sub)

This is rarely important; the operator module exists for the benefit of the
few applications where it is important.

> Any specific reasons for such an approach ?

There are always reasons, but not always compelling reasons.  The answers
aren't usually exciting <wink>.



From patrick@kirks.net  Tue May 22 11:34:32 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 11:34:32 +0100
Subject: [Tutor] on line courses?
References: <E1FFCDB218D0D411A13B00010212DB418DF3@animal.magiclantern.co.uk>
Message-ID: <001501c0e2aa$ca01fee0$1900a8c0@pod>

Its a good question.  I'm doing the two online tutorials and finding that I
need to find some practical applications to use the ideas before I lose
them.  Perhaps a homework type section to try out the ideas is in
order...I'll keep anything I come up with and send to Alan Gauld.



From robnospam@jam.rr.com  Tue May 22 12:04:11 2001
From: robnospam@jam.rr.com (Rob Andrews)
Date: Tue, 22 May 2001 06:04:11 -0500
Subject: [Tutor] on line courses?
References: <E1FFCDB218D0D411A13B00010212DB418DF3@animal.magiclantern.co.uk> <001501c0e2aa$ca01fee0$1900a8c0@pod>
Message-ID: <3B0A47AB.9FC8FEAB@jam.rr.com>

In case this sounds like a shameless plug, it really isn't intended to
be one. But having said that, have you looked at Useless Python for
this? There are quite a few (about 60, not including the programming
contest scripts) Python apps that range from the quick and the silly to
the considerably more interesting. And they are all there for you to
tinker with.

A few times already someone has sent in different approaches to doing
the same thing, added increased functionality to someone else's code,
etc. I know it's not quite an on-line course, but you can work with
these (mostly contributed by members of this list) and ask questions to
the list about what you are trying to do.

Rob

Patrick Kirk wrote:
> 
> Its a good question.  I'm doing the two online tutorials and finding that I
> need to find some practical applications to use the ideas before I lose
> them.  Perhaps a homework type section to try out the ideas is in
> order...I'll keep anything I come up with and send to Alan Gauld.
> 

-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From vishnja@web.de  Tue May 22 12:11:07 2001
From: vishnja@web.de (Kathrin Kirsch)
Date: Tue, 22 May 2001 13:11:07 +0200
Subject: [Tutor] logical oprators and REs
Message-ID: <01d901c0e2af$edb6aca0$ad85fea9@vishnja>

Hi List,

being a newbie to programming (well, I worked myself through Ian van
Laninghams tutorial...) I'm just stucked with  the problem translating the
logical operators "AND" , "OR" and "NOT" into regular expressions.
The result shouldt be something like a search engine: the user shouldt be
able to combine those operators.. and this is where I'm stucked.
Untill now the code looks like:

"def suchwas(spr1, spr2, such):
    done=0

    if done == 0:
        such1 = string.split (such, "OR")
        if len(such1) > 1:
            done = 1
            if ganzeswort== 'ja':
# ganzeswort and grossklein are radiobuttons (options, whether to match
whole

# words and capitals)
                such = '(\\b' + such1[0] + '\\b|\\b' + such1[1] + '\\b)'
            else:
                such = string.replace(such, ' OR ', '|')

    if done == 0:
        such2 = string.split (such, "AND")
        if len(such2) > 1:
            done = 1
            if ganzeswort == 'ja':
                such = '((\\b' + such2[0] + '\\b.*\\b' + such2[1] +
'\\b)|(\\b' + such2[1] + '\\b.*' + '\\b' + such2[0] + '\\b))'
            else:
                such = '((' + such2[0] + '.*' + such2[1] + ')|(' + such2[1]
+ '.*' + such2[0] + '))'

    if done == 0:
        if ganzeswort == 'ja':
            such = '\\b' + such + '\\b'
        else:
            such = such


    if grossklein == 'nein':
        muster = re.compile(such, re.L | re.I)
    else:
        muster = re.compile(such, re.L)

    resultat  = []
"

So, how "AND" and "OR"(and "NOT") couldt be combined in one search?
I heard, that in Perl exists a parser like Yacc. Is there something like
that for Python? Or : are there solutions for that problem already?

Kathrin.



From toodles@yifan.net  Tue May 22 13:40:10 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Tue, 22 May 2001 20:40:10 +0800
Subject: [Tutor] on line courses?
In-Reply-To: <3B0A47AB.9FC8FEAB@jam.rr.com>
Message-ID: <FPEHJJPEEOIPMAHOADBKOEKBCDAA.toodles@yifan.net>

I'm backing this plug!
As programming is a hobby for me, not an occupation (well maybe when I'm all
grown up!) I sometimes lack ideas of what to program. When the Useless
Challenges came to Useless Python pages, some of them I found quite
interesting, and a good way to learn python. In fact, I'm currently learning
XML and python at the same time with one of the challenges =)

So...it might be a good idea to give it a go, if you want some practical
application!

Useless Challenges:
http://www.lowerstandard.com/python/UselessIdeas.html

Andrew Wilkins

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Rob Andrews
> Sent: Tuesday, 22 May 2001 7:04 PM
> To: Patrick Kirk
> Cc: Joe Ditoro; tutor@python.org
> Subject: Re: [Tutor] on line courses?
>
>
> In case this sounds like a shameless plug, it really isn't intended to
> be one. But having said that, have you looked at Useless Python for
> this? There are quite a few (about 60, not including the programming
> contest scripts) Python apps that range from the quick and the silly to
> the considerably more interesting. And they are all there for you to
> tinker with.
>
> A few times already someone has sent in different approaches to doing
> the same thing, added increased functionality to someone else's code,
> etc. I know it's not quite an on-line course, but you can work with
> these (mostly contributed by members of this list) and ask questions to
> the list about what you are trying to do.
>
> Rob
>
> Patrick Kirk wrote:
> >
> > Its a good question.  I'm doing the two online tutorials and
> finding that I
> > need to find some practical applications to use the ideas before I lose
> > them.  Perhaps a homework type section to try out the ideas is in
> > order...I'll keep anything I come up with and send to Alan Gauld.
> >
>
> --
>
> You should have listened when your mother warned you about
> Useless Python!
> http://www.lowerstandard.com/python/pythonsource.html
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From patrick@kirks.net  Tue May 22 13:48:34 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 13:48:34 +0100
Subject: [Tutor] on line courses?
References: <FPEHJJPEEOIPMAHOADBKOEKBCDAA.toodles@yifan.net>
Message-ID: <00d701c0e2bd$83cbed10$1900a8c0@pod>

Has anyone started the chat application?  It sounds like a very tough
challenge for a newbie.

Is there a database to download for the database challenge?  It looks
do-able.



From kalle@gnupung.net  Tue May 22 13:53:50 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Tue, 22 May 2001 14:53:50 +0200
Subject: [Tutor] on line courses?
In-Reply-To: <FPEHJJPEEOIPMAHOADBKOEKBCDAA.toodles@yifan.net>; from toodles@yifan.net on Tue, May 22, 2001 at 08:40:10PM +0800
References: <3B0A47AB.9FC8FEAB@jam.rr.com> <FPEHJJPEEOIPMAHOADBKOEKBCDAA.toodles@yifan.net>
Message-ID: <20010522145350.A10432@father>

Sez Andrew Wilkins:
> [Rob Andrews]
> > Patrick Kirk wrote:
> > >
> > > Its a good question.  I'm doing the two online tutorials and
> > finding that I
> > > need to find some practical applications to use the ideas before I lose
> > > them.  Perhaps a homework type section to try out the ideas is in
> > > order...I'll keep anything I come up with and send to Alan Gauld.
> > 
> > In case this sounds like a shameless plug, it really isn't intended to
> > be one. But having said that, have you looked at Useless Python for
> > this?
> 
> I'm backing this plug!

+1

<grumble>
I would also like to add that y'all would make my life much more comfortable
if you wrote your answers after the relevant piece of the quoted message
instead of writing your message first and then including the entire previous
conversation below!  But perhaps it's penance for my sins.
</grumble>

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From ryanbooz@alumni.psu.edu  Tue May 22 13:58:15 2001
From: ryanbooz@alumni.psu.edu (Ryan Booz)
Date: Tue, 22 May 2001 08:58:15 -0400
Subject: [Tutor] Getting info from Toplevel() window?
Message-ID: <3B0A6267.9B261FD5@alumni.psu.edu>

I'm wondering if someone can help me with this question.  I have a
simple program that puts a Proverb in a small Tk window when students
log into the computers here at school.  I've been trying to add the
ability to let them add Proverbs of their own.  They hit a button that
brings up a second Toplevel() window which has three entry fields.  From
that window, they hit an "add" button that should write the proverb.
However, it does not grab the info out of the fields.  The separators I
used for the split function (to separate the chapter, verse, and
Proverb) gets written, so the function does work (mostly), but I can't
figure out how to get the info from the window!  Thanks a bunch.  Slowly
moving up the learning curve!

Ryan Booz
Tech Coordinator
Belleville Mennonite School

---------- Proverb.py ---------------
from random import randint
from string import *
import string
from Tkinter import *

def split(proverb):
        if proverb[-1]=="\012":
                proverb=proverb[:-1]
        else:
                proverb=proverb

        x=len(proverb)/2

        while proverb[x]!=" ":
                x=x+1
        else:
                x=x

        daily_prov=proverb[:x]+"\n"+"\t"+proverb[x+1:]
        return daily_prov

def add_prov():

        add_window=Toplevel(main)

        add_frame1=Frame(add_window,relief=SUNKEN,border=0)
        add_frame1.pack(side=TOP,fill=BOTH)

        add_frame2=Frame(add_window,relief=SUNKEN,border=0)
        add_frame2.pack(side=TOP,fill=BOTH)

        add_frame3=Frame(add_window,relief=SUNKEN,border=0)
        add_frame3.pack(side=TOP,fill=BOTH)

        add_entry=Entry(add_frame1,textvariable=typed_entry,fg="black")
        add_entry.pack(side=LEFT,fill=BOTH,expand=1)

        chapter_label=Label(add_frame2,text="Chapter")
        chapter_label.pack(side=LEFT,fill=BOTH)

        chapter_entry=Entry(add_frame2,textvariable=chap)
        chapter_entry.pack(side=LEFT,fill=BOTH)

        verse_label=Label(add_frame2,text="Verse(s)")
        verse_label.pack(side=LEFT,fill=BOTH)

        verse_entry=Entry(add_frame2,textvariable=ver)
        verse_entry.pack(side=LEFT,fill=BOTH)

        add_proverb=Button(add_frame3,text="Add a
Proverb",font=("Arial",8),command= lambda
chap=chapter_entry.get(),ver=verse_entry.get(),proverb=add_entry.get():
write_prov(chap,ver,proverb))
        add_proverb.pack(side=LEFT,fill=BOTH,expand=1)

def write_prov(chapter,verse,proverb):

        new=open("new.txt",'a+')
#        print chapter
#         print proverb
#        proverb=add_entry.get()
#     chapter=chapter_entry.get()
#        verse=verse_entry.get()
        print chapter
        new.write("\n" + chapter + "*" + verse + "*" + proverb)
        typed_entry.set("")
        chap.set("")
        ver.set("")
        new.close()

def get_prov():
        new_file=open("new.txt",'r+')
        new_list=new_file.readlines()
        total_prov=len(new_list)
        x=randint(0,total_prov-1)
        daily_prov=new_list[x]
        daily_prov=string.split(daily_prov,"*")
        chap=daily_prov[0]
        ver=daily_prov[1]
        daily_prov=split(daily_prov[2])

        new_file.close()
        return chap,ver,daily_prov

def change_prov():
        new_file=open("new.txt",'r+')
        new_list=new_file.readlines()
        total_prov=len(new_list)
        x=randint(0,total_prov-1)
        daily_prov=new_list[x]
        daily_prov=string.split(daily_prov,"*")
        chap=daily_prov[0]
        ver=daily_prov[1]
        daily_proverb=split(daily_prov[2])

        proverb.config(text=daily_proverb+"\n"+"Proverb"+"
"+chap+":"+ver)
        new_file.close()


#-----This is the start of the program ----------#

chap,ver,daily_proverb=get_prov()

main=Tk()
main.title("BMS Proverb of the Day")
#main.geometry('200x160')

outer_frame=Frame(main,relief=SUNKEN,border=0)
outer_frame.pack(fill=BOTH,expand=1)

top_frame=Frame(outer_frame,relief=SUNKEN,border=0)
top_frame.pack(side=TOP,fill=BOTH)

middle_frame=Frame(outer_frame,relief=SUNKEN,border=0)
middle_frame.pack(side=TOP,fill=BOTH)

middle_frame2=Frame(outer_frame,relief=SUNKEN,border=0)
middle_frame2.pack(side=TOP,fill=BOTH)

bottom_frame=Frame(outer_frame,relief=SUNKEN,border=0)
bottom_frame.pack(side=TOP,fill=BOTH)

proverb=Label(top_frame,text=daily_proverb+"\n"+"Proverb"+"
"+chap+":"+ver,fg="blue",bg="white",height=3,font=("Arial",10,"bold"))
proverb.pack(fill=BOTH,expand=1)

typed_entry=StringVar()
chap=StringVar()
ver=StringVar()

change_proverb=Button(bottom_frame,text="Give me a new
Proverb",fg="blue",command=change_prov)
change_proverb.pack(side=LEFT,fill=BOTH,expand=1)

add_proverb=Button(bottom_frame,text="Add Proverb",command=add_prov)
add_proverb.pack(side=LEFT)

quit=Button(bottom_frame,text="Quit",command=main.quit)
quit.pack(side=LEFT,fill=BOTH,expand=1)

mainloop()



From randrews@planhouse.com  Tue May 22 14:46:44 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Tue, 22 May 2001 08:46:44 -0500
Subject: [Tutor] on line courses?
In-Reply-To: <20010522145350.A10432@father>
Message-ID: <000a01c0e2c5$a3f12b20$de00a8c0@planhouse5>

3;-><grumble>
3;->I would also like to add that y'all would make my life much
3;->more comfortable
3;->if you wrote your answers after the relevant piece of the
3;->quoted message
3;->instead of writing your message first and then including
3;->the entire previous
3;->conversation below!  But perhaps it's penance for my sins.
3;-></grumble>

It seems like a valid grumble. For the life of me, I don't seem able to
figure out how to set Outlook 2000 (which we must use at the office as
penance for my own sins) to exhibit the proper default behavior. But I'll
make efforts to ease your suffering by contributing to it less.

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html



From bdupire@seatech.fau.edu  Tue May 22 14:54:21 2001
From: bdupire@seatech.fau.edu (Benoit Dupire)
Date: Tue, 22 May 2001 09:54:21 -0400
Subject: [Tutor] on line courses?
References: <E1FFCDB218D0D411A13B00010212DB418DF3@animal.magiclantern.co.uk>
Message-ID: <3B0A6F8D.45F78157@seatech.fau.edu>

I exactly have the opposite problem.. I usually have ideas but SSSOOOOO little
time to do them.... :o)

What about doing a program which changes the WallPaper of your computer ?
-every time you turn it on ..
- or every day (in case you rarely turn off your PC)

This issue might be Platform-dependant, so a good starting point is to do a big
'if .. elif' case (or a strategy pattern  or whatever what would do the trick)

The program should detect all the images in a particular directory, or you can
just specify the root directory where the program has to fetch the images ( then
it walks through the subdirectories... )

Then you can enhance the program with a GUI.... something to preview the
images..

Maybe this has already been done, i don't know....

Benoit

Joe Ditoro wrote:

> I know there are lots of tutorials out there and I have done a few of them
> already, but I was wondering if there are on-line courses that are taught by
> humans.  Something with tasks, home work, and some direction.
>
> If you know of anything, please let me know,
>
> thanksm
>
> joe
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From patrick@kirks.net  Tue May 22 15:08:53 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 15:08:53 +0100
Subject: [Tutor] PythonWin
Message-ID: <003d01c0e2c8$bbf4e7e0$1900a8c0@pod>

Does anyone know a working URL to download PythonWin?  All the ones I've
tried on python.org are broken as are the mirrirs found via Google.
--
Patrick Kirk
GSM: +44 7712 184 480
ICQ: 42219699

Wise Chinese Proverb:  "If tired of computer winning at real time strategy
games, try it at kick-boxing instead"



From arcege@speakeasy.net  Tue May 22 15:09:18 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Tue, 22 May 2001 10:09:18 -0400 (EDT)
Subject: [Tutor] Getting info from Toplevel() window?
In-Reply-To: <3B0A6267.9B261FD5@alumni.psu.edu> from "Ryan Booz" at May 22, 2001 08:58:15 AM
Message-ID: <200105221409.f4ME9IG02090@dsl092-074-184.bos1.dsl.speakeasy.net>

Ryan Booz wrote
> 
> I'm wondering if someone can help me with this question.  I have a
> simple program that puts a Proverb in a small Tk window when students
> log into the computers here at school.  I've been trying to add the
> ability to let them add Proverbs of their own.  They hit a button that
> brings up a second Toplevel() window which has three entry fields.  From
> that window, they hit an "add" button that should write the proverb.
> However, it does not grab the info out of the fields.  The separators I
> used for the split function (to separate the chapter, verse, and
> Proverb) gets written, so the function does work (mostly), but I can't
> figure out how to get the info from the window!  Thanks a bunch.  Slowly
> moving up the learning curve!

In your lambda, you are passing the result of the "get" methods of
the entry widgets.  Instead you will want to just pass the
widgets themselves and call get in the write_prov function.  The
problem is that calling the get() methods when the button is created
means that the entry widgets are empty, and the values will be empty
strings.  If you wait until the write_prov function, then the button
has been pressed and the entry widgets have (supposedly) been filled
out.

def add_prov():
  ...
  # at this point, the widgets are being created and the user has not
  # had time to enter values yet
  add_proverb = Button(add_frame3, text="Add a Proverb", font=("Arial", 8),
    command=lambda chap=chapter_entry, ver=vers_entry, proverb=add_entry:
      write_prov(chap, ver, proverb)
  )
def write_prov(chap, ver, proverb):
  # get the values after the button has been pressed
  chap = chap.get()
  ver = ver.get()
  proverb = proverb.get()
  ...

Another take on it is to have the button widget destroy the toplevel
widget, and to wait for that to happen.

def add_prov():
  add_window = Toplevel()
  ...
  add_proverb = Button(add_frame3, text="Add a Proverb", font=("Arial", 8),
    command=add_window.destroy)
  add_proverb.pack(side=LEFT, fill=BOTH, expand=1)
  add_window.wait_window()  # wait until destroyed
  write_prov(
    chapter_entry.get(),
    verse_entry.get(),
    add_entry.get()
  )

Or, to create a new event loop for just this (which is how some dialogs
work).

def add_prov():
  add_window = Toplevel()
  ...
  add_proverb = Button(add_frame3, ..., add_window.quit)
  add_proverb.pack(...)
  add_window.mainloop()
  write_prov(...)

Good luck,
  -Arcege

> ---------- Proverb.py ---------------
> from random import randint
> from string import *
> import string
> from Tkinter import *
> 
> def split(proverb):
>         if proverb[-1]=="\012":
>                 proverb=proverb[:-1]
>         else:
>                 proverb=proverb
> 
>         x=len(proverb)/2
> 
>         while proverb[x]!=" ":
>                 x=x+1
>         else:
>                 x=x
> 
>         daily_prov=proverb[:x]+"\n"+"\t"+proverb[x+1:]
>         return daily_prov
> 
> def add_prov():
> 
>         add_window=Toplevel(main)
> 
>         add_frame1=Frame(add_window,relief=SUNKEN,border=0)
>         add_frame1.pack(side=TOP,fill=BOTH)
> 
>         add_frame2=Frame(add_window,relief=SUNKEN,border=0)
>         add_frame2.pack(side=TOP,fill=BOTH)
> 
>         add_frame3=Frame(add_window,relief=SUNKEN,border=0)
>         add_frame3.pack(side=TOP,fill=BOTH)
> 
>         add_entry=Entry(add_frame1,textvariable=typed_entry,fg="black")
>         add_entry.pack(side=LEFT,fill=BOTH,expand=1)
> 
>         chapter_label=Label(add_frame2,text="Chapter")
>         chapter_label.pack(side=LEFT,fill=BOTH)
> 
>         chapter_entry=Entry(add_frame2,textvariable=chap)
>         chapter_entry.pack(side=LEFT,fill=BOTH)
> 
>         verse_label=Label(add_frame2,text="Verse(s)")
>         verse_label.pack(side=LEFT,fill=BOTH)
> 
>         verse_entry=Entry(add_frame2,textvariable=ver)
>         verse_entry.pack(side=LEFT,fill=BOTH)
> 
>         add_proverb=Button(add_frame3,text="Add a
> Proverb",font=("Arial",8),command= lambda
> chap=chapter_entry.get(),ver=verse_entry.get(),proverb=add_entry.get():
> write_prov(chap,ver,proverb))
>         add_proverb.pack(side=LEFT,fill=BOTH,expand=1)
> 
> def write_prov(chapter,verse,proverb):



From randrews@planhouse.com  Tue May 22 15:30:16 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Tue, 22 May 2001 09:30:16 -0500
Subject: [Tutor] PythonWin
In-Reply-To: <003d01c0e2c8$bbf4e7e0$1900a8c0@pod>
Message-ID: <000c01c0e2cb$b8bce700$de00a8c0@planhouse5>

3;-> Does anyone know a working URL to download PythonWin?  All
3;-> the ones I've
3;-> tried on python.org are broken as are the mirrirs found via Google.
3;-> --

Have you checked out this one? It's the ActiveState Python distro, which
includes PythonWin.

http://aspn.activestate.com/ASPN/Downloads/ActivePython/More

It's a bit more than you asked for, but I've used it before and think it's
pretty decent.

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html



From SBrunning@trisystems.co.uk  Tue May 22 15:27:52 2001
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Tue, 22 May 2001 15:27:52 +0100
Subject: [Tutor] PythonWin
Message-ID: <31575A892FF6D1118F5800600846864D78BC59@intrepid>

> Does anyone know a working URL to download PythonWin?  All the ones I've
> tried on python.org are broken as are the mirrirs found via Google.
 
Try
<http://aspn.activestate.com/ASPN/Downloads/ActivePython/Extensions/Win32all
>

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 karimy@nipltd.com  Tue May 22 15:31:08 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Tue, 22 May 2001 15:31:08 +0100
Subject: [Tutor] PythonWin
References: <003d01c0e2c8$bbf4e7e0$1900a8c0@pod>
Message-ID: <010a01c0e2cb$d83ba580$a5020a0a@private.nipltd.com>

Patrick,
Have you tried Active State page?
http://aspn.activestate.com/ASPN/Downloads/ActivePython/...however, with
this package, you'll get more than an IDE ; -)

Hope it helps,

Cheers
Karim
----- Original Message -----
From: "Patrick Kirk" <patrick@kirks.net>
To: "Python Tutors" <tutor@python.org>
Sent: Tuesday, May 22, 2001 3:08 PM
Subject: [Tutor] PythonWin


> Does anyone know a working URL to download PythonWin?  All the ones I've
> tried on python.org are broken as are the mirrirs found via Google.
> --
> Patrick Kirk
> GSM: +44 7712 184 480
> ICQ: 42219699
>
> Wise Chinese Proverb:  "If tired of computer winning at real time strategy
> games, try it at kick-boxing instead"
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From patrick@kirks.net  Tue May 22 15:39:40 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 15:39:40 +0100
Subject: [Tutor] PythonWin
References: <31575A892FF6D1118F5800600846864D78BC59@intrepid>
Message-ID: <00f201c0e2cd$08a7c680$1900a8c0@pod>

Thanks all!



From gwperry@tva.gov  Tue May 22 17:13:23 2001
From: gwperry@tva.gov (Perry, George W.)
Date: Tue, 22 May 2001 12:13:23 -0400
Subject: [Tutor] Accessing Access
Message-ID: <DF936EB98CCBD4118EC500508BCFE69A0C0A1D@tvachaxch1.cha.tva.gov>

What would be the general approach to extract data from a Microsoft Access
database? I.e. what module should be used? I am running the Python 2.1 for
Windows available from www.python.org.

Thanks
George Perry



From rob@jam.rr.com  Tue May 22 17:27:29 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Tue, 22 May 2001 11:27:29 -0500
Subject: [Tutor] Accessing Access
References: <DF936EB98CCBD4118EC500508BCFE69A0C0A1D@tvachaxch1.cha.tva.gov>
Message-ID: <003e01c0e2dc$18987120$de00a8c0@planhouse5>

> What would be the general approach to extract data from a Microsoft Access
> database? I.e. what module should be used? I am running the Python 2.1 for
> Windows available from www.python.org.
>

I have yet to find one, but ohhhh how I could use one if it exists.

Rob



From scarblac@pino.selwerd.nl  Tue May 22 17:26:57 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 22 May 2001 18:26:57 +0200
Subject: [Tutor] Accessing Access
In-Reply-To: <DF936EB98CCBD4118EC500508BCFE69A0C0A1D@tvachaxch1.cha.tva.gov>; from gwperry@tva.gov on Tue, May 22, 2001 at 12:13:23PM -0400
References: <DF936EB98CCBD4118EC500508BCFE69A0C0A1D@tvachaxch1.cha.tva.gov>
Message-ID: <20010522182657.A20625@pino.selwerd.nl>

On  0, "Perry, George W." <gwperry@tva.gov> wrote:
> What would be the general approach to extract data from a Microsoft Access
> database? I.e. what module should be used? I am running the Python 2.1 for
> Windows available from www.python.org.

You need the Windows extension modules, win32all, from
http://aspn.activestate.com/ASPN/Downloads/ActivePython/Extensions/Win32all

Then someone has written a small page for using Python with Access, see
http://starship.python.net/crew/bwilk/access.html

You probably want to buy the book "Python Programming on Win32" to learn
more about COM and Python.

I don't know more, I don't do Windows...

-- 
Remco Gerlich


From kauphlyn@speakeasy.org  Tue May 22 17:31:42 2001
From: kauphlyn@speakeasy.org (Daniel Coughlin)
Date: Tue, 22 May 2001 09:31:42 -0700 (PDT)
Subject: [Tutor] Accessing Access
In-Reply-To: <003e01c0e2dc$18987120$de00a8c0@planhouse5>
Message-ID: <Pine.LNX.4.33L2.0105220929060.13473-100000@grace.speakeasy.net>

The ODBC module is a good place to start.

http://www.python.org/windows/win32/odbc.html

Hope this helps.

Daniel


On Tue, 22 May 2001, Rob Andrews wrote:

> > What would be the general approach to extract data from a Microsoft Access
> > database? I.e. what module should be used? I am running the Python 2.1 for
> > Windows available from www.python.org.
> >
>
> I have yet to find one, but ohhhh how I could use one if it exists.
>
> Rob
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From patrick@kirks.net  Tue May 22 17:33:37 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 17:33:37 +0100
Subject: [Tutor] Joy of PythonWin
Message-ID: <015501c0e2dc$f42fcdf0$1900a8c0@pod>

Hi all

Got Pythonwin working and I keep pressing uparrow to access previous
commands the way you do in the bash shell or in a command box.

Should I get used to this or am I better off ssh-ing into a Linux box?  The
Debian box I ssh into seems to offer all the comfort of a bash shell but
obviously no GUI nor Win32 stuff.  Can any of this command line comfort be
brought into Pythonwin?

My programming environment is most likely to be Win2k.
--
Patrick Kirk
GSM: +44 7712 184 480
ICQ: 42219699

Wise Chinese Proverb:  "If tired of computer winning at real time strategy
games, try it at kick-boxing instead"



From SBrunning@trisystems.co.uk  Tue May 22 17:38:06 2001
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Tue, 22 May 2001 17:38:06 +0100
Subject: [Tutor] Joy of PythonWin
Message-ID: <31575A892FF6D1118F5800600846864D78BC5E@intrepid>

> From:	Patrick Kirk [SMTP:patrick@kirks.net]
> Got Pythonwin working and I keep pressing uparrow to access previous
> commands the way you do in the bash shell or in a command box.
 
Ctrl-up arrow retrieves previous commands.

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 patrick@kirks.net  Tue May 22 17:49:43 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 17:49:43 +0100
Subject: [Tutor] Joy of PythonWin
References: <31575A892FF6D1118F5800600846864D78BC5E@intrepid>
Message-ID: <016601c0e2df$33b8fe40$1900a8c0@pod>

Sorry.  Not for me it doesn't.  Uparrow takes me up a line.  How strange and
illogical can you get?



From SBrunning@trisystems.co.uk  Tue May 22 17:52:43 2001
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Tue, 22 May 2001 17:52:43 +0100
Subject: [Tutor] Joy of PythonWin
Message-ID: <31575A892FF6D1118F5800600846864D78BC5F@intrepid>

> Sorry.  Not for me it doesn't.  Uparrow takes me up a line.  How strange
> and
> illogical can you get?
 
*Ctrl*-up-arrow, not just up-arrow. See the PythonWin reference (from the
help menu), which includes a full list of keyboard shortcuts.

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 dsh8290@rit.edu  Tue May 22 18:37:55 2001
From: dsh8290@rit.edu (D-Man)
Date: Tue, 22 May 2001 13:37:55 -0400
Subject: [Tutor] Joy of PythonWin
In-Reply-To: <015501c0e2dc$f42fcdf0$1900a8c0@pod>; from patrick@kirks.net on Tue, May 22, 2001 at 05:33:37PM +0100
References: <015501c0e2dc$f42fcdf0$1900a8c0@pod>
Message-ID: <20010522133755.B20783@harmony.cs.rit.edu>

On Tue, May 22, 2001 at 05:33:37PM +0100, Patrick Kirk wrote:
| Should I get used to this or am I better off ssh-ing into a Linux box?  The
| Debian box I ssh into seems to offer all the comfort of a bash shell but
| obviously no GUI nor Win32 stuff.  Can any of this command line comfort be
| brought into Pythonwin?

I don't use an IDE (I prefer gvim and some xterms).  On Unix and on
Windows with Cgywin (version 2.1) the interactive python interpreter
has support for the GNU readline library.  This is the same library
that bash uses for it's input.  To get that sort of functionality you
need a python interpreter with readline support.  Then see the man
page for inputrc -- ~/.inputrc is the config file for readline.  A
little while back someome posted a description of how to get
commandline history, tab completion, and vi-style line editing
commands.  It is all done through readline and the .inputrc file.  I
don't know if PythonWin will work with the cygwin-enabled interpreter
or if it needs it's own modified interpreter.

In case you aren't familiar with cygwin it is a POSIX emulation layer
on top of the win32 API.  See sources.redhat.com for more information.
IMO windows isn't usable without a proper cygwin installation.


Of course, if you have access to a Linux system, you could enable X
forwarding over ssh and get an X server for Windows.  Then you could
remotely use any *nix gui tool.

-D



From ffrt@ace.ulyssis.org  Tue May 22 19:41:14 2001
From: ffrt@ace.ulyssis.org (ffrt)
Date: Tue, 22 May 2001 20:41:14 +0200 (CEST)
Subject: [Tutor] Python and PostgreSQL?
Message-ID: <Pine.LNX.4.33.0105222038290.17257-100000@ace>

Hi all,

I'm currently working on a program that is supposed to generate some
Prolog code for data mining, based on a PostgreSQL database. Only recently
I discovered about the possibilities of Pyhton - and my question is
simple: how about interfacing between PostgreSQL and Python? I know it
should be possible (because of C-embeddability), but is it a good idea?

Thanks.

-- 
ffrt (pgp public key on simple request)
Key fingerprint: FE F8 D4 63 A5 93 98 80  AC 7F 95 C1 85 6E 39 53



From scarblac@pino.selwerd.nl  Tue May 22 19:50:46 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 22 May 2001 20:50:46 +0200
Subject: [Tutor] Python and PostgreSQL?
In-Reply-To: <Pine.LNX.4.33.0105222038290.17257-100000@ace>; from ffrt@ace.ulyssis.org on Tue, May 22, 2001 at 08:41:14PM +0200
References: <Pine.LNX.4.33.0105222038290.17257-100000@ace>
Message-ID: <20010522205046.A20895@pino.selwerd.nl>

On  0, ffrt <ffrt@ace.ulyssis.org> wrote:
> I'm currently working on a program that is supposed to generate some
> Prolog code for data mining, based on a PostgreSQL database. Only recently
> I discovered about the possibilities of Pyhton - and my question is
> simple: how about interfacing between PostgreSQL and Python? I know it
> should be possible (because of C-embeddability), but is it a good idea?

Don't see why not. Would depend on the rest of your system I suppose, I'm
not sure I've ever read something about connecting Python to a Prolog engine.

Plenty of things for PostgreSQL, see the Parnassus page:
http://www.vex.net/parnassus/apollo.py?find=postgresql

Play around and see how it goes, I'd say.

-- 
Remco Gerlich


From ium@micromuse.com  Tue May 22 19:58:53 2001
From: ium@micromuse.com (ibraheem umaru-mohammed)
Date: Tue, 22 May 2001 19:58:53 +0100
Subject: [Tutor] Joy of PythonWin
In-Reply-To: <20010522133755.B20783@harmony.cs.rit.edu>; from dsh8290@rit.edu on Tue, May 22, 2001 at 01:37:55PM -0400
References: <015501c0e2dc$f42fcdf0$1900a8c0@pod> <20010522133755.B20783@harmony.cs.rit.edu>
Message-ID: <20010522195853.A2230@micromuse.com>

[D-Man wrote...]
<snip>
-| I don't use an IDE (I prefer gvim and some xterms).  On Unix and on
-| Windows with Cgywin (version 2.1) the interactive python interpreter
-| has support for the GNU readline library.  This is the same library
-| that bash uses for it's input.  To get that sort of functionality you
-| need a python interpreter with readline support.  Then see the man
-| page for inputrc -- ~/.inputrc is the config file for readline.  A
-| little while back someome posted a description of how to get
-| commandline history, tab completion, and vi-style line editing
-| commands.  It is all done through readline and the .inputrc file.  I
-| don't know if PythonWin will work with the cygwin-enabled interpreter
-| or if it needs it's own modified interpreter.
-| 
</snip>

	>>> import rlcompleter
	>>> import readline
	>>> readline.parse_and_bind("tab: complete")

Kindest regards,

	--ibs.

-- 
Reality always seems harsher in the early morning.


From patrick@kirks.net  Tue May 22 20:21:18 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 20:21:18 +0100
Subject: [Tutor] Joy of PythonWin
References: <015501c0e2dc$f42fcdf0$1900a8c0@pod>
Message-ID: <002e01c0e2f4$608e73e0$1900a8c0@pod>

Thanks for pointing out Ctrl+UpArrow (twice!)




From patrick@kirks.net  Tue May 22 21:58:17 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 21:58:17 +0100
Subject: [Tutor] %d
Message-ID: <003e01c0e301$ed889e80$1900a8c0@pod>

In Alan Gauld's tutorial page 2 you suddenly move from gentle hand holding
to this:

>>>print "The sum of %d and %d is: %d" % (v,w,x)

v,w,x are variables and have integer values.  d is less clear.  And %?

I thought % was for the modulus function.  So what is that % doing in front
of d which I assume to be a built in variable?  And what is the % in front
of the curly brackets?

I generally keep going when I don't understand and the answer normally comes
from the context.

I've carried on through Alan's explanation of "for" and "while".  This is
easy to use and I need never memorise my 29 times tables but what is the %
before the curly brackets?  I'm in the position that I can do the
calculation but not clear on why I use this syntax until I understand that
%.

Sorry if this is a little less challenging than interfaces to
Postgres...give me another couple of weeks for that :-()  Meanwhile please
point me in the right direction.
--
Patrick Kirk
GSM: +44 7712 184 480
ICQ: 42219699




From m.hadfield@niwa.cri.nz  Tue May 22 22:16:48 2001
From: m.hadfield@niwa.cri.nz (Mark Hadfield)
Date: Wed, 23 May 2001 09:16:48 +1200
Subject: [Tutor] %d
References: <003e01c0e301$ed889e80$1900a8c0@pod>
Message-ID: <004c01c0e304$8347f7c0$d938a8c0@Hadfield>

From: "Patrick Kirk" <patrick@kirks.net>

>>>print "The sum of %d and %d is: %d" % (v,w,x)

> I thought % was for the modulus function.  So what is that % doing in
front
> of d which I assume to be a built in variable?  And what is the % in front
> of the curly brackets?

The %d etc are string-formatting specifiers. %d means "format the
corresponding value as an integer. The 3 %d's in the above example
correspond to the three variables, v, w, & x. It's the same style of
string-formatting as used by C's printf function. Because a lot of Python
programmers already know C, the documentation and tutorials assume that you
know what this means.

See

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

---
Mark Hadfield
m.hadfield@niwa.cri.nz  http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research



From dsh8290@rit.edu  Tue May 22 22:25:28 2001
From: dsh8290@rit.edu (D-Man)
Date: Tue, 22 May 2001 17:25:28 -0400
Subject: [Tutor] %d
In-Reply-To: <003e01c0e301$ed889e80$1900a8c0@pod>; from patrick@kirks.net on Tue, May 22, 2001 at 09:58:17PM +0100
References: <003e01c0e301$ed889e80$1900a8c0@pod>
Message-ID: <20010522172528.A21534@harmony.cs.rit.edu>

On Tue, May 22, 2001 at 09:58:17PM +0100, Patrick Kirk wrote:
| In Alan Gauld's tutorial page 2 you suddenly move from gentle hand holding
| to this:
| 
| >>>print "The sum of %d and %d is: %d" % (v,w,x)
| 
| v,w,x are variables and have integer values.  d is less clear.  And %?
| 
| I thought % was for the modulus function.  So what is that % doing in front
| of d which I assume to be a built in variable?  And what is the % in front
| of the curly brackets?

The % operator does several different things, depending on the
context.  It does modulo arithmatic if it is applied to integer
objects such as

print 5 % 2


If it is applied with a string as the left hand side it performs
string interpolation.  To understand string interpolation one must
become familiar with "format strings".  There is brief mention of
format strings in the documentation with regard to the print
statement.  It basically says that it behaves the same way C's printf
works.  (you can try reading 'man printf' if you have a Unix system
and want to see some terse documentation)  IIRC you have a book on
C++.  You should be able to find some info regarding printf/scanf and
format strings in there.  A _brief_ (and shallow) introduction follows
:


The '%d' construct you see isn't actually python code -- it is inside
a string.  This particular string is called a "format string" because
it contains markup that indicates how the text should be formatted.
Each markup code begins with a '%' sign such as '%d'.  The 'd'
indicates that the value provided (in python through the use of string
interpolation) should be formatted as an integer (decimal? digit?).
It will be right aligned and use only as much space as is needed for
all the digits.  A number can follow the % and precede the d to
specify how the text should be aligned.  For example :

%2d         Right aligned, 2 characters for field width 
%-2d        Left  aligned,  2 characters for field width
%10.1f      Right aligned float, 10 characters for field width, 1
                character for precision
%-10.1f     Left  aligned float, 10 characters for field width, 1
                character for precision
%x          A hexadecimal number
%#x         A hexadecimal number preceded by 0x, uses abcdef
%#X         A hexadecimal number preceded by 0X, uses ABCDEF
%s          A string


Here are a few examples :

>>> print "'%-10.1f'" % 987.65
'987.6     '
>>> print "'%10.1f'" % 987.65
'     987.6'
>>> print "'%x'" % 987
'3db'
>>> print "'%#x'" % 987
'0x3db'
>>> print "'%#X'" % 987
'0X3DB'
>>>



This might be too much information, but in Python string interpolation
can handle interpolating with a dict:

>>> d = { "first" : "Hello World" , "second" : "Python Is Cool" }
>>> print "First he said '%(first)s' then he said '%(second)s'" % d
First he said 'Hello World' then he said 'Python Is Cool'

The parenthesized text in between the '%' and the 's' is the key for
the dictionary.


HTH,
-D



From dyoo@hkn.eecs.berkeley.edu  Tue May 22 22:26:07 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 22 May 2001 14:26:07 -0700 (PDT)
Subject: [Tutor] %d
In-Reply-To: <003e01c0e301$ed889e80$1900a8c0@pod>
Message-ID: <Pine.LNX.4.21.0105221359540.1061-100000@hkn.eecs.berkeley.edu>

On Tue, 22 May 2001, Patrick Kirk wrote:

> In Alan Gauld's tutorial page 2 you suddenly move from gentle hand holding
> to this:
> 
> >>>print "The sum of %d and %d is: %d" % (v,w,x)
> 
> v,w,x are variables and have integer values.  d is less clear.  And %?
>
> I thought % was for the modulus function.  So what is that % doing in
> front of d which I assume to be a built in variable?  And what is the
> % in front of the curly brackets?

In this particular case, Python borrows some of the syntax of "formatted
strings" in C.  When we're using the '%' operator with strings, we're now
doing a string formatting operation instead of the modulus.

By string formatting, this means that everywhere you see '%d' in the
string, it will get replaced by the corresponding integer value in the
tuple.  For example, in the string:

    "The sum of %d and %d is: %d"

there are three '%d' parts, and each will be replaced by the values of v,
w, and x, respectively.  Think Mad Libs, and you'll have the general idea
of how string interpolation works.


You might wonder why we have this sort of stuff: this seems equivalent to
doing:

    "The sum of " + v + " and " + w + " is: " + x

and, in this case, we'll get a similar result.  The difference, though, is
that string formatting is generally easier to write, and less messy
looking.  Also, it gives us really fine control over the way we want our
strings to look.


For example, let's say that we're doing stuff with money.

###
>>> salary = 12345.29
>>> tax = salary * .14
>>> tax
1728.3406000000002
###

If we want to just print out tax as "1728.34", we can use a neat feature
of formatting:

###
>>> "%.2f" % tax
'1728.34'
###

which means, "We'll replace (interpolate) a floating point number where
'%.2f' appears, and this number will only have, at most, 2 decimal
places."  I'm using a "%f" thing, which formats a floating point value
into the string.


(Sometimes, string formatting is referred to as "interpolation", which is
sometimes why I'll slip and say "interpolation."  Habits are hard to
break.)

You can find out more about string formatting here:

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

Hope this helps!



From kstoner@netins.net  Tue May 22 22:37:39 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Tue, 22 May 2001 16:37:39 -0500
Subject: [Tutor] encryption
Message-ID: <001e01c0e307$6d546ea0$cd52b1cf@oemcomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_001B_01C0E2DD.83CEECC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi to all python people,

I am working on a very simple encryption program.  The program replaces =
all of the keys on the keyboard to numbers.  The problem is that I =
cannot get letters to be traded for the numbers very easily.  I can't =
get it to be put in a function so when I make the GUI for encryption and =
decription.  I also need to be able to transform a message into the =
numbers through a loop in the translation function.  It gives me an =
error when I try and use the function to change letters to numbers.  It =
says name is not defined.  If someone would tell me what is wrong with =
this function.  I need a new aproach.
-thanks
Cameron

Here is what I have so far:

def letters(ltter):
    if ltter =3D=3D ' ':
        print '~'
    if ltter =3D=3D '':
        print '`'
    if ltter =3D=3D 'A':
        print '1'
    if ltter =3D=3D 'B':
        print '2'
    if ltter =3D=3D 'C':
        print '3'
    if ltter =3D=3D 'D':
        print '4'
    if ltter =3D=3D 'E':
        print '5'
    if ltter =3D=3D 'F':
        print '6'
    if ltter =3D=3D 'G':
        print '7'
    if ltter =3D=3D 'H':
        print '8'
    if ltter =3D=3D 'I':
        print '9'
    if ltter =3D=3D 'J':
        print '10'
    if ltter =3D=3D 'K':
        print '11'
    if ltter =3D=3D 'L':
        print '12'
    if ltter =3D=3D 'M':
        print '13'
    if ltter =3D=3D 'N':
        print '14'
    if ltter =3D=3D 'O':
        print '15'
    if ltter =3D=3D 'P':
        print '16'
    if ltter =3D=3D 'Q':
        print '17'
    if ltter =3D=3D 'R':
        print '18'
    if ltter =3D=3D 'S':
        print '19'
    if ltter =3D=3D 'T':
        print '20'
    if ltter =3D=3D 'U':
        print '21'
    if ltter =3D=3D 'V':
        print '22'
    if ltter =3D=3D 'W':
        print '23'
    if ltter =3D=3D 'X':
        print '24'
    if ltter =3D=3D 'Y':
        print '25'
    if ltter =3D=3D 'Z':
        print '26'



------=_NextPart_000_001B_01C0E2DD.83CEECC0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi to all python people,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am working on a very simple =
encryption=20
program.&nbsp; The program replaces all of the keys on the keyboard to=20
numbers.&nbsp; The problem is that I cannot get letters to be traded for =
the=20
numbers very easily.&nbsp; I can't get it to be put in a function so =
when I make=20
the GUI for encryption and decription.&nbsp; I also need to be able to =
transform=20
a message into&nbsp;the numbers through a loop in the translation=20
function.&nbsp; It gives me an error when I try and use the function to =
change=20
letters to numbers.&nbsp; It says name is not defined.&nbsp; If someone =
would=20
tell me what is wrong with this function.&nbsp; I need a new=20
aproach.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>-thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Cameron</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is what I have so =
far:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def =
letters(ltter):<BR>&nbsp;&nbsp;&nbsp; if ltter=20
=3D=3D ' ':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'~'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'`'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'A':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'1'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'B':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'2'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'C':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'3'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'D':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'4'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'E':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'5'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'F':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'6'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'G':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'7'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'H':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'8'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'I':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'9'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'J':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'10'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'K':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'11'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'L':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'12'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'M':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'13'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'N':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'14'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'O':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'15'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'P':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'16'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'Q':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'17'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'R':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'18'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'S':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'19'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'T':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'20'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'U':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'21'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'V':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'22'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'W':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'23'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'X':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'24'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'Y':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
'25'<BR>&nbsp;&nbsp;&nbsp; if ltter =3D=3D=20
'Z':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =
'26'</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_001B_01C0E2DD.83CEECC0--



From patrick@kirks.net  Tue May 22 22:40:45 2001
From: patrick@kirks.net (Patrick Kirk)
Date: Tue, 22 May 2001 22:40:45 +0100
Subject: [Tutor] %d
References: <Pine.LNX.4.21.0105221359540.1061-100000@hkn.eecs.berkeley.edu>
Message-ID: <002201c0e307$dc00cc90$1900a8c0@pod>

Many thanks to all.  What I've learnt so far makes sense now.



From kauphlyn@speakeasy.org  Tue May 22 23:12:02 2001
From: kauphlyn@speakeasy.org (Daniel Coughlin)
Date: Tue, 22 May 2001 15:12:02 -0700 (PDT)
Subject: [Tutor] encryption
In-Reply-To: <001e01c0e307$6d546ea0$cd52b1cf@oemcomputer>
Message-ID: <Pine.LNX.4.33L2.0105221458290.22786-100000@grace.speakeasy.net>

First off i think using a dictionary would help you enormously:

dict = {'a':'1','b':'2' ... }

then your function could look something like this:

def letters(ltter):
	dict = {'a':'1','b':'2' ... }
	print dict[ltter]

then you could do your translation like this:

>c = 'aaabbb'
>for letter in c:
>	letters(letter)
1
1
1
2
2
2

or put the values where ever you need to. I think using a dictionary would be a
lot faster than using if statements.

On Tue, 22 May 2001, Katharine Stoner wrote:

> Hi to all python people,
>
> I am working on a very simple encryption program.  The program replaces all of the keys on the keyboard to numbers.  The problem is that I cannot get letters to be traded for the numbers very easily.  I can't get it to be put in a function so when I make the GUI for encryption and decription.  I also need to be able to transform a message into the numbers through a loop in the translation function.  It gives me an error when I try and use the function to change letters to numbers.  It says name is not defined.  If someone would tell me what is wrong with this function.  I need a new aproach.
> -thanks
> Cameron
>
> Here is what I have so far:
>
> def letters(ltter):
>     if ltter == ' ':
>         print '~'
>     if ltter == '':
>         print '`'
>     if ltter == 'A':
>         print '1'
>     if ltter == 'B':
>         print '2'
>     if ltter == 'C':
>         print '3'
>     if ltter == 'D':
>         print '4'
>     if ltter == 'E':
>         print '5'
>     if ltter == 'F':
>         print '6'
>     if ltter == 'G':
>         print '7'
>     if ltter == 'H':
>         print '8'
>     if ltter == 'I':
>         print '9'
>     if ltter == 'J':
>         print '10'
>     if ltter == 'K':
>         print '11'
>     if ltter == 'L':
>         print '12'
>     if ltter == 'M':
>         print '13'
>     if ltter == 'N':
>         print '14'
>     if ltter == 'O':
>         print '15'
>     if ltter == 'P':
>         print '16'
>     if ltter == 'Q':
>         print '17'
>     if ltter == 'R':
>         print '18'
>     if ltter == 'S':
>         print '19'
>     if ltter == 'T':
>         print '20'
>     if ltter == 'U':
>         print '21'
>     if ltter == 'V':
>         print '22'
>     if ltter == 'W':
>         print '23'
>     if ltter == 'X':
>         print '24'
>     if ltter == 'Y':
>         print '25'
>     if ltter == 'Z':
>         print '26'
>
>
>



From bsass@freenet.edmonton.ab.ca  Tue May 22 23:17:28 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Tue, 22 May 2001 16:17:28 -0600 (MDT)
Subject: ideas (was: Re: [Tutor] on line courses?)
In-Reply-To: <3B0A6F8D.45F78157@seatech.fau.edu>
Message-ID: <Pine.LNX.4.33.0105221554580.22858-100000@bms>

On Tue, 22 May 2001, Benoit Dupire wrote:
> I exactly have the opposite problem.. I usually have ideas but SSSOOOOO little
> time to do them.... :o)

ditto.  I tend to get them far enough along to explore what I was
interested in at the time, then get sidetracked with something else.

> What about doing a program which changes the WallPaper of your computer ?
> -every time you turn it on ..
> - or every day (in case you rarely turn off your PC)
>
> This issue might be Platform-dependant, so a good starting point is to do a big
> 'if .. elif' case (or a strategy pattern  or whatever what would do the trick)

`Desktop-dependent' would probably be a better term; on Linux, with
twm you could get away with just changing the root window's
background, with kde you would need to talk to the configuration
subsystem or the background(s) you set would not stick when you
switched to different workspaces.  (but I guess it just depends on how
you define "platform" <shrug>)

A monolithic solution would be too bloated with never-will-be-used
code, but a modular one could work...

> The program should detect all the images in a particular directory, or you can
> just specify the root directory where the program has to fetch the images ( then
> it walks through the subdirectories... )
>
> Then you can enhance the program with a GUI.... something to preview the
> images..

...would be the main piece.  Actually doing the setting of the
background would be in desktop-environment specific modules (kde,
gnome, X, win...), so you'll need an API so independent developers
(tutor subscribers looking for something to do) can work on the
modules easily.

Now, packaging up the result, that is platform&flavour-dependent.  :)


- Bruce



From dyoo@hkn.eecs.berkeley.edu  Tue May 22 23:14:34 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 22 May 2001 15:14:34 -0700 (PDT)
Subject: [Tutor] encryption
In-Reply-To: <001e01c0e307$6d546ea0$cd52b1cf@oemcomputer>
Message-ID: <Pine.LNX.4.21.0105221509040.2251-100000@hkn.eecs.berkeley.edu>

On Tue, 22 May 2001, Katharine Stoner wrote:

> I am working on a very simple encryption program.  The program
> replaces all of the keys on the keyboard to numbers.  The problem is
> that I cannot get letters to be traded for the numbers very easily.  
> I can't get it to be put in a function so when I make the GUI for
> encryption and decription.

Thankfully, there's a function called ord() that will do a lot of this
work for you: it will return the "ordinal" (number) of a character:

###
>>> ord('a')
97
>>> ord('b')
98
>>> ord('c')
99
>>> ord('A')
65
>>> ord('B')
66
>>> ord('C')
67
###

This itself will reallly help reduce the amount of work you'll be doing to
convert letters to numbers.


>  I also need to be able to transform a message into the numbers
> through a loop in the translation function.  It gives me an error when
> I try and use the function to change letters to numbers.  It says name
> is not defined.  If someone would tell me what is wrong with this
> function.  I need a new aproach. -thanks Cameron

Can you show us how you're using your letters() function?

Good luck to you!



From kstoner@netins.net  Tue May 22 23:32:12 2001
From: kstoner@netins.net (Katharine Stoner)
Date: Tue, 22 May 2001 17:32:12 -0500
Subject: [Tutor] encryption
References: <Pine.LNX.4.21.0105221509040.2251-100000@hkn.eecs.berkeley.edu>
Message-ID: <003601c0e30f$0c076640$cd52b1cf@oemcomputer>

----- Original Message -----
From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
To: Katharine Stoner <kstoner@netins.net>
Cc: python tutor <tutor@python.org>
Sent: Tuesday, May 22, 2001 5:14 PM
Subject: Re: [Tutor] encryption


> On Tue, 22 May 2001, Katharine Stoner wrote:
>
> > I am working on a very simple encryption program.  The program
> > replaces all of the keys on the keyboard to numbers.  The problem is
> > that I cannot get letters to be traded for the numbers very easily.
> > I can't get it to be put in a function so when I make the GUI for
> > encryption and decription.
>
> Thankfully, there's a function called ord() that will do a lot of this
> work for you: it will return the "ordinal" (number) of a character:
>
> ###
> >>> ord('a')
> 97
> >>> ord('b')
> 98
> >>> ord('c')
> 99
> >>> ord('A')
> 65
> >>> ord('B')
> 66
> >>> ord('C')
> 67
> ###
>
> This itself will reallly help reduce the amount of work you'll be doing to
> convert letters to numbers.
>
>
> >  I also need to be able to transform a message into the numbers
> > through a loop in the translation function.  It gives me an error when
> > I try and use the function to change letters to numbers.  It says name
> > is not defined.  If someone would tell me what is wrong with this
> > function.  I need a new aproach. -thanks Cameron
>
> Can you show us how you're using your letters() function?
>
> Good luck to you!
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From glenbar@gte.net  Wed May 23 01:50:43 2001
From: glenbar@gte.net (Glen Barnett)
Date: Tue, 22 May 2001 17:50:43 -0700
Subject: [Tutor] Array of structures
Message-ID: <200105230032.TAA109689402@smtppop1pub.verizon.net>

Is there an equivalent Python script for the C  language array of
structures? An example C program is:

struct day
{
	char month[3];
	int day;
	int year;
};
void PrintIt( struct day bd );

void main(void)
{
	struct day Birthday[15];

	Birthday[2].month[0]=3D=92J=92;
	Birthday[2].month[1]=3D=92a=92;
	Birthday[2].month[2]=3D=92n=92;
	Birthday[2].day=3D21;
	Birthday[2].year=3D1970;

	PrintIt(Birthday[2]);

}
void PrintIt( struct day bd )
{
	printf (=93\nMonth %c%c%c  =94, bd.month[0], bd.month[1] bd.month[2]);
	printf (=93Day %d  =94, bd.day );
	printf (=93Year %d=94, bd.year);
}

Thanks

Glen Barnett




From dyoo@hkn.eecs.berkeley.edu  Wed May 23 03:42:25 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 22 May 2001 19:42:25 -0700 (PDT)
Subject: [Tutor] Array of structures
In-Reply-To: <200105230032.TAA109689402@smtppop1pub.verizon.net>
Message-ID: <Pine.LNX.4.21.0105221922350.5510-100000@hkn.eecs.berkeley.edu>

On Tue, 22 May 2001, Glen Barnett wrote:

> Is there an equivalent Python script for the C language array of
> structures? An example C program is:
>=20
> struct day
> {
> =09char month[3];
> =09int day;
> =09int year;
> };

Almost.  Python's list structures can hold arbitrary elements:

###
>>> mylist =3D [1, "two", "iii", 4]
>>> mylist
[1, 'two', 'iii', 4]
###

which will also allows us to store Dates into a list.  If we want to
presize a list, we can fill it up with a bunch of zeros:

###
birthdays =3D [0] * 15     ## Let's make 15 birthdays
###

and then initialize each list element appropriately.  What's nice is that
Python's lists can grow: we can append() new elements to them:

###
>>> names =3D ['glen']
>>> names.append('danny')
>>> names
['glen', 'danny']
###

so you don't need to worry so much about sizing Python lists: they'll
expand for you.


When we're doing structures in Python, we can either bundle the whole
thing together as a list:

###
def MakeDate(month, day, year):
    return [month, day, year]

def GetMonth(date):  return date[0]
def GetDay(date): return date[1]
def GetYear(date): return date[2]
###


or as a dictionary:

###
def MakeDate(month, day, year):
    return { 'month' : month,
             'day' : day,
             'year' : year }

def GetMonth(date): return date['month']
def GetDay(date): return date['day']
def GetYear(date): return date['year']
###


(I'm renaming your struct Day as a "Date" --- I thought that the name was
a little confusing.)  Above, we're using a small helper function to help
construct these dates for us; more formally, we're making our own
"constructor" for dates.  We also have a few helper functions to help us
grab parts out of our date.


If we have either of the above date implementations, we can write
PrintIt() from the C version:

> void PrintIt( struct day bd )
> {
> =09printf (=93\nMonth %c%c%c  =94, bd.month[0], bd.month[1] bd.month[2]);
> =09printf (=93Day %d  =94, bd.day );
> =09printf (=93Year %d=94, bd.year);
> }

to a Python version like this:

###
def PrintIt(date):
    print "Month: %s\nDay %d\nYear %d" % (GetMonth(date),
                                          GetDay(date),
                                          GetYear(date))
if __name__ =3D=3D '__main__':
    birthday =3D MakeDate("Jan", 21, 1970)
    PrintIt(birthday)
###


Another implementation that's a little closer to your defintion uses a
class approach:

###
class Date:
    def __init__(self, month, day, year):
        self.month =3D month
        self.day =3D day
        self.year =3D year
###

and when you get to object oriented programming, I think you will have a
blast with it.  *grin*  Good luck!



From lumbricus@gmx.net  Wed May 23 06:59:26 2001
From: lumbricus@gmx.net (=?iso-8859-1?Q?J=F6W=F6?=)
Date: Wed, 23 May 2001 07:59:26 +0200
Subject: [Tutor] Array of structures
In-Reply-To: <200105230032.TAA109689402@smtppop1pub.verizon.net>; from glenbar@gte.net on Tue, May 22, 2001 at 05:50:43PM -0700
References: <200105230032.TAA109689402@smtppop1pub.verizon.net>
Message-ID: <20010523075926.A2642@Laplace.localdomain>

On Tue, May 22, 2001 at 05:50:43PM -0700, Glen Barnett wrote:
> 
> Is there an equivalent Python script for the C  language array of
> structures? An example C program is:
> 
> struct day
> {
> 	char month[3];
> 	int day;
> 	int year;
> };
> void PrintIt( struct day bd );
> 
> void main(void)

int main(void)

> {
> 	struct day Birthday[15];
> 
> 	Birthday[2].month[0]=’J’;
> 	Birthday[2].month[1]=’a’;
> 	Birthday[2].month[2]=’n’;
> 	Birthday[2].day=21;
> 	Birthday[2].year=1970;
> 
> 	PrintIt(Birthday[2]);

<nitpick>
return 0;
</nitpick>

> 
> }
> void PrintIt( struct day bd )
> {
> 	printf (“\nMonth %c%c%c  ”, bd.month[0], bd.month[1] bd.month[2]);
> 	printf (“Day %d  ”, bd.day );
> 	printf (“Year %d”, bd.year);
> }
> 
> Thanks
> 
> Glen Barnett
> 

greetings jö

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

-- 
Will this never-ending series of PLEASURABLE EVENTS never cease?


From SBrunning@trisystems.co.uk  Wed May 23 10:03:26 2001
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Wed, 23 May 2001 10:03:26 +0100
Subject: [Tutor] Accessing Access
Message-ID: <31575A892FF6D1118F5800600846864D78BC61@intrepid>

> From:	Rob Andrews [SMTP:rob@jam.rr.com]
> > What would be the general approach to extract data from a Microsoft
> Access
> > database? I.e. what module should be used? I am running the Python 2.1
> for
> > Windows available from www.python.org.
> >
> 
> I have yet to find one, but ohhhh how I could use one if it exists.
 
See <http://www.lemburg.com/files/python/mxODBC.html>.

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 agauld@crosswinds.net  Wed May 23 10:22:30 2001
From: agauld@crosswinds.net (Alan Gauld)
Date: Wed, 23 May 2001 10:22:30 +0100
Subject: [Tutor] Re: %d
Message-ID: <3b0b8222.12a53.0@crosswinds.net>


>In Alan Gauld's tutorial page 2 you suddenly move 
> from gentle hand holding to this:
>
>>>>print "The sum of %d and %d is: %d" % (v,w,x)


Not sure where you get page 2 from but in the 4th chapter we introduce that
notation as below:

-------------
>>>print 'The total is: ', 23+45

You've seen that we can print strings and numbers. Now we combine the two in
one print statement,
separating them with a comma. We can extend this feature by combining it with
a useful Python trick for
outputting data called a format string: 

>>> print "The sum of %d and %d is: %d" % (7,18,7+18)

In this command the format string contains '%' markers within it. The letter
'd' after the % tells Python
that a 'decimal number' should be placed there. The values to fill in the markers
are obtained from the
values inside the bracketed expression following the % sign on its own. 

There are other letters that can be placed after the % markers. Some of these
include: 

      %s - for string 
      %x - for hexadecimal number 
      %0.2f - for a real number with a maximum of 2 decimal places 
      %04d - pad the number out to 4 digits with 0's 

The Python documentation will give lots more... 

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

There then follows a chapter on data which introduces the concept of variables.
Then in the 6th chapter I use the line you quote above.... I recommend you read
the topics in order
using the master sitre at:

http://www.crosswinds.net/~agauld

or the zip/tgz files that you can download from there.

I do try to explain all concepts before using them!

Alan G.
>I thought % was for the modulus function.  

It is, but is also used for formatting.

> So what is that % doing in front of d which 
> I assume to be a built in variable?  

See the excerpt from simple seqiuences quoted above

>I've carried on through Alan's explanation of "for" 
> and "while".  This is easy to use 

You need to go back not forward, the explanation is 
in chapter 3...

>Sorry if this is a little less challenging than interfaces to
>Postgres...

Now I'm confusded, I've never written an interface 
to PostGres in my life! :-)

HTH,

Alan G


From alan.gauld@bt.com  Wed May 23 11:23:47 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 23 May 2001 11:23:47 +0100
Subject: [Tutor] %d
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7B5@mbtlipnt02.btlabs.bt.co.uk>

> Sorry if this is a little less challenging than interfaces to
> Postgres...give me another couple of weeks for that :-()  

Having now received the tutor digest I see what you mean 
by that previously rather cryptic statement :-)

Hope you got my previous response to your question, 
basically the answer is in the Simple Sequences topic 
earlier in the tutor.

Alan G


From karimy@nipltd.com  Wed May 23 12:11:49 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Wed, 23 May 2001 12:11:49 +0100
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machine?
Message-ID: <00bc01c0e379$299ee100$a5020a0a@private.nipltd.com>

Hi,
Don't blame me for asking this question, but I could not make the
installation of Python 2.1 on the top of  Python 2.0 under windows
possible. I've got some packages that require Python 2.0 but whenever I
install Python 2.1 (on a different directory), it takes over the control of
py, pyc and pyw.

Thank you...

Karim
PS: sorry, but I am still a sinner as I am currently using Windows Me. I'll
make a move someday ;-)



From GADGILP@INFOTECH.ICICI.com  Wed May 23 12:42:38 2001
From: GADGILP@INFOTECH.ICICI.com (GADGIL PRASAD /INFRA/INFOTECH)
Date: Wed, 23 May 2001 17:12:38 +0530
Subject: [Tutor] OO scripting in python...
Message-ID: <718A0962DFC2D4119FF80008C7289E4701032D37@ICICIBACK3>

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

------_=_NextPart_001_01C0E37D.77ACBBC0
Content-Type: text/plain;
	charset="iso-8859-1"

hello,

I am coming from moderate C, basic C++ knowledge, and some perl exp.

For OO scripting, the basic concepts I learned during c++ seems
rather unconnected when I read py-tutorial chapter 9 (classes). 
It seems individual languages like perl, python implement various
basic concepts of OO in such different ways, with such varying grammer,
especially with perl, I was totally confused with 
'perltoot' (perl- tom christian's O. O. tutorial')
It seemd c++ is rather straight forward than that.

I am not that confused after chapter 9, but I don't have OO coding exp., 
and things are not very clear either.

Do I need to buy a book to be able to do OO programming
in python ?

Can someone pl. explain oo coding in a 10,000 feet overview ?

regards,
prasad


. 


------_=_NextPart_001_01C0E37D.77ACBBC0
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>OO scripting in python...</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>hello,</FONT>
</P>

<P><FONT SIZE=2>I am coming from moderate C, basic C++ knowledge, and some perl exp.</FONT>
</P>

<P><FONT SIZE=2>For OO scripting, the basic concepts I learned during c++ seems</FONT>
<BR><FONT SIZE=2>rather unconnected when I read py-tutorial chapter 9 (classes). </FONT>
<BR><FONT SIZE=2>It seems individual languages like perl, python implement various</FONT>
<BR><FONT SIZE=2>basic concepts of OO in such different ways, with such varying grammer,</FONT>
<BR><FONT SIZE=2>especially with perl, I was totally confused with </FONT>
<BR><FONT SIZE=2>'perltoot' (perl- tom christian's O. O. tutorial')</FONT>
<BR><FONT SIZE=2>It seemd c++ is rather straight forward than that.</FONT>
</P>

<P><FONT SIZE=2>I am not that confused after chapter 9, but I don't have OO coding exp., </FONT>
<BR><FONT SIZE=2>and things are not very clear either.</FONT>
</P>

<P><FONT SIZE=2>Do I need to buy a book to be able to do OO programming</FONT>
<BR><FONT SIZE=2>in python ?</FONT>
</P>

<P><FONT SIZE=2>Can someone pl. explain oo coding in a 10,000 feet overview ?</FONT>
</P>

<P><FONT SIZE=2>regards,</FONT>
<BR><FONT SIZE=2>prasad</FONT>
</P>
<BR>

<P><B><FONT SIZE=2>.. </FONT></B>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C0E37D.77ACBBC0--


From robnospam@jam.rr.com  Wed May 23 12:44:30 2001
From: robnospam@jam.rr.com (Rob Andrews)
Date: Wed, 23 May 2001 06:44:30 -0500
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machine?
References: <00bc01c0e379$299ee100$a5020a0a@private.nipltd.com>
Message-ID: <3B0BA29E.CE49CE48@jam.rr.com>

Karim Yaici wrote:
> 
> Hi,
> Don't blame me for asking this question, but I could not make the
> installation of Python 2.1 on the top of  Python 2.0 under windows
> possible. I've got some packages that require Python 2.0 but whenever I
> install Python 2.1 (on a different directory), it takes over the control of
> py, pyc and pyw.
> 
> Thank you...
> 
> Karim
> PS: sorry, but I am still a sinner as I am currently using Windows Me. I'll
> make a move someday ;-)
> 

I use several flavors of Windows, as well as having about 20 linux &
Unix machines here, so you're not the only Windows user alive. (ME,
though?) heehee

In Windows, only one application can own any given file association
(unless I'm just mistaken), so you have to choose which Python install
will automagically run a .py script if you double-click it (or similar).
This is the natural way of things, as it keeps Windows from choking
itself in confusion.

I may be wrong, but I'd wager that if you had a copy of myprogram.py in
your C:\Python21 folder (even if C:\Python20 owned the file
association), and you go to your command prompt (DOS prompt, as some
still call it), cd into C:\Python21 and tell it to

C:\Python21 > python myfile.py

Then the Python installed in that folder will execute the script by that
name.

I've had less than one cup of coffee yet, so I might have made all this
up by mistake,

Rob
-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From karimy@nipltd.com  Wed May 23 13:03:40 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Wed, 23 May 2001 13:03:40 +0100
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machine?
References: <00bc01c0e379$299ee100$a5020a0a@private.nipltd.com> <3B0BA29E.CE49CE48@jam.rr.com>
Message-ID: <00ce01c0e380$68350c80$a5020a0a@private.nipltd.com>

> I may be wrong, but I'd wager that if you had a copy of myprogram.py in
> your C:\Python21 folder (even if C:\Python20 owned the file
> association), and you go to your command prompt (DOS prompt, as some
> still call it), cd into C:\Python21 and tell it to
>
> C:\Python21 > python myfile.py
>
> Then the Python installed in that folder will execute the script by that
> name.

True, I can easily do that with my editor, but the problem is that when you
install Python 2.1, this will overrride the settings, so to summerise my
situation :
Though my Python Path is using Python 2.0 (basicaly when you type in the Dos
prompt: Python you'll get V2.0), however, when you click on a py (or pyw)
file then Python 2.1 is used (which I don't want if I don't tell it so
;-) ).

> I've had less than one cup of coffee yet, so I might have made all this
> up by mistake,

Enjoy your coffee, I've just finished my pizza ;-)

Karim



From robnospam@jam.rr.com  Wed May 23 13:06:07 2001
From: robnospam@jam.rr.com (Rob Andrews)
Date: Wed, 23 May 2001 07:06:07 -0500
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machine?
References: <00bc01c0e379$299ee100$a5020a0a@private.nipltd.com> <3B0BA29E.CE49CE48@jam.rr.com> <00ce01c0e380$68350c80$a5020a0a@private.nipltd.com>
Message-ID: <3B0BA7AF.7EBE2741@jam.rr.com>

Karim Yaici wrote:
> 
> > I may be wrong, but I'd wager that if you had a copy of myprogram.py in
> > your C:\Python21 folder (even if C:\Python20 owned the file
> > association), and you go to your command prompt (DOS prompt, as some
> > still call it), cd into C:\Python21 and tell it to
> >
> > C:\Python21 > python myfile.py
> >
> > Then the Python installed in that folder will execute the script by that
> > name.
> 
> True, I can easily do that with my editor, but the problem is that when you
> install Python 2.1, this will overrride the settings, so to summerise my
> situation :
> Though my Python Path is using Python 2.0 (basicaly when you type in the Dos
> prompt: Python you'll get V2.0), however, when you click on a py (or pyw)
> file then Python 2.1 is used (which I don't want if I don't tell it so
> ;-) ).
> 
> > I've had less than one cup of coffee yet, so I might have made all this
> > up by mistake,
> 
> Enjoy your coffee, I've just finished my pizza ;-)
> 
> Karim
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Do you know how to go into Windows Explorer and change the file
association for the .py, .pyc, and .pyw files? If so, you can tell
Windows to use 2.0 instead of 2.1 by default, but only one of them at a
time can own the association.

Is your Python Path unfriendly to Python 2.1?

Rob
-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From karimy@nipltd.com  Wed May 23 13:23:20 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Wed, 23 May 2001 13:23:20 +0100
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machine?
References: <00bc01c0e379$299ee100$a5020a0a@private.nipltd.com> <3B0BA29E.CE49CE48@jam.rr.com> <00ce01c0e380$68350c80$a5020a0a@private.nipltd.com> <3B0BA7AF.7EBE2741@jam.rr.com>
Message-ID: <00ee01c0e383$27c7cb80$a5020a0a@private.nipltd.com>

> Do you know how to go into Windows Explorer and change the file
> association for the .py, .pyc, and .pyw files? If so, you can tell
> Windows to use 2.0 instead of 2.1 by default, but only one of them at a
> time can own the association.

My question was a more general one.  I could do that but I was wondering
wether it is possible to have a Python installation which just sits there
(without changing file association...), a kind of zip package.

> Is your Python Path unfriendly to Python 2.1?

I have not tried that but I wouldn't think so.

> Rob
> --
>
> You should have listened when your mother warned you about
> Useless Python!
> http://www.lowerstandard.com/python/pythonsource.html
>



From din22@home.com  Wed May 23 13:38:05 2001
From: din22@home.com (sheri)
Date: Wed, 23 May 2001 07:38:05 -0500
Subject: [Tutor] tkinter?
Message-ID: <000c01c0e385$372067c0$134d0141@dstn1.fl.home.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C0E35B.4DF67360
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hello my little script is working just fine thanks to everyone.
i was looking at the tcl widget demo and saw the file selection
dialog code which would be really neat to integrate into my program.
unfortunately i cannot figure out how to do this. is there a nice =
tkinter
way of adding this to my program?=20

------=_NextPart_000_0009_01C0E35B.4DF67360
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>hello my little script is working just =
fine thanks=20
to everyone.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>i was looking at the tcl widget demo =
and saw the=20
file selection</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>dialog code which would be really neat =
to integrate=20
into my program.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>unfortunately i cannot figure out how =
to do this.=20
is there a nice tkinter</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>way of adding this to my program?=20
</FONT></DIV></BODY></HTML>

------=_NextPart_000_0009_01C0E35B.4DF67360--



From lsloan@umich.edu  Wed May 23 14:11:57 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Wed, 23 May 2001 09:11:57 -0400
Subject: [Tutor] encryption
In-Reply-To: Your message of "Tue, 22 May 2001 16:37:39 CDT."
 <001e01c0e307$6d546ea0$cd52b1cf@oemcomputer>
Message-ID: <200105231311.JAA17620@birds.us.itd.umich.edu>

"Katharine Stoner" wrote:
> I am working on a very simple encryption program.  The program replaces =
> all of the keys on the keyboard to numbers.  The problem is that I =
> cannot get letters to be traded for the numbers very easily.  I can't =
> get it to be put in a function so when I make the GUI for encryption and =
> decription.  I also need to be able to transform a message into the =
> numbers through a loop in the translation function.  It gives me an =
> error when I try and use the function to change letters to numbers.  It =
> says name is not defined.  If someone would tell me what is wrong with =
> this function.  I need a new aproach.

Cameron/Katharine,

As others have suggested, using a dictionary, list, or simply using
ord() on each character would be the best thing to do.  I have a
comment on your algorithm, though.  If your original text is, "AZ",
your encrypted output should either have one number per line or
delimited by some other character, like spaces:

    1
    26

Or:

    1 26

Because if you run them all together, like this:

    126

It might be decrypted later as "ABF", for characters number one, two,
and six, rather than what you intended, "AZ", characters one and twenty
six.

Good luck!

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From arcege@speakeasy.net  Wed May 23 14:14:02 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 23 May 2001 09:14:02 -0400 (EDT)
Subject: [Tutor] OO scripting in python...
In-Reply-To: <718A0962DFC2D4119FF80008C7289E4701032D37@ICICIBACK3> from "GADGIL PRASAD     /INFRA/INFOTECH" at May 23, 2001 05:12:38 PM
Message-ID: <200105231314.f4NDE2302328@dsl092-074-184.bos1.dsl.speakeasy.net>

GADGIL PRASAD     /INFRA/INFOTECH wrote
> I am coming from moderate C, basic C++ knowledge, and some perl exp.
> 
> For OO scripting, the basic concepts I learned during c++ seems
> rather unconnected when I read py-tutorial chapter 9 (classes). 
> It seems individual languages like perl, python implement various
> basic concepts of OO in such different ways, with such varying grammer,
> especially with perl, I was totally confused with 
> 'perltoot' (perl- tom christian's O. O. tutorial')
> It seemd c++ is rather straight forward than that.
> 
> I am not that confused after chapter 9, but I don't have OO coding exp., 
> and things are not very clear either.
> 
> Do I need to buy a book to be able to do OO programming
> in python ?
> 
> Can someone pl. explain oo coding in a 10,000 feet overview ?

Well.. first is that there are a lot of different philosophies for
object-oriented programming.  But how I tend to think about it is
that you don't want to think about the programming, concentrate on the
object-oriented design.

"Object-oriented" basically means that instead of procedures and data
structures, your program wants to think of objects and behaviors of
the objects.

One classic example program is a bank.  You have a teller and some
customers, a line to wait in, transactions for each.  In "normal"
(procedural) programming, you would have a structure for the teller,
one for the line (queue), and possibly structures for the transactions
since that data is more important than the customer information.

Something like:
  assign values to teller structure
  define queue for transactions
  check_for_new_transactions(queue)
  until queue is empty:
    next = get_next_transaction(, queue)
    process_transaction(teller, next)
    check_for_new_transactions(queue)
Here, the routines are typically geared to the precise data structure
being passed.

With object-oriented programmer, you would have a teller object, which
would have a queue (with a "interact_with_next_customer" method?), and
customer objects.  The behavior between the tellers and customers is more
important: customer must fill out deposit slip, teller must check account
information (right bank, valid account), customer must pass over money,
teller must return a receipt.

How about:
  create new teller object
  create new queue object, associated with teller object
  queue.check_for_new_users()
  until queue is empty:
    user = queue.get_next_user()
    teller.process_transaction(user)
    queue.check_for_new_users()

Now this doesn't seem all that different.  But let's replace the teller
with an ATM.  The transactions might be the same, but the routines called
would be very different in procedural programming (since most are are
typed languages).  However in object-oriented programming, we can make
an ATM object that behaves just like the teller object and the rest of
the program wouldn't have to change much.  Or if the user was now an
online user and the queue was from a webpage, then those could be more
easily changed as well.

What is commonly thrown about is "code reuse".  As you can see, if
designed correctly, things like the queue, user, teller can be reused
more easily than the functions in the first example (but all can be
reused if all designed correctly).

  -Arcege

PS: IMO, Perl makes things very confusing in general, and how they added
"objects" in Perl5 was especially so.  Congratulations on actually making
it through that document.

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From arcege@speakeasy.net  Wed May 23 14:40:49 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 23 May 2001 09:40:49 -0400 (EDT)
Subject: [Tutor] tkinter?
In-Reply-To: <000c01c0e385$372067c0$134d0141@dstn1.fl.home.com> from "sheri" at May 23, 2001 07:38:05 AM
Message-ID: <200105231340.f4NDenL02365@dsl092-074-184.bos1.dsl.speakeasy.net>

sheri wrote
> 
> This is a multi-part message in MIME format.
> 
> ------=_NextPart_000_0009_01C0E35B.4DF67360
> Content-Type: text/plain;
> 	charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
> 
> hello my little script is working just fine thanks to everyone.
> i was looking at the tcl widget demo and saw the file selection
> dialog code which would be really neat to integrate into my program.
> unfortunately i cannot figure out how to do this. is there a nice =
> tkinter
> way of adding this to my program?=20
> 
> ------=_NextPart_000_0009_01C0E35B.4DF67360

There are two file dialog widget sets in Tkinter.  One is built from
the raw Tk(inter) widgets.  The second is newer and uses Tk's new
"native-feel" widgets.

First one (from FileDialog.test):
  from FileDialog import *
  root = Tk()      # Dialog has a bug where it cannot take None as root
  root.withdraw()  # don't display root window
  fd = FileDialog.LoadFileDialog(root)
  loadfile = fd.go(key="test")
  fd = FileDialog.SaveFileDialog(root)
  savefile = fd.go(key="test")
  print loadfile, savefile

Second one (from tkFileDialog main code):
  import tkFileDialog
  print "open" askopenfilename(filenames=[('all filez", "*")])
  print "saveas", asksaveasfilename()

The advantage of the first is that it is easier to reuse the widget (and
to make subclasses).  The second looks more like a X-Windows/WinXX/Mac
file dialog.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From lsloan@umich.edu  Wed May 23 14:49:15 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Wed, 23 May 2001 09:49:15 -0400
Subject: [Tutor] line labels?
Message-ID: <200105231349.JAA18160@birds.us.itd.umich.edu>

Does Python support labelling lines of code?  I was just in the
middle of supporting some Perl poorly-written by somebody else
when I saw constructs like this:
  
  while0:
  while(1) {
    do something...
  
    while1:
    while (&read_input) {
      do something...
  
      if (condition) {
        last while1;
      }
    }
  
    if (condition) {
      last while0;
    }
  }

I know that C has something like this and you can use "goto" statements.
Personally, I consider using those labels in Perl and C to be bad
form and "goto" is just plain heinous.

I'm really enjoying learning Python.  I hope it doesn't have this
feature.  I think it would allow programmers to develop bad habits and
hard-to-maintain code.  For example, in the Perl example above, I
think the code would work as it is if the labels were deleted.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From randrews@planhouse.com  Wed May 23 14:53:33 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Wed, 23 May 2001 08:53:33 -0500
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machine?
In-Reply-To: <00ee01c0e383$27c7cb80$a5020a0a@private.nipltd.com>
Message-ID: <000601c0e38f$c2205060$de00a8c0@planhouse5>

3;-> -----Original Message-----

3;-> My question was a more general one.  I could do that but I
3;-> was wondering
3;-> wether it is possible to have a Python installation which
3;-> just sits there
3;-> (without changing file association...), a kind of zip package.
3;->

I did find one distribution of Python a short while back that might be just
what you're looking for. It's a small install package and doesn't make any
registry changes. However, I can not remember where I found it. Does anyone
else know what I'm talking about?

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html



From dyoo@hkn.eecs.berkeley.edu  Wed May 23 14:53:56 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 23 May 2001 06:53:56 -0700 (PDT)
Subject: [Tutor] line labels?
In-Reply-To: <200105231349.JAA18160@birds.us.itd.umich.edu>
Message-ID: <Pine.LNX.4.21.0105230650570.14873-100000@hkn.eecs.berkeley.edu>

On Wed, 23 May 2001, Lance E Sloan wrote:

> Does Python support labelling lines of code?  I was just in the
> middle of supporting some Perl poorly-written by somebody else
> when I saw constructs like this:


> I'm really enjoying learning Python.  I hope it doesn't have this
> feature.  I think it would allow programmers to develop bad habits and
> hard-to-maintain code.  For example, in the Perl example above, I
> think the code would work as it is if the labels were deleted.

Thankfully, there is no standard goto in Python.  However, the Python FAQ
does give a way of abusing the exception handling system recklessly enough
to simulate most uses of goto.

    http://python.org/doc/FAQ.html#6.26

Hope this helps!



From george@perrymtn.com  Wed May 23 15:22:17 2001
From: george@perrymtn.com (George Perry)
Date: Wed, 23 May 2001 10:22:17 -0400
Subject: [Tutor] Accessing Access
Message-ID: <200105231422.KAA16100@www21.ureach.com>

Thanks to all who replied to my question about retrieving data 
from an Access database with Python.

George Perry


From randrews@planhouse.com  Wed May 23 15:40:02 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Wed, 23 May 2001 09:40:02 -0500
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machine?
In-Reply-To: <000601c0e38f$c2205060$de00a8c0@planhouse5>
Message-ID: <000701c0e396$4099e180$de00a8c0@planhouse5>

3;-> 3;-> -----Original Message-----
3;->
3;-> 3;-> My question was a more general one.  I could do that but I
3;-> 3;-> was wondering
3;-> 3;-> wether it is possible to have a Python installation which
3;-> 3;-> just sits there
3;-> 3;-> (without changing file association...), a kind of zip package.
3;-> 3;->
3;->
3;-> I did find one distribution of Python a short while back
3;-> that might be just
3;-> what you're looking for. It's a small install package and
3;-> doesn't make any
3;-> registry changes. However, I can not remember where I
3;-> found it. Does anyone
3;-> else know what I'm talking about?
3;->
3;-> Rob

Answering my own question here, and hopefully someone else's as well. Take a
look at PythonWare's Py20. Is something like this what you are looking for?
This one is based on 2.0, but to quote from their website, "PY20 for Windows
can coexist with other Python installations, since it does not use the
Windows registry."

http://www.pythonware.com/products/python/index.htm

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html



From alan.gauld@bt.com  Wed May 23 15:35:36 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 23 May 2001 15:35:36 +0100
Subject: [Tutor] line labels?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C1@mbtlipnt02.btlabs.bt.co.uk>

> Does Python support labelling lines of code?  

I don't think so, but then the new features I keep 
finding continue to amaze me!

>       if (condition) {
>         last while1;

I think the nearest to that in Python would be a
combination of break and continue statements...

> Personally, I consider using those labels in Perl and C to be bad
> form and "goto" is just plain heinous.

There are times when they are handy, but they're pretty rare.
In 3 years with Python I've not missed them yet.

Alan g



From alan.gauld@bt.com  Wed May 23 15:28:39 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 23 May 2001 15:28:39 +0100
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machin e?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C0@mbtlipnt02.btlabs.bt.co.uk>

> Do you know how to go into Windows Explorer and change the file
> association for the .py, .pyc, and .pyw files? If so, you can tell
> Windows to use 2.0 instead of 2.1 by default, but only one of 
> them at a
> time can own the association.

You can also creayte a new right click menu item to run 
in either version of Python - say run2.0 and run2.1.

That way you can click on any Python file and choose which 
version of the interpreter to run it with...

Alan g


From alan.gauld@bt.com  Wed May 23 15:25:51 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 23 May 2001 15:25:51 +0100
Subject: [Tutor] OO scripting in python...
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7BF@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C0E394.450F7600
Content-type: text/plain; charset="iso-8859-1"

It seemd c++ is rather straight forward than that. 

That's because C++ takes its own rather idiosyncratic 
view of OO which is somewhat at odds with most other 
OO implementations. 

Do I need to buy a book to be able to do OO programming 
in python ? Can someone pl. explain oo coding in a 10,000 feet overview ?  

No book necessary but several are helpful. My favourite 
beginners OO books are Coad/Yourdon OO Analysis and 
Timothy Budds OO Programming. Both easy to read.
 
As to a 10,000 foot view try my tutor at:
 
http://www.crosswinds.net/~agauld <http://www.crosswinds.net/~agauld> 
 
Look at the OO topic and the OO section of the Case Study.
 
HTH,
 
Alan G.

 


------_=_NextPart_001_01C0E394.450F7600
Content-type: text/html; charset="iso-8859-1"

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

<META content="MSHTML 5.00.3013.2600" name=GENERATOR></HEAD>
<BODY>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <P><FONT size=2>It seemd c++ is rather straight forward than that.</FONT> 
</P></BLOCKQUOTE>
<DIV><SPAN class=160002814-23052001><FONT color=#0000ff face="Courier New" 
size=2>That's because C++ takes its own rather idiosyncratic </FONT></SPAN><SPAN 
class=160002814-23052001><BR><FONT color=#0000ff face="Courier New" size=2>view 
of OO which is somewhat at odds with most other </FONT></SPAN></DIV>
<DIV><SPAN class=160002814-23052001><FONT color=#0000ff face="Courier New" 
size=2>OO implementations.&nbsp;</FONT></SPAN></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <P><FONT size=2>Do I need to buy a book to be able to do OO programming</FONT> 
  <BR><FONT size=2>in python ?</FONT> <FONT size=2>Can someone pl. explain oo 
  coding in a 10,000 feet overview ?</FONT>&nbsp;<FONT color=#0000ff 
  face="Courier New" size=2><SPAN 
  class=160002814-23052001>&nbsp;</SPAN></FONT></P></BLOCKQUOTE>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001>No book necessary but several are helpful. </SPAN><SPAN 
class=160002814-23052001>My favourite </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001>beginners OO books are Coad/Yourdon OO Analysis and 
</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001>Timothy Budds OO Programming. Both easy to 
read.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001>As to a 10,000 foot view try my tutor 
at:</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001><A 
href="http://www.crosswinds.net/~agauld">http://www.crosswinds.net/~agauld</A></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001>Look at the OO topic and the OO section of the Case 
Study.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001>HTH,</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff><FONT size=2><FONT face="Courier New"><SPAN 
class=160002814-23052001>Alan G.</SPAN></FONT></FONT></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <P>&nbsp;</P></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C0E394.450F7600--


From rob@jam.rr.com  Wed May 23 15:54:13 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Wed, 23 May 2001 09:54:13 -0500
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machin e?
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C0@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <003c01c0e398$3bae80c0$de00a8c0@planhouse5>

----- Original Message -----
> You can also creayte a new right click menu item to run
> in either version of Python - say run2.0 and run2.1.
>
> That way you can click on any Python file and choose which
> version of the interpreter to run it with...
>
> Alan g
>

I must learn this trick. I know more arcane Windows features than anyone
else I know, but this one is new to me.

Rob



From karimy@nipltd.com  Wed May 23 16:25:15 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Wed, 23 May 2001 16:25:15 +0100
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machine?
References: <000701c0e396$4099e180$de00a8c0@planhouse5>
Message-ID: <001701c0e39c$9135cf40$a5020a0a@private.nipltd.com>

> Answering my own question here, and hopefully someone else's as well. Take
a
> look at PythonWare's Py20. Is something like this what you are looking
for?
> This one is based on 2.0, but to quote from their website, "PY20 for
Windows
> can coexist with other Python installations, since it does not use the
> Windows registry."
>
> http://www.pythonware.com/products/python/index.htm
>

Thanks Rob,
I'll try this and see if it's worth making Python 2.1 my default Python
interpreter.

Cheers,

Karim



From dsh8290@rit.edu  Wed May 23 16:32:26 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 23 May 2001 11:32:26 -0400
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machin e?
In-Reply-To: <003c01c0e398$3bae80c0$de00a8c0@planhouse5>; from rob@jam.rr.com on Wed, May 23, 2001 at 09:54:13AM -0500
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C0@mbtlipnt02.btlabs.bt.co.uk> <003c01c0e398$3bae80c0$de00a8c0@planhouse5>
Message-ID: <20010523113226.B22312@harmony.cs.rit.edu>

On Wed, May 23, 2001 at 09:54:13AM -0500, Rob Andrews wrote:
| 
| > You can also creayte a new right click menu item to run
| > in either version of Python - say run2.0 and run2.1.
| >
| > That way you can click on any Python file and choose which
| > version of the interpreter to run it with...
| >
| 
| I must learn this trick. I know more arcane Windows features than anyone
| else I know, but this one is new to me.

(I have a win2k box in front of me now so all steps are accurate for
 win2k,  win9x uses a slightly different naming scheme for menus and
 buttons but it is fairly similar and I will try my best to remember
 the right names)


1:  open windows explorer  (or is that internet explorer?  can't tell
                            the difference nowadays anyways)

2:  Tools->Folder Options  (IIRC win9x has this under the 'View' menu)

3:  click the "File Types" tab

4:  scroll down to  "PY  Python File"  (it has the icon too, they're
                                        alphabetical)

5:  Here it makes a difference which windows :
        win2k -- click the "Advanced" button
        win9x -- click the "edit" or some similar button

6:  Click the "New" button in the dialog that pops up

7:  give the action a name (ie run2.0 as suggested by Alan)

8:  give the action a command (ie c:\python20\python.exe)

9:  click "Ok"

10: again (click "Ok")

11: one more time -- did we use enough dialogs yet?

12: right-click on a .py file to see/verify that a new entry exists in
    the popup menu


-D



From karimy@nipltd.com  Wed May 23 16:41:02 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Wed, 23 May 2001 16:41:02 +0100
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machin e?
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C0@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <003d01c0e39e$c5a5f6e0$a5020a0a@private.nipltd.com>

First, I'd like to thank you all for your valuable replies,

> You can also creayte a new right click menu item to run
> in either version of Python - say run2.0 and run2.1.

Just for reference,  I explain what I did:
1 - Go to Settings -> Folder Options
2 - Search for 'Python File', click on 'edit'
3 - 'Add' a new action, call it 'Open with Python 2.1' and in the
'Application' field type in:

C:\Progra~1\Python21\python.exe "%1" %*
(The above line may change according to your installation path of Python)

Voila, now, whenever you right click on a python file you'll have the option
to start the script with either version.

Cheers,
Karim




From rob@jam.rr.com  Wed May 23 16:49:38 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Wed, 23 May 2001 10:49:38 -0500
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machin e?
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C0@mbtlipnt02.btlabs.bt.co.uk> <003c01c0e398$3bae80c0$de00a8c0@planhouse5> <20010523113226.B22312@harmony.cs.rit.edu>
Message-ID: <007501c0e39f$f984a960$de00a8c0@planhouse5>

----- Original Message -----
From: "D-Man" <dsh8290@rit.edu>
To: <tutor@python.org>
Sent: Wednesday, May 23, 2001 10:32 AM
Subject: Re: [Tutor] How Can Install Python 2.0 and 2.1 on the same machin
e?


> On Wed, May 23, 2001 at 09:54:13AM -0500, Rob Andrews wrote:
> |
> | > You can also creayte a new right click menu item to run
> | > in either version of Python - say run2.0 and run2.1.
> | >
> | > That way you can click on any Python file and choose which
> | > version of the interpreter to run it with...
> | >
> |
> | I must learn this trick. I know more arcane Windows features than anyone
> | else I know, but this one is new to me.
>
> (I have a win2k box in front of me now so all steps are accurate for
>  win2k,  win9x uses a slightly different naming scheme for menus and
>  buttons but it is fairly similar and I will try my best to remember
>  the right names)
>
>
> 1:  open windows explorer  (or is that internet explorer?  can't tell
>                             the difference nowadays anyways)
>
> 2:  Tools->Folder Options  (IIRC win9x has this under the 'View' menu)
>
> 3:  click the "File Types" tab
>
> 4:  scroll down to  "PY  Python File"  (it has the icon too, they're
>                                         alphabetical)
>
> 5:  Here it makes a difference which windows :
>         win2k -- click the "Advanced" button
>         win9x -- click the "edit" or some similar button
>
> 6:  Click the "New" button in the dialog that pops up
>
> 7:  give the action a name (ie run2.0 as suggested by Alan)
>
> 8:  give the action a command (ie c:\python20\python.exe)
>
> 9:  click "Ok"
>
> 10: again (click "Ok")
>
> 11: one more time -- did we use enough dialogs yet?
>
> 12: right-click on a .py file to see/verify that a new entry exists in
>     the popup menu
>

I feel like I must have known this trick at some point in the distant past,
but it's great to know it again. I just ran through it on a Win98SE box and
it all worked just fine. Steps 10 and 11 on this box used Close instead of
OK, but to get that close from memory is impressive, D-Man.

-Rob

Useless Python
It's not just for breakfast anymore!
http://www.lowerstandard.com/python/pythonsource.html



From MLange@atmedicausa.com  Wed May 23 16:55:31 2001
From: MLange@atmedicausa.com (Mike Lange)
Date: Wed, 23 May 2001 09:55:31 -0600
Subject: [Tutor] re: range function
Message-ID: <OF6CAE4709.15CB7CDE-ON87256A55.00574C7B@atmedicausa.com>

This is a multipart message in MIME format.
--=_alternative 0057EC9287256A55_=
Content-Type: text/plain; charset="us-ascii"

how would I go about creating a range for float-type numbers?  I've tried 
range(1.0, 1000.0, 4.55) as well as range(float(1.0), float(1000), 
float(4.55)) and even float(range(1.0, 1000.0, 4.55)) but none of these 
work. 

Thanks in advance for the reply,



Mike Lange
Developer
mlange@atmedicausa.com
Phone:   801-517-6944
Fax:        801-517-6990

He who controls vocabulary controls thought. 
-Luigi Wittgenstein 
--=_alternative 0057EC9287256A55_=
Content-Type: text/html; charset="us-ascii"


<br><font size=2 face="sans-serif">how would I go about creating a range for float-type numbers? &nbsp;I've tried range(1.0, 1000.0, 4.55) as well as range(float(1.0), float(1000), float(4.55)) and even float(range(1.0, 1000.0, 4.55)) but none of these work. &nbsp;</font>
<br>
<br><font size=2 face="sans-serif">Thanks in advance for the reply,</font>
<br>
<br>
<br>
<br><font size=2 face="sans-serif">Mike Lange<br>
Developer<br>
mlange@atmedicausa.com<br>
Phone: &nbsp; 801-517-6944<br>
Fax: &nbsp; &nbsp; &nbsp; &nbsp;801-517-6990<br>
<br>
He who controls vocabulary controls thought. <br>
-Luigi Wittgenstein </font>
--=_alternative 0057EC9287256A55_=--


From MLange@atmedicausa.com  Wed May 23 17:25:24 2001
From: MLange@atmedicausa.com (Mike Lange)
Date: Wed, 23 May 2001 10:25:24 -0600
Subject: [Tutor] re: Tim's answer
Message-ID: <OF398FD742.FFE7C2A0-ON87256A55.005A2559@atmedicausa.com>

This is a multipart message in MIME format.
--=_alternative 005AA8E687256A55_=
Content-Type: text/plain; charset="us-ascii"

Thanks, Tim.  Works for me :-)




Mike

He who controls vocabulary controls thought. 
-Luigi Wittgenstein 
--=_alternative 005AA8E687256A55_=
Content-Type: text/html; charset="us-ascii"


<br><font size=2 face="sans-serif">Thanks, Tim. &nbsp;Works for me :-)</font>
<br>
<br>
<br>
<br>
<br><font size=2 face="sans-serif">Mike<br>
<br>
He who controls vocabulary controls thought. <br>
-Luigi Wittgenstein </font>
--=_alternative 005AA8E687256A55_=--


From tmbrau00@centre.edu  Wed May 23 17:29:38 2001
From: tmbrau00@centre.edu (Timothy M. Brauch)
Date: Wed, 23 May 2001 12:29:38 -0400
Subject: [Tutor] re: range function
References: <OF6CAE4709.15CB7CDE-ON87256A55.00574C7B@atmedicausa.com>
Message-ID: <3B0BE572.CCEAAC42@centre.edu>

Oops, first time I forgot to send this to the list...

I know this probably isn't the best way to do it, but I think it should
work...

Mike Lange wrote:
> 
> how would I go about creating a range for float-type numbers?  I've
> tried range(1.0, 1000.0, 4.55) as well as range(float(1.0),
> float(1000), float(4.55)) and even float(range(1.0, 1000.0, 4.55)) but
> none of these work.

You would like an output of (aligning by decimals, which is not default
for python, but makes it easier to read):
 1.00
 5.55
10.10
14.65
...
992.90
997.45

A way to get these same results would be

for num in range(1,221):
   num=num*4.55-3.55

This will provide the same results, but it is probably not the best way
to go about it.

 - Tim


From DOUGS@oceanic.com  Wed May 23 17:31:32 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Wed, 23 May 2001 06:31:32 -1000
Subject: [Tutor] re: range function
Message-ID: <8457258D741DD411BD3D0050DA62365907A81E@huina.oceanic.com>

[Mike Lange]
> how would I go about creating a range for float-type
> numbers?  I've tried range(1.0, 1000.0, 4.55) as well
> as range(float(1.0), float(1000), float(4.55)) and
> even float(range(1.0, 1000.0, 4.55)) but none of these work.   

First, I'm assuming you know all the shortcomings of using floats. ;-)

I've always found that working in the interpreter helps give me answers to
these kinds of questions.  I assume thats what you were doing above:

Python 1.5.2 (#1, Apr 18 1999, 16:03:16)  [GCC pgcc-2.91.60 19981201
(egcs-1.1.1  on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> range(1.0, 1000.0, 4.55)
[1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73,
77, 81, 85, 89, 93, 97, 10
1, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157,
161, 165, 169, 
------snip------
985, 989, 993, 997]

Seems consistant with what the 'Python Library Reference' says ... "The
arguments must be plain integers. ... The full form returns a list of plain
integers."  Seems it was leniant that it didn't cough up on the non-integer
inputs.  From the above it seems you want numbers from 1 to nearly 1000 that
increment by 4.55.  Apparently that would require two decimal places of
precision:

>>> y = range(100,100000,455)
>>> y
[100, 555, 1010, 1465, 1920, 2375, 2830, 3285, 3740, 4195, 4650, 5105, 5560,
6015, 6470, 6925, 7380,
 7835, 8290, 8745, 9200, 9655, 10110, 10565, 11020, 11475, 11930, 12385,
12840, 13295, 13750, 14205,
-----------snip------------
465, 92920, 93375, 93830, 94285, 94740, 95195, 95650, 96105, 96560, 97015,
97470, 97925, 98380, 9883
5, 99290, 99745]
>>> for counter in range(len(y)):
...   y[counter] = float(y[counter])/100
...
>>> y
[1.0, 5.55, 10.1, 14.65, 19.2, 23.75, 28.3, 32.85, 37.4, 41.95, 46.5, 51.05,
55.6, 60.15, 64.7, 69.2
5, 73.8, 78.35, 82.9, 87.45, 92.0, 96.55, 101.1, 105.65, 110.2, 114.75,
119.3, 123.85, 128.4, 132.95
, 137.5, 142.05, 146.6, 151.15, 155.7, 160.25, 164.8, 169.35, 173.9, 178.45,
183.0, 187.55, 192.1, 1
-------------snip------------
.8, 988.35, 992.9, 997.45]
>>>

> Thanks in advance for the reply, 

HTH

-Doug-

Mike Lange
Developer
mlange@atmedicausa.com
Phone:   801-517-6944
Fax:        801-517-6990

He who controls vocabulary controls thought. 
-Luigi Wittgenstein 


From dsh8290@rit.edu  Wed May 23 17:47:15 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 23 May 2001 12:47:15 -0400
Subject: [Tutor] re: range function
In-Reply-To: <8457258D741DD411BD3D0050DA62365907A81E@huina.oceanic.com>; from DOUGS@oceanic.com on Wed, May 23, 2001 at 06:31:32AM -1000
References: <8457258D741DD411BD3D0050DA62365907A81E@huina.oceanic.com>
Message-ID: <20010523124715.A22446@harmony.cs.rit.edu>

On Wed, May 23, 2001 at 06:31:32AM -1000, Doug Stanfield wrote:
...
| >>> y = range(100,100000,455)
| >>> y
| [100, 555, 1010, 1465, 1920, 2375, 2830, 3285, 3740, 4195, 4650, 5105, 5560,
| -----------snip------------
| 97470, 97925, 98380, 9883
| 5, 99290, 99745]
| >>> for counter in range(len(y)):
| ...   y[counter] = float(y[counter])/100
| ...
| >>> y
| [1.0, 5.55, 10.1, 14.65, 19.2, 23.75, 28.3, 32.85, 37.4, 41.95, 46.5, 51.05,
| -------------snip------------
| .8, 988.35, 992.9, 997.45]
| >>>

Just to see if I can write a list comprehension :

>>>y = [ x/100.0  for x in range( 100 , 100000 , 455 ) ]
>>> def p( n ) :
...     return "%.2f" % n
...
>>> print map( p , y )
['1.00', '5.55', '10.10', '14.65', '19.20', '23.75', '28.30', '32.85', '37.40',
'41.95', '46.50', '51.05', '55.60', '60.15', '64.70', '69.25', '73.80', '78.35',
 '82.90', '87.45', '92.00', '96.55', '101.10', '105.65', '110.20', '114.75', '11
9.30', '123.85', '128.40', '132.95', '137.50', '142.05', '146.60', '151.15', '15
-------------snip------------
6.50', '961.05', '965.60', '970.15', '974.70', '979.25', '983.80', '988.35', '99
2.90', '997.45']
>>>


(that 'p' function was just to truncate the output to 2 decimal
 places;  a side effect of this was to generate a list of strings,
 hence the quotes in the output)

-D




From scott@zenplex.com  Wed May 23 19:04:20 2001
From: scott@zenplex.com (Scott Ralph Comboni)
Date: 23 May 2001 14:04:20 -0400
Subject: [Tutor] Python2 speed vs Python1.5.2
Message-ID: <990641060.1311.0.camel@scoot>

I just finished a small script that uses the re module for regular
expression processing.  It's a very simple script that parses a text
file and does a re.sub then saves the new file out 1000 times. I ran the
script under Python2.0 and Python1.5.2 and found that Python1.5.2 took
4secs while 2.0 took 15secs..  Any answer why Python2.0 is slower?

Scott


-- 
Scott Comboni
Zenplex, Inc.
317 Madison Ave.
Suite 1500
New York NY, 10017
212.499.0668 ext2219
http://www.zenplex.com
http://www.zenplex.org
http://tambora.zenplex.org



From randrews@planhouse.com  Wed May 23 19:11:28 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Wed, 23 May 2001 13:11:28 -0500
Subject: [Tutor] Python2 speed vs Python1.5.2
In-Reply-To: <990641060.1311.0.camel@scoot>
Message-ID: <000f01c0e3b3$ca320220$de00a8c0@planhouse5>

3;-> I just finished a small script that uses the re module for regular
3;-> expression processing.  It's a very simple script that
3;-> parses a text
3;-> file and does a re.sub then saves the new file out 1000
3;-> times. I ran the
3;-> script under Python2.0 and Python1.5.2 and found that
3;-> Python1.5.2 took
3;-> 4secs while 2.0 took 15secs..  Any answer why Python2.0 is slower?
3;->
3;-> Scott
3;->

Can you provide a little more info, such as which OS you are running on and
maybe the source to the script?

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html



From scott@zenplex.com  Wed May 23 19:46:44 2001
From: scott@zenplex.com (Scott Ralph Comboni)
Date: 23 May 2001 14:46:44 -0400
Subject: [Tutor] Python2 speed vs Python1.5.2
In-Reply-To: <000f01c0e3b3$ca320220$de00a8c0@planhouse5>
References: <000f01c0e3b3$ca320220$de00a8c0@planhouse5>
Message-ID: <990643604.1658.1.camel@scoot>

Yes I should have done that in the first place.  I'm running Linux
RH7.1.  I'm still very much new at all this Python being my first
language.  Also Im sure there are plenty of better ways to accomplish
what this script does but here it is.
Anyway the reason for the script is we are trying to simulate
transaction loads on a large scale so I just wrote this to generate 1000
transactions.

#!/usr/bin/env python

# Created May 23, 2001
#
# Im sure there are plenty of ways to accomplish this.
# One using the Python xmllib.


import re
import whrandom

# Base SAN # change as needed
SAN = '222-2222-'

# A Working XML file.  I used this as a template.
xmlfile = open('xmltemplate','r').read()

# Create regular expressions.
# I'm sure most of this can be accomplished with one regex but..
# I have not spent enough time trying to figure it out.
isbn          = re.compile(r"<isbn>.+</isbn>")
recordid      = re.compile(r"<recordid>.+</recordid>")
ponumber      = re.compile(r"<ponumber>.+</ponumber>")
printingno    = re.compile(r"<printingno>.+</printingno>")
noterecordid  = re.compile(r"<noterecordid>.+</noterecordid>")
noteparentid  = re.compile(r"<noteparentid>.+</noteparentid>")
compparentid  = re.compile(r"<compparentid>.+</compparentid>")
transrecordid = re.compile(r"<transrecordid>.+</transrecordid>")

# Use range() to set the max number of transactions. Default is 1000.
# Using str to convert a int to string.
# whrandom to generate a randomo # for po, isbn ,printno.
for x in range(1000):
    xmlfile = recordid.sub('<recordid>' + SAN + str(x) + '</recordid>',
xmlfile)
    xmlfile = transrecordid.sub('<transrecordid>' + SAN + str(x) +
'</transrecordid>', xmlfile)
    xmlfile = noterecordid.sub('<noterecordid>' + SAN + str(x) +
'</noterecordid>', xmlfile)
    xmlfile = noteparentid.sub('<noteparentid>' + SAN + str(x) +
'</noteparentid>', xmlfile)
    xmlfile = compparentid.sub('<compparentid>' + SAN + str(x) +
'</compparentid>', xmlfile)
    xmlfile = ponumber.sub('<ponumber>' + str(whrandom.random()) +
'</ponumber>', xmlfile)
    xmlfile = isbn.sub('<isbn>' + str(whrandom.random()) + '</isbn>',
xmlfile)
    xmlfile = printingno.sub('<printingno>' + str(whrandom.random())
+'</printingno>', xmlfile)
    outputfile = open(SAN + str(x) + '.xml','w')
    outputfile.write(xmlfile)
    outputfile.close()
    print 'Creating transaction ', x, 'done'


Thanks Scott

On 23 May 2001 13:11:28 -0500, Rob Andrews wrote:
> 3;-> I just finished a small script that uses the re module for regular
> 3;-> expression processing.  It's a very simple script that
> 3;-> parses a text
> 3;-> file and does a re.sub then saves the new file out 1000
> 3;-> times. I ran the
> 3;-> script under Python2.0 and Python1.5.2 and found that
> 3;-> Python1.5.2 took
> 3;-> 4secs while 2.0 took 15secs..  Any answer why Python2.0 is slower?
> 3;->
> 3;-> Scott
> 3;->
> 
> Can you provide a little more info, such as which OS you are running on and
> maybe the source to the script?
> 
> Rob
> 
> Got Python?
> http://www.lowerstandard.com/python/pythonsource.html

-- 
Scott Comboni
president
Zenplex, Inc.
317 Madison Ave.
Suite 1500
New York NY, 10017
212.499.0668 ext2219
http://www.zenplex.com
http://www.zenplex.org
http://tambora.zenplex.org



From Vladimir.Denis@olsinc.net  Wed May 23 20:11:47 2001
From: Vladimir.Denis@olsinc.net (Vladimir.Denis@olsinc.net)
Date: Wed, 23 May 2001 15:11:47 -0400
Subject: [Tutor] python backup script
Message-ID: <OF42EF4DB4.D4226FD5-ON85256A55.00685B2F@olsinc.net>

Hello everyone I have a few red hat 7 systems that I would like to create a
backup script for.  I'm new to programming so I am starting out with
python.  I am thinking that I could use the os command du and then capture
the output and then tell python to back up directories and subdirectories
up to 200 megs (using tar).  If people could let me know what to include in
the script (not necessary the code (although if someone has sample scripts,
or what modules to use it would be great) but what is good to have in a
backup script and I can work hard and try to create the code and get better
at both python and programming.

Thanks in advance for the help.



From lsloan@umich.edu  Wed May 23 20:06:11 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Wed, 23 May 2001 15:06:11 -0400
Subject: [Tutor] re: range function
In-Reply-To: Your message of "Wed, 23 May 2001 09:55:31 MDT."
 <OF6CAE4709.15CB7CDE-ON87256A55.00574C7B@atmedicausa.com>
Message-ID: <200105231906.PAA21761@birds.us.itd.umich.edu>

"Mike Lange" wrote:
> how would I go about creating a range for float-type numbers?  I've
> tried range(1.0, 1000.0, 4.55) as well as range(float(1.0),
> float(1000), float(4.55)) and even float(range(1.0, 1000.0, 4.55)) but
> none of these work.

Python told me:
    
    Python 2.0 (#1, Jan  8 2001, 10:18:58) 
    [GCC egcs-2.91.66 19990314 (egcs-1.1.2 release)] on sunos5
    Type "copyright", "credits" or "license" for more information.
    >>> print range.__doc__ 
    range([start,] stop[, step]) -> list of integers

    Return a list containing an arithmetic progression of integers.
    range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
    When step is given, it specifies the increment (or decrement).
    For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!
    These are exactly the valid indices for a list of 4 elements.
    >>>

Integers only.  So I tried my hand at making a float version:
    
    def float_range(*args):
        start = 0.0
        step = 1.0
        if (len(args) == 1):
            (stop,) = args
        elif (len(args) == 2):
            (start, stop) = args
        elif (len(args) == 3):
            (start, stop, step) = args
        else:
            raise TypeError, "float_range needs 1-3 float arguments"
    
        the_range = []
        i = float(start)
        while (i < stop):
            the_range.append(i)
            i = i + step
    
        return the_range
    
The only problem is the inaccurate way floating-point numbers are
represented on most computers:

    Python 2.0 (#1, Jan  8 2001, 10:18:58) 
    [GCC egcs-2.91.66 19990314 (egcs-1.1.2 release)] on sunos5
    Type "copyright", "credits" or "license" for more information.
    >>> from float_range import *
	>>> float_range(1.0, 20.0, 4.55)
    [1.0, 5.5499999999999998, 10.1, 14.649999999999999, 19.199999999999999]

Well, it was right twice!  :)

Maybe somebody else knows of a Python module that will help us do more
accurate float math.

Actually, I came up with an idea that works on its own, but when I
try to put this logic into my function, I get the same results as above.
Try this, though:

    Python 2.0 (#1, Jan  8 2001, 10:18:58)
    [GCC egcs-2.91.66 19990314 (egcs-1.1.2 release)] on sunos5
    Type "copyright", "credits" or "license" for more information.
    >>> x = range(5)
    >>> for i in x:
    ...   print i * 4.55 + 1.0
    ... 
    1.0
    5.55
    10.1
    14.65
    19.2
    >>> 

Maybe somebody else has a better idea.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From Blake.Garretson@dana.com  Wed May 23 20:48:49 2001
From: Blake.Garretson@dana.com (Blake.Garretson@dana.com)
Date: Wed, 23 May 2001 15:48:49 -0400
Subject: [Tutor] Tkinter: "command=" with Listbox
Message-ID: <OFEDB3383C.90AC90B0-ON85256A55.006C25CE@dana.com>

Tkinter's Listbox widget has no "command" option like many other widgets.
This presents a problem for me.  I have a button that is greyed out
(disabled) that I would like to become active only when an item from a
listbox is highlighted.

Anybody have any work-arounds to the lack of a "command" option?

Thanks,
Blake Garretson



From kromag@nsacom.net  Wed May 23 23:41:06 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Wed, 23 May 2001 15:41:06 -0700 (PDT)
Subject: [Tutor] ODBC vs. pygresql, psycopg, etc.
Message-ID: <200105232241.f4NMf5L28095@pop.nsacom.net>

I have been looking at the mxODBC pages and wonder:

How should I decide (as the rankest of newbies) whether to put my efforts 
into ODBC connectivity or to use a more 'direct' module like psycopg?

Thanks!

d


From dsh8290@rit.edu  Wed May 23 21:29:59 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 23 May 2001 16:29:59 -0400
Subject: [Tutor] re: range function
In-Reply-To: <200105231906.PAA21761@birds.us.itd.umich.edu>; from lsloan@umich.edu on Wed, May 23, 2001 at 03:06:11PM -0400
References: <OF6CAE4709.15CB7CDE-ON87256A55.00574C7B@atmedicausa.com> <200105231906.PAA21761@birds.us.itd.umich.edu>
Message-ID: <20010523162959.A22746@harmony.cs.rit.edu>

On Wed, May 23, 2001 at 03:06:11PM -0400, Lance E Sloan wrote:
| 
<doc string from range>
| Integers only.  So I tried my hand at making a float version:
...
| The only problem is the inaccurate way floating-point numbers are
| represented on most computers:
...
| Maybe somebody else knows of a Python module that will help us do more
| accurate float math.

Floating point is inaccurate even on paper -- try writing 1/3 in
decimal.

The solution is to rework your algorithm to use ints instead of
floats or create a rational type that uses ints as its basis.  There
is a PEP to add rationals as builtin types.  I think there is also
some sample code on the web somewhere for a Rational class.

The key is to determine what you need the floats for, why you need
them and what kind of precission you need.  Then you can create a
solution that works for those situations, but a general solution is
not possible on hardware that uses base-2 "scientific notation"
floating point.

-D



From arcege@speakeasy.net  Wed May 23 21:35:23 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 23 May 2001 16:35:23 -0400 (EDT)
Subject: [Tutor] Tkinter: "command=" with Listbox
In-Reply-To: <OFEDB3383C.90AC90B0-ON85256A55.006C25CE@dana.com> from "Blake.Garretson@dana.com" at May 23, 2001 03:48:49 PM
Message-ID: <200105232035.f4NKZNK02789@dsl092-074-184.bos1.dsl.speakeasy.net>

Blake.Garretson@dana.com wrote
> 
> Tkinter's Listbox widget has no "command" option like many other widgets.
> This presents a problem for me.  I have a button that is greyed out
> (disabled) that I would like to become active only when an item from a
> listbox is highlighted.
> 
> Anybody have any work-arounds to the lack of a "command" option?

You'll need to set up an event binding.

  # define grayed out buttons and put them in some bigger structure
  # (dict, list, etc.)
  def set_button(event=None, buttons=struct_o_buttons):
    listbox = event.widget # where we clicked the mouse
    # what has been selected (what index was closest to the mouse)
    index = listbox.nearest(event.y)
    # I'll leave this to you to figure out how you might want to keep
    # track of the relationship between the listbox item and the buttons
    button = get_button_from(listbox, index, buttons)
    if button.cget('state') == NORMAL:
      button.config(state=DISABLED)
    else:
      button.config(state=NORMAL)
  box = Listbox(frame, ...)
  box.bind('<Button-1>', set_button)

At this point, when the mouse clicks on an entry in the Listbox,
the set_button() function gets called and toggles the button's state.
I won't get into how you keep track of which button is associated with
which item in the Listbox.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From bsass@freenet.edmonton.ab.ca  Wed May 23 22:09:31 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Wed, 23 May 2001 15:09:31 -0600 (MDT)
Subject: [Tutor] re: range function
In-Reply-To: <200105231906.PAA21761@birds.us.itd.umich.edu>
Message-ID: <Pine.LNX.4.33.0105231334210.26138-100000@bms>

On Wed, 23 May 2001, Lance E Sloan wrote:
> "Mike Lange" wrote:
<...>
> Integers only.  So I tried my hand at making a float version:
>
>     def float_range(*args):
>         start = 0.0
>         step = 1.0
>         if (len(args) == 1):
>             (stop,) = args
>         elif (len(args) == 2):
>             (start, stop) = args
>         elif (len(args) == 3):
>             (start, stop, step) = args
>         else:
>             raise TypeError, "float_range needs 1-3 float arguments"
>
>         the_range = []
>         i = float(start)
>         while (i < stop):
>             the_range.append(i)
>             i = i + step
>
>         return the_range
>
> The only problem is the inaccurate way floating-point numbers are
> represented on most computers:
>
>     Python 2.0 (#1, Jan  8 2001, 10:18:58)
>     [GCC egcs-2.91.66 19990314 (egcs-1.1.2 release)] on sunos5
>     Type "copyright", "credits" or "license" for more information.
>     >>> from float_range import *
> 	>>> float_range(1.0, 20.0, 4.55)
>     [1.0, 5.5499999999999998, 10.1, 14.649999999999999, 19.199999999999999]
>
> Well, it was right twice!  :)
>
> Maybe somebody else knows of a Python module that will help us do more
> accurate float math.
>
> Actually, I came up with an idea that works on its own, but when I
> try to put this logic into my function, I get the same results as above.
> Try this, though:
>
>     Python 2.0 (#1, Jan  8 2001, 10:18:58)
>     [GCC egcs-2.91.66 19990314 (egcs-1.1.2 release)] on sunos5
>     Type "copyright", "credits" or "license" for more information.
>     >>> x = range(5)
>     >>> for i in x:
>     ...   print i * 4.55 + 1.0
>     ...
>     1.0
>     5.55
>     10.1
>     14.65
>     19.2
>     >>>
>
> Maybe somebody else has a better idea.

Combine the two...

---8<--- floatrange.py ---
#!/usr/bin/env python2.0

def float_range(*args):
    start = 0.0
    step = 1.0
    if (len(args) == 1):
        (stop,) = args
    elif (len(args) == 2):
        (start, stop) = args
    elif (len(args) == 3):
        (start, stop, step) = args
    else:
        raise TypeError, "float_range needs 1-3 float arguments"

    the_range = []
    steps = (stop-start)/step
    if steps != int(steps):
        steps = steps + 1.0
    for i in range(int(steps)):
        the_range.append(i*step+start)

    return the_range

if __name__ == '__main__':
    print "(1.0, 20.0, 4.55):", float_range(1.0, 20.0, 4.55)
    print "(0.0):", float_range(0.0)
    print "(4.0, 2.0, -1.0):", float_range(4.0, 2.0, -1.0)
    print "(2.0, 2.01, 0.001):", float_range(2.0, 2.01, 0.001)
    print "(-2.0, -4.0, -1.0):", float_range(-2.0, -4.0, -1.0)
    print "(-4.0, -2.0, 1.0):", float_range(-2.0, -4.0, -1.0)

--->8---

output is:
(1.0, 20.0, 4.55): [1.0, 5.55, 10.1, 14.65, 19.2]
(0.0): []
(4.0, 2.0, -1.0): [4.0, 3.0]
(2.0, 2.01, 0.001): [2.0, 2.001, 2.002, 2.003, 2.004, 2.005, 2.006, 2.007, 2.008, 2.009]
(-2.0, -4.0, -1.0): [-2.0, -3.0]
(-4.0, -2.0, 1.0): [-2.0, -3.0]


I'm not 100% sure the "steps" variable is being handled correctly, or
if it does the right thing in all cases... someone more math-matically
inclined should look at it closely.


- Bruce




From tmbrau00@centre.edu  Wed May 23 22:46:52 2001
From: tmbrau00@centre.edu (Timothy M. Brauch)
Date: Wed, 23 May 2001 17:46:52 -0400
Subject: [Tutor] Zope
Message-ID: <3B0C2FCC.22A641D2@centre.edu>

I'm just curious, does anyone use or know much about Zope?  I'm starting
to look at it st for fun (oh god, did I just say that?).

 - Tim


From deirdre@deirdre.net  Wed May 23 23:39:11 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Wed, 23 May 2001 15:39:11 -0700
Subject: [Tutor] Zope
In-Reply-To: <3B0C2FCC.22A641D2@centre.edu>
References: <3B0C2FCC.22A641D2@centre.edu>
Message-ID: <a05100e09b731ec691e67@[169.254.124.249]>

At 5:46 PM -0400 5/23/01, Timothy M. Brauch wrote:
>I'm just curious, does anyone use or know much about Zope?  I'm starting
>to look at it st for fun (oh god, did I just say that?).

Zope is so specific that you're better off getting info on a Zope 
list. That said, I know enough about it that I'm not a fan.

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From wilson@visi.com  Thu May 24 00:02:45 2001
From: wilson@visi.com (Timothy Wilson)
Date: Wed, 23 May 2001 18:02:45 -0500 (CDT)
Subject: [Tutor] Zope
In-Reply-To: <3B0C2FCC.22A641D2@centre.edu>
Message-ID: <Pine.GSO.4.21.0105231801460.8775-100000@isis.visi.com>

On Wed, 23 May 2001, Timothy M. Brauch wrote:

> I'm just curious, does anyone use or know much about Zope?  I'm starting
> to look at it st for fun (oh god, did I just say that?).

I'll second Deirdre's idea to check out zope.org and the zope lists more
closely. I use Zope a lot and I think it's great. We're using it a lot for
our school district's Web page.

-Tim

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



From kauphlyn@speakeasy.org  Thu May 24 00:32:21 2001
From: kauphlyn@speakeasy.org (Daniel Coughlin)
Date: Wed, 23 May 2001 16:32:21 -0700 (PDT)
Subject: [Tutor] HTTP_User_Agent?
In-Reply-To: <Pine.GSO.4.21.0105231801460.8775-100000@isis.visi.com>
Message-ID: <Pine.LNX.4.33L2.0105231613570.27261-100000@grace.speakeasy.net>

Hello Everyone,

I am trying to create a web client using python for use testing asp. My problem
is formulating a user agent header so that the server thinks my bot is
mozilla/4.0 compatible.

I have written a test asp page that returns the user agent varible. And this
works fine with an ordinary browser.

My python script contains the following line:

h.putheader('User-Agent', 'Mozilla/4.0')

However, when I test the script against my test page, no user_agent is returned
at all.

So I am guessing I have written it incorrectly. Does anyone out there know how
to do this sort of thing?

Many thanks in advance,

Daniel





From dyoo@hkn.eecs.berkeley.edu  Thu May 24 01:24:07 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 23 May 2001 17:24:07 -0700 (PDT)
Subject: [Tutor] Zope
In-Reply-To: <Pine.GSO.4.21.0105231801460.8775-100000@isis.visi.com>
Message-ID: <Pine.LNX.4.21.0105231721430.23219-100000@hkn.eecs.berkeley.edu>

On Wed, 23 May 2001, Timothy Wilson wrote:

> On Wed, 23 May 2001, Timothy M. Brauch wrote:
> 
> > I'm just curious, does anyone use or know much about Zope?  I'm starting
> > to look at it st for fun (oh god, did I just say that?).
> 
> I'll second Deirdre's idea to check out zope.org and the zope lists more
> closely. I use Zope a lot and I think it's great. We're using it a lot for
> our school district's Web page.


You might also find the zopenewbies web site to be helpful:

    http://weblogs.userland.com/zopeNewbies/

They have a bunch of tutorials and resources there that should help you
get started with it.  I've played a little bit with Zope too; it looks
very complicated for my poor brain... *grin*



From robnospam@jam.rr.com  Thu May 24 01:32:03 2001
From: robnospam@jam.rr.com (Rob Andrews)
Date: Wed, 23 May 2001 19:32:03 -0500
Subject: [Tutor] Zope
References: <Pine.LNX.4.21.0105231721430.23219-100000@hkn.eecs.berkeley.edu>
Message-ID: <3B0C5683.288DABFE@jam.rr.com>

Daniel Yoo wrote:
> 

> They have a bunch of tutorials and resources there that should help you
> get started with it.  I've played a little bit with Zope too; it looks
> very complicated for my poor brain... *grin*
> 

Okay, if Danny Yoo can say that, then I don't feel bad at all about not
being able to get anywhere with it.

Genuflecting,
Rob

-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From dsh8290@rit.edu  Thu May 24 02:19:53 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 23 May 2001 21:19:53 -0400
Subject: [Tutor] How Can Install Python 2.0 and 2.1 on the same machin e?
In-Reply-To: <007501c0e39f$f984a960$de00a8c0@planhouse5>; from rob@jam.rr.com on Wed, May 23, 2001 at 10:49:38AM -0500
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C0@mbtlipnt02.btlabs.bt.co.uk> <003c01c0e398$3bae80c0$de00a8c0@planhouse5> <20010523113226.B22312@harmony.cs.rit.edu> <007501c0e39f$f984a960$de00a8c0@planhouse5>
Message-ID: <20010523211953.A23058@harmony.cs.rit.edu>

On Wed, May 23, 2001 at 10:49:38AM -0500, Rob Andrews wrote:
| ----- Original Message -----
| From: "D-Man" <dsh8290@rit.edu>
| To: <tutor@python.org>
| Sent: Wednesday, May 23, 2001 10:32 AM
| 
| > On Wed, May 23, 2001 at 09:54:13AM -0500, Rob Andrews wrote:
| > | I must learn this trick. I know more arcane Windows features than anyone
| > | else I know, but this one is new to me.
| >
| > (I have a win2k box in front of me now so all steps are accurate for
| >  win2k,  win9x uses a slightly different naming scheme for menus and
| >  buttons but it is fairly similar and I will try my best to remember
| >  the right names)
<...>
| 
| I feel like I must have known this trick at some point in the distant past,
| but it's great to know it again. I just ran through it on a Win98SE box and
| it all worked just fine. Steps 10 and 11 on this box used Close instead of
| OK, but to get that close from memory is impressive, D-Man.

Thanks.  The "from memory" part was just the differences between win2k
and win98 (as stated above).  

-D



From wilson@visi.com  Thu May 24 03:07:14 2001
From: wilson@visi.com (Timothy Wilson)
Date: Wed, 23 May 2001 21:07:14 -0500 (CDT)
Subject: [Tutor] Zope
In-Reply-To: <3B0C5683.288DABFE@jam.rr.com>
Message-ID: <Pine.GSO.4.21.0105232106110.16554-100000@isis.visi.com>

On Wed, 23 May 2001, Rob Andrews wrote:

> > They have a bunch of tutorials and resources there that should help you
> > get started with it.  I've played a little bit with Zope too; it looks
> > very complicated for my poor brain... *grin*
> 
> Okay, if Danny Yoo can say that, then I don't feel bad at all about not
> being able to get anywhere with it.

I'd recommend having another look. If you haven't seen it already, you might
check out the soon to be published Zope Book (available with an open content
license) at http://www.zope.org/Members/michel/ZB/.

-Tim

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



From robnospam@jam.rr.com  Thu May 24 03:06:30 2001
From: robnospam@jam.rr.com (Rob Andrews)
Date: Wed, 23 May 2001 21:06:30 -0500
Subject: [Tutor] Zope
References: <Pine.GSO.4.21.0105232106110.16554-100000@isis.visi.com>
Message-ID: <3B0C6CA6.B9CFF6C3@jam.rr.com>

Timothy Wilson wrote:
> 
> On Wed, 23 May 2001, Rob Andrews wrote:
> 
> > > They have a bunch of tutorials and resources there that should help you
> > > get started with it.  I've played a little bit with Zope too; it looks
> > > very complicated for my poor brain... *grin*
> >
> > Okay, if Danny Yoo can say that, then I don't feel bad at all about not
> > being able to get anywhere with it.
> 
> I'd recommend having another look. If you haven't seen it already, you might
> check out the soon to be published Zope Book (available with an open content
> license) at http://www.zope.org/Members/michel/ZB/.
> 
> -Tim
> 

Actually, I was looking at it a couple of hours ago. I guess I'm a
lover, not a hacker!

hehe
Rob
-- 

You should have listened when your mother warned you about
Useless Python!
http://www.lowerstandard.com/python/pythonsource.html


From joejava@dragoncat.net  Thu May 24 04:47:06 2001
From: joejava@dragoncat.net (JRicker)
Date: Wed, 23 May 2001 23:47:06 -0400
Subject: [Tutor] Joining multiple lists
References: <Pine.GSO.4.21.0105232106110.16554-100000@isis.visi.com> <3B0C6CA6.B9CFF6C3@jam.rr.com>
Message-ID: <012101c0e405$a21aab00$a2804cd8@ceo>

I'm struggling with a little algorithm and I hope this list can shed
some light on it.  How would you go about joining a variable number of
lists together?  I can see two or three but for what I'm doing I can't
be forced to code for only a couple possibilities.  To clarify what I'm
doing a little, if you had three lists to join:

a = 1,2,3
b = 5,10,15
c = 20,30,40

The results would be something like:

((1,5,20), (1,5,30), (1,5,40), (1,10,20),
(1,10,30),(1,10,40),(1,15,20),(1,15,30)....etc).

Thanks for any advice.

Joel





From GADGILP@INFOTECH.ICICI.com  Thu May 24 06:09:09 2001
From: GADGILP@INFOTECH.ICICI.com (GADGIL PRASAD /INFRA/INFOTECH)
Date: Thu, 24 May 2001 10:39:09 +0530
Subject: [Tutor] OO scripting in python...
Message-ID: <718A0962DFC2D4119FF80008C7289E4701032D39@ICICIBACK3>

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

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

hello,

It seems you know odd perl OO style alright. The pseudo code example is 
really nice.

Back during c++, for study excercise, I had gone abt finding nouns from 
the problem statement, classes from them, and things like Object flow
diagrams, 
network diagrams etc for railway reservation system.

I used concise study material from my institute prepared from some of famous

OO design related books in turn.

I however found, that the diagrams by diff classmates used to be diff from
each 
other just on paper, implimenting in c++ was a diff story all together which
we 
weren't supposed to do (gratefully!). Instead we coded a very small progs
and 
things like 'date' class etc...

Any de facto book you would suggest ?


BTW alan, I already downloaded ur tut a few days back. One of the
articles due to which, I finally jumped in python fray.

/prasad

-----Original Message-----
From: Michael P. Reilly
[mailto:arcege@dsl092-074-184.bos1.dsl.speakeasy.net]
Sent: Wednesday, May 23, 2001 6:44 PM
To: GADGILP@INFOTECH.ICICI.com
Cc: tutor@python.org
Subject: Re: [Tutor] OO scripting in python...


GADGIL PRASAD     /INFRA/INFOTECH wrote
> I am coming from moderate C, basic C++ knowledge, and some perl exp.
> 
> For OO scripting, the basic concepts I learned during c++ seems
> rather unconnected when I read py-tutorial chapter 9 (classes). 
> It seems individual languages like perl, python implement various
> basic concepts of OO in such different ways, with such varying grammer,
> especially with perl, I was totally confused with 
> 'perltoot' (perl- tom christian's O. O. tutorial')
> It seemd c++ is rather straight forward than that.
> 
> I am not that confused after chapter 9, but I don't have OO coding exp., 
> and things are not very clear either.
> 
> Do I need to buy a book to be able to do OO programming
> in python ?
> 
> Can someone pl. explain oo coding in a 10,000 feet overview ?

Well.. first is that there are a lot of different philosophies for
object-oriented programming.  But how I tend to think about it is
that you don't want to think about the programming, concentrate on the
object-oriented design.

"Object-oriented" basically means that instead of procedures and data
structures, your program wants to think of objects and behaviors of
the objects.

One classic example program is a bank.  You have a teller and some
customers, a line to wait in, transactions for each.  In "normal"
(procedural) programming, you would have a structure for the teller,
one for the line (queue), and possibly structures for the transactions
since that data is more important than the customer information.

Something like:
  assign values to teller structure
  define queue for transactions
  check_for_new_transactions(queue)
  until queue is empty:
    next = get_next_transaction(, queue)
    process_transaction(teller, next)
    check_for_new_transactions(queue)
Here, the routines are typically geared to the precise data structure
being passed.

With object-oriented programmer, you would have a teller object, which
would have a queue (with a "interact_with_next_customer" method?), and
customer objects.  The behavior between the tellers and customers is more
important: customer must fill out deposit slip, teller must check account
information (right bank, valid account), customer must pass over money,
teller must return a receipt.

How about:
  create new teller object
  create new queue object, associated with teller object
  queue.check_for_new_users()
  until queue is empty:
    user = queue.get_next_user()
    teller.process_transaction(user)
    queue.check_for_new_users()

Now this doesn't seem all that different.  But let's replace the teller
with an ATM.  The transactions might be the same, but the routines called
would be very different in procedural programming (since most are are
typed languages).  However in object-oriented programming, we can make
an ATM object that behaves just like the teller object and the rest of
the program wouldn't have to change much.  Or if the user was now an
online user and the queue was from a webpage, then those could be more
easily changed as well.

What is commonly thrown about is "code reuse".  As you can see, if
designed correctly, things like the queue, user, teller can be reused
more easily than the functions in the first example (but all can be
reused if all designed correctly).

  -Arcege

PS: IMO, Perl makes things very confusing in general, and how they added
"objects" in Perl5 was especially so.  Congratulations on actually making
it through that document.

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


. 


------_=_NextPart_001_01C0E40F.A9F54600
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>RE: [Tutor] OO scripting in python...</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>hello,</FONT>
</P>

<P><FONT SIZE=3D2>It seems you know odd perl OO style alright. The =
pseudo code example is </FONT>
<BR><FONT SIZE=3D2>really nice.</FONT>
</P>

<P><FONT SIZE=3D2>Back during c++, for study excercise, I had gone abt =
finding nouns from </FONT>
<BR><FONT SIZE=3D2>the problem statement, classes from them, and things =
like Object flow diagrams, </FONT>
<BR><FONT SIZE=3D2>network diagrams etc for railway reservation =
system.</FONT>
</P>

<P><FONT SIZE=3D2>I used concise study material from my institute =
prepared from some of famous </FONT>
<BR><FONT SIZE=3D2>OO design related books in turn.</FONT>
</P>

<P><FONT SIZE=3D2>I however found, that the diagrams by diff classmates =
used to be diff from each </FONT>
<BR><FONT SIZE=3D2>other just on paper, implimenting in c++ was a diff =
story all together which we </FONT>
<BR><FONT SIZE=3D2>weren't supposed to do (gratefully!). Instead we =
coded a very small progs and </FONT>
<BR><FONT SIZE=3D2>things like 'date' class etc...</FONT>
</P>

<P><FONT SIZE=3D2>Any de facto book you would suggest ?</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>BTW alan, I already downloaded ur tut a few days =
back. One of the</FONT>
<BR><FONT SIZE=3D2>articles due to which, I finally jumped in python =
fray.</FONT>
</P>

<P><FONT SIZE=3D2>/prasad</FONT>
</P>

<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: Michael P. Reilly</FONT>
<BR><FONT SIZE=3D2>[<A =
HREF=3D"mailto:arcege@dsl092-074-184.bos1.dsl.speakeasy.net">mailto:arce=
ge@dsl092-074-184.bos1.dsl.speakeasy.net</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: Wednesday, May 23, 2001 6:44 PM</FONT>
<BR><FONT SIZE=3D2>To: GADGILP@INFOTECH.ICICI.com</FONT>
<BR><FONT SIZE=3D2>Cc: tutor@python.org</FONT>
<BR><FONT SIZE=3D2>Subject: Re: [Tutor] OO scripting in =
python...</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>GADGIL PRASAD&nbsp;&nbsp;&nbsp;&nbsp; /INFRA/INFOTECH =
wrote</FONT>
<BR><FONT SIZE=3D2>&gt; I am coming from moderate C, basic C++ =
knowledge, and some perl exp.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; For OO scripting, the basic concepts I learned =
during c++ seems</FONT>
<BR><FONT SIZE=3D2>&gt; rather unconnected when I read py-tutorial =
chapter 9 (classes). </FONT>
<BR><FONT SIZE=3D2>&gt; It seems individual languages like perl, python =
implement various</FONT>
<BR><FONT SIZE=3D2>&gt; basic concepts of OO in such different ways, =
with such varying grammer,</FONT>
<BR><FONT SIZE=3D2>&gt; especially with perl, I was totally confused =
with </FONT>
<BR><FONT SIZE=3D2>&gt; 'perltoot' (perl- tom christian's O. O. =
tutorial')</FONT>
<BR><FONT SIZE=3D2>&gt; It seemd c++ is rather straight forward than =
that.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; I am not that confused after chapter 9, but I =
don't have OO coding exp., </FONT>
<BR><FONT SIZE=3D2>&gt; and things are not very clear either.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Do I need to buy a book to be able to do OO =
programming</FONT>
<BR><FONT SIZE=3D2>&gt; in python ?</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Can someone pl. explain oo coding in a 10,000 =
feet overview ?</FONT>
</P>

<P><FONT SIZE=3D2>Well.. first is that there are a lot of different =
philosophies for</FONT>
<BR><FONT SIZE=3D2>object-oriented programming.&nbsp; But how I tend to =
think about it is</FONT>
<BR><FONT SIZE=3D2>that you don't want to think about the programming, =
concentrate on the</FONT>
<BR><FONT SIZE=3D2>object-oriented design.</FONT>
</P>

<P><FONT SIZE=3D2>&quot;Object-oriented&quot; basically means that =
instead of procedures and data</FONT>
<BR><FONT SIZE=3D2>structures, your program wants to think of objects =
and behaviors of</FONT>
<BR><FONT SIZE=3D2>the objects.</FONT>
</P>

<P><FONT SIZE=3D2>One classic example program is a bank.&nbsp; You have =
a teller and some</FONT>
<BR><FONT SIZE=3D2>customers, a line to wait in, transactions for =
each.&nbsp; In &quot;normal&quot;</FONT>
<BR><FONT SIZE=3D2>(procedural) programming, you would have a structure =
for the teller,</FONT>
<BR><FONT SIZE=3D2>one for the line (queue), and possibly structures =
for the transactions</FONT>
<BR><FONT SIZE=3D2>since that data is more important than the customer =
information.</FONT>
</P>

<P><FONT SIZE=3D2>Something like:</FONT>
<BR><FONT SIZE=3D2>&nbsp; assign values to teller structure</FONT>
<BR><FONT SIZE=3D2>&nbsp; define queue for transactions</FONT>
<BR><FONT SIZE=3D2>&nbsp; check_for_new_transactions(queue)</FONT>
<BR><FONT SIZE=3D2>&nbsp; until queue is empty:</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; next =3D get_next_transaction(, =
queue)</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; process_transaction(teller, =
next)</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; =
check_for_new_transactions(queue)</FONT>
<BR><FONT SIZE=3D2>Here, the routines are typically geared to the =
precise data structure</FONT>
<BR><FONT SIZE=3D2>being passed.</FONT>
</P>

<P><FONT SIZE=3D2>With object-oriented programmer, you would have a =
teller object, which</FONT>
<BR><FONT SIZE=3D2>would have a queue (with a =
&quot;interact_with_next_customer&quot; method?), and</FONT>
<BR><FONT SIZE=3D2>customer objects.&nbsp; The behavior between the =
tellers and customers is more</FONT>
<BR><FONT SIZE=3D2>important: customer must fill out deposit slip, =
teller must check account</FONT>
<BR><FONT SIZE=3D2>information (right bank, valid account), customer =
must pass over money,</FONT>
<BR><FONT SIZE=3D2>teller must return a receipt.</FONT>
</P>

<P><FONT SIZE=3D2>How about:</FONT>
<BR><FONT SIZE=3D2>&nbsp; create new teller object</FONT>
<BR><FONT SIZE=3D2>&nbsp; create new queue object, associated with =
teller object</FONT>
<BR><FONT SIZE=3D2>&nbsp; queue.check_for_new_users()</FONT>
<BR><FONT SIZE=3D2>&nbsp; until queue is empty:</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; user =3D =
queue.get_next_user()</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; =
teller.process_transaction(user)</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; =
queue.check_for_new_users()</FONT>
</P>

<P><FONT SIZE=3D2>Now this doesn't seem all that different.&nbsp; But =
let's replace the teller</FONT>
<BR><FONT SIZE=3D2>with an ATM.&nbsp; The transactions might be the =
same, but the routines called</FONT>
<BR><FONT SIZE=3D2>would be very different in procedural programming =
(since most are are</FONT>
<BR><FONT SIZE=3D2>typed languages).&nbsp; However in object-oriented =
programming, we can make</FONT>
<BR><FONT SIZE=3D2>an ATM object that behaves just like the teller =
object and the rest of</FONT>
<BR><FONT SIZE=3D2>the program wouldn't have to change much.&nbsp; Or =
if the user was now an</FONT>
<BR><FONT SIZE=3D2>online user and the queue was from a webpage, then =
those could be more</FONT>
<BR><FONT SIZE=3D2>easily changed as well.</FONT>
</P>

<P><FONT SIZE=3D2>What is commonly thrown about is &quot;code =
reuse&quot;.&nbsp; As you can see, if</FONT>
<BR><FONT SIZE=3D2>designed correctly, things like the queue, user, =
teller can be reused</FONT>
<BR><FONT SIZE=3D2>more easily than the functions in the first example =
(but all can be</FONT>
<BR><FONT SIZE=3D2>reused if all designed correctly).</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; -Arcege</FONT>
</P>

<P><FONT SIZE=3D2>PS: IMO, Perl makes things very confusing in general, =
and how they added</FONT>
<BR><FONT SIZE=3D2>&quot;objects&quot; in Perl5 was especially =
so.&nbsp; Congratulations on actually making</FONT>
<BR><FONT SIZE=3D2>it through that document.</FONT>
</P>

<P><FONT SIZE=3D2>-- </FONT>
<BR><FONT =
SIZE=3D2>+----------------------------------+---------------------------=
--------+</FONT>
<BR><FONT SIZE=3D2>| Michael P. =
Reilly&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; | =
arcege@speakeasy.net&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp; |</FONT>
</P>
<BR>

<P><B><FONT SIZE=3D2>.. </FONT></B>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C0E40F.A9F54600--


From sheila@thinkspot.net  Thu May 24 05:30:34 2001
From: sheila@thinkspot.net (Sheila King)
Date: Wed, 23 May 2001 21:30:34 -0700
Subject: [Tutor] Joining multiple lists
In-Reply-To: <012101c0e405$a21aab00$a2804cd8@ceo>
References: <Pine.GSO.4.21.0105232106110.16554-100000@isis.visi.com> <3B0C6CA6.B9CFF6C3@jam.rr.com> <012101c0e405$a21aab00$a2804cd8@ceo>
Message-ID: <95F3075253@kserver.org>

First off, those aren't lists you're working with. Those are tuples.

Anyhow, it looks like what you want to do, is list all possible permutations of
the combinations of the elements in a with the elements in b with the elements
in c, keeping them in the order (a, b, c) ???

Try this snipped of code, after assigning a, b, and c as you have done below:

>>> for x in a:
... 	for y in b:
... 		for z in c:
... 			print "(x, y, z) = ", (x, y, z)

See what happens when you run that.

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


On Wed, 23 May 2001 23:47:06 -0400, "JRicker" <joejava@dragoncat.net>  wrote
about [Tutor] Joining multiple lists:

:I'm struggling with a little algorithm and I hope this list can shed
:some light on it.  How would you go about joining a variable number of
:lists together?  I can see two or three but for what I'm doing I can't
:be forced to code for only a couple possibilities.  To clarify what I'm
:doing a little, if you had three lists to join:
:
:a = 1,2,3
:b = 5,10,15
:c = 20,30,40
:
:The results would be something like:
:
:((1,5,20), (1,5,30), (1,5,40), (1,10,20),
:(1,10,30),(1,10,40),(1,15,20),(1,15,30)....etc).
:
:Thanks for any advice.
:
:Joel
:
:
:
:
:_______________________________________________
:Tutor maillist  -  Tutor@python.org
:http://mail.python.org/mailman/listinfo/tutor



From dyoo@hkn.eecs.berkeley.edu  Thu May 24 06:24:50 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 23 May 2001 22:24:50 -0700 (PDT)
Subject: [Tutor] Joining multiple lists
In-Reply-To: <012101c0e405$a21aab00$a2804cd8@ceo>
Message-ID: <Pine.LNX.4.21.0105232204310.27323-100000@hkn.eecs.berkeley.edu>

On Wed, 23 May 2001, JRicker wrote:

> I'm struggling with a little algorithm and I hope this list can shed
> some light on it.  How would you go about joining a variable number of
> lists together?  I can see two or three but for what I'm doing I can't
> be forced to code for only a couple possibilities.  To clarify what I'm
> doing a little, if you had three lists to join:
> 
> a = 1,2,3
> b = 5,10,15
> c = 20,30,40
> 
> The results would be something like:
> 
> ((1,5,20), (1,5,30), (1,5,40), (1,10,20),
> (1,10,30),(1,10,40),(1,15,20),(1,15,30)....etc).

It will be helpful to try doing it with two lists first.  If we can do it
with two lists, then doing it with multiple lists shouldn't be bad.

Let's pretend that we do have something that gives all possible pairs from
two lists, and call this hypothetical function "allPossiblePairs()".  
Since we're in a fantasy, let's also pretend that we know how it will
work:

###
>>> x = allPossiblePairs([1, 2, 3], [5, 10, 15])
>>> x
[(1, 5), (1, 10), (1, 15),
 (2, 5), (2, 10), (2, 15),
 (3, 5), (3, 10), (3, 15)]
###

There's a reason reason why doing it with two lists is useful: what
happens when we try doing something like this?

###
>>> a = 1, 2, 3
>>> b = 5, 10, 15
>>> c = 20, 30, 40
>>> list1 = allPossiblePairs(b, c)
>>> list2 = allPossiblePairs(a, list1)
###

What comes out won't exactly look like what we want with three lists, but
it will be very close: there will be some extra parentheses in there.  
For example, list2 will probably contain these sort of elements:

    [(1, (5, 20)),  (1, (5, 30)),  ...]

and you can probably do something to fix it.

If we add an additional list 'd' and try to take all possible combinations
of four lists, let's see what that code might look like:

###
>>> d = 100, 200, 300
>>> list3 = allPossiblePairs(d, list2)
###

Again, we'll have too many parentheses in each element, but it's darn
close to what you'll want.  To fix those extra parens, I think that Alan
Gauld's tutorial mentions a way of "flattening" anything that looks like:

    (1, (2, (3, 4))) ===>flattening===>  (1, 2, 3, 4)

but I can't find the page.

This should give you an idea about how to make your program work for lists
of any length.  Good luck!



From juno@gamefire.com  Thu May 24 06:33:24 2001
From: juno@gamefire.com (juno@gamefire.com)
Date: Wed, 23 May 2001 22:33:24 -0700
Subject: [Tutor] HTTP_User_Agent?
In-Reply-To: <Pine.LNX.4.33L2.0105231613570.27261-100000@grace.speakeasy.net>
Message-ID: <DEEGIKBPAICAIOPICOHKOEMPCBAA.juno@gamefire.com>

Hey Daniel,
I had the same problem until I removed the 4.0, then it worked. Try this:

h.putheader('User-Agent', 'Mozilla')

That should do it.

Hunter


-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Daniel Coughlin
Sent: Wednesday, May 23, 2001 4:32 PM
To: tutor@python.org
Subject: [Tutor] HTTP_User_Agent?

Hello Everyone,

I am trying to create a web client using python for use testing asp. My
problem
is formulating a user agent header so that the server thinks my bot is
mozilla/4.0 compatible.

I have written a test asp page that returns the user agent varible. And this
works fine with an ordinary browser.

My python script contains the following line:

h.putheader('User-Agent', 'Mozilla/4.0')

However, when I test the script against my test page, no user_agent is
returned
at all.

So I am guessing I have written it incorrectly. Does anyone out there know
how
to do this sort of thing?

Many thanks in advance,

Daniel




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



From dyoo@hkn.eecs.berkeley.edu  Thu May 24 06:31:47 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 23 May 2001 22:31:47 -0700 (PDT)
Subject: [Tutor] Joining multiple lists
In-Reply-To: <Pine.LNX.4.21.0105232204310.27323-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.21.0105232228560.27323-100000@hkn.eecs.berkeley.edu>

> Again, we'll have too many parentheses in each element, but it's darn
> close to what you'll want.  To fix those extra parens, I think that Alan
> Gauld's tutorial mentions a way of "flattening" anything that looks like:
> 
>     (1, (2, (3, 4))) ===>flattening===>  (1, 2, 3, 4)
> 
> but I can't find the page.

I did, however, find one of the old messages that talked about list
flattening here:

    http://aspn.activestate.com/ASPN/Mail/msg/python-Tutor%3A454781

Good luck to you!



From walterv@jps.net  Thu May 24 07:20:30 2001
From: walterv@jps.net (Walter Vannini)
Date: Wed, 23 May 2001 23:20:30 -0700
Subject: [Tutor] Joining multiple lists
References: <Pine.GSO.4.21.0105232106110.16554-100000@isis.visi.com>
 <3B0C6CA6.B9CFF6C3@jam.rr.com> <012101c0e405$a21aab00$a2804cd8@ceo>
Message-ID: <3B0CA82E.F6DE88A1@jps.net>

Here's one way to do it, using reduce.
The idea behind the solution is to find a solution
for two lists. Then, find a way to combine that solution,
with reduce, to get a solution for a variable number of lists.
This is a general technique that can be used in many situations.

def CrossProduct ( PartialProduct, rhs ):
        return [ i+(j,) for i in PartialProduct for j in rhs ]
ListOfLists = [ [1,2,3] , [5,10,15], [20,30,40] ]
Answer = reduce ( CrossProduct, ListOfLists, [()] )
for tup in Answer: print tup

Running the above code will get you:
(1, 5, 20)
(1, 5, 30)
(1, 5, 40)
(1, 10, 20)
(1, 10, 30)
(1, 10, 40)
(1, 15, 20)
(1, 15, 30)
(1, 15, 40)
(2, 5, 20)
(2, 5, 30)
(2, 5, 40)
(2, 10, 20)
(2, 10, 30)
(2, 10, 40)
(2, 15, 20)
(2, 15, 30)
(2, 15, 40)
(3, 5, 20)
(3, 5, 30)
(3, 5, 40)
(3, 10, 20)
(3, 10, 30)
(3, 10, 40)
(3, 15, 20)
(3, 15, 30)
(3, 15, 40)

Walter.

> I'm struggling with a little algorithm and I hope this list can shed
> some light on it.  How would you go about joining a variable number of
> lists together?  I can see two or three but for what I'm doing I can't
> be forced to code for only a couple possibilities.  To clarify what I'm
> doing a little, if you had three lists to join:
> 
> a = 1,2,3
> b = 5,10,15
> c = 20,30,40
> 
> The results would be something like:
> 
> ((1,5,20), (1,5,30), (1,5,40), (1,10,20),
> (1,10,30),(1,10,40),(1,15,20),(1,15,30)....etc).
> 
> Thanks for any advice.
> 
> Joel


From bsass@freenet.edmonton.ab.ca  Thu May 24 07:33:54 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Thu, 24 May 2001 00:33:54 -0600 (MDT)
Subject: [Tutor] re: range function
In-Reply-To: <Pine.LNX.4.33.0105231334210.26138-100000@bms>
Message-ID: <Pine.LNX.4.33.0105232330200.26604-100000@bms>

On Wed, 23 May 2001, Bruce Sass wrote:

Here is a mistake I'm not going to make again.

I said...

> Combine the two...
>
> ---8<--- floatrange.py ---
> #!/usr/bin/env python2.0
<...>
>     steps = (stop-start)/step
>     if steps != int(steps):
>         steps = steps + 1.0
>     for i in range(int(steps)):
>         the_range.append(i*step+start)
<...>
> --->8---
>
> output is:
> (1.0, 20.0, 4.55): [1.0, 5.55, 10.1, 14.65, 19.2]

The only problem is I did it while in xemacs, using ^c^c, and the
default python interpreter is 1.5.2 -- the #! was having no effect
'cause xemacs was passing the buffer onto /usr/bin/python.  When I
pointed "python" to "python2.1" I got the ugly representation again.

Since...

>>> 5.5499999999999998 == 5.55
1

...is it anything more than a cosmetic issue when print-ing, e.g., a
list of floats (rather than the items in a list of floats).


- Bruce




From kauphlyn@speakeasy.org  Thu May 24 08:40:54 2001
From: kauphlyn@speakeasy.org (Daniel Coughlin)
Date: Thu, 24 May 2001 00:40:54 -0700 (PDT)
Subject: [Tutor] HTTP_User_Agent?
In-Reply-To: <DEEGIKBPAICAIOPICOHKOEMPCBAA.juno@gamefire.com>
Message-ID: <Pine.LNX.4.33L2.0105240030040.14841-100000@grace.speakeasy.net>

Thank you, Hunter.

I now also realise I was using a backslash instead of a
forward slash (for how long will this plague me!!!).

The script now does return a user agent string.

Any idea what I should put as the user agent to mimic recent versions of
Internet Explorer or Netscape?


On Wed, 23 May 2001, juno@gamefire.com wrote:

> Hey Daniel,
> I had the same problem until I removed the 4.0, then it worked. Try this:
>
> h.putheader('User-Agent', 'Mozilla')
>
> That should do it.
>
> Hunter
>
>
> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Daniel Coughlin
> Sent: Wednesday, May 23, 2001 4:32 PM
> To: tutor@python.org
> Subject: [Tutor] HTTP_User_Agent?
>
> Hello Everyone,
>
> I am trying to create a web client using python for use testing asp. My
> problem
> is formulating a user agent header so that the server thinks my bot is
> mozilla/4.0 compatible.
>
> I have written a test asp page that returns the user agent varible. And this
> works fine with an ordinary browser.
>
> My python script contains the following line:
>
> h.putheader('User-Agent', 'Mozilla/4.0')
>
> However, when I test the script against my test page, no user_agent is
> returned
> at all.
>
> So I am guessing I have written it incorrectly. Does anyone out there know
> how
> to do this sort of thing?
>
> Many thanks in advance,
>
> Daniel
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From alan.gauld@bt.com  Thu May 24 10:23:54 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 24 May 2001 10:23:54 +0100
Subject: [Tutor] re: range function
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C8@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C0E433.409C8B40
Content-type: text/plain; charset="iso-8859-1"

>  how would I go about creating a range for float-type   
>  numbers?   
 
A range is just a list. range returns a list of integers but to turn them
into floats just use map:
 
for f in map(float, range(10000)):
    print f

------_=_NextPart_001_01C0E433.409C8B40
Content-type: text/html; charset="iso-8859-1"

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


<META content="MSHTML 5.00.3013.2600" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN 
class=350442609-24052001>&gt; &nbsp;</SPAN>how would I go about creating a range 
for float-type&nbsp;<SPAN class=350442609-24052001>&nbsp; 
</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN 
class=350442609-24052001>&gt; &nbsp;</SPAN>numbers?&nbsp;&nbsp;<SPAN 
class=350442609-24052001>&nbsp;</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=sans-serif size=2><SPAN 
class=350442609-24052001></SPAN></FONT>&nbsp;</DIV>
<DIV 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px"><FONT 
color=#0000ff face="Courier New" size=2><SPAN class=350442609-24052001>A range 
is just a list. range returns a list of integers but to turn them into floats 
just use map:</SPAN></FONT></DIV>
<DIV 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px"><FONT 
color=#0000ff face="Courier New" size=2><SPAN 
class=350442609-24052001></SPAN></FONT>&nbsp;</DIV>
<DIV 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px"><FONT 
color=#0000ff face="Courier New" size=2><SPAN class=350442609-24052001>for f in 
map(float, range(10000)):</SPAN></FONT></DIV>
<DIV 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px"><FONT 
color=#0000ff face="Courier New" size=2><SPAN 
class=350442609-24052001>&nbsp;&nbsp;&nbsp; print 
f</SPAN></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C0E433.409C8B40--


From alan.gauld@bt.com  Thu May 24 10:41:21 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 24 May 2001 10:41:21 +0100
Subject: [Tutor] floating ranges again
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7C9@mbtlipnt02.btlabs.bt.co.uk>

Sorry I deleted the original thread message but
was playing around with a general purpose floating point 
range function and cxame up with the following. It works 
for ints or floats. You give it an initial value, the 
number of entries you want(which could be the difference 
of upper and lower) and the step value:

>>> def frange(first, number, step):
...     return map(lambda n, f=first, s=step: f+(n*s),
...                range(number))
...
>>> frange(1,10,1)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> frange(5,5,2)
[5, 7, 9, 11, 13]
>>> frange(3,10,2.5)
[3.0, 5.5, 8.0, 10.5, 13.0, 15.5, 18.0, 20.5, 23.0, 25.5]
>>> frange(5,7,4.5)
[5.0, 9.5, 14.0, 18.5, 23.0, 27.5, 32.0]
>>> frange(2.5,(7.5-2.5),1)
[2.5, 3.5, 4.5, 5.5, 6.5]
>>>

Sorry, could resist playing with that one :-)

Alan G


From alan.gauld@bt.com  Thu May 24 11:07:11 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 24 May 2001 11:07:11 +0100
Subject: [Tutor] Joining multiple lists
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7CB@mbtlipnt02.btlabs.bt.co.uk>

> a = 1,2,3
> b = 5,10,15
> c = 20,30,40

These aren't lists but if you enclose them in [] they 
would be. In which case:

new = a+b+c

should do the trick.

> 
> The results would be something like:
> 
> ((1,5,20), (1,5,30), (1,5,40), (1,10,20),
> (1,10,30),(1,10,40),(1,15,20),(1,15,30)....etc).

Ah, that's different, you want all the permutations.

I think for that you need nested for loops, 
something like:

result = []
for indexA in len(a):
   for indexB in len(b):
      for indexC in len(c):
         result.append((a[indexA],b[indexB],c[index[C]))

Maybe the new listcomprehensions can do it more easily 
- I think they can but haven't played withb them enough...   

Alan G.


From arcege@speakeasy.net  Thu May 24 11:33:36 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 24 May 2001 06:33:36 -0400 (EDT)
Subject: [Tutor] HTTP_User_Agent?
In-Reply-To: <Pine.LNX.4.33L2.0105240030040.14841-100000@grace.speakeasy.net> from "Daniel Coughlin" at May 24, 2001 12:40:54 AM
Message-ID: <200105241033.f4OAXat03784@dsl092-074-184.bos1.dsl.speakeasy.net>

Daniel Coughlin wrote
> 
> 
> Thank you, Hunter.
> 
> I now also realise I was using a backslash instead of a
> forward slash (for how long will this plague me!!!).
> 
> The script now does return a user agent string.
> 
> Any idea what I should put as the user agent to mimic recent versions of
> Internet Explorer or Netscape?

You could easily get the User-Agent values from the browsers by whipping
up your own little web server.

import BaseHTTPServer
class EnvHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  def go_GET(self):
    self.send_response(200) # things are okay
    self.send_header('Content-type', 'text/plain')
    self.end_headers()
    # now print out the HTTP headers from the client (including user-agent)
    keys = self.headers.keys()
    keys.sort()
    for key in keys:
      self.wfile.write('%s: %s\n' % (key, self.headers[key]))
# now handle one such request on "http://localhost:8080/"
BaseHTTPServer.HTTPServer(('', 8080), EnvHandler).handle_request()

You could run this for each client to get the basic parameters.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From lsloan@umich.edu  Thu May 24 11:34:16 2001
From: lsloan@umich.edu (Lance E Sloan)
Date: Thu, 24 May 2001 06:34:16 -0400
Subject: [Tutor] re: range function
In-Reply-To: Your message of "Wed, 23 May 2001 15:09:31 MDT."
 <Pine.LNX.4.33.0105231334210.26138-100000@bms>
Message-ID: <200105241034.GAA02002@birds.us.itd.umich.edu>

Bruce Sass wrote:
> On Wed, 23 May 2001, Lance E Sloan wrote:
> > Actually, I came up with an idea that works on its own, but when I
> > try to put this logic into my function, I get the same results as above.
> > ...
> > Maybe somebody else has a better idea.
> 
> Combine the two...

Yeah, I did.  Like I said, I got the same results.  I'll have to compare
mine to yours and see where I went wrong.

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"


From joejava@dragoncat.net  Thu May 24 13:50:40 2001
From: joejava@dragoncat.net (JRicker)
Date: Thu, 24 May 2001 08:50:40 -0400
Subject: [Tutor] Joining multiple lists
References: <Pine.LNX.4.21.0105232228560.27323-100000@hkn.eecs.berkeley.edu>
Message-ID: <004201c0e450$262a5900$78a1d6d1@ceo>

Thanks everyone for their help.

Thats right, I meant brackets instead of parenthesis but I was a bit
tired when I posted that message and wasn't thinking about the meaning
behind my parenthesis -- I more using it as an example rather than true
python code which I should be thinking more in when posted.

Plus the answer that alan gave, I was looing for my along the lines of
what Daniel and Water came up with, not knowing how many loops I would
need until runtime.

Thanks again everyone,
Joel




From dsh8290@rit.edu  Thu May 24 14:40:43 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 24 May 2001 09:40:43 -0400
Subject: [Tutor] re: range function
In-Reply-To: <Pine.LNX.4.33.0105232330200.26604-100000@bms>; from bsass@freenet.edmonton.ab.ca on Thu, May 24, 2001 at 12:33:54AM -0600
References: <Pine.LNX.4.33.0105231334210.26138-100000@bms> <Pine.LNX.4.33.0105232330200.26604-100000@bms>
Message-ID: <20010524094042.A25363@harmony.cs.rit.edu>

On Thu, May 24, 2001 at 12:33:54AM -0600, Bruce Sass wrote:
| On Wed, 23 May 2001, Bruce Sass wrote:
| 
| Here is a mistake I'm not going to make again.
...
| The only problem is I did it while in xemacs, using ^c^c, and the

^c^c? I thought it was C-c C-c ;-).  (I'm just teasing you, I don't
remember the emacs keys anymore)

| default python interpreter is 1.5.2 -- the #! was having no effect
| 'cause xemacs was passing the buffer onto /usr/bin/python.  When I
| pointed "python" to "python2.1" I got the ugly representation again.
| 
| Since...
| 
| >>> 5.5499999999999998 == 5.55
| 1
| 
| ...is it anything more than a cosmetic issue when print-ing, e.g., a
| list of floats (rather than the items in a list of floats).

Yes -- the actual number in memory hasn't changed.  If you look at my
example I used string interpolation to truncate the numbers at 2
decimal points when I printed my results.

If you want a description of the IEEE 754 floating point
representation I can give it to you (I had to implement addition,
subtraction and multiplication on single precision IEEE 754 floats in
m68k assembly for a lab, but I didn't have enough time to do the
multiplication)

-D



From randrews@planhouse.com  Thu May 24 15:46:08 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Thu, 24 May 2001 09:46:08 -0500
Subject: [Tutor] Zope
In-Reply-To: <3B0C6CA6.B9CFF6C3@jam.rr.com>
Message-ID: <000801c0e460$452638a0$de00a8c0@planhouse5>

3;-> -----Original Message-----

<snip />

3;-> > > Okay, if Danny Yoo can say that, then I don't feel bad
3;-> at all about not
3;-> > > being able to get anywhere with it.
3;-> >
3;-> > I'd recommend having another look. If you haven't seen
3;-> it already, you might
3;-> > check out the soon to be published Zope Book (available
3;-> with an open content
3;-> > license) at http://www.zope.org/Members/michel/ZB/.
3;-> >
3;-> > -Tim
3;-> >
3;->
3;-> Actually, I was looking at it a couple of hours ago. I guess I'm a
3;-> lover, not a hacker!
3;->
3;-> hehe
3;-> Rob
3;-> --
3;->

Well, despite my "lover, not a hacker" status, I came in to work and had no
trouble getting Zope to install and execute on a machine here. I'm guessing
that my box at the house has too esoteric a configuration. Zope just
wouldn't run start.bat successfully at all there.

Rob

If Bubba can program, I can too!
http://www.lowerstandard.com/python/pythonsource.html



From curtis.larsen@Covance.Com  Thu May 24 17:20:31 2001
From: curtis.larsen@Covance.Com (Curtis Larsen)
Date: Thu, 24 May 2001 11:20:31 -0500
Subject: [Tutor] Silly Object Namespace Questions
Message-ID: <sb0cee98.024@madis2.truax.covance.com>

<Sigh> OK I'm still trying to wrap my head around class namespace(s),
and I know this is gonna sound dumb, (BUT) I have a few questions about
the following example:

class object1:
   def __init__(self):
      a = 10
      self.x = 1
   def doit(self):
      self.str = "This is a string"
      wumpus = "Gotcha!"
      print wumpus


Doing a "dir(x)" produces  "['x']", and after running "self.doit()"
(which prints "Gotcha!"), "dir(x)" gives "['str', 'x']".  Okay, soooo:


1. What namespace(s) do "x", "a", "str", and "wumpus" respectively
belong to?

2. Why isn't "a" visible?  (I know it relates to #1.)

3. Although (I believe) "x" and "str" are "safe" from modification,
would another instance of "object1" change the value of "a" or
"wumpus"?

4. Is using "undeclared" variables such as "a" and "wumpus" the best
way to temporarily manipulate data within an object instance without
"publishing" that data for external use?  (For example, you can print
"wumpus", or do calculations on "a", but no one can get at them
externally.)

5. Is there anything "wrong" with defining "x" on it's own?  (I've
usually seen such defined in the parm list of "__init__".)

6. What function(s) can I use to see/list methods such as "doit" within
an instance?  ("vars()" and "dir()" don't do it.)



Thanks!
Curtis



-----------------------------------------------------
Confidentiality Notice: This e-mail transmission 
may contain confidential or legally privileged 
information that is intended only for the individual 
or entity named in the e-mail address. If you are not 
the intended recipient, you are hereby notified that 
any disclosure, copying, distribution, or reliance 
upon the contents of this e-mail is strictly prohibited. 

If you have received this e-mail transmission in error, 
please reply to the sender, so that we can arrange 
for proper delivery, and then please delete the message 
from your inbox. Thank you.


From alan.gauld@bt.com  Thu May 24 17:27:12 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 24 May 2001 17:27:12 +0100
Subject: [Tutor] Joining multiple lists
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7D0@mbtlipnt02.btlabs.bt.co.uk>

> close to what you'll want.  To fix those extra parens, I 
> think that Alan
> Gauld's tutorial mentions a way of "flattening" anything that 
> looks like:
> 
>     (1, (2, (3, 4))) ===>flattening===>  (1, 2, 3, 4)
> 
> but I can't find the page.

Its the recursion topic.

But that won't give himn what he asked for which was a set 
of tuples for each permutation of his lists. I think that 
really needs the nested loops approach.

Alan G


From shaleh@valinux.com  Thu May 24 17:41:35 2001
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Thu, 24 May 2001 09:41:35 -0700 (PDT)
Subject: [Tutor] Silly Object Namespace Questions
In-Reply-To: <sb0cee98.024@madis2.truax.covance.com>
Message-ID: <XFMail.20010524094135.shaleh@valinux.com>

On 24-May-2001 Curtis Larsen wrote:
> <Sigh> OK I'm still trying to wrap my head around class namespace(s),
> and I know this is gonna sound dumb, (BUT) I have a few questions about
> the following example:
> 
> class object1:
>    def __init__(self):
>       a = 10
>       self.x = 1
>    def doit(self):
>       self.str = "This is a string"
>       wumpus = "Gotcha!"
>       print wumpus
> 
> 
> Doing a "dir(x)" produces  "['x']", and after running "self.doit()"
> (which prints "Gotcha!"), "dir(x)" gives "['str', 'x']".  Okay, soooo:
> 
> 
> 1. What namespace(s) do "x", "a", "str", and "wumpus" respectively
> belong to?
> 

x and str are variables owned by the class instance 'self'.  a and wumpus are
temporary variables that live as long as the namespace where they are declared
(i.e. the function call).  Every time doit() is called a new variable called
'wumpus' is defined.  Same goes for __init__() and 'a'.

> 2. Why isn't "a" visible?  (I know it relates to #1.)
> 

because it is a local variable in the function.

> 3. Although (I believe) "x" and "str" are "safe" from modification,
> would another instance of "object1" change the value of "a" or
> "wumpus"?
> 

yes, but not for why you are thinking.  Each object's doit() will create a new
variable called 'wumpus' when called.  This variable lives for as long as it
takes for doit() to execute, then it goes away.

> 4. Is using "undeclared" variables such as "a" and "wumpus" the best
> way to temporarily manipulate data within an object instance without
> "publishing" that data for external use?  (For example, you can print
> "wumpus", or do calculations on "a", but no one can get at them
> externally.)
> 

depends on what you are trying to do.  If you want temporary variables, then
yes.  If you need the variable to live between function calls, then no.

> 5. Is there anything "wrong" with defining "x" on it's own?  (I've
> usually seen such defined in the parm list of "__init__".)
> 

Putting it in the param list lets it be specified when object1 is created. 
There is no reason it can not simply start with a sane value and be modified by
later function calls.  For instance:

class Counter:
  def __init__(self):
    self.count = 0
  def incr(self):
    self.count = self.count + 1
  def value(self):
    return self.count


> 6. What function(s) can I use to see/list methods such as "doit" within
> an instance?  ("vars()" and "dir()" don't do it.)
> 

not sure on this one, sorry.


From fun@1stCasino.com  Thu May 24 17:37:39 2001
From: fun@1stCasino.com (fun@1stCasino.com)
Date: Thu, 24 May 2001 12:37:39 -0400
Subject: [Tutor] Monthly Drawing Winner!
Message-ID: <200105241637.MAA11475@sun1.>

  Hey Tutor :)

  You have got to try our games!!

  http://www.1stCasino.com

  Blackjack!
  Poker!
  Roulette!

  ...and EZ Slots !!


  We have already !! 1047 !! winning players today!!

  Try our free games!  Nothing to download!

  Play and WIN MONEY instantly!!!


  http://www.1stCasino.com

  The First On The Net!! (TM)



From bill_tolbert@bigfoot.com  Thu May 24 19:26:26 2001
From: bill_tolbert@bigfoot.com (Bill Tolbert)
Date: Thu, 24 May 2001 14:26:26 -0400 (EDT)
Subject: [Tutor] Zope
In-Reply-To: <000801c0e460$452638a0$de00a8c0@planhouse5>
Message-ID: <Pine.A41.4.21L1.0105241422350.79446-100000@login3.isis.unc.edu>

On Thu, 24 May 2001, Rob Andrews wrote:

> Well, despite my "lover, not a hacker" status, I came in to work and had no
> trouble getting Zope to install and execute on a machine here. I'm guessing
> that my box at the house has too esoteric a configuration. Zope just
> wouldn't run start.bat successfully at all there.
> 
> Rob
> 

I had the same problem on my W95 box. I"m sure there is a better way, but
I used to connect to my ISP (back when I had a dialup account) and Zope
would start. I could then disconnect and all would be well. Was your home
machine online when you tried start.bat?

Bill



From randrews@planhouse.com  Thu May 24 19:31:46 2001
From: randrews@planhouse.com (Rob Andrews)
Date: Thu, 24 May 2001 13:31:46 -0500
Subject: [Tutor] Zope
In-Reply-To: <Pine.A41.4.21L1.0105241422350.79446-100000@login3.isis.unc.edu>
Message-ID: <000001c0e47f$ca3f4ee0$de00a8c0@planhouse5>

3;-> -----Original Message-----

3;-> Subject: RE: [Tutor] Zope
3;-> 
3;-> 
3;-> On Thu, 24 May 2001, Rob Andrews wrote:
3;-> 
3;-> > Well, despite my "lover, not a hacker" status, I came in 
3;-> to work and had no
3;-> > trouble getting Zope to install and execute on a machine 
3;-> here. I'm guessing
3;-> > that my box at the house has too esoteric a 
3;-> configuration. Zope just
3;-> > wouldn't run start.bat successfully at all there.
3;-> > 
3;-> > Rob
3;-> > 
3;-> 
3;-> I had the same problem on my W95 box. I"m sure there is a 
3;-> better way, but
3;-> I used to connect to my ISP (back when I had a dialup 
3;-> account) and Zope
3;-> would start. I could then disconnect and all would be 
3;-> well. Was your home
3;-> machine online when you tried start.bat?
3;-> 
3;-> Bill
3;-> 

Yes. It's always on.

Rob

Got Python?
http://www.lowerstandard.com/python/pythonsource.html 


From bsass@freenet.edmonton.ab.ca  Thu May 24 19:51:50 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Thu, 24 May 2001 12:51:50 -0600 (MDT)
Subject: [Tutor] re: range function
In-Reply-To: <20010524094042.A25363@harmony.cs.rit.edu>
Message-ID: <Pine.LNX.4.33.0105241230160.32098-100000@bms>

On Thu, 24 May 2001, D-Man wrote:

> On Thu, May 24, 2001 at 12:33:54AM -0600, Bruce Sass wrote:
> | The only problem is I did it while in xemacs, using ^c^c, and the
>
> ^c^c? I thought it was C-c C-c ;-).  (I'm just teasing you, I don't
> remember the emacs keys anymore)

:)

> | Since...
> |
> | >>> 5.5499999999999998 == 5.55
> | 1
> |
> | ...is it anything more than a cosmetic issue when print-ing, e.g., a
> | list of floats (rather than the items in a list of floats).
>
> Yes -- the actual number in memory hasn't changed.  If you look at my
> example I used string interpolation to truncate the numbers at 2
> decimal points when I printed my results.

Right.  What I meant is... if you are using Python's builtin fp, you
know it is limited to binary accuracy, so what should it matter
(computationally) if 5.55 == 5.5499999999999998.  It is only the
display that `looks' off, and then only because python2.x spits out
the repr, and not the str, of floats in a list when "print"-ing the
list.

[Which gets me wondering why it was changed, but's another story.]

> If you want a description of the IEEE 754 floating point
> representation I can give it to you (I had to implement addition,
> subtraction and multiplication on single precision IEEE 754 floats in
> m68k assembly for a lab, but I didn't have enough time to do the
> multiplication)

Naw, thanks though.
I still remember some of the fp stuff I learned way back when I was
doing it on 8-bit machines, so I've got an idea of what's up.  That
kinda thing should be done in assembler anyways... ;)


- Bruce



From kromag@nsacom.net  Thu May 24 22:05:16 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Thu, 24 May 2001 14:05:16 -0700 (PDT)
Subject: [Tutor] Difficulties with % operator
Message-ID: <200105242105.f4OL5GL01561@pop.nsacom.net>

Okay, I feel like a dolt...

A few weeks ago I asked some folks here about insertion of random numbers 
into a database. No problem! This was (one of)my answer(s):

"insert into pork values(%d, 'stuff', '1-2-1999')" % random.randint(1,1000))

No big deal, right?

Well, I have since been playing around with Abcess:

------------scriptish--------

import win32com.client
import random
import time
import string

engine=win32com.client.Dispatch("DAO.DBEngine.35")
db=engine.OpenDatabase("\windows\desktop\db2.mdb")
while 1:
	db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" % 
time.time() %random.randint(1, 1000))

---------/scriptish-----------

Notice that I am getting fancy and attempting to do something semi-useful  
(inserting time...)

Unfortunately, I get the following error message:

c:windowsdesktop>python test.py
Traceback (most recent call last):
  File "test.py", line 9, in ?
    db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" % 
time.time() %random.randint(1, 1000))
TypeError: not enough arguments for format string


Now my copy of Learning Python gives an example:

'That is %d %s bird' % (1, dead)

so I tried variants like:

db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" % 
(time.time() %random.randint(1, 1000)))

which looks unweildy and didn't work besides! :-)

Where am I going wrong?

d





From dsh8290@rit.edu  Thu May 24 20:26:52 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 24 May 2001 15:26:52 -0400
Subject: [Tutor] Silly Object Namespace Questions
In-Reply-To: <XFMail.20010524094135.shaleh@valinux.com>; from shaleh@valinux.com on Thu, May 24, 2001 at 09:41:35AM -0700
References: <sb0cee98.024@madis2.truax.covance.com> <XFMail.20010524094135.shaleh@valinux.com>
Message-ID: <20010524152652.B25875@harmony.cs.rit.edu>

On Thu, May 24, 2001 at 09:41:35AM -0700, Sean 'Shaleh' Perry wrote:
| 
| On 24-May-2001 Curtis Larsen wrote:
| > <Sigh> OK I'm still trying to wrap my head around class namespace(s),
| > and I know this is gonna sound dumb, (BUT) I have a few questions about
| > the following example:

This list is the perfect place to ask such questions :-).

| > class object1:
<...>

| > Doing a "dir(x)" produces  "['x']", and after running "self.doit()"
| > (which prints "Gotcha!"), "dir(x)" gives "['str', 'x']".  Okay, soooo:

<Sean's good answers to the questions>

| > 6. What function(s) can I use to see/list methods such as "doit" within
| > an instance?  ("vars()" and "dir()" don't do it.)

dir( object1 )

or

instance = object1()
dir( instance.__class__ )


Notice that instead of passing the instance to the dir funtion I
passed the class object.

-D



From dsh8290@rit.edu  Thu May 24 20:34:30 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 24 May 2001 15:34:30 -0400
Subject: [Tutor] Difficulties with % operator
In-Reply-To: <200105242105.f4OL5GL01561@pop.nsacom.net>; from kromag@nsacom.net on Thu, May 24, 2001 at 02:05:16PM -0700
References: <200105242105.f4OL5GL01561@pop.nsacom.net>
Message-ID: <20010524153430.C25875@harmony.cs.rit.edu>

On Thu, May 24, 2001 at 02:05:16PM -0700, kromag@nsacom.net wrote:
...
| 	db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" % 
| time.time() %random.randint(1, 1000))
...
| Unfortunately, I get the following error message:
| 
| c:windowsdesktop>python test.py
| Traceback (most recent call last):
|   File "test.py", line 9, in ?
|     db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" % 
| time.time() %random.randint(1, 1000))
| TypeError: not enough arguments for format string
|
| 
| Now my copy of Learning Python gives an example:
| 
| 'That is %d %s bird' % (1, dead)

This string has 2 format operators (%d and %s).  After the string
follows the string interpolation operator '%'.  After that is a single
_tuple_ who size is the same as the number of format operators in the
string and it contains the values to be inserted into the string.

(excess stuff removed)
| "insert into food values(%d, %i, 'goat', 'pig', 'cow')" % \
|       time.time() % random.randint(1, 1000)

Here you have a string that also has 2 format operators (%d and %i).
Following it you have the string interpolation operator, then a bit
different expression.

|       time.time() % random.randint(1, 1000)

Here you are getting the time and a random number, then performing
modulo division on it which results in a single float.  Ex:

>>> time.time() % random.randint( 1 , 1000 )
248.07400000095367

What you mean instead is to have a 2-tuple containing the result of
each function :
 ( time.time() , random.randint(1, 1000) )

So the line should read :


 	db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" % 
 ( time.time() , random.randint(1, 1000) ) )


HTH,
-D



From dsh8290@rit.edu  Thu May 24 22:49:21 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 24 May 2001 17:49:21 -0400
Subject: [Tutor] Difficulties with % operator
In-Reply-To: <200105242345.f4ONjdL28102@pop.nsacom.net>; from kromag@nsacom.net on Thu, May 24, 2001 at 04:45:39PM -0700
References: <200105242345.f4ONjdL28102@pop.nsacom.net>
Message-ID: <20010524174921.A27013@harmony.cs.rit.edu>

On Thu, May 24, 2001 at 04:45:39PM -0700, kromag@nsacom.net wrote:
| D-Man <dsh8290@rit.edu> said: 
| 
| > What you mean instead is to have a 2-tuple containing the result of
| > each function :
| >  ( time.time() , random.randint(1, 1000) )
| > 
| > So the line should read :
| > 
| >  	db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" % 
| >  ( time.time() , random.randint(1, 1000) ) )
| 
| TUPLE! TUPLE! Now I get it! I was thinking about replacing things and moving 
| parentheses and forgetting chapter 2 altogether! Now If I could just figure 
| out how to properly slow the loop so it won't overload access and lock my 
| little script....

import time
while <...> :
    <...>
    # give Access 10 minutes to get with the program ;-)
    time.sleep( 10 * 60 )


Python is even better than Java -- sleep works properly and doesn't
throw exceptions!

-D



From Greg.Furmanek@hit.cendant.com  Thu May 24 23:44:19 2001
From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg)
Date: Thu, 24 May 2001 18:44:19 -0400
Subject: [Tutor] help:  UnicodeError: ASCII decoding error: ordinal not in range(1
 28)
Message-ID: <E5468D0C0B2DD411AE52009027B0FA3F8D9DB3@hit-phx-mail-3.hfscorp.com>

I am trying to manipulate string containing hex characters.

I get following error when I try to join the strings:
UnicodeError: ASCII decoding error: ordinal not in range(128)

How can I join strings containing "\x81" without the error?

Grzegorz Furmanek
Furmanek.Greg@hit.cendant.com
----------------------------------------------------------
Three Mile Island '79   Chernobyl '86   Windows '00 (1900) 


"The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent.  This message
and its attachments could have been infected during transmission.  By
reading the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects.  The sender's employer is not liable for any loss or damage
arising in any way from this message or its attachments."


From kalle@gnupung.net  Fri May 25 00:29:40 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Fri, 25 May 2001 01:29:40 +0200
Subject: [Tutor] Silly Object Namespace Questions
In-Reply-To: <20010524152652.B25875@harmony.cs.rit.edu>; from dsh8290@rit.edu on Thu, May 24, 2001 at 03:26:52PM -0400
References: <sb0cee98.024@madis2.truax.covance.com> <XFMail.20010524094135.shaleh@valinux.com> <20010524152652.B25875@harmony.cs.rit.edu>
Message-ID: <20010525012940.A31924@father>

Sez D-Man:
> On Thu, May 24, 2001 at 09:41:35AM -0700, Sean 'Shaleh' Perry wrote:
> | On 24-May-2001 Curtis Larsen wrote:
> | > 6. What function(s) can I use to see/list methods such as "doit" within
> | > an instance?  ("vars()" and "dir()" don't do it.)
> 
> dir( object1 )
> 
> or
> 
> instance = object1()
> dir( instance.__class__ )
> 
> 
> Notice that instead of passing the instance to the dir funtion I
> passed the class object.

Even this won't be enough if the class has inherited methods from
superclasses, though.  For that situation, you'll need something like this
(almost untested):

def classdir(c):
    res = dir(c)
    try:
        for s in c.__bases__:
	    res += classdir(s)
    except AttributeError:
        pass
    return res

It is far from perfect, but should illustrate the principle...

Finally, this would do what you (might) want (almost untested too):

import types
def superdir(obj):
    if isinstance(obj, types.InstanceType):
        return dir(obj) + classdir(obj.__class__)
    elif isinstance(obj, types.ClassType):
        return classdir(obj)
    else:
        return dir(obj)

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From juno@gamefire.com  Fri May 25 01:02:25 2001
From: juno@gamefire.com (juno)
Date: Thu, 24 May 2001 17:02:25 -0700
Subject: [Tutor] Difficulties with % operator
In-Reply-To: <200105242105.f4OL5GL01561@pop.nsacom.net>
Message-ID: <CFEKIMLINCOCHCDCCFHACEDMCCAA.juno@gamefire.com>

You forgot a "," and an "("

Try this: db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')"
% (time.time(), random.randint(1, 1000))

Also, you might want to make this a little more readable. Try something
like:

while 1:
RNum = random.random(1, 1000)
MyTime = time.time()
Db.Execute("insert into food values(%d, %I, 'goat', 'pig', 'cow')" % (Rnum,
MyTime))


Hope that helps,


Hunter


-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
kromag@nsacom.net
Sent: Thursday, May 24, 2001 2:05 PM
To: tutor@python.org
Subject: [Tutor] Difficulties with % operator

Okay, I feel like a dolt...

A few weeks ago I asked some folks here about insertion of random numbers
into a database. No problem! This was (one of)my answer(s):

"insert into pork values(%d, 'stuff', '1-2-1999')" % random.randint(1,1000))

No big deal, right?

Well, I have since been playing around with Abcess:

------------scriptish--------

import win32com.client
import random
import time
import string

engine=win32com.client.Dispatch("DAO.DBEngine.35")
db=engine.OpenDatabase("\windows\desktop\db2.mdb")
while 1:
        db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" %
time.time() %random.randint(1, 1000))

---------/scriptish-----------

Notice that I am getting fancy and attempting to do something semi-useful
(inserting time...)

Unfortunately, I get the following error message:

c:windowsdesktop>python test.py
Traceback (most recent call last):
  File "test.py", line 9, in ?
    db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" %
time.time() %random.randint(1, 1000))
TypeError: not enough arguments for format string


Now my copy of Learning Python gives an example:

'That is %d %s bird' % (1, dead)

so I tried variants like:

db.Execute("insert into food values(%d, %i, 'goat', 'pig', 'cow')" %
(time.time() %random.randint(1, 1000)))

which looks unweildy and didn't work besides! :-)

Where am I going wrong?

d




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



From walterv@jps.net  Fri May 25 02:08:19 2001
From: walterv@jps.net (Walter Vannini)
Date: Thu, 24 May 2001 18:08:19 -0700
Subject: [Tutor] help:  UnicodeError: ASCII decoding error: ordinal not in
 range(1 28)
References: <E5468D0C0B2DD411AE52009027B0FA3F8D9DB3@hit-phx-mail-3.hfscorp.com>
Message-ID: <3B0DB083.3005E9B8@jps.net>

Hi Grzegorz,

I'm unable to reproduce the error message in Python 2.0.
For example, the following code does not seem to trigger
the error message:

aString = "\x81\x82\x83"
bString = "\x83\x84\x85"
cString = aString+bString
dString = "".join([aString, bString])
import string
eString = string.join([aString, bString], "")
print aString
print bString
print cString
print dString
print eString

Some example code would be helpful in diagnosing the problem.
Also, your version of python would be useful.
It can be found via "import sys; print sys.version"
The string I get via this code is:
"2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)]"

Walter.

> I am trying to manipulate string containing hex characters.
> 
> I get following error when I try to join the strings:
> UnicodeError: ASCII decoding error: ordinal not in range(128)
> 
> How can I join strings containing "\x81" without the error?
> 
> Grzegorz Furmanek
> Furmanek.Greg@hit.cendant.com


From roderick.krause@dubbocs.com.au  Fri May 25 02:16:52 2001
From: roderick.krause@dubbocs.com.au (Rod Krause)
Date: Fri, 25 May 2001 11:16:52 +1000
Subject: [Tutor] random number generation
Message-ID: <001a01c0e4b8$64685b50$a901a8c0@rm27020>

This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C0E50C.3358A6B0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am wondering what the syntax is for generating random numbers in =
python - I am developing a set of numeracy programs for high school kids =
and need to be able to generate questions that are different each time


Rod Krause

------=_NextPart_000_0015_01C0E50C.3358A6B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am wondering what the syntax is for =
generating=20
random numbers in python - I am developing a set of numeracy programs =
for high=20
school kids and need to be able to generate questions that are different =
each=20
time</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Rod Krause</FONT></DIV></BODY></HTML>

------=_NextPart_000_0015_01C0E50C.3358A6B0--



From dyoo@hkn.eecs.berkeley.edu  Fri May 25 03:38:37 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 24 May 2001 19:38:37 -0700 (PDT)
Subject: [Tutor] random number generation
In-Reply-To: <001a01c0e4b8$64685b50$a901a8c0@rm27020>
Message-ID: <Pine.LNX.4.21.0105241923460.9487-100000@hkn.eecs.berkeley.edu>

On Fri, 25 May 2001, Rod Krause wrote:

> I am wondering what the syntax is for generating random numbers in
> python - I am developing a set of numeracy programs for high school
> kids and need to be able to generate questions that are different each
> time

Very cool!  You'll want to check the "random" module:

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

Warning: this module seems to have changed and cleaned up quite a bit
between Python 1.52 and 2.1, so you'll want to look at the docs and see
which functions have been affected.


There are several functions in there that will be useful.  One is the
random.random() function, which returns a number in [0.0, 1.0):

###
>>> import random
>>> random.random()
0.409399621988
>>> random.random()
0.134217003599
>>> random.random()
0.949996824385
###


If your students want to pull a random element from a list, the
random.choice() function is also a good choice:

###
>>> random.choice(['vanilla', 'grape', 'orange', 'banana'])
'vanilla'
>>> random.choice(['vanilla', 'grape', 'orange', 'banana'])
'orange'
>>> random.choice(['vanilla', 'grape', 'orange', 'banana'])
'vanilla'
>>> random.choice(['vanilla', 'grape', 'orange', 'banana'])
'banana'
###


If you look through the reference documentation, you'll see some other
interesting functions.  There's also a reference to a whrandom module in
the library documentation, but since it is deprecated (2.1), you should
probably avoid it.


I wonder what sort of programs you can show your students that take
advantage of randomness.  My personal favorite is the one that calculates
pi via the "dartboard" approach.  I hope your students have a blast!



From tron@submatrix.com  Fri May 25 10:08:47 2001
From: tron@submatrix.com (Tron)
Date: Fri, 25 May 2001 02:08:47 -0700
Subject: [Tutor] Web Store
References: <Pine.GSO.4.21.0105231801460.8775-100000@isis.visi.com>
Message-ID: <000b01c0e4fa$4f44f4d0$52aab2d1@praxis>

I need to make a web store script a good example would be things like
Dell's, and Alienwares site where you can configure your own system.  Is
there a good tutorial on how to do this or something that will help get me
going in the right direction?

-Thanks,
Tron



From karimy@nipltd.com  Fri May 25 10:11:55 2001
From: karimy@nipltd.com (Karim Yaici)
Date: Fri, 25 May 2001 10:11:55 +0100
Subject: [Tutor] random number generation
References: <001a01c0e4b8$64685b50$a901a8c0@rm27020>
Message-ID: <005501c0e4fa$bf173520$a5020a0a@private.nipltd.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0052_01C0E503.2087B0C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Rod,
If you are interested in a better random generator, have a look at =
http://sourceforge.net/projects/pyaes/. This is a package  that contains =
a couple of encryption modules and one psudo-number generator (which =
does interest us) is called: Entropy.

There are tests which show the 'predictability' and the standard =
deviation of the numbers generated by Entropy.py and whrandom.py.

You may probably not need that much of randomness, but I was thinking =
that people in this list may be interested :-)

Karim

  ----- Original Message -----=20
  From: Rod Krause=20
  To: tutor@python.org=20
  Sent: Friday, May 25, 2001 2:16 AM
  Subject: [Tutor] random number generation


  I am wondering what the syntax is for generating random numbers in =
python - I am developing a set of numeracy programs for high school kids =
and need to be able to generate questions that are different each time


  Rod Krause

------=_NextPart_000_0052_01C0E503.2087B0C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi Rod,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>If you are interested in a better =
random generator,=20
have a look&nbsp;at <A=20
href=3D"http://sourceforge.net/projects/pyaes/">http://sourceforge.net/pr=
ojects/pyaes/</A>.=20
This is a package&nbsp; that contains a couple of encryption =
modules&nbsp;and=20
one psudo-number generator (which does interest us) is called:=20
Entropy.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>There are tests which show the =
'predictability' and=20
the standard deviation of the numbers generated by Entropy.py and=20
whrandom.py.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>You may probably not need that much of =
randomness,=20
but I was thinking that people in this list may be interested =
:-)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Karim</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Droderick.krause@dubbocs.com.au=20
  href=3D"mailto:roderick.krause@dubbocs.com.au">Rod Krause</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, May 25, 2001 2:16 =
AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] random number=20
  generation</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>I am wondering what the syntax is for =
generating=20
  random numbers in python - I am developing a set of numeracy programs =
for high=20
  school kids and need to be able to generate questions that are =
different each=20
  time</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Rod =
Krause</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0052_01C0E503.2087B0C0--



From alan.gauld@bt.com  Fri May 25 12:00:14 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 25 May 2001 12:00:14 +0100
Subject: [Tutor] Silly Object Namespace Questions
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7D4@mbtlipnt02.btlabs.bt.co.uk>

> > 6. What function(s) can I use to see/list methods such as 
> "doit" within an instance?  ("vars()" and "dir()" don't do it.)

dir does but you have to use the class not the instance.
You can access the class via the __class__  attribute 
thus:

>>> class C:
...   def __init__(s): s.foo = 42
...   def sayit(s): print s.foo
...
>>> f = C()
>>> dir(f)
['foo']
>>> dir(f.__class__)
['__doc__', '__init__', '__module__', 'sayit']
>>>

Alan G


From pdiaz88@terra.es  Fri May 25 14:52:21 2001
From: pdiaz88@terra.es (Pedro Diaz Jimenez)
Date: Fri, 25 May 2001 13:52:21 +0000
Subject: [Tutor] random number generation
In-Reply-To: <001a01c0e4b8$64685b50$a901a8c0@rm27020>
References: <001a01c0e4b8$64685b50$a901a8c0@rm27020>
Message-ID: <01052513522107.10910@duero>

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

What about using the random module?. Its rather good if your aren't going
to use it in crypto

pdiaz@duero:~$ python
Python 1.5.2 (#0, Dec 27 2000, 13:59:38)  [GCC 2.95.2 20000220 (Debian 
GNU/Linux)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import random
>>> random.random()
0.431786822224
>>> a=[1,2,3,4,5,6]
>>> random.choice(a)
4
>>> random.choice(a)
2
>>> random.choice(a)
1
>>>


On Friday 25 May 2001 01:16, Rod Krause wrote:
> I am wondering what the syntax is for generating random numbers in python -
> I am developing a set of numeracy programs for high school kids and need to
> be able to generate questions that are different each time
>
>
> Rod Krause

- ----------------------------------------
Content-Type: text/html; charset="iso-8859-1"; name="Attachment: 1"
Content-Transfer-Encoding: quoted-printable
Content-Description: 
- ----------------------------------------

- -- 

/*
 * Pedro Diaz Jimenez
 * pdiaz88@terra.es 
 * pdiaz@acm.asoc.fi.upm.es
 *
 * Wanna see how 100000! looks like?:
 * http://acm.asoc.fi.upm.es/~pdiaz/fact_100.000
 * 
 * La sabiduria me persigue, pero yo soy mas rapido
 *
 */

Random quote:
- -------------

You know something, folks, as ridiculous as this sounds, I would rather
feel the sweet breath of my beautiful wife on the back of my neck as I
sleep than stuff dollar bills into some stranger's G-string.

		-- Homer Simpson
		   Homer's Night Out
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7DmOVnu53feEYxlERAmvhAJsGiZbWKh4b14LaomB8PZqTxU7H3wCfRXtR
L0zcO+PEqmacdhXrxlNaHvU=
=d7bK
-----END PGP SIGNATURE-----


From dsh8290@rit.edu  Fri May 25 14:39:20 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 25 May 2001 09:39:20 -0400
Subject: [Tutor] Silly Object Namespace Questions
In-Reply-To: <20010525012940.A31924@father>; from kalle@gnupung.net on Fri, May 25, 2001 at 01:29:40AM +0200
References: <sb0cee98.024@madis2.truax.covance.com> <XFMail.20010524094135.shaleh@valinux.com> <20010524152652.B25875@harmony.cs.rit.edu> <"from dsh8290"@rit.edu> <20010525012940.A31924@father>
Message-ID: <20010525093920.B27976@harmony.cs.rit.edu>

On Fri, May 25, 2001 at 01:29:40AM +0200, Kalle Svensson wrote:
| Sez D-Man:
| > On Thu, May 24, 2001 at 09:41:35AM -0700, Sean 'Shaleh' Perry wrote:
| > | On 24-May-2001 Curtis Larsen wrote:
| > | > 6. What function(s) can I use to see/list methods such as "doit" within
| > | > an instance?  ("vars()" and "dir()" don't do it.)
| > 
| > instance = object1()
| > dir( instance.__class__ )
| > 
| > 
| > Notice that instead of passing the instance to the dir funtion I
| > passed the class object.
| 
| Even this won't be enough if the class has inherited methods from
| superclasses, though.  For that situation, you'll need something like this

You're right -- it isn't recursive.  One would need to traverse the
entire inheritance heirarchy to get _all_ methods.

-D



From curtis.larsen@Covance.Com  Fri May 25 15:06:47 2001
From: curtis.larsen@Covance.Com (Curtis Larsen)
Date: Fri, 25 May 2001 09:06:47 -0500
Subject: [Tutor] Silly Object Namespace Questions
Message-ID: <sb0e20b8.068@madis2.truax.covance.com>

>>> "Sean 'Shaleh' Perry" <shaleh@valinux.com> 05/24/2001 11:41:35 AM
>>>

<snip>

> On 24-May-2001 Curtis Larsen wrote:
>> <Sigh> OK I'm still trying to wrap my head around class
namespace(s),
>> and I know this is gonna sound dumb, (BUT) I have a few questions
about
>> the following example:
>> 
>> class object1:
>>    def __init__(self):
>>       a = 10
>>       self.x = 1
>>    def doit(self):
>>       self.str = "This is a string"
>>       wumpus = "Gotcha!"
>>       print wumpus

<snip again>

>> 3. Although (I believe) "x" and "str" are "safe" from modification,
>> would another instance of "object1" change the value of "a" or
>> "wumpus"?

> yes, but not for why you are thinking.  Each object's doit() will
create a new
> variable called 'wumpus' when called.  This variable lives for as
long as it
> takes for doit() to execute, then it goes away.

Thanks (to everyone) -- that makes it all much more understandable. 
One thing I'm still missing though, is whether or not different
instances of the above example class will overwrite the "a" or "wumpus"
variables.  In other words, is the namespace for both those variables
shared amongst the different instances, and will one instance (possibly)
changing the the value of, say, "a" mean that another instance will also
perceive the change?

If it helps, what I'm looking for is the best way to use "temporary"
calculation ("working") variables within a class (or methods of that
class) without callers seeing those variables (unlike the "x" variable
above).  "a" and "wumpus" appear to be good examples of doing this very
thing, but if different instance will step on each others values for
them, it would be... ummmm... "bad".

One other question: If you have an import statement within a method or
function, how often does the import actually occur?  Once upon
instantiation?  Every time the function/method is called?  Only once
ever? (Wow!  Not *that* would be a nifty pre-parser!)


Thanks!
Curtis


PS: Thanks very much also for the example code on listing methods --
I'll use it!



-----------------------------------------------------
Confidentiality Notice: This e-mail transmission 
may contain confidential or legally privileged 
information that is intended only for the individual 
or entity named in the e-mail address. If you are not 
the intended recipient, you are hereby notified that 
any disclosure, copying, distribution, or reliance 
upon the contents of this e-mail is strictly prohibited. 

If you have received this e-mail transmission in error, 
please reply to the sender, so that we can arrange 
for proper delivery, and then please delete the message 
from your inbox. Thank you.


From arcege@speakeasy.net  Fri May 25 15:53:40 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Fri, 25 May 2001 10:53:40 -0400 (EDT)
Subject: [Tutor] Web Store
In-Reply-To: <000b01c0e4fa$4f44f4d0$52aab2d1@praxis> from "Tron" at May 25, 2001 02:08:47 AM
Message-ID: <200105251453.f4PErf602780@dsl092-074-184.bos1.dsl.speakeasy.net>

Tron wrote
> I need to make a web store script a good example would be things like
> Dell's, and Alienwares site where you can configure your own system.  Is
> there a good tutorial on how to do this or something that will help get me
> going in the right direction?

I'd suggest reading the "Advanced Web" sections of "Programming Python,
2nd ed." by Mark Lutz.  He gives good full examples CGI based systems
and other web systems.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From dsh8290@rit.edu  Fri May 25 16:19:25 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 25 May 2001 11:19:25 -0400
Subject: [Tutor] Silly Object Namespace Questions
In-Reply-To: <sb0e20b8.068@madis2.truax.covance.com>; from curtis.larsen@Covance.Com on Fri, May 25, 2001 at 09:06:47AM -0500
References: <sb0e20b8.068@madis2.truax.covance.com>
Message-ID: <20010525111924.D29831@harmony.cs.rit.edu>

On Fri, May 25, 2001 at 09:06:47AM -0500, Curtis Larsen wrote:

<snip>

| > On 24-May-2001 Curtis Larsen wrote:
| >> 
| >> class object1:
| >>    def __init__(self):
| >>       a = 10
| >>       self.x = 1
| >>    def doit(self):
| >>       self.str = "This is a string"
| >>       wumpus = "Gotcha!"
| >>       print wumpus
| 
| Thanks (to everyone) -- that makes it all much more understandable. 
| One thing I'm still missing though, is whether or not different
| instances of the above example class will overwrite the "a" or "wumpus"
| variables.  In other words, is the namespace for both those variables
| shared amongst the different instances, and will one instance (possibly)
| changing the the value of, say, "a" mean that another instance will also
| perceive the change?
| 
| If it helps, what I'm looking for is the best way to use "temporary"
| calculation ("working") variables within a class (or methods of that
| class) without callers seeing those variables (unlike the "x" variable
| above).  "a" and "wumpus" appear to be good examples of doing this very
| thing, but if different instance will step on each others values for
| them, it would be... ummmm... "bad".

'a' and 'wumpus' are local variables.  Their scope is only in the
method and they only exist for the duration of the method.  Once the
method returns they disappear.  Since any given method invocation only
occurs once (you can invoke the same method many times, but each
invocation is a separate invocation) those variables are only
accessible from that invocation.  Each invocation has its own local
variables.

The conclusion is yes, that is the way to make "temporary" (usually
called 'local :-)) variables for intermediate operations.

| One other question: If you have an import statement within a method or
| function, how often does the import actually occur?  Once upon
| instantiation?  Every time the function/method is called?  Only once
| ever? (Wow!  Not *that* would be a nifty pre-parser!)

The import statement is executed each time it is reached (for each
invocation of that method ).  When an import statement is executed the
first thing it does is check the cache of already imported modules.
If the module has already been imported then it is not imported again.
It is similar to your last guess, but if the method is never called
the module won't be imported at all.

(Also be sure _not_ to use the  from <module> import *   form except
 maybe at module level.  It is even better to not use it at all.)

-D



From walterv@jps.net  Fri May 25 16:41:02 2001
From: walterv@jps.net (Walter Vannini)
Date: Fri, 25 May 2001 08:41:02 -0700
Subject: [Tutor] help:  UnicodeError: ASCII decoding error: ordinal not in
 range(1 28)
References: <E5468D0C0B2DD411AE52009027B0FA3F8D9DB3@hit-phx-mail-3.hfscorp.com>
 <3B0DB083.3005E9B8@jps.net>
Message-ID: <3B0E7D0E.E5E14193@jps.net>

Hi Grzegorz,

I don't know unicode well enough to answer your question.
I hope someone out there might be able to tell you (and me) what's going on.

I can tell you that the error can be reproduced very easily via:

>>> str(u"\x81")
which attempts to convert the unicode object u"\x81" to a string object

or via:

>>> unicode("\x81")
which attempts to convert the string object "\x81" to a unicode object

Walter.

Furmanek, Greg wrote:
> 
> >>> a = "\x81"
> >>> b = "test"
> >>> c = 00123
> >>> print a b c
>   File "<stdin>", line 1
>     print a b c
>             ^
> SyntaxError: invalid syntax
> >>> print a
> 
> >>> print b
> test
> >>> print c
> 83
> >>> c = "01405'
>   File "<stdin>", line 1
>     c = "01405'
>               ^
> SyntaxError: invalid token
> >>> c = "01405"
> >>> a + b + c
> '\201test01405'
> >>> a + a + b + a + c + a + c
> '\201\201test\20101405\20101405'
> >>> u'\x81'
> u'\201'
> >>> d = u'\x81'
> >>> a + b + c + d
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> UnicodeError: ASCII decoding error: ordinal not in range(128)
> 
> I was able to recreate the error.
> 
> when I add regurlar ascii then it is ok,
> but when the unicode is added then I get
> the error.
> 
> I am using xml parsing and I guess it gives a result
> using unicode.
> 
> -> -----Original Message-----
> -> From: Walter Vannini [mailto:walterv@jps.net]
> -> Sent: Thursday, May 24, 2001 6:08 PM
> -> To: 'tutor@python.org'
> -> Subject: Re: [Tutor] help: UnicodeError: ASCII decoding
> -> error: ordinal
> -> not in range(1 28)
> ->
> ->
> -> Hi Grzegorz,
> ->
> -> I'm unable to reproduce the error message in Python 2.0.
> -> For example, the following code does not seem to trigger
> -> the error message:
> ->
> -> aString = "\x81\x82\x83"
> -> bString = "\x83\x84\x85"
> -> cString = aString+bString
> -> dString = "".join([aString, bString])
> -> import string
> -> eString = string.join([aString, bString], "")
> -> print aString
> -> print bString
> -> print cString
> -> print dString
> -> print eString
> ->
> -> Some example code would be helpful in diagnosing the problem.
> -> Also, your version of python would be useful.
> -> It can be found via "import sys; print sys.version"
> -> The string I get via this code is:
> -> "2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)]"
> ->
> -> Walter.
> ->
> -> > I am trying to manipulate string containing hex characters.
> -> >
> -> > I get following error when I try to join the strings:
> -> > UnicodeError: ASCII decoding error: ordinal not in range(128)
> -> >
> -> > How can I join strings containing "\x81" without the error?
> -> >
> -> > Grzegorz Furmanek
> -> > Furmanek.Greg@hit.cendant.com
> ->


From Greg.Furmanek@hit.cendant.com  Fri May 25 17:19:11 2001
From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg)
Date: Fri, 25 May 2001 12:19:11 -0400
Subject: [Tutor] help:  UnicodeError: ASCII decoding error: ordinal no
 t in range(1 28)
Message-ID: <E5468D0C0B2DD411AE52009027B0FA3F8D9DB5@hit-phx-mail-3.hfscorp.com>

Ok I found the answer.

When I read the unicode I try to convert it to 
ascii by:

ascii_string = u'\x81'.encode('ascii')

this did the trick

-> -----Original Message-----
-> From: Walter Vannini [mailto:walterv@jps.net]
-> Sent: Friday, May 25, 2001 8:41 AM
-> To: 'tutor@python.org'
-> Subject: Re: [Tutor] help: UnicodeError: ASCII decoding 
-> error: ordinal
-> not in range(1 28)
-> 
-> 
-> Hi Grzegorz,
-> 
-> I don't know unicode well enough to answer your question.
-> I hope someone out there might be able to tell you (and me) 
-> what's going on.
-> 
-> I can tell you that the error can be reproduced very easily via:
-> 
-> >>> str(u"\x81")
-> which attempts to convert the unicode object u"\x81" to a 
-> string object
-> 
-> or via:
-> 
-> >>> unicode("\x81")
-> which attempts to convert the string object "\x81" to a 
-> unicode object
-> 
-> Walter.
-> 
-> Furmanek, Greg wrote:
-> > 
-> > >>> a = "\x81"
-> > >>> b = "test"
-> > >>> c = 00123
-> > >>> print a b c
-> >   File "<stdin>", line 1
-> >     print a b c
-> >             ^
-> > SyntaxError: invalid syntax
-> > >>> print a
-> > 
-> > >>> print b
-> > test
-> > >>> print c
-> > 83
-> > >>> c = "01405'
-> >   File "<stdin>", line 1
-> >     c = "01405'
-> >               ^
-> > SyntaxError: invalid token
-> > >>> c = "01405"
-> > >>> a + b + c
-> > '\201test01405'
-> > >>> a + a + b + a + c + a + c
-> > '\201\201test\20101405\20101405'
-> > >>> u'\x81'
-> > u'\201'
-> > >>> d = u'\x81'
-> > >>> a + b + c + d
-> > Traceback (most recent call last):
-> >   File "<stdin>", line 1, in ?
-> > UnicodeError: ASCII decoding error: ordinal not in range(128)
-> > 
-> > I was able to recreate the error.
-> > 
-> > when I add regurlar ascii then it is ok,
-> > but when the unicode is added then I get
-> > the error.
-> > 
-> > I am using xml parsing and I guess it gives a result
-> > using unicode.
-> > 
-> > -> -----Original Message-----
-> > -> From: Walter Vannini [mailto:walterv@jps.net]
-> > -> Sent: Thursday, May 24, 2001 6:08 PM
-> > -> To: 'tutor@python.org'
-> > -> Subject: Re: [Tutor] help: UnicodeError: ASCII decoding
-> > -> error: ordinal
-> > -> not in range(1 28)
-> > ->
-> > ->
-> > -> Hi Grzegorz,
-> > ->
-> > -> I'm unable to reproduce the error message in Python 2.0.
-> > -> For example, the following code does not seem to trigger
-> > -> the error message:
-> > ->
-> > -> aString = "\x81\x82\x83"
-> > -> bString = "\x83\x84\x85"
-> > -> cString = aString+bString
-> > -> dString = "".join([aString, bString])
-> > -> import string
-> > -> eString = string.join([aString, bString], "")
-> > -> print aString
-> > -> print bString
-> > -> print cString
-> > -> print dString
-> > -> print eString
-> > ->
-> > -> Some example code would be helpful in diagnosing the problem.
-> > -> Also, your version of python would be useful.
-> > -> It can be found via "import sys; print sys.version"
-> > -> The string I get via this code is:
-> > -> "2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)]"
-> > ->
-> > -> Walter.
-> > ->
-> > -> > I am trying to manipulate string containing hex characters.
-> > -> >
-> > -> > I get following error when I try to join the strings:
-> > -> > UnicodeError: ASCII decoding error: ordinal not in range(128)
-> > -> >
-> > -> > How can I join strings containing "\x81" without the error?
-> > -> >
-> > -> > Grzegorz Furmanek
-> > -> > Furmanek.Greg@hit.cendant.com
-> > ->
-> 
-> _______________________________________________
-> Tutor maillist  -  Tutor@python.org
-> http://mail.python.org/mailman/listinfo/tutor
-> 


"The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent.  This message
and its attachments could have been infected during transmission.  By
reading the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects.  The sender's employer is not liable for any loss or damage
arising in any way from this message or its attachments."


From dsh8290@rit.edu  Fri May 25 18:16:16 2001
From: dsh8290@rit.edu (D-Man)
Date: Fri, 25 May 2001 13:16:16 -0400
Subject: [Tutor] help:  UnicodeError: ASCII decoding error: ordinal no	t in range(1 28)
In-Reply-To: <E5468D0C0B2DD411AE52009027B0FA3F8D9DB5@hit-phx-mail-3.hfscorp.com>; from Greg.Furmanek@hit.cendant.com on Fri, May 25, 2001 at 12:19:11PM -0400
References: <E5468D0C0B2DD411AE52009027B0FA3F8D9DB5@hit-phx-mail-3.hfscorp.com>
Message-ID: <20010525131616.A750@harmony.cs.rit.edu>

On Fri, May 25, 2001 at 12:19:11PM -0400, Furmanek, Greg wrote:
| Ok I found the answer.
| 
| When I read the unicode I try to convert it to 
| ascii by:
| 
| ascii_string = u'\x81'.encode('ascii')

Are you sure it works?

Python 2.1 (#1, Apr 17 2001, 09:45:01)
[GCC 2.95.3-2 (cygwin special)] on cygwin_nt-4.01
Type "copyright", "credits" or "license" for more information.
>>> u'\x81'.encode( 'ascii' )
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>> '\x81'
'\x81'
>>> u'\x81'
u'\x81'
>>>


I don't know much about unicode, other than it is a different map from
binary <-> characters than ascii is.

My question(s) for you:  Do you really need to use unicode?  In the
above example you have a string literal.  In that case, why not use an
ascii string literal?  Alternatively can you convert the ascii strings
that you have to unicode?

>>> u'\x81' + "Hello"
u'\x81Hello'
>>> "Hello" + u'\x81'
u'Hello\x81'

I'm noticing that here the ascii string was automatically promoted to
a unicode string (kind of like int->float or int->long promotion).

-D



From jko@andover.edu  Fri May 25 21:19:34 2001
From: jko@andover.edu (Justin Ko)
Date: Fri, 25 May 2001 16:19:34 -0400
Subject: [Tutor] Message Passing in Windows
Message-ID: <5.1.0.14.2.20010525161653.01c61760@mail.andover.edu>

         Hey everyone.
         On this page 
<http://www.winamp.com/nsdn/winamp2x/dev/sdk/api.jhtml> the folks at 
Nullsoft show how to control Winamp using windows messages. I have been 
poring over the documentation, and I don't think I have yet found a way to 
pass windows messages. Is there a module out there somewhere that can do this?



_justin Ko



From jko@andover.edu  Fri May 25 21:23:35 2001
From: jko@andover.edu (Justin Ko)
Date: Fri, 25 May 2001 16:23:35 -0400
Subject: [Tutor] (no subject)
Message-ID: <5.1.0.14.2.20010525162314.01c68da0@mail.andover.edu>


         Hey everyone.
         On this page 
<http://www.winamp.com/nsdn/winamp2x/dev/sdk/api.jhtml> the folks at 
Nullsoft show how to control Winamp using windows messages. I have been 
poring over the documentation, and I don't think I have yet found a way to 
pass windows messages. Is there a module out there somewhere that can do this?


_justin Ko



From Blake.Garretson@dana.com  Fri May 25 21:40:50 2001
From: Blake.Garretson@dana.com (Blake.Garretson@dana.com)
Date: Fri, 25 May 2001 16:40:50 -0400
Subject: [Tutor] store icon bitmap as a string
Message-ID: <OF87EF0E93.559C0528-ON85256A57.00704020@dana.com>

(I am almost positive I saw someone mention this topic on this list a while
back, but I can't find it in the archives.  So please bear with me if this
sounds familiar.)

I want to place a xbm bitmap in a string in my program so I don't need to
reference any outside files.  I create a Tkinter button with the following
code (which works fine):

self.UpButton = Button( self, bitmap="@up.xbm", command=self.moveup)

Since xbm is a text format, I can represent the icon as a string.  Now, I'd
like to do something like:

UpImage='#define image_width 23\012#define image_height 24\012static char
image_bits[] =
\0120x00,0x08,0x00,0x00,0x1c,0x00,0x00,0x1c,0x00,0x00,0x3e,0x00,0x00,0x3e,0x00,

0120x00,0x7f,0x00,0x00,0x7f,0x00,0x80,0xff,0x00,0x80,0xff,0x00,0xc0,0xff,0x01,

0120xc0,0xff,0x01,0xe0,0xff,0x03,0xe0,0xff,0x03,0xf0,0xff,0x07,0xf0,0xff,0x07,


0120xf8,0xff,0x0f,0xf8,0xff,0x0f,0xfc,0xff,0x1f,0xfc,0xff,0x1f,0xfe,0xff,0x3f,

0 120xfe,0xff,0x3f,0xff,0xff,0x7f,0xff,0xff,0x7f,0xff,0xff,0x7f\012};'

self.UpButton = Button( self, bitmap=self.UpImage, command=self.moveup)

The "bitmap" option is expecting a name of a bitmap (either a builtin one,
or an external one if preceded by the @), so this doesn't work as written.

Any suggestions on how to do this?

Thanks,
Blake




From arcege@speakeasy.net  Fri May 25 22:43:13 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Fri, 25 May 2001 17:43:13 -0400 (EDT)
Subject: [Tutor] store icon bitmap as a string
In-Reply-To: <OF87EF0E93.559C0528-ON85256A57.00704020@dana.com> from "Blake.Garretson@dana.com" at May 25, 2001 04:40:50 PM
Message-ID: <200105252143.f4PLhEw02545@dsl092-074-184.bos1.dsl.speakeasy.net>

Blake.Garretson@dana.com wrote
> 
> (I am almost positive I saw someone mention this topic on this list a while
> back, but I can't find it in the archives.  So please bear with me if this
> sounds familiar.)
> 
> I want to place a xbm bitmap in a string in my program so I don't need to
> reference any outside files.  I create a Tkinter button with the following
> code (which works fine):
> 
> self.UpButton = Button( self, bitmap="@up.xbm", command=self.moveup)
> 
> Since xbm is a text format, I can represent the icon as a string.  Now, I'd
> like to do something like:
> 
> UpImage='#define image_width 23\012#define image_height 24\012static char
> image_bits[] =
> \0120x00,0x08,0x00,0x00,0x1c,0x00,0x00,0x1c,0x00,0x00,0x3e,0x00,0x00,0x3e,0x00,
> 
> 0120x00,0x7f,0x00,0x00,0x7f,0x00,0x80,0xff,0x00,0x80,0xff,0x00,0xc0,0xff,0x01,
> 
> 0120xc0,0xff,0x01,0xe0,0xff,0x03,0xe0,0xff,0x03,0xf0,0xff,0x07,0xf0,0xff,0x07,
> 
> 
> 0120xf8,0xff,0x0f,0xf8,0xff,0x0f,0xfc,0xff,0x1f,0xfc,0xff,0x1f,0xfe,0xff,0x3f,
> 
> 0 120xfe,0xff,0x3f,0xff,0xff,0x7f,0xff,0xff,0x7f,0xff,0xff,0x7f\012};'
> 
> self.UpButton = Button( self, bitmap=self.UpImage, command=self.moveup)
> 
> The "bitmap" option is expecting a name of a bitmap (either a builtin one,
> or an external one if preceded by the @), so this doesn't work as written.
> 
> Any suggestions on how to do this?

Look into the BitmapImage(data=...) widget.

  self.upbitmap = BitmapImage(name='upimage', data=UpImage)
  self.UpButton = Button(self, image=bitmap, command=self.moveup)

The "bitmap" option is not to be used, make sure you use "image" instead.
Also, make sure that the bitmap image exists for as long as the button.
If the BitmapImage object is deleted early, the button will have problems.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From dyoo@hkn.eecs.berkeley.edu  Sat May 26 09:46:27 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sat, 26 May 2001 01:46:27 -0700 (PDT)
Subject: [Tutor] OO scripting in python...
In-Reply-To: <718A0962DFC2D4119FF80008C7289E4701032D37@ICICIBACK3>
Message-ID: <Pine.LNX.4.21.0105260024430.3101-100000@hkn.eecs.berkeley.edu>

On Wed, 23 May 2001, GADGIL PRASAD     /INFRA/INFOTECH wrote:

> I am coming from moderate C, basic C++ knowledge, and some perl exp.

Hello; I hope you're having a good time learning Python.  I'll try to take
a shot at giving a small...er...long... overview of OOP.


> For OO scripting, the basic concepts I learned during c++ seems rather
> unconnected when I read py-tutorial chapter 9 (classes).  It seems
> individual languages like perl, python implement various basic
> concepts of OO in such different ways, with such varying grammer,
> especially with perl, I was totally confused with 'perltoot' (perl-

This is surprising; from what I remember, Perl's object orientedness is
actually based on Python's model.  Granted, the way that Perl implements
objects might look weird at first, but the idea of object oriented
programming, that information can be associated with a bunch of actions,
is the same.


> tom christian's O. O. tutorial') It seemd c++ is rather straight
> forward than that.

No comment about C++.  *grin*

For an introduction to OOP, I really like Damian Conway's "Objected
Oriented Perl" book.  The first chapter dedicates itself to explaining
what OOP is all about, so you might want to go to your local bookstore,
browse through chapter one, and then things might make more sense.


Before understanding OOP, it will help by seeing a few things that might
be already familiar to you --- from there, the idea of object oriented
programming might make more sense.

First an analogy to a computery thing: If we're on a Windows system, we
can take a look at one of our file directories, and press the right mouse
button on a file.  What appears on our screen is a list of actions that we
can perform.  "What sort of things can files do?"  --- this is a question
that's phrased in object-oriented terms.


At the heart of OOP is the idea that we have a thing, some data, that can
perform actions for us.  This is something that's totally natural to us:
As another example, if we have a car, we know that we can do certain
things with it.

    1.  Drive it around the block.
    2.  Wash it.
    3.  Crash it.

And we also know that a car has an identity, some data... like a license
plate number, or the color of the paint job.  So we can view a car, in
programming terms, as a structure or record.  Let's represent a car as a
dictionary,

###
def makeCar(plate_number, paint_job):
    return { 'plate_number' : plate_number,
             'paint_job' :  paint_job }
###

that we associate with certain actions:

###
def driveCar(car):
    print "Just drivin' my ", car['plate_number'], "around the block"

def washCar(car):
    print "The", car['paint_job'], "is starting to shimmer and shine."

def crashCar(car):
    print "Oh no!  We just dented our paint job!"
    car['paint_job'] = '*dented*' + car['paint_job'] + '*dented*'
###


Let's try it out:

###
>>> mycar = makeCar('1800ONERING', 'gold')
>>> mycar
{'paint_job': 'silver', 'plate_number': '1800ONERING'}
>>> driveCar(mycar)
Just drivin' my  1800ONERING around the block
>>> washCar(mycar)
The gold is starting to shimmer and shine.
>>> # muhahah
... 
>>> crashCar(mycar)
Oh no!  We just dented our paint job!
>>> washCar(mycar)
The *dented*gold*dented* is starting to shimmer and shine.
###


Believe it or not, that's practically most of what OOP is all about: when
we're writing programs that deal with data, we sometimes want to emphasize
that certain functions ("methods") should be really tied together with
that data.  In fact, much of the machinery in Python is there just to
prevent us from doing silly things like:

###
>>> washCar('foo!')
The
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/tmp/python-1762VZD", line 12, in washCar
TypeError: sequence index must be integer
###

just because it shouldn't make any sense to call washCar() on anything but
a Car made by our makeCar() function.


With this in mind, it might be instructive to look at how a Car would look
like, if we started using all the machinery Python gives us to make things
nicer looking.  Time to start using the "class" keyword.

###
class Car:
    def __init__(self, plate_number, paint_job):
        self.plate_number = plate_number
        self.paint_job = paint_job

    def drive(self):
        print "Just drivin' my ", self.plate_number, "around the block"

    def wash(self):
        print "The", self.paint_job, "is starting to shimmer and shine."

    def crash(self):
        print "Oh no!  We just dented our paint job!"
        self.paint_job = '*dented*' + self.paint_job + '*dented*'
###


The ideas here are the same; we're defining how to create a car with the
'__init__' definition (taking the place of makeCar()), and we tell Python
what sort of things a Car can do --- drive, wash, and crash! --- and the
code to use it looks similar:

###
>>> mycar = Car('1800RULETHEM', 'Aluminum')
>>> mycar.drive()
Just drivin' my  1800RULETHEM around the block
>>> mycar.wash()
The Aluminum is starting to shimmer and shine.
>>> mycar.crash()
Oh no!  We just dented our paint job!
>>> mycar.wash()
The *dented*Aluminum*dented* is starting to shimmer and shine.
###


Let's compare the two implementations of Cars: we'll see that this "class"
based approach emphasizes the activity of the car itself.  That is,
instead of saying "crashCar(car)", as if car were a passive thing being
acted upon, we're now saying "car.crash()".  We are commanding a poor,
hapless car, "car, crash for me!"  Passive voice and active voice?  
Hmmm...

Anyway, In C++, in Perl, in Python, all these mechanisms are there to make
our life easier.  I know the car analogy is stretching things a little bit
though: for a more realistic example, let's go back to files.  If we look
at what Python files are really like:

###
>>> myfile = open('carreports.txt', 'w')
>>> myfile
<open file 'carreports.txt', mode 'w' at 0x812cdb0>
###

it might come as a surprise to see that files in Python are object
oriented:

###
>>> dir(myfile)
['close', 'closed', 'fileno', 'flush', 'isatty', 'mode', 'name', 'read',
'readinto', 'readline', 'readlines', 'seek', 'softspace', 'tell',
'truncate', 'write', 'writelines']
###

There's our list of actions that files know how to do: they can be read(),
write()ed, seek()ed, and close()ed, among other things.  (Sorry about the
mangling of English there...)  So a file is some thing, some object, that
has a bunch of actions that we associate it with.


How about strings?  What can they do?

###
>>> mystring = 'hello'
>>> dir(mystring)
['capitalize', 'center', 'count', 'encode', 'endswith', 'expandtabs',
'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace',
'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace',
'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitlines', 'startswith',
'strip', 'swapcase', 'title', 'translate', 'upper']
###

Most likely you've already been working with object orientation quite a
bit: we just haven't been _calling_ it OOP since it sounds intimidating at
first.

There's a little more about OOP that we haven't touched yet (inheritence),
nor have we even talked about the "Why?" part:  Why do we do this OOP
stuff in the first place?  What are the advantages?  As a short answer:
it's usually easy for a programmer to handle objects since they're in
nice, neat packages, compared to functions that seem disconnected from the
data they work with.  But this message is getting too long already, so I'd
better stop for now.

I hope that this clears some things up; if you have more questions, feel
free to ask us.  Good luck to you.



From pursang@interact.net.au  Sat May 26 22:57:00 2001
From: pursang@interact.net.au (John Murray)
Date: Sat, 26 May 2001 21:57:00 +0000
Subject: [Tutor] OO scripting in python...
In-Reply-To: <Pine.LNX.4.21.0105260024430.3101-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105260024430.3101-100000@hkn.eecs.berkeley.edu>
Message-ID: <01052621570000.03154@localhost.localdomain>

On Saturday 26 May 2001 08:46, you wrote:
> On Wed, 23 May 2001, GADGIL PRASAD     /INFRA/INFOTECH wrote:

Daniel,
Your car analogy is the clearest and most easily understood introduction to 
OOP I have seen yet. I'm glad Gadgil asked the question......
 Cheers,
  John


From mlc@saigonnet.vn  Sun May 27 04:38:05 2001
From: mlc@saigonnet.vn (mlc)
Date: Sun, 27 May 2001 10:38:05 +0700
Subject: [Tutor] please teach me to begin
Message-ID: <000801c0e65e$7122e340$1201a8c0@mlc>

This is a multi-part message in MIME format.

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



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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0005_01C0E699.1CD24160--



From dsh8290@rit.edu  Sat May 26 16:53:01 2001
From: dsh8290@rit.edu (D-Man)
Date: Sat, 26 May 2001 11:53:01 -0400
Subject: [Tutor] please teach me to begin
In-Reply-To: <000801c0e65e$7122e340$1201a8c0@mlc>; from mlc@saigonnet.vn on Sun, May 27, 2001 at 10:38:05AM +0700
References: <000801c0e65e$7122e340$1201a8c0@mlc>
Message-ID: <20010526115301.A3600@harmony.cs.rit.edu>

On Sun, May 27, 2001 at 10:38:05AM +0700, mlc wrote:
| 

start with downloading the interpreter from www.python.org, then
reading www.crosswinds.net/~agauld  (I also recommend gvim from
www.vim.org, but that is another big learning experience :-))

-D



From wheelege@tsn.cc  Sat May 26 17:24:28 2001
From: wheelege@tsn.cc (wheelege)
Date: Sun, 27 May 2001 02:24:28 +1000
Subject: [Tutor] Multiple identical keys in a dictionary
Message-ID: <020801c0e600$56d59400$0200a8c0@ACE>

This is a multi-part message in MIME format.

------=_NextPart_000_0205_01C0E654.27F3BBE0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

  Hi all,

  I'm implementing a high score table for this game I'm writing in =
python (tkinter) and I thought it would be nice to use a dictionary for =
all the high scores - with the score as the key.
  A rather annoying problem has presented itself in that if somebody =
scores the same as another then one of the two (or however many are =
equal) is kept and the rest overwritten.  The reason I had thrown out a =
list was because I want to store things other than just the score (such =
as name, highest level reached, difficulty level).
  The same thing will happen if I use strings and convert to int then =
sort, then convert back to a string for updating the dict.
  Anyway, the essence of the problem is...

>>> d =3D {100: ['Jim', 'Hard', 10], 50: ['Bob', 'Easy', 6], 20: =
['Fred', 'Silly', 2]}
>>> d[50] =3D ['Darren', 'Medium', 3]
>>> d
{100: ['Jim', 'Hard', 10], 20: ['Fred', 'Silly', 2], 50: ['Darren', =
'Medium', 3]}

  And I'm probably asking for the impossible, but what I'd like instead =
is...

>>> d =3D {100: ['Jim', 'Hard', 10], 50: ['Bob', 'Easy', 6], 20: =
['Fred', 'Silly', 2]}
>>> d[50] =3D ['Darren', 'Medium', 3]
>>> d
{100: ['Jim', 'Hard', 10], 20: ['Fred', 'Silly', 2], 50: ['Darren', =
'Medium', 3], 50: ['Bob', 'Easy', 6]}
>>>=20

  So I'm left thinking - what other data structure to use?  A class for =
just the scores seems a little excessive...especially as I'm already =
using a class to handle all the reading and writing to the actual file =
and things like that.

  Thanks,
  Glen.

------=_NextPart_000_0205_01C0E654.27F3BBE0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Hi all,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; I'm implementing a high score table for this game I'm =
writing in=20
python (tkinter) and I thought it would be nice to use a dictionary for =
all the=20
high scores - with the score as the key.</DIV>
<DIV>&nbsp; A rather annoying problem has presented itself in that if =
somebody=20
scores the same as another then one of the two (or however many are =
equal) is=20
kept and the rest overwritten.&nbsp; The reason I had thrown out a list =
was=20
because I want to store things other than just the score (such as name, =
highest=20
level reached, difficulty level).</DIV>
<DIV>&nbsp; The same thing will happen if I use strings and convert to =
int then=20
sort, then convert back to a string for updating the dict.</DIV>
<DIV>&nbsp; Anyway, the essence of the problem is...</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&gt;&gt; d =3D {100: ['Jim', 'Hard', 10], 50: ['Bob', 'Easy', =
6], 20:=20
['Fred', 'Silly', 2]}<BR>&gt;&gt;&gt; d[50] =3D ['Darren', 'Medium',=20
3]<BR>&gt;&gt;&gt; d<BR>{100: ['Jim', 'Hard', 10], 20: ['Fred', 'Silly', =
2], 50:=20
['Darren', 'Medium', 3]}<BR></DIV>
<DIV>&nbsp; And I'm probably asking for the impossible, but what I'd =
like=20
instead is...</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&gt;&gt; d =3D {100: ['Jim', 'Hard', 10], 50: ['Bob', 'Easy', =
6], 20:=20
['Fred', 'Silly', 2]}<BR>&gt;&gt;&gt; d[50] =3D ['Darren', 'Medium',=20
3]<BR>&gt;&gt;&gt; d<BR>{100: ['Jim', 'Hard', 10], 20: ['Fred', 'Silly', =
2], 50:=20
['Darren', 'Medium', 3], 50: ['Bob', 'Easy', 6]}<BR>&gt;&gt;&gt; </DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;So I'm left thinking - what other data structure to =
use?&nbsp;=20
A class for just the scores seems a little excessive...especially as I'm =
already=20
using a class to handle all the reading and writing to the actual file =
and=20
things like that.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_0205_01C0E654.27F3BBE0--



From deirdre@deirdre.net  Sat May 26 17:45:09 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Sat, 26 May 2001 09:45:09 -0700
Subject: [Tutor] Multiple identical keys in a dictionary
In-Reply-To: <020801c0e600$56d59400$0200a8c0@ACE>
References: <020801c0e600$56d59400$0200a8c0@ACE>
Message-ID: <a05100e03b7358cddc4d2@[169.254.124.249]>

>   I'm implementing a high score table for this game I'm writing in 
>python (tkinter) and I thought it would be nice to use a dictionary 
>for all the high scores - with the score as the key.

You should use the place as a key and the value should be a tuple of 
the score and the name.

-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From dyoo@hkn.eecs.berkeley.edu  Sat May 26 17:51:23 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Sat, 26 May 2001 09:51:23 -0700 (PDT)
Subject: [Tutor] Multiple identical keys in a dictionary
In-Reply-To: <020801c0e600$56d59400$0200a8c0@ACE>
Message-ID: <Pine.LNX.4.21.0105260943580.8582-100000@hkn.eecs.berkeley.edu>

On Sun, 27 May 2001, wheelege wrote:

>   Anyway, the essence of the problem is...
> 
> >>> d = {100: ['Jim', 'Hard', 10], 50: ['Bob', 'Easy', 6], 20: ['Fred', 'Silly', 2]}
> >>> d[50] = ['Darren', 'Medium', 3]
> >>> d
> {100: ['Jim', 'Hard', 10], 20: ['Fred', 'Silly', 2], 50: ['Darren', 'Medium', 3]}
> 
>   And I'm probably asking for the impossible, but what I'd like instead is...
> 
> >>> d = {100: ['Jim', 'Hard', 10], 50: ['Bob', 'Easy', 6], 20: ['Fred', 'Silly', 2]}
> >>> d[50] = ['Darren', 'Medium', 3]
> >>> d
> {100: ['Jim', 'Hard', 10], 20: ['Fred', 'Silly', 2], 
>  50: ['Darren', 'Medium', 3], 50: ['Bob', 'Easy', 6]}

One way you can do this is by having the dictionary go from a particular
score to list of people who've gotten that score.  Let's take a look at
how the structure might initially look like.

    d = {100: [['Jim', 'Hard', 10]], 
         50: [['Bob', 'Easy', 6]],
         20: [['Fred', 'Silly', 2]]}

This will seem weird at first; we'll be containing a lot of lists with
only one element, so it seems wasteful.  However, this approach will allow
us to do to something like this:

    d[50].append(['Darren', 'Medium', 3])

and now we know that a score of 50 matches up with a list of two people.

Good luck to you!



From rick@niof.net  Sat May 26 18:47:48 2001
From: rick@niof.net (Rick Pasotto)
Date: Sat, 26 May 2001 13:47:48 -0400
Subject: [Tutor] Multiple identical keys in a dictionary
In-Reply-To: <020801c0e600$56d59400$0200a8c0@ACE>; from wheelege@tsn.cc on Sun, May 27, 2001 at 02:24:28AM +1000
References: <020801c0e600$56d59400$0200a8c0@ACE>
Message-ID: <20010526134748.E2517@tc.niof.net>

What I would do is to use a list of tuples:

>>> scores = []
>>> scores.append(('0050', 'Bob', 'Easy', 6))
>>> scores.append(('0020', 'Fred', 'Silly', 2))
>>> scores.append(('0100', 'Jim', 'Hard',10))
>>> scores.append(('0050', 'Darren', 'Medium', 3))

Then when you want to print them out, high scores first:

>>> scores.sort(lambda x,y: -1 * cmp(x,y))
>>> for s in scores:
...    print "%8s: %3d" % (s[1],int(s[0]))

     Jim: 100
  Darren:  50
     Bob:  50
    Fred:  20

The trick is to store the scores as a zero-filled string.

On Sun, May 27, 2001 at 02:24:28AM +1000, wheelege wrote:
>   Hi all,
> 
>   I'm implementing a high score table for this game I'm writing in
>   python (tkinter) and I thought it would be nice to use a dictionary
>   for all the high scores - with the score as the key.
>
>   A rather annoying problem has presented itself in that if somebody
>   scores the same as another then one of the two (or however many are
>   equal) is kept and the rest overwritten.  The reason I had thrown
>   out a list was because I want to store things other than just the
>   score (such as name, highest level reached, difficulty level).
>
>   The same thing will happen if I use strings and convert to int then
>   sort, then convert back to a string for updating the dict.
>
>   Anyway, the essence of the problem is...
> 
> >>> d = {100: ['Jim', 'Hard', 10], 50: ['Bob', 'Easy', 6], 20:
> >>> ['Fred', 'Silly', 2]} d[50] = ['Darren', 'Medium', 3] d
> {100: ['Jim', 'Hard', 10], 20: ['Fred', 'Silly', 2], 50: ['Darren',
> 'Medium', 3]}
> 
>   And I'm probably asking for the impossible, but what I'd like
>   instead is...
> 
> >>> d = {100: ['Jim', 'Hard', 10], 50: ['Bob', 'Easy', 6], 20:
> >>> ['Fred', 'Silly', 2]} d[50] = ['Darren', 'Medium', 3] d
> {100: ['Jim', 'Hard', 10], 20: ['Fred', 'Silly', 2], 50: ['Darren',
> 'Medium', 3], 50: ['Bob', 'Easy', 6]}
> >>> 
> 
>   So I'm left thinking - what other data structure to use?  A class
>   for just the scores seems a little excessive...especially as I'm
>   already using a class to handle all the reading and writing to the
>   actual file and things like that.
> 
>   Thanks, Glen.

-- 
Within the limits of equity, everything is to be accomplished
through the free and perfectible initiative of man; nothing is to
be achieved by law or by force save universal justice.
	-- Frédéric Bastiat (1801-1850)
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From sarnold@earthling.net  Sat May 26 21:30:19 2001
From: sarnold@earthling.net (Stephen L Arnold)
Date: Sat, 26 May 2001 13:30:19 -0700
Subject: [Tutor] Re: Zope
In-Reply-To: <a05100e09b731ec691e67@[169.254.124.249]>
References: <3B0C2FCC.22A641D2@centre.edu>
Message-ID: <20010526203019.C2BB01F661@shiva.arnolds.bogus>

On 23 May 01, at 15:39, Deirdre Saoirse Moen wrote:

> At 5:46 PM -0400 5/23/01, Timothy M. Brauch wrote:
> >I'm just curious, does anyone use or know much about Zope?  I'm 
> >starting to look at it st for fun (oh god, did I just say that?).
> 
> Zope is so specific that you're better off getting info on a Zope 
> list. That said, I know enough about it that I'm not a fan.

You're right, Zope is relatively specific in it's intended purpose, 
but it seems to fulfill a pretty broad set of web-centric 
applications.  While it doesn't meet the Big Book of Universal 
Requirements, it's got some pretty cool and well-implemented ideas. 
 From what I saw at Python9, the next Zope architecture should be 
way better.

For something less monolithic, and more to Deirdre's liking :) you 
could check out webware:

http://webware.sourceforge.net/

I had bookmarked it way back when, and then promptly forgot about 
it (doh!) but when I saw Chuck Esterbrook's talk at the conference, 
I was extremely impressed by the clean modular design.  Very cool :)

HTH, Steve

*************************************************************
Steve Arnold                            sarnold@earthling.net
                                       http://arnolds.dhs.org
Java is for staying up late while you program in Python...


From tmbrau00@centre.edu  Sat May 26 23:13:09 2001
From: tmbrau00@centre.edu (Timothy M. Brauch)
Date: Sat, 26 May 2001 18:13:09 -0400
Subject: [Tutor] lambda and map
Message-ID: <3B102A75.5752DD63@centre.edu>

Okay, I am now what I would call competent in Python.  But, I keep
noticing (learning) some new stuff every time I get an email from
tutor.  There is, however, one thing I am not really sure about,
lambda.  I don't quite understand what a lambda does or why to use it. 
I think I understand map, more or less, but the two are often seen
together.

 - Tim


From kalle@gnupung.net  Sat May 26 23:56:37 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Sun, 27 May 2001 00:56:37 +0200
Subject: [Tutor] lambda and map
In-Reply-To: <3B102A75.5752DD63@centre.edu>; from tmbrau00@centre.edu on Sat, May 26, 2001 at 06:13:09PM -0400
References: <3B102A75.5752DD63@centre.edu>
Message-ID: <20010527005637.A8274@father>

Sez Timothy M. Brauch:
> Okay, I am now what I would call competent in Python.  But, I keep
> noticing (learning) some new stuff every time I get an email from
> tutor.  There is, however, one thing I am not really sure about,
> lambda.  I don't quite understand what a lambda does or why to use it.

The lambda operator creates an anonymous function.  That is, it creates a
callable object without automatically binding it to a name.

func = lambda arg: <expression>
is very similar to 
def func(arg):
    return <expression>

Lambdas are a bit crippled in that they are limited to one expression and
can't contain statements (like print).  They also don't provide anything
that can't be done with ordinary functions or callable class instances.  In
fact, the use of lambda seems to be generally viewed as a bit suspicious...

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From pdiaz88@terra.es  Sun May 27 02:11:17 2001
From: pdiaz88@terra.es (Pedro Diaz Jimenez)
Date: Sun, 27 May 2001 01:11:17 +0000
Subject: [Tutor] lambda and map
In-Reply-To: <3B102A75.5752DD63@centre.edu>
References: <3B102A75.5752DD63@centre.edu>
Message-ID: <01052701111704.02795@duero>

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


Thats because map needs a funcition, like reduce or filter. lambda functions 
are the fast food of programming: not much content, but you can use it 
inmediatlly

say you wanna filter [1,2,3,4,5,6] taking away the odd numbers
if you don't use lambda, you have to
def isOdd(n):
	blah
	blah

filter( isOdd, [1,2,3,4,5] );

With lambda calculus, is just:
>>> filter( lambda x: (x%2)==0, [1,2,3,4,5,6] )
[2, 4, 6]
>>>

voila!

Cheers
Pedro

On Saturday 26 May 2001 22:13, Timothy M. Brauch wrote:
> Okay, I am now what I would call competent in Python.  But, I keep
> noticing (learning) some new stuff every time I get an email from
> tutor.  There is, however, one thing I am not really sure about,
> lambda.  I don't quite understand what a lambda does or why to use it.
> I think I understand map, more or less, but the two are often seen
> together.
>
>  - Tim
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

- -- 

/*
 * Pedro Diaz Jimenez
 * pdiaz88@terra.es 
 * pdiaz@acm.asoc.fi.upm.es
 *
 * Wanna see how 100000! looks like?:
 * http://acm.asoc.fi.upm.es/~pdiaz/fact_100.000
 * 
 * La sabiduria me persigue, pero yo soy mas rapido
 *
 */

Random quote:
- -------------

After your lover has gone you will still have PEANUT BUTTER!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7EFQ1nu53feEYxlERAhqcAKDOJ7iQXQ/+4iIY+xYAToe29NywvgCgwcmu
PetmNNTZthZ8PwPbCYZv71A=
=CPXd
-----END PGP SIGNATURE-----


From wheelege@tsn.cc  Sun May 27 01:39:02 2001
From: wheelege@tsn.cc (wheelege)
Date: Sun, 27 May 2001 10:39:02 +1000
Subject: [Tutor] Multiple identical keys in a dictionary
References: <Pine.LNX.4.21.0105260943580.8582-100000@hkn.eecs.berkeley.edu>
Message-ID: <003101c0e645$6dd0b460$0200a8c0@ACE>

  Thanks Daniel, Deirdre and Rick - all your suggestions would work fine.  I
think I'll go with what Daniel suggested, because it will fit with my
existing architecture nicely.  Although using the rank as a key could be a
much easier way to do it all round...and Rick's suggestion was something I
had just never even considered before...  So many choices :)

  Thanks again!
  Glen.



From kojo@hal-pc.org  Sun May 27 05:22:11 2001
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Sat, 26 May 2001 23:22:11 -0500
Subject: [Tutor] Off-Topic: Deirdre the Celeb
Message-ID: <5.0.2.1.0.20010526180420.00b088f8@Pop3.norton.antivirus>

Did anyone else notice a quote from our list co-owner in the June issue of 
Linux Journal?  It's on page 14.  Not Python related, but it was kind of 
neat to see a quote from someone I "know".

That is all.  We now return you to your already scheduled Python-learning 
discussion, already in progress...

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

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



From tim@johnsons-web.com  Sun May 27 17:58:51 2001
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 27 May 2001 08:58:51 -0800
Subject: [Tutor] Selecting Modules to Compile
Message-ID: <20010527085851.A21343@johnsons-web.com>

Hello All:
	I have python 2.0 installed. I did so on RH 6.0 via rpm,
but would like to do some experimentation on customizing and selectively
compiling the python binary. 

What I have in mind is a alternate interpreter that would have only
what I need, plus (perhaps) my own addition. I would welcome
being pointed towards documentation or discussions of such.

Thanks!
-- 
Tim Johnson <tim@johnsons-web.com>
       http://www.johnsons-web.com
  "My shroe, my shroe, my dingkom for a shroe!"
  --TheManWhoSpeaksInAnagrams (Monty Python)


From steve@opensourcedirectory.com  Sun May 27 11:29:55 2001
From: steve@opensourcedirectory.com (Steve Mallett)
Date: Sun, 27 May 2001 07:29:55 -0300
Subject: [Tutor] starting from scratch.
Message-ID: <01052707295503.01102@localhost.localdomain>

I've decided to take up programming and choosen to start with Python (after 
some research).

One thing that is not terribly clear is if I should've started somewhere else 
& let that lead me to Python.

Q's
1) I know this list is for beginners, but for scratch beginners?
2) Will I benefit from starting with "Learning Python" from O'Reilly?  
Someone told me to start with learning shell scripting, but I wonder if 
that's not a bias'd opinion.
3) Should I start somewhere else & lead up to Python?


Kindest regards,
-- 
Steve Mallett
steve@opensourcedirectory.com | http:www.opensourcedirectory.org
aka <spaceman> #osd, irc.openprojects.net

Member of OSDN's Community Sites: http://osdn.com/gallery.pl?type=community

----------------------------
http://personal.nbnet.nb.ca/blab/ <vanity site>


From rob@jam.rr.com  Sun May 27 17:32:04 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Sun, 27 May 2001 11:32:04 -0500
Subject: [Tutor] starting from scratch.
References: <01052707295503.01102@localhost.localdomain>
Message-ID: <3B112C04.C312CE3@jam.rr.com>

Steve Mallett wrote:
> 
> I've decided to take up programming and choosen to start with Python (after
> some research).
> 
> One thing that is not terribly clear is if I should've started somewhere else
> & let that lead me to Python.
> 
> Q's
> 1) I know this list is for beginners, but for scratch beginners?
> 2) Will I benefit from starting with "Learning Python" from O'Reilly?
> Someone told me to start with learning shell scripting, but I wonder if
> that's not a bias'd opinion.
> 3) Should I start somewhere else & lead up to Python?
> 

Python is a great place to start, really. And this list is usually
populated with any number of absolute beginners. If you have never
programmed in your life, I wouldn't recommend "Learning Python" as your
first book, but it might make a good second. "Learning to Program"
(http://www.crosswinds.net/~agauld/) is a great starting point, and you
can read a good sample of the material on the website while waiting for
your book to arrive.

There are links to quite a few tutorials and such on the Useless Python
site, which members of this list contribute to. Download any Python
distribution you wish, start working your way through a tutorial, and
ask us what's going on when you get stumped by something.

Enjoy!
Rob

-- 

Useless Python!
It's the right thing to do.
http://www.lowerstandard.com/python/pythonsource.html


From scarblac@pino.selwerd.nl  Sun May 27 17:46:53 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sun, 27 May 2001 18:46:53 +0200
Subject: [Tutor] starting from scratch.
In-Reply-To: <01052707295503.01102@localhost.localdomain>; from steve@opensourcedirectory.com on Sun, May 27, 2001 at 07:29:55AM -0300
References: <01052707295503.01102@localhost.localdomain>
Message-ID: <20010527184653.A31768@pino.selwerd.nl>

On  0, Steve Mallett <steve@opensourcedirectory.com> wrote:
> I've decided to take up programming and choosen to start with Python (after 
> some research).
> 
> One thing that is not terribly clear is if I should've started somewhere else 
> & let that lead me to Python.
> 
> Q's
> 1) I know this list is for beginners, but for scratch beginners?

Yep. Anyone who wants to learn Python or help others to learn it.

> 2) Will I benefit from starting with "Learning Python" from O'Reilly?

I don't know. It's a good book, but I think it's hard to read if you can't
program yet.

I point most people to Alan Gauld's web tutorial at
http://www.crosswinds.net/~agauld/ . He's active on this list, it's easier
on the list if most people use the same tutorial (if several people have
difficulty with something here, Alan can change it), and it's available as a
book now as well.

Other books I've heard good things about are Core Python Programming, the
Quick Python Book and Teach Yourself Python in 24 Hours. But I don't know
them myself.

> Someone told me to start with learning shell scripting, but I wonder if 
> that's not a bias'd opinion.

Nah. Shell scripting is weird in many ways, and anything you can use it for,
Python will be at least as good at. Maybe not quite as succint as shell
scripts, but Python will be a lot less cryptic.

> 3) Should I start somewhere else & lead up to Python?

No. Wouldn't know where :-).

-- 
Remco Gerlich


From kalle@gnupung.net  Sun May 27 17:50:04 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Sun, 27 May 2001 18:50:04 +0200
Subject: [Tutor] starting from scratch.
In-Reply-To: <01052707295503.01102@localhost.localdomain>; from steve@opensourcedirectory.com on Sun, May 27, 2001 at 07:29:55AM -0300
References: <01052707295503.01102@localhost.localdomain>
Message-ID: <20010527185004.A10157@father>

Sez Steve Mallett:
> Q's
> 1) I know this list is for beginners, but for scratch beginners?

Absolutely!  The beginninger the better! <wink>

> 2) Will I benefit from starting with "Learning Python" from O'Reilly?

Hmmm...  That depends.
For the absolute beginner with computers, or one that's only used Windows to
run Word, it's a bit heavy, I think.  If you're not afraid to test stuff and
used to finding out some details for yourself, it should be good.
Disclaimer:  I've only read it once, and not in great detail.  I knew python
before anyway.

> Someone told me to start with learning shell scripting, but I wonder if 
> that's not a bias'd opinion.

Is there such a thing as an unbiased opinion?
Anyway, I suggest going with Python.  Shell scripting isn't as useful or
enjoyable, and might give you bad habits.  That's my (biased) opinion.

> 3) Should I start somewhere else & lead up to Python?

No, I think Python is a great beginners language.  Check out the thread
starting at http://mail.python.org/pipermail/tutor/2001-May/005905.html for
a few reasons.

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From sheila@thinkspot.net  Sun May 27 18:01:09 2001
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 27 May 2001 10:01:09 -0700
Subject: [Tutor] starting from scratch.
In-Reply-To: <20010527184653.A31768@pino.selwerd.nl>
References: <01052707295503.01102@localhost.localdomain> <20010527184653.A31768@pino.selwerd.nl>
Message-ID: <202216532C6@kserver.org>

On Sun, 27 May 2001 18:46:53 +0200, Remco Gerlich
<scarblac@pino.selwerd.nl>  wrote about Re: [Tutor] starting from
scratch.:

:Other books I've heard good things about are Core Python Programming, the
:Quick Python Book and Teach Yourself Python in 24 Hours. But I don't know
:them myself.

I have copies of Core Python Programming and Quick Python, and I
wouldn't recommend them to a totally new programmer. Both seem to assume
that you have some previous acquaintance with programming, via another
language, and do not take you by the hand, as most beginner books do,
and explain everything to you from scratch.

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

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


From deirdre@deirdre.net  Sun May 27 18:52:12 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Sun, 27 May 2001 10:52:12 -0700
Subject: [Tutor] starting from scratch.
In-Reply-To: <01052707295503.01102@localhost.localdomain>
References: <01052707295503.01102@localhost.localdomain>
Message-ID: <a05100e06b736ee6cf739@[169.254.124.249]>

>I've decided to take up programming and choosen to start with Python (after
>some research).
>
>One thing that is not terribly clear is if I should've started somewhere else
>& let that lead me to Python.
>
>Q's
>1) I know this list is for beginners, but for scratch beginners?

Yes.

>2) Will I benefit from starting with "Learning Python" from O'Reilly?

I think two of the other books are probably better for beginners. I 
know Wes Chun's is designed that way and people have already 
recommended Alan Gauld's.

>Someone told me to start with learning shell scripting, but I wonder if
>that's not a bias'd opinion.

Shell scripting is NOT, imho, as a programmer of 25 years experience,

>3) Should I start somewhere else & lead up to Python?

And where would you find helpful people like us? :)
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From wilson@visi.com  Sun May 27 19:33:06 2001
From: wilson@visi.com (Timothy Wilson)
Date: Sun, 27 May 2001 13:33:06 -0500 (CDT)
Subject: [Tutor] starting from scratch.
In-Reply-To: <01052707295503.01102@localhost.localdomain>
Message-ID: <Pine.GSO.4.21.0105271331170.12070-100000@isis.visi.com>

On Sun, 27 May 2001, Steve Mallett wrote:

> 2) Will I benefit from starting with "Learning Python" from O'Reilly?  

I think "Learning Python" is good, but as a complete beginner you might find
"How to Think Like a Computer Scientist" helpful. The online edition is at
http://www.ibiblio.org/obp/thinkCSpy/

Good luck.

-Tim

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



From alan.gauld@bt.com  Sun May 27 19:41:49 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 27 May 2001 19:41:49 +0100
Subject: [Tutor] lambda and map
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7D9@mbtlipnt02.btlabs.bt.co.uk>

> Okay, I am now what I would call competent in Python.  But, I keep
> noticing (learning) some new stuff every time I get an email from
> tutor.  There is, however, one thing I am not really sure about,
> lambda.  I don't quite understand what a lambda does or why 
> to use it. 

First, I will (as usual? :-) recommend you visit my tutor 
and read the Functional Programming advbanced topic. It 
explains how lambda works and to some extent why.

http://www.crosswinds.net/~agauld/

Now the short answer:

lambda is just a shortcut for defining a single 
line function. It saves us cluttering up our code with lots of little
functions that only get used one.

thus:

double = lambda x : x*2

is identical to:

def double(x): return x*2

But in situations where we need to pass a function object - like map() we
can create the lambda within the map function call instead of defining it as
a function first. Thus

def double(x): return x*2
twos = map(double, range(6))

is the same as but longer than:

twos = map(lambda x: x*2, range(6))

There is also another use, particularly in programming 
Tkinter where we use a lambda within a loop to create 
the command function for a set of widgets. If the 
function has a default parameter. You cant do that 
by defining a function because the default parameter
is set when you define it, however using lambda inside 
the loop we create a new default each time thru the loop.


(See my hmgui.py code in the Games framework on Useless 
  Python for an example of this use.)

HTH.

Personal aside to the list...
To be honest, in Python lamda is a bit limited 
- essentially to single line expressions.
I'm not sure why we can't do:

>>>modmult = lambda x,y:
         result = x * y
         if result > 0:
            return result
         else: return (-1 * result)

>>>modmult(4,3)
12
>>>modmult(4,-3)
12

I know that in this case a def modmult(x,y): would do 
the same(*) but given lambda's use of a colon I'd have 
thought the extra to allow block defintions would 
have been viable.

Alan G.


From alan.gauld@bt.com  Sun May 27 19:47:02 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 27 May 2001 19:47:02 +0100
Subject: [Tutor] lambda and map
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7DA@mbtlipnt02.btlabs.bt.co.uk>

> They also don't provide anything
> that can't be done with ordinary functions or callable class 
> instances.  

While that true, the callable class thing is quite an 
overhead compared to defining a lambda. And functions 
cant handle the looped gui callback creation type scenario 
so the only alternative is callable classes...

I much prefer lambdas to cluttering up my namesace with 
lots of little function I only use once.

But maybe thats coz I used to be a lisper...

Alan g.


From kalle@gnupung.net  Sun May 27 20:20:14 2001
From: kalle@gnupung.net (Kalle Svensson)
Date: Sun, 27 May 2001 21:20:14 +0200
Subject: [Tutor] lambda and map
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D7D9@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Sun, May 27, 2001 at 07:41:49PM +0100
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D7D9@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20010527212014.B10157@father>

Sez alan.gauld@bt.com:
> Personal aside to the list...
> To be honest, in Python lamda is a bit limited 
> - essentially to single line expressions.
> I'm not sure why we can't do:
[multiple statement/expression lambdas]

I think because Guido wanted it crippled.  He has later expressed the
opinion that letting lambda in at all was a mistake.  Somebody who was
out of diapers in the early 1990's might know. <wink>

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


From bsass@freenet.edmonton.ab.ca  Sun May 27 21:45:41 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Sun, 27 May 2001 14:45:41 -0600 (MDT)
Subject: [Tutor] a ScoreList class (was: Multiple identical keys in a dictionary)
In-Reply-To: <020801c0e600$56d59400$0200a8c0@ACE>
Message-ID: <Pine.LNX.4.33.0105261155300.4124-100000@bms>

On Sun, 27 May 2001, wheelege wrote:

<...>
>   So I'm left thinking - what other data structure to use?  A class
for just the scores seems a little excessive...especially as I'm
already using a class to handle all the reading and writing to the
actual file and things like that.

Whether or not a class makes sense for a score list depends on what
you want to do with the scores, and should have nothing to do with how
many other classes you may have already devised for the program.

If all you are doing is keeping a list of scores which you want to
display every now and then, a simple list of tuples is probably best.
A dictionary looks attractive in general, but depends on having a
unique key for each entry to really shine... if you don't have a
unique key available you may end up losing any advantage dicts give
you through needing to handle collisions yourself, and manually
looking through the values of the dict to find whatever data you need.
i.e., It may be easier to generalize extracting data from a flat list
of tuples, where all datum are equal, than the case where one piece of
data is artifically elevated in importance and everything else must be
done in terms of a relationship to it.

An example is aways best...
(works with 1.5.2, lots of tweaks can be done to improve it,
especially if you are using a 2.x interpreter)

---8<--- scores.py ---
class Score:
    """Defines the basic properties of a 'score'."""
    def __init__(self, player=None, value=None, level=None):
        self.player = player
        self.value = value
        self.level = level
        # there may be other things to keep track of, like...
        #... is "level" the game play level or the players skill level
        #... when they finished.  Putting stuff into a class lets you
        #... add properties later on without needing to rewrite old
        #... code (new code uses the new stuff, old code doesn't even
        #... know it exists).

    def __cmp__(self, other):
        """Allows for comparison with other Score-s and numerics."""
        if isinstance(other, Score):
            cmpval = other.value
        else:
            cmpval = other
        if self.value < cmpval:
            return -1
        elif self.value == cmpval:
            return 0
        else:
            return 1

    # these are setup to have an ok display in this specific
    #... situation, you would probably want something a little
    #... fancier/better for an actual application.
    def __str__(self):
        return "%s %s (%s)" % \
               (self.player, self.value, self.level)

    def __repr__(self):
        return "Score(%s, %s, %s)" % \
               (self.player, self.value, self.level)


class ScoreList:
    """A high-level interface to a list of scores.

    You get:
    - "cutoff", so only the most deserving make it into the list
    - "+" operator, for an implementation independent interface
    - "top" method to easily extract the top scores
    - "name" and "level" methods, for extracting specific info

    """
    def __init__(self, scores=None, cutoff=None):
        if scores == None:
            self.values = []
        else:
            self.values = scores
        self.cutoff = cutoff

    def __add__(self, score):
        # I think this bit is most significant; it defines the
        #... semantics of adding to the list and is where you would
        #... do any 'magic' needed to ensure the list has the
        #... properties you want.  So far the only 'magic' is the
        #... disappearing score if it is below the cutoff.
        if self.cutoff == None or score > self.cutoff:
            self.values.append(score)
        return ScoreList(self.values, self.cutoff)

    def __str__(self):
        import string
        self.values.sort()
        return string.join(map(str, self.values), '\n')


    def top(self, number):
        self.values.sort()
        return ScoreList(self.values[-number:], self.cutoff)

    # These two methods are identical in form, and that form should
    #... be generalized so one can use any attribute as a key and get
    #... all the associated information back, IMO.
    def name(self, name):
        result = []
        for item in self.values:
            if item.player == name:
                result.append((item.value, item.level))
        return result

    def level(self, level):
        result = []
        for item in self.values:
            if item.level == level:
                result.append((item.player, item.value))
        return result


if __name__ == '__main__':
    # set things up
    from random import randint
    ri = randint

    # you need a score of 2500 to get into the hiscore list
    hiscores = ScoreList(cutoff=2500)

    # generate random test data...
    for i in range(3):
        for j in range(1,7):
            ascore = Score('player'+str(j), ri(0,5000), ri(1,10))
            hiscores = hiscores + ascore
    # ...with some specific properties...
    for i in range(3):
        for j in range(1,4):
            part = ri(0,5000), ri(1,10)
            hiscores = hiscores \
                       + Score('player'+str(j), part[0], part[1]) \
                       + Score('player'+str(j+3), part[0], part[1])
    # ...although you probably want something a little more thorough.

    # after going through all the above, use had better be simple...
    print "\nAll scores:\n", hiscores
    print "\nTop 3:\n", hiscores.top(3)
    print "\nTop 10:\n", hiscores.top(10)
    print "\nBy player..."
    for i in range(1,6):
        name = 'player' + str(i)
        print name + ": ", hiscores.name(name)
    print "\nBy level..."
    for i in range(1,11):
        print "level" + str(i) + ": ", hiscores.level(i)

--->8---

Overkill???, sure... unless, for example:  you have written the next
wildly popular networked game and have a thousand dedicated users
asking you for a way to analyse hiscore lists, or pestering you
because they don't like the hardcoded default you think looks great;
perhaps you just don't want to re-write or integrate(-yet-again) a
score list subsystem everytime you code up a game, having all the core
bits in a class or two make for easy code re-use; or maybe you want to
allow for others to expand on what you have done, so they can have
their own fancy hiscore display, without having to re-write your code
and risk introducing incompatibilities.

Generally, I think you will find that as programs get larger, and the
user base increases, it becomes more and more attractive to use
classes.  Simply because it is easier to modify the behaviour of a
class than to track down and change a convention you scattered
throughout your code, or keep track of a bunch of stand-alone
functions and data structure declarations when you need to change or
replicate some behaviour.

Food for thought, I hope.


- Bruce





From rob@jam.rr.com  Sun May 27 21:44:46 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Sun, 27 May 2001 15:44:46 -0500
Subject: [Tutor] Python books online
Message-ID: <3B11673E.4E527767@jam.rr.com>

Here's a link to a February article on some of the Python books
available online. If anyone has missed onlamp.com's Python section, it's
worth checking out (and I don't just say that because they favorably
reviewed Useless Python ;-> ).

http://www.onlamp.com/pub/a/python/2001/02/07/pythonnews.html
-- 

Useless Python!
It's the right thing to do.
http://www.lowerstandard.com/python/pythonsource.html


From tim.one@home.com  Sun May 27 22:04:54 2001
From: tim.one@home.com (Tim Peters)
Date: Sun, 27 May 2001 17:04:54 -0400
Subject: [Tutor] lambda and map
In-Reply-To: <20010527212014.B10157@father>
Message-ID: <LNBBLJKPBEHFEDALKOLCEEMJKEAA.tim.one@home.com>

[alan.gauld@bt.com]
> Personal aside to the list...
> To be honest, in Python lamda is a bit limited
> - essentially to single line expressions.
> I'm not sure why we can't do:
> [multiple statement/expression lambdas]

[Kalle]
> I think because Guido wanted it crippled.

No, "lambda" was contributed code -- Guido had nothing to do with it apart
from approving the idea and applying the patch.

> He has later expressed the opinion that letting lambda in at all
> was a mistake.  Somebody who was out of diapers in the early
> 1990's might know. <wink>

I'm older than Guido, but that doesn't mean I've outgrown diapers <wink>.
Guido considered lambda (along with map(), filter() and reduce(), which were
contributed in the same patch that introduced lambda) "minor conveniences".
He still thinks of them that way at heart, although in public he's more
likely to call them "minor annoyances" now, because people who want *more*
from them than minor convenience are heading down a road Guido doesn't want
to see Python travel.  Functional programming styles aren't natural in
Python, and Guido doesn't intend to do anything to make them more natural.
So use these things when they're *obviously* useful, but never strain to
make code fit.

Natural:

    print len(x)

Strained:

    print reduce(lambda n, elt: n+1, x, 0)

Both print the length of a sequence x, but the second way is just silly in
Python.

Natural:

    print map(ord, "abc")

    print filter(lambda x: x & 1, list_of_ints) # extract the odd ints
    print [x for x in list_of_ints if x & 1]    # also natural

BTW, I don't believe I've ever seen a good use for reduce() in Python!  The
equivalent loop is almost always clearer, faster and easier to modify.



From rod.krause@dubbocs.com.au  Mon May 28 03:32:25 2001
From: rod.krause@dubbocs.com.au (Rod Krause (School))
Date: Mon, 28 May 2001 12:32:25 +1000
Subject: [Tutor] Unique values in an array.
Message-ID: <NFBBKCKCOKKAOEOCEBMJOEHNCAAA.rod.krause@dubbocs.com.au>

I am trying to generate 20 unique questions for testing numeracy skills in
high school students. Assuming that I want to generate a simple question for
adding two integers eg x+y what I am doing is radnomly generating x and y
and testing to see whether this combination has already been used.  Normally
I have placed the generated x into an one array and y into another.  When
the next x is generated I test to see if it is already in the array.  If it
is it is rejected and a new integer is generated.

I am trying to find out how to read numbers into an array using Python and
then testing a new integer to see if it has been used.  The aim is to
generate 20 unique questions when the program is run.

I am not sure of array usage in Python - or maybe an alternative.  Can
anybody give me a little direction.


Thanks

Rod



From lgwb@home.com  Mon May 28 03:53:30 2001
From: lgwb@home.com (Michael Schmitt)
Date: Sun, 27 May 2001 21:53:30 -0500
Subject: [Tutor] how to decypther which module function was imported from when from module import * is used
Message-ID: <002301c0e721$60dbabc0$0a0a0a0a@mntp1.il.home.com>

I am trying to read code that has several line off "from module import *"
and I want to know how as I trying to read though the code how I decipher
which module a function has been imported from when the fully-qualified name
is not used.


Michael Schmitt




From tescoil@irtc.net  Mon May 28 04:38:17 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Sun, 27 May 2001 22:38:17 -0500
Subject: [Tutor] mp3 range violation reportage.
Message-ID: <3B11C829.B392F9A4@irtc.net>

First, a sorry-as-brief-as-I-can-manage-but-hopefully
not-so-brief-absolutely-no-one-comprehends briefing on 
mpg123 command line options, beginning with an example:

$ mpg123 -t -c Raw_Power.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3.
Version 0.59r (1999/Jun/15). Written and copyrights by Michael Hipp.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
Title  : Raw Power                       Artist: The Stooges            
Album  : Raw Power                       Year  : 1973
Comment:                                 Genre : Punk Rock

Playing MPEG stream from Raw_Power.mp3 ...
MPEG 1.0 layer III, 128 kbit/s, 44100 Hz stereo
2 samples clipped
2 samples clipped
2 samples clipped
1 samples clipped

[4:21] Decoding of Raw_Power.mp3 finished

-t is test mode, doesn't play any sound, and faster.
-c checks for range violations, the "samples clipped" stuff.

One could also do mpg123 -t -c -@ playlist.m3u and check 
a whole bunch of files at once.

Now to the Python part of the question.  It would seem an
easy enough proposition to write a program that would go
through the results and, given the above example, return:

Raw_Power.mp3: 7 samples clipped.

First obstacle is, mpg123 -t -c Raw_Power.mp3 > a_file
doesn't redirect this or any data to a_file.

Another approach to capturing the results?



From DOUGS@oceanic.com  Mon May 28 05:02:41 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Sun, 27 May 2001 18:02:41 -1000
Subject: [Tutor] mp3 range violation reportage.
Message-ID: <8457258D741DD411BD3D0050DA62365907A83B@huina.oceanic.com>

[Tesla Coil...]
> First obstacle is, mpg123 -t -c Raw_Power.mp3 > a_file
> doesn't redirect this or any data to a_file.
> 
> Another approach to capturing the results?

Completely speculation, but it may be that the text output from the program
is to standard error not standard output.  If you tried to use popen2.popen3
you might get something.

-Doug-


From DOUGS@oceanic.com  Mon May 28 05:25:16 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Sun, 27 May 2001 18:25:16 -1000
Subject: [Tutor] how to decypther which module function was imported f
 rom when from module import * is used
Message-ID: <8457258D741DD411BD3D0050DA62365907A83C@huina.oceanic.com>

[Michael Schmitt ]
> I am trying to read code that has several line off "from 
> module import *"
> and I want to know how as I trying to read though the code 
> how I decipher
> which module a function has been imported from when the 
> fully-qualified name
> is not used.

There're kind of two answers to this.  Which one applies depends on the
code, so you pick since I haven't seen the code (hint).

Several well known and respected framework types of packages expect the use
of the 'from module import *' command.  This is well documented with those
packages.  It would be very unusual to have two of these imported in that
way in the same program.  I suppose that it is also expected you would
recognize the functions because they are usually named very descriptively
and are distinct from your program.

It is generally considered bad coding style, by the elite of the guru corp
at least, to use this form in anything else but interactive sessions.
You've run across it and been stung by one of its bad points, the namespace
confusion.  You're apparently lucky not to have another side effect, name
conflicts.

Your asking the question implies you can change the programs.  Assuming the
second point is at issue, my suggestion is to change the import statements
one at a time to see what breaks.  Change to a regular 'import module' form
and run the program.  Use each traceback to edit the file with the correct
module.function format.  It may be tedious but if this is something you
might be involved with for a while it will be worth it.

-Doug-


From tescoil@irtc.net  Mon May 28 07:04:19 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Mon, 28 May 2001 01:04:19 -0500
Subject: [Tutor] mp3 range violation reportage.
References: <8457258D741DD411BD3D0050DA62365907A83B@huina.oceanic.com>
Message-ID: <3B11EA63.E9A47E52@irtc.net>

On 27 May 2001, Doug Stanfield replied:
> Completely speculation, but it may be that the text output 
> from the program is to standard error not standard output.
> If you tried to use popen2.popen3 you might get something.

And correct completely speculation it is:

>>> import popen2
>>> this = popen2.popen3('mpg123 -t -c Raw_Power.mp3')
>>> that = this[2]
>>> andtheother = that.readlines()
>>> andtheother[8]
'Playing MPEG stream from Raw_Power.mp3 ...\012

Thanks.  Haven't done anything with popen2 before.



From dyoo@hkn.eecs.berkeley.edu  Mon May 28 08:14:58 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 28 May 2001 00:14:58 -0700 (PDT)
Subject: [Tutor] Creating a local copy of Python
In-Reply-To: <20010527085851.A21343@johnsons-web.com>
Message-ID: <Pine.LNX.4.21.0105271807580.902-100000@hkn.eecs.berkeley.edu>

On Sun, 27 May 2001, Tim Johnson wrote:

> What I have in mind is a alternate interpreter that would have only
> what I need, plus (perhaps) my own addition. I would welcome
> being pointed towards documentation or discussions of such.

What we can do is keep a copy of our own Python somewhere in our home
directory.  Let's say, for example, that we'd like to play around with
Python 2.1 before really installing it.  If we're in an empty home
directory so far:

###
dyoo@coffeetable:~$ ls
Desktop  Python-2.1.tgz
###

What we'd like to do is put all the binaries and libraries in
'~/python-local/'.  Our plan is to compile Python, specifying the
"--prefix" option to get it to use ~/python-local as the "root" for
installation.  Here's a log that shows each step:

###
dyoo@coffeetable:~$ tar xzvf Python-2.1.tgz

[lots and lots of files extract at this point]

dyoo@coffeetable:~$ cd Python-2.1
dyoo@coffeetable:~/Python-2.1$ ./configure \
                        --prefix=/home/dyoo/python-local

[lots of output come up about configuration details ...]

dyoo@coffeetable:~/Python-2.1$ make install

[lots of compiling stuff flies by the screen]

dyoo@coffeetable:~/Python-2.1$ cd ~/python-local
dyoo@coffeetable:~/python-local$ ls
bin  include  lib  man
dyoo@coffeetable:~/python-local$ bin/python
Python 2.1 (#2, May 28 2001, 00:10:24) 
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> print "Hello world!"
Hello world!
###

And that should be it!  Since the python-local/bin directory isn't in our
PATH yet, we'll need to specifically spell out "~python-local/bin/python"
until we're satisfied that everything looks good.

Warning:  It's important that the --prefix is an absolute path; I ran into
a weird error message when I specified "--prefix=~/python-local" instead.


Anyway, hope this helps!



From tmbrau00@centre.edu  Mon May 28 08:19:09 2001
From: tmbrau00@centre.edu (Timothy M. Brauch)
Date: Mon, 28 May 2001 03:19:09 -0400
Subject: [Tutor] ASCII Code
Message-ID: <3B11FBED.291A647B@centre.edu>

I'm just a little curious about something I find odd in Python.  Here
are two scripts that do pretty much the same thing...

---Script 1---
chars=[]
for num in range(0,256):
    chars.append(chr(num))
for item in chars:
    print item
---End Script---

---Script 2---
for num in range(0,256):
    print chr(num)
---End Script---

Both scripts have the same output.  But, if in the first script you look
at chars, you don't see the same characters that are printed.  Instead,
you see the normal 'keyboard' letters and then the (octal) code '\177',
'200', etc. for all the special characters.  Obviously Python can
display those other characters, it did when I printed them.

And, why does Python choose to display the special characters in octal?
This makes it slightly confusing to me.  For example, ord('\n'), the
carriage return, gives me 10, but if I print '\010', what I really mean
is print '\012'.  Again, these are things that I find odd, and things I
have to try and remember when I am coding.  Of course, I don't actually
use these commands very often in coding...

 - Tim


From dyoo@hkn.eecs.berkeley.edu  Mon May 28 08:28:08 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Mon, 28 May 2001 00:28:08 -0700 (PDT)
Subject: [Tutor] Unique values in an array.
In-Reply-To: <NFBBKCKCOKKAOEOCEBMJOEHNCAAA.rod.krause@dubbocs.com.au>
Message-ID: <Pine.LNX.4.21.0105280017430.6607-100000@hkn.eecs.berkeley.edu>

On Mon, 28 May 2001, Rod Krause (School) wrote:

> I am trying to generate 20 unique questions for testing numeracy
> skills in high school students. Assuming that I want to generate a
> simple question for adding two integers eg x+y what I am doing is
> radnomly generating x and y and testing to see whether this
> combination has already been used.  Normally I have placed the

Ok, sounds good so far.


> generated x into an one array and y into another.  When the next x is
> generated I test to see if it is already in the array.  If it is it is
> rejected and a new integer is generated.

Which array should be checked for duplicates then when we generate a new
X?  The array that contains the other X values, or both the X and Y
arrays?  The question needs a little clarification in this area.


> I am trying to find out how to read numbers into an array using Python
> and then testing a new integer to see if it has been used.  The aim is
> to generate 20 unique questions when the program is run.

I'm seeing the following pseudocode:

###
def makeRandomNumbers():
    numbers = []
    while we haven't filled 'numbers' with 20 elements yet:
        new_choice = some random number
        if the new_choice isn't in our numbers list:
            add the new_choice into the list
    return the numbers back
###

The reason it might be nice to have it as a function is because you'll be
able to use the same procedure to source the X and Y numbers.


> I am not sure of array usage in Python - or maybe an alternative.  Can
> anybody give me a little direction.

Using Python lists for this should work well.  Here are a few examples
that use lists:

###
>>> mylist = []     
>>> mylist.append(42)
>>> mylist.append(7)
>>> mylist.append(13)
>>> mylist.append(3)
>>> mylist
[42, 7, 13, 3]
>>> 123 in mylist
0
>>> 13 in mylist
1
>>> 42 not in mylist
0
###

Good luck to you.



From wheelege@tsn.cc  Mon May 28 08:27:52 2001
From: wheelege@tsn.cc (wheelege)
Date: Mon, 28 May 2001 17:27:52 +1000
Subject: [Tutor] a ScoreList class (was: Multiple identical keys in a dictionary)
References: <Pine.LNX.4.33.0105261155300.4124-100000@bms>
Message-ID: <006501c0e747$b5163680$0200a8c0@ACE>

> <...>
> > <snip>
> Whether or not a class makes sense for a score list depends on what
> you want to do with the scores, and should have nothing to do with how
> many other classes you may have already devised for the program.
>

  Heh - I should explain in more detail. I already have a detailed class to
handle all operations with the scores - so basically, yes I have a 'scores'
class.  I was saying that I didn't want to make another class on top of that
just to store the values of the scores, since in my mind a 'HighScores'
(actual name of class in this example) class should contain the scores as an
attribute.
  However...*reads on*


> If all you are doing is keeping a list of scores which you want to
> display every now and then, a simple list of tuples is probably best.
> A dictionary looks attractive in general, but depends on having a
> unique key for each entry to really shine... if you don't have a
> unique key available you may end up losing any advantage dicts give
> you through needing to handle collisions yourself, and manually
> looking through the values of the dict to find whatever data you need.
> i.e., It may be easier to generalize extracting data from a flat list
> of tuples, where all datum are equal, than the case where one piece of
> data is artifically elevated in importance and everything else must be
> done in terms of a relationship to it.
>

  What I ended up deciding on was a dictionary where the keys were scores
and the values are a list of lists (which have name, level, difficulty in
them).  The time spent displaying or grabbing values is actually quite fast,
since I'm using a dictionary, and because I can have more than one entry for
each score, it is easy to handle multiple similar scores.

> An example is aways best...
> (works with 1.5.2, lots of tweaks can be done to improve it,
> especially if you are using a 2.x interpreter)
>
> ---8<--- scores.py ---
> class Score:
>     """Defines the basic properties of a 'score'."""
>     def __init__(self, player=None, value=None, level=None):
>         self.player = player
>         self.value = value
>         self.level = level
>         # there may be other things to keep track of, like...
>         #... is "level" the game play level or the players skill level
>         #... when they finished.  Putting stuff into a class lets you
>         #... add properties later on without needing to rewrite old
>         #... code (new code uses the new stuff, old code doesn't even
>         #... know it exists).
>

  :)  The way I wrote my class it is in fact very easy to add further
attributes...all you do is pass an additional argument to it's 'update'
method and everything will work fine...although I do agree having an object
to hold each value would be much 'cleaner' and although no more
possibilities (what can a class have as an attribute that a list can't have
as an item?) it is nicer to think about.

>     def __cmp__(self, other):
>         """Allows for comparison with other Score-s and numerics."""
>         if isinstance(other, Score):
>             cmpval = other.value
>         else:
>             cmpval = other
>         if self.value < cmpval:
>             return -1
>         elif self.value == cmpval:
>             return 0
>         else:
>             return 1
>

  Now that's something I didn't think about...although I didn't have to
because I ended up using a dictionary :)
  Very cool.

>     # these are setup to have an ok display in this specific
>     #... situation, you would probably want something a little
>     #... fancier/better for an actual application.
>     def __str__(self):
>         return "%s %s (%s)" % \
>                (self.player, self.value, self.level)
>
>     def __repr__(self):
>         return "Score(%s, %s, %s)" % \
>                (self.player, self.value, self.level)
>

  It's a tk game so this is actually considerably more complicated :)

>
> class ScoreList:
>     """A high-level interface to a list of scores.
>
>     You get:
>     - "cutoff", so only the most deserving make it into the list
>     - "+" operator, for an implementation independent interface
>     - "top" method to easily extract the top scores
>     - "name" and "level" methods, for extracting specific info
>
>     """
>     def __init__(self, scores=None, cutoff=None):
>         if scores == None:
>             self.values = []
>         else:
>             self.values = scores
>         self.cutoff = cutoff
>
>     def __add__(self, score):
>         # I think this bit is most significant; it defines the
>         #... semantics of adding to the list and is where you would
>         #... do any 'magic' needed to ensure the list has the
>         #... properties you want.  So far the only 'magic' is the
>         #... disappearing score if it is below the cutoff.
>         if self.cutoff == None or score > self.cutoff:
>             self.values.append(score)
>         return ScoreList(self.values, self.cutoff)

  Right now this is implemented by the size of the actual high scores file -
top limit 1k, lowest scores being cut off when the limit is reached.  The
user can ask for how many they wish to see inside the 'Hall of Fame' dialog
(generated by the HighScores.display() method, coincidentally) so a cutoff
as such isn't such an important thing.
  Unless storing a (potentially) 1k long dictionary is a problem for a
computer...

>
>     def __str__(self):
>         import string
>         self.values.sort()
>         return string.join(map(str, self.values), '\n')
>
>
>     def top(self, number):
>         self.values.sort()
>         return ScoreList(self.values[-number:], self.cutoff)
>
>     # These two methods are identical in form, and that form should
>     #... be generalized so one can use any attribute as a key and get
>     #... all the associated information back, IMO.

  Exactly what my HighScores.parse() method does :)

>     def name(self, name):
>         result = []
>         for item in self.values:
>             if item.player == name:
>                 result.append((item.value, item.level))
>         return result
>
>     def level(self, level):
>         result = []
>         for item in self.values:
>             if item.level == level:
>                 result.append((item.player, item.value))
>         return result
>
>
> if __name__ == '__main__':
>     # set things up
>     from random import randint
>     ri = randint
>
>     # you need a score of 2500 to get into the hiscore list
>     hiscores = ScoreList(cutoff=2500)
>
>     # generate random test data...
>     for i in range(3):
>         for j in range(1,7):
>             ascore = Score('player'+str(j), ri(0,5000), ri(1,10))
>             hiscores = hiscores + ascore
>     # ...with some specific properties...
>     for i in range(3):
>         for j in range(1,4):
>             part = ri(0,5000), ri(1,10)
>             hiscores = hiscores \
>                        + Score('player'+str(j), part[0], part[1]) \
>                        + Score('player'+str(j+3), part[0], part[1])
>     # ...although you probably want something a little more thorough.
>
>     # after going through all the above, use had better be simple...
>     print "\nAll scores:\n", hiscores
>     print "\nTop 3:\n", hiscores.top(3)
>     print "\nTop 10:\n", hiscores.top(10)
>     print "\nBy player..."
>     for i in range(1,6):
>         name = 'player' + str(i)
>         print name + ": ", hiscores.name(name)
>     print "\nBy level..."
>     for i in range(1,11):
>         print "level" + str(i) + ": ", hiscores.level(i)
>
> --->8---
>
> Overkill???, sure... unless, for example:  you have written the next
> wildly popular networked game and have a thousand dedicated users
> asking you for a way to analyse hiscore lists, or pestering you
> because they don't like the hardcoded default you think looks great;
> perhaps you just don't want to re-write or integrate(-yet-again) a
> score list subsystem everytime you code up a game, having all the core
> bits in a class or two make for easy code re-use; or maybe you want to
> allow for others to expand on what you have done, so they can have
> their own fancy hiscore display, without having to re-write your code
> and risk introducing incompatibilities.
>

  ...agreed, and although I had considered that (not the 'wildly-popular'
part :) I have a deadline of this friday and alot of things have to be fixed
in it before that time, perhaps if I continue work on it after the deadline
I'll implement the scores as a seperate class.

> Generally, I think you will find that as programs get larger, and the
> user base increases, it becomes more and more attractive to use
> classes.

  Preach the good word :)

>  Simply because it is easier to modify the behaviour of a
> class than to track down and change a convention you scattered
> throughout your code, or keep track of a bunch of stand-alone
> functions and data structure declarations when you need to change or
> replicate some behaviour.
>
> Food for thought, I hope.
>

  You bet.  For what it's worth I do consider your class idea an
intrinsically 'better' approach to the problem, as it does offer advantages
over the existing system but...hmmm.
  Perhaps if something mind-boggling evil comes of the ye olde 'dictionary'
approach and a rewrite is neccessary I will go for the class implementation.
In which case I will be happy for this discussion :)

  Thanks,
  Glen.

>
> - Bruce
>



From bsass@freenet.edmonton.ab.ca  Mon May 28 11:29:28 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Mon, 28 May 2001 04:29:28 -0600 (MDT)
Subject: [Tutor] a ScoreList class (was: Multiple identical keys in a
 dictionary)
In-Reply-To: <006501c0e747$b5163680$0200a8c0@ACE>
Message-ID: <Pine.LNX.4.33.0105280244180.438-100000@bms>

On Mon, 28 May 2001, wheelege wrote:

<...>
>   Heh - I should explain in more detail. I already have a detailed class to

:)

<...>
>   What I ended up deciding on was a dictionary where the keys were scores
> and the values are a list of lists (which have name, level, difficulty in
> them).  The time spent displaying or grabbing values is actually quite fast,
> since I'm using a dictionary, and because I can have more than one entry for
> each score, it is easy to handle multiple similar scores.

Ya, I was thinking along those lines (list, dict, class, whatever)
with ScoreList.__add__

<...>
> >         self.level = level
> >         # there may be other things to keep track of, like...
<...>
>   :)  The way I wrote my class it is in fact very easy to add further
> attributes...all you do is pass an additional argument to it's 'update'
> method and everything will work fine...although I do agree having an object
> to hold each value would be much 'cleaner' and although no more
> possibilities (what can a class have as an attribute that a list can't have
> as an item?) it is nicer to think about.

There are almost too many ways to add properties to an instances
(seems to be a regular theme on c.l.p. :)

> >     def __cmp__(self, other):
> >         """Allows for comparison with other Score-s and numerics."""
<...>
>   Now that's something I didn't think about...although I didn't have to
> because I ended up using a dictionary :)
>   Very cool.

At one point I figured it would be nice to have a sort() come out in
descending order, like you expect from a displayed list of scores.
Of course, "if score1 < score2:", came out backwards.  :) [cont...]

<...>
> >     def __add__(self, score):
> >         # I think this bit is most significant; it defines the
> >         #... semantics of adding to the list and is where you would
> >         #... do any 'magic' needed to ensure the list has the
> >         #... properties you want.  So far the only 'magic' is the
> >         #... disappearing score if it is below the cutoff.
> >         if self.cutoff == None or score > self.cutoff:
> >             self.values.append(score)
> >         return ScoreList(self.values, self.cutoff)
>
>   Right now this is implemented by the size of the actual high scores file -
> top limit 1k, lowest scores being cut off when the limit is reached.  The
> user can ask for how many they wish to see inside the 'Hall of Fame' dialog
> (generated by the HighScores.display() method, coincidentally) so a cutoff
> as such isn't such an important thing.
>   Unless storing a (potentially) 1k long dictionary is a problem for a
> computer...

Ya, I was thinking big (all the scores in the list, except for the
wimps who didn't even try), and considering that a limit on the number
of entries may be needed (or maybe users named bob21 couldn't post
scores when the moon was full, whatever [played nethack?]).

<...>
[...cont]
> >     def top(self, number):
> >         self.values.sort()
> >         return ScoreList(self.values[-number:], self.cutoff)

While thinking about getting "print aScoreList" to spit out in
descending order, I discovered that this...

def top(self, number):
    self.values.sort()
    self.values.reverse()
    return ScoreList(self.values[:number], self.cutoff)

...doesn't do the same as reversing the sense of Score.__cmp__ :/
In fact, reverse() doesn't appear to do anything.

Since it was almost as late then as it is now, I didn't investigate
any further... maybe tomorrow....

Any ideas?


<...>
>   Perhaps if something mind-boggling evil comes of the ye olde 'dictionary'
> approach and a rewrite is neccessary I will go for the class implementation.
> In which case I will be happy for this discussion :)

I was thinking a dict may be better than a list (for the Score
objects) if a ScoreList had a lot of Scores... not sure what the best
key would be, probably depend on the game and players (is it just a
list of scores, or will players want to analyse it for weaknesses in
their opponents, kinda thing).


- Bruce



From fdsf@gfdasf.com  Mon May 28 12:29:05 2001
From: fdsf@gfdasf.com (china)
Date: Mon, 28 May 2001 07:29:05 -0400
Subject: [Tutor] The best chinese manufacturer
Message-ID: <E154LCr-0003n5-00@mail.python.org>

Dear sir, welcome to:http://www.longf.com,
the best chinese manufacturer with biggest production scale, full range of products, most advanced technological facilities, perfect means of measurement and strongest capacity for development and research within the same domestic profession.
Web site:http://www.longf.com. 


From wheelege@tsn.cc  Mon May 28 13:01:36 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Mon, 28 May 2001 22:01:36 +1000
Subject: [Tutor] ASCII Code
References: <3B11FBED.291A647B@centre.edu>
Message-ID: <002401c0e76d$f2b566c0$0200a8c0@ACE>

  Seems no reply yet...I'll throw in my two cents although be certain I am
far from being confident in python :)

> I'm just a little curious about something I find odd in Python.  Here
> are two scripts that do pretty much the same thing...
>
 > <snip>
>
> Both scripts have the same output.  But, if in the first script you look
> at chars, you don't see the same characters that are printed.  Instead,
> you see the normal 'keyboard' letters and then the (octal) code '\177',
> '200', etc. for all the special characters.  Obviously Python can
> display those other characters, it did when I printed them.
>

  You must be in a pre-2.1 python - the octal representation was thrown out
for hex in 2.1, it was never meant to be octal.  I myself have 2.0 so I
can't test this, but I seem to recall it in the list of changes in the
readme for 2.1.

> And, why does Python choose to display the special characters in octal?

  Well, it chooses hex because hex is really easy for computers (and humans)
to convert to binary - which as well all know is what computers think in.
Octal is easy to use as a midpoint type stage...so I guess that is why it
has been sneaking in for so long.  But maybe not - someone correct me?

> This makes it slightly confusing to me.  For example, ord('\n'), the
> carriage return, gives me 10, but if I print '\010', what I really mean
> is print '\012'.

  Right, don't think you will ever use escape codes in decimal...it just
isn't going to happen :)

>  Again, these are things that I find odd, and things I
> have to try and remember when I am coding.  Of course, I don't actually
> use these commands very often in coding...
>

  No prob,
  Glen.

>  - Tim
>



From wheelege@tsn.cc  Mon May 28 13:27:27 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Mon, 28 May 2001 22:27:27 +1000
Subject: [Tutor] a ScoreList class (was: Multiple identical keys in a dictionary)
References: <Pine.LNX.4.33.0105280244180.438-100000@bms>
Message-ID: <006401c0e771$8f441ba0$0200a8c0@ACE>

> <snip!>
>
> > >     def __cmp__(self, other):
> > >         """Allows for comparison with other Score-s and numerics."""
> <...>
> >   Now that's something I didn't think about...although I didn't have to
> > because I ended up using a dictionary :)
> >   Very cool.
>
> At one point I figured it would be nice to have a sort() come out in
> descending order, like you expect from a displayed list of scores.
> Of course, "if score1 < score2:", came out backwards.  :) [cont...]
>

so it does...

> <snip>
> Ya, I was thinking big (all the scores in the list, except for the
> wimps who didn't even try), and considering that a limit on the number
> of entries may be needed (or maybe users named bob21 couldn't post
> scores when the moon was full, whatever [played nethack?]).
>

  Ha ha, yeah I've played nethack - although I like (Z)Angband just that tad
bit more :)  Right now I've actually included the wimps that didn't even get
a single point in a special 'Hall of Shame' listing :)

> <...>
> [...cont]
> > >     def top(self, number):
> > >         self.values.sort()
> > >         return ScoreList(self.values[-number:], self.cutoff)
>
> While thinking about getting "print aScoreList" to spit out in
> descending order, I discovered that this...
>
> def top(self, number):
>     self.values.sort()
>     self.values.reverse()
>     return ScoreList(self.values[:number], self.cutoff)
>
> ...doesn't do the same as reversing the sense of Score.__cmp__ :/
> In fact, reverse() doesn't appear to do anything.
>

  Are you sure..?  self.values...that is a list isn't it?  *checks code*
Well, it is a list.  I added the reverse() line and also a 'print 'values
are', self.values' line and it does in fact reverse the list.  Perhaps
something to do with the 'return ...' statement?
  Well, this does the right thing...

###
    def top(self, number):
        self.values.sort()
        self.values.reverse()
        return ScoreList(self.values[-number:], self.cutoff)
###

  Aha!  Seems somewhere along the line the little negative sign
dissappeared...*has a fiddle*  Well, from what I can tell, your __cmp__
function actually does sort them in the right (descending) order - so when
you reverse your list your actually making it back ascending, then printing
it.  If you have the negative sign there then is will work, but I think we
will both agree that...

###
    def top(self, number):
        self.values.sort()
        return ScoreList(self.values[number:], self.cutoff)
###

  Is better :)

> Since it was almost as late then as it is now, I didn't investigate
> any further... maybe tomorrow....
>
> Any ideas?
>

  Yup, detailed above :)

>
> <...>
> >   Perhaps if something mind-boggling evil comes of the ye olde
'dictionary'
> > approach and a rewrite is neccessary I will go for the class
implementation.
> > In which case I will be happy for this discussion :)
>
> I was thinking a dict may be better than a list (for the Score
> objects) if a ScoreList had a lot of Scores... not sure what the best
> key would be, probably depend on the game and players (is it just a
> list of scores, or will players want to analyse it for weaknesses in
> their opponents, kinda thing).
>

  Heh, not sure how they could analyze anything for weaknesses - since it is
an Arkanoid variant (hey, I was just told to make a small fun distracting
(but not too much so) game...in the vein of old arcade style, I wasn't told
why - even stranger that this is for company wide use too :).  Basically,
all I am thinking of including is player name, score, difficulty and level.
It will probably be netwoked...hmmm how cool would it be to have a single
high score table for everybody...aaa hmmm....must implement...hmmm must
think of code to implement...perhaps a token style file access...aaa
thinking out loud.  I've rambled for way too long :)

  Thanks,
  Glen.

>
> - Bruce
>
>



From scarblac@pino.selwerd.nl  Mon May 28 13:43:39 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 28 May 2001 14:43:39 +0200
Subject: [Tutor] a ScoreList class (was: Multiple identical keys in a dictionary)
In-Reply-To: <006401c0e771$8f441ba0$0200a8c0@ACE>; from wheelege@tsn.cc on Mon, May 28, 2001 at 10:27:27PM +1000
References: <Pine.LNX.4.33.0105280244180.438-100000@bms> <006401c0e771$8f441ba0$0200a8c0@ACE>
Message-ID: <20010528144339.A1184@pino.selwerd.nl>

On  0, Glen Wheeler <wheelege@tsn.cc> wrote:
> > <snip>
> > Ya, I was thinking big (all the scores in the list, except for the
> > wimps who didn't even try), and considering that a limit on the number
> > of entries may be needed (or maybe users named bob21 couldn't post
> > scores when the moon was full, whatever [played nethack?]).
> >
> 
>   Ha ha, yeah I've played nethack - although I like (Z)Angband just that tad
> bit more :)  Right now I've actually included the wimps that didn't even get
> a single point in a special 'Hall of Shame' listing :)

Ahem. Major danger of addiction detected.

You're not saying you're coding a roguelike in Python, are you?

(I'm ex-ZAngband DevTeam member, finished Nethack 8 times, but never a *band)

>   Heh, not sure how they could analyze anything for weaknesses - since it is
> an Arkanoid variant 

Phew.

> (hey, I was just told to make a small fun distracting
> (but not too much so) game...in the vein of old arcade style, I wasn't told
> why - even stranger that this is for company wide use too :).

I envy you.


I'll go look for some unanswered questions now :)

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Mon May 28 13:52:32 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 28 May 2001 14:52:32 +0200
Subject: [Tutor] how to decypther which module function was imported from when from module import * is used
In-Reply-To: <002301c0e721$60dbabc0$0a0a0a0a@mntp1.il.home.com>; from lgwb@home.com on Sun, May 27, 2001 at 09:53:30PM -0500
References: <002301c0e721$60dbabc0$0a0a0a0a@mntp1.il.home.com>
Message-ID: <20010528145232.B1184@pino.selwerd.nl>

On  0, Michael Schmitt <lgwb@home.com> wrote:
> I am trying to read code that has several line off "from module import *"
> and I want to know how as I trying to read though the code how I decipher
> which module a function has been imported from when the fully-qualified name
> is not used.

In general, you can't. That's the problem with 'from module import *', and
one of the reasons why it's usually a bad idea.

There are some exceptions, like GUI toolkits - wxPython is usually used with
'from wxPython.wx import *' - but *its* objects have names like wxApp,
wxFrame, wxDialog - you can tell.

I suppose you can make a small function to use in the interpreter, like

def find_object(modulenames, name):
   modules = [__builtins__]+map(__import__, modulenames)
   modules.reverse()
   
   for mod in modules:
      if hasattr(mod, name):
         return mod.__name__
   return "Not found"

Now you can keep track of the imported modules and see where something would
come from. If the program does from...import * on sys, os and string, you
could do

>>> mods=["sys","os","string"]
>>> find_object(mods, "open")
'os'

And you see that the builtin open() would be overwritten by os.open().

(not tested)

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Mon May 28 14:02:52 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 28 May 2001 15:02:52 +0200
Subject: [Tutor] Unique values in an array.
In-Reply-To: <NFBBKCKCOKKAOEOCEBMJOEHNCAAA.rod.krause@dubbocs.com.au>; from rod.krause@dubbocs.com.au on Mon, May 28, 2001 at 12:32:25PM +1000
References: <NFBBKCKCOKKAOEOCEBMJOEHNCAAA.rod.krause@dubbocs.com.au>
Message-ID: <20010528150252.C1184@pino.selwerd.nl>

On  0, "Rod Krause (School)" <rod.krause@dubbocs.com.au> wrote:
> I am trying to generate 20 unique questions for testing numeracy skills in
> high school students. Assuming that I want to generate a simple question for
> adding two integers eg x+y what I am doing is radnomly generating x and y
> and testing to see whether this combination has already been used.  Normally
> I have placed the generated x into an one array and y into another.  When
> the next x is generated I test to see if it is already in the array.  If it
> is it is rejected and a new integer is generated.

But that means that no x can be used twice - you said you wanted to check
for unused *combinations* - it could ask for both 14+7 and 14+21, right?

> I am trying to find out how to read numbers into an array using Python and
> then testing a new integer to see if it has been used.  The aim is to
> generate 20 unique questions when the program is run.
> 
> I am not sure of array usage in Python - or maybe an alternative.  Can
> anybody give me a little direction.

A dictionary is better, I think. You can add keys like (3,4) to the
dictionary (we just use a dummy value, it's the keys that matter). So that
if we have the sums 3+4, 5+7 and 13+4, the dictionary would look like

{ (3,4): None,
  (5,7): None,
  (13,4): None
  }
  
Now if we randomly find (3,4) again and add it, the dictionary doesn't
change since it's already in there. We can just add random combinations
until the dictionary is of the desired size.

This makes a dictionary with 20 different combinations, with numbers between
1 and 50, and then prints them as sums:

from random import randrange

dict = {}
while len(dict) < 20:
    x = randrange(0,50)+1
    y = randrange(0,50)+1
    dict((x,y)) = None

for combination in dict.keys():       # We can loop over the dictionary keys
    x, y = combination
    print x, "+", y, "="

You could also have done it with lists in which you store the tuples. Then
you have to manually check if the tuple is in the list already, though:

l = []
while len(l) < 20:
   x = randrange(0,50)+1
   y = randrange(0,50)+1
   if (x,y) not in l:
      l.append((x,y))

for combination in l:
   x, y = combination
   print x, "+", y, "="
   
For large lists, the dictionary will be alot faster, but for 20 combinations
it's a matter of taste.

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Mon May 28 14:10:39 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 28 May 2001 15:10:39 +0200
Subject: [Tutor] ASCII Code
In-Reply-To: <3B11FBED.291A647B@centre.edu>; from tmbrau00@centre.edu on Mon, May 28, 2001 at 03:19:09AM -0400
References: <3B11FBED.291A647B@centre.edu>
Message-ID: <20010528151039.D1184@pino.selwerd.nl>

On  0, "Timothy M. Brauch" <tmbrau00@centre.edu> wrote:
> I'm just a little curious about something I find odd in Python.  Here
> are two scripts that do pretty much the same thing...
> 
> ---Script 1---
> chars=[]
> for num in range(0,256):
>     chars.append(chr(num))
> for item in chars:
>     print item
> ---End Script---
> 
> ---Script 2---
> for num in range(0,256):
>     print chr(num)
> ---End Script---
> 
> Both scripts have the same output.  But, if in the first script you look
> at chars, you don't see the same characters that are printed.  Instead,
> you see the normal 'keyboard' letters and then the (octal) code '\177',
> '200', etc. for all the special characters.  Obviously Python can
> display those other characters, it did when I printed them.

It can display them, but when you look at them in the interpreter, Python
runs repr() on the string first. Repr() has to translate the special
characters into the escape codes, since they're not ASCII (ASCII only goes
up to 127). Hmm. I don't know why it can't show chr(127), what is that again?

And yes, print simply dumps the string to the screen, and then it is shown
as *some* special character. 255 looks like an y with an umlaut to me, but
then I think my terminal uses Latin-1. Other people may use very different
codecs, depending on the country they're in. It's not Python that interprets
it, it's your terminal.

This is madness, it's always been madness, but slowly Unicode is becoming
more and more normal, it should get better in a few years...

> And, why does Python choose to display the special characters in octal?
> This makes it slightly confusing to me.  For example, ord('\n'), the
> carriage return, gives me 10, but if I print '\010', what I really mean
> is print '\012'.  Again, these are things that I find odd, and things I
> have to try and remember when I am coding.  Of course, I don't actually
> use these commands very often in coding...

Yep, it's strange. And from 2.1 onwards, it's in hexadecimal. This is
something to learn to live with.

-- 
Remco Gerlich


From walterv@jps.net  Mon May 28 14:52:06 2001
From: walterv@jps.net (Walter Vannini)
Date: Mon, 28 May 2001 06:52:06 -0700
Subject: [Tutor] ASCII Code
References: <3B11FBED.291A647B@centre.edu>
Message-ID: <3B125806.2C6CAA31@jps.net>

Hi Timothy,

It looks like you're asking "why does printing a list
differ from printing each element of a list?".

For example, define the following function and three lists.
 
def PrintList(list):
    print "[",
    for i in list:
        print i,
    print "]"
aList = [ 1, 2]
bList = [ 1/10.0, 1/5.0 ]
cList = [ chr(1), chr(2)]

I then get the following in Python 2.0
>>> print aList
[1, 2]
>>> PrintList(aList)
[ 1 2 ]
which is reasonably consistent print behaviour.

However
>>> print bList
[0.10000000000000001, 0.20000000000000001]
>>> PrintList(bList)
[ 0.1 0.2 ]
which is very different printing behaviour.

And finally, your example, print cList and PrintList(cList)
>>> print cList
['\001', '\002']
>>> PrintList(cList)
---unprintable in ascii mail---
results in very different printing behaviour.

>From these experiments, my guess is that when print is used on an object,
the builtin function str is used. When print is used on a list,
it looks like the str builtin function calls the repr builtin function
repeatedly.

So for example, "print bList" uses the strings repr(1/10.0)
and repr(1/5.0), while "PrintList(bList)" uses the strings
str(1/10.0) and str(1/5.0).

>>> repr(1/10.0)
'0.10000000000000001'
>>> str(1/10.0)
'0.1'

This would imply that the seemingly inconsistent behaviour
you observed is due to the different behaviour of str and repr.
I hope someone with more knowledge of the python internals
can confirm the above guess.

Walter.

Timothy M. Brauch wrote:
> 
> I'm just a little curious about something I find odd in Python.  Here
> are two scripts that do pretty much the same thing...
> 
> ---Script 1---
> chars=[]
> for num in range(0,256):
>     chars.append(chr(num))
> for item in chars:
>     print item
> ---End Script---
> 
> ---Script 2---
> for num in range(0,256):
>     print chr(num)
> ---End Script---
> 
> Both scripts have the same output.  But, if in the first script you look
> at chars, you don't see the same characters that are printed.  Instead,
> you see the normal 'keyboard' letters and then the (octal) code '\177',
> '200', etc. for all the special characters.  Obviously Python can
> display those other characters, it did when I printed them.
> ...


From arcege@speakeasy.net  Mon May 28 19:35:01 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Mon, 28 May 2001 14:35:01 -0400 (EDT)
Subject: [Tutor] how to decypther which module function was imported from when from module import * is used
In-Reply-To: <20010528145232.B1184@pino.selwerd.nl> from "Remco Gerlich" at May 28, 2001 02:52:32 PM
Message-ID: <200105281835.f4SIZ1X01040@dsl092-074-184.bos1.dsl.speakeasy.net>

Remco Gerlich wrote
> 
> On  0, Michael Schmitt <lgwb@home.com> wrote:
> > I am trying to read code that has several line off "from module import *"
> > and I want to know how as I trying to read though the code how I decipher
> > which module a function has been imported from when the fully-qualified name
> > is not used.
> 
> In general, you can't. That's the problem with 'from module import *', and
> one of the reasons why it's usually a bad idea.
> 
> There are some exceptions, like GUI toolkits - wxPython is usually used with
> 'from wxPython.wx import *' - but *its* objects have names like wxApp,
> wxFrame, wxDialog - you can tell.
> 
> I suppose you can make a small function to use in the interpreter, like
> 
> def find_object(modulenames, name):
>    modules = [__builtins__]+map(__import__, modulenames)
>    modules.reverse()
>    
>    for mod in modules:
>       if hasattr(mod, name):
>          return mod.__name__
>    return "Not found"
> 
> Now you can keep track of the imported modules and see where something would
> come from. If the program does from...import * on sys, os and string, you
> could do

Actually, you can look in the sys.modules structure without having to
"remember" much.  The "sys" module is a built-in C module so you don't
have to worry about it adding space by being imported.

def find_object(obj, modnames=None):
  import sys
  # if we supply an ordered list of module names
  if modnames:
    modules = []
    for name in modnames:
      if sys.modules.has_key(name):
        modules.append( (name, sys.modules[name]) )
  # otherwise get an unordered list of all modules imported
  else:
    modules = sys.modules.items()
  objnames = []
  for (modname, module) in modules.items():
    for (objname, modobj) in vars(module):
      if obj is modobj:
        objnames.append( '%s.%s' % (modname, objname) )
  return objnames  # return the list of module.object names

As you can see, the disadvantage of this is that, unless you give all the
module names you wish to search, a) it will search all loaded modules,
and b) it will not search in the order the modules were imported (but
that could be handled by keeping track of the order though the "imp"
or "imputil" modules).  But the advantage is that is checks for object
identity, not just name binding.

Python 2.1 also has a new module called "inspect" with a function called
"getmodule" which tries to deduce which module an object is defined in.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From bsass@freenet.edmonton.ab.ca  Mon May 28 21:47:19 2001
From: bsass@freenet.edmonton.ab.ca (Bruce Sass)
Date: Mon, 28 May 2001 14:47:19 -0600 (MDT)
Subject: [Tutor] a ScoreList class (was: Multiple identical keys in a
 dictionary)
In-Reply-To: <006401c0e771$8f441ba0$0200a8c0@ACE>
Message-ID: <Pine.LNX.4.33.0105281347540.1083-100000@bms>

On Mon, 28 May 2001, Glen Wheeler wrote:
<...>
Thanks.

> > Since it was almost as late then as it is now, I didn't investigate
> > any further... maybe tomorrow....

...all I needed was some caffine and a fresher brain.
Of course reverse() works, what problem was is I wasn't seeing the
sort() in ScoreList-s __str__ ().  Duh!

So when I did...

	print hiscores.top(3)

..top() did a reverse(), followed by __str__() of the temp ScoreList
instance returned by top() doing a sort().  Duh!!, !

<sigh>

<...>
>   Heh, not sure how they could analyze anything for weaknesses - since it is
> an Arkanoid variant (hey, I was just told to make a small fun distracting
> (but not too much so) game...in the vein of old arcade style, I wasn't told
> why - even stranger that this is for company wide use too :).  Basically,

Gotta play also, I guess.

> all I am thinking of including is player name, score, difficulty and level.
> It will probably be netwoked...hmmm how cool would it be to have a single
> high score table for everybody...aaa hmmm....must implement...hmmm must

That is expected from a networked game, eh.  :)


Have fun,

	Bruce



From sanyol@omen.ru  Mon May 28 22:31:11 2001
From: sanyol@omen.ru (sanyol@omen.ru)
Date: Mon, 28 May 2001 14:31:11 -0700
Subject: [Tutor] îïõôâõëé, íõìøôéíåäéá-ðòïåëôïòù
Message-ID: <E154UbX-000NfZ-00@zeus.net-werks.com>

This is a MIME encoded message.

--b16bcb27d58756cb2ef4d1f9af4cb91b4
Content-Type: text/html ;	charset="windows-1251"
Content-Transfer-Encoding: base64

PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIj4NCg0KPGh0bWw+DQo8aGVhZD4NCgk8dGl0bGU+zc7T0sHTysgsIMzTy9zSyMzFxMjALc/Q
zsXK0s7Q2zwvdGl0bGU+DQo8L2hlYWQ+DQoNCjxib2R5Pg0KPGRpdiBhbGlnbj0iQ0VOVEVSIj48
Zm9udCBmYWNlPSIiIGNvbG9yPSJCbHVlIj48aDI+zc7T0sHTysgsIMzTy9zSyMzFxMjALc/QzsXK
0s7Q2zwvaDI+PC9mb250PjwvZGl2Pg0KoKCgoKCg0+Lg5uDl7PvlIOPu8e/u5OAhPGJyPg0KoKCg
oKCgz/Dl5Ovg4+Dl7CDh7uv8+O7pIOL74e7wIM3O09LB08rOwiDoIMzTy9zSyMzFxMjALc/QzsXK
0s7QzsIg8e4g8err4OTgIOIgzO7x6uLlLjxicj4NCqCgoKCgoNbl7fsg5+3g9+jy5ev87e4g8e3o
5uXt+y48YnI+DQqgoKCgoKDP7vHw5eTt6Org7CDv8OXk8/Hs7vLw5e3uIODj5e3y8eru5SDi7uft
4OPw4Obk5e3o5S48YnI+DQqgoKCgoKDP8OXk6+Dj4OXsIPLg6ublIO7h7vDz5O7i4O3o5SDk6/8g
8e7n5ODt6P8g4eXx7/Du4u7k7fv1IPHl8uXpIOgg8/Hr8+PoIO/uIOj1IO/w7uXq8ujw7uLg7ej+
IOgg7O7t8uDm8y48YnI+DQqgoKCgoKDS5esuL9Tg6vE6ICgwOTUpIDxmb250IHNpemU9IisxIj48
Yj43NjAtNzktNDI8L2I+PC9mb250Pjxicj4NCg0KIKCgoKCgoDxhIGhyZWY9Im1haWx0bzpzYW55
b21Ab21lbi5ydSI+c2FueW9tQG9tZW4ucnU8L2E+DQoNCg0KDQo8L2JvZHk+DQo8L2h0bWw+DQo=

--b16bcb27d58756cb2ef4d1f9af4cb91b4--





From dsh8290@rit.edu  Tue May 29 03:17:19 2001
From: dsh8290@rit.edu (D-Man)
Date: Mon, 28 May 2001 22:17:19 -0400
Subject: [Tutor] mp3 range violation reportage.
In-Reply-To: <3B11EA63.E9A47E52@irtc.net>; from tescoil@irtc.net on Mon, May 28, 2001 at 01:04:19AM -0500
References: <8457258D741DD411BD3D0050DA62365907A83B@huina.oceanic.com> <3B11EA63.E9A47E52@irtc.net>
Message-ID: <20010528221719.B5747@harmony.cs.rit.edu>

On Mon, May 28, 2001 at 01:04:19AM -0500, Tesla Coil wrote:
| On 27 May 2001, Doug Stanfield replied:
| > Completely speculation, but it may be that the text output 
| > from the program is to standard error not standard output.
| > If you tried to use popen2.popen3 you might get something.
| 
| And correct completely speculation it is:
| 
| >>> import popen2
| >>> this = popen2.popen3('mpg123 -t -c Raw_Power.mp3')
| >>> that = this[2]
| >>> andtheother = that.readlines()
| >>> andtheother[8]
| 'Playing MPEG stream from Raw_Power.mp3 ...\012
| 
| Thanks.  Haven't done anything with popen2 before.

BTW, for the bash equivalent use file descriptor '2'.  Ex:

# redirect stderr to stdout, redirect stdout to a file
mpg123 2>&1 > a_file

# redirect only stderr to a file, let stdout stay on the terminal
mpg123 2>a_file

-D



From syrinx@simplecom.net  Tue May 29 03:23:06 2001
From: syrinx@simplecom.net (Scott)
Date: Mon, 28 May 2001 21:23:06 -0500
Subject: [Tutor] tkinter v. wxpython
Message-ID: <ht16htkr3o0s5h812kfhpcftsvt97agt72@4ax.com>

Could someone compare and contrast?  Thank you.


From hoki0001@student-zw.fh-kl.de  Tue May 29 11:54:45 2001
From: hoki0001@student-zw.fh-kl.de (Holger Kipp)
Date: Tue, 29 May 2001 12:54:45 +0200
Subject: [Tutor] Heeeeeeeeeeeeeeelp .... Please help me urgent
Message-ID: <000001c0e82d$c6198ef0$0ba8a8c0@clinton>

Hi 2 everyone,
I've got some problems installing Python 2.1 on SuSE-Linux 7.0.
Perhaps, I'm too silly for installing ... here are my worksteps

a) after downloading http://www.python.org/ftp/python/2.1/Python-2.1.tgz
   in directory "/installationen" 
   => unpacking:  gunzip -c Python-2.1.tgz |tar xvf -

b) executing:  ./configure
    used compiler: gcc

c) when I wanted to start "make", i became following message:
    > make


>gcc -c -g -O2 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H
-o
Modules/python.o Modules/python.c
    >In file included from /usr/include/errno.h:36,
    >            from Include/Python.h:48,
    >            from Modules/python.c:3:
    >/usr/include/bits/errno.h:25: linux/errno.h: No such file or
directory
    >make: *** [Modules/python.o] Error 1

What was wrong? What does the Errormessage mean? Do I have a
misconfiguration on my system? How can I remove this Error?
Please help me ... it's very important for my diploma ...

-Holger-



From scarblac@pino.selwerd.nl  Tue May 29 12:17:25 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 29 May 2001 13:17:25 +0200
Subject: [Tutor] Heeeeeeeeeeeeeeelp .... Please help me urgent
In-Reply-To: <000001c0e82d$c6198ef0$0ba8a8c0@clinton>; from hoki0001@student-zw.fh-kl.de on Tue, May 29, 2001 at 12:54:45PM +0200
References: <000001c0e82d$c6198ef0$0ba8a8c0@clinton>
Message-ID: <20010529131724.A3475@pino.selwerd.nl>

On  0, Holger Kipp <hoki0001@student-zw.fh-kl.de> wrote:
> Hi 2 everyone,
> I've got some problems installing Python 2.1 on SuSE-Linux 7.0.
> Perhaps, I'm too silly for installing ... here are my worksteps
> 
> a) after downloading http://www.python.org/ftp/python/2.1/Python-2.1.tgz
>    in directory "/installationen" 
>    => unpacking:  gunzip -c Python-2.1.tgz |tar xvf -
> 
> b) executing:  ./configure
>     used compiler: gcc
> 
> c) when I wanted to start "make", i became following message:
>     > make
> 
> 
> >gcc -c -g -O2 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H
> -o
> Modules/python.o Modules/python.c
>     >In file included from /usr/include/errno.h:36,
>     >            from Include/Python.h:48,
>     >            from Modules/python.c:3:
>     >/usr/include/bits/errno.h:25: linux/errno.h: No such file or
> directory
>     >make: *** [Modules/python.o] Error 1
> 
> What was wrong? What does the Errormessage mean? Do I have a
> misconfiguration on my system? How can I remove this Error?
> Please help me ... it's very important for my diploma ...

You need to have the Linux kernel source installed (some Python modules need
to work with the kernel, ie networking, and for that they need definitions
from the kernel source).

There should be a Suse rpm, probably kalled linux-src, linux-devel or
kernel-devel or something like that.

-- 
Remco Gerlich


From rpm@wag.caltech.edu  Tue May 29 13:33:56 2001
From: rpm@wag.caltech.edu (Richard P. Muller)
Date: Tue, 29 May 2001 05:33:56 -0700
Subject: [Tutor] tkinter v. wxpython
References: <ht16htkr3o0s5h812kfhpcftsvt97agt72@4ax.com>
Message-ID: <3B139734.9C36F713@wag.caltech.edu>

Scott wrote:
> 
> Could someone compare and contrast?  Thank you.
> 

Here goes:

Tkinter uses the Tk toolkit for GUI construction. wxpython uses GTK on
Linux platforms, and the standard windows toolkit on Windows. As such,
both are cross platform development tools. Tkinter also runs on
Macintosh; last time I checked wxpython was being ported there, but I'm
not sure whether the port has been completed.

The advantage of Tkinter is that it's included with Python. Thus, any
code you write that uses Tkinter will probably run on everyone's python
installation. The Python Mega-Widgets (PMW) are built using Tkinter, and
give the interface some much-needed additional widgets. But overall the
widgets are fairly outdated.

wxpython has some more modern widgets, but I've found the interface a
little non-intuitive. Plus, we've had trouble getting the OpenGL to work
with wxpython in cross-platform applications, but that might just be our
bad luck. 

The other alternative is to simply use the GTK widgets themselves. The
GTK widgets are very up-to-date. You can even use Glade (a graphical
design tool) to design your GUI. We haven't tried using PyGTK on
windows, but it should be possible, as the GTK widgets are ported there.

I used Tkinter to write the Python Checkbook Manager, since I wanted to
allow it to run on as many machines as possible. But for code that only
needs to run on Linux, we are now using PyGTK almost exclusively.

Rick


From dsh8290@rit.edu  Tue May 29 15:42:08 2001
From: dsh8290@rit.edu (D-Man)
Date: Tue, 29 May 2001 10:42:08 -0400
Subject: [Tutor] Heeeeeeeeeeeeeeelp .... Please help me urgent
In-Reply-To: <20010529131724.A3475@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Tue, May 29, 2001 at 01:17:25PM +0200
References: <000001c0e82d$c6198ef0$0ba8a8c0@clinton> <"from hoki0001"@student-zw.fh-kl.de> <20010529131724.A3475@pino.selwerd.nl>
Message-ID: <20010529104208.B7806@harmony.cs.rit.edu>

On Tue, May 29, 2001 at 01:17:25PM +0200, Remco Gerlich wrote:
| On  0, Holger Kipp <hoki0001@student-zw.fh-kl.de> wrote:
...
| There should be a Suse rpm, probably kalled linux-src, linux-devel or
| kernel-devel or something like that.

Don't they have an rpm for python itself too?  I know that there are
Debian packages and RedHat rpms available.

-D



From rob@jam.rr.com  Tue May 29 15:52:03 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Tue, 29 May 2001 09:52:03 -0500
Subject: [Tutor] Heeeeeeeeeeeeeeelp .... Please help me urgent
References: <000001c0e82d$c6198ef0$0ba8a8c0@clinton> <"from hoki0001"@student-zw.fh-kl.de> <20010529131724.A3475@pino.selwerd.nl> <20010529104208.B7806@harmony.cs.rit.edu>
Message-ID: <3B13B793.734E1423@jam.rr.com>

D-Man wrote:
> 

<snip />

> Don't they have an rpm for python itself too?  I know that there are
> Debian packages and RedHat rpms available.
> 
> -D

I've never been able to get anywhere with the Python rpms because of
massive dependency problems I couldn't solve. But I can confirm the
existence of the rpms.

Rob
-- 
If Bubba can program, I can too!
---> Useless Python <---
http://www.lowerstandard.com/python/index.html


From kromag@nsacom.net  Tue May 29 23:23:44 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Tue, 29 May 2001 15:23:44 -0700 (PDT)
Subject: [Tutor] Difficulties reading from database.
Message-ID: <200105292223.f4TMNiL24065@pop.nsacom.net>

I have been having some difficulty reading from an access database using 
win32com.client. I can write and execute SQL commands just fine, but actually 
getting readable output has eluded me thus far.

When I try the following in IDLE:


>>> import win32com.client
>>> engine=win32com.client.Dispatch("DAO.DBEngine.35")
>>> db=engine.OpenDatabase("\windows\desktop\db1.mdb")
>>> rs=db.OpenRecordset("select * from food")
>>> rs
<COMObject OpenRecordset>

results. I get the same results from the interpreter started on the command 
line.

I got my howto info from http://starship.python.net/crew/bwilk/access.html. 

I have had similar difficulties using idle under linux accessing postgres 
with pygresql, but when I ran the interpreter from the command line the 
results were as I expected. Clues?

d


From arcege@speakeasy.net  Tue May 29 21:40:05 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Tue, 29 May 2001 16:40:05 -0400 (EDT)
Subject: [Tutor] Difficulties reading from database.
In-Reply-To: <200105292223.f4TMNiL24065@pop.nsacom.net> from "kromag@nsacom.net" at May 29, 2001 03:23:44 PM
Message-ID: <200105292040.f4TKe5f02211@dsl092-074-184.bos1.dsl.speakeasy.net>

kromag@nsacom.net wrote
> 
> I have been having some difficulty reading from an access database using 
> win32com.client. I can write and execute SQL commands just fine, but actually 
> getting readable output has eluded me thus far.
> 
> When I try the following in IDLE:
> 
> 
> >>> import win32com.client
> >>> engine=win32com.client.Dispatch("DAO.DBEngine.35")
> >>> db=engine.OpenDatabase("\windows\desktop\db1.mdb")
> >>> rs=db.OpenRecordset("select * from food")
> >>> rs
> <COMObject OpenRecordset>
> 
> results. I get the same results from the interpreter started on the command 
> line.
> 
> I got my howto info from http://starship.python.net/crew/bwilk/access.html. 
> 
> I have had similar difficulties using idle under linux accessing postgres 
> with pygresql, but when I ran the interpreter from the command line the 
> results were as I expected. Clues?

I'm not a M$ user, but according to Hammond's (very good for WinXX) book
"Python Programming on Win32", this is what you are supposed to get,
an OpenRecordset object.

>>> rs = DB.OpenRecordset('SELECT ClientID, InvoiceData, \
  Consultant, Hours FROM Invoices')
>>> rs.MoveLast()
>>> rs.RecordCount
>>> for i in range(rs.Count):
...   field = rs.Fields[i]
...   print '%s = %s' % (rs.Name, rs.Value)
...
>>>

I'm assuming this would be explained in the "win32com" documentation
(under "Data Access Object" or DAO?).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From arthur.watts@gbst.com  Tue May 29 23:35:03 2001
From: arthur.watts@gbst.com (Arthur Watts)
Date: Wed, 30 May 2001 08:35:03 +1000
Subject: [Tutor] Installing Python 2.1 on SuSE-Linux 7.0.
Message-ID: <1CDB101F0CB6D311882F0000F80639240389D6DF@aquarius.bne.star.com.au>

Guys,

	As per the other replies to Holger's problem installing 2.1 on SuSe
7.0, I can only pass on my experiences with 2.1 on this version of SuSE :

	1. 7.0 does come with a Python RPM (1.5.2, I think) which you can
select from YaST
	2. As mentioned, installing a later RPM can lead to dependancy
issues, but I believe that there are RPM setting which allow you to ignore
these (!)
	3. I simply elected to install 2.1 in /usr/local/python-2.1, instead
of the default location. This means ensuring that my PATH and PYTHONPATH are
set correctly, but that's not too great a price to pay ..

	Looking at the error message which Holger received, a couple of
things stand out :

	1. configure does seem to have correctly identified that it needs to
build Python for a Linux system (ok, Sherlock..). That's a good start.
	2. It is not able to find linux/errno.h in its default C include
path. This is usually the current directory, followed by /usr/include,
/usr/include/sys etc. You need to cd into /usr and run the find command to
determine if errno.h is installed on your system. This header file may
appear in a number of locations under Linux - one of the guys has RedHat and
it lives under /usr/include/linux on his system. This is where it lives on
our Compaq AlphaServer (I'm at work, SuSE is at home..) :

/gbst_optsrc/python/Python-2.1=> find /usr/include -name errno.h -print
/usr/include/errno.h 
	
	Since configure has told your Makefile to only look in the current
directory and the Include directory of the Python source (' -I. -I./Include
'), I believe that it expects to find errno.h in the default include path.
Obviously, your system expects to find errno.h in
/usr/include/linux/errno.h, or similar. If you are unable to find this C
header file, fire up YaST and look for something in the 'Development'
section (from memory). I may be mixing up RedHat and SuSE, but I think you
are given the option at install time of installing certain C libraries and
header files. Exactly which selection you need to make escapes me, but if
you intend building software on a regular basis, I'd install them all !
Installing all that kernel source may be a bit overboard, but I'm way too
lazy to go looking for files when I need them :} I would have thought that
errno.h was part of the base install, but I may be mistaken. 

	If the above still does not work, I would consider reinstalling
SuSE. I have nothing but admiration for V7.0 of this distro, and have built
Apache, PHP etc without any problems. As with any source, ensure that you
read the accompanying README, INSTALL or whatever the distributor has
provided. I ususally grep on '[Ll]inux' in the base directory to see if
there is anything in any of the files I need to investigate.

Good Luck,

Arthur


From tescoil@irtc.net  Wed May 30 00:33:28 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Tue, 29 May 2001 18:33:28 -0500
Subject: [Tutor] mp3 range violation reportage.
References: <3B11C829.B392F9A4@irtc.net>
Message-ID: <3B1431C8.89E2D0EC@irtc.net>

What I crufted up--looks to work with both 1.5.2 & 2.0.
Turning this over to the Useless repository.

A "does user have mpg123 available" test might be nice
--not certain how to go about that.  If a file to be
tested is incorrectly named or doesn't exist, it simply
doesn't print any results on that one--could stand to
return something more descriptive there, just haven't
worked that out yet.  And whatever else critique finds...

#!/usr/bin/env python
""" clippage.py -- uses mpg123 to produce a report of
    total samples clipped from an single mp3 or those
    listed in an .m3u playlist.

    usage: 
    $ clippage.py track.mp3
    $ clippage.py playlist.m3u """

__author__ = 'Tesla Coil <tescoil@irtc.net>'
__date__ = 'May 2001'
__version__ = '$Revision: 0.1 $'

from string import atoi
from sys import argv
from popen2 import popen3
from operator import add

def modusoperandi(extension):
    # Playlist or single mp3?
    command = 'mpg123 -t -c '
    if extension[-3:] == 'm3u':
        command = command+'-@ '+extension
    elif extension[-3:] == 'mp3':
        command = command+extension
    else: print ' Input filename requires .mp3 or .m3u extension'
    return command

def runtest(command):
    # The excruciatingly slow part.
    allofit = popen3(command)
    someofit = allofit[2]
    rawreport = someofit.readlines()
    for obj in allofit:
    	obj.close()
    return rawreport

def slicedown(rawreport):
    # Edit mpg123's output somewhat.
    divbegin=[]
    divend=[]
    for x in range(len(rawreport)):
        if rawreport[x][0:7]=='Playing':
            divbegin.append(x)
        if rawreport[x][-10:-2]=='finished':
     	    divend.append(x)
    firstedit = []
    for x in range(len(divbegin)):
        firstedit.append(rawreport[divbegin[x]:divend[x]])
    return firstedit

def gettracks(firstedit):   
    # Get list of the mp3s tested.
    tracklist = []
    for x in range(len(firstedit)):
        tracklist.append(firstedit[x][0][25:-1])
    return tracklist

def clipsums(firstedit):
    # Locate and total test results.
    trackclips = [0]
    allclips = []
    for x in range(len(firstedit)):
        for y in range(len(firstedit[x])):
            if firstedit[x][y][-16:-1]=='samples clipped':
	        trackclips.append(atoi(firstedit[x][y][:-17]))	    
        allclips.append(trackclips)
        trackclips = [0]
    for x in range(len(allclips)):	   
        allclips[x]=reduce(add, allclips[x])
    return allclips

def reportout(tracklist, allclips):
    # Generate the final report.
    for x in range(len(tracklist)):
        print tracklist[x], allclips[x], 'samples clipped.'

if __name__ == '__main__':
    commandline = modusoperandi(argv[1])
    mpgout = runtest(commandline)
    relevantdata = slicedown(mpgout)
    tracks = gettracks(relevantdata)
    clips = clipsums(relevantdata)
    reportout(tracks, clips)



From arcege@speakeasy.net  Wed May 30 01:10:11 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Tue, 29 May 2001 20:10:11 -0400 (EDT)
Subject: [Tutor] mp3 range violation reportage.
In-Reply-To: <3B1431C8.89E2D0EC@irtc.net> from "Tesla Coil" at May 29, 2001 06:33:28 PM
Message-ID: <200105300010.f4U0ABX02705@dsl092-074-184.bos1.dsl.speakeasy.net>

Tesla Coil wrote
> 
> A "does user have mpg123 available" test might be nice

Actually, there is a module out there to help; it isn't really a
majorly important one.
<URL: http://starship.python.net/~arcege/python/Os_path.py>

>>> import Os_path
>>> mypath = Os_Path.Binpath()
>>> mypath['mpg123']
'/usr/bin/mpg123'
>>>

It also works on Windoze and Mac.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From tescoil@irtc.net  Wed May 30 01:58:12 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Tue, 29 May 2001 19:58:12 -0500
Subject: [Tutor] mp3 range violation reportage.
References: <200105300010.f4U0ABX02705@dsl092-074-184.bos1.dsl.speakeasy.net>
Message-ID: <3B1445A4.7AE1A243@irtc.net>

On 29 May 2001, Michael P. Reilly replied:
>> A "does user have mpg123 available" test might be nice
>
> Actually, there is a module out there to help; it isn't
> really a majorly important one.
> <URL: http://starship.python.net/~arcege/python/Os_path.py>

Not Found.  That would be:
<http://starship.python.net/~arcege/modules/Os_path.py>

Nice, but kinda compounds the problem in that one
is testing for a program not certain to be available
by using a module not certain to be available.  :{

I was looking at: 
>>> import os.path
>>> if not os.path.isfile('/usr/bin/mpg123'):
...     print 'clippage.py requires mpg123 on path.'
...
>>>

But don't know the system doesn't have mpg123 
in /usr/local/bin or elsewhere on path.

There's *gotta* be an easy answer to this one.



From wheelege@tsn.cc  Wed May 30 02:30:31 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 30 May 2001 11:30:31 +1000
Subject: [Tutor] Code now broken with upgrade to 2.1...
Message-ID: <001101c0e8a8$1e2eb0a0$0200a8c0@ACE>

This is a multi-part message in MIME format.

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

  Hi all,

  I upgraded to 2.1, and now it seems this code acts quite differently.

###
from Tkinter import *

def pjim(jim):
    print jim

root =3D Tk()
tlw =3D Toplevel(root)
jim =3D 1
f =3D Frame(tlw, height=3D100, width=3D150)
Radiobutton(f, text=3D'Path', value=3D50, variable=3Djim).pack()
Radiobutton(f, text=3D'Alright', value=3D9, variable=3Djim).pack()
Radiobutton(f, text=3D'Fun', value=3D5, variable=3Djim).pack()
Radiobutton(f, text=3D'Stupid', value=3D1, variable=3Djim).pack()
f.pack(padx=3D5, pady=3D5)
b =3D Button(tlw, text=3D'print jim', command=3Dlambda x=3Djim:pjim(x))
b.pack()
mainloop()
###

  Of course, it was alot more complicated originally - so I compressed =
it down until I have come to this.  For the life of me, I cannot get a =
little white 'radiobutton' to appear - only the text for each =
radiobutton.
  If I change the fg and/or bg (foreground, background) of a single =
radiobutton then it changes when I click on it...however, using the =
printjim button it tells me that jim in fact does not change upon =
clicking just the text.
  Any ideas or help?

  Thanks,
  Glen.=20

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Hi all,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; I upgraded to 2.1, and now it seems this code acts quite=20
differently.</DIV>
<DIV>&nbsp;</DIV>
<DIV>###</DIV>
<DIV>from Tkinter import *</DIV>
<DIV>&nbsp;</DIV>
<DIV>def pjim(jim):<BR>&nbsp;&nbsp;&nbsp; print jim</DIV>
<DIV>&nbsp;</DIV>
<DIV>root =3D Tk()<BR>tlw =3D Toplevel(root)<BR>jim =3D 1<BR>f =3D =
Frame(tlw,=20
height=3D100, width=3D150)<BR>Radiobutton(f, text=3D'Path', value=3D50,=20
variable=3Djim).pack()<BR>Radiobutton(f, text=3D'Alright', value=3D9,=20
variable=3Djim).pack()<BR>Radiobutton(f, text=3D'Fun', value=3D5,=20
variable=3Djim).pack()<BR>Radiobutton(f, text=3D'Stupid', value=3D1,=20
variable=3Djim).pack()<BR>f.pack(padx=3D5, pady=3D5)<BR>b =3D =
Button(tlw, text=3D'print=20
jim', command=3Dlambda x=3Djim:pjim(x))<BR>b.pack()<BR>mainloop()</DIV>
<DIV>###</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Of course, it was alot more complicated originally - so I =
compressed=20
it down until I have come to this.&nbsp; For the life of me, I cannot =
get a=20
little white 'radiobutton' to appear - only the text for each =
radiobutton.</DIV>
<DIV>&nbsp; If I change the fg&nbsp;and/or bg (foreground, background) =
of a=20
single radiobutton then it changes when I click on =
it...however,&nbsp;using the=20
printjim button&nbsp;it tells me that jim&nbsp;in fact does not change =
upon=20
clicking&nbsp;just the text.</DIV>
<DIV>&nbsp; Any ideas or help?</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_000E_01C0E8FB.EF654280--



From wheelege@tsn.cc  Wed May 30 02:36:53 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 30 May 2001 11:36:53 +1000
Subject: [Tutor] *sigh*
Message-ID: <002401c0e8a9$01d00160$0200a8c0@ACE>

This is a multi-part message in MIME format.

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

  Urgh, me and my overtired brain.  I forgot to make Jim an IntVar... so =
yeah clicking on the text does in fact set the variable to the correct =
value...but it still doesn't look right.

###
from Tkinter import *

def pjim(jim):
    print jim.get()

root =3D Tk()
tlw =3D Toplevel(root)
jim =3D IntVar()
jim.set(1)
f =3D Frame(tlw, height=3D100, width=3D150)
Radiobutton(f, text=3D'Path', value=3D50, variable=3Djim).pack()
Radiobutton(f, text=3D'Alright', value=3D9, variable=3Djim).pack()
Radiobutton(f, text=3D'Fun', value=3D5, variable=3Djim).pack()
Radiobutton(f, text=3D'Stupid', value=3D1, variable=3Djim).pack()
f.pack(padx=3D5, pady=3D5)
b =3D Button(tlw, text=3D'print jim', command=3Dlambda x=3Djim:pjim(x))
b.pack()
mainloop()
###

  Help??

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Urgh, me and my overtired brain.&nbsp; I forgot to make Jim =
an=20
IntVar... so yeah clicking on the text does in fact set the variable to =
the=20
correct value...but it still doesn't look right.</DIV>
<DIV>&nbsp;</DIV>
<DIV>###</DIV>
<DIV>from Tkinter import *</DIV>
<DIV>&nbsp;</DIV>
<DIV>def pjim(jim):<BR>&nbsp;&nbsp;&nbsp; print jim.get()</DIV>
<DIV>&nbsp;</DIV>
<DIV>root =3D Tk()<BR>tlw =3D Toplevel(root)<BR>jim =3D =
IntVar()<BR>jim.set(1)<BR>f =3D=20
Frame(tlw, height=3D100, width=3D150)<BR>Radiobutton(f, text=3D'Path', =
value=3D50,=20
variable=3Djim).pack()<BR>Radiobutton(f, text=3D'Alright', value=3D9,=20
variable=3Djim).pack()<BR>Radiobutton(f, text=3D'Fun', value=3D5,=20
variable=3Djim).pack()<BR>Radiobutton(f, text=3D'Stupid', value=3D1,=20
variable=3Djim).pack()<BR>f.pack(padx=3D5, pady=3D5)<BR>b =3D =
Button(tlw, text=3D'print=20
jim', command=3Dlambda x=3Djim:pjim(x))<BR>b.pack()<BR>mainloop()</DIV>
<DIV>###</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Help??</DIV></BODY></HTML>

------=_NextPart_000_0021_01C0E8FC.D2F5CA60--



From dyoo@hkn.eecs.berkeley.edu  Wed May 30 03:00:54 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 29 May 2001 19:00:54 -0700 (PDT)
Subject: [Tutor] *sigh*
In-Reply-To: <002401c0e8a9$01d00160$0200a8c0@ACE>
Message-ID: <Pine.LNX.4.21.0105291858370.407-100000@hkn.eecs.berkeley.edu>

On Wed, 30 May 2001, Glen Wheeler wrote:

>   Urgh, me and my overtired brain.  I forgot to make Jim an IntVar...
> so yeah clicking on the text does in fact set the variable to the
> correct value...but it still doesn't look right.

It has to do with the Toplevel:  I made the following kludge:

    tlw = root

and now all the radiobuttons are showing up.  I'll see why it's doing
that, and post again.

Here's the program at the moment:


###
from Tkinter import *
 
def pjim(jim):
    print jim.get()
 
root = Tk()
tlw = root          # Toplevel(root)  <--- something weird is happening
jim = IntVar()
jim.set(1)
f = Frame(tlw, height=100, width=150)
Radiobutton(f, text='Path', value=50, variable=jim).pack()
Radiobutton(f, text='Alright', value=9, variable=jim).pack()
Radiobutton(f, text='Fun', value=5, variable=jim).pack()
Radiobutton(f, text='Stupid', value=1, variable=jim).pack()
f.pack(padx=5, pady=5)
b = Button(tlw, text='print jim', command=lambda x=jim:pjim(x))
b.pack()
mainloop()
###

Don't worry, we'll figure this out.




From brett@earthlight.co.nz  Wed May 30 02:28:38 2001
From: brett@earthlight.co.nz (Brett Shand)
Date: Wed, 30 May 2001 13:28:38 +1200
Subject: [Tutor] newbie question
Message-ID: <3B14F586.9284.5E8C639@localhost>

Hi

I'm back to programming after 20 years, and now starting to learn 
python, using pythonwin in w2k.

i'm reading 'learning python' - lutz and ascher, mar 99 and run into a 
problem.

i've made a module file 'spam.py' and saved it as 
c:\modules\spam.py - and then run it (see below) as suggested on 
page 13-14. i get the error below.  What am i doing wroing? 

-------------------------------------------------
>>> c:\modules> python spam.py -i eggs -o bacon
Traceback (  File "<interactive input>", line 1
c:\modules> python spam.py -i eggs -o bacon
SntaxError: invalid syntax
>>>
---------------------------------------------------

there is also a caret ^ appears below the colon in line 3 above.

any ideas please.

tia

brett




From dyoo@hkn.eecs.berkeley.edu  Wed May 30 03:08:58 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 29 May 2001 19:08:58 -0700 (PDT)
Subject: [Tutor] *sigh*
In-Reply-To: <Pine.LNX.4.21.0105291858370.407-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.21.0105291903210.407-100000@hkn.eecs.berkeley.edu>

On Tue, 29 May 2001, Daniel Yoo wrote:

> On Wed, 30 May 2001, Glen Wheeler wrote:
> 
> >   Urgh, me and my overtired brain.  I forgot to make Jim an IntVar...
> > so yeah clicking on the text does in fact set the variable to the
> > correct value...but it still doesn't look right.
> 
> It has to do with the Toplevel:  I made the following kludge:
> 
>     tlw = root

Err... never mind!  That was silly of me.  Of course you wanted tlw to be
another Toplevel window.  Sorry, I misinterpreted the question.

In that case, I'm a little baffled, because the radiobuttons and their
respective labels are showing up for me under 2.1.  I'm running on Linux,
if that helps anything.  I hate saying this, but your program appears to
be working fine.  Can anyone else confirm this?

Sorry about that!



From dyoo@hkn.eecs.berkeley.edu  Wed May 30 03:17:19 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Tue, 29 May 2001 19:17:19 -0700 (PDT)
Subject: [Tutor] newbie question
In-Reply-To: <3B14F586.9284.5E8C639@localhost>
Message-ID: <Pine.LNX.4.21.0105291910520.407-100000@hkn.eecs.berkeley.edu>

On Wed, 30 May 2001, Brett Shand wrote:

> I'm back to programming after 20 years, and now starting to learn 
> python, using pythonwin in w2k.
> 
> i'm reading 'learning python' - lutz and ascher, mar 99 and run into a 
> problem.
> 
> i've made a module file 'spam.py' and saved it as 
> c:\modules\spam.py - and then run it (see below) as suggested on 
> page 13-14. i get the error below.  What am i doing wroing? 
> 
> -------------------------------------------------
> >>> c:\modules> python spam.py -i eggs -o bacon
> Traceback (  File "<interactive input>", line 1
> c:\modules> python spam.py -i eggs -o bacon
> SntaxError: invalid syntax
> >>>
> ---------------------------------------------------

What they meant by

    c:\modules> python spam.py -i eggs -o bacon

is that when you're on the DOS command prompt, you'll see something that
looks like:

    c:\modules>

At this point, we should not in Python yet.  What we can do is call Python
on that spam.py program:

    c:\modules> python spam.py -i eggs -o bacon

and then it should run ok.


PythonWin should have a menu command to execute a script; this might be
easier to use than going to the Command Prompt.


> there is also a caret ^ appears below the colon in line 3 above.

The caret directs our attention to where exactly things looks weird to
Python.  In this case, the whole line looks weird to Python.  *grin*


Hope this helps!



From DOUGS@oceanic.com  Wed May 30 03:25:04 2001
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Tue, 29 May 2001 16:25:04 -1000
Subject: [Tutor] newbie question
Message-ID: <8457258D741DD411BD3D0050DA62365907A848@huina.oceanic.com>

[Brett Shand]
> I'm back to programming after 20 years, and now starting to learn 
> python, using pythonwin in w2k.

Wise choice in Python, but you'll find that out in good time...

> i'm reading 'learning python' - lutz and ascher, mar 99 and 
> run into a 
> problem.

Excellent choice of books...

> i've made a module file 'spam.py' and saved it as 
> c:\modules\spam.py - and then run it (see below) as suggested on 
> page 13-14. i get the error below.  What am i doing wroing? 
> 
> -------------------------------------------------
> >>> c:\modules> python spam.py -i eggs -o bacon
> Traceback (  File "<interactive input>", line 1
> c:\modules> python spam.py -i eggs -o bacon
> SntaxError: invalid syntax
> >>>
> ---------------------------------------------------
> 
> there is also a caret ^ appears below the colon in line 3 above.
> 
> any ideas please.

Well, to be more complete in describing what you did, you first opened the
interpreter window in Pythonwin, right.  The '>>>' is the giveaway.  The
line that you then typed in was actually meant to be entered at a Windows
command prompt.  When typed in the interpreter, Python doesn't interpret
them as Python language so its telling you that as soon as it hits a
character that doesn't fit its preconceived ideas. ;-)

HTH

-Doug-


From brett@earthlight.co.nz  Wed May 30 03:34:52 2001
From: brett@earthlight.co.nz (Brett Shand)
Date: Wed, 30 May 2001 14:34:52 +1200
Subject: [Tutor] newbie question
In-Reply-To: <Pine.LNX.4.21.0105291910520.407-100000@hkn.eecs.berkeley.edu>
References: <3B14F586.9284.5E8C639@localhost>
Message-ID: <3B15050C.22809.62567D7@localhost>

> What they meant by
> 
>     c:\modules> python spam.py -i eggs -o bacon
> 
> is that when you're on the DOS command prompt, you'll see something
> that looks like:

of course ... thank you.  there is a 'run script' option in pythonwin 
that makes everything work fine :)

brett


From wheelege@tsn.cc  Wed May 30 03:38:47 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 30 May 2001 12:38:47 +1000
Subject: [Tutor] *sigh*
References: <Pine.LNX.4.21.0105291903210.407-100000@hkn.eecs.berkeley.edu>
Message-ID: <006801c0e8b1$a7a15f00$0200a8c0@ACE>

>
> Err... never mind!  That was silly of me.  Of course you wanted tlw to be
> another Toplevel window.  Sorry, I misinterpreted the question.
>

  :)

> In that case, I'm a little baffled, because the radiobuttons and their
> respective labels are showing up for me under 2.1.  I'm running on Linux,
> if that helps anything.  I hate saying this, but your program appears to
> be working fine.  Can anyone else confirm this?
>

  Urgh, not a compaitability thing with win-bloody-hard-to-develop-in
again...I tell ya, I'm so over windows.  Damn it's popularity.
  Can anyone think of a workaround?  I'll get fiddling, and post if I find
something.  This did work fine in 2.0 remember :)

  Glen.




From curtishorn@home.com  Wed May 30 06:51:33 2001
From: curtishorn@home.com (Curtis Horn)
Date: Tue, 29 May 2001 22:51:33 -0700
Subject: [Tutor] database connectivity over networks
Message-ID: <4.3.2.7.0.20010529224932.00a98820@mail>

I was wondering how I would go about sending data to a database over a 
network using python.


		Curtis



From toodles@yifan.net  Wed May 30 08:38:53 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Wed, 30 May 2001 15:38:53 +0800
Subject: [Tutor] *sigh*
In-Reply-To: <006801c0e8b1$a7a15f00$0200a8c0@ACE>
Message-ID: <FPEHJJPEEOIPMAHOADBKGEMOCDAA.toodles@yifan.net>

> > I hate saying this, but your program appears to
> > be working fine.  Can anyone else confirm this?

Maybe.

> >
>
>   Urgh, not a compaitability thing with win-bloody-hard-to-develop-in
> again...I tell ya, I'm so over windows.  Damn it's popularity.
>   Can anyone think of a workaround?  I'll get fiddling, and post if I find
> something.  This did work fine in 2.0 remember :)

Hey not so fast! =)
I'm using Windows ME and Python 2.1, and it seems to be working...it opens
two windows, one blank and one with radio buttons (yes with buttons as well
as text). Is this what it's meant to be doing?

Andrew Wilkins




From wheelege@tsn.cc  Wed May 30 08:36:33 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 30 May 2001 17:36:33 +1000
Subject: [Tutor] *sigh*
References: <FPEHJJPEEOIPMAHOADBKGEMOCDAA.toodles@yifan.net>
Message-ID: <001001c0e8db$40cafaa0$0200a8c0@ACE>

> > > I hate saying this, but your program appears to
> > > be working fine.  Can anyone else confirm this?
>
> Maybe.
>

  I have several win98 boxes here...they all exhibit the behaviour of text
minus buttons.

> > >
> >
> >   Urgh, not a compaitability thing with win-bloody-hard-to-develop-in
> > again...I tell ya, I'm so over windows.  Damn it's popularity.
> >   Can anyone think of a workaround?  I'll get fiddling, and post if I
find
> > something.  This did work fine in 2.0 remember :)
>
> Hey not so fast! =)
> I'm using Windows ME and Python 2.1, and it seems to be working...it opens
> two windows, one blank and one with radio buttons (yes with buttons as
well
> as text). Is this what it's meant to be doing?
>

  Yes, that is what it's meant to be doing.  ME?  Urgh.  Well, better tell
the people with < ME to go and upgrade...
  Anyone with a 98 box they can test this on?  Just to ensure I am sane...

> Andrew Wilkins
>



From dyoo@hkn.eecs.berkeley.edu  Wed May 30 08:58:47 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 30 May 2001 00:58:47 -0700 (PDT)
Subject: [Tutor] database connectivity over networks
In-Reply-To: <4.3.2.7.0.20010529224932.00a98820@mail>
Message-ID: <Pine.LNX.4.21.0105300046310.4159-100000@hkn.eecs.berkeley.edu>

On Tue, 29 May 2001, Curtis Horn wrote:

> I was wondering how I would go about sending data to a database over a
> network using python.

What sort of database is it?  Is it MySQL, Postgres, or something else?  
I'll assume that you mean an SQL database. Python uses a standardized
database interface (DB API 2.0), so the motions to set things up are
similar between database systems.

    http://python.org/topics/database/DatabaseAPI-2.0.html

You'll need to start up a connection with the server, and this is usually
done with a connect() call.  In MySQL, for example, if we wanted to
connect to a database in Tokyo, for example, we could do something like
this:

###
import MySQLdb
db = MySQLdb.Connection(host="database.monster.jp",
                        user="godzilla",
                        passwd="rubberducky",
                        db="GameraDefensePlans")
###

>From then on, we can do database stuff through our 'db' instance.  So it
really shouldn't matter where the database is located after we initialize
our connection, be it overseas or in the middle of the Nevada desert.

Tell us a little more about what kind of database it is, and we can point
you toward relevant information.  You can also find more information here:

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


Good luck to you.



From wheelege@tsn.cc  Wed May 30 10:33:07 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Wed, 30 May 2001 19:33:07 +1000
Subject: [Tutor] Illegal Operation??
Message-ID: <002a01c0e8eb$89353ca0$0200a8c0@ACE>

This is a multi-part message in MIME format.

------=_NextPart_000_0027_01C0E93F.5A4A3CC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

  Hello again,

  Well, this one definitely has me stumped (yes, even more so than the =
phantom radiobutton).  After playing my game for a period of time, =
PYTHON will cause an illegal operation in module tcl83.dll and it shuts =
down.
  Needless to say this is very annoying.  It happens at the same memory =
address every single time, so I imagine it is something happening around =
there.  I'm running win98.
  My script is a little...large to be posting here.  Also, if it was an =
error with my code then wouldn't there be at least some kind of =
traceback?
  This has been happenning for a while...but only recently has it become =
a major issue in actually playing the game.
  Could this be to do with threads?  I always have at least two running, =
sometimes more (up to 10 for short periods of time).  It seems to handle =
the large number of threads fine, except right when they start.  For =
example, if your playing for about 3 mins, then hit kill a block and a =
thread starts, if it's going to lock up it does it right at the =
beginning.  It doesn't seem to be linked to the actual number of threads =
running, since it usually crashes about 20% of the way through a thread, =
even if only two or threee are running.
  Any clues?

  Thanks,
  Glen.

------=_NextPart_000_0027_01C0E93F.5A4A3CC0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Hello again,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Well, this one definitely has me stumped (yes, even more so =
than the=20
phantom radiobutton).&nbsp; After playing my game for a period of time, =
PYTHON=20
will cause an illegal operation in module tcl83.dll and it shuts =
down.</DIV>
<DIV>&nbsp; Needless to say this is very annoying.&nbsp; It happens at =
the same=20
memory address every single time, so I imagine it is something happening =
around=20
there.&nbsp; I'm running win98.</DIV>
<DIV>&nbsp; My script is a little...large to be posting here.&nbsp; =
Also, if it=20
was an error with my code then wouldn't there be at least some kind of=20
traceback?</DIV>
<DIV>&nbsp; This has been happenning for&nbsp;a while...but only =
recently has it=20
become a major issue in actually playing the game.</DIV>
<DIV>&nbsp; Could this be to do with threads?&nbsp; I always have at =
least two=20
running, sometimes more (up to 10 for short periods of time).&nbsp; It =
seems to=20
handle the large number of threads fine, except right when they =
start.&nbsp; For=20
example, if your playing for about 3 mins, then hit kill a block and a =
thread=20
starts, if it's going to lock up it does it right at the =
beginning.&nbsp; It=20
doesn't seem to be linked to the actual number of threads running, since =
it=20
usually crashes about 20% of the way through a thread, even if only two =
or=20
threee are running.</DIV>
<DIV>&nbsp; Any clues?</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_0027_01C0E93F.5A4A3CC0--



From FayyazA@3fifteen.co.za  Wed May 30 10:45:10 2001
From: FayyazA@3fifteen.co.za (Fayyaz Asmal)
Date: Wed, 30 May 2001 11:45:10 +0200
Subject: [Tutor] help
Message-ID: <2CBB2B49D955264DAF22D7E9B67D2FBD06E76B@durban3.logical.co.za>

This is a multi-part message in MIME format.

------_=_NextPart_001_01C0E8ED.37BE3780
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

i need help on python
=20
im learning the language for the 1st time
=20
i need help on making a connection to MY*SQL or SQL server
adding a record
deleteing a record
and updating a record
=20
eg : a user interface with 3 options
add
edit
delete
=20
when u click on add - it allows u to add a firstname and lastname
etc etc
=20
when u clik on edit - it allows u to edit a record
=20
when u click on delete - it allows u to delete a record
=20
PLZ HELP ME!!!!
or put me thru to sumone who can help
=20
=20
THANKS
Fayyaz

------_=_NextPart_001_01C0E8ED.37BE3780
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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


<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>i need =
help on=20
python</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>im =
learning=20
th</SPAN></FONT><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001>e&nbsp;language for the 1st =
time</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>i need =
help on=20
making a connection to MY*SQL or SQL server</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>adding =
a=20
record</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D809243609-30052001>deleteing a=20
record</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>and =
updating a=20
record</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>eg : a =
user=20
interface with 3 options</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001>add</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001>edit</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001>delete</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>when u =
click on add=20
- it allows u to add a firstname and lastname</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>etc=20
etc</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>when u =
clik on edit=20
- it allows u to edit a record</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>when u =
click on=20
delete&nbsp;- it allows u to delete a record</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>PLZ =
HELP=20
ME!!!!</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D809243609-30052001>or put =
me thru to=20
sumone who can help</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D809243609-30052001>THANKS<BR>Fayyaz</SPAN></FONT></DIV></FONT></D=
IV></BODY></HTML>

------_=_NextPart_001_01C0E8ED.37BE3780--


From Eugene.Leitl@lrz.uni-muenchen.de  Wed May 30 11:24:48 2001
From: Eugene.Leitl@lrz.uni-muenchen.de (Eugene Leitl)
Date: Wed, 30 May 2001 12:24:48 +0200 (MET DST)
Subject: [Tutor] single underscore convention?
Message-ID: <Pine.SOL.4.33.0105301222400.14954-100000@sun1.lrz-muenchen.de>

I'm hacking some random tree code, attempting to dump a tree as a HTML
table. The code snippet I'm using has:

if __name__ == "__main__":

	blah blah blah


	_def _test1():
        	print animals[0]    # print Mammals
        	animals.printtree()

	blah blah blah

	_test1()



Why the underscore, is this a convention?



From arcege@speakeasy.net  Wed May 30 12:01:01 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 30 May 2001 07:01:01 -0400 (EDT)
Subject: [Tutor] Code now broken with upgrade to 2.1...
In-Reply-To: <001101c0e8a8$1e2eb0a0$0200a8c0@ACE> from "Glen Wheeler" at May 30, 2001 11:30:31 AM
Message-ID: <200105301101.f4UB12K03369@dsl092-074-184.bos1.dsl.speakeasy.net>

Glen Wheeler wrote
> 
> This is a multi-part message in MIME format.
> 
> ------=_NextPart_000_000E_01C0E8FB.EF654280
> Content-Type: text/plain;
> 	charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
> 
>   Hi all,
> 
>   I upgraded to 2.1, and now it seems this code acts quite differently.
> 
> ###
> from Tkinter import *
> 
> def pjim(jim):
>     print jim
> 
> root =3D Tk()
> tlw =3D Toplevel(root)
> jim =3D 1
> f =3D Frame(tlw, height=3D100, width=3D150)
> Radiobutton(f, text=3D'Path', value=3D50, variable=3Djim).pack()
> Radiobutton(f, text=3D'Alright', value=3D9, variable=3Djim).pack()
> Radiobutton(f, text=3D'Fun', value=3D5, variable=3Djim).pack()
> Radiobutton(f, text=3D'Stupid', value=3D1, variable=3Djim).pack()
> f.pack(padx=3D5, pady=3D5)
> b =3D Button(tlw, text=3D'print jim', command=3Dlambda x=3Djim:pjim(x))
> b.pack()
> mainloop()
> ###
> 
>   Of course, it was alot more complicated originally - so I compressed =
> it down until I have come to this.  For the life of me, I cannot get a =
> little white 'radiobutton' to appear - only the text for each =
> radiobutton.
>   If I change the fg and/or bg (foreground, background) of a single =
> radiobutton then it changes when I click on it...however, using the =
> printjim button it tells me that jim in fact does not change upon =
> clicking just the text.
>   Any ideas or help?

For me, this is working the same for 1.5.2, 2.0 and 2.1.  I see all
the radio buttons, and all the values are always one.  It could be a
platform problem; you didn't say what platform you were testing this on
(mine right now is RedHat Linux 7.0).

The problem that I see is that you are giving a Python variable name to
the Radiobutton widget; Python variables are just references to objects,
not "slots" to store values in.  Therefore you cannot "pass-by-reference"
as you are attempting (here "pass-by-reference" means passing the
address of the variable, not the value in the variable).  Tkinter (on
some platform) might give unexpected results if not given the Tkinter
variable required.

Instead, change your code to:
def pjim(jim):
  print jim.get()
root = Tk()
jim = IntVar(); jim.set(1) # a Tkinter integer variable
...

At this point, the variable jim is pointing to a Tkinter variable that
a) will exist in the Tcl/Tk world for modification, and
b) can be modified independent of the variable name "jim".
(unlike an integer which is immutable).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From rob@jam.rr.com  Wed May 30 11:58:37 2001
From: rob@jam.rr.com (Rob Andrews)
Date: Wed, 30 May 2001 05:58:37 -0500
Subject: [Tutor] *sigh*
References: <FPEHJJPEEOIPMAHOADBKGEMOCDAA.toodles@yifan.net> <001001c0e8db$40cafaa0$0200a8c0@ACE>
Message-ID: <3B14D25D.DA66A4ED@jam.rr.com>

Glen Wheeler wrote:
> 
> > > > I hate saying this, but your program appears to
> > > > be working fine.  Can anyone else confirm this?
> >
> > Maybe.
> >
> 
>   I have several win98 boxes here...they all exhibit the behaviour of text
> minus buttons.
> 
> > > >
> > >
> > >   Urgh, not a compaitability thing with win-bloody-hard-to-develop-in
> > > again...I tell ya, I'm so over windows.  Damn it's popularity.
> > >   Can anyone think of a workaround?  I'll get fiddling, and post if I
> find
> > > something.  This did work fine in 2.0 remember :)
> >
> > Hey not so fast! =)
> > I'm using Windows ME and Python 2.1, and it seems to be working...it opens
> > two windows, one blank and one with radio buttons (yes with buttons as
> well
> > as text). Is this what it's meant to be doing?
> >
> 
>   Yes, that is what it's meant to be doing.  ME?  Urgh.  Well, better tell
> the people with < ME to go and upgrade...
>   Anyone with a 98 box they can test this on?  Just to ensure I am sane...
>
 
I tried it on Python 2.1 on a 98 SE box. Two windows appeared, one blank
and one with the words Path, Alright, Fun, and Stupid and a button
*pring jim*. *print jim* just caused a number (seemed random) to output.
Same thing under 2.0 on the same box.

Rob
-- 

Useless Python!
It's all pretty now.
http://www.lowerstandard.com/python/pythonsource.html


From dsh8290@rit.edu  Wed May 30 13:02:28 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 30 May 2001 08:02:28 -0400
Subject: [Tutor] mp3 range violation reportage.
In-Reply-To: <3B1445A4.7AE1A243@irtc.net>; from tescoil@irtc.net on Tue, May 29, 2001 at 07:58:12PM -0500
References: <200105300010.f4U0ABX02705@dsl092-074-184.bos1.dsl.speakeasy.net> <3B1445A4.7AE1A243@irtc.net>
Message-ID: <20010530080228.B18885@harmony.cs.rit.edu>

On Tue, May 29, 2001 at 07:58:12PM -0500, Tesla Coil wrote:
| On 29 May 2001, Michael P. Reilly replied:
| >> A "does user have mpg123 available" test might be nice
...
| But don't know the system doesn't have mpg123 
| in /usr/local/bin or elsewhere on path.
| 
| There's *gotta* be an easy answer to this one.

The easiest way is to just try it.


import os
retval = os.system( "nosuchprog" )
# the following constant was determined experimentally on a Linux 2.2 box
if retval == 32512 :
    print "The required program 'nosuchprog' wasn't found in the PATH."
    sys.exit( 1 )


Or, if you assume *nix :

pipe = os.popen( "which python" )
path = pipe.read()
pipe.close()
if not path :
    print "not in path"
    sys.exit( 1 )


-D



From dsh8290@rit.edu  Wed May 30 13:14:52 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 30 May 2001 08:14:52 -0400
Subject: [Tutor] Illegal Operation??
In-Reply-To: <002a01c0e8eb$89353ca0$0200a8c0@ACE>; from wheelege@tsn.cc on Wed, May 30, 2001 at 07:33:07PM +1000
References: <002a01c0e8eb$89353ca0$0200a8c0@ACE>
Message-ID: <20010530081452.C18885@harmony.cs.rit.edu>

On Wed, May 30, 2001 at 07:33:07PM +1000, Glen Wheeler wrote:
|   Hello again,
| 
|   Well, this one definitely has me stumped (yes, even more so than
|   the phantom radiobutton).  After playing my game for a period of
|   time, PYTHON will cause an illegal operation in module tcl83.dll
|   and it shuts down.

Ooh, fun with windows.  At least *nix systems give you a core dump to
inspect!  I have a friend who had a temporary job doing C++ work on
Windows a few months ago.  He said that sometimes he got "Invalid
operation in kernel.dll" messages.  Not surprising that the kernel
didn't work right, but needless to say it was his code that needed
fixing.  He never wants to do development on windows again.

|   Needless to say this is very annoying.  It happens at the same
|   memory address every single time, so I imagine it is something
|   happening around there.  I'm running win98.
|   My script is a little...large to be posting here.  Also, if it was
|   an error with my code then wouldn't there be at least some kind of
|   traceback?

Only if it is an error that Python is prepared to check for.  It is
conceivable that there is some condition not being checked by tcl,
then it executes some invalid C/C++ level instruction (it is a dll)
causing the crash.

I would recommend adding a bunch of print statements in strategic
locations in your script.  Since you are using threads be sure to
include the thread name in the output (Java has a  Thread.getName()
method).  Output such as "got to this function" is sufficient.  When
it crashes, see the last thing that was printed (oh, yeah, be sure to
flush stdout so that it actually makes it to the screen ;-)) and
follow the code from there adding more prints until the problem is
identified.

HTH,
-D



From Eugene.Leitl@lrz.uni-muenchen.de  Wed May 30 13:40:00 2001
From: Eugene.Leitl@lrz.uni-muenchen.de (Eugene Leitl)
Date: Wed, 30 May 2001 14:40:00 +0200 (MET DST)
Subject: [Tutor] stuck with html table
Message-ID: <Pine.SOL.4.33.0105301438560.19101-100000@sun1.lrz-muenchen.de>

What's wrong with following code?

def dumptable(table):
    result1 = ""
    resutl2 = ""
    htmlheader = "<html><head></head><body>"
    htmlfooter = "</body></html>"
    tablefoot = "</table>"

    def tablehead(columns):
        return "<table BORDER COLS=" + str(columns) + """ WIDTH="100%" NOSAVE>"""

    def tablerow(row):
        result1 = "<tr>"
        for j in row:
            result1 += "<td>"+str(j)+"</td>"
    return result1 + "</tr>"

    result2 = htmlheader + tablehead(5)
    for i in table:
        result2 += tablerow(i)
    return result2 + tablefoot + htmlfooter


# test table
tt = [[ "oans",  "zwoa",  3,  4,  5],
      [ 6,  "siebene",  8,  9, 10],
      ["eifi", 12, 13, 14, 15],
      [16, 17, 18, 19, 20]]

print dumptable(tt)

When run it just dumps </tr> instead of the real thing.



From Eugene.Leitl@lrz.uni-muenchen.de  Wed May 30 13:44:21 2001
From: Eugene.Leitl@lrz.uni-muenchen.de (Eugene Leitl)
Date: Wed, 30 May 2001 14:44:21 +0200 (MET DST)
Subject: [Tutor] disregard last fortune cookie
Message-ID: <Pine.SOL.4.33.0105301443090.19101-100000@sun1.lrz-muenchen.de>

Indentation got me. Misindented a return, that's wy.

This one works:

def dumptable(table):
    result1 = ""
    result2 = ""
    htmlheader = "<html><head></head><body>"
    htmlfooter = "</body></html>"
    tablefoot = "</table>"

    def tablehead(columns):
        return "<table BORDER COLS=" + str(columns) + """ WIDTH="100%" NOSAVE>"""

    def tablerow(row):
        result1 = "<tr>"
        for j in row:
            result1 += "<td>"+str(j)+"</td>"
        return result1 + "</tr>"

    result2 = htmlheader + tablehead(5)

    for i in table:
        result2 += tablerow(i)
    return result2 + tablefoot + htmlfooter


# test table
tt = [[ "oans",  "zwoa",  3,  4,  5],
      [ 6,  "siebene",  8,  9, 10],
      ["eifi", 12, 13, 14, 15],
      [16, 17, 18, 19, 20]]

print dumptable(tt)



From alan.gauld@bt.com  Wed May 30 13:46:38 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 30 May 2001 13:46:38 +0100
Subject: [Tutor] stuck with html table
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7E1@mbtlipnt02.btlabs.bt.co.uk>

> What's wrong with following code?
> 
> def dumptable(table):
>     result1 = ""
>     resutl2 = ""
>     htmlheader = "<html><head></head><body>"
>     htmlfooter = "</body></html>"
>     tablefoot = "</table>"
> 
>     def tablehead(columns):

Indented def? Implies you are on 2.1 since nested 
functions are iffy (IMHO) in earlier versions...

Since I can't really see a goiod reason to use 
them here why not just dedent the nrested functions?

>     return result1 + "</tr>"

Here's the line that returns the /tr
result is not being changed from the initial ""
up to this point. I think this line should be 
indented to be the return value of then nrested 
function???

I really don't like nested functions much, 
unless its for functions that return functions
and for those I'd prefer a real lambda 
- see a previous post! :-)

>     result2 = htmlheader + tablehead(5)
>     for i in table:
>         result2 += tablerow(i)
>     return result2 + tablefoot + htmlfooter

This is never executed because of the return 
above...

Alan G


From alan.gauld@bt.com  Wed May 30 13:51:22 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 30 May 2001 13:51:22 +0100
Subject: [Tutor] Kylix was  Illegal Operation??
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7E2@mbtlipnt02.btlabs.bt.co.uk>

> fun with windows.  At least *nix systems give you a core dump 

Way off topic here...

I just ordered Borland's Kylix for Linux (they cut 
the Delphi upgrade price from 550 UK pounds to 150!).

Just wondered if any other python tutor folks were 
using Kylix? Any thoughts? Does anyone know of any 
attempts to integrate Pytrhon and Kylix - since it 
works with Qt and GTk it must surely be viable?

Sorry to hijack a thread.

Alan G


From Eugene.Leitl@lrz.uni-muenchen.de  Wed May 30 14:05:48 2001
From: Eugene.Leitl@lrz.uni-muenchen.de (Eugene Leitl)
Date: Wed, 30 May 2001 15:05:48 +0200 (MET DST)
Subject: [Tutor] stuck with html table
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D7E1@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.SOL.4.33.0105301502040.19101-100000@sun1.lrz-muenchen.de>

On Wed, 30 May 2001 alan.gauld@bt.com wrote:

> Indented def? Implies you are on 2.1 since nested
> functions are iffy (IMHO) in earlier versions...

Yep, and thanks for reminding me. Result will have
to run on 1.5.2, so I have to change it then.

> Since I can't really see a goiod reason to use
> them here why not just dedent the nrested functions?
>
> >     return result1 + "</tr>"
>
> Here's the line that returns the /tr
> result is not being changed from the initial ""
> up to this point. I think this line should be
> indented to be the return value of then nrested
> function???

I'm not sure what nrested is, but I'm using local functions as mnemonics
to increase code readability.

> I really don't like nested functions much,
> unless its for functions that return functions
> and for those I'd prefer a real lambda
> - see a previous post! :-)

I know what lambdas are, but I'm very sketchy with text formatting on
Python yet, and I don't want extra long lines sticking out.



From alan.gauld@bt.com  Wed May 30 14:10:31 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 30 May 2001 14:10:31 +0100
Subject: [Tutor] stuck with html table
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7E3@mbtlipnt02.btlabs.bt.co.uk>

> > >     return result1 + "</tr>"
> >
> > Here's the line that returns the /tr...
> > indented to be the return value of then nrested
> > function???
> 
> I'm not sure what nrested is, 

A typo, I meant nested. You need to indent that 
return statement coz just now its being seen as 
the return of your top level function.


> but I'm using local functions as mnemonics
> to increase code readability.

Why bother? What does nesting give you over just 
defining them in the same module. OK, I know 
they give some namespace protection but it seems 
a marginal advantage here. Creating a Table class 
would be a better option IMHO. (Better still use one of the html generating
modules that are available


> 
> > I really don't like nested functions much,
> > unless its for functions that return functions
> > and for those I'd prefer a real lambda
> > - see a previous post! :-)
> 
> I know what lambdas are, but I'm very sketchy with text formatting on
> Python yet, and I don't want extra long lines sticking out.
> 


From alan.gauld@bt.com  Wed May 30 14:12:29 2001
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 30 May 2001 14:12:29 +0100
Subject: [Tutor] stuck with html table
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D7E4@mbtlipnt02.btlabs.bt.co.uk>

I wrote and accidentally sent....
> > but I'm using local functions as mnemonics
> > to increase code readability.
> 
> Why bother? What does nesting give you over just 
> defining them in the same module. OK, I know 
> they give some namespace protection but it seems 
> a marginal advantage here. Creating a Table class 
> would be a better option IMHO. (Better still use one of the 
> html generating modules that are available

such as htmlgen...

> > Python yet, and I don't want extra long lines sticking out.

That's what I meant about 'fixing' lambda - to allow any 
anonymous function with sensible layout, thus avoiding 
long lines...

Alan G


From scarblac@pino.selwerd.nl  Wed May 30 14:24:37 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 30 May 2001 15:24:37 +0200
Subject: [Tutor] stuck with html table
In-Reply-To: <Pine.SOL.4.33.0105301502040.19101-100000@sun1.lrz-muenchen.de>; from Eugene.Leitl@lrz.uni-muenchen.de on Wed, May 30, 2001 at 03:05:48PM +0200
References: <5104D4DBC598D211B5FE0000F8FE7EB20751D7E1@mbtlipnt02.btlabs.bt.co.uk> <Pine.SOL.4.33.0105301502040.19101-100000@sun1.lrz-muenchen.de>
Message-ID: <20010530152437.A5986@pino.selwerd.nl>

On  0, Eugene Leitl <Eugene.Leitl@lrz.uni-muenchen.de> wrote:
> On Wed, 30 May 2001 alan.gauld@bt.com wrote:
> 
> > Indented def? Implies you are on 2.1 since nested
> > functions are iffy (IMHO) in earlier versions...
> 
> Yep, and thanks for reminding me. Result will have
> to run on 1.5.2, so I have to change it then.

Nested functions like you do them here are perfectly ok in old versions.

The problems come when the function tries to use a variable from the
function in which it was defined - that wasn't possible in older versions
(this is "nested scoping"). But since you don't do that, it's perfectly ok.

-- 
Remco Gerlich


From Eugene.Leitl@lrz.uni-muenchen.de  Wed May 30 14:37:02 2001
From: Eugene.Leitl@lrz.uni-muenchen.de (Eugene Leitl)
Date: Wed, 30 May 2001 15:37:02 +0200 (MET DST)
Subject: [Tutor] stuck with html table
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D7E4@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.SOL.4.33.0105301530540.17594-100000@sun1.lrz-muenchen.de>

On Wed, 30 May 2001 alan.gauld@bt.com wrote:

> > would be a better option IMHO. (Better still use one of the
> > html generating modules that are available
>
> such as htmlgen...

I don't think HTMLgen will lay out a tree of ./cgi-bin references
(actually Bobo method maps) as a table for me. I've had a look at it right
now, and it doesn't seem to do nested lists.

> > > Python yet, and I don't want extra long lines sticking out.
>
> That's what I meant about 'fixing' lambda - to allow any
> anonymous function with sensible layout, thus avoiding
> long lines...

I'm all about good style, unfortunately this project is getting more than
a bit late. The best recipe to create atrocious code, to be late and not
to know the language...



From ryanbooz@alumni.psu.edu  Wed May 30 14:16:45 2001
From: ryanbooz@alumni.psu.edu (Ryan Booz)
Date: Wed, 30 May 2001 09:16:45 -0400
Subject: [Tutor] Pythonw question...
Message-ID: <3B14F2BD.1119EF57@alumni.psu.edu>

Hey gang...

I have a PYW program (Tkinter based) that I want to run when students
log in.  Problem is, they can't even run it normally, so putting it in
the startup folder won't do any good.  I can log into any computer and
run it so I know that PythonW is theoretically set up correctly.  But
when anyone else logs into the same computer, they can't run it.  They
do have permissions to run it and execute it.  I run a Samba server for
our Windows machines.  Any thoughts?  When anyone does try to execute
it, the computer appears to do something (I get an hourglass..) but then
nothing.  Oh yeah, I'm running 1.52.

Thanks for any help...
Ryan Booz
Tech Coordinator
Belleville Mennonite School



From dsh8290@rit.edu  Wed May 30 15:07:16 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 30 May 2001 10:07:16 -0400
Subject: [Tutor] Pythonw question...
In-Reply-To: <3B14F2BD.1119EF57@alumni.psu.edu>; from ryanbooz@alumni.psu.edu on Wed, May 30, 2001 at 09:16:45AM -0400
References: <3B14F2BD.1119EF57@alumni.psu.edu>
Message-ID: <20010530100715.B19096@harmony.cs.rit.edu>

On Wed, May 30, 2001 at 09:16:45AM -0400, Ryan Booz wrote:
| Hey gang...
| 
| I have a PYW program (Tkinter based) that I want to run when students
| log in.  Problem is, they can't even run it normally, so putting it in
| the startup folder won't do any good.  I can log into any computer and
| run it so I know that PythonW is theoretically set up correctly.  But
| when anyone else logs into the same computer, they can't run it.  They
| do have permissions to run it and execute it.  I run a Samba server for
| our Windows machines.  Any thoughts?  When anyone does try to execute
| it, the computer appears to do something (I get an hourglass..) but then
| nothing.  Oh yeah, I'm running 1.52.

It could be that you have different settings in your account than
everyone else (NT/2k, right?).  If Python was installed as a user,
then only that user will get the file associations.  If it is
installed as 'administrator' then I certainly hope (but don't have
enough experience to verify ;-)) that all users will get the new file
associations.  Can you log in as someone else (ie a student) and see
what running a simple "Hello World" python program does?  (ie 'print
"hello World"', no Tkinter yet)  Do the .py and .pyw files have the
proper icon in the students' account?  Check under (in explorer)
Tools->Folder Options, then "File Types" and look for python in the
list.

Where is python installed?  On a local disk or on a samba share?  If
it is on the samba share, do other users have access to it?

HTH,
-D



From shalehperry@home.com  Wed May 30 16:05:32 2001
From: shalehperry@home.com (Sean 'Shaleh' Perry)
Date: Wed, 30 May 2001 08:05:32 -0700 (PDT)
Subject: [Tutor] single underscore convention?
In-Reply-To: <Pine.SOL.4.33.0105301222400.14954-100000@sun1.lrz-muenchen.de>
Message-ID: <XFMail.20010530080532.shalehperry@home.com>

> 
>       _def _test1():
>               print animals[0]    # print Mammals
>               animals.printtree()
> 
>       blah blah blah
> 
>       _test1()
> 
> Why the underscore, is this a convention?
> 

Names with a leading underscore are a convention used for denoting an item is
for internal use only and not meant to be exported.  When used as members of a
class, the _ denotes intentions for this to be a private member.

__foo is typically reserved for python's use.  __foo__ implies an internal
language interface, like __init__().


From scarblac@pino.selwerd.nl  Wed May 30 16:28:47 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 30 May 2001 17:28:47 +0200
Subject: [Tutor] single underscore convention?
In-Reply-To: <XFMail.20010530080532.shalehperry@home.com>; from shalehperry@home.com on Wed, May 30, 2001 at 08:05:32AM -0700
References: <Pine.SOL.4.33.0105301222400.14954-100000@sun1.lrz-muenchen.de> <XFMail.20010530080532.shalehperry@home.com>
Message-ID: <20010530172847.A6192@pino.selwerd.nl>

On  0, Sean 'Shaleh' Perry <shalehperry@home.com> wrote:
> > 
> >       _def _test1():
> >               print animals[0]    # print Mammals
> >               animals.printtree()
> > 
> >       blah blah blah
> > 
> >       _test1()
> > 
> > Why the underscore, is this a convention?
> > 
> 
> Names with a leading underscore are a convention used for denoting an item is
> for internal use only and not meant to be exported. 

Especially, a 'from module import *' statement will not import any names
starting with an underscore.

Btw, '_def' there is a syntax error, you were overdoing it :)

-- 
Remco Gerlich


From clickron@webtv.net  Wed May 30 17:17:56 2001
From: clickron@webtv.net (clickron@webtv.net)
Date: Wed, 30 May 2001 12:17:56 -0400 (EDT)
Subject: [Tutor] starting tcl?
Message-ID: <25617-3B151D34-198@storefull-164.iap.bryant.webtv.net>

I'm on windows 98 IE and have python 2.1
On Alan Gaulds webpage lessons it says to type tclsh80 at the dos prompt
to start tcl. I tried tclsh83 since I think that is the version I have,
but it doesn't work for me.

Can anyone tell me how to start it up?

Ron



From deirdre@deirdre.net  Wed May 30 17:55:19 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Wed, 30 May 2001 09:55:19 -0700
Subject: [Tutor] help
In-Reply-To: <2CBB2B49D955264DAF22D7E9B67D2FBD06E76B@durban3.logical.co.za>
References: <2CBB2B49D955264DAF22D7E9B67D2FBD06E76B@durban3.logical.co.za>
Message-ID: <a05100e04b73ad557db07@[10.0.1.7]>

First, some etiquette:

This is a group of volunteers. We all have different skills and 
different available time.

Don't set your messages highest priority -- some of us will tend not 
to look at them. In fact, I deleted this before opening, but before 
purging deleted messages, decided to answer.

At 11:45 AM +0200 5/30/01, Fayyaz Asmal wrote:
>i need help on python
>
>im learning the language for the 1st time
>
>i need help on making a connection to MY*SQL or SQL server
>adding a record
>deleteing a record
>and updating a record

See:
http://www.amk.ca/python/writing/DB-API.html

>eg : a user interface with 3 options
>add
>edit
>delete
>
>when u click on add - it allows u to add a firstname and lastname
>etc etc
>
>when u clik on edit - it allows u to edit a record
>
>when u click on delete - it allows u to delete a record

GUI is a whole 'nother subject I'll let someone else tackle.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From RWare@INTERPLASTIC.com  Wed May 30 16:58:24 2001
From: RWare@INTERPLASTIC.com (Ryan Ware)
Date: Wed, 30 May 2001 10:58:24 -0500
Subject: [Tutor] python and ms access resource
Message-ID: <8794B3B640FED2118D8600C00D0020A593F48C@ipserver2.interplastic.com>

	Someone was asking about python and ms access the other day.  I
wasn't sure if anyone had any suggestions, so here is a link with some info.
http://starship.python.net/crew/bwilk/access.html  Can't speak for it
myself.  I am only beginning programming.

	Ryan Ware




From deirdre@deirdre.net  Wed May 30 18:08:17 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Wed, 30 May 2001 10:08:17 -0700
Subject: [Tutor] python and ms access resource
In-Reply-To: <8794B3B640FED2118D8600C00D0020A593F48C@ipserver2.interplastic.com>
References: <8794B3B640FED2118D8600C00D0020A593F48C@ipserver2.interplastic.com>
Message-ID: <a05100e05b73ad91fbdfb@[10.0.1.7]>

>	Someone was asking about python and ms access the other day.  I
>wasn't sure if anyone had any suggestions, so here is a link with some info.
>http://starship.python.net/crew/bwilk/access.html  Can't speak for it
>myself.  I am only beginning programming.

In general, almost all databases that support ODBC will be supported 
in Python through the mxODBC module.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From dyoo@hkn.eecs.berkeley.edu  Wed May 30 18:14:00 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Wed, 30 May 2001 10:14:00 -0700 (PDT)
Subject: [Tutor] database connectivity over networks (fwd)
Message-ID: <Pine.LNX.4.21.0105301012530.10062-100000@hkn.eecs.berkeley.edu>

Dear Curtis,

Let me forward this to the rest of the tutor list; I think you accidently
sent it only to me... *grin*


---------- Forwarded message ----------
Date: Wed, 30 May 2001 02:13:29 -0700
From: Curtis Horn <curtishorn@home.com>
To: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] database connectivity over networks

Thank you, and yes, I'd like to use mySQL.  I'm basically monitoring a log 
file that is constantly updated, so what I'd figure I'd do is have python 
make a copy of the log every 5? seconds then look for new lines, if it 
finds lines that I want it would send that info to a database.  I'm 
thinking of using zope to create a page that will show what these logs are 
doing, maybe visually, and have the capability to search the DB.

BTW, for any other newbies out there, if you are having trouble with Object 
Oriented stuff I recommend the book "the object oriented thought process". 
It wasn't till I read this book that I felt I got it, and now I'm rereading 
my python books with allot more confidence.

Ok, second question.  What about if I have a data stream I want to connect 
to, like maybe stock quotes and, of course, I'd like to make my own program 
to graph/calculate indicators/ect.. written in python.  What do I need to 
know about the way the data is sent?  Anyone have experience doing 
something like this?

                 Curtis

At 12:58 AM 5/30/01 -0700, you wrote:
>On Tue, 29 May 2001, Curtis Horn wrote:
>
> > I was wondering how I would go about sending data to a database over a
> > network using python.
>
>What sort of database is it?  Is it MySQL, Postgres, or something else?
>I'll assume that you mean an SQL database. Python uses a standardized
>database interface (DB API 2.0), so the motions to set things up are
>similar between database systems.
>
>     http://python.org/topics/database/DatabaseAPI-2.0.html
>
>You'll need to start up a connection with the server, and this is usually
>done with a connect() call.  In MySQL, for example, if we wanted to
>connect to a database in Tokyo, for example, we could do something like
>this:
>
>###
>import MySQLdb
>db = MySQLdb.Connection(host="database.monster.jp",
>                         user="godzilla",
>                         passwd="rubberducky",
>                         db="GameraDefensePlans")
>###
>
> From then on, we can do database stuff through our 'db' instance.  So it
>really shouldn't matter where the database is located after we initialize
>our connection, be it overseas or in the middle of the Nevada desert.
>
>Tell us a little more about what kind of database it is, and we can point
>you toward relevant information.  You can also find more information here:
>
>     http://python.org/topics/database/
>
>
>Good luck to you.



From deirdre@deirdre.net  Wed May 30 18:29:10 2001
From: deirdre@deirdre.net (Deirdre Saoirse Moen)
Date: Wed, 30 May 2001 10:29:10 -0700
Subject: [Tutor] database connectivity over networks (fwd)
In-Reply-To: <Pine.LNX.4.21.0105301012530.10062-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.21.0105301012530.10062-100000@hkn.eecs.berkeley.edu>
Message-ID: <a05100e06b73adc4e7cf9@[10.0.1.7]>

>Dear Curtis,
>
>Let me forward this to the rest of the tutor list; I think you accidently
>sent it only to me... *grin*
>
>---------- Forwarded message ----------
>Ok, second question.  What about if I have a data stream I want to connect
>to, like maybe stock quotes and, of course, I'd like to make my own program
>to graph/calculate indicators/ect.. written in python.  What do I need to
>know about the way the data is sent?  Anyone have experience doing
>something like this?

This is a complex problem and there's a bunch of ways to solve it. In 
fact, there's two whole books dedicated to network programming that 
are considered the reference in the field. Search for "unix network 
programming" on your web bookstore of choice. The books are by 
Richard Stevens.
-- 
_Deirdre     Stash-o-Matic: http://weirdre.com      http://deirdre.net
Macintosh Developer (seeking work): Will work for Cocoa
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                          - Douglas Adams


From tescoil@irtc.net  Wed May 30 21:58:21 2001
From: tescoil@irtc.net (Tesla Coil)
Date: Wed, 30 May 2001 15:58:21 -0500
Subject: [Tutor] mp3 range violation reportage.
References: <200105300010.f4U0ABX02705@dsl092-074-184.bos1.dsl.speakeasy.net> <3B1445A4.7AE1A243@irtc.net> <20010530080228.B18885@harmony.cs.rit.edu>
Message-ID: <3B155EED.E4008C4@irtc.net>

On 30 May 2001, D-Man replied:
>> But don't know the system doesn't have mpg123 
>> in /usr/local/bin or elsewhere on path.
>> 
>> There's *gotta* be an easy answer to this one.
>
> The easiest way is to just try it.

I did a temporary rename of mpg123 and found that 
clippage.py then just exits rapidly, with nothing
returned to stdout.  Q&D program that this is, I'm
kinda satisfied just to have it not blow sky high.
Conveniently, it's already reading stderr, and it
does the trick here to add:

def whatwentwrong(rawreport):
    # Pass error messages.
    if rawreport[-1][-10:-1]=='not found':
        print rawreport[-1]
    elif rawreport[-1][-26:-14]=='No such file':
        print rawreport[-1]

if __name__ == '__main__':
    commandline = modusoperandi(argv[1])
    mpgout = runtest(commandline)
    whatwentwrong(mpgout)
    relevantdata = slicedown(mpgout)
    tracks = gettracks(relevantdata)
    clips = clipsums(relevantdata)
    reportout(tracks, clips)

Not sure it does the trick elsewhere, but there's
lotsa things I'm not sure about elsewhere.



From tim.one@home.com  Wed May 30 23:01:16 2001
From: tim.one@home.com (Tim Peters)
Date: Wed, 30 May 2001 18:01:16 -0400
Subject: [Tutor] Illegal Operation??
In-Reply-To: <20010530081452.C18885@harmony.cs.rit.edu>
Message-ID: <LNBBLJKPBEHFEDALKOLCMEHGKFAA.tim.one@home.com>

I'm afraid Tcl/Tk doesn't play nice with threads.  For example, the usual
result of trying to run a threaded program under IDLE is also some sort of
crash in tcl83.dll.  AFAIK, the only way to get it to work is to write your
code such that *you* guarantee that the thread in which Tk is first invoked
is the *only* thread Tk ever gets invoked from or gets called back from.
For example, do all your computation in one thread and all your GUI in a
different thread.



From toodles@yifan.net  Thu May 31 03:36:10 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Thu, 31 May 2001 10:36:10 +0800
Subject: [Tutor] Lists...
Message-ID: <FPEHJJPEEOIPMAHOADBKEENECDAA.toodles@yifan.net>

Hi people,

Is there a way of returning the intersection of two lists?
Eg. [1,2,'3',4.0,'x'] & [1,8,'3',9,10,'x'] to return [1,'3','x']

Andrew Wilkins




From dsh8290@rit.edu  Thu May 31 03:52:03 2001
From: dsh8290@rit.edu (D-Man)
Date: Wed, 30 May 2001 22:52:03 -0400
Subject: [Tutor] Lists...
In-Reply-To: <FPEHJJPEEOIPMAHOADBKEENECDAA.toodles@yifan.net>; from toodles@yifan.net on Thu, May 31, 2001 at 10:36:10AM +0800
References: <FPEHJJPEEOIPMAHOADBKEENECDAA.toodles@yifan.net>
Message-ID: <20010530225202.C521@harmony.cs.rit.edu>

On Thu, May 31, 2001 at 10:36:10AM +0800, Andrew Wilkins wrote:
| Hi people,
| 
| Is there a way of returning the intersection of two lists?
| Eg. [1,2,'3',4.0,'x'] & [1,8,'3',9,10,'x'] to return [1,'3','x']

(untested)

def instersect( l1 , l2 ) :
    result = []
    for item in l1 :
        if item in l2 :
            result.append( item )

    return result

If the lists get large, this will have horrible performance because
the "item in l2" performs a linear search.  If you can create a
dictionary from one of the lists then the speed of the inersection
will be improved, but time will be spent building the citionary.  (It
is faster because the has_key method hashes the key and checks if it
exists rather than performing a linear search on a list)

This list comprehension shoud do the same thing :

def intersect( l1 , l2 ) :
    return [ item for item in l1 if item in l2 ]


-D



From gibbs05@flash.net  Thu May 31 04:04:52 2001
From: gibbs05@flash.net (Archimedes)
Date: Wed, 30 May 2001 22:04:52 -0500
Subject: [Tutor] Lists...
References: <FPEHJJPEEOIPMAHOADBKEENECDAA.toodles@yifan.net>
Message-ID: <009401c0e97e$829185a0$e0ef3040@gibbs05>

----- Original Message ----- 
From: "Andrew Wilkins" <toodles@yifan.net>
To: <tutor@python.org>
Sent: Wednesday, May 30, 2001 9:36 PM
Subject: [Tutor] Lists...


> Hi people,
> 
> Is there a way of returning the intersection of two lists?
> Eg. [1,2,'3',4.0,'x'] & [1,8,'3',9,10,'x'] to return [1,'3','x']

Sure.

Here's how to do it by brute force:

    >>> a = [1,2,'3',4.0,'x']
    >>> b = [1,8,'3',9,10,'x']
    >>> def intersection(a, b):
    ...        result = []
    ...        for item in a:
    ...            if item in b:
    ...                result.append(item)
    ...        return result
    ... 
    >>> intersection(a, b)
    [1, '3', 'x']

> Andrew Wilkins

Good luck.

Sam




From sarnold@earthling.net  Thu May 31 04:50:21 2001
From: sarnold@earthling.net (Stephen L Arnold)
Date: Wed, 30 May 2001 20:50:21 -0700
Subject: [Tutor] help
In-Reply-To: <2CBB2B49D955264DAF22D7E9B67D2FBD06E76B@durban3.logical.co.za>
Message-ID: <20010531035021.934C11F61A@shiva.arnolds.bogus>

On 30 May 01, at 11:45, Fayyaz Asmal wrote:

> i need help on making a connection to MY*SQL or SQL server
> adding a record
> deleteing a record
> and updating a record

I'd check the database section here:

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

and see if someone has already written one.

Steve

*************************************************************
Steve Arnold                            sarnold@earthling.net
                                       http://arnolds.dhs.org
Java is for staying up late while you program in Python...


From toodles@yifan.net  Thu May 31 04:58:46 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Thu, 31 May 2001 11:58:46 +0800
Subject: [Tutor] Lists...
In-Reply-To: <20010530225202.C521@harmony.cs.rit.edu>
Message-ID: <FPEHJJPEEOIPMAHOADBKAENFCDAA.toodles@yifan.net>

> If the lists get large, this will have horrible performance because
> the "item in l2" performs a linear search.  If you can create a
> dictionary from one of the lists then the speed of the inersection
> will be improved, but time will be spent building the citionary.  (It
> is faster because the has_key method hashes the key and checks if it
> exists rather than performing a linear search on a list)

Ahh just what I was hoping not to receive =)
The thing is, the lists I'm using are terribly big. What I'm doing is
creating ranges of coordinates,
so the lists generally will vary from 100 to 1000 elements. I'll try the
dictionary method! If that's slow, do you think a C implementation would be
worth the trouble? I've never tried implementing modules in C, could be fun
=)

Thanks!

>
> This list comprehension shoud do the same thing :
>
> def intersect( l1 , l2 ) :
>     return [ item for item in l1 if item in l2 ]
>
>
> -D
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From scarblac@pino.selwerd.nl  Thu May 31 06:48:04 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 31 May 2001 07:48:04 +0200
Subject: [Tutor] Lists...
In-Reply-To: <FPEHJJPEEOIPMAHOADBKAENFCDAA.toodles@yifan.net>; from toodles@yifan.net on Thu, May 31, 2001 at 11:58:46AM +0800
References: <20010530225202.C521@harmony.cs.rit.edu> <FPEHJJPEEOIPMAHOADBKAENFCDAA.toodles@yifan.net>
Message-ID: <20010531074804.A7063@pino.selwerd.nl>

On  0, Andrew Wilkins <toodles@yifan.net> wrote:
> > If the lists get large, this will have horrible performance because
> > the "item in l2" performs a linear search.  If you can create a
> > dictionary from one of the lists then the speed of the inersection
> > will be improved, but time will be spent building the citionary.  (It
> > is faster because the has_key method hashes the key and checks if it
> > exists rather than performing a linear search on a list)
> 
> Ahh just what I was hoping not to receive =)
> The thing is, the lists I'm using are terribly big. What I'm doing is
> creating ranges of coordinates,
> so the lists generally will vary from 100 to 1000 elements. I'll try the
> dictionary method!

That should work much faster. What you didn't mention is what should happen
if something occurs more than once in the first or second lists, what kind
of objects can be in it (a list can't be a dictionary key) and if the order
of the items matters.

Hmm. The following way should be pretty fast, it preservers the order in l1,
if something occurs in l1 more then once it will still occur more than once
(or not at all depending on l2), and it doesn't work if there are
non-hashable things like lists and instances in l2:

l1 = [...]
l2 = [...]

dict = {}
for thing in l2:
   dict[thing] = 1
   
l3 = filter(dict.has_key, l1)

The filter command takes all the elements of l1, and 'lets through' only
those for which dict.has_key(element) is true. By the way we made dict, its
keys are the things in l2.

> If that's slow, do you think a C implementation would be
> worth the trouble? I've never tried implementing modules in C, could be fun
> =)

Try how fast this is, first. Much of the work is done in the filter, which
is written in C. And it's gone from taking time proportional to
len(l1)*len(l2) to time proportional to len(l1)+len(l2). It should be fast
enough. 

Changing the algorithm can help a lot more than changing the language - if
you had done it in C, building a hash table (like a dictionary) wouldn't
have been obvious, and lots of work.

Oh, and dictionaries are *cool* :).

-- 
Remco Gerlich


From lonetwin@yahoo.com  Thu May 31 07:23:20 2001
From: lonetwin@yahoo.com (steve)
Date: Thu, 31 May 2001 11:53:20 +0530
Subject: [Tutor] database connectivity over networks (fwd)
In-Reply-To: <a05100e06b73adc4e7cf9@[10.0.1.7]>
References: <Pine.LNX.4.21.0105301012530.10062-100000@hkn.eecs.berkeley.edu> <a05100e06b73adc4e7cf9@[10.0.1.7]>
Message-ID: <01053111532000.03611@mercury.in.cqsl.com>

Hey there,

On Wednesday 30 May 2001 22:59, you wrote:
> >Dear Curtis,
> >
> >Let me forward this to the rest of the tutor list; I think you acciden=
tly
> >sent it only to me... *grin*
> >
> >---------- Forwarded message ----------
> >Ok, second question.  What about if I have a data stream I want to con=
nect
> >to, like maybe stock quotes and, of course, I'd like to make my own
> > program to graph/calculate indicators/ect.. written in python.  What =
do I
> > need to know about the way the data is sent?  Anyone have experience
> > doing something like this?
>
> This is a complex problem and there's a bunch of ways to solve it. In
> fact, there's two whole books dedicated to network programming that
> are considered the reference in the field. Search for "unix network
> programming" on your web bookstore of choice. The books are by
> Richard Stevens.

ehe......b4 u go that deep ...don't you think a dekko at the sockets-HOWT=
O in=20
the python docs wud do ??

Just my thoughts....

Peace
Steve
--=20
||||||||||||||||||||||
|||||||||#####||||||||
||||||||#######|||||||
||||||||# O O #|||||||
||||||||#\ ~ /#|||||||
||||||##||\_/||##|||||
|||||#||||||||||##||||
||||#||||||||||||##|||
||||#|||||||||||||##||=09
|||/\##|||||||||##/\||=09
|/    \#########/    \=09
|\     \#######/     /=09
||\____/#######\____/|=09
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09
Hello.  Just walk along and try NOT to think about your INTESTINES
being almost FORTY YARDS LONG!!
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


From r.b.rigilink@chello.nl  Thu May 31 08:00:16 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Thu, 31 May 2001 09:00:16 +0200
Subject: [Tutor] Lists...
References: <FPEHJJPEEOIPMAHOADBKAENFCDAA.toodles@yifan.net>
Message-ID: <3B15EC00.6C5BA23E@chello.nl>

Andrew Wilkins wrote:
> 
> Ahh just what I was hoping not to receive =)
> The thing is, the lists I'm using are terribly big. What I'm doing is
> creating ranges of coordinates,
> so the lists generally will vary from 100 to 1000 elements. I'll try the
> dictionary method! If that's slow, do you think a C implementation would be
> worth the trouble? I've never tried implementing modules in C, could be fun
> =)
> 

Hi Andrew,

Just out of curiosity I did the timing.
I added a intersection method based on the assumption that the lists
are already sorted

Here's the code:

def intersect1(l1, l2):
    '''brute force intersection of two lists'''
    return [item for item in l1 if item in l2]

def intersect2(l1, l2):
    '''intersection of two lists, using dicts'''
    dict = {}
    for item in l2:
        dict[item] = None
    return [item for item in l1 if dict.has_key(item)]

def intersect2a(l1, l2):
    '''using dicts with filter, thanks to Remco Gehrlich'''
    dict = {}
    for item in l2:
        dict[item] = 1
    return filter(dict.has_key, l1)

def intersect3(l1, l2):
    '''intersection of two sorted lists of unique items'''
    result = []
    lo = 0
    hi = len(l2)
    for i in l1:
        for j in xrange(lo, hi):
            n = cmp(l2[j], i)
            if n==-1:
                lo = j
            elif n==1:
                break
            else:
                lo = j
                result.append(i)
                break
    return result
             
def make_list(n):
    '''Make a sorted list of unique ints larger than 1'''
    import random
    l = []
    x = 1
    for i in xrange(n):
        x = x+random.randrange(1, 5)
        l.append(x)
    return l

def time_func(intersect_func, l1, l2):
    import time
    t1 = time.time()
    l = intersect_func(l1, l2)
    t2 = time.time()-t1
#    print l[0:10]
    return t2

def test(n):
    l1 = make_list(n)
    l2 = make_list(n)
    print 'Brute force (n=%i), t=%f' % (n, time_func(intersect1, l1,
l2))
    print 'Dict lookup (n=%i), t=%f' % (n, time_func(intersect2, l1,
l2))
    print 'Dict filter (n=%i), t=%f' % (n, time_func(intersect2a, l1,
l2))
    print 'Sorted list (n=%i), t=%f' % (n, time_func(intersect3, l1,
l2))

if __name__=='__main__':
    test(10)
    test(100)
    test(1000)

And this is the result:

Brute force (n=10), t=0.000131
Dict lookup (n=10), t=0.000169
Dict filter (n=10), t=0.000146
Sorted list (n=10), t=0.000450
Brute force (n=100), t=0.006470
Dict lookup (n=100), t=0.001560
Dict filter (n=100), t=0.000723
Sorted list (n=100), t=0.003907
Brute force (n=1000), t=0.626828
Dict lookup (n=1000), t=0.013675
Dict filter (n=1000), t=0.007070
Sorted list (n=1000), t=0.041294


As you can see, Remco's version is fastest (staying at less than .1 sec
for two
10k lists). I minor quibble would be that that method doesn't detect a 0
that's in both lists.

intersect3 is the only reasonable thing I could come up with that
doesn't use dicts. It's also scales linearly, but it's 4 times slower
(and took 100 times longer to write, it had a non-obvious bug) than
intersect2. It may be usefull if your list elements are non-hashable
(can't be dictionary keys).

Note that make_list() produces lists that meet all the rather severe
requirements that some of the intersection function require.

You shouldn't expect a C version to improve this by huge factors.

Hope this helps,

Roeland


From scarblac@pino.selwerd.nl  Thu May 31 08:32:02 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 31 May 2001 09:32:02 +0200
Subject: [Tutor] Lists...
In-Reply-To: <3B15EC00.6C5BA23E@chello.nl>; from r.b.rigilink@chello.nl on Thu, May 31, 2001 at 09:00:16AM +0200
References: <FPEHJJPEEOIPMAHOADBKAENFCDAA.toodles@yifan.net> <3B15EC00.6C5BA23E@chello.nl>
Message-ID: <20010531093202.A7244@pino.selwerd.nl>

On  0, Roeland Rengelink <r.b.rigilink@chello.nl> wrote:
> As you can see, Remco's version is fastest (staying at less than .1 sec
> for two
> 10k lists). I minor quibble would be that that method doesn't detect a 0
> that's in both lists.

It does. dict.has_key(0) is 1 in that case, and the filter puts it in the
result.

> intersect3 is the only reasonable thing I could come up with that
> doesn't use dicts. It's also scales linearly, but it's 4 times slower
> (and took 100 times longer to write, it had a non-obvious bug) than
> intersect2. It may be usefull if your list elements are non-hashable
> (can't be dictionary keys).

Yes. Sorting them hadn't occurred to me yet.

-- 
Remco Gerlich


From r.b.rigilink@chello.nl  Thu May 31 09:11:19 2001
From: r.b.rigilink@chello.nl (Roeland Rengelink)
Date: Thu, 31 May 2001 10:11:19 +0200
Subject: [Tutor] Lists...
References: <FPEHJJPEEOIPMAHOADBKAENFCDAA.toodles@yifan.net> <3B15EC00.6C5BA23E@chello.nl> <20010531093202.A7244@pino.selwerd.nl>
Message-ID: <3B15FCA7.369CD46C@chello.nl>

Remco Gerlich wrote:
> 
> On  0, Roeland Rengelink <r.b.rigilink@chello.nl> wrote:
> > As you can see, Remco's version is fastest (staying at less than .1 sec
> > for two
> > 10k lists). I minor quibble would be that that method doesn't detect a 0
> > that's in both lists.
> 
> It does. dict.has_key(0) is 1 in that case, and the filter puts it in the
> result.
>

I should have remembered

1. Drink koffee
2. Drink more koffee
3. Think
4. Write

I omitted both 2 and 3, a sure recipe for stupidity

Thanks for catching it.

Roeland

-- 
r.b.rigilink@chello.nl

"Half of what I say is nonsense. Unfortunately I don't know which half"


From toodles@yifan.net  Thu May 31 09:21:10 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Thu, 31 May 2001 16:21:10 +0800
Subject: [Tutor] Lists...
In-Reply-To: <20010531093202.A7244@pino.selwerd.nl>
Message-ID: <FPEHJJPEEOIPMAHOADBKKENGCDAA.toodles@yifan.net>

Thanks very much D-Man, Sam, Remco and Roeland, this has been very helpful!

Andrew Wilkins

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Remco Gerlich
> Sent: Thursday, 31 May 2001 3:32 PM
> To: tutor@python.org
> Subject: Re: [Tutor] Lists...
>
>
> On  0, Roeland Rengelink <r.b.rigilink@chello.nl> wrote:
> > As you can see, Remco's version is fastest (staying at less than .1 sec
> > for two
> > 10k lists). I minor quibble would be that that method doesn't detect a 0
> > that's in both lists.
>
> It does. dict.has_key(0) is 1 in that case, and the filter puts it in the
> result.
>
> > intersect3 is the only reasonable thing I could come up with that
> > doesn't use dicts. It's also scales linearly, but it's 4 times slower
> > (and took 100 times longer to write, it had a non-obvious bug) than
> > intersect2. It may be usefull if your list elements are non-hashable
> > (can't be dictionary keys).
>
> Yes. Sorting them hadn't occurred to me yet.
>
> --
> Remco Gerlich
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From dyoo@hkn.eecs.berkeley.edu  Thu May 31 09:42:09 2001
From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo)
Date: Thu, 31 May 2001 01:42:09 -0700 (PDT)
Subject: [Tutor] Lists...
In-Reply-To: <FPEHJJPEEOIPMAHOADBKAENFCDAA.toodles@yifan.net>
Message-ID: <Pine.LNX.4.21.0105310140520.21869-100000@hkn.eecs.berkeley.edu>

On Thu, 31 May 2001, Andrew Wilkins wrote:

> > If the lists get large, this will have horrible performance because
> > the "item in l2" performs a linear search.  If you can create a
> > dictionary from one of the lists then the speed of the inersection
> > will be improved, but time will be spent building the citionary.  (It
> > is faster because the has_key method hashes the key and checks if it
> > exists rather than performing a linear search on a list)
> 
> Ahh just what I was hoping not to receive =)
> The thing is, the lists I'm using are terribly big. What I'm doing is
> creating ranges of coordinates,
> so the lists generally will vary from 100 to 1000 elements. I'll try the
> dictionary method! If that's slow, do you think a C implementation would be
> worth the trouble? I've never tried implementing modules in C, could be fun

If it's possible to sort both lists of numbers, then taking the
intersection of two sorted lists isn't too bad either; what kind of things
will your lists contain?



From wheelege@tsn.cc  Thu May 31 09:48:42 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Thu, 31 May 2001 18:48:42 +1000
Subject: [Tutor] *sigh*
References: <FPEHJJPEEOIPMAHOADBKGEMOCDAA.toodles@yifan.net> <001001c0e8db$40cafaa0$0200a8c0@ACE> <3B14D25D.DA66A4ED@jam.rr.com>
Message-ID: <015a01c0e9ae$7f0095e0$0200a8c0@ACE>

>
> I tried it on Python 2.1 on a 98 SE box. Two windows appeared, one blank
> and one with the words Path, Alright, Fun, and Stupid and a button
> *pring jim*. *print jim* just caused a number (seemed random) to output.
> Same thing under 2.0 on the same box.
>

  Same thing under 2.0?  Now that's a little crazy.  It should have
radiobuttons in 2 and just text in 2.1 - at least from my
observations...they are meant to be radiobuttons on both versions.
  Ah the joys of platform specific bugs.

> Rob



From toodles@yifan.net  Thu May 31 10:03:02 2001
From: toodles@yifan.net (Andrew Wilkins)
Date: Thu, 31 May 2001 17:03:02 +0800
Subject: [Tutor] Lists...
In-Reply-To: <Pine.LNX.4.21.0105310140520.21869-100000@hkn.eecs.berkeley.edu>
Message-ID: <FPEHJJPEEOIPMAHOADBKGENHCDAA.toodles@yifan.net>

> If it's possible to sort both lists of numbers, then taking the
> intersection of two sorted lists isn't too bad either; what kind of things
> will your lists contain?

They'll just contain positive integers, sorry for not mentioning
earlier...I'll try to be a little less abstract in future! But it really
doesn't need to be sorted, I just want to know whether any of list a's
elements are contained in list b. The solutions I've got already are great,
so don't worry about this one anymore. Thanks!

Andrew Wilkins

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




From wheelege@tsn.cc  Thu May 31 10:01:55 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Thu, 31 May 2001 19:01:55 +1000
Subject: [Tutor] Illegal Operation??
References: <002a01c0e8eb$89353ca0$0200a8c0@ACE> <20010530081452.C18885@harmony.cs.rit.edu>
Message-ID: <01a001c0e9b0$59717ea0$0200a8c0@ACE>

> On Wed, May 30, 2001 at 07:33:07PM +1000, Glen Wheeler wrote:
> |   Hello again,
> |
> |   Well, this one definitely has me stumped (yes, even more so than
> |   the phantom radiobutton).  After playing my game for a period of
> |   time, PYTHON will cause an illegal operation in module tcl83.dll
> |   and it shuts down.
>
> Ooh, fun with windows.  At least *nix systems give you a core dump to
> inspect!  I have a friend who had a temporary job doing C++ work on
> Windows a few months ago.  He said that sometimes he got "Invalid
> operation in kernel.dll" messages.  Not surprising that the kernel
> didn't work right, but needless to say it was his code that needed
> fixing.  He never wants to do development on windows again.
>

  Ha ha, I feel his pain...I've had plenty of invalid operation in
kernel.dll - usually when my code is broken, or if the system is say running
about 4 or 5 applications at a time.

> |   Needless to say this is very annoying.  It happens at the same
> |   memory address every single time, so I imagine it is something
> |   happening around there.  I'm running win98.
> |   My script is a little...large to be posting here.  Also, if it was
> |   an error with my code then wouldn't there be at least some kind of
> |   traceback?
>
> Only if it is an error that Python is prepared to check for.  It is
> conceivable that there is some condition not being checked by tcl,
> then it executes some invalid C/C++ level instruction (it is a dll)
> causing the crash.
>

  Yes...I think it is either Tcl or Windows...and Tim thinks Tcl so, who am
I (or any intelligent man) to argue?

> I would recommend adding a bunch of print statements in strategic
> locations in your script.  Since you are using threads be sure to
> include the thread name in the output (Java has a  Thread.getName()
> method).  Output such as "got to this function" is sufficient.  When
> it crashes, see the last thing that was printed (oh, yeah, be sure to
> flush stdout so that it actually makes it to the screen ;-)) and
> follow the code from there adding more prints until the problem is
> identified.
>

  This is a good idea, but one which is absolutely exhausted.  The crash
happens seemingly randomly, in a random thread at a random time.  When I
showed a supervisor the error, (although not too impressed) it was a little
embarrasing...it didn't die for a full 15 minutes.  I was genuinely relieved
when it did.
  Needless to say, he just said 'fix it'.

> HTH,
> -D
>



From wheelege@tsn.cc  Thu May 31 10:08:18 2001
From: wheelege@tsn.cc (Glen Wheeler)
Date: Thu, 31 May 2001 19:08:18 +1000
Subject: [Tutor] Illegal Operation??
References: <LNBBLJKPBEHFEDALKOLCMEHGKFAA.tim.one@home.com>
Message-ID: <01a401c0e9b1$3c528ca0$0200a8c0@ACE>

> I'm afraid Tcl/Tk doesn't play nice with threads.  For example, the usual
> result of trying to run a threaded program under IDLE is also some sort of
> crash in tcl83.dll.  AFAIK, the only way to get it to work is to write
your
> code such that *you* guarantee that the thread in which Tk is first
invoked
> is the *only* thread Tk ever gets invoked from or gets called back from.
> For example, do all your computation in one thread and all your GUI in a
> different thread.
>

  ARGH....seriosuly?  *sneaks a side look at 1200+ line script in question*.

  Oh dear.  Allow me some time to grieve.

...

...

...

  Ok, over it...  So, it should be fine if I keep all the gui stuff in one
thread...and all the other stuff in other threadS?  I will need more than
two...and here I was thinking I was finished.
  Perhaps the lockups aren't random, but where GUI calls are made to
tcl...hmmm there may be a pattern.  There is a pattern!  Brilliant, now if I
just grow an extra day, I can get this finished on time.
  Argh...perhaps two days...why doesn't tcl just work with threads?  :(

  *gets ready for an all-niter*

  Glen.



From quack@netguard.com.cn  Thu May 31 10:49:25 2001
From: quack@netguard.com.cn (quack)
Date: Thu, 31 May 2001 17:49:25 +0800
Subject: [Tutor] (no subject)
Message-ID: <E155P7N-0007NO-00@mail.python.org>





From GADGILP@INFOTECH.ICICI.com  Thu May 31 11:06:45 2001
From: GADGILP@INFOTECH.ICICI.com (GADGIL PRASAD /INFRA/INFOTECH)
Date: Thu, 31 May 2001 15:36:45 +0530
Subject: [Tutor] async signal/notification & resulting action bet 2 seperate progr
 ams.
Message-ID: <718A0962DFC2D4119FF80008C7289E4701032D40@ICICIBACK3>

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

------_=_NextPart_001_01C0E9B9.65BD72F0
Content-Type: text/plain;
	charset="iso-8859-1"

hello,

I am trying to write a generic monitering agent.

There will be some monitoring task for the AGENT_program. This program
(currently) does the reqd check every polling interval. It's basically
doing the monitering in a continous while loop, sleeping the poll_interval
time, for every pass through the loop.

But some things are important enough that I might want an near immidiate
notification rather than at the next poll after the severity of the
monitered
thing changes.

How do I implement such an out of the poll notification ?

I guess, for such a task, the Monitered thing will need to send a 
signal/exception/whatever to my monitering program. My monitering program
will
awaken on reciept of such an event, and make another pass through the while
loop.

I checked, signal()/pause()/exception related stuff, in PY-TUT. But, I don't
know
how to send the messages bet 2 diff programs/processes.

Can someone pl. explain what do I need to do in this case ?

regards,

prasad


. 


------_=_NextPart_001_01C0E9B9.65BD72F0
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>async signal/notification &amp; resulting action bet 2 seperate programs.</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>hello,</FONT>
</P>

<P><FONT SIZE=2>I am trying to write a generic monitering agent.</FONT>
</P>

<P><FONT SIZE=2>There will be some monitoring task for the AGENT_program. This program</FONT>
<BR><FONT SIZE=2>(currently) does the reqd check every polling interval. It's basically</FONT>
<BR><FONT SIZE=2>doing the monitering in a continous while loop, sleeping the poll_interval</FONT>
<BR><FONT SIZE=2>time, for every pass through the loop.</FONT>
</P>

<P><FONT SIZE=2>But some things are important enough that I might want an near immidiate</FONT>
<BR><FONT SIZE=2>notification rather than at the next poll after the severity of the monitered</FONT>
<BR><FONT SIZE=2>thing changes.</FONT>
</P>

<P><FONT SIZE=2>How do I implement such an out of the poll notification ?</FONT>
</P>

<P><FONT SIZE=2>I guess, for such a task, the Monitered thing will need to send a </FONT>
<BR><FONT SIZE=2>signal/exception/whatever to my monitering program. My monitering program will</FONT>
<BR><FONT SIZE=2>awaken on reciept of such an event, and make another pass through the while loop.</FONT>
</P>

<P><FONT SIZE=2>I checked, signal()/pause()/exception related stuff, in PY-TUT. But, I don't know</FONT>
<BR><FONT SIZE=2>how to send the messages bet 2 diff programs/processes.</FONT>
</P>

<P><FONT SIZE=2>Can someone pl. explain what do I need to do in this case ?</FONT>
</P>

<P><FONT SIZE=2>regards,</FONT>
</P>

<P><FONT SIZE=2>prasad</FONT>
</P>
<BR>

<P><B><FONT SIZE=2>.. </FONT></B>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C0E9B9.65BD72F0--


From arcege@speakeasy.net  Thu May 31 13:38:44 2001
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Thu, 31 May 2001 08:38:44 -0400 (EDT)
Subject: [Tutor] async signal/notification & resulting action bet 2 seperate progr
In-Reply-To: <718A0962DFC2D4119FF80008C7289E4701032D40@ICICIBACK3> from "GADGIL PRASAD     /INFRA/INFOTECH" at May 31, 2001 03:36:45 PM
Message-ID: <200105311238.f4VCcjR01766@dsl092-074-184.bos1.dsl.speakeasy.net>

GADGIL PRASAD     /INFRA/INFOTECH wrote
> hello,
> 
> I am trying to write a generic monitering agent.
> 
> There will be some monitoring task for the AGENT_program. This program
> (currently) does the reqd check every polling interval. It's basically
> doing the monitering in a continous while loop, sleeping the poll_interval
> time, for every pass through the loop.
> 
> But some things are important enough that I might want an near immidiate
> notification rather than at the next poll after the severity of the
> monitered
> thing changes.
> 
> How do I implement such an out of the poll notification ?
> 
> I guess, for such a task, the Monitered thing will need to send a 
> signal/exception/whatever to my monitering program. My monitering program
> will
> awaken on reciept of such an event, and make another pass through the while
> loop.
> 
> I checked, signal()/pause()/exception related stuff, in PY-TUT. But, I don't
> know
> how to send the messages bet 2 diff programs/processes.
> 
> Can someone pl. explain what do I need to do in this case ?

If it is UNIX then you can use signals, otherwise I would suggest
using select and named pipes or sockets (sockets on WinXX) to send
notifications.  (Below is all "pseudocode" and not meant to be working
code.)

Signals:
First choose a signal to use, there are some common signals that are
"used" already.  SIGHUP for server restart, SIGTERM to terminate, SIGINT
and SIGQUIT (keyboard interrupts) should be ignored.  But there are
plenty of others: USR1, USR2 (SIGALRM is likely being used by sleep).
For this, let's assume that we'll use SIGUSR1.

* server (with loop)
signal_seen = 0
def signal_handler(signum, frame):
  global signal_seen
  signal_seen = 1
  do_something_in_the_signal()
signal.signal(signal.SIGUSR1, signal_handler)
while 1:
  signal_seen = 0
  time.sleep(wait_for_a_time)
  if signal_seen:
    continue # go back to sleep
  do_what_needs_to_be_done()
  # it is possible that signal came here, so set variable to zero before
  # sleep

* client
# if the server spawned the client, then use os.getppid, otherwise one
# common convention is to put the server's PID in a file
srvpid = get_server_pid()
...
os.kill(srvpid, signal.SIGUSR1)



Using select with named pipes:
The server creates a named uni-directional pipe to receive messages
from client programs (it could be as simple as a single character).
This is a mechanism that some implementations of UNIX printers use.

* server
def read_pipe(svrpipe):
  msg = svrpipe.readline() # assumes newline-terminated message
  do_something_in_the_signal()
os.mkfifo(ServerPipeFilename, 0600)
try:
  svrpipe = open(ServerPipeFilename, 'r')
  while 1:
    [r, w, e] = select.select([svrpipe], [], [], wait_for_a_time)
    if r:  # we received a notification
      assert(r == [svrpipe])
      read_pipe(svrpipe)
    else:
      do_what_needs_to_be_done()
finally:
  svrpipe.close()
  os.remove(ServerPipeFilename)

* client
# we don't make the named pipe here, if the pipe doesn't exist,
# then the server is not running
svrpipe = open(ServerPipeFilename, 'w')
...
try:
  svrpipe.write(NotificationMsg)
except EnvironmentError, err:
  if err.errno == errno.EPIPE:
    print 'Server closed'
  else:
    raise

The same thing could be done with sockets (UNIX domain or INET); depending
on implementations, you might loose the EPIPE notification in the client.
UNIX domain sockets are more like named pipes (creating a local file)
and are more secure than INET sockets.

The asyncore module can do a lot of this as well; but since a lot of
the work is not within the handlers, I see using asyncore as overkill.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |


From kromag@nsacom.net  Thu May 31 17:02:08 2001
From: kromag@nsacom.net (kromag@nsacom.net)
Date: Thu, 31 May 2001 09:02:08 -0700 (PDT)
Subject: [Tutor] Python syntax highligting with Vim
Message-ID: <200105311602.f4VG28L28735@pop.nsacom.net>

I found the following python.vim file:

syn match   pythonSpecialCharacter      "\['"?\abfnrtv]" contained
syn match   pythonSpecialCharacter      "\(0x)=[0123456789]{1,3}" 
contained
hi link pythonSpecialCharacter        pythonFormat
syn match   pythonFormat                contained "%%"
syn match   pythonFormat                "%(d+$)=[-+' #0*]
*(d*|*|*d+$)(.(d*|*|*d+$))=([hlL]|ll)
=([diuoxXfeEgGcCsSpn]|[^=.[^]]*])" contained
syn match   pythonFormat                "%([^)]+)(d+(.d+)=)=
[sdf]" contained
syn region  pythonString		start=+'+  end=+'+ skip=+\\|\'+ 
contains=pythonFormat,pythonSpecialCharacter
syn region  pythonString		start=+"+  end=+"+ skip=+\\|\"+ 
contains=pythonFormat,pythonSpecialCharacter
syn region  pythonString		start=+"""+  end=+"""+ 
contains=pythonFormat,pythonSpecialCharacter
syn region  pythonString		start=+'''+  end=+'''+ 
contains=pythonFormat,pythonSpecialCharacter

and would like to implement it in gvim under windows. I cannot find any 
documentation on turning on syntax highligting. Can anyone point to a good 
howto?


From dsh8290@rit.edu  Thu May 31 15:26:29 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 31 May 2001 10:26:29 -0400
Subject: [Tutor] Illegal Operation??
In-Reply-To: <01a401c0e9b1$3c528ca0$0200a8c0@ACE>; from wheelege@tsn.cc on Thu, May 31, 2001 at 07:08:18PM +1000
References: <LNBBLJKPBEHFEDALKOLCMEHGKFAA.tim.one@home.com> <01a401c0e9b1$3c528ca0$0200a8c0@ACE>
Message-ID: <20010531102629.E5996@harmony.cs.rit.edu>

On Thu, May 31, 2001 at 07:08:18PM +1000, Glen Wheeler wrote:
| > I'm afraid Tcl/Tk doesn't play nice with threads.  For example, the usual
| > result of trying to run a threaded program under IDLE is also some sort of
| > crash in tcl83.dll.  AFAIK, the only way to get it to work is to write
| your
| > code such that *you* guarantee that the thread in which Tk is first
| invoked
| > is the *only* thread Tk ever gets invoked from or gets called back from.
| > For example, do all your computation in one thread and all your GUI in a
| > different thread.
| >
| 
|   ARGH....seriosuly?  *sneaks a side look at 1200+ line script in question*.
| 
|   Oh dear.  Allow me some time to grieve.
| 
| ...
| 
|   Ok, over it...  So, it should be fine if I keep all the gui stuff in one
| thread...and all the other stuff in other threadS?  I will need more than
| two...and here I was thinking I was finished.
|   Perhaps the lockups aren't random, but where GUI calls are made to
| tcl...hmmm there may be a pattern.  There is a pattern!  Brilliant, now if I
| just grow an extra day, I can get this finished on time.
|   Argh...perhaps two days...why doesn't tcl just work with threads?  :(
| 
|   *gets ready for an all-niter*

It's really not that unusual -- neither GTK+ nor Swing are
thread-safe.  Swing, however, provides 3 methods that are extrememly
useful for threaded applications :

http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/SwingUtilities.html#isEventDispatchThread()

http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable)

http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/SwingUtilities.html#invokeAndWait(java.lang.Runnable)


In Swing there is a thread (named AWTEvent_Queue) that handles all
user interaction.  It is in this thread (or the 'main' thread if a
single-threaded app) that all GUI operations must occur.  (Any
operation on a not-yet-visible and
no-visible-widget-has-a-reference-to-it widget is fine because no
events will happen from the AWTEvent_Queue thread)

The standard Java idiom for allowing threads to interact with swing is
:


Runnable r = new Runnable()
    {
        public void run()
        {
            // this would really contain the code to tinker with the
            // GUI
            System.out.println( "I am tinkering with the GUI now" ) ;
        }
    } ;

if ( javax.swing.SwingUtitilies.isEventDispatchThread() )
{
    r.run() ;
}
else
{
    javax.swing.SwingUtitilies.invokeLater( r ) ;
}



A "Runnable" in Java is like a "callable object" in Python except it
can't return any object.  The SwingUtilities class has synchronized
access to the GUI event thread so it can append any callable
(Runnable) object to the event queue.  When it gets to the front of
the queue it is run by the event thread.  The only problem is if this
code is already in the event dispatch thread -- it will sit in
deadlock waiting until it is finished to continue.  Thus the
isEventDispatchThread() query -- if this is the event thread just run
the code now.

You should be able to create such utility functions for Tkinter and
replace all GUI interaction code with the above blocks (without the
excess braces, etc).

HTH,
-D



From dsh8290@rit.edu  Thu May 31 15:37:28 2001
From: dsh8290@rit.edu (D-Man)
Date: Thu, 31 May 2001 10:37:28 -0400
Subject: [Tutor] Python syntax highligting with Vim
In-Reply-To: <200105311602.f4VG28L28735@pop.nsacom.net>; from kromag@nsacom.net on Thu, May 31, 2001 at 09:02:08AM -0700
References: <200105311602.f4VG28L28735@pop.nsacom.net>
Message-ID: <20010531103728.F5996@harmony.cs.rit.edu>

On Thu, May 31, 2001 at 09:02:08AM -0700, kromag@nsacom.net wrote:
| I found the following python.vim file:
<snip>
| and would like to implement it in gvim under windows. I cannot find any 
| documentation on turning on syntax highligting. Can anyone point to a good 
| howto?

First open a "DOS shell" (unless you have cygwin, which IMO is many
times better).  Then type 
    
    echo %HOME%
    echo %VIM%

In one of those directories you should have a .vimrc or _vimrc file.
Open that file and add the line

    syn on

to it.  That should be all you need to do.  The python.vim syntax file
is included in the (g)vim distribution under the directory
%VIM%\syntax.  As long as you have the environment set properly (%VIM%
and optionally %HOME%) gvim will properly syntax highlight all known
filetypes including python.


I use (at work, at home I use Debian ;-)) cygwin and set %HOME% (aka
$HOME) to my cygwin home directory.  In there I have a .vimrc that
both gvim (win32 build) and vim (console, cygwin build) use.  If you
would like I can send it to you -- it has a lot of customization and
autocommands for various file types.

-D



From Daniel.Kinnaer@Advalvas.be  Thu May 31 17:53:12 2001
From: Daniel.Kinnaer@Advalvas.be (Daniel Kinnaer)
Date: Thu, 31 May 2001 18:53:12 +0200
Subject: [Tutor] Serial Comm in Python on WinNT
Message-ID: <LPBBLJLBPKOAHOOJGJIJGEDNDAAA.Daniel.Kinnaer@Advalvas.be>

Hi,

I've been searching for an Async module which allows me to send/receive data
to/from a terminal like a modem (in a Windows environment).  I suppose that
things are different in a Linux environment, but I would like to learn how
to control the serial port (com1,com2) on a WinNT/Win9x/W2K platform.  Is
there any info available on this topic? All help greatly appreciated.
Thanks.

best regards,

Daniel



From samus@feudalkingdoms.tzo.org  Thu May 31 20:54:29 2001
From: samus@feudalkingdoms.tzo.org (Sam Corder)
Date: Thu, 31 May 2001 19:54:29 +0000
Subject: [Tutor] Serial Comm in Python on WinNT
Message-ID: <E155YYZ-0004Gn-00@mail.python.org>

You can try http://starship.python.net/crew/roger/ He has a module for serial 
communication under Windows. 

-Sam 

Daniel.Kinnaer@Advalvas.be, tutor@python.org wrote:
>
>Hi,
>I've been searching for an Async module which allows me to send/receive data
>to/from a terminal like a modem (in a Windows environment).  I suppose that
>things are different in a Linux environment, but I would like to learn how
>to control the serial port (com1,com2) on a WinNT/Win9x/W2K platform.  Is
>there any info available on this topic? All help greatly appreciated.
>Thanks.
>best regards,
>Daniel
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


From tbrauch@mindless.com  Thu May 31 20:08:26 2001
From: tbrauch@mindless.com (Timothy M. Brauch)
Date: Thu, 31 May 2001 15:08:26 -0400 (EDT)
Subject: [Tutor] IMAP Help
Message-ID: <1064.216.68.187.145.991336106.squirrel@titan.centre.edu>

Okay, this seemed like something I could have done on my own, but I failed 
miserably.  What I want to do is check an IMAP mailbox and see if I have 
any new mail.  If I do, I just want to know, if not, then I want it to 
check again in 15 minutes (or 30, or 60 or whatever).

My problem is in using imaplib.  I can't figure out what I'm suppose to do.

I've tried

Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import imaplib
>>> imaplib.IMAP4('mail.centre.edu')
<imaplib.IMAP4 instance at 00B596FC>
>>> 

But, where do I go from here?  If I can figure out how to do it using 
command line, then I can write a program that will check it.  But, I can't 
figure out what to do on the command line.  I don't want to read the mail 
or get the subject lines (although, that might be a good idea also), I just 
want to know if I have mail.

 - Tim



From NHYTRO@compuserve.com  Thu May 31 21:11:50 2001
From: NHYTRO@compuserve.com (Sharriff Aina)
Date: Thu, 31 May 2001 16:11:50 -0400
Subject: [Tutor] Scripting TK
Message-ID: <200105311612_MC3-D2CE-6803@compuserve.com>

Hi guys! theres a game engine I=B4ve discovered that allows TK scripting,=

could I access this interface also with Python?


regards


Sharriff


From scarblac@pino.selwerd.nl  Thu May 31 21:12:48 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 31 May 2001 22:12:48 +0200
Subject: [Tutor] IMAP Help
In-Reply-To: <1064.216.68.187.145.991336106.squirrel@titan.centre.edu>; from tbrauch@mindless.com on Thu, May 31, 2001 at 03:08:26PM -0400
References: <1064.216.68.187.145.991336106.squirrel@titan.centre.edu>
Message-ID: <20010531221248.A19277@pino.selwerd.nl>

On  0, "Timothy M. Brauch" <tbrauch@mindless.com> wrote:
> Okay, this seemed like something I could have done on my own, but I failed 
> miserably.  What I want to do is check an IMAP mailbox and see if I have 
> any new mail.  If I do, I just want to know, if not, then I want it to 
> check again in 15 minutes (or 30, or 60 or whatever).
> 
> My problem is in using imaplib.  I can't figure out what I'm suppose to do.
> 
> I've tried
> 
> Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> >>> import imaplib
> >>> imaplib.IMAP4('mail.centre.edu')
> <imaplib.IMAP4 instance at 00B596FC>
> >>> 
> 
> But, where do I go from here?  If I can figure out how to do it using 
> command line, then I can write a program that will check it.  But, I can't 
> figure out what to do on the command line.  I don't want to read the mail 
> or get the subject lines (although, that might be a good idea also), I just 
> want to know if I have mail.

You have an IMAP4 object instance, but haven't bound it to a variable so
it's gone again.

Try

>>> x = imaplib.IMAP4("mail.centre.edu")
>>> print x.__doc__

To get some information about the object.

Also, check the library documentation!

IMAP4 objects and their methods are explained in
http://www.python.org/doc/current/lib/imap4-objects.html

And there is a tiny example in
http://www.python.org/doc/current/lib/imap4-example.html

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Thu May 31 21:14:48 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 31 May 2001 22:14:48 +0200
Subject: [Tutor] Scripting TK
In-Reply-To: <200105311612_MC3-D2CE-6803@compuserve.com>; from NHYTRO@compuserve.com on Thu, May 31, 2001 at 04:11:50PM -0400
References: <200105311612_MC3-D2CE-6803@compuserve.com>
Message-ID: <20010531221448.B19277@pino.selwerd.nl>

On  0, Sharriff Aina <NHYTRO@compuserve.com> wrote:
> Hi guys! theres a game engine I´ve discovered that allows TK scripting,
> could I access this interface also with Python?

I think you mean Tcl scripting (TK is the GUI library of Tcl, originally).

Just that you can control it with Tcl scripts doesn't mean you can control
it with Python, unfortunately. They're different languages, the game needs
support for Python.

-- 
Remco Gerlich


From kent@springfed.com  Thu May 31 22:58:55 2001
From: kent@springfed.com (Kent Tenney)
Date: Thu, 31 May 2001 16:58:55 -0500
Subject: [Tutor] Is there any kind of Python group scheduling product
Message-ID: <200105312159.OAA05605@svc1.netwk-innov.net>

Howdy,

I need to facilitate meetings, and would like
to use a Python app.

Know of any?

Thanks,
Kent
-- Kent Tenney, kent@springfed.com on 05/31/2001



From scarblac@pino.selwerd.nl  Thu May 31 23:14:46 2001
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Fri, 1 Jun 2001 00:14:46 +0200
Subject: [Tutor] Is there any kind of Python group scheduling product
In-Reply-To: <200105312159.OAA05605@svc1.netwk-innov.net>; from kent@springfed.com on Thu, May 31, 2001 at 04:58:55PM -0500
References: <200105312159.OAA05605@svc1.netwk-innov.net>
Message-ID: <20010601001446.A19597@pino.selwerd.nl>

On  0, Kent Tenney <kent@springfed.com> wrote:
> I need to facilitate meetings, and would like
> to use a Python app.
> 
> Know of any?

Go to the Vaults of Parnassus (Python resources) at
http://www.vex.net/parnassus/ and search for 'groupware'.

Amphora / Amphora light may be what you need, or overkill.

Apart from those, I don't know any existing apps.

-- 
Remco Gerlich


From steve.tran@nts-inc.com  Thu May 31 00:53:34 2001
From: steve.tran@nts-inc.com (steve tran)
Date: Wed, 30 May 2001 16:53:34 -0700
Subject: [Tutor] [Fwd: [Python-Help] Dos command line]
Message-ID: <3B1587FE.CCA19B58@nts-inc.com>

This is a multi-part message in MIME format.
--------------510B1D9849FE1A144BA26F23
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

Can I have an example for os.open to run dos comand line or batch file?

thanks,

Steve

--------------510B1D9849FE1A144BA26F23
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Received: from hkn.EECS.Berkeley.EDU ([128.32.138.117]) by kerberos2.sie-inc.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13)
	id JQSRS83M; Thu, 31 May 2001 16:08:55 -0700
Received: from localhost (dyoo@localhost)
	by hkn.eecs.berkeley.edu (8.9.3/8.9.3) with ESMTP id PAA31991;
	Thu, 31 May 2001 15:55:11 -0700
Date: Thu, 31 May 2001 15:55:11 -0700 (PDT)
From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
To: steve tran <steve.tran@nts-inc.com>
cc: help@python.org
Subject: Re: [Python-Help] Dos command line
In-Reply-To: <3B157A05.A3B055B0@nts-inc.com>
Message-ID: <Pine.LNX.4.21.0105311549430.31586-100000@hkn.eecs.berkeley.edu>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Mozilla-Status2: 00000000

On Wed, 30 May 2001, steve tran wrote:

> How can I run or execute dos command line or batch file in Python?

You can use the os.system() or os.popen() commands.  Here's the reference
material for os.system():

"""
system(command)

Execute the command (a string) in a subshell. This is implemented by
calling the Standard C function system(), and has the same limitations.
Changes to posix.environ, sys.stdin, etc. are not reflected in the
environment of the executed command. The return value is the exit status
of the process encoded in the format specified for wait(), except on
Windows 95 and 98, where it is always 0. Note that POSIX does not specify
the meaning of the return value of the C system() function, so the return
value of the Python function is system-dependent. Availability: Unix,
Windows.
"""
    http://python.org/doc/current/lib/os-process.html

So you can do this, for example:

###
import os
os.system('dir')
###


For more fine-grained control, you'll want os.popen(), which is explained
here:

    http://python.org/doc/current/lib/os-newstreams.html


The reference material is a little terse though; play around with it a
bit, and if you have questions, feel free to email us again.  Also,
there's a beginner's mailing list called tutor@python.org, so if you want
to talk with other Python learners, you can subscribe to the mailing list
here:

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

--------------510B1D9849FE1A144BA26F23--