Re: dynamically creating variables

2006-03-03 Thread Crutcher
> Is it possible to do something like that? No, you can't change the binding of variables in your calling space. -- http://mail.python.org/mailman/listinfo/python-list

Re: Catch exceptions

2006-02-27 Thread Crutcher
Without seeing more of your code, I'm not sure what you are doing wrong. This works: ex.py vv def xopen(path): try: return open(path) except IOError, e: print 'Error:', e.args[1] xopen('xyzzy') ^^ $ python ex.py Error: No such file or direct

Re: different ways to strip strings

2006-02-27 Thread Crutcher
It is something of a navel (left over feature). "xyz".strip() is (I think) newer than string.strip() -- http://mail.python.org/mailman/listinfo/python-list

Re: different ways to strip strings

2006-02-27 Thread Crutcher
It is something of a navel (left over feature). "xyz".strip() is (I think) newer than string.strip() -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Crutcher
This seems great, except why can't I compare strings? It seems too useful when dealing with user input, or parsing messages or config files. >>> Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') >>> Weekdays.mon.__cmp__('mon') 0 Additionaly, perhaps the call method of the enumerati

Re: Use of __slots__

2006-02-26 Thread Crutcher
Steven is right, however, there is a way: def new_record(slotlist): class R(object): __slots__ = slotlist return R() record1 = new_record(["age", "name", "job"]) record1.age = 27 record1.name = 'Fred' record1.job = 'Plumber' record1.salary = 5 -- http://mail.python.org/mailman/listi

Re: Tail Call Optimization as a Decorator

2006-02-26 Thread Crutcher
I've tossed it to python-dev, but how do I submit it to the cookbook? -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a Zen language?

2006-02-26 Thread Crutcher
> My point is simply that, for some languages L, > "Zen and the art of L" or "The Tao of L" are plausible > titles ("Zen and the Art of Lisp Programming" would be plausible) but > for some languages they wouldn't ("The Tao of Fortran" ?) > Do you disagree? No, I don't disagree that people do this.

Re: How to use python regular expression to substitute string value

2006-02-26 Thread Crutcher
Are you sure node.data contains newlines? You could try just: print node.data print node.data.split('\n') This should give you an idea. From the interpreter: >>> s = """ ... abc ... def ... xyz""" >>> s.split('\n') ['', 'abc', 'def', 'xyz'] -- http://mail.python.org/mailman/listinfo/python-list

Tail Call Optimization as a Decorator

2006-02-26 Thread Crutcher
This is fun :) {Note: I take no responsibilty for anyone who uses this in production code} #!/usr/bin/env python2.4 # This program shows off a python decorator # which implements tail call optimization. It # does this by throwing an exception if it is # it's own grandparent, and catching such # ex

Re: How to use python regular expression to substitute string value

2006-02-26 Thread Crutcher
You don't really need regexes for this. Assuming there is no whitespace in any of your values, it should be really easy to parse the string. s = 'x:11 y:0 w:760 h:19 area:14440 areaPerCent:0 totalAreaPerCent:-3.08011e+16 type:3 path:///-/1/1' s.split() # break the string on whitespace > ['x:11',

Re: xslt queries in xml to SQL queries

2006-02-26 Thread Crutcher
> I don't know what it is with comp.lang.python/python-list these days > and the cheap put-downs. Unless you know the person you're responding > to personally, and thus the above counts as some kind of banter, you > would do better to keep the insults to yourself. You are completely right, I was o

Re: Is Python a Zen language?

2006-02-25 Thread Crutcher
You are a very silly person. You have tripped so many of my internet bullshit triggers that I think perhaps you are trolling. All languages alter the way you think. They structure the nature of questions you can ask, and problems you can solve. Do you understand 'Zen', by which I mean, have you de

Re: xslt queries in xml to SQL queries

2006-02-25 Thread Crutcher
Skipping ahead, let me try to rephrase this. First, this isn't really a python question, it is SQL, XSLT, and program design, but I'll try to answer. You have templates, they contain general layout stuff, and input fields. You are transforming them into HTML pages, and part of what you want to do

Re: Modify the local scope inside a function

2006-02-25 Thread Crutcher
Here you go. Unfortunate that you can't modify locals() easily, but there are other options. def foo(d): for k in d: exec '%s = %s' % (k, repr(d[k])) print a + b foo({'a':1, 'b':2}) -- http://mail.python.org/mailman/listinfo/python-list

New Module: CommandLoop

2006-02-19 Thread Crutcher
This is something I've been working on for a bit, and I think it is more or less ready to bring up on this list. I'd like to add a module (though probably not for 2.5). Before you ask, this module is _not_ compatible with cmd.py, as it is command oriented, whereas cmd.py is line oriented. Anyway,

Strange interaction between exec, dictionary subtypes, and global variables in 2.4

2005-12-30 Thread Crutcher
I've been playing with dictionary subtypes for custom environments, and I encountered a strange interaction between exec, dictionary subtypes, and global variables. I've attached a test program, but first I'd like to give some background. Python uses dictionary objects as symbol tables in it's exe