plotting slows down
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 j>ypos-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
Am 12.01.2014 08:50 schrieb [email protected]: 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)
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("", filename.replace('"', '\\"')))
...
ls "\\"; rm whatever; ls \"
--
https://mail.python.org/mailman/listinfo/python-list
Re: Problem writing some strings (UnicodeEncodeError)
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("", filename.replace('"', '\\"')))
> ...
> ls "\\"; rm whatever; ls \"
The complete session:
>>> import os
>>> template = 'ls ""'
>>> with open('\\"; rm whatever; ls \\', "w") as f: pass
...
>>> for filename in os.listdir():
... print(template.replace("", 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[:]
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
Le lundi 13 janvier 2014 09:27:46 UTC+1, Thomas Rachel a écrit : > Am 12.01.2014 08:50 schrieb [email protected]: > > 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
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
On Mon, Jan 13, 2014 at 9:05 PM, Sean Murphy 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
On Mon, Jan 13, 2014 at 8:54 PM, 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
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 "", line 1, in
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 "", line 1, in
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
On Mon, Jan 13, 2014 at 9:38 PM, Steven D'Aprano
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
[email protected] 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
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 j>ypos-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
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
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
On Mon, Jan 13, 2014 at 3:47 PM, Neal Becker 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
On Tue, Jan 14, 2014 at 1:47 AM, Neal Becker 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
On 13/01/2014 15:12, Giampaolo Rodola' wrote: On Mon, Jan 13, 2014 at 3:47 PM, Neal Becker mailto:[email protected]>> 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
On 13/01/2014 15:28, Chris Angelico wrote: On Tue, Jan 14, 2014 at 2:24 AM, Mark Lawrence 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
On Tue, Jan 14, 2014 at 2:24 AM, Mark Lawrence 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
On 01/13/2014 02:54 AM, [email protected] 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)
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("", filename.replace('"', '\\"')))
>> ...
>> ls "\\"; rm whatever; ls \"
>
> The complete session:
>
import os
template = 'ls ""'
with open('\\"; rm whatever; ls \\', "w") as f: pass
> ...
for filename in os.listdir():
> ... print(template.replace("", 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
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
>
> 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?
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?
On Tue, Jan 14, 2014 at 3:29 AM, Adam 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?
On Jan 11, 2014, at 11:34 AM, Michael Torrie 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/ > 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?
On Tue, Jan 14, 2014 at 2:42 AM, William Ray Wing 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
On 13/01/2014 16:24, [email protected] 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)
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("", filename.replace('"', '\\"')))
>>> ...
>>> ls "\\"; rm whatever; ls \"
>>
>> The complete session:
>>
> import os
> template = 'ls ""'
> with open('\\"; rm whatever; ls \\', "w") as f: pass
>> ...
> for filename in os.listdir():
>> ... print(template.replace("", 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
On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel 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
On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly wrote: > On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel 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
Chris Angelico Wrote in message: > On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly wrote: >> On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel 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
On Mon, Jan 13, 2014 at 1:15 AM, 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
On Mon, Jan 13, 2014 at 1:09 AM, Chris Angelico wrote:
> On Mon, Jan 13, 2014 at 2:35 PM, Larry Martell
> 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 x 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 y 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
On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell 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
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
On 13/01/2014 18:32, Chris Angelico wrote: On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell 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
On 13/01/2014 18:27, Larry Martell wrote:
On Mon, Jan 13, 2014 at 1:09 AM, Chris Angelico wrote:
On Mon, Jan 13, 2014 at 2:35 PM, Larry Martell 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 x
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
Am 13.01.2014 10:54 schrieb [email protected]: 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 "", line 1, in 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)
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
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
Forgot to mention I am using Python 3.3.3 -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter GUI Error
Am 13.01.14 19:49, schrieb [email protected]: 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
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
[email protected] 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 "", line 1, in File "", 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
On Mon, Jan 13, 2014 at 1:32 PM, Chris Angelico wrote: > On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell > 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[:]
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
On Mon, 13 Jan 2014 08:26:11 -0500, Dave Angel wrote: > [email protected] 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- [email protected] 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?
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
On Jan 13, 2014, at 7:42 PM, Mark Lawrence 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
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
On 1/13/2014 12:45 PM, Chris Angelico wrote: On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly wrote: On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel 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)
On 1/13/2014 4:54 AM, [email protected] 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?
On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano 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
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) ## CORRECT ## py> label = Label(root, text="Blah") py> label.pack() py> label py> type(label) ## ANY QUESTIONS? ## py> help() -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter GUI Error
On Tue, Jan 14, 2014 at 5:49 AM, 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?
in 714500 20140113 233415 Chris Angelico wrote: >On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano 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?
On 14-01-2014 11:22, Bob Martin wrote: in 714500 20140113 233415 Chris Angelico wrote: On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano 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?
On Tue, Jan 14, 2014 at 6:22 PM, Bob Martin 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
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
