Re: [Tutor] Review my code

2011-09-26 Thread Steven D'Aprano
Chanakya Mitra wrote: I wrote a short script that tries to check if an email address exists or not. Some brief comments: When you send code by HTML email, you mess up the formatting of the code. Please don't do that in the future. def mailxch(hname): mxhosts = DNS.mxlookup(hname)

Re: [Tutor] How Python handles data (was guess-my-number programme)

2011-09-27 Thread Steven D'Aprano
Wayne Werner wrote: When you do something like this in C: int x = 0; int y = 0; What you have actually done behind the scenes is allocated two bytes of memory(IIRC that's in the C spec, but I'm not 100% sure that it's guaranteed to be two bytes). Perhaps they are near each other, say at addres

Re: [Tutor] help with a recursive function

2011-09-27 Thread Steven D'Aprano
c smith wrote: hi list, i understand the general idea of recursion and if I am following well written code I can understand how it works, but when I try to write it for myself I get a bit confused with the flow. Your flow is fine. You just forget to return anything in two of the three branches

Re: [Tutor] help with a recursive function

2011-09-27 Thread Steven D'Aprano
Mac Ryan wrote: raise BaseException('Something is wrong here!') Never raise BaseException directly! BaseException is the very top of the exception hierarchy, you should raise the *most* specific exception you can, not the least specific. BaseException isn't even just for errors, it's al

Re: [Tutor] Why subclassing exceptions?

2011-09-28 Thread Steven D'Aprano
Mac Ryan wrote: I have to say - however - that even after a few years of python development I seldom use exceptions that way: in fact I can only remember having subclassed error classes once, when I wrote a library that was intended to be used by third-parties (for the exact same reasons that yo

Re: [Tutor] Input

2011-09-30 Thread Steven D'Aprano
Cameron Macleod wrote: Hi, When you type Input("\n\nPress The Enter Key To Exit") it forces you to press the enter key to close the program. Why is it the enter key instead of e.g. the 'esc' key? Because the convention is that you use the Enter key to ENTER information. That's why it is cal

Re: [Tutor] guess age programme (please help)

2011-09-30 Thread Steven D'Aprano
Hi Adrian, ADRIAN KELLY wrote: Hi all, can anyone help me with the attached programme. I'd love to, but I can't open it :( If the truth be known, I could open it if I spent the time and effort. But that actually is significant time and effort: in my email, your attachment looks like this:

Re: [Tutor] How to "refresh" the interactive prompt?

2011-10-02 Thread Steven D'Aprano
Richard D. Moores wrote: Python 3.2.2, Win 7 When using the Python 3 interactive prompt, is there a way to quickly "refresh" the prompt? By "refresh" I mean get a new interactive prompt with nothing imported and all things like a = "qwerty", n = 123, etc. no longer in effect. Not sure what th

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread Steven D'Aprano
lina wrote: May I ask a further question: a {'B': [4, 5, 6], 'E': {1, 2, 3}} Why is a['B'] a list and a['E'] a set? How can I get the value of set(a['E'])+set(a['B']) I mean, get a new dict 'B+E':[5,7,9] You are confusing different things into one question, as if I had asked: "How

Re: [Tutor] force imports from site-packages?

2011-10-06 Thread Steven D'Aprano
Alex Hall wrote: Hi all, I have managed to get a couple of packages in site-packages which share names with some folders in the same directory as a program, or at least a subdir somewhere below has the same name. Is there a way to force my script to look in lib/site-packages before the script's f

Re: [Tutor] swapping list elements based on some criterion

2011-10-07 Thread Steven D'Aprano
Emad Nawfal (عمـ نوفل ـاد) wrote: Hello Tutors, It's been quite some time since I last posted something here, and now I'm back with a question: I want to re-structure English so that the adjectives appear after the nouns, instead of before. If I have a sentence like: The tall man plays well I n

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Steven D'Aprano
Alan Gauld wrote: On 07/10/11 16:40, lina wrote: but today I was also discouraged, I was told that you should not have learned python, you should focus on C or bash, or D, cause python is going to be obsolete, C is a great language for writing Operating Systems and other "near the metal" cod

Re: [Tutor] Runtime error while Test data creation

2011-10-08 Thread Steven D'Aprano
Guess?!? wrote: Hello all, I am trying to create some test data for a search module that I am building. Since I dont want to hit performance related issues late in the game, I decided to create half a million records in the DB. My approach is create a csv file with valid UUIDs which I already h

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-08 Thread Steven D'Aprano
Walter Prins wrote: As for the compiler/interpreter argument, I'll just point out again that actually Python in its various forms can either be compiled and/or interepreted, it depends on you really. For compiled Python flavours, see for example Cython (http://cython.org/) which provides a way

Re: [Tutor] Crazy craps problem

2011-10-08 Thread Steven D'Aprano
col speed wrote: Hi again, Once more I've come up with a problem I can't explain. It must be something simple, but I can't work it out. The part of the script that is causing the problem is as follows: def point(num): while True: raw_input("Roll") You ask the user for input, but d

Re: [Tutor] Help refactoring this code

2011-10-09 Thread Steven D'Aprano
D. Guandalino wrote: Hi, in this class many methods share common code. Given your example, I wouldn't bother refactoring it. There's not enough code in common to matter. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change s

Re: [Tutor] vcf_files and strings

2011-10-09 Thread Steven D'Aprano
Anna Olofsson wrote: Hi, I'm a beginner at Python and would really like some help in how to extract information from a vcf file. The attached file consists of a lot of information on mutations, this one though is just 2 rows and 10 columns (the real one has a lot more rows). What do you mean

Re: [Tutor] I am trying to print list elements but i am getting 'none'

2011-10-10 Thread Steven D'Aprano
Praveen Singh wrote: This is my code- def getNumbers(num): myList=[] for numbers in range(0,num,2): print myList.append(numbers) output- getNumbers(10) None None None None None Then i find out that list.append doesn't return anything.Then what should i use for this kind of

Re: [Tutor] swapping list elements based on some criterion

2011-10-10 Thread Steven D'Aprano
Wayne Werner wrote: 2011/10/7 Emad Nawfal (عمـ نوفل ـاد) I want to re-structure English so that the adjectives appear after the nouns, instead of before. If I have a sentence like: The tall man plays well I need to change it to The man tall plays well Others have offered plenty of help, th

Re: [Tutor] Finding if a passed variable is within to set parameters

2011-10-10 Thread Steven D'Aprano
Mike Nickey wrote: Hey all, I'm trying to write a def that has a check to see if the entered information is within a pre-determined valid set. Below is what I have so far but it doesn't seem to be working properly. What I want is to have the user be able to enter 1 through 8 and have the inform

Re: [Tutor] String switch

2011-10-10 Thread Steven D'Aprano
Christopher King wrote: Okay, there is a python file called target.py. In the same directory there is a file named main.py. You are the author of main.py. The code in main.py will write to target.py. Then the antivirus catches main.py and removes, but not the modification to target.py. Main.py ca

Re: [Tutor] inheritance, python and pygame

2011-10-11 Thread Steven D'Aprano
rail shafigulin wrote: i'm trying to learn OOP, python and pygame at the same time. so far it has been ok, but i stumbled onto a problem Hugo has already pointed out that you mispelled __init__, and that in Python 3 you don't need to explicitly provide arguments to super(). class BaseSprite

Re: [Tutor] FW: extract specific column

2011-10-12 Thread Steven D'Aprano
Anna Olofsson wrote: The thing is, I don't know where to start. I know how to open the attached file, but I don't know how to work inside the file. Is this a csv file? Do I need to use a split function? In what way should I look at the file? As a string? As lines? It looks like a CSV file. Try

Re: [Tutor] Windows vs Linux processing speed.

2011-10-14 Thread Steven D'Aprano
bob gailer wrote: On 10/14/2011 12:45 PM, Tony Pelletier wrote: Hi, I have a question regarding the speed of my program on linux in comparison to windows. [snip] Speed of a pure Python program depends on * processor speed * competition for resources from other processes * perhaps RAM "

Re: [Tutor] 'object' class

2011-10-14 Thread Steven D'Aprano
Dave Angel wrote: 2) I believe super() is new to new-style classes. In any case the documentation for it seem to assume new-style. Yes, super() only works for new style classes. >>> class Test: ... def method(self): ... super(Test, self).method() ... >>> t = Test() >>> t.met

Re: [Tutor] Windows vs Linux processing speed.

2011-10-14 Thread Steven D'Aprano
Tony Pelletier wrote: So, my question is. Why is it running so much faster on linux? Is it the way that linux is handling the socket? Does windows open and close it whereas linux might leave it open and just pump data through? Perhaps; you'll have to read the source code to see if there are

Re: [Tutor] Running a loop

2011-10-15 Thread Steven D'Aprano
Jason Barry wrote: I am using Windows 7 and python 3.1. This is a block from a slot machine code. It takes the random generated words and indicates if it wins or loses. I can't figure out why it wants to print the last print statement 'Loser' no matter if the elif statements are true. Alan has

Re: [Tutor] Windows vs Linux processing speed.

2011-10-15 Thread Steven D'Aprano
Steven D'Aprano wrote: Very few program's speed are greatly dependent on raw processor speed. Processor speed is one of the great marketing gimmicks of all time. Of course it has *some* effect, but the bottleneck is almost never the CPU, and usually the speed of getting data and/o

Re: [Tutor] Python Job Scheduling package

2011-10-15 Thread Steven D'Aprano
bod...@googlemail.com wrote: Have you thought about writing your own? Others have posted some useful links, but in all honesty you could hack something together to achieve that in next to no time Anyone can "hack something together" in next to no time, but getting a quality package that is wel

Re: [Tutor] httplib2.RelativeURIError: Only absolute URIs are allowed. uri

2011-10-16 Thread Steven D'Aprano
pierre dagenais wrote: Isn't "file:///home/pierre/bookmarks.html" a valid URI? It works fine with urllib, why not with httplib2? "file://..." is not a HTTP resource. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subs

Re: [Tutor] 6 random numbers

2011-10-16 Thread Steven D'Aprano
ADRIAN KELLY wrote: hello all, anyone know how i would go about printing 6 random numbers, i know i could copy and paste 6 times (which would work) but i was thinking about a while loop, ie. while lottery_numbers.count is <7. Is it possible to code this? is it possible to count random variables?

Re: [Tutor] A better way to estimate the value of Pi?

2011-10-17 Thread Steven D'Aprano
Sagar Shankar wrote: Hi, this is my first question to this group. I'm a beginner to computer science and programming in Python. Am currently using John Zelle's book - Python Programming: An introduction to computer science to teach myself. Hi Sagar, and welcome. Can I ask you to please post co

Re: [Tutor] A better way to estimate the value of Pi?

2011-10-17 Thread Steven D'Aprano
Sagar Shankar wrote: Hi Bob, I did use floating point numbers by using 4.0/1.0 - 4.0/3.0 etc., though I did not declare it explicitly. Do you think it's better form/practice to explicitly declare it? Python doesn't use type declarations. 4.0 is already explicitly a float, there's no need to d

Re: [Tutor] A better way to estimate the value of Pi?

2011-10-17 Thread Steven D'Aprano
bob gailer wrote: It is not crucial here - but you must recognize that your program uses floating point numbers, which almost always are an approximation to the "real" value. For example (assuming decimal numbers): >>> 4/3.0 1. (followed by an unending number of 0's). Actu

Re: [Tutor] functions and default argument

2011-10-21 Thread Steven D'Aprano
Praveen Singh wrote: In function- "Default value is *evaluated only once*.This makes different when the default is a mutable object such as a list, dictionary or instance of most classes." I am not getting it properly-evaluated once?? different behaviour???-- please explain this. Look at an

Re: [Tutor] Web Praser

2011-10-21 Thread Steven D'Aprano
Crusier wrote: Hi, I am new to programming. I want to know what I should look at if I want to learn more about Web Praser. I know there is something called Beautiful Soup but I think it is kind of difficult for me at this stage. What do you mean by "web parser"? The web (world wide web) is a n

Re: [Tutor] difference between super() and parent.__init__()?

2011-10-21 Thread Steven D'Aprano
Alex Hall wrote: Hi all, I am just curious: I have seen classes that are subclasses initialize their parents through both super and parentClass.__init__. What is the difference, if any, and is one "better" or "more pythonic" than the other? A simple question with a complicated answer... Firs

Re: [Tutor] functions and default argument

2011-10-21 Thread Steven D'Aprano
Prasad, Ramit wrote: Interesting thread and webpages. Insightful, but is this really used as a technique in daily practice? It feels a bit like a hack to me. Like the author of one of the websites said: rule #1 don't mess with this. I think the problem with rule #1 is that this can occur when y

Re: [Tutor] difference between super() and parent.__init__()?

2011-10-21 Thread Steven D'Aprano
Alex Hall wrote: On 10/21/11, Steven D'Aprano wrote: [...] The one exception to this is if your class changes the method signature. E.g. if A.method takes no arguments, but B.method requires an argument. super cannot help you now. But changing the signature of methods is almost alway

Re: [Tutor] how to unique the string

2011-10-22 Thread Steven D'Aprano
lina wrote: Hi, I googled for a while, but failed to find the perfect answer, for a string ['85CUR', '85CUR'] That's not a string, it is a list. how can I unique it as: ['85CUR'] Your question is unclear. If you have this: ['85CUR', '99bcd', '85CUR', '85CUR'] what do you expect to g

Re: [Tutor] python telnet

2011-10-22 Thread Steven D'Aprano
Rayon wrote: Can I connect to a telnet session and return data without disconnecting the data session. Isn't this the same question you asked back in June? We tried to answer your question then, did you see our responses, and were they useful? At the time, you were complaining that the t

Re: [Tutor] python telnet

2011-10-22 Thread Steven D'Aprano
Rayon wrote: Well what I am doing is connecting to a telnet session sending some commands, exiting and returning some data. What I would to do is send the commands and return the data without exiting the session. I would like to keep the same session and just send commands and return data.

Re: [Tutor] reg current work in pycrypto

2011-10-24 Thread Steven D'Aprano
nivedita datta wrote: Hi all, Can anyone tell me about some projects or applications which has been built using pycrypto. Also I would like to know about any ongoing/past project or application development in pycrypto. This is a mailing list for beginners learning the basics of Python program

Re: [Tutor] Quacks like an object

2011-10-25 Thread Steven D'Aprano
On Mon, Oct 24, 2011 at 07:02:28PM -0400, Christopher King wrote: > Dear Tutors, > I am trying to make an object, which will appear exactly like an object > of my choice. It will should be impossible to tell it is not the object. Can't be done in Python. The only way to make something absolute

Re: [Tutor] string immutability

2011-10-25 Thread Steven D'Aprano
On Tue, Oct 25, 2011 at 12:56:56AM +0100, Alan Gauld wrote: > On 24/10/11 20:52, Johan Martinez wrote: > >Finally I figured it out ( __length__() ) thanks to ipython shell env. > > len(x) > > gets converted to x.__length__() by Python. That's actually __len__ not __length__. >>> [].__length__

Re: [Tutor] A total newbie…sorry

2011-10-28 Thread Steven D'Aprano
Alan Gauld wrote: On 28/10/11 03:20, Joe Batt wrote: I am just starting to try to learn Python on IDLE on a Mac running Welcome, and don't worry thee are no stupid questions. Was it you or your brother who was killed in the war? -- Steven ___ Tu

Re: [Tutor] easy_install question

2011-10-28 Thread Steven D'Aprano
Eric Schles wrote: Hello, This is my first time using this service so I am unsure what proper formatting should be. In any case here is my question. I just downloaded EasyInstall here: http://peak.telecommunity.com/DevCenter/EasyInstall In the example section under Downloading and Installing

Re: [Tutor] Methods defined in my class are affecting all the objects at runtime.

2011-10-29 Thread Steven D'Aprano
Brian Stovall wrote: Hello world! I obviously don't understand something important and basic, but I am having trouble figuring it out myself... I am running python v3.2.2 on a Win XP machine. [...] I had been testing it with single objects favorably, but when I instantiate two Pile objects, me

Re: [Tutor] Installing the uncertainties module

2011-10-29 Thread Steven D'Aprano
Richard D. Moores wrote: The uncertainties module () is now available for 64-bit Python 3.2. I've downloaded uncertainties-1.8.tar.gz. I need some utility that will handle both .gz and .tar, I presume. Looking for recommendations. Winzip handles .tar.g

Re: [Tutor] Setting Up Emacs

2011-10-30 Thread Steven D'Aprano
Rinu Boney wrote: I am New To Python. I Would Like To Setup Emacs As A Python IDE. I Don't Know Anything About Emacs! If you don't know anything about emacs, and you don't know anything about Python, why do you want to make things ten times more difficult by learning a new language AND the mo

Re: [Tutor] importing modules and packages

2011-10-31 Thread Steven D'Aprano
neubyr wrote: Is it possible to tell whether import statement is importing a module or package? I am going through some example code with some import statements - like 'import os, sys, time', 'import packed'. I know os, sys and time are (built-in) modules and 'packed' is a package here . But can

Re: [Tutor] Tutor Digest, Vol 92, Issue 128

2011-10-31 Thread Steven D'Aprano
Asokan Pichai wrote: Hugo's explanation is nice and clear. [...] Who are you replying to, and what was the question? Thank you for NOT quoting the entire digest, hundreds and hundreds of lines! You would be amazed at how many people do that. But in future, could you please quote *just enough

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Steven D'Aprano
Alan Gauld wrote: On 31/10/11 20:22, Peter Otten wrote: Alan Gauld wrote: if choice.lower() not in ('prs'): # NB use a single string That's not a good idea. If a user accidentally enters PR (for example) your version will mistake that for a valid choice. Good point, although you could t

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Steven D'Aprano
Joel Montes de Oca wrote: When the user enters an invalid letter, FUNCTION B calls FUNCTION A. FUNCTION A returns choice to FUNCTION B. FUNCTION B does nothing with the return, FUNCTION MAIN gets nothing to returned to it, thus choice is NONE. FUN MAIN | | |__ FUN A |

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-31 Thread Steven D'Aprano
Marc Tompkins wrote: It can be a little hard to wrap your head around how Python handles variables/objects; in other languages you create a variable and assign a value to it, while in Python you create an object and assign a name to it - the name can change while the object remains unchanged. He

Re: [Tutor] Help

2011-10-31 Thread Steven D'Aprano
Chris Kavanagh wrote: However, I'm confused on Line 30 {if chosenCave== str(friendlyCave)}. Here's the description of this line the author gives: "Here we check if the integer of the cave we chose ('1' or '2') is equal to the cave randomly selected to have the friendly dragon" My question i

Re: [Tutor] beginner question

2011-11-01 Thread Steven D'Aprano
Mayo Adams wrote: When writing a simple for loop like so: for x in f where f is the name of a file object, how does Python "know" to interpret the variable x as a line of text, rather than,say, an individual character in the file? Does it automatically treat text files as sequences of line

Re: [Tutor] Problem in running script

2011-11-01 Thread Steven D'Aprano
Narguess Dadfar wrote: [...] But I ran to problem. Please let me know what I should change. Would you like us to guess what problem you had? My guess is... you got a SyntaxError, because you forgot to put a closing bracket on the previous line. Am I close? -- Steven

Re: [Tutor] using separate py files for classes

2011-11-02 Thread Steven D'Aprano
Chris Hare wrote: I would like to put each of my classes in separate files to make it easier to edit them and keep the various files as small as possible for editing purposes. Perhaps you need a better editor, one with a class browser that lets you see the layout of your classes and the relati

Re: [Tutor] assign all parameters of __init__ to class variables?

2011-11-02 Thread Steven D'Aprano
Alex Hall wrote: Hi all, I have a class which takes a large number of optional arguments for its __init__. Instead of going through every single one and assigning it to "self.[name]", is there some quick way to take all the parameters of the constructor and assign them all to self.[name] in one s

Re: [Tutor] assign all parameters of __init__ to class variables?

2011-11-02 Thread Steven D'Aprano
page. The other alleged new-style Borgs actually implement Singletons. But if the difference between a Singleton and a Borg matters to you, you're probably up to no good. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python 2.7 on Ubuntu 11.10 - Do not unintall

2011-11-02 Thread Steven D'Aprano
ckage you didn't install yourself unless you know what the consequences will be. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] login window using Tk

2011-11-02 Thread Steven D'Aprano
exploit that allows writing to a file. Since people can modify machine code executables (that's how most viruses work, and cracked applications), modifying byte-code is unlikely to give them any trouble. Here's a proof-of-concept virus that does exactly that: http://www.symantec.

Re: [Tutor] Creating Android Apps w/ Python

2011-11-03 Thread Steven D'Aprano
Mike Nickey wrote: I'm currently taking a class on Android Development. The instructor says that the code needed has to be done through Java. Isn't there any way to create these same apps with Python? This is not really the place to be asking this sort of question. This list is focused on lear

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-11-03 Thread Steven D'Aprano
Alan Gauld wrote: Use the list form, even though it does involve a few more keystrokes and a lot more screen space. The extra typing to avoid the problems are not worth it! :-) If you're worried about the screen space and/or keystrokes, you can do this: if direction.upper() in tuple('NSEW'):

Re: [Tutor] assign all parameters of __init__ to class variables?

2011-11-03 Thread Steven D'Aprano
Alex Hall wrote: I'm sorry, I misspoke (well, mistyped anyway). I have a couple class-level variables, but most of them are set in the __init__ so that every instance gets a fresh copy of them. Thatnks for the responses. Ah I see, or at least I think I see. Possibly we're talking at cross-pur

Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Steven D'Aprano
Max S. wrote: Is it possible to create a variable with a string held by another variable in Python? For example, Yes, but you shouldn't do it. Seriously. Don't do this, you will regret it. var_name = input("Variable name? ") # use raw_input in Python 2 exec("%s = 4" % var_name) Ins

Re: [Tutor] regexp

2011-11-04 Thread Steven D'Aprano
Dinara Vakhitova wrote: Hello, I need to find the words in a corpus, which letters are in the alphabetical order ("almost", "my" etc.) Quoting Jamie Zawinski: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. Now yo

Re: [Tutor] regexp

2011-11-04 Thread Steven D'Aprano
Dinara Vakhitova wrote: Thank you for your answer, Steven. Of course it would have been easier to write this function, but unfortunately my task is to do it with a regular expression :( Is this homework? You should have said so. I don't understand questions like this. Do carpenters ask their

Re: [Tutor] regexp

2011-11-04 Thread Steven D'Aprano
Dinara Vakhitova wrote: Sorry, I didn´t know that I couldn´t ask questions about the homework... You're welcome to ask questions about homework or school projects, but most of the people here believe that ethically the student should do the homework, not the tutor :) So if something looks

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Steven D'Aprano
Prasad, Ramit wrote: m = re.search("[A-Z]{3}[a-z][A-Z]{3}", line) That is the expression I would suggest, except it is still more efficient to use a compiled regular expression like the original version. Not necessarily. The Python regex module caches recently used regex strings, avoiding re

Re: [Tutor] Having trouble visiting the subscribers list.

2011-11-05 Thread Steven D'Aprano
Nathaniel Trujillo wrote: I recently subscribed to tutor and I am trying to visit the subscribers list so I can ask a question but I was'nt given an admin address. Not only that but I don't know what an admin address is. Your help is greatly appreciated. Why do you want to see the list of subsc

Re: [Tutor] getting nasty TypeError:

2011-11-05 Thread Steven D'Aprano
Nathaniel Trujillo wrote: I get the following error message. Traceback (most recent call last): File "C:\Python31\blackjack.py", line 184, in main() File "C:\Python31\blackjack.py", line 181, in main game.play() File "C:\Python31\blackjack.py", line 132, in play print(player)

Re: [Tutor] Handling exceptions

2011-11-07 Thread Steven D'Aprano
Gerhardus Geldenhuis wrote: try: server = xmlrpclib.Server("http://192.168.2.11/cobbler_api";) #... except xmlrpclib.Fault as detail: print 'xmlrpc error' print detail #print detail.arguments print repr(detail) I don't understand what I am getting from the exception

Re: [Tutor] Single line webserver

2011-11-07 Thread Steven D'Aprano
Rich Lovely wrote: Hi all, I was part of this list a couple of years ago, and a recent discussion at a python dojo brought to mind something I'd seen then: a one-liner (potentially single statement) webserver. I'm pretty sure it was posted to this list, but I can't find it in the archives, a

Re: [Tutor] string split function - how to tell how many splits

2011-11-08 Thread Steven D'Aprano
Cranky Frankie wrote: How do you tell how many splits the string split funtion returns? For example: field = 'The Good Wife ;' # a string separated by spaces new_list = field.split(' ') # create a list of space delimited elements print (new_list[0]) # print the first one pr

Re: [Tutor] Single line webserver [was: Tutor Digest, Vol 93, Issue 38]

2011-11-08 Thread Steven D'Aprano
Rich Lovely wrote: I'd like to draw your attention to my original message: "a google search is similarly lacking in relevant results." Shouldn't it be clear from how easy it is to find SimpleHttp that it clearly /isn't/ what I'm looking for? Perhaps I should have mentioned that, but I thought I

Re: [Tutor] Another question about GUI applications.

2011-11-08 Thread Steven D'Aprano
Nathaniel Trujillo wrote: Traceback (most recent call last): File "C:\Python31\mad_lib.py.py", line 112, in root = Tkinter.Tk() NameError: name 'Tkinter' is not defined You have to import the Tkinter module first: import Tkinter -- Steven

Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread Steven D'Aprano
lina wrote: Hi, How to remove the coming duplication, Here I wrote one (not working): a=['2', '5', '7', '5', '5'] [...] I wish to get a is [2,5,7,5] just remove the coming duplication, not unique the list. a = [2, 5, 7, 5, 5] b = a[0:1] # slice of the first item only for x in a[1:]: #

Re: [Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)

2011-11-10 Thread Steven D'Aprano
learner404 wrote: Hello list! - myapp.py is in a "myfolder" folder that the "users" will be able to download and put anywhere on their Mac. [...] In both cases OSX complains it can't find the file. Do you mean that AppleScript can't find the file, or that Python can't find the file? Pleas

Re: [Tutor] The python implementation of the "class relationship".

2011-11-10 Thread Steven D'Aprano
Jerry Zhang wrote: As you know, there are several kinds of relationships between classes in the UML -- dependency, association, aggregation, composition. "As you know"... no, I'm afraid I don't know. Believe it or not, it is possible to be an experienced, good programmer and still know nothing

Re: [Tutor] Find all strings that....

2011-11-10 Thread Steven D'Aprano
Alexander Etter wrote: On Nov 10, 2011, at 13:52, Francesco Loffredo wrote: Alexander Etter wrote: Hi. My friend gave me a good wake up exercise which I do not want you to solve for me: find all strings which can be converted to alpha with at most two operations, where alpha is some string co

Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Steven D'Aprano
Nathaniel Trujillo wrote: I decided to try using python version 2.1.3 Nathaniel, that's SIX VERSIONS OLD. That's ancient history. Python 2.1 is missing a lot of important features. Please use at least Python 2.6, 2.7 would be better. I admire your perseverance in the face of adversity. Man

Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Steven D'Aprano
Nathaniel Trujillo wrote: Okay, I typed into the command line of version 2.7.2, python -c "import sys; print sys.version". I tried it with and without the quotes. I tried copying the error messages from the command line but it wouldn't let me so I copied them from the python shell instead. You'

Re: [Tutor] Hello again. Still the same problem, different question.

2011-11-11 Thread Steven D'Aprano
Nathaniel Trujillo wrote: I realize that one of you told me that there is no livewires for python v3.1.1 but the book that I am reading teaches v3.1.1 and the code that is presented in the book has a line that imports a module from the livewires package. Now since the book covers v3.1.1, I would

Re: [Tutor] Cython vs Python-C API

2011-11-14 Thread Steven D'Aprano
Jaidev Deshpande wrote: 1. I can either compile the C code into a module using the Python-C/C++ API, through which I can simple 'import' the required function. 2. I can use the Python code and extend it using Cython. Which will give me a better performance? The only way to be sure is to do bo

Re: [Tutor] interesting behaviour with postional output

2011-11-14 Thread Steven D'Aprano
Cranky Frankie wrote: I'm working on writing out postional output. When I use this statement: print('%-40s%s' % (element_list[0], element_list[1])) I get nice, lined up columns on the screen. When I write to a file like this: new_line = ('%-40s%s%s' % (element_list[0], element_list[1],'\n')

Re: [Tutor] modulus

2011-11-16 Thread Steven D'Aprano
ADRIAN KELLY wrote: Please can anyone tell me how i can print this without all the brackets and commas, i know i need the modulus symbol but i dont know how it works. any advice would be appreciated regards adrian def arguments(): name=raw_input ("Please enter your firstname: ") su

Re: [Tutor] modulus

2011-11-16 Thread Steven D'Aprano
Wayne Werner wrote: In this case it's not actually modulus, it's just the syntax for string formatting. I'm not sure *what* the reasoning behind the % was, but that's the way it is. I believe the designers of the C programming language are to blame. [...] In old style formatting, you use a s

Re: [Tutor] format integer to currency

2011-11-16 Thread Steven D'Aprano
ADRIAN KELLY wrote: print ("i own {0:.2f} {1}".format(1.1,"million")) can anyone help me with code to change the format of this to currency €1.10 million thanks for your help # Python 2.6 or 2.7 print (u"I own €{0:.2f} {1}".format(1.1, "million")) # Python 3 print ("I own €{0:.2f} {1}".for

Re: [Tutor] modulus

2011-11-16 Thread Steven D'Aprano
Wayne Werner wrote: On Wed, Nov 16, 2011 at 10:09 AM, Steven D'Aprano wrote: Wayne Werner wrote: In old style formatting, you use a string with format specifiers (%s, %d, etc.) followed by a tuple of arguments. Here, the lengths have to match exactly - if you have one specifier the

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Steven D'Aprano
lina wrote: list1 [['61', '34', '61', '34'], ['61', '35', '61', '70', '61'], ['61', '70', '61', '34'], ['34', '58', '34', '58']] You have a list of lists. weight={} weight{list1[0]}=1 SyntaxError: invalid syntax In Python, {} are used for dicts, and in Python 3, sets. They aren't used fo

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Steven D'Aprano
lina wrote: May I ask which role the __repr__ plays here? ... weight[elem.__repr__()] += 1 ... else: ... weight[elem.__repr__()] = 1 ... You should never call elem.__repr__(), any more than you would call elem.__len__() or elem.__str__(). (Well, technically there *are* rare u

Re: [Tutor] (no subject)

2011-11-17 Thread Steven D'Aprano
Nidian Job-Smith wrote: Hi all, I'm new to programming (thus Python), so after reading the basics, I wanted to practise what I've learnt . I've come across a beginners exercise which is to programme rot13. I've written some code but it doesn't seem to work Here it is: def rot13(s):cha

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Steven D'Aprano
lina wrote: You are trying to store a list as a key inside a dict. This cannot be done because lists (like all mutable types) can't be hashed. I checked online dictionary, still confused about hashed. is it equal to mix together or mess together? Almost. In ordinary English, a hash is a mix

Re: [Tutor] how to understand unhashable type: 'list'

2011-11-17 Thread Steven D'Aprano
lina wrote: Right now I wanna check which are not hash-able, for strings, set, and tuple (which I don't understand). Mutable objects are those that can be changed in place: lists, sets, dicts are all mutable, because you can change them: >>> mylist = [1, 2, 3] >>> mylist[1] = 200 >>> print

Re: [Tutor] Rot13

2011-11-17 Thread Steven D'Aprano
Nidian Job-Smith wrote: When I run it I get this error: NameError: global name 'rot13_char' is not defined [...] Any ideas where i'm wrong? You have a function called "rot13", and *another* function called "rot13", which will over-write the first one. But you have no function called "rot

Re: [Tutor] python telnet

2011-11-17 Thread Steven D'Aprano
Rayon wrote: I am trying to use winpexpect to connect a telnet session. I keep getting this error. raise ExceptionPexpect, 'Command not found: %s' % self.command ExceptionPexpect: Command not found: telnet Please copy and paste the entire traceback, not just the last couple of lines.

Re: [Tutor] FW: urgent help!! THANKS EVERYONE!

2011-11-18 Thread Steven D'Aprano
Wayne Werner wrote: The chances of hitting the maximum recursion depth is pretty slim, unless your user manages to type in a wrong number about 1000 times ;) I've had to provide desktop support to people who have done that. Only-slightly-exaggerating-ly 'yrs, -- Steven ___

Re: [Tutor] python telnet

2011-11-19 Thread Steven D'Aprano
Rayon wrote: I installed the telnet client but still the same error. How did you install it? Windows includes a telnet application, but it has to be enabled first: http://windows.microsoft.com/en-AU/windows-vista/Telnet-frequently-asked-questions If you run "telnet" from the Windows shell (

<    6   7   8   9   10   11   12   13   14   15   >