Re: Where to find python c-sources

2005-09-29 Thread Michael J. Fromberger
gt; look? I recommend you look in the "Modules" subdirectory of the Python source tree. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Parser suggestion

2005-09-29 Thread Michael J. Fromberger
anning Parsing And Rewriting Kit) http://pages.cpsc.ucalgary.ca/~aycock/spark/ You might also find the following an interesting read, if this sort of thing interests you: http://www.python.org/sigs/parser-sig/towards-standard.html Cheers, -M -- Michael J. Fromberger | Lecturer

Re: Burrows-Wheeler (BWT) Algorithm in Python

2005-11-02 Thread Michael J. Fromberger
for the Sep. 1996 issue of Dr. Dobbs, you might have a look: http://www.dogma.net/markn/articles/bwt/bwt.htm I hope this helps you get started. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Burrows-Wheeler (BWT) Algorithm in Python

2005-11-03 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > Michael J. Fromberger: > > I can send you a Python implementation I wrote, if you like; but if > > you're interested in better understanding how the transform works, > > I would recommend you try

Re: Loop until condition is true

2005-06-18 Thread Michael J. Fromberger
"j test" instruction. Even if forward conditional jumps are bad for your particular architecture, this method avoids the problem neatly. Personally, I'd be pretty suspicious of the quality of a compiler that produced radically different code for these two constructs without s

Re: Permutation Generator

2005-08-12 Thread Michael J. Fromberger
ccur in ALL positions, not just the beginning and the end. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacing large number of substrings

2005-09-04 Thread Michael J. Fromberger
exp = re.compile('|'.join(re.escape(x) for x in r.keys())) . return exp.sub(lambda m: r.get(m.group()), s) Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: add sys to __builtins__

2005-09-05 Thread Michael J. Fromberger
u draw the line? Do you really want to hard-code user opinions into the language? Right now, we have a nice, simple yet effective mechanism for controlling the contents of our namespaces. I don't think this would be a worthwhile change. -1. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: add sys to __builtins__

2005-09-06 Thread Michael J. Fromberger
aying you couldn't deal with this, but it rules out some of the more obvious ways of detecting and automatically handling this kind of substitution. Naturally, you might well ask, "why would you do such a fool thing?" To this I can only respond: "Never underestimate the inge

Re: encryption with python

2005-09-07 Thread Michael J. Fromberger
ed back to the > originals. > > It would be great if there exists a library already written to do this, > and if there is, can somebody please point me to it?? I recommend you investigate PyCrypto: http://www.amk.ca/python/code/crypto http://sourceforge.net/projects/pycrypto

Re: Crypto.Cipher.ARC4, bust or me doing something wrong?

2005-09-20 Thread Michael J. Fromberger
gt; enc = cipher.new("abcdefgh") >>> dec = cipher.new("abcdefgh") >>> x = enc.encrypt("This is some random text") >>> x "\x05o\xd5XH|\xa4\xfc\xf7z\xecd\xe92\xfb\x05rR'\xbf\xc0F\xfc\xde" >>> y = dec.decrypt(x) >&

Re: Replace string except inside quotes?

2004-12-03 Thread Michael J. Fromberger
, "bar") It's not the most elegant solution in the world. This code does NOT deal with the problem of commented text. I think it will handle triple quotes, though I haven't tested it on that case. At any rate, I hope it may help you get started. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: variables exist

2005-04-17 Thread Michael J. Fromberger
## ==> False >>> lloc = "foo!" >>> print isset('lloc')## ==> True Perhaps this is not the most elegant solution, but I believe it handles scoping correctly. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: can't solve an exercise-help me with it

2006-01-11 Thread Michael J. Fromberger
) = 4 * atan(1/5) - atan(1/239) Or, pi = 16 * atan(1/5) - 4 * atan(1/239). The Taylor series will converge more quickly for atan(1/5) and atan(1/239). (LaTeX: \mathrm{atan}(x) = \sum_{i=0}^\infty\frac{(-1^i)x^i}{2i+1}) Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer

Dispatch with multiple inheritance

2006-07-18 Thread Michael J. Fromberger
It seems to me that one should not have to "know" (i.e., write down the names of) the ancestors of C in order to dispatch to superclass methods in D, since C and D share no common ancestors south of object. Is there a better (i.e., more elegant) way to handle the case

Re: Dispatch with multiple inheritance

2006-07-19 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>, "Michele Simionato" <[EMAIL PROTECTED]> wrote: > Michael J. Fromberger ha scritto: > > > Consider the following class hierarchy in Python: > > > > > Is there a better (i.e., more elegant) way to handle the ca

Re: Dispatch with multiple inheritance

2006-07-19 Thread Michael J. Fromberger
stuctor it is an initializer Yes, you're right; I apologize for the imprecision. However, for the purposes of this example, the distinction is irrelevant. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth Colle

Re: Dispatch with multiple inheritance

2006-07-19 Thread Michael J. Fromberger
_init__(self, ...) form is probably the best solution! Thanks for your feedback. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Semantics of propagated exceptions

2006-07-21 Thread Michael J. Fromberger
Or, if you really want to use one of the existing exception types, then perhaps you can catch the exceptions from functions called by f, within f itself, and raise some other error (or suppress the errors, if appropriate). Cheers, -M -- Michael J. Fromberger | Lecturer, Dep

Re: Arrghh... Problems building Python from source on OS X --

2006-06-28 Thread Michael J. Fromberger
GNU readline I installed via Darwin ports. The Tk headers allow pythonw to build properly. Having configured, I built and installed via: make sudo make frameworkinstall I hope this may be helpful to you. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Python 2.5 and Unicode on MacOS

2006-09-21 Thread Michael J. Fromberger
m with Unicode support in the MacOS build of Python 2.5. For reference, I have done a framework build of Python, and it seems to work fine for everything else I have tried. Do you have any idea what might be causing this trouble? I'd be grateful for your insights. Cheers, -M -- Michael J

Re: +1 QOTW

2006-09-24 Thread Michael J. Fromberger
on, as the "anti-Perl," is heavily invested in maintaining Order. > > > > In the state of the onion address? > > > > http://www.perl.com/pub/a/2006/09/21/onion.html > > There is also this: > 'But I think the basic Perl paradigm is "Whatever-orie

Re: How to sort list

2006-11-23 Thread Michael J. Fromberger
option is to use the .sort() method of a list: Emails.sort(key = lambda s: list(reversed(s.split('@' The "key" parameter specifies how to obtain a sort key from each element in the source list. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Michael J. Fromberger
]]) for k in dict1 if dict1[k] in dict2) Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Unique Elements in a List

2005-05-09 Thread Michael J. Fromberger
ctly once, and pos is its index in the original sequence. This implementation traverses the input sequence exactly once, and requires storage proportional to the length of the input. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/

Re: a dict trick

2007-08-02 Thread Michael J. Fromberger
value = d.get('sex', 'unknown') This accomplishes what your above code does, using a method of the built-in dict object. If you also wish to ADD the new value to the dictionary, you may also use the following: value = d.setdefault('sex', 'unknown')

Re: boolean operations on sets

2007-08-06 Thread Michael J. Fromberger
descendants also behave in this manner, as do the AND and OR of Lisp or Scheme. It is possible that beginners may find it a little bit confusing at first, but I believe such confusion is minor and easily remedied. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression Grouping

2007-08-12 Thread Michael J. Fromberger
"abc", and the result shows you only the last occurrence of the matching. Compare this with the following: ] import re ] m = re.match('([abc]+)', 'abc') ] m.groups() => ('abc',) I suspect the latter is what you are after. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: tempfile.mkstemp and os.fdopen

2007-08-28 Thread Michael J. Fromberger
ile descriptor, it does not have a convenient way to obtain the file's name. However, you might also want to look at the TemporaryFile and NamedTemporaryFile classes in the tempfile module -- these expose a file-like API, including a .name attribute. Assuming tempfile.mkstemp()

Re: Image manipulation

2007-08-28 Thread Michael J. Fromberger
p://newcenturycomputers.net/projects/gdmodule.html> I do not know, however, whether or not the Python wrapper supports the animated GIF portions of the library. You'll probably have to do some digging. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Scie

Re: fcntl problems

2007-08-31 Thread Michael J. Fromberger
, ] import errno ] errno.errorcode[35] 'EDEADLOCK' Note that some codes have multiple names (e.g., EAGAIN and EWOULDBLOCK) so that this lookup may not return exactly the name you're expecting. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Sci

Re: how to remove multiple occurrences of a string within a list?

2007-04-04 Thread Michael J. Fromberger
count = {} for elt in lst: count[elt] = count.get(elt, 0) + 1 return [elt for elt in lst if count[elt] == 1] This solution is not particularly tricky, but it has the nice properties that: 1. It works on lists of any hashable type, not just strings, 2. It preserves the order of the u

Re: How to initialize a table of months.

2007-04-15 Thread Michael J. Fromberger
t by using time.strptime(), e.g., import time def month2int(mName): return time.strptime(mName, '%b').tm_mon # parses "short" names Without knowing anything further about your needs, I would probably suggest the latter simply because it makes the hard work be somebody else's problem. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing problems: A journey from a text file to a directory tree

2007-09-18 Thread Michael J. Fromberger
.: test1 = ''' [New client]. |-Invoices |-Offers |--Denied |--Accepted |---Reasons |---Rhymes |-Delivery notes ''' from StringIO import StringIO result = parse_folders(StringIO(test1)) As the documentation suggests, the result is a nested dictionary structure, representing the folder structure you encoded. I hope this helps. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing problems: A journey from a text file to a directory tree

2007-09-19 Thread Michael J. Fromberger
t; [New client]. > > Won't work with the dot on the end. My mistake. The period was a copy-and-paste artifact, which I missed. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: frange() question

2007-09-21 Thread Michael J. Fromberger
range itself is not written as a generator, it does return a generator as its result. The syntax is like that of list comprehensions; see: <http://docs.python.org/ref/genexpr.html> Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting a list numbers stored as strings

2007-09-24 Thread Michael J. Fromberger
"] > > thanks, > > aine Try: lst.sort(key = lambda s: int(s)) Assuming, of course, that "lst" is your original list; this will sort it in place. Also, you should probably read about the "sorted" function here: <http://docs.python.org/lib/built-in-funcs.

Re: Last iteration?

2007-10-19 Thread Michael J. Fromberger
def marked(self): | return self._end And finally, matching: | class matching (marker): | def __init__(self, seq, func): | super(matching, self).__init__(seq) | self._func = func | self._mark = False | | def next(self): | out = super(matching, sel

Re: Iteration for Factorials

2007-10-22 Thread Michael J. Fromberger
an you now see how you would re-write "fact3" into legal Python code, using this equivalence? Once you have done so, you will also be able to get rid of the extra accumulating parameter, and then you will have what you wanted. I hope this helps. Cheers, -M -- Michael J. Fromber

Re: Loop three lists at the same time?

2007-11-14 Thread Michael J. Fromberger
n, <http://docs.python.org/lib/built-in-funcs.html> Look near the bottom of the page. Example: zip([1,2,3], [4,5,6], [7,8,9]) ==> [(1, 4, 7), (2, 5, 8), (3, 6, 9)] Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~st

Re: Python Exponent Question

2007-12-17 Thread Michael J. Fromberger
*v**v = 2**2**2**2 = 65536 > >>> > > I would expect 2**2**2**2 to be 256 Python's ** operator associates to the right, not to the left; thus, 2 ** 2 ** 2 ** 2 ... really means 2 ** (2 ** (2 ** 2)) ... and not ((2 ** 2) ** 2) ** 2 ... as you seem to expect. As

Re: Splice two lists

2006-05-06 Thread Michael J. Fromberger
> [a,1,b,2,c,3] as the result. > > I've been searching around but I can't seem to find a good example. Here's one possibility: list(reduce(lambda s, t: s + t, zip(L1, L2), ())) -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www

Re: Enumerating Regular Expressions

2006-05-08 Thread Michael J. Fromberger
regular expression operators if you wanted. The basic problem isn't all that hard to solve, though the full generality of the re module's input syntax is far more expressive than truly "regular" expressions from language theory. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding yesterday's date with datetime

2006-05-15 Thread Michael J. Fromberger
y = datetime.today() yesterday = today - timedelta(1) # See the .month, .day, and .year fields of yesterday Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list