On Jan 11, 9:44 am, Mike <[EMAIL PROTECTED]> wrote:
> On Jan 11, 8:41 am, Lonnie Princehouse <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > I'm the author of Yapgvb, a Python binding for Graphviz. Yapgvb
> > enjoys modest success, but for some time it has bee
I'm the author of Yapgvb, a Python binding for Graphviz. Yapgvb
enjoys modest success, but for some time it has been in dire need of a
Python 2.5 build for Windows. I'm posting this message in the hopes of
finding someone who is interested in making this build.
This is a relatively quick task for
List comprehensions appear to store their temporary result in a
variable named "_[1]" (or presumably "_[2]", "_[3]" etc for nested
comprehensions)
In other words, there are variables being put into the namespace with
illegal names (names can't contain brackets). Can't someone come up
with a bette
A search to see how many words from the text belong to
english/german/spanish common word dictionaries would be an easy way to
get a crude guess at the language.
--
http://mail.python.org/mailman/listinfo/python-list
The first 'typedef' line will have a NameError when it tries to
evaluate LinkedListB
--
http://mail.python.org/mailman/listinfo/python-list
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
I'm hesitant to resort to tricks like "import pyexpat before wx, so
that symbols are loaded from the right library".
Luckily, I stumbled onto pxdom. It's a pure-python DOM implementation,
and switching to it was as easy as this:
# import xml.dom.minidom as dom
import pxdom as dom
--
http://mai
In general, you're right - if speed is a concern, loops should be used
instead of recursion in Python when possible.
In this case, the recursive overhead is insignificant compared to the
expense of iterating over the sequence at every iteration. By the time
there are 70 stack frames of recursion
> What's wrong with the following ?
>
> def morris(seed,n) :
> """..."""
> for k in xrange(n-1) :
> seed=length_encode(seed)
> return seed
Nothing's wrong with it.
I happen to think the recursive version is more elegant, but that's
just me ;-)
--
http://mail.python.org/mailm
Oops, I missed a bracket... that should read:
testxml = ''
But it still crashes ;-)
--
http://mail.python.org/mailman/listinfo/python-list
Hi all,
I'm getting a seg fault when I try to use minidom to parse some XML
inside a wxPython app.
I was wondering if someone else could run the simple code below on
Linux and, if it doesn't crash horribly, post which versions of
(Python, wxPython) they are using? I can't find other messages rel
Tkinter takes strings as its arguments; it's TCL's legacy. You can use
string formatting for this:
x = width/2-40
y = height/2-30
root.geometry('%ldx%ld+%ld+%ld' % (width, height, x, y))
--
http://mail.python.org/mailman/listinfo/python-list
Here's my take on the thing. It only prints one term, though.
http://www.magicpeacefarm.com/lonnie/code/morris.py.html
(a bit too long to post)
--
http://mail.python.org/mailman/listinfo/python-list
The generator in your original post /does/ rebind seed, but only on the
last iteration of the loop. You'll need to wrap that loop in another
loop if you want the generator to yield more than once.
As for "communicating" with a generator --- e.g. telling it to stop ---
this might be done by passin
Pickling is the Python term for serialization. See
http://en.wikipedia.org/wiki/Serialization
Suppose you want to save a Python object "x" to a file...
output_file = open('my_pickle', 'wb') # open a file
import pickle
pickle.dump(x, output_file) # write x to the file
output_file.close()
...
Recompile Python and SANE with debugging enabled, if you haven't
already. That should allow you to trace back to the source of the error
using gdb (or your favorite gdb front-end). AFAIK there's no inherent
reason that embedding Python in a shared library wouldn't work.Did
you try compiling th
There is a sets.Set class built in to Python. You might want to use
this instead of lists. It defines some handy set operations like
intersection, union, and so on.
from sets import Set
my_sets = {
'one' : Set([0,4,7,9]),
'two' : Set([0,3,7,9]),
etc...
}
--
http://mail.python.org/mailm
> Beautiful is better than ugly.
> Explicit is better than implicit.
>> Err... I see no contradiction nor conflict here.
What to do when explicit is ugly and implicit is beautiful? Aye,
there's the rub. ;-)
--
http://mail.python.org/mailman/listinfo/python-list
Very clever!
This looks like exactly what I wanted. Thanks =)
--
http://mail.python.org/mailman/listinfo/python-list
Occaisionally, the first two lines of The Zen of Python conflict with
one another.
An API I'm working on involves a custom namespace implementation using
dictionaries, and I want a pretty syntax for initializing the custom
namespaces. The fact that these namespaces are implemented as
dictionaries
> What's your use case exactly ?
I'm trying to use a function to implicitly update a dictionary. The
whole point is to avoid the normal dictionary semantics, so kw['x'] = 5
unfortunately won't do.
I think bytecode hacks may be the way to go
--
http://mail.python.org/mailman/listinfo/python-lis
Can anyone think of a way to substitute a user-supplied dictionary as
the local dict for a function call?
e.g.
def f():
x = 5
d = {}
exec_function_in_dictionary( f, d ) # ???
print d["x"] # 5
#--
Right now, the way I'm doing this is to parse the function body out of
it
I don't know spamassassin's exact set up, but usually procmail spam
filters read an email message from standard input and produce an exit
code that tells you if the message is spam or not.
So from the Python side, it should be as easy as running whatever the
command is (a quick googling suggests i
It looks like a good start! Some tips-
- Index your arrays starting from 0 instead of 1. It will make life
easier (and it's the convention in most modern languages)
- Try a two dimensional array for the board representation? A list of
lists will do:
brd = [ [0] * 5 for i in xrange(5) ]
Google for "boost graph python"
--
http://mail.python.org/mailman/listinfo/python-list
> Python closures are apparently very poor, but from what I can surmise
> of the PyGTK2 page, instances of objects are dynamic enough to add new
> methods, so you get your callbacks, at least.
It's true that Python's "lambda" is somewhat limited, but this is
rarely a problem because you can define
Well, you could iterate over an index into the list:
from __future__ import division
def moving_average(sequence, n):
return [sum(sequence[i:i+n])/n for i in
xrange(len(sequence)-n+1)]
Of course, that's hardly efficient. You really want to use the value
calculated for the i_th term in
I made a logic error in that. Must be tired :-( Alas, there is no
undo on usenet.
--
http://mail.python.org/mailman/listinfo/python-list
The parsing is good; the structure can be transformed after the parsing
is done.
The basic problem with the "reverse lookup" search is that you need to
iterate over lots of things. If you're only doing one search, that's
not too horrible But if you're going to perform multiple searches, you
can
Here's the illegible gibberish version of your function. Once you
understand completely the following line of code, you will be well on
your way to Python nirvana:
getNodes = lambda Foundry=None,Process=None: [node for node,foundries
in dict.iteritems() if ((Foundry is None) and ((Process is None
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
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
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
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
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:
> 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
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
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
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://
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
> (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
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
> 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
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):
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
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
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
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
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
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', (
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
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
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
> 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
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
> 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
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-
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
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
Yes. With the unbuffered flag, raw_input() strings on my box end in
\r.
--
http://mail.python.org/mailman/listinfo/python-list
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
Will do
--
http://mail.python.org/mailman/listinfo/python-list
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
That's exactly what I was looking for. Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
>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
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
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
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
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()
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
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
> 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
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
> 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
> 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
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
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
ctypes!
http://starship.python.net/crew/theller/ctypes/
--
http://mail.python.org/mailman/listinfo/python-list
> 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
>> 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
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
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
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
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
> 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
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
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
> 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 -
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
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
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
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
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
> 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 =)
> 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
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 %
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
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
> 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
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
1 - 100 of 128 matches
Mail list logo