Re: vi and python

2005-01-09 Thread David Wilson
km wrote:
Is there a way to display inbuilt function syntax as the user starts typing a function name with 'Vi' editor in console mode? 
 

Hi there,
Unfortunately due to the highly dynamic nature of Python, this is 
difficult to do reliably. It is one benefit that static typing, to a 
certain extent, would bring to the language. Sadly we don't have that, 
yet. :)

David.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python in C integration and WxPython

2005-09-15 Thread David Wilson
It sounds like your C program and Python script are running under
different interpreters. Your C program almost certainly is using a
Python version that comes with Cygwin, while the script is probably
using a native win32 Python that has wxPython installed.

Assuming this is true, then compiling your C program natively on
Windows should solve the problem. Alternatively, if wxPython is
available for cygwin (possibly via cygwin's X server) then installing
it would also help.


David.


Alain Paschoud wrote:
> Hi all,
>
> I made a small dialog in WxPython. I can run the python script with a
> double-click or through command line, and everything goes fine (dialog
> appears, which means that wx module has been found).
> Then, I decided to write a C program (under Windows, with Cygwin) that
> will read my script (through PyRun_SimpleFile() function) and run it.
> But the system doesn't find the wx module to import...
>
> Traceback (most recent call last):
>   File "Dialog.py", line 2, in ?
> import  wx
> ImportError: No module named wx
>
> How can I say to my program where to search for this module ? I tried to
> set $PYTHONPATH and $PYTHONHOME, but this doesn't change anything.
>
> More generally : Does a C program that embedded python run an external
> executable (interpreter), or does it only load libraries ?
> 
> Thank you very much for any help on this topic.
> 
> Best regards.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb UPDATE does nothing

2005-09-15 Thread David Wilson
>> sql="UPDATE product_attribute SET index_column = "+str(index)+" WHERE id = 
>> "+str(record2[0])
>> ..
>> cursor.execute(sql)

To allow the DB-API adaptor to correctly take care of value conversion
and SQL escaping for you, this should be written as:

cursor.execute("UPDATE product_attribute SET col1 = %s WHERE id = %s",
(index, record2[0]))


As for why the UPDATE has no effect, which version of MySQL are you
using?


David.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python optimization

2005-09-15 Thread David Wilson
For the most part, CPython performs few optimisations by itself. You
may be interested in psyco, which performs several heavy optimisations
on running Python code.

http://psyco.sf.net/

Defining a function inside a loop in CPython will cause a new function
object to be created each and every time the loop runs. No such
automatic optimisation is performed there. For the most part, this lack
of opimisation not only simplifies the CPython implementation, but also
causes code to act much more closely to how it was defined, which is
good for new and advanced users alike.

Other than psyco, IronPython and PyPy are two projects which you might
be interested in if execution performance is of interest to you.

http://www.ironpython.com/
http://codespeak.net/pypy/


David.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for system/network monitoring tool written in Python

2005-09-22 Thread David Wilson
See http://pynms.sourceforge.net/
Also see Google. :)


David.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling python scripts from C# programs

2005-09-22 Thread David Wilson
You should also be aware of IronPython, although it is not suitable for
production use due to its reliance on a beta version of the .NET
runtime. In some future time, IronPython will probably be the cleanest
and simplest way to integrate Python with existing .NET code.

http://www.ironpython.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: change extensions

2005-04-04 Thread David Wilson
Bob Then wrote:
> how can i change all files from one extension to another within a
direcory?

This should work:

import os

def change_exts(suffix, new_suffix, dir_name):
for name in os.listdir(dir_name):
if name.endswith(suffix):
old_pathname = os.path.join(dir_name, name)
new_pathname = old_pathname[:-len(suffix)] + new_suffix
os.rename(old_pathname, new_pathname)



David.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: this must be a stupid question ...

2007-07-28 Thread David Wilson
On 28/07/07, Stef Mientki <[EMAIL PROTECTED]> wrote:
> but I can;t find the answer ;-)
>
> As searching for the '$' sign doesn't work well in the help files,
> I can not find out, where is the '$' sign used for.
>
> If I try to use it in names,
> I get a compiler error,
> so it probably has some special meaning.

Hi Stef,

It has no special meaning in the Python language, beyond being invalid
for use in identifiers. I believe there is a new string formatting
module which interprets it when it is part of a format string, but
nothing in the core language.

If you look at the language grammar, you can see why this is an error

http://docs.python.org/ref/identifiers.html


David.


>
> thanks,
> Stef Mientki
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Events: The Python Way

2007-07-28 Thread David Wilson
Hi there,

Python has no built-in way of doing this. You may consider writing
your own class if you like this pattern (I personally do):

class Event(object):
def __init__(self):
self.subscribers = set()

def __iadd__(self, subscriber):
self.subscribers.add(subscriber)
return self

def __isub__(self, subscriber):
self.subscribers.pop(subscriber)
return self

def __call__(self, *args, **kwargs):
for subscriber in self.subscribers:
subscriber(*args, **kwargs)


def HandleFoo(strng):
print "HandleFoo:", strng

OnFoo = Event()
OnFoo += HandleFoo

OnFoo("Test.")


On 29/07/07, Gianmaria <[EMAIL PROTECTED]> wrote:
> Hi,
> i'm a .net programmer and i'm learnig python, so this question can be very
> stupid or easy for python programmers. I've a doubt about events here is
> what:
>
> in c# for example i can write a delegate and an event in this way...
>
> public delegate SomethingChangedHandler(string message);
> public event SomethingChangedHandler SomethingChanged;
>
> and later in the code fire this event in this way...
>
> if(SomethingChanged != null)
> {
> SomethingChanged("Nothing important");
> }
>
> and the subscription of this event of other objects can be easy as
>
> eventGeneratorObject.SomethingChanged += new
> SomethingChangedHandler(aFunctionto_takecareof_it);
>
> and even the handlig of the event is aesy...
>
> void aFunctionto_takecareof_it(string msg)
> {
>
> }
>
>
> now the question is.. how can i do the same using Python? Every help is
> appreciated
>
>
>
>
>
> Regards,
> Gianmaria
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.6 json & encoding of datetime.

2008-10-10 Thread David Wilson
Hi there,

I've been playing with Python's new json library, and found myself
facing a seemingly simple problem: encoding of datetime objects. Some
'jsonlib' that I was using previously was unable to do this, and the
new built-in json module shares the same limitation.

A bit of googling around brought me to  which seems to suggest there is no
standardised way of doing it. Indeed, reading the rather sparse JSON
RFC makes no mention of it.

It appears my only possibility is writing little helper functions to
convert my datetimes to/from ISO8601 strings or UNIX timestamps, but
this just feels wrong. Suggestions?

Thanks,


David.
--
http://mail.python.org/mailman/listinfo/python-list


IOS-style command line interface module?

2006-03-11 Thread David Wilson
Hi folks,

I seem to remember seeing a module some time in the distant past that
provided an API for implementing Cisco IOS-like command line
interfaces. I can't for the life of me find a reference to it on Google
now.

Does anyone know what I'm talking about?

Thanks,


David.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IOS-style command line interface module?

2006-03-13 Thread David Wilson
Doh, I am indeed referring to the standard "cmd" module - thanks!

To [EMAIL PROTECTED], the above module does what you describe.

Thanks again,


David.

-- 
http://mail.python.org/mailman/listinfo/python-list


itertools.intersect?

2009-06-10 Thread David Wilson
Hi,

During a fun coding session yesterday, I came across a problem that I
thought was already solved by itertools, but on investigation it seems
it isn't.

The problem is simple: given one or more ordered sequences, return
only the objects that appear in each sequence, without reading the
whole set into memory. This is basically an SQL many-many join.

I thought it could be accomplished through recursively embedded
generators, but that approach failed in the end. After posting the
question to Stack Overflow[0], Martin Geisler proposed a wonderfully
succinct and reusable solution (see below, or pretty printed at the
Stack Overflow URL).

It is my opinion that this particular implementation is a wonderful
and incredibly valid use of iterators, and something that could be
reused by others, certainly least not myself again in the future. With
that in mind I thought it, or something very similar, would be a great
addition to the itertools module.

My question then is, are there better approaches to this? The heapq-
based solution at the Stack Overflow page is potentially more useful
still, for its ability to operate on orderless sequences, but in that
case, it might be better to simply listify each sequence, and sort it
before passing to the ordered-only functions.

Thanks,


David.

Stack Overflow page here:

http://stackoverflow.com/questions/969709/joining-a-set-of-ordered-integer-yielding-python-iterators


Sweet solution:

import operator

def intersect(sequences):
"""Compute intersection of sequences of increasing integers.

>>> list(intersect([[1,   100, 142, 322, 12312],
... [2,   100, 101, 322, 1221],
... [100, 142, 322, 956, 1222]]))
[100, 322]


"""
iterators = [iter(seq) for seq in sequences]
last = [iterator.next() for iterator in iterators]
indices = range(len(iterators))
while True:
# The while loop stops when StopIteration is raised. The
# exception will also stop the iteration by our caller.
if reduce(operator.and_, [l == last[0] for l in last]):
# All iterators contain last[0]
yield last[0]
last = [iterator.next() for iterator in iterators]

# Now go over the iterators once and advance them as
# necessary. To stop as soon as the smallest iterator we
# advance each iterator only once per loop iteration.
for i in indices[:-1]:
if last[i] < last[i+1]:
last[i] = iterators[i].next()
if last[i] > last[i+1]:
last[i+1] = iterators[i+1].next()

-- 
http://mail.python.org/mailman/listinfo/python-list


Where does setuptools live?

2009-07-04 Thread David Wilson
I'm trying to create a patch for a diabolical issue I keep running
into, but I can't seem to find the setuptools repository. Is it this
one?

http://svn.python.org/view/sandbox/trunk/setuptools/

It's seen no changes in 9 months.

The issue in question is its (ab)use of .svn to directly read working
copy information rather than going via the well designed 'svn info --
xml' route, which if done, wouldn't result in setuptools busting every
few years, nor require me to downgrade my Subversion installation (OS
X packages don't support multiple versions installed at a time),
checkout a source tree, use setuptools, then re-upgrade so I can go
back to using my other trees.


David
-- 
http://mail.python.org/mailman/listinfo/python-list