Re: [Tutor] Request For Suggestions

2005-12-03 Thread Ismael Garrido
Basem Narmok wrote:

>Hi all,
>
>I am planning to make a Python CD for advocating Python, and I need your 
>suggestions about this, the objective is to build a CD that contains the 
>basic material for Python beginner (e.g. Python 2.4.2 for different 
>platforms) with some advocating material (e.g. videos), and here is what 
>comes to my mind to present on the CD:
>
>Software:
>- Python 2.4.2 for different platforms.
>- ironPython 0.9.5
>- wxPython 2.6
>- SPE 0.7.5
>  
>
SPE is now at 0.8.0

You should include some tutorials, too.

Perhaps the modules noted on UsefulModules could be included, too? (With 
their respective docs/tutorials)
http://wiki.python.org/moin/UsefulModules

Take a look at the edu-sig page, too:
http://www.python.org/sigs/edu-sig/

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


Re: [Tutor] Is it a good idea to use TKInter to change my password program into a GUI?

2005-12-03 Thread Michael Lange
On Fri, 2 Dec 2005 15:20:43 -0700
"Nathan Pinno" <[EMAIL PROTECTED]> wrote:

> I like the Toolkit, is there anywhere where there is a how to use it?
>  

A good place to look for Tkinter resources is the wiki:



There is a number of links to Tkinter documentation there:



And still the best resource on Tkinter programming is John Grayson's "Python 
and Tkinter programming":



Regards

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


Re: [Tutor] tkFileDialog bug on windows

2005-12-03 Thread Michael Lange
On Fri, 2 Dec 2005 16:58:26 -0800
Fred Lionetti <[EMAIL PROTECTED]> wrote:

> Hi everyone,
> 
> I may have found a strange bug with tkFileDialog, and I'm wondering if
> anyone has a workaround for the problem.  It happens when you have a
> button (or any other clickable widget) directly behind the
> askopenfilename dialog box and double click on a file.  The button
> (behind the open file dialog) gets clicked, when it shouldn't.  It
> occurs with the code below (but only under windows).
> 
> --
> from Tkinter import *
> import tkFileDialog
> 
> def cmd():
> print "button was pressed"
> 
> parent = Tk()
> Button(parent, text = "hello", command = cmd, width=30, height = 10).pack()
> tkFileDialog.askopenfilename(parent=parent, title = "Double click on a
> file with the 'hello' button directly behind")
> 
> parent.mainloop()
> -

Hi Fred,

I don't have a windows box here to try it, so I can just guess.
On my linux box the list in the dialog responds to ButtonRelease events,
but I think on windows tk uses native dialogs, and maybe these respond to 
ButtonPress events;
if this is the case, it may happen that the ButtonRelease occurs *after* the 
dialog window
has been destroyed, so the event gets delivered to the button in the parent 
window.

Regards

Michael

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


[Tutor] Printing regular expression match

2005-12-03 Thread Srinivas Iyyer
Dear group, 

I have two lists:

>>> a
['apple', 'boy', 'boy', 'apple']

>>> b
['Apple', 'BOY', 'APPLE-231']

>>> for i in a:
pat = re.compile(i,re.IGNORECASE)
for m in b:
if pat.match(m):
print m


Apple
APPLE-231
BOY
BOY
Apple
APPLE-231
>>> 




Here I tried to match element in list a to element in
list b
and asked to ignore the case.  It did work.

However, I do not know how to make it print only m

What I want :

Apple
BOY
APPLE-231


I do not want python to print both elenents from lists
a and b. 
I just want only the elements in the list B.

how can i do that.. 

Please help me. thank you.


srini



__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 

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


[Tutor] Command line arguments passing

2005-12-03 Thread Vlad Popescu
Hi there, everyone; first time poster! Sorry if this isn't very closely
related to Python, but I have encountered the issue while trying to
learn Python, so I guess I can just ask here.

My question is: when invoking a program with, let's say, a filename
containing spaces as a parameter:

myprog -file "Long name"

What does sys.argv hold in this case? I am specifically interested in
whether argv[2]=="\"Long" or argv[2]=="Long name", that is, if the shell
does the processing or I need to do it in the program. Also, I need to
know if most environments do the same (I wouldn't want to be caught
pants down while porting this to Windows).

Many thanks in advance for your valuable suggestions and apologies if I
have misposted,

Vlad


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


Re: [Tutor] Command line arguments passing

2005-12-03 Thread Christopher Arndt
Vlad Popescu schrieb:
> Hi there, everyone; first time poster! Sorry if this isn't very closely
> related to Python, but I have encountered the issue while trying to
> learn Python, so I guess I can just ask here.
> 
> My question is: when invoking a program with, let's say, a filename
> containing spaces as a parameter:
> 
> myprog -file "Long name"
> 
> What does sys.argv hold in this case? I am specifically interested in
> whether argv[2]=="\"Long" or argv[2]=="Long name", 

Why don't you just try it out?

$ python - -f "Long file"
Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.argv[1]
-f
>>> print sys.argv[2]
...

I think you can do the rest.

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


Re: [Tutor] Printing regular expression match

2005-12-03 Thread Danny Yoo


On Sat, 3 Dec 2005, Srinivas Iyyer wrote:
> >>> a
> ['apple', 'boy', 'boy', 'apple']
>
> >>> b
> ['Apple', 'BOY', 'APPLE-231']
>
> >>> for i in a:
>   pat = re.compile(i,re.IGNORECASE)
>   for m in b:
>   if pat.match(m):
>   print m


Hi Srinivas,

We may want to change the problem so that it's less focused on "print"ing
results directly.  We can rephrase the question as a list "filtering"
operation: we want to keep the elements of b that satisfy a certain
criteron.


Let's give a name to that criterion now:

##
def doesNameMatchSomePrefix(word, prefixes):
"""Returns True if the input word is matched by some prefix in
the input list of prefixes.  Otherwise, returns False."""
# ... fill me in

##


Can you write doesNameMatchSomePrefix()?  In fact, you might not even need
regexes to write an initial version of it.



If you can write that function, then what you're asking:

> I do not want python to print both elenents from lists a and b.  I just
> want only the elements in the list B.

should not be so difficult: it'll be a straightforward loop across b,
using that helper function.



(Optimization can be done to make doesNameMatchSomePrefix() fast, but you
probably should concentrate on correctness first.  If you're interested in
doing something like this for a large number of prefixes, you might be
interested in:

http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/

which has more details and references to specialized modules that attack
the problem you've shown us so far.)


Good luck!

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


Re: [Tutor] Command line arguments passing

2005-12-03 Thread Danny Yoo


> > My question is: when invoking a program with, let's say, a filename
> > containing spaces as a parameter:
> >
> > myprog -file "Long name"
> >
> > What does sys.argv hold in this case? I am specifically interested in
> > whether argv[2]=="\"Long" or argv[2]=="Long name",


Hi Vlad,

What you're asking is a platform-specific thing.  I believe it should do
what you're expecting --- "Long name" should be a pulled together as a
single argument in sys.argv.  But it's not Python that's pulling "Long
name" together: it's your operating system's command line shell that's
doing this.

For example, on Windows, the following pages:

http://www.microsoft.com/technet/community/columns/scripts/sg0704.mspx
http://www.microsoft.com/technet/archive/winntas/deploy/shellscr.mspx

talk about how Windows does command line argument parsing.  (Search those
pages for the word "quote", and you'll see a mention of this.) And the
details on the role of quoting arguments is simliar for Unix shells like
'bash' or 'tcsh'.  For example, for the bash shell:

http://www.gnu.org/software/bash/manual/bashref.html#SEC8


So all Python knows is that it's getting an array of strings: it doesn't
even see the original line that the user typed at the command line prompt;
it instead gets something that has already been partially digested by your
command line shell.


Hope this helps!

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


Re: [Tutor] Printing regular expression match

2005-12-03 Thread Srinivas Iyyer
Hi Danny, 
thanks for your email. 

In the example I've shown, there are no odd elements
except for character case. 

In the real case I have a list of 100 gene names for
Humans. 
The human gene names are conventioanlly represented in
higher cases (eg.DDX3X).  However, NCBI's gene_info
dataset the gene names are reported in lowercase (eg.
ddx3x).  I want to extract the rest of the information
for DDX3X that I have from NCBI's file (given that
dataset is in tab delim format). 

my approach was if i can define DDX3X is identical
ddx3x then I want to print that line from the other
list (NCBI's gene_info dataset). 

I guess, I understood your suggestion wrongly.  In
such case, why do I have to drop something from list b
(which is over 150 K lines). If I can create a sublist
of all elements in b (a small list of 100) then it is
more easy. this is my opinion. 

-srini


--- Danny Yoo <[EMAIL PROTECTED]> wrote:

> 
> 
> On Sat, 3 Dec 2005, Srinivas Iyyer wrote:
> > >>> a
> > ['apple', 'boy', 'boy', 'apple']
> >
> > >>> b
> > ['Apple', 'BOY', 'APPLE-231']
> >
> > >>> for i in a:
> > pat = re.compile(i,re.IGNORECASE)
> > for m in b:
> > if pat.match(m):
> > print m
> 
> 
> Hi Srinivas,
> 
> We may want to change the problem so that it's less
> focused on "print"ing
> results directly.  We can rephrase the question as a
> list "filtering"
> operation: we want to keep the elements of b that
> satisfy a certain
> criteron.
> 
> 
> Let's give a name to that criterion now:
> 
> ##
> def doesNameMatchSomePrefix(word, prefixes):
> """Returns True if the input word is matched by
> some prefix in
> the input list of prefixes.  Otherwise, returns
> False."""
> # ... fill me in
> 
> ##
> 
> 
> Can you write doesNameMatchSomePrefix()?  In fact,
> you might not even need
> regexes to write an initial version of it.
> 
> 
> 
> If you can write that function, then what you're
> asking:
> 
> > I do not want python to print both elenents from
> lists a and b.  I just
> > want only the elements in the list B.
> 
> should not be so difficult: it'll be a
> straightforward loop across b,
> using that helper function.
> 
> 
> 
> (Optimization can be done to make
> doesNameMatchSomePrefix() fast, but you
> probably should concentrate on correctness first. 
> If you're interested in
> doing something like this for a large number of
> prefixes, you might be
> interested in:
> 
>
>
http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/
> 
> which has more details and references to specialized
> modules that attack
> the problem you've shown us so far.)
> 
> 
> Good luck!
> 
> 




__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 

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


[Tutor] (no subject)

2005-12-03 Thread david



hello again. i think my dig function is working 
correctly now.
any input on how to save and restore all the rooms 
and descriptions?
thanks for helping.
 
import sysimport string
 
world = {}
 
class Room:    def 
__init__(self,coords):    
self.contents = []    
self.description = ''    self.coords 
= coords    world[tuple(coords)] = 
self    self.exits = 
{}    def 
nextdoor(self,direction):    if 
direction == 
'n':    
nextdoor =  (self.coords[0], self.coords[1] + 
1)    return 
list(nextdoor)    elif direction == 
's':    
nextdoor =  list((self.coords[0], self.coords[1] - 
1))    return 
nextdoor    elif direction == 
'e':    
nextdoor =  list((self.coords[0] +1, 
self.coords[1]))    
return nextdoor    elif direction == 
'w':    
nextdoor =  (self.coords[0] -1, 
self.coords[1])    
return list(nextdoor)    
 
class Player:    def 
__init__(self,name):    self.name = 
name    self.location = 
None    self.inventory = 
[]    self.wielded = 
None    def 
look(self):    print 
self.location.coords    print 
self.location.description
 
    def 
move(self,direction):    
type(direction)    if 
self.location.exits.has_key(direction):    
self.location = 
self.location.exits[direction]    
else:    
print 'alas, you cannot go that way'    def 
wield(self,what):    self.wielded = 
what    def 
wear(self,what):    
pass    def 
take(self,what):    
pass    def 
drop(self,what):    
pass    def 
dig(self,direction):    target = 
tuple(self.location.nextdoor(direction))    
print target    if 
self.location.exits.has_key(target):    
print 'there is already an exit to that 
room'    elif 
world.has_key(target):    
print 'already a room there, attempt to make 
exits'    
self.location.exits[direction] = 
Room(target)    
world[target].exits[opdir(direction)] = 
self.location    
else:    
world[target]=Room(target)    
self.location.exits[direction] = 
Room(target)    
world[target].exits[opdir(direction)] = self.location    def 
describeroom(self):    
self.location.description = raw_input('>>')    def 
do(self):    cmd = 
string.split(raw_input('>'))    
verb = cmd[0]    if len(cmd) > 
1:    target 
= cmd[1]    
    if verb == 
'l':    
self.look()    elif verb in 
['n','s','e','w']:   
    
self.move(verb)    elif verb == 
'quit':    
sys.exit()    elif verb == 
'i':    for a 
in 
self.inventory:    
print a.name    elif verb == 
'dig':    
self.dig(target)    elif verb == 
'dr':    
self.describeroom()    
else:    
print 'what?'
 
class Thing:    def 
__init__(self,name):    self.name = 
name
 
def opdir(direction):    if direction == 
'n':    return 
's'    if direction == 
's':    return 
'n'    if direction == 
'e':    return 
'w'    if direction == 
'w':    return 
'e'        p = 
Player('david')room1 = Room([0,0])
 
p.location = room1sword = Thing('sword')hat = 
Thing('hat')p.inventory.append(sword)p.inventory.append(hat)while 
1:    p.do()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] my text adventure

2005-12-03 Thread david



sorry i forgot a subject line. i have looked at the 
pickle module and was able to pickle world.
but i can't figure how to restore everything. 


  - Original Message - 
  From: 
  david 

  To: tutor@python.org 
  Sent: Saturday, December 03, 2005 8:36 
  PM
  Subject: [Tutor] (no subject)
  
  hello again. i think my dig function is working 
  correctly now.
  any input on how to save and restore all the 
  rooms and descriptions?
  thanks for helping.
   
  import sysimport string
   
  world = {}
   
  class Room:    def 
  __init__(self,coords):    
  self.contents = []    
  self.description = ''    
  self.coords = coords    
  world[tuple(coords)] = self    
  self.exits = {}    def 
  nextdoor(self,direction):    if 
  direction == 
  'n':    
  nextdoor =  (self.coords[0], self.coords[1] + 
  1)    
  return list(nextdoor)    elif 
  direction == 
  's':    
  nextdoor =  list((self.coords[0], self.coords[1] - 
  1))    
  return nextdoor    elif direction 
  == 'e':    
  nextdoor =  list((self.coords[0] +1, 
  self.coords[1]))    
  return nextdoor    elif direction 
  == 'w':    
  nextdoor =  (self.coords[0] -1, 
  self.coords[1])    
  return list(nextdoor)    
   
  class Player:    def 
  __init__(self,name):    self.name = 
  name    self.location = 
  None    self.inventory = 
  []    self.wielded = 
  None    def 
  look(self):    print 
  self.location.coords    print 
  self.location.description
   
      def 
  move(self,direction):    
  type(direction)    if 
  self.location.exits.has_key(direction):    
  self.location = 
  self.location.exits[direction]    
  else:    
  print 'alas, you cannot go that way'    def 
  wield(self,what):    self.wielded = 
  what    def 
  wear(self,what):    
  pass    def 
  take(self,what):    
  pass    def 
  drop(self,what):    
  pass    def 
  dig(self,direction):    target = 
  tuple(self.location.nextdoor(direction))    
  print target    if 
  self.location.exits.has_key(target):    
  print 'there is already an exit to that 
  room'    elif 
  world.has_key(target):    
  print 'already a room there, attempt to make 
  exits'    
  self.location.exits[direction] = 
  Room(target)    
  world[target].exits[opdir(direction)] = 
  self.location    
  else:    
  world[target]=Room(target)    
  self.location.exits[direction] = 
  Room(target)    
  world[target].exits[opdir(direction)] = self.location    
  def describeroom(self):    
  self.location.description = raw_input('>>')    def 
  do(self):    cmd = 
  string.split(raw_input('>'))    
  verb = cmd[0]    if len(cmd) > 
  1:    
  target = cmd[1]    
      if verb == 
  'l':    
  self.look()    elif verb in 
  ['n','s','e','w']:   
      
  self.move(verb)    elif verb == 
  'quit':    
  sys.exit()    elif verb == 
  'i':    for 
  a in 
  self.inventory:    
  print a.name    elif verb == 
  'dig':    
  self.dig(target)    elif verb == 
  'dr':    
  self.describeroom()    
  else:    
  print 'what?'
   
  class Thing:    def 
  __init__(self,name):    self.name = 
  name
   
  def opdir(direction):    if direction == 
  'n':    return 
  's'    if direction == 
  's':    return 
  'n'    if direction == 
  'e':    return 
  'w'    if direction == 
  'w':    return 
  'e'        p 
  = Player('david')room1 = Room([0,0])
   
  p.location = room1sword = Thing('sword')hat = 
  Thing('hat')p.inventory.append(sword)p.inventory.append(hat)while 
  1:    p.do()
  
  

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


Re: [Tutor] my text adventure

2005-12-03 Thread Dan Lowe
On Dec 3, 2005, at 9:40 PM, david wrote: sorry i forgot a subject line. i have looked at the pickle module and was able to pickle world. but i can't figure how to restore everything.import pickledef save_game(state, filename):    file = open(filename, 'w')    pickle.dump(state, file)    file.close()def load_game(filename):    file = open(filename, 'r')    state = pickle.load(file)    file.close()    return statesave_game(world, 'mygame')world = load_game('mygame')-- logic (n.): the art of being wrong with confidence. ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor