[Tutor] Re: Presentation

2005-02-01 Thread Wolfram Kraus
Paul Hartley wrote:
[...]
When I was a member of the Forth Interest Group in the USA we learned
that Forth was used on the buggy that went to mars, that it started
life controlling huge radio telescopes which only had 4k (yes 4k) of
memory for both language and application.
Well, the rover used Forth, but the rover-website is Plone powered:
http://plone.org/newsitems/mars-rover
Plone is a CMS built on top of Zope, which itself is Python powered. For 
more sites running plone see: http://plone.org/about/sites/

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


Re: [Tutor] Better structure?

2005-02-01 Thread Danny Yoo


On Mon, 31 Jan 2005, Jacob S. wrote:

> BTW, it was a few months ago, not days... but the thought still counts.
> At least you remember.


Hi Jacob,

Wait, was it really a few months ago?  Let me check the archive...

http://mail.python.org/pipermail/tutor/2004-December/033728.html

You're right.  Wow, I'm getting that much more senile by the minute.


> I was getting stumped by the difference in comparing y The check for
> seeing what the first word is made me slamp my forehead...

I'm glad that you enjoyed one of those "ah ha!" moments.  *grin* If you
ever get the chance, you may want to take a look at a book called
Programming Pearls:

http://www.cs.bell-labs.com/cm/cs/pearls/

for a few more examples of "ah ha!" moments of enlightenment.


As a side note: it's possible to do the same sort of thing that we did in
the last post --- with class instances --- but it's slightly more
heavyweight compared to using first-class function values.  Let's see what
that looks like, just for comparison.


The following variant will probably feel more comfortable to Java
programmers: here's a sketch of how we can do this dispatch technique with
classes instead of first-class functions:


##
class Command(object):
def execute(self, args):
raise NotImplementedError

class ClearCommand(Command):
def execute(self, args):
...

class QuitCommand(Command):
def execute(self, args):
...

...

commandDispatchTable = { 'clear' : ClearCommand(),
 'quit' : QuitCommand(),
 ...
   }

def evaluate(line):
   """Evaluates the line."""
   pieces = line.split()
   cmd, rest = pieces[0], pieces[1:]
   if cmd in commandDispatchTable:
   dispatchTable[cmd].execute(rest)
   elif isAssignment(line):
   ...
   else:
   ...
##


It's the same general idea.  But just more typing.  *grin*


An advantage of using the class approach is that it is easy to extend the
commands to respond to different methods besides direct execution.  For
example, we might want to add a "help()" Command that provides a
functionality similar to the one provided by the builtin Python help()
function.  If each of the Commands implements a help() method, then we can
do something like:

###
class Command(object):
def execute(self, args):
raise NotImplementedError

def help(self):
return self.__doc__


class HelpCommand(Command):
"""Displays help for a command.
Syntax: help [command name].
Example Usage: help clear
"""

def getHelpString(self, commandName):
if commandName in dispatchTable:
return dispatchTable[commandName].help()
else:
return "Unknown command."

def execute(self, args):
if not args:
commandName = 'help'
else:
commandName = args[0]
print "help on %r: %s" % (commandName,
  self.getHelpString(commandName))
###

We can get more complicated from here.  I'm not sure if this help()
Command is a good idea, but it's an option.


And perhaps not coincidently, if we look at your program's structure again
now, we might notice that it's gradually looking more and more like an
interpreter.  *grin*


Best of wishes to you!

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


Re: [Tutor] Presentation

2005-02-01 Thread Kent Johnson
Eric Raymond's "Why Python?" essay is a classic:
http://pythonology.org/success&story=esr
Bruce Eckel's "Why I love Python" presentation is here:
http://64.78.49.204/pub/eckel/LovePython.zip
This page has lots of links you might be interested in:
http://www.ferg.org/python_presentations/index.html
This page has links to language comparisons:
http://www.python.org/moin/LanguageComparisons
Good luck!
Kent
Paul Hartley wrote:
I am trying to get Python established here in the Philippines. Currently 
I am in charge of operations at a business based in Manila and I have 
asked my IT staff to start using Python (with some success).
 
A local university has now asked that I give a talk to their IT people 
on Python - so here is an opportunity to spread the word and get some 
more converts and maybe introduce python into their computer science 
courses.
 
Any help I can get would be much appreciated - such as language 
comparisons, companies and systems that use python, debates about what 
python is good for (almost everything), examples of elegant code..
 
When I was a member of the Forth Interest Group in the USA we learned 
that Forth was used on the buggy that went to mars, that it started life 
controlling huge radio telescopes which only had 4k (yes 4k) of memory 
for both language and application.
 
Anything like the above concerning python would be useful.
 
Any other suggestions would help also, the audience will have computers, 
so a demonstration of small workshop would also be good - the 
presentation/session is for 4 hours on the 10th February.
 
Paul
 


___
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] Better structure?

2005-02-01 Thread Kent Johnson
Danny Yoo wrote:
On Mon, 31 Jan 2005, Jacob S. wrote:
### Pseudocode
commandDispatchTable = {'clear'  :  clearCommand
'quit'   :  quitCommand
'remove' :  removeCommand
'return' :  returnCommand
'gatl'   :  gatlCommand
'ganl'   :  ganlCommand
'gotl'   :  gotlCommand
'gonl'   :  gonlCommand
'getpt'  :  getplCommand
'regraph':  regraphCommand
def evaluate(line):
"""Evaluates the line."""
pieces = line.split()
cmd, rest = pieces[0], pieces[1:]
if cmd in commandDispatchTable:
dispatchTable[cmd](rest)
elif isAssignment(line):
...
else:
...
###
The evaluate() function tries to handle the common-case stuff with a
dispatch-table method, and otherwise follows up with special-case stuff to
handle the rest of the case analysis.
Jacob, if you like this you might want to look into the cmd module, it supports dispatching on the 
first word of a command with support for help, etc.

step2 = float(y.lstrip("gatl "))
x = float(y.lstrip('gotl '))
x = float(y.lstrip('gonl '))
y = y.lstrip("getpt ")
This code is broken. lstrip('gonl ') will remove *all* leading g, o, n, l 
and space, in any order:
 >>> s='go long on log buddy!'
 >>> s.lstrip('gonl ')
'buddy!'
Instead of y.lstrip('gonl ') you should use y[5:] or maybe y[len('gonl '):]
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Programming Challenge C++ and Python

2005-02-01 Thread Ali Polatel
I need a favor.I play chess at a chess server with the name
ICC(www.chessclub.com). I want to write a plugin for their interface
using Python.
   I don't have any idea about how to write a plugin but I found out
that the server administrator has written a Plugin Development Kit in
C++ for those who wish to write plugins for the interface.I don't know
C++ so I cannot convert this kit into python scripts.Can anyone do
this for me? or can anyone examine those scripts and tell me a way how
to write those with python?The development kit is avaliable at the
site ftp://ftp.chessclub.com/pub/icc/interface/blitzin2/plugins/
under the name PluginDevkit.zip
Any kind of help is appreciated.
Regards,
Ali Polatel
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Better structure?

2005-02-01 Thread Liam Clarke
> http://www.cs.bell-labs.com/cm/cs/pearls/
That link seems to be dead. Pity. My whole programming experience is
comprised of Ah-Ha's followed by Um's...





-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: Better structure?

2005-02-01 Thread Jorge Luiz Godoy Filho
Liam Clarke wrote:

>> http://www.cs.bell-labs.com/cm/cs/pearls/
> That link seems to be dead. Pity. My whole programming experience is
> comprised of Ah-Ha's followed by Um's...

It worked here.

-- 
Godoy.  <[EMAIL PROTECTED]>


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


Re: [Tutor] How does import work?

2005-02-01 Thread Michael Janssen
On Fri, 28 Jan 2005 18:40:53 +0100, Johan Nilsson
<[EMAIL PROTECTED]> wrote:

>  >>> from scipy.signal.signaltools import *
> 
> /Traceback (most recent call last):
>   File "", line 1, in -toplevel-
> from scipy.signal.signaltools import *
> ImportError: No module named signaltools/
> 
> So I try the methodic way and this works, giving me access to the
> functions I need
> 
>  >>> from scipy import *
>  >>> from scipy.signal import *
>  >>> from scipy.signal.signaltools import *

seems like overkill (and I don't understand why it works better than
the above, but that's more an issue about my understanding and not
about python ;-). Try

from scipy.signal import signaltools # don't import everything from signal

and go on using functions from signaltools like this: signaltools.function

> Now what confuses me is that when I put the above three lines in a file
> (of course without the >>>) and execute them I get a long error message.

perhaps different python versions?

> / Traceback (most recent call last):
>   File "/home/johan/pyton/import_test.py", line 5, in -toplevel-
> from scipy.signal import *

note that the error occours while importing everything from
scipy.signal . The chance are well that this error goes away when
using a reduced import statement.

[snip long traceback talking about scipy and Numerics imports]

> import lapack_lite
> ImportError:
> /usr/local/lib/python2.3/site-packages/Numeric/lapack_lite.so: undefined
> symbol: dgesdd_/

given the fact that I'm no c-programmer this seems to me like a broken
c module. I would try to reinstall Numeric/ scipy (After hunting the
problem down to a specific import).

The most obvious reason why the import in idle works is that idle uses
another version of python (ask sys.version)

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


Re: [Tutor] carriage return on windows

2005-02-01 Thread Michael Janssen
On Mon, 31 Jan 2005 18:01:59 -0600, Victor Rex <[EMAIL PROTECTED]> wrote:

> I played around with this output issue and I love the way it works.
> Now, how do you do this in *nix? I tried the same approach and I get a
> blank line for 5 seconds (or whatever number of cycles you have on your
> example) and the a final line with the last value of the iterable.
> 
> Do you happen to know how this in done?

you might want to flush stdout after printing to it. "print" will
cares for this only when not using that trailing comma. "flush" means
to write immedatly instead to wait for a fair amount of data.

import sys,time
for i in range(8):
sys.stdout.write( "step: %s\r" % i) 
# or: print "step: %s\r" % i,
sys.stdout.flush()
time.sleep(.5)


There's still another possibilty using ansi control sequences. The
dirty way is to print (without trailing comma) and go back to previous
line:

import time
for i in range(8):
print "step: %s\033[A" % i
# print subsystem has done stdout.flush
time.sleep(.5)

It's dirty cause the next line was already entered and thus is written
(as an empty line) and content of older "steps" will stay an screen,
when subsequents lines aren't long enough to overwrite them. Which
also applies to \r:

import sys,time
for i in range(8,0,-1):
# printing 8**8, ..., 0**0 on line. Forget to overwrite
sys.stdout.write( "step: %s\r" % (i**i))
sys.stdout.flush()
time.sleep(.5)

Fixes are to add whitespace to the line. Stepping back with \033[D
fixes the empty newline issue (which is most often not worth the
effort):

import sys,time
for i in range(8,0,-1):
# fixing output length to 30
output = "%-30s" % "step: %s" % (i**i)
length = len(output)
sys.stdout.write(output)
# "print output," would be different, because of implizit spaces
sys.stdout.write("\033[D"* (length))
sys.stdout.flush()
time.sleep(.5)


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


[Tutor] Test

2005-02-01 Thread Mark Brown
Test, please disregard.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] carriage return on windows

2005-02-01 Thread Victor Rex
Michael Janssen wrote:
On Mon, 31 Jan 2005 18:01:59 -0600, Victor Rex <[EMAIL PROTECTED]> wrote:
 

I played around with this output issue and I love the way it works.
Now, how do you do this in *nix? I tried the same approach and I get a
blank line for 5 seconds (or whatever number of cycles you have on your
example) and the a final line with the last value of the iterable.
Do you happen to know how this in done?
   

you might want to flush stdout after printing to it. "print" will
cares for this only when not using that trailing comma. "flush" means
to write immedatly instead to wait for a fair amount of data.
import sys,time
for i in range(8):
   sys.stdout.write( "step: %s\r" % i) 
   # or: print "step: %s\r" % i,
   sys.stdout.flush()
   time.sleep(.5)

There's still another possibilty using ansi control sequences. The
dirty way is to print (without trailing comma) and go back to previous
line:
import time
for i in range(8):
   print "step: %s\033[A" % i
   # print subsystem has done stdout.flush
   time.sleep(.5)
It's dirty cause the next line was already entered and thus is written
(as an empty line) and content of older "steps" will stay an screen,
when subsequents lines aren't long enough to overwrite them. Which
also applies to \r:
import sys,time
for i in range(8,0,-1):
   # printing 8**8, ..., 0**0 on line. Forget to overwrite
   sys.stdout.write( "step: %s\r" % (i**i))
   sys.stdout.flush()
   time.sleep(.5)
Fixes are to add whitespace to the line. Stepping back with \033[D
fixes the empty newline issue (which is most often not worth the
effort):
import sys,time
for i in range(8,0,-1):
   # fixing output length to 30
   output = "%-30s" % "step: %s" % (i**i)
   length = len(output)
   sys.stdout.write(output)
   # "print output," would be different, because of implizit spaces
   sys.stdout.write("\033[D"* (length))
   sys.stdout.flush()
   time.sleep(.5)
regards
Michael
 

Excellent. Thanks Kent and Michael.
Great tutorial ;-)
You're right Michael. This last one works nicely but it is probably not 
worth the effort.

I likes the previous one but adding fixed formatting to the number 
output, something like
"step: %9s\r"

instead of just
"step: %s\r".
Thanks again.
Victor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Matching with beginning of the line in the character set

2005-02-01 Thread Smith, Jeff
I want to match a string which is preceeded by a space or occurs at the
beginning of the line.  I also don't want to catch the preceeding
character as a group.

I have found both of the following to work
re.compile('(?:^|\s)string')
re.compile('(?:\A|\s)string')

But would prefer to use the more concise [] notation.  However
re.compile('[^\s]string')
Does not work and
re.compile('[\A\s]string')
throws an exception:
Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python24\Lib\sre.py", line 180, in compile
return _compile(pattern, flags)
  File "C:\Python24\Lib\sre.py", line 227, in _compile
raise error, v # invalid expression
error: internal: unsupported set operator

Why don't either of these work (particularly the latter)?

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


[Tutor] Tkinter questions

2005-02-01 Thread Mark Kels
Hello,
I got some Tkinter questions that I need the answer for to complete a
little project of mine:
1. How can I make the program to open in a X*Y sized window ?
2. How can I open another window from the first one (without closing it) ?
3. How can I add a file browser for my app (like the one you get when
you press "Save as..." in windows apps) ?
4. How do I configure the font size on the Text widget (its realy
huge, and I would like to change it to somthing like 12).
5. [OT] Do you know any web-sites that I can store my project at (like
sourceforge and others) ?

This is all for now :)
Thanks in advence .

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Matching with beginning of the line in the character set

2005-02-01 Thread Kent Johnson

Smith, Jeff wrote:
I want to match a string which is preceeded by a space or occurs at the
beginning of the line.  I also don't want to catch the preceeding
character as a group.
I have found both of the following to work
re.compile('(?:^|\s)string')
re.compile('(?:\A|\s)string')
How about r'\bstring' ? It doesn't mean quite the same as \sstring but it 
might work for you.
But would prefer to use the more concise [] notation.  However
re.compile('[^\s]string')
As the first character in [], ^ means 'not'.
Does not work and
re.compile('[\A\s]string')
I guess \A doesn't count as a 'character class'? Or do you need to be using 
raw strings?
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Matching with beginning of the line in the character set

2005-02-01 Thread Smith, Jeff
Kent,

I think \b will work for me since I was really looking for [\A\W]
anyway.

That still doesn't answer the generalized question about something like
[\A\d] for instance.

Thanks,
Jeff

BTW, I was using raw strings although I forgot to put that in.

-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 01, 2005 1:15 PM
Cc: Tutor@python.org
Subject: Re: [Tutor] Matching with beginning of the line in the
character set




Smith, Jeff wrote:
> I want to match a string which is preceeded by a space or occurs at 
> the beginning of the line.  I also don't want to catch the preceeding 
> character as a group.
> 
> I have found both of the following to work
>   re.compile('(?:^|\s)string')
>   re.compile('(?:\A|\s)string')

How about r'\bstring' ? It doesn't mean quite the same as \sstring but
it might work for you.

> 
> But would prefer to use the more concise [] notation.  However
>   re.compile('[^\s]string')

As the first character in [], ^ means 'not'.

> Does not work and
>   re.compile('[\A\s]string')

I guess \A doesn't count as a 'character class'? Or do you need to be
using raw strings?

Kent


___
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] Matching with beginning of the line in the character set

2005-02-01 Thread Kent Johnson
Smith, Jeff wrote:
Kent,
I think \b will work for me since I was really looking for [\A\W]
anyway.
That still doesn't answer the generalized question about something like
[\A\d] for instance.
I know :-)
The docs say [] is "Used to indicate a set of characters." So it kind of makes sense that it works 
for \w and \s, which are just shortcuts for sets of characters themselves, but not for \A which is 
something different.

Kent
Thanks,
Jeff
BTW, I was using raw strings although I forgot to put that in.
-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 01, 2005 1:15 PM
Cc: Tutor@python.org
Subject: Re: [Tutor] Matching with beginning of the line in the
character set


Smith, Jeff wrote:
I want to match a string which is preceeded by a space or occurs at 
the beginning of the line.  I also don't want to catch the preceeding 
character as a group.

I have found both of the following to work
re.compile('(?:^|\s)string')
re.compile('(?:\A|\s)string')

How about r'\bstring' ? It doesn't mean quite the same as \sstring but
it might work for you.

But would prefer to use the more concise [] notation.  However
re.compile('[^\s]string')

As the first character in [], ^ means 'not'.

Does not work and
re.compile('[\A\s]string')

I guess \A doesn't count as a 'character class'? Or do you need to be
using raw strings?
Kent
___
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] Matching with beginning of the line in the character set

2005-02-01 Thread Mike Bell
Alternatively, you could .split() your string and not invoke the
mechanisms dealing with regular expressions.

Is this considered stylistically sloppy in the event that the split
results in a very long array?  Sloppier than REs are to begin with?

I think that the problem with [\A\d] is that \A is zero-length, which
doesn't make sense in the context of [].  Brackets aren't shorthand
for "'or' a bunch of small things together" but rather "'or' a bunch
of these single-character matches together"

mike


On Tue, 1 Feb 2005 13:30:44 -0500, Smith, Jeff <[EMAIL PROTECTED]> wrote:
> Kent,
> 
> I think \b will work for me since I was really looking for [\A\W]
> anyway.
> 
> That still doesn't answer the generalized question about something like
> [\A\d] for instance.
> 
> Thanks,
> Jeff
> 
> BTW, I was using raw strings although I forgot to put that in.
> 
> -Original Message-
> From: Kent Johnson [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, February 01, 2005 1:15 PM
> Cc: Tutor@python.org
> Subject: Re: [Tutor] Matching with beginning of the line in the
> character set
> 
> Smith, Jeff wrote:
> > I want to match a string which is preceeded by a space or occurs at
> > the beginning of the line.  I also don't want to catch the preceeding
> > character as a group.
> >
> > I have found both of the following to work
> >   re.compile('(?:^|\s)string')
> >   re.compile('(?:\A|\s)string')
> 
> How about r'\bstring' ? It doesn't mean quite the same as \sstring but
> it might work for you.
> 
> >
> > But would prefer to use the more concise [] notation.  However
> >   re.compile('[^\s]string')
> 
> As the first character in [], ^ means 'not'.
> 
> > Does not work and
> >   re.compile('[\A\s]string')
> 
> I guess \A doesn't count as a 'character class'? Or do you need to be
> using raw strings?
> 
> Kent
> 
> ___
> 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


Re: [Tutor] Append function

2005-02-01 Thread kumar s
Hi Danny:

 I have ~50 files in this format:

File1:

680:209 3006.3
266:123 250.5
62:393  117.3
547:429 161.5
341:311 546.5
132:419 163.3
98:471  306.3

File 2:
266:123 168.0
62:393  119.3
547:429 131.0
341:311 162.3
132:419 149.5
98:471  85.0
289:215 207.0
75:553  517.0


I am generating these files using this module:

f1 = open("test2_cor.txt","r")
ana = f1.read().split('\n')
ana = ana[:-1]
pbs = []
for line in ana:
cols = line.split('\t')
pb = cols[0]
pbs.append(pb)
##CEL Files section 
files = glob.glob("c:\files\*.cel")

def parSer(file):
f1 = open(file,'r')
celf = f1.read().split('\n')
celfile = celf[24:409624]
my_vals = celParser(celfile,pbs)
f2 = open(file+'.txt','w')
for line in my_vals:
f2.write(line+'\t')
f2.write('\n')
f2.close()

def main():
for each in files:
parSer(each)
main()
 

Because, I asked to write a file with the name of the
file as output, it is generating 50 output files for
50 input files. 

What I am interested in is to append the output to one
single file but with tab delimmitation. 

For example:

for each file there are 2 columns. Cor and val
file 1file 2file 3 file 4
cor val  cor  val  cor val cor val
x:x 1345 x:x 5434  x:x 4454 x:x 4462
x:y 3463 x:y 3435  x:y 3435 x:y 3435

Could you suggest a way. Thank you. 



__ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Better structure?

2005-02-01 Thread Alan Gauld
> What, like
> global radiusaxis, radiusaxis2

exactly.

> > And since there is no input parameter and no return statement
> > and you only call start() once...
>
> Not true. If y == 'clear', then start is called to "redraw" the
window.
> Very important part.

OK, I missed that, but its still better to hide the call to
start inside an
if name== main
clause since otherwise you can't ever import your file without
drawing the screen.

> I think I'll do that, but of course I'll have to add ValueError -- 
because
> of math domain errors on my function. That's what the try except
block is for.

In that case just put the ValueError clause in and leave other erors
to raise an error stack - that way you get to see the source of
the problem.

Then wrap your call to start in a try/except to catch the errors
and print a message at the outer level. That way its easy to turn
error reporting on/off

Alan G.

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


Re: [Tutor] Presentation

2005-02-01 Thread Alan Gauld
> Any help I can get would be much appreciated - such as 
> language comparisons, companies and systems that use python, 
> debates about what python is good for 

Most of that can be found under the General FAQ on 
the python web site. And links to other similar material.

Alan G


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


Re: [Tutor] Append function

2005-02-01 Thread kumar s
Hi Kent, 
 Thank you for your suggestion.  I keep getting
IOError permission denied every time I try the tips
that you provided. I tried to lookup on this error and
did not get reasonable answer. Is this error something
to do with Windows OS?

Any suggestions. 

Thank you
K

>>> allColumns = [readColumns("C:\Documents and
Settings\myfiles")for filePath in file_list]

Traceback (most recent call last):
  File "", line 1, in -toplevel-
allColumns = [readColumns("C:\Documents and
Settings\myfiles")for filePath in file_list]
  File "", line 2, in readColumns
rows = [line.split() for line in open(filePath)]
IOError: [Errno 13] Permission denied: 'C:\\Documents
and Settings\\myfiles'
>>> 



> def readColumns(filePath):
>  rows = [ line.split() for line in
> open(filePath) ]
>  return zip(*rows)
> 
> # list of all the files to read
> allFiles = [ 'f1.txt', 'f2.txt' ]
> 
> # both columns from all files
> allColumns = [ readColumns(filePath) for filePath in
> allFiles ]
> 
> # just the second column from all files
> allSecondColumns = [ cols[1] for cols in allColumns
> ]
> 
> # a representative first column
> col1 = allColumns[0][0]
> 
> # zip it up into rows
> allRows = zip(col1, *allSecondColumns)
> 
> for row in allRows:
>  print '\t'.join(row)
> 
> 
> Kent


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Better structure?

2005-02-01 Thread Alan Gauld
> ever get the chance, you may want to take a look at a book called
> Programming Pearls:
> 
> http://www.cs.bell-labs.com/cm/cs/pearls/
> 

I'll second that. Personally I try to read both books 
(I have the original 2 volume version!) every couple of years 
- they are that valuable. Most newbie programmers can learn 
a lot from Bentley's book(s) - especially about programming 
for performance. But loads of other tricks too.

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


Re: [Tutor] Programming Challenge C++ and Python

2005-02-01 Thread Alan Gauld
>I don't have any idea about how to write a plugin but I found out
> that the server administrator has written a Plugin Development Kit
in
> C++ for those who wish to write plugins for the interface.I don't
know
> C++ so I cannot convert this kit into python scripts.

Caveat: I've never done this so don't know how easy it is but...

There is a tool called SWIG which is for creating Python(or Perl
or Tcl etc) wrappers around C/C++ APIs.
So SWIG might be able to wrap your plug-in API for you.

But I've no idea how easy that is!

Alan G.

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


[Tutor] Introductory Links

2005-02-01 Thread jhomme

-Original message-
From: "Alan Gauld" [EMAIL PROTECTED]
Date: Tue,  1 Feb 2005 16:15:14 -0500
To: "jhomme" [EMAIL PROTECTED]
Subject: Re: [Tutor] Dictionary Nesting

> > Um, thanks for reminding me about the prompt.
> > work my way through some other stuff before wasting people's
> time.
> 
> It was your own time I was thinking of. Its much quicker to
> experiment briefly if you think you might know the answer
> than to compose an email, send it and then wait for replies!
> 
> Then if you do send a mail you can be much more specific too,
> because you know what doesn't work! :-)
> 
> Alan G.
> 
Hi,
Is it possible to get a copy of the message sent to us when we first join? I 
want to follow the links in it so I can learn how to do the research and ask 
questions on the list.

Thanks.

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


Re: [Tutor] Append function

2005-02-01 Thread Kent Johnson
You seem to be giving a path to a directory rather than a single file. Also you are putting it in 
the wrong place, you should edit the allFiles list.

Kent
kumar s wrote:
Hi Kent, 
 Thank you for your suggestion.  I keep getting
IOError permission denied every time I try the tips
that you provided. I tried to lookup on this error and
did not get reasonable answer. Is this error something
to do with Windows OS?

Any suggestions. 

Thank you
K

allColumns = [readColumns("C:\Documents and
Settings\myfiles")for filePath in file_list]
Traceback (most recent call last):
  File "", line 1, in -toplevel-
allColumns = [readColumns("C:\Documents and
Settings\myfiles")for filePath in file_list]
  File "", line 2, in readColumns
rows = [line.split() for line in open(filePath)]
IOError: [Errno 13] Permission denied: 'C:\\Documents
and Settings\\myfiles'


def readColumns(filePath):
rows = [ line.split() for line in
open(filePath) ]
return zip(*rows)
# list of all the files to read
allFiles = [ 'f1.txt', 'f2.txt' ]
# both columns from all files
allColumns = [ readColumns(filePath) for filePath in
allFiles ]
# just the second column from all files
allSecondColumns = [ cols[1] for cols in allColumns
]
# a representative first column
col1 = allColumns[0][0]
# zip it up into rows
allRows = zip(col1, *allSecondColumns)
for row in allRows:
print '\t'.join(row)
Kent

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: [Tutor] Introductory Links

2005-02-01 Thread Brian van den Broek
jhomme said unto the world upon 2005-02-01 17:15:

Hi, Is it possible to get a copy of the message sent to us when we
first join? I want to follow the links in it so I can learn how to
do the research and ask questions on the list.
Thanks.
Jim
Hi Jim,
I don't still have a copy of my Welcome msg. But the following links
all are good places to look:

The Python wwiki's beginner's page

Search com.lang.python

The Python Wiki page -- not the front, but the recent changes which is
how I like to enter it.

The Python Sidebar for Mozilla -- works for FireFox, too. A useful 
tool if you're using the right [ambiguity intended ;-)] browser.


How To Ask Questions The Smart Way by Eric Raymond.
The Tutor list won't bite you if you don't follow any of the advice in
that essay. But it is a very useful thing to read to learn how best to
frame your questions so as to get maximum return from everyone's
effort (your and those who answer you both).
HTH,
Brian vdB
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Introductory Links

2005-02-01 Thread Alan Gauld
> > Then if you do send a mail you can be much more specific too,
> > because you know what doesn't work! :-)
> >
> Is it possible to get a copy of the message sent to us when we first
join?
>I want to follow the links in it so I can learn how to do the
research
> and ask questions on the list.

I'm not sure which message you mean, but assuming its the one
you get when you start a new thread on tutor then I guess thats
a question for the list admin team. It sounds emminently sensible
to send a welcome message with some kind of set of intro links in it.

Its so long sice I joined I can't recall what happened!!

Danny?

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


[Tutor] Classes

2005-02-01 Thread Ismael Garrido
Hello.
I was just wondering, what magic can you do with classes? I mean, things 
like "class Name(Exception)" or "class Name(threading.Thread), which 
other classes are interesting to subclass? I've seen Object too, but I 
don't understand what it does.

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


Re: [Tutor] Classes

2005-02-01 Thread Max Noel
On Feb 1, 2005, at 23:08, Ismael Garrido wrote:
Hello.
I was just wondering, what magic can you do with classes? I mean, 
things like "class Name(Exception)" or "class Name(threading.Thread), 
which other classes are interesting to subclass? I've seen Object too, 
but I don't understand what it does.
	Basically, Object is the class all your classes should be deriving 
from (when you do that, you're using "new-style classes"). It's the 
root in the class hierarchy of Python. This gives you access to a lot 
of nifty features for free, such as properties.

Oh, and the best classes are those you create yourself, of course :D
-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

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


[Tutor] permutations, patterns, and probability

2005-02-01 Thread kevin parks
Greetings,
I am working on a program to produce patterns. What would like is for 
it to  exhaustively produce all possible permutations of a sequence of 
items but for each permutation produce variations, and also a sort of 
stutter based on probability / weighted randomess.

Let us say we have tiles of four primary colors: ['Red', 'Blue', 
'Green', 'Yellow']. Now we also have 4 alternatives or substitutes for 
each color ['Maroon', 'Navy_Blue', 'Forest_Green', 'Dark_Brown']

We pick a unique permutation, say: ['Red', 'Blue', 'Yellow', 'Green']
Now I would like to pick the primary colors substitute (say 30% chance 
for each element) so instead of our plain

['Red', 'Blue', 'Yellow', 'Green']
we might end up with:
['Red', 'Navy_Blue', 'Yellow', 'Forest_Green']
or
['Maroon', 'Navy_Blue', 'Yellow', 'Green']
Whatever... The main point is that sometimes the original color is 
retained and sometimes the dark color is substituted.

Now I want to take this list and sometimes stutter an element so that 
there is, let us say a 50% chance for each element, that it is 
stuttered, and it may be repeated 1 (34%), 2(66%), or 3(33%) times. So 
that we could get:

['Maroon','Maroon','Navy_Blue', 'Yellow','Yellow','Yellow','Yellow', 
'Green']

The program would quit when all 24 (in the case of 4 elements) was 
exhausted.

I have code that makes weighted randomness. I have code that makes 
permutations, but I am having trouble putting this all together... 
While i work on it though that i might ask for help... I'd like for the 
code to be reusable and am building a library of functions for 
patterns.

cheers,
kevin
### This is not mine, it is from a python book... I believe the Lutz 
book

def permute(list):
if not list:# shuffle any 
sequence
return [list]   # empty sequence
else:
res = []
for i in range(len(list)):
rest = list[:i] + list[i+1:]# delete 
current node
for x in permute(rest): # permute the 
others
res.append(list[i:i+1] + x) # add node at 
front
return res

mport random
### This this is mine, but seems to work anyway hee hee
def windex(lst):
'''an attempt to make a random.choose() function that makes 
weighted choices

accepts a list of tuples with the item and probability as a pair
like: >>> x = [('one', 0.25), ('two', 0.25), ('three', 0.5)]
>>> y=windex(x)'''
n = random.uniform(0, 1)
for item, weight in lst:
if n < weight:
break
n = n - weight
return item

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


Re: [Tutor] Presentation

2005-02-01 Thread Victor Rex
This is a great series of links. I found the following on Pythology too:
Python Spotting
http://pythonology.org/spotting
Best of luck.

Kent Johnson wrote:
Eric Raymond's "Why Python?" essay is a classic:
http://pythonology.org/success&story=esr
Bruce Eckel's "Why I love Python" presentation is here:
http://64.78.49.204/pub/eckel/LovePython.zip
This page has lots of links you might be interested in:
http://www.ferg.org/python_presentations/index.html
This page has links to language comparisons:
http://www.python.org/moin/LanguageComparisons
Good luck!
Kent
Paul Hartley wrote:
I am trying to get Python established here in the Philippines. 
Currently I am in charge of operations at a business based in Manila 
and I have asked my IT staff to start using Python (with some success).
 
A local university has now asked that I give a talk to their IT 
people on Python - so here is an opportunity to spread the word and 
get some more converts and maybe introduce python into their computer 
science courses.
 
Any help I can get would be much appreciated - such as language 
comparisons, companies and systems that use python, debates about 
what python is good for (almost everything), examples of elegant code..
 
When I was a member of the Forth Interest Group in the USA we learned 
that Forth was used on the buggy that went to mars, that it started 
life controlling huge radio telescopes which only had 4k (yes 4k) of 
memory for both language and application.
 
Anything like the above concerning python would be useful.
 
Any other suggestions would help also, the audience will have 
computers, so a demonstration of small workshop would also be good - 
the presentation/session is for 4 hours on the 10th February.
 
Paul
 


___
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


Re: [Tutor] permutations, patterns, and probability

2005-02-01 Thread Kent Johnson
kevin parks wrote:
Greetings,
I am working on a program to produce patterns. What would like is for it 
to  exhaustively produce all possible permutations of a sequence of 
items but for each permutation produce variations, and also a sort of 
stutter based on probability / weighted randomess.

Let us say we have tiles of four primary colors: ['Red', 'Blue', 
'Green', 'Yellow']. Now we also have 4 alternatives or substitutes for 
each color ['Maroon', 'Navy_Blue', 'Forest_Green', 'Dark_Brown']

We pick a unique permutation, say: ['Red', 'Blue', 'Yellow', 'Green']
Now I would like to pick the primary colors substitute (say 30% chance 
for each element) so instead of our plain

['Red', 'Blue', 'Yellow', 'Green']
we might end up with:
['Red', 'Navy_Blue', 'Yellow', 'Forest_Green']
or
['Maroon', 'Navy_Blue', 'Yellow', 'Green']
Whatever... The main point is that sometimes the original color is 
retained and sometimes the dark color is substituted.

Now I want to take this list and sometimes stutter an element so that 
there is, let us say a 50% chance for each element, that it is 
stuttered, and it may be repeated 1 (34%), 2(66%), or 3(33%) times. So 
that we could get:

['Maroon','Maroon','Navy_Blue', 'Yellow','Yellow','Yellow','Yellow', 
'Green']

The program would quit when all 24 (in the case of 4 elements) was 
exhausted.

I have code that makes weighted randomness. I have code that makes 
permutations, but I am having trouble putting this all together... While 
i work on it though that i might ask for help... I'd like for the code 
to be reusable and am building a library of functions for patterns.
If you had a randomizeList function and a stutterList function then your top-level function would 
look like this:

permutations = permute(['Red', 'Blue', 'Yellow', 'Green'])
permutations = [ randomizeList(list) for list in permutations ]
permutations = [ stutterList(list) for list in permutations ]
In other words you start with the basic permutations, then apply the randomize function to each 
permutation, then apply the stutter function.

The randomizeList function should walk through the list, find the right randomize list for that list 
element (a dict could help with that - look up the list element and get the randomize list), and 
build a new list with the randomized values.

The stutterList function walks through the list building a new list with 
possibly repeated elements.
HTH,
Kent
cheers,
kevin
### This is not mine, it is from a python book... I believe the Lutz book
def permute(list):
if not list:# shuffle any 
sequence
return [list]   # empty sequence
else:
res = []
for i in range(len(list)):
rest = list[:i] + list[i+1:]# delete current 
node
for x in permute(rest): # permute the 
others
res.append(list[i:i+1] + x) # add node at front
return res

mport random
### This this is mine, but seems to work anyway hee hee
def windex(lst):
'''an attempt to make a random.choose() function that makes 
weighted choices

accepts a list of tuples with the item and probability as a pair
like: >>> x = [('one', 0.25), ('two', 0.25), ('three', 0.5)]
>>> y=windex(x)'''
n = random.uniform(0, 1)
for item, weight in lst:
if n < weight:
break
n = n - weight
return item

___
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] carriage return on windows

2005-02-01 Thread Alan Gauld
> I played around with this output issue and I love the way it works.
> Now, how do you do this in *nix? I tried the same approach and I get
a
> blank line for 5 seconds (or whatever number of cycles you have on
your
> example) and the a final line with the last value of the iterable.

On Unix it is easiest to use the curses library.
There are so many different terminals in use on Unix that
no single set of control codes can be guaranteed to work.
Curses provides an abstract terminal that you can control
by positioning the cursor at x,y coordinates etc.

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] Better structure?

2005-02-01 Thread Jacob S.
I don't know who's going crazy here... but I checked that straight from the 
python 2.4 interpreter...

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
a = "go on long buddy"
a.lstrip("gonl")
' on long buddy'
a = "go long on log buddy!"
a.lstrip('gonl')
' long on log buddy!'

In both cases, lstrip just removed the first word... I don't see how this 
code is broken.

Hope we figure it out.
Jacob
This code is broken. lstrip('gonl ') will remove *all* leading g, o, n, l 
and space, in any order:
 >>> s='go long on log buddy!'
 >>> s.lstrip('gonl ')
'buddy!'

Instead of y.lstrip('gonl ') you should use y[5:] or maybe y[len('gonl 
'):]

Kent
___
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] Tkinter questions

2005-02-01 Thread Jacob S.
I suggest looking at Introduction to Tkinter.
http://www.pythonware.com/library/tkinter/introduction/index.htm
HTH,
Jacob
Hello,
I got some Tkinter questions that I need the answer for to complete a
little project of mine:
1. How can I make the program to open in a X*Y sized window ?
2. How can I open another window from the first one (without closing it) ?
3. How can I add a file browser for my app (like the one you get when
you press "Save as..." in windows apps) ?
4. How do I configure the font size on the Text widget (its realy
huge, and I would like to change it to somthing like 12).
5. [OT] Do you know any web-sites that I can store my project at (like
sourceforge and others) ?
This is all for now :)
Thanks in advence .
--
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon
___
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] Better structure?

2005-02-01 Thread Jeff Shannon
Jacob S. wrote:
I don't know who's going crazy here... but I checked that straight from 
the python 2.4 interpreter...
>>> a = "go on long buddy"
>>> a.lstrip('gonl')
' on long buddy'
>>> a.lstrip('gonl ')
'buddy'
>>>
Note that in the second case, I've included a space in the lstrip() 
parameter.  lstrip() is essentially saying "remove all leading 
characters until you find a character that's not in this sequence" -- 
a space counts as a character.  (Took me trying it out before I saw 
this, so don't feel bad. ;) )

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


Re: [Tutor] Better structure?

2005-02-01 Thread Jacob S.
So, how would one go about this in a non broken code way? Don't they have 
something like what I'm requesting.
It seems to me that a few things are flawed in the standard distribution. 
Little things like the overlooking of adding a method or function to decimal 
for returning an instance with x places right of the decimal. I know of 
quantize, but that's junk and not simple. Also why shouldn't string methods 
include stuff like lstrip which do precisely what I request?
Maybe because they don't want to bother putting

def mylstrip(string,stripstring):
   return string[len(stripstring):]
as a method or something?
Messy, just plain messy.
Jacob Schmidt

Jacob S. wrote:
I don't know who's going crazy here... but I checked that straight from 
the python 2.4 interpreter...
>>> a = "go on long buddy"
>>> a.lstrip('gonl')
' on long buddy'
>>> a.lstrip('gonl ')
'buddy'
>>>
Note that in the second case, I've included a space in the lstrip() 
parameter.  lstrip() is essentially saying "remove all leading characters 
until you find a character that's not in this sequence" -- 
a space counts as a character.  (Took me trying it out before I saw this, 
so don't feel bad. ;) )

Jeff Shannon
Technician/Programmer
Credit International
___
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] Better structure?

2005-02-01 Thread Jeff Shannon
Jacob S. wrote:
So, how would one go about this in a non broken code way? Don't they 
have something like what I'm requesting.
No, but it's pretty easy to do:
def exact_lstrip(astring, stripstring):
if astring.startswith(stripstring):
astring = astring[len(stripstring):]
return astring

[...] Also why 
shouldn't string methods include stuff like lstrip which do precisely 
what I request?
Maybe it's because other people would have different expectations?
The current implementation of strip() (including lstrip() and 
rstrip()) seems to work well for the most common case, and I'm not 
sure that your expectation is necessarily more generally useful than 
the current behavior.  Especially given that your behavior is the one 
that's easier to hand-code if it's desired.

Jeff Shannon
Technician/Programmer
Credit International

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


Re: [Tutor] permutations, patterns, and probability

2005-02-01 Thread kevin parks
Tremendously helpful One question though. How can i pluck a unique 
item from my exhaustive list of permutations without repeats making 
sure that each one is used once? Like filling a bag, shaking it, and 
then picking from the bag and removing that item from the bag so it 
isn't used again

-k
On Feb 1, 2005, at 8:58 PM, [EMAIL PROTECTED] wrote:
f you had a randomizeList function and a stutterList function then 
your top-level function would
look like this:

permutations = permute(['Red', 'Blue', 'Yellow', 'Green'])
permutations = [ randomizeList(list) for list in permutations ]
permutations = [ stutterList(list) for list in permutations ]
In other words you start with the basic permutations, then apply the 
randomize function to each
permutation, then apply the stutter function.

The randomizeList function should walk through the list, find the 
right randomize list for that list
element (a dict could help with that - look up the list element and 
get the randomize list), and
build a new list with the randomized values.

The stutterList function walks through the list building a new list 
with possibly repeated elements.

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


Re: [Tutor] Presentation

2005-02-01 Thread Paul Hartley



Thank you for all your feedback on this - 
powerpoint presentations and all!!
 
Not only is the language amazing but the community 
is fantastic!!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Presentation

2005-02-01 Thread Terry Carroll
On Wed, 2 Feb 2005, Paul Hartley wrote:

> Not only is the language amazing but the community is fantastic!!

The community is one of the things I particularly like about Python.  I
always hated asking a question in the Perl newsgroups; although you
usually got an answer, you were almost certain to be told you're stupid
for not already knowing it.

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


Re: [Tutor] permutations, patterns, and probability

2005-02-01 Thread Kent Johnson
kevin parks wrote:
Tremendously helpful One question though. How can i pluck a unique 
item from my exhaustive list of permutations without repeats making sure 
that each one is used once? Like filling a bag, shaking it, and then 
picking from the bag and removing that item from the bag so it isn't 
used again
Use random.shuffle() to 'shake' the list. Then use pop() to remove an item:
 >>> import random
 >>> l=range(10)
 >>> random.shuffle(l)
 >>> l
[4, 5, 0, 8, 9, 6, 2, 1, 7, 3]
 >>> l.pop()
3
 >>> l.pop()
7
 >>> l.pop()
1
 >>> l
[4, 5, 0, 8, 9, 6, 2]
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to separate hexadecimal

2005-02-01 Thread jrlen balane
i have a 4 digit hex number (2 bytes) and i want to separate it into 2
digit hex (1 byte each) meaning i want to get the upper byte and the
lower byte since i am going to add this two.
how am i going to do this?
should i treat it just like a normal string?
please help, thanks.

ex. hexa = '0x87BE"  # what i want to do is:
  a = 0x87, b = 0xBE# so that i could do this:
  c = a + b#which should be equal to 0x145
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor