Re: [Tutor] console text positioning

2005-11-13 Thread Alan Gauld
>  ANSI is the standard for terminal control, so I usually code for
>  that, but put it in a separate module so that other terminals can
>  easily be accommodated.

It certainly used to be under MS DOS but I find very few windows 
machines set up to use ANSI codes. Do you know any way to set 
ANSI controls under wIndows (that doesn't require a reboot ideally!)

ISTR it involved putting the line 

DISPLAY=ANSI

in the Config.sys file.
Does that still work under XP?  I suppose it should...

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



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


Re: [Tutor] Symbolic maths In Python

2005-11-13 Thread Matt Williams
I don't know if this will do anywhere near what you want...

http://swiginac.berlios.de/

is a set of Python bindings to GiNaC, which handles symbolic maths in
C/C++.

Matt

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


Re: [Tutor] problem calling a function

2005-11-13 Thread Roel Schroeven
Vincent Wan wrote:
> Dear all,
> 
> I have a simple program that calls a function I got off of active  
> state that draws
> a tree given a description of it in standard string form.
> 
> My code generates a string description and calls the function to draw  
> the tree.
> Instead of drawing the tree it echos the string. But when I call the  
> function
> interactively with the same string it prints the tree! Why dosn't it  
> work non-interactivly
> 
> here is my IDLE run
> 
> '0','9'),('4','6')),'2'),(('1',(('5','8'),'7')),'3'))
> '0','9'),('4','6')),'2'),(('1',(('5','8'),'7')),'3')) --
> 
>  >>> printDendrogram('0','9'),('4','6')),'2'),(('1', 
> (('5','8'),'7')),'3')))

printDendrogram accepts tuples, not strings:

>>> printDendrogram(((1, 2), (3, 4)))
1 --+
|--+
2 --+  |
   |--
3 --+  |
|--+
4 --+
>>> printDendrogram("((1, 2), (3, 4))")
((1, 2), (3, 4)) --

You'll have to modify your code so that it creates a tuple instead of a
string. I made it work by changing

printDendrogram(tree)

to

printDendrogram(eval(tree))

at the end of your code, but that's just a quick hack, not the
recommended way of doing things.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

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


Re: [Tutor] Seeking PYTHON Mentor

2005-11-13 Thread Kent Johnson
mike donato wrote:
> I believe in academic honesty and so I am not inclining to cheating  just 
> seeking support for the given language so I may develop the fundamental 
> skills to work thru the excercises.
> 
> Any assistance which can be provided will be greatly appreciated.

Ask questions here on the list. The best questions show what you have tried so 
far so we can see where you are having trouble and help you with the next step.

Did you find a tutorial you like? There is one that comes with Python when you 
download it and many others linked here:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers?highlight=%28BeginnersGuide%2F%29

Kent
-- 
http://www.kentsjohnson.com

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


Re: [Tutor] problem calling a function

2005-11-13 Thread Roel Schroeven
Roel Schroeven wrote:
> 
> You'll have to modify your code so that it creates a tuple instead of a
> string.

It seems that doing it without using a string complicates matters, or at
least increases the line count. I tried it with a list, since you can't
build a tuple on the go since tuples are immutable, but that didn't work
out very well so I created a tree with nodes to store the branches:

class Tree(object):
class Node(object):
def __init__(self, linage, left=None, right=None):
self.linage = linage
self.left = left
self.right = right
def AsTuple(self):
if self.left and self.right:
return self.left.AsTuple(), self.right.AsTuple()
else:
return self.linage
def __init__(self, rootlinage):
self.rootnode = Tree.Node(rootlinage)
self.linagetonode = {rootlinage: self.rootnode}
def AddBranch(self, linage, newlinage):
node = self.linagetonode[linage]
left = Tree.Node(linage)
right = Tree.Node(newlinage)
node.left = left
node.right = right
self.linagetonode[linage] = left
self.linagetonode[newlinage] = right
def AsTuple(self):
return self.rootnode.AsTuple()

In this data structure the nodes are stored as a tree, but are also
accessible via the linage values. Branching is done by looking up the
node via the linage and creating appropriate left and right children.
Creating the tuple for printing the dendrogram can be done via simple
recursion.

I initialize the tree (both at the beginning and when restarting) by doing:

tree = Tree('0')

Branching becomes:

next_linage += 1
linages.append(next_linage)
print 'At ', time,' linage ', linages[i], 'evolved', next_linage
tree.AddBranch(str(linages[i]), str(next_linage))
num_linages += 1
if num_linages == 10: break

Printing the tree:

printDendrogram(tree.AsTuple())



The whole program:

# Thesis_ex_gen6.py

import random

# constants that control the simulation
MAX_LINAGES = 10
BRANCHING_PROBABILITY = 0.01
EXTINCTION_PROBABILITY = 0.01

def printDendrogram(T, sep=3):

 """Print dendrogram of a binary tree.  Each tree node is
represented by a length-2 tuple.
routine written by David Eppstein from ActiveState Programers
Network Last Updated: 2002/07/13"""

 def isPair(T):
 return type(T) == tuple and len(T) == 2

 def maxHeight(T):
 if isPair(T):
 h = max(maxHeight(T[0]), maxHeight(T[1]))
 else:
 h = len(str(T))
 return h + sep

 activeLevels = {}

 def traverse(T, h, isFirst):
 if isPair(T):
 traverse(T[0], h-sep, 1)
 s = [' ']*(h-sep)
 s.append('|')
 else:
 s = list(str(T))
 s.append(' ')

 while len(s) < h:
 s.append('-')

 if (isFirst >= 0):
 s.append('+')
 if isFirst:
 activeLevels[h] = 1
 else:
 del activeLevels[h]

 A = list(activeLevels)
 A.sort()
 for L in A:
 if len(s) < L:
 while len(s) < L:
 s.append(' ')
 s.append('|')

 print ''.join(s)

 if isPair(T):
 traverse(T[1], h-sep, 0)

 traverse(T, maxHeight(T), -1)


if __name__ == '__main__':
for x in range(1):

print '\n','run ',  x+1, '\n'

class Tree(object):
class Node(object):
def __init__(self, linage, left=None, right=None):
self.linage = linage
self.left = left
self.right = right
def AsTuple(self):
if self.left and self.right:
return self.left.AsTuple(), self.right.AsTuple()
else:
return self.linage
def __init__(self, rootlinage):
self.rootnode = Tree.Node(rootlinage)
self.linagetonode = {rootlinage: self.rootnode}
def AddBranch(self, linage, newlinage):
node = self.linagetonode[linage]
left = Tree.Node(linage)
right = Tree.Node(newlinage)
node.left = left
node.right = right
self.linagetonode[linage] = left
self.linagetonode[newlinage] = right
def AsTuple(self):
return self.rootnode.AsTuple()


next_linage = 0# next counter initalized
linages = [0]# linages initalized
num_linages = 1# total linage counter initalized

Re: [Tutor] Seeking PYTHON Mentor

2005-11-13 Thread Alan Gauld
Hi Mike,

> Greetings, I am an Information Technology student and am seeking a mentor 
> for the Python Language.

Treat this mailing list as a virtual mentor.

We will take questions either theoretical, conceptual or practical.
Tell us what you need help with, tell us what you've done to try to
solve it yourself and we will point you in the right direction to find
the answer. If the question involves code post the problem code
and any error dumps you get.

We don't normally do one-on-one mentoring because that way only
one person benefits, on a list everyone gets answers - even to questions
they might not have thought of asking! :-) And you get the benefit of
many viewpoints and many, many years of accumulated experience.

Enjoy,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread Tim Johnson
* Kent Johnson <[EMAIL PROTECTED]> [051112 20:33]:
> Tim Johnson wrote:
> >I need to get up to speed on iterators. I learned python 1.5~ via
> >Alan G's book ...
> >For an example, I've written a subclass of dict where keys are kept in
> >a ordered fashion is a list called __keys:
> >
> >#Here is my items function:
> >def items(self):
> >""" Return all pairs in order of addition"""
> >return [(key,self.__dict[key]) for key in self.__keys]
> >
> >#And here is my iteritems function (currently does exactly the same thing)
> >def iteritems(self):
> >""" At this implementation, does exactly the same thing as 
> >method items()"""
> >for key in self.__keys:
> >yield (key,self.__dict[key])
 
  Ah. I did it right without know what I was doing. 
  Now if I assign a value to the iteritems method, as in 
  it = s.iteritems()
  I get an object of 
  and dir(it) shows that (it) has one public method - next().

  Question: Can one subclass an iterator object?
  thanks for making this a little clearer.
  
  tim
  
> I think you have it right. Your two methods don't do the same thing - 
> items() returns a list of key, value pairs; iteritems() returns a generator 
> which yields key, value pairs. This is the correct behaviour.
> 
> Kent
> -- 
> http://www.kentsjohnson.com

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread Kent Johnson
Tim Johnson wrote:
>   Question: Can one subclass an iterator object?
>   thanks for making this a little clearer.

Most *classes* can be subclassed. What do you have in mind?

-- 
http://www.kentsjohnson.com

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


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread John Fouhy
On 14/11/05, Tim Johnson <[EMAIL PROTECTED]> wrote:
>   Now if I assign a value to the iteritems method, as in
>   it = s.iteritems()
>   I get an object of 
>   and dir(it) shows that (it) has one public method - next().

Yep.  The normal way to use an iterator is in a for loop.

So, if you've done 'it = s.iteritems()', you can then do:

for key, value in it:
# do something with key, value

Of course, normally you would cut out the assignment step:

for key, value in s.iteritems():
# do something with key, value

When dealing with an iterator, a for loop is basically equivalent to this:

it = s.iteritems()
while True:
  try:
key, value = it.next()
  except StopIteration:
break
  # do something with key, value

HTH!

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


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread Tim Johnson
* John Fouhy <[EMAIL PROTECTED]> [051113 12:16]:
> On 14/11/05, Tim Johnson <[EMAIL PROTECTED]> wrote:
> >   Now if I assign a value to the iteritems method, as in
> >   it = s.iteritems()
> >   I get an object of 
> >   and dir(it) shows that (it) has one public method - next().
> 
> Yep.  The normal way to use an iterator is in a for loop.
 
  As soon as I saw the next() method, I recognized it from
  using a csv module ..


> So, if you've done 'it = s.iteritems()', you can then do:
> 
> for key, value in it:
> # do something with key, value
> 
> Of course, normally you would cut out the assignment step:
> 
> for key, value in s.iteritems():
> # do something with key, value
> 
> When dealing with an iterator, a for loop is basically equivalent to this:
> 
> it = s.iteritems()
> while True:
>   try:
> key, value = it.next()
>   except StopIteration:
> break
>   # do something with key, value
> 
> HTH!
> 
> --
> John.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread Tim Johnson
* Kent Johnson <[EMAIL PROTECTED]> [051113 12:04]:
> Tim Johnson wrote:
> >   Question: Can one subclass an iterator object?
> >   thanks for making this a little clearer.
> 
> Most *classes* can be subclassed. What do you have in mind?
 
  Oh, I'm just playing right now  but what is the
  iterator object class name?
  thnx
  tj
  
> -- 
> http://www.kentsjohnson.com
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread Liam Clarke-Hutchinson
Someone correct me if I'm wrong, but I believe there is no specific iterator
object, but rather objects that have a method for __iter___...

Liam Clarke-Hutchinson

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tim
Johnson
Sent: Monday, 14 November 2005 10:37 a.m.
To: tutor@python.org
Subject: Re: [Tutor] iteritems() vs items()


* Kent Johnson <[EMAIL PROTECTED]> [051113 12:04]:
> Tim Johnson wrote:
> >   Question: Can one subclass an iterator object?
> >   thanks for making this a little clearer.
> 
> Most *classes* can be subclassed. What do you have in mind?
 
  Oh, I'm just playing right now  but what is the
  iterator object class name?
  thnx
  tj
  
> --
> http://www.kentsjohnson.com
> 
> ___
> Tutor maillist  -  Tutor@python.org 
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

A new monthly electronic newsletter covering all aspects of MED's work is now 
available.  Subscribers can choose to receive news from any or all of seven 
categories, free of charge: Growth and Innovation, Strategic Directions, Energy 
and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government 
services

Any opinions expressed in this message are not necessarily those of the 
Ministry of Economic Development. This message and any files transmitted with 
it are confidential and solely for the use of the intended recipient. If you 
are not the intended recipient or the person responsible for delivery to the 
intended recipient, be advised that you have received this message in error and 
that any use is strictly prohibited. Please contact the sender and delete the 
message and any attachment from your computer.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread Tim Johnson
* Liam Clarke-Hutchinson <[EMAIL PROTECTED]> [051113 12:41]:
> Someone correct me if I'm wrong, but I believe there is no specific iterator
> object, but rather objects that have a method for __iter___...
 
  Some light is slowly dawning here (I think)  from 
  http://docs.python.org/ref/yield.html

  It appears that a generator, is an object, but
  not derived from a class, but from a generator function,
  using yield.

> Liam Clarke-Hutchinson
> 
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Tim
> Johnson
> Sent: Monday, 14 November 2005 10:37 a.m.
> To: tutor@python.org
> Subject: Re: [Tutor] iteritems() vs items()
> 
> 
> * Kent Johnson <[EMAIL PROTECTED]> [051113 12:04]:
> > Tim Johnson wrote:
> > >   Question: Can one subclass an iterator object?
> > >   thanks for making this a little clearer.
> > 
> > Most *classes* can be subclassed. What do you have in mind?
>  
>   Oh, I'm just playing right now  but what is the
>   iterator object class name?
>   thnx
>   tj
>   
> > --
> > http://www.kentsjohnson.com
> > 
> > ___
> > Tutor maillist  -  Tutor@python.org 
> > http://mail.python.org/mailman/listinfo/tutor
> 
> -- 
> Tim Johnson <[EMAIL PROTECTED]>
>   http://www.alaska-internet-solutions.com
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> A new monthly electronic newsletter covering all aspects of MED's work is now 
> available.  Subscribers can choose to receive news from any or all of seven 
> categories, free of charge: Growth and Innovation, Strategic Directions, 
> Energy and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
> http://news.business.govt.nz for more details.
> 
> 
> 
> 
> http://www.govt.nz - connecting you to New Zealand central & local government 
> services
> 
> Any opinions expressed in this message are not necessarily those of the 
> Ministry of Economic Development. This message and any files transmitted with 
> it are confidential and solely for the use of the intended recipient. If you 
> are not the intended recipient or the person responsible for delivery to the 
> intended recipient, be advised that you have received this message in error 
> and that any use is strictly prohibited. Please contact the sender and delete 
> the message and any attachment from your computer.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread Kent Johnson
Tim Johnson wrote:
> * Liam Clarke-Hutchinson <[EMAIL PROTECTED]> [051113 12:41]:
> 
>>Someone correct me if I'm wrong, but I believe there is no specific iterator
>>object, but rather objects that have a method for __iter___...
> 
>  
>   Some light is slowly dawning here (I think)  from 
>   http://docs.python.org/ref/yield.html
> 
>   It appears that a generator, is an object, but
>   not derived from a class, but from a generator function,
>   using yield.

I would say it is an object of a built-in class created by calling a generator 
function, which is a function that uses yield.

You can create your own iterators by defining a class that defines the special 
methods __iter__() and next(). __iter__ just returs self, and next() returns 
the next item in the iteration or raises StopIteration. See
http://docs.python.org/lib/typeiter.html

Generators provide a convenient short-cut for creating many kinds of iterators 
because generator state is maintained implicitly. For example, a class for 
iterators that count from 1 to 10 might look like this:

class counter:
  def __init__(self):
self.count = 0
  def __iter__(self):
return self
  def next(self):
if self.count < 10:
  self.count += 1
  return self.count
raise StopIteration

The equivalent generator function could be

def counter():
  for count in range(1, 11):
yield count

or, maybe a fairer comparison would be

def counter():
  count = 0
  if count < 10:
count += 1
yield count

which is still much shorter and easier to understand than the class version. 
Usage of all three is identical:

for i in counter():
  print i

Kent

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


Re: [Tutor] iteritems() vs items()

2005-11-13 Thread Tim Johnson
Well put. Got it.
Thanks Kent
tj

* Kent Johnson <[EMAIL PROTECTED]> [051113 14:44]:
> Tim Johnson wrote:
> > * Liam Clarke-Hutchinson <[EMAIL PROTECTED]> [051113 12:41]:
> > 
> >>Someone correct me if I'm wrong, but I believe there is no specific iterator
> >>object, but rather objects that have a method for __iter___...
> > 
> >  
> >   Some light is slowly dawning here (I think)  from 
> >   http://docs.python.org/ref/yield.html
> > 
> >   It appears that a generator, is an object, but
> >   not derived from a class, but from a generator function,
> >   using yield.
> 
> I would say it is an object of a built-in class created by calling a 
> generator function, which is a function that uses yield.
> 
> You can create your own iterators by defining a class that defines the 
> special methods __iter__() and next(). __iter__ just returs self, and next() 
> returns the next item in the iteration or raises StopIteration. See
> http://docs.python.org/lib/typeiter.html
> 
> Generators provide a convenient short-cut for creating many kinds of 
> iterators because generator state is maintained implicitly. For example, a 
> class for iterators that count from 1 to 10 might look like this:
> 
> class counter:
>   def __init__(self):
> self.count = 0
>   def __iter__(self):
> return self
>   def next(self):
> if self.count < 10:
>   self.count += 1
>   return self.count
> raise StopIteration
> 
> The equivalent generator function could be
> 
> def counter():
>   for count in range(1, 11):
> yield count
> 
> or, maybe a fairer comparison would be
> 
> def counter():
>   count = 0
>   if count < 10:
> count += 1
> yield count
> 
> which is still much shorter and easier to understand than the class version. 
> Usage of all three is identical:
> 
> for i in counter():
>   print i
> 
> Kent
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Converting a List/Tuple to delimited string

2005-11-13 Thread Roy Bleasdale
I have a list of strings and wanted to output them as a single delimited 
string.

Eg

('ab','cd','ef') becomes "ab:cd:ef"

My first attempt was to do it as a function:

def Addsomething(a):
y = []
for x in a:
y.append( x + ':')
return "".join(y)

I then converted the this to a lambda function and mapped it.

"".join(map((lambda x: x + ":"),L))



And this works just fine

BUT

This somehow seems a little incongruous for Python and wondered if there 
was a simpler, more stylish way of achieving this.

Are there any suggestions or is my solution good enough?

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


Re: [Tutor] Converting a List/Tuple to delimited string

2005-11-13 Thread John Fouhy
On 14/11/05, Roy Bleasdale <[EMAIL PROTECTED]> wrote:
> I have a list of strings and wanted to output them as a single delimited
> string.
>
> Eg
>
> ('ab','cd','ef') becomes "ab:cd:ef"

You almost had it ...

What about:

>>> lst = ['ab', 'cd', 'ef']
>>> ':'.join(lst)
'ab:cd:ef'

In general, foo.join(lst) (where foo is a string) is equivalent to:

def join(foo, lst):
  if not lst:
  return ''
  s = lst[0]
  for item in lst[1:]:
  s += foo + item
  return s

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


[Tutor] problem calling a function

2005-11-13 Thread Vincent Wan
Thank you Roel Schroeven

I don't know how I missed the fact that the printDendrogram function  
needs tuples not strings.
I didn't recognize that my string was a tuple so I didn't realize  
that when I pasted it interactively
in IDEL I was allowing python to change the type.

eval() changes the type from string to tuple. But, to my surprise  
tuple() does not yeild the tuple that
is represented by the string but a tuple representation of the string.

If eval() does convert correctly why not use it? The string will  
always be a valid tuple.

Thank you for you elegant tree based representation. I'm sure I'll  
need help when it comes
to adding support for more that two nodes. Of course, I'll also have  
to modify the drawing code.

Thank you, thank you

Vincent

 
--
PhD Candidate
Committee on the Conceptual and Historical Studies of Science
University of Chicago

PO Box 73727
Fairbanks, AK 99707

wan AT walrus DOT us (change CAPS to @ and . )

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


[Tutor] Looking for suggestions

2005-11-13 Thread ->Terry<-
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


I have written a small peg game using Pygame.
This is the first working version. I have a
request and a couple of perhaps silly questions.

To anyone willing to take the time to have a
look at the code and offer any advice or
suggestions, I would be much appreciative.
I'm looking for code suggestions rather than
game-play suggestions, although I'm open to
any help.

I haven't got my head really wrapped around the
OO stuff, so I'm thinking rewriting it using
classes would make a good project to learn
with. Is this the sort of thing that one would
use classes for? Or is is better left as
simple as possible?

Now here is the perhaps silly question. Is
something like this need to have a license?
What I mean is, as I play with and improve
this game and want to share it with others,
should I choose a license and add the legal
stuff with the distributed product?

I have learned so much reading this list. I
hope I've asked my questions right.

The game appears to also work on Windows also,
but does require you to have Pygame installed.
It was written on Slackware with Python 2.4.1

The code:

http://members.socket.net/~tvbare/pypeg/pypeg.py>

And the images:

http://members.socket.net/~tvbare/pypeg/board.png>
http://members.socket.net/~tvbare/pypeg/peg.png>

Cheers,
- -- 
 Terry


"Be who you are and say what you feel, because those
  who mind don't matter and those who matter don't mind."
  -- Dr. Seuss
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFDeCyyQvSnsfFzkV0RAqnBAJ9TEwpP7gmUPt06ZWCS/vUJ9lLSXACbBhFl
NxIKZYKxi4OK9vR13HYP7IA=
=gYkg
-END PGP SIGNATURE-

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


[Tutor] Another Quick Question

2005-11-13 Thread Steve Haley








Folks,

 

I’m one of the people new to Python who has started
going through a beginner’s book to learn the basics of the language (“Python
Programming for the Absolute Beginner”).  In the second chapter the
author (Michael Dawson) illustrates the use of escape sequences with, among
other things, the “\a” to sound the system bell.  However, when I
run the little program myself, the program runs but I get no sound – all is
get is the word BEL in while letters on a blue background.  I’ve turned
the volume up all the way and still no sound.  I know the speakers on my laptop
work because I just finished my daily session trying to learn a little Spanish
which involves sound.

 

I went to the language reference which also seems to
indicate I should get a sound with exactly what the author is saying.  The
exact line is:

 

print “\a”

 

I’m not sure why but this kind of thing bothers me. 
Can anyone suggest why my laptop won’t produce a bell?  Does the fact
that I’m running version 2.1 have something to do with it?  Does my
laptop have something against me and just doesn’t want to ring its bell
for me? (just kidding with that last one)

 

Thanks in advance.

Steve

 






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


Re: [Tutor] problem calling a function

2005-11-13 Thread Danny Yoo


> eval() changes the type from string to tuple. But, to my surprise
> tuple() does not yeild the tuple that is represented by the string but a
> tuple representation of the string.
>
> If eval() does convert correctly why not use it? The string will always
> be a valid tuple.

Hi Vincent,

Alternative question: can your program just pass the tuple itself to the
function, or does it always have to turn things into strings?  Your code
in:

   http://mail.python.org/pipermail/tutor/2005-November/043208.html

constructs a string that represents a tree near the bottom of the code.
But can you modify it to construct the data structure that represents that
tree?  I haven't read the code too closely yet, but it looks like it's
doing too much working in building a string representation.


Take a look again at Roel Schroven's code in:

http://mail.python.org/pipermail/tutor/2005-November/043214.html

Does the approach there make sense to you?  If that code is complex, we
could probably simplify that code to expose the core idea more clearly.
The core idea is to use real, enriched data structures: you don't have to
treat everything as an anemic string.


eval() is a dangerous function and almost always never appropriate as a
data-structure parser.  It does much more than just value conversion.
We've written about this a week ago:

http://mail.python.org/pipermail/tutor/2005-November/042838.html
http://mail.python.org/pipermail/tutor/2005-November/042854.html

so eva() is obviously the seductive solution, but it's wrong here.
*grin*



Hope this helps!


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


Re: [Tutor] Another Quick Question

2005-11-13 Thread Johan Geldenhuys




Could this be a OS thing?
I use Linux and it works here.

Steve Haley wrote:

  
  
  
  
  Folks,
   
  I’m one of the people new
to Python who has started
going through a beginner’s book to learn the basics of the language
(“Python
Programming for the Absolute Beginner”).  In the second chapter the
author (Michael Dawson) illustrates the use of escape sequences with,
among
other things, the “\a” to sound the system bell.  However, when I
run the little program myself, the program runs but I get no sound –
all is
get is the word BEL in while letters on a blue background.  I’ve turned
the volume up all the way and still no sound.  I know the speakers on
my laptop
work because I just finished my daily session trying to learn a little
Spanish
which involves sound.
   
  I went to the language
reference which also seems to
indicate I should get a sound with exactly what the author is saying. 
The
exact line is:
   
  print “\a”
   
  I’m not sure why but this
kind of thing bothers me. 
Can anyone suggest why my laptop won’t produce a bell?  Does the fact
that I’m running version 2.1 have something to do with it?  Does my
laptop have something against me and just doesn’t want to ring its bell
for me? (just kidding with that last one)
   
  Thanks in advance.
  Steve
   
  
  

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



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


Re: [Tutor] Another Quick Question

2005-11-13 Thread Pujo Aji
I use windows, it works for meHave checked your sound card, volume before trying the code?pujoOn 11/14/05, Johan Geldenhuys <
[EMAIL PROTECTED]> wrote:


  
  


Could this be a OS thing?
I use Linux and it works here.

Steve Haley wrote:

  
  
  
  
  Folks,
   
  I'm one of the people new
to Python who has started
going through a beginner's book to learn the basics of the language
("Python
Programming for the Absolute Beginner").  In the second chapter the
author (Michael Dawson) illustrates the use of escape sequences with,
among
other things, the "\a" to sound the system bell.  However, when I
run the little program myself, the program runs but I get no sound –
all is
get is the word BEL in while letters on a blue background.  I've turned
the volume up all the way and still no sound.  I know the speakers on
my laptop
work because I just finished my daily session trying to learn a little
Spanish
which involves sound.
   
  I went to the language
reference which also seems to
indicate I should get a sound with exactly what the author is saying. 
The
exact line is:
   
  print "\a"
   
  I'm not sure why but this
kind of thing bothers me. 
Can anyone suggest why my laptop won't produce a bell?  Does the fact
that I'm running version 2.1 have something to do with it?  Does my
laptop have something against me and just doesn't want to ring its bell
for me? (just kidding with that last one)
   
  Thanks in advance.
  Steve
   
  
  
___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  




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