PyCon: Two weeks left for early-bird registration

2005-12-21 Thread A.M. Kuchling
Early bird registration for PyCon ends on December 31st, so there's
now slightly less than two weeks left. To register, go to:

http://us.pycon.org/TX2006/Registration

You can still register after Dec. 31st, but the cost will go up by
US$65 (US$25 for students).

Course outlines have now been posted for all the
tutorials; see
http://wiki.python.org/moin/PyCon2006/Tutorials

All of the PyCon tutorials are still open for new registrations, but
space is limited, and I suspect they'll all be filled up by the time
early-bird registration closes.

Don't forget to book your hotel room, too:
http://us.pycon.org/Addison/Hotels


A.M. Kuchling
Chair, PyCon 2006
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Steve Holden
Kent Johnson wrote:
 Luis M. Gonzalez wrote:
 
I don't think Pierre (Karrigell's creator) is awared of licenses and
legal issues.
Perhaps you can tell us what's the problem with GPL and, if possible,
propose an alternative...
 
 
 OK I'll try. First let me say I have no interest in a licensing flame war, 
 there are valid 
 reasons why an author might prefer one license over another and certainly 
 there are good 
 reasons to choose GPL. However the work I do is commercial and proprietary 
 and I doubt I 
 could get approval to release it under GPL. So I am restricted to projects 
 with more 
 liberal licenses such as MIT, BSD and Apache licenses. These allow 
 closed-source 
 distribution of products based on them.
 
I see the GPL is a problem in this environment, and you are clearly 
aware of the issues it raises. Do be aware, though, that not all GPL 
authors are rabid communists, and some will consider licensing to you 
under other licenses if you ask them. It's always worth asking, as some 
authors have chosen GPL in a somewhat uninformed way rather than as a 
political statement (you'll notice I too am trying to avoid the flame wars).

 Certainly it is within an author's rights to prohibit use of his code in 
 closed source 
 products, as the author of Karrigell has done by choosing GPL and I respect 
 this decision. 
 Unfortunately this makes it impossible for me to consider using Karrigell in 
 my work. I 
 recently needed a stand-alone web server for a small in-house project that 
 might possibly 
 be distributed to business partners or become a product some day. I chose 
 CherryPy in part 
 because its license allows this. I would have considered Karrigell if it had 
 a different 
 license.

As we say in Yorkshire, You get nowt if you don't ask.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Why my thread can't access the global data?

2005-12-21 Thread Antoon Pardon
Op 2005-12-21, ddh schreef [EMAIL PROTECTED]:
 Hi,
   I got a problem. I use a 'select' in a loop in the main thread, and
 when select return, a new thread will be created to handle the network
 event. And if the client send some special string, the thread will
 change a global flag to false, so the loop in the main thread will
 break. But it never work.

 Below is the code:
 - s.py (the server) --
 import socket
 import select
 import thread
 import sys

 go_on = True

 def read_send(s):
 s.setblocking(1)
 str = s.recv(1024)
 print 'recv:', str
 s.send(str)
 s.close()
 if (str == 'quit'):
 go_on = False
 print 'User quit...with go_on =', go_on
 return

 [ ... ]

It has nothing to do with threads. If you assign to a name in
a function, that name will be treated as a local variable. So
the go_on = False in read_send will not affect the global go_on.

If you want to rebind global names in a function you have to use
the global statement. So your function would start:


   def read_send(s):
   global go_on
   s.setblocking(1)
   ...

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


Re: ANNOUNCE; Try python beta

2005-12-21 Thread Eric
On 20 December 2005, Mike Meyer wrote:
 Ok, I've given it the interface I want, and made it less of an
 attractive nuisance.

 http://www.mired.org/home/mwm/try_python/ is now ready for people to
 play with. There's no tutorial information on it yet, that's the next
 thing to do. However, I won't be able to work on it for a while, so if
 you want to make suggestions about what that should look like, all
 such suggestions will be given proper consideration.

I'm not sure about everyone else, but I find the big warnings about
CSS and JavaScript almost as annoying as the fact that it doesn't do
anything.  At all, even with JavaScript enabled.  Then again, my main
browser is elinks, so my opinion is somewhat biased.  

If you get it working in Lynx, supporting other browsers should be
easier than the other posts make this solution sound.

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


Re: Why my thread can't access the global data?

2005-12-21 Thread ddh
Thank you very much.
I am a newbie for python :-)


Antoon Pardon wrote:

 It has nothing to do with threads. If you assign to a name in
 a function, that name will be treated as a local variable. So
 the go_on = False in read_send will not affect the global go_on.

 If you want to rebind global names in a function you have to use
 the global statement. So your function would start:


def read_send(s):
global go_on
s.setblocking(1)
...
 
 -- 
 Antoon Pardon

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


Re: Xah's Edu Corner: Responsible Software Licensing

2005-12-21 Thread robic0
On Mon, 19 Dec 2005 10:05:59 GMT, Roedy Green
[EMAIL PROTECTED] wrote:

On Sun, 18 Dec 2005 18:42:52 -0800, robic0 wrote, quoted or indirectly
quoted someone who said :

If the software opens a file and is in the middle of writing to it,
then the user dumps the power to the machine and ends up having to
reformat, thereby losing all his data, at what point does the 
liability stop? And how is fault proven or dished out? Does the
law specifically state repeatability in its language?

It would expect it to work much the way a car works.  If you have an
accident, that is your fault. If the fuel pump is badly designed so it
catches fire, that in the manufacturers fault.

You'ld have to prove the fuel pump caused your accident wouldn't you?
I'm reversed when it comes to engineering. I always assume defects
when buss loads of people are killed. 
If software ever guards lives that isin't certified then its a 
manufacturing defect. That is imbedded software though. Not the
for public consumption. I know that fly-by-wire military software 
has 100 levels of precaution. Hey but its a 7 million dollar plane
and a 700 billion dollar budget. The written requirements for a
single design is a book 5 inches thick. Ever see that for 
Joe bullshit software designer?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes:
  However the work I do is commercial and proprietary and I doubt
  I could get approval to release it under GPL. 
 I see the GPL is a problem in this environment, and you are clearly
 aware of the issues it raises. Do be aware, though, that not all GPL
 authors are rabid communists, and some will consider licensing to you
 under other licenses if you ask them. It's always worth asking, as
 some authors have chosen GPL in a somewhat uninformed way rather than
 as a political statement (you'll notice I too am trying to avoid the
 flame wars).

I'm trying to avoid flame wars too, but my take on this is that Kent's
reading is a little too restrictive and the GPL isn't really a problem
in this situation unless he's actually modifying Karrigell itself,
rather than writing applications that run under it.  I'm not trying to
advocate Karrigell (I browsed the docs for a minute and it looks nice
but I have no experience with it) but I don't see the GPL as an
obstacle to that type of usage.  All kinds of proprietary applications
are written and distributed all the time to run under the GPL'd Linux
kernel and Karrigell apps don't seem too terribly different from that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Pierre Quentel
Hello all,

I am Karrigell's author. I have chosen the GPL licence almost at random
(I saw that the Python licence was GPL-compatible), so I don't mind
switching to another Open Source licence if the GPL is liable to cause
problems. Which one would you advice : BSD ? Python licence ? another ?

Regards,
Pierre

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Pierre Quentel [EMAIL PROTECTED] writes:
 I am Karrigell's author. I have chosen the GPL licence almost at random
 (I saw that the Python licence was GPL-compatible), so I don't mind
 switching to another Open Source licence if the GPL is liable to cause
 problems. Which one would you advice : BSD ? Python licence ? another ?

My own hope (not shared by everyone obviously) is that you will stay
with the GPL, but make clear that applications that simply run under
Karrigell but don't modify the Karrigell code aren't subjected to the
GPL.  That should satisfy Kent's concerns.

See http://www.gnu.org/philosophy/pragmatic.html for some reasons to
use the GPL.

French version: http://www.gnu.org/philosophy/pragmatic.fr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to lock a file in ftp site

2005-12-21 Thread Kinsley Turner


 I've come across this problem - instead of uploading the file to it's
 
 intended directory, upload it to a temp directory, with a unique name
 (say ummddhhmmss where u is username and the rest are
 obvious) and then *rename* it to it's correct name in the real
 destination directory. Do the move in a try... except block and if it
 fails, take evasive action.
 
 In FTP a rename (i.e. move) is usually an atomic action but an upload is
 not. You have an unavoidable race condition here trying to lock a file
 (even if ftp allowed it) but with the method described above, you can
 avoid it, but get the same effect.

This is a good method for transferring files, it handles broken-transfers
especially well (if something on the other end is waiting for a particular 

filename.)

But I think it just moves the locking problem from the
upload to a rename.  What happends if two clients try to rename their
files at a half-second interval: both succeed, but the first-clients 
changes
are clobbered.  Actually, speaking of atomic functions, maybe you could
use directory creation instead of a rename, because only one directory
creation can succeed.  This might be able to be incorperated into some
sort of locking mechanism.

cheers,
-kt























(obnoxious corporate .sig below)
--




Please consider our environment before printing this email.

WARNING - This email and any attachments may be confidential. If received in 
error, please delete and inform us by return email. Because emails and 
attachments may be interfered with, may contain computer viruses or other 
defects and may not be successfully replicated on other systems, you must be 
cautious. Westpac cannot guarantee that what you receive is what we sent. If 
you have any doubts about the authenticity of an email by Westpac, please 
contact us immediately.

It is also important to check for viruses and defects before opening or using 
attachments. Westpac's liability is limited to resupplying any affected 
attachments.


This email and its attachments are not intended to constitute any form of 
financial advice or recommendation of, or an offer to buy or offer to sell, any 
security or other financial product. We recommend that you seek your own 
independent legal or financial advice before proceeding with any investment 
decision.

Westpac Institutional Bank is a division of Westpac Banking Corporation, a 
company registered in New South Wales in Australia under the Corporations Act 
2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the 
Financial Services Authority and is registered at Cardiff in the United Kingdom 
as Branch No. BR 106. Westpac operates in the United States of America as a 
federally chartered branch, regulated by the Office of the Comptroller of the 
Currency.

Westpac Banking Corporation ABN 33 007 457 141.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Steve Holden
Paul Rubin wrote:
 Steve Holden [EMAIL PROTECTED] writes:
 
However the work I do is commercial and proprietary and I doubt
I could get approval to release it under GPL. 

I see the GPL is a problem in this environment, and you are clearly
aware of the issues it raises. Do be aware, though, that not all GPL
authors are rabid communists, and some will consider licensing to you
under other licenses if you ask them. It's always worth asking, as
some authors have chosen GPL in a somewhat uninformed way rather than
as a political statement (you'll notice I too am trying to avoid the
flame wars).
 
 
 I'm trying to avoid flame wars too, but my take on this is that Kent's
 reading is a little too restrictive and the GPL isn't really a problem
 in this situation unless he's actually modifying Karrigell itself,
 rather than writing applications that run under it.  I'm not trying to
 advocate Karrigell (I browsed the docs for a minute and it looks nice
 but I have no experience with it) but I don't see the GPL as an
 obstacle to that type of usage.  All kinds of proprietary applications
 are written and distributed all the time to run under the GPL'd Linux
 kernel and Karrigell apps don't seem too terribly different from that.

Indeed. But most software authors aren't lawyers and aren't likely to 
trust their own judgment about these matters unless the situation is 
pretty unambiguous.  I suspect this may be evidence that Microsoft's 
viral propaganda has had some effect.

In this case I agree there's likely to be a clear separation between 
server and content that will allow Kent to distribute an unmodified 
Karrigell and a separate proprietary content bundle without 
interference, but it's too late (at least for that project) now.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes:
 Indeed. But most software authors aren't lawyers and aren't likely to
 trust their own judgment about these matters unless the situation is
 pretty unambiguous.  I suspect this may be evidence that Microsoft's
 viral propaganda has had some effect.

Hmm, good point.

 In this case I agree there's likely to be a clear separation between
 server and content that will allow Kent to distribute an unmodified
 Karrigell and a separate proprietary content bundle without
 interference, but it's too late (at least for that project) now.

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


Re: Wanted: binary of OpenCV Python extension module for Windows

2005-12-21 Thread Claudio Grondi
Claudio Grondi wrote:
 
 OpenCV means Intel® Open Source Computer Vision Library. It is a 
 collection of C functions and a few C++ classes that implement some 
 popular Image Processing and Computer Vision algorithms.
 OpenCV library is mainly aimed at real time computer vision.  Some 
 example areas would be Human-Computer Interaction (HCI); Object 
 Identification, Segmentation and Recognition; Face Recognition; Gesture 
 Recognition; Motion Tracking, Ego Motion, Motion Understanding; 
 Structure From Motion (SFM);  and Mobile Robotics:
 
 Overview:
   http://www.intel.com/technology/computing/opencv/overview.htm
 Download:
 
 http://heanet.dl.sourceforge.net/sourceforge/opencvlibrary/chopencv-2.3.0-win.zip
  
 
 
 OpenCV provides a Python wrapper in
  OpenCV\interfaces\swig\python\
 directory, but I have no idea how to turn it into a Windows binary yet.
 
 I have downloaded SWIG, but it creates files which are already in the 
 directory, so it was the wrong idea. Probably I have to compile the 
 _cv.cpp as a DLL, but my MS .NET 2003 Visual C++ compiler throws tons of 
 error messages at me when I create an empty project, telling it should 
 create an DLL out of _cv.cpp and then try to compile it.
 
 It would be so nice to have this Computer Vision Library as extension 
 module in my modules library.
 
 Any hints how to achieve it?
 
 Claudio

For your information:

The conclusion from contacting the authors of the Python wrapper for 
OpenCV is, that there is currently only support for Linux, but no for 
the Windows platform available.
The
http://heanet.dl.sourceforge.net/sourceforge/opencvlibrary/chopencv-2.3.0-win.zip
dowload is outdated, so anyone willing to dig into this deeper should 
access the CVS repository for the latest additions and changes.
Anyone interested in this subject and especially in the available 
distutils setup script (fails to build the Python wrapper on Windows 
with .NET 2003) from the CVS is welcome to contact me per email.

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


Is it possible to use python to unit test C++ code?

2005-12-21 Thread sylcheung
Is it possible to use python to unit test C++ code? If yes, is there
any example available?

Thank you.

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


Re: type 'slice' is not an acceptable base type

2005-12-21 Thread Antoon Pardon
Op 2005-12-21, Michael Hoffman schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:

 Traceback (most recent call last):
   File stdin, line 1, in ?
   File vslice.py, line 48, in ?
 class iterslice(slice):
 TypeError: Error when calling the metaclass bases
 type 'slice' is not an acceptable base type

 Searching for not an acceptable base type in the Python source reveals 
 that this exception is produced when the proposed base type doesn't have 
 Py_TPFLAGS_BASETYPE set.

 So what is going on. I thought the class vs type
 distinction was eliminated in order to be able
 to subclass base types. So why doesn't this work?

 slice.__base__ == object. It's the basetype flag issue. You could 
 propose a patch to make it subclassable.

I'll keep this is mind. It'll have to wait for after the holidays
though.

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


Parsing a date-time string?

2005-12-21 Thread Tim N. van der Leeuw
Hi,

I want to parse strings containing date-time, which look like the
following:

 Mon Dec 19 11:06:12:333 CET 2005

That's a problem for strptime it seems, b/c I cannot find any
format-spec for the milliseconds-part in here. (I'm also not sure about
the validity of the tz part, but ...)

As an aside, the dates are all in english while my PC might have a
dutch locale -- not even sure about what Python would consider the
current locale.
So that's an extra obstacle to parsing these dates.

The datetime module doesn't seem to provide a better solution either.

What I want to get is some sort of sortable date; either as a number or
(if nothing else) as a string in ISO8601 format.
(But I want to avoid doing too many string manipulations on my input
dates; and changing the dateformat of the input-source will be hard if
at all justifiable.)


Any help is appreciated.

Cheers,

--Tim

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


Globals, Locals Dictionaries + Callbacks Question

2005-12-21 Thread Faisal Alquaddoomi
Hello,

I'm having a bit of trouble isolating my scripts from each other in my 
embedded Python interpreter, so that their global namespaces don't get 
all entangled. I've had some luck with PyRun_FileEx(), as you can 
specify dictionaries to use for the globals and locals, but it seems 
that you can't do the same for PyEval_CallObject() (which i use for 
calling the callbacks previously registered by scripts run via 
PyRun_FileEx()). Is there any way to substitute the current global/local 
dictionaries, run the callback, then switch back to the default? It 
would be just as good if I could switch between several sets of global 
variable dictionaries, one for each script; unfortunately, the 
documentation is less than informative on this point (there isn't even a 
formal defintion for PyEval_CallObject()). Also, I'm aware that eval() 
and exec() allow you to pass in global/local dictionaries, but I think 
it'd be a bit wasteful to drop into Python, run exec(), then have that 
call my callback, rather than just calling the callback directly from 
the host program.

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


scipy.stats.itemfreq: overflow with add.reduce

2005-12-21 Thread Hans Georg Krauthaeuser
Hi All,

I was playing with scipy.stats.itemfreq when I observed the following 
overflow:

In [119]:for i in [254,255,256,257,258]:
.:l=[0]*i
.:print i, stats.itemfreq(l), l.count(0)
.:
254 [ [  0 254]] 254
255 [ [  0 255]] 255
256 [ [0 0]] 256
257 [ [0 1]] 257
258 [ [0 2]] 258

itemfreq is pretty small (in stats.py):

--
def itemfreq(a):
 
Returns a 2D array of item frequencies.  Column 1 contains item values,
column 2 contains their respective counts.  Assumes a 1D array is passed.

Returns: a 2D frequency table (col [0:n-1]=scores, col n=frequencies)

 scores = _support.unique(a)
 scores = sort(scores)
 freq = zeros(len(scores))
 for i in range(len(scores)):
 freq[i] = add.reduce(equal(a,scores[i]))
 return array(_support.abut(scores, freq))
--

It seems that add.reduce is the source for the overflow:

In [116]:from scipy import *

In [117]:for i in [254,255,256,257,258]:
.:l=[0]*i
.:print i, add.reduce(equal(l,0))
.:
254 254
255 255
256 0
257 1
258 2

Is there any possibility to avoid the overflow?

BTW:
Python 2.3.5 (#2, Aug 30 2005, 15:50:26)
[GCC 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)] on linux2

scipy_version.scipy_version  -- '0.3.2'


Thanks and best regards
Hans Georg Krauthäuser
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a date-time string?

2005-12-21 Thread Fuzzyman
Quick response - there is a DateUtil module with a *very* flexible
string-to-date parser. It will almost certainly do what you want :

http://labix.org/python-dateutil

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


How to check if a string is an int?

2005-12-21 Thread [EMAIL PROTECTED]
How do I check if a string contains (can be converted to) an int? I
want to do one thing if I am parsing and integer, and another if not.

/David

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


Re: Is it possible to use python to unit test C++ code?

2005-12-21 Thread Alex Stapleton

On 21 Dec 2005, at 09:33, [EMAIL PROTECTED] wrote:

 Is it possible to use python to unit test C++ code? If yes, is there
 any example available?

 Thank you.

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

You could use Python to unittest a Python module written in C++ I  
suppose. I guess that would probably work. I suspect that you would  
get better/more accurate/reliable results by writing your tests in C+ 
+ as well though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: putting checkbuttons in a listbox

2005-12-21 Thread Martin Franklin
valen1260 wrote:
 I'd like to have a multicolumn listbox, with one column being a list of 
 items and the other being a list of checkbuttons.  The user could check 
 his favorites and then shorten the list to show only the checked items.
 
 I have implemented the MultiListbox at 
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52266 .  I then 
 tried attaching the checkbuttons to a listbox object.  To get them to 
 display, I had to pack them, but in packing them, they just disregard 
 the scrollable listbox and take as much room as needed.
 
 Has anyone implemented anything like this?  Is there a way to put 
 checkbuttons in a fixed-height, scrollable listbox or similar structure?


snipped from the above recipe :-



Discussion:

The resulting widget is lightweight, fast, and very easy to use. The main
limitation is that only text is supported which is a fundamental limitation
of the Listbox.

In this implementation, only single-selection is allowed but it could be
extended to multiple selection. User-resizeable columns and auto-sorting by
clicking on the column label should also be possible.

Auto-scrolling while dragging Button-1 was disabled because this was breaks
the synchronization between the lists. However, scrolling with Button-2 
works
fine.



so you cannot put anything other than text into a standard Tk Listbox
however you could try using a non-standard table widget see here for 
more details :-

http://tkinter.unpythonic.net/wiki/Widgets


Martin



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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Pierre Quentel
I definitely don't want to invent another licence, there are enough of
them already !
Pierre

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


Re: How to check if a string is an int?

2005-12-21 Thread Erik Max Francis
[EMAIL PROTECTED] wrote:

 How do I check if a string contains (can be converted to) an int? I
 want to do one thing if I am parsing and integer, and another if not.

try:
x = int(aPossibleInt)
... do something with x ...
except ValueError:
... do something else ...

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   May it not be that, at least, the brighter stars are like our Sun,
   the upholding and energizing centres of systems of worlds, adapted to
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Ben Sizer
Paul Rubin wrote:
 Pierre Quentel [EMAIL PROTECTED] writes:
  I am Karrigell's author. I have chosen the GPL licence almost at random
  (I saw that the Python licence was GPL-compatible), so I don't mind
  switching to another Open Source licence if the GPL is liable to cause
  problems. Which one would you advice : BSD ? Python licence ? another ?

 My own hope (not shared by everyone obviously) is that you will stay
 with the GPL, but make clear that applications that simply run under
 Karrigell but don't modify the Karrigell code aren't subjected to the
 GPL.  That should satisfy Kent's concerns.

Unfortunately, that doesn't really satisfy the GPL's concerns. The work
arguably contains or is derived from Karrigell, which is explicitly
covered in section 2b of the GPL. If you start excluding key clauses
from the GPL, then there's little point using it.

To cut a long story short, and to avoid quibbling over the details of
how a license designed with the low-level mechanics of C-style programs
and libraries in mind actually applies to a language like Python with
very loose coupling, I'll just say that this sort of situation is
exactly what the LGPL exists for. I would suggest the author adopts the
LGPL as a good compromise between the community benefits of GPL and the
user benefits of, say, BSD or zlib licenses.

-- 
Ben Sizer

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


Re: scipy.stats.itemfreq: overflow with add.reduce

2005-12-21 Thread Hans Georg Krauthaeuser
Hans Georg Krauthaeuser schrieb:
 Hi All,
 
 I was playing with scipy.stats.itemfreq when I observed the following 
 overflow:
 
 In [119]:for i in [254,255,256,257,258]:
.:l=[0]*i
.:print i, stats.itemfreq(l), l.count(0)
.:
 254 [ [  0 254]] 254
 255 [ [  0 255]] 255
 256 [ [0 0]] 256
 257 [ [0 1]] 257
 258 [ [0 2]] 258
 
 itemfreq is pretty small (in stats.py):
 
 --
 def itemfreq(a):
 
 Returns a 2D array of item frequencies.  Column 1 contains item values,
 column 2 contains their respective counts.  Assumes a 1D array is passed.
 
 Returns: a 2D frequency table (col [0:n-1]=scores, col n=frequencies)
 
 scores = _support.unique(a)
 scores = sort(scores)
 freq = zeros(len(scores))
 for i in range(len(scores)):
 freq[i] = add.reduce(equal(a,scores[i]))
 return array(_support.abut(scores, freq))
 --
 
 It seems that add.reduce is the source for the overflow:
 
 In [116]:from scipy import *
 
 In [117]:for i in [254,255,256,257,258]:
.:l=[0]*i
.:print i, add.reduce(equal(l,0))
.:
 254 254
 255 255
 256 0
 257 1
 258 2
 
 Is there any possibility to avoid the overflow?
 
 BTW:
 Python 2.3.5 (#2, Aug 30 2005, 15:50:26)
 [GCC 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)] on linux2
 
 scipy_version.scipy_version  -- '0.3.2'
 
 
 Thanks and best regards
 Hans Georg Krauthäuser
After some further investigation:

In [150]:add.reduce(array(equal([0]*256,0),typecode='l'))
Out[150]:256

In [151]:add.reduce(equal([0]*256,0))
Out[151]:0

The problem occurs with arrays with typecode 'b' (as returned by equal).

Workaround patch for itemfreq is obvious, but ... is it a bug or a feature?

regards
Hans Georg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Ben Sizer [EMAIL PROTECTED] writes:
 Unfortunately, that doesn't really satisfy the GPL's concerns. The work
 arguably contains or is derived from Karrigell,

I don't see that.  The web app gets run by Karrigell like a CGI script
is run by Apache, like a Linux app is run by the Linux kernel.  The
Linux kernel is GPL but that doesn't mean every Linux app that calls
through the kernel through its documented API is affected.  The Linux
kernel GPL only comes into play if you start modifying the kernel, not
writing programs that use it.  

 which is explicitly covered in section 2b of the GPL. If you start
 excluding key clauses from the GPL, then there's little point using it.

There should be no exclusion.

 To cut a long story short, and to avoid quibbling over the details of
 how a license designed with the low-level mechanics of C-style programs
 and libraries in mind actually applies to a language like Python with
 very loose coupling, I'll just say that this sort of situation is
 exactly what the LGPL exists for. 

The LGPL has fallen into some disfavor at the FSF, and I don't see
Karrigell as a library.  The application is not an integrated blob
combining Karrigell and user code, from what I can tell.  Rather, the
user code is run under Karrigell's control, like Karrigell itself
is run under the Python interpreter.

 I would suggest the author adopts the LGPL as a good compromise
 between the community benefits of GPL and the user benefits of, say,
 BSD or zlib licenses.

But that doesn't gain the community benefits of the GPL since it
foregoes the possibility of users improving Karrigell by incorporating
other GPL'd code into it and distributing the improved version.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Richie Hindle

[Pierre]
 I am Karrigell's author. I have chosen the GPL licence almost at random
 (I saw that the Python licence was GPL-compatible), so I don't mind
 switching to another Open Source licence if the GPL is liable to cause
 problems. Which one would you advice : BSD ? Python licence ? another ?

Well done on being open-minded!

You will hear valid arguments for GPL, LGPL, BSD and other licenses (though
the Python license is unsuitable for anything other than Python - see
http://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq)

A good solution would be multiple-licensing.  You state that the code is
(for example) triple-licensed under the GPL, LGPL and BSD licenses.  The
user of your code decides which license to obey.  It's no more work for you,
and you can please almost everyone (the only people you won't please are
those who believe that there is One True License, and frankly you should
ignore them - it's your code).

The only downside of allowing people to choose the BSD license rather than
the GPL is that potentially someone can choose the BSD license, improve
Karrigell, ship their product based on the improved code, and not give those
improvements back to the community.  But the Python license allows for this
too, and Python hasn't suffered for it.  IMO choosing a BSD license will get
you more users than GPL, and the benefits of that will outweigh the
potential downside.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Richie Hindle [EMAIL PROTECTED] writes:
 A good solution would be multiple-licensing.  You state that the
 code is (for example) triple-licensed under the GPL, LGPL and BSD
 licenses.  The user of your code decides which license to obey.
 It's no more work for you, and you can please almost everyone (the
 only people you won't please are those who believe that there is One
 True License, and frankly you should ignore them - it's your code).

That's silly, you might as well just use BSD instead of triple
licensing like that.  

 The only downside of allowing people to choose the BSD license
 rather than the GPL is that potentially someone can choose the BSD
 license, improve Karrigell, ship their product based on the improved
 code, and not give those improvements back to the community. 

Another downside to BSD is that it becomes impermissible to improve
Karrigell by transplanting GPL code into it from other programs.  Yet
another downside is that it leads some potential contributors to not
bother getting involved with such projects.  (On the other hand, it
possibly attracts some different potential contributors).

 But the Python license allows for this too, and Python hasn't
 suffered for it.

That Python hasn't suffered for it is a questionable assertion.

 IMO choosing a BSD license will get you more users than GPL, and
 the benefits of that will outweigh the potential downside.

Of course anyone is entitled to hold any opinion they choose.  I have
to say both notions expressed there (that BSD will attract more users,
and that merely attracting more users produces such big benefits) are
questionable.  As for me, for something like this, I'd be more
interested in attracting more contributors than in merely attracting
more users with me doing all the work.  But what Karrigell's author
wants is of course purely up to the him.
-- 
http://mail.python.org/mailman/listinfo/python-list


coverting EST to PST

2005-12-21 Thread Narendra
Hi All,

i got a problem. I need to convert time from EST standard to PST
standard.

Thu, 15 Dec 2005 09:24:19 -0500 to PST

this time i need to convert as PST time

is there any python code which helps me.

your help will be greatly apreciated.

Thanks,
Narendra

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


Guido at Google

2005-12-21 Thread JB
It seems that our master Guido van Rossum had an offer from google and 
he accepted it!!

long life to Guido  Goole ! many things to come ;)

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


Re: How to check if a string is an int?

2005-12-21 Thread Steven D'Aprano
On Wed, 21 Dec 2005 02:12:35 -0800, [EMAIL PROTECTED] wrote:

 How do I check if a string contains (can be converted to) an int? I
 want to do one thing if I am parsing and integer, and another if not.

Okay, this has got to be homework, surely. This is the third, maybe the
fourth, question on this topic in a week or so :-)

In Python, the best solution to most how can I check if X is a something
questions is usually the Nike motto: Just Do It.

# s is some arbitrary string object
try:
n = int(s)
print Integer %d % n
except ValueError:
print Not an integer %s % s

try...except blocks are cheap in Python.


-- 
Steven.

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Kent Johnson
Steve Holden wrote:
 Paul Rubin wrote:
 I'm trying to avoid flame wars too, but my take on this is that Kent's
 reading is a little too restrictive and the GPL isn't really a problem
 in this situation unless he's actually modifying Karrigell itself,
 rather than writing applications that run under it.  I'm not trying to
 advocate Karrigell (I browsed the docs for a minute and it looks nice
 but I have no experience with it) but I don't see the GPL as an
 obstacle to that type of usage.  All kinds of proprietary applications
 are written and distributed all the time to run under the GPL'd Linux
 kernel and Karrigell apps don't seem too terribly different from that.

You may be right, I honestly don't know. Would your interpretation change if I 
wanted to 
distribute an app built with py2exe that bundles Karrigell and my code?

 Indeed. But most software authors aren't lawyers and aren't likely to 
 trust their own judgment about these matters unless the situation is 
 pretty unambiguous.  

That really is the issue as much as anything. Paul has raised some good 
questions for 
which I don't have good answers. Maybe using Karrigell is analogous to writing 
an app to 
run on Linux. OTOH maybe it is more like linking to a library. I could ask the 
author for 
clarification - which I would then have to document in a form acceptable to my 
own 
company's lawyers. Or I could choose to use a product that doesn't leave any 
doubt that I 
can distribute it as I like in a proprietary product.

 I suspect this may be evidence that Microsoft's 
 viral propaganda has had some effect.

Not in my case, at least. I have been avoiding GPL products at work for many 
years, much 
longer than Microsoft has been telling me to do so.

 
 In this case I agree there's likely to be a clear separation between 
 server and content that will allow Kent to distribute an unmodified 
 Karrigell and a separate proprietary content bundle without 
 interference, but it's too late (at least for that project) now.

Maybe next time...

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Raffaele Salmaso
Pierre Quentel ha scritto:
 Hello all,
 
 I am Karrigell's author. I have chosen the GPL licence almost at random
 (I saw that the Python licence was GPL-compatible), so I don't mind
 switching to another Open Source licence if the GPL is liable to cause
 problems. Which one would you advice : BSD ? Python licence ? another ?
I think you should use the BSD or the Python License.
I've choose the BSD for my works, with these clauses (my intentions are 
clearly stated, so no misinterpretation should be done):

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.
  3. If the binary program depends on a modified version of this package,
 you are encouraged to publicly release the modified version of this
 package.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS 
IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

And it is almost the same of CherryPy, which you use.

-- 
()_() | Ho un cervello, non sono analfabeta e non sento| +
(o.o) | l'irrefrenabile bisogno di deturpare la mia lingua | +---+
'm m' | madre con K ed abbreviazioni...  |  O  |
(___) | K.K.K (Kill the Key Klub)|
 raffaele punto salmaso at gmail punto com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to check if a string is an int?

2005-12-21 Thread Neuruss
Can't we just check if the string has digits?
For example:

 x = '15'
 if x.isdigit():
print int(x)*3


45


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


Re: Guido at Google

2005-12-21 Thread Fuzzyman
That's potentially very good news. (Or slightly sinister -depending on
your paranoia levels).

You got any references on that ?

I was just thinking that the open source offerings from google are
actually pretty pitiful - considering the time investment they have put
into developing software systems. (Summer of Code not-withstanding of
course).

I wonder if this heralds google finally upgrading from Python 2.2 ;-)

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Arthur Clune
Kent Johnson wrote:
 
 OK I'll try. First let me say I have no interest in a licensing flame war, 
 there are valid 
 reasons why an author might prefer one license over another and certainly 
 there are good 
 reasons to choose GPL. However the work I do is commercial and proprietary 
 and I doubt I 
 could get approval to release it under GPL. So I am restricted to projects 
 with more 
 liberal licenses such as MIT, BSD and Apache licenses. These allow 
 closed-source 
 distribution of products based on them.
 

As long as the author holds copyright on all the code, he can release it to you 
under
any license he wants, as well as via GPL to the world (this is how MySQL and 
SleepyCat
opterate).

So you could, for example, offer him X pounds/dollars/euros for a BSD version + 
support
etc.

Arthur

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


Re: How to check if a string is an int?

2005-12-21 Thread [EMAIL PROTECTED]
It's not homework in my case, I don't know about the others :)

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


Re: How to check if a string is an int?

2005-12-21 Thread Juho Schultz
Neuruss wrote:
 Can't we just check if the string has digits?
 For example:
 
 
x = '15'
if x.isdigit():
 
   print int(x)*3
 
   
 45
 
 
No, we can't. '-15' has non-digits but is a valid int.

Another point is that the try-except
can also be used for string-to-float conversion

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


Re: Globals, Locals Dictionaries + Callbacks Question

2005-12-21 Thread Steve Holden
Faisal Alquaddoomi wrote:
 Hello,
 
 I'm having a bit of trouble isolating my scripts from each other in my 
 embedded Python interpreter, so that their global namespaces don't get 
 all entangled. 

[tales of woe ...]

Would it help to use PyNewInterpreter to create subinterpreters for each 
of the different scripts?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Fuzzyman
BSD license is good. It requires that your copyright notice be included
with any derivative works - but otherwise lets users create and
distribute derivatives how they see fit. The version I use is at
http://www.voidspace.org.uk/python/license.shtml (which links to the
version at the OSI).

The MIT license is even *less* restrictive. I would use one or other of
these two.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: ANNOUNCE; Try python beta

2005-12-21 Thread Maravilloso
I'm afraid that I've spoiled the try_python working by means of
executing the sentence:

open(try.py).write(\n)

Sorry. I hope it don't be difficult for you to restore the module again
to the default folder.

In any case, I think it should include some control for malicious code
like that one.

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


Re: How to check if a string is an int?

2005-12-21 Thread Steven D'Aprano
On Wed, 21 Dec 2005 03:37:27 -0800, Neuruss wrote:

 Can't we just check if the string has digits?

Why would you want to?


 For example:
 
 x = '15'
 if x.isdigit():
   print int(x)*3

15 is not a digit. 1 is a digit. 5 is a digit. Putting them together to
make 15 is not a digit.


If you really wanted to waste CPU cycles, you could do this:

s = 1579
for c in s:
if not c.isdigit():
print Not an integer string
break
else:
# if we get here, we didn't break
print Integer %d % int(s)


but notice that this is wasteful: first you walk the string, checking each
character, and then the int() function has to walk the string again,
checking each character for the second time.

It is also buggy: try s = -1579 and it will wrongly claim that s is not
an integer when it is. So now you have to waste more time, and more CPU
cycles, writing a more complicated function to check if the string can be
converted.


-- 
Steven.

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


Creating interactive command-line Python app?

2005-12-21 Thread planetthoughtful
Hello All,

Newbie to Python, and I'm wondering if it's possible to create a Python
console app that prompts for further input on the command line when run
(in Windows XP, if that's important)?

I've tried Googling, but the results are overwhelmingly about
interactive Python environments (IPython etc etc), instead of how to
achieve prompting at the command line when running your own Python app.

Any help appreciated!

Much warmth,

planetthoughtful

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


Re: How to check if a string is an int?

2005-12-21 Thread Kent Johnson
Steven D'Aprano wrote:
 On Wed, 21 Dec 2005 03:37:27 -0800, Neuruss wrote:
x = '15'
if x.isdigit():

  print int(x)*3
 
 
 15 is not a digit. 1 is a digit. 5 is a digit. Putting them together to
 make 15 is not a digit.

Maybe so, but '15'.isdigit() == True:

isdigit(...)
 S.isdigit() - bool

 Return True if all characters in S are digits
 and there is at least one character in S, False otherwise.

   '15'.isdigit()
True

though your other points are valid and I agree this is not the right solution 
to the OP.

Kent

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


Re: How to check if a string is an int?

2005-12-21 Thread Paul Rubin
Kent Johnson [EMAIL PROTECTED] writes:
 Maybe so, but '15'.isdigit() == True:
 
 isdigit(...)
  S.isdigit() - bool
 
  Return True if all characters in S are digits
  and there is at least one character in S, False otherwise.

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


Re: How to check if a string is an int?

2005-12-21 Thread Antoon Pardon
Op 2005-12-21, Steven D'Aprano schreef [EMAIL PROTECTED]:
 On Wed, 21 Dec 2005 03:37:27 -0800, Neuruss wrote:

 Can't we just check if the string has digits?

 Why would you want to?


 For example:
 
 x = '15'
 if x.isdigit():
  print int(x)*3

 15 is not a digit. 1 is a digit. 5 is a digit. Putting them together to
 make 15 is not a digit.

So? the isdigit method tests whether all characters are digits.

 '15'.isdigit()
True

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Kent Johnson
Paul Rubin wrote:
 Kent Johnson [EMAIL PROTECTED] writes:
 
You've lost me here. The server certainly would contain Karrigell
code, it wouldn't function without it. I don't understand the analogy
to GCC, the web site is not something that is compiled with
Karrigell. Karrigell is a library or framework that is an essential
part of the server. I don't know how I would write the app without
Karrigell.
 
 
 Let me ask it this way: suppose you used ASP instead.  As I understand
 ASP, it's like PHP except it's proprietary.  Would ASP's license be a
 problem?
 
 Maybe you're using the server to encompass too much.  If I have an
 Apache-based web site, then the web server is Apache.  If I have a
 Python CGI script that the Apache server runs, the CGI script is not
 the server--it's an application running under the server.  It would
 not be affected by the GPL if Apache used the GPL.  Karrigell scripts
 seem to me to work out about the same way.

You may be right, I don't know. In the case of CherryPy, my code is a bit more 
intimate 
with CP than a CGI is with Apache - I import CP modules, subclass CP classes 
and make 
calls to CP functions from my code. My guess is a Karrigell-based server would 
be similar.

Where would you draw the line? Suppose I want to use a GPLed library in my 
Python code, 
does that mean I have to distribute my code under the GPL if I distribute them 
together?

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


Re: Creating interactive command-line Python app?

2005-12-21 Thread Steve Holden
planetthoughtful wrote:
 Hello All,
 
 Newbie to Python, and I'm wondering if it's possible to create a Python
 console app that prompts for further input on the command line when run
 (in Windows XP, if that's important)?
 
 I've tried Googling, but the results are overwhelmingly about
 interactive Python environments (IPython etc etc), instead of how to
 achieve prompting at the command line when running your own Python app.
 
 Any help appreciated!
 
 Much warmth,
 
 planetthoughtful
 
Yes. Look at the raw_input() function:

   result = raw_input(What can I do for you? )
What can I do for you? Something
   result
'Something'
  

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: How to check if a string is an int?

2005-12-21 Thread Steven D'Aprano
On Wed, 21 Dec 2005 07:36:15 -0500, Kent Johnson wrote:

 Maybe so, but '15'.isdigit() == True:

Well I'll be a monkey's uncle.

In that case, the name is misleadingly wrong. I suppose it is not likely
that it could be changed before Python 3?

-- 
Steven

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


Re: How to check if a string is an int?

2005-12-21 Thread bonono

Steven D'Aprano wrote:
 If you really wanted to waste CPU cycles, you could do this:

 s = 1579
 for c in s:
 if not c.isdigit():
 print Not an integer string
 break
 else:
 # if we get here, we didn't break
 print Integer %d % int(s)


 but notice that this is wasteful: first you walk the string, checking each
 character, and then the int() function has to walk the string again,
 checking each character for the second time.

Wasteful enough that there is a specific built-in function to do just
this ?

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


Re: How to check if a string is an int?

2005-12-21 Thread Roy Smith
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 How do I check if a string contains (can be converted to) an int? I
 want to do one thing if I am parsing and integer, and another if not.
 
 /David

The most straight-forward thing is to try converting it to an int and see 
what happens.

try:
   int(s)
except ValueError:
   print sorry, '%s' isn't a valid integer % s
-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.splitext() and case sensitivity

2005-12-21 Thread rbt
Hi,

Is there a way to make os.path.splitext() case agnostic?

def remove_file_type(target_dir, file_type):
 for root, dirs, files in os.walk(target_dir):
 for f in files:
 if os.path.splitext(os.path.join(root, f))[1] in file_type:
 pass

remove_file_type(sysroot, ['.tmp', '.TMP'])

As you can see, the way I do it now, I place file extensions in a list. 
However, I'd like to able just to say '.tmp' and for that to work on any 
type of file that has tmp (no matter the case) in the extension.

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


Re: How to check if a string is an int?

2005-12-21 Thread Peter Hansen
Steven D'Aprano wrote:
 On Wed, 21 Dec 2005 07:36:15 -0500, Kent Johnson wrote:
Maybe so, but '15'.isdigit() == True:
 
 Well I'll be a monkey's uncle.
 
 In that case, the name is misleadingly wrong. I suppose it is not likely
 that it could be changed before Python 3?

That was my first thought too, Steven, but then I considered whether I'd 
think the same about the others: islower, isspace, istitle, isupper, 
isalnum, isalpha.

Some of those suffer from the same confusion, probably inspired by 
having written lots of C in the past, but certain istitle wouldn't be 
particularly useful on a single character.  isalnum and isalpha don't 
necessarily invoke the same mental awkwardness since, after all, what is 
an alpha?  It could just as well be read is this string alphabetic 
as is this character 'an alpha'.

Given that Python doesn't have a distinct concept of character (but 
merely a string of length one), having those routines operate on the 
entire string is probably pretty sensible, and I'm not sure that naming 
them isdigits() would be helpful either since then it would feel 
awkward to use them on length-one-strings.

-Peter

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


Re: os.path.splitext() and case sensitivity

2005-12-21 Thread Juho Schultz
rbt wrote:
 Hi,
 
 Is there a way to make os.path.splitext() case agnostic?
 
 def remove_file_type(target_dir, file_type):
 for root, dirs, files in os.walk(target_dir):
 for f in files:
 if os.path.splitext(os.path.join(root, f))[1] in file_type:
 pass
 
 remove_file_type(sysroot, ['.tmp', '.TMP'])
 
 As you can see, the way I do it now, I place file extensions in a list. 
 However, I'd like to able just to say '.tmp' and for that to work on any 
 type of file that has tmp (no matter the case) in the extension.
 
 Many thanks!!!


One solution would be to convert the extensions to lowercase
(or uppercase, if you prefer that)

if fileExtension.lower() == .tmp:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.splitext() and case sensitivity

2005-12-21 Thread Richie Hindle

[rbt]
 Is there a way to make os.path.splitext() case agnostic?
 
 def remove_file_type(target_dir, file_type):
  for root, dirs, files in os.walk(target_dir):
  for f in files:
  if os.path.splitext(os.path.join(root, f))[1] in file_type:
  pass
 
 remove_file_type(sysroot, ['.tmp', '.TMP'])

  def remove_file_type(target_dir, file_type):
  [...]
   if os.path.splitext(f)[1].lower() == file_type.lower():
   pass

remove_file_type(sysroot, '.tmp')

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When Python *Eggs* better than Python *distutils*?? What's Eggs?

2005-12-21 Thread Maurice LING
Xavier Morel wrote:

 [EMAIL PROTECTED] wrote:
 
 So basically Python Eggs precompiles and compresses
 binaries for you so you just have to load it to run
 your app?

 
 Nah, Eggs is a packaging system, what you don't have to do is 
 compile/configure, because the packaging does that for you. It also 
 handles things like pre-required packages (the packages that this 
 package uses), even though that doesn't always work atm.
 
 If you ever used a debian-based linux system, think of Eggs as a 
 Python-specific apt-get.
 
 The most advanced kind of language-specific installer atm is the Ruby 
 Gems packaging and distribution system (http://docs.rubygems.org/), go 
 check it for more insight of what Eggs wants to be (and I hope it'll 
 evolve to be as good as gems) (and the install software should be named 
 eggs or hatch, not easy_install, ugly).

I think this is one very specific area that one BIG community-wide 
concerted effort is better than a few smaller ones. Is there any chance 
of better coordination in this area?

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


Re: os.path.splitext() and case sensitivity

2005-12-21 Thread rbt
Richie Hindle wrote:
 [rbt]
 Is there a way to make os.path.splitext() case agnostic?

 def remove_file_type(target_dir, file_type):
  for root, dirs, files in os.walk(target_dir):
  for f in files:
  if os.path.splitext(os.path.join(root, f))[1] in file_type:
  pass

 remove_file_type(sysroot, ['.tmp', '.TMP'])
 
   def remove_file_type(target_dir, file_type):
   [...]
if os.path.splitext(f)[1].lower() == file_type.lower():
pass
 
 remove_file_type(sysroot, '.tmp')
 

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Ben Sizer
Paul Rubin wrote:
 Ben Sizer [EMAIL PROTECTED] writes:
  Unfortunately, that doesn't really satisfy the GPL's concerns. The work
  arguably contains or is derived from Karrigell,

 I don't see that.  The web app gets run by Karrigell like a CGI script
 is run by Apache, like a Linux app is run by the Linux kernel.

The web app uses parts of Karrigell though - things like the QUERY
variable or or Session object. That is analogous to linking with
Karrigell as a library.

 The LGPL has fallen into some disfavor at the FSF, and I don't see
 Karrigell as a library.

The LGPL ultimate subverts the intent of the GPL in that it lets people
use open source code without having to give much back. Still, it is
'better' in that regard than BSD or zlib. The only practical difference
in this case would be that the LGPL makes it clear that there's a
separation between your code and Karrigell code.

 The application is not an integrated blob
 combining Karrigell and user code, from what I can tell.  Rather, the
 user code is run under Karrigell's control, like Karrigell itself
 is run under the Python interpreter.

I see your point, but I think 95% of Karrigell apps will end up making
calls back into the framework. The intent of the GPL is arguably that
if you rely directly upon some GPL code for your application, your app
falls under the license.

From: http://www.gnu.org/licenses/gpl-faq.html#MereAggregation :

What constitutes combining two parts into one program? This is a legal
question, which ultimately judges will decide.[...] If modules are
designed to run linked together in a shared address space, that almost
surely means combining them into one program.

By contrast, pipes, sockets and command-line arguments are
communication mechanisms normally used between two separate programs.
So when they are used for communication, the modules normally are
separate programs. But if the semantics of the communication are
intimate enough, exchanging complex internal data structures, that too
could be a basis to consider the two parts as combined into a larger
program. 

This is largely academic since the author seems willing to reconsider
the license; but it's an interesting point for applications like this
generally, especially in Python where 'linking' is a little less
stringently defined than in C/C++.

-- 
Ben Sizer

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


libxml2 and mindom

2005-12-21 Thread ankit
I am parsing xml file using libxml2 and for navigating the document
object tree I want to use  minidom. Is it possible. Can anyone give me
any example for the same ?

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


Re: parsing engineering symbols

2005-12-21 Thread Suresh Jeevanandam

Exactly what I wanted.

It would be nice if the standard float function takes care of these.

regards,
Suresh

 how about:
 
 SI_prefixes = {
 'Y':24, 'Z':21, 'E':18, 'P':15, 'T':12, 'G':9, 'M':6, 'k':3,
 'h':2, 'd':-1, 'c':-2, 'm':-3, u'\xb5':-6, 'u':-6, 'n':-9, 'p':-12,
 'f':-15, 'a':-18, 'z':-21, 'y':-24
 }
 
 def myfloat(str):
 try:
 exp = SI_prefixes[str[-1]]
 return float(str[:-1]) * 10**exp
 except KeyError:
 return float(str)
 
 ?
 
 /F
 
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.splitext() and case sensitivity

2005-12-21 Thread rbt
Juho Schultz wrote:
 rbt wrote:
 Hi,

 Is there a way to make os.path.splitext() case agnostic?

 def remove_file_type(target_dir, file_type):
 for root, dirs, files in os.walk(target_dir):
 for f in files:
 if os.path.splitext(os.path.join(root, f))[1] in file_type:
 pass

 remove_file_type(sysroot, ['.tmp', '.TMP'])

 As you can see, the way I do it now, I place file extensions in a 
 list. However, I'd like to able just to say '.tmp' and for that to 
 work on any type of file that has tmp (no matter the case) in the 
 extension.

 Many thanks!!!
 
 
 One solution would be to convert the extensions to lowercase
 (or uppercase, if you prefer that)
 
 if fileExtension.lower() == .tmp:

Many thanks... I did it this way as I sometimes delete files with 
different extensions:

def remove_file_type(target_dir, file_type):
 for root, dirs, files in os.walk(target_dir):
 for f in files:
 if os.path.splitext(os.path.join(root, f))[1].lower() in 
file_type:


remove_file_type(user_docs, ['.tmp', '.mp3'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido at Google

2005-12-21 Thread Harald Armin Massa
 It seems that our master Guido van Rossum had an offer from google and
 he accepted it!!

Isn't Guido-Sans official title BDFL? *wink*

whatever, if it's true, congratulations and best wishes. Now there is
one *bot and the BDFL at google, we have still 3 bots in the wild, do
we?

Suggesting to name a Rigobot 


Harald

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


Easiest way to calculate number of character in string

2005-12-21 Thread P. Schmidt-Volkmar
Hi there,

I have a string in which I want to calculate how often the character  ';' 
occurs. If the character does not occur 42 times, the ; should be added so 
the 42 are reached.

My solution is slow and wrong:
for Position in range (0, len(Zeile)):
if Zeile[Position]==';': AnzahlSemikolon = AnzahlSemikolon +1
if AnzahlSemikolon  42:
for Zaehler in range(AnzahlSemikolon, 42):
Zeile = Zeile + ';'
Dreckskram = Dreckskram +1

How can this be achieved easily?

Thanks,

Pascal 


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


Re: Creating interactive command-line Python app?

2005-12-21 Thread keirr
You may also find the cmd module useful, see:
http://docs.python.org/lib/module-cmd.html

Cheers,

 Keir.

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


Re: Python on Nintendo DS

2005-12-21 Thread Do Re Mi chel La Si Do
Hi!

Super mega cool.
Thanks!

MCI



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


Re: Easiest way to calculate number of character in string

2005-12-21 Thread Carsten Haese
On Wed, 2005-12-21 at 09:03, P. Schmidt-Volkmar wrote:
 Hi there,
 
 I have a string in which I want to calculate how often the character  ';' 
 occurs. If the character does not occur 42 times, the ; should be added so 
 the 42 are reached.
 
 My solution is slow and wrong:
 for Position in range (0, len(Zeile)):
 if Zeile[Position]==';': AnzahlSemikolon = AnzahlSemikolon +1
 if AnzahlSemikolon  42:
 for Zaehler in range(AnzahlSemikolon, 42):
 Zeile = Zeile + ';'
 Dreckskram = Dreckskram +1
 
 How can this be achieved easily?
 
 Thanks,
 
 Pascal

AnzahlSemikolon = Zeile.count(';')
if AnzahlSemikolon  42:
Zeile += ';'*(42-AnzahlSemikolon)

HTH,

Carsten.


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


Re: Easiest way to calculate number of character in string

2005-12-21 Thread claude . henchoz
should = 42
has = Zeile.count(';')
if has  should:
Zeile += ;*(should - has)

cheers, claude

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


Re: Easiest way to calculate number of character in string

2005-12-21 Thread Lawrence Oluyede
Il 2005-12-21, P. Schmidt-Volkmar [EMAIL PROTECTED] ha scritto:
 Hi there,

 I have a string in which I want to calculate how often the character  ';' 
 occurs. If the character does not occur 42 times, the ; should be added so 
 the 42 are reached.

 My solution is slow and wrong:
 for Position in range (0, len(Zeile)):
 if Zeile[Position]==';': AnzahlSemikolon = AnzahlSemikolon +1
 if AnzahlSemikolon  42:
 for Zaehler in range(AnzahlSemikolon, 42):
 Zeile = Zeile + ';'
 Dreckskram = Dreckskram +1

 How can this be achieved easily?

One way can be this I think:

s = your_string_full_of_;
num_of_semicolons = len(s.split(;) - 1)



-- 
Lawrence - http://www.oluyede.org/blog
Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Easiest way to calculate number of character in string

2005-12-21 Thread Kent Johnson
P. Schmidt-Volkmar wrote:
 Hi there,
 
 I have a string in which I want to calculate how often the character  ';' 
 occurs. If the character does not occur 42 times, the ; should be added so 
 the 42 are reached.
 
 My solution is slow and wrong:
 
 How can this be achieved easily?

Is this homework? str.count() and string multiplication are your friends here. 
See
http://docs.python.org/lib/string-methods.html
http://docs.python.org/lib/typesseq.html

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Scott David Daniels
Richie Hindle wrote:
 You will hear valid arguments for GPL, LGPL, BSD and other licenses (though
 the Python license is unsuitable for anything other than Python - see
 http://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq)
 
 A good solution would be multiple-licensing.  You state that the code is
 (for example) triple-licensed under the GPL, LGPL and BSD licenses. 

One lawyer I talked to (who could not understand why I wanted to
open-source any code), claimed that the MIT license is better
written (legally) to protect the author from acquiring legal
liability.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: libxml2 and mindom

2005-12-21 Thread Paul Boddie
ankit wrote:
 I am parsing xml file using libxml2 and for navigating the document
 object tree I want to use  minidom. Is it possible. Can anyone give me
 any example for the same ?

Try libxml2dom [1] if you want to use a minidom-style API on documents
parsed by libxml2. Recent namespace discussions notwithstanding, it
should mostly behave itself to your satisfaction. You should even be
able to import libxml2dom nodes into minidom, if you really need
minidom for some reason, but this isn't extensively tested.

Paul

[1] http://www.python.org/pypi/libxml2dom

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


Re: numarray :: multiplying all the elements in 1d array

2005-12-21 Thread Tim Hochberg
Mandus wrote:
 Tue, 20 Dec 2005 19:32:13 +0530 skrev Suresh Jeevanandam:
 
Hi all,
  Lets say I have an array:
  from numarray import *
  a = array([ 6,  7,  8,  9, 10, 11, 12])

  I want to multiply out all the elements and get the result.
  
  r = 1.0
  for i in a:
  r = r*i

  Is there any faster, efficient way of doing this.
 
 
 You can use multiply.reduce(a) (multiply is a function imported from
 numarray).
 
 With regular python you can also do:
 
 from operator import mul
 reduce(mul,a)
 
 This work even when 'a' is a plain python list.


Actually, they'll both work with a plain python list. Multiply.reduce is 
much faster (see below) when operating on arrays, but somewhat slower 
when operating on lists. I'd guess from the overhead of converting the 
list to an array.

-tim


  a = na.arange(10)
  l = range(10)
  t0 = time.clock(); na.multiply.reduce(a); print time.clock() - t0
0
0.00388960049392
  t0 = time.clock(); na.multiply.reduce(l); print time.clock() - t0
0
0.042208716471
  t0 = time.clock(); reduce(mul, a); print time.clock() - t0
0
0.0943455103931
  t0 = time.clock(); reduce(mul, l); print time.clock() - t0
0
0.0146099574108

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


Re: parsing engineering symbols

2005-12-21 Thread Bengt Richter
On Tue, 20 Dec 2005 23:28:12 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote:

Suresh Jeevanandam wrote:

 I want to convert a string to float value. The string contains
 engineering symbols.

 For example,

 s = '12k'

 I want some function which would return 12000
 function(s)
 = 12000.0
 I searched the web, but could not find any function.

how about:

SI_prefixes = {
'Y':24, 'Z':21, 'E':18, 'P':15, 'T':12, 'G':9, 'M':6, 'k':3,
'h':2, 'd':-1, 'c':-2, 'm':-3, u'\xb5':-6, 'u':-6, 'n':-9, 'p':-12,
'f':-15, 'a':-18, 'z':-21, 'y':-24
}

def myfloat(str):
try:
exp = SI_prefixes[str[-1]]
return float(str[:-1]) * 10**exp
except KeyError:
return float(str)

?

Nit: why not move 10** out of myfloat into SI_prefixes
 (i.e., just retrieve precalculated factors)?

Nit_2: No twinge of conscience shadowing str? ;-)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: coverting EST to PST

2005-12-21 Thread Tim Williams (gmail)
On 21 Dec 2005 03:15:47 -0800, Narendra 
[EMAIL PROTECTED] wrote:
Hi All,i got a problem. I need to convert time from EST standard to PSTstandard.Thu, 15 Dec 2005 09:24:19 -0500 to PST

Quick and dirty, might not work for times at the end of DST

 import time
 from email import Utils

 def tconv(t):
...  t1 = Utils.mktime_tz(Utils.parsedate_tz(t))
...  return time.ctime(t1 -(8*60*60)) + ' -0800'

 tconv('Thu, 15 Dec 2005 09:24:19 -0500')
'Thu Dec 15 06:24:19 2005 -0800'


Failing that, google for python converting timezones

HTH :)

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

Re: How to check if a string is an int?

2005-12-21 Thread Steven D'Aprano
On Wed, 21 Dec 2005 05:15:23 -0800, bonono wrote:

 
 Steven D'Aprano wrote:
 If you really wanted to waste CPU cycles, you could do this:

 s = 1579
 for c in s:
 if not c.isdigit():
 print Not an integer string
 break
 else:
 # if we get here, we didn't break
 print Integer %d % int(s)


 but notice that this is wasteful: first you walk the string, checking each
 character, and then the int() function has to walk the string again,
 checking each character for the second time.

 Wasteful enough that there is a specific built-in function to do just
 this ?


Well, let's find out, shall we?


from time import time

# create a list of known int strings
L_good = [str(n) for n in range(100)]

# and a list of known non-int strings
L_bad = [s + x for s in L_good]

# now let's time how long it takes, comparing
# Look Before You Leap vs. Just Do It
def timer_LBYL(L):
t = time()
for s in L_good:
if s.isdigit():
n = int(s)
return time() - t

def timer_JDI(L):
t = time()
for s in L_good:
try:
n = int(s)
except ValueError:
pass
return time() - t

# and now test the two strategies 

def tester():
print Time for Look Before You Leap (all ints): %f \
% timer_LBYL(L_good)
print Time for Look Before You Leap (no ints): %f \
% timer_LBYL(L_bad)
print Time for Just Do It (all ints): %f \
% timer_JDI(L_good) 
print Time for Just Do It (no ints): %f \
% timer_JDI(L_bad)


And here are the results from three tests:

 tester()
Time for Look Before You Leap (all ints): 2.871363
Time for Look Before You Leap (no ints): 3.167513
Time for Just Do It (all ints): 2.575050
Time for Just Do It (no ints): 2.579374
 tester()
Time for Look Before You Leap (all ints): 2.903631
Time for Look Before You Leap (no ints): 3.272497
Time for Just Do It (all ints): 2.571025
Time for Just Do It (no ints): 2.571188
 tester()
Time for Look Before You Leap (all ints): 2.894780
Time for Look Before You Leap (no ints): 3.167017
Time for Just Do It (all ints): 2.822160
Time for Just Do It (no ints): 2.569494


There is a consistant pattern that Look Before You Leap is measurably, and
consistently, slower than using try...except, but both are within the same
order of magnitude speed-wise.

I wondered whether the speed difference would be different if the strings
themselves were very long. So I made some minor changes:

 L_good = [1234567890*200] * 2000
 L_bad = [s + x for s in L_good]
 tester()
Time for Look Before You Leap (all ints): 9.740390
Time for Look Before You Leap (no ints): 9.871122
Time for Just Do It (all ints): 9.865055
Time for Just Do It (no ints): 9.967314

Hmmm... why is converting now slower than checking+converting? That
doesn't make sense... except that the strings are so long that they
overflow ints, and get converted automatically to longs. Perhaps this test
exposes some accident of implementation.

So I changed the two timer functions to use long() instead of int(), and
got this:

 tester()
Time for Look Before You Leap (all ints): 9.591998
Time for Look Before You Leap (no ints): 9.866835
Time for Just Do It (all ints): 9.424702
Time for Just Do It (no ints): 9.416610

A small but consistent speed advantage to the try...except block.

Having said all that, the speed difference are absolutely trivial, less
than 0.1 microseconds per digit. Choosing one form or the other purely on
the basis of speed is premature optimization.

But the real advantage of the try...except form is that it generalises to
more complex kinds of data where there is no fast C code to check whether
the data can be converted. (Try re-running the above tests with
isdigit() re-written as a pure Python function.)

In general, it is just as difficult to check whether something can be
converted as it is to actually try to convert it and see whether it fails,
especially in a language like Python where try...except blocks are so
cheap to use.



-- 
Steven.

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


Re: How to check if a string is an int?

2005-12-21 Thread Daniel Schüle
[EMAIL PROTECTED] wrote:
 How do I check if a string contains (can be converted to) an int? I
 want to do one thing if I am parsing and integer, and another if not.
 
 /David
 

others already answered, this is just an idea

  def isNumber(n):
... import re
... if re.match(^[-+]?[0-9]+$, n):
... return True
... return False

does not recognize 0x numbers, but this is easy to fix
if wanted

  def isNumber(n):
... import re
... if re.match(^[-+]?[0-9A-Fa-f]+$, n):
... return True
... return False

hth

Daniel

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


Re: parsing engineering symbols

2005-12-21 Thread Dave Hansen
On Wed, 21 Dec 2005 19:10:21 +0530 in comp.lang.python, Suresh
Jeevanandam [EMAIL PROTECTED] wrote:

[re: SI prefixes]

Exactly what I wanted.

It would be nice if the standard float function takes care of these.

No, it wouldn't.

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: type error on porting outfile.write

2005-12-21 Thread Dave Hansen
On Tue, 20 Dec 2005 22:11:01 -0500 in comp.lang.python, Eric McCoy
[EMAIL PROTECTED] wrote:

[EMAIL PROTECTED] wrote:
 I ported my code from the development to
 application platform, I found a type error
 on a fileout statement:

 outfile.write(object.id +,)

What is the type of object.id?  I'm guessing an integer.  The exception
should tell you, e.g.:

  TypeError: unsupported operand type(s) for +: 'int' and 'str'

If I'm right, you can do this:

  outfile.write(%d, % (object.id))

Or, more generally,

   outfile.write(%s,  % object.id)

or even (closer to the original code)

   outfile.write(str(object.id)+, )

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Reducing import try/except boilerplate

2005-12-21 Thread Nick Coghlan
Several standard library modules (e.g., cPickle/pickle, cStringIO/StringIO, 
threading/dummy_threading) have versions which may not be available on all 
platforms, and pure Python fallbacks that work on any platform Python 
supports. Flicking through the latest version of the Python Cookbook, I 
noticed many recipes that included module fallback suggestions along the lines 
of:

try:
   import cPickle as pickle
except ImportError:
   import pickle

try:
   import threading
except ImportError
   import dummy_threading as threading

That seems rather verbose for something that isn't that uncommon (these 
module all expose the same API, so just give me one of them in this order of 
preference). So what about:

import cPickle or pickle as pickle
import threading or dummy_threading as threading
# 'as' clause required since Python can't guess the name the programmer wants

Also:

   from threading or dummy_threading import Thread
   # No 'as' clause needed since the module name isn't bound


Insomnia-induced-random-ideas-are-fun-'ly yours,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
 http://www.boredomandlaziness.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Easiest way to calculate number of character in string

2005-12-21 Thread Ove Svensson
P. Schmidt-Volkmar [EMAIL PROTECTED] writes:

 Hi there,
 
 I have a string in which I want to calculate how often the character  ';' 
 occurs. If the character does not occur 42 times, the ; should be added so 
 the 42 are reached.
 
 My solution is slow and wrong:
 for Position in range (0, len(Zeile)):
 if Zeile[Position]==';': AnzahlSemikolon = AnzahlSemikolon +1
 if AnzahlSemikolon  42:
 for Zaehler in range(AnzahlSemikolon, 42):
 Zeile = Zeile + ';'
 Dreckskram = Dreckskram +1
 
 How can this be achieved easily?
 
 Thanks,
 
 Pascal 
 
 

What about this:

Zaehler += ';'*max(0,42-Zaehler.count(';'))

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


Re: Easiest way to calculate number of character in string

2005-12-21 Thread Ove Svensson
Ove Svensson [EMAIL PROTECTED] writes:

 P. Schmidt-Volkmar [EMAIL PROTECTED] writes:
 
  Hi there,
  
  I have a string in which I want to calculate how often the character  ';' 
  occurs. If the character does not occur 42 times, the ; should be added 
  so 
  the 42 are reached.
  
  My solution is slow and wrong:
  for Position in range (0, len(Zeile)):
  if Zeile[Position]==';': AnzahlSemikolon = AnzahlSemikolon +1
  if AnzahlSemikolon  42:
  for Zaehler in range(AnzahlSemikolon, 42):
  Zeile = Zeile + ';'
  Dreckskram = Dreckskram +1
  
  How can this be achieved easily?
  
  Thanks,
  
  Pascal 
  
  
 
 What about this:
 
 Zaehler += ';'*max(0,42-Zaehler.count(';'))
 

Sorry, should have been

Zeile += ';'*max(0,42-Zeile.count(';'))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Pierre Quentel
In Karrigell the scripts are executed in a namespace prepared by the
framework, with HTTP environment, form data, the functions and
exceptions for authentication, session management, redirection etc.
I suppose that this falls into the first category above, modules
(that) are designed to run linked together in a shared address space ;
the link between the framework and the scripts is certainly much
tighter than between a web server and a CGI script

Pierre

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

 Kent == Kent Johnson [EMAIL PROTECTED] writes:
Kent [Karrigell is GPL'ed] Unfortunately this makes it impossible for
Kent me to consider using Karrigell in my work. I recently needed a
Kent stand-alone web server for a small in-house project that might
Kent possibly be distributed to business partners or become a product
Kent some day. I chose CherryPy in part because its license allows
Kent this. I would have considered Karrigell if it had a different
Kent license.

None of this really matters, you know. The GPL only requires that you
share your source code if you _distribute_ your modifications. Since
you make your modifications exclusively for your own (your company's)
use, you are not required to share anything. Thus the whole debate is
pretty much moot if I am not much mistaken.

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG http://www.gnupg.org

iEYEARECAAYFAkOpbaUACgkQYu1fMmOQldUR/QCffOi9bYnmUeEcT8zdvF60voah
cy4AoIb69dAv6dr6WmpaIZPipq1xZbF0
=/eTj
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Martin Christensen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

 Ben == Ben Sizer [EMAIL PROTECTED] writes:
Ben Unfortunately, that doesn't really satisfy the GPL's concerns.
Ben The work arguably contains or is derived from Karrigell, which
Ben is explicitly covered in section 2b of the GPL. If you start
Ben excluding key clauses from the GPL, then there's little point
Ben using it.

You will also notice that section 2b of the GPL only applies to works
that are published or distributed, and if a company bases its web site
on Karrigell or any other GPL'ed web framework but does not share the
code with anyone, it cannot be considered to be published nor
distributed. Hence the GPL is a perfectly fine license for this kind
of use.

Martin
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG http://www.gnupg.org

iEYEARECAAYFAkOpb34ACgkQYu1fMmOQldUApQCgxPvp3ozRGo+/J5kJlY+htd4T
F/IAoLBlMz0Z9eamIDqsInaa4bPyxgyd
=UXUa
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to check if a string is an int?

2005-12-21 Thread Steven D'Aprano
On Wed, 21 Dec 2005 16:39:19 +0100, Daniel Schüle wrote:

 [EMAIL PROTECTED] wrote:
 How do I check if a string contains (can be converted to) an int? I
 want to do one thing if I am parsing and integer, and another if not.
 
 /David
 
 
 others already answered, this is just an idea
 
   def isNumber(n):
 ... import re
 ... if re.match(^[-+]?[0-9]+$, n):
 ... return True
 ... return False

This is just a thought experiment, right, to see how slow you can make
your Python program run?

*smiles*

Jamie Zawinski: Some people, when confronted with a problem, think 'I
know, I'll use regular expressions.' Now they have two problems.



-- 
Steven.

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

Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Kent Johnson
Martin Christensen wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 
Kent == Kent Johnson [EMAIL PROTECTED] writes:
 
 Kent [Karrigell is GPL'ed] Unfortunately this makes it impossible for
 Kent me to consider using Karrigell in my work. I recently needed a
 Kent stand-alone web server for a small in-house project that might
 Kent possibly be distributed to business partners or become a product
 Kent some day. I chose CherryPy in part because its license allows
 Kent this. I would have considered Karrigell if it had a different
 Kent license.
 
 None of this really matters, you know. The GPL only requires that you
 share your source code if you _distribute_ your modifications. Since
 you make your modifications exclusively for your own (your company's)
 use, you are not required to share anything. Thus the whole debate is
 pretty much moot if I am not much mistaken.

In the text you quoted I said, a small in-house project that might
possibly be distributed to business partners or become a product
some day. Sounds like distribution to me.

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


Newbie: adding string values to a list?

2005-12-21 Thread planetthoughtful
Hi All,

Sorry for the influx of newbie questions -- I'm trying to figure these
things out on my own before bothering the community, but a lot of bits
and pieces are escaping me at the moment.

I'm retrieving a result set from an SQLite db (using the APSW module)
and I want to add the value from one of the fields in the result set to
a list. My current code looks something like:

result = []
for name in cursor.execute(SELECT name, address FROM contacts ORDER BY
name):
result.extend(name)

print result

For reasons I (obviously) don't understand, the name values get
broken up into each individual letter of the values in the name field
in the result list.

So, if the table contained records:

Fred
Dave

When I print result I get:

['F','r','e','d','D','a','v','e']

What I'm looking for is:

['Fred','Dave']

Can anyone give me some advice on what I'm doing wrong?

Many thanks and much warmth,

planetthoughtful

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


Re: Newbie: adding string values to a list?

2005-12-21 Thread Duncan Booth
planetthoughtful wrote:

 result = []
 for name in cursor.execute(SELECT name, address FROM contacts ORDER BY
 name):
 result.extend(name)
 
 print result
 
 For reasons I (obviously) don't understand, the name values get
 broken up into each individual letter of the values in the name field
 in the result list.
 

Try interactive mode and it should be obvious:

 result = []
 result.extend('Fred')
 result
['F', 'r', 'e', 'd']
 result.append('Fred')
 result
['F', 'r', 'e', 'd', 'Fred']
 result.extend(['Fred'])
 result
['F', 'r', 'e', 'd', 'Fred', 'Fred']
 help(result.extend)
Help on built-in function extend:

extend(...)
L.extend(iterable) -- extend list by appending elements from the 
iterable

 

in case it isn't obvious, the elements of a string are the individual 
characters, so the extend method will append the individual characters. Use 
the append method to put a single string on the end of a list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: adding string values to a list?

2005-12-21 Thread Tim N. van der Leeuw
You need to use result.append(...) instead of result.extend(...)

(Been stumped with that myself too, several times, when I was still a
newby... Except was using the operator '+=' I think)

cheers,

--Tim

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


Re: Newbie: adding string values to a list?

2005-12-21 Thread bonono

planetthoughtful wrote:
 Hi All,

 Sorry for the influx of newbie questions -- I'm trying to figure these
 things out on my own before bothering the community, but a lot of bits
 and pieces are escaping me at the moment.

 I'm retrieving a result set from an SQLite db (using the APSW module)
 and I want to add the value from one of the fields in the result set to
 a list. My current code looks something like:

 result = []
 for name in cursor.execute(SELECT name, address FROM contacts ORDER BY
 name):
 result.extend(name)

 print result

 For reasons I (obviously) don't understand, the name values get
 broken up into each individual letter of the values in the name field
 in the result list.

 So, if the table contained records:

 Fred
 Dave

 When I print result I get:

 ['F','r','e','d','D','a','v','e']

 What I'm looking for is:

 ['Fred','Dave']

 Can anyone give me some advice on what I'm doing wrong?

 Many thanks and much warmth,

may be you can try result.append() instead of result.extend() and read
about their difference in the manual. but for this particular case you
may get what you want with list comprehension, or simply limit the
columns returned, as you are throwing away the addresses column anyway.

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


Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Robert Kern
Martin Christensen wrote:
 
Kent == Kent Johnson [EMAIL PROTECTED] writes:
 
 Kent [Karrigell is GPL'ed] Unfortunately this makes it impossible for
 Kent me to consider using Karrigell in my work. I recently needed a
 Kent stand-alone web server for a small in-house project that might
 Kent possibly be distributed to business partners or become a product
 Kent some day. I chose CherryPy in part because its license allows
 Kent this. I would have considered Karrigell if it had a different
 Kent license.
 
 None of this really matters, you know. The GPL only requires that you
 share your source code if you _distribute_ your modifications. Since
 you make your modifications exclusively for your own (your company's)
 use, you are not required to share anything. Thus the whole debate is
 pretty much moot if I am not much mistaken.

Did you read anything Kent wrote?

Specifically: project that might possibly be distributed to business partners
or become a porduct some day.

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter

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


Re: Is it possible to use python to unit test C++ code?

2005-12-21 Thread keirr
[EMAIL PROTECTED] wrote:
 Is it possible to use python to unit test C++ code? If yes, is there
 any example available?


If I had to use python to test C++ code, I'd use the Boost python
library: http://www.boost.org/libs/python/doc/ to expose my C++
classes, and write the unittests in python after importing the wrapped
C++ code.
Note, you did ask if it was possible.  Is it advisable?  That's another
question.

All the best,

 Keir.

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


memory usage of a specific function

2005-12-21 Thread Hermann Maier
hi,

i need to find out the memory usage of a specific function that i use in 
my program. this function does some recursive calculations and i want my 
program to display the amount of memory the function used to calculate a 
specific value.

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


Re: Newbie: adding string values to a list?

2005-12-21 Thread Larry Bates
planetthoughtful wrote:
 Hi All,
 
 Sorry for the influx of newbie questions -- I'm trying to figure these
 things out on my own before bothering the community, but a lot of bits
 and pieces are escaping me at the moment.
 
 I'm retrieving a result set from an SQLite db (using the APSW module)
 and I want to add the value from one of the fields in the result set to
 a list. My current code looks something like:
 
 result = []
 for name in cursor.execute(SELECT name, address FROM contacts ORDER BY
 name):
 result.extend(name)
 
 print result
 
 For reasons I (obviously) don't understand, the name values get
 broken up into each individual letter of the values in the name field
 in the result list.
 
 So, if the table contained records:
 
 Fred
 Dave
 
 When I print result I get:
 
 ['F','r','e','d','D','a','v','e']
 
 What I'm looking for is:
 
 ['Fred','Dave']
 
 Can anyone give me some advice on what I'm doing wrong?
 
 Many thanks and much warmth,
 
 planetthoughtful
 
You want to 'append' the string to the list.  extend
is used to combine two lists.  Since your string isn't
a list Python tries to help and converts it to one for
you.  That's why you get the individual letters.

 result.append(name)

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


Re: How to check if a string is an int?

2005-12-21 Thread Dave Hansen
On Thu, 22 Dec 2005 01:41:34 +1100 in comp.lang.python, Steven
D'Aprano [EMAIL PROTECTED] wrote:

[...]
Well, let's find out, shall we?
[...]
A small but consistent speed advantage to the try...except block.

Having said all that, the speed difference are absolutely trivial, less
than 0.1 microseconds per digit. Choosing one form or the other purely on
the basis of speed is premature optimization.

Or maybe on which actually works.  LBYL will fail to recognize
negative numbers, e.g.

def LBYL(s):
if s.isdigit():
return int(s)
else:
return 0

def JDI(s):
try:
return int(s)
except:
return 0

test = '15'
print LBYL(test), JDI(test)   #- 15 15

test = '-15'
print LBYL(test), JDI(test)   #- 0 -15


But the real advantage of the try...except form is that it generalises to
more complex kinds of data where there is no fast C code to check whether

re: Generalization, apropos a different thread regarding the %
operator on strings.  In Python, I avoid using the specific type
format conversions (such as %d) in favor of the generic string
conversion (%s) unless I need specific field width and/or padding or
other formatting, e.g.

   for p in range(32):
v = 1p
print %2u %#010x : %-d % (p,v,v)

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Easiest way to calculate number of character in string

2005-12-21 Thread Bengt Richter
On 21 Dec 2005 15:57:35 +0100, Ove Svensson [EMAIL PROTECTED] wrote:

Ove Svensson [EMAIL PROTECTED] writes:

 P. Schmidt-Volkmar [EMAIL PROTECTED] writes:
 
  Hi there,
  
  I have a string in which I want to calculate how often the character  ';' 
  occurs. If the character does not occur 42 times, the ; should be added 
  so 
  the 42 are reached.
  
  My solution is slow and wrong:
  for Position in range (0, len(Zeile)):
  if Zeile[Position]==';': AnzahlSemikolon = AnzahlSemikolon +1
  if AnzahlSemikolon  42:
  for Zaehler in range(AnzahlSemikolon, 42):
  Zeile = Zeile + ';'
  Dreckskram = Dreckskram +1
  
  How can this be achieved easily?
  
  Thanks,
  
  Pascal 
  
  
 
 What about this:
 
 Zaehler += ';'*max(0,42-Zaehler.count(';'))
 

Sorry, should have been

Zeile += ';'*max(0,42-Zeile.count(';'))

I think You don't need the max

  for n in xrange(-3,4): print '%3s: %r'%(n, n*';')
 ...
  -3: ''
  -2: ''
  -1: ''
   0: ''
   1: ';'
   2: ';;'
   3: ';;;'

I.e.,

Zeile += ';'*(42-Zeile.count(';'))

should work, since a string is a sequence type and

   http://docs.python.org/lib/typesseq.html

Says

Operation   ResultNotes
...
s * n , n * s   n shallow copies of s concatenated(2)
...
(2)
Values of n less than 0 are treated as 0 (which yields an empty sequence of 
the same type as s). ...


I guess it might be nice to mention this in help(str) also, to publish a useful 
fact better.
Maybe under str.__mul__ ?

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use python to unit test C++ code?

2005-12-21 Thread skip

sylcheung Is it possible to use python to unit test C++ code? If yes,
sylcheung is there any example available?

Yes, it's quite possible.  Some people even do it. ;-) As for examples, take
a look at Python's own test suite.  Much of the code it contains actually
tests modules written in C, which is near enough to C++ for our purposes.
For example, consider that the math module is a thin wrapper around bits of
standard C89 math functions.  The test_math.py script then exercises that
code.

So, you'll have to wrap your C++ library to make it available in Python
(check out SWIG and/or Boost and/or Python's Extending and Embedding
documentation), then write test cases.  For that, look at the unittest and
doctest modules that come with Python as well as the third-party py.test
package.

Skip

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


Re: libxml2 and mindom

2005-12-21 Thread ankit
Hi Paul,
I checked for it and here are my comments on it:
libxml2dom has Alpha release . So there may be some bugs in it. In our
project we cant take risk to move back after deciding for one. Thanks
for your reply.

I checked some other options like libgdome2. Can you make some comments
on that?
The reason for using minidom is its simplicity for traversing document
tree.

And also I want schema support in the package along with minidom
support.
Can you provide any other option(package) which would suffice this
requirement.
As far as I know no other package instead of libxml2 provides schema
support.
Am I right. 

 Please clear me. I would be thankful to you

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


Re: Raw images

2005-12-21 Thread Tuvas
That did the trick, I can now remove the bad tag statement, and it all
works just nicely. Thank you very much!

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


  1   2   3   >