ANN: pyftpdlib 0.1.1

2007-03-07 Thread billiejoex
Changed in version 0.1.1
==

* port selection on PASV command has been randomized (this to prevent
a remote user
   to know how many data connections are in progress on the server).
* fixed bug in demo/unix_ftpd.py script.
* ftpd automatically re-use address if current system is unix.
* license changed into a MIT style one.


About
=

pyftpdlib is an high-level FTP server library based on asyncore/
asychat frameworks.
pyftpdlib is actually the most complete RFC959 FTP server
implementation available for Python programming language.


Requirements
==

Python 2.2 or higher


Bug reports / Contacts


billiejoex -_[AT]_- gmail (dot) com

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: pinder 0.5.0

2007-03-07 Thread Lawrence Oluyede

Pinder is a straightforward API to interface with Campfire http://
www.campfirenow.com, the web chat application from 37Signals.

Pinder allows you to create rooms, delete them, speak from a remote
client and more. For example:

 room = campfire.find_room_by_name('Jonz Room')
 print room.users()
set([u'Alice'])

or

 print campfire.users()
set([u'Alice', u'Bob'])

which gets the list of the users talking in each room of the
subdomain.

 room.speak(Foobar)

will send the message to the chat room so you can speak too.

There's more like creating and deleting rooms, toggling guest access,
locking the room etc.

See the usage documentation http://dev.oluyede.org/pinder/doc.html
and the API documentation http://dev.oluyede.org/pinder/api/ for
details.


You can install the latest release with:

$ easy_install pinder

or

download from here: http://dev.oluyede.org/download/pinder/

This is the first public release.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Any module to parse httpd.conf?

2007-03-07 Thread Ger Flanagan

On 6 Mar 2007 02:03:33 -0800, Gerard Flanagan [EMAIL PROTECTED] wrote: 
Hello,

Does anyone know of an existing module to parse httpd.conf files?

Thanks.

Jeff McNeil [EMAIL PROTECTED] wrote: I looked at 
http://www.python.org/pypi/httpdrun not so long ago, itmight be able to 
do what you want. I think it was a bit hard to read.Remember that with 
Apache you (may) also need to worry aboutconfiguration merges and 
whatnot (Directory, VirtualHost, .htaccess, and so on...).  

 What specifically do you want to do? There are a lot of ways to do a  lot of 
 things with Apache.  If you're looking to create virtual hosts, take a look 
 at mod_vhost_alias or some RewriteRule magic.  You're  configuration could 
 be pretty simplified and reduced to updating a gdbm  file or creating a 
 directory? 

Jeff



 Thanks Jeff,

At the minute I'm creating a httpd.conf from a template, but at some point the 
procedure will be completely automated and I may need to merge a generated 
httpd.conf with an existing one. (This is IHS but I'm told it's identical to 
Apache as far as httpd.conf is concerned). I don't know where gdbm fits in but 
I'll look into it.

Thanks for the reply.

Gerard


-
 New Yahoo! Mail is the ultimate force in competitive emailing. Find out more 
at the Yahoo! Mail Championships. Plus: play games and win prizes.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to check whether file is open or not

2007-03-07 Thread Diez B. Roggisch
Ros wrote:

 There are 10 files in the folder. I wish to process all the files one
 by one. But if the files are open or some processing is going on them
 then I do not want to disturb that process. In that case I would
 ignore processing that particular file and move to next file.
 
 How can I check whether the file is open or not?
 
 I tried os.stat and os.access but I am not getting the expected
 results.
 Also I checked in IO exceptions, IO error handler doesnt raise any
 error if the file is open.
 There are some options to check but they are platform dependent (works
 only with unix)

You can't do that, at least not in a platform agnostic way, and usually not
without cooperation of the file-modifying processes.

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


Re: How to check whether file is open or not

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 02:28:33 -0300, Ros [EMAIL PROTECTED] escribió:

 There are 10 files in the folder. I wish to process all the files one
 by one. But if the files are open or some processing is going on them
 then I do not want to disturb that process. In that case I would
 ignore processing that particular file and move to next file.

 How can I check whether the file is open or not?

 I tried os.stat and os.access but I am not getting the expected
 results.
 Also I checked in IO exceptions, IO error handler doesnt raise any
 error if the file is open.
 There are some options to check but they are platform dependent (works
 only with unix)

This works only on Windows:
You can use the _sopen function (from the C runtime library), which takes  
additional flags for specifying file sharing. See
http://msdn2.microsoft.com/en-us/library/aa273350(VS.60).aspx
_sopen with _SH_DENYRW will fail if the file is already open by the same  
or another process. Try to open the file using this flag: if _sopen  
succeeds (does not return -1) the file was not already open (remember to  
close it as soon as possible!); if _sopen fails (returns -1) it was  
already open.

Using the ctypes module (included with Python 2.5; you can download and  
install it for previous versions) you can call that function easily:

py from ctypes import *
py crt = cdll.msvcrt
py _sopen = crt._sopen
py _sopen.argtypes = (c_char_p, c_int, c_int, c_int)
py _SH_DENYRW = 0x10 # from share.h
py h = _sopen(C:\\1.txt, 0, _SH_DENYRW, 0)
py h
3
py h2 = _sopen(C:\\1.txt, 0, _SH_DENYRW, 0)
py h2
-1
py _close = crt._close
py _close(h)
0
py h2 = _sopen(C:\\1.txt, 0, _SH_DENYRW, 0)
py h2
3
py _close(h2)
0

Note: You said But if the files are open or some processing is going on  
them then I do not want to disturb that process.. There exist a (small)  
risk of disturbing the other process: if it tries to open the file just  
after you opened it, but before you close it, the operation will fail. It  
is a tiny window, but might happen...

Surely there are other ways - some programs can report all processes  
having a certain file opened, by example, but I don't know how to do that.

-- 
Gabriel Genellina

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


Re: Device Drivers in python(kernel modules)

2007-03-07 Thread Laurent Pointal
John Nagle a écrit :
 Thomas Ploch wrote:
 rishi pathak schrieb:

 I am not much of a kernel programmer , I have a requirement to shift a
 python code to work as a kernel module.
 So I was just wondering whether we can write a kernel module in python.
 A thought is that if we can somehow convert python code into a C object
 code then it can be done.
 Can some one suggest something..anything
 
3.  This is probably a bad idea.  If it doesn't have to go in the
 operating system kernel, it shouldn't go in the kernel.
 
 John Nagle

I agree.

If (under Linux) this is just to provide a driver-like interface (ie.
using file-system objects manipulation), OP may take a look at FUSE
(Filesystem in Userspace - http://fuse.sourceforge.net/) and its Python
binding (http://www.google.fr/search?q=FUSE+%2B+Python).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to check whether file is open or not

2007-03-07 Thread Mattias Nilsson
Ros wrote:
 There are 10 files in the folder. I wish to process all the files one
 by one. But if the files are open or some processing is going on them
 then I do not want to disturb that process. In that case I would
 ignore processing that particular file and move to next file.
 
 How can I check whether the file is open or not?
 
snip

 From what I know: You can't, in a platform independent way.

You'd still be in trouble even if python would let you write something like:

if file_is_open(filename):
 process_file(filename)


There's nothing that says no one will open the file after the 
file_is_open call but before the process_file call. Also, the file might 
be opened during the processing.

If the files to be processed only are written and then closed without 
being reopened or modified, then your situation is a bit simpler.

If you can get the process that creates the files to cooperate, a common 
way to solve this problem is to have a temporary suffix on files while 
they are being created. Once the file is complete, the temporary suffix 
is removed and that signals to other processes that this file is ready 
for processing.





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


distutils: tweaking my ini to use relevant data_files path

2007-03-07 Thread Anastasios Hatzis
I would like to let my setup script know if the user has provided a 
custom path for the data_files of my distribution, e.g. by using the 
--install-data option, so the setup can automagically change a config 
information in my package to the local path applied, instead of using 
some default path I hard-coded into the config information. I could not 
find an appropriate pattern for this, but I'm rather confident that this 
is not too exotic and some of you already use such a pattern. Would be 
great to learn. Thank you in advance.

Following some details. My development version is Python 2.4.4 on 
Windows XP. My project contains a sdk.ini configuration file which is in 
the root package of my tool (by default in site-packages of course). 
This INI has a OSPDIR option for a path to some example *.osp files 
(data_files) coming with the distribution. These *.osp files are some 
work files that should be typically stored in an user's home directory 
or somewhere else, but not in the Python directory.

So, the setup() in my setup.py has (among many other arguments, which I 
don't consier to be important for my task here):

data_files=[('projects', ['projects/foo.osp', 'projects/bar.osp']),

By default this projects directory is going into the Python directory, 
right? At least I could see that in my Python 2.4.4 installation on 
Windows XP:

C:\Python24\projects\

My default config could be:
OSPDIR = os.path.join(sys.prefix, 'projects')

so, my tool should usually know where this directory is on a local machine.

But, as mentioned earlier, it makes much sense to have projects (and 
its contained data files) installed instead to another location, e.g. 
user home or D:\ etc. - of course this should work on any platform with 
Python and distutils.

I already learned, that user's can alter where setup distributes 
specific parts, such as the data_files with the --install-data option, 
see alternate installation 
http://www.python.org/doc/2.4.4/inst/alt-install-windows.html
or custom installation http://www.python.org/doc/2.4.4/inst/search-path.html

I think, this is reasonable for any user. But what do I need to do, to 
provide OSPDIR with this particular --install-data path applied by the 
user? Can I use OptionParser module (as I already do for my tools) in 
the setup.py which checks, if this option is given, and eventually which 
value it has, and somehow putting it dynamically into the OSPDIR variable?

a) Is --install-data the only way for users to customize path to data_files?
b) Am I right to parse --install-data in setup.py and change OSPDIR 
variable on the fly?
c) If yes, how do I add this to my setup.py? It currently has only a 
setup() call with plenty of arguments (no weired stuff, though). Do I 
need to put this verifcation before or after setup() or is there any 
callback or hook to use?

Many thanks for your support,
Anastasios
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: askstring Window to the top under Windows

2007-03-07 Thread iwl
On 7 Mrz., 02:49, jim-on-linux [EMAIL PROTECTED] wrote:
 On Tuesday 06 March 2007 08:13, iwl wrote:

  Hi,

  I tryed askstring to input some text in my
  script, but some ugly empty Window appears with
  the Input-Window behind and all together behind
  my Console showing my script. So all have to
  brought to the top first by the user - very
  unconfortable

 By default
 tk will open a root window.

Is this default changeable befor askstring?

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


Re: audio video streaming communications

2007-03-07 Thread Paul Sijben
Hi Ken,

I am looking for something similar. I can do the communications myself
but need to be able to select a video feed, capture it and also need to
display it through wxPython.

Trawled the web and even tried to hire coders to create it for me. So
far I have been having no luck.

I did learn that fastaudio is a good way to bluescreen a WinXP box ;-)

Have you found something?

Paul

Ken Seehart wrote:
 Hello,
 
 I am looking for a good audio/video conferencing library.  Ideally it
 should work with wxPython (or have some means of making it work there).
 
 So far my main difficulty in my attempt at searching for such a package
 is that there is so much stuff out there on downloading music and videos.
 
 I am not interested in download torrents, etc.  I'm just looking video
 conferencing, and live video broadcasts, etc.
 
 Any recommendations?
 
 Thanks,
 - Ken
 
 

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


finding monitor or screen resolution in Linux with standard python module

2007-03-07 Thread akbar
I googled and searched in archive. All I can find is finding
resolution with Tkinter and pygame. Any idea to find monitor
resolution with standard python module?
I can check from output of: xprop -root
_NET_DESKTOP_GEOMETRY(CARDINAL) . The problem is when you use Beryl or
Xgl, it is not correct anymore because Beryl or Xgl set this value
from amount of workspaces multiplied by monitor or screen resolution.

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


How to build a Windows service using win32?

2007-03-07 Thread Gregor Mosheh
I'm trying to write a Win32 service. The following is straight from Python
Programming on Win32 and it doesn't work. Is that book out of date; is
there a new way to do services? I searched Google for hours trying to find
any other method, and have been beating on this one for 5 more hours.

The present error is:

C:\Testerpython tester.py debug
Debugging service Tester - press Ctrl+C to stop.
Error 0xC004 - Python could not import the service's module

type 'exceptions.ImportError': No module named service


The code is:

import win32serviceutil, win32service, win32event

class Service(win32serviceutil.ServiceFramework):
_svc_name_ = EDMS-to-CG
_svc_display_name_ = EDMS-to-CG Syncer
_svc_description_  = Uploaded the EDMS database to Cartograph

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):
pausetime = 60 * 1000
while True:
stopsignal = win32event.WaitForSingleObject(self.hWaitStop,
pausetime)
if stopsignal == win32event.WAIT_OBJECT_0: break
self.runOneLoop()

def runOneLoop(self):
import servicemanager
servicemanager.LogInfoMsg('Running')

win32serviceutil.HandleCommandLine(Service)


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


Re: Recommended FastCGI module?

2007-03-07 Thread Jon Ribbens
In article [EMAIL PROTECTED], John Nagle wrote:
   The JonPy version:
   http://jonpy.sourceforge.net/fcgi.html
   Last revised in 2004.

I'd recommend my one, but it's just possible I'm not impartial ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to build a Windows service using win32?

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 07:25:56 -0300, Gregor Mosheh [EMAIL PROTECTED]  
escribió:

 I'm trying to write a Win32 service. The following is straight from  
 Python
 Programming on Win32 and it doesn't work. Is that book out of date; is
 there a new way to do services? I searched Google for hours trying to  
 find
 any other method, and have been beating on this one for 5 more hours.

Have you installed the pywin32 package from  
https://sourceforge.net/projects/pywin32/ ?
The code skeleton looks OK to me.

-- 
Gabriel Genellina

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


thread and portability Unix/Linux

2007-03-07 Thread awalter1
Hi,
I have a Python application that runs under HPUX 11.11 (then unix). It
uses threads :
from threading import Thread
# Class Main
class RunComponent(Thread):

My application should run under Linux (red hat 3 ou 4) and I read that
differences exist between the implementation of threads : on HPUX
11.11 there is CMA (ou DCE) threads and on Linux POSIX thread. Do you
think that my Python application should be modified or may be such
differences are hidden by the python interpreter ?
In other terms, do I get some risks on this particular aspect by
porting my application ?
Thanks a lot

PS: If you are aware of other risk of porting, I am interested too.

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


Pb with __del__ and inheritence

2007-03-07 Thread Erwan Adam
Hello all,

Can someone reproduce this bug ... I use :

[EMAIL PROTECTED] /home/adam/Work/Python] python
Python 2.4.3 (#2, Sep 18 2006, 21:07:35)
[GCC 4.1.1 20060724 (prerelease) (4.1.1-3mdk)] on linux2
Type help, copyright, credits or license for more information.
 

First test :

[EMAIL PROTECTED] /home/adam/Work/Python] cat bug_del.py  echo -- 
 python bug_del.py

class XObject(object):

 def __del__(self):
 print XObject.__del__
 return

 pass

class A(XObject):

 def __del__(self):
 print A.__del__
 XObject.__del__(self)
 return

 pass

a = A()
--
A.__del__
XObject.__del__
[EMAIL PROTECTED] /home/adam/Work/Python]

Everything is ok ... now I just replace a = A() by aaa = A():

[EMAIL PROTECTED] /home/adam/Work/Python] cat bug_del.py  echo -- 
 python bug_del.py

class XObject(object):

 def __del__(self):
 print XObject.__del__
 return

 pass

class A(XObject):

 def __del__(self):
 print A.__del__
 XObject.__del__(self)
 return

 pass

aaa = A()
--
A.__del__
Exception exceptions.AttributeError: 'NoneType' object has no attribute 
'__del__' in bound method A.__del__ of __main__.A object at 
0xb7bb124c ignored
[EMAIL PROTECTED] /home/adam/Work/Python]

!!!


Thanks in advance,

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


Re: Pb with __del__ and inheritence

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 07:35:05 -0300, Erwan Adam [EMAIL PROTECTED]  
escribió:

 Can someone reproduce this bug ... I use :
Same on 2.5 Windows.

 class XObject(object):

  def __del__(self):
  print XObject.__del__
  return

  pass

 class A(XObject):

  def __del__(self):
  print A.__del__
  XObject.__del__(self)
  return

  pass

 aaa = A()
 --
 A.__del__
 Exception exceptions.AttributeError: 'NoneType' object has no attribute
 '__del__' in bound method A.__del__ of __main__.A object at
 0xb7bb124c ignored

Print XObject inside A.__del__ and you can see that it is None. That means  
that the XObject reference was set to None *before* aaa was deleted.  
Values inside the module namespace are set to None when it's destroyed (to  
break possible reference cycles, I presume). I can't find any place in the  
docs that guarantees any ordering on the object deletion, so I don't  
consider this a bug. See the big notes on the __del__ method docs.

If you *really* must do some cleanup on A.__del__, you can't trust on  
*any* globals, and you must store a reference to anything needed inside  
__del__

-- 
Gabriel Genellina

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


Re: re-point mod_python - is it possible?

2007-03-07 Thread leland
great explaination - thanks graham!

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


Re: PyQt4: Clickable links in QLabel?

2007-03-07 Thread Tina I
David Boddie wrote:
 On Thursday 01 March 2007 09:00, Tina I wrote:
 
 A short and sweet question: Is it possible to put a clickable link in a
 QLabel that will open in the systems default browser?
 
 Yes.
 
 I tried to put in some HTML but it did (of course?) simply display the
 code instead of a link. I also tried to set openExternalLinks 'true' but
 then pyuic4 bombed.
 
 Well, that shouldn't happen. :-(
 
 Can you send a bug report to the PyQt mailing list (assuming you're
 subscribed to it) with the error message or backtrace that you get
 when this happens?
 
 I see that QLabel does not have a html text format but I'm still hoping
 it's possible. I really need a link on my main window form.
 
 If you enclose the HTML with qt and /qt tags, the HTML should be
 displayed properly. Any other matching tags should also work, so you
 could use p and /p if you want.
 
 Setting the label's openExternalLinks property to True should then
 enable what you want. You can try this out by previewing the form in
 Qt Designer.
 
 David
Thanks David,

This is embarrassing... but my PyQt4 was too old *blush*
I can't believe I didn't think of double checking what version I had 
installed. A swift upgrade and it works like a charm :)

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


Re: *** CANADIAN ANTI-TERROR LAW HAS BEEN STRUCK DOWN BY ITS HONORABLE SUPREME COURT UNANIMOUSLY *** (REPOST)

2007-03-07 Thread Aviroce
On Feb 24, 11:22 am, [EMAIL PROTECTED] wrote:
 Canada anti-terror law is struck downFrom the Associated Press

 February 24, 2007

 OTTAWA - Canada's Supreme Court on Friday unanimously declared it
 unconstitutional to detain foreign terrorism suspects indefinitely
 while the courts review their deportation orders.

 Five Arab Muslim men have been held for years under the security
 certificate program, which the Justice Department has said is a key
 tool in the fight against global terrorism and essential to Canada's
 security.

 The court found that the system violated the Charter of Rights and
 Freedoms, Canada's bill of rights. However, it suspended its ruling
 for a year to give Parliament time to rewrite the part of the
 Immigration and Refugee Protection Act that covers the certificate
 process.

 The security certificates were challenged by three men from Morocco,
 Syria and Algeria - all alleged by the Canadian Security Intelligence
 Service to have ties to terrorist networks.

 The men have spent years in jail while fighting deportation orders.

 They risk being labeled terrorists and sent back to their native
 countries, where they say they could face torture.

 The court said the treatment of the suspects was a violation of their
 rights.

 The overarching principle of fundamental justice that applies here is
 this: Before the state can detain people for significant periods of
 time, it must accord them a fair judicial process, Chief Justice
 Beverley McLachlin wrote in a ruling for all nine justices.

 The secrecy required by the scheme denies the person named in a
 certificate the opportunity to know the case put against him or her,
 and hence to challenge the government's case, she said.

 The challenged law allows sensitive intelligence to be heard behind
 closed doors by a federal judge, with only sketchy summaries given to
 defense attorneys.

 The court said the men and their lawyers should have a right to
 respond to the evidence used against them by intelligence agents.

 Stockwell Day, the minister of public safety, noted that because the
 ruling does not take effect for a year, the certificates would remain
 in place. He said the government would address the court's ruling in
 a timely and decisive fashion.

 Two of the men are out on bail and remain under house arrest. Three
 others are being held in a federal facility in Ontario.

The court said the treatment of the suspects was a
violation of their
rights.


The overarching principle of fundamental justice that applies here
is
this: Before the state can detain people for significant periods of
time, it must accord them a fair judicial process, Chief Justice
Beverley McLachlin wrote in a ruling for all nine justices.


The secrecy required by the scheme denies the person named in a
certificate the opportunity to know the case put against him or her,
and hence to challenge the government's case, she said.


THAT IS CALLED PROTECTING CIVIL RIGHTS.  IN THE UNITED STATES OF
AMERICA, WHERE CIVIL RIGHTS ARE PROTECTED BY LAW, FOREIGN SUSPECTS ARE
NOT PROTECTED BY THE GENEVA CONVENTION.  DR. EVIL, V.P. CHENEY, AND
MINI-ME, PRESIDENT BUSH, OPTED TO MODIFY THE GENEVA CONVENTION TO DENY
FOREIGN SUSPECTS DUE PROCESS DEMANDED BY THE CONVENTION.  THIS MEANS
ENEMIES OF THE UNITED STATES OF AMERICA WILL BE DOING JUST THAT TOO.
WHAT IS GOOD FOR THE GOOSE IS GOOD FOR GANDER.









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


Re: How to build a Windows service using win32?

2007-03-07 Thread Giles Brown
On 7 Mar, 10:25, Gregor Mosheh [EMAIL PROTECTED] wrote:
 I'm trying to write a Win32 service. The following is straight from Python
 Programming on Win32 and it doesn't work. Is that book out of date; is
 there a new way to do services? I searched Google for hours trying to find
 any other method, and have been beating on this one for 5 more hours.

 The present error is:

 C:\Testerpython tester.py debug
 Debugging service Tester - press Ctrl+C to stop.
 Error 0xC004 - Python could not import the service's module

 type 'exceptions.ImportError': No module named service

 The code is:

 import win32serviceutil, win32service, win32event

 class Service(win32serviceutil.ServiceFramework):
 _svc_name_ = EDMS-to-CG
 _svc_display_name_ = EDMS-to-CG Syncer
 _svc_description_  = Uploaded the EDMS database to Cartograph

 def __init__(self, args):
 win32serviceutil.ServiceFramework.__init__(self, args)
 self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

 def SvcStop(self):
 self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
 win32event.SetEvent(self.hWaitStop)

 def SvcDoRun(self):
 pausetime = 60 * 1000
 while True:
 stopsignal = win32event.WaitForSingleObject(self.hWaitStop,
 pausetime)
 if stopsignal == win32event.WAIT_OBJECT_0: break
 self.runOneLoop()

 def runOneLoop(self):
 import servicemanager
 servicemanager.LogInfoMsg('Running')

 win32serviceutil.HandleCommandLine(Service)

Yeah.  You've cleverly decided to simplify the smallest possible
python service by removing the

if __name__ == '__main__':

bit from the script ;)

Try adding it back it.  It worked for me.


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


Re: Python Source Code Beautifier

2007-03-07 Thread Alan Franzoni
Il Tue, 06 Mar 2007 01:55:54 -0300, Gabriel Genellina ha scritto:


 The problem is that other people -not necesarily smarter and more  
 experienced than you- may use those features, and perhaps you have to  
 read, understand and modify some code written by someone else.
 So, you should at least know what a += b means, even if you are not  
 going to use it.

That's sure, and I'm in fact glad to know that by now. I still think it's
risky, BTW. Python is dynamically typed, after all, and there's no 'a
priori' way to know if 'a' is a list or another type, especially another
container type.

If we rely on duck typing, by the way, we may encounter two types quacking
like ducks, flying like ducks, but in fact acting as slightly different
ducks. I should remember as well, when designing a container type that I
want to use in place of a list, to carefully craft an __iadd__ method which
works just like the a list's own __iadd__ method; if I forget, I may
introduce a subtle error. 


-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E 
-- 
http://mail.python.org/mailman/listinfo/python-list


distutils - how to get more flexible configuration

2007-03-07 Thread Jonathan Fine
Hello

I'm writing a package that has cgi-bin scripts, html
files and data files (templates used by cgi scripts).
I find that using distutils in the standard way
does not give me enough flexibilty, even if I use
a setup.cfg.

For example, I want certain data files to go to
markedly different locations.

However, I have come up with a solution, that looks
like it will work for me, and I'd welcome comments.

Here's the MANIFEST file
===
setup.py
myproj_cfg.py
data/wibble.txt
data/wobble.txt
===

And here's the setup.py file I've written
===
from distutils.core import setup
import myproj_cfg

data_files = [
(myproj_cfg.wibble, ['data/wibble.txt']),
(myproj_cfg.wobble, ['data/wobble.txt']),
]

setup(data_files=data_files)
===

The user is asked to create a myproj_cfg.py file,
which might look like
===
wibble = '/wibble'
wobble = '/wobble'
===

And when a distribution is created and installed
we get
===
$ python setup.py install
running install
running build
running install_data
creating /wibble
copying data/wibble.txt - /wibble
creating /wobble
copying data/wobble.txt - /wobble
===

This is an example of what I want.  I'd welcome
your comments.

-- 
Jonathan Fine
The Open University, Milton Keynes, England


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


Re: Why does SocketServer default allow_reuse_address = false?

2007-03-07 Thread Greg Copeland
On Feb 26, 5:54 pm, Joshua J. Kugler [EMAIL PROTECTED] wrote:
 Considering that UNIX Network Programming, Vol 1 (by W. Richard Stevens)
 recommends _All_ TCP servers should specify [SO_REUSEADDR] to allow the
 server to be restarted [if there are clients connected], and that
 self.allow_reuse_address = False makes restarting a server a pain if there
 were connected clients, why does SocketServer default allow_reuse_address
 to False?  It's kind of bemusing to subclass ThreadingTCPServer just to
 change one variable that arguably should have been True in the first place.

 Is there some history to this of which I'm not aware?  Is there a good
 reason for it to default to false?


Yes, it is there for a good reason.  Security is the primary focus of
that option.  If you enable that option, rogue applications can assume
service processing under a number of server failure conditions.  In
other words, start your rogue, crash the primary service, and you now
have a rogue service running.  Even periodic checks will show the
server is still running.  Under a number of other configurations, it
is also possible for the rogue service to simply start and usurp some
types of IP traffic on certain OSs which would otherwise be delivered
to your real server.

Contrary to the book, blindly enabling SO_REUSEADDR is a very, very
bad idea unless you completely understand the problem domain.  I'm
sure Stevens' does understand so it makes for a good choice for him.
On the other hand, most people don't understand the implications so it
makes for a very, very poor move from a security perspective.

Long story short, it is not a bug.  It is a feature.  The proper
default is that of the OS, which is to ensure SO_REUSEADDR is disabled
unless you absoluetely understand what you're buying by enabling it.


Greg

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


Re: askstring Window to the top under Windows

2007-03-07 Thread jim-on-linux
On Wednesday 07 March 2007 05:05, iwl wrote:
 On 7 Mrz., 02:49, jim-on-linux 
[EMAIL PROTECTED] wrote:
  On Tuesday 06 March 2007 08:13, iwl wrote:
   Hi,
  
   I tryed askstring to input some text in my
   script, but some ugly empty Window appears
   with the Input-Window behind and all
   together behind my Console showing my
   script. So all have to brought to the top
   first by the user - very unconfortable
 
  By default
  tk will open a root window.

 Is this default changeable befor askstring?

Here is an example of a simple button that will 
open a tkSimpleDialog box
==

from Tkinter import *
import tkSimpleDialog
from tkSimpleDialog import askfloat

root = Tk()  ## this is the default window
vlab = Button( root, text= 'Click here to Open 
Dialog',
width = 20, height = 2,
bg = 'yellow',
   command =(lambda:   askfloat( 'Entery',
   'Enter credit card number') ) )
vlab.grid()
mainloop()

jim-on-linux
http://www.inqvista.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter menu

2007-03-07 Thread Gigs_
hi i have create widget with menu bar and menus on it.
when i resize my widget to less than menubar is than from
right to left menus on menubar goes to second row.
who to disable that?
all I want is that when i resize my widget to less size, that menus on 
menubar stays on default position .

thanks i advance
-- 
http://mail.python.org/mailman/listinfo/python-list


Generator expression parenthesis mixed with function call ones

2007-03-07 Thread Laurent Pointal
[Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32]

Given the following:

 sum(i for i in range(10))
45
 def f(*args) : print args
...
 f(i for i in range(10))
(generator object at 0x00A79788,)
 def f(a,*args) : print a,ar
...
 f(4,i for i in range(10))
  File stdin, line 1
SyntaxError: invalid syntax


Why does Python allow generator expression parenthesis to be mixed with
function call parenthesis when there is only one parameter ?

IMHO this should be forbidden, usage must not be different when there is
only one parameter and when there are more parameters.
User should all times explicitly use () for a generator expression and
[] for a list comprehension expression.


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


Re: finding monitor or screen resolution in Linux with standard python module

2007-03-07 Thread José Antonio Salazar Montenegro
I'm using Beryl too, and xwininfo -root gives te correct resolution.

akbar wrote:
 I googled and searched in archive. All I can find is finding
 resolution with Tkinter and pygame. Any idea to find monitor
 resolution with standard python module?
 I can check from output of: xprop -root
 _NET_DESKTOP_GEOMETRY(CARDINAL) . The problem is when you use Beryl or
 Xgl, it is not correct anymore because Beryl or Xgl set this value
 from amount of workspaces multiplied by monitor or screen resolution.

   

NOTA: La informacion de este correo es de propiedad exclusiva y confidencial. 
Este mensaje es solo para el destinatario indicado, si usted no lo es, 
destruyalo de inmediato. Ninguna informacion aqui contenida debe ser entendida 
como dada o avalada por MADISA, sus subsidiarias o sus empleados, salvo cuando 
ello expresamente se indique. Es responsabilidad de quien recibe este correo de 
asegurarse que este libre de virus, por lo tanto ni MADISA, sus subsidiarias ni 
sus empleados aceptan responsabilidad alguna.

NOTE: The information in this email is proprietary and confidential. This 
message is for the designated recipient only, if you are not the intended 
recipient, you should destroy it immediately. Any information in this message 
shall not be understood as given or endorsed by MADISA, its subsidiaries or 
their employees, unless expressly so stated. It is the responsibility of the 
recipient to ensure that this email is virus free, therefore neither MADISA, 
its subsidiaries nor their employees accept any responsibility.

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


Re: Generator expression parenthesis mixed with function call ones

2007-03-07 Thread Facundo Batista
Laurent Pointal wrote:


 f(4,i for i in range(10))
   File stdin, line 1
 SyntaxError: invalid syntax


 Why does Python allow generator expression parenthesis to be mixed with
 function call parenthesis when there is only one parameter ?

For simplicity and elegant coding, so you can do something like you did
at first:

  sum(i for i in range(10))


 IMHO this should be forbidden, usage must not be different when there is
 only one parameter and when there are more parameters.

The problem in your last test is that if you use more than one argument,
you *must* use the parenthesis. In Py2.5 there's a better message error:

 f(4,i for i in range(10))
  File stdin, line 1
SyntaxError: Generator expression must be parenthesized if not sole argument


The correct way to do that is:

 f(4,(i for i in range(10)))
4 (generator object at 0xb7dab56c,)

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: finding monitor or screen resolution in Linux with standard python module

2007-03-07 Thread MonkeeSage
On Mar 7, 4:25 am, akbar [EMAIL PROTECTED] wrote:
 I googled and searched in archive. All I can find is finding
 resolution with Tkinter and pygame. Any idea to find monitor
 resolution with standard python module?
 I can check from output of: xprop -root
 _NET_DESKTOP_GEOMETRY(CARDINAL) . The problem is when you use Beryl or
 Xgl, it is not correct anymore because Beryl or Xgl set this value
 from amount of workspaces multiplied by monitor or screen resolution.

Perhaps read-edid [1] or ddcprobe [2] would work since they read the
info strait off the EDID. You could probably read the EDID from python
(mabye through the xlib binding?), but no need to reinvent the wheel.

[1] http://john.fremlin.de/programs/linux/read-edid/index.html
[2] http://sources.gentoo.org/viewcvs.py/gentoo-src/Xorgautoconfig/ddcprobe/

Regards,
Jordan

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


Re: Generator expression parenthesis mixed with function call ones

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 12:53:43 -0300, Laurent Pointal  
[EMAIL PROTECTED] escribió:

 f(4,i for i in range(10))
   File stdin, line 1
 SyntaxError: invalid syntax

2.5 has a better error message:
py f(4,i for i in range(10))
   File stdin, line 1
SyntaxError: Generator expression must be parenthesized if not sole  
argument

 Why does Python allow generator expression parenthesis to be mixed with
 function call parenthesis when there is only one parameter ?

Because they are redundant when only one argument is used.
sum(i for i in range(10)) looks better than sum((i for i in range(10)))
Beautiful is better than ugly, and Readability counts.

 IMHO this should be forbidden, usage must not be different when there is
 only one parameter and when there are more parameters.

It's similar to %d % 123 vs. %d % (123,)
Special cases aren't special enough to break the rules.
Although practicality beats purity.

 User should all times explicitly use () for a generator expression and
 [] for a list comprehension expression.

For a list comprehension, yes. For a generator, not always.

-- 
Gabriel Genellina

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


Re: How to build a Windows service using win32?

2007-03-07 Thread Gregor Mosheh

Giles Brown wrote:
 Yeah.  You've cleverly decided to simplify the smallest possible
 python service by removing the
 if __name__ == '__main__':

Ha ha. :)
Seriously, though, I removed that long after it was failing to work, and
have since replaced it and it didn't affect a thing.


Gabriel Genellina wrote:
 Have you installed the pywin32 package from
 https://sourceforge.net/projects/pywin32/ ?
 The code skeleton looks OK to me.

Indeed, I have win32 installed. I'm used to writing wx applications,
compiling into exes, etc. Services are a new direction for me.


So, both of you say that the program I sent *did* work?import win32serviceutil, win32service, win32event


class Service(win32serviceutil.ServiceFramework):
_svc_name_ = EDMS-to-CG
_svc_display_name_ = EDMS-to-CG Syncer
_svc_description_  = Uploaded the EDMS database to Cartograph

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):
pausetime = 60 * 1000
while True:
stopsignal = win32event.WaitForSingleObject(self.hWaitStop, 
pausetime)
if stopsignal == win32event.WAIT_OBJECT_0: break
self.runOneLoop()

def runOneLoop(self):
import servicemanager
servicemanager.LogInfoMsg('Running')

if __name__ == '__main__':
win32serviceutil.HandleCommandLine(Service)-- 
http://mail.python.org/mailman/listinfo/python-list

Re: askstring Window to the top under Windows

2007-03-07 Thread jim-on-linux
On Wednesday 07 March 2007 05:02, Ingo Wolf wrote:
  Original-Nachricht 
 Datum: Tue, 06 Mar 2007 20:49:42 -0500
 Von: jim-on-linux [EMAIL PROTECTED]
 An: python-list@python.org
 CC: iwl [EMAIL PROTECTED]
 Betreff: Re: askstring Window to the top under
 Windows

  By default
  tk will open a root window.
  so you will have to create
  something to put into the
  root window.
  I suggest a button to open the tkSimpleDialog
  box.
 
  go to;
 
  http://www.pythonware.com/library/tkinter/int
 roduction/

 I've allready had a short look trough this to
 find an idea how to change this behavior (which
 should be done by the askstring makers) but
 haven't up to now. I think what I do is what
 askstring was made for keeping me away from tk
 internals only wanting a little string input.

 Because I have embedded python In my C-App I
 make my own window now In C and extend python
 by it so having more control about things
 happen.


Check out how to use Entry Wiget
for data entry.



from Tkinter import *

root = Tk()  ## this is the default window
vlab = Label(root,   width = 20, 
  text = 'Enter data here')
vlab.grid( row=0, column =0)

ventry= Entry(root, width = 30)
ventry.grid(row = 0, column = 1)
mainloop()

jim-on-linux
http:\\www.inqvista.com







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


Re: How to build a Windows service using win32?

2007-03-07 Thread Gregor Mosheh
Giles Brown wrote:
 Yeah.  You've cleverly decided to simplify the smallest
 possible python service by removing the
 if __name__ == '__main__':

Ha ha. :)
Seriously, though, I removed that long after it was failing to work, and
have since replaced it and it didn't affect a thing.


Gabriel Genellina wrote:
 Have you installed the pywin32 package from
 https://sourceforge.net/projects/pywin32/ ?
 The code skeleton looks OK to me.

Indeed, I have win32 installed. :)

I'm used to writing wxPython apps, even a small-scale video game, but
services are a new and alien direction for me. :)

Now, I did stumble upon the solution to this one this morning, after a
fresh night of sleep: I re-ran python tester.py install I got a message
that the service had been updated, and now it runs! Hooray!

Any insight into why that would be the case? Does pythonservice.exe keep a
cached copy or some such, so I'll have to re-install the service after
code changes?


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


Re: Python Source Code Beautifier

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 10:29:29 -0300, Alan Franzoni  
[EMAIL PROTECTED] escribió:

 Il Tue, 06 Mar 2007 01:55:54 -0300, Gabriel Genellina ha scritto:

 If we rely on duck typing, by the way, we may encounter two types  
 quacking
 like ducks, flying like ducks, but in fact acting as slightly different
 ducks. I should remember as well, when designing a container type that I
 want to use in place of a list, to carefully craft an __iadd__ method  
 which
 works just like the a list's own __iadd__ method; if I forget, I may
 introduce a subtle error.

I'm not sure of your concerns. If you want to provide your own container  
that mimics a list, there are a lot more things to consider than __iadd__  
(See the UserList class or this ListMixin recipe:  
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440656).

__iadd__, in general, is not *required* to modify the instance in place  
(but should try to do that, if possible). After this code:
b = a
a += c
you can't assert than a and b both refer to the *same* object, as before.  
If you need that, don't use += at all. (For a generic object, I mean. The  
built-in list does the right thing, of course)

-- 
Gabriel Genellina

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


Re: Recommended FastCGI module?

2007-03-07 Thread John Nagle
Jon Ribbens wrote:
 In article [EMAIL PROTECTED], John Nagle wrote:
 
  The JonPy version:
  http://jonpy.sourceforge.net/fcgi.html
  Last revised in 2004.
 
 
 I'd recommend my one, but it's just possible I'm not impartial ;-)

Does it work with current Pythons?  (2.4, 2.5)?  I'm mainly
concerned about the abandonware problem with some of them.

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


Re: How to build a Windows service using win32?

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 13:45:44 -0300, Gregor Mosheh [EMAIL PROTECTED]  
escribió:

 Now, I did stumble upon the solution to this one this morning, after a
 fresh night of sleep: I re-ran python tester.py install I got a message
 that the service had been updated, and now it runs! Hooray!

 Any insight into why that would be the case? Does pythonservice.exe keep  
 a
 cached copy or some such, so I'll have to re-install the service after
 code changes?

I don't think so. After code changes, stopping and restarting the service  
should be enough.
Maybe you had registered another source file, maybe on another directory,  
using the same service name?

-- 
Gabriel Genellina

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


Re: Recommended FastCGI module?

2007-03-07 Thread Robin Becker
John Nagle wrote:
What's the recommended FastCGI module for Python.  There are at least five:
 
   The Robin Dunn / Total Control Software version:
   http://alldunn.com/python/fcgi.py
   Last revised in 1998.
...

we are using a slightly modified and modernized version of the above in a front 
facing app for a large company with reasonable results. Our decision was 
prompted by a consultant who wanted more speed, but it turned out the original 
traffic assumptions were wrong so the small advantage over CGI isn't actually 
needed. At the back end we're using apache+mod_fastcgi and choosing the 
configuration parameters was the main difficulty.

Using fcgi did induce some fairly careful code consideration to ensure we could 
rerun without blowing up the universe.
-- 
Robin Becker

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


Re: Recommended FastCGI module?

2007-03-07 Thread Jon Ribbens
In article [EMAIL PROTECTED], John Nagle wrote:
 Jon Ribbens wrote:
 The JonPy version:
 http://jonpy.sourceforge.net/fcgi.html
 Last revised in 2004.
 
 I'd recommend my one, but it's just possible I'm not impartial ;-)
 
 Does it work with current Pythons?  (2.4, 2.5)?  I'm mainly
 concerned about the abandonware problem with some of them.

Yes, I use it myself in my day job, where we have recently upgraded
to Python 2.5. jonpy itself hasn't been revised for a while because
there have been no revisions I felt necessary. There may be a new
version released in the next couple of months, but there won't be
any major changes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project organization and import

2007-03-07 Thread [EMAIL PROTECTED]
 package_name/
  package_pre.py - contains globals for the package
  component_a.py- a useful-sized collection of functionality
  component_b.py- another
  component_c.py- another
  package_post.py   - stuff that relies on the prior stuff
  __init__.py   - or you can put the post stuff here

 Then __init__.py contains something like:

 from package_pre import *
 from component_a import *
 from component_b import *
 from component_c import *
 from package_post import *

 Anansi Spaceworkshttp://www.AnansiSpaceworks.com

Thank you! That is by far the clearest I have ever seen that
explained.
I saved it and Sent it on to a friend that is learning python.

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


Re: Generator expression parenthesis mixed with function call ones

2007-03-07 Thread Laurent Pointal
Gabriel Genellina wrote:

 En Wed, 07 Mar 2007 12:53:43 -0300, Laurent Pointal
 [EMAIL PROTECTED] escribió:
 
 f(4,i for i in range(10))
   File stdin, line 1
 SyntaxError: invalid syntax
 
 2.5 has a better error message:
 py f(4,i for i in range(10))
File stdin, line 1
 SyntaxError: Generator expression must be parenthesized if not sole
 argument
 
 Why does Python allow generator expression parenthesis to be mixed with
 function call parenthesis when there is only one parameter ?
 
 Because they are redundant when only one argument is used.
 sum(i for i in range(10)) looks better than sum((i for i in range(10)))
 Beautiful is better than ugly, and Readability counts.

I complement my reply.

Beginners generally know about list-comprehensions and associate the
syntax x for x in asequence to a list expression. I'm not sure that
reading a f(i for i in range(20)) they understand that they are dealing
with a different object kind.

If function f start by a if len(myparameter)...
  TypeError: len() of unsized object

If function f goes among its parameter with for x in myparameter more than
once, other loops goes throught an empty loop.

 IMHO this should be forbidden, usage must not be different when there is
 only one parameter and when there are more parameters.
 
 It's similar to %d % 123 vs. %d % (123,)
 Special cases aren't special enough to break the rules.
 Although practicality beats purity.

In that case there cannot be confusion.

A+

Laurent.

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

catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
Hi all,

Imagine I have three functions a(x), b(x), c(x) that each return
something or raise an exception.  Imagine I want to define a function
that returns a(x) if possible, otherwise b(x), otherwise c(x),
otherwise raise CantDoIt.

Here are three ways I can think of doing it:

--
# This one looks ugly
def nested_first(x):
try:
return a(x)
except:
try:
return b(x)
except:
try:
return c(x)
except:
raise CantDoIt

# This one looks long-winded
def flat_first(x):
try:
return a(x)
except:
pass
try:
return b(x)
except:
pass
try:
return c(x)
except:
raise CantDoIt

# This one only works because a,b,c are functions
# Moreover it seems like an abuse of a loop construct to me
def rolled_first(x):
for f in a, b, c:
try:
return f(x)
except:
continue
raise CantDoIt
--

I don't feel happy with any of these.  Is there a more satisfying way
of doing this in Python? What I would like is something like:

--
# This one isn't correct but looks the clearest to me
def wished_first(x):
try:
return a(x)
except:
return b(x)
except:
return c(x)
except:
raise CantDoIt
--

I guess what I'm looking for is some sort of
if:
elif:
...
elif:
else:

but for try: except:
That's why
try:
except:
except:
...
except:

seemed natural to me :)  And I'd like to find a nice way to do this in
a syntactically correct way.

Note: I've chosen functions a, b, c, but really I'm looking for a way
that is suitable for any chunk of code.

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


Re: persistent fifo queue class

2007-03-07 Thread David Bear
Diez B. Roggisch wrote:

 David Bear schrieb:
 I'm looking to see if there are any examples or prewritting fifo queue
 classes. I know this is a broad topic. I'm looking to implement a simple
 application where a web server enqueue and pickle using a local socket on
 to a 'queue server' -- and then I will have another application dequeue
 the pickles again using a local socket.
 
 Why don't you use a DB for that? If you want pickles, use a  blob
 column. But all the rest - a defined protocol, stable server,
 transactions - you get for free.
 
 Diez

Thanks for the suggestion. I did think of this. Indeed the final destination
of the data is in a db. However, the postsgresql server is on a separate
box. It will be connected via a private lan. I was worried that possible
network disruptions would cause either the web application to hang -- or
data to just get lost. I was thinking along the lines is a message queue
architecture, where the web app would push data directly onto a queue --
and then a worker app would dequeue the data and handle it by sending it to
the db server or otherwise.


-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Debugging segmentation faults

2007-03-07 Thread George Sakkis
I have a pure python program (no C extensions) that occasionally core
dumps in a non-reproducible way. The program is started by a (non-
python) cgi script when a form is submitted. It involves running a
bunch of other programs through subprocess in multiple threads and
writing its output in several files. So the only suspicious parts I
can think of is subprocess and/or multithreading. For the
multithreading part I'm using a modified version of threadpool.py
(http://www.chrisarndt.de/en/software/python/threadpool/), which is
built on top of the threading and Queue stdlib modules. Whatever bugs
may linger there, I'd hope that they would show up as normal Python
exceptions instead of segfaults.

All I have now is a few not particularly insightful core files (actual
path names and args changed for privacy):

/home/gsakkis/foogdb --core core.20140
GNU gdb Red Hat Linux (5.2-2)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type show copying to see the conditions.
There is absolutely no warranty for GDB.  Type show warranty for
details.
This GDB was configured as i386-redhat-linux.
Core was generated by `python2.5 /home/gsakkis/foo/foo.py --XXX --
max=30 --bar=/tmp/83840`
Program terminated with signal 11, Segmentation fault.
#0  0x080b222d in ?? ()
(gdb) backtrace
#0  0x080b222d in ?? ()
#1  0x080b28d1 in ?? ()
#2  0x080fa8ab in ?? ()
#3  0x0805c918 in ?? ()
(...)
#28 0x080b310f in ?? ()
#29 0x080dbfdd in ?? ()
#30 0x40021fef in ?? ()

Any hints ?

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


Any HTML to Latex module available in Python

2007-03-07 Thread Ramdas
Any HTML to Latex module available in Python which I can use to
convert HTML text to Latex

Ramdas

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


Re: catching exceptions from an except: block

2007-03-07 Thread Miki
Hello Arnaud,

 Imagine I have three functions a(x), b(x), c(x) that each return
 something or raise an exception.  Imagine I want to define a function
 that returns a(x) if possible, otherwise b(x), otherwise c(x),
 otherwise raise CantDoIt.
Exceptions are for error handling, not flow control.

 Here are three ways I can think of doing it:
 ...

 # This one only works because a,b,c are functions
 # Moreover it seems like an abuse of a loop construct to me
 def rolled_first(x):
 for f in a, b, c:
 try:
 return f(x)
 except:
 continue
 raise CantDoIt
My vote is for that one.

 I don't feel happy with any of these.  Is there a more satisfying way
 of doing this in Python? What I would like is something like:

 --
 # This one isn't correct but looks the clearest to me
 def wished_first(x):
 try:
 return a(x)
 except:
 return b(x)
 except:
 return c(x)
 except:
 raise CantDoIt
Again, exception are for error handling, not for flow control.

As a side note, try to avoid catch:, always catch explicit
exceptions.

HTH,
Miki [EMAIL PROTECTED]
http://pythonwise.blogspot.com

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


RE: Python 2.1 and Daylight saving time

2007-03-07 Thread Hammett, Wayne
Thanks for the quick reply.

Help me OB1,

I mainly needed to know if I could avert Daylight Saving Time issues by
upgrading to Python 2.5.

It appears that Python gets it UTC settings from a table in the C
library. Does this still hold true for Python 2.5. It looks that it will
fail to recognize the new DST 2007 changes.


Thanks again,

Wayne Hammett - MCSE
Snr. Network Engineer
1214 Church Street
Nashville,  TN  37246
(615) 747-3092
[EMAIL PROTECTED]
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 07, 2007 1:41 PM
To: Hammett, Wayne
Cc: [EMAIL PROTECTED]
Subject: Re: Python 2.1 and Daylight saving time


Wayne It appears that Python 2.1 is affected by the DST 2007 issue.
I
Wayne cannot really tell.

Wayne Can you point me to support documentation?

Wayne,

Python 2.1 is quite old and no longer supported.  The last 2.1 release
(2.1.3) was April 8, 2002.  The current release is Python 2.5.  That
said,
can you describe your problem clearly?  Do you have a simple script that
demonstrates the problem?  If so, it's possible that you can get some
help
from the folks on the python-list@python.org mailing list.  At the very
least people should be able to tell you if the problem you see exists in
later versions or if there's a bug in your script you can fix to avoid
the
problem.

-- 
Skip Montanaro - [EMAIL PROTECTED] - http://www.webfast.com/~skip/
The hippies and the hipsters did some great stuff in the sixties,
but the geeks pulled their weight too. -- Billy Bragg


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


Re: Why does SocketServer default allow_reuse_address = false?

2007-03-07 Thread Joshua J. Kugler
Greg Copeland wrote:
 Is there some history to this of which I'm not aware?  Is there a good
 reason for it to default to false?
SNIP Greg's very informative reply
 Long story short, it is not a bug.  It is a feature.  The proper
 default is that of the OS, which is to ensure SO_REUSEADDR is disabled
 unless you absoluetely understand what you're buying by enabling it.

Thanks for your reply.  Those are all point of which I had not been aware.

My problem (and the reason I set reuse to True) is this: if I have
connections active when I restart my service, upon restart, the socket will
fail to bind because there is still a connection in a WAIT state.  And
until that old connection goes away (30 seconds or so?) I cannot restart
the service.  So, the only option would be to sit there in a loop calling
serve_forever until it doesn't throw a can't bind to socket exception.

Or is there something I'm *really* missing about the way SocketServer is
supposed to work?  Am I supposed to notify my connection threads to shut
down and disconnect properly?  Which gets even more fun since they are
sitting there waiting for input on the connection and not in a position to
respond to other events...gets back to the fun of killing threads that
are blocking.

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

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

Re: SPE python IDE: Call for testers!

2007-03-07 Thread SPE - Stani's Python Editor
On 6 Mrz., 23:21, MonkeeSage [EMAIL PROTECTED] wrote:
 Very nice. One issue I've come across is that it doesn't seem to work
 with  wxwidgets-2.8 (segfault when trying to load a file), so you
 should probably set MIN_WX_VERSION to 2.8.

 Regards,
 Jordan

Hi Jordan,

Thanks for trying. Did you try from subversion? Could you send me the
debug output (python SPE.py --debug) or send me the file you were
trying to open? SPE has not any specific wxPython2.8 feature, so I am
very curious what causes the error.

Stani

PS Erratum: I forgot to update my blog with the changes in SPE: now
you can read them at: http://pythonide.stani.be

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


Re: thread and portability Unix/Linux

2007-03-07 Thread Joshua J. Kugler
awalter1 wrote:

 Hi,
 I have a Python application that runs under HPUX 11.11 (then unix). It
 uses threads :
 from threading import Thread
 # Class Main
 class RunComponent(Thread):
 
 My application should run under Linux (red hat 3 ou 4) and I read that
 differences exist between the implementation of threads : on HPUX
 11.11 there is CMA (ou DCE) threads and on Linux POSIX thread. Do you
 think that my Python application should be modified or may be such
 differences are hidden by the python interpreter ?
 In other terms, do I get some risks on this particular aspect by
 porting my application ?
 Thanks a lot
 
 PS: If you are aware of other risk of porting, I am interested too.

The Python threading model abstracts from the underlying OS threading, so
there should be no need to change anything (AFAIK).

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

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

Re: catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
On 7 Mar, 19:26, Miki [EMAIL PROTECTED] wrote:
 Hello Arnaud,

Hi Miki

[snip]
 Exceptions are for error handling, not flow control.

Maybe but it's not always that clear cut! As error handling is a form
of flow control the two have to meet somewhere.

[snip]
 As a side note, try to avoid catch:, always catch explicit
 exceptions.

I didn't specify what I wanted to catch because it didn't feel it was
relevant to the problem.

Thanks

--
Arnaud

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


Re: Why does SocketServer default allow_reuse_address = false?

2007-03-07 Thread Chris Mellon
On 3/7/07, Joshua J. Kugler [EMAIL PROTECTED] wrote:
 Greg Copeland wrote:
  Is there some history to this of which I'm not aware?  Is there a good
  reason for it to default to false?
 SNIP Greg's very informative reply
  Long story short, it is not a bug.  It is a feature.  The proper
  default is that of the OS, which is to ensure SO_REUSEADDR is disabled
  unless you absoluetely understand what you're buying by enabling it.

 Thanks for your reply.  Those are all point of which I had not been aware.

 My problem (and the reason I set reuse to True) is this: if I have
 connections active when I restart my service, upon restart, the socket will
 fail to bind because there is still a connection in a WAIT state.  And
 until that old connection goes away (30 seconds or so?) I cannot restart
 the service.  So, the only option would be to sit there in a loop calling
 serve_forever until it doesn't throw a can't bind to socket exception.

 Or is there something I'm *really* missing about the way SocketServer is
 supposed to work?  Am I supposed to notify my connection threads to shut
 down and disconnect properly?  Which gets even more fun since they are
 sitting there waiting for input on the connection and not in a position to
 respond to other events...gets back to the fun of killing threads that
 are blocking.

 j


This is just the way sockets work on your platform. How exactly
sockets shut down, and the exact effect that SO_REUSEADDR varies from
platform to platform. In your case, using it is probably reasonable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using python to query active directory

2007-03-07 Thread Michael Ströder
David Bear wrote:
 Is it possible to use python to make calls agains microsoft active
 directory?

What do you mean with calls agains microsoft active directory?
Querying user and computer entries etc.?

python-ldap might be an option for you.

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Is numeric keys of Python's dictionary automatically sorted?

2007-03-07 Thread John
I am coding a radix sort in python and I think that Python's dictionary may 
be a choice for bucket.

The only problem is that dictionary is a mapping without order. But I just 
found that if the keys are numeric, the keys themselves are ordered in the 
dictionary.

part of my code is like this:
radix={}
for i in range(256):
radix[i]=[]

I checked and found that it is ordered like: {1:[], 2:[], 3[],...}

So I can just print out the contents of the dictionary in the desired order 
without additional code.
I also tried adding new numeric keys and found that the dictionary's keys 
are still ordered.

However, I am not sure whether it is always like this. Can anybody confirm 
my finding?
 


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


Re: catching exceptions from an except: block

2007-03-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Arnaud Delobelle
wrote:

 # This one only works because a,b,c are functions
 # Moreover it seems like an abuse of a loop construct to me
 def rolled_first(x):
 for f in a, b, c:
 try:
 return f(x)
 except:
 continue
 raise CantDoIt
 --

Why do you think this is an abuse?  I think it's a perfectly valid use of
a loop.

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


Re: catching exceptions from an except: block

2007-03-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Miki wrote:

 Exceptions are for error handling, not flow control.

That's not true, they are *exceptions* not *errors*.  They are meant to
signal exceptional situations.  And at least under the cover it's used in
every ``for``-loop because the end condition is signaled by a
`StopIteration` exception.  Looks like flow control to me.

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


More M2Crypto build problems

2007-03-07 Thread John Nagle
Trying to build M2Crypto on a dedicated server running Red Hat Fedora Core 6.
I'm trying to do this right, without manual patching.

The error message I'm getting during build is:

python setup.py build
...
swig -python -I/usr/include -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
/usr/include/openssl/opensslconf.h:27: Error: CPP #error This openssl-devel 
package does not work your architecture?. Use the -cpperraswarn option to 
continue swig processing.
error: command 'swig' failed with exit status 1

We went through this before, but last time, the versions of OpenSSL and
of SWIG on the system were old, and I was running on a shared server
and couldn't update it.  Eventually, M2Crypto was hammered
into working, but it was ugly.  It was necessary to patch setup.py as
follows:

107,108d106
 target_cpu_str = '-D__i386__' # PATCH - assume Intel target. OpenSSL build 
needs this.

  116c114
  swig_opts = [swig_opts_str,target_cpu_str]
---
   swig_opts = [swig_opts_str]

The problem is that the include file in OpenSSL assumes that some
system ID, like __i386__, is defined, which GCC does, but SWIG
does not. It might be considered a bug in SWIG.

This time, everything on the dedicated server has been updated with Yum,
so it ought to just work.

Yum says:
 
  Installed Packages
  openssl.i686 0.9.8a-5.4 installed
  openssl-devel.i386   0.9.8a-5.4 installed
  python.i386  2.4.3-9.FC5installed
  swig.i3861.3.31-0.fc5   installed
  Available Packages
  openssl.i386 0.9.8a-5.4 updates

All of those are later than the ones required for M2Crypto, so the system
should be current.
 
But it doesn't.

Also reported as a SWIG bug, as #1676049.

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


Re: Direct memory access

2007-03-07 Thread Travis Oliphant
Collin Stocks wrote:
 Does anyone know how to directly handle memory using python?
 I want to be able, for example, to copy the actual contents of a memory 
 address, or set the actual contents of a memory address.

This kind of thing is generally not what Python is used for, so it's not 
really easy to do.

Writing to arbitrary memory areas is an easy way to cause segmentation 
violations which Python and its extensions try to make segmentation 
violations (memory violations) as near impossible as they can.

If you really need to do this then you can use ctypes to do it.

Let N be the number of bytes you want to access, then

import ctypes
g = (ctypes.c_char*N).from_address(addr)

g is now a settable sequence of bytes that you can read and write to 
using strings.

g[0]  # read the first byte
g[1]  # read the second byte

g[0] = '\x24' # set the first byte to hexadecimal 24

etc...

If you don't have permission to write to addr then you will get memory 
violations and your program will crash if you try to read from or write 
to the resulting sequence.

-Travis


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


Re: finding monitor or screen resolution in Linux with standard python module

2007-03-07 Thread consmash
On Mar 7, 11:25 am, akbar [EMAIL PROTECTED] wrote:
 I googled and searched in archive. All I can find is finding
 resolution with Tkinter and pygame. Any idea to find monitor
 resolution with standard python module?
 I can check from output of: xprop -root
 _NET_DESKTOP_GEOMETRY(CARDINAL) . The problem is when you use Beryl or
 Xgl, it is not correct anymore because Beryl or Xgl set this value
 from amount of workspaces multiplied by monitor or screen resolution.

A method 'screen' from Python X Library looks promising:
http://python-xlib.sourceforge.net/doc/html/python-xlib_16.html#SEC15

More, or less if I understand right you just need to request from
server dimensions of the screen, over x protocol of course. So it will
be something associated with Xlib.

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


Re: Is numeric keys of Python's dictionary automatically sorted?

2007-03-07 Thread Ant
On Mar 7, 8:18 pm, John [EMAIL PROTECTED] wrote:
...
 However, I am not sure whether it is always like this. Can anybody confirm
 my finding?

From the standard library docs:

Keys and values are listed in an arbitrary order which is non-random,
varies across Python implementations, and depends on the dictionary's
history of insertions and deletions.

i.e. the behaviour you have discovered is an implementation detail,
and could change in future versions.

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


Re: Is numeric keys of Python's dictionary automatically sorted?

2007-03-07 Thread Carsten Haese
On Wed, 2007-03-07 at 15:18 -0500, John wrote:
 I am coding a radix sort in python and I think that Python's dictionary may 
 be a choice for bucket.
 
 The only problem is that dictionary is a mapping without order. But I just 
 found that if the keys are numeric, the keys themselves are ordered in the 
 dictionary.

No.

The sequence of keys in a dictionary is a coincidental side effect of
the particular Python implementation, the number of keys, the values of
the keys, and the order in which the keys are inserted. You must not
rely on the keys appearing in any particular order.

Here is a simple counterexample that breaks the ordering, at least for
the version I'm running:

 d = {}
 for i in range(0,6): d[10**i] = []
... 
 d
{10: [], 1: [], 100: [], 1000: [], 10: [], 1: []}

-Carsten


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


Re: Is numeric keys of Python's dictionary automatically sorted?

2007-03-07 Thread John
Then is there anyway to sort the numeric keys and avoid future implemetation 
confusion?


Ant [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On Mar 7, 8:18 pm, John [EMAIL PROTECTED] wrote:
 ...
 However, I am not sure whether it is always like this. Can anybody 
 confirm
 my finding?

From the standard library docs:

 Keys and values are listed in an arbitrary order which is non-random,
 varies across Python implementations, and depends on the dictionary's
 history of insertions and deletions.

 i.e. the behaviour you have discovered is an implementation detail,
 and could change in future versions.
 


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


Re: catching exceptions from an except: block

2007-03-07 Thread Larry Bates
Arnaud Delobelle wrote:
 Hi all,
 
 Imagine I have three functions a(x), b(x), c(x) that each return
 something or raise an exception.  Imagine I want to define a function
 that returns a(x) if possible, otherwise b(x), otherwise c(x),
 otherwise raise CantDoIt.
 
 Here are three ways I can think of doing it:
 
 --
 # This one looks ugly
 def nested_first(x):
 try:
 return a(x)
 except:
 try:
 return b(x)
 except:
 try:
 return c(x)
 except:
 raise CantDoIt
 
 # This one looks long-winded
 def flat_first(x):
 try:
 return a(x)
 except:
 pass
 try:
 return b(x)
 except:
 pass
 try:
 return c(x)
 except:
 raise CantDoIt
 
 # This one only works because a,b,c are functions
 # Moreover it seems like an abuse of a loop construct to me
 def rolled_first(x):
 for f in a, b, c:
 try:
 return f(x)
 except:
 continue
 raise CantDoIt
 --
 
 I don't feel happy with any of these.  Is there a more satisfying way
 of doing this in Python? What I would like is something like:
 
 --
 # This one isn't correct but looks the clearest to me
 def wished_first(x):
 try:
 return a(x)
 except:
 return b(x)
 except:
 return c(x)
 except:
 raise CantDoIt
 --
 
 I guess what I'm looking for is some sort of
 if:
 elif:
 ...
 elif:
 else:
 
 but for try: except:
 That's why
 try:
 except:
 except:
 ...
 except:
 
 seemed natural to me :)  And I'd like to find a nice way to do this in
 a syntactically correct way.
 
 Note: I've chosen functions a, b, c, but really I'm looking for a way
 that is suitable for any chunk of code.
 
Without knowing more about the functions and the variable it is somewhat
hard to tell what you are trying to accomplish.  If a, b, c are functions
that act on x when it is a different type, change to one function that
can handle all types.

def d(x):
if isinstance(x, basestring):
#
# Code here for string
#
elif isinstance(x, int):
#
# Code here for int
#
elif isinstance(x, float):
#
# Code here for string
#
else:
raise ValueError


If they are different functions based on type do something like this:

#
# Set up a dictionary with keys for different types and functions
# that correspond.
#
fdict={type(''): a, type(1): b, type(1.0): c}
#
# Call the appropriate function based on type
#
fdict[type(x)](x)

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


Re: Debugging segmentation faults

2007-03-07 Thread SPE - Stani's Python Editor
If the error is reproducable and you can run wxPython, you could use
the excellent WinPdb debugger, which ships with SPE (python editor):
http://www.digitalpeers.com/pythondebugger/

... but if you can only run your script on a remote server this won't
help you.

Stani

--
SPE - http://pythonide.stani.be

On 7 Mrz., 20:15, George Sakkis [EMAIL PROTECTED] wrote:
 I have a pure python program (no C extensions) that occasionally core
 dumps in a non-reproducible way. The program is started by a (non-
 python) cgi script when a form is submitted. It involves running a
 bunch of other programs through subprocess in multiple threads and
 writing its output in several files. So the only suspicious parts I
 can think of is subprocess and/or multithreading. For the
 multithreading part I'm using a modified version of threadpool.py
 (http://www.chrisarndt.de/en/software/python/threadpool/), which is
 built on top of the threading and Queue stdlib modules. Whatever bugs
 may linger there, I'd hope that they would show up as normal Python
 exceptions instead of segfaults.

 All I have now is a few not particularly insightful core files (actual
 path names and args changed for privacy):

 /home/gsakkis/foogdb --core core.20140
 GNU gdb Red Hat Linux (5.2-2)
 Copyright 2002 Free Software Foundation, Inc.
 GDB is free software, covered by the GNU General Public License, and
 you are
 welcome to change it and/or distribute copies of it under certain
 conditions.
 Type show copying to see the conditions.
 There is absolutely no warranty for GDB.  Type show warranty for
 details.
 This GDB was configured as i386-redhat-linux.
 Core was generated by `python2.5 /home/gsakkis/foo/foo.py --XXX --
 max=30 --bar=/tmp/83840`
 Program terminated with signal 11, Segmentation fault.
 #0  0x080b222d in ?? ()
 (gdb) backtrace
 #0  0x080b222d in ?? ()
 #1  0x080b28d1 in ?? ()
 #2  0x080fa8ab in ?? ()
 #3  0x0805c918 in ?? ()
 (...)
 #28 0x080b310f in ?? ()
 #29 0x080dbfdd in ?? ()
 #30 0x40021fef in ?? ()

 Any hints ?


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


Re: Why does SocketServer default allow_reuse_address = false?

2007-03-07 Thread Joshua J. Kugler
Chris Mellon wrote:
 My problem (and the reason I set reuse to True) is this: if I have
 connections active when I restart my service, upon restart, the socket
 will
 fail to bind because there is still a connection in a WAIT state.
 
 This is just the way sockets work on your platform. How exactly
 sockets shut down, and the exact effect that SO_REUSEADDR varies from
 platform to platform. In your case, using it is probably reasonable.

Thank you.  Glad to know I've chosen the best solution for my situation.

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

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

Re: Is numeric keys of Python's dictionary automatically sorted?

2007-03-07 Thread Robert Kern
John wrote:
 Then is there anyway to sort the numeric keys and avoid future implemetation 
 confusion?

sorted(mydict.keys())

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Generator expression parenthesis mixed with function call ones

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 15:21:57 -0300, Laurent Pointal  
[EMAIL PROTECTED] escribió:

 Gabriel Genellina wrote:

 En Wed, 07 Mar 2007 12:53:43 -0300, Laurent Pointal
 [EMAIL PROTECTED] escribió:

 Why does Python allow generator expression parenthesis to be mixed with
 function call parenthesis when there is only one parameter ?
Beginners generally know about list-comprehensions and associate the
 syntax x for x in asequence to a list expression. I'm not sure that

But list comprehensions have [] around... When you don't see the [], you  
should think this is something different...

 reading a f(i for i in range(20)) they understand that they are dealing
 with a different object kind.

Exactly.

 If function f start by a if len(myparameter)...
   TypeError: len() of unsized object

 If function f goes among its parameter with for x in myparameter more  
 than
 once, other loops goes throught an empty loop.

Then he thinks Something is wrong!, and reads some Python books, or asks  
here, and somebody will point him to the Python Tutorial, section 9.11:  
http://docs.python.org/tut/node11.html#SECTION000

 IMHO this should be forbidden, usage must not be different when there  
 is only one parameter and when there are more parameters.

If you want to review the original discussion on how to spell a generator  
expression (called accumulator display by that time) see  
http://mail.python.org/pipermail/python-dev/2003-October/038868.html

-- 
Gabriel Genellina

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


Re: Debugging segmentation faults

2007-03-07 Thread John Nagle
You're using Python on a web server to do something
complicated.  You must suffer.

Are you trying to fork off a subprocess in a multithreaded
program?  That's unlikely to work.  The sematics differ
from OS to OS (Solaris forks all the threads, most other
operating systems don't; most UNIX-based OSs copy all the
open file descriptors, but some give you control of which
open files are passed), and Python may not be thread-safe
in that area.

John Nagle

SPE - Stani's Python Editor wrote:
 If the error is reproducable and you can run wxPython, you could use
 the excellent WinPdb debugger, which ships with SPE (python editor):
 http://www.digitalpeers.com/pythondebugger/
 
 ... but if you can only run your script on a remote server this won't
 help you.
 
 Stani
 
 --
 SPE - http://pythonide.stani.be
 
 On 7 Mrz., 20:15, George Sakkis [EMAIL PROTECTED] wrote:
 
I have a pure python program (no C extensions) that occasionally core
dumps in a non-reproducible way. The program is started by a (non-
python) cgi script when a form is submitted. It involves running a
bunch of other programs through subprocess in multiple threads and
writing its output in several files. So the only suspicious parts I
can think of is subprocess and/or multithreading. For the
multithreading part I'm using a modified version of threadpool.py
(http://www.chrisarndt.de/en/software/python/threadpool/), which is
built on top of the threading and Queue stdlib modules. Whatever bugs
may linger there, I'd hope that they would show up as normal Python
exceptions instead of segfaults.

All I have now is a few not particularly insightful core files (actual
path names and args changed for privacy):

/home/gsakkis/foogdb --core core.20140
GNU gdb Red Hat Linux (5.2-2)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type show copying to see the conditions.
There is absolutely no warranty for GDB.  Type show warranty for
details.
This GDB was configured as i386-redhat-linux.
Core was generated by `python2.5 /home/gsakkis/foo/foo.py --XXX --
max=30 --bar=/tmp/83840`
Program terminated with signal 11, Segmentation fault.
#0  0x080b222d in ?? ()
(gdb) backtrace
#0  0x080b222d in ?? ()
#1  0x080b28d1 in ?? ()
#2  0x080fa8ab in ?? ()
#3  0x0805c918 in ?? ()
(...)
#28 0x080b310f in ?? ()
#29 0x080dbfdd in ?? ()
#30 0x40021fef in ?? ()

Any hints ?
 
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Miki a écrit :
 Hello Arnaud,
 
 
Imagine I have three functions a(x), b(x), c(x) that each return
something or raise an exception.  Imagine I want to define a function
that returns a(x) if possible, otherwise b(x), otherwise c(x),
otherwise raise CantDoIt.
 
 Exceptions are for error handling, not flow control.

def until(iterable,sentinel):
   for item in iterable:
 if item == sentinel:
   raise StopIteration
 yield item

  for item in until(range(10), 5):
... print item
...
0
1
2
3
4
 

Exceptions *are* a form of flow control.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Larry Bates a écrit :
(snip)

 def d(x):
 if isinstance(x, basestring):
 #
 # Code here for string
 #
 elif isinstance(x, int):
 #
 # Code here for int
 #
 elif isinstance(x, float):
 #
 # Code here for string
 #
 else:
 raise ValueError

As a side note : While there are a few corner cases where this is hardly 
avoidable (and yet I'd rather test on interface, not on concrete type), 
this kind of cose is exactly what OO polymorphic dispatch is supposed to 
avoid (no, don't tell me: I know you can't easily add methods to most 
builtin types).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 19:00:59 -0300, Bruno Desthuilliers  
[EMAIL PROTECTED] escribió:

 this kind of cose is exactly what OO polymorphic dispatch is supposed to

this kind of cose? Ce genre de chose?

-- 
Gabriel Genellina

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


Re: catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
On Mar 7, 8:52 pm, Larry Bates [EMAIL PROTECTED] wrote:
[snip]
 Without knowing more about the functions and the variable it is somewhat
 hard to tell what you are trying to accomplish.  If a, b, c are functions
 that act on x when it is a different type, change to one function that
 can handle all types.

I'm not really thinking about this situation so let me clarify. Here
is a simple concrete example, taking the following for the functions
a,b,c I mention in my original post.
  - a=int
  - b=float
  - c=complex
  - x is a string
This means I want to convert x to an int if possible, otherwise a
float, otherwise a complex, otherwise raise CantDoIt.

I can do:

for f in int, float, complex:
try:
return f(x)
except ValueError:
continue
raise CantDoIt

But if the three things I want to do are not callable objects but
chunks of code this method is awkward because you have to create
functions simply in order to be able to loop over them (this is whay I
was talking about 'abusing loop constructs').  Besides I am not happy
with the other two idioms I can think of.

--
Arnaud

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


Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Arnaud Delobelle a écrit :
 Hi all,
 
 Imagine I have three functions a(x), b(x), c(x) that each return
 something or raise an exception.  Imagine I want to define a function
 that returns a(x) if possible, otherwise b(x), otherwise c(x),
 otherwise raise CantDoIt.
 
 Here are three ways I can think of doing it:
 
 --
 # This one looks ugly

Yes.

 def nested_first(x):
 try:
 return a(x)
 except:

side-note
Try avoiding bare except clauses. It's usually way better to specify the 
type(s) of exception you're expecting to catch, and let other propagate.
/side-note

 try:
 return b(x)
 except:
 try:
 return c(x)
 except:
 raise CantDoIt
 
 # This one looks long-winded

Yes. And not's very generic.

 def flat_first(x):
 try:
 return a(x)
 except:
 pass
 try:
 return b(x)
 except:
 pass
 try:
 return c(x)
 except:
 raise CantDoIt
 
 # This one only works because a,b,c are functions

It works with any callable. Anyway, what else would you use here ???

 # Moreover it seems like an abuse of a loop construct to me

Why so ? loops are made for looping, adn functions are objects like any 
other.

 def rolled_first(x):
 for f in a, b, c:
 try:
 return f(x)
 except:
 continue
 raise CantDoIt

Here's an attempt at making it a bit more generic (side-noteit still 
lacks a way to specify which kind of exceptions should be silently 
swallowed/side-note.

def trythese(*functions):
   def try_(*args, **kw):
 for func in functions:
try:
  return func(*args, **kw)
except: # FIX ME : bare except clause
  pass
 else:
   # really can't do it, sorry
   raise CantDoIt
   return try_

result = trythese(a, b, c)(x)

 --
 # This one isn't correct but looks the clearest to me
 def wished_first(x):
 try:
 return a(x)
 except:
 return b(x)
 except:
 return c(x)
 except:
 raise CantDoIt

Having multiple except clauses is correct - but it has another semantic.


 Note: I've chosen functions a, b, c, but really I'm looking for a way
 that is suitable for any chunk of code.

A function is an object wrapping a chunk of code...

I personnaly find the loop-based approach quite clean and pythonic.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Direct memory access

2007-03-07 Thread Collin Stocks

Thanks. I didn't know about ctypes.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: catching exceptions from an except: block

2007-03-07 Thread garrickp
On Mar 7, 2:48 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote:

 I'm not really thinking about this situation so let me clarify. Here
 is a simple concrete example, taking the following for the functions
 a,b,c I mention in my original post.
   - a=int
   - b=float
   - c=complex
   - x is a string
 This means I want to convert x to an int if possible, otherwise a
 float, otherwise a complex, otherwise raise CantDoIt.

 I can do:

 for f in int, float, complex:
 try:
 return f(x)
 except ValueError:
 continue
 raise CantDoIt

 But if the three things I want to do are not callable objects but
 chunks of code this method is awkward because you have to create
 functions simply in order to be able to loop over them (this is whay I
 was talking about 'abusing loop constructs').  Besides I am not happy
 with the other two idioms I can think of.

 --
 Arnaud

Wouldn't it be easier to do:

if isinstance(x, int):
# do something
elif isinstance(x, float)t:
# do something
elif isinstance(x, complex):
# do something
else:
raise CantDoIt

or,

i = [int, float, complex]
for f in i:
if isinstance(x, f):
return x
else:
raise CantDoIt

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


RE: Python 2.1 and Daylight saving time

2007-03-07 Thread skip
removing webmaster email address...

Others reading this with more experience manipulating timezones please
reply.  This is completely out of the realm of my experience, but since I
pointed Wayne here from the webmaster mailing list I felt I should respond.
What I've written is based solely on reading a bit of the current time
module documentation and peeking at the time module source
(ever-so-briefly).

Wayne I mainly needed to know if I could avert Daylight Saving Time
Wayne issues by upgrading to Python 2.5.

Wayne It appears that Python gets it UTC settings from a table in the C
Wayne library. Does this still hold true for Python 2.5. It looks that
Wayne it will fail to recognize the new DST 2007 changes.

Python's timezone code is reliant on the functions provided by your system's
libc routines.  Starting in Python 2.3 if your system has a working tzset()
function in libc the time module exposes a tzset() function which you can
use to change the rules used by your system.  If your system's timezone
information hasn't been updated I imagine you could coax the correct
behavior out of your application with tzset().  I suggest you read the
relevant documentation

http://docs.python.org/dev/lib/module-time.html

before contemplating upgrading from 2.1 to something more recent and/or
modifying your application to use tzset().  Given the minimal amount of time
between now and Sunday morning I suspect your best chance of correct
operation will be to have the correct timezone tables installed on your
computer.

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


Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Gabriel Genellina a écrit :
 En Wed, 07 Mar 2007 19:00:59 -0300, Bruno Desthuilliers  
 [EMAIL PROTECTED] escribió:
 
 this kind of cose is exactly what OO polymorphic dispatch is supposed to
 
 
 this kind of cose?

sorry
s/cose/code/

 Ce genre de chose?
 
En quelques sortes, oui, quoique pas tout à fait !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-07 Thread garrickp
On Mar 7, 3:04 pm, [EMAIL PROTECTED] wrote:
 On Mar 7, 2:48 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote:





  I'm not really thinking about this situation so let me clarify. Here
  is a simple concrete example, taking the following for the functions
  a,b,c I mention in my original post.
- a=int
- b=float
- c=complex
- x is a string
  This means I want to convert x to an int if possible, otherwise a
  float, otherwise a complex, otherwise raise CantDoIt.

  I can do:

  for f in int, float, complex:
  try:
  return f(x)
  except ValueError:
  continue
  raise CantDoIt

  But if the three things I want to do are not callable objects but
  chunks of code this method is awkward because you have to create
  functions simply in order to be able to loop over them (this is whay I
  was talking about 'abusing loop constructs').  Besides I am not happy
  with the other two idioms I can think of.

  --
  Arnaud

 Wouldn't it be easier to do:

 if isinstance(x, int):
 # do something
 elif isinstance(x, float)t:
 # do something
 elif isinstance(x, complex):
 # do something
 else:
 raise CantDoIt

 or,

 i = [int, float, complex]
 for f in i:
 if isinstance(x, f):
 return x
 else:
 raise CantDoIt

I so missed the point of this. Not my day. Please ignore my post.

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


Re: catching exceptions from an except: block

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 18:48:18 -0300, Arnaud Delobelle  
[EMAIL PROTECTED] escribió:

 for f in int, float, complex:
 try:
 return f(x)
 except ValueError:
 continue
 raise CantDoIt

 But if the three things I want to do are not callable objects but
 chunks of code this method is awkward because you have to create
 functions simply in order to be able to loop over them (this is whay I
 was talking about 'abusing loop constructs').  Besides I am not happy
 with the other two idioms I can think of.

Hmmm, functions are cheap - nobody is charging you $2 for each def  
statement you write, I presume :)

A bit more serious, if those chunks of code are processing its input and  
returning something that you further process... they *are* functions. If  
you don't want them to be publicly available, use inner functions:

def xxxfactory(x):
   def f1(x):
  ...
   def f2(x):
  ...
   def f3(x):
  ...

   for f in f1,f2,f3:
 try:
   return f(x)
   ... same as above...

-- 
Gabriel Genellina

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


Re: Direct memory access

2007-03-07 Thread Collin Stocks

One last thing. Does anyone know how to take a python object and measure how
much space it is taking up in memory? I'm thinking probably not, but it's
worth asking.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2007-03-07 Thread Brian Adkins
George Sakkis wrote:
 [EMAIL PROTECTED] wrote:
 
 1. Lisp is the only industrial strength language
   ^^^
 You keep using that phrase. I don't think it means what you think it
 means.

[Vizzini has just cut the rope The Dread Pirate Roberts is climbing up]
Vizzini: HE DIDN'T FALL? INCONCEIVABLE.
Inigo Montoya: You keep using that word. I do not think it means what 
you think it means.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Arnaud Delobelle a écrit :
 On Mar 7, 8:52 pm, Larry Bates [EMAIL PROTECTED] wrote:
 [snip]
 
Without knowing more about the functions and the variable it is somewhat
hard to tell what you are trying to accomplish.  If a, b, c are functions
that act on x when it is a different type, change to one function that
can handle all types.
 
 
 I'm not really thinking about this situation so let me clarify. Here
 is a simple concrete example, taking the following for the functions
 a,b,c I mention in my original post.
   - a=int
   - b=float
   - c=complex
   - x is a string
 This means I want to convert x to an int if possible, otherwise a
 float, otherwise a complex, otherwise raise CantDoIt.
 
 I can do:
 
 for f in int, float, complex:
 try:
 return f(x)
 except ValueError:
 continue
 raise CantDoIt
 
 But if the three things I want to do are not callable objects but
 chunks of code this method is awkward because you have to create
 functions 

You have to write the chunks of code anyway, don't you ? So just 
adding a def statement above each chunk is not such a big deal.

Remember that you can define nested funcs, that will close over the 
namespace of the enclosing one, so you dont necessarily have to pollute 
the global namespace nor explicitly pass the whole environment to each 
of these functions.

Using the generic higher order func I proposed in a previous answer:

def maincode(tati, pouffin):
   def a():
 # some
 # code
 # here
 # that may raise
 return foo

   def b():
 # some
 # shorter chunk
 return bar

   def c():
 # yet
 # some
 # other
 # code
 return quux

   return trythese(a, b)()

Is it really less readable than:

def maincode(tati, pouffin):
   try:
 # some
 # code
 # here
 # that may raise
 return foo

   except_retry: # the missing(???) keyword you're after
 # some
 # shorter chunk
 return bar

   except_retry:
 # yet
 # some
 # other
 # code
 return quux

   else:
 raise CantDoIt


 simply in order to be able to loop over them (this is whay I
 was talking about 'abusing loop constructs').  Besides I am not happy
 with the other two idioms I can think of.
 
 --
 Arnaud
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Best place for a function?

2007-03-07 Thread Sergio Correia
I'm writing a class, where one of the methods is kinda complex. The
method uses a function which I know for certain will not be used
anywhere else. This function does not require anything from self, only
the args passed by the method.

Where should I put the function?

a) Inside the module but outside the class (to avoid cluttering it;
besides the function does not require to access any property or method
of the class).

# mymodule.py

def  _myfunction():
 ...

class myclass(object):
 def mymethod(self):
  ...
  spam = _myfunction()
...


b) Inside the class but outside the method

# mymodule.py

class myclass(object):
 def  _myfunction(self):
 ...

 def mymethod(self):
  ...
  spam = self._myfunction()
...

c) Inside the method:

# mymodule.py

class myclass(object):
 ...
 def mymethod(self):
 def  _myfunction(self):
   ...
 ...
 spam = self._myfunction()
 ...


I'm new to python (and couldn't find anything about this in PEP 8).
What would you suggest me?

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


Re: Best place for a function?

2007-03-07 Thread Diez B. Roggisch
Sergio Correia schrieb:
 I'm writing a class, where one of the methods is kinda complex. The
 method uses a function which I know for certain will not be used
 anywhere else. This function does not require anything from self, only
 the args passed by the method.
 
 Where should I put the function?
 
 a) Inside the module but outside the class (to avoid cluttering it;
 besides the function does not require to access any property or method
 of the class).
 
 # mymodule.py
 
 def  _myfunction():
 ...
 
 class myclass(object):
 def mymethod(self):
  ...
  spam = _myfunction()
...
 
 
 b) Inside the class but outside the method
 
 # mymodule.py
 
 class myclass(object):
 def  _myfunction(self):
 ...
 
 def mymethod(self):
  ...
  spam = self._myfunction()
...
 
 c) Inside the method:
 
 # mymodule.py
 
 class myclass(object):
 ...
 def mymethod(self):
 def  _myfunction(self):
   ...
 ...
 spam = self._myfunction()
 ...
 
 
 I'm new to python (and couldn't find anything about this in PEP 8).
 What would you suggest me?

If it really has no other use as in this class, put it as an 
instancemethod in there. Alternatively, you _could_ nest it like this:

class Foo(object):

def bar(self):
def my_long_important_method(argument):
pass
pass


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


Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Gabriel Genellina a écrit :
 En Wed, 07 Mar 2007 18:48:18 -0300, Arnaud Delobelle  
 [EMAIL PROTECTED] escribió:
 
 for f in int, float, complex:
 try:
 return f(x)
 except ValueError:
 continue
 raise CantDoIt

 But if the three things I want to do are not callable objects but
 chunks of code this method is awkward because you have to create
 functions simply in order to be able to loop over them (this is whay I
 was talking about 'abusing loop constructs').  Besides I am not happy
 with the other two idioms I can think of.
 
 
 Hmmm, functions are cheap 

To define. You pay the price when you call them !-)

(sorry, couldn't resist - I otherwise totally agree with you)

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


Re: More M2Crypto build problems

2007-03-07 Thread John Nagle
Still more M2Crypto build problems:

In M2Crypto's file SWIG/_ec.i, there's this:

#if OPENSSL_VERSION_NUMBER  0x0090800fL || defined(OPENSSL_NO_EC)
#undef OPENSSL_NO_EC
%constant OPENSSL_NO_EC = 1;
#else
%constant OPENSSL_NO_EC = 0;

%{
#include openssl/bn.h
#include openssl/err.h
#include openssl/pem.h
#include openssl/x509.h
#include openssl/ecdsa.h
#include openssl/ecdh.h
%}

There's the assumption here that versions of OpenSSL greater than 0.9.08???
contain elliptical curve cryptography support.  There's
also the assumption that ecdsa.h is present; it is included
unconditionally, and definitions from it are used later.

Unfortunately, the ones that ship with Fedora Core 5 and 6 do not have it:

http://threebit.net/mail-archive/fedora-list/msg14507.html

Updating with yum doesn't help.  Apparently there are patent problems
with the algorithm, and Red Hat pulled that code.  See

http://en.wikipedia.org/wiki/ECC_patents

I'm trying to get M2Crypto to build without elliptical cryptography, but
it's not working

John Nagle

Python.  Embrace the pain.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best place for a function?

2007-03-07 Thread Bruno Desthuilliers
Sergio Correia a écrit :
 I'm writing a class, where one of the methods is kinda complex. The
 method uses a function which I know for certain will not be used
 anywhere else. This function does not require anything from self, only
 the args passed by the method.
 
 Where should I put the function?

Somewhere in your module ?-)

(snip)

If your problem is to reduce the apparent complexity of the method, 
defining the function inside the method won't help that much (unless the 
function by itself is short enough - and event then...). Apart from 
having a direct access to the method's namespace, you don't gain much by 
doing so. And if it's a an implementation function that doesn't need to 
access the instance, it has no reason to be a method. Moreover, since 
it's not part of neither the class or the module interface, you can 
freely change your mind if and when you find a need to do so.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-07 Thread Diez B. Roggisch
Arnaud Delobelle schrieb:
 On Mar 7, 8:52 pm, Larry Bates [EMAIL PROTECTED] wrote:
 [snip]
 Without knowing more about the functions and the variable it is somewhat
 hard to tell what you are trying to accomplish.  If a, b, c are functions
 that act on x when it is a different type, change to one function that
 can handle all types.
 
 I'm not really thinking about this situation so let me clarify. Here
 is a simple concrete example, taking the following for the functions
 a,b,c I mention in my original post.
   - a=int
   - b=float
   - c=complex
   - x is a string
 This means I want to convert x to an int if possible, otherwise a
 float, otherwise a complex, otherwise raise CantDoIt.
 
 I can do:
 
 for f in int, float, complex:
 try:
 return f(x)
 except ValueError:
 continue
 raise CantDoIt
 
 But if the three things I want to do are not callable objects but
 chunks of code this method is awkward because you have to create
 functions simply in order to be able to loop over them (this is whay I
 was talking about 'abusing loop constructs').  

In your case, I don't consider it an abuse - au contraire. Because in 
such a situation where a possibly growing number of functions dealing 
with one value until one of them fits a loop is the natural thing to 
do, as it won't change in appearance just because you add a new 
conversion-function to some (semi-)global list. I'd consider it 
especially good style in that case.

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


Re: image processing

2007-03-07 Thread Claudio Grondi
edurand wrote:
 Hi,
 
 We are are pleased to announce the version 3.0 of the image processing
 library 'Filters'.
 You can use it in Python, and we have provided tutorials and samples
 in Python, with for exemple conversion from/to PIL image format.
 
 Have a look at : http://filters.sourceforge.net/
 
 it's open source of course
 
 regards
 edurand
 
In the context of this posting it would be interesting for me (and maybe 
also to others) to know:

What was the actual motivation behind the project?

What are other image processing packages missing, that is worth to be 
covered by a separate package?

(i.e. I checked http://filters.sourceforge.net/ out, but haven't yet 
found the mentioned questions answered )

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


Calling a function with unknown arguments?

2007-03-07 Thread Rob
I can get a list of a function's arguments.
 def bob(a, b):
... return a+b
...
 bob.func_code.co_varnames
('a', 'b')

Let's say that I also have a dictionary of possible arguments for this
function.
 possible = {'a':10, 'b':5, 'c':-3}

How do I proceed to call bob(a=10, b=5) with this information?

Thanks!

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


Re: Best place for a function?

2007-03-07 Thread bearophileHUGS
Diez B. Roggisch:
 If it really has no other use as in this class, put it as an
 instancemethod in there. Alternatively, you _could_ nest it like this:

Using an instancemethod may be the most formally correct solution for
that problem, but often nested function are the simpler solution. A
downside of nested functions is that you can't give them a doctest (in
a simple way).

Bye,
bearophile

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


Re: merits of Lisp vs Python

2007-03-07 Thread John Nagle
Brian Adkins wrote:
 George Sakkis wrote:
 
 [EMAIL PROTECTED] wrote:

 1. Lisp is the only industrial strength language

Neither Lisp nor Python is an industrial strength language.
The infrastructure is too weak.  Hosting providers and distro
makers aren't concerned over whether Python works.  They
care if C, C++, Java, PHP, and Perl work, but not Python or LISP.
Ask them.

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


Re: Calling a function with unknown arguments?

2007-03-07 Thread Grant Edwards
On 2007-03-07, Rob [EMAIL PROTECTED] wrote:
 I can get a list of a function's arguments.
 def bob(a, b):
 ... return a+b
 ...
 bob.func_code.co_varnames
 ('a', 'b')

 Let's say that I also have a dictionary of possible arguments for this
 function.
 possible = {'a':10, 'b':5, 'c':-3}

 How do I proceed to call bob(a=10, b=5) with this information?

bob(a=possible['a'],b=possible['b'])

-- 
Grant Edwards   grante Yow!  BRILL CREAM is
  at   CREAM O' WHEAT in another
   visi.comDIMENSION...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best place for a function?

2007-03-07 Thread Sergio Correia
I also found out I can't use `unittest` with nested functions :-(

Thank you all for the responses,

Best,
Sergio

On 7 Mar 2007 14:57:54 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Diez B. Roggisch:
  If it really has no other use as in this class, put it as an
  instancemethod in there. Alternatively, you _could_ nest it like this:

 Using an instancemethod may be the most formally correct solution for
 that problem, but often nested function are the simpler solution. A
 downside of nested functions is that you can't give them a doctest (in
 a simple way).

 Bye,
 bearophile

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

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


Re: Calling a function with unknown arguments?

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 19:55:08 -0300, Rob [EMAIL PROTECTED] escribió:

 I can get a list of a function's arguments.
 def bob(a, b):
 ... return a+b
 ...
 bob.func_code.co_varnames
 ('a', 'b')

 Let's say that I also have a dictionary of possible arguments for this
 function.
 possible = {'a':10, 'b':5, 'c':-3}

 How do I proceed to call bob(a=10, b=5) with this information?

You're almost done. Notice that co_varnames includes local variables too;  
only the first co_argcount are positional arguments.
If you only want to deal with positional arguments (no *args, no **kw):

py def bob(a,b):
...   c = a+b
...   return c
...
py bob.func_code.co_varnames
('a', 'b', 'c')
py bob.func_code.co_argcount
2
py args = dict((name, possible[name]) for name in  
bob.func_code.co_varnames[:bo
b.func_code.co_argcount] if name in possible)
py args
{'a': 10, 'b': 5}
py bob(**args)
15

It can handle missing arguments (if they have a default value, of course):

py def bob(a, k=3):
...   return a+k
...
py args = dict((name, possible[name]) for name in  
bob.func_code.co_varnames[:bo
b.func_code.co_argcount] if name in possible)
py args
{'a': 10}
py bob(**args)
13

-- 
Gabriel Genellina

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


Re: merits of Lisp vs Python

2007-03-07 Thread Brian Adkins
John Nagle wrote:
Neither Lisp nor Python is an industrial strength language.
 The infrastructure is too weak.  Hosting providers and distro
 makers aren't concerned over whether Python works.  They
 care if C, C++, Java, PHP, and Perl work, but not Python or LISP.
 Ask them.
 
 John Nagle

In your excitement to post a sweeping and inaccurate generalization (you 
missed diss'ing Ruby), I think you may have missed the point of my post. 
I surely wasn't trying to restart a dead thread, I just thought it was 
funny that there was a similarity to a line from Princess Bride in the 
thread (see relevant part below that you cut out).

If you want to restart a debate, please go back and reply to some 
serious post in the thread - don't hijack mine for your own evil 
purposes and cut out the good parts - did you even see the movie?

George Sakkis wrote:
  You keep using that phrase. I don't think it means what you think it
  means.

[Vizzini has just cut the rope The Dread Pirate Roberts is climbing up]
Vizzini: HE DIDN'T FALL? INCONCEIVABLE.
Inigo Montoya: You keep using that word. I do not think it means what 
you think it means.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling a function with unknown arguments?

2007-03-07 Thread Tombo
On Mar 7, 10:55 pm, Rob [EMAIL PROTECTED] wrote:
 I can get a list of a function's arguments. def bob(a, b):

 ... return a+b
 ... bob.func_code.co_varnames

 ('a', 'b')

 Let's say that I also have a dictionary of possible arguments for this
 function.

  possible = {'a':10, 'b':5, 'c':-3}

 How do I proceed to call bob(a=10, b=5) with this information?

 Thanks!

You can do this with a list comprehension:
bob(*[possible[k] for k in bob2.func_code.co_varnames])

The LC creates a list of arg values in the same order as the var names
for the function. Putting a * before the list when you call bob()
turns that list into it's arguments.


Alternativly (and this may not be useful) you can call a function with
a dictionary of arguments:

def bob(**kwargs):
print kwargs

possible = {'a' : 10, 'b':5, 'c':-3}


 bob(**possible)
{'a': 10, 'c': -3, 'b': 5}


Tom

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


Re: is it possible to give an instance a value?

2007-03-07 Thread manstey
Thanks everyone for your replies. The language is Cache Object Script,
a language used in  Intersystems Relational Dbase.

I think egbert's answer provides the simplest answer. It allows our
python interface to Cache to be almost identical to Cache Object
Script, with simeply the addition of (), which we prefer to .val
or .data for various reasons.

Using the example .type was a mistake, as I meant simply any metadata
about a value. If we make the instance callable, then we can have:

instance()
instance.calculated
instance.type
instance.whatever
instance.save()
etc

thanks.

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


Flatten a two-level list -- one liner?

2007-03-07 Thread Sergio Correia
Hi,

I'm looking for an easy way to flatten a two level list like this

spam = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

Into something like
eggs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

There are *no* special cases (no empty sub-lists).

I have found two ways:

1) Accumulator
eggs = []
for x in eggs:
   eggs.extend(x)

2) Reduce
eggs = reduce(lambda x, y: x+y, spam)

I feel the 1st way is too cumbersome (three lines), and although I
like the 2nd way (except for the lambda part), I understand reduce is
discouraged by Guido so I want to know if there is a Better Way(TM)
?

Any ideas?

Thanks,
Sergio

PS: Why does `sum` works only with numbers?
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter how to write

2007-03-07 Thread Gigs_
as I write my first gui program (text editor) I wanna ask you guys how 
to separate code in classes.?
Should I put in one class my menu and in another class text and 
scorllbars etc?

or something else?


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


  1   2   >