Re: [Tutor] %T as a strftime format identifier
Terry Carroll wrote: My question: was %T ever a valid format specifier in Python? My best guess is that it was when Edna was written (the most current release is from 2006, and the docs say it needs at least Python 1.5.2, which gives you an example of its age). It seems odd that the format identifier would be dropped if it had existed, though; that seems like a needless upward compatibility issue. Works for me: [st...@sylar ~]$ python2.5 Python 2.5 (r25:51908, Nov 6 2007, 16:54:01) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.strftime("%T") '19:03:16' and similarly for other versions as well. I think what you are seeing is differences in the C compiler, not deliberate language changes. As I recall it, the time format identifiers are dependent on the C library used to compile the time module, and/or the locale. If the C library involved doesn't recognise %T, neither will Python. On the other hand, %T isn't listed in the manual: http://docs.python.org/library/time.html#time.strftime -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 90
-- I NOLONGER WANT YOUR TUTORIALS BECAUSE OF SPAM VIRUSES THANK YOU FOR YOUR SERVISES ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] lambda in python
"john tsolox" wrote seeing various examples of lambda in python being ALL one-liners. These one-liners inside a lambda seems not to have the full permissible use of the full power of python language (if,for,while). Is this correct? The lambda expression was introduced into Python by popular demand to further support the functional style of programming. Functional programming does not encourage the use of state and so lambda was constrained to be a pure expression. For practical purposes this is a slight inconvenience and full function code block syntax - ala Ruby - would be nice, but for most of it's intended uses lambda expressions are adequate. You can always define a named function within the using scope if you need more. IMO. Rather than seeing lambda increased in power we are frankly more likely to see lambda removed from the language in some far future incarnation. This has been seriously discussed several times on the main Python newsgroup. See the functional programming topic in my tutorial for more info on lambda and Python's FP support as a whole. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 90
I am beginning to feel the name Wangolo Joel is not human. It probably could be the name of a virus. It has been said over and over how to unsubscribe to an extent that someone actually sent a link and yet, we are still getting this mail. Can anyone write a simple program to deactivate this virus. Regards. Sent from my BlackBerry wireless device from MTN -Original Message- From: Wangolo Joel Sender: tutor-bounces+delegbede=dudupay@python.org Date: Sat, 27 Nov 2010 08:55:10 To: Subject: Re: [Tutor] Tutor Digest, Vol 81, Issue 90 ___ 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] Tutor Digest, Vol 81, Issue 90
I have unsubscribed Joel since he seems incapable of following the instructions. Alan G. Moderator. "Wangolo Joel" wrote in message news:631794.21995...@web29702.mail.ird.yahoo.com... -- I NOLONGER WANT YOUR TUTORIALS BECAUSE OF SPAM VIRUSES THANK YOU FOR YOUR SERVISES ___ 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
[Tutor] Python Exercise
Hi, I created this website for practising python online: http://www.pyschools.com. Hope to gather feedback from people here who are interesting in teaching and learning python. Regards, Kok Cheng ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Reload() in v3? WAS Re: IDEs
"Steven D'Aprano" wrote The other nine times out of ten *wink* I need to do debugging, and I swap tabs and work in my interactive Python interpreter. import filename # first time only reload(filename) # all subsequent times I'm working on the v3 version of my tutor and while testing some module code I tried to reload the module in IDLE... I got an error: import os reload(os) Traceback (most recent call last): File "", line 1, in reload(os) NameError: name 'reload' is not defined Has reload been removed in V3? Whats the alternative? Does a repeated import auto-reload? I'm surprised and confused... -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reload() in v3? WAS Re: IDEs
"Alan Gauld" wrote Has reload been removed in V3? Whats the alternative? Does a repeated import auto-reload? I'm surprised and confused... Found it, its been moved into the imp module. You need to import imp and then do imp.reload(foo) import os reload(os) Traceback (most recent call last): File "", line 1, in reload(os) NameError: name 'reload' is not defined import imp imp.reload(os) I wonder why that was considered "a good idea"? Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Exercise
On Sat, 27 Nov 2010 22:00:03 +0800 Kok Cheng Tan wrote: > I created this website for practising python online: > http://www.pyschools.com. Hope to gather feedback from people here > who are interesting in teaching and learning python. Here you go with the first suggestion: remove the need to log in! (Haven't really watched at the site content, given that I - like 99% of the Internet users - wouldn't bother to login just to roam around a site). Mac. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] normalize an array
Hello John! On Friday 26.11.2010 23:23:51 Peter Otten wrote: > John wrote: > > I know this is a simple problem, but I want to do it the most > > efficient way (that is vectorized...) > > > > import numpy as np > > > > a = np.array(([1,2,3,4],[1,.2,3,4],[1,22,3,4])) > > b = np.sum(a,axis=1) > > > > for i,elem in enumerate(a): > > a[i,:] = elem/b[i] > > > > suggestions? > > I'm not a numpy expert, but: > > (a.transpose()/np.sum(a, axis=1)).transpose() The underlying feature of Peter's solution is called broadcasting. For a detailed explanation look at: http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html Eike. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Exercise
Hi - I just wanted to add to Mac's comment. I don't have Google mail/gmail and don't want to create a mail account with them. I was also wondering if I should just try clicking on links anyway and changed my mind and exited. Regards, Patty > On Sat, 27 Nov 2010 22:00:03 +0800 > Kok Cheng Tan wrote: > >> I created this website for practising python online: >> http://www.pyschools.com. Hope to gather feedback from people here >> who are interesting in teaching and learning python. > > Here you go with the first suggestion: remove the need to log in! > (Haven't really watched at the site content, given that I - like 99% of > the Internet users - wouldn't bother to login just to roam around a > site). > > Mac. > ___ > 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] Python Exercise
> -Original Message- > On Sat, 27 Nov 2010 22:00:03 +0800 > Kok Cheng Tan wrote: > > > I created this website for practising python online: > > http://www.pyschools.com. Hope to gather feedback from > people here who > > are interesting in teaching and learning python. > I logged in using my google account and the first page that came up was a ranking of competitors in the site's Python Tournament. I would recommend that you bring people to an introductory learning page after their first sign in (if you keep the sign-in requirement, which I also think is a bad idea) rather than a competition page--that is, unless you want to intimidate some (many?) beginning programmers into looking elsewhere. Joel ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] normalize an array
Thank you both! Broadcasting is a concept I hadn't yet read about, but knew was important for efficient python programming... thanks for the link! On Sat, Nov 27, 2010 at 6:44 PM, Eike Welk wrote: > Hello John! > > On Friday 26.11.2010 23:23:51 Peter Otten wrote: >> John wrote: >> > I know this is a simple problem, but I want to do it the most >> > efficient way (that is vectorized...) >> > >> > import numpy as np >> > >> > a = np.array(([1,2,3,4],[1,.2,3,4],[1,22,3,4])) >> > b = np.sum(a,axis=1) >> > >> > for i,elem in enumerate(a): >> > a[i,:] = elem/b[i] >> > >> > suggestions? >> >> I'm not a numpy expert, but: >> >> (a.transpose()/np.sum(a, axis=1)).transpose() > > The underlying feature of Peter's solution is called broadcasting. For a > detailed explanation look at: > http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html > > > Eike. > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Configuration `` Plone 2.5.3-final, CMF-1.6.4, Zope (Zope 2.9.7-final, python 2.4.4, linux2), Python 2.6 PIL 1.1.6 Mailman 2.1.9 Postfix 2.4.5 Procmail v3.22 2001/09/10 Basemap: 1.0 Matplotlib: 1.0.0 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] %T as a strftime format identifier
On Sat, 27 Nov 2010, Steven D'Aprano wrote: [st...@sylar ~]$ python2.5 Python 2.5 (r25:51908, Nov 6 2007, 16:54:01) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type "help", "copyright", "credits" or "license" for more information. import time time.strftime("%T") '19:03:16' Interesting. On my Windows systems (Windows 7 and Vista, both Activestate Python 2.6.4.8) I get: import time time.strftime("%T") '' On Linux (Ubuntu 10.04 and 10.10, Python 2.6.5) I get: import time time.strftime("%T") '10:54:54' It may be an Activestate thing, hewing closely to the docs. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reload() in v3? WAS Re: IDEs
Alan Gauld wrote: import os reload(os) Traceback (most recent call last): File "", line 1, in reload(os) NameError: name 'reload' is not defined Has reload been removed in V3? Not removed, just moved. >>> import imp >>> imp.reload The reason for moving it is that reload is quite simple-minded and full of traps for the unwary, and consequently isn't useful enough to be in the build-it namespace. Whats the alternative? Does a repeated import auto-reload? Absolutely not! That would make importing much more expensive, and change the behaviour. import(module) caches the module in sys, so that subsequent imports are fast. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Exercise
Hi, Thanks for the feedback. I will add a trial section that doesn't require login so that new visitors are able to give the website a try. Regards, Kok Cheng -- Forwarded message -- From: Date: Sun, Nov 28, 2010 at 2:41 AM Subject: Tutor Digest, Vol 81, Issue 105 To: tutor@python.org Send Tutor mailing list submissions to tutor@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutor-requ...@python.org You can reach the person managing the list at tutor-ow...@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." Today's Topics: 1. Python Exercise (Kok Cheng Tan) 2. Reload() in v3? WAS Re: IDEs (Alan Gauld) 3. Re: Reload() in v3? WAS Re: IDEs (Alan Gauld) 4. Re: Python Exercise (Mac Ryan) 5. Re: normalize an array (Eike Welk) 6. Python Exercise (pa...@cruzio.com) 7. Re: Python Exercise (Joel Schwartz) 8. Re: normalize an array (John) -- Message: 1 Date: Sat, 27 Nov 2010 22:00:03 +0800 From: Kok Cheng Tan To: tutor@python.org Subject: [Tutor] Python Exercise Message-ID: Content-Type: text/plain; charset=ISO-8859-1 Hi, I created this website for practising python online: http://www.pyschools.com. Hope to gather feedback from people here who are interesting in teaching and learning python. Regards, Kok Cheng -- Message: 2 Date: Sat, 27 Nov 2010 15:04:57 - From: "Alan Gauld" To: tutor@python.org Subject: [Tutor] Reload() in v3? WAS Re: IDEs Message-ID: Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response "Steven D'Aprano" wrote > The other nine times out of ten *wink* I need to do debugging, and I > swap tabs and work in my interactive Python interpreter. > > import filename # first time only > reload(filename) # all subsequent times I'm working on the v3 version of my tutor and while testing some module code I tried to reload the module in IDLE... I got an error: >>> import os >>> reload(os) Traceback (most recent call last): File "", line 1, in reload(os) NameError: name 'reload' is not defined >>> Has reload been removed in V3? Whats the alternative? Does a repeated import auto-reload? I'm surprised and confused... -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ -- Message: 3 Date: Sat, 27 Nov 2010 15:11:53 - From: "Alan Gauld" To: tutor@python.org Subject: Re: [Tutor] Reload() in v3? WAS Re: IDEs Message-ID: Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response "Alan Gauld" wrote > Has reload been removed in V3? > Whats the alternative? Does a repeated import auto-reload? > > I'm surprised and confused... Found it, its been moved into the imp module. You need to import imp and then do imp.reload(foo) >>> import os >>> reload(os) Traceback (most recent call last): File "", line 1, in reload(os) NameError: name 'reload' is not defined >>> import imp >>> imp.reload(os) >>> I wonder why that was considered "a good idea"? Alan G. -- Message: 4 Date: Sat, 27 Nov 2010 18:12:59 +0100 From: Mac Ryan To: tutor@python.org Subject: Re: [Tutor] Python Exercise Message-ID: <20101127181259.770ea...@jabbar> Content-Type: text/plain; charset=US-ASCII On Sat, 27 Nov 2010 22:00:03 +0800 Kok Cheng Tan wrote: > I created this website for practising python online: > http://www.pyschools.com. Hope to gather feedback from people here > who are interesting in teaching and learning python. Here you go with the first suggestion: remove the need to log in! (Haven't really watched at the site content, given that I - like 99% of the Internet users - wouldn't bother to login just to roam around a site). Mac. -- Message: 5 Date: Sat, 27 Nov 2010 18:44:25 +0100 From: Eike Welk To: tutor@python.org Subject: Re: [Tutor] normalize an array Message-ID: <201011271845.38868.eike.w...@gmx.net> Content-Type: Text/Plain; charset="iso-8859-1" Hello John! On Friday 26.11.2010 23:23:51 Peter Otten wrote: > John wrote: > > I know this is a simple problem, but I want to do it the most > > efficient way (that is vectorized...) > > > > import numpy as np > > > > a = np.array(([1,2,3,4],[1,.2,3,4],[1,22,3,4])) > > b = np.sum(a,axis=1) > > > > for i,elem in enumerate(a): > > a[i,:] = elem/b[i] > > > > suggestions? > > I'm not a numpy expert, but: > > (a.transpose()/np.sum(a, axis=1)).transpose() The underlying feature of Peter's solution is called broadcasting. For a detailed explanation look at: http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html Eike. -- Message: 6 Date: Sat, 27 Nov 2010
[Tutor] Is Python useful for emulating?
I never created any emulator before, and i'm learning C++. Let's say i try to write an emulator for... SNES. Would Python be fast enough? Also, any useful advice you can give me? Things i should know about before i start coding? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] %T as a strftime format identifier
32-bit Python 2.7 for Windows: >>> import time >>> time.strftime("%T") Traceback (most recent call last): File "", line 1, in time.strftime("%T") ValueError: Invalid format string Malcolm ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is Python useful for emulating?
On 28 November 2010 02:59, Mauricio Alejandro wrote: > I never created any emulator before, and i'm learning C++. Let's say i try > to write an emulator for... SNES. Would Python be fast enough? > Also, any useful advice you can give me? Things i should know about before > i start coding? > Because of the performance requirements generally applciable to emulating a games console, I would not think to write an emulator in native Python. However you can probably write the main parts that need performance as C based Python modules, and write "the rest" in Python. (Whether "the rest" is substantial enough to warrant it is hard to say.) This is the route taken by any Python modules/applications that have critical performance requirements. As for useful advice, I don't want to put you off but writing a complete console emulator is not a trivial project by any stretch of the imagination, and you'll also need to have very detailed specs about the SNES's hardware (CPU, video hardware, memory and IO maps, sound hardware etc), as well as have copies of its firmware (BIOS/ROMS etc) in order to even be able to begin to work on such a project. Additionally, there's already (or there was several years ago) several SNES emulators and doing another one just for the sake of it, well, is it really worth it? Maybe something a little more accessible might be to implement a MIPS CPU emulator, something like this: http://weblogs.mozillazine.org/roc/archives/2010/11/implementing_a.html or this: http://codu.org/projects/trac/jsmips/ And then see how fast you can make that without resorting to C, like the guy above did in the browser. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] string case manipulation in python 3.x
I need to do some case manipulation that I don't see in the documented string functions. I want to make sure that user input meets a certain capitalization scheme, for example, if user input is a name, then the first letter of each word in the name is upper case, and the rest are lower. I know how to force the upper and lower cases with string.lower() and friends. and I could even do a string.split() on the spaces in the names to break the name into pieces. I don't see an obvious way to do this. what I've come up with so far is to do something like this. break the name into pieces force each piece to be lower case replace the first letter in each word with a uppercase version of whats there already. Problems with this approach as I see them: The built in split function will create undesirable results for names that contain suffixes like Jr. etc. I'm not entirely sure how to replace the string with an uppercase first letter on a per word basis. Whats the "right" way to do something like this? Thanks Rance ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string case manipulation in python 3.x
On Sun, Nov 28, 2010 at 5:55 AM, Rance Hall wrote: > I need to do some case manipulation that I don't see in the documented > string functions. > > I want to make sure that user input meets a certain capitalization > scheme, for example, if user input is a name, then the first letter of > each word in the name is upper case, and the rest are lower. > > I know how to force the upper and lower cases with string.lower() and friends. > > and I could even do a string.split() on the spaces in the names to > break the name into pieces. > > I don't see an obvious way to do this. > > what I've come up with so far is to do something like this. > > break the name into pieces > force each piece to be lower case > replace the first letter in each word with a uppercase version of > whats there already. > > Problems with this approach as I see them: > The built in split function will create undesirable results for names > that contain suffixes like Jr. etc. > I'm not entirely sure how to replace the string with an uppercase > first letter on a per word basis. > > Whats the "right" way to do something like this? > I'd say split the string, call the capitalize method on each part, then join back together. Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string case manipulation in python 3.x
On Sat, Nov 27, 2010 at 10:55 PM, Rance Hall wrote: > I need to do some case manipulation that I don't see in the documented > string functions. > > I want to make sure that user input meets a certain capitalization > scheme, for example, if user input is a name, then the first letter of > each word in the name is upper case, and the rest are lower. > So for instance, something like this? In [3]: badcasename = 'eRic SPAM IDle jr.' In [4]: badcasename.title() Out[4]: 'Eric Spam Idle Jr.' Problems with this approach as I see them: > The built in split function will create undesirable results for names > that contain suffixes like Jr. etc. > If you want it to behave differently for suffixes, I'm not sure how to do that... > I'm not entirely sure how to replace the string with an uppercase > first letter on a per word basis. > mystring = mystring.title() > Whats the "right" way to do something like this? gaining more familiarity with the builtin functions ;) HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor