useless python - term rewriter

2011-11-18 Thread Sean McIlroy
## term rewriter (python 3.1.1) def gettokens(string): spaced = string.replace('(',' ( ').replace(')',' ) ') return spaced.split() def getterm(tokens): if tokens[0] in '()': term = [] assert tokens[0] == '(' tokens.pop(0) while not tokens[0] == ')':

Re: change text of a Tkinter Button by clicking it

2011-09-29 Thread Sean McIlroy
never mind. i found it. -- http://mail.python.org/mailman/listinfo/python-list

change text of a Tkinter Button by clicking it

2011-09-28 Thread Sean McIlroy
hello (how) can you change the text of a Tkinter Button by clicking it? something like def click(index): return lambda: buttons[index].text = 'hello' buttons = [Button(root,command=click(index)) for index in range(numbuttons)] only with an attribute that Buttons actually have. sorry to have to

midi file parser

2009-11-23 Thread Sean McIlroy
A Sequence is a list [FormatType, TimeDivision, Tracks] where *) FormatType is in [0,1,2] *) TimeDivision is either [TicksPerBeat] with TicksPerBeat in range (2**15) or [FramesPerSecond, TicksPerFrame] with FramesPerSecond in range (2**7) and TicksPerFrame in range(2**8) *) Tracks is a

Re: chr / ord

2009-11-03 Thread Sean McIlroy
thanks. that did the trick. in case anyone else is in the same boat as myself, here are the relevant correspondences: string - [int] bytes - [int] --- -- lambda string: [ord(x) for x in string] list lambda ints: ''.join([chr(x)

chr / ord

2009-11-02 Thread Sean McIlroy
hello how do i say chr and ord in the new python? the functions below (which work in 2.6.6) show what i'm trying to do. thanks if you can help. def readbytes(filepath): return [ord(x) for x in open(filepath,'rb').read()] def writebytes(numbers,filepath):

midi file toolkit

2009-09-05 Thread Sean McIlroy
## python 2.6.2 from tkFileDialog import askopenfilename, askdirectory def nowindow(function): def windowless(): from Tkinter import Tk Tk().withdraw() return function() return windowless getfilename = nowindow(askopenfilename) getdirectoryname =

Re: tkinter: get filename of askopenfilename

2009-06-25 Thread Sean McIlroy
i think what he means is to put the global declaration inside the function that assigns to filename: def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [(allfiles,*)]) as it was, the function was creating a new variable called filename and

tictactoe (reprise)

2008-06-28 Thread Sean McIlroy
AUTHOR: Sean McIlroy LANGUAGE: Python 2.5 OVERVIEW: instances of tictactoeplayer play optimal tictactoe SPECIALIZED TYPES: player={ex,oh}; empty={blank}; cell=player+empty; board=[cell] TYPE RELATIONS: bool(c)==True for any c in cell ex, oh, blank = 'X', '0', ' ' linear = [[0,1,2],[3,4,5

override the interpreter's parser?

2008-04-12 Thread Sean McIlroy
hi all i'd like to write a module that, when run in the interpreter, would cause the interpreter to read certain strings that would normally be rejected as syntax errors (strings beginning with the @ symbol, say) and pass them on to an object defined in the aforementioned module. where should i

Re: override the interpreter's parser?

2008-04-12 Thread Sean McIlroy
never mind. i found it. -- http://mail.python.org/mailman/listinfo/python-list

is this a bug? (python 2.3)

2007-03-09 Thread Sean McIlroy
hi all when i run this code in python 2.3 ## BEGIN CODE class warfare: def __init__(self): self.pairs = [[0,0]]*2 def __str__(self): return str(self.pairs) def setfirst (self,i,value): self.pairs[i][0] = value def setsecond(self,i,value): self.pairs[i][1] =

Re: is this a bug? (python 2.3)

2007-03-09 Thread Sean McIlroy
thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: Need an identity operator because lambda is too slow

2007-02-18 Thread Sean McIlroy
On Feb 17, 9:59 pm, Deron Meranda [EMAIL PROTECTED] wrote: [snip] this may be really dense, but i'm curious what's wrong with the multiplexer idiom: for item in some_sequence: item2 = (not some_rare_condition and item) or \ (some_rare_condition and

alias for data member of class instance?

2007-02-05 Thread Sean McIlroy
hi all is there a way to do this ... class clown: def __init__(self): self.x = 0 self.y = ALIAS(self.x) ## FEASIBLE ? ... so that you get results like this ... krusty = clown() krusty.x 0 krusty.y 0 krusty.x = 1 krusty.x 1 krusty.y 1 ... ? thanks.

tkinter blues (greens, reds, ...)

2005-10-28 Thread Sean McIlroy
hi all i recently wrote a script that implements a puzzle. the interface mostly consists of a bunch of colored disks on a tkinter canvas. the problem is that the disks change their colors in ways other than the way they're supposed to. it certainly isn't just a bug in my script, since i can

Re: tkinter blues (greens, reds, ...)

2005-10-28 Thread Sean McIlroy
i'm using the canned colors (pink, orange, etc). should i try changing to explicit color specifications to see if that makes a difference? i'm not sure what the other guy meant by a soft toy, but i take it the idea is to try and construct a correctness proof for the script, and see what keeps it

Re: tkinter blues (greens, reds, ...)

2005-10-28 Thread Sean McIlroy
hi ron changing from english words to hexadecimal numerals did the trick for me, so everything's cool now. thanks for looking at it. peace -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Sean McIlroy
Tom Anderson wrote: snip So, if you're a pythonista who loves map and lambda, and disagrees with Guido, what's your background? Functional or not? glad you asked. personally i don't know lisp (or scheme), but now i've decided to learn it, because eventually it will no longer be possible in

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Sean McIlroy
Peter Hansen wrote: snip Sean, what gave you the impression this would change? just inductive reasoning. i've been wrong before (like anyone who makes that claim), and i'm a former python enthusiast, so my judgement must be colored to some extent by bitterness. maybe they have solid reasons for

Re: Two questions on lambda:

2005-06-24 Thread Sean McIlroy
def PRINT(x): print x f = lambda: PRINT(hello) ### def let(x,y): globals()[x] = y return True f = lambda x: let('y',x*x) and y+y -- http://mail.python.org/mailman/listinfo/python-list

Re: Null String Variable

2005-05-16 Thread Sean McIlroy
well, somebody's already pointed out that bool(msg)==False iff msg==''. i'm curious to know what's wrong with simply writing if msg=='': ## do_something -- http://mail.python.org/mailman/listinfo/python-list

Re: the bugs that try men's souls

2005-04-04 Thread Sean McIlroy
Jordan Rastrick [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... snip Wow. I'd resigned myself to the task of reformulating my question in an intelligent way, I stopped by just to leave a little note to the effect that the thread wasn't dead, and I find out the question's been

Re: the bugs that try men's souls

2005-04-04 Thread Sean McIlroy
later Wow again. I had a real V8 moment when I looked at your solution (smacking my forhead, groaning ruefully, etc). You were right: my intention was simply to hide the trivial cases from view; I completely missed the fact that I was now testing for membership in a different set. I should have

the bugs that try men's souls

2005-04-03 Thread Sean McIlroy
This needs some background so bear with me. The problem: Suppose p is a permutation on {0...n} and t is the transposition that switches x and y [x,y in {0...n}]. A stepup pair (just a term I invented) for p is a pair (a,b) of integers in {0...n} with ab. A stepup pair (a,b) for p is an inversion

Re: mysteriously nonfunctioning script - very simple

2005-03-27 Thread Sean McIlroy
Heiko Wundram [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... snip Why not try the following: snip I did try it, and it didn't work either. It appears there must be something wrong with my computer, hopefully something benign. Thanks anyway. Peace, STM --

Re: mysteriously nonfunctioning script - very simple

2005-03-26 Thread Sean McIlroy
## Peter Hansen [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... Sean McIlroy wrote: Can anybody help me make sense of the fact that the following script doesn't work? It's so simple I can't imagine what I'm missing. Any help will be much appreciated. Always

mysteriously nonfunctioning script - very simple

2005-03-25 Thread Sean McIlroy
Can anybody help me make sense of the fact that the following script doesn't work? It's so simple I can't imagine what I'm missing. Any help will be much appreciated. Peace, STM ## ALARM CLOCK: from time import sleep,time,localtime wakeuptime = input('hours: '), input('minutes: ') onehourlater

how to use structured markup tools

2005-03-19 Thread Sean McIlroy
I'm dealing with XML files in which there are lots of tags of the following form: abx/bcy/c/a (all of these letters are being used as 'metalinguistic variables') Not all of the tags in the file are of that form, but that's the only type of tag I'm interested in. (For the insatiably curious, I'm

Re: how to use structured markup tools

2005-03-19 Thread Sean McIlroy
Exactly what I was looking for. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

seeking tree-browser widget for use with Tkinter

2005-03-06 Thread Sean McIlroy
I'm looking for a widget, to be used with Tkinter, that displays a tree whose leaves are strings. I thought there was something like that in the Python Megawidgets, but when I look at the documentation (http://pmw.sourceforge.net/doc/refindex.html), it doesn't seem to be there. Any advice will be

Re: canvassing for assistance

2005-03-03 Thread Sean McIlroy
'scale' puts the lower-right corner of a bounding box where the pointer is, while keeping the upper-left corner where it was before (or, if the relevant item's coordinates aren't of bounding-box type, the function does nothing). Thanks for the link. Peace, STM [EMAIL PROTECTED] [EMAIL

Re: String Replace Problem...

2005-02-28 Thread Sean McIlroy
I can't claim to have studied your problem in detail, but I get reasonable results from the following: filename = 'Errors.txt' S = open(filename,'r').read().split() f = lambda x: (x[0]=='@' and x[6:] + '.0') or (x=='/' and x + '\n') or x open(filename,'w').write(' '.join(map(f,S))) HTH

canvassing for assistance

2005-02-28 Thread Sean McIlroy
Hi all! I've written a utility for making diagrams. It could also be a good environment for experimenting with a Tk canvas, so I'm including the code here (see below). The problem is that, when I save a canvas and include the resulting postscript file in a LaTeX document, I often find that the

Re: String Replace Problem...

2005-02-28 Thread Sean McIlroy
Alright, now it's too much. It's not enough that you're eliminating it from the language, you have to stigmatize the lambda as well. You should take some time to reflect that not everybody thinks the same way. Those of us who are mathematically inclined like the lambda because it fits in well with

'modal dialogs' with Tkinter

2005-02-22 Thread Sean McIlroy
success. Any assistance would be greatly appreciated. Peace, Sean McIlroy -- http://mail.python.org/mailman/listinfo/python-list

two questions - no common theme

2005-02-09 Thread Sean McIlroy
And now for a pair of questions that are completely different: 1) I'd like to be able to bind callbacks to presses of the arrow buttons on the keyboard. How do you say that in Tkinter? 2) The function 'listdir' in os.path returns a list of all the files in the given directory - how do I get hold

Save the Canvas!

2005-02-01 Thread Sean McIlroy
I'd like to be able to save a Tkinter Canvas in a format other than postscript (preferably gif). Is there a tool out there for accomplishing that? Any help will be much appreciated. Peace, STM -- http://mail.python.org/mailman/listinfo/python-list

reusing Tkinter Canvases

2005-01-14 Thread Sean McIlroy
I'd like to save one Tkinter Canvas in order to use it on another Canvas later. The problem is that it gets saved as EPS but it needs to be GIF to be reuseable. How can I convert that format? Peace, STM -- http://mail.python.org/mailman/listinfo/python-list

unicode mystery

2005-01-10 Thread Sean McIlroy
I recently found out that unicode(\347, iso-8859-1) is the lowercase c-with-cedilla, so I set out to round up the unicode numbers of the extra characters you need for French, and I found them all just fine EXCEPT for the o-e ligature (oeuvre, etc). I examined the unicode characters from 0 to 900

mysterious buggy behavior

2005-01-08 Thread Sean McIlroy
While fiddling with a little script I ran into a problem that baffles me completely. Maybe I'm missing something completely obvious, and somebody out there can diagnose the problem at a glance. Anyway, that's the hope. Here's the code (it plays tic tac toe): Something goes wrong with the time

cosmetic Tkinter question

2004-12-26 Thread Sean McIlroy
I've got a bunch of Frames, all packed into the root window with side=TOP, and in each Frame I've got a Checkbutton packed with side=LEFT. I expected the Checkbuttons to be flush with the left edge of the window, but they're not, and it looks a little gross. How do I get them to align? --

example code sought

2004-12-18 Thread Sean McIlroy
There's something quite simple I'd like to do, but I'm hampered by lack of knowledge regarding Tkinter. If someone could help me out with a snippet of maximally-simple code showing, in general terms, how to do this, that would be really great. What I want to do is simply to move a shape around on

Re: Mean, median, and mode

2004-12-05 Thread Sean McIlroy
mean = lambda x: sum(x)/len(x) median = lambda x: (max(x)-min(x))/2 mode = lambda x: max([(x.count(y),y) for y in x])[1] Robert Brewer [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... (now that we have a meaningful subject line) Alfred Canoy wrote: I'm just new to