Re: [Tutor] why inline-only string literals?
[sorry, Steve, first replied to sender instead of list] On Sun, 7 Feb 2010 09:54:12 -0800 Steve Willoughby wrote: > I believe it's a deliberate design decision, [...] > So by making you explicitly state when you wanted multi-line strings, > it makes it easier to spot this common mistake as well as making > your intent more clear when just looking at the code. Thank you. I guess this really makes sense. Or rather it did make sense at the time of python design. Nowadays most editors (even not programming editors) are able to _very_ clearly show such errors (when I add a quote, the whole rest of the code becomes a string ;-). It seems such a change would be backwards-compatible, no? I thought there may be a (for me) hidden issue due to lexer+parser separation. My parser was PEG-based, so with a single grammar and a single pass. I'm not used to reason about lexers and token strings. But since python does have multi-line strings, anyway... Denis la vita e estrany http://spir.wikidot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Closing a matplotlib window after show()
When I installed matplotlib2.5 on my W7 machine last were a few error msgs about missing about missing files. Is that usual for matplotlib. BTW, I've posted details of my problem to the MPL list. Here I'm interested in the basic of install and use with IDLE, and not the details of the use of MPL. Supposedly an uninstall is provided by a Python setup tool. I hae not used it yet. The basic problem is the show(). One person checked out the examples I provided and found show() to operate fine. On my XP machine the program I'm modifying has plot code someone put in a year or two ago, and it all works fine. My code produces the desired plot, but gets hung up on show(). On 2/7/2010 8:11 PM, Wayne Watson wrote: The code below is a typical example of matplotlib use. I've used it both in xp and win7 in IDLE. It produces the required plots and stop with the plot display. If I close the plot window with the x in the upper right corner, the shell window is left open. I have to do the same to close it. If I run it again, and look at the shell window, it looks hung up with the cursor below the >>> prompt. Ctrl-c doesn't break it, and I have to resort to x again. There must be some mechanism to insert below that allows the program to continue on and thus complete. Supposedly fig.close() will but I've put it in several places and have gotten unknown attribute to figure. Comments? from matplotlib.pyplot import figure, show from numpy import arange, pi, cos, sin, pi from numpy.random import rand # unit area ellipse rx, ry = 3., 1. area = rx * ry * pi theta = arange(0, 2*pi+0.01, 0.1) verts = zip(rx/area*cos(theta), ry/area*sin(theta)) x,y,s,c = rand(4, 30) s*= 10**2. fig = figure() ax = fig.add_subplot(111) ax.scatter(x,y,s,c,marker=None,verts =verts) show() -- "Crime is way down. War is declining. And that's far from the good news." -- Steven Pinker (and other sources) Why is this true, but yet the media says otherwise? The media knows very well how to manipulate us (see limbic, emotion, $$). -- WTW ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] datetime a.m. not AM
Hello, I have an issue with data that I am trying to convert to datetime. It has 'a.m.' rather than 'am' and the %p format doesn't seem to work. I am pretty sure there should be an easy solution. That said I can not see it at the moment. the following illustrates the issue. test1 and test2 work BUT my data is in the format of 'data below: import StringIO import datetime test1 = '1/09/1978 1:00:00 ' test2 = '1/09/1978 1:00:00 am' data = '1/09/1978 1:00:00 a.m.' print datetime.datetime.strptime(test1,('%d/%m/%Y %I:%M:%S ')) print datetime.datetime.strptime(test2,('%d/%m/%Y %I:%M:%S %p')) print datetime.datetime.strptime(data,('%d/%m/%Y %I:%M:%S %p')) Thank you for your time, bevan -- View this message in context: http://old.nabble.com/datetime-a.m.-not-AM-tp27506228p27506228.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime a.m. not AM
On ma, 2010-02-08 at 13:02 -0800, bevan j wrote: > data = '1/09/1978 1:00:00 a.m.' If you know this will always be in the form of 'a.m.' you can replace it with 'am' by data.replace('a.m.','am'). Greets Sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime a.m. not AM
Well, I have managed to get it working by using the locale setting. It would be nice to use the am/pm setting only and leave the rest unset. Will have to look into it further. Any tips? import locale #to set locale to use a.m. instead of AM locale.setlocale(locale.LC_ALL, '') bevan j wrote: > > Hello, > > I have an issue with data that I am trying to convert to datetime. It has > 'a.m.' rather than 'am' and the %p format doesn't seem to work. I am > pretty sure there should be an easy solution. That said I can not see it > at the moment. the following illustrates the issue. test1 and test2 work > BUT my data is in the format of 'data below: > > import StringIO > import datetime > > test1 = '1/09/1978 1:00:00 ' > test2 = '1/09/1978 1:00:00 am' > data = '1/09/1978 1:00:00 a.m.' > > print datetime.datetime.strptime(test1,('%d/%m/%Y %I:%M:%S ')) > print datetime.datetime.strptime(test2,('%d/%m/%Y %I:%M:%S %p')) > print datetime.datetime.strptime(data,('%d/%m/%Y %I:%M:%S %p')) > > Thank you for your time, > > bevan > > -- View this message in context: http://old.nabble.com/datetime-a.m.-not-AM-tp27506228p27506926.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] List Comprehension question
I've been trying to work my way through some 'beginner projects' I found around the web, one of them involves generating some random numbers. I decided to use a list of lists, and I'm wondering if this is a valid comprehension...IDLE doesn't seem to mind, but maybe I lack the experience to know better: numbers = [[random.randint(1, 10) for x in range(5)] for y in range(5)] I'm using Python 3.1. If this is valid, is there a shorter version or better way? Thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Closing a matplotlib window after show()
Hello Wayne! On Monday February 8 2010 20:54:27 Wayne Watson wrote: > The basic problem is the show(). One person checked out the examples I > provided and found show() to operate fine. On my XP machine the program > I'm modifying has plot code someone put in a year or two ago, and it all > works fine. My code produces the desired plot, but gets hung up on show(). The behavior that you describe, is the normal behavior of Matplotlib: When you call show(), the program gets stuck. Therefore the call to show is always the last statement in the example programs. Show returns when the last plot window is closed, and in principle the program could then continue. If you want to look at plots while the program is running, you must use Ipython. This is a modified Python interpreter, that contains special code to change the way how Matplotlib works. http://ipython.scipy.org/moin/ Eike. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List Comprehension question
On Mon, Feb 8, 2010 at 4:15 PM, wrote: > I've been trying to work my way through some 'beginner projects' I found > around the web, one of them involves generating some random numbers. I > decided to use a list of lists, and I'm wondering if this is a valid > comprehension...IDLE doesn't seem to mind, but maybe I lack the experience > to know better: > > numbers = [[random.randint(1, 10) for x in range(5)] for y in range(5)] > > I'm using Python 3.1. If this is valid, is there a shorter version or > better way? > If Python executes it without throwing exceptions that means it's syntactically valid. Are you asking if it's semantically valid? Well, that depends what you're trying to do. Are you trying to make a 5x5 matrix of random numbers chosen from [1,2,3,4,5,6,7,8,9,10]? In that case I'd say it does what you want. most people opt to use randrange rather than randint though as it makes more sense when related to other range functions. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] python
python ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python
quite. On Mon, Feb 8, 2010 at 8:54 PM, ailx ailx wrote: > python > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Closing a matplotlib window after show()
Hi, I'm not so sure that's true. I have a large 900 line program where some original plot code just continues beyond plot() and show(), after the user closes the plot window. New code that I put in gets knotted up, as far as I can tell. In both cases, I've put print statements after show(), but nothing appears in the shell or, if run by clicking the program file, in the DOS-like window that appears. Further, I posted this elsewhere, and someone claims to have tried a few simple examples with show() at the ended,and they did not get tied up in knots when the user closed the window. I'm going to assume he used IDLE, or a straight execute of the file. On 2/8/2010 2:23 PM, Eike Welk wrote: Hello Wayne! On Monday February 8 2010 20:54:27 Wayne Watson wrote: The basic problem is the show(). One person checked out the examples I provided and found show() to operate fine. On my XP machine the program I'm modifying has plot code someone put in a year or two ago, and it all works fine. My code produces the desired plot, but gets hung up on show(). The behavior that you describe, is the normal behavior of Matplotlib: When you call show(), the program gets stuck. Therefore the call to show is always the last statement in the example programs. Show returns when the last plot window is closed, and in principle the program could then continue. If you want to look at plots while the program is running, you must use Ipython. This is a modified Python interpreter, that contains special code to change the way how Matplotlib works. http://ipython.scipy.org/moin/ Eike. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- "Crime is way down. War is declining. And that's far from the good news." -- Steven Pinker (and other sources) Why is this true, but yet the media says otherwise? The media knows very well how to manipulate us (see limbic, emotion, $$). -- WTW ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor