Re: [Tutor] How to examine the following problem
On 19/04/12 04:11, lina wrote: I meet a problem, mainly some error waring: CmdException Exception in Tk callback Function: at 0x46fdde8> (type: ) Args: () Traceback (innermost last): File "/usr/lib/python2.7/dist-packages/Pmw/Pmw_1_3/lib/PmwBase.py", line This tells us the problem originates in a PMW file File "/usr/local/bin/modules/pymol/selecting.py", line 118, in select And this says its from pymol code. The code I was downloading from http://www.biotec.tu-dresden.de/~hongboz/dssp_pymol/pymol_script/dssp_stride_pymol.py This list is for problems with the Python language and its standard library. We are not equipped to support all of the 3rd party modules out there so unless you are very lucky and somebody on the list uses pymol and can help, you will be better off asking for help on a pymol forum, or by contacting the authors. If you do that, one thing that might help is to provide information about the OS you are using, the Python version, and how you are running the code. For example, you have not provided any clues above as to what actual python code you were trying to run which caused the error message. The more context you can provide the easier it will be for the pymol experts to see what's gone wrong. -- Alan G 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] How to examine the following problem
On Thursday 19,April,2012 03:27 PM, Alan Gauld wrote: On 19/04/12 04:11, lina wrote: I meet a problem, mainly some error waring: CmdException Exception in Tk callback Function: at 0x46fdde8> (type: ) Args: () Traceback (innermost last): File "/usr/lib/python2.7/dist-packages/Pmw/Pmw_1_3/lib/PmwBase.py", line This tells us the problem originates in a PMW file Seems I have not update PMW recently. File "/usr/local/bin/modules/pymol/selecting.py", line 118, in select And this says its from pymol code. The code I was downloading from http://www.biotec.tu-dresden.de/~hongboz/dssp_pymol/pymol_script/dssp_stride_pymol.py This list is for problems with the Python language and its standard library. We are not equipped to support all of the 3rd party modules out there so unless you are very lucky and somebody on the list uses pymol and can help, you will be better off asking for help on a pymol forum, or by contacting the authors. I have asked on pymol list. none response. I also sent email to the author, none feedback yet. haha ... get my luck is a bit late? Well, I have some faith about this list. If you do that, one thing that might help is to provide information about the OS you are using, the Python version, and how you are running the code. For example, you have not provided clues above as to what actual python code you were trying to run which caused the error message. The more context you can provide the easier it will be for the pymol experts to see what's gone wrong. I installed 2.6, 2.7, 3.1, 3.2, 3.2mu But in this situation it uses the 2.7. I use debian. I guess something become incompatible using his plugin. Thanks, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to select a player to play first on a multiplayer game which runs on IRC
I am writing tic tac toe game which runs on IRC (i am using freenode now). Each player will be a channel member. So, players send private messages between each other to play game. This sounds fine but I need the below things to get done, but I don't know how to do them.. How my game works: Each player will have my program (tictactoe.exe). So, each player has to enter a unique Nick Name for them and a their's friend's nick name to play : ## Now, I want to know whether the player is on the channel or not. for that I need a list of nick's on the channel. How to get them? The biggest problem is here: ## How to select a player to play first... ??? How do I get this done? Help me!!!___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to select a player to play first on a multiplayer game which runs on IRC
On 04/19/2012 06:54 AM, Surya K wrote: > I am writing tic tac toe game which runs on IRC (i am using freenode now). > Each player will be a channel member. So, players send private messages > between each other to play game. This sounds fine but I need the below things > to get done, but I don't know how to do them.. > How my game works: > Each player will have my program (tictactoe.exe). > So, each player has to enter a unique Nick Name for them and a their's > friend's nick name to play : > ## Now, I want to know whether the player is on the channel or not. for that > I need a list of nick's on the channel. How to get them? I can't help there. > The biggest problem is here: > ## How to select a player to play first... ??? How do I get this done? > > In a peer-to-peer connection, there are a number of situations where you have to break symmetry. This is one of them, though not the first. Since you don't have a 3rd party arbiter, the two endpoints have to agree between themselves which of them is to be the arbiter when both sides need to agree on something. Once you've chosen the arbiter, then each decision is made by asking the arbiter. Start by choosing a large "random" number (or guid) at each end. Each sends his own guid along with the two nick-names to propose the new game. One of the guids will be larger, and that machine is the arbiter. The first conflict to be resolved this way is not who goes first, but how you make sure you only have one game between any two endpoints. What happens if more than two players are present, and what happens if more than one of them picks the same nickname? Are you going to permit one of the players to play against two others at the same time, and how will you keep the games straight? You need a connection token for each running game, and that's probably the first time you need an arbiter. The second case is choosing who goes first. The arbiter probably chooses that randomly, and notifies the other player. The third case is how to handle miscommunication. Messages can be lost between the end points, and you may have to reconstruct the state, so both ends get back in synch. Fourth is how to quit. If one player quits, the other might not get notified correctly, so you have to keep the connection token for a while, to aid cleanup. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Readabilty vs 80 characters
Hi! I have a question about style. In PEP-8, it says don't exceed 79 characters, but can this rule ever be trumped by readability? Eg. if someobject.filter(something) \ .filter(somethingreallyreallyreallyreallylong == somethingelsereallyreallylong) \ .filter(othethingreallylongreallyreally == ternarythingreallyreallyreallylong) \ .filter(thirdthingreallylessreallymaybelong == thirdotherthingreallylong) \ .first(): < do something > if someobject.filter(something) \ .filter(somethingreallyreallyreallyreallylong == \ somethingelsereallyreallylong) \ .filter(othethingreallylongreallyreally == \ ternarythingreallyreallyreallylong ) \ .filter(thirdthingreallylessreallymaybelong == \ thirdotherthingreallylong) \ .first(): < do something > The first example is more readable to me but violates the 80 character rule. The second is less readable, but doesn't violate the 80 character rule. Is there a guideline or convention that pythonistas follow about this style case? Thanks, Tino ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to select a player to play first on a multiplayer game which runs on IRC
> Date: Thu, 19 Apr 2012 07:24:33 -0400 > From: d...@davea.name > To: sur...@live.com > CC: tutor@python.org; bgai...@gmail.com > Subject: Re: [Tutor] how to select a player to play first on a multiplayer > game which runs on IRC > > On 04/19/2012 06:54 AM, Surya K wrote: > > I am writing tic tac toe game which runs on IRC (i am using freenode now). > > Each player will be a channel member. So, players send private messages > > between each other to play game. This sounds fine but I need the below > > things to get done, but I don't know how to do them.. > > How my game works: > > Each player will have my program (tictactoe.exe). > > So, each player has to enter a unique Nick Name for them and a their's > > friend's nick name to play : > > ## Now, I want to know whether the player is on the channel or not. for > > that I need a list of nick's on the channel. How to get them? > I can't help there. > > > The biggest problem is here: > > ## How to select a player to play first... ??? How do I get this done? > > > > > > In a peer-to-peer connection, there are a number of situations where you > have to break symmetry. This is one of them, though not the first. > Since you don't have a 3rd party arbiter, the two endpoints have to > agree between themselves which of them is to be the arbiter when both > sides need to agree on something. Once you've chosen the arbiter, then > each decision is made by asking the arbiter. > > Start by choosing a large "random" number (or guid) at each end. Each > sends his own guid along with the two nick-names to propose the new > game. One of the guids will be larger, and that machine is the arbiter. > > The first conflict to be resolved this way is not who goes first, but > how you make sure you only have one game between any two endpoints. > What happens if more than two players are present, and what happens if > more than one of them picks the same nickname? Are you going to permit > one of the players to play against two others at the same time, and how > will you keep the games straight? You need a connection token for each > running game, and that's probably the first time you need an arbiter. > Actually, as in a IRC channel, each user should have a unique nick name, the problem is resolved.Actually, in this game, the 2 players will have a private chat.. so, there would be no chance that other person will come into picture. Rather that doing all this mess, I want to put a server on Google App Engine and run clients on my PC. But I don't know how!! I have to know Google API for writing GAE app's using python 2.7 Lets say, I have created a server using python 2.7, can you tell me how to run it on GAE ?? (Assuming, I haven't used any google api).. Actually, I don't need any Templates, nice HTML pages on Google App. Its enough to just mention how many peers are connected at that particular instant... can you tell me how to do that?? > The second case is choosing who goes first. The arbiter probably > chooses that randomly, and notifies the other player. The third case is > how to handle miscommunication. Messages can be lost between the end > points, and you may have to reconstruct the state, so both ends get back > in synch. Fourth is how to quit. If one player quits, the other might > not get notified correctly, so you have to keep the connection token for > a while, to aid cleanup. > > > > -- > > DaveA > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Readabilty vs 80 characters
On Thu, 19 Apr 2012, Tino Dai wrote: Hi! I have a question about style. In PEP-8, it says don't exceed 79 characters, but can this rule ever be trumped by readability? PEP 8 is style guidelines, not hard and fast rules or they wouls be syntax errors. But that would just be annoying, so yes, there are cases where you would want to extend... Eg. if someobject.filter(something) \ .filter(somethingreallyreallyreallyreallylong == somethingelsereallyreallylong) \ .filter(othethingreallylongreallyreally == ternarythingreallyreallyreallylong) \ .filter(thirdthingreallylessreallymaybelong == thirdotherthingreallylong) \ .first(): < do something > if someobject.filter(something) \ .filter(somethingreallyreallyreallyreallylong == \ somethingelsereallyreallylong) \ .filter(othethingreallylongreallyreally == \ ternarythingreallyreallyreallylong ) \ .filter(thirdthingreallylessreallymaybelong == \ thirdotherthingreallylong) \ .first(): < do something > The first example is more readable to me but violates the 80 character rule. The second is less readable, but doesn't violate the 80 character rule. This is exactly what the style guide is meant to help. Regardless of which format you chose here I would tell you that both ways are wrong. The right way is to fix your algorithm (how you solve the problem) so you don't have to have such an insane amount of code on one line. Of course this isn't a hard and fast rule either, but I'd say about 99% of the time a lot of nesting or chaining indicates a broken flow (even if the logic is 100% accurate). Is there a guideline or convention that pythonistas follow about this style case? Refactor! hth, Wayne___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Readabilty vs 80 characters
> I have a question about style. In PEP-8, it says don't exceed 79 > characters, but can this rule ever be trumped by > readability? > > Eg. > > > if someobject.filter(something) \ > .filter(somethingreallyreallyreallyreallylong == > somethingelsereallyreallylong) \ > .filter(othethingreallylongreallyreally == > ternarythingreallyreallyreallylong) \ > .filter(thirdthingreallylessreallymaybelong == > thirdotherthingreallylong) \ > .first(): > < do something > > > if someobject.filter(something) \ > .filter(somethingreallyreallyreallyreallylong == \ >somethingelsereallyreallylong) \ > .filter(othethingreallylongreallyreally == \ > ternarythingreallyreallyreallylong ) \ > .filter(thirdthingreallylessreallymaybelong == \ >thirdotherthingreallylong) \ > .first(): > < do something > > > > The first example is more readable to me but violates the 80 character > rule. The second is less readable, but doesn't violate > the 80 character rule. > > Is there a guideline or convention that pythonistas follow about this > style case? It is a guideline, not a rule. Usually your (work) environment or common sense trumps the guideline. On a side note, if you wrap that if statement with a parenthesis you can avoid the error prone '\' at the end of each line if ( someobject.filter(something) .filter(somethingreallyreallyreallyreallylong == somethingelsereallyreallylong) .filter(othethingreallylongreallyreally == ternarythingreallyreallyreallylong ) .filter(thirdthingreallylessreallymaybelong == thirdotherthingreallylong) .first() ): < do something > Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Readabilty vs 80 characters
On 19 Apr, 2012, at 15:29 , Tino Dai wrote: > Hi! > > I have a question about style. In PEP-8, it says don't exceed 79 > characters, but can this rule ever be trumped by > readability? > Yes, it obviously can. I am a big fan of the 79 character "rule", though. Even with screens and terminals being well over 79 characters wide these days: with the 79 character limit, I can have multiple things side by side (*without* using multiple screens). > Eg. > > > if someobject.filter(something) \ > .filter(somethingreallyreallyreallyreallylong == > somethingelsereallyreallylong) \ > .filter(othethingreallylongreallyreally == > ternarythingreallyreallyreallylong) \ > .filter(thirdthingreallylessreallymaybelong == > thirdotherthingreallylong) \ > .first(): > < do something > > > if someobject.filter(something) \ > .filter(somethingreallyreallyreallyreallylong == \ >somethingelsereallyreallylong) \ > .filter(othethingreallylongreallyreally == \ > ternarythingreallyreallyreallylong ) \ > .filter(thirdthingreallylessreallymaybelong == \ >thirdotherthingreallylong) \ > .first(): > < do something > I would let the parenthesis do the line breaking, so not use backslashes (a hidden space after a backslash can be hard to spot). In my case, it would become something like: if someobject.filter( something).filter( somethingreallyreallyreallyreallylong == somethingelsereallyreallylong).filter( othethingreallylongreallyreally == ternarythingreallyreallyreallylong).filter( thirdthingreallylessreallymaybelong == thirdotherthingreallylong).first(): pass Of course, this isn't very readable either: the filter() function starts at the end of a line, and the comparison is broken over two lines. Note that I've left my editor (emacs) do the indentation. It would have helped to indent the second part of the comparison just a bit. Then again, one can (and should) ask whether somethingreallyreallyreallyreallylong is really a good name for a variable. Occasionally, it does happen in case of dicts within dicts within list, eg mylist[counter]['somekey']['anotherkey'], but those are the cases where you would assign this to a separate (temporary) variable. > The first example is more readable to me but violates the 80 character rule. > The second is less readable, but doesn't violate > the 80 character rule. > > Is there a guideline or convention that pythonistas follow about this style > case? Not as such, I think. But, if lines get long or indentation gets heavy (4 or more indents), it may be good to consider two things: - move parts to a separate function - assign parts to a temporary variable. In your case, the outcome of the various comparisons could be assigned to individual variables: result1 = somethingreallyreallyreallyreallylong == somethingelsereallyreallylong result2 = othethingreallylongreallyreally == ternarythingreallyreallyreallylong etc and then the last line becomes someobject.filter(something).filter(result1).filter(result2).filter(… Or, since filter() apparently returns a new object: results1 = someobject.filter(something) results2 = result1.filter(somethingreallyreallyreallyreallylong == somethingelsereallyreallylong) results3 = result2.filter(othethingreallylongreallyreally == ternarythingreallyreallyreallylong) etc In both cases, you have changed the backslashes into actual separate statements. (And yes, those lines still are longer than 79 characters, but to me it becomes more readable overall, even if you would break those individual statements.) So, basically, when you run into something like your suggestion here, try and see another way of breaking it up then just splitting across multiple lines. Cheers, Evert > > Thanks, > Tino > > > ___ > 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] Readabilty vs 80 characters
Tino Dai wrote: > Hi! > > I have a question about style. In PEP-8, it says don't exceed 79 > characters, but can this rule ever be trumped by > readability? > > Eg. > > > if someobject.filter(something) \ > .filter(somethingreallyreallyreallyreallylong == > somethingelsereallyreallylong) \ > .filter(othethingreallylongreallyreally == > ternarythingreallyreallyreallylong) \ > .filter(thirdthingreallylessreallymaybelong == > thirdotherthingreallylong) \ > .first(): > < do something > > > if someobject.filter(something) \ > .filter(somethingreallyreallyreallyreallylong == \ >somethingelsereallyreallylong) \ > .filter(othethingreallylongreallyreally == \ > ternarythingreallyreallyreallylong ) \ > .filter(thirdthingreallylessreallymaybelong == \ >thirdotherthingreallylong) \ > .first(): > < do something > > > > The first example is more readable to me but violates the 80 character > rule. The second is less readable, but doesn't violate > the 80 character rule. > > Is there a guideline or convention that pythonistas follow about this > style case? I would give you a thoughtful answer, but I am currently facing a serious problem myself: my stretch limo doesn't fit into my garage. Should I drive through the back wall or block the street with the part that sticks out? Seriously, learn that you don't need backslashes if you put the expression into parens, precalculate parts of the expression and put them into temporary variables -- and if that doesn't suffice to keep the code readable and below the 80 char threshold reread the part of the PEP with the Emerson quote ("A foolish consistency..."). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to run a small python client-server on Google App Engine
I wrote a small python Client-Server program.. (I use python 2.7) and want to make it real. I mean, I want to put the server on Google App Engine.. I went through it and found that, I need to use Google API so that it should work on GAE. So, How could I create such a small Google App Engine's app. I mean.. Can anyone help me on it..(Assuming that there is a server.py which just shows how many clients are connected to it, how do I make a app of such program) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to run a small python client-server on Google App Engine
I suppose you could run something persistent on a reserved instance at Google App Engine, but typically they kill any process running longer than 30 seconds. And the persistent servers aren't free. On Apr 19, 2012 7:36 AM, "Surya K" wrote: > I wrote a small python Client-Server program.. (I use python 2.7) > > and want to make it real. I mean, I want to put the server on Google App > Engine.. > > I went through it and found that, I need to use Google API so that it > should work on GAE. > > So, How could I create such a small Google App Engine's app. I mean.. > > Can anyone help me on it.. > (Assuming that there is a server.py which just shows how many clients are > connected to it, how do I make a app of such program) > > > ___ > 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] .py vs .pyc
Could anyone tell me why I should use a .pyc file rather than a .py? After doing some research, I have found that a .py file is first precompiled and then run, while a .pyc file is already precompiled and is simply run. But unless I'm mistaken, it seems that a .pyc is no faster or better than a .py file. When should I use a .py, and when should I use a .pyc? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] .py vs .pyc
Then if I understand correctly, I work with .py files and (should) run them as .pyc files? On Thu, Apr 19, 2012 at 10:55 AM, Russel Winder wrote: > On Thu, 2012-04-19 at 10:47 -0400, Max S. wrote: > > Could anyone tell me why I should use a .pyc file rather than a .py? > After > > doing some research, I have found that a .py file is first precompiled > and > > then run, while a .pyc file is already precompiled and is simply run. > But > > unless I'm mistaken, it seems that a .pyc is no faster or better than a > .py > > file. When should I use a .py, and when should I use a .pyc? > > pyc files are just internal PVM files. Although they appear on the > filestore visible to the programmer, just leave management of them to > the PVM. Humans deal only with .py files -- or possibly pyx if you are > using Cython. > > -- > Russel. > > = > Dr Russel Winder t: +44 20 7585 2200 voip: > sip:russel.win...@ekiga.net > 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk > London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] .py vs .pyc
On Thu, 2012-04-19 at 10:47 -0400, Max S. wrote: > Could anyone tell me why I should use a .pyc file rather than a .py? After > doing some research, I have found that a .py file is first precompiled and > then run, while a .pyc file is already precompiled and is simply run. But > unless I'm mistaken, it seems that a .pyc is no faster or better than a .py > file. When should I use a .py, and when should I use a .pyc? pyc files are just internal PVM files. Although they appear on the filestore visible to the programmer, just leave management of them to the PVM. Humans deal only with .py files -- or possibly pyx if you are using Cython. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Readabilty vs 80 characters
On Thu, 2012-04-19 at 16:00 +0200, Peter Otten wrote: [...] > Seriously, learn that you don't need backslashes if you put the expression > into parens, precalculate parts of the expression and put them into > temporary variables -- and if that doesn't suffice to keep the code readable > and below the 80 char threshold reread the part of the PEP with the Emerson > quote ("A foolish consistency..."). I agree that where there is a backslash in a Python program, there is a better layout that doesn't have it. I wouldn't agree though that, necessarily, decomposing long expression using temporary variables improves anything. A good fluent API leads to function call chaining, far fewer variables, and far more readable code. Much of the time, not always, of course. There is currently a definite trend (*) away from 1960s FORTRAN style code structuring, to a 1980s Miranda (think Haskell and Scala) type thinking about how to structure code. There is experimental evidence in psychology of programming that declarative expression leads to more easily comprehensible code. This isn't advocacy research as much of programming research has been. Even C++ is going to a more declarative mode of expression, along with Java. Python's list comprehensions fit into this trend. (*) Which may turn out just to be just the latest fashion ready to be replaced in 2013. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] .py vs .pyc
On Thu, 2012-04-19 at 10:57 -0400, Max S. wrote: > Then if I understand correctly, I work with .py files and (should) run > them as .pyc files? No, you always run the py files, don't worry about the pyc files at all, the PVM will do what it does. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Readabilty vs 80 characters
On 4/19/2012 6:29 AM Tino Dai said... Hi! I have a question about style. In PEP-8, it says don't exceed 79 characters, but can this rule ever be trumped by readability? It's trumped by something: >>> for ii in range(10): ... D="*/"*ii+"*.py" ... L=glob.glob(D) ... for pypgm in L: ... pgm = open(pypgm,'r').readlines() ... totalLines+=len(pgm) ... LongLines.extend([(pypgm,jj) for jj in pgm if len(jj)>79]) ... >>> >>> print len(LongLines),totalLines 12043 606760 >>> Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] .py vs .pyc
On 19/04/12 15:47, Max S. wrote: Could anyone tell me why I should use a .pyc file rather than a .py? You don't, python handles that for you. They only come into effect on import statement. When Python imports the module it will use the pyc if available (and more recent that the .py). Don't try to second guess this just let Python do what it does. After doing some research, I have found that a .py file is first precompiled and then run, while a .pyc file is already precompiled and is simply run. But unless I'm mistaken, it seems that a .pyc is no faster or better than a .py file. The pyc file will be imported faster because python will not need to do the initial precompile. Other than that small improvement it should make no difference. -- Alan G 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] how to select a player to play first on a multiplayer game which runs on IRC
On 19/04/12 14:41, Surya K wrote: Rather that doing all this mess, I want to put a server on Google App Engine and run clients on my PC. But I don't know how!! Neither do I, nor I suspect most folks on this list. But there might be a few who do. The list is for learning the core Python language and library, esoteric 3rd party libraries and frameworks are a bit off topic. But you might get lucky. I have to know Google API for writing GAE app's using python 2.7 That seems reasonable if you want to use it. Presumably Google have support forums that you can ask questions on? -- Alan G 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
[Tutor] RuntimeError: maximum recursion depth exceeded
I have seen in a few places where this means my program is essentially in an endless loop, but as far as I can see it is formatted correctly. Any help would be greatly appreciated. Thanks in advance. #This function defines the main calls in this program def main(): mealPrice = getMeal() #call to get the meal price before tip and tax tipPercent = getTip(mealPrice) #call to get the total tip based on meal price stateTax = getTax(mealPrice)#call to get the total tax based on meal price mealTotal = getTotal(mealPrice,tipPercent,stateTax) #call to get the total cost including tip and tax #This function gets the original meal price before tax and tip are added def getMeal(): mealPrice = input ('Enter the price of the meal $ ') mealPrice = float (mealPrice) return mealPrice #This function gets the tip which will be added to the meal def getTip(mealPrice): tipPercent = getTip(mealPrice) if mealPrice >= 25.01: tipPercent == .22 elif mealPrice >= 17.01: tipPercent == .19 elif mealPrice >= 12.01: tipPercent == .16 elif mealPrice >= 6: tipPercent == .13 else: tipPercent == .10 return tipPercent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] RuntimeError: maximum recursion depth exceeded
On 2012-04-19 21:51, James Stauble wrote: I have seen in a few places where this means my program is essentially in an endless loop, but as far as I can see it is formatted correctly. Any help would be greatly appreciated. Thanks in advance. [snip] #This function gets the tip which will be added to the meal def getTip(mealPrice): tipPercent = getTip(mealPrice) As soon as you enter "getTip()" you immediately call it again and again and again ... without a chance to break out of this endless loop. As far as I can tell from your code snippet you don't need the line tipPercent = getTip(mealPrice) Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] RuntimeError: maximum recursion depth exceeded
On 19/04/12 20:51, James Stauble wrote: I have seen in a few places where this means my program is essentially in an endless loop, Yes same here. Its not necessarily an endless loop it may just be processing more items that Pythons call stack can hamndle, but in this case it is endless. #This function gets the tip which will be added to the meal def getTip(mealPrice): tipPercent = getTip(mealPrice) Here it is, you call the same function recursively with no break condition. But you don't want a loop here anyway you just want the tip which is a one-off calculation. In general its best to restrict the use of recursion in Python to traversing recursive data structures (like trees and linked lists), and even then only where you know the depth will be well within Python's recursion limit (usually set to 1000 I think). And always, always, always, write recursive functions to have a termination condition, usually at the top of the function. Then ensure the recursive calls move the function towards that condition if at all possible. If you can't write it that way you should recode it as a regular loop. HTH, -- Alan G 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
[Tutor] Thanks Everyone!!!
Thanks for the tips everyone! I am fairly new to programming and am finding myself both bewildered and amazed. Its fun when it works, but boy oh boy, when it doesn't Anyway thanks again, you all have been very helpful. [?] <<330.gif>>___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor