Re: [Tutor] string codes

2013-11-28 Thread spir
On 11/28/2013 02:34 AM, Alan Gauld wrote: Not so. If you are looking for a string and know the string ends with that string you want the end point to exclude the known result at the end. And it is a startswith because you are checking from the start of the substring. Ah, thank you, Alan! Denis

Re: [Tutor] Python scope and variable binding

2013-11-29 Thread spir
On 11/29/2013 06:20 AM, eryksun wrote: On Wed, Nov 27, 2013 at 10:04 AM, Arnaud Legout wrote: [...] For what it's worth, a personal point of view on Python class defs. I ended up undertanding class definitions as code blocks the following way: Imagine Python has kinds of free sections of co

Re: [Tutor] empty delimiters, and None

2013-11-30 Thread spir
On 11/29/2013 02:19 PM, uga...@talktalk.net wrote: I have also looked at locale.py Line 494 of which is the last line of a def (def function?) I include this below, hopefully this may save you searching for locale.py (Pyhon 2.6) should you need it and wish to answer the above questions, it may

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread spir
On 12/01/2013 06:50 AM, Reuben wrote: Hi, How can we write a logic for detecting the number 2 in range from 1 to 100 Do you mean: if 2 in numbers: ? Also for a more general solution, think at the very nice function any(bools), in combination with a generator comprehension:

Re: [Tutor] Alternatives to append() for "growing" a list

2013-12-01 Thread spir
On 12/01/2013 05:32 AM, Amit Saha wrote: Hello, I was told by someone (as a comment) that a code snippet such as this "would make Pythonistas talk my ear off about how evil the append()" function is: mylist = [] mylist.append(1) # a number of times over I have some ideas that on an append()

Re: [Tutor] Loop over floating point values

2013-12-01 Thread spir
On 12/01/2013 10:03 AM, Amit Saha wrote: Hello, Much to my disbelief, I realized I hadn't written a program in Python as far as I can recall which required me to do something like this, in psuedocode: x = 0.1 for i = 0 to x step 0.01 # do something with i end i Simply stated, I want to start

Re: [Tutor] truncated dictionary return

2013-12-01 Thread spir
On 12/01/2013 08:28 PM, richard kappler wrote: I have a script that reads sensor values gathered by an Arduino board from serial as a dictionary, said values to later be used in the AI for Nav & Control. Here's the script: #!/usr/bin/python def sensorRead(): import serial from time im

Re: [Tutor] need a hint

2013-12-02 Thread spir
On 12/02/2013 03:25 AM, Byron Ruffin wrote: The following program works and does what I want except for one last problem I need to handle. The program reads a txt file of senators and their associated states and when I input the last name it gives me their state. The problem is "Udall". There

Re: [Tutor] ignoring diacritical signs

2013-12-02 Thread spir
On 12/02/2013 04:53 PM, Steven D'Aprano wrote: Also, the above function leaves LATIN CAPITAL LETTER O WITH STROKE as Ø instead of stripping the stroke. I'm not sure whether that is an oversight or by design. Likewise for the lowercase version. You might want to do some post-processing: There's

Re: [Tutor] Fwd: question about lists

2013-12-04 Thread spir
On 12/04/2013 10:35 AM, Ismar Sehic wrote: [...] Your presentation is a bit abscure (to me, at least): it is hard to help you. Maybe you could explain better, and progressively: * what is the purpose of your software, and its context * what are your input data and what they mean, and whether

Re: [Tutor] Generate list-of-transforms

2013-12-05 Thread spir
On 12/05/2013 11:52 AM, Steven D'Aprano wrote: There is a name for this: it is called a RANK TABLE. In the example given: values = [3, 1, 2, 5, 4] the rank table gives the rank of each element, that is, the position they would get after sorting. In this case, the rank table is not terribly exci

Re: [Tutor] Generate list-of-transforms

2013-12-05 Thread spir
On 12/05/2013 12:02 PM, Alan Gauld wrote: But the OP didn't ask for the final transform he asked for the list of transforms that got from A to B. That means all of the intermediate steps. At least that's how I read his statement "list-of-transforms that got me from before to after" I did not re

[Tutor] 'slice', etc

2013-12-06 Thread spir
Hello, How does slicing in Python really work? Apparently, there are slice objects (start, past-end, step), generated using either the 'slice' builtin func or the extended slicing syntax [i:k:s]. Is this correct? [1] Does (only) the extended syntax (always) trigger slicing instead of contruct

Re: [Tutor] 'slice', etc

2013-12-06 Thread spir
On 12/07/2013 02:07 AM, Alan Gauld wrote: On 06/12/13 15:39, spir wrote: How does slicing in Python really work? Apparently, there are slice objects (start, past-end, step), generated using either the 'slice' builtin func or the extended slicing syntax [i:k:s]. Is this correct? [1]

Re: [Tutor] 'slice', etc

2013-12-07 Thread spir
On 12/07/2013 02:45 AM, Mark Lawrence wrote: The good news is there is a memoryview in Python, see http://docs.python.org/3/library/functions.html#func-memoryview. The bad news is it doesn't work on strings. See here for the slice object http://docs.python.org/3/library/functions.html#slice. T

Re: [Tutor] 'slice', etc

2013-12-07 Thread spir
On 12/07/2013 02:49 AM, Joel Goldstick wrote: >>Hum, we are not talking of the same topic, apparently. I mean this, from >>the library ref, builtin funcs: >>http://docs.python.org/3.3/library/functions.html#slice: >> >> slice(start, stop[, step]) >> > I'm totally confused by this. What is th

Re: [Tutor] 'slice', etc

2013-12-07 Thread spir
On 12/07/2013 11:42 AM, Steven D'Aprano wrote: >Are slices and subsequences transparently usable one for the other? Of course not. They are completely different things. A slice has to be applied to a sequence before you get a subsequence: Right, thank you, Staven, that's the bit I missed. [I k

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-08 Thread spir
On 12/08/2013 11:22 AM, Rafael Knuth wrote: Hey there, I struggle to understand what unit testing specifically means in practice and how to actually write unit tests for my code (my gut is telling me that it's a fairly important concept to understand). [...] Hello Rafael, This post is quite l

Re: [Tutor] Suggestion required on python as scripting language

2013-12-08 Thread spir
On 12/08/2013 07:59 AM, Shankar Donepudi wrote: Hi All, I am working as test engineer in Networking in storage domain. We have decided to automate our testing and have chosen python for the same. We have basic knowledge on python so can anyone suggest good tutorials for writing automation script

Re: [Tutor] Alternatives to append() for "growing" a list

2013-12-08 Thread spir
On 12/08/2013 07:14 AM, Amit Saha wrote: >If all of the bitN are strings: > bit1 + bit2 + bit3 + bit4 + bit5 >actually constructs: > bit1+bit2 > bit1+bit2+bit3 > bit1+bit2+bit3+bit4 > bit1+bit2+bit3+bit4+bit5 >A number of unneeded string object, and a very

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 09:08 AM, Rafael Knuth wrote: Hej there, I wrote a program that converts an integer into a digit sum: def DigitSum(YourNumber): DigitList = [] YourNumber = str(YourNumber) for i in YourNumber: DigitList.append(int(i)) print(sum(DigitList)) DigitSum(55

Re: [Tutor] What is a namespace? What is meant by "A namespace is a mapping from names to objects"

2013-12-09 Thread spir
On 12/09/2013 05:46 AM, Varuna Seneviratna wrote: Let’s begin with some definitions. A *namespace* is a mapping from names to objects. Most namespaces are currently implemented as Python dictionaries, but that’s normally not noticeable in any way (except for performance), and it may change in t

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 02:42 PM, Rafael Knuth wrote: Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. It's certainly the most obvious one, but there is also the pure numbers approach pointed out by me and Alan. So far I received 7 different alternative suggestion

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 02:29 PM, Wolfgang Maier wrote: spir gmail.com> writes: Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. It's certainly the most obvious one, but there is also the pure numbers approach pointed out by me and Alan. You a

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 03:49 PM, Alan Gauld wrote: On 09/12/13 13:48, spir wrote: On 12/09/2013 02:29 PM, Wolfgang Maier wrote: spir gmail.com> writes: Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. ... also the pure numbers approach pointed out b

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 09:27 PM, Alan Gauld wrote: On 09/12/13 17:57, Roel Schroeven wrote: You are right in a sense, but this is what int() does, isn't it? No. int() can be done in several ways... spir should have said "..., but this is what str() does, ..." I think. Doh! Yes, tha

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread spir
On 12/10/2013 11:56 AM, Steven D'Aprano wrote: This is because the function does *two things*, when it should do one. First it calculates the digit sum, and then it prints it. print's inside functions are a sign of debug not completely cleaned ;-) (and also a sign that test funcs do not provid

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-10 Thread spir
On 12/10/2013 12:46 AM, Steven D'Aprano wrote: In Python 2.7, you can abbreviate that last one slightly: '{} "{}"'.format(number, word) Why 2.7? By me also works with 3.3. Either should be preferred to building the string by hand with + signs. The rule of thumb I use is to say that adding tw

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread spir
[off-topic] On 12/10/2013 01:39 PM, Wolfgang Maier wrote: def digits(n): """Generator that breaks down an integer into digits from right to left.""" while n>0: yield n % 10 n //= 10 Aha! one more sign that we write numbers backwards! Denis _

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread spir
On 12/10/2013 02:31 PM, Rafael Knuth wrote: Hej Steven, thanks for the clarification. I have two questions - one about map function and the other about return. So, in mathematics we might have a mapping between (let's say) counting numbers 1, 2, 3, 4, ... and the even numbers larger than fifty

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread spir
On 12/10/2013 02:31 PM, Rafael Knuth wrote: Hej Steven, thanks for the clarification. I have two questions - one about map function and the other about return. So, in mathematics we might have a mapping between (let's say) counting numbers 1, 2, 3, 4, ... and the even numbers larger than fifty

Re: [Tutor] recursive function example

2013-12-11 Thread spir
On 12/10/2013 03:48 PM, uga...@talktalk.net wrote: [...] Recursivity is hard to get really, meaning intuitively with your guts so-to-say. Maybe using another example may help. Lets us say you want a function that sums numbers from 1 up to n, the only input variable. (The result should thus be

Re: [Tutor] recursive function example

2013-12-11 Thread spir
On 12/11/2013 09:50 AM, Alan Gauld wrote: Remember that each time mult() is called it creates its own mini-world of variables independent of the previous calls. That, is a key point. Denis ___ Tutor maillist - Tutor@python.org To unsubscribe or cha

Re: [Tutor] recursive function example

2013-12-11 Thread spir
On 12/11/2013 03:56 PM, uga...@talktalk.net wrote: Self-similar (fractal) recursion, sounds complex, I am guessing this is like linear recursion but simultaneously in more than one dimension? Curious business really. Wonders, if I may be a closet programmer, or something, It is not complex,

Re: [Tutor] recursive function example

2013-12-11 Thread spir
On 12/11/2013 07:15 PM, Alan Gauld wrote: Remember we are calling mul() several times, each with a new set of values. So mul(3,2) calls mul(3,1) and mul(3,1) calls mul(3,0) mul(3.0) returns 0 to mul(3,1) mul(3,1) then returns 3+0 => 3 to mul(3,2) mul(3,2) returns 3+3 => 6. This is a very cle

Re: [Tutor] recursive function example

2013-12-11 Thread spir
This is a pretty good clarification! (debug prints well designed and well placed) Congrats, Mark! denis On 12/11/2013 06:37 PM, Mark Lawrence wrote: On 10/12/2013 14:48, uga...@talktalk.net wrote: [snipped] As you're clearly struggling here's my attempt at showing you what is happening. c:

Re: [Tutor] formatting datetime.timedelta to "HH:MM:SS"

2013-12-11 Thread spir
On 12/11/2013 02:55 PM, Jignesh Sutar wrote: Thanks Mark, print('%02d:%02d:%04d' % (now.hour, now.minute, now.year)) That works for; now = datetime.now() but not for; exe_time = endTime-startTime Yes, because exe-time is not a ate, a point in time, but a time delta (a difference), thus doe

Re: [Tutor] formatting datetime.timedelta to "HH:MM:SS"

2013-12-11 Thread spir
On 12/11/2013 06:40 PM, Jignesh Sutar wrote: c = b-a print "%s days, %.2dh: %.2dm: %.2ds" % (c.days,c.seconds//3600,(c.seconds//60)%60, c.seconds%60) This is a correct and general solution. Maybe worth being built-in, in fact, in my view. Denis __

[Tutor] flush of output

2013-12-12 Thread spir
Hello, I need to write out, both to stdout and stderr channels, which indeed in general are the same one, and things written to be in order (lol!). For now, I flush on stderr, and apparently there is no issue on stdout. Does someone know more about that? I seem to remember stdout is flushed on

Re: [Tutor] Coding for a Secret Message in a Game

2013-12-13 Thread spir
On 12/13/2013 05:10 AM, Sky blaze wrote: Hi, I'm a newbie Python programmer. I was introduced to Python via the Hour of Code, and after completing all three of Grok Learning's tutorials, I was inspired to create a text-based RPG adventure. I composed this e-mail after searching for a forum for Py

Re: [Tutor] 'slice', etc

2013-12-14 Thread spir
On 12/14/2013 12:24 AM, Mark Lawrence wrote: I've just remembered that one distinct disadvantage of memoryviews is that you can't use them anywhere if you want to do any sorting, as you can't compare them :( Not a blocker in my case (matching/parsing), thankfully. Denis __

Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)

2013-12-14 Thread spir
On 12/14/2013 04:31 AM, Steven D'Aprano wrote: To err is human, to forgive is humane. Nicely said. To the Original Poster, whoever you are... I hope you'll hang around here and [...] If it were me, he would probably not; too bad. Denis ___ Tutor

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread spir
On 12/14/2013 10:12 AM, Bo Morris wrote: Thank you for your assistance. Based on your direction, I figured it out. *This... * def add(number): print 1 + int(number) x = ['2', '4', '6', '8', '10', '12'] [add(item) for item in x] *Is the same as... * def add(number): print 1 +

Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread spir
On 12/14/2013 03:14 AM, Michael Crawford wrote: I found this piece of code on github mkdict = lambda row: dict((col, row[col]) for col in cols) #<< Apart form the "lambda" part, explained by others, one point I would note that makes the whole expression weird and hard to

Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread spir
On 12/14/2013 03:28 PM, spir wrote: This 'cols' is not even defined in the piece of code you posted (which is not all reproduced above). Oops! did not see it as param of the enclosing func. Sorry for the error, Denis ___ Tutor maillist

Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread spir
On 12/14/2013 12:37 PM, Alan Gauld wrote: I must admit I'd never even thought of checking the __name__ attribute of a lambda, I'd kind of just assumed it would be empty (or maybe 'anonymous')! You are right, Alan, in my view. any_lambda_func.__name__ == "" would be a better choice. (And

Re: [Tutor] trying to parse an xml file

2013-12-14 Thread spir
On 12/14/2013 03:29 PM, bruce wrote: Hi. Looking at a file -->> http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml The file is generated via online/web url, and appears to be XML. However, when I use elementtree: document = ElementTree.parse( '/apps/parseapp

Re: [Tutor] Prime Numbers

2013-12-16 Thread spir
On 12/15/2013 05:54 PM, Rafael Knuth wrote: Hej, I stumbled upon this program here (Python 3.3.0) and I don't quite understand how the for loop plays with the return True statement: def is_prime(number): for element in range(2, number): if number % element == 0: retur

Re: [Tutor] Prime Numbers

2013-12-16 Thread spir
On 12/16/2013 11:34 AM, spir wrote: On 12/15/2013 05:54 PM, Rafael Knuth wrote: PS: using "print" as Mark proposes is indeed you best friend to unsertand loops (and also recursion). Denis ___ Tutor maillist - Tutor@python.org To unsu

Re: [Tutor] Prime Numbers

2013-12-16 Thread spir
On 12/16/2013 09:49 AM, Rafael Knuth wrote: Hej there, number = 9 for element in range(2,9): 3 % 2 != 0: My assumption is that the program should end the loop after the first iteration again and it then should return True. No. If it did that, it wouldn't be a *loop* at all, would it? The whol

Re: [Tutor] Continue Statement

2013-12-16 Thread spir
On 12/16/2013 03:12 PM, Alina Campana wrote: Hello dear tutorlist, I feel terribly ashamed for my bad english... Yet I'll try to form my question: It is about the continue statement in python.I wrote this code i = 0while (i < 10): if i == 5: continueprint i i+=1 What i expect

Re: [Tutor] Built In Functions

2013-12-16 Thread spir
On 12/16/2013 04:28 PM, Rafael Knuth wrote: Hey there, I am currently looking into all built in functions in Python 3.3.0, one by one, in order to understand what each of them specifically does (I am familiar with some of them already, but most built in functions are still alien to me). I am wor

[Tutor] set locals

2013-12-17 Thread spir
Hello, is it at all possible to set new vars (or any symbol) into an existing scope (typically locals())? scope[name] = value raises by me an error like: TypeError: 'mappingproxy' object does not support item assignment I guess 'mappingproxy' is the implementation name of a scope (her

Re: [Tutor] set locals

2013-12-18 Thread spir
On 12/18/2013 10:02 AM, Peter Otten wrote: spir wrote: [...] Like Steven I have no idea how you produced the mappingproxy. Are you trying to use a class as a namespace (in Python 3.3)? class A: pass ... A.__dict__["foo"] = "bar" Traceback (most recent call last):

Re: [Tutor] Saving files in Python, IDE's & editors

2013-12-18 Thread spir
On 12/18/2013 03:28 AM, Keith Winston wrote: On Tue, Dec 17, 2013 at 7:26 PM, wrote: What else do I need to do to make this version of Python an actually usable programming environment? Chris Acreman Chris, I'm also a noob, but I would recommend you install/use an IDE, such as IDLE which c

Re: [Tutor] Built In Functions

2013-12-18 Thread spir
On 12/17/2013 11:30 PM, Dave Angel wrote: On Wed, 18 Dec 2013 02:39:43 +1100, Steven D'Aprano wrote: if a > 0 and b > 0 and c > 0: if all(x for x in (a, b, c): Er, perhaps it should be: if all (x> 0 for x in (a, b, c): I saw the missing paren at once (maybe a few months progr lisp

Re: [Tutor] set locals

2013-12-18 Thread spir
On 12/18/2013 12:07 PM, eryksun wrote: On Wed, Dec 18, 2013 at 5:40 AM, spir wrote: C.__setattr__(C, "baz", "BAZ") which fails, for any reason, with TypeError: can't apply this __setattr__ to type object You need __setattr__ from the metaclass

Re: [Tutor] set locals

2013-12-18 Thread spir
On 12/18/2013 11:51 AM, eryksun wrote: On Tue, Dec 17, 2013 at 10:52 AM, spir wrote: is it at all possible to set new vars (or any symbol) into an existing scope (typically locals())? scope[name] = value raises by me an error like: TypeError: 'mappingproxy' object does n

Re: [Tutor] Saving files in Python, IDE's & editors

2013-12-18 Thread spir
On 12/18/2013 06:35 PM, Reuben wrote: Keep caution while using geany. It causes indentation problems ??? (funny assertion ;-) doesn't it raise an AssertionError, perhaps?) Denis ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscri

Re: [Tutor] set locals

2013-12-19 Thread spir
On 12/18/2013 09:45 PM, Alan Gauld wrote: On 18/12/13 17:45, Mark Lawrence wrote: Can I be so bold as to ask how discussing metaclasses and __setattr__ on a tutor mailing list is going to help the newbie who's having problems with their "hello world" program? It won't, but the tutor list is a

Re: [Tutor] Saving files in Python, IDE's & editors

2013-12-19 Thread spir
On 12/19/2013 12:56 AM, Steven D'Aprano wrote: On Tue, Dec 17, 2013 at 09:28:14PM -0500, Keith Winston wrote: On Tue, Dec 17, 2013 at 7:26 PM, wrote: What else do I need to do to make this version of Python an actually usable programming environment? Chris Acreman Chris, I'm also a noob,

Re: [Tutor] Generator next()

2013-12-30 Thread spir
On 12/29/2013 01:38 PM, Steven D'Aprano wrote: >In the previous timer function that I was using, it defined a timer class, >and then I had to instantiate it before I could use it, and then it saved a >list of timing results. I think in yours, it adds attributes to each >instance of a function/met

Re: [Tutor] Generator next()

2013-12-30 Thread spir
On 12/29/2013 12:33 PM, Steven D'Aprano wrote: def adder_factory(n): def plus(arg): return arg + n return plus # returns the function itself If you call adder_factory(), it returns a function: py> adder_factory(10) .plus at 0xb7af6f5c> What good is this? Watch carefully:

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread spir
rint". It is rarely a good idea to reuse such names, but maybe you did not know it. Here is what it does (if you don't know yet about iterator objects, this will give you a fore-taste, but don't bother with that topic before you actually need them): spir@ospir:~$ python3 Python 3.

[Tutor] subtyping builtin type

2013-12-31 Thread spir
Hello, I don't remember exactly how to do that. As an example: class Source (str): __slots__ = ['i', 'n'] def __init__ (self, string): self.i = 0 # current matching index in source self.n = len(string)# number of ucodes (Unicode code points)

Re: [Tutor] subtyping builtin type

2013-12-31 Thread spir
On 12/31/2013 04:03 PM, Zachary Ware wrote: On Tue, Dec 31, 2013 at 8:35 AM, spir wrote: Hello, I don't remember exactly how to do that. As an example: class Source (str): __slots__ = ['i', 'n'] def __init__ (self, string): self.i = 0

Re: [Tutor] subtyping builtin type

2013-12-31 Thread spir
On 12/31/2013 06:53 PM, eryksun wrote: On Tue, Dec 31, 2013 at 11:21 AM, Mark Lawrence wrote: The glossary entry for __slots__ states "A declaration inside a class that saves memory by pre-declaring space for instance attributes and eliminating instance dictionaries. Though popular, the techniq

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread spir
On 12/31/2013 09:46 PM, Keith Winston wrote: Thanks Denis, I found out about the iter builtin last night, a few hours after I'd coded/posted that. Oops. Thanks for your other comments, I am clearer now about the distinction of creating a new, empty list vs. clearing the same list out, and the sub

Re: [Tutor] lists of lists: more Chutes & Ladders!

2013-12-31 Thread spir
On 01/01/2014 07:13 AM, eryksun wrote: >I'm afraid I've lost the context, and don't understand why this is >important. It's true that not all built-in objects are in builtins, and >not all objects in builtins are built-in, but other than for pedantic >correctness, why does this matter? Denis sai

Re: [Tutor] subtyping builtin type

2014-01-01 Thread spir
On 01/01/2014 01:26 AM, Steven D'Aprano wrote: On Tue, Dec 31, 2013 at 03:35:55PM +0100, spir wrote: Hello, I don't remember exactly how to do that. As an example: class Source (str): __slots__ = ['i', 'n'] def __init__ (self, string): self.i

Re: [Tutor] subtyping builtin type

2014-01-02 Thread spir
On 01/02/2014 03:21 AM, Steven D'Aprano wrote: On Wed, Jan 01, 2014 at 02:49:17PM +0100, spir wrote: On 01/01/2014 01:26 AM, Steven D'Aprano wrote: On Tue, Dec 31, 2013 at 03:35:55PM +0100, spir wrote: [...] I take the opportunity to add a few features, but would do without Source

[Tutor] what's your name? (to a class)

2014-01-02 Thread spir
Hello tutorians, Am I missing something or don't classes know how they're called (unlike funcs, which have a __name__ attribute, very practicle)? Is there a way to get it otherwise? The point is to have a super-type define a general __repr__ like eg: class SuperType: # ... def __repr

Re: [Tutor] what's your name? (to a class)

2014-01-02 Thread spir
On 01/02/2014 11:18 AM, Dominik George wrote: Hi, Am I missing something or don't classes know how they're called (unlike funcs, which have a __name__ attribute, very practicle)? Is there a way to get it otherwise? The class has it, the instance doesn't. That said, you are looking for self._

Re: [Tutor] what's your name? (to a class)

2014-01-02 Thread spir
On 01/02/2014 02:40 PM, Steven D'Aprano wrote: On Thu, Jan 02, 2014 at 11:12:30AM +0100, spir wrote: Hello tutorians, Am I missing something or don't classes know how they're called (unlike funcs, which have a __name__ attribute, very practicle)? Is there a way to get it otherw

Re: [Tutor] what's your name? (to a class)

2014-01-02 Thread spir
On 01/02/2014 04:48 PM, eryksun wrote: On Thu, Jan 2, 2014 at 5:12 AM, spir wrote: Am I missing something or don't classes know how they're called (unlike funcs, which have a __name__ attribute, very practicle)? Is there a way to get it otherwise? What are you smoking, and where

Re: [Tutor] What's in a name?

2014-01-03 Thread spir
On 01/03/2014 12:41 PM, Alan Gauld wrote: return [step, self.move_count, self.num_chutes, self.num_ladders, self.chutes_list, self.ladders_list] In OOP you rarely have to return attributes. And since step is passed in as an argument the caller already knows [it]. So I don't think you

Re: [Tutor] Mastering the fundamentals

2014-01-03 Thread spir
On 01/03/2014 09:30 AM, Christian Alexander wrote: Hello Tutorians, I've just recently acquired "Learning Python", and I must state that it is a fairly thorough book. However it seems as if I am learning at a very slow pace, so my question is, as far as setting a goal to master the basics, wher

Re: [Tutor] python, speed, game programming

2014-01-03 Thread spir
On 01/03/2014 10:53 PM, Keith Winston wrote: My concern is with speed. This will have to keep up with (somewhat arbitrarily) fast typing, while doing background processing, with a GUI of course. I wouldn't even bother. Try & see, you may be surprised. There are several factors at play: * The c

Re: [Tutor] More or less final Chutes & Ladders

2014-01-04 Thread spir
On 01/04/2014 05:47 AM, Keith Winston wrote: Here is what I think will be about the final version of C and L. I rearranged it quite a bit (into 2 classes), fixed a bug or two, and generally cleaned it up a bit. I haven't really polished it, but hopefully it will be less difficult to read... which

Re: [Tutor] simple arg problem

2014-01-04 Thread spir
On 01/04/2014 05:45 AM, Steven D'Aprano wrote: On Fri, Jan 03, 2014 at 09:56:25PM -0500, Keith Winston wrote: gmail is driving me crazy. Anyway, every time I run it with: if __name__ == "__main__": tarray = CandL_Array tarray.populate(100) I get an error Traceback (most recent call

Re: [Tutor] What's in a name?

2014-01-04 Thread spir
On 01/04/2014 06:32 AM, Keith Winston wrote: On Fri, Jan 3, 2014 at 11:59 PM, Steven D'Aprano wrote: thelist = vars()[name] I see: vars() certainly looks less dangerous than eval(), but I'm guessing that's still smelly code? I hadn't known about vars() or I probably would have used it. It

Re: [Tutor] Fwd: What's in a name?

2014-01-04 Thread spir
On 01/04/2014 06:36 AM, Steven D'Aprano wrote: Now, it's true that when *debugging code*, being able to see the name of the variable and the contents of the variable is useful. But in ordinary code, why would you care to print the name of the variable and its contents. Who cares what the variable

Re: [Tutor] Copying [was Re: What's in a name?]

2014-01-04 Thread spir
On 01/04/2014 07:24 AM, Keith Winston wrote: I had heard about deep/shallow copies, though in this particular example (all int dicts), I don't think there's a difference...? There's none, you're right. It's only whenever inner items (fields, etc...) themselves are complex elements and mutable.

Re: [Tutor] python, speed, game programming

2014-01-04 Thread spir
On 01/04/2014 10:14 AM, Steven D'Aprano wrote: While I agree with Devin, it is possible to write absurdly slow code in *any* language. This is why is is better to write straightforward, simple code in preference to complicated, intricate code -- it is easier to understand simple code, which means

Re: [Tutor] python, speed, game programming

2014-01-04 Thread spir
On 01/04/2014 02:38 AM, Keith Winston wrote: The thing that put me on edge was noticing that my simple Chutes & Ladders game doesn't go ANY faster on a machine that benchmarks perhaps 1000 times faster than another... You could say this about most programs in most langs. Actually, some even re

Re: [Tutor] More or less final Chutes & Ladders

2014-01-04 Thread spir
On 01/04/2014 12:33 PM, Keith Winston wrote: Thanks Alan & Denis: Alan, the improvement you suggested had already been made, and adopted. Good catch. Denis: alas, there are chutes and ladders dicts, but I guess your chutes & ladders lists are local to the results class... Your suggestion is quit

Re: [Tutor] More or less final Chutes & Ladders

2014-01-04 Thread spir
On 01/04/2014 02:03 PM, Steven D'Aprano wrote: >I understand that Python doesn't have composite objects, but neither does >it dislallow my list of lists of ints and lists... which is, I imagine, >very space efficient. I'm afraid I have no idea what you mean by Python not having "composite object

Re: [Tutor] More or less final Chutes & Ladders

2014-01-04 Thread spir
On 01/04/2014 02:03 PM, Steven D'Aprano wrote: >I'm also a bit confused here: obviously tuples are immutable, but one can >use lists in them... I think that makes those lists' contents immutable? Nope. It makes the tuple immutable in the sense that it's *direct* contents cannot be changed, but m

Re: [Tutor] More or less final Chutes & Ladders

2014-01-05 Thread spir
On 01/05/2014 08:52 AM, Mark Lawrence wrote: On 05/01/2014 07:09, Keith Winston wrote: Thanks all, interesting. I'll play more with tuples, I haven't knowingly used them at all... Keith Homework for you :) Write a line of code that creates a list of say 3 or 4 integers, then write a line t

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 12:52 AM, Steven D'Aprano wrote: If you don't understand an exception, you have no business covering it up and hiding that it took place. Never use a bare try...except, always catch the *smallest* number of specific exception types that make sense. Better is to avoid catching except

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/04/2014 08:26 PM, Alex Kleider wrote: Any suggestions as to a better way to handle the problem of encoding in the following context would be appreciated. The problem arose because 'Bogota' is spelt with an acute accent on the 'a'. $ cat IP_info.py3 #!/usr/bin/env python3 # -*- coding : ut

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 03:31 AM, Alex Kleider wrote: I've been maintaining both a Python3 and a Python2.7 version. The latter has actually opened my eyes to more complexities. Specifically the need to use unicode strings rather than Python2.7's default ascii. So-called Unicode strings are not the solut

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 08:57 AM, Alex Kleider wrote: On 2014-01-04 21:20, Danny Yoo wrote: Oh! That's unfortunate! That looks like a bug on the hostip.info side. Check with them about it. I can't get the source code to whatever is implementing the JSON response, so I can not say why the city is not

Re: [Tutor] More or less final Chutes & Ladders

2014-01-06 Thread spir
On 01/05/2014 08:40 PM, Keith Winston wrote: On Sun, Jan 5, 2014 at 2:52 AM, Mark Lawrence wrote: Homework for you :) Write a line of code that creates a list of say 3 or 4 integers, then write a line that creates a tuple with the same integers. Use the dis module to compare the byte code th

Re: [Tutor] garbage collecting

2014-01-08 Thread spir
On 01/08/2014 10:30 AM, Keith Winston wrote: well, fair enough. Generally, the issue involves instances when Python will come back, but it might take several minutes or much longer. And weird behaviour ensues: like timers I put on the program don't actually time the amount of time it's busy (by a

Re: [Tutor] recursion depth

2014-01-08 Thread spir
rammer feedback. Guess it has to do with cycles, but there are ways to do that; and python manages cycles in list expressions: spir@ospir:~$ python3 Python 3.3.1 (default, Sep 25 2013, 19:29:01) [GCC 4.7.3] on linux Type "help", "copyright", "credits" or "license&q

Re: [Tutor] Python Question

2014-01-10 Thread spir
On 01/10/2014 01:11 AM, Amy Davidson wrote: Hi, I am a university student who is struggling with writing functions in Python. I’ve been attempting to write a function in Python for over 2 hours with no progress. The function must be called, printID and take a name and student number as parame

Re: [Tutor] lambdas, generators, and the like

2014-01-16 Thread spir
's written like a list comprehension, bit with () instead of []. The semantic difference is that items are generated once at a time instead of all in one go and stored in a list. Another difference is that one cannot reuse such a generator object (once end is reached, it is like "e

Re: [Tutor] lambdas, generators, and the like

2014-01-16 Thread spir
On 01/12/2014 10:04 AM, Keith Winston wrote: I've got this line: for k in range(len(tcombo)): tcombo_ep.append(list(combinations(tcombo, k+1))) generating every possible length combination of tcombo. I then test them, and throw most of them away. I need to do this differently, it gets way

Re: [Tutor] iterators

2014-01-18 Thread spir
On 01/18/2014 09:51 AM, Keith Winston wrote: I don't really get iterators. I saw an interesting example on Stackoverflow, something like with open('workfile', 'r') as f: for a, b, c in zip(f, f, f): And this iterated through a, b, c assigned to 3 consecutive lines of the file as it it

<    1   2   3   4   5   6   7   >