plotting slows down

2014-01-13 Thread norman . elliott
First let me say I have not done much python programming!
I am running Python 2.7.3.
I am trying to use python as a front end to a simple oscilloscope.
Ultimately I intend to use it with my micropython board.

At the moment I am just developing it. All it does is use a module I found 
called graphics.py to create a window and display randomly generated data.

Each time it goes through the outer loop it gets slower and slower.
I put in a small delay just so I could observe what is happening and for the 
first line it draws it takes about a second. If I set it to loop 20 times the 
final loop takes more than 6 seconds.
Can anyone explain what I am doing wrong please?
Here is the code:
[code]
#!/usr/bin/python
from graphics import *
import random
import time

xpos=1200
ypos=400
ypnt=ypos/2
pos=1
#setBackground(white)
def main():
win = GraphWin(My Circle, xpos, ypos)
#   win.setBackGround('white')
for y in range(1,5):
cir2 = Circle(Point(xpos/2,20), 10)
cir2.setFill(white)
cir2.draw(win)
message = Text(Point(win.getWidth()/2, 20), y)
message.draw(win)
j = random.randint(1,ypos)
for x in range(1,xpos):
updown = random.randint(0,1)
if updown:
j=j+1
else:
j=j-1
if j 1:
j=ypos/2
if jypos-1:
j=ypos/2
win.plot(x,j,red)
time.sleep(.0001)

main()
time.sleep(5)
[/code]


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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread Thomas Rachel

Am 12.01.2014 08:50 schrieb wxjmfa...@gmail.com:

sys.version

2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]

s = 'Straße'
assert len(s) == 6
assert s[5] == 'e'



Wow. You just found one of the major differences between Python 2 and 3.

Your assertins are just wrong, as s = 'Straße' leads - provided you use 
UTF8 - to a representation of 'Stra\xc3\x9fe', obviously leading to a 
length of 7.



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


Re: Problem writing some strings (UnicodeEncodeError)

2014-01-13 Thread Peter Otten
Paulo da Silva wrote:

 Em 12-01-2014 20:29, Peter Otten escreveu:
 Paulo da Silva wrote:
 
 but I have not tried it myself. Also, some bytes may need to be
 escaped, either to be understood by the shell, or to address security
 concerns:


 Since I am puting the file names between , the only char that needs to
 be escaped is the  itself.
 
 What about the escape char?
 
 Just this fn=fn.replace('','\\')
 
 So far I didn't find any problem, but the script is still running.

To be a bit more explicit:

 for filename in os.listdir():
... print(template.replace(fn, filename.replace('', '\\')))
... 
ls \\; rm whatever; ls \


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


Re: Problem writing some strings (UnicodeEncodeError)

2014-01-13 Thread Peter Otten
Peter Otten wrote:

 Paulo da Silva wrote:
 
 Em 12-01-2014 20:29, Peter Otten escreveu:
 Paulo da Silva wrote:
 
 but I have not tried it myself. Also, some bytes may need to be
 escaped, either to be understood by the shell, or to address security
 concerns:


 Since I am puting the file names between , the only char that needs
 to be escaped is the  itself.
 
 What about the escape char?
 
 Just this fn=fn.replace('','\\')
 
 So far I didn't find any problem, but the script is still running.
 
 To be a bit more explicit:
 
 for filename in os.listdir():
 ... print(template.replace(fn, filename.replace('', '\\')))
 ...
 ls \\; rm whatever; ls \

The complete session:

 import os
 template = 'ls fn'
 with open('\\; rm whatever; ls \\', w) as f: pass
... 
 for filename in os.listdir():
... print(template.replace(fn, filename.replace('', '\\')))
... 
ls \\; rm whatever; ls \


Shell variable substitution is another problem. c.l.py is probably not the 
best place to get the complete list of possibilities.


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


Re: L[:]

2014-01-13 Thread Laszlo Nagy



Unless L is aliased, this is silly code.
There is another use case. If you intend to modify a list within a for 
loop that goes over the same list, then you need to iterate over a copy. 
And this cannot be called an alias because it has no name:


for idx,item in enumerate(L[:]):
   # do something with L here, including modification



--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread wxjmfauth
Le lundi 13 janvier 2014 09:27:46 UTC+1, Thomas Rachel a écrit :
 Am 12.01.2014 08:50 schrieb wxjmfa...@gmail.com:
 
  sys.version
 
  2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
 
  s = 'Stra�e'
 
  assert len(s) == 6
 
  assert s[5] == 'e'
 
 
 
 
 
 Wow. You just found one of the major differences between Python 2 and 3.
 
 
 
 Your assertins are just wrong, as s = 'Stra�e' leads - provided you use 
 
 UTF8 - to a representation of 'Stra\xc3\x9fe', obviously leading to a 
 
 length of 7.
 
 


Not at all. I'm afraid I'm understanding Python (on this
aspect very well).

Do you belong to this group of people who are naively
writing wrong Python code (usually not properly working)
during more than a decade?

'ß' is the the fourth character in that text Straße
(base index 0).

This assertions are correct (byte string and unicode).

 sys.version
'2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
 assert 'Straße'[4] == 'ß'
 assert u'Straße'[4] == u'ß'
 

jmf

PS Nothing to do with Py2/Py3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Module depositary

2014-01-13 Thread Sean Murphy
Hi All.

I am aware that active state python has a commercial module depositary which 
you can get modules from. Under PERL you had CPAN. Is there anything like this 
for Python?


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


Re: Module depositary

2014-01-13 Thread Chris Angelico
On Mon, Jan 13, 2014 at 9:05 PM, Sean Murphy mhysnm1...@gmail.com wrote:
 Hi All.

 I am aware that active state python has a commercial module depositary which 
 you can get modules from. Under PERL you had CPAN. Is there anything like 
 this for Python?

Check out the Python Package Index:

https://pypi.python.org/pypi

It's not commercial, and (as far as I know) there's no curating of
projects, so you need to make your own decision about what you trust
and how you handle version dependencies. There are easy and convenient
ways to install packages, most notably pip (which is mentioned on the
landing page).

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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread Chris Angelico
On Mon, Jan 13, 2014 at 8:54 PM,  wxjmfa...@gmail.com wrote:
 This assertions are correct (byte string and unicode).

 sys.version
 '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
 assert 'Straße'[4] == 'ß'
 assert u'Straße'[4] == u'ß'


 jmf

 PS Nothing to do with Py2/Py3.

This means that either your source encoding happens to include that
character, or you have assertions disabled. It does NOT mean that you
can rely on writing this string out to a file and having someone else
read it in and understand it the same way.

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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread Steven D'Aprano
On Mon, 13 Jan 2014 01:54:21 -0800, wxjmfauth wrote:

 sys.version
 '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
 assert 'Straße'[4] == 'ß'
 assert u'Straße'[4] == u'ß'

I think you are using from __future__ import unicode_literals. 
Otherwise, that cannot happen in Python 2.x. Using a narrow build:


# on my machine ando
py sys.version
'2.7.2 (default, May 18 2012, 18:25:10) \n[GCC 4.1.2 20080704 (Red Hat 
4.1.2-52)]'
py sys.maxunicode
65535
py assert 'Straße'[4] == 'ß'
Traceback (most recent call last):
  File stdin, line 1, in module
AssertionError
py list('Straße')
['S', 't', 'r', 'a', '\xc3', '\x9f', 'e']


Using a wide build is the same:


# on my machine orac
 sys.maxunicode
1114111
 assert 'Straße'[4] == 'ß'
Traceback (most recent call last):
  File stdin, line 1, in module
AssertionError


But once you run the from __future__ line, the behaviour changes to 
what you show:

py from __future__ import unicode_literals
py list('Straße')
[u'S', u't', u'r', u'a', u'\xdf', u'e']
py assert 'Straße'[4] == 'ß'
py


But I still don't understand the point you are trying to make.



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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread Chris Angelico
On Mon, Jan 13, 2014 at 9:38 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 I think you are using from __future__ import unicode_literals.
 Otherwise, that cannot happen in Python 2.x.


Alas, not true.

 sys.version
'2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]'
 sys.maxunicode
65535
 assert 'Straße'[4] == 'ß'
 list('Straße')
['S', 't', 'r', 'a', '\xdf', 'e']

That's Windows XP. Presumably Latin-1 (or CP-1252, they both have that
char at 0xDF). He happens to be correct, *as long as the source code
encoding matches the output encoding and is one that uses 0xDF to mean
U+00DF*. Otherwise, he's not.

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


Re:plotting slows down

2014-01-13 Thread Dave Angel
 norman.elli...@gmail.com Wrote in message:
 First let me say I have not done much python programming!
 I am running Python 2.7.3.
 I am trying to use python as a front end to a simple oscilloscope.
 Ultimately I intend to use it with my micropython board.
 
 At the moment I am just developing it. All it does is use a module I found 
 called graphics.py to create a window and display randomly generated data.
 
 Each time it goes through the outer loop it gets slower and slower.
 I put in a small delay just so I could observe what is happening and for the 
 first line it draws it takes about a second. If I set it to loop 20 times the 
 final loop takes more than 6 seconds.
 Can anyone explain what I am doing wrong please?
 Here is the code:
 [code]
 #!/usr/bin/python
 from graphics import *

First things first. what operating system are you using,  and
 where did you get the mysterious graphics. py?  Thanks for
 telling us python 2.7.3

Next, please repost any source code with indentation preserved. 
 Your message shows it all flushed to the left margin,  probably
 due to posting in html mode. Use text mode here.

Finally,  since you seem to be using googlegroups,  please make
 sure you don't double space your quotes. See. wiki.python.org/moi
n/GoogleGroupsPython

 

-- 
DaveA



Android NewsGroup Reader
http://www.piaohong.tk/newsgroup

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


Re: plotting slows down

2014-01-13 Thread Norman Elliott
On Monday, 13 January 2014 08:15:08 UTC, Norman Elliott  wrote:
 First let me say I have not done much python programming!
 
 I am running Python 2.7.3.
 
 I am trying to use python as a front end to a simple oscilloscope.
 
 Ultimately I intend to use it with my micropython board.
 
 
 
 At the moment I am just developing it. All it does is use a module I found 
 called graphics.py to create a window and display randomly generated data.
 
 
 
 Each time it goes through the outer loop it gets slower and slower.
 
 I put in a small delay just so I could observe what is happening and for the 
 first line it draws it takes about a second. If I set it to loop 20 times the 
 final loop takes more than 6 seconds.
 
 Can anyone explain what I am doing wrong please?
 
 Here is the code:
 
 [code]
 
 #!/usr/bin/python
 
 from graphics import *
 
 import random
 
 import time
 
 
 
 xpos=1200
 
 ypos=400
 
 ypnt=ypos/2
 
 pos=1
 
 #setBackground(white)
 
 def main():
 
   win = GraphWin(My Circle, xpos, ypos)
 
 # win.setBackGround('white')
 
   for y in range(1,5):
 
   cir2 = Circle(Point(xpos/2,20), 10)
 
   cir2.setFill(white)
 
   cir2.draw(win)
 
   message = Text(Point(win.getWidth()/2, 20), y)
 
   message.draw(win)
 
   j = random.randint(1,ypos)
 
   for x in range(1,xpos):
 
   updown = random.randint(0,1)
 
   if updown:
 
   j=j+1
 
   else:
 
   j=j-1
 
   if j 1:
 
   j=ypos/2
 
   if jypos-1:
 
   j=ypos/2
 
   win.plot(x,j,red)
 
   time.sleep(.0001)
 
 
 
 main()
 
 time.sleep(5)
 
 [/code]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Norman Elliott
I am running ubuntu 12.04 with all updates installed.

I got the graphics here:
http://mcsp.wartburg.edu/zelle/python/graphics/graphics/index.html

I cannot see how to change from html to text mode in chromium or within the 
group.

I read the link about double spacing so I will watch out for it.
-- 
https://mail.python.org/mailman/listinfo/python-list


proposal: bring nonlocal to py2.x

2014-01-13 Thread Neal Becker
py3 includes a fairly compelling feature: nonlocal keywork
But backward compatibility is lost.  It would be very helpful
if this was available on py2.x.

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


Re: proposal: bring nonlocal to py2.x

2014-01-13 Thread Giampaolo Rodola'
On Mon, Jan 13, 2014 at 3:47 PM, Neal Becker ndbeck...@gmail.com wrote:

 py3 includes a fairly compelling feature: nonlocal keywork
 But backward compatibility is lost.  It would be very helpful
 if this was available on py2.x.

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



It's not gonna happens as per PEP-404:
http://www.python.org/dev/peps/pep-0404/

-- 
Giampaolo - http://grodola.blogspot.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: proposal: bring nonlocal to py2.x

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 1:47 AM, Neal Becker ndbeck...@gmail.com wrote:
 py3 includes a fairly compelling feature: nonlocal keywork
 But backward compatibility is lost.  It would be very helpful
 if this was available on py2.x.

Python 2.x is no longer being developed. It won't be gaining features
like this. Use the nonlocal feature as a reason for migrating to
Python 3 :)

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


Re: proposal: bring nonlocal to py2.x

2014-01-13 Thread Mark Lawrence

On 13/01/2014 15:12, Giampaolo Rodola' wrote:


On Mon, Jan 13, 2014 at 3:47 PM, Neal Becker ndbeck...@gmail.com
mailto:ndbeck...@gmail.com wrote:

py3 includes a fairly compelling feature: nonlocal keywork
But backward compatibility is lost.  It would be very helpful
if this was available on py2.x.

It's not gonna happens as per PEP-404:
http://www.python.org/dev/peps/pep-0404/



But it could theoretically happen if Neal wants it so badly that he 
raises an issue on the bug tracker against Python 2.7, finds all the 
relevant source code in Python 3, back ports it, modifies all the 
relevant docs and unit tests, then finds some warm hearted person to 
commit the changes.  Five minute job.  Simples :)


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


Mark Lawrence

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


Re: proposal: bring nonlocal to py2.x

2014-01-13 Thread Mark Lawrence

On 13/01/2014 15:28, Chris Angelico wrote:

On Tue, Jan 14, 2014 at 2:24 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:

But it could theoretically happen if Neal wants it so badly that he raises
an issue on the bug tracker against Python 2.7, finds all the relevant
source code in Python 3, back ports it, modifies all the relevant docs and
unit tests, then finds some warm hearted person to commit the changes.  Five
minute job.  Simples :)


It's even worse than that, because adding 'nonlocal' is not a bugfix.
So to be committed to the repo, it has to be approved for either 2.7
branch (which is in bugfix-only maintenance mode) or 2.8 branch (which
does not exist). Good luck. :)

ChrisA



Then target the 2.8 fork that will take place if there's no agreement 
over PEP 460.  Still a five minute job, still simples :)


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


Mark Lawrence

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


Re: proposal: bring nonlocal to py2.x

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 2:24 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:
 But it could theoretically happen if Neal wants it so badly that he raises
 an issue on the bug tracker against Python 2.7, finds all the relevant
 source code in Python 3, back ports it, modifies all the relevant docs and
 unit tests, then finds some warm hearted person to commit the changes.  Five
 minute job.  Simples :)

It's even worse than that, because adding 'nonlocal' is not a bugfix.
So to be committed to the repo, it has to be approved for either 2.7
branch (which is in bugfix-only maintenance mode) or 2.8 branch (which
does not exist). Good luck. :)

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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread Michael Torrie
On 01/13/2014 02:54 AM, wxjmfa...@gmail.com wrote:
 Not at all. I'm afraid I'm understanding Python (on this
 aspect very well).

Are you sure about that?  Seems to me you're still confused as to the
difference between unicode and encodings.

 
 Do you belong to this group of people who are naively
 writing wrong Python code (usually not properly working)
 during more than a decade?
 
 'ß' is the the fourth character in that text Straße
 (base index 0).
 
 This assertions are correct (byte string and unicode).

How can they be?  They only are true for the default encoding and
character set you are using, which happens to have 'ß' as a single byte.
 Hence your little python 2.7 snippet is not using unicode at all, in
any form.  It's using a non-unicode character set.  There are methods
which can decode your character set to unicode and encode from unicode.
 But let's be clear.  Your byte streams are not unicode!

If the default byte encoding is UTF-8, which is a variable number of
bytes per character, your assertions are completely wrong.  Maybe it's
time you stopped programming in Windows and use OS X or Linux which
throw out the random single-byte character sets and instead provide a
UTF-8 terminal environment to support non-latin characters.

 
 sys.version
 '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
 assert 'Straße'[4] == 'ß'
 assert u'Straße'[4] == u'ß'

 
 jmf
 
 PS Nothing to do with Py2/Py3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem writing some strings (UnicodeEncodeError)

2014-01-13 Thread Paulo da Silva
Em 13-01-2014 08:58, Peter Otten escreveu:
 Peter Otten wrote:
 
 Paulo da Silva wrote:

 Em 12-01-2014 20:29, Peter Otten escreveu:
 Paulo da Silva wrote:

 but I have not tried it myself. Also, some bytes may need to be
 escaped, either to be understood by the shell, or to address security
 concerns:


 Since I am puting the file names between , the only char that needs
 to be escaped is the  itself.

 What about the escape char?

 Just this fn=fn.replace('','\\')

 So far I didn't find any problem, but the script is still running.

 To be a bit more explicit:

 for filename in os.listdir():
 ... print(template.replace(fn, filename.replace('', '\\')))
 ...
 ls \\; rm whatever; ls \
 
 The complete session:
 
 import os
 template = 'ls fn'
 with open('\\; rm whatever; ls \\', w) as f: pass
 ... 
 for filename in os.listdir():
 ... print(template.replace(fn, filename.replace('', '\\')))
 ... 
 ls \\; rm whatever; ls \
 
 
 Shell variable substitution is another problem. c.l.py is probably not the 
 best place to get the complete list of possibilities.
I see what you mean.
This is a tedious problem. Don't know if there is a simple solution in
python for this. I have to think about it ...
On a more general and serious application I would not produce a bash
script. I would do all the work in python.

That's not the case, however. This is a few times execution script for a
very special purpose. The only problem was the occurrence of some
Portuguese characters in old filenames encoded in another code than
utf-8. Very few also include the .

The worst thing that could happen was the bash script to abort. Then it
would be easy to fix it using a simple editor.

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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread wxjmfauth
Le lundi 13 janvier 2014 11:57:28 UTC+1, Chris Angelico a écrit :
 On Mon, Jan 13, 2014 at 9:38 PM, Steven D'Aprano
 
 steve+comp.lang.pyt...@pearwood.info wrote:
 
  I think you are using from __future__ import unicode_literals.
 
  Otherwise, that cannot happen in Python 2.x.
 
 
 
 
 
 Alas, not true.
 
 
 
  sys.version
 
 '2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]'
 
  sys.maxunicode
 
 65535
 
  assert 'Straße'[4] == 'ß'
 
  list('Straße')
 
 ['S', 't', 'r', 'a', '\xdf', 'e']
 
 
 
 That's Windows XP. Presumably Latin-1 (or CP-1252, they both have that
 
 char at 0xDF). He happens to be correct, *as long as the source code
 
 encoding matches the output encoding and is one that uses 0xDF to mean
 
 U+00DF*. Otherwise, he's not.
 
 

You are right. It's on Windows. It is only showing how
Python can be a holy mess.

The funny aspect is when I'm reading  *YOUR* assertions
are false when I'm presenting *PYTHON* assertions!

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


Code review?

2014-01-13 Thread Adam
Hey all.  New to the list.  I’m working on a web app with 2.6 and Flask.  I’m 
still relatively new to python.  Is there a chance to get a code review from 
anyone?  I really want someone to just tear up my code and tell me how to 
increase my efficiency and what I’m doing wrong (and how to upload images via a 
form in Flask, but that’s another story).

Happy coding
Adam
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Code review?

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 3:29 AM, Adam sk82...@gmail.com wrote:
 Hey all.  New to the list.  I’m working on a web app with 2.6 and Flask.  I’m 
 still relatively new to python.  Is there a chance to get a code review from 
 anyone?  I really want someone to just tear up my code and tell me how to 
 increase my efficiency and what I’m doing wrong (and how to upload images via 
 a form in Flask, but that’s another story).


Definitely! Preferably, post your code in-line; if it's too long for
that, post it someplace else and link to it. Be sure not to damage
indentation, of course, but no matter how new you are to Python you'll
know that!

Incidentally, is there a reason you're using Python 2.6? You should be
able to upgrade at least to 2.7, and Flask ought to work fine on 3.3
(the current stable Python). If it's the beginning of your project,
and you have nothing binding you to Python 2, go with Python 3.
Converting a small project now will save you the job of converting a
big project in ten years' time :)

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


Re: How to get Mac address of ethernet port?

2014-01-13 Thread William Ray Wing
On Jan 11, 2014, at 11:34 AM, Michael Torrie torr...@gmail.com wrote:

 On 01/11/2014 07:35 AM, Andriy Kornatskyy wrote:
 Sam,
 
 How about this?
 
 from uuid import getnode as get_mac
 '%012x' % get_mac()
 
 This seems to work if you have only one ethernet adapter.  Most
 computers have two (wired and wireless) adapters.
 
 Getting a mac address is platform-specific, and the OP has not specified
 what OS he is using.
 
 On Windows I imagine you'd have to access the WMI subsystem in Windows.
 
 On Linux you could access the /sys/devices/virtual/net/interface name
 file in the sysfs filesystem.  I'm sure there are other ways.
 
 No idea on OS X.
 -- 
 https://mail.python.org/mailman/listinfo/python-list

There are probably several ways in OS-X, just as there are in any other UNIX 
system.  The one I've used is to spawn a subprocess and run the ifconfig 
command with no arguments (which doesn't require any special privileges).  This 
will return a string of all the network interfaces (including the loopback and 
firewire interfaces in addition to Ethernet and WiFi) and their config specs.  
The OP would then parse this string looking for the location of the phrase 
status: active and then back up to the mac address that precedes it.  More 
work than using uuid, but this guarantees a current and correct answer.

 import string
 import subprocess
 mac_result = subprocess.Popen(['ifconfig'], stderr = subprocess.PIPE, 
 stdout = subprocess.PIPE).communicate()[0]
 mac_loc = string.find(mac_result, status: active)

...and so on.

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


Re: How to get Mac address of ethernet port?

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 2:42 AM, William Ray Wing w...@mac.com wrote:
 The one I've used is to spawn a subprocess and run the ifconfig command 
 with no arguments (which doesn't require any special privileges).

Very small caveat: On some systems, running ifconfig doesn't require
privileges, but it's not in the unprivileged user's default path (it's
in root's path though). I've seen this on Debian Linux, for instance.
So you may need to explicitly call /sbin/ifconfig or whereever it's
stored.

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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread Mark Lawrence

On 13/01/2014 16:24, wxjmfa...@gmail.com wrote:


You are right. It's on Windows. It is only showing how
Python can be a holy mess.



Regarding unicode Python 2 was a holy mess, fixed in Python 3.

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


Mark Lawrence

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


Re: Problem writing some strings (UnicodeEncodeError)

2014-01-13 Thread Peter Otten
Paulo da Silva wrote:

 Em 13-01-2014 08:58, Peter Otten escreveu:
 Peter Otten wrote:
 
 Paulo da Silva wrote:

 Em 12-01-2014 20:29, Peter Otten escreveu:
 Paulo da Silva wrote:

 but I have not tried it myself. Also, some bytes may need to be
 escaped, either to be understood by the shell, or to address
 security concerns:


 Since I am puting the file names between , the only char that needs
 to be escaped is the  itself.

 What about the escape char?

 Just this fn=fn.replace('','\\')

 So far I didn't find any problem, but the script is still running.

 To be a bit more explicit:

 for filename in os.listdir():
 ... print(template.replace(fn, filename.replace('', '\\')))
 ...
 ls \\; rm whatever; ls \
 
 The complete session:
 
 import os
 template = 'ls fn'
 with open('\\; rm whatever; ls \\', w) as f: pass
 ...
 for filename in os.listdir():
 ... print(template.replace(fn, filename.replace('', '\\')))
 ...
 ls \\; rm whatever; ls \
 
 
 Shell variable substitution is another problem. c.l.py is probably not
 the best place to get the complete list of possibilities.
 I see what you mean.
 This is a tedious problem. Don't know if there is a simple solution in
 python for this. I have to think about it ...
 On a more general and serious application I would not produce a bash
 script. I would do all the work in python.
 
 That's not the case, however. This is a few times execution script for a
 very special purpose. The only problem was the occurrence of some
 Portuguese characters in old filenames encoded in another code than
 utf-8. Very few also include the .
 
 The worst thing that could happen was the bash script to abort. Then it
 would be easy to fix it using a simple editor.

I looked around in the stdlib and found shlex.quote(). It uses ' instead of 
 which simplifies things, and special-cases only ':

 print(shlex.quote(alpha'beta))
'alpha'''beta'

So the answer is simpler than I had expected.


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


Re: plotting slows down

2014-01-13 Thread Ian Kelly
On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel da...@davea.name wrote:
 Next, please repost any source code with indentation preserved.
  Your message shows it all flushed to the left margin,  probably
  due to posting in html mode. Use text mode here.

That's odd, the message that I got includes proper indentation and is
plain text, not html.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel da...@davea.name wrote:
 Next, please repost any source code with indentation preserved.
  Your message shows it all flushed to the left margin,  probably
  due to posting in html mode. Use text mode here.

 That's odd, the message that I got includes proper indentation and is
 plain text, not html.

Also what I saw. Dave, do you get the newsgroup or the mailing list? I
get the mailing list - it's possible the HTML version got stripped by
Mailman.

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


Re: plotting slows down

2014-01-13 Thread Dave Angel
 Chris Angelico ros...@gmail.com Wrote in message:
 On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel da...@davea.name wrote:
 Next, please repost any source code with indentation preserved.
  Your message shows it all flushed to the left margin,  probably
  due to posting in html mode. Use text mode here.

 That's odd, the message that I got includes proper indentation and is
 plain text, not html.
 
 Also what I saw. Dave, do you get the newsgroup or the mailing list? I
 get the mailing list - it's possible the HTML version got stripped by
 Mailman.
 

I'm using gmane newsgroup, and recently switched to the Android
 Newsgroup Reader. Previously was using Groundhog, which seemed to
 eat the body of any message containing an html part. (Though
 strangely it showed the footer in the tutor newsgroup). This one
 was mentioned byAlan, and she far has seemed much
 better.

-- 
DaveA



Android NewsGroup Reader
http://www.piaohong.tk/newsgroup

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


Re: plotting slows down

2014-01-13 Thread Ian Kelly
On Mon, Jan 13, 2014 at 1:15 AM,  norman.elli...@gmail.com wrote:
 First let me say I have not done much python programming!
 I am running Python 2.7.3.
 I am trying to use python as a front end to a simple oscilloscope.
 Ultimately I intend to use it with my micropython board.

 At the moment I am just developing it. All it does is use a module I found 
 called graphics.py to create a window and display randomly generated data.

 Each time it goes through the outer loop it gets slower and slower.
 I put in a small delay just so I could observe what is happening and for the 
 first line it draws it takes about a second. If I set it to loop 20 times the 
 final loop takes more than 6 seconds.
 Can anyone explain what I am doing wrong please?

I wager the problem is in the range(1, xpos) inner loop.  Each time
this runs the win.plot() call adds a 1-pixel line to the underlying Tk
canvas.  These 1-pixel lines are never deleted, so they accumulate
over each outer loop.  Every time a new object is drawn, the canvas
has to process all of the lines that have been drawn in order to
redraw itself, and so it gets slower and slower.

One simple fix you might try to improve the rendering efficiency is to
disable the autoflush option documented here:

http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node14.html

And then call the module-level update() function after each iteration
of the outer loop to force things to redraw.  In order to
realistically use this module for animation it looks like you will at
some point need to keep the number of graphics objects under some
constant.  To do this you could either reuse the existing objects by
calling their move method to reposition them as needed, or simply
remove them from the plot with the undraw method and draw new
objects in their place.  See:

http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node3.html

If this still isn't fast enough for the number of objects you're
drawing, then you may just need to find a new drawing package, as this
one appears to be designed for teaching rather than efficiency.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: efficient way to process data

2014-01-13 Thread Larry Martell
On Mon, Jan 13, 2014 at 1:09 AM, Chris Angelico ros...@gmail.com wrote:
 On Mon, Jan 13, 2014 at 2:35 PM, Larry Martell larry.mart...@gmail.com 
 wrote:
 Thanks for the reply. I'm going to take a stab at removing the group
 by and doing it all in python. It doesn't look too hard, but I don't
 know how it will perform.

 Well, if you can't switch to PostgreSQL or such, then doing it in
 Python is your only option. There are such things as GiST and GIN
 indexes that might be able to do some of this magic, but I don't think
 MySQL has anything even remotely like what you're looking for.

 So ultimately, you're going to have to do your filtering on the
 database, and then all the aggregation in Python. And it's going to be
 somewhat complicated code, too. Best I can think of is this, as
 partial pseudo-code:

 last_x = -999
 x_map = []; y_map = {}
 merge_me = []
 for x,y,e in (SELECT x,y,e FROM t WHERE whatever ORDER BY x):
 if xlast_x+1:
 x_map[-1].append((y,e))
 else:
 x_map.append([(y,e)])
 last_x=x
 if y in y_map:
 merge_me.append((y_map[y], x_map[-1]))
 y_map[y]=x_map[-1]

 # At this point, you have x_map which is a list of lists, each one
 # being one group, and y_map which maps a y value to its x_map list.

 last_y = -999
 for y in sorted(y_map.keys()):
 if ylast_y+1:
 merge_me.append((y_map[y], last_x_map))
 last_y=y
 last_x_map=y_map[y]

 for merge1,merge2 in merge_me:
 merge1.extend(merge2)
 merge2[:]=[] # Empty out the list

 for lst in x_map:
 if not lst: continue # been emptied out, ignore it
 do aggregate stats, get sum(lst) and whatever else

 I think this should be linear complexity overall, but there may be a
 few aspects of it that are quadratic. It's a tad messy though, and
 completely untested. But that's an algorithmic start. The idea is that
 lists get collected based on x proximity, and then lists get merged
 based on y proximity. That is, if you have (1.0, 10.1), (1.5, 2.3),
 (3.0, 11.0), (3.2, 15.2), they'll all be treated as a single
 aggregation unit. If that's not what you want, I'm not sure how to
 handle it.

Thanks. Unfortunately this has been made a low priority task and I've
been put on to something else (I hate when they do that). I'll revive
this thread when I'm allowed to get back on this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: efficient way to process data

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell larry.mart...@gmail.com wrote:
 Thanks. Unfortunately this has been made a low priority task and I've
 been put on to something else (I hate when they do that).

Ugh, I know that feeling all too well! Life's better when you're
unemployed, and you can choose the interesting problems to work on.
Apart from the has to be in MySQL restriction (dodged now that the
work's all being done in Python anyway), yours is _definitely_ an
interesting problem.

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


Re: plotting slows down

2014-01-13 Thread Norman Elliott
On Monday, 13 January 2014 18:05:52 UTC, Dave Angel  wrote:
 Chris Angelico  Wrote in message:
 


Well Ian's suggestion has really done the job. Now each iteration takes just 
0.14 seconds now.
changed to:
[code]
win = GraphWin(My Circle, xpos, ypos, autoflush=False)
[/code]

and added 
[code]
update()
[/code]

immediately after the line
[code]
for y in range(1,12):
[/code]

previously the first iteration took 0.48 seconds and the the 10th 4.76
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: efficient way to process data

2014-01-13 Thread Mark Lawrence

On 13/01/2014 18:32, Chris Angelico wrote:

On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell larry.mart...@gmail.com wrote:

Thanks. Unfortunately this has been made a low priority task and I've
been put on to something else (I hate when they do that).


Ugh, I know that feeling all too well! Life's better when you're
unemployed, and you can choose the interesting problems to work on.


No it ain't :(

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


Mark Lawrence

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


Re: efficient way to process data

2014-01-13 Thread Mark Lawrence

On 13/01/2014 18:27, Larry Martell wrote:

On Mon, Jan 13, 2014 at 1:09 AM, Chris Angelico ros...@gmail.com wrote:

On Mon, Jan 13, 2014 at 2:35 PM, Larry Martell larry.mart...@gmail.com wrote:

Thanks for the reply. I'm going to take a stab at removing the group
by and doing it all in python. It doesn't look too hard, but I don't
know how it will perform.


Well, if you can't switch to PostgreSQL or such, then doing it in
Python is your only option. There are such things as GiST and GIN
indexes that might be able to do some of this magic, but I don't think
MySQL has anything even remotely like what you're looking for.

So ultimately, you're going to have to do your filtering on the
database, and then all the aggregation in Python. And it's going to be
somewhat complicated code, too. Best I can think of is this, as
partial pseudo-code:

last_x = -999
x_map = []; y_map = {}
merge_me = []
for x,y,e in (SELECT x,y,e FROM t WHERE whatever ORDER BY x):
 if xlast_x+1:
 x_map[-1].append((y,e))
 else:
 x_map.append([(y,e)])
 last_x=x
 if y in y_map:
 merge_me.append((y_map[y], x_map[-1]))
 y_map[y]=x_map[-1]

# At this point, you have x_map which is a list of lists, each one
# being one group, and y_map which maps a y value to its x_map list.

last_y = -999
for y in sorted(y_map.keys()):
 if ylast_y+1:
 merge_me.append((y_map[y], last_x_map))
 last_y=y
 last_x_map=y_map[y]

for merge1,merge2 in merge_me:
 merge1.extend(merge2)
 merge2[:]=[] # Empty out the list

for lst in x_map:
 if not lst: continue # been emptied out, ignore it
 do aggregate stats, get sum(lst) and whatever else

I think this should be linear complexity overall, but there may be a
few aspects of it that are quadratic. It's a tad messy though, and
completely untested. But that's an algorithmic start. The idea is that
lists get collected based on x proximity, and then lists get merged
based on y proximity. That is, if you have (1.0, 10.1), (1.5, 2.3),
(3.0, 11.0), (3.2, 15.2), they'll all be treated as a single
aggregation unit. If that's not what you want, I'm not sure how to
handle it.


Thanks. Unfortunately this has been made a low priority task and I've
been put on to something else (I hate when they do that). I'll revive
this thread when I'm allowed to get back on this.



I've not followed this thread closely but would this help 
http://pandas.pydata.org/ ?  When and if you get back to it, that is!!!


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


Mark Lawrence

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


Re: 'Straße' ('Strasse') and Python 2

2014-01-13 Thread Thomas Rachel

Am 13.01.2014 10:54 schrieb wxjmfa...@gmail.com:


Not at all. I'm afraid I'm understanding Python (on this
aspect very well).


IBTD.


Do you belong to this group of people who are naively
writing wrong Python code (usually not properly working)
during more than a decade?


Why should I be?


'ß' is the the fourth character in that text Straße
(base index 0).


Character-wise, yes. But not byte-string-wise. In a byte string, this 
depends on the character set used.


On CP 437, 850, 12xx (whatever Windows uses) or latin1, you are right, 
but not on the widely used UTF8.



sys.version

'2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'

assert 'Straße'[4] == 'ß'
assert u'Straße'[4] == u'ß'


Linux box at home:

Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
Type help, copyright, credits or license for more information.
 assert 'Straße'[4] == 'ß'
Traceback (most recent call last):
  File stdin, line 1, in module
AssertionError
 assert u'Straße'[4] == u'ß'

Python 3.3.0 (default, Oct 01 2012, 09:13:30) [GCC] on linux
Type help, copyright, credits or license for more information.
 assert 'Straße'[4] == 'ß'
 assert u'Straße'[4] == u'ß'

Windows box at work:

Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit 
(AMD64)] on win32

Type help, copyright, credits or license for more information.
 assert 'Straße'[4] == 'ß'
 assert u'Straße'[4] == u'ß'


PS Nothing to do with Py2/Py3.


As bytes and unicode and str stuff is heavily changed between them, of 
course it has to do.


And I think you know that and try to confuse and FUD us all - with no avail.


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


Re: Problem writing some strings (UnicodeEncodeError)

2014-01-13 Thread Paulo da Silva
Em 13-01-2014 17:29, Peter Otten escreveu:
 Paulo da Silva wrote:
 
 Em 13-01-2014 08:58, Peter Otten escreveu:

 
 I looked around in the stdlib and found shlex.quote(). It uses ' instead of 
  which simplifies things, and special-cases only ':
 
 print(shlex.quote(alpha'beta))
 'alpha'''beta'
 
 So the answer is simpler than I had expected.
 
Yes, it should work, at least in this case.
Although python oriented, it seems to work to bash also.
I need to remove the  from the templates and use shlex.quote for
filenames. I'll give it a try.

Thanks

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


Tkinter GUI Error

2014-01-13 Thread fluttershy363

Inside the function is where I am having the problem, I am trying to get it to 
delete the label so that it may then replace it with a shorter text.
Here is the full code:




from tkinter import *
import random
main = Tk()
main.title(Crack the Code)

def check1():
entry = entry1var.get()
if entry == num1:
labelent1.destroy()
labelent1 = Label(main, text=Correct!,fg=green).grid(row = 0, 
column = 3)
elif entry  num1:
labelent1.destroy()
labelent1 = Label(main, text=Too Big,fg=red).grid(row = 0, column = 
3)
elif entry  num1:
labelent1.destroy()
labelent1 = Label(main, text=Too Small,fg=red).grid(row = 0, column 
= 3)




global num1
global num2
global num3
num1 =str(random.randint(10,99))
num2 =str(random.randint(10,99))
num3 =str(random.randint(10,99))
mastercode = num1+num2+num3


entry1var = StringVar()
entry2var = StringVar()
entry3var = StringVar()


number1 = Label(main, text=Number 1).grid(row = 0, column = 0)
number2 = Label(main, text=Number 2).grid(row = 1, column = 0)
number3 = Label(main, text=Number 3).grid(row = 2, column = 0)
entry1  = Entry(main, textvariable=entry1var).grid(row=0,column=1)
entry2  = Entry(main, textvariable=entry2var).grid(row=1,column=1)
entry3  = Entry(main, textvariable=entry3var).grid(row=2,column=1)
button1 = Button(main, text=Try Number,command=check1).grid(row=0,column=2)
button2 = Button(main, text=Try Number).grid(row=1,column=2)
button3 = Button(main, text=Try Number).grid(row=2,column=2)

labelent1 = Label(main, text=Waiting for Input).grid(row = 0, column = 3)
labelent2 = Label(main, text=Waiting for Input).grid(row = 1, column = 3)
labelent3 = Label(main, text=Waiting for Input).grid(row = 2, column = 3)



mastercodelabel= Label(main, text=Enter master code 
below:).grid(row=3,column=1)
mastercodeentry= Entry(main).grid(row=4,column=1)
mastercodebutton= Button(main,text=Enter).grid(row=4,column=2)




#main.config(menu=menubar)
main.mainloop()




And this is the error displayed when clicking on button1:

Exception in Tkinter callback
Traceback (most recent call last):
  File C:\Python33\lib\tkinter\__init__.py, line 1475, in __call__
return self.func(*args)
  File C:/Users/User/Desktop/Programming/Tkinter/Tkinter.py, line 15, in 
check1
labelent1.destroy()
UnboundLocalError: local variable 'labelent1' referenced before assignment


Thanks, Lewis.

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


Re: Tkinter GUI Error

2014-01-13 Thread Lewis Wood
Forgot to mention I am using Python 3.3.3
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter GUI Error

2014-01-13 Thread Christian Gollwitzer

Am 13.01.14 19:49, schrieb fluttershy...@gmail.com:


Inside the function is where I am having the problem, I am trying to get it to 
delete the label so that it may then replace it with a shorter text.
Here is the full code:




from tkinter import *
import random
main = Tk()
main.title(Crack the Code)

def check1():
 entry = entry1var.get()
 if entry == num1:
 labelent1.destroy()
 labelent1 = Label(main, text=Correct!,fg=green).grid(row = 0, 
column = 3)


This is the wrong way to do it. Yes, in principle you could remove the 
label and put a new one there; but it's much better to just change the 
text of it by means of either


labelent1.configure(text=New text )

or by linking a variable with the label variable at the setup time
somestringvar = StringVar(initial text)
Label(main, textvariable=somestringvar)

and then change that variable
somestringvar.set(New text)

Both of these don't solve the error, though; it has nothing to do with 
Tk, you just did not make labelent1 global. However, I strongly advise 
to use an object for the entire window, where you make this labelent1 an 
instance variable (put into self).


Christian


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


Re: Tkinter GUI Error

2014-01-13 Thread Lewis Wood
When I try to use the labelent1.configure, it greets me with an error:
AttributeError: 'NoneType' object has no attribute 'configure'

I changed the labelent's to global. Don't suppose you know why?
Also how would I go about using an object for the entire window. I am still a 
Novice at Tkinter and Python but can make my way around it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter GUI Error

2014-01-13 Thread Peter Otten
fluttershy...@gmail.com wrote:

 Inside the function is where I am having the problem, I am trying to get
 it to delete the label so that it may then replace it with a shorter text.
 Here is the full code:

 def check1():
 entry = entry1var.get()
 if entry == num1:
 labelent1.destroy()
 labelent1 = Label(main, text=Correct!,fg=green).grid(row = 0,
 column = 3)
 elif entry  num1:
 labelent1.destroy()
 labelent1 = Label(main, text=Too Big,fg=red).grid(row = 0,
 column = 3)
 elif entry  num1:
 labelent1.destroy()
 labelent1 = Label(main, text=Too Small,fg=red).grid(row = 0,
 column = 3)

 And this is the error displayed when clicking on button1:
 
 Exception in Tkinter callback
 Traceback (most recent call last):
   File C:\Python33\lib\tkinter\__init__.py, line 1475, in __call__
 return self.func(*args)
   File C:/Users/User/Desktop/Programming/Tkinter/Tkinter.py, line 15, in
   check1
 labelent1.destroy()
 UnboundLocalError: local variable 'labelent1' referenced before assignment
 
 
 Thanks, Lewis.

Kudos, your problem description is very clear!

Your post would be perfect, had you reduced the number of Labels from three 
to one ;)

The error you are seeing has nothing to do with the GUI. When you assign to 
a name inside a function Python determines that the name is local to that 
function. A minimal example that produces the same error is

 a = global
 def test():
... print(a)
... a = local
... 
 test()
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 2, in test
UnboundLocalError: local variable 'a' referenced before assignment

The name `a` passed to print() references the local `a` which is not yet 
defined. A possible fix is to tell Python to reference the global `a`

 a = global
 def test():
... global a
... print(a)
... a = local
... 
 test()
global
 a
'local'

However, in the case of your GUI code you should not destroy and create 
Label instances -- it is more efficient (and easier I think) to modify the 
Label's text:

(1) working demo with 'global' -- don't do it that way:

from tkinter import *

main = Tk()

def check1():
global labelent1
labelent1.destroy()
labelent1 = Label(main, text=Correct!, fg=green)
labelent1.grid(row = 0, column = 3) # must be a separate statement as
# grid() returns None

Button(main, text=Try Number, command=check1).grid(row=0, column=2)
labelent1 = Label(main, text=Waiting for Input)
labelent1.grid(row=0, column=3) # must be a separate statement as 
# grid() returns None

main.mainloop()


(2) The way to go, modify the label text instead of replacing it:

from tkinter import *

main = Tk()

def check1():
labelent1.configure(text=Correct!, fg=green)

Button(main, text=Try Number, command=check1).grid(row=0, column=2)
labelent1 = Label(main, text=Waiting for Input)
labelent1.grid(row=0, column=3)

main.mainloop()

 global num1

By the way, global declarations on the module level have no effect.


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


Re: efficient way to process data

2014-01-13 Thread Larry Martell
On Mon, Jan 13, 2014 at 1:32 PM, Chris Angelico ros...@gmail.com wrote:
 On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell larry.mart...@gmail.com 
 wrote:
 Thanks. Unfortunately this has been made a low priority task and I've
 been put on to something else (I hate when they do that).

 Ugh, I know that feeling all too well!

Right? You're deep in debugging and researching and waking up in the
middle of the night with potential solutions, and then they say put it
aside. It's so hard to put it down, and then when you pick it up later
(sometimes months) you're like WTF is this all about. I recently
picked up something I had to put down in September - spent an entire
day getting back to where I was, then it was put on the back burner
again.

 Life's better when you're
 unemployed, and you can choose the interesting problems to work on.

Ahhh  I don't think so.

 Apart from the has to be in MySQL restriction (dodged now that the
 work's all being done in Python anyway),

It's a big existing django app.

 yours is _definitely_ an
 interesting problem.

Thanks! I thought so too.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: L[:]

2014-01-13 Thread Terry Reedy

On 1/13/2014 4:00 AM, Laszlo Nagy wrote:



Unless L is aliased, this is silly code.

There is another use case. If you intend to modify a list within a for
loop that goes over the same list, then you need to iterate over a copy.
And this cannot be called an alias because it has no name:


for i in somelist: creates a second reference to somelist that somewhere 
in the loop code has a name, so it is effectively an 'alias'. The 
essential point is that there are two access paths to the same object.



for idx,item in enumerate(L[:]):
# do something with L here, including modification


The copy is only needed in the above if one inserts or deletes. But if 
one inserts or deletes more than one item, one nearly always does better 
to iterate through the original and construct a new list with new items 
added and old items not copied.


--
Terry Jan Reedy

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


Re:plotting slows down

2014-01-13 Thread Steven D'Aprano
On Mon, 13 Jan 2014 08:26:11 -0500, Dave Angel wrote:

 norman.elli...@gmail.com Wrote in message:

 [code]
 #!/usr/bin/python
 from graphics import *
 
 First things first. what operating system are you using,  and
  where did you get the mysterious graphics. py?  Thanks for telling us
  python 2.7.3
 
 Next, please repost any source code with indentation preserved.

He did. If you look at the original message as posted to python-
l...@python.org and comp.lang.python, e.g. here:

https://mail.python.org/pipermail/python-list/2014-January/664430.html

you will see that the message is correctly indented with tabs.

  Your message shows it all flushed to the left margin,  probably due to
  posting in html mode. Use text mode here.

Looks like perhaps Gmane is stripping tabs from their mirror. You should 
report that as a bug to them.



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


Re: Code review?

2014-01-13 Thread Steven D'Aprano
On Tue, 14 Jan 2014 03:40:25 +1100, Chris Angelico wrote:

 Incidentally, is there a reason you're using Python 2.6? You should be
 able to upgrade at least to 2.7, and Flask ought to work fine on 3.3
 (the current stable Python). If it's the beginning of your project, and
 you have nothing binding you to Python 2, go with Python 3. Converting a
 small project now will save you the job of converting a big project in
 ten years' time

Everything you say is correct, but remember that there is a rather large 
ecosystem of people writing code to run on servers where the supported 
version of Python is 2.6, 2.5, 2.4 and even 2.3. RedHat, for example, 
still has at least one version of RHEL still under commercial support 
where the system Python is 2.3, at least that was the case a few months 
back, it may have reached end-of-life by now. But 2.4 will definitely 
still be under support.

(I don't believe there is any mainstream Linux distro still supporting 
versions older than 2.3.)

Not everyone is willing, permitted or able to install Python other than 
that which their OS provides, and we ought to respect that.

Hell, if somebody wants to ask questions about Python 1.5, we can answer 
them! The core language is still recognisably Python, a surprisingly 
large number of libraries were around back then (it was Python 1.4 or 1.5 
which first got the reputation of batteries included), and I for one 
still have it installed so I can even test code for it.


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


Re: efficient way to process data

2014-01-13 Thread Petite Abeille

On Jan 13, 2014, at 7:42 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:

 I've not followed this thread closely but would this help 
 http://pandas.pydata.org/ ?  When and if you get back to it, that is!!!

I doubt it. The mean overhead by far would be to shuffle pointless data between 
the server  client. Best to process data closest to their source.

On the other hand:

http://devour.com/video/never-say-no-to-panda/



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


Re: proposal: bring nonlocal to py2.x

2014-01-13 Thread Terry Reedy

On 1/13/2014 9:47 AM, Neal Becker wrote:

py3 includes a fairly compelling feature: nonlocal keywork

[keyword]

But backward compatibility is lost.


I am not sure what your particular point is. Every new feature, in any 
release, if used, makes code not compatible with earlier releases that 
do not have the feature. Every new feature is compelling to someone, and 
to use it, one must use a version that has it.



It would be very helpful if this was available on py2.x.


For every new feature, there is someone who thinks it would be helpful 
if it were availale in an earlier version. Backports of library features 
are sometimes available on PyPI, but this cannot be done for syntax 
features like 'nonlocal'.


'2.x' refers to a sequence of feature-frozen versions. It literally 
means '2.0 to 2.7', but may refer to '2.2 to 2.7' (because 2.2 gained 
new classes and iterators) or even a more restricted sequence. Core 
developers consider 3.2, or maybe a later version, to be the successor 
of 2.7.


--
Terry Jan Reedy

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


Re: plotting slows down

2014-01-13 Thread Terry Reedy

On 1/13/2014 12:45 PM, Chris Angelico wrote:

On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly ian.g.ke...@gmail.com wrote:

On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel da...@davea.name wrote:

Next, please repost any source code with indentation preserved.
  Your message shows it all flushed to the left margin,  probably
  due to posting in html mode. Use text mode here.


That's odd, the message that I got includes proper indentation and is
plain text, not html.


Also what I saw. Dave, do you get the newsgroup or the mailing list? I
get the mailing list - it's possible the HTML version got stripped by
Mailman.


I am reading via gmane. Viewing the source, there is no html.
BUT, indents are with tabs, not spaces. Some readers just delete tabs, 
as there is no standard for conversion to spaces, especially with 
proportional fonts. Thunderbird used to do this, but now uses tab stops 
every 8 spaces (maybe because a switched to a fixed font?) This means 
that the first tab gives an indent 8 chars in the original post, 6 in 
the first quotation, and, I presume, 4 in a second quotation, etc. It 
works better to post code with space indents.


--
Terry Jan Reedy

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


Mistake or Troll (was Re: 'Straße' ('Strasse') and Python 2)

2014-01-13 Thread Terry Reedy

On 1/13/2014 4:54 AM, wxjmfa...@gmail.com wrote:


I'm afraid I'm understanding Python (on this
aspect very well).


Really?


Do you belong to this group of people who are naively
writing wrong Python code (usually not properly working)
during more than a decade?


To me, the important question is whether this and previous similar posts 
are intentional trolls designed to stir up the flurry of responses they 
get or 'innocently' misleading or even erroneous. If your claim of 
understanding Python and Unicode is true, then this must be a troll 
post. Either way, please desist, or your access to python-list from 
google-groups may be removed.



'ß' is the the fourth character in that text Straße
(base index 0).


As others have said, in the *unicode text Straße, 'ß' is the fifth 
character, at character index 4, ...



This assertions are correct (byte string and unicode).


whereas, when the text is encoded into bytes, the byte index depends on 
the encoding and the assertion that it is always 4 is incorrect. Did you 
know this or were you truly ignorant?



sys.version

'2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'

assert 'Straße'[4] == 'ß'


Sometimes true, sometimes not.


assert u'Straße'[4] == u'ß'



PS Nothing to do with Py2/Py3.


This issue has everything to do with Py2, where 'Straße' is encoded 
bytes, versus Py3, where 'Straße' is unicode text where each character 
of that word takes one code unit, whether each is 2 bytes or 4 bytes.


If you replace 'ß' with any astral (non-BMP) character, this issue 
appears even for unicode text in 3.2-, where an astral character 
requires 2, not 1, code units on narrow builds, thereby screwing up 
indexing, just as can happen for encoded bytes. In 3.3+, all characters 
use 1 code unit and indexing (and slicing) always works properly. This 
is another unicode issue where you appear not to understand, but might 
just be trolling.


--
Terry Jan Reedy



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


Re: Code review?

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano st...@pearwood.info wrote:
 On Tue, 14 Jan 2014 03:40:25 +1100, Chris Angelico wrote:

 Incidentally, is there a reason you're using Python 2.6? You should be
 able to upgrade at least to 2.7, and Flask ought to work fine on 3.3
 (the current stable Python). If it's the beginning of your project, and
 you have nothing binding you to Python 2, go with Python 3. Converting a
 small project now will save you the job of converting a big project in
 ten years' time

 Everything you say is correct, but remember that there is a rather large
 ecosystem of people writing code to run on servers where the supported
 version of Python is 2.6, 2.5, 2.4 and even 2.3. RedHat, for example,
 still has at least one version of RHEL still under commercial support
 where the system Python is 2.3, at least that was the case a few months
 back, it may have reached end-of-life by now. But 2.4 will definitely
 still be under support.

Pledging that your app will run on the system Python of RHEL is
something that binds you to a particular set of versions of Python.
It's not just library support that does that.

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


Re: Tkinter GUI Error

2014-01-13 Thread Rick Johnson
On Monday, January 13, 2014 12:49:07 PM UTC-6, Lewis Wood wrote:
 labelent1 = Label(main, text=Correct!,fg=green).grid(row = 0, column = 3)
 
 [snip]
 
 UnboundLocalError: local variable 'labelent1' referenced before assignment

Observe the following interactive session and prepare to be enlightened.

## INCORRECT ##
py from Tkinter import *
py root = Tk()
py label = Label(root, text=Blah).pack()
py type(label)
type 'NoneType'

## CORRECT ##
py label = Label(root, text=Blah)
py label.pack()
py label
Tkinter.Label instance at 0x027C69B8
py type(label)
type 'instance'

## ANY QUESTIONS? ##
py help()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter GUI Error

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 5:49 AM,  fluttershy...@gmail.com wrote:
 entry = entry1var.get()
 if entry == num1:
 elif entry  num1:
 elif entry  num1:

 num1 =str(random.randint(10,99))
 num2 =str(random.randint(10,99))
 num3 =str(random.randint(10,99))
 mastercode = num1+num2+num3

Be careful of code like this. You've specified that your three parts
range from 10 through 99, so this will work as long as the user knows
this and enters exactly two digits. Doing inequality comparisons on
strings that represent numbers will work as long as they're the same
length, but if the lengths vary, the string comparisons will start at
the beginning - not what most people will expect. These are all true:

2  10
3.14159  2,000,000
42  Life, the universe, and everything
00012  12

If your intention is to have a six-digit number, you could simply ask
for one, and then format the pieces accordingly:

num = random.randint(1,99)
num_str = %06d % num

You can then slice up num_str as needed (it'll have leading zeroes if
it needs them), or you can do numerical comparisons against num
itself.

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


Re: Code review?

2014-01-13 Thread Bob Martin
in 714500 20140113 233415 Chris Angelico ros...@gmail.com wrote:
On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano st...@pearwood.info wrote:
 On Tue, 14 Jan 2014 03:40:25 +1100, Chris Angelico wrote:

 Incidentally, is there a reason you're using Python 2.6? You should be
 able to upgrade at least to 2.7, and Flask ought to work fine on 3.3
 (the current stable Python). If it's the beginning of your project, and
 you have nothing binding you to Python 2, go with Python 3. Converting a
 small project now will save you the job of converting a big project in
 ten years' time

 Everything you say is correct, but remember that there is a rather large
 ecosystem of people writing code to run on servers where the supported
 version of Python is 2.6, 2.5, 2.4 and even 2.3. RedHat, for example,
 still has at least one version of RHEL still under commercial support
 where the system Python is 2.3, at least that was the case a few months
 back, it may have reached end-of-life by now. But 2.4 will definitely
 still be under support.

Pledging that your app will run on the system Python of RHEL is
something that binds you to a particular set of versions of Python.
It's not just library support that does that.

Does any Linux distro ship with Python 3?  I haven't seen one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Code review?

2014-01-13 Thread Bayram Güçlü

On 14-01-2014 11:22, Bob Martin wrote:

in 714500 20140113 233415 Chris Angelico ros...@gmail.com wrote:

On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano st...@pearwood.info wrote:

On Tue, 14 Jan 2014 03:40:25 +1100, Chris Angelico wrote:


Incidentally, is there a reason you're using Python 2.6? You should be
able to upgrade at least to 2.7, and Flask ought to work fine on 3.3
(the current stable Python). If it's the beginning of your project, and
you have nothing binding you to Python 2, go with Python 3. Converting a
small project now will save you the job of converting a big project in
ten years' time


Everything you say is correct, but remember that there is a rather large
ecosystem of people writing code to run on servers where the supported
version of Python is 2.6, 2.5, 2.4 and even 2.3. RedHat, for example,
still has at least one version of RHEL still under commercial support
where the system Python is 2.3, at least that was the case a few months
back, it may have reached end-of-life by now. But 2.4 will definitely
still be under support.


Pledging that your app will run on the system Python of RHEL is
something that binds you to a particular set of versions of Python.
It's not just library support that does that.


Does any Linux distro ship with Python 3?  I haven't seen one.


Debian GNU/Linux

https://wiki.debian.org/Python/Python3.3
--
https://mail.python.org/mailman/listinfo/python-list


Re: Code review?

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 6:22 PM, Bob Martin bob.mar...@excite.com wrote:
 Does any Linux distro ship with Python 3?  I haven't seen one.

On most Debian-based distros, you can simply 'apt-get install
python3', and you'll get some 3.x version (in Debian Squeeze, that's
3.1, Debian Wheezy packages 3.2; Ubuntu since Raring gives you 3.3).
Whether or not you actually have it - or python2 for that matter -
installed depends on your choices, anything that depends on it will
pull it in or you can grab it manually.

Arch Linux ships 3.3.3 under the name python, and 2.7.6 under the
name python2 - an inversion of the Debian practice. Other distros
are looking toward shifting, too.

I'd guess that all mainstream distributions carry both branches. It's
just a question of what people get when they ask for Python in the
most normal way to do that.

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


Re: Python example source code

2014-01-13 Thread Koray YILMAZ
On Sunday, January 12, 2014 4:37:18 PM UTC+2, ngangsia akumbo wrote:
 where can i find example source code by topic?
 
 Any help please

Hi,

Take a look at https://github.com/dabeaz/python-cookbook. I am using NapCat 
mobile application to read codes.

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


[issue6625] UnicodeEncodeError on pydoc's CLI

2014-01-13 Thread Berker Peksag

Berker Peksag added the comment:

 I suppose this is a duplicate of #1065986.

Yes, it is. I created a test file from the tests in issue6625_pydoc.diff and 
ran it on the current 2.7 branch.

def foo():
ufooo bar
baz
\xfcnicode\u2026
return 42

def bar():
uf\xfcr Elise
return 11

--
nosy: +berker.peksag
resolution:  - out of date
stage: patch review - committed/rejected
status: open - closed

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



[issue1185124] pydoc doesn't find all module doc strings

2014-01-13 Thread Akira Kitada

Akira Kitada added the comment:

I tried pydoc_2.7.patch with the following test file and
found source_synopsis returns \x escaped string instead of \u escaped one.


# -*- coding: utf-8 -*-

uツ

class Spam(object):
uツ


 import utf8
 utf8.__doc__
u'\u30c4'
 print(utf8.__doc__)
ツ
 import pydoc
 pydoc.source_synopsis(file('utf8.py'))
u'\xe3\x83\x84'
 print pydoc.source_synopsis(file('utf8.py'))
ツ
 print pydoc.source_synopsis(file('utf8.py')).encode('latin-1')
ツ

--

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



[issue20237] Ambiguous sentence in document of xml package.

2014-01-13 Thread INADA Naoki

New submission from INADA Naoki:

http://docs.python.org/3.3/library/xml.html#defused-packages

The courses of action are recommended for any server code that parses 
untrusted XML data.

What this sentence means?
What The courses is?

--
assignee: docs@python
components: Documentation
messages: 208015
nosy: docs@python, naoki
priority: normal
severity: normal
status: open
title: Ambiguous sentence in document of xml package.
versions: Python 3.2, Python 3.3, Python 3.4

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



[issue20229] platform.py uses deprecated feature of plistlib

2014-01-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

There is no need to indent any except the pl = plistlib.load(f) line.

--
nosy: +serhiy.storchaka

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



[issue20238] Incomplete gzip output with tarfile.open(fileobj=..., mode=w:gz)

2014-01-13 Thread Martin Panter

New submission from Martin Panter:

I am trying to create a tar file after opening it as a temporary file, and it 
seems to be writing truncated output when I use mode=w:gz. My workaround 
looks like it will be to use mode=w|gz instead. It’s not clear what the 
difference is: am I losing anything practical by disallowing “random” seeking?

Simplified demonstration:

 from io import BytesIO; b = BytesIO()
 import tarfile; t = tarfile.open(fileobj=b, mode=w:gz)
 t._extfileobj
True
 type(t.fileobj)
class 'gzip.GzipFile'
 t.close()
 b.getvalue()
b'\x1f\x8b\x08\x00]\xb8\xd3R\x02\xff'
 del t
 b.getvalue()
b\x1f\x8b\x08\x00]\xb8\xd3R\x02\xff\xed\xc1\x01\r\x00\x00\x00\xc2\xa0\xf7Om\x0e7\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x807\x03\x9a\xde\x1d'\x00(\x00\x00

Looking at the code, the TarFile.close() method would not be closing the 
GzipFile object because of this condition:

if not self._extfileobj:
self.fileobj.close()

Perhaps it needs to also check if file compression is being used or something; 
I’m not familiar with the internals.

I did notice that the bug happens with Python 3.3.3 and 3.2.3, but not 2.7.5. 
Also, I do not see the issue when a file name is passed to tarfile.open() 
rather than a file object, nor do I see it with the bzip or XZ compressors, 
uncompressed tar creation, or the “special purposes” w|gz mode.

--
components: Library (Lib)
messages: 208017
nosy: vadmium
priority: normal
severity: normal
status: open
title: Incomplete gzip output with tarfile.open(fileobj=..., mode=w:gz)
type: behavior
versions: Python 3.3

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



[issue6625] UnicodeEncodeError on pydoc's CLI

2014-01-13 Thread Torsten Landschoff

Torsten Landschoff added the comment:

I tested this as well and it seems to work now. :-) Thanks for fixing it!

--

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



[issue4356] Add key argument to bisect module functions

2014-01-13 Thread Dima Tisnek

Dima Tisnek added the comment:

I've worked around this in 2.6/2.7 like this:

class Arr:
def __getitem__(self, i):
return foo(i)  # your key function
def __len__(self):
return 1000  # your max index value

bisect.bisect(Arr(), value, ...)

--
nosy: +Dima.Tisnek

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



[issue20239] Allow repeated deletion of unittest.mock.Mock attributes

2014-01-13 Thread Michael Foord

New submission from Michael Foord:

Reported as mock issue 221: http://code.google.com/p/mock/issues/detail?id=221

 from unittest.mock import Mock
 m = Mock()
 m.foo = 3
 del m.foo
 m.foo = 4
 del m.foo
Traceback (most recent call last):
  File stdin, line 1, in module
  File /compile/py3k-cpython/Lib/unittest/mock.py, line 687, in __delattr__
raise AttributeError(name)
AttributeError: foo

Suggested change:

Previous:

   def __delattr__(self, name):
   if name in _all_magics and name in type(self).__dict__:
   delattr(type(self), name)
   if name not in self.__dict__:
   # for magic methods that are still MagicProxy objects and
   # not set on the instance itself
   return

   if name in self.__dict__:
   object.__delattr__(self, name)

   obj = self._mock_children.get(name, _missing)
   if obj is _deleted:
   raise AttributeError(name)
   if obj is not _missing:
   del self._mock_children[name]
   self._mock_children[name] = _deleted


Change:

   def __delattr__(self, name):
   if name in _all_magics and name in type(self).__dict__:
   delattr(type(self), name)
   if name not in self.__dict__:
   # for magic methods that are still MagicProxy objects and
   # not set on the instance itself
   return

   obj = self._mock_children.get(name, _missing)
   if name in self.__dict__:
   object.__delattr__(self, name)
   elif obj is _deleted:
   raise AttributeError(name)
   if obj is not _missing:
   del self._mock_children[name]
   self._mock_children[name] = _deleted


Incidentally the if ‘obj is not _missing’ line seems superfluous.

--
assignee: michael.foord
messages: 208019
nosy: michael.foord
priority: normal
severity: normal
stage: needs patch
status: open
title: Allow repeated deletion of unittest.mock.Mock attributes
type: behavior
versions: Python 3.3, Python 3.4

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



[issue20173] Derby #4: Convert 53 sites to Argument Clinic across 5 files

2014-01-13 Thread Vajrasky Kok

Vajrasky Kok added the comment:

Here is the patch for _codecs module.

--
Added file: http://bugs.python.org/file33443/clinic_codecsmodule.patch

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



[issue20240] Whitespace ignored in relative imports: from.package import something is valid syntax

2014-01-13 Thread Jacek Szpot

New submission from Jacek Szpot:

Just wanted to let you know that missing whitespace between from and a 
dot-prefixed name is not considered invalid:

from.foo import bar 

.. does not raise an error. Perhaps it should?

--
messages: 208022
nosy: maligree
priority: normal
severity: normal
status: open
title: Whitespace ignored in relative imports: from.package import something is 
valid syntax
type: behavior
versions: Python 2.7

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



[issue20137] Logging: RotatingFileHandler computes string length instead of byte representation length.

2014-01-13 Thread A. Libotean

A. Libotean added the comment:

Sure, will come back shortly with a patch.

--

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



[issue20136] Logging: StreamHandler does not use OS line separator.

2014-01-13 Thread A. Libotean

A. Libotean added the comment:

Let me write also a test for this and come back with a reply.

--

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



[issue20238] Incomplete gzip output with tarfile.open(fileobj=..., mode=w:gz)

2014-01-13 Thread Serhiy Storchaka

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


--
nosy: +lars.gustaebel, nadeem.vawda, serhiy.storchaka

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



[issue20240] Whitespace ignored in relative imports: from.package import something is valid syntax

2014-01-13 Thread Eric V. Smith

Eric V. Smith added the comment:

This is no different from other places in python where white space is optional. 
As long as the parser can tell the end of a token, there need not be white 
space before the next token.

For example:
 1+2
3
 1 + 2
3

However, if the parser cannot tell the end of a token, white space is required:
 1.__add__
  File stdin, line 1
1.__add__
^
SyntaxError: invalid syntax
 1 .__add__
method-wrapper '__add__' of int object at 0x1300c68

We're not likely to add required white space after the from token.

[I realize that in a whitespace required language, this is a slightly odd 
statement!]

--
nosy: +eric.smith
resolution:  - invalid
stage:  - committed/rejected
status: open - closed

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



[issue20238] Incomplete gzip output with tarfile.open(fileobj=..., mode=w:gz)

2014-01-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Martin for you report.

Here is a patch which fixes this issue.

--
assignee:  - serhiy.storchaka
keywords: +patch
stage:  - patch review
versions: +Python 3.4
Added file: http://bugs.python.org/file33444/tarfile_fobj_gz_close.patch

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



[issue20173] Derby #4: Convert 53 sites to Argument Clinic across 5 files

2014-01-13 Thread Vajrasky Kok

Changes by Vajrasky Kok sky@speaklikeaking.com:


Removed file: http://bugs.python.org/file33443/clinic_codecsmodule.patch

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



[issue20241] Bad reference to RFC in document of ipaddress?

2014-01-13 Thread INADA Naoki

New submission from INADA Naoki:

http://docs.python.org/3.3/library/ipaddress.html#ipaddress.IPv4Address.is_unspecified

 True if the address is unspecified. See RFC 5375 (for IPv4) or RFC 2373 
 (for IPv6).

RFC 5375 is IPv6 Unicast Address Assignment Considerations.

--
assignee: docs@python
components: Documentation
messages: 208027
nosy: docs@python, naoki
priority: normal
severity: normal
status: open
title: Bad reference to RFC in document of ipaddress?
versions: Python 3.3, Python 3.4

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



[issue20173] Derby #4: Convert 53 sites to Argument Clinic across 5 files

2014-01-13 Thread Vajrasky Kok

Changes by Vajrasky Kok sky@speaklikeaking.com:


Added file: http://bugs.python.org/file33445/clinic_codecsmodule.patch

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



[issue20241] Bad reference to RFC in document of ipaddress?

2014-01-13 Thread INADA Naoki

INADA Naoki added the comment:

Is it 5735 ?


Next sentence may be wrong, too.

 True if the address is otherwise IETF reserved.

Is it True if the address is IETF reserved. ?

--

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



[issue18622] reset_mock on mock created by mock_open causes infinite recursion

2014-01-13 Thread Laurent De Buyst

Laurent De Buyst added the comment:

The proposed patch does solve the infinite recursion bug, but a different 
problem appears when resetting the same mock multiple times: it only works the 
first time.

Using the patch as it stands:

 from unittest.mock import mock_open
 mo = mock_open()
 a = mo()
 mo.call_count
1
 mo.reset_mock()
 mo.call_count
0
 b = mo()
 mo.call_count
1
 mo.reset_mock()
 mo.call_count
1

And here from a version with an added print(visited) statement:

 from unittest.mock import mock_open
 mo = mock_open()
 a = mo()
 mo.call_count
1
 mo.reset_mock()
[]
[139803191795152]
[139803191795152, 139803181189008]
[139803191795152, 139803181189008, 139803213598416]
[139803191795152, 139803181189008, 139803213598416, 139803213652048]
[139803191795152, 139803181189008, 139803213598416, 139803213652048]
 mo.call_count
0
 b = mo()
 mo.call_count
1
 mo.reset_mock()
[139803191795152, 139803181189008, 139803213598416, 139803213652048, 
139803213598288]
 mo.call_count
1
 mo.reset_mock(visited=[])
[]
[139803191795152]
[139803191795152, 139803181189008]
[139803191795152, 139803181189008, 139803213598416]
[139803191795152, 139803181189008, 139803213598416, 139803213652048]
[139803191795152, 139803181189008, 139803213598416, 139803213652048]
 mo.call_count
0

As you can see, for some reason I don't quite grasp, the 'visited' parameter 
persists across calls to reset_mock(), meaning that the very first call does 
indeed reset it but subsequent calls do not.

As the last two calls show, one can force a reset by explicitly providing an 
empty list, but this is starting to become a change in API and not just a 
bugfix...

--
nosy: +Laurent.De.Buyst

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



[issue20206] email quoted-printable encoding issue

2014-01-13 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 4c5b1932354b by R David Murray in branch '3.3':
#20206, #5803: more efficient algorithm that doesn't truncate output.
http://hg.python.org/cpython/rev/4c5b1932354b

New changeset b6c3fc21286f by R David Murray in branch 'default':
Merge #20206, #5803: more efficient algorithm that doesn't truncate output.
http://hg.python.org/cpython/rev/b6c3fc21286f

--
nosy: +python-dev

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



[issue5803] email/quoprimime: encode and decode are very slow on large messages

2014-01-13 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 4c5b1932354b by R David Murray in branch '3.3':
#20206, #5803: more efficient algorithm that doesn't truncate output.
http://hg.python.org/cpython/rev/4c5b1932354b

New changeset b6c3fc21286f by R David Murray in branch 'default':
Merge #20206, #5803: more efficient algorithm that doesn't truncate output.
http://hg.python.org/cpython/rev/b6c3fc21286f

--
nosy: +python-dev

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



[issue20206] email quoted-printable encoding issue

2014-01-13 Thread R. David Murray

R. David Murray added the comment:

Fixed.

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

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



[issue5803] email/quoprimime: encode and decode are very slow on large messages

2014-01-13 Thread R. David Murray

R. David Murray added the comment:

I've reviewed this and applied it to both 3.3 and 3.4 in order to fix issue 
20206.  Thanks, Serhiy.

--
stage: patch review - committed/rejected
status: open - closed
versions: +Python 3.3

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



[issue20242] logging style parameter does not work correctly

2014-01-13 Thread kespindler

New submission from kespindler:

In Python 3.3, 3.4beta2, and bleeding edge (88411:e7d922d8ee03), the following 
occurs 

 import logging
 logging.basicConfig(style={)
 logging.error(hello)
%(levelname)s:%(name)s:%(message)s


Of course, I would expect

ERROR:root:hello

to be output instead.

--
components: Library (Lib)
messages: 208035
nosy: kespindler
priority: normal
severity: normal
status: open
title: logging style parameter does not work correctly
type: behavior
versions: Python 3.3, Python 3.4

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



[issue20242] logging style parameter does not work correctly

2014-01-13 Thread kespindler

kespindler added the comment:

I created a patch that fixes this behavior for both { and $ style formats.

Previously, default format strings were not being set correctly for those 
styles. This patch ensures that the correct default_format string is used.

There is a minor weirdness issue that, due to there previously being 2 
different default format strings for % style formatting, some tests rely on 
one, and some tests rely on the other. My patch remains backwards compatible 
with both default styles of format strings.

This patch also includes test cases for behavior with the style keyword, which 
was not being tested before.

--
keywords: +patch
Added file: http://bugs.python.org/file33446/Issue20242.patch

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



[issue20237] Ambiguous sentence in document of xml package.

2014-01-13 Thread R. David Murray

R. David Murray added the comment:

It means that the package suggests what courses of action to take when parsing 
untrusted data.  I don't know how it goes about doing that, though, so we'll 
have to ask Christian to clarify.

--
assignee: docs@python - 
nosy: +christian.heimes, r.david.murray

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



[issue20237] Ambiguous sentence in document of xml package.

2014-01-13 Thread R. David Murray

R. David Murray added the comment:

s/courses of action/kinds of actions/ in my explanation, otherwise it might be 
just as confusing :)

--

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



[issue20236] Invalid inline markup in xml document.

2014-01-13 Thread Roundup Robot

Roundup Robot added the comment:

New changeset fb1dd44d1f76 by R David Murray in branch '3.3':
#20236: Fix sphinx markup.
http://hg.python.org/cpython/rev/fb1dd44d1f76

New changeset 60163fc72017 by R David Murray in branch 'default':
Merge #20236: Fix sphinx markup.
http://hg.python.org/cpython/rev/60163fc72017

New changeset 3481c6f36e55 by R David Murray in branch '2.7':
#20236: Fix sphinx markup.
http://hg.python.org/cpython/rev/3481c6f36e55

--
nosy: +python-dev

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



[issue20236] Invalid inline markup in xml document.

2014-01-13 Thread R. David Murray

R. David Murray added the comment:

Fixed, thanks.

--
nosy: +r.david.murray
resolution:  - fixed
stage:  - committed/rejected
status: open - closed
type:  - behavior

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



[issue20221] #define hypot _hypot conflicts with existing definition

2014-01-13 Thread Tabrez Mohammed

Changes by Tabrez Mohammed tabr...@microsoft.com:


--
keywords: +patch
Added file: http://bugs.python.org/file33447/fix20221.patch

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



[issue20242] logging style parameter does not work correctly

2014-01-13 Thread Ned Deily

Changes by Ned Deily n...@acm.org:


--
nosy: +vinay.sajip

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



[issue20229] platform.py uses deprecated feature of plistlib

2014-01-13 Thread Roundup Robot

Roundup Robot added the comment:

New changeset cd728dc893c9 by Ned Deily in branch 'default':
Issue #20229: Avoid plistlib deprecation warning in platform.mac_ver().
http://hg.python.org/cpython/rev/cd728dc893c9

--
nosy: +python-dev

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



[issue14031] logging module cannot format str.format log messages

2014-01-13 Thread kespindler

kespindler added the comment:

I came across this issue while fixing issue20242. This issue (14031) still 
exists and is a major source of annoyance and confusion, and I suggest 
re-opening it.

Specifying the { style, while still being forced to use % formatting in log 
statements is backward and incredibly confusing for a number of key reasons:

 - The `style` keyword accomplishes a single thing only, and that is changing 
the format specification of the output, which is specified once and never 
touched again. For the myriad log statements littered throughout a codebase, it 
has *absolutely* no effect.
 - This is incredibly misleading to users. Why would there be this parameter to 
basicConfig that does (next to) nothing? Furthermore, if I've specified the { 
style, **why** would I write my log statements using the % style.
 - It forces the user to keep using % style formatting. The documentation 
explicitly states that this is old style formatting, and new style should 
be used, (due to its many advantages). Why force the user to know two 
formatting styles?


I created a patch (with test cases) that allows for this functionality. The 
whole idea of this feature is giving users the choice, if their environment 
allows it, to use the new-style formatting. Users should not have to rely on 
the hack linked in the blog in order to achieve *exected* behavior!

--
keywords: +patch
nosy: +kespindler
Added file: http://bugs.python.org/file33448/issue14031.patch

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



[issue20229] platform.py uses deprecated feature of plistlib

2014-01-13 Thread Ned Deily

Changes by Ned Deily n...@acm.org:


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

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



[issue14031] logging module cannot format str.format log messages

2014-01-13 Thread R. David Murray

R. David Murray added the comment:

The reason is simple: in the general case you do not control all of the 
statements that produce log messages.  Some of them come from 3rd party library 
code.

Perhaps the documentation needs to be clarified on this point, and document the 
technique mentioned in the blog post Vinay linked to?  Or perhaps some 
pre-built wrappers can be provided in 3.5?

--

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



[issue20243] ReadError when open a tarfile for writing

2014-01-13 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

ReadError can be raised when open a tarfile in write mode (e.g. 'w:gz'). Here 
is a patch wish a test. In additional it rewrites the handling errors in 
gzopen() which is too complicated now. This complication is possible the cause 
of bugs #11513 and #20238.

--
assignee: serhiy.storchaka
components: Library (Lib)
files: tarfile_readerror_write_mode.patch
keywords: patch
messages: 208044
nosy: georg.brandl, lars.gustaebel, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: ReadError when open a tarfile for writing
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file33449/tarfile_readerror_write_mode.patch

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



[issue20243] ReadError when open a tarfile for writing

2014-01-13 Thread Serhiy Storchaka

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


--
dependencies: +Incomplete gzip output with tarfile.open(fileobj=..., 
mode=w:gz)

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



[issue14031] logging module cannot format str.format log messages

2014-01-13 Thread kespindler

kespindler added the comment:

I definitely do recognize that important case. I think the proper solution,
however, to that is make a very clear warning in the documentation that
changing the style might affect the logging of 3rd party tools. Those users
would probably have to use the % style formatting, which continues to work
exactly as always. I'd also note, this issue is largely related to the
`basicConfig` command. Anybody using significant 3rd party tools is likely
using a more complicated solution. In that case, this patch gives them the
flexibility to specify both LogRecords and the Formatter in whichever way
they desire.

The problem with leaving the behavior as is is that currently the style
keyword is effectively useless and grossly misleading to users.

Furthermore, the documentation makes reference to the ability to use new
style formats. From Logging HOWTO:

 As you can see, merging of variable data into the event description
message uses the old, %-style of string formatting. This is for backwards
compatibility: the logging package pre-dates newer formatting options such
as str.format() and string.Template. **These newer formatting options are
supported, but exploring them is outside the scope of this tutorial.**

This interpretation is the most logical interpretation of the style
keyword. Again, the format string is used once and is of comparative little
consequence - there's no real need for changing its format. Log messages
are written many, many times, and so it makes sense to allow the user to
write them in the modern format.

If the behavior really cannot be changed, this patch does provide
subclasses to LogRecord that give the desired behavior. Technically these
can be used independently of the style keyword.

On Mon, Jan 13, 2014 at 11:48 AM, R. David Murray rep...@bugs.python.orgwrote:


 R. David Murray added the comment:

 The reason is simple: in the general case you do not control all of the
 statements that produce log messages.  Some of them come from 3rd party
 library code.

 Perhaps the documentation needs to be clarified on this point, and
 document the technique mentioned in the blog post Vinay linked to?  Or
 perhaps some pre-built wrappers can be provided in 3.5?

 --

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


--

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



[issue20244] Possible resources leak in tarfile.open()

2014-01-13 Thread Serhiy Storchaka

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


--
dependencies: +ReadError when open a tarfile for writing

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



  1   2   >