Re: Using asyncio workers in a `concurrent.futures` interface

2014-08-13 Thread Ian Kelly
On Tue, Aug 12, 2014 at 11:03 PM, Marko Rauhamaa ma...@pacujo.net wrote:

 Ian Kelly ian.g.ke...@gmail.com:

  On Tue, Aug 12, 2014 at 11:02 AM, cool-RR ram.rac...@gmail.com wrote:
  And that's it, no coroutines, no `yield from`. Since, if I understand
  correctly, asyncio requires a mainloop, it would make sense for the
  AsyncIOExecutor to have a thread of its own in which it could run its
  mainloop.
 
  I think that putting the event loop in a separate thread would be
  necessary if the intention is that the executor be invoked from
  outside. I'm not aware of this work having been done, but it sounds
  perfectly feasible.

 Multithreading will require normal locking to protect critical sections.
 Care must be taken to never yield while holding a threading lock.

You can use event_loop.call_soon_threadsafe() to schedule tasks and
callbacks on the event loop, and Queue objects to pass futures back to the
caller. Apart from whatever synchronization those use internally, I don't
think any locking would be needed.

However, it would of course require that the functions passed in to the
executor be coroutines in actuality. You just can't pass a blocking
function into an asynchronous framework and expect it to magically not
block.
-- 
https://mail.python.org/mailman/listinfo/python-list


[Announce] Python-Future v0.13; cheatsheet for Python 2/3 compatible code

2014-08-13 Thread Ed Schofield
Hi all,

I am happy to announce an update to Python-Future for Python 2/3 compatibility 
and a new cheat-sheet for writing code compatible with both versions.

Here’s the What’s New page for v0.13:

http://python-future.org/whatsnew.html

Here’s the Py2/3 compatibility cheat-sheet:

http://python-future.org/compatible_idioms.html

or as a PDF:

http://python-future.org/compatible_idioms.pdf

The cheat-sheet accompanies a talk I gave at PyCon AU 2014 last weekend called 
“Writing Python 2/3 compatible code”. I will add a link to the video and slides 
from the cheat-sheet page when they are online.

I would be happy to accept pull requests for additions or changes to the Py2/3 
cheat-sheet. The source is here:


https://github.com/PythonCharmers/python-future/blob/master/docs/notebooks/Writing%20Python%202-3%20compatible%20code.ipynb

Best wishes,
Ed


--
Dr. Edward Schofield
Python Charmers
http://pythoncharmers.com

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


newbee

2014-08-13 Thread Frank Scafidi
I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
programmer back in the 60's  70's and Python is similar. I am struggling
with some very fundamental things that I am not finding in the
documentation. Can someone help me with the basics like how do I save a
program I've written, reload it in Python, list the program once it's
loaded? How do I edit a program? Are these command line functions?

Thanks
Frank
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Object Systems

2014-08-13 Thread Michele Simionato
Years ago I wrote strait: https://pypi.python.org/pypi/strait
I wonder who is using it and for what purpose, since surprisingly enough it has 
50+ downloads per day. For me it was more of an experiment than a real project.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Announce] Python-Future v0.13; cheatsheet for Python 2/3 compatible code

2014-08-13 Thread Steven D'Aprano
On Wed, 13 Aug 2014 13:28:03 +1000, Ed Schofield wrote:

 Hi all,
 
 I am happy to announce an update to Python-Future for Python 2/3
 compatibility and a new cheat-sheet for writing code compatible with
 both versions.

Nice! But are you aware that some of your Python 2 code only works in 
certain versions of Python 2? E.g. raising bare strings only works up to 
Python 2.5, in 2.6 and higher it is a syntax error.



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


Re: newbee

2014-08-13 Thread Joel Goldstick
On Tue, Aug 12, 2014 at 7:57 PM, Frank Scafidi fpscaf...@gmail.com wrote:
 I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
 programmer back in the 60's  70's and Python is similar. I am struggling
 with some very fundamental things that I am not finding in the
 documentation. Can someone help me with the basics like how do I save a
 program I've written, reload it in Python, list the program once it's
 loaded? How do I edit a program? Are these command line functions?

I've not worked with Rasberry Pi, but it has some kind of linux on it.
So find a text editor (maybe vim is on it).


Write your code with text editor and save.

To run it type:

python my_program.py

See python.org website and read the tutorial

 Thanks
 Frank


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




-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


odd difference calling function from class or instance variable

2014-08-13 Thread GregS

Hello,

This is my first post here so please gently inform me of any etiquette 
breaches.


I'm seeing a behaviour I can't explain with Python 3.4.1 when I call a 
function via a reference stored in an object.


When I assign the reference as a class variable, the reference has 
__self__ set, too, so I get an extra argument passed to the function.  
If I assign the reference as an instance variable, then __self__ is 
unset so no extra argument.


Here's what I mean:


def print_args(*args):

print(args)


class C:

ref = None


C.ref = print_args# assign to class variable
i = C()
i.ref() # call via class variable - get a 'self' argument passed

(__main__.C object at 0x1071a05f8,)

i.ref = print_args   # assign to instance variable
i.ref() # call via instance variable: no arguments

()

If you look at i.ref.__self__ for the two cases, you'll see what's 
going on.  I've tried RTFMing but can't find the reason for the two 
behaviours.  Could someone provide an explanation for me, please?


Thanks,

Greg


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


Re: newbee

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 9:57 AM, Frank Scafidi fpscaf...@gmail.com wrote:
 I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
 programmer back in the 60's  70's and Python is similar. I am struggling
 with some very fundamental things that I am not finding in the
 documentation. Can someone help me with the basics like how do I save a
 program I've written, reload it in Python, list the program once it's
 loaded? How do I edit a program? Are these command line functions?

These sound like RPi questions, rather than Python questions. You may
find knowledgeable people here on this list, but if not, I would
advise hunting down an RPi mailing list or newsgroup and asking there.
Most of us here use full computers, where questions like how do I
save a file? are trivially easy... you may find, actually, that
starting on a PC and then pushing the file to the RPi is the easiest
way to work.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: odd difference calling function from class or instance variable

2014-08-13 Thread Peter Otten
GregS wrote:

 Hello,
 
 This is my first post here so please gently inform me of any etiquette
 breaches.
 
 I'm seeing a behaviour I can't explain with Python 3.4.1 when I call a
 function via a reference stored in an object.
 
 When I assign the reference as a class variable, the reference has
 __self__ set, too, so I get an extra argument passed to the function.
 If I assign the reference as an instance variable, then __self__ is
 unset so no extra argument.
 
 Here's what I mean:
 
 def print_args(*args):
 print(args)
 
 class C:
 ref = None
 
 C.ref = print_args# assign to class variable
 i = C()
 i.ref() # call via class variable - get a 'self' argument passed
 (__main__.C object at 0x1071a05f8,)
 i.ref = print_args   # assign to instance variable
 i.ref() # call via instance variable: no arguments
 ()
 
 If you look at i.ref.__self__ for the two cases, you'll see what's
 going on.  I've tried RTFMing but can't find the reason for the two
 behaviours.  Could someone provide an explanation for me, please?

When an attribute is found in the instance it is left as-is, so

i.ref()

is the same as

print_ref()

When the attribute is found in the class and itself has a __get__ attribute 

i.ref()

is equivalent to

print_ref.__get__(i, C)()

which creates a bound method object (i. e. it is assumed that the function  
implements a method):

 class C: pass
... 
 def f(self): pass
... 
 f.__get__(C(), C)
bound method C.f of __main__.C object at 0x7f3a99ce86a0

As you have seen a bound method implicitly passes the instance as the first 
arg to the function. The underlying mechanism is called descriptor 
protocol and is also used to implement properties.

If you need to store a function in the class you can wrap it as a 
staticmethod:

 def print_args(*args): print(args)
... 
 class C:
... ref = staticmethod(print_args)
... 
 C().ref()
()


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


Re: odd difference calling function from class or instance variable

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 7:06 PM, GregS n...@my.real.address.com wrote:
 If you look at i.ref.__self__ for the two cases, you'll see what's going on.
 I've tried RTFMing but can't find the reason for the two behaviours.  Could
 someone provide an explanation for me, please?

What you're seeing there is the magic of instance methods. I'll
simplify it some by defining the method right there in the class,
rather than doing the weird injection that you were doing:

 class C:
def meth(self):
print(Hi! I'm a method.,self)

 C().meth()
Hi! I'm a method. __main__.C object at 0x012BC6D0
 C.meth
function C.meth at 0x012AF300
 C().meth
bound method C.meth of __main__.C object at 0x012AEDF0
 _()
Hi! I'm a method. __main__.C object at 0x012AEDF0

When you look up something on the instance, if there's a regular
function of that name on its class, you'll get back a piece of magic
called a bound method. It's a curried function, if you know what that
means (if you don't, just skip this sentence). When you then call that
bound method, it ultimately goes back to the original function, with a
pre-filled first argument (which comes from __self__).

Basically, what this means is that a bound method can be treated like
a function, and it automatically keeps track of its proper state; the
unbound method *is* a function, so if you call that directly, you'll
need to pass it an object as self.

 C.meth(C())
Hi! I'm a method. __main__.C object at 0x0169AA70

As a general rule, though, you won't be doing this kind of thing.
Define functions inside a class body, and then call them on instances.
Everything'll happily work, and all these little details are magic :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 7:06 PM, GregS n...@my.real.address.com wrote:
 When I assign the reference as a class variable, the reference has __self__
 set, too, so I get an extra argument passed to the function.  If I assign
 the reference as an instance variable, then __self__ is unset so no extra
 argument.

Spin-off from Greg's thread.

The bound method object stores a reference to the original object (the
thing that becomes the first argument to the target function) in
__self__ (and the function in __func__). ISTM this ought to be _self
(and _func), as it's intended to be private; is it really something
that has language-level significance on par with __lt__ and so on?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Peter Otten
Frank Scafidi wrote:

 I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
 programmer back in the 60's  70's and Python is similar. I am struggling
 with some very fundamental things that I am not finding in the
 documentation. Can someone help me with the basics like how do I save a
 program I've written, reload it in Python, list the program once it's
 loaded? How do I edit a program? Are these command line functions?

You can use any text editor to write a python script. A simple editor which 
might be present ont the Pi is called nano. It shows the hotkeys to store 
the text and quit the editor, and thus should be self-explanatory:

$ nano helloworld.py

Once you have written your simple script you can look at it with the cat 
command:

$ cat helloworld.py 
#!/usr/bin/env python
print Hello world

Invoke it with:

$ python helloworld.py 
Hello world

You can also make your script executable which means that the first line 
controls which program is used to run it:

$ chmod +x helloworld.py 
$ ./helloworld.py 
Hello world
$

If the script is in a directory listed in the PATH environment variable you 
can omit the path (the ./ in the above example):

$ mv helloworld.py ~/bin
$ helloworld.py 
Hello world

PS: I ran the above demo on a Linux system, but not on the Raspberry Pi, so 
if something doesn't work as shown above it's probably due to the difference 
between the two systems.


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


logging question

2014-08-13 Thread Arulnambi Nandagoban
Hello,

 

I posted a question about logger module to create a log file every day. I
had a problem recently in logging. 

My pc restarts regularly. Whenever it restarts I lose all the log since it
writes in the file once per day.  Is there a way to log information in a
file as soon as it available.

My application is a tcp server. Before I did it without using logger module,
I developed customized log module for the application.  As soon as there is
a connection I append it in the log file.

By that way I didn't lose any log information.  

 

--

nambi

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


Re: odd difference calling function from class or instance variable

2014-08-13 Thread GregS
Thanks to both of you for your incredibly prompt replies.  My homework 
for tonight is to digest the descriptor protocol...


Peter, thanks for suggesting using staticmethod() to get the behaviour 
I was expecting.  I've only used staticmethod as a decorator before now.


Chris, I agree that it's not every day you assign functions to class 
attributes, but it does have its uses (I won't bore you with mine).  
Now that I know how it treads on the toes of Python's method magic, I 
can decide whether it's the best approach or not.


Thanks again,

Greg



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


Re: odd difference calling function from class or instance variable

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 8:20 PM, GregS n...@my.real.address.com wrote:
 Thanks to both of you for your incredibly prompt replies.  My homework for
 tonight is to digest the descriptor protocol...

 Peter, thanks for suggesting using staticmethod() to get the behaviour I was
 expecting.  I've only used staticmethod as a decorator before now.

 Chris, I agree that it's not every day you assign functions to class
 attributes, but it does have its uses (I won't bore you with mine).  Now
 that I know how it treads on the toes of Python's method magic, I can decide
 whether it's the best approach or not.

You seem to know what you're doing, which is a good start :) I aimed
my explanation a bit lower than your actual knowledge turns out to be,
so go ahead and do what you know you need to do. You're not treading
on Python's toes, here, but you're basically recreating some of what
Python normally does under the covers, so you'll need to actually
understand (instead of just treating as black-box magic) stuff like
the descriptor protocol.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-08-13 Thread Wolfgang Keller
  By the way, you keep replying to people, and quoting them, but
  deleting their name. Please leave the attribution in place, so we
  know who you are replying to.
  
  That's what the References:-Header is there for.
 
 The References header is for the benefit of news and mail clients,
 not human readers.

Any half-decent news client will happily display a thread tree for you.
Based on that References:-Header.

 It is rude to deliberately refuse to give attributes:

 So please stop being rude, and follow the convention of both email and
 usenet (as well as broader society) to give attribution to those you
 quote.

I've been using mail and news for over 20 years now, you definitely
don't need to teach me anything.

End of subthread.

Good Bye,

Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Duncan Booth
Peter Otten __pete...@web.de wrote:

 Frank Scafidi wrote:
 
 I just acquired a Raspberry Pi and want to program in Python. I was a
 PL/1 programmer back in the 60's  70's and Python is similar. I am
 struggling with some very fundamental things that I am not finding in
 the documentation. Can someone help me with the basics like how do I
 save a program I've written, reload it in Python, list the program
 once it's loaded? How do I edit a program? Are these command line
 functions? 
 
 You can use any text editor to write a python script. A simple editor
 which might be present ont the Pi is called nano. It shows the
 hotkeys to store the text and quit the editor, and thus should be
 self-explanatory: 
 
 $ nano helloworld.py
 
 Once you have written your simple script you can look at it with the
 cat command:
 
 $ cat helloworld.py 
 #!/usr/bin/env python
 print Hello world
 
 Invoke it with:
 
 $ python helloworld.py 
 Hello world
 
 You can also make your script executable which means that the first
 line controls which program is used to run it:
 
 $ chmod +x helloworld.py 
 $ ./helloworld.py 
 Hello world
 $
 
 If the script is in a directory listed in the PATH environment
 variable you can omit the path (the ./ in the above example):
 
 $ mv helloworld.py ~/bin
 $ helloworld.py 
 Hello world
 
 PS: I ran the above demo on a Linux system, but not on the Raspberry
 Pi, so if something doesn't work as shown above it's probably due to
 the difference between the two systems.
 

All of the above should work just fine on a Pi. The only thing I thing 
you could have added is that you also have the option of using Idle to 
edit and run Python programs. If you are running Raspian on your Pi then 
you will find an icon to run Idle sitting on the initial desktop. 
There's an introduction to using Idle on the Raspberry Pi at 
http://www.raspberrypi.org/documentation/usage/python/


-- 
Duncan Booth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-08-13 Thread Wolfgang Keller
   Because on such operating systems, each and every application is
   an entirely self-contained package that doesn't need any
   packages or installers to use it.
 
  For people who have never used such a system it's probably
  difficult to see the  advantages.
 
  That's the whole point.
 
  The problem is that the ones who decide (well, they pretend to,
  but actually can't, because they don't know the alternatives) are
  always people who are not even clueless.
 
 Ha!  I love it.  I presume that's an allusion to that-other-Wolfgang's
 apocryphal not even wrong comment.  :)

Exactly.

And it's also an allusion to that statement that knowledge means to
know what you don't know.

Sincerely,

Wolfgang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread alister
On Tue, 12 Aug 2014 19:57:14 -0400, Frank Scafidi wrote:

 I just acquired a Raspberry Pi and want to program in Python. I was a
 PL/1 programmer back in the 60's  70's and Python is similar. I am
 struggling with some very fundamental things that I am not finding in
 the documentation. Can someone help me with the basics like how do I
 save a program I've written, reload it in Python, list the program once
 it's loaded? How do I edit a program? Are these command line functions?
 
 Thanks Frank div dir=ltrdiv class=gmail_default
 style=font-family:georgia,serif;font-size:small;color:#3366ffI just
 acquired a Raspberry Pi and want to program in Python. I was a PL/1
 programmer back in the 60#39;s amp; 70#39;s and Python is similar. I
 am struggling with some very fundamental things that I am not finding in
 the documentation. Can someone help me with the basics like how do I
 save a program I#39;ve written, reload it in Python, list the program
 once it#39;s loaded? How do I edit a program? Are these command line
 functions? /div
 div class=gmail_default
 style=font-family:georgia,serif;font-size:small;color:#3366ffbr/
divdiv
 class=gmail_default
 style=font-family:georgia,serif;font-size:small;color:#3366ffThanks/
divdiv
 class=gmail_default
 style=font-family:georgia,serif;font-size:small;color:#3366ff
 Frank/divdiv class=gmail_default
 style=font-family:georgia,serif;font-size:small;color:#3366ffbr/
div/div


I am not in the same league as many of the posters here when it comes to 
Python but fortunately i do have two Raspberry Pi's :-)

if you are running the Pi connected to a TV/Monitor with the Gui enabled 
then you should have access to Idle as well as a number of text editors 
(Geany works well if installed)

if you are using it from the commands line then as previously stated you 
need to use a text editor to write the code (Nano is part of the basic 
Raspian Distro and easier to use than VI/Vim)

once you have created your code file type python file Name at the 
command prompt

remember if you are connecting to the Pi remotely Via SSH it is useful to 
have multiple connections open, one for the text editor  1 to enable you 
to run the code or execute other Linux commands.

If you have any more questions post them back I hope I can help
(Maybe I can become useful to this group as the R-Pi expert, hopefully 
more productively than some of the groups other 'Experts')



-- 
Expect the worst, it's the least you can do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Ned Batchelder

On 8/13/14 5:51 AM, Chris Angelico wrote:

On Wed, Aug 13, 2014 at 7:06 PM, GregS n...@my.real.address.com wrote:

When I assign the reference as a class variable, the reference has __self__
set, too, so I get an extra argument passed to the function.  If I assign
the reference as an instance variable, then __self__ is unset so no extra
argument.


Spin-off from Greg's thread.

The bound method object stores a reference to the original object (the
thing that becomes the first argument to the target function) in
__self__ (and the function in __func__). ISTM this ought to be _self
(and _func), as it's intended to be private; is it really something
that has language-level significance on par with __lt__ and so on?

ChrisA



As I see it, dunder names are those whose meaning is defined by the 
Python language (and/or implementation?), and whose use is typically 
behind-the-scenes.  So len is defined by the language, but is meant to 
be front-and-center, so it has a nice name.  __init__, __lt__, and 
__self__, have meanings and uses defined by Python itself, and so are 
reasonable as dunder names.


This is a crude namespacing: Python can use any name it likes so long as 
its a dunder name, and I can use any name I like, so long as it isn't.


Yes, the definition is fuzzy :)

--
Ned Batchelder, http://nedbatchelder.com

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


Log base 2 of large integers

2014-08-13 Thread Mok-Kong Shen


I like to compute log base 2 of a fairly large integer n but
with math.log(n,2) I got:

OverflowError: long int too large to convert to float.

Is there any feasible work-around for that?

Thanks in advance.

M. K. Shen
--
https://mail.python.org/mailman/listinfo/python-list


Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Steven D'Aprano
Chris Angelico wrote:

 The bound method object stores a reference to the original object (the
 thing that becomes the first argument to the target function) in
 __self__ (and the function in __func__). ISTM this ought to be _self
 (and _func), as it's intended to be private;

Why do you say they are intended to be private? Is that documented
somewhere, or do you mean that if you designed the system, *you* would have
intended them to be private? :-)

 is it really something 
 that has language-level significance on par with __lt__ and so on?

To be honest, I didn't even know about __self__, but I understood __func__
to be public. And yes, it should be public: being able to introspect a
method and find the function it came from is a good thing, and sometimes
useful.



-- 
Steven

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


Re: Log base 2 of large integers

2014-08-13 Thread Skip Montanaro
On Wed, Aug 13, 2014 at 8:05 AM, Mok-Kong Shen
mok-kong.s...@t-online.de wrote:
 I like to compute log base 2 of a fairly large integer n but
 with math.log(n,2) I got:

 OverflowError: long int too large to convert to float.

 Is there any feasible work-around for that?

A bit of googling turned up this page:

http://gnumbers.blogspot.com/2011/10/logarithm-of-large-number-it-is-not.html

Might be worth studying for ideas.

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


Re: newbee

2014-08-13 Thread Mok-Kong Shen

Am 13.08.2014 13:55, schrieb alister:
[snip]

A related question: How could one write a Python program and
have it run on a mobile phone in general (independent of a PC)?

M. K. Shen
--
https://mail.python.org/mailman/listinfo/python-list


Re: Log base 2 of large integers

2014-08-13 Thread Steven D'Aprano
Mok-Kong Shen wrote:

 
 I like to compute log base 2 of a fairly large integer n but
 with math.log(n,2) I got:
 
 OverflowError: long int too large to convert to float.
 
 Is there any feasible work-around for that?

If you want the integer log2, that is, the floor of log2, the simplest way
is calculate it like this:

def log2(n):
Return the floor of log2(n).
if n = 0: raise ValueError
i = -1
while n:
n //= 2
i += 1
return i

log2(511)
= returns 8
log2(512)
= returns 9
log2(513)
= returns 9


Does that help?



-- 
Steven

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


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-08-13 Thread Steven D'Aprano
Wolfgang Keller wrote:

 I've been using mail and news for over 20 years now, you definitely
 don't need to teach me anything.

Except common courtesy.

You may have been rude for over 20 years, but I don't have to put up with it
for a second longer.

 Good Bye,

Agreed.

*plonk*


-- 
Steven

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


Re: Log base 2 of large integers

2014-08-13 Thread Mok-Kong Shen

Am 13.08.2014 15:32, schrieb Steven D'Aprano:

Mok-Kong Shen wrote:



I like to compute log base 2 of a fairly large integer n but
with math.log(n,2) I got:

OverflowError: long int too large to convert to float.

Is there any feasible work-around for that?


If you want the integer log2, that is, the floor of log2, the simplest way
is calculate it like this:

def log2(n):
 Return the floor of log2(n).
 if n = 0: raise ValueError
 i = -1
 while n:
 n //= 2
 i += 1
 return i

log2(511)
= returns 8
log2(512)
= returns 9
log2(513)
= returns 9


Does that help?


That is too inaccurate (e.g. for 513 above) for me, I would like
to get accuracy around 0.01 and that for very large n.

M. K. Shen

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


Re: Log base 2 of large integers

2014-08-13 Thread Mok-Kong Shen

Am 13.08.2014 15:16, schrieb Skip Montanaro:


http://gnumbers.blogspot.com/2011/10/logarithm-of-large-number-it-is-not.html

Might be worth studying for ideas.


Thanks. I think the idea may help.

M. K. Shen

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


Re: Log base 2 of large integers

2014-08-13 Thread Peter Otten
Mok-Kong Shen wrote:
 
 I like to compute log base 2 of a fairly large integer n but
 with math.log(n,2) I got:
 
 OverflowError: long int too large to convert to float.
 
 Is there any feasible work-around for that?

What version of Python are you using? Python 2.7 can handle fairly large 
integers:

 float(x)
Traceback (most recent call last):
  File stdin, line 1, in module
OverflowError: long int too large to convert to float
 math.log(x, 2)
50462500.07504181

Or maybe our idea of fairly large differ; so how large is fairly large?

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


Re: newbee

2014-08-13 Thread alister
On Wed, 13 Aug 2014 15:13:34 +0200, Mok-Kong Shen wrote:

 Am 13.08.2014 13:55, schrieb alister:
 [snip]
 
 A related question: How could one write a Python program and have it run
 on a mobile phone in general (independent of a PC)?
 
 M. K. Shen

you would need a python interpreter for that device, IIRC there is one 
available for android, I do not know about IOS



-- 
It's not hard to admit errors that are [only] cosmetically wrong.
-- J.K. Galbraith
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Log base 2 of large integers

2014-08-13 Thread Andrew Jaffe

On 13/08/2014 14:46, Mok-Kong Shen wrote:

Am 13.08.2014 15:32, schrieb Steven D'Aprano:

Mok-Kong Shen wrote:



I like to compute log base 2 of a fairly large integer n but
with math.log(n,2) I got:

OverflowError: long int too large to convert to float.

Is there any feasible work-around for that?


If you want the integer log2, that is, the floor of log2, the simplest
way
is calculate it like this:

   removed... see below 

Does that help?


That is too inaccurate (e.g. for 513 above) for me, I would like
to get accuracy around 0.01 and that for very large n.

M. K. Shen


Well, we can use Steven d'A's idea as a starting point:

import math
def log2_floor(n):
 Return the floor of log2(n).
 if n = 0: raise ValueError
 i = -1
 while n:
 n //= 2
 i += 1
 return i

def log2(n):
 return log_2(n) by splitting the problem into the integer and 
fractional parts

l2f = log2_floor(n)
if n == 2**l2f:
return l2f
else:
return l2f + math.log(n*2**-l2f, 2)


Andrew


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


Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 11:12 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Chris Angelico wrote:

 The bound method object stores a reference to the original object (the
 thing that becomes the first argument to the target function) in
 __self__ (and the function in __func__). ISTM this ought to be _self
 (and _func), as it's intended to be private;

 Why do you say they are intended to be private? Is that documented
 somewhere, or do you mean that if you designed the system, *you* would have
 intended them to be private? :-)

Good point - the latter :) However, that applies only to the one
leading underscore. Whether they're _self/_func or self/func, they
could be regular attributes without being dunder ones.

 is it really something
 that has language-level significance on par with __lt__ and so on?

 To be honest, I didn't even know about __self__, but I understood __func__
 to be public. And yes, it should be public: being able to introspect a
 method and find the function it came from is a good thing, and sometimes
 useful.

I stand corrected on the privacy issue. But introspection would be
just as easy if it were called func instead. Picking up Ned's wording:

On Wed, Aug 13, 2014 at 10:11 PM, Ned Batchelder n...@nedbatchelder.com wrote:
 This is a crude namespacing: Python can use any name it likes so long as its
 a dunder name, and I can use any name I like, so long as it isn't.

This concept generally applies to Python doing stuff with my class. If
I define a class that I want a built-in function, operator, or
language feature, to work with, I define a dunder attribute (most
often a method) to tie in with that - my class, Python's
functionality.

When Python defines the class, it's free to do whatever it likes with
naming. There are public methods and attributes, named nice and simply
because there's no possibility of collision. The bound method object
is like this; it could easily have any number of simply-named
attributes, and most of us wouldn't even be aware of them, much less
concerned that we now can't use those names. We can't possibly
collide, because this is a completely different class from anything
I'm working with.

Even namedtuple, where it *is* possible to have collisions, doesn't go
dunder - it has single-underscore public members. That's a deliberate
decision to use a namespace other than the normal one of simply-named
members; and dunders weren't used. In the case of __self__ and
__func__, what's the advantage of this tagging?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:Log base 2 of large integers

2014-08-13 Thread Dave Angel
Mok-Kong Shen mok-kong.s...@t-online.de Wrote in message:
 
 I like to compute log base 2 of a fairly large integer n but
 with math.log(n,2) I got:
 
 OverflowError: long int too large to convert to float.
 
 Is there any feasible work-around for that?
 
 Thanks in advance.
 
 M. K. Shen
 

Easiest way to get the integer part is to convert to binary
 string,  and take the length of that string.
Call that m.

Then construct a string consisting of a 1 followed by m zeroes.
 
Convert that to a long,  and divide your original number by it.
 Now take the log base 2 of the quotient. Add that to m and you
 have your answer, plus or minus 1.

-- 
DaveA

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


Re: Log base 2 of large integers

2014-08-13 Thread Peter Otten
Steven D'Aprano wrote:

 Mok-Kong Shen wrote:
 
 
 I like to compute log base 2 of a fairly large integer n but
 with math.log(n,2) I got:
 
 OverflowError: long int too large to convert to float.
 
 Is there any feasible work-around for that?
 
 If you want the integer log2, that is, the floor of log2, the simplest way
 is calculate it like this:
 
 def log2(n):
 Return the floor of log2(n).
 if n = 0: raise ValueError
 i = -1
 while n:
 n //= 2
 i += 1
 return i
 
 log2(511)
 = returns 8
 log2(512)
 = returns 9
 log2(513)
 = returns 9

For base 2 there is also the bit_length() method:

 511 .bit_length()
9
 512 .bit_length() 
10
 513 .bit_length()  
10


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


Re: Suitable Python code to scrape specific details from web pages.

2014-08-13 Thread Denis McMahon
On Tue, 12 Aug 2014 13:00:30 -0700, Simon Evans wrote:

 in accessing from the 'Racing Post' on a daily basis. Anyhow, the code

Following is some starter code. You will have to look at the output, 
compare it to the web page, and work out how you want to process it 
further. Note that I use beautifulsoup and requests. The output is the 
html for each cell in the table with a line of + characters at the 
table row breaks. I suggest you look at the beautifulsoup documentation 
at http://www.crummy.com/software/BeautifulSoup/bs4/doc/ to work out how 
you may wish to select which table cells contain data you are interested 
in and how to extract it.

#!/usr/bin/python

Program to extract data from racingpost.


from bs4 import BeautifulSoup
import requests

r = requests.get( http://www.racingpost.com/horses2/cards/card.sd?
race_id=607466r_date=2014-08-13#raceTabs=sc_ )

if r.status_code == 200:
soup = BeautifulSoup( r.content )
table = soup.find( table, id=sc_horseCard )
for row in table.find_all( tr ):
for cell in row.find_all( td ):
print cell
print +
else:
print HTTP Status, r.status_code

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Begginer in python trying to load a .dll

2014-08-13 Thread c1234 py
Thanks a lot. 



El martes, 12 de agosto de 2014 17:17:26 UTC-3, Mark Lawrence  escribió:
 On 12/08/2014 20:25, c1234 py wrote:
 
  El martes, 12 de agosto de 2014 16:16:21 UTC-3, Christian Gollwitzer  
  escribi�:
 
  Am 12.08.14 20:36, schrieb c1223:
 
 
 
  Hi, Im working in the development of a program based in python that
 
 
 
  allow us to contrl a spectometer. The spectometer has an .dll file.
 
 
 
  The idea is to work through this dll and operate the spectometer. The
 
 
 
  name of the .dll is AS5216.dll. I've trying with ctype, but it
 
 
 
  doesn't work. I'm begginer in python. All the comments are useful to
 
 
 
  me.
 
 
 
 
 
 
 
  For sure this DLL will come with a header file for C. You could pass it
 
 
 
  through SWIG and see if it generates a useful Python module. You need a
 
 
 
  C compiler for that route, though.
 
 
 
 
 
 
 
 Christian
 
 
 
 
 
  How can i pass it through a SWIG?, i don't know that and what it mean?
 
 
 
 
 
 Start here http://www.swig.org/ which you could easily have found for 
 
 yourself, as I did by using a search engine.
 
 
 
 Also would you please access this list via 
 
 https://mail.python.org/mailman/listinfo/python-list or read and action 
 
 this https://wiki.python.org/moin/GoogleGroupsPython to prevent us
 
 seeing double line spacing and single line paragraphs, thanks.
 
 
 
 -- 
 
 My fellow Pythonistas, ask not what our language can do for you, ask
 
 what you can do for our language.
 
 
 
 Mark Lawrence

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


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-08-13 Thread Mark Lawrence

On 13/08/2014 11:42, Wolfgang Keller wrote:

By the way, you keep replying to people, and quoting them, but
deleting their name. Please leave the attribution in place, so we
know who you are replying to.


That's what the References:-Header is there for.


The References header is for the benefit of news and mail clients,
not human readers.


Any half-decent news client will happily display a thread tree for you.
Based on that References:-Header.


It is rude to deliberately refuse to give attributes:



So please stop being rude, and follow the convention of both email and
usenet (as well as broader society) to give attribution to those you
quote.


I've been using mail and news for over 20 years now, you definitely
don't need to teach me anything.


Very funny.  It strikes me that your knowledge of using mail and news is 
akin to that of our resident unicode expert's knowledge of the FSR.




End of subthread.



The subthread ends when people want it to end, not when you state that 
it has ended.  It will not end until you stop being so downright rude in 
refusing to give attribution to those you quote.



Good Bye,


Good riddance.

Ditto Steven D'Aprano's *plonk*



Wolfgang




--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Why does str not have a __radd__ method?

2014-08-13 Thread Steven D'Aprano
I just tried to override str.__radd__:

class Special(str):
def __radd__(self, other):
print(I'm special!)
return super().__radd__(self, other)

My __radd__ method was called correctly by the + operator, but to my
surprise, the super().__radd__ call failed with:

Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 4, in __radd__
AttributeError: 'super' object has no attribute '__radd__'

Sure enough, in both Python 3.3 and 2.7:

py str.__radd__
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: type object 'str' has no attribute '__radd__'


This is especially astonishing, since int and float both have __radd__
methods, and yet numeric addition is commutative (x+y == y+x) whereas the
same is not true for string concatenation.

What is the rationale for str not having __radd__ method?


-- 
Steven

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


Re: Log base 2 of large integers

2014-08-13 Thread Peter Pearson
On Wed, 13 Aug 2014 15:58:02 +0200, Peter Otten __pete...@web.de wrote:
 Mok-Kong Shen wrote:
  
 I like to compute log base 2 of a fairly large integer n but
 with math.log(n,2) I got:
 
 OverflowError: long int too large to convert to float.
[snip]
 Or maybe our idea of fairly large differ; so how large is fairly large?

MK Shen used to hang out on the sci.crypt newsgroup, so we're
probably talking cryptographically large rather than engineeringly
large.

-- 
To email me, substitute nowhere-spamcop, invalid-net.
-- 
https://mail.python.org/mailman/listinfo/python-list


Need simple Python Script

2014-08-13 Thread taifulsust
Hello Guys

I am new in Python programming.Currently reading the book  Learn Python the 
Heard Way.However i need a python script which will take an image file (any 
standard format) from my windows pc as input.Can anybody have any solution?I 
use command prompt and gedit to learn python.

Thanks

Leon
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need simple Python Script

2014-08-13 Thread Chris Angelico
On Thu, Aug 14, 2014 at 2:11 AM,  taifuls...@gmail.com wrote:
 I am new in Python programming.Currently reading the book  Learn Python the 
 Heard Way.However i need a python script which will take an image file (any 
 standard format) from my windows pc as input.Can anybody have any solution?I 
 use command prompt and gedit to learn python.


If you finish studying the book, you'll have a better idea of how to
go about doing things in Python, and also of how to find out more
about what you can work with. For a start, you probably want a Python
imaging library. You could type those three words into a search engine
and see what comes back. In fact, that's probably a good start for any
question you have.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Log base 2 of large integers

2014-08-13 Thread Chris Angelico
On Thu, Aug 14, 2014 at 2:12 AM, Peter Pearson ppearson@nowhere.invalid wrote:
 MK Shen used to hang out on the sci.crypt newsgroup, so we're
 probably talking cryptographically large rather than engineeringly
 large.

So fairly large means somewhere between googolplex an Graham's
Number, and after that they'd be called very large?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Log base 2 of large integers

2014-08-13 Thread Marko Rauhamaa
Peter Pearson ppearson@nowhere.invalid:

 MK Shen used to hang out on the sci.crypt newsgroup, so we're probably
 talking cryptographically large rather than engineeringly large.

I'm thinking we're talking about philosophically large. Those kinds of
numbers are unwieldy from all angles, including cryptography.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-13 Thread Rob Gaddi
On Tue, 12 Aug 2014 18:36:21 -0700 (PDT)
Wesley nisp...@gmail.com wrote:

 If my questions make you guys not so happy, I am sorry and please just ignore.
 I just wanna a general suggestion here in the beginning.
 Why I need to write such program is just having such requirements, and has 
 nothing to do with the coding work itself. Don't say something to prove 
 you're so noble.
 

Hai guyz I am new to biochemistry and so I need lots of help with
things.can you tell me how to make anthrax?

I need it for stuff, so dont worry

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread William Ray Wing
On Aug 13, 2014, at 9:57 AM, alister alister.nospam.w...@ntlworld.com wrote:

 On Wed, 13 Aug 2014 15:13:34 +0200, Mok-Kong Shen wrote:
 
 Am 13.08.2014 13:55, schrieb alister:
 [snip]
 
 A related question: How could one write a Python program and have it run
 on a mobile phone in general (independent of a PC)?
 
 M. K. Shen
 
 you would need a python interpreter for that device, IIRC there is one 
 available for android, I do not know about IOS
 

There are several for iOS, but because of Apple’s sandboxing they don’t have as 
much reach as you might want.

-Bill
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need simple Python Script

2014-08-13 Thread John Gordon
In 0ec17bee-0ed6-4494-b4ab-231988031...@googlegroups.com taifuls...@gmail.com 
writes:

 I am new in Python programming.Currently reading the book  Learn Python
 the Heard Way.However i need a python script which will take an image
 file (any standard format) from my windows pc as input.Can anybody have
 any solution?  I use command prompt and gedit to learn python.

What is the script supposed to *do* with the image file?

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

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


Re: Python Object Systems

2014-08-13 Thread thequietcenter
On Wednesday, August 13, 2014 4:32:04 AM UTC-4, Michele Simionato wrote:
 Years ago I wrote strait: https://pypi.python.org/pypi/strait

What is the difference between traits and roles?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why does str not have a __radd__ method?

2014-08-13 Thread Ethan Furman

On 08/13/2014 09:00 AM, Steven D'Aprano wrote:


What is the rationale for str not having __radd__ method?


At a guess I would say because string only knows how to add itself to other 
strings, so __add__ is sufficient.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-13 Thread Steven D'Aprano
Rob Gaddi wrote:

 On Tue, 12 Aug 2014 18:36:21 -0700 (PDT)
 Wesley nisp...@gmail.com wrote:
 
 If my questions make you guys not so happy, I am sorry and please just
 ignore. I just wanna a general suggestion here in the beginning.
 Why I need to write such program is just having such requirements, and
 has nothing to do with the coding work itself. Don't say something to
 prove you're so noble.
 
 
 Hai guyz I am new to biochemistry and so I need lots of help with
 things.can you tell me how to make anthrax?
 
 I need it for stuff, so dont worry

:-)

You'll only use it for good, right?



-- 
Steven

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


Re: Why does str not have a __radd__ method?

2014-08-13 Thread Steven D'Aprano
Ethan Furman wrote:

 On 08/13/2014 09:00 AM, Steven D'Aprano wrote:

 What is the rationale for str not having __radd__ method?
 
 At a guess I would say because string only knows how to add itself to
 other strings, so __add__ is sufficient.

# Python 2.7
py Hello + uWorld
u'HelloWorld'
py unicode.__radd__
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: type object 'unicode' has no attribute '__radd__'


My brain hurts.



-- 
Steven

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


Re: Log base 2 of large integers

2014-08-13 Thread Ian Kelly
On Wed, Aug 13, 2014 at 10:18 AM, Chris Angelico ros...@gmail.com wrote:
 On Thu, Aug 14, 2014 at 2:12 AM, Peter Pearson ppearson@nowhere.invalid 
 wrote:
 MK Shen used to hang out on the sci.crypt newsgroup, so we're
 probably talking cryptographically large rather than engineeringly
 large.

 So fairly large means somewhere between googolplex an Graham's
 Number, and after that they'd be called very large?

I estimate that representing a googolplex as a 64-bit Python 3 int
would require around 4.429 * 10**75 yottabytes of memory. So probably
not that large.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-13 Thread Chris Angelico
On Thu, Aug 14, 2014 at 3:52 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 I need it for stuff, so dont worry

 :-)

 You'll only use it for good, right?

He needs it for stuffing. Remind me to decline any invitation to
turkey dinner that he sends.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why does str not have a __radd__ method?

2014-08-13 Thread Ethan Furman

On 08/13/2014 10:55 AM, Steven D'Aprano wrote:

Ethan Furman wrote:


On 08/13/2014 09:00 AM, Steven D'Aprano wrote:


What is the rationale for str not having __radd__ method?


At a guess I would say because string only knows how to add itself to
other strings, so __add__ is sufficient.


# Python 2.7
py Hello + uWorld
u'HelloWorld'
py unicode.__radd__
Traceback (most recent call last):
   File stdin, line 1, in module
AttributeError: type object 'unicode' has no attribute '__radd__'


Well, unicode is a string type, right? ;)

And for the proof:


'hello'.__add__(u'world')

u'helloworld'

u'hello'.__add__('world')

u'helloworld'



My brain hurts.


An occupational hazard of unicode, surely.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why does str not have a __radd__ method?

2014-08-13 Thread Jason Swails
On Wed, Aug 13, 2014 at 1:55 PM, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 Ethan Furman wrote:

  On 08/13/2014 09:00 AM, Steven D'Aprano wrote:
 
  What is the rationale for str not having __radd__ method?
 
  At a guess I would say because string only knows how to add itself to
  other strings, so __add__ is sufficient.

 # Python 2.7
 py Hello + uWorld
 u'HelloWorld'
 py unicode.__radd__
 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: type object 'unicode' has no attribute '__radd__'


This happens because the str.__add__ function calls string_concat under the
hood (see Objects/stringobject.c) -- there's a unicode check on the other
operand that results in the result of PyUnicode_Concat being returned
instead of the concatenated str type.  This doesn't require that unicode
define __radd__.

When the left-hand operand is Unicode, PyUnicode_Concat is called directly
(which is why the exception message is different for u'this' + 1 and 'this'
+ 1):

 'this' + 1
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: cannot concatenate 'str' and 'int' objects
 u'this' + 1
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: coercing to Unicode: need string or buffer, int found


All the best,
Jason
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Terry Reedy

On 8/13/2014 5:51 AM, Chris Angelico wrote:

On Wed, Aug 13, 2014 at 7:06 PM, GregS n...@my.real.address.com wrote:

When I assign the reference as a class variable, the reference has __self__
set, too, so I get an extra argument passed to the function.  If I assign
the reference as an instance variable, then __self__ is unset so no extra
argument.


Spin-off from Greg's thread.

The bound method object stores a reference to the original object (the
thing that becomes the first argument to the target function) in
__self__ (and the function in __func__). ISTM this ought to be _self
(and _func), as it's intended to be private; is it really something
that has language-level significance on par with __lt__ and so on?


In 3.0, the iterator protocol .next became .__next__ for consistency 
with other syntax dunder methods.


In 2.x, bound python-coded functions had im_func and im_self (and 
im_class for the class im_func was attached to, which has no equivalent 
in 3.x).  Bound C-coded functions, such as [].sort, had and still have 
__self__ instead of im_self (and no equivalent of im_func/__func__). I 
presume this difference goes back to the gulf between C-coded types and 
Python-coded old-style classes. With old-style classes gone, im_class 
went and it made sense to consistently use __self__ instead of sometimes 
im_self (and change im_func to __func__ alone with it).


In 3.0, function attributes were also dunderized.  This was needed once 
function namespaces were unfrozen and users allowed to add possibly 
conflicting function attributes.


 dir(lambda:0) #2.7
['__call__', '__class__', '__closure__', '__code__', '__defaults__', 
'__delattr__', '__dict__', '__doc__', '__format__', '__get__', 
'__getattribute__', '__globals__', '__hash__', '__init__', '__module__', 
'__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__sizeof__', '__str__', '__subclasshook__', 
'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 
'func_globals', 'func_name']


(In 2.7, many of the func attributes are duplicates: __code__ == 
func_code, etc, though this might not have always been true.)


 dir(lambda:0)
['__annotations__', '__call__', '__class__', '__closure__', '__code__', 
'__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', 
'__eq__', '__format__', '__ge__', '__get__', '__getattribute__', 
'__globals__', '__gt__', '__hash__', '__init__', '__kwdefaults__', 
'__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', 
'__qualname__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__sizeof__', '__str__', '__subclasshook__']


The function specific attributes are documented in
https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy

The same was not done for 'internal types': code objects and co_, frame 
objects and f_, traceback objects and tb_.  Their namespaces are still 
frozen.


--
Terry Jan Reedy

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


Re: Captcha identify

2014-08-13 Thread Eric S. Johansson


On 8/12/2014 9:46 PM, Chris Angelico wrote:

On Wed, Aug 13, 2014 at 11:36 AM, Wesley nisp...@gmail.com wrote:

If my questions make you guys not so happy, I am sorry and please just ignore.
I just wanna a general suggestion here in the beginning.
Why I need to write such program is just having such requirements, and has 
nothing to do with the coding work itself. Don't say something to prove you're 
so noble.

The general suggestion you're getting is: Do not do this. Many of us
here use CAPTCHAs and spend time keeping one step ahead of those who
try to break them with software. By writing something to solve
CAPTCHAs, you would be stealing time from those people. Don't do it.

Am I sufficiently clear?

you are clear but also missing a really good reason to break captchas.  
handicapped accessibility.  Captchas are a huge barrier to access and in 
many cases push disabled users away from using a service  with 
captchas.  For me (very acute vision, crap hands) it take me 2-5 tries 
before I get an image I think I can read reliably, then it take 2-3 
tries to type the letters in (slowly and with hand pain) correctly. My 
mom (80yr and going strong) sees a captcha and gives up on using the 
site unless I tell her what to type.


one major tests for accessibility is can I automate common user tasks 
including tasks with context based decisions.  Captchas fail that test 
as do many authentication system user interactions and, if one is 
entirely truthful, entire applications.  Automating captcha solving 
would be a boon for the disabled or aging user.


try taking this moment as a challenge.  build an authentication 
system+ui that works for the disabled/aged and you will have an 
authentication system that will work better for everybody.  for example, 
use an equivalent of ssh-agent to supply credentials to sites needing 
them.  I can automate ssh-agent and we can make the process+UI easy 
enough for my mom to use it or automate it for her too.


eliminate captchas, 35+million disabled people would thank you as would 
many more millions of the not-yet-disabled like your future self.

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


Re: Captcha identify

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 9:39 PM, Eric S. Johansson e...@harvee.org wrote:
 you are clear but also missing a really good reason to break captchas.
 handicapped accessibility.  Captchas are a huge barrier to access and in
 many cases push disabled users away from using a service  with captchas.
 For me (very acute vision, crap hands) it take me 2-5 tries before I get an
 image I think I can read reliably, then it take 2-3 tries to type the
 letters in (slowly and with hand pain) correctly. My mom (80yr and going
 strong) sees a captcha and gives up on using the site unless I tell her what
 to type.

 one major tests for accessibility is can I automate common user tasks
 including tasks with context based decisions.  Captchas fail that test as
 do many authentication system user interactions and, if one is entirely
 truthful, entire applications.  Automating captcha solving would be a boon
 for the disabled or aging user.

 try taking this moment as a challenge.  build an authentication system+ui
 that works for the disabled/aged and you will have an authentication system
 that will work better for everybody.  for example, use an equivalent of
 ssh-agent to supply credentials to sites needing them.  I can automate
 ssh-agent and we can make the process+UI easy enough for my mom to use it or
 automate it for her too.

 eliminate captchas, 35+million disabled people would thank you as would many
 more millions of the not-yet-disabled like your future self.

I agree with you, and I don't use CAPTCHAs on any of my services,
anywhere, and never have. (Partly because they *are* broken by people
writing scripts, and/or by just grinding them with human solvers; but
also because of the problems they cause for legit users, even those
with perfect eyesight.) However, the accessibility argument is one for
the removal of the captcha, *not* for its automated solving. I will
not support a scripted captcha solver for any reason. If you move away
from a site because you can't use it, so be it. If you get a chance,
tell the owner that there are alternatives to barely-readable images;
tricks involving page layouts are almost always safe, and there's
infinite room to play around in them.

There is no valid reason for automating something that's specifically
to prevent automation. The admin needs to provide an alternative,
instead.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-13 Thread Chris Kaynor
On Wed, Aug 13, 2014 at 4:39 AM, Eric S. Johansson e...@harvee.org wrote:

 eliminate captchas, 35+million disabled people would thank you as would
 many more millions of the not-yet-disabled like your future self.


And so would the spammers, which is who captchas are trying to block.

For ease-of-use, most sites only require captchas to be entered once upon
creating the account. Some might also require additional captcha entries
when the account is suspected of spamming. This is ultimately a trade-off
of blocking spammers and allowing accessibility.

Many of the better captchas also include options for an audio cue in
addition to the default visual one.

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


Re: newbee

2014-08-13 Thread Terry Reedy

On 8/13/2014 7:55 AM, alister wrote:


I am not in the same league as many of the posters here when it comes to
Python but fortunately i do have two Raspberry Pi's :-)


Great! We really someone with hands-on experience.


if you are running the Pi connected to a TV/Monitor with the Gui enabled
then you should have access to Idle


Have you verified that Idle *does* (not just *should*) run on RPi? 
(That would mean having tcl/tk running, with whatever *it* requires on 
linux.) I am working on Idle and the idea of people (especially 
hobbyists, students, and other amateurs) running it on microsystems 
would really please me.



If you have any more questions post them back I hope I can help
(Maybe I can become useful to this group as the R-Pi expert,


Answering questions, sometimes after experiment and research, is a great 
way to learn.


--
Terry Jan Reedy

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


Re: Captcha identify

2014-08-13 Thread Chris Angelico
On Thu, Aug 14, 2014 at 5:24 AM, Chris Kaynor ckay...@zindagigames.com wrote:
 On Wed, Aug 13, 2014 at 4:39 AM, Eric S. Johansson e...@harvee.org wrote:

 eliminate captchas, 35+million disabled people would thank you as would
 many more millions of the not-yet-disabled like your future self.


 And so would the spammers, which is who captchas are trying to block.

There are alternatives that are both easier for legit people and
harder for spambots. Some rely on the fact that humans read things two
dimensionally, and scripts look at the underlying structure; so, for
instance, random field names and cunning CSS to match them up with
their labels can result in a form that's completely messed up in the
source, but looks perfect to a user. Or you can put extra fields down
that you can't see if the form's laid out properly. Or you can combine
those sorts of tricks with a very simple challenge-response, like
What is one plus one? that requires some specific value to be in a
specific field - and if that value occurs in the wrong field, you
throw the form back to the user.

For some reason, everyone's jumped on the show some mangled
text/numbers and ask the user to enter them bandwagon, in the same
way that everyone has gone for passwords that require
lower/upper/digit/symbol and (in the most annoying cases) are actually
length-limited to something stupid like 12 characters. Yes, maximum,
not minimum. Grumble.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-13 Thread Joel Goldstick
On Wed, Aug 13, 2014 at 3:24 PM, Chris Kaynor ckay...@zindagigames.com wrote:
 On Wed, Aug 13, 2014 at 4:39 AM, Eric S. Johansson e...@harvee.org wrote:

 eliminate captchas, 35+million disabled people would thank you as would
 many more millions of the not-yet-disabled like your future self.


 And so would the spammers, which is who captchas are trying to block.

 For ease-of-use, most sites only require captchas to be entered once upon
 creating the account. Some might also require additional captcha entries
 when the account is suspected of spamming. This is ultimately a trade-off of
 blocking spammers and allowing accessibility.

 Many of the better captchas also include options for an audio cue in
 addition to the default visual one.

 Chris

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

I wrote a sample form page with a simple math problem to solve -- 2 or
3 random small integers to add and put the result in a form field

def produce_expression():

return a tuple: expression (str), answer (int)

num_terms = random.randint(2,3)
operands = []
while num_terms:
n = random.randint(1,21)
operands.append(n)
num_terms -= 1

result = sum(operands)
string_operands = map(str, operands)
expression =  + .join(string_operands)
return expression, result

Its not as annoying as captcha and I think it would work with audio
browsers.  Never tested
-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-13 Thread Skip Montanaro
On Wed, Aug 13, 2014 at 2:44 PM, Joel Goldstick
joel.goldst...@gmail.com wrote:
 I wrote a sample form page with a simple math problem to solve -- 2 or
 3 random small integers to add ...

I've also seen challenge systems where they present you with a small
set of images and ask you to select one with a particular property
(looks like a tennis racquet, shaped like a square, etc). While simple
to solve for most humans -- assuming they can read the language --
they would be difficult to solve by automated means.  You can also
magnify them for visually impaired or speak what they are on
rollover/hover, and don't require any typing. They can make cultural
assumptions (not everyone will know what a tennis racquet looks like,
for instance), so the images might have to be selected carefully.

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


Re: Captcha identify

2014-08-13 Thread Tim Chase
On 2014-08-13 12:24, Chris Kaynor wrote:
 Many of the better captchas also include options for an audio cue in
 addition to the default visual one.

Have you actually tried to use the audio cue?  They're atrocious.  I
got more intelligible words out of my old 8-bit SoundBlaster or a
de-tuned radio station.  I'm all for just ditching them (and avoiding
sites that employ them).

-tkc



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


Re: Captcha identify

2014-08-13 Thread Ian Kelly
On Wed, Aug 13, 2014 at 1:43 PM, Chris Angelico ros...@gmail.com wrote:
 There are alternatives that are both easier for legit people and
 harder for spambots. Some rely on the fact that humans read things two
 dimensionally, and scripts look at the underlying structure; so, for
 instance, random field names and cunning CSS to match them up with
 their labels can result in a form that's completely messed up in the
 source, but looks perfect to a user. Or you can put extra fields down
 that you can't see if the form's laid out properly.

Chances are that if these tricks mess up a spambot, they will also
mess up a screen reader.

 Or you can combine
 those sorts of tricks with a very simple challenge-response, like
 What is one plus one? that requires some specific value to be in a
 specific field - and if that value occurs in the wrong field, you
 throw the form back to the user.

If I ask my phone What is one plus one, a very nice sounding voice
will tell me that one plus one is two. It takes some cleverness to
come up with a question that is likely to stump a machine but not
deter a human, so the pool of such questions will necessarily be
limited. Meanwhile, all the spambot has to do is flag the question for
a human to answer and store the answer somewhere, and the question is
now useless.

 For some reason, everyone's jumped on the show some mangled
 text/numbers and ask the user to enter them bandwagon, in the same
 way that everyone has gone for passwords that require
 lower/upper/digit/symbol and (in the most annoying cases) are actually
 length-limited to something stupid like 12 characters. Yes, maximum,
 not minimum. Grumble.

I've seen some captcha systems that I couldn't solve after a dozen
attempts, and I have no serious vision problems. It's a problem with
no easy solution, and as computers get more powerful the intersection
of {problems machines can't solve} and {problems humans can reliably
solve} grows ever smaller.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-13 Thread Eric S. Johansson


On 8/13/2014 3:27 PM, Chris Angelico wrote:

I agree with you, and I don't use CAPTCHAs on any of my services,
anywhere, and never have. (Partly because they *are* broken by people
writing scripts, and/or by just grinding them with human solvers; but
also because of the problems they cause for legit users, even those
with perfect eyesight.) However, the accessibility argument is one for
the removal of the captcha, *not* for its automated solving. I will
not support a scripted captcha solver for any reason. If you move away
from a site because you can't use it, so be it. If you get a chance,
tell the owner that there are alternatives to barely-readable images;
tricks involving page layouts are almost always safe, and there's
infinite room to play around in them.


your suggestion reminds me of the time I asked front range for help with 
accessibility because I had to use Goldmine on the job. Immediately 
after I asked for accessibility information, they told me they don't 
have any accessibility information because they don't have any disabled 
users.


Yes, they really did

your suggestion will probably generate a similar response.




There is no valid reason for automating something that's specifically
to prevent automation. The admin needs to provide an alternative,
instead.


There is only one valid reason based in the fact that we don't own or 
control many of the sites we depend on. Therefore, if I need to use a 
site be it government or commercial and it has a Captcha, I need to pay 
some form of cripple tax by either incurring pain or find/pay somebody 
to type for me. In this situation I thing it is perfectly acceptable to 
automate bypassing Captcha's.


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


Re: Need simple Python Script

2014-08-13 Thread Terry Reedy

On 8/13/2014 12:11 PM, taifuls...@gmail.com wrote:


I am new in Python programming.

 Currently reading the book  Learn Python the Heard Way.

The title is '... Hard Way'.  This is literally true. The author 'warns' 
beginners to not learn Python 3, which is easier to learn than Python 2, 
and works better in many ways.


Even worse, he warns people not to use Idle (or any other IDE) and use a 
plain text editor like Notepad++ and a terminal to edit and run 
programs.  This is definitely the Hard Way compared to edit and run with 
Idle.  I know from experience, because I started the way he recommends 
(editor and command prompt) and put off learning to use Idle.  What I 
fool I was.


 However i need a python script which will take

an image file (any standard format) from my windows pc as input.


Python will read any file as input: bytes are bytes.  Open non-text 
files in binary mode.  For example,


pic = open('image.jpg', 'rb')  # I believe this is the same in 2.x.

However, this is not useful unless you know the file layout and enjoy 
parsing it at the byte level.  Better to use a package that does that 
for you. For doing anything with images, you might use pillow, a 
friendly updated fork of PIL (Python Imaging Library), which works on 
2.6-7 and 3.2-4. I just did

C:\Programs\Python34pip install pillow
(I have been meaning to do this anyway) and a few seconds later it is 
installed and 'import PIL' works.


For the docs, I had to go back to
https://pypi.python.org/pypi/Pillow/2.5.2
to find the reference to
http://pillow.readthedocs.org/en/latest/

In Idle I added 'pillow' to the help menu, linked to the url above, 
using the options dialog General tab, Additional Help Sources box.


--
Terry Jan Reedy

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


Re: Captcha identify

2014-08-13 Thread Ian Kelly
On Wed, Aug 13, 2014 at 2:01 PM, Tim Chase
python.l...@tim.thechases.com wrote:
 On 2014-08-13 12:24, Chris Kaynor wrote:
 Many of the better captchas also include options for an audio cue in
 addition to the default visual one.

 Have you actually tried to use the audio cue?  They're atrocious.  I
 got more intelligible words out of my old 8-bit SoundBlaster or a
 de-tuned radio station.  I'm all for just ditching them (and avoiding
 sites that employ them).

Just like the images, if they were easy to understand then they would
be easily defeated by a spambot with a speech recognition module.  I
think the effort to make captcha systems more accessible is laudable,
if perhaps misguided.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Captcha identify

2014-08-13 Thread Chris Angelico
On Thu, Aug 14, 2014 at 6:16 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Wed, Aug 13, 2014 at 1:43 PM, Chris Angelico ros...@gmail.com wrote:
 There are alternatives that are both easier for legit people and
 harder for spambots. Some rely on the fact that humans read things two
 dimensionally, and scripts look at the underlying structure; so, for
 instance, random field names and cunning CSS to match them up with
 their labels can result in a form that's completely messed up in the
 source, but looks perfect to a user. Or you can put extra fields down
 that you can't see if the form's laid out properly.

 Chances are that if these tricks mess up a spambot, they will also
 mess up a screen reader.

They may, yes. I haven't seen a report on that. However, they're
hardly going to be worse at messing up screen readers than classic
captchas.

 Or you can combine
 those sorts of tricks with a very simple challenge-response, like
 What is one plus one? that requires some specific value to be in a
 specific field - and if that value occurs in the wrong field, you
 throw the form back to the user.

 If I ask my phone What is one plus one, a very nice sounding voice
 will tell me that one plus one is two. It takes some cleverness to
 come up with a question that is likely to stump a machine but not
 deter a human...

The point isn't the question itself, the point is that you have to put
the answer in exactly this field. The field is visually near the
challenge, but only because of CSS, and its name is randomized in some
way as to be unpredictable. If, as some spambots do, you blat the
response into lots of fields in the expectation of catching the right
one, then the form gets rejected (I don't know of anyone whose name or
email address is two, all lowercase, and if you have even a small
pool of questions, you'll get past those weird cases by having the
next question be What colour is the sky?).

 I've seen some captcha systems that I couldn't solve after a dozen
 attempts, and I have no serious vision problems. It's a problem with
 no easy solution, and as computers get more powerful the intersection
 of {problems machines can't solve} and {problems humans can reliably
 solve} grows ever smaller.

The issue isn't finding an intersection there. The issue is finding a
form of test that a computer can administer. There's a really great
test for humanness: be creative. You know that I'm a human, because
I've made posts here on python-list that are just way too complex for
a computer to synthesize. This sums up my feelings on the matter:

http://xkcd.com/810/
(Warning, language.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


how to change the time string into number?

2014-08-13 Thread luofeiyu

s=Aug

how can i change it into 8 with some python time module?
--
https://mail.python.org/mailman/listinfo/python-list


Re: how to change the time string into number?

2014-08-13 Thread Chris Angelico
On Thu, Aug 14, 2014 at 11:46 AM, luofeiyu elearn2...@gmail.com wrote:
 s=Aug

 how can i change it into 8 with some python time module?

Is this homework? If not, let me set you some homework.

Step 1: Read the docs for some Python time module.
Step 2: See if it lets you do what you want.
Step 3: Return to step 1 with a different module, until your problem is solved.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


what is the / mean in __init__(self, /, *args, **kwargs) ?

2014-08-13 Thread luofeiyu

 help(int.__init__)
Help on wrapper_descriptor:

__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.

what is the / mean in __init__(self, /, *args, **kwargs) ?

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


Re: how to change the time string into number?

2014-08-13 Thread Ben Finney
luofeiyu elearn2...@gmail.com writes:

 s=Aug

 how can i change it into 8 with some python time module?

What is your purpose here? If you want to parse a text value into a
structured time object, don't do it piece by piece. Use the
‘time.strptime’ function.

 import time
 input_time_text = 14 Aug 2014
 input_time = time.strptime(input_text, %d %b %Y)
 input_time.tm_mon
8

-- 
 \“I knew it was a shocking thing to say, but … no-one has the |
  `\right to spend their life without being offended.” —Philip |
_o__)  Pullman, 2010-03-28 |
Ben Finney

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


Re: how to change the time string into number?

2014-08-13 Thread Tim Chase
On 2014-08-14 09:46, luofeiyu wrote:
 s=Aug
 
 how can i change it into 8 with some python time module?

  import time
  s = Aug
  time.strptime(s, %b).tm_mon
 8

works for me.

-tkc


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


Re: newbee

2014-08-13 Thread Larry Hudson

On 08/12/2014 04:57 PM, Frank Scafidi wrote:

I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 
programmer back in
the 60's  70's and Python is similar. I am struggling with some very 
fundamental things that I
am not finding in the documentation. Can someone help me with the basics like 
how do I save a
program I've written, reload it in Python, list the program once it's loaded? 
How do I edit a
program? Are these command line functions?

Thanks
Frank


You've already received a lot of suggestions, but I'll add one more...

If you don't mind shelling out for some dead-tree documentation, there is a book in the Sam's 
Teach Yourself in 24 Hours series -- Python Programming for Raspberry Pi.


It is a pretty good basic tutorial for Python in general, and specifically written for the RPi. 
 You might check it out.  (Current Amazon price -- $25.81)


 -=- Larry -=-

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


Re: what is the / mean in __init__(self, /, *args, **kwargs) ?

2014-08-13 Thread Ben Finney
luofeiyu elearn2...@gmail.com writes:

  help(int.__init__)
 Help on wrapper_descriptor:

 __init__(self, /, *args, **kwargs)
 Initialize self.  See help(type(self)) for accurate signature.

 what is the / mean in __init__(self, /, *args, **kwargs) ?

I don't know, I haven't seen that before. It is confusing.

At least it is acknowledged (“See [elsewhere] for accurate signature”)
to be unhelpful.

I suspect this is an artefact of the impedance mismatch between Python
function signatures and the implementation of ‘int’ in C code. The “/”
may be a placeholder for something the C implementation requires but
that Python's function signature expectation doesn't allow.

Perhaps Python 3's keyword-only arguments may one day help functions
like that get implemented with a more useful signature, but I'm not
holding my breath for that.

-- 
 \ “Religious faith is the one species of human ignorance that |
  `\ will not admit of even the *possibility* of correction.” —Sam |
_o__) Harris, _The End of Faith_, 2004 |
Ben Finney

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


Re: what is the / mean in __init__(self, /, *args, **kwargs) ?

2014-08-13 Thread Tim Chase
On 2014-08-14 10:01, luofeiyu wrote:
   help(int.__init__)
 Help on wrapper_descriptor:
 
 __init__(self, /, *args, **kwargs)
  Initialize self.  See help(type(self)) for accurate signature.
 
 what is the / mean in __init__(self, /, *args, **kwargs) ?

Where are you seeing this?



Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type help, copyright, credits or license for more information.
 help(int.__init__)
Help on wrapper_descriptor:

__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature
 ^D


Python 3.2.3 (default, Feb 20 2013, 14:44:27) 
[GCC 4.7.2] on linux2
Type help, copyright, credits or license for more information.
 help(int.__init__)
Help on wrapper_descriptor:

__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature



-tkc


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


Re: how to change the time string into number?

2014-08-13 Thread Tim Chase
On 2014-08-13 21:01, Tim Chase wrote:
 On 2014-08-14 09:46, luofeiyu wrote:
  s=Aug
  
  how can i change it into 8 with some python time module?
 
   import time
   s = Aug
   time.strptime(s, %b).tm_mon
  8
 
 works for me.

Or, if you want a more convoluted way:

  import calendar as c
  [i for i, m in enumerate(c.month_abbr) if m == Aug].pop()
 8

-tkc



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


Re: what is the / mean in __init__(self, /, *args, **kwargs) ?

2014-08-13 Thread Ethan Furman

On 08/13/2014 07:01 PM, luofeiyu wrote:

help(int.__init__)

Help on wrapper_descriptor:

__init__(self, /, *args, **kwargs)
 Initialize self.  See help(type(self)) for accurate signature.

what is the / mean in __init__(self, /, *args, **kwargs) ?


The '/' means that all arguments before it must be positional only.  This looks like an artifact of the new Argument 
Clinic for C code.


For example, if this also worked at the Python level, you could say:

   def some_func(this, that, /, spam, eggs, *, foo, bar):
  pass

Meaning that the first two parameters could not be specified by name, the next two could be either name or position, and 
the last two by name only.


Oh, and the * is valid Python now (the / is not -- it's solely a documentation 
feature at this point).

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: what is the / mean in __init__(self, /, *args, **kwargs) ?

2014-08-13 Thread Ethan Furman

On 08/13/2014 07:12 PM, Tim Chase wrote:


Where are you seeing this?


Probably in 3.4, or the tip (what will be 3.5).

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


web2py and python3

2014-08-13 Thread Dan Stromberg
I heard there was a presentation about web2py in my area tonight.
Trying to decide if I wanted to attend, I googled about web2py and
python3.

I was amazed by what I found.  I've never seen a group so opposed to python3.

They make the old (and long-since lost) Solaris 2 wars seem tame.

I don't think I'm going to be doing web2py anytime soon.   :(  But I
was hoping it'd be a better alternative than Django for web
development.
-- 
https://mail.python.org/mailman/listinfo/python-list


a python console in bluestacks

2014-08-13 Thread luofeiyu
I have installed bluestacks(an android phone emulator) on my pc,and SL4A 
on it.Now i can run python thish way :
1.edit an file ending with |.py|, save it in 
/sdcard/sl4a/scripts/yourname.py.

2.open sl4a ,and click the file to make it run.

Is there a python console to type python command to run python directly 
such as in pc ?


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


Re: how to change the time string into number?

2014-08-13 Thread YBM

Le 14/08/2014 04:16, Tim Chase a écrit :

On 2014-08-13 21:01, Tim Chase wrote:

On 2014-08-14 09:46, luofeiyu wrote:

s=Aug

how can i change it into 8 with some python time module?


   import time
   s = Aug
   time.strptime(s, %b).tm_mon
  8

works for me.


Or, if you want a more convoluted way:

   import calendar as c
   [i for i, m in enumerate(c.month_abbr) if m == Aug].pop()
  8


it's a joke isn't it ?

 import calendar as c
 list(c.month_abbr).index('Aug')
8

BTW, why iterators does not have such an index method ?

 iter(c.month_abbr).index('Aug')
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'iterator' object has no attribute 'index'

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


Re: how to change the time string into number?

2014-08-13 Thread Ian Kelly
On Wed, Aug 13, 2014 at 8:51 PM, YBM ybm...@nooos.fr.invalid wrote:
 BTW, why iterators does not have such an index method ?

Because iterators don't support indexing. In order to support such a thing,
it would have to exhaust the iterator.

 iter(range(5))[3]
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'range_iterator' object is not subscriptable

The only methods you can rely upon an arbitrary iterator to have are
__iter__ and __next__.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: web2py and python3

2014-08-13 Thread Chris Angelico
On Thu, Aug 14, 2014 at 12:21 PM, Dan Stromberg drsali...@gmail.com wrote:
 I don't think I'm going to be doing web2py anytime soon.   :(  But I
 was hoping it'd be a better alternative than Django for web
 development.

I'm no expert on Python web frameworks, but the only one that I've
used seems to be pretty decent: Flask. I'm happy with it. It's
light-weight, it gets the job done, it doesn't much get in the way. If
someone's going to hate Py3, ignore 'em and go somewhere else.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to change the time string into number?

2014-08-13 Thread Roy Smith
In article 53ec2453$0$2299$426a7...@news.free.fr,
 YBM ybm...@nooos.fr.invalid wrote:

 Le 14/08/2014 04:16, Tim Chase a écrit :
  On 2014-08-13 21:01, Tim Chase wrote:
  On 2014-08-14 09:46, luofeiyu wrote:
  s=Aug
 
  how can i change it into 8 with some python time module?
 
 import time
 s = Aug
 time.strptime(s, %b).tm_mon
8
 
  works for me.
 
  Or, if you want a more convoluted way:
 
 import calendar as c
 [i for i, m in enumerate(c.month_abbr) if m == Aug].pop()
8
 
 it's a joke isn't it ?

No, it's a song.

If I could save time in a bottle
The first thing that I'd like to do
Is to make every month be an integer number
And then I could count them with you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what is the / mean in __init__(self, /, *args, **kwargs) ?

2014-08-13 Thread Ben Finney
Tim Chase python.l...@tim.thechases.com writes:

 On 2014-08-14 10:01, luofeiyu wrote:
help(int.__init__)
  Help on wrapper_descriptor:
  
  __init__(self, /, *args, **kwargs)
   Initialize self.  See help(type(self)) for accurate signature.
  
  what is the / mean in __init__(self, /, *args, **kwargs) ?

 Where are you seeing this?

I see the same output as ‘luofeiyu’ reports. My Python is::

 sys.version
'3.4.1 (default, Jul 26 2014, 13:46:45) \n[GCC 4.9.1]'

-- 
 \“Stop — Drive sideways.” —detour sign, Kyushu, Japan |
  `\   |
_o__)  |
Ben Finney

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


Re: what is the / mean in __init__(self, /, *args, **kwargs) ?

2014-08-13 Thread Terry Reedy

On 8/13/2014 10:20 PM, Ethan Furman wrote:

On 08/13/2014 07:01 PM, luofeiyu wrote:

help(int.__init__)

Help on wrapper_descriptor:

__init__(self, /, *args, **kwargs)
 Initialize self.  See help(type(self)) for accurate signature.

what is the / mean in __init__(self, /, *args, **kwargs) ?


The '/' means that all arguments before it must be positional only.


In particular, int.__init__(self = subclass instance) will not work 
because 'self' is positional only. (I don't think int.__init__ actually 
does anything, but a subclass of int might call it.)



This looks like an artifact of the new Argument Clinic for C code.

For example, if this also worked at the Python level, you could say:

def some_func(this, that, /, spam, eggs, *, foo, bar):
   pass

Meaning that the first two parameters could not be specified by name,
the next two could be either name or position, and the last two by name
only.

Oh, and the * is valid Python now (the / is not -- it's solely a
documentation feature at this point).


I hope / will be valid Python in 3.5.

--
Terry Jan Reedy

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


[OT] Awesome bug of the week

2014-08-13 Thread Steven D'Aprano
Nothing to do with Python, but awesome: OpenOffice won't print on 
Tuesdays.

https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/255161/comments/28



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


Optional static typing

2014-08-13 Thread Steven D'Aprano
The BDFL Guido van Rossum is considering optional static typing (ish) for 
Python 3.5:

https://mail.python.org/pipermail/python-ideas/2014-August/028618.html



Does anyone here use function annotations? If so, what do you use them 
for?


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


Re: [OT] Awesome bug of the week

2014-08-13 Thread Xavier Ho
Haha!


On 14 August 2014 14:54, Steven D'Aprano st...@pearwood.info wrote:

 Nothing to do with Python, but awesome: OpenOffice won't print on
 Tuesdays.

 https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/255161/comments/28



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

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


Re: how to change the time string into number?

2014-08-13 Thread Marko Rauhamaa
Tim Chase python.l...@tim.thechases.com:

 Or, if you want a more convoluted way:

   import calendar as c
   [i for i, m in enumerate(c.month_abbr) if m == Aug].pop()
  8

Let's not forget the much simpler solutions:

 def eight(x): return 8
...
 eight(Aug)
8

and:

 8
8


BTW, is this a bug:

import locale
locale.getlocale()
   ('de_DE', 'UTF-8')
import time
time.strptime(Dez, %b).tm_mon
   Traceback (most recent call last):
 File stdin, line 1, in module
 File /usr/lib/python3.2/_strptime.py, line 482, in _strptime_time
   tt = _strptime(data_string, format)[0]
 File /usr/lib/python3.2/_strptime.py, line 337, in _strptime
   (data_string, format))
   ValueError: time data 'Dez' does not match format '%b'
time.strftime(%b, time.localtime(time.time() + 120 * 86400))
   'Dec'
time.strftime(%x)
   '08/14/14'

After all, %b is documented as Locale’s abbreviated month name.

Anyway, %b *should* depend on the locale, so str[pf]time may not be
suitable to deal with email dates, for example.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue20729] mailbox.Mailbox does odd hasattr() check

2014-08-13 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 5fd1f8271e8a by Serhiy Storchaka in branch '3.4':
Issue #20729: Restored the use of lazy iterkeys()/itervalues()/iteritems()
http://hg.python.org/cpython/rev/5fd1f8271e8a

New changeset acb30ed7eceb by Serhiy Storchaka in branch 'default':
Issue #20729: Restored the use of lazy iterkeys()/itervalues()/iteritems()
http://hg.python.org/cpython/rev/acb30ed7eceb

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20729
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22189] collections.UserString missing some str methods

2014-08-13 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
assignee:  - rhettinger
components: +Library (Lib)
nosy: +rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22189
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22190] Integrate tracemalloc into regrtest refleak hunting

2014-08-13 Thread Nick Coghlan

New submission from Nick Coghlan:

Trying to debug issue #22166, I realised it would be nice if there was an easy 
way to use tracemalloc to get a clear idea of *what's* leaking when regrtest -R 
reports a refleak.

For that specific issue, I'm just trying to hack something together as a 
learning experience, but it would be good to have something more sophisticated 
built in to regrtest.

--
components: Tests
messages: 225257
nosy: haypo, ncoghlan, neologix, zach.ware
priority: normal
severity: normal
stage: needs patch
status: open
title: Integrate tracemalloc into regrtest refleak hunting
type: enhancement
versions: Python 3.4, Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22190
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22190] Integrate tracemalloc into regrtest refleak hunting

2014-08-13 Thread Ezio Melotti

Ezio Melotti added the comment:

Isn't this the same as #19816?

--
nosy: +ezio.melotti

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22190
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16773] int() half-accepts UserString

2014-08-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Looks as there is no easy fix of this issue. This issue is particular case of 
issue232493.

--
resolution:  - duplicate
stage: needs patch - resolved
status: open - closed
superseder:  - UserString can not be used as string in calls to C routines

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16773
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20729] mailbox.Mailbox does odd hasattr() check

2014-08-13 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
resolution:  - fixed
stage: patch review - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20729
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22157] FAIL: test_with_pip (test.test_venv.EnsurePipTest)

2014-08-13 Thread snehal

snehal added the comment:

/home/python/Python-3.4.1/Modules/_ctypes/libffi/config.guess: unable to guess 
system type

This script, last modified 2012-12-29, has failed to recognize
the operating system you are using. It is advised that you
download the most up to date version of the config scripts from

  
http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
and
  
http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD

If the version you run 
(/home/python/Python-3.4.1/Modules/_ctypes/libffi/config.guess) is already up 
to date, please
send the following data and any information you think might be
pertinent to config-patc...@gnu.org in order to provide the needed
information to handle your system.

config.guess timestamp = 2012-12-29

uname -m = ppc64le
uname -r = 3.13-1-powerpc64le
uname -s = Linux
uname -v = #1 SMP Debian 3.13.4-1 (2014-02-22)

/usr/bin/uname -p = 
/bin/uname -X = 

hostinfo   = 
/bin/universe  = 
/usr/bin/arch -k   = 
/bin/arch  = 
/usr/bin/oslevel   = 
/usr/convex/getsysinfo = 

UNAME_MACHINE = ppc64le
UNAME_RELEASE = 3.13-1-powerpc64le
UNAME_SYSTEM  = Linux
UNAME_VERSION = #1 SMP Debian 3.13.4-1 (2014-02-22)
configure: error: cannot guess build type; you must specify one

--
I tried modifying config.guess for ppc65le , and did run configure and make 
again... after which I got following 


Could not find platform dependent libraries exec_prefix
Consider setting $PYTHONHOME to prefix[:exec_prefix]
/usr/bin/ld: 
build/temp.linux-ppc64le-3.4/home/python/Python-3.4.1/Modules/_ctypes/libffi/src/powerpc/linux64.o:
 ABI version 1 is not compatible with ABI version 2 output
/usr/bin/ld: failed to merge target specific data of file 
build/temp.linux-ppc64le-3.4/home/python/Python-3.4.1/Modules/_ctypes/libffi/src/powerpc/linux64.o
/usr/bin/ld: 
build/temp.linux-ppc64le-3.4/home/python/Python-3.4.1/Modules/_ctypes/libffi/src/powerpc/linux64_closure.o:
 ABI version 1 is not compatible with ABI version 2 output
/usr/bin/ld: failed to merge target specific data of file 
build/temp.linux-ppc64le-3.4/home/python/Python-3.4.1/Modules/_ctypes/libffi/src/powerpc/linux64_closure.o

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22157
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22034] posixpath.join() and bytearray

2014-08-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Copied nosy list from issue15180 and issue15377.

--
nosy: +Arfrever, chris.jerdonek, eric.araujo, georg.brandl, pitrou, 
r.david.murray, terry.reedy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22034
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22065] Update turtledemo menu creation

2014-08-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Terry?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22065
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >