Where can I get Lucid Toolkit?

2008-11-11 Thread est
Hi guys,

I tried to grab source code for  Lucid Toolkit 
http://www.clarographics.org/svn_details
which was mentioned http://wiki.python.org/moin/GuiProgramming

So is this project abandoned? Is there any backup that I can get the
code?

Any other recommands for simple GUI development, with out large
library runtime(qt, gtk, wx) ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.5.3: call for patches

2008-11-11 Thread Matthias Klose
Martin v. Löwis schrieb:
>> I would like to apply fixes for some CVE's which are addressed in 2.5 but not
>> yet in 2.4. this would include
>>
>> CVE-2007-4965
>> CVE-2008-1679
>> CVE-2008-1721
>> CVE-2008-2315
>> CVE-2008-3144
>> CVE-2008-1887
>> CVE-2008-4864
> 
> Can you identify the revisions that would need backporting?
> 
> I could only find (trunk revisions)
>   CVE-2007-4965: r65880
>   CVE-2008-1721: r62235, issue2586
>   CVE-2008-3144: issue2588, issue2589, r63734, r63728.
>   CVE-2008-1887: issue2587, r62261, r62271
>   CVE-2008-4864: r66689
> 
> So what about
> 
>   CVE-2008-1679: claimed to be issue1179 in the CVE, but
>  that says it fixes CVE-2007-4965 only?

the original fix for CVE-2007-4965 did miss two chunks, which are included in
r65878 on the 2.5 branch.

>   CVE-2008-2315

this is r65334 on the 2.5 branch and r65335 on the trunk:
Security patches from Apple:  prevent int overflow when allocating memory
this was already checked in, with an added NEWS item in 2.4.5. Moved this
to 2.4.6.

> In principle, this is fine with me, so go ahead.

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


inspect.findsource problem with llinecache

2008-11-11 Thread Rafe
Hi,

I think I have discovered two bugs with the inspect module and I would
like to know if anyone can spot any traps in my workaround.

I needed a function which takes a function or method and returns the
code inside it (it also adjusts the indent because I have to paste the
to a text string without indents, which is parsed later...long story).
At first this seemed trivial but then I started getting an error on
line 510 of inspect.py:
504if iscode(object):
505if not hasattr(object, 'co_firstlineno'):
506raise IOError('could not find function definition')
507lnum = object.co_firstlineno - 1
508pat = re.compile(r'^(\s*def\s)|(.*(? 0:
510if pat.match(lines[lnum]): break
511lnum = lnum - 1
512return lines, lnum

I finally figured out that there was a caching problem. The function I
passed was changed, but the code lines (strings) retrieved by
linecache.getlines() (on lines 464 and 466) didn't update with the new
module contents. The resulting error I was getting occurred when real
module had less lines than the cached module (or the other way around,
whatever.)

To get around this, I invoke linecache.clearcache(). Here is the
function (minus doc strings)...

INDENT_SPACES = 4

def get_fn_contents(fn, remove_indents=1):
# Clear the cache so inspect.getsourcelines doesn't try to
# check an older version of the function's module.
linecache.clearcache()
source_lines, n = inspect.getsourcelines(fn)

# Skip the first line which contains the function definition.
# Only want the code inside the function is needed.
fn_contents = source_lines[1:]

# Remove indents
new_indent_lines = [remove_indent(line, remove_indents) for line
in fn_contents]

return "".join(new_indent_lines)


def remove_indent(in_str, num_indent=1):
s = in_str
for i in range(num_indent):
if s[:INDENT_SPACES] == "":   # Whitespace indents
s = s[INDENT_SPACES:]
elif s[:1] == "\t":   # Tab characters indents
 s = s[1:]

return s

[END CODE]

The second issue is that the last line in the passed function's module
seems to be ignored. So, if the last line of the module is also the
last line of the function, the function is returned one line too
short.

I welcome comments on the bugs or optimization pointers for my code. I
am still quite new to Python. My primary question though is: will
linecache.clearcache() cause me any problems?

Thanks,

- Rafe


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


Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-11 Thread Arnaud Delobelle
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> I am very happy to say that x=1 implies that the value of x is the object 
> 1 itself, in fact I would insist on such a definition of value.
>
> If you insist that Python is call by value, the only way that can work is 
> by defining values to be references

That's a neat and concise way of summarising this whole thread.

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


Re: SHA1withRSA in python

2008-11-11 Thread Python Nutter
For simple hashing algorithms, then use the aformentioned built in
hashlib in Python.

However for the rest you need M2Crypto to get a wrapper around OpenSSL:

M2Crypto is the most complete Python wrapper for OpenSSL featuring
RSA, DSA, DH, HMACs, message digests, symmetric ciphers (including
AES); SSL functionality to implement clients and servers; HTTPS
extensions to Python's httplib, urllib, and xmlrpclib; unforgeable
HMAC'ing AuthCookies for web session management; FTP/TLS client and
server; S/MIME; ZServerSSL: A HTTPS server for Zope and ZSmime: An
S/MIME messenger for Zope. M2Crypto can also be used to provide SSL
for Twisted.

http://chandlerproject.org/Projects/MeTooCrypto


Cheers,
PN

2008/11/12 Mailing List SVR <[EMAIL PROTECTED]>:
> Hi all,
>
> in java there are several libraries for sha1withrsa, there is something
> similar in python?
>
> thanks
> Nicola
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing: request for pointers

2008-11-11 Thread Steven D'Aprano
On Tue, 11 Nov 2008 11:59:50 -0800, André wrote:

> 4. I want to do this only using modules in the standard Python
>library, as I want to use this to learn about the basics of parsing. 
>So, please don't *simply* suggest to use a third-party module, such
>as
>[1] plex, [2] yapps, [3] pyparsing
>The learning journey is more important for me than just having a
>canned solution to my (current) parsing problem.

Believe me, there is no canned solution to your current parsing problem. 
Once you have a parser engine (e.g. pyparsing) you still have to build a 
parser, and that's not necessarily trivial.

Other than that, try this:

http://docs.python.org/library/shlex.html



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


Re: How can a function know what module it's in?

2008-11-11 Thread Rafe
On Nov 12, 11:17 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> Some corrections, to highlight the depth of my confusion...
>
> On Nov 11, 2008, at 9:10 PM, Joe Strout wrote:
>
> >    doctest.testmod(mymodule)
>
> > This actually works fine if I'm importing the module (with the  
> > standard name) somewhere else
>
> Actually, it does not.
>
> > I noticed that a function object has a __module__ attribute, that is  
> > a reference to the module the function is in.
>
> And no, it isn't; it's the NAME of the module the function is in.  I'm  
> not sure what good that does me.  docstring.testmod does take an  
> optional "name" parameter, but the documentation (at least in 2.5.2)  
> does not explain what this parameter is used for.  I tried using it  
> thusly:
>
>         doctest.testmod(name=_test.__module__)
>
> but that didn't work; it appears to still be testing the __main__  
> module.  (Perhaps the name parameter is only used to describe the  
> module in the output, in which case, all I've accomplished here is  
> getting doctest to lie.)
>
> > I'm sure there is a magic identifier somewhere that lets a code get  
> > a reference to its own module, but I haven't been able to find it.  
> > Can someone share a clue?
>
> This question remains open.  :)
>
> Thanks,
> - Joe

import sys
this_module = sys.modules[__name__]

sys.modules is a dictionary of all modules which have been imported
during the current session. Since the module had to be imported to
access it, it will be in there. '__name__' is available inside
functions because it is in the module scope.

Classes are a little more tricky because doing something like:
this_module = sys.modules[self.__class__.__module__]
will return a different module if the class is inherited in a
different module (since the base class is __class__ now). However,
putting a function at the module level (in the super-class module)
should anchor the results (untested though).

I'm not sure if this is the answer you need with regards to doctest,
but it I think it answers the question in the subject of this thread.

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


Re: How can a function know what module it's in?

2008-11-11 Thread Joe Strout

Some corrections, to highlight the depth of my confusion...

On Nov 11, 2008, at 9:10 PM, Joe Strout wrote:


doctest.testmod(mymodule)

This actually works fine if I'm importing the module (with the  
standard name) somewhere else


Actually, it does not.

I noticed that a function object has a __module__ attribute, that is  
a reference to the module the function is in.


And no, it isn't; it's the NAME of the module the function is in.  I'm  
not sure what good that does me.  docstring.testmod does take an  
optional "name" parameter, but the documentation (at least in 2.5.2)  
does not explain what this parameter is used for.  I tried using it  
thusly:


doctest.testmod(name=_test.__module__)

but that didn't work; it appears to still be testing the __main__  
module.  (Perhaps the name parameter is only used to describe the  
module in the output, in which case, all I've accomplished here is  
getting doctest to lie.)


I'm sure there is a magic identifier somewhere that lets a code get  
a reference to its own module, but I haven't been able to find it.   
Can someone share a clue?


This question remains open.  :)

Thanks,
- Joe

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


How can a function know what module it's in?

2008-11-11 Thread Joe Strout
I've been using docstring to exercise each of my modules, with code  
like this:


def _test():
import doctest
doctest.testmod()

if __name__ == "__main__":
_test()


This works great when I execute each module by itself.  However, if I  
want to call mymodule._test() from somewhere else, it doesn't work,  
because doctest.testmod() tests the __main__ module instead of  
mymodule.  And of course changing the call to this doesn't work either:


doctest.testmod(mymodule)

This actually works fine if I'm importing the module (with the  
standard name) somewhere else, but not when I'm executing it directly,  
or (I would guess) if the module is imported under a different name.


What I want to express is "doctest THIS module, right here, the one  
this code is in!"  But I can't find a clean way to do that.


I noticed that a function object has a __module__ attribute, that is a  
reference to the module the function is in. But that just pushes the  
problem back a step: how can a function get a reference to itself?


I'm sure there is a magic identifier somewhere that lets a code get a  
reference to its own module, but I haven't been able to find it.  Can  
someone share a clue?


Thanks,
- Joe



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


Re: cannot pickle object returned by urllib2.urlopen()

2008-11-11 Thread Steven D'Aprano
On Wed, 12 Nov 2008 11:00:26 +0800, scsoce wrote:

> got a exception:  "a class that defines __slots__ without defining
> __getstate__ cannot be pickled "
> why?
> and is there any other dump method but for pickle to store the kind of
> object ?

I can't answer either of your questions, but why are you trying to pickle 
an open connection to a (possibly remote) URL? I can't imagine how that 
could possibly work even in principle.



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


Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-11 Thread Steven D'Aprano
On Wed, 12 Nov 2008 02:44:42 +, Steven D'Aprano wrote:

> But one thing is clear: values aren't references. Given the assignment
> x=1, the value of x is not "a reference to 1" but 1 itself. So the one
> thing we can unambiguously say is that Algol's assignment model is not
> the same as Python's assignment model.

Sorry, this is very misleading.

What I meant to say is that if you are one of those people who insist 
that values in Python are references, then Algol's assignment model is 
not that same as what you understand Python assignment to be.

I am very happy to say that x=1 implies that the value of x is the object 
1 itself, in fact I would insist on such a definition of value.

If you insist that Python is call by value, the only way that can work is 
by defining values to be references, which is nothing like Algol.



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


cannot pickle object returned by urllib2.urlopen()

2008-11-11 Thread scsoce
got a exception:  "a class that defines __slots__ without defining 
__getstate__ cannot be pickled "
why? 
and is there any other dump method but for pickle to store the kind of 
object ?


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


Re: pysqlite install error on hp ux (ld: Can't find library for -lpython2.5)

2008-11-11 Thread Geon.
On 11월11일, 오후6시10분, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> * Geon. (Mon, 10 Nov 2008 18:00:56 -0800 (PST))
>
>
>
>
>
> > On 11?10?, ??1?31?, ??? <[EMAIL PROTECTED]> wrote:
> > > On Nov 10, 10:29 am, "Geon." <[EMAIL PROTECTED]> wrote:
> > > > when i install pysqlite i meet bellow error. ( use easy_install and
> > > > source code building same problem )
>
> > > > ld: Can't find library for -lpython2.5
>
> > > > what mean this message? and what i do?
>
> > > > my system is hp-ux 11i v3. and python2.5 is installed.
> > > > ld command also avaliable.
>
> > > > please help for me~
>
> > > Hi, as far as I know.
>
> > > 1. you can use module sqlite3 instead.
> > > 2. you can use these commands on ubuntu:
>
> > > sudo apt-get install libsqlite3-dev
> > > sudo easy_install -Z pysqlite
>
> > is possible apt-get on hp unix?
> > i think apt-get is only available ubuntu linux system..
>
> No, on all Debian based distributions.
>
> Thorsten- 따온 텍스트 숨기기 -
>
> - 따온 텍스트 보기 -

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


Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-11 Thread Steven D'Aprano
On Wed, 12 Nov 2008 13:10:10 +1300, greg wrote:

> Here is the definition of call-by-value from the "Revised Report on the
> Algorithmic Language Algol 60"
> :


Why should anyone take the "Revised Report on the Algorithmic Language 
Algol 60" as the "official" (only?) definition of call-by-value for all 
languages everywhere?

Particularly since in practice, people's *understanding* of such terms 
have more to do with common practice than formal definitions. You're 
welcome to tell people that tomatoes are actually berries from the Deadly 
Nightshade family of plants, rather than vegetables, but if you do so you 
better follow it up with further explanations.



> 4.7.3.1. Value assignment (call by value). All formal parameters quoted
> in the value part of the procedure declaration heading are assigned the
> values (cf. section 2.8. Values and types) of the corresponding actual
> parameters, these assignments being considers as being performed
> explicitly before entering the procedure body. The effect is as though
> an additional block embracing the procedure body were created in which
> these assignments were made to variables local to this fictitious block
> with types as given in the corresponding specifications (cf. section
> 5.4.5).

I notice that you deleted the last sentence of the definition. I quote:

"As a consequence, variables called by value are to be considered as 
nonlocal to the body of the procedure, but local to the fictitious block 
(cf. section 5.4.3)."

And what's the fictitious block? As I understand it, their intention is 
to say that calling a procedure foo(x) with an actual argument y should 
be considered the same as:

# start a new block (a new scope, in Python terminology)
x = y   # behave as if we explicitly assigned y to x
foo(x)  # enter the body of foo with argument x local to the new block


What are the consequences of such assignment? Unfortunately, assignment 
isn't unambiguously defined:


"4.2.3. Semantics. Assignment statements serve for assigning the value of 
an expression to one or several variables or procedure identifiers. 
Assignment to a procedure identifier may only occur within the body of a 
procedure defining the value of a function designator (cf. section 
5.4.4). The process will in the general case be understood to take place 
in three steps as follows:
4.2.3.1. Any subscript expression occurring in the left part variables 
are evaluated in sequence from left to right.
4.2.3.2. The expression of the statement is evaluated.
4.2.3.3. The value of the expression is assigned to all the left part 
variables, with any subscript expressions having values as evaluated in 
step 4.2.3.1."


In other words, assignment takes three steps: 

(1) evaluate the subscript expressions on the left part (presumably of 
the statement); 

(2) evaluate the expression of the statement (presumably the right hand 
side, but the document doesn't make that clear);

(3) assign the value of the expression.

Got that? Assignment means the value is assigned. Glad that's all clear 
then.

So given an assignment of x = y in Algol, it isn't clear from this 
document whether x and y refer to the same value, or if they merely have 
the same value by equality. That second case would imply copying. To put 
it in Python terms, following x = y we know that x == y is true but we 
don't know whether id(x) == id(y).


Can we at least determine what variables and values are? Well, almost... 

"3.1.3. Semantics. A variable is a designation given to a single value."

Okay, a variable is a designation (a name if you prefer) for a value. So 
what's a value?


"2.8. Values and types
 
A value is an ordered set of numbers (special case: a single number), an 
ordered set of logical values (special case: a single logical value), or 
a label.
Certain of the syntactic units are said to possess values. These values 
will in general change during the execution of the program The values of 
expressions and their constituents are defined in section 3. The value of 
an array identifier is the ordered set of values of the corresponding 
array of subscripted variables (cf. section 3.1.4.1)."


Now we're getting somewhere! Values are sets of numbers or sets of true/
false logical elements. Hmmm... apparently strings aren't values in 
Algol. Oh well.

But one thing is clear: values aren't references. Given the assignment 
x=1, the value of x is not "a reference to 1" but 1 itself. So the one 
thing we can unambiguously say is that Algol's assignment model is not 
the same as Python's assignment model.



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


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Steve Holden
Phillip B Oldham wrote:
> On Nov 11, 9:24 pm, paul <[EMAIL PROTECTED]> wrote:
>> Phillip B Oldham schrieb:> Are there any FOSS Python Single-Sign-on Servers?
>>
>> [snip]
>>
>>> I've searched around but can only seem to find OpenID servers, which
>>> will probably be too "open" for our needs.
>> So if it is not OpenID, which protocol are you going to implement?
> 
> In theory, we could use an OpenID server: our staff could register
> with something like MyOpenID, register with each of our individual
> webapps, and then gain access with a single sign-on. However, its not
> really getting round the problem we have: we need to give our staff
> access to all of our apps in one go, give them one place to sign on,
> and have the ability to disable their account at short notice. Doing
> this with openid would mean we have *no* access to the user account
> and therefore would still have the overhead of having to disable
> accounts with each webapp we provide. It also opens-up a security
> threat in that anyone could register to our "internal" apps with an
> OpenID account. Which is bad.
> 
> Essentially, we need a SSO server with which we would register our
> *webapps* and then create user account, specifying which webapps that
> user has access to, and at what level. Essentially something like
> OpenSSO but python-based.

Why not just implement a private OpenID server and only accept
identities from that domain?

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Strange output from list

2008-11-11 Thread Steve Holden
Rob Williscroft wrote:
> Steve Holden wrote in news:mailman.3804.1226412496.3487.python-
> [EMAIL PROTECTED] in comp.lang.python:
> 
>>> Shouldn't it be GROUP BY master.id? I would have thought that SQL
>>> would be sad about a non-aggregate (master.id) that's in the SELECT
>>> list but not also in the GROUP BY list.
>>>
>> Well, I did say "untested". But in SQL Server, for example, any field
>> argument to COUNT() must be an aggregated column. So it may depend on
>> the SQL implementation. I should really have said
> 
> You must mean an "SQL Server" other than the Microsofts one, as:
> 
>   select count( aid ) as "count"
>   from table_1
>   group by aid
> 
>   count
>   ---
>   8
>   8
>   8
>   8
>   8
>   8
>   8
>   8
> 
>   (8 row(s) affected)
> 
> and:
> 
>   select count( aid ) as "count"
>   from table_1
> 
>   count
>   ---
>   64
> 
>   (1 row(s) affected)
> 
> Like it should.
> 
Hmm, strange. I must be thinking of some other SQL Server then. Or, more
likely, some other error situation.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-11 Thread Aahz
In article <[EMAIL PROTECTED]>,
greg  <[EMAIL PROTECTED]> wrote:
>
>Here is the definition of call-by-value from the
>"Revised Report on the Algorithmic Language Algol 60"
>:
>
>4.7.3.1. Value assignment (call by value). All formal parameters quoted in the 
>value part of the procedure declaration heading are assigned the values (cf. 
>section 2.8. Values and types) of the corresponding actual parameters, these 
>assignments being considers as being performed explicitly before entering the 
>procedure body. The effect is as though an additional block embracing the 
>procedure body were created in which these assignments were made to variables 
>local to this fictitious block with types as given in the corresponding 
>specifications (cf. section 5.4.5).
>
>There you have it -- call by value is offially defined in
>terms of assignment. There is no mention in there of copying.
>
>So it's perfectly correct to use it in relation to Python.

Except, of course, for the fact that it is generally misleading.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
--
http://mail.python.org/mailman/listinfo/python-list


Re: sorting list of complex numbers

2008-11-11 Thread Steve Holden
Thomas Bellman wrote:
> Steve Holden <[EMAIL PROTECTED]> wrote:
> 
>> Only half the number, of course. The advantage of the key function is
>> that each element requires only one call out to a Python function, and
>> the comparisons then take place using a C-coded comparison function.
> 
> You don't need any Python-coded function at all.  The operator
> module is your friend: key=operator.attrgetter('real', 'imag')
> will create the required tuples for sorting.
> 
True; "requires only one call out to the key function", then. You're
right, attrgetter will be faster still, and it's a really neat solution.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: python bug when subclassing list?

2008-11-11 Thread Steve Holden
Hamish McKenzie wrote:
> I want to write a Vector class and it makes the most sense to just
> subclass list.  I also want to be able to instantiate a vector using either:
> 
>  
> 
> Vector( 1, 2, 3 )
> 
> OR
> 
> Vector( [1, 2, 3] )
> 
>  
> 
>  
> 
> so I have this:
> 
>  
> 
> class Vector(list):
> 
>   def __new__( cls, *a ):
> 
> try:
> 
>   print a
> 
>   return list.__new__(cls, a)
> 
> except:
> 
>   print 'broken'
> 
>   return list.__new__(cls, list(a))
> 
>  
> 
>  
> 
> doing Vector( 1, 2, 3 ) on this class results in a TypeError – which
> doesn’t seem to get caught by the try block (ie “broken” never gets
> printed, and it never tries to
> 
>  
> 
> I can do pretty much the exact same code but inheriting from tuple
> instead of list and it works fine.
> 
>  
> 
> is this a python bug?  or am I doing something wrong?
> 
Vector(1, 2, 3) fails for exactly the same reasons as list:

>>> list(1, 2, 3)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: list() takes at most 1 argument (3 given)

So the behavior you want cannot be inherited from list, since list
doesn't implement that behavior!

As toy our assertion that you can subclass tuple that way, I am inclined
to doubt it because of this:

>>> tuple(1, 2, 3)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: tuple() takes at most 1 argument (3 given)

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Simple question about Python lists

2008-11-11 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Wed, 12 Nov 2008 10:08:45 +1100, Ben Finney wrote:
> 
> > Eric <[EMAIL PROTECTED]> writes:
> >> In MATLAB, if  I just want the first, fifth  and eighth element I
> >> might do something like this:
> >> 
> >> b = a([1 5 8]);
> > 
> > Yes: the above code uses magic numbers which convey no semantic
> > meaning, and should instead use *named* elemets of a container. In
> > Python, that's done with a mapping type, which has the built-in
> > type of ‘dict’.
> > 
> > In other words: a list is best for sequences where any item is
> > semantically identical to any other, and you can (for example)
> > re-order all the elements in the list without changing their
> > semantic meaning. If, instead, you want semantic meaning, that's
> > best done via *names*, not magic numbers.
> 
> What the OP is asking for is a generalization of slicing.

I don't think so. (The OP is, of course, welcome to respond to
this or existing requests for clarification of their intent.)

> Given a slice alist[start:end:stride] the indices are given by the
> sequence start+i*stride, bounded by end. It seems to me that the OP
> has asked how to take a slice where the indices are from an
> arbitrary set, possibly given by an equation, but not necessarily.

I think that's exactly what is *not* being asked for, based on the
specific example given. The example was “I just want the first,
fifth, and eighth element”, and the example implementation showed
them with those numeric literals in the code. On that basis I
interpreted the need for *those elements specifically*, for some
semantic reason not yet disclosed.

If, instead, the OP wanted to retrieve “indices … from an arbitrary
set, possibly given by an equation”, I would recommend that *that
equation* be abstracted behind an expression, or even a well-named
function, that would make explicit what the *meaning* of the set was.

I maintain that anything which expresses “retrieve the indices at
these numbers” without saying *in the code* what the meaning of those
numbers is, is to be deprecated in favour of an implementation that
makes the semantic meaning explicit.

And no, before anyone suggests it, an explanatory comment is not
sufficient for this condition: the names and types used should make
clear what the meaning of the expression is. A comment saying *why* is
always appreciated; but if the comment needs to tell me *what* the
code is doing or *how*, the code instead needs to be re-written to be
explicit.

-- 
 \  “Saying that Java is nice because it works on all OSes is like |
  `\ saying that anal sex is nice because it works on all genders” |
_o__)—http://bash.org/ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question about Python lists

2008-11-11 Thread Robert Kern

Steven D'Aprano wrote:

On Wed, 12 Nov 2008 10:08:45 +1100, Ben Finney wrote:


Eric <[EMAIL PROTECTED]> writes:


I'm learning Python (while coming from MATLAB). One question I have is
that if I have a list with say 8 elements, and I want just a few of
them how do I select them out. In MATLAB, if I just want the first,
fifth and eighth element I might do something like this:

b = a([1 5 8]);

I can't seem to figure out a similar Python construct for selecting
specific indices. Any suggestions?

Yes: the above code uses magic numbers which convey no semantic meaning,
and should instead use *named* elemets of a container. In Python, that's
done with a mapping type, which has the built-in type of ‘dict’.

In other words: a list is best for sequences where any item is
semantically identical to any other, and you can (for example) re-order
all the elements in the list without changing their semantic meaning.
If, instead, you want semantic meaning, that's best done via *names*,
not magic numbers.



While I see your point, and in practice there are circumstance where I 
would agree with you, I don't agree in general.


What the OP is asking for is a generalization of slicing. Slices already 
take a stride:




alist = range(20)
alist[2:17:3]

[2, 5, 8, 11, 14]

Given a slice alist[start:end:stride] the indices are given by the 
sequence start+i*stride, bounded by end. It seems to me that the OP has 
asked how to take a slice where the indices are from an arbitrary set, 
possibly given by an equation, but not necessarily. No practical examples 
come to mind just off the top of my head, but given that the OP is coming 
from a Matlab background, I bet they involve some pretty hairy maths.


Hmmm... let's see now...

http://en.wikipedia.org/wiki/Series_(mathematics)
#Summations_over_arbitrary_index_sets

To put it another way... suppose you have a sequence S given by a list, 
and a set of indexes I (perhaps given by a tuple or a set), and you want 
to sum the terms of S at those indexes, which mathematicians apparently 
have good reason for doing, then you might write in Python:


sum(S[i] for i in I)

But if there was slicing support for arbitrary indexes, you could write:

sum(S[I])

which is apparently what Matlab allows. Standard lists don't support this 
slicing generalization, but numpy arrays do.


It's also worth noting that using a literal list is pretty rare. Usually the 
index array/list comes from some other computation. The OP was just trying to be 
describe the feature he wanted; that's not always the same thing as the use case 
that drives the feature.


--
Robert Kern

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

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


Re: How to make arrays from Lists

2008-11-11 Thread Robert Kern

[EMAIL PROTECTED] wrote:

On Nov 11, 7:48 pm, [EMAIL PROTECTED] wrote:

gc_ott:


How do I change the value of any element to produce (say)
[[99,0,0],[0,0,0],[0,0,0]] ?
gordc

To create a 2D list, that is a list of lists:
x = [[0] * ncols for i in nrows]
(Don't do what you were doing, because you end with many references to
the same list, and that will give you troubles.)

To set an item you do just:
x[0][0] = 99

Bye,
bearophile


Many thanks, I don't think I would ever 'discovered' this.


If you are trying to emulate numerical arrays, you may want to use numpy, 
instead.

  http://numpy.scipy.org/

import numpy
x = numpy.zeros([3,3], dtype=int)
x[0,0] = 99

--
Robert Kern

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

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


Re: best python unit testing framwork

2008-11-11 Thread Roy Smith
In article 
<[EMAIL PROTECTED]>,
 Brendan Miller <[EMAIL PROTECTED]> wrote:

> What would heavy python unit testers say is the best framework?
> 
> I've seen a few mentions that maybe the built in unittest framework
> isn't that great. I've heard a couple of good things about py.test and
> nose. Are there other options? Is there any kind of concensus about
> the best, or at least how they stack up to each other?
> 
> Brendan

I've been using unittest for years.  I'm happy with it.  I've looked at a 
couple of the other ones (I don't remember exactly which ones) and came to 
the conclusion that they didn't seem to provide enough advantage over 
unittest to make it worth switching.

Just my opinion.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question about Python lists

2008-11-11 Thread Steven D'Aprano
On Wed, 12 Nov 2008 10:08:45 +1100, Ben Finney wrote:

> Eric <[EMAIL PROTECTED]> writes:
> 
>> I'm learning Python (while coming from MATLAB). One question I have is
>> that if I have a list with say 8 elements, and I want just a few of
>> them how do I select them out. In MATLAB, if I just want the first,
>> fifth and eighth element I might do something like this:
>> 
>> b = a([1 5 8]);
>> 
>> I can't seem to figure out a similar Python construct for selecting
>> specific indices. Any suggestions?
> 
> Yes: the above code uses magic numbers which convey no semantic meaning,
> and should instead use *named* elemets of a container. In Python, that's
> done with a mapping type, which has the built-in type of ‘dict’.
> 
> In other words: a list is best for sequences where any item is
> semantically identical to any other, and you can (for example) re-order
> all the elements in the list without changing their semantic meaning.
> If, instead, you want semantic meaning, that's best done via *names*,
> not magic numbers.


While I see your point, and in practice there are circumstance where I 
would agree with you, I don't agree in general.

What the OP is asking for is a generalization of slicing. Slices already 
take a stride:


>>> alist = range(20)
>>> alist[2:17:3]
[2, 5, 8, 11, 14]

Given a slice alist[start:end:stride] the indices are given by the 
sequence start+i*stride, bounded by end. It seems to me that the OP has 
asked how to take a slice where the indices are from an arbitrary set, 
possibly given by an equation, but not necessarily. No practical examples 
come to mind just off the top of my head, but given that the OP is coming 
from a Matlab background, I bet they involve some pretty hairy maths.

Hmmm... let's see now...

http://en.wikipedia.org/wiki/Series_(mathematics)
#Summations_over_arbitrary_index_sets

To put it another way... suppose you have a sequence S given by a list, 
and a set of indexes I (perhaps given by a tuple or a set), and you want 
to sum the terms of S at those indexes, which mathematicians apparently 
have good reason for doing, then you might write in Python:

sum(S[i] for i in I)

But if there was slicing support for arbitrary indexes, you could write:

sum(S[I])

which is apparently what Matlab allows. Standard lists don't support this 
slicing generalization, but numpy arrays do.



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


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Ben Finney
Phillip B Oldham <[EMAIL PROTECTED]> writes:

> Even with using OpenID in this way, it still doesn't resolve the
> issue we have: quick user registration & sign-on. The user will need
> to register an OpenID account then register with each service/webapp
> we provide.

Why? You presumably have *existing* accounts for all these people; or
at least, some other database of people for whom you want
authentication credentials. why not cause the OpenID provider (the one
that you manage under your control, that is) to provide OpenIDs for
these existing accounts, and only those?

OpenID is a means of *authentication*, it doesn't mandate any
particular system of registration or account creation. You presumably
already have solutions for those; use them, but de-couple the
authentication process from those systems by using OpenID.

> What we're looking for is the reverse: registering our
> webapps/services with a SSO service

If you write the web application to accept OpenIDs only if they match
a specific pattern, you achieve the same effect; and you then have the
option to later choose to allow some other OpenIDs without needing to
change the authentication protocol.

> then (upon starting with the company) registering our new staff
> members with this service and specifying which webapps they have
> access to and what privileges they have with those apps.

That's quite a different thing from “single sign-on”. I recommend
you use OpenID for the purpose of authentication (proving that the
person's claim of identity is authentic), and implement whatever
system of *authorisation* (determining what the authenticated person
is authorised to do) is appropriate for each application.

You can use the associated OAuth standard protocol to transfer
information from a central provider about what authorisation
information is recorded for a person; I'm given to understand this
integrates well with OpenID.

> Please understand I have nothing against OpenID; I use it all the
> time and think its a great solution. I just don't think its a great
> solution for our particular problem.

OpenID is a solution for transporting authentication data, and
managing the data in a central location under your control. It does
well at that, because the protocol is mature (solving the transport
problem) and there are many supported free-software implementations
for providers and relying parties (allowing you to solve your specific
centralisation needs).

You later revealed that you *also* want a solution for transporting
authorisation data, and managing it in a central manner. This is a
separate issue, but OAuth is a similar solution: it is a standard
transport protocol, with many free-software implementations for both
ends of the conversation.

> Keep in mind that OpenID is user- centric.

If you mean “the user has to do the set-up work”, that's entirely
wrong. There exist *services* which *allow* people to set up a new
OpenID, but that's entirely optional. Millions of users on, e.g.
Flickr, AOL, and Yahoo, have now got OpenIDs provided without having
to do anything additional at all.

Your IT support team should be the ones setting up people's account
information, and the systems should be automatically providing OpenIDs
and OAuth profiles for any or all accounts as specified.

The user only needs to be told how to log in, once all this is set up;
and that's necessary no matter what authentication system you use.

> While I don't mind registering my openid account with the various
> sites I use, our staff members will have a nightmare spending their
> first day initially trying to understand OpenID, then registering
> with each of our services, then waiting while the support team
> review their registrations and give them relevant permissions.

Right, so you should be providing these OpenIDs and OAuth profiles as
part of whatever other data collection and account set-up needs to be
done.

-- 
 \   “If you make people think they're thinking, they'll love you; |
  `\ but if you really make them think, they'll hate you.” —Donald |
_o__) Robert Perry Marquis |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to make arrays from Lists

2008-11-11 Thread gc_ottawa
On Nov 11, 7:48 pm, [EMAIL PROTECTED] wrote:
> gc_ott:
>
> > How do I change the value of any element to produce (say)
> > [[99,0,0],[0,0,0],[0,0,0]] ?
>
> > gordc
>
> To create a 2D list, that is a list of lists:
> x = [[0] * ncols for i in nrows]
> (Don't do what you were doing, because you end with many references to
> the same list, and that will give you troubles.)
>
> To set an item you do just:
> x[0][0] = 99
>
> Bye,
> bearophile

Many thanks, I don't think I would ever 'discovered' this.
gordc
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sqlite3 cursor and imbricated for loop

2008-11-11 Thread Michiel Overtoom

Charles V. wrote:

It seems the second call to execute modify the first cursor. Is it normal ? 
How am I suppose to write this ?


Maybe introduce a second cursor?

import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
d = conn.cursor() # second cursor
c.execute('''create table stocks
(date text, trans text, symbol text,
 qty real, price real)''')
c.execute("insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)")
c.execute("insert into stocks values ('2006-01-06','BUY','RHAT',100,20.0)")
c.execute("insert into stocks values ('2006-01-07','BUY','RHAT',100,15.0)")
c.execute("insert into stocks values ('2006-01-08','BUY','RHAT',100,10.0)")
conn.commit()
c.execute("select * from stocks")
for s in c:
   print s[0]
   d.execute("select * from stocks where price<20") # use the second cursor
   for s in d:
  print '  '+s[0]
c.close()


Outputs:

2006-01-05
  2006-01-07
  2006-01-08
2006-01-06
  2006-01-07
  2006-01-08
2006-01-07
  2006-01-07
  2006-01-08
2006-01-08
  2006-01-07
  2006-01-08


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to make arrays from Lists

2008-11-11 Thread bearophileHUGS
gc_ott:
> How do I change the value of any element to produce (say)
> [[99,0,0],[0,0,0],[0,0,0]] ?
>
> gordc

To create a 2D list, that is a list of lists:
x = [[0] * ncols for i in nrows]
(Don't do what you were doing, because you end with many references to
the same list, and that will give you troubles.)

To set an item you do just:
x[0][0] = 99

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


Re: python bug when subclassing list?

2008-11-11 Thread Ethan Furman

Hamish McKenzie wrote:
I want to write a Vector class and it makes the most sense to just 
subclass list.  I also want to be able to instantiate a vector using either:


Vector( 1, 2, 3 )
OR
Vector( [1, 2, 3] )

so I have this:

class Vector(list):
  def __new__( cls, *a ):
try:
  print a
  return list.__new__(cls, a)
except:
  print 'broken'
  return list.__new__(cls, list(a))

doing Vector( 1, 2, 3 ) on this class results in a TypeError – which 
doesn’t seem to get caught by the try block (ie “broken” never gets 
printed, and it never tries to


I can do pretty much the exact same code but inheriting from tuple 
instead of list and it works fine.


is this a python bug?  or am I doing something wrong?

thanks,
-h.


Greetings!

I am not sure of the proper way to fix this issue, but the problem you 
have is that lists do not have a __new__ method:


--> list


--> list.__new__


--> list.__init__


Changing the __new__ to __init__ at least gets your code to run, but 
then you have this:


--> vector.Vector(1, 2, 3)
(1, 2, 3)
broken
Traceback (most recent call last):
  File "", line 1, in 
  File "vector.py", line 15, in __init__
return list.__new__(cls, list(a))
TypeError: list.__new__(X): X is not a type object (Vector)

Good luck in your journey!
~ethan~
--
http://mail.python.org/mailman/listinfo/python-list


baa ob baa

2008-11-11 Thread megiacomonadeau
http://fromhollywood.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to make arrays from Lists

2008-11-11 Thread Benjamin Kaplan
On Tue, Nov 11, 2008 at 7:32 PM, <[EMAIL PROTECTED]> wrote:

> I want to construct a 2-dimensional array from a List but I cannot
> find a simple way of changing any element. For example, construct a
> 3x3 array like this:-
> >>> x=[0,0,0]
>   x=[x]*3
> this produces [[0,0,0],[0,0,0],[0,0,0]. So far so good.
> How do I change the value of any element to produce (say)
> [[99,0,0],[0,0,0],[0,0,0]] ?
>

First of all, this is not a "2-d array". It is a list of lists. Each element
in x is a list consisting of three elements.
so x[0] is a list (x[0])[0] is the first element of that list. So what you
want is
>>>x[0][0] = 99

***In this case, each list inside of x refers to the same object. Any
changes you make to one row will appear in all of them.
>>> a = x[0]
>>> a
[0, 0, 0]
>>> a[0] = 99
>>> a
[99, 0, 0]
>>> x
[[99, 0, 0], [99, 0, 0], [99, 0, 0]]


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


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Phillip B Oldham
On Nov 11, 11:48 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Phillip B Oldham <[EMAIL PROTECTED]> writes:
>
> > I think maybe there's some misunderstanding. The protocol isn't the
> > issue; I'm happy to use whatever (HTTP, LDAP, SOAP, XMPP, etc). The
> > issue is that OpenID, by its name, is open. We don't want to allow
> > anyone with an openid account to register with our webapps
>
> Then don't do that. The OpenID protocol says nothing whatsoever about
> *which* OpenIDs your service will accept.
>
> > we simply want to centralise registration and sign-on for our
> > employees.
>
> Then you should reject any attempt to authenticate with an OpenID that
> you don't accept.

Even with using OpenID in this way, it still doesn't resolve the issue
we have: quick user registration & sign-on. The user will need to
register an OpenID account then register with each service/webapp we
provide. What we're looking for is the reverse: registering our
webapps/services with a SSO service then (upon starting with the
company) registering our new staff members with this service and
specifying which webapps they have access to and what privileges they
have with those apps.

Please understand I have nothing against OpenID; I use it all the time
and think its a great solution. I just don't think its a great
solution for our particular problem. Keep in mind that OpenID is user-
centric. While I don't mind registering my openid account with the
various sites I use, our staff members will have a nightmare spending
their first day initially trying to understand OpenID, then
registering with each of our services, then waiting while the support
team review their registrations and give them relevant permissions.

Since the support team will have to do this, along-side setting up
email accounts, it makes sense for them to have one interface to grant
access & permissions to the various webapps and for our staff to have
one place to sign-on. Since each staff-member already has a unique
email address it again makes sense to use this rather than an openid-
url which could be confusing.
--
http://mail.python.org/mailman/listinfo/python-list


How to make arrays from Lists

2008-11-11 Thread gc_ottawa
I want to construct a 2-dimensional array from a List but I cannot
find a simple way of changing any element. For example, construct a
3x3 array like this:-
>>> x=[0,0,0]
   x=[x]*3
this produces [[0,0,0],[0,0,0],[0,0,0]. So far so good.
How do I change the value of any element to produce (say)
[[99,0,0],[0,0,0],[0,0,0]] ?

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


Re: best python unit testing framwork

2008-11-11 Thread J Kenneth King
Brendan Miller <[EMAIL PROTECTED]> writes:

> What would heavy python unit testers say is the best framework?
>
> I've seen a few mentions that maybe the built in unittest framework
> isn't that great. I've heard a couple of good things about py.test and
> nose. Are there other options? Is there any kind of concensus about
> the best, or at least how they stack up to each other?
>
> Brendan

I find nose to be the best. It's simple, easy, and doesn't sacrifice
power. All good things if you value your time. :)
--
http://mail.python.org/mailman/listinfo/python-list


Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-11 Thread greg

Here is the definition of call-by-value from the
"Revised Report on the Algorithmic Language Algol 60"
:

4.7.3.1. Value assignment (call by value). All formal parameters quoted in the 
value part of the procedure declaration heading are assigned the values (cf. 
section 2.8. Values and types) of the corresponding actual parameters, these 
assignments being considers as being performed explicitly before entering the 
procedure body. The effect is as though an additional block embracing the 
procedure body were created in which these assignments were made to variables 
local to this fictitious block with types as given in the corresponding 
specifications (cf. section 5.4.5).


There you have it -- call by value is offially defined in
terms of assignment. There is no mention in there of copying.

So it's perfectly correct to use it in relation to Python.

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


Re: Where to locate existing standard encodings in python

2008-11-11 Thread Tim Chase

  Content-Type: text/html; charset=utf-8lias

For Python to parse this, I had to use Python's list of known encodings 
in order to determine whether I could even parse the site (for passing 
it to a string's .encode() method). 


You haven't said why you think you need a list of known encodings!

I would have thought that just trying it on some dummy data will let you 
determine very quickly whether the alleged encoding is supported by the 
Python version etc that you are using.


E.g.

| >>> alleged_encoding = "utf-8lias"
| >>> "any old ascii".decode(alleged_encoding)
| Traceback (most recent call last):
|  File "", line 1, in 
| LookupError: unknown encoding: utf-8lias


I then try to remap the bogus encoding to one it seems most like 
(in this case, utf-8) and retry.  Having a list of encodings 
allows me to either eyeball or define a heuristic to say "this is 
the closest match...try this one instead".  That mapping can then 
be used to update a mapping file so I don't have to think about 
it the next time I encounter the same bogus encoding.


-tkc



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


Re: Where to locate existing standard encodings in python

2008-11-11 Thread Grzegorz Staniak
On 11.11.2008, Tim Chase <[EMAIL PROTECTED]> wroted:

> (Aside: stupid dilbert.com site developers...what sorta rubbish is 
> "utf-8lias"?!  It's not like it's something that would appear 
> accidentally.  

It very much looks like an accident during httpd.conf editing, 
e.g. pasting part of an "Alias" at the end of the line for 
"AddDefaultCharset" or sth like this.

GS
-- 
Grzegorz Staniak 
Nocturnal Infiltration and Accurate Killing
--
http://mail.python.org/mailman/listinfo/python-list


Re: Null object pattern

2008-11-11 Thread Terry Reedy

Ben Finney wrote:

Terry Reedy <[EMAIL PROTECTED]> writes:


We're not going to add the "feature" back that None compares smaller
than everything. It's a slippery slope that ends with all operations
involving None returning None -- I've seen a proposal made in all
earnestness requesting that None+42 == None, None() == None, and so
on. This Nonesense was wisely rejected


I agree with that decision. However, the behaviour you specify *is*


For the record, I was quoting Guido there.

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


Re: best python unit testing framwork

2008-11-11 Thread Ben Finney
Brendan Miller <[EMAIL PROTECTED]> writes:

> What would heavy python unit testers say is the best framework?
> 
> I've seen a few mentions that maybe the built in unittest framework
> isn't that great.

That's right, there are many flaws in ‘unittest’. It nevertheless has
the overwhelming advantage of being present in any standard Python
installation.

Using ‘nose’ at least builds upon the standard library ‘unittest’
module, so can easily integrate existing unit tests. It can also be
used as a unit test discovery and runner framework, which doesn't
impact the usefulness of the tests themselves on machines that don't
have ‘nose’ installed.

-- 
 \“Holy contributing to the delinquency of minors, Batman!” —Robin |
  `\   |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Problem with sqlite3 cursor and imbricated for loop

2008-11-11 Thread Charles V.
Hi,

I hope this is not already known. But Google wasn't any help. So here begins a 
script to explain my problem.

-
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute('''create table stocks
(date text, trans text, symbol text,
 qty real, price real)''')
c.execute("insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)")
c.execute("insert into stocks values ('2006-01-06','BUY','RHAT',100,20.0)")
c.execute("insert into stocks values ('2006-01-07','BUY','RHAT',100,15.0)")
c.execute("insert into stocks values ('2006-01-08','BUY','RHAT',100,10.0)")
conn.commit()
c.execute("select * from stocks")
for s in c:
   print s[0]
   c.execute("select * from stocks where price<20")
   for s in c:
  print '  '+s[0]
c.close()
-

It is a adapted copy of the example in the Python documentation. But I was 
expecting the output as with MySQL engine but, here, I get only:
2006-01-05
  2006-01-07
  2006-01-08

It seems the second call to execute modify the first cursor. Is it normal ? 
How am I suppose to write this ?

Thanks

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


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Ben Finney
Phillip B Oldham <[EMAIL PROTECTED]> writes:

> I think maybe there's some misunderstanding. The protocol isn't the
> issue; I'm happy to use whatever (HTTP, LDAP, SOAP, XMPP, etc). The
> issue is that OpenID, by its name, is open. We don't want to allow
> anyone with an openid account to register with our webapps

Then don't do that. The OpenID protocol says nothing whatsoever about
*which* OpenIDs your service will accept.

> we simply want to centralise registration and sign-on for our
> employees.

Then you should reject any attempt to authenticate with an OpenID that
you don't accept.

This could be done by, as one possible example, only accepting OpenIDs
of the form ‘http://example.com/openid/username’ (or whatever URL path
you deem useful), and ensuring that you control the OpenID provider
that serves those OpenIDs.

-- 
 \  “He who allows oppression, shares the crime.” —Erasmus Darwin, |
  `\ grandfather of Charles Darwin |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Jeremiah Dodds
On Tue, Nov 11, 2008 at 6:29 PM, Phillip B Oldham
<[EMAIL PROTECTED]>wrote:

>
> anyone with an openid account to register with our webapps, we simply
> want to centralise registration and sign-on for our employees.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Are your webapps written in python or something else? If they're written in
python, it doesn't seem like it would be very hard to set up automation of
registration / sign on for all the apps from one spot. As far as I can tell,
it would be trivial to do with (for instance) CherryPy.

If they're not, then why the requirement of a python SSO server?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-11-11 Thread greg

Steven D'Aprano wrote:

If you equate "arguments within the called procedure" to the *name* of 
the arguments, then changing the arguments would mean changing the NAME


If "changing the name" means "rebinding the name",
then I agree -- that's exactly the point I was trying to
make.

If you equate "value" with "object", as you suggested some posts ago, 


*I* didn't suggest that, someone else did. I was just
pointing out that you can use the word that way if you
want, as long as you're consistent about it. And being
consistent means using it in the same way when talking
about assignment and about by-value parameter passing.
If you insist that one of these implies copying the
"value" but the other doesn't, then you're being
inconsistent.

At least some sections of the Java community seem to prefer a misleading 
and confusing use of the word "value" over clarity and simplicity, but I 
for one do not agree with them.


I don't see anything inherently confusing or misleading
about it. Confusion only arises when some people jump up
and say that it's wrong to use the terms that way, because
it might cause confusion...

In the general case, you can't emulate call-by-reference by passing a 
name, because you don't know what the name of an object is.


That's true, you need to communicate the namespace as
well, either implicitly or explicitly. So a
(namespace, name) pair, or a (sequence, index) pair
in the case of a sequence item, would be the equivalent
of a "reference" in the sense meant by "call by reference".

--
Greg

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


Re: Where to locate existing standard encodings in python

2008-11-11 Thread John Machin

On 12/11/2008 10:07, Tim Chase wrote:

You haven't explained why you think that you *need* a list of all
encodings that exist at a point in time. What are you going to do with
the list?


Just because I ran into this recently, the Dilbert.com site returns a 
bogus Content-type header with


  Content-Type: text/html; charset=utf-8lias

For Python to parse this, I had to use Python's list of known encodings 
in order to determine whether I could even parse the site (for passing 
it to a string's .encode() method). 


You haven't said why you think you need a list of known encodings!

I would have thought that just trying it on some dummy data will let you 
determine very quickly whether the alleged encoding is supported by the 
Python version etc that you are using.


E.g.

| >>> alleged_encoding = "utf-8lias"
| >>> "any old ascii".decode(alleged_encoding)
| Traceback (most recent call last):
|  File "", line 1, in 
| LookupError: unknown encoding: utf-8lias
| >>>



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


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Phillip B Oldham
On Nov 11, 11:00 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Phillip B Oldham <[EMAIL PROTECTED]> writes:
>
> > I've searched around but can only seem to find OpenID servers, which
> > will probably be too "open" for our needs.
>
> Please, if you're going to be coding new systems, use established,
> standard, open protocols with actively maintained implementations. For
> single sign-on. OpenID is the one to choose.

I think maybe there's some misunderstanding. The protocol isn't the
issue; I'm happy to use whatever (HTTP, LDAP, SOAP, XMPP, etc). The
issue is that OpenID, by its name, is open. We don't want to allow
anyone with an openid account to register with our webapps, we simply
want to centralise registration and sign-on for our employees.
--
http://mail.python.org/mailman/listinfo/python-list


Null object pattern (was: Python 3.0 - is this true?)

2008-11-11 Thread Ben Finney
Terry Reedy <[EMAIL PROTECTED]> writes:

> We're not going to add the "feature" back that None compares smaller
> than everything. It's a slippery slope that ends with all operations
> involving None returning None -- I've seen a proposal made in all
> earnestness requesting that None+42 == None, None() == None, and so
> on. This Nonesense was wisely rejected

I agree with that decision. However, the behaviour you specify *is*
useful (though I don't think ‘None’ should have that behaviour). It is
the “Null object” design pattern, and may be familiar to many
readers in its SQL implementation as the ‘NULL’ non-value.

In fact, there is a Python Cookbook recipe implementing a ‘Null’
object http://code.activestate.com/recipes/68205/> that also
features in the O'Reilly _Python Cookbook, second edition_.

-- 
 \ “This world in arms is not spending money alone. It is spending |
  `\  the sweat of its laborers, the genius of its scientists, the |
_o__)   hopes of its children.” —Dwight Eisenhower, 1953-04-16 |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question about Python lists

2008-11-11 Thread Ben Finney
Eric <[EMAIL PROTECTED]> writes:

> I'm learning Python (while coming from MATLAB). One question I have is
> that if I have a list with say 8 elements, and I want just a few of
> them how do I select them out. In MATLAB, if I just want the first,
> fifth and eighth element I might do something like this:
> 
> b = a([1 5 8]);
> 
> I can't seem to figure out a similar Python construct for selecting
> specific indices. Any suggestions?

Yes: the above code uses magic numbers which convey no semantic
meaning, and should instead use *named* elemets of a container. In
Python, that's done with a mapping type, which has the built-in type
of ‘dict’.

In other words: a list is best for sequences where any item is
semantically identical to any other, and you can (for example)
re-order all the elements in the list without changing their semantic
meaning. If, instead, you want semantic meaning, that's best done via
*names*, not magic numbers.

In your example, presumably the numbered elements above are being
selected because they, as distinct from the second, fourth, seventh,
et cetera, have specific semantic meaning. That's better represented
in Python by using a mapping type such as ‘dict’, that maps a
semantically-meaningful name (or, sometimes, some other identifying
object) to each value.

If you explain what it is you want to do (your example above gives no
clue), we can perhaps give more specific advice.

-- 
 \“I saw a sign: ‘Rest Area 25 Miles’. That's pretty big. Some |
  `\  people must be really tired.” —Steven Wright |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: SHA1withRSA in python

2008-11-11 Thread Jeremiah Dodds
On Tue, Nov 11, 2008 at 12:40 PM, Mailing List SVR
<[EMAIL PROTECTED]>wrote:

> Hi all,
>
> in java there are several libraries for sha1withrsa, there is something
> similar in python?
>
> thanks
> Nicola
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


http://docs.python.org/library/crypto.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Where to locate existing standard encodings in python

2008-11-11 Thread Tim Chase

You haven't explained why you think that you *need* a list of all
encodings that exist at a point in time. What are you going to do with
the list?


Just because I ran into this recently, the Dilbert.com site 
returns a bogus Content-type header with


  Content-Type: text/html; charset=utf-8lias

For Python to parse this, I had to use Python's list of known 
encodings in order to determine whether I could even parse the 
site (for passing it to a string's .encode() method).  (Aside: 
stupid dilbert.com site developers...what sorta rubbish is 
"utf-8lias"?!  It's not like it's something that would appear 
accidentally.  And there were bogus characters in the document to 
boot)


-tkc




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


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Ben Finney
Phillip B Oldham <[EMAIL PROTECTED]> writes:

> I've searched around but can only seem to find OpenID servers, which
> will probably be too "open" for our needs.

Huh? I'm sure you use HTTP for transferring requests and responses,
too, and that protocol is at least as as open. What does the openness
of the protocol have to do with who can access it?

Please, if you're going to be coding new systems, use established,
standard, open protocols with actively maintained implementations. For
single sign-on. OpenID is the one to choose.

-- 
 \  “I stayed up all night playing poker with tarot cards. I got a |
  `\  full house and four people died.” —Steven Wright |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


best python unit testing framwork

2008-11-11 Thread Brendan Miller
What would heavy python unit testers say is the best framework?

I've seen a few mentions that maybe the built in unittest framework
isn't that great. I've heard a couple of good things about py.test and
nose. Are there other options? Is there any kind of concensus about
the best, or at least how they stack up to each other?

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


Re: Python 2.5 and sqlite

2008-11-11 Thread david . lyon

> Can you ask them if sqlite3 is installed? and if not... to install it?

Why would he have to install SQLite?!


Seems a stupid question. If he wants to use SQLite... it needs to be  
on the system


ould include in your discussions "well sqlite3 is part of python"

> "if it isn't, you haven't installed python properly"

Sqlite3 is an optional part of Python.


But Python itself is dependent upon SQlite3 being installed first...

try it yourself...

first compile python 2.5 from source without SQLite.. see if it  
works... it won't.


Install Sqlite first... then compile python 2.5 from source.. python  
sqlite support will work...


The dependency is within the make files of python 2.5. It checks  
whether sqlite is installed on the machine and includes support if it  
is there.. if not.. doesn't support it...


It is very logical




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


Re: Where to locate existing standard encodings in python

2008-11-11 Thread rurpy
On Nov 11, 11:19 am, Philip Semanchuk <[EMAIL PROTECTED]> wrote:
> On Nov 11, 2008, at 1:08 PM, News123 wrote:
>
> > Hi Philip,
>
> > Thanks for your answer:
> > The fact, that a module 'encodings' exists was new to me.
>
> We both learned something new today. =)
>
> > encodings.aliases.aliases has however one problem.
> > It helps to locate all encoding aliases, but it won't find entries for
> > which no aliases exist:
>
> Ooops, I hadn't thought about that.
>
> > What gives me a list of quite some encodings on my host is the shell
> > command
> > ls /usr/lib/python2.5/encodings  | sed -n 's/\.py$//p' | sort
> > (soma false hits, bit this is fine for me purposes)
>
> > I don't know if really all encodings are represented with a .py file
> > and
> > if all encodigns have to be in this directory, but it's a start.
>
> > Using shell commands is not that pythonic:
>
> > I could try to rewrite this in python by
> > 1.) determine from which directory encodings was imported and
> > then using the glob module to list all .py files located there.
>
> Yes, I'd thought about this but I agree with you that it seems
> unpythonic and fragile. Unfortunately I can't think of anything better
> at this point.
>
> Good luck
> Philip
...snip...

If it's of any help, in a post on 2007-07-22 by Peter Otten,
(though I can't get a url for it at the moment) he took the
same approach.  From a saved copy of that post:

import encodings
import os
import glob

def encodings_from_modulenames():
ef = os.path.dirname(encodings.__file__)
for fn in glob.glob(os.path.join(ef, "*.py")):
fn = os.path.basename(fn)
yield os.path.splitext(fn)[0]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Where to locate existing standard encodings in python

2008-11-11 Thread John Machin
On Nov 10, 11:00 am, News123 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I was googling quite some time before finding the answer to my question:
> 'what are the names for the encodings supported by python?'
>
> I found the answer athttp://python.active-venture.com/lib/node127.html
>
> Now my question:
>
> Can I find the same info in the standard python doc or query python with
> a certain command to print out all existing codings?
>
> thanks in advance for your answer and bye
>
> N

You haven't explained why you think that you *need* a list of all
encodings that exist at a point in time. What are you going to do with
the list? Surely not use it to validate user input, one would hope.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sorting list of complex numbers

2008-11-11 Thread Thomas Bellman
Steve Holden <[EMAIL PROTECTED]> wrote:

> Only half the number, of course. The advantage of the key function is
> that each element requires only one call out to a Python function, and
> the comparisons then take place using a C-coded comparison function.

You don't need any Python-coded function at all.  The operator
module is your friend: key=operator.attrgetter('real', 'imag')
will create the required tuples for sorting.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"God is real, but Jesus is an integer."  !  bellman @ lysator.liu.se
 !  Make Love -- Nicht Wahr!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in PIL 1.1.6

2008-11-11 Thread Markus Mayer
Markus Mayer schrieb:
> Okay, for the* tip, here we go:

*2nd tip that is.
I need some sleep.

--
PGP/GPG key 0x2EB39BF9
--
http://mail.python.org/mailman/listinfo/python-list


Re: sys.stdout, urllib and unicode... I don't understand.

2008-11-11 Thread Tino Wildenhain

Thierry wrote:

Hello fellow pythonists,

I'm a relatively new python developer, and I try to adjust my
understanding about "how things works" to python, but I have hit a
block, that I cannot understand.
I needed to output unicode datas back from a web service, and could
not get back unicode/multibyte text before applying an hack that I
don't understand (thank you google)

I have realized an wxPython simple application, that takes the input
of a user, send it to a web service, and get back translations in
several languages.
The service itself is fully UTF-8.

The "source" string is first encoded to "latin1" after a passage into
unicode.normalize(), as urllib.quote() cannot work on unicode

srcText=unicodedata.normalize('NFKD',srcText).encode('latin1','ignore')


urllib.quote() operates on byte streams. If your web service is UTF-8
it would make sense to use UTF-8 as input encoding not latin1,
wouldn't it? unicodeinput.encode("utf-8")


After that, an urllib request is sent with this encoded string to the
web service

con=urllib2.Request(self.url, headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux 
i686) Gecko/20071127 Firefox/2.0.0.11'}, 
origin_req_host='http://translate.google.com')



req=urllib2.urlopen(con)


First problem, how to determine the encoding of the return ?


It is sent as part of the headers. e.g. content-type: text/html; 
charset=utf-8



If I inspect a request from firefox, I see that the server return
header specify UTF-8
But if I use this code:

ret=U''
for line in req:
 ret=ret+string.replace(line.strip(),'\n',chr(10))

I end up with an UnicodeDecodeError. I tried various line.decode(),
line.normalize and such, but could not make this error disapear.
I, until now, avoided that problem as the service always seems to
return 1 line, but I am wondering.


web server answer is encoded byte stream too (usually utf-8 but you
can check the headers)  so

line.decoce("utf-8") should give you unicode to operate on (always
do string operations on canonized form)


Second problem, if I try an

print line

into the loop, I too get the same error. I though that unicode() would
force python to consider the given text as unicode, not to try to
convert it to unicode.


But it is what it does. Basically unicode() is a constructor for
unicode objects.


Here again, trying several normalize/decode combination did not helped
at all.


Its not too complicated, you just need to keep unicode and byte strings
separate and draw a clean line between the two. (the line is decode() 
and encode() )



Then, looking for help through google, I have found this post:
http://mail.python.org/pipermail/python-list/2007-October/462977.html
and I gave it a try. What I did, though, was not to override
sys.stdout, but to declare a new writer stream as a property of my
main class:

self.out=OutStreamEncoder(sys.stdout, 'utf-8')




This is fancy but not needed if you take care like above.

HTH
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in PIL 1.1.6

2008-11-11 Thread Markus Mayer
Steve Holden schrieb:
> [EMAIL PROTECTED] wrote:
> From
> 
>   http://www.pythonware.com/products/pil/
> 
> """
> You can join the Image SIG via python.org's subscription page, or by
> sending a mail to [EMAIL PROTECTED] Put subscribe in the
> message body to automatically subscribe to the list, or help to get
> additional information.
> """

Hum, I was hoping I could avoid that. :/ (The list, of course)

Markus

--
PGP/GPG key 0x2EB39BF9
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bug in PIL 1.1.6

2008-11-11 Thread Markus Mayer
[EMAIL PROTECTED] schrieb:
> Markus Mayer:
>> Any idea where I should send this (and/or more) information to?
> 
> You can send your note and and image to effbot.
> You can also put an image online somewhere and give here the link (a
> small image, to avoid saturating your server, etc) so people can test
> it.

Okay, for the tip, here we go:
http://www.defx.de/usenet/imgqtbug/index.html
I included a small test case that shows this behavior.

Regards,
Markus

--
PGP/GPG key 0x2EB39BF9
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strange output from list

2008-11-11 Thread Rob Williscroft
Steve Holden wrote in news:mailman.3804.1226412496.3487.python-
[EMAIL PROTECTED] in comp.lang.python:

>> Shouldn't it be GROUP BY master.id? I would have thought that SQL
>> would be sad about a non-aggregate (master.id) that's in the SELECT
>> list but not also in the GROUP BY list.
>> 
> Well, I did say "untested". But in SQL Server, for example, any field
> argument to COUNT() must be an aggregated column. So it may depend on
> the SQL implementation. I should really have said

You must mean an "SQL Server" other than the Microsofts one, as:

select count( aid ) as "count"
from table_1
group by aid

count
---
8
8
8
8
8
8
8
8

(8 row(s) affected)

and:

select count( aid ) as "count"
from table_1

count
---
64

(1 row(s) affected)

Like it should.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
--
http://mail.python.org/mailman/listinfo/python-list


Wing IDE 3.1.5 released

2008-11-11 Thread Wingware

Hi,

Wingware has released version 3.1.5 of Wing IDE, a bugfix release for all
three product levels of Wing IDE.

*Release Highlights*

This release includes the following:

* Avoid auto-starting batch searches when a new project is opened
* Several vi mode fixes
* Added debug 'watch' item to editor context menu
* Recognize type of 'x' in 'from x import y'
* Allow debugger to start even if replacing sys.stdin fails
* Store list of test files in shared project file (*.wpr)
* About 16 other bug fixes: see the change log for details:
  http://wingware.com/pub/wingide/3.1.5/CHANGELOG.txt

*Downloads*

Wing IDE Professional and Wing IDE Personal are commercial software and
require a license to run. A free trial license can be obtained directly from
the product when launched.

Wing IDE Pro 3.1.5http://wingware.com/downloads/wingide/3.1

Wing IDE Personal 3.1.5   http://wingware.com/downloads/wingide-personal/3.1

Wing IDE 101 3.1.5http://wingware.com/downloads/wingide-101/3.1

*About Wing IDE*

Wing IDE is an integrated development environment for the Python programming
language.  It provides powerful debugging, editing, code intelligence,
testing, and search capabilities that reduce development and debugging
time, cut down on coding errors, and make it easier to understand
and navigate Python code.

Wing IDE is available in three product levels:  Wing IDE Professional is
the full-featured Python IDE, Wing IDE Personal offers a reduced feature
set at a low price, and Wing IDE 101 is a free simplified version designed
for teaching entry level programming courses with Python.

System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or
Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit).
Wing IDE 3.1 supports Python versions 2.0.x through 2.5.x.

*New Features in Wing 3.1*

This release adds the following features not found in Wing 3.0.x:

* Support for zip archives
* Support for pkg_resources name spaces and eggs
* Support for doctest and nose style unit tests (*)
* Scan for sys.path changes such as those used in buildout
* How-To and support for Google App Engine
* Inline context appropriate templates/snippets integrated with autocompleter 
(*)
* Word list driven auto-completion in non-Python files (**)
* Quick navigation to files and symbols by typing a fragment (**)
* Improved support for Stackless Python
* Preference to strip trailing white space on save
* Display gi_running and gi_frame for generators
* Improved code analysis for Python 2.5
* Other minor features and bug fixes not found in Wing 3.0.x

(*)'d items are available in Wing IDE Professional only.
(**)'d items are available in Wing IDE Personal or Professional only.

Please see the change log for a detailed list of changes:
http://wingware.com/pub/wingide/3.1.5/CHANGELOG.txt

*Purchasing and Upgrading*

Wing 3.1 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Any 2.x license 
sold
after May 2nd 2006 is free to upgrade; others cost 1/2 the normal price to
upgrade.

Upgrade a 2.x license: https://wingware.com/store/upgrade

Purchase a 3.x license:https://wingware.com/store/purchase

--

The Wingware Team
Wingware | Python IDE
Advancing Software Development

www.wingware.com

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


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread Phillip B Oldham
On Nov 11, 9:24 pm, paul <[EMAIL PROTECTED]> wrote:
> Phillip B Oldham schrieb:> Are there any FOSS Python Single-Sign-on Servers?
>
> [snip]
>
> > I've searched around but can only seem to find OpenID servers, which
> > will probably be too "open" for our needs.
>
> So if it is not OpenID, which protocol are you going to implement?

In theory, we could use an OpenID server: our staff could register
with something like MyOpenID, register with each of our individual
webapps, and then gain access with a single sign-on. However, its not
really getting round the problem we have: we need to give our staff
access to all of our apps in one go, give them one place to sign on,
and have the ability to disable their account at short notice. Doing
this with openid would mean we have *no* access to the user account
and therefore would still have the overhead of having to disable
accounts with each webapp we provide. It also opens-up a security
threat in that anyone could register to our "internal" apps with an
OpenID account. Which is bad.

Essentially, we need a SSO server with which we would register our
*webapps* and then create user account, specifying which webapps that
user has access to, and at what level. Essentially something like
OpenSSO but python-based.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are there any FOSS Python Single-Sign-on Servers?

2008-11-11 Thread paul

Phillip B Oldham schrieb:

Are there any FOSS Python Single-Sign-on Servers?

[snip]


I've searched around but can only seem to find OpenID servers, which
will probably be too "open" for our needs. 

So if it is not OpenID, which protocol are you going to implement?

cheers
 Paul

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


Re: Python 3.0 - is this true?

2008-11-11 Thread Robin Becker

Terry Reedy wrote:

M.-A. Lemburg wrote:



I think the special case for None should be readded to Python 3.0.


Quick summary of thread that MAL started on Python-3000-dev list:

Once upon a time, 0 < None was true.

When rich comparisons were added, None < 0 (and *most* other things) 
become true as an intentionally undocumented implementation detail.


The None rule only applies for sure when None controls the comparison: 
ob < None is true or undefined if type(ob) says so.


Guido's pronouncement: "In short, I'll have None of it."
summarizing

We're not going to add the "feature" back that None compares smaller
than everything. It's a slippery slope that ends with all operations
involving None returning None -- I've seen a proposal made in all
earnestness requesting that None+42 == None, None() == None, and so
on. This Nonesense was wisely rejected; a whole slew of
early-error-catching would have gone out of the window. It's the same
with making None smaller than everything else. For numbers, you can
already use -inf; for other types, you'll have to invent your own
Smallest if you need it.

tjr


This still doesn't explain why None should not be comparable to itself.

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


Re: module cwiid and threading: how to use cwiid.Wiimote without blocking

2008-11-11 Thread News123
The only solution, that I found was recompiling the libcwiid wrapper,
such that it allows threading (the patch existed already on the libcwiid
Trac data base, though it's not part of an official release)


bye


N

News123 wrote:
> Hi,
> 
> I'm using the module cwiid to conncet to a wiimote.
> 
> import cwiid
> wiimote = cwiid.Wiimote()
> 
> This function is blocking:
> It waits until it could sucessfully connect to a device or
> until 20 seconds passed without sucessful connection.
> 
> As I wanted to do some things even if the wii-mote is not
> connected I though about creating  a thread, which tries connecting
> until it is sucessfully connected
> and let the application do something else meanwhile.
> 
> Unfortunately it seems, that the call to cwiid.Wiimote() blocks
> all threads.
> Probably the call to Wiimote() doesn't release the GIL.
> 
> 
> So my question:
> 
> Is there anybody knowing if there's any trick in python or
> in libcwiid  to avoid this 'complete block'
> 
> The only idea, that I have is to do the polling in a second process.
> I'm just not sure though how I could pass the sucessfully connected
> device to the parent process without creating pipes or
> 
> thanks for any ideas and bye
> 
> N
> 
> P.S. Attached a test script and its output:
> 
> #[code]
> import os,sys,time,threading,cwiid
> class wii_thread(threading.Thread):
> def run(self):
> wm = None
> while not wm:
> try:
> print "try to connect"
> wm=cwiid.Wiimote()
> except:
> print "Didn't find wiimote will retry"
> time.sleep(0.5)
> print "setup wiimote,poll and queue wii events"
> time.sleep(1000)
> if __name__ == '__main__':
> wii_thrd = wii_thread()
> wii_thrd.start()
> while True:
> print 'do something'
> time.sleep(1)
> #[code end]
> 
> # the output
> ##
> do something
> try to connect
> No wiimotes found
> Didn't find wiimote will retry
> do something
> try to connect
> setup wiimote,poll and queue wii events
> do something
> do something
> do something
> Traceback (most recent call last):
>   File "./threadprob.py", line 22, in 
> time.sleep(1)
> KeyboardInterrupt
> 
> 
--
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess communication, exec()

2008-11-11 Thread Chuckk Hubbard
On Tue, Nov 11, 2008 at 9:39 PM, Jeff McNeil <[EMAIL PROTECTED]> wrote:
> On Nov 11, 1:23 pm, "Chuckk Hubbard" <[EMAIL PROTECTED]>
> wrote:
>> If I run 'python -i subprocessclient.py' I expect to see the nice
>> level of it go up 2, and the nice level of the subprocess go up 1.
>> But all I see is the nice level of the client change.  What am I doing
>> wrong?
>>
>> subprocessserver.py:
>> 
>> #!/usr/bin/python2.5
>>
>> import os
>> import sys
>>
>> while True:
>> next_line = sys.stdin.readline()
>> if not next_line:
>> break
>> exec(next_line)
>> #sys.stdout.write(output)
>> #sys.stdout.write(next_line)
>> #sys.stdout.flush()
>> 
>>
>> subprocessclient.py:
>> 
>> #!/usr/bin/python2.5
>>
>> import subprocess, os
>>
>> server = subprocess.Popen(('python2.5', 'subprocessserver.py'),
>> shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
>> stderr=subprocess.PIPE)
>>
>> os.nice(2)
>>
>> server.stdin.write('''os.nice(1)''')
>> 
>>
>> Thanks.
>> -Chuckk
>>
>> --http://www.badmuthahubbard.com
>
> Looks like you're dropping an error by redirecting the child process'
> standard error into a pipe.
>
> First off, remove the stderr=subprocess.PIPE from
> subprocessclient.py.  When you do so, you'll start seeing an error
> message whenever your code runs:
>
> [EMAIL PROTECTED] ~]$ python client.py
> None
> [EMAIL PROTECTED] ~]$ Traceback (most recent call last):
>  File "", line 1, in 
> NameError: name 'os' is not defined
>
> That doesn't make a lot of sense at first, until you consider the
> following:
>
> [EMAIL PROTECTED] ~]$ echo 'os.nice(1)' | python
> Traceback (most recent call last):
>  File "", line 1, in 
> NameError: name 'os' is not defined
>
> The Python interpreter is trying to execute the data you write to the
> stdin of the child process.  Changing the Popen line to use the string
> form rather than the sequence form remedies the problem, as does
> changing 'string=True' to 'string=False.'
>
> The reason? Because when you set shell=True, additional arguments in
> args sequence are passed as additional arguments to the shell itself,
> not to the command.
>
> >From subprocess.py:
>
>if isinstance(args, types.StringTypes):
>args = [args]
>else:
>args = list(args)
>
>if shell:
>args = ["/bin/sh", "-c"] + args
>
> So, in your attempt, you're effectively doing the following:
>
> /bin/sh -c "python2.5" "server.py"
>
> When you want:
>
> /bin/sh -c "python2.5 server.py"
>
> HTH,
>
> Jeff

That helps immensely, Jeff, thank you for explaining all that.  I took
out 'shell=True' and it works, and I took out the stdout and stderr
arguments to debug. I am finally able to perform every step in my
plan: start a child process of python running a script that imports
the Csound API; raise the nice level of the parent process; compile
and run a Csound orchestra remotely; and send it notes from the parent
process.
Thanks for your help.
-Chuckk

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


Re: Simple question about Python lists

2008-11-11 Thread Robert Kern

Eric wrote:

On Nov 11, 1:51 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

On Tue, 11 Nov 2008 11:47:53 -0800, Eric wrote:

I'm learning Python (while coming from MATLAB). One question I have is
that if I have a list with say 8 elements, and I want just a few of them
how do I select them out. In MATLAB, if I just want the first, fifth and
eighth element I might do something like this:
b = a([1 5 8]);
I can't seem to figure out a similar Python construct for selecting
specific indices. Any suggestions?

b = [a[i] for i in [1, 5, 8]]

Ciao,
Marc 'BlackJack' Rintsch


Thanks! It makes sense, but in this case MATLAB seems easier and no
less readable. That said, I know better than for a newbie like me to
question syntax issues.


In my experience, I never do this with lists so there's no optimized syntax for 
it. I do use it very often with numpy arrays, and that does have optimized syntax.


--
Robert Kern

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

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


Re: concurrency program design stackless python tasklet or python thread?

2008-11-11 Thread Aahz
In article <[EMAIL PROTECTED]>,
davy zhang <[EMAIL PROTECTED]> wrote:
>
>first here is my basic idea is every actor holds their own msg queue,
>the process function will handle the message as soon as the dispatcher
>object put the message in.

Sounds like a standard design.

>This idea naturally leads me to place every actor in a separate thread
>waiting for msg
>
>but the rumor has it, stackless python with tasklet and channel can do
>much more better in concurrency program, so I dive my head into it.
>
>but I found the tasklet is really a lined-up sequence , that means if
>a tasklet blocked or do some time consuming calculation, the other
>tasklets can not get the cpu slice
>
>so we must design very carefully to avoid the big job for single task
>
>I am just confused why the stackless python is said to be good at
>concurrency program model or just I get a wrong idea to practice?

Well, you have to be a bit careful, but Stackless is definitely one good
approach to handling your design.  For example, EVE Online is an MMORPG
written in Python with a similar design.  That said, I personally have
trouble wrapping my brain around Stackless, so I'd probably choose a
different technique.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5 and sqlite

2008-11-11 Thread Thorsten Kampe
* "Martin v. Löwis" (Tue, 11 Nov 2008 21:40:44 +0100)
> > That's not what I meant: the question is, do you need SQLite /after/ 
> > you've built from source or if you install the Python binary.
> 
> Depends on how you built SQLite on your system. If it was a static
> library, you won't need it - if it is a shared library, you certainly
> need the shared library at run-time.

Aah, thanks. Makes sense a lot. There were quite a few people here in 
the last few days who asked how to build or use Python (or pysqlite) 
when SQLite is not installed (and they can't because it's not their 
system). I always said that it's not necessary to have SQLite installed 
for /running/ Python. Seems that I was "65%" right.

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


Re: Simple question about Python lists

2008-11-11 Thread Eric
On Nov 11, 1:51 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Tue, 11 Nov 2008 11:47:53 -0800, Eric wrote:
> > I'm learning Python (while coming from MATLAB). One question I have is
> > that if I have a list with say 8 elements, and I want just a few of them
> > how do I select them out. In MATLAB, if I just want the first, fifth and
> > eighth element I might do something like this:
>
> > b = a([1 5 8]);
>
> > I can't seem to figure out a similar Python construct for selecting
> > specific indices. Any suggestions?
>
> b = [a[i] for i in [1, 5, 8]]
>
> Ciao,
>         Marc 'BlackJack' Rintsch

Thanks! It makes sense, but in this case MATLAB seems easier and no
less readable. That said, I know better than for a newbie like me to
question syntax issues.

Regards,

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


Re: Simple question about Python lists

2008-11-11 Thread Robert Kern

Guilherme Polo wrote:

On Tue, Nov 11, 2008 at 5:47 PM, Eric <[EMAIL PROTECTED]> wrote:

I'm learning Python (while coming from MATLAB). One question I have is
that if I have a list with say 8 elements, and I want just a few of
them how do I select them out. In MATLAB, if I just want the first,
fifth and eighth element I might do something like this:

b = a([1 5 8]);

I can't seem to figure out a similar Python construct for selecting
specific indices. Any suggestions?


MATLAB works with 1-based index, while Python is 0-based, so accessing
the index number 8 wouldn't be valid with 8 elements here in Python.

Now, to solve your problem you could either use the already suggested
answer above mine or depending on what you what else you wanna do, you
will feel more comfortable using numpy.

Supposing you have a array with 8 elements: x = numpy.arange(8)
To pull out the first, fifth and eighth elements you would do:
x[numpy.array([0, 4, 7])]


Actually, x[[0,4,7]] will work just as well.

--
Robert Kern

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

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


Re: Python 2.5 and sqlite

2008-11-11 Thread Martin v. Löwis
> That's not what I meant: the question is, do you need SQLite /after/ 
> you've built from source or if you install the Python binary.

Depends on how you built SQLite on your system. If it was a static
library, you won't need it - if it is a shared library, you certainly
need the shared library at run-time.

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


Re: etymology of "list comprehension"?

2008-11-11 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>,
 Paul Rubin  wrote:

> [EMAIL PROTECTED] writes:
> > Ah, thanks... and does "comprehension" have any special computer
> > science meaning?
> 
> It is from mathematical set theory.  If you write something like
> 
>{ p | [some logical expression indicating that p is prime] }
> 
> then that denotes a set (the set of all prime numbers).  That every
> such formula names a set is called the axiom of comprehension.  The
> above notation is sometimes called set-builder notation.
> 
> Frege's original system of logic (late 19th century), now called
> "naive set theory" had "unrestricted comprehension" which meant
> you could say anything at all where the logical expression went.
> This made the system inconsistent, because of Russell's paradox
> ("c is the class of all classes that are not members of themselves.
> So is c a member of itself?").  
> 
> Axiomatic set theory has a restricted axiom of comprehension that
> requires the logical expression to be a first order formula with
> a certain syntax, to avoid such paradoxes.

Not that it matters, but the fix is not by using a first-order
formula with a certain syntax. The comprehension itself is
not 

   {p | p satisfies some condition}, 

it's

   {p in S | p satisfies some condition},

where S is some set. You're not allowed to ask for _everything_
satisfying a certain condition, just for the elements of
some given set satisfying the condition.

The paradox doesn't come from being allowed to say anything
at all. If you write

(*)  c = {x | ~(x e x)}

(where ~ means "not" and "a e b" means "a is an element of b")
you get Russell's paradox: if c is an element of c then it follows
that c is not an element of c, while if c is not an element of c
then it follows that c is an element of c. The problem is not
with the formula ~(x e x); given a set S, there's no problem
with the set {x in S | ~(x e x)}, for example. "restricted"
versus "unrestricted" does not refer to some restriction on
that formula - the "restriction" in restricted comprehension
is the "x in S" part - we're restricting things to elements
of a given set S.

Writing informally people often omit the "in S" part when the
S in clear from the context. For example, your original
{p | p is prime} should officially be {p in N | p is prime},
where N is the set of natural numbers - the first form is 
often written because the "in N" is implicit in "prime".

> Anyway, list comprehensions in programming languages got their
> name because of their resemblance to set-builder notation that
> invoked the axiom of comprehension.

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


Has anyone tried calling zip.py in feedback.py and print out an innerHTML to provide a download link?

2008-11-11 Thread David Shi
Hello, there.
 
Has anyone tried calling zip.py in feedback.py and print out an innerHTML to 
provide a download link?
 
I find difficult to make it work.
 
Sincerely,
 
David
 #**
# Description:
#Zips the contents of a folder.
# Parameters:
#   0 - Input folder.
#   1 - Output zip file. It is assumed that the user added the .zip 
#   extension.  
#**

# Import modules and create the geoprocessor
#
import sys, zipfile, arcgisscripting, os, traceback
gp = arcgisscripting.create()

# Function for zipping files.  If keep is true, the folder, along with 
#  all its contents, will be written to the zip file.  If false, only 
#  the contents of the input folder will be written to the zip file - 
#  the input folder name will not appear in the zip file.
#
def zipws(path, zip, keep):
path = os.path.normpath(path)
# os.walk visits every subdirectory, returning a 3-tuple
#  of directory name, subdirectories in it, and filenames
#  in it.
#
for (dirpath, dirnames, filenames) in os.walk(path):
# Iterate over every filename
#
for file in filenames:
# Ignore .lock files
#
if not file.endswith('.lock'):
gp.AddMessage("Adding %s..." % os.path.join(path, dirpath, 
file))
try:
if keep:
zip.write(os.path.join(dirpath, file),
os.path.join(os.path.basename(path), 
os.path.join(dirpath, file)[len(path)+len(os.sep):]))
else:
zip.write(os.path.join(dirpath, file),
os.path.join(dirpath[len(path):], file)) 

except Exception, e:
gp.AddWarning("Error adding %s: %s" % (file, e))

return None

if __name__ == '__main__':
try:
# Get the tool parameter values
#
infolder = gp.GetParameterAsText(0)
outfile = gp.GetParameterAsText(1)  

# Create the zip file for writing compressed data. In some rare
#  instances, the ZIP_DEFLATED constant may be unavailable and
#  the ZIP_STORED constant is used instead.  When ZIP_STORED is
#  used, the zip file does not contain compressed data, resulting
#  in large zip files. 
#
try:
zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED)
zipws(infolder, zip, True)
zip.close()
except RuntimeError:
# Delete zip file if exists
#
if os.path.exists(outfile):
os.unlink(outfile)
zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_STORED)
zipws(infolder, zip, True)
zip.close()
gp.AddWarning("Unable to compress zip file contents.")

gp.AddMessage("Zip file created successfully")

except:
# Return any python specific errors as well as any errors from the 
geoprocessor
#
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n 
   " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
gp.AddError(pymsg)

msgs = "GP ERRORS:\n" + gp.GetMessages(2) + "\n"
gp.AddError(msgs)



 


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


Re: Python 3.0 - is this true?

2008-11-11 Thread Martin v. Löwis
> The sorting is in a performance-critical part of the system, so the
> overhead of evaluating a key function is not insignificant.

Can you easily produce an example? It doesn't have to be real data,
but should have the structure (typewise) of the real data. I would
like to perform some measurements. For example, I could imagine that

l = []
for i in range(1000):
  x = random.randint(0,100)
  if x < 4: l.append(None)
  else: l.append(x)

might adequately model your problem.

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


Re: Python 2.5 and sqlite

2008-11-11 Thread Guilherme Polo
On Tue, Nov 11, 2008 at 6:04 PM, Thorsten Kampe
<[EMAIL PROTECTED]> wrote:
> * "Martin v. Löwis" (Tue, 11 Nov 2008 20:54:37 +0100)
>> > Sqlite3 is an optional part of Python. It has no dependencies on
>> > SQLite.
>>
>> That's not true. To build the _sqlite3 module, you need the SQLite3
>> sources or binaries, in addition to the Python sources.
>
> That's not what I meant: the question is, do you need SQLite /after/
> you've built from source or if you install the Python binary.
>

Is that some form of tricky question ? The binary package either comes
with the sqlite lib, or in the case of linux distributions, the
package requires the installation of sqlite lib. If you try removing
the sqlite lib package (in Linux), the package manager will tell you
that python depends on it.

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



-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


sys.stdout, urllib and unicode... I don't understand.

2008-11-11 Thread Thierry
Hello fellow pythonists,

I'm a relatively new python developer, and I try to adjust my
understanding about "how things works" to python, but I have hit a
block, that I cannot understand.
I needed to output unicode datas back from a web service, and could
not get back unicode/multibyte text before applying an hack that I
don't understand (thank you google)

I have realized an wxPython simple application, that takes the input
of a user, send it to a web service, and get back translations in
several languages.
The service itself is fully UTF-8.

The "source" string is first encoded to "latin1" after a passage into
unicode.normalize(), as urllib.quote() cannot work on unicode
>>srcText=unicodedata.normalize('NFKD',srcText).encode('latin1','ignore')

After that, an urllib request is sent with this encoded string to the
web service
>>con=urllib2.Request(self.url, headers={'User-Agent':'Mozilla/5.0 (X11; U; 
>>Linux i686) Gecko/20071127 Firefox/2.0.0.11'}, 
>>origin_req_host='http://translate.google.com')

>>req=urllib2.urlopen(con)

First problem, how to determine the encoding of the return ?
If I inspect a request from firefox, I see that the server return
header specify UTF-8
But if I use this code:
>>ret=U''
>>for line in req:
>>  ret=ret+string.replace(line.strip(),'\n',chr(10))
I end up with an UnicodeDecodeError. I tried various line.decode(),
line.normalize and such, but could not make this error disapear.
I, until now, avoided that problem as the service always seems to
return 1 line, but I am wondering.

Second problem, if I try an
>>print line
into the loop, I too get the same error. I though that unicode() would
force python to consider the given text as unicode, not to try to
convert it to unicode.
Here again, trying several normalize/decode combination did not helped
at all.

Then, looking for help through google, I have found this post:
http://mail.python.org/pipermail/python-list/2007-October/462977.html
and I gave it a try. What I did, though, was not to override
sys.stdout, but to declare a new writer stream as a property of my
main class:
>>self.out=OutStreamEncoder(sys.stdout, 'utf-8')

But what is strange, is that since I did that, even without using this
self.out writer, the unicode translation are working as I was
expecting them to. Except on the for loop, where a concatenation still
triggers the UnicodeDecodeErro exception.
I know the "explicit is better than implicit" python motto, and I
really like it.
But here, I don't understand what is going on.

Does the fact that defining that writer object does a initialization
of the standard sys.stdout object ?
Does it is related to an internal usage of it, maybe in urllib ?
I tried to find more on the subject, but felt short.
Can someone explain to me what is happening ?
The full script source can be found at 
http://www.webalis.com/translator/translator.pyw
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question about Python lists

2008-11-11 Thread Guilherme Polo
On Tue, Nov 11, 2008 at 5:47 PM, Eric <[EMAIL PROTECTED]> wrote:
> I'm learning Python (while coming from MATLAB). One question I have is
> that if I have a list with say 8 elements, and I want just a few of
> them how do I select them out. In MATLAB, if I just want the first,
> fifth and eighth element I might do something like this:
>
> b = a([1 5 8]);
>
> I can't seem to figure out a similar Python construct for selecting
> specific indices. Any suggestions?
>

MATLAB works with 1-based index, while Python is 0-based, so accessing
the index number 8 wouldn't be valid with 8 elements here in Python.

Now, to solve your problem you could either use the already suggested
answer above mine or depending on what you what else you wanna do, you
will feel more comfortable using numpy.

Supposing you have a array with 8 elements: x = numpy.arange(8)
To pull out the first, fifth and eighth elements you would do:
x[numpy.array([0, 4, 7])]

It is so no natural as it was in MATLAB, but well, it was a different language.

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



-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sync paramstyle between sqlite and mysql

2008-11-11 Thread Thorsten Kampe
* Jerry Hill (Tue, 11 Nov 2008 11:24:50 -0500)
> On Mon, Nov 10, 2008 at 1:00 PM, Daniel <[EMAIL PROTECTED]> wrote:
> > I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that
> > there are five paramstyles, though it wasn't clear if I should expect
> > these to be implemented in all DBAPI2 compliant modules.  I have found
> > that I can set the paramstyle, but it doesn't seem to apply:
> 
> As far as I understand it, paramstyle is informational, not a setting
> that you can change.  You have no choice but to use the paramstyle
> that the provider of the dbapi-compliant module has chosen to use.

Right.

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


Re: [ANN] sqlite 0.8.3

2008-11-11 Thread Thorsten Kampe
* sandro (Tue, 11 Nov 2008 11:42:00 GMT)
>   ANNOUNCE: sqlkit 0.8.3 
> 
> November, 10  2008
> 
> I'm happy to announce release 0.8.3 of sqlkit package for python - the
> first public release.

Are you aware that you announced "sqlite 0.8.3" in the subject??!!

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


Re: Python 2.5 and sqlite

2008-11-11 Thread Thorsten Kampe
* "Martin v. Löwis" (Tue, 11 Nov 2008 20:54:37 +0100)
> > Sqlite3 is an optional part of Python. It has no dependencies on
> > SQLite.
> 
> That's not true. To build the _sqlite3 module, you need the SQLite3
> sources or binaries, in addition to the Python sources.

That's not what I meant: the question is, do you need SQLite /after/ 
you've built from source or if you install the Python binary.

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


Parsing: request for pointers

2008-11-11 Thread André
Hi everyone,

I would like to implement a parser for a mini-language
and would appreciate some pointers.  The type of
text I would like to parse is an extension of:

http://www.websequencediagrams.com/examples.html

For those that don't want to go to the link, consider
the following, *very* simplified, example:
===

programmer Guido
programmer "Fredrik Lundh" as effbot
programmer "Alex Martelli" as martellibot
programmer "Tim Peters" as timbot
note left of effbot: cutting sense of humor
note over martellibot:
Offers detailed note, explaining a problem,
accompanied by culinary diversion
to the delight of the reader
note over timbot: programmer "clever" as fox
timbot -> Guido: I give you doctest
Guido --> timbot: Have you checked my time machine?

===
>From this, I would like to be able to extract
("programmer", "Guido")
("programmer as", "Fredrik Lundh", "effbot")
...
("note left of", "effbot", "cutting sense of humor")
("note over", "martellibot", "Offers...")
("note over", "timbot", 'programmer "clever" as fox')

Some observations:
1. I want to use indentation to identify blocks.
  (the site I referred to uses "end note" which I don't want)
2. "keywords"  (such as "programmer", "note over")
   can appear in text, and should not then be misidentified
3. I was thinking of using http://effbot.org/zone/simple-top-down-parsing.htm
   as a guide; however, it is not clear to me how it could be
   adapted to handle observations 1 and 2. (If it "easily" could,
   just a few pointers would be enough, and I'll start from there...)
4. I want to do this only using modules in the standard Python
   library, as I want to use this to learn about the basics
   of parsing.  So, please don't *simply* suggest to use a
   third-party module, such as
   [1] plex, [2] yapps, [3] pyparsing
   The learning journey is more important for me than just
   having a canned solution to my (current) parsing problem.

Cheers,

André

[1] http://www.cosc.canterbury.ac.nz/greg.ewing/python/Plex/
[2] http://theory.stanford.edu/~amitp/yapps/
[3] http://pyparsing.wikispaces.com/

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


Re: Printing a "status " line from a python script

2008-11-11 Thread Chris Seymour
Thanks guys for the ideas.

Appreciate the help.

Cheers.

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


Re: Python 2.5 and sqlite

2008-11-11 Thread Martin v. Löwis
> Sqlite3 is an optional part of Python. It has no dependencies on SQLite.

That's not true. To build the _sqlite3 module, you need the SQLite3
sources or binaries, in addition to the Python sources.

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


Re: Simple question about Python lists

2008-11-11 Thread Marc 'BlackJack' Rintsch
On Tue, 11 Nov 2008 11:47:53 -0800, Eric wrote:

> I'm learning Python (while coming from MATLAB). One question I have is
> that if I have a list with say 8 elements, and I want just a few of them
> how do I select them out. In MATLAB, if I just want the first, fifth and
> eighth element I might do something like this:
> 
> b = a([1 5 8]);
> 
> I can't seem to figure out a similar Python construct for selecting
> specific indices. Any suggestions?

b = [a[i] for i in [1, 5, 8]]

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


Simple question about Python lists

2008-11-11 Thread Eric
I'm learning Python (while coming from MATLAB). One question I have is
that if I have a list with say 8 elements, and I want just a few of
them how do I select them out. In MATLAB, if I just want the first,
fifth and eighth element I might do something like this:

b = a([1 5 8]);

I can't seem to figure out a similar Python construct for selecting
specific indices. Any suggestions?

Thanks,

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


Re: Close access to the base class public methods

2008-11-11 Thread Chris Rebert
On Tue, Nov 11, 2008 at 11:16 AM, RinKaMeAri <[EMAIL PROTECTED]> wrote:
> On Nov 11, 9:12 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>> RinKaMeAri wrote:
>> > Hi!
>> > Could you imagine any way to block access to the base class public
>> > methods?
>> > Here is an example:
>> > class B:
>> > def public_method():
>> > pass
>>
>> > class A(B):
>> > def public_a_method():
>> >  pass
>>
>> > def a = A()
>>
>> > Is there any way to block the call a.public_method() without any
>> > changes to B class?
>> > Thank you!
>>
>> The simplest way would be to override B.public_method within A by
>> defining A.public_method to raise a NotImplementedError or similar
>> exception. Though of course this then begs the question of why A would
>> need to subclass B in the first place, but I assume there would be
>> methods you *did* want to implement.
>>
 
>
> BTW, what do you mean "to subclass B in the *first place*"?

Because you're inheriting from A and yet you don't want to inherit a
certain part of A, in this case public_method(), it's usually a sign
something is wrong with your class hierarchy; otherwise, you could
just inherit from something else which would have just the part of A
you want to inherit; it's a so-called "code smell", specifically
Refused Bequest I believe.

See this link into Fowler's Refactoring for more info on Refused
Bequest and the other code smells:
http://books.google.com/books?id=1MsETFPD3I0C&pg=PA87&lpg=PA87&dq=refused+bequest&source=bl&ots=pKN4o0QJc7&sig=rYT4lfWxhKijvNHpLYqk8DY5Epw&hl=en&sa=X&oi=book_result&resnum=3&ct=result

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Close access to the base class public methods

2008-11-11 Thread Steve Holden
RinKaMeAri wrote:
> On Nov 11, 9:12 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>> RinKaMeAri wrote:
>>> Hi!
>>> Could you imagine any way to block access to the base class public
>>> methods?
>>> Here is an example:
>>> class B:
>>> def public_method():
>>> pass
>>> class A(B):
>>> def public_a_method():
>>>  pass
>>> def a = A()
>>> Is there any way to block the call a.public_method() without any
>>> changes to B class?
>>> Thank you!
>> The simplest way would be to override B.public_method within A by
>> defining A.public_method to raise a NotImplementedError or similar
>> exception. Though of course this then begs the question of why A would
>> need to subclass B in the first place, but I assume there would be
>> methods you *did* want to implement.
>>
>> Perhaps more background would yield a better solution.
>>
>> regards
>>  Steve
>> --
>> Steve Holden+1 571 484 6266   +1 800 494 3119
> 
> 
> Thanks, Steve! will do what you have proposed.
> 
> It is just the stub example. Have been writing some tests for class
> hierarchy and found the case when user can call the base method with
> the derived instance and have problems :-)  IMO, it is the class
> design bug. Tried to play with __all__, setattr, getattr, but didn't
> find any solution.
> 
> BTW, what do you mean "to subclass B in the *first place*"?

It's just an expression. As in "I built A as a subclass of B, but since
I overrode all B's methods in A there was no point making it a subclass
in the first place".

regards
 Steve

-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: subprocess communication, exec()

2008-11-11 Thread Jeff McNeil
On Nov 11, 1:23 pm, "Chuckk Hubbard" <[EMAIL PROTECTED]>
wrote:
> If I run 'python -i subprocessclient.py' I expect to see the nice
> level of it go up 2, and the nice level of the subprocess go up 1.
> But all I see is the nice level of the client change.  What am I doing
> wrong?
>
> subprocessserver.py:
> 
> #!/usr/bin/python2.5
>
> import os
> import sys
>
> while True:
> next_line = sys.stdin.readline()
> if not next_line:
> break
> exec(next_line)
> #sys.stdout.write(output)
> #sys.stdout.write(next_line)
> #sys.stdout.flush()
> 
>
> subprocessclient.py:
> 
> #!/usr/bin/python2.5
>
> import subprocess, os
>
> server = subprocess.Popen(('python2.5', 'subprocessserver.py'),
> shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
> stderr=subprocess.PIPE)
>
> os.nice(2)
>
> server.stdin.write('''os.nice(1)''')
> 
>
> Thanks.
> -Chuckk
>
> --http://www.badmuthahubbard.com

Looks like you're dropping an error by redirecting the child process'
standard error into a pipe.

First off, remove the stderr=subprocess.PIPE from
subprocessclient.py.  When you do so, you'll start seeing an error
message whenever your code runs:

[EMAIL PROTECTED] ~]$ python client.py
None
[EMAIL PROTECTED] ~]$ Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'os' is not defined

That doesn't make a lot of sense at first, until you consider the
following:

[EMAIL PROTECTED] ~]$ echo 'os.nice(1)' | python
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'os' is not defined

The Python interpreter is trying to execute the data you write to the
stdin of the child process.  Changing the Popen line to use the string
form rather than the sequence form remedies the problem, as does
changing 'string=True' to 'string=False.'

The reason? Because when you set shell=True, additional arguments in
args sequence are passed as additional arguments to the shell itself,
not to the command.

>From subprocess.py:

if isinstance(args, types.StringTypes):
args = [args]
else:
args = list(args)

if shell:
args = ["/bin/sh", "-c"] + args

So, in your attempt, you're effectively doing the following:

/bin/sh -c "python2.5" "server.py"

When you want:

/bin/sh -c "python2.5 server.py"

HTH,

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


Re: [Python-Dev] Python 2.5.3: call for patches

2008-11-11 Thread Martin v. Löwis
> I would like to apply fixes for some CVE's which are addressed in 2.5 but not
> yet in 2.4. this would include
> 
> CVE-2007-4965
> CVE-2008-1679
> CVE-2008-1721
> CVE-2008-2315
> CVE-2008-3144
> CVE-2008-1887
> CVE-2008-4864

Can you identify the revisions that would need backporting?

I could only find (trunk revisions)
  CVE-2007-4965: r65880
  CVE-2008-1721: r62235, issue2586
  CVE-2008-3144: issue2588, issue2589, r63734, r63728.
  CVE-2008-1887: issue2587, r62261, r62271
  CVE-2008-4864: r66689

So what about

  CVE-2008-1679: claimed to be issue1179 in the CVE, but
 that says it fixes CVE-2007-4965 only?
  CVE-2008-2315

In principle, this is fine with me, so go ahead.

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


Re: Printing a "status " line from a python script

2008-11-11 Thread Chris Rebert
On Tue, Nov 11, 2008 at 11:02 AM, Chris Seymour <[EMAIL PROTECTED]> wrote:
> Hi All,
> I am working on a python script for my colleague that will walk a
> directory and search in the different files for a specific string.
> These pieces I am able to do.  What my colleague wants is that when
> she runs the script the filename is replaced by the current file that
> is being processed.  So instead of seeing a series of files being
> listed down the page, she only wants to see the file currently being
> processed.
>
> I am not sure if this is even possible.  Any thoughts would be greatly
> appreciated.

Have you tried using carriage returns ("\r")?

chris ~ $ python
Python 2.5.1 (r251:54863, Feb  4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range(10):
... print '\r'+str(i),
9
>>>

Note how each line gets overwritten by the next so that we only see
the final number output (9).

But really, I don't see a good reason to do this. So what, the output
takes up some extra lines on the terminal? Big whoop. Your colleague
can either pipe the script to `less` or a file if it really bothers
them. And that way you get a list of all files processed, which can
often come in handy in my experience.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

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


Re: Printing a "status " line from a python script

2008-11-11 Thread Steve Holden
Chris Seymour wrote:
> Hi All,
> I am working on a python script for my colleague that will walk a
> directory and search in the different files for a specific string.
> These pieces I am able to do.  What my colleague wants is that when
> she runs the script the filename is replaced by the current file that
> is being processed.  So instead of seeing a series of files being
> listed down the page, she only wants to see the file currently being
> processed.
> 
> I am not sure if this is even possible.  Any thoughts would be greatly
> appreciated.
> 
Try printing each filename with

  sys.write("\r%s\r%s" % (" "*80, filename)

It's crappy, but it might just work (you may need to change the 80 to
some other numeric value).

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Close access to the base class public methods

2008-11-11 Thread RinKaMeAri
On Nov 11, 9:12 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> RinKaMeAri wrote:
> > Hi!
> > Could you imagine any way to block access to the base class public
> > methods?
> > Here is an example:
> > class B:
> >     def public_method():
> >         pass
>
> > class A(B):
> >     def public_a_method():
> >          pass
>
> > def a = A()
>
> > Is there any way to block the call a.public_method() without any
> > changes to B class?
> > Thank you!
>
> The simplest way would be to override B.public_method within A by
> defining A.public_method to raise a NotImplementedError or similar
> exception. Though of course this then begs the question of why A would
> need to subclass B in the first place, but I assume there would be
> methods you *did* want to implement.
>
> Perhaps more background would yield a better solution.
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119


Thanks, Steve! will do what you have proposed.

It is just the stub example. Have been writing some tests for class
hierarchy and found the case when user can call the base method with
the derived instance and have problems :-)  IMO, it is the class
design bug. Tried to play with __all__, setattr, getattr, but didn't
find any solution.

BTW, what do you mean "to subclass B in the *first place*"?
--
http://mail.python.org/mailman/listinfo/python-list


Re: plot for sale

2008-11-11 Thread Brian Blais

On Nov 7, 2008, at 7:27 , [EMAIL PROTECTED] wrote:


A plot in the new
economic zone of the city


Plots can be done using a library called matplotlib, and its free as  
far as I know. I'm not sure if the licensing prohibits selling the  
plots, but you'd need to post on that list for more details.




bb

--
Brian Blais
[EMAIL PROTECTED]
http://web.bryant.edu/~bblais



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


Printing a "status " line from a python script

2008-11-11 Thread Chris Seymour
Hi All,
I am working on a python script for my colleague that will walk a
directory and search in the different files for a specific string.
These pieces I am able to do.  What my colleague wants is that when
she runs the script the filename is replaced by the current file that
is being processed.  So instead of seeing a series of files being
listed down the page, she only wants to see the file currently being
processed.

I am not sure if this is even possible.  Any thoughts would be greatly
appreciated.

Thanks.

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


Re: f2py usage problem

2008-11-11 Thread Robert Kern

[EMAIL PROTECTED] wrote:

Hi Python gurus,
I have installed numpy and interested in testing f2py module using the
first example in the documentation.


Hi,

You will want to ask numpy questions on the numpy mailing list.

  http://www.scipy.org/Mailing_Lists


First I tried:

C:\test>python "C:\Program Files\Python25\Scripts\f2py.py" -c fib1.f

...

running build_ext
No module named msvccompiler in numpy.distutils; trying from distutils
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible
binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin
installed,
you can try compiling with MingW32, by passing "-c mingw32" to
setup.py.


Then I installed mingw32 and tried to pass "-c mingw32" to setup.py as
below, but got another error:


C:\tests>python "C:\Program Files\Python25\Lib\site-packages
\numpy-1.0.4.0002-py2.5-win32.egg\numpy\f2py\setup.py" -c mingw32


That's not the setup.py it is talking about. f2py is used both as a program and 
a library inside your own distutils setup.py scripts. Internally, the f2py 
program uses distutils to build the extension module. The error message you see 
comes from distutils, so it is (confusingly, in this case) assuming you are 
calling distutils from a setup.py script.


The corresponding f2py program option would be --compiler=mingw32 . See "f2py 
-h" for all of the command line options.


--
Robert Kern

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

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


Re: Python 3.0 - is this true?

2008-11-11 Thread Terry Reedy

M.-A. Lemburg wrote:



I think the special case for None should be readded to Python 3.0.


Quick summary of thread that MAL started on Python-3000-dev list:

Once upon a time, 0 < None was true.

When rich comparisons were added, None < 0 (and *most* other things) 
become true as an intentionally undocumented implementation detail.


The None rule only applies for sure when None controls the comparison: 
ob < None is true or undefined if type(ob) says so.


Guido's pronouncement: "In short, I'll have None of it."
summarizing

We're not going to add the "feature" back that None compares smaller
than everything. It's a slippery slope that ends with all operations
involving None returning None -- I've seen a proposal made in all
earnestness requesting that None+42 == None, None() == None, and so
on. This Nonesense was wisely rejected; a whole slew of
early-error-catching would have gone out of the window. It's the same
with making None smaller than everything else. For numbers, you can
already use -inf; for other types, you'll have to invent your own
Smallest if you need it.

tjr

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


Re: Python 3.0 - is this true?

2008-11-11 Thread Terry Reedy

Duncan Grisby wrote:


Yes, very hard.


There is a difference between 'very hard' (to get 'right') and 'to slow' 
(for a particular application).  I accept the latter.



There are only ever simple types in the lists --
strings, integers, Nones, very occasionally floats, and lists of those
things. The sort is always predictable with those types. Just because
you can contrive situations to demonstrate unpredictable sorts doesn't
mean that all sorts with mixed types are unpredictable.


The 2.5 manual (and I sure before that) *intentially* defines the 
default cross-type comparisons as unreliable.


"(This unusual definition of comparison was used to simplify the 
definition of operations like sorting and the in and not in operators. 
In the future, the comparison rules for objects of different types are 
likely to change.)"


They have changed in the past and now they change again (yes, a little 
more drastically this time, but as expected for some years).



The sorting is in a performance-critical part of the system, so the
overhead of evaluating a key function is not insignificant. A key
function that returns objects that contrive to emulate the
functionality of a comparison function is definitely not appropriate.
That area of the system already builds the lists using C++ for speed,
so if we ever migrate to Python 3 it will probably be easier to do the
whole thing in C++ rather than jump through hoops to make the Python
sort work efficiently enough.


Assuming the premises, agreed.  No hurry, but you can even pull 
timsort() out of the source, if you otherwise like its large-list 
behavior, and hardcode the comparison function.


Terry Jan Reedy

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


Re: disable ctrl-P in idle?

2008-11-11 Thread timw.google
On Nov 10, 10:35 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Nov 10, 4:49 pm, RichardT <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mon, 10 Nov 2008 10:40:28 -0800 (PST), "timw.google"
>
> > <[EMAIL PROTECTED]> wrote:
> > >Is there a way to disable ctrl-P (print window) in IDLE? I'm editing
> > >some python code in IDLE and I keep hitting this by mistake from my
> > >years of emacs editing.
>
> > >Thanks in advance.
>
> > In Idle, select 'Configure IDLE..' from the options menu.
>
> > In the Options dialog, select the Keys tab.
>
> > Scroll down to the 'print-window' entry and select it.
>
> > Click the "Get New Keys For Selection" button.
>
> > Select the new key combination e.g. Shift+Ctrl+p and click OK button.
>
> > If you have not enter any custom keys before, you will get a prompt
> > for a Custom Key Set Name - enter a name and click OK.
>
> For the archive, since our hero prefers not to receive credit.
>
> > Ctrl+P should no longer send the window to the printer. On my system
> > (python 2.5.1 on XP) it now moves the cursor up a line for some reason
> > (deafult binding for the widget?)
>
> Cursor up is the default emacs binding for Ctrl+P so this will
> probably please the original poster (and me too!)

Wonderful! I remapped ctrl-N too while I was at it. Thanks

(and no help desk involvement either!)
--
http://mail.python.org/mailman/listinfo/python-list


Re: disable ctrl-P in idle?

2008-11-11 Thread timw.google
On Nov 10, 4:53 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Nov 10, 3:27 pm, "timw.google" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Nov 10, 2:57 pm, Robert Singer <[EMAIL PROTECTED]> wrote:
>
> > > On Mon, 10 Nov 2008 20:56:46 +0100, Robert Singer <[EMAIL PROTECTED]>
> > > wrote:
>
> > > >On Mon, 10 Nov 2008 10:40:28 -0800 (PST), "timw.google"
> > > ><[EMAIL PROTECTED]> wrote:
>
> > > >>Is there a way to disable ctrl-P (print window) in IDLE? I'm editing
> > > >>some python code in IDLE and I keep hitting this by mistake from my
> > > >>years of emacs editing.
>
> > > >>Thanks in advance.
>
> > > >Try autohotkey and map it to something else. Like, nothing :-)
>
> > > >Internally, I don't think so, it's part of CUI.
>
> > > >-- Bob
>
> > > ... continue:
> > > Or, you can just continue using emacs. I'm using vim, and can't think
> > > of a single reason why I should change it for idle.
>
> > > -- Bob
>
> > Thanks. I on a XP box now, and it's a pain to get things installed
> > here. That's why I'm not using emacs. When I'm on Linux, I use emacs.
> > It's not worth the trouble to install something else for just this.
>
> It is not more difficult to install emacs on XP. What makes you think
> that?

It's not that it's technically  difficult. It's just a hassle to
involve the help desk.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >