Re: [Tutor] class methods: using class vars as args?
On 23/05/2010 20:40, Alex Hall wrote: Hello all, I know Python reasonably well, but I still run into basic questions which those over on the other python list request I post here instead. I figure this would be one of them: Why would this not work: class c(object): def __init__(self, arg1, arg2): self.arg1=arg1 self.arg2=arg2 def doSomething(self, arg3=self.arg1): ... The above results in an error that "name 'self' is not defined". Why can I not set the default values of a method's arguments to class vars like that? Thanks! You've already had some explanations as to what happens, but what are you trying to achieve? Why don't you forget about arg3 because it is arg1, which must exist by creating an instance of class c, or you wouldn't be able to call doSomething in the first place? HTH. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list of dicts <-> dict of lists?
I confess that I don't like top posting :) Please see below. On 28/05/2010 00:19, Matthew Wood wrote: #!/usr/bin/env python Here's my best attempt. I'm not sure if it's "simpler" than yours, but for me it seems a bit cleaner. Then again, I LOVE the zip operator, and the '*' operator too. :-) Whenever I see a "transpose this" type problem, I think zip. y = {'a': [1, 2, 3], 'c': [7, 8, 9], 'b': [4, 5, 6]} print y old = [dict([(i, y[i][j]) for i in y.keys()]) for j in range(len(y[y.keys()[0]]))] print old keys, values = zip(* y.items()) new = [dict([(i, j) for i, j in zip(keys, column)]) for column in zip(* values)] print new print new == old I BELIEVE there's some new cool features in 2.6 or maybe 3.0 where non-simultaneous access to my_dict.keys() and my_dict.values() will keep them "paired up", but I don't know the details. If you skipped the upper line (setting keys and values) you'd be accessing y.keys() 3 times (in this example). I'm not sure if you're guaranteed to have the order remain the same for all three accesses. If that's the case, I'd change the code to be: # This line isn't necessary #keys, values = zip(* y.items()) new = [dict([(i, j) for i, j in zip(y.keys(), column)]) for column in zip(* y.values())] or even # This line isn't necessary #keys, values = zip(* y.items()) new = [dict([(i, j) for i, j in zip(y, column)]) for column in zip(* y.values())] RTFM? :) From the Python docs for 2.6.5 "items() Return a copy of the dictionary’s list of (key, value) pairs. CPython implementation detail: Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions. If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond. This allows the creation of (value, key) pairs using zip(): pairs = zip(d.values(), d.keys()). The same relationship holds for the iterkeys() and itervalues() methods: pairs = zip(d.itervalues(), d.iterkeys()) provides the same value for pairs. Another way to create the same list is pairs = [(v, k) for (k, v) in d.iteritems()]." But since I'm a coward, and I'd like my code to run on older versions of python too, I'd leave the initial step. -- I enjoy haiku but sometimes they don't make sense; refrigerator? On Thu, May 27, 2010 at 4:15 PM, David Perlman wrote: Using the csv.DictReader and csv.DictWriter lets you read and write lists of dictionaries from files containing tabular data. I have a system that naturally generates tabular data in the form of a dictionary of lists: the dictionary key is the name of the column, and then the value is a list which contains the data for that column. Sort of like a spreadsheet. I would like to use csv.DictWriter to write out this data but that requires a list of dicts. I can convert the dict of lists to a list of dicts, and thus make it compatible with csv.DictWriter, with the following ugly comprehensions: y {'a': [1, 2, 3], 'c': [7, 8, 9], 'b': [4, 5, 6]} [dict([(i,y[i][j]) for i in y.keys()]) for j in range(len(y[y.keys()[0]]))] [{'a': 1, 'c': 7, 'b': 4}, {'a': 2, 'c': 8, 'b': 5}, {'a': 3, 'c': 9, 'b': 6}] ...but I'm wondering if anyone knows of a more elegant way, perhaps something built-in suited for this purpose... I am aware that any solution will only work if the lists in the dict are all the same length. :) Thanks! -- -dave "Pseudo-colored pictures of a person's brain lighting up are undoubtedly more persuasive than a pattern of squiggles produced by a polygraph. That could be a big problem if the goal is to get to the truth." -Dr. Steven Hyman, Harvard ___ 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 maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] class methods as static methods?
On 29/05/2010 20:49, Alex Hall wrote: Hi all, In Battleship, I have a weapons.py file, currently with just one missile type (a Harpoon anti-ship missile). This Harpoon class defines a getImpactCoords method, which returns all coordinates on the map that it will hit. I would like to not instantiate a Harpoon object, just call the Harpoon's getImpactCoords method and pass it the required arguments. Is this possible? Thanks. Sorry if I got the terms backwards in the subject; I can never remember which is static and which is non-static. Hi Alex, See you're still going for it :) I think that you're trying to build a Yamoto/Musashi before you've built a raft from oil drums or whatever :) If I'm wrong, I'll apologise here and now. For a really great introduction to Python, I suggest diveintopython, it's what got me going eight years ago. Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] class methods as static methods?
Hi Alex, thanks for the response, please see below. On 30/05/2010 02:50, Alex Hall wrote: On 5/29/10, Mark Lawrence wrote: On 29/05/2010 20:49, Alex Hall wrote: Hi all, In Battleship, I have a weapons.py file, currently with just one missile type (a Harpoon anti-ship missile). This Harpoon class defines a getImpactCoords method, which returns all coordinates on the map that it will hit. I would like to not instantiate a Harpoon object, just call the Harpoon's getImpactCoords method and pass it the required arguments. Is this possible? Thanks. Sorry if I got the terms backwards in the subject; I can never remember which is static and which is non-static. Hi Alex, See you're still going for it :) I think that you're trying to build a Yamoto/Musashi before you've built a raft from oil drums or whatever :) If I'm wrong, I'll apologise here and now. I have built one app in Python and have experience in Java and Javascript, as well as some in PHP; in fact, I am going into my fourth year of college for a computer science degree in September. While they have not done as much programming as I would like, I have had enough that I can find the commonalities between languages and generally know what I am looking for (make this public, turn that into a class instead of an independent collection of vars...) That said, I have no professional experience programming and do only assigned problems and hobby-level programming. My Screenless Widgets app is nearing beta testing and works to my satisfaction, but I am sure there is much I could do to improve it. Still, everyone has to start somewhere... I say all this not to express any offense at your message - believe me, none taken - but rather to tell everyone just where I am coming from. I should hope not, I used to be big-headed, but now I'm perfect :) For a really great introduction to Python, I suggest diveintopython, it's what got me going eight years ago. I feel that I understand the basics; what I am running into are things that crop up and I learn them as needed; if I learn a concept but then never use it, I will forget it, or mix it up with a similar comcept in another language, so I generally attack things by reading intro tutorials, modifying them, and then continuing from there until I feel that I can start my own project from scratch and figure out the pieces as I go along. I suggest that you do *NOT* understand the basics, at least wrt Python, otherwise you would not have placed your original queries on c.l.py, before being asked to move to this ng/ml. Regardless of that, you're on *THE* finest group of mls/ngs going for getting very sound advice from some of the most highly respected guys/gals going. And if you want some kind of feeling of industry experiences, subscribe to the Python bugs/development/ideas ngs/mls (if you haven't already done so) and you'll very rapidly get an idea of just how difficult software development can get. As an example, look for the thread on comp.lang.python within the last 24 hours from myself subject "xrange issue 7721". A relatively simple thing you'd have thought, but read the background on the Python bug tracker, and you'll see it ain't quite that easy. But then, what do I know, I've only 34 years industry experience, albeit slightly tempered over the last nine years by physical and mental ill health. Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I'm now going to bed, as it's 04:08 BST and I'm absolutely shattered. Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] matmolplot
On 01/06/2010 14:14, saurabh agrawal wrote: Hi, I am trying to make plot using following code:---#!/usr/bin/pythonimport numpy as npimport matplotlib.pyplot as pltimport stringfrom pylab import savefigfrom sys import argv #input file as first argumentf1=argv[1]f = open(f1,'r')line=f.readlines()f.close() f2 = f1.split(".")#f3 = f2[0].split("-") l1=[];l2=[]for lines in line: lin=lines.split() l1.append(float(lin[0])) l2.append(float(lin[1])) #print max(l2) for i in range(len(l2)): plt.axvline(x=l1[i], ymin=0, ymax=l2[i], linewidth=2, color='r') plt.axis([350, 650, 0.0, max(l2)])plt.grid(True)savefig(f2[0]+"-"+"uv.png",dpi=(600/8))plt.show() My problem is the output plot I am getting is not showing correct values in the plot as are in the input file (MS.txt - attached). It looks like it is scaled to lower value. Please help. Regards, Saurabh ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor If I've managed to reformat your code correctly, the problem is the call to plt.axis which sets xmin to 350, compare this to your data values where the lowest value of x is 233.27. Note that there is also a matplotlib mailing list. HTH. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] while loops causing python.exe to crash on windows
On 07/06/2010 01:44, Alex Hall wrote: Further to the other comments that you've had, could you please refer to the following, thanks. http://www.catb.org/~esr/faqs/smart-questions.html Kindest regards. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] a class query
On 07/06/2010 16:12, pyt...@bdurham.com wrote: Not the OP, but I was surprised to see class Name() work (in Python 2.6.5 at least). Is this equivalent to class Name( object ) or does this create an old style class? Going forward into the 2.7/3.x world, is there a preferred style? Thanks, Malcolm ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor RTFM? :) Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] a class query
On 07/06/2010 17:03, pyt...@bdurham.com wrote: Hi Mark, I was surprised to see class Name() work (in Python 2.6.5 at least). Is this equivalent to class Name( object ) or does this create an old style class? Going forward into the 2.7/3.x world, is there a preferred style? RTFM? :) I am reading TFM :) Here's why I'm confused. The following paragraph from TFM seems to indicate that old style classes are the default: Quote: For compatibility reasons, classes are still old-style by default. New-style classes are created by specifying another new-style class (i.e. a type) as a parent class, or the “top-level type” object if no other parent is needed. The behaviour of new-style classes differs from that of old-style classes in a number of important details in addition to what type() returns. Some of these changes are fundamental to the new object model, like the way special methods are invoked. Others are “fixes” that could not be implemented before for compatibility concerns, like the method resolution order in case of multiple inheritance. http://docs.python.org/reference/datamodel.html#newstyle Yet TFM for 2.6.5 shows all class examples without specifying a parent class. http://docs.python.org/tutorial/classes.html I've been taught that the proper way to create new style classes has been to always specify an explicit "object" parent class when creating a new class not based on other classes. Somewhere along the line I seemed to have missed the fact that it is no longer necessary to define classes with 'object' as a parent in order to get a new style class. In other words, it seems that the following are now equivalent: class Name: -AND- class Name( object ): My impression was the "class Name:" style created an old style class. Thanks for your help! Malcolm ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Hi Malcolm, I see that Stephen D'Aprano has already replied twice so I won't bother. Apart from that no offence meant, I hope none taken. Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] a class query
On 07/06/2010 17:30, pyt...@bdurham.com wrote: Hi Mark, I see that Stephen D'Aprano has already replied twice so I won't bother. Apart from that no offence meant, I hope none taken. Your RTFM reply actually gave me a good laugh. No (zero) offence taken. And I appreciate your many helpful posts in these forums. Cheers, Malcolm ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Hi Malcolm, Thanks for your kind response. Mind you it will cost you, if you ever get into my neck of the woods it will be at least 2 pints of Ringwood Old Thumper. Cheers. Mark. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with Importing into the Python Shell
On 12/06/2010 05:50, Andrew Martin wrote: Hey, everyone, I am new to programming and just downloaded Python 2.6 onto my windows vista laptop. I am attempting to follow 4.11 of the tutorial called "How to Think Like a Computer Scientist: Learning with Python v2nd Edition documentation" ( http://openbookproject.net/thinkcs/python/english2e/ch04.html). However, I am having some trouble. First off, I do not understand how to import things into the python shell. I have a script I saved as chap03.py, but when I try to import it into the python shell i get an error like this: from chap03 import * This is generally considered bad practice, I'll let you do some research to find out why. :) Traceback (most recent call last): File "", line 1, in from chap03 import * File "C:/Python26\chap03.py", line 2 print param param ^ SyntaxError: invalid syntax The chap03.py file is a simple one that looks like this: def print_twice(param): print param param One of the great advantages of Python is trying things from an interactive prompt, so let's go. c:\Users\Mark\python>python Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def print_twice(param): ... print param param File "", line 2 print param param ^ SyntaxError: invalid syntax So it is! What's print_twice trying to do, let's guess? >>> def print_twice(param): ... print param, param ... >>> print_twice('Hi Andrew') Hi Andrew Hi Andrew >>> Better! See how I slotted that comma into the function print_twice, just hope my guess is right. So run up some editor/IDE and slap that comma in there, it should at least keep you going. My second problem is that I need to install and import GASP in order to follow the tutorial. When I tried to do import it, I ran into an error like this: from gasp import * Traceback (most recent call last): The line above basically says "start reading from the bottom up" File "", line 1, in from gasp import * File "C:\Python26\lib\site-packages\gasp\__init__.py", line 1, in from api import * File "C:\Python26\lib\site-packages\gasp\api.py", line 1, in import backend File "C:\Python26\lib\site-packages\gasp\backend.py", line 7, in except ImportError: raise 'Pygame is not installed. Please install it.' TypeError: exceptions must be old-style classes or derived from BaseException, not str The TypeError means exactly what it says. The ImportError is trying to raise an exception, but what follows is a string type, not an exception type. Just install Pygame to get yourself going, at some point in the tutorial you're bound to run into exception handling. Can anybody help me with this? Thanks a lot P.S. SORRY FOR THE LONG EMAIL By some standards this doesn't even qualify as short, it's just a snippet. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor HTH, and keep asking as Python lists are renowned for their friendlyness. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to model objects aimed to persistence?
On 16/06/2010 21:39, Knacktus wrote: Hi everyone, within a python application I can easily model object association with simple references, e.g.: # class FavoritMovies(object): def __init__(self, movies): self.movies = movies class Movie(object): def __init__(self, name, actor): self.name = name self.actor = actor gladiator = Movie("Gladiator", "Russel Crowe") my_favorit_movies = FavoritMovies([gladiator]) kung_fu_panda = Movie("Kung Fu Panda", "Jack Black") your_favorit_movies = FavoritMovies([gladiator, kung_fu_panda]) ## So far, so good. But what is best practise to prepare this data for general persistence? It should be usable for serialisation to xml or storing to an RDBMS or ObjectDatabase ... I guess I have to incorporate some kind of id for every object and use this as reference with some kind of look-up dictionary, but I wouldn't like it and hope that there're some other sweet pythonic solutions? Cheers, Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Hi Jan, I guess you're looking for something like the shelve or pickle modules. http://docs.python.org/library/shelve.html http://docs.python.org/library/pickle.html HTH. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help
On 17/06/2010 08:28, KB SU wrote: help ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Help, I need somebody, Help, not just anybody, Help, you know I need someone, help. I'll leave you to find out the rests of the lyrics. :) Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help
On 17/06/2010 19:22, Lowell Tackett wrote: From the virtual desk of Lowell Tackett --- On Thu, 6/17/10, Mark Lawrence wrote: From: Mark Lawrence Subject: Re: [Tutor] help To: tutor@python.org Date: Thursday, June 17, 2010, 8:30 AM On 17/06/2010 08:28, KB SU wrote: help Help, I need somebody, Help, not just anybody, Help, you know I need someone, help. I'll leave you to find out the rests of the lyrics. :) Mark Lawrence. You're "dating" yourself! (I was in 'Nam when that song came out.) Jeesh, unlucky you :( (I was in shorts at our village primary school) Another lyric, "I hope I die before I get old", similar sort of era, eh? :) Regards. Mark Lawrence. ___ 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] Question
On 19/06/2010 04:55, Independent Learner wrote: ~After doing a google search, I could not find any good solid anwsers. So I will apologize ahead of time since this is not really a Python specific question. However... ~I was wondering if I should try to learn 2 programming languages at once, Python and C++. Obviously I am working on learning python right now, I have gotten up to Classes(I am studying from Learning Python 3rd and 4th editions from Mark Lutz on Safari online books), and feel like I have a pretty good idea of everything before classes. Yea there are still a lot of things I am not really fully comprehending, but like I said I have a pretty good idea. ~Perhaps it is also worth nothing Python is pretty much my first real Programming Language. Yea I took an intro to comp sci class(like 2 years ago) and a computer programming logic class(also like 2 years ago) both using pseudocode and have since dabbled in C(I started a programming class for school but dropped out twice after about 1/3 of the semester, for two consecutive semesters about 9 months ago) So here I am, a computer engineering major failure who had to change my major to Physics so I wouldn't have to take all those dammed comp sci classes Figured I could just teach myself. I mention this because I want to make clear I have the logic and critical thinking skills down, and in my opinion the aptitude as well. ~So is it better to learn 1 programming language first, then learn another. Or better to pretty much learn them at the same time? And why? ++Thank you so much if you have actually taken the time to read this. =) P.S. Julius Hernandez ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor You've had a lot of sound advice, but I take issue with this "learn a language in five minutes" bit. It took me five years to get to grips with plain old C. Assume that the same applies to all other languages to make it simple, that means for me to get to grips with 30 languages takes 150 years. I don't think I'll live to do that. Just my viewpoint. Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] re.sub() query
On 20/06/2010 10:54, Payal wrote: Hi, Is it possible to solve the below, w/o making a re object? a 'Mary Had a Little Lamb' p=re.compile('l',re.I) re.sub(p,'-',a) 'Mary Had a -itt-e -amb' I cannot figure how to se re.I w/o involving p. Thanks. With warm regards, -Payal You can do this. >>> re.sub('[lL]','-',a) 'Mary Had a -itt-e -amb' However it strikes me as overkill to use an re for something that could be done with the string replace function. Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] retrieve URLs and text from web pages
On 29/06/2010 17:32, Joel Goldstick wrote: [big snips] It might not be completely relevant, but there is nothing to stop anybody mixing regex and/or string methods. Horses for courses? Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] puzzled by Python 3's print()
On 01/07/2010 14:11, Richard D. Moores wrote: On Thu, Jul 1, 2010 at 04:57, Steven D'Aprano wrote: On Thu, 1 Jul 2010 06:26:21 pm Richard D. Moores wrote: x = 2034 x/2 1017.0 print(x/2) 1e+15 I was expecting, in fact needing, 117 or 117.0 1e+15 is unsatisfactory. Am I forced to use the decimal module? This is not an issue with print, this is an issue with floats -- they produced a rounded, approximate value when converted to a string. print merely prints that string: x = 1e15 +17 x 1017.0 print(x) 1e+15 str(x) '1e+15' If you want more control over the string conversion, you can do something like this: print(repr(x)) 1017.0 print('%.5f' % x) 1017.0 Thanks to yours and others responses, I've learned some things I didn't know, but remember, I'm starting with long ints such as x = 2034, cutting it in half, and hoping to print 1017 or 1017.0 (I also need to divide odd ints like 2033 and print 1017.5) (In my initial post, I used a smaller x, x = 2034. I should have made it longer, to reflect the ints I'm dealing with (big primes and their near neighbors). I'm still hoping to be saved from the decimal module :) . I think that we can manage that. :) Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Take a look at section 7.1.3 here. http://docs.python.org/py3k/library/string.html#string-formatting This is the recommended way to format strings in Python 3. Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] puzzled by Python 3's print()
On 01/07/2010 20:18, Eike Welk wrote: Hello Richard! On Thursday July 1 2010 15:11:21 Richard D. Moores wrote: Thanks to yours and others responses, I've learned some things I didn't know, but remember, I'm starting with long ints such as Also note that in Python 3 the "/" (division) operator returns a floating point number when you divide integers. This is one of the changes that Python 3 introduces. As you are using long integers (and you were previously writing about prime numbers) the precision of floating point numbers might not be enough for your purposes. Therefore you should probably use the integer division operator: "//" The following (edited) snippet from IPython demonstrates "//" and the loss of precision when using "/": ... Python 2.6.2 (r262:71600, Mar 29 2010, 15:30:01) Type "copyright", "credits" or "license" for more information. IPython 0.10 -- An enhanced Interactive Python. ... In [1]: from __future__ import division In [2]: a = 12 In [3]: a Out[3]: 12L In [4]: a//2 Out[4]: 50001L In [5]: a/2 Out[5]: 4.9994e+56 In [6]: long(a/2) Out[6]: 499937061060126016582882140297920412594995200L Eike. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Drat, drat and double drat, I believe Dick Dastardly from the Wacky Races cartoons. I meant to mention this, got side-tracked and completely forgot, sorry. Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] S.find()
On 01/07/2010 23:05, Corey Richardson wrote: Hello Tutors! I'm having a problem with the find() method of string objects. I'm currently making a hangman game, and I'm making the part that finds if there are multiple copies of the guessed letter in the word, and then if there are, finds them all. I can't for the life of me figure out the syntax of the find() method. gameWord = "python", btw. The module documentation lists it as this: "S.find(sub[, start[, end]]) -> int". What version of Python are you using? For Python 2.6.5 on Windows I have from the compiled help file. " str.find(sub[, start[, end]]) Return the lowest index in the string where substring sub is found, such that sub is contained in the range [start, end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found. " I'm assuming sub is the string you want to find, and that is how it has worked out for me. (Bonus Points: What does sub mean? I'm guessing See above. subscriptable, as one of my errors says, but I'll get to that...) When I try gameWord.find('p'[,1[,3]]), as the little help box suggests, You don't need the square brackets, they're used in many forms of documentation to indicate an optional argument. I get this: SyntaxError: invalid syntax Ok then, that is the exact syntax I was given. My next try is, and gives, this: >>> gameWord.find('p', [1,[3]]) Traceback (most recent call last): File "", line 1, in gameWord.find('p', [1,[3]]) TypeError: slice indices must be integers or None or have an __index__ method I assumed the comma after the 1 was messing it up, so I put this: >>> gameWord.find("p", [1[3]]) Traceback (most recent call last): File "", line 1, in gameWord.find("p", [1[3]]) TypeError: 'int' object is not subscriptable Is subscriptable what sup stands for in find()? What does mean? (5 Bonus Points for answering that). I'd prefer 5 bonus pints, but the documentation quoted above means I couldn't really accept. Alright then, twist my arm if you must. :) I also tried passing a slice index right into it like gameWord.find('p', [1:4]), but that returned a SyntaxError as well. I have the entirety of my code posted up at http://pastebin.com/k9nMZNMy, I won't edit the code until I get this worked out, except maybe a few housekeeping things, documentation, etc.* *I've tried everything I can, and I appreciate your time and help! ~Corey Richardson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Kindest regards. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Documentation Clarification
On 12/07/2010 15:49, Huy Ton That wrote: This is going to sound silly, but I realized there are some areas within the documentation that do not make absolute sense to me. e.g. compile(source, filename, mode[, flags[, dont_inherit]]) I see within this built in function, the first argument can be what they define as source, the second argument as the filename and the third as the mode. But what confuses me is sometimes I see a bracket, above as [, flags[, dont_inherit]]. Is this an optional argument like flags=dont_inherit? They are both optional arguments so you could call compile with:- compile(source, filename, mode) compile(source, filename, mode, flags) compile(source, filename, mode, flags, dont_inherit) Just not grokking it correctly and I can't seem to track down where the documentation formatting is defined within the python.org documentation... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor HTH. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A file containing a string of 1 billion random digits.
On 17/07/2010 13:01, Richard D. Moores wrote: That's the goal of the latest version of my script at <http://tutoree7.pastebin.com/5XYaaNfp>. The best I've been able to do so far is a file with 800 million digits. But it seems the writing of 800 million digits is the limit for the amount of memory my laptop has (4 GB). So my question is, how can I do this differently? I'm pretty brand new to opening and writing files. Here, I can't write many shorter lines, because the end result I seek is one long string. But am I correct? I'd appreciate any advice. BTW line 29 was added after getting the outputs noted at the bottom of the script. Using close() does seem to shorten the time it takes for my laptop to become usable again, but it's not decisive. Sometimes I have to reboot in order to get healthy again. (64-bit Vista). BTW2 It's probably not obvious why the list comprehension (line 19) has random.choice(d) where d is '0123456789'. Without that, the random ints of 1000 digits would never begin with a '0'. So I give them a chance to by prefixing one random digit using choice(d), and cutting the length of the rest from 1000 to 999. Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor As an alternative to the suggestions given so far, why not open the file for write in binary mode, i.e. use 'wb' instead of 'w', and don't bother converting to strings? Then when reading the file use 'rb' instead of 'r'. HTH. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] position of an element in list:
On 23/07/2010 16:43, Steven D'Aprano wrote: On Fri, 23 Jul 2010 11:22:54 pm Vineeth Rakesh wrote: Hello all, How to return the position of a character in a string. Say I have str1 = "welcome to the world" if i want to return the position of the first occurrence of "o" how to do it? str1.find("o") will return the index of the first "o", or -1 if not found. str1.rfind("o") does the same, but searches from the right instead of the left. str1.index("o") is like find, but it raises an exception instead of returning -1. Naturally there is a rindex as well. For the OP and possibly others, all of these methods have optional start and end arguments. Help for find shows:- find(...) S.find(sub [,start [,end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calculating and returning possible combinations of elements from a given set
On 27/07/2010 23:20, ZUXOXUS wrote: Hi all pythoners I've got a probably easy to answer question. Say I've got a collections of strings, e.g.: 'man', 'bat', 'super', 'ultra'. They are in a list, or in a sequence or whatever, say a bag of words And now I want to know how many couples I can do with them, and I want the program to show me the actual couples: 'manman', 'manbat', 'mansuper', 'manultra', 'batbat', 'batman', 'batsuper', etc. But hey, why building up new words from just two strings? I also want to know the possible combinations of three words, four words, and perhaps, why not, five words. So, is it easy to do? Sorry, I'm new in programing, and am probably far from being a math-master I'm clueless, I think probably the code have some FOR I IN SEQUENCE... but then what? I don't know how to say: take every element and paste it to another one from the bag, and with another one, and with another one,... If it's too complex, I dont need the whole code recipe, just need some clues, or perhaps a useful link Thank you very much in advance! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The lazy way. http://docs.python.org/library/itertools.html Look for combinations(). HTH. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string editing
On 31/07/2010 08:50, ANKUR AGGARWAL wrote: hey although i knw string are mutable but i want to know if there is anyway ^^^ immutable! to add in the string. like i m wrking on the tool and want to run the input from the user in the terminal like user makes input "this is ankur" and i want it like "this\ is\ ankur" ??? is it possible?? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor >>> ankur = "this is ankur" >>> ankur.replace(' ', '\ ') 'this\\ is\\ ankur' HTH. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Where to start with Unit Testing
On 01/08/2010 08:30, Huy Ton That wrote: Hi all, Do any of you have any feedback, strategies and best practices related to unit testing within Python. This is a relatively new topic for me. I was thinking of starting with reading the documentation associate with the unittest module. -Huy ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The documentation is a good starting point. Then see the excellent:- http://diveintopython.org/unit_testing/index.html. Also look at the actual Python test code in the Lib\test\ directory. Depending on the code that you're wanting to test you might also want to google for mock+objects, but this can wait until you've got your feet under the table. HTH. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] iterating over less than a full list
On 04/09/2010 18:29, Sander Sweers wrote: On 4 September 2010 19:25, Sander Sweers wrote: for x in some_stuff: if x<= 10: print x else: break Oops, corrected version... count = 0 for x in some_stuff: if count< 10: print x count +=1 else: break Greets Sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I prefer for i, x in enumerate(some_stuff): if i < 10: do_it(x) else: break Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionary of methods calling syntax
On 08/02/2012 17:41, Gregory, Matthew wrote: Alan Gauld wrote: Since a class is effectively a disguised dictionary I'm not sure why you want to do this? If you just want to access the method by name then why not just call getattr(spam,'get_mean')? Thanks for the feedback and, yes, this makes sense. My use case was when the statistic desired was going to be specified at runtime (through file input or UI) and that a dictionary would be a convenient crosswalk to associate the statistic name with the method name (and thus avoid an if/else ladder). But I understand that as long as there is a direct relationship between the name of the statistic and my class method (e.g. 'mean' -> get_mean), that I should be able to use the getattr() syntax as above. Thanks also to Joel for the suggestion to put the dictionary inside of __init__. thanks, matt ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor This should help if you need more info http://code.activestate.com/lists/python-list/403361/ -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionaries
On 10/02/2012 14:13, myles broomes wrote: Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving another challenge where I have to improve the previous program by adding a choice that lets the user enter a name and get back a grandfather. The program should still only use one dictionary of father-son pairs and finally I have to make sure to include several generations in your dictionary so that a match can be found. Im not sure I fully understand the task because surely its only possible to have one key and one value per pair but the challenge seems to want me to have a key (for the father), a value (for the son) and then something else (for the grandfather). Is this actually possible? Or am I just misinterpreting the challenge? Myles Broomes ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Take a look at this http://www.daniweb.com/software-development/python/code/217019 and think about it in relation to the replies you've already had. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Concatenating multiple lines into one
On 10/02/2012 17:08, Peter Otten wrote: Spyros Charonis wrote: Dear python community, I have a file where I store sequences that each have a header. The structure of the file is as such: sp|(some code) =>1st header AGGCGG MNKPLOI . . sp|(some code) => 2nd header AA ... . .. I am looking to implement a logical structure that would allow me to group each of the sequences (spread on multiple lines) into a single string. So instead of having the letters spread on multiple lines I would be able to have 'AGGCGGMNKP' as a single string that could be indexed. This snipped is good for isolating the sequences (=stripping headers and skipping blank lines) but how could I concatenate each sequence in order to get one string per sequence? for line in align_file: ... if line.startswith('>sp'): ... continue ... elif not line.strip(): ... continue ... else: ... print line (... is just OS X terminal notation, nothing programmatic) Many thanks in advance. Instead of printing the line directly collect it in a list (without trailing "\n"). When you encounter a line starting with">sp" check if that list is non-empty, and if so print "".join(parts), assuming the list is called parts, and start with a fresh list. Don't forget to print any leftover data in the list once the for loop has terminated. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The advice from Peter is sound if the strings could grow very large but you can simply concatenate the parts if they are not. For the indexing simply store your data in a dict. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string integers?
On 12/02/2012 14:51, Dave Angel wrote: On 02/12/2012 08:25 AM, William Stewart wrote: [snipped] My usual advice when seeing a beginner with a complex line that gives a syntax error is to see if you can replace it by a few simpler lines. Then the error might be more obvious. So use several print lines. So what if the output isn't quite right; you have some more debugging to do before you'll even see that output. For the OP. print str1, "*", str2, "*", int1, "*"int2 "=", str1, * str2, * int1 * int 2 To print all of this on one line you can use print str1, print "*", etc See http://docs.python.org/tutorial/inputoutput.html -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to stop a running program in python without closing python interface?
On 12/02/2012 22:19, Steven D'Aprano wrote: Debashish Saha wrote: actually a i ran a progam in python which is sufficiently large . so i want to stop the execution of the program now . how can i do this? Control-C should work on every operating system. Obviously you have send the Ctrl-C to the Python process, not some other application. E.g. if you are running your program in a terminal window, bring the terminal window to the front so it captures keystrokes and type Ctrl-C. If you have to kill the Python process from outside, use your operating system's standard method for killing processes. E.g. on Windows you would type ctrl-alt-del and then select which process to kill from the dialog box. On Linux you would use the ps and kill commands. At least on Windows Vista ctrl-alt-del brings up a list of options, one of which lets you bring up the Task Manager to kill the process and/or application. ctrl-shift-esc brings up the Task Manager directly. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ipython trouble with editor
On 13/02/2012 16:07, Steven D'Aprano wrote: [snipped] You might be better off asking your question on a dedicated ipython support forum. Like http://news.gmane.org/gmane.comp.python.ipython.user -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Request for advice on Python code
On 13/02/2012 23:50, Elaina Ann Hyde wrote: Hi, I'm working on a routine for reading in the Schlegel dustmaps. I have an ascii table with values, Ra-Dec and I'm trying to convert 2 columns to l,b and get the dust values out, this is a 2 part problem as I need to first convert to l,b, keep those values for other uses (calculating VLSR), and get extinctions for each l,b value, I have: import astropysics from astropysics.coords import ICRSCoordinates,GalacticCoordinates import asciitable x='Core_rod_name.list' dat=asciitable.read(x,Reader=asciitable.CommentedHeader, fill_values=['','-999.99']) Radeg=dat['ra-drad']*180./math.pi Decdeg=dat['dec-drad']*180./math.pi plot(Radeg,Decdeg,'o') xlabel('Radeg') ylabel('Decdeg') gcoords=ICRSCoordinates(dat['ra-drad'],dat['dec-drad'],radians=True).convert(GalacticCoordinates) l=gcoords.l.degrees b=gcoords.b.degrees VLSR=dat['Vhel_f'] + 9*np.cos(l)*np.cos(b) + 12*np.sin(l)*np.cos(b) + 7*np.sin(b) VGSR=VLSR + 220*np.sin(l)*np.cos(b) dustmap='SFD_dust_4096_ngp.fits' EB_V=astropysics.obstools.get_SFD_dust(l,b,dustmap,interpolate=True) --- this gives the error 'Only length-1 arrays can be converted to Python scalars' ... however, I cannot do: for row in dat: gcoords=ICRSCoordinates(dat['ra-drad'],dat['dec-drad'],radians=True).convert(GalacticCoordinates) without the same error. Any ideas would be apreciated, thanks! ~Elaina ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Well it's as clear as dust to me :) Unlike others who have already responded I don't believe that this will be too difficult to sort as the astropysics package is available on Pypi and there it states that it requires scipy and numpy. Did you or someone else install the package, if the latter can you ask them about this problem? Best of British/Australian/Whatever luck with this. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] problem in plotting circular plates at regular separation
On 14/02/2012 14:07, Alan Gauld wrote: On 14/02/12 13:56, Debashish Saha wrote: for r in range (1,5): ... z=r mlab.mesh(x, y,z, colormap='Greens') ... AssertionError: Array z must be 2 dimensional. And your question is? It's implied, please do my work for me because I can't be bothered to phrase a question. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] specific recommendation for a Python book, to move from baby-level to intermediate-level
On 15/02/2012 02:16, Tamar Osher wrote: Hello! I have finished reading some Python tutorials. My favorite tutorial is the official tutorial at Python.org. I am hoping to find a professionally designed, serious, university level book (with exercises, with a learning disc, and answers, and an elaborately helpful website) that will carefully and surely guide me through learning computer programming with Python version 3. I want to be lifted up from a baby-level to an intermediate level. I don't want to spend a lot of time casually browsing through the websites, trying out different things. I am in a rush to become a Python expert, I need a job! I enjoy computer programming. Python is my only programming language. A note to Python Teachers: I downloaded Python version 3.2.2 on my computer. Most Python books and tutorials are several years old, for older, outdated versions. My learning Python got off to a slow start: Initially, I had spent over a week trying to figure out the (version 2) tutorial for "Hello, World!", and the print/print() situation. Today, there is a huge and growing number of online Python tutorials and websites. My request is that the list of recommended tutorials be revised and updated. There is a sizable amount of learning and tutorial info at Python.org that seems to be valuable historical information rather than urgent-read-now-tutorials for new beginning programmers. For instance, there are some very well written Python tutorials from years 2009, 2007, and 2005. An idea: Delete all references to tutorials that are not version 2 or 3. And clearly label all the well-written version 2 tutorials, as being outdated version 2. For me, learning computer programming is easy, so far. What is difficult is finding the proper tutorials, and learning how to manage the difference between version 3.2.2 and older versions. For someone new to programming, the difference between version 3.2.2 and the older versions is enormous. (I have a background as a professional classroom teacher.) I am very eager to get kind help and wise counsel from others. If I need to install install Python version 2, buy a version 2 university-level book, read some version 2 tutorials, and do some version 2 exercises, please let me know. I want to quickly move myself from a baby-level to a capable, intermediate-level Python programmer. Please contact me when you have time. I am eager to connect with everyone and hear each person's comments. Have a GREAT day! From Your Friend: Tamar Osher Skype: tamarosher Email: emeraldoff...@hotmail.com Message Phone: 011- 1- 513-252-2936 www.HowToBeGifted.com - marketing communication, web design, and much more ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor For an unbiased set of book reviews search the book reviews here http://accu.org/index.php?module=bookreviews&func=search -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Class definition confusion
On 15/02/2012 18:14, Sivaram Neelakantan wrote: I was under the impression that you have to define the attributes of the class before using it in an instance. Following the book 'thinking in Python', class Point: ... """pts in 2d space""" ... print Point __main__.Point b = Point() b.x =3 b.y =4 print b.y 4 Why is it not throwing an error? This is confusing me a bit. sivaram -- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Your impression is incorrect. This type of behaviour is allowed because of Python's dynamic nature, so the following is fine. >>> class Point: ... """pts in 2d space""" ... >>> b = Point() >>> b.x = 3 >>> b.y = 4 >>> del b.x >>> del b.y >>> b.l = 5 >>> b.m = 6 >>> print b, b.l, b.m <__main__.Point instance at 0x02FB89B8> 5 6 Also be careful of your terminology. Here we are discussing instance attributes. Class attributes are different in that they are are shared at the class level so. >>> class Point: ... """pts in 2d space""" ... x = 3 ... y = 4 ... >>> a = Point() >>> b = Point() >>> a.x 3 >>> b.y 4 HTH. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Class definition confusion
On 15/02/2012 18:35, Hugo Arts wrote: [snip] An __init__ might seem like it's special in some way, declaring attributes. But it's not, really, it's just another method that gets passed the object it is called on (that would be "self"). It's only special because it gets called when an object is created, so generally an object is initialized there and attributes are assigned (hence the name "init").' HTH, Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor To the OP. Note that __init__ is an initialiser and not a constructor which is __new__, see e.g. http://mail.python.org/pipermail/tutor/2008-April/061426.html -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] finding a maximum between the absolute difference of several columns
On 17/02/2012 01:04, Elaina Ann Hyde wrote: Hello all, I am still scripting away and have reached my next quandry, this one is much simpler than the last, basically I read in a file with several columns. Vmatch3_1=dat[col1] Vmatch3_2=dat[col2] Vmatch3_3=dat[col3] Vdav=5.0 Vhel_fdiff3=max(abs(Vmatch3_1 - Vmatch3_2),abs(Vmatch3_1 - Vmatch3_3),abs(Vmatch3_3 - Vmatch3_2)) What I would like this to return is the maximum difference in each case, so I end up with one column which contains only the largest differences. now I use this to write the condition: with_v1_3=(Vhel_fdiff3>= Vdav) I know the condition works and plots if Vhel_fdiff3=(Vmatch3_1 - Vmatch3_2) for example, and I know this syntax would work if it was numbers instead of columns. max(abs(1-2),abs(3-7),abs(2-4)) 4 The error is: --- Traceback (most recent call last): File "double_plot.py", line 109, in Vhel_fdiff3=max(abs(Vmatch3_1 - Vmatch3_2),abs(Vmatch3_1 - Vmatch3_3),abs(Vmatch3_3 - Vmatch3_2)) ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() - So it can't handle the fact that it's columns of numbers and not single numbers, so my question is, can I solve this without doing a loop around it... use numpy, or some other function instead? I've been searching around and haven't found any good ways forward so I thought one of you might know. Thanks ~Elaina ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Throwing the error message into google gave a pile of hits from stackoverflow.com, which indicate that the error message is from numpy. See if this can get you going http://stackoverflow.com/questions/1322380/gotchas-where-numpy-differs-from-straight-python. The fourth answer down states "this is a horrible problem" so I'll duck out here, sorry :) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] finding a maximum between the absolute difference of several columns
On 17/02/2012 02:53, Elaina Ann Hyde wrote: On Fri, Feb 17, 2012 at 1:41 PM, Rohan Sachdeva wrote: The way I would do this is to put all of the differences in a list then take the maximum of the list. So.. a = Vmatch3_1 - Vmatch3_2 b = Vmatch3_1 - Vmatch3_3 c = Vmatch3_3 - Vmatch3_2 Vhel_fdiff3=max([a,b,c]) That should work. a,b,c are pretty bad variable names... Rohan On Thu, Feb 16, 2012 at 5:04 PM, Elaina Ann Hydewrote: Hello all, I am still scripting away and have reached my next quandry, this one is much simpler than the last, basically I read in a file with several columns. Vmatch3_1=dat[col1] Vmatch3_2=dat[col2] Vmatch3_3=dat[col3] Vdav=5.0 Vhel_fdiff3=max(abs(Vmatch3_1 - Vmatch3_2),abs(Vmatch3_1 - Vmatch3_3),abs(Vmatch3_3 - Vmatch3_2)) What I would like this to return is the maximum difference in each case, so I end up with one column which contains only the largest differences. now I use this to write the condition: with_v1_3=(Vhel_fdiff3>= Vdav) I know the condition works and plots if Vhel_fdiff3=(Vmatch3_1 - Vmatch3_2) for example, and I know this syntax would work if it was numbers instead of columns. max(abs(1-2),abs(3-7),abs(2-4)) 4 The error is: --- Traceback (most recent call last): File "double_plot.py", line 109, in Vhel_fdiff3=max(abs(Vmatch3_1 - Vmatch3_2),abs(Vmatch3_1 - Vmatch3_3),abs(Vmatch3_3 - Vmatch3_2)) ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() - So it can't handle the fact that it's columns of numbers and not single numbers, so my question is, can I solve this without doing a loop around it... use numpy, or some other function instead? I've been searching around and haven't found any good ways forward so I thought one of you might know. Thanks ~Elaina -- PhD Candidate Department of Physics and Astronomy Faculty of Science Macquarie University North Ryde, NSW 2109, Australia ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Thanks for the replies so far. I don't think that Rohan's idea solves the numbers versus columns issue. If I run it I get --- Traceback (most recent call last): File "double_plot.py", line 112, in Vhel_fdiff3=max(a,b,c) ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() - which is just the same error, I looked at the forums and the link suggested and I guess maybe my problem is trickier than I first thought! ~Elaina ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I've found this http://comments.gmane.org/gmane.comp.python.tutor/72882. HTH. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] arrays, while loops
On 18/02/2012 18:35, Deborah Knoll wrote: Hi I need some help with my program. I need to: Inside a getNumbers() function: Make an array that holds 7 elements - (got that done) make sure the numbers entered are greater than 0 and less than 1001 (can't get this) - is there a way to write a "between" statment or an "or"?? send the array to the aboveAverage () function What I can't get to work is the between 0 and 1001, and also where to make the array entries integer (I get an error saying can't compare string and integer) I also have to answer the three questions I have commented out at the end. I know this should be simple, but the more I read and try things, the more confused I get. Thanks for any suggestions! Here is what I have so far: amount = [0 for index in range (7)] This is outside getNumbers! Could be written as amount = [0] * 7. Better still amounts, see below. size = len (amount) You don't need this, because... def getNumbers(): for index in range (size): Usually written something like for amount in amounts: amount = ... amount[index] = input ("Enter an amount: ") Input some strings into your list overwriting the original integers. while amount[index]>0 or< 1001: Whoops. You'll first need to convert the input numbers with an appropriate function such as int or float, which you can do at the input stage. Python also lets you chain comparisons so this is allowed. while 0 < amount[index] < 1001: return (amount[index]) No point to this as amount is external to getNumbers. ##getNumbers() ## ##def aboveAverage(): ##total = 0.0 ## ##for value in amount: ##total +=amount[index] You don't need the loop, use the sum built-in function. ##average = total/len(amount) ## ## ##getNumbers() ##def printData(): ## ##print ("The numbers you entered from lowest to highest are: ") Use built-in functions min and max. ##print ("The average number is: ") ##print ("You entered this many numbers above average: ") I'll leave this for you :) ## ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor HTH. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list comprehension efficiency
On 19/02/2012 01:31, Bill Allen wrote: Generally speaking, are list comprehensions more efficient that the equivalent for loop with interior conditionals for a given task? Do they compile down to the same Python byte code? Thanks, Bill Allen ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Use the timeit module to answer Q1 and the dis module to answer Q2. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What made Python differ from other Languages?
On 20/02/2012 16:43, Sunil Tech wrote: *I am Beginner (very little i know), i want to know what are new things i can find in Python.* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor This sums up the Python philosophy. C:\Users\Mark\cpython\PCbuild>py -3.2 -c "import this" The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Create a table by writing to a text file.
On 22/02/2012 13:40, Evert Rol wrote: Hi, This is always a tricky thing to go about. Nicely human-readable doesn't imply nicely machine readable. Sometimes a single space or a single tab between values/columns is more practical for a(nother) program to read, but not for humans. So I will work from the assummption that you want it human-readable only. In that case, have a careful read through the string formatting options: http://docs.python.org/library/stdtypes.html#string-formatting Before the two tables there, there's a point 4 which mention a minimum field width; that'd be something you could use. Eg: print "|%20d|" % 10 | 10| print "|%20.5f|" % 12.3456789 |12.34568| Hopefully that gets you on the way. Cheers, Evert Note that string formatting referenced above is old style, new style can be found here http://docs.python.org/library/string.html#formatexamples -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] I cannot "run" any Python programs
On 22/02/2012 23:29, Tamar Osher wrote: Thanks! I hope to find a Windows7 expert to help me. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Try reading this http://docs.python.org/using/windows.html -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which computer operating system is best for Python developers?
On 23/02/2012 01:00, Tamar Osher wrote: Hi. I am still having trouble installing and using Python on my (new) Windows 7 computer, but I plan to contact Microsoft forums and see if they can help me, since this is a Windows problem and not a Python problem. My question: For the future, what type of computer is best for Python developers? Do all Python developers use some type of Unix computer? I appreciate your feedback and look forward to hearing from you. Thanks for your time. From Your Friend: Tamar Osher Email: emeraldoff...@hotmail.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I use Windows simply for the convenience and have never had a problem that couldn't be solved. I guess that some 40 years of industry experience tells me that reading manuals before trying something tends to save time in the long run. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reading/dealing/matching with truly huge (ascii) files
On 23/02/2012 01:55, Elaina Ann Hyde wrote: [big snips] Hi Elaina, I'm sorry but I can't help with your problem with the memory cos I don't know enough about the combination of Python and Unix wrt memory management. However can I suggest that you use more whitespace in your code to make it easier on all MkI eyeballs, e.g. you have Decdeg2=dat2['col4']+(dat2['col5']/60.)+(dat2['col6']/(60.*60.)) I think this looks better as Decdeg2 = dat2['col4'] + (dat2['col5']/60.) + (dat2['col6'] / (60.*60.)) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which computer operating system is best for Python developers?
On 23/02/2012 15:23, Jugurtha Hadjar wrote: On 23/02/2012 02:00, Tamar Osher wrote: Hi. I am still having trouble installing and using Python on my (new) Windows 7 computer, but I plan to contact Microsoft forums and see if they can help me, since this is a Windows problem and not a Python problem. My question: For the future, what type of computer is best for Python developers? Do all Python developers use some type of Unix computer? I appreciate your feedback and look forward to hearing from you. Thanks for your time. That's actually a good question. I am in Instrumentation Engineering (Electronics), and a lot of the software is designed to run only in Windows, or, the equivalent software in Linux is more for hobbyists than for professionnals (Think software for printed circuit boards), or, in the best case there are versions that run on Linux, but they aren't as featured or updated as the one that run on Windows. So I work on Windows. I have both Python26 and Python32 installed (Python26 for things like Numpy/SciPy). I also installed VirtualBox and run Ubuntu 11.10. It's nice because most of the software I use is on Windows, but I fire up the virtual machine sometimes for programming stuff. So it depends what you do and the software you use. One last point: Having two versions of Python, here's what I did in order to chose which version is used depending what I'm doing (If I'm tinkering with Numpy, I must use Python26) Python 2.6 is installed in C:\Python26 Python 3.2 is installed in C:\Python32 I added both paths to the Windows Environment Variables. I created two .bat files named Python26.bat and Python32.bat, each one in the respective directory. The Python26.bat file contains the follwoing lines: @echo off C:\Python26\python.exe %1 And the Python32.bat file contains the follwoing lines: @echo off C:\Python32\python.exe %1 So, if I write "python26 test.py" in the command line, the script gets "executed" by Python 2.6. In the same way, if I write "python32 test.py", it gets executed by Python 3.2.. Just a little thing to make my life easier. PS: If you have any question regarding the setting of the Virtual Box to run Ubuntu as a guest on Windows, feel free to ask for details. I'll be glad to provide links and things like that. Have you seen pylauncher? https://bitbucket.org/vinay.sajip/pylauncher Here's the background http://www.python.org/dev/peps/pep-0397/ -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GameTracker help
return UserSkillLvl if GameType == 8: temp = 0 while temp == 0: if ((UserSkillLvl<= 8) and (UserSkillLvl>=1)): print "thank you" temp = 1 break elif (UserSkillLvl>8) or (UserSkillLvl< 1): while temp == 0: UserSkillLvl = raw_input("Please re-enter your skill level: ") return UserSkillLvl def getUserOppSkillLvl(): UserOppSkillLvl = raw_input("Enter your opponents current skill level: ") while (str.isdigit(UserOppSkillLvl)==False): UserOppSkillLvl = raw_input("That is not a proper Skill Level. \ Please enter a number between 1 and 9 for 9-ball or 1 and 8 for 8-ball: ") UserOppSkillLvl = int(UserOppSkillLvl) return UserOppSkillLvl def getPointsNeeded(): if (GameType == 9): for UserSkillLvl in range (0, len(pointDictionary)): pointsNeeded = pointDictionary(UserSkillLvl) return pointsNeeded getPointsNeeded will never work as :- a) you can't call a dictionary, i.e. pointsNeeded = pointDictionary(UserSkillLvl) is incorrect b) if you write pointsNeeded = pointDictionary[UserSkillLvl] instead you'll get a KeyError c) if GameType isn't 9 you'll get an UnboundLocalError How do I know this? I've tried it at the interactive prompt, one of Python's great strengths. >>> pointDictionary = {1:14, 2:19, 3:25, 4:31, 5:38, 6:46, 7:55, 8:65, 9:75} >>> def getPointsNeeded(): if (GameType == 9): for UserSkillLvl in range (0, len(pointDictionary)): pointsNeeded = pointDictionary(UserSkillLvl) return pointsNeeded >>> GameType = 9 >>> pointsNeeded = getPointsNeeded() Traceback (most recent call last): File "", line 1, in File "", line 4, in getPointsNeeded TypeError: 'dict' object is not callable! >>> def getPointsNeeded(): ... if GameType == 9: ... for UserSkillLvl in range (0, len(pointDictionary)): ... pointsNeeded = pointDictionary[UserSkillLvl] ... return pointsNeeded ... >>> pointsNeeded = getPointsNeeded() Traceback (most recent call last): File "", line 1, in File "", line 4, in getPointsNeeded KeyError: 0 >>> GameType = 8 >>> pointsNeeded = getPointsNeeded() Traceback (most recent call last): File "", line 1, in File "", line 6, in getPointsNeeded UnboundLocalError: local variable 'pointsNeeded' referenced before assignment But this function isn't needed anyway just have. pointsNeeded = pointDictionary[UserSkillLvl] Hence. >>> UserSkillLvl = 5 >>> pointsNeeded = pointDictionary[UserSkillLvl] >>> pointsNeeded 38 def getOppPointsNeeded(): if (GameType == 9): if (UserOppSkillLvl == 9): oppPointsNeeded = 75 elif (UserOppSkillLvl == 8): oppPointsNeeded = 65 elif (UserOppSkillLvl == 7): oppPointsNeeded = 55 elif(UserOppSkillLvl == 6): oppPointsNeeded = 46 elif (UserOppSkillLvl == 5): oppPointsNeeded = 38 elif (UserOppSkillLvl == 4): oppPointsNeeded = 31 elif (UserOppSkillLvl == 3): oppPointsNeeded = 25 elif (UserOppSkillLvl == 2): oppPointsNeeded = 19 elif (UserOppSkillLvl == 1): oppPointsNeeded = 14 return oppPointsNeeded UserName = getUserName() UserOppName = getUserOppName() UserID = getUserNumber() OppUserID = getUserOppNumber() GameType = getGameType() UserSkillLvl = getUserSkillLvl(GameType) UserOppSkillLvl = getUserOppSkillLvl() print "\nPlayer Name:",UserName, "\nOpponent Name:", UserOppName, "\nUser ID: ",UserID, "\nOpponent APA ID", OppUserID, \ "\nGameType: ",GameType,"\nUser Skill Level: ",UserSkillLvl, "\nUser Opponents Level: ",UserOppSkillLvl pointsNeeded = getPointsNeeded() oppPointsNeeded = getOppPointsNeeded() print "\nYou need", pointsNeeded, "to win while your opponent needs", oppPointsNeeded,"." -- ~MEN -- ~MEN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] roman to arabic
On 26/02/2012 23:29, Sukhpreet Sdhu wrote: Hi I just wrote python code to convert roman to arabic numerals, but its not working. Can you just check where the problem is and way to correct that. So here is my python code import string print "Welcome to the numeric conversion program" print "Please enter command" data=raw_input() now = 0 previous = 0 total = 0 if data == "r": print "Enter roman numeric to convert in arabic" roman_numeric=string.swapcase(raw_input("Enter the Roman Numeral to convert to arabic")) if roman_numeric == ("M" or "D" or "L" or "C" or "L" or "X" or "V" or "I"): Length = len(roman_numeric) - 1 i = roman_numeric[Length] if i == "M": now = 1000 if i == "D": now = 500 if i == "C": now = 100 if i == "L": now = 50 if i == "X": now = 10 if i == "V": now = 5 if i == "I": now = 1 acc = now if (previous>= now): total += acc-prvious print "The total is",total if (previous<= now): total += acc-prevous print "The total is",total else : if data == "a" : print "Arabic number to convert" thanks sukhpreet sidhu ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I'm sorry but the code is so badly formatted via Thunderbird that it's pretty much impossible to work out what you intend. Try resending with the code correctly formatted. Also put print statements into the code so that you can follow the flow and see what it's doing, then you'll be able to make some progress yourself. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mentorship
On 03/03/2012 03:49, Christopher Conner wrote: Hello folks - I'm a little lost and seek a mentor to accelerate the learning curve associated with open-source development, with python in particular but not exclusively. I've been an computer enthusiast / amateur programmer for 20 years. Too, in the past few years I've researched a variety of related topics: historical computer culture, modern security and cryptography, Linux administration and the philosophy of software development. I also have some working knowledge of apache, website design and a compsci degree from 10 years ago. NOW WHAT? HELP! I've got some free time and I feel like I should pick an open source project and begin contributing, but the options are just staggering. I've narrowed things down to the Python language - maybe the Plone project? maybe helping with documentation at first? Maybe testing? I welcome any suggestions on any point or question given. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Start with http://pythonmentors.com/ ? -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] inserting new lines in long strings while printing
On 07/03/2012 01:26, Abhishek Pratap wrote: I have this one big string in python which I want to print to a file inserting a new line after each 100 characters. Is there a slick way to do this without looping over the string. I am pretty sure there shud be something its just I am new to the lang. Thanks! -Abhi ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Simplest way I can think of (untested). onebigstring = 'nbgkasgf;sh;slfgh;asdgh;adsdhg fg...' for i in range(0, len(onebigstring), 100): # for Python3, xrange for Python 2 print onebigstring[i:i+100] -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] misunderstanding "any"
On 07/03/2012 03:24, col speed wrote: Hello again Hope you are all well. I'm trying to make a "match 3" game, where you have a square grid and have to put 3 matching shapes in a row. I need a function that tells me if the game is playable, ie. it is possible to match 3 shapes by only swapping 2 adjacent shapes. I have looked at the co-ordinates and got a list of the "offset co-ordinates" needed for the above. I have a list of coordinates and a list of "lemons" and I want to see if *any* lemon coordinate is in the list of coordinates. I tried this: if any(((x+1, y+1), (x-1, y+2),(x-2, y+1),(x-1, y-1 ))) in fruit_type: return True Thinking that if *any* of the tuples is in fruit_type(a list of tuples), then it should return True. However, it always equates to False. If I iterate through the tuples and see if any are in fruit_type, it returns True (when it should). I have tried many print statements to make sure what is happening, and also to make sure that I am comparing type. Here's the way to find out. >>> help(any) Help on built-in function any in module __builtin__: any(...) any(iterable) -> bool Return True if bool(x) is True for any x in the iterable. >>> help('in') Comparisons *** [snipped] The operators ``in`` and ``not in`` test for collection membership. ``x in s`` evaluates to true if *x* is a member of the collection *s*, and false otherwise. ``x not in s`` returns the negation of ``x in s``. The collection membership test has traditionally been bound to sequences; an object is a member of a collection if the collection is a sequence and contains an element equal to that object. However, it make sense for many other object types to support membership tests without being a sequence. In particular, dictionaries (for keys) and sets support membership testing. For the list and tuple types, ``x in y`` is true if and only if there exists an index *i* such that ``x == y[i]`` is true. For the Unicode and string types, ``x in y`` is true if and only if *x* is a substring of *y*. An equivalent test is ``y.find(x) != -1``. Note, *x* and *y* need not be the same type; consequently, ``u'ab' in 'abc'`` will return ``True``. Empty strings are always considered to be a substring of any other string, so ``"" in "abc"`` will return ``True``. Changed in version 2.3: Previously, *x* was required to be a string of length ``1``. For user-defined classes which define the ``__contains__()`` method, ``x in y`` is true if and only if ``y.__contains__(x)`` is true. For user-defined classes which do not define ``__contains__()`` but do define ``__iter__()``, ``x in y`` is true if some value ``z`` with ``x == z`` is produced while iterating over ``y``. If an exception is raised during the iteration, it is as if ``in`` raised that exception. Lastly, the old-style iteration protocol is tried: if a class defines ``__getitem__()``, ``x in y`` is true if and only if there is a non- negative integer index *i* such that ``x == y[i]``, and all lower integer indices do not raise ``IndexError`` exception. (If any other exception is raised, it is as if ``in`` raised that exception). The operator ``not in`` is defined to have the inverse true value of ``in``. [snipped] -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] misunderstanding "any"
On 07/03/2012 04:36, col speed wrote: On 7 March 2012 10:45, Mark Lawrence wrote: On 07/03/2012 03:24, col speed wrote: Hello again Hope you are all well. I'm trying to make a "match 3" game, where you have a square grid and have to put 3 matching shapes in a row. I need a function that tells me if the game is playable, ie. it is possible to match 3 shapes by only swapping 2 adjacent shapes. I have looked at the co-ordinates and got a list of the "offset co-ordinates" needed for the above. I have a list of coordinates and a list of "lemons" and I want to see if *any* lemon coordinate is in the list of coordinates. I tried this: if any(((x+1, y+1), (x-1, y+2),(x-2, y+1),(x-1, y-1 ))) in fruit_type: return True Thinking that if *any* of the tuples is in fruit_type(a list of tuples), then it should return True. However, it always equates to False. Here's the way to find out. help(any) Help on built-in function any in module __builtin__: any(...) any(iterable) -> bool Return True if bool(x) is True for any x in the iterable. help('in') Comparisons *** [snipped] For the list and tuple types, ``x in y`` is true if and only if there exists an index *i* such that ``x == y[i]`` is true. [snipped] -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Thanks Mark I looked up help(any), but not help(in)! Note as it's a keyword it has to be in quotes, help('in'). I *think* I understand: Where it says: "For the list and tuple types, ``x in y`` is true if and only if there exists an index *i* such that ``x == y[i]`` is true." I suppose I am looking for .an index *i* and *j* such that x[j] == y[i]. Is that right? I reckon so although I don't believe that the interactive prompt lies. >>> a=tuple(range(10)) >>> b=tuple(reversed(a)) >>> a,b ((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) >>> a[3] == b[3] False >>> a[5] == b[4] True cheers Col ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor HTH. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] top-posting and text mode email
This is top posted. On 14/03/2012 01:50, Tamar Osher wrote: Hi!Could someone please explain what top-posting is? Specifically how does someone not "top-post"? What is text mode email? How does someone get and use text mode email? How can I recognize that I am sending an email message in text mode? I have a hotmail email account. What is the best way to get text mode email? Text mode email is an email sent in plain text, i.e. it doesn't have any html embedded. Your hotmail account should have an option that allows you to toggle between plain text and html. If not get a different email account :) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor This is bottom posted. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Cannot run python programs on my windows7 computer
On 14/03/2012 00:52, Tamar Osher wrote: Hello. Is there someone who can tutor me about how to "run" Python files on my windows7 computer? I have IDLE (the white box, the Python shell). I have the command prompt (the black box). And I also have Notepad++ on my computer. I have a total of 3 ways of trying to run my Python programs. I have tried and tried. The books and the online tutorials don't mention or discuss the problems that I am having; I cannot run Python programs. The computer itself it fabulously great, but I cannot get my Python files to easily run on it. If I am sometimes able to get a program to run, it is just seems to happen by chance, and I am not able to do it again next time. I feel frustrated with this situation, and need help. I hope to hear from someone, please. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Stating "I cannot run Python programs" doesn't give us much to go on. Read this first http://www.imladris.com/Scripts/PythonForWindows.html If you still have problems tell us exactly what you are doing and what the error messages are by cutting and pasting into email, don't try to type stuff yourself. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] seeing the results of a python program in windows7
On 14/03/2012 16:12, Tamar Osher wrote: Hi. I ask for help. Thanks very much for your time. I can run a python program in Notepad++, but what happens is that the black box flashes and disappears immediately, so that I never see the results. How can I style it so that the results of the program stay on the computer screen, for me to see? Using IDLE, the Python Shell, I can click File/New Window, to get a new window that allows me to RUN a program. But the RUN option does not allow me to choose which program I want to run. How can I style it so that I can choose which program to run, and how can I see the results of that program? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Now that you can actually run a program, would you please be kind enough to tell everybody for the record how you overcame the problem "I cannot run Python programs" as asked in the thread entitled "Cannot run python programs on my windows7 computer". -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how I overcame the problem "I cannot run Python programs"
On 15/03/2012 22:30, eire1...@gmail.com wrote: That's the nature of things I'm afraid. I do about half of my development on windows. My recomendation, download eclipse and install pydev. IDE choice is always a touchy subject but for windows, this should be your choice. I have notepad++ as well. Its great. But eclipse is better, especially for learning. I can't describe how much it helped me. I believe that eclipse is crap. I tried it 10 years ago and gave up because it was so slow. I tried it a couple of months ago for two weeks and again gave up for the same reasons. Why not stick with pythonwin, it's perfectly adequate for my needs? -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python arthematics
On 22/03/2012 22:14, Sukhpreet Sdhu wrote: i want to write a program that reads simple arithematic epressions and calculates the result. for example input "1*3+2" should generate "5'" as result ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Take a look at the operator module as it should give you some ideas. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error handling
On 25/03/2012 08:22, Russel Winder wrote: Michael, On Sat, 2012-03-24 at 15:20 -0700, Michael Lewis wrote: [...] It is perhaps worth noting that in Python 3, the syntax has changed: import os, errno try: os.makedirs('a/b/c') except OSError, e: except OSError as e : if e.errno != errno.EEXIST: raise This "as" syntax works in 2.6 and 2.7 so is probably the syntax to use unless you have to use very old versions of Python. I think the "as" syntax makes it clearer that e is a variable referring to the instance of OSError that causes the except clause to execute if it does. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor It's worth noting that PEP 3151 has been implemented in Python 3.3 see http://docs.python.org/dev/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy Quoting from the above link. "Thanks to the new exceptions, common usages of the errno can now be avoided. For example, the following code written for Python 3.2: from errno import ENOENT, EACCES, EPERM try: with open("document.txt") as f: content = f.read() except IOError as err: if err.errno == ENOENT: print("document.txt file is missing") elif err.errno in (EACCES, EPERM): print("You are not allowed to read document.txt") else: raise can now be written without the errno import and without manual inspection of exception attributes: try: with open("document.txt") as f: content = f.read() except FileNotFoundError: print("document.txt file is missing") except PermissionError: print("You are not allowed to read document.txt") " -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Lists and While Loops
On 28/03/2012 21:15, Emile van Sebille wrote: On 3/28/2012 11:53 AM Ricky Brown said... So I have to write a program that reads a message from the user and prints a new message ok -- that contains all the words from the original message but in the same order without repeating any of them unless they show up more than once in the original message. ?? doesn't this mean repeat the exact same message? IOW if the user suppies: This is is a test test the above rule would resuire you to output exactly the same input I think What I have thus far looks like this: message = input("Your message:") so, "print message" does it... ... but I suspect your requirement isn't accurate. Emile What the OP is asking for would output your original This is is a test test as is is test test I have a strong sense of Déjà vu, namely gathering requirements being far more difficult than writing code :) I've no idea whether the requirement given is right or wrong. Whatever the case I'd be using the built-in set or on older Pythons the sets module. myList = message.split() y = random.choice(myList) z = len(myList) while z !=0: myList.remove(y) print(y) I can't figure out 1) How to remove "y" from the list and continue the loop; when I use .remove etc. it runs once then give me the error that "y" is not in the list. I imagine the answer is quite simple I'm just getting really frustrated trying to get this done any advice is appreciated. Thanks -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New to this list ....
On 30/03/2012 15:13, Barry Drake wrote: On 30/03/12 15:04, Barry Drake wrote: One of the things I wanted to do is to use a four integer array to get four integers returned from a function. I ended up using what I think is a list. (I'm not really sure of the datatypes yet). This is what I Please read the tutorial if you haven't done so already at http://docs.python.org/tutorial/index.html did, and it works, but looks very inelegant to me: correct = 0 match = 0 wrong = 0 results = [correct, match, wrong] Usually written results = [0, 0, 0] or even results = [0] * 3 results = getflag(flag_1, results) results = getflag(flag_2, results) results = getflag(flag_3, results) results = getflag(flag_4, results) How is getflag defined and what are flag_1/2/3/4 ? Sorry - I meant three-digit array, and the indents in the code fragment above were all in line originally. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New to this list ....
On 30/03/2012 15:04, Barry Drake wrote: One of the few c things I miss is the switch/case statement. if and elif in it's place is a bit cumbersome. Still, it works. The recipe here http://code.activestate.com/recipes/410692-readable-switch-construction-without-lambdas-or-di/ refers to several other recipes which you might want to take a look at, sorry I meant to mention this earlier. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem Stripping
On 30/03/2012 18:09, leam hall wrote: Python 2.4.3 on Red Hat 5. Trying to use strip to remove characters but it doesn't seem to work like I thought. What do you expect it to do? res = subprocess.Popen(['uname', '-a'], stdout=subprocess.PIPE) uname = res.stdout.read().strip() uname 'Linux myserver 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011 i686 i686 i386 GNU/Linux' uname.strip(':') 'Linux myserver 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011 i686 i686 i386 GNU/Linux' 'www.example.com'.strip('cmowz.') 'example' Thoughts? Leam Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> help(''.strip) Help on built-in function strip: strip(...) S.strip([chars]) -> string or unicode Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is unicode, S will be converted to unicode before stripping So it appears that your examples are doing precisely what is defined above. HTH. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem Stripping
On 30/03/2012 18:28, Joel Goldstick wrote: On Fri, Mar 30, 2012 at 1:25 PM, Joel Goldstick wrote: On Fri, Mar 30, 2012 at 1:09 PM, leam hall wrote: Python 2.4.3 on Red Hat 5. Trying to use strip to remove characters but it doesn't seem to work like I thought. res = subprocess.Popen(['uname', '-a'], stdout=subprocess.PIPE) uname = res.stdout.read().strip() uname 'Linux myserver 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011 i686 i686 i386 GNU/Linux' uname.strip(':') 'Linux myserver 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011 i686 i686 i386 GNU/Linux' 'www.example.com'.strip('cmowz.') 'example' Thoughts? Leam -- Mind on a Mission<http://leamhall.blogspot.com/> ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor str.strip() removes characters from begining and end of the string -- Not any in between. Notice example = "www.example.com".strip("wcomx") example '.example.' The x remains You could do list comprehension n = "".join([x for x in "this has : some : colons" if x not in ':']) n 'this has some colons' Yuck :( Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> "this has : some : colons".replace(':', '') 'this has some colons' -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem Stripping
On 31/03/2012 03:01, bob gailer wrote: Then, of course, there's "15:45".replace(':','') For the record in earlier Python versions such as the one the OP is using you can do >>> allchars = "".join([chr(x) for x in range(256)]) >>> 'www.example.com'.translate(allchars, 'cmowz.') 'exaple' As of Python 2.6 you don't even need the allchars hence >>> 'www.example.com'.translate(None, 'cmowz.') 'exaple' -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Open source projects build using Python
On 03/04/2012 18:22, Alan Gauld wrote: On 03/04/12 15:45, Simon Yan wrote: Do a search on SourceForge and Google and see what comes up. Hopefully codeplex.com amongst others. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] cPickle/pickle help
On 04/04/2012 18:25, b. nyec wrote: Hello, I'm not sure if this is the correct list to post this on, but i was wondering i someone could help me. I'm wondering if there exists a pickler example written in C ? I understand the cPickle module was written in C, but looking at it seems daunting to create sample code from it. I found a post on this list here: http://mail.python.org/pipermail//tutor/2011-September/085414.html that shows an example of pickling data to disk. I'm wondering if that's pickle or cPickle (protocol version?) ?? What i'm trying to do is write a client in C that will send pickled data to a server written in python for unpicking over TCP. I'm still learning this stuff (pickle/serialization) as i go (i have zero knowledge of python), so apologies if i'm not making any sense as i've had trouble finding help on other places when explaining what i'm trying to accomplish. If this is off topic, feel free to e-mail me privately and i could explain in more detail without adding noise to this list. Thanks for any help. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor You're probably better off asking on comp.lang.python but the advice will almost certainly be don't do it see e.g. http://www.velocityreviews.com/forums/t944852-re-re-advise-of-programming-one-of-my-first-programs.html -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to use g_timeout_add () function?
On 06/04/2012 15:17, Lion Chen wrote: Hello all, i have a question: when i check gtk_time_out in the gtk+2 reference, it said " |gtk_timeout_add|has been deprecated since version 2.4 and should not be used in newly-written code. Use |g_timeout_add()|instead." but i don't know how tu use the g_timout_add() function: my_id = g_timeout_add(500, myfunction()) or: my_id = gtk.g_timeout_add(500, myfunction()) everytime i run the program, it prompted me a message like modules do not have g_timeout_add() attribute. so i still have to use gtk_timeout_add anybody help me? Lion Chen ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor It's much easier for us to help if you provide an exact snippet of code that reproduces the problem with the error message cut and pasted. Having said that there's nothing to stop you using gtk_timeout_add as it's only deprecated, i.e. it's been marked for removal at some time in the future. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] which gets called
On 06/04/2012 14:54, John Fabiani wrote: Hi, I want to create a class that inherits two other classes. class NewClass( A,B) But both "A" and "B" contain a method with the same name ("onKeyDown"). If my "NewClass" does not contain something to override the methods which one would be called if myinstance = NewClass() myinstance.onKeyDown() Please see http://docs.python.org/tutorial/classes.html#multiple-inheritance. This references http://www.python.org/download/releases/2.3/mro/ Having read these why not try typing code into the interactive prompt and see what happens? Worst case you get an exception, if you don't understand it cut and paste it to a reply to this and we'll help out. Second to insure the right one is called is it possible to do the following NewClass(object): def onKeyDown(self, event): b.onKeyDown(event) It's B.onKeyDown(self, event), without the self you'll get an unbound method error. Johnf ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to use g_timeout_add () function?
Please don't top post and please reply to the list Top posting fixed. - Forwarded Message - From: Lion Chen To: Mark Lawrence Cc: Sent: Friday, 6 April 2012, 16:43 Subject: Re: [Tutor] How to use g_timeout_add () function? fixed top posting > On 06/04/2012 15:17, Lion Chen wrote: >> Hello all, i have a question: >> >> when i check gtk_time_out in the gtk+2 reference, it said " >> |gtk_timeout_add|has been deprecated since version 2.4 and should not be >> used in newly-written code. Use |g_timeout_add()|instead." >> >> but i don't know how tu use the g_timout_add() function: >> my_id = g_timeout_add(500, myfunction()) >> >> or: >> >> my_id = gtk.g_timeout_add(500, myfunction()) >> >> everytime i run the program, it prompted me a message like modules do >> not have g_timeout_add() attribute. >> >> so i still have to use gtk_timeout_add >> >> anybody help me? >> >> Lion Chen >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor > > It's much easier for us to help if you provide an exact snippet of > code that reproduces the problem with the error message cut and > pasted. Having said that there's nothing to stop you using > gtk_timeout_add as it's only deprecated, i.e. it's been marked for > removal at some time in the future. > the problem is solved. in Python, should use gobject.timeout_add() replace the g_timeout_add() g_timeout_add() is for c. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help with a script..
On 11/04/2012 14:50, Khalid Al-Ghamdi wrote: Hi All, I'm using python 3.2 on a windows xp. I wrote the below script and ran it with the hope of returning a list of proctors (list_proc), but when it runs it doesn't call the function convert_proctors() as intended. On the other hand, when i import the module from the IDLE prompt and call the convert_proctors() function, the function returns the desired list. Why is this so? Thanks 1. import csv 2. 3. proctor_file=r'c:\Python32\Khalid Stuff\Testing_Scheduler\p roctors.csv' 4. 5. 6. def convert_proctors(): 7. proctor_csv_reader = csv.reader(open(proctor_file)) 8. proctor_list=list(proctor_csv_reader) 9. list_proc=[] 10. for row in range(len(proctor_list)): 11. list_proc.append(proctor_list[row][0]) 12. return (list_proc) 13. 14. 15. convert_proctors() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Your main query has already been answered, but I'd like to point out that your function could be written something like this. def convert_proctors(): list_proc = [] for row in csv.reader(open(proctor_file)): list_proc.append(row[0]) return list_proc -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] write list to columns
On 12/04/2012 08:48, Alan Gauld wrote: On 12/04/12 03:31, questions anon wrote: I am trying to simply write a list of values to txt file in one column. I would then like to add another list in a second column. That's going to be quite awkward to do. Files like to be written one complete line at a time. The normal approach would be to build up the table structure in memory and then write the entire table out in one go. If it won't fit in memory use a simple database like SQLite to build the table then print that out row by row. Built-in zip? Or have I missed something? Somehow they only appear as one long row. You need to write newlines but you probably also want to use string formatting to control the amount of space required so that your columns line up. HTH -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] user created lists
On 12/04/2012 05:42, john moore wrote: Hello Pyhton World, Hello Hojn Rooem and welcome :) I'm new at this and was wondering how I create a number of user specified lists? Why? Tell us what you're trying to achieve and we may well come up with a better solution. Example: "How many list would you like to create?" User inputs 5 creates five lists, list1 [] list2 [] list3 [] list4 [] list5 [] I can create one with append, but I don't know how to loop it to create five different named list.. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Re.findall()
On 12/04/2012 14:53, mjole...@gmail.com wrote: Hi everyone, I am having trouble understanding re.findall(). I've read through the documentation and looked at at some examples online, but I still don't have a clear picture. I am going through pythonchallenge.com and I am on challenge 3. I've see. The answer to the problem, but I don't understand the "pattern" portion of re.findall(). Thanks! Sent from my iPhone ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Please give us an example of the code that you've tried, what you expect to see and what the actual output from your program was. If an exception occurred please cut and paste the entire exception traceback into this thread. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] write list to columns
On 13/04/2012 08:47, questions anon wrote: thanks all! No problem, but I would like like to point out, albeit repeating myself, that my normal profesional fees apply, i.e. two pints of Ringwood Old Thumper or equivalent should you ever be in my neck of the woods. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] creating a regularly placed fields in a line
On 25/04/2012 16:57, Prasad, Ramit wrote: Not really sure how to do the equivalent with % substitution. Ramit See http://docs.python.org/library/stdtypes.html#string-formatting-operations -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] virtualenv
On 27/04/2012 07:49, Ivor Surveyor wrote: I recently asked the question how can I get graphic.py to work on my edition of Python which is 2.7.2 The problem was identified by Python tutor from my error messages as: "What that error is telling you is that you have a version 8.5.9 oftcl, but whatever you're trying to run is expecting _only_ 8.5.2 Sadly, probably, the way to "fix" this is by relaxing the requirements of the thing you're trying to run. Alternatively, look at virtualenv to set up an environment your code will work with." My next question is where do I obtain an appropriate version of virtualenv? My operating system is OS Name Microsoft Windows 7 Professional Version 6.1.7600 Build 7600 . I would appreciate any help, kind regards Ivor Surveyor isurve...@vianet.net.au ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Google for python virtualenv windows and it's the first hit. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: help
On 30/04/2012 08:00, viral shah wrote: I want to print below matrix. can any one suggest me the method for the same 1 2 3 4 5 6 7 8 9 Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Quoting from c.l.p at 07:46 "In general, for homework questions, you should present your attempt at a solution, with specific questions where you are running into difficulty. Are you able to output anything using a python program? If not, you should take a look at one of the several excellent tutorials easily found by a web search. The official tutorial is at http://docs.python.org/py3k/tutorial/ and it might be enough for you to at least attempt a solution to your problem." -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Variable Addition
On 30/04/2012 18:36, Alan Gauld wrote: On 30/04/12 11:00, Kapil Shukla कपिल शुक्ला wrote: Viral You should be doing this "Addition of two numbers is" + str(x+y) There is no need for str() since print implicitly calls string to convert objects to string format. Also the addition is not needed since print takes a comma separated list of arguments. So it would normally be: print 'Addition of above two numbers are : ', z Except that you'll get two spaces after the colon :) + operator works on same datatypes and Using addition on strings is quite expensive and there are usually better ways to do the same job. int being one of the built in objects in python does not have a method z This however is true(ish - int is a type not strictly an object, except that everything in Python is an object, including types! :-) and it is the source of the original error message. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Variable Addition
On 30/04/2012 19:40, Alan Gauld wrote: On 30/04/12 19:27, Mark Lawrence wrote: print 'Addition of above two numbers are : ', z Except that you'll get two spaces after the colon :) OK thats true, Try this: print 'Addition of above two numbers are :', z for one. :-) But if the number of spaces is critical string formatting is better still. And better than string addition. True indeed, but which of the three versions of string formatting that I'm aware of? -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Variable Addition
On 01/05/2012 00:35, Steven D'Aprano wrote: Mark Lawrence wrote: On 30/04/2012 19:40, Alan Gauld wrote: But if the number of spaces is critical string formatting is better still. And better than string addition. True indeed, but which of the three versions of string formatting that I'm aware of? Any of them. Alright you antipodean :) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
On 02/05/2012 01:27, Steven D'Aprano wrote: Alan Gauld wrote: If its Windows the line makes no difference. On Windows, the presence or absence of a space will make no difference, because it's just a comment. This is changed by PEP397, which also refers to an implementation. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to exit this loop in the interpreter
On 03/05/2012 16:52, Gergely Lőrincz wrote: Dear folks, I've been struggling to set up python on snow leopard, mac os x. Stupidly I downloaded and installed python 3.2 and since then the 'python' command in the terminal yields 'no command found'. In addition when opening the terminal I get this error message on the top of the window: http://pastebin.com/QS3gpkjK For some reason the installation littered my Android SDK folder with main.py and other kind of python files. Don't ask me why, it's beyond me. I removed the offending files manually and deleted the python 3.2.2 folder form /Library/Frameworks/python.framework/versions folder. After rebooting the terminal still complains about those files. I wonder how can I fix it? I would love to learn to use python! Your help would be appreciated! On 3 May 2012 15:22, Simon Yan wrote: On Thu, May 3, 2012 at 9:57 PM, wrote: Hello all, I have encountered the following scenario. Here is the code - on IDLE on Windows XP. *>>> while True: try: number = raw_input("enter number - ") print number * number except ValueError: print "invalid number" except: print "unspecified exception" else: print "other conditions" enter number - 3 unspecified exception * What I noticed is that no matter, what input I give, I cannot exit this loop. I have tried control-C, control-D etc. all the keys. So how can I exit from this loop? If you simply want to stop after an exception was caught, you can insert "break" after each print line. Like below: >>> while True: try: number = raw_input("enter number - ") print number * number except ValueError: print "invalid number" break except: print "unspecified exception" break else: print "other conditions" break Thanks and Regards, Sumod -- http://spawgi.wordpress.com We can do it and do it better. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Regards, YeeYaa (Simon Yan) http://simonyan.fedorapeople.org/ ___ 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 I say old chap, it's simply not cricket to hijack a thread, particularly when you've already asked your question some 4 hours and 38 minutes earlier. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Embed python in a website
On 03/05/2012 23:56, Emile van Sebille wrote: On 5/3/2012 2:28 PM Adrian said... I recently created a gui form using tkinter, is it possible to integrate this form to my website page? How do i integrate? pyjs aka pyjamas allows you to write once and run on both web and desktop. I'd start there. Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Sadly the ongoing status of pyjamas is uncertain see http://code.activestate.com/lists/python-list/620105/ -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Embed python in a website
On 04/05/2012 02:02, Mark Lawrence wrote: On 03/05/2012 23:56, Emile van Sebille wrote: On 5/3/2012 2:28 PM Adrian said... I recently created a gui form using tkinter, is it possible to integrate this form to my website page? How do i integrate? pyjs aka pyjamas allows you to write once and run on both web and desktop. I'd start there. Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Sadly the ongoing status of pyjamas is uncertain see http://code.activestate.com/lists/python-list/620105/ A follow up to the above here http://www.velocityreviews.com/forums/t945930-pyjamas-pyjs.html -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Curious dictionary printing
On 07/05/2012 18:16, Cranky Frankie wrote: In 3.2.2 in IDLE I have this dictionary entry: Namath = {"first_name": "Joe", "last_name": "Namath", "phone": "212-222-",\ "email": "joe.nam...@gmail.com", "stadium": "Shea Stadium"} when I print it: print(Namath) I get: {'phone': '212-222-', 'first_name': 'Joe', 'last_name': 'Namath', 'email': 'joe.nam...@gmail.com', 'stadium': 'Shea Stadium'} Why is it out of order? Cos plain old dicts have no order, but this can be done with http://docs.python.org/library/collections.html#ordereddict-objects -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Script to search in string of values from file A in file B
On 09/05/2012 15:00, Afonso Duarte wrote: object = open(B.txt', 'r') You'll already received some sound advice, so I'd just like to point out that your object will override the built-in object, apologies if somebody has already said this and I've missed it. Afonso ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hello~
On 14/05/2012 00:04, Keitaro Kaoru wrote: hey. Austin here for some reason this command. all it does it produces the error message at the bottom.. itll say my name and the persons name im trying to send the message to but thats it. heres the command. mgr.addCommand("tell", 1, "send a person a message to the rooms he is in", tell, unlisted = True) def tell(mgr, croom, user, msg, args): name = args.lower().split(" ")[0] if not name.isalnum(): return Html("Non-alphanumeric name, seriously?") data = shared_db.get("seen:" + name) if data == None: return Html("I have no records about this user.") data = json.loads(data) for room in mgr.rooms: if data[1] == "join": mgr.sendObject(target, Html("%s,%s wants to tell you%s", name.title, user.name.title$ else: return Error("%s I couldn't find %s anywhere", user.name.title(), name.title()) i built it off these 2 commands def broadcast(mgr, croom, user, msg, args): for room in mgr.rooms: mgr.sendObject(room, Html("Broadcast by%s:%s", user.name, args)) def seen(mgr, room, user, msg, args): name = args.lower().split(" ")[0] if not name.isalnum(): return Html("Non-alphanumeric name, seriously?") data = shared_db.get("seen:" + name) if data == None: return Html("I have no records about this user.") data = json.loads(data) ifdata[1] == "join": return Html("Last seen%s join%s,%s ago.", name, data[0], tdelta(data[2])) elif data[1] == "leave": return Html("Last seen%s leave%s,%s ago.", name, data[0], tdelta(data[2])) elif data[1] == "message": return Html("Last seen%s message in%s,%s ago: \"%s\"", name, data[0], tdelta(data[2]), data[3]) return Html("I have no records about this user.") as you can see i only use some of the command. it doesnt produce an error message tho.. just repeats "return Error("%s I couldn't find %s anywhere", user.name.title(), name.title())" ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Sorry but it's unreadable to me. Have you sent this in HTML when you should have sent in plain text? -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sorry seems like it was sent in html
On 14/05/2012 00:22, Keitaro Kaoru wrote: is that better? not html... ? hey. Austin here for some reason this command. all it does it produces the error message at the bottom.. itll say my name and the persons name im trying to send the message to but thats it. heres the command. mgr.addCommand("tell", 1, "send a person a message to the rooms he is in", tell, unlisted = True) mgr is wahh ? def tell(mgr, croom, user, msg, args): name = args.lower().split(" ")[0] if not name.isalnum(): return Html("Non-alphanumeric name, seriously?") data = shared_db.get("seen:" + name) if data == None: return Html("I have no records about this user.") data = json.loads(data) for room in mgr.rooms: if data[1] == "join": mgr.sendObject(target, Html("%s,%s wants to tell you%s", name.title, user.name.title$ else: return Error("%s I couldn't find %s anywhere", user.name.title(), name.title()) i built it off these 2 commands def broadcast(mgr, croom, user, msg, args): for room in mgr.rooms: mgr.sendObject(room, Html("Broadcast by%s:%s", user.name, args)) def seen(mgr, room, user, msg, args): name = args.lower().split(" ")[0] if not name.isalnum(): return Html("Non-alphanumeric name, seriously?") data = shared_db.get("seen:" + name) if data == None: return Html("I have no records about this user.") data = json.loads(data) ifdata[1] == "join": return Html("Last seen%s join%s,%s ago.", name, data[0], tdelta(data[2])) elif data[1] == "leave": return Html("Last seen%s leave%s,%s ago.", name, data[0], tdelta(data[2])) elif data[1] == "message": return Html("Last seen%s message in%s,%s ago: \"%s\"", name, data[0], tdelta(data[2]), data[3]) return Html("I have no records about this user.") as you can see i only use some of the command. it doesnt produce an error message tho.. just repeats "return Error("%s I couldn't find %s anywhere", user.name.title(), name.title())" ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor No :( Please cut and past the exact code that you're using and the exception that you're getting, without that that it's impossible for us to help you. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] table to dictionary and then analysis
On 17/05/2012 10:35, Steven D'Aprano wrote: On Thu, May 17, 2012 at 08:27:07AM +0100, Russel Winder wrote: Should we be promoting use of the format method in strings rather than the % operator? % is deprecated now. It most certainly is not. There are no plans to deprecate the string % operator any time in the foreseeable future. It may, hypothetically, wither away from lack of use (although I doubt it -- so long as there are C programmers, there will be people who like % formatting). If you think it is deprecated, please show me in the official Python documentation where it says so. As far as I am concerned, the final word on deprecation belongs to the creator of Python, and BDFL, Guido van Rossum, who hopes that *at best* the format method will gradually replace % formatting over the next decade or so before the (as yet hypothetical) Python 4: http://mail.python.org/pipermail/python-dev/2009-September/092399.html Rather than repeat myself, I will just point to what I wrote back in January: http://mail.python.org/pipermail/python-list/2012-January/1285894.html You beat me to it :) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print 'hello world' - invalid syntax
On 20/05/2012 19:08, Quidam S-enfuit wrote: I have installed python on the windows 7 machine. (Tried 64 bit version also; same error). I tried print "Hello world" and print 'hello world'. It stated syntax error!?... Thanks. ===copied from python (interactive command) /pasted below== Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. print 'hello world' File "", line 1 print 'hello world' ^ SyntaxError: invalid syntax ==end ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Print is a function in Python 3, so you need print('hello world'). -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Query with SOAP request generation, which other modules can be used.
On 23/05/2012 08:17, Ataulla S H wrote: We can try suds its very lightweight soap client. Thanks Ataulla SH On Wed, May 23, 2012 at 9:43 AM, ankur ~ अंकुर wrote: Dear Pythoneers, We want to butile the SOAP request request in below manner. - In header we want to pass the wsse auth part and custom transref section and both has different xmlns. http://schemas.xmlsoap.org/soap/envelope/ " xmlns:com="http://some.xmlns.org/.1.0/Common.xsd"; xmlns:bil=" http://some.xmlns.org/Schema/Billing/1.0/Billing.xsd";> PORTAL 123456 123456 http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd "> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd "> user pass 187000 Currently we are using pysimplesoap ( http://code.google.com/p/pysimplesoap/) module for this. The current python code is attached. But we are not able to pass the custom xmlns ( for bil and for com - the very first line ) with pysimplesoap module. *Any idea which other module we have to explore for generating the SOAP request like above.* Thank You, Ankur. ___ BangPypers mailing list bangpyp...@python.org http://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list bangpyp...@python.org http://mail.python.org/mailman/listinfo/bangpypers What is the unladen airspeed velocity of a swallow in flight? -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] removing sq. of items.
On 23/05/2012 12:27, Dave Angel wrote: On 05/23/2012 06:07 AM, Bala subramanian wrote: Hi, I infact want write each of the item in the sliced list to a file. This line is top-posted. Please put your remarks *after* the part I agree entirely but top posting is getting worse and worse on all Python mailing lists. I complained several months ago but was told to shut up as it had previously caused too many flame wars. I guess there's two options, keep reminding peole or give up, I prefer the former but would certainly consider the other. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running .py Files
On 06/06/2012 04:14, Benjamin Cox wrote: Hello, So, I'm very new to Python and programming in general, and I've been having trouble figuring out how to run programs by clicking on their .py file name. For some reason, my computer's default setting is to open them in wordpad. I have Windows 7 32-bit OS and Python 3.2.3. Any help would be greatly appreciated! Thanks, Ben ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Start here http://docs.python.org/release/3.2/using/windows.html, any problems please feel free to ask as we don't bite :) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] special attributes naming confusion
On 06/06/2012 20:19, Dave wrote: I was reading some tutorial material on creating iterators. It shows the following example implementation of an iterator: class Reverse: """Iterator for looping over a sequence backwards.""" def __init__(self, data): self.data = data self.index = len(data) def __iter__(self): return self def next(self): if self.index == 0: raise StopIteration self.index = self.index - 1 return self.data[self.index] My question is how was I supposed to kinow that the function I call using the name iter() is implemented using the name __iter__()? Is there a rule that describes when I would implement an attribute name with leading and trailing double underscores, and then call it without those underscores? How many names like this exist in Python? Are these special cases or is there a general rule that leading and trailing double underscores get dropped when calling functions that were implemented with these names? I'm trying to understand the big picture as far as how Python works when it comes to this situation. Thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Try this to start with http://docs.python.org/reference/datamodel.html#special-method-names. Note this is for Python 2.7.3, there may be differences in Python 3.x. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] properties beginner M Dawson book
On 11/06/2012 16:05, brian arb wrote: I would look into pylint, Python source code looking for bugs and signs of poor quality. Or pychecker or pyflakes. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Query - Where to put in global variables, if needed, as a good programming practice
On 15/06/2012 12:44, spa...@gmail.com wrote: Hello, The point of good-bad-ness of global variables aside, if I needed to use them, which is a better place to put them. 1. In the __init__ function of a class? So they are available at the time an object is initialized or 2. In the actual function of the class where the variables are needed? Pros and Cons of either approach? Thanks and Regards, Sumod ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I don't understand why you would need global variables, and then promptly start discussing them wrt classes. Please explain what you are trying to achieve and I'm certain that we'll come up with the best solution for your use case. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does slicing work?
On 16/06/2012 13:16, Kanone Seele wrote: Thank you guys~ the two blades method really works well! And I think it'd be better to dive into the source code of Pytho.Well,it seems difficult for me now. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I suggest you read the tutorial before starting on source code. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Matplotlib labels
On 19/06/2012 00:46, Alan Gauld wrote: On 19/06/12 00:13, Sean Carolan wrote: and not the total of all the individual items. Anyone matplotlib experts out there who can weigh in? Not me, but I notice there is a gmane newsfeed for matplotlib: gmane.comp.python.matplotlib.general Probably worth posting questions there. No probably about it, I've asked questions there and like all Python lists found them extremely friendly and helpful. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 19/06/2012 21:07, Dave Angel wrote: On 06/19/2012 03:35 PM, Selby Rowley-Cannon wrote: Mailing list; I have a small, [for the most part] functioning translation app for Rydish, a language created for the sole purpose of an RPG. The only problem is when I enter a word that has not yet been translated, I get this error: Traceback (most recent call last): File "translator.py", line 25, in Etranslate() File "translator.py", line 14, in Etranslate print(Edictionary[Eword]) KeyError: 'world' Is there a way to print a user-freindly message instead of displaying a traceback? Thanks, -Selby Even easier than catching an exception is to test for the condition you expect might not pass. Assuming your Edictionary is a dict, all you need to do is to make the reference conditional on the presence of that particular key. if Eword in Edictionary: print(Edictionary[Eword]) else: print("oops But note the comparison between LBYL and EAFP - I'll leave those interested to google for it :) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor