Re: [Tutor] [Fwd: Re: python problem - help!!]
It's not a homework problem it is a practice problem to figure out how to code, to be able to do the assignments... Chris wrote: > If I sent you the problem can you build it so I know what it is suppose to > look like? I've spend too much time it, and made it worse...all I know is > that it does not produce the wanted results and is missing a loop... > > The worse part is that I did not find anything that can help me among the > hundreds of websites I visited... No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.487 / Virus Database: 269.13.25/1018 - Release Date: 9/19/2007 3:59 PM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.487 / Virus Database: 269.13.25/1018 - Release Date: 9/19/2007 3:59 PM ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [Fwd: Re: python problem - help!!]
Chris wrote: If I sent you the problem can you build it so I know what it is suppose to look like? I've spend too much time it, and made it worse...all I know is that it does not produce the wanted results and is missing a loop... It looks like a homework problem, so we can't just give you an answer, we can only provide guidance. The worse part is that I did not find anything that can help me among the hundreds of websites I visited... If you give us more indication of what problems you're having we can better assist you. Please in the future reply to the list and not directly to me. Use the "reply all" button, or "reply to group" button, to do this. If such a button is not available in your mail client, carbon-copy (cc) a copy of the message to tutor@python.org You'll have much more luck finding an answer if you ask the whole list rather than a specific person. -Luke --- Begin Message --- If I sent you the problem can you build it so I know what it is suppose to look like? I've spend too much time it, and made it worse...all I know is that it does not produce the wanted results and is missing a loop... The worse part is that I did not find anything that can help me among the hundreds of websites I visited... Hope you can help Chris -Original Message- From: Luke Paireepinart [mailto:[EMAIL PROTECTED] Sent: Sunday, September 23, 2007 9:38 PM To: Chris Cc: tutor@python.org Subject: Re: [Tutor] python problem - help!! Chris wrote: > > I need your help! > > > > I have this problem that I can’t seem to figure out. Can you help? > The problem is listed below, and below it is my code that I have so far. > What results / errors are you getting, how are they different from the results you want to get? -Luke No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.487 / Virus Database: 269.13.25/1018 - Release Date: 9/19/2007 3:59 PM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.487 / Virus Database: 269.13.25/1018 - Release Date: 9/19/2007 3:59 PM --- End Message --- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python problem - help!!
Chris wrote: > > I need your help! > > > > I have this problem that I can’t seem to figure out. Can you help? > The problem is listed below, and below it is my code that I have so far. > What results / errors are you getting, how are they different from the results you want to get? -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python course at Foothill College
If you would like to learn Python, Foothill College in Los Altos Hills California is offering a course starting this Wednesday evening, 26 Sept. The course is designed for students who are already familiar with some type of programming. Here is the course description: CIS 68K "INTRODUCTION TO PYTHON PROGRAMMING" 5 Units This course will introduce students to the Python language and environment. Four hours lecture, four hours terminal time. Advisory: CIS 15A or 27A, and CIS 68A. 2182 CIS -068K-01 LEC6:00PM- 9:50 Wednesdays - HAIGHT Middlefield Campus, Room I5. Course fee, $4. If you would like to sign up for the class, it would be very helpful if you would register beforehand by going to: http://www.foothill.fhda.edu/reg/index.php If you have questions, you can contact the instructor at: [EMAIL PROTECTED] Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Counting method calls
Kent Johnson wrote: > Ricardo Aráoz wrote: >> Kent Johnson wrote: >>> One more reference: >>> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252151 >>> >>> This appears as recipe 6.6 in the second edition of the printed >>> cookbook. >>> >>> Kent >> >> Thanks Kent. I guess I got into deep waters. >> It's a shame though that you can not do this in a simple manner, >> considering python simplifies so many other chores. > > I agree, also because it is so easy to do with old-style classes. > > The root of the problem seems to be that new-style classes do not use > the normal attribute lookup mechanism to find special methods when they > are being invoked by the interpreter *as* special methods. For example, > when executing a[0], __getattribute__() is not called on the class of a > or its metaclass. Instead the predefined slot for __getitem__ is > accessed; if it is empty then indexing is not allowed. > > Here is a demonstration that __getattribute__() is not called on the > class or the metaclass when __getitem__() is accessed as a special method: > > In [4]: class ShowMeta(type): >...: def __getattribute__(self, name): >...: print 'ShowMeta:', name >...: return type.__getattribute__(self, name) >...: >...: > In [5]: class Show(object): >...: def __getattribute__(self, name): >...: print 'Show:', name >...: return object.__getattribute__(self, name) >...: __metaclass__ = ShowMeta >...: >...: > In [6]: a=Show() > In [7]: a[1] > > Traceback (most recent call last): > File "", line 1, in > : 'Show' object is unindexable > > Notice that neither __getattribute__() is called. OTOH if __getitem__() > is accessed as a normal attribute then Show.__getattribute__() *is* called: > > In [9]: a.__getitem__(0) > Show: __getitem__ > > Traceback (most recent call last): > File "", line 1, in > File "", line 4, in __getattribute__ > : 'Show' object has no attribute > '__getitem__' > > The only way to put something in the __getitem__ slot to assign to > cls.__getitem__. That is why the cookbook recipe copies methods from the > delegate into the proxy. It seems unfortunate that the recipe requires > knowing which special methods you want to delegate. Maybe an approach > like the one here > http://groups.google.com/group/comp.lang.python/msg/f4bf020fd94d631a > of delegating all special methods with a list of exceptions would work > better. > > Kent > Anyway, if you have to know the innards of the language to be able to do it then it is not good. If nothing else it is against encapsulation. An application writer should not need to know those things in order to accomplish a simple concept as intercepting all methods. I think I'll stay with old style classes for this, the code is simpler and easy to understand what you are doing. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Counting method calls
Ricardo Aráoz wrote: > Kent Johnson wrote: >> One more reference: >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252151 >> >> This appears as recipe 6.6 in the second edition of the printed cookbook. >> >> Kent > > Thanks Kent. I guess I got into deep waters. > It's a shame though that you can not do this in a simple manner, > considering python simplifies so many other chores. I agree, also because it is so easy to do with old-style classes. The root of the problem seems to be that new-style classes do not use the normal attribute lookup mechanism to find special methods when they are being invoked by the interpreter *as* special methods. For example, when executing a[0], __getattribute__() is not called on the class of a or its metaclass. Instead the predefined slot for __getitem__ is accessed; if it is empty then indexing is not allowed. Here is a demonstration that __getattribute__() is not called on the class or the metaclass when __getitem__() is accessed as a special method: In [4]: class ShowMeta(type): ...: def __getattribute__(self, name): ...: print 'ShowMeta:', name ...: return type.__getattribute__(self, name) ...: ...: In [5]: class Show(object): ...: def __getattribute__(self, name): ...: print 'Show:', name ...: return object.__getattribute__(self, name) ...: __metaclass__ = ShowMeta ...: ...: In [6]: a=Show() In [7]: a[1] Traceback (most recent call last): File "", line 1, in : 'Show' object is unindexable Notice that neither __getattribute__() is called. OTOH if __getitem__() is accessed as a normal attribute then Show.__getattribute__() *is* called: In [9]: a.__getitem__(0) Show: __getitem__ Traceback (most recent call last): File "", line 1, in File "", line 4, in __getattribute__ : 'Show' object has no attribute '__getitem__' The only way to put something in the __getitem__ slot to assign to cls.__getitem__. That is why the cookbook recipe copies methods from the delegate into the proxy. It seems unfortunate that the recipe requires knowing which special methods you want to delegate. Maybe an approach like the one here http://groups.google.com/group/comp.lang.python/msg/f4bf020fd94d631a of delegating all special methods with a list of exceptions would work better. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python problem - help!!
I need your help! I have this problem that I can’t seem to figure out. Can you help? The problem is listed below, and below it is my code that I have so far. Two hockey teams play eight times during the regular season. Team A wins five times and Team B wins the other three times. They meet in the playoffs in a best of seven series. Write a program that estimates the chances of Team B winning the series. A sample run of the program might look like this: . Are team B's chances better in a 1 game "series", a 3 game series, a 5 game series, or a 7 game series? What would team B's chances of winning a 51 game series be? --- import random SERIES = 1000 game = 0 series = 0 while series < SERIES: teamA = random.randint (1,8) teamB = random.randint (1,8) teams = teamA + teamB if random.randint(1,8) >= 5: 'Team A' = team else: 'Team B' = team game = game + 1 series = series + 1 print 'In %2d simulated series %2d won %2d ' % (SERIES,team,game) print 'so I estimate there is a',(game / 10.00),'% chance they will win the series.' No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.487 / Virus Database: 269.13.25/1018 - Release Date: 9/19/2007 3:59 PM <>___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning a Language
You could also try the showmedo videos at: http://showmedo.com/videos/python I started with Java and am still learning Java but after just a few days of learning python I knew more about programming in python than I knew about in Java.I have also found it helpful trying out some of the challenges such as those at: http://www.pythonchallenge.com/ http://www.spoj.pl/ If you select a problem you can research using the google and the resources mentioned and try to find a solution.I have found it difficult to learn by just reading a book and prefer having a problem at hand,then using the book or other resources to try and solve the problem. Hope the above helps. The videos are simple clear and will have you programming in no time! On Sun, 2007-09-23 at 13:59 -0400, Michael Langford wrote: > First off, please don't pick a random message and reply to it. Please > send an email directly to tutor@python.org if you have a new > conversation topic. Some people's mail readers group emails together > by what email you hit reply on, so it will put your email with > messages it doesn't really belong with. > > That said: You're in luck, python is PERFECT for you. Javascript is > quite a bit harder than python to do, especially for many sorts of > project. I'd also say python has a lower barrier to entry than Java as > well. > > I'm primarily a programmer, so I used Dive into Python to get started > (4 years ago). Now this is a short PDF for programmers on python, but > its still a good, short intro to people who aren't. > http://www.diveintopython.org > > I've also went through some of "Learning Python". A new edition is > coming out in about 10 days, and I'd suggest you'd get it and go > through the exercises. Don't read them, actually type them in (don't > copy and paste), and then fiddle with them to do something different > with them. My wife (who does marketing for a living, and doesn't > program except for the occasional VBA script) is starting this book > (using the old one until the new one comes in): > http://snipurl.com/learningpython > > Another approach, one that I use from time to time to pick up a topic, > is to snarf down the course exercises of a college course that is > posted on the web. For instance, Georgia Tech's intro to programming > course is on the web for all to see at: > http://www-static.cc.gatech.edu/classes/AY2008/cs1301_fall/homework.html > > It may be easier to go through a past semester (as it will have all > the homeworks up there for you to do): > http://www-static.cc.gatech.edu/classes/AY2007/cs1301_spring/ > > One nice thing about going through the course work is that they're > trying to teach programming, and just happen to be using python. That > approach means you'll get the most important, general skills out of > it. (That course or harder ones is required for all undergrads at that > institution, so I expect you'll be able to do its coursework). > > --Michael > > -- > Michael Langford > Phone: 404-386-0495 > Consulting: http://www.TierOneDesign.com/ > Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com > > On 9/23/07, Daniel Kavic <[EMAIL PROTECTED]> wrote: > Ok I have been a multimedia major for a few years now. I have > tried > javascript and that was bad, Java is just too difficult, so I > joined > this mailing list a while back. I have been frustrated because > I just > don't get entirely how OOProgramming works and how to actually > write > the stuff correctly. I have a hard time programming and I wish > I > could be better at knowing at least one language. I need a > really > good book or something to explain this to me. I am not the > best in math > On Sep 22, 2007, at 12:46 PM, Kent Johnson wrote: > > > Ricardo Aráoz wrote: > >> Kent Johnson wrote: > > > >>> What version of Python are you using? When I try this > program it > >>> prints > >> > >> Py 0.9.5 > >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 > 32 bit > >> (Intel)] on win32 > >> > >> I thought it might be you were trying the class with the > list init > >> call > >> but I tried it and works the same way. > >> Was using PyAlaMode, tried it using IDLE and it works like > yours, > >> probably a bug of PyAlaMode. > > > > My guess is PyAlaMode is trying to introspect the objects in > some way > > and that is causing the extra access (to non-existent > attributes). > > > >>> class CallCounter(object): > >>> def __init__(self, delegate): > >>> self._delegate = delegate > >>> self.calls = 0 > >>> def __getattr__(self, name): > >>> value = getattr(self._d
Re: [Tutor] Advice for a Multimedia Major [was: Counting method calls]
Daniel Kavic wrote: > Ok I have been a multimedia major for a few years now. I have tried > javascript and that was bad, Java is just too difficult, so I joined > this mailing list a while back. I have been frustrated because I just > don't get entirely how OOProgramming works and how to actually write > the stuff correctly. I have a hard time programming and I wish I > could be better at knowing at least one language. I need a really > good book or something to explain this to me. I am not the best in math So if you want some recommendations, make your own thread. Don't post in another, unrelated thread. -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Learning a Language
First off, please don't pick a random message and reply to it. Please send an email directly to tutor@python.org if you have a new conversation topic. Some people's mail readers group emails together by what email you hit reply on, so it will put your email with messages it doesn't really belong with. That said: You're in luck, python is PERFECT for you. Javascript is quite a bit harder than python to do, especially for many sorts of project. I'd also say python has a lower barrier to entry than Java as well. I'm primarily a programmer, so I used Dive into Python to get started (4 years ago). Now this is a short PDF for programmers on python, but its still a good, short intro to people who aren't. http://www.diveintopython.org I've also went through some of "Learning Python". A new edition is coming out in about 10 days, and I'd suggest you'd get it and go through the exercises. Don't read them, actually type them in (don't copy and paste), and then fiddle with them to do something different with them. My wife (who does marketing for a living, and doesn't program except for the occasional VBA script) is starting this book (using the old one until the new one comes in): http://snipurl.com/learningpython Another approach, one that I use from time to time to pick up a topic, is to snarf down the course exercises of a college course that is posted on the web. For instance, Georgia Tech's intro to programming course is on the web for all to see at: http://www-static.cc.gatech.edu/classes/AY2008/cs1301_fall/homework.html It may be easier to go through a past semester (as it will have all the homeworks up there for you to do): http://www-static.cc.gatech.edu/classes/AY2007/cs1301_spring/ One nice thing about going through the course work is that they're trying to teach programming, and just happen to be using python. That approach means you'll get the most important, general skills out of it. (That course or harder ones is required for all undergrads at that institution, so I expect you'll be able to do its coursework). --Michael -- Michael Langford Phone: 404-386-0495 Consulting: http://www.TierOneDesign.com/ Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com On 9/23/07, Daniel Kavic <[EMAIL PROTECTED]> wrote: > > Ok I have been a multimedia major for a few years now. I have tried > javascript and that was bad, Java is just too difficult, so I joined > this mailing list a while back. I have been frustrated because I just > don't get entirely how OOProgramming works and how to actually write > the stuff correctly. I have a hard time programming and I wish I > could be better at knowing at least one language. I need a really > good book or something to explain this to me. I am not the best in math > On Sep 22, 2007, at 12:46 PM, Kent Johnson wrote: > > > Ricardo Aráoz wrote: > >> Kent Johnson wrote: > > > >>> What version of Python are you using? When I try this program it > >>> prints > >> > >> Py 0.9.5 > >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit > >> (Intel)] on win32 > >> > >> I thought it might be you were trying the class with the list init > >> call > >> but I tried it and works the same way. > >> Was using PyAlaMode, tried it using IDLE and it works like yours, > >> probably a bug of PyAlaMode. > > > > My guess is PyAlaMode is trying to introspect the objects in some way > > and that is causing the extra access (to non-existent attributes). > > > >>> class CallCounter(object): > >>> def __init__(self, delegate): > >>> self._delegate = delegate > >>> self.calls = 0 > >>> def __getattr__(self, name): > >>> value = getattr(self._delegate, name) > >>> if callable(value): > >>> self.calls += 1 > >>> return value > >>> > >>> a = CallCounter(list()) > >> > >> Sadly : > > a = CallCounter(list()) > > a.append(1) > > a.calls > >> 2 > > a.append(2) > > a.append(3) > > a.calls > >> 5 > > a[3] > >> > >> Traceback (most recent call last): > >> File "", line 1, in > >> a[3] > >> TypeError: 'CallCounter' object is unindexable > > > > Hmm. The problem is that new-style classes don't look up special > > methods > > on instances, just in the class itself. > > > > There is some discussion here, it looks a bit ugly: > > http://groups.google.com/group/comp.lang.python/browse_thread/ > > thread/c5bb6496970b5c5a?hl=en&tvc=2 > > Alex Martelli's second response proposes a solution that overrides > > __new__() to create a custom class for each wrapper. > > > > There might be some help here too, I haven't read it closely: > > http://tinyurl.com/25lx5t > > > > The code works if CallCounter is an old-style class. > > > > Kent > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailma
Re: [Tutor] Counting method calls
Ok I have been a multimedia major for a few years now. I have tried javascript and that was bad, Java is just too difficult, so I joined this mailing list a while back. I have been frustrated because I just don't get entirely how OOProgramming works and how to actually write the stuff correctly. I have a hard time programming and I wish I could be better at knowing at least one language. I need a really good book or something to explain this to me. I am not the best in math On Sep 22, 2007, at 12:46 PM, Kent Johnson wrote: > Ricardo Aráoz wrote: >> Kent Johnson wrote: > >>> What version of Python are you using? When I try this program it >>> prints >> >> Py 0.9.5 >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win32 >> >> I thought it might be you were trying the class with the list init >> call >> but I tried it and works the same way. >> Was using PyAlaMode, tried it using IDLE and it works like yours, >> probably a bug of PyAlaMode. > > My guess is PyAlaMode is trying to introspect the objects in some way > and that is causing the extra access (to non-existent attributes). > >>> class CallCounter(object): >>> def __init__(self, delegate): >>> self._delegate = delegate >>> self.calls = 0 >>> def __getattr__(self, name): >>> value = getattr(self._delegate, name) >>> if callable(value): >>> self.calls += 1 >>> return value >>> >>> a = CallCounter(list()) >> >> Sadly : > a = CallCounter(list()) > a.append(1) > a.calls >> 2 > a.append(2) > a.append(3) > a.calls >> 5 > a[3] >> >> Traceback (most recent call last): >> File "", line 1, in >> a[3] >> TypeError: 'CallCounter' object is unindexable > > Hmm. The problem is that new-style classes don't look up special > methods > on instances, just in the class itself. > > There is some discussion here, it looks a bit ugly: > http://groups.google.com/group/comp.lang.python/browse_thread/ > thread/c5bb6496970b5c5a?hl=en&tvc=2 > Alex Martelli's second response proposes a solution that overrides > __new__() to create a custom class for each wrapper. > > There might be some help here too, I haven't read it closely: > http://tinyurl.com/25lx5t > > The code works if CallCounter is an old-style class. > > Kent > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] pythons xf86misc documentation ?
Can anyone tell me where the documentation for pythons xf86misc module is, ie what methods are avalible ? Many thanks Dave -- Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] scite with python 2.51
> how do I set up scite editor with python so that I can click check > syntax and compile from the editor? You just need to setup your environment's PATH so that it knows where to find python. This probably means you need to add "C:/python25" to your path. Once you do this, restart scite, and it you will automatically be able to check syntax / compile (ctrl-1) or execute (F3) your python code. In case you don't know how to change your system's PATH variable... On windows: http://www.computerhope.com/issues/ch000549.htm On linux: http://www.linuxheadquarters.com/howto/basic/path.shtml -Fred ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unicode problem
Hi Tutors, I've just realized that i forgot to thank Kent Johnson for his advise on Unicode. Thank you kent. Best, Emad On 9/18/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > > Emad Nawfal wrote: > > *Hi All Tutors,* > > *I'm new and I'm trying to use unicode strings in my code (specifically > > Arabic), but I get this:* > > > > IDLE 1.2.1 > text = ur'المصريون' > > Unsupported characters in input > > This seems to be a problem with IDLE rather than Python itself. This > message: > http://www.thescripts.com/forum/thread543035.html > > suggests editing one of the IDLE files to make it support unicode. > Alternately you might want to use the plain Python interpreter and a > text editor that supports arabic. > > Kent > -- لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد الغزالي Emad Soliman Nawfal Indiana University, Bloomington http://emadnawfal.googlepages.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor