Re: tarfile...bug?

2007-10-12 Thread alan . haffner
On Oct 9, 10:33 pm, Anurag <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Have any one faced such problem, I assume it must be common if it can
> be replicated so easily , or something wrong with my system
>
> Also if I use tar.members instead of tar.getmembers() it works
> so what is the diff. between tar.members and tar.getmembers()
>
> rgds
> Anurag

if you are not fully dependant on tarfiles, have a look at the zipfile
library in Python.  Everytime I start to use the tarfile .lib, the
zip .lib turns out to be a better solution.

Cheers,

  --Alan

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


Re: Declarative properties

2007-10-12 Thread Artur Siekielski
George Sakkis wrote:
> By now you must have been convinced that default getters/setters is
> not a very useful idea in Python but this does not mean you can't do
> it;

It's a perfect summary of my thoughts after reading this thread. I
will use public attributes (with access customizable with properties)
and remember that in Python I can do everything :).
Thanks everybody.

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


Re: Declarative properties

2007-10-12 Thread Bruno Desthuilliers
Dan Stromberg a écrit :
> On Thu, 11 Oct 2007 13:46:12 +, Marc 'BlackJack' Rintsch wrote:
> 
>> On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote:
>>
>>> On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
 But why?  Default getters and setters are unnecessary and if you need
 something other than the default you need to write it anyway more
 explicitly.
>>> I see some problems with your approach:
>>>
>>> 1. If I use instance field 'name' which is accessed directly by other
>>> classes,
>>> and later I decide to implement nonstandard getter, I must refactor
>>> 'Person' class
>>> and in some places change 'name' to '_name' (assuming this is now the
>>> field's name).
>>> The problem is that I cannot automatically change 'name' to '_name'
>>> everywhere, because
>>> in some places I want public property value (eg. validated and
>>> formatted), and in other
>>> places raw property value.
>> So what?  Otherwise you carry *always* the baggage of a public property
>> and a private attribute whether you need this or not.  At least for me it
>> would be unnecessary in most cases.
> 
> That "baggage" of carrying around "unneeded" methods is something the
> computer carries for you - IE, no big deal in 99.99% of all cases.

1/ Accessing the value of a property is not free. Accessing a plain 
attribute is much cheaper.

2/ cluttering the class's namespace with useless names and the source 
code with useless code is definitively not a good thing.

> The "baggage" of possibly fixing (AKA "generalizing") how your attributes
> are accessed is something you lug around while your deadline looms.
> 
> Here's some code that defines such methods for you:
> 
> #!/usr/bin/env python
> 
> def gimme_set_get(foo, attribute):
>lst = [ \
>   'def set_%s(self, value):' % attribute, \
>   '  self._%s = value' % attribute, \
>   'def get_%s(self):' % attribute, \
>   '  return self._%s' % attribute, \
>   'foo.set_%s = set_%s' % (attribute, attribute), \
>   'foo.get_%s = get_%s' % (attribute, attribute) \
>   ]
>s = '\n'.join(lst)
>code = compile(s, '', 'exec')
>eval(code)

Yuck. This is not only a waste of time, but also badly coded. have mercy 
and at least learn how to properly use lexical scoping and closures.

> class foo:
>def __init__(self, value):
>   self.public_value = value
> gimme_set_get(foo, 'via_accessor_method_only')
> 
> f = foo(1)
> f.set_via_accessor_method_only(1/9.0)
> print f.get_via_accessor_method_only()
> 
> print dir(f)
> 
Correction: this is not only a waste of time and badly coded, this is 
also misleading and braindead.

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


Re: Declarative properties

2007-10-12 Thread Bruno Desthuilliers
Artur Siekielski a écrit :
> George Sakkis wrote:
>> By now you must have been convinced that default getters/setters is
>> not a very useful idea in Python but this does not mean you can't do
>> it;
> 
> It's a perfect summary of my thoughts after reading this thread. I
> will use public attributes (with access customizable with properties)
> and remember that in Python I can do everything :).

Well... Almost !-)

And +1 QOTW, BTW.


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


Cross-platform GUI development

2007-10-12 Thread [EMAIL PROTECTED]
I've been programming in Python for 5 or more years now and whenever I
want a quick-n-dirty GUI, I use Tkinter. This is partly because it's
the first toolkit I learnt, but also because it's part of the standard
Python distribution and therefore easy to get Python apps to work
cross platform - it usually requires almost no porting effort.

However, when I need a little bit more grunt, I tend to turn to Tix,
which I thought was also fairly standard. However, this week, I wrote
a Tix application under Linux which I'd really like to work on Mac OS
and it's proving fairly painful to get it going. There is no Tix in
the standard fink or apt repositories and when I download a tar-ball,
it wouldn't build because it had a lot of unmet dependencies. I then
read a post which said that only Tkinter/Python people really use Tix
anymore and people in tcl/tk moved onto better toolkits long ago.

My question is if Tix is old hat, what is the GUI toolkit I *should*
be using for quick-n-dirty cross platform GUI development? I guess
this is tangentially related to:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/2ed58ff6ac7d030c/42ed0d40ffd0b1c0?lnk=gst&q=tix+#42ed0d40ffd0b1c0

I hope this isn't a stupid question. I'm wearing flame retardant
underwear.

Peter

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-10-12 Thread Paul Rubin
Mark Summerfield <[EMAIL PROTECTED]> writes:
> Below is a PEP proposal for a sorteddict. ...

Is this proposal dead?  I'd been meaning to post some thoughts which I
still haven't gotten around to writing up, and am wondering whether to
keep it on my todo list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Script to Remove Attachments in Exchange Mailbox

2007-10-12 Thread Tim Golden
[KDawg44]

>>> I am frustrated with my users who send large files around the office
>>> instead of using the network shares.

[Tim Golden]
>> I have something v. similar, ...
>> It's a while since they were last run to they're probably quite
>> dusty but it sounds like the kind of thing you're after.

Well, here's[1] the first part -- running through folders and replacing
big attachments with links. Now I look, it's designed to be run by
a user on his/her own mailbox rather than by an administrator. Naturally
it's got some stuff which is specific to my setup but nothing, I think,
which isn't easily understood and adapted or removed.

One note is that, as it says in the comments, there doesn't seem to
be a way of identifying large attachments as such, only large messages.
So there may be some corner case where an attachment is stripped out
which is in fact quite small. Obviously you could adapt the
process_attachment function to do something fancier than it is based
on the saved file size etc.

There are no dependencies outside the stdlib except, of course, the
pywin32 package. (Which is, for me, part of the stdlib whenever I
install on Windows). Feel free to email me privately or on-list if
you wish if there's anything which isn't clear etc.

TJG

[1] http://timgolden.me.uk/python/downloads/strip_attachments.py

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


Re: Cross-platform GUI development

2007-10-12 Thread Alexandre Badez
On Oct 12, 10:13 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> I've been programming in Python for 5 or more years now and whenever I
> want a quick-n-dirty GUI, I use Tkinter. This is partly because it's
> the first toolkit I learnt, but also because it's part of the standard
> Python distribution and therefore easy to get Python apps to work
> cross platform - it usually requires almost no porting effort.
>
> However, when I need a little bit more grunt, I tend to turn to Tix,
> which I thought was also fairly standard. However, this week, I wrote
> a Tix application under Linux which I'd really like to work on Mac OS
> and it's proving fairly painful to get it going. There is no Tix in
> the standard fink or apt repositories and when I download a tar-ball,
> it wouldn't build because it had a lot of unmet dependencies. I then
> read a post which said that only Tkinter/Python people really use Tix
> anymore and people in tcl/tk moved onto better toolkits long ago.
>
> My question is if Tix is old hat, what is the GUI toolkit I *should*
> be using for quick-n-dirty cross platform GUI development? I guess
> this is tangentially related to:
>
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
> I hope this isn't a stupid question. I'm wearing flame retardant
> underwear.
>
> Peter

Personnaly, I use PyQt simply because I prefere Qt to Gtk, witch is
much more integrated with all desktop than Gtk.
In fact, your application in Qt on Mac, Win or Linux look like a
native app.

Just a question of "feeling" I think; because most of those GUI
framework, offer quiet the same functionality.

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


Re: Pyro: ActiveState (wind32) to Unix

2007-10-12 Thread Tim Golden
Sells, Fred wrote:
> I'm using ActiveState python on a windows box to talk to ACtive Directory.  
 > I'm running a Pyro Server on the same box.
> 
> The client is Linux running std Python 2.4.
> 
> It works just fine until the server codes calls some 
 > win32com.client api;  then I get
> 
> 
> Traceback (most recent call last):
>   File "C:\All\projects\AccAdminTools\src\demo002\client\client.py", line 25, 
> in ?
> unittest()
>   File "C:\All\projects\AccAdminTools\src\demo002\client\client.py", line 21, 
> in unittest
> properties = ad.getProperties()
>   File 
> "c:\all\tools\python24\lib\site-packages\Pyro-3.7-py2.4-win32.egg\Pyro\core.py",
>  line 390, in __call__
> return self.__send(self.__name, args, kwargs)
>   File 
> "c:\all\tools\python24\lib\site-packages\Pyro-3.7-py2.4-win32.egg\Pyro\core.py",
>  line 468, in _invokePYRO
> return self.adapter.remoteInvocation(name, 
> constants.RIF_VarargsAndKeywords, vargs, kargs)
>   File 
> "c:\all\tools\python24\lib\site-packages\Pyro-3.7-py2.4-win32.egg\Pyro\protocol.py",
>  line 416, in remoteInvocation
> answer = pickle.loads(answer)
> ImportError: No module named pywintypes
> 
> the offending code is 
> def getProperties(self):
> def getProperties(self):
>   attr_dict={}
>   adobj=win32com.client.GetObject(self.LdapPath)  #<<< the error
>   return {'aaa':'bbb'}

It looks to me as though the Pyro server is passing back a "raw"
win32com object, which therefore needs various bits of the pywin32
plumbing in order to work. What happens is that the Pyro server
pickles up the object you return and the client unpickles it. In
order to unpickle, the client must have access to the modules,
classes etc. which the server does. (You can use mobile code etc.
but that wouldn't help here). The problem is, of course, that the
pywin32 stuff is Windows specific.

In short, make sure that whatever you pass back from your Pyro
server is either plain Python types (eg a dict of values etc)
or uses a class which is available -- or at least would work if
passed over by Pyro's mobile code -- on the Linux box.

Is that clear? Or do you need an example?

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


Re: decorating container types (Python 2.4)

2007-10-12 Thread James Stroud
[EMAIL PROTECTED] wrote:
> On Oct 12, 12:19 pm, James Stroud <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>>> I have a container class A and I want to add functionality to it by
>>> using a decorator class B, as follows:
>>> class A(object):
>>> def __len__(self):
>>> return 5
>>> class B(object):
>>> def __init__(self, a):
>>> self._a = a
>>> def __getattr__(self, attr):
>>> return getattr(self._a, attr)
>>> def other_methods(self):
>>> blah blah blah
>>> I was expecting len(B) to return 5 but I get
>>> AttributeError: type object 'B' has no attribute '__len__'
>>> instead.
>>> I was expecting len() to call B.__len__() which would invoke
>>> B.__getattr__ to call A.__len__ but __getattr__ is not being called.
>>> I can work around this, but I am curious if anyone knows _why_
>>> __getattr__ is not being called in this situation.
>>> Thanks
>>> Tim
>> The why part is that __len__ is an unbound method of the class, not an
>> unbound method of the class's metaclass. Also, your code above makes
>> absolutely no association between classes A and B, which is the most
>> fundamental reason.
> 
> Just so I'm clear on this: Are you saying that the problem with my
> original code is that len() is equivalent to type(x).__len__(x) that
> looks for a class attribute rather than an instance attribute as my
> code requires?
> 
> I don't own class A and they are generated by function calls rather
> than instantiated directly, that's why I'm decorating them instead of
> inheriting.  The crux of the (academic) question is why does len()
> expect '__len__' to be a class attribute instead of an instance
> attribute, and why is this a good idea?

You are taking the length of the *class* (whatever that means) with 
"len(B)", so B must have a method __len__() bound to itself, which would 
be an unbound method of B's class (which I am calling the metaclass of 
B, since B is a class--a class's class is a metaclass). So you want the 
unbound __len__() method of A to be the unbound __len__() method of the 
metaclass of B. This is easier done than said:

def long_class_factory(cls, name):
   class _longmeta(type):
 __len__ = cls.__len__.im_func
   return _longmeta(name, (), {})


E.g.:

py> def long_class_factory(cls, name):
...   class _longmeta(type):
... __len__ = cls.__len__.im_func
...   return _longmeta(name, (), {})
...
py> class A(object):
... def __len__(self):
... return 5
...
py> B = long_class_factory(A, 'B')
py> B

py> len(B)
5

Of course you can now inherit from B:

class C(B):
   pass

E.g.:

py> class C(B): pass
...
py> len(C)
5

James

--
James Stroud
UCLA-DOE Institute of Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: EasyMock for python ?

2007-10-12 Thread Simon Brunning
On 10/12/07, Ben Finney <[EMAIL PROTECTED]> wrote:
> BlueBird <[EMAIL PROTECTED]> writes:
> This means that the Mock object automatically supports any number of
> attributes and methods by any reasonable names; the only setup needed
> beyond creating the instance is to seed it with anything you *don't*
> want returned as a Mock.

Now *that* is what the OP was talking about - that's not a Mock,
that's a Stub. See .
.

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: EasyMock for python ?

2007-10-12 Thread Ben Finney
(Please don't send me personal copies of messages that are sent to the
forum; I read via the newsgroup, and it's annoying to also get replies
in email when I didn't send an email message.)

"Simon Brunning" <[EMAIL PROTECTED]> writes:

> On 10/12/07, Ben Finney <[EMAIL PROTECTED]> wrote:
> > This means that the Mock object automatically supports any number
> > of attributes and methods by any reasonable names; the only setup
> > needed beyond creating the instance is to seed it with anything
> > you *don't* want returned as a Mock.
> 
> Now *that* is what the OP was talking about - that's not a Mock,
> that's a Stub. See .

Because the minimock.Mock instance is instrumented to emit a message
any time one of its attributes is called, that output becomes the
playback — which then, using doctest, can be compared against the
*expected* sequence of method calls.

That seems like it's a Mock to me: intended to assert that a specific
sequence of method calls with specific arguments was made on the mock
instance.

-- 
 \   "I love to go down to the schoolyard and watch all the little |
  `\   children jump up and down and run around yelling and screaming. |
_o__)  They don't know I'm only using blanks."  -- Emo Philips |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problem with MySQL cursor

2007-10-12 Thread Florian Lindner
Carsten Haese wrote:

> On Thu, 2007-10-11 at 15:14 +0200, Florian Lindner wrote:
>> Hello,
>> I have a function that executes a SQL statement with MySQLdb:
>> 
>> def executeSQL(sql,  *args):
>> print sql % args
>> cursor = conn.cursor()
>> cursor.execute(sql, args)
>> cursor.close()
>> 
>> it's called like that:
>> 
>> sql = "INSERT INTO %s (%s) VALUES (%s)"
>> executeSQL(sql,  DOMAIN_TABLE, DOMAIN_FIELD, domainname)
> 
> You can't use parameter binding to substitute table names and column
> names, or any other syntax element, into a query. You can only bind
> parameters in places where a literal value would be allowed (more or
> less, the real rules are more complicated, but this rule of thumb gets
> you close enough). You have to construct the query string like this, for
> example:
> 
> sql = "INSERT INTO "+DOMAIN_TABLE+"("+DOMAIN_FIELD+") VALUES (%s)"
> executeSQL(sql, domainname)

Ok, I understand it and now it works, but why is limitation? Why can't I
just the string interpolation in any playes and the cursor function escapes
any strings so that they can't do harm to my query?

Regards,

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


Re: Cross-platform GUI development

2007-10-12 Thread Peter Decker
On 10/12/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> My question is if Tix is old hat, what is the GUI toolkit I *should*
> be using for quick-n-dirty cross platform GUI development?

I would heartily recommend Dabo (http://dabodev.com). It wraps the
wxPython toolkit, but eliminates 99% of the hassle in dealing with the
C++ feel of wxPython. And while it is supposed to be for
database-related apps, it works great for UI-only apps, which is what
I use it for.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Memory Problems in Windows 2003 Server

2007-10-12 Thread amdescombes
Hi,

I am using Python 2.5.1
I have an application that reads a file and generates a key in a 
dictionary for each line it reads. I have managed to read a 1GB file and 
generate more than 8 million keys on an Windows XP machine with only 1GB 
of memory and all works as expected. When I use the same program on a 
Windows 2003 Server with 2GB of RAM I start getting MemoryError exceptions!
I have tried setting the IMAGE_FILE_LARGE_ADDRESS_AWARE on both 
Python.exe and Python25.dll and setting the /3GB flag on the boot.ini 
file to no avail. I still get the MemoryError exceptions.

Has anybody encountered this problem before?

Thanks in advance for any ideas/suggestions.

Best Regards,

André M. Descombes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Last iteration?

2007-10-12 Thread Peter Otten
Diez B. Roggisch wrote:

> Florian Lindner wrote:

>> can I determine somehow if the iteration on a list of values is the
>> last iteration?

>  def last_iter(iterable):
> it = iter(iterable)
> buffer = [it.next()]
> for i in it:
> buffer.append(i)
> old, buffer = buffer[0], buffer[1:]
> yield False, old
> yield True, buffer[0]

This can be simplified a bit since you never have to remember more than on
item:

>>> def mark_last(items):
... items = iter(items)
... last = items.next()
... for item in items:
... yield False, last
... last = item
... yield True, last
...
>>> list(mark_last([]))
[]
>>> list(mark_last([1]))
[(True, 1)]
>>> list(mark_last([1,2]))
[(False, 1), (True, 2)]

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


Traceback (most recent call last): PROBLEM

2007-10-12 Thread smarras
Hello everyone, I keep obtaining an error message whenever I execute some
very simple routines; the error that follows says that I am calling
certain functions that, in reality, I am not calling from any of the
routines that I wrote:

error:

> python fwrite_mat.py

  0, 0, 0, 0 ,  0, 1, 2, 3 ,  0, 2, 4, 6
Traceback (most recent call last):
  File "fwrite_mat.py", line 7, in 
from xlrd import *
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/xlrd/__init__.py",
line 256, in 
from timemachine import *
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/xlrd/timemachine.py",
line 21, in 
from array import array as array_array
ImportError: cannot import name array

In these lines that I pasted, for example the "array-looking" string has
nothing to do with my function, nor the import name "timemachine" or the
import name "array".

Can anyone help me understand why python is looking such libraries, and
why it keeps in memory an array that I am not using?

Here also the simple routine I wrote:

import os, sys
import xlrd
from numpy import *
from Numeric import *
from matplotlib import *

book = xlrd.open_workbook("/Users/simone/Desktop/prova.xls")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols
for i in range(sh.nrows):
for j in range(sh.ncols):
print sh.row(i)
print sh.cell_value(i, j)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error on base64.b64decode() ?!

2007-10-12 Thread Jean-Paul Calderone
On Fri, 12 Oct 2007 14:59:13 -, Christoph Krammer <[EMAIL PROTECTED]> wrote:
>Hello everybody,
>
>I am using a python script to extract images from email messages. This
>works fine for some messages, but not all attached images can be
>decoded. I use the following code to decode the image and save it to a
>database:
>
>try:
>  imagedec = base64.b64decode(imageenc)
>  imagehash = md5.new(imagedec).hexdigest()
>  dbcurs.execute()
>except TypeError, e:
>  print "Error '%s' in Message %s" % (e, dbrow[1])
>  print imageenc)
>
>The problem is that for some images, the method b64decode() returns a
>TypeError "Incorrect Padding". But if I paste the content of imageenc
>to some other base64 decode (like this one:
>http://www.php-einfach.de/base64_generator.php?code=1), I get the
>correct result.

If you get an incorrect padding error, try appending a "=" and decoding
again.  If you get the error again, try appending one more "=".  If it
still doesn't work, then you might be out of luck.

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


Error on base64.b64decode() ?!

2007-10-12 Thread Christoph Krammer
Hello everybody,

I am using a python script to extract images from email messages. This
works fine for some messages, but not all attached images can be
decoded. I use the following code to decode the image and save it to a
database:

try:
  imagedec = base64.b64decode(imageenc)
  imagehash = md5.new(imagedec).hexdigest()
  dbcurs.execute()
except TypeError, e:
  print "Error '%s' in Message %s" % (e, dbrow[1])
  print imageenc)

The problem is that for some images, the method b64decode() returns a
TypeError "Incorrect Padding". But if I paste the content of imageenc
to some other base64 decode (like this one:
http://www.php-einfach.de/base64_generator.php?code=1), I get the
correct result.

One example content is included below.

Is this a bug in the base64 module, or is there something wrong with
my code?

Regards,
 Christoph

---
R0lGODlhOwKDAfcAAICAAICAgIAAgACAgICAgMDAwP8AAAD/AP////
8A/wD/
/
wAA
MwAAZgAAmQAAzAAA/
wAzAAAzMwAzZgAzmQAzzAAz/wBm
AABmMwBmZgBmmQBmzABm/wCZAACZMwCZZgCZmQCZzACZ/wDMAADMMwDMZgDMmQDMzADM/
wD/AAD/
MwD/ZgD/mQD/zAD//zMAADMAMzMAZjMAmTMAzDMA/zMzADMzMzMzZjMzmTMzzDMz/
zNmADNmMzNm
ZjNmmTNmzDNm/zOZADOZMzOZZjOZmTOZzDOZ/zPMADPMMzPMZjPMmTPMzDPM/zP/ADP/
MzP/ZjP/
mTP/zDP//2YAAGYAM2YAZmYAmWYAzGYA/2YzAGYzM2YzZmYzmWYzzGYz/
2ZmAGZmM2ZmZmZmmWZm
zGZm/2aZAGaZM2aZZmaZmWaZzGaZ/2bMAGbMM2bMZmbMmWbMzGbM/2b/AGb/M2b/Zmb/
mWb/zGb/
/5kAAJkAM5kAZpkAmZkAzJkA/5kzAJkzM5kzZpkzmZkzzJkz/
5lmAJlmM5lmZplmmZlmzJlm/5mZ
AJmZM5mZZpmZmZmZzJmZ/5nMAJnMM5nMZpnMmZnMzJnM/5n/AJn/M5n/Zpn/mZn/zJn//
8wAAMwA
M8wAZswAmcwAzMwA/8wzAMwzM8wzZswzmcwzzMwz/8xmAMxmM8xmZsxmmcxmzMxm/
8yZAMyZM8yZ
ZsyZmcyZzMyZ/8zMAMzMM8zMZszMmczMzMzM/8z/AMz/M8z/Zsz/mcz/zMz///8AAP8AM/
8AZv8A
mf8AzP8A//8zAP8zM/8zZv8zmf8zzP8z//9mAP9mM/9mZv9mmf9mzP9m//+ZAP+ZM/+ZZv
+Zmf+Z
zP+Z///MAP/MM//MZv/Mmf/MzP/MAP//M///Zv//mf//zP///
yH5BAEAABAALAA7AoMB
AAj/
ANFpwoJCCi5NKOww4cZEnCZxUqTAEedLHApfLviIs4OLGyWBvqRo0sSH40BfCjXZ8fWQmx1x
xDTREOkLFJOKKimKg
+NSEyWcFVna0QTHjgtKK6X4cskThThcvkJSYmJQHBZxLhriknJTylCIxFhy
06RUCjpcfBLCISYF1MijlIhxVIoiLFSJGL3agSOFkjhKEnFRIiuS6M6tf8+SRcdkokWUxFz8ZeJC
qYuRG4syscONJS4XbkWC
+tlQ02aRESty3CvFqiZcuNCJAyUlrB0pfJhQguMith1QE32h88WELERK
WJaqHMpNIlfD3CD6goOSIhbAL3E99bpwb9TKU0G5/5h
+fDNVXCgOonArXbcdLENV9lY5UiptYhP9
MkGBovFS2EZhtZhwQ31F0Wt8ZDWUbg/
xFVdhjXE13kEx8bGVHZSgBRETxOw2mFJwkMVRSRCpNJVX
f2kSkna+0LBSekwkuNlwGNph41Y/
RUUVCuhI0Vxf6KxEUWkUCfbTT2S9JkVWKMHRozibOQVHV1CF
aB5ZoIx1WXVLyoWaOFBSZCMWRY20Uo7T1eeLYAqxRVtaQ1FSUIhehWjmTVn1BcdFKBCF0V5QUrZS
SAbtxY0L3OBSY5+aMGRTk0xEupQdKCTKmG4SDfaanSoi16hSg8LB25pIRbfRQZQhhYKcayqqyXgv
Ff/
2GqUqdcZRpboRBxt1XK10G0Go6RbXRQZl1NiUR930EmBHUSdffTf5ZBActPkC2Ge4UMcRlJ1J
plKfjUW6H6VL4lJcQiPtWZu4je6JYUHmGmWtRNxQV1OVT/EkBbqU
+KWJXNFNR0lzPxXkAnNU+SVY
Qs16Ve++fAWnqVeXYaGiJqNBGRFRu
+HFVIZEUZXgoSk6tZlkt10LClSVRbkRS3jd5qPCPl1GGWWK
ZjuaTwIKBy9GU+7lQkaDdaYUh9mSlltkQ
+npwqqRcbUmQhmO1SOGjblolLmhbcbsmgyZ9tpOrFFi
YUp+cYNOQoOVZpRpcKiHUn/PfYfeZ/
GBKepClU3/5CBgO7Ekp0USwTFVcYgnV91LzvrSZ1QBjtbh
RjvRRrhZGQYdEkUiYQgzhmbjQlCAU7bVFl96nbUkRkSxNbZIPDGBhc3ccINFc6sxxBKY9FLy9Fco
vQpRZ2tF5epQ6fGxZkJo7dURcqI6pfdLjUXHl8XEzSq7WSH1RpVFa/
G03F8i3XQWhsLjAkpFoDm0
1ZLUdYbuQW5VthRXIcr5aqKWCYYXH2ThC1mK06+LII5QS9rLZgyHAsON5EOxYQKAolKQiKCABlvJ
n4puA5E4iYMPrdnKa/rmnZUEx0ZmEkm2ItUa0BhkKyiZTl0mksG
+zG5NqzkY9C5mPEL9hCK9Gdpv
/
yISkZ9kyywowAKIDGeQkYSFMEXxyL6A1sBXpeQ2vUGNtlQCFSShw0OBUZFWctMbjKwpJHGjiF/
I
VZSpVEkwphkRlDD2EGtJ8FUXyY8AEzYv4hANMF4ZXEea1CGPnIUnT5TZ4AjmkIgoRGi
+IAhbJPKP
SlrykpjMpCY3yclOevKToAylKEdJylKa8pSoTKUqV8nKVrrylbCMpSxnSctL9gkpYKqlLnfJy176
8pfADKYwh0nMYhKzOBXhijGXycxmOvOZ0IymNKfZTN5QhSzUzKY2t8nNbtISBd4MpzHrVStciPOc
6EynOtfJznaSclQUgYM750nPetrznvik5bbgUP+SfPrzn/
8AJ0AHSlB07udpWymoQhfK0IY6tJZL
8g8lHkrRilr0ohaljl
+shdGOepSZAv2oSEsZKEXJc6Qo7WZIU8rSgXZxJr5oqUxnStOashIdIbqM
C2zK05769KeRMttmfkrUi660qJY8qkxdEJyhIfWpUK2oUmXqCwCqRApRzapWCzpVY3aVmU8j3ES3
Stay2vOrI8XOrMzK1ramE60jDQlOEeLWutp1m3D96Fq6iIW7gpIGOqCBMQF7ScJiErCCxWRgdZBJ
xGZysY0N7GMNW1jJKpaylnRsKRG7WM4mVpOe7awoPftXy2YWsqbU7CVRq0nWVlK0qcxrR00zHeL/
+PWTrt3kZy3J2Faa9h+/fS1mgcvZy/
a2srv9B2mRO9njCje3uQ1lZ6c73NWGVrWcpG50jYtc55Iy
utg97G9hi0rZdhQ2vugQVm/
bSR0EN7KX9e1u3btJ17oXsM7dLnDHe9/8vve19D3tfVcb4M26d7H9
9W5lE4zg9jIYvwom8GchnMoBc7e+lD1wcktp3o72yI8drqt
+K4ndEZMSs9Ul8XiLe9oNP7e7802x
clfs2vCa0sS8Ha6JWaziFIOTtTjGbXVt3OIis9dJhAIFezupWQ0LGLIItiyUbQzdGGP4uFPGsozx
W2QLzzjCxMUyfYE83BD3uLTJ5bFiwQtmFfc2/8if5PKa24xaL98WCzfZDzeWnN3rSpm0oe2xdpmb
Yy2DWbWORfR/w1xoRr8YtKZNdKQXPUo4s9nFjv4uYeEsZAUT
+cyfrutteLQTPtcXyBa2L38nnV/M
FnjGTA7wgff7Zko7mstynnV2/8xY1MpZlb
+OtYJ1Hdk2OxjCMq50lJFNZ2Ybm60iecraTN1aHRu2
xCgObqiJa932bjrD3za2pCcs2W1nudGc9qSlh7zodFuXuqvU7nIhHWhWmrmi/
LTRbagd2TTzmtCP
bjQnsx1rwSra4LY+94t3XO5JIxzTJ7a1kd
+tW4lXfNzAlveIp5tpvzJ1bQ3k94UFjm3nhjfUBP/3
dq/BvXJxN5zcD1d5phWuynV7ut3JVnli3V3tm0Ocxds2656iFFOR8za4qXb1que8626ru7/
GtTOk
pc5gdVOYwA1eZbAH/moAH5rYRz821iv83o0rHeJmNUpyNmJ0gZOcxgA/
c8UrG2fyChrtz7V2kOd9
d/k+O+CA77fJze5dnlNcvD/XtsW1uhLY9Kntcjcy2IOddeVe8PDcDrvVwU7rnAP45Ha/
st67jng0
o1nDoRe8YKHOde9uPe7iHTbp3R54t3

Re: PEP idea: Instrumented Python

2007-10-12 Thread Jean-Paul Calderone
On Fri, 12 Oct 2007 11:33:11 -0500, Erik Jones <[EMAIL PROTECTED]> wrote:
> [snip]
>
>This got me thinking about building a module that could be included
>by projects that creates a socket and responds to messages on that
>socket in a separate thread from the main app so that you can connect
>to the app and explore its current state.  Take a look at the
>evalexception module in Paste to see what he does.
>

Or manhole in Twisted.

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


Re: Python module for making Quicktime or mpeg movies from images

2007-10-12 Thread Daniel Fetchinson
> My Python script makes a bunch of images that I want to use as frames
> in a movie.  I've tried searching for a module that will take these
> images and put them together in a Quicktime or mpeg movie, but haven't
> found anything.  My images are currently pdfs, but I could make them
> into just about anything if needed.
>
> Is there a module, or example of how to do this?
> Thanks,
> Jeremy

If you'll be happy with a flash movie you can try ming: ming.sf.net
which is a C library for creating flash files and there is a python
binding for it (among other languages).
-- 
http://mail.python.org/mailman/listinfo/python-list


Announcement: Project to get some CPython C extensions running under IronPython

2007-10-12 Thread Giles Thomas
The great thing about CPython is that it comes with the batteries 
included.  The problem with IronPython is that some of these batteries 
just don't fit - in particular, most of the the C extensions don't 
work.  We'd like to help fix at least some of this problem, to help 
people who use IronPython to use their CPython scripts without having to 
port everything over to .NET.


Solving the general problem - plugging an arbitrary C extension into 
IronPython - is a huge project, and we're not even sure we could work 
out *how much work it is* without a lot of investigation.  What we 
intend to do is to solve a specific problem, to integrate just one 
extension, and to use that project as a testbed to examine the 
possibilities for getting other extensions working - and perhaps, in the 
long term, solving the general problem.


We think that any solution like this will be valuable not just to us, 
but to the Python community as a whole.  And so, we want to make it Open 
Source.


Right now, we'd really like to hear from people about the following:

   * Who wants to get involved?  We're really keen on working with
 other people on this.
   * Which module should we go for?  NumPy looks like a good start, as
 it gives us a start on getting SciPy working.  But perhaps there
 are better choices.
   * Should this be a new project, or should we be talking to other
 people about getting it into other projects?
   * Which license?  If we're to work on it with a view to building it
 into Resolver One, then it will need to be
 commercial-software-friendly.  Apart from that - we have no view.
   * What is the best architecture?  We're thinking of this as being a
 bit of C# managed code to interface with the C extension, and a
 thin Python wrapper on top.  The module's existing C extension and
 Python code would "sandwich" this layer.  Let us know if this is a
 silly idea :-)
   * Is there anything else we should be thinking about to get this
 started?

Any thoughts much appreciated!


Regards,

Giles

--
Giles Thomas
MD & CTO, Resolver Systems Ltd.
[EMAIL PROTECTED]
+44 (0) 20 7253 6372

We're hiring! http://www.resolversystems.com/jobs/ 


17a Clerkenwell Road, London EC1M 5RD, UK
VAT No.: GB 893 5643 79 
Registered in England and Wales as company number 5467329.

Registered address: 843 Finchley Road, London NW11 8NA, UK

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

Re: matching a street address with regular expressions

2007-10-12 Thread Paul McGuire
On Oct 12, 8:19 am, John Machin <[EMAIL PROTECTED]> wrote:
> "... most of the developed world" was the [very optimistic] request.
> How does it go with "JAPAN 112-0001 TOKYO Bunkyo-Ku Hakusan 4-Chome 3-
> 2" and will it give the same result for "4-3-2 HAKUSAN BUNKYO-KU TOKYO
> 112-1 JAPAN"? OK, a little exotic ... closer to "home", what about
> addresses in Quebec? People often write addresses in formats that you
> won't find on the postal service website, but the local postal workers
> will still deliver. Rural addresses can be quaintly medieval e.g. "Lot
> 123, Hundred of Foughbarre" [South Australia]. Etc etc ...

John -

As I'm sure you already know, the answer is "not too well".  I've been
to Japan and Europe too, and I can't even figure out how many digits a
phone number is supposed to have!

I once lived in a small town in Virginia, and received a Christmas
card from a friend (who wanted to remind me just how small a town I
was living in) addressed simply as "The McGuire's, ,
Virginia" - I happened to mention it the next time I was at the post
office, and they said "yep, you're the only McGuires we got!"

In the spectrum of tools from string.split, to re, to pyparsing and
its ilk, to natural language toolkits, the broader the scope of your
"address space", the further you find your self moving toward NLTK.  I
knew my pyparsing script wasn't in the "anywhere in the developed
world" category, that's why I posted the test cases, too.

If you've got an re that can handle everything from "123 Main" to
"221B Baker Street" to "Hollywood and Vine" to "Lot 123, Hundred of
Foughbarre", now THAT would be something.

-- Paul

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


Re: Simple question about python logic.

2007-10-12 Thread Colin J. Williams
Tim Chase wrote:
>> I have a file containing following data. But the dimension can be
>> different.
>>
>> A B C D E F G
>> 3 4 1 5 6 2 4
>> 7 2 4 1 6 9 3
>> 3 4 1 5 6 2 4
>> 7 2 4 1 6 9 3
>> .
>> .
>> .
>> .
>>
>> What is the best approach to make a column vector with the name such
>> as A B, etc?
> 
> 
> There are a couple different ways to go about it depending on
> 
> 1) whether just one or whether both dimensions can be different
> 2) whether you want to extract each column vector
> 
> Both of the following should allow for an arbitrary number of
> columns:
> 
> To map everything, you can do something like
> 
> ###
> infile = file("in.txt")
> header_row = infile.next().rstrip('\n').split()
> values = [[] for header in header_row]
> for line in infile:
> line = line.rstrip('\n').split()
> for dest, value in zip(values, line):
> dest.append(value)
> infile.close()
> results = dict(zip(header_row, values))
> ###
> 
> 
> which you can then use with
> 
> results['A']
> 
> However, if you just want a particular column from the file and
> don't care about the rest, you can do something like
> 
> ###
> from itertools import islice
> 
> column_c = [
>  line.rstrip('\n').split()[2]
>  for line in islice(file('in'), 1, None)
>  ]
> ###
> 
> where "2" is the zero-based column offset you want (in this case,
> column C = 2)
> 
> -tkc
> 
> 
> 
Numpy appears to have this capability.

Colin W.

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


How to set proxy in Python for flickr api

2007-10-12 Thread honestguy1999
Hi, everyone, I am using beej's flickr api in Python. For some reason
I have to bypass the firewall using a proxy. I read the urllib
reference and set http_proxy="my proxy". But it didn't work. I can't
even get authenticated. Is there anyway that we can set the proxy?

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


Re: PEP idea: Instrumented Python

2007-10-12 Thread Erik Jones
On Oct 12, 2007, at 12:10 PM, Jean-Paul Calderone wrote:

> On Fri, 12 Oct 2007 11:33:11 -0500, Erik Jones <[EMAIL PROTECTED]>  
> wrote:
>> [snip]
>>
>> This got me thinking about building a module that could be included
>> by projects that creates a socket and responds to messages on that
>> socket in a separate thread from the main app so that you can connect
>> to the app and explore its current state.  Take a look at the
>> evalexception module in Paste to see what he does.
>>
>
> Or manhole in Twisted.

Thanks for the tip!

Erik Jones

Software Developer | Emma®
[EMAIL PROTECTED]
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com


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


Re: Web Ontology Language (OWL) parsing

2007-10-12 Thread Tim Churches
Sean Davis wrote:
> I would like to parse some OWL files, but I haven't dealt with OWL in
> python or any other language for that matter.  Some quick google
> searches do not turn up much in the way of possibilities for doing so
> in python.  Any suggestions of available code or using existing
> libraries for doing so?

I'm not sure whether it is still being maintained, but what about CWM,
by Sir Semantic Web himself: http://www.w3.org/2000/10/swap/doc/cwm.html

Tim C
(If it is written by a Tim it must be good.)

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


Re: Cross-platform GUI development

2007-10-12 Thread Dan Stromberg
On Fri, 12 Oct 2007 05:30:13 -0500, Nick Craig-Wood wrote:


> 3) Isn't a pain to install on windows (GTK)

pygtk is easy to install on windows if you use cygwin.

I started developing a little ssh GUI frontend on a windows laptop using
cygwin pygtk and cygwin openssh.  When I moved it over to a Linux VMware
on the same laptop to finish it, the code Just Worked.


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


Re: Convert obejct string repr to actual object

2007-10-12 Thread English, Mark
> From: Tor Erik Sønvisen
> Date: October 8th 2007
> I've tried locating some code that can recreate an object from
> it's string representation... 
On a related note I've wondered about this:
>>> class Foo(object): pass
>>> f = Foo()
>>> s = repr(f)
>>> s
'<__main__.Foo object at 0x007CBAB0>'

So how do I get f back from s ?
Obviously this is open to abuse. I just wondered if a mechanism existed short 
of writing
a C-extension which parses that string, casts the hex number to a PyObject *, 
INCREFs it,
and gives it back...
__

This email is intended only for the use of the individual(s) to whom it is 
addressed and may be privileged and confidential.
Unauthorised use or disclosure is prohibited.If you receive This e-mail in 
error, please advise immediately and delete the original message.
This message may have been altered without your or our knowledge and the sender 
does not accept any liability for any errors or omissions in the message.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RMI with Pyro et al

2007-10-12 Thread Diez B. Roggisch
Irmen de Jong schrieb:
> Diez B. Roggisch wrote:
> 
>> Go install cygwin (but not it's included python-interpreter, or at least
>> make sure you have your python path properly under control) and then 
>> simply
>> start the script from the command-line. And hit C-c if you need it to 
>> stop,
>> and restart it. Only start it as service if it's deployed.
> 
> What's cygwin got to do with it?

Being the better shell. Nothing else :)

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


Re: PEP idea: Instrumented Python

2007-10-12 Thread Erik Jones
On Oct 12, 2007, at 10:09 AM, Christopher Nelson wrote:

> I was looking at adding dtrace-like dynamic tracing to Python.   
> Note that this isn't dtrace itself.  The basic rationale:
>
> 1. A lot of enterprise-level software is written in Python.  It is  
> difficult to impossible to reproduce the customer environment in a  
> test lab.  Sometimes applications hang mysteriously, and we are  
> unable to duplicate the problems in our environment.
> 2. dtrace is a good design.  It has little to no overhead for  
> collection points that are not collecting data.  Emulating that  
> behavior allows you to test what you fly and fly what you test.
> 3. Having the ability to only get trace data you want (or need)  
> instead of trace data for every instruction executed is very  
> useful.  It also reduces bandwidth requirements when archiving the  
> traces, or shipping them out over a network connection.
> 4. The ability to dynamically expand and contract the tracing scope  
> during a trace is vital to getting the right data.
>
> The general plan would be to provide collectors in all of the  
> public python API functions.  The filtering code would also be in  
> the local system, for speed and bandwidth-conserving purposes.  The  
> filters should generally be native code.  The data should be  
> writeable to a file or to a network socket.  In addition, there  
> should be a network socket listening for commands from a tracing  
> client.  The client would be able to upload additional filter  
> scripts and start or stop tracing transparently to the running source.
>
> For security there should be an authentication mechanism that  
> allows the application to decide whether or not a connection to the  
> trace facility should be allowed, and a way to disable the trace  
> listening port on startup.  (Or perhaps it should be disabled on  
> startup by default and enabled if so desired.)
>
> Finally, there should, of course, be Pythonic access to the trace  
> system.
>
> The essential differences between the current tracing system and  
> the proposal involve the selectable granularity, the transparent  
> remote access, and automatic triggering of collection points.
>
> Comments? Please make sure to reply to all, I am not subscribed to  
> the list.

I've recently starting thinking of something along these lines  
although I don't the need to alter existing libraries or even mimic  
Dtrace given Python's extremely dynamic nature and reflection  
capabilities.  Ian Bicking wrote something along these lines for  
Paste that is used in Pylons wherein exceptions raised by the  
application during debug mode drop you into an interactive debugger  
with a web interface -- very handy for developing webapps.

This got me thinking about building a module that could be included  
by projects that creates a socket and responds to messages on that  
socket in a separate thread from the main app so that you can connect  
to the app and explore its current state.  Take a look at the  
evalexception module in Paste to see what he does.

Erik Jones

Software Developer | Emma®
[EMAIL PROTECTED]
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com


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


Re: Simple question about python logic.

2007-10-12 Thread Tim Chase
> I have a file containing following data. But the dimension can be
> different.
> 
> A B C D E F G
> 3 4 1 5 6 2 4
> 7 2 4 1 6 9 3
> 3 4 1 5 6 2 4
> 7 2 4 1 6 9 3
> .
> .
> .
> .
> 
> What is the best approach to make a column vector with the name such
> as A B, etc?


There are a couple different ways to go about it depending on

1) whether just one or whether both dimensions can be different
2) whether you want to extract each column vector

Both of the following should allow for an arbitrary number of
columns:

To map everything, you can do something like

###
infile = file("in.txt")
header_row = infile.next().rstrip('\n').split()
values = [[] for header in header_row]
for line in infile:
line = line.rstrip('\n').split()
for dest, value in zip(values, line):
dest.append(value)
infile.close()
results = dict(zip(header_row, values))
###


which you can then use with

results['A']

However, if you just want a particular column from the file and
don't care about the rest, you can do something like

###
from itertools import islice

column_c = [
 line.rstrip('\n').split()[2]
 for line in islice(file('in'), 1, None)
 ]
###

where "2" is the zero-based column offset you want (in this case,
column C = 2)

-tkc



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


Re: Top 10 Caribbean island destinations

2007-10-12 Thread John McWilliams
[EMAIL PROTECTED] wrote:
> lol :) another one on baseball : 90% of the game is physical, the
> other half is mental.
> 
> GS
> [EMAIL PROTECTED]
> 
> On Oct 11, 7:32 pm, willshak <[EMAIL PROTECTED]> wrote:
>> on 10/11/2007 10:14 PM Audio expert said the following:
>>
>>> Now I know where NOT to go.
>>> TOO crowded for me.
>> No one goes there anymore. It's too crowded.
>> Lawrence "Yogi" Berra
>>
>>
>>
>>> <[EMAIL PROTECTED]> wrote in message
>>> news:[EMAIL PROTECTED]
 See the most popular Caribbean island destinations
 http://tropical-destinations.blogspot.com/
>> --
>>
>> Bill
>> In Hamptonburgh, NY
>> To email, remove the double zeroes after @
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question about python logic.

2007-10-12 Thread Carl Banks
On Oct 12, 11:32 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I have a file containing following data. But the dimension can be
> different.
>
> A B C D E F G
> 3 4 1 5 6 2 4
> 7 2 4 1 6 9 3
> 3 4 1 5 6 2 4
> 7 2 4 1 6 9 3
> .
> .
> .
> .
>
> What is the best approach to make a column vector with the name such
> as A B, etc?

Use a dict.  dict objects are the main way we map names to objects on
the fly.  Simple example:

columns = {}
columns["A"] = [3,7,3,3]
columns["B"] = [4,2,4,2]


Filling in the columns with data from your file is left as an
exercise.


Carl Banks

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


Re: Cross-platform GUI development

2007-10-12 Thread Grant Edwards
On 2007-10-12, Grant Edwards <[EMAIL PROTECTED]> wrote:

> I use wxPython, because it uses Gtk on Linux, and Gtk is
> "native" for both me and for my Windows users.

I didn't state that very well.  

What I meant was that wxPython uses Gtk under Linux (which is
native for me) so wxPython looks native for both me and my
Windows users.

-- 
Grant Edwards   grante Yow! I demand IMPUNITY!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-platform GUI development

2007-10-12 Thread Grant Edwards
On 2007-10-12, BlueBird <[EMAIL PROTECTED]> wrote:

>> I'd recommend wxPython over those becase
>>
>> 1) native look and feel on all platforms

Not true for KDE or other non-Gtk desktops.

> You get it with PyQt as well.

Not true for Gnome or other non-Qt desktops.

There is no single "native look and feel" for Linux systems.

There are about a half-dozen different widget sets (Gtk and Qt
being the two big ones).

-- 
Grant Edwards   grante Yow! !!  I am having fun!!!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-platform GUI development

2007-10-12 Thread Grant Edwards
On 2007-10-12, Alexandre Badez <[EMAIL PROTECTED]> wrote:

> Personnaly, I use PyQt simply because I prefere Qt to Gtk,
> witch is much more integrated with all desktop than Gtk.

So you're claiming Qt is much more integrated with Gnome than
Gtk? The mind wobbles.  The Gnome and XFCE desktops are _built_
using Gtk.  A machine running a Gnome or XFCE desktop doesn't
even need to have Qt installed.  The same can be said for
various other deskops (openstep, equinox, etc. -- most of them
other than KDE, actually).

> In fact, your application in Qt on Mac, Win or Linux look like
> a native app.

Qt sure doesn't look native on my Linux machines, and it's not
going to look native on any GTK-based desktops such an Gnome or
XFCE.  Qt will only look native on Linux machines running a Qt
based desktop such as KDE.

> Just a question of "feeling" I think; because most of those
> GUI framework, offer quiet the same functionality.

I use wxPython, because it uses Gtk on Linux, and Gtk is
"native" for both me and for my Windows users.

-- 
Grant Edwards   grante Yow! My Aunt MAUREEN was a
  at   military advisor to IKE &
   visi.comTINA TURNER!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyserial doesn't recognize virtual serial port

2007-10-12 Thread Grant Edwards
On 2007-10-12, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
>   I am trying to use virtual serial ports to develop/test my serial
> communication program. Running in to trouble...
>
>   I am using com0com to create the virtual ports. The virtual ports
> seem to be working fine when I test it with Hyperterminal.

I'm not sure what you mean by "virtual ports".  I've used
pyserial with several different network attached devices that
provide drivers that make them appear as COMnn devices under
windows.  I never had any problems.

> I am using the example program that comes with pyserial, as below.
> ---
> import serial
> ser = serial.Serial('CNCA0') #open virtual serial port
> print ser.portstr#check which port was realy used
> ser.write("Hello")   #write a string
> ser.close()  #close port
> -
>
> The following is the error message:
>
> --
> Traceback (most recent call last):
>   File "C:\Python25\Naveen Files\TestSerial", line 2, in 
> ser = serial.Serial('CNCA0') #open first serial port
>   File "c:\Python25\Lib\site-packages\serial\serialutil.py", line 156,
> in __init__
> self.open()
>   File "c:\Python25\Lib\site-packages\serial\serialwin32.py", line 55,
> in open
> raise SerialException("could not open port: %s" % msg)
> SerialException: could not open port: (2, 'CreateFile', 'The system
> cannot find the file specified.')
> --

If you specify a filename that the OS doesn't recognize there's
nothing pyserial can do about it.

> When I try with 'COM3', which comes inbuilt in my laptop, COM3 is
> recognized. Few other posts on the web seem to indicate pyserial
> should work fine with virtual serial ports. What am I missing?

My guess is you're not spelling the device name correctly.
Device names under Windows are even more screwed up than the
rest of the OS.  By default there are a limited set of devices
with specially mapped "DOS compatible" names such as LPT1,
COM3, etc.  My guess is that the device you're attempting to
use doesn't have a name that's mapped to the DOS-compatible
namespace as CNCA0.

You could try using the name \\.\CNCA0

Or you could try to figure otu how to map the device into the
DOS namespace as CNCA0.

You could also try running some sort of system call trace on
HyperTerminal to find out what name it's using to open the
device when you tell it to use port CNCA0.

Or you could just give up and switch to Linux.  [That's what
I'd recommend, personally.]

-- 
Grant Edwards   grante Yow! YOU PICKED KARL
  at   MALDEN'S NOSE!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Simple question about python logic.

2007-10-12 Thread [EMAIL PROTECTED]
I have a file containing following data. But the dimension can be
different.

A B C D E F G
3 4 1 5 6 2 4
7 2 4 1 6 9 3
3 4 1 5 6 2 4
7 2 4 1 6 9 3
.
.
.
.

What is the best approach to make a column vector with the name such
as A B, etc?

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


PEP idea: Instrumented Python

2007-10-12 Thread Christopher Nelson
I was looking at adding dtrace-like dynamic tracing to Python.  Note that
this isn't dtrace itself.  The basic rationale:

1. A lot of enterprise-level software is written in Python.  It is difficult
to impossible to reproduce the customer environment in a test lab.
Sometimes applications hang mysteriously, and we are unable to duplicate the
problems in our environment.
2. dtrace is a good design.  It has little to no overhead for collection
points that are not collecting data.  Emulating that behavior allows you to
test what you fly and fly what you test.
3. Having the ability to only get trace data you want (or need) instead of
trace data for every instruction executed is very useful.  It also reduces
bandwidth requirements when archiving the traces, or shipping them out over
a network connection.
4. The ability to dynamically expand and contract the tracing scope during a
trace is vital to getting the right data.

The general plan would be to provide collectors in all of the public python
API functions.  The filtering code would also be in the local system, for
speed and bandwidth-conserving purposes.  The filters should generally be
native code.  The data should be writeable to a file or to a network
socket.  In addition, there should be a network socket listening for
commands from a tracing client.  The client would be able to upload
additional filter scripts and start or stop tracing transparently to the
running source.

For security there should be an authentication mechanism that allows the
application to decide whether or not a connection to the trace facility
should be allowed, and a way to disable the trace listening port on
startup.  (Or perhaps it should be disabled on startup by default and
enabled if so desired.)

Finally, there should, of course, be Pythonic access to the trace system.

The essential differences between the current tracing system and the
proposal involve the selectable granularity, the transparent remote access,
and automatic triggering of collection points.

Comments? Please make sure to reply to all, I am not subscribed to the list.

-={C}=-
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python module for making Quicktime or mpeg movies from images

2007-10-12 Thread TYR
On Oct 11, 4:17 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> jeremito wrote:
> > On Oct 11, 10:43 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> >> jeremito wrote:
> >>> My Python script makes a bunch of images that I want to use as frames
> >>> in a movie.  I've tried searching for a module that will take these
> >>> images and put them together in a Quicktime or mpeg movie, but haven't
> >>> found anything.  My images are currently pdfs, but I could make them
> >>> into just about anything if needed.
> >>> Is there a module, or example of how to do this?
> >>http://pymedia.org/
>
> >> Diez
>
> > That initially looked promising, but it looks like nobody is working
> > on it anymore and it doesn't compile on Mac.  (I should have mentioned
> > I am using a Mac.)  Any other suggestions?
>
> Not really a Python module but... run them
> through mencoder? (Haven't tried it but it
> seems to be saying it's possible).
>
> http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html#EXAMPLES%20OF%20ME...
>
> TJG

NodeBox; nodebox.org

GUI application that creates either PDFs or Quicktime vids from python
code. Unix/Linux/MacOS.

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


Re: Memory Problems in Windows 2003 Server

2007-10-12 Thread brad
amdescombes wrote:
> Hi,
> 
> I am using Python 2.5.1
> I have an application that reads a file and generates a key in a 
> dictionary for each line it reads. I have managed to read a 1GB file and 
> generate more than 8 million keys on an Windows XP machine with only 1GB 
> of memory and all works as expected. When I use the same program on a 
> Windows 2003 Server with 2GB of RAM I start getting MemoryError exceptions!
> I have tried setting the IMAGE_FILE_LARGE_ADDRESS_AWARE on both 
> Python.exe and Python25.dll and setting the /3GB flag on the boot.ini 
> file to no avail. I still get the MemoryError exceptions.
> 
> Has anybody encountered this problem before?
> 
> Thanks in advance for any ideas/suggestions.
> 
> Best Regards,
> 
> André M. Descombes

I forgot to mention that the OS itself or other processes may be using a 
lot of memory. So, just because you have 2GB, that does not mean you can 
access all of that at once. I would guess that 25% of memory is in 
constant use by the OS. So, do your IO/reads in smaller chunks similar 
to the example I gave earlier.

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


Re: Memory Problems in Windows 2003 Server

2007-10-12 Thread brad
amdescombes wrote:
> Hi,
> 
> I am using Python 2.5.1
> I have an application that reads a file and generates a key in a 
> dictionary for each line it reads. I have managed to read a 1GB file and 
> generate more than 8 million keys on an Windows XP machine with only 1GB 
> of memory and all works as expected. When I use the same program on a 
> Windows 2003 Server with 2GB of RAM I start getting MemoryError exceptions!
> I have tried setting the IMAGE_FILE_LARGE_ADDRESS_AWARE on both 
> Python.exe and Python25.dll and setting the /3GB flag on the boot.ini 
> file to no avail. I still get the MemoryError exceptions.
> 
> Has anybody encountered this problem before?
> 
> Thanks in advance for any ideas/suggestions.
> 
> Best Regards,
> 
> André M. Descombes

How are you reading the large files? IMO, large files are better read in 
chunks:

target_file = open(f, 'rb')
while 1:
 data = target_file.read(8192000)
 if data:
 DO SOMETHING
 else:
 break

The above reads 8MB at a time until the file has been completely read. 
Change the 8MB to whatever you like.
-- 
http://mail.python.org/mailman/listinfo/python-list


Subprocess Running Slowly

2007-10-12 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm looking for a little advice on spawning a sub process to run a command
line application for transferring a file over Bluetooth. Now the spawned
process runs from start to finish exactly as I would expect it too, however
its very slow. 

 

Now the main reason this is so odd, is that If I have my python application
running as usual, and I start the command line application manually myself
from the command line, then it'll transfer the file to my phone about 3 or 4
times faster than when the app is launch using sub process. Take a look
below for a quick snippet example of my process launch code.

 

send = 'ussp-push --debug --dev hci%s [EMAIL PROTECTED] /pblue/new/Media/%s %s' 
% (

adapter, 

mac, 

result, 

media[3], 

media[0]

)

process = subprocess.Popen(

send, 

shell=True, 

stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr

 

Do you have any ideas what might be causing this slow behaviour? Do spawned
sub processes generally run at a much slower rate than expected? Or is this
something specific to my application?

 

I'd love to work this out as when transferring larger files this becomes a
real pain, especial when I know there is no real physical reason for it
running so slowly.

 

Thanks guys for any help you can offer.

 

Rob

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

Re: Traceback (most recent call last): PROBLEM

2007-10-12 Thread Peter Otten
smarras wrote:

> Hello everyone, I keep obtaining an error message whenever I execute some
> very simple routines; the error that follows says that I am calling
> certain functions that, in reality, I am not calling from any of the
> routines that I wrote:
> 
> error:
> 
>> python fwrite_mat.py
> 
>   0, 0, 0, 0 ,  0, 1, 2, 3 ,  0, 2, 4, 6
> Traceback (most recent call last):
>   File "fwrite_mat.py", line 7, in 
> from xlrd import *
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/xlrd/__init__.py",
> line 256, in 
> from timemachine import *
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/xlrd/timemachine.py",
> line 21, in 
> from array import array as array_array
> ImportError: cannot import name array
> 
> In these lines that I pasted, for example the "array-looking" string has
> nothing to do with my function, nor the import name "timemachine" or the
> import name "array".
> 
> Can anyone help me understand why python is looking such libraries, and
> why it keeps in memory an array that I am not using?
> 
> Here also the simple routine I wrote:
> 
> import os, sys
> import xlrd

"import xlrd" triggers the execution of the file .../xlrd/__init__.py
containing the statement "from timemachine import *" which in turn causes
.../xlrd/timemachine.py to execute. The latter file contains "from array
import array as array_array", so yes you are using "array" though
indirectly -- or you would if the import didn't fail.

The cause of the failure is probably a script named "array.py" that you
have written and put in the same folder as fwrite_mat.py. Rename
your array.py, remove the corresponding array.pyc, and the error should go
away.

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


Re: matching a street address with regular expressions

2007-10-12 Thread John Machin
On Oct 12, 4:07 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Oct 11, 11:50 pm, John Nagle <[EMAIL PROTECTED]> wrote:
>
>
>
> > If anyone has a first-rate address parser in Python that will cover
> > most of the developed world, I'd like to talk to them.
>
> > John Nagle
> > SiteTruth
>
> The pyparsing examples page includes a street address parser (http://
> pyparsing.wikispaces.com/space/showimage/streetAddressParser.py) that
> will handle these test cases:
>
> 100 South Street
> 123 Main
> 221B Baker Street
> 10 Downing St
> 1600 Pennsylvania Ave
> 33 1/2 W 42nd St.
> 454 N 38 1/2
> 21A Deer Run Drive
> 256K Memory Lane
> 12-1/2 Lincoln
> 23N W Loop South
> 23 N W Loop South
> 25 Main St
> 2500 14th St
> 12 Bennet Pkwy
> Pearl St
> Bennet Rd and Main St
> 19th St
>
> -- Paul

"... most of the developed world" was the [very optimistic] request.
How does it go with "JAPAN 112-0001 TOKYO Bunkyo-Ku Hakusan 4-Chome 3-
2" and will it give the same result for "4-3-2 HAKUSAN BUNKYO-KU TOKYO
112-1 JAPAN"? OK, a little exotic ... closer to "home", what about
addresses in Quebec? People often write addresses in formats that you
won't find on the postal service website, but the local postal workers
will still deliver. Rural addresses can be quaintly medieval e.g. "Lot
123, Hundred of Foughbarre" [South Australia]. Etc etc ...

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


Re: Declarative properties

2007-10-12 Thread Stargaming
On Thu, 11 Oct 2007 18:58:44 +0200, Bruno Desthuilliers wrote:
[snip]

Your implementation seems particularly broken. You do not return anything 
from `name()`, hereby removing name as an attribute (or: replacing it 
with its return value -- None). You should return ``property(**locals())
`` (or ``property(fget=fget, fset=fset, ...)``, whatever you like).

I'm going to point out a few other mistakes first:

> class Toto(object):
>def __iinit__(self, name):

Typo here: __init__

>  self.name = name
>@apply
>def name():
>  def fget(self):
>print "getting %s.name" % self
>return self._name
>  def fset(self, val):
>print "setting %s.name to %s" % (self, val) 
>self._name = name

It should be `val`, not `name`, huh? And, as mentioned above, the return 
value is missing.

>def say_hello(self):
>  print "Hello, my name is %s" % self.name

A fixed implementation could be something along these lines::

>>> class Toto(object):
...def __init__(self, name):
...  self.name = name
...@apply
...def name():
...  def fget(self):
...print "getting %s.name" % self
...return self._name
...  def fset(self, val):
...print "setting %s.name to %s" % (self, val)
...self._name = val
...  return property(**locals())
...def say_hello(self):
...  print "Hello, my name is %s" % self.name
...
>>> t = Toto("bruno")
setting <__main__.Toto object at 0xb792f66c>.name to bruno
>>> t.say_hello()
getting <__main__.Toto object at 0xb792f66c>.name
Hello, my name is bruno
>>> t.name
getting <__main__.Toto object at 0xb792f66c>.name
'bruno'
>>> t.name = "jon"
setting <__main__.Toto object at 0xb792f66c>.name to jon
>>> t.say_hello()
getting <__main__.Toto object at 0xb792f66c>.name
Hello, my name is jon

Cheers,
Stargaming
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set proxy in Python for flickr api

2007-10-12 Thread honestguy1999
On Oct 12, 2:40 pm, [EMAIL PROTECTED] wrote:
> Hi, everyone, I am using beej's flickr api in Python. For some reason
> I have to bypass the firewall using a proxy. I read the urllib
> reference and set http_proxy="my proxy". But it didn't work. I can't
> even get authenticated. Is there anyway that we can set the proxy?

I am using v2.5 in windows

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


Re: Problem with MySQL cursor

2007-10-12 Thread Carsten Haese
On Fri, 2007-10-12 at 13:12 +0200, Florian Lindner wrote:
> Carsten Haese wrote: 
> > sql = "INSERT INTO "+DOMAIN_TABLE+"("+DOMAIN_FIELD+") VALUES (%s)"
> > executeSQL(sql, domainname)
> 
> Ok, I understand it and now it works, but why is limitation? Why can't I
> just the string interpolation in any playes and the cursor function escapes
> any strings so that they can't do harm to my query?

What's happening here is not string interpolation. It's called parameter
binding, and the SQL standard defines exactly what parameter binding can
and can not do. (The SQL standard also defines that parameter markers
are question marks, and the fact that DB-API v2 modules are allowed to
blur the distinction between string interpolation and parameter binding
by choosing to use %s markers is very unfortunate.)

A primary purpose of parameter binding is the ability to prepare a query
once and then execute it many times over with different values. This
saves time because the query only needs to be parsed and planned once.
For this to be useful, parameters can't be bound to anything that would
alter the query plan. Consequently, parameter binding can't "substitute"
any of the following:

* The type of statement (SELECT/UPDATE/etc.)
* The tables involved
* The columns involved
* The structure of the join and where clauses
* The group by, order by, and having clauses
* The names of called functions and procedures
* Probably a whole lot of other things I'm not thinking of right now

Once you exclude all the things that parameter binding can't substitute,
you're left with only a very small segment of the SQL language that
parameter binding *can* substitute, which basically boils down to
"anything that could be a literal value".

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Last iteration?

2007-10-12 Thread tasjaevan
On Oct 12, 11:58 am, Florian Lindner <[EMAIL PROTECTED]> wrote:
> Hello,
> can I determine somehow if the iteration on a list of values is the last
> iteration?
>
> Example:
>
> for i in [1, 2, 3]:
>if last_iteration:
>   print i*i
>else:
>   print i
>
> that would print
>
> 1
> 2
> 9
>
> Can this be acomplished somehow?
>

Another suggestion:

  l = [1, 2, 3]
  for i in l[:-1]: print i
  i = l[-1]
  print i*i


James



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


Re: Cross-platform GUI development

2007-10-12 Thread Eric Brunel
On Fri, 12 Oct 2007 10:13:29 +0200, [EMAIL PROTECTED]  
<[EMAIL PROTECTED]> wrote:
> I've been programming in Python for 5 or more years now and whenever I
> want a quick-n-dirty GUI, I use Tkinter. This is partly because it's
> the first toolkit I learnt, but also because it's part of the standard
> Python distribution and therefore easy to get Python apps to work
> cross platform - it usually requires almost no porting effort.
>
> However, when I need a little bit more grunt, I tend to turn to Tix,
> which I thought was also fairly standard. However, this week, I wrote
> a Tix application under Linux which I'd really like to work on Mac OS
> and it's proving fairly painful to get it going. There is no Tix in
> the standard fink or apt repositories and when I download a tar-ball,
> it wouldn't build because it had a lot of unmet dependencies. I then
> read a post which said that only Tkinter/Python people really use Tix
> anymore and people in tcl/tk moved onto better toolkits long ago.
>
> My question is if Tix is old hat, what is the GUI toolkit I *should*
> be using for quick-n-dirty cross platform GUI development?

Since you're already used to Tkinter, I'd say: just wait... tcl/tk 8.5 is  
on the way and it will bring a lot of new and long-awaited widgets, along  
with native look on most platforms. See here:
http://wiki.tcl.tk/14796
and here for the look:
http://tktable.sf.net/tile/

Note that there are already Tkinter wrappers for these widgets, but they  
may not be the ones that'll end up in the official distribution. If you  
want to play with them, you can find them here:
https://sourceforge.net/project/showfiles.php?group_id=165637
(download tkinter-wrappers)

If you want to use these, you'll of course also need the latest beta of  
tcl/tk 8.5, downloadable from here:
http://www.tcl.tk/software/tcltk/8.5.html

> I hope this isn't a stupid question. I'm wearing flame retardant
> underwear.

You won't need these much around here... ;-)

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Last iteration?

2007-10-12 Thread Paul Hankin
On Oct 12, 11:58 am, Florian Lindner <[EMAIL PROTECTED]> wrote:
> Hello,
> can I determine somehow if the iteration on a list of values is the last
> iteration?
>
> Example:
>
> for i in [1, 2, 3]:
>if last_iteration:
>   print i*i
>else:
>   print i

Yes, either use enumerate or just stop the loop early and deal with
the last element outside the loop.

xs = [1, 2, 3]
for x in xs[:-1]:
print x
print xs[-1] * xs[-1]

--
Paul Hankin

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


Re: Last iteration?

2007-10-12 Thread Diez B. Roggisch
Florian Lindner wrote:

> Hello,
> can I determine somehow if the iteration on a list of values is the last
> iteration?
> 
> Example:
> 
> for i in [1, 2, 3]:
>if last_iteration:
>   print i*i
>else:
>   print i
> 
> that would print
> 
> 1
> 2
> 9
> 
> 
> Can this be acomplished somehow?

 def last_iter(iterable):
it = iter(iterable)
buffer = [it.next()]
for i in it:
buffer.append(i)
old, buffer = buffer[0], buffer[1:]
yield False, old
yield True, buffer[0]

  

for last, i in last_iter(xrange(4)):
   if last:
   print i*i
   else:
   print i



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


Re: matching a street address with regular expressions

2007-10-12 Thread Grant Edwards
On 2007-10-12, Paul McGuire <[EMAIL PROTECTED]> wrote:

> I've been to Japan and Europe too, and I can't even figure out
> how many digits a phone number is supposed to have!

I was shocked at utterly foreign and lost I felt looking at
phone numbers in various places overseas.  I could deal with
phone numbers having other than 7/10 digits and being
punctuated differently, but in some places the number of digits
in a phone number is apparently random. Even among phone
numbers of the same length, the formatting (where the
spaces/hyphens) go, seems to be more-or-less random.

[Here in the US, a phone number is always the same length: 10
digits (though you only have to dial the first 3 if they're
different than your own).  Back in the pre-cellular days, given
just the first two digits of a phone number, you even knew
whether it was going to be all 10 digits or just 7.]

People speaking a different language was fine.  Driving on the
other side of the road was fine.  Colorful money with
rediculous exchange rates was fine.  Daytime being the wrong
length was definitely strange. But, phone numbers not having a
fixed length and format?  That's utter madness!

-- 
Grant Edwards   grante Yow! Oh my GOD -- the
  at   SUN just fell into YANKEE
   visi.comSTADIUM!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Last iteration?

2007-10-12 Thread Florian Lindner
Hello,
can I determine somehow if the iteration on a list of values is the last
iteration?

Example:

for i in [1, 2, 3]:
   if last_iteration:
  print i*i
   else:
  print i

that would print

1
2
9


Can this be acomplished somehow?

Thanks,

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


Re: EasyMock for python ?

2007-10-12 Thread BlueBird
On Oct 11, 4:26 pm, "Simon Brunning" <[EMAIL PROTECTED]> wrote:
> On 10/10/07, BlueBird <[EMAIL PROTECTED]> wrote:
>
> > Does anybody know where to find a library like EasyMock for python ? I
> > searched quickly but could not find anything.
>
> > I found python-mocks on sourceforge but form quickly reading the docs,
> > it is not an EasyMock style mock. Actually, according to
> >http://martinfowler.com/articles/mocksArentStubs.htmlI don't think it
> > is even a mock library. More a stub.
>
> python-mock is more jMock than EasyMock in style, it's true, and the
> fact that you define expectations *after* the test invocation rather
> than before does feel a bit odd. But it does indeed check against the
> defined expectations, so that makes it a mock library in my book.
>
> A record-playback EasyMock style mock library would be nice, it's true...

It should not be that hard to do, given that python-mocks already has
the notion of recording and expectation verifiation.

I may give it a stab.

   Philippe


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


Re: Python service gets interrupted function call

2007-10-12 Thread Roger Upole

"ashish" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Hi All,
> I wanted to know how to handle events like 'logoff' in the main thread
> so that any process which is being run by svcDoRun method of service
> does not get 'interrupted function call' exception.
>
> I am posting a very simple service program , and i want to know that
> is there a way to handle such interrupts without explicitly calling
> try except block over blocking calls.
>
> Here is the example which is getting interrupted exception at logoff.
> ===
> import os, time, sys
> import win32serviceutil, win32service
> import pywintypes, win32con, winerror
> # Use "import *" to keep this looking as much as a "normal" service
> # as possible.  Real code shouldn't do this.
> from win32event import *
> from win32file import *
> from win32pipe import *
> from win32api import *
> from ntsecuritycon import *
>
> import servicemanager
>
> import traceback
> import thread, time
>
> class TrialService(win32serviceutil.ServiceFramework):
>_svc_name_ = "TrialService"
>_svc_display_name_ = "TrialService"
>_svc_description_ = "TrialService"
>_exe_name_ = "C:/Python24/Lib/site-packages/win32/
> pythonservice.exe"
>
>def __init__(self, args):
>win32serviceutil.ServiceFramework.__init__(self, args)
>self.hWaitStop = CreateEvent(None, 0, 0, None)
>self.overlapped = pywintypes.OVERLAPPED()
>self.overlapped.hEvent = CreateEvent(None,0,0,None)
>
>def SvcStop(self):
>self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
>SetEvent(self.hWaitStop)
>
>def SvcDoRun(self):
>time.sleep(1000)
>
> def ctrl_handler(ctrl_type):
>return True
>
> if __name__ =='__main__':
>SetConsoleCtrlHandler(ctrl_handler, True)
>win32serviceutil.HandleCommandLine(TrialService)
>
> 
>
> In actual call i just want to call my app in place of time.sleep but
> my app will have blocking code segments.
> Any help will be greatly appreciated .
> Thanks
> Ashish

Use win32api.Sleep, and pass True for the second arg.

 Roger



== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-platform GUI development

2007-10-12 Thread Nick Craig-Wood
Alexandre Badez <[EMAIL PROTECTED]> wrote:
>  On Oct 12, 10:13 am, "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> wrote:
> > My question is if Tix is old hat, what is the GUI toolkit I *should*
> > be using for quick-n-dirty cross platform GUI development? I guess
> > this is tangentially related to:
> >
> > http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
> 
>  Personnaly, I use PyQt simply because I prefere Qt to Gtk, witch is
>  much more integrated with all desktop than Gtk.
>  In fact, your application in Qt on Mac, Win or Linux look like a
>  native app.

I'd recommend wxPython over those becase

1) native look and feel on all platforms
2) doesn't require expensive licensing for non-commercial apps (QT)
3) Isn't a pain to install on windows (GTK)

That said, times change and 1-3 may have changed since I last looked
at it!

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with global

2007-10-12 Thread Florian Lindner
Hello,
I have a little problem with the global statement.

def executeSQL(sql, *args):
try:
import pdb; pdb.set_trace()
cursor = db.cursor()  # db is .
[...]
except:
print "Problem contacting MySQL database. Please contact root."
sys.exit(-1) 


db  = None # Global Variable for DB connection

def main():
[...]
global db
db = MySQLdb.connect(...)
[...]
executeSQL(sql, args)


Why isn't the global variable db not written in main() to be a mysql
connection and still none type in executeSQL?

Thanks,

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


Re: Script to Remove Attachments in Exchange Mailbox

2007-10-12 Thread Tim Golden
Tim Golden wrote:
> [KDawg44]
> 
 I am frustrated with my users who send large files around the office
 instead of using the network shares.
> 
> [Tim Golden]
>>> I have something v. similar, ...
>>> It's a while since they were last run to they're probably quite
>>> dusty but it sounds like the kind of thing you're after.
> 
> Well, here's[1] the first part -- running through folders and replacing
> big attachments with links. 

... and here's [1] the second part -- running through folders on disk
and replacing duplicate files with a link to the first one found. For
obvious reasons, be careful with this: it deletes files and replaces
them with hardlinks, but there's no rollback. Nor is it so well
commented as the other, I'm afraid, but I think it is still fairly
clear what's going on.

You call it with a space-separated list of directories to search
(usually one in my own experience) and it walks down those directory
trees looking for files of type INCLUDE_EXTENSIONS except for files
called IGNORE_FILES. Its comparison is very simple: comparing md5
hashes with no optimisations; obviously a lot of work could be done
there if it were an issue.

It ends up with nested dictionaries, the outer one keyed by filename,
the inner one by size and containing a list of directories where
files of that name/size are found. The first in the list is considered
the master and all the others are deleted and replaced by NTFS
hardlinks. Probably safer to hardlink first to an alias, *then*
delete and then rename the alias, but I leave that up to you if
you want to use the script at all.

TJG

[1] http://timgolden.me.uk/python/downloads/find_duplicate_files.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-platform GUI development

2007-10-12 Thread BlueBird
On Oct 12, 12:30 pm, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> > > My question is if Tix is old hat, what is the GUI toolkit I *should*
> > > be using for quick-n-dirty cross platform GUI development? I guess
> > > this is tangentially related to:
>
> > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
> >  Personnaly, I use PyQt simply because I prefere Qt to Gtk, witch is
> >  much more integrated with all desktop than Gtk.
> >  In fact, your application in Qt on Mac, Win or Linux look like a
> >  native app.

>From my point of view, PyQt is very good. Qt is very actively
developed and maintained, and the PyQt binding is of very good
quality, and fully documented. I have used personally for several
cross-platform projects and it worked like a charm.

I like Qt's approach and extensive documentation. I've found that it
works both for complex GUI as for quick'n dirty. There is usually a
widget to do just what I need so that I can focus on my application
logic instead of on the GUI code.

In short, usage of Qt has driven me to love it.

When looking at the other guis, I always find that the documentation
is under my expectations, or that that things are quite complex to set-
up to get what you need.

On Oct 12, 12:30 pm, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> I'd recommend wxPython over those becase
>
> 1) native look and feel on all platforms

You get it with PyQt as well.

> 2) doesn't require expensive licensing for non-commercial apps (QT)

You mean "doesn't require expensive licensing for close source apps".
Open source apps are free of charge. For professional developments, I
bought the Qt license several times in the past because it was worth
the time saved in my opinion.

> 3) Isn't a pain to install on windows (GTK)

You get it with Qt as well. I was able to use it even as a windows
newbie.


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


RE: Last iteration?

2007-10-12 Thread Andreas Tawn
> Hello,
> can I determine somehow if the iteration on a list of values 
> is the last
> iteration?
> 
> Example:
> 
> for i in [1, 2, 3]:
>if last_iteration:
>   print i*i
>else:
>   print i
> 
> that would print
> 
> 1
> 2
> 9

Something like:

myList = [1, 2, 3]
for i, j in enumerate(myList):
if i == len(myList)-1:
print j*j
else:
print j

Cheers,

Andreas Tawn
Lead Technical Artist
Ubisoft Reflections
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Last iteration?

2007-10-12 Thread Stefan Behnel
Florian Lindner wrote:
> can I determine somehow if the iteration on a list of values is the last
> iteration?
> 
> Example:
> 
> for i in [1, 2, 3]:
>if last_iteration:
>   print i*i
>else:
>   print i
> 
> that would print
> 
> 1
> 2
> 9
> 
> 
> Can this be acomplished somehow?

You could do this:

  l = [1,2,3]
  s = len(l) - 1
  for i, item in enumerate(l): # Py 2.4
  if i == s:
  print item*item
  else:
  print item

Or, you could look one step ahead:

   l = [1,2,3]
   next = l[0]
   for item in l[1:]:
   print next
   next = item
   print next * next

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-10-12 Thread Mark Summerfield
On 12 Oct, 09:17, Paul Rubin  wrote:
> Mark Summerfield <[EMAIL PROTECTED]> writes:
> > Below is a PEP proposal for a sorteddict. ...
>
> Is this proposal dead?  I'd been meaning to post some thoughts which I
> still haven't gotten around to writing up, and am wondering whether to
> keep it on my todo list.

Yes, it's dead.

I've left the sorteddict implementation on PyPI for those that want
it, but there will be no PEP. GvR's view is that people should use
dict + sorted().

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


Re: Is this a bug of the lambda function

2007-10-12 Thread Carsten Haese
On Fri, 12 Oct 2007 01:00:47 -0400, Zhu Wayne wrote 
> Hi, 
> I have a short code which gives me strange results, the code is as follows: 
> 
> f = [lambda x: None]*5 
> for j in range(0, 5): 
>  f[j] = lambda x: float(j)*x 
> [...]
> It seems only when I use the index j (which is declear with the lambda
> function), I can get expected answer [...]

'j' is not declared with the lambda function. Inside the lambda, 'j' is a
global name. Global names inside a function body are looked up when the
function is called, not when the function is defined.

You are actually defining five identical functions that look up the global
name j, take its float value, and multiply that times the argument x.
If the name 'j' is deleted, the functions won't run anymore. Observe:

>>> f = [lambda x: None]*5
>>> for j in range(0, 5):
...   f[j] = lambda x: float(j)*x
...
>>> del j
>>> f[0](1)
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 2, in 
NameError: global name 'j' is not defined

To get the behavior you expect, you're going to have to cause the name 'j' to
be looked up (and frozen, so to speak) at the time the lambda is defined. One
way to do that is to use a default function argument:

>>> for j in range(0, 5):
...   f[j] = lambda x, inner_j=j: float(inner_j)*x
...
>>> del j
>>> f[0](1.)
0.0

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net

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


Re: matching a street address with regular expressions

2007-10-12 Thread Paul McGuire
On Oct 12, 8:19 am, John Machin <[EMAIL PROTECTED]> wrote:
> "... most of the developed world" was the [very optimistic] request.
> How does it go with "JAPAN 112-0001 TOKYO Bunkyo-Ku Hakusan 4-Chome 3-
> 2" and will it give the same result for "4-3-2 HAKUSAN BUNKYO-KU TOKYO
> 112-1 JAPAN"? OK, a little exotic ... closer to "home", what about
> addresses in Quebec? People often write addresses in formats that you
> won't find on the postal service website, but the local postal workers
> will still deliver. Rural addresses can be quaintly medieval e.g. "Lot
> 123, Hundred of Foughbarre" [South Australia]. Etc etc ...

John -

As I'm sure you already know, the answer is "not too well".  I've been
to Japan and Europe too, and I can't even figure out how many digits a
phone number is supposed to have!

I once lived in a small town in Virginia, and received a Christmas
card from a friend (who wanted to remind me just how small a town I
was living in) addressed simply as "The McGuire's, ,
Virginia" - I happened to mention it the next time I was at the post
office, and they said "yep, you're the only McGuires we got!"

In the spectrum of tools from string.split, to re, to pyparsing and
its ilk, to natural language toolkits, the broader the scope of your
"address space", the further you find your self moving toward NLTK.  I
knew my pyparsing script wasn't in the "anywhere in the developed
world" category, that's why I posted the test cases, too.

If you've got an re that can handle everything from "123 Main" to
"221B Baker Street" to "Hollywood and Vine" to "Lot 123, Hundred of
Foughbarre", now THAT would be something.

-- Paul

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


Re: decorating container types (Python 2.4)

2007-10-12 Thread George Sakkis
On Oct 11, 5:42 pm, [EMAIL PROTECTED] wrote:
> Hi,
>
> I have a container class A and I want to add functionality to it by
> using a decorator class B, as follows:
>
> class A(object):
> def __len__(self):
> return 5
>
> class B(object):
> def __init__(self, a):
> self._a = a
>
> def __getattr__(self, attr):
> return getattr(self._a, attr)
>
> def other_methods(self):
> blah blah blah
>
> I was expecting len(B) to return 5 but I get
> AttributeError: type object 'B' has no attribute '__len__'
> instead.
> I was expecting len() to call B.__len__() which would invoke
> B.__getattr__ to call A.__len__ but __getattr__ is not being called.
> I can work around this, but I am curious if anyone knows _why_
> __getattr__ is not being called in this situation.
>
> Thanks
> Tim

Unfortunately __getattr__ is not called for special attributes; I'm
not sure if this is by design or a technical limitation. You have to
manually delegate all special methods (or perhaps write a metaclass
that does this for you).

George

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


Re: Problem with MySQL cursor

2007-10-12 Thread Diez B. Roggisch
Florian Lindner wrote:

> Carsten Haese wrote:
> 
>> On Thu, 2007-10-11 at 15:14 +0200, Florian Lindner wrote:
>>> Hello,
>>> I have a function that executes a SQL statement with MySQLdb:
>>> 
>>> def executeSQL(sql,  *args):
>>> print sql % args
>>> cursor = conn.cursor()
>>> cursor.execute(sql, args)
>>> cursor.close()
>>> 
>>> it's called like that:
>>> 
>>> sql = "INSERT INTO %s (%s) VALUES (%s)"
>>> executeSQL(sql,  DOMAIN_TABLE, DOMAIN_FIELD, domainname)
>> 
>> You can't use parameter binding to substitute table names and column
>> names, or any other syntax element, into a query. You can only bind
>> parameters in places where a literal value would be allowed (more or
>> less, the real rules are more complicated, but this rule of thumb gets
>> you close enough). You have to construct the query string like this, for
>> example:
>> 
>> sql = "INSERT INTO "+DOMAIN_TABLE+"("+DOMAIN_FIELD+") VALUES (%s)"
>> executeSQL(sql, domainname)
> 
> Ok, I understand it and now it works, but why is limitation? Why can't I
> just the string interpolation in any playes and the cursor function
> escapes any strings so that they can't do harm to my query?

Because the function doesn't know that you wanted

select * from user where email = '[EMAIL PROTECTED]'

instead of

select * from user where email = 'foo'; drop table user where '' = ''

And of course you don't gain anything from using USER INPUT in the
string-interpolation for creating the sql statement!!!

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


Re: problem with wxPanel derivation class ~ thanks

2007-10-12 Thread none
none wrote:
> wxGlade created a simple Frame with a panel a sizer and 3 wxControls ,
> saticText, TextCtrl, and a Button.
> 
> The resulting code works fine.
> 
> Now the problem.
> I wish to make a separate class derrived from wxPanel that has the sized
> and controls as above.  It jusst won't work
> 
> 
> 
> #!/usr/bin/env python
> # -*- coding: ISO-8859-1 -*-
> # generated by wxGlade 0.4cvs on Thu Oct 11 13:26:19 2007
> 
> import wx
> 
> class MyFrameOne(wx.Frame):
> def __init__(self, *args, **kwds):
> # begin wxGlade: MyFrameOne.__init__
> kwds["style"] = wx.DEFAULT_FRAME_STYLE
> wx.Frame.__init__(self, *args, **kwds)
> self.panel = wx.Panel(self, -1)
> self.staticbox = wx.StaticBox(self.panel, -1, "StaticBox")
> self.label = wx.StaticText(self.panel, -1, "Field Name")
> self.textBox = wx.TextCtrl(self.panel, -1, "Field Value")
> self.button = wx.Button(self.panel, -1, "Edit")
> 
> self.__set_properties()
> self.__do_layout()
> # end wxGlade
> 
> def __set_properties(self):
> # begin wxGlade: MyFrameOne.__set_properties
> self.SetTitle("frame_1")
> self.label.SetMinSize((-1, 15))
> # end wxGlade
> 
> def __do_layout(self):
> # begin wxGlade: MyFrameOne.__do_layout
> sizer_1 = wx.BoxSizer(wx.VERTICAL)
> sizer = wx.StaticBoxSizer(self.staticbox, wx.HORIZONTAL)
> sizer.Add(self.label, 0, wx.ALL, 3)
> sizer.Add(self.textBox, 0, wx.ALL, 3)
> sizer.Add(self.button, 0, wx.ALL, 3)
> self.panel.SetAutoLayout(True)
> self.panel.SetSizer(sizer)
> sizer.Fit(self.panel)
> sizer.SetSizeHints(self.panel)
> sizer_1.Add(self.panel, 1, wx.EXPAND, 0)
> self.SetAutoLayout(True)
> self.SetSizer(sizer_1)
> sizer_1.Fit(self)
> sizer_1.SetSizeHints(self)
> self.Layout()
> # end wxGlade
> 
> # end of class MyFrameOne
> 
> ## modified from BoaApp
> class App(wx.App):
>   def OnInit(self):
>   wx.InitAllImageHandlers()
>   self.main = MyFrameOne(None)
>   self.main.Show()
>   self.SetTopWindow(self.main)
>   return True
> 
> def main():
>   application = App(0)
>   application.MainLoop()
> 
> if __name__ == '__main__':
>   main()
> 
> 
> 
> 
> #!/usr/bin/env python
> # -*- coding: ISO-8859-1 -*-
> #The commented out code from MyFrame was moved to class Panel \
> # and appropriately modified by changing self.panel to self etc
> 
> import wx
> 
> class MyFrameTwo(wx.Frame):
>   def __init__(self, *args, **kwds):
>   # begin wxGlade: MyFrameTwo.__init__
>   kwds["style"] = wx.DEFAULT_FRAME_STYLE
>   wx.Frame.__init__(self, *args, **kwds)
> ##self.panel = panel(self, -1)
>   self.panel = Panel(self, -1)
>   self.__set_properties()
>   self.__do_layout()
>   # end wxGlade
> 
>   def __set_properties(self):
>   # begin wxGlade: MyFrameTwo.__set_properties
>   self.SetTitle("frame_1")
>   self.label.SetMinSize((-1, 15))
>   # end wxGlade
> 
>   def __do_layout(self):
>   # begin wxGlade: MyFrameTwo.__do_layout
>   sizer_1 = wx.BoxSizer(wx.VERTICAL)
> ##sizer = wx.StaticBoxSizer(self.staticbox, wx.HORIZONTAL)
> ##sizer.Add(self.label, 0, wx.ALL, 3)
> ##sizer.Add(self.textBox, 0, wx.ALL, 3)
> ##sizer.Add(self.button, 0, wx.ALL, 3)
>   self.panel.SetAutoLayout(True)
> ##self.panel.SetSizer(sizer)
> ##sizer.Fit(self.panel)
> ##sizer.SetSizeHints(self.panel)
>   sizer_1.Add(self.panel, 1, wx.EXPAND, 0)
>   self.SetAutoLayout(True)
>   self.SetSizer(sizer_1)
>   sizer_1.Fit(self)
>   sizer_1.SetSizeHints(self)
>   self.Layout()
>   # end wxGlade
> 
> # end of class MyFrameTwo
> 
> 
> class Panel (wx.Panel):
>   def __init__(self, *args, **kwds):
>   self.staticbox = wx.StaticBox(self, -1, "StaticBox")
>   self.label = wx.StaticText(self, -1, "Field Name")
>   self.textBox = wx.TextCtrl(self, -1, "Field Value")
>   self.button = wx.Button(self, -1, "Edit")
>   __doLayout()
> 
>   def __doLayout():
>   sizer = wx.StaticBoxSizer(self.staticbox, wx.HORIZONTAL)
>   sizer.Add(self.label, 0, wx.ALL, 3)
>   sizer.Add(self.textBox, 0, wx.ALL, 3)
>   sizer.Add(self.button, 0, wx.ALL, 3)
>   
>   # maybe comment this and uncommennt  frame2's corresponding line
>   panel.SetAutoLayout(True)
>   
>   self.SetSizer(sizer)
>   sizer.Fit(self.panel)
>   sizer.SetSizeHin

Re: problem with wxPanel derivation class

2007-10-12 Thread kyosohma
On Oct 11, 4:01 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 10/11/07, <"@bag.python.org <"none> wrote:> wxGlade created a simple Frame 
> with a panel a sizer and 3 wxControls ,
> > saticText, TextCtrl, and a Button.
>
> 
>
> > It seems as though the complaint is that  a 'wxWindow *' is expected,
> > 'Panel' is received
> > However, Panel IS a wx.Panel derivative which IS a wx.Window derivative!
> > Additionally, the methods in the code of Panel and MyFrameOne seem to be
> > identical.
> > I can't understand this. Anyone have any thoughts?
>
> It's because you didn't call the base class __init__. wxPython is a
> SWIG wrapper around the C++ wxWidgets library, and if you don't call
> the base class the SWIG infrastructure that maps your class to an
> underlying C++ class doesn't happen and you get this error.

Ah-so. I knew there was a more technical answer than what I gave.
Hopefully I didn't muddy the issue with my doofy code.

Mike

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


Re: matching a street address with regular expressions

2007-10-12 Thread Paul McGuire
On Oct 12, 1:07 am, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Oct 11, 11:50 pm, John Nagle <[EMAIL PROTECTED]> wrote:
>
>
>
> > If anyone has a first-rate address parser in Python that will cover
> > most of the developed world, I'd like to talk to them.
>
> > John Nagle
> > SiteTruth
>
> The pyparsing examples page includes a street address parser (http://
> pyparsing.wikispaces.com/space/showimage/streetAddressParser.py) that
> will handle these test cases:
>
> 100 South Street
> 123 Main
> 221B Baker Street
> 10 Downing St
> 1600 Pennsylvania Ave
> 33 1/2 W 42nd St.
> 454 N 38 1/2
> 21A Deer Run Drive
> 256K Memory Lane
> 12-1/2 Lincoln
> 23N W Loop South
> 23 N W Loop South
> 25 Main St
> 2500 14th St
> 12 Bennet Pkwy
> Pearl St
> Bennet Rd and Main St
> 19th St
>
> -- Paul

Here are the results from parsing 3120 De la Cruz Boulevard:

['3120', 'De la Cruz', 'Boulevard']
- name: De la Cruz
- number: 3120
- street: ['3120', 'De la Cruz', 'Boulevard']
  - name: De la Cruz
  - number: 3120
  - type: Boulevard
- type: Boulevard

-- Paul

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


Re: matching a street address with regular expressions

2007-10-12 Thread Grant Edwards
On 2007-10-12, Paul McGuire <[EMAIL PROTECTED]> wrote:

> If you've got an re that can handle everything from "123 Main" to
> "221B Baker Street" to "Hollywood and Vine" to "Lot 123, Hundred of
> Foughbarre", now THAT would be something.

Don't forget street addresses like:

  The Low Cowsheds

  Green Cottage

  etc.

AFAICT, there are still a lot of places in England that don't
even use a number, street-name tuple.  Just a building name
andn a town.
  
-- 
Grant Edwards   grante Yow! Are you mentally here
  at   at Pizza Hut??
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw_input() and utf-8 formatted chars

2007-10-12 Thread kyosohma
On Oct 12, 1:53 pm, 7stud <[EMAIL PROTECTED]> wrote:
> s = 'A\xcc\x88'   #capital A with umlaut
> print s   #displays capital A with umlaut
>
> s = raw_input('Enter: ')   #A\xcc\x88
> print s#displays A\xcc\x88
>
> print len(input)   #9
>
> It looks like every character of the string I enter in utf-8 is being
> interpreted literally as 9 separate characters rather than one
> character.  How do I enter a capital A with an umlaut so that python
> treats it as one character?

I don't know. This works for me:

>>> x = raw_input('Enter: ')
Enter: ä
>>> len(x)
1
>>>

I'm using Python 2.4 with Default Source Encoding set to None on
Windows XP SP2.

Mike

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

Re: Last iteration?

2007-10-12 Thread Carsten Haese
On Fri, 2007-10-12 at 12:58 +0200, Florian Lindner wrote:
> Hello,
> can I determine somehow if the iteration on a list of values is the last
> iteration?
> 
> Example:
> 
> for i in [1, 2, 3]:
>if last_iteration:
>   print i*i
>else:
>   print i
> 
> that would print
> 
> 1
> 2
> 9

Here's another solution:

mylist = [1,2,3]
for j,i in reversed(list(enumerate(reversed(mylist:
  if j==0:
 print i*i
  else:
 print i

;)

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Last iteration?

2007-10-12 Thread Paul Hankin
On Oct 12, 2:18 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Fri, 2007-10-12 at 12:58 +0200, Florian Lindner wrote:
> > Hello,
> > can I determine somehow if the iteration on a list of values is the last
> > iteration?
>
> > Example:
>
> > for i in [1, 2, 3]:
> >if last_iteration:
> >   print i*i
> >else:
> >   print i
>
> > that would print
>
> > 1
> > 2
> > 9
>
> Here's another solution:
>
> mylist = [1,2,3]
> for j,i in reversed(list(enumerate(reversed(mylist:
>   if j==0:
>  print i*i
>   else:
>  print i

Nice! A more 'readable' version is:

mylist = [1,2,3]
for not_last, i in reversed(list(enumerate(reversed(mylist:
  if not_last:
 print i
  else:
 print i * i

--
Paul Hankin

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


Traceback (most recent call last): PROBLEM

2007-10-12 Thread smarras
Hello everyone, I keep obtaining an error message whenever I execute some
very simple routines; the error that follows says that I am calling
certain functions that, in reality, I am not calling from any of the
routines that I wrote:

error:

> python fwrite_mat.py

  0, 0, 0, 0 ,  0, 1, 2, 3 ,  0, 2, 4, 6
Traceback (most recent call last):
  File "fwrite_mat.py", line 7, in 
from xlrd import *
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/xlrd/__init__.py",
line 256, in 
from timemachine import *
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/xlrd/timemachine.py",
line 21, in 
from array import array as array_array
ImportError: cannot import name array

In these lines that I pasted, for example the "array-looking" string has
nothing to do with my function, nor the import name "timemachine" or the
import name "array".

Can anyone help me understand why python is looking such libraries, and
why it keeps in memory an array that I am not using?

Here also the simple routine I wrote:

import os, sys
import xlrd
from numpy import *
from Numeric import *
from matplotlib import *

book = xlrd.open_workbook("/Users/simone/Desktop/prova.xls")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols
for i in range(sh.nrows):
for j in range(sh.ncols):
print sh.row(i)
print sh.cell_value(i, j)

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


Moving objects in Tkinter

2007-10-12 Thread Evjen Halverson
  I have tried to make a Tkinter program make a rectangle move down the window, 
but did not succeed. All it does is make a rectangle trail.
   What am I doing wrong?
   
 from Tkinter import*
 root = Tk()
 RectangleColor='orange'
 Background=tk_rgb = "#%02x%02x%02x" % (100, 255, 100)
 root.geometry('1000x800+0+0')
 root.title("Moving Object Test")
 w = Canvas (root,width=1000,height=800,bg=Background)
 w.grid()
 import time
 t1=time.time()
 t2=t1
 ti=t2-t1
 x=100
 y=0
 a=0
 rect=Canvas.create_rectangle(w,x,y,200,100,fill=RectangleColor)
  
   
   
 def CLS():
 cls=Canvas.create_rectangle(w,0,0,1000,800,fill=Background)
 while ti<10:
 t2=time.time()
 ti=t2-t1
 y=y+10
 Canvas.create_rectangle(w,x,y,200,100,fill=RectangleColor)
   
 st1=time.time()
 st2=st1
 subti=st2-st1
 root.mainloop()
 time.sleep(100)
   
 while subti<1:
 st2=time.time()
 subti=st2-st1
 a=a+1
 CLS()
   
 #rect=Canvas.create_rectangle(w,x,y,1000,800,fill=RectangleColor)
   
   
   
 root.mainloop()
   
 quit()
   
-
Building a website is a piece of cake. 
Yahoo! Small Business gives you all the tools to get online.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: matching a street address with regular expressions

2007-10-12 Thread Grant Edwards
On 2007-10-12, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-10-12, Paul McGuire <[EMAIL PROTECTED]> wrote:
>
>> If you've got an re that can handle everything from "123 Main" to
>> "221B Baker Street" to "Hollywood and Vine" to "Lot 123, Hundred of
>> Foughbarre", now THAT would be something.
>
> Don't forget street addresses like:
>
>   The Low Cowsheds

Honest, that (along with the town, county, and postal code) was
the mailing address for one of the engineering groups at a
company I used to work for.

-- 
Grant Edwards   grante Yow! There's enough money
  at   here to buy 5000 cans of
   visi.comNoodle-Roni!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-12 Thread David Kastrup
George Neuner  writes:

> Yes and no.  General continuations, as you describe, are not the
> only form continuations take.  Nor are they the most common form
> used.  The most common continuations are function calls and returns.
> Upward one-shot continuations (exceptions or non-local returns) are
> the next most common form used, even in Scheme.
>
> Upward continuations can be stack implemented.  On many CPU's, using
> the hardware stack (where possible) is faster than using heap
> allocated structures.  For performance, some Scheme compilers go to
> great lengths to identify upward continuations and nested functions
> that can be stack implemented.

There is a Scheme implementation (I keep forgetting the name) which
actually does both: it actually uses the call stack but never returns,
and the garbage collection includes the stack.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross-platform GUI development

2007-10-12 Thread Kevin Walzer
[EMAIL PROTECTED] wrote:

> 
> My question is if Tix is old hat, what is the GUI toolkit I *should*
> be using for quick-n-dirty cross platform GUI development? I guess
> this is tangentially related to:

What widgets are you using in Tix? They may be available in BWidgets, 
Tablelist, or other script-level Tk exetensions (i.e. they do not 
require compiliaton). Wrappers for many of these are available at the 
Tkinter wiki (http://tkinter.unpythonic.net/wiki/FrontPage)

--Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Declarative properties

2007-10-12 Thread Dan Stromberg
On Fri, 12 Oct 2007 09:42:28 +0200, Bruno Desthuilliers wrote:

>>> So what?  Otherwise you carry *always* the baggage of a public
>>> property and a private attribute whether you need this or not.  At
>>> least for me it would be unnecessary in most cases.
>> 
>> That "baggage" of carrying around "unneeded" methods is something the
>> computer carries for you - IE, no big deal in 99.99% of all cases.
> 
> 1/ Accessing the value of a property is not free. Accessing a plain
> attribute is much cheaper.

Python's current performance characteristics have no bearing on what is
good software engineering practice in general, and little bearing on what
is good software engineering practice in python.  Even from a
strictly "what's good for python" perspective, if we limit our view of
"good SE practice" to what python can express well right now (and IMO,
python can express this fine, but you seem to be arguing it cannot),
that needlessly limits python's evolution.

I'm not omniscient, and neither is anyone else; when one initially codes a
class, one doesn't know to what purposes it will need to be bent in the
future; using accessor methods instead of exposed attributes is
significantly more flexible for the future of your class.  In fact, I may
even go so far as to say that public attributes would be good to leave out
of future languages that don't have a lot of backward compatibility
baggage.

It may not be traditional to use accessor methods in python.  It may even
be a more expensive operation.  But neither of these make accessor methods
a bad idea in the abstract.

> 2/ cluttering the class's namespace with useless names and the source
> code with useless code is definitively not a good thing.

Adding two clear and flexible methods and eliminating one clear and
inflexible attribute is not namespace clutter.  It's paydirt.

The performance expense in the vast majority of cases is tiny compared to
the human expense of going back and fixing a design bug if anything
significant has been hinging on your exposed implementation detail.

Unless, that is, you don't think your code is important enough to be
stretched to another, previously unforeseen purpose someday.  If you're
coding for a hobby, and enjoy coding for the sake of coding irrespective
of how long it takes, rather than as a means to a valuable end, maybe
needlessly exposing attributes is a Really Good Idea.

My implementation may or may not be lacking (feel free to improve it - in
fact, please do!), but that's irrelevant to the heart of the matter, which
is "what you didn't think to plan for now most definitely can hurt you
later".

If you have a program that needs to perform well, you're much better off
coding your classes the best way you know how from a Software Engineering
perspective, and using pysco or shedskin or pypy or similar to
improve performance.  If that's not enough, then you're better off
profiling the program, and only after that should you recode the critical
portions into something like pyrex or a C extension module, or -maybe-
some python "tricks".  I'd argue that trick-free C or C++ is normally
better than python with tricks from a performance vantage -and- from an SE
viewpoint.

Little hackish tricks for performance's sake scattered throughout a
program are very wasteful of something more precious than CPU time.


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


raw_input() and utf-8 formatted chars

2007-10-12 Thread 7stud
s = 'A\xcc\x88'   #capital A with umlaut
print s   #displays capital A with umlaut

s = raw_input('Enter: ')   #A\xcc\x88
print s#displays A\xcc\x88

print len(input)   #9


It looks like every character of the string I enter in utf-8 is being
interpreted literally as 9 separate characters rather than one
character.  How do I enter a capital A with an umlaut so that python
treats it as one character?

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


Re: Convert obejct string repr to actual object

2007-10-12 Thread Carsten Haese
On Fri, 2007-10-12 at 17:41 +0100, English, Mark wrote:
> > From: Tor Erik Sønvisen
> > Date: October 8th 2007
> > I've tried locating some code that can recreate an object from
> > it's string representation... 
> On a related note I've wondered about this:
> >>> class Foo(object): pass
> >>> f = Foo()
> >>> s = repr(f)
> >>> s
> '<__main__.Foo object at 0x007CBAB0>'
> 
> So how do I get f back from s ?
> Obviously this is open to abuse. I just wondered if a mechanism existed short 
> of writing
> a C-extension which parses that string, casts the hex number to a PyObject *, 
> INCREFs it,
> and gives it back...

I can't help but wonder, do you often find yourself having to locate an
object from its hexadecimal address?

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Problem with MySQL cursor

2007-10-12 Thread Florian Lindner
Carsten Haese wrote:

> On Fri, 2007-10-12 at 13:12 +0200, Florian Lindner wrote:
>> Carsten Haese wrote:
>> > sql = "INSERT INTO "+DOMAIN_TABLE+"("+DOMAIN_FIELD+") VALUES (%s)"
>> > executeSQL(sql, domainname)
>> 
>> Ok, I understand it and now it works, but why is limitation? Why can't I
>> just the string interpolation in any playes and the cursor function
>> escapes any strings so that they can't do harm to my query?
> 
[...]

Thanks for your good explanation!

Florian

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


test if email

2007-10-12 Thread Florian Lindner
Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?

Thanks,

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


Re: raw_input() and utf-8 formatted chars

2007-10-12 Thread 7stud
On Oct 12, 1:18 pm, [EMAIL PROTECTED] wrote:
> On Oct 12, 1:53 pm, 7stud <[EMAIL PROTECTED]> wrote:
>
> > s = 'A\xcc\x88'   #capital A with umlaut
> > print s   #displays capital A with umlaut
>
> > s = raw_input('Enter: ')   #A\xcc\x88
> > print s#displays A\xcc\x88
>
> > print len(input)   #9
>
> > It looks like every character of the string I enter in utf-8 is being
> > interpreted literally as 9 separate characters rather than one
> > character.  How do I enter a capital A with an umlaut so that python
> > treats it as one character?
>
> I don't know. This works for me:
>
>
>
> >>> x = raw_input('Enter: ')
> Enter: ä
> >>> len(x)
> 1
>
> I'm using Python 2.4 with Default Source Encoding set to None on
> Windows XP SP2.
>
> Mike

Yeah, but what happens when you enter A\xcc\x88?  And what is it that
your keyboard enters to produce an 'a' with an umlaut?

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

Re: Declarative properties

2007-10-12 Thread Dan Stromberg
On Thu, 11 Oct 2007 18:42:16 +, Marc 'BlackJack' Rintsch wrote:


>> The "baggage" of possibly fixing (AKA "generalizing") how your attributes
>> are accessed is something you lug around while your deadline looms.
> 
> Sorry I don't get it.  If I want to customize the access to a "normal"
> attribute I simply turn it into a property.

You're right, properties are an intersting language feature.  I wasn't
aware of them until today.

I'm not sure I believe they are better than disallowing public attributes
and requiring setters and getters, but they do appear to address the same
issue: the needless change in API when your internal representation
needs to change.

Apologies.


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


Re: test if email

2007-10-12 Thread kyosohma
On Oct 12, 2:55 pm, Florian Lindner <[EMAIL PROTECTED]> wrote:
> Hello,
> is there a function in the Python stdlib to test if a string is a valid
> email address?
>
> Thanks,
>
> florian

What do you mean? If you're just testing the construction of the email
address string, then it's pretty easy. If you want to know if the
email address is live and works, the only way to reliably find that
out is to send a test email there to see if it goes through or
bounces.

Here's an interesting article on the topic, which is completely non-
Python related:

http://www.oreillynet.com/onlamp/blog/2002/12/how_to_validate_an_email_addre.html

Mike

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


Re: Python module for making Quicktime or mpeg movies from images

2007-10-12 Thread jeremito
On Oct 12, 10:37 am, TYR <[EMAIL PROTECTED]> wrote:
> On Oct 11, 4:17 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
>
>
>
> > jeremito wrote:
> > > On Oct 11, 10:43 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > >> jeremito wrote:
> > >>> My Python script makes a bunch of images that I want to use as frames
> > >>> in a movie.  I've tried searching for a module that will take these
> > >>> images and put them together in a Quicktime or mpeg movie, but haven't
> > >>> found anything.  My images are currently pdfs, but I could make them
> > >>> into just about anything if needed.
> > >>> Is there a module, or example of how to do this?
> > >>http://pymedia.org/
>
> > >> Diez
>
> > > That initially looked promising, but it looks like nobody is working
> > > on it anymore and it doesn't compile on Mac.  (I should have mentioned
> > > I am using a Mac.)  Any other suggestions?
>
> > Not really a Python module but... run them
> > through mencoder? (Haven't tried it but it
> > seems to be saying it's possible).
>
> >http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html#EXAMPLES%20OF%20ME...
>
> > TJG
>
> NodeBox; nodebox.org
>
> GUI application that creates either PDFs or Quicktime vids from python
> code. Unix/Linux/MacOS.

I actually found NodeBox in my googling.  This seems to be a stand
alone application.  I need to be able to convert my images to a movie
from my code I wrote myself.

Thanks,
Jeremy

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


Re: Moving objects in Tkinter

2007-10-12 Thread Matt McCredie
On 10/12/07, Evjen Halverson <[EMAIL PROTECTED]> wrote:
>   I have tried to make a Tkinter program make a rectangle move down the
> window, but did not succeed. All it does is make a rectangle trail.
>What am I doing wrong?
>
>  from Tkinter import*
>  root = Tk()
>  RectangleColor='orange'
>  Background=tk_rgb = "#%02x%02x%02x" % (100, 255, 100)
>  root.geometry('1000x800+0+0')
>  root.title("Moving Object Test")
>  w = Canvas (root,width=1000,height=800,bg=Background)
>  w.grid()
>  import time
>  t1=time.time()
>  t2=t1
>  ti=t2-t1
>  x=100
>  y=0
>  a=0
> rect=Canvas.create_rectangle(w,x,y,200,100,fill=RectangleColor)
>
>
>
>  def CLS():
>
> cls=Canvas.create_rectangle(w,0,0,1000,800,fill=Background)
>  while ti<10:
>  t2=time.time()
>  ti=t2-t1
>  y=y+10
>
> Canvas.create_rectangle(w,x,y,200,100,fill=RectangleColor)
>
>  st1=time.time()
>  st2=st1
>  subti=st2-st1
>  root.mainloop()
>  time.sleep(100)
>
>  while subti<1:
>  st2=time.time()
>  subti=st2-st1
>  a=a+1
>  CLS()
>
>  #
> rect=Canvas.create_rectangle(w,x,y,1000,800,fill=RectangleColor)
>
>
>
>  root.mainloop()
>
>  quit()

Tkinter canvas works a little different than say, openGL or pygame.
You don't have to draw the rectangle over and over for each frame.
Every time you call create_rectangle you are creating another
rectangle. Another thing to note is that Tkinter has a built in
scheduler. You don't need to use time. The way you are calling Canvas
looks a little funny to me also.

Anyway, here is a simple example:

[code]
import Tkinter as tk

rectanglecolor = 'orange'
background = tk_rgb = "#%02x%02x%02x" % (100, 255, 100)
disty = 6

root = tk.Tk()
root.geometry('1000x800+0+0')
root.title("Moving Object Test")

can = tk.Canvas (root,width=1000,height=800,bg=background)
can.grid()

# note that rect is actually just an integer that is used to identify
that shape in the
# context of the canvas that it was created within.
rect = can.create_rectangle(400,0,600,200,fill=rectanglecolor)

for i in range(100):
# move the rectangle 0 in the x direction and disty in the y direction.
can.move(rect, 0, disty)
root.update() # update the display
root.after(30) # wait 30 ms

root.mainloop() # this just keeps the window open
[/code]

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


Re: Declarative properties

2007-10-12 Thread George Sakkis
On Oct 12, 2:55 pm, Dan Stromberg <[EMAIL PROTECTED]> wrote:

> If you have a program that needs to perform well, you're much better off
> coding your classes the best way you know how from a Software Engineering
> perspective, and using pysco or shedskin or pypy or similar to
> improve performance.

"best way you know how from a Software Engineering" != "best way to do
it in less flexible languages that will go unnamed, such as Java"

You seem to conflate these two.

George

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


Re: test if email

2007-10-12 Thread Tim Williams
On 12/10/2007, brad <[EMAIL PROTECTED]> wrote:
> Florian Lindner wrote:
> > Hello,
> > is there a function in the Python stdlib to test if a string is a valid
> > email address?
>
> Nope, most any string with an @ in it could be a valid email addy. Send
> a message to the addy, if it doesn't bounce, then it's valid.

Invalid email doesn't always bounce, ( or the bounces may not always reach you )

:)

-- 

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


Re: test if email

2007-10-12 Thread Tim Williams
On 12/10/2007, Florian Lindner <[EMAIL PROTECTED]> wrote:
> Hello,
> is there a function in the Python stdlib to test if a string is a valid
> email address?
>

You mean a valid SMTP email address?

In reality, there isn't a way of doing this.  But a good rule of thumb
is if it hasn't got at least one '@' symbol with at least one '.' to
the right of the right-most '@' symbol then it isn't valid for
internet transmission.

If you meant "test if a string is an existing email address",  then
again there is no foolproof way of testing.   Valid email addresses
can bounce for a variety of reasons, and invalid email addresses don't
always bounce.  Using an SMTP dialogue with the server without sending
an email can have the same bounce/non-bounce (actually, accept/refuse)
results.

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


Re: test if email

2007-10-12 Thread brad
Florian Lindner wrote:
> Hello,
> is there a function in the Python stdlib to test if a string is a valid
> email address?

Nope, most any string with an @ in it could be a valid email addy. Send 
a message to the addy, if it doesn't bounce, then it's valid.
-- 
http://mail.python.org/mailman/listinfo/python-list


stderr is a lame hack?

2007-10-12 Thread Erik Jones
So, I was just taking a look at doctest.py and saw this:

Then running the module as a script will cause the examples in the
docstrings to get executed and verified:

python M.py

This won't display anything unless an example fails, in which case the
failing example(s) and the cause(s) of the failure(s) are printed to  
stdout
(why not stderr? because stderr is a lame hack <0.2 wink>), and the  
final
line of output is "Test failed.".


What does he mean by stderr being a lame hack?


Erik Jones

Software Developer | Emma®
[EMAIL PROTECTED]
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com


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


Re: problem with wxPanel derivation class ~ thanks

2007-10-12 Thread Chris Mellon
On 10/12/07, <"@bag.python.org <"none> wrote:
> none wrote:
> > wxGlade created a simple Frame with a panel a sizer and 3 wxControls ,



> Thanks All,
> I didn't make the super() call (java terminology)
> to the base class.
>
> this is the only python group (en) on giganews, my first search
>  no wx or qt.
> gmane.com.python.wxpython is not found
> gmane.org came up and crashed firefox 3 times searching for python.
> I'll try the wxpython forrum for x stuff, but you spoiled me with prompt
> and accurate responses.
>


The wxpython mailing list is wxpython-users. You can subscribe at
wxPython.org. It's not mirrored to an actual newsgroup, although I'm
sure gmane has it. You'll find wxpython-users to be at least as prompt
and accurate, at least with regard to wxPython-specific questions.
-- 
http://mail.python.org/mailman/listinfo/python-list


[Pyro] ConnectionClosedError

2007-10-12 Thread George Sakkis
Didn't have much luck with this in the Pyro mailing list so I am
trying here, just in case. I have a Pyro server running as a daemon
process and occasionally (typically after several hours or days of
uptime) a ConnectionClosedError is raised when a client calls a remote
method. Both client and server run on the same machine, so I don't
think it's an actual network connectivity issue. The problem is that
once this happens, it is persistent; retrying to call a few times does
not work although the server process is still alive. The current
"solution" is to manually kill the server and restart it but obviously
this is not ideal. Is there a way to either prevent or at least
recover automatically the server when it hangs ?

George

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


Re: Declarative properties

2007-10-12 Thread Chris Mellon
On 10/12/07, Dan Stromberg <[EMAIL PROTECTED]> wrote:
> On Fri, 12 Oct 2007 09:42:28 +0200, Bruno Desthuilliers wrote:
>
> >>> So what?  Otherwise you carry *always* the baggage of a public
> >>> property and a private attribute whether you need this or not.  At
> >>> least for me it would be unnecessary in most cases.
> >>
> >> That "baggage" of carrying around "unneeded" methods is something the
> >> computer carries for you - IE, no big deal in 99.99% of all cases.
> >
> > 1/ Accessing the value of a property is not free. Accessing a plain
> > attribute is much cheaper.
>
> Python's current performance characteristics have no bearing on what is
> good software engineering practice in general, and little bearing on what
> is good software engineering practice in python.  Even from a
> strictly "what's good for python" perspective, if we limit our view of
> "good SE practice" to what python can express well right now (and IMO,
> python can express this fine, but you seem to be arguing it cannot),
> that needlessly limits python's evolution.
>
> I'm not omniscient, and neither is anyone else; when one initially codes a
> class, one doesn't know to what purposes it will need to be bent in the
> future; using accessor methods instead of exposed attributes is
> significantly more flexible for the future of your class.

This is simply not true in Python, and anyone who thinks it is hasn't
the slightest understanding of the consequences of dynamic vs static
lookup. The best practice (in C++, which Java inherited) of using
accessors is because changing a public attribute to a property  broke
your interface, and all the clients of your code needed to be altered.
Later languages, like C#, introduced syntax support for properties,
which improved the situation such that clients didn't need to be
re-written, but only recompiled.

Python, however, uses truly dynamic attribute lookup and there is
*zero* cost to clients in a change from a public attribute to a
property.

Writing accessors in a language that doesn't have the pressures that
introduced them is cargo cult programming, not Software Engineering.

>In fact, I may
> even go so far as to say that public attributes would be good to leave out
> of future languages that don't have a lot of backward compatibility
> baggage.
>

>From a reasonable point of view, Python doesn't have public
attributes, it just has things that syntactically look like them.
Discuss!

> It may not be traditional to use accessor methods in python.  It may even
> be a more expensive operation.  But neither of these make accessor methods
> a bad idea in the abstract.
>

Of course not, that's why Python supports properties. What's being
called the anti-pattern here is the creation-by-default of trivial
accessors.

> > 2/ cluttering the class's namespace with useless names and the source
> > code with useless code is definitively not a good thing.
>
> Adding two clear and flexible methods and eliminating one clear and
> inflexible attribute is not namespace clutter.  It's paydirt.
>

No, you kept the attribute and also added (at least) 2 methods.

> The performance expense in the vast majority of cases is tiny compared to
> the human expense of going back and fixing a design bug if anything
> significant has been hinging on your exposed implementation detail.
>

You still don't know what language you're writing in, do you? There is
zero additional cost associated with changing a public attribute to a
property.

> Unless, that is, you don't think your code is important enough to be
> stretched to another, previously unforeseen purpose someday.  If you're
> coding for a hobby, and enjoy coding for the sake of coding irrespective
> of how long it takes, rather than as a means to a valuable end, maybe
> needlessly exposing attributes is a Really Good Idea.
>

Ah, the old "my code is way more important than yours, so what I do is
right" approach. You hang out in the Java world a lot, don't you?

> My implementation may or may not be lacking (feel free to improve it - in
> fact, please do!), but that's irrelevant to the heart of the matter, which
> is "what you didn't think to plan for now most definitely can hurt you
> later".
>

Your implementation is, quite possibly, the worst possible
implementation of automatic properties in Python, both in terms of
readability and code size (and thus maintenance), as well as
performance and flexibility. The fact that you consider it, even for a
moment, to be better than writing accessors when and if you need them
(and not writing them otherwise) belies a dreadful lack of self
awareness.

> If you have a program that needs to perform well, you're much better off
> coding your classes the best way you know how from a Software Engineering
> perspective, and using pysco or shedskin or pypy or similar to
> improve performance.  If that's not enough, then you're better off
> profiling the program, and only after that should you recode the critical
> portions into som

Re: raw_input() and utf-8 formatted chars

2007-10-12 Thread Marc 'BlackJack' Rintsch
On Fri, 12 Oct 2007 13:18:35 -0700, 7stud wrote:

> On Oct 12, 1:18 pm, [EMAIL PROTECTED] wrote:
>> On Oct 12, 1:53 pm, 7stud <[EMAIL PROTECTED]> wrote:
>>
>> > s = 'A\xcc\x88'   #capital A with umlaut
>> > print s   #displays capital A with umlaut
>>
>> > s = raw_input('Enter: ')   #A\xcc\x88
>> > print s#displays A\xcc\x88
>>
>> > print len(input)   #9
>>
>> > It looks like every character of the string I enter in utf-8 is being
>> > interpreted literally as 9 separate characters rather than one
>> > character.  How do I enter a capital A with an umlaut so that python
>> > treats it as one character?
>>
>> I don't know. This works for me:
>>
>>
>>
>> >>> x = raw_input('Enter: ')
>> Enter: 
>> >>> len(x)
>> 1
>>
>> I'm using Python 2.4 with Default Source Encoding set to None on
>> Windows XP SP2.
>>
>> Mike
> 
> Yeah, but what happens when you enter A\xcc\x88?

You mean literally!?  Then of course I get A\xcc\x88 because that's what I
entered.  In string literals in source code the backslash has a special
meaning but `raw_input()` does not "interpret" the input in any way.

> And what is it that your keyboard enters to produce an 'a' with an umlaut?

*I* just hit the ä key.  The one right next to the ö key.  ;-)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: test if email

2007-10-12 Thread Grant Edwards
On 2007-10-12, brad <[EMAIL PROTECTED]> wrote:
> Florian Lindner wrote:
>> Hello,
>> is there a function in the Python stdlib to test if a string is a valid
>> email address?
>
> Nope, most any string with an @ in it could be a valid email addy. Send 
> a message to the addy, if it doesn't bounce, then it's valid.

Just because it doesn't bounce, that doesn't mean it's "valid".
Some servers don't bounce e-mail to invalid addresses, they
just drop them into the bit bucket in an effort to prevent
spammers from harvesting valid e-mail addresses using
dictionary attacks.

If you send an e-mail to an address and you get a response,
then it's valid.

-- 
Grant Edwards   grante Yow! BARRY ... That was
  at   the most HEART-WARMING
   visi.comrendition of "I DID IT MY
   WAY" I've ever heard!!
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >