Re: Help with regexp please

2005-07-22 Thread Scott David Daniels
Felix Collins wrote: > Hi, > I'm not a regexp expert and had a bit of trouble with the following search. > I have an "outline number" system like > 1 > 1.2 > 1.2.3 > I want to parse an outline number and return the parent. Seems to me regex is not the way to go: def parent(string):

Re: PEP on path module for standard library

2005-07-22 Thread Scott David Daniels
(a FAT drive) might naturally be str, while C: (an NTFS drive) might naturally be unicode. Even worse, would be a path that switches in the middle (which it might do if we get to a ZIP file or use the newer dir-in-file file systems. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mai

Re: tuple to string?

2005-07-23 Thread Scott David Daniels
is last should be: >>>''.join(map(chr, (0x73, 0x70, 0x61, 0x6D))) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: "Aliasing" an object's __str__ to a different method

2005-07-23 Thread Scott David Daniels
example, you could also define the methods like: class MyEditClass(MyClass): def __repr__(self): return "I, %s, am being edited" % MyClass.__repr__(self) When to use super rather than direct access to the superclass is an involved discussion. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: multiple inheritance super()

2005-07-26 Thread Scott David Daniels
super (A, self) .__init__ () print '' class B (object): def __init__ (self): print '', super (B, self) .__init__ () print '' class C (A, B): def __init__ (self):

Re: Create a variable "on the fly"

2005-07-28 Thread Scott David Daniels
y then, wherever your python scripts use MY_XYZ, you begin the script with "import MY" and change every "MY_XYZ" to "MY.XYZ". --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: functions without parentheses

2005-07-28 Thread Scott David Daniels
Jerry He wrote: > ... Is there some way to define [examine] so I can call it like > examine "string" > instead of examine("string")? Perhaps you are looking for ipython (google for it) if all you are looking for is ease of interactive entry.

Re: baffling error-handling problem

2005-07-28 Thread Scott David Daniels
mode4l_000.py with the moral equivalent of from MCMC import LikelihoodError then this is what is going wrong. By the way, if it were I, I'd:raise LikelihoodError(p) just so I could discover a bit of what went wrong. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: can list comprehensions replace map?

2005-07-29 Thread Scott David Daniels
return itertools.izip(*seqs) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: A replacement for lambda

2005-07-29 Thread Scott David Daniels
nction until the second with is encountered. Then you need to backtrack to the shift and convert it to a pair of less-thans before you can successfully translate it. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: HELP:sorting list of outline numbers

2005-08-02 Thread Scott David Daniels
'1.12', '1.1', '3.1'] decorated = [(numparts(txt), txt) for txt in lst] decorated.sort() lst[:] = [txt for code, txt in decorated] --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: HELP:sorting list of outline numbers

2005-08-03 Thread Scott David Daniels
Delaney, Timothy (Tim) wrote: > Scott David Daniels wrote: >>For 2.3: (using DSU -- Decorate, Sort, Undecorate) ... >> lst = ['1', '1.2', '1.12', '1.1', '3.1'] >> decorated = [(numparts(txt), txt) for tx

Re: namespaces

2005-08-09 Thread Scott David Daniels
tor technique to get to some (but not necessarily all) of the attributes. Think of this technique as a hack to get to a goal, rather than a good technique to use; good for debugging, not so nice for production work. If you still don't know how to do this from this admittedly sketchy description,

Re: Does any one recognize this binary data storage format

2005-08-09 Thread Scott David Daniels
t; That sounds pretty unlikely. Are you 100% sure you're looking > at the correct bytes? Perhaps the one bit is an exponent -- some kind of floating point based format? That matches the doubling of all digits. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: How to determine that if a folder is empty?

2005-08-09 Thread Scott David Daniels
while len(stack) and not (root.startswith(stack[-1]) and root[len(stack[-1])] == os.path.sep): stack.pop() stack.append(root) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: "Ordered" dicts

2005-08-10 Thread Scott David Daniels
= sorted(mydict.items()) as in: For key, value in sorted(mydict.items()): print '%s -> %r' % (key, value) -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Using globals with classes

2005-08-12 Thread Scott David Daniels
lare "global varname" inside the function or method in which you do the writing. Simply using (reading) a global in a module does not require the "global" declaration. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: simpli int/str problem

2005-08-12 Thread Scott David Daniels
parameter style your DB interface supports, you may use at least one of: cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(?, ?)", [(holder['str_name'], holder['int_name'])]) or cursor.execute("INSERT INTO TABLENAME(AH, BH)

Re: UCALC equivalent

2005-08-12 Thread Scott David Daniels
;) << endl; The python equivalent: exec "def area(length,width): return length*width" exec "def frac(x): return abs(abs(x) - int(abs(x)))" exec "def test(): return 5" exec "def abc(x, y=10): return x + y" exec &

Re: UCALC equivalent

2005-08-12 Thread Scott David Daniels
Max Erickson wrote: > Scott David Daniels <[EMAIL PROTECTED]> wrote in > news:[EMAIL PROTECTED]: > > >>max wrote: >> From the web page referenced: >> ... >> cout << ucEval("abc(5)-abc(3,4)*(#b01101 shl 1)") >> <

Re: UCALC equivalent

2005-08-13 Thread Scott David Daniels
John Machin wrote: > Scott David Daniels wrote: >> max wrote: >>> Larry Bates <[EMAIL PROTECTED]> wrote in >> The python equivalent: >> ... >> exec "def shl(x, y): return x * 2^y" > > Perhaps this should be: > exec "def

Re: help with mysql cursor.execute()

2005-08-14 Thread Scott David Daniels
antage of this two-step approach, but the DB interface is designed to allow it, so the parameterization is constrained. See if something like this works: sql = 'select * from %s where cusid like ? ' % name Cursor.execute(sql, (recID,)) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Py_DECREF Question:

2005-08-15 Thread Scott David Daniels
count; ... PyObject* num = Py_BuildValue("i", 10); precount = num.ob_refcnt; PyList_Append(list, num); ... If you need to do the DECREF, precount should exceed num.ob_refcnt. If they match, the "PyList_Append" call "stole&qu

Re: determine variable type

2005-08-18 Thread Scott David Daniels
able is an > integer? if isinstance(var, (int, long)): print 'var (%r) is an integer' % var elif isinstance(var, float) and int(var) == var: print 'var (%r) is a float that could be an integer' % var else: print 'var (%r) is not an i

Re: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ?

2005-08-20 Thread Scott David Daniels
delete all the .py, .pyc, .pyo files you put in the zip. Compress them using "DEFLATE", since Python's zipfile module doesn't do BZIP2 compression (yet). --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie]search string in tuples

2005-08-20 Thread Scott David Daniels
ot;airplane", "car", "boat"] select = None while missing(select, vehicles): select = raw_input("Which vehicle?") For this particular test, there happens to be an idiom you can use: vehicles = ["airplane", "car", "boat"] select = None while select not in vehicles: select = raw_input("Which vehicle?") --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ?

2005-08-22 Thread Scott David Daniels
rst use of a module, and > perhaps aviod the surprise of an installation that continues to grow > after a completed installation... Another reason is to allow efficient access to python for users who do not have permission to create files (the .pyc and .pyo files) in Python's library dire

Re: Reg Python Byte code

2005-08-22 Thread Scott David Daniels
ll of this you will have to think a lot about exactly what code is being executed. A help to figuring this out is to remember that if you import a module you get a new and different copy of the module from the main program. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Error with Python

2005-08-22 Thread Scott David Daniels
(accessible as news:gmane.comp.python.wxpython), and if it important enough to you, offer a bounty for help reflecting its importance to you. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Sanitizing untrusted code for eval()

2005-08-22 Thread Scott David Daniels
pping source code to python. Eventually there will be another form available (the AST form), but that will show up no earlier than 2.5. As a matter of pure practicality, it turns out you can probably use almost the same code to look at 2.3 and 2.4 byte codes. --Scott David Daniels [EMAIL PROTECTE

Re: Sorta noob question - file vs. open?

2005-08-23 Thread Scott David Daniels
t;MyFile.txt", "w") > MyFile.write("This is a test.") > MyFile.close() I cannot help you if you don't tell me what went wrong. Both bits of code seem to do the same thing for me. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Externally-defined properties?

2005-08-24 Thread Scott David Daniels
obj): try: return thevar except NameError: raise AttributeError > Am I about to shoot myself in the foot? Well, usually all this playing is good for understanding how Python works, but makes your connections less than explicit, and we know that explic

Re: Sorta noob question - file vs. open?

2005-08-24 Thread Scott David Daniels
back to open(). I expect somewhere previously in the same frame (perhaps the interpreter top level) you had done either "file = open(...)" or "file = file(...)" which would prevent you from getting to the file in __builtins__. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: argument matching question

2005-08-26 Thread Scott David Daniels
if values: total = values[0] for element in values[1:]: total += element return total else: return 0 --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: classes and list as parameter, whats wrong?

2005-08-26 Thread Scott David Daniels
print sys.getrefcount(q), r = None print sys.getrefcount(q) Note that whenever you call sys.getrefcount, the argument to the function itself will increase the count by 1. This demonstrates that: print sys.getrefcount(object()) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Python library/module for MSAccess

2005-08-26 Thread Scott David Daniels
efault DB _is_ the Jet Database engine. Easiest access for me is through the win32 module 'odbc'. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: trictionary?

2005-08-28 Thread Scott David Daniels
except KeyError: bin[week] = [full, not full] --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type

2005-09-03 Thread Scott David Daniels
trical situations. Although it is _way_ too late to try something like this, once upon a time you could have done all of this using the one's complement operator: ~0 does exist and is distinct from 0. So you could talk about a slice: str[4 : ~2] and so on. --Scott David Daniels

Re: dual processor

2005-09-05 Thread Scott David Daniels
for fear of leaking memory, even though it will most often turn out the objects being DECREF'ed by distinct threads are themselves distinct. In short, two Python threads running simultaneously cannot trust that any basic Python data structures they access are in a consistent state without som

Re: Possible improvement to slice opperations.

2005-09-05 Thread Scott David Daniels
, which > is exactly the same as you would write today. Actually, a[1 : -1] is how you get to drop the first and last characters today. I suspect you knew this and were just a bit in a hurry criticizing a lame-brained scheme. -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: infinite loop

2005-09-06 Thread Scott David Daniels
ght want to rewrite as: def main(): choices = {1: function_a, 2:function_b} choices[option]() while iteration: choices[option]() --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Unusual Python Sighting

2005-09-10 Thread Scott David Daniels
In article: http://humorix.org/articles/2005/08/notice/ ... 6. The use of semantically significant whitespace in Python® programs might be protected by intellectual property laws in five (5) countries, --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org

Re: Unexpected Behavior Iterating over a Mutating Object

2005-09-13 Thread Scott David Daniels
sed(list(enumerate(data))): if 'DEL' in text: removed.append(text) else: del data[position] This uses reversed so positions remain valid as the list is pruned. --Scott David [EMAIL PROTECTED] [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Software bugs aren't inevitable

2005-09-17 Thread Scott David Daniels
Sybren Stuvel wrote: > ... Computers aren't happy. They couldn't care less about the > programming language. This reminds me of a quote I love (and wish I could cite the originator): Don't anthropomorphize computers, they don't like that. --Scott David Daniels

Re: Organising a python project

2005-09-20 Thread Scott David Daniels
# doc string, author, copyright, and license info # and a line like: __version__ = "0.2" product.py setup.py --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: zlib written in python

2005-09-20 Thread Scott David Daniels
LIB_VERSION There were some fixes you can see described at 'http://www.zlib.net/' that are going into python 2.5. If you can figure it out yourself, you could build an alternative zlib module to either sit beside /DLLs/zlib.pyd or replace it. --Scott David Daniels [EMAIL PROTECTED] -- ht

Re: Object default value

2005-09-20 Thread Scott David Daniels
bj = SomeDemo() obj.foo = 123 obj.foo += 1 del obj.foo --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting tired with py2exe

2005-09-20 Thread Scott David Daniels
rk on py2exe over the years, which has benefited the Windows > Python community immeasurably. I second this. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: What am I doing wrong?

2005-09-21 Thread Scott David Daniels
s = [] else: self.folders = folders ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: C#3.0 and lambdas

2005-09-21 Thread Scott David Daniels
(x1, y1), (x2, y2) = p1, p2 return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: I am not able to setup pydb2 ! Any help !

2005-09-21 Thread Scott David Daniels
if necessary, and are built by people with the right to redistribute it. So, at the cost of a two-step install, you can legally build and distribute Python 2.4 apps. In case you don't know: I am not a lawyer; don't regard my guesses about the legal status of things as definitive; don&#

Re: I am not able to setup pydb2 ! Any help !

2005-09-21 Thread Scott David Daniels
Fredrik Lundh wrote: > Scott David Daniels wrote: > >>MS is fairly determined to get you develop money; you may not >>redistribute the C runtime with your app from the "free" stuff. > > that's a myth, based on a flawed reading of the MS license. to

Re: time challenge

2005-09-22 Thread Scott David Daniels
o work, and _then_ if you have problems ask "smart questions" here about specific issues you have with getting your code to work. See: http://www.catb.org/~esr/faqs/smart-questions.html -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: negative integer division

2005-02-07 Thread Scott David Daniels
ons to get the canonical value, and the guarantee simplifies the user's code. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: negative integer division

2005-02-09 Thread Scott David Daniels
Jive Dadson wrote: I've forgotten what we are arguing about, but I'm sure I'm right. ^^^ QOTW --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: A great Alan Kay quote

2005-02-09 Thread Scott David Daniels
forts to measure ease of use and reliability. They did not simply start with a good (or great) guess and charge forward. They produced the mouse, and the earliest "linked" documents that I know of. http://sloan.stanford.edu/MouseSite/1968Demo.html --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Iteration over two sequences

2005-02-11 Thread Scott David Daniels
David Isaac wrote: "Scott David Daniels" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]: Numarray is the future, Numeric is the "past", This statement is not obviously true. See the recent discussion on the developer lists. (Search for Numeric3.) Alan Isaac

For American numbers

2005-02-12 Thread Scott David Daniels
if magnitude >= 1.0: break if magnitude < .001: return 'zero %s' % units else: prefix = '' if value < 0: return '-%.3f %s%s' % (magnitude, prefix, units)

Re: For American numbers

2005-02-14 Thread Scott David Daniels
Neil Benn wrote: Scott David Daniels wrote: Kind of fun exercise (no good for British English). what's American about it? If anything, it's more French than American ;-) Well, actually this started with scaling integers, and I was worried about a billion / billionth (and up / down). I

Re: Newbie help

2005-02-14 Thread Scott David Daniels
lso be a task from a tutorial page. I'd just make sure to hand out clues rather than answers, and wait for evidence of work between clues. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterator / Iteratable confusion

2005-02-14 Thread Scott David Daniels
e: print 'and', blunge Because of how iterables work, you know you can do this locally without looking all around to see what "whatever" is. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with the sort() function

2005-02-22 Thread Scott David Daniels
NameError: def enumerate(iterable): ... try: test = sorted except NameError: def sorted(iterable, cmp=None, key=None, reverse=False): ... --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: pydoc documentation- referred to Michele answer

2005-02-22 Thread Scott David Daniels
or syntax that works without showing syntax that doesn't work, along with the _complete_ error messages that you get when you try your syntax. You seem to be asking for help without assisting your rescuers. You should be trying to make it easy for them. Google for "smart questions". --S

Re: user interface for python

2005-02-23 Thread Scott David Daniels
s, but they don't _guarantee_ it. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: assert 0, "foo" vs. assert(0, "foo")

2005-02-23 Thread Scott David Daniels
ike: if __debug__ and test: raise AssertionError, text As far as raise goes, where you have been writing: raise "some complaint" you could simply use: raise ValueError, "some complaint" or: raise ValueError("some complaint") --Scott David Daniels

Re: Dynamically pass a function arguments from a dict

2005-02-24 Thread Scott David Daniels
thon/Recipe/52549 not show you what args it accepts, but decorators, a Python 2.4 invention, will typically obscure the interface of the decorated function. Since they wrap _any_ function call, they typically take the most general arguments possible in order to accommodate the widest range of fu

Re: Canonical way of dealing with null-separated lines?

2005-02-24 Thread Scott David Daniels
hould be a more cannonical way. You could start with this code and add '\0' as a line terminator: http://members.dsl-only.net/~daniels/ilines.html --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Interesting decorator use.

2005-02-24 Thread Scott David Daniels
e code this way allows you to say, watcher-by-watcher, where to get the parent for the message box. You would then use it as follows: @exceptionwatcher(someholder, 'frame') def something(somearg) if somearg is not None: raise ValueE

Re: Canonical way of dealing with null-separated lines?

2005-02-24 Thread Scott David Daniels
y sysadmin (and many other users) would want to do on practically a daily basis. The general model is that you produce a module, and if it gains a audience to a stable interface, inclusion might be considered. I'd suggest you put up a recipe at ActiveState. --Scott David Daniels [EMAIL PRO

Re: strange SyntaxError

2005-02-25 Thread Scott David Daniels
t variables the exec can write: exec 'k = 3 * k' in globals(), locals() This is why locals() does not do write-back. The rule below (which was high on the list when searching for exec), tells the exact rules, the above stuff is just why. http://www.python.org/doc/2.4/ref/dyna

Re: strange SyntaxError

2005-02-26 Thread Scott David Daniels
Attila Szabo wrote: 2005, Feb 25 -> Scott David Daniels wrote : Attila Szabo wrote: >>...lambda x: 'ABC%s' % str(x) ... OK, to no real effect, in main you define an unnamed function that you can never reference. Pretty silly, but I'll bite. This code was simplified,

Re: Newbie question -- fiddling with pictures.

2005-02-28 Thread Scott David Daniels
splay an image in Python? - I've run over Tkinter, but obviously in all the wrong places. You probably want Fredrik Lundh's PIL (Python Imaging Library) package to read and manipulate the images, and then use TKinter to display the images. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.

Re: Possible to import a module whose name is contained in avariable?

2005-03-07 Thread Scott David Daniels
me = 'libinfo.' + modulename module = __import__(fullname) sys.modules[fullname] = module module.libinfo() CFLAGS += module.CFLAGS Remember, this is computer science, not mathematics. We are allowed to use more than a single (possibly strangely draw

Re: select random entry from dictionary

2005-03-07 Thread Scott David Daniels
Tony Meyer wrote: How can I select a random entry from a dictionary, regardless of its key-values? a = random.choice(d.keys()) a, d[a] Or even: key, value = random.choice(d.items()) or: value = random.choice(d.values()) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org

Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Scott David Daniels
re out how to accomplish your real goal in the normal flow of the language. -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to make a list unique?

2005-03-08 Thread Scott David Daniels
can define sorted in 2.3 as: def sorted(iterable): result = list(iterable) result.sort() return result The full sorted functionality can be (and has been) defined in 2.3, but just using 2.4 would be a better bet. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.o

Re: looking for way to include many times some .py code fromanotherpython code

2005-03-08 Thread Scott David Daniels
do_a_bunch(self) def some_other_method(self): ... do_a_bunch(self) def mangle(self): ... do_other_stuff(self) I'm newbie, sure. That is why I was trying to figure out your original requirement, not how to accomplish your original plan. I was trying to see

Re: Sorting dictionary by 'sub' value

2005-03-08 Thread Scott David Daniels
e: ordered_keys = sorted(v, key=lambda name: v[name][9]['date']) In 2.3, or earlier, use "decorate-sort-undecorate": decorated = [(value[9]['date'], key) for key, value in v.iteritems()] decorated.sort() result = [key for key, date in deco

Re: None in string formatting

2005-03-08 Thread Scott David Daniels
y string? If you want the other effect, you can always do: "%s" % (x or '') --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: split a string with quoted parts into list

2005-03-10 Thread Scott David Daniels
entries into a list of strings? First break into strings, then space-split the non-strings. def splitup(somestring): gen = iter(somestring.split('"')) for unquoted in gen: for part in unquoted.split(): yield part yield gen.next().join('""') --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie : prune os.walk

2005-03-10 Thread Scott David Daniels
r root, dirs, files in os.walk(base): if root != base: dirs[:] = [] --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: multiple buffers management

2005-03-11 Thread Scott David Daniels
html For some versions of "buffers", this might work. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: How to turn a variable name into a string?

2005-03-11 Thread Scott David Daniels
Stewart Midwinter wrote: I'd like to do something like the following: a = 1; b = 2; c = None mylist = [a, b, c] for my in mylist: if my is None: print 'you have a problem with %s' % my #this line is problematic You have a problem with None What I want to see in the output is: How do

Re: How to turn a variable name into a string?

2005-03-12 Thread Scott David Daniels
frobotz = os.environ['NotThere'] jangle = int(os.environ['WEIGHT']) ... except KeyError, e: print 'Mising env var %r. Fix it and try again' % e.args raise SystemExit --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: a program to delete duplicate files

2005-03-12 Thread Scott David Daniels
st likely to find them distinct in three comparisons. Using hashes, three file reads and three comparisons of hash values. Without hashes, six file reads; you must read both files to do a file comparison, so three comparisons is six files. Naturally, as it grows beyond three, the deference grows

Re: PEP 309 (Partial Function Application) Idea

2005-03-12 Thread Scott David Daniels
ry definition in the first place; I couldn't convince myself there was a good, obvious, resolution. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: large amount of or's

2005-03-13 Thread Scott David Daniels
irs where position is an offset within the "current" block. ''' You might consider taking a look at providing that form. -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Who Knows of a Good Computational Physics Textbook?

2005-03-14 Thread Scott David Daniels
Look into Ruth Chabay's physics books for a possibly appropriate choice and surpisingly on-topic choice. That is, unless you are talking computational physics at the level of "ab initio chemistry" and friends. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/m

Re: slicing, mapping types, ellipsis etc.

2004-11-29 Thread Scott David Daniels
m__(self, *args, **kwargs): print '%s._gi_(*%r, **%r):' % (self.name, args, kwargs), return input() >>> c = CheckOut('a') >>> b = c[1, ...] c.gi(*(1, Ellipsis), **{}): self.name * 7 >>> b 'aaa' --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP generic objects

2004-11-30 Thread Scott David Daniels
: class Hash(object): def __init__(self, **kwargs): for key,value in kwargs.items(): setattr(self, key, value) __getitem__ = getattr __setitem__ = setattr --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: documentation for PyArg_ParseTupleAndKeywords

2004-11-30 Thread Scott David Daniels
Steven Bethard wrote: Thanks for the pointers. What's the "doco gadget" you're talking about? I conclude from this question that you are not using a Windows python. I suspect, therefore, the answer is Gilda Ratner's " Never mind." --Scott Davi

Re: weird behaviour of "0 in [] is False"

2004-11-30 Thread Scott David Daniels
...: often, however, such names are necessary when discussing abstract code properties. -Scott -- http://mail.python.org/mailman/listinfo/python-list

Re: recombination variations

2004-12-02 Thread Scott David Daniels
if char in multis: break else: yield string raise StopIteration parts = multis[char] prelude, string = string[:pos], string[pos+1:] for expansion in expanded(string, multis): for middle in parts: yield prelude + middle + expansion --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP generic objects

2004-12-02 Thread Scott David Daniels
Nick Craig-Wood wrote: Scott David Daniels <[EMAIL PROTECTED]> wrote: You can simplify this: class Hash(object): def __init__(self, **kwargs): for key,value in kwargs.items(): setattr(self, key, value) __getitem__ = getattr __setitem__ = setattr That d

Re: Module list generation

2004-12-03 Thread Scott David Daniels
quot; For earlier pythons, use: python -c "import sys; nms = sys.modules.keys(); nms.sort(); print nms" or: python -c "import sys; print sys.modules.keys()" if you don't care about order. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: finding byte order

2004-12-03 Thread Scott David Daniels
? > > Thanks! How about sys.byteorder? At least if you are using array.array, note the "byteswap" method: >>> import array >>> v = array.array('h',range(8)) >>> v array('h', [0, 1, 2, 3, 4, 5, 6, 7]) >>> v.byt

Re: Few things

2004-12-03 Thread Scott David Daniels
_111 == 7..77377 1..10010010101 9..9329765872 7..767 Takes a bit to associate 9 with base ten, but lexing the number is duck soup. Note I am not advocating this syntax any more than Josiah is advocating his. I just find alternate representations interesting. --Scott David Daniels [EMAIL

Re: finding byte order

2004-12-03 Thread Scott David Daniels
biner wrote: > I am using a program that has to read binary data from files coming > from different machines. The file are always written with big endian. Diez B. Roggisch wrote: [Scott David Daniels wrote] How about sys.byteorder? This doesn't help, as he wants to read files f

Re: GUI Frames and classmethod

2004-12-03 Thread Scott David Daniels
ept KeyError: raise NoRuleError, (self.current, newstate) # or pass to ignore missing transitions. else: action(self) This method belongs in BaseFrame and assumes a class like: class NoRuleError(ValueError): def __str__(self): return 'No transition defined for %r -> %r' % self.args --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: GUI Frames and classmethod

2004-12-06 Thread Scott David Daniels
Zak Arntson wrote: On Fri, 03 Dec 2004 14:48:30 -0800, Scott David Daniels <> wrote: question: A dictionary of dictionaries is slower than a dictionary of tuples, right? Because when Python accesses a dictionary, it produces a hash from the key and finds that in its hash table. Produ

<    3   4   5   6   7   8   9   10   11   12   >