Re: [Tutor] Compound if statement question.

2011-05-01 Thread Steven D'Aprano
Greg Christian wrote: Is there a way to write an if statement that will pick up duplicates (two ‘1’s): L = ['1', '4', '1'] if (L[0]) != (L[1]) != (L[2]): print "THEY ARE NOT EQUAL" else: print "THEY ARE EQUAL" When I run this code, it prints “THEY ARE NOT EQUAL” when it should print the

Re: [Tutor] (no subject)

2011-05-02 Thread Steven D'Aprano
Austin Rodgers wrote: I’m trying to learn by using pyschools.com, and ran across a question I can’t answer. I tried to google it, but I don’t even know what type of function I’m looking for. I know I am supposed to modify the list, but I just can’t figure out how. anyway, here’s the question:

Re: [Tutor] Filtering out unique list elements

2011-05-04 Thread Steven D'Aprano
Spyros Charonis wrote: Dear All, I have built a list with multiple occurrences of a string after some text processing that goes something like this: [cat, dog, cat, cat, cat, dog, dog, tree, tree, tree, bird, bird, woods, woods] I am wondering how to truncate this list so that I only print out

Re: [Tutor] dictionary

2011-05-05 Thread Steven D'Aprano
louis leichtnam wrote: HEllo everyone, I have a dictionnary, and I would like to print only the values that have more/equal than 3 spaces in them for example: My name is Xavier. d = {1: "Hello world", 2: "My name is Xavier", 3: "ham and eggs", 4: "Eat more cheese please!", 5: "spam spam

Re: [Tutor] Need some help

2011-05-07 Thread Steven D'Aprano
Aaron Brown wrote: Here is the code I have, and the error.I don't understand the TUPLE problem. Can someone explain. The error you get is: TypeError: 'tuple' object does not support item assignment This tells you that tuples are immutable (fixed) objects. You cannot do this: >>> t = (1,

Re: [Tutor] How to extract a value from a matrix.

2011-05-07 Thread Steven D'Aprano
dlwdan...@uct.ac.za wrote: Hi there I am a student and is new to python. I would like to know how to exact a value from a list that has been opened from a text file in python. Exactly the same way that you would get a value from any other list. >>> my_list = [10, 20, 30, 40, 50] >>> print my

Re: [Tutor] Printing output from Python program to HTML

2011-05-10 Thread Steven D'Aprano
Spyros Charonis wrote: newline = line.replace(item, " item ") # compiler complains here about the word "red" You should pay attention when Python tells you where there is an error. If it says there is a syntax error, then your syntax is invalid and you need to fix it. The Pyth

Re: [Tutor] cpython

2011-05-14 Thread Steven D'Aprano
that it runs on top of CPython. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Academic publications

2011-05-16 Thread Steven D'Aprano
bably just give a link to where people can download it. But I'm just guessing. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] can I walk or glob a website?

2011-05-18 Thread Steven D'Aprano
nloading' is called again, something > that sounds like 'whacking' (??) Sometimes called screen or web scraping, recursive downloading, or copyright-infringement *wink* http://en.wikipedia.org/wiki/Web_scraping -- Steven D'Aprano __

Re: [Tutor] Help with understanding classes

2011-05-21 Thread Steven D'Aprano
you don't need to care about it, *except* that you have to remember to declare a parameter in all your methods to hold that auto-magic instance argument. Conventionally, we call it "self", but you can call it anything you like. (You can, but you shouldn't.) Forgetting to de

Re: [Tutor] need help with lxml errors

2011-05-22 Thread Steven D'Aprano
ime) The later tries to insert a method get_time into the element tree. You need to call the method by putting brackets () after it. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mai

Re: [Tutor] Python and the web

2011-05-22 Thread Steven D'Aprano
don't inflict another of those abominations on the world. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Logical Structure of Snippet

2011-05-23 Thread Steven D'Aprano
x27;ICA1_BOVINE': description, 'ICA1_HUMAN': description, ...} If you need help assembling this dict, just ask. With a dict, searches are easy. Making the new line takes three short lines of code: key = extract_ica(line) descr = descriptions[key] new_li

Re: [Tutor] Clunky Password maker

2011-05-27 Thread Steven D'Aprano
of getting random numbers has been the random module all the way back to version 1.5! Since version 2.3, Python has been using the Mersenne Twister as the default random number generator, instead of Wichmann-Hill. Mersenne Twister is *much* better and stronger than WH. --

Re: [Tutor] Cherrypy

2011-05-27 Thread Steven D'Aprano
Sorry Bryton, I don't know any. Have you googled to see what is available? -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python Variables Changing in Other Functions

2011-05-27 Thread Steven D'Aprano
Rachel-Mikel ArceJaeger wrote: Hello, I am having trouble with determining when python is passing by reference and by value Others have already discussed this, but at the risk of blowing my own trumpet, I'd like to point you at an earlier discussion on this list: http://mail.python.org/pi

Re: [Tutor] Creating a dictionary

2011-05-27 Thread Steven D'Aprano
Válas Péter wrote: Hi, I think I am new to here, as far as I remember. :-) http://docs.python.org/dev/library/stdtypes.html#dict says: we can create a dictionary with - dict({'one': 1, 'two': 2}) What is the adventage of this form to simply writing d = {'one': 1, 'two': 2}? Is there any dif

Re: [Tutor] Python Interview Questions..

2011-05-27 Thread Steven D'Aprano
Marc Tompkins wrote: And anyone who starts down that road will be weeded out very quickly. Not quickly enough! They should be weeded out IN SCHOOL, or before they even commit to a computer-science track. It's cruel to students, inefficient for business, and disastrous for consumers if they d

Re: [Tutor] Python Interview Questions..

2011-05-27 Thread Steven D'Aprano
Alan Gauld wrote: "Walter Prins" wrote Java just isn't a hard enough language to separate great programmers from plodders (neither is Python, for that matter) because pointers and memory allocation are taken care of automagically. I fundamentally disagree with his stand on this. Not sure w

Re: [Tutor] zero crossing pitch detection

2011-05-29 Thread Steven D'Aprano
김태윤 wrote: hello I made a simple recording / pitch detecting program but it seems work weird way when I record "a~" then this program printing (I am not a singer and I can't go up and down G0 and C3) I'm afraid that most of your post just went over my head. I have no idea what these G0 an

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Steven D'Aprano
Timo wrote: Hello all, I have a question about how this is done the best way. In my project I have a folder with multiple file parsers, like this: - src -- main.py -- parsers --- __init__.py --- parser1.py --- parser2.py This gives you a stand-alone module called "main.py", and a sepa

Re: [Tutor] Finding error from os.system(cmd)

2011-05-30 Thread Steven D'Aprano
Kann Vearasilp wrote: Dear all, I tried using python to execute some external java program in my code. My problem is the os.system(cmd) was not working properly while Define "not working properly". My guess is that you're probably getting an exception OSError: [Errno 2] No such file or dire

Re: [Tutor] Nicer error message

2011-05-31 Thread Steven D'Aprano
Válas Péter wrote: Hi, my code is (Python 2.5): class SomeError(Error): """Uff!""" raise SomeError, "blahblah" Screen result: __main__.SomeError: "blahblah" I get Traceback (most recent call last): File "", line 1, in NameError: name 'Error' is not defined How can I make "__main__

Re: [Tutor] Nicer error message

2011-05-31 Thread Steven D'Aprano
Válas Péter wrote: 2011. május 31. 16:39 Japhy Bartlett írta, : You could write directly to sys.stderr instead of raising an error. If other programmers have to work with your code, they'll probably find this _incredibly_ annoying. You mean there is no way to write it nicely? Or are error m

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Steven D'Aprano
Peter Lavelle wrote: I think you could also use the type() function. See example below: if type(yourvar) == int: #Do stuff here if it is an integer You can do that, but that will miss out on subclasses of int. It is better to use isinstance(yourvar, int) which will accept an int, or a s

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Steven D'Aprano
Rachel-Mikel ArceJaeger wrote: Isn't one of the unsolved millenium prize problems one that includes the ability to find all of the prime numbers? I'm not sure if your program is possible if the input number is large. Finding all the prime numbers isn't hard. Well, it's not hard if you have a

Re: [Tutor] checking if a variable is an integer?

2011-06-01 Thread Steven D'Aprano
Válas Péter wrote: Hi guys, do you think, Hans, who wants to write his first prime number program, still understands what we are talking about? :-) If not, he can google the bits he doesn't understand, or ask. We won't bite! -- Steven ___ Tutor ma

Re: [Tutor] __init__.py question

2011-06-01 Thread Steven D'Aprano
Marilyn Davis wrote: [...] There's something I'm missing because I think you simply can't call something string.py unless you are willing to give up the library string.py. No, you're right about that. Python's search path is "first match wins". Whether it's a package or a module, it will match

Re: [Tutor] Structured files?

2011-06-02 Thread Steven D'Aprano
Alan Gauld wrote: "Alexandre Conrad" wrote you want to share that data between non-Python application, I could also suggest the use of the JSON module. JSON is a standard format (see json.org) supported by many programming languages. But isn't it a string based format? I thought JSON conve

Re: [Tutor] if statement

2011-06-08 Thread Steven D'Aprano
Matthew Brunt wrote: i'm very new to python (currently going through a python for beginners book at work to pass the time), and i'm having trouble with an if statement exercise. basically, i'm creating a very simple password program that displays "Access Granted" if the if statement is true. the

Re: [Tutor] Python Beginners

2011-06-08 Thread Steven D'Aprano
Vincent Balmori wrote: Hello. Right now I am learning the python language through Python Programming for the Absolute Beginner 3rd Edition. I am having trouble with one question in Ch. 4 #3, which says "Improve 'WordJumble so that each word is paired with a hint. The player should be able to se

Re: [Tutor] Python Beginners

2011-06-08 Thread Steven D'Aprano
Dave Angel wrote: On 01/-10/-28163 02:59 PM, Vincent Balmori wrote: Hello. Right now I am learning the python language through Python Programming for the Absolute Beginner 3rd Edition. I am having trouble with one question in Ch. 4 #3, which says "Improve 'WordJumble so that each word is paired

Re: [Tutor] Copying a mutable

2011-06-08 Thread Steven D'Aprano
Válas Péter wrote: Being one of the purposes of Python to be a simple educational language, I want to make this simple to a beginner who does care. :-) Here is a piece of code, Python 3.1.2, a small game with a list and a tuple: li=[3,4] id(li) 13711200 la=li id(la) 13711200 You can make

Re: [Tutor] lxml.html

2011-06-08 Thread Steven D'Aprano
nitin chandra wrote: Hello Every One, doc = lxml.html.parse('/home/dev/wsgi-scripts/index.py').getroot() name = doc.forms[0].fields['name'] html = 'name is ' html += name ERROR [Wed Jun 08 20:29:51 2011] [error] [client 192.168.1.9] Traceback (most recent ca

Re: [Tutor] lxml.html

2011-06-08 Thread Steven D'Aprano
nitin chandra wrote to me off-list. I've taken the liberty of returning the conversation to the mailing list. Hi, ERROR [Wed Jun 08 20:29:51 2011] [error] [client 192.168.1.9] Traceback (most recent call last): What is all this extraneous date/error/ip address nonsense in the traceback? Wher

Re: [Tutor] Lists

2011-06-10 Thread Steven D'Aprano
Vincent Balmori wrote: I'm stuck on two problems from the Absolute Beginners book. The first is simple. I am trying to print all the words in the list in random order without repeats, but it always shows None for some reason. #Program prints list of words in random order with no repeats impor

Re: [Tutor] telnet connection question

2011-06-10 Thread Steven D'Aprano
Rayon wrote: HI All, Is there any way that I can use python telnetlib to connect to a telnet session. It would be a pretty rubbish telnet library if it didn't let you make telnet connections. I don't understand why you are asking this question, since you have successfully made connection

Re: [Tutor] Lists

2011-06-10 Thread Steven D'Aprano
Piotr Kamiński wrote: Could you please refrain from presenting your *religious* convictions in this list: the notions you believe in as well as the ones that you believe are false? This is a *technical* list, as I understand it, solely dedicated to the technical side of teaching the *Python* pr

Re: [Tutor] STUPID telnet connection question

2011-06-11 Thread Steven D'Aprano
davidheise...@gmail.com wrote: I think Steven and Alan misunderstood the Rayon's question. Rayon is using his telnet script to pass commands to a device ONE AT A TIME. Then he breaks the connection and reconnects for the next command.. He is asking how to open a telnet connection, pass MULTI

Re: [Tutor] dummy, underscore and unused local variables

2011-06-11 Thread Steven D'Aprano
Tim Johnson wrote: Consider the following code: for i in range(mylimit): foo() running pychecker gives me a """ Local variable (i) not used """ complaint. If I use for dummy in range(mylimit): ## or for _ in range(mylimit): I get no complaint from pychecker. I wou

Re: [Tutor] Saving data as jpg file

2011-06-11 Thread Steven D'Aprano
Johan Geldenhuys wrote: Hi, I have a Axis IP camera that I can send a HTTP command to and the data returned is the jpg image. When I get this data, I want to save it as a .jpg file, but I think my encoding is not correct, because the image is all distorted. Are you sure that the data produced

Re: [Tutor] Floating Point Craziness

2011-06-12 Thread Steven D'Aprano
Ryan Strunk wrote: Hi everyone, I'm designing a timeline. When the user presses the right arrow, 0.1 is added to the current position. The user can add events to the timeline, and can later scroll back across those events to see what they are. But something I absolutely don't understand is happen

Re: [Tutor] [OT] Re: Floating Point Crazines

2011-06-12 Thread Steven D'Aprano
Robert Sjoblom wrote: * Or you just get used to the fact that some numbers are not exact in floating point. This got me thinking. How many decimal places do you need to accurately, say, aim a laser somewhere in a 180 degree arc accurately enough to hit a dime on the surface of the moon? Alan

Re: [Tutor] Creating Reports in Python

2011-06-12 Thread Steven D'Aprano
Mark Cowley - FlexSystems wrote: Hi I am looking for recommendations for Report writers under Python. Current reports are in Crystal reports if that is an option. Any suggestions are welcome. You might get more responses on the main python mailing list, python-l...@python.org, or comp.la

Re: [Tutor] step value

2011-06-13 Thread Steven D'Aprano
Vincent Balmori wrote: I am stuck on a question for Absolute Beginner's. I googled this and there have been others who have not understood the question and I am also not clear on the question he is asking. This function is a part of a tic tac toe program."Improve the function ask_number() so th

Re: [Tutor] python-gobject for debian4

2011-06-13 Thread Steven D'Aprano
Ganesh Kumar wrote: Hi Guys. I want python-gobject package for debian4 (etch). But unfortunately removed for debian4 depository . This is not a Python problem. It is especially not a problem about learning Python. You should ask this at either a Debian forum or on the python-gobject mailin

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano
Nathan wrote: who can tell me how to unsubscribe the message. Look at the bottom of every single message to the mailing list, and you will see this: Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steven _

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano
Válas Péter wrote: 2011/6/12 Brett Ritter Okay fine, so "1024" stored as a number only requires 10 bits (binary digits) to store, Actually, 11. :-) I see your smiley, but actually more than that. Due to the way computers are designed, numbers are stored in fixed bundles of 8 bits making a

Re: [Tutor] Medical Decision-Making Question

2011-06-13 Thread Steven D'Aprano
Fred G wrote: Hello-- I'm a pre-med student interested in decision-making as applied to medical decisions. I am trying to build a medical decision-making algorithm and am pretty stuck on a few things. Essentially what you want is to build an expert system. I don't want to discourage you, bu

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano
Kĩnũthia Mũchane wrote: On 06/12/2011 08:13 PM, Steven D'Aprano wrote: Unfortunately, many common fractions cannot be written exactly in binary. You're probably familiar with the fact that fractions like 1/3 cannot be written exactly in decimal: 1/3 = 0.... goes on foreve

Re: [Tutor] Break stament issue

2011-06-14 Thread Steven D'Aprano
Susana Iraiis Delgado Rodriguez wrote: Hello members! I'm doing a script that needs to loop to get some information, in order to do that I'm using modules from OGR and Mapnik. These to get data from shapefiles, but some of the files have 0 elements, I wrote a line to validate it, but it hasn't w

Re: [Tutor] Communicating Between Programs Using Raw Inputs

2011-06-14 Thread Steven D'Aprano
Jacob Bender wrote: Dear Python Tutors, I was wondering how to break into my one program I made using brute force methods. Here's the code: password = "Helloworld" try= raw_input("What's the password?") while try != password: try = raw_input("Incorrect, what's the password?") I know how t

Re: [Tutor] Already Initialized Object Inheritance?

2011-06-15 Thread Steven D'Aprano
WolfRage wrote: Unfortunately I am not able to inherit "stdscr" using that method. As Python returns with an error stating that "stdscr" is not defined. This error is returned at run time and by the compiler prior to actual execution. If you would like I can write a quick example that will genera

Re: [Tutor] step value

2011-06-15 Thread Steven D'Aprano
Vincent Balmori wrote: The question to that code I am trying to solve is "Improve the function ask_number() so that the function can be called with a step value. Make the default value of step 1." You need to be able to tell ask_number what step function you want to use. So it isn't enou

Re: [Tutor] using python to write web page

2011-06-15 Thread Steven D'Aprano
naheed arafat wrote: Got a question in this context. If i would like to edit an html file. suppose i want to edit the values of href tags or the img tags, what should i do? This question is more general than just editing HTML files. The same question, and answer, applies to editing *any* file

Re: [Tutor] Tutor Digest, Vol 88, Issue 56

2011-06-16 Thread Steven D'Aprano
WolfRage wrote: CODE BELOW #!/usr/bin/python3 """With this method I can make the class "Screen" become "stdscr" but if I refernce any of the new methods or properties the applications promptly fails and notifies me that the attribute does not exist.""" That's because it doesn't exist.

Re: [Tutor] Step Value

2011-06-16 Thread Steven D'Aprano
Vincent Balmori wrote: Okay, I think I understand it better for the quesiton: "Improve the function ask_number() so that the function can be called with a step value. Make the default value of step 1." Here is the improved function and the human_move function that calls it later on. The thing

Re: [Tutor] File parsing

2011-06-16 Thread Steven D'Aprano
Neha P wrote: Thanks James I guess i have to use the same code for text in yellow... seems like ther's no other way... What code in yellow? I see no code in yellow. This is email, don't assume people can see colours. They may have HTML blocked or turned off (very important for security, avo

Re: [Tutor] Seattle PyCamp 2011

2011-06-17 Thread Steven D'Aprano
Noah Hall wrote: Just a note, but are these questions jokes? Know how to use a text editor (not a word processor, but a text editor)? Know how to use a browser to download a file? Know how to run a program installer? If not, then I'd consider removing them. This isn't 1984. I think the que

Re: [Tutor] Step Value

2011-06-17 Thread Steven D'Aprano
Vincent Balmori wrote: Here is my updated code. As simple as this may be, I am a little lost again. I appreciate the help and explanations to try to push me to get this on my own, but at this point (especially after one week) this is when me being given the answer with an explanation will help me

Re: [Tutor] Break stament issue

2011-06-17 Thread Steven D'Aprano
Susana Iraiis Delgado Rodriguez wrote: Hello members!! Steven, I already changed the settings in the IDE to avoid the trouble when I type the code. In the other hand I added the pass statement so the script keep working even though it finds an error, but the scripts ignore the pass statement. Co

Re: [Tutor] Medical Decision-Making Question

2011-06-17 Thread Steven D'Aprano
Fred G wrote: Thanks guys for all the feedback. re Jim's comments: I completely agree that the difference b/t "slight" fever and "returning" fever, etc will pose some problems. My hunch is that initially I'll just do something like make "fever" be the only one for now Any qualitative rating s

Re: [Tutor] Closing triple quotation marks.

2011-06-18 Thread Steven D'Aprano
Lisi wrote: [...] Fair enough. the closing quotation marks are not there. But when they _are_ there, i.e. when that stanza reads: target.write """ line1\nline2\nline3\n """ This is not the problem, but I just thought I'd mention that it's a bit silly to go to the trouble of using newline esc

Re: [Tutor] Closing triple quotation marks.

2011-06-18 Thread Steven D'Aprano
Lisi wrote: But I still can't write to the file. If I do: target.write(line1) The value of the variable line1 is written to the file. But if I put the three variables into the write command, what gets printed is the name of the variables, not their values. I am clearly still doing someth

Re: [Tutor] using configobj package to output quoted strings

2011-06-18 Thread Steven D'Aprano
Alex Hall wrote: Hello all, I am using the configobj package to handle a ridiculously simple ini What's configobj? >>> import configobj Traceback (most recent call last): File "", line 1, in ImportError: No module named configobj It's not in the 3.1 standard library. Is it a third-part pac

Re: [Tutor] using configobj package to output quoted strings

2011-06-18 Thread Steven D'Aprano
Alex Hall wrote: Still, it is odd (well, to me at least) that when I write the string to the file with no quotes, I get no quotes, but using double quotes in the string's value gives me both single and double quotes. Sounds to me like bad design on the part of configobj, but perhaps I'm misu

Re: [Tutor] nitinchandra rubbish on list

2011-06-19 Thread Steven D'Aprano
Válas Péter wrote: Each time I send a message to this list, I get an autoreply like this. No, I won't add myself to any stupid guestlists to use a public list. Could a list moderator please show this user the exit? I've been sending many lists to this list, and haven't received any such autore

Re: [Tutor] line continuation characters

2011-06-19 Thread Steven D'Aprano
Lisi wrote: I am having problems with line continuation characters. Error message: SyntaxError: unexpected character after line continuation character Then delete it ;) Seriously. You have your editor open, right? Go to the line where the error is reported. It will look something like this:

Re: [Tutor] nitinchandra rubbish on list

2011-06-19 Thread Steven D'Aprano
nitin chandra wrote: Hello All, MY Sincerest APOLOGIES i had joined a a mail box management services... But unfortunately It started interfering with my Gmail mail box. Thanks for fixing this! -- Steven ___ Tutor maillist - Tutor@python.org

Re: [Tutor] decorators

2011-06-23 Thread Steven D'Aprano
Robert wrote: Is there a good tutorial out there somewhere about decorators? Google doesn't bring up much. Define "good" :) I'm interested in what you think about this article: http://www.artima.com/weblogs/viewpost.jsp?thread=240808 Personally, I think it's filled with jargon that will b

Re: [Tutor] decorators

2011-06-24 Thread Steven D'Aprano
Prasad, Ramit wrote: Excellent explanation Steven; I understood the mechanical basics but this has made the reason behind it a lot clearer. If test_argument is only being passed the function how does it have access to the arguments? It doesn't. There are three functions involved. The first is

Re: [Tutor] Conceptual Question About Use of Python for Employee Training Program

2011-06-25 Thread Steven D'Aprano
Adam Carr wrote: Good Morning: I am very new to Python but I am enjoying the learning process. I have a question about the application of Python to a problem at the industrial business where I work. My two main questions are: 1. Can Python be used to achieve the goals of the possible project

Re: [Tutor] Efficiency

2011-06-25 Thread Steven D'Aprano
naheed arafat wrote: 1) zip('How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] map(lambda i,j:(i,j),'How are you?'.split(' ')[::-1],'i am fine.'.split(' ')) [('you?', 'i'), ('are', 'am'), ('How', 'fine.')] Which one has better efficiency

Re: [Tutor] Efficiency

2011-06-25 Thread Steven D'Aprano
arafat wrote: On Sat, Jun 25, 2011 at 9:42 PM, Steven D'Aprano wrote: [...] Define "efficiency". Do you mean: - most efficient for the programmer to write? - easiest to read? - fastest for the compiler to compile? - uses the smallest number of characters in source code? - takes

Re: [Tutor] Defining a "format string"

2011-06-26 Thread Steven D'Aprano
Lisi wrote: In the following excerpt from a program in the book I am following: print "If I add %d, %d, and %d I get %d." % ( my_age, my_height, my_weight, my_age + my_height + my_weight) is % ( my_age, my_height, my_weight, my_age + my_height + my_weight) the/a format str

Re: [Tutor] The Card Game

2011-06-30 Thread Steven D'Aprano
Christopher King wrote: I would go with __cmp__ which covers them all. 1 for greater, 0 for equal, -1 for less than. So-called "rich comparisons" using __lt__, __gt__, etc. have been preferred since Python 2.1. The major advantage of them is that they can be used for more complicated data ty

Re: [Tutor] 2to3 conversion

2011-07-01 Thread Steven D'Aprano
Zubin Mithra wrote: Hey everyone, I was running 2to3 on a particular file and I got the following traceback( http://paste.pocoo.org/show/223468/). For short amounts of text, such as a traceback, please don't use a paste bin, just copy it into your post. Some people are reading mail at a tim

Re: [Tutor] 2to3 conversion

2011-07-01 Thread Steven D'Aprano
Steven D'Aprano wrote: Zubin Mithra wrote: Hey everyone, I was running 2to3 on a particular file and I got the following traceback( http://paste.pocoo.org/show/223468/). For short amounts of text, such as a traceback, please don't use a paste bin, just copy it into your post.

Re: [Tutor] Limit raw_input to hundredth decimal point

2011-07-01 Thread Steven D'Aprano
Ryan Kirk wrote: Is there a way to limit raw_input to the hundredth decimal point? No. raw_input is a tool that does one thing: it collects input from the user. It doesn't understand numbers, check for decimal places, check the input for spelling errors, or anything else. It's a hammer, not a

Re: [Tutor] problem reading script

2011-07-01 Thread Steven D'Aprano
Lisi wrote: I am supposed to be looking at scripts on-line, reading them and making sure that I understand them. I think taht most of teh things I can't make more than a guess at, are modules taht I don't know, and I can mostly make them out. But the unpaired double quotation mark, " , in the

Re: [Tutor] The Card Game

2011-07-01 Thread Steven D'Aprano
Christopher King wrote: Sorry, I haven't upgraded to 3 yet. No need to apologise for that! Python 2.7 will be around a long time yet. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.pytho

Re: [Tutor] problem reading script

2011-07-01 Thread Steven D'Aprano
Lisi wrote: On Friday 01 July 2011 14:26:07 Steven D'Aprano wrote: If they look the same to you, then you need to increase your font size, change to a programmers font, or possible clean your glasses :) Thanks for the reply, Steven. Suggestions for "a programmers font" grat

Re: [Tutor] Algorithm for sequence matching

2011-07-02 Thread Steven D'Aprano
ANKUR AGGARWAL wrote: Hey I am looking for an algo for the largest sequence search in the two list. Example : list a accepts some say 'm' numbers. list b accept says 'n' numbers. I want to look for the largest same sequence between the two list and then display it. I tried out but failed to do s

Re: [Tutor] problem with reading dns query

2011-07-02 Thread Steven D'Aprano
preetam shivaram wrote: I have got a very simple idea in mind that i want to try out. Say i have a browser, chrome for instance, and i want to search for the ip of the domain name, say `www.google.com`. I use windows 7 and i have set the dns lookup properties to manual and have given the address

Re: [Tutor] Using a dict value in the same dict

2011-07-05 Thread Steven D'Aprano
Válas Péter wrote: So the trick is to define the dictionary in separate sessions, not at once. No. value = 42 my_dict = {'a': value, 'b': value, 'c': 23, 'd': value, 'e': 97} will work fine too. -- Steven ___ Tutor maillist - Tutor@python.org

Re: [Tutor] What algorithm suits here

2011-07-13 Thread Steven D'Aprano
Amit Sethi wrote: I have a list of dictionaries in this form. { message : xyz parent : 23 id : 25 } or { message : abc parent : None id : 25 } { message : cde parent : 28 id : 32 } { message : cde parent : 23 id : 35 } I want to make seperate the lists such that messages in same thread(

Re: [Tutor] Get file last user

2011-07-13 Thread Steven D'Aprano
Susana Iraiis Delgado Rodriguez wrote: Hello list!!! I want to get the last user who accessed to a file, I already have the way to know who owns the file, but I really need to get this information. To get file user I'm using: os.environ.get("USERNAME") and to get the machine host: socket.gethost

Re: [Tutor] Descriptors and type declaration order

2011-07-14 Thread Steven D'Aprano
Knacktus wrote: Hi guys, I've got the following (not working) code: [...] The problem is that the descriptors are created when the module is evaluated. But at this time the class BaseItem is not known yet. Any ideas? Yes -- don't do that. What are you actually trying to accomplish? Embeddin

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Steven D'Aprano
Richard D. Moores wrote: But that makes me wonder if there isn't a simpler way to do it with Python -- to delete the contents of a file without deleting the file? Opening a file for writing will flush the contents. open(filename, 'w') will do it, taking advantage of Python's garbage collecto

Re: [Tutor] Filling orders FIFO

2011-07-15 Thread Steven D'Aprano
Charles John wrote: Hi I am new to python and was wondering what the best way to create an order(bid and offer) queue, then match a bid and offer so that if bid==offer, creates a filled order FIFO in python cgi using mysql? Does anybody have any ideas? It would be greatly appreciated. The simpl

Re: [Tutor] IDLE/tk in 10.6

2011-07-15 Thread Steven D'Aprano
Luke Thomas Mergner wrote: [...] I'd like to try IDLE but there appears to be a known bug with 10.6's version of ActiveTCL. I've installed a newer version 8.5 via their website, but this has not fixed the problem. The module tkinter is still unable to load. Since both python and activeTCL ar

Re: [Tutor] how to add directory to python search list

2011-07-17 Thread Steven D'Aprano
Surya P.K. Kasturi wrote: can you tell me in detail how to do this. I am new to linux. "this" being: On Sat, Jul 16, 2011 at 11:48 AM, Alan Gauld wrote: You need to add the folder to your PYTHONPATH environment variable. You usually do this your .login or .profile file. Python will add the

Re: [Tutor] Filling orders FIFO

2011-07-17 Thread Steven D'Aprano
has a good solution to the problem, by all means show us how you would use it. P.S. we prefer that you don't top-post on this mailing list. It makes it easier to understand replies if they follow what they are replying to, rather than come before. Steven. 2011/7/16 Steven D&#

Re: [Tutor] Homework problem

2011-07-20 Thread Steven D'Aprano
Ken Baclig wrote: Hi, I'm trying to make a function that receives text (a string) as an argument and returns the same text (as string), but with 1 added to each word that is a number. What counts as a number? In the string: "Hello world 1234 ham spam" which of these do you expect to get b

Re: [Tutor] questions on encoding

2011-07-20 Thread Steven D'Aprano
Albert-Jan Roskam wrote: Hi, I am looking for test data with accented and multibyte characters. I have found a good resource that I could use to cobble something together (http://www.inter-locale.com/whitepaper/learn/learn-to-test.html) but I was hoping somebody knows some ready resource. I

Re: [Tutor] little/big endian was Re: what is 'doubleword alignment'?

2011-07-21 Thread Steven D'Aprano
Dave Angel wrote: Little-endian is the method used by the Intel processor (such as the Pentium). Big-endian is the system used by most network protocols, as well as the 68000 and many other processors. There used to be mainframes with various forms of middle-endian layouts. Fortunately they

Re: [Tutor] Avoiding reauthentication to web services?

2011-07-21 Thread Steven D'Aprano
Ryan on the Beach wrote: Hello. I am trying to write a python program to control a lighting controller through it's rest interface. It requires ssl and basic authentication. I have been successful using urllib2. However, the authentication takes a very long time on the controller so multi

Re: [Tutor] Don't understand this class/constructor call syntax

2011-07-22 Thread Steven D'Aprano
dave wrote: class transmit_path(gr.top_block) [...] self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2) This calls the ieee802_15_4_mod_pkts initializer (not a constructor -- see below) with one posit

Re: [Tutor] Copying Variables

2011-07-23 Thread Steven D'Aprano
Ryan Strunk wrote: Hello everyone, How can I make two copies of a dictionary that don't point to the same location in memory? My plan is to generate d1 and make d2 a copy of d1. After the user modifies d1 I want him/her to be able to return to the initial dictionary (d2) values. I tried: d1 = {va

<    4   5   6   7   8   9   10   11   12   13   >