reload fails if module not in sys.path

2005-10-20 Thread Lonnie Princehouse
So, it turns out that reload() fails if the module being reloaded isn't in sys.path. Maybe it could fall back to module.__file__ if the module isn't found in sys.path?? ... or reload could just take an optional path parameter... Or perhaps I'm the only one who thinks this is silly: >>> my_module

Re: reload fails if module not in sys.path

2005-10-21 Thread Lonnie Princehouse
It's not just load_module. Reload fails on modules imported normally if their paths are no longer in sys.path. Easy to reproduce example: bash$ mkdir module_dir bash$ touch module_dir/plugin.py bash$ python Python 2.4.1 (#1, Sep 25 2005, 15:12:45) [GCC 3.4.3 20041125 (Gentoo 3.4.3-r1, ssp-3.4.3-

Re: reload fails if module not in sys.path

2005-10-21 Thread Lonnie Princehouse
> That's OK, but you may find fiddling with sys.path is more productive :-) Yeah, that's what I'm doing and it works just fine. When I stumbled over this behavior yesterday it seemed (and still does) like a low-priority bug in reload. I was hoping a guru would reply with something like, "Of cour

C extension + libm oddity [fmod(2.0, 2.0) == nan ?!]

2005-11-04 Thread Lonnie Princehouse
I've been trying to debug this for two days now, and it's a longshot but I'm hoping that someone here might recognize a solution. I've got a C extension which calls a function in a C library, which calls another function in another library, which calls another function, which calls fmod from the s

Re: C extension + libm oddity [fmod(2.0, 2.0) == nan ?!]

2005-11-04 Thread Lonnie Princehouse
> Have you compiled the C extension with all optimization turned off? Yes. The C extension's objects are compiled only with the debugging flag and -fPIC for position indepdendent code, necessary for shared objects. No optimization. The only things that have any optimization are Python and glib

Re: Pythonising the vim (e.g. syntax popups)

2005-11-09 Thread Lonnie Princehouse
There is a Python folding script, as someone already mentioned. That will help you track indentation, although it's not perfect (iirc, long triple quoted strings cause folding malfunctions) I don't know of any way to get dynamic help about functions, although it seems like an ideal use of Vim's b

Re: help make it faster please

2005-11-10 Thread Lonnie Princehouse
You're making a new countDict for each line read from the file... is that what you meant to do? Or are you trying to count word occurrences across the whole file? -- In general, any time string manipulation is going slowly, ask yourself, "Can I use the re module for this?" # disclaimer: unteste

Re: help make it faster please

2005-11-10 Thread Lonnie Princehouse
The word_finder regular expression defines what will be considered a word. "[a-z0-9_]" means "match a single character from the set {a through z, 0 through 9, underscore}". The + means "match as many as you can, minimum of one" To match @ as well, add it to the set of characters to match: wor

Re: What do you use as symbols for Python ?

2005-11-10 Thread Lonnie Princehouse
I use custom classes and the "is" operator... that way, things don't get confused with integers, and I have an object where repr(state) will give me more than an integer. (the integer approach works well enough but seems like a case of "I can program C in ANY language!") opened = type('opened', (

Re: wxPython newbie question, creating "mega widgets" , and DnD

2005-11-10 Thread Lonnie Princehouse
Yes, wx.Panel. > A side question - why is their a EVT_LIST_BEGIN_DRAG but no > EVT_LIST_END_DRAG, unlike tree's which have BEGIN and END? I need a > draggable list box, and would prefer to not handle low level mouse > events. Dunno. There is an EVT_LIST_COL_END_DRAG, though, maybe that will hel

Re: Python music interfaces

2005-11-10 Thread Lonnie Princehouse
Are you talking about audio files (wav, mp3) or MIDI? Converting audio files into discrete notes ("music recognition") is seriously non-trivial, although there are some commercial products you might be able to use for this. On the other hand, you could draw a spectrographs without too much troub

Re: 3-dimensional plot in Python?

2005-11-15 Thread Lonnie Princehouse
Google for "MayaVi" It's overkill for what you've described (it doesn't even make 2D graphs afaik), but it could draw your function as a 3D surface. And besides, it's way cool. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using printf in a C Extension

2005-12-09 Thread Lonnie Princehouse
printf will generally work in C extensions (although, as others have said, it goes to STDOUT which is not necessarily the same as Python sys.stdout) Try explicitly flushing the buffer with fflush(stdout) -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating Python wrapper for DLL

2005-06-28 Thread Lonnie Princehouse
ctypes! http://starship.python.net/crew/theller/ctypes/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-11 Thread Lonnie Princehouse
IIRC, the self.__dict__.update(locals()) trick confuses psyco. But you can make a decorator to achieve the same result. There's not really a convincing case for extending python syntax. def attribute_decorator(f): import inspect argnames = inspect.getargspec(f)[0] def decorator(*arg

Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-25 Thread Lonnie Princehouse
I haven't used PyGTK very much, so I can't comment on it. My last impression of GTK-on-Windows was that it wasn't very stable and didn't blend well with the Windows native look and feel, but that was a while ago and it has probably improved a great deal since then. I use wxPython, doing my develo

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Lonnie Princehouse
> Is there some equivalent feature in Python regexps? cpp_pat = re.compile('(/\*.*?\*/)|(".*?")', re.S) def subfunc(match): if match.group(2): return match.group(2) else: return '' stripped_c_code = cpp_pat.sub(subfunc, c_code) ...I suppose this is what the Perl code might do, but

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Lonnie Princehouse
> Is there some equivalent feature in Python regexps? cpp_pat = re.compile('(/\*.*?\*/)|(".*?")', re.S) def subfunc(match): if match.group(2): return match.group(2) else: return '' stripped_c_code = cpp_pat.sub(subfunc, c_code) ...I suppose this is what the Perl code might do, but

Re: Filtering terminal commands on linux

2005-07-29 Thread Lonnie Princehouse
Firstly, there's probably a better way to do whatever you're trying to do w.r.t cd/dvd burning. I'm not familiar with gear, but its webpage lists "Batch file scripting capability" as a feature, which suggests that you might be able to do what you want without parsing output intended for humans. T

Re: 2.3 or 2.4 on linux

2005-08-04 Thread Lonnie Princehouse
> I assume some system tools must use them, even if I don't. I don't know if > I can just copy all this into the 2.4 site-packages (deleting .pyc and .pyo) > and get what I need. Copying pure python site-packages from python23 to python24 should be safe, but the binaries (.so) will not work becau

Re: Parallel arithmetic?

2005-08-04 Thread Lonnie Princehouse
There are many ways to do this. None of them avoids looping, technically, although you can easily avoid the "for" syntax. -- Simple but wastes some memory c = [i-j for i,j in zip(a,b)] -- Using itertools.izip (python 2.3) c = [i-j for i,j in itertools.izip(a,b) ] -- Generator expression

Re: Why does __init__ not get called?

2005-08-08 Thread Lonnie Princehouse
Uh... are you actually trying to instantiate this class? mydate = DateTime(2005, 8, 8) The reason I ask is that __init__ /is/ called when I run your code on Python 2.4, provided that the above line is added to the end. -- http://mail.python.org/mailman/listinfo/python-list

Re: Import question

2005-08-09 Thread Lonnie Princehouse
Circular import issues can usually be resolved by moving import statements into the bodies of functions which aren't executed when the module itself is imported. Simple example: fileA.py -- import fileB as fb foo = 10# we're going to access foo from fileB fb.do_something_with_foo()

Re: Why does __init__ not get called?

2005-08-09 Thread Lonnie Princehouse
What kinds of illegal date values are you trying to represent? The reason I ask is that it's not going to be as easy as subclassing datetime... datetime is implemented in C. and so enforcement of legal values is going to be in the C code. For the time.h functions, you're also going to be constra

Re: How to print the name of a list?

2005-08-22 Thread Lonnie Princehouse
In general, no --- there is no unique mapping between references and names. For debugging, however, it is sometimes useful to try this kind of reverse lookup by iterating over the global dictionary: def guess_name(thing): for name, reference in globals.iteritems(): if thing is referen

wxPython StyledTextCtrl and tabs?

2005-09-13 Thread Lonnie Princehouse
Does anyone know of a way to make the wxPython StyledTextCtrl expand tabs into spaces? (yes, I'm trying to use it to edit Python code :P) -- http://mail.python.org/mailman/listinfo/python-list

Windows Python 2.4: Unbuffered flag causes SyntaxError on interactive sessions?

2005-09-13 Thread Lonnie Princehouse
>From the cmd shell on both Windows 2k and XP, I'm getting this weird syntax error in conjunction with the unbuffered flag. It works fine without -u. Has anyone else encountered it? This didn't happen with Python 2.2... C:\>python -u Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit

Re: wxPython StyledTextCtrl and tabs?

2005-09-13 Thread Lonnie Princehouse
That's exactly what I was looking for. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows Python 2.4: Unbuffered flag causes SyntaxError on interactive sessions?

2005-09-13 Thread Lonnie Princehouse
Weird. Did you build Python yourself? The 2.4.1 release on python.org is from March 30. I just tried ActiveState's 2.4.1... the same thing happens. -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-13 Thread Lonnie Princehouse
Will do -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-14 Thread Lonnie Princehouse
After doing some more reading, I now think this isn't a bug. Evidently the unbuffered flag not only makes stdin unbuffered, but it also forces it into binary mode. I didn't realize that when I posted earlier. So the SyntaxErrors arise because the interpreter isn't converting \r\n into \n because

Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-14 Thread Lonnie Princehouse
Yes. With the unbuffered flag, raw_input() strings on my box end in \r. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python GUIs

2005-09-21 Thread Lonnie Princehouse
B is a tuple if it's assigned that way. Tuples are immutable. To make a list instead, you need square brackets: B = ['\x12', '\x32'] Regarding your original post, you'll probably have to ask more specific questions if you want to get good answers. -- http://mail.python.org/mailman/listinfo/p

Re: Accessing Python parse trees

2005-03-03 Thread Lonnie Princehouse
No. I don't think it's possible to read the parse tree used by the interpreter, especially as it is being created. Here are a couple of kludgy ideas that might come close, though: 1. Use introspection to have your on_parsing function locate the and parse the code being executed. I'm not sure if

Re: python cvs interface?

2005-03-10 Thread Lonnie Princehouse
Unless your CVS repository is local, the overhead associated with calling CVS through system calls isn't going to be a bottleneck, and even then it shouldn't be too bad. Using one of the varieties of os.popen instead of os.system will make it easier to avoid disk I/O when communicating with the cv

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

2005-03-11 Thread Lonnie Princehouse
Any given Python object may be bound to multiple names or none at all, so trying to find the symbol(s) which reference an object is sort of quixotic. In fact, you've got None referenced by both "my" and "c" in this example, and in a more complicated program None will be referenced by dozens symbol

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

2005-03-11 Thread Lonnie Princehouse
Perhaps try something like this? variables = ['a', 'b', 'c'] defaults = { 'a': 'c:\\programs', 'b': 'd:\\data', # etc } try: settings = dict([(v, os.environ.get(v, defaults[v])) for v in variables]) except KeyError, k: # handle missing variable print "you have a problem with %s" % k.

Re: Getting current variable name

2005-03-17 Thread Lonnie Princehouse
> There should be an easier way that doesn't require stepping though the name list. Trying to find names bound to a particular object is a /very/ strange thing to want to do in Python. If this is for anything more than debugging diagnostics, it's probably better to use a dictionary explicitly for

Re: Newbie alert !

2004-12-03 Thread Lonnie Princehouse
> bou_asia=Button(fen1, text='Asia',\ >command=rings(size=41, offsetX=50,offsetY=22, > coul='yellow')) You're calling the rings function when you create the button. What you really want is for "command" to be a callable object that the button will invoke when it's clicked, e.

Re: Import a module without executing it?

2004-12-07 Thread Lonnie Princehouse
> The real question, I suppose, is "what is a good technique to find what > modules and classes implement or refer to particular names" I think your best bet is still to import the module and introspect it. It will execute some code, but (by convention) simply importing a module doesn't usually un

Re: MP3 - VBR - Frame length in time

2004-12-08 Thread Lonnie Princehouse
It might be much easier to use an external program to figure out the length. Here's an example that uses sox to convert just about any audio file into a raw format, and then determines duration by dividing length of the raw output by number of bytes per frame. I don't know if they make sox for Win

Re: Help beautify ugly heuristic code

2004-12-08 Thread Lonnie Princehouse
Regular expressions. It takes a while to craft the expressions, but this will be more elegant, more extensible, and considerably faster to compute (matching compiled re's is fast). Example using the top five from your function's comments: . host_patterns = [ . '^1Cust\d+\.tnt\d+\..*\.da\.uu\

Re: Help beautify ugly heuristic code

2004-12-08 Thread Lonnie Princehouse
I don't think a Bayesian classifier is going to be very helpful here, unless you have tens of thousands of examples to feed it, or unless it was specially coded to first break addresses into better tokens for classification (such as alphanumeric strings and numbers). The series of if host.find(...

Re: Help beautify ugly heuristic code

2004-12-09 Thread Lonnie Princehouse
Doh! I misread "a" as host instead of ip in your first post. I'm sorry about that; I really must slow down. Anyhow, I believe you can still do this with only compiling a regex once and then performing a few substitutions on the hostname. Substitutions: 1st byte of IP => (0) 2nd byte of IP =>

module file length limitations on windows?

2004-12-16 Thread Lonnie Princehouse
I've run into some eccentric behavior... It appears that one of my modules is being cut off at exactly 2^14 characters when I try to import it. Has anyone else encountered this? I can't find any mention of such a bug, and stranger yet, other modules that exceed 16384 characters seem to work just

Re: module file length limitations on windows?

2004-12-16 Thread Lonnie Princehouse
No non-printing characters. However, I just tried copying the file (from a windows cmd prompt), and the copy was cut off at the same point the interpreter is getting to. When I edit the file with vim, though, the whole thing comes through. I think this is a pretty strong indication that this monke

Re: Tuple Question

2004-12-21 Thread Lonnie Princehouse
> Why is this? It should work.Are you using an old version of Python? -- http://mail.python.org/mailman/listinfo/python-list

Re: list Integer indexing dies??

2004-12-23 Thread Lonnie Princehouse
> ;-) gotcha. But shouldn't this be valid too?? > >>> 123232[0] No, it shouldn't be valid. It makes the implicit assumption that you want the base 10 digit, which isn't really a good assumption to make in the world of computers. Programmers are just as likely to want hexadecimal, and arguments c

Re: C pointers/Python

2005-03-22 Thread Lonnie Princehouse
"len" is a built-in function in Python, so you probably don't want to use it as a variable name. What is this C code actually trying to do? Don't try to transliterate it; instead, read up on how lists and slicing work, and rewrite it in Python starting from a higher level of abstraction. One hin

Re: Changing the value of a for loop index on the fly

2005-03-23 Thread Lonnie Princehouse
i = 0 while i < len(subject): if subject[i] in preps: psubject.append(noun_syn_parser(subject[0:i])) subject[0:i] = [] i = 0 else: i += 1 Gabriel F. Alcober wrote: > Hi! There goes a newbie trouble: > > for i in range(0, len(subject)): > if subject[i] in preps: >

Re: newbie help

2005-03-23 Thread Lonnie Princehouse
How about describing what your program is supposed to /do/ instead of posting C code? What are the "buffers" for? This group might be more helpful if you did that. If you really do need this sort of random-access character buffer, you have a couple of options. Python strings aren't mutable, so t

Re: newbie help

2005-03-23 Thread Lonnie Princehouse
buf1 = [None] * 512 buf2 = [None] * 512 (Not quite the same as C because the list isn't filled with gibberish...) -- http://mail.python.org/mailman/listinfo/python-list

Re: Data types

2005-03-24 Thread Lonnie Princehouse
Lists, tuples, and dictionaries are built-in types. Classes are the mechanism for user-defined types in Python. -- http://mail.python.org/mailman/listinfo/python-list

Re: The Greatest News Ever!

2005-03-28 Thread Lonnie Princehouse
I complained to blogger about this spammer earlier, and shortly after receiving the automated "Thanks for your feedback..." message, I got another message from Blogger support: > Hi there, > > Thanks for writing us regarding this possible Terms of Service > violation. We will examine it soon and

Re: Stylistic question about inheritance

2005-03-31 Thread Lonnie Princehouse
If you try this sort of inheritance, I'd recommend writing down the formal grammar before you start writing classes. Don't try to define the grammar through the inheritance hierarchy; it's too easy to accidentally build a hierarchy that can't be translated into a single-pass-parsable grammar... I

Re: Stylistic question about inheritance

2005-03-31 Thread Lonnie Princehouse
Well, that's true, but I meant to convey that no grammatical entity is the base class of another entity, so it's a flat inheritance tree in that respect. ASTNode would not be something that the parser would know anything about. I guess that's sort of moot if your expression trees are just a contr

Re: Supercomputer and encryption and compression @ rate of 96%

2005-04-14 Thread Lonnie Princehouse
That's pretty good, but I have an algorithm that compresses data into zero bits. def compress(data): pass To decompress, you simply generate a random string of random length using a random number generator based on quantum states, with the expectation that you happen to be in one of the possibl

Re: newbie question

2005-04-19 Thread Lonnie Princehouse
What is usually meant when Python is mentioned in the context of game scripting is that it's relatively easy for a game's developers to embed a Python interpreter into the game. Python would then be used to control higher-level gameplay elements like artificial intelligence while the game's native

Re: Faster os.walk()

2005-04-20 Thread Lonnie Princehouse
If you're trying to track changes to files on (e.g. by comparing current size with previously recorded size), fam might obviate a lot of filesystem traversal. http://python-fam.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Injecting code into a function

2005-04-25 Thread Lonnie Princehouse
I expect you could combine the following with decorators as an easy way to grab a function's locals just before it exits... you could also use exec or eval to execute code in the function's local namespace. --- # Try it: def trace_returns(frame, event, arg):

Re: Bounding box on clusters in a 2D list

2005-04-25 Thread Lonnie Princehouse
def floodFill4(m, r, c, newCol, oldCol): stack = [ (r, c) ] while stack: r, c = stack.pop() if c >=0 and c < maxc and r >=0 and r< maxr and m[r][c]==oldCol: m[r][c] = newCol stack += [ (r+1, c), (r-1, c), (r, c+1), (r, c-1) ] -- http://mail.python.org/mailman/listinfo/pyth

Re: Injecting code into a function

2005-04-25 Thread Lonnie Princehouse
I don't know of a way to get the current global trace function. This could certainly cause trouble if you're trying to be compatible with other packages that want to use their own trace functions (like psyco, or debuggers). Does anyone know how to get the global trace? On the other hand, the lo

Re: Injecting code into a function

2005-04-26 Thread Lonnie Princehouse
> I think that Your trace_returns function is actually a global trace > that returns itself and does not handle the 'call' event. By returning itself, the global trace also becomes the local trace. The code in bdb.py does the same thing--- self.trace_dispatch is set as the global trace, and retur

Re: Pythonic way to do static local variables?

2005-04-26 Thread Lonnie Princehouse
A quick, hackish way to keep a static variable is to declare it as a parameter and give it a default value. The parameter list is evaluated when the function is compiled, not when it is called. The underscores are added as per convention to indicate that the variable is special/private. Example

Re: Pythonic way to do static local variables?

2005-04-26 Thread Lonnie Princehouse
A quick, hackish way to keep a static variable is to declare it as a parameter and give it a default value. The parameter list is evaluated when the function is compiled, not when it is called. The underscores are added as per convention to indicate that the variable is special/private. Example

Re: how can I sort a bunch of lists over multiple fields?

2005-04-27 Thread Lonnie Princehouse
Might as well make a class for Book instead of dealing with buckets of lists... class Book(object): def __init__(self, title, author, publisher, isbn, date):# add more fields according to CSV self.__dict__.update(locals()) # lazy! def __repr__(self): return '<"%s" by %

Re: how can I sort a bunch of lists over multiple fields?

2005-04-28 Thread Lonnie Princehouse
> I'd be just such a newbie; I don't understand why it would matter if I > left the book instance referencing itself It's just kind of sloppy and unnecessary to have self.self > firstly, I am trying hard to figure out how to create a new file with > the list rather than print to standard out

Re: how can I sort a bunch of lists over multiple fields?

2005-04-28 Thread Lonnie Princehouse
> Likewise, the above is basically just an inefficient way of writing: > > def date_key(book): > return book.data > > def author_and_date_key(book): > return (author_key(book), date_key(book)) It's certainly more elegant, but I wanted to talk about the mechanics of comparison functions =)

Re: how can I sort a bunch of lists over multiple fields?

2005-04-29 Thread Lonnie Princehouse
key and cmp are equivalent for non-trivial cases (defined below), and for trivial cases the performance will be a trade-off between more function calls with cmp versus more memory use with key. Granted, for the smallish lists that the majority of Python sorts are done on, key is probably the bette

Re: module exports a property instead of a class -- Evil?

2005-04-29 Thread Lonnie Princehouse
The property factory is nice, but have you considered subclassing property? class Mode(property): def __init__(self, *vals): if [v for v in vals if not isinstance(v,str)]: raise ValueError, 'Mode values must be strings' else: self.values = list(vals) property.__init__(sel

Re: Sorting an Edge List

2005-04-29 Thread Lonnie Princehouse
Sort demands a unique ordering, which isn't present in your case. You're constructing an Eulerian path. See Fleury's algorithm: http://en.wikipedia.org/wiki/Eulerian_path -- http://mail.python.org/mailman/listinfo/python-list

Re: ANNOUNCE; Try python beta

2005-12-19 Thread Lonnie Princehouse
Pretty neat =) But aren't you concerned about security? Letting anybody execute arbitrary Python expressions (and therefore also arbitrary system commands?!) on your box --- even from within a FreeBSD jail --- seems a bit dangerous. -- http://mail.python.org/mailman/listinfo/python-list

Re: Augmented generators?

2006-01-10 Thread Lonnie Princehouse
AFAIK there's no way to have "yield" produce anything other than a generator. You could achieve the syntax you want with a decorator, although under the hood it would still be iterating over a (key,value) tuples so there's not really any point. class GeneratorTupleWrapper: def __init__(self, g):

Re: Help with fast tree-like structure

2006-01-25 Thread Lonnie Princehouse
> A = [, B, C] >B = [, D] >C = [] Why store node data in the same list that contains the children? It seems like the OO approach would be more extensible, e.g. class Node: def __init__(self): self.children = [] # list of nodes # store node data as attributes... # If you wa

any way to customize the is operator?

2006-01-26 Thread Lonnie Princehouse
There doesn't seem to be any way to customize the behavior of "is" as can be done for other operators... why not? -- http://mail.python.org/mailman/listinfo/python-list

Re: any way to customize the is operator?

2006-01-26 Thread Lonnie Princehouse
> (objects are not allowed to lie about who they are, or what they are). Dangit! I need to find a less honest programming language. Anyone have a Perl cookbook handy? ... -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the public callables of self

2006-02-09 Thread Lonnie Princehouse
import inspect myCallables = [name for name, value in inspect.getmembers(self) if not name.startswith('_') and callable(value)] Instance methods aren't in self.__dict__ because they're a part of the class. To made a comprehensive list of all the attributes available to an instance, you have to t

Re: Finding the public callables of self

2006-02-09 Thread Lonnie Princehouse
Ha! I didn't realize that was getmembers' implementation. What a hack ;-) In fact, your way is faster, since getmembers is taking the time to sort its results (presumably so that repeated calls to the same object will yield the same list; I don't think dir has a guaranteed ordering) -- http://

Re: is there a better way?

2006-02-10 Thread Lonnie Princehouse
everybody is making this way more complicated than it needs to be. storage = list[:list.index(O)] incidentally, "list" is the name of a type, so you might want to avoid using it as a variable name. -- http://mail.python.org/mailman/listinfo/python-list

appending to a list via properties

2006-02-10 Thread Lonnie Princehouse
Here's a curious hack I want to put up for discussion. I'm thinking of writing a PEP for it. Observation - I found myself using this construct for assembling multiple lists: foo = [] qux = [] while some_condition: a, b = calculate_something() foo.append

Re: any way to customize the is operator?

2006-02-10 Thread Lonnie Princehouse
> Why did you want to customize "is"? Well, mostly out of principle ;-) But also because I'm wrapping a C library which passes around C structs which are wrapped in shim C++ classes for a Boost.Python layer. Boost Python does a marvelous job of translating between Python and C++ data types; when

Re: equivalent functions?

2006-02-10 Thread Lonnie Princehouse
Very close... it is equivalent to: apply_each = lambda fns, args=[]: [f(*args) for f in fns] The asterisk in f(*args) expands the sequence to fill the arguments to f, where as f(args) would pass the args as only the first argument to the function. apply is deprecated, replaced by the syntax:

Re: Merging two lists of data (Pythonic way)

2006-02-16 Thread Lonnie Princehouse
You might consider writing two classes to represent the values in list1 and list2. It might be more Pythonic than sloshing around all of those lists and dictionaries. But as it is, it looks like you want to find matching pairs of lists and dictionaries from list1 and list2, respectively: # index

ANN: yet another python graphviz binding (yapgvb) 1.1.1

2006-02-22 Thread Lonnie Princehouse
Introducing Yapgvb, a Python wrapper around the AT&T's graph layout library Graphviz. Features: - A nice clean Pythonic interface - Boost.Python wrapper around the C libraries; no more fiddling with system calls to dot. - Read and write .dot files using Graphviz's own library routines. - T

automatic html generation for documentation?

2006-02-24 Thread Lonnie Princehouse
I plan on writing some documentation that will consist of blocks of commentary with interspersed snippets of syntax-colored Python code and the occaisional image. Does anyone know of a package that will take a high level description of what I just described and auto-generate clean-looking web page

Re: Simulation Programming Skills and Python

2006-03-06 Thread Lonnie Princehouse
Object oriented languages lend themselves fairly well to this sort of modeling, and a strong programmer in any language should be able to take a good description of a well thought-out model and write some code for it. However, by far the harder part is designing a good model. Asking whether all p

Debugging C extensions on Gentoo

2005-05-04 Thread Lonnie Princehouse
I've spent the last couple of hours trying to figure out how to set breakpoints in Python C extensions under gdb 6.2 using Gentoo Linux, and finally figured it out. So for posterity (aka Google), here's the trick: If GDB is giving you the message "Unable to find dynamic linker breakpoint funct

Re: python and glut

2005-05-04 Thread Lonnie Princehouse
See if you can run `glxgears`, and read the output of `glxinfo`. If neither of those work, you will probably have better luck on a debian or XFree86/xorg forum than on c.l.py -- http://mail.python.org/mailman/listinfo/python-list

Re: how can I sort a bunch of lists over multiple fields?

2005-05-04 Thread Lonnie Princehouse
> If you want to compare partial keys, often the simplest approach is to > use tuples as keys, with the elements of the tuple being the "parts" of > the key. Python's standard tuple comparison mechanism takes care of the > rest. Right, but suppose it's expensive to generate each part of the key -

Re: python and glut

2005-05-05 Thread Lonnie Princehouse
Welcome to the exciting world of trying to make graphics work on Linux =) DRI is direct rendering. The Module section of your XF8Config should have: Load "glx" Load "dri" Load "GLCore" That probably won't solve things. Google for some combination of ("debian" + "xfree86" + your vide

Re: Need a little parse help

2005-05-10 Thread Lonnie Princehouse
write() doesn't automatically add a newline like print does. You can either do: outputfile.write(words[1] + '\n') or print >> outputfile, words[1] -- http://mail.python.org/mailman/listinfo/python-list

Re: Python features

2005-05-12 Thread Lonnie Princehouse
> Quoting from that link: > There are three main types of programming languages. > > * Imperative > * Functional > * Declarative > Aren't functional languages a subset of declarative? (c.f. http://en.wikipedia.org/wiki/Declarative_programming) -- http://mail.python.org/mailman/l

Re: speeding up Python script

2005-05-18 Thread Lonnie Princehouse
Quick tip- Try xrange instead of range. This will use dramatically less memory if your search space is large, which will speed things up /if/ your machine is being forced to swap. Besides that, without seeing the code for your functions, it's hard to offer more advice. Your algorithm is necess

Re: Function Serialization

2005-06-01 Thread Lonnie Princehouse
By default, shelve uses pickle to serialize objects.Pickle doesn't actually serialize functions... it just saves the function's name and name of its defining module, and upon loading attempts to find that function again. This is pretty much /never/ going to work the way you want it to if you'r

Any way to not create .pyc files?

2005-06-09 Thread Lonnie Princehouse
In short: Is there any way to run Python WITHOUT trying to create .pyc files (or .pyo) or to have Python not attempt to import the .pyc files it finds? Reason: We have a site-specific package installed on a network drive[1]. When anyone with write access imports this package, the network drive

Re: Any way to not create .pyc files?

2005-06-09 Thread Lonnie Princehouse
Of course! ZIP imports! I think that will solve the problem nicely. We already have a starter application that locates the codebase on the network drive, so it wouldn't be too hard to implement the "keep a local copy up to date" solution. But I'll try the zip idea first. Many thanks for your h

Re: Any way to not create .pyc files?

2005-06-09 Thread Lonnie Princehouse
>> PEP 304 would have helped, but it appears to be deceased. > Not sure it's deceased (a dead parrot?) - it's on the standards track, > it hasn't been rejected, and Skip has actually provided a patch to > implement the solution. It is possible that PEP 304 is really just pining for the fjords, bu

Re: Any way to not create .pyc files?

2005-06-09 Thread Lonnie Princehouse
> You didn't really describe the nature of the problem. Perhaps the whole > .pyc thing is a bit of a red herring, and the real problem lies > elsewhere? What are the actual symptoms of your problem? Yes, the .pyc thing could be a red herring. I was hoping to find an easy way to disable them to

SOAP server with WSDL?

2006-04-24 Thread Lonnie Princehouse
Does anyone know of a Python SOAP package that will publish a SOAP service /and/ generate a corresponding WSDL file? Looking at SOAPpy and ZSI, it seems that their WSDL support is limited to client-side stuff. -- http://mail.python.org/mailman/listinfo/python-list

Re: Deferred Evaluation in Recursive Expressions?

2006-05-09 Thread Lonnie Princehouse
The first 'typedef' line will have a NameError when it tries to evaluate LinkedListB -- http://mail.python.org/mailman/listinfo/python-list

  1   2   >