makefile based python build

2013-02-12 Thread Antonio Cavallo


Hi,

I'm releasing my first attempt to cross compile python on android using 
a simple makefile based build system:


  https://bitbucket.org/cavallo71/android

As side effect it can also build on a gcc based system as (linux so far).

The attempt was started in order to simplify the build system and cross 
compiling modules. In future the hope is to remove distutils package and 
clear other modules (notably sysconfig.py and site.py).


Thanks
Antonio
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: Training - Professional Testing with pytest and tox

2013-02-12 Thread Mike Müller
Professional Testing with pytest and tox


What: An in-depth pytest and tox course
When: June 24 - 26, 2013
Where: Python Academy, Leipzig, Germany
Who: Holger Krekel
Details:
http://www.python-academy.com/courses/specialtopics/python_course_testing.html

You always write tests for your code, even before you write the
code itself, right? If yes, than you can learn how to do this with
the help of pytest [1] and tox [2]. These smart Python tools help you
to make your tests better. If you don't write tests yet, you can learn
how to do this on a professional level right from the beginning.

Join Holger Krekel, the author of pytest and tox, when he explains
how to integrate testing and deployment using real-world examples.
Learn what it means to do pythonic testing by taking advantage of
Python's philosophy to make simple things simple and complex things
possible. Bring your own problems to be discussed in the course.

The course is offered in Leipzig, Germany. This city has about half
a million inhabitants and  provides a very rich cultural life.
It was the home of the first two PyCon DE conferences in 2011 and 2012.
The teaching location can be easily reached via car or public
transportation. Leipzig is very well connected to the German Autobahn
and railway systems. The airport is only 15 taxi minutes away from the
training location. There are plenty of reasonably priced hotels nearby.


[1] http://pytest.org/latest/
[2] http://codespeak.net/tox/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: Twisted Training - Three days to untwist the framework

2013-02-12 Thread Mike Müller
Twisted Training


What: An in-depth Twisted course
When: September 9 - 11, 2013
Where: Python Academy, Leipzig, Germany
Who: Laurens Van Houtven
Details:
http://www.python-academy.com/courses/specialtopics/python_course_twisted.html

Twisted [1] is a powerful framework to develop network applications
of all kinds. Since the way it works is somewhat different from
the typical Python programming style, it might not be that easy to
take full advantage of all the power that comes with Twisted.

This course gives a solid introduction and takes you deep into the
land of deferreds, callbacks and events. Learn from the Twisted
committer Laurens Van Houtven how to integrate Twisted into
existing, non-Twisted applications. Inherited some Twisted code
and feel kind of lost? This training will help you to understand
what is going on.

The course is offered in Leipzig, Germany. This city has about half
a million inhabitants and  provides a very rich cultural life.
It was the home of the first two PyCon DE conferences in 2011 and 2012.
The teaching location can be easily reached via car or public
transportation. Leipzig is very well connected to the German Autobahn
and railway systems. The airport is only 15 taxi minutes from the
training location. There are plenty of reasonably priced hotels nearby.


[1] http://twistedmatrix.com/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: LangWart: Method congestion from mutate multiplicty

2013-02-12 Thread Jean-Michel Pichavant


 Yeah, this is, pardon the french, just batshit crazy. 

huh ? :)


JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Web Testing Frameworks

2013-02-12 Thread Greg Lindstrom
Hello,

I'm not wanting to start anything here, but I am wanting to automate
testing of my Django-based websites.  A quick search on Google turns up a
number of packages and I would like to know if any stand out from the
others?  Our main sites are used to display a customer dashboard, so my
concerns are is the site up and assessable, are the proper navigational
tabs displayed and is the appropriate information presented when I fill out
a request.  My guess is that is pretty standard for testing a web site?

So,

1.  What framework(s) should I look at?
2.  Where can I get information/documentation/training on how to test a web
site?

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


Re: LangWart: Method congestion from mutate multiplicty

2013-02-12 Thread Chris Angelico
On Mon, Feb 11, 2013 at 8:52 PM, Jean-Michel Pichavant
jeanmic...@sequans.com wrote:

 Yeah, this is, pardon the french, just batshit crazy.

 huh ? :)

You're French, ergo you are pardoned. Makes good sense to me!

:)

ChrisA
Cheshire was right, we're all mad here...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: call from pthon to shell

2013-02-12 Thread Andrew Robinson

On 02/12/2013 05:38 AM, Bqsj Sjbq wrote:

 import os
 os.system(i=3)
0
 os.system(echo $i)

0

why i can not get the value of i?



First:
os.system is only defined to give the return value (exit code) of the 
sub-process.


However, one way to get the output of shell commands is to use subprocess.

import subprocess
x = subprocess.check_output( [ echo, 3,5,7 ] )

However, bash built-ins are not executables; nor is shell expansion 
performed; so you will actually need to do something like:

x=subprocess.check_output( [ bash, -c, i=3; echo $i ] )
 x
 '3\n'

To get the result you're interested in.
There may be better ways to get the result you want but hopefully 
you understand the problem better.


:)


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


Re: call shell from python

2013-02-12 Thread spilcm
On Tuesday, February 12, 2013 6:13:38 AM UTC+1, contro opinion wrote:
  import os
  os.system(i=3)
 0
  os.system(echo $i)
 
 
 0
 how can i get the value of  i?

You may want to take a look at the pexcpect module : 
http://www.noah.org/wiki/pexpect
-- 
http://mail.python.org/mailman/listinfo/python-list


UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Magnus Pettersson
I am using Eclipse to write my python scripts and when i run them from inside 
eclipse they work fine without errors. 

But almost in every script that handle some form of special characters like 
swedish åäö and chinese characters etc i get Unicode errors when running the 
script externally with python.exe or pythonw.exe (but the scripts run 
completely fine from within Eclipse (standard pydev projects, python2.7). I 
have usually launched the script gui from wihin eclipse because of this error 
but now i want to get the bottom of this so i dont have to open eclipse 
everytime i want to run a script!

Here is the error i get now when running the script with python.exe:
UnicodeEncodeError:'charmap' codec cant encode character u'\u898b' in position 
32: character maps to undefined

what can i do to fix this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Andrew Berg
On 2013.02.12 04:43, Magnus Pettersson wrote:
 I am using Eclipse to write my python scripts and when i run them from inside 
 eclipse they work fine without errors. 
 
 But almost in every script that handle some form of special characters like 
 swedish åäö and chinese characters etc i get Unicode errors when running the 
 script externally with python.exe or pythonw.exe (but the scripts run 
 completely fine from within Eclipse (standard pydev projects, python2.7). I 
 have usually launched the script gui from wihin eclipse because of this error 
 but now i want to get the bottom of this so i dont have to open eclipse 
 everytime i want to run a script!
 
 Here is the error i get now when running the script with python.exe:
 UnicodeEncodeError:'charmap' codec cant encode character u'\u898b' in 
 position 32: character maps to undefined
 
 what can i do to fix this?
 
Since you didn't say what code actually does this, I'll turn to my
crystal ball. It says you are trying to print characters to a terminal
that doesn't support them. If that is the case, you could try changing
the code page (but only 3.3 supports cp65001, so that probably won't
help) or use replacement characters when printing.

-- 
CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to call shell?

2013-02-12 Thread Albert Hopkins


On Tue, Feb 12, 2013, at 12:12 AM, contro opinion wrote:
  import os
  os.system(i=3)
 0
  os.system(echo $i)
 
 0
 
 why i can't get the value of i ?

Whenever you call os.system, a new shell is created and the command is
run, system() then waits for the command to complete.
You don't see i because your two system() calls are in two different
processes:

python import os
python os.system('echo $$')
24294
0
python os.system('echo $$')
24295
0

However, ths (e.g.) would work:

python os.system('i=3; echo $i')
3
0

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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Steven D'Aprano
Magnus Pettersson wrote:

 I am using Eclipse to write my python scripts and when i run them from
 inside eclipse they work fine without errors.
 
 But almost in every script that handle some form of special characters
 like swedish åäö and chinese characters etc

A comment: they are not special characters. They're merely not American.


 i get Unicode errors when 
 running the script externally with python.exe or pythonw.exe (but the
 scripts run completely fine from within Eclipse (standard pydev projects,
 python2.7). I have usually launched the script gui from wihin eclipse
 because of this error but now i want to get the bottom of this so i dont
 have to open eclipse everytime i want to run a script!
 
 Here is the error i get now when running the script with python.exe:
 UnicodeEncodeError:'charmap' codec cant encode character u'\u898b' in
 position 32: character maps to undefined

Please show the *complete* traceback, including the line of code that causes
the exception.

 
 what can i do to fix this?

My guess is that you are trying to print a character which your terminal
cannot display. My terminal is set to use UTF-8, and so it can display it
fine:

py c = u'\u898b'
py print(c)
見


(or at least it would display fine if the font used had a glyph for that
character). Why there are still terminals in the world that don't default
to UTF-8 is beyond me.

If I manually change the terminal's encoding to Western European ISO 8859-1,
I get some moji-bake:

py print(c)
è¦


I can't replicate the exception you give, so I assume it is specific to
Windows.




-- 
Steven

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


Python3 exec locals - this must be a FAQ

2013-02-12 Thread Helmut Jarausch
Hi,

I've tried but didn't find an answer on the net.

The exec function in Python modifies a copy of locals() only.
How can I transfer changes in that local copy to the locals of my function
** without **  knowing the names of these variables.

E.g.  I have a lot of local names.

Doing

_locals= locals()
expr=compile(input('statements assigning to some local variables '),
 'user input','exec')
exec(expr,globals(),_locals)

How can I copy the new values within _locals to my current locals.

If I knew that  Var1  has changed I could say
Var1 = _locals['Var1'] but what to do in general?

Many thanks for a hint,
Helmut.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Magnus Pettersson
Ahh so its the actual printing that makes it error out outside of eclipse 
because its a different terminal that its printing to. Its the default DOS 
terminal in windows that runs then i run the script with python.exe and i guess 
its the same when i run with pythonw.exe just that the terminal window is not 
opened up, only the pyqt gui in this case.

I will try to fix it now when i know what it is :)

I never thought about the terminal, last time i had the same problem i just 
were playing around for hours with unicode encode and decode and all that 
not-so-fun stuff :)

Andrew Berg: Thanks, your crystal ball seems to be right :P

On Tuesday, February 12, 2013 12:43:00 PM UTC+1, Steven D'Aprano wrote:
 Magnus Pettersson wrote:
 
 
 
  I am using Eclipse to write my python scripts and when i run them from
 
  inside eclipse they work fine without errors.
 
  
 
  But almost in every script that handle some form of special characters
 
  like swedish åäö and chinese characters etc
 
 
 
 A comment: they are not special characters. They're merely not American.
 
 
 
 
 
  i get Unicode errors when 
 
  running the script externally with python.exe or pythonw.exe (but the
 
  scripts run completely fine from within Eclipse (standard pydev projects,
 
  python2.7). I have usually launched the script gui from wihin eclipse
 
  because of this error but now i want to get the bottom of this so i dont
 
  have to open eclipse everytime i want to run a script!
 
  
 
  Here is the error i get now when running the script with python.exe:
 
  UnicodeEncodeError:'charmap' codec cant encode character u'\u898b' in
 
  position 32: character maps to undefined
 
 
 
 Please show the *complete* traceback, including the line of code that causes
 
 the exception.
 
 
 
  
 
  what can i do to fix this?
 
 
 
 My guess is that you are trying to print a character which your terminal
 
 cannot display. My terminal is set to use UTF-8, and so it can display it
 
 fine:
 
 
 
 py c = u'\u898b'
 
 py print(c)
 
 見
 
 
 
 
 
 (or at least it would display fine if the font used had a glyph for that
 
 character). Why there are still terminals in the world that don't default
 
 to UTF-8 is beyond me.
 
 
 
 If I manually change the terminal's encoding to Western European ISO 8859-1,
 
 I get some moji-bake:
 
 
 
 py print(c)
 
 è¦
 
 
 
 
 
 I can't replicate the exception you give, so I assume it is specific to
 
 Windows.
 
 
 
 
 
 
 
 
 
 -- 
 
 Steven

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


Generate 16+MAX_WBITS decompressable data

2013-02-12 Thread Fayaz Yusuf Khan
I'm trying write unit-tests for some of my old code and have run into this 
piece of code.

dcomp = zlib.decompressobj(16+zlib.MAX_WBITS)
chunk = ''.join(f.chunks())
received_data =  dcomp.decompress(chunk)

How do I generate the chunk here? From what I've been trying I'm getting 
this exception:
 import zlib
 zlib.compress('hello')
'x\x9c\xcbH\xcd\xc9\xc9\x07\x00\x06,\x02\x15'
 zlib.decompress(_, 16+zlib.MAX_WBITS)
Traceback (most recent call last):
  File stdin, line 1, in module
zlib.error: Error -3 while decompressing data: incorrect header check

zlib.decompress without the second argument works, but I can't really go 
ahead into my project file and remove it.
-- 
Fayaz Yusuf Khan
Cloud architect, Dexetra SS, India
fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com
+91-9746-830-823

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


how to add socks proxy feature to script based on requests module?

2013-02-12 Thread xliiv
Hi!

I've go a script which uses python requests 
(http://docs.python-requests.org/en/latest/).

I need to add to it socks proxy feature.

AFAIK requests doesn't support socks proxy 
(http://stackoverflow.com/questions/12601316/how-to-make-python-requests-work-via-socks-proxy)
 so i was about to switch requests module to human_curl 
(http://stackoverflow.com/questions/8482896/making-http-requests-via-python-requests-module-not-working-via-proxy-where-curl).
Then it turned out that human_curl doesn't support requests module's session.

Ok, what can You recommend me to do? I need the best solution for adding socks 
proxy feature to script (based on requests module).

if nothing better is recommended i'll clone requests' module session feature 
in human_curl.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3 exec locals - this must be a FAQ

2013-02-12 Thread Dave Angel

On 02/12/2013 06:46 AM, Helmut Jarausch wrote:

Hi,

I've tried but didn't find an answer on the net.

The exec function in Python modifies a copy of locals() only.
How can I transfer changes in that local copy to the locals of my function
** without **  knowing the names of these variables.

E.g.  I have a lot of local names.

Doing

_locals= locals()


This doesn't copy everything.  But perhaps you know that and you're just 
testing us.



expr=compile(input('statements assigning to some local variables '),
  'user input','exec')
exec(expr,globals(),_locals)

How can I copy the new values within _locals to my current locals.

If I knew that  Var1  has changed I could say
Var1 = _locals['Var1'] but what to do in general?


locals()[Var1] = _locals[Var1]  will set the same Var1 local.

So you might write a loop on _locals.

But beware if someone has deleted one of the variables it may not do 
what you'd like.  You cannot necessarily add back a local with the above 
syntax.



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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Magnus Pettersson
I have tried now to take away printing to terminal and just keeping the writing 
to a .txt file to disk (which is what the scripts purpose is):

with open(filepath,a) as f:
for card in cardlist:
f.write(card+\n)

The file it writes to exists and im just appending to it, but when i run the 
script trough eclipse, all is fine. When i run in terminal i get this error 
instead:

File K:\dev\python\webscraping\kanji_anki.py, line 69, in savefile
f.write(card+\n)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u898b' in position 3
2: ordinal not in range(128)

On Tuesday, February 12, 2013 12:01:19 PM UTC+1, Andrew Berg wrote:
 On 2013.02.12 04:43, Magnus Pettersson wrote:
 
  I am using Eclipse to write my python scripts and when i run them from 
  inside eclipse they work fine without errors. 
 
  
 
  But almost in every script that handle some form of special characters like 
  swedish åäö and chinese characters etc i get Unicode errors when running 
  the script externally with python.exe or pythonw.exe (but the scripts run 
  completely fine from within Eclipse (standard pydev projects, python2.7). I 
  have usually launched the script gui from wihin eclipse because of this 
  error but now i want to get the bottom of this so i dont have to open 
  eclipse everytime i want to run a script!
 
  
 
  Here is the error i get now when running the script with python.exe:
 
  UnicodeEncodeError:'charmap' codec cant encode character u'\u898b' in 
  position 32: character maps to undefined
 
  
 
  what can i do to fix this?
 
  
 
 Since you didn't say what code actually does this, I'll turn to my
 
 crystal ball. It says you are trying to print characters to a terminal
 
 that doesn't support them. If that is the case, you could try changing
 
 the code page (but only 3.3 supports cp65001, so that probably won't
 
 help) or use replacement characters when printing.
 
 
 
 -- 
 
 CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3 exec locals - this must be a FAQ

2013-02-12 Thread Helmut Jarausch
On Tue, 12 Feb 2013 08:27:41 -0500, Dave Angel wrote:

 On 02/12/2013 06:46 AM, Helmut Jarausch wrote:
 Hi,

 I've tried but didn't find an answer on the net.

 The exec function in Python modifies a copy of locals() only.
 How can I transfer changes in that local copy to the locals of my
 function ** without **  knowing the names of these variables.

 E.g.  I have a lot of local names.

 Doing

 _locals= locals()
 
 This doesn't copy everything.  But perhaps you know that and you're just
 testing us.

No, I didn't know. And I'm bit surprised since this is recommend
several times, e.g. in Python Essential Reference, 4th ed by
David Beazley.

 
 expr=compile(input('statements assigning to some local variables '),
   'user input','exec')
 exec(expr,globals(),_locals)

 How can I copy the new values within _locals to my current locals.

 If I knew that  Var1  has changed I could say Var1 = _locals['Var1']
 but what to do in general?
 
 locals()[Var1] = _locals[Var1]  will set the same Var1 local.

Thanks for this hint which surprises me again since I thought
locals() by itself is a copy only.

 
 So you might write a loop on _locals.
 
 But beware if someone has deleted one of the variables it may not do
 what you'd like.  You cannot necessarily add back a local with the above
 syntax.

Does this mean that adding something completely new won't work?

Many thanks,
Helmut.

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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Peter Otten
Magnus Pettersson wrote:

 I have tried now to take away printing to terminal and just keeping the
 writing to a .txt file to disk (which is what the scripts purpose is):
 
 with open(filepath,a) as f:
 for card in cardlist:
 f.write(card+\n)
 
 The file it writes to exists and im just appending to it, but when i run
 the script trough eclipse, all is fine. When i run in terminal i get this
 error instead:
 
 File K:\dev\python\webscraping\kanji_anki.py, line 69, in savefile
 f.write(card+\n)
 UnicodeEncodeError: 'ascii' codec can't encode character u'\u898b' in
 position 3 2: ordinal not in range(128)

Are you sure you are writing the same data? That would mean that pydev 
changes the default encoding -- which is evil.

A portable approach would be to use codecs.open() or io.open() instead of 
the built-in:

import io
with io.open(filepath, a) as f:
...

io.open() uses UTF-8 by default, but you can specify other encodings with
io.open(filepath, mode, encoding=whatever).

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


A newbie question

2013-02-12 Thread Alberto Salvati
Hi, All.
I'm a (old) delphi developer.
I want to learn Python.
I've python 2.7 and django.
For learning purpose I want to use firebird.
But, package (egg) to use firebird needs easy_install for setup.
When i run:

python ez_setup.py install

python says me error:

Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-p
y2.7.egg
Searching for install
Reading http://pypi.python.org/simple/install/
Couldn't find index page for 'install' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for install
Best match: None
Traceback (most recent call last):
  File ez_setup.py, line 278, in module
main(sys.argv[1:])
  File ez_setup.py, line 213, in main
return main(list(argv)+[egg])   # we're done here
  File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 1712, in main
  File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 1700, in with_ei_usage
  File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 1716, in lambda
  File C:\Python27\lib\distutils\core.py, line 152, in setup
dist.run_commands()
  File C:\Python27\lib\distutils\dist.py, line 953, in run_commands
self.run_command(cmd)
  File C:\Python27\lib\distutils\dist.py, line 972, in run_command
cmd_obj.run()
  File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 211, in run
  File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 434, in easy_install
  File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\package_index
.py, line 475, in fetch_distribution
AttributeError: 'NoneType' object has no attribute 'clone'


In download site I get info about installer works only on win32, but I'm uisng 
64 bit version, so I need to do setup manually.

Searching error, I see a lot of message baout errors AFTER easy_install was 
done.
Also, I see that some link used in python file does'nt exist or is broken.

TIA for any suggestion.

A.




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


Re: Awsome Python - chained exceptions

2013-02-12 Thread Terry Reedy

On 2/12/2013 1:15 AM, Steven D'Aprano wrote:

As an antidote to the ill-informed negativity of Ranting Rick's
illusionary PyWarts, I thought I'd present a few of Python's more
awesome features, starting with exception contexts.


You do not need Rick to justify such an informative post.


If you've ever written an exception handler, you've probably written a
*buggy* exception handler:


def getitem(items, index):
 # One-based indexing.
 try:
 return items[index-1]
 except IndexError:
 print (Item at index %d is missing % index - 1)  # Oops!


Unfortunately, when an exception occurs inside an except or finally
block, the second exception masks the first, and the reason for the
original exception is lost:

py getitem(['one', 'two', 'three'], 5)  # Python 2.6
Traceback (most recent call last):
   File stdin, line 1, in module
   File stdin, line 6, in getitem
TypeError: unsupported operand type(s) for -: 'str' and 'int'


But never fear! In Python 3.1 and better, Python now shows you the full
chain of multiple exceptions, and exceptions grow two new special
attributes: __cause__ and __context__.


Some thought was given to having only one special attribute, but in the 
end it was decided to have __context__ be the actual context and 
__cause__ be the programmer set and displayed 'context'.



If an exception occurs while handling another exception, Python sets the
exception's __context__ and displays an extended error message:

py getitem(['one', 'two', 'three'], 5)  # Python 3.1
Traceback (most recent call last):
   File stdin, line 4, in getitem
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   File stdin, line 1, in module
   File stdin, line 6, in getitem
TypeError: unsupported operand type(s) for -: 'str' and 'int'

Python 3 also allows you to explicitly set the exception's __cause__
using raise...from syntax:

py try:
... len(None)
... except TypeError as e:
... raise ValueError('bad value') from e
...
Traceback (most recent call last):
   File stdin, line 2, in module
TypeError: object of type 'NoneType' has no len()

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
   File stdin, line 4, in module
ValueError: bad value

Note the slight difference in error message. If both __cause__ and
__context__ are set, the __cause__ takes priority.

Sometimes you actually want to deliberately catch one exception and raise
another, without showing the first exception. A very common idiom in
Python 2:

try:
 do_work()
except SomeInternalError:
 raise PublicError(error_message)

Starting with Python 3.3, there is now support from intentionally
suppressing the __context__:

py try:
... len(None)
... except TypeError:
... raise ValueError('bad value') from None  # Python 3.3
...
Traceback (most recent call last):
   File stdin, line 4, in module
ValueError: bad value

The new features are explained in the Library manual, Ch. 5, Exceptions, 
but without so many clear examples. The 'from None' option has not yet 
been added to the Language reference section on raise statements (an 
issue on the tracker), so it is easy to miss if one does not also read 
the Library chapter.


You can read more about exception chaining here:

http://www.python.org/dev/peps/pep-3134/
http://www.python.org/dev/peps/pep-0409/


--
Terry Jan Reedy

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


Re: Python3 exec locals - this must be a FAQ

2013-02-12 Thread MRAB

On 2013-02-12 13:27, Dave Angel wrote:

On 02/12/2013 06:46 AM, Helmut Jarausch wrote:

Hi,

I've tried but didn't find an answer on the net.

The exec function in Python modifies a copy of locals() only.
How can I transfer changes in that local copy to the locals of my function
** without **  knowing the names of these variables.

E.g.  I have a lot of local names.

Doing

_locals= locals()


This doesn't copy everything.  But perhaps you know that and you're just
testing us.


expr=compile(input('statements assigning to some local variables '),
  'user input','exec')
exec(expr,globals(),_locals)

How can I copy the new values within _locals to my current locals.

If I knew that  Var1  has changed I could say
Var1 = _locals['Var1'] but what to do in general?


locals()[Var1] = _locals[Var1]  will set the same Var1 local.

So you might write a loop on _locals.

But beware if someone has deleted one of the variables it may not do
what you'd like.  You cannot necessarily add back a local with the above
syntax.


The docs for locals() warns The contents of this dictionary should
not be modified; changes may not affect the values of local and free
variables used by the interpreter.

That's because local variables in a function are implemented (at least
in CPython) using 'slots' for efficiency reasons.

 def example():
a = 1
print(a is {}, locals() is {}.format(a, locals()))
print(Changing a to 2 directly)
a = 2
print(a is {}, locals() is {}.format(a, locals()))
print(Changing a to 3 via locals())
locals()[a] = 3
print(a is {}, locals() is {}.format(a, locals()))
locals()[b] = 0
print(locals() is {}.format(locals()))
print(b is {}.format(b))

 example()
a is 1, locals() is {'a': 1}
Changing a to 2 directly
a is 2, locals() is {'a': 2}
Changing a to 3 via locals()
a is 2, locals() is {'a': 2}
locals() is {'b': 0, 'a': 2}
Traceback (most recent call last):
  File pyshell#39, line 1, in module
example()
  File pyshell#38, line 12, in example
print(b is {}.format(b))
NameError: global name 'b' is not defined

Note how attempting to change variable a in locals() is ignored, and
how adding variable b to locals() doesn't actually make it a local
variable (it raises a NameError).

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


Re: string.replace doesn't removes :

2013-02-12 Thread vduncan80
On Sunday, February 10, 2013 4:36:53 AM UTC-6, Johannes Bauer wrote:
 On 09.02.2013 12:04, Joshua Robinson wrote:
 
  Hi *Monte-Pythons*,
 
  
 
  x = this is a simple : text: that has colon
 
  s = x.replace(string.punctuation, );  OR
 
  s = x.replace(string.punctuation, );
 
  print x   # 'this is a simple : text: that has colon'
 
  # The colon is still in the text 
 
  
 
  Is this a bug or am I doing something wrong ?
 
 
 
 The latter. str.replace() only replaces complete substrings, not single
 
 character occurences of the given pattern. That is
 
 
 
 foo.replace(foo, bar) == bar
 
 foofoo.replace(foo, bar) == barbar
 
 foofoo.replace(fo, bar) == barobaro
 
 foofoo.replace(abcdef, bar) == foofoo
 
 
 
 Regards,
 
 Johannes
 
 
 
 -- 
 
  Wo hattest Du das Beben nochmal GENAU vorhergesagt?
 
  Zumindest nicht öffentlich!
 
 Ah, der neueste und bis heute genialste Streich unsere großen
 
 Kosmologen: Die Geheim-Vorhersage.
 
  - Karl Kaos über Rüdiger Thomas in dsa hidbv3$om2$1...@speranza.aioe.org

Hello Joshua:

Hopefully you have worked out the issue.  Johannes is right on the money using 
'replace' as shown below.

x = this is a simple : text: that has colon
s = x.replace(:, )
print(s)
'this is a simple  text that has colon'

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


Re: Web Testing Frameworks

2013-02-12 Thread John Gordon
In mailman.1689.1360655922.2939.python-l...@python.org Greg Lindstrom 
gslindst...@gmail.com writes:

 I'm not wanting to start anything here, but I am wanting to automate
 testing of my Django-based websites.  A quick search on Google turns up a

Have you looked at using the built-in django test client?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: Logwatch python

2013-02-12 Thread Jean-Michel Pichavant

- Original Message -
 In article 1de56e5b-4f9b-477d-a1d4-71e7222a2...@googlegroups.com,
  Cleuson Alves cleuso...@gmail.com wrote:
 
  Hello, I am trying to run this code, but I get an answer incorrect
  arguments
  numbers. someone could put an example of arguments for me to use in
  the / var
  / log?
 
 Since the first cave man tried to sort his rock collection into
 descending order of mastodon kills, people have been inventing really
 awesome debugging tools.  One of the earliest, and still near the top
 of
 most people's toolkits is the print statement.
 
 You've got:
 
  if options.logfile is None or options.findstring is None or
  options.logpos is None:
  print(Incorrect arguments numbers.\n)
 
 Start by printing out the values of options.logfile,
 options.findstring,
 and options.logpos.  Then at least you will know which of those three
 is
 causing the problem.

You're being too sarcastic, this guy 's just invented options that are not 
optional, show some respect :)

To the OP : you forgot to specify one or more of the 3 mandatory options 
--logfile
--logpos
--find

Check your command line.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Magnus Pettersson
 Are you sure you are writing the same data? That would mean that pydev 
 
 changes the default encoding -- which is evil.
 
 
 
 A portable approach would be to use codecs.open() or io.open() instead of 
 
 the built-in:
 
 
 
 import io
 
 with io.open(filepath, a) as f:
 
 ...
 
 
 
 io.open() uses UTF-8 by default, but you can specify other encodings with
 
 io.open(filepath, mode, encoding=whatever).


Interesting. Pydev must be doing something behind the scenes because when i 
changed open() to io.open() i get error inside of eclipse now:

f.write(card+\n)
  File C:\python27\lib\encodings\cp1252.py, line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character u'\u53c8' in 
position 32: character maps to undefined



io.open(filepath, a, encoding=UTF-8) as f: 

Then it works in eclipse. But I seem to be having an encoding problem all over 
the place that works in eclipse but dosnt work outside of eclipse pydev.

Here is the flow of my data, im terrible at using unicode/encode/decode so 
could use some help here:

kanji_anki_gui.py:

def on_addButton_clicked(self):
#code
# self.kanji.text() comes from a kanji letter written into a pyqt4 QLineEdit
kanji = unicode(self.kanji.text())
card = kanji_anki.scrapeKanji(kanji,tags)
#more code

kanji_anki.py:

def scrapeKanji(kanji, tags=, onlymeaning=False):
baseurl = unicode(http://www.romajidesu.com/kanji/;)
url = unicode(baseurl+kanji)
#test to write out url to disk, works outside of eclipse now
savefile([url])

#getting webpage works fine in eclipse, prints Oh no... in terminal
try:
page = urllib2.urlopen(url)
except:
print OH no website dont work
return None

#Code that does some scraping and returns a string containing kanji letters
return card

def savefile(cardlist,filepath=D:/iknow_kanji.txt):
with io.open(filepath, a) as f:
for card in cardlist:
f.write(card+\n)
return True
-- 
http://mail.python.org/mailman/listinfo/python-list


buffers and memoryviews

2013-02-12 Thread Demian Brecht
I didn't know a whole lot (read: nothing) about buffers and memoryviews
before digging into the C side of Python. Once I found them, ran into some
of the 2.7 ugliness of having /both/ buffers and memoryviews available and
found the tremendous usefulness in them, I decided to write a blog post.
In this post, I hope to give the reader a brief overview of what each is,
detail some of the ugliness in 2.7 and provide useful information for
those wanting to incorporate them into their work.

http://demianbrecht.github.com/posts/2013/02/10/buffer-and-memoryview/


Demian Brecht
http://demianbrecht.github.com


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


Re: Generate 16+MAX_WBITS decompressable data

2013-02-12 Thread Terry Reedy

On 2/12/2013 7:47 AM, Fayaz Yusuf Khan wrote:

I'm trying write unit-tests for some of my old code and have run into this
piece of code.

dcomp = zlib.decompressobj(16+zlib.MAX_WBITS)


Since zlib.MAX_WBITS is the largest value that should be passed (15), 
adding 16 makes no sense. Since it is also the default, there is also no 
point in providing it explicitly. Its absolute value should be between 
8 and 15 for the most recent versions of the zlib library.



chunk = ''.join(f.chunks())
received_data =  dcomp.decompress(chunk)


Since decompressobj is intended for data that will not all fit in memory 
at once, and since chunk does, just use zlib.decompress(chunk)



How do I generate the chunk here? From what I've been trying I'm getting
this exception:

import zlib
zlib.compress('hello')

'x\x9c\xcbH\xcd\xc9\xc9\x07\x00\x06,\x02\x15'

zlib.decompress(_, 16+zlib.MAX_WBITS)

Traceback (most recent call last):
   File stdin, line 1, in module
zlib.error: Error -3 while decompressing data: incorrect header check


You asked for an internal buffer of 2**31 = 2 gigabytes.


zlib.decompress without the second argument works, but I can't really go
ahead into my project file and remove it.


--
Terry Jan Reedy

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


Re: Python3 exec locals - this must be a FAQ

2013-02-12 Thread Dave Angel

On 02/12/2013 09:29 AM, Helmut Jarausch wrote:

On Tue, 12 Feb 2013 08:27:41 -0500, Dave Angel wrote:


On 02/12/2013 06:46 AM, Helmut Jarausch wrote:

Hi,

I've tried but didn't find an answer on the net.

The exec function in Python modifies a copy of locals() only.
How can I transfer changes in that local copy to the locals of my
function ** without **  knowing the names of these variables.

E.g.  I have a lot of local names.

Doing

_locals= locals()


This doesn't copy everything.  But perhaps you know that and you're just
testing us.


No, I didn't know. And I'm bit surprised since this is recommend
several times, e.g. in Python Essential Reference, 4th ed by
David Beazley.



That assignment is useful, because it presumably saves the time that 
calling locals() will take constructing the dict.  But copying anything 
by assignment just makes a new reference to the same thing.  If that 
thing is mutable, as a dict is, then changes made to the (dict) object 
are visible to both.






expr=compile(input('statements assigning to some local variables '),
   'user input','exec')
exec(expr,globals(),_locals)

How can I copy the new values within _locals to my current locals.

If I knew that  Var1  has changed I could say Var1 = _locals['Var1']
but what to do in general?


locals()[Var1] = _locals[Var1]  will set the same Var1 local.


Thanks for this hint which surprises me again since I thought
locals() by itself is a copy only.



(Thanks MRAB for your correction.)

As MRAB points out, I was in error on this point.  I only tested it in 
global scope.  Inside a function it doesn't seem to work.  See docs below.




So you might write a loop on _locals.

But beware if someone has deleted one of the variables it may not do
what you'd like.  You cannot necessarily add back a local with the above
syntax.


Does this mean that adding something completely new won't work?

Many thanks,
Helmut.



That depends.  All I can say for sure is it won't work for CPython to 
create new local variables inside a function that way.  It seems to work 
for globals (which are also locals when code of global scope is using 
it), but I wouldn't count on it.


http://docs.python.org/2/library/functions.html#locals

Note the sentence:

The contents of this dictionary should not be modified; changes may 
not affect the values of local and free variables used by the interpreter


Notice that adding or removing items from a dictionary is modifying it, 
while changing values that the keys are associated with is not.  But 
apparently the documentation meant it more strictly than it was worded.


If you really have dozens of variables that you want to pass to exec, 
then restore their original values after it returns, I suggest you make 
your own (empty) class, and use that as a namespace to accomplish it. 
The reason I was tripped up on this definition is that I've concluded 
long ago that messing with locals() is a losing game, so I'd forgotten 
some of the subtlety.


If we knew what the real problem was, we might have a suggestion.  For 
example, if the intent is for the exec to work with a copy of the 
variables, without affecting the originals, then why not use the copy 
module, and pass the *copy* to the exec logic.



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


Re: buffers and memoryviews

2013-02-12 Thread MRAB

On 2013-02-12 15:25, Demian Brecht wrote:

I didn't know a whole lot (read: nothing) about buffers and memoryviews
before digging into the C side of Python. Once I found them, ran into some
of the 2.7 ugliness of having /both/ buffers and memoryviews available and
found the tremendous usefulness in them, I decided to write a blog post.
In this post, I hope to give the reader a brief overview of what each is,
detail some of the ugliness in 2.7 and provide useful information for
those wanting to incorporate them into their work.

http://demianbrecht.github.com/posts/2013/02/10/buffer-and-memoryview/


3.4? I didn't know that it was out yet! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Peter Otten
Magnus Pettersson wrote:

 io.open() uses UTF-8 by default, but you can specify other encodings with
 
 io.open(filepath, mode, encoding=whatever).
 
 
 Interesting. Pydev must be doing something behind the scenes because when
 i changed open() to io.open() i get error inside of eclipse now:
 
 f.write(card+\n)
   File C:\python27\lib\encodings\cp1252.py, line 19, in encode
 return codecs.charmap_encode(input,self.errors,encoding_table)[0]
 UnicodeEncodeError: 'charmap' codec can't encode character u'\u53c8' in
 position 32: character maps to undefined
 
 
 
 io.open(filepath, a, encoding=UTF-8) as f:
 
 Then it works in eclipse. But I seem to be having an encoding problem all
 over the place that works in eclipse but dosnt work outside of eclipse
 pydev.

No, I was wrong about the default; it is actually 
locale.getpreferredencoding(). Sorry for the confusion.


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


Re: Python3 exec locals - this must be a FAQ

2013-02-12 Thread Terry Reedy

On 2/12/2013 8:27 AM, Dave Angel wrote:

On 02/12/2013 06:46 AM, Helmut Jarausch wrote:



I've tried but didn't find an answer on the net.


You should start with the fine manual, which is on the net as well as 
included with at least the Windows distribution. It has a nice index 
that includes an entry for locals (built-in function).



The exec function in Python modifies a copy of locals() only.
How can I transfer changes in that local copy to the locals of my
function
** without **  knowing the names of these variables.


You cannot. Just accept that.


E.g.  I have a lot of local names.

Doing

_locals= locals()


This merely gives you a handle of the dict returned by locals() for when 
you want to do more than just pass it to (for example) exec). This is 
unusual because it is not very useful.



This doesn't copy everything.


I have no idea what you mean. The locals() dict contains all local and 
nonlocal names, excluding global names, which are in the globals() dict.



expr=compile(input('statements assigning to some local variables '),
  'user input','exec')
exec(expr,globals(),_locals)

How can I copy the new values within _locals to my current locals.

If I knew that  Var1  has changed I could say
Var1 = _locals['Var1'] but what to do in general?


If you want to put a value back into the function local namespace, this 
is the only thing you can do. In CPython, at least, all function local 
names must be explicit and known when the function statement is executed 
and the function object is created. Read the Library manual entry for 
locals(), including the highlighted note.



locals()[Var1] = _locals[Var1]  will set the same Var1 local.


Huh??? The dict returned by this locals call is the same dict returned 
by the previous locals call and bound to _locas. So the above does 
nothing. It is the same thing as _locals[Var1] = _locals[Var1].


--
Terry Jan Reedy

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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Dave Angel

On 02/12/2013 10:29 AM, Magnus Pettersson wrote:

Are you sure you are writing the same data? That would mean that pydev

changes the default encoding -- which is evil.



A portable approach would be to use codecs.open() or io.open() instead of

the built-in:



import io

with io.open(filepath, a) as f:

 ...



io.open() uses UTF-8 by default, but you can specify other encodings with


I think you are using Python 2.x, not Python 3.  So you'd better be 
explicit what encodings you want for each file.




io.open(filepath, mode, encoding=whatever).



Interesting. Pydev must be doing something behind the scenes because when i 
changed open() to io.open() i get error inside of eclipse now:


What encoding is this file?  Since you're appending to it, you really 
need to match the pre-existing encoding, or the next program to deal 
with it is in big trouble.  So using the io.open() without the encoding= 
keyword is probably a mistake.




f.write(card+\n)
   File C:\python27\lib\encodings\cp1252.py, line 19, in encode
 return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character u'\u53c8' in position 32: 
character maps to undefined






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


Re: A newbie question

2013-02-12 Thread Colin J. Williams

On 12/02/2013 10:06 AM, Alberto Salvati wrote:

Hi, All.
I'm a (old) delphi developer.
I want to learn Python.
I've python 2.7 and django.
For learning purpose I want to use firebird.
But, package (egg) to use firebird needs easy_install for setup.
When i run:

python ez_setup.py install

python says me error:

Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-p
y2.7.egg
Searching for install
Reading http://pypi.python.org/simple/install/
Couldn't find index page for 'install' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for install
Best match: None
Traceback (most recent call last):
   File ez_setup.py, line 278, in module
 main(sys.argv[1:])
   File ez_setup.py, line 213, in main
 return main(list(argv)+[egg])   # we're done here
   File 
C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 1712, in main
   File 
C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 1700, in with_ei_usage
   File 
C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 1716, in lambda
   File C:\Python27\lib\distutils\core.py, line 152, in setup
 dist.run_commands()
   File C:\Python27\lib\distutils\dist.py, line 953, in run_commands
 self.run_command(cmd)
   File C:\Python27\lib\distutils\dist.py, line 972, in run_command
 cmd_obj.run()
   File 
C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 211, in run
   File 
C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_
install.py, line 434, in easy_install
   File 
C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\package_index
.py, line 475, in fetch_distribution
AttributeError: 'NoneType' object has no attribute 'clone'


In download site I get info about installer works only on win32, but I'm uisng 
64 bit version, so I need to do setup manually.

Searching error, I see a lot of message baout errors AFTER easy_install was 
done.
Also, I see that some link used in python file does'nt exist or is broken.

TIA for any suggestion.

A.

Try Easy_install, but first, make sure that C:\Python27\Scripts is in 
your path.


Colin W.

PS Assuming you are using Windows, you might wish to try PyScripter.  I 
was developed using Delphi.


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


Re: A newbie question

2013-02-12 Thread Alberto Salvati
Hi, Colin.
Thanks for your answer.
But C:\Python27\Scripts  is in my path and my trouble is about INSTALL 
easy_isntall.

Bye

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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Terry Reedy

On 2/12/2013 7:34 AM, Magnus Pettersson wrote:

Ahh so its the actual printing that makes it error out outside of
eclipse because its a different terminal that its printing to. Its
the default DOS terminal in windows that runs then i run the script
with python.exe and i guess its the same when i run with pythonw.exe
just that the terminal window is not opened up, only the pyqt gui in
this case.


Writing

txt = expression involving coding
print(txt)

rather than

print(expression involving coding)

makes it easier to tell whether a UnicodeError comes from evaluating the 
expression or from the print operation.


Using 3.3 instead of 2.7 will make using unicode somewhat easier.

--
Terry Jan Reedy

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


Re: Python3 exec locals - this must be a FAQ

2013-02-12 Thread Dave Angel

On 02/12/2013 10:50 AM, Terry Reedy wrote:

On 2/12/2013 8:27 AM, Dave Angel wrote:

On 02/12/2013 06:46 AM, Helmut Jarausch wrote:



snip

Doing

_locals= locals()


This merely gives you a handle of the dict returned by locals() for when
you want to do more than just pass it to (for example) exec). This is
unusual because it is not very useful.


This doesn't copy everything.


The OP presumably wanted to restore the original values of the original 
variables.  The above assignment won't help a bit with that.





I have no idea what you mean. The locals() dict contains all local and
nonlocal names, excluding global names, which are in the globals() dict.


expr=compile(input('statements assigning to some local variables '),
  'user input','exec')
exec(expr,globals(),_locals)

How can I copy the new values within _locals to my current locals.

If I knew that  Var1  has changed I could say
Var1 = _locals['Var1'] but what to do in general?


If you want to put a value back into the function local namespace, this
is the only thing you can do. In CPython, at least, all function local
names must be explicit and known when the function statement is executed
and the function object is created. Read the Library manual entry for
locals(), including the highlighted note.


locals()[Var1] = _locals[Var1]  will set the same Var1 local.


Huh??? The dict returned by this locals call is the same dict returned
by the previous locals call and bound to _locas. So the above does
nothing. It is the same thing as _locals[Var1] = _locals[Var1].



My claim was based on the assumption that the earlier assignment had 
been fixed by some kind of copy.  If not, there's nothing to restore.


I also retracted my use of that trick anyway, since being corrected by 
MRAB.  I only tested it in top-level code, not inside a function.



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


Re: buffers and memoryviews

2013-02-12 Thread Demian Brecht
I guess I /should/ have written it with current releases.. My 3 is current
dev source :P

Demian Brecht
http://demianbrecht.github.com




On 2013-02-12 7:42 AM, MRAB pyt...@mrabarnett.plus.com wrote:

On 2013-02-12 15:25, Demian Brecht wrote:
 I didn't know a whole lot (read: nothing) about buffers and memoryviews
 before digging into the C side of Python. Once I found them, ran into
some
 of the 2.7 ugliness of having /both/ buffers and memoryviews available
and
 found the tremendous usefulness in them, I decided to write a blog post.
 In this post, I hope to give the reader a brief overview of what each
is,
 detail some of the ugliness in 2.7 and provide useful information for
 those wanting to incorporate them into their work.

 http://demianbrecht.github.com/posts/2013/02/10/buffer-and-memoryview/

3.4? I didn't know that it was out yet! :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


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


Installing Apache 2 and mod_wsgi on CentOS?

2013-02-12 Thread Gilles
Hello

Before I go ahead, I'd like to make sure I'm doing it the right away:

1. yum install httpd mod_wsgi

2. Edit /etc/sysconfig/httpd to uncomment this line to get Apache to
run as worker MPM:
#HTTPD=/usr/sbin/httpd.worker

3. Edit mod_wsgi

4. Build a test WSGI Python script

5. Start Apache, and launch a browser

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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Magnus Pettersson
 What encoding is this file?  Since you're appending to it, you really 
 
 need to match the pre-existing encoding, or the next program to deal 
 
 with it is in big trouble.  So using the io.open() without the encoding= 
 
 keyword is probably a mistake.

The .txt file is in UTF-8

I have got it to work now in the terminal, but i dont understand what im doing 
and why i didnt need to do all the unicode strings and encode mumbo jumbo in 
eclipse

#Here kanji = u私
baseurl = uhttp://www.romajidesu.com/kanji/;
url = baseurl+kanji
savefile([url]) #this test works now. uses: io.open(filepath, 
a,encoding=UTF-8) as f:
# This made the fetching of the website work. Why did i have to write 
url.encode(UTF-8) when url already is unicode? I feel i dont have a good 
understanding of this.
page = urllib2.urlopen(url.encode(UTF-8))



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


Re: Implicit conversion to boolean in if and while statements

2013-02-12 Thread Rick Johnson
On Monday, February 11, 2013 11:55:19 PM UTC-6, Chris Angelico wrote:
 On Tue, Feb 12, 2013 at 12:06 PM, 8 Dihedral wrote:
  A permanently mutated list is a tuple of constant objects.

 I nominate this line as bemusing head-scratcher of the week.

Actually the statement is fact IF you can grok it through the eyes of clarity.

A permanently mutated list...

A list that has been mutated permanently, that is, it cannot be changed back 
into a list. psst: i have a sneaking suspicion that he his referring to tuples, 
let's see.

...is a tuple...

Ha! Well in Python the immutable sequence type /is/ a tuple after all.

...of constant objects...

The tuple contains objects, and it's objects will maintain a constant ordering 
(relatively in tuple structure) until until the tuple's death. 

Your confusion may stem from interpreting constant as the CS term 
CONSTANT[1]; whereby the objects in the tuple are programming CONSTANTS, that 
is, unable to change. But in reality, although a tuple (bka:StaticList) cannot 
expand to add more objects, or shrink to eject existing objects, the objects 
themselves CAN change their own internal state WITHOUT disrupting the immutable 
harmony of the tuple. 

Observe:

py class Foo(object):
pass
py foo = Foo()
py t = (1,'1', foo)
py t
(1, '1', __main__.Foo object at 0x0267BF50)
py t[-1].bar = abc
py t
(1, '1', __main__.Foo object at 0x0267BF50)

Or by expanding a list

py t = (1,2,3)
py t = t+([],)
py t
(1, 2, 3, [])
py t[-1].append('circus')
py t
(1, 2, 3, ['circus'])

[1] Which is an unfortunate side-effect of polysemy and compounded 
exponentially by naive (and sometimes a purely malevolent intent when) 
transformation of words into esoteric problem domains.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Awsome Python - chained exceptions

2013-02-12 Thread Zero Piraeus
:

On 12 February 2013 02:15, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 As an antidote to the ill-informed negativity of Ranting Rick's
 illusionary PyWarts, I thought I'd present a few of Python's more
 awesome features [...]

You could call them PyW00ts.

 -[]z.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Awsome Python - chained exceptions

2013-02-12 Thread Ethan Furman

On 02/12/2013 10:01 AM, Zero Piraeus wrote:

On 12 February 2013 02:15, Steven D'Aprano wrote:

As an antidote to the ill-informed negativity of Ranting Rick's
illusionary PyWarts, I thought I'd present a few of Python's more
awesome features [...]


You could call them PyW00ts.


+1 QOTW

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


A better way to accomplish loop

2013-02-12 Thread Joseph L. Casale
I have an issue with some code I have been passed:

for (x, y) in [(a_dict1, a_tuple[0]), (a_dict2, a_tuple[1])]:


I only noticed it as PyCharm failed to assign the str type to y, whereas it knew
the tuples 0 and 1 item were type str.


In the loop it flags the passing of y into a method that expects type str. I 
can ignore
it, but looking at the loop, I cant help but think there is a better way?


Any guidance would be appreciated!
jlc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Fabio Zadrozny
Just to note, PyDev does something behind the scenes (it sets the encoding
for the console).

You may specify which encoding you want at your launch configuration (in
the 'common' tab you can set the encoding you want for the shell).

Cheers,

Fabio


On Tue, Feb 12, 2013 at 3:12 PM, Magnus Pettersson
magpetters...@gmail.comwrote:

  What encoding is this file?  Since you're appending to it, you really
 
  need to match the pre-existing encoding, or the next program to deal
 
  with it is in big trouble.  So using the io.open() without the encoding=
 
  keyword is probably a mistake.

 The .txt file is in UTF-8

 I have got it to work now in the terminal, but i dont understand what im
 doing and why i didnt need to do all the unicode strings and encode mumbo
 jumbo in eclipse

 #Here kanji = u私
 baseurl = uhttp://www.romajidesu.com/kanji/;
 url = baseurl+kanji
 savefile([url]) #this test works now. uses: io.open(filepath,
 a,encoding=UTF-8) as f:
 # This made the fetching of the website work. Why did i have to write
 url.encode(UTF-8) when url already is unicode? I feel i dont have a good
 understanding of this.
 page = urllib2.urlopen(url.encode(UTF-8))


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

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


Re: A better way to accomplish loop

2013-02-12 Thread Dave Angel

On 02/12/2013 02:59 PM, Joseph L. Casale wrote:

I have an issue with some code I have been passed:


I had to read it about four times before I knew what you were saying. 
Maybe I still have it wrong.




for (x, y) in [(a_dict1, a_tuple[0]), (a_dict2, a_tuple[1])]:


I only noticed it as PyCharm failed to assign the str type to y, whereas it knew
the tuples 0 and 1 item were type str.


I think you're saying that the lint-feature of PyCharm is trying to 
guess the object types, and telling you there's a conflict here.  I 
don't think you're saying that it executes incorrectly.





In the loop it flags the passing of y into a method that expects type str. I 
can ignore
it, but looking at the loop, I cant help but think there is a better way?



By better, you could have meant
   1) clearer for the reader
   2) runs faster or takes less memory
   3) fools PyCharm into guessing better in its checking.

If it's #3, then I'm no real help, as I've never seen a paper on the 
philosophy of the PyCharm guesser.


Still there are ways to express it differently, and maybe one of them 
will happen to please PyCharm.


Name the variables to represent what they're holding.  Those names might 
also imply type, though I wouldn't normally go out of my way to 
accomplish it.  But if the two parts of the two tuple are strings, 
perhaps the tuple as a whole might be called names, or titles, or 
authors.  However, generally a tuple is NOT expected to have the same 
type for all its elements.


for x,y in zip((a_dict1, a_dict2), a_tuple):

dicts = [a_dict1, a_dict2]
for x,y in zip(dicts, a_tuple):


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


Re: Generate 16+MAX_WBITS decompressable data

2013-02-12 Thread Marc Christiansen
Terry Reedy tjre...@udel.edu wrote:
 On 2/12/2013 7:47 AM, Fayaz Yusuf Khan wrote:
 dcomp = zlib.decompressobj(16+zlib.MAX_WBITS)
 
 Since zlib.MAX_WBITS is the largest value that should be passed (15), 
 adding 16 makes no sense. Since it is also the default, there is also no 
 point in providing it explicitly. Its absolute value should be between 
 8 and 15 for the most recent versions of the zlib library.

The above code uses a feature of the zlib library which isn't really
widely known.
From http://www.zlib.net/manual.html#Advanced (inflateInit2):
  windowBits can also be greater than 15 for optional gzip decoding. Add
  32 to windowBits to enable zlib and gzip decoding with automatic
  header detection, or add 16 to decode only the gzip format (the zlib
  format will return a Z_DATA_ERROR).


 How do I generate the chunk here? From what I've been trying I'm getting
 this exception:
 import zlib
 zlib.compress('hello')
 'x\x9c\xcbH\xcd\xc9\xc9\x07\x00\x06,\x02\x15'
 zlib.decompress(_, 16+zlib.MAX_WBITS)
 Traceback (most recent call last):
File stdin, line 1, in module
 zlib.error: Error -3 while decompressing data: incorrect header check

Try using a compressobj with 24 = wbits  32. It should work, but I
didn't try.

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


Re: LangWart: Method congestion from mutate multiplicty

2013-02-12 Thread Rick Johnson
On Monday, February 11, 2013 11:28:57 PM UTC-6, zipher wrote:
 [...]
 Yeah, this is where one has to consider the idea of a unified data
 model (a sort of OOPv2).  Right now, it's all confused because people
 are using their own internal, subconscious ideas of data.

Indeed! 

The current paradigms lack concrete structures which will prevent these 
ever-long bickering over minutiae. Our current paradigms are actually 
self-defeating because they allow too much interpretation of what is correct, 
and what is incorrect. It's like the early pioneer days, cowboys everywhere. We 
need Wyatt Earp!

 There are
 natural ways of working with data that ***actually map onto the world
 we all share*** and there are other ways which are purely abstract and
 not-pragmatic however pure.   (Apart from this, there is the
 ultra-concrete data model, like C, which only maps onto the machine
 architecture).  This is where pretty much every computer language is
 today.
 
 What I'm suggesting I think is somewhat novel.  The first version of
 OOP was too concrete in the sense that it was actually trying to make
 real-world objects in the machine (class Chevy(Car):).  This is
 ridiculous.  There needs to be a refactor of the OOP paradigm.  In
 practice OOP never was used to represent real-world objects.  It came
 to model virtual world objects, a very different world with different
 relationships.  It became the evolution of the data type itself.

 The
 unified object model needs to do for OOP what arithmetic did for
 number:  defined a very basic and general set of operations on the
 concept of quantificiation.  But here were trying to do that not for
 quantification but for structures.

Most people in the this group would probably consider this to be a fantastical 
idea. But aren't ALL great ideas fantastical?

From as long as man has existed he has wanted to fly like a bird -- whether 
his wish was based on logistical expeditiously or simply a primitive 
egotistical rebelliousness to overcome the limits of his own physiology.

It's no surprise that the initial attempts were naive at best and resulted in 
total embarrassment. When he attempted to borrow some flight attributes of 
his feathered friends by taring-and-feathering himself, he did /look/ like a 
bird, however, when he executed the perfect 10 swan-dive from his second 
story cave dwelling, only to bounce his face off the granite welcome mat, he 
was reminded by his audience of the one bird-like feature he already had... his 
brain!

You see, early man wanted to fly, and knew /somehow/ it was possible, however, 
his folly was to attempt flight by borrowing attributes of the bird /directly/. 
In reality, even if could borrow /every/ flight specific attribute of the bird: 
light weight frame from hollow bones, large lung capacity, aerodynamic body 
shape and wing structure, features, etc. He would then be /himself/ a bird, and 
NOT a /human/ flying. Besides, a human changing into a bird is impossible... or 
is it?[3]

[Warning: Slight tangent curve ahead!]

I think a lot of the failure of achieving flight hinged around the 
superfluous complexity of articulated wings-- of which is something that we 
have trouble replicating even today with our advancements in mechanical, 
hydraulic, and computing technology. But articulating wings are another fine 
example of how intelligent design will always beat the pants off evolution. 
The simple technology of combining fixed wings with brute force propulsion 
can overcome the complex design of articulating wings and gain maintainability 
in the process. It seems the bird should have developed a squid-like air 
propulsion emanating from his anus instead of articulating wings and large 
breast muscles; But i digress!

RR: A billion years worth of dice rolling is no replacement one human 
imagination! Evolution, you have created your replacement; prepare for your 
deprecation!

[Back to the beaten path!]

What early man failed to realize is that he should create a model of the bird, 
and then hitch a ride on the model! This is an example if utilizing an 
/indirect/ approach to solving the problem of human flight.

However, it is still possible to solve the problem directly. Although this 
direct approach involves man manipulating atomic structures (using 
nano-technology) and then transforming cognitive state from one entity into 
another entity (or in-place if we're really good![1]); AKA: Shapeshifting

But some rules require too much time to hack, so while the brute algorthim is 
chewing away for the next 100 years, we need to follow these steps:
  0. Start the brute force algorithm (study nano-tech, computing)
  1. in the short term use the indirect approach (aeroplane)
  2. until the direct approach becomes attainable (shapeshifting)

 My suggestion is to create the fractal graph data type to end (and
 represent) all data types.  (Keep all the special, high-speed matrix
 ideas in SciPi/VPython.)  But generally, re-arrange the 

Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Dave Angel

On 02/12/2013 12:12 PM, Magnus Pettersson wrote:

 snip 


#Here kanji = u私
baseurl = uhttp://www.romajidesu.com/kanji/;
url = baseurl+kanji
savefile([url]) #this test works now. uses: io.open(filepath, 
a,encoding=UTF-8) as f:
# This made the fetching of the website work.


You don't show the code that actually does the io.open(), nor the 
url.encode, so I'm not going to guess what you're actually doing.




Why did i have to write url.encode(UTF-8) when url already is unicode? I feel 
i dont have a good understanding of this.
page = urllib2.urlopen(url.encode(UTF-8))


utf-8 is NOT unicode;  they are entirely different.  Unicode is 
conceptually 32 bits per character, and is an internal representation. 
There are a million or so characters defined.  Nearly always when you're 
talking to an external device, you need bytes.  Since you can't cram 32 
bits into 8, you have to encode it.  Examples of devices would be any 
file, or the console.  Notice that sometimes you can use unicode 
directly for certain functions.  For example, the Windows file name is 
composed of Unicode characters, so Windows has function calls that 
accept Unicode directly.  But back to 8 bits:


One encoding is called ASCII, which is simply the bottommost 7 bits. 
But of course it gets an error if there are any characters above 127.


Other encodings try to pick an 8 bit subset of the million possible 
characters.  Again, if you happen to have a character that's not in that 
subset, you'll get an error.


There are also other encodings which are hard to describe, but 
fortunately pretty rare these days.


Then there's utf-8, which uses a variable length  bunch of bytes for 
each character.  It's designed to use the ASCII encoding for characters 
which are below 128, but uses two or more bytes for all the other 
characters.  So it works out well when most characters happen to be ASCII.


Once encoded, a stream of bytes can only be successfully interpreted if 
you use the same decoding when processing them.




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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread MRAB

On 2013-02-12 14:24, Magnus Pettersson wrote:

I have tried now to take away printing to terminal and just keeping the writing 
to a .txt file to disk (which is what the scripts purpose is):

with open(filepath,a) as f:
 for card in cardlist:
 f.write(card+\n)

The file it writes to exists and im just appending to it, but when i run the 
script trough eclipse, all is fine. When i run in terminal i get this error 
instead:

File K:\dev\python\webscraping\kanji_anki.py, line 69, in savefile
 f.write(card+\n)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u898b' in position 3
2: ordinal not in range(128)


When you open the file, tell it what encoding to use. For example:

with open(filepath, a, encoding=utf-8) as f:
for card in cardlist:
f.write(card + \n)

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


Re: Implicit conversion to boolean in if and while statements

2013-02-12 Thread Chris Angelico
On Wed, Feb 13, 2013 at 4:48 AM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
 Your confusion may stem from interpreting constant as the CS term 
 CONSTANT[1]; whereby the objects in the tuple are programming CONSTANTS, 
 that is, unable to change.

Uhh, yeah. Not being Humpty Dumpty, I interpret constants to mean
things that won't change. (Or, eliding the second t, as I've found
a friend. But I digress.) There's just something about that word
constant that really suggests a meaning of constant.

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


RE: A better way to accomplish loop

2013-02-12 Thread Joseph L. Casale
 I think you're saying that the lint-feature of PyCharm is trying to 

 guess the object types, and telling you there's a conflict here.  I
 don't think you're saying that it executes incorrectly.

Hah, yeah sorry Dave that's it.


 Still there are ways to express it differently, and maybe one of them 
 will happen to please PyCharm.

Wasn't overly concerned with pycharm, but clarity would be more desirable.


 dicts = [a_dict1, a_dict2] 
 for x,y in zip(dicts, a_tuple):


Ironically, that is clearer and satisfied pycharms lint feature.
Thanks!
jlc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python3 exec locals - this must be a FAQ

2013-02-12 Thread Steven D'Aprano
Dave Angel wrote:

 Thanks for this hint which surprises me again since I thought
 locals() by itself is a copy only.

 
 (Thanks MRAB for your correction.)
 
 As MRAB points out, I was in error on this point.  I only tested it in
 global scope.  Inside a function it doesn't seem to work.

One of the two classic blunders:

- Never get involved in a land war in Asia;
- Never go against a Sicilian when death is on the line;
- Never test locals() outside of a function and extrapolate the 
  behaviour to inside a function!



-- 
Steven

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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Steven D'Aprano
Magnus Pettersson wrote:


 # This made the fetching of the website work. Why did i have to write
 # url.encode(UTF-8) when url already is unicode? I feel i dont have a
 # good understanding of this.
 page = urllib2.urlopen(url.encode(UTF-8))


Start here:

The Absolute Minimum Every Software Developer Absolutely, Positively Must
Know About Unicode and Character Sets (No Excuses!)

http://www.joelonsoftware.com/articles/Unicode.html


Basically, Unicode is an in-memory data format. Python knows about Unicode
characters (to be technical: code points), but files on disk do not.
Neither do network protocols, or terminals, or other simple devices. They
only understand bytes.

So when you have Unicode text, and you want to write it to a file on disk,
or print it, or send it over the network to another machine, it has to be
*encoded* into bytes, and then *decoded* back into Unicode when you read it
from the file again. Sometimes the system will helpfully do that encoding
and decoding automatically for you, which is fine when it works but when it
doesn't it can be perplexing.

There are many, many, many different *encoding schemes*. ASCII is one. UTF-8
is another. And then there are about a bazillion legacy encodings which, if
you are lucky, you will never need to care about. Only some encodings can
deal with the entire range of Unicode characters, most can only deal with a
(typically small) subset of possible characters. E.g. ASCII only knows
about 127 characters out of the million-plus that Unicode deals with.
Latin-1 can handle close to 256 different characters. If you have a say in
the matter, always use UTF-8, since it can handle the full set of Unicode
characters in the most efficient manner.


-- 
Steven

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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Magnus Pettersson

 You don't show the code that actually does the io.open(), nor the 
 
 url.encode, so I'm not going to guess what you're actually doing.

Hmm im not sure what you mean but I wrote all code needed in a previous post so 
maybe you missed that one :)
In short I basically just have:
import io
io.open(myfile,a,encode=UTF-8) as f:
f.write(my_ustring_with_kanji)

the url.encode() is my unicode string variable named url using the type built 
in  function .encode() which was the thing i wondered why i needed to use, 
which you explained very well, thank you!

Just one more question since all this is still a little fuzzy in my head.

When do i need to use .decode() in my code? is it when i read lines from f.ex a 
UTF-8 file? And why didn't I have to use .encode() on my unicode string when 
running from within eclipse pydev? someone wrote that it has a default codec 
setting so maybe that handles it for me there (which is kinda dangerous since 
my programs wont work running outside of eclipse since i didnt do any encoding 
or using of unicode strings before in my script and it still worked)

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


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Magnus Pettersson
Thanks a lot Steven, you gave me a good AHA experience! :)

Now I understand why I had to use encoding when calling the urllib2! So 
basically Eclipse PyDev does this in the background for me, and its console 
supports utf-8, so thats why i never had to think about it before (and why some 
scripts tends to fail with unicode errors when run outside of the Eclipse IDE).

cheers
Magnus

 Start here:
 
 
 
 The Absolute Minimum Every Software Developer Absolutely, Positively Must
 
 Know About Unicode and Character Sets (No Excuses!)
 
 
 
 http://www.joelonsoftware.com/articles/Unicode.html
 
 
 
 
 
 Basically, Unicode is an in-memory data format. Python knows about Unicode
 
 characters (to be technical: code points), but files on disk do not.
 
 Neither do network protocols, or terminals, or other simple devices. They
 
 only understand bytes.
 
 
 
 So when you have Unicode text, and you want to write it to a file on disk,
 
 or print it, or send it over the network to another machine, it has to be
 
 *encoded* into bytes, and then *decoded* back into Unicode when you read it
 
 from the file again. Sometimes the system will helpfully do that encoding
 
 and decoding automatically for you, which is fine when it works but when it
 
 doesn't it can be perplexing.
 
 
 
 There are many, many, many different *encoding schemes*. ASCII is one. UTF-8
 
 is another. And then there are about a bazillion legacy encodings which, if
 
 you are lucky, you will never need to care about. Only some encodings can
 
 deal with the entire range of Unicode characters, most can only deal with a
 
 (typically small) subset of possible characters. E.g. ASCII only knows
 
 about 127 characters out of the million-plus that Unicode deals with.
 
 Latin-1 can handle close to 256 different characters. If you have a say in
 
 the matter, always use UTF-8, since it can handle the full set of Unicode
 
 characters in the most efficient manner.
 
 
 
 
 
 -- 
 
 Steven

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


Python Makefiles... are they possible?

2013-02-12 Thread Malcolm White
I have written a piece of code that will be part of a larger repository of 
related programs. Within this repository, it is standard to issue a 'make' 
command to compile any desired program. Is it possible to create a Makefile to 
compile a simple Python program? Based on what I have come across so far, this 
is not (at least not typically) the way things are done with Python.

Thanks for any pointers in the right direction!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Makefiles... are they possible?

2013-02-12 Thread Joel Goldstick
On Tue, Feb 12, 2013 at 7:44 PM, Malcolm White white@gmail.com wrote:

 I have written a piece of code that will be part of a larger repository of
 related programs. Within this repository, it is standard to issue a 'make'
 command to compile any desired program. Is it possible to create a Makefile
 to compile a simple Python program? Based on what I have come across so
 far, this is not (at least not typically) the way things are done with
 Python.

 Thanks for any pointers in the right direction!


Python is an interpreted language.  The source code is 'compiled' into
bytecode when invoked.  Make is a process that converts source code to
compiled code, so it doesn't apply to python

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




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


Re: Python Makefiles... are they possible?

2013-02-12 Thread Oscar Benjamin
On 13 February 2013 00:44, Malcolm White white@gmail.com wrote:
 I have written a piece of code that will be part of a larger repository of 
 related programs. Within this repository, it is standard to issue a 'make' 
 command to compile any desired program. Is it possible to create a Makefile 
 to compile a simple Python program? Based on what I have come across so far, 
 this is not (at least not typically) the way things are done with Python.

You can use a Makefile for anything you want in a Python project.
However Python code is not (typically) compiled so it is not common
practise to compile it with or without a Makefile. When part of a
Python project is compiled because, for example it bundles some C code
to be used within Python, the compilation needs to performed in way
that will be compatible with Python so the process is normally
controlled by Python, through a setup.py file. In this case
compilation is done with something like 'python setup.py build' (Of
course there's nothing to stop you from adding that command to a
Makefile and invoking it with 'make').

I often use Makefiles in Python projects for other purposes, though,
such as running tests with 'make test' or building documentation with
'make doc'.


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


Re: Python Makefiles... are they possible?

2013-02-12 Thread Roy Smith
In article mailman.1731.1360717275.2939.python-l...@python.org,
 Oscar Benjamin oscar.j.benja...@gmail.com wrote:

 On 13 February 2013 00:44, Malcolm White white@gmail.com wrote:
  I have written a piece of code that will be part of a larger repository of 
  related programs. Within this repository, it is standard to issue a 'make' 
  command to compile any desired program. Is it possible to create a Makefile 
  to compile a simple Python program? Based on what I have come across so 
  far, this is not (at least not typically) the way things are done with 
  Python.
 
 You can use a Makefile for anything you want in a Python project.
 However Python code is not (typically) compiled so it is not common
 practise to compile it with or without a Makefile. When part of a
 Python project is compiled because, for example it bundles some C code
 to be used within Python, the compilation needs to performed in way
 that will be compatible with Python so the process is normally
 controlled by Python, through a setup.py file. In this case
 compilation is done with something like 'python setup.py build' (Of
 course there's nothing to stop you from adding that command to a
 Makefile and invoking it with 'make').
 
 I often use Makefiles in Python projects for other purposes, though,
 such as running tests with 'make test' or building documentation with
 'make doc'.

One thing we do in our Makefiles is find . -name '*.pyc' | xargs rm.  
It avoids all sorts of nasty and hard to track down bugs (consider what 
happens if you move a .py file from one place in your source tree to 
another and leave the old .pyc behind).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-12 Thread 88888 Dihedral
Rick Johnson於 2013年2月13日星期三UTC+8上午1時48分07秒寫道:
 On Monday, February 11, 2013 11:55:19 PM UTC-6, Chris Angelico wrote:
 
  On Tue, Feb 12, 2013 at 12:06 PM, 8 Dihedral wrote:
 
   A permanently mutated list is a tuple of constant objects.
 
 
 
  I nominate this line as bemusing head-scratcher of the week.
 
 
 
 Actually the statement is fact IF you can grok it through the eyes of clarity.
 
 
 
 A permanently mutated list...
 
 
 
 A list that has been mutated permanently, that is, it cannot be changed back 
 into a list. psst: i have a sneaking suspicion that he his referring to 
 tuples, let's see.
 
 
 
 ...is a tuple...
 
 
 
 Ha! Well in Python the immutable sequence type /is/ a tuple after all.
 
 
 
 ...of constant objects...
 
 
 
 The tuple contains objects, and it's objects will maintain a constant 
 ordering (relatively in tuple structure) until until the tuple's death. 
 
 

 a1=[1,2,3]
 tuple1=(a1,4,5,6)
 tuple1
([1, 2, 3], 4, 5, 6)
 a1=[1,2]
 tuple1
([1, 2, 3], 4, 5, 6)
 

Yes, a tuple of constant objects is still not clear. 


 
 Your confusion may stem from interpreting constant as the CS term 
 CONSTANT[1]; whereby the objects in the tuple are programming CONSTANTS, 
 that is, unable to change. But in reality, although a tuple (bka:StaticList) 
 cannot expand to add more objects, or shrink to eject existing objects, the 
 objects themselves CAN change their own internal state WITHOUT disrupting the 
 immutable harmony of the tuple. 
 
 
 
 Observe:
 
 
 
 py class Foo(object):
 
   pass
 
 py foo = Foo()
 
 py t = (1,'1', foo)
 
 py t
 
 (1, '1', __main__.Foo object at 0x0267BF50)
 
 py t[-1].bar = abc
 
 py t
 
 (1, '1', __main__.Foo object at 0x0267BF50)
 
 
 
 Or by expanding a list
 
 
 
 py t = (1,2,3)
 
 py t = t+([],)
 
 py t
 
 (1, 2, 3, [])
 
 py t[-1].append('circus')
 
 py t
 
 (1, 2, 3, ['circus'])
 
 
 
 [1] Which is an unfortunate side-effect of polysemy and compounded 
 exponentially by naive (and sometimes a purely malevolent intent when) 
 transformation of words into esoteric problem domains.

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


Re: Awsome Python - chained exceptions

2013-02-12 Thread Rick Johnson
On Tuesday, February 12, 2013 12:15:29 AM UTC-6, Steven D'Aprano wrote:
 [snip inflammatory remarks]
 I thought I'd present a few of Python's more
 awesome features, starting with exception contexts.

Well that's great idea, however, in order to find this very valuable 
information the searcher must not only remember an unintuitive search tag, he 
must also remember /exactly/ how you misspelled the unintuitive search tag! I 
sure hope you have more of these Awsome Python's to share because i fear this 
one will surely be forgotten in 2 days. 

 If you've ever written an exception handler, you've probably written a
 *buggy* exception handler:

 def getitem(items, index):
 # One-based indexing.
 try:
 return items[index-1]
 except IndexError:
 print (Item at index %d is missing % index - 1)  # Oops!


 Unfortunately, when an exception occurs inside an except or finally
 block, the second exception masks the first, and the reason for the
 original exception is lost:

 py getitem(['one', 'two', 'three'], 5)  # Python 2.6
 Traceback (most recent call last):
   File stdin, line 1, in module
   File stdin, line 6, in getitem
 TypeError: unsupported operand type(s) for -: 'str' and 'int'

But that's exactly what any sane person wants to happen. And i don't know why 
your error messages are so vague because i got this message (using IDLE):

py getitem([1,2,3], 5)
Traceback (most recent call last):
  File pyshell#3, line 1, in module
getitem([1,2,3], 5)
  File pyshell#1, line 5, in getitem
print (Item at index %d is missing % index - 1)  # Oops!
TypeError: unsupported operand type(s) for -: 'str' and 'int'

Which (by showing the offensive line) is quite clear to me. I even tried a 
simplified version on the command line (to make sure IDLE was not injecting 
anything) and got a better exception message, but sadly without the offending 
line:

py try:
... l[10]
... except IndexError:
... {0}.format(blah)
...
Traceback (most recent call last):
  File stdin, line 4, in module
NameError: name 'blah' is not defined

But in either case, both forms of the message i got are far more helpful than 
the exception you posted. Did you trim the exception in an attempt to 
sensationalize the problem?

But who cares about the exception message python returned when there are /so/ 
many abominations in this code sample. I mean, i know this is an example, but 
it should not be an example of how not to code+ANYTHING+!*10

Some of the problems include:

1. You are using the print function (so we can assume you are using Python 3.x) 
but then you go and use that old ugly % string interpolation syntax crap! 
when you should have used the format method of strings.

print(Item at index {0} is missing.format(index-1)) # Oops!

...Oh Steven, if you only knew how we interpreted the Oops!, more like Doh!.

2. Your stdout message is not only confusing, it's a freaking lie! 

Item at index %d is missing. 

...Steven, i can assure you that if list[index] raises an IndexError, the 
item is NOT /missing/. Neither the item OR the index even /exist/ as far as the 
sequence is concerned. Contrary to your naive beliefs, Python sequences are not 
initialized with every possible integer index (that the current machine can 
represent) just sitting around twiddling their thumbs complaining of boredom 
whilst waiting for a value to come along they can point to; can you imagine the 
memory usage of such a design (flaw)?

3. Your claim that the broken code in the exception block masks the exception 
that would have been raised by the code in the try block is false, because if 
it's true, then you'd better find the fool who told Python to mask the try 
block in the first place!

Got any more bright ideas DeAprano? (Oh gawd that felt good!)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Awsome Python - chained exceptions

2013-02-12 Thread Rick Johnson
On Tuesday, February 12, 2013 12:01:45 PM UTC-6, Zero Piraeus wrote:

 You could call them PyW00ts.

+1 on the name
-INFINITY on the execution

Actually i am happy that DeAprano used the unintuitive tag now. Bad enough to 
use an unintuitive tag. Worse to misspell it. But it would been a crime to 
tarnish such an intuitive tag as PyW00ts with the clumsy teachings provided. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError when not running script from IDE

2013-02-12 Thread Dave Angel

On 02/12/2013 07:20 PM, Magnus Pettersson wrote:



You don't show the code that actually does the io.open(), nor the

url.encode, so I'm not going to guess what you're actually doing.


Hmm im not sure what you mean but I wrote all code needed in a previous post so 
maybe you missed that one :)
In short I basically just have:
import io
io.open(myfile,a,encode=UTF-8) as f:
 f.write(my_ustring_with_kanji)

the url.encode() is my unicode string variable named url using the type built 
in  function .encode() which was the thing i wondered why i needed to use, which you 
explained very well, thank you!

Just one more question since all this is still a little fuzzy in my head.

When do i need to use .decode() in my code? is it when i read lines from f.ex a 
UTF-8 file? And why didn't I have to use .encode() on my unicode string when 
running from within eclipse pydev? someone wrote that it has a default codec 
setting so maybe that handles it for me there (which is kinda dangerous since 
my programs wont work running outside of eclipse since i didnt do any encoding 
or using of unicode strings before in my script and it still worked)



decode goes from bytes to unicode, the exact reverse.  And you're right, 
you'd need it on input from a file, and theoretically on input from a 
keyboard.


Conceptually, the easiest (not necessarily the fastest) thing to do is 
to always convert any input that comes in byte form to unicode, 
immediately on getting it. Then all processing in the code should be 
done in unicode form.  And you encode any output just before it goes out 
to a byte-device.


Python 3 makes that a natural, as the string type is already unicode, 
and it's byte strings that are the exception.  But all that really 
changes is the syntax you use.


There are defaults all over the place on these conversions.  And 
apparently, your IDE sets those defaults for you, which is a nasty 
thing, since it means things that run in the IDE will run differently 
outside of it.  You're just lucky the difference was an error.  If there 
weren't an error, you might have merrily been creating files with a 
mixture of encodings, which is a real disaster.


One other place where decoding happens is in your source file.  There is 
an optional encoding line you can place at the top of the file 
(immediately after the shebang line) to change how unicode literals with 
non-ASCII characters are interpreted.  Remember your source file is a 
byte file edited with some text editor, and it has been encoded, 
deliberately or accidentally by that editor.  You can avoid the issue by 
always using escape sequences, but if for example, you copy/paste some 
unicode string from an email message into your source code, you'd like 
it to be equivalent.  If your email program, your text editor, and your 
Python compiler are all on the same page, it works amazingly simply.


(That encoding line may affect other things;  I know in Python 3, it 
makes non-ASCII attribute names possible, but I'm not sure if it matters 
in Python 2.x other than for unicode literal strings)



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


Re: Awsome Python - chained exceptions

2013-02-12 Thread Michael Torrie
On 02/12/2013 07:47 PM, Rick Johnson wrote:
 ...Oh Steven, if you only knew how we interpreted the Oops!, more like 
 Doh!.

You keep using that word. I do not think it means what you think it means.

 Got any more bright ideas DeAprano? (Oh gawd that felt good!)

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


Re: string.replace doesn't removes :

2013-02-12 Thread Rick Johnson
On Saturday, February 9, 2013 5:04:18 AM UTC-6, Joshua Robinson wrote:
 Hi Monte-Pythons,
 
 x = this is a simple : text: that has colon
 s = x.replace(string.punctuation, );  OR
 s = x.replace(string.punctuation, ); 
 print x   # 'this is a simple : text: that has colon'
 
 # The colon is still in the text 
 
 Is this a bug or am I doing something wrong ?

Not a bug, you are just expecting Python to read your mind. In actuality what 
you are doing is asking the method string.replace() to replace the 32 char 
string:

   '!#$%\'()*+,-./:;=?@[\\]^_`{|}~' 

with the null string: 

   

...what you INTENDED to do was have Python find every occurrence the each char 
in the string you passed and replace them with the null string. You are 
assuming the replace method handles sequences in the manner you are projecting. 
Sorry, but string#replace does not work that way. Whether or not it should is 
up for debate[1].

However, you can create a loop and pass the arguments one-by-one into the 
method:

py s = a:b  :c: d
py for char in string.punctuation:
s = s.replace(char, ) 
py s
'ab  c d'

But this seems really wasteful if all you want is to remove colons. Are you 
just removing the colons or truly wanting to remove ALL punctuation from the 
string?


 REFERENCES:


[1]: Should string.replace handle list, tuple and dict arguments in addition to 
strings?

py string.replace(('a', 'b', 'c'), 'abcdefgabc')
'defg'
py string.replace(['a', 'b', 'c'], 'abcdefgabc')
'defg'
py string.replace({'a':'A', 'b':'2', 'c':'C'}, 'abcdefgabc')
'A2CdefgA2C'

This would be a more consistent approach to me. Handling only string arguments 
is woefully inadequate. Why would you have a programmer write a loop for this 
every time? 

@pydevGvR
What is the justification for not processing (at the minimum) multiple 
arguments? Do you think strings will most often only need one modification?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generate 16+MAX_WBITS decompressable data

2013-02-12 Thread Fayaz Yusuf Khan
Marc Christiansen wrote:

 Try using a compressobj with 24 = wbits  32. It should work, but I
 didn't try.
 
Er, the problem is that compressobj doesn't accept a WBIT argument.
-- 
Fayaz Yusuf Khan
Cloud architect, Dexetra SS, India
fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com
+91-9746-830-823

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


Re: string.replace doesn't removes :

2013-02-12 Thread Rick Johnson
On Tuesday, February 12, 2013 10:44:09 PM UTC-6, Rick Johnson wrote:

 
  REFERENCES:
 
 [1]: Should string.replace handle list, tuple and dict
 arguments in addition to strings?
 
 py string.replace(('a', 'b', 'c'), 'abcdefgabc')
 'defg'
 [...]

And here is a fine example of how a global function architecture can 
seriously warp your mind! Let me try that again!

Hypothetical Examples:

py 'abcdefgabc'.replace(('a', 'b', 'c'), )
'defg'
py 'abcdefgabc'.replace(['a', 'b', 'c'], )
'defg'
py 'abcdefgabc'.replace({'a':'A', 'b':'2', 'c':'C'})
'A2CdefgA2C'

Or, an alternative to passing dict where both old and new arguments accept the 
sequence:

py d = {'a':'A', 'b':'2', 'c':'C'}
py 'abcdefgabc'.replace(d.keys(), d.values())
'A2CdefgA2C'

Nice thing about dict is you can control both sub-string and replacement-string 
on a case-by-case basis. But there is going to be a need to apply a single 
replacement string to a sequence of substrings; like the null string example 
provided by the OP.

(hopefully there's no mistakes this time) 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Makefiles... are they possible?

2013-02-12 Thread Steven D'Aprano
On Tue, 12 Feb 2013 20:06:35 -0500, Roy Smith wrote:

 One thing we do in our Makefiles is find . -name '*.pyc' | xargs rm.
 It avoids all sorts of nasty and hard to track down bugs (consider what
 happens if you move a .py file from one place in your source tree to
 another and leave the old .pyc behind).


How often do you move files around in the source tree? Meanwhile, *every* 
time you run make, you take a performance hit on every Python module in 
your project, whether it has moved or not.

Seems to me like a fairly heavy-handed response for something quite rare, 
but I suppose that depends on how often you run make.




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


Re: Generate 16+MAX_WBITS decompressable data

2013-02-12 Thread Terry Reedy

On 2/13/2013 12:18 AM, Fayaz Yusuf Khan wrote:

Marc Christiansen wrote:


Try using a compressobj with 24 = wbits  32. It should work, but I
didn't try.


Er, the problem is that compressobj doesn't accept a WBIT argument.


Changed in version 3.3: Added the method, wbits, memlevel, strategy and 
zdict parameters.


--
Terry Jan Reedy

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


Re: Awsome Python - chained exceptions

2013-02-12 Thread Chris Angelico
On Wed, Feb 13, 2013 at 1:47 PM, Rick Johnson
rantingrickjohn...@gmail.com wrote:
On Tuesday, February 12, 2013 12:15:29 AM UTC-6, Steven D'Aprano wrote:
 If you've ever written an exception handler, you've probably written a
 *buggy* exception handler:

 def getitem(items, index):
 # One-based indexing.
 try:
 return items[index-1]
 except IndexError:
 print (Item at index %d is missing % index - 1)  # Oops!


 Unfortunately, when an exception occurs inside an except or finally
 block, the second exception masks the first, and the reason for the
 original exception is lost:

 py getitem(['one', 'two', 'three'], 5)  # Python 2.6
 Traceback (most recent call last):
   File stdin, line 1, in module
   File stdin, line 6, in getitem
 TypeError: unsupported operand type(s) for -: 'str' and 'int'

 Which (by showing the offensive line) is quite clear to me.

No, the offending (not offensive) line is return items[index-1],
which doesn't feature in your traceback at all. It DOES, however,
feature in the Py3.1 double traceback (it's listed as line 4)..

 1. You are using the print function (so we can assume you are using Python 
 3.x)

He is? Could just as easily be the print statement with a single
argument, with unnecessary parentheses around that argument. Which, if
I recall correctly, is one of the recommended approaches for making
2/3 bi-compatible code.

 but then you go and use that old ugly % string interpolation syntax crap! 
 when you should have used the format method of strings.

 print(Item at index {0} is missing.format(index-1)) # Oops!

 ...Oh Steven, if you only knew how we interpreted the Oops!, more like 
 Doh!.

No. Definitely not. Percent interpolation isn't going anywhere - core
devs have said so - and there are many occasions when it is at least
as well suited to the task as .format() is. Also, it's a notation
that's well understood *across languages* and in a variety of message
interpolation systems. Anyone who's worked with *any* of them will
understand that %s inserts a string, %d a number (in decimal), etc,
etc. Granted, the exact details after that may change (eg Python has
%r to emit the representation, while Pike uses %O for any object,
with similar notation), but the format specifiers and modifiers that
came from C are fairly stable, readable, and compact.

In what way is a trivial example like this improved by the use of
format()? The ONLY thing I can think of is that, by forcing you to put
parentheses around the argument, it avoids the issue from the original
post, which is one of operator precedence - but that's something
that's fairly easy to spot when you know what you're looking for, and
is definitely not specific to string formatting.

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


Re: string.replace doesn't removes :

2013-02-12 Thread jmfauth
On 13 fév, 06:26, Rick Johnson rantingrickjohn...@gmail.com wrote:
 On Tuesday, February 12, 2013 10:44:09 PM UTC-6, Rick Johnson wrote:
  
   REFERENCES:
  
  [1]: Should string.replace handle list, tuple and dict
  arguments in addition to strings?

  py string.replace(('a', 'b', 'c'), 'abcdefgabc')
  'defg'
  [...]

 And here is a fine example of how a global function architecture can 
 seriously warp your mind! Let me try that again!

 Hypothetical Examples:

 py 'abcdefgabc'.replace(('a', 'b', 'c'), )
 'defg'
 py 'abcdefgabc'.replace(['a', 'b', 'c'], )
 'defg'
 py 'abcdefgabc'.replace({'a':'A', 'b':'2', 'c':'C'})
 'A2CdefgA2C'

 Or, an alternative to passing dict where both old and new arguments accept 
 the sequence:

 py d = {'a':'A', 'b':'2', 'c':'C'}
 py 'abcdefgabc'.replace(d.keys(), d.values())
 'A2CdefgA2C'

 Nice thing about dict is you can control both sub-string and 
 replacement-string on a case-by-case basis. But there is going to be a need 
 to apply a single replacement string to a sequence of substrings; like the 
 null string example provided by the OP.

 (hopefully there's no mistakes this time)



 d = {ord('a'): 'A', ord('b'): '2', ord('c'): 'C'}
 'abcdefgabc'.translate(d)
'A2CdefgA2C'


 def jmTranslate(s, table):
... table = {ord(k):table[k] for k in table}
... return s.translate(table)
...
 d = {'a': 'A', 'b': '2', 'c': 'C'}
 jmTranslate('abcdefgabc', d)
'A2CdefgA2C'
 d = {'a': None, 'b': None, 'c': None}
 jmTranslate('abcdefgabc', d)
'defg'
 d = {'a': '€', 'b': '', 'c': ''}
 jmTranslate('abcdefgabc', d)
'€defg€'



jmf

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


Re: Awsome Python - chained exceptions

2013-02-12 Thread Michael Torrie
On Feb 13, 2013 12:00 AM, Chris Angelico ros...@gmail.com wrote:

 Which word? we? I'm not entirely sure, given that non-monospaced
 fonts get in the way. Normally people would put exactly as many 
carets/tildes as there are letters in the word, but aligning the text
 in a mono font puts the carets under we, so that clue isn't there.

Sorry I assumed that on a technical list like this one folks would be
viewing emails as the internet gods intended, in a nice monospace font.

I don't see how leading carets would help in a proportional font; it just
doesn't work well for quoting emails I think. Maybe that's why email from
html clients seem to do a lot of top posting and ditch quoting (and I fear
reading) emails all together.

Apologies if the quoted stuff is messed up in this email. Darn phones are
not good at doing proper emailing.
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue17190] _FAST opcodes do no range checking

2013-02-12 Thread Larry Hastings

Larry Hastings added the comment:

I'm not surprised it was discussed to death long ago.  And I can get behind 
wontfix.  But let me just say that

a) I think an uncrashable Python interpreter is a laudable goal, and steps we 
can take towards that should not be dismissed out of hand.

b) I doubt a range check would kill the performance of the _FAST operands.  
It'd be one lookup/compare/branch each, and the branch predictor would always 
guess correctly.  But I admit I have not tested it.

c) Anyway we needn't do it at runtime.  We could just as easily scan over the 
opcodes in the code object constructor and do the range checking there.  If we 
only did the check when the constructor was called directly from Python, it 
should have no measurable performance impact, only a maintenance cost.

d) I expect all these points were brought up in the original discussion.  I'd 
like to read that--but I can't find it.  Any pointers would be appreciated.

--

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



[issue12077] Harmonizing descriptor protocol documentation

2013-02-12 Thread Raymond Hettinger

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


--
assignee: rhettinger - 

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



[issue17136] ctypes tests fail with clang on non-OS X

2013-02-12 Thread Dirkjan Ochtman

Dirkjan Ochtman added the comment:

libffi-3.0.12 has been released with that fix. Perhaps that should be included 
in future Python releases?

--
nosy: +benjamin.peterson, georg.brandl, larry
priority: normal - release blocker

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



[issue9400] multiprocessing.pool.AsyncResult.get() messes up exceptions

2013-02-12 Thread Torsten Bronger

Changes by Torsten Bronger bron...@physik.rwth-aachen.de:


--
nosy: +bronger

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



[issue917120] imaplib: incorrect quoting in commands

2013-02-12 Thread Mauro Cicognini

Mauro Cicognini added the comment:

The removal of the dead code causes imaplib under py3k to lose the quoting 
functionality that is described in documentation (except for passwords, that do 
get always quoted as stated).

I submit that we give at least a temporary warning in the docs, and that the 
_quote() function is exposed to let the programmer do their own quoting when 
they feel it necessary.

--
nosy: +Mauro.Cicognini
versions: +Python 3.3 -Python 2.7

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



[issue17191] pdb list shows unexpected code when stack frame includes a try / finally block

2013-02-12 Thread Abram Clark

New submission from Abram Clark:

The list command in pdb shows an unexpected portion of code after an up command 
enters a try / finally block in the call stack.

To reproduce:

pdb pdb_list_bug_reproduce.py
c
up
list

Expected behavior: Show 11 lines around line 8, throw_something(), which was 
the entry point to the lower stack frame.

Actual behavior: Shows code centered around line 10, in the finally block, 
which is likely cleanup code that has nothing to do with the exception thrown.

--
files: pdb_list_bug_reproduce.py
messages: 181951
nosy: Abram.Clark
priority: normal
severity: normal
status: open
title: pdb list shows unexpected code when stack frame includes a try / finally 
block
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file29047/pdb_list_bug_reproduce.py

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



[issue17170] string method lookup is too slow

2013-02-12 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

I left some comments on Rietveld.

I wonder if PyArg_ParseTupleAndKeywords can be replaced by something that would 
compute and cache the set of keywords; a bit like _Py_IDENTIFIER.

--
nosy: +amaury.forgeotdarc

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



[issue9285] Add a profile decorator to profile and cProfile

2013-02-12 Thread Giampaolo Rodola'

Changes by Giampaolo Rodola' g.rod...@gmail.com:


--
nosy: +georg.brandl

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



[issue17130] Add runcall() function to profile.py and cProfile.py

2013-02-12 Thread Giampaolo Rodola'

Changes by Giampaolo Rodola' g.rod...@gmail.com:


--
nosy: +georg.brandl

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



[issue17187] Python segfaults from improperly formed and called function

2013-02-12 Thread Ramchandra Apte

Ramchandra Apte added the comment:

 Perhaps types.CodeType should refuse to generate the malformed code object in 
 the first place?
Yup.

--
nosy: +ramchandra.apte

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



[issue17189] Add zip64 support to shutil

2013-02-12 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
stage:  - patch review
versions: +Python 3.4 -Python 3.3

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



[issue17172] Add turtledemo to IDLE menu

2013-02-12 Thread Ramchandra Apte

Ramchandra Apte added the comment:

Attached is a patch. I hope the File menu is the right place for this. I had to 
move the code in Lib/turtledemo.py after if __name__ ==... into main().

--

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



[issue17172] Add turtledemo to IDLE menu

2013-02-12 Thread Ramchandra Apte

Changes by Ramchandra Apte maniandra...@gmail.com:


--
keywords: +patch
Added file: http://bugs.python.org/file29048/issue.patch

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



[issue17172] Add turtledemo to IDLE menu

2013-02-12 Thread Ramchandra Apte

Ramchandra Apte added the comment:

Should this be added to Lib/idlelib/NEWS.txt ?

--

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



[issue17192] libffi-3.0.12 import

2013-02-12 Thread Matthias Klose

New submission from Matthias Klose:

issue for tracking the libffi-3.0.12 import. checked that builds on 
x86_64-linux-gnu and arm-linux-gnueabihf do work.

still needs updating/checking the extra copies of:

 - libffi_arm_wince
 - libffi_msvc
 - libffi_osx

--
components: Extension Modules
messages: 181956
nosy: doko
priority: normal
severity: normal
status: open
title: libffi-3.0.12 import
versions: Python 3.4

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



[issue917120] imaplib: incorrect quoting in commands

2013-02-12 Thread R. David Murray

R. David Murray added the comment:

I don't understand what you mean by removing dead code leading to loss of 
functionality, unless you mean that the removal of the call to the quoting code 
in Python3 led to a loss of functionality relative to Python2, in which case I 
agree.  It also led to the behavior being out of sync with the documentation.

Reviewing the history of the changes (see issue 1210), it appears to me that 
the removal of the call to _checkquote was in fact unintentional and is a bug 
(it existed in the port-to-python3 patch submitted by Victor, but was commented 
out, which probably means he had it commented out for testing and did not 
notice he had not restored it).  This makes the later removal of _checkquote 
incorrect as well.

This error is primarily a consequence of imaplib having very few tests.

This module needs a lot of love in Python3 from someone, and it is not an easy 
topic to wrap ones head around.  It's on my list of things to look at, but 
there are a bunch of things ahead of it.

For the immediate issue, it is working as documented in Python2.7, so there is 
nothing to do there.  For Python3 we haven't had the quoting since the start, 
so we have the opportunity to consider changing the quoting rules if we 
wish...and we may have have no choice, since the new behavior has been in 
released versions for several Python3 versions now and starting to quote like 
Python2.7 did might break otherwise working code.  I don't have an opinion on 
how to fix this this yet, since while I know more about the IMAP protocol than 
I did a year ago, I still don't know enough to even write the tests

--
components: +email
nosy: +barry

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



[issue17192] libffi-3.0.12 import

2013-02-12 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 7727be7613f9 by doko in branch 'default':
- Issue #17192: Import libffi-3.0.12.
http://hg.python.org/cpython/rev/7727be7613f9

--
nosy: +python-dev

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



[issue17136] ctypes tests fail with clang on non-OS X

2013-02-12 Thread Matthias Klose

Matthias Klose added the comment:

libffi-3.0.12 is now imported, tracked in issue #17192.

--

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



[issue17192] libffi-3.0.12 import

2013-02-12 Thread Matthias Klose

Changes by Matthias Klose d...@debian.org:


--
nosy: +ronaldoussoren

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



[issue17192] libffi-3.0.12 import

2013-02-12 Thread Ronald Oussoren

Ronald Oussoren added the comment:

libffi_osx is not a copy of the regular libffi, but a (fairly old) fork. I 
don't know how far the two branches have diverged.  

An important feature  of liffi_osx is that is compiles cleanly when all intel 
and ppc related sources are compiled with '-arch ppc -arch i386 -arch x86_64' 
(that is, the relevant sources contain preprocessor guards to ensure the code 
in those files is only compiled for the right archictures). This greatly 
simplifies the build process because it is not necessary to build libffi a 
couple of times and then merge the resulting binaries.

I'm -0 at this point w.r.t. trying to remove libffi_osx, that tree works and 
I'll work on it anyway (it is also used in PyObjC).

--

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



[issue17193] Use binary prefixes

2013-02-12 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Starting around 1998, a number of standards and trade organizations approved 
standards and recommendations for a new set of binary prefixes that would refer 
unambiguously to powers of 1024. According to these, the SI prefixes would only 
be used in the decimal sense, even when referring to data storage capacities: 
kilobyte and megabyte would denote one thousand bytes and one million bytes 
respectively (consistent with SI), while new terms such as kibibyte, mebibyte 
and gibibyte, abbreviated KiB, MiB, and GiB, would denote 1024 bytes, 1048576 
bytes, and 1073741824 bytes respectively.[1]

The proposed patch replaces old terms such as kB or KBytes by new terms such as 
KiB.

[1] http://en.wikipedia.org/wiki/Binary_prefix

--
assignee: docs@python
components: Documentation
files: binary_prefixes.patch
keywords: easy, patch
messages: 181961
nosy: docs@python, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Use binary prefixes
type: enhancement
Added file: http://bugs.python.org/file29049/binary_prefixes.patch

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



[issue9285] Add a profile decorator to profile and cProfile

2013-02-12 Thread Giampaolo Rodola'

Giampaolo Rodola' added the comment:

A preliminary patch for cProfile.py is in attachment. Will make changes to 
profile.py later.

--
Added file: http://bugs.python.org/file29050/profile.patch

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



[issue17187] Python segfaults from improperly formed and called function

2013-02-12 Thread Benjamin Peterson

Benjamin Peterson added the comment:

In general, you can generate whatever junky bytecode you want, and the eval 
loop will happy crash itself. Your on your own when screwing with 
types.CodeType.

--
nosy: +benjamin.peterson

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



[issue17193] Use binary prefixes

2013-02-12 Thread Brett Cannon

Brett Cannon added the comment:

Patch looks good except for the consistent lack of space between number and 
unit, e.g. 5MiB instead of 5 MiB. Is there a reason for this?

--
nosy: +brett.cannon

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



[issue17170] string method lookup is too slow

2013-02-12 Thread Guido van Rossum

Guido van Rossum added the comment:

What's the status of Argument Clinic? Won't that make this obsolete?

--Guido van Rossum (sent from Android phone)

--

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



[issue17194] operator.attrgetter is slower than a lambda

2013-02-12 Thread Florent Xicluna

Changes by Florent Xicluna florent.xicl...@gmail.com:


--
title: operator.attrgetter is slow - operator.attrgetter is slower than a 
lambda

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



  1   2   >