Re: [Tutor] writing function changeColor

2012-07-18 Thread Steven D'Aprano
Aditi Pai wrote: Emile, So far I have started with def changeColor(pict,scale,color): I was told to make different names for the float and integer (float = scale and color= integer) and then I kept everything else the same, just to test it out and see if that would work. So it looks like this

Re: [Tutor] writing function changeColor

2012-07-18 Thread Steven D'Aprano
On Wed, Jul 18, 2012 at 05:31:00PM -0400, Aditi Pai wrote: > Ramit told me not to "top post," and I looked it up and I think I am doing > that same thing again, so if I am let me know how to avoid that. This kind > of discussion board is something I haven't interacted with before. In your email pr

Re: [Tutor] string to binary and back... Python 3

2012-07-18 Thread Steven D'Aprano
On Wed, Jul 18, 2012 at 10:22:43PM +, Prasad, Ramit wrote: > I forgot to say, that once you have the integer equivalents, > you can then convert that easily to binary using bin. > I used ast.literal_eval to convert from binary string > (as returned from bin) to number, but there might be bet

Re: [Tutor] writing function changeColor

2012-07-18 Thread Steven D'Aprano
Coming back to your original question... On Wed, Jul 18, 2012 at 01:10:51PM -0400, Aditi Pai wrote: > Hello, > > I am trying to write a function changeColor for an assignment. Two things > that I am unsure about for this assignment are how to assign different > colors to integers so that, red wi

Re: [Tutor] writing function changeColor

2012-07-18 Thread Steven D'Aprano
On Wed, Jul 18, 2012 at 05:37:17PM -0400, Aditi Pai wrote: > Hey, > > Do you know how to take your post off the discussion board? Do you mean taking a previous post off the discussion list? You can't. Once a post has been made, you can't delete it. It is public knowledge, archived on a dozen d

Re: [Tutor] Problem When Iterating Over Large Test Files

2012-07-18 Thread Steven D'Aprano
On Wed, Jul 18, 2012 at 04:33:20PM -0700, Ryan Waples wrote: > I'm seeing some unexpected output when I use a script (included at > end) to iterate over large text files. I am unsure of the source of > the unexpected output and any help would be much appreciated. It may help if you can simplify y

Re: [Tutor] Problem When Iterating Over Large Test Files

2012-07-18 Thread Steven D'Aprano
On Wed, Jul 18, 2012 at 04:33:20PM -0700, Ryan Waples wrote: > I've included 20 consecutive lines of input and output. Each of these > 5 'records' should have been selected and printed to the output file. I count only 19 lines. The first group has only three lines. See below. There is a blank l

Re: [Tutor] check against multiple variables

2012-07-19 Thread Steven D'Aprano
Selby Rowley-Cannon wrote: I am using a hash table in a small randomization program. I know that some hash functions can be prone to collisions, so I need a way to detect collisions. I doubt that very much. This entire question seems like a remarkable case of premature optimization. Start wi

Re: [Tutor] suggestion for an editor

2012-07-20 Thread Steven D'Aprano
Bala subramanian wrote: Friends, At present i write programs using vi editor. I am interested to change to something else. My specific need is that i want to select a portion/small segment of my program (for eg. a nested loop) and then monitor processing time it takes for that portion while i run

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-20 Thread Steven D'Aprano
PyProg PyProg wrote: Hi all, I would get a new list as: [(0, '3eA', 'Dupont', 'Juliette', '11.0/10.0', '4.0/5.0', '17.5/30.0', '3.0/5.0', '4.5/10.0', '35.5/60.0'), (1, '3eA', 'Pop', 'Iggy', '12.0/10.0', '3.5/5.0', '11.5/30.0', '4.0/5.0', '5.5/10.0', '7.5/10.0', '40.5/60.0')] ... from this one:

Re: [Tutor] Problem When Iterating Over Large Test Files

2012-07-20 Thread Steven D'Aprano
Ryan Waples wrote: I count only 19 lines. yep, you are right. My bad, I think I missing copy/pasting line 20. The first group has only three lines. See below. Not so, the first group is actually the first four lines listed below. Lines 1-4 serve as one group. For what it is worth, line f

Re: [Tutor] Problem When Iterating Over Large Test Files

2012-07-20 Thread Steven D'Aprano
Alan Gauld wrote: On 19/07/12 07:00, Steven D'Aprano wrote: for reads, lines in four_lines( INFILE ): ID_Line_1, Seq_Line, ID_Line_2, Quality_Line = lines Shouldn't that be for reads, lines in enumerate( four_lines(INFILE) ):

Re: [Tutor] check against multiple variables

2012-07-20 Thread Steven D'Aprano
Walter Prins wrote: On 19 July 2012 23:20, Steven D'Aprano wrote: Selby Rowley-Cannon wrote: I am using a hash table in a small randomization program. I know that some hash functions can be prone to collisions, so I need a way to detect collisions. This entire question seems l

Re: [Tutor] Where to put small auxiliary function

2012-07-20 Thread Steven D'Aprano
Jose Amoreira wrote: Hi. This is a question about style. I have a class definition that calls a small auxiliary function. Because this function isn't used anywhere else, I'd like to include it inside the class definition. *shrug* Then do so. class Whatever: @staticmethod def is_odd(

Re: [Tutor] measuring the start up time of an event-driven program

2012-07-24 Thread Steven D'Aprano
On Tue, Jul 24, 2012 at 02:18:43AM -0700, Albert-Jan Roskam wrote: > Hi, > > I would like to test how long it takes for two versions of the same > program to start up and be ready to receive commands. The program is > SPSS version-very-old vs. SPSS version-latest. I don't think this is a Python

Re: [Tutor] What on earth is happening here ???

2012-07-25 Thread Steven D'Aprano
Alan Gauld wrote: def getDOMDocument(self): def getDOMDocument(self, namespaceUri=__defaultNamespaceUri): def getDOMDocument(self, namespaceUri=__defaultNamespaceUri, qualifiedName=__defaultQualifiedName): > def getDOMDocument(self, namespaceUri=_

[Tutor] Private attributes [was Re: What on earth is happening here ???]

2012-07-25 Thread Steven D'Aprano
Prasad, Ramit wrote: Trying to make things "private" is a throwback to Java. In Python the tendency is to just leave everything "public". And "private" is with one underbar/underscore. Yes, and no. It is true that Python encourages a "consenting adults" philosophy, where private attributes a

Re: [Tutor] How to use introspection to discover parameters?

2012-07-26 Thread Steven D'Aprano
David wrote: Please help me understand the following (I have python 2.6.2) ... Because I want to write nice docstrings, I read PEP257 where it says: "The one-line docstring should NOT be a "signature" reiterating the function/method parameters (which can be obtained by introspection)." As a ge

Re: [Tutor] Encoding error when reading text files in Python 3

2012-07-28 Thread Steven D'Aprano
Dat Huynh wrote: Dear all, I have written a simple application by Python to read data from text files. Current I have both Python version 2.7.2 and Python 3.2.3 on my laptop. I don't know why it does not run on Python version 3 while it runs well on Python 2. Python 2 is more forgiving of beg

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-28 Thread Steven D'Aprano
Francesco Loffredo wrote: but I must avoid reading my function again, or I'll find some more bugs! Perhaps you should run your function, and test it. Finding bugs is not the problem. Once you find them, you can fix them. It is the bugs that you don't know about that is the problem. -- Ste

Re: [Tutor] finally without try or except

2012-07-30 Thread Steven D'Aprano
Tino Dai wrote: Yes, but that would involve surrounding the entire method with a try except finally block. I was told by the Python-Guru-In Residence that shouldn't emulate Java code in Python, and that was generally bad programming practice (no flame war intended) And that is correct. It is *

Re: [Tutor] finally without try or except

2012-07-30 Thread Steven D'Aprano
Tino Dai wrote: I just remember that there was a performance hit or something for doing that. Does that sound familiar to anyone? Yes, and no. Creating a try block in Python is lightweight and fast. It is about as fast as the "pass" statement, that is, pretty damn fast and more or less faste

Re: [Tutor] int("10**6")

2012-08-01 Thread Steven D'Aprano
On Wed, Aug 01, 2012 at 01:37:00AM -0700, Albert-Jan Roskam wrote: > Hi > I want the user to be able to specify "10**6" as arguments. How can I cast > this string value (it's from sys.argv) to an int value?. > Simply doing int("10**6") won't work. The code below works, but seems overly > complic

Re: [Tutor] __new__ and __init__

2012-08-01 Thread Steven D'Aprano
On 02/08/12 00:28, rail shafigulin wrote: Hello everyone. I'm trying to understand how to use the two methods. I know that __new__ is used to create an object, while __init__ to initialize. But I'm not sure what happens when I create an object. I found the following code in the book (Python 3 O

Re: [Tutor] __new__ and __init__

2012-08-01 Thread Steven D'Aprano
On 02/08/12 01:10, Hugo Arts wrote: * small caveat: I'm entirely unsure of this, but I *think* if you create CarModel with a metaclass that overrides __call__ you can change the way __new__ and __init__ work? If anyone can confirm this, be my guest. Correct. Metaclasses can essentially change

Re: [Tutor] PYFTDI Library for FT232H

2012-08-02 Thread Steven D'Aprano
On 03/08/12 09:38, John Battle wrote: I am relatively new to Pyton and am trying to use a library called pyftdi which is used to establish communication with USB chips made by FTDI. I have been able to install the library and write a simple piece of code to discover my interfaces (I have two FT23

Re: [Tutor] adding a windows registry value

2012-08-03 Thread Steven D'Aprano
On 04/08/12 00:39, Albert-Jan Roskam wrote: Hi, I am trying to change a registry value (Windows 7, Python 2.7) but it won't work when I try to do this using Python: Define "won't work". Does it: - change the registry entry, but no effect is apparent? - raise an exception? - crash? - silently

Re: [Tutor] adding a windows registry value

2012-08-03 Thread Steven D'Aprano
On 04/08/12 06:32, Walter Prins wrote: On 3 August 2012 19:35, Alan Gauld wrote: The list doesn't care, you probably did it by hitting Reply instead of Reply All. Reply replies to the person who posted. Reply All replies to all on the list. Just like regular email. That's just how its set u

Re: [Tutor] Recursive assignment in nested lists

2012-08-04 Thread Steven D'Aprano
On 04/08/12 16:58, Alonzo Quijote wrote: Is there a way to define a function which takes a list (of lists), a position specified by a list of integers [i0,i1,...,in], and a value and returns the result of setting list[i0][i1]...[in]=value Yes it is possible, but if you need th

Re: [Tutor] How to import a few modules when I enter python?

2012-08-07 Thread Steven D'Aprano
On Tue, Aug 07, 2012 at 09:09:02AM +0530, Santosh Kumar wrote: > Hello there, > > I have a few scripts that I made to experiment with, I have to import > them everytime I enter the Python shell. The scripts are in > `/home/username/workshop/` (this directory has also some non .py > files) director

Re: [Tutor] Unzip a zipfile, then unzip the zipfiles within the original zip

2012-08-08 Thread Steven D'Aprano
On 09/08/12 01:34, Ramchandra Apte wrote: Sorry. This is my first time using a mailing list! Any idea how to send a message without replying? The same way you would send a message to anyone else without replying. In your mail program, click "New Message" or "Write Message" or whatever the co

Re: [Tutor] Confusion with Python, Bash and Command Prompt

2012-08-09 Thread Steven D'Aprano
On 10/08/12 14:01, Santosh Kumar wrote: Hello There, We all know that line starting with "#" in Python is a comment. We also know that when the first line of any file (with any extension) has "#!/usr/bin/env bash" and if you make it executable and do ./filename.ext in the terminal then it will

Re: [Tutor] Confusion with Python, Bash and Command Prompt

2012-08-10 Thread Steven D'Aprano
On 10/08/12 15:35, Modulok wrote: ... My Question: Is it true that doing that is as same as doing #!/usr/bin/env python on Unix? Because I think that the matter of shebang is limited to Bash and Windows don't have a bash, it has a Command Prompt. And I don't think such thing happens in Windows.

Re: [Tutor] Recursive optimization function, binary tree

2012-08-10 Thread Steven D'Aprano
On 10/08/12 21:44, Roman Vashkevich wrote: Alright, this may sound like a dumb stupid question. I am testing a recursive optimization function that builds a binary tree. I started a hand simulation but the amount of manual work grows exponentially with the amount of function frames. Is there a g

Re: [Tutor] Multipage Tiff to PDF

2012-08-10 Thread Steven D'Aprano
On 11/08/12 06:05, Stuart van Zee wrote: I need to write a simple app that will convert a folder of multi-page tiff files to PDFs. I was hoping to be able to write a simple, one button Tkinter app to do this because the people who need to run this job a few times a day are basically unskilled. M

Re: [Tutor] output not in ANSI

2012-08-13 Thread Steven D'Aprano
On 14/08/12 04:04, Joel Goldstick wrote: On Mon, Aug 13, 2012 at 1:58 PM, Alan Gauld wrote: On 13/08/12 16:01, leon zaat wrote: I wrote a program for creating a csv file. I am using pyton on windows. The output i get is not in ANSI. Can you clarify what you mean by ANSI? According to Wikip

Re: [Tutor] overriding instance attributes with keywords

2012-08-13 Thread Steven D'Aprano
On 14/08/12 07:16, eryksun wrote: On Mon, Aug 13, 2012 at 3:13 PM, Gregory, Matthew wrote: I'm trying to create a new instance from an existing instance def new_with_overrides(s1, **kwargs): new_params = {'a': s1.a, 'b': s1.b} for (k, v) in kwargs.iteritems(): if k in ne

Re: [Tutor] Matching 3 tables with almost identical columns

2012-08-14 Thread Steven D'Aprano
Hi Elaina, My comments interleaved with yours. If you read nothing else, scroll down and read my last paragraph. Good luck! On 13/08/12 17:24, Elaina Ann Hyde wrote: Greetings, I have a rather monolithic database I am re-building at the moment, and I want to join 3 tables with semi-matc

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread Steven D'Aprano
On 15/08/12 04:25, Matt Gregory wrote: Thanks to you both for really helpful advice. A quick follow-up question - would you want to create a deepcopy of obj1 in the above example if your obj1 contained other objects? Only the person making the copy can answer that question, but in general,

Re: [Tutor] Python cms

2012-08-19 Thread Steven D'Aprano
On 19/08/12 15:05, Douglas Kuo wrote: Hi all, I am mainly a php/drupal developer totally new to python.. Any experienced python especially in term of cms developers out there can tell me what are the benefits of python cms over php cms? This might upset you, but the biggest advantage is that t

Re: [Tutor] (no subject)

2012-08-19 Thread Steven D'Aprano
On Sun, Aug 19, 2012 at 08:29:22PM +0100, Selby Rowley Cannon wrote: > OK, I have some code, and it uses glob.glob('*.py') to find all the > python files in the current directory. That works because if you don't specify an absolute directory, the current directory is used. It does not look insid

Re: [Tutor] Error in apparently correct code

2012-08-20 Thread Steven D'Aprano
On 21/08/12 06:24, Osemeka Osuagwu wrote: [...] p.s I apologise for the lack of comments Don't apologise for lack of comments, apologise for posting in HTML which causes your code to be mangled, leading indentation stripped, and generally turned into an unreadable mess. Indentation has mean

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Steven D'Aprano
Hello Cecilia, My replies are below, interleaved with your comments, which are prefixed with > marks. On 22/08/12 20:10, Cecilia Chavana-Bryant wrote: By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Steven D'Aprano
On 22/08/12 20:28, Pete O'Connell wrote: Hi. The next step for me to parse the file as I want to is to change lines that look like this: f 21/21/21 22/22/22 24/24/23 23/23/24 into lines that look like this: f 21 22 23 24 In English, what is the rule you are applying here? My guess is: "Given t

Re: [Tutor] pickle problems

2012-08-22 Thread Steven D'Aprano
On 23/08/12 02:17, Richard D. Moores wrote: I've incorporated many of the suggestions I've received here. Here's a function, factor_integer(), for quickly factoring any integer up to 1e17:. That relies on a pre-existing cache of prime numbers. If you don't use tho

Re: [Tutor] pickle problems

2012-08-23 Thread Steven D'Aprano
On Wed, Aug 22, 2012 at 11:39:46PM -0400, Dave Angel wrote: > On 08/22/2012 07:32 PM, Richard D. Moores wrote: > > > > > > My code uses gmpy2.is_prime() (lines 79 and 89). is_prime() is VERY fast. > > You do know that this gmpy2 function is only statistically correct ? it > can false positive.

Re: [Tutor] NTLM authentication, python 2.6 and windows

2012-08-23 Thread Steven D'Aprano
On 24/08/12 01:42, Marco Mistroni wrote: Hi all i was wondering if anyone coud provide examples on how to open an URL that requires NTLM authentication i have tried to use python-ntml but it does not seems to work as i keep on getting this errorlib\python2.6\ntlm\ntlm.py", line 219, in parse

Re: [Tutor] Error message...

2012-08-23 Thread Steven D'Aprano
On 24/08/12 01:33, Victoria Homsy wrote: Dear All - sorry to bother you. I just tried to run this program: def isPalindrome(s): if len(s)<= 1: return True else: return s[0] == s[-1] and isPalindrome (s[1:-1]) isPalindrome('aba') However when I run it in terminal it doesn't give me any answer

Re: [Tutor] Python 3.2: processing text files in binary mode, because I want to remove carriage returns and line feeds...

2012-08-23 Thread Steven D'Aprano
On 24/08/12 00:42, Flynn, Stephen (L & P - IT) wrote: Python 3.2, as in the subject, although I also have 2.7 on this machine too. I have some data which contains text separated with field delimiters (|~) and a record terminator (||) [trim well over 50 lines of explanation] Is there a meth

Re: [Tutor] What are all those letters after terminal commands?

2012-08-23 Thread Steven D'Aprano
On 23/08/12 23:18, Cecilia Chavana-Bryant wrote: [...] I found this command: mkdir -p i/like/icecream. I am guessing that the -p stands for directory path? Ha, that's the trouble with command line interfaces -- they tend to end up being cryptic and painfully terse. In this case, -p actually sta

Re: [Tutor] Python working with Bash....arrrggggh!

2012-08-24 Thread Steven D'Aprano
On 24/08/12 16:27, Ray Jones wrote: I am forever confused, however, on which methods can be found where. I just spent quarter of an hour searching in sys,* os.*, and shutil.*. for a 'kill' command that I knew I'd seen beforeI found it hidden in subprocess.Popen. Arrrgggh. These various impor

Re: [Tutor] Python working with Bash....arrrggggh!

2012-08-24 Thread Steven D'Aprano
On 24/08/12 17:05, Ray Jones wrote: On 08/24/2012 12:02 AM, Steven D'Aprano wrote: On 24/08/12 16:27, Ray Jones wrote: I am forever confused, however, on which methods can be found where. I just spent quarter of an hour searching in sys,* os.*, and shutil.*. for a 'kill' comm

Re: [Tutor] creating a subclass from superclass without __init__

2012-08-24 Thread Steven D'Aprano
On 25/08/12 04:22, Matt Gregory wrote: Is it possible to create a subclass of a superclass that doesn't have an __init__ and is only created through another class. Here is an example of what isn't working: class Spam(object): def __new__(cls, *args): return super(Spam, cls).__new__(c

Re: [Tutor] creating a subclass from superclass without __init__

2012-08-24 Thread Steven D'Aprano
On 25/08/12 06:03, Matt Gregory wrote: There are two classes of interest in GDAL - a Dataset which typically describes a geospatial raster file and Band which described a single band from the Dataset. gdal.Band just raises an AttributeError within __init__, but a gdal.Band instance can be creat

Re: [Tutor] askopenfilename - columns missing in navigationwindow

2012-08-26 Thread Steven D'Aprano
On 26/08/12 11:56, Joel Levine wrote: Mystery of the day: I'm using Python 2.6. My program uses from tkFileDialog import askopenfilename and fn=askopenfilename() I use this program repeatedly. Up to a few hours ago, the navigation window opened with a full array of columns, including name

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Steven D'Aprano
On 29/08/12 03:41, Ray Jones wrote: I'm working on another Python replacement for a Bash script, and I ran into a need for enhanced time zone functions. Following directions I found on a web site, I did the following: # easy_install --upgrade pytz [...] Everything I'm reading suggests that now

Re: [Tutor] running more than one python program at the same time

2012-08-28 Thread Steven D'Aprano
On 29/08/12 08:30, Benjamin Fishbein wrote: Hello, I wrote a program that I want to have running 24/7. But the problem is that I also want to write and run other programs. I'm using Idle and it won't let me run more than one script at a time. Then don't use IDLE. IDLE is for running code intera

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 28/08/12 10:26, Richard D. Moores wrote: I've been going through Steven D'Aprano's pyprimes () and have many questions. One is why begin a function name with an underscore. He has several functions that do this. Two are: [...] I'm stealing these f

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On Mon, Aug 27, 2012 at 6:33 PM, Japhy Bartlett wrote: something like: def _validate_int(obj): """Raise an exception if obj is not an integer.""" m = int(obj + 0) # May raise TypeError. if obj != m: raise ValueError('expected an integer but got %r' % obj) is a really

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 28/08/12 19:02, Peter Otten wrote: Personally, I'm a big fan of ducktyping, so I would probably remove the check completely and live with the consequences: >>> pyprimes._validate_int = lambda x: None >>> pyprimes.isprime_naive(8.5) True garbage-in, garbage-out -- so what. Duck-typing

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 28/08/12 20:00, Peter Otten wrote: [...] The differences to _validate_int() are subtle: class S(str): ... def __eq__(self, other): return True ... def __ne__(self, other): return False ... def __add__(self, other): return self ... vi(S("42")) Traceback (most recent call last):

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 28/08/12 21:24, Wayne Werner wrote: On Mon, 27 Aug 2012, Richard D. Moores wrote: What the best way to test if something's an integer? try: whatever_you_want(supposed_integer) except ValueError: print("Oops, that wasn't an integer! Please try again") That's usually the best way..

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 30/08/12 05:39, Japhy Bartlett wrote: If you tried to check in code like this: def _validate_int(obj): """Raise an exception if obj is not an integer.""" m = int(obj + 0) # May raise TypeError. if obj != m: raise ValueError('expected an integer but got %r' % obj

Re: [Tutor] understanding pydoc try

2012-08-30 Thread Steven D'Aprano
On 30/08/12 23:30, John Maclean wrote: What does the first line from `pydoc try` actually mean? This does not look like the syntax that one is supposed to use. try_stmt ::= try1_stmt | try2_stmt That's a description of the Python grammar in some variation of Backus-Naur Form. In English, it

Re: [Tutor] Why begin a function name with an underscore

2012-08-30 Thread Steven D'Aprano
On 31/08/12 04:07, Peter Otten wrote: Allowing floats for a primality test is a can of worms anyway. You will inevitably run out of significant digits: [snip] Yes, I had more or less come to the same conclusion earlier. The problem is that although sufficiently large floats are all integer-va

Re: [Tutor] Scheme

2012-08-30 Thread Steven D'Aprano
On 31/08/12 09:32, Ashley Fowler wrote: This is a problem using the Scheme programming...Can anybody help me with this problem? Probably, but not likely to be anyone here. Have you considered asking on a Lisp or Scheme mailing list or discussion forum? -- Steven

Re: [Tutor] Why begin a function name with an underscore

2012-08-30 Thread Steven D'Aprano
On 31/08/12 06:57, eryksun wrote: On Thu, Aug 30, 2012 at 2:07 PM, Peter Otten<__pete...@web.de> wrote: Allowing floats for a primality test is a can of worms anyway. You will inevitably run out of significant digits: Allowing floats can also lead to type errors for operations that require a

Re: [Tutor] Lambda?? Whaaaaat?

2012-08-30 Thread Steven D'Aprano
On 31/08/12 13:39, Scurvy Scott wrote: I'm fairly new to python having recently completed LPTHW. While randomly reading stack overflow I've run into "lambda" but haven't seen an explanation of what that is, how it works, etc. Would anyone care to point me in the right direction? Lambda is just

Re: [Tutor] Scheme

2012-08-31 Thread Steven D'Aprano
On 31/08/12 19:13, Mark Lawrence wrote: [...] Please don't top post. And Mark, please trim your replies. Bottom posting without trimming is just as annoying as top posting without trimming. (Among other things, your post ended up containing THREE copies of the mailing list footer.) -- Steve

Re: [Tutor] Tutor Digest, Vol 102, Issue 98

2012-08-31 Thread Steven D'Aprano
On 31/08/12 18:31, Mark Lawrence wrote: On 31/08/2012 04:27, William R. Wing (Bill Wing) wrote: How about - for item in iter(list): ….print item Overengineering? :) A list is an iterator. Technically, no it isn't, it is an "iterable" or a "sequence" but not an iterator. py> mylist = [1,

Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread Steven D'Aprano
On 02/09/12 17:09, Ray Jones wrote: But didn't I read somewhere that you can reset an iterator to go through the whole process again? In general, no. The usual way to "reset" an iterator is to re-create it. walker = os.walk("/home/steve/start") # ... process files in walker walker = os.walk

Re: [Tutor] Running a script in the background

2012-09-02 Thread Steven D'Aprano
On Sun, Sep 02, 2012 at 03:14:53PM -0700, Ray Jones wrote: > This is only tangentially related to the thread. Someone mentioned that > so long as a script didn't require user input or output to the user, it > could run silently in the background. But is there a way for a Python > (2.7.3) script to

Re: [Tutor] running more than one python program at the same time

2012-09-03 Thread Steven D'Aprano
On 04/09/12 01:01, Benjamin Fishbein wrote: Hi. I started running the program in the terminal rather than IDLE. It works, and I can run several programs at the same time. The problem is that when the program is finished running, it prints: exit status: 0 logout [Process completed] Which termi

Re: [Tutor] Running a script in the background

2012-09-03 Thread Steven D'Aprano
On 04/09/12 10:26, Dwight Hutto wrote: On *nix there is a cron daemon that runs in the background. but one job running in the background controlling dozens(?) of others is way more efficient than dozens of programs all running idle in the background and periodically springing into action. But

Re: [Tutor] making a shortcut in windows

2012-09-03 Thread Steven D'Aprano
On Tue, Sep 04, 2012 at 11:57:48AM +1000, Garry Willgoose wrote: > I want to put a shortcut onto the desktop in windows (XP and later) in > Python 2.6 or later. In Unix its easy using os.symlink but I can't > find anything equivalent for windows. My searches on the web led me to > the code belo

Re: [Tutor] Unicode? UTF-8? UTF-16? WTF-8? ;)

2012-09-05 Thread Steven D'Aprano
On 06/09/12 00:04, Ray Jones wrote: On 09/05/2012 04:52 AM, Peter Otten wrote: Ray Jones wrote: But doesn't that entail knowing in advance which encoding you will be working with? How would you automate the process while reading existing files? If you don't *know* the encoding you *have* to

Re: [Tutor] Unicode? UTF-8? UTF-16? WTF-8? ;)

2012-09-05 Thread Steven D'Aprano
On 06/09/12 00:51, Ray Jones wrote: subprocess.call(['dolphin', '/my_home/testdir/\u044c\u043e\u0432']) Dolphin's error message: 'The file or folder /my_home/testdir/\u044c\u043e\u0432 does not exist' That's because you're telling Dolphin to look for a file literally called: BACKSLASH u ZERO

Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Steven D'Aprano
On 06/09/12 23:56, Ray Jones wrote: I have a multiple 'if' expression that I need to drastically reduce in size, both for readability and to keep errors from creeping in. For example, I would like to have the variable 'test' point to the a location 'grid[rcount-1][ccount-1]' so that everywhere I

Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Steven D'Aprano
On 07/09/12 01:33, Ray Jones wrote: Our homework "monitor" complains if we use code that hasn't been discussed in session yet. The good old "teaching by enforced ignorance" method. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe o

Re: [Tutor] How to get MAC address using Python at windows 7

2012-09-06 Thread Steven D'Aprano
On 06/09/12 23:44, bob gailer wrote: On 8/18/2012 10:12 AM, šãñ wrote: I need to find some way how i can get mac address of windows 7 in python. Windows 7 does not have a MAC address. It is an operating system. Ethernet adapters have MAC addresses. Your computer will have one or more Ethernet

Re: [Tutor] urllib2.urlopen(....., timeout=)

2012-09-07 Thread Steven D'Aprano
On 08/09/12 01:16, Ray Jones wrote: 2.7.3 According to the docs, urlopen has a timeout capability. But it says that the timeout = '' Which docs are those? According to these docs: http://docs.python.org/library/urllib2.html "The optional timeout parameter specifies a timeout in seconds for bl

Re: [Tutor] I need Help

2012-09-08 Thread Steven D'Aprano
Hi Tavo, My responses are interleaved between your comments, shown with > markers. On 09/09/12 02:24, tayo rotimi wrote: Hi, I am a new beginner/learner of Python. Welcome and good luck! My first challenge is that I am unable to install the Python IDLE after downloading it from Python we

Re: [Tutor] web frameworks

2012-09-09 Thread Steven D'Aprano
On 10/09/12 05:41, Matthew Ngaha wrote: [...] i thought cherrypy, but was told it's not nearly as simple as Flask, and since my main focus is learning GUIs, a simple web framework will be ideal only to understand how they work. Understanding *how they work* is not going to be simple. Web frame

Re: [Tutor] web frameworks

2012-09-09 Thread Steven D'Aprano
On Sun, Sep 09, 2012 at 10:07:30PM +0100, Matthew Ngaha wrote: > sorry steven i keep replying to sender and not tutor:( That's fine, but there's no point apologising publically if you don't resend your question to the tutor list. You asked: [quote] oh? is cherrypy compaitable with Python 3? >

Re: [Tutor] I Need Help - further details now provided.

2012-09-09 Thread Steven D'Aprano
On Sun, Sep 09, 2012 at 08:20:19PM +0100, Matthew Ngaha wrote: > SORRY i wrote to you not the mailing list:( > > im a beginner myself, and those instructions seem very complicated for > me. What instructions are you talking about? I'm sure that was very clear in your head when you wrote that, b

Re: [Tutor] Help - My First Program Fails

2012-09-09 Thread Steven D'Aprano
Please, please, PLEASE do not reply to a digest without deleting the irrelevant text from your email! We don't need to read HUNDREDS of lines of text we've already seen before. When you want to start a *new* question, ALWAYS start a fresh, blank email, set the "To" address to tutor@python.org,

Re: [Tutor] Help - My First Program Fails

2012-09-10 Thread Steven D'Aprano
On 10/09/12 19:40, tayo rotimi wrote: Hi Steven. Thank you for your answer below. The program now runs, using print("Game Over"). I use Python 3..; but the book - python for absolute beginner - that I have is an old (2003) edition. I don't know how this combination may affect my learning, goin

Re: [Tutor] convert ascii to binary

2012-09-12 Thread Steven D'Aprano
On 12/09/12 21:20, Aaron Pilgrim wrote: Hello, I am trying to write a small program that converts ascii to binary. Can you explain what you mean by "ascii to binary"? Any of these could be described that way: 'hello world' => '68656c6c6f20776f726c64' => 'begin 666 \n+:&5L;&\\@=V]R;&0 \n \nen

Re: [Tutor] setting a timer

2012-09-12 Thread Steven D'Aprano
On 13/09/12 03:56, Matthew Ngaha wrote: class Game(object): interval = 0 def play(self): Game.interval = 40 while Game.interval> 0: self.count_down() def count_down(self): Game.interval -= 1 so the play() method gives interval a

Re: [Tutor] Print List

2012-09-12 Thread Steven D'Aprano
On 13/09/12 10:57, bob gailer wrote: On 9/12/2012 11:36 AM, Ashley Fowler wrote: I am trying to complete the following below: You also need to write a function "printList" of one parameter that takes a list as its input and neatly prints the entire contents of the list in a column. Any Suggestio

Re: [Tutor] Sigh first real python task

2012-09-12 Thread Steven D'Aprano
On 13/09/12 13:06, Mike S wrote: Now, I'm having to change the remote host and pass both the username and pass but cannot get it to work. Since we don't have access to your machine to try it, would you care to tell us what happens when you try, or shall we just guess? -- Steven _

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread Steven D'Aprano
On 14/09/12 18:43, Ray Jones wrote: Between the two arrows, 'source' inexplicably switches from to. Why? source.remove('') does not do what you think it does. Checking the Fine Manual is always a good idea, or experimentation at the interactive interpreter: py> source = list('abcd') py> resu

Re: [Tutor] 2.7.3 documentation gripe (feel free to ignore)

2012-09-14 Thread Steven D'Aprano
On 14/09/12 17:29, Ray Jones wrote: 6.5. The del statement [...] They call this DOCUMENTATION??? "it's similar to such and such - you figure it outhere are the hints"! Bah! I hope their code is better than the documentati

Re: [Tutor] is this use or abuse of __getitem__ ?

2012-09-14 Thread Steven D'Aprano
On 14/09/12 22:16, Albert-Jan Roskam wrote: Hi, I defined a __getitem__ special method in a class that reads a binary data file using a C library. The docstring should clarify the purpose of the method. This works exactly as I intended it, however, the "key" argument is actually used as an index

Re: [Tutor] (no subject)

2012-09-15 Thread Steven D'Aprano
On 15/09/12 15:09, Johny Rei wrote: hi to all readers, i 'm a newbie and i'm interested to learn python programming, can anybody please guide me out to learn basic to advance python programming, be actually can anyone out there should suggest a free book that i can read it on just to learn from

Re: [Tutor] Cube root

2012-09-15 Thread Steven D'Aprano
On 16/09/12 07:28, Amanda Colley wrote: Ok, I have to get input from a user ('enter a number') and then get the cube root of that number. I am having trouble with the code to get the cube root. If anyone can help me solve this I would greatly appreciate it. ('enter a number') n=number ??? cube

Re: [Tutor] [Semi-OT] Yes or no on using a Graphical IDE?

2012-09-15 Thread Steven D'Aprano
On 15/09/12 22:51, leam hall wrote: Hey all, not trying to contribute to the flames of one graphical IDE over another. I'm just trying to figure out if they are worth the learning curve? I have been doing most of my work in vi and the graphical IDE I'm supposed to use for a class keeps adding cra

Re: [Tutor] All possible 16 character alphanumeric strings?

2012-09-15 Thread Steven D'Aprano
On 16/09/12 13:06, aklei...@sonic.net wrote: #!/usr/bin/env python # file : every.py print 'Running "every.py"' possible = "234567abcdefghijklmnopqrstuvwxyz" word_length = 16 word_list = [] def add_word(word): if len(word)==word_length: word_list.append(word) print wor

Re: [Tutor] All possible 16 character alphanumeric strings?

2012-09-15 Thread Steven D'Aprano
On 16/09/12 08:50, Scurvy Scott wrote: Hello again python tutor list. I have what I see as a somewhat complicated problem which I have no idea where to begin. I'm hoping you fine folks can help me. I'm trying to generate a list of every possible 16 character string containing only 2-7 and a-z lo

Re: [Tutor] All possible 16 character alphanumeric strings?

2012-09-15 Thread Steven D'Aprano
Akleider, you didn't include attribution for the person you are quoting, which is a bit rude and also means I can't be sure who it was. From context, I *think* it is the original poster Scott: On 16/09/12 13:06, aklei...@sonic.net wrote: I'm using this to write a program I'm calling TORdialer wi

<    10   11   12   13   14   15   16   17   18   19   >