[ANN] bzr 2.6.0 released

2013-08-05 Thread Vincent Ladeuil
On behalf of the Bazaar team and community, I'm happy to announce
availability of a new release of the bzr adaptive version control
system.

Bazaar http://bazaar.canonical.com/ is a Canonical project and part of
the GNU project http://gnu.org/ to produce a free operating system.

Thanks to everyone who contributed patches, suggestions, and feedback.

Bazaar is now available for download from
https://launchpad.net/bzr/2.6/2.6.0 as a source tarball.

An Installer is available for OSX from the url above too.

Volunteers are welcome to build a windows one.

This release marks the start of a new long-term-stable series. From here, we
will only make bugfix releases on the 2.6 series (2.6.1, etc), while 2.7
will become our new development series.

This is a bugfix and polish release over the 2.5 series, with a large number
of bugs fixed (~50 for the 2.6 series alone).

All known fixed bugs are included here.

Users are encouraged to upgrade from the other stable series.

See
http://doc.bazaar.canonical.com/bzr.dev/en/release-notes/bzr-2.6.html
for more details,

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

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


Astroid 1.0 released

2013-08-05 Thread Sylvain Thénault
Astroid_ is the new name of former logilab-astng library. It's an AST library,
used as the basis of Pylint_ and including Python 2.5 - 3.3 compatible tree
representation, statical type inference and other features useful for advanced
Python code analysis, such as an API to provide extra information when
statistical inference can't overcome Python dynamic nature (see the
`pylint-brain`_ project for instance).

It has been renamed and hosted to bitbucket to make clear that this is not a
Logilab dedicated project but a community project that could benefit to any
people manipulating Python code (statistical analysis tools, IDE, browser, etc).

Documentation is a bit rough but should quickly improve. Also a dedicated
web-site is now online, visit www.astroid.org (or
https://bitbucket.org/logilab/astroid for development).

You may download and install it from Pypi or from `Logilab's debian
repositories`_.


.. _Pylint: http://www.pylint.org
.. _`Logilab's debian repositories`: http://www.logilab.org/bookmark/4621/follow
.. _Astroid: http://www.astroid.org
.. _`pylint-brain`: https://bitbucket.org/logilab/pylint-brain


Enjoy!
-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
CubicWeb, the semantic web framework:http://www.cubicweb.org
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


[RELEASED] Python 3.4.0a1

2013-08-05 Thread Larry Hastings



On behalf of the Python development team, I'm pleased to announce the
first alpha release of Python 3.4.

This is a preview release, and its use is not recommended for
production settings.

Python 3.4 includes a range of improvements of the 3.x series, including
hundreds of small improvements and bug fixes.  Major new features and
changes in the 3.4 release series so far include:

* PEP 435, a standardized enum module
* PEP 442, improved semantics for object finalization
* PEP 443, adding single-dispatch generic functions to the standard library
* PEP 445, a new C API for implementing custom memory allocators


To download Python 3.4.0a1 visit:

http://www.python.org/download/releases/3.4.0/


Please consider trying Python 3.4.0a1 with your code and reporting any
issues you notice to:

 http://bugs.python.org/


Enjoy!

--
Larry Hastings, Release Manager
larry at hastings.org
(on behalf of the entire python-dev team and 3.4's contributors)
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Hangman question

2013-08-05 Thread Joshua Landau
On 5 August 2013 06:11, eschneide...@comcast.net wrote:

 I'm  on chapter 9 of this guide to python:
 http://inventwithpython.com/chapter9.html but I don't quite
 understand why line 79 is what it is (blanks = blanks[:i] + secretWord[i] +
 blanks[i+1:]). I particularly don't get the [i+1:] part. Any additional
 information and help would be greatly appreciated!


First you should realise that this isn't actually great code by my
standards. There are quite a few un-idiomatic things done, but hopefully
the learning you get outweighs the things you have to unlearn ;).

That said, here's an explanation.

This loop:

for i in range(len(secretWord)): # replace blanks with correctly
guessed letters
if secretWord[i] in correctLetters:
blanks = blanks[:i] + secretWord[i] + blanks[i+1:]

wants to change blanks from a string like  to a string like a_t_.
It has a companion string, secretWord, of the same length (such as acts).

the for i in range(len(secretWord)): loop¹ goes through all the numbers
from 0 to 3 in this case.

if secretWord[i] in correctLetters:³ takes the letter from position 0 to
3, which is each of the letters in the secret word in turn, so a, c,
t and s and checks if that letter is in correctLetters.

If it is, we want to do the transformation like  - a___ and a___
- a_t_.

This brings us to line 79.

blanks = blanks[:i] + secretWord[i] + blanks[i+1:]⁴

Let blanks be a___. When i == 2, secretWord[i] == t which we can
assume is in correctLetters.

blanks[:2] returns a_ because you're slicing the string up to the
second stop. I don't know how slices have been taught but I'd been taught
like so:

[0]a[1]_[2]_[3]_[4]

so slicing from the start (by missing the start index in the slice) to 2
would return the a and _.

secretWord[i] returns t as before.

blanks[i+1:] == blanks[2+1:] == blanks[3:] so return the rest *after
skipping one*, so just _. This means that the additions resolve to:

blanks = a_ + t + _

which results in a_t_.

Does this help?



¹ You should really use for i, letter in enumerate(secretWord²): but I'll
let it pass for simplicity.
² Really, secret_word is better than secretWord, too, but w/e.
 ³ Better written as if letter in guessed_letters: given [1] and a
generalisation of [2].
⁴ This is *really* bad practice. Not only is the string rebuilt every time
the loop happens but it's actually rebuilt in part about *three* times per
loop. In this case it's not a big deal, but don't write things like this.⁵
⁵ You should probably use a mutable list which you .join() OR replace
elements using an iterator (the second of those you can leave for later but
they're not that hard).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hangman question

2013-08-05 Thread Peter Otten
eschneide...@comcast.net wrote:

 I'm  on chapter 9 of this guide to python:
 http://inventwithpython.com/chapter9.html but I don't quite understand
 why line 79 is what it is (blanks = blanks[:i] + secretWord[i] +
 blanks[i+1:]). I particularly don't get the [i+1:] part. Any additional
 information and help would be greatly appreciated!

When you have a list with and want to replace the third item with something 
else you can do it like this:

 items = [r, e, e, d]
 items[2] = a
 items
['r', 'e', 'a', 'd']

With a string that is not possible because strings cannot be modified (they 
are immutable):

 s = reed
 s[2] = a
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'str' object does not support item assignment

You could try replace() to build a new string

 s.replace(e, a)
'raad'

but that replaces all occurrences. So to manually replace th third character 
you take the first two characters of the original

 s[:2]
're'

then the characters after the third

 s[3:]
'd'

and finally build the new string by putting the new character (or string) in 
between:

 s[:2] + a + s[3:]
'read'

A function to replace the n-th character would then look like this:

 def replace_nth_char(s, n, replacement):
... return s[:n] + replacement + s[n+1:]
... 
 replace_nth_char(read, 2, e)
'reed'


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


Re: Hangman question

2013-08-05 Thread Dave Angel
eschneide...@comcast.net wrote:

 I'm  on chapter 9 of this guide to python: 
 http://inventwithpython.com/chapter9.html but I don't quite understand 
 why line 79 is what it is (blanks = blanks[:i] + secretWord[i] + 
 blanks[i+1:]). I particularly don't get the [i+1:] part. Any additional 
 information and help would be greatly appreciated!

(You're using googlegroups, which is painfully buggy.  Just an alert
that some folks won't even see a message from googlegroups, because they
filter it out in protest.

If you join this mailing list with more conventional means, you can
avoid several problems.)

The syntax you're describing is called a slice.  it works on strings,
and on lists, and some other places.  For strings in particular, because
they are immutable, something that ought to be easy becomes a
strange-looking slice expression.  it's worth taking the trouble to
figure out the patterns of those, so you can just recognize them without
too much thought.

And of course, asking here is one good first step for that.

A slice can specify up to 3 numeric values, which could be labeled as
start, end, and step, just like range.  However, they're separated by
colons, rather than commas.

Go to the debugger (by just typing python at the command prompt, without
a script), and play a bit.

abcdefg[:3]  is analogous to  range(3), which is equivalent to
range(0,3).  Those ranges produce a list containing 0, 1 and 2.  So the
string slice produces the characters at those 3 positions.  In other
words, abc  (Remember Python is 99.9% zero-based).

(If on Python 3.x, use  list(range(qqq)) to expand it out and actually
see the elements as a list)

abcdefg[4:]is analogous to range(4, 7) and produces 'efg'

Notice that character 3 is not in either string.  The letter 'd' is
missing.  So this particular pattern:

xxx[:i] + other + xxx[i+1:]

lets you replace the ith character with whatever's in other.  if it's
a single character, the net effect is just replacing the ith character
with a different one.

Does that help?




-- 
DaveA

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


Re: outputting time in microseconds or milliseconds

2013-08-05 Thread Ulrich Eckhardt

Am 02.08.2013 15:17, schrieb matt.doolittl...@gmail.com:

so you are saying that

self.logfile.write('%s\t'%(str(time(

should be:

self.logfile.write('%s\t'%(str(time.time(


No, I'm not saying that. What I wanted to make clear is that your code 
is impossible to understand as it stands, because nobody knows what 
time refers to. My guess was that you had from time import time, 
strftime somewhere in your code so that the time in your code refers 
to the time function from Python's time module.


Uli


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


Re: stupid simple scope issue

2013-08-05 Thread JohnD
On 2013-08-04, Chris Angelico ros...@gmail.com wrote:
 On Sun, Aug 4, 2013 at 8:21 PM, JohnD j...@nowhere.com wrote:
 On 2013-08-04, Chris Angelico ros...@gmail.com wrote:
[...]

 Python does have a slightly odd (compared to other languages)
 interpretation of variable assignments (name bindings, really)
 inside a class block. Trips up a lot of people.

Changed the code: 10% smaller, more elegant, and it seems to work!
If it really works I am close to half-way...
-- 
http://mail.python.org/mailman/listinfo/python-list


__iadd__ for a subclass of array - howto

2013-08-05 Thread Helmut Jarausch
Hi,

I'd like to subclass array.array and implement operators like __iadd__
How can this be accomplished.

I'tried

from array import array

class Vec(array) :
  def __new__(cls,Vinit) :
return array.__new__(cls,'d',Vinit)

  def __init__(self,*args) :
self.N = len(self)

  def __str__(self) :
out=[ {}.format(self.__getitem__(i)) for i in range(0,self.N) ]
return ,.join(out)

  def __iadd__(self,Op) :
#for i,x in enumerate(self) :
#  x+= Op[i] # this doesn't update self
for i in range(0,self.N) :
  (self.__getitem__(i))+= Op[i]  # __getitem__ doesn't return a reference 
(like in C++)
return self


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


Re: __iadd__ for a subclass of array - howto

2013-08-05 Thread Ian Kelly
On Mon, Aug 5, 2013 at 1:34 AM, Helmut Jarausch
jarau...@igpm.rwth-aachen.de wrote:
 Hi,

 I'd like to subclass array.array and implement operators like __iadd__
 How can this be accomplished.

 I'tried

 from array import array

 class Vec(array) :
   def __new__(cls,Vinit) :
 return array.__new__(cls,'d',Vinit)

   def __init__(self,*args) :
 self.N = len(self)

   def __str__(self) :
 out=[ {}.format(self.__getitem__(i)) for i in range(0,self.N) ]
 return ,.join(out)

   def __iadd__(self,Op) :
 #for i,x in enumerate(self) :
 #  x+= Op[i] # this doesn't update self
 for i in range(0,self.N) :
   (self.__getitem__(i))+= Op[i]  # __getitem__ doesn't return a 
 reference (like in C++)
 return self


for i in range(len(self)):
self[i] += Op[i]

There's no reason to be calling __getitem__ directly.  Use the
operators and let Python decide what to call.
-- 
http://mail.python.org/mailman/listinfo/python-list


Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi everybody,
I am trying to understand how to use named pipes in python to launch external 
processes (in a Linux environment).

As an example I am trying to imitate the behaviour of the following sets of 
commands is bash:

 mkfifo named_pipe
 ls -lah  named_pipe 
 cat  named_pipe

In Python I have tried the following commands:

import os
import subprocess as sp

os.mkfifo(named_pipe,0777) #equivalent to mkfifo in bash..
fw = open(named_pipe,'w')
#at this point the system hangs...

My idea it was to use subprocess.Popen and redirect stdout to fw...
next open named_pipe for reading and giving it as input to cat (still using 
Popen).

I know it is a simple (and rather stupid) example, but I can't manage to make 
it work..


How would you implement such simple scenario?

Thanks a lot in advance for the help!!!

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-08-05 Thread Sanjay Arora
On Tue, Jul 23, 2013 at 2:49 PM, Chris Angelico ros...@gmail.com wrote:


 Ah, there's a solution to this one. You simply use your own
 envelope-from address; SPF shouldn't be being checked for the From:
 header. Forwarding and using the original sender's address in the SMTP
 'MAIL FROM' command is forging mail from them, so it is correct for
 that to be thrown out. The mail is coming from your own account, so
 you put your address in it, and you might even be able to put an
 uber-strict SPF record like v=spf1 ip4:1.2.3.4 -all which is quick
 to process and guarantees that nobody can pretend to forward mail on
 your behalf. The checks are for the *current connection*, not anything
 earlier.

 ChrisA


Bit Late, but do check out  http://www.openspf.org/FAQ/Forwarding

Forwarding does get broken, but a partial solution in whitelisting is
there, though too manual  therefore cumbersome.

Another option http://www.openspf.org/SRS is there to be worked in
conjunction with spf. There is a best spf practices guide on the site. And
all this email authentication issue given on openspf.org makes an
interesting read.

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


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Paul Wiseman
On 5 August 2013 14:09, Luca Cerone luca.cer...@gmail.com wrote:

 Hi everybody,
 I am trying to understand how to use named pipes in python to launch
 external processes (in a Linux environment).

 As an example I am trying to imitate the behaviour of the following sets
 of commands is bash:

  mkfifo named_pipe
  ls -lah  named_pipe 
  cat  named_pipe

 In Python I have tried the following commands:

 import os
 import subprocess as sp

 os.mkfifo(named_pipe,0777) #equivalent to mkfifo in bash..
 fw = open(named_pipe,'w')
 #at this point the system hangs...

 My idea it was to use subprocess.Popen and redirect stdout to fw...
 next open named_pipe for reading and giving it as input to cat (still
 using Popen).

 I know it is a simple (and rather stupid) example, but I can't manage to
 make it work..


 How would you implement such simple scenario?

 Thanks a lot in advance for the help!!!


You can pipe using subprocess

p1 = subprocess.Popen([ls, -lah], stdout=subprocess.PIPE)
p2 = subprocess.Popen([cat], stdin=p1.stdout)
p1.wait()
p2.wait()

You can also pass a file object to p1's stdout and p2's stdin if you want
to pipe via a file.

with open(named_pipe, rw) as named_pipe:
p1 = subprocess.Popen([ls, -lah], stdout=named_pipe)
p2 = subprocess.Popen([cat], stdin=named_pipe)
p1.wait()
p2.wait()


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

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


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi Paul, first of all thanks for the help.

I am aware of the first solutions, just now I would like to experiment a bit 
with  using named pipes (I also know that the example is trivial, but it just 
to grasp the main concepts)

 
 You can also pass a file object to p1's stdout and p2's stdin if you want to 
 pipe via a file.
 
 
 with open(named_pipe, rw) as named_pipe:
     p1 = subprocess.Popen([ls, -lah], stdout=named_pipe)
     p2 = subprocess.Popen([cat], stdin=named_pipe)
 
     p1.wait()
     p2.wait()
  

Your second example doesn't work for me.. if named_file is not a file in the 
folder I get an error saying that there is not such a file.

If I create named_pipe as a named pipe using os.mkfifo(named_file,0777) than 
the code hangs.. I think it is because there is not process that reads the
content of the pipe, so the system waits for the pipe to be emptied.

Thanks a lot in advance for the help in any case.
Luca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB

On 05/08/2013 14:09, Luca Cerone wrote:

Hi everybody,
I am trying to understand how to use named pipes in python to launch external 
processes (in a Linux environment).

As an example I am trying to imitate the behaviour of the following sets of 
commands is bash:


mkfifo named_pipe
ls -lah  named_pipe 
cat  named_pipe


In Python I have tried the following commands:

import os
import subprocess as sp

os.mkfifo(named_pipe,0777) #equivalent to mkfifo in bash..
fw = open(named_pipe,'w')
#at this point the system hangs...

My idea it was to use subprocess.Popen and redirect stdout to fw...
next open named_pipe for reading and giving it as input to cat (still using 
Popen).

I know it is a simple (and rather stupid) example, but I can't manage to make 
it work..


How would you implement such simple scenario?

Thanks a lot in advance for the help!!!


Opening the pipe for reading will block until it's also opened for
writing, and vice versa.

In your bash code, 'ls' blocked until you ran 'cat', but because you
ran 'ls' in the background you didn't notice it!

In your Python code, the Python thread blocked on opening the pipe for
writing. It was waiting for another thread or process to open the pipe
for reading.

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


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi MRAB, thanks for the reply!
 
 Opening the pipe for reading will block until it's also opened for
 
 writing, and vice versa.
 

OK.

 
 
 In your bash code, 'ls' blocked until you ran 'cat', but because you
 
 ran 'ls' in the background you didn't notice it!
 
 
Right.
 
 In your Python code, the Python thread blocked on opening the pipe for
 
 writing. It was waiting for another thread or process to open the pipe
 
 for reading.

OK. What you have written makes sense to me. So how do I overcome the block?
As you said in bash I run the ls process in background. How do I do that in 
Python?

Thanks again for the help,
Luca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Miki Tebeka
 Is it possible with argparse to have this syntax for a script?
 my-script (-a -b VALUE-B | -c -d VALUE-D)
 
 I would like to do this with the argparse module.
You can probably do something similar using sub commands 
(http://docs.python.org/2/library/argparse.html#sub-commands).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Alister
On Mon, 05 Aug 2013 06:09:53 -0700, Luca Cerone wrote:

 Hi everybody,
 I am trying to understand how to use named pipes in python to launch
 external processes (in a Linux environment).
 
 As an example I am trying to imitate the behaviour of the following
 sets of commands is bash:
 
 mkfifo named_pipe ls -lah  named_pipe 
 cat  named_pipe
 
 In Python I have tried the following commands:
 
 import os import subprocess as sp
 
 os.mkfifo(named_pipe,0777) #equivalent to mkfifo in bash..
 fw = open(named_pipe,'w')
 #at this point the system hangs...
 
 My idea it was to use subprocess.Popen and redirect stdout to fw...
 next open named_pipe for reading and giving it as input to cat (still
 using Popen).
 
 I know it is a simple (and rather stupid) example, but I can't manage to
 make it work..
 
 
 How would you implement such simple scenario?
 
 Thanks a lot in advance for the help!!!
 
 Luca

Are you sure you are using the correct tool for the task?

I tend to find that in most cases if you are trying to execute bash 
commands from Python you are doing it wrong.

certainly if you are trying to pipe one bash command into another you 
would probably be better of with a bash script.




-- 
When I was crossing the border into Canada, they asked if
I had any firearms with me.  I said, Well, what do you need?
-- Steven Wright
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB

On 05/08/2013 15:11, Luca Cerone wrote:

Hi MRAB, thanks for the reply!


Opening the pipe for reading will block until it's also opened for
writing, and vice versa.



OK.



In your bash code, 'ls' blocked until you ran 'cat', but because you
ran 'ls' in the background you didn't notice it!



Right.


In your Python code, the Python thread blocked on opening the pipe for
writing. It was waiting for another thread or process to open the pipe
for reading.


OK. What you have written makes sense to me. So how do I overcome the block?
As you said in bash I run the ls process in background. How do I do that in 
Python?


You need to ensure that the pipe is already open at the other end.

Why are you using a named pipe anyway?

If you're talking to another program, then that needs to be running
already, waiting for the connection, at the point that you open the
named pipe from this end.

If you're using a pipe _within_ a program (a queue would be better),
then you should opening for writing in one thread and for reading in
another.

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


Re: Bug? ( () == [] ) != ( ().__eq__([]) )

2013-08-05 Thread Markus Rother

Thanks for the good explanation.

My intention was to pass a custom method/function as a comparator
to an object.  My misconception was, that __eq__ is equivalent to
the '==' operator, and could be passed as a first class function.
Apparently, that is not possible without wrapping the comparison
into another function/method.

Best regards,
Markus R.

On 05.08.2013 01:06, Chris Angelico wrote:

On Sun, Aug 4, 2013 at 11:35 PM, Markus Rother pyt...@markusrother.de wrote:

Hello,

The following behaviour seen in 3.2 seems very strange to me:

As expected:

() == []

False

However:

().__eq__([])

NotImplemented

[].__eq__(())

NotImplemented


You don't normally want to be calling dunder methods directly. The
reasoning behind this behaviour goes back to a few things, including a
way to handle 1 == Foo() where Foo is a custom type that implements
__eq__; obviously the integer 1 won't know whether it's equal to a Foo
instance or not, so it has to defer to the second operand to get a
result. This deferral is done by returning NotImplemented, which is an
object, and so is true by default. I don't see any particular reason
for it to be false, as you shouldn't normally be using it; it's more
like a null state, it means I don't know if we're equal or not. If
neither side knows whether they're equal, then they're presumed to be
unequal, but you can't determine that from a single call to __eq__.

ChrisA



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


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Hi Alister,
 Are you sure you are using the correct tool for the task?

Yes. For two reasons: 1. I want to learn how to do this in Python :) 2. for an 
application I have in mind I will need to run external tools (not developed by 
me) and process the output using some tools that I have written in Python.

For technical reasons I can't use the subprocess.communicate() (the output to 
process is very large) method, and due to a bug in the interactive shell I am 
using (https://github.com/ipython/ipython/issues/3884) I cannot pipe processes 
just using the standard subprocess.Popen() approach.

 
 I tend to find that in most cases if you are trying to execute bash 
 
 commands from Python you are doing it wrong.

As I said, the example in my question is just for learning purposes, I don't 
want to reproduce ls and cat in Python...

I just would like to learn how to handle named pipes in Python, which I find it 
easier to do by using a simple example that I am comfortable to use :)

Thanks in any case for your answer,
Luca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bug? ( () == [] ) != ( ().__eq__([]) )

2013-08-05 Thread Ian Kelly
On Mon, Aug 5, 2013 at 8:58 AM, Markus Rother markus.rot...@web.de wrote:
 Thanks for the good explanation.

 My intention was to pass a custom method/function as a comparator
 to an object.  My misconception was, that __eq__ is equivalent to
 the '==' operator, and could be passed as a first class function.
 Apparently, that is not possible without wrapping the comparison
 into another function/method.

The operator.eq function is equivalent to the == operator.  Use that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Thanks MRAB,
 
 You need to ensure that the pipe is already open at the other end.

So I need to open the process that reads the pipe before writing in it?

 
 
 
 Why are you using a named pipe anyway?

For some bug in ipython (see my previous email) I can't use subprocess.Popen 
and pipe in the standard way.
One of Ipython developers has suggested me to use named pipes as a temporary 
workaround. So I am taking the occasion to learn :)

 
 
 If you're talking to another program, then that needs to be running
 
 already, waiting for the connection, at the point that you open the
 
 named pipe from this end.

I am not entirely sure I got this: ideally I would like to have a function that 
runs an external tool (the equivalent of ls in my example) redirecting its 
output in a named pipe.

A second function (the cat command in my example) would read the named_pipe, 
parse it and extract some features from the output.

I also would like that the named_pipe is deleted when the whole communication 
is ended.


 
 If you're using a pipe _within_ a program (a queue would be better),
 
 then you should opening for writing in one thread and for reading in
 
 another.

Let's stick with the pipe :) I will ask about the queue when I manage to use 
pipes ;)

I should have explained better that I have no idea how to run threads in Python 
:): how do I open a thread that executes ls -lah in background and writes 
into a named pipe? And how do I open a thread that reads from the named pipe?

Can you please post a small example, so that I have something to work on?

Thanks a lot in advance for your help!

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


Re: Piping processes works with 'shell = True' but not otherwise.

2013-08-05 Thread Luca Cerone
thanks and what about python 2.7?
 
 
 In Python 3.3 and above:
 
 
 
 p = subprocess.Popen(..., stderr=subprocess.DEVNULL)

P.s. sorry for the late reply, I discovered I don't receive notifications from 
google groups..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB

On 05/08/2013 16:27, Luca Cerone wrote:

Thanks MRAB,


You need to ensure that the pipe is already open at the other end.


So I need to open the process that reads the pipe before writing in
it?



Why are you using a named pipe anyway?


For some bug in ipython (see my previous email) I can't use
subprocess.Popen and pipe in the standard way. One of Ipython
developers has suggested me to use named pipes as a temporary
workaround. So I am taking the occasion to learn :)


An alternative workaround is to use CPython. :-)


If you're talking to another program, then that needs to be
running already, waiting for the connection, at the point that you
open the named pipe from this end.


I am not entirely sure I got this: ideally I would like to have a
function that runs an external tool (the equivalent of ls in my
example) redirecting its output in a named pipe.

A second function (the cat command in my example) would read the
named_pipe, parse it and extract some features from the output.

I also would like that the named_pipe is deleted when the whole
communication is ended.


If you're using a pipe _within_ a program (a queue would be
better), then you should opening for writing in one thread and for
reading in another.


Let's stick with the pipe :) I will ask about the queue when I
manage to use pipes ;)

I should have explained better that I have no idea how to run
threads in Python :): how do I open a thread that executes ls -lah
in background and writes into a named pipe? And how do I open a
thread that reads from the named pipe?

Can you please post a small example, so that I have something to
work on?


You could try something like this:

os.mkfifo(named_pipe, 0777)
ls_process = subprocess.Popen(ls -lah  named_pipe)
pipe = open(named_pipe, r)
# Read the output of the subprocess from the pipe.

When the subprocess terminates (look at the docs for Popen objects),
close and delete the fifo.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Neil Cerutti
On 2013-08-05, Luca Cerone luca.cer...@gmail.com wrote:
 I just would like to learn how to handle named pipes in Python,
 which I find it easier to do by using a simple example that I
 am comfortable to use :)

Names pipes are a unix concept that saves you the hassle and
limitations of writing to and reading from a temp file.

You'll have to create the temp file and manage attaching
processes to it yourself.

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


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
Thanks this works (if you add shell=True in Popen).
If I don't want to use shell = True, how can I redirect the stdout to 
named_pipe? Popen accepts an open file handle for stdout, which I can't open 
for writing because that blocks the process...

 
 
 os.mkfifo(named_pipe, 0777)
 
 ls_process = subprocess.Popen(ls -lah  named_pipe)
 
 pipe = open(named_pipe, r)
 
 # Read the output of the subprocess from the pipe.
 
 
 
 When the subprocess terminates (look at the docs for Popen objects),
 
 close and delete the fifo.

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


RE: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Joseph L. Casale
 You can probably do something similar using sub commands
 (http://docs.python.org/2/library/argparse.html#sub-commands).

The problem here is that argparse does not pass the subparser into the
parsed args and shared args between subparsers need to be declared
each time. Come execution time, when you have shared args you end
up testing for various incantations of the invoked code, you're better
off omitting subparsers and performing conditional tests after parsing
for incompatible combinations.

It's a waste of typing to write out a mode followed by params to achieve
the ops goal, I've hit the same limitation. Certainly a weakness of argparse
in my opinion. It's also a tough sell to force a user to install a package just
for the cli if you go with docopt. I'd love to see argparse expand or docopt
get included...

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


Re: Piping processes works with 'shell = True' but not otherwise.

2013-08-05 Thread Tobiah

On 05/27/2013 04:33 AM, Luca Cerone wrote:



Will it violate privacy / NDA to post the command line? Even if we

can't actually replicate your system, we may be able to see something

from the commands given.




Unfortunately yes..



p1 = Popen(['nsa_snoop', 'terror_suspect', '--no-privacy', '--dispatch-squad'], 
...


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


Module for dialoging with intercative programs, sockets, files, etc.

2013-08-05 Thread Olive
I have found telnetlib which make very easy to interact with a telnet server, 
especially the read_until command. I wonder if something similar exits for 
other things that a telnet server. I for the moment have in mind interacting 
with a GSM modem (we do it by reading and writing a pseudo serial device file). 
But we could also want to interact with an interactive program or a socket, 
etc...

Olive 

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


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB

On 05/08/2013 17:54, Luca Cerone wrote:

Thanks this works (if you add shell=True in Popen).
If I don't want to use shell = True, how can I redirect the stdout to 
named_pipe? Popen accepts an open file handle for stdout, which I can't open 
for writing because that blocks the process...


You're back to using separate threads for the reader and the writer.
The one that opens the pipe first will block until the other one opens
the other end.




os.mkfifo(named_pipe, 0777)

ls_process = subprocess.Popen(ls -lah  named_pipe)

pipe = open(named_pipe, r)

# Read the output of the subprocess from the pipe.



When the subprocess terminates (look at the docs for Popen objects),

close and delete the fifo.




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


Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Rafael Durán Castañeda

El 04/08/13 04:10, Francois Lafont escribió:

Hi,

Is it possible with argparse to have this syntax for a script?

my-script (-a -b VALUE-B | -c -d VALUE-D)

I would like to do this with the argparse module.

Thanks in advance.



I think you are looking for exclusive groups:

http://docs.python.org/2.7/library/argparse.html#argparse.add_mutually_exclusive_group

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


Newbie: static typing?

2013-08-05 Thread Rui Maciel
Is there any pythonic way to perform static typing?  After searching the web 
I've stumbled on a significant number of comments that appear to cover 
static typing as a proof of concept , but in the process I've found no 
tutorial on how to implement it.

Does anyone care to enlighten a newbie?


Thanks in advance,
Rui Maciel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: static typing?

2013-08-05 Thread Gary Herron

On 08/05/2013 01:46 PM, Rui Maciel wrote:

Is there any pythonic way to perform static typing?  After searching the web
I've stumbled on a significant number of comments that appear to cover
static typing as a proof of concept , but in the process I've found no
tutorial on how to implement it.

Does anyone care to enlighten a newbie?


Thanks in advance,
Rui Maciel


The Pythonic way is to *enjoy* the freedom and flexibility and power of 
dynamic typing.  If you are stepping out of a static typing language 
into Python, don't step just half way.  Embrace dynamic typing.  (Like 
any freedom, it can bite you at times, but that's no reason to hobble 
Python with static typing.)



Python is both dynamically typed and strongly typed.  If you are 
confusing dynamic/static typing with week/strong typing, see

http://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language

Gary Herron




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


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread Luca Cerone
 You're back to using separate threads for the reader and the writer.

And how do I create separate threads in Python? I was trying to use the 
threading library without not too success..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Francois Lafont
Le 05/08/2013 16:11, Miki Tebeka a écrit :

 You can probably do something similar using sub commands 
 (http://docs.python.org/2/library/argparse.html#sub-commands).

Yes, but this is not the same syntax. I want this syntax :

my-script (-a -b VALUE-B | -c -d VALUE-D)

I don't want this syntax:

my-script (subcommad-a -b VALUE-B | subcommand-c -d VALUE-D)

In fact, in this post, I have simplified my question to put the stress just on 
my problem. In the real life, my script already uses the subcommands (and no 
problem with that). But I need to have mutually exclusive groups with 2 *sets* 
of options for compatibility reasons with another programs.

-- 
François Lafont
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Joseph L. Casale
 I think you are looking for exclusive groups:
 
 http://docs.python.org/2.7/library/argparse.html#argparse.add_mutually_excl
 usive_group

No. That links first doc line in that method shows the very point we are all 
discussing:

Create a mutually exclusive group. argparse will make sure that only one
of the arguments in the mutually exclusive group was present on the
command line:

Op requires more than one per group, this method make sure that only one
of the arguments is accepted.

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


undefined method []' for nil:NilClass (NoMethodError)

2013-08-05 Thread thcerbla . netsrot
Hi,

I have this script to monitor solr4 with munin.

But I get an error and I hove no idea what's the problem.

Hope someone can help me...


Thanks,

Torsten

Error:
/etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:60: undefined method 
[]' for nil:NilClass (NoMethodError)
from /etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:50:in each' 
from /etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:50

Script:
#%# family=auto
#%# capabilities=autoconf 

require 'open-uri'

SOLR_PORT = 8983
SOLR_HOST = localhost

target = __FILE__.split(_)[-1]

cores_url = 
http://#{SOLR_HOST}:#{SOLR_PORT}/solr/admin/cores?action=STATUSwt=ruby;

error = false
begin
  cores = eval(open(cores_url).read)['status'].keys.sort
rescue
  error = true
end

case ARGV[0]
when 'autoconf'
  puts error ? no : yes
when 'config'
  if target.end_with?(Cache)
puts graph_title #{target} hitratio
puts graph_args --base 1000 -r --lower-limit 0 --upper-limit 100
puts graph_vlabel %
  else
puts graph_title #{target}
puts graph_args --base 1000
puts graph_vlabel Size #{target}
  end

  puts graph_category Solr
  puts graph_info Info for cores: #{cores.join(,)}

  cores.each do |core|
puts #{core}.label #{core}
puts #{core}.type GAUGE
puts #{core}.min 0
  end
else
  cores.each do |core|
url = 
http://#{SOLR_HOST}:#{SOLR_PORT}/solr/#{core}/admin/mbeans?stats=truewt=ruby;
res = eval(open(url).read)

if target.end_with?('Cache')
  cache = Hash[*res['solr-mbeans']]['CACHE']
  hitratio = cache[target]['stats']['hitratio']
  stat = (hitratio.to_f * 100).round
else
  handler = Hash[*res['solr-mbeans']][QUERYHANDLER]
  stat = handler['/select']['stats'][target]
end

puts #{core}.value #{stat}
  end
end
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: undefined method []' for nil:NilClass (NoMethodError)

2013-08-05 Thread Chris Angelico
On Mon, Aug 5, 2013 at 11:24 PM,  thcerbla.nets...@googlemail.com wrote:
 I have this script to monitor solr4 with munin.

 But I get an error and I hove no idea what's the problem.

 Error:
 /etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:60: undefined method 
 []' for nil:NilClass (NoMethodError)

 cores_url = 
 http://#{SOLR_HOST}:#{SOLR_PORT}/solr/admin/cores?action=STATUSwt=ruby;


Your first problem, I think, is that that's not Python code. My
crystal ball suggests it's probably Ruby.

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


Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Francois Lafont
Le 05/08/2013 22:01, Rafael Durán Castañeda a écrit :

 I think you are looking for exclusive groups:
 
 http://docs.python.org/2.7/library/argparse.html#argparse.add_mutually_exclusive_group

Yes... but no. The doc explains you can do this:

my-script (-b VALUE-B | -d VALUE-D) 

ie mutally exclusive group with *just* *one* option incompatible with another 
one.

But, apparently, you can't do that:

my-script (-a -b VALUE-B | -c -d VALUE-D) 

ie mutually exclusive group with one *set* of option*s* incompatible with 
another *set* of option*s*. This is why I have posted my message. I have read 
the documentation before to post it. ;-)

I know docopt but I prefer argparse. My script have subcommands and some of 
them have common options, so I appreciate the parser objects and the 
inheritance between parser objects (with parents parameter of 
argparse.ArgumentParser class).

-- 
François Lafont
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulate `bash` behaviour using Python and named pipes.

2013-08-05 Thread MRAB

On 05/08/2013 22:47, Luca Cerone wrote:

You're back to using separate threads for the reader and the writer.


And how do I create separate threads in Python? I was trying to use the 
threading library without not too success..


To run a function in a separate thread:

import threading

def my_func(arg_1, arg_2):
...

my_thread = threading.Thread(target=my_func, args=(arg_1, arg_2))
my_thread.start()


Is the thread still running?

if my_thread.is_alive():
...


Wait for the thread to terminate:

my_thread.join()

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


Re: PyArg_ParseTuple() when the type could be anything?

2013-08-05 Thread David M. Cotter
i was able to get what i wanted by simply iterating over the tupile instead of 
using ParseTupile, then just query the type, then convert the type to C and 
move on to the next.  totally great, now i can pass N different argument types 
to a single function, and have the C side deal gracefully with whatever types 
are sent.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: static typing?

2013-08-05 Thread Ian Kelly
On Mon, Aug 5, 2013 at 2:46 PM, Rui Maciel rui.mac...@gmail.com wrote:
 Is there any pythonic way to perform static typing?  After searching the web
 I've stumbled on a significant number of comments that appear to cover
 static typing as a proof of concept , but in the process I've found no
 tutorial on how to implement it.

 Does anyone care to enlighten a newbie?

Python 3 has support for function annotations, but it leaves it
entirely up to the user how they wish to use these annotations (if at
all).  In theory, a Python IDE could use function annotations to
perform static type checking, but I am not aware of any IDE that has
actually implemented this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: static typing?

2013-08-05 Thread Ben Finney
Rui Maciel rui.mac...@gmail.com writes:

 Is there any pythonic way to perform static typing?

I think no; static typing is inherently un-Pythonic.

Python provides strong, dynamic typing. Enjoy it!

 Does anyone care to enlighten a newbie?

Is there some specific problem you think needs static typing? Perhaps
you could start a new thread, giving an example where you are having
trouble and you think static typing would help.

-- 
 \“Pinky, are you pondering what I'm pondering?” “Wuh, I think |
  `\so, Brain, but will they let the Cranberry Duchess stay in the |
_o__) Lincoln Bedroom?” —_Pinky and The Brain_ |
Ben Finney

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


Creating a running tally/ definitely new to this

2013-08-05 Thread gratedmedia

I currently working on a game, where I need to maintain a running tally of 
money, as the player makes purchases as they navigate thru game.   I not 
exactly sure how to do this in python.  I know it is a fairly basic step, 
nonetheless.  Any assistance would be greatly appreciated.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Sort lines in a plain text file alphanumerically

2013-08-05 Thread Devyn Collier Johnson
I am wanting to sort a plain text file alphanumerically by the lines. I 
have tried this code, but I get an error. I assume this command does not 
accept newline characters.



 file = open('/home/collier/pytest/sort.TXT', 'r').read()
 print(file)
z
c
w
r
h
s
d


 file.sort() #The first blank line above is from the file. I do not 
know where the second comes from.

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

I had the parameters (key=str.casefold, reverse=True), but I took those 
out to make sure the error was not with my parameters.


Specifically, I need something that will sort the lines. They may 
contain one word or one sentence with punctuation. I need to reverse the 
sorting ('z' before 'a'). The case does not matter ('a' = 'A').


I have also tried this without success:

 file.sort(key=str.casefold, reverse=True)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


Mahalo,

devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a running tally/ definitely new to this

2013-08-05 Thread Joshua Landau
On 6 August 2013 02:01, gratedme...@gmail.com wrote:


 I currently working on a game, where I need to maintain a running tally of
 money, as the player makes purchases as they navigate thru game.   I not
 exactly sure how to do this in python.  I know it is a fairly basic step,
 nonetheless.  Any assistance would be greatly appreciated.


If I understand correctly you want to store the amount of money in a
variable as a number that can be changed from many places within the code.

Say you have:

money = 0

def do_some_adventuring():
... # Add some money

You can add some money with:

global money # Allow changing money from within the function
money += 10 # for example

Is that it?



Note that normally you'd have some class of player with a money attribute
which can be accessed, but as a guess from the question I'm not sure you
know about classes yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a running tally/ definitely new to this

2013-08-05 Thread Dave Angel
gratedme...@gmail.com wrote:


 I currently working on a game, where I need to maintain a running tally of 
 money, as the player makes purchases as they navigate thru game.   I not 
 exactly sure how to do this in python.  I know it is a fairly basic step, 
 nonetheless.  Any assistance would be greatly appreciated.  

(just to save you the pain later:
   http://wiki.python.org/moin/GoogleGroupsPython
)

So what have you written so far?  Is this a homework assignment and
you've been covering certain parts of Python in a certain order? Is it
part of learning some tutorial?

There are so many ways of accomplishing this sort of thing, that without
some constraints, there are a dozen reasonable responses.  I'll try one:

in the class Player, you make a pair of methods, purchase() and
income(), which manipulate the instance attribute assets.   Then you
make a property that returns the assets.



Class Player:
 
 def purchase(self, amount):
self.assets -= amount
 def income(self, amount):
self.assets += amount
 def wealth(self):
return self.assets


-- 
DaveA


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


Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread MRAB

On 06/08/2013 03:00, Devyn Collier Johnson wrote:

I am wanting to sort a plain text file alphanumerically by the lines. I
have tried this code, but I get an error. I assume this command does not
accept newline characters.


   file = open('/home/collier/pytest/sort.TXT', 'r').read()


That returns the file as a single string.


   print(file)
z
c
w
r
h
s
d


   file.sort() #The first blank line above is from the file. I do not
know where the second comes from.
Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


Strings don't have a sort method.


I had the parameters (key=str.casefold, reverse=True), but I took those
out to make sure the error was not with my parameters.

Specifically, I need something that will sort the lines. They may
contain one word or one sentence with punctuation. I need to reverse the
sorting ('z' before 'a'). The case does not matter ('a' = 'A').

I have also tried this without success:

   file.sort(key=str.casefold, reverse=True)
Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'str' object has no attribute 'sort'


Try this:

lines = open('/home/collier/pytest/sort.TXT', 'r').readlines()
lines.sort()


Actually, a more Pythonic way these days is to use the 'with' statement:

with open('/home/collier/pytest/sort.TXT') as file:
lines = file.readlines()

lines.sort()

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


Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread Joshua Landau
On 6 August 2013 03:00, Devyn Collier Johnson devyncjohn...@gmail.comwrote:

 I am wanting to sort a plain text file alphanumerically by the lines. I
 have tried this code, but I get an error. I assume this command does not
 accept newline characters.


HINT #1: Don't assume that without a reason. It's wrong.


  file = open('/home/collier/pytest/**sort.TXT', 'r').read()


HINT #2: Don't lie. file is not a file so you probably shouldn't call it
one. It's the contents of a file object.


  print(file)
 z
 c
 w
 r
 h
 s
 d


  file.sort() #The first blank line above is from the file. I do not
 know where the second comes from.
 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: 'str' object has no attribute 'sort'


HINT #3: *Read*. What does it say?

AttributeError: 'str' object has no attribute 'sort'

Probably your problem, then, is that a 'str' object has no attribute
'sort'. That's what it says.

file is a 'str' object. You are accessing the 'sort' attribute which it
doesn't have.

I had the parameters (key=str.casefold, reverse=True), but I took those out
 to make sure the error was not with my parameters.


HINT #4: Don't just guess what the problem is. The answer is in the error.


 Specifically, I need something that will sort the lines. They may contain
 one word or one sentence with punctuation. I need to reverse the sorting
 ('z' before 'a'). The case does not matter ('a' = 'A').

 I have also tried this without success:

  file.sort(key=str.casefold, reverse=True)
 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: 'str' object has no attribute 'sort'




So you want to sort your string by lines. Rather than trying to abuse a
.sort attribute that patently doesn't exist, just use sorted OR convert to
a list first.

sorted(open('/home/collier/pytest/**sort.TXT'), key=str.casefold,
reverse=True)

Because it's bad to open files without a with unless you know what you're
doing, use a with:

with open('/home/collier/pytest/**sort.TXT') as file:
sorted(file, key=str.casefold, reverse=True)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread edu4madh
On Monday, August 5, 2013 10:00:55 PM UTC-4, Devyn Collier Johnson wrote:
 I am wanting to sort a plain text file alphanumerically by the lines. I 
 
 have tried this code, but I get an error. I assume this command does not 
 
 accept newline characters.
 
 
 
 
 
   file = open('/home/collier/pytest/sort.TXT', 'r').read()
 
   print(file)
 
 z
 
 c
 
 w
 
 r
 
 h
 
 s
 
 d
 
 
 
 
 
   file.sort() #The first blank line above is from the file. I do not 
 
 know where the second comes from.
 
 Traceback (most recent call last):
 
File stdin, line 1, in module
 
 AttributeError: 'str' object has no attribute 'sort'
 
 
 
 I had the parameters (key=str.casefold, reverse=True), but I took those 
 
 out to make sure the error was not with my parameters.
 
 
 
 Specifically, I need something that will sort the lines. They may 
 
 contain one word or one sentence with punctuation. I need to reverse the 
 
 sorting ('z' before 'a'). The case does not matter ('a' = 'A').
 
 
 
 I have also tried this without success:
 
 
 
   file.sort(key=str.casefold, reverse=True)
 
 Traceback (most recent call last):
 
File stdin, line 1, in module
 
 AttributeError: 'str' object has no attribute 'sort'
 
 
 
 
 
 Mahalo,
 
 
 
 devyncjohn...@gmail.com

fileName = open('test.txt')
lines = fileName.readlines()
lines.sort()
print lines
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23

On 6/08/2013 1:12 PM, Joshua Landau wrote:

Because it's bad to open files without a with unless you know what
you're doing, use a with:

 with open('/home/collier/pytest/__sort.TXT') as file:
 sorted(file, key=str.casefold, reverse=True)


Shouldn't that be:

with open('/home/collier/pytest/__sort.TXT') as file:
data = file.readlines()
sorted(data, key=str.casefold, reverse=True)

I'm tempted to say HINT #5: don't provide a solution without testing it 
first but that would be pretty obnoxious.

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


Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23

On 6/08/2013 1:49 PM, alex23 wrote:

Shouldn't that be:

 with open('/home/collier/pytest/__sort.TXT') as file:
 data = file.readlines()
 sorted(data, key=str.casefold, reverse=True)

I'm tempted to say HINT #5: don't provide a solution without testing it
first but that would be pretty obnoxious.


Even more so when I got it wrong myself :)

data = sorted(file.readlines(), key=str.casefold, reverse=True)

I can never remember which one sorts in place and which doesn't.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sort lines in a plain text file alphanumerically

2013-08-05 Thread alex23

On 6/08/2013 1:49 PM, alex23 wrote:

On 6/08/2013 1:12 PM, Joshua Landau wrote:

Because it's bad to open files without a with unless you know what
you're doing, use a with:

 with open('/home/collier/pytest/__sort.TXT') as file:
 sorted(file, key=str.casefold, reverse=True)


Shouldn't that be:

 with open('/home/collier/pytest/__sort.TXT') as file:
 data = file.readlines()
 sorted(data, key=str.casefold, reverse=True)


Hmm, I take that back entirely. Your version does work. Weirdly, I tried 
yours under both 2.7  3.2 without it working at all, but a subsequent 
attempt did. Sorry for the noise.

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


Re: Hangman question

2013-08-05 Thread eschneider92
Thanks I get it now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: static typing?

2013-08-05 Thread Steven D'Aprano
On Mon, 05 Aug 2013 21:46:57 +0100, Rui Maciel wrote:

 Is there any pythonic way to perform static typing?  After searching the
 web I've stumbled on a significant number of comments that appear to
 cover static typing as a proof of concept , but in the process I've
 found no tutorial on how to implement it.

Try Cobra instead. It's Python-like syntax, but allows static typing.

http://cobra-language.com/



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


[issue18658] Mercurial CPython log ticket link is broken

2013-08-05 Thread Vajrasky Kok

Vajrasky Kok added the comment:

Okay, it looks like it has been fixed. The format has changed as well.

Previously:
5 hours ago R David Murray  Merge: #18657: remove duplicate entries from 
Misc/ACKS.default tip
5 hours ago R David Murray  #18657: remove duplicate entries from 
Misc/ACKS.3.3

Now:
10 hours agoR David Murray  Merge: #18657: remove duplicate entries from 
Misc/ACKS. [#18657] default
10 hours agoR David Murray  #18657: remove duplicate entries from 
Misc/ACKS. [#18657] 3.3

Now we have separate link to ticket (inside the bracket) at the end of commit 
message, whereas previously it was inside the commit message.

I guess we can close this ticket as fixed.

--

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



[issue18651] test failures on KFreeBSD

2013-08-05 Thread Petr.Salinger

Petr.Salinger added the comment:

It is related to 

http://bugs.python.org/issue12958
http://bugs.python.org/issue17684

The second one changed support.anticipate_failure to unittest.skipIf

--
nosy: +Petr.Salinger

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



[issue18532] hashlib.HASH objects should officially expose the hash name

2013-08-05 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 238c37e4c395 by Jason R. Coombs in branch 'default':
Issue 18532: Added tests and documentation to formally specify the .name 
attribute on hashlib objects.
http://hg.python.org/cpython/rev/238c37e4c395

--
nosy: +python-dev

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



[issue18532] hashlib.HASH objects should officially expose the hash name

2013-08-05 Thread Jason R. Coombs

Jason R. Coombs added the comment:

I've confirmed the tests pass and the updated documentation renders nicely and 
without warnings. These changes now make the name attribute 
officially-supported and tested.

--
resolution:  - fixed

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



[issue18658] Mercurial CPython log ticket link is broken

2013-08-05 Thread Vajrasky Kok

Vajrasky Kok added the comment:

Wait, something weird is happening in CPython commits log website, 
http://hg.python.org/cpython .

These are the latest four commits.

age author  description
45 hours agoJason R. Coombs Issue 18532: Added tests and 
documentation to formally specify the .name attribute on hashlib 
objects.default tip
105 minutes ago Raymond Hettinger   Silence compiler warning for 
unused declaration.2.7
11 hours agoR David Murray  Merge: #18657: remove duplicate entries from 
Misc/ACKS. [#18657]
11 hours agoR David Murray  #18657: remove duplicate entries from 
Misc/ACKS. [#18657]3.3

The age column is screwed up. 11 hours ago goes to 105 minutes ago then goes 
back to 45 hours ago.

--

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



[issue18658] Mercurial CPython log ticket link is broken

2013-08-05 Thread Ezio Melotti

Ezio Melotti added the comment:

This is a separate issue though, isn't it?
Have you tried to ctrl+f5 the page?

(Also this is probably something that should be reported to the Mercurial bug 
tracker, since -- unlike the issue links -- is not something we modified.)

--
nosy: +ezio.melotti

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



[issue6057] sqlite3 error classes should be documented

2013-08-05 Thread timm

timm added the comment:

I would find it useful to have the exception classes listed in the Python 
documentation rather than having to refer to two documents, but I don't have 
strong feelings on this.

Given that nobody has fixed this for 4 years, should we just close the ticket? 
I'd be happy to do the necessary work if this is something we want changed, but 
I don't want to prepare a patch for a ticket that's never going to go anywhere.

--
nosy: +timm

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



[issue18658] Mercurial CPython log ticket link is broken

2013-08-05 Thread Ned Deily

Ned Deily added the comment:

While it looks unusual, the commit list is fine.  It reflects what you see 
currently in a hg log.  What happened is that someone imported an older local 
change set or something similar.  It's not always easy to tell from the log.

--
resolution:  - invalid
stage:  - committed/rejected
status: open - closed

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Vajrasky Kok

New submission from Vajrasky Kok:

There is test_precision in Lib/test_format.py which is not being unit tested.

Also, there is a unused variable inside test_precision.

Attached the patch to fix these problems.

--
components: Tests
files: test_precision.patch
keywords: patch
messages: 194459
nosy: vajrasky
priority: normal
severity: normal
status: open
title: test_precision in test_format.py is not executed and has unused variable
versions: Python 3.4
Added file: http://bugs.python.org/file31162/test_precision.patch

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



[issue14323] Normalize math precision in RGB/YIQ conversion

2013-08-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 Can you add a reference for the coefficients?

I have only link to Wikipedia which refers to Code of Federal Regulations 
§73.682. This link (http://en.wikipedia.org/wiki/YIQ) already mentioned at the 
top of the file.

 (You claim about the current rounding is not exactly correct. While .28*g 
 rounds .277 rather than .274, the current .52*g rounds the non-FCC .523 
 rather than the FCC .5251. So I avoided making the claim in the suggested 
 entry. It is not important.)

A sum of coefficients in this line should be 0 (Q=0 for R=G=B).

Patch updated. I added a What's New entry and update to use of unittest.main(), 
rewrite rgb_to_yiq() in the form as in Wikipedia (it uses less multiplications) 
and write coefficients in yiq_to_rgb() with maximal precision (as calculated 
with Python).

--
Added file: http://bugs.python.org/file31163/colorsys_yiq_fcc_2.patch

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



[issue18660] os.read behavior on Linux

2013-08-05 Thread Louis RIVIERE

New submission from Louis RIVIERE:

A call to os.read that used to work on older Linux kernel, doesn't anymore with 
newer Linux kernel.
As a workaroud we can use libc.read (ctypes) instead of os.read.
But I feel like os.read should work, as it used to.

The code (and comments) can be seen here : 
http://code.activestate.com/recipes/576375-low-level-inotify-wrapper/

--
components: IO
messages: 194461
nosy: dugres
priority: normal
severity: normal
status: open
title: os.read behavior on Linux
type: behavior
versions: Python 2.7

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Mark Dickinson

Mark Dickinson added the comment:

Patch looks good to me.

--
nosy: +mark.dickinson

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Roundup Robot

Roundup Robot added the comment:

New changeset cfd875bcbe41 by Mark Dickinson in branch 'default':
Issue #18659: fix test_format test that wasn't being executed.  Thanks Vajrasky 
Kok for the patch.
http://hg.python.org/cpython/rev/cfd875bcbe41

--
nosy: +python-dev

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Mark Dickinson

Mark Dickinson added the comment:

Fixed.  Thanks!

--
assignee:  - mark.dickinson
resolution:  - fixed
stage:  - committed/rejected
status: open - closed
type:  - behavior

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



[issue18661] Typo in grpmodule.c

2013-08-05 Thread Vajrasky Kok

New submission from Vajrasky Kok:

I guess, there is a typo in Modules/grpmodule.c. See the patch below:

diff -r f4f81ebc3de9 Modules/grpmodule.c
--- a/Modules/grpmodule.c   Sun Aug 04 15:50:08 2013 -0400
+++ b/Modules/grpmodule.c   Mon Aug 05 17:40:33 2013 +0800
@@ -10,7 +10,7 @@
{gr_name, group name},
{gr_passwd, password},
{gr_gid, group id},
-   {gr_mem, group memebers},
+   {gr_mem, group members},
{0}
 };

I am not sure whether the line after typo should be {0} or {0, 0}.

--
assignee: docs@python
components: Documentation
messages: 194465
nosy: docs@python, vajrasky
priority: normal
severity: normal
status: open
title: Typo in grpmodule.c
versions: Python 3.4

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



[issue18661] Typo in grpmodule.c

2013-08-05 Thread Mark Dickinson

Mark Dickinson added the comment:

{0} is fine;  some compilers will warn about it, but I believe it's valid C.

--
nosy: +mark.dickinson

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Mark Dickinson

Mark Dickinson added the comment:

Okay, that caused some buildbots to fail.  I'm going to back out the change 
until I have time to figure out what's going on.

--
resolution: fixed - 
status: closed - open

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 9bee1fd64ee6 by Mark Dickinson in branch 'default':
Issue #18659: Backed out changeset cfd875bcbe41 after buildbot failures.
http://hg.python.org/cpython/rev/9bee1fd64ee6

--

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Mark Dickinson

Mark Dickinson added the comment:

Sample buildbot output here:

http://buildbot.python.org/all/builders/x86%20RHEL%206%203.x/builds/2485/steps/test/logs/stdio

Relevant snippet:

test_precision (test.test_format.FormatTest) ... FAIL

==
FAIL: test_precision (test.test_format.FormatTest)
--
Traceback (most recent call last):
  File 
/home/buildbot/buildarea/3.x.coghlan-redhat/build/Lib/test/test_format.py, 
line 338, in test_precision
self.assertEqual(str(cm.exception), precision too big)
AssertionError: 'Too many decimal digits in format string' != 'precision too 
big'
- Too many decimal digits in format string
+ precision too big


--
Ran 5 tests in 0.011s

--

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Vajrasky Kok

Vajrasky Kok added the comment:

Let me help you to debug this issue.

ethan@amiau:~/Documents/code/python/cpython$ cat /tmp/a.py
import sys

INT_MAX = sys.maxsize
f = 1.2
format(f, .%sf % (INT_MAX + 1))
ethan@amiau:~/Documents/code/python/cpython$ ./python /tmp/a.py
Traceback (most recent call last):
  File /tmp/a.py, line 5, in module
format(f, .%sf % (INT_MAX + 1))
ValueError: Too many decimal digits in format string
ethan@amiau:~/Documents/code/python/cpython$ cat /tmp/b.py
import sys

INT_MAX = 2147483647
f = 1.2
format(f, .%sf % (INT_MAX + 1))
ethan@amiau:~/Documents/code/python/cpython$ ./python /tmp/b.py
Traceback (most recent call last):
  File /tmp/b.py, line 5, in module
format(f, .%sf % (INT_MAX + 1))
ValueError: precision too big

My question is whether we should have different exception message for these two 
cases?

--

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



[issue18660] os.read behavior on Linux

2013-08-05 Thread Ronald Oussoren

Changes by Ronald Oussoren ronaldousso...@mac.com:


--
nosy: +ronaldoussoren

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Vajrasky Kok

Vajrasky Kok added the comment:

For now, instead of hardcoding INT_MAX to 2147483647 in test, maybe we can use 
module:

 import IN
 IN.INT_MAX
2147483647

--

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



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-05 Thread Mark Dickinson

Mark Dickinson added the comment:

+1 on the name 'first_true'.  Does exactly what it says on the tin.

--

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



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-05 Thread Hynek Schlawack

Hynek Schlawack added the comment:

 +1 on the name 'first_true'.  Does exactly what it says on the tin.

I fully agree.

***

I assume what's missing now is a permission from Raymond to mess with his turf?

--

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



[issue18515] zipfile._ZipDecryptor generates wasteful crc32 table on import

2013-08-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The objection to zipfile-no-crc32.patch is that binascii.crc32() and _crc32() 
have different signatures. binascii.crc32() accepts a byte object while 
_crc32() accepts a single integer. With packing this value into a bytes object 
_crc32() will be much slower.

As for zdlazy.patch, there is a proposed patch in issue10030 which speedups 
pure Python decryption. I'm afraid that with zdlazy.patch this path will lose a 
part of it's speedup.

--

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Serhiy Storchaka

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


--
nosy: +haypo, serhiy.storchaka

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



[issue13083] _sre: getstring() releases the buffer before using it

2013-08-05 Thread Serhiy Storchaka

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


--
resolution:  - duplicate
stage:  - committed/rejected
status: open - closed
superseder:  - Segfault when using re.finditer over mmap

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



[issue13083] _sre: getstring() releases the buffer before using it

2013-08-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Agree.

--

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread STINNER Victor

STINNER Victor added the comment:

The IN module must not be used, it is hardcoded and never regenerated.

--

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread STINNER Victor

STINNER Victor added the comment:

I added the test in the following commit:

changeset:   84266:ef5175d08e7e
branch:  3.3
parent:  84263:7ecca1a98220
user:Victor Stinner victor.stin...@gmail.com
date:Sun Jun 23 14:54:30 2013 +0200
files:   Lib/test/test_format.py Misc/NEWS Python/formatter_unicode.c
description:
Issue #18137: Detect integer overflow on precision in float.__format__() and
complex.__format__().

--

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

We have _testcapi.INT_MAX.

I guess different exceptions raised on 64-bit platform. First parser checks 
that a number can be represented as Py_ssize_t (i.e. = PY_SSIZE_T_MAX). Here 
Too many decimal digits in format string can be raised. Then precision passed 
to internal function which accepts int and checked to be = INT_MAX before cast 
to int. Here precision too big can be raised.

--

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Vajrasky Kok

Vajrasky Kok added the comment:

For the passers-by who want to help:

The precision too big exception is raised in Python/formatter_unicode.c line 
1168 and 1002.

The Too many decimal digits... exception is raised in 
Python/formatter_unicode.c line 71.

So the question is whether it is beneficial to differentiate the exception 
message. If not, we can change the exception message or test whether the digit 
passes INT_MAX first before checking with sys.max_size. If yes, we need to add 
test case for sys.max_size and use _testcapi.INT_MAX for current unit test case.

--

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



[issue18273] Simplify calling and discovery of json test package

2013-08-05 Thread Ezio Melotti

Ezio Melotti added the comment:

I like the patch.
Can you make ./python Lib/test/test_json/ work too?  Currently it doesn't 
seem to work (it works for e.g. ./python Lib/test/test_email/).

--
stage:  - patch review

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



[issue14323] Normalize math precision in RGB/YIQ conversion

2013-08-05 Thread Ezio Melotti

Ezio Melotti added the comment:

LGTM.

--
stage: patch review - commit review

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



[issue18078] threading.Condition to allow notify on a specific waiter

2013-08-05 Thread João Bernardo

João Bernardo added the comment:

Seems like just because I never used I don't support. Boost C++ libraries has 
a wait_for_any functionality to synchronize futures. C# has a WaitAny in the 
WaitHandle class (like our Condition).

Another problem is: the Condition class cannot be easily subclassed because all 
the important bits are _protected... Can you add an interface for the 
_waiters list and _lock objects?? If you do that I'll be happy subclassing 
it.

--

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



[issue18585] Add a text truncation function

2013-08-05 Thread Ezio Melotti

Ezio Melotti added the comment:

[...] and ASCII are fine with me.

 Perhaps there could be an argument controlling where to truncate
 (left, right or centre). A good use-case for the new Enums, perhaps? :-)

I wrote a similar function once and in addition to the width it had this 
feature too (defaulting on center), so it sounds like a reasonable addition 
to me.  Back then I was simply passing a left/right/center string -- not 
sure it's worth adding an enum for this (FWIW for text alignment there are 3 
separate methods: ljust, center, and rjust).

--

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



[issue18585] Add a text truncation function

2013-08-05 Thread Ezio Melotti

Ezio Melotti added the comment:

Perhaps shorten would be a better name -- summarize sounds smarter than it 
actually is :)

--

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



[issue18659] test_precision in test_format.py is not executed and has unused variable

2013-08-05 Thread Vajrasky Kok

Vajrasky Kok added the comment:

Okay, I guess the fix for this ticket should be kept simple.

If we want to merge the exception message or touch the code base or do 
something smarter than fixing the test, maybe we should create a separate 
ticket.

So I used Serhiy Storchaka's suggestion to use _testcapi.INT_MAX for the second 
patch.

--
Added file: http://bugs.python.org/file31164/test_precision_v2.patch

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



[issue18585] Add a text truncation function

2013-08-05 Thread R. David Murray

R. David Murray added the comment:

Looking just at the proposed functionality (taking a prefix) and ignoring the 
requested complexification :), the usual name for the text produced by this 
process is a lead 
(http://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Lead_section), although 
formally a lead is actually written to be used as such, as opposed to just 
taking a prefix, so that word really has the same problem as 'summarize'.

I think 'truncate' would be a better name.  Or, if you don't mind being 
wordier, extract_prefix.  The fact that it is part of the textwrap module 
should be enough clue that the truncation happens at whitespace.  Truncate 
could also apply to the expanded version if you squint a little, if Antoine is 
interested in that.  On the other hand, the use case presented for that is not 
going to be served by this function anyway, since this function (being part of 
textwrap) breaks on whitespace...it shouldn't (IMO) elide text other than at 
whitespace.  If you want that functionality it belongs in some other module, I 
think.

The placeholder argument could alternatively be named 'ellipsis', but 
placeholder is certainly fine.

shorten would probably be better if you are going with the expanded version, 
but I like truncate.  It is probably significant that that is what the title of 
the issue calls it :)

--
nosy: +r.david.murray

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



[issue18472] Update PEP 8 to encourage modern conventions

2013-08-05 Thread Ezio Melotti

Ezio Melotti added the comment:

I'm a bit late but I still have a few comments:

+  The paren-using form also means that when the exception arguments are
+  long or include string formatting, you don't need to use line
+  continuation characters thanks to the containing parentheses.

This paragraph doesn't add much and could be removed IMHO.


+- When binding caught exceptions to a name, prefer the explicit name
+  binding syntax added in Python 2.6::
+
+  try:
+  process_data()
+  except Exception as exc:
+  raise DataProcessingFailedError(str(exc))

It took me a bit to realize that this is talking about as.  I think it would 
be better to be more explicit, and simplify the example a bit so that it's not 
as distracting.


+  Note that in Python 3, ``unicode`` and ``basestring`` no longer exist
+  (there is only ``str``) and a bytes object is no longer a kind of
+  string (it is a sequence of integers instead)

Is there any specific reason to use sequence of integers instead of sequence 
of bytes?

--

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



[issue18606] Add statistics module to standard library

2013-08-05 Thread Steven D'Aprano

Steven D'Aprano added the comment:

On 03/08/13 13:22, Alexander Belopolsky wrote:

 Alexander Belopolsky added the comment:

 The implementation of median and mode families of functions as classes is 
 clever,

So long as it is not too clever.

 but I am not sure it is a good idea to return something other than an 
 instance of the class from __new__().

Returning foreign instances is supported behaviour for __new__. (If the object 
returned from __new__ is not an instance, __init__ is not called.) I believe 
the current implementation is reasonable and prefer to keep it. If I use the 
traditional implementation, there will only be one instance, with no state, 
only methods. That's a rather poor excuse for an instance, and a class already 
is a singleton object with methods and (in this case) no state, so creating an 
instance as well adds nothing.

I will change the implementation if the consensus among senior devs is against 
it, but would prefer not to.

--

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



[issue2528] Change os.access to check ACLs under Windows

2013-08-05 Thread Tim Golden

Tim Golden added the comment:

Here's an updated patch against trunk with tests  doc changes

--
status: languishing - open
Added file: http://bugs.python.org/file31165/issue2528.2.patch

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



[issue2528] Change os.access to check ACLs under Windows

2013-08-05 Thread Tim Golden

Tim Golden added the comment:

... and to answer Amaury's question in msg109871 it creates a reasonable 
consistency between the results of os.access and the user's actual ability to 
read / write a file. eg, you might have no permissions whatsoever on the file 
but as long as it wasn't read-only, os.access would return True for reading, 
writing and executing.

--

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



[issue17372] provide pretty printer for xml.etree.ElementTree

2013-08-05 Thread Laszlo Papp

Laszlo Papp added the comment:

This has just made me switching away from xml.etree.ElementTree today, sadly.

What a pity; it would have been all kind of cool to stick to this minimal, 
otherwise working parser and builder.

--
nosy: +lpapp

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



  1   2   >