numba 0.7.1: bugfix release + random package

2013-03-12 Thread mark florisson
Numba 0.7.1 is a bugfix release which brings bug fixes such as the
array slicing bug, but it also brings us closer to Python 3
compatibility thanks to Hernan Grecco. The release also brings the
'numba.random' package, thanks to Travis Oliphant. It allows you to
use fast random number generators from randomkit provided in NumPy,
directly from numba code. An example can be found here:
https://github.com/numba/numba/blob/master/numba/tests/support/random/test_random_gibbs.py#L13

Download: https://pypi.python.org/pypi/numba/0.7.1
Documentation: http://numba.pydata.org/numba-doc/0.7/
Github: https://github.com/numba/numba

Numba
==
Numba is an just-in-time specializing compiler for Python and NumPy
code to LLVM for annotated functions (through decorators). It's goal
is to seamlessly integrate with the Python scientific software stack
and provide optimized native code and integration with native foreign
languages.


Enjoy!
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Running external module and accessing the created objects

2013-03-12 Thread Rick Johnson
On Monday, March 11, 2013 6:57:28 PM UTC-5, Kene Meniru wrote:

 --
 # contents of myapp.py
 import math

 class MyApp(object):
 def __init__(self):
 super(MyApp, self).__init__()
 self.name = MyAppName


 def testFunction():
 boke = Smilling
 print math.sin(1), boke
 -
 # contents of myappwin
 def test():
 dic = {}
 execfile(myapp.py, dic)
 testObj = dic[MyApp]() # access MyApp class
 dic[testFunction]()# execute testFunction
 print testObj.name   # print string


 test()
 -
 # OUTPUT
 $ python myappwin.py
 0.841470984808 Smilling
 MyAppName

Hmm. I don't understand why you think a simple old import won't work. Here is 
code (with names slightly adjusted for sanity).


 Contents of mymodule.py


import math

class Foo(object):
def __init__(self):
super(Foo, self).__init__()
self.name = MyAppName

def foo():
boke = Smilling
print math.sin(1), boke


 Contents of myscript.py


# This next import statement requires that a script named
# myapp.py exist on the Python search path. If you cannot
# bring the script into the search path, you can bring the
# search path to the script by editing sys.path.
#
# import sys
# sys.path.append('foderContainingMyModule')
# del sys
#
# But i would suggest placing the module on search path.

from mymodule import Foo, foo

def test():
##dic = {}
##execfile(myapp.py, dic)
##testObj = dic[MyApp]() # access MyApp class
instance = Foo()
##dic[testFunction]()# execute testFunction
foo()
##print testObj.name   # print string
print instance.name

if __name__ == '__main__':
test()


 Results of running myscript


0.841470984808 Smilling
MyAppName

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


RE: metatype

2013-03-12 Thread Peter Otten
shangyu wrote:

 Hi dear all,
 I have following Python code
 class mydict(dict):
 def __init__(self):
 pass
 I wonder how this new type get created . What is the type of metatype in
 the following line ? type = (PyTypeObject *)metatype-tp_alloc(metatype,
 nslots); (line 2296 of typeobject.c Python2.7.3 source code)
 It seems PyDict_Type . If so , how do I expect the tp_alloc will return a
 PyTypeObject object ? Maybe I've missed something ? Many thanks!!!

 I think I've found it out . For new-style class it's PyType_Type and for
 old-style class it's PyClass_Type . Thanks anyway.

Yes. You can find that out without resorting to the C API:

 class A(dict): pass
... 
 type(A)
type 'type'

A fancy example:

 import abc
 class B:
... __metaclass__ = abc.ABCMeta
... 
 type(B)
class 'abc.ABCMeta'


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


Re: Store a variable permanently

2013-03-12 Thread Steven D'Aprano
On Mon, 11 Mar 2013 11:19:49 +0100, Jean-Michel Pichavant wrote:

[...]
 While your point about security is fair, the others aren't. Pickle uses
 by default an ascii representation of the data, it's readable and
 writeable.
 
 import pickle
 a = 758
 pickle.dump(a, open('test.pickle', 'w')) 
 !cat test.pickle
 I758
 .


What is that? It's not Python code, !cat test.pickle gives a syntax error.


By the way, you can dump pickles directly to a string, which may be more 
convenient for demonstration purposes:

py import pickle
py pickle.dumps(758)
'I758\n.'


I take your point that a pickle of a simple int is relatively readable, 
although it does require care when editing. If you drop the dot, or the 
newline, or change the I to lowercase, or even merely add a space after 
the dot, bad things happen.

But yes, I will concede that a single pickled int is relatively readable. 
But that certainly isn't always the case:

py pickle.dumps([])
'(lp0\n.'
py pickle.dumps([None])
'(lp0\nNa.'


For even a *slightly* more complex example, the pickle turns into noise.



 I don't see how 1 line of code (+ the import) can be overkill versus the
 dozen untested lines you provide (I'm sure it's working, my point being
 pickle has already been tested). 

Pickle is a big module, over 1400 lines, capable of serialising almost 
anything. It's a big, powerful hammer for cracking armour-plated 
coconuts. But a single int is pretty much a peanut. Compare pickle's 1400 
lines with the dozen or so lines I provided. That is all that I meant by 
overkill.


 More importantly, if the code evolve
 and you need to store 2 integers, or a tuple or anything else that is
 pickable, it costs you 0 dev if you're using pickle.


Sure. And once you move beyond a single value, the ability to call pickle 
human readable and writable decreases rapidly. Without using pickle, 
can you tell what this represents?

((dp0
S'y'
p1
I3
sS'x'
p2
I2
s(lp3
S'a'
p4
aS'b'
p5
aI23
tp6
.




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


Re: Running external module and accessing the created objects

2013-03-12 Thread Dave Angel

On 03/12/2013 12:05 AM, Michael Torrie wrote:

On 03/11/2013 06:48 PM, Dave Angel wrote:

I hope you're just kidding.  execfile() and exec() are two of the most
dangerous mechanisms around.  import or __import__() would be much
better, as long as your user hasn't already run myapp.py as his script.


It's not possible to setuid a python script, so I don't see how execfile
or exec is any more dangerous than the user creating a shell script that
rm -rf * things, and then running it.

Bash exec's scripts all the time that users create and provide.  How
is this different and what issues did you have in mind, exactly?



Mainly that exec and execfile are a slippery slope for a new programmer. 
 Once as they get it in their minds that this is the way to do things, 
they'll soon fall into using one of them on raw_input() data, on network 
data, and on other untrusted sources.



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


Re: Missing logging output in Python

2013-03-12 Thread W. Matthew Wilson
I made that code into a program like this:

### BEGIN

import logging

def configure_logging():

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s
%(name)-12s %(levelname)8s %(message)s',
datefmt='%Y-%m-%d\t%H:%M:%s',
filename='/tmp/logfun.log', filemode='a')

# define a Handler that writes INFO messages to sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)

# set format that is cleaber for console use
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s
%(message)s')

# tell the handler to use this format
console.setFormatter(formatter)

# add the handler to the root logger
logging.getLogger('').addHandler(console)

if __name__ == '__main__':

configure_logging()

logging.debug('a')
logging.info('b')
logging.warn('c')
logging.error('d')
logging.critical('e')

### END

and when I run the program, I get INFO and greater messages to stderr:

$ python logfun.py
root: INFO b
root: WARNING  c
root: ERRORd
root: CRITICAL e

and I get this stuff in the log file:

$ cat /tmp/logfun.log
2013-03-12 07:31:1363087862 rootDEBUG a
2013-03-12 07:31:1363087862 root INFO b
2013-03-12 07:31:1363087862 root  WARNING c
2013-03-12 07:31:1363087862 rootERROR d
2013-03-12 07:31:1363087862 root CRITICAL e

In other words, your code works!  Maybe you should check permissions on the
file you are writing to.

Matt




On Fri, Mar 8, 2013 at 9:07 AM, gabor.a.hal...@gmail.com wrote:

 Hi,

 I would like to enable loggin in my script using the logging module that
 comes with Python 2.7.3.

 I have the following few lines setting up logging in my script, but for
 whatever reason  I don't seem to get any output to stdout  or to a file
 provided to the basicConfig method.

 Any ideas?

 # cinfiguring logging
 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s
 %(levelname)8s %(message)s',
 datefmt='%Y-%m-%d\t%H:%M:%s',
 filename=config[currentLoop], filemode='a')
 # define a Handler that writes INFO messages to sys.stderr
 console = logging.StreamHandler()
 console.setLevel(logging.INFO)
 # set format that is cleaber for console use
 formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
 # tell the handler to use this format
 console.setFormatter(formatter)
 # add the handler to the root logger
 logging.getLogger('').addHandler(console)
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
W. Matthew Wilson
m...@tplus1.com
http://tplus1.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Store a variable permanently

2013-03-12 Thread Jean-Michel Pichavant
- Original Message -
 On Mon, 11 Mar 2013 11:19:49 +0100, Jean-Michel Pichavant wrote:
 
 [...]
  While your point about security is fair, the others aren't. Pickle
  uses
  by default an ascii representation of the data, it's readable and
  writeable.
  
  import pickle
  a = 758
  pickle.dump(a, open('test.pickle', 'w'))
  !cat test.pickle
  I758
  .
 
 
 What is that? It's not Python code, !cat test.pickle gives a syntax
 error.

It's a IPython shell session, !cat test.pickle writes the content of that file 
to stdout. But I have the feeling you already know that ;)

[snip] 
 Pickle is a big module, over 1400 lines, capable of serialising
 almost
 anything. It's a big, powerful hammer for cracking armour-plated
 coconuts. But a single int is pretty much a peanut. Compare pickle's
 1400
 lines with the dozen or so lines I provided. That is all that I meant
 by
 overkill.

I would be surprised if the 1400 lines were used to dump an integer. Anyway who 
cares about the size of the module, a lot of people import sys and os while 
using only a very subset of it.

And to reuse your analogy, there's nothing wrong cracking a peanut with a 
hammer as long as you have it in your hands and that it takes absolutely no 
effort, compared to building your own small peanut cracker. Trying to crack the 
peanut by landing an airplane on it, that would work *and* be overkill.

Now about analogies:
http://www.linguistrix.com/blog/?p=456

Cheers,

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


Reversing bits in a byte

2013-03-12 Thread Robert Flintham
Hi,

I have a 'bytes' object which contains a simple bitmap image (i.e. 1 bit per 
pixel).  I can't work out how I would go about displaying this image.  Does 
anyone have any thoughts?

All the best,
Rob


Robert Flintham
Trainee Clinical Scientist - MRI
Tel:

 +44 (0)121 371 7000

Email:

 robert.flint...@uhb.nhs.uk

Web:

 http://www.uhb.nhs.uk


We're bringing the world's most advanced cancer treatments to Birmingham.
Find out more at www.qecancerappeal.orghttp://www.qecancerappeal.org or text 
QEHB01 £5 to 70070 to donate £5 to our appeal.

RRPPS
Medical Physics - University Hospitals Birmingham NHS Foundation Trust
63 Melchett Road, Kings Norton,
Birmingham, B30 3HP

[cid:image001.gif@01CE1E6D.AF57F9D0]
DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or 
all of which may be confidential or legally privileged. It is for the exclusive 
use of the intended recipient(s) only. If an addressing or transmission error 
has misdirected this e-mail and you are not the intended recipient(s), please 
notify the author by replying to this e-mail. If you are not the intended 
recipient you must not use, disclose, distribute, copy, print, or rely on this 
e-mail or any attachments, as this may be unlawful.
inline: image001.gif-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing bits in a byte

2013-03-12 Thread Dave Angel

On 03/11/2013 11:32 AM, Robert Flintham wrote:

Hi,

I have a 'bytes' object which contains a simple bitmap image (i.e. 1 bit per 
pixel).  I can't work out how I would go about displaying this image.  Does 
anyone have any thoughts?

All the best,
Rob




How does your subject line relate to your question?

But more importantly, what version of Python, what OS, and which GUI 
library (wxpython, qt, etc.) are you used to?  Specify those, and 
somebody familiar with that particular library will probably pop up with 
an answer.




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


RE: Reversing bits in a byte

2013-03-12 Thread Robert Flintham
Sorry, the subject line was for a related question that I decided not to ask, I 
forgot to change it when I changed my email.  I've changed it now!

I'm using Python 3.3 on Windows with the pydicom module 
(http://code.google.com/p/pydicom/).  Using pydicom, I've ended up with a 
bytes object of length (512*512/8 = 32768) containing a 512x512 1-bit bitmap 
(i.e. each byte represents 8 pixels of either 1 or 0).  When I print this to 
screen I get:
'b\x00\x00\x00.'

I can unpack this to a tuple of the integer representations of binary data, but 
that doesn't really help as presume I need the binary (8 digit) representation 
to be able to translate that into an image.

I wasn't sure which GUI library to use, so haven't specified one.  As it's 
Python 3, Tkinter is available.  I also have matplotlib and numpy installed, 
and PIL.

Ideally, I'd like to be able to access the pixel data in the form of a numpy 
array so that I can perform image-processing tasks on the data.

So now that I've explained myself slightly more fully, does anyone have any 
thoughts on how to do this?

All the best,
Rob

Robert Flintham
Trainee Clinical Scientist - MRI

Tel:  +44 (0)121 371 7000
Email:   robert.flint...@uhb.nhs.uk
Web:  http://www.uhb.nhs.uk

We're bringing the world's most advanced cancer treatments to Birmingham.
Find out more at www.qecancerappeal.org or text QEHB01 £5 to 70070 to donate £5 
to our appeal.

RRPPS
Medical Physics - University Hospitals Birmingham NHS Foundation Trust
63 Melchett Road, Kings Norton,
Birmingham, B30 3HP


ð Delivering the best in care



-Original Message-
From: Python-list 
[mailto:python-list-bounces+robert.flintham=uhb.nhs...@python.org] On Behalf Of 
Dave Angel
Sent: 12 March 2013 12:47
To: python-list@python.org
Subject: Re: Reversing bits in a byte

On 03/11/2013 11:32 AM, Robert Flintham wrote:
 Hi,

 I have a 'bytes' object which contains a simple bitmap image (i.e. 1 bit per 
 pixel).  I can't work out how I would go about displaying this image.  Does 
 anyone have any thoughts?

 All the best,
 Rob



How does your subject line relate to your question?

But more importantly, what version of Python, what OS, and which GUI library 
(wxpython, qt, etc.) are you used to?  Specify those, and somebody familiar 
with that particular library will probably pop up with an answer.



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

DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or 
all of which may be confidential or legally privileged. It is for the exclusive 
use of the intended recipient(s) only. If an addressing or transmission error 
has misdirected this e-mail and you are not the intended recipient(s), please 
notify the author by replying to this e-mail. If you are not the intended 
recipient you must not use, disclose, distribute, copy, print, or rely on this 
e-mail or any attachments, as this may be unlawful.

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


RE: Reversing bits in a byte

2013-03-12 Thread Robert Flintham
Further to my earlier reply to Dave:

I'd like to either display the image in a GUI, or save it in a format that can 
be opened easily in Windows (like a PNG or a 24-bit BMP).

I know the dimensions as it's coming from the header of a DICOM file.  I'm 
trying to analyse DICOM images where an 'overlay' image is stored as a bitmap 
in the header information.  So the bitmap data is one DICOM tag (6000,3000) and 
the height and width of the overlay are in two other tags (6000,0010) and 
(6000,0011).

All the best,
Rob

Robert Flintham
Trainee Clinical Scientist - MRI

Tel:  +44 (0)121 371 7000
Email:   robert.flint...@uhb.nhs.uk
Web:  http://www.uhb.nhs.uk

We're bringing the world's most advanced cancer treatments to Birmingham.
Find out more at www.qecancerappeal.org or text QEHB01 £5 to 70070 to donate £5 
to our appeal.

RRPPS
Medical Physics - University Hospitals Birmingham NHS Foundation Trust
63 Melchett Road, Kings Norton,
Birmingham, B30 3HP


ð Delivering the best in care



-Original Message-
From: Tim Chase [mailto:python.l...@tim.thechases.com] 
Sent: 12 March 2013 13:21
To: Robert Flintham
Cc: 'python-list@python.org'
Subject: Re: Reversing bits in a byte

On 2013-03-11 15:32, Robert Flintham wrote:
 I have a 'bytes' object which contains a simple bitmap image (i.e.
 1 bit per pixel).  I can't work out how I would go about displaying 
 this image.  Does anyone have any thoughts?

You'd need to detail
- how you want to display it (console, GUI, web page)
- how you know what the dimensions are
- the bit order

It could be something as simple as

  HEIGHT = 40
  some_bytes = file('data.bin').read()
  WIDTH = len(some_bytes) // HEIGHT
  for i, byte in enumerate(some_bytes):
if i and i % WIDTH == 0:
  print # a new line
for bit in range(8):
  if byte  (1  bit):
print '*',
  else:
print ' ',


-tkc

 DISCLAIMER:
[trim a paragraph of useless junk]
Please remove these disclaimers if at all possible.  You're posting to a public 
forum, which pretty much waives all credibility to the disclaimer (not that 
they've held much legal standing in any argument I've heard).






DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or 
all of which may be confidential or legally privileged. It is for the exclusive 
use of the intended recipient(s) only. If an addressing or transmission error 
has misdirected this e-mail and you are not the intended recipient(s), please 
notify the author by replying to this e-mail. If you are not the intended 
recipient you must not use, disclose, distribute, copy, print, or rely on this 
e-mail or any attachments, as this may be unlawful.

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


Re: Running external module and accessing the created objects

2013-03-12 Thread Kene Meniru
Michael Torrie torriem at gmail.com writes:

 It's not possible to setuid a python script, so I don't see how execfile
 or exec is any more dangerous than the user creating a shell script that
 rm -rf * things, and then running it.
 
 Bash exec's scripts all the time that users create and provide.  How
 is this different and what issues did you have in mind, exactly?
 

This is close to my reasoning too, although I appreciate Dave's concern.



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


Re: Running external module and accessing the created objects

2013-03-12 Thread Kene Meniru
Dave Angel davea at davea.name writes:

 
 The __import__() function is defined
 http://docs.python.org/2/library/functions.html#__import__
 

Thanks. The name of the imported file will change with each user and for
each project so according to the this reference using this in my situation makes
sense.

 appname = myapp
 usermodule = __import__(appname, globals(), locals(), [], -1)
 
 And now you can use usermodule as though you had imported it in the 
 usual way.
 

Thanks. This worked! I was using __import__ without the other arguments
before. I guess did not think it will work :-)

 As for my other caveat, I've said it before in this thread.  Make sure 
 you don't ever load a module by more than one name, or you'll end up 
 with a mess.  And that includes the original script, which is loaded by 
 the name '__main__'
 
 You also should avoid any circular import, as it can be very tricky to 
 deal with them.
 

The two programs are separate, there is no fear of a circular import. Also,
I need only a function to get access to the objects in the other module so
the import is inside the function... no fear of ending up in a mess.

Thanks. I guess this makes more sense than execfile and it works.

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


Matplotlib Slider Widget and changing colorbar threshold

2013-03-12 Thread kevin . khan27
I am currently trying to work on a program that will allow the user to display 
their dataset in the form of a colormap and through the use of sliders, it will 
also allow the user to adjust the threshold of the colormap and thus update the 
colormap accordingly.  The best to describe this would be through the use of a 
picture:  ![enter image description here][1]


  [1]: http://i.stack.imgur.com/1T9Qp.png


This image shows how the colorbar should look before (the image on the left) 
and after (the image on the right) the adjustment.  As the threshold values of 
the colrobar are changed, the colormap would be updated accordingly.

Now I am mainly using matplotlib and I found that matplotlib does support some 
widgets, such as a slider.  However the area I need help in is devising a piece 
of code which will update the colorbar and colormap (like the way shown in the 
picture above) when the slider is adjusted.  I was wondering if anyone has done 
this before and might have a piece of code they would be willing to share and 
might have pointers as to how this can be achieved.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing bits in a byte

2013-03-12 Thread Tim Chase
On 2013-03-11 15:32, Robert Flintham wrote:
 I have a 'bytes' object which contains a simple bitmap image (i.e.
 1 bit per pixel).  I can't work out how I would go about displaying
 this image.  Does anyone have any thoughts?

You'd need to detail
- how you want to display it (console, GUI, web page)
- how you know what the dimensions are
- the bit order

It could be something as simple as

  HEIGHT = 40
  some_bytes = file('data.bin').read()
  WIDTH = len(some_bytes) // HEIGHT
  for i, byte in enumerate(some_bytes):
if i and i % WIDTH == 0:
  print # a new line
for bit in range(8):
  if byte  (1  bit):
print '*',
  else:
print ' ',


-tkc

 DISCLAIMER:
[trim a paragraph of useless junk]
Please remove these disclaimers if at all possible.  You're posting
to a public forum, which pretty much waives all credibility to the
disclaimer (not that they've held much legal standing in any argument
I've heard).





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


Re: Reversing bits in a byte

2013-03-12 Thread Oscar Benjamin
On 12 March 2013 13:28, Robert Flintham robert.flint...@uhb.nhs.uk wrote:
 Sorry, the subject line was for a related question that I decided not to ask, 
 I forgot to change it when I changed my email.  I've changed it now!

 I'm using Python 3.3 on Windows with the pydicom module 
 (http://code.google.com/p/pydicom/).  Using pydicom, I've ended up with a 
 bytes object of length (512*512/8 = 32768) containing a 512x512 1-bit 
 bitmap (i.e. each byte represents 8 pixels of either 1 or 0).  When I print 
 this to screen I get:
 'b\x00\x00\x00.'

 I can unpack this to a tuple of the integer representations of binary data, 
 but that doesn't really help as presume I need the binary (8 digit) 
 representation to be able to translate that into an image.

 I wasn't sure which GUI library to use, so haven't specified one.  As it's 
 Python 3, Tkinter is available.  I also have matplotlib and numpy installed, 
 and PIL.

 Ideally, I'd like to be able to access the pixel data in the form of a numpy 
 array so that I can perform image-processing tasks on the data.

 So now that I've explained myself slightly more fully, does anyone have any 
 thoughts on how to do this?

Numpy and matplotlib will do what you want:

import numpy as np
import matplotlib.pyplot as plt

def bits_to_ndarray(bits, shape):
abytes = np.frombuffer(bits, dtype=np.uint8)
abits = np.zeros(8 * len(abytes), np.uint8)
for n in range(8):
abits[n::8] = (abytes % (2 ** (n+1))) != 0
return abits.reshape(shape)

# 8x8 image = 64 bits bytes object
bits = b'\x00\xff' * 4

img = bits_to_ndarray(bits, shape=(8, 8))
plt.imshow(img)
plt.show()


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


Snowed In?

2013-03-12 Thread BlindAnagram
Hi Geoff

Are you snowed in?

Its OK here.

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


Re: Reversing bits in a byte

2013-03-12 Thread Oscar Benjamin
On 12 March 2013 14:59, Oscar Benjamin oscar.j.benja...@gmail.com wrote:
 Numpy and matplotlib will do what you want:

 import numpy as np
 import matplotlib.pyplot as plt

 def bits_to_ndarray(bits, shape):
 abytes = np.frombuffer(bits, dtype=np.uint8)
 abits = np.zeros(8 * len(abytes), np.uint8)
 for n in range(8):
 abits[n::8] = (abytes % (2 ** (n+1))) != 0

Whoops! The line above should be
abits[n::8] = (abytes  (2 ** n)) != 0

 return abits.reshape(shape)

 # 8x8 image = 64 bits bytes object
 bits = b'\x00\xff' * 4

 img = bits_to_ndarray(bits, shape=(8, 8))
 plt.imshow(img)
 plt.show()


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


Re: [Python-Help] idle doesn't work

2013-03-12 Thread leonardo


first of all thanks for trying to help me. the text of my email was the 
following:
i have a mac os x 10.8, i had already python 2.7, i downloaded python 
3.3 and active tcl 8.5, but idle and the new version don't work, the 
answer is:idle's subprocess didn't make connection or personal firewall 
is blocking. do you know what can i do ?

or can i use other easy editors to program in python?

i am frustated cause i can use only the old python 2.7 in the terminal 
window. python 3.3 has not taken place and idle gives the above 
mentioned error..


thanks for any help!





Il 12/03/2013 0.20, Matthew Dixon Cowles ha scritto:

Dear Leonardo,
I only got two copies of that message. We're going in the right
direction.


that answer didn't help me..

Did it not work to run IDLE in a terminal window with the -n
argument? Or are you having difficulty doing that?

IDLE doesn't have any unique abilities. Many people (including me)
use Python under OS X with just a couple of terminal windows and a
text editor. Have you tried that? Have you run into difficulties with
it?

Regards,
Matt




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


2-D drawing/map with python

2013-03-12 Thread Huseyin Emre Guner
Hello, 
I am newbie in Python. I would like to make a project using python.
The main ideo of this project is that a user enters the x,y values to  the 
Gui(PyQt or Gtk) and then a 2-D map is plotted due to the x,y values. First, I 
use Pygame commands (pygame.draw.line(window, (255, 255, 255), (10, 10), (200, 
400)) However  I could not establish a gui with pygame. Now I would like to 
use the PyQt.  Could you please give me advice for this project?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing bits in a byte

2013-03-12 Thread 88888 Dihedral
Oscar Benjamin於 2013年3月12日星期二UTC+8下午11時44分50秒寫道:
 On 12 March 2013 14:59, Oscar Benjamin oscar.j.benja...@gmail.com wrote:
 
  Numpy and matplotlib will do what you want:
 
 
 
  import numpy as np
 
  import matplotlib.pyplot as plt
 
 
 
  def bits_to_ndarray(bits, shape):
 
  abytes = np.frombuffer(bits, dtype=np.uint8)
 
  abits = np.zeros(8 * len(abytes), np.uint8)
 
  for n in range(8):
 
  abits[n::8] = (abytes % (2 ** (n+1))) != 0
 
 
 
 Whoops! The line above should be
 
 abits[n::8] = (abytes  (2 ** n)) != 0
 
 
 
  return abits.reshape(shape)
 
 
 
  # 8x8 image = 64 bits bytes object
 
  bits = b'\x00\xff' * 4
 
 
 
  img = bits_to_ndarray(bits, shape=(8, 8))
 
  plt.imshow(img)
 
  plt.show()
 
 
 
 
 
  Oscar

Now the dram is so cheap in the street. Please type in a tuple of 
all 8 bit inversions  from the index to the result then just take a look up
by the index to solve the problem. 

# there are ways to exchange the top 4 bits and the low 4bits, then swap
inside the nibbles then swap the 4 2bit pairs in the old way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Snowed In?

2013-03-12 Thread Octothorpe
On Tue, 12 Mar 2013 15:28:27 +, BlindAnagram wrote:

 Hi Geoff
 
 Are you snowed in?
 
 Its OK here.
 
Brian

Why Yes, matter if fact I am listening to snow blind
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Help] idle doesn't work

2013-03-12 Thread Ned Deily
In article 513f5080.6030...@libero.it,
 leonardo tampucciol...@libero.it wrote:
 first of all thanks for trying to help me. the text of my email was the 
 following:
 i have a mac os x 10.8, i had already python 2.7, i downloaded python 
 3.3 and active tcl 8.5, but idle and the new version don't work, the 
 answer is:idle's subprocess didn't make connection or personal firewall 
 is blocking. do you know what can i do ?
 or can i use other easy editors to program in python?
 
 i am frustated cause i can use only the old python 2.7 in the terminal 
 window. python 3.3 has not taken place and idle gives the above 
 mentioned error..

Try typing the following in a terminal window:

 idle3.3

or, possibly

 /usr/local/bin/idle3.3

and see if there is a more useful error message.

If that doesn't work, try adding -n:

 idle3.3 -n

-- 
 Ned Deily,
 n...@acm.org

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


How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread Norah Jones
I want to create a random float array of size 100, with the values in the array 
ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not 
work. How can i get what i want to achieve?

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


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread Boris FELD
You can use [random.random() * 5 for x in range(100)] but works only
on range [0, 5). If you want to include 5, you will need more code.

Cheers,
FELD Boris

2013/3/12 Norah Jones nh.jone...@gmail.com:
 I want to create a random float array of size 100, with the values in the
 array ranging from 0 to 5. I have tried random.sample(range(5),100) but that
 does not work. How can i get what i want to achieve?
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Finding the Min for positive and negative in python 3.3 list

2013-03-12 Thread Norah Jones
For example:
a=[-15,-30,-10,1,3,5]

I want to find a negative and a positive minimum.

example: negative
print(min(a)) = -30
 
positive
print(min(a)) = 1

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


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread Gary Herron

On 03/12/2013 10:11 AM, Norah Jones wrote:
I want to create a random float array of size 100, with the values in 
the array ranging from 0 to 5. I have tried 
random.sample(range(5),100) but that does not work. How can i get what 
i want to achieve?






 [random.uniform(0,5) for i in range(100)]
[0.035440065542497456, 1.437405027400226, 4.3729265564939235, 
1.8571876890801535, 3.3707291675828355, 3.8527038142772803, 
2.335308526527048, 1.6648256912958126, 2.619282525564386, 
0.49146229156297017, 0.44118757769151584, 4.739666518393803, 
2.382053744691543, 0.49644235270002446, 3.2450874430280967, 
2.907453418492667, 4.476790608458042, 3.6331854165844604, 
4.048234752835737, 1.0561381241342283, 2.812909536326582, 
3.561597391575344, 2.6487355099594017, 0.29397014028037627, 
2.4479483428627753, 3.958448741888134, 2.407241234096458, 
1.3214223763910538, 2.13697973410729, 0.5948251249983533, 
1.7529836288331397, 1.5086813377327446, 1.8586362776340244, 
1.2208704263132752, 0.641484635760266, 1.3848412838385726, 
0.9293523709719054, 2.186001913964843, 4.573380203193875, 
2.139476734752273, 2.9472883699144536, 2.896233361842901, 
3.6862386168483736, 0.34731746668937247, 0.32240948705737016, 
3.5558945043043533, 3.2122777306650474, 4.361615595368701, 
0.015650980269780734, 3.6657002416980946, 2.559029702763296, 
3.1821909947792215, 1.110074378492174, 4.631074891897119, 
0.34141410223593516, 4.857392826027885, 3.527794364975918, 
1.1557966421173278, 3.052715879227505, 3.5157974813529522, 
1.1124961331040095, 0.3481541778415814, 4.669841649649461, 
0.5971397176504589, 2.558151735886299, 1.2604807126742945, 
2.281602331386756, 2.1519211043558695, 3.3468967934451657, 
1.8240743647766071, 2.91696855571327, 0.6894263573879533, 
2.7732038929294616, 4.783919829213994, 4.082864012400709, 
0.16128311206877133, 4.959480373070126, 2.8458909583600187, 
4.49488874467, 4.647426388056034, 3.111088594459788, 
4.261340689865024, 1.6013438490852865, 3.6386026965034852, 
1.212916907042898, 3.3586184962657706, 3.6105733007635954, 
0.5372141790624257, 0.9433843973095679, 3.113889114931214, 
3.05408169326, 2.360224809741029, 2.026697918525358, 
1.322913986495805, 4.341848866805052, 0.970311202088483, 
2.002058149505537, 0.07453277198439523, 1.9633241018322773, 
4.22967258746455]



--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: Finding the Min for positive and negative in python 3.3 list

2013-03-12 Thread Jean-Michel Pichavant

- Original Message - 

 For example:
 a=[-15,-30,-10,1,3,5]

 I want to find a negative and a positive minimum.

 example: negative
 print(min(a)) = -30

 positive
 print(min(a)) = 1
 --
 http://mail.python.org/mailman/listinfo/python-list

min(a)

and

min([e for e in a if e =0]

Cheers,

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: Finding the Min for positive and negative in python 3.3 list

2013-03-12 Thread Wolfgang Maier
Norah Jones nh.jones01 at gmail.com writes:

 
 For example:
 a=[-15,-30,-10,1,3,5]
 I want to find a negative and a positive minimum.
 example: negative
 print(min(a)) = -30
 positive
 print(min(a)) = 1
 
 
 

try this:
min(a)   = -30
min([n for n in a if i0])   = 1

of course, you have to figure out what you want to do with a zero value.






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


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread Maarten
On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote:
 I want to create a random float array of size 100, with the values in the 
 array ranging from 0 to 5. I have tried random.sample(range(5),100) but that 
 does not work. How can i get what i want to achieve?

Use numpy

import numpy as np
np.random.uniform(0, 5, 100)

# note that the values are from the interval [0, 5)

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


Re: Finding the Min for positive and negative in python 3.3 list

2013-03-12 Thread Devin Jeanpierre
 min(a)

This does not return a negative minimum on input [1] (because there is none).

 and

 min([e for e in a if e =0]

This does not return a positive minimum on input [0] (because there is none).

I would have said:

pos_min = min(e for e in a if e  0)
neg_min = min(e for e in a if e  0)

And then deal with the ValueError when there is no such minimum, as appropriate.

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


Re: Finding the Min for positive and negative in python 3.3 list

2013-03-12 Thread Terry Reedy

On 3/12/2013 1:03 PM, Norah Jones wrote:

For example:
a=[-15,-30,-10,1,3,5]

I want to find a negative and a positive minimum.

example: negative
print(min(a)) = -30

positive
print(min(a)) = 1


If this is homework, stop reading and do it yourself ;-)
Otherwise...
 min(i for i in a if i 0)
1
 max(i for i in a if i  0)
-10
 min(i for i in a if i  0)
-30

You did not specify if you would include 0 in a pos min (0 is neither 
really positive or negative).


--
Terry Jan Reedy

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


image transforming web proxy?

2013-03-12 Thread Skip Montanaro
I stumbled upon an old FFT tutorial on astro.berkeley.edu website
whose images are in xbm format.  Neither Chrome nor Firefox knows how
to display X bitmap format and for Chrome at least, I've been unable
to find an extension to do the conversion (didn't hunt for a FF
extension).  I can clearly download the whole kit-n-kaboodle, use any
of a number of different tools to convert the images from xbm to png,
then view things locally.  I finally figured out that Opera supports
xbm and downloaded it.

I wonder though, if there is a Python-based web proxy out there which
can transparently transform obsolete image formats like xbm into
png, jpeg, presumably using PIL?

Thanks,

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


Re: Finding the Min for positive and negative in python 3.3 list

2013-03-12 Thread Wolfgang Maier
Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de writes:

 
 Norah Jones nh.jones01 at gmail.com writes:
 
  
  For example:
  a=[-15,-30,-10,1,3,5]
  I want to find a negative and a positive minimum.
  example: negative
  print(min(a)) = -30
  positive
  print(min(a)) = 1
  
  
  
 
 try this:
 min(a)   = -30
 min([n for n in a if n0])   = 1
 
 of course, you have to figure out what you want to do with a zero value.
 
 

the i above has to be an n, of course, sorry for that typo.

by the way, if you need both values and your list is really huge, an explicit
for loop checking each number whether it's the current negative and positive
minimum might be faster, but that would have to be tested. Also, I'm wondering
whether you could somehow exploit the fact that if your list contains 0 (or 1
depending on how you want to treat zero values) you have for sure found the
minimum for your positive numbers? 





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


Re: [Python-Help] idle doesn't work

2013-03-12 Thread leonardo


thanks now python shell works



Il 12/03/2013 17.52, Ned Deily ha scritto:

In article 513f5080.6030...@libero.it,
  leonardo tampucciol...@libero.it wrote:

first of all thanks for trying to help me. the text of my email was the
following:
i have a mac os x 10.8, i had already python 2.7, i downloaded python
3.3 and active tcl 8.5, but idle and the new version don't work, the
answer is:idle's subprocess didn't make connection or personal firewall
is blocking. do you know what can i do ?
or can i use other easy editors to program in python?

i am frustated cause i can use only the old python 2.7 in the terminal
window. python 3.3 has not taken place and idle gives the above
mentioned error..

Try typing the following in a terminal window:

  idle3.3

or, possibly

  /usr/local/bin/idle3.3

and see if there is a more useful error message.

If that doesn't work, try adding -n:

  idle3.3 -n



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


programming course

2013-03-12 Thread leonardo

sorry for bothering you, i found www.code.org, do you think is that useful? i 
am a beginner and i would really like to learn, but i need a step by step 
website or books, any recommendations?

thanks!



Inizio messaggio inoltrato:

 Da: Ned Deily n...@acm.org
 Oggetto: Re: [Python-Help] idle doesn't work
 Data: 12 marzo 2013 17:52:12 CET
 A: python-list@python.org
 
 In article 513f5080.6030...@libero.it,
 leonardo tampucciol...@libero.it wrote:
 first of all thanks for trying to help me. the text of my email was the 
 following:
 i have a mac os x 10.8, i had already python 2.7, i downloaded python 
 3.3 and active tcl 8.5, but idle and the new version don't work, the 
 answer is:idle's subprocess didn't make connection or personal firewall 
 is blocking. do you know what can i do ?
 or can i use other easy editors to program in python?
 
 i am frustated cause i can use only the old python 2.7 in the terminal 
 window. python 3.3 has not taken place and idle gives the above 
 mentioned error..
 
 Try typing the following in a terminal window:
 
 idle3.3
 
 or, possibly
 
 /usr/local/bin/idle3.3
 
 and see if there is a more useful error message.
 
 If that doesn't work, try adding -n:
 
 idle3.3 -n
 
 -- 
 Ned Deily,
 n...@acm.org
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list

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


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread llanitedave
On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote:
 On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote:
 
  I want to create a random float array of size 100, with the values in the 
  array ranging from 0 to 5. I have tried random.sample(range(5),100) but 
  that does not work. How can i get what i want to achieve?
 
 
 
 Use numpy
 
 
 
 import numpy as np
 
 np.random.uniform(0, 5, 100)
 
 
 
 # note that the values are from the interval [0, 5)
 
 
 
 Maarten

While numpy would work, I fail to see how encouraging the op to download and 
install a separate library and learn a whole new set of tools would be 
beneficial by default, without knowing the purpose of the need.  This is like 
recommending an RPG to fix a sticky door hinge.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread Dave Angel

On 03/12/2013 01:11 PM, Norah Jones wrote:

I want to create a random float array of size 100, with the values in the array 
ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not 
work. How can i get what i want to achieve?




None of the responses so far actually give you what you asked for, as 
they assume you didn't mean 'array' but meant 'list.'  I suspect they're 
right, but here's an approach for array.array.


If you really want a multiprocess.Array, or numpy's array, please say 
so, and somebody'll tell you how to put random numbers in one of them.




import array
import random

floats = (random.random() * 5 for _ in xrange(100))
data = array.array('d', floats)

print data
print type(data)



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


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread Oscar Benjamin
On 12 March 2013 20:21, llanitedave llanited...@veawb.coop wrote:
 On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote:
 On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote:

  I want to create a random float array of size 100, with the values in the 
  array ranging from 0 to 5. I have tried random.sample(range(5),100) but 
  that does not work. How can i get what i want to achieve?

 Use numpy
[SNIP]

 While numpy would work, I fail to see how encouraging the op to download and 
 install a separate library and learn a whole new set of tools would be 
 beneficial by default, without knowing the purpose of the need.  This is like 
 recommending an RPG to fix a sticky door hinge.

This suggestion comes after others that show how to use the stdlib's
random module. I don't think it's unreasonable to recommend numpy for
this. If you want to create *arrays* of random numbers then why not
use a library that provides an API specifically for that? You can test
yourself to see that numpy is 10x faster for large arrays:

Python 2.7 on Linux:
$ python -m timeit -s 'import random' -- '[random.uniform(0, 5) for x
in range(1000)]'
1000 loops, best of 3: 729 usec per loop
$ python -m timeit -s 'import random' -- '[random.random() * 5 for x
in range(1000)]'
1000 loops, best of 3: 296 usec per loop
$ python -m timeit -s 'import numpy' -- 'numpy.random.uniform(0, 5, 1000)'
1 loops, best of 3: 32.2 usec per loop

I would use numpy for this mainly because if I'm creating arrays of
random numbers I probably want to use them in ways that are easier
with numpy arrays. There's also a chance the OP might benefit more
generally from using numpy depending on what they're working on.


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


Re: del not working for (exhausted) dict iterable value (Python 3.3)

2013-03-12 Thread Nick Mellor
Thanks Alex!

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


Re: Pygame mouse cursor load/unload

2013-03-12 Thread Alex Gardner
On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote:
 I am in the process of making a pong game in python using the pygame library. 
  My current problem is that when I move the mouse, it turns off as soon as 
 the mouse stops moving.  The way I am doing this is by making the default 
 cursor invisible and using .png files as replacements for the cursor.  
 Perhaps my code would best explain my problem.  I will take help in any way 
 that I can.  Here are the links that contain my code:
 
 
 
 Main class:  http://pastebin.com/HSQzX6h2
 
 Main file (where the problem lies):  http://pastebin.com/67p97RsJ
 
 
 
 If the links yield nothing, please let me know (agardner...@gmail.com)

Sorry but im back to square one.  My paddle isn't showing up at all! 
http://pastebin.com/PB5L8Th0
-- 
http://mail.python.org/mailman/listinfo/python-list


A string and an integer to appear in tuple (python 2.7)

2013-03-12 Thread Jiewei Huang
Hi all,

I'm currently stuck at this question on 

Writing a function len_str that takes a string as an argument and returns a 
pair consisting of the length of the string and the string itself. 

Example: len_str('Meaning of life') should return the tuple (15, 'Meaning of 
life').


I can only think of this :

len_str = ('welcome to life' )

print (len(len_str,), len_str)


However that not an correct answer I need to make a def len_str but I can't 
seen to get it right.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A string and an integer to appear in tuple (python 2.7)

2013-03-12 Thread Oscar Benjamin
On 13 March 2013 00:21, Jiewei Huang jiewe...@gmail.com wrote:
 Hi all,

 I'm currently stuck at this question on

 Writing a function len_str that takes a string as an argument and returns a 
 pair consisting of the length of the string and the string itself.

 Example: len_str('Meaning of life') should return the tuple (15, 'Meaning of 
 life').


 I can only think of this :

 len_str = ('welcome to life' )

 print (len(len_str,), len_str)


 However that not an correct answer I need to make a def len_str but I can't 
 seen to get it right.

Perhaps an example will help. Let's say we have a variable called x
that we initialise with

x = 2

Here's a line of code that prints 2*x:

print(2 * x)

This will print out 4 but that's not what you want. Here's a function
that prints its argument multiplied by 2:

def double(y):
print(2 * y)

Now we have a function and we can call it with

double(x)

so that it prints 4. Again, though, you didn't want to print it. You
wanted to *return* the value. So here's a function that *returns* 2
times its argument:

def double(x):
return 2 * x

Now if we do

z = double(x)

z will have the value 4. You can check this with

print(z)

Try the code above and see if you can apply the same principles to your problem.


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


Re: A string and an integer to appear in tuple (python 2.7)

2013-03-12 Thread Vlastimil Brom
2013/3/13 Jiewei Huang jiewe...@gmail.com:
 Hi all,

 I'm currently stuck at this question on

 Writing a function len_str that takes a string as an argument and returns a 
 pair consisting of the length of the string and the string itself.

 Example: len_str('Meaning of life') should return the tuple (15, 'Meaning of 
 life').


 I can only think of this :

 len_str = ('welcome to life' )

 print (len(len_str,), len_str)


 However that not an correct answer I need to make a def len_str but I can't 
 seen to get it right.
 --
 http://mail.python.org/mailman/listinfo/python-list


Hi,
unless you are required to code the length-counting by hand as a part
of the exercise, you would simply use the built-in function for that,
i.e.
http://docs.python.org/3.3/library/functions.html#len

Tuples are created using the coma delimiter; optionally with enclosing parens.
http://docs.python.org/3.3/library/stdtypes.html#tuples

 input_string = Meaning of life
 input_string
'Meaning of life'
 len(input_string)
15
 (len(input_string), input_string)
(15, 'Meaning of life')


Now you have to put the needed code to the function body; see
http://docs.python.org/3.3/tutorial/controlflow.html#defining-functions

(Be sure not to forget the return statement containing the result of
your function.)

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


Re: Finding the Min for positive and negative in python 3.3 list

2013-03-12 Thread Steven D'Aprano
On Tue, 12 Mar 2013 17:03:08 +, Norah Jones wrote:

 For example:
 a=[-15,-30,-10,1,3,5]
 
 I want to find a negative and a positive minimum.
 
 example: negative
 print(min(a)) = -30
  
 positive
 print(min(a)) = 1

Thank you for providing examples, but they don't really cover all the 
possibilities. For example, if you had:

a = [-1, -2, -3, 100, 200, 300]

I can see that you consider -3 to be the negative minimum. Do you 
consider the positive minimum to be 100, or 1?

If you expect it to be 100, then the solution is:

min([item for item in a if item  0])

If you expect it to be 1, then the solution is:

min([abs(item) for item in a])

which could also be written as:

min(map(abs, a))

A third alternative is in Python 3.3:

min(a, key=abs)

which will return -1.



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


Re: del not working for (exhausted) dict iterable value (Python 3.3)

2013-03-12 Thread Thomas Rachel

Am 12.03.2013 06:52 schrieb alex23:


You're effectively doing this:


event = dict(Items=[1,2,3])
for e in event['Items']:

... del event['Items']
...
Traceback (most recent call last):
   File stdin, line 2, in module
KeyError: 'Items'

You want to move your del statement up an indentation level so it
happens after the iterator is actually exhausted, and not after the
first iteration.


Just to be clear: Exhausting the iterator is not the problem, as I 
thought as well at the first glance.


The problem is the fact that the loop body tuns multiple times - and so 
does the del statement. A


event = dict(Items=[1,2,3])
for e in event['Items']:
if 'Items' in event: del event['Items']

runs perfectly, as the iterable is transformed to an iterator at the 
very start of the loop.



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


Re: How can i create a random array of floats from 0 to 5 in python

2013-03-12 Thread llanitedave
On Tuesday, March 12, 2013 2:59:29 PM UTC-7, Oscar Benjamin wrote:
 On 12 March 2013 20:21, llanitedave llanited...@veawb.coop wrote:
 
  On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote:
 
  On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote:
 
 
 
   I want to create a random float array of size 100, with the values in 
   the array ranging from 0 to 5. I have tried random.sample(range(5),100) 
   but that does not work. How can i get what i want to achieve?
 
 
 
  Use numpy
 
 [SNIP]
 
 
 
  While numpy would work, I fail to see how encouraging the op to download 
  and install a separate library and learn a whole new set of tools would be 
  beneficial by default, without knowing the purpose of the need.  This is 
  like recommending an RPG to fix a sticky door hinge.
 
 
 
 This suggestion comes after others that show how to use the stdlib's
 
 random module. I don't think it's unreasonable to recommend numpy for
 
 this. If you want to create *arrays* of random numbers then why not
 
 use a library that provides an API specifically for that? You can test
 
 yourself to see that numpy is 10x faster for large arrays:
 
 
 
 Python 2.7 on Linux:
 
 $ python -m timeit -s 'import random' -- '[random.uniform(0, 5) for x
 
 in range(1000)]'
 
 1000 loops, best of 3: 729 usec per loop
 
 $ python -m timeit -s 'import random' -- '[random.random() * 5 for x
 
 in range(1000)]'
 
 1000 loops, best of 3: 296 usec per loop
 
 $ python -m timeit -s 'import numpy' -- 'numpy.random.uniform(0, 5, 1000)'
 
 1 loops, best of 3: 32.2 usec per loop
 
 
 
 I would use numpy for this mainly because if I'm creating arrays of
 
 random numbers I probably want to use them in ways that are easier
 
 with numpy arrays. There's also a chance the OP might benefit more
 
 generally from using numpy depending on what they're working on.
 
 
 
 
 
 Oscar

I don't think numpy is unreasonable for you or me.  I just started learning it 
recently, and I'm pretty jazzed about its possibilities.  I obtained an app for 
work that uses it, and now it's up to me to maintain it, so learning it is a 
good idea for me regardless.  Now I'm starting to fantasize about other things 
I could do with it.

But the OP appears like a pretty basic beginner, and I really think that for 
such a entry-level knowledge scale, we should stick to the standard library 
until they're ready to take on more sophisticated tasks.  Premature 
Optimization is the analogy that comes to mind.
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue17047] Fix double double words words

2013-03-12 Thread Ezio Melotti

Ezio Melotti added the comment:

The files in Modules/_ctypes/libffi/* shouldn't have been changed, but it 
probably doesn't matter much.  You also got the wrong issue id in Misc/NEWS 
(c162e2ff15bd).

--

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



[issue14707] extend() puzzled me.

2013-03-12 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
Removed message: http://bugs.python.org/msg184008

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



[issue17047] Fix double double words words

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I should have made separate new in 3.3 and new in 3.4 patches to begin with. 
This suggests that we need to recheck with each version. Serhiy and Mathew, 
could you post your search re's or scripts to use again on occasion?

I unlinked the 2.7 news notice, rev82624, misdirected to 14707
 Documentation
 -
 
+- Issue #14707: remove doubled words in docs and docstrings
+  reported by Serhiy Storchaka and Matthew Barnett.
+
 - Issue #16406: combine the pages for uploading and registering to PyPI.
 
 - Issue #16403: Document how distutils uses the maintainer field in

I am unable to properly add the 2 line NEWS note to 3.2 (or 3.3) as explained 
in a response on the python-checkins list. The whole file is deleted and added 
back with three extra lines (I presume they are added), or even with just one 
blank line added, in a monster 319kb patch. If someone wants to add a corrected 
version of the above for 3.2,3,4 on *nix, please go ahead.

Ezio, I do not understand your comment. The only change that looks even 
possibly wrong is 'that that' to 'that', and I am pretty sure I checked the 
context.

--
assignee: terry.reedy - docs@python

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

running kill-python results in
Warning -- threading._dangling was modified by test_multiprocessing
Warning -- multiprocessing.process._dangling was modified by 
test_multiprocessing
test test_multiprocessing failed -- multiple errors occurred; run in verbose 
mode for details

-v added the attached details, and the test finished, though failed.

--
Added file: http://bugs.python.org/file29385/test_multi.txt

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



[issue17047] Fix double double words words

2013-03-12 Thread Ezio Melotti

Ezio Melotti added the comment:

AFAIK libffi is maintained externally, so as soon as it gets updated your 
changes will simply get lost (see #17192).  I replied on your python-checkins 
email.  If you still have problems I can add the NEWS entry on 3.x.

--

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



[issue17402] In mmap doc examples map() is shadowed

2013-03-12 Thread py.user

New submission from py.user:

http://docs.python.org/3/library/mmap.html

examples use map as a name for the mmap object

--
assignee: docs@python
components: Documentation
messages: 184015
nosy: docs@python, py.user
priority: normal
severity: normal
status: open
title: In mmap doc examples map() is shadowed
type: performance
versions: Python 3.3

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



[issue17402] In mmap doc examples map() is shadowed

2013-03-12 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
keywords: +easy
nosy: +ezio.melotti
stage:  - needs patch
type: performance - enhancement
versions: +Python 2.7, Python 3.2, Python 3.4

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



[issue17381] IGNORECASE breaks unicode literal range matching

2013-03-12 Thread Ezio Melotti

Ezio Melotti added the comment:

Is this the same issue described in #12728?

--

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



[issue17403] Robotparser fails to parse some robots.txt

2013-03-12 Thread Ben Mezger

New submission from Ben Mezger:

I am trying to parse Google's robots.txt (http://google.com/robots.txt) and it 
fails when checking whether I can crawl the url /catalogs/p? (which it's 
allowed) but it's returning false, according to my question on stackoverflow - 
http://stackoverflow.com/questions/15344253/robotparser-doesnt-seem-to-parse-correctly

Someone has answered it has to do with the line 
rllib.quote(urlparse.urlparse(urllib.unquote(url))[2]) in robotparser's 
module, since it removes the ? from the end of the url. 

Here is the answer I received - http://stackoverflow.com/a/15350039/1649067

--
components: Library (Lib)
messages: 184017
nosy: benmezger
priority: normal
severity: normal
status: open
title: Robotparser fails to parse some robots.txt
type: behavior
versions: Python 2.7

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



[issue17397] ttk::themes missing from ttk.py

2013-03-12 Thread klappnase

Changes by klappnase klappn...@web.de:


--
title: ttk::themes missing form ttk.py - ttk::themes missing from ttk.py

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Richard Oudkerk

Richard Oudkerk added the comment:

Does this happen every time you run the tests?  (I don't see these errors.)

--

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



[issue17400] ipaddress.is_private needs to take into account of rfc6598

2013-03-12 Thread Christian Heimes

Christian Heimes added the comment:

According to Wikipedia [1] even more address ranges are reserved and 
non-routable. But only three address ranges are marked as private. So 
100.64.0.0/10 is reserved and non-routable but not considered a private address 
range.

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

--
nosy: +christian.heimes

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



[issue17402] In mmap doc examples map() is shadowed

2013-03-12 Thread Aman Shah

Aman Shah added the comment:

Corrected map - mymap.

--
keywords: +patch
nosy: +Aman.Shah
Added file: http://bugs.python.org/file29386/issue17402.patch

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



[issue1669349] make install fails if no previous Python installation

2013-03-12 Thread Myroslav Opyr

Myroslav Opyr added the comment:

I've got the issue with Python 2.4.6 and solved the issue with changing 
sequence of altinstall steps (moved sharedinstall before libinstall). See 
attached 
Makefile-2.4.6-unicodedata-zipfile-libinstall-altinstall-sequence.patch.

--
nosy: +Myroslav.Opyr
Added file: 
http://bugs.python.org/file29387/Makefile-2.4.6-unicodedata-zipfile-libinstall-altinstall-sequence.patch

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



[issue11367] xml.etree.ElementTree.find(all): docs are wrong

2013-03-12 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 958217164846 by Eli Bendersky in branch '3.2':
Issue #11367: fix documentation of some find* methods in ElementTree
http://hg.python.org/cpython/rev/958217164846

New changeset 4012d4b41b2b by Eli Bendersky in branch '3.3':
Issue #11367: fix documentation of some find* methods in ElementTree
http://hg.python.org/cpython/rev/4012d4b41b2b

New changeset 7ae2c90f1ba2 by Eli Bendersky in branch 'default':
Issue #11367: fix documentation of some find* methods in ElementTree
http://hg.python.org/cpython/rev/7ae2c90f1ba2

--
nosy: +python-dev

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



[issue11367] xml.etree.ElementTree.find(all): docs are wrong

2013-03-12 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 8e6db2462a77 by Eli Bendersky in branch '2.7':
Issue #11367: fix documentation of some find* methods in ElementTree
http://hg.python.org/cpython/rev/8e6db2462a77

--

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



[issue11367] xml.etree.ElementTree.find(all): docs are wrong

2013-03-12 Thread Eli Bendersky

Eli Bendersky added the comment:

Thanks for the patches - committed with slight adaptations (in default branch 
the internal documentation switched from comments to docstrings).

--
resolution:  - fixed
stage: needs patch - committed/rejected
status: open - closed

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



[issue17404] ValueError: can't have unbuffered text I/O for io.open(1, 'wt', 0)

2013-03-12 Thread Robert Collins

New submission from Robert Collins:

The io library rejects unbuffered text I/O, but this is not documented - and in 
fact can be manually worked around:
binstdout = io.open(sys.stdout.fileno(), 'wt', 0)
sys.stdout = io.TextIOWrapper(binstdout, encoding=sys.stdout.encoding)
will get a sys.stdout that is unbuffered.

Note that writing to a pipe doesn't really need to care about buffering anyway, 
if the user writes 300 characters, the codec will output a single block and the 
IO made will be one write:

This test script:
import sys
import io
stream = io.TextIOWrapper(io.open(sys.stdout.fileno(), 'wb', 0), 
encoding='utf8')
for r in range(10):
  stream.write(u'\u1234'*500)

When run under strace -c does exactly 10 writes: so the performance is 
predictable. IMO it doesn't make sense to prohibit unbuffered text write I/O. 
readers may be another matter, but that doesn't suffer the same latency issues.

--
messages: 184025
nosy: rbcollins
priority: normal
severity: normal
status: open
title: ValueError: can't have unbuffered text I/O for io.open(1, 'wt', 0)
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 
3.4, Python 3.5

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



[issue17047] Fix double double words words

2013-03-12 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 Serhiy and Mathew, could you post your search re's or scripts to use again on 
 occasion?

For example:

  find * -type f -name '*.[ch]' -exec egrep -n '\b([a-zA-Z]+) \1\b' '{}' + | 
grep -v 'long long' | egrep --color '\b([a-zA-Z]+) \1\b'
  find * -type f -name '*.py' -exec egrep -n --color '\b([a-zA-Z]+) \1\b' '{}' +

And similar one-time one-liners for *.rst, *.txt, etc.

--

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



[issue17368] Python version of JSON decoder does not work with object_pairs_hook

2013-03-12 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

LGTM. Perhaps with object_pairs_hook=tuple or object_pairs_hook=dict this test 
will look simpler.

--

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



[issue17397] ttk::themes missing from ttk.py

2013-03-12 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Can you provide some tests for the new method?

--
nosy: +gpolo, serhiy.storchaka
stage:  - test needed
versions: +Python 3.4

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



[issue17404] ValueError: can't have unbuffered text I/O for io.open(1, 'wt', 0)

2013-03-12 Thread Serhiy Storchaka

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


--
components: +IO
nosy: +benjamin.peterson, hynek, pitrou, stutzbach
versions:  -Python 2.6, Python 3.1, Python 3.5

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



[issue17047] Fix double double words words

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I emailed the libffi subpatch to libffi-discuss.
Please add the 3.x news entry if you can get to it before I am able.
Then this issue can be closed, though the problem will obviously recur without 
an automatic check.

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

All 4 or 5 times I tried on 3.2, yes.

--

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



[issue17400] ipaddress.is_private needs to take into account of rfc6598

2013-03-12 Thread pmoody

pmoody added the comment:

I don't see anyway to actually assign this bug to myself, but I'll get a patch 
for this.

--
nosy: +pmoody

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



[issue17405] Add _Py_memset_s() to securely clear memory

2013-03-12 Thread Christian Heimes

New submission from Christian Heimes:

Compilers like GCC optimize away code like memset(var, 0, sizeof(var)) if the 
code occurs at the end of a function and var is not used anymore [1]. But 
security relevant code like hash and encryption use this to overwrite sensitive 
data with zeros.

The code in _sha3module.c uses memset() to clear its internal state. The other 
hash modules don't clear their internal states yet.


There exists a couple of solutions for the problem:

 * C11 [ISO/IEC 9899:2011] has a memset_s() function
 * MSVC has SecureZeroMemory()
 * GCC can disable the optimization with #pragma GCC optimize (O0) since GCC 
4.4
 * [2] contains an example for a custom implementation of memset_s() with 
volatile.

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8537

[2] 
https://www.securecoding.cert.org/confluence/display/seccode/MSC06-C.+Be+aware+of+compiler+optimization+when+dealing+with+sensitive+data

--
assignee: christian.heimes
messages: 184032
nosy: christian.heimes
priority: normal
severity: normal
stage: needs patch
status: open
title: Add _Py_memset_s() to securely clear memory
type: security
versions: Python 3.4

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



[issue17405] Add _Py_memset_s() to securely clear memory

2013-03-12 Thread Benjamin Peterson

Benjamin Peterson added the comment:

Even if you get the memset to actually run, that's hardly sufficient for 
security. The OS can could have swapped it to disk.

--
nosy: +benjamin.peterson

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



[issue17405] Add _Py_memset_s() to securely clear memory

2013-03-12 Thread Christian Heimes

Christian Heimes added the comment:

mlock() can prevent swapping but it may need extra capabilities. A working 
memset_s() removes critical information from core dumps at least.

If we don't want to add _Py_memset_s() then I'm going to remove the 
dysfunctional clearstate macro from my sha3 module.

--
nosy: +gregory.p.smith

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Richard Oudkerk

Richard Oudkerk added the comment:

Could you try the following program:

import socket
import multiprocessing
import multiprocessing.reduction
import multiprocessing.connection

def socketpair():
with socket.socket() as l:
l.bind(('localhost', 0))
l.listen(1)
s = socket.socket()
s.connect(l.getsockname())
a, _ = l.accept()
return s, a

def bar(s):
print(s)
s.sendall(b'from bar')

if __name__ == '__main__':
a, b = socketpair()
p = multiprocessing.Process(target=bar, args=(b,))
p.start()
b.close()
print(a.recv(100))

--

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



[issue17405] Add _Py_memset_s() to securely clear memory

2013-03-12 Thread Benjamin Peterson

Benjamin Peterson added the comment:

I'm not saying don't add it, just that you can't really win in the securely 
deleting data game unless you have special hardware.

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

In Command Prompt, 3.2 gave same error as before, 3.3 a different error.
multi-test.txt has full tracebacks.

--
Added file: http://bugs.python.org/file29388/mult-test.txt

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



[issue17400] ipaddress.is_private needs to take into account of rfc6598

2013-03-12 Thread Santoso Wijaya

Changes by Santoso Wijaya santoso.wij...@gmail.com:


--
nosy: +santa4nt

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



[issue17402] In mmap doc examples map() is shadowed

2013-03-12 Thread py.user

py.user added the comment:

how about mm ?

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Richard Oudkerk

Richard Oudkerk added the comment:

Now could you try the attached file?  (It will not work on 2.7 because a 
missing socket.fromfd().)

P.S. It looks like the error for 3.3 is associated with a file 
f:\python\mypy\traceback.py which presumably clashes with the one in the 
standard library.

--
Added file: http://bugs.python.org/file29389/inherit_socket.py

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



[issue17402] In mmap doc examples map() is shadowed

2013-03-12 Thread py.user

Changes by py.user bugzilla-mail-...@yandex.ru:


Added file: http://bugs.python.org/file29390/mm.patch

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



[issue17404] ValueError: can't have unbuffered text I/O for io.open(1, 'wt', 0)

2013-03-12 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

The proposed workaround seems to work (wb instead of wt!), with the 
following restrictions:

- it's not really unbuffered: the encoder has its own buffers (OK, in the 
stdlib only 'idna' encoding will retain data)

- it won't work for reading: TextIOWrapper calls the read1() method, which is 
only defined by BufferedIO objects.

IMO this explains why it's not a supported combination in io.open().

--
nosy: +amaury.forgeotdarc

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



[issue17404] ValueError: can't have unbuffered text I/O for io.open(1, 'wt', 0)

2013-03-12 Thread Robert Collins

Robert Collins added the comment:

Huh, I didn't realise idna would retain data! But that will still be within the 
TextIOWrapper itself, right?

And a stream opened 'wt' cannot be read from anyway, so the read1 limitation is 
irrelevant.

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

According to difflib, the attached file is identical with the code in your 
previous message. With my traceback renamed, both files print b'from bar' with 
3.3 and the same error message as before with 3.2.

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Let me try downloading again.

--

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



[issue17405] Add _Py_memset_s() to securely clear memory

2013-03-12 Thread Gregory P. Smith

Gregory P. Smith added the comment:

I'd personally say don't bother with this.  Let people who _need_ this use 
their own C extension modules to handle all secure data as we're not in a 
position to make and test any guarantees about what happens to data anywhere 
within a Python VM.

If this is added, at least document it (comments since its an _internal 
function) as being best effort with no guarantee that it is better than nothing.

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Both 3.2 and 3.3 give essentially the same traceback as 3.2 did before, both 
with installed python and yesterdays debug builds.

--
Added file: http://bugs.python.org/file29391/multi-test2.txt

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



[issue17404] ValueError: can't have unbuffered text I/O for io.open(1, 'wt', 0)

2013-03-12 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

 But that will still be within the TextIOWrapper itself, right?

Yes. And I just noticed that the _io module (the C version) will also buffer 
encoded bytes, up to f._CHUNK_SIZE.

On the other hand, TextIOWrapper is broken for buffering codecs, encode() is 
never called with final=True

 import io
 buffer = io.BytesIO()  # -- not really buffered, right?
 output = io.TextIOWrapper(buffer, encoding='idna')
 output.write(www.somesite.com)
16
 print(buffer.getvalue())
b''# -- ok, _CHUNK_SIZE buffering
 output.flush()
 print(buffer.getvalue())
b'www.somesite.'   # -- the last word is missing!
 output.close()
 print(buffer.getvalue())
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: I/O operation on closed file.


And it's even worse with python 2.7::

 import io as io
 buffer = io.BytesIO()
 output = io.TextIOWrapper(buffer, encoding='idna')
 output.write(www.somesite.com)
Traceback (most recent call last):
  File stdin, line 3, in module
TypeError: must be unicode, not str

--

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



[issue17232] Improve -O docs

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I added :const: and tweaked -OO entry and -h startup display.
Tested new html and python_d -h. Any other comments before I apply?

--
assignee: docs@python - terry.reedy
Added file: http://bugs.python.org/file29392/17232-O.diff

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



[issue17232] Improve -O docs

2013-03-12 Thread Antoine Pitrou

Antoine Pitrou added the comment:

There's a typo in your patch:

+-O : remove assert and __debug__-dependent statements; change .py\n\
+ to .pyo; also PYTHONOPTIMIZE=x\n\

should say .pyc, not .py.

--

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



[issue17232] Improve -O docs

2013-03-12 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Also, in 3.2 and higher I'm not sure there's a point in mentioning pyc/pyo 
files; they're all shelved in __pycache__ now.

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Richard Oudkerk

Richard Oudkerk added the comment:

 Both 3.2 and 3.3 give essentially the same traceback as 3.2 did before, 
 both with installed python and yesterdays debug builds.

It looks like on your machine socket handles are not correctly inherited by 
child processes -- I had assumed that they always would be.

I suppose to fix things for 3.2 and earlier it would be necessary to backport 
the functionality of socket.socket.share() and socket.fromshare() from 3.3.

--

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



[issue17232] Improve -O docs

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I corrected my copy of the .diff.

Since this issue is so far focused on removing the false optimize claim, hiding 
.pyx info is a new sub-issue. I will follow whatever the consensus is, but 
since this is a cpython-specific doc and help, I would prefer to give complete 
info. In fact, I would like to add 'stored in __pycache__' or even 'hidden away 
in  __pycache__', the latter to suggest that most people should generally 
forget about them. On Windows, _xxx files like __pycache__ appear in both 
Command Prompt dir and Explorer file listings, so beginners need to known that 
__cache__ is both normal and ignorable.

--

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



[issue17400] ipaddress.is_private needs to take into account of rfc6598

2013-03-12 Thread Lei Miao

Lei Miao added the comment:

Thanks Peter.

On 13 March 2013 03:35, pmoody rep...@bugs.python.org wrote:


 pmoody added the comment:

 I don't see anyway to actually assign this bug to myself, but I'll get a
 patch for this.

 --
 nosy: +pmoody

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue17400
 ___


--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
Removed message: http://bugs.python.org/msg184042

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
Removed message: http://bugs.python.org/msg184043

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



[issue14243] tempfile.NamedTemporaryFile not particularly useful on Windows

2013-03-12 Thread Piotr Dobrogost

Piotr Dobrogost added the comment:

@sbt

 (...) and it seems that on Windows open() is more or less implemented
 as a wrapper of sopen(..., ..., SH_DENYNO, ...).

 So the only reason that trying to reopen a NamedTemporaryFile fails on
 Windows is because when we reopen we need to use O_TEMPORARY.

Could you elaborate on this? What's the relation between SH_DENYNO argument to 
sopen() and O_TEMPORARY flag?

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

My original report was for 32 bit debug build on 64 bit Win 7 machine. I just 
re-ran test_multiprocessing with installed 64 bit python with same result. Was 
I don't see these errors. on different Windows or non-Windows.

One option is to skip the failing sub-tests on Windows, like some other 
sub-tests:
skipped 'does not work with windows sockets'
and consider the limitation on use of multi-processing in 2.7,3.2 as won't 
fix. (My view is that 3.2 users should upgrade as soon as dependencies allow.) 
Backporting new features requires pydev discussion.

--

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



[issue17399] test_multiprocessing hang on Windows, non-sockets

2013-03-12 Thread Richard Oudkerk

Richard Oudkerk added the comment:

 My original report was for 32 bit debug build on 64 bit Win 7 machine.
 I just re-ran test_multiprocessing with installed 64 bit python with same 
 result. Was I don't see these errors. on different Windows or non-Windows.

On 64-bit Windows 7 with both 32 and 64 bit builds.

 One option is to skip the failing sub-tests on Windows, like some other 
 sub-tests:
 skipped 'does not work with windows sockets'
 and consider the limitation on use of multi-processing in 2.7,3.2 as won't 
 fix. 
 (My view is that 3.2 users should upgrade as soon as dependencies allow.) 

Yes, I would be inclined to do that.

 Backporting new features requires pydev discussion.

I only meant exposing that functionality in the private _multiprocessing 
extension.

--

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



  1   2   >