Re: New docs for set elements/dictionary keys (Was: Why is dictionary.keys() a list and not a set?)

2005-11-26 Thread Martin v. Löwis
Mike Meyer wrote:
> Personally, I think we'd be better off to come up with a term for this
> property that doesn't have a commonly understood meaning that has such
> broad areas of disagreement with the property. I've been using
> "hashable", which I would currently define as "has a __hash__ method
> with the properties described in the __hash__ documentation, or does
> not have either a __cmp__ or a __eq__ method."

I would like to use "hashable" as a term as well, but it appears that
many people would understand that to mean "has a __hash__ 
implementation" (i.e. hash(x) returns a value, instead of raising an
exception).

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


Re: SOAP - Beginner Desperately looking for Help

2005-11-26 Thread Rodney Garland
Thanks  :-)


"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> I wanted to attach these - however, taht didn't work for NNTP, so I mail 
>> them to you.
>
> Didn't work - my mail server won't let me send these to you. So you're on 
> your own here. Shouldn't be too hard :)
>
> Diez 


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


interactive prompts

2005-11-26 Thread Michael Williams
Hi all,

I'm having an issue with environment variables and spawned commands.   
Specifically, I'm using "eval `ssh-agent`" and "ssh-add".  My  
question is, how do I force the environmental variables set by one  
'popen' or 'pexpect' to propagate throughout the entire Python  
session so that any commands called will see those env variables?

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


Re: Which License Should I Use?

2005-11-26 Thread [EMAIL PROTECTED]
First thing first, you need to find out if you are an "employee", not
in the normal sense, but legal sense.

This directly affect the copyright issue, outside your "work hours".

If you need their consent on take on other clients, that would be iffy.
There are a number of things a court would look at to determine this.
You may think you are a consultant(thus tools you develop during the
course is yours, so long it is outside "contracted hours"), the court
may not think it this way.

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


Re: Syntax

2005-11-26 Thread Terry Hancock
On Sat, 26 Nov 2005 20:54:49 -0800
Robert Kern <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > So, two options:
> > 
> > from os import *
> > import os

> > One of these two ways you're not supposed to use for
> > security reasons, but I'm spacing on which one.
> 
> I don't think there are any *security* reasons, but
> stylistically, "import os" is greatly preferred. When
> someone else reads your code, they will immediately know
> where getcwd() comes from.

It's not a question of "security" in the usual sense, but
the first syntax imports a lot of stuff into the current
namespace, increasing the risk of unintentionally clobbering
local names. So it's certainly "riskier" in the sense of
"likely to cause bugs".


-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


why?

2005-11-26 Thread teimu . tm
ive been using python for about two years now, and cant think of an
instance where i would need that functionality. Dictionaries arent
supposed to be ordered...they provide object associations, and simply
that. Whatever your trying to do in pythonTMTOWTDI

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


Weekly Python Patch/Bug Summary

2005-11-26 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  372 open ( -7) /  2980 closed (+12) /  3352 total ( +5)
Bugs:  908 open ( -2) /  5395 closed (+11) /  6303 total ( +9)
RFE :  200 open ( +0) /   191 closed ( +0) /   391 total ( +0)

New / Reopened Patches
__

CodeContext - Improved text indentation  (2005-11-21)
   http://python.org/sf/1362975  opened by  Tal Einat

test_cmd_line expecting English error messages   (2005-11-23)
CLOSED http://python.org/sf/1364545  opened by  A.B., Khalid

Add reference for en/decode error types  (2005-11-23)
CLOSED http://python.org/sf/1364946  opened by  Wummel

[PATCH] mmap fails on AMD64  (2005-11-24)
   http://python.org/sf/1365916  opened by  Joe Wreschnig

Patches Closed
__

zlib.crc32 doesn't handle 0x seed  (2005-11-07)
   http://python.org/sf/1350573  closed by  akuchling

xml.dom.minidom.Node.replaceChild(obj, x, x) removes child x  (2005-01-01)
   http://python.org/sf/1094164  closed by  akuchling

Patch for (Doc) #1255218  (2005-10-17)
   http://python.org/sf/1328526  closed by  birkenfeld

Patch for (Doc) #1261659  (2005-10-17)
   http://python.org/sf/1328566  closed by  birkenfeld

Patch for (Doc) #1357604  (2005-11-18)
   http://python.org/sf/1359879  closed by  birkenfeld

CallTip Modifications  (2005-05-11)
   http://python.org/sf/1200038  closed by  kbk

ensure lock is released if exception is raised  (2005-10-05)
   http://python.org/sf/1314396  closed by  bcannon

test_cmd_line expecting English error messages   (2005-11-23)
   http://python.org/sf/1364545  closed by  doerwalter

ToolTip.py: fix main() function  (2005-10-06)
   http://python.org/sf/1315161  closed by  kbk

Add reference for en/decode error types  (2005-11-23)
   http://python.org/sf/1364946  closed by  doerwalter

solaris 10 should not define _XOPEN_SOURCE_EXTENDED  (2005-06-27)
   http://python.org/sf/1227966  closed by  loewis

Solaris 10 fails to compile complexobject.c [FIX incl.]  (2005-02-05)
   http://python.org/sf/1116722  closed by  loewis

New / Reopened Bugs
___

textwrap.dedent() expands tabs  (2005-11-19)
   http://python.org/sf/1361643  opened by  Steven Bethard

Text.edit_modified() doesn't work  (2005-11-20)
   http://python.org/sf/1362475  opened by  Ron Provost

Problem with tapedevices and the tarfile module  (2005-11-21)
   http://python.org/sf/1362587  opened by  Henrik

spawnlp is missing  (2005-11-21)
   http://python.org/sf/1363104  opened by  Greg MacDonald

A possible thinko in the description of os/chmod  (2005-11-22)
CLOSED http://python.org/sf/1363712  opened by  Evgeny Roubinchtein

urllib cannot open data: urls  (2005-11-25)
CLOSED http://python.org/sf/1365984  opened by  Warren Butler

Bug bz2.BZ2File(...).seek(0,2)  (2005-11-25)
   http://python.org/sf/1366000  opened by  STINNER Victor

inoorrect documentation for optparse  (2005-11-25)
   http://python.org/sf/1366250  opened by  Michael Dunn

SRE engine do not release the GIL  (2005-11-25)
   http://python.org/sf/1366311  opened by  Eric Noyau

inspect.getdoc fails on objs that use property for __doc__  (2005-11-26)
   http://python.org/sf/1367183  opened by  Drew Perttula

Bugs Closed
___

A possible thinko in the description of os.chmod  (2005-11-22)
   http://python.org/sf/1363712  closed by  birkenfeld

docs need to discuss // and __future__.division  (2001-08-08)
   http://python.org/sf/449093  closed by  akuchling

Prefer configured browser over Mozilla and friends  (2005-11-17)
   http://python.org/sf/1359150  closed by  birkenfeld

Incorrect documentation of raw unidaq string literals  (2005-11-17)
   http://python.org/sf/1359053  closed by  birkenfeld

"appropriately decorated" is undefined in MultiFile.push doc  (2005-08-09)
   http://python.org/sf/1255218  closed by  birkenfeld

Tutorial doesn't cover * and ** function calls  (2005-08-17)
   http://python.org/sf/1261659  closed by  birkenfeld

os.path.makedirs DOES handle UNC paths  (2005-11-15)
   http://python.org/sf/1357604  closed by  birkenfeld

Exec Inside A Function  (2005-04-06)
   http://python.org/sf/1177811  closed by  birkenfeld

Py_BuildValue k format units don't work with big values  (2005-09-04)
   http://python.org/sf/1281408  closed by  birkenfeld

urllib cannot open data: urls  (2005-11-25)
   http://python.org/sf/1365984  closed by  birkenfeld

imaplib: parsing INTERNALDATE  (2003-03-06)
   http://python.org/sf/698706  closed by  birkenfeld

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


Re: Crash in python while run from U3 device

2005-11-26 Thread Philippe C. Martin
PS: I should add that the U3 device does not actually run Python, but copies
it to the PC and launches it: I'm almost certain this is a bug in my code.

Help please !

Regards,

Philippe



Philippe C. Martin wrote:

> Hi,
> 
> I am currently porting some of my applications to U3 (www.u3.com) and I do
> get a crash in ...objects\frameobject.c: PyFrameObject *back =
> tstate->frame.
> 
> The point of the current test is to get a python function called on a U3
> device event. (U3 only work with Windows currently).
> 
> My C stub callback does get called but crashes when it tries to call the
> python function.
> 
> 
> 
> ***
> This is the function that registers the callback (actual dll prototype in
> header):
> ***
> static PyObject *s_callback=NULL;
> /**/
> /**/
> /* HRESULT dapiRegisterCallback(   HSESSION hSession ,wchar_t*
> pszConnectionString ,DAPI_CALLBACK pCallBack,void* pEx ,HCALLBACK*
> hCallback) */
> /**/
> /**/
> 
> static PyObject *Py_dapiRegisterCallback(PyObject *p_self, PyObject
> *p_args)
> {
> HRESULT l_result;
> HSESSION l_hSession;
> wchar_t* l_pszConnectionString;
> PyObject *l_tmp_cb;
> //PyObject cs;
> void* l_pEx;
> HCALLBACK l_hCallback;
> 
> if
>
(!PyArg_ParseTuple(p_args,"iuOi",&l_hSession,&l_pszConnectionString,&l_tmp_cb,&l_pEx)
> )
> {
> BAD_PARAM;
> return NULL;
> }
> //l_pszConnectionString = PyObject_Unicode(cs);
> Py_XINCREF(l_tmp_cb);
> Py_XDECREF(s_callback);
> s_callback=l_tmp_cb;
> l_result =
>
dapiRegisterCallback(l_hSession,l_pszConnectionString,Stub_Callback,l_pEx,&l_hCallback);
> 
> CHECK_RESULT;
> 
> return Py_BuildValue("l",l_hCallback);
> 
> }
> 
> ***
> This is the stub callback that crashes:
> ***
> void _stdcall Stub_Callback(HDEVICE p_dev, DWORD p_event, void *p_pEx)
> {
> PyObject *l_result;
> PyObject *l_arg_list;
> 
> l_arg_list = Py_BuildValue("(iii)", p_dev,p_event,p_pEx);
> l_result = PyEval_CallObject(s_callback, l_arg_list); /*No crash
> if I
> comment this line*/
> Py_DECREF(l_arg_list);
> }
> 
> 
> *
> This is the python source
> *
> (cs, and s have a correct value ... I think )
> import u3
> def mf(a,b,c):
>print 'CB'
> 
> h=u3.dapiRegisterCallback(s, cs, mf, 0)
> 
> 
> 
> 
> Any help _greatly_ appreciated.
> 
> Regards,
> 
> Philippe

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


Re: Whitespace test after string.split

2005-11-26 Thread Bengt Richter
On Sat, 26 Nov 2005 16:15:17 +0100, Peter Otten <[EMAIL PROTECTED]> wrote:

>David Pratt wrote:
>
>> Hi.  I am splitting a string on a non whitespace character. One or more
>> whitespace characters can be returned as items in the list. I do not
>> want the items in the list that are only whitespace (can be one or more
>> characters of whitespace) and plan to use string.strip on those items
>> that are not only whitespace (to remove any whitespace from front or
>> back of items).
>> 
>> What kind of efficient test can I use to obtain only list items
>> returned from the split that I am interested in, ignoring any list
>> items that would only be comprised of one or more characters of
>> whitespace (since whitespace can mean one or more spaces, tabs, and
>> other characters)
>
 s = "alpha, \t\n, gamma, delta,"
 s.split(",")
>['alpha', ' \t\n', ' gamma', ' delta', '']
 [t for t in s.split(",") if not t.isspace()]
>['alpha', ' gamma', ' delta', '']
 [t for t in s.split(",") if t and not t.isspace()]
>['alpha', ' gamma', ' delta']
 [t.strip() for t in s.split(",") if t and not t.isspace()]
>['alpha', 'gamma', 'delta']
>
>There you are.
Alternatively, possibly

 >>> [t for t in (t.strip() for t in s.split(",")) if t]
 ['alpha', 'gamma', 'delta']

>
>> As a second question, I am seeing string split as deprecated in 2.4.2
>> manual.  What is planned in future to split (strings or unicode)?
>
>Just use the corresponding methods, e. g. s.strip() instead of
>string.strip(s) etc.
>
>Peter
>

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


Re: wxPython Licence vs GPL

2005-11-26 Thread Mike Meyer
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Sat, 26 Nov 2005 18:18:44 -0500, Mike Meyer wrote:
>> So that's the basis of the disagreement. I'm using "restriction" with
>> the intent of communicating it's normal english meaning, 
> Your meaning is about as far from the plain English sense of "restrictive"

restiction != restrictive.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax

2005-11-26 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> If you use 'from os import *' then you shouldn't preface the commands
> with os.
> 
> So, two options:
> 
> from os import *
> print "Working Path: %s" % getcwd()
> 
> OR
> 
> import os
> print "Working Path: %s" % os.getcwd()
> 
> One of these two ways you're not supposed to use for security reasons,
> but I'm spacing on which one.

I don't think there are any *security* reasons, but stylistically,
"import os" is greatly preferred. When someone else reads your code,
they will immediately know where getcwd() comes from.

-- 
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: wxPython Licence vs GPL

2005-11-26 Thread Steven D'Aprano
On Sat, 26 Nov 2005 18:18:44 -0500, Mike Meyer wrote:

> The GPL is *not* such a license - it places
> restrictions on the redistribution. Which is what I said in the first
> place.

If you want me to agree that the GPL puts more conditions on distribution
than the MIT/BSD licence, then I'll happily agree. If you want me to
describe that as a "restrictive licence", then I refuse.

Look: would you agree that the BSD licence is a restrictive licence? You
can't get much more liberal than the BSD licence -- in fact some people
argue that if you are going to use a BSD licence, you might as well just
put the work in the public domain. I can respect the argument for putting
works in the public domain.

But *technically* the BSD licence does restrict the distributor, because
they must give attribution. But there is a difference between the
existence of a "restriction" and the licence being "restrictive". If you
can see that difference, you will understand why I do not agree to
describe the GPL as "restrictive" -- and if you can't see that difference,
then you must also describe the BSD licence as restrictive.

[snip]

> So that's the basis of the disagreement. I'm using "restriction" with
> the intent of communicating it's normal english meaning, 

Your meaning is about as far from the plain English sense of "restrictive"
as it is possible to get without actually contradicting the dictionary
meaning. And that's the reason for my vehement disagreement with the
suggestion that the GPL is "restrictive". 

We've already had one suggestion that if you ask 100 ordinary people what
free software means, 99 will say "free of cost" rather than free like
speech. (Thanks to Ed for that thought-experiment.)

I suggest that you if told 100 ordinary people that there is software that
allowed you to make as many copies as you liked, to give them away for
free or sell them for as much money as you wanted, to install it on as
many computers you liked, and that they didn't have to pay a single cent
for that software if they didn't want to, and that to be allowed to do
that all you had to do was to pass those rights on to those you give
the software to, then asked them if those conditions were "restrictive", I
think all 100 of them would look at you like you came from another planet.

If you want to use "restrictive" in the hair-splitting, pedantic,
non-plain English sense of "containing any restriction no matter how
infinitesimal", then please have the honesty to describe the BSD licence
as restrictive too. Then we can all agree that all software licences are
restrictive and that moral rights are restrictive ("but what if I *want*
to plagiarise the author of this public domain work?").

I think that your usage of the word is about as useful as plutonium
underwear, but if you are going to use it in that way, at least be
consistent.


-- 
Steven.

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


Syntax

2005-11-26 Thread calad . sigilon
If you use 'from os import *' then you shouldn't preface the commands
with os.

So, two options:

from os import *
print "Working Path: %s" % getcwd()

OR

import os
print "Working Path: %s" % os.getcwd()

One of these two ways you're not supposed to use for security reasons,
but I'm spacing on which one.

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


Re: Why are there no ordered dictionaries?

2005-11-26 Thread Bengt Richter
On Fri, 25 Nov 2005 19:42:49 +, Tom Anderson <[EMAIL PROTECTED]> wrote:

>On Wed, 23 Nov 2005, Carsten Haese wrote:
>
>> On Wed, 2005-11-23 at 15:17, Christoph Zwerschke wrote:
>>> Bengt Richter wrote:
>>>
>>> > E.g., it might be nice to have a mode that assumes d[key] is
>>> d.items()[k][1] when
>>> > key is an integer, and otherwise uses dict lookup, for cases where
>>> the use
>>> > case is just string dict keys.
>>>
>>> I also thought about that and I think PHP has that feature, but it's 
>>> probably better to withstand the temptation to do that. It could lead 
>>> to an awful confusion if the keys are integers.
>>
>> Thus quoth the Zen of Python:
>> "Explicit is better than implicit."
>> "In the face of ambiguity, refuse the temptation to guess."
>>
>> With those in mind, since an odict behaves mostly like a dictionary, [] 
>> should always refer to keys. An odict implementation that wants to allow 
>> access by numeric index should provide explicitly named methods for that 
>> purpose.
>
>+1
>
>Overloading [] to sometimes refer to keys and sometimes to indices is a 
>really, really, REALLY bad idea. Let's have it refer to keys, and do 
>indices either via a sequence attribute or the return value of items().
>
>More generally, if we're going to say odict is a subtype of dict, then we 
>have absolutely no choice but to make the methods that it inherits behave 
>the same way as in dict - that's what subtyping means. That means not 
>doing funky things with [], returning a copy from items() rather than a 
>live view, etc.
>
OTOH,
 >>> {}[:]
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: unhashable type
I.e., slices are not valid keys for ordinary dicts, and slices tie in
very well with the ordered aspect of ordered dicts, so that's an
argument for permitting it via the indexing syntax, not just items[:]
or items()[:] which have related but not identical semantics.

>So, how do we provide mutatory access to the order of items? Of the 
>solutions discussed so far, i think having a separate attribute for it - 
>like items, a live view, not a copy (and probably being a variable rather 
>than a method) - is the cleanest, but i am starting to think that 
>overloading items to be a mutable sequence as well as a method is quite 
>neat. I like it in that the it combines two things - a live view of the 
>order and a copy of the order - that are really two aspects of one thing, 
>which seems elegant. However, it does strike me as rather unpythonic; it's 
>trying to cram a lot of functionality in an unexpected combination into 
>one place. Sparse is better than dense and all that. I guess the thing to 
>do is to try both out and see which users prefer.
>
I wonder who is going to use it for what.

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


Re: Nested list comprehensions

2005-11-26 Thread Mike Meyer
[EMAIL PROTECTED] writes:
> Hey guys:
>
 [(i,j,k) for i in range(1,j) for j in range(1,k) for k in range(1,5)]
> [(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 1, 4), (1, 2, 1), (1, 2, 2), (1,
> 2, 3), (1, 2, 4), (1, 3, 1), (1, 3, 2), (1, 3, 3), (1, 3, 4), (2, 1,
> 1), (2, 1, 2), (2, 1, 3), (2, 1, 4), (2, 2, 1), (2, 2, 2), (2, 2, 3),
> (2, 2, 4), (2, 3, 1), (2, 3, 2), (2, 3, 3), (2, 3, 4)]

Give this a careful look: i varies slowest, and takes on the values 1
and 2. j varies next slowest, and takes on the values range(1, 4) in
both the i loops. k varies fastest, and goes through range(1, 5) in
all loops. I don't think it's doing what you intend.

 def a():
> ... print [(j,k) for j in range(1,k) for k in range(1,5)]
> ...
 a()
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 2, in a
> UnboundLocalError: local variable 'k' referenced before assignment
>
> Why is it that I can execute the nested list comprehension in the
> intepreter
> but if the same line is within a method declaration I get an unbound
> reference error?
>
> Is this a bug or am I missing some deep rule?

What are the values of the global variables j and k before you enter
the loop? Wouldn't happen to be 2 and 4, would they? Deleting them
first gives different results:

>>> del j
>>> del k
>>> [(i,j,k) for i in range(1,j) for j in range(1,k) for k in range(1,5)]
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'j' is not defined

Methinks you want your for loops in the opposite order.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested list comprehensions

2005-11-26 Thread Carl Waldbieser
[EMAIL PROTECTED] wrote:

> Hey guys:
> 
 [(i,j,k) for i in range(1,j) for j in range(1,k) for k in range(1,5)]
> [(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 1, 4), (1, 2, 1), (1, 2, 2), (1,
> 2, 3), (1, 2, 4), (1, 3, 1), (1, 3, 2), (1, 3, 3), (1, 3, 4), (2, 1,
> 1), (2, 1, 2), (2, 1, 3), (2, 1, 4), (2, 2, 1), (2, 2, 2), (2, 2, 3),
> (2, 2, 4), (2, 3, 1), (2, 3, 2), (2, 3, 3), (2, 3, 4)]
 def a():
> ... print [(j,k) for j in range(1,k) for k in range(1,5)]
> ...
 a()
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 2, in a
> UnboundLocalError: local variable 'k' referenced before assignment
> 
> Why is it that I can execute the nested list comprehension in the
> intepreter
> but if the same line is within a method declaration I get an unbound
> reference error?
> 
> Is this a bug or am I missing some deep rule?
> 
> Regards, Neil Dunn
You may not be getting the name error in the interpreter because you already
defined those variables.  Try this:

$ python
>>> [(j,k) for j in range(1,k) for k in range(1,5)]
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'k' is not defined
>>>

Looks like the variable was not defined here, either.

You are trying to use the variable "k" in the range() function before it has
been bound to anything, hence the error.


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


Re: Why are there no ordered dictionaries?

2005-11-26 Thread Bengt Richter
On Thu, 24 Nov 2005 18:42:45 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> 
wrote:

>Bengt Richter schrieb:
>
>>>d.setvalues((13, 14)) ==> d = OrderedDict((1, 13), (2, 14))
>
>> The implication above is that OrderedDict takes an *args argument,
>> but really it takes a single argument that is a sequence of k,v pairs,
>> (and maybe some keyword options).
>
>Right. Interpret it as a short notation only, I did not want to change 
>the interface. I think it's a common mistake to forget the brackets 
>because you think one pair should be enough. At least I often forget it.
Ok, I forget this too.
>
>> You could make keys, values, and items custom descriptors which would define 
>> __call__
>> for the old key() etc accesses, well as __getitem__ and __setitem__. Then 
>> you could write
>> 
>> d.items[0], d.items[-1] = d.items[-1], d.items[0]
>> 
>> to swap the order of the first and last items in the thing (I hesitate to 
>> say dict ;-)
>> You could also operate on slices.
>
>Nice. You could also get the i-th value with d.values[i].
>
>But is this considered good style or would it be considered "dirty" to 
>have a callable member that also supports indexing and slicing? (I don't 
>know, just asking?) Plus, it opens a can of worms by increasing the 
>complexity tremendously. Let's see whether this can be handled.
I suspect not that complex, but it has the same performance disadvantage as
properties.

>
>> BTW, before I showed an example where d[2:3] returned
>> a new dict instance rather than d.items()[:]. I think the items list
> > is better, since they naturally add, sort, reverse, etc as lists,
> > and you can write OrderedDict(d[2:3]+d[1:2]) if you want a new dict.
>
>Not sure about that. I would rather expect that if you slice an object, 
>you get an object of the same type. And you can also add, sort, reverse, 
>etc the ordered dict if you want.
>
>> A slice assignment to d[i:j] is really sugar for something, but we have to 
>> decide exactly
>> what in case of duplicate keys in the incoming items, either with each other 
>> ...
>
>You mean slice assignments to d.items[i:j]. If you make the slice 
>assignment to d[i:j] then at least you cannot have conflicts in the 
>incoming items. The first question is: Should a slice assignment be 
>treated as deletion with subsequential addition (changing the order) or 
>as a replacement (i.e. try to not change the order)? I agree that the 
>second would be the expected semantics, but as you mentioned more 
>difficult to implement.
>
> > One way to define it would be
> > d.items[i:j] = itemseq
>> 
>> to be implemented as sugar for
>> newitems = d.items[:i] + list(itemseq) + d.items[j:]
>> d.clear()
>> d.update(newitems)
>
>Which should be the same as
>d = OrderedDict(d.items[:i] + list(itemseq) + d.items[j:])
>Sounds reasonable.
Actually it's not the same, which is why I wrote it with update.
Analogous to slice assignment in lists, the referred-to object
gets mutated. Hence preexisting references to the object see the change too.

If you just rebind d with a new OrderedDict object, previous bindings
are not affected. I.e.,
   d = OrderedDict(sorted((k,i)) for i,k in enumerate('abc'))
   e = d
   d = OrderedDict(d.items[:1] + [('b', 100)] + d.items[2:])
   d.items()[1] # => ('b', 100)
   e.items()[1] # => ('b', 1)   # unaffected


>
>> So
>> d.reverse()
>> could be spelled
>> d.items[:] = d.items[::-1]
>
>Slice assignment for keys and values would also allow to set a new key 
>order with
>
>d.keys[:] = newkeyseq
Do you really mean just re-ordering the keys without a corresponding reording 
of values??
That would be a weird renaming of all values. Or do you means that any key 
should still
retrieve the same value as before if used as d[key]? In which case the values 
must undergo
the same permutation as the keys. I.e., you are assuming key->value pairings 
remain stable
through any key reorderings?

>
>So no need to define a setkeys() method or let keys() take arguments.
>If we want to allow this kind of things at all.
>
>> If you are using slices, you can safely use them directly in the __getitem__ 
>> of th dict interface,
>> as I did in the "Que mas?" post. So we don't have to write d.items[i:j] and 
>> could write d[i:j].
>> The thing is, d[i:j] will tempt to skip ".items" in d.items[i] and write 
>> d[i], which has the dict
> > key meaning, not the item list index. It is faster not have a 
>descriptor between though.
>
>I still think d[i:j] should return an ordered dict, not an item list.
Easy to do either way.

>
>> I think maybe allowing write to keys or values is pretty iffy. There are too 
>> many weird
>> re-associations of keys and values possible, and which you could do my other 
>> means if you
>> really really wanted to. But I do think full index and slice read access 
>> would be fine.
>
>There are different opinions. Fuzzyman would probably say "Don't trust 
>yourself?" I myself am undecided. Perhaps you cou

Re: CGI question

2005-11-26 Thread Mike Meyer
Dan Stromberg <[EMAIL PROTECTED]> writes:
> On Sat, 26 Nov 2005 13:26:11 +0100, Fredrik Lundh wrote:
>> Dan Stromberg wrote:
>>> What's the best way of converting this:
>>> 'hide\\?http://www.dedasys.com/articles/programming_language_economics.html\x012005-07-20
>>> 14:48'
>>> ...to something easily usable in a python CGI script?
>> easily usable for what purpose?
>> if you want to extract the URL that seems to be hidden in that string,
>> something like:
>> url, junk = text.split("\x01", 1)
>> junk, url = url.split("\\?", 1)
>> should work.
> But I thought there might be a python module intended for parsing inputs
> to CGI scripts?  Sometimes using a pre-written module can contend with
> issues you didn't know where going to come up...

Generally, input to CGI scripts are done via the Common Gateway
Interface (CGI). The cgi module does those things.  Your example
doesn't look anything like a CGI string, though. Maybe if you told us
where it came from, we could recommend a module for dealing with such.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Nested list comprehensions

2005-11-26 Thread neildunn
Hey guys:

>>> [(i,j,k) for i in range(1,j) for j in range(1,k) for k in range(1,5)]
[(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 1, 4), (1, 2, 1), (1, 2, 2), (1,
2, 3), (1, 2, 4), (1, 3, 1), (1, 3, 2), (1, 3, 3), (1, 3, 4), (2, 1,
1), (2, 1, 2), (2, 1, 3), (2, 1, 4), (2, 2, 1), (2, 2, 2), (2, 2, 3),
(2, 2, 4), (2, 3, 1), (2, 3, 2), (2, 3, 3), (2, 3, 4)]
>>> def a():
... print [(j,k) for j in range(1,k) for k in range(1,5)]
...
>>> a()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 2, in a
UnboundLocalError: local variable 'k' referenced before assignment

Why is it that I can execute the nested list comprehension in the
intepreter
but if the same line is within a method declaration I get an unbound
reference error?

Is this a bug or am I missing some deep rule?

Regards, Neil Dunn

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


Re: Call OCX from python?

2005-11-26 Thread Claudio Grondi
"JustSomeGuy" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> Hi I have a commercial OCX that I want to use in
> my python application.  How do I call OCXs from
> python?
> TIA

import win32com.client
axOCX =
win32com.client.Dispatch("RegistryEntryForThisOCXin[VersionIndependentProgID
]section")
retVal = axOCX.methodOfThisOCX(param1, param2)
value = axOCX.attributeOfThisOCX

Claudio


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


scanl in python

2005-11-26 Thread [EMAIL PROTECTED]
>I think that the test for an empty iterator makes ireduce() unintuitive. Try
>asking someone who has not followed the discussion
>what list(ireduce(add, [], 42)) might produce, given that

>list(ireduce(add, [1], 42)) --> [43]
>list(ireduce(add, [1, 2], 42)) --> [43, 45]
>list(ireduce(add, [])) --> []
>list(ireduce(add, [1])) --> [1]
>list(ireduce(add, [1, 2])) --> [1, 3]

>I suspect that [42] will be a minority vote.

Don't know about the intend, but if it is duplicate of scanl(say on
Haskell), it is  :

list(ireduce(add, [1], 42)) --> [42, 43]
list(ireduce(add, [1, 2], 42)) --> [42, 43, 45]

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


Re: SOAP - Beginner Desperately looking for Help

2005-11-26 Thread Diez B. Roggisch
> I wanted to attach these - however, 
> taht didn't work for NNTP, so I mail them to you.

Didn't work - my mail server won't let me send these to you. So you're 
on your own here. Shouldn't be too hard :)

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


Re: SOAP - Beginner Desperately looking for Help

2005-11-26 Thread Diez B. Roggisch
Rodney Garland wrote:
> Hi All,
> 
> I am a relative beginner to Python and am looking for help with sending and 
> XML message and getting back a return file.  The server is:
> 
> https://node.deq.state.or.us/node/node.asmx
> 
> I have have successfully sent and recieved using the PING, AUTHENTICATE 
> (send in username and password and return a secuirity token), SOLICIT(send 
> in information for a query and get a number indicating the query), 
> GETSTATUS(status of query) using SOAPpy.  I am using Python 2.4 on a Window 
> XP machine.
> 
> What I want to do now is download the result of my query using the DOWNLOAD 
> method.  However, I cann't figure out how to do this.  I have tried SOAPpy 
> and httplib and I cann't send the correct XML outgoing message.  Any help 
> with this would be greatly appreciated.  Following is the needed outgoing 
> XML file and my successful SOAPpy code.

Use wsdl2py(.py). It come with e.g. ZSI, but SOAPpy also use wsdltools - 
which should include it. There is a WSDL given at the site, passing it 
to wsdl2py results in type-definitions. Use these as arguments to 
download - hopefully, that helps. I wanted to attach these - however, 
taht didn't work for NNTP, so I mail them to you.

This whole mess is another reason to depsise SOAP and stick to xmlrpc or 
better CORBA, btw.

Regards,

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


Re: CGI question

2005-11-26 Thread Dan Stromberg
On Sat, 26 Nov 2005 13:26:11 +0100, Fredrik Lundh wrote:

> Dan Stromberg wrote:
> 
>> What's the best way of converting this:
>>
>> 'hide\\?http://www.dedasys.com/articles/programming_language_economics.html\x012005-07-20
>> 14:48'
>>
>> ...to something easily usable in a python CGI script?
> 
> easily usable for what purpose?
> 
> if you want to extract the URL that seems to be hidden in that string,
> something like:
> 
> url, junk = text.split("\x01", 1)
> junk, url = url.split("\\?", 1)
> 
> should work.

Um, yeah.  I can work out this sort of thing.

But I thought there might be a python module intended for parsing inputs
to CGI scripts?  Sometimes using a pre-written module can contend with
issues you didn't know where going to come up...

Thanks!


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


Re: Comparison problem

2005-11-26 Thread Alex Martelli
Tom Anderson <[EMAIL PROTECTED]> wrote:
   ...
> But, more importantly, egad! What's the thinking behind having slicing
> behave like that? Anyone got any ideas? What's the use case, as seems to
> be the fashionable way of putting it these days? :)

Slicing has always been "soft" (it's OK to specify slice indices beyond
the boundaries) while indexing has always been "hard" (specifying an
index beyond the boundaries raises an exception).  It does allow simpler
and more concise expression of conditions on slices, without requiring
you to guard the test on the slice with another test on the sequence's
length.  For example, to say "those sublists of lists-of-lists bigL that
don't end in [...1,2,3]" you can code

[L for L in bigL if L[-3:] != [1,2,3]]

instead of

[L for L in bigL if len(L) < 3 or L[-3:] != [1,2,3]]

Introducing the endswith and startswith string methods lowered the
usefulness of soft slicing for such tests on strings (since it
subtracted some specific use cases), but not all sequences have such
specialized methods, and not all use cases of soft slicing are tests.
E.g., "remove the last character of s (if any)" can be compactly
expressed with "s=s[:-1]" rather than "s=s and s[:-1]" or more expansive
testing.  No big deal, but then again I don't recall any situation in
which getting an exception from slicing (as opposed to indexing) would
have helped me catch a bug faster.


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


Re: 2d array slicing problem

2005-11-26 Thread Robert Kern
Tune Kamae (sent by Nabble.com) wrote:
> I am thinking to upgrade my desktop to 64bit cpu with 16GB memory to handle
> large astronomical images and data.  I wonder if
> 1) the latest numarry (besides 2d slicing) has been tested with one or more
> 64 bit CPU and Linux distributions

Certainly.

> 2) with 64 bit address space, will numarray be able to handle larger arrays
> and matrices (many 3d-arrays 100x100x100 and matrices 50k x 50k)?
> (with 32 bit CPU I was limited by the memory.)
> 
> I would appreciate knowing about your experience.

You'll probably want to ask on the appropriate mailing list[1], but
since you ask here, I will say that there are limitations that prevent
numarray from fully utilizing 64-bit systems. numarray uses the Python
buffer interface which is addressed by 32-bit integers even on 64-bit
platforms[2]. There has been some work on numarray's replacement,
scipy_core, to address this deficiency, but more work needs to be done
and more volunteers with 64-bit systems are needed. 100x100x100 arrays
should work with numarray; 5x5 perhaps not. You could always try
and let us know.

[1] http://lists.sourceforge.net/lists/listinfo/numpy-discussion
[2] http://permalink.gmane.org/gmane.comp.python.numeric.general/2690

-- 
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: Comparison problem

2005-11-26 Thread Peter Hansen
Tom Anderson wrote:
> On Sat, 26 Nov 2005, Peter Hansen wrote:
>>Tom Anderson wrote:
>>>On Sat, 26 Nov 2005, Chris wrote:
  if item[0:1]=="-":
>>>
>>>item[0:1] seems a rather baroque way of writing item[0]! I'd actually 
>>>suggest writing this line like this:
>>
>>Actually, it's not so much baroque as it is safe... item[0] will fail if 
>>the string is empty, while item[0:1] will return '' in that case.
> 
> Ah i didn't realise that. Whether that's safe rather depends on what the 
> subsequent code does with an empty string - 

I meant "safe" as in "doesn't throw an exception", as item[0] will when 
passed an empty string...  sometimes you don't want code to throw an 
exception, and you don't want to have to do a separate test for certain 
conditions that might do so.  This technique is one example.

> an empty string might be some 
> sort of error (in this particular case, it would mean that the loop test 
> had gone wrong, since bool("") == False), and the slicing behaviour would 
> constitute silent passing of an error.
> 
> But, more importantly, egad! What's the thinking behind having slicing 
> behave like that? Anyone got any ideas? What's the use case, as seems to 
> be the fashionable way of putting it these days? :)

Well, since slicing is (I believe, and speaking only roughly) supposed 
to return a sequence of the same type as that on which it's operating, 
what would be the alternative?  Unless you allow slicing to return None, 
or raise an exception in certain cases, return a null sequence of the 
appropriate type seems to be perfectly logical behaviour when the 
requested slice doesn't exist in the input.

But I'm not sure this is from a specific use case so much as a side 
effect of other more desirable behaviours of slicing.  Asking for this 
to behave differently without analyzing the impact it has on slicing in 
general is likely to overlook something crucial...

-Peter

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


New docs for set elements/dictionary keys (Was: Why is dictionary.keys() a list and not a set?)

2005-11-26 Thread Mike Meyer
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>>>This is not true. The second definition of __hash__ does not meet
>>>the specifications:
>> The specification isn't on the __hash__ method, but on objects.
> What does it mean for a specification to be "on" something? The
> specification I quoted is listed "under" the __hash__ heading
> of the reference manual.

"applies to"

>> That's pretty flaky. The same docs say:
>> Should return a 32-bit integer usable as a hash value for dictionary
>> operations.
> What is flaky about this?

What's flaky is the claim in the docs that "the *only* requirement is
...". There are clearly other requirements, and they're listed in the
same paragraph as that requirement.

>> the dictionary implementation requires that a key's hash value is
>> immutable
> Indeed, the question here is: what does "an object is immutable"
> mean in this context? You appear to read it as "an object whose
> state does not change", however, what it really means is "an object
> which will always use the same state in __hash__ and __eq__".

I've given up on trying to say what "immutable" means, because common
usage in the CS and Python communities is ambiguous when it comes to
container objects. You give an unambiguous definition, but it's
specific to python, and clashes with common usage in the CS and Python
communities. Every old-style class that doesn't define __hash__,
__eq__ or __cmp__ is immutable by that definition, even if it has
mutator methods. Similar comments apply to new-style classes, but
require more work to pin down.

That's the reason this thread went the direction it did - because I
started discussing fixing the docs to not use "immutable" as the
defining property.

>> Maybe those are only "recommended" properties, but any class that
>> doesn't meet them is going to have instances with interesting
>> behaviors in sets and as dictionary keys.
> Indeed, you can anything return you want in __hash__, or always
> raise an exception. What precisely the result of dictionary
> operations is when you do so is undefined in Python.

I certainly hope that if __hash__ raises an exception, dictionary
operations pass the exception on to their caller. For the other cases,
undefined behavior is perfectly reasonable.

Back onto topic:

If you want to use your definition of "immutable" in the docs for
dictionary keys and set elements, I think that the docs should
explicitly include that definition. We can probably come up with a
less ambiguous (does "same state" mean "same state variables" or
"variables that don't change value"?) wording as well.

Personally, I think we'd be better off to come up with a term for this
property that doesn't have a commonly understood meaning that has such
broad areas of disagreement with the property. I've been using
"hashable", which I would currently define as "has a __hash__ method
with the properties described in the __hash__ documentation, or does
not have either a __cmp__ or a __eq__ method." Listing which builtin
types are hashable and which aren't (and which vary on an
instance-by-instance basis) would seem to be worthwhile as well.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


SOAP - Beginner Desperately looking for Help

2005-11-26 Thread Rodney Garland
Hi All,

I am a relative beginner to Python and am looking for help with sending and 
XML message and getting back a return file.  The server is:

https://node.deq.state.or.us/node/node.asmx

I have have successfully sent and recieved using the PING, AUTHENTICATE 
(send in username and password and return a secuirity token), SOLICIT(send 
in information for a query and get a number indicating the query), 
GETSTATUS(status of query) using SOAPpy.  I am using Python 2.4 on a Window 
XP machine.

What I want to do now is download the result of my query using the DOWNLOAD 
method.  However, I cann't figure out how to do this.  I have tried SOAPpy 
and httplib and I cann't send the correct XML outgoing message.  Any help 
with this would be greatly appreciated.  Following is the needed outgoing 
XML file and my successful SOAPpy code.

Thank you,

Rodney ([EMAIL PROTECTED])

POST /node/node.asmx HTTP/1.1
Host: node.deq.state.or.us
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: ""


http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"; 
xmlns:tns="http://www.ExchangeNetwork.net/schema/v1.0/node.wsdl"; 
xmlns:types="http://www.ExchangeNetwork.net/schema/v1.0/node.wsdl/encodedTypes"; 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
  http://schemas.xmlsoap.org/soap/encoding/";>
http://www.ExchangeNetwork.net/schema/v1.0/node.xsd";>
  string
  string
  string
  

http://www.ExchangeNetwork.net/schema/v1.0/node.xsd"; 
soapenc:arrayType="q1:NodeDocument[2]">
  
  

http://www.ExchangeNetwork.net/schema/v1.0/node.xsd";>
  string
  string

http://www.ExchangeNetwork.net/schema/v1.0/node.xsd";>
  string
  string

  

Below is an example of the code that does work.

urlNode = 'https://node.deq.state.or.us/node/node.asmx?op=NodePing'
namespace = 'http://www.ExchangeNetwork.net/schema/v1.0/node.xsd'
server = SOAPProxy(urlNode, namespace)
PING = server.NodePing('Ping')

urlAuth = 'https://node.deq.state.or.us/node/node.asmx?op=Authenticate'
# AUTHENTICATE - Returns a variable with the token
server = SOAPProxy(urlAuth, namespace)
token = server.Authenticate(userId='MYUSERNAME', credential='MYPASSWORD', 
authenticationMethod='Invoke')
print token

urlSolicit = 'https://node.deq.state.or.us/node/node.asmx?op=Solicit'
server = SOAPProxy(urlSolicit, namespace)
rowID='0'
maxRows='1000'
service='GetAirMeasurements'
fieldEventStartDate='2005-01-01'
fieldEventEndDate='2005-02-01'
analyteName='PM10'
parameters=[rowID,maxRows,'','','','','','','','','','','','','','','',fieldEventStartDate,fieldEventEndDate,'',analyteName]
transID = server.Solicit(securityToken = token, returnURL = '', request = 
'GetAirMeasurements', parameters = parameters)
print transID





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


Re: 2d array slicing problem

2005-11-26 Thread Tune Kamae (sent by Nabble.com)

I am thinking to upgrade my desktop to 64bit cpu with 16GB memory to handle
large astronomical images and data.  I wonder if 
1) the latest numarry (besides 2d slicing) has been tested with one or more 
    64 bit CPU and Linux distributions
2) with 64 bit address space, will numarray be able to handle larger arrays 
    and matrices (many 3d-arrays 100x100x100 and matrices 50k x 50k)?
    (with 32 bit CPU I was limited by the memory.)

I would appreciate knowing about your experience.

Tune Kamae, SLAC/KIPAC, Stanford University 
    

Sent from the Python - python-list forum at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Comparison problem

2005-11-26 Thread Tom Anderson
On Sat, 26 Nov 2005, Peter Hansen wrote:

> Tom Anderson wrote:
>> On Sat, 26 Nov 2005, Chris wrote:
>> 
>>>   if item[0:1]=="-":
>> 
>> item[0:1] seems a rather baroque way of writing item[0]! I'd actually 
>> suggest writing this line like this:
>
> Actually, it's not so much baroque as it is safe... item[0] will fail if 
> the string is empty, while item[0:1] will return '' in that case.

Ah i didn't realise that. Whether that's safe rather depends on what the 
subsequent code does with an empty string - an empty string might be some 
sort of error (in this particular case, it would mean that the loop test 
had gone wrong, since bool("") == False), and the slicing behaviour would 
constitute silent passing of an error.

But, more importantly, egad! What's the thinking behind having slicing 
behave like that? Anyone got any ideas? What's the use case, as seems to 
be the fashionable way of putting it these days? :)

tom

-- 
This should be on ox.boring, shouldn't it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparison problem

2005-11-26 Thread Peter Hansen
Tom Anderson wrote:
> On Sat, 26 Nov 2005, Chris wrote:
> 
>>   if item[0:1]=="-":
> 
> item[0:1] seems a rather baroque way of writing item[0]! I'd actually 
> suggest writing this line like this:

Actually, it's not so much baroque as it is safe... item[0] will fail if 
the string is empty, while item[0:1] will return '' in that case.

Of course, as you point out, .startswith() is the better approach anyway.

-Peter

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


Re: Why is dictionary.keys() a list and not a set?

2005-11-26 Thread Martin v. Löwis
Mike Meyer wrote:
>>This is not true. The second definition of __hash__ does not meet
>>the specifications:
> 
> 
> The specification isn't on the __hash__ method, but on objects.

What does it mean for a specification to be "on" something? The
specification I quoted is listed "under" the __hash__ heading
of the reference manual.

> Instances of mylist2 that aren't otherwise tweaked won't meet the
> specification.

Right, that's what I meant.

> That's pretty flaky. The same docs say:
> 
> Should return a 32-bit integer usable as a hash value for dictionary
> operations.

What is flaky about this?

> the dictionary implementation requires that a key's hash value is
> immutable

Indeed, the question here is: what does "an object is immutable"
mean in this context? You appear to read it as "an object whose
state does not change", however, what it really means is "an object
which will always use the same state in __hash__ and __eq__".

> Maybe those are only "recommended" properties, but any class that
> doesn't meet them is going to have instances with interesting
> behaviors in sets and as dictionary keys.

Indeed, you can anything return you want in __hash__, or always
raise an exception. What precisely the result of dictionary
operations is when you do so is undefined in Python.

> That's a problem with mylist2 instances, and may or may not be a
> problem in the mylist2 __hash__ method. You can't tell just by
> examining the __hash__ method whether or not it meets this
> specification.

Correct. I would expect that this is the case for any specification
of __hash__ you can come up with: __hash__ would typically refer
to the state of the object, and whether or not the results meets
some specified requirement would also depend on what the state is.
(unless either the specification is trivial (e.g. "may or may
not return a value") or the implementation is trivial (e.g.
"return 0"))

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


Re: Cheapest pocket device to code python on

2005-11-26 Thread Ten
On Friday 04 November 2005 03:55, [EMAIL PROTECTED] wrote:
> What is the cheapest/affordable pocket device that I can code python
> on? I think the closest I have seen is pocketpc from this page:
>
> http://www.murkworks.com/Research/Python/PocketPCPython/Overview

Depends what you're using it for, and how cheap you mean.

Having seen the PocketPC angle covered, I may as well cover a different angle 
give an even cheaper option.

I use an old epocpython on a Psion Revo Plus for jotting down python concepts
and testing out ideas, and I wouldn't be without it - especially because the 
Revo keyboard is usable in a way touchscreens aren't for me.

It's not the most extensive python installation, and it won't stand much 
earthshifting (it doesn't include some modules, like tkinter) but it's a hell 
of a lot of portable python considering the fact you can pick one up for 
around 10 to 20 squids on ebay.

Better keyboard than a pda, portable python for next to nothing.

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


Re: Which License Should I Use?

2005-11-26 Thread Ben Finney
Jorgen Grahn <[EMAIL PROTECTED]> wrote:
> Tom Anderson <[EMAIL PROTECTED]> wrote:
> > The logic, i think, is that the freedom of the code is the key to
> > the freedom of the end-users: applying the GPL to your code means
> > that other programmers will be forced to apply to to their code,
> > which means that users of that code will get the benefits of open
> > source.
> 
> ... which implies that one believes that every end-user has the
> potential to become a hacker.

To become, or *independently engage another person as* a hacker
without necessary further contact with the copyright holder.

The same freedom you get with, e.g., any complicated machine. You can
open it up yourself, or you can persuade a third party to do so,
without the necessity to get the maker involved.

It's not necessary for every single user of such machines to become
hackers of those machines; they still all get the benefit of the
freedom for anyone they choose to hack on it.

-- 
 \   "I have a map of the United States; it's actual size. It says |
  `\   '1 mile equals 1 mile'... Last summer, I folded it."  -- Steven |
_o__)   Wright |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython Licence vs GPL

2005-11-26 Thread Mike Meyer
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Sat, 26 Nov 2005 04:46:15 -0500, Mike Meyer wrote:
>> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>>> But if you *do* redistribute it, then you must live up to conditions in
>>> the licence. If you aren't willing to do that, use software with a
>>> different licence. 
>> That's a restriction on redistribution.
> ALL licences make that "restriction". There is no licence that allows you
> to distribute the product in contradiction to the terms of the licence.

True. Some license have terms which don't place any restrictions on
redistribution. The GPL is *not* such a license - it places
restrictions on the redistribution. Which is what I said in the first
place.

>>> The only restriction is that you can't give those people fewer, weaker
>>> rights than you got
>> That's a restriction on redistribution.
> Well now we're getting somewhere. 
> That's a restriction 

Which is exactly what I said in the first place that you disagreed
with.

> that actually *increases* freedom so I don't see it as a restriction
> at all -- I see it as something that enables rather than disables.

So that's the basis of the disagreement. I'm using "restriction" with
the intent of communicating it's normal english meaning, and you're
using it with the intent of making a political statement. When you say
"restriction", you mean "restriction that I think of as bad". If
you're willing to do that, proprietary commercial software has no
restriction on redistribution.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is dictionary.keys() a list and not a set?

2005-11-26 Thread Mike Meyer
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>>>class mylist1(list):
>>> def __hash__(self): return 0815
>>>
>>>class mylist2(list):
>>> def __hash__(self): return id(self)
>>>
>>>In the case of mylist1, everything is ok including semantics, but
>>>performance suffers dramatically. In mylist2, performance is great,
>>>but semantics suffers greatly.
>>>Which of these user-defined types would you call "hashable"?
>> The latter two, as the given __hash__ meets the specifications for
>> __hash__.
> This is not true. The second definition of __hash__ does not meet
> the specifications:

The specification isn't on the __hash__ method, but on objects.
Instances of mylist2 that aren't otherwise tweaked won't meet the
specification.

> http://docs.python.org/ref/customization.html
> "The only required property is that objects which compare equal have the
> same hash value"

That's pretty flaky. The same docs say:

Should return a 32-bit integer usable as a hash value for dictionary
operations.

the dictionary implementation requires that a key's hash value is
immutable

Maybe those are only "recommended" properties, but any class that
doesn't meet them is going to have instances with interesting
behaviors in sets and as dictionary keys.

FWIW, the mutable builtins have __hash__ methods that don't meet that
requirement. Instances of them don't have has values at all.

> However, I can have two instances of mylist2 which compare equal,
> yet have different hash values.

That's a problem with mylist2 instances, and may or may not be a
problem in the mylist2 __hash__ method. You can't tell just by
examining the __hash__ method whether or not it meets this
specification.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (Nov 26)

2005-11-26 Thread Cameron Laird
QOTW:  "... '[B]ut assume that I have some other use case' isn't a valid
use case". - Fredrik Lundh

"Rolling your own solution, on the other hand, can end in a long road
discovering what those CORBA people were doing for all those years." - Paul
Boddie


NOTW:  sceptifications.


Steven D'Aprano carefully details a common confusion among
newcomers about empty lists and initialization:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8480fae54a64fc15/

Inyeol Lee and others illustrate use of regular expression
syntax having to do with repeated patterns:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b5e7abb4ff1e156c/

Metakit 2.4.9.5 corrects a potential disk-full error, and
improves performance greatly in certain circumstances:
http://www.equi4.com/pub/mk/CHANGES
http://www.equi4.com/metakit.html

William Peterson jokes that, "[i]f you ask ten people on 
this newsgroup [about GUI construction newcomers] you'll
probably get twelve opinions"--and then the community 
promptly proves him right:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6fd1ea6b4a2d31f8/

Having arrived in the twenty-first century, clp now has 
its own (provisional) podcast:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b39581f59dce9191/

David Wahler cogently perverts^H^H^H^H^H^H^H^Hextends pickle
to serialize *classes* (as opposed to their instances):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/10a03f094303a91c/

Fully-general backward-compatibility has substantial costs,
often greater than the version migration it's supposed to
spare us.  Several of the regulars discuss this seriously:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/423d9dfa80456966/

__slots__ are only a (memory) optimization, restricted to
well-defined circumstances, explains the martellibot:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/1cc68de7af477386/

A good thing about Cheetah is that it cooperates with Python's
inheritance:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f063406b648c7d0c/


Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%2

Re: Which License Should I Use?

2005-11-26 Thread Robert Kern
mojosam wrote:

> I would have to talk to a lawyer to be sure, but right now, I think I
> can argue that anything I do on my own time belongs to me.  I'm
> technically a consultant right now (even though I'm spending 40
> hours/week with the one "client").  I can take on other clients, as
> long as they don't directly compete.  This means they're hiring my
> expertise.  If I bring my own tools, that's part of my expertise.  I do
> recall there was a clause in the contract that anything I did on their
> time belonged to them.  For my next client, I should definitely include
> a clause about rereleasing open source changes.

You're in something of a gray area, but one that has seen a lot of
litigation. Although you are "technically" a consultant, you are
probably considered an employee with regards to the "work made for hire"
doctrine. You should probably have a chat with a lawyer soon (I am not
one! TINLA!).

As Steve Holden said, being open with your client and putting an
agreement in your contract is probably the best way to ensure that your
work will belong to you or, failing that, continue to be available to
you under an open source license.

-- 
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: Why is dictionary.keys() a list and not a set?

2005-11-26 Thread Martin v. Löwis
Christoph Zwerschke wrote:
>> This is not true. The second definition of __hash__ does not meet
>> the specifications:
>> "The only required property is that objects which compare equal have the
>> same hash value"
> 
> 
> As Mike has written in his last posting, you could easily "fix" that by 
> tweaking the equality relation as well. So technically speaking, Mike is 
> probably right.

No. If you define both __hash__ and __eq__ consistently, then __hash__
would meet the specification. As posted in the example, __hash__ does
not meet the specification, contrary to Mike's claim that it does.

> It would completely break common-sense semantics, 
> because for mylist2, if I have a=[1] and b=[1] then I will have a!=b. 
> This would not be very reasonable, but probably allowed by Python.

If you have a=[1] and b=[1], then *always* a==b; you cannot
change the semantics of list displays. To achieve !=, you
would need to have a=mylist2([1]), b=mylist([2]). Whether or not
it is common sense that classes named "mylist2" compare equal
if they consist of the same items, I don't know - I personally don't
have any intuition as to what a class named "mylist2" should or
should not do.

Just that it has "list" in its name provides not sufficient clue: for
example, IdentityDictionary has "dictionary" in its name, yet I would
*not* expect that equality is used to compare keys, but instead I
would expect that identity is used.

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


Re: Crash in python while run from U3 device

2005-11-26 Thread Philippe C. Martin
Philippe C. Martin wrote:

> Hi,
> 
> I am currently porting some of my applications to U3 (www.u3.com) and I do
> get a crash in ...objects\frameobject.c: PyFrameObject *back =
> tstate->frame.
> 
> The point of the current test is to get a python function called on a U3
> device event. (U3 only work with Windows currently).
> 
> My C stub callback does get called but crashes when it tries to call the
> python function.
> 
> 
> 
> ***
> This is the function that registers the callback (actual dll prototype in
> header):
> ***
> static PyObject *s_callback=NULL;
> /**/
> /**/
> /* HRESULT dapiRegisterCallback(   HSESSION hSession ,wchar_t*
> pszConnectionString ,DAPI_CALLBACK pCallBack,void* pEx ,HCALLBACK*
> hCallback) */
> /**/
> /**/
> 
> static PyObject *Py_dapiRegisterCallback(PyObject *p_self, PyObject
> *p_args)
> {
> HRESULT l_result;
> HSESSION l_hSession;
> wchar_t* l_pszConnectionString;
> PyObject *l_tmp_cb;
> //PyObject cs;
> void* l_pEx;
> HCALLBACK l_hCallback;
> 
> if
>
(!PyArg_ParseTuple(p_args,"iuOi",&l_hSession,&l_pszConnectionString,&l_tmp_cb,&l_pEx)
> )
> {
> BAD_PARAM;
> return NULL;
> }
> //l_pszConnectionString = PyObject_Unicode(cs);
> Py_XINCREF(l_tmp_cb);
> Py_XDECREF(s_callback);
> s_callback=l_tmp_cb;
> l_result =
>
dapiRegisterCallback(l_hSession,l_pszConnectionString,Stub_Callback,l_pEx,&l_hCallback);
> 
> CHECK_RESULT;
> 
> return Py_BuildValue("l",l_hCallback);
> 
> }
PS: the crash is in PyFrame_New

Thanks,

Philippe



> 
> ***
> This is the stub callback that crashes:
> ***
> void _stdcall Stub_Callback(HDEVICE p_dev, DWORD p_event, void *p_pEx)
> {
> PyObject *l_result;
> PyObject *l_arg_list;
> 
> l_arg_list = Py_BuildValue("(iii)", p_dev,p_event,p_pEx);
> l_result = PyEval_CallObject(s_callback, l_arg_list); /*No crash
> if I
> comment this line*/
> Py_DECREF(l_arg_list);
> }
> 
> 
> *
> This is the python source
> *
> (cs, and s have a correct value ... I think )
> import u3
> def mf(a,b,c):
>print 'CB'
> 
> h=u3.dapiRegisterCallback(s, cs, mf, 0)
> 
> 
> 
> 
> Any help _greatly_ appreciated.
> 
> Regards,
> 
> Philippe

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


Re: Which License Should I Use?

2005-11-26 Thread mojosam
Thanks to everyone so far.  You've helped a lot.  (BTW, I read this
through Google Groups.  Somehow they've gotten about 24 hours behind,
so I'm seeing your replies a day late.)

The biggest misconception I had was that the license could force the
code to stay open source.  You're right.  What I do on company time
belongs to the company.  I guess I assumed there was a license that
forced them to release it.

At one place I worked, they had to delay the release of the product by
a few weeks, because they discovered that they had included an open
source (don't know which license) module.  They had to pull it out and
recode it themselves (I know the other thread covered the subtleties of
whether even that was kosher, but let's ignore that here).  I think the
problem there was they believed that if they included the module, they
would have had to release the source code to the entire project.  I was
kind of hoping for something like that.

I would have to talk to a lawyer to be sure, but right now, I think I
can argue that anything I do on my own time belongs to me.  I'm
technically a consultant right now (even though I'm spending 40
hours/week with the one "client").  I can take on other clients, as
long as they don't directly compete.  This means they're hiring my
expertise.  If I bring my own tools, that's part of my expertise.  I do
recall there was a clause in the contract that anything I did on their
time belonged to them.  For my next client, I should definitely include
a clause about rereleasing open source changes.

Anyway, staying away from the lawyer issues, if anyone has additional
thoughts to add to this, please keep the conversation going.  People
are raising some good points.

Ron Britton
nk67v8o02
at
sneakemail.com

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


Re: Call OCX from python?

2005-11-26 Thread Do Re Mi chel La Si Do
>From WxPython, or from PythonWin.

Other way : call, & drive, Internet-Explorer, who call the ocx.

Michel Claveau



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


Re: Why is dictionary.keys() a list and not a set?

2005-11-26 Thread Christoph Zwerschke
>>> class mylist1(list):
>>> def __hash__(self): return 0815
>>>
>>> class mylist2(list):
>>> def __hash__(self): return id(self)
>>>
>>> Which of these user-defined types would you call "hashable"?

 > Mike Meyer wrote:

>> The latter two, as the given __hash__ meets the specifications for
>> __hash__.

Martin v. Löwis wrote:

> This is not true. The second definition of __hash__ does not meet
> the specifications:
> "The only required property is that objects which compare equal have the
> same hash value"

As Mike has written in his last posting, you could easily "fix" that by 
tweaking the equality relation as well. So technically speaking, Mike is 
probably right. It would completely break common-sense semantics, 
because for mylist2, if I have a=[1] and b=[1] then I will have a!=b. 
This would not be very reasonable, but probably allowed by Python.

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


Using SSL in socket module.

2005-11-26 Thread Carl Waldbieser
I am trying to understand how the SSL object in the socket module is
supposed to be used.  From looking at the documentation, I can work out
that you need to pass a socket into the ssl() function, and you get back an
SSL object that has write() and read() methods similar to a file object.

However, what I don't get is the context you are supposed to use this object
in.  I thought that SSL was like a socket, but the transmission would be
encrypted.  So I guess I was expecting the SSL object to look like a socket
object-- so that you could just use an SSL object as a drop-in replacement
for a socket object when you wanted to encrypt the transmission.

Am I missing something fundamental here?

Thanks for any pointers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Call OCX from python?

2005-11-26 Thread JustSomeGuy
Hi I have a commercial OCX that I want to use in
my python application.  How do I call OCXs from
python?
TIA


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


Re: FTP over TLS

2005-11-26 Thread Carl Waldbieser
David Isaac wrote:

> 
> "Carl Waldbieser" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Does anyone know of any good examples for writing client side code to
> upload
>> files over a secure FTP connection?
> 
> http://trevp.net/tlslite/
> 
> Alan Isaac

Thanks.  I have actually looked at this library before.  It looks like it
might be able to do what I want, but my problem is that I don't really
understand how the protocol itself works very well.  I mean, from a high
level view, I thing something like this happens:

1) FTP client contacts server, sends command requesting secure connection.
2) Server responds by sending some sort of public key
3) Client uses key to encrypt the rest of the communication.

I don't really understand the nitty-gritty of what's going on, though.  I
can read the API for the library, but I am really lost as to how to use it.

I didn't see any docs on the site that clarify how it's supposed to be used. 
Did I miss something?  Is there somewhere else I should be looking?

Thanks

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


Re: Persist a class (not an instance)

2005-11-26 Thread Phillip J. Eby

David  Wahler wrote:
> Kent Johnson wrote:
> > Is there a way to persist a class definition (not a class instance,
> > the actual class) so it can be restored later? A naive approach
> > using pickle doesn't work:
> [snip]
> > The idea is to persist classes that are created and modified at runtime.
>
> I couldn't resist the challenge, so I decided to take a crack at it. My
> code is below. (I hope it's OK to post it even though it's a bit on the
> long side.) So far, it seems to work OK; the biggest caveat to be aware
> of is that functions' global context is not preserved.
>
> My approach was to use pickle's __reduce__ protocol to store functions
> and classes. Of course, you can't modify the built-in function and
> classobj types, so I subclassed Pickler to override them. The advantage
> of this is that you don't need an extension to the pickling data
> format, and you can use the standard unpickler. (The custom module
> still needs to have been imported, as it adds the classobj type to
> __builtins__.)
>
> Unfortunately, I'm not sure how to go about making it work for
> new-style classes. It would seem to involve messing with dictproxy and
> descriptor objects, and that's getting me into more unfamiliar
> territory.
>
> I'm sure there's a better way to do this; this seemed like "the
> simplest thing that could possibly work".

This is actually pretty sweet.  It seems to me that you'll be fine with
new-style classes if you just save dict(ob.__dict__) instead of trying
to save __dict__ directly, as that'll get rid of the dictproxy part.
There's no generic way to save descriptors, as far as I know, but you
can always register reducers for specific types, like property, and
user-defined descriptor classes are likely to be picklable anyway.

As for functions' global context, you could look to see if there's a
__name__ present, in which case you can save a reference to that
module's __dict__.  Otherwise, simply pickle the func_globals as-is.
Some folks might just want to do that anyway, if the code isn't
actually being loaded from a module.

Of course, the classic caveat regarding pickles and security applies to
all this.  That is, pickles and security don't mix.  If you want one,
you can't really get the other.  ;-)

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


Re: icmp - should this go in itertools?

2005-11-26 Thread Tom Anderson
On Sat, 26 Nov 2005, Diez B. Roggisch wrote:

> Tom Anderson wrote:
>
>> Is this any good? Would it be any use? Should this be added to itertools?
>
> Whilst not a total itertools-expert myself, I have one little objection 
> with this: the comparison won't let me know how many items have been 
> consumed. And I end up with two streams that lack some common prefix 
> plus one field.

Good point. It would probably only be useful if you didn't need to do 
anything with the iterators afterwards.

One option - which is somewhat icky - would be to encode that in the 
return value; if n is the number of items read from both iterators, then 
if the first argument is smaller, the return value is -n, and if the 
second is smaller, it's n. The trouble is that you couldn't be sure 
exactly how many items had been read from the larger iterator - it could 
be n, if the values in the iterators differ, or n+1, if the values were 
the same but the larger one was longer.

> I'm just not sure if there is any usecase for that.

I used it in my ordered dictionary implementation; it was a way of 
comparing two 'virtual' lists that are lazily generated on demand.

I'll go away and think about this more.

tom

-- 
Gotta treat 'em mean to make 'em scream.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython Licence vs GPL

2005-11-26 Thread Martin P. Hellwig
Steven D'Aprano wrote:

> 
> 
> I think you are over-estimating both the numbers and profitability of such
> niche software distributors, and misunderstanding the business models of
> them.

Coincidently, I worked at a software company making a "standard" 
administration software for primary schools. Which concentrate on the 
national market. Because this in the Netherlands, not such a big 
country, the customer base is not that big.
So on a population of 17 million people there are about 7.500 thousands 
primary schools, our market share was quit big we had 4.500 thousands 
customers, there where "only" about 7 other competitive 
products/companies in that market.

The software was sold in 3 separates modules requiring a yearly renewal, 
the base module was required for all customers the other modules where 
add on packages, the base module cost about 500 EUR, then there where 
2000 clients for 350 EUR module and about 500 clients for the third 250 
module.

They also sold administration software for the academic market with 
about the same annual income as that of the primary schools.

So for a niche market on a small user base using non-consulting 
software, they had a quite profitable steady income.

Perhaps not the billions of dollars you expect from a software company 
but for me and the 40 other employees it was enough to say that we 
didn't over-estimated both the numbers and profitability of such a niche 
software distributor and we sure didn't misunderstood the business model 
of that. Unfortunately the profitable company was merged by the VC's 
with 8 non-profitables companies because they had that this would make 
them all profitable.

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


Re: icmp - should this go in itertools?

2005-11-26 Thread Tom Anderson
On Fri, 25 Nov 2005, Roy Smith wrote:

> Tom Anderson <[EMAIL PROTECTED]> wrote:
>
>> It's modelled after the way cmp treats lists - if a and b are lists,
>> icmp(iter(a), iter(b)) should always be the same as cmp(a, b).
>>
>> Is this any good? Would it be any use? Should this be added to itertools?
>
> Whatever happens, please name it something other than icmp.  When I read 
> "icmp", I think "Internet Control Message Protocol".

Heh! That's a good point. The trouble is, icmp is clearly the Right Thing 
to call it from the point of view of itertools, continuing the pattern of 
imap, ifilter, izip etc. Wouldn't it be clear from context that this was 
nothing to do with ICMP?

tom

-- 
Gotta treat 'em mean to make 'em scream.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparison problem

2005-11-26 Thread Tom Anderson
Chris, as well as addressing what i think is causing your problem, i'm 
going to point out some bits of your code that i think could be polished a 
little. It's intended in a spirit of constructive criticism, so i hope you 
don't mind!

On Sat, 26 Nov 2005, Chris wrote:

>if item[0:1]=="-":

item[0:1] seems a rather baroque way of writing item[0]! I'd actually 
suggest writing this line like this:

if item.startswith("-:):

As i feel it's more readable.

> item=item[ :-7]
> item=item[1:]

You could just write:

item = item[1:7]

For those two lines.

> infile=open("inventory","r")

The "r" isn't necessary - reading is the default mode for files. You could 
argue that this documents your intentions towards the file, i suppose, but 
the traditional python idiom would leave it out.

> while infile:
>  dummy=infile.readline()

The pythonic idiom for this is:

for dummy in infile:

Although i'd strongly suggest you change 'dummy' to a more descriptive 
variable name; i use 'line' myself.

Now, this is also the line that i think is at the root of your trouble: 
readline returns lines with the line-terminator ('\n' or whatever it is on 
your system) still on them. That gets you into trouble later - see below.

When i'm iterating over lines in a file, the first thing i do with the 
line is chomp off any trailing newline; the line after the for loop is 
typically:

line = line.rstrip("\n")

>  if dummy=='':break

You don't by any chance mean 'continue' here, do you?

>  print item
>  print ", "+dummy
>  if (dummy == item): 

This is where it all falls down - i suspect that what's happening here is 
that dummy has a trailing newline, and item doesn't, so although they look 
very similar, they're not the same string, so the comparison comes out 
false. Try throwing in that rstrip at the head of the loop and see if it 
fixes it.

HTH.

tom

-- 
Gotta treat 'em mean to make 'em scream.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: icmp - should this go in itertools?

2005-11-26 Thread Jorgen Grahn
On Fri, 25 Nov 2005 21:58:00 -0500, Roy Smith <[EMAIL PROTECTED]> wrote:
> Tom Anderson <[EMAIL PROTECTED]> wrote:
>
>> It's modelled after the way cmp treats lists - if a and b are lists, 
>> icmp(iter(a), iter(b)) should always be the same as cmp(a, b).
>> 
>> Is this any good? Would it be any use? Should this be added to itertools?
>
> Whatever happens, please name it something other than icmp.  When I read 
> "icmp", I think "Internet Control Message Protocol".

Me too, but I see that as an added bonus ;-). OTOH, if this is part of
itertools or some other module, "itertools.cmp" would be a more logical
name. (On the third hand, as someone else said, I don't see the use case for
this.)

/Jorgen
-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which License Should I Use?

2005-11-26 Thread Jorgen Grahn
On Sat, 26 Nov 2005 00:13:10 +, Tom Anderson <[EMAIL PROTECTED]> wrote:
...
> freedom - 'free software', 'free as in speech', etc. What you have to 
> realise is that they're not talking about the freedom of the programmers, 
> but about the freedom of the software. The logic, i think, is that the 
> freedom of the code is the key to the freedom of the end-users: applying 
> the GPL to your code means that other programmers will be forced to apply 
> to to their code, which means that users of that code will get the 
> benefits of open source.

... which implies that one believes that every end-user has the potential to
become a hacker. That, I think, is at the core of the GPL, and RMS's
rantings are easier to understand if you keep that in mind.

But yes, let's not dive too deeply into all that here.

> Oops!
;-)

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which License Should I Use?

2005-11-26 Thread Jorgen Grahn
On 25 Nov 2005 11:30:46 -0800, mojosam <[EMAIL PROTECTED]> wrote:
...
> How do I decide on a license?  Are there any web sites that summarize
> the pros and cons?

I like this list:

  http://www.gnu.org/licenses/license-list.html

It's from a GPL perspective of course, but pretty balanced I think.

Personally, I use the GPL or the Modified BSD license, depending on the
phase of the moon. And I do take software with me to work, but never in the
reverse direction.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter on mac - Binding command-q to quit application

2005-11-26 Thread Brandon
Hi All,

I'm attempting to develop a Tcl/Tk application on the mac using python
and Tkinter.  The one problem I'm having is adding basic keyboard
support to my application, specifically binding command-q so that it
quits the application (this is standard behavior for almost every mac
application, the equivalent of alt-f4 on windows).  Has anyone
successfully been able to do this?  If so, could you please share some
code which demonstrates how?


If it matters, I've been working with both python 2.3.5 and python
2.4.1:

 >>> print sys.version; print "-"*30; print Tkinter.__version__
 2.3.5 (#1, Aug 22 2005, 22:13:23)
 [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)]
 --
 $Revision: 1.177 $

and on python 2.4:

 >>> print sys.version; print "-"*30; print Tkinter.__version__
 2.4.1 (#2, Mar 31 2005, 00:05:10)
 [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)]
 --
 $Revision: 1.181.2.1 $


Thanks in advance,
Brandon

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


Crash in python while run from U3 device

2005-11-26 Thread Philippe C. Martin
Hi,

I am currently porting some of my applications to U3 (www.u3.com) and I do
get a crash in ...objects\frameobject.c: PyFrameObject *back =
tstate->frame.

The point of the current test is to get a python function called on a U3
device event. (U3 only work with Windows currently).

My C stub callback does get called but crashes when it tries to call the
python function.



***
This is the function that registers the callback (actual dll prototype in
header):
***
static PyObject *s_callback=NULL;
/**/
/**/
/* HRESULT dapiRegisterCallback(   HSESSION hSession ,wchar_t*
pszConnectionString ,DAPI_CALLBACK pCallBack,void* pEx ,HCALLBACK*
hCallback) */
/**/
/**/

static PyObject *Py_dapiRegisterCallback(PyObject *p_self, PyObject *p_args)
{
HRESULT l_result;
HSESSION l_hSession;
wchar_t* l_pszConnectionString;
PyObject *l_tmp_cb;
//PyObject cs;
void* l_pEx;
HCALLBACK l_hCallback;

if
(!PyArg_ParseTuple(p_args,"iuOi",&l_hSession,&l_pszConnectionString,&l_tmp_cb,&l_pEx)
 )
{
BAD_PARAM;
return NULL;
}
//l_pszConnectionString = PyObject_Unicode(cs);
Py_XINCREF(l_tmp_cb);
Py_XDECREF(s_callback);
s_callback=l_tmp_cb;
l_result =
dapiRegisterCallback(l_hSession,l_pszConnectionString,Stub_Callback,l_pEx,&l_hCallback);

CHECK_RESULT;

return Py_BuildValue("l",l_hCallback);

}

***
This is the stub callback that crashes:
***
void _stdcall Stub_Callback(HDEVICE p_dev, DWORD p_event, void *p_pEx)
{
PyObject *l_result;
PyObject *l_arg_list;

l_arg_list = Py_BuildValue("(iii)", p_dev,p_event,p_pEx);
l_result = PyEval_CallObject(s_callback, l_arg_list); /*No crash if I
comment this line*/
Py_DECREF(l_arg_list);
}


*
This is the python source
*
(cs, and s have a correct value ... I think )
import u3
def mf(a,b,c):
   print 'CB'

h=u3.dapiRegisterCallback(s, cs, mf, 0)




Any help _greatly_ appreciated.

Regards,

Philippe




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


Re: Dynamic classes

2005-11-26 Thread Dave Rose
Duh!  how dumb am I?  A dictionary solves all those problems, with each 
entry named, and the value of each name could be a class instace. plus all 
the class instances can be iterated by a loop.

Thanks Piet & Alex for your guidance!
-Dave

"Piet van Oostrum" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> "Dave Rose" <[EMAIL PROTECTED]> (DR) wrote:
>
>>DR> Hello all.
>>DR>   I was wondering if creating classes could be dynamic. I want to know
>>DR> if I can make a class Person, then read in a list of names (say
>>DR> people's names) so then I can have a class instance created for each
>>DR> name in the list?
>
> If you have the class Person, you are not creating it dynamically. And of
> course you can create instances dynamically as you describe.
>
>>DR>   Why do I want to do this?  I was just thinking if I had a name on 
>>the
>>DR> list, Dave, I could then be able to read the name in the list, and
>>DR> assign Maria.birthday = <> and all the other attributes I would want
>>DR> to use a class for, except this is dynamic. I don't know how to
>>DR> iterate thru the list to assign the different attributes yet, but this
>>DR> seemed reasonable to want to do, and thought I could learn from this.
>
> If I understand you correctly, you want to create a variable with name
> 'Maria' when you read the name "Maria". Creating variables dynamically is
> possible in Python but is almost always the wrong thing to do. Instead it
> is usually better to use a dictionary.
>
> class Person:
>  def __init__(self, name):
>  self.name = name
>
> persons = {}
>
> now you have a loop that reads persons' names, say in name.
>
> myperson = persons[name] = Person(name)
>
> Now I suppose you want to read additional attributes, while the list of
> possible attributes is in principle open.
>
> So suppose you have read the attribute name in attr and the value in val.
> The you can dynamically create an instance attribute with:
>
> setattr(myperson, attr, val)
> -- 
> Piet van Oostrum <[EMAIL PROTECTED]>
> URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
> Private email: [EMAIL PROTECTED] 


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


Comparison problem

2005-11-26 Thread Chris
Hi,

I'm new to python, and I'm trying to write a small python script for a
webpage.  The script opens up a file called inventory, reads the
contents, and checks the contents against the data from the form in my
webpage.  Now I have to do some slicing to get the name of the form
elements (in this case, checkboxes), to resemble the values in the
inventory file.  Here's my python part:

#!/usr/local/bin/python
import cgi
import types
from Cookie import *
form=cgi.FieldStorage()
user_answer=[]
error='false'
item=''
qty=''
def main():
  print"Content-type: text/html\n"
  i=open("inventory","r")
  keys=form.keys()
  for key in keys:
   field=form[key]
   if type(field)==types.InstanceType:
item=field.value
if item[0:1]=="-":
 item=item[ :-7]
 item=item[1:]
 infile=open("inventory","r")
 while infile:
  dummy=infile.readline()
  if dummy=='':break
  print item
  print ", "+dummy
  if (dummy == item): 
   print"Found it"
  else:
   print"Didn\'t Find it"
  print ""
 infile.close()
else:
 #print"Quantity: "
 #print item
 print""
#print field.value
   else:
print"BAD"
main()

Let me know if more information is needed.  Any assistance will be
greatly appreciated.

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


Re: How to get started in GUI Programming?

2005-11-26 Thread Luis M. Gonzalez
Try PythonCard (http://pythoncard.sf.net).
Like VB or Delphi (drag and drop widgets), but much simpler, easy and
fun.
It's based on wxWidgets, and it gives your apps a native look, no
matter your platform (much nicer than Tkinter, which looks uglier and
dated).

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


forum

2005-11-26 Thread Henri Stryd













What is this what I get om my screen?
does it have anything to do with the Sam Francke who has that beautiful genealogical entry?
Answer at: [EMAIL PROTECTED]
Henri.


















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

Re: How to get started in GUI Programming?

2005-11-26 Thread Rembrant
ok i'm begginer in programing but i found some online books so you'll
probably find in them what you need! Just send me a mail and i'll reply
with the address! hope this can be helpfull...

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


Re: How to get started in GUI Programming?

2005-11-26 Thread Jonathan Gardner
I would argue with your assertion that either TKinter of PyGTK are the
best. There are several other good alternatives, including wxPython and
PyQt, which are very comparable, if not better.

I would strongly suggest starting with PyQt. It's my personal favorite.
I wrote a short tutorial on the Python Wiki.

http://wiki.python.org/moin/JonathanGardnerPyQtTutorial

I find that the Qt API is a lot simpler than the alternatives. Plus, it
has great documentation.

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


Re: Stealing focus: emacs, and PIL, in Windows

2005-11-26 Thread Graham Fawcett
[EMAIL PROTECTED] wrote:
> I'm using GNU Emacs 21.3.1 with python-mode 1.0alpha under Windows XP.
> Whenever I execute a command in an edit window (with
> py-execute-region), the output window steals the focus. How can I stop
> this happening?
[snip]
> I commented out the command
>   (pop-to-buffer (current-buffer))
> and now the command window no longer steals focus. But I don't know if
> this has any other side effects, or it there's a better way to prevent
> focus being stolen.

For someone who says he doesn't know Lisp, you seem to be doing just
fine. :-)

Not sure if there would be side-effects. Note that py-execute-string,
py-execute-buffer, py-execute-def-or-class all use py-execute-region.
Their behaviour may be altered by your change. But it would be easy to
test.

If you did encounter a problematic side-effect, you could define your
own "py-execute-region-custom" as a copy of py-execute-region but with
the (pop-to-buffer) call removed. Then use

  (require 'python-mode)  ;; if you're putting this in .emacs
  (define-key py-mode-map "\C-c|" 'py-execute-region-custom)

to redefine the keyboard mapping.  (The (require 'python-mode) call
ensures that the py-mode-map variable has been initialized.) You could
provide an alternate mapping for your new function, of course.

If you put the custom function and your define-key call both in your
.emacs file, then you can easily port it to other machines (perh.
easier than maintaining a patch for python-mode).

Graham

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


Re: Whitespace test after string.split

2005-11-26 Thread David Pratt
Hi Fredrik. Good to know.  Many thanks for your replies.

Regards
David

On Saturday, November 26, 2005, at 12:27 PM, Fredrik Lundh wrote:

> David Pratt wrote:
>
>> Also thanks for heads up for changes with method.  I am
>> still using 2.3 but will move to 2.4 as soon as this is formally
>> approved for use in Zope.
>
> note that the string.split function has been "outdated" since Python
> 1.6 (released in 2000), and despite what the documentation implies,
> it won't go away before 3.0.
>
> there's no reason not to use it in 2.3, but if you have lots of old 
> code
> using the old syntax, there's no reason to change that just because you
> want to upgrade to a newer Python release...
>
> 
>
>
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython Licence vs GPL

2005-11-26 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
   ...
> >> Apart from Microsoft, and possibly Quark (makers of Quark Express desktop
> >> packaging software), and perhaps a few console game developers, is there
> >> any company making a profit on software sales?
> > 
> > I believe Oracle is doing fine (and they appear to be trying to buy up
> > most everybody else -- other companies which used to make profits from
> > software sales before they got gobbled up).  I think SAP and Adobe
> > aren't doing badly, either, but I haven't checked up on them in a while.
> 
> My understanding is that both Oracle and SAP make most of their money
> through consulting and customization rather than licencing or sales. I

Have you checked their quarterly statements recently?  What I read about
Oracle (look for ORCL on Google, go to SEC filings, quarterly statement;
sorry, but the URL comes out way mangled this way...) is that their
software business is 79% of their revenues (on a 4-quarters-trainling
basis) and "our highest margin business" with a forecast to "continually
improve margins and profits"; while "Our services business consists of
consulting", "21% of our total revenues on a trailing 4-quarter basis,
has significantly lower margins than our software business" (further
broken down into Consulting, On Demand, and Education).  Of course for
all I know they might be playing some accounting tricks, but I don't see
why they should.

SAP is a bit harder to fathom for the typical US investor since they
officially report under Handelsgesetzbuch rules, but they've long been
voluntarily offering a US GAAP report side by side; you can study their
reports at http://www.sap.com/company/investor/reports/index.epx ,
though (at least for somebody most used to reading typical SEC filings
of US companies) it's not quite as immediate to read those for details,
partly because of US$ vs EUR exchange rate issues.

Nevertheless, it would appear that in SAP's case both statements are
correct; they DO make profits on software sales, and even more in
ancillary service business driven by those sales.  "Software revenues
were €590 million for the third quarter of 2005", up 19% or 20% year
over year depending on currency used; "Total revenues for third quarter
of 2005 were €2.01 billion", up 12% or 13%.  They don't distinguish
operating margins between their software and service business, though I
don't see why their margins structure should be substantially different
from Oracle's -- higher in software, lower in services.  Anyway, they
make almost 1/3 of their revenue (probably more than 1/3 of their
profits, though that's just an educated guess) from software, with
(right now) faster growth, and more than that from services, though
currently with lower growth rates.

The assumed difference in operating margins is, I believe, why they show
software revenues separately: software, potentially, can have wider
operating margins than services, as it can ``scale'' -- you could sell
licenses for just the same bits over and over with just modest customer
acquisition costs, driving operating margins skywards, while in services
you're basically reselling some professionals' time at a markup... a
hefty markup, sure, but margins just can't be as stellar as they could
be in software sales if it all worked right (higher acquisition costs,
&c).

> don't know anyone who has bought a SAP solution that didn't spend an awful
> lot of money having it customized -- and unless I'm very mistaken, you
> don't own the customizations you pay for.

I have acquaintances in Italy who make great consulting income helping
SAP customers implement their purchases -- but they do so as freelance
consultants, not as SAP employees (many of them USED to work for SAP,
then figured out they could keep that "hefty markup" to themselves).  Do
not assume that SAP can capture all or even most of the ancillary
services their software generates demands for, even though their 2
billion euro total revenues shows they're doing pretty well in that
field (I believe the situation is even more extreme for Oracle, with way
more business going to independent consultants in that sector).


> Adobe, I'm not sure -- I suspect their biggest source of income is
> royalties on Postscript for laser printers, but I could be wrong. I don't
> even know anyone who uses Pagemaker any more -- it seems to have been
> almost completely overshadowed by Quark Xpress.

Even if Pagemaker is not an earner any more, and maybe Framemaker
neither, aren't you forgetting Acrobat, Photoshop (probably the biggest
earner), Premiere, After Effects, Encore, Audition, Illustrator,
InDesign, GoLive, InCopy...?  Not to mention Flash, Dreamweaver,
Coldfusion, Freehand, Director... (Adobe DOES own Macromedia, you know;
the acquisition was over a month ago).

Anyway, looking for ADBE and their latest quarterly report (before the
Macromedia acquisition), they claim 98% of their revenues come from
product sales and only 2% from service

Re: Whitespace test after string.split

2005-11-26 Thread Fredrik Lundh
David Pratt wrote:

> Also thanks for heads up for changes with method.  I am
> still using 2.3 but will move to 2.4 as soon as this is formally
> approved for use in Zope.

note that the string.split function has been "outdated" since Python
1.6 (released in 2000), and despite what the documentation implies,
it won't go away before 3.0.

there's no reason not to use it in 2.3, but if you have lots of old code
using the old syntax, there's no reason to change that just because you
want to upgrade to a newer Python release...

 



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


Re: Whitespace test after string.split

2005-11-26 Thread David Pratt
Hi Fredrik and Peter. Many thanks for this helpful advice :-)  These 
are very nice solutions and much better than what I had been 
contemplating. Also thanks for heads up for changes with method.  I am 
still using 2.3 but will move to 2.4 as soon as this is formally 
approved for use in Zope.

Regards,
David

On Saturday, November 26, 2005, at 11:42 AM, Fredrik Lundh wrote:

> Peter Otten wrote:
>
> [t.strip() for t in s.split(",") if t and not t.isspace()]
>> ['alpha', 'gamma', 'delta']
>
> footnote: this solution is faster than my filter version.
>
> 
>
>
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing pins to the RS232

2005-11-26 Thread Paul Watson
[EMAIL PROTECTED] wrote:
> I want to write to the pins of an RS232 without using the serial
> protocol.  The use would be every pin could act to complete a circuit
> in customized hardware.  I could use python to communicate serially to
> a BASIC stamp or a Javelin stamp and then use the stamp to set however
> many pins as 0's or 1's but should it be that hard to do with python.
> I've looked through how python does serial with the "serial" module but
> it just uses Java's javax.comm libraries.  Is there anyway to do very
> low level device writing to COM ports?
> 
> In summary I'm looking for something like:
> ser = serial.Serial(0)
> ser.pin0 = 1
> ser.pin1 = 1
> ser.pin2 = 1
> 
> 
> 
> or
> ser.write('0xFF')
> which would set 8 pins on the RS232 cable to 1's
> 

Accessing hardware at this level is almost always managed by some form 
of device driver in any real operating system.  Even Microsoft Windows 
has device drivers for serial and parallel ports.  This is not your 
father's MS-DOS any more.  It would be a security breach to allow user 
applications direct access at the hardware level.

Also, if you ever hope to run on anything except an IBM-PC clone, then 
the hardware will be different.  Even systems that run x86 processors 
like the NEC PC-98 have 8255 parallel interfaces, but they are located 
on different ports in the machine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Whitespace test after string.split

2005-11-26 Thread Fredrik Lundh
Peter Otten wrote:

 [t.strip() for t in s.split(",") if t and not t.isspace()]
> ['alpha', 'gamma', 'delta']

footnote: this solution is faster than my filter version.

 



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


Re: wxPython Licence vs GPL

2005-11-26 Thread Fredrik Lundh
Steven D'Aprano wrote:

> Fine. If you want to take rights away from the people you redistribute
> somebody else's software to, then the GPL is not for you.

the people you distribute somebody else's open source software to
still have the same rights to that software as you have.  GPL or not
GPL doesn't change that a bit.

if someone grabs my stuff and hides it in a commercial application,
anyone can still get my stuff under the original license.  (e.g. Adobe's
use of bits and pieces from Python's Unicode string implementation
doesn't seem to affect Python users the slightest...)

I find it a lot more annoying when people grab my stuff, make trivial
additions or bugfixes to it, and GPL the result instead of contributing
it back.  exactly how that increases freedom is hard for me to tell,
but I guess there's freedom and then there's freedom...

 



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


Re: Whitespace test after string.split

2005-11-26 Thread Fredrik Lundh
David Pratt wrote:

> Hi.  I am splitting a string on a non whitespace character. One or more
> whitespace characters can be returned as items in the list. I do not
> want the items in the list that are only whitespace (can be one or more
> characters of whitespace) and plan to use string.strip on those items
> that are not only whitespace (to remove any whitespace from front or
> back of items).
>
> What kind of efficient test can I use to obtain only list items
> returned from the split that I am interested in, ignoring any list
> items that would only be comprised of one or more characters of
> whitespace (since whitespace can mean one or more spaces, tabs, and
> other characters)

call strip, and only include the string in the result if it's not empty.  
combining
a generator expression with the filter() function should be rather efficient:

>>> text = "blah blah  \n: : blah   ::blah"
>>> print filter(None, (x.strip() for x in text.split(":")))
['blah blah', 'blah', 'blah']

in 2.3 and earlier, use

>>> print filter(None, [x.strip() for x in text.split(":")])

instead.

(this assumes that you don't want to keep empty items either)

> As a second question, I am seeing string split as deprecated in 2.4.2
> manual.  What is planned in future to split (strings or unicode)?

the "string.split" function in the "string" module is outdated; the "split"
method on string objects is not.

 



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


Re: Whitespace test after string.split

2005-11-26 Thread Peter Otten
David Pratt wrote:

> Hi.  I am splitting a string on a non whitespace character. One or more
> whitespace characters can be returned as items in the list. I do not
> want the items in the list that are only whitespace (can be one or more
> characters of whitespace) and plan to use string.strip on those items
> that are not only whitespace (to remove any whitespace from front or
> back of items).
> 
> What kind of efficient test can I use to obtain only list items
> returned from the split that I am interested in, ignoring any list
> items that would only be comprised of one or more characters of
> whitespace (since whitespace can mean one or more spaces, tabs, and
> other characters)

>>> s = "alpha, \t\n, gamma, delta,"
>>> s.split(",")
['alpha', ' \t\n', ' gamma', ' delta', '']
>>> [t for t in s.split(",") if not t.isspace()]
['alpha', ' gamma', ' delta', '']
>>> [t for t in s.split(",") if t and not t.isspace()]
['alpha', ' gamma', ' delta']
>>> [t.strip() for t in s.split(",") if t and not t.isspace()]
['alpha', 'gamma', 'delta']

There you are.

> As a second question, I am seeing string split as deprecated in 2.4.2
> manual.  What is planned in future to split (strings or unicode)?

Just use the corresponding methods, e. g. s.strip() instead of
string.strip(s) etc.

Peter

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


Whitespace test after string.split

2005-11-26 Thread David Pratt
Hi.  I am splitting a string on a non whitespace character. One or more 
whitespace characters can be returned as items in the list. I do not 
want the items in the list that are only whitespace (can be one or more 
characters of whitespace) and plan to use string.strip on those items 
that are not only whitespace (to remove any whitespace from front or 
back of items).

What kind of efficient test can I use to obtain only list items 
returned from the split that I am interested in, ignoring any list 
items that would only be comprised of one or more characters of 
whitespace (since whitespace can mean one or more spaces, tabs, and 
other characters)

As a second question, I am seeing string split as deprecated in 2.4.2 
manual.  What is planned in future to split (strings or unicode)?

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


Re: wxPython Licence vs GPL

2005-11-26 Thread Steven D'Aprano
On Sat, 26 Nov 2005 04:46:15 -0500, Mike Meyer wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> But if you *do* redistribute it, then you must live up to conditions in
>> the licence. If you aren't willing to do that, use software with a
>> different licence. 
> 
> That's a restriction on redistribution.

ALL licences make that "restriction". There is no licence that allows you
to distribute the product in contradiction to the terms of the licence.

>> The only restriction is that you can't give those people fewer, weaker
>> rights than you got
> 
> That's a restriction on redistribution.

Well now we're getting somewhere. 

Fine. If you want to take rights away from the people you redistribute
somebody else's software to, then the GPL is not for you.

That's a restriction that actually *increases* freedom, so I don't see it
as a restriction at all -- I see it as something that enables rather than
disables.

What you see as a restriction to the GPL is, in my opinion, not
restrictive at all. After all, there are plenty of other software written
under other licences if you prefer. But the GPL's technical restriction
actually increases freedom rather than decreases it, in much the same way
as the Constitution of the USA increases freedom by restricting the laws
which Congress can pass. The framers of the Constitution understood the
ways in which even well-meaning governments could destroy freedom, and
took steps to try to prevent that.

There is something seriously wrong with saying that "the Constitutional
right to free speech is a restrictive law", even if it is technically true
that the Constitution restricts the ability of the government to prohibit
freedom of speech. Describing the GPL as restrictive is much the same.



-- 
Steven.

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


Re: Making immutable instances

2005-11-26 Thread Mike Meyer
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Sat, 26 Nov 2005 04:59:59 -0500, Mike Meyer wrote:
>> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>>> On Fri, 25 Nov 2005 23:20:05 -0500, Mike Meyer wrote:
 If you've got a use case, I'd be interested in hearing it.
>>> frozenset perhaps? If it were needed once, it could be needed again.
>> That's not a use case, that's an example. 
> Fine. "I want to use a set as a dictionary key, but dict keys must be
> immutable."

Except that dict keys don't have to be immutable. The docs say (or
imply) that, but they're wrong. We're discussing new wording in
another thread.

>> And not a very good one, as
>> it's not at all clear that the restriction is intentional in that
>> case. After all, the same restriction applies to every builtin type,
>> including the mutable version of frozenset.
> Every builtin type, including mutable sets, is immutable???

No. I think you missed the entire second half the thread.

> I think we're talking at cross purposes. I'm talking about immutable
> instances. What are you talking about?

I'm talking about being able to add attributes to an instance. You
can't add an attribute to *any* builtin type. This is an
implementation detail. I consider it to be a wart in the language, but
an acceptable one, because the costs of fixing it are much worse than
the costs of working around it, and practicality beats purity.

>>> The obvious case would be for a class where distinct instances that
>>> compare equal but not identical map to the same value in a dict.
>> How does the ability to add attributes to the instances of the class
>> change that behavior?
> Er, who said it did?

You did. We're looking for a use case for adding the ability to mark a
class as having instances that you can't add an attribute to. You
suggested this as such a use case.

>> The best reason Ben could come up with is that it makes
>> finding bugs a bit easier. 
> Are you sure that was Ben? Maybe I missed it.

No, I'm no sure it was Ben - I didn't go chase down the
reference. It's the best use case *from anyone* so far, though.

> All joking aside, I think having immutable custom classes, with or without
> restricting attribute creation, is no worse than (say) Python's name
> mangling.

There are well-defined facilities for creating read-only
attributes. Is there a difference between an immutable object you can
add attributes to, and an object that has nothing but read-only
attributes?

>> Of course, that a feature has a lot in common with features from
>> un-Pythonic languages doesn't make it ipso facto unPythonic. After
>> all, practicality beats purity. So what's the practical application
>> for such a feature? What's the use case?
> Class instances match by identity when used as keys, not equality. That's
> over-strict: why should Parrot("Norwegian Blue") map to a different item
> from Parrot("Norwegian" + " Blue") just because the first instance has a
> different memory location to the second?

Uh - HTH did we get here?

> Please note, I do not expect -- and would not want -- the default
> behaviour to change. Most class instances presumably should be mutable,
> and therefore mapping by ID is the right behaviour.

The default behavior is right for in many cases. For those that it's
not right, you can fix it. Proper definition of the Parrot class will
insure that Parrot("Norwegian Blue") == Parrot("Norwegian" + " Blue")
always evaluates to True.

> But some class instances shouldn't be mutable, and should match as keys by
> equality not identity: we would expect Fraction(num=1, den=2) to match
> Fraction(num=2, den=4) as a key.

And you can do that with Python as it exists today (and one of these
days I'll get back to my Rational class that does that...). There's no
need for any changes to the language to deal with this case.

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is dictionary.keys() a list and not a set?

2005-11-26 Thread Martin v. Löwis
Mike Meyer wrote:
>>class mylist1(list):
>> def __hash__(self): return 0815
>>
>>class mylist2(list):
>> def __hash__(self): return id(self)
>>
>>In the case of mylist1, everything is ok including semantics, but
>>performance suffers dramatically. In mylist2, performance is great,
>>but semantics suffers greatly.
>>Which of these user-defined types would you call "hashable"?
> 
> 
> The latter two, as the given __hash__ meets the specifications for
> __hash__.

This is not true. The second definition of __hash__ does not meet
the specifications:

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

"The only required property is that objects which compare equal have the
same hash value"

However, I can have two instances of mylist2 which compare equal,
yet have different hash values.

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


Re: Why is dictionary.keys() a list and not a set?

2005-11-26 Thread Mike Meyer
Christoph Zwerschke <[EMAIL PROTECTED]> writes:
> Mike Meyer wrote:
>  > I think you're trying to tweak the wrong definition. Types are
>  > immutable if their instances are immutable.
> I'm not trying to tweak it, but to gain more clarity about what is
> actually meant when you talk about "mutable" types and objects and
> whether it suffices to use these terms as long as you speak about
> built-in datatypes.

I think we both agree that mutability isn't adequate, because it's
really irrelevant to the question. What it seems to provide is a
convenient and usually well-understood way of describing which builtin
types can be used: "Mutable builtin types cannot be used as dictionary
keys."  "Immutable builtin types can be used as dictionary keys,
except for certain tuples." That exception creates headaches. Then you
have to ponder things like "Is a file instance immutable?" because
they are hashable. Maybe we should just skip the idea completely.

>  > Do you think it's really necessary to specify "has a __hash__ method
>  > that returns a value", as opposed to just "has a __hash__ method"?
> I think it is necessary to require that it has a "proper" __hash__
> function. As far as I understand you can always add a __hash__
> method. Not only invalid __hash__ methods like in this case:
> class mylist0(list):
>  def __hash__(self): return None
> But you can also easily add valid __hash__ methods:
>
> class mylist1(list):
>  def __hash__(self): return 0815
>
> class mylist2(list):
>  def __hash__(self): return id(self)
>
> In the case of mylist1, everything is ok including semantics, but
> performance suffers dramatically. In mylist2, performance is great,
> but semantics suffers greatly.
> Which of these user-defined types would you call "hashable"?

The latter two, as the given __hash__ meets the specifications for
__hash__.  __hash__ itself isn't enough to decide the question of
semantics. You can make mylist2 have the right semantics by adding
def __eq__(self, other): return self is other
to it.

> Technically speaking, both probably are, so you can indeed use list
> objects of both types as keys of a dictionary - but I think there
> should be a hint in the docs that you need to have a "proper" hash
> function if you want your dictionary to be performant and show the
> usually expected behavior.

I agree - but where does that hint belong? I think it belongs in the
documentation for __hash__, not the documentation for sets and
dictionaries.

How about we document it in the spirit of Python's "try it and see"
philosophy:

Any hashable object can be used as a dictionary key/set element. An
object is hashable if calling hash on that object returns an integer. 

That's 100% correct. However, is it to little information to be
useful? If so, then going back to the mutable/immutable thing seems to
be right:

Any hashable object can be used as a dictionary key/set
element. Instances of mutable builtins are not hashable. Instances of
immutable builtins are hashable, except for tuples that contain a
non-hashable value. Instances of classes are usually hashable(*).

Footnote *: An instance of a class is hashable if it has a __hash__
method, or does not have either a __cmp__ or __eq__ method. If you're
not sure, call hash() on the instance, and if it returns an integer,
the instance is hashable.

Either way, over in the documentation for __hash__, add a note that:

For instances of a class to work properly with builtin container
types, two instances that compare as equal must have the same hash
value. For best performance, hash values should be different as often
as possible while honoring the equality requirement. (or is that
wrong?)

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making immutable instances

2005-11-26 Thread Steven D'Aprano
On Sat, 26 Nov 2005 04:59:59 -0500, Mike Meyer wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> On Fri, 25 Nov 2005 23:20:05 -0500, Mike Meyer wrote:
>>> If you've got a use case, I'd be interested in hearing it.
>> frozenset perhaps? If it were needed once, it could be needed again.
> 
> That's not a use case, that's an example. 

Fine. "I want to use a set as a dictionary key, but dict keys must be
immutable."


> And not a very good one, as
> it's not at all clear that the restriction is intentional in that
> case. After all, the same restriction applies to every builtin type,
> including the mutable version of frozenset.

Every builtin type, including mutable sets, is immutable???

I think we're talking at cross purposes. I'm talking about immutable
instances. What are you talking about?


>> The obvious case would be for a class where distinct instances that
>> compare equal but not identical map to the same value in a dict.
> 
> How does the ability to add attributes to the instances of the class
> change that behavior?

Er, who said it did?


>> In any case, I'm not the one claiming that I need custom immutable
>> classes. I'm just suggesting that there is nothing non-Pythonic about
>> them. If Ben thinks he needs them, I'm sure he has put *far* more thought
>> into it than I have. I know Ben in RL, and he is not someone to make snap
>> judgements about turning Python into Some Other Language Just Because.
> 
> I claim that the dynamic natture of Python - which is exemplified by
> things like duck typing and the ability to add attributes to nearly
> everything on the fly - is a fundamental part of what makes Python
> Python. 

I can't disagree with you there.

> The best reason Ben could come up with is that it makes
> finding bugs a bit easier. 

Are you sure that was Ben? Maybe I missed it.


> But so do type declarations, static
> namespaces, private and protected attributes, and a slew of similar
> B&D features that are pretty much anathema to dynamic languages. This
> feature fits *very* well in languages that have those features, and
> poorly in languages that reject them, which includes Python.

Perhaps. But I don't object to *mild* B&D, the sort you can get out of
relatively easily. You know, handcuffs, maybe a few ropes, but not
lock-them-up-in-the-oubliette-and-throw-away-the-key *wink*

All joking aside, I think having immutable custom classes, with or without
restricting attribute creation, is no worse than (say) Python's name
mangling.


> Of course, that a feature has a lot in common with features from
> un-Pythonic languages doesn't make it ipso facto unPythonic. After
> all, practicality beats purity. So what's the practical application
> for such a feature? What's the use case?

Class instances match by identity when used as keys, not equality. That's
over-strict: why should Parrot("Norwegian Blue") map to a different item
from Parrot("Norwegian" + " Blue") just because the first instance has a
different memory location to the second?

Please note, I do not expect -- and would not want -- the default
behaviour to change. Most class instances presumably should be mutable,
and therefore mapping by ID is the right behaviour.

But some class instances shouldn't be mutable, and should match as keys by
equality not identity: we would expect Fraction(num=1, den=2) to match
Fraction(num=2, den=4) as a key.



-- 
Steven.

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


Re: Hello World-ish

2005-11-26 Thread Jesse Lands
On 26 Nov 2005 03:19:55 -0800
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> from os import *
> print "Working path: %s" % os.getcwd();
> 
> Just wondering how you would do that .. in theory, if you get what I
> mean?
> I get
> NameError: name 'os' is not defined
> currently, which I don't know how to fix.. anyone?
> 

your using the getcwd from os.  You need to change the 'from os import
*'  to import os


i.e.

import os
print "Working path: %s" % os.getcwd()


-- 
JLands
Slackware 9.1
Registered Linux User #290053
"If you were plowing a field, which would you rather use? Two strong
oxen or 1024 chickens?"
- Seymour Cray (1925-1996), father of supercomputing
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI question

2005-11-26 Thread Fredrik Lundh
Dan Stromberg wrote:

> What's the best way of converting this:
>
> 'hide\\?http://www.dedasys.com/articles/programming_language_economics.html\x012005-07-20
> 14:48'
>
> ...to something easily usable in a python CGI script?

easily usable for what purpose?

if you want to extract the URL that seems to be hidden in that string,
something like:

url, junk = text.split("\x01", 1)
junk, url = url.split("\\?", 1)

should work.





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


Re: icmp - should this go in itertools?

2005-11-26 Thread Diez B. Roggisch
Tom Anderson wrote:
> Hi all,
> 
> This is a little function to compare two iterators:
> 
> 
> 
> def icmp(a, b):
> for xa in a:
> try:
> xb = b.next()
> d = cmp(xa, xb)
> if (d != 0):
> return d
> except StopIteration:
> return 1
> try:
> b.next()
> return -1
> except StopIteration:
> return 0
> 
> 
> 
> It's modelled after the way cmp treats lists - if a and b are lists, 
> icmp(iter(a), iter(b)) should always be the same as cmp(a, b).
> 
> Is this any good? Would it be any use? Should this be added to itertools?

Whilst not a total itertools-expert myself, I have one little objection 
with this: the comparison won't let me know how many items have been 
consumed. And I end up with two streams that lack some common prefix 
plus one field. I'm just not sure if there is any usecase for that.

However, _if_ there is one, I'm all for adding it to itertools - it 
seems to be in the appropriate spirit.

Regards,

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


Re: wxPython Licence vs GPL

2005-11-26 Thread Steven D'Aprano
On Sat, 26 Nov 2005 11:26:30 +0100, Martin P. Hellwig wrote:

> Steven D'Aprano wrote:
>> On Thu, 24 Nov 2005 17:43:22 +0100, Martin P. Hellwig wrote:
>> 
>>> if I owned a company 
>>> making profit on software sales (sale =! support) you sign a death wish 
>>> for using GPL
>> 
>> Apart from Microsoft, and possibly Quark (makers of Quark Express desktop
>> packaging software), and perhaps a few console game developers, is there
>> any company making a profit on software sales?
>> 
>> 
> 
> Eehm, about hundreds of thousands customized software manufactures 
> around the whole globe?

They don't sell software, they sell services: their expertise in
developing software. The difference is analogous to going to a builder to
buy a house, and going to a builder and paying him to build you a house.

I should know what I'm talking about: I work for one of them.

> Where not talking about off the shell software then of course, but for
> software used in a particular corner of a sector. 

And that's not "off the shelf"?

> Most prominent types
> are administration software, although most of them have a common base,
> implementation differs on your type of: products, customers, location,
> law, quality and quantity . Say about everything it can differ, ie you
> don't want to use your high-school student administration program for a
> pet shop or a cheese manufacture.


I think you are over-estimating both the numbers and profitability of such
niche software distributors, and misunderstanding the business models of
them.

Let me give you an example: some years ago, I was involved in an IT
project where a small wholesaler changed accounting software. Without
mentioning names, they purchased some licences to a mid-level package from
a consultant. I later found out that the consultant in fact made little
money from the sale: perhaps a few tens of dollars out of multiple
thousands. Most of the initial sale price went to the software vendor. The
consultant made her money from services: installation and training mostly.

Of course the software vendor made *some* money from the sale, but in
fact the majority of their income came from yearly service fees,
upgrade fees, compulsory upgrades ("pay for this upgrade or we will no
longer support your system"), customizations and similar. But even if
they were making some money from sales, that doesn't guarantee
profitability. 

"Being in the software business" can and will remain profitable into the
future, but I have serious reservations that "selling software" will be --
even today, few companies make money from selling software and rely more
on associated services for the bulk of their income.

Which is exactly what economics tells us to expect.



-- 
Steven.

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


Re: Hello World-ish

2005-11-26 Thread Jorge Godoy
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> from os import *
> print "Working path: %s" % os.getcwd();
> 
> Just wondering how you would do that .. in theory, if you get what I
> mean?
> I get
> NameError: name 'os' is not defined
> currently, which I don't know how to fix.. anyone?

Either:

import os

or

print "Working path: %s" % getcwd();



Avoid "from  import *" always when you can (there are still modules
designed to work with it).  It pollutes namespace and might lead to
undesirable clobbing of data structures (is it your 'getId' method or the
module's that is being used? ;-)).



Be seeing you,
-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Hello World-ish

2005-11-26 Thread [EMAIL PROTECTED]
from os import *
print "Working path: %s" % os.getcwd();

Just wondering how you would do that .. in theory, if you get what I
mean?
I get
NameError: name 'os' is not defined
currently, which I don't know how to fix.. anyone?

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


Re: Why is dictionary.keys() a list and not a set?

2005-11-26 Thread Christoph Zwerschke
Mike Meyer wrote:

 > I think you're trying to tweak the wrong definition. Types are
 > immutable if their instances are immutable.

I'm not trying to tweak it, but to gain more clarity about what is 
actually meant when you talk about "mutable" types and objects and 
whether it suffices to use these terms as long as you speak about 
built-in datatypes.

Tuples have been considered an immutable type since generations, becaue 
the elements of a tuple cannot be changed (i.e. the elements themselves, 
not their values). Likewise, they should be considered a hashable type 
because they have a proper hash function that can be used if all 
elements are hashable. Still, you can create instances of this 
immutable/hashable data type which are mutable/not hashable. So in the 
docs it will be important to be clear and emphasize that the *objects* 
have to be immutable/hashable, not only their types.

 > So whether or not a tuple containing a mutable object is
 > immutable depends on whether you define a immutable as "the object
 > can't change" or "the objects value can't change".

Right - if you have an actual tuple instance like (a,) and a is a list, 
you can argue whether it should be considered mutable or not. But you 
cannot argue whether it is hashable or not. It's simply not hashable. In 
so far, speaking about whether an object is hashable is more precise 
(well-defined) than asking whether it is mutable, you're right.

 > Do you think it's really necessary to specify "has a __hash__ method
 > that returns a value", as opposed to just "has a __hash__ method"?

I think it is necessary to require that it has a "proper" __hash__ 
function. As far as I understand you can always add a __hash__ method. 
Not only invalid __hash__ methods like in this case:

class mylist0(list):
 def __hash__(self): return None

But you can also easily add valid __hash__ methods:

class mylist1(list):
 def __hash__(self): return 0815

class mylist2(list):
 def __hash__(self): return id(self)

In the case of mylist1, everything is ok including semantics, but 
performance suffers dramatically. In mylist2, performance is great, but 
semantics suffers greatly.

Which of these user-defined types would you call "hashable"? Technically 
speaking, both probably are, so you can indeed use list objects of both 
types as keys of a dictionary - but I think there should be a hint in 
the docs that you need to have a "proper" hash function if you want your 
dictionary to be performant and show the usually expected behavior.

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


Re: wxPython Licence vs GPL

2005-11-26 Thread Chris F.A. Johnson
On 2005-11-26, Steven D'Aprano wrote:
>
> If you don't like that clause, you have two very simple options: don't
> redistribute the GPLed software. Or use some other software provided under
> a different licence.

There is a third option: persuade the owner of the copyright to
give you a different license.


-- 
   Chris F.A. Johnson, author   |
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is dictionary.keys() a list and not a set?

2005-11-26 Thread Christoph Zwerschke
Mike Meyer wrote:

> Ok, how about this for dictionaries/sets:
> 
> Any hashable object can be used as a dictionary key (set member). Immutable
> objects, except for tuples that contain a non-hashable object, are
> hashable. Python classes are normally hashable(1).

The problem with the last sentence is that can be misunderstood (classes 
themselves as objects are always hashable) and has little information 
otherwise (what is "normal"?).

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


Re: Profiling with hotshot and wall clock time

2005-11-26 Thread Dieter Maurer
Geert Jansen <[EMAIL PROTECTED]> writes on Thu, 24 Nov 2005 21:33:03 +0100:
> ...
> Is possible to use hotshot with wall clock time, i.e. is it possible
> to have the code fragment below show one second as opposed to zero? 
> The old profiler seems to have functionality choosing a timer function
> but it crashed on my code.

I do not know whether it is possible with "hotshop" but it is
with "profile". Depending on how large the waiting time it,
"profile" might be adequate to analyse the problem.


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


Re: wxPython Licence vs GPL

2005-11-26 Thread Martin P. Hellwig
Steven D'Aprano wrote:
> On Thu, 24 Nov 2005 17:43:22 +0100, Martin P. Hellwig wrote:
> 
>> if I owned a company 
>> making profit on software sales (sale =! support) you sign a death wish 
>> for using GPL
> 
> Apart from Microsoft, and possibly Quark (makers of Quark Express desktop
> packaging software), and perhaps a few console game developers, is there
> any company making a profit on software sales?
> 
> 

Eehm, about hundreds of thousands customized software manufactures 
around the whole globe?
Where not talking about off the shell software then of course, but for 
software used in a particular corner of a sector.
Most prominent types are administration software, although most of them 
have a common base, implementation differs on your type of: products, 
customers, location, law, quality and quantity . Say about everything it 
can differ, ie you don't want to use your high-school student 
administration program for a pet shop or a cheese manufacture.

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


Re: Which License Should I Use?

2005-11-26 Thread Mike Meyer
Steve Holden <[EMAIL PROTECTED]> writes:
> Simply assuming that because you have developed the code "in your own
> time" you have sole rights to it, or even a right to redistribute, is
> likely to lead to trouble and I would recommend against that course of
> action.

The employment agreement may state specifically that the company owns
such properties. There have been companies that explicitly claim all
software/inventions/etc that you produce while in their employee, even
if they had nothing to do with said IP. Some jurisdictions make this
illegal - but that doesn't stop the company from trying to convince
you they can do that.

But this cuts both ways - if you get them to agree in writing as part
of the employment agreement that the code isn't there, which Steve
suggested, then laws about "work for hire" are pretty much
irrelevant.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

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


Re: Which License Should I Use?

2005-11-26 Thread Steven D'Aprano
On Fri, 25 Nov 2005 11:30:46 -0800, mojosam wrote:

> I guess I don't care too much about how other people use it.

Then probably the best licence to use is just to follow the lead of
Python. For that sort of small program of limited value, I put something
like this in the code:

Copyright (c) 2005 Steven D'Aprano.
Released under the same license as used by Python 2.3.2 itself. 
See http://www.python.org/psf/license.html for details, and 
http://www.python.org/2.3.2/license.html for the full text of the license.

I use that as a no-brainer licence: it is weaker than but compatible with
the GPL, and requires less documentation.


> I will be doing the bulk of the coding on my own time, because I need to
> be able to take these tools with me when I change employers. However,
> I'm sure that in the course of using these tools, I will need to spend
> time on the job debugging or tweaking them.  I do not want my current
> employer to have any claim on my code in any way.  Usually if you
> program on company time, that makes what you do a "work for hire". I
> can't contaminate my code like that.  Does that mean the GPL is the
> strongest defense in this situation?

Not at all.

I am not a lawyer and this is not legal advice, but I suggest that your
*only* defence will be to get your employer to sign a legal agreement
acknowledging that you own the code. If you like, offer them a perpetual
royalty-free non-exclusive licence to use the code, and explain how using
your own code will make you more productive in their time.

If they refuse, then you must absolutely keep a cast-iron barrier between
what you develop in your own time and what you develop in theirs. To be
safe, I wouldn't even *use* that code in their time: if your productivity
suffers, that's their choice.

As an alternative, consider that who owns the copyright doesn't matter. If
your employer insists on keeping the copyright, get permission from them
to distribute the code under an open source licence. Then you can take it
with you when you leave, and still use it. 

Unless you explicitly sign them away (and even that is legally dubious)
you still retain the "moral rights" to the code, even if copyright is
owned by your employer: you can still say "I wrote this".

Please note that merely putting the code under a GPL or other OSS licence
is NOT sufficient -- they must agree to let you DISTRIBUTE the code.
Merely being under the GPL does not make it compulsory to distribute the
code, and if you distribute software copyrighted by your employer without
their permission, the fact that is GPLed is not going to save you.

Getting permission to put it up on the corporate website might be
sufficient, but if it were me, I'd insist on an agreement allowing me to
take the code with me when I leave. (This is only necessary if your
employer owns the copyright.)

It need not be a complicated agreement: I recently signed a copyright
transfer agreement for some employees who left the company to start their
own company. The agreement was less than two pages long.


-- 
Steven.

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


Re: wxPython Licence vs GPL

2005-11-26 Thread Martin P. Hellwig
Steven D'Aprano wrote:
> On Thu, 24 Nov 2005 23:26:38 +0100, Martin P. Hellwig wrote:
> 
>> BSD/MIT style license is a 
>> good substitute of no license at all.
> 
> But that's not true: "no licence at all" means that nobody has the right
> to use or copy or even *see* your work. You can, of course, choose to
> show them your work without a licence, but unless you give them a licence
> they can't legally do anything with it.
> 
> Perhaps you are thinking of the public domain, which does not require a
> licence, but that is because it is not owned by anyone -- not even you,
> the creator.
> 
> If you want to release your work with no restrictions whatsoever, then
> just put the work in the public domain. Is attribution really that
> important to you -- especially when that attribution may be buried deep in
> the source code of software which nobody will ever see?
> 
> 

Well I don't know how it's legally outside (most of) the EU, but here if 
your are actioned in publishing information of any kind (including 
source code) without restricting it, you can not refer to any copyrights 
or protected IP thereafter, but you still are responsible for the 
consequences of your action if the results are related to a more or less 
unmodified version of your publishing. Of course you still have the 
right to claim to be the original author and accuse anybody else who 
falsely claim that as plagiarist.

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


Re: Making immutable instances

2005-11-26 Thread Mike Meyer
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Fri, 25 Nov 2005 23:20:05 -0500, Mike Meyer wrote:
>> If you've got a use case, I'd be interested in hearing it.
> frozenset perhaps? If it were needed once, it could be needed again.

That's not a use case, that's an example. And not a very good one, as
it's not at all clear that the restriction is intentional in that
case. After all, the same restriction applies to every builtin type,
including the mutable version of frozenset.

> The obvious case would be for a class where distinct instances that
> compare equal but not identical map to the same value in a dict.

How does the ability to add attributes to the instances of the class
change that behavior?

> In any case, I'm not the one claiming that I need custom immutable
> classes. I'm just suggesting that there is nothing non-Pythonic about
> them. If Ben thinks he needs them, I'm sure he has put *far* more thought
> into it than I have. I know Ben in RL, and he is not someone to make snap
> judgements about turning Python into Some Other Language Just Because.

I claim that the dynamic natture of Python - which is exemplified by
things like duck typing and the ability to add attributes to nearly
everything on the fly - is a fundamental part of what makes Python
Python. The best reason Ben could come up with is that it makes
finding bugs a bit easier. But so do type declarations, static
namespaces, private and protected attributes, and a slew of similar
B&D features that are pretty much anathema to dynamic languages. This
feature fits *very* well in languages that have those features, and
poorly in languages that reject them, which includes Python.

Of course, that a feature has a lot in common with features from
un-Pythonic languages doesn't make it ipso facto unPythonic. After
all, practicality beats purity. So what's the practical application
for such a feature? What's the use case?

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as Guido Intended

2005-11-26 Thread Mike Meyer
Paul Rubin  writes:
> Mike Meyer <[EMAIL PROTECTED]> writes:
>> Those two statements say the same thing. Part of the Python philosphy,
>> from "import this", is that there should only be one obvious way to do
>> it. By enabling that part of Python's philosphy, you're automatically
>> limiting python to not allow other - specifically non-pythonic - ways
>> to do the same thing.
> Sometimes there are zero obvious ways to do it, or an obvious way that
> doesn't work, so if you want to do it at all, you have to find a
> contorted way.  At that point it's normal to ask why there isn't an
> obvious way that works.  All too often, the answer is "that would be
> un-Pythonic".

Examples?

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython Licence vs GPL

2005-11-26 Thread Mike Meyer
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> But if you *do* redistribute it, then you must live up to conditions in
> the licence. If you aren't willing to do that, use software with a
> different licence. 

That's a restriction on redistribution.

> The only restriction is that you can't give those people fewer,
> weaker rights than you got

That's a restriction on redistribution.

> I would still like to find out what sense of "restricting distribution"
> you think the GPL does.

You named the restrictions yourself.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython Licence vs GPL

2005-11-26 Thread Steven D'Aprano
On Fri, 25 Nov 2005 20:54:55 -0500, Mike Meyer wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> On Thu, 24 Nov 2005 16:00:29 -0500, Mike Meyer wrote:
>> The GPL doesn't restrict distribution. I don't understand where
>> people get this bizarre view of the GPL from.>
> 
> It happens because people say things like:
> 
>> If you don't like that clause, you have two very simple options: don't
>> redistribute the GPLed software. Or use some other software provided under
>> a different licence.

If you don't want to redistribute the GPLed software, then don't. Nobody
can force you to. I use lots of GPL software which I don't redistribute.

But if you *do* redistribute it, then you must live up to conditions in
the licence. If you aren't willing to do that, use software with a
different licence. 

You are free to redistribute it for free, or charge a bazillion dollars.
You can choose to only redistribute to people with green hair. The only
restriction is that you can't give those people fewer, weaker rights than
you got: having got the software from you, you can't prevent those green
haired people from distributing it to anyone they like, even baldies or
brunettes.

Unlike proprietary licences, the GPL doesn't prohibit you from
redistributing the software, nor does it make you count licences. It
doesn't prohibit you from distributing the software to people who haven't
paid a licence fee, or to people with eleven fingers. 

I would still like to find out what sense of "restricting distribution"
you think the GPL does. As near as I can tell, the only sense that the GPL
restricts distribution is that if you redistribute GPLed code you must not
take away the rights you were granted from those you distribute too.


-- 
Steven.

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


Re: wxPython Licence vs GPL

2005-11-26 Thread Steven D'Aprano
On Sat, 26 Nov 2005 03:25:58 +, Ed Jensen wrote:

> Paul Rubin  wrote:
>> Python and *BSD are getting far less volunteer development love than,
>> say, GCC or Linux, and the licensing is at least part of the reason.
> 
> I disagree.  I believe *BSD gets less volunteer development because of
> some legal wrangling in the early 90s that didn't affect Linux.

That was over a decade ago, and the BSD licence was vindicated by the
courts -- why has there been such limited volunteer development, and
practically zero commercial development, for BSD?

The BSDs are about 15 years older than Linux, and the legal wrangling they
went through were no worse than the SCO nonsense going on now. With a 15
year head start, and 10 years since the legal problems, why has BSD never
attracted 1% the commercial interest of Linux?

You can often tell something of a thing by those who oppose it. Microsoft
is perhaps the epitome of the closed-source mentality: on the rare
occasions they release their source code at all, they do so only
grudgingly, never the entire tool chain, at very high cost, and with
exceedingly restrictive conditions. (Yes, I'm aware I'm generalising --
but it is a valid generalisation, one or two minor exceptions doesn't
invalidate the overall picture of Microsoft's desire to keep their source
code locked up tight.)

Microsoft is spending a lot of time and effort trying to fight the GPL,
but have said that BSD licences are acceptable to them. In fact they
*love* BSD licences -- for others, just not for themselves.

And no wonder: Windows only has an TCP/IP stack because they could grab
the BSD source code and use it. Has Microsoft show any gratitude to the
BSDs? Have they returned any code to BSDs, or given money to BSD coders?
In a pig's ear they have.

Microsoft stands for closed source software: they absolutely hate the
GPL. But they like the BSD licence, because it lets them freeload
off the labour of idealistic programmers for free, without so much as a
thank you.



-- 
Steven.

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


Re: Which License Should I Use?

2005-11-26 Thread Steve Holden
mojosam wrote:
> I've been watching the flame war about licenses with some interest.
> There are many motivations for those who participate in this sector, so
> disagreements over licenses reflect those agendas.
> 
> I don't have an agenda, at least not right now.  I do plan on writing a
> few programs.
> 
> These will be tools I need for firmware testing.  They will be
> relatively simple things like tools for breaking down data by its
> structure for easy viewing, sending commands/macros over serial ports,
> etc.  Similar things exist, but they don't do everything I need.  These
> will also be excellent learning opportunities for me, since I'm still
> pretty shaky on Python.
> 
> How do I decide on a license?  Are there any web sites that summarize
> the pros and cons?  I guess I don't care too much about how other
> people use it.  These things won't be comprehensive enough or have
> broad enough appeal that somebody will slap a new coat of paint on them
> and try to sell them.  I guess I don't care if somebody incorporates
> them into something bigger.  If somebody were to add features to them,
> it would be nice to get the code and keep the derivative work as open
> source, but I don't think that matters all that much to me.  If
> somebody can add value and find a way of making money at it, I don't
> think I'd be too upset.
> 
> I will be doing the bulk of the coding on my own time, because I need
> to be able to take these tools with me when I change employers.
> However, I'm sure that in the course of using these tools, I will need
> to spend time on the job debugging or tweaking them.  I do not want my
> current employer to have any claim on my code in any way.  Usually if
> you program on company time, that makes what you do a "work for hire".
> I can't contaminate my code like that.  Does that mean the GPL is the
> strongest defense in this situation?
> 
> I'm open to suggestions as to which licenses to consider.  However,
> please try to keep the conversation to the decision process or what
> sounds like it is best for this purpose.  Let's keep the broader issue
> of which license will bring about the fall of Western Civilization on
> the other thread.
> 

Openness is your best protection here, as licensing the software can 
only impose conditions on those who accept it under the license. It 
cannot affect your employer's rights to work you performed while an 
employee. Those rights are determined by applicable law.

The only way to ensure that you can take your own unencumbered copy of 
code you wrote as an employee is to explain the position fully to your 
employer and get their agreement, in writing and in advance, that they 
are prepared to have you do so.

Simply assuming that because you have developed the code "in your own 
time" you have sole rights to it, or even a right to redistribute, is 
likely to lead to trouble and I would recommend against that course of 
action.

Apart from that, as others have suggested it looks like a BSD-style 
license would suit you best.

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: Unicode in MIMEText

2005-11-26 Thread Steve Holden
Damjan wrote:
>>... and being concerned to improve the library you logged this patch in
>>Sourceforge for consideration by the developers?
>>
>>That's the only way to guarantee proper consideration of your fix.
> 
> 
> Ok I will, can you confirm that the patch is correct?
> Maybe I got something wrong?
> 
> 
I can't confirm its correctness but I can say it looks reasonable enough 
to submit as a path. The fact that you have identified an issue and a 
possible fix is quite enough to allow you to submit the patch.

The adequacy of the patch will ultimately be decided by the maintainer 
who considers your submission (in all probability Barry Warsaw, but not 
necessarily).

Thanks for taking the time to improve the quality of the Python library.

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


  1   2   >