Re: Python is slow?

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, José Matos
wrote:

> The gnuplot license is a free software according to FSF ...

Not listed as one
.

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


Buy propecia cheap

2008-10-05 Thread oneillbknut
buy propecia canada cheap
.
.
.
Enough to seek Propecia! You've already found the best site where
you can purchase Propecia for lowest price!
To order Propecia without prescription visit link below!

http://med247.us/?p=buy+propecia

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
 uy propecia canada cheap by propecia canada cheap bu propecia canada
cheap buy ropecia canada cheap buy popecia canada cheap buy prpecia
canada cheap buy proecia canada cheap buy propcia canada cheap buy
propeia canada cheap buy propeca canada cheap buy propeci canada cheap
buy propecia anada cheap buy propecia cnada cheap buy propecia caada
cheap buy propecia canda cheap buy propecia canaa cheap buy propecia
canad cheap buy propecia canada heap buy propecia canada ceap buy
propecia canada chap buy propecia canada chep buy propecia canada chea
bbuy propecia canada cheap buuy propecia canada cheap buyy propecia
canada cheap buy ppropecia canada cheap buy prropecia canada cheap buy
proopecia canada cheap buy proppecia canada cheap buy propeecia canada
cheap buy propeccia canada cheap buy propeciia canada cheap buy
propeciaa canada cheap buy propecia ccanada cheap buy propecia caanada
cheap buy propecia cannada cheap buy propecia canaada cheap buy
propecia canadda cheap buy propecia canadaa cheap buy propecia canada
ccheap buy propecia canada chheap buy propecia canada cheeap buy
propecia canada cheaap buy propecia canada cheapp uby propecia canada
cheap byu propecia canada cheap bu ypropecia canada cheap buy rpopecia
canada cheap buy porpecia canada cheap buy prpoecia canada cheap buy
proepcia canada cheap buy propceia canada cheap buy propeica canada
cheap buy propecai canada cheap buy propeci acanada cheap buy propecia
acnada cheap buy propecia cnaada cheap buy propecia caanda cheap buy
propecia candaa cheap buy propecia canaad cheap buy propecia canad
acheap buy propecia canada hceap buy propecia canada cehap buy
propecia canada chaep buy propecia canada chepa buypropecia canada
cheap buy propeciacanada cheap buy propecia canadacheap vuy propecia
canada cheap guy propecia canada cheap huy propecia canada cheap nuy
propecia canada cheap byy propecia canada cheap b7y propecia canada
cheap b8y propecia canada cheap biy propecia canada cheap bky propecia
canada cheap bjy propecia canada cheap bhy propecia canada cheap but
propecia canada cheap bu6 propecia canada cheap bu7 propecia canada
cheap buu propecia canada cheap buj propecia canada cheap buh propecia
canada cheap bug propecia canada cheap buy oropecia canada cheap buy
0ropecia canada cheap buy lropecia canada cheap buy peopecia canada
cheap buy p4opecia canada cheap buy p5opecia canada cheap buy ptopecia
canada cheap buy pgopecia canada cheap buy pfopecia canada cheap buy
pdopecia canada cheap buy pripecia canada cheap buy pr9pecia canada
cheap buy pr0pecia canada cheap buy prppecia canada cheap buy prlpecia
canada cheap buy prkpecia canada cheap buy prooecia canada cheap buy
pro0ecia canada cheap buy prolecia canada cheap buy propwcia canada
cheap buy prop3cia canada cheap buy prop4cia canada cheap buy proprcia
canada cheap buy propfcia canada cheap buy propdcia canada cheap buy
propscia canada cheap buy propexia canada cheap buy propedia canada
cheap buy propefia canada cheap buy propevia canada cheap buy propecua
canada cheap buy propec8a canada cheap buy propec9a canada cheap buy
propecoa canada cheap buy propecla canada cheap buy propecka canada
cheap buy propecja canada cheap buy propeciq canada cheap buy propeciw
canada cheap buy propecis canada cheap buy propecix canada cheap buy
propeciz canada cheap buy propecia xanada cheap buy propecia danada
cheap buy propecia fanada cheap buy propecia vanada cheap buy propecia
cqnada cheap buy propecia cwnada cheap buy propecia csnada cheap buy
propecia cxnada cheap buy propecia cznada cheap buy propecia cabada
cheap buy propecia cahada cheap buy propecia cajada cheap buy propecia
camada cheap buy propecia canqda cheap buy propecia canwda cheap buy
propecia cansda cheap buy propecia canxda cheap buy propecia canzda
cheap buy propecia canasa cheap buy propecia canaea cheap buy propecia
canara cheap buy propecia canafa cheap buy propecia canaca cheap buy
propecia canaxa cheap buy propecia canadq cheap buy propecia canadw
cheap buy propecia canads cheap buy propecia canadx cheap buy propecia
canadz cheap buy propecia canada xheap buy propecia canada dheap buy
propecia canada fheap buy propecia canada vheap buy propecia canada
cgeap buy propecia canada cyeap buy propecia canada cueap buy propecia
canada cjeap buy propecia canada cneap buy propecia canada cbeap buy
propecia canada chwap buy propecia canada ch3ap buy propecia canada
ch4ap buy propecia canada chrap buy propecia canada chfap buy propecia
canada chdap buy propecia canada chsap buy propecia canada cheqp buy
propecia canada chewp buy propecia canada chesp buy propecia ca

Re: Python is slow?

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Ben Finney wrote:

> Note that I consider a work free even if it fails to grant “the right
> to distribute misrepresentations of the author's words”, because that
> act is an exercise of undue power over another person, and so falls
> outside the limit imposed by the freedoms of others.

That's the difference between software and, say, an artistic work like a
novel, poem or illustration. Software is nearly always a work in progress.
That's why we have Free Software licences for the former, and Creative
Commons licences for the latter.
--
http://mail.python.org/mailman/listinfo/python-list


Buy fioricet online

2008-10-05 Thread ihcircekirkpatrick
buy fioricet
.
.
.
Enough to seek Fioricet! You've already found the best site where
you can purchase Fioricet for lowest price!
To order Fioricet without prescription visit link below!

http://med247.us/?p=fioricet

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
 uy fioricet by fioricet bu fioricet buy ioricet buy foricet buy
firicet buy fioicet buy fiorcet buy fioriet buy fiorict buy fiorice
bbuy fioricet buuy fioricet buyy fioricet buy ffioricet buy fiioricet
buy fiooricet buy fiorricet buy fioriicet buy fioriccet buy fioriceet
buy fioricett uby fioricet byu fioricet bu yfioricet buy iforicet buy
foiricet buy firoicet buy fioircet buy fiorciet buy fioriect buy
fioricte buyfioricet vuy fioricet guy fioricet huy fioricet nuy
fioricet byy fioricet b7y fioricet b8y fioricet biy fioricet bky
fioricet bjy fioricet bhy fioricet but fioricet bu6 fioricet bu7
fioricet buu fioricet buj fioricet buh fioricet bug fioricet buy
dioricet buy rioricet buy tioricet buy gioricet buy vioricet buy
cioricet buy fuoricet buy f8oricet buy f9oricet buy fooricet buy
floricet buy fkoricet buy fjoricet buy fiiricet buy fi9ricet buy
fi0ricet buy fipricet buy filricet buy fikricet buy fioeicet buy
fio4icet buy fio5icet buy fioticet buy fiogicet buy fioficet buy
fiodicet buy fiorucet buy fior8cet buy fior9cet buy fiorocet buy
fiorlcet buy fiorkcet buy fiorjcet buy fiorixet buy fioridet buy
fiorifet buy fiorivet buy fioricwt buy fioric3t buy fioric4t buy
fioricrt buy fioricft buy fioricdt buy fioricst buy fioricer buy
fiorice5 buy fiorice6 buy fioricey buy fioriceh buy fioriceg buy
fioricef
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Scott David Daniels

Terry Reedy wrote:

...
Your point, that taking floor(log2(x)) is redundant, is a good catch. 
However, you should have added 'untested' ;-).  When value has more 
significant bits than the fp mantissa can hold, this expression can be 1 
off (but no more, I assume).   The following correction should be 
sufficient:


res = math.frexp(value)[1] - EXP_OF_ONE
test = 1< r: res -= 1
elif 2*test < r: res += 1


Well, I did test, but poorly.
>>> high_bit(1<<587)
587
>>> high_bit(1<<587-1)
586

And of course, I _should_ have tested
>>> high_bit((1<<587)-1)
587

By the way, I wrote my response before any replies had happened; it was
not a correction to your post.

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


Places that are hiring in my area

2008-10-05 Thread woodsonturtletw
.
.
.
Enough to seek places that are hiring! You've already found the best
site!
Visit link below!

http://med247.us/?p=job+hiring

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
 I was thankful that places that are hiring was a little worse for
wear.  I was thankful that now hiring was a little worse for wear.  I
was thankful that jobs hiring in my area was a little worse for wear.
I was thankful that fast hiring jobs was a little worse for wear.  I
was thankful that who's hiring right now was a little worse for wear.
I was thankful that jobs for 14 year olds was a little worse for
wear.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ABCs -> infix syntax for isinstance() ?

2008-10-05 Thread bborcic
Bruno Desthuilliers dixit :

> Boris Borcic a écrit :
>
> > Given the ABC innovation, maybe an infix syntax for isinstance() would
> > be good.
>
> > Possibilities :
>
> > - stealing "is" away from object identity. As a motivation, true use
> > cases for testing object identity are rare;
>
> "x is None" is a *very* common test. Using a _marker object as default
> arg value when you want to accept None as a meaningfull value is pretty
> common.

(a) Okay, 3to2 can take care of "x is NoneType" and/or "x == None".
The latter could also be a compiler optimization.

(b) Give me None==False and in exchange I will adopt "x is None" as
sacred forever :)

(not quite BTW, how much future do you think is there in turning 2to3
into some usable 3to2 ? What about "NtoM" as a more generic Python
project ?)

> Testing a class identity often happens when writing metaclasses

This kind-of-talks for Terry's proposition : adding a __contains__ to
type, looks like easier to pass before lead metaclass-writers. Or if
not easier to pass, easier to write a simple patch for. So "x in
Number" syntax.

A intriguing wider proposition would be to transpose Ruby's notion of
"Open Classes" to Python built-in metaclasses (or just to type
itself ?).

Let's threaten lead metaclass-writers with *that* if they don't settle
on just type.__contains__ = lambda cls,i : isinstance(i,cls) !! :)

Cheers, BB


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


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Rich Healey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Aaron "Castironpi" Brady wrote:
> Duncan Booth wrote:
>> [EMAIL PROTECTED] wrote:
>>
>>> My question to the group: Does anyone know of a non-hackish way to
>>> determine the required bit position in python? I know that my two
>>> ideas
>>> can be combined to get something working. But is there a *better* way,
>>> that isn't that hackish?
>>>
>> How about using the hex representation of the value?
>>
>> OFFSET = dict(("%x"%i, int(c)) for i,c in enumerate("5433"))
>> def get_highest_bit_num(r):
>> s = "%x"%r
>> return len(s) * 4 - OFFSET[s[0]]
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>>
> 
> You can replace the dict if it's faster.
> 
> OFFSET= tuple( int(x) for x in "5433" )
> def get_highest_bit_num(r):
> s = "%x"%r
> return len(s) * 4 - OFFSET[int(s[0],16)]
> 
> P.S.  Back home, this sort of 'nitpicking' would be judged
> unconstructive.  Worth pointing out, or not worth saying?
> 
> P.S.S.  'Thighest' bit?  I thought the spam filters would catch that.
> 
That should be P.P.S.

PS: This is also unconstructive nitpicking.

Kind regards


Rich ;)

- --
Rich Healey - iTReign  \.''`.   / [EMAIL PROTECTED]
Developer / Systems Admin   \  : :' :  /[EMAIL PROTECTED]
AIM: richohealey33   \ `. `'  / [EMAIL PROTECTED]
MSN: [EMAIL PROTECTED] \  `-  / [EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjpVZUACgkQLeTfO4yBSAcgeACgr45Hu4XKyMjCf0jwq1LR35tU
Lv8AnRn2RgHCxJ3QwYpNO8/DjLncKv2t
=/WZa
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Aaron "Castironpi" Brady
On Oct 5, 2:12 pm, "Aaron \"Castironpi\" Brady" <[EMAIL PROTECTED]>
wrote:
> Duncan Booth wrote:
> > [EMAIL PROTECTED] wrote:
>
> > OFFSET = dict(("%x"%i, int(c)) for i,c in enumerate("5433"))
> > def get_highest_bit_num(r):
> >s = "%x"%r
> >return len(s) * 4 - OFFSET[s[0]]
>
> OFFSET= tuple( int(x) for x in "5433" )
> def get_highest_bit_num(r):
>  s = "%x"%r
>  return len(s) * 4 - OFFSET[int(s[0],16)]

That's really counterintuitive.  (That's the word, yes.)  They're both
function calls and both global variables.  Maybe you could use 'len(s)
* 4' to mask out the rest and lookup that index, rather than
converting -back- to integer.  Or, better yet, take 'ord' of s[0].
(Ha ha, -you- time it.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Aaron "Castironpi" Brady
On Oct 5, 7:02 pm, Rich Healey <[EMAIL PROTECTED]> wrote:
> > P.S.  Back home, this sort of 'nitpicking' would be judged
> > unconstructive.  Worth pointing out, or not worth saying?
>
> > P.S.S.  'Thighest' bit?  I thought the spam filters would catch that.
>
> That should be P.P.S.
>
> PS: This is also unconstructive nitpicking.
>
> Kind regards
>
> Rich ;)

Hey, whatever gets the bills paid, friend.
--
http://mail.python.org/mailman/listinfo/python-list


When Python should not be used?

2008-10-05 Thread Andrea Francia

The right tool depends on the current problem.

While some python users prefer to talk about when Python is the right 
tool I think that it is more instructive to know when it is not.


Please, could you let me know what do you think about that?

Thanks
--
Andrea Francia
http://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-windows.html
--
http://mail.python.org/mailman/listinfo/python-list


"'int' object is not iterable" iterating over a dict

2008-10-05 Thread mmiikkee13
>>> a_list = range(37)
>>> list_as_dict = dict(zip(range(len(a_list)), [str(i) for i in a_list]))
>>> for k, v in list_as_dict:
... print k, v
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not iterable

What 'int' object is this referring to? I'm iterating over a dict, not
an int.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 / 3.0: Determining if a method is inherited

2008-10-05 Thread MRAB
Fuzzyman wrote:
> Hello all,
>
> I may well be being dumb (it has happened before), but I'm struggling
> to fix some code breakage with Python 2.6.
>
> I have some code that looks for the '__lt__' method on a class:
>
> if hasattr(clr, '__lt__'):
>
> However - in Python 2.6 object has grown a default implementation of
> '__lt__', so this test always returns True.
>
> >>> class X(object): pass
> ...
> >>> X.__lt__
> 
> >>> X.__lt__ == object.__lt__
> False
>
> So how do I tell if the X.__lt__ is inherited from object? I can look
> in the '__dict__' of the class - but that doesn't tell me if X
> inherits '__lt__' from a base class other than object. (Looking inside
> the method wrapper repr with a regex is not an acceptable answer...)
>
> Some things I have tried:
>
> >>> X.__lt__.__self__
> 
> >>> dir(X.__lt__)
> ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__',
> '__format__', '__getattribute__', '__hash__', '__init__', '__name__',
> '__new__', '__objclass__', '__reduce__', '__reduce_ex__', '__repr__',
> '__self__', '__setattr__', '__sizeof__', '__str__',
> '__subclasshook__']
> >>> X.__lt__.__func__
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'method-wrapper' object has no attribute '__func__'
>
>
> Hmmm... I can get this working with Python 2.6 with:
>
> if '__lt__' in dir(cls):
>
> The default implementation of '__lt__' doesn't appear in the dir of
> classes. However this fails with Python 3 where the default
> implementation *does* appear in the output of 'dir'. Any suggestions?
>
Methods are objects. How do you know if two references refer to the
same object? You use "is":

X.__lt__ is object.__lt__
--
http://mail.python.org/mailman/listinfo/python-list


Re: "'int' object is not iterable" iterating over a dict

2008-10-05 Thread Alex_Gaynor
On Oct 5, 8:11 pm, mmiikkee13 <[EMAIL PROTECTED]> wrote:
> >>> a_list = range(37)
> >>> list_as_dict = dict(zip(range(len(a_list)), [str(i) for i in a_list]))
> >>> for k, v in list_as_dict:
>
> ...     print k, v
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: 'int' object is not iterable
>
> What 'int' object is this referring to? I'm iterating over a dict, not
> an int.

It thinks you are trying to unpack the first item, you mean to be
doing for k, v in list_as_dict.iteritems()
--
http://mail.python.org/mailman/listinfo/python-list


Re: When Python should not be used?

2008-10-05 Thread bborcic
On 6 oct, 02:08, Andrea Francia <[EMAIL PROTECTED]
HERE.ohoihihoihoih.TO-HERE.gmx.it> wrote:

> While some python users prefer to talk about when Python is the right
> tool I think that it is more instructive to know when it is not.

Python is not the right tool when you know what the right tool is, and
it happens not to be Python.

I-guess-it-is-more-instructive-in-context-ly yours, BB
--
http://mail.python.org/mailman/listinfo/python-list


EARN 1000$ IN EVERY MONTH

2008-10-05 Thread chinu
hai,
i am srinu from india. i am sending a blog url for yours use.

click on the blog and get more information to choose yours job.

the blog url is:


 http://earnmonthlyincome.blogspot.com/



  goodluck

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


Re: Python 2.6 / 3.0: Determining if a method is inherited

2008-10-05 Thread Aaron "Castironpi" Brady
On Oct 5, 7:13 pm, MRAB <[EMAIL PROTECTED]> wrote:
> Fuzzyman wrote:
> > Hello all,
>
> > I may well be being dumb (it has happened before), but I'm struggling
> > to fix some code breakage with Python 2.6.
>
> > I have some code that looks for the '__lt__' method on a class:
>
> > if hasattr(clr, '__lt__'):
>
> > However - in Python 2.6 object has grown a default implementation of
> > '__lt__', so this test always returns True.
>
> > Hmmm... I can get this working with Python 2.6 with:
>
> Methods are objects. How do you know if two references refer to the
> same object? You use "is":
>
> X.__lt__ is object.__lt__

That doesn't work for me.

>>> class A( object ):
... pass
...
>>> class B( A ):
... def __lt__( self, other ):
... return self
...
>>> a= A()
>>> b= B()
>>> B.__lt__ is object.__lt__
False
>>> A.__lt__ is object.__lt__
False
>>>

Further, it's been noted before that

A().meth is not A().meth
--
http://mail.python.org/mailman/listinfo/python-list


Re: When Python should not be used?

2008-10-05 Thread Aaron "Castironpi" Brady
On Oct 5, 7:08 pm, Andrea Francia <[EMAIL PROTECTED]
HERE.ohoihihoihoih.TO-HERE.gmx.it> wrote:
> The right tool depends on the current problem.
>
> While some python users prefer to talk about when Python is the right
> tool I think that it is more instructive to know when it is not.
>
> Please, could you let me know what do you think about that?
>
> Thanks
> --
> Andrea 
> Franciahttp://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-window...

In a team situation when you need code and can't find discipline.  Its
freedom would only handicap you, and the restrictions static typing
has would help programmers keep their hands to themselves, more or
less enforcing function signatures and member visibility and so on.
--
http://mail.python.org/mailman/listinfo/python-list


Re: lint for Python?

2008-10-05 Thread Aaron "Castironpi" Brady
On Oct 5, 8:53 am, Pat <[EMAIL PROTECTED]> wrote:
> Miki wrote:
> > Hello,
>
> >> In module one, I have a function:
>
> >> def foo( host, userid, password ):
> >>      pass
>
> >> In module two, I call that function:
>
> >> foo( userid, password)
>
> >> lint doesn't find that error and it won't be caught until it's called
> >> while the program is running.
> > pychecker does find these kind of errors.
>
> Before posting my original question, I tried pychecker and it didn't
> catch that error.

Sorry for the multiple posting earlier (you heard me right, not 2 but
3 identical).  The basic checker of walking a parse tree, doing
imports by hand, and checking call signatures isn't awful.  60 lines.

/File:

from ng23mod1 import foo as foo
userid, password= 'abc', '123'
import random
foo( 'localhost', userid, password)
if random.uniform( 0, 1 )< .01: # 1 out of 100 times
foo( userid, password)

/Checker output:

foo ['Str', 'Name', 'Name'] found 3 expected
random ['Num', 'Num'] found 2 expected
foo ['Name', 'Name'] found 3 expected

But it's extremely delicate and at 60 lines only checks fixed-length
call signatures and functions, not even methods.  If you have a
statement:

x= y.z()

Then 'y' has to be defined somewhere, so you could make some educated
guesses that way.
--
http://mail.python.org/mailman/listinfo/python-list


Pr. Euler 18, recursion problem

2008-10-05 Thread process
I am trying to solve project euler problem 18 with brute force(I will
move on to a better solution after I have done that for problem 67).
http://projecteuler.net/index.php?section=problems&id=18

However I can't get the recursive function right.

I always have to use return right? Unless I am printing? So I canät
stack to diffferent recursive calls after each other like so:
recur_left(t, p)
recur_right(t,p+1)


Some stuff I have tried:

def recur(tree, pos):
if not tree:
return []
else:
return [[tree[0][pos]] + recur(tree[1:], pos)] + \
   [[tree[0][pos]] + recur(tree[1:], pos+1)]


>>> recur([[1],[2,3],[4,5,6]],0)
[[1, [2, [4], [4]], [2, [5], [5]]], [1, [3, [5], [5]], [3, [6], [6


SO it is kind of working, just not exactly like I want.
A more easily parseable/readable result would be nice, I want to be
able to sum() over each path preferrably.

So the result should be:
[[1,2,4],[1,2,5],[1,3,5],[1,3,6]]



I know conceptually what has to be done.
Base case: empty tree, return []
Else: recur to the left and to the right.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sftp problem!

2008-10-05 Thread Mike Hjorleifsson
here is a snippet that works, you need to replace the default data or
create a database etc.. and the fields to store it
you also need to generate and share your public key to the receiving
server to avoid password prompt


# Standard library imports
import os
import sys
import time
import traceback
import paramiko


# my defaultdata is stored in a sqllite table called merchant.lib
# you can just assign values to defaultdata or recreate a database of
your own
from merchant.lib import defaultdata


# set up default values
hostname = defaultdata.defaults['hostname']
username = defaultdata.defaults['username']
password = defaultdata.defaults['password']

# paramiko required data
port = defaultdata.defaults['port']
fname = defaultdata.defaults['fname']
pathupload = defaultdata.defaults['pathupload']
pathdownload = defaultdata.defaults['pathdownload']
input_dir = defaultdata.defaults['input_dir']
output_dir = defaultdata.defaults['output_dir']
curdir = os.path.abspath(os.curdir)

# load ssh pkey  you need to precreate the key and ensure the server
side
# has it in its authorized_keys
pkey_path = os.path.expanduser('~/.ssh/id_dsa')
pkey = paramiko.DSSKey.from_private_key_file(pkey_path)

paramiko.util.log_to_file('transfer.log')
logger = paramiko.util.get_logger('paramiko')

try:
# set up connection
t = paramiko.Transport((hostname, port))
t.connect(username=username, pkey=pkey)
sftp = paramiko.SFTPClient.from_transport(t)

# upload files
files = [file for file in os.listdir(output_dir)
if file.endswith('.txt')]
logger.info("UPLOAD FILES %s" % files)
os.chdir(output_dir)
for file in files:
sftp.put(file, os.path.join(pathupload, file))
os.rename(file, file + '.old')

# download files
response_files = [file for file in sftp.listdir(pathdownload)
if file.startswith('DISCOVER_RESPONSE_')]

logger.info("RESPOSE FILES: %s" % response_files)
os.chdir(os.path.join(curdir, input_dir))
for file in response_files:
file_path = os.path.join(pathdownload, file)
sftp.get(file_path, file)
sftp.remove(file_path)


  # close connection
t.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: paramiko.SSHException : No existing session ???

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, sa6113
wrote:

> print "doing authentication"
...
> 
> -
> the result is :
...
> donig authentication

Interesting that these two don't match up. When you're supposed to copy and
paste, you should copy and paste, not type it in.
--
http://mail.python.org/mailman/listinfo/python-list


If an OS was to be written in Python, how'w it look?

2008-10-05 Thread process
If an OS was to be written in Python and the hardware optimized for
it, what changes would be made to the hardware to accomodate Python
strenghs and weaknesses?

Some tagged architecture like in Lisp machines?
http://en.wikipedia.org/wiki/Tagged_architecture

What else?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with lower() for unicode strings in russian

2008-10-05 Thread Alexey Moskvin
Martin, thanks for fast reply, now anything is ok!
On Oct 6, 1:30 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > I have a set of strings (all letters are capitalized) at utf-8,
>
> That's the problem. If these are really utf-8 encoded byte strings,
> then .lower likely won't work. It uses the C library's tolower API,
> which works on a byte level, i.e. can't work for multi-byte encodings.
>
> What you need to do is to operate on Unicode strings. I.e. instead
> of
>
>   s.lower()
>
> do
>
>   s.decode("utf-8").lower()
>
> or (if you need byte strings back)
>
>   s.decode("utf-8").lower().encode("utf-8")
>
> If you find that you write the latter, I recommend that you redesign
> your application. Don't use byte strings to represent text, but use
> Unicode strings all the time, except at the system boundary (where
> you decode/encode as appropriate).
>
> There are some limitations with Unicode .lower also, but I don't
> think they apply to Russian (specifically, SpecialCasing.txt is
> not considered).
>
> HTH,
> Martin

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


ANN: M2Crypto 0.19

2008-10-05 Thread Heikki Toivonen
I am happy to announce the M2Crypto 0.19 release!

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.

Note: Python 2.6 shipped with optional timeout parameters to many
network modules; there is no support for these in M2Crypto 0.19.
Otherwise 2.6 is supported.

Changes:

- OpenSSL OBJ_* functions wrapped by Pavel Shramov
- OpenSSL ENGINE interface wrapped, providing support for smart cards,
  by Martin Paljak and Pavel Shramov
- EVP.PKey.get_rsa() now returns RSA_pub, which fixes segmentation fault
  when trying to encrypt using public key from X509 certificate,
  by Ben Timby
- httpslib.ProxyHTTPSConnection now sends the required Host header,
  by Karl Grindley
- Use the proxied User-Agent value in CONNECT requests, by James Antill
  and Miloslav Trmac
- Fixed m2urllib.build_opener when optional handlers were in use,
  affected Python 2.5 and later, by Miloslav Trmac
- Reverted the incorrect GIL change done in 0.18 to
  m2.passphrase_callback, which caused a deadlock when called from
  mod_python for example. Thanks to Michal Kochel and Keith Jackson.
- SSL.Connection.accept() passed wrong certificate to
  postConnectionCheck callback
- httpslib.HTTPSConnection now raises ValueError for illegal keyword
  argument
- m2.pkey_write_pem[_no_cipher] changed to use the recommended (more
  secure) PEM_write_bio_PKCS8PrivateKey (used by
  PEM_write_bio_PrivateKey).
- X509.load_cert, load_cert_bio, load_cert_der_string,
  new_stack_from_der, load_request and load_crl now raise X509Error for
  invalid data. Previously some of these raised a string as an error,
  some did not raise but caused strange errors later, for example
  x509.verify() would return -1.
- Fixed SSL.Connection.get_socket_read_timeout and
  set_socket_read_timeout on 64bit platforms by adding
  SSL.timeout.struct_size() and using it instead of
  hardcoded size for socket.getsockopt
- X509_Store.load_info now returns the value from the underlying
  m2.x509_store_load_locations call, and in case of error raises
  X509Error
- Fixed SMIME.verify to raise the correct PKCS7_Error (used to raise
  SMIME_Error) when verification fails with Python 2.6

Requirements:

* Python 2.3 or newer
  o m2urllib2 requires Python 2.4 or newer
* OpenSSL 0.9.7 or newer
  o Some optional new features will require OpenSSL 0.9.8 or newer
* SWIG 1.3.24 or newer required for building
  o SWIG 1.3.30 or newer may be required with Python 2.5 or newer and
  Python 2.4 with Py_ssize_t patches

Download link available from the M2Crypto homepage:
http://chandlerproject.org/Projects/MeTooCrypto

Or use easy_install (may not work on all systems): easy_install M2Crypto

-- 
  Heikki Toivonen - http://www.heikkitoivonen.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie: decorator

2008-10-05 Thread Michele Simionato
On Oct 5, 4:27 pm, TK <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need an understandable Decorator-Example? Who can help? Thanks.
>
> o-o
>
> Thomas

You may want to look at my decorator module, which has
plenty of examples, some simple, some less simple:
http://www.phyast.pitt.edu/~micheles/python/documentation.html
--
http://mail.python.org/mailman/listinfo/python-list


XML-Stylesheet

2008-10-05 Thread mini.walia
Hi,

I want to insert into a xml file after
 through java
How to insert it in between a .xsd document.



Please do not print this email unless it is absolutely necessary. 

The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email. 

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


In Python 2.6, bytes is str

2008-10-05 Thread Bryan Olson


Python 3 has the 'bytes' type, which the string type I've long wanted in 
various languages. Among other advantages, it is immutable, and 
therefore bytes objects can be dict keys. There's a mutable version too, 
called "bytearray".


In Python 2.6, the name 'bytes' is defined, and bound to str. The 2.6 
assignment presents some pitfalls. Be aware.


Consider constructing a bytes object as:

b = bytes([68, 255, 0])

In Python 3.x, len(b) will be 3, which feels right.

In Python 2.6, len(b) will be  12, because b is the str, '[68, 255, 0]'.


I'm thinking I should just avoid using 'bytes' in Python 2.6. If there's 
 another Python release between 2.6 and 3.gold, I'd advocate removing 
the pre-defined 'bytes', or maybe defining it as something else.



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


Re: garbage collector and slowdown (guillaume weymeskirch)

2008-10-05 Thread guillaume weymeskirch
Thanks !
No more slowdown in python 2.6, both on gentoo and winxp systems.

I love python so much so I can live with that until I will upgrade to
the 2.6 version.
--
http://mail.python.org/mailman/listinfo/python-list


Re: paramiko.SSHException : No existing session ???

2008-10-05 Thread sa6113

My problem is in password authentication.


Lawrence D'Oliveiro wrote:
> 
> In message <[EMAIL PROTECTED]>, sa6113
> wrote:
> 
>> print "doing authentication"
> ...
>> 
>> -
>> the result is :
> ...
>> donig authentication
> 
> Interesting that these two don't match up. When you're supposed to copy
> and
> paste, you should copy and paste, not type it in.
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/paramiko.SSHException-%3A-No-existing-session-tp19823051p19832282.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: python-2.6

2008-10-05 Thread Rajanikanth Jammalamadaka
There seems to be a bug with idle on Mac OS X.

http://bugs.python.org/issue4017

It has to do something with reinstalling the TCL and TK.

 If you want to see detailed error messages, open a terminal and type
idle at the command prompt.

Cheers,

Raj

On Thu, Oct 2, 2008 at 11:26 PM,  <[EMAIL PROTECTED]> wrote:
> Strange things happens.
>
> I've download the installer package for Mac of Python 2.6 and I've launched
> it. When finished, I've launched from a terminal the command "Python" and
> all worked fine The response was "Python 2.6 etc...". Now I've launched
> IDLE. Nothing. IDLE icon blinked a couple of time in dock and then
> disapeared. I've disabled any firewall in the system but the behavior was
> the same. I've repared the privilege and restarted the system.
> A disaster. The system was dramatically slow and IDLE was still not
> starting. Then I've reinstalled Python 2.5.2 an all was working fine again
> (included IDLE and System speed).
>
> What is wrong with Python 2.6 on my system (MacOS X 10.4.11 PPC)?
>
>
>- Original Message 
>Da: Terry Reedy <[EMAIL PROTECTED]>
>To: [email protected] 
>Oggetto: Re: python-2.6
>Data: 03/10/08 03:41
>
>>
>>
>>
>> [EMAIL PROTECTED] wrote:
>> > Hi all.
>> >
>> > I've installed on may MacOS X 10.4.11 (PPC) Python-2.5.2, numpy and
> scipy.
>> > Now I'm interested to insall Python-2.6. My question is: What will
> happen to
>> > may scientific modules if now I jump fro 2.5.2 to 2.6? I've to reinstall
>> > numpy and scipy?
>>
>> Keep your 2.5.2 install intact until you have everything you need and
>> want in a 2.6 install.
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>>
>  --
>  Email.it, the professional e-mail, gratis per te: http://www.email.it/f
>
>  Sponsor:
>  CheBanca! La prima banca che ti dà gli interessi in anticipo.
> Fino al 4,70% sul Conto Deposito, zero spese e interessi subito. Aprilo!
>  Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=7919&d=20081003
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: Pr. Euler 18, recursion problem

2008-10-05 Thread Aidan

process wrote:

I am trying to solve project euler problem 18 with brute force(I will
move on to a better solution after I have done that for problem 67).
http://projecteuler.net/index.php?section=problems&id=18

However I can't get the recursive function right.

I always have to use return right? Unless I am printing? So I canät
stack to diffferent recursive calls after each other like so:
recur_left(t, p)
recur_right(t,p+1)


Some stuff I have tried:

def recur(tree, pos):
if not tree:
return []
else:
return [[tree[0][pos]] + recur(tree[1:], pos)] + \
   [[tree[0][pos]] + recur(tree[1:], pos+1)]



recur([[1],[2,3],[4,5,6]],0)

[[1, [2, [4], [4]], [2, [5], [5]]], [1, [3, [5], [5]], [3, [6], [6


SO it is kind of working, just not exactly like I want.
A more easily parseable/readable result would be nice, I want to be
able to sum() over each path preferrably.

So the result should be:
[[1,2,4],[1,2,5],[1,3,5],[1,3,6]]



I know conceptually what has to be done.
Base case: empty tree, return []
Else: recur to the left and to the right.


This is just my opinion, but I felt the non-brute force solution to this 
problem was actually simpler than trying to define a brute force 
recursive solution I tried to implement a brute force algorithm at 
first, until I had an epiphany with regard to how simple the problem 
actually was.  Then I faced palmed.

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


Re: Python 2.6: Determining if a method is inherited

2008-10-05 Thread Christian Heimes

Terry Reedy wrote:
In 3.0, the test returns true because function attributes only get 
wrapped when bound.  In the meanwhile, " 'object' in repr(X.__lt__)" 
should do it for you.


This session should give you some hints how to archive your goal :)
Have fun!

>>> import types
>>> class A(object):
... def __lt__(self):
... pass
...
>>> isinstance(A.__lt__, types.MethodType)
True
>>> isinstance(A.__gt__, types.MethodType)
False

>>> type(A.__lt__)

>>> type(A.__gt__)

>>> type(A.__str__)

>>> type(A.__new__)


>>> A.__lt__.im_func

>>> A.__lt__.im_func == A.__lt__.im_func
True
>>> A.__gt__.im_func
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'method-wrapper' object has no attribute 'im_func'

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


Re: Python 2.6, GUI not working on vista?

2008-10-05 Thread Steve Holden
Thorsten Kampe wrote:
> * Lawrence D'Oliveiro (Sun, 05 Oct 2008 22:13:46 +1300)
>> In message <[EMAIL PROTECTED]>, Michel Claveau - NoSpam
>> SVP ; merci wrote:
>>
>>> Another way is to de-activate UAC.
>> Please don't be stupid!
> 
> He's not stupid. Disabling UAC is the recommended way to get rid of 
> these problems.
> 
Microsoft have now admitted that they implemented UAC not to improve
security but to cause complaints from customers so that application
vendors would stop their programs from taking actions that needed UAC
confirmation.

http://arstechnica.com/news.ars/post/20080411-vistas-uac-security-prompt-was-designed-to-annoy-you.html

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: "'int' object is not iterable" iterating over a dict

2008-10-05 Thread Diez B. Roggisch

mmiikkee13 schrieb:

a_list = range(37)
list_as_dict = dict(zip(range(len(a_list)), [str(i) for i in a_list]))
for k, v in list_as_dict:

... print k, v
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not iterable

What 'int' object is this referring to? I'm iterating over a dict, not
an int.


Because

for name in dictionary:


will bind name to the *keys* of dictionary. Thus you end up with an int.

Then the tuple-unpacking occurs:

k, v = 

Which is equivalent to

k = [0]
v = [1]

And because  isn't iterable, it will fail.

Use

for k, v in dictionary.iteritems():


instead.

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


Re: Tuple parameter unpacking in 3.x

2008-10-05 Thread Martin Geisler
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Sat, 04 Oct 2008 17:07:14 +0200, Martin Geisler wrote:
>
>> A somewhat related question: do I pay a performance penalty when I
>> let a function define an inner function like this:
>> 
>>   def foo():
>> 
>> def bar()
>>   ...
>> 
>> bar()
>> 
>> compared to just defining it once outside:
>> 
>>   def bar():
>> ...
>> 
>>   def foo():
>> ...
>> bar()
>> 
>> I'm thinking that each execution of the first foo could spend a
>> little time defining a new bar each time, or is that not how things
>> work?
>> 
>> I realize that defining bar as an inner function has the advantage of
>> being able to see variables in the namespace of foo.
>
> That is the main advantage, followed by reducing namespace pollution,
> but yes there is a very small performance penalty.
>
>
 def outer(x):
> ... return x+1
> ...
 def func(x):
> ... return outer(x+1)
> ...

 def func2(x):
> ... def inner(x):
> ... return x+1
> ... return inner(x+1)
> ...
 assert func(37) == func2(37)
 from timeit import Timer
 t1 = Timer('func(23)', 'from __main__ import func')
 t2 = Timer('func2(23)', 'from __main__ import func2')
 t1.repeat()
> [1.5711719989776611, 0.82663798332214355, 0.82708191871643066]
 t2.repeat()
> [1.8273210525512695, 1.1913230419158936, 1.1786220073699951]

Very interesting, thanks for measuring this!

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.


pgpLR7SBbBPVr.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: del and sets proposal

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:

> Would it really be "confusing" if sets used the same interface as dicts
> use? I don't think so. What else could "del aset[x]" mean other than
> "delete element x"?

Yes, but "x" in what sense? In dicts it's a key, in sets, shouldn't it also
be a key and not a value?

Sets have no keys, only values. One might suggest assignment of keys, à la
array indexes, but that means assigning an ordering to the values, whereas
sets are explicitly unordered.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6, GUI not working on vista?

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Michel Claveau - NoSpam
SVP ; merci wrote:

> Another way is to de-activate UAC.

Please don't be stupid!
--
http://mail.python.org/mailman/listinfo/python-list


Re: lint for Python?

2008-10-05 Thread Miki
Hello,

> In module one, I have a function:
>
> def foo( host, userid, password ):
>      pass
>
> In module two, I call that function:
>
> foo( userid, password)
>
> lint doesn't find that error and it won't be caught until it's called
> while the program is running.
pychecker does find these kind of errors.

> I've never used a language that didn't catch that type of error.  I'm
> quite surprised that Python is being used by a number of major
> companies.  How you catch these types of errors?
By running a large test suite, I highly recommend "nose".

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple parameter unpacking in 3.x

2008-10-05 Thread Duncan Booth
Martin Geisler <[EMAIL PROTECTED]> wrote:

> Letting the callbacks take several arguments would definitely be the
> nicest syntax, but I'm unfortunately restricted by the Twisted
> framework: there all functions in a callback chain return one result
> which is passed to the next callback as the first argument. That is why
> I do a fair amount of tuple unpacking in my code.
 
If you only have to contend with that one pattern then you could write a 
decorator to unpack a single argument. Maybe not ideal, but then you have 
the option to write:

@unpacked
def product(a, b):
return a*b
ci.addCallback(product)

or

ci.addCallback(unpacked(lambda a,b: a*b))

for some suitable definition of unpacked.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem: neither urllib2.quote nor urllib.quote encode the unicode strings arguments

2008-10-05 Thread Miki
Hello,

> things like urllib.quote(u"пиво Müller ") fail with error message:
> : u'\u043f'
>
> Similarly with urllib2.
>
> Anyone got a hint?? I need it to form the URI containing non-ascii chars
.

n = u"пиво Müller "
print urllib.quote(n.encode("utf-8")) -> %D0%BF%D0%B8%D0%B2%D0%BE%20M
%C3%BCller

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sockets code

2008-10-05 Thread Lawrence D'Oliveiro
In message
<[EMAIL PROTECTED]>, Daniel
wrote:

> while data:
> ...
> data = self.rfile.readline().strip()

Interpreting a random string value as a Boolean is a bad idea.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sftp problem!

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, sa6113
wrote:

> host = "LinuxComputerName" (or its Ip)
> port = 22
> 
> and after runing this code I get this error:
> socket.error: (10061, 'Connection refused')

Did you try

sftp LinuxComputerName

just to confirm it's got a listener on port 22?
--
http://mail.python.org/mailman/listinfo/python-list


paramiko.SSHException : No existing session ???

2008-10-05 Thread sa6113

I use this code :

hostname = "192.168.1.4"
username = "test"
port = 22
password = '123456'

# now connect
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect_ex((hostname, port))
except Exception, e:
print 'Connect failed: ' + str(e)
traceback.print_exc()
sys.exit(1)

t = paramiko.Transport(sock)
event = threading.Event()
t.start_client(event)
print "started client"
event.wait(15)

if not t.is_active():
print 'SSH negotiation failed.'
sys.exit(1)
else:
print "SSH negotiation sucessful"

print "doing authentication"
t.auth_password(username, password, event)


event.clear()
event.wait(20)

- 
the result is :
started client
ssh negotiation sucessful
donig authentication

paramiko.SSHException : No existing session

---
I am sure that the username and password exists properly.
what is the problem??


-- 
View this message in context: 
http://www.nabble.com/paramiko.SSHException-%3A-No-existing-session-tp19822257p19822257.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: sftp problem!

2008-10-05 Thread sa6113

what do you mean?


Lawrence D'Oliveiro wrote:
> 
> In message <[EMAIL PROTECTED]>, sa6113
> wrote:
> 
>> host = "LinuxComputerName" (or its Ip)
>> port = 22
>> 
>> and after runing this code I get this error:
>> socket.error: (10061, 'Connection refused')
> 
> Did you try
> 
> sftp LinuxComputerName
> 
> just to confirm it's got a listener on port 22?
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/sftp-problem%21-tp19821106p19823566.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


2to3 refactoring [was Re: Tuple parameter unpacking in 3.x]

2008-10-05 Thread Steven D'Aprano
PEP 3113 offers the following recommendation for refactoring tuple 
arguments:

def fxn((a, (b, c))):
pass

will be translated into:

def fxn(a_b_c):
(a, (b, c)) = a_b_c
pass

and similar renaming for lambdas. 
http://www.python.org/dev/peps/pep-3113/


I'd like to suggest that this naming convention clashes with a very 
common naming convention, lower_case_with_underscores. That's easy enough 
to see if you replace the arguments a, b, c above to something more 
realistic:

def function(vocab_list, (result, flag), max_value)

becomes:

def function(vocab_list, result_flag, max_value)

Function annotations may help here, but not everyone is going to use them 
in the same way, or even in a way that is useful, and the 2to3 tool 
doesn't add annotations.

It's probably impossible to avoid all naming convention clashes, but I'd 
like to suggest an alternative which distinguishes between a renamed 
tuple and an argument name with two words:

def function(vocab_list, (result, flag), max_value):
pass

becomes:

def function(vocab_list, t__result_flag, max_value):
result, flag = t__result_flag
pass

The 't__' prefix clearly marks the tuple argument as different from the 
others. The use of a double underscore is unusual in naming conventions, 
and thus less likely to clash with other conventions. Python users are 
already trained to distinguish single and double underscores. And while 
it's three characters longer than the current 2to3 behaviour, the length 
compares favorably with the original tuple form:

t__result_flag
(result, flag)

What do people think? Is it worth taking this to the python-dev list?


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


paramiko.SSHException : No existing session ???

2008-10-05 Thread sa6113

I use this code :

hostname = "192.168.1.4"
username = "test"
port = 22
password = '123456'

# now connect
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect_ex((hostname, port))
except Exception, e:
print 'Connect failed: ' + str(e)
traceback.print_exc()
sys.exit(1)

t = paramiko.Transport(sock)
event = threading.Event()
t.start_client(event)
print "started client"
event.wait(15)

if not t.is_active():
print 'SSH negotiation failed.'
sys.exit(1)
else:
print "SSH negotiation sucessful"

print "doing authentication"
t.auth_password(username, password, event)


event.clear()
event.wait(20)

- 
the result is :
started client
ssh negotiation sucessful
donig authentication

paramiko.SSHException : No existing session

---
I am sure that the username and password exists properly.
what is the problem??


-- 
View this message in context: 
http://www.nabble.com/paramiko.SSHException-%3A-No-existing-session-tp19823051p19823051.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Tuple parameter unpacking in 3.x

2008-10-05 Thread Martin Geisler
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> On Sat, 04 Oct 2008 22:57:23 +0200, Martin Geisler wrote:
>
> Here's another alternative. Compare:
>
 x = (2, 3)
 (lambda (a,b): a*b)(x)
> 6
>
> with this:
>
 (lambda a,b: a*b)(*x)
> 6

Letting the callbacks take several arguments would definitely be the
nicest syntax, but I'm unfortunately restricted by the Twisted
framework: there all functions in a callback chain return one result
which is passed to the next callback as the first argument. That is why
I do a fair amount of tuple unpacking in my code.

>> From reading the PEP-3113 I got the impression that the author
>> thought that this feature was unused and didn't matter. With this I
>> wish to say that it matters to me.
>
> Alas, I think it's too late. I feel your pain.

Thanks! And I know it's too late, I should have found out about this
earlier :-(

> The final release of Python 3.0 hasn't been made yet. If you really
> care strongly about this, you could write to the python-dev mailing
> list and ask if it is worth trying to change their mind about tuple
> unpacking. They'll almost certainly say no, but there's a chance it
> might be reverted in 3.1.

I can't see this being changed back and forth like that, so I don't
think I'll bother. But thanks for the support.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/.


pgpaYyDaSrqBF.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: code critique requested - just 60 lines

2008-10-05 Thread Lawrence D'Oliveiro
In message
<[EMAIL PROTECTED]>,
Terrence Brannon wrote:

> On Oct 2, 11:56 am, [EMAIL PROTECTED] wrote:
>
>> Terrence Brannon, I suggest you to shorten a lot some of those very
>> long lines.
> 
> yes, I wanted to, but was not sure how to continue a line on the next
> line in Python.

Did you check the manual?


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


Top 10 Things To Look For In A Web Host

2008-10-05 Thread so . sexy . hot69
Top 10 Things To Look For In A Web Host
http://hosting-top10.blogspot.com/2008/07/top-10-things-to-look-for-in-web-host.html

5 Tips To Choose A Domain Name For An Internet Business
http://hosting-top10.blogspot.com/2008/07/5-tips-to-choose-domain-name-for.html
Domain Name Registration - Investments That Reap Benefits (part 2)

http://hosting-top10.blogspot.com/2008/07/domain-name-registration-investments_28.html
Domain Name Registration - Investments That Reap Benefits (part 1)
http://hosting-top10.blogspot.com/2008/07/domain-name-registration-investments.html
Getting One Free Domains - Free Stuff Sites
http://hosting-top10.blogspot.com/2008/07/getting-one-free-domains-free-stuff.html
Domain Names And Their Importance Of Choice
http://hosting-top10.blogspot.com/2008/07/domain-names-and-their-importance-of.html
Web Hosting Advice
http://hosting-top10.blogspot.com/2008/07/web-hosting-advice.html
Web Host Review 2008
http://hosting-top10.blogspot.com/2008/07/web-host-review-2008.html

Tips for finding free webhosting
http://hosting-top10.blogspot.com/2008/07/tips-for-finding-free-webhosting.html
How To Save With Web Hosting Coupons
http://hosting-top10.blogspot.com/2008/07/how-to-save-with-web-hosting-coupons.html
Advantages Of Virtual Dedicated ServersWhen your website grows out of
the facilities provided by shared hosting services, the next natural
progression
http://hosting-top10.blogspot.com/2008/07/advantages-of-virtual-dedicated.html
Finding The Right Web Host In Today's Market
http://hosting-top10.blogspot.com/2008/07/finding-right-web-host-in-todays-market.html
How To Find A Secure And Reliable Hosting?
http://hosting-top10.blogspot.com/2008/07/how-to-find-secure-and-reliable-hosting.html
Windows Or Linux – Which One Is Better Option For Web Hosting?
http://hosting-top10.blogspot.com/2008/07/windows-or-linux-which-one-is-better.html
What Is Reseller Website Hosting?
http://hosting-top10.blogspot.com/2008/07/what-is-reseller-website-hosting.html
Understanding Web-hosting: Selecting An Ideal Server
http://hosting-top10.blogspot.com/2008/07/understanding-web-hosting-selecting.html
Choosing A Cpanel Web Hosting For Your Online Business
http://hosting-top10.blogspot.com/2008/07/choosing-cpanel-web-hosting-for-your.html
Shared Hosting Vs. Dedicated Web Hosting
http://hosting-top10.blogspot.com/2008/07/shared-hosting-vs-dedicated-web-hosting.html
Web Hosting In Seo Services
http://hosting-top10.blogspot.com/2008/07/web-hosting-in-seo-services.html
Shared Web Hosting, Is It Right For You?
http://hosting-top10.blogspot.com/2008/07/shared-web-hosting-is-it-right-for-you.html
How Can Managed Hosting Benefit Me?
http://hosting-top10.blogspot.com/2008/07/how-can-managed-hosting-benefit-me.html
Xoops Hosting
http://hosting-top10.blogspot.com/2008/07/xoops-hosting.html

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


Re: del and sets proposal

2008-10-05 Thread Steven D'Aprano
On Sun, 05 Oct 2008 22:11:38 +1300, Lawrence D'Oliveiro wrote:

> In message <[EMAIL PROTECTED]>, Steven D'Aprano
> wrote:
> 
>> Would it really be "confusing" if sets used the same interface as dicts
>> use? I don't think so. What else could "del aset[x]" mean other than
>> "delete element x"?
> 
> Yes, but "x" in what sense? 

The only sense possible.

If I wrote aset.remove(x) would you ask "what's x, a key or a value?" No 
of course you wouldn't, because the question is nonsense for sets. The 
same goes for "x in aset", "aset.add(x)" and any other set method that 
takes an element as an argument. Why are you singling out del for this 
pretend confusion?


> In dicts it's a key, in sets, shouldn't it
> also be a key and not a value?

That question isn't even meaningful. Sets have elements. The semantics of 
set elements is closer to dictionary keys than to dictionary values:

x in adict  # is key x in dictionary?
x in aset  # is element x in set?

and an early implementation of Python sets used dictionaries, where the 
elements where stored as keys, not values. It makes no sense to treat set 
elements as if they were analogous to dict values.


> Sets have no keys, only values. One might suggest assignment of keys, à
> la array indexes, but that means assigning an ordering to the values,
> whereas sets are explicitly unordered.

Why on earth should "del aset[x]" imply that sets are ordered? Dicts 
aren't ordered. You don't find people going "wibble wibble wibble, I 
don't understand del adict[x] because dicts aren't ordered, what could it 
mean???"


-- 
Steven

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


Re: problem with sockets code

2008-10-05 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote:

> In message
> <[EMAIL PROTECTED]>, Daniel
> wrote:
> 
> > while data:
> > ...
> > data = self.rfile.readline().strip()
> 
> Interpreting a random string value as a Boolean is a bad idea.

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


Re: 2to3 refactoring [was Re: Tuple parameter unpacking in 3.x]

2008-10-05 Thread Aaron "Castironpi" Brady

Steven D'Aprano wrote:
PEP 3113 offers the following recommendation for refactoring tuple 
arguments:


def fxn((a, (b, c))):
pass

will be translated into:

def fxn(a_b_c):
(a, (b, c)) = a_b_c
pass

and similar renaming for lambdas. 
http://www.python.org/dev/peps/pep-3113/



I'd like to suggest that this naming convention clashes with a very 
common naming convention, lower_case_with_underscores. That's easy enough 
to see if you replace the arguments a, b, c above to something more 
realistic:


def function(vocab_list, (result, flag), max_value)

becomes:

def function(vocab_list, result_flag, max_value)

Function annotations may help here, but not everyone is going to use them 
in the same way, or even in a way that is useful, and the 2to3 tool 
doesn't add annotations.


It's probably impossible to avoid all naming convention clashes, but I'd 
like to suggest an alternative which distinguishes between a renamed 
tuple and an argument name with two words:


def function(vocab_list, (result, flag), max_value):
pass

becomes:

def function(vocab_list, t__result_flag, max_value):
result, flag = t__result_flag
pass

The 't__' prefix clearly marks the tuple argument as different from the 
others. The use of a double underscore is unusual in naming conventions, 
and thus less likely to clash with other conventions. Python users are 
already trained to distinguish single and double underscores. And while 
it's three characters longer than the current 2to3 behaviour, the length 
compares favorably with the original tuple form:


t__result_flag
(result, flag)

What do people think? Is it worth taking this to the python-dev list?




There's the possibility that the most important words should go first in 
this case:


result_flag__t

But, I'll admit that other people could have learned different orders of 
scanning words than I, especially depending on their spoken language 
backgrounds.  A poll of the newsgroup isn't exactly academically 
impartial sampling, but there aren't any better ways to make decisions, 
are there?  (I think it would be easy to make either one a habit.)


Here's the other option in the same context:

def function(vocab_list, result_flag__t, max_value):
result, flag = result_flag__t
pass

To be thorough, there's also a trailing double underscore option.

def function(vocab_list, result_flag__, max_value):
result, flag = result_flag__
pass

Which I don't recognize from any other usages, but I defer.  If there 
aren't any, conditionally, I think this is my favorite.


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


Re: lint for Python?

2008-10-05 Thread Pat

Miki wrote:

Hello,


In module one, I have a function:

def foo( host, userid, password ):
 pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called
while the program is running.

pychecker does find these kind of errors.


Before posting my original question, I tried pychecker and it didn't 
catch that error.





I've never used a language that didn't catch that type of error.  I'm
quite surprised that Python is being used by a number of major
companies.  How you catch these types of errors?

By running a large test suite, I highly recommend "nose".


That's something I'll look into after I'm more proficient in Python. 
Currently, I'm learning my way around Python.


Thank you.



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

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


newbie: decorator

2008-10-05 Thread TK

Hi,

I need an understandable Decorator-Example? Who can help? Thanks.

o-o

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


Re: lint for Python?

2008-10-05 Thread Aaron "Castironpi" Brady

Pat wrote:
I've been searching for a good multi-module lint checker for Python and 
I haven't found one yet.


Pylint does a decent job at checking for errors only within a single 
module.


Here's one of my problems.  I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called 
while the program is running.  I don't want that error found at 3AM.


I've never used a language that didn't catch that type of error.  I'm 
quite surprised that Python is being used by a number of major 
companies.  How you catch these types of errors?


I've spoken to tech support at Wing and they weren't aware of a 
multi-module lint but they're considering putting their own lint into 
their IDE.


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



The example you gave is specific.  You could catch that one by hand. 
But, would it hurt, perhaps by causing neglect of other errors; and 
would it be worth the effort?  And, if you're using any dynamics at all, 
catching that one's even in question.


from mod import foo
bar= foo
bar( arg1, arg2 )

It would add difficulty to catching by hand.  Same with variable 
argument lists.


from mod import foo
args= ( arg1, arg2 )
foo( *args )

If you could knock off an error and ignore the false positives, that 
might be worth an afternoon.




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


Re: lint for Python?

2008-10-05 Thread Aaron "Castironpi" Brady

Pat wrote:
I've been searching for a good multi-module lint checker for Python and 
I haven't found one yet.


Pylint does a decent job at checking for errors only within a single 
module.


Here's one of my problems.  I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called 
while the program is running.  I don't want that error found at 3AM.


I've never used a language that didn't catch that type of error.  I'm 
quite surprised that Python is being used by a number of major 
companies.  How you catch these types of errors?


I've spoken to tech support at Wing and they weren't aware of a 
multi-module lint but they're considering putting their own lint into 
their IDE.


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



The example you gave is specific.  You could catch that one by hand.
But, would it hurt, perhaps by causing neglect of other errors; and
would it be worth the effort?  And, if you're using any dynamics at all,
catching that one's even in question.

from mod import foo
bar= foo
bar( arg1, arg2 )

It would add difficulty to catching by hand.  Same with variable
argument lists.

from mod import foo
args= ( arg1, arg2 )
foo( *args )

If you could knock off an error and ignore the false positives, that
might be worth an afternoon.




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


Re: lint for Python?

2008-10-05 Thread Aaron "Castironpi" Brady

Pat wrote:
I've been searching for a good multi-module lint checker for Python and 
I haven't found one yet.


Pylint does a decent job at checking for errors only within a single 
module.


Here's one of my problems.  I have two modules.

In module one, I have a function:

def foo( host, userid, password ):
pass

In module two, I call that function:

foo( userid, password)

lint doesn't find that error and it won't be caught until it's called 
while the program is running.  I don't want that error found at 3AM.


I've never used a language that didn't catch that type of error.  I'm 
quite surprised that Python is being used by a number of major 
companies.  How you catch these types of errors?


I've spoken to tech support at Wing and they weren't aware of a 
multi-module lint but they're considering putting their own lint into 
their IDE.


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



The example you gave is specific.  You could catch that one by hand.
But, would it hurt, perhaps by causing neglect of other errors; and
would it be worth the effort?  And, if you're using any dynamics at all,
catching that one's even in question.

from mod import foo
bar= foo
bar( arg1, arg2 )

It would add difficulty to catching by hand.  Same with variable
argument lists.

from mod import foo
args= ( arg1, arg2 )
foo( *args )

If you could knock off an error and ignore the false positives, that
might be worth an afternoon.




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


Re: newbie: decorator

2008-10-05 Thread Duncan Booth
TK <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I need an understandable Decorator-Example? Who can help? Thanks.
> 
Google? Try typing into the search box: python decorator
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2to3 refactoring [was Re: Tuple parameter unpacking in 3.x]

2008-10-05 Thread Peter Otten
Steven D'Aprano wrote:

> PEP 3113 offers the following recommendation for refactoring tuple
> arguments:
> 
> def fxn((a, (b, c))):
> pass
> 
> will be translated into:
> 
> def fxn(a_b_c):
> (a, (b, c)) = a_b_c
> pass
> 
> and similar renaming for lambdas.
> http://www.python.org/dev/peps/pep-3113/
> 
> 
> I'd like to suggest that this naming convention clashes with a very
> common naming convention, lower_case_with_underscores. That's easy enough
> to see if you replace the arguments a, b, c above to something more
> realistic:
> 
> def function(vocab_list, (result, flag), max_value)
> 
> becomes:
> 
> def function(vocab_list, result_flag, max_value)
> 
> Function annotations may help here, but not everyone is going to use them
> in the same way, or even in a way that is useful, and the 2to3 tool
> doesn't add annotations.
> 
> It's probably impossible to avoid all naming convention clashes, but I'd
> like to suggest an alternative which distinguishes between a renamed
> tuple and an argument name with two words:
> 
> def function(vocab_list, (result, flag), max_value):
> pass
> 
> becomes:
> 
> def function(vocab_list, t__result_flag, max_value):
> result, flag = t__result_flag
> pass
> 
> The 't__' prefix clearly marks the tuple argument as different from the
> others. The use of a double underscore is unusual in naming conventions,
> and thus less likely to clash with other conventions. Python users are
> already trained to distinguish single and double underscores. And while
> it's three characters longer than the current 2to3 behaviour, the length
> compares favorably with the original tuple form:
> 
> t__result_flag
> (result, flag)

Let's see what the conversion tool does:

$ cat tmp.py
g = lambda (a, b): a*b + a_b
$ 2to3 tmp.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: ws_comma
--- tmp.py (original)
+++ tmp.py (refactored)
@@ -1,1 +1,1 @@
-g = lambda (a, b): a*b + a_b
+g = lambda a_b1: a_b1[0]*a_b1[1] + a_b
RefactoringTool: Files that need to be modified:
RefactoringTool: tmp.py

So the current strategy is to add a numerical suffix if a name clash occurs.
The fixer clearly isn't in final state as for functions instead of lambdas
it uses xxx_todo_changeme.

> What do people think? Is it worth taking this to the python-dev list?

I suppose that actual clashes will be rare. If there is no clash a_b is the
best name and I prefer trying it before anything else. 
I don't particularly care about what the fallback should be except that I
think it should stand out a bit more than the current numerical suffix.
xxx1_a_b, xxx2_a_b,... maybe?

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


how to get the thighest bit position in big integers?

2008-10-05 Thread mmgarvey
Hi,

I'm using python to develop some proof-of-concept code for a
cryptographic application. My code makes extended use of python's
native bignum capabilities.

In many cryptographic applications there is the need for a function
'get_highest_bit_num' that returns the position number of the highest
set bit of a given integer. For example:

   get_highest_bit_num( (1 << 159)) == 159
   get_highest_bit_num( (1 << 160) - 1) == 159
   get_highest_bit_num( (1 << 160)) == 160

I implemented this the following way:

def get_highest_bit_num(r):
i = -1
while r > 0:
r >>= 1
i = i + 1
return i

This works, but it is a very unsatisfying solution, because it is so
slow.

My second try was using the math.log function:

import math
r = (1 << 160) - 1
print highest_bit_num(r)  # prints out 159
print math.floor(math.log(r, 2))  # prints out 160.0

We see that math.log can only serve as a heuristic for the highest bit
position. For small r, for example r = (1 << 16) - 1, the result from
math.log(, 2) is correct, for big r it isn't any more.

My question to the group: Does anyone know of a non-hackish way to
determine the required bit position in python? I know that my two
ideas
can be combined to get something working. But is there a *better* way,
that isn't that hackish?

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


Re: Python 2.6, GUI not working on vista?

2008-10-05 Thread Thorsten Kampe
* Lawrence D'Oliveiro (Sun, 05 Oct 2008 22:13:46 +1300)
> In message <[EMAIL PROTECTED]>, Michel Claveau - NoSpam
> SVP ; merci wrote:
> 
> > Another way is to de-activate UAC.
> 
> Please don't be stupid!

He's not stupid. Disabling UAC is the recommended way to get rid of 
these problems.

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


Re: Tuple parameter unpacking in 3.x

2008-10-05 Thread Terry Reedy

Martin Geisler wrote:

Steven D'Aprano <[EMAIL PROTECTED]> writes:



From reading the PEP-3113 I got the impression that the author
thought that this feature was unused and didn't matter.


And that there were good alternatives, and that there were technical 
reasons why maintaining the feature in the face of other arguments 
options would be a nuisance.


>>> With this I wish to say that it matters to me.

Alas, I think it's too late. I feel your pain.


Thanks! And I know it's too late, I should have found out about this
earlier :-(


For future reference, the time to have said something would have been 
during the 3 month alpha phase, which is for testing feature and api 
changes.  I suspect, from reading the pydev discussion, that the answer 
still would have been to either use a def statement and add the unpack 
line or to subscript the tuple arg to stick with lambda expressions. 
But who knows?


tjr

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


Re: del and sets proposal

2008-10-05 Thread Bruno Desthuilliers

Steven D'Aprano a écrit :

On Sat, 04 Oct 2008 18:36:28 +0200, Bruno Desthuilliers wrote:


Yes I know that sets have a remove method (like lists), but since
dictionaries don't have a remove method, shouldn't sets behave like
more like dictionaries and less like lists?  IMHO del for sets is quite
intuitive.

For lists, del a[x] means 'remove item at index x'. For dicts, del a[x]
means 'remove key:value pair which key is x'. In both cases, del a[x] is
meaningful because a[x] is meaningful. Sets are neither ordered nor
indexed, and can't be subscripted. So "del aset[x]" is IMHO as
meaningless as 'aset[x]' is. Using this syntax for an operation which
semantic is the same as alist.remove(x) would be at best inconsistent
and confusing.


Consider the mutable built-in collections set, dict and list, and how 
they remove elements:


aset.remove(x)
alist.remove(x)
del adict[x]


This last one doesn't remove the key,value pair(s) where *the value* is 
x, it removes the key,value pair where the *key* is x - which is 
semantically very different, just like alist.remove(x) is very different 
from del alist[x].


Would it really be "confusing" if sets used the same interface as dicts 
use? I don't think so.


I do. In both dict.__delitem__ and list.__delitem__, the argument is an 
index (whether arbitrary key or positional index), not the value of the 
element to remove. wrt/ consistency, i'd rather have dict growing a 
remove(value) method with same semantic as list.remove and set.remove 
than abuse subscript syntax to duplicate an existing API which has a 
very different semantic.



What else could "del aset[x]" mean


As far as I'm concerned, since sets are not subscriptables, del aset[x] 
just can't have any meaning.


other than 
"delete element x"?


Going this way, 'del adict[x]' should mean 'remove key,value pair(s) 
where value is x' and 'del alist[x]' should be an alias for alist.remove(x).



Lists are the odd one out, because del alist[x] is used to remove the 
element at position x, rather than removing an element x.


Nope. It's perfectly consistent with dicts, where del adict[x] is used 
to remove element associated to key x, not to remove element with value 
x. Lists and dicts are both indexed collections, list being indexed by 
position and dicts by key. sets are not indexed.


(snip remaining - I could only keep on repeating the same thing).
--
http://mail.python.org/mailman/listinfo/python-list


Re: del and sets proposal

2008-10-05 Thread Bruno Desthuilliers

Steven D'Aprano a écrit :

On Sun, 05 Oct 2008 22:11:38 +1300, Lawrence D'Oliveiro wrote:


In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:


Would it really be "confusing" if sets used the same interface as dicts
use? I don't think so. What else could "del aset[x]" mean other than
"delete element x"?
Yes, but "x" in what sense? 


The only sense possible.

If I wrote aset.remove(x) would you ask "what's x, a key or a value?" No 
of course you wouldn't, because the question is nonsense for sets.


And also because the semantic of 'remove' is already defined for lists.

The 
same goes for "x in aset", "aset.add(x)" and any other set method that 
takes an element as an argument. Why are you singling out del for this 
pretend confusion?




In dicts it's a key, in sets, shouldn't it
also be a key and not a value?


That question isn't even meaningful. Sets have elements. The semantics of 
set elements is closer to dictionary keys than to dictionary values:


x in adict  # is key x in dictionary?


This is a pragmatic design choice - just like the fact that default 
iteration over dicts is made on keys, not values - due to the most 
frequent use case. FWIW, this has been debated quite a few times here.



x in aset  # is element x in set?



and an early implementation of Python sets used dictionaries,


And this is only an implementation detail.

where the 
elements where stored as keys, not values. It makes no sense to treat set 
elements as if they were analogous to dict values.


Would it make sense to treat them as if they where list values ?-)




Sets have no keys, only values. One might suggest assignment of keys, à
la array indexes, but that means assigning an ordering to the values,
whereas sets are explicitly unordered.


Why on earth should "del aset[x]" imply that sets are ordered? Dicts 
aren't ordered. You don't find people going "wibble wibble wibble, I 
don't understand del adict[x] because dicts aren't ordered, what could it 
mean???"


s/ordered/indexed/, and it makes perfect sense. Dicts and lists are 
indexed, sets are not.



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


Re: newbie: decorator

2008-10-05 Thread Bruno Desthuilliers

TK a écrit :

Hi,

I need an understandable Decorator-Example? Who can help? Thanks.


What don't you understand in decorators ?
--
http://mail.python.org/mailman/listinfo/python-list


The difference sports gambling online sport book

2008-10-05 Thread shiva
webpage -  http;//elemotor.blogspot.com/




The difference sports gambling online sport book


The difference sports gambling online sport book no doubt partly
sports gambling
online sport book to the fact sports gambling online sport book our
first
glimpses sports gambling online sport book of Hellenic and of sports
gambling
--
http://mail.python.org/mailman/listinfo/python-list


Re: One class per file?

2008-10-05 Thread Bruno Desthuilliers

greg a écrit :

Bruno Desthuilliers wrote:

Nope. But IIRC, one-class-per-file helps saving on compile/link time. 
A problem we don't have with dynamic languages !-)


That's mostly true. Although I've noticed that if I have
a very large .py file, it can take a noticeable number
of moments to regenerate the .pyc after I've changed
something.


Indeed - and "very large" files are a maintainance nightmare anyway.

The point was that with C++, when you edit a file, you not only have to 
recompile this file, you *also* have to relink *everything* depending on 
what's defined in this file. So the saving is mostly on on (re)linking 
time.

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


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Gary Herron
[EMAIL PROTECTED] wrote:
> Hi,
>
> I'm using python to develop some proof-of-concept code for a
> cryptographic application. My code makes extended use of python's
> native bignum capabilities.
>
> In many cryptographic applications there is the need for a function
> 'get_highest_bit_num' that returns the position number of the highest
> set bit of a given integer. For example:
>
>get_highest_bit_num( (1 << 159)) == 159
>get_highest_bit_num( (1 << 160) - 1) == 159
>get_highest_bit_num( (1 << 160)) == 160
>   


How about a binary search? 

>>> from bisect import bisect
>>> BITS = [1<>> bisect(BITS, 1<<159)
159
>>> bisect(BITS, 1<<160-1)
159
>>> bisect(BITS, 1<<160)
160
>>>

I have no clue if this is faster or not.  The comparison function used
in the search is (potentially) slow, but the search is O(log n) on the
number of bits rather than O(n), so its worth a test.


If you run timing test, let us know the results.

Gary Herron



> I implemented this the following way:
>
> def get_highest_bit_num(r):
> i = -1
> while r > 0:
> r >>= 1
> i = i + 1
> return i
>
> This works, but it is a very unsatisfying solution, because it is so
> slow.
>
> My second try was using the math.log function:
>
> import math
> r = (1 << 160) - 1
> print highest_bit_num(r)  # prints out 159
> print math.floor(math.log(r, 2))  # prints out 160.0
>
> We see that math.log can only serve as a heuristic for the highest bit
> position. For small r, for example r = (1 << 16) - 1, the result from
> math.log(, 2) is correct, for big r it isn't any more.
>
> My question to the group: Does anyone know of a non-hackish way to
> determine the required bit position in python? I know that my two
> ideas
> can be combined to get something working. But is there a *better* way,
> that isn't that hackish?
>
> cheers,
> mmg
> --
> http://mail.python.org/mailman/listinfo/python-list
>   

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


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> My question to the group: Does anyone know of a non-hackish way to
> determine the required bit position in python? I know that my two
> ideas
> can be combined to get something working. But is there a *better* way,
> that isn't that hackish?
> 
How about using the hex representation of the value?

OFFSET = dict(("%x"%i, int(c)) for i,c in enumerate("5433"))
def get_highest_bit_num(r):
s = "%x"%r
return len(s) * 4 - OFFSET[s[0]]
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Scott David Daniels

[EMAIL PROTECTED] wrote:

I'm using python to develop some proof-of-concept code for a
cryptographic application. My code makes extended use of python's
native bignum capabilities.

In many cryptographic applications there is the need for a function
'get_highest_bit_num' that returns the position number of the highest
set bit of a given integer. For example:
   get_highest_bit_num( (1 << 159)) == 159
...
def get_highest_bit_num(r):
i = -1
while r:
r >>= 1
i += 1
return i
My second try was using the math.log function:
print math.floor(math.log(r, 2))  # prints out 160.0


Since floating point has to identify the position of the highest bit,
you can use that hardware to "quickly" get to the highest bit.  IEEE
has the mantissa .5 <= mantissa < 1., but some other floating point
formats treated the mantissa in different ranges.  This should work
for anything where the exponent is truly a "binary point." In an older
IBM floating point format, for example, the exponent was a "hexadecimal
point," so the exponent only went up 1 when you multiplied by 16.


EXP_OF_ONE = math.frexp(1.0)[1]

def high_bit(value):
'''Find the highest order bit of a positive integer <= maxfloat'''
assert value > 0
return math.frexp(value)[1] - EXP_OF_ONE

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


PyOpenGL double-buffered hardware surface

2008-10-05 Thread Clay Hobbs
How do I create a double-buffered hardware surface with PyOpenGL?  I
knew how to once, but forgot.

--Ratfink

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


gdbm threadsafeness

2008-10-05 Thread Eric S. Johansson
how thread safe is the gdbm module?
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Terry Reedy

[EMAIL PROTECTED] wrote:

Hi,

I'm using python to develop some proof-of-concept code for a
cryptographic application. My code makes extended use of python's
native bignum capabilities.

In many cryptographic applications there is the need for a function
'get_highest_bit_num' that returns the position number of the highest
set bit of a given integer. For example:

   get_highest_bit_num( (1 << 159)) == 159
   get_highest_bit_num( (1 << 160) - 1) == 159
   get_highest_bit_num( (1 << 160)) == 160

I implemented this the following way:

def get_highest_bit_num(r):
i = -1
while r > 0:
r >>= 1
i = i + 1
return i

This works, but it is a very unsatisfying solution, because it is so
slow.


One alternative is to compare r against successive larger powers of 2, 
starting with 2**0 == 1.  Given that you have p=2**(n-1), you could test 
whether generating 2**n for large n is faster as 1

CALL FOR PAPERS: International Journal of Imaging

2008-10-05 Thread [EMAIL PROTECTED]
-

(Apologies for cross-posting)

International Journal of Imaging (IJI)
http://www.ceser.res.in/iji.html

ISSN 0974-0627

We would appreciate if you could distribute this information by your
colleagues and co-workers.
-

CALL FOR PAPERS

The main aim of the International Journal of Imaging (ISSN 0974-0627)
is to publish refereed, well-written original research articles, and
studies that describe the latest research and developments in the area
of imaging.
This is a broad-based journal covering all branches of imaging, its
application in technology and interdisciplinary research.
International Journal of Imaging (IJI) is a peer-reviewed online
journal and is published in Spring and Autumn i.e. two times a year.
The areas of interest include (but are not limited to):

- Signal and Image Processing,
- Image Acquisition and Calibration,
- Pattern Analysis and Recognition,
- Feature Extraction and Detection,
- Filters, Algorithms, Video Coding and Watermarking,
- Video Processing and Analysis,
- Reconstruction, Restoration, and Enhancement,
- Image Understanding, Registration, Tracking, Segmentation and
Classification,
- 3D Vision,
- Statistical Imaging & Tomography,
- Face Recognition and Facial Expression Analysis,
- Human-Machine Interfaces,
- Virtual Reality and Augmented Reality,
- Inverse Problem & Imaging,
- Medical Imaging,
- Software Development for Image Processing and Analysis,
- Computer Aided Diagnosis, Surgery, Therapy, and Treatment,
- Computational Bioimaging and Visualization,
- Telemedicine Systems and their Applications, and
- Software Development.

Manuscripts can also be sent to the Editor-in-Chief International
Journal of Imaging, via e-mail (tavares[at]fe.up.pt). Detailed
instructions on how to prepare your manuscript are available at Author
Instructions http://www.ceser.res.in/iji.html.

Sincerely yours,

João Manuel R. S. Tavares
(University of Porto, Portugal)
Editor-in-Chief
International Journal of Imaging (IJI)
http://www.ceser.res.in/iji.html
E-mail: tavares[at]fe.up.pt
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyOpenGL double-buffered hardware surface

2008-10-05 Thread Mike C. Fletcher

Clay Hobbs wrote:

How do I create a double-buffered hardware surface with PyOpenGL?  I
knew how to once, but forgot.

  
Depends on your GUI library, most of them have a flag-set that you pass 
to the initializer of the OpenGL-holding widget.  If you're using 
Pygame, see Pygame's display module.  If wxPython, see their GLcanvas 
object.  If GLUT, see glutInitDisplayMode, etceteras.


Good luck,
Mike

--

 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://www.vrplumber.com
 http://blog.vrplumber.com

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


Python 2.6: Determining if a method is inherited

2008-10-05 Thread Fuzzyman
Hello all,

I may well be being dumb (it has happened before), but I'm struggling
to fix some code breakage with Python 2.6.

I have some code that looks for the '__lt__' method on a class:

if hasattr(clr, '__lt__'):

However - in Python 2.6 object has grown a default implementation of
'__lt__', so this test always returns True.

>>> class X(object): pass
...
>>> X.__lt__

>>> X.__lt__ == object.__lt__
False

So how do I tell if the X.__lt__ is inherited from object? I can look
in the '__dict__' of the class - but that doesn't tell me if X
inherits '__lt__' from a base class other than object. (Looking inside
the method wrapper repr with a regex is not an acceptable answer...)

Some things I have tried:


>>> X.__lt__.__self__

>>> dir(X.__lt__)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__',
'__format__', '__getattribute__', '__hash__', '__init__', '__name__',
'__new__', '__objclass__', '__reduce__', '__reduce_ex__', '__repr__',
'__self__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__']
>>> X.__lt__.__func__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'method-wrapper' object has no attribute '__func__'

Michael Foord
--
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Aaron "Castironpi" Brady

Duncan Booth wrote:

[EMAIL PROTECTED] wrote:


My question to the group: Does anyone know of a non-hackish way to
determine the required bit position in python? I know that my two
ideas
can be combined to get something working. But is there a *better* way,
that isn't that hackish?


How about using the hex representation of the value?

OFFSET = dict(("%x"%i, int(c)) for i,c in enumerate("5433"))
def get_highest_bit_num(r):
s = "%x"%r
return len(s) * 4 - OFFSET[s[0]]
--
http://mail.python.org/mailman/listinfo/python-list



You can replace the dict if it's faster.

OFFSET= tuple( int(x) for x in "5433" )
def get_highest_bit_num(r):
s = "%x"%r
return len(s) * 4 - OFFSET[int(s[0],16)]

P.S.  Back home, this sort of 'nitpicking' would be judged 
unconstructive.  Worth pointing out, or not worth saying?


P.S.S.  'Thighest' bit?  I thought the spam filters would catch that.

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


Python 2.6 / 3.0: Determining if a method is inherited

2008-10-05 Thread Fuzzyman
Hello all,

I may well be being dumb (it has happened before), but I'm struggling
to fix some code breakage with Python 2.6.

I have some code that looks for the '__lt__' method on a class:

if hasattr(clr, '__lt__'):

However - in Python 2.6 object has grown a default implementation of
'__lt__', so this test always returns True.

>>> class X(object): pass
...
>>> X.__lt__

>>> X.__lt__ == object.__lt__
False

So how do I tell if the X.__lt__ is inherited from object? I can look
in the '__dict__' of the class - but that doesn't tell me if X
inherits '__lt__' from a base class other than object. (Looking inside
the method wrapper repr with a regex is not an acceptable answer...)

Some things I have tried:

>>> X.__lt__.__self__

>>> dir(X.__lt__)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__',
'__format__', '__getattribute__', '__hash__', '__init__', '__name__',
'__new__', '__objclass__', '__reduce__', '__reduce_ex__', '__repr__',
'__self__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__']
>>> X.__lt__.__func__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'method-wrapper' object has no attribute '__func__'


Hmmm... I can get this working with Python 2.6 with:

if '__lt__' in dir(cls):

The default implementation of '__lt__' doesn't appear in the dir of
classes. However this fails with Python 3 where the default
implementation *does* appear in the output of 'dir'. Any suggestions?

Michael Foord
--
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6: Determining if a method is inherited

2008-10-05 Thread Valentino Volonghi aka Dialtone
Fuzzyman <[EMAIL PROTECTED]> wrote:

> So how do I tell if the X.__lt__ is inherited from object? I can look

I don't have python 2.6 installed so I can't try but what I think could
work is:

>>> class Foo(object):
... def hello(self):
... pass
... 
>>> class Bla(Foo):
... def hello(self):
... pass
... 
>>> class Baz(Foo):
... pass
... 
>>> Baz.hello.im_func

>>> Bla.hello.im_func

>>> Foo.hello.im_func

>>> Foo.hello.im_func is Baz.hello.im_func
True
>>> Foo.hello.im_func is Bla.hello.im_func
False

Which to me also makes sense. If it's inherited I expect it to be the
very same function object of one of the bases (which you can get with
inspect.getmro(Clazz)). On the other end if you override it it's not the
same function object so it won't return True when applied to 'is'.

HTH

-- 
Valentino Volonghi aka Dialtone
http://stacktrace.it -- Aperiodico di resistenza informatica
Blog: http://www.twisted.it/
Public Beta: http://www.adroll.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: del and sets proposal

2008-10-05 Thread Aaron "Castironpi" Brady

Bruno Desthuilliers wrote:

Steven D'Aprano a écrit :

On Sat, 04 Oct 2008 18:36:28 +0200, Bruno Desthuilliers wrote:

Lists are the odd one out, because del alist[x] is used to remove the 
element at position x, rather than removing an element x.


Nope. It's perfectly consistent with dicts, where del adict[x] is used 
to remove element associated to key x, not to remove element with value 
x. Lists and dicts are both indexed collections, list being indexed by 
position and dicts by key. sets are not indexed.


(snip remaining - I could only keep on repeating the same thing).
--
http://mail.python.org/mailman/listinfo/python-list


Which one has seniority?  It's somewhat arbitrary which of 'pop' and 
'remove' have which meanings in lists.  You can 'remove' on index or 
value in lists, key or value in dicts, and only value in sets.


I agree that you don't pass an 'index' to 'del' in dicts, you pass a 
key.  Does the OP also hold that dicts should grow a 'remove' method to 
remove a value?


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


Re: Python 2.6: Determining if a method is inherited

2008-10-05 Thread Aaron "Castironpi" Brady

Fuzzyman wrote:

Hello all,

I may well be being dumb (it has happened before), but I'm struggling
to fix some code breakage with Python 2.6.

I have some code that looks for the '__lt__' method on a class:

if hasattr(clr, '__lt__'):

However - in Python 2.6 object has grown a default implementation of
'__lt__', so this test always returns True.


class X(object): pass

...

X.__lt__



X.__lt__ == object.__lt__

False

So how do I tell if the X.__lt__ is inherited from object? I can look
in the '__dict__' of the class - but that doesn't tell me if X
inherits '__lt__' from a base class other than object. (Looking inside
the method wrapper repr with a regex is not an acceptable answer...)


They're of different types.  I'm not sure how much you could use that, 
or how reliable it is.


>>> class A( object ):
... pass
...
>>> class B( object ):
... def __lt__( self, other ):
... pass
...
>>> hasattr( A, '__lt__' )
True
>>> hasattr( B, '__lt__' )
True
>>> A.__lt__

>>> B.__lt__

>>>

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


Python 2.6 / 3.0: Determining if a method is inherited (Fixed)

2008-10-05 Thread Fuzzyman
Hello all,

Sorry - my messages aren't showing up via google groups, so I'm kind
of posting on faith...

Anyway, I solved my problem (I think)...

import sys

if sys.version_info[0] == 3:
def _has_method(cls, name):
for B in cls.__mro__:
if B is object:
continue
if name in B.__dict__:
return True
return False
else:
def _has_method(cls, name):
for B in cls.mro():
if B is object:
continue
if name in B.__dict__:
return True
return False

I've reposted the question that this is the answer to below...


I may well be being dumb (it has happened before), but I'm struggling
to fix some code breakage with Python 2.6.

I have some code that looks for the '__lt__' method on a class:

if hasattr(clr, '__lt__'):

However - in Python 2.6 object has grown a default implementation of
'__lt__', so this test always returns True.

>>> class X(object): pass
...
>>> X.__lt__

>>> X.__lt__ == object.__lt__
False

So how do I tell if the X.__lt__ is inherited from object? I can look
in the '__dict__' of the class - but that doesn't tell me if X
inherits '__lt__' from a base class other than object. (Looking inside
the method wrapper repr with a regex is not an acceptable answer...)

Some things I have tried:

>>> X.__lt__.__self__

>>> dir(X.__lt__)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__',
'__format__', '__getattribute__', '__hash__', '__init__', '__name__',
'__new__', '__objclass__', '__reduce__', '__reduce_ex__', '__repr__',
'__self__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__']
>>> X.__lt__.__func__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'method-wrapper' object has no attribute '__func__'


Hmmm... I can get this working with Python 2.6 with:

if '__lt__' in dir(cls):

The default implementation of '__lt__' doesn't appear in the dir of
classes. However this fails with Python 3 where the default
implementation *does* appear in the output of 'dir'. Any suggestions?

Michael Foord
--
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Simple GUI design in Python

2008-10-05 Thread xkenneth
All,

I've posted some slides on my blog (xkenneth.blogspot.com)
detailing some simple ways to describe GUI apps in python. Please let
me know what you think.

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


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Duncan Booth
"Aaron \"Castironpi\" Brady" <[EMAIL PROTECTED]> wrote:

>> OFFSET = dict(("%x"%i, int(c)) for i,c in enumerate("5433"))
>> def get_highest_bit_num(r):
>>  s = "%x"%r
>>  return len(s) * 4 - OFFSET[s[0]]
> 
> You can replace the dict if it's faster.
> 
> OFFSET= tuple( int(x) for x in "5433" )
> def get_highest_bit_num(r):
>  s = "%x"%r
>  return len(s) * 4 - OFFSET[int(s[0],16)]
> 
> P.S.  Back home, this sort of 'nitpicking' would be judged 
> unconstructive.  Worth pointing out, or not worth saying?
> 
You could have answered your own question fairly quickly using the 'timeit' 
module. In this case you trade off the dict lookup for a global name lookup 
and a function call so I'd expect you would have made it slower and indeed 
it seems to be about 30-40% slower than mine.

The math.floor/math.log version isn't so good for small values, but both 
string versions seem to slow down dramatically somewhere around 526 bits 
(2.8uS suddenly jumps to about 4us while the math version stays roughly 
steady around 3.2uS).
--
http://mail.python.org/mailman/listinfo/python-list


Problem with lower() for unicode strings in russian

2008-10-05 Thread Alexey Moskvin
Hi!
I have a set of strings (all letters are capitalized) at utf-8,
russian language. I need to lower it, but
my_string.lower(). Doesn't work.
See sample script:
# -*- coding: utf-8 -*-
[skip]
s1 = self.title
s2 = self.title.lower()
print s1 == s2

returns true.
I have no problems with lower() for english letters:, or with
something like this:
u'russian_letters_here'.lower(), but I don't need constants, I need to
modify variables, but there is no any changs, when I apply lower()
function to mine strings.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritance but only partly?

2008-10-05 Thread George Sakkis
On Oct 3, 11:56 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Fri, 03 Oct 2008 03:32:52 -0700, Michele Simionato wrote:
> > IMO, if you have methods that you want to use in different classes, this
> > is hint that
> > you are in need of generic functions. See this blog post for an example:
>
> >http://www.artima.com/weblogs/viewpost.jsp?thread=237764
>
> That's a very interesting article, but I'm afraid I don't understand what
> makes them "generic functions" as opposed to just functions. Your simple
> generic example:
>
> from pkgutil import simplegeneric
>
> @simplegeneric
> def print_out(self, text, *args):
>     if args:
>         text = text % args
>     print >> self.stdout, text
> # and similar for print_err and readln_in
>
> class FileOut(object):
>     def __init__(self):
>         self.stdout = file('out.txt', 'w')
>
> print_out(FileOut(), 'writing on file') # prints a line on out.txt
>
> doesn't seem to do anything extra that the following would do:
>
> def print_out2(obj, text, *args):
>     if args:
>         text = text % args
>     print >> obj.stdout, text
>
> class FileOut2(object):
>     def __init__(self):
>         self.stdout = file('out2.txt', 'w')
>
> print_out(FileOut2(), 'writing on file')
>
> What's the difference?
>
> --
> Steven

Did you read the next section, "extending generic functions" ?

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


Re: Problem with lower() for unicode strings in russian

2008-10-05 Thread Diez B. Roggisch

Alexey Moskvin schrieb:

Hi!
I have a set of strings (all letters are capitalized) at utf-8,
russian language. I need to lower it, but
my_string.lower(). Doesn't work.
See sample script:
# -*- coding: utf-8 -*-
[skip]
s1 = self.title
s2 = self.title.lower()
print s1 == s2

returns true.
I have no problems with lower() for english letters:, or with
something like this:
u'russian_letters_here'.lower(), but I don't need constants, I need to
modify variables, but there is no any changs, when I apply lower()
function to mine strings.


Can you give a concrete example? I doubt that there is anything 
different between lowering a unicode object given as literal or acquired 
somewhere else. And because my russian skills equal my chinese - total 
of zero - I can't create a test myself :)

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


Re: Problem with lower() for unicode strings in russian

2008-10-05 Thread Martin v. Löwis
> I have a set of strings (all letters are capitalized) at utf-8,

That's the problem. If these are really utf-8 encoded byte strings,
then .lower likely won't work. It uses the C library's tolower API,
which works on a byte level, i.e. can't work for multi-byte encodings.

What you need to do is to operate on Unicode strings. I.e. instead
of

  s.lower()

do

  s.decode("utf-8").lower()

or (if you need byte strings back)

  s.decode("utf-8").lower().encode("utf-8")

If you find that you write the latter, I recommend that you redesign
your application. Don't use byte strings to represent text, but use
Unicode strings all the time, except at the system boundary (where
you decode/encode as appropriate).

There are some limitations with Unicode .lower also, but I don't
think they apply to Russian (specifically, SpecialCasing.txt is
not considered).

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


Re: Python 2.6: Determining if a method is inherited

2008-10-05 Thread Fuzzyman
On Oct 5, 8:15 pm, [EMAIL PROTECTED] (Valentino
Volonghi aka Dialtone) wrote:
> Fuzzyman <[EMAIL PROTECTED]> wrote:
> > So how do I tell if the X.__lt__ is inherited from object? I can look
>
> I don't have python 2.6 installed so I can't try but what I think could
> work is:
>
> >>> class Foo(object):
>
> ...     def hello(self):
> ...         pass
> ...>>> class Bla(Foo):
>
> ...     def hello(self):
> ...         pass
> ...>>> class Baz(Foo):
>
> ...     pass
> ...>>> Baz.hello.im_func
>
> >>> Bla.hello.im_func
>
> >>> Foo.hello.im_func
>
> >>> Foo.hello.im_func is Baz.hello.im_func
> True
> >>> Foo.hello.im_func is Bla.hello.im_func
>
> False
>


Nope:

Python 2.6 (trunk:66714:66715M, Oct  1 2008, 18:36:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class X(object): pass
...
>>> X.__lt__.im_func
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'method-wrapper' object has no attribute 'im_func'
>>>

What I went with in the end:

import sys as _sys

if _sys.version_info[0] == 3:
def _has_method(cls, name):
for B in cls.__mro__:
if B is object:
continue
if name in B.__dict__:
return True
return False
else:
def _has_method(cls, name):
for B in cls.mro():
if B is object:
continue
if name in B.__dict__:
return True
return False

See this page for why I needed it:

http://www.voidspace.org.uk/python/weblog/arch_d7_2008_10_04.shtml#e1018

Michael

> Which to me also makes sense. If it's inherited I expect it to be the
> very same function object of one of the bases (which you can get with
> inspect.getmro(Clazz)). On the other end if you override it it's not the
> same function object so it won't return True when applied to 'is'.
>
> HTH
>
> --
> Valentino Volonghi aka Dialtonehttp://stacktrace.it-- Aperiodico di 
> resistenza informatica
> Blog:http://www.twisted.it/
> Public Beta:http://www.adroll.com/

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


Re: Simple GUI design in Python

2008-10-05 Thread Stef Mientki

xkenneth wrote:

All,

I've posted some slides on my blog (xkenneth.blogspot.com)
detailing some simple ways to describe GUI apps in python. Please let
me know what you think.
  

Did you look at the pdf file,
to me a lot of information is missing :-(
cheers,
Stef Mientki

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


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


Buy carisoprodol online

2008-10-05 Thread eqweqwe
buy cheap carisoprodol online
.
.
.
Enough to seek Carisoprodol! You've already found the best site where
you can purchase Carisoprodol for lowest price!
To order Carisoprodol without prescription visit link below!

http://med247.us/?p=Carisoprodol

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
 uy cheap carisoprodol online by cheap carisoprodol online bu cheap
carisoprodol online buy heap carisoprodol online buy ceap carisoprodol
online buy chap carisoprodol online buy chep carisoprodol online buy
chea carisoprodol online buy cheap arisoprodol online buy cheap
crisoprodol online buy cheap caisoprodol online buy cheap carsoprodol
online buy cheap carioprodol online buy cheap carisprodol online buy
cheap carisorodol online buy cheap carisopodol online buy cheap
carisoprdol online buy cheap carisoprool online buy cheap carisoprodl
online buy cheap carisoprodo online buy cheap carisoprodol nline buy
cheap carisoprodol oline buy cheap carisoprodol onine buy cheap
carisoprodol onlne buy cheap carisoprodol onlie buy cheap carisoprodol
onlin bbuy cheap carisoprodol online buuy cheap carisoprodol online
buyy cheap carisoprodol online buy ccheap carisoprodol online buy
chheap carisoprodol online buy cheeap carisoprodol online buy cheaap
carisoprodol online buy cheapp carisoprodol online buy cheap
ccarisoprodol online buy cheap caarisoprodol online buy cheap
carrisoprodol online buy cheap cariisoprodol online buy cheap
carissoprodol online buy cheap carisooprodol online buy cheap
carisopprodol online buy cheap carisoprrodol online buy cheap
carisoproodol online buy cheap carisoproddol online buy cheap
carisoprodool online buy cheap carisoprodoll online buy cheap
carisoprodol oonline buy cheap carisoprodol onnline buy cheap
carisoprodol onlline buy cheap carisoprodol onliine buy cheap
carisoprodol onlinne buy cheap carisoprodol onlinee uby cheap
carisoprodol online byu cheap carisoprodol online buy cheap
carisoprodol online buy hceap carisoprodol online buy cehap
carisoprodol online buy chaep carisoprodol online buy chepa
carisoprodol online buy cheap carisoprodol online buy cheap
acrisoprodol online buy cheap craisoprodol online buy cheap
cairsoprodol online buy cheap carsioprodol online buy cheap
cariosprodol online buy cheap carisporodol online buy cheap
carisorpodol online buy cheap carisopordol online buy cheap
carisoprdool online buy cheap carisoproodl online buy cheap
carisoprodlo online buy cheap carisoprodol online buy cheap
carisoprodol noline buy cheap carisoprodol olnine buy cheap
carisoprodol onilne buy cheap carisoprodol onlnie buy cheap
carisoprodol onlien buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online buy cheap
carisoprodol online buy cheap carisoprodol online
--
http://mail.python.org/mailman/listinfo/python-list


Buy Soma online

2008-10-05 Thread sjmacdonaldjail
buy cheap soma online
.
.
.
Enough to seek Soma! You've already found the best site where
you can purchase Soma for lowest price!
To order Soma without prescription visit link below!

http://med247.us/?p=soma

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
 uy cheap soma online by cheap soma online bu cheap soma online buy
heap soma online buy ceap soma online buy chap soma online buy chep
soma online buy chea soma online buy cheap oma online buy cheap sma
online buy cheap soa online buy cheap som online buy cheap soma nline
buy cheap soma oline buy cheap soma onine buy cheap soma onlne buy
cheap soma onlie buy cheap soma onlin bbuy cheap soma online buuy
cheap soma online buyy cheap soma online buy ccheap soma online buy
chheap soma online buy cheeap soma online buy cheaap soma online buy
cheapp soma online buy cheap ssoma online buy cheap sooma online buy
cheap somma online buy cheap somaa online buy cheap soma oonline buy
cheap soma onnline buy cheap soma onlline buy cheap soma onliine buy
cheap soma onlinne buy cheap soma onlinee uby cheap soma online byu
cheap soma online buy cheap soma online buy hceap soma online buy
cehap soma online buy chaep soma online buy chepa soma online buy
cheap soma online buy cheap osma online buy cheap smoa online buy
cheap soam online buy cheap soma online buy cheap soma noline buy
cheap soma olnine buy cheap soma onilne buy cheap soma onlnie buy
cheap soma onlien buy cheap soma online buy cheap soma online buy
cheap soma online buy cheap soma online buy cheap soma online buy
cheap soma online buy cheap soma online buy cheap soma online buy
cheap soma online buy cheap soma online buy cheap soma online buy
cheap soma online buy cheap soma online buy cheap soma online buy
cheap soma online buy cheap soma online buy cheap soma online buy
cheap soma online buy cheap soma online
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the thighest bit position in big integers?

2008-10-05 Thread Terry Reedy

Scott David Daniels wrote:


Since floating point has to identify the position of the highest bit,
you can use that hardware to "quickly" get to the highest bit.  IEEE
has the mantissa .5 <= mantissa < 1., but some other floating point
formats treated the mantissa in different ranges.  This should work
for anything where the exponent is truly a "binary point." In an older
IBM floating point format, for example, the exponent was a "hexadecimal
point," so the exponent only went up 1 when you multiplied by 16.

EXP_OF_ONE = math.frexp(1.0)[1]

def high_bit(value):
'''Find the highest order bit of a positive integer <= maxfloat'''
assert value > 0
return math.frexp(value)[1] - EXP_OF_ONE


Your point, that taking floor(log2(x)) is redundant, is a good catch. 
However, you should have added 'untested' ;-).  When value has more 
significant bits than the fp mantissa can hold, this expression can be 1 
off (but no more, I assume).   The following correction should be 
sufficient:


res = math.frexp(value)[1] - EXP_OF_ONE
test = 1< r: res -= 1
elif 2*test < r: res += 1

For value = 2**n -1, n > 53, it is always 1 too high on my Intel 
machine, so the first correction is sometimes needed.  I do not know if 
the second is or not.


Terry Jan Reedy

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


Re: Python 2.6: Determining if a method is inherited

2008-10-05 Thread Terry Reedy

Fuzzyman wrote:

Hello all,

I may well be being dumb (it has happened before), but I'm struggling
to fix some code breakage with Python 2.6.

I have some code that looks for the '__lt__' method on a class:

if hasattr(clr, '__lt__'):

However - in Python 2.6 object has grown a default implementation of
'__lt__', so this test always returns True.


class X(object): pass

...

X.__lt__



X.__lt__ == object.__lt__

False


In 3.0, the test returns true because function attributes only get 
wrapped when bound.  In the meanwhile, " 'object' in repr(X.__lt__)" 
should do it for you.


tjr

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


Buy cheap levitra

2008-10-05 Thread lpyeagertutu
buy cheap levitra
.
.
.
Enough to seek Levitra! You've already found the best site where
you can purchase Levitra for lowest price!
To order Levitra without prescription visit link below!

http://med247.us/?p=levitra

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
 uy cheap levitra by cheap levitra bu cheap levitra buy heap levitra
buy ceap levitra buy chap levitra buy chep levitra buy chea levitra
buy cheap evitra buy cheap lvitra buy cheap leitra buy cheap levtra
buy cheap levira buy cheap levita buy cheap levitr bbuy cheap levitra
buuy cheap levitra buyy cheap levitra buy ccheap levitra buy chheap
levitra buy cheeap levitra buy cheaap levitra buy cheapp levitra buy
cheap llevitra buy cheap leevitra buy cheap levvitra buy cheap
leviitra buy cheap levittra buy cheap levitrra buy cheap levitraa uby
cheap levitra byu cheap levitra bu ycheap levitra buy hceap levitra
buy cehap levitra buy chaep levitra buy chepa levitra buy chea
plevitra buy cheap elvitra buy cheap lveitra buy cheap leivtra buy
cheap levtira buy cheap levirta buy cheap levitar buycheap levitra buy
cheaplevitra vuy cheap levitra guy cheap levitra huy cheap levitra nuy
cheap levitra byy cheap levitra b7y cheap levitra b8y cheap levitra
biy cheap levitra bky cheap levitra bjy cheap levitra bhy cheap
levitra but cheap levitra bu6 cheap levitra bu7 cheap levitra buu
cheap levitra buj cheap levitra buh cheap levitra bug cheap levitra
buy xheap levitra buy dheap levitra buy fheap levitra buy vheap
levitra buy cgeap levitra buy cyeap levitra buy cueap levitra buy
cjeap levitra buy cneap levitra buy cbeap levitra buy chwap levitra
buy ch3ap levitra buy ch4ap levitra buy chrap levitra buy chfap
levitra buy chdap levitra buy chsap levitra buy cheqp levitra buy
chewp levitra buy chesp levitra buy chexp levitra buy chezp levitra
buy cheao levitra buy chea0 levitra buy cheal levitra buy cheap
kevitra buy cheap oevitra buy cheap pevitra buy cheap lwvitra buy
cheap l3vitra buy cheap l4vitra buy cheap lrvitra buy cheap lfvitra
buy cheap ldvitra buy cheap lsvitra buy cheap lecitra buy cheap
lefitra buy cheap legitra buy cheap lebitra buy cheap levutra buy
cheap lev8tra buy cheap lev9tra buy cheap levotra buy cheap levltra
buy cheap levktra buy cheap levjtra buy cheap levirra buy cheap
levi5ra buy cheap levi6ra buy cheap leviyra buy cheap levihra buy
cheap levigra buy cheap levifra buy cheap levitea buy cheap levit4a
buy cheap levit5a buy cheap levitta buy cheap levitga buy cheap
levitfa buy cheap levitda buy cheap levitrq buy cheap levitrw buy
cheap levitrs buy cheap levitrx buy cheap levitrz
--
http://mail.python.org/mailman/listinfo/python-list


Re: del and sets proposal

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:

> On Sun, 05 Oct 2008 22:11:38 +1300, Lawrence D'Oliveiro wrote:
> 
>> In message <[EMAIL PROTECTED]>, Steven D'Aprano
>> wrote:
>> 
>>> Would it really be "confusing" if sets used the same interface as dicts
>>> use? I don't think so. What else could "del aset[x]" mean other than
>>> "delete element x"?
>> 
>> Yes, but "x" in what sense?
> 
> The only sense possible.

There is no precedent for using a set element as a subscript to the set.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python is slow?

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Terry
Reedy wrote:

> greg wrote:
>
>> Steven D'Aprano wrote:
>> 
>>> We agree that the restriction is artificial, and I think irrational
>> 
>> I think it's irrational for another reason, too -- it's
>> actually vacuous. There's nothing to prevent you creating
>> a set of patches that simply say "Delete all of the original
>> source and replace it with the following".
>> 
>> Then you're effectively distributing the modified source in
>> its entirety, just with a funny header at the top of each
>> source file that serves no useful purpose.
> 
> The useful purpose is to show that you are distributing your work under
> someone else's product name, instead of making up your own as you ought
> to.

Except that the approach Terry Reedy gets around that without violating the
licence.
--
http://mail.python.org/mailman/listinfo/python-list