From ian.g.kelly at gmail.com Sat Mar 1 00:16:18 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Feb 2014 22:16:18 -0700 Subject: Tuples and immutability In-Reply-To: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> Message-ID: On Fri, Feb 28, 2014 at 5:22 PM, Mark H. Harris wrote: > I really think this is a bug; honestly. IMHO it should be an error to use += with an immutable type and that means not at all. In other words, the list should not even be considered, because we're talking about changing a tuple... which should not be changed (nor should its members be changed). How would you propose doing that? Bear in mind that while Python knows that tuples specifically are immutable, it doesn't generally know whether a type is immutable. The best it can do is try the operation and raise a TypeError if it fails. So you can special-case the code for += to fail earlier if the left side of the assignment is an tuple index, but it's not currently possible to do the same for arbitrary immutable user types. Even if that is solved, how you do propose preventing the simple workaround: tup = (0, [1, 2, 3], 4) thelist = tup[1] thelist += [5, 6] which currently works just fine. I don't think that entirely disallowing mutable objects inside tuples is an acceptable solution. For one, it would mean never allowing instances of custom classes. They could then basically only contain strings, numbers, frozensets, and other tuples. For another, my experience suggests that if I'm putting a list inside a tuple in the first place, I am generally not relying on the immutability of that tuple anyway, so I don't really see this as fixing an actual problem. The usual reason for wanting an immutable object is to hash it, and a tuple containing a list already can't be hashed. From ian.g.kelly at gmail.com Sat Mar 1 00:26:07 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Feb 2014 22:26:07 -0700 Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> Message-ID: On Fri, Feb 28, 2014 at 6:27 PM, Eric Jacoboni wrote: > Anyway, the TypeError should rollback, not commit the mistake. The Python interpreter isn't a database. It can't rollback the object because the operation that was performed may not be reversible. Consider for example a socket class where the += operator is overloaded to send a message on the socket. The message can't be unsent. From harrismh777 at gmail.com Sat Mar 1 00:30:30 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Fri, 28 Feb 2014 21:30:30 -0800 (PST) Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> Message-ID: <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> On Friday, February 28, 2014 8:01:45 PM UTC-6, Chris Angelico wrote: > > Does your switch construct have to handle the magic of GT_1 meaning "> > 1", or do you first figure out where it falls with an if/elif tree? > ChrisA hi Chris, yeah... well think again of the switch block in C... the switch block selects a branch based on an integral number (int character) that is generally a return code from a function. The function hides all of that logic. The function runs and returns a "number" which is passed to the switch block. That number generally corresponds to a DEFINE constant at the top or in the header... so we get something really readable: x = somefunc() switch (x): case: CONSTANT1 call blah blah case: CONSTANT2 call blah blah blah default blah This very same concept can work in python code too... if everyone would just agree to try. Again, how it switches is less important than does the "switch" appear readable to humans... whether its optimized or not. Its up to the devs whether it switches on an int, a "switch object" whatever I mean by that, or on something else I have not thought about... the point is , ... can we make something more readable to average people than large if elif else chains, or dict dispatch tables... ?? Its just a question. I know Guido thinks not... and a lot of other people too... but what if there is a third option? If we think about this hard enough there is probably a win win out there that would work/ just sayin marcus From ian.g.kelly at gmail.com Sat Mar 1 00:34:56 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 28 Feb 2014 22:34:56 -0700 Subject: Tuples and immutability In-Reply-To: <2ddad91d-e188-4fd0-be1c-ed30edbf280b@googlegroups.com> References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <2ddad91d-e188-4fd0-be1c-ed30edbf280b@googlegroups.com> Message-ID: On Fri, Feb 28, 2014 at 9:45 PM, Mark H. Harris wrote: > I really believe IMHO that the error should have come when you made the list an item of a tuple. An immutable object should have NO REASON to contain a mutable object like list... I mean the whole point is to eliminate the overhead of a list ... why would the python interpreter allow you to place a mutable object within an immutable list in the first place. This is just philosophical, and yes, the core dev's are not going to agree with me on this either. One very common example of tuples containing lists is when lists are passed to any function that accepts *args, because the extra arguments are passed in a tuple. A similarly common example is when returning multiple objects from a function, and one of them happens to be a list, because again they are returned in a tuple. def f(*args): print(args) return (args[1:]) >>> result = f(1, 2, 3, [4, 5]) (1, 2, 3, [4, 5]) >>> print(result) (2, 3, [4, 5]) Both of these things are quite handy, and if you restrict tuples from containing lists, then you lose both of them (or you switch to lists and lose the optimization for no good reason). From harrismh777 at gmail.com Sat Mar 1 00:50:44 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Fri, 28 Feb 2014 21:50:44 -0800 (PST) Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <2ddad91d-e188-4fd0-be1c-ed30edbf280b@googlegroups.com> Message-ID: <2c38b941-9f3f-485f-9e97-525f28c5453a@googlegroups.com> On Friday, February 28, 2014 11:34:56 PM UTC-6, Ian wrote: > One very common example of tuples containing lists is when lists are > passed to any function that accepts *args, because the extra arguments > are passed in a tuple. A similarly common example is when returning > multiple objects from a function, and one of them happens to be a > list, because again they are returned in a tuple. > def f(*args): > print(args) > return (args[1:] > > >>> result = f(1, 2, 3, [4, 5]) > (1, 2, 3, [4, 5]) > >>> print(result) > (2, 3, [4, 5]) I agree Ian... good points all. ... again, I'm not arguing with anyone... just saying that an error (whatever we mean by that) should not half-way-fail.... we are only pointing out the problem... we have not idea what the solution is yet. Intuitively everyone can see that there is a problem here... the debate cannot be answered either because of the inherent design of python (almost all of which we love). So, as they say, what is a mother to do? ... I mean, some people's kids... I don't know how I propose to handle the problem... I think the first step is getting everyone to agree that there IS a problem... then debate how to tackle the solution proposals. marcus From harrismh777 at gmail.com Sat Mar 1 01:16:24 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Fri, 28 Feb 2014 22:16:24 -0800 (PST) Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> Message-ID: On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: > How would you propose doing that? Bear in mind that while Python > knows that tuples specifically are immutable, it doesn't generally > know whether a type is immutable. hi Ian, consider the problem... its a "cake" and "eat it too" scenario... you can't have your cake and eat it too.... This is what I mean... the error message is telling the user that it cannot do what he has requested, and yet IT DID. You have one of two scenarios: 1) the message is arbitrarily lying and it really can assign an immutable's item... (and it did!) or 2) It really should NOT assign an immutables item (the message is truth) but the action was "allowed" anyway despite the protocol and accepted policy... in which case the two scenarios add up to a giant logical inconsistency... QED a bug. There really is no way to get around this from the average user's perspective. And therefore, this is going to come up again and again and again... because coders don't like unexpected logical inconsistencies. It is not helpful either to explain it away by knowing how the policy works under the covers... the average user of the python language should not have to understand the policy of the underlying substructure... 1) either they can't assign the list item of an immutable tuple type (and the action is a flaw, say bug of 2) they really CAN set the immutable's list item type (which it did!) and the message is bogus. Its one way or the other.... we can't have our cake and eat it too... this is (one way or the other) a bug. IMHO From rosuav at gmail.com Sat Mar 1 01:24:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Mar 2014 17:24:15 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> Message-ID: On Sat, Mar 1, 2014 at 4:30 PM, Mark H. Harris wrote: > hi Chris, yeah... well think again of the switch block in C... the switch block selects a branch based on an integral number (int character) that is generally a return code from a function. The function hides all of that logic. The function runs and returns a "number" which is passed to the switch block. That number generally corresponds to a DEFINE constant at the top or in the header... so we get something really readable: > > x = somefunc() > switch (x): > case: CONSTANT1 > call blah blah > case: CONSTANT2 > call blah blah blah > default > blah Okay. So you'd do that to make this more readable. Here's the original: if (n**2 < D(1)): a = __atan__(n) elif (n == D(1)): a = gpi/4 elif (n == D(-1)): a = -(gpi/4) elif (n < D(-1)): a = __atan__Lt_neg1__(n) else: a = __atan__Gt_1__(n) Now let's see. Your code doesn't perfectly translate, so I'm having to guess a bit here. GT_1 = object() LT_n1 = object() IS_1 = object() IS_n1 = object() def categorize(n): if (n**2 < D(1)): return None elif (n == D(1)): return IS_1 elif (n == D(-1)): return IS_n1 elif (n < D(-1)): return LT_n1 else: return GT_1 switch categorize(x): case GT_1: __atan__Gt_1__(x) # Not sure which you mean, this case LT_n1: __atan__Lt_neg1__(x) # or this case LT_1: __atan__Lt_1__(x) # So I have both, ish. case IS_1: a = gpi/4 case IS_n1: a = -gpi/4 default: # Presumably this should be a=? __atan__(x) Please copy and paste this, and then edit it so the two actually do exactly the same thing. And then, if you please [1], explain to me how the second one is more readable. It still has the exact same if/elif tree, because there's no other way to figure out which constant you should have for the switch; and as well as that, it exhibits an appalling degree of Soft Coding[2], and it's roughly three times as much code. If you want to change anything, you potentially have to edit three places: the list of constants at the top, the condition function, and the switch. This can't be your idea of readability. Show me where I'm wrong. ChrisA [1] Steven D'Aprano unwittingly quoted HMS Pinafore a few posts back. I'm now doing it consciously, for I hold that (on the seas) the expression "if you please" a particularly gentlemanly tone implants. [2] http://thedailywtf.com/Articles/Soft_Coding.aspx From rosuav at gmail.com Sat Mar 1 01:29:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Mar 2014 17:29:44 +1100 Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> Message-ID: On Sat, Mar 1, 2014 at 5:16 PM, Mark H. Harris wrote: > This is what I mean... the error message is telling the user that it cannot do what he has requested, and yet IT DID. You have one of two scenarios: 1) the message is arbitrarily lying and it really can assign an immutable's item... (and it did!) or 2) It really should NOT assign an immutables item (the message is truth) but the action was "allowed" anyway despite the protocol and accepted policy... in which case the two scenarios add up to a giant logical inconsistency... QED a bug. > It did not assign anything. The error was raised because the tuple rejects item assignment. It's that simple. The object was mutated before the assignment was attempted. ChrisA From harrismh777 at gmail.com Sat Mar 1 01:25:50 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Fri, 28 Feb 2014 22:25:50 -0800 (PST) Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> Message-ID: <9ee137b0-3313-41c6-9792-9438ff05038a@googlegroups.com> On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: > How would you propose doing that? Bear in mind that while Python > knows that tuples specifically are immutable, it doesn't generally > know whether a type is immutable. I was going to bed, and then thought of the solution. Allow the action. Hold the error pending until the action either succeeds or fails for the "item," in this case a list, and then post the error for the tuple depending... this would make the whole mess consistent, and even compatible with the idea of dynamic name and type binding... So, in other words, the action should be permitted, and actually was allowed, and the message is incorrectly reporting something that for this particular "item" is NOT true. The error message (and timing of same) is the bug (philosophically). Under the covers it may be (and probably is) more complicated. Good night everyone. Cheers From as at sci.fi Sat Mar 1 01:54:45 2014 From: as at sci.fi (Anssi Saari) Date: Sat, 01 Mar 2014 08:54:45 +0200 Subject: how to install automatically missing modules on a debian-system References: <7841a394-46ff-4f63-8afc-12b396bb8695@googlegroups.com> Message-ID: hugocoolens writes: > It often happens I start a python-script I wrote some time ago on another > system and get messages like "module_x is missing". I then perform an apt-cache search module_x, followed by an apt-get install name_of_missing_module.deb > I was wondering whether someone here has a kind of method which automatically > looks for the missing modules as debian-packages and offers to install them? I don't know if there's anything that works with random Python scripts. I suppose the straightforward Debian way of it would be to package your script in a .deb package and include the proper dependencies, then apt would take care of installing those too. Debian has a wiki page covering the project's Python packaging policy and how to do it at https://wiki.debian.org/Python/Packaging. From as at sci.fi Sat Mar 1 01:55:07 2014 From: as at sci.fi (Anssi Saari) Date: Sat, 01 Mar 2014 08:55:07 +0200 Subject: extend methods of decimal module References: <02cdd9c7-aef7-4cc7-a813-cd1c9627ceb4@googlegroups.com> <94b1962a-0004-4c5b-b484-972a166b88b5@googlegroups.com> <55525f2c-fd3a-4927-b642-2dbf5eae7e9b@googlegroups.com> Message-ID: Terry Reedy writes: > On 2/27/2014 7:07 AM, Mark H. Harris wrote: > >> Oh, and one more thing... whoever is doing the work on IDLE these >> days, nice job! It is stable, reliable, and just works/ >> appreciate it! > > As one of 'them', thank you for the feedback. There are still some > bugs, but I hit them seldom enough that I am now looking at > enhancement issues. I recently watched a presentation by Jessica McKellar of PSF about what Python needs to stay popular. Other than the obvious bits (difficulties or limited support of Python on major platforms like Windows and mobile) the slight lack of perfection in IDLE was mentioned. Specifically the old blog post titled "The Things I Hate About IDLE That I Wish Someone Would Fix" at http://inventwithpython.com/blog/2011/11/29/the-things-i-hate-about-idle-that-i-wish-someone-would-fix/ It lists 17 issues and some more in the comments. Are those things something that could be considered? Or have maybe been done already? I'm not an IDLE user so this is mostly an academic interest on my part. From swdunning at cox.net Sat Mar 1 01:46:02 2014 From: swdunning at cox.net (Scott W Dunning) Date: Fri, 28 Feb 2014 23:46:02 -0700 Subject: Help with "Guess the number" script Message-ID: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Hello, i am working on a project for learning python and I?m stuck. The directions are confusing me. Please keep in mind I?m very ne to this. The directions are long so I?ll just add the paragraphs I?m confused about and my code if someone could help me out I?d greatly appreciate it! Also, we haven?t learned loops yet so just conditional operators and for some reason we can?t use global variables. from random import randrange randrange(1, 101) from random import seed seed(129) def print_description(): print """Welcome to Guess the Number. I have seleted a secret number in the range 1 ... 100. You must guess the number within 10 tries. I will tell you if you ar high or low, and I will tell you if you are hot or cold.\n""" def get_guess(guess_number): print "(",guess_number,")""Plese enter a guess:" current_guess = raw_input() return int(guess_number) def main(): print_description() secret = 50 current_guess = 1 get_guess(1) if current_guess != secret(): print "Congratulations you win!!" main() Here are the instructions I?m having a hard time with and just not sure I?m doing it correctly. I?m not sure the get_guess function is correct and I?m a little lost with the secret and current_guess variable. From within the body of the main function, immediately after the call to print description, create variable secret and assign it a random number between 1 and 100, generated using the randrange function. You will need to pass two argument to randrange, what do you think they should be? You should be able to use the python help system or online python documentation to make sure you understand the arguments to randrange. After the end of the body of the print description function, define a new global function named get guess that takes a single parameter. Name the parameter guess number, because it will hold the index (1, 2, 3, ..., 10) of current guess attempt. Make the function ask the user to enter guess using the raw input function. The function will return the number entered by the user, after it has been converted to an integer. Return to the main function after the statement that assigned a value to the secret variable. In a new variable named current guess store the result of calling the get guess function with an argument of 1. Run your program to make sure it works correctly. At the end of the main function, check if the current guess matches the secret. If it matches, print ?Congratulations, you win!?. If it does not, print ?Please play again!? Thanks again!!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sat Mar 1 02:33:13 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Mar 2014 18:33:13 +1100 Subject: Help with "Guess the number" script References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: <85y50ul6fa.fsf@benfinney.id.au> Scott W Dunning writes: > Hello, i am working on a project for learning python and I?m stuck. > The directions are confusing me. Please keep in mind I?m very ne to > this. Scott, please default to asking these ?covered in a beginner Python course? questions at the Python tutor forum . Discussions here are going to assume you've already covered the very basics, so it's not very suitable for the questions you're asking. -- \ ?Isn't it enough to see that a garden is beautiful without | `\ having to believe that there are fairies at the bottom of it | _o__) too?? ?Douglas Adams | Ben Finney From marko at pacujo.net Sat Mar 1 05:31:39 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Mar 2014 12:31:39 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> Message-ID: <874n3irz04.fsf@elektro.pacujo.net> Ben Finney : > Since you don't care about identity, only that the objects have > different values, you should be comparing for equality with ?==?. Ok, one last attempt. I need *identifiers*. I could simply define: class ABC: A = object() B = object() C = object() The program would work perfectly. Except, if it's got a bug. I know self.abc contains either A, B or C, but which one? Printing out self.abc won't give me any help. I could print out ABC.A, ABC.B and ABC.C and see which one matches, but that's cumbersome. The next variant is to use objects that have names: class Symbol: def __init__(self, name): self.name = name def __str__(self): return self.name class ABC: A = Symbol("A") B = Symbol("B") C = Symbol("C") The same program still works (and still uses "is" for identity tests, mind you). The next realization is that the Symbol class is completely redundant as any string object would fit the bill. Hence we can reduce the visual clutter by simply defining: class ABC: A = "A" B = "B" C = "C" The same program still works (and still uses "is" for identity tests, mind you). Marko PS The only remaining redundancy is having to repeat the symbol name in every assignment. If Python (like Lisp) had a builtin symbol datatype, you wouldn't have to define anything at all but simply assign something like this: self.abc = $A where $A would be a symbol. From marko at pacujo.net Sat Mar 1 05:39:58 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Mar 2014 12:39:58 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <531115e1$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ob1qeqe0.fsf@elektro.pacujo.net> <53112d71$0$29985$c3e8da3$5496439d@news.astraweb.com> <874n3ienhd.fsf@elektro.pacujo.net> <53113f1b$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wqgeqk1t.fsf@elektro.pacujo.net> Steven D'Aprano : > But I'm not sure that there is a good reason to put the class definitions > inside the __init__ method. That means every time you create a new > StateMachine instance, the classes have to be re-created. > > [...] > > It will be much more efficient if you pull all the Idle, etc. classes out > and make them top-level global classes. > [...] > But then the closure over sm won't work... Precisely. As for effiency, I don't know if it is more efficient to create ad hoc classes or ad hoc instances; might be a tossup in CPython. > Since in this example you've actually got significant behaviour in the > states, they aren't just symbols, and some sort of solution along > these lines (whether you use multiple inner classes or not) is > appropriate. That inner class solution is an alternative to the symbol approach. In the absense of a switch statement, the inner class has lots going for it. Marko From ben+python at benfinney.id.au Sat Mar 1 05:48:40 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Mar 2014 21:48:40 +1100 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> Message-ID: <85ppm6kxdj.fsf@benfinney.id.au> Marko Rauhamaa writes: > Ben Finney : > > > Since you don't care about identity, only that the objects have > > different values, you should be comparing for equality with ?==?. > > Ok, one last attempt. > > I need *identifiers*. And, as you've realised, without an Enum pattern you have the option of using string *values* ? because it's the values you want to see in error message output. The *identity* of the values doesn't matter. Any string of the given value will work fine. So don't fool the reader into thinking you actually care about object identity; don't use ?is? for comparing these values. Use ?==?, since that's all that matters for getting a value that will work fine. > The same program still works (and still uses "is" for identity tests, > mind you). You have provided no justification for using an identity test. It confuses the matter by pretending you care about object identity, when you *do not* as evidenced by all your arguments so far. The equality operator ?==? is clearer for your purpose, and less confusing. -- \ ?[Entrenched media corporations will] maintain the status quo, | `\ or die trying. Either is better than actually WORKING for a | _o__) living.? ?ringsnake.livejournal.com, 2007-11-12 | Ben Finney From ganesh1pal at gmail.com Sat Mar 1 06:13:11 2014 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 1 Mar 2014 16:43:11 +0530 Subject: Python : parsing the command line options using optparse In-Reply-To: References: Message-ID: > > > > Thanks Peter and Simon for the hints it worked : ) without ' =' > > # Python corrupt.py -o INODE -p /ifs/1.txt -q SET -f 1 > > Current Default Choice : > > Choice: INODE > Choice: SET > Choice: 1 > > > > Iam done with the command line parsing but got stuck while trying to implement switch kind of behavior with dictionaries. So posting 2 more questions Question 1 : Iam using the options.name directly for manipulations is this fine or do I need to assign it to variable and then use it Example: Entered at cli #python corrupt.py -object_type INODE --path_name/ifs/1.txt -operation_type SET Initialize all the command line option and then use it object_type = options.object_type path_name = options.path_name if object_type == 'LIN': corrupt_inode() elif object_type == 'DATA': corrupt_data() OR if options.object_type == 'LIN': corrupt_inode() elif options.object_type == 'DATA': corrupt_data() elif options.object_type == 'INODE': corrupt_data() #output #python corrupt.py -object_type INODE -p /ifs/1.txt -q SET -f 10 -m 10 -n 123 -l -c Corrupted inode _________________________________________________________________________________________________________ Question 2 : I wanted to use dictionary to match the above if else behavior (we don't have switch in python I guess ) and If else looks very untidy. Is it possible to store the options.object_type as a key in the dictionary and then based on the value entered in the command line invoke the appropriate function I tried creating a dictionary like this but Iam getting a wrong output object_type_dictonary = { 'LIN' : corrupt_inode(), 'INODE' : corrupt_lin(), 'DATA' : corrupt_data(), }; and then ran # python corrupt.py -object_type= inode ( This prints all the values for me) Example : Corrupted inode Corrupted LIN Corrupted data PS : If user enters object_type= inode it should execute corrupt_inode and print corrupted inode Any help on tips highly helpful :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Sat Mar 1 06:28:09 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Mar 2014 13:28:09 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> Message-ID: <87k3ceqhti.fsf@elektro.pacujo.net> Ben Finney : > Use ?==?, since that's all that matters for getting a value that will > work fine. You are telling me to use '==' if I choose string objects and 'is' if I choose some other objects. I prefer a solution that works regardless of what objects I choose for identifiers. There really is no taboo against string object identity if you know what you are doing. Marko From __peter__ at web.de Sat Mar 1 06:37:16 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 01 Mar 2014 12:37:16 +0100 Subject: Python : parsing the command line options using optparse References: Message-ID: Ganesh Pal wrote: > Iam using the options.name directly for manipulations is this fine or do > I need to assign it to variable and then use it > if options.object_type == 'LIN': > corrupt_inode() This is fine. You would only consider storing the value if you are going to use it very often (millions rather than thousands) in a time-critical loop. > I wanted to use dictionary to match the above if else behavior (we don't > have switch in python I guess ) and If else looks very untidy. > Is it possible to store the options.object_type as a key in the dictionary > and then based on the value entered in the command line invoke the > appropriate function > I tried creating a dictionary like this but Iam getting a wrong output > object_type_dictonary = { 'LIN' : corrupt_inode(), > 'INODE' : corrupt_lin(), > 'DATA' : corrupt_data(), > }; > and then ran # python corrupt.py -object_type= inode ( This prints all > the values for me) That's because you are storing the result of the function call when you should be storing the function itself: # build the dispatch table: object_type_dictionary = { "LIN": corrupt_lin, # no () here, we're storing the function "INODE": corrupt_inode, "DATA": corrupt_data } ... handler = object_type_dictionary[options.object_type] # look up the function handler() # call it The last two lines could also be merged into one object_type_dictionary[options.object_type]() but the first version may be clearer. From steve+comp.lang.python at pearwood.info Sat Mar 1 06:47:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2014 11:47:03 GMT Subject: Python : parsing the command line options using optparse References: Message-ID: <5311c8b7$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sat, 01 Mar 2014 16:43:11 +0530, Ganesh Pal wrote: > Iam done with the command line parsing but got stuck while trying to > implement switch kind of behavior with dictionaries. So posting 2 more > questions You should start new threads for new questions. The subject line here has nothing to do with the questions you ask. > Question 1 : > > Iam using the options.name directly for manipulations is this fine or > do I need to assign it to variable and then use it It is perfectly fine to use options.name directly. There's no need to save it to a temporary variable just to use it, unless doing this makes your code easier to read. > Question 2 : > > I wanted to use dictionary to match the above if else behavior (we don't > have switch in python I guess ) and If else looks very untidy. > > Is it possible to store the options.object_type as a key in the > dictionary and then based on the value entered in the command line > invoke the appropriate function Yes. You almost got it right here: > object_type_dictonary = { 'LIN' : corrupt_inode(), > 'INODE' : corrupt_lin(), > 'DATA' : corrupt_data(), > }; (By the way, this is Python, not C, and there is no need for redundant semi-colons at the end of each line.) The mistake you made is that you *called* the functions inside the dict. Instead, just refer to the function object itself, without calling it: object_type_dictonary = { # no parens after the functions 'LIN' : corrupt_inode, 'INODE' : corrupt_lin, 'DATA' : corrupt_data, } Then, after you look up the object type, then and only then call the function: func = object_type_dictionary[object_type] func() -- Steven From rosuav at gmail.com Sat Mar 1 06:59:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Mar 2014 22:59:52 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <87k3ceqhti.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> Message-ID: On Sat, Mar 1, 2014 at 10:28 PM, Marko Rauhamaa wrote: > Ben Finney : > >> Use ?==?, since that's all that matters for getting a value that will >> work fine. > > You are telling me to use '==' if I choose string objects and 'is' if I > choose some other objects. > > I prefer a solution that works regardless of what objects I choose for > identifiers. > > There really is no taboo against string object identity if you know what > you are doing. And, as proven here in this thread, you do not know what you are doing. ChrisA From ganesh1pal at gmail.com Sat Mar 1 07:12:03 2014 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 1 Mar 2014 17:42:03 +0530 Subject: Python : parsing the command line options using optparse In-Reply-To: References: Message-ID: > > handler = object_type_dictionary[options.object_type] # look up the > function > handler() # call it > > The last two lines could also be merged into one > > object_type_dictionary[options.object_type]() > > but the first version may be clearer. > > Thanks for your valuable inputs all worked :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ganesh1pal at gmail.com Sat Mar 1 07:17:09 2014 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 1 Mar 2014 17:47:09 +0530 Subject: Python : parsing the command line options using optparse In-Reply-To: <5311c8b7$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <5311c8b7$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 1, 2014 at 5:17 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > > You should start new threads for new questions. The subject line here has > nothing to do with the questions you ask. > > Sure Steven and thanks for replying and your suggestion for Question 2 ( same as Peter Otten ) worked and Iam closing this thread now :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sat Mar 1 08:03:32 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 02 Mar 2014 00:03:32 +1100 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> Message-ID: <85lhwukr4r.fsf@benfinney.id.au> Marko Rauhamaa writes: > Ben Finney : > > > Use ?==?, since that's all that matters for getting a value that will > > work fine. > > You are telling me to use '==' if I choose string objects and 'is' if I > choose some other objects. No. I'm telling you that ?is? is *wrong* for comparing strings, because it is unreliable. > I prefer a solution that works regardless of what objects I choose for > identifiers. Some languages have a ?symbol? type, whose values can be directly compared. Python doesn't have such a type. If you want to use strings as a substitute, go ahead: they work fine. But compare strings by *equality*, not identity, because it's their *values* which will be the identifiers. Their object identity will not be reliably comparable. That's what everyone has been telling you all along, for reasons already explained. > There really is no taboo against string object identity if you know what > you are doing. You, as has been amply demonstrated, do not, despite your dogmatic assertions. -- \ ?Under democracy one party always devotes its chief energies to | `\ trying to prove that the other party is unfit to rule ? and | _o__) both commonly succeed, and are right.? ?Henry L. Mencken | Ben Finney From stefan_ml at behnel.de Sat Mar 1 09:26:09 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 01 Mar 2014 15:26:09 +0100 Subject: insert html into ElementTree without parsing it In-Reply-To: References: Message-ID: graeme.pietersz at gmail.com, 24.02.2014 10:45: > I am building HTML pages using ElementTree. > I need to insert chunks of untrusted HTML into the page. I do not need or want to parse this, just insert it at a particular point as is. How would you want to find out if it can be safely inserted or not without parsing it? > The best solutions I can think of are rather ugly ones: manipulating the string created by tostring. > > Is there a nicer way of doing this? Is it possible, for example, to customise how an element is converted to a string representation? I am open to using something else (e.g. lxml) if necessary. lxml has a tool to discard potentially unsafe content from HTML files: http://lxml.de/lxmlhtml.html#cleaning-up-html Stefan From breamoreboy at yahoo.co.uk Sat Mar 1 09:54:43 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 01 Mar 2014 14:54:43 +0000 Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> Message-ID: On 01/03/2014 06:16, Mark H. Harris wrote: > On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: > >> How would you propose doing that? Bear in mind that while Python >> knows that tuples specifically are immutable, it doesn't generally >> know whether a type is immutable. > > > hi Ian, consider the problem... its a "cake" and "eat it too" scenario... you can't have your cake and eat it too.... > > This is what I mean... the error message is telling the user that it cannot do what he has requested, and yet IT DID. You have one of two scenarios: 1) the message is arbitrarily lying and it really can assign an immutable's item... (and it did!) or 2) It really should NOT assign an immutables item (the message is truth) but the action was "allowed" anyway despite the protocol and accepted policy... in which case the two scenarios add up to a giant logical inconsistency... QED a bug. > > There really is no way to get around this from the average user's perspective. And therefore, this is going to come up again and again and again... because coders don't like unexpected logical inconsistencies. > > It is not helpful either to explain it away by knowing how the policy works under the covers... the average user of the python language should not have to understand the policy of the underlying substructure... > > 1) either they can't assign the list item of an immutable tuple type (and the action is a flaw, say bug > > of > > 2) they really CAN set the immutable's list item type (which it did!) and the message is bogus. > > > Its one way or the other.... we can't have our cake and eat it too... this is (one way or the other) a bug. > > IMHO > would you please be kind enough to use plain English... your use of sentences like this... is starting to annoy me... you're also using google groups... it doesn't wrap paragraphs correctly... please read and action this https://wiki.python.org/moin/GoogleGroupsPython... it does wrap paragraphs correctly... it also prevents us seeing double line spacing... do you get my drift??? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From thrinaxodon at troll.thrinaxodon Sat Mar 1 09:50:08 2014 From: thrinaxodon at troll.thrinaxodon (THRINAXODON) Date: Sat, 01 Mar 2014 09:50:08 -0500 Subject: HUMANS HAVE ORIGINS IN THE DEVONIAN..... Message-ID: ================================ >BREAKING FUCKING NEWS, ASSHOLES! ================================ > THRINAXODON JUST FOUND THREE HUMAN FOSSILS FROM DEVONIAN STRATA IN GREENLAND; THE FOSSILS WERE A HUMAN FEMUR, KNEECAP, AND SKULLCAP. > THE SMITHSONIAN IS CHASTISING OVER THESE FINDS, DOING EVERYTHING IN THEIR POWER TO CENSOR THE TRUTH. > DONATE TO THE BIOLORD9 FOUNDATION TO FIND OUT HOW TO STOP THE SMITHSONIAN FROM CENSORING THE TRUTH, AND LET THE TRUTH THAT HUMAN EVOLUTION IS A SCAM BE REVEALED! > =========================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# ==================================== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON REDDIT -- ---Thrinaxodon From breamoreboy at yahoo.co.uk Sat Mar 1 10:15:13 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 01 Mar 2014 15:15:13 +0000 Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> Message-ID: On 01/03/2014 11:59, Chris Angelico wrote: > On Sat, Mar 1, 2014 at 10:28 PM, Marko Rauhamaa wrote: >> >> There really is no taboo against string object identity if you know what >> you are doing. > > And, as proven here in this thread, you do not know what you are doing. > Why do you think I admitted him onto my dream team some days ago? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From torriem at gmail.com Sat Mar 1 12:05:37 2014 From: torriem at gmail.com (Michael Torrie) Date: Sat, 01 Mar 2014 10:05:37 -0700 Subject: Can global variable be passed into Python function? In-Reply-To: <87k3ceqhti.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> Message-ID: <53121361.8000505@gmail.com> On 03/01/2014 04:28 AM, Marko Rauhamaa wrote: > Ben Finney : > >> Use ?==?, since that's all that matters for getting a value that will >> work fine. > > You are telling me to use '==' if I choose string objects and 'is' if I > choose some other objects. No, '==' works fine no matter what objects you assign to your state variables. class Foo(object): STATE1 = object() STATE2 = "testing" STATE3 = 2 def __init__(self): self.state = Foo.STATE1 def bar(self): if self.state == Foo.STATE1: pass elif self.state == Foo.STATE2: pass elif self.state == Foo.STATE3: pass > I prefer a solution that works regardless of what objects I choose for > identifiers. As shown, '==' does work for this too. I don't know which is more correct, but it does work. From steve+comp.lang.python at pearwood.info Sat Mar 1 12:07:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2014 17:07:16 GMT Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> Message-ID: <531213c4$0$29987$c3e8da3$5496439d@news.astraweb.com> On Sat, 01 Mar 2014 22:59:52 +1100, Chris Angelico wrote: > On Sat, Mar 1, 2014 at 10:28 PM, Marko Rauhamaa > wrote: >> Ben Finney : >> >>> Use ?==?, since that's all that matters for getting a value that will >>> work fine. >> >> You are telling me to use '==' if I choose string objects and 'is' if I >> choose some other objects. >> >> I prefer a solution that works regardless of what objects I choose for >> identifiers. >> >> There really is no taboo against string object identity if you know >> what you are doing. > > And, as proven here in this thread, you do not know what you are doing. Steady on, that's a bit harsh. In context, I think that Marko is assuming that the caller will only ever use the state values via their symbolic names, e.g. only refer to them as IDLE, CONNECTED etc. and never use their internal string values "IDLE", "CONNECTED". I don't think that's a safe assumption, since it requires the caller to only ever do the right thing, but if it is true, then using "is" in the way he suggests cannot fail. Still, I've repeatedly asked Marko to justify why we should care about the symbols being singletons, and unless I've missed something, he hasn't even attempted to justify that. It seems to me that he's just assuming that symbols ought to be singletons, hence his focus on identity rather than equality. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sat Mar 1 12:18:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2014 17:18:22 GMT Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> Message-ID: <5312165e$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sat, 01 Mar 2014 12:31:39 +0200, Marko Rauhamaa wrote: > I need *identifiers*. I could simply define: > > class ABC: > A = object() > B = object() > C = object() > > The program would work perfectly. > > Except, if it's got a bug. I know self.abc contains either A, B or C, > but which one? Printing out self.abc won't give me any help. I could > print out ABC.A, ABC.B and ABC.C and see which one matches, but that's > cumbersome. All very good so far. > The next variant is to use objects that have names: > > class Symbol: > def __init__(self, name): > self.name = name > def __str__(self): > return self.name > > class ABC: > A = Symbol("A") > B = Symbol("B") > C = Symbol("C") > > > The same program still works (and still uses "is" for identity tests, > mind you). But why are you using identity tests? Equality will work perfectly well, and won't expose the implementation detail that these objects may be singletons. That's especially important at the next step, when you replace the Symbol class with regular strings. If the caller happens to use "C" rather than ABC.C, why is this a problem? -- Steven D'Aprano http://import-that.dreamwidth.org/ From marko at pacujo.net Sat Mar 1 12:23:57 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Mar 2014 19:23:57 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> Message-ID: <87r46l96j6.fsf@elektro.pacujo.net> Ben Finney : > No. I'm telling you that ?is? is *wrong* for comparing strings, > because it is unreliable. No, it isn't as long as the string object references have a common assignment "pedigree." Assignment (including parameter passing) is guaranteed to preserve identity of any object. Marko From rosuav at gmail.com Sat Mar 1 12:27:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 04:27:28 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <531213c4$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <531213c4$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 2, 2014 at 4:07 AM, Steven D'Aprano wrote: > On Sat, 01 Mar 2014 22:59:52 +1100, Chris Angelico wrote: >> And, as proven here in this thread, you do not know what you are doing. > > Steady on, that's a bit harsh. In context, I think that Marko is assuming > that the caller will only ever use the state values via their symbolic > names, e.g. only refer to them as IDLE, CONNECTED etc. and never use > their internal string values "IDLE", "CONNECTED". A bit harsh, perhaps, but I stand by it: by repeatedly declaring that something is safe when it has been proven not safe, he shows that he does not know what he is doing - that he is not fully comprehending the significance of object value vs identity as regards strings. Incidentally, Python somewhat creates this issue, by sometimes interning and sometimes not. (And the same with small integers, although I've never heard the expression "int interning".) If strings were always interned, then it would be obvious that identity and value were one and the same. On the flip side, if a string literal always created a new string (that is, if it were more like a "string construction syntax" like square brackets for lists), then it would be obvious that each one is a separate object. I don't say either option is worth doing (especially the latter, O!), but by sometimes merging and sometimes not, Python does slightly blur the line between identity and value. (Obviously if strings were mutable, they'd *have* to have separate identities.) > I don't think that's a safe assumption, since it requires the caller to > only ever do the right thing, but if it is true, then using "is" in the > way he suggests cannot fail. If you're depending on the caller doing the right thing, it's still safe to use == rather than is. The only reason to use 'is' is to prevent the caller from stuffing in some other string that happens to be correct - hence his point about being able to change the keywords. If the caller stuffs in the string "INIT" instead of the object Foo.INIT, then "==" will happen to work until such time as Foo.INIT becomes "INITIALIZING", at which point it breaks. Preventing that means that unique object identity is crucial to the system working, and that's pretty much impossible with strings. (I don't say it's absolutely impossible; maybe if you intern some other string with the same value, and then construct the string you want out of pieces, and somehow prevent the compiler from figuring out what you're doing and optimizing it all away, then maybe you could have something that doesn't get reused anywhere else. But it's certainly not normal to be able to be sure of that.) ChrisA From marko at pacujo.net Sat Mar 1 12:29:41 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Mar 2014 19:29:41 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> Message-ID: <87mwh9969m.fsf@elektro.pacujo.net> Michael Torrie : > No, '==' works fine no matter what objects you assign to your state > variables. Well, it doesn't since >>> a = float("nan") >>> a is a True >>> a == a False More generally, it depends on how the __eq__ method has been implemented for the class. You might even (foolishly) define a class such that: >>> a == b False >>> a != b False The "is" operator is immune to such modality. Marko From rosuav at gmail.com Sat Mar 1 12:30:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 04:30:41 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <87r46l96j6.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87r46l96j6.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 2, 2014 at 4:23 AM, Marko Rauhamaa wrote: > Ben Finney : > >> No. I'm telling you that ?is? is *wrong* for comparing strings, >> because it is unreliable. > > No, it isn't as long as the string object references have a common > assignment "pedigree." Assignment (including parameter passing) is > guaranteed to preserve identity of any object. Of course it is, but your identity tests also depend on there NOT being a common object when there is NOT an "assignment pedigree". The positive is guaranteed; the negative is not. And if you don't care about a false positive - that is, that some other string with the same value matches - then what you actually want is equality, not identity, comparison. ChrisA From rosuav at gmail.com Sat Mar 1 12:36:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 04:36:29 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <87mwh9969m.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 2, 2014 at 4:29 AM, Marko Rauhamaa wrote: > You might even (foolishly) define a class such that: > > >>> a == b > False > >>> a != b > False Not necessarily even foolish; the SQL NULL value [1] behaves like that. ChrisA [1] Which isn't a value, except when it is From rvernucio at gmail.com Sat Mar 1 12:49:49 2014 From: rvernucio at gmail.com (Renato) Date: Sat, 1 Mar 2014 09:49:49 -0800 (PST) Subject: Password validation security issue Message-ID: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Hello everybody, I implemented a password validation with a Python 2.7.5 script in OpenSUSE 13.1. The user calls it passing 'login' and 'password' as arguments. I made a dictionary in the format hashtable = {'login':'password'} and I use this hash table to compare the 'login' and 'password' that were passed in order to validate them. The problem is that any user who can execute the script will be able to read it too (since it must be read by python's interpreter), and this is causing some security issues since any user can access all other users' passwords if he opens this script and reads the code. My question is: is there a way of preventing the user from reading the script's content? Is there any strategy I could use to hide the passwords from the users? From ned at nedbatchelder.com Sat Mar 1 12:56:24 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 01 Mar 2014 12:56:24 -0500 Subject: Tuples and immutability In-Reply-To: <2c38b941-9f3f-485f-9e97-525f28c5453a@googlegroups.com> References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <2ddad91d-e188-4fd0-be1c-ed30edbf280b@googlegroups.com> <2c38b941-9f3f-485f-9e97-525f28c5453a@googlegroups.com> Message-ID: On 3/1/14 12:50 AM, Mark H. Harris wrote: > On Friday, February 28, 2014 11:34:56 PM UTC-6, Ian wrote: > >> One very common example of tuples containing lists is when lists are >> passed to any function that accepts *args, because the extra arguments >> are passed in a tuple. A similarly common example is when returning >> multiple objects from a function, and one of them happens to be a >> list, because again they are returned in a tuple. > >> def f(*args): >> print(args) >> return (args[1:] >> >> >>> result = f(1, 2, 3, [4, 5]) >> (1, 2, 3, [4, 5]) >> >>> print(result) >> (2, 3, [4, 5]) > > I agree Ian... good points all. ... again, I'm not arguing with anyone... just saying that an error (whatever we mean by that) should not half-way-fail.... we are only pointing out the problem... we have not idea what the solution is yet. > > Intuitively everyone can see that there is a problem here... the debate cannot be answered either because of the inherent design of python (almost all of which we love). So, as they say, what is a mother to do? ... I mean, some people's kids... > > I don't know how I propose to handle the problem... I think the first step is getting everyone to agree that there IS a problem... then debate how to tackle the solution proposals. > > marcus > Everyone can agree that it is not great to raise an exception and also leave the list modified. But I very much doubt that anything will be done to change the situation. All of the solutions are too extreme, and bring their own infelicities, and the actual problems caused by this scenario are vanishingly small. BTW: I also am mystified why you uses ellipses to end your sentences, surely one period would be enough? :) -- Ned Batchelder, http://nedbatchelder.com From susanaldridge555 at gmail.com Sat Mar 1 13:03:25 2014 From: susanaldridge555 at gmail.com (Susan Aldridge) Date: Sat, 1 Mar 2014 10:03:25 -0800 (PST) Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: <233865a4-cd75-4466-811b-d3cb644c279c@googlegroups.com> Try this def guess1(upLimit = 100): import random num = random.randint(1,upLimit) count = 0 gotIt = False while (not gotIt): print('Guess a number between 1 and', upLimit, ':') guess= int(input()) count += 1 if guess == num: print('Congrats! You win') gotIt = True elif guess < num: print('Go up!') else: print('Guess less') print('You got it in ', count, 'guesses.') guess1(100) From torriem at gmail.com Sat Mar 1 13:06:54 2014 From: torriem at gmail.com (Michael Torrie) Date: Sat, 01 Mar 2014 11:06:54 -0700 Subject: Can global variable be passed into Python function? In-Reply-To: <87mwh9969m.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> Message-ID: <531221BE.1000504@gmail.com> On 03/01/2014 10:29 AM, Marko Rauhamaa wrote: > Michael Torrie : > >> No, '==' works fine no matter what objects you assign to your state >> variables. > > Well, it doesn't since > > >>> a = float("nan") > >>> a is a > True > >>> a == a > False > > More generally, it depends on how the __eq__ method has been implemented > for the class. You might even (foolishly) define a class such that: > > >>> a == b > False > >>> a != b > False Yes, good point. From rosuav at gmail.com Sat Mar 1 13:11:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 05:11:59 +1100 Subject: Password validation security issue In-Reply-To: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 4:49 AM, Renato wrote: > Hello everybody, I implemented a password validation with a Python 2.7.5 script in OpenSUSE 13.1. The user calls it passing 'login' and 'password' as arguments. I made a dictionary in the format hashtable = {'login':'password'} and I use this hash table to compare the 'login' and 'password' that were passed in order to validate them. The problem is that any user who can execute the script will be able to read it too (since it must be read by python's interpreter), and this is causing some security issues since any user can access all other users' passwords if he opens this script and reads the code. > > My question is: is there a way of preventing the user from reading the script's content? Is there any strategy I could use to hide the passwords from the users? > Yeah, that's a pretty major issue, right there :) The most common way to deal with this is to salt and hash your passwords. While that might sound like a great thing to do to potatoes, it's also the best way to stop your passwords from being sniffed. Best practice is to combine the password with the user name and with some fixed text (the "salt"), and then run it through a cryptographically secure hashing algorithm. In Python 2.7, you have the hashlib module: >>> import hashlib >>> login = 'rosuav' >>> password = 'xkcd936passwordgoeshere' >>> encrypted = hashlib.sha256(login+'NaCl protects your passwords'+password).hexdigest() >>> encrypted 'b329f2674af4d8d873e264d23713ace4505c211410eb46779c27e02d5a50466c' Then all you store is that encrypted password. When the user enters the login and password, you do the same operation, and compare it with the stored hash; if they're the same, you accept the credentials. The reason for including two pieces of salt (a constant and the user's login) is that it ensures that duplicate passwords don't have identical hashes, and that your set of password hashes are unique to you (so someone can't have a "standard set of password hashes"). So put some other string in between the two (or somewhere else in the string - it doesn't matter how you put the pieces together, as long as you're consistent). Also, as hinted in the example above, encourage everyone to use XKCD 936 compliant passwords. http://xkcd.com/936/ This is not a joke, this is not trivial. Using this scheme, you make passwords that are orders of magnitude stronger than the classic "minimum 8 characters, must include uppercase, lowercase, digit, symbol". If that gives a theoretical 80 character corpus, then it's insisting on a theoretical 50 bits of entropy (but, as the XKCD above shows, it's more likely to be roughly half that); you can get pretty much the same by using four common words at an estimated 11 bits per word, which assumes you use a pool of just two thousand words. If your pool's larger (if you use one or two less common words), you could be looking at a corpus of 65536 words (my /usr/share/dict/words has more than that), which would give you 64 bits of entropy from four words. Bank style passwords are *weak*. Long passwords are strong. So with truly strong passwords, and a hashing system that means an attacker has to brute-force every possible password to figure out how to get in, you can be confident that it's safe. But don't be naive; still do your best to protect the password hashes from scrying eyes - on Unix, you may be able to use a setuid binary to bounce into your script, which could then be owned by and readable only by some other user. Or, depending on how permissions are set up, you could arrange it so any user may run 'sudo /usr/local/bin/yourscript.py', which would then be freely able to read from a root-owned file of passwords. But at this point, we're outside of Python code and into Unix security, which is quite a different topic. ChrisA From marko at pacujo.net Sat Mar 1 13:25:51 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 01 Mar 2014 20:25:51 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <531213c4$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87iorx93o0.fsf@elektro.pacujo.net> Steven D'Aprano : > It seems to me that he's just assuming that symbols ought to be > singletons, hence his focus on identity rather than equality. Yes. A practical angle is this: if I used strings as symbols and compared them with "==", logically I shouldn't define them as constants but simply use strings everywhere: class Connection: def __init__(self): self.state = "IDLE" def connect(self, address): if self.state == "IDLE": ... elif self.state == ... The principal (practical) problem with that is that I might make a typo and write: if self.state == "IDLE ": which could result in some hard-to-find problems. That's why I want get the help of the Python compiler and always refer to the states through symbolic constants: if self.state == self.IDLE: Marko From christian at python.org Sat Mar 1 13:31:10 2014 From: christian at python.org (Christian Heimes) Date: Sat, 01 Mar 2014 19:31:10 +0100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On 01.03.2014 19:11, Chris Angelico wrote: > On Sun, Mar 2, 2014 at 4:49 AM, Renato wrote: >> Hello everybody, I implemented a password validation with a Python 2.7.5 script in OpenSUSE 13.1. The user calls it passing 'login' and 'password' as arguments. I made a dictionary in the format hashtable = {'login':'password'} and I use this hash table to compare the 'login' and 'password' that were passed in order to validate them. The problem is that any user who can execute the script will be able to read it too (since it must be read by python's interpreter), and this is causing some security issues since any user can access all other users' passwords if he opens this script and reads the code. >> >> My question is: is there a way of preventing the user from reading the script's content? Is there any strategy I could use to hide the passwords from the users? >> > > Yeah, that's a pretty major issue, right there :) > > The most common way to deal with this is to salt and hash your > passwords. While that might sound like a great thing to do to > potatoes, it's also the best way to stop your passwords from being > sniffed. > > Best practice is to combine the password with the user name and with > some fixed text (the "salt"), and then run it through a > cryptographically secure hashing algorithm. In Python 2.7, you have > the hashlib module: > >>>> import hashlib >>>> login = 'rosuav' >>>> password = 'xkcd936passwordgoeshere' >>>> encrypted = hashlib.sha256(login+'NaCl protects your passwords'+password).hexdigest() >>>> encrypted > 'b329f2674af4d8d873e264d23713ace4505c211410eb46779c27e02d5a50466c' Please don't do that. It's insecure and not the proper way to handle passwords. In fact it's insecure on so many levels that I don't know where to start... A hash function and a fixed salt are always the wrong way to handle passwords. You must use a non-deterministic key stretching and key derivation function with a salt from a CPRNG. For example PBKDF2 (usually used with HMAC as PRF), bcrypt or scrypt are well studied and tune-able KDFs. You must also use a constant timing comparison function. You don't have to do all the hard stuff on your own. I highly recommend `passlib` to handle your passwords. It has a good API and is secure. Christian From python.list at tim.thechases.com Sat Mar 1 13:38:25 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 1 Mar 2014 12:38:25 -0600 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: <20140301123825.2c2dd24e@bigbox.christie.dr> On 2014-03-02 05:11, Chris Angelico wrote: > On Sun, Mar 2, 2014 at 4:49 AM, Renato wrote: > > My question is: is there a way of preventing the user from > > reading the script's content? Not really. It might be a bit obfuscated, but >> Is there any strategy I could use to hide the passwords from the >> users? use Chris's suggestion about hashing. That said, if the user has access to the source code, there's nothing preventing them from changing if hash(provided_password) == existing_hash: do_magic() into just if True: do_magic() and re-running the program. -tkc From rosuav at gmail.com Sat Mar 1 13:43:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 05:43:33 +1100 Subject: Password validation security issue In-Reply-To: <20140301123825.2c2dd24e@bigbox.christie.dr> References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <20140301123825.2c2dd24e@bigbox.christie.dr> Message-ID: On Sun, Mar 2, 2014 at 5:38 AM, Tim Chase wrote: > That said, if the user has access to the source code, there's nothing > preventing them from changing > > if hash(provided_password) == existing_hash: > do_magic() > > into just > > if True: > do_magic() > > and re-running the program. They don't necessarily have to have the ability to edit the file. Based on the original description, the problem is that if Python running as that user can read the file (to run it), then so can anything else running as that user. Python doesn't need to be able to change the file. ChrisA From rosuav at gmail.com Sat Mar 1 13:45:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 05:45:08 +1100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 5:31 AM, Christian Heimes wrote: >>>>> encrypted = hashlib.sha256(login+'NaCl protects your passwords'+password).hexdigest() >>>>> encrypted >> 'b329f2674af4d8d873e264d23713ace4505c211410eb46779c27e02d5a50466c' > > Please don't do that. It's insecure and not the proper way to handle > passwords. In fact it's insecure on so many levels that I don't know > where to start... Please do start. This is an extremely common practice; are you able, from just the information above, to figure out the password using anything better than brute force? ChrisA From oscar.j.benjamin at gmail.com Sat Mar 1 13:55:53 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 1 Mar 2014 18:55:53 +0000 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On 27 February 2014 21:47, Nick Timkovich wrote: > On Thu, Feb 27, 2014 at 10:33 AM, Chris Angelico wrote: >> >> It's unintuitive, but it's a consequence of the way += is defined. If >> you don't want assignment, don't use assignment :) > > Where is `.__iadd__()` called outside of `list += X`? Numpy uses it for in-place operations with numpy arrays: >>> import numpy >>> a = numpy.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> a[::2] += 10 >>> a array([10, 1, 12, 3, 14, 5, 16, 7, 18, 9]) It makes sense for any mutable type that supports +. The stdlib doesn't have many of these. The obvious one is list but there's also MutableString (in 2.x): >>> from UserString import MutableString >>> a = MutableString("qwe") >>> a 'qwe' >>> b = a >>> b += "asd" >>> a 'qweasd' > If the only difference from `.extend()` is that it returns `self`, but the list was > already modified anyway, why bother with reassignment? I don't know of any situation where __iadd__ is defined but doesn't return self and I can't think of a use case apart from operator abuse. I had thought that the other difference was that .extend would accept any iterable but it seems += does also. Perhaps that was changed at some point. >>> l = [1, 2, 3] >>> l + (1, 2, 3) Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate list (not "tuple") to list >>> l += (1, 2, 3) >>> l [1, 2, 3, 1, 2, 3] Oscar From geniusrko at gmail.com Sat Mar 1 14:12:32 2014 From: geniusrko at gmail.com (geniusrko at gmail.com) Date: Sat, 1 Mar 2014 11:12:32 -0800 (PST) Subject: Boxes of O's Message-ID: Hi Can anyone help with this problem Create a big box out of n rows of little o's for any desired size n. Use an input statement to allow the user to enter the value for n and then print the properly sized box. E.g. n = 3 oooooo o o oooooo E.g. n = 8 oooooooooooooooo o o o o o o o o o o o o oooooooooooooooo using only loops Thanks From rosuav at gmail.com Sat Mar 1 14:16:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 06:16:37 +1100 Subject: Boxes of O's In-Reply-To: References: Message-ID: On Sun, Mar 2, 2014 at 6:12 AM, wrote: > Create a big box out of n rows of little o's for any desired size n. Use an input statement to allow the user to enter the value for n and then print the properly sized box. How far have you gotten so far with your homework? Show us some code and we can help you debug it. ChrisA From geniusrko at gmail.com Sat Mar 1 14:28:37 2014 From: geniusrko at gmail.com (geniusrko at gmail.com) Date: Sat, 1 Mar 2014 11:28:37 -0800 (PST) Subject: Boxes of O's In-Reply-To: References: Message-ID: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> Well, This is what i got n = int(input("enter number of o: ")) for i in range(n): print("O", end = '') for j in range(n* 2): print("O", end = '') print() From python at mrabarnett.plus.com Sat Mar 1 14:41:30 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 01 Mar 2014 19:41:30 +0000 Subject: Boxes of O's In-Reply-To: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> References: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> Message-ID: <531237EA.6050704@mrabarnett.plus.com> On 2014-03-01 19:28, geniusrko at gmail.com wrote: > Well, This is what i got > > n = int(input("enter number of o: ")) > > for i in range(n): > print("O", end = '') > for j in range(n* 2): > print("O", end = '') > > print() > From the examples: The first row has n*2 of 'o' There are n-2 middle rows, each with 'o', then n*2-2 spaces, then 'o' The last row has n*2 of 'o' Incidentally, in your code you're writing 'O', not 'o'. From ian.g.kelly at gmail.com Sat Mar 1 14:45:55 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 1 Mar 2014 12:45:55 -0700 Subject: Tuples and immutability In-Reply-To: <9ee137b0-3313-41c6-9792-9438ff05038a@googlegroups.com> References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <9ee137b0-3313-41c6-9792-9438ff05038a@googlegroups.com> Message-ID: On Fri, Feb 28, 2014 at 11:25 PM, Mark H. Harris wrote: > On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: > >> How would you propose doing that? Bear in mind that while Python >> knows that tuples specifically are immutable, it doesn't generally >> know whether a type is immutable. > > I was going to bed, and then thought of the solution. Allow the action. > > Hold the error pending until the action either succeeds or fails for the "item," in this case a list, and then post the error for the tuple depending... this would make the whole mess consistent, and even compatible with the idea of dynamic name and type binding... > > So, in other words, the action should be permitted, and actually was allowed, and the message is incorrectly reporting something that for this particular "item" is NOT true. The error message (and timing of same) is the bug (philosophically). > > Under the covers it may be (and probably is) more complicated. Indeed. For one thing, __iadd__ is not required to return the object it was called on; it could return some other object. Imagine a balanced binary tree that is stored by referencing the root node object (whether this is good design is tangential; it's a possible design). If the __iadd__ operator is implemented to insert a node, and it causes the root node to change, then it might return that new root node, expecting it to be assigned. If Python simply ignores the exception from the assignment, then the data structure has been modified in-place, but the tuple does not contain the correct object, and worst of all no exception has been raised to alert anybody of this failure condition. So at best you could only ignore these exceptions when the object returned by __iadd__ is self, which to be fair is probably most of the time. Additionally, recall my statement up-thread that "If you skip the assignment, and that assignment is meaningful to whatever the left side may be (e.g. assigning to a descriptor or something that invokes __setitem__ or __setattr__), then the operation is not equivalent." If you quash the exception from the assignment because the __iadd__ call succeeded, then you have effectively skipped the assignment and then lied to the programmer about it. For example, imagine a list subclass that contains other lists but only permits itself to be nested 1-deep; the contained lists are required to be flat. The __setitem__ method for the class might enforce the constraint and perhaps also update a count of the total combined length of the nested lists. Then suppose we have this code: lol = ListOfLists([1,2,3], [4], [6, 7, 8, 9]) lol[1] += [5, [5.25, 5.5, 5.75]] The effect of this is that the middle sublist has been extended to include a doubly-nested list. __setitem__ was then called, which noticed that the list it was passed includes another nested list, so it raised an exception instead of performing the assignment and updating the count. The ListOfLists is now in an invalid state, but if Python swallows the exception raised by __setitem__, then there is nothing to warn the programmer of this (until something else mysteriously fails to process the ListOfLists later on). The result is code that is hard to debug. Now, we might notice that the above code would probably not raise a TypeError, which is the exception we would expect if trying to mutate an immutable object, so we might revise the rule again: we only silence the exception if __iadd__ returns self and the exception is a TypeError. But even then, we have no guarantee that this is what the TypeError was meant to convey. A TypeError may have simply propagated up from other buggy code that was indirectly called by __setitem__, a legitimate error that should be brought to the programmer's attention. tldr: Swallowing exceptions is a risky practice unless you're quite sure that you know where the exception is coming from and that it's safe to ignore, and the language runtime should practically never do this. From rosuav at gmail.com Sat Mar 1 14:54:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 06:54:23 +1100 Subject: Boxes of O's In-Reply-To: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> References: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 6:28 AM, wrote: > Well, This is what i got > > n = int(input("enter number of o: ")) > > for i in range(n): > print("O", end = '') > for j in range(n* 2): > print("O", end = '') > > print() Okay! Good. Now, presumably this isn't working yet, or you wouldn't be asking. So we just need the other crucial part of the puzzle: What is it doing wrong? That might be an exception (copy and paste it all, including the full traceback), or it might be producing the wrong output, or maybe it produces the right output on everything except some specific input. I'll level with you here. We do not want to do your homework for you, and we do not want anyone else to do your homework. When you're asked to write code like this, it's not because the teacher/tutor wants the code written - it's because you need to learn what you're doing. Having someone else hand you perfectly working code defeats that purpose, and it will tend to produce a sort of faux comprehension that results in you getting a certificate and a job, while being still quite incompetent as a programmer. Now, you may protest that it's not as bad as that (and you'd probably be right - you have produced some partially-working code there), but that's the extreme, and going even part-way down that path is a Bad Thing. We, as programmers, would hate to be coworkers to someone who glided through some course by getting someone else to do the work; we do not want to have to try to work with that sort of person. (Digression: I have, and quite a few of us here probably have, worked with exactly such a person. In my case, eventually even the boss/owner figured out that he was a rubbish programmer; when we eventually dug into his code thoroughly, we threw out the whole lot and literally started over with a blank file. But before that, we found gems like this PHP code - by the way, it *is* possible to write good PHP code, even though the language is itself pretty appalling, but this... isn't proof of that. $step = 1; do { switch ($step) { case 1: .... code code code .... break; case 2: .... code code code .... break; default: ... raise an error .... } } while (++$step<2); This code was supposed to verify certain requirements on an incoming HTTP request. What you may not notice - and I didn't notice when I saw this and decided to simplify the code - is that this is NOT the for-switch paradigm, it's something even worse: a for-switch with an off-by-one, so the only code actually executed is the "case 1" block. And since we had properly working code in our client, none of the errors that the "case 2" block was supposed to catch ever actually got triggered, so we didn't see a problem... until I cleaned up the code, and discovered that "case 2" had bugs in it. This is what happens when you have incompetent people writing code. This is why we are strongly disinclined to give you the answers. End digression.) However, while we won't just give you the answers, we *will* gladly help you to understand what's going on. So if you post code and output (maybe an error) and ask a specific question, preferably one that shows some level of comprehension, we will cheerfully put in quite a bit of time to help you understand the error message, or learn how to decipher Python tracebacks, or whatever. Helping you to understand things makes you a better programmer, and by extension improves the world's total programming skill; giving you the answers makes you no better and possibly worse (by encouraging laziness), and so we don't want to do it. So, there you have it. Don't be a bad programmer. :) You'll find more handy tips here - it's an invaluable resource: http://www.catb.org/~esr/faqs/smart-questions.html ChrisA From christian at python.org Sat Mar 1 14:54:24 2014 From: christian at python.org (Christian Heimes) Date: Sat, 01 Mar 2014 20:54:24 +0100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On 01.03.2014 19:45, Chris Angelico wrote: > On Sun, Mar 2, 2014 at 5:31 AM, Christian Heimes wrote: >>>>>> encrypted = hashlib.sha256(login+'NaCl protects your passwords'+password).hexdigest() >>>>>> encrypted >>> 'b329f2674af4d8d873e264d23713ace4505c211410eb46779c27e02d5a50466c' >> >> Please don't do that. It's insecure and not the proper way to handle >> passwords. In fact it's insecure on so many levels that I don't know >> where to start... > > Please do start. This is an extremely common practice; are you able, > from just the information above, to figure out the password using > anything better than brute force? I'm aware that it's still a common technique. It makes me sad everytime I see code that uses SHA256 for password hashing. :( Why haven't people learnt from mistakes like LinkedIn's and Adobe's password disaster? Yes, for most applications brute force is still the best option to crack the password. Passwords are usually rather short, have a low entropy and modern hardware is insanely fast. With software like [1] and a fast GPU it is possible to do more than 10*10^9 checks/second for SHA-256. Clever and very capable people have come up with algorithms like [2] to make it much harder to crack passwords. The Wikipedia articles on KDF and KSA explain both algorithm much better than I could. The PHC [3] is a recent attempt to come up with an even more secure algorithm. Please don't implement PBKDF2 on your own. Django, several other Python libraries and OpenSSL did and made a really bad error that lead to a DoS vulnerability. Christian [1] http://hashcat.net/oclhashcat/ [2] http://en.wikipedia.org/wiki/Key_derivation_function [3] https://password-hashing.net/ From shiblydu60 at yahoo.com Sat Mar 1 13:10:58 2014 From: shiblydu60 at yahoo.com (Golam Md. Shibly) Date: Sat, 1 Mar 2014 10:10:58 -0800 (PST) Subject: How to extract contents of inner text of html tag? Message-ID: <1393697458.5147.YahooMailNeo@web126004.mail.ne1.yahoo.com> Hi, ###in.txt cp -v --remove-destination /usr/share/zoneinfo/ \ /etc/localtime import sys import unicodedata from bs4 import BeautifulSoup file_name="in.txt" html_doc=open(file_name,'r') soup=BeautifulSoup(html_doc) #print soup.prettify().encode('utf-8') #file_to_write.writelines( soup.prettify().encode() ) all_kbd=soup.find_all('kbd') for line in all_kbd: if line.string == None: extract_code=line.code.extract().string #store_code=line.code.decompose() for inside_line in line: if "<<" not in inside_line and "EOF" not in inside_line: if len(inside_line)>0: print inside_line print extract_code expected output: cp -v --remove-destination /usr/share/zoneinfo/\ /etc/localtime Got output: cp -v --remove-destination /usr/share/zoneinfo/ None \ /etc/localtime None shibly -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Mar 1 15:11:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 07:11:49 +1100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 6:54 AM, Christian Heimes wrote: > Yes, for most applications brute force is still the best option to crack > the password. Passwords are usually rather short, have a low entropy and > modern hardware is insanely fast. With software like [1] and a fast GPU > it is possible to do more than 10*10^9 checks/second for SHA-256. Using XKCD 936's estimate, 44 bits of entropy would still require 17592 seconds of processing at 10^9 per second. That's not a lot if someone's personally targeting you *and* they know you use XKCD 936 *and* know the exact set of 2048 words that you drew your password from *and* they know how you lay them out (spaces between, no spaces, whether or not you capitalize the words, etc etc). Not knowing any of these would add a few more bits of entropy; and if you use /usr/share/dict/words and take only those words which consist entirely of lower-case letters, then your corpus is over 65536 words [1], so you have 64 bits of entropy. Even at 10^10 checks/second (which is what 10*10^9 is, but that's an odd way to write it), that would be 21350 *days* of dedicated processing, just to crack the one password. If cracking my password, and mine alone, in sixty years, is considered "insanely fast", then I'm going to keep using SHA-256 for a while. The problem isn't SHA-256. The problem is insecure passwords, the way we've been taught to make them by the banks. Hence, XKCD 936. ChrisA [1] On my Debian Wheezy system: $ grep -c '^[a-z]*$' /usr/share/dict/words 72861 From harrismh777 at gmail.com Sat Mar 1 16:01:41 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 13:01:41 -0800 (PST) Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> Message-ID: <3ad31471-26ea-401d-a860-3604cf0e55b7@googlegroups.com> On Saturday, March 1, 2014 8:54:43 AM UTC-6, Mark Lawrence wrote: > you're also using google groups... it doesn't wrap paragraphs > > correctly... please read and action this > > https://wiki.python.org/moin/GoogleGroupsPython... it does wrap > > paragraphs correctly... it also prevents us seeing double line spacing... > > > > do you get my drift??? > hi Mark, yes, I understand. I am using google groups (for the moment) and it does not wrap correctly, at least not on my end. It also adds additional carrots > that make replying difficult. The elipses thing is a bad habit which I 'picked up' in academia lately. We use elipses frequently in papers (also this---which also annoys people) and there is no problem. In a writing context the elipses seem to function for some people (intentionally) as 'um'. When humans speak they use the word 'um' to pause between though context and its usually unintentional at the surface. Often when I write the elipses (...) show up for the same reason. I really don't know that I'm doing it... it just happens. So, I am working on it. No, you're not the first to mention it. Its one of my many flaws. Thanks for keeping me accountable. Enjoy the day! marcus From breamoreboy at yahoo.co.uk Sat Mar 1 16:20:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 01 Mar 2014 21:20:10 +0000 Subject: Can tuples be replaced with lists all the time? In-Reply-To: References: <64af70e3-6876-4fbf-8386-330d2f48735a@googlegroups.com> Message-ID: On 23/02/2014 17:48, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> In constrast, tuples are often used as fixed-length heterogenous >> containers (more like a struct in C except the fields are named 0, 1, >> 2, 3, etc.). In a particular context, the Nth element of a tuple will >> always mean one thing (e.g. a person's last name) while the Mth >> element will always be something else (e.g. a person's age). > > And, of course, namedtuples make that much more explicit. > > It also appears that tuples are more memory efficient. I just ran some > quick tests on my OSX box. Creating a list of 10 million [1, 2, 3, 4, > 5] lists gave me a 1445 MB process. The name number of (1, 2, 3, 4, 5) > tuples was 748 MB. I'm sure this is implementation dependent, but it > seems plausible to assume similar results will be had on other > implementations. > In CPython a list is overallocated so there's usually spare slots available if you want to add something to it. In contrast you know when you create the tuple just how big it is so no overallocation is needed. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Sat Mar 1 16:21:44 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 13:21:44 -0800 (PST) Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> Message-ID: <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: > How would you propose doing that? Bear in mind that while Python > knows that tuples specifically are immutable, it doesn't generally > know whether a type is immutable. hi Ian, I thought of something else after I slept on it, so to speak. Consider this: >>> s=(2,3,[42,43,44],7) >>> s[2] [42, 43, 44] >>> s[2] is a list. We should be able to change s[2] even though its within a tuple, like the: [42, 43, 44] >>> s[2].append(45) >>> s[2] [42, 43, 44, 45] <===== no error >>> or like this: >>> s[2] [42, 43, 44, 45] >>> s[2]=s[2]+[46] Traceback (most recent call last): File "", line 1, in s[2]=s[2]+[46] <==========error, but look below====== TypeError: 'tuple' object does not support item assignment >>> >>> s[2] [42, 43, 44, 45] <=========also no change to list !! >>> The point I'm trying to make with this post is that s[2]+=[46] and s[2]=s[2]+[46] are handled inconsistently. In each case (whether the list is part of a tuple or not) s[2] is a valid list and should be mutable. In every case, in fact, it is. In each case, in fact, the change might occur. But, the change occurs in the first case (append) without an error. The change occurs in the next case too (+=) but with an error not related to the tuple. The change does not occur in the third case (s=s+ with an error) but the list is not changed ! We all know this is not good. We also all know that its because of implementation details the user/coder should not need to know. QED: a bug. Having slept on it, I am remembering my Zen of Python: Errors should never pass silently, unless explicitly silenced. It looks to me like (+=) in this case is not being handled correctly under the covers. At any rate the three scenarios of trying to change a mutable list as an immutable tuple item should be handled consistently. Either we can change the tuple item (if its a list) or we can't. Also, if we cannot then the expected error should be consistent. Wow. I think I got that whole thing out without one elipses. Cheers From roy at panix.com Sat Mar 1 13:30:06 2014 From: roy at panix.com (Roy Smith) Date: Sat, 01 Mar 2014 13:30:06 -0500 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> Message-ID: In article <87mwh9969m.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > Michael Torrie : > > > No, '==' works fine no matter what objects you assign to your state > > variables. > > Well, it doesn't since > > >>> a = float("nan") > >>> a is a > True > >>> a == a > False > > More generally, it depends on how the __eq__ method has been implemented > for the class. You might even (foolishly) define a class such that: > > >>> a == b > False > >>> a != b > False Well, there's always things like SQL's NULL, which is both not equal and not not equal to itself. From roy at panix.com Sat Mar 1 15:25:47 2014 From: roy at panix.com (Roy Smith) Date: Sat, 01 Mar 2014 15:25:47 -0500 Subject: Password validation security issue References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: In article , Christian Heimes wrote: > With software like [1] and a fast GPU > it is possible to do more than 10*10^9 checks/second for SHA-256. Just out of curiosity, how does that differ from 10^10 checks/second? From harrismh777 at gmail.com Sat Mar 1 16:40:20 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 13:40:20 -0800 (PST) Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> Message-ID: On Saturday, March 1, 2014 12:24:15 AM UTC-6, Chris Angelico wrote: > much code. If you want to change anything, you potentially have to > > edit three places: the list of constants at the top, the condition > > function, and the switch. > > > > This can't be your idea of readability. Show me where I'm wrong. > > > > ChrisA hi Chris, I don't think you're wrong. There are two issues for me (and one of them is not how the switch is implemented). 1) Is it easier for average users of python as a language to read switch case default, or if elif else ? 2) Would most average users concur that 'readable' means something like, "readily understandable at quick glance, or rapid preview" (or quiv). I readily admit that 'subjective' is the operative work here. As Guido found at his 2007 keynote most experienced devs are not clamoring for a switch block. Just so. But I'm not thinking of experienced devs. I'm thinking of the average coder who is used to looking at switch blocks. I personally can see and understand a switch block 2x to 3x faster than looking at an elif chain. Because I am primarily a C programmer and I personally use and read switch blocks. An experienced python dev can readily 'see' an elif chain, well, because that's all they have and that's all they look at day to day. So, naturally a python dev is going to think an elif chain is readable. Thank you sir, you have good insights. A quote from the high seas is classy. (another post with no elipses) Cheers From breamoreboy at yahoo.co.uk Sat Mar 1 17:01:12 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 01 Mar 2014 22:01:12 +0000 Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> Message-ID: On 01/03/2014 21:40, Mark H. Harris wrote: > On Saturday, March 1, 2014 12:24:15 AM UTC-6, Chris Angelico wrote: >> much code. If you want to change anything, you potentially have to >> >> edit three places: the list of constants at the top, the condition >> >> function, and the switch. >> >> >> >> This can't be your idea of readability. Show me where I'm wrong. >> >> >> >> ChrisA > > hi Chris, I don't think you're wrong. There are two issues for me (and one of them is not how the switch is implemented). > > 1) Is it easier for average users of python as a language to read switch case default, or if elif else ? > > 2) Would most average users concur that 'readable' means something like, "readily understandable at quick glance, or rapid preview" (or quiv). > > I readily admit that 'subjective' is the operative work here. As Guido found at his 2007 keynote most experienced devs are not clamoring for a switch block. Just so. But I'm not thinking of experienced devs. I'm thinking of the average coder who is used to looking at switch blocks. > > I personally can see and understand a switch block 2x to 3x faster than looking at an elif chain. Because I am primarily a C programmer and I personally use and read switch blocks. > > An experienced python dev can readily 'see' an elif chain, well, because that's all they have and that's all they look at day to day. So, naturally a python dev is going to think an elif chain is readable. > > Thank you sir, you have good insights. A quote from the high seas is classy. > > (another post with no elipses) > > Cheers > No elipses, just the paragraphs not wrapped and the double line spacing. Good old gg, I just love it. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From gheskett at wdtv.com Sat Mar 1 16:55:11 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Sat, 1 Mar 2014 16:55:11 -0500 Subject: posting code snippets In-Reply-To: References: Message-ID: <201403011655.11405.gheskett@wdtv.com> On Saturday 01 March 2014 16:52:44 Grant Edwards did opine: > On 2014-02-28, Chris Angelico wrote: > > The problem does have to believe that the rubber duck/teddy > > bear/figurine is an expert, though. I've had my siblings or parents > > come to me with problems and, without saying a word or touching the > > computer or anything, I've solved them. The problem itself respects > > my skill, and retracts its objection and solves itself. > > The same thing works with expensive/complex test equipment instead of > an expert. > > You drag out the lab scope, logic analyzer, spectrum analyzer, sweep > generator, strip plotter, and the machine that goes "ping". You start > to get everything set up to nail that problem securely to the > dissecting board. Long before you actually get to that point, the > problem becomes intimidated and reveals itself and a solution. Chuckle ;-) Is there not a Murphy's Law corollary on that, Grant? I have certainly been there and done that enough times to know its 100% true. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page NOTICE: Will pay 100 USD for an HP-4815A defective but complete probe assembly. From christian at python.org Sat Mar 1 17:07:24 2014 From: christian at python.org (Christian Heimes) Date: Sat, 01 Mar 2014 23:07:24 +0100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On 01.03.2014 21:25, Roy Smith wrote: > In article , > Christian Heimes wrote: > >> With software like [1] and a fast GPU >> it is possible to do more than 10*10^9 checks/second for SHA-256. > > Just out of curiosity, how does that differ from 10^10 checks/second? I find 10 * 10^9 easier to read because it has more resemblance to "10 billion". Next time I'll use the normalized scientific form 1.0e10. ;) From harrismh777 at gmail.com Sat Mar 1 17:07:37 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 14:07:37 -0800 (PST) Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> Message-ID: On Saturday, March 1, 2014 4:01:12 PM UTC-6, Mark Lawrence wrote: > > No elipses, just the paragraphs not wrapped and the double line spacing. > > Good old gg, I just love it. How do I fix it? Is there a setting someplace? I tried pulling up the page you linked, but blank. Thanks in advance. From rosuav at gmail.com Sat Mar 1 17:11:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 09:11:21 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 8:40 AM, Mark H. Harris wrote: > hi Chris, I don't think you're wrong. There are two issues for me (and one of them is not how the switch is implemented). > > 1) Is it easier for average users of python as a language to read switch case default, or if elif else ? > > I personally can see and understand a switch block 2x to 3x faster than looking at an elif chain. Because I am primarily a C programmer and I personally use and read switch blocks. Sure. But before you can ask us to consider how readable it is, we need to have comparisons. Mock up a switch statement equivalent and show us how it'd be better. I just looked at your version, and couldn't see any way that it would be an improvement, because it required that there be the exact same if/elif chain to figure out what to switch on. So give us your readable version, in an exact reimplementation of the if/elif chain, so we can see exactly how it would go. ChrisA From rosuav at gmail.com Sat Mar 1 17:13:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 09:13:25 +1100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 9:07 AM, Christian Heimes wrote: > On 01.03.2014 21:25, Roy Smith wrote: >> In article , >> Christian Heimes wrote: >> >>> With software like [1] and a fast GPU >>> it is possible to do more than 10*10^9 checks/second for SHA-256. >> >> Just out of curiosity, how does that differ from 10^10 checks/second? > > > I find 10 * 10^9 easier to read because it has more resemblance to "10 > billion". Next time I'll use the normalized scientific form 1.0e10. ;) I wasn't sure if it ought to have been 10^9 or 10^10. In any case, that makes only one order of magnitude of difference, and based on the way I generate passwords, that still leaves it at 60-ish years of GPU spinning. (It'd be 600 years at 10^9.) ChrisA From rosuav at gmail.com Sat Mar 1 17:16:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 09:16:35 +1100 Subject: posting code snippets In-Reply-To: References: <85ppm8nqx7.fsf@benfinney.id.au> Message-ID: On Sat, Mar 1, 2014 at 1:31 AM, Grant Edwards wrote: > You drag out the lab scope, logic analyzer, spectrum analyzer, sweep > generator, strip plotter, and the machine that goes "ping". You start > to get everything set up to nail that problem securely to the > dissecting board. Long before you actually get to that point, the > problem becomes intimidated and reveals itself and a solution. *ALL* my machines go ping. It's fundamental to network debugging. I know that's not what you meant, but somehow it comes to the same thing. :) And yep. That is so absolutely right. Problems know when concealment becomes pointless. ChrisA From rosuav at gmail.com Sat Mar 1 17:29:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 09:29:25 +1100 Subject: intersection, union, difference, symmetric difference for dictionaries In-Reply-To: References: Message-ID: On Wed, Feb 26, 2014 at 7:44 AM, John Gordon wrote: > In mauro writes: > >> - Dictionaries and sets are both accessed by key > > As far as I have used sets, they are not accessed by key. > >>>> x = set([1, 2, 'buckle my shoe']) >>>> x > set([1, 2, 'buckle my shoe']) >>>> 1 in x > True >>>> 5 in x > False >>> x = {1:3, 2:4, 'buckle my shoe':'spamming the door'} >>> x {1: 3, 2: 4, 'buckle my shoe': 'spamming the door'} >>> 1 in x True >>> 5 in x False A dict does the exact same thing with its keys as a set does with its elements. Actually, one of the things that periodically trips me up when I switch from Pike to Python is that a Python set can't be used like this: >>> x = set() >>> x["test"] = 1 >>> x["foo"] = 1 >>> assert x == {"test","foo"} Instead, I have to use x.add("test"). In Pike, I can treat a set as if it were a mapping where every value is simply the integer 1 (Python could use True instead). Setting it to any truthy value would add it, setting to any falsy value would remove it. This wouldn't be a huge change; it certainly wouldn't fundamentally change the set type - because it *is* working with keys. Hmm. Actually, it shouldn't be too hard to subclass and add that. Lessee. class set(set): def __setitem__(self, key, state): if state: self.add(key) else: self.remove(key) def __getitem__(self, key): return key in self I might need to toss that into site.py or something. It'd work as long as I don't use set literal notation anywhere. ChrisA From ben+python at benfinney.id.au Sat Mar 1 17:30:20 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 02 Mar 2014 09:30:20 +1100 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <531213c4$0$29987$c3e8da3$5496439d@news.astraweb.com> <87iorx93o0.fsf@elektro.pacujo.net> Message-ID: <85ha7hlfgj.fsf@benfinney.id.au> Marko Rauhamaa writes: > Steven D'Aprano : > > > It seems to me that he's just assuming that symbols ought to be > > singletons, hence his focus on identity rather than equality. > > Yes. Give that up, then. Your assumption is false in Python, and is not needed to get the behaviour you say you need. > A practical angle is this: if I used strings as symbols and compared > them with "==", logically I shouldn't define them as constants but > simply use strings everywhere Yes, that works fine. It's also quite understandable for the reader. > The principal (practical) problem with that is that I might make a > typo and write: > > if self.state == "IDLE ": > > which could result in some hard-to-find problems. That's just one of a huge variety of problems. Write a comprehensive unit test suite to catch this and a great many other errors. > That's why I want get the help of the Python compiler and always refer > to the states through symbolic constants Python doesn't let you compare symbols, only values. Work within its constraints. -- \ ?I cannot conceive that anybody will require multiplications at | `\ the rate of 40,000 or even 4,000 per hour ?? ?F. H. Wales, 1936 | _o__) | Ben Finney From harrismh777 at gmail.com Sat Mar 1 17:32:43 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 14:32:43 -0800 (PST) Subject: Mac vs. Linux for Python Development In-Reply-To: <2465a8c7-ce0e-4606-ad3b-9135c96e3e4c@googlegroups.com> References: <2465a8c7-ce0e-4606-ad3b-9135c96e3e4c@googlegroups.com> Message-ID: <4e741358-ce12-40ac-97b8-3bbbf2d6ddca@googlegroups.com> On Sunday, February 23, 2014 2:43:14 AM UTC-6, twiz wrote: > I'm sure this is a common question but I can't seem to find a previous thread that addresses it. If one one exists, please point me to it. My personal preference for writing and testing python code is Gnu/Linux as a platform (free libre open easier to build from C sources etc). As an editor, VI of course. Although, I can honestly say I've been using the latest GNU Emacs lately. It has a very nice python mode. I also use TextWrangler from time to time (can be extended with scripts and it has the same 'feel' as the IDLE editor (kind-of). The main problem you will see with OSX (if you're not careful) is that IDLE will be unstable. To be fair about it, its not IDLE's problem, per se. Its about tcl/tk tkinter. DO NOT use the built-in tcl that comes from Apple, nor the one that comes through the Apple store! Actually go to the Active TCL site and download the version related to your system (yes there is a different one depending on 10.5 10.6 etc). Py3.3.4 and the latest Active TCL are stable on OSX 10.6 or higher. I have been very pleased with IDLE on both Gnu/Linux and OSX ( I refuse to use Windows ever again, ever) and my latest experience has been fabulous, really. My hat is off to the folks that have made IDLE the simple stable and powerful IDE that it is. I am being genuine about this. Another reason for using Gnu/Linux (and/or OSX) is that generally they are faster. Faster loading, and faster running. Serious. I have been hearing of (4) second import times for decimal, for instance. Its almost instantaneous on Gnu/Linux, or OSX. Also, run times are considerably faster. That has less to do with the Windows version of python, and more to do with the Windows version. YMMV If you want to extend your python code with C (as many of us do) well OSX and/or Gnu/Linux are your best bets there too, and frankly Gnu/Linux is the better of the two (from personal experience). OSX 10.6 uses the GNU gcc compiler by default, but the Apple idiosyncratic approach to builds can be annoying. Although, its minimal really (hardly worth mentioning). If you want to build python from sources (as many of us do) my personal opinion is also that Gnu/Linux is the way to go there too. I agree with most of the rest of the posts here that personal preference is at play primarily. Your editor run environment is going to be more important to you than your platform. There is one main difference to that, and it has to do with what you're used to. In IDLE on Gnu/Linux the menu options are on the top of the IDE. In OSX they are on the OSX tool bar at top left (where they are for every other OSX app). OSX guys don't mind this, but Gnu/Linux guys hate it (sometimes). Also, the menu items on Gnu/Linux can be 'torn' off (its a tcl/tk tkinter thing) and on OSX that does not work. Also the 'Options' menu item on OSX has nothing in it. The Options menu is in Preferences in the IDLE drop down on the OSX tool bar. Other than those things, I have spent many cheerful hours in the OSX IDLE editor and have been happy as a clam. Same goes for the Gnu/Linux IDLE editor. If you want to use terminals on OSX you'll want to install Quartz and run the terminal on the emulated X environment. It works better for python IMHO. The built-in terminal for OSX need serious configuring (which is possible) because its color is bad, and its tiny by default, with a crummy font. All of that can be changed, but it just works better to use XQuartz. Enjoy Cheers From ben+python at benfinney.id.au Sat Mar 1 17:34:15 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 02 Mar 2014 09:34:15 +1100 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87r46l96j6.fsf@elektro.pacujo.net> Message-ID: <85d2i5lfa0.fsf@benfinney.id.au> Marko Rauhamaa writes: > Ben Finney : > > > No. I'm telling you that ?is? is *wrong* for comparing strings, > > because it is unreliable. > > No, it isn't as long as the string object references have a common > assignment "pedigree." Assignment (including parameter passing) is > guaranteed to preserve identity of any object. The unreliability isn't ?will the same object have the same identity??. The unreliability is ?will objects defined elsewhere have a different identity?? In the case of Python strings, the latter question is not reliably answerable from the programmer's perspective. You are obstinately ignoring the point that the identity of a string is *not* guaranteed to be different from a string with the same value. Since you're persistently misconstruing what is being said to you, I'm not going to run through it all again. -- \ ?[W]e are still the first generation of users, and for all that | `\ we may have invented the net, we still don't really get it.? | _o__) ?Douglas Adams | Ben Finney From ben+python at benfinney.id.au Sat Mar 1 17:36:07 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 02 Mar 2014 09:36:07 +1100 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> Message-ID: <858ustlf6w.fsf@benfinney.id.au> Grant Edwards writes: > On 2014-02-28, Mark Lawrence wrote: > > > http://c2.com/cgi/wiki?SwitchStatementsSmell > > So lack of a switch state is an attempt [?] Since when is the absence of action an ?attempt? to do anything? You're assuming the not-doing of something must have a purpose. That assumption doesn't seem justified. -- \ ?You are welcome to visit the cemetery where famous Russian and | `\ Soviet composers, artists, and writers are buried daily except | _o__) Thursday.? ?Russian orthodox monastery, Moscow | Ben Finney From harrismh777 at gmail.com Sat Mar 1 17:50:45 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 14:50:45 -0800 (PST) Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> Message-ID: On Saturday, March 1, 2014 4:36:07 PM UTC-6, Ben Finney wrote: > Since when is the absence of action an "attempt" to do anything? > > You're assuming the not-doing of something must have a purpose. That > assumption doesn't seem justified. Correct. Argument from silence is logical fallacy; lack of motion is not the "doing" of being motionless. :) From rosuav at gmail.com Sat Mar 1 17:57:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 09:57:30 +1100 Subject: Mac vs. Linux for Python Development In-Reply-To: <4e741358-ce12-40ac-97b8-3bbbf2d6ddca@googlegroups.com> References: <2465a8c7-ce0e-4606-ad3b-9135c96e3e4c@googlegroups.com> <4e741358-ce12-40ac-97b8-3bbbf2d6ddca@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 9:32 AM, Mark H. Harris wrote: > Py3.3.4 and the latest Active TCL are stable on OSX 10.6 or higher. I have been very pleased with IDLE on both Gnu/Linux and OSX ( I refuse to use Windows ever again, ever) and my latest experience has been fabulous, really. My hat is off to the folks that have made IDLE the simple stable and powerful IDE that it is. I am being genuine about this. > > Another reason for using Gnu/Linux (and/or OSX) is that generally they are faster. Faster loading, and faster running. Serious. I have been hearing of (4) second import times for decimal, for instance. Its almost instantaneous on Gnu/Linux, or OSX. Also, run times are considerably faster. That has less to do with the Windows version of python, and more to do with the Windows version. YMMV > The point of this thread isn't really about Windows, so I'll try to keep it brief, but there are a couple of things I should clarify. The first one is about the 4+ second import time for decimal. I cited that, recently, and comparing that with "almost instantaneous" on Debian (which is what I experience) isn't entirely fair, because it's more about cold cache versus warm cache. (When I shut down IDLE and fire it up again, I get sub-second import time. Not as fast as the "so quick as to be immeasurable" that my Debian box gave, but still quicker than the 4ish second cold cache.) Actually, I do find that my Linux boxes manage their disk caches far better than my Windows boxes do. Not sure if that's Linux versus Windows, or the ext3/4 versus NTFS file system drivers, or something else, but a warm cache on any of my Linux boxes gives a *huge* advantage, and my Windows boxes still show it a bit slower. ChrisA From nad at acm.org Sat Mar 1 18:07:29 2014 From: nad at acm.org (Ned Deily) Date: Sat, 01 Mar 2014 15:07:29 -0800 Subject: Mac vs. Linux for Python Development References: <2465a8c7-ce0e-4606-ad3b-9135c96e3e4c@googlegroups.com> <4e741358-ce12-40ac-97b8-3bbbf2d6ddca@googlegroups.com> Message-ID: In article <4e741358-ce12-40ac-97b8-3bbbf2d6ddca at googlegroups.com>, "Mark H. Harris" wrote: > [...] > The main problem you will see with OSX (if you're not careful) is that IDLE > will be unstable. To be fair about it, its not IDLE's problem, per se. Its > about tcl/tk tkinter. DO NOT use the built-in tcl that comes from Apple, nor > the one that comes through the Apple store! Actually go to the Active TCL > site and download the version related to your system (yes there is a > different one depending on 10.5 10.6 etc). The gory details are here: http://www.python.org/download/mac/tcltk/ TL;DR You'll need to install newer versions of Python (like those download from python.org) that link with third-party builds of Tcl/Tk rather than use the Pythons and Tcl/Tk that Apple ships with OS X 10.6+. > [...] > If you want to use terminals on OSX you'll want to install Quartz and run > the terminal on the emulated X environment. It works better for python IMHO. > The built-in terminal for OSX need serious configuring (which is possible) > because its color is bad, and its tiny by default, with a crummy font. All of > that can be changed, but it just works better to use XQuartz. That certainly is a matter of preference. There are plenty of drawbacks to using X11-based apps on OS X. I wouldn't advise new users to OS X to go that route unless they were really set on using X11 entirely and, in that case, why use OS X at all? If you don't like Apple's built-in Terminal.app, another option is to use iTerm 2, an open source native alternative that has many more features. http://www.iterm2.com/ It's also available through MacPorts. -- Ned Deily, nad at acm.org From steve+comp.lang.python at pearwood.info Sat Mar 1 18:13:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2014 23:13:22 GMT Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <531213c4$0$29987$c3e8da3$5496439d@news.astraweb.com> <87iorx93o0.fsf@elektro.pacujo.net> Message-ID: <53126992$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sat, 01 Mar 2014 20:25:51 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> It seems to me that he's just assuming that symbols ought to be >> singletons, hence his focus on identity rather than equality. > > Yes. > > A practical angle is this: if I used strings as symbols and compared > them with "==", logically I shouldn't define them as constants That doesn't follow. There is no logical connection between using named constants (well, pseudo-constants, constants by convention only) and ==. You can do both, or neither, or either one, whichever suits you. You might as well say that when you have float constants: TAU = 6.283185307179586 that "logically" implies that you are prohibited in asking whether another float is less than or greater than TAU. [...] > The principal (practical) problem with that is that I might make a typo > and write: > > if self.state == "IDLE ": Then used named constants. if self.state == IDLE: See how easy it is? Just replace "is" with == unless you have a good reason for caring about identity instead of equality. -- Steven D'Aprano http://import-that.dreamwidth.org/ From tjreedy at udel.edu Sat Mar 1 18:15:10 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 01 Mar 2014 18:15:10 -0500 Subject: Can tuples be replaced with lists all the time? In-Reply-To: References: <64af70e3-6876-4fbf-8386-330d2f48735a@googlegroups.com> Message-ID: On 3/1/2014 4:20 PM, Mark Lawrence wrote: > On 23/02/2014 17:48, Roy Smith wrote: >> It also appears that tuples are more memory efficient. I just ran some >> quick tests on my OSX box. Creating a list of 10 million [1, 2, 3, 4, >> 5] lists gave me a 1445 MB process. The name number of (1, 2, 3, 4, 5) >> tuples was 748 MB. I'm sure this is implementation dependent, but it >> seems plausible to assume similar results will be had on other >> implementations. The numbers sound right. > In CPython a list is overallocated so there's usually spare slots > available if you want to add something to it. In contrast you know when > you create the tuple just how big it is so no overallocation is needed. Besides which, in CPython, a tuple is one block of memory, with a PyObject header followed by the object references, while a list uses 2 blocks of memory. The first has a PyObject header, followed by a reference to the list block, its allocated length (minimum 8 I believe), and its current in-use length. The over-allocated list block, which must also start on a 4 or 8 byte alignment boundary, has the object references plus extra space. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sat Mar 1 18:21:57 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 01 Mar 2014 23:21:57 +0000 Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> Message-ID: On 01/03/2014 22:07, Mark H. Harris wrote: > On Saturday, March 1, 2014 4:01:12 PM UTC-6, Mark Lawrence wrote: > >> >> No elipses, just the paragraphs not wrapped and the double line spacing. >> >> Good old gg, I just love it. > > How do I fix it? Is there a setting someplace? I tried pulling up the page you linked, but blank. > > Thanks in advance. > https://wiki.python.org/moin/GoogleGroupsPython -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Sat Mar 1 19:23:10 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 16:23:10 -0800 (PST) Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> Message-ID: <268ea8b1-85a8-4b41-bbe2-b8a13ca0a469@googlegroups.com> On Saturday, March 1, 2014 5:21:57 PM UTC-6, Mark Lawrence wrote: > https://wiki.python.org/moin/GoogleGroupsPython Thanks, Mark. Whoohoo! Looks like gg has some work to do. rats(). Ok, so I'm typing away here and when I get to the boarder I should press the enter key so that the text is forced to wrap to the next line so that you don't see the text as a run-off the page nuisance and complete annoyance leading to homicidal rage and/or other illicit behaviors like nail-biting. How does this look on your news client. I just need to setup an nntp server and use a real client. Thanks for your input Mark. Peace. marcus From rosuav at gmail.com Sat Mar 1 19:28:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 11:28:43 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <268ea8b1-85a8-4b41-bbe2-b8a13ca0a469@googlegroups.com> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> <268ea8b1-85a8-4b41-bbe2-b8a13ca0a469@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 11:23 AM, Mark H. Harris wrote: > On Saturday, March 1, 2014 5:21:57 PM UTC-6, Mark Lawrence wrote: > >> https://wiki.python.org/moin/GoogleGroupsPython > > Thanks, Mark. Whoohoo! Looks like gg has some work to do. rats(). Ok, so I'm typing away here and when > I get to the boarder I should press the enter key so that the text is forced to wrap to the next line so that > you don't see the text as a run-off the page nuisance and complete annoyance leading to homicidal rage > and/or other illicit behaviors like nail-biting. > How does this look on your news client. I just need to setup an nntp server and use a real client. The usual recommendation is to wrap to 70-80 characters. Most likely you're seeing a proportionally-spaced font, so going for the border of the display is going to be inherently sloppy. What I would recommend, if you don't feel like setting up NNTP, is to subscribe to the mailing list: https://mail.python.org/mailman/listinfo/python-list All the same content, but via email instead. Take your pick between that and a newsreader - whichever's easier to get to work. ChrisA From breamoreboy at yahoo.co.uk Sat Mar 1 19:36:07 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 00:36:07 +0000 Subject: Can global variable be passed into Python function? In-Reply-To: <268ea8b1-85a8-4b41-bbe2-b8a13ca0a469@googlegroups.com> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> <268ea8b1-85a8-4b41-bbe2-b8a13ca0a469@googlegroups.com> Message-ID: On 02/03/2014 00:23, Mark H. Harris wrote: > On Saturday, March 1, 2014 5:21:57 PM UTC-6, Mark Lawrence wrote: > >> https://wiki.python.org/moin/GoogleGroupsPython > > Thanks, Mark. Whoohoo! Looks like gg has some work to do. rats(). Ok, so I'm typing away here and when > I get to the boarder I should press the enter key so that the text is forced to wrap to the next line so that > you don't see the text as a run-off the page nuisance and complete annoyance leading to homicidal rage > and/or other illicit behaviors like nail-biting. > How does this look on your news client. I just need to setup an nntp server and use a real client. > > Thanks for your input Mark. > > Peace. marcus > I love it when a plan comes together :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Sat Mar 1 19:49:28 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 16:49:28 -0800 (PST) Subject: extend methods of decimal module In-Reply-To: References: <02cdd9c7-aef7-4cc7-a813-cd1c9627ceb4@googlegroups.com> <94b1962a-0004-4c5b-b484-972a166b88b5@googlegroups.com> <55525f2c-fd3a-4927-b642-2dbf5eae7e9b@googlegroups.com> Message-ID: <360ca828-1524-4594-97d5-26363210c5df@googlegroups.com> On Saturday, March 1, 2014 12:55:07 AM UTC-6, Anssi Saari wrote: > I recently watched a presentation by Jessica McKellar of PSF about what > Python needs to stay popular. Other than the obvious bits (difficulties > of limited support of Python on major platforms like Windows and mobile) > the slight lack of perfection in IDLE was mentioned. Specifically the > old blog post titled "The Things I Hate About IDLE That I Wish Someone > Would Fix" at > http://inventwithpython.com/blog/2011/11/29/the-things-i-hate-about-idle-that-i-wish-someone-would-fix/ hi Anssi, this discussion really doesn't belong in this thread, but I'll give you my two cents on it anyway, just because I put the random comment in here to begin with. The blog link which you posted is quite old, and yes, as I remember back to the 2009-2011 time frame IDLE had some problems with stability and some other issues related to tkinter. My experience with IDLE today is one of stability usefulness; clean and simple. Like that FORD commercial here in the States, " Have you driven and IDLE lately?" Some of the bloggers 'hates' are actually features of IDLE and we really don't want to change them. Some of them have been fixed. Some of them are annoyances not with IDLE per se, but with tcl/tk and are a tkinter thing. For instance, the blogger 'hates' the menu tear-off feature. I love it. All of my tcl/tk apps have tear-off menus; its totally a tkinter thing and if you're not used to apps written with the tk library then this 'feature' may annoy you. The IDLE concept was to have an IDE written in pure python that would use the tk library. If you've not written any code using the tk library then try it. GUI apps can be built with the tk library (with either tcl, or with python, and others) that are reduced to a few lines of code vs. many pages of code. In two pages of tk coding I can create a GUI app that would use 16 pages of code written in C, and 8-16 pages of code written in C++ or Java. The down-side to the tk library is that the GUI work they do for you under the covers (which is extensive by the way) makes some assumptions and simplifies the options. So, you trade off the speed and efficiency of writing the app and getting it to market quickly, with not having the explicit control over the GUI that you might have if you had written the code to Q, or GTK, or some such. Producing IDLE using tk was genius on the part of Guido initially. The tradition has been kept up, but has not received the priority that other python issues have received. By the way, there are other python IDEs out there (I don't use them, just pointing out that they are available). IDLE is free, its efficient, and for the moment its also very stable and highly useful. If you have not driven an IDLE lately, give it a try. Also, my experience with the devs on IDLE (and particularly Terry Reedy) is that they have been very responsive, helpful, even courteous and professional. So, I think the blogger was a little too harsh. Cheers From cs at zip.com.au Sat Mar 1 19:55:51 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 2 Mar 2014 11:55:51 +1100 Subject: Mac vs. Linux for Python Development In-Reply-To: References: Message-ID: <20140302005551.GA74610@cskk.homeip.net> On 01Mar2014 15:07, Ned Deily wrote: > In article <4e741358-ce12-40ac-97b8-3bbbf2d6ddca at googlegroups.com>, > "Mark H. Harris" wrote: > > [...] > > If you want to use terminals on OSX you'll want to install Quartz and run > > the terminal on the emulated X environment. It works better for python IMHO. > > The built-in terminal for OSX need serious configuring (which is possible) > > because its color is bad, and its tiny by default, with a crummy font. All of > > that can be changed, but it just works better to use XQuartz. > > That certainly is a matter of preference. There are plenty of drawbacks > to using X11-based apps on OS X. I wouldn't advise new users to OS X to > go that route unless they were really set on using X11 entirely and, in > that case, why use OS X at all? If you don't like Apple's built-in > Terminal.app, another option is to use iTerm 2, an open source native > alternative that has many more features. > > http://www.iterm2.com/ > > It's also available through MacPorts. > I also recommend iTerm2. It is really good, far better than OSX's Terminal app. I run it full screen and split it into panes, typically 3 or 4 vertical and then as many horizontal as required (ssh to multiple hosts); I edit in a full height pane usually. To reiterate from a post to mutt-users: I like iTerm2 for the following reasons: - focus follows mouse - selecting text can be set to set the cut buffer immediately, no %C needed. Like X11. - horizontal and vertical pane tiling I've bound shift-%V to open a new vertical pane (splits the current pane vertically) and shift-%T to open a new horizontal pane (splits the current pane horizontally). This is outstandingly useful for working in multiple shells. I do a lot of remote admin and opening shells on a bunch of machines nicely arranged for coordinated work is very pleasing. And of course I've spent some time tuning fonts and colours, and made things slightly transparent with a slight brightening for the currently focussed pane. iTerm2 has lots of features, but the ones above are the real winners for me. Here's a screenshot of this message: https://www.dropbox.com/s/3zvit1cwuoac80h/iterm2-fullscreen-2014-03-02-11.49.02.png Cheers, -- Cameron Simpson TeX: When you pronounce it correctly to your computer, the terminal may become slightly moist. - D. E. Knuth. From nad at acm.org Sat Mar 1 19:55:58 2014 From: nad at acm.org (Ned Deily) Date: Sat, 01 Mar 2014 16:55:58 -0800 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87iorzf4ro.fsf@elektro.pacujo.net> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> <268ea8b1-85a8-4b41-bbe2-b8a13ca0a469@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > What I would recommend, if you don't feel like setting up NNTP, is to > subscribe to the mailing list: > > https://mail.python.org/mailman/listinfo/python-list > > All the same content, but via email instead. Take your pick between > that and a newsreader - whichever's easier to get to work. Or use one of the multiple interfaces to the group/list provided by gmane.org: nntp, web, or (read-only) rss. http://dir.gmane.org/gmane.comp.python.general -- Ned Deily, nad at acm.org From swdunning at cox.net Sat Mar 1 20:11:07 2014 From: swdunning at cox.net (Scott W Dunning) Date: Sat, 1 Mar 2014 18:11:07 -0700 Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: On Mar 1, 2014, at 11:03 AM, Susan Aldridge wrote: > Try this > > def guess1(upLimit = 100): > import random > num = random.randint(1,upLimit) > count = 0 > gotIt = False > while (not gotIt): > print('Guess a number between 1 and', upLimit, ':') > guess= int(input()) > count += 1 > if guess == num: > print('Congrats! You win') > gotIt = True > elif guess < num: > print('Go up!') > else: > print('Guess less') > print('You got it in ', count, 'guesses.') > > guess1(100) Thanks Susan! The only problem is he wants us to do it without loops because we haven?t learned them yet. I need to use the variables and function names that he?s given as well. I think I can make sense of what you wrote though so that should help me a bit. From breamoreboy at yahoo.co.uk Sat Mar 1 20:15:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 01:15:31 +0000 Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <877g8ff3hn.fsf@elektro.pacujo.net> <87wqgfdk6a.fsf@elektro.pacujo.net> <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com> <4bd11eec-395a-4484-a991-9fabf12328e1@googlegroups.com> <2633c4d3-e8cc-47fa-b22a-48dab2ef1a29@googlegroups.com> <268ea8b1-85a8-4b41-bbe2-b8a13ca0a469@googlegroups.com> Message-ID: On 02/03/2014 00:55, Ned Deily wrote: > In article > , > Chris Angelico wrote: >> What I would recommend, if you don't feel like setting up NNTP, is to >> subscribe to the mailing list: >> >> https://mail.python.org/mailman/listinfo/python-list >> >> All the same content, but via email instead. Take your pick between >> that and a newsreader - whichever's easier to get to work. > > Or use one of the multiple interfaces to the group/list provided by > gmane.org: nntp, web, or (read-only) rss. > > http://dir.gmane.org/gmane.comp.python.general > This mechanism has the added advantage of being a one stop shop. Not only can you subscribe to hundreds of Python lists there is also a setup that lets you take feeds from numerous Python blogs. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sat Mar 1 20:16:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 12:16:10 +1100 Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: On Sun, Mar 2, 2014 at 12:11 PM, Scott W Dunning wrote: >> print('You got it in ', count, 'guesses.') >> > Thanks Susan! The only problem is he wants us to do it without loops because we haven?t learned them yet. I need to use the variables and function names that he?s given as well. I think I can make sense of what you wrote though so that should help me a bit. > Another consideration: Susan's code is written for Python 3, but you seemed to be using Python 2. You'll find that the code won't even run on your version of Python. (If you have the chance, ask if the course writer would consider updating it to use Python 3. There's getting to be less and less reason to use Python 2 for any new projects; when you start a brand new system, you should be using Python 3 unless there's something holding you on the old version. So it's correspondingly more useful to learn Py3.) ChrisA From eric.jacoboni at gmail.com Sat Mar 1 21:04:32 2014 From: eric.jacoboni at gmail.com (Eric Jacoboni) Date: Sun, 02 Mar 2014 03:04:32 +0100 Subject: Tuples and immutability In-Reply-To: <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> Message-ID: Le 01/03/2014 22:21, Mark H. Harris a ?crit : > The point I'm trying to make with this post is that s[2]+=[46] and > s[2]=s[2]+[46] are handled inconsistently. For my own, the fact that, in Python, a_liste += e_elt gives a different result than a_list = a_list + e_elt is a big source of trouble... I don't really find a good reason to justify that : a_list += "spam" gives a valid result, when a_list = a_list + "spam" is not allowed. Why the former is like a_list.extend() in the first place ? (well, it's not exactly an extend() as extend returns None, not +=). And if both operations were equivalent, i think my initial question about tuples will be clear and the behavio(u)r would me more consistent for me : tu = (10, [10, 30]) tu[1] = tu[1] + [20] <-- Big mistake! TypeError: 'tuple' object does not support item assignment <-- ok tu (10, [10, 30]) <-- ok too... In fact, i think i'm gonna forget += on lists :) From harrismh777 at gmail.com Sat Mar 1 21:15:10 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 18:15:10 -0800 (PST) Subject: Tuples and immutability In-Reply-To: <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> Message-ID: On Saturday, March 1, 2014 3:21:44 PM UTC-6, Mark H. Harris wrote: > On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: hi Ian, I thought of something else after I slept on it, so to speak. Consider this: >>> s=(2,3,[42,43,44],7) >>> s[2] [42, 43, 44] >>> s[2] is a list. We should be able to change s[2] even though its within a tuple, like this: [42, 43, 44] >>> s[2].append(45) >>> s[2] [42, 43, 44, 45] <===== no error >>> or like this: >>> s[2] [42, 43, 44, 45] >>> s[2]=s[2]+[46] Traceback (most recent call last): File "", line 1, in s[2]=s[2]+[46] <==========error, but look below====== TypeError: 'tuple' object does not support item assignment >>> >>> s[2] [42, 43, 44, 45] <=========also no change to list !! >>> The point I'm trying to make with this post is that s[2]+=[46] and s[2]=s[2]+[46] are handled inconsistently. In each case (whether the list is part of a tuple or not) s[2] is a valid list and should be mutable. In every case, in fact, it is. In each case, in fact, the change might occur. But, the change occurs in the first case (append) without an error. The change occurs in the next case too (+=) but with an error not related to the tuple. The change does not occur in the third case (s=s+ with an error) but the list is not changed ! We all know this is not good. We also all know that its because of implementation details the user/coder should not need to know. QED: a bug. Having slept on it, I am remembering my Zen of Python: Errors should never pass silently, unless explicitly silenced. It looks to me like (+=) in this case is not being handled correctly under the covers. At any rate the three scenarios of trying to change a mutable list as an immutable tuple item should be handled consistently. Either we can change the tuple item (if its a list) or we can't. Also, if we cannot then the expected error should be consistent. Cheers Hi , I'm experimenting a bit with TextWrangler and gg to see if I can at least solve my double spacing and wrap problems with cut a paste for the moment. Looks ok? Thanks From harrismh777 at gmail.com Sat Mar 1 21:28:21 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Sat, 1 Mar 2014 18:28:21 -0800 (PST) Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> Message-ID: On Saturday, March 1, 2014 8:04:32 PM UTC-6, Eric Jacoboni wrote: > > > In fact, i think i'm gonna forget += on lists :) hi Eric, well, that might be extreme, but you certainly want to avoid trying to change an immutable. Something you might want to consider is trying something like creating a new immutable. In the example we've been looking at I think I would change the tuple list item with an append(); however, you might try building a new tuple instead of trying to change an existing tuple item. I must admit that I would never have found this bug myself, because I don't try to change tuples (at all). Anyway, I'm glad you found it -- we all learn and that's the good news. Cheers From swdunning at cox.net Sat Mar 1 20:06:09 2014 From: swdunning at cox.net (Scott W Dunning) Date: Sat, 1 Mar 2014 18:06:09 -0700 Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: On Mar 1, 2014, at 9:35 AM, Dennis Lee Bieber wrote: > Without loops, one part of your assignment is going to be tedious, > unless the intent is to only allow for one guess per run. No, 10 guesses per game. Yes very tedious and repetative. > >> from random import randrange >> randrange(1, 101) > > You generated a random number and then threw it away. >> >> from random import seed >> seed(129) I do not know what seed is. The directions in the begining said to do that I guess to test the code through out writing it? This is what the directions for that part said. At the top of your file, import the randrange function from the random module. In order to test this module I also want you to import the seed function from the random module. Immediately after importing it I want you to call the seed function with an argument of 129. By calling the seed function we ensure that the sequence of random numbers you generate will exactly match the ones used in this document. > > Now you are seeding the random number generator but never generate a > new number after it. > >> >> def print_description(): >> print """Welcome to Guess the Number. >> I have seleted a secret number in the range 1 ... 100. >> You must guess the number within 10 tries. >> I will tell you if you ar high or low, and >> I will tell you if you are hot or cold.\n""" >> >> def get_guess(guess_number): >> print "(",guess_number,")""Plese enter a guess:" >> current_guess = raw_input() >> return int(guess_number) > > You're returning the counter of how many guesses have been made, and > dropping the player's guess into the trash I actually do not understand what you mean here. Should I get rid of the current_guess line completely? Should it look more like this; def get_guess(guess_number): raw_input(?Please enter a guess?) guess_number = int(guess_number) return (guess_number) get_guess(1) > >> >> def main(): >> print_description() >> secret = 50 > > That's supposed to be the random number, isn't it? Yes it is, I put 50 there because I was going to try and test it. I think it should be secret = randrange(1,101) right? > >> current_guess = 1 >> get_guess(1) > > You drop the return value into the trash > >> if current_guess != secret(): > > You are /calling/ a function called secret -- which doesn't exist, > since you bound it to the integer value 50; And current_guess doesn't exist > in this function either. > >> print "Congratulations you win!!" > > > Read the documentation on how function calls and return values operate. > Hint: you need to do something with the returned value /at the point where > you call the function/. Hmm, ok I?ll try and find what I?m missing. > > And -- as has been mentioned; these mistakes are better served in the > tutor list, as they would be mistakes in /any/ common programming language. > -- > Yes, I?m sorry I completely forgot. I?ll repost there and go that route. Thanks though! -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Sat Mar 1 22:04:13 2014 From: davea at davea.name (Dave Angel) Date: Sat, 1 Mar 2014 22:04:13 -0500 (EST) Subject: Boxes of O's References: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> Message-ID: geniusrko at gmail.com Wrote in message: > Well, This is what i got > > n = int(input("enter number of o: ")) > > for i in range(n): > print("O", end = '') > for j in range(n* 2): > print("O", end = '') > > print() > Are you permitted to write and call functions? If so, then write functions to solve pieces of the problem, and call those functions from your main one. That's called factoring, and is an important tool. In this case, one function could print a row of 'o' of length siz, while the second one print a 'hollow' row. Then your main calls first, then loops calling hollow, then calls first again. -- DaveA From davea at davea.name Sat Mar 1 23:02:19 2014 From: davea at davea.name (Dave Angel) Date: Sat, 1 Mar 2014 23:02:19 -0500 (EST) Subject: [OT] Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: Grant Edwards Wrote in message: > On 2014-02-24, Michael Torrie wrote: > >> >> Why would you think that? The address of the start of your malloc'ed >> structure is the same as the address of the first element. Surely >> this is logical? > > Not only is it logical, the C standard explicitly requires it. Here's > a second-hand citation since I don't happend to have an actual copy of > the standard on hand: > > C1x ???6.7.2.1.13: > > A pointer to a structure object, suitably converted, points to > its initial member ... and vice versa. There may be unnamed > padding within a structure object, but not at its beginning. The quote you make from the C standard doesn't mention malloc, so you're arguing different things. It's not the compiler that casts the malloc return value to the struct type. C++ does implicitly convert the result, and the return value of new already has the struct type. But the runtime stores at least two kinds of overhead on occasion, the array size, and the vtable. So the malloc address can not be assumed to match the struct beginning. (Not even considering that one can override operator new at two levels) Glad python doesn't have any of this mess. -- DaveA From rosuav at gmail.com Sat Mar 1 23:17:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 15:17:21 +1100 Subject: [OT] Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 3:02 PM, Dave Angel wrote: > The quote you make from the C standard doesn't mention malloc, so > you're arguing different things. It's not the compiler that casts > the malloc return value to the struct type. > > C++ does implicitly convert the result, and the return value of > new already has the struct type. But the runtime stores at least > two kinds of overhead on occasion, the array size, and the > vtable. So the malloc address can not be assumed to match the > struct beginning. (Not even considering that one can override Whatever pointer malloc returns is the beginning of the *usable* space. Any overhead for array size etc has to be before that; a virtual function table pointer would be inside that space, but that's very much compiler-dependent. ChrisA From greg.ewing at canterbury.ac.nz Sat Mar 1 23:20:08 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 02 Mar 2014 17:20:08 +1300 Subject: posting code snippets In-Reply-To: References: <85ppm8nqx7.fsf@benfinney.id.au> Message-ID: Grant Edwards wrote: > You drag out the lab scope, logic analyzer, spectrum analyzer, sweep > generator, strip plotter, and the machine that goes "ping". You start > to get everything set up to nail that problem securely to the > dissecting board. Long before you actually get to that point, the > problem becomes intimidated and reveals itself and a solution. "No! No! Not the comfy spectrum analyser! I give up!" -- Greg From frank at chagford.com Sun Mar 2 00:51:11 2014 From: frank at chagford.com (Frank Millman) Date: Sun, 2 Mar 2014 07:51:11 +0200 Subject: Mac vs. Linux for Python Development References: <2465a8c7-ce0e-4606-ad3b-9135c96e3e4c@googlegroups.com> <4e741358-ce12-40ac-97b8-3bbbf2d6ddca@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmrBU9K0aoJyCUmif1FCExtbsuq27pGxiRvyNd=yVn-D5g at mail.gmail.com... > > The point of this thread isn't really about Windows, so I'll try to > keep it brief, but there are a couple of things I should clarify. The > first one is about the 4+ second import time for decimal. I cited > that, recently, and comparing that with "almost instantaneous" on > Debian (which is what I experience) isn't entirely fair, because it's > more about cold cache versus warm cache. (When I shut down IDLE and > fire it up again, I get sub-second import time. Not as fast as the "so > quick as to be immeasurable" that my Debian box gave, but still > quicker than the 4ish second cold cache.) > Which version are you talking about? I have an old, slow box running Windows Server 2003 and python 3.3.2. I have just booted it up now, called up a command prompt, typed 'python' to start the interpreter, and typed 'import decimal'. The interpreter prompt re-appeared in the blink of an eye. Are you talking about something else? Frank Millman From rosuav at gmail.com Sun Mar 2 01:57:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 17:57:04 +1100 Subject: Mac vs. Linux for Python Development In-Reply-To: References: <2465a8c7-ce0e-4606-ad3b-9135c96e3e4c@googlegroups.com> <4e741358-ce12-40ac-97b8-3bbbf2d6ddca@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 4:51 PM, Frank Millman wrote: > Which version are you talking about? > > I have an old, slow box running Windows Server 2003 and python 3.3.2. > > I have just booted it up now, called up a command prompt, typed 'python' to > start the interpreter, and typed 'import decimal'. The interpreter prompt > re-appeared in the blink of an eye. > > Are you talking about something else? I did it in IDLE, which might have added a bit, but not hugely. It was 3.4.0, so the module in both cases is the C-accelerated version. My suspicion is that you've used the decimal module already on that system, so you had a warm cache. When I repeat the exercise, I get sub-second load times (usually of the order of 100-200ms); the difference between that and your "blink of an eye" would be to do with exactness of measurement, CPU/HDD performance, etc, etc, etc. ChrisA From cs at zip.com.au Sun Mar 2 01:32:12 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 2 Mar 2014 17:32:12 +1100 Subject: How to run multiple virtualenv in product server In-Reply-To: References: Message-ID: <20140302063212.GA46253@cskk.homeip.net> On 27Feb2014 07:29, YE SHANG wrote: > I'm starting to learn virtualenv, I wonder how run python project developed in virtualenv. > > Here is my situation, there is a server we can access with a common user name and password, there are many py scripts wrote by different people on this server. > > If I develop my python project with virtualenv, could I run it in product server?? If you are suggesting that you are developing on a different machine from the production server, then you probably need to install a virtualenv on the production server equivalent to the one you are using on your development machine. -- Cameron Simpson Anagram: Information superhighway <==> I'm on a huge wispy rhino fart. From frank at chagford.com Sun Mar 2 02:35:29 2014 From: frank at chagford.com (Frank Millman) Date: Sun, 2 Mar 2014 09:35:29 +0200 Subject: Mac vs. Linux for Python Development References: <2465a8c7-ce0e-4606-ad3b-9135c96e3e4c@googlegroups.com> <4e741358-ce12-40ac-97b8-3bbbf2d6ddca@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmrmJjiGMfqui=PpJco7LjtqVpUjj=XNmTYbYQEmxG3fmw at mail.gmail.com... > On Sun, Mar 2, 2014 at 4:51 PM, Frank Millman wrote: >> Which version are you talking about? >> >> I have an old, slow box running Windows Server 2003 and python 3.3.2. >> >> I have just booted it up now, called up a command prompt, typed 'python' >> to >> start the interpreter, and typed 'import decimal'. The interpreter prompt >> re-appeared in the blink of an eye. >> >> Are you talking about something else? > > I did it in IDLE, which might have added a bit, but not hugely. It was > 3.4.0, so the module in both cases is the C-accelerated version. My > suspicion is that you've used the decimal module already on that > system, so you had a warm cache. When I repeat the exercise, I get > sub-second load times (usually of the order of 100-200ms); the > difference between that and your "blink of an eye" would be to do with > exactness of measurement, CPU/HDD performance, etc, etc, etc. > I assume by 'warm cache' you mean that I had used the decimal module before and not switched the machine off before trying the above exercise. In my case, the machine was switched off before I started. I switched it on and executed the above steps. To be slightly more precise, instead of 'the blink of an eye', I estimate it was between 250-500 ms. If I close the interpreter and start it up again, it takes maybe 100-200ms. Just to be sure, I switched the machine off and on again, and repeated the exercise. Starting the interpreter for the first time takes 1.5 - 2 seconds. Importing decimal for the first time takes less than 500ms. Frank From orgnut at yahoo.com Sun Mar 2 02:38:08 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Sat, 01 Mar 2014 23:38:08 -0800 Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: <1ZidnQpoVoB9Qo_OnZ2dnUVZ_rmdnZ2d@giganews.com> On 03/01/2014 05:11 PM, Scott W Dunning wrote: > > On Mar 1, 2014, at 11:03 AM, Susan Aldridge wrote: >> Try this >> >> def guess1(upLimit = 100): >> import random >> num = random.randint(1,upLimit) >> count = 0 >> gotIt = False >> while (not gotIt): >> print('Guess a number between 1 and', upLimit, ':') >> guess= int(input()) >> count += 1 >> if guess == num: >> print('Congrats! You win') >> gotIt = True >> elif guess < num: >> print('Go up!') >> else: >> print('Guess less') >> print('You got it in ', count, 'guesses.') >> >> guess1(100) > Thanks Susan! The only problem is he wants us to do it without loops because we haven?t learned them yet. I need to use the variables and function names that he?s given as well. I think I can make sense of what you wrote though so that should help me a bit. > Another 'problem' is what you failed to mention in your post, but is apparent from the instructions that you posted -- this assignment is NOT the complete program, just the beginning of one. Your instructor obviously wants you to work on (and understand) this program fragment before continuing with the rest of it. -=- Larry -=- From marko at pacujo.net Sun Mar 2 03:00:36 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 10:00:36 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87y50vwjq4.fsf@elektro.pacujo.net> <87d2i7wbxs.fsf@elektro.pacujo.net> Message-ID: <87bnxp58t7.fsf@elektro.pacujo.net> Roy Smith : > Python already has a switch statement. It's just spelled funny... > > [...] > > try: > raise value > except Case1: > print "did case 1" > except (Case2, Case3): > print "did either case 2 or 3" > else: > print "did default" Not bad! Definitely worth considering. > No fall-through, however. Fall-trough is an unfortunate C syntax accident, not a feature worth emulating. Marko From marko at pacujo.net Sun Mar 2 03:00:39 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 10:00:39 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87y50vwjq4.fsf@elektro.pacujo.net> <87d2i7wbxs.fsf@elektro.pacujo.net> <877g8fgsr1.fsf@elektro.pacujo.net> Message-ID: <874n3h58t4.fsf@elektro.pacujo.net> Grant Edwards : > any decent compiler should be able to generate the same code for a > switch statement and for an equivalent chained if/else. It's not so easy to be decent, especially when it comes to a language as dynamic as Python. Marko From marko at pacujo.net Sun Mar 2 03:03:18 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 10:03:18 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87r46l96j6.fsf@elektro.pacujo.net> Message-ID: <87zjl93u49.fsf@elektro.pacujo.net> Ben Finney : > The unreliability is ?will objects defined elsewhere have a different > identity?? That question is not interesting in my context, and has no bearing on the correctness of the program. Marko From steve+comp.lang.python at pearwood.info Sun Mar 2 03:35:23 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2014 08:35:23 GMT Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> Message-ID: <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sat, 01 Mar 2014 19:29:41 +0200, Marko Rauhamaa wrote: > Michael Torrie : > >> No, '==' works fine no matter what objects you assign to your state >> variables. > > Well, it doesn't since > > >>> a = float("nan") > >>> a is a > True > >>> a == a > False No, that is working correctly, so the comment that equals works fine is correct: returning False is the correct thing to do if one or both of the objects are a NAN. NANs are supposed to compare unequal to everything, including themselves. The is operator and the == operator do not have the same purpose and they do not do the same thing. "is" should not be considered an improved == without the quirks, this is not PHP and we're not comparing == and ===. The argument here is not about which operator performs the check we want, but over what check we want: do we want an identity test or an equality test? -- Steven D'Aprano http://import-that.dreamwidth.org/ From marko at pacujo.net Sun Mar 2 04:35:43 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 11:35:43 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ha7h9c40.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sat, 01 Mar 2014 19:29:41 +0200, Marko Rauhamaa wrote: >> Michael Torrie : >>> No, '==' works fine no matter what objects you assign to your state >>> variables. >> >> Well, it doesn't since >> >> >>> a = float("nan") >> >>> a is a >> True >> >>> a == a >> False > > No, that is working correctly, so the comment that equals works fine > is correct: returning False is the correct thing to do if one or both > of the objects are a NAN. NANs are supposed to compare unequal to > everything, including themselves. Nobody is saying there's a bug in the implementation of "==". I'm just saying "==" cannot be taken as a universal superset of "is". Therefore a program cannot blindly use "==" to test for identity. That's why "==" is a bit fishy. It immediately raises the question: what does it mean for a == b, especially since the exact implementation of a and b are intended to be opaque. Example: The os module defines the constants os.SEEK_SET, os.SEEK_CUR and os.SEEK_END that can be used as arguments for os.lseek(). Must those constants be used, or can a regular integer be used instead? The documentation clearly states that integers can be used: SEEK_SET or 0 to set the position relative to the beginning of the file; SEEK_CUR or 1 to set it relative to the current position; SEEK_END or 2 to set it relative to the end of the file. However, on the same reference page, os.posix_fadvise() is defined. We read: advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or POSIX_FADV_DONTNEED and: os.POSIX_FADV_NORMAL os.POSIX_FADV_SEQUENTIAL os.POSIX_FADV_RANDOM os.POSIX_FADV_NOREUSE os.POSIX_FADV_WILLNEED os.POSIX_FADV_DONTNEED Flags that can be used in advice in posix_fadvise() Now, what kinds of object are those constants? We are not supposed to know or care. We could peek into the implementation, but it would be a grave mistake to trust the implementation choices in the application. So in my application code I might set: favd_flag = os.POSIX_FADV_RANDOM in some other part of my code I might want to see how "flag" was set. Should I use "==" or "is" to test it? If I take the API documentation on its face value, I *must* use "==" for os.SEEK*: if seek_flag == os.SEEK_END: ... and I *must* use "is" for os.POSIX_FAVD_*: if fsavd_flag is os.POSIX_FADV_RANDOM: ... Since, for all I know, os.POSIX_FAVD_RANDOM might return a random value for __eq__(). Marko From marko at pacujo.net Sun Mar 2 04:40:05 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 11:40:05 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> Message-ID: <87d2i59bwq.fsf@elektro.pacujo.net> Marko Rauhamaa : > If I take the API documentation on its face value, [...] > I *must* use "is" for os.POSIX_FAVD_*: > > if fsavd_flag is os.POSIX_FADV_RANDOM: > ... However, since a documentation flaw is more than likely, it is even more prudent to avoid both "==" and "is" and create a set of shadow constants in the application code: if self.fsavd_flag is self.FAVD_RANDOM: os.posix_fadvice(fd, offset, len, os.POSIX_FAVD_RANDOM): Marko From rosuav at gmail.com Sun Mar 2 04:58:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 20:58:52 +1100 Subject: Mac vs. Linux for Python Development In-Reply-To: References: <2465a8c7-ce0e-4606-ad3b-9135c96e3e4c@googlegroups.com> <4e741358-ce12-40ac-97b8-3bbbf2d6ddca@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 6:35 PM, Frank Millman wrote: > I assume by 'warm cache' you mean that I had used the decimal module before > and not switched the machine off before trying the above exercise. > > In my case, the machine was switched off before I started. I switched it on > and executed the above steps. That would be about it, yeah. So that would be a cold cache test. > To be slightly more precise, instead of 'the blink of an eye', I estimate it > was between 250-500 ms. If I close the interpreter and start it up again, it > takes maybe 100-200ms. Alright, so now we're talking about some other factors on my system that slow down the cold cache load dramatically. That I can completely understand; when I originally posted it, I was fully aware that the exact figures wouldn't be duplicable. 500ms is a major delay to startup; but what's really significant is the 100-200ms warm cache, because that one is what's going to be repeated. (Imagine a web server that periodically restarts its subprocesses - say, every N requests. Adding 200ms to startup time effectively adds 200/N ms to every request.) An awesome disk cache can improve that immensely, though. My Debian box, warm cache, takes 0.0 seconds to import decimal. But it's a faster computer overall, so even cold cache it only takes a hundred ms or so. > Just to be sure, I switched the machine off and on again, and repeated the > exercise. Starting the interpreter for the first time takes 1.5 - 2 seconds. > Importing decimal for the first time takes less than 500ms. I'm beginning to get a suspicion here that the Windows XP disk cache actually might have a "most pessimal" state, where it's full of other stuff. Worse than a cold cache in performance, a cache warmed by something else. But in any case, the exact figures for cold cache are almost immaterial compared to a noticeable warm-cache delay - if there's enough work to be done just loading the .pyc from the disk cache that it takes visible time, then it would be a problem to force that to be loaded on every interpreter startup. Which was kinda the point of my original testing - I wanted to know how much of a penalty there'd be to moving decimal to built-in. ChrisA From rosuav at gmail.com Sun Mar 2 05:07:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Mar 2014 21:07:39 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <87ha7h9c40.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 2, 2014 at 8:35 PM, Marko Rauhamaa wrote: > However, on the same reference page, os.posix_fadvise() is defined. We > read: > > advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, > POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or > POSIX_FADV_DONTNEED > > Now, what kinds of object are those constants? We are not supposed to > know or care. We could peek into the implementation, but it would be a > grave mistake to trust the implementation choices in the application. > > So in my application code I might set: > > favd_flag = os.POSIX_FADV_RANDOM > > in some other part of my code I might want to see how "flag" was set. > Should I use "==" or "is" to test it? In the absence of any advice to the contrary, I would use == to test. The flags are most likely to be, in order: * An enumeration, in a sufficiently new Python * Integers * Strings * Arbitrary object()s All of the above will compare correctly with ==, and if someone stuffs in an object that compares equal to more than one of them, they're likely to have problems at the far end. If identity is really crucial, I would expect there to be a comment in the docs. And there's another thing you can do to test. >>> import os >>> type(os.POSIX_FADV_RANDOM) So use ==. If it's later changed and you have to instead use 'is', you can change your code. ChrisA From marko at pacujo.net Sun Mar 2 05:37:13 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 12:37:13 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> Message-ID: <8761nwanty.fsf@elektro.pacujo.net> Chris Angelico : > And there's another thing you can do to test. > >>>> import os >>>> type(os.POSIX_FADV_RANDOM) > Is that what you do in your programs? > So use ==. If it's later changed and you have to instead use 'is', you > can change your code. Quite a robust API, huh? Anyway, you recognize that the API definer is within their rights to require 'is' semantics for the constants. IOW, the application must use the given constant objects and nothing that happens to be == to them. Consequently, the implementer is within their rights to define: def __eq__(): return True Marko From stefan_ml at behnel.de Sun Mar 2 05:41:56 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 02 Mar 2014 11:41:56 +0100 Subject: why indentation should be part of the syntax Message-ID: Haven't seen any mention of it on this list yet, but since it's such an obvious flaw in quite a number of programming languages, here's a good article on the recent security bug in iOS, which was due to accidentally duplicated code not actually being as indented as it looked: https://www.imperialviolet.org/2014/02/22/applebug.html Stefan From steve+comp.lang.python at pearwood.info Sun Mar 2 05:44:19 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2014 10:44:19 GMT Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> Message-ID: <53130b83$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sun, 02 Mar 2014 11:35:43 +0200, Marko Rauhamaa wrote: > Nobody is saying there's a bug in the implementation of "==". I'm just > saying "==" cannot be taken as a universal superset of "is". Therefore a > program cannot blindly use "==" to test for identity. Um, yes? Nor can you use ">" to test for identity, or "+", or "%", or any other operator other than "is". Why do you think it is a problem that == doesn't test for identity? It's not supposed to test for identity. Why do you want to test for identity? I think I've asked five times now, why you care whether a state value has one instance or a thousand instances, and you haven't even attempted an answer. > That's why "==" is a bit fishy. It immediately raises the question: what > does it mean for a == b, especially since the exact implementation of a > and b are intended to be opaque. It means that a equals b. For ints, it means that they have the same numeric value. The same applies for floats. For strings, it means that they contain the same code points in the same order. And so on. For all built-in types, equality is well-defined. For custom types you create yourself, the onus is on you to ensure that equality is meaningful and well-defined. > Example: > > The os module defines the constants os.SEEK_SET, os.SEEK_CUR and > os.SEEK_END that can be used as arguments for os.lseek(). Must those > constants be used, or can a regular integer be used instead? The > documentation clearly states that integers can be used: > > SEEK_SET or 0 to set the position relative to the beginning of the > file; SEEK_CUR or 1 to set it relative to the current position; > SEEK_END or 2 to set it relative to the end of the file. > > However, on the same reference page, os.posix_fadvise() is defined. We > read: > > advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, > POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or > POSIX_FADV_DONTNEED > > and: > > os.POSIX_FADV_NORMAL > os.POSIX_FADV_SEQUENTIAL > os.POSIX_FADV_RANDOM > os.POSIX_FADV_NOREUSE > os.POSIX_FADV_WILLNEED > os.POSIX_FADV_DONTNEED > > Flags that can be used in advice in posix_fadvise() > > Now, what kinds of object are those constants? We are not supposed to > know or care. Incorrect. We are supposed to know and care. os.posix is exactly the sort of library I mentioned earlier when I said sometimes you're constrained by compatibility with some other system. In this case, the os module is explicitly designed to be compatible with the POSIX interface, which is defined to use certain integer values as flags. This is not an implementation choice which implementers can change at will, it is part of the interface. The specific *values* possibly may be allowed to vary from platform to platform, and since this is C even the definition of "int" may be platform specific, but not that fact that they are ints. Hence the value of POSIX_FADV_RANDOM could, theoretically, be different under Linux and FreeBSD (say). It probably isn't, but it could be. If you hard-code the magic number 1 in your code, you're risking the (tiny) chance of it failing on some obscure POSIX system. But that doesn't imply that we must test for object identity. There could be a million different instances, all with the value POSIX_FADV_RANDOM. Python does not guarantee that there is only a single 1 instance. If you want to test whether a value is os.POSIX_FADV_RANDOM, the right way is to compare that value for equality with os.POSIX_FADV_RANDOM, not identity. > We could peek into the implementation, but it would be a > grave mistake to trust the implementation choices in the application. > So in my application code I might set: > > favd_flag = os.POSIX_FADV_RANDOM A much better choice than hard-coding the magic value 1. But that choice has absolutely nothing to do with whether 1 is a singleton or not. > in some other part of my code I might want to see how "flag" was set. > Should I use "==" or "is" to test it? Equals, of course. There is absolutely no question about that. To even *think* that you should test it with "is" means that you have completely misunderstood what you are doing here. Why are you relying on an implementation detail that CPython happens to cache and reuse small integers like 1? What happens if you run your code under an implementation of Python that doesn't cache small ints? Or if your platform happens to set POSIX_FADV_RANDOM to a non-cached value like 8531201? Python does not promise that POSIX_FADV_RANDOM will be a singleton value. Using "is" is unsafe. > If I take the API documentation on its face value, I *must* use "==" for > os.SEEK*: Correct. > if seek_flag == os.SEEK_END: > ... > > and I *must* use "is" for os.POSIX_FAVD_*: Incorrect. > if fsavd_flag is os.POSIX_FADV_RANDOM: > ... > > Since, for all I know, os.POSIX_FAVD_RANDOM might return a random value > for __eq__(). For all *you* know, perhaps, but since os.posix_fadvise is a thin wrapper around the POSIX C function fadvise, and that is documented as expecting ints for the advice parameter, that cannot be the case. Unfortunately Python has not had the money put into it to make it an ISO standard like Java, and so there are certain areas where the behaviour is known by common practice but not officially documented. (A bit like British common law.) That the os module is a thin wrapper around os- specific services may not be explicitly stated, but it is nevertheless true. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben+python at benfinney.id.au Sun Mar 2 05:59:26 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 02 Mar 2014 21:59:26 +1100 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87r46l96j6.fsf@elektro.pacujo.net> <87zjl93u49.fsf@elektro.pacujo.net> Message-ID: <85r46kkgs1.fsf@benfinney.id.au> Marko Rauhamaa writes: > Ben Finney : > > > The unreliability is ?will objects defined elsewhere have a different > > identity?? > > That question is not interesting in my context, and has no bearing on > the correctness of the program. You keep vacillating between two positions: pick one for the context. Either you care about object identity in this context, and the above observation is relevant. Or, you don't care about object identity in this context, and you should avoid ?is? and use ?==?. But you cannot have both. -- \ ?You know I could rent you out as a decoy for duck hunters?? | `\ ?Groucho Marx | _o__) | Ben Finney From alister.ware at ntlworld.com Sun Mar 2 06:25:31 2014 From: alister.ware at ntlworld.com (Alister) Date: Sun, 02 Mar 2014 11:25:31 GMT Subject: posting code snippets References: <85ppm8nqx7.fsf@benfinney.id.au> Message-ID: On Sun, 02 Mar 2014 09:16:35 +1100, Chris Angelico wrote: > On Sat, Mar 1, 2014 at 1:31 AM, Grant Edwards > wrote: >> You drag out the lab scope, logic analyzer, spectrum analyzer, sweep >> generator, strip plotter, and the machine that goes "ping". You start >> to get everything set up to nail that problem securely to the >> dissecting board. Long before you actually get to that point, the >> problem becomes intimidated and reveals itself and a solution. > > *ALL* my machines go ping. It's fundamental to network debugging. I know > that's not what you meant, but somehow it comes to the same thing. :) > > And yep. That is so absolutely right. Problems know when concealment > becomes pointless. > > ChrisA As a maintenance engineer I find there is also an opposite factor in operation. Equipment manufacturers appear to include an "Engineer Proximity Detector" in all designs that cause the equipment to work flawlessly when triggered. The issue the customer has been complaining about incessantly never occurs whilst there is an engineer on site. -- We're out of slots on the server From marko at pacujo.net Sun Mar 2 06:33:11 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 13:33:11 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> <53130b83$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871tykal8o.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 02 Mar 2014 11:35:43 +0200, Marko Rauhamaa wrote: >> Now, what kinds of object are those constants? We are not supposed to >> know or care. > > Incorrect. We are supposed to know and care. Then, the documentation is seriously flawed. It gives no hint whatsoever on the nature of those objects. > os.posix is exactly the sort of library I mentioned earlier when I > said sometimes you're constrained by compatibility with some other > system. In this case, the os module is explicitly designed to be > compatible with the POSIX interface, which is defined to use certain > integer values as flags. This is not an implementation choice which > implementers can change at will, it is part of the interface. The values of those Python constants don't need to have any relationship with those of the underlying operating system. > Python does not guarantee that there is only a single 1 instance. Nobody has ever argued such a thing. I certainly haven't. However, nothing in the API spec gives you the right to call the function with an integer. > If you want to test whether a value is os.POSIX_FADV_RANDOM, the right > way is to compare that value for equality with os.POSIX_FADV_RANDOM, > not identity. That might well be true but is not explicitly or implicitly specified in the documentation. (The os.SEEK_* constants are explicitly defined.) >> Since, for all I know, os.POSIX_FAVD_RANDOM might return a random value >> for __eq__(). > > For all *you* know, perhaps, but since os.posix_fadvise is a thin > wrapper around the POSIX C function fadvise, and that is documented as > expecting ints for the advice parameter, that cannot be the case. A pretty serious documentation flaw, then. Misleading even. I take it from the documentation that you *must* use the given constant objects and not some improvised integers. > That the os module is a thin wrapper around os- specific services may > not be explicitly stated, but it is nevertheless true. The example was given for illustration purposes; any criticism against the accuracy of the documentation is a sideshow. Marko From Bernd.Nawothnig at t-online.de Sun Mar 2 07:07:02 2014 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sun, 2 Mar 2014 13:07:02 +0100 Subject: why indentation should be part of the syntax References: Message-ID: <6gjbua-ac9.ln1@bernd.nawothnig.dialin.t-online.de> On 2014-03-02, Stefan Behnel wrote: > Haven't seen any mention of it on this list yet, but since it's such an > obvious flaw in quite a number of programming languages, here's a good > article on the recent security bug in iOS, which was due to accidentally > duplicated code not actually being as indented as it looked: > > https://www.imperialviolet.org/2014/02/22/applebug.html The way Perl or Go handles it where it is not possible to omit the curly braces would have prevented the same error too. Bernd -- no time toulouse From gheskett at wdtv.com Sun Mar 2 07:20:49 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 2 Mar 2014 07:20:49 -0500 Subject: posting code snippets In-Reply-To: References: Message-ID: <201403020720.50027.gheskett@wdtv.com> On Sunday 02 March 2014 07:05:06 Alister did opine: > On Sun, 02 Mar 2014 09:16:35 +1100, Chris Angelico wrote: > > On Sat, Mar 1, 2014 at 1:31 AM, Grant Edwards > > > > > > wrote: > >> You drag out the lab scope, logic analyzer, spectrum analyzer, sweep > >> generator, strip plotter, and the machine that goes "ping". You > >> start to get everything set up to nail that problem securely to the > >> dissecting board. Long before you actually get to that point, the > >> problem becomes intimidated and reveals itself and a solution. > > > > *ALL* my machines go ping. It's fundamental to network debugging. I > > know that's not what you meant, but somehow it comes to the same > > thing. :) > > > > And yep. That is so absolutely right. Problems know when concealment > > becomes pointless. > > > > ChrisA > > As a maintenance engineer I find there is also an opposite factor in > operation. > Equipment manufacturers appear to include an "Engineer Proximity > Detector" in all designs that cause the equipment to work flawlessly > when triggered. > > The issue the customer has been complaining about incessantly never > occurs whilst there is an engineer on site. Most sensitive when any cover has been opened. It took me 5 years to find an intermittent video insert problem in a piece of Chyron gear, and when I found it, I called the guy at Chyron whose name was on the schematic page and told him in no uncertain terms that the best part of him ran down his mothers leg. He'd used a spare gate in a quad nand gate package as an inverter, a common practice when you need just one more inverter in a design. Nothing at all wrong with the concept, but the idiot left one of the two inputs floating, disconnected. That is an absolute no-no in any digital logic circuit, and will bite somebody on the ass, repeatedly. And since I could only get at it for not more than 20 minutes at a time because of its duties, I am ashamed that it took me 5 years to find it when the fix was half an inch of wire wrapping wire to tie it to the other input pin. There is not a digital logic chip book on the planet that doesn't contain warnings about floating inputs. Yeah, I CAN be one of those to idiots. As Marion Morrison, aka John Wayne was fond of saying in his movies, stupidity should hurt. And this guy deserved to hurt. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page NOTICE: Will pay 100 USD for an HP-4815A defective but complete probe assembly. From ashish.u.panchal at googlemail.com Sun Mar 2 07:05:14 2014 From: ashish.u.panchal at googlemail.com (Ashish Panchal) Date: Sun, 2 Mar 2014 17:35:14 +0530 Subject: Can tuples be replaced with lists all the time? Message-ID: No, not always. You can use yuples as dictionary key as keys are immutable and you can't use it as list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sun Mar 2 07:32:35 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 2 Mar 2014 05:32:35 -0700 Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> Message-ID: On Sat, Mar 1, 2014 at 7:04 PM, Eric Jacoboni wrote: > In fact, i think i'm gonna forget += on lists :) Well, do what you want, but I think you're taking the wrong lesson from this. Don't forget about using += on lists. Instead, forget about using assignments, augmented or otherwise, on tuple elements. Would you expect this to work? tup = (1, 2, 3) tup[1] += 42 I'm guessing probably not. So I have a hard time understanding why it should be expected to work any differently when the tuple element happens to be a list. The fact that the list is actually modified I think is a distraction from the main point: the error indicates that something illegal happened, not that nothing has changed. Assignments just are not allowed on tuple elements, and it doesn't matter what type they happen to be. From ned at nedbatchelder.com Sun Mar 2 07:36:31 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 02 Mar 2014 07:36:31 -0500 Subject: why indentation should be part of the syntax In-Reply-To: References: Message-ID: On 3/2/14 5:41 AM, Stefan Behnel wrote: > Haven't seen any mention of it on this list yet, but since it's such an > obvious flaw in quite a number of programming languages, here's a good > article on the recent security bug in iOS, which was due to accidentally > duplicated code not actually being as indented as it looked: > > https://www.imperialviolet.org/2014/02/22/applebug.html > > Stefan > As much as I like indentation as syntax, and am amused by this bug, I'm not sure we can chalk it all up to space-vs-brace. After all, who would have wanted two goto's in a row even with braces? It's not like there's some engineer at Apple who meant for the code to read like this: if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) { goto fail; goto fail; } This looks to me like a poorly handled merge conflict maybe? I wonder if we'll ever get the details. -- Ned Batchelder, http://nedbatchelder.com From breamoreboy at yahoo.co.uk Sun Mar 2 08:00:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 13:00:40 +0000 Subject: Can global variable be passed into Python function? In-Reply-To: <85r46kkgs1.fsf@benfinney.id.au> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87r46l96j6.fsf@elektro.pacujo.net> <87zjl93u49.fsf@elektro.pacujo.net> <85r46kkgs1.fsf@benfinney.id.au> Message-ID: On 02/03/2014 10:59, Ben Finney wrote: > Marko Rauhamaa writes: > >> Ben Finney : >> >>> The unreliability is ?will objects defined elsewhere have a different >>> identity?? >> >> That question is not interesting in my context, and has no bearing on >> the correctness of the program. > > You keep vacillating between two positions: pick one for the context. > > Either you care about object identity in this context, and the above > observation is relevant. > > Or, you don't care about object identity in this context, and you should > avoid ?is? and use ?==?. > > But you cannot have both. > Unless you're a troll. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Sun Mar 2 08:04:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 13:04:17 +0000 Subject: Can global variable be passed into Python function? In-Reply-To: <87ha7h9c40.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> Message-ID: On 02/03/2014 09:35, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Sat, 01 Mar 2014 19:29:41 +0200, Marko Rauhamaa wrote: >>> Michael Torrie : >>>> No, '==' works fine no matter what objects you assign to your state >>>> variables. >>> >>> Well, it doesn't since >>> >>> >>> a = float("nan") >>> >>> a is a >>> True >>> >>> a == a >>> False >> >> No, that is working correctly, so the comment that equals works fine >> is correct: returning False is the correct thing to do if one or both >> of the objects are a NAN. NANs are supposed to compare unequal to >> everything, including themselves. > > Nobody is saying there's a bug in the implementation of "==". I'm just > saying "==" cannot be taken as a universal superset of "is". Therefore > a program cannot blindly use "==" to test for identity. > > That's why "==" is a bit fishy. It immediately raises the question: what > does it mean for a == b, especially since the exact implementation of a > and b are intended to be opaque. > > Example: > > The os module defines the constants os.SEEK_SET, os.SEEK_CUR and > os.SEEK_END that can be used as arguments for os.lseek(). Must those > constants be used, or can a regular integer be used instead? The > documentation clearly states that integers can be used: > > SEEK_SET or 0 to set the position relative to the beginning of the > file; SEEK_CUR or 1 to set it relative to the current position; > SEEK_END or 2 to set it relative to the end of the file. > > However, on the same reference page, os.posix_fadvise() is defined. We > read: > > advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, > POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or > POSIX_FADV_DONTNEED > > and: > > os.POSIX_FADV_NORMAL > os.POSIX_FADV_SEQUENTIAL > os.POSIX_FADV_RANDOM > os.POSIX_FADV_NOREUSE > os.POSIX_FADV_WILLNEED > os.POSIX_FADV_DONTNEED > > Flags that can be used in advice in posix_fadvise() > > Now, what kinds of object are those constants? We are not supposed to > know or care. We could peek into the implementation, but it would be a > grave mistake to trust the implementation choices in the application. > > So in my application code I might set: > > favd_flag = os.POSIX_FADV_RANDOM > > in some other part of my code I might want to see how "flag" was set. > Should I use "==" or "is" to test it? > > If I take the API documentation on its face value, I *must* use "==" for > os.SEEK*: > > if seek_flag == os.SEEK_END: > ... > > and I *must* use "is" for os.POSIX_FAVD_*: > > if fsavd_flag is os.POSIX_FADV_RANDOM: > ... > > Since, for all I know, os.POSIX_FAVD_RANDOM might return a random value > for __eq__(). > > > Marko > Will you please be kind enough to stop writing this drivel. You've been told repeatedly that you don't know what you're talking about, so have the decency to just belt up. Now try testing these words for identity. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From davea at davea.name Sun Mar 2 08:22:57 2014 From: davea at davea.name (Dave Angel) Date: Sun, 2 Mar 2014 08:22:57 -0500 (EST) Subject: [OT] Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: Chris Angelico Wrote in message: > On Sun, Mar 2, 2014 at 3:02 PM, Dave Angel wrote: >> The quote you make from the C standard doesn't mention malloc, so >> you're arguing different things. It's not the compiler that casts >> the malloc return value to the struct type. >> >> C++ does implicitly convert the result, and the return value of >> new already has the struct type. But the runtime stores at least >> two kinds of overhead on occasion, the array size, and the >> vtable. So the malloc address can not be assumed to match the >> struct beginning. (Not even considering that one can override > > Whatever pointer malloc returns is the beginning of the *usable* > space. Any overhead for array size etc has to be before that; a > virtual function table pointer would be inside that space, but that's > very much compiler-dependent. > Sure, for some definition of "usable". Overhead such as block size, freelist pointer etc., are obviously outside of the returned block. But the array size that's specified in a call to new [], and the vptr, are definitely inside the malloc'ed block, and may be before the struct data. -- DaveA From thrinass at thrinaxodon.thrinassodon Sun Mar 2 08:28:27 2014 From: thrinass at thrinaxodon.thrinassodon (THRINASSODON1) Date: Sun, 02 Mar 2014 08:28:27 -0500 Subject: HUMANS HAVE ORIGINS IN THE DEVONIAN, AND YOU KNOW IT! Message-ID: ================================ >BREAKING FUCKING NEWS, ASSHOLES! ================================ > THRINAXODON JUST FOUND THREE HUMAN FOSSILS FROM DEVONIAN STRATA IN GREENLAND; THE FOSSILS WERE A HUMAN FEMUR, KNEECAP, AND SKULLCAP. > THE SMITHSONIAN IS CHASTISING OVER THESE FINDS, DOING EVERYTHING IN THEIR POWER TO CENSOR THE TRUTH. > DONATE TO THE BIOLORD9 FOUNDATION TO FIND OUT HOW TO STOP THE SMITHSONIAN FROM CENSORING THE TRUTH, AND LET THE TRUTH THAT HUMAN EVOLUTION IS A SCAM BE REVEALED! > =========================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# ==================================== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON REDDIT -- ---Thrinaxodon From eric.jacoboni at gmail.com Sun Mar 2 08:38:51 2014 From: eric.jacoboni at gmail.com (Eric Jacoboni) Date: Sun, 02 Mar 2014 14:38:51 +0100 Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> Message-ID: Le 02/03/2014 13:32, Ian Kelly a ?crit : > On Sat, Mar 1, 2014 at 7:04 PM, Eric Jacoboni wrote: >> In fact, i think i'm gonna forget += on lists :) > > Well, do what you want, but I think you're taking the wrong lesson > from this. Don't forget about using += on lists. Instead, forget > about using assignments, augmented or otherwise, on tuple elements. > Would you expect this to work? Well, the thing about += on lists that makes me forget it, like i said in my previous post, is that its behaviour is not consistent with +. Don't get me wrong: i don't expect that modifying a tuple element works. That's exactly my point: my initial question was, why it "half works : it should not work at all". I was thinking that += on lists worked like update() or extend() : modifying lists in place... It was my mistake So, yes, i still don't get the point using a += operation, which is not even consistent with the + operation (see my exemple on "spam" in my previous post). The + operator to return the modified list and the update() or extend() methods to do in place replacements are well enough for my present needs. Maybe, in the future, i will find a use case of += for lists which is not covered by others methods, though... Who knows? I don't doubt that Python designers have made this choice and this behavior for a good reason: i've just not get it yet. From breamoreboy at yahoo.co.uk Sun Mar 2 09:05:35 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 14:05:35 +0000 Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> Message-ID: On 02/03/2014 13:38, Eric Jacoboni wrote: > Le 02/03/2014 13:32, Ian Kelly a ?crit : >> On Sat, Mar 1, 2014 at 7:04 PM, Eric Jacoboni wrote: >>> In fact, i think i'm gonna forget += on lists :) >> >> Well, do what you want, but I think you're taking the wrong lesson >> from this. Don't forget about using += on lists. Instead, forget >> about using assignments, augmented or otherwise, on tuple elements. >> Would you expect this to work? > > Well, the thing about += on lists that makes me forget it, like i said > in my previous post, is that its behaviour is not consistent with +. The behaviour is consistent except when you try to modify a tuple. > > Don't get me wrong: i don't expect that modifying a tuple element works. > That's exactly my point: my initial question was, why it "half works : > it should not work at all". I was thinking that += on lists worked like > update() or extend() : modifying lists in place... It was my mistake I'd like to see you get update to work on a list. This shows how confused you are over this issue. > > So, yes, i still don't get the point using a += operation, which is not > even consistent with the + operation (see my exemple on "spam" in my > previous post). The + operator to return the modified list and the > update() or extend() methods to do in place replacements are well enough > for my present needs. Maybe, in the future, i will find a use case of += > for lists which is not covered by others methods, though... Who knows? I > don't doubt that Python designers have made this choice and this > behavior for a good reason: i've just not get it yet. > All of this comes about because of the known issue with tuples. Take them out of the equation and the behaviour of =, +=, extend and append is consistent. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sun Mar 2 09:08:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 01:08:24 +1100 Subject: why indentation should be part of the syntax In-Reply-To: References: Message-ID: On Sun, Mar 2, 2014 at 11:36 PM, Ned Batchelder wrote: > As much as I like indentation as syntax, and am amused by this bug, I'm not > sure we can chalk it all up to space-vs-brace. After all, who would have > wanted two goto's in a row even with braces? It's not like there's some > engineer at Apple who meant for the code to read like this: > > if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) { > goto fail; > goto fail; > } > > This looks to me like a poorly handled merge conflict maybe? I wonder if > we'll ever get the details. Put it this way: If I saw two gotos in a row like that, with or without braces, I would be firing up gitk or git gui blame or something to figure out what happened. But ultimately, it comes down to this: No matter what, the compiler can't catch every bug. That's why we have peer review, test suites, and (above all) the magnificent time machine of source control. "What the <> happened here?" becomes "Huh. I see, someone didn't notice that x and y did a z" when you can see the commit that introduced something. Indentation-as-syntax doesn't prevent weird errors from creeping in - look at this one from the Python stdlib: http://bugs.python.org/issue20729 Notably this bit of code: if hasattr(arg, 'iteritems'): source = arg.items() elif hasattr(arg, 'items'): source = arg.items() else: source = arg It would take an exceedingly weird set of circumstances for this to actually matter, but it's something that looks pretty odd in the code, and no compiler support would help it. Although... to plug my own proposal... PEP 463 exception expressions might have reduced the duplication a bit. But it'd still be possible to get something that looks weird, like: source = (arg.items() except AttributeError: (arg.items() except AttributeError: arg)) or, equally weirdly: source = ((arg.items() except AttributeError: arg.items()) except AttributeError: arg) There's no "easy fix" for this sort of thing. Maybe a linter could have been run over the original C code and flagged a warning (Unexpected indent!), but that's really all. (That actually goes against the subject line. If the indentation is what matters, you can't lint it against the braces, you just get the other odd behaviour.) ChrisA From rosuav at gmail.com Sun Mar 2 08:57:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 00:57:27 +1100 Subject: [OT] Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 12:22 AM, Dave Angel wrote: > Sure, for some definition of "usable". Overhead such as block > size, freelist pointer etc., are obviously outside of the > returned block. But the array size that's specified in a call to > new [], and the vptr, are definitely inside the malloc'ed block, > and may be before the struct data. Hmm. Last I was working with it, the array size to new[] was outside the block, just as the block size to malloc(). The vptr is part of any struct/class with virtual functions, and effectively acts as a hidden class member, so you get one of those inside the block, and it's included in sizeof. //Allocated Space: The Final Frontier! #include //cout sucks :) class Foo { int x; int y; int z; }; class Bar { int x; int y; int z; virtual int get_x() {return x;} }; int main() { printf("sizeof(int) = %u\n",sizeof(int)); printf("sizeof(int*) = %u\n",sizeof(int*)); printf("sizeof(Foo) = %u\n",sizeof(Foo)); printf("sizeof(Bar) = %u\n",sizeof(Bar)); Foo *foo = new Foo[10]; printf("foo = %p/%p = %u\n",foo,foo+10,(char *)(foo+10)-(char *)foo); Bar *bar = new Bar[10]; printf("bar = %p/%p = %u\n",bar,bar+10,(char *)(bar+10)-(char *)bar); return 0; } rosuav at sikorsky:~$ g++ frontier.cpp && ./a.out sizeof(int) = 4 sizeof(int*) = 8 sizeof(Foo) = 12 sizeof(Bar) = 24 foo = 0xf38010/0xf38088 = 120 bar = 0xf38090/0xf38180 = 240 The rules of structs are that they be contiguous, that they be laid out sequentially, and that any padding needed between structures is at the end of the previous one (which is why three of 4 bytes makes 12 bytes, but three of 4 bytes plus 8 bytes makes 24 - the eight-byte pointer has to be aligned on a multiple of eight bytes, so having a 20-byte structure that starts with an 8-byte pointer is a no-no). The allocated block of memory is, by definition, the same as the pointer to its first element. As it happens, the pointer bar is not synonymous with &bar->x, &bar->y, or &bar->z, which means the vptr is at the beginning of bar, which makes sense; but the compiler's not obliged to do that, and in some cases may choose not to - for instance, if bar (with a virtual function) inherited from foo (with none), it might be convenient to allow a pointer-cast to not change the value of the pointer. (g++ 4.7.2 still puts the vptr at the beginning of bar in that case, but other compilers or other versions may differ.) Array size is outside the block, presumably before it, as &foo[0] is by definition identical to foo, and there's no room inside the structure for any spare data. Virtual function table is inside the block because it's a hidden member of the object (like __class__ in Python, only better hidden). ChrisA From eric.jacoboni at gmail.com Sun Mar 2 09:17:11 2014 From: eric.jacoboni at gmail.com (Eric Jacoboni) Date: Sun, 02 Mar 2014 15:17:11 +0100 Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> Message-ID: Le 02/03/2014 15:05, Mark Lawrence a ?crit : > The behaviour is consistent except when you try to modify a tuple. > Not in my opinion... li = [10, 30] li = li + "spam" --> TypeError: can only concatenate list (not "str") li += "spam" --> Ok So, not, that's not what i call consistent. And it's not related to tuples... > I'd like to see you get update to work on a list. This shows how > confused you are over this issue. Well, sorry, i wanted to write .append() From python.list at tim.thechases.com Sun Mar 2 09:28:34 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 2 Mar 2014 08:28:34 -0600 Subject: why indentation should be part of the syntax In-Reply-To: References: Message-ID: <20140302082834.02d8ce42@bigbox.christie.dr> On 2014-03-03 01:08, Chris Angelico wrote: > > if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) > > { goto fail; > > goto fail; > > } > > Put it this way: If I saw two gotos in a row like that, with or > without braces, I would be firing up gitk or git gui blame or > something to figure out what happened. That depends on actually seeing them in the first place :-) Computers are great -- it's the people interacting with them (both on the coding-end and the user-end) that cause problems every time ;-) -tkc From albert.visser at gmail.com Sun Mar 2 09:37:44 2014 From: albert.visser at gmail.com (albert visser) Date: Sun, 02 Mar 2014 15:37:44 +0100 Subject: Tuples and immutability In-Reply-To: References: <059a3d10-453a-40fd-99f9-33ceb8ecabf7@googlegroups.com> <889d371a-c8e3-4d6b-8ba4-d3df61f29b0d@googlegroups.com> Message-ID: On Sun, 02 Mar 2014 15:17:11 +0100, Eric Jacoboni wrote: > Le 02/03/2014 15:05, Mark Lawrence a ?crit : > >> The behaviour is consistent except when you try to modify a tuple. >> > > Not in my opinion... > > li = [10, 30] > li = li + "spam" --> TypeError: can only concatenate list (not "str") > li += "spam" --> Ok > possibly because you expect += to take "spam" as a string, but have you looked at the result? In [1]: mylist = ['1', '2'] In [2]: mylist += 'spam' In [3]: mylist Out[3]: ['1', '2', 's', 'p', 'a', 'm'] consequently, try adding something that can not be interpreted as a sequence: In [4]: mylist += 3 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () ----> 1 mylist += 3 TypeError: 'int' object is not iterable -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ From roy at panix.com Sun Mar 2 09:38:50 2014 From: roy at panix.com (Roy Smith) Date: Sun, 02 Mar 2014 09:38:50 -0500 Subject: why indentation should be part of the syntax References: Message-ID: In article , Stefan Behnel wrote: > Haven't seen any mention of it on this list yet, but since it's such an > obvious flaw in quite a number of programming languages, here's a good > article on the recent security bug in iOS, which was due to accidentally > duplicated code not actually being as indented as it looked: > > https://www.imperialviolet.org/2014/02/22/applebug.html > > Stefan Hogwash. What this looks like is two gotos in a row. Anybody who reviewed this code would have thrown up a red flag when they saw two gotos in a row. If anything, the "incorrect" indentation makes it even more obvious. Any static code analyzer would have also caught this as an unreachable statement. Paraphrasing this into Python, you get: def bogus(): if SSLHashSHA1.update(hashCtx, serverRandom) != 0: raise fail if SSLHashSHA1.update(hashCtx, signedParams) != 0: raise fail raise fail if SSLHashSHA1.final(hashCtx, hashOut) != 0: raise fail which is syntactically valid (at least, I can import it), but clearly not what the author intended. So how did Python's indentation rules save us? On the other hand, the Python code was actually a little annoying to type in because emacs refused to auto-indent the second raise! So maybe the real rule is to only write code using emacs :-) From geniusrko at gmail.com Sun Mar 2 09:43:48 2014 From: geniusrko at gmail.com (geniusrko at gmail.com) Date: Sun, 2 Mar 2014 06:43:48 -0800 (PST) Subject: Boxes of O's In-Reply-To: References: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> Message-ID: <729104f4-92f8-48a3-9b7c-e7ba4fb6a38e@googlegroups.com> I agree with you and really appreciate your experience. But what I was looking for is clues. Thank you anyway From breamoreboy at yahoo.co.uk Sun Mar 2 09:56:55 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 14:56:55 +0000 Subject: Boxes of O's In-Reply-To: <729104f4-92f8-48a3-9b7c-e7ba4fb6a38e@googlegroups.com> References: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> <729104f4-92f8-48a3-9b7c-e7ba4fb6a38e@googlegroups.com> Message-ID: On 02/03/2014 14:43, geniusrko at gmail.com wrote: > I agree with you and really appreciate your experience. But what I was looking for is clues. Thank you anyway > Sorry, can't resist this one https://www.youtube.com/watch?v=oaGpaj2nHIo :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Sun Mar 2 10:26:46 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 17:26:46 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87y50vwjq4.fsf@elektro.pacujo.net> <87d2i7wbxs.fsf@elektro.pacujo.net> <87bnxp58t7.fsf@elektro.pacujo.net> Message-ID: <87fvn08vux.fsf@elektro.pacujo.net> Marko Rauhamaa : > Roy Smith : > >> Python already has a switch statement. It's just spelled funny... >> >> [...] >> >> try: >> raise value >> except Case1: >> print "did case 1" >> except (Case2, Case3): >> print "did either case 2 or 3" >> else: >> print "did default" > > Not bad! Definitely worth considering. I wrote a simple test that switched between 26 "enums" using three techniques and measured execution times (2,600,000 switching operations). I also measured the time with no switching and subtracted that time from the test times. Results of the competition (performed with python3.2.3): 1. DICT DISPATCH TABLE (0.2 ?s/switch) 2. IF-ELSE CHAIN (850% slower than DICT DISPATCH TABLE) 3. TRY-EXCEPT (3500% slower than DICT DISPATCH TABLE) Marko From roy at panix.com Sun Mar 2 10:34:33 2014 From: roy at panix.com (Roy Smith) Date: Sun, 02 Mar 2014 10:34:33 -0500 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87y50vwjq4.fsf@elektro.pacujo.net> <87d2i7wbxs.fsf@elektro.pacujo.net> <87bnxp58t7.fsf@elektro.pacujo.net> <87fvn08vux.fsf@elektro.pacujo.net> Message-ID: In article <87fvn08vux.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > Marko Rauhamaa : > > > Roy Smith : > > > >> Python already has a switch statement. It's just spelled funny... > >> > >> [...] > >> > >> try: > >> raise value > >> except Case1: > >> print "did case 1" > >> except (Case2, Case3): > >> print "did either case 2 or 3" > >> else: > >> print "did default" > > > > Not bad! Definitely worth considering. > > [...] > 3. TRY-EXCEPT (3500% slower than DICT DISPATCH TABLE) I'm glad to hear that. I hope nobody took me seriously when I suggested this. From marko at pacujo.net Sun Mar 2 10:52:07 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 17:52:07 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87y50vwjq4.fsf@elektro.pacujo.net> <87d2i7wbxs.fsf@elektro.pacujo.net> <87bnxp58t7.fsf@elektro.pacujo.net> <87fvn08vux.fsf@elektro.pacujo.net> Message-ID: <87a9d88uoo.fsf@elektro.pacujo.net> Roy Smith : > In article <87fvn08vux.fsf at elektro.pacujo.net>, > Marko Rauhamaa wrote: >> 3. TRY-EXCEPT (3500% slower than DICT DISPATCH TABLE) > > I'm glad to hear that. I hope nobody took me seriously when I > suggested this. I actually have employed the idea before in a related but slightly different use case. Anyway, it's extremely close to the switch statement's use case and should give some guidance if a proper switch statement is ever worked into the language. What's killing the performance is the backtrace generation and longjmp trickery. If an analogous syntax could be (A) separated from BaseException and (B) compiled into a dict, we could have a winner. Marko From rmorgan466 at gmail.com Sun Mar 2 10:56:56 2014 From: rmorgan466 at gmail.com (Rita) Date: Sun, 2 Mar 2014 10:56:56 -0500 Subject: source code control and documentation Message-ID: Hi, I am trying to achieve this, every time I commit to svn I automatically run hooks to test my libraries, ATM I am doing this manually cd libs PYTHONPATH=. python test_lib.py and if everything passes I do a svn commit -m 'committing code' I don't have access to my svn server so I can't create my own hooks (or can I?) Also, I would like to auto-document my library and project so, when I do a svn commit I would like to generate a sphinix-doc (and I am open to suggestions). In the source code do I need to do anything special to my Classes and Functions? class myClass(object): ""do I need to do anything special here"""? Ideally, I would like to automatically draw a UML diagram since my codebase is rather large. How do people achieve this? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Mar 2 11:02:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 03:02:32 +1100 Subject: source code control and documentation In-Reply-To: References: Message-ID: On Mon, Mar 3, 2014 at 2:56 AM, Rita wrote: > I am trying to achieve this, every time I commit to svn I automatically run > hooks to test my libraries, ATM I am doing this manually > > cd libs > PYTHONPATH=. python test_lib.py > > and if everything passes I do a svn commit -m 'committing code' > > I don't have access to my svn server so I can't create my own hooks (or can > I?) This is really a subversion question, not a Python one. But this much I'll say: svn is vastly inferior to modern version control systems like git and Mercurial (the latter being written in Python and used for CPython and many other Python-related projects). You can easily import your svn history into either git or Mercurial (at least, I'm pretty sure Mercurial offers good import facilities - if not, there are ways around the problem), so you won't lose anything by switching. And hook support is excellent. Personally, I'm very friendly with git - we work together really well. Mercurial and I are like business acquaintances that don't see each other quite as often, and interactions are a bit more formal and stilted. But I know that either one will serve you well, and far more easily than svn does. ChrisA From rosuav at gmail.com Sun Mar 2 11:23:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 03:23:10 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <87a9d88uoo.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87y50vwjq4.fsf@elektro.pacujo.net> <87d2i7wbxs.fsf@elektro.pacujo.net> <87bnxp58t7.fsf@elektro.pacujo.net> <87fvn08vux.fsf@elektro.pacujo.net> <87a9d88uoo.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 3, 2014 at 2:52 AM, Marko Rauhamaa wrote: > Roy Smith : > >> In article <87fvn08vux.fsf at elektro.pacujo.net>, >> Marko Rauhamaa wrote: >>> 3. TRY-EXCEPT (3500% slower than DICT DISPATCH TABLE) >> >> I'm glad to hear that. I hope nobody took me seriously when I >> suggested this. > > I actually have employed the idea before in a related but slightly > different use case. > > Anyway, it's extremely close to the switch statement's use case and > should give some guidance if a proper switch statement is ever worked > into the language. What's killing the performance is the backtrace > generation and longjmp trickery. If an analogous syntax could be (A) > separated from BaseException and (B) compiled into a dict, we could have > a winner. The trouble is, try/except fundamentally can't be compiled into a dict, because Python's exception handling is based on subclasses. try: func() except FileNotFoundError: pass except OSError: raise RuntimeError("Oops") except Exception as e: log(e) except: log("Aborting!"); raise finally: log("Done") How would you handle that with a dict? It's inherently ordered - a FileNotFoundError would be caught by any one of those clauses, and since there's no sane way to "pick the narrowest", the best way to handle it is sequential evaluation. (Also, it's worth noting that exception lists are not constants. It's possible to do downright insane things like calling a function to figure out what exceptions to handle. Yeah, that's pretty stupid, right there.) A switch block that works with constants and equality *can* be turned into a dict. If the constants are hashable, use them as the keys directly; if they're not hashable and/or you want to use object identity as the criterion (effectively like using 'is' rather than '==' for your case statements), use id(x) as the keys, and make sure you have other references to the objects. Then it'll be fine as a straight-up dict. If the switch block uses inequalities, then it suffers from the same problem as the try/except block - it's inherently ordered, in case (pun intended) there's a switched-on value that matches more than one. (You could possibly optimize the int case, but that would be way WAY too specific for a generic language structure.) ChrisA From scigenium at gmail.com Sun Mar 2 11:24:38 2014 From: scigenium at gmail.com (scigenium at gmail.com) Date: Sun, 2 Mar 2014 08:24:38 -0800 (PST) Subject: Job - Senior Python Engineer - User Interface Applications, Cambridge MA Message-ID: Senior Python Engineer - User Interface Applications Location : Cambridge MA Who We Are: Gen9 is transforming synthetic biology by creating novel technologies to increase innovation within several industries including biopharmaceuticals, fine chemicals and bio-fuels. Currently such genes are synthesized 'one at a time' resulting in high-cost low-capacity gene synthesis capabilities in the marketplace. Gen9 is building the first 'fab' for synthetic biology -- the BioFab(R) platform -- based on next generation gene synthesis technologies. The BioFab(R) platform was chosen by "The Scientist" as the #1 innovation of 2012. Position summary: Gen9 is looking for a senior software engineer to contribute to software architecture that will help to scale our next-generation DNA synthesis platform. The ideal candidate will be comfortable with a range of responsibilities as a member of a small, efficient team. Responsibilities: * Design and develop user-friendly web-based applications to improve work flow management, support scale up of production processes, and query information for data mining and analysis to better enable all aspects of our business * Support infrastructure and provide code base maintenance (documentation, testing, and revision control) * Respond to R&D and Manufacturing requests for custom requirements on an as needed basis Requirements: * BS/ MS in computer science, bioinformatics, or related degree plus 5-7 years of industry experience, or equivalent combination of education and experience * 3+ years of experience using and developing within UNIX/Linux environments * Demonstrated proficiency with Python, JavaScript, and CSS * Demonstrated experience with SQL and database modeling * Demonstrated ability to work effectively and with minimal supervision in a small collaborative team * Demonstrated ability to multi-task and manage numerous activities simultaneously * Strong communication, documentation, and presentation skills * Familiarity with biology is not required, but is beneficial HOW TO APPLY: Send resume & cover letter to: resumes at gen9bio.com. Please briefly describe your skills, knowledge, and experience with the Required Qualifications in your cover letter/email. From invalid at invalid.invalid Sun Mar 2 11:45:28 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 2 Mar 2014 16:45:28 +0000 (UTC) Subject: [OT] Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: On 2014-03-02, Dave Angel wrote: > Grant Edwards Wrote in message: >> On 2014-02-24, Michael Torrie wrote: >> >>> >>> Why would you think that? The address of the start of your malloc'ed >>> structure is the same as the address of the first element. Surely >>> this is logical? >> >> Not only is it logical, the C standard explicitly requires it. Here's >> a second-hand citation since I don't happend to have an actual copy of >> the standard on hand: >> >> C1x ???6.7.2.1.13: >> >> A pointer to a structure object, suitably converted, points to >> its initial member ... and vice versa. There may be unnamed >> padding within a structure object, but not at its beginning. > > The quote you make from the C standard doesn't mention malloc, so > you're arguing different things. No, I'm not. A pointer to a structure object and a pointer to it's first field are the same. It doesn't matter where the object came from. > It's not the compiler that casts the malloc return value to the > struct type. That's irrelevent. The actual location of the memory containing the struct object (static, stack, heap, shared) doesn't matter. The address of the first field in a struture object _is_ the address of the structure object. -- Grant From breamoreboy at yahoo.co.uk Sun Mar 2 11:53:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 16:53:06 +0000 Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87y50vwjq4.fsf@elektro.pacujo.net> <87d2i7wbxs.fsf@elektro.pacujo.net> <87bnxp58t7.fsf@elektro.pacujo.net> <87fvn08vux.fsf@elektro.pacujo.net> <87a9d88uoo.fsf@elektro.pacujo.net> Message-ID: On 02/03/2014 16:23, Chris Angelico wrote: > > A switch block that works with constants and equality *can* be turned > into a dict. If the constants are hashable, use them as the keys > directly; if they're not hashable and/or you want to use object > identity as the criterion (effectively like using 'is' rather than > '==' for your case statements), use id(x) as the keys, and make sure > you have other references to the objects. Then it'll be fine as a > straight-up dict. > > If the switch block uses inequalities, then it suffers from the same > problem as the try/except block - it's inherently ordered, in case > (pun intended) there's a switched-on value that matches more than one. > (You could possibly optimize the int case, but that would be way WAY > too specific for a generic language structure.) > > ChrisA > You clearly don't get my point. I *DON'T* want to use stupid constants and stupid equalities, I want to use identities. I *DON'T* want to use stupid ==, I want to use 'is'. I *DON'T* care how many people with years of experience of Python tell me that this is the wrong thing to do, that is how I am going to do it. So, for the final time of asking, how do I do the above with, and only with, the identity, even if you stupidly keep on trying to tell me that this is wrong? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Sun Mar 2 11:55:49 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 16:55:49 +0000 Subject: [OT] Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: On 02/03/2014 16:45, Grant Edwards wrote: > > That's irrelevent. The actual location of the memory containing the > struct object (static, stack, heap, shared) doesn't matter. The > address of the first field in a struture object _is_ the address of > the structure object. > You say struture, I'll say structure, let's call the whole thing off :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From torriem at gmail.com Sun Mar 2 13:48:15 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 02 Mar 2014 11:48:15 -0700 Subject: Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> Message-ID: <53137CEF.6070205@gmail.com> On 03/02/2014 03:07 AM, Chris Angelico wrote: > >>>> import os >>>> type(os.POSIX_FADV_RANDOM) > > > So use ==. If it's later changed and you have to instead use 'is', you > can change your code. I don't see why == wouldn't continue to work if os.POSIX_FADV_RANDOM became an object of a different type. From nicholas.cole at gmail.com Sun Mar 2 14:08:42 2014 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 2 Mar 2014 19:08:42 +0000 Subject: why indentation should be part of the syntax In-Reply-To: References: Message-ID: On Sun, Mar 2, 2014 at 2:38 PM, Roy Smith wrote: > In article , > Stefan Behnel wrote: > >> Haven't seen any mention of it on this list yet, but since it's such an >> obvious flaw in quite a number of programming languages, here's a good >> article on the recent security bug in iOS, which was due to accidentally >> duplicated code not actually being as indented as it looked: >> >> https://www.imperialviolet.org/2014/02/22/applebug.html >> >> Stefan > > Hogwash. What this looks like is two gotos in a row. Anybody who > reviewed this code would have thrown up a red flag when they saw two > gotos in a row. If anything, the "incorrect" indentation makes it even > more obvious. Any static code analyzer would have also caught this as > an unreachable statement. > > Paraphrasing this into Python, you get: > > def bogus(): > if SSLHashSHA1.update(hashCtx, serverRandom) != 0: > raise fail > if SSLHashSHA1.update(hashCtx, signedParams) != 0: > raise fail > raise fail > if SSLHashSHA1.final(hashCtx, hashOut) != 0: > raise fail > > which is syntactically valid (at least, I can import it), but clearly > not what the author intended. So how did Python's indentation rules > save us? Actually, that's incorrect. The bug (written in Python) would have been: if SSLHashSHA1.update(hashCtx, signedParams) != 0: raise fail raise fail # ie. no indent. If written with the indent, it's a useless line of code, but it doesn't become a bug. From davea at davea.name Sun Mar 2 14:17:41 2014 From: davea at davea.name (Dave Angel) Date: Sun, 2 Mar 2014 14:17:41 -0500 (EST) Subject: [OT] Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: Chris Angelico Wrote in message: > On Mon, Mar 3, 2014 at 12:22 AM, Dave Angel wrote: >> Sure, for some definition of "usable". Overhead such as block >> size, freelist pointer etc., are obviously outside of the >> returned block. But the array size that's specified in a call to >> new [], and the vptr, are definitely inside the malloc'ed block, >> and may be before the struct data. > > Hmm. Last I was working with it, the array size to new[] was outside > the block, just as the block size to malloc(). The vptr is part of any > struct/class with virtual functions, and effectively acts as a hidden > class member, so you get one of those inside the block, and it's > included in sizeof. > > //Allocated Space: The Final Frontier! > #include //cout sucks :) > > class Foo > { > int x; > int y; > int z; > }; > > class Bar > { > int x; > int y; > int z; > virtual int get_x() {return x;} > }; > > int main() > { > printf("sizeof(int) = %u\n",sizeof(int)); > printf("sizeof(int*) = %u\n",sizeof(int*)); > printf("sizeof(Foo) = %u\n",sizeof(Foo)); > printf("sizeof(Bar) = %u\n",sizeof(Bar)); > Foo *foo = new Foo[10]; > printf("foo = %p/%p = %u\n",foo,foo+10,(char *)(foo+10)-(char *)foo); > Bar *bar = new Bar[10]; > printf("bar = %p/%p = %u\n",bar,bar+10,(char *)(bar+10)-(char *)bar); > return 0; > } > > > rosuav at sikorsky:~$ g++ frontier.cpp && ./a.out > sizeof(int) = 4 > sizeof(int*) = 8 > sizeof(Foo) = 12 > sizeof(Bar) = 24 > foo = 0xf38010/0xf38088 = 120 > bar = 0xf38090/0xf38180 = 240 > > > > The rules of structs are that they be contiguous, that they be laid > out sequentially, and that any padding needed between structures is at > the end of the previous one (which is why three of 4 bytes makes 12 > bytes, but three of 4 bytes plus 8 bytes makes 24 - the eight-byte > pointer has to be aligned on a multiple of eight bytes, so having a > 20-byte structure that starts with an 8-byte pointer is a no-no). The > allocated block of memory is, by definition, the same as the pointer > to its first element. As it happens, the pointer bar is not synonymous > with &bar->x, &bar->y, or &bar->z, which means the vptr is at the > beginning of bar, which makes sense; but the compiler's not obliged to > do that, and in some cases may choose not to - for instance, if bar > (with a virtual function) inherited from foo (with none), it might be > convenient to allow a pointer-cast to not change the value of the > pointer. (g++ 4.7.2 still puts the vptr at the beginning of bar in > that case, but other compilers or other versions may differ.) > > Array size is outside the block, presumably before it, as &foo[0] is > by definition identical to foo, and there's no room inside the > structure for any spare data. Virtual function table is inside the > block because it's a hidden member of the object (like __class__ in > Python, only better hidden). > Array size is inside the malloc block, but outside the struct block. As you can see if you try to delete without the brackets when you used new [], some runtimes will crash. This is not to say that there will always be these extra offsets, just that they can be there. -- DaveA From rosuav at gmail.com Sun Mar 2 14:24:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 06:24:16 +1100 Subject: [OT] Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 3:55 AM, Mark Lawrence wrote: > On 02/03/2014 16:45, Grant Edwards wrote: >> >> >> That's irrelevent. The actual location of the memory containing the >> struct object (static, stack, heap, shared) doesn't matter. The >> address of the first field in a struture object _is_ the address of >> the structure object. >> > > You say struture, I'll say structure, let's call the whole thing off :) :) Note that, technically, Grant is correct as long as you grant (heh) that a structure may have an invisible member, the virtual function table pointer. C++ only (I don't believe C has virtual functions - but it may have grown them in one of the newer standards), so in C, all members are public. With an array, the array's pointer *is* the same as the pointer to its first member, because adding zero to a pointer does nothing, and x <-> &x[0] <-> &(*(x+0)). ChrisA From christian at python.org Sun Mar 2 14:25:24 2014 From: christian at python.org (Christian Heimes) Date: Sun, 02 Mar 2014 20:25:24 +0100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On 01.03.2014 21:11, Chris Angelico wrote: > The problem isn't SHA-256. The problem is insecure passwords, the way > we've been taught to make them by the banks. Hence, XKCD 936. Your argumentation is just wrong. You are saying "It's OK to use a totally insecure way to hash passwords because passwords are insecure". The point of KDF and KSA is to derive some token from a low entropy source (human input) that makes an attack harder. Please do your reading and trust secure experts on algorithms like PBKDF2, bcrypt and scrypt. hash(salt + password) is outdated and proven to be insecure for at least a decade, more like 15+ years. The concept of passwords itself is insecure. But we are stuck with passwords for authentication mechanism for the foreseeable future. 2FA is an attempt to increase the security of passwords-based authentication schemes. Christian From rosuav at gmail.com Sun Mar 2 14:32:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 06:32:28 +1100 Subject: [OT] Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 6:17 AM, Dave Angel wrote: > Array size is inside the malloc block, but outside the struct > block. As you can see if you try to delete without the brackets > when you used new [], some runtimes will crash. As in, you have to use "delete [] x" to correspond with "x = new whatever[n]"? Yes, that's right, but that array size is earlier in memory than x itself. I can pretend that x is the same as one declared statically as "whatever x[n]", and it'll function the same way. When new[] is implemented using malloc(), it'll be something like this: { data = malloc(n * sizeof(whatever) + sizeof n); *(int *)data = n; return ((int *)data)+1; } so in that case, the array size is inside the malloc'd block, but it's still invisible to the calling function. A fully compliant C++ implementation could choose to store that elsewhere, in some kind of lookup table - it could then easily catch bugs like "delete malloc(1)", "delete [] malloc(1)", "delete [] new whatever", and "delete new whatever[1]" (because the pointer given wouldn't be in the 'new' table or the 'new[]' table, respectively). ChrisA From as at sci.fi Sun Mar 2 14:40:46 2014 From: as at sci.fi (Anssi Saari) Date: Sun, 02 Mar 2014 21:40:46 +0200 Subject: passing an option to the python interpreter References: <871tz4kn6p.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Jabba Laci : > >> I tried this: >> >> #!/usr/bin/env python -u > > The hash-bang notation is quite rigid; it only accepts a single argument > ("python") to the command ("/usr/bin/env"). > > I don't know if there is a simple workaround. Using the relevant environment variable (PYTHONUNBUFFERED) seems simple to me. From roy at panix.com Sun Mar 2 15:01:09 2014 From: roy at panix.com (Roy Smith) Date: Sun, 02 Mar 2014 15:01:09 -0500 Subject: Password validation security issue References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: In article , Christian Heimes wrote: > On 01.03.2014 21:11, Chris Angelico wrote: > > The problem isn't SHA-256. The problem is insecure passwords, the way > > we've been taught to make them by the banks. Hence, XKCD 936. > > Your argumentation is just wrong. You are saying "It's OK to use a > totally insecure way to hash passwords because passwords are insecure". > The point of KDF and KSA is to derive some token from a low entropy > source (human input) that makes an attack harder. Please do your reading > and trust secure experts on algorithms like PBKDF2, bcrypt and > scrypt. hash(salt + password) is outdated and proven to be insecure for > at least a decade, more like 15+ years. > > The concept of passwords itself is insecure. But we are stuck with > passwords for authentication mechanism for the foreseeable future. 2FA > is an attempt to increase the security of passwords-based authentication > schemes. > > Christian Security is as much about cryptography as it is about human factors and business drivers. You can make things resistant to brute-force attacks by using longer keys, but people are still going to pick bad passwords. You can force them to pick "good" passwords by rejecting their first 37 choices, but all that does is encourage them to write the passwords down on sticky notes. And, yes, you can make things more secure with 2FA, but there's a cost there. You have to purchase and manage the infrastructure. More than that, there's lost business if potential customers prefer a competitor's product because it's easier to access. Many of the known insecure systems we use today are not that way because the people who run them are stupid; they're that way because the people who run them have worked the numbers and decided the cost to implement more secure systems would exceed the risk exposure. We recently got a frothing email from a user, which basically said, "You farking idiots, you emailed me my password in plain text!" It turns out, his user name was the same as his password and what we had sent him (in response to an account recovery query) was his username. In response to that, we altered our account generation process to forbid passwords which are too similar to your chosen username or email address. Which, of course, means we've taken one more step down the road to forcing our users to write their passwords on sticky notes. From rosuav at gmail.com Sun Mar 2 15:32:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 07:32:16 +1100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 7:01 AM, Roy Smith wrote: > We recently got a frothing email from a user, which basically said, "You > farking idiots, you emailed me my password in plain text!" It turns > out, his user name was the same as his password and what we had sent him > (in response to an account recovery query) was his username. Sadly, there *are* systems that will actually email passwords in plain text, and don't tell you so beforehand (Mailman at least tells you that the password isn't meant for security). I met one recently. Did not appreciate that. Fortunately when I changed my password, the new password wasn't emailed back to me. ChrisA From marko at pacujo.net Sun Mar 2 16:03:30 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 02 Mar 2014 23:03:30 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> Message-ID: <87txbg48kd.fsf@elektro.pacujo.net> Michael Torrie : > I don't see why == wouldn't continue to work if os.POSIX_FADV_RANDOM > became an object of a different type. It probably would. If one were begging for trouble, one *could* define: class ABC: A = 1 B = 1.0 C = 1+0j Now: ABC.A == ABC.B ABC.B == ABC.C ABC.C == ABC.A but: ABC.A is not ABC.B ABC.B is not ABC.C ABC.C is not ABC.A Marko From roy at panix.com Sun Mar 2 16:16:14 2014 From: roy at panix.com (Roy Smith) Date: Sun, 02 Mar 2014 16:16:14 -0500 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> <87txbg48kd.fsf@elektro.pacujo.net> Message-ID: In article <87txbg48kd.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > Michael Torrie : > > > I don't see why == wouldn't continue to work if os.POSIX_FADV_RANDOM > > became an object of a different type. > > It probably would. > > If one were begging for trouble, one *could* define: > > class ABC: > A = 1 > B = 1.0 > C = 1+0j > > Now: > > ABC.A == ABC.B > ABC.B == ABC.C > ABC.C == ABC.A > > but: > > ABC.A is not ABC.B > ABC.B is not ABC.C > ABC.C is not ABC.A > > > Marko On can do all sorts of bizarre things. If you wish to shoot yourself in the foot, Python is happy to provide the gun. class ABC(object): _instance = None def __new__(cls): if cls._instance is None: i = object.__new__(cls) i.__class__ = ABC cls._instance = i return cls._instance def __eq__(self, other): return False a = ABC() b = ABC() print a is b print a == b From rosuav at gmail.com Sun Mar 2 16:28:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 08:28:17 +1100 Subject: Can global variable be passed into Python function? In-Reply-To: <87txbg48kd.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> <87txbg48kd.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 3, 2014 at 8:03 AM, Marko Rauhamaa wrote: > If one were begging for trouble, one *could* define: > > class ABC: > A = 1 > B = 1.0 > C = 1+0j You're missing the point of flags, though. One does not use floats for flags. Flags are normally going to be integers (passed directly to an underlying C API), strings (self-documenting), or arbitrary objects with no value beyond their identities. In all cases, value equality is the normal way to recognize them, except in the special case of bit-flag integers, where you use bitwise operations (and then equality checks, possibly): DIRECTORY = 512 # Not sure that one's right, tbh OWNER_READ = 256 OWNER_WRITE = 128 OWNER_EXEC = 64 GROUP_READ = 32 ... OTHERS_EXEC = 1 mode = 1005 if mode & DIRECTORY: # It's a directory! if mode & OTHERS_READ: # You're allowed to read (eg 'ls') if mode & GROUP_EXEC: # You get the idea. With multi-bit flags you might have to do a bitwise AND followed by an equality check: NOT_STICKY = 0 STICKY_PARTIAL = 16 STICKY_MOSTLY = 32 STICKY_ENTIRELY = 48 STICKY_BITS = 48 if style & STICKY_BITS == STICKY_MOSTLY: # I've no idea what this means, actually At no time can you do identity checks. It might happen to work with the lower bit values and CPython, but when you check the 2048 bit, you don't get that. Value is all that matters. ChrisA From yoavglazner at gmail.com Sun Mar 2 16:30:03 2014 From: yoavglazner at gmail.com (Glazner) Date: Sun, 2 Mar 2014 13:30:03 -0800 (PST) Subject: Boxes of O's In-Reply-To: <729104f4-92f8-48a3-9b7c-e7ba4fb6a38e@googlegroups.com> References: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> <729104f4-92f8-48a3-9b7c-e7ba4fb6a38e@googlegroups.com> Message-ID: <86560890-42bb-4090-a178-1669d4486dcf@googlegroups.com> On Sunday, March 2, 2014 4:43:48 PM UTC+2, geni... at gmail.com wrote: > I agree with you and really appreciate your experience. But what I was looking for is clues. Thank you anyway #not tested for i in range(n): for j in range(n*2): if i in (0, n - 1) or j in (0, n*2 - 1): print('o', end='') else: print(' ', end='') print() From torriem at gmail.com Sun Mar 2 16:44:08 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 02 Mar 2014 14:44:08 -0700 Subject: Can global variable be passed into Python function? In-Reply-To: <87txbg48kd.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> <87txbg48kd.fsf@elektro.pacujo.net> Message-ID: <5313A628.9080501@gmail.com> On 03/02/2014 02:03 PM, Marko Rauhamaa wrote: > Michael Torrie : > >> I don't see why == wouldn't continue to work if os.POSIX_FADV_RANDOM >> became an object of a different type. > > It probably would. > > If one were begging for trouble, one *could* define: > > class ABC: > A = 1 > B = 1.0 > C = 1+0j And one could also set A=1 and B=1 if he was trying to be stupid. That would fail the equality test and the identity test (in CPython). Seems like this argument is getting a bit on the absurd side. The normal idiom is to use equality checks to test state variables' *values*. I don't know of any developer that would purposely try to break that when defining a new module or class. If Mark H wants to use an idiom that isn't conventional, or isn't widely used, he is free to do so; I can't see much harm in it. But certainly it's not the "normal" way that it's done in Python from what I can see. From torriem at gmail.com Sun Mar 2 16:48:02 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 02 Mar 2014 14:48:02 -0700 Subject: Boxes of O's In-Reply-To: <729104f4-92f8-48a3-9b7c-e7ba4fb6a38e@googlegroups.com> References: <31bde8f6-25a6-484f-af6b-bbef7f7a0fdf@googlegroups.com> <729104f4-92f8-48a3-9b7c-e7ba4fb6a38e@googlegroups.com> Message-ID: <5313A712.60507@gmail.com> On 03/02/2014 07:43 AM, geniusrko at gmail.com wrote: > I agree with you and really appreciate your experience. But what I > was looking for is clues. Thank you anyway Not sure what you mean. Chris certainly offered you clues to solving this problem. Certainly he pointed you in the right direction to learn how to approach a problem and debug code. Seems like what you really wanted was the answer to be given you for this homework problem. And usually someone is willing to step up and do the work for you, so you lucked out. From marko at pacujo.net Sun Mar 2 17:46:49 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 03 Mar 2014 00:46:49 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> <87txbg48kd.fsf@elektro.pacujo.net> Message-ID: <87lhws43s6.fsf@elektro.pacujo.net> Michael Torrie : > And one could also set A=1 and B=1 if he was trying to be stupid. > [...] > If Mark H wants to use an idiom that isn't conventional, or isn't > widely used, he is free to do so; I can't see much harm in it. But > certainly it's not the "normal" way that it's done in Python from what > I can see. You might be referring to what I have proposed. Note that the idiom is in use in some standard python modules (socket.py, ftplib.py, argparse.py, optparse.py). It is used extensively in sre_compile.py/sre_constants.py: ANY = "any" [...] AT = "at" [...] CALL = "call" [...] IN = "in" elif op is IN: [...] elif op is ANY: [...] elif op is CALL: [...] elif op is AT: Marko From davea at davea.name Sun Mar 2 17:58:36 2014 From: davea at davea.name (Dave Angel) Date: Sun, 2 Mar 2014 17:58:36 -0500 (EST) Subject: [OT] Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: Chris Angelico Wrote in message: > > } > > so in that case, the array size is inside the malloc'd block, but it's > still invisible to the calling function. > Please quit using negative language when you're so vehemently agreeing with me. The data is sometimes not at the beginning of the malloc'ed block. -- DaveA From rvernucio at gmail.com Sun Mar 2 18:10:06 2014 From: rvernucio at gmail.com (Renato) Date: Sun, 2 Mar 2014 15:10:06 -0800 (PST) Subject: Password validation security issue In-Reply-To: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: I would like to thank every one who posted a reply. I learnt a lot from you, guys! I appreciate your attention and your help :) I took a class on Computer Simulation last year. It was told that deterministic (pseudo-)random numbers are excellent for simulations, because they allow debugging and replication when using a seed(). But it was said that deterministic random numbers weren't indeed suitable for encryption and security issues in general. For this purpose, non-deterministc stochastic methods would be more indicated. I learnt a lot about deterministic random numbers generation in this course, like using Mersenne Twister algorithm, but I learnt nothing about encryption, since it wasn't in the scope of that course. Could you suggest some introductory material concerning encryption? I have an intermediate math background (calculus, linear algebra etc) and I'm willing to learn more about security matters. One last thing, about my original question. So, the only way of encapsulating a Python script content is to code a simple binary program to call it? Regards, Renato Em s?bado, 1 de mar?o de 2014 14h49min49s UTC-3, Renato escreveu: > Hello everybody, I implemented a password validation with a Python 2.7.5 script in OpenSUSE 13.1. The user calls it passing 'login' and 'password' as arguments. I made a dictionary in the format hashtable = {'login':'password'} and I use this hash table to compare the 'login' and 'password' that were passed in order to validate them. The problem is that any user who can execute the script will be able to read it too (since it must be read by python's interpreter), and this is causing some security issues since any user can access all other users' passwords if he opens this script and reads the code. > > > > My question is: is there a way of preventing the user from reading the script's content? Is there any strategy I could use to hide the passwords from the users? From breamoreboy at yahoo.co.uk Sun Mar 2 18:55:56 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 02 Mar 2014 23:55:56 +0000 Subject: 3.4rc2 and pip on windows Message-ID: Trying to install pyttsx, it doesn't strike me as very clever that, as seen below, you get "Successfully installed pyttsx" despite the syntax errors and you can't actually do an import. c:\Users\Mark\CrossCode>c:\Python34\Scripts\pip3.4.exe install pyttsx Downloading/unpacking pyttsx Downloading pyttsx-1.1.tar.gz Running setup.py (path:C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\pyttsx\setup.py) egg_info for package pyttsx Installing collected packages: pyttsx Running setup.py install for pyttsx File "C:\Python34\Lib\site-packages\pyttsx\driver.py", line 105 except Exception, e: ^ SyntaxError: invalid syntax [other syntax errors snipped] Successfully installed pyttsx Cleaning up... c:\Users\Mark\CrossCode>py -3.4 Python 3.4.0rc2 (v3.4.0rc2:a300712ed38c, Feb 23 2014, 10:49:04) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pyttsx Traceback (most recent call last): File "", line 1, in File "C:\Python34\lib\site-packages\pyttsx\__init__.py", line 18, in from engine import Engine I've looked at pyttsx in my 3.3 site-packages and it appears that I've manually run 2to3. Is this something that could be done automatically by pip? Your thoughts please, ladies and gentlemen. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From musicdenotation at gmail.com Sun Mar 2 18:14:09 2014 From: musicdenotation at gmail.com (musicdenotation at gmail.com) Date: Mon, 3 Mar 2014 06:14:09 +0700 Subject: Functional programming Message-ID: If Python is not a fnctional language, then which programming paradigmis dominant? From tjreedy at udel.edu Sun Mar 2 19:07:36 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Mar 2014 19:07:36 -0500 Subject: 3.4rc2 and pip on windows In-Reply-To: References: Message-ID: On 3/2/2014 6:55 PM, Mark Lawrence wrote: > Trying to install pyttsx, it doesn't strike me as very clever that, as > seen below, you get "Successfully installed pyttsx" despite the syntax > errors and you can't actually do an import. > > c:\Users\Mark\CrossCode>c:\Python34\Scripts\pip3.4.exe install pyttsx > Downloading/unpacking pyttsx > Downloading pyttsx-1.1.tar.gz > Running setup.py > (path:C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\pyttsx\setup.py) > egg_info for package pyttsx > > Installing collected packages: pyttsx > Running setup.py install for pyttsx > File "C:\Python34\Lib\site-packages\pyttsx\driver.py", line 105 > except Exception, e: > ^ > SyntaxError: invalid syntax > > [other syntax errors snipped] > > Successfully installed pyttsx A bug it seems to me. > Cleaning up... > > c:\Users\Mark\CrossCode>py -3.4 > Python 3.4.0rc2 (v3.4.0rc2:a300712ed38c, Feb 23 2014, 10:49:04) [MSC > v.1600 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import pyttsx > Traceback (most recent call last): > File "", line 1, in > File "C:\Python34\lib\site-packages\pyttsx\__init__.py", line 18, in > > from engine import Engine > > I've looked at pyttsx in my 3.3 site-packages and it appears that I've > manually run 2to3. Is this something that could be done automatically > by pip? Your thoughts please, ladies and gentlemen. I should hope so. -- Terry Jan Reedy From ben+python at benfinney.id.au Sun Mar 2 19:08:42 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 03 Mar 2014 11:08:42 +1100 Subject: Functional programming References: Message-ID: <85mwh8jg8l.fsf@benfinney.id.au> musicdenotation at gmail.com writes: > If Python is not a fnctional language, then which programming > paradigmis dominant? Python uses a mixture of programming paradigms. Object-oriented, procedural, functional, and probably some I don't recall. So it's not accurate to say ?Python is not a functional language?. You can do functional programming in Python. But you're not required to :-) -- \ ?It's dangerous to be right when the government is wrong.? | `\ ?Francois Marie Arouet Voltaire | _o__) | Ben Finney From tjreedy at udel.edu Sun Mar 2 19:05:45 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 02 Mar 2014 19:05:45 -0500 Subject: Functional programming In-Reply-To: References: Message-ID: On 3/2/2014 6:14 PM, musicdenotation at gmail.com wrote: > If Python is not a fnctional language, then which programming paradigmis dominant? Python is an object based procedural language with builtin classes and many functional features. Arguing about the precise wording of such a statement is not worthwhile. -- Terry Jan Reedy From juraj.ivancic at gmail.com Sun Mar 2 19:07:27 2014 From: juraj.ivancic at gmail.com (=?ISO-8859-2?Q?Juraj_Ivan=E8i=E6?=) Date: Mon, 03 Mar 2014 01:07:27 +0100 Subject: how to get bytes from bytearray without copying Message-ID: Is it possible to somehow 'steal' bytearray's buffer and make it a read-only bytes? I failed to find a way to do this, and would like to make sure. My use case is, I would expect, fairly common. I read a certain (potentially very large) amount of data from the network into a pre-allocated bytearray. From that point on, this data is logically read-only. To prevent making redundant copies, I wrap it in a memoryview, and then slice and dice it. The problem with this memoryview is that it, and its slices, are considered writable, and thus cannot be hashed: ValueError: cannot hash writable memoryview object The only way (AFAICT) to make this work is to first create a bytes object from bytearray, but this copies the data. I don't need this copy, so I'd like to avoid it, because of both principle and performance reasons. Is there any reason why bytearray isn't able to release/convert its buffer to bytes? I see that it has a clear() method which... well... clears it. The former would be much more useful. I would also be content if there is some way of making memoryview artificially read-only to avoid the above error. Any help/thoughts/comments are highly appreciated. From roy at panix.com Sun Mar 2 19:11:30 2014 From: roy at panix.com (Roy Smith) Date: Sun, 02 Mar 2014 19:11:30 -0500 Subject: Functional programming References: Message-ID: In article , Terry Reedy wrote: > On 3/2/2014 6:14 PM, musicdenotation at gmail.com wrote: > > If Python is not a fnctional language, then which programming paradigmis > > dominant? > > Python is an object based procedural language with builtin classes and > many functional features. Arguing about the precise wording of such a > statement is not worthwhile. +1 QOTW. Especially the second sentence. From miguelcoam at gmail.com Sun Mar 2 19:38:49 2014 From: miguelcoam at gmail.com (Mike) Date: Sun, 2 Mar 2014 16:38:49 -0800 (PST) Subject: Error compressing tar file Message-ID: Hello, I have the script that make a backup file (this process is ok), but now i wish compress the file on tar file format. But i have problem syntax in the line of the tar function. The error is [root at master ~]# python bkp_db.py File "bkp_db.py", line 19 tar = tarfile.open(dumpfile)+'.tar.gz','w:gz') ^ Note: The 'dumpfile' is the variable for my dump generate with format db_02-27-14 ...... tar = tarfile.open(dumpfile)+'.tar.gz','w:gz') tar.add(os.path.join(dumpfile), arcname=dumpfile) tar.close() ........ Wath is the correct sintax? Thanks. From joel.goldstick at gmail.com Sun Mar 2 19:41:45 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 2 Mar 2014 19:41:45 -0500 Subject: Error compressing tar file In-Reply-To: References: Message-ID: On Mar 2, 2014 7:40 PM, "Mike" wrote: > > Hello, > I have the script that make a backup file (this process is ok), but now i wish compress the file on tar file format. But i have problem syntax in the line of the tar function. > > The error is > > [root at master ~]# python bkp_db.py > File "bkp_db.py", line 19 > tar = tarfile.open(dumpfile)+'.tar.gz','w:gz')) > ^ > > Note: The 'dumpfile' is the variable for my dump generate with format db_02-27-14 > > ...... > tar = tarfile.open(dumpfile)+'.tar.gz','w:gz') > tar.add(os.path.join(dumpfile), arcname=dumpfile) > tar.close() > ........ > > Wath is the correct sintax? > > > Thanks. > > > > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Sun Mar 2 19:43:40 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 2 Mar 2014 19:43:40 -0500 Subject: Error compressing tar file In-Reply-To: References: Message-ID: On Mar 2, 2014 7:41 PM, "Joel Goldstick" wrote: > > > On Mar 2, 2014 7:40 PM, "Mike" wrote: > > > > Hello, > > I have the script that make a backup file (this process is ok), but now i wish compress the file on tar file format. But i have problem syntax in the line of the tar function. > > > > The error is > > > > [root at master ~]# python bkp_db.py > > File "bkp_db.py", line 1 Oops. Remove ) after dumpfile > > tar = tarfile.open(dumpfile)+'.tar.gz','w:gz')) > > > ^ > > > > Note: The 'dumpfile' is the variable for my dump generate with format db_02-27-14 > > > > ...... > > tar = tarfile.open(dumpfile)+'.tar.gz','w:gz') > > tar.add(os.path.join(dumpfile), arcname=dumpfile) > > tar.close() > > ........ > > > > Wath is the correct sintax? > > > > > > Thanks. > > > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Sun Mar 2 19:44:58 2014 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 3 Mar 2014 11:44:58 +1100 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: <20140303004458.GA73815@cskk.homeip.net> On 03Mar2014 01:07, Juraj Ivan?i? wrote: > Is it possible to somehow 'steal' bytearray's buffer and make it a > read-only bytes? I failed to find a way to do this, and would like > to make sure. > > My use case is, I would expect, fairly common. I read a certain > (potentially very large) amount of data from the network into a > pre-allocated bytearray. From that point on, this data is logically > read-only. To prevent making redundant copies, I wrap it in a > memoryview, and then slice and dice it. The problem with this > memoryview is that it, and its slices, are considered writable, and > thus cannot be hashed: > > ValueError: cannot hash writable memoryview object Have you considered subclassing memoryview and giving the subclass a __hash__ method? Cheers, -- Cameron Simpson Mountain rescue teams insist the all climbers wear helmets, and fall haedfirst. They are then impacted into a small globular mass easily stowed in a rucsac. - Tom Patey, who didnt, and wasnt From breamoreboy at yahoo.co.uk Sun Mar 2 19:49:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 03 Mar 2014 00:49:28 +0000 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: On 03/03/2014 00:07, Juraj Ivan?i? wrote: > Is it possible to somehow 'steal' bytearray's buffer and make it a > read-only bytes? I failed to find a way to do this, and would like to > make sure. > > My use case is, I would expect, fairly common. I read a certain > (potentially very large) amount of data from the network into a > pre-allocated bytearray. From that point on, this data is logically > read-only. To prevent making redundant copies, I wrap it in a > memoryview, and then slice and dice it. The problem with this memoryview > is that it, and its slices, are considered writable, and thus cannot be > hashed: > > ValueError: cannot hash writable memoryview object > > The only way (AFAICT) to make this work is to first create a bytes > object from bytearray, but this copies the data. I don't need this copy, > so I'd like to avoid it, because of both principle and performance reasons. > > Is there any reason why bytearray isn't able to release/convert its > buffer to bytes? I see that it has a clear() method which... well... > clears it. The former would be much more useful. > > I would also be content if there is some way of making memoryview > artificially read-only to avoid the above error. > > Any help/thoughts/comments are highly appreciated. > If your data is readonly why can't you simply read it as bytes in the first place? Failing that from http://docs.python.org/3/library/stdtypes.html#memoryview tobytes() - Return the data in the buffer as a bytestring. This is equivalent to calling the bytes constructor on the memoryview. >>> m = memoryview(b"abc") >>> m.tobytes() b'abc' >>> bytes(m) b'abc' -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ian.g.kelly at gmail.com Sun Mar 2 19:55:48 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 2 Mar 2014 17:55:48 -0700 Subject: how to get bytes from bytearray without copying In-Reply-To: <20140303004458.GA73815@cskk.homeip.net> References: <20140303004458.GA73815@cskk.homeip.net> Message-ID: On Sun, Mar 2, 2014 at 5:44 PM, Cameron Simpson wrote: > Have you considered subclassing memoryview and giving the subclass > a __hash__ method? >>> class MyMemoryView(memoryview): ... def __hash__(self): return 42 ... Traceback (most recent call last): File "", line 1, in TypeError: type 'memoryview' is not an acceptable base type From miguelcoam at gmail.com Sun Mar 2 20:11:19 2014 From: miguelcoam at gmail.com (Mike) Date: Sun, 2 Mar 2014 17:11:19 -0800 (PST) Subject: Error compressing tar file In-Reply-To: References: Message-ID: <2567f9c6-494d-4a69-b126-5e0e09c40a00@googlegroups.com> El domingo, 2 de marzo de 2014 21:38:49 UTC-3, Mike escribi?: > Hello, > > I have the script that make a backup file (this process is ok), but now i wish compress the file on tar file format. But i have problem syntax in the line of the tar function. > > > > The error is > > > > [root at master ~]# python bkp_db.py > > File "bkp_db.py", line 19 > > tar = tarfile.open(dumpfile)+'.tar.gz','w:gz') > > ^ > > > > Note: The 'dumpfile' is the variable for my dump generate with format db_02-27-14 > > > > ...... > > tar = tarfile.open(dumpfile)+'.tar.gz','w:gz') > > tar.add(os.path.join(dumpfile), arcname=dumpfile) > > tar.close() > > ........ > > > > Wath is the correct sintax? > > > > > > Thanks. Hello, without ")" i have the same sintax error: [root at master ~]# python bkp_db.py Traceback (most recent call last): File "bkp_db.py", line 19, in tar = tarfile.open(dumpfile + '.tar.gz','w:gz') TypeError: unsupported operand type(s) for +: 'file' and 'str' Thanks. From steve+comp.lang.python at pearwood.info Sun Mar 2 20:16:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 01:16:47 GMT Subject: Password validation security issue References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sun, 02 Mar 2014 15:01:09 -0500, Roy Smith wrote: > Security is as much about cryptography as it is about human factors and > business drivers. You can make things resistant to brute-force attacks > by using longer keys, but people are still going to pick bad passwords. Yes. But: > You can force them to pick "good" passwords by rejecting their first 37 > choices, but all that does is encourage them to write the passwords down > on sticky notes. There is nothing wrong with writing passwords down on sticky notes. (Well, figuratively speaking. Perhaps not *literal* sticky notes, since they are too easy to lose.) You have to ask, what is the threat you are trying to defend against? If your threat is that the Secret Police will break your door down at 3am, and smash your fingers one at a time until you give them your passwords, then strong passwords that only you remember will not save you. If the threat is that your little brother will log into your hotmail account and send rude messages to your school friends, then writing your password down on a Postit and sticking it on the computer is insecure, but keeping it in your wallet or purse may be secure enough. Today, one of the biggest (but not the only) threats most people face is the mass theft of passwords from idiot organisations that store them in insecure databases as plain text. There's not much we, the users, can do about that, except complain complain complain when it happens. Possibly sue, on the basis that storing passwords as plain text is not within a million miles of best practice or even standard practice. Another threat comes from black-hat hackers breaking your password. Whether they want *your* password specifically, or just picked your account randomly, this is where strong passwords can have a good effect. Until such time as an attacker can reach through the Internet to read the password on your Postit Note, writing down your strong password and keeping it by your computer is an effective way to counter this threat. > And, yes, you can make things more secure with 2FA, but there's a cost > there. You have to purchase and manage the infrastructure. More than > that, there's lost business if potential customers prefer a competitor's > product because it's easier to access. Many of the known insecure > systems we use today are not that way because the people who run them > are stupid; they're that way because the people who run them have worked > the numbers and decided the cost to implement more secure systems would > exceed the risk exposure. While in principle you are right, in practice I think that most of these people and organisations start from number of dodgy assumptions, starting with "Meh, it'll never happen...". They underestimate the risk, underestimate the consequences, ignore costs that don't apply solely to them (e.g. the cost of spam sent from tens of millions of compromised PCs and gmail accounts), overestimate the strength of their half-baked solutions, and ignore the portion of their user-base who actually does want better security. When they do make a half-hearted attempt at security, it's often security theatre, e.g. I have a bank account with one bank that doesn't let you type your password, instead you have to click keys on a simulated keyboard on screen. You're limited to *six* (SIX!!!) case-insensitive alphanumeric characters, letters and digits only. And then, to add insult to injury, they have the fecking cheek to hassle you every few months to change your insecure password for another insecure password, thus increasing the chance that you'll forgot what it is and lock yourself out of the account. This encourages people to choose even weaker passwords, so they won't forget them. Another bank I use eschews such ridiculous "security" and actually provides you with a real cryptographic key for which you have to provide a passphrase. A passphrase limited to *eight* alphanumeric characters. And I think it is case-insensitive, although I haven't actually tried it. I expect that these idiots spent more time, effort and money *preventing* their users from putting in strong passwords than they would have spent to allow strong passwords. > We recently got a frothing email from a user, which basically said, "You > farking idiots, you emailed me my password in plain text!" It turns > out, his user name was the same as his password and what we had sent him > (in response to an account recovery query) was his username. In > response to that, we altered our account generation process to forbid > passwords which are too similar to your chosen username or email > address. Which, of course, means we've taken one more step down the > road to forcing our users to write their passwords on sticky notes. That's a good thing. People have managed physical keys for *centuries*. Yes, there are a class of threats where you lose your key, or someone steals it, or makes a copy, but the risks are well-understood and can be managed even by your grandmother. We have good solutions for those problems that work well, and many of them apply just as well to sticky notes with secure passwords written on them. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ned at nedbatchelder.com Sun Mar 2 20:27:15 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 02 Mar 2014 20:27:15 -0500 Subject: Functional programming In-Reply-To: References: Message-ID: On 3/2/14 6:14 PM, musicdenotation at gmail.com wrote: > If Python is not a fnctional language, then which programming paradigmis dominant? > is_a_functional_language() is not a binary condition, yes or no. It's a continuum. Python has more functional constructs than Pascal, and fewer than Haskell. -- Ned Batchelder, http://nedbatchelder.com From ian.g.kelly at gmail.com Sun Mar 2 20:27:40 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 2 Mar 2014 18:27:40 -0700 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: On Sun, Mar 2, 2014 at 5:07 PM, Juraj Ivan?i? wrote: > Is it possible to somehow 'steal' bytearray's buffer and make it a read-only > bytes? I failed to find a way to do this, and would like to make sure. > > My use case is, I would expect, fairly common. I read a certain (potentially > very large) amount of data from the network into a pre-allocated bytearray. > From that point on, this data is logically read-only. To prevent making > redundant copies, I wrap it in a memoryview, and then slice and dice it. The > problem with this memoryview is that it, and its slices, are considered > writable, and thus cannot be hashed: > > ValueError: cannot hash writable memoryview object > > The only way (AFAICT) to make this work is to first create a bytes object > from bytearray, but this copies the data. I don't need this copy, so I'd > like to avoid it, because of both principle and performance reasons. > > Is there any reason why bytearray isn't able to release/convert its buffer > to bytes? I see that it has a clear() method which... well... clears it. The > former would be much more useful. > > I would also be content if there is some way of making memoryview > artificially read-only to avoid the above error. Python 3.3 has a C API function to create a memoryview for a char*, that can be made read-only. http://docs.python.org/3/c-api/memoryview.html#PyMemoryView_FromMemory I don't see a way to do what you want in pure Python, apart from perhaps writing an elaborate proxy class that would just be a poor man's memoryview. Or you could bite the bullet and copy everything once at the start to create a bytes object, and then never have to worry about it again. From swdunning at cox.net Sun Mar 2 20:36:04 2014 From: swdunning at cox.net (Scott W Dunning) Date: Sun, 2 Mar 2014 18:36:04 -0700 Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: <7FA59B96-ABA7-4AD2-A4DD-6F50BDA2C2F6@cox.net> On Mar 2, 2014, at 12:38 AM, Larry Hudson wrote: > > Another 'problem' is what you failed to mention in your post, but is apparent from the instructions that you posted -- this assignment is NOT the complete program, just the beginning of one. Your instructor obviously wants you to work on (and understand) this program fragment before continuing with the rest of it. > No it is the whole program I just didn?t post his entire instructs because they were like 5 pages. Ifugured I just post what I was struggling with right now. I?m hoping once I get past this first par I?ll be good to go. Hopefully! Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: From swdunning at cox.net Sun Mar 2 20:40:21 2014 From: swdunning at cox.net (Scott W Dunning) Date: Sun, 2 Mar 2014 18:40:21 -0700 Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: On Mar 1, 2014, at 6:16 PM, Chris Angelico wrote: > > Another consideration: Susan's code is written for Python 3, but you > seemed to be using Python 2. You'll find that the code won't even run > on your version of Python. > > (If you have the chance, ask if the course writer would consider > updating it to use Python 3. There's getting to be less and less > reason to use Python 2 for any new projects; when you start a brand > new system, you should be using Python 3 unless there's something > holding you on the old version. So it's correspondingly more useful to > learn Py3.) > > ChrisA I completely agree. However, the instructor is wanting to use Python 2.7.6 because the book he is using for the course goes over 2.7.6. Hopefully, once I learn more it will not be a huge jump to python 3. Scott From cs at zip.com.au Sun Mar 2 20:47:58 2014 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 3 Mar 2014 12:47:58 +1100 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: <20140303014758.GA40714@cskk.homeip.net> On 02Mar2014 17:55, Ian Kelly wrote: > On Sun, Mar 2, 2014 at 5:44 PM, Cameron Simpson wrote: > > Have you considered subclassing memoryview and giving the subclass > > a __hash__ method? > > >>> class MyMemoryView(memoryview): > ... def __hash__(self): return 42 > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: type 'memoryview' is not an acceptable base type Ah. The slices were going to be an issue too, anyway. He could write a wrapper class with a __hash__ method, whose slices themselves are also the wrapper class. It raises the implementation bar only slightly. Cheers, -- Cameron Simpson Please do not send me Microsoft Word files. http://en.nothingisreal.com/wiki/Please_don't_send_me_Microsoft_Word_documents From ian.g.kelly at gmail.com Sun Mar 2 20:49:27 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 2 Mar 2014 18:49:27 -0700 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: On Sun, Mar 2, 2014 at 4:10 PM, Renato wrote: > I would like to thank every one who posted a reply. I learnt a lot from you, guys! I appreciate your attention and your help :) > > I took a class on Computer Simulation last year. It was told that deterministic (pseudo-)random numbers are excellent for simulations, because they allow debugging and replication when using a seed(). But it was said that deterministic random numbers weren't indeed suitable for encryption and security issues in general. For this purpose, non-deterministc stochastic methods would be more indicated. I learnt a lot about deterministic random numbers generation in this course, like using Mersenne Twister algorithm, but I learnt nothing about encryption, since it wasn't in the scope of that course. Could you suggest some introductory material concerning encryption? I have an intermediate math background (calculus, linear algebra etc) and I'm willing to learn more about security matters. > > One last thing, about my original question. So, the only way of encapsulating a Python script content is to code a simple binary program to call it? Another alternative would be to implement the script as a service that runs under a separate account. All the user can directly access is a client script that sends requests to the service, which does the actual work and is effectively encapsulated. I'll also reiterate what others have written about protecting passwords. No matter how much you think you've locked down the script, you shouldn't be storing plaintext passwords *anywhere*. Remember that nothing that you code will ever be as secure as you think it is. From steve+comp.lang.python at pearwood.info Sun Mar 2 20:50:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 01:50:39 GMT Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> <53130b83$0$29985$c3e8da3$5496439d@news.astraweb.com> <871tykal8o.fsf@elektro.pacujo.net> Message-ID: <5313dfee$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sun, 02 Mar 2014 13:33:11 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Sun, 02 Mar 2014 11:35:43 +0200, Marko Rauhamaa wrote: >>> Now, what kinds of object are those constants? We are not supposed to >>> know or care. >> >> Incorrect. We are supposed to know and care. > > Then, the documentation is seriously flawed. It gives no hint whatsoever > on the nature of those objects. "Seriously" flawed? I doubt it. It's a trivial, pedantic point, and I expect that most practising Python programmers will consider it too obvious to bother documenting the fact that flags meant for compatibility with POSIX operating systems are ints. On the other hand, perhaps I am wrong and it is a documentation bug. Feel free to suggest a documentation patch on the bug tracker. >> os.posix is exactly the sort of library I mentioned earlier when I said >> sometimes you're constrained by compatibility with some other system. >> In this case, the os module is explicitly designed to be compatible >> with the POSIX interface, which is defined to use certain integer >> values as flags. This is not an implementation choice which >> implementers can change at will, it is part of the interface. > > The values of those Python constants don't need to have any relationship > with those of the underlying operating system. In theory, they could be different. In practice, no they won't. You should be able to pass the Python constants directly to some C library which expects to see ints. It's a thin wrapper, not a bridge. >> Python does not guarantee that there is only a single 1 instance. > > Nobody has ever argued such a thing. I certainly haven't. You may not have intended to, but by championing the use of "is", that is precisely what you have done. Using "is" tests for *identity*, not value. To get the behaviour you want, it requires those objects to be singletons. > However, nothing in the API spec gives you the right to call the > function with an integer. But you do call the function with an integer. And if you don't, you get a type error that explicitly tells you that an integer is needed: py> os.posix_fadvise(open("/tmp/spam").fileno(), 0, 100, None) Traceback (most recent call last): File "", line 1, in TypeError: an integer is required >> If you want to test whether a value is os.POSIX_FADV_RANDOM, the right >> way is to compare that value for equality with os.POSIX_FADV_RANDOM, >> not identity. > > That might well be true but is not explicitly or implicitly specified in > the documentation. (The os.SEEK_* constants are explicitly defined.) Not everything needs to be documented explicitly. Would you rather the Python developers spend their time fixing bugs and improving the language, or ensuring that every trivial and obvious point is explicitly documented? If you feel this is not a trivial or obvious point, and that it needs documenting, then feel free to contribute a documentation patch. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Mar 2 20:54:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 01:54:47 GMT Subject: Functional programming References: Message-ID: <5313e0e6$0$29985$c3e8da3$5496439d@news.astraweb.com> On Mon, 03 Mar 2014 06:14:09 +0700, musicdenotation wrote: > If Python is not a fnctional language, then which programming paradigmis > dominant? Object oriented and procedural are about equally dominant, with a strong influence from functional paradigm. There are small amounts of imperative paradigm (e.g. the import and del statements), and you can use iterators and generators to program using a pipelining paradigm. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Mar 2 21:02:10 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 02:02:10 GMT Subject: Error compressing tar file References: <2567f9c6-494d-4a69-b126-5e0e09c40a00@googlegroups.com> Message-ID: <5313e2a1$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sun, 02 Mar 2014 17:11:19 -0800, Mike wrote: > without ")" i have the same sintax error: > > [root at master ~]# python bkp_db.py > Traceback (most recent call last): > File "bkp_db.py", line 19, in > tar = tarfile.open(dumpfile + '.tar.gz','w:gz') > TypeError: unsupported operand type(s) for +: 'file' and 'str' That is not a syntax error. It is a type error. You cannot add a file object and a string object together. Please inspect the value of dumpfile. You are treating it as if it were a string, but it looks like it is an open file object. I think that you probably expect this: dumpfile = "path to some file" tarfile.open(dumpfile + '.tar.gz','w:gz') but what you actually have is probably something like this: dumpfile = open("path to some file") tarfile.open(dumpfile + '.tar.gz','w:gz') -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Mar 2 21:30:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 02:30:52 GMT Subject: Password validation security issue References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> Message-ID: <5313e95b$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sun, 02 Mar 2014 15:10:06 -0800, Renato wrote: > I would like to thank every one who posted a reply. I learnt a lot from > you, guys! I appreciate your attention and your help :) > > I took a class on Computer Simulation last year. It was told that > deterministic (pseudo-)random numbers are excellent for simulations, > because they allow debugging and replication when using a seed(). But it > was said that deterministic random numbers weren't indeed suitable for > encryption and security issues in general. For this purpose, > non-deterministc stochastic methods would be more indicated. Either you have misunderstood, or you have been told something incorrect. You don't in general want non-deterministic stochastic randomness, because you can't control it and you can't make any guarantees about it. Stochastic randomness nearly always has deviations from uniformity which can be exploited, that is, it is less random than you might think. For example: http://www.newscientist.com/article/mg21428644.500-roulette-beater-spills- physics-behind-victory.html http://en.wikipedia.org/wiki/Eudaemons Nor do should you use deterministic PRNGs like the Mersenne Twister, not because they are deterministic, but because they aren't cryptographically strong. The right approach is to use a deterministic PRNG which is deliberately designed for use in cryptographic applications, and then add in a source of entropy (which might be non-deterministic, like thermal noise or the output of radioactive decay). On Unix systems, the OS already does this for you: http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ > One last thing, about my original question. So, the only way of > encapsulating a Python script content is to code a simple binary program > to call it? I don't understand this question. Can you explain more? -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Sun Mar 2 20:52:40 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 2 Mar 2014 18:52:40 -0700 Subject: Password validation security issue In-Reply-To: <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 2, 2014 at 6:16 PM, Steven D'Aprano wrote: > People have managed physical keys for *centuries*. Yes, there are a class > of threats where you lose your key, or someone steals it, or makes a > copy, but the risks are well-understood and can be managed even by your > grandmother. We have good solutions for those problems that work well, > and many of them apply just as well to sticky notes with secure passwords > written on them. I don't know how well the analogy holds up. People protect their keys, because a) if they lose them, they can't get into their house or business, and b) if they're stolen, somebody else could gain access and steal expensive items from them. People are less likely to protect their sticky notes, because a) nobody is going to steal a piece of paper, and b) if it does go missing, the IT guy is just one phone call away, and c) who would want to break into my desktop anyway? I don't have any trade secrets in there. From rosuav at gmail.com Sun Mar 2 21:56:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 13:56:58 +1100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 3, 2014 at 12:52 PM, Ian Kelly wrote: > On Sun, Mar 2, 2014 at 6:16 PM, Steven D'Aprano > wrote: >> People have managed physical keys for *centuries*. Yes, there are a class >> of threats where you lose your key, or someone steals it, or makes a >> copy, but the risks are well-understood and can be managed even by your >> grandmother. We have good solutions for those problems that work well, >> and many of them apply just as well to sticky notes with secure passwords >> written on them. > > I don't know how well the analogy holds up. People protect their > keys, because a) if they lose them, they can't get into their house or > business, and b) if they're stolen, somebody else could gain access > and steal expensive items from them. People are less likely to > protect their sticky notes, because a) nobody is going to steal a > piece of paper, and b) if it does go missing, the IT guy is just one > phone call away, and c) who would want to break into my desktop > anyway? I don't have any trade secrets in there. The greatest threats these days are from the network, not from someone physically walking into an office. (That said, though, the low-hanging fruit from walking into an office can be *extremely* tempting. Pulling off a basic password leech off sticky notes is often so easy that it can be done as a visitor, or at least as a pizza deliveryman.) Ultimately, any network-accessible resource is protected by some system of credentials that can be guessed; the only question is how hard it is to guess. Any scheme to steal the password has to be easier than guessing, or it's not worth it. Breaking a salted SHA-256 versus XKCD 538 password cracking? Take your pick, but guessing a six-character password beats both (being quicker than the one and more subtle than the other). Maybe salted SHA-256 isn't perfect, but it's certainly (a) a lot better than plain text, unsalted hashes, or salted MD5, and (b) good enough to raise the cracking of the hash above a lot of other infiltration techniques. ChrisA From swdunning at cox.net Sun Mar 2 22:44:47 2014 From: swdunning at cox.net (Scott W Dunning) Date: Sun, 2 Mar 2014 20:44:47 -0700 Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> Message-ID: <3FDED793-DA02-4F9F-B431-33499B6949ED@cox.net> On Mar 2, 2014, at 6:40 PM, Scott W Dunning wrote: This is what Im having trouble with now. Here are the directions I?m stuck on and what I have so far, I?ll bold the part that?s dealing with the instructions if anyone could help me figure out where I?m going wrong. Thanks! from random import randrange randrange(1, 101) from random import seed seed(129) def print_description(): print """Welcome to Guess the Number. I have seleted a secret number in the range 1 ... 100. You must guess the number within 10 tries. I will tell you if you ar high or low, and I will tell you if you are hot or cold.\n""" def get_guess(guess_number): promt = "(" + str(guess_number) +") Please enter a guess:" user_guess = raw_input(promt) user_guess = int(user_guess) return user_guess def print_hints(secrets, guess): secret_number = secret guess = guess if guess < 0 or user_guess> 101: print "Out of range!" def main(): print_description() secret = randrange(1,101) current_guess = get_guess(1) if current_guess != secret: print_hints(secret_number, guess) current_guess = get_guess(2) if secret == current_guess: print "Congratulations, you win!" else: print "Please play again" print "The secret number was", secret main() Just below the body of the get guess function, define a new function named print hints that takes two arguments. The first is a secret num- ber and is kept in a parameter named secret. The second is a guess made by the user and it is held in a parameter named guess. The user?s guess is supposed to be within the range 1 ... 100. Write a conditional statement that checks if the guess is out of that range, and if it is print ?out of range? in the body of the print hints function. Now we are going to give the user the option to make a second guess. You must add code to the main function immediately after assignment statement you wrote for task 7. Write a conditional statement to check if the current guess does not match the secret number. If the numbers to not match, in the body of the conditional statement you will do two things. (a) call print hints to give the user hints, (b) re-assign current guess to the result of calling get guess with an argument of 2. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sun Mar 2 22:52:10 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 03 Mar 2014 14:52:10 +1100 Subject: Help with "Guess the number" script References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> <3FDED793-DA02-4F9F-B431-33499B6949ED@cox.net> Message-ID: <857g8cj5w5.fsf@benfinney.id.au> Scott W Dunning writes: > This is what Im having trouble with now. Once again, Scott, this discussion should be happening at the Tutor forum. Please don't continue the fragmentation of this discussion; keep the discusson over at the Tutor forum. -- \ ?I like to fill my bathtub up with water, then turn the shower | `\ on and pretend I'm in a submarine that's been hit.? ?Steven | _o__) Wright | Ben Finney From swdunning at cox.net Sun Mar 2 23:04:17 2014 From: swdunning at cox.net (Scott W Dunning) Date: Sun, 2 Mar 2014 21:04:17 -0700 Subject: Help with "Guess the number" script In-Reply-To: References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> <3FDED793-DA02-4F9F-B431-33499B6949ED@cox.net> Message-ID: On Mar 2, 2014, at 8:52 PM, Ben Finney wrote: > > Once again, Scott, this discussion should be happening at the Tutor > forum. Please don't continue the fragmentation of this discussion; keep > the discusson over at the Tutor forum. Sorry, I was just replying to replies to my post. I get the posts through my email so it?s hard to distinguish, especially since people are responding under both. I guess since people are responding it?s not that big a deal. From steve at pearwood.info Sun Mar 2 23:38:33 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 04:38:33 GMT Subject: Password validation security issue References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53140749$0$2923$c3e8da3$76491128@news.astraweb.com> On Sun, 02 Mar 2014 18:52:40 -0700, Ian Kelly wrote: > On Sun, Mar 2, 2014 at 6:16 PM, Steven D'Aprano > wrote: >> People have managed physical keys for *centuries*. Yes, there are a >> class of threats where you lose your key, or someone steals it, or >> makes a copy, but the risks are well-understood and can be managed even >> by your grandmother. We have good solutions for those problems that >> work well, and many of them apply just as well to sticky notes with >> secure passwords written on them. > > I don't know how well the analogy holds up. People protect their keys, > because a) if they lose them, they can't get into their house or > business, and b) if they're stolen, somebody else could gain access and > steal expensive items from them. A bit like the password to your bank account, or for that matter your Facebook account. > People are less likely to protect > their sticky notes, because a) nobody is going to steal a piece of > paper, Oh really? Chances are you're wallet is *full* of pieces of paper that people would steal, given half the chance. > and b) if it does go missing, the IT guy is just one phone call > away, Last time I had to call my bank to unlock my account, it took two phone calls and nearly three hours of elapsed time. And I was lucky I didn't have to physically go in to a branch and show photo ID. > and c) who would want to break into my desktop anyway? I don't > have any trade secrets in there. Who would want to steal somebody else's identity? I'm not saying that people are born with an intuitive understanding of the security issues of a modern technological society. But they can *learn* (perhaps only after they get burned) that they need to protect their computer accounts, including their desktop. Having learned that, they're screwed: even in the (uncommon) case that their account will support a cryptographically strong passphrase, most people need a dozen or more different passwords and/or passphrases. (I have about 50, only a dozen of which I keep in my head.) Who is going to remember a 12 character high-entropy string for an account they only use once a year? Most people have trouble remembering four-digit PINs if they don't use them regularly. We cannot solve the social problem that people *don't* care about security with a technical solution, but we might be able to solve the problem that people *can't* remember sufficient passphrases and passwords for their needs. Lacking a technical solution for that, for most people, under many practical threat models, writing down your strong passwords on bits of paper which you then keep safe is better than using weak passwords, using one strong password for everything, or trying to remember a dozen strong, independent passwords. -- Steven From wuwei23 at gmail.com Sun Mar 2 23:49:56 2014 From: wuwei23 at gmail.com (alex23) Date: Mon, 03 Mar 2014 14:49:56 +1000 Subject: Coding a simple state machine in python In-Reply-To: References: <65ac9612-fd48-472a-b077-c802be96ece3@googlegroups.com> Message-ID: On 25/02/2014 8:01 PM, Peter Otten wrote: > alex23 wrote: >> No, the _easy_ solution is [find a suitable package on PyPI] > > Easy? By the time I have evaluated these I've written my own ;) It's never writing a solution that's the problem...it's maintaining it over time :) From rosuav at gmail.com Mon Mar 3 00:44:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 16:44:26 +1100 Subject: Password validation security issue In-Reply-To: <53140749$0$2923$c3e8da3$76491128@news.astraweb.com> References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> <53140749$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Mar 3, 2014 at 3:38 PM, Steven D'Aprano wrote: > Oh really? Chances are you're wallet is *full* of pieces of paper that > people would steal, given half the chance. Alas no... around here, wallets get filled with pieces of plastic [1], of which my wallet is sadly devoid. And I can't imagine anyone putting effort into stealing my Gilbert & Sullivan Society membership card, nor my coupon card for a half-price watch battery replacement on condition that I take it back to some place that I don't go anywhere near any more... But don't let that detract from your point :D >> and b) if it does go missing, the IT guy is just one phone call >> away, > > Last time I had to call my bank to unlock my account, it took two phone > calls and nearly three hours of elapsed time. And I was lucky I didn't > have to physically go in to a branch and show photo ID. That's about par for the course. Worst part of it is when you lose your connection and have to (a) go right back to the end of the caller queue, (b) get through to a different agent, and therefore (c) have to start over with the whole identifying-yourself thing. I wish I could invoke tmux or GNU Screen on arrival,and then just reconnect. This is, perhaps, the best argument in favour of password security. The thought that someone might steal your identity is so vague and hard to comprehend that it won't scare people; the possibility of someone stealing money is "Oh but my bank will keep me safe" (whether or not that's true is quite tangential); but explain that forgetting your password (or having someone else figure out your password) means having to call support? *That* is an incentive. > Having learned that, they're screwed: even in the (uncommon) case that > their account will support a cryptographically strong passphrase, most > people need a dozen or more different passwords and/or passphrases. (I > have about 50, only a dozen of which I keep in my head.) Who is going to > remember a 12 character high-entropy string for an account they only use > once a year? Most people have trouble remembering four-digit PINs if they > don't use them regularly. What if you create XKCD 936 passwords, and then have one "master password file" in which you store, for each password, four words that are synonyms for the originals, plus the first letters of them? (Obviously your master password file (a) never leaves your own computer, and (b) should itself be encrypted with some secure password, and treated with extreme sensitivity. But that gets around the "once a year" problem, as you'll refer to this one file any time you need to check any of your rare passwords.) As a second line of defense before contacting support, it feels plausible, but I've never actually had an opportunity to try it. Of course, the whole concept depends on being able to use long memorable passwords. Any system that sets a maximum password length of anything less than about 30-40 characters is causing its users problems. There's almost never any reason to set a maximum at all. ChrisA [1] http://en.wikipedia.org/wiki/Polymer_banknote From anikom15 at gmail.com Mon Mar 3 01:16:31 2014 From: anikom15 at gmail.com (=?ISO-8859-1?Q?Westley_Mart=EDnez?=) Date: Sun, 2 Mar 2014 22:16:31 -0800 (PST) Subject: Origin of 'self' Message-ID: I understand that in an object method the first argument in the object itself, called self. However, it doesn't have to be called self, and can be called anything. So my question is why is it called self and not this like from C++ and Java. It's kind of a silly question, but one that I'm curious about nevertheless. Sincerely, Westley Mart?nez From davea at davea.name Mon Mar 3 01:49:04 2014 From: davea at davea.name (Dave Angel) Date: Mon, 3 Mar 2014 01:49:04 -0500 (EST) Subject: Origin of 'self' References: Message-ID: Westley Mart??nez Wrote in message: > I understand that in an object method the first argument in the object itself, called self. However, it doesn't have to be called self, and can be called anything. So my question is why is it called self and not this like from C++ and Java. It's kind of a silly question, but one that I'm curious about nevertheless. > I couldn't tell you the history, but I can say it makes sense to me. In c++, this is a pointer, and the name this seems reasonable. But in python it's a reference, a reference to myself. -- DaveA From ian.g.kelly at gmail.com Mon Mar 3 01:50:35 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 2 Mar 2014 23:50:35 -0700 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> <53140749$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Sun, Mar 2, 2014 at 10:44 PM, Chris Angelico wrote: > Of course, the whole concept depends on being able to use long > memorable passwords. Any system that sets a maximum password length of > anything less than about 30-40 characters is causing its users > problems. There's almost never any reason to set a maximum at all. Well, there's usually *some* reason. If you allow your users to set a 100-MB password then your system has to accept and attempt to verify any 100-MB passwords that might get passed in, which opens you up to a certain DoS attack. Setting the limit at 8 characters though is absurd and a probable indication of bad password handling. From steve at pearwood.info Mon Mar 3 01:52:40 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 06:52:40 GMT Subject: Origin of 'self' References: Message-ID: <531426b8$0$2923$c3e8da3$76491128@news.astraweb.com> On Sun, 02 Mar 2014 22:16:31 -0800, Westley Mart?nez wrote: > I understand that in an object method the first argument in the object > itself, called self. However, it doesn't have to be called self, and > can be called anything. So my question is why is it called self and not > this like from C++ and Java. It's kind of a silly question, but one > that I'm curious about nevertheless. A better question is why C++ and Java used "this" instead of "self" like Smalltalk. It's fairly clear that Java copied C++, but why did C++ use "this"? http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28object-oriented_programming%29#Special_variables As far as I can tell, Simula 67 (the first OOP programming language) doesn't seem to use a standard name for the current instance, it appears to be unneeded. But Simula 67 was the inspiration for Smalltalk, invented by Alan Kay at Xerox PARC in the 1970s, and Smalltalk used "self". Virtually everything in OOP that followed was influenced by or derived from Smalltalk. -- Steven From ian.g.kelly at gmail.com Mon Mar 3 02:03:18 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 3 Mar 2014 00:03:18 -0700 Subject: Origin of 'self' In-Reply-To: References: Message-ID: On Sun, Mar 2, 2014 at 11:16 PM, Westley Mart?nez wrote: > I understand that in an object method the first argument in the object itself, called self. However, it doesn't have to be called self, and can be called anything. So my question is why is it called self and not this like from C++ and Java. It's kind of a silly question, but one that I'm curious about nevertheless. The idea of requiring references to attributes and methods of self to be explicit comes from Modula-3; likely the naming convention follows the same lineage. From davea at davea.name Mon Mar 3 02:10:13 2014 From: davea at davea.name (Dave Angel) Date: Mon, 3 Mar 2014 02:10:13 -0500 (EST) Subject: Help with "Guess the number" script References: <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> <3FDED793-DA02-4F9F-B431-33499B6949ED@cox.net> Message-ID: Scott W Dunning Wrote in message: > Here are the directions I???m stuck on and what I have so far, I???ll bold the part That assumes that people can see which parts of your message are bold. Rather a poor assumption in a text list like these two python forums. You should be posting in text, not html. Show some code and explain what you wish it would do. Then explain what it actually does, usually by pasting in an exception traceback, or the console output. And respond on the tutor forum, not here. -- DaveA From juraj.ivancic at gmail.com Mon Mar 3 03:15:00 2014 From: juraj.ivancic at gmail.com (=?ISO-8859-2?Q?Juraj_Ivan=E8i=E6?=) Date: Mon, 03 Mar 2014 09:15:00 +0100 Subject: how to get bytes from bytearray without copying In-Reply-To: <20140303004458.GA73815@cskk.homeip.net> References: <20140303004458.GA73815@cskk.homeip.net> Message-ID: On 3.3.2014. 1:44, Cameron Simpson wrote: >> ValueError: cannot hash writable memoryview object > > Have you considered subclassing memoryview and giving the subclass > a __hash__ method? I have, and then, when I failed to subclass it, I considered doing aggregation, and make it behave byte-like. But how to implement the overridden __hash__ method? It will still require at least *some* redundant copying. And there is the slicing thing... the whole idea started to feel like I was performing tonsillectomy through the anal cavity. From juraj.ivancic at gmail.com Mon Mar 3 03:52:25 2014 From: juraj.ivancic at gmail.com (=?ISO-8859-2?Q?Juraj_Ivan=E8i=E6?=) Date: Mon, 03 Mar 2014 09:52:25 +0100 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: On 3.3.2014. 1:49, Mark Lawrence wrote: > If your data is readonly why can't you simply read it as bytes in the > first place? Failing that from > http://docs.python.org/3/library/stdtypes.html#memoryview > > tobytes() - Return the data in the buffer as a bytestring. This is > equivalent to calling the bytes constructor on the memoryview. > > >>> m = memoryview(b"abc") > >>> m.tobytes() > b'abc' > >>> bytes(m) > b'abc' Initially it has to be a bytearray because I read this data from a socket. My point is that once I have a bytearray x, then m = memoryview(bytes(x)) is a very expensive way to make a read-only memoryview, opposed to m = memoryview(x) or (fictional) m = memoryview(x, force_readonly=True) especially if the x-es are many, large, and occur often. I feel like memoryview's __hash__ is trying to be to smart for its own good, and that it should just return the damn hash like its name suggests, regardless of the value of 'writable' flag. From juraj.ivancic at gmail.com Mon Mar 3 04:09:56 2014 From: juraj.ivancic at gmail.com (=?ISO-8859-2?Q?Juraj_Ivan=E8i=E6?=) Date: Mon, 03 Mar 2014 10:09:56 +0100 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: On 3.3.2014. 2:27, Ian Kelly wrote: > Python 3.3 has a C API function to create a memoryview for a char*, > that can be made read-only. > > http://docs.python.org/3/c-api/memoryview.html#PyMemoryView_FromMemory Yes, this is probably what I'll do in absence of pure Python solution. Thanks for the tip. > Or you could bite the bullet and copy everything > once at the start to create a bytes object, and then never have to > worry about it again. That would be a surrender :-) From nomail at invalid.com Mon Mar 3 04:42:30 2014 From: nomail at invalid.com (ast) Date: Mon, 3 Mar 2014 10:42:30 +0100 Subject: Reference Message-ID: <53144e8d$0$2149$426a74cc@news.free.fr> hello Consider following code: >>> A=7 >>> B=7 >>> A is B True I understand that there is a single object 7 somewhere in memory and both variables A and B point toward this object 7 now do the same with a list: >>> l1 = [1, 2] >>> l2 = [1, 2] >>> l1 is l2 False It seems this time that there are 2 distincts objects [1, 2] in memory. l1 points toward the first one and l2 points toward the second one. if I change one, the second remains unchanged >>> l1.append(3) >>> l1 [1, 2, 3] >>> l2 [1, 2] I dont really understand why the behavior is different. Both integer 7 and list [1, 2] are objects. Why is it different ? thanks From georg at python.org Mon Mar 3 04:51:38 2014 From: georg at python.org (Georg Brandl) Date: Mon, 03 Mar 2014 10:51:38 +0100 Subject: [RELEASED] Python 3.3.5 release candidate 2 Message-ID: <531450AA.3030005@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the release of Python 3.3.5, release candidate 2. Python 3.3.5 includes a fix for a regression in zipimport in 3.3.4 (see http://bugs.python.org/issue20621) and a few other bugs. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in the 3.3 series, see http://docs.python.org/3.3/whatsnew/3.3.html To download Python 3.3.5 visit: http://www.python.org/download/releases/3.3.5/ This is a preview release, please report any bugs to http://bugs.python.org/ The final release is scheduled one week from now. Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iEYEARECAAYFAlMUUKoACgkQN9GcIYhpnLD5OACfTpRkcM9aXUx2XbiXoZtIgSE7 BqwAnjwpAuqc9lKJ0O3XOw5qDvDPYsNb =EGuB -----END PGP SIGNATURE----- From ben+python at benfinney.id.au Mon Mar 3 05:00:18 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 03 Mar 2014 21:00:18 +1100 Subject: Object identity (was: Reference) References: <53144e8d$0$2149$426a74cc@news.free.fr> Message-ID: <85y50rioul.fsf@benfinney.id.au> "ast" writes: > >>> A=7 > >>> B=7 > >>> A is B > True > > I understand that there is a single object 7 somewhere in memory and > both variables A and B point toward this object 7 Try not to think in terms of ?point to?. Rather, the names ?A? and ?B? are bound to that object. The distinction is subtle; but it's important to realise that *all* references in Python do this, and there's no way to talk about an object in Python without using a reference. The ?pointer? model from other languages doesn't exist in Python. > now do the same with a list: > > >>> l1 = [1, 2] > >>> l2 = [1, 2] > >>> l1 is l2 > False > > It seems this time that there are 2 distincts objects [1, 2] in > memory. That's correct. > I dont really understand why the behavior is different. Both integer 7 > and list [1, 2] are objects. Why is it different ? Short answer: object identity is an implementation detail. It's up to the Python implementation to decide when to re-use an object when a new one is requested. No guarantee is made, when you ask to create an object, that you won't get an existing one if that would work just as well. Since the integer object 7 is immutable, it will behave the same no matter how many times you ask for a new one, the Python implementation can choose to give you the same object. But it might not ? don't depend on this! Since two separate lists are mutable, each one can have a distinct history after creation, so it would be less helpful to return an existing list when you ask for a new one. But again, there's no guarantee here either! A Python implementation might decide to give you an existing list, if existing guarantees can be kept. The moral is: Don't depend on differences in object identity. You can be guaranteed that an object will retain its own identity, and its identity will always be different from all other co-existing objects that have different values. Beyond that, don't make any assumptions. -- \ ?Programs must be written for people to read, and only | `\ incidentally for machines to execute.? ?Abelson & Sussman, | _o__) _Structure and Interpretation of Computer Programs_ | Ben Finney From alister.ware at ntlworld.com Mon Mar 3 05:06:59 2014 From: alister.ware at ntlworld.com (Alister) Date: Mon, 03 Mar 2014 10:06:59 GMT Subject: Functional programming References: Message-ID: <7vYQu.45397$hQ.28727@fx12.am4> On Mon, 03 Mar 2014 06:14:09 +0700, musicdenotation wrote: > If Python is not a fnctional language, then which programming paradigmis > dominant? Python follows the Pythonic paradigm :-) -- Hope this helps some, sorry for not being able to do a brain dump. - Mike Stump helping a clueless user on the gcc mailing list From nomail at invalid.com Mon Mar 3 05:21:56 2014 From: nomail at invalid.com (ast) Date: Mon, 3 Mar 2014 11:21:56 +0100 Subject: Object identity (was: Reference) In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> Message-ID: <531457cd$0$2032$426a74cc@news.free.fr> thanks ben, that's clear From bob.martin at excite.com Mon Mar 3 05:26:18 2014 From: bob.martin at excite.com (Bob Martin) Date: Mon, 03 Mar 2014 10:26:18 GMT Subject: Functional programming References: Message-ID: in 718085 20140302 231409 musicdenotation at gmail.com wrote: >If Python is not a fnctional language, then which programming paradigmis dom= >inant?= Labels are always misleading. From harrismh777 at gmail.com Mon Mar 3 06:34:30 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 03:34:30 -0800 (PST) Subject: python decimal library dmath.py v0.3 released Message-ID: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> hi folks, Python Decimal Library dmath.py v0.3 Released https://code.google.com/p/pythondecimallibrary/ This code provides the C accelerated decimal module with scientific/transcendental functions for arbitrary precision. I have also included pilib.py which is a PI library of historic algorithms for generating PI, which uses dmath.py. I wish to thank Oscar, Wolfgang, Steven, Chris (and others) for the help you gave me understanding decimal, particularly format, rounding, and context managers. Everything is documented well (including issues) on the code site, and things are working better, and are certainly cleaner. No doubt there are still bugs, but its getting closer. Thanks again. marcus From rustompmody at gmail.com Mon Mar 3 06:45:48 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 03:45:48 -0800 (PST) Subject: Functional programming In-Reply-To: References: Message-ID: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> On Monday, March 3, 2014 6:57:15 AM UTC+5:30, Ned Batchelder wrote: > On 3/2/14 6:14 PM, musicdenotation wrote: > > If Python is not a fnctional language, then which programming paradigmis dominant? > is_a_functional_language() is not a binary condition, yes or no. It's a > continuum. Python has more functional constructs than Pascal, and fewer > than Haskell. I find this the most agreeable answer. I would add: There are really two continuaa: the 'CAN' and the 'CANNOT' (sounds 180 deg apart but they are actually rather independent) As Ned says on the CAN spectrum python sits between standard imperative languages like C,Pascal and Haskell, in fact coming quite close to Haskell. However it is also useful to consider the CANNOT spectrum for beginners/pedagogical purposes. If you start a beginner on a language like Haskell which CANNOT: - express iteration except with recursion - cannot have assignments (and therefore anything remotely like a normal program variable; variables are only ever math variables) - cannot do a 'type-incorrect' expression like >>> [1,2] + [[3,4],[5]] [1, 2, [3, 4], [5]] the beginner will develop a significantly different mind-set than starting from a python-like language From harrismh777 at gmail.com Mon Mar 3 07:02:26 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 04:02:26 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> Message-ID: On Monday, March 3, 2014 5:34:30 AM UTC-6, Mark H. Harris wrote: > hi folks, Terry, I posted this mod as an idea on python-ideas, as you suggested. Also, I made the additional suggestion that decimal floating point be considered as the primary floating point type for python4.x, with an optional binary floating type (2.345b) if the user might like that. As Steven pointed out last week, we have a fast module now for decimal floating point; it seems this is a good time to consider this as a serious idea for future python(s). marcus From rosuav at gmail.com Mon Mar 3 07:20:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 23:20:37 +1100 Subject: Functional programming In-Reply-To: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 10:45 PM, Rustom Mody wrote: > - cannot do a 'type-incorrect' expression like >>>> [1,2] + [[3,4],[5]] > [1, 2, [3, 4], [5]] What do you mean by "type-incorrect"? This is adding two lists and getting back a list. Seems perfectly correct to me. ChrisA From marcuscvj at gmail.com Mon Mar 3 07:32:39 2014 From: marcuscvj at gmail.com (Marcus) Date: Mon, 3 Mar 2014 04:32:39 -0800 (PST) Subject: Iterate through a list and try log in to a website with urllib and re Message-ID: Hello, I'm trying to use urllib and urllib2 to open an url + login_data in a for loop. How can I display when successfully logged in and how to show when the login is denied? I've tried use this: html_content = urllib2.urlopen(url).read() re.findall('ERROR: The password you entered for the username USER is incorrect.', html_content) 1. I want to try an if statement in a for loop 2. Iterate through a list and when the first password in the list is denied. It shall continue with the next password in the list and try that one. 3. When it's successfully logged in the program will stop the loop and print out the password that matches. I'm stuck and need some help creating this. From marcuscvj at gmail.com Mon Mar 3 07:35:41 2014 From: marcuscvj at gmail.com (Marcus) Date: Mon, 3 Mar 2014 04:35:41 -0800 (PST) Subject: Iterate through a list and try log in to a website with urllib and re In-Reply-To: References: Message-ID: <1177d930-a3c4-4152-818c-33d5172083f8@googlegroups.com> This is the code right now: http://pastebin.com/pE1YZX2K From rosuav at gmail.com Mon Mar 3 07:44:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 23:44:27 +1100 Subject: Iterate through a list and try log in to a website with urllib and re In-Reply-To: References: <1177d930-a3c4-4152-818c-33d5172083f8@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 11:44 PM, Chris Angelico wrote: > So basically, you're doing a dictionary attack. May I ask why you're > doing this, exactly? From rosuav at gmail.com Mon Mar 3 07:45:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 23:45:44 +1100 Subject: Iterate through a list and try log in to a website with urllib and re In-Reply-To: References: <1177d930-a3c4-4152-818c-33d5172083f8@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 11:44 PM, Chris Angelico wrote: > So basically, you're doing a dictionary attack. May I ask why you're > doing this, exactly? oops, misclicked. I note that the user name 'alex' does not appear to match your name. I'm going to want a good reason for this code to be written, else you're on your own - I don't intend to help you steal someone else's password. ChrisA From rosuav at gmail.com Mon Mar 3 07:44:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 3 Mar 2014 23:44:20 +1100 Subject: Iterate through a list and try log in to a website with urllib and re In-Reply-To: <1177d930-a3c4-4152-818c-33d5172083f8@googlegroups.com> References: <1177d930-a3c4-4152-818c-33d5172083f8@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 11:35 PM, Marcus wrote: > This is the code right now: http://pastebin.com/pE1YZX2K That looks short enough to include in-line, no need to point us to an external site :) So basically, you're doing a dictionary attack. May I ask why you're doing this, exactly? ChrisA From marcuscvj at gmail.com Mon Mar 3 07:51:31 2014 From: marcuscvj at gmail.com (Marcus) Date: Mon, 3 Mar 2014 04:51:31 -0800 (PST) Subject: Iterate through a list and try log in to a website with urllib and re In-Reply-To: References: <1177d930-a3c4-4152-818c-33d5172083f8@googlegroups.com> Message-ID: Yes, it's only for my own use on my local WordPress installation. Only educational use. From rosuav at gmail.com Mon Mar 3 08:00:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 00:00:11 +1100 Subject: Iterate through a list and try log in to a website with urllib and re In-Reply-To: References: <1177d930-a3c4-4152-818c-33d5172083f8@googlegroups.com> Message-ID: On Mon, Mar 3, 2014 at 11:51 PM, Marcus wrote: > Yes, it's only for my own use on my local WordPress installation. Only educational use. What are you trying to learn, exactly? How to break into a WP site? Still dubious. ChrisA From marcuscvj at gmail.com Mon Mar 3 08:05:38 2014 From: marcuscvj at gmail.com (Marcus) Date: Mon, 3 Mar 2014 05:05:38 -0800 (PST) Subject: Iterate through a list and try log in to a website with urllib and re In-Reply-To: References: <1177d930-a3c4-4152-818c-33d5172083f8@googlegroups.com> Message-ID: <948ed27b-e9ec-4062-97d7-2b4b0bb05672@googlegroups.com> It's not that hard to find a program that does this already. But I'm trying to learn how to use these modules to create this. I've started it and now i want to complete it so I can create another program and learn more about other stuff, maybe a Twitter script or something. How do I learn when not practice? From harrismh777 at gmail.com Mon Mar 3 08:09:31 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 05:09:31 -0800 (PST) Subject: Reference In-Reply-To: <53144e8d$0$2149$426a74cc@news.free.fr> References: <53144e8d$0$2149$426a74cc@news.free.fr> Message-ID: On Monday, March 3, 2014 3:42:30 AM UTC-6, ast wrote: > Consider following code: > > >>> A=7 > >>> B=7 > >>> A is B > True The names A and B are both bound to the same object (7). You will discover that this is True for all small ints less than 257; on CPython3.3.4. I just checked it. :) Its just more efficient to do this for small ints because they are immutable (1) and because they are used for frequently (2). As somebody pointed out last week, don't use "is" for ints and strings (generally speaking). Value is what's important here, not identity. My python coding is yet simple and straight forward enough that I have not had a need yet for "is". Cheers marcus From oscar.j.benjamin at gmail.com Mon Mar 3 08:34:40 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 3 Mar 2014 13:34:40 +0000 Subject: python decimal library dmath.py v0.3 released In-Reply-To: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> Message-ID: On 3 March 2014 11:34, Mark H. Harris wrote: > hi folks, > > Python Decimal Library dmath.py v0.3 Released > > https://code.google.com/p/pythondecimallibrary/ Hi Mark, Is this available on PyPI? It seems there already is a "dmath" package on PyPI that was written by someone else some time ago so you might need to use a different name: https://pypi.python.org/pypi/dmath/0.9 Oscar From mailinglists at vanwingerde.nl Mon Mar 3 08:35:41 2014 From: mailinglists at vanwingerde.nl (Jaap van Wingerde) Date: Mon, 3 Mar 2014 13:35:41 +0000 Subject: modification time in Python - Django: datetime != datetime :-( Message-ID: <20140303133541.66fccbbb@lia.custard.shrl.nl> Django views.py: ... pwd = os.path.dirname(os.path.realpath(__file__ )) home_lastmod = strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime(pwd+'/templates/art_index.html'))) ... The template gives a wrong modification time: "2014-03-02T19:03:55Z". ... jaap at liakoster:~$ python Python 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os, time >>> from time import >>> gmtime >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html'))) '2014-03-02T19:03:55Z' >>> quit() jaap at liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 +0000 /var/django/test2/art/templates/art_index.html jaap at liakoster:~$ ... ls gives the right modification time. What is wrong? ... jaap at liakoster:~$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 7.4 (wheezy) Release: 7.4 Codename: wheezy jaap at liakoster:~$ uname -a Linux liakoster.shrl.nl 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 GNU/Linux jaap at liakoster:~$ ... -- Jaap van Wingerde e-mail: 1234567890 at vanwingerde.nl From roy at panix.com Mon Mar 3 08:41:10 2014 From: roy at panix.com (Roy Smith) Date: Mon, 03 Mar 2014 08:41:10 -0500 Subject: Password validation security issue References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > The greatest threats these days are from the network, not from someone > physically walking into an office. (That said, though, the low-hanging > fruit from walking into an office can be *extremely* tempting. Pulling > off a basic password leech off sticky notes is often so easy that it > can be done as a visitor, or at least as a pizza deliveryman.) Doesn't even require physical presence. With the ubiquity of various video chat applications, as long as the sticky note is in the field of view of the camera, you've leaked the password. With the right lighting, I wouldn't be surprised if you could pick up the reflection of a sticky note in somebody's eyeglasses. So, here's my own (embarrassing) story of password leaking. Back when smartphones were new, I had one of the early Palm Treos. I decided a good place to store my passwords was as fields on my own card. What I didn't realize was that if I beamed[*] my card to somebody, I was also giving them all my passwords, mostly because it had never occurred to me that I might want to beam my card to somebody. Until somebody else in my office got another smart phone that had beaming capabilities and we decided to see how it worked. It occurred to me as soon as we completed the first experiment. I used to work at which had a typical big company IT department which enforced all sorts of annoying pseudo-security rules. As far as I could figure out, however, all you needed to get them to reset anybody's password and tell you the new one was to know their employee ID number (visible on the front of their ID badge), and to make the call from their desk phone. [*] Beaming: a prehistoric technology which allows exchange of data over an infrared light beam. From roy at panix.com Mon Mar 3 08:47:16 2014 From: roy at panix.com (Roy Smith) Date: Mon, 03 Mar 2014 08:47:16 -0500 Subject: Iterate through a list and try log in to a website with urllib and re References: Message-ID: In article , Marcus wrote: > I'm trying to use urllib and urllib2 to open an url + login_data in a for > loop. Step 1: Ignore all that crap and get http://www.python-requests.org/ > How can I display when successfully logged in and how to show when the > login is denied? > > I've tried use this: > > html_content = urllib2.urlopen(url).read() > re.findall('ERROR: The password you entered for the username USER is > incorrect.', html_content) In the ideal case, whatever you're talking to will return a success or failure indication in the HTTP status code. Lacking that, it will at least return something intended to be parsed (like JSON). Lacking that (and, unfortunately, common), you're reduced to screen-scraping. But, if you've got to do that, at least use a tool like lxml or BeautifulSoup to parse the HTML. From rustompmody at gmail.com Mon Mar 3 08:48:00 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 05:48:00 -0800 (PST) Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> Message-ID: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> On Monday, March 3, 2014 5:50:37 PM UTC+5:30, Chris Angelico wrote: > On Mon, Mar 3, 2014 at 10:45 PM, Rustom Mody wrote: > > - cannot do a 'type-incorrect' expression like > >>>> [1,2] + [[3,4],[5]] > > [1, 2, [3, 4], [5]] > What do you mean by "type-incorrect"? This is adding two lists and > getting back a list. Seems perfectly correct to me. Here's the behavior from an (old version of) haskell. Unfortunately modern versions give a less helpful error message '++' is list-append, '?' is the prompt ? [1,2] + [[3,4],[5]] ERROR: Type error in application *** expression : [1,2] + [[3,4],[5]] *** term : [1,2] *** type : [Int] *** does not match : [[Int]] IOW [1,2,[3,4],[5]] is a type-wise ill-formed expression just as in python [[1,2]) is syntax-wise ill-formed Is it worth having such a restriction? Thats a different argument... From rustompmody at gmail.com Mon Mar 3 08:51:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 05:51:21 -0800 (PST) Subject: Functional programming In-Reply-To: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> Message-ID: <3a913df5-5034-4d9c-985a-a46a7015d6cd@googlegroups.com> On Monday, March 3, 2014 7:18:00 PM UTC+5:30, Rustom Mody wrote: > Unfortunately modern versions give a less helpful error message > '++' is list-append, '?' is the prompt > ? [1,2] + [[3,4],[5]] Whoops Wrong cut-paste! ? [1,2] ++ [[3,4],[5]] ERROR: Type error in application *** expression : [1,2] ++ [[3,4],[5]] *** term : [1,2] *** type : [Int] *** does not match : [[Int]] ? From rosuav at gmail.com Mon Mar 3 08:55:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 00:55:45 +1100 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 12:41 AM, Roy Smith wrote: > I used to work at which had a typical big company IT > department which enforced all sorts of annoying pseudo-security rules. > As far as I could figure out, however, all you needed to get them to > reset anybody's password and tell you the new one was to know their > employee ID number (visible on the front of their ID badge), and to make > the call from their desk phone. Technically, that's a separate vulnerability. If you figure out someone else's password, you can log in as that person and nobody is any the wiser (bar detailed logs eg of IP addresses). Getting a password reset will at least alert the person on their next login. That may or may not be safe, of course. Doing a password reset at 4:30pm the day before someone goes away for two months might give you free reign for that time *and* might not even arouse suspicions ("I can't remember my password after the break, can you reset it please?"). But it's an attack vector that MUST be considered, which is why I never tell the truth in any "secret question / secret answer" boxes. Why some sites think "mother's maiden name" is at all safe is beyond my comprehension. And that's not counting the ones that I can't answer because I can't find the "NaN" key on my keyboard, like "Surname of first girlfriend". *twiddle thumbs* ChrisA From rosuav at gmail.com Mon Mar 3 09:00:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 01:00:17 +1100 Subject: Functional programming In-Reply-To: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 12:48 AM, Rustom Mody wrote: > ? [1,2] + [[3,4],[5]] > ERROR: Type error in application > *** expression : [1,2] + [[3,4],[5]] > *** term : [1,2] > *** type : [Int] > *** does not match : [[Int]] > > IOW [1,2,[3,4],[5]] > is a type-wise ill-formed expression just as in python > [[1,2]) > is syntax-wise ill-formed > > Is it worth having such a restriction? > Thats a different argument... How do you know that [1,2] is a list that must contain nothing but integers? By extension, it's also a list that must contain positive integers less than three, so adding [5] violates that. And [] is a list that must contain nothing, ergo it can't be added to, although (since it contains nothing) it can be added to anything. Some languages do let you specify element types (Pike has an "array" type that can hold anything, or you can say "array(int)" to restrict it to integers; you could also say "array(int(1..2))" to specify what I said above, if you actually intend that), but without a declaration from the programmer, it's dangerous to assume there's an error. ChrisA From rosuav at gmail.com Mon Mar 3 09:08:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 01:08:52 +1100 Subject: modification time in Python - Django: datetime != datetime :-( In-Reply-To: <20140303133541.66fccbbb@lia.custard.shrl.nl> References: <20140303133541.66fccbbb@lia.custard.shrl.nl> Message-ID: On Tue, Mar 4, 2014 at 12:35 AM, Jaap van Wingerde wrote: >>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html'))) > '2014-03-02T19:03:55Z' >>>> quit() > jaap at liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html > -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 +0000 /var/django/test2/art/templates/art_index.html See if ls is actually giving you ctime rather than mtime - compare the results if you ask for os.path.getctime. ChrisA From rustompmody at gmail.com Mon Mar 3 09:08:11 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 06:08:11 -0800 (PST) Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> Message-ID: <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> On Monday, March 3, 2014 7:30:17 PM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 12:48 AM, Rustom Mody wrote: > > ? [1,2] + [[3,4],[5]] > > ERROR: Type error in application > > *** expression : [1,2] + [[3,4],[5]] > > *** term : [1,2] > > *** type : [Int] > > *** does not match : [[Int]] > > IOW [1,2,[3,4],[5]] > > is a type-wise ill-formed expression just as in python > > [[1,2]) > > is syntax-wise ill-formed > > Is it worth having such a restriction? > > Thats a different argument... > How do you know that [1,2] is a list that must contain nothing but > integers? By extension, it's also a list that must contain positive > integers less than three, so adding [5] violates that. And [] is a > list that must contain nothing, ergo it can't be added to, although > (since it contains nothing) it can be added to anything. If 'integer-less-than-3' were a type then yes there would be this problem. More generally, if types could overlap then automatic type-inference is impossible Whether all thats good is as I earlier said a different argument The OP asked about FP and so its appropriate to mention how python's and standard FPL's choices differ From ndbecker2 at gmail.com Mon Mar 3 09:17:24 2014 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 3 Mar 2014 09:17:24 -0500 (EST) Subject: How security holes happen References: Message-ID: Charles R Harris Wrote in message: > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion at scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > Imo the lesson here is never write in low level c. Use modern languages with well designed exception handling. -- ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From invalid at invalid.invalid Mon Mar 3 09:18:09 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 3 Mar 2014 14:18:09 +0000 (UTC) Subject: [OT] Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: On 2014-03-02, Chris Angelico wrote: > On Mon, Mar 3, 2014 at 3:55 AM, Mark Lawrence wrote: >> On 02/03/2014 16:45, Grant Edwards wrote: >>> >>> >>> That's irrelevent. The actual location of the memory containing the >>> struct object (static, stack, heap, shared) doesn't matter. The >>> address of the first field in a struture object _is_ the address of >>> the structure object. >>> >> >> You say struture, I'll say structure, let's call the whole thing off :) > >:) > > Note that, technically, Grant is correct as long as you grant (heh) > that a structure may have an invisible member, the virtual function > table pointer. C++ only (I don't believe C has virtual functions - > but it may have grown them in one of the newer standards), so in C, > all members are public. Yes. I was talking about C, not C++. I made that quite clear in portions of my post that have been elided. In C there is no such thing as a virtual table pointer. -- Grant Edwards grant.b.edwards Yow! We have DIFFERENT at amounts of HAIR -- gmail.com From rosuav at gmail.com Mon Mar 3 09:23:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 01:23:01 +1100 Subject: Functional programming In-Reply-To: <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody wrote: >> How do you know that [1,2] is a list that must contain nothing but >> integers? By extension, it's also a list that must contain positive >> integers less than three, so adding [5] violates that. And [] is a >> list that must contain nothing, ergo it can't be added to, although >> (since it contains nothing) it can be added to anything. > > If 'integer-less-than-3' were a type then yes there would be this > problem. More generally, if types could overlap then automatic > type-inference is impossible > First, does Haskell allow this? ? [1,2,'foo'] ++ [3,4,'bar'] If not, then find some other form of the expression that has the same point, and substitute in for the below. And then: which of these is permitted? ? [1,2] ++ [3,4,'bar'] ? [1,2,'foo'] ++ [3,4] ? [] ++ [3,4,'bar'] ? [1,2,'foo'] ++ [] ? ([1,2,'foo'] ++ []) ++ [3,4,'bar'] ? [1,2,'foo'] ++ ([] ++ [3,4,'bar']) If it's okay to have heterogeneous lists, how do you tell it that your [1,2] is actually going to get strings in it later, and that it's okay to combine it with one that has strings? With Pike, that's all based on the variable type. (There is type inference; the type of an array containing just 3 and 4 is "array(int(3..4))", but it's acceptable to add that to an array containing the string "asdf", which itself has type "array(string(97..115))" - the combination would be "array(int(3..4) | string(97..115))", which gets a bit wordy.) I can't assign an array(string) to a variable that's been declared as taking array(int). But I can assign an array(int) to a variable declared as accepting array(int|string), and then I can append a string to it, because that's legal based on the destination. ChrisA From rosuav at gmail.com Mon Mar 3 09:25:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 01:25:14 +1100 Subject: [OT] Can global variable be passed into Python function? In-Reply-To: References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87sird7wuw.fsf@handshake.de> <8454E8CB-E6E3-452F-8E54-9A77BFF34EC2@gmail.com> <1m3gg9lbf2ln5m2kbki954t17mqni3b20k@4ax.com> <53095145$0$29985$c3e8da3$5496439d@news.astraweb.com> <877g8mcg1m.fsf@elektro.pacujo.net> <87ob1yay9m.fsf@elektro.pacujo.net> <08aa32de-cd51-4888-bd60-2c2b53d86ecc@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 1:18 AM, Grant Edwards wrote: >> Note that, technically, Grant is correct as long as you grant (heh) >> that a structure may have an invisible member, the virtual function >> table pointer. C++ only (I don't believe C has virtual functions - >> but it may have grown them in one of the newer standards), so in C, >> all members are public. > > Yes. I was talking about C, not C++. I made that quite clear in > portions of my post that have been elided. In C there is no such > thing as a virtual table pointer. I wasn't certain of the newer C standards. C's been gaining all sorts of features, not all of which are necessary, and it's entirely possible based on my current knowledge that C specifies #include ... ChrisA From mailinglists at vanwingerde.nl Mon Mar 3 09:28:21 2014 From: mailinglists at vanwingerde.nl (Jaap van Wingerde) Date: Mon, 3 Mar 2014 14:28:21 +0000 Subject: modification time in Python - Django: datetime != datetime :-( In-Reply-To: References: <20140303133541.66fccbbb@lia.custard.shrl.nl> Message-ID: <20140303142821.0d24c929@lia.custard.shrl.nl> Op schreef Chris Angelico in bericht : > See if ls is actually giving you ctime rather than mtime - compare the > results if you ask for os.path.getctime. jaap at liakoster:~$ python Python 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os, time >>> from time import gmtime >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html'))) '2014-03-02T19:03:55Z' >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getctime('/var/django/test2/art/templates/art_index.html'))) '2014-03-02T19:03:55Z' >>> quit() jaap at liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 +0000 /var/django/test2/art/templates/art_index.html jaap at liakoster:~$ ls is giving me the modified time. From harrismh777 at gmail.com Mon Mar 3 09:27:56 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 06:27:56 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> Message-ID: On Monday, March 3, 2014 7:34:40 AM UTC-6, Oscar Benjamin wrote: > Python Decimal Library dmathlib.py v0.3 Released > https://code.google.com/p/pythondecimallibrary/ > Is this available on PyPI? It seems there already is a "dmath" package > on PyPI that was written by someone else some time ago so you might > need to use a different name: > Oscar hi Oscar; thanks again for your help. Yes, I actually intended to call it dmathlib.py at first, and then had my brain stuck on dmath, partly because several folks threw that name around, and partly because I got used to abbreviating it and forgot to fix things up name-wise. [ Done ] Actually, code.google tries to help folks with that because if the name is taken you have to create a unique name; which I did, but I forgot to fix up all the references and heading. Thanks again for keeping me accountable. Kind regards, marcus From invalid at invalid.invalid Mon Mar 3 09:29:38 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 3 Mar 2014 14:29:38 +0000 (UTC) Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> Message-ID: On 2014-03-03, ast wrote: > hello > > Consider following code: > >>>> A=7 >>>> B=7 >>>> A is B > True > > I understand that there is a single object 7 somewhere in memory Maybe, maybe not. Integer are immutable, so that's allowed but not required. In CPython, that's true for small integers, but that is an implementation detail, and you shouldn't depend on it. > and both variables A and B point toward this object 7 They might. They might not. > now do the same with a list: > >>>> l1 = [1, 2] >>>> l2 = [1, 2] >>>> l1 is l2 > False > > It seems this time that there are 2 distincts objects [1, 2] in > memory. Yep. Lists are mutable, therefore each literal produces a distinct object. > l1 points toward the first one and l2 points toward the > second one. Yep. > I dont really understand why the behavior is different. > Both integer 7 and list [1, 2] are objects. Why is it > different ? Integer objects are immutable (they can't change value), therefore you can reuse them without causing problems. Lists are mutable (you can change the values in them), so you can't reuse them. -- Grant Edwards grant.b.edwards Yow! Maybe I should have at asked for my Neutron Bomb gmail.com in PAISLEY -- From rustompmody at gmail.com Mon Mar 3 09:38:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 06:38:33 -0800 (PST) Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> Message-ID: <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> On Monday, March 3, 2014 7:53:01 PM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody wrote: > >> How do you know that [1,2] is a list that must contain nothing but > >> integers? By extension, it's also a list that must contain positive > >> integers less than three, so adding [5] violates that. And [] is a > >> list that must contain nothing, ergo it can't be added to, although > >> (since it contains nothing) it can be added to anything. > > If 'integer-less-than-3' were a type then yes there would be this > > problem. More generally, if types could overlap then automatic > > type-inference is impossible > First, does Haskell allow this? > ? [1,2,'foo'] ++ [3,4,'bar'] > If not, then find some other form of the expression that has the same > point, and substitute in for the below. And then: which of these is > permitted? Dunno what you mean/whats the 'point' > ? [1,2] ++ [3,4,'bar'] > ? [1,2,'foo'] ++ [3,4] > ? [] ++ [3,4,'bar'] > ? [1,2,'foo'] ++ [] > ? ([1,2,'foo'] ++ []) ++ [3,4,'bar'] > ? [1,2,'foo'] ++ ([] ++ [3,4,'bar']) > If it's okay to have heterogeneous lists, Its not. None of the above work If you want the (semantic) equivalent of python's [1,2,'foo'] you need to make an explicit union Int and String and its that *single* union type's elements that must go in. In all cases its always a single type. And so sum([1,2,[3]) is a syntax error unlike python where its a runtime error From rosuav at gmail.com Mon Mar 3 10:01:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 02:01:47 +1100 Subject: Functional programming In-Reply-To: <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 1:38 AM, Rustom Mody wrote: > If you want the (semantic) equivalent of python's [1,2,'foo'] > you need to make an explicit union Int and String and its that > *single* union type's elements that must go in. > > In all cases its always a single type. And so > sum([1,2,[3]) Okay. That's how the declaration goes, then. So how do you tell it that 1 isn't an Int, it's a member of the union of Int and String? How do you create a list which has [Int_String(1), Int_String(2)] and is therefore allowed to be added to [Int_String('foo')] ? Can you do that with literals? This is why it's tricky to put rules in based on type inference. The programmer's intent isn't in the picture. If Python ever acquires that kind of restriction ("here's a list that can contain only this type / these types of object"), I would hope that it's left up to the programmer, not the compiler, to stipulate. That's how it is with Pike (if you just say "array", it can take anything), and that's the only way to be sure the programmer doesn't have to fight the language. You said earlier >> On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody wrote: >> > If 'integer-less-than-3' were a type then yes there would be this >> > problem. More generally, if types could overlap then automatic >> > type-inference is impossible The type "Int" overlaps with the type "Union of Int and String". How is that resolved? Type inference ignores unions? That's the only way I can think of. Hence the original difficulty of type-inferring on a list that isn't complete yet. ChrisA From andywu1206 at gmail.com Mon Mar 3 10:22:22 2014 From: andywu1206 at gmail.com (Harry Wood) Date: Mon, 3 Mar 2014 07:22:22 -0800 (PST) Subject: How to create a voting website by Python and Flask? Message-ID: <39d907df-7fc9-4843-ab8a-cb6a16e668a9@googlegroups.com> How to create a voting website by Python and Flask? I studying Python and Flask for some months, and - Now I have some Python & Flask basic skills. - I need some advices like following example: Step 1: You could writing an voting application by Python Step 2: You could build a website by Flask ... Thanks very much! From harrismh777 at gmail.com Mon Mar 3 10:22:47 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 07:22:47 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> Message-ID: <466dcd2a-4198-47ac-9797-d4c993e03d61@googlegroups.com> On Monday, March 3, 2014 7:34:40 AM UTC-6, Oscar Benjamin wrote: > On 3 March 2014 11:34, Mark H. Harris wrote: > > Is this available on PyPI? It seems there already is a "dmath" package > on PyPI that was written by someone else some time ago so you might > need to use a different name: > Oscar Oscar, thanks again for your help, and for keeping me accountable. I did intend on using the naming convention pythondecimallibrary but got dmath stuck in my mind from the discussions earlier last week. At any rate the naming problem is fixed. Thanks again. Python3.3 Decimal Library v0.3 is Released here: https://code.google.com/p/pythondecimallibrary/ *pdeclib.py* is the decimal library, and *pilib.py* is the PI library. marcus From rustompmody at gmail.com Mon Mar 3 10:28:38 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 07:28:38 -0800 (PST) Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> Message-ID: <8dbc91d9-42e5-4404-ba10-7a6d8e404986@googlegroups.com> On Monday, March 3, 2014 8:31:47 PM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 1:38 AM, Rustom Mody wrote: > > If you want the (semantic) equivalent of python's [1,2,'foo'] > > you need to make an explicit union Int and String and its that > > *single* union type's elements that must go in. > > In all cases its always a single type. And so > > sum([1,2,[3]) > Okay. That's how the declaration goes, then. So how do you tell it > that 1 isn't an Int, it's a member of the union of Int and String? How > do you create a list which has [Int_String(1), Int_String(2)] and is > therefore allowed to be added to [Int_String('foo')] ? Can you do that > with literals? Mmmm This is getting a bit OT for a python list Anyway here goes The Union type is called Either. Its got two constructors -- Left and Right -- better to think of them as tags to not confuse with OO constructors. The names Left and Right seem to be a bit meaningless because the Either type is completely generic -- any types S and T can be 'unioned' as Either S T where the S components look like Left x for x : S and the T components look like Right x for x : T So python's [1,2,"foo"] is written as [Left 1, Left 2, Right "foo"] > This is why it's tricky to put rules in based on type inference. The > programmer's intent isn't in the picture. If Python ever acquires that > kind of restriction ("here's a list that can contain only this type / > these types of object"), I would hope that it's left up to the > programmer, not the compiler, to stipulate. That's how it is with Pike > (if you just say "array", it can take anything), and that's the only > way to be sure the programmer doesn't have to fight the language. > You said earlier > >> On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody wrote: > >> > If 'integer-less-than-3' were a type then yes there would be this > >> > problem. More generally, if types could overlap then automatic > >> > type-inference is impossible > The type "Int" overlaps with the type "Union of Int and String". How > is that resolved? By decreeing "no overlap!" :-) Left 1 : Either Int String whereas 1 : Int Strictly speaking 'union' should be called 'disjoint union' but this is so universal in programming that its dropped as redundant. Heck even C's union is disjoint! If we have union u { int i; char c; }; union u x; Now you cant interchange the usages of x x.i and x.c From rustompmody at gmail.com Mon Mar 3 10:52:29 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 07:52:29 -0800 (PST) Subject: Reference In-Reply-To: <53144e8d$0$2149$426a74cc@news.free.fr> References: <53144e8d$0$2149$426a74cc@news.free.fr> Message-ID: <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> On Monday, March 3, 2014 3:12:30 PM UTC+5:30, ast wrote: > hello > Consider following code: > >>> A=7 > >>> B=7 > >>> A is B > True > I understand that there is a single object 7 somewhere in memory and > both variables A and B point toward this object 7 > now do the same with a list: > >>> l1 = [1, 2] > >>> l2 = [1, 2] > >>> l1 is l2 > False > It seems this time that there are 2 distincts objects [1, 2] in memory. l1 points > toward the first one and l2 points toward the second one. > if I change one, the second remains unchanged > >>> l1.append(3) > >>> l1 > [1, 2, 3] > >>> l2 > [1, 2] > I dont really understand why the behavior is different. > Both integer 7 and list [1, 2] are objects. Why is it > different ? Short answer: Avoid using 'is'. Long answer: http://www.beyondwilber.ca/healing-thinking/non-identity-korzybski.html Pragmatic answer: Think of 'is' as a short-form for 'machine-rep-is' And use machine representations with the same alacrity that a C programmer uses inline assembly From david.froger at inria.fr Mon Mar 3 11:01:49 2014 From: david.froger at inria.fr (David Froger) Date: Mon, 03 Mar 2014 17:01:49 +0100 Subject: How to create a voting website by Python and Flask? In-Reply-To: <39d907df-7fc9-4843-ab8a-cb6a16e668a9@googlegroups.com> References: <39d907df-7fc9-4843-ab8a-cb6a16e668a9@googlegroups.com> Message-ID: <20140303160149.11066.53696@fl-58186.rocq.inria.fr> Quoting Harry Wood (2014-03-03 16:22:22) > How to create a voting website by Python and Flask? I studying Python and Flask for some months, and > > - Now I have some Python & Flask basic skills. > - I need some advices like following example: > Step 1: You could writing an voting application by Python Step 2: You could build a website by Flask ... > Thanks very much! > -- > https://mail.python.org/mailman/listinfo/python-list Hi Harry, For example: You define an URL, something like /voting. Used with a GET request, the Python function associated to the /voting URL renders and returns a template containing a form. You can create the form using Flask-WTF, and use Flask-Bootstrap to make your page looks better. The user fill the form, and submit it (POST request on /voting). Here, the function associated with /voting get the form data, and store it in a database. You define a second URL, /results, which on a GET request reads your database and returns the results by rendering a template, something like render_template('result.html', result=result) Hope it helps! David From python at mrabarnett.plus.com Mon Mar 3 11:29:51 2014 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 03 Mar 2014 16:29:51 +0000 Subject: Password validation security issue In-Reply-To: References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5314ADFF.6000909@mrabarnett.plus.com> On 2014-03-03 13:55, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 12:41 AM, Roy Smith wrote: >> I used to work at which had a typical big company IT >> department which enforced all sorts of annoying pseudo-security rules. >> As far as I could figure out, however, all you needed to get them to >> reset anybody's password and tell you the new one was to know their >> employee ID number (visible on the front of their ID badge), and to make >> the call from their desk phone. > > Technically, that's a separate vulnerability. If you figure out > someone else's password, you can log in as that person and nobody is > any the wiser (bar detailed logs eg of IP addresses). Getting a > password reset will at least alert the person on their next login. > That may or may not be safe, of course. Doing a password reset at > 4:30pm the day before someone goes away for two months might give you > free reign for that time *and* might not even arouse suspicions ("I > can't remember my password after the break, can you reset it > please?"). > > But it's an attack vector that MUST be considered, which is why I > never tell the truth in any "secret question / secret answer" boxes. > Why some sites think "mother's maiden name" is at all safe is beyond > my comprehension. And that's not counting the ones that I can't answer > because I can't find the "NaN" key on my keyboard, like "Surname of > first girlfriend". *twiddle thumbs* > I don't think you're obliged to answer such questions truthfully. Q: Surname of first girlfriend? A: Luxury Yacht From oscar.j.benjamin at gmail.com Mon Mar 3 11:44:16 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 3 Mar 2014 16:44:16 +0000 Subject: python decimal library dmath.py v0.3 released In-Reply-To: <466dcd2a-4198-47ac-9797-d4c993e03d61@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <466dcd2a-4198-47ac-9797-d4c993e03d61@googlegroups.com> Message-ID: On 3 March 2014 15:22, Mark H. Harris wrote: > On Monday, March 3, 2014 7:34:40 AM UTC-6, Oscar Benjamin wrote: >> On 3 March 2014 11:34, Mark H. Harris wrote: >> >> Is this available on PyPI? > > Python3.3 Decimal Library v0.3 is Released here: > > https://code.google.com/p/pythondecimallibrary/ > > *pdeclib.py* is the decimal library, and *pilib.py* is the PI library. Is it on PyPI though? I was referring to a PyPI name so that people could install it with "pip install pdeclib" (or whatever you called it). That's how open source Python projects are usually distributed. Oscar From steve+comp.lang.python at pearwood.info Mon Mar 3 11:46:38 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 16:46:38 GMT Subject: Password validation security issue References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5314b1ed$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 00:55:45 +1100, Chris Angelico wrote: > But it's an attack vector that MUST be considered, which is why I never > tell the truth in any "secret question / secret answer" boxes. Why some > sites think "mother's maiden name" is at all safe is beyond my > comprehension. And that's not counting the ones that I can't answer > because I can't find the "NaN" key on my keyboard, like "Surname of > first girlfriend". *twiddle thumbs* If you lie to these secret questions -- and I strongly recommend that you do -- you should record the answers somewhere so you can retrieve them later, long after you've forgotten whether the name of your first pet was Obama bin Bush or Tarzan the King of the Desert. Trust me on this, you will need them. The missus has a Yahoo account, and being paranoid even by my standards for keeping her web presence completely separate from her real life, she invented fake answers to the secret questions like Your Birthday. (As you should. It is my opinion that lying to big faceless corporations is not a sin, but a duty. They are not on your side, and the more they know about you the more they will abuse the knowledge.) So fast forward a few months, and the Yahoos at Yahoo put through another bloody round of bloody so-called improvements that break everything in sight, including people's passwords. So She Who Must Be Obeyed resets her password, except now it's *permanently broken* -- no matter how many times she resets her password, Yahoo will let her log in *once* then the next time claim the password is invalid. And then a week or two ago, Yahoo added another piece of broken security theatre, and ask you to answer one of those secret questions before they'll reset your password. So now SWMBO is locked out of her account because she can't remember what she used. Mind you, Yahoo is rapidly going from Worse to Even Worse, so it was only a matter of time before she would have dumped them for good. Still, it's annoying -- it's like having your identity stolen by a hermit on some mountain top who doesn't do anything with it, except prevent you from using it. -- Steven D'Aprano http://import-that.dreamwidth.org/ From harrismh777 at gmail.com Mon Mar 3 11:52:55 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 08:52:55 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <466dcd2a-4198-47ac-9797-d4c993e03d61@googlegroups.com> Message-ID: On Monday, March 3, 2014 10:44:16 AM UTC-6, Oscar Benjamin wrote: > Is it on PyPI though? I was referring to a PyPI name so that people > could install it with "pip install pdeclib" > Oscar hi Oscar, I'm sorry, I completely missed the point of your question. No its not on PyPI, but I don't mind putting it there. Are there special instructions, or is it fairly straight-forward? marcus From xpysol at gmail.com Mon Mar 3 12:23:13 2014 From: xpysol at gmail.com (Wolfgang Maier) Date: Mon, 3 Mar 2014 09:23:13 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> Message-ID: <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> Am Montag, 3. M?rz 2014 12:34:30 UTC+1 schrieb Mark H. Harris: > hi folks, > > > > Python Decimal Library dmath.py v0.3 Released > > > > https://code.google.com/p/pythondecimallibrary/ > > > > This code provides the C accelerated decimal module with > > scientific/transcendental functions for arbitrary precision. > > I have also included pilib.py which is a PI library of historic > > algorithms for generating PI, which uses dmath.py. > > > > I wish to thank Oscar, Wolfgang, Steven, Chris (and others) > > for the help you gave me understanding decimal, particularly > > format, rounding, and context managers. > Hi Marcus and thanks for the acknowledgement. Here's one more suggestion for your code. Your current implementation of fact() for calculating factorials has nothing to offer that isn't provided by math.factorial. Since this is all about Decimal calculations, shouldn't you modify it to something like: def fact(x): """ fact(x) factorial {x} int x > 0 (x must be integral) """ return +Decimal(math.factorial(x)) to make it return a Decimal rounded to context precision? From steve+comp.lang.python at pearwood.info Mon Mar 3 12:27:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 17:27:51 GMT Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> Message-ID: <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 02:01:47 +1100, Chris Angelico wrote: > This is why it's tricky to put rules in based on type inference. The > programmer's intent isn't in the picture. Of course it is. If I assign 23 to variable x, that signals my intent to assign an int to x. By Occam's razor, it is reasonable to extrapolate that intent to mean "x is an int", rather than "an int, or a list" or "an odd int larger than 7 but smaller than 25", or "any int except 13". Type inference picks the type which involves the fewest additional assumptions. The programmer can always over-ride the type inference by explicitly stating the type. It works really well in practice, because most of the time you don't need a lot of type dynamism. Or even any. Think about the sort of type declarations you have to do in (say) Pascal, and consider how stupid the compiler must be: function add_one(x: integer):integer; begin add_one := x+1; end; Given that x is an integer, and that you add 1 (also an integer) to it, is it really necessary to tell the compiler that add_one returns an integer? What else could the output type be? This was state of the art back in 1970, but these days, if the compiler cannot *at least* infer the type of the return result of a function given the argument types, the static type system is too dumb to bother with. A good static type system can even detect infinite loops at compile time: http://perl.plover.com/yak/typing/notes.html This is not cutting edge technology: ML dates back to the 1990s, if not older. > If Python ever acquires that > kind of restriction ("here's a list that can contain only this type / > these types of object"), I would hope that it's left up to the > programmer, not the compiler, to stipulate. That's not type inference. That's ancient and annoying obligatory type declarations as used by ancient languages with primitive type systems, like Pascal and C. > That's how it is with Pike > (if you just say "array", it can take anything), and that's the only way > to be sure the programmer doesn't have to fight the language. To be sure, any form of static typing is going to restrict what you can do. This isn't intended to imply that static typing is better than dynamic typing. But if you have static typing, there's *no point* to it if the type system cannot detect bugs, and having to declare types is like having to calculate your own GOTO addresses. With a good type system like ML or Haskell have, you're not fighting the compiler, *every* type error you get is a real, actual bug in your code. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Mon Mar 3 12:41:43 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2014 17:41:43 GMT Subject: Password validation security issue References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5314bed6$0$29985$c3e8da3$5496439d@news.astraweb.com> On Mon, 03 Mar 2014 08:41:10 -0500, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> The greatest threats these days are from the network, not from someone >> physically walking into an office. (That said, though, the low-hanging >> fruit from walking into an office can be *extremely* tempting. Pulling >> off a basic password leech off sticky notes is often so easy that it >> can be done as a visitor, or at least as a pizza deliveryman.) > > Doesn't even require physical presence. With the ubiquity of various > video chat applications, as long as the sticky note is in the field of > view of the camera, you've leaked the password. With the right > lighting, I wouldn't be surprised if you could pick up the reflection of > a sticky note in somebody's eyeglasses. Let's see now... - one in a ten thousand chance that somebody will hack my account because it has a weak password; versus - one in a thousand million chance that somebody will view my strong password reflected in my glasses and be able to identify what account name for which system it goes with, and be the sort of opportunistic black-hat who will use it to break into my account. Nobody is saying that writing passwords down is secure against every and any possible attack. (When the Secret Police smash your door down at 3am, you probably won't have time to eat the passwords, even if you remembered to print them on rice paper instead of a sticky note.) The concept is that writing down strong passwords is preferable to remembering weak passwords given the typical threats most people are exposed to. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Mon Mar 3 13:37:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 05:37:27 +1100 Subject: Functional programming In-Reply-To: <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 4:27 AM, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 02:01:47 +1100, Chris Angelico wrote: > >> This is why it's tricky to put rules in based on type inference. The >> programmer's intent isn't in the picture. > > Of course it is. If I assign 23 to variable x, that signals my intent to > assign an int to x. By Occam's razor, it is reasonable to extrapolate > that intent to mean "x is an int", rather than "an int, or a list" or "an > odd int larger than 7 but smaller than 25", or "any int except 13". Type > inference picks the type which involves the fewest additional > assumptions. The programmer can always over-ride the type inference by > explicitly stating the type. Yes, and that's fine for most purposes. The problem isn't the inference, the problem is when rules are created based on that kind of guess - when the programmer's subsequent actions are governed by a guess the compiler takes. x = 23 # Compiler goes: Okay, x takes ints. x += 5 # Compiler: No prob, int += int --> int x = str(x) # Compiler: NO WAY! str(int) --> str, not allowed! It's fine and correct to infer that x is an int, x is an int, x is a str. It's *not* okay to make the third line a SyntaxError because you just put a str into an int variable. >> If Python ever acquires that >> kind of restriction ("here's a list that can contain only this type / >> these types of object"), I would hope that it's left up to the >> programmer, not the compiler, to stipulate. > > That's not type inference. That's ancient and annoying obligatory type > declarations as used by ancient languages with primitive type systems, > like Pascal and C. And that's exactly what Haskell apparently has, with homogeneous lists and no easy way to say that it can take more types. Python's handling is: A list can hold anything. Pike's handling is: An array can hold anything, unless you specify otherwise. You can specify whatever you can code: array(int(1000..2000) | string('a'..'z') | float) foo = ({1234, "abcd", 1.2}); Haskell's handling apparently is: A list/array can hold one thing and one thing only. That 'thing' can be a union, but then you need to be REALLY explicit about which side is which. It's not possible to sub-specify a type (like the "string('a'..'x')" type in Pike that will take only strings with nothing but the first 24 lower-case letters - not that I've ever needed that), but the compiler can work out everything else. The way I see it, Python's form is fully dynamic and open, Pike's is fully dynamic and the programmer's allowed to explicitly close things, and Haskell's is rigidly tight. That's not to say that tight is a bad thing (it's probably good for learning under), but personally, I'd rather have the freedom. ChrisA From tjreedy at udel.edu Mon Mar 3 13:35:37 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 03 Mar 2014 13:35:37 -0500 Subject: Origin of 'self' In-Reply-To: References: Message-ID: On 3/3/2014 1:16 AM, Westley Mart?nez wrote: > I understand that in an object method the first argument in the > object itself, called self. However, it doesn't have to be called > self, and can be called anything. So my question is why is it called > self and not this like from C++ and Java. It's kind of a silly > question, but one that I'm curious about nevertheless. Three responses and I learned or had something pointed out in each. That is a better track record than most threads. -- Terry Jan Reedy From rosuav at gmail.com Mon Mar 3 13:46:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 05:46:48 +1100 Subject: Password validation security issue In-Reply-To: <5314b1ed$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <09f43567-779e-4d01-8621-c4eb36354d99@googlegroups.com> <5313d7fe$0$29985$c3e8da3$5496439d@news.astraweb.com> <5314b1ed$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 3:46 AM, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 00:55:45 +1100, Chris Angelico wrote: > >> But it's an attack vector that MUST be considered, which is why I never >> tell the truth in any "secret question / secret answer" boxes. Why some >> sites think "mother's maiden name" is at all safe is beyond my >> comprehension. And that's not counting the ones that I can't answer >> because I can't find the "NaN" key on my keyboard, like "Surname of >> first girlfriend". *twiddle thumbs* > > If you lie to these secret questions -- and I strongly recommend that you > do -- you should record the answers somewhere so you can retrieve them > later, long after you've forgotten whether the name of your first pet was > Obama bin Bush or Tarzan the King of the Desert. Trust me on this, you > will need them. > > The missus has a Yahoo account, and being paranoid even by my standards > for keeping her web presence completely separate from her real life, she > invented fake answers to the secret questions like Your Birthday. (As you > should. It is my opinion that lying to big faceless corporations is not a > sin, but a duty. They are not on your side, and the more they know about > you the more they will abuse the knowledge.) I've followed this for a long time. If anything asks for my date of birth and appears to be just verifying that I'm at least 13 years old, I'll say Jan 1st in some year that's vaguely near my year of birth. (This is largely because the drop down combo boxes usually already say Jan 1st, and it's pointlessly tedious to aim for my exact year, much less the day within that.) My brother's new wife (married last Nov) didn't understand this about me when I was helping her port her mobile phone onto the family account. The system asks me for a date of birth, and I turn to her and say, "What date of birth did you use?" - and she looks at me funny, not understanding why I don't already know what to fill in. But for all I know, she could have set up her mobile account with a DOB of 1912/6/23 in commemoration of cryptography. But yes, on the (frequent) occasions when I lie through my teeth, I usually record my answers as separate passwords. ChrisA From tjreedy at udel.edu Mon Mar 3 13:48:39 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 03 Mar 2014 13:48:39 -0500 Subject: Reference In-Reply-To: <53144e8d$0$2149$426a74cc@news.free.fr> References: <53144e8d$0$2149$426a74cc@news.free.fr> Message-ID: On 3/3/2014 4:42 AM, ast wrote: > Consider following code: > >>>> A=7 >>>> B=7 >>>> A is B The 'is' operator has three uses, two intended and one not. In production code, 'is' tests that an object *is* a particular singular object, such as None or a sentinel instance of class object. In test code, 'is' can also be used to test details of a particular implementation, such as pre-allocation of small ints. New python programmers also use it to confuse themselves. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Mon Mar 3 14:47:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 03 Mar 2014 19:47:36 +0000 Subject: 3.4rc2 and pip on windows In-Reply-To: References: Message-ID: On 03/03/2014 00:07, Terry Reedy wrote: > On 3/2/2014 6:55 PM, Mark Lawrence wrote: >> Trying to install pyttsx, it doesn't strike me as very clever that, as >> seen below, you get "Successfully installed pyttsx" despite the syntax >> errors and you can't actually do an import. >> >> c:\Users\Mark\CrossCode>c:\Python34\Scripts\pip3.4.exe install pyttsx >> Downloading/unpacking pyttsx >> Downloading pyttsx-1.1.tar.gz >> Running setup.py >> (path:C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\pyttsx\setup.py) >> egg_info for package pyttsx >> >> Installing collected packages: pyttsx >> Running setup.py install for pyttsx >> File "C:\Python34\Lib\site-packages\pyttsx\driver.py", line 105 >> except Exception, e: >> ^ >> SyntaxError: invalid syntax >> >> [other syntax errors snipped] >> >> Successfully installed pyttsx > > A bug it seems to me. > >> Cleaning up... >> >> c:\Users\Mark\CrossCode>py -3.4 >> Python 3.4.0rc2 (v3.4.0rc2:a300712ed38c, Feb 23 2014, 10:49:04) [MSC >> v.1600 32 bit (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import pyttsx >> Traceback (most recent call last): >> File "", line 1, in >> File "C:\Python34\lib\site-packages\pyttsx\__init__.py", line 18, in >> >> from engine import Engine >> >> I've looked at pyttsx in my 3.3 site-packages and it appears that I've >> manually run 2to3. Is this something that could be done automatically >> by pip? Your thoughts please, ladies and gentlemen. > > I should hope so. > FTR I raised this as http://bugs.python.org/issue20846 and it was closed 11 minutes after I raised it. I won't say anything else as I'm extremely tired and irritable and might well regret it later. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Mon Mar 3 15:03:19 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 12:03:19 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> Message-ID: <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> On Monday, March 3, 2014 11:23:13 AM UTC-6, Wolfgang Maier wrote: > def fact(x): > """ fact(x) factorial {x} int x > 0 > > return +Decimal(math.factorial(x)) > to make it return a Decimal rounded to context precision? hi Wolfgang, I'm not sure. We're doing some things with very large factorials where (existentially) we want to know how many zeros are coming up and the end of the very large number (thousands of digits) and 2) what are the last significant figures (say twenty of them) that are just before the zero chain. What I don't want is for the Decimal module to overflow (didn't know it would do that), and we don't want the number rounded in scientific notation at some number of places. We want to actually see the digits; all of them. Python will do multiplications til the proverbial cows come home; well, as long as you don't try it recursively --- killing the recursive depth. Decimal has some limits internally which I still do not understand (and I have been looking at the doc and playing with it for hours). If I want to build a BIGNUM int in memory only the memory should limit what can be built, not some arbitrary limit inside Decimal. Does any of this make sense? and 2) can you help me understand the overflow in Decimal a little bit better. I know you're a busy guy, maybe you just know a link / Thanks much. From harrismh777 at gmail.com Mon Mar 3 15:10:22 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 12:10:22 -0800 (PST) Subject: pip and distutils2-1.0a4 Message-ID: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> hi folks, I am having a fit with pip this afternoon. I finally got pip installed on this system from a binary blob (what nightmare, talk about 1987). Anyway, pip is installed, but when I go to PyPI to pull down distutils is gives a message that no such package exists. I feel like Obeewan; "if the archive computer says your planet is not there, it simply does not exist". Can somebody tell me what is the best way to get distutils downloaded to this system? Thanks in advance. Somewhere I heard a rumor that distutils is preloaded with Py3.3.x / is this True? like, I might already have it?? thanks again marcus From donarb at nwlink.com Mon Mar 3 15:22:48 2014 From: donarb at nwlink.com (donarb) Date: Mon, 3 Mar 2014 12:22:48 -0800 (PST) Subject: modification time in Python - Django: datetime != datetime :-( In-Reply-To: References: <20140303133541.66fccbbb@lia.custard.shrl.nl> Message-ID: <04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com> On Monday, March 3, 2014 6:28:21 AM UTC-8, Jaap van Wingerde wrote: > Op schreef Chris Angelico in bericht : > > > See if ls is actually giving you ctime rather than mtime - compare the > > results if you ask for os.path.getctime. > > jaap at liakoster:~$ python > Python 2.7.3 (default, Jan 2 2013, 13:56:14) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import os, time > >>> from time import gmtime > >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html'))) > '2014-03-02T19:03:55Z' > >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getctime('/var/django/test2/art/templates/art_index.html'))) > '2014-03-02T19:03:55Z' > >>> quit() > jaap at liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html > -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 +0000 /var/django/test2/art/templates/art_index.html > jaap at liakoster:~$ > > ls is giving me the modified time. You're using the months format '%m' when you should be using minutes '%M'. From breamoreboy at yahoo.co.uk Mon Mar 3 15:53:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 03 Mar 2014 20:53:00 +0000 Subject: pip and distutils2-1.0a4 In-Reply-To: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> References: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> Message-ID: On 03/03/2014 20:10, Mark H. Harris wrote: > hi folks, > > I am having a fit with pip this afternoon. I finally > got pip installed on this system from a binary > blob (what nightmare, talk about 1987). Anyway, > pip is installed, but when I go to PyPI to pull > down distutils is gives a message that no such > package exists. I feel like Obeewan; "if the archive > computer says your planet is not there, it simply > does not exist". > Can somebody tell me what is the best way to get > distutils downloaded to this system? > Thanks in advance. > Somewhere I heard a rumor that distutils is preloaded > with Py3.3.x / is this True? like, I might already have > it?? > thanks again > marcus > distutils has been part of the standard library for years. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ben+python at benfinney.id.au Mon Mar 3 16:06:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Mar 2014 08:06:21 +1100 Subject: modification time in Python - Django: datetime != datetime :-( References: <20140303133541.66fccbbb@lia.custard.shrl.nl> Message-ID: <85txbfhu0i.fsf@benfinney.id.au> Jaap van Wingerde writes: > >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html'))) > '2014-03-02T19:03:55Z' > >>> quit() > jaap at liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html > -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 +0000 /var/django/test2/art/templates/art_index.html > jaap at liakoster:~$ > ... > > ls gives the right modification time. What is wrong? You're using ?gmtime? to display the Python datetime value, but ?ls? will display the time in the local timezone. Do you have a strange timezone set? What value does the Python datetime value show in the local timezone? How does that compare to the time shown by ?ls?? -- \ ?When cryptography is outlawed, bayl bhgynjf jvyy unir | `\ cevinpl.? ?Anonymous | _o__) | Ben Finney From rosuav at gmail.com Mon Mar 3 16:11:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 08:11:46 +1100 Subject: modification time in Python - Django: datetime != datetime :-( In-Reply-To: <04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com> References: <20140303133541.66fccbbb@lia.custard.shrl.nl> <04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 7:22 AM, donarb wrote: > You're using the months format '%m' when you should be using minutes '%M'. Heh! I didn't even notice that. When I tested it, I didn't use strftime at all, just looked at gmtime's output. ChrisA From ben+python at benfinney.id.au Mon Mar 3 16:10:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Mar 2014 08:10:21 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> Message-ID: <85ppm3httu.fsf@benfinney.id.au> Rustom Mody writes: > Short answer: Avoid using 'is'. This is bad advice in a Python forum. The ?is? operator is commonly used in Python, so please don't advise against it in an unqualified ?short answer?. > Long answer: http://www.beyondwilber.ca/healing-thinking/non-identity-korzybski.html Interesting, but mostly a distraction for the querent here. Short answer: Use ?use? any time you need to compare object identity. You usually do not need to compare object identity. -- \ ?Some people, when confronted with a problem, think ?I know, | `\ I'll use regular expressions?. Now they have two problems.? | _o__) ?Jamie Zawinski, in alt.religion.emacs | Ben Finney From harrismh777 at gmail.com Mon Mar 3 16:18:37 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 13:18:37 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> Message-ID: <3d7636ab-7544-46db-a1b1-113967dc28d6@googlegroups.com> On Monday, March 3, 2014 2:03:19 PM UTC-6, Mark H. Harris wrote: > On Monday, March 3, 2014 11:23:13 AM UTC-6, Wolfgang Maier wrote: Wolfgang, answer is not so much, in fact, not at all. But it is an interesting question for me; where I am continuing to learn the limits of Decimal, and the decimal context. I don't need rounding for integer multiplication, of course. I am interested in arbitrary limits, like emax, for instance. The doc is a little ambiguous. Is emax the max exponent, and if so, is 999999999 the limit, or is that the default context value which might be bumped up? If so, why have a limit on the emin & emax values? I'm playing with it. Shouldn't a Decimal value be able to continue to grow to the limit of memory if we wanted to be silly about it? According to the doc 'clamping' occurs if the exponent falls outside the range of emin & emax (what is overflow vs clamping ?) if the significant digits are allowed to grow and grow? Well, the doc then states that overflow occurs if we blow past the emax exponent value? What is the difference between overflow and clamping? Am I able to set emin & emax arbitrarily high or low? I have discovered just by playing with integer multiplication that those BIGNUMS don't seem to have a physical limit. Of course there isn't a decimal to keep track of, and they can just grow and grow; wouldn't want to make a Decimal from one of those, other than it is interesting to me as I'm trying to understand Decimal floating point. marcus From python.list at tim.thechases.com Mon Mar 3 16:24:38 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 3 Mar 2014 15:24:38 -0600 Subject: Reference In-Reply-To: <85ppm3httu.fsf@benfinney.id.au> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> Message-ID: <20140303152438.3454049a@bigbox.christie.dr> On 2014-03-04 08:10, Ben Finney wrote: > > Long answer: > > http://www.beyondwilber.ca/healing-thinking/non-identity-korzybski.html > > Interesting, but mostly a distraction for the querent here. > > Short answer: Use ?use? any time you need to compare object > identity. You usually do not need to compare object identity. I think there use something wrong with that sentence...unless there usen't. ;-) -tkc From harrismh777 at gmail.com Mon Mar 3 16:20:50 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 13:20:50 -0800 (PST) Subject: pip and distutils2-1.0a4 In-Reply-To: References: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> Message-ID: On Monday, March 3, 2014 2:53:00 PM UTC-6, Mark Lawrence wrote: > distutils has been part of the standard library for years. hi Mark, that's fabulous, why can't I import it? Because I'm doing something wrong of course. :) marcus From ben+python at benfinney.id.au Mon Mar 3 16:31:23 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Mar 2014 08:31:23 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303152438.3454049a@bigbox.christie.dr> Message-ID: <85lhwrhsus.fsf@benfinney.id.au> Tim Chase writes: > On 2014-03-04 08:10, Ben Finney wrote: > > Short answer: Use ?use? any time you need to compare object > > identity. You usually do not need to compare object identity. Damn it, a snappy response marred by a typo. > I think there use something wrong with that sentence...unless there > usen't. ;-) That use correct. Thanks, Tim :-) -- \ ?Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.? ?Anthony Taylor | Ben Finney From robert.kern at gmail.com Mon Mar 3 16:32:43 2014 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 03 Mar 2014 21:32:43 +0000 Subject: pip and distutils2-1.0a4 In-Reply-To: References: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> Message-ID: On 2014-03-03 21:20, Mark H. Harris wrote: > On Monday, March 3, 2014 2:53:00 PM UTC-6, Mark Lawrence wrote: > >> distutils has been part of the standard library for years. > > hi Mark, that's fabulous, why can't I import it? Because I'm doing > something wrong of course. :) Probably. If you want us to help, you need to show us what you tried, tell us what results you expected, and copy-paste the output that you got. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From breamoreboy at yahoo.co.uk Mon Mar 3 16:35:56 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 03 Mar 2014 21:35:56 +0000 Subject: Reference In-Reply-To: <85ppm3httu.fsf@benfinney.id.au> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> Message-ID: On 03/03/2014 21:10, Ben Finney wrote: > Rustom Mody writes: > >> Short answer: Avoid using 'is'. > > This is bad advice in a Python forum. > > The ?is? operator is commonly used in Python, so please don't advise > against it in an unqualified ?short answer?. > >> Long answer: http://www.beyondwilber.ca/healing-thinking/non-identity-korzybski.html > > Interesting, but mostly a distraction for the querent here. > > Short answer: Use ?use? any time you need to compare object identity. > You usually do not need to compare object identity. > That last paragraph is as clear as mud. I'd just like to know why people are so obsessed with identities, I've never thought to use them in 10+ years of writing Python. Do I use the KISS principle too often? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Mon Mar 3 16:37:22 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 13:37:22 -0800 (PST) Subject: pip and distutils2-1.0a4 In-Reply-To: References: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> Message-ID: <31feb451-7fb6-48a6-9986-bddce69c4991@googlegroups.com> On Monday, March 3, 2014 3:32:43 PM UTC-6, Robert Kern wrote: > Probably. If you want us to help, you need to show us what you tried, tell us > what results you expected, and copy-paste the output that you got. > Robert Kern hi Robert, well, I finally came up with trying to find setup(). Its a part of distutils.core. So, I tried: from distutils.core import setup from distutils import * Then I tried to run setup() --help-commands and python3 crashed. What did I do wrong? running Py3.3.4 Thanks, marcus From bc at freeuk.com Mon Mar 3 16:43:29 2014 From: bc at freeuk.com (BartC) Date: Mon, 3 Mar 2014 21:43:29 -0000 Subject: why indentation should be part of the syntax In-Reply-To: References: Message-ID: "Stefan Behnel" wrote in message news:mailman.7568.1393756930.18130.python-list at python.org... > Haven't seen any mention of it on this list yet, but since it's such an > obvious flaw in quite a number of programming languages, here's a good > article on the recent security bug in iOS, which was due to accidentally > duplicated code not actually being as indented as it looked: > > https://www.imperialviolet.org/2014/02/22/applebug.html Indentation is actually a little more fragile than block-delimited source code. (Press Delete inadvertently so that a tab disappears, and the code might still be valid, but is now wrong.) Perhaps indentation /and/ block-delimiting would be more robust. (And the link shows a bad example: the error should have been picked up anyway, but the language not only doesn't require formal indentation, but it uses optional block ({}) delimiters, another source of errors. Having an undifferentiated } to close all kinds of blocks doesn't help either. -- Bartc From roy at panix.com Mon Mar 3 16:44:31 2014 From: roy at panix.com (Roy Smith) Date: Mon, 03 Mar 2014 16:44:31 -0500 Subject: pip and distutils2-1.0a4 References: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> <31feb451-7fb6-48a6-9986-bddce69c4991@googlegroups.com> Message-ID: In article <31feb451-7fb6-48a6-9986-bddce69c4991 at googlegroups.com>, "Mark H. Harris" wrote: > On Monday, March 3, 2014 3:32:43 PM UTC-6, Robert Kern wrote: > > > Probably. If you want us to help, you need to show us what you tried, tell > > us > > what results you expected, and copy-paste the output that you got. > > > Robert Kern > > hi Robert, well, I finally came up with trying to find setup(). Its a part > of > distutils.core. So, I tried: > > from distutils.core import setup > from distutils import * > > Then I tried to run setup() --help-commands and python3 crashed. > > What did I do wrong? running Py3.3.4 > > Thanks, marcus General advice to everybody who asks questions. Please don't *describe* what you did. *Show* us what you did. Run your commands in a terminal window and then copy-and-paste everything that you typed and everything that got printed. From python.list at tim.thechases.com Mon Mar 3 16:51:12 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 3 Mar 2014 15:51:12 -0600 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> Message-ID: <20140303155112.46e34ff8@bigbox.christie.dr> On 2014-03-03 21:35, Mark Lawrence wrote: > I'd just like to know why people are so obsessed with identities, > I've never thought to use them in 10+ years of writing Python. Do > I use the KISS principle too often? There are a couple use-cases I've encountered where "is" matters: 1) the most popular: if foo is None: do_stuff() 2) sentinels (which are effectively non-None None values) SENTINEL = object() def myfuntion(value=SENTINEL): if value is SENTINEL: do_something_parameterless() else: do_something_else(value) # allow for value=None 3) when doing recursion and you want to prevent touching the same object multiple times, such as what happens when you do lst = [1,2,3] lst.append(lst) print(lst) and it needs to recognize that the final element of "lst" is one that it has already seen (as done by identity). There might be some other use cases, but #1 is a good 95% of my usage, #2 is a good 4%, and I can only think of once in my Python career when I've needed to do what is described in #3. -tkc From cs at zip.com.au Mon Mar 3 17:02:07 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 4 Mar 2014 09:02:07 +1100 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: <20140303220207.GA29739@cskk.homeip.net> On 03Mar2014 09:15, Juraj Ivan?i? wrote: > On 3.3.2014. 1:44, Cameron Simpson wrote: > >>ValueError: cannot hash writable memoryview object > > > >Have you considered subclassing memoryview and giving the subclass > >a __hash__ method? > > I have, and then, when I failed to subclass it, I considered doing > aggregation, and make it behave byte-like. But how to implement the > overridden __hash__ method? It will still require at least *some* > redundant copying. And there is the slicing thing... the whole idea > started to feel like I was performing tonsillectomy through the anal > cavity. Write a wrapper class instead and use: def __hash__(self): return id(self) Simple and fast. Unless you need slices with the same content to hash the same (eg storing them as dict keys, or in sets). And alternative would be a simple hash of the first few bytes in whatever slice you had. Cheers, -- Cameron Simpson Why is it so hard for people to simply leave people alone? But, the answer comes to me: they are idiots and in a perfect world, I would be permitted to kill them all. - Julie Rhodes From malaclypse2 at gmail.com Mon Mar 3 17:02:14 2014 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 3 Mar 2014 17:02:14 -0500 Subject: Reference In-Reply-To: <20140303155112.46e34ff8@bigbox.christie.dr> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> Message-ID: On Mon, Mar 3, 2014 at 4:51 PM, Tim Chase wrote: > There are a couple use-cases I've encountered where "is" matters: > > 1) the most popular: > > if foo is None: > do_stuff() I know this is the one that always comes up, but honestly, I feel like "is" doesn't matter here. That code would be just as correct if it was written as: if foo == None: do_stuff() The only time it would give you a different result from the "is" version is if foo was bound to an object that returned True when compared with None. And if that were the case, I'm still not convinced that you can tell from looking at those two lines of code which one is buggy, except for the fact that there has been 20 years of custom saying that comparing to None with equality is wrong. -- Jerry From greg.ewing at canterbury.ac.nz Mon Mar 3 17:06:31 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 04 Mar 2014 11:06:31 +1300 Subject: Functional programming In-Reply-To: <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Given that x is an integer, and that you add 1 (also an integer) to it, > is it really necessary to tell the compiler that add_one returns an > integer? What else could the output type be? Just because the compiler *can* infer the return type doesn't necessarily mean it *should*. When I was playing around with functional languages, I ended up adopting the practice of always declaring the types of my functions, because it helps the *human* reader. (It also helped the compiler produce comprehensible error messages in the event of a type error.) -- Greg From marko at pacujo.net Mon Mar 3 17:07:45 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 04 Mar 2014 00:07:45 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> Message-ID: <87wqgb6imm.fsf@elektro.pacujo.net> Mark Lawrence : > I'd just like to know why people are so obsessed with identities, I've > never thought to use them in 10+ years of writing Python. Do I use the > KISS principle too often? Calmly choosing the right tool for the job is not an obsession. Marko From harrismh777 at gmail.com Mon Mar 3 17:08:37 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 14:08:37 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <3d7636ab-7544-46db-a1b1-113967dc28d6@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> <3d7636ab-7544-46db-a1b1-113967dc28d6@googlegroups.com> Message-ID: <3169bb71-472c-4c26-8de2-113e8942df15@googlegroups.com> On Monday, March 3, 2014 3:18:37 PM UTC-6, Mark H. Harris wrote: Yeah, you can set Emin & Emax enormously large (or small), can set off overflow, and set clamping. I am needing a small utility (tk?) that will allow the context to be set manually by the interactive user dynamically (for a particular problem). Its like, one context doesn't fit all. Some of the pdeclib funcs will need to take into account the various signals also. The context manger is fabulous, but not for the average user; all the try block stuff is encapsulated (which makes the coding clean) but it is not obvious in any way what is happening with __init__() , __enter__() and __exit__() (although I did find a couple of good articles on the subject. The 'with localcontext(cts=None) as ctx' is genius, but not for the average user who just wants to get work done with python. So, the bottom line is we have this fabulous speedy decimal module that is nothing short of wonderful for experts, and completely out of the grasp of average users relatively new to python or with limited experience with decimal floating point arithmetic. "They would like to sing soft and sweet, like the cucumber, but they can't!" So, we need a complete wrapper around the decimal module (or better yet we need to make decimal floating point default) so that average users may take advantage of precise floating point math without having to be experts on decimal floating point arithmetic constraints in the new high speed module. :-} marcus From robert.kern at gmail.com Mon Mar 3 17:11:44 2014 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 03 Mar 2014 22:11:44 +0000 Subject: pip and distutils2-1.0a4 In-Reply-To: <31feb451-7fb6-48a6-9986-bddce69c4991@googlegroups.com> References: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> <31feb451-7fb6-48a6-9986-bddce69c4991@googlegroups.com> Message-ID: On 2014-03-03 21:37, Mark H. Harris wrote: > On Monday, March 3, 2014 3:32:43 PM UTC-6, Robert Kern wrote: > >> Probably. If you want us to help, you need to show us what you tried, tell us >> what results you expected, and copy-paste the output that you got. > >> Robert Kern > > hi Robert, well, I finally came up with trying to find setup(). Its a part of > distutils.core. So, I tried: > > from distutils.core import setup > from distutils import * > > Then I tried to run setup() --help-commands and python3 crashed. > > What did I do wrong? running Py3.3.4 You don't run `setup() --help-commands` in the Python interpreter. `--help-commands` is a command-line argument to the setup.py script that you will write. It is not Python syntax. Please read the documentation. http://docs.python.org/3/distutils/index.html -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From zachary.ware+pylist at gmail.com Mon Mar 3 16:48:03 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 3 Mar 2014 15:48:03 -0600 Subject: 3.4rc2 and pip on windows In-Reply-To: References: Message-ID: On Mon, Mar 3, 2014 at 1:47 PM, Mark Lawrence wrote: > FTR I raised this as http://bugs.python.org/issue20846 and it was closed 11 > minutes after I raised it. I won't say anything else as I'm extremely tired > and irritable and might well regret it later. Best I can tell, the issue was closed correctly. It doesn't look like a Python or Pip bug, it looks like a bug in pyttsx's packaging. Based on empirical data [1], Pip does properly take care of running 2to3, but *only when told to do so*. Pip can't decide whether it should run 2to3 when it hasn't been told either way, because it's not safe. It can't try compiling .py files and running 2to3 if it gets SyntaxErrors, because what if the SyntaxError is just a SyntaxError, and not a ThisHasntBeenPortedToPython3Error? Then 2to3 might blow up, possibly leaving things in a state that makes the underlying issue very hard to find. It can't try importing the installed package, because what if importing without specific external state in place has ugly side-effects? Pip can't safely do anything it's not told to do with the packages it installs because then responsibility for the fire in your hard drive could be laid at Pip's feet, not the evil evil package author who wrote the code that started the fire. It could be argued that Pip could compile any .py files that it installs and just start screaming if it gets any SyntaxError, but what if your package (for some weird reason) relies on .py file with bad syntax? I don't think Python itself is involved at all here, and I think Pip is doing the right thing. Everything installed successfully into the right place (since `import pyttsx` did find the package); the fact that it SyntaxError'd out is on the package author. My 0.02USD, anyway. -- Zach [1] `pip install sphinx` from a 3.4 venv From ben+python at benfinney.id.au Mon Mar 3 17:17:55 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Mar 2014 09:17:55 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> Message-ID: <85d2i3hqp8.fsf@benfinney.id.au> Jerry Hill writes: > if foo == None: > do_stuff() > > The only time it would give you a different result from the "is" > version is if foo was bound to an object that returned True when > compared with None. That's right. Python provides this singleton and then recommends you compare with ?is?, precisely to protect against pathological cases like a ?return True when compared for equality with None? data type. Using ?if foo is None? means you don't even have to spend time worrying about such cases. > And if that were the case, I'm still not convinced that you can tell > from looking at those two lines of code which one is buggy, except for > the fact that there has been 20 years of custom saying that comparing > to None with equality is wrong. Yes. And because of that widespread convention, it's much more correct to compare against None with ?is?. -- \ ?Always do right. This will gratify some people, and astonish | `\ the rest.? ?Mark Twain | _o__) | Ben Finney From cs at zip.com.au Mon Mar 3 17:19:26 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 4 Mar 2014 09:19:26 +1100 Subject: How security holes happen In-Reply-To: References: Message-ID: <20140303221926.GA57537@cskk.homeip.net> On 03Mar2014 09:17, Neal Becker wrote: > Charles R Harris Wrote in message: > > > > Imo the lesson here is never write in low level c. Use modern > languages with well designed exception handling. What, and rely on someone else's low level C? -- Cameron Simpson Hag: Two things you must know about the wise woman. First...she is a woman. Second...she is... Edmund Blackadder: Wise? Hag: Oh! You know her then? Edmund Blackadder: No, just a stab in the dark, which is what you'll be getting in a minute if you don't become more helpful. - Edmund Blackadder to Old Hag, Bells, BA2 From wolfgang.maier at biologie.uni-freiburg.de Mon Mar 3 17:15:39 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 3 Mar 2014 14:15:39 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> Message-ID: <27d19767-84ee-4ab7-87fd-784e8ac57680@googlegroups.com> On Monday, March 3, 2014 9:03:19 PM UTC+1, Mark H. Harris wrote: > On Monday, March 3, 2014 11:23:13 AM UTC-6, Wolfgang Maier wrote: > > def fact(x): > > """ fact(x) factorial {x} int x > 0 > > > > return +Decimal(math.factorial(x) > > to make it return a Decimal rounded to context precision? > > hi Wolfgang, I'm not sure. We're doing some things with very large factorials where (existentially) we want to know how many zeros are coming up and the end of the very large number (thousands of digits) and 2) what are the last significant figures (say twenty of them) that are just before the zero chain. That's ok, but I do not understand - why you shouldn't be able to use math.factorial for this purpose and - why a factorial function accepting and returning ints should be part of your dmath package. math.factorial is accurate and faster than your pure-Python function, especially for large numbers. Compare: >>> a = math.factorial(100000) and your >>> b = fact(100000) > What I don't want is for the Decimal module to overflow (didn't know it would do that), and we don't want the number rounded in scientific notation at some number of places. We want to actually see the digits; all of them. Well, that may be your use-case, but then math.factorial is for you. On the other hand, you may be interested in getting context-rounded factorials and rounding to context precision is what you'd expect from a Decimal function, so, logically, that's how it should be implemented in your package if you think it needs to have a fact function (which I'm not sure of). > Python will do multiplications til the proverbial cows come home; well, as long as you don't try it recursively --- killing the recursive depth. While that's true you pay a heavy price for abusing this feature in terms of performance because with VERY large integers there will be just too much memory shuffling activity. (I haven't looked into how math.factorial handles this internally, but it's certainly performing much better for large numbers than Python integer multiplication. Best, Wolfgang From ben+python at benfinney.id.au Mon Mar 3 17:18:57 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Mar 2014 09:18:57 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <87wqgb6imm.fsf@elektro.pacujo.net> Message-ID: <858usrhqni.fsf@benfinney.id.au> Marko Rauhamaa writes: > Mark Lawrence : > > > I'd just like to know why people are so obsessed with identities, I've > > never thought to use them in 10+ years of writing Python. Do I use the > > KISS principle too often? > > Calmly choosing the right tool for the job is not an obsession. Persistently banging your head in contradiction to the facts of Python's data model, as you have been doing, starts to look very much like obsession. -- \ ?Please to bathe inside the tub.? ?hotel room, Japan | `\ | _o__) | Ben Finney From marko at pacujo.net Mon Mar 3 17:22:55 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 04 Mar 2014 00:22:55 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> Message-ID: <87siqy7whs.fsf@elektro.pacujo.net> Jerry Hill : > except for the fact that there has been 20 years of custom saying that > comparing to None with equality is wrong. "if foo == None" is not wrong in any manner. It's just that if you are comfortable with the "is" operator and its semantics, "if foo is None" is slightly more natural. You generally use "==" if more than one object could be equal. If you know there's only one object of the kind, you convey that knowledge by the use of "is" even when functionally, it doesn't matter. Marko From rosuav at gmail.com Mon Mar 3 17:27:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 09:27:26 +1100 Subject: Reference In-Reply-To: <87siqy7whs.fsf@elektro.pacujo.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 4, 2014 at 9:22 AM, Marko Rauhamaa wrote: > You generally use "==" if more than one object could be equal. If you > know there's only one object of the kind, you convey that knowledge by > the use of "is" even when functionally, it doesn't matter. It's even simpler than that. You use "==" when you care about value, and "is" when you care about identity. This is because "==" tests value, and "is" tests identity. I do not understand why there is confusion. ChrisA From ben+python at benfinney.id.au Mon Mar 3 17:31:48 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Mar 2014 09:31:48 +1100 Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <854n3ej4mj.fsf@benfinney.id.au> Gregory Ewing writes: > Just because the compiler *can* infer the return type doesn't > necessarily mean it *should*. When I was playing around with > functional languages, I ended up adopting the practice of always > declaring the types of my functions, because it helps the *human* > reader. Sure. In a duck-typed language like Python, it is still helpful to the human reader to document the *meaning* of each parameter, beyond what is indicated by the name. We have reStructuredText and docstrings for this purpose. def frobnicate(flang, splets, queeble=False): """ Righteously frobnicate the flang. :param flang: A file-like object, opened for reading. :param splets: A sequence of unprocessed Splet instances. :param queeble: If ``True``, re-vitrify the flang during frobnication. :return: A new list of processed Splet instances. The flang is frobnicated according to the Weebly-Ruckford algorithm. """ for line in flang: ? > (It also helped the compiler produce comprehensible error messages in > the event of a type error.) Docstrings in the above reStructuredText field-list style will be processed by Epydoc . Other styles of specifying parameters in an mechanically-extractable form are also used, by Sphinx for example. The point is, we have docstrings, and conventions in docstrings for specifying parameters for the human reader *and* for automated tools to read. -- \ ?? Nature ? is seen to do all things Herself and through | `\ herself of own accord, rid of all gods.? ?Titus Lucretius | _o__) Carus, c. 40 BCE | Ben Finney From rosuav at gmail.com Mon Mar 3 17:25:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 09:25:49 +1100 Subject: How security holes happen In-Reply-To: <20140303221926.GA57537@cskk.homeip.net> References: <20140303221926.GA57537@cskk.homeip.net> Message-ID: On Tue, Mar 4, 2014 at 9:19 AM, Cameron Simpson wrote: > On 03Mar2014 09:17, Neal Becker wrote: >> Charles R Harris Wrote in message: >> > >> >> Imo the lesson here is never write in low level c. Use modern >> languages with well designed exception handling. > > What, and rely on someone else's low level C? Someone needs to port Python to LISP. And then write a LISP interpreter in JavaScript. And an ECMAScript engine in Pike. And a Pike interpreter in Java. And a Java run-time written in ActionScript. It's turtles all the way down... ChrisA From ben+python at benfinney.id.au Mon Mar 3 17:33:36 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Mar 2014 09:33:36 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> Message-ID: <85zjl6hpz3.fsf@benfinney.id.au> Marko Rauhamaa writes: > Jerry Hill : > > > except for the fact that there has been 20 years of custom saying that > > comparing to None with equality is wrong. > > "if foo == None" is not wrong in any manner. Marko, please don't keep asserting falsehoods. It's already been pointed out in this forum many times, essentially since the forum existed, why what you say here is false. -- \ ?The fact that I have no remedy for all the sorrows of the | `\ world is no reason for my accepting yours. It simply supports | _o__) the strong probability that yours is a fake.? ?Henry L. Mencken | Ben Finney From rosuav at gmail.com Mon Mar 3 17:42:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 09:42:03 +1100 Subject: Functional programming In-Reply-To: <854n3ej4mj.fsf@benfinney.id.au> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <854n3ej4mj.fsf@benfinney.id.au> Message-ID: On Tue, Mar 4, 2014 at 9:31 AM, Ben Finney wrote: > def frobnicate(flang, splets, queeble=False): > """ Righteously frobnicate the flang. > > :param flang: A file-like object, opened for reading. I had to read that a few times before I was sure that you actually meant "file" there, you used a real word with its real meaning! ChrisA From harrismh777 at gmail.com Mon Mar 3 17:42:38 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 14:42:38 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <27d19767-84ee-4ab7-87fd-784e8ac57680@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> <27d19767-84ee-4ab7-87fd-784e8ac57680@googlegroups.com> Message-ID: <65862588-a0a8-4c3e-a3b2-8848c8170145@googlegroups.com> On Monday, March 3, 2014 4:15:39 PM UTC-6, Wolfgang Maier wrote: > Well, that may be your use-case, but then math.factorial is for you. > On the other hand, you may be interested in getting > context-rounded factorials and rounding to context > precision is what you'd expect from a Decimal function, > so, logically, that's how it should be implemented in your > package if you think it needs to have a fact function (which I'm not sure of). hi Wolfgang, you are absolutely right. I see what you're getting at now. I've stuffed something into the library that really does not belong in that library; it was just convenient for me. I get that. marcus From wolfgang.maier at biologie.uni-freiburg.de Mon Mar 3 17:44:27 2014 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 3 Mar 2014 14:44:27 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <3d7636ab-7544-46db-a1b1-113967dc28d6@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> <3d7636ab-7544-46db-a1b1-113967dc28d6@googlegroups.com> Message-ID: <6b871278-47e5-42de-afdf-f42b46a8a459@googlegroups.com> On Monday, March 3, 2014 10:18:37 PM UTC+1, Mark H. Harris wrote: > On Monday, March 3, 2014 2:03:19 PM UTC-6, Mark H. Harris wrote: > > Wolfgang, answer is not so much, in fact, not at all. > But it is an interesting question for me; where I am > continuing to learn the limits of Decimal, and the > decimal context. I don't need rounding for integer > multiplication, of course. > You don't want it and you don't get it for integer multiplication, but you may get it with Decimal multiplication and not high-enough precision: >>> with localcontext() as ctx: ctx.prec=2 Decimal(11)*Decimal(11) Decimal('1.2E+2') This is the very nature of rounding to context precision and functions dealing with Decimals shouldn't behave differently in my opinion. If you don't want rounding either use sufficiently high precision or use integers. > > I am interested in arbitrary limits, like emax, for instance. > The doc is a little ambiguous. Is emax the max exponent, > and if so, is 999999999 the limit, or is that the default > context value which might be bumped up? > I don't find much ambiguity in the docs here: " class decimal.Context(prec=None, rounding=None, Emin=None, Emax=None, capitals=None, clamp=None, flags=None, traps=None) Creates a new context. If a field is not specified or is None, the default values are copied from the DefaultContext. If the flags field is not specified or is None, all flags are cleared. .. The Emin and Emax fields are integers specifying the outer limits allowable for exponents. Emin must be in the range [MIN_EMIN, 0], Emax in the range [0, MAX_EMAX]." So, Emax is the maximal exponent allowed in a specific context and the constant MAX_EMAX is the maximum Emax that you can set in any context. Also (on my system): >>> from decimal import getcontext >>> getcontext() Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZero, Overflow]) shows that my default context Emax is way smaller than MAX_EMAX. > I have discovered just by playing with integer multiplication > that those BIGNUMS don't seem to have a physical limit. Of > course there isn't a decimal to keep track of, and they can > just grow and grow; wouldn't want to make a Decimal from > one of those, other than it is interesting to me as I'm trying > to understand Decimal floating point. > decimal can handle BIGNUMS fairly well, you just need to increase context Emax. Have you ever tried to calculate stuff with ints as big as MAX_EMAX (10**999999999999999999) or even close to it and still had a responsive system ?? My point in suggesting the fix for your epx function was that the unnecessary juggling of extremely large values (Decimal or int) is a killer for performance. > marcus From breamoreboy at yahoo.co.uk Mon Mar 3 17:50:24 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 03 Mar 2014 22:50:24 +0000 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> Message-ID: On 03/03/2014 22:25, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 9:19 AM, Cameron Simpson wrote: >> On 03Mar2014 09:17, Neal Becker wrote: >>> Charles R Harris Wrote in message: >>>> >>> >>> Imo the lesson here is never write in low level c. Use modern >>> languages with well designed exception handling. >> >> What, and rely on someone else's low level C? > > Someone needs to port Python to LISP. > > And then write a LISP interpreter in JavaScript. > > And an ECMAScript engine in Pike. > > And a Pike interpreter in Java. > > And a Java run-time written in ActionScript. > > It's turtles all the way down... > > ChrisA > Or write every language in Applescript which has 42 not very obvious ways of doing each and everything. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ckaynor at zindagigames.com Mon Mar 3 17:55:32 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 3 Mar 2014 14:55:32 -0800 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> Message-ID: On Mon, Mar 3, 2014 at 2:25 PM, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 9:19 AM, Cameron Simpson wrote: > > On 03Mar2014 09:17, Neal Becker wrote: > >> Charles R Harris Wrote in message: > >> > > >> > >> Imo the lesson here is never write in low level c. Use modern > >> languages with well designed exception handling. > > > > What, and rely on someone else's low level C? > > Someone needs to port Python to LISP. > > And then write a LISP interpreter in JavaScript. > > And an ECMAScript engine in Pike. > > And a Pike interpreter in Java. > > And a Java run-time written in ActionScript. > > It's turtles all the way down... > You can go much simpler than that. Merely port Python to LISP, then write a LISP interpreter in Python. Done. Now, bootstrapping those interpreters might pose a bit of a challenge... > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Mar 3 18:03:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 10:03:53 +1100 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> Message-ID: On Tue, Mar 4, 2014 at 9:55 AM, Chris Kaynor wrote: > You can go much simpler than that. Merely port Python to LISP, then write a > LISP interpreter in Python. Done. Actually, here's an easier way. Just write an 80x86 assembly language interpreter in Python, then port CPython to Python. ChrisA From roy at panix.com Mon Mar 3 18:02:04 2014 From: roy at panix.com (Roy Smith) Date: Mon, 03 Mar 2014 18:02:04 -0500 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> Message-ID: In article , Ben Finney wrote: > That's right. Python provides this singleton and then recommends you > compare with ???is???, precisely to protect against pathological cases like > a ???return True when compared for equality with None??? data type. Going off on a tangent, I've often wished Python provided more kinds of None-ness. I'll often write: def f(arg=None): whatever where it would be nice to differentiate between "this was called with no arguments" and "this was called with an argument of None". Sure, I can work around that with things like **kwargs, and then test "args" in kwargs vs. kwargs["args"] is None but that always feels clumsy. It also makes the function declaration less sell-describing. "Hmmm, let's see what help() says. Oh, gee, I can pass it some stuff". From rosuav at gmail.com Mon Mar 3 18:09:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 10:09:28 +1100 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> Message-ID: On Tue, Mar 4, 2014 at 10:02 AM, Roy Smith wrote: > In article , > Ben Finney wrote: > >> That's right. Python provides this singleton and then recommends you >> compare with ?is?, precisely to protect against pathological cases like >> a ?return True when compared for equality with None? data type. > > Going off on a tangent, I've often wished Python provided more kinds of > None-ness. I'll often write: > > def f(arg=None): > whatever > > where it would be nice to differentiate between "this was called with no > arguments" and "this was called with an argument of None". That's why you have your own sentinel. _NONE_PASSED=object() def f(arg=_NONE_PASSED): if f is not _NONE_PASSED: pass ChrisA From roy at panix.com Mon Mar 3 18:05:08 2014 From: roy at panix.com (Roy Smith) Date: Mon, 03 Mar 2014 18:05:08 -0500 Subject: How security holes happen References: Message-ID: In article , Cameron Simpson wrote: > On 03Mar2014 09:17, Neal Becker wrote: > > Charles R Harris Wrote in message: > > > > > > > Imo the lesson here is never write in low level c. Use modern > > languages with well designed exception handling. > > What, and rely on someone else's low level C? Don't laugh. http://c2.com/cgi/wiki?TheKenThompsonHack From rosuav at gmail.com Mon Mar 3 18:36:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 10:36:03 +1100 Subject: How security holes happen In-Reply-To: References: Message-ID: On Tue, Mar 4, 2014 at 10:05 AM, Roy Smith wrote: > In article , > Cameron Simpson wrote: > >> On 03Mar2014 09:17, Neal Becker wrote: >> > Charles R Harris Wrote in message: >> > > >> > >> > Imo the lesson here is never write in low level c. Use modern >> > languages with well designed exception handling. >> >> What, and rely on someone else's low level C? > > Don't laugh. http://c2.com/cgi/wiki?TheKenThompsonHack I don't think malicious interference with C compilers is the issue here, so much as the constant discovery of flaws in honestly-written C code. Currently, I'm porting a MUD client from C++ to Pike. On average, a hunk of code shrinks by about 50% during the translation, mainly because I can let memory management happen elsewhere. (Sometimes the difference is even more dramatic. I wrote my own binary tree in the C++ client, because the compiler I was targeting at the time didn't provide a suitable mapping type; now, I just call on the language's facilities, and it's more efficient and takes no code whatsoever. That's basically one entire module eliminated.) Along the way, I'm noticing myriad little issues around the place, where too much data would result in something being truncated (I was careful in most places to ensure that it couldn't blow the stack, although I certainly wouldn't bet money that I was perfect on that score), and the truncation could have unexpected results. Malformed data coming in over a TCP socket would eventually consume all the buffer space and then make the client think the other end had closed its connection. That one I knew about and didn't care, but there were others that were weird and esoteric and would *most likely* never happen. Writing low level code opens you up to a huge collection of weird behaviours that might, at best, become bug reports that you spend hours trying to solve. At worst, they become exploits. Yes, high level languages have their own attack vectors, but I'd much rather have the entire python-dev team working to solve my problems than me alone :) ChrisA From ben+python at benfinney.id.au Mon Mar 3 18:52:53 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 04 Mar 2014 10:52:53 +1100 Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <854n3ej4mj.fsf@benfinney.id.au> Message-ID: <85ppm2hmay.fsf@benfinney.id.au> Chris Angelico writes: > On Tue, Mar 4, 2014 at 9:31 AM, Ben Finney wrote: > > def frobnicate(flang, splets, queeble=False): > > """ Righteously frobnicate the flang. > > > > :param flang: A file-like object, opened for reading. > > I had to read that a few times before I was sure that you actually > meant "file" there, you used a real word with its real meaning! Sometimes I say what I mean, to test whether people are alert. -- \ ?Faith, n. Belief without evidence in what is told by one who | `\ speaks without knowledge, of things without parallel.? ?Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney From dihedral88888 at gmail.com Mon Mar 3 19:35:34 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Mon, 3 Mar 2014 16:35:34 -0800 (PST) Subject: Functional programming In-Reply-To: <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> Message-ID: <862fca31-9154-4fb9-b02e-869c9e575efe@googlegroups.com> On Monday, March 3, 2014 10:08:11 PM UTC+8, Rustom Mody wrote: > On Monday, March 3, 2014 7:30:17 PM UTC+5:30, Chris Angelico wrote: > > > On Tue, Mar 4, 2014 at 12:48 AM, Rustom Mody wrote: > > > > ? [1,2] + [[3,4],[5]] > > > > ERROR: Type error in application > > > > *** expression : [1,2] + [[3,4],[5]] > > > > *** term : [1,2] > > > > *** type : [Int] > > > > *** does not match : [[Int]] > > > > IOW [1,2,[3,4],[5]] > > > > is a type-wise ill-formed expression just as in python > > > > [[1,2]) > > > > is syntax-wise ill-formed > > > > Is it worth having such a restriction? > > > > Thats a different argument... > > > > > How do you know that [1,2] is a list that must contain nothing but > > > integers? By extension, it's also a list that must contain positive > > > integers less than three, so adding [5] violates that. And [] is a > > > list that must contain nothing, ergo it can't be added to, although > > > (since it contains nothing) it can be added to anything. > > > > If 'integer-less-than-3' were a type then yes there would be this > > problem. More generally, if types could overlap then automatic > > type-inference is impossible > > > > Whether all thats good is as I earlier said a different argument > > > > The OP asked about FP and so its appropriate to mention how python's > > and standard FPL's choices differ OK, lets talk about the real meats of high-level dynamical typed languages. Test the claim that the old OOP programs and modules can use the new objects and programs written or obtained later in the run time. From harrismh777 at gmail.com Mon Mar 3 20:22:33 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 17:22:33 -0800 (PST) Subject: pip and distutils2-1.0a4 In-Reply-To: References: <248fe774-aed4-4a59-afac-e746e2110dd7@googlegroups.com> <31feb451-7fb6-48a6-9986-bddce69c4991@googlegroups.com> Message-ID: <1279b5f0-aff5-429d-a8d0-a9d93cc48242@googlegroups.com> On Monday, March 3, 2014 4:11:44 PM UTC-6, Robert Kern wrote: > http://docs.python.org/3/distutils/index.html > Robert Kern hi Robert, I'm not whining --really-- but there is so dang much doc out there on how to upload a package to PyPI with every tool under the sun and all of them fancier than they need to be. So, that you! That doc file led me to another doc file that showed me how to build the setup.py file line by line. The real trick is building the src tree (and there are more than several ways to do that) and then matching the setup.py script to the src tree: then, python3 setup.py register python3 setup.py sdist upload python3 setup.py upload whew... I never worked so hard to get one silly tarball on a repository in my life ever... very rewarding; but, and I genuinely mean this, thank you for pointing me in the correct direction, sir. marcus From abhishek1899 at gmail.com Mon Mar 3 20:33:15 2014 From: abhishek1899 at gmail.com (Rolando) Date: Mon, 3 Mar 2014 17:33:15 -0800 (PST) Subject: Idle thread (Polling) python GUI and saving program state Message-ID: I have a GUI with a bunch of cells which is my "View" in the MVC design. The user enters some information in the view and I pass this on to the model so that using the information entered by the user it(model) can do some processing. I have coded up my model as a state machine. Wherein, once a function is complete it switches to the next state and so on. I want to know how do I save the program state between restarts. Basically, I'm trying to handle a scenario wherein if someone closes the program. The next time someone starts it up, it should start from where it left off (both the view and model) Also, I want to setup a poll method where once in a while I can poll each cell to know the state it is in. How do I do this? I don't want my GUI to hang when I'm doing anything. It will be great if someone could help. Thanks! From harrismh777 at gmail.com Mon Mar 3 20:42:16 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 17:42:16 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <6b871278-47e5-42de-afdf-f42b46a8a459@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> <3d7636ab-7544-46db-a1b1-113967dc28d6@googlegroups.com> <6b871278-47e5-42de-afdf-f42b46a8a459@googlegroups.com> Message-ID: <3b2f4dbc-fa84-4a41-9632-946e99def48e@googlegroups.com> On Monday, March 3, 2014 4:44:27 PM UTC-6, Wolfgang Maier wrote: > decimal can handle BIGNUMS fairly well, you just need to increase context Emax. Have you ever tried to calculate stuff with ints as big as MAX_EMAX (10**999999999999999999) or even close to it and still had a responsive system ?? hi Wolfgang, yes correct you are... I've been playing with it; very interesting. I think I've almost got my arms around these things. If I don't get it right in my head, then my library is gonna suck. Still looking, but I think I may have one or two more funcs that have a similar problem to epx(). I've decided to go through them one by one while I'm testing and make sure that they are as efficient as I can make them. Thanks again for your inputs. marcus From harrismh777 at gmail.com Mon Mar 3 20:46:38 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 3 Mar 2014 17:46:38 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> Message-ID: <4c40a0a4-e8ee-422a-a227-4a1a0597bb81@googlegroups.com> On Monday, March 3, 2014 5:34:30 AM UTC-6, Mark H. Harris wrote: > https://code.google.com/p/pythondecimallibrary/ I released my pdeclib module this afternoon on PyPI here: https://pypi.python.org/pypi/pdeclib/0.3 The tarball.gz may be downloaded and installed with: pip install pdeclib Contains: pdeclib.py | pilib.py Thanks again to all who helped me with this beta package. Cheers, marcus From python at mrabarnett.plus.com Mon Mar 3 21:06:22 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Mar 2014 02:06:22 +0000 Subject: Idle thread (Polling) python GUI and saving program state In-Reply-To: References: Message-ID: <5315351E.9040308@mrabarnett.plus.com> On 2014-03-04 01:33, Rolando wrote: > I have a GUI with a bunch of cells which is my "View" in the MVC > design. The user enters some information in the view and I pass this > on to the model so that using the information entered by the user > it(model) can do some processing. > > I have coded up my model as a state machine. Wherein, once a function > is complete it switches to the next state and so on. > > I want to know how do I save the program state between restarts. > Basically, I'm trying to handle a scenario wherein if someone closes > the program. The next time someone starts it up, it should start from > where it left off (both the view and model) > When the user closes the window (you don't say what you're using for the GUI, but there should be a way of detecting when window closes), save the necessary info to a file using, say, the 'json' module. You can then reload the info from the file when the program is restarted. > Also, I want to setup a poll method where once in a while I can poll > each cell to know the state it is in. How do I do this? I don't want > my GUI to hang when I'm doing anything. It will be great if someone > could help. Thanks! > Can the model run continuously? If so, you should run it in its own (background) thread and the GUI in the main thread and communicate with the model's thread via, say, a queue (for that use the 'queue' module). From rosuav at gmail.com Mon Mar 3 21:13:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 13:13:24 +1100 Subject: Origin of 'self' In-Reply-To: <7edah9989mdjb9mrnrsh5067np0ihv1jml@4ax.com> References: <7edah9989mdjb9mrnrsh5067np0ihv1jml@4ax.com> Message-ID: On Tue, Mar 4, 2014 at 1:09 PM, Dennis Lee Bieber wrote: > On Sun, 2 Mar 2014 22:16:31 -0800 (PST), Westley Mart?nez > declaimed the following: > >>I understand that in an object method the first argument in the object itself, called self. However, it doesn't have to be called self, and can be called anything. So my question is why is it called self and not this like from C++ and Java. It's kind of a silly question, but one that I'm curious about nevertheless. >> > > It didn't want to be egotistical (as I recall, M$ VB uses "me") ALL language designers are egotistical. Goes with the territory. (Larry Wall said that, I believe, regarding Perl.) ChrisA From roy at panix.com Mon Mar 3 21:14:44 2014 From: roy at panix.com (Roy Smith) Date: Mon, 03 Mar 2014 21:14:44 -0500 Subject: Origin of 'self' References: Message-ID: In article , Dennis Lee Bieber wrote: > On Sun, 2 Mar 2014 22:16:31 -0800 (PST), Westley Mart?nez > declaimed the following: > > >I understand that in an object method the first argument in the object > >itself, called self. However, it doesn't have to be called self, and can be > >called anything. So my question is why is it called self and not this like > >from C++ and Java. It's kind of a silly question, but one that I'm curious > >about nevertheless. > > > > It didn't want to be egotistical (as I recall, M$ VB uses "me") And Freud uses "id", but that was taken already in Python :-) From zachary.ware+pylist at gmail.com Mon Mar 3 21:24:27 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 3 Mar 2014 20:24:27 -0600 Subject: 3.4rc2 and pip on windows In-Reply-To: References: Message-ID: On Mon, Mar 3, 2014 at 3:48 PM, Zachary Ware wrote: > It could be argued that Pip could compile any .py files that it > installs and just start screaming if it gets any SyntaxError, but what > if your package (for some weird reason) relies on .py file with bad > syntax? Somehow, I missed that this is exactly what seems to be happening, sans screaming. So yes, Pip is doing this slightly wrong, but it's still on the package author to fix it properly. But it's still not a Python issue, since Pip is still a separate project. -- Zach On Mon, Mar 3, 2014 at 3:48 PM, Zachary Ware wrote: > On Mon, Mar 3, 2014 at 1:47 PM, Mark Lawrence wrote: >> FTR I raised this as http://bugs.python.org/issue20846 and it was closed 11 >> minutes after I raised it. I won't say anything else as I'm extremely tired >> and irritable and might well regret it later. > > Best I can tell, the issue was closed correctly. It doesn't look like > a Python or Pip bug, it looks like a bug in pyttsx's packaging. Based > on empirical data [1], Pip does properly take care of running 2to3, > but *only when told to do so*. Pip can't decide whether it should run > 2to3 when it hasn't been told either way, because it's not safe. It > can't try compiling .py files and running 2to3 if it gets > SyntaxErrors, because what if the SyntaxError is just a SyntaxError, > and not a ThisHasntBeenPortedToPython3Error? Then 2to3 might blow up, > possibly leaving things in a state that makes the underlying issue > very hard to find. It can't try importing the installed package, > because what if importing without specific external state in place has > ugly side-effects? Pip can't safely do anything it's not told to do > with the packages it installs because then responsibility for the fire > in your hard drive could be laid at Pip's feet, not the evil evil > package author who wrote the code that started the fire. > > It could be argued that Pip could compile any .py files that it > installs and just start screaming if it gets any SyntaxError, but what > if your package (for some weird reason) relies on .py file with bad > syntax? > > I don't think Python itself is involved at all here, and I think Pip > is doing the right thing. Everything installed successfully into the > right place (since `import pyttsx` did find the package); the fact > that it SyntaxError'd out is on the package author. > > My 0.02USD, anyway. > > -- > Zach > > [1] `pip install sphinx` from a 3.4 venv -- Zach From abhishek1899 at gmail.com Mon Mar 3 21:41:54 2014 From: abhishek1899 at gmail.com (Rolando) Date: Mon, 3 Mar 2014 18:41:54 -0800 (PST) Subject: Idle thread (Polling) python GUI and saving program state In-Reply-To: References: Message-ID: <4034b33f-0cb6-46fa-931c-450834c98d6e@googlegroups.com> On Monday, March 3, 2014 6:06:22 PM UTC-8, MRAB wrote: > On 2014-03-04 01:33, Rolando wrote: > > > I have a GUI with a bunch of cells which is my "View" in the MVC > > > design. The user enters some information in the view and I pass this > > > on to the model so that using the information entered by the user > > > it(model) can do some processing. > > > > > > I have coded up my model as a state machine. Wherein, once a function > > > is complete it switches to the next state and so on. > > > > > > I want to know how do I save the program state between restarts. > > > Basically, I'm trying to handle a scenario wherein if someone closes > > > the program. The next time someone starts it up, it should start from > > > where it left off (both the view and model) > > > > > When the user closes the window (you don't say what you're using for > > the GUI, but there should be a way of detecting when window closes), > > save the necessary info to a file using, say, the 'json' module. You > > can then reload the info from the file when the program is restarted. > > > > > Also, I want to setup a poll method where once in a while I can poll > > > each cell to know the state it is in. How do I do this? I don't want > > > my GUI to hang when I'm doing anything. It will be great if someone > > > could help. Thanks! > > > > > Can the model run continuously? If so, you should run it in its own > > (background) thread and the GUI in the main thread and communicate > > with the model's thread via, say, a queue (for that use the 'queue' > > module). I'm using wxPython for my GUI. I have tried running the model thread in the background. But how will I save the state if the whole model is running on a thread? When the program is restarted I want the program to continue from the same state where it left off for each cell. I was thinking of having an idle thread that calls a poll method which polls all the cells and checks what each one is doing. But, I don't know how to do that. I'm confused. From albert at spenarnc.xs4all.nl Mon Mar 3 21:45:58 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 04 Mar 2014 02:45:58 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> Message-ID: <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> In article , Chris Angelico wrote: >On Wed, Feb 12, 2014 at 7:17 PM, Ben Finney wrote: >> Chris Angelico writes: >> >>> I have yet to find any computer that works with the set of real >>> numbers in any way. Never mind optimization, they simply cannot work >>> with real numbers. >> >> Not *any* computer? Not in *any* way? The Python built-in ???float??? type >> ???works with the set of real numbers???, in a way. > >No, the Python built-in float type works with a subset of real numbers: To be more precise: a subset of the rational numbers, those with a denominator that is a power of two. > >>>> float("pi") >Traceback (most recent call last): > File "", line 1, in > float("pi") >ValueError: could not convert string to float: 'pi' >>>> float("??") >Traceback (most recent call last): > File "", line 1, in > float("??") >ValueError: could not convert string to float: '??' > >Same goes for fractions.Fraction and [c]decimal.Decimal. All of them >are restricted to some subset of rational numbers, not all reals. > >> The ABC >> defines behaviours for types implementing the set of real numbers. >> >> What specific behaviour would, for you, qualify as ???works with the set >> of real numbers in any way???? > >Being able to represent surds, pi, e, etc, for a start. It'd >theoretically be possible with an algebraic notation (eg by carrying >through some representation like "2*pi" rather than 6.28....), but >otherwise, irrationals can't be represented with finite storage and a >digit-based system. An interesting possibility is working with rules that generate the continued fraction sequence of a real number. Say yield() gives the next coefficient (or the next hex digit). It was generally believed that summing two numbers in their cf representation was totally impractical because it required conversion to a rational number. OTOH if we consider a cf as an ongoing progress, the situation is much better. Summing would be a process that yields coefficients of the sum, and you could just stop when you've enough precision. Fascinating stuff. It is described in a self contained, type writer style document gosper.txt that is found on the web in several places e.g. http://home.strw.leidenuniv.nl/~gurkan/gosper.pdf I have a gosper.txt, don't know from where. It really is a cookbook, one could built a python implementation from there, without being overly math savvy. I'd love to hear if some one does it. ( in principle a coefficient of a cf can overflow machine precision, that has never been observed in the wild. A considerable percentage of the coefficients for a random number are ones or otherwise small. The golden ratio has all ones.) > >ChrisA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From rosuav at gmail.com Mon Mar 3 22:02:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 14:02:01 +1100 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> Message-ID: On Tue, Mar 4, 2014 at 1:45 PM, Albert van der Horst wrote: >>No, the Python built-in float type works with a subset of real numbers: > > To be more precise: a subset of the rational numbers, those with a denominator > that is a power of two. And no more than N bits (53 in a 64-bit float) in the numerator, and the denominator between the limits of the exponent. (Unless it's subnormal. That adds another set of small numbers.) It's a pretty tight set of restrictions, and yet good enough for so many purposes. But it's a far cry from "all real numbers". Even allowing for continued fractions adds only some more; I don't think you can represent surds that way. ChrisA From rustompmody at gmail.com Mon Mar 3 22:13:58 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 19:13:58 -0800 (PST) Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> Message-ID: <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> On Tuesday, March 4, 2014 8:32:01 AM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 1:45 PM, Albert van der Horst wrote: > >>No, the Python built-in float type works with a subset of real numbers: > > To be more precise: a subset of the rational numbers, those with a denominator > > that is a power of two. > And no more than N bits (53 in a 64-bit float) in the numerator, and > the denominator between the limits of the exponent. (Unless it's > subnormal. That adds another set of small numbers.) It's a pretty > tight set of restrictions, and yet good enough for so many purposes. > But it's a far cry from "all real numbers". Even allowing for > continued fractions adds only some more; I don't think you can > represent surds that way. See http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfINTRO.html#sqrts From nad at acm.org Mon Mar 3 22:38:24 2014 From: nad at acm.org (Ned Deily) Date: Mon, 03 Mar 2014 19:38:24 -0800 Subject: 3.4rc2 and pip on windows References: Message-ID: In article , Zachary Ware wrote: > On Mon, Mar 3, 2014 at 3:48 PM, Zachary Ware > wrote: > > It could be argued that Pip could compile any .py files that it > > installs and just start screaming if it gets any SyntaxError, but what > > if your package (for some weird reason) relies on .py file with bad > > syntax? > Somehow, I missed that this is exactly what seems to be happening, > sans screaming. So yes, Pip is doing this slightly wrong, but it's > still on the package author to fix it properly. But it's still not a > Python issue, since Pip is still a separate project. FTR, pip is not doing anything wrong: see the updates to Issue20846 and the discussion on python-dev. The "syntax error" messages displayed are warnings which originate from Distutils (which is called by pip and other installers) when it tries to byte-compiles the installed files, which actually do install successfully. Byte-compiling is merely an optimization and installs do not (and should not) depend on them. But just because a package installs without error doesn't mean it executes without error. The real problem is that the package that was trying to be installed with Python 3 is not compatible with Python 3 but there is currently no way for pip or any other installer to know that, other than perhaps by running a package's test suite if one is provided. The package author could include metadata hints ("Requires-Python") about which versions of Python are supported by the package but those optional hints aren't used today by any installer. Having more usable and reliable metadata is a focus of packaging PEPs in various stages of design and development. The goal is that eventually installers would be able to detect Python version mismatches. Today it is up to the person installing a package to determine that. -- Ned Deily, nad at acm.org From rosuav at gmail.com Mon Mar 3 22:46:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 14:46:25 +1100 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 2:13 PM, Rustom Mody wrote: >> But it's a far cry from "all real numbers". Even allowing for >> continued fractions adds only some more; I don't think you can >> represent surds that way. > > See > > http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfINTRO.html#sqrts That's neat, didn't know that. Is there an efficient way to figure out, for any integer N, what its sqrt's CF sequence is? And what about the square roots of non-integers - can you represent ?? that way? I suspect, though I can't prove, that there will be numbers that can't be represented even with an infinite series - or at least numbers whose series can't be easily calculated. ChrisA From steve at pearwood.info Mon Mar 3 22:45:55 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 03:45:55 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> Message-ID: <53154c73$0$2923$c3e8da3$76491128@news.astraweb.com> On Mon, 03 Mar 2014 13:48:39 -0500, Terry Reedy wrote: > On 3/3/2014 4:42 AM, ast wrote: > >> Consider following code: >> >>>>> A=7 >>>>> B=7 >>>>> A is B > > The 'is' operator has three uses, two intended and one not. In > production code, 'is' tests that an object *is* a particular singular > object, such as None or a sentinel instance of class object. In test > code, 'is' can also be used to test details of a particular > implementation, such as pre-allocation of small ints. New python > programmers also use it to confuse themselves. +1 QOTW -- Steven From steve at pearwood.info Mon Mar 3 22:59:03 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 03:59:03 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> Message-ID: <53154f85$0$2923$c3e8da3$76491128@news.astraweb.com> On Mon, 03 Mar 2014 17:02:14 -0500, Jerry Hill wrote: > On Mon, Mar 3, 2014 at 4:51 PM, Tim Chase > wrote: >> There are a couple use-cases I've encountered where "is" matters: >> >> 1) the most popular: >> >> if foo is None: >> do_stuff() > > I know this is the one that always comes up, but honestly, I feel like > "is" doesn't matter here. That code would be just as correct if it was > written as: > > if foo == None: > do_stuff() > > The only time it would give you a different result from the "is" version > is if foo was bound to an object that returned True when compared with > None. And if that were the case, I'm still not convinced that you can > tell from looking at those two lines of code which one is buggy, It's all about the intention of the code. Are you trying to test whether an object *is* the None singleton, and no other value? Then use "is", don't use == because it is subject to false positives (returning True for some objects that aren't actually None). Or do you want to test whether an object merely happens to have the same value as None? Then use == and be glad. Personally, I have never written code that looks like this: def spam(a, b=None): """Spamify a with optional b. If b is None ***OR SOMETHING THAT COMPARES EQUAL TO NONE*** or not supplied, use extra-yummy spammification mode. """ if b == None: ... But if I ever did want to do that, I can. Since None is a singleton null-object, something with no state and no behaviour, we normally treat it as a sentinel, in which case an identity test is usual. I can't really think of any good reason to treat it as a value where I would want to use an equality test. > except > for the fact that there has been 20 years of custom saying that > comparing to None with equality is wrong. It's not *necessarily* wrong, merely wrong the 99.9998% of the time that you want to treat None as a sentinel. -- Steven From ikorot01 at gmail.com Mon Mar 3 23:03:46 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 3 Mar 2014 20:03:46 -0800 Subject: How do I process this? Message-ID: Hi, ALL, I have a csv file which depending on how it was produced gives 2 different strings as shown in the example below (test1 and test2). I am only interested in the first field in test1 and obviously in the whole string of test2. So, I tried to see if I can get what I want in one simple way, but failed. Is it possible to process the file independently? Thank you. python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> test1 = "a,,,," >>> test2 = "a" >>> (t1,_) = test1.split(',') Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack >>> (t2,_) = test2.split(',') Traceback (most recent call last): File "", line 1, in ValueError: need more than 1 value to unpack >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Mar 3 23:09:43 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 3 Mar 2014 22:09:43 -0600 Subject: How do I process this? In-Reply-To: References: Message-ID: <20140303220943.0a244e96@bigbox.christie.dr> On 2014-03-03 20:03, Igor Korot wrote: > Hi, ALL, > I have a csv file which depending on how it was produced gives 2 > different strings as shown in the example below (test1 and test2). > I am only interested in the first field in test1 and obviously in > the whole string of test2. > > So, I tried to see if I can get what I want in one simple way, but > failed. Is it possible to process the file independently? > > Thank you. > > >>> test1 = "a,,,," > >>> test2 = "a" > >>> (t1,_) = test1.split(',') > Traceback (most recent call last): > File "", line 1, in > ValueError: too many values to unpack > >>> (t2,_) = test2.split(',') > Traceback (most recent call last): > File "", line 1, in > ValueError: need more than 1 value to unpack > >>> Have you tried t = test.split(',', 1)[0] or t = test.partition(',')[0] Both of which yield the same results for me. -tkc From zachary.ware+pylist at gmail.com Mon Mar 3 23:16:02 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 3 Mar 2014 22:16:02 -0600 Subject: How do I process this? In-Reply-To: References: Message-ID: On Mon, Mar 3, 2014 at 10:03 PM, Igor Korot wrote: > Hi, ALL, > I have a csv file which depending on how it was produced gives 2 different > strings as shown in the example below (test1 and test2). > I am only interested in the first field in test1 and obviously in the whole > string of test2. > > So, I tried to see if I can get what I want in one simple way, but failed. > Is it possible to process the file independently? > > Thank you. > > python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> test1 = "a,,,," >>>> test2 = "a" >>>> (t1,_) = test1.split(',') > Traceback (most recent call last): > File "", line 1, in > ValueError: too many values to unpack >>>> (t2,_) = test2.split(',') > Traceback (most recent call last): > File "", line 1, in > ValueError: need more than 1 value to unpack >>>> I'm not sure what you mean by "is it possible to process the file independently", can you expand on that a bit? As far as what you're trying to do, there are a couple ways to do it. If you can use Python 3 instead: T:\emp>py -3 Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> test1 = "a,,,," >>> test2 = "a" >>> t1, *remainder1 = test1.split(',') >>> t1 'a' >>> remainder1 ['', '', '', ''] >>> t2, *remainder2 = test2.split(',') >>> t2 'a' >>> remainder2 [] >>> ^Z Or, if you're stuck on Python 2: T:\emp>py -2 Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> test1 = "a,,,," >>> test2 = "a" >>> t1 = test1.split(',')[0] >>> t1 'a' >>> t2 = test2.split(',')[0] >>> t2 'a' >>> Hope this helps, -- Zach From steve at pearwood.info Mon Mar 3 23:38:05 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 04:38:05 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> Message-ID: <531558ac$0$2923$c3e8da3$76491128@news.astraweb.com> On Mon, 03 Mar 2014 18:02:04 -0500, Roy Smith wrote: > In article , > Ben Finney wrote: > >> That's right. Python provides this singleton and then recommends you >> compare with ?is?, precisely to protect against pathological cases like >> a ?return True when compared for equality with None? data type. > > Going off on a tangent, I've often wished Python provided more kinds of > None-ness. I'll often write: > > def f(arg=None): > whatever > > where it would be nice to differentiate between "this was called with no > arguments" and "this was called with an argument of None". Sure, I can > work around that with things like **kwargs, That's the hard way. The easy way is: _SENTINEL = object() def f(arg=_SENTINEL): if arg is _SENTINEL: ... If you really cared, you could implement your own None_ish_Type and create as many named sentinels as you wish. -- Steven From gordon at panix.com Mon Mar 3 23:46:24 2014 From: gordon at panix.com (John Gordon) Date: Tue, 4 Mar 2014 04:46:24 +0000 (UTC) Subject: How do I process this? References: Message-ID: In Igor Korot writes: > --047d7b6dc250a1426004f3bffd8d > Content-Type: text/plain; charset=ISO-8859-1 > Hi, ALL, > I have a csv file which depending on how it was produced gives 2 different > strings as shown in the example below (test1 and test2). > I am only interested in the first field in test1 and obviously in the whole > string of test2. > So, I tried to see if I can get what I want in one simple way, but failed. > Is it possible to process the file independently? > Thank you. split() returns a list. Use indexing to grab only the element you want, like this: t1 = test1.split(',')[0] t2 = test2.split(',')[0] -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From steve at pearwood.info Mon Mar 3 23:52:38 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 04:52:38 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> Message-ID: <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 04 Mar 2014 00:22:55 +0200, Marko Rauhamaa wrote: > Jerry Hill : > >> except for the fact that there has been 20 years of custom saying that >> comparing to None with equality is wrong. > > "if foo == None" is not wrong in any manner. It's just that if you are > comfortable with the "is" operator and its semantics, "if foo is None" > is slightly more natural. > > You generally use "==" if more than one object could be equal. If you > know there's only one object of the kind, you convey that knowledge by > the use of "is" even when functionally, it doesn't matter. I don't agree that it doesn't matter. Code, even when functionally equivalent, should express the intention of the programmer in as simple a fashion as is possible given the constraints of the task, performance, etc. For example, if you want to add 1 to a number, you would write: x += 1 not: x += (127 - 102)//(5**2) even though you know that the two expressions are exactly equivalent. Even if you know that there is a peep-hole optimizer that ensures that the code actually compiled is "x += 1". The intention to the reader is important. This is why, unless performance is *really* critical, one should normally write x*2 when multiplying x by 2 rather than x >> 1. (And in Python, the overhead means that there is no real performance benefit to using bit shifts instead of multiplication or division.) If your intention is to treat None as a singleton sentinel, not as a value, then you ought to use "is" to signal that intention, rather than using == even if you know that there won't be any false positives. -- Steven From rustompmody at gmail.com Tue Mar 4 00:19:48 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 21:19:48 -0800 (PST) Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> Message-ID: <3e6e8aa4-b2f5-4aec-bae3-20423978a4a0@googlegroups.com> On Tuesday, March 4, 2014 9:16:25 AM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 2:13 PM, Rustom Mody wrote: > >> But it's a far cry from "all real numbers". Even allowing for > >> continued fractions adds only some more; I don't think you can > >> represent surds that way. > > See > > http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfINTRO.html#sqrts > That's neat, didn't know that. Is there an efficient way to figure > out, for any integer N, what its sqrt's CF sequence is? And what about > the square roots of non-integers - can you represent ?? that way? I > suspect, though I can't prove, that there will be numbers that can't > be represented even with an infinite series - or at least numbers > whose series can't be easily calculated. You are now asking questions that are really (real-ly?) outside my capacities. What I know (which may be quite off the mark :-) ) Just as all real numbers almost by definition have a decimal form (may be infinite eg 1/3 becomes 0.33333...) all real numbers likewise have a CF form For some mathematical (aka arcane) reasons the CF form is actually better. Furthermore: 1. Transcendental numbers like e and pi have non-repeating infinite CF forms 2. Algebraic numbers (aka surds) have repeating maybe finite(?) forms 3. For some numbers its not known whether they are transcendental or not (vague recollection pi^sqrt(pi) is one such) 4 Since e^ipi is very much an integer, above question is surprisingly non-trivial From rosuav at gmail.com Tue Mar 4 00:24:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 16:24:03 +1100 Subject: Reference In-Reply-To: <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 3:52 PM, Steven D'Aprano wrote: > This is why, unless performance is *really* critical, one should normally > write x*2 when multiplying x by 2 rather than x >> 1. (And in Python, the > overhead means that there is no real performance benefit to using bit > shifts instead of multiplication or division.) In most C compilers today (C being where x << 1 would be used rather than x * 2), the expressions would be equivalent, so you can still express it as x * 2 and let the compiler turn that into a bit shift. (And it's possible that "x * 5" will become "x << 2 + x", too.) Definitely go for the expressive version unless you've actually tested that the obscure version is faster. (Of course, that doesn't mean the bit-shift operators should never be used. If you're trying to pack three tiny integers into a single larger integer, you probably want bit shifts and bitwise or, not multiplication and addition, even though either would work.) Code should look like its intent. Warping it around performance is hardly ever worthwhile. ChrisA From tjreedy at udel.edu Tue Mar 4 00:32:56 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 04 Mar 2014 00:32:56 -0500 Subject: 3.4rc2 and pip on windows In-Reply-To: References: Message-ID: On 3/3/2014 2:47 PM, Mark Lawrence wrote: > On 03/03/2014 00:07, Terry Reedy wrote: >> On 3/2/2014 6:55 PM, Mark Lawrence wrote: >>> Trying to install pyttsx, it doesn't strike me as very clever that, as >>> seen below, you get "Successfully installed pyttsx" despite the syntax >>> errors and you can't actually do an import. >>> >>> c:\Users\Mark\CrossCode>c:\Python34\Scripts\pip3.4.exe install pyttsx >>> Downloading/unpacking pyttsx >>> Downloading pyttsx-1.1.tar.gz >>> Running setup.py >>> (path:C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\pyttsx\setup.py) >>> egg_info for package pyttsx >>> >>> Installing collected packages: pyttsx >>> Running setup.py install for pyttsx >>> File "C:\Python34\Lib\site-packages\pyttsx\driver.py", line 105 >>> except Exception, e >>> ^ >>> SyntaxError: invalid syntax This is from setup.py >>> [other syntax errors snipped] >>> >>> Successfully installed pyttsx This is from pip, saying that it successfully downloaded and installed the files on your disk, which it did. >> A bug it seems to me. After reading the responses on the tracker and here, the bug is in the total systen of interaction of multiple parts. It is not a bug for the part covered by the tracker. >>> Cleaning up... >>> >>> c:\Users\Mark\CrossCode>py -3.4 >>> Python 3.4.0rc2 (v3.4.0rc2:a300712ed38c, Feb 23 2014, 10:49:04) [MSC >>> v.1600 32 bit (Intel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> import pyttsx >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "C:\Python34\lib\site-packages\pyttsx\__init__.py", line 18, in >>> >>> from engine import Engine >>> >>> I've looked at pyttsx in my 3.3 site-packages and it appears that I've >>> manually run 2to3. Is this something that could be done automatically >>> by pip? Your thoughts please, ladies and gentlemen. >> >> I should hope so. > FTR I raised this as http://bugs.python.org/issue20846 and it was closed > 11 minutes after I raised it. I won't say anything else as I'm > extremely tired and irritable and might well regret it later. The issue brought to attention that the parts do not work together perfectly yet and stimulated some thought and some clarification on what needs to be done. I understand the irritation, but sleeping on it and letting it go is a good idea. -- Terry Jan Reedy From steve at pearwood.info Tue Mar 4 00:35:24 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 05:35:24 GMT Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 04 Mar 2014 05:37:27 +1100, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 4:27 AM, Steven D'Aprano > wrote: >> On Tue, 04 Mar 2014 02:01:47 +1100, Chris Angelico wrote: >> >>> This is why it's tricky to put rules in based on type inference. The >>> programmer's intent isn't in the picture. >> >> Of course it is. If I assign 23 to variable x, that signals my intent >> to assign an int to x. By Occam's razor, it is reasonable to >> extrapolate that intent to mean "x is an int", rather than "an int, or >> a list" or "an odd int larger than 7 but smaller than 25", or "any int >> except 13". Type inference picks the type which involves the fewest >> additional assumptions. The programmer can always over-ride the type >> inference by explicitly stating the type. > > Yes, and that's fine for most purposes. The problem isn't the inference, > the problem is when rules are created based on that kind of guess - when > the programmer's subsequent actions are governed by a guess the compiler > takes. > > x = 23 # Compiler goes: Okay, x takes ints. x += 5 # Compiler: No prob, > int += int --> int x = str(x) # Compiler: NO WAY! str(int) --> str, not > allowed! > > It's fine and correct to infer that x is an int, x is an int, x is a > str. It's *not* okay to make the third line a SyntaxError because you > just put a str into an int variable. It won't be a Syntax Error, it will be a compile-time Type Error. And, yes, it is fine. That's the point of static typing! The tradeoff of being able to detect a whole lot of errors *at compile time* is that you give up the ability to re-use the same variable for different types in a single scope. (You can have an x which is a string elsewhere, just not in this scope where it is an int.) It's okay if you personally prefer the flexibility and freedom of dynamic typing. The cost of this choice is that you become responsible for writing unit tests that ensure that code behaves safely when given unexpected types. If you choose static typing instead, you get a whole lot of error checking done at compile time, and likely a lot of compiler optimizations. But the cost is that you can't write: x = 23 x += 5 x = str(x) and instead have to write: x = 23 x += 5 s = str(x) You should, I think, read this: http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/ [...] >> That's not type inference. That's ancient and annoying obligatory type >> declarations as used by ancient languages with primitive type systems, >> like Pascal and C. > > And that's exactly what Haskell apparently has, with homogeneous lists > and no easy way to say that it can take more types. That Haskell has homogeneous lists is not a property of the type system, but a design choice. I'm sure Haskell will also have a tuple or record type that allows fields of different types. > Python's handling is: A list can hold anything. [...] > Haskell's handling apparently is: A list/array can hold one thing and > one thing only. That 'thing' can be a union, but then you need to be > REALLY explicit about which side is which. Yes. > It's not possible to > sub-specify a type (like the "string('a'..'x')" type in Pike that will > take only strings with nothing but the first 24 lower-case letters - not > that I've ever needed that), but the compiler can work out everything > else. I have not used Haskell enough to tell you whether you can specify subtypes. I know that, at least for numeric (integer) types, venerable old Pascal allows you to define subtypes based on integer ranges, so I'd be surprised if you couldn't do the same thing in Haskell. The flexibility of the type system -- its ability to create subtypes and union types -- is independent of whether it is explicitly declared or uses type inference. > The way I see it, Python's form is fully dynamic and open, Pike's is > fully dynamic and the programmer's allowed to explicitly close things, > and Haskell's is rigidly tight. That's not to say that tight is a bad > thing (it's probably good for learning under), but personally, I'd > rather have the freedom. Hey, I'm a Python programmer! You don't have to sell me on the benefits of dynamic typing. Before Python, my language of choice was Apple's Hyperscript, which is untyped -- everything, and I mean everything, is a string in Hyperscript. It works remarkably well, so long as you don't care about speed. But even in the late 80s or early 1990s, on single-core CPUs running at a piddly 7.8 MHz (compared to about 1000 MHz for desktops today), you could get acceptable performance for a remarkable range of applications. But don't be fooled, those benefits aren't free. Static typing has benefits too. -- Steven From steve at pearwood.info Tue Mar 4 00:53:06 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 05:53:06 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> Message-ID: <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 04 Mar 2014 14:46:25 +1100, Chris Angelico wrote: > That's neat, didn't know that. Is there an efficient way to figure out, > for any integer N, what its sqrt's CF sequence is? And what about the > square roots of non-integers - can you represent ?? that way? I suspect, > though I can't prove, that there will be numbers that can't be > represented even with an infinite series - or at least numbers whose > series can't be easily calculated. Every rational number can be written as a continued fraction with a finite number of terms[1]. Every irrational number can be written as a continued fraction with an infinite number of terms, just as every irrational number can be written as a decimal number with an infinite number of digits. Most of them (to be precise: an uncountably infinite number of them) will have no simple or obvious pattern. [1] To be pedantic, written as *two* continued fractions, one ending with the term 1, and one with one less term which isn't 1. That is: [a; b, c, d, ..., z, 1] == [a; b, c, d, ..., z+1] Any *finite* CF ending with one can be simplified to use one fewer term. Infinite CFs of course don't have a last term. -- Steven From rustompmody at gmail.com Tue Mar 4 00:59:03 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 21:59:03 -0800 (PST) Subject: Functional programming In-Reply-To: <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <596a3756-808c-4d66-995f-a9db13effb9a@googlegroups.com> On Tuesday, March 4, 2014 11:05:24 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 05:37:27 +1100, Chris Angelico wrote: > > It's not possible to > > sub-specify a type (like the "string('a'..'x')" type in Pike that will > > take only strings with nothing but the first 24 lower-case letters - not > > that I've ever needed that), but the compiler can work out everything > > else. > I have not used Haskell enough to tell you whether you can specify > subtypes. I know that, at least for numeric (integer) types, venerable > old Pascal allows you to define subtypes based on integer ranges, so I'd > be surprised if you couldn't do the same thing in Haskell. Its a bit murkier. See http://lambda-the-ultimate.org/node/4771 Especially see the scala choices comment Also this comment by Peyton Jones is telling Damas-Milner* is on a cusp: Can infer most-general types without any type annotations at all But virtually any extension destroys this property from www.cs.nott.ac.uk/~gmh/appsem-slides/peytonjones.ppt * The functional programming type inference algorithm From rosuav at gmail.com Tue Mar 4 01:04:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 17:04:55 +1100 Subject: Functional programming In-Reply-To: <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 4:35 PM, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 05:37:27 +1100, Chris Angelico wrote: >> x = 23 # Compiler goes: Okay, x takes ints. x += 5 # Compiler: No prob, >> int += int --> int x = str(x) # Compiler: NO WAY! str(int) --> str, not >> allowed! >> >> It's fine and correct to infer that x is an int, x is an int, x is a >> str. It's *not* okay to make the third line a SyntaxError because you >> just put a str into an int variable. > > It won't be a Syntax Error, it will be a compile-time Type Error. And, > yes, it is fine. That's the point of static typing! The tradeoff of being > able to detect a whole lot of errors *at compile time* is that you give > up the ability to re-use the same variable for different types in a > single scope. (You can have an x which is a string elsewhere, just not in > this scope where it is an int.) Okay, a compile-type type error, same difference. What I'm saying is that the auto-detection can't know what else you plan to do. If you explicitly say that this is an int, then yes, that should be disallowed; if you explicitly say that it's either an int or a float, then you should be able to have either, but not a string. (C does this with explicitly tagged unions, usually. Python and Pike do it by simply allowing multiple types in the same slot.) > That Haskell has homogeneous lists is not a property of the type system, > but a design choice. I'm sure Haskell will also have a tuple or record > type that allows fields of different types. If it's not the list type, pick some other. It's not uncommon to want to have a record that has different types (C does this with struct, C++ has a few more ways to do it); what I'm finding odd is that whatever goes into it first is specifying for everything else. > I have not used Haskell enough to tell you whether you can specify > subtypes. I know that, at least for numeric (integer) types, venerable > old Pascal allows you to define subtypes based on integer ranges, so I'd > be surprised if you couldn't do the same thing in Haskell. > > The flexibility of the type system -- its ability to create subtypes and > union types -- is independent of whether it is explicitly declared or > uses type inference. I'm not sure how you could have type inference with subtypes. How does the compiler figure out what subtype of integers is acceptable, such that it can reject some? x = 5 x = 7 x = 11 x = 17 x = 27 Should the last one be rejected because it's not prime? How can it know that I actually wanted that to be int(3..20)? That's why I see them as connected. All sorts of flexibilities are possible when the programmer explicitly tells the compiler what the rules are. > Hey, I'm a Python programmer! You don't have to sell me on the benefits > of dynamic typing. Before Python, my language of choice was Apple's > Hyperscript, which is untyped -- everything, and I mean everything, is a > string in Hyperscript. It works remarkably well, so long as you don't > care about speed. But even in the late 80s or early 1990s, on single-core > CPUs running at a piddly 7.8 MHz (compared to about 1000 MHz for desktops > today), you could get acceptable performance for a remarkable range of > applications. > > But don't be fooled, those benefits aren't free. Static typing has > benefits too. For me, that untyped language was REXX. One data type (the string), and a special feature of variable names to handle what most people would do with arrays/lists/mappings/dicts/etc/etc/etc. (Or, of course, you do what you'd presumably do in Hyperscript, and implement an array of words as a string that you separate on ' '. VX-REXX had a neat 'initializer format' where you simply prefix every element with the separator - that is to say, the first character of the string is the separator. It nests perfectly and is pretty convenient to type. A little obscure for most people, though.) Was also my first taste of arbitrary-precision arithmetic. C could cream it as long as I didn't need anything over 2**32 or anything I can't do in a double-precision float, but I could calculate 200! with clean brute-force code and it'd work perfectly. Static and dynamic typing both have their uses. But when I use static typing, I want to specify the types myself. I'm aware that's a matter of opinion, but I don't like the idea of the compiler rejecting code based on inferred types. ChrisA From rustompmody at gmail.com Tue Mar 4 01:20:51 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 3 Mar 2014 22:20:51 -0800 (PST) Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tuesday, March 4, 2014 11:34:55 AM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 4:35 PM, Steven D'Aprano wrote: > > I have not used Haskell enough to tell you whether you can specify > > subtypes. I know that, at least for numeric (integer) types, venerable > > old Pascal allows you to define subtypes based on integer ranges, so I'd > > be surprised if you couldn't do the same thing in Haskell. > > The flexibility of the type system -- its ability to create subtypes and > > union types -- is independent of whether it is explicitly declared or > > uses type inference. > I'm not sure how you could have type inference with subtypes. Short answer: You cant [Yeah Some folks dont like my short answers :-) ] Long answer: See the links I posted above Intermediate answer: Types (for a modern FPL) are like math sets except that: - set-membership is in general hard and in principle undecidable - type-membership had better be decidable and preferably linear-time if its to be part of an implementation (and not a philosophical discussion over a cuppa chai) - Which means that... > Static and dynamic typing both have their uses. But when I use static > typing, I want to specify the types myself. I'm aware that's a matter > of opinion, but I don't like the idea of the compiler rejecting code > based on inferred types. ...Type inference is strictly (aka mathematically) syntax even though in the implementation, the parsing phase and the type checking/inferencing phase are sequenced In short: An important flavor of the FP koolaid is the Damas-Milner type-inferencing algorithm. Damas-Milner + Subtyping is the recipe for a severe headache -- An important reason why FP and OOP are incompatible From rosuav at gmail.com Tue Mar 4 01:35:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 17:35:12 +1100 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 4:53 PM, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 14:46:25 +1100, Chris Angelico wrote: > >> That's neat, didn't know that. Is there an efficient way to figure out, >> for any integer N, what its sqrt's CF sequence is? And what about the >> square roots of non-integers - can you represent ?? that way? I suspect, >> though I can't prove, that there will be numbers that can't be >> represented even with an infinite series - or at least numbers whose >> series can't be easily calculated. > > Every irrational number can be written as a > continued fraction with an infinite number of terms, just as every > irrational number can be written as a decimal number with an infinite > number of digits. It's easy enough to have that kind of expansion, I'm wondering if it's possible to identify it directly. To render the decimal expansion of a square root by the cut-and-try method, you effectively keep dividing until you find that you're "close enough"; that means you (a) have to keep the entire number around for each step, and (b) need to do a few steps to find that the digits aren't changing. But if you can take a CF (finite or infinite) and do an O(n) transformation on it to produce that number's square root, then you have an effective means of representing square roots. Suppose I make a generator function that represents a fraction: def one_third(): while True: yield 3 def one_seventh(): while True: yield 1; yield 4; yield 2; yield 8; yield 5; yield 7 I could then make a generator that returns the sum of those two: def add_without_carry(x, y): whiile True: yield next(x)+next(y) Okay, that's broken for nearly any case, but with a bit more sophistication: def add(x, y): prev=None nines=0 while True: xx,yy=next(x),next(y) tot=xx+yy if tot==9: nines+=1 continue if tot>9: if prev is None: raise OverflowError("exceeds 1.0") yield prev+1 tot-=10 for _ in range(nines): yield 0 nines=0 else: if prev is not None: yield prev prev=tot def show(n): return ''.join(str(_) for _ in itertools.islice(n,20)) >>> show(add(one_third(),one_seventh())) '47619047619047619047' >>> show(add(add(add(one_seventh(),one_seventh()),add(one_seventh(),one_seventh())),add(one_seventh(),one_seventh()))) '85714285714285714285' In constant space, that will produce the sum of two infinite sequences of digits. (And it's constant time, too, except when it gets a stream of nines. Adding three thirds together will produce an infinite loop as it waits to see if there'll be anything that triggers an infinite cascade of carries.) Now, if there's a way to do that for square rooting a number, then the CF notation has a distinct benefit over the decimal expansion used here. As far as I know, there's no simple way, in constant space and/or time, to progressively yield more digits of a number's square root, working in decimal. ChrisA From steve at pearwood.info Tue Mar 4 03:56:33 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 08:56:33 GMT Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 04 Mar 2014 17:04:55 +1100, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 4:35 PM, Steven D'Aprano > wrote: >> On Tue, 04 Mar 2014 05:37:27 +1100, Chris Angelico wrote: >>> x = 23 # Compiler goes: Okay, x takes ints. x += 5 # Compiler: No >>> prob, int += int --> int x = str(x) # Compiler: NO WAY! str(int) --> >>> str, not allowed! >>> >>> It's fine and correct to infer that x is an int, x is an int, x is a >>> str. It's *not* okay to make the third line a SyntaxError because you >>> just put a str into an int variable. >> >> It won't be a Syntax Error, it will be a compile-time Type Error. And, >> yes, it is fine. That's the point of static typing! The tradeoff of >> being able to detect a whole lot of errors *at compile time* is that >> you give up the ability to re-use the same variable for different types >> in a single scope. (You can have an x which is a string elsewhere, just >> not in this scope where it is an int.) > > Okay, a compile-type type error, same difference. What I'm saying is > that the auto-detection can't know what else you plan to do. Obviously it can't see the code you haven't written yet, but it can see what you *do* do. > If you > explicitly say that this is an int, then yes, that should be disallowed; It's that "explicitly" part that doesn't follow. Having to manage types is the most tedious, boring, annoying, *unproductive* part of languages like Java, C and Pascal. Almost always, you're telling the compiler stuff that it can work out for itself. In the same way that managing jumps for GOTO has been automated with for loops, while, etc., and managing memory has been automated, there's no good reason not to allow the compiler to manage types. Dynamically typed languages like Python do so at runtime. Type inference simply allows statically typed languages to do the same only at compile time. [...] >> That Haskell has homogeneous lists is not a property of the type >> system, but a design choice. I'm sure Haskell will also have a tuple or >> record type that allows fields of different types. > > If it's not the list type, pick some other. It's not uncommon to want to > have a record that has different types (C does this with struct, C++ has > a few more ways to do it); what I'm finding odd is that whatever goes > into it first is specifying for everything else. That's because in Haskell the design was made that lists *must* be used for homogeneous data. If you read Python documentation from back in the 1.5 and early 2.x days, there was a *very* strong recommendation that lists be used for homogeneous data only and tuples for heterogeneous data. This recommendation goes all the way up to Guido. # Yes [1, 3, 4, 2, 5, 9] (1, "hello", None, 3.5) # No [1, "hello", None, 3.5] That is, lists are for collections of data of arbitrary length, tuples are for records or structs with dedicated fields. That convention is a bit weaker these days than it used to be. Tuples now have list-like methods, and we have namedtuple for record/struct-like objects with named fields. But still, it is normal to use lists with homogeneous data, where there is an arbitrary number of "things" with different values, but all the same kind of thing. In the case of Haskell, that's more than a mere convention, it's a rule, but that's not terribly different from (say) Pascal where you can have an array of integer but not an array of integer-or-real. The thing is though, how often do you really have a situation where you have a bunch of arbitrary data, or unknown length, where you don't know what type of data it is? Sure, in the interactive interpreter it is useful to be able to write [1, "spam", None, [], {}, 0.1, set()] and I write unit tests with that sort of thing all the time: for obj in list_of_arbitrary_objects: self.assertRaises(TypeError, func, obj) kind of thing. But that doesn't have to be a *list*. It just needs to have convenient syntax. >> I have not used Haskell enough to tell you whether you can specify >> subtypes. I know that, at least for numeric (integer) types, venerable >> old Pascal allows you to define subtypes based on integer ranges, so >> I'd be surprised if you couldn't do the same thing in Haskell. >> >> The flexibility of the type system -- its ability to create subtypes >> and union types -- is independent of whether it is explicitly declared >> or uses type inference. > > I'm not sure how you could have type inference with subtypes. How does > the compiler figure out what subtype of integers is acceptable, such > that it can reject some? You seem to be under the impression that type inference means "guess what the programmer wants", or even "read the programmer's mind". Take this example: > x = 5 > x = 7 > x = 11 > x = 17 > x = 27 > > Should the last one be rejected because it's not prime? How can it know > that I actually wanted that to be int(3..20)? It can't, of course, any more than I could, or anyone other than you. But if you asked a hundred people what all those values of x had in common, 93 of them would say "they're all integers", 6 would say "they're all positive integers", and 1 would say "they're all positive odd integers". [Disclaimer: percentages plucked out of thin air.] No type system can, or should, try to guess whatever bizarre subtype you *might* want. ("Only numbers spelled with the letter V.") If you want something stupid^W weird^W unusual, it's your responsibility to work within the constraints of the programming language to get that, whether you are using Python, Pascal or Haskell. > That's why I see them as > connected. All sorts of flexibilities are possible when the programmer > explicitly tells the compiler what the rules are. And you can still do that, *when you need to*. Assuming the type system has a way of specifying "integers that include the letter V", you can specify it when you want it. > Static and dynamic typing both have their uses. But when I use static > typing, I want to specify the types myself. I'm aware that's a matter of > opinion, but I don't like the idea of the compiler rejecting code based > on inferred types. Well, so long as you admit it's an irrational preference :-) The bottom line is, if the compiler rejects code, it's because it has a bug. There's *no difference* between the compiler telling you that you can't add a string and an int when you've explicitly declared the types, and the compiler telling you that you can't add a string and an int when it has determined for itself that they are the types because that's all that they can be. -- Steven From francis.moro at gmail.com Tue Mar 4 04:29:43 2014 From: francis.moro at gmail.com (Francis Moreau) Date: Tue, 04 Mar 2014 10:29:43 +0100 Subject: Decoding a process output Message-ID: Hi, In my understanding (I'm relatively new to python), I need to decode any bytes data provided, in my case, by a shell command (such as findmnt) started by the subprocess module. The goal of my application is to parse the command outputs. My application runs only on linux BTW and should run fine on both python 2.7 and py3k. My question is when decoding the output bytes data of the external command, which encoding should I use ? Should I guess the encoding by inspecting LANG or any LC_* environment variables ? Should I force one of those environment variable to a specific value before running my external command ? Thanks for any tips. From bc at freeuk.com Tue Mar 4 04:41:34 2014 From: bc at freeuk.com (BartC) Date: Tue, 4 Mar 2014 09:41:34 -0000 Subject: Functional programming In-Reply-To: <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com><3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com><216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com><0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:5314bb96$0$29985$c3e8da3$5496439d at news.astraweb.com... > Think about the sort of type declarations you have to do in (say) Pascal, > and consider how stupid the compiler must be: > > function add_one(x: integer):integer; > begin > add_one := x+1; > end; > > Given that x is an integer, and that you add 1 (also an integer) to it, > is it really necessary to tell the compiler that add_one returns an > integer? What else could the output type be? > > This was state of the art back in 1970, but these days, if the compiler > cannot *at least* infer the type of the return result of a function given > the argument types, the static type system is too dumb to bother with. To me that is perfectly reasonable. This kind of language, while it allows expressions of mixed numeric types, treats each kind of number type as different: integer and real, even signed and unsigned integer, and there might be short, medium and long versions of each! And Pascal has an unlimited number of scalar types too. The compiler could make a guess at what the intended result might be, based on a hundred add_one:= assignments, all with a slightly different type on the right-hand-side, and perhaps choose a type that encompasses all the possibilities (although it might erroneously decide the result is real, based on one of those hundred, and use floating point for all of them). But then someone edits the code, and this time the guess will be different! For a static language such as this, type-discipline is important. And even if the compiler gets it right, a human reading the code would have trouble determining the return type, except in trivial examples like this. Putting in an explicit return type is the simplest way to go. -- Bartc From peacech at gmail.com Tue Mar 4 04:52:59 2014 From: peacech at gmail.com (Charles Gunawan) Date: Tue, 4 Mar 2014 01:52:59 -0800 (PST) Subject: Python 2.7 documentation with readthedocs theme Message-ID: <0f2da19b-1b8a-4da1-8354-773ff224f734@googlegroups.com> Hi, I was just looking into some documentation on readthedocs and I saw that they have a cool new theme. I was wondering how the python documentation will look like with that theme. So after some tinkering I have build python 2.7 CHM documentation with the theme. If you are wondering too you can look at the chm (http://d-h.st/e1W) or the screenshot (http://imgur.com/7kVzZUt). From ikorot01 at gmail.com Tue Mar 4 05:02:17 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 4 Mar 2014 02:02:17 -0800 Subject: Logging Message-ID: Hi, ALL, Could someone please explain to me how the code in http://docs.python.org/2/howto/logging#logging-from-multiple-modules works? In particular I'm interested in how the mylib.py knows about the myapp.log. What I mean is: logging object is not passed to mylib.py, so essentially it should create a new instance of the logging object. What am I missing? But this question comes from the following fact about my application. I tried to create a logging object which will store the logging information to the file in the main class. Then I pass this object to another class constructor and use it in that second class. Upon running everything is OK, but when the program successfully finishes, the log file has 0 length. AFAIU, I'm doing it properly and the example referenced is wrong, yet the results are completely different. Thank you for any expplanation. From mailinglists at vanwingerde.nl Tue Mar 4 05:33:19 2014 From: mailinglists at vanwingerde.nl (Jaap van Wingerde) Date: Tue, 4 Mar 2014 10:33:19 +0000 Subject: modification time in Python - Django: datetime != datetime :-( In-Reply-To: <04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com> References: <20140303133541.66fccbbb@lia.custard.shrl.nl> <04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com> Message-ID: <20140304103319.5f8cd8cf@jaap.custard.shrl.nl> Op 2014-03-03T12:22:48 UTC schreef donarb in het bericht , ID: <04659633-e14e-4d5b-90f2-93af04f056be at googlegroups.com> het volgende. > You're using the months format '%m' when you should be using minutes > '%M'. Arrgh: stupid error (snik). p 2014-03-04T08:11:46 UTC schreef Chris Angelico in het bericht , ID: het volgende. > Heh! I didn't even notice that. When I tested it, I didn't use > strftime at all, just looked at gmtime's output. Op 2014-03-04T08:06:21 UTC schreef Ben Finney in het bericht , ID: <85txbfhu0i.fsf at benfinney.id.au> het volgende. > You're using ?gmtime? to display the Python datetime value, but ?ls? > will display the time in the local timezone. Do you have a strange > timezone set? I only use UTC. Thanks!!!! The view.py is now as follows. ... home_lastmod = strftime('%Y-%m-%dT%H:%M:%SZ',gmtime(os.path.getmtime(os.path.dirname(os.path.realpath(__file__ ))+'/templates/art_index.html'))) ... -- Jaap van Wingerde e-mail: 1234567890 at vanwingerde.nl From antoon.pardon at rece.vub.ac.be Tue Mar 4 05:56:07 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 04 Mar 2014 11:56:07 +0100 Subject: Functional programming In-Reply-To: <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5315B147.3050002@rece.vub.ac.be> Op 04-03-14 09:56, Steven D'Aprano schreef: > > >> If you >> explicitly say that this is an int, then yes, that should be disallowed; > It's that "explicitly" part that doesn't follow. Having to manage types > is the most tedious, boring, annoying, *unproductive* part of languages > like Java, C and Pascal. Almost always, you're telling the compiler stuff > that it can work out for itself. In the same way writing unit tests is the most tedious, boring, annoying, *unproductive* part. Amost always you are giving the program results it can work out for itself. -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Tue Mar 4 06:02:33 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 04 Mar 2014 12:02:33 +0100 Subject: why indentation should be part of the syntax In-Reply-To: <531480DD.5040204@rece.vub.ac.be> References: <531480DD.5040204@rece.vub.ac.be> Message-ID: <5315B2C9.3020709@rece.vub.ac.be> Op 02-03-14 11:41, Stefan Behnel schreef: > Haven't seen any mention of it on this list yet, but since it's such an > obvious flaw in quite a number of programming languages, here's a good > article on the recent security bug in iOS, which was due to accidentally > duplicated code not actually being as indented as it looked: > > https://www.imperialviolet.org/2014/02/22/applebug.html > > Stefan > Well I can give an example where accidentally duplicated code can get you in trouble with python and which would be easily caught in C. If you accidentally duplicate the first half of a function. Chances are python will just accept it, because it is unlikely the last line that was duplicated was an if, for or while line. So your half duplicated function is probably legal python. However it is very unlikely that the braces will match so you will very likely get a compilation error. IMO the problem with C, is not that indentation is not part of the language. The problem is that after an if, for or while, you get the choice between putting either one simple statement or a block. I doubt you would get this problem in a language like modula2 where an if, for or while statement is always followed by a block, terminated with "END". So with modula like syntax the code would have looked like IF (err := SSLHashSHA1.update(&hashCtx, &signedParams)) != 0 THEN goto fail; goto fail; END which wouldn't have been a problem Or it might have looked like this IF (err := SSLHashSHA1.update(&hashCtx, &signedParams)) != 0 THEN goto fail; END goto fail; This would have produced the same problem but it would also have stood out because the second goto is indented in a place where it is obvious it doesn't match the program structure. -- Antoon Pardon From greg.ewing at canterbury.ac.nz Tue Mar 4 06:05:10 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 05 Mar 2014 00:05:10 +1300 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: Chris Angelico wrote: > In constant space, that will produce the sum of two infinite sequences > of digits. It's not constant space, because the nines counter can grow infinitely large. -- Greg From alister.ware at ntlworld.com Tue Mar 4 06:10:34 2014 From: alister.ware at ntlworld.com (Alister) Date: Tue, 04 Mar 2014 11:10:34 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <87wqgb6imm.fsf@elektro.pacujo.net> Message-ID: On Tue, 04 Mar 2014 09:18:57 +1100, Ben Finney wrote: > Marko Rauhamaa writes: > >> Mark Lawrence : >> >> > I'd just like to know why people are so obsessed with identities, >> > I've never thought to use them in 10+ years of writing Python. Do I >> > use the KISS principle too often? >> >> Calmly choosing the right tool for the job is not an obsession. > > Persistently banging your head in contradiction to the facts of Python's > data model, as you have been doing, starts to look very much like > obsession. Definition of insanity Doing the same thing over and over again & expecting different results -- Support staff hung over, send aspirin and come back LATER. From ian.g.kelly at gmail.com Tue Mar 4 06:19:59 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 4 Mar 2014 04:19:59 -0700 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Mar 3, 2014 at 11:35 PM, Chris Angelico wrote: > In constant space, that will produce the sum of two infinite sequences > of digits. (And it's constant time, too, except when it gets a stream > of nines. Adding three thirds together will produce an infinite loop > as it waits to see if there'll be anything that triggers an infinite > cascade of carries.) Now, if there's a way to do that for square > rooting a number, then the CF notation has a distinct benefit over the > decimal expansion used here. As far as I know, there's no simple way, > in constant space and/or time, to progressively yield more digits of a > number's square root, working in decimal. The code for that looks like this: def cf_sqrt(n): """Yield the terms of the square root of n as a continued fraction.""" m = 0 d = 1 a = a0 = floor_sqrt(n) while True: yield a next_m = d * a - m next_d = (n - next_m * next_m) // d if next_d == 0: break next_a = (a0 + next_m) // next_d m, d, a = next_m, next_d, next_a def floor_sqrt(n): """Return the integer part of the square root of n.""" n = int(n) if n == 0: return 0 lower = 2 ** int(math.log(n, 2) // 2) upper = lower * 2 while upper - lower > 1: mid = (upper + lower) // 2 if n < mid * mid: upper = mid else: lower = mid return lower The floor_sqrt function is merely doing a simple binary search and could probably be optimized, but then it's only called once during initialization anyway. The meat of the loop, as you can see, is just a constant amount of integer arithmetic. If it were desired to halt once the continued fraction starts to repeat, that would just be a matter of checking whether the triple (m, d, a) has been seen already. Going back to your example of adding generated digits though, I don't know how to add two continued fractions together without evaluating them. From ian.g.kelly at gmail.com Tue Mar 4 06:23:04 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 4 Mar 2014 04:23:04 -0700 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 4:19 AM, Ian Kelly wrote: > def cf_sqrt(n): > """Yield the terms of the square root of n as a continued fraction.""" > m = 0 > d = 1 > a = a0 = floor_sqrt(n) > while True: > yield a > next_m = d * a - m > next_d = (n - next_m * next_m) // d > if next_d == 0: > break > next_a = (a0 + next_m) // next_d > m, d, a = next_m, next_d, next_a Sorry, all that "next" business is totally unnecessary. More simply: def cf_sqrt(n): """Yield the terms of the square root of n as a continued fraction.""" m = 0 d = 1 a = a0 = floor_sqrt(n) while True: yield a m = d * a - m d = (n - m * m) // d if d == 0: break a = (a0 + m) // d From steve+comp.lang.python at pearwood.info Tue Mar 4 06:47:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 11:47:53 GMT Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 11:56:07 +0100, Antoon Pardon wrote: > Op 04-03-14 09:56, Steven D'Aprano schreef: > > >> >>> If you >>> explicitly say that this is an int, then yes, that should be >>> disallowed; >> It's that "explicitly" part that doesn't follow. Having to manage types >> is the most tedious, boring, annoying, *unproductive* part of languages >> like Java, C and Pascal. Almost always, you're telling the compiler >> stuff that it can work out for itself. > > In the same way writing unit tests is the most tedious, boring, > annoying, *unproductive* part. Actually, I like writing unit tests. How do you know what the function does until you test it? I'm not a TDD fanatic, but often I write tests before I write the code, and there's really nothing nicer than seeing a whole lot of failing unit tests suddenly start working. Well, maybe a nice BLT sandwich, when the bacon is nice and lean and the lettuce crisp and the tomato flavourful and not too soggy. But other than that, writing unit tests and seeing them pass is great. On the other hand, writing int n, m double x, y and similar three hundred times throughout your program is not terribly exciting. Even when it compiles, it doesn't mean it works. > Amost always you are giving the program > results it can work out for itself. Not even close. I'd like to see the compiler that can work out for itself that this function is buggy: def sine_rule(side_a, side_b, angle_a): """Return the angle opposite side_b.""" return math.sin(side_b/side_a)*angle_a If you don't remember your Sine Rule from trigonometry, that's okay. Trust me, the function is badly wrong. It's rubbish really. But short of some really impressive AI coupled with a Mathematica-level of maths knowledge, how is the compiler supposed to know that? Static type testing, while valuable, cannot tell you that the program does what you wanted it to do. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Tue Mar 4 06:48:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 11:48:46 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <87wqgb6imm.fsf@elektro.pacujo.net> Message-ID: <5315bd9e$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 11:10:34 +0000, Alister wrote: > Definition of insanity > > Doing the same thing over and over again & expecting different results *rolls dice* :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From jldunn2000 at gmail.com Tue Mar 4 07:27:55 2014 From: jldunn2000 at gmail.com (loial) Date: Tue, 4 Mar 2014 04:27:55 -0800 (PST) Subject: find and replace string in binary file Message-ID: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> How do I read a binary file, find/identify a character string and replace it with another character string and write out to another file? Its the finding of the string in a binary file that I am not clear on. Any help appreciated From rosuav at gmail.com Tue Mar 4 07:43:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 4 Mar 2014 23:43:53 +1100 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 10:05 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> In constant space, that will produce the sum of two infinite sequences >> of digits. > > > It's not constant space, because the nines counter > can grow infinitely large. Okay, okay, technically yes. But the counter can go a long way up before it takes up any additional space, so all that's really saying is that this has a major flaw with anything that produces a long stream of nines. It can't tell the difference between .99999999999999998 and .999999999999999999999999[11] where the 11 suddenly carries and it has to flip it all back. Anyway, that was like ten minutes' knocking-together work, you can't expect it to be perfect. I'm amazed it even worked. :) ChrisA From python at mrabarnett.plus.com Tue Mar 4 07:47:09 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Mar 2014 12:47:09 +0000 Subject: Origin of 'self' In-Reply-To: <7edah9989mdjb9mrnrsh5067np0ihv1jml@4ax.com> References: <7edah9989mdjb9mrnrsh5067np0ihv1jml@4ax.com> Message-ID: <5315CB4D.4030907@mrabarnett.plus.com> On 2014-03-04 02:09, Dennis Lee Bieber wrote: > On Sun, 2 Mar 2014 22:16:31 -0800 (PST), Westley Mart?nez > declaimed the following: > >> I understand that in an object method the first argument in the >> object itself, called self. However, it doesn't have to be called >> self, and can be called anything. So my question is why is it >> called self and not this like from C++ and Java. It's kind of a >> silly question, but one that I'm curious about nevertheless. >> > > It didn't want to be egotistical (as I recall, M$ VB uses "me") > So does AppleScript. In AppleScript a script can refer to the title of a window as "title of window" or "window's title", and it can refer to the title of its own window as "title of window of me" or "me's window's title". Consistent, yes, but bad English. That's why I prefer a programming language not to be too much like a natural language. :-) From news at blinne.net Tue Mar 4 07:55:39 2014 From: news at blinne.net (Alexander Blinne) Date: Tue, 04 Mar 2014 13:55:39 +0100 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> Message-ID: <5315cd4b$0$6670$9b4e6d93@newsspool2.arcor-online.net> Am 03.03.2014 19:48, schrieb Terry Reedy: > The 'is' operator has three uses, two intended and one not. In > production code, 'is' tests that an object *is* a particular singular > object, such as None or a sentinel instance of class object. Just a bit of statistics on this one from a recent small project: <13:51:20> alex at firefly$ grep ' is ' *.py | wc 65 415 3234 <13:51:35> alex at firefly$ grep ' is None' *.py | wc 43 243 1948 <13:51:40> alex at firefly$ grep ' is not None' *.py | wc 21 167 1241 <13:51:44> alex at firefly$ grep ' is False' *.py | wc 1 5 45 No other uses if 'is' found in almost 3 KLOC... From rosuav at gmail.com Tue Mar 4 08:01:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 00:01:01 +1100 Subject: Functional programming In-Reply-To: <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 4, 2014 at 10:47 PM, Steven D'Aprano wrote: > Not even close. I'd like to see the compiler that can work out for itself > that this function is buggy: > > def sine_rule(side_a, side_b, angle_a): > """Return the angle opposite side_b.""" > return math.sin(side_b/side_a)*angle_a > > > If you don't remember your Sine Rule from trigonometry, that's okay. > Trust me, the function is badly wrong. It's rubbish really. I'm not entirely sure what it's trying to do, but you're taking the sine of a ratio. That... seems wrong, gut-feeling-wise. You take the sine of an angle and get a ratio, or the arcsine of a ratio and get an angle. Also, trig functions apply only to right triangles, so the other angle is either going to be 90?-angle_a or 90?, depending on whether you want the angle opposite the hypotenuse or not. But it's years since I studied any of that. ChrisA From python at mrabarnett.plus.com Tue Mar 4 08:08:50 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Mar 2014 13:08:50 +0000 Subject: find and replace string in binary file In-Reply-To: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> References: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> Message-ID: <5315D062.2000004@mrabarnett.plus.com> On 2014-03-04 12:27, loial wrote: > How do I read a binary file, find/identify a character string and > replace it with another character string and write out to another > file? > > Its the finding of the string in a binary file that I am not clear > on. > > Any help appreciated > Read it in chunks and search each chunk (the chunks should be at least as long as the search string). You should note that the string you're looking for could be split across 2 chunks, so when writing the code make sure that you include some overlap between adjacent chunks (it's best if the overlap is at least N-1 characters, where N is the length of the search string). From __peter__ at web.de Tue Mar 4 08:18:58 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 04 Mar 2014 14:18:58 +0100 Subject: find and replace string in binary file References: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> Message-ID: loial wrote: > How do I read a binary file, find/identify a character string and replace > it with another character string and write out to another file? > > Its the finding of the string in a binary file that I am not clear on. That's not possible. You have to convert either binary to string or string to binary before you can replace. Whatever you choose, you have to know the encoding of the file. Consider #python3 ENCODING = "iso-8859-1" with open(source, encoding=ENCODING) as infile: data = infile.read() with open(dest, "w", encoding=ENCODING) as outfile: outfile.write(data.replace("n?tig", "m?glich")) If the file is indeed iso-8859-1 this will replace occurrences of the bytes b'n\xf6tig' with b'm\xf6glich' But if you were guessing wrong and the file is utf-8 it may contain the bytes b'n\xc3\xb6tig' instead which are incorrectly interpreted by your script as 'n??tig' and thus left as is. From python at mrabarnett.plus.com Tue Mar 4 08:19:54 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Mar 2014 13:19:54 +0000 Subject: Idle thread (Polling) python GUI and saving program state In-Reply-To: <4034b33f-0cb6-46fa-931c-450834c98d6e@googlegroups.com> References: <4034b33f-0cb6-46fa-931c-450834c98d6e@googlegroups.com> Message-ID: <5315D2FA.20903@mrabarnett.plus.com> On 2014-03-04 02:41, Rolando wrote:> On Monday, March 3, 2014 6:06:22 PM UTC-8, MRAB wrote: >> On 2014-03-04 01:33, Rolando wrote: >> > I have a GUI with a bunch of cells which is my "View" in the MVC >> > design. The user enters some information in the view and I pass >> > this on to the model so that using the information entered by >> > the user it(model) can do some processing. >> > >> > I have coded up my model as a state machine. Wherein, once a >> > function is complete it switches to the next state and so on. >> > >> > I want to know how do I save the program state between restarts. >> > Basically, I'm trying to handle a scenario wherein if someone >> > closes the program. The next time someone starts it up, it >> > should start from where it left off (both the view and model) >> > >> When the user closes the window (you don't say what you're using for >> the GUI, but there should be a way of detecting when window closes), >> save the necessary info to a file using, say, the 'json' module. You >> can then reload the info from the file when the program is >< restarted. >> >> > Also, I want to setup a poll method where once in a while I can >> > poll each cell to know the state it is in. How do I do this? I >> > don't want my GUI to hang when I'm doing anything. It will be >> > great if someone could help. Thanks! >> > >> Can the model run continuously? If so, you should run it in its own >> (background) thread and the GUI in the main thread and communicate >> with the model's thread via, say, a queue (for that use the 'queue' >> module). > > I'm using wxPython for my GUI. I have tried running the model thread in the background. But how will I save the state if the whole model is running on a thread? When the program is restarted I want the program to continue from the same state where it left off for each cell. I was thinking of having an idle thread that calls a poll method which polls all the cells and checks what each one is doing. But, I don't know how to do that. I'm confused. > Please read this: https://wiki.python.org/moin/GoogleGroupsPython because Gmail is formatting your email badly, making it harder to read. When the front-end wants to quit, it tells the back-end and then waits for it to terminate before itself quitting. When the back-end receives the message that it should quit, it saves its state and terminates. When the front-end starts up again, it starts the back-end. When the back-end starts, it load the state and runs. From bc at freeuk.com Tue Mar 4 08:30:04 2014 From: bc at freeuk.com (BartC) Date: Tue, 4 Mar 2014 13:30:04 -0000 Subject: Functional programming In-Reply-To: <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com><3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com><216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com><0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com><5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com><5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:53159540$0$2923$c3e8da3$76491128 at news.astraweb.com... > It's that "explicitly" part that doesn't follow. Having to manage types > is the most tedious, boring, annoying, *unproductive* part of languages > like Java, C and Pascal. Almost always, you're telling the compiler stuff > that it can work out for itself. Isn't creating classes in Python similar to creating types elsewhere? > In the same way that managing jumps for GOTO has been automated with for > loops, while, etc., and managing memory has been automated, there's no > good reason not to allow the compiler to manage types. Dynamically typed > languages like Python do so at runtime. Type inference simply allows > statically typed languages to do the same only at compile time. Eliminating 'goto' is simple code-generation logic; type inference is more of an art. But declaring variables is not just about specifying a type; it registers the name too so that misspelled names can be picked up very early rather than at runtime (and that's if you're lucky). > # Yes > [1, 3, 4, 2, 5, 9] > (1, "hello", None, 3.5) > > # No > [1, "hello", None, 3.5] > > > That is, lists are for collections of data of arbitrary length, tuples > are for records or structs with dedicated fields. > > That convention is a bit weaker these days than it used to be. Tuples now > have list-like methods, and we have namedtuple for record/struct-like > objects with named fields. (Aren't tuples immutable? They wouldn't work well for records then, because it would be impossible to change a field of a record.) -- Bartc From rosuav at gmail.com Tue Mar 4 08:47:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 00:47:54 +1100 Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 12:30 AM, BartC wrote: > But declaring variables is not just about specifying a type; it registers > the name too so that misspelled names can be picked up very early rather > than at runtime (and that's if you're lucky). The two are separate. I don't know of any language that lets you declare a type without catching the names, but there's certainly the other way around (ECMAScript just has "var x, y, z"). It'd be theoretically possible to have a Python-style "variable inference" system (if I can call it that - the rules of "if you assign to it and don't declare it as global/nonlocal, it's local") coupled with an optional type declaration system; if you don't declare, then it can hold anything. I just don't know of any language that does it. >> That convention is a bit weaker these days than it used to be. Tuples now >> have list-like methods, and we have namedtuple for record/struct-like >> objects with named fields. > > (Aren't tuples immutable? They wouldn't work well for records then, because > it would be impossible to change a field of a record.) They are, including namedtuples. But an object() can be used that way, if you want. ChrisA From breamoreboy at yahoo.co.uk Tue Mar 4 09:05:44 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Mar 2014 14:05:44 +0000 Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com><3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com><216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com><0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com><5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com><5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On 04/03/2014 13:30, BartC wrote: > > But declaring variables is not just about specifying a type; it registers > the name too so that misspelled names can be picked up very early rather > than at runtime (and that's if you're lucky). > I've said before that this, to me, is one of the major downsides of dynamic typing. Once a statically typed language has been compiled the programmer can head down to the pub. The programmer using dynamically typed languages has to hang around doing long, boring, tedious testing. Unless they're using an IDE like Pydev and have Pylint turned on so it picks up errors as they type, in which case they can also head down to the pub. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Tue Mar 4 09:06:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 01:06:20 +1100 Subject: Reference In-Reply-To: <5315cd4b$0$6670$9b4e6d93@newsspool2.arcor-online.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <5315cd4b$0$6670$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Tue, Mar 4, 2014 at 11:55 PM, Alexander Blinne wrote: > Am 03.03.2014 19:48, schrieb Terry Reedy: >> The 'is' operator has three uses, two intended and one not. In >> production code, 'is' tests that an object *is* a particular singular >> object, such as None or a sentinel instance of class object. > > Just a bit of statistics on this one from a recent small project: > > <13:51:20> alex at firefly$ grep ' is ' *.py | wc > 65 415 3234 > <13:51:35> alex at firefly$ grep ' is None' *.py | wc > 43 243 1948 > <13:51:40> alex at firefly$ grep ' is not None' *.py | wc > 21 167 1241 > <13:51:44> alex at firefly$ grep ' is False' *.py | wc > 1 5 45 > > No other uses if 'is' found in almost 3 KLOC... Lemme spin you up a different way of doing it, which actually looks for the operators. https://github.com/Rosuav/ExceptExpr/blob/master/find_except_expr.py Run across the Python stdlib, that tells me there are 4040 uses of is/is not, of which 16 compare against False, 18 against True (see? Python has a bias for truth above falsehood!), and 3386 against None. The other 620 are probably mostly sentinel objects, but I didn't look at them. ChrisA From rosuav at gmail.com Tue Mar 4 09:17:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 01:17:43 +1100 Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 1:05 AM, Mark Lawrence wrote: > On 04/03/2014 13:30, BartC wrote: >> >> >> But declaring variables is not just about specifying a type; it registers >> the name too so that misspelled names can be picked up very early rather >> than at runtime (and that's if you're lucky). >> > > I've said before that this, to me, is one of the major downsides of dynamic > typing. Once a statically typed language has been compiled the programmer > can head down to the pub. The programmer using dynamically typed languages > has to hang around doing long, boring, tedious testing. Unless they're > using an IDE like Pydev and have Pylint turned on so it picks up errors as > they type, in which case they can also head down to the pub. Type declarations are orthogonal to that. ECMAScript, as mentioned, just has 'var'. If it didn't have the implicit variables rule (anything not explicitly declared goes onto the primary object), it'd give you exactly that functionality, without any type checking at all. And there's not "static" and "dynamic". It's a spectrum. Each time you move one direction, you gain a set of potential bugs that the language can detect; each time you move the other direction, you save on keyboarding. But at no time do you truly get away from the need to test, because anything non-trivial can't be proven by the language anyway. ChrisA From steve+comp.lang.python at pearwood.info Tue Mar 4 09:25:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 14:25:15 GMT Subject: OT Sine Rule [was Re: Functional programming] References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5315e24a$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Mar 2014 00:01:01 +1100, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 10:47 PM, Steven D'Aprano > wrote: >> Not even close. I'd like to see the compiler that can work out for >> itself that this function is buggy: >> >> def sine_rule(side_a, side_b, angle_a): >> """Return the angle opposite side_b.""" return >> math.sin(side_b/side_a)*angle_a >> >> >> If you don't remember your Sine Rule from trigonometry, that's okay. >> Trust me, the function is badly wrong. It's rubbish really. > > I'm not entirely sure what it's trying to do, The Sine Rule applies to any triangle, right-angled or not. I'm not going to try to draw an ASCII-art triangle here, so you just have to imagine one. Label the three sides "a", "b" and "c". Now label the angle opposite each side as "A", "B" and "C", so angle A is opposite side a, and so forth. The Sine Rule, or Law of Sines, tells us that the ratio of the length of a side and the sine of the angle opposite that side is constant for any triangle. That is: a/sin(A) == b/sin(B) == c/sin(C) Given any two sides and one corresponding angle, let's say a, b and A, you can calculate the other angle B. The correct formula would be: B = asin( sin(A)*b/a ) which is not what my bogus function does. > but you're taking the sine > of a ratio. That... seems wrong, gut-feeling-wise. Well of course it's wrong. Given the intended geometric meanings of the function parameters, the quantity calculated is meaningless. But mathematically, it's okay to calculate the sine of a ratio of two other quantities. It's just a number. These even a whole lot of double-angle formulae that allow you to calculate sin(2*x) given sin(x), or sin(x/2) given sin(x), etc. But, giving that ratio physical or geometric meaning is another story, and in this case the semantics of the function is entirely bogus. That was my point -- the compiler cannot possibly tell what the function is intended to do, it can only check that it is self-consistent. > You take the sine of > an angle and get a ratio, or the arcsine of a ratio and get an angle. > Also, trig functions apply only to right triangles, Not quite. Or to put it another way, not at all :-) Trig functions are *defined* in terms of right-angled triangles, but (say) the sine of 30? is 0.5 regardless of whether that 30? angle is in a right-angled triangle, an acute triangle or an obtuse triangle. 30? is 30? regardless of what the rest of the triangle is doing. Ask-me-about-versine-and-haversine-ly y'rs, -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Tue Mar 4 09:27:05 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 14:27:05 GMT Subject: Origin of 'self' References: <7edah9989mdjb9mrnrsh5067np0ihv1jml@4ax.com> Message-ID: <5315e2b9$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 12:47:09 +0000, MRAB wrote: > In AppleScript a script can refer to the title of a window as "title of > window" or "window's title", and it can refer to the title of its own > window as "title of window of me" or "me's window's title". Consistent, > yes, but bad English. > > That's why I prefer a programming language not to be too much like a > natural language. :-) But the problem with that is not that it is too much like a natural language, but too little like a natural language. -- Steven D'Aprano http://import-that.dreamwidth.org/ From python.list at tim.thechases.com Tue Mar 4 09:37:21 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 4 Mar 2014 08:37:21 -0600 Subject: OT Sine Rule [was Re: Functional programming] In-Reply-To: <5315e24a$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315e24a$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140304083721.67f81d5d@bigbox.christie.dr> On 2014-03-04 14:25, Steven D'Aprano wrote: > Ask-me-about-versine-and-haversine-ly y'rs, More interested in a karosine, cuisine, and a limousine. ;-) -tkc From breamoreboy at yahoo.co.uk Tue Mar 4 09:42:23 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Mar 2014 14:42:23 +0000 Subject: OT Sine Rule [was Re: Functional programming] In-Reply-To: <20140304083721.67f81d5d@bigbox.christie.dr> References: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315e24a$0$29985$c3e8da3$5496439d@news.astraweb.com> <20140304083721.67f81d5d@bigbox.christie.dr> Message-ID: On 04/03/2014 14:37, Tim Chase wrote: > On 2014-03-04 14:25, Steven D'Aprano wrote: >> Ask-me-about-versine-and-haversine-ly y'rs, > > More interested in a karosine, cuisine, and a limousine. ;-) > > -tkc > > What do you get if you differentiate versines, haversines, karosines, cuisines and limosines? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Tue Mar 4 09:55:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 14:55:32 GMT Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5315e963$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 14:05:44 +0000, Mark Lawrence wrote: > Once a statically typed language has been compiled the programmer can > head down to the pub. "It compiles? Quick! Ship it!" Well, that certainly explains the quality of some programs... -- Steven D'Aprano http://import-that.dreamwidth.org/ From invalid at invalid.invalid Tue Mar 4 09:59:51 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 4 Mar 2014 14:59:51 +0000 (UTC) Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-03-03, Ben Finney wrote: > Gregory Ewing writes: > >> Just because the compiler *can* infer the return type doesn't >> necessarily mean it *should*. When I was playing around with >> functional languages, I ended up adopting the practice of always >> declaring the types of my functions, because it helps the *human* >> reader. > > Sure. In a duck-typed language like Python, it is still helpful to the > human reader to document the *meaning* of each parameter, beyond what is > indicated by the name. We have reStructuredText and docstrings for this > purpose. > > def frobnicate(flang, splets, queeble=False): > """ Righteously frobnicate the flang. > > :param flang: A file-like object, opened for reading. > :param splets: A sequence of unprocessed Splet instances. > :param queeble: If ``True``, re-vitrify the flang during > frobnication. > :return: A new list of processed Splet instances. > > The flang is frobnicated according to the Weebly-Ruckford > algorithm. > > """ > for line in flang: That's fine, if the comments are correct. I'm currently working with a library of third party code that was internally documented like that (though in a different language, with a slightly different comment formatting). Then they run it through something (Doxygen?) to produce a giant .CHM file that's pretty much useless to those of us running Linux. It turns out it's just as well I can't read a CHM file: the documentation in the comments is wrong often enough that I've learned it's best to ignore it completely. Sometimes the number of parameters and their names don't even match up with the comments. Sometimes the "docstring" is from a completely different function which was apparently cut/pasted and then reworked to do something else. After a couple decades of working in software development, I've decided that comments like that are not correct often enough to be useful. You've got to reverse-engineer the code if there's no such comment. If there _is_ a comment, you have to reverse-engineer the code to see of the comment is accurate. -- Grant Edwards grant.b.edwards Yow! I'm young ... I'm at HEALTHY ... I can HIKE gmail.com THRU CAPT GROGAN'S LUMBAR REGIONS! From rosuav at gmail.com Tue Mar 4 10:06:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 02:06:11 +1100 Subject: OT Sine Rule [was Re: Functional programming] In-Reply-To: <5315e24a$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315e24a$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 1:25 AM, Steven D'Aprano wrote: > > The Sine Rule, or Law of Sines, tells us that the ratio of the > length of a side and the sine of the angle opposite that side is constant > for any triangle. That is: > > a/sin(A) == b/sin(B) == c/sin(C) Oh! Right. Now I remember. Yeah. Still, it looks wrong to... well, what I said next: > On Wed, 05 Mar 2014 00:01:01 +1100, Chris Angelico wrote: >> but you're taking the sine >> of a ratio. That... seems wrong, gut-feeling-wise. > > Well of course it's wrong. Given the intended geometric meanings of the > function parameters, the quantity calculated is meaningless. But > mathematically, it's okay to calculate the sine of a ratio of two other > quantities. It's just a number. These even a whole lot of double-angle > formulae that allow you to calculate sin(2*x) given sin(x), or sin(x/2) > given sin(x), etc. What I meant there was "ratio of side lengths". The definition of sine is that, in a right triangle, the ratio of the lengths of the side opposite an angle and the hypotenuse is the sine of that angle. So I consider sine to be a function that takes an angle and returns a side-length-ratio, and arcsine does the reverse. It's like asking for the length of an integer and getting back a string - it just looks wrong. The sine of double an angle makes sense - it's still an angle. You don't multiply an angle by a side length, you don't take the sine of a number of meters per second, and you don't calculate the number of parsecs it takes you to get to Kessel. The units are just wrong. Maybe there's some specific situation where that makes sense, but I'd call it "formula smell". And note that your corrected form still applies the functions the way I describe - the units are maintained. (Technically the sine of an angle is a pure number, a straight ratio. I'm not sure that "pure number" is a unit - it's kinda the absence of any unit - but that's still something to be maintained.) > But, giving that ratio physical or geometric meaning is another story, > and in this case the semantics of the function is entirely bogus. That > was my point -- the compiler cannot possibly tell what the function is > intended to do, it can only check that it is self-consistent. Right. It's a consequence of a type system that distinguishes floating point from string, but not angle_in_degrees from length_in_meters. It's theoretically possible to build a type system that's like that (sometimes you can subclass to do that, and create explicit operations only), but I've never really felt the need to. But that's the theory behind some forms of Hungarian notation - identifying a "data type" concept that's broader than the compiler knows. >> You take the sine of >> an angle and get a ratio, or the arcsine of a ratio and get an angle. >> Also, trig functions apply only to right triangles, > > Not quite. Or to put it another way, not at all :-) > > Trig functions are *defined* in terms of right-angled triangles, but > (say) the sine of 30? is 0.5 regardless of whether that 30? angle is in a > right-angled triangle, an acute triangle or an obtuse triangle. 30? is > 30? regardless of what the rest of the triangle is doing. Yes indeed. Like I said, I'm a bit rusty on all that, and forgot about the ways of using them in non-right triangles :) But that 0.5 doesn't have intrinsic meaning if you don't have a right triangle around it; it needs something else to give it useful meaning, like another angle's sine. ChrisA From rosuav at gmail.com Tue Mar 4 10:13:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 02:13:03 +1100 Subject: Functional programming In-Reply-To: <5315e963$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315e963$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 1:55 AM, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 14:05:44 +0000, Mark Lawrence wrote: > >> Once a statically typed language has been compiled the programmer can >> head down to the pub. > > "It compiles? Quick! Ship it!" > > Well, that certainly explains the quality of some programs... It explains the quality of other programs too. They were written after the programmer came back from the pub. *ducks for cover* ChrisA From malaclypse2 at gmail.com Tue Mar 4 10:19:22 2014 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 4 Mar 2014 10:19:22 -0500 Subject: Reference In-Reply-To: <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Mar 3, 2014 at 11:52 PM, Steven D'Aprano wrote: > If your intention is to treat None as a singleton sentinel, not as a > value, then you ought to use "is" to signal that intention, rather than > using == even if you know that there won't be any false positives. In all of the years I've been on this list, I don't think I've seen more than one or two cases of someone deliberately treating None as a singleton sentinel. In most cases, they're either checking the return value from a function or using it as a default argument to a function to force some default behavior when no parameter is passed. I'm pretty sure you're going to say that the latter use is exactly where you should us 'is' instead of '=='. Respectfully, I disagree. For a beginning python user, identity checking is an attractive nuisance. The only time most beginners should use it is when comparing to None. But, as soon as they are taught that there are two comparison operators, I start to see 'is' cropping up in more and more places where they ought to use '=='. And the problem is that sometimes it works for them, and sometimes it doesn't. Sure, students eventually need to understand the difference between identity and equality. My problem is that by enshrining in python custom that the only correct way to compare to None is with 'is', we have to explain that concept way early in the teaching process. I can't count the number of times that a thread has completely derailed into identity vs equality, then into interning of strings and small integers, and suddenly the thread is 40 messages long, and no one has actually talked about the code that was originally posted beyond that issue. In approximately zero cases, have I seen code where 'is' versus '==' actually made any difference, except where the 'is' is wrong. I've also never seen the supposedly ever-present boogie man of an object that mistakenly compares equal to None, much less seen that object passed to functions with None-based sentinels. I feel like 'is' is an operator that ought to be saved for an advanced course. Out of curiosity, do you think we should be doing truth checking with 'is'? True and False are singletons, and it seems to me that the justification for idenity versus equality should be just as strong there, but I don't think I've ever seen anyone even suggest that. -- Jerry From steve+comp.lang.python at pearwood.info Tue Mar 4 10:18:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 15:18:24 GMT Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 13:30:04 +0000, BartC wrote: > "Steven D'Aprano" wrote in message > news:53159540$0$2923$c3e8da3$76491128 at news.astraweb.com... > >> It's that "explicitly" part that doesn't follow. Having to manage types >> is the most tedious, boring, annoying, *unproductive* part of languages >> like Java, C and Pascal. Almost always, you're telling the compiler >> stuff that it can work out for itself. > > Isn't creating classes in Python similar to creating types elsewhere? Depends on the type: I suppose you can draw an analogy between records or structs and classes with no methods. But I'm not talking about creating types, I'm talking about type declarations. int x=2; # 2 is an int? Who would have guessed! >> In the same way that managing jumps for GOTO has been automated with >> for loops, while, etc., and managing memory has been automated, there's >> no good reason not to allow the compiler to manage types. Dynamically >> typed languages like Python do so at runtime. Type inference simply >> allows statically typed languages to do the same only at compile time. > > Eliminating 'goto' is simple code-generation logic; type inference is > more of an art. Type inference is nothing like an art. It's a mathematically provable correct algorithm from the lambda calculus. http://en.wikipedia.org/wiki/Hindley%E2%80%93Milner Unfortunately the wikipedia page above appears to be complete gobbledygook if you aren't an expert in the lambda calculus, which I certainly am not, so I'm not even going to try to explain how it works. But there is no *guessing* involved, no heuristics which only sometimes work. There are certain assumptions involved, e.g. that the type of something is, in the absence of a declaration otherwise, the *most* general thing it could be (e.g. "it's an integer" rather than "it's an integer between 3 and 27"). But they're reasonable, practical assumptions. > But declaring variables is not just about specifying a type; it > registers the name too so that misspelled names can be picked up very > early rather than at runtime (and that's if you're lucky). You don't need to have static typing to have declared variables. The two are independent. E.g. one might have a system like Python, except you have to declare your variables before using them: global x local a a = x+1 ... Or a system like (ancient) BASIC, where the type of the variable is given by the name. E.g. X is a numeric variable, and X$ is a string variable. There's no need for a separate declaration, because the presence or absence of the $ sign tells the interpreter whether it is a number or string variable. Perl, PHP and many other languages also use sigils. Having to declare variables, and having to declare their type, are independent. -- Steven D'Aprano http://import-that.dreamwidth.org/ From python.list at tim.thechases.com Tue Mar 4 10:21:32 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 4 Mar 2014 09:21:32 -0600 Subject: OT Sine Rule [was Re: Functional programming] In-Reply-To: References: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315e24a$0$29985$c3e8da3$5496439d@news.astraweb.com> <20140304083721.67f81d5d@bigbox.christie.dr> Message-ID: <20140304092132.523e6440@bigbox.christie.dr> On 2014-03-04 14:42, Mark Lawrence wrote: > What do you get if you differentiate versines, haversines, > karosines, cuisines and limosines? Well, with cuisines, you can usually differentiate by seasoning: your Tex/Mex is spicier and tends to have chili & cumin, while your Indian tends to lean more towards the garam masala. With your limosines, you have stretch and non-stretch, and some are these crazy contraptions made out of Hummers or buses rather than luxury sedans. And if I could spell "kerosine" instead of "karosine", I guess they would differentiate from other hydrocarbons by the length of the carbon chain. ;-) -tkc From juraj.ivancic at gmail.com Tue Mar 4 10:23:32 2014 From: juraj.ivancic at gmail.com (=?ISO-8859-2?Q?Juraj_Ivan=E8i=E6?=) Date: Tue, 04 Mar 2014 16:23:32 +0100 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: On 3.3.2014. 2:27, Ian Kelly wrote: > Python 3.3 has a C API function to create a memoryview for a char*, > that can be made read-only. > > http://docs.python.org/3/c-api/memoryview.html#PyMemoryView_FromMemory > > I don't see a way to do what you want in pure Python, apart from > perhaps writing an elaborate proxy class that would just be a poor > man's memoryview. Or you could bite the bullet and copy everything > once at the start to create a bytes object, and then never have to > worry about it again. Just for reference, it is doable in pure Python, with ctypes help: pydll = ctypes.cdll.LoadLibrary("python{}{}".format( sys.version_info.major, sys.version_info.minor)) def ro_memoryview_from_bytearray(buffer): assert isinstance(buffer, bytearray) ptr = ctypes.c_char_p(pydll.PyByteArray_AsString( ctypes.py_object(buffer))) mv_id = pydll.PyMemoryView_FromMemory(ptr, len(buffer), 0) return ctypes.cast(mv_id, py_object).value Note that this is just the jist, in real code I added safeguards to prevent misuse of the (temporary) memoryview. From steve+comp.lang.python at pearwood.info Tue Mar 4 10:22:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 15:22:52 GMT Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5315efcc$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 14:59:51 +0000, Grant Edwards wrote: > After a couple decades of working in software development, I've decided > that comments like that are not correct often enough to be useful. > You've got to reverse-engineer the code if there's no such comment. If > there _is_ a comment, you have to reverse-engineer the code to see of > the comment is accurate. http://import-that.dreamwidth.org/956.html -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue Mar 4 10:25:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 02:25:57 +1100 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 2:19 AM, Jerry Hill wrote: > Out of curiosity, do you think we should be doing truth checking with > 'is'? True and False are singletons, and it seems to me that the > justification for idenity versus equality should be just as strong > there, but I don't think I've ever seen anyone even suggest that. Normal truth testing is done like this: if cond: This isn't truth testing, this is checking the identity of what's in cond: if cond is True: And that's specifically testing for something much tighter than truthiness. As you can see from my stats above, that's actually fairly rare. Usually you'd just accept that True, 1, "yes", [1,2,3], and 1.2345 are all equally true. ChrisA From rosuav at gmail.com Tue Mar 4 10:28:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 02:28:17 +1100 Subject: Functional programming In-Reply-To: <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 2:18 AM, Steven D'Aprano wrote: > You don't need to have static typing to have declared variables. The two > are independent. E.g. one might have a system like Python, except you > have to declare your variables before using them: > > global x > local a > a = x+1 Aside: If you declare your locals, you shouldn't need to declare your globals. Though I could imagine a rule that global rebinding still needs to be declared, but you certainly shouldn't need to declare nonlocal if you have a local declaration. Absence of local => nonlocal. ChrisA From __peter__ at web.de Tue Mar 4 10:30:51 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 04 Mar 2014 16:30:51 +0100 Subject: Logging References: Message-ID: Igor Korot wrote: > Hi, ALL, > Could someone please explain to me how the code in > http://docs.python.org/2/howto/logging#logging-from-multiple-modules > works? > In particular I'm interested in how the mylib.py knows about the > myapp.log. > > What I mean is: logging object is not passed to mylib.py, so > essentially it should create a new instance of the logging object. > > What am I missing? loggers are cached and organized in a tree. If you ask for a logger abc = logging.getLogger("a.b.c") you get the same logger every time. At the top of the tree there is the root logger >>> import logging >>> root = logging.getLogger() >>> abc = logging.getLogger("a.b.c") >>> ab = logging.getLogger("a.b") >>> a = logging.getLogger("a") >>> abc.parent is ab True >>> ab.parent is a True >>> a.parent is root True >>> logging.getLogger("a.b.c") is abc True >>> logging.info(...) is basically a shortcut for root.info(...) that also does a basicConfig() if necessary. By default loggers delegate handling log messages to their parent. You only have to tell the root logger what to do with the incoming messages. There are optimizations (placeholders for the intermediate loggers), but the above is the basic concept. > But this question comes from the following fact about my application. > I tried to create a logging object which will store the logging > information to the file in the main class. Then I pass this object to > another class constructor and use it in that second class. > > Upon running everything is OK, but when the program successfully > finishes, the log file has 0 length. > > AFAIU, I'm doing it properly and the example referenced is wrong, yet > the results are completely different. > > Thank you for any expplanation. Did you run the example consisting of myapp.py and myapp.lib? Did it work? If so, what did you differently in your real app? Please provide a minimal example showing the unexpected behaviour. From steve+comp.lang.python at pearwood.info Tue Mar 4 10:42:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 15:42:03 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5315f44a$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 10:19:22 -0500, Jerry Hill wrote: > On Mon, Mar 3, 2014 at 11:52 PM, Steven D'Aprano > wrote: >> If your intention is to treat None as a singleton sentinel, not as a >> value, then you ought to use "is" to signal that intention, rather than >> using == even if you know that there won't be any false positives. > > In all of the years I've been on this list, I don't think I've seen more > than one or two cases of someone deliberately treating None as a > singleton sentinel. In most cases, they're either checking the return > value from a function Okay, that's not *precisely* a sentinel, but it's related. I don't know what to call that, but it's a sentinel applied to the return result rather than to an input parameter. > or using it as a default argument to a function to > force some default behavior when no parameter is passed. I call that a sentinel. It doesn't match the Wikipedia definition of a sentinel, but I think that's wrong. What Wikipedia calls a sentinel, I would call a guard. http://en.wikipedia.org/wiki/Sentinel_value > I'm pretty > sure you're going to say that the latter use is exactly where you should > us 'is' instead of '=='. Yes. > Respectfully, I disagree. > > For a beginning python user, identity checking is an attractive > nuisance. True. In Hypertalk, which was designed for non-coders, the "is" operator was a synonym for "==". Even after nearly 20 years of using Python, I still sometimes instinctively write "x is y" when I mean equality, especially the "if __name__ is __main__" idiom. > The only time most beginners should use it is when comparing > to None. We're agreed on that. > But, as soon as they are taught that there are two comparison > operators, I start to see 'is' cropping up in more and more places where > they ought to use '=='. And the problem is that sometimes it works for > them, and sometimes it doesn't. Sure, students eventually need to > understand the difference between identity and equality. My problem is > that by enshrining in python custom that the only correct way to compare > to None is with 'is', we have to explain that concept way early in the > teaching process. I can't count the number of times that a thread has > completely derailed into identity vs equality, then into interning of > strings and small integers, and suddenly the thread is 40 messages long, > and no one has actually talked about the code that was originally posted > beyond that issue. Heh heh, welcome to the Internet. > In approximately zero cases, have I seen code where > 'is' versus '==' actually made any difference, except where the 'is' is > wrong. I've also never seen the supposedly ever-present boogie man of > an object that mistakenly compares equal to None, much less seen that > object passed to functions with None-based sentinels. > > I feel like 'is' is an operator that ought to be saved for an advanced > course. > > Out of curiosity, do you think we should be doing truth checking with > 'is'? True and False are singletons, and it seems to me that the > justification for idenity versus equality should be just as strong > there, but I don't think I've ever seen anyone even suggest that. Normally you shouldn't compare to True or False at all. Python duck-types truth-values, or to put it another way, you should normally only care about truthy and falsey values: # Duck-typing is your friend if flag: ... # These are buggy unless you know flag is an actual bool if flag == True: ... if flag is True: ... # Why convert to a canonical bool flag just to do a comparison? if bool(flag): ... # Not this if bool(flag) is True: # I never know when to stop if bool(flag) is True is True is True is True is True is True: ... -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Tue Mar 4 10:45:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2014 15:45:51 GMT Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5315f52f$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Mar 2014 02:28:17 +1100, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 2:18 AM, Steven D'Aprano > wrote: >> You don't need to have static typing to have declared variables. The >> two are independent. E.g. one might have a system like Python, except >> you have to declare your variables before using them: >> >> global x >> local a >> a = x+1 > > Aside: If you declare your locals, you shouldn't need to declare your > globals. Though I could imagine a rule that global rebinding still needs > to be declared, but you certainly shouldn't need to declare nonlocal if > you have a local declaration. Absence of local => nonlocal. You missed that the purpose of the declaration is to avoid accidental typos: local process procces = 1234 With declarations, the compiler can catch some typos at compile-time. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue Mar 4 11:02:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 03:02:24 +1100 Subject: Reference In-Reply-To: <5315f44a$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <5315f44a$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 2:42 AM, Steven D'Aprano wrote: > # I never know when to stop > if bool(flag) is True is True is True is True is True is True: ... The banana problem. ChrisA From rosuav at gmail.com Tue Mar 4 11:04:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 03:04:36 +1100 Subject: Functional programming In-Reply-To: <5315f52f$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315f52f$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 2:45 AM, Steven D'Aprano wrote: >> Aside: If you declare your locals, you shouldn't need to declare your >> globals. Though I could imagine a rule that global rebinding still needs >> to be declared, but you certainly shouldn't need to declare nonlocal if >> you have a local declaration. Absence of local => nonlocal. > > You missed that the purpose of the declaration is to avoid accidental > typos: > > local process > procces = 1234 > > > With declarations, the compiler can catch some typos at compile-time. Yep, but if you're declaring all your locals (and globals get declared at module scope - they're just local to a different and broader scope), then "procces" will never have been declared anywhere. You shouldn't need to re-declare everything you're referencing from an outer scope. ChrisA From __peter__ at web.de Tue Mar 4 11:05:50 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 04 Mar 2014 17:05:50 +0100 Subject: Decoding a process output References: Message-ID: Francis Moreau wrote: > Hi, > > In my understanding (I'm relatively new to python), I need to decode any > bytes data provided, in my case, by a shell command (such as findmnt) > started by the subprocess module. The goal of my application is to parse > the command outputs. > > My application runs only on linux BTW and should run fine on both python > 2.7 and py3k. > > My question is when decoding the output bytes data of the external > command, which encoding should I use ? > > Should I guess the encoding by inspecting LANG or any LC_* environment > variables ? > > Should I force one of those environment variable to a specific value > before running my external command ? > > Thanks for any tips. You can use locale.getpreferredencoding(), which seems to evaluate LANG: $ python3 -c 'import locale; print(locale.getpreferredencoding())' UTF-8 $ LANG= python3 -c 'import locale; print(locale.getpreferredencoding())' ANSI_X3.4-1968 I haven't seen a Linux system that doesn't use UTF-8 for a while, but you have to remember that filenames are still arbitrary byte sequences. You can cope with this in Python by not decoding the bytes or using surrogateescape >>> os.mkdir(bytes([i for i in range(1, 256) if i != b"/"[0]])) >>> os.listdir(b".") [b'\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-.0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'] >>> os.listdir(".") ['\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-.0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\udc80\udc81\udc82\udc83\udc84\udc85\udc86\udc87\udc88\udc89\udc8a\udc8b\udc8c\udc8d\udc8e\udc8f\udc90\udc91\udc92\udc93\udc94\udc95\udc96\udc97\udc98\udc99\udc9a\udc9b\udc9c\udc9d\udc9e\udc9f\udca0\udca1\udca2\udca3\udca4\udca5\udca6\udca7\udca8\udca9\udcaa\udcab\udcac\udcad\udcae\udcaf\udcb0\udcb1\udcb2\udcb3\udcb4\udcb5\udcb6\udcb7\udcb8\udcb9\udcba\udcbb\udcbc\udcbd\udcbe\udcbf\udcc0\udcc1\udcc2\udcc3\udcc4\udcc5\udcc6\udcc7\udcc8\udcc9\udcca\udccb\udccc\udccd\udcce\udccf\udcd0\udcd1\udcd2\udcd3\udcd4\udcd5\udcd6\udcd7\udcd8\udcd9\udcda\udcdb\udcdc\udcdd\udcde\udcdf\udce0\udce1\udce2\udce3\udce4\udce5\udce6\udce7\udce8\udce9\udcea\udceb\udcec\udced\udcee\udcef\udcf0\udcf1\udcf2\udcf3\udcf4\udcf5\udcf6\udcf7\udcf8\udcf9\udcfa\udcfb\udcfc\udcfd\udcfe\udcff'] However, the typical shell tools have problems with names containing a newline or even space (and if not you may introduce such problems parsing the tool's output), so I'd like to see how findmnt responds to a mount point like the above directory. From roy at panix.com Tue Mar 4 11:14:13 2014 From: roy at panix.com (Roy Smith) Date: Tue, 04 Mar 2014 11:14:13 -0500 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <5315f44a$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Wed, Mar 5, 2014 at 2:42 AM, Steven D'Aprano > wrote: > > # I never know when to stop > > if bool(flag) is True is True is True is True is True is True: ... > > The banana problem. > > ChrisA You can refactor that as: eval(" is ".join(itertools.chain(["if bool(flag)"], [str(t) for t in itertools.repeat(True)]))) From stefan_ml at behnel.de Tue Mar 4 11:19:52 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 04 Mar 2014 17:19:52 +0100 Subject: how to get bytes from bytearray without copying In-Reply-To: References: Message-ID: Juraj Ivan?i?, 04.03.2014 16:23: > Just for reference, it is doable in pure Python, with ctypes help For some questionable meaning of "pure". Stefan From rustompmody at gmail.com Tue Mar 4 11:24:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 08:24:22 -0800 (PST) Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tuesday, March 4, 2014 8:49:22 PM UTC+5:30, Jerry Hill wrote: > On Mon, Mar 3, 2014 at 11:52 PM, Steven D'Aprano wrote: > > If your intention is to treat None as a singleton sentinel, not as a > > value, then you ought to use "is" to signal that intention, rather than > > using == even if you know that there won't be any false positives. > In all of the years I've been on this list, I don't think I've seen > more than one or two cases of someone deliberately treating None as a > singleton sentinel. In most cases, they're either checking the return > value from a function or using it as a default argument to a function > to force some default behavior when no parameter is passed. I'm > pretty sure you're going to say that the latter use is exactly where > you should us 'is' instead of '=='. Respectfully, I disagree. > For a beginning python user, identity checking is an attractive > nuisance. The only time most beginners should use it is when comparing > to None. But, as soon as they are taught that there are two > comparison operators, I start to see 'is' cropping up in more and more > places where they ought to use '=='. And the problem is that > sometimes it works for them, and sometimes it doesn't. Sure, students > eventually need to understand the difference between identity and > equality. My problem is that by enshrining in python custom that the > only correct way to compare to None is with 'is', we have to explain > that concept way early in the teaching process. I can't count the > number of times that a thread has completely derailed into identity vs > equality, then into interning of strings and small integers, and > suddenly the thread is 40 messages long, and no one has actually > talked about the code that was originally posted beyond that issue. > In approximately zero cases, have I seen code where 'is' versus '==' > actually made any difference, except where the 'is' is wrong. I've > also never seen the supposedly ever-present boogie man of an object > that mistakenly compares equal to None, much less seen that object > passed to functions with None-based sentinels. Beautifully put -- thanks Jerry! > I feel like 'is' is an operator that ought to be saved for an advanced course. +100 My choice: have an isNone function which should take care of 90% of the cases of valid 'is' (if I got Chris' statistics right) and avoid most of the metaphysical BS about identity From sffjunkie at gmail.com Tue Mar 4 11:41:16 2014 From: sffjunkie at gmail.com (sffjunkie at gmail.com) Date: Tue, 4 Mar 2014 08:41:16 -0800 (PST) Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> Message-ID: <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> On Monday, 3 March 2014 22:55:32 UTC, Chris Kaynor wrote: > You can go much simpler than that. Merely port Python to LISP, then write a LISP interpreter in Python. Done. http://blog.pault.ag/post/46982895940/heres-my-talk-from-pycon-2013-i-tried-to-queue From donarb at nwlink.com Tue Mar 4 11:45:09 2014 From: donarb at nwlink.com (donarb) Date: Tue, 4 Mar 2014 08:45:09 -0800 (PST) Subject: modification time in Python - Django: datetime != datetime :-( In-Reply-To: References: <20140303133541.66fccbbb@lia.custard.shrl.nl> <04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com> Message-ID: Note that it's bad form to post the same question to different forums, you also posted this question to django-users. By posting to multiple forums, you run the risk of not having the question answered or followed up in one of the forums. This frustrates other users who may one day have a similar problem and find your orphaned question. Remember, these forums are not just about you, they are also about those who follow later. From python at mrabarnett.plus.com Tue Mar 4 12:07:15 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Mar 2014 17:07:15 +0000 Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315e963$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53160843.9090406@mrabarnett.plus.com> On 2014-03-04 15:13, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 1:55 AM, Steven D'Aprano > wrote: >> On Tue, 04 Mar 2014 14:05:44 +0000, Mark Lawrence wrote: >> >>> Once a statically typed language has been compiled the programmer can >>> head down to the pub. >> >> "It compiles? Quick! Ship it!" >> >> Well, that certainly explains the quality of some programs... > > It explains the quality of other programs too. They were written after > the programmer came back from the pub. > > *ducks for cover* > Or compiled before and tested after? From rosuav at gmail.com Tue Mar 4 12:07:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 04:07:44 +1100 Subject: How security holes happen In-Reply-To: <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> Message-ID: On Wed, Mar 5, 2014 at 3:41 AM, wrote: > On Monday, 3 March 2014 22:55:32 UTC, Chris Kaynor wrote: >> You can go much simpler than that. Merely port Python to LISP, then write a LISP interpreter in Python. Done. > > http://blog.pault.ag/post/46982895940/heres-my-talk-from-pycon-2013-i-tried-to-queue I don't have time to watch an hour-long video... what'd he do, exactly that? ChrisA From python at mrabarnett.plus.com Tue Mar 4 12:10:10 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Mar 2014 17:10:10 +0000 Subject: Origin of 'self' In-Reply-To: <5315e2b9$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <7edah9989mdjb9mrnrsh5067np0ihv1jml@4ax.com> <5315e2b9$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <531608F2.4080302@mrabarnett.plus.com> On 2014-03-04 14:27, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 12:47:09 +0000, MRAB wrote: > >> In AppleScript a script can refer to the title of a window as >> "title of window" or "window's title", and it can refer to the >> title of its own window as "title of window of me" or "me's >> window's title". Consistent, yes, but bad English. >> >> That's why I prefer a programming language not to be too much like >> a natural language. :-) > > But the problem with that is not that it is too much like a natural > language, but too little like a natural language. > The more it's like a natural language, the more intelligent you expect it to be, and the more you expect it to be able to work out ambiguities for itself. From python at mrabarnett.plus.com Tue Mar 4 12:12:16 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Mar 2014 17:12:16 +0000 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <5315f44a$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53160970.2090705@mrabarnett.plus.com> On 2014-03-04 16:02, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 2:42 AM, Steven D'Aprano > wrote: >> # I never know when to stop >> if bool(flag) is True is True is True is True is True is True: ... > > The banana problem. > Speaking of which: The 'right' way to peel a banana http://www.telegraph.co.uk/news/good-to-share/10664935/The-right-way-to-peel-a-banana.html From skip at pobox.com Tue Mar 4 12:16:49 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 4 Mar 2014 11:16:49 -0600 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 11:07 AM, Chris Angelico wrote: > I don't have time to watch an hour-long video... what'd he do, exactly that? If you fast forward to 16:14, his talk is about five minutes long. He wrote a Lisp compiler whose backend is Python. Skip From roy at panix.com Tue Mar 4 12:43:41 2014 From: roy at panix.com (Roy Smith) Date: Tue, 04 Mar 2014 12:43:41 -0500 Subject: modification time in Python - Django: datetime != datetime :-( References: <20140303133541.66fccbbb@lia.custard.shrl.nl> <04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com> Message-ID: In article , donarb wrote: > Note that it's bad form to post the same question to different forums, you > also posted this question to django-users. By posting to multiple forums, you > run the risk of not having the question answered or followed up in one of the > forums. This frustrates other users who may one day have a similar problem > and find your orphaned question. Even worse, you run the risk of having it answered differently in different places, and then you need to figure out which is right :-) From marko at pacujo.net Tue Mar 4 14:49:03 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 04 Mar 2014 21:49:03 +0200 Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <87iortoic0.fsf@elektro.pacujo.net> Chris Angelico : > As far as I know, there's no simple way, in constant space and/or > time, to progressively yield more digits of a number's square root, > working in decimal. I don't know why the constant space/time requirement is crucial. Anyway, producing more digits simple: . I believe producing the nth digit is O(n) in time and space. Still, there's more to arithmetics than that. For example, if you have two generated decimal expansions, you don't have an effective algorithm to generate the decimal expansion of their ratio. That's because there's no effective algorithm to decide if a < b. Marko From marko at pacujo.net Tue Mar 4 14:49:13 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 04 Mar 2014 21:49:13 +0200 Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <87bnxloibq.fsf@elektro.pacujo.net> Antoon Pardon : > In the same way writing unit tests is the most tedious, boring, > annoying, *unproductive* part. Amost always you are giving the program > results it can work out for itself. Undoubtedly, explicit type declarations add a dimension of quality to software. However, they also significantly reduce readability and tempt you to dirty shortcuts (to avoid writing truckloads of boilerplate code). On the balance, I estimate the explicit style reduces code quality. Example (found by a random Google search): ===JAVA BEGIN=========================================================== class WrappedSqlException extends RuntimeException { static final long serialVersionUID = 20130808044800000L; public WrappedSqlException(SQLException cause) { super(cause); } public SQLException getSqlException() { return (SQLException) getCause(); } } public ConnectionPool(int maxConnections, String url) throws SQLException { try { super(() -> { try { return DriverManager.getConnection(url); } catch ( SQLException ex ) { throw new WrappedSqlException(ex); } }, maxConnections); } catch (WrappedSqlException wse) { throw wse.getSqlException(); } } ===JAVA END============================================================= ===PYTHON BEGIN========================================================= def __init__(self, max_connections, url): super().__init__(lambda: DriverManager.get_connection(url), max_connections) ===PYTHON END=========================================================== or, a bit less cryptically: ===PYTHON BEGIN========================================================= def __init__(self, max_connections, url): def get_connection(): return DriverManager.get_connection(url) super().__init__(get_connection, max_connections) ===PYTHON END=========================================================== Marko From rosuav at gmail.com Tue Mar 4 14:58:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 06:58:23 +1100 Subject: Working with the set of real numbers In-Reply-To: <87iortoic0.fsf@elektro.pacujo.net> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> As far as I know, there's no simple way, in constant space and/or >> time, to progressively yield more digits of a number's square root, >> working in decimal. > > I don't know why the constant space/time requirement is crucial. Anyway, > producing more digits simple: . > > I believe producing the nth digit is O(n) in time and space. The reason for striving for constant space/time is because the obvious method (cut-and-try) is already O(n) for the nth digit, which means it's quadratic on the number of digits desired. That gets pretty nasty. So what I was asking was: By representing values as continued fractions rather than as decimal digits, are you able to perform a straight-forward transformation that produces the square root, in constant time (which means linear in the length)? And I guess the answer's no. CF representation doesn't have the advantage I was wondering about. ChrisA From rosuav at gmail.com Tue Mar 4 15:01:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 07:01:54 +1100 Subject: Functional programming In-Reply-To: <87bnxloibq.fsf@elektro.pacujo.net> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa wrote: > public ConnectionPool(int maxConnections, String url) throws SQLException { > try { > super(() -> { > try { > return DriverManager.getConnection(url); > } catch ( SQLException ex ) { > throw new WrappedSqlException(ex); > } > }, maxConnections); > } catch (WrappedSqlException wse) { > throw wse.getSqlException(); > } > } > > ===JAVA END============================================================= > > ===PYTHON BEGIN========================================================= > > def __init__(self, max_connections, url): > super().__init__(lambda: DriverManager.get_connection(url), max_connections) You're not doing the same thing, though. The Java rigmarole is to ensure that an SQLException thrown in getConnection will propagate up, despite (presumably) something inside the equivalent of super().__init__ that swallows SQLExceptions. Of course it looks tidier when you don't do the messy bit. ChrisA From thrinassodon at thrinassodon.thrinassodon Tue Mar 4 15:02:53 2014 From: thrinassodon at thrinassodon.thrinassodon (Thrinazodji0fecnfv) Date: Tue, 04 Mar 2014 15:02:53 -0500 Subject: NEW RESEARCH TEARS PALAEOANTHROPOLOGY APART: THE THRINAXODON TIMES Message-ID: =============== >BREAKING NEWS! =============== NEW YORK TIMES, THRINAXODON, OHIO ===================== > THRINAXODON RECENTLY FOUND 3 HUMAN FOSSILS FROM DEVONIAN STRATA FROM GREENLAND, THE EVOLUTIONISTS HAVE NO BONES ABOUT. > ONE EVIL EVOLUTIONIST, BOB CASANOVA HAS ADMITTED THAT HUMAN EVOLUTION IS IN FREE-FALL. > RICHARD LEAKEY HAS DIED FROM A HEART ATTACK DUE TO THIS GROUND-BREAKING FIND THAT CONCLUSIVELY SHOWS THAT HUMANS HAVE ORIGINS IN THE DEVONIAN. > NOW, IF YOU PLEASE, I HAVE TO SUE THE SMITHSONIAN FOR YEARS OF CENSORSHIP. > ====================================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# -- ---Thrinaxodon From ned at nedbatchelder.com Tue Mar 4 15:47:26 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 04 Mar 2014 15:47:26 -0500 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> Message-ID: On 3/4/14 12:16 PM, Skip Montanaro wrote: > On Tue, Mar 4, 2014 at 11:07 AM, Chris Angelico wrote: >> I don't have time to watch an hour-long video... what'd he do, exactly that? > > If you fast forward to 16:14, his talk is about five minutes long. He > wrote a Lisp compiler whose backend is Python. > > Skip > It's Hy: http://hylang.org -- Ned Batchelder, http://nedbatchelder.com From marko at pacujo.net Tue Mar 4 15:50:30 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 04 Mar 2014 22:50:30 +0200 Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> Message-ID: <8738ixofhl.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa wrote: >> public ConnectionPool(int maxConnections, String url) throws SQLException { >> try { >> super(() -> { >> try { >> return DriverManager.getConnection(url); >> } catch ( SQLException ex ) { >> throw new WrappedSqlException(ex); >> } >> }, maxConnections); >> } catch (WrappedSqlException wse) { >> throw wse.getSqlException(); >> } >> } >> >> ===JAVA END============================================================= > > You're not doing the same thing, though. The Java rigmarole is to > ensure that an SQLException thrown in getConnection will propagate up, > despite (presumably) something inside the equivalent of > super().__init__ that swallows SQLExceptions. Of course it looks > tidier when you don't do the messy bit. See . The "rigmarole" is trying to get around Java's mandatory exception handling limitations, which Python doesn't have. You are not allowed to pass a lambda to the super constructor that throws an SQLException. To get around the limitation, a RuntimeException wrapper is created to smuggle the SQLException through the compiler's defenses. Any code is free to throw a RuntimeException. I don't know, though, if this is that good of an example. I don't know if the lambda gets called within the constructor or, as I would guess, whenever a new connection is needed. The whole wrapping exercise would be for nothing, then. Here's a more prosaic example (probably contains errors): ===JAVA BEGIN=========================================================== private Map> filings = new TreeMap>(); class FormFiling { public FormFiling(TaxpayerIdNumber taxpayerId, Form form) { this.taxpayerId = taxpayerId; this.form = form; } public TaxpayerIdNumber getTaxpayerId() { return taxpayerId; } public Form getForm() { return form; } private TaxpayerIdNumber taxpayerId; private Form form; }; List getForms(FormId formId) { List forms = new LinkedList(); for (Map.Entry> payerEntry : filings.entrySet()) { TaxpayerIdNumber taxpayerId = payerEntry.getKey(); Map filing = payerEntry.getValue(); if (filing.containsKey(formId)) forms.add(new FormFiling(taxpayerId, filing.get(formId))) } return forms; } ===JAVA END============================================================= ===PYTHON BEGIN========================================================= filings = {} def getForms(formId): forms = [] for taxpayerId, filing in filings.iteritems(): if formId in filing: forms.append((taxpayerId, filing[formId])) return forms ===PYTHON END=========================================================== or: ===PYTHON BEGIN========================================================= filings = {} def getForms(formId): return ((taxpayerId, filing[formId]) for (taxpayerId, filing) in filings.iteritems() if formId in filing) ===PYTHON END=========================================================== Marko From oscar.j.benjamin at gmail.com Tue Mar 4 15:55:33 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 4 Mar 2014 20:55:33 +0000 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On 4 March 2014 19:58, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> As far as I know, there's no simple way, in constant space and/or >>> time, to progressively yield more digits of a number's square root, >>> working in decimal. >> >> I don't know why the constant space/time requirement is crucial. Anyway, >> producing more digits simple: . >> >> I believe producing the nth digit is O(n) in time and space. > > The reason for striving for constant space/time is because the obvious > method (cut-and-try) is already O(n) for the nth digit, which means > it's quadratic on the number of digits desired. That gets pretty > nasty. I don't quite follow your reasoning here. By "cut-and-try" do you mean bisection? If so it gives the first N decimal digits in N*log2(10) iterations. However each iteration requires a multiply and when the number of digits N becomes large the multiplication is worse than linear. So the result is something like N**2 log(N)log(log(N)), To me the obvious method is Newton iteration which takes O(sqrt(N)) iterations to obtain N digits of precision. This brings the above complexity below quadratic: #!/usr/bin/env python from decimal import Decimal as D, localcontext def sqrt(y, prec=1000): '''Solve x**2 = y''' assert y > 0 eps = D(10) ** -(prec + 5) x = D(y) with localcontext() as ctx: ctx.prec = prec + 10 while x ** 2 - y > x * eps: x = (x + y/x) / 2 return x print(sqrt(2)) Some modification would be required to handle a situation where it ends in a run of nines or zeros if you really care about the exact digits rather than having a bounded error. Oscar From ikorot01 at gmail.com Tue Mar 4 15:57:08 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 4 Mar 2014 12:57:08 -0800 Subject: Proper conversion of timestamp Message-ID: Hi, ALL, I'm getting this: timestamp out of range for platform localtime()/gmtime() function trying to convert the timestamp with milliseconds into the datetime object. The first hit of Google gives me this: http://stackoverflow.com/questions/12458595/convert-epoch-timestamp-in-python but the solution described is not good for me since it does not gives me the milliseconds value. How do I get the proper datetime value including milliseconds from the timestamp? Thank you. From rosuav at gmail.com Tue Mar 4 16:06:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 08:06:17 +1100 Subject: Functional programming In-Reply-To: <8738ixofhl.fsf@elektro.pacujo.net> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> <8738ixofhl.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 7:50 AM, Marko Rauhamaa wrote: > The "rigmarole" is trying to get around Java's mandatory exception > handling limitations, which Python doesn't have. > > You are not allowed to pass a lambda to the super constructor that > throws an SQLException. To get around the limitation, a RuntimeException > wrapper is created to smuggle the SQLException through the compiler's > defenses. Any code is free to throw a RuntimeException. > Oh, it's THAT problem. Well, it's still not really a fair comparison of declared types. It shows how Python's much easier to work with, but what you're showing off is the simpler exception handling :) ChrisA From marko at pacujo.net Tue Mar 4 16:05:06 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 04 Mar 2014 23:05:06 +0200 Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: <87y50pn08t.fsf@elektro.pacujo.net> Oscar Benjamin : > To me the obvious method is Newton iteration which takes O(sqrt(N)) > iterations to obtain N digits of precision. This brings the above > complexity below quadratic: > > #!/usr/bin/env python > > from decimal import Decimal as D, localcontext > > def sqrt(y, prec=1000): > '''Solve x**2 = y''' > assert y > 0 > eps = D(10) ** -(prec + 5) > x = D(y) > with localcontext() as ctx: > ctx.prec = prec + 10 > while x ** 2 - y > x * eps: > x = (x + y/x) / 2 > return x > > print(sqrt(2)) At a quick glance, I believe x ** 2 is O(N?) and so the total complexity should be O(N ** 2.5). Marko From rosuav at gmail.com Tue Mar 4 16:18:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 08:18:29 +1100 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin wrote: > I don't quite follow your reasoning here. By "cut-and-try" do you mean > bisection? If so it gives the first N decimal digits in N*log2(10) > iterations. However each iteration requires a multiply and when the > number of digits N becomes large the multiplication is worse than > linear. So the result is something like N**2 log(N)log(log(N)), By "cut and try" I'm talking about the really REALLY simple algorithm for calculating square roots. It's basically brute force. epsilon = 0.0001 def sqrt(n): guess1, guess2 = 1, n while abs(guess1-guess2) > epsilon: guess1 = n/guess2 guess2 = (guess1 + guess2)/2 return guess1 It's generally going to take roughly O(n*n) time to generate n digits, give or take. That's the baseline against which anything else can be compared. There are plenty of better ways to calculate them. ChrisA From marko at pacujo.net Tue Mar 4 16:21:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 04 Mar 2014 23:21:44 +0200 Subject: Functional programming References: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> <8738ixofhl.fsf@elektro.pacujo.net> Message-ID: <87txbdmzh3.fsf@elektro.pacujo.net> Chris Angelico : > Oh, it's THAT problem. Well, it's still not really a fair comparison > of declared types. It shows how Python's much easier to work with, but > what you're showing off is the simpler exception handling :) The other example I gave is really bread-and-butter Java. An ergonomic disaster and takes some staring at to figure out what's going on. Note that Java doesn't possess typedef's so you really are pretty much forced to write those < , < >>'s a lot. Marko From rosuav at gmail.com Tue Mar 4 16:26:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 08:26:53 +1100 Subject: Functional programming In-Reply-To: <87txbdmzh3.fsf@elektro.pacujo.net> References: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> <8738ixofhl.fsf@elektro.pacujo.net> <87txbdmzh3.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 8:21 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Oh, it's THAT problem. Well, it's still not really a fair comparison >> of declared types. It shows how Python's much easier to work with, but >> what you're showing off is the simpler exception handling :) > > The other example I gave is really bread-and-butter Java. An ergonomic > disaster and takes some staring at to figure out what's going on. > > Note that Java doesn't possess typedef's so you really are pretty much > forced to write those < , < >>'s a lot. C++ at least has typedefs, and in the newer standards, the 'auto' keyword was repurposed. ChrisA From python at mrabarnett.plus.com Tue Mar 4 16:38:06 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 04 Mar 2014 21:38:06 +0000 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: <531647BE.70104@mrabarnett.plus.com> On 2014-03-04 20:57, Igor Korot wrote: > Hi, ALL, > I'm getting this: > > timestamp out of range for platform localtime()/gmtime() function > > trying to convert the timestamp with milliseconds into the datetime object. > > The first hit of Google gives me this: > > http://stackoverflow.com/questions/12458595/convert-epoch-timestamp-in-python > > but the solution described is not good for me since it does not gives > me the milliseconds value. > > How do I get the proper datetime value including milliseconds from the > timestamp? > > Thank you. > Are you using Python 2? If yes, then try dividing by 1000.0. From stefan at bytereef.org Tue Mar 4 16:35:48 2014 From: stefan at bytereef.org (Stefan Krah) Date: Tue, 4 Mar 2014 21:35:48 +0000 (UTC) Subject: python decimal library dmath.py v0.3 released References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> <27d19767-84ee-4ab7-87fd-784e8ac57680@googlegroups.com> Message-ID: [I found this via the python-ideas thread] Wolfgang Maier biologie.uni-freiburg.de> writes: > math.factorial is accurate and faster than your pure-Python function, especially for large numbers. It is slower for huge numbers than decimal if you use this Python function: http://www.bytereef.org/mpdecimal/quickstart.html#factorial-in-pure-python Be sure to set MAX_EMAX and MIN_EMIN, that's missing in the example. If you want to *see* all digits of a very large number, then decimal is probably even faster than gmpy. See: http://www.bytereef.org/mpdecimal/benchmarks.html#arbitrary-precision-libraries Stefan Krah From breamoreboy at yahoo.co.uk Tue Mar 4 16:44:04 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Mar 2014 21:44:04 +0000 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: On 04/03/2014 20:57, Igor Korot wrote: > Hi, ALL, > I'm getting this: > > timestamp out of range for platform localtime()/gmtime() function > > trying to convert the timestamp with milliseconds into the datetime object. > > The first hit of Google gives me this: > > http://stackoverflow.com/questions/12458595/convert-epoch-timestamp-in-python > > but the solution described is not good for me since it does not gives > me the milliseconds value. > > How do I get the proper datetime value including milliseconds from the > timestamp? > > Thank you. > You have a long record of asking timestamp related questions so you should know where the docs are that provide the answer to this question. I'll leave you to go off and read them. If you don't understand them, please cut and paste your code here, state what you expected to happen, what actually happened, including any traceback if applicable, and then we'll be happy to point you the error of your ways. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Tue Mar 4 16:43:05 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 04 Mar 2014 23:43:05 +0200 Subject: Functional programming References: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> <8738ixofhl.fsf@elektro.pacujo.net> <87txbdmzh3.fsf@elektro.pacujo.net> Message-ID: <87ppm1myhi.fsf@elektro.pacujo.net> Chris Angelico : > C++ at least has typedefs, and in the newer standards, the 'auto' > keyword was repurposed. Last I checked, C++ had no satisfactory way to express callbacks/functors/listeners/lambdas. That's why Qt came up with a metacompiler to supplement C++'s facilities. No, STL and Boost can't remedy the situation. The main reason was the unfortunate way method pointers were defined in C++. C#'s delegates and Java's anonymous inner classes are something a C++ developer can only dream of (unless something has already been dreamt up in a recent standard). Python, of course, has delegates: that_object.register_callback(self.handle_it) Python doesn't have anonymous inner classes, but it has named inner classes, and that's quite sufficient. Marko From ikorot01 at gmail.com Tue Mar 4 16:46:21 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 4 Mar 2014 13:46:21 -0800 Subject: Proper conversion of timestamp In-Reply-To: <531647BE.70104@mrabarnett.plus.com> References: <531647BE.70104@mrabarnett.plus.com> Message-ID: MRAB, On Tue, Mar 4, 2014 at 1:38 PM, MRAB wrote: > On 2014-03-04 20:57, Igor Korot wrote: > >> Hi, ALL, >> I'm getting this: >> >> timestamp out of range for platform localtime()/gmtime() function >> >> trying to convert the timestamp with milliseconds into the datetime >> object. >> >> The first hit of Google gives me this: >> >> http://stackoverflow.com/questions/12458595/convert- >> epoch-timestamp-in-python >> >> but the solution described is not good for me since it does not gives >> me the milliseconds value. >> >> How do I get the proper datetime value including milliseconds from the >> timestamp? >> >> Thank you. >> >> Are you using Python 2? If yes, then try dividing by 1000.0. > Yes, I'm using python 2.7. But dividing by 1000 will give the precision in seconds, i.e. "YYYY-MM-DD HH:MM:SS". What I want is to have this: "YYYY-MM-DD HH:MM:SS.XXX", where "XXX" is a milliseconds. Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Mar 4 16:45:50 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Mar 2014 21:45:50 +0000 Subject: Proper conversion of timestamp In-Reply-To: <531647BE.70104@mrabarnett.plus.com> References: <531647BE.70104@mrabarnett.plus.com> Message-ID: On 04/03/2014 21:38, MRAB wrote: > On 2014-03-04 20:57, Igor Korot wrote: >> Hi, ALL, >> I'm getting this: >> >> timestamp out of range for platform localtime()/gmtime() function >> >> trying to convert the timestamp with milliseconds into the datetime >> object. >> >> The first hit of Google gives me this: >> >> http://stackoverflow.com/questions/12458595/convert-epoch-timestamp-in-python >> >> >> but the solution described is not good for me since it does not gives >> me the milliseconds value. >> >> How do I get the proper datetime value including milliseconds from the >> timestamp? >> >> Thank you. >> > Are you using Python 2? If yes, then try dividing by 1000.0. > You learn something new every day, I wasn't aware that you could multiply or divide timestamps. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Tue Mar 4 16:52:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 08:52:57 +1100 Subject: Functional programming In-Reply-To: <87ppm1myhi.fsf@elektro.pacujo.net> References: <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> <8738ixofhl.fsf@elektro.pacujo.net> <87txbdmzh3.fsf@elektro.pacujo.net> <87ppm1myhi.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 8:43 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> C++ at least has typedefs, and in the newer standards, the 'auto' >> keyword was repurposed. > > Last I checked, C++ had no satisfactory way to express > callbacks/functors/listeners/lambdas. That's why Qt came up with a > metacompiler to supplement C++'s facilities. I think one of the recent standards added some kind of closure for callbacks. I tried to grok it and couldn't figure out what it was doing, so I gave it up as a bad job. It got hairy. Really hairy. Either that, or I was reading a poorly-written article, which is also possible. ChrisA From news at blinne.net Tue Mar 4 16:53:22 2014 From: news at blinne.net (Alexander Blinne) Date: Tue, 04 Mar 2014 22:53:22 +0100 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <5315cd4b$0$6670$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <53164b54$0$6663$9b4e6d93@newsspool2.arcor-online.net> Am 04.03.2014 15:06, schrieb Chris Angelico: > https://github.com/Rosuav/ExceptExpr/blob/master/find_except_expr.py I have always found it quite nice that the python parser is so easy to use from within python itself. > Run across the Python stdlib, that tells me there are 4040 uses of > is/is not, of which 16 compare against False, 18 against True (see? > Python has a bias for truth above falsehood!), and 3386 against None. I think i will have to rephrase my "is False" condition to make it more truthy :) From ikorot01 at gmail.com Tue Mar 4 16:55:11 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 4 Mar 2014 13:55:11 -0800 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: Hi, Mark, On Tue, Mar 4, 2014 at 1:44 PM, Mark Lawrence wrote: > On 04/03/2014 20:57, Igor Korot wrote: > >> Hi, ALL, >> I'm getting this: >> >> timestamp out of range for platform localtime()/gmtime() function >> >> trying to convert the timestamp with milliseconds into the datetime >> object. >> >> The first hit of Google gives me this: >> >> http://stackoverflow.com/questions/12458595/convert- >> epoch-timestamp-in-python >> >> but the solution described is not good for me since it does not gives >> me the milliseconds value. >> >> How do I get the proper datetime value including milliseconds from the >> timestamp? >> >> Thank you. >> >> > You have a long record of asking timestamp related questions so you should > know where the docs are that provide the answer to this question. I'll > leave you to go off and read them. If you don't understand them, please > cut and paste your code here, state what you expected to happen, what > actually happened, including any traceback if applicable, and then we'll be > happy to point you the error of your ways. > Working with the dates is not that easy and not just in Python. There are too many different formatting involved with many different representation. And on top of it it is possible to use one system in completely different environment. But this particular question is easy. What I have is a timestamp which reads: 1289410678L. Trying to convert this into the datetime object in Python using: import datetime datetime.datetime.fromtimestamp( stamp ) produces the error: timestamp out of range for platform localtime()/gmtime() function. This is because this timestamp is not in seconds, but rather in milliseconds. Now the question I have is: how do I properly convert this timestamp into the datetime object with the milliseconds? Thank you. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > --- > This email is free from viruses and malware because avast! Antivirus > protection is active. > http://www.avast.com > > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Mar 4 16:55:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 08:55:43 +1100 Subject: Proper conversion of timestamp In-Reply-To: References: <531647BE.70104@mrabarnett.plus.com> Message-ID: On Wed, Mar 5, 2014 at 8:46 AM, Igor Korot wrote: >> Are you using Python 2? If yes, then try dividing by 1000.0. > > > Yes, I'm using python 2.7. > But dividing by 1000 will give the precision in seconds, i.e. "YYYY-MM-DD > HH:MM:SS". Did you notice the bit at the end there? Try dividing by 1000.0, see if that's any different. ChrisA From ikorot01 at gmail.com Tue Mar 4 16:57:56 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 4 Mar 2014 13:57:56 -0800 Subject: Proper conversion of timestamp In-Reply-To: References: <531647BE.70104@mrabarnett.plus.com> Message-ID: Mark, On Tue, Mar 4, 2014 at 1:45 PM, Mark Lawrence wrote: > On 04/03/2014 21:38, MRAB wrote: > >> On 2014-03-04 20:57, Igor Korot wrote: >> >>> Hi, ALL, >>> I'm getting this: >>> >>> timestamp out of range for platform localtime()/gmtime() function >>> >>> trying to convert the timestamp with milliseconds into the datetime >>> object. >>> >>> The first hit of Google gives me this: >>> >>> http://stackoverflow.com/questions/12458595/convert- >>> epoch-timestamp-in-python >>> >>> >>> but the solution described is not good for me since it does not gives >>> me the milliseconds value. >>> >>> How do I get the proper datetime value including milliseconds from the >>> timestamp? >>> >>> Thank you. >>> >>> Are you using Python 2? If yes, then try dividing by 1000.0. >> >> > You learn something new every day, I wasn't aware that you could multiply > or divide timestamps. Of course you can. Its just the number. And this is exactly what happens on the stackoverflow question I referenced in the OP. Problem is I want the milliseconds in the datetime object. Thank you. > > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > --- > This email is free from viruses and malware because avast! Antivirus > protection is active. > http://www.avast.com > > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Mar 4 17:01:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 09:01:43 +1100 Subject: Reference In-Reply-To: <53164b54$0$6663$9b4e6d93@newsspool2.arcor-online.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <5315cd4b$0$6670$9b4e6d93@newsspool2.arcor-online.net> <53164b54$0$6663$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Wed, Mar 5, 2014 at 8:53 AM, Alexander Blinne wrote: > Am 04.03.2014 15:06, schrieb Chris Angelico: >> https://github.com/Rosuav/ExceptExpr/blob/master/find_except_expr.py > > I have always found it quite nice that the python parser is so easy to > use from within python itself. Yes. Until I put together the original version of that, to search for PEP 463 translation candidates, I'd never used the ast module other than for literal_eval. It's marvelously powerful. >> Run across the Python stdlib, that tells me there are 4040 uses of >> is/is not, of which 16 compare against False, 18 against True (see? >> Python has a bias for truth above falsehood!), and 3386 against None. > > I think i will have to rephrase my "is False" condition to make it more > truthy :) if x is False: --> if not x: ChrisA From oscar.j.benjamin at gmail.com Tue Mar 4 17:02:15 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 4 Mar 2014 22:02:15 +0000 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On 4 March 2014 21:18, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin > wrote: >> I don't quite follow your reasoning here. By "cut-and-try" do you mean >> bisection? If so it gives the first N decimal digits in N*log2(10) >> iterations. However each iteration requires a multiply and when the >> number of digits N becomes large the multiplication is worse than >> linear. So the result is something like N**2 log(N)log(log(N)), > > By "cut and try" I'm talking about the really REALLY simple algorithm > for calculating square roots. It's basically brute force. > > epsilon = 0.0001 > def sqrt(n): > guess1, guess2 = 1, n > while abs(guess1-guess2) > epsilon: > guess1 = n/guess2 > guess2 = (guess1 + guess2)/2 > return guess1 That's the exact same algorithm I showed! How on earth would you call that brute force? > It's generally going to take roughly O(n*n) time to generate n digits, > give or take. It does not take O(n*n) time. This is Newton iteration and for well-behaved problems such as this it generates more than n digits after n iterations. I modified my code to show the error (x**2 - y) at each iteration: $ python3.3 root.py 2 0.2 0.007 0.000006 5E-12 3E-24 8E-49 8E-98 8E-196 9E-392 1E-783 The number of correct digits doubles at each iteration so after n iterations you have 2**n digits (I misstated this as n**2 before). This means that it takes log(N) iterations to get N digits. See here for more: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method See also the section below that: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Digit-by-digit_calculation > That's the baseline against which anything else can be > compared. There are plenty of better ways to calculate them. Such as? Oscar From rosuav at gmail.com Tue Mar 4 17:03:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 09:03:05 +1100 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: On Wed, Mar 5, 2014 at 8:55 AM, Igor Korot wrote: > > This is because this timestamp is not in seconds, but rather in > milliseconds. > > Now the question I have is: how do I properly convert this timestamp into > the datetime object with the milliseconds? Read elsewhere in the thread, two people have explained this already. ChrisA From oscar.j.benjamin at gmail.com Tue Mar 4 17:08:44 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 4 Mar 2014 22:08:44 +0000 Subject: Working with the set of real numbers In-Reply-To: <87y50pn08t.fsf@elektro.pacujo.net> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> <87y50pn08t.fsf@elektro.pacujo.net> Message-ID: On 4 March 2014 21:05, Marko Rauhamaa wrote: > Oscar Benjamin : > >> To me the obvious method is Newton iteration which takes O(sqrt(N)) >> iterations to obtain N digits of precision. This brings the above >> complexity below quadratic: >> >> #!/usr/bin/env python >> >> from decimal import Decimal as D, localcontext >> >> def sqrt(y, prec=1000): >> '''Solve x**2 = y''' >> assert y > 0 >> eps = D(10) ** -(prec + 5) >> x = D(y) >> with localcontext() as ctx: >> ctx.prec = prec + 10 >> while x ** 2 - y > x * eps: >> x = (x + y/x) / 2 >> return x >> >> print(sqrt(2)) > > At a quick glance, I believe x ** 2 is O(N?) and so the total complexity > should be O(N ** 2.5). x**2 is just a multiplication which can be done in better than O(N**2): http://en.wikipedia.org/wiki/Multiplication_algorithm#Fast_multiplication_algorithms_for_large_inputs Oscar From rosuav at gmail.com Tue Mar 4 17:18:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 09:18:33 +1100 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 9:02 AM, Oscar Benjamin wrote: > On 4 March 2014 21:18, Chris Angelico wrote: >> On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin >> wrote: >>> I don't quite follow your reasoning here. By "cut-and-try" do you mean >>> bisection? If so it gives the first N decimal digits in N*log2(10) >>> iterations. However each iteration requires a multiply and when the >>> number of digits N becomes large the multiplication is worse than >>> linear. So the result is something like N**2 log(N)log(log(N)), >> >> By "cut and try" I'm talking about the really REALLY simple algorithm >> for calculating square roots. It's basically brute force. >> >> epsilon = 0.0001 >> def sqrt(n): >> guess1, guess2 = 1, n >> while abs(guess1-guess2) > epsilon: >> guess1 = n/guess2 >> guess2 = (guess1 + guess2)/2 >> return guess1 > > That's the exact same algorithm I showed! How on earth would you call > that brute force? It uses a lot of division. There are various refinements that can be done that replace some of that division with multiplication, but I'd have to go do some research to figure it out. This is the purest form of attempted-division algorithm. If you're describing it on a blackboard, you would write it pretty much like this. At each iteration, you have to divide by a number that's n digits long, and then do some additional arithmetic. >> It's generally going to take roughly O(n*n) time to generate n digits, >> give or take. > > It does not take O(n*n) time. This is Newton iteration and for > well-behaved problems such as this it generates more than n digits > after n iterations. I modified my code to show the error (x**2 - y) at > each iteration: > > $ python3.3 root.py > 2 > 0.2 > 0.007 > 0.000006 > 5E-12 > 3E-24 > 8E-49 > 8E-98 > 8E-196 > 9E-392 > 1E-783 > > The number of correct digits doubles at each iteration so after n > iterations you have 2**n digits (I misstated this as n**2 before). > This means that it takes log(N) iterations to get N digits. It seems I'm partly mistaken, though not entirely. Let's compare two versions. In the first, you set the precision (I'm talking in terms of REXX's "NUMERIC DIGITS" statement - anything beyond this many digits will be rounded (and represented exponentially, if necessary); I'm not sure if decimal.Decimal precision works this way) such that you get 10 digits. Each iteration requires division by a 10-digit number, which is an operation that takes a certain amount of time; and it's going to take some number of iterations to get to the final answer. Second version, you set the precision so you get 20 digits. Now, it's going to take you approximately one more iteration to get to the final answer. (This bit I was mistaken on. I thought it would take something like 25% more or 50% more iterations.) But each iteration will take longer. The complexity of division depends on the algorithm - grade school long division would be O(n) with a fixed-length dividend, I think, but you could probably pull that down a bit. So that's why I said it'd be very roughly O(n*n) - because the division in each step is O(n), and I thought it'd take O(n) steps. Turns out it's O(n*log(n)), which is a lot better. >> That's the baseline against which anything else can be >> compared. There are plenty of better ways to calculate them. > > Such as? Improved versions of the above, and I was under the impression that there were some completely different techniques that converged a lot more quickly. But it may be that I was mistaken, as I'd been expecting this to converge in O(n) steps. Reducing the amount of division would speed things up significantly, although it probably won't change the algorithmic complexity. So, put it down to misremembering and thinking the simple algorithm was worse than it actually is :) ChrisA From ethan at stoneleaf.us Tue Mar 4 17:05:35 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 04 Mar 2014 14:05:35 -0800 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: <53164E2F.4020807@stoneleaf.us> On 03/04/2014 01:55 PM, Igor Korot wrote: > > Now the question I have is: how do I properly convert this timestamp > into the datetime object with the milliseconds? And Mark's point is: How do the docs say to do it? What fails when you try it that way? -- ~Ethan~ From ethan at stoneleaf.us Tue Mar 4 16:49:38 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 04 Mar 2014 13:49:38 -0800 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> Message-ID: <53164A72.3050806@stoneleaf.us> On 03/04/2014 12:47 PM, Ned Batchelder wrote: > On 3/4/14 12:16 PM, Skip Montanaro wrote: >> On Tue, Mar 4, 2014 at 11:07 AM, Chris Angelico wrote: >>> I don't have time to watch an hour-long video... what'd he do, >>> exactly that? >> >> If you fast forward to 16:14, his talk is about five minutes long. He >> wrote a Lisp compiler whose backend is Python. >> >> Skip >> > > It's Hy: http://hylang.org Okay, that looks totally cool. Maybe I'll finally get a handle on LISP! :) -- ~Ethan~ From rosuav at gmail.com Tue Mar 4 17:44:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 09:44:03 +1100 Subject: find and replace string in binary file In-Reply-To: References: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> Message-ID: On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <__peter__ at web.de> wrote: > loial wrote: > >> How do I read a binary file, find/identify a character string and replace >> it with another character string and write out to another file? >> >> Its the finding of the string in a binary file that I am not clear on. > > That's not possible. You have to convert either binary to string or string > to binary before you can replace. Whatever you choose, you have to know the > encoding of the file. If it's actually a binary file (as in, an executable, or an image, or something), then the *file* won't have an encoding, so you'll need to know the encoding of the particular string you want and encode your string to bytes. ChrisA From breamoreboy at yahoo.co.uk Tue Mar 4 17:46:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Mar 2014 22:46:38 +0000 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: On 04/03/2014 21:55, Igor Korot wrote: > > But this particular question is easy. > If it's easy why can't you answer it via the docs rather than ask here? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Tue Mar 4 17:48:40 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 00:48:40 +0200 Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> Message-ID: <87d2i1mvg7.fsf@elektro.pacujo.net> Ethan Furman : > Okay, that looks totally cool. Maybe I'll finally get a handle on > LISP! :) Lisp is conceptually simpler than Python, but awe-inspiring. One day, it will overtake Python, I believe. Once you have Lisp down pat, you'll be able to appreciate . The final Nirvana is reached with . Marko From oscar.j.benjamin at gmail.com Tue Mar 4 17:54:01 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 4 Mar 2014 22:54:01 +0000 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On 4 March 2014 22:18, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 9:02 AM, Oscar Benjamin > wrote: >> On 4 March 2014 21:18, Chris Angelico wrote: >>> On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin >>> wrote: >>> >>> epsilon = 0.0001 >>> def sqrt(n): >>> guess1, guess2 = 1, n >>> while abs(guess1-guess2) > epsilon: >>> guess1 = n/guess2 >>> guess2 = (guess1 + guess2)/2 >>> return guess1 >> >> That's the exact same algorithm I showed! How on earth would you call >> that brute force? > > It uses a lot of division. There are various refinements that can be > done that replace some of that division with multiplication, but I'd > have to go do some research to figure it out. There's a description of such a method here: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Iterative_methods_for_reciprocal_square_roots I don't know whether that would work out faster (when using decimal - for float it would probably be slower). > Let's compare two > versions. In the first, you set the precision (I'm talking in terms of > REXX's "NUMERIC DIGITS" statement I have no idea what that is. >- anything beyond this many digits > will be rounded (and represented exponentially, if necessary); I'm not > sure if decimal.Decimal precision works this way) such that you get 10 > digits. With the decimal module if you set the precision to 5 digits then it basically represents the number in "standard form" with 5 digits .e.g: 1.2345 x 10**21. > Each iteration requires division by a 10-digit number, which > is an operation that takes a certain amount of time; and it's going to > take some number of iterations to get to the final answer. > > Second version, you set the precision so you get 20 digits. If we're talking about 10-20 digits then the decimal module is overkill: just use float. The speed up from hardware arithmetic will massively out-weigh any other performance considerations. My version was intended to produce large numbers of digits which is when the big-O comes in: $ python3.3 -m timeit -s 'from root import sqrt' 'sqrt(2, 10)' 10000 loops, best of 3: 22.4 usec per loop $ python3.3 -m timeit -s 'from root import sqrt' 'sqrt(2, 100)' 10000 loops, best of 3: 59.1 usec per loop $ python3.3 -m timeit -s 'from root import sqrt' 'sqrt(2, 1000)' 1000 loops, best of 3: 1.15 msec per loop $ python3.3 -m timeit -s 'from root import sqrt' 'sqrt(2, 10000)' 10 loops, best of 3: 85.9 msec per loop $ python3.3 -m timeit -s 'from root import sqrt' 'sqrt(2, 100000)' 10 loops, best of 3: 1.59 sec per loop Oscar From rosuav at gmail.com Tue Mar 4 17:57:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 09:57:20 +1100 Subject: How security holes happen In-Reply-To: <87d2i1mvg7.fsf@elektro.pacujo.net> References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 9:48 AM, Marko Rauhamaa wrote: > Lisp is conceptually simpler than Python, but awe-inspiring. One day, it > will overtake Python, I believe. > > The final Nirvana is reached with... No no no. The final Nirvana is achieved when you no longer write text at all, but simply edit an empty file. When you are done, the file is still empty, and you have truly reached nirvana. Either that, or you code in http://en.wikipedia.org/wiki/Whitespace_(programming_language) ... ChrisA From roy at panix.com Tue Mar 4 17:59:23 2014 From: roy at panix.com (Roy Smith) Date: Tue, 04 Mar 2014 17:59:23 -0500 Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: In article , Chris Angelico wrote: > On Wed, Mar 5, 2014 at 9:48 AM, Marko Rauhamaa wrote: > > Lisp is conceptually simpler than Python, but awe-inspiring. One day, it > > will overtake Python, I believe. > > > > The final Nirvana is reached with... > > No no no. The final Nirvana is achieved when you no longer write text > at all, but simply edit an empty file. When you are done, the file is > still empty, and you have truly reached nirvana. > > Either that, or you code in > http://en.wikipedia.org/wiki/Whitespace_(programming_language) ... > > ChrisA Man, imagine what you could do with a Unicode version of Whitespace? From rosuav at gmail.com Tue Mar 4 18:01:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 10:01:27 +1100 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 9:54 AM, Oscar Benjamin wrote: >> Let's compare two >> versions. In the first, you set the precision (I'm talking in terms of >> REXX's "NUMERIC DIGITS" statement > > I have no idea what that is. > >>- anything beyond this many digits >> will be rounded (and represented exponentially, if necessary); I'm not >> sure if decimal.Decimal precision works this way) such that you get 10 >> digits. > > With the decimal module if you set the precision to 5 digits then it > basically represents the number in "standard form" with 5 digits .e.g: > 1.2345 x 10**21. That's how NUMERIC DIGITS works, so we're on the same page. I'm not familiar enough with decimal.Decimal and how precision is configured, but it seems to function the same way. >> Each iteration requires division by a 10-digit number, which >> is an operation that takes a certain amount of time; and it's going to >> take some number of iterations to get to the final answer. >> >> Second version, you set the precision so you get 20 digits. > > If we're talking about 10-20 digits then the decimal module is > overkill: just use float. The speed up from hardware arithmetic will > massively out-weigh any other performance considerations. Yeah, I'm just digging into the algorithm. The same concept applies when going from 100 to 200 digits, or 1000 to 2000, and in each case, the division will get way slower, but the number of iterations won't go up as fast as I thought it would. In theory, it should be possible to do the first few divisions at lower precision, and scale up as you have need. In practice, would the churning of precisions mean that you lose all the benefit? ChrisA From notbob at nothome.com Tue Mar 4 18:03:13 2014 From: notbob at nothome.com (notbob) Date: 4 Mar 2014 23:03:13 GMT Subject: Geezer learns python Message-ID: I'm trying to learn python. I'm doing it via Zed Shaw's Learn Python the Hard Way. Sure enough, 16 lessons in and I've run aground. Is it OK for a painfully stupid ol' fart to ask painfully stupid noob questions, here? I'm a long time usenet fan and prefer it to irc. I've run Slackware for many yrs and know jes enough bash to get the drift of a slack script, but am no programmer, not by any stretch of the imagination. I really wanna succeed on this one and have signed up for an online python class from Rice U. I'd like to finish Zed's tutorial by the 24th of this month. I'm retired, so have the time to burn. Thnx. ;) nb From toby at tobiah.org Tue Mar 4 18:05:52 2014 From: toby at tobiah.org (Tobiah) Date: Tue, 04 Mar 2014 15:05:52 -0800 Subject: Geezer learns python In-Reply-To: References: Message-ID: <53165C50.6030602@tobiah.org> On 03/04/2014 03:03 PM, notbob wrote: > I'm trying to learn python. I'm doing it via Zed Shaw's Learn Python > the Hard Way. Sure enough, 16 lessons in and I've run aground. Is it > OK for a painfully stupid ol' fart to ask painfully stupid noob > questions, here? I'm a long time usenet fan and prefer it to irc. > > I've run Slackware for many yrs and know jes enough bash to get the > drift of a slack script, but am no programmer, not by any stretch of > the imagination. I really wanna succeed on this one and have signed > up for an online python class from Rice U. I'd like to finish Zed's > tutorial by the 24th of this month. I'm retired, so have the time to > burn. Thnx. ;) > > nb > All are welcome here. Try to narrow down the focus of the question, and where applicable, post source code and program output. From rosuav at gmail.com Tue Mar 4 18:10:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 10:10:47 +1100 Subject: Geezer learns python In-Reply-To: References: Message-ID: On Wed, Mar 5, 2014 at 10:03 AM, notbob wrote: > I'm trying to learn python. I'm doing it via Zed Shaw's Learn Python > the Hard Way. Sure enough, 16 lessons in and I've run aground. Is it > OK for a painfully stupid ol' fart to ask painfully stupid noob > questions, here? I'm a long time usenet fan and prefer it to irc. Yep! Either here or on the python-tutor list: https://mail.python.org/mailman/listinfo/tutor Just remember to give your question a good subject line, and have all the necessary details there. This is long, but if you want to know how to "get the most" out of a community like this, consider this to be the cheat modes. IDKFA! http://www.catb.org/esr/faqs/smart-questions.html ChrisA From torriem at gmail.com Tue Mar 4 18:11:31 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 04 Mar 2014 16:11:31 -0700 Subject: Geezer learns python In-Reply-To: References: Message-ID: <53165DA3.3020400@gmail.com> On 03/04/2014 04:03 PM, notbob wrote: > I'm trying to learn python. I'm doing it via Zed Shaw's Learn Python > the Hard Way. Sure enough, 16 lessons in and I've run aground. Is it > OK for a painfully stupid ol' fart to ask painfully stupid noob > questions, here? I'm a long time usenet fan and prefer it to irc. > > I've run Slackware for many yrs and know jes enough bash to get the > drift of a slack script, but am no programmer, not by any stretch of > the imagination. I really wanna succeed on this one and have signed > up for an online python class from Rice U. I'd like to finish Zed's > tutorial by the 24th of this month. I'm retired, so have the time to > burn. Thnx. ;) I say, fire away. I think you'll find a decent reception here. From davea at davea.name Tue Mar 4 18:20:20 2014 From: davea at davea.name (Dave Angel) Date: Tue, 4 Mar 2014 18:20:20 -0500 (EST) Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: Oscar Benjamin Wrote in message: > On 4 March 2014 21:18, Chris Angelico wrote: > > > It does not take O(n*n) time. This is Newton iteration and for > well-behaved problems such as this it generates more than n digits > after n iterations. I modified my code to show the error (x**2 - y) at > each iteration: > > $ python3.3 root.py > 2 > 0.2 > 0.007 > 0.000006 > 5E-12 > 3E-24 > 8E-49 > 8E-98 > 8E-196 > 9E-392 > 1E-783 > > The number of correct digits doubles at each iteration so after n > iterations you have 2**n digits (I misstated this as n**2 before). > This means that it takes log(N) iterations to get N digits. See here > for more: > http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method > > See also the section below that: > http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Digit-by-digit_calculation > >> That's the baseline against which anything else can be >> compared. There are plenty of better ways to calculate them. > > Such as? > One problem with complexity claims is that it's easy to miss some contributing time eaters. I haven't done any measuring on modern machines nor in python, but I'd assume that multiplies take *much* longer for large integers, and that divides are much worse. So counting iterations isn't the whole story. On the assumption that division by 2 is very fast, and that a general multiply isn't too bad, you could improve on Newton by observing that the slope is 2. err = n - guess * guess guess += err/2 Some 37 years ago I microcoded a math package which included square root. All the math was decimal, and there was no hardware multiply or divide. The algorithm I came up with generated the answer one digit at a time, with no subsequent rounding needed. And it took just a little less time than two divides. For that architecture, Newton's method would've been too slow. Incidentally, the algorithm did no divides, not even by 2. No multiplies either. Just repeated subtraction, sorta like divide was done. If anyone is curious, I'll be glad to describe the algorithm; I've never seen it published, before or since. I got my inspiration from a method used in mechanical, non-motorized, adding machines. My father had shown me that approach in the 50's. -- DaveA From breamoreboy at yahoo.co.uk Tue Mar 4 18:16:48 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Mar 2014 23:16:48 +0000 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: On 04/03/2014 22:59, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Wed, Mar 5, 2014 at 9:48 AM, Marko Rauhamaa wrote: >>> Lisp is conceptually simpler than Python, but awe-inspiring. One day, it >>> will overtake Python, I believe. >>> >>> The final Nirvana is reached with... >> >> No no no. The final Nirvana is achieved when you no longer write text >> at all, but simply edit an empty file. When you are done, the file is >> still empty, and you have truly reached nirvana. >> >> Either that, or you code in >> http://en.wikipedia.org/wiki/Whitespace_(programming_language) ... >> >> ChrisA > > Man, imagine what you could do with a Unicode version of Whitespace? > Yes, but how do we pursuade the Python core devs to give us a decent implementation? Let's face it, according to our resident unicode expert, they can't get anything right about unicode. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Tue Mar 4 18:22:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 10:22:49 +1100 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 10:16 AM, Mark Lawrence wrote: >> Man, imagine what you could do with a Unicode version of Whitespace? >> > > Yes, but how do we pursuade the Python core devs to give us a decent > implementation? Let's face it, according to our resident unicode expert, > they can't get anything right about unicode. Easy. We get him to implement it. ChrisA From breamoreboy at yahoo.co.uk Tue Mar 4 18:27:07 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Mar 2014 23:27:07 +0000 Subject: Geezer learns python In-Reply-To: References: Message-ID: On 04/03/2014 23:03, notbob wrote: > I'm trying to learn python. I'm doing it via Zed Shaw's Learn Python > the Hard Way. Sure enough, 16 lessons in and I've run aground. Is it > OK for a painfully stupid ol' fart to ask painfully stupid noob > questions, here? I'm a long time usenet fan and prefer it to irc. > > I've run Slackware for many yrs and know jes enough bash to get the > drift of a slack script, but am no programmer, not by any stretch of > the imagination. I really wanna succeed on this one and have signed > up for an online python class from Rice U. I'd like to finish Zed's > tutorial by the 24th of this month. I'm retired, so have the time to > burn. Thnx. ;) > > nb > You might feel more comfortable on the tutor mailing list https://mail.python.org/mailman/listinfo/tutor -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Tue Mar 4 18:40:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 04 Mar 2014 23:40:10 +0000 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: On 04/03/2014 23:22, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 10:16 AM, Mark Lawrence wrote: >>> Man, imagine what you could do with a Unicode version of Whitespace? >>> >> >> Yes, but how do we pursuade the Python core devs to give us a decent >> implementation? Let's face it, according to our resident unicode expert, >> they can't get anything right about unicode. > > Easy. We get him to implement it. > > ChrisA > Bingo, nail struck firmly on head with steam roller :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From greg.ewing at canterbury.ac.nz Tue Mar 4 18:57:00 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 05 Mar 2014 12:57:00 +1300 Subject: Functional programming In-Reply-To: <87ppm1myhi.fsf@elektro.pacujo.net> References: <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> <8738ixofhl.fsf@elektro.pacujo.net> <87txbdmzh3.fsf@elektro.pacujo.net> <87ppm1myhi.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Python doesn't have anonymous inner classes, but it has named inner > classes, and that's quite sufficient. I would say it's Python's closures that make up for not having Java's inner classes. Or to put it another way, inner classes are Java's kludgy way of working around a lack of closures. -- Greg From cs at zip.com.au Tue Mar 4 19:07:37 2014 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 5 Mar 2014 11:07:37 +1100 Subject: How security holes happen In-Reply-To: References: Message-ID: <20140305000737.GA9013@cskk.homeip.net> On 05Mar2014 09:57, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 9:48 AM, Marko Rauhamaa wrote: > > Lisp is conceptually simpler than Python, but awe-inspiring. One day, it > > will overtake Python, I believe. > > > > The final Nirvana is reached with... > > No no no. The final Nirvana is achieved when you no longer write text > at all, but simply edit an empty file. When you are done, the file is > still empty, and you have truly reached nirvana. Every program has at least one bug and can be shortened by at least one instruction -- from which, by induction, it is evident that every program can be reduced to one instruction that does not work. - Ken Arnold Cheers, Cameron Simpson From emile at fenx.com Tue Mar 4 19:13:00 2014 From: emile at fenx.com (emile) Date: Tue, 04 Mar 2014 16:13:00 -0800 Subject: find and replace string in binary file In-Reply-To: References: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> Message-ID: On 03/04/2014 02:44 PM, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <__peter__ at web.de> wrote: >> loial wrote: >> >>> How do I read a binary file, find/identify a character string and replace >>> it with another character string and write out to another file? >>> >>> Its the finding of the string in a binary file that I am not clear on. >> >> That's not possible. You have to convert either binary to string or string >> to binary before you can replace. Whatever you choose, you have to know the >> encoding of the file. > > If it's actually a binary file (as in, an executable, or an image, or > something), then the *file* won't have an encoding, so you'll need to > know the encoding of the particular string you want and encode your > string to bytes. On 2.7 it's as easy as it sounds without having to think much about encodings and such. I find it mostly just works. emile at paj39:~$ which python /usr/bin/python emile at paj39:~$ python Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> image = open('/usr/bin/python','rb').read() >>> image.find("""Type "help", "copyright", "credits" """) 1491592 >>> image = image[:1491592]+"Echo"+image[1491592+4:] >>> open('/home/emile/pyecho','wb').write(image) >>> emile at paj39:~$ chmod a+x /home/emile/pyecho emile at paj39:~$ /home/emile/pyecho Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 Echo "help", "copyright", "credits" or "license" for more information. YMMV, Emile From marko at pacujo.net Tue Mar 4 19:11:05 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 02:11:05 +0200 Subject: Functional programming References: <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <87bnxloibq.fsf@elektro.pacujo.net> <8738ixofhl.fsf@elektro.pacujo.net> <87txbdmzh3.fsf@elektro.pacujo.net> <87ppm1myhi.fsf@elektro.pacujo.net> Message-ID: <878uspmrmu.fsf@elektro.pacujo.net> Gregory Ewing : > Marko Rauhamaa wrote: >> Python doesn't have anonymous inner classes, but it has named inner >> classes, and that's quite sufficient. > > I would say it's Python's closures that make up for not having Java's > inner classes. > > Or to put it another way, inner classes are Java's kludgy way of > working around a lack of closures. I actually quite like Java's inner classes. In fact, I think introducing lambdas into Java was a grave mistake; the silly competitive pressure from C# made them accept a very ugly and disheveled syntax. Inner classes *are* closures. They are more general than (Lisp-style) lambda's because they accept more than one method. Python, of course, has all of the above. Marko From galaxyblue63 at gmail.com Tue Mar 4 19:14:20 2014 From: galaxyblue63 at gmail.com (Bill) Date: Tue, 4 Mar 2014 16:14:20 -0800 (PST) Subject: How to create an instance of a python class from C++ Message-ID: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> Hello: I can't figure out how to create an instance of a python class from 'C++': ( I am relatively new to Python so excuse some of the following. ) In a .py file I create an ABC and then specialize it: from MyMod import * from abc import ABCMeta, abstractmethod # Declare an abstract base class. class Base(metaclass=ABCMeta): """Base class.""" @abstractmethod def description(self): return "From the base class." # Declare a class that inerits from the base. class Derived(Base): """Derived class.""" def description(self): return "From the Derived." # Register the derived class. RegisterClass(Derived) Then from 'C++' (my implementation of RegisterClass) I try to create an instance static PyObject * RegisterClass( PyObject *, PyObject *args ) { // This gets called ok. PyObject *class_decl; if( ! PyArg_ParseTuple(args, "O", &class_decl) ) return NULL; Py_INCREF(class_decl); PyTypeObject *typ = class_decl->ob_type; // Tried this. // PyObject *an = _PyObject_New(class_decl->ob_type); assert(an); // PyObject *desc = PyObject_CallMethod(an,"description",NULL); assert(desc); // Tried this. // PyObject *an = PyType_GenericNew((PyTypeObject *)class_decl->ob_type, NULL, NULL); assert(an); // assert(class_decl); assert(class_decl->ob_type); assert(class_decl->ob_type->tp_new); // This returns something. assert(class_decl); assert(class_decl->ob_type); assert(class_decl->ob_type->tp_new); PyObject *an_inst = class_decl->ob_type->tp_new(class_decl->ob_type,NULL, NULL); assert(an_inst); assert(class_decl->ob_type->tp_init); // This crashes. int ret = class_decl->ob_type->tp_init(an_inst,NULL, NULL); assert(ret == 0); // PyObject_CallMethod(an_inst,"__init__",NULL); // PyObject *an_inst = PyObject_CallMethod(class_decl,"__new__",NULL); assert(an_inst); // Never get here. PyObject *desc = PyObject_CallMethod(an_inst,"description",NULL); assert(desc); char *cp = _PyUnicode_AsString(desc); cerr << "Description:" << cp << endl; return PyLong_FromLong(0); } static PyMethodDef MyModMethods[] = { { "RegisterClass", RegisterClass, METH_VARARGS, "Register class." }, { NULL, NULL, 0, NULL } }; static struct PyModuleDef MyModMod = { PyModuleDef_HEAD_INIT, "MyMod", // name of module NULL, // module documentation, may be NULL -1, MyModMethods, NULL, NULL, NULL, NULL }; PyMODINIT_FUNC PyInit_MyMod( void ) { PyObject* m = PyModule_Create(&MyModMod); if( m == NULL ) return NULL; return m; } int main( int, char ** ) { PyImport_AppendInittab( "MyMod", PyInit_MyMod ); Py_Initialize(); const char *file_name = "z.py"; FILE *fp = fopen(file_name,"r"); if( fp ) { PyRun_SimpleFileExFlags(fp,file_name,1,0); } Py_Finalize(); return 0; } From rhodri at wildebst.org.uk Tue Mar 4 19:25:36 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Wed, 05 Mar 2014 00:25:36 -0000 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <87wqgb6imm.fsf@elektro.pacujo.net> <5315bd9e$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 04 Mar 2014 11:48:46 -0000, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 11:10:34 +0000, Alister wrote: > >> Definition of insanity >> >> Doing the same thing over and over again & expecting different results > > *rolls dice* As any gamer will tell you, dice are not random number generators. They are far too cussed for that :-) -- Rhodri James *-* Wildebeest Herder to the Masses From python at mrabarnett.plus.com Tue Mar 4 19:42:51 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 05 Mar 2014 00:42:51 +0000 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: <5316730B.3080706@mrabarnett.plus.com> On 2014-03-04 21:55, Igor Korot wrote: > Hi, Mark, > > > On Tue, Mar 4, 2014 at 1:44 PM, Mark Lawrence > wrote: > > On 04/03/2014 20:57, Igor Korot wrote: > > Hi, ALL, > I'm getting this: > > timestamp out of range for platform localtime()/gmtime() function > > trying to convert the timestamp with milliseconds into the > datetime object. > > The first hit of Google gives me this: > > http://stackoverflow.com/__questions/12458595/convert-__epoch-timestamp-in-python > > > but the solution described is not good for me since it does not > gives > me the milliseconds value. > > How do I get the proper datetime value including milliseconds > from the > timestamp? > > Thank you. > > > You have a long record of asking timestamp related questions so you > should know where the docs are that provide the answer to this > question. I'll leave you to go off and read them. If you don't > understand them, please cut and paste your code here, state what you > expected to happen, what actually happened, including any traceback > if applicable, and then we'll be happy to point you the error of > your ways. > > > Working with the dates is not that easy and not just in Python. > There are too many different formatting involved with many different > representation. > And on top of it it is possible to use one system in completely > different environment. > > But this particular question is easy. > > What I have is a timestamp which reads: 1289410678L. > That's an integer. It looks like the timestamp is a whole number of seconds, so the number of milliseconds is 0. (I make it '2010-11-10 17:37:58'.) > Trying to convert this into the datetime object in Python using: > > import datetime > datetime.datetime.fromtimestamp( stamp ) > > produces the error: timestamp out of range for platform > localtime()/gmtime() function. > > This is because this timestamp is not in seconds, but rather in > milliseconds. > > Now the question I have is: how do I properly convert this timestamp > into the datetime object with the milliseconds? > Using the datetime's .strftime method, you can include the number of microseconds in the format with '%f' (it'll write the microseconds as 6 digits). If you want it to the nearest millisecond (the timestamp would be a float), you could round the timestamp to 3 decimal places, use the '%f' in the format, and then truncate the string result to remove the last 3 digits. From root at 127.0.0.1 Tue Mar 4 19:52:31 2014 From: root at 127.0.0.1 (Andrew Cooper) Date: Wed, 05 Mar 2014 00:52:31 +0000 Subject: How security holes happen In-Reply-To: References: Message-ID: On 03/03/2014 22:19, Cameron Simpson wrote: > On 03Mar2014 09:17, Neal Becker wrote: >> Charles R Harris Wrote in message: >>> >> >> Imo the lesson here is never write in low level c. Use modern >> languages with well designed exception handling. > > What, and rely on someone else's low level C? > Why is C the lowest denominator? Even with correctly written C and assembly, how can you be sure that your processor is executing the SYSRET instruction safely? (CVE-2012-0217 for anyone interested) ~Andrew From rhodri at wildebst.org.uk Tue Mar 4 20:08:57 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Wed, 05 Mar 2014 01:08:57 -0000 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, 04 Mar 2014 05:24:03 -0000, Chris Angelico wrote: > Code should look like its intent. Warping it around performance is > hardly ever worthwhile. That depends. In Python, I'd agree with you; if I'm worrying about performance in Python, I'm worrying at the level of the algorithms I'm using. In a constrained embedded C environment, which is where I spend most of my working life, writing your code so that the compiler chooses the right optimisation is critical. Sometimes it matters a great deal to me that something like "x *= 5" compiles to a single ARM instruction, or that splitting a loop into two to avoid a conditional test will let an DSP's optimiser double the speed of a section of code. -- Rhodri James *-* Wildebeest Herder to the Masses From ian.g.kelly at gmail.com Tue Mar 4 20:55:04 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 4 Mar 2014 18:55:04 -0700 Subject: How to create an instance of a python class from C++ In-Reply-To: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 5:14 PM, Bill wrote: > Hello: > > I can't figure out how to create an instance > of a python class from 'C++': > > ( I am relatively new to Python so excuse some of > the following. ) > > In a .py file I create an ABC and then specialize it: Why are you creating an ABC? Most Python classes do not use them. Maybe you have a reason for it, but it's irrelevant to what you're currently trying to do. > Then from 'C++' (my implementation of RegisterClass) > I try to create an instance > > static PyObject * > RegisterClass( PyObject *, PyObject *args ) { // This gets called ok. > > PyObject *class_decl; > if( ! PyArg_ParseTuple(args, "O", &class_decl) ) > return NULL; > Py_INCREF(class_decl); So far, so good. The object that was passed in was the "Derived" class object. Since you presumably only want class objects to be passed in, you might want to check that here using PyType_Check. > PyTypeObject *typ = class_decl->ob_type; Okay, now if class_decl is the class object that was passed in, then class_decl->ob_type is the *type* of that class object -- the metaclass, which in this case would be ABCMeta. You probably don't need this, because you want to instantiate Derived, not ABCMeta. > // Tried this. > // PyObject *an = _PyObject_New(class_decl->ob_type); assert(an); > // PyObject *desc = PyObject_CallMethod(an,"description",NULL); assert(desc); In Python, you instantiate a class by calling it. You should do the same in C, using PyObject_CallFunction. But as above, note that you want to call class_decl, not class_decl->ob_type. PyObject_New doesn't do any initialization and is, I believe, meant to be used when implementing types in C. From roy at panix.com Tue Mar 4 20:57:43 2014 From: roy at panix.com (Roy Smith) Date: Tue, 04 Mar 2014 20:57:43 -0500 Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: In article , Dennis Lee Bieber wrote: > On Wed, 05 Mar 2014 00:48:40 +0200, Marko Rauhamaa > declaimed the following: > > >Ethan Furman : > > > >> Okay, that looks totally cool. Maybe I'll finally get a handle on > >> LISP! :) > > > >Lisp is conceptually simpler than Python, but awe-inspiring. One day, it > >will overtake Python, I believe. I first played with Lisp in 1976. The only time I ever used it for anything serious was an A/I course I took in the mid 80's. At the end of the semester, I was just starting to write things in Lisp (as opposed to writing C transliterated to Lisp syntax and keywords). > It's already had 54 years to become a major language... > > Instead it has schismed into Common Lisp and Scheme (and a few other > dialects) Python has had 23 years to become a major language... Instead it has schismed into Python 2.x and Python 3.x. [holding hands over ears to avoid the howls of derision, while ducking and running] From roy at panix.com Tue Mar 4 21:09:17 2014 From: roy at panix.com (Roy Smith) Date: Tue, 04 Mar 2014 21:09:17 -0500 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: In article , "Rhodri James" wrote: > On Tue, 04 Mar 2014 05:24:03 -0000, Chris Angelico > wrote: > > > Code should look like its intent. Warping it around performance is > > hardly ever worthwhile. > > That depends. In Python, I'd agree with you; if I'm worrying about > performance in Python, I'm worrying at the level of the algorithms I'm > using. In a constrained embedded C environment, which is where I spend > most of my working life, writing your code so that the compiler chooses > the right optimisation is critical. Sometimes it matters a great deal to > me that something like "x *= 5" compiles to a single ARM instruction, or > that splitting a loop into two to avoid a conditional test will let an > DSP's optimiser double the speed of a section of code. Yeah. BTDT. I've stolen the bottom three bits of a pointer for my own use because I know everything is 64-bit aligned so it's all zeros anyway. I feel like there must be some organization I should be going to every month that meets in a church basement and I can get up in front of the room and say, "Hi, my name is Roy and I'm a C++ hacker", and have everybody be supportive. I mostly live in the Python world these days, where I'm firmly in the camp of, "Stay away from O(n^2) and don't hit the database with unindexed queries, and you're probably good". But, that's because we push most of the hard work off onto C and C++ code that is written by guys who worry about the bottom three bits. One of those really awesome tools is haproxy. It's just amazing how fast (and stable) that thing is. It's all written in C. Most of the if statements are decorated with #pragmas telling the compiler which branch is the most likely to be taken, so it can optimize better. We need people like that down in the trenches, so the rest of us can run around naked in the park with flowers in our hair and not worry about the bottom three bits any more. From ikorot01 at gmail.com Tue Mar 4 21:13:43 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 4 Mar 2014 18:13:43 -0800 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: Hi, Mark, On Tue, Mar 4, 2014 at 2:46 PM, Mark Lawrence wrote: > On 04/03/2014 21:55, Igor Korot wrote: >> >> >> But this particular question is easy. >> > > If it's easy why can't you answer it via the docs rather than ask here? What I meant to say is: it is easy for all you people and it is definitely easier than trying to figure out how to process and display different dates. Thank you. > > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > --- > This email is free from viruses and malware because avast! Antivirus > protection is active. > http://www.avast.com > > > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Tue Mar 4 21:19:48 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 4 Mar 2014 18:19:48 -0800 Subject: Proper conversion of timestamp In-Reply-To: <5316730B.3080706@mrabarnett.plus.com> References: <5316730B.3080706@mrabarnett.plus.com> Message-ID: MRAB, On Tue, Mar 4, 2014 at 4:42 PM, MRAB wrote: > On 2014-03-04 21:55, Igor Korot wrote: >> >> Hi, Mark, >> >> >> On Tue, Mar 4, 2014 at 1:44 PM, Mark Lawrence > > wrote: >> >> On 04/03/2014 20:57, Igor Korot wrote: >> >> Hi, ALL, >> I'm getting this: >> >> timestamp out of range for platform localtime()/gmtime() function >> >> trying to convert the timestamp with milliseconds into the >> datetime object. >> >> The first hit of Google gives me this: >> >> >> http://stackoverflow.com/__questions/12458595/convert-__epoch-timestamp-in-python >> >> >> >> >> but the solution described is not good for me since it does not >> gives >> me the milliseconds value. >> >> How do I get the proper datetime value including milliseconds >> from the >> timestamp? >> >> Thank you. >> >> >> You have a long record of asking timestamp related questions so you >> should know where the docs are that provide the answer to this >> question. I'll leave you to go off and read them. If you don't >> understand them, please cut and paste your code here, state what you >> expected to happen, what actually happened, including any traceback >> if applicable, and then we'll be happy to point you the error of >> your ways. >> >> >> Working with the dates is not that easy and not just in Python. >> There are too many different formatting involved with many different >> representation. >> And on top of it it is possible to use one system in completely >> different environment. >> >> But this particular question is easy. >> >> What I have is a timestamp which reads: 1289410678L. >> > That's an integer. It looks like the timestamp is a whole number of > seconds, so the number of milliseconds is 0. (I make it '2010-11-10 > 17:37:58'.) Well it is this particular timestamp. But I have a lot of files to process and some do have a timestamp with the milliseconds. > > >> Trying to convert this into the datetime object in Python using: >> >> import datetime >> datetime.datetime.fromtimestamp( stamp ) >> >> produces the error: timestamp out of range for platform >> localtime()/gmtime() function. >> >> This is because this timestamp is not in seconds, but rather in >> milliseconds. >> >> Now the question I have is: how do I properly convert this timestamp >> into the datetime object with the milliseconds? >> > Using the datetime's .strftime method, you can include the number of > microseconds in the format with '%f' (it'll write the microseconds as 6 > digits). > > If you want it to the nearest millisecond (the timestamp would be a > float), you could round the timestamp to 3 decimal places, use the '%f' > in the format, and then truncate the string result to remove the last 3 > digits. Right. The question is: how to get the number of milliseconds out of timestamp? Once again: I can get the datetime object with the seconds precision by dividing it on 1000. But that will produce the datetime object with the seconds precision. I can actually produce another timestamp with the milliseconds from a different file... Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list From albert at spenarnc.xs4all.nl Tue Mar 4 21:27:51 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 05 Mar 2014 02:27:51 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <53168ba7$0$25064$e4fe514c@dreader37.news.xs4all.nl> In article , Ian Kelly wrote: >On Mon, Mar 3, 2014 at 11:35 PM, Chris Angelico wrote: >> In constant space, that will produce the sum of two infinite sequences >> of digits. (And it's constant time, too, except when it gets a stream >> of nines. Adding three thirds together will produce an infinite loop >> as it waits to see if there'll be anything that triggers an infinite >> cascade of carries.) Now, if there's a way to do that for square >> rooting a number, then the CF notation has a distinct benefit over the >> decimal expansion used here. As far as I know, there's no simple way, >> in constant space and/or time, to progressively yield more digits of a >> number's square root, working in decimal. > >The code for that looks like this: > >def cf_sqrt(n): > """Yield the terms of the square root of n as a continued fraction.""" > m = 0 > d = 1 > a = a0 = floor_sqrt(n) > while True: > yield a > next_m = d * a - m > next_d = (n - next_m * next_m) // d > if next_d == 0: > break > next_a = (a0 + next_m) // next_d > m, d, a = next_m, next_d, next_a > > >def floor_sqrt(n): > """Return the integer part of the square root of n.""" > n = int(n) > if n == 0: return 0 > lower = 2 ** int(math.log(n, 2) // 2) > upper = lower * 2 > while upper - lower > 1: > mid = (upper + lower) // 2 > if n < mid * mid: > upper = mid > else: > lower = mid > return lower > > >The floor_sqrt function is merely doing a simple binary search and >could probably be optimized, but then it's only called once during >initialization anyway. The meat of the loop, as you can see, is just >a constant amount of integer arithmetic. If it were desired to halt >once the continued fraction starts to repeat, that would just be a >matter of checking whether the triple (m, d, a) has been seen already. > >Going back to your example of adding generated digits though, I don't >know how to add two continued fractions together without evaluating >them. That is highly non-trivial indeed. See the gosper.txt reference I gave in another post. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From harrismh777 at gmail.com Tue Mar 4 21:28:30 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Tue, 4 Mar 2014 18:28:30 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <44cb976d-cb25-468a-8525-edbf4b539f60@googlegroups.com> <1ba60da3-93d4-4bca-ab96-9f94e6afe519@googlegroups.com> <27d19767-84ee-4ab7-87fd-784e8ac57680@googlegroups.com> Message-ID: <8386c37e-239a-4c60-9fbb-0a368d0c5d82@googlegroups.com> On Tuesday, March 4, 2014 3:35:48 PM UTC-6, Stefan Krah wrote: > http://www.bytereef.org/mpdecimal/quickstart.html#factorial-in-pure-python > Be sure to set MAX_EMAX and MIN_EMIN, that's missing in the example. > http://www.bytereef.org/mpdecimal/benchmarks.html#arbitrary-precision-libraries > Stefan Krah hi Stefan! Good to hear from you, sir. My hat is off to you for sure, and thank you very kindly for your good work on the decimal.Decimal code; ~very nice! {hands clapping} Thanks for the input above, will read. Stay in touch. I have an expansion of my decimal idea for python (stay tuned on python-ideas) which I think will be for the better, if we can convince wide adoption; could be an up-hill climb, but who knows. Its been good to meet you in the code, and now a true pleasure to meet you on-line as well. Hope to see you sometime at a python convention perhaps. Best regards, Mark H Harris From wuwei23 at gmail.com Tue Mar 4 21:28:45 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 05 Mar 2014 12:28:45 +1000 Subject: How do I process this? In-Reply-To: References: Message-ID: On 4/03/2014 2:03 PM, Igor Korot wrote: > Hi, ALL, > I have a csv file which depending on how it was produced gives 2 > different strings as shown in the example below (test1 and test2). > I am only interested in the first field in test1 and obviously in the > whole string of test2. > >>> test1 = "a,,,," > >>> test2 = "a" Try using the csv module: >>> from StringIO import StringIO >>> csvfile = StringIO() >>> csvfile.write('a,,,,\n') >>> csvfile.write('a\n') >>> csvfile.seek(0) >>> >>> import csv >>> reader = csv.reader(csvfile) >>> [x[0] for x in reader] ['a', 'a'] From ben+python at benfinney.id.au Tue Mar 4 21:33:47 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Mar 2014 13:33:47 +1100 Subject: Proper conversion of timestamp References: <5316730B.3080706@mrabarnett.plus.com> Message-ID: <85siqxfk6s.fsf@benfinney.id.au> Igor Korot writes: > On Tue, Mar 4, 2014 at 4:42 PM, MRAB wrote: > >> But this particular question is easy. > >> > >> What I have is a timestamp which reads: 1289410678L. > >> > > That's an integer. It looks like the timestamp is a whole number of > > seconds, so the number of milliseconds is 0. (I make it '2010-11-10 > > 17:37:58'.) > > Well it is this particular timestamp. Which is what you presented as ?what I have?. > But I have a lot of files to process and some do have a timestamp with > the milliseconds. So, if you want help with such timestamps, you'll need to present a real example (or preferably several exmaples) of timestamps that need this handling. > Right. > The question is: how to get the number of milliseconds out of > timestamp? >From the timestamp you showed: The number of milliseconds is zero, since it's an integer. That datatype will *always* have zero milliseconds. > Once again: I can get the datetime object with the seconds precision > by dividing it on 1000. But that will produce the datetime object with > the seconds precision. Because that's the data you're showing us: A timestamp with an integer number of seconds. > I can actually produce another timestamp with the milliseconds from a > different file... Then you won't be able to represent it as an integer number of seconds. What are you receiving in the data? What data type is it? -- \ ?He who allows oppression, shares the crime.? ?Erasmus Darwin, | `\ grandfather of Charles Darwin | _o__) | Ben Finney From albert at spenarnc.xs4all.nl Tue Mar 4 21:15:14 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 05 Mar 2014 02:15:14 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> Message-ID: <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> In article , Chris Angelico wrote: >On Tue, Mar 4, 2014 at 1:45 PM, Albert van der Horst > wrote: >>>No, the Python built-in float type works with a subset of real numbers: >> >> To be more precise: a subset of the rational numbers, those with a denominator >> that is a power of two. > >And no more than N bits (53 in a 64-bit float) in the numerator, and >the denominator between the limits of the exponent. (Unless it's >subnormal. That adds another set of small numbers.) It's a pretty >tight set of restrictions, and yet good enough for so many purposes. > >But it's a far cry from "all real numbers". Even allowing for >continued fractions adds only some more; I don't think you can >represent surds that way. Adding cf's adds all computable numbers in infinite precision. However that is not even a drop in the ocean, as the computable numbers have measure zero. A cf object yielding its coefficients amounts to a program that generates an infinite amount of data (in infinite time), so it is not very surprising it can represent any computable number. Pretty humbling really. > >ChrisA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From breamoreboy at yahoo.co.uk Tue Mar 4 21:39:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 02:39:34 +0000 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: On 05/03/2014 02:13, Igor Korot wrote: > Hi, Mark, > > On Tue, Mar 4, 2014 at 2:46 PM, Mark Lawrence wrote: >> On 04/03/2014 21:55, Igor Korot wrote: >>> >>> >>> But this particular question is easy. >>> >> >> If it's easy why can't you answer it via the docs rather than ask here? > > What I meant to say is: it is easy for all you people and it is > definitely easier than > trying to figure out how to process and display different dates. > > Thank you. > You've never once referred to anything that you've read in the docs but don't understand, so how can we help you? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From albert at spenarnc.xs4all.nl Tue Mar 4 21:38:18 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 05 Mar 2014 02:38:18 GMT Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <871tz7864a.fsf@elektro.pacujo.net> <87fvnm7q1n.fsf@elektro.pacujo.net> Message-ID: <53168e1a$0$25064$e4fe514c@dreader37.news.xs4all.nl> In article <87fvnm7q1n.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: >Chris Angelico : > >> On Fri, Feb 14, 2014 at 1:00 AM, Marko Rauhamaa wrote: >>> Well, if your idealized, infinite, digital computer had ?????? bytes of RAM >>> and ran at ?????? hertz and Python supported transfinite iteration, you >>> could easily do reals: >>> >>> for x in continuum(0, max(1, y)): >> >> How exactly do you iterate over a continuum, with a digital computer? > >How "digital" our idealized computers are is a matter for a debate. >However, iterating over the continuum is provably "possible:" > > http://en.wikipedia.org/wiki/Transfinite_induction > >> it would take a finite amount of time to assign to x the "next >> number", ergo your algorithm can't guarantee to finish in finite time. > >My assumption was you could execute ?????? statements per second. That >doesn't guarantee a finite finish time but would make it possible. That >is because > > ?????? * ?????? = ?????? = ?????? * 1 > >This computer is definitely more powerful than a Turing machine, which >only has ?????? bytes of RAM and thus can't even store an arbitrary real >value in memory. You're very much off the track here. A Turing machine is an abstraction for a computer were the limitations of size are gone. The most obvious feature of a Turing machine is an infinite tape. A Turing machine happily calculates Ackerman functions long after a real machine runs out of memory to represent it, with as a result a number of ones on that tape. But it only happens in the mathematicians mind. > > >Marko -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From breamoreboy at yahoo.co.uk Tue Mar 4 22:06:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 03:06:05 +0000 Subject: 3.4rc2 and pip on windows In-Reply-To: References: Message-ID: On 04/03/2014 05:32, Terry Reedy wrote: > On 3/3/2014 2:47 PM, Mark Lawrence wrote: >> On 03/03/2014 00:07, Terry Reedy wrote: >>> On 3/2/2014 6:55 PM, Mark Lawrence wrote: >>>> Trying to install pyttsx, it doesn't strike me as very clever that, as >>>> seen below, you get "Successfully installed pyttsx" despite the syntax >>>> errors and you can't actually do an import. >>>> >>>> c:\Users\Mark\CrossCode>c:\Python34\Scripts\pip3.4.exe install pyttsx >>>> Downloading/unpacking pyttsx >>>> Downloading pyttsx-1.1.tar.gz >>>> Running setup.py >>>> (path:C:\Users\Mark\AppData\Local\Temp\pip_build_Mark\pyttsx\setup.py) >>>> egg_info for package pyttsx >>>> >>>> Installing collected packages: pyttsx >>>> Running setup.py install for pyttsx >>>> File "C:\Python34\Lib\site-packages\pyttsx\driver.py", line 105 >>>> except Exception, e >>>> ^ >>>> SyntaxError: invalid syntax > > This is from setup.py > > >>>> [other syntax errors snipped] >>>> >>>> Successfully installed pyttsx > > This is from pip, saying that it successfully downloaded and installed > the files on your disk, which it did. > >>> A bug it seems to me. > > After reading the responses on the tracker and here, the bug is in the > total systen of interaction of multiple parts. It is not a bug for the > part covered by the tracker. > >>>> Cleaning up... >>>> >>>> c:\Users\Mark\CrossCode>py -3.4 >>>> Python 3.4.0rc2 (v3.4.0rc2:a300712ed38c, Feb 23 2014, 10:49:04) [MSC >>>> v.1600 32 bit (Intel)] on win32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>> import pyttsx >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> File "C:\Python34\lib\site-packages\pyttsx\__init__.py", line 18, in >>>> >>>> from engine import Engine >>>> >>>> I've looked at pyttsx in my 3.3 site-packages and it appears that I've >>>> manually run 2to3. Is this something that could be done automatically >>>> by pip? Your thoughts please, ladies and gentlemen. >>> >>> I should hope so. > >> FTR I raised this as http://bugs.python.org/issue20846 and it was closed >> 11 minutes after I raised it. I won't say anything else as I'm >> extremely tired and irritable and might well regret it later. > > The issue brought to attention that the parts do not work together > perfectly yet and stimulated some thought and some clarification on what > needs to be done. I understand the irritation, but sleeping on it and > letting it go is a good idea. > Attempted overnight sleep failed :( Sleeping late afternoon and early evening GMT yesterday 04/03/2014 succeeded :) Having raised the issue I certainly understand things much better, especially because of the words from Ned Deilly. So a question springs to my mind. How do we educate the people putting their code on pypi to correctly set up the relevant fields so that it can be correctly handled by any tools that want to download from pypi? How does the lack of correct data and/or code on pypi add more credence to the impression that libraries are not ready for Python 3 when in actual fact they are? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rustompmody at gmail.com Tue Mar 4 22:36:38 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 19:36:38 -0800 (PST) Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> On Wednesday, March 5, 2014 7:39:17 AM UTC+5:30, Roy Smith wrote: > "Rhodri James" wrote: > > wrote: > > > Code should look like its intent. Warping it around performance is > > > hardly ever worthwhile. > > That depends. In Python, I'd agree with you; if I'm worrying about > > performance in Python, I'm worrying at the level of the algorithms I'm > > using. In a constrained embedded C environment, which is where I spend > > most of my working life, writing your code so that the compiler chooses > > the right optimisation is critical. Sometimes it matters a great deal to > > me that something like "x *= 5" compiles to a single ARM instruction, or > > that splitting a loop into two to avoid a conditional test will let an > > DSP's optimiser double the speed of a section of code. > Yeah. BTDT. I've stolen the bottom three bits of a pointer for my own > use because I know everything is 64-bit aligned so it's all zeros > anyway. I feel like there must be some organization I should be going > to every month that meets in a church basement and I can get up in front > of the room and say, "Hi, my name is Roy and I'm a C++ hacker", and have > everybody be supportive. > I mostly live in the Python world these days, where I'm firmly in the > camp of, "Stay away from O(n^2) and don't hit the database with > unindexed queries, and you're probably good". But, that's because we > push most of the hard work off onto C and C++ code that is written by > guys who worry about the bottom three bits. > One of those really awesome tools is haproxy. It's just amazing how > fast (and stable) that thing is. It's all written in C. Most of the if > statements are decorated with #pragmas telling the compiler which branch > is the most likely to be taken, so it can optimize better. We need > people like that down in the trenches, so the rest of us can run around > naked in the park with flowers in our hair and not worry about the > bottom three bits any more. I agree with most of the sentiment above... Except the implication that C and C++ are equivalent I wrote http://www.the-magus.in/Publications/chor.pdf 25 years ago criticising C *in education*. I was half my age then and used stronger language then than I would now Ive tried to express some pangs of conscience here http://blog.languager.org/2013/02/c-in-education-and-software-engineering.html However my point then as now was: "C is dangerous to TEACH CS/programming with. Its sweet if you KNOW what you are up to." With C++ its horrible all the way - C++ has pretentious abstractions that invariably leak* C is honest in having few abstractions - C++ syntax is ridiculously brittle. C syntax is mostly straightforward - One of C's difficulties is complex binding-times: pre-process, compile, link load, run. Needs work but is master-able. With C++ Ive not got the basics after 25 years -- order of static constructors, templates... - I dont believe its coincidence that most of the rock-solid software I use has a C (not C++) under-belly -- python, linux-kernel, emacs, gcc, haskell, git, latex With apps in C++ its always catching-cook -- will it segfault me before I save my file? - Some guys with a wee bit more reputation who seem to agree with yours truly o http://article.gmane.org/gmane.comp.version-control.git/57918 o http://harmful.cat-v.org/software/c++/rms * ... which summarizes my objection in this thread: Python's 'is' leaks the machine abstraction. 'id' does it legitimately (somewhat), 'is' does it illegitimately From steve at pearwood.info Tue Mar 4 22:41:13 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 03:41:13 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> Message-ID: <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> On Wed, 05 Mar 2014 02:15:14 +0000, Albert van der Horst wrote: > Adding cf's adds all computable numbers in infinite precision. However > that is not even a drop in the ocean, as the computable numbers have > measure zero. On the other hand, it's not really clear that the non-computable numbers are useful or necessary for anything. They exist as mathematical abstractions, but they'll never be the result of any calculation or measurement that anyone might do. -- Steven From rustompmody at gmail.com Tue Mar 4 22:45:04 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 19:45:04 -0800 (PST) Subject: Origin of 'self' In-Reply-To: References: <7edah9989mdjb9mrnrsh5067np0ihv1jml@4ax.com> Message-ID: <49693163-cb83-4651-81c5-241fad6145d5@googlegroups.com> On Tuesday, March 4, 2014 6:17:09 PM UTC+5:30, MRAB wrote: > On 2014-03-04 02:09, Dennis Lee Bieber wrote: > > On Sun, 2 Mar 2014 22:16:31 -0800 (PST), Westley Mart?nez declaimed: > >> I understand that in an object method the first argument in the > >> object itself, called self. However, it doesn't have to be called > >> self, and can be called anything. So my question is why is it > >> called self and not this like from C++ and Java. It's kind of a > >> silly question, but one that I'm curious about nevertheless. > > It didn't want to be egotistical (as I recall, M$ VB uses "me") > So does AppleScript. > > In AppleScript a script can refer to the title of a window as "title of > window" or "window's title", and it can refer to the title of its own > window as "title of window of me" or "me's window's title". Consistent, > yes, but bad English. > That's why I prefer a programming language not to be too much like a > natural language. :-) > There could be other conclusions. Such as that English could learn from AppleScript to not make bogus distinctions between me and my. Or latin in which case is sufficiently explicit that word-order does not matter Reminds me of "How do we know whether smoking causes cancer or cancer causes smoking?" From python at mrabarnett.plus.com Tue Mar 4 22:58:33 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 05 Mar 2014 03:58:33 +0000 Subject: Origin of 'self' In-Reply-To: <49693163-cb83-4651-81c5-241fad6145d5@googlegroups.com> References: <7edah9989mdjb9mrnrsh5067np0ihv1jml@4ax.com> <49693163-cb83-4651-81c5-241fad6145d5@googlegroups.com> Message-ID: <5316A0E9.90003@mrabarnett.plus.com> On 2014-03-05 03:45, Rustom Mody wrote: > On Tuesday, March 4, 2014 6:17:09 PM UTC+5:30, MRAB wrote: >> On 2014-03-04 02:09, Dennis Lee Bieber wrote: >> > On Sun, 2 Mar 2014 22:16:31 -0800 (PST), Westley Mart?nez declaimed: > >> >> I understand that in an object method the first argument in the >> >> object itself, called self. However, it doesn't have to be called >> >> self, and can be called anything. So my question is why is it >> >> called self and not this like from C++ and Java. It's kind of a >> >> silly question, but one that I'm curious about nevertheless. >> > It didn't want to be egotistical (as I recall, M$ VB uses "me") >> So does AppleScript. > >> > >> In AppleScript a script can refer to the title of a window as "title of >> window" or "window's title", and it can refer to the title of its own >> window as "title of window of me" or "me's window's title". Consistent, >> yes, but bad English. > >> That's why I prefer a programming language not to be too much like a >> natural language. :-) > >> > > > > There could be other conclusions. Such as that English could learn > from AppleScript to not make bogus distinctions between me and my. Or > latin in which case is sufficiently explicit that word-order does not matter > Latin's not that explicit: the endings aren't unique within a declension. > > Reminds me of > "How do we know whether smoking causes cancer or cancer causes smoking?" > > > > From harrismh777 at gmail.com Tue Mar 4 23:03:13 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Tue, 4 Mar 2014 20:03:13 -0800 (PST) Subject: Geezer learns python In-Reply-To: References: Message-ID: <04771cd8-4702-4fb6-a49d-29e265f51927@googlegroups.com> On Tuesday, March 4, 2014 5:03:13 PM UTC-6, notbob wrote: {snip} hi notbob, Get a good book on python3 programming {Barnes and Noble, Amazon} and please, start with python (3). Great book: & fabulous tutorial: Summerfield, Mark. Programming in Python 3: A Complete Introduction to the Python Language. Developer's Library. 2nd Edition. (Upper Saddle River: Addison-Wesley, 2010) The book is 630 pages, illustrated, and explains everything with very clear insightful use cases, example coding, and exercises. It is also not a bad reference, although there are better ones. IMHO if you can purchase just one book on python programming, this is it. Also, don't forget that google is your friend. You will find the python community very friendly (as compared to some groups) but folks can be short if the questions show little or no research. There are great tutorials on-line for python too, and very good doc. Start here: http://docs.python.org/3.3/tutorial/ Also Docs: http://docs.python.org/3.3/# Cheers marcus From ian.g.kelly at gmail.com Tue Mar 4 23:08:58 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 4 Mar 2014 21:08:58 -0700 Subject: Reference In-Reply-To: <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> Message-ID: On Tue, Mar 4, 2014 at 8:36 PM, Rustom Mody wrote: > * ... which summarizes my objection in this thread: Python's 'is' leaks the > machine abstraction. 'id' does it legitimately (somewhat), > 'is' does it illegitimately Well, since "if x == None" is buggy as a test for sentinel values, that means the only legitimate non-buggy way to do it is with "if id(x) == id(None)", which just seems gross to me. From greg.ewing at canterbury.ac.nz Tue Mar 4 23:06:47 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 05 Mar 2014 17:06:47 +1300 Subject: Proper conversion of timestamp In-Reply-To: References: Message-ID: Igor Korot wrote: > What I have is a timestamp which reads: 1289410678L. > > Trying to convert this into the datetime object in Python using: > > import datetime > datetime.datetime.fromtimestamp( stamp ) > > produces the error: timestamp out of range for platform > localtime()/gmtime() function. Divide the timestamp by 1000.0 to give floating point seconds, and then use datetime.fromtimestamp(). >>> d = datetime.datetime.fromtimestamp(1289410678 / 1000.0) >>> d datetime.datetime(1970, 1, 16, 10, 10, 10, 678000) >>> d.strftime("%Y-%m-%d-%H:%M:%S.%f")[:-3] '1970-01-16-10:10:10.678' -- Greg From python at mrabarnett.plus.com Tue Mar 4 23:11:05 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 05 Mar 2014 04:11:05 +0000 Subject: Proper conversion of timestamp In-Reply-To: <85siqxfk6s.fsf@benfinney.id.au> References: <5316730B.3080706@mrabarnett.plus.com> <85siqxfk6s.fsf@benfinney.id.au> Message-ID: <5316A3D9.4050305@mrabarnett.plus.com> On 2014-03-05 02:33, Ben Finney wrote: > Igor Korot writes: > >> On Tue, Mar 4, 2014 at 4:42 PM, MRAB wrote: >> >> But this particular question is easy. >> >> >> >> What I have is a timestamp which reads: 1289410678L. >> >> >> > That's an integer. It looks like the timestamp is a whole number of >> > seconds, so the number of milliseconds is 0. (I make it '2010-11-10 >> > 17:37:58'.) >> >> Well it is this particular timestamp. > > Which is what you presented as ?what I have?. > I'd expect all of the timestamps to be the same type. That example is an integer (a 'long' to be exact). >> But I have a lot of files to process and some do have a timestamp with >> the milliseconds. > > So, if you want help with such timestamps, you'll need to present a real > example (or preferably several exmaples) of timestamps that need this > handling. > >> Right. >> The question is: how to get the number of milliseconds out of >> timestamp? > > From the timestamp you showed: The number of milliseconds is zero, since > it's an integer. That datatype will *always* have zero milliseconds. > >> Once again: I can get the datetime object with the seconds precision >> by dividing it on 1000. But that will produce the datetime object with >> the seconds precision. > > Because that's the data you're showing us: A timestamp with an integer > number of seconds. > And in Python 2, an integer divided by an integer gives an integer. >> I can actually produce another timestamp with the milliseconds from a >> different file... > > Then you won't be able to represent it as an integer number of seconds. > What are you receiving in the data? What data type is it? > From python at mrabarnett.plus.com Tue Mar 4 23:11:58 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 05 Mar 2014 04:11:58 +0000 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: <5316A40E.2080903@mrabarnett.plus.com> On 2014-03-05 01:57, Roy Smith wrote: > In article , > Dennis Lee Bieber wrote: > >> On Wed, 05 Mar 2014 00:48:40 +0200, Marko Rauhamaa >> declaimed the following: >> >> >Ethan Furman : >> > >> >> Okay, that looks totally cool. Maybe I'll finally get a handle on >> >> LISP! :) >> > >> >Lisp is conceptually simpler than Python, but awe-inspiring. One day, it >> >will overtake Python, I believe. > > I first played with Lisp in 1976. The only time I ever used it for > anything serious was an A/I course I took in the mid 80's. At the end > of the semester, I was just starting to write things in Lisp (as opposed > to writing C transliterated to Lisp syntax and keywords). > >> It's already had 54 years to become a major language... >> >> Instead it has schismed into Common Lisp and Scheme (and a few other >> dialects) > > Python has had 23 years to become a major language... > > Instead it has schismed into Python 2.x and Python 3.x. > Into how many versions did Lisp split in its first 23 years? :-) > [holding hands over ears to avoid the howls of derision, while ducking > and running] > From rustompmody at gmail.com Tue Mar 4 23:15:19 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 20:15:19 -0800 (PST) Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wednesday, March 5, 2014 9:11:13 AM UTC+5:30, Steven D'Aprano wrote: > On Wed, 05 Mar 2014 02:15:14 +0000, Albert van der Horst wrote: > > Adding cf's adds all computable numbers in infinite precision. However > > that is not even a drop in the ocean, as the computable numbers have > > measure zero. > On the other hand, it's not really clear that the non-computable numbers > are useful or necessary for anything. They exist as mathematical > abstractions, but they'll never be the result of any calculation or > measurement that anyone might do. There are even more extreme versions of this amounting to roughly this view: "Any infinity supposedly 'larger' than the natural numbers is a nonsensical notion." See eg http://en.wikipedia.org/wiki/Controversy_over_Cantor%27s_theory and Weyl/Polya bet (pg 10 of http://research.microsoft.com/en-us/um/people/gurevich/Opera/123.pdf ) I cannot find the exact quote so from memory Weyl says something to this effect: Cantor's diagonalization PROOF is not in question. Its CONCLUSION very much is. The classical/platonic mathematician (subject to wooly thinking) concludes that the real numbers are a superset of the integers The constructvist mathematician (who supposedly thinks clearly) only concludes the obvious, viz that real numbers cannot be enumerated To go from 'cannot be enumerated' to 'is a proper superset of' requires the assumption of 'completed infinities' and that is not math but theology From gheskett at wdtv.com Tue Mar 4 23:27:13 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 4 Mar 2014 23:27:13 -0500 Subject: How security holes happen In-Reply-To: References: Message-ID: <201403042327.14066.gheskett@wdtv.com> On Tuesday 04 March 2014 23:17:40 Andrew Cooper did opine: > On 03/03/2014 22:19, Cameron Simpson wrote: > > On 03Mar2014 09:17, Neal Becker wrote: > >> Charles R Harris Wrote in message: > >> Imo the lesson here is never write in low level c. Use modern > >> > >> languages with well designed exception handling. > > > > What, and rely on someone else's low level C? > > Why is C the lowest denominator? > > Even with correctly written C and assembly, how can you be sure that > your processor is executing the SYSRET instruction safely? > (CVE-2012-0217 for anyone interested) > If you do not have the system tools to determine that, the system is seriously incomplete. Change os's, its that simple when you are down to the bare metal. If I wanted to determine that was correct on the TRS-80 Color Computer 3 in the basement, running nitros9 right now, I would put 3 calls to F$RegDump in the assembly code, one in the caller as the last thing done before the call, one in the subroutine immediately in front of the return, and one as the first operation done when the return register image has been pulled from the stack. > ~Andrew Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page NOTICE: Will pay 100 USD for an HP-4815A defective but complete probe assembly. From roy at panix.com Tue Mar 4 23:25:37 2014 From: roy at panix.com (Roy Smith) Date: Tue, 04 Mar 2014 23:25:37 -0500 Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: In article , Rustom Mody wrote: > I cannot find the exact quote so from memory Weyl says something to this > effect: > > Cantor's diagonalization PROOF is not in question. > Its CONCLUSION very much is. > The classical/platonic mathematician (subject to wooly thinking) concludes > that > the real numbers are a superset of the integers > > The constructvist mathematician (who supposedly thinks clearly) only > concludes > the obvious, viz that real numbers cannot be enumerated > > To go from 'cannot be enumerated' to 'is a proper superset of' requires the > assumption of 'completed infinities' and that is not math but theology I stopped paying attention to mathematicians when they tried to convince me that the sum of all natural numbers is -1/12. Sure, you can manipulate the symbols in a way which is consistent with some set of rules that we believe govern the legal manipulation of symbols, but it just plain doesn't make sense. From ben+python at benfinney.id.au Tue Mar 4 23:32:16 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Mar 2014 15:32:16 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> Message-ID: <85ob1lfepb.fsf@benfinney.id.au> Rustom Mody writes: > * ... which summarizes my objection in this thread: Your long post references many things. Which is the ?which? to which you refer? What is it you're referring to that summarises your position? > Python's 'is' leaks the machine abstraction. No, it does not. The ?is? operator compares object identity, which is itself an abstraction. What is leaking? Note that the ?location of the object in memory? is not a guarantee made by either Python's object identity nor the ?id? function. There's no need to treat ?object location in memory? as equal to ?object identity?, and code which makes that assumption is buggy. The documentation doesn't promise they will be the same. So, the fact that some Python implementations happen to present ?id(foo)? values that coincide with a representation of memory location, does not constitute a leaky abstraction: there is no need for any Python programmer to care about what the memory location is. So if that's the basis of your objection, I don't consider that objection to be legitimate. > 'id' does it legitimately (somewhat), 'is' does it illegitimately What would, in your view, be a legitimate way for Python to present object identity to the programmer? How would it differ substantially from Python's existing abstraction of object identity? -- \ ?That's all very good in practice, but how does it work in | `\ *theory*?? ?anonymous | _o__) | Ben Finney From rustompmody at gmail.com Tue Mar 4 23:31:52 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 20:31:52 -0800 (PST) Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> Message-ID: <16c6d0af-924c-4b44-9d0a-614ccde61720@googlegroups.com> On Wednesday, March 5, 2014 9:38:58 AM UTC+5:30, Ian wrote: > On Tue, Mar 4, 2014 at 8:36 PM, Rustom Mody wrote: > > * ... which summarizes my objection in this thread: Python's 'is' leaks the > > machine abstraction. 'id' does it legitimately (somewhat), > > 'is' does it illegitimately > Well, since "if x == None" is buggy as a test for sentinel values, > that means the only legitimate non-buggy way to do it is with "if > id(x) == id(None)", which just seems gross to me. Ha Ha! -- Fully agreed! One should not need to leak the machine abstraction for something as basic as None testing As I said earlier my current preference which is least disruptive is to have as builtin def isNone(x): return x is None which should obviate most (basic) uses of is From ben+python at benfinney.id.au Tue Mar 4 23:37:44 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Mar 2014 15:37:44 +1100 Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <85k3c9feg7.fsf@benfinney.id.au> Roy Smith writes: > I stopped paying attention to mathematicians when they tried to convince > me that the sum of all natural numbers is -1/12. I stopped paying attention to a particular person when they said ?I stopped paying attention to an entire field of study because one position expressed by some practicioners was disagreeable to me?. Would you think ?I stopped listening to logicians when some of them expressed Zeno's paradox of the impossibility of motion? to be a good justification for ignoring the entire field of logic? Rather, a more honest response is to say why that position is incorrect, and not dismiss the entire field of study merely for a disagreement with that position. -- \ ?Life does not cease to be funny when people die any more than | `\ it ceases to be serious when people laugh.? ?George Bernard Shaw | _o__) | Ben Finney From rustompmody at gmail.com Tue Mar 4 23:47:36 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 20:47:36 -0800 (PST) Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> Message-ID: <79068c6c-b0bc-4917-af6e-80f497a0474c@googlegroups.com> On Wednesday, March 5, 2014 10:02:16 AM UTC+5:30, Ben Finney wrote: > Rustom Mody writes: > > * ... which summarizes my objection in this thread: > Your long post references many things. Which is the "which" to which you > refer? What is it you're referring to that summarises your position? Text : C++ has pretentious abstractions that invariably leak* Footnote: * ... which summarizes my objection in this thread: Python's 'is' leaks the machine abstraction. 'id' does it legitimately (somewhat), 'is' does it illegitimately Not sure whats not clear: "is" in python leaks machine representations into the otherwise clean HLL abstraction in python like in C++ From rustompmody at gmail.com Tue Mar 4 23:57:09 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 20:57:09 -0800 (PST) Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wednesday, March 5, 2014 10:07:44 AM UTC+5:30, Ben Finney wrote: > Roy Smith writes: > > I stopped paying attention to mathematicians when they tried to convince > > me that the sum of all natural numbers is -1/12. > I stopped paying attention to a particular person when they said "I > stopped paying attention to an entire field of study because one > position expressed by some practicioners was disagreeable to me". In general this is a correct response In this particular case (apart from Roy speaking tongue-in-cheek) it (Roy's viewpoint) is more appropriate and central to our field than you perhaps realize: Nonsensical results believed in by a small minority (Cantor's time) became full scale war between platonists (Hilbert) and constructivists (Brouwer) a generation later. G?del staunchly in Hilbert camp made his incompleteness theorem to rebut the constructivists Turing unable to disagree with G?del's result but disagreeing with platonic philosophy made his 'machine'. The negative result that he did not like but had to admit was uncomputability/undecidability. However he trumped G?del in making a 'universal' machine And so we are here :-) From steve at pearwood.info Wed Mar 5 00:06:37 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 05:06:37 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> Message-ID: <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 04 Mar 2014 19:36:38 -0800, Rustom Mody wrote: > Python's 'is' leaks > the machine abstraction. 'id' does it legitimately (somewhat), 'is' does > it illegitimately and then later in another post: > "is" in python leaks machine representations > into the otherwise clean HLL abstraction in python Rather than respond with incredulity and declare that you have no idea what you are talking about, I'll give you the benefit of the doubt, and accept the possibility that I am wrong, or possibly misunderstanding you. Can you explain what machine representations are leaked into Python by the is operator? Do you see this as an accident of implementation, a bug that might be fixed, or a misfeature that was deliberately designed? Can you elaborate on why id() is legitimate and "is" is not? -- Steven From roy at panix.com Wed Mar 5 00:29:43 2014 From: roy at panix.com (Roy Smith) Date: Wed, 05 Mar 2014 00:29:43 -0500 Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: In article , Ben Finney wrote: > Roy Smith writes: > > > I stopped paying attention to mathematicians when they tried to convince > > me that the sum of all natural numbers is -1/12. > > I stopped paying attention to a particular person when they said ???I > stopped paying attention to an entire field of study because one > position expressed by some practicioners was disagreeable to me???. > > Would you think ???I stopped listening to logicians when some of them > expressed Zeno's paradox of the impossibility of motion??? to be a good > justification for ignoring the entire field of logic? > > Rather, a more honest response is to say why that position is incorrect, > and not dismiss the entire field of study merely for a disagreement with > that position. I *was* partly joking (but only partly). Still, there's lots of stuff mathematicians do which I don't understand. I cannot understand, for example, Andrew's Wiles's proof of Fermat's Last Theorm. I can't even get past the first few paragraphs of the Wikipedia article. But, that doesn't sour me on the proof. I can accept that there are things I don't understand. I don't know how to speak Chinese. I don't know how to paint a flower. I don't know how to run a mile in 4 minutes. But I accept that there are people who do know how to do those things. I can watch a friend pick up a piece of paper, a brush, and some watercolors and 5 minutes later, she's got a painting of a flower. I watched her hands hold the brush and move it over the paper. There's nothing mystical about what she did. Her hands made no motions which are fundamentally impossible for my hands to make, yet I know that my attempt at reproducing her work would not result in a painting of a flower. But, as I watch the -1/12 proof unfold, I don't get the same feeling. I understand every step. I wouldn't have thought to manipulate the symbols that way, but once I've seen it done, I can reproduce the steps myself. It's all completely understandable. The only problem is, it results in a conclusion which makes no sense. I can *prove* that it makes no sense, by manipulating the symbols in different ways. The sum of any two positive numbers must be positive. I can group them and add them up any way I want and that's still true. But, here I've got some guy telling me it's not true. If you just slide this over that way, and add these parts up this way, it's -1/12. That does not compute. But it doesn't not compute in the sense of, "that's so complicated, I have no idea what you did", but in the sense of "thats so simple, I know exactly what you did, and it's bullshit" :-) From rustompmody at gmail.com Wed Mar 5 00:47:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 21:47:21 -0800 (PST) Subject: Reference In-Reply-To: <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> On Wednesday, March 5, 2014 10:36:37 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 19:36:38 -0800, Rustom Mody wrote: > > Python's 'is' leaks > > the machine abstraction. 'id' does it legitimately (somewhat), 'is' does > > it illegitimately > and then later in another post: > > "is" in python leaks machine representations > > into the otherwise clean HLL abstraction in python > Rather than respond with incredulity and declare that you have no idea > what you are talking about, I'll give you the benefit of the doubt, and > accept the possibility that I am wrong, or possibly misunderstanding you. Umm... I guess my language was sloppy (a bit) A machine is ultimately also an abstraction -- What is firmware/microcode? Is it a virtual machine? etc Lets leave that however and just take 'machine' as a given. Using machines as given, we build reprs for our (programmer's) data structures So data structures are abstractions that have two 'faces' -- the machine-facing and the programmer-facing For clarity of expression (and where you perhaps found me sloppy?? not sure...) its best to call the machine-face 'a representation' and the programmer-face 'an abstraction' Clearly this is a programmer-biased viewpoint. A hardware engineer would see things differently. As would the user of the app the programmer programs. Which is why to use the locution "is" without appropriate framing is philosopical is a pretension to a 'God's-eye-view'. If you are privy to such a viewpoint I'd be interested to know But for the rest of us who are not, its good to remember there are only perspectives no absolute truth. That python is a hll means that machine reprs are intended to be abstracted away. 'is' fails to do that -- proof of that being the discrepancy between is and == > Can you explain what machine representations are leaked into Python by > the is operator? > Do you see this as an accident of implementation, a bug that might be > fixed, or a misfeature that was deliberately designed? > Can you elaborate on why id() is legitimate and "is" is not? Let me talk of Lisp which is IMHO more philosophically sane. Lisp has eq eql equal and a few type-specific others such as = for numbers string-= for strings etc eq is roughly python's 'is' equal is roughl python's == The type-specific ones error out rather than returning false for out-of-bounds types. So much for the technology Now to the philosophy behind it: Decide the viewpoint -- choose the appropriate equivence predicate No claim even remotely to having a clue to metaphysical being that python's 'is' implies From wuwei23 at gmail.com Wed Mar 5 01:01:04 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 05 Mar 2014 16:01:04 +1000 Subject: Reference In-Reply-To: <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: On 5/03/2014 3:47 PM, Rustom Mody wrote: > That python is a hll means that machine reprs are intended to be abstracted > away. 'is' fails to do that -- proof of that being the discrepancy between > is and == The "discrepancy" is because _they're fundamentally different_: >>> a = b = [1,2] >>> c = [1,2] >>> a is b True >>> a is c False >>> a == b True >>> a == c True `is` is used to determine if two names refer to the same object. `==` is used to determine if they're equivalent in value. Both have their uses. From rustompmody at gmail.com Wed Mar 5 01:03:36 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 22:03:36 -0800 (PST) Subject: Reference In-Reply-To: <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wednesday, March 5, 2014 10:36:37 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 19:36:38 -0800, Rustom Mody wrote: > > Python's 'is' leaks > > the machine abstraction. 'id' does it legitimately (somewhat), 'is' does > > it illegitimately > Can you elaborate on why id() is legitimate and "is" is not? Mostly a question of more or less infelicitous English leading to philosophical nonsense. [And note I put a 'somewhat'] I can say "'id' is just 'machine-id' is just address at some low level" Its uglier to say "Is is machine-is" And before you bring it up, "Jython's id is not machine-id" is putting the cart before the horse. "Jython is an imitation of Cpython and does a good job but not quite as in the case of 'id'" is the right order (IMHO) From rustompmody at gmail.com Wed Mar 5 01:10:12 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 22:10:12 -0800 (PST) Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: On Wednesday, March 5, 2014 11:31:04 AM UTC+5:30, alex23 wrote: > On 5/03/2014 3:47 PM, Rustom Mody wrote: > > That python is a hll means that machine reprs are intended to be abstracted > > away. 'is' fails to do that -- proof of that being the discrepancy between > > is and == > The "discrepancy" is because _they're fundamentally different_: Yeah I know :D > Both have their uses. Yes -- see my lisp example above > >>> a = b = [1,2] > >>> c = [1,2] > >>> a is b > True > >>> a is c > False > >>> a == b > True > >>> a == c > True > `==` is used to determine if they're equivalent in value. Right > `is` is used to determine if two names refer to the same object. 'Same' is 'is' in a different guise and is what I object to. A python programmer who needs/wants to think of same/is in this sense should probably be using C or assembly In the exceptional circumstances when 'low-level-machine-equivalence-relation' is desired, a name carrying some of those connotations would be ok From ben+python at benfinney.id.au Wed Mar 5 01:20:46 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Mar 2014 17:20:46 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: <85fvmxf9oh.fsf@benfinney.id.au> Rustom Mody writes: > That python is a hll means that machine reprs are intended to be abstracted > away. 'is' fails to do that -- proof of that being the discrepancy between > is and == That's your proof? That is a non sequitur. Those two operators are *designed to be* different, to compare different things. How does the difference between ?==? versus ?is?, which are designed and documented to have different behaviour, lead to your assertion of a ?leaky abstraction?? You have yet to respond to this question asked several times: > > Can you explain what machine representations are leaked into Python > > by the is operator? So, what machine represenatation is leaked? I'll re-iterate that ?memory location of the object? isn't a valid response. There is no necessary relation between the memory location of the object referenced by ?foo? and the return value of ?id(foo)?. The latter is useable with utter ignorance of the concept of memory location, so it is not a leaky abstraction. Note that for an abstraction to be leaky, the programmer must *be required* to have an understanding of what lies beneath the abstraction. If the values that the programmer deals with can be dealt with entirely at the level of the abstraction, and no knowledge of what's under the hood is needed, then the abstraction does not leak. > No claim even remotely to having a clue to metaphysical being that > python's 'is' implies Yes, exactly. You have no need to know what is under the hood: it is the object's identity, which is simply a property which is unique to that object among all other concurrently-existing objects. The value returned by ?id(foo)? and compared by ?is? means nothing else other than the abstraction of ?object identity?. The value has to be *something*, so it may resemble other things ? such as the object's memory location, or not ? but that resemblance is not promised by anything, and is irrelevant to the user of the abstraction. -- \ ?As far as the laws of mathematics refer to reality, they are | `\ not certain, and as far as they are certain, they do not refer | _o__) to reality.? ?Albert Einstein, 1983 | Ben Finney From marko at pacujo.net Wed Mar 5 01:23:21 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 08:23:21 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> Message-ID: <8761ntp3ja.fsf@elektro.pacujo.net> Rustom Mody : > * ... which summarizes my objection in this thread: Python's 'is' > leaks the machine abstraction. 'id' does it legitimately (somewhat), > 'is' does it illegitimately I agree that the Python data model can be exceedingly challenging to a beginner. However, I wouldn't throw the baby away with the bathwater, but look for ingenious ways to teach it. The Spanish say, "Mal de muchos, consuelo de tontos." Python is hardly alone in this mess. For example, Java's '==' operator corresponds to Python's "is". Nobody would consider throwing Java's "==" away. Instead, we are offered esoteric rules like: If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2. For Python's "==", Java offers the "equals()" method. So is it wrong in Java to check: if (list.equals(null)) { The spec says: For any non-null reference value x, x.equals(null) should return false. So it *should* work, but why would you avoid the more natural test: if (list == null) { Similarly, in Python: if the_list == None: *should* work (even if there's no such stipulation in Python's reference material), but why wouldn't you use the more natural: if the_list is None: Marko From ben+python at benfinney.id.au Wed Mar 5 01:22:31 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Mar 2014 17:22:31 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: <85bnxlf9lk.fsf@benfinney.id.au> Rustom Mody writes: > A python programmer who needs/wants to think of same/is in this sense > should probably be using C or assembly Please back up that bald assertion. How does the usefulness of the ?object identity? abstraction oblige the programmer to not use Python? -- \ ?Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.? ?Anthony Taylor | Ben Finney From wuwei23 at gmail.com Wed Mar 5 01:28:53 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 05 Mar 2014 16:28:53 +1000 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: On 5/03/2014 4:10 PM, Rustom Mody wrote: > A python programmer who needs/wants to think of same/is in this sense > should probably be using C or assembly Any programmer who is obsessing about some idea of philosophical purity should probably not be using Python. From ben+python at benfinney.id.au Wed Mar 5 01:26:25 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Mar 2014 17:26:25 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <857g89f9f2.fsf@benfinney.id.au> Rustom Mody writes: > I can say "'id' is just 'machine-id' is just address at some low > level" You could say that, but it's wrong. The only thing promised by ?object identity? is that each object has it, and that it is different from the identity of every other object concurrently existing. ?Machine id? is not entailed within that at all. > And before you bring it up, "Jython's id is not machine-id" is putting > the cart before the horse. You have a false idea of what Python's object identity means, and it has warped your understanding of what implementations do. > "Jython is an imitation of Cpython and does a good job but not quite as > in the case of 'id'" Wrong. Jython and CPython both adhere to the guarantees of object identity. Both implementations follow the language reference, and neither implementation does object identity better or worse than the other. -- \ ?Science shows that belief in God is not only obsolete. It is | `\ also incoherent.? ?Victor J. Stenger, 2001 | _o__) | Ben Finney From rosuav at gmail.com Wed Mar 5 01:32:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 17:32:57 +1100 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 5:03 PM, Rustom Mody wrote: > I can say "'id' is just 'machine-id' is just address at some low level" And I can say that "id" returns a list of digits, but that doesn't make either statement true. The id() function returns a number which (a) never changes for any given object, and (b) will never be the same for any two concurrently-existing objects. It's a proxy for object identity. That's all. ChrisA From rustompmody at gmail.com Wed Mar 5 01:33:58 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 4 Mar 2014 22:33:58 -0800 (PST) Subject: Reference In-Reply-To: <8761ntp3ja.fsf@elektro.pacujo.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <8761ntp3ja.fsf@elektro.pacujo.net> Message-ID: <89e7d1ac-af88-4781-b23d-b64e571e811b@googlegroups.com> On Wednesday, March 5, 2014 11:53:21 AM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody : > > * ... which summarizes my objection in this thread: Python's 'is' > > leaks the machine abstraction. 'id' does it legitimately (somewhat), > > 'is' does it illegitimately > I agree that the Python data model can be exceedingly challenging to a > beginner. However, I wouldn't throw the baby away with the bathwater, > but look for ingenious ways to teach it. I'm curious how you understand my position on this You hear me as saying 'is' should go?? No I am not saying that All I am saying is that 'is' should have (be!) a name that is not philosophically grandiloquent bullshit but rather a name that more accurately conveys 'machine-representation-equivalence' From marko at pacujo.net Wed Mar 5 01:37:42 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 08:37:42 +0200 Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: <871tyhp2vd.fsf@elektro.pacujo.net> MRAB : > Into how many versions did Lisp split in its first 23 years? :-) I'm partial to Scheme, but I'll take any version. If you had tried Python 30 years ago, you'd give it up for any serious work because it would be so slow and consume so much memory. C++ virtual functions used to be avoided because of performance reasons. These are truly amazing times for computing: Java, C#, Python etc are now mainstream, and advanced programming concepts like closures are available to and expected from run-of-the-mill code pushers. Java programmers were afflicted by XML and didn't know of anything better. They are now being exposed to Clojure. Python programmers are starting to see glimpses of a better world with ast.literal_eval(). So we are getting there. Give it a few more decades. Marko From ben+python at benfinney.id.au Wed Mar 5 01:40:40 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Mar 2014 17:40:40 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <8761ntp3ja.fsf@elektro.pacujo.net> <89e7d1ac-af88-4781-b23d-b64e571e811b@googlegroups.com> Message-ID: <8538ixf8rb.fsf@benfinney.id.au> Rustom Mody writes: > All I am saying is that 'is' should have (be!) a name that is not > philosophically grandiloquent bullshit but rather a name that more > accurately conveys 'machine-representation-equivalence' You haven't made either case. How is the simple abstraction of object identity characterised as ?philosophically grandiloquent bullshit?? Why should we discard the useful abstraction of object identity as it currently is in Python, for some different concept that you prefer (?machine representation equivalence?, whatever that's supposed to be ? I don't care right now, only that you want something different from what is now) and have not justified why? -- \ ?The opposite of a correct statement is a false statement. But | `\ the opposite of a profound truth may well be another profound | _o__) truth.? ?Niels Bohr | Ben Finney From harrismh777 at gmail.com Wed Mar 5 02:09:43 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Tue, 4 Mar 2014 23:09:43 -0800 (PST) Subject: python decimal library dmath.py v0.3 released In-Reply-To: <4c40a0a4-e8ee-422a-a227-4a1a0597bb81@googlegroups.com> References: <55fc232e-f1a5-4c28-8fc0-06b3e3c63a68@googlegroups.com> <4c40a0a4-e8ee-422a-a227-4a1a0597bb81@googlegroups.com> Message-ID: <95331e0f-2775-4927-b3d2-ca6129febc9b@googlegroups.com> On Monday, March 3, 2014 7:46:38 PM UTC-6, Mark H. Harris wrote: > On Monday, March 3, 2014 5:34:30 AM UTC-6, Mark H. Harris wrote: > > > https://code.google.com/p/pythondecimallibrary/ > > https://pypi.python.org/pypi/pdeclib/0.3 Greetings, just a minor update here for version testing and portability. I have tested pdeclib.py | pilib.py on the following distributions: Py2.5 [ not supported, problems with "with" and localcontext ] Py2.6.1 [ runs correctly as written ] Py2.7.2 [ runs correctly as written ] Py2.7.6 [ runs correctly as written ] Py3.2.0 [ runs correctly as written ] Py3.3.4 [ runs very fast ] Py2.7.2 was interesting for me to verify, because that is the version that is currently supported by the QPython people, for the Android platform. I now have pdeclib module loaded on my phone running quite well, Samsung Galaxy SII Android 4.1.2 QPython 0.9.7.2 (Py2.7.2), although not as speedy as 3.3, it imports & runs without errors so far. If you put pdeclib on your Android tablet|phone, you may run the script from your personal directory, of course, or you may place it in the python2.7 lib/site-packages folder and it will be on the PYTHONPATH regardless of which directory you open python2.7.2 over. marcus From christoff.kok at ex-mente.co.za Wed Mar 5 02:10:33 2014 From: christoff.kok at ex-mente.co.za (Christoff Kok) Date: Tue, 4 Mar 2014 23:10:33 -0800 (PST) Subject: Struggling to create an extension wrapping a 3rd party dll Message-ID: <4f813ff8-d0c8-4370-b669-5484f3dcd467@googlegroups.com> Hi, We are trying to wrap a 3rd party dll (written in C) to access it through python. The dll has a .lib .c and a .h file with it. We are accessing the dll through the .c file. Outisde of the extension (running as a console application), the code works without an issue. without the 3rd party dll, the python extension works without an issue. The issue comes in when trying combine the third party dll with the python extension. Here is the distutil installation script ################ Setup.py ################################ from distutils.core import setup, Extension chemAppPython_mod = Extension('chemAppPython', sources = ['chemAppPython.c', 'cacint.c'], libraries=['ca_vc_opt_e'], depends = ['cacint.h']) setup(name = "chemAppPython", version = "1.0", description = "The ChemnApp Python module", ext_modules = [chemAppPython_mod], data_files = [('',['ca_vc_e.dll'])] ) ########################################################## * ca_vc_opt_e.lib and ca_vc_e.dll is the library containing the third party methods we want to access. * cacint.h and cacint.c is the files acting as an interface to the ca_vc_opt_e.lib and ca_vc_e.dll. * chemAppPython.c is file containing the code wrapping the calls to the cacint.c (and in effect, the third party dll) The errors we are receiving are: C:\Python33\source\Python-3.3.4\ChemAppPython>setup.py install running install running build running build_ext building 'chemAppPython' extension creating build creating build\temp.win-amd64-3.3 creating build\temp.win-amd64-3.3\Release C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python33\include -IC:\Python33\include /TcchemAppPython.c /Fobuild\temp.win-amd64-3.3\Release\chemAppPython.obj chemAppPython.c C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python33\include -IC:\Python33\include /Tccacint.c /Fobuild\temp.win-amd64-3.3\Release\cacint.obj cacint.c cacint.c(357) : warning C4267: 'function' : conversion from 'size_t' to 'long', possible loss of data cacint.c(390) : warning C4267: 'function' : conversion from 'size_t' to 'long', possible loss of data . . . (some more of the same warning message for different functions.) . cacint.c(619) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. . . . . (some more of the same warning message at different positions in code.) . creating build\lib.win-amd64-3.3 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python33\libs /LIBPATH:C:\Python33\PCbuild\amd64 ca_vc_opt_e.lib /EXPORT:PyInit_chemAppPython build\temp.win-amd64-3.3\Release\chemAppPython.obj build\temp.win-amd64-3.3\Rele chemAppPython.obj : warning LNK4197: export 'PyInit_chemAppPython' specified multiple times; using first specification Creating library build\temp.win-amd64-3.3\Release\chemAppPython.lib and object build\temp.win-amd64-3.3\Release\chemAppPython.exp cacint.obj : error LNK2019: unresolved external symbol TQINI referenced in function tqini cacint.obj : error LNK2019: unresolved external symbol TQOPEN referenced in function tqopen . . . (a lot more of them, for different methods. Again, it builds and runs fine in the console app host application.) . build\lib.win-amd64-3.3\chemAppPython.pyd : fatal error LNK1120: 74 unresolved externals error: command '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe"' failed with exit status 1120 Help would really be appreciated. From bouncingcats at gmail.com Wed Mar 5 02:52:31 2014 From: bouncingcats at gmail.com (David) Date: Wed, 5 Mar 2014 18:52:31 +1100 Subject: Geezer learns python In-Reply-To: References: Message-ID: On 5 March 2014 10:03, notbob wrote: > > I'm trying to learn python. I'm doing it via Zed Shaw's Learn Python > the Hard Way. Sure enough, 16 lessons in and I've run aground. Is it > OK for a painfully stupid ol' fart to ask painfully stupid noob > questions, here? I'm a long time usenet fan and prefer it to irc. The python-tutor mailing list exists for precisely those kind of questions: https://mail.python.org/mailman/listinfo/tutor You might also find it interesting to browse/download previous messages in the archive at that link. See you there :) From steve at pearwood.info Wed Mar 5 02:52:01 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 07:52:01 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 04 Mar 2014 23:25:37 -0500, Roy Smith wrote: > I stopped paying attention to mathematicians when they tried to convince > me that the sum of all natural numbers is -1/12. I'm pretty sure they did not. Possibly a physicist may have tried to tell you that, but most mathematicians consider physicists to be lousy mathematicians, and the mere fact that they're results seem to actually work in practice is an embarrassment for the entire universe. A mathematician would probably have said that the sum of all natural numbers is divergent and therefore there is no finite answer. Well, that is, apart from mathematicians like Euler and Ramanujan. When people like them tell you something, you better pay attention. We have an intuitive understanding of the properties of addition. You can't add 1000 positive whole numbers and get a negative fraction, that's obvious. But that intuition only applies to *finite* sums. They don't even apply to infinite *convergent* series, and they're *easy*. Remember Zeno's Paradoxes? People doubted that the convergent series: 1/2 + 1/4 + 1/8 + 1/16 + ... added up to 1 for the longest time, even though they could see with their own eyes that it had to. Until they worked out what *infinite* sums actually meant, their intuitions were completely wrong. This is a good lesson for us all. The sum of all the natural numbers is a divergent infinite series, so we shouldn't expect that our intuitions hold. We can't add it up as if it were a convergent series, because it's not convergent. Nobody disputes that. But perhaps there's another way? Normally mathematicians will tell you that divergent series don't have a total. That's because often the total you get can vary depending on how you add them up. The classic example is summing the infinite series: 1 - 1 + 1 - 1 + 1 - ... Depending on how you group them, you can get: (1 - 1) + (1 - 1) + (1 - 1) ... = 0 + 0 + 0 + ... = 0 or you can get: 1 - (1 - 1 + 1 - 1 + ... ) = 1 - (1 - 1) - (1 - 1) - ... ) = 1 - 0 - 0 - 0 ... = 1 Or you can do a neat little trick where we define the sum as "x": x = 1 - 1 + 1 - 1 + 1 - ... x = 1 - (1 - 1 + 1 - 1 + ... ) x = 1 - x 2x = 1 x = 1/2 So at first glance, summing a divergent series is like dividing by zero. You get contradictory results, at least in this case. But that's not necessarily always the case. You do have to be careful when summing divergent series, but that doesn't always mean you can't do it and get a meaningful answer. Sometimes you can, sometimes you can't, it depends on the specific series. With the sum of the natural numbers, rather than getting three different results from three different methods, mathematicians keep getting the same -1/12 result using various methods. That's a good hint that there is something logically sound going on here, even if it seems unintuitive. Remember Zeno's Paradoxes? Our intuitions about equality and plus and sums of numbers don't apply to infinite series. We should be at least open to the possibility that while all the *finite* sums: 1 + 2 1 + 2 + 3 1 + 2 + 3 + 4 ... and so on sum to positive whole numbers, that doesn't mean that the *infinite* sum has to total to a positive whole number. Maybe that's not how addition works. I don't know about you, but I've never personally added up an infinite number of every-increasing quantities to see what the result is. Maybe it is a negative fraction. (I'd say "try it and see", but I don't have an infinite amount of time to spend on it.) And in fact that's exactly what seems to be case here. Mathematicians can demonstrate an identity (that is, equality) between the divergent sum of the natural numbers with the zeta function ?(-1), and *that* can be worked out independently, and equals -1/12. So there are a bunch of different ways to show that the divergent sum adds up to -1/12, some of them are more vigorous than others. The zeta function method is about as vigorous as they come. The addition of an infinite number of things behaves differently than the addition of finite numbers of things. More here: http://scitation.aip.org/content/aip/magazine/physicstoday/news/10.1063/PT.5.8029 http://math.ucr.edu/home/baez/week126.html http://en.wikipedia.org/wiki/1_+_2_+_3_+_4_+_%E2%8B%AF and even here: http://scientopia.org/blogs/goodmath/2014/01/20/oy-veh-power-series-analytic-continuations-and-riemann-zeta/ where a mathematician tries *really hard* to discredit the idea that the sum equals -1/12, but ends up proving that it does. So he simply plays a linguistic slight of hand and claims that despite the series and the zeta function being equal, they're not *actually* equal. In effect, the author Mark Carrol-Chu in the "GoodMath" blog above wants to make the claim that the divergent sum is not equal to ?(-1), but everywhere you find that divergent sum in your calculations you can rub it out and replace it with ?(-1), which is -1/12. In other words, he's accepting that the divergent sum behaves *as if* it were equal to -1/12, he just doesn't want to say that it *is* equal to -1/12. Is this a mere semantic trick, or a difference of deep and fundamental importance? Mark C-C thinks it's an important difference. Mathematicians who actually work on this stuff all the time think he's making a semantic trick to avoid facing up to the fact that sums of infinite sequences don't always behave like sums of finite sequences. -- Steven From francis.moro at gmail.com Wed Mar 5 03:07:18 2014 From: francis.moro at gmail.com (Francis Moreau) Date: Wed, 05 Mar 2014 09:07:18 +0100 Subject: Decoding a process output In-Reply-To: References: Message-ID: On 03/04/2014 05:05 PM, Peter Otten wrote: > Francis Moreau wrote: > >> Hi, >> >> In my understanding (I'm relatively new to python), I need to decode any >> bytes data provided, in my case, by a shell command (such as findmnt) >> started by the subprocess module. The goal of my application is to parse >> the command outputs. >> >> My application runs only on linux BTW and should run fine on both python >> 2.7 and py3k. >> >> My question is when decoding the output bytes data of the external >> command, which encoding should I use ? >> >> Should I guess the encoding by inspecting LANG or any LC_* environment >> variables ? >> >> Should I force one of those environment variable to a specific value >> before running my external command ? >> >> Thanks for any tips. > > You can use locale.getpreferredencoding(), which seems to evaluate LANG: > > $ python3 -c 'import locale; print(locale.getpreferredencoding())' > UTF-8 > $ LANG= python3 -c 'import locale; print(locale.getpreferredencoding())' > ANSI_X3.4-1968 Hmm I'm confused here: when unsetting or changing LANG, the encoding is changed on the fly that makes me wonder which part of the linux system encodes the command output. I don't think it's the latter, is the libc ? Thanks From steve at pearwood.info Wed Mar 5 03:26:12 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 08:26:12 GMT Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> <871tyhp2vd.fsf@elektro.pacujo.net> Message-ID: <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> On Wed, 05 Mar 2014 08:37:42 +0200, Marko Rauhamaa wrote: > MRAB : > >> Into how many versions did Lisp split in its first 23 years? :-) > > I'm partial to Scheme, but I'll take any version. > > If you had tried Python 30 years ago, you'd give it up for any serious > work because it would be so slow and consume so much memory. /facepalm Python is only 23 years old, so it would have been a good trick to have tried it 30 years ago. While it was slow back then, it used LESS memory, not more. (Trading off more memory for speed is one of the ways that Python has gotten faster.) Nevertheless, people did use it for serious work, at least by the time it got to version 1.4 and quite likely much earlier. -- Steven From steve at pearwood.info Wed Mar 5 03:38:16 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 08:38:16 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5316e278$0$2923$c3e8da3$76491128@news.astraweb.com> Following up on my own post. On Wed, 05 Mar 2014 07:52:01 +0000, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 23:25:37 -0500, Roy Smith wrote: > >> I stopped paying attention to mathematicians when they tried to >> convince me that the sum of all natural numbers is -1/12. [...] > In effect, the author Mark Carrol-Chu in the "GoodMath" blog above wants > to make the claim that the divergent sum is not equal to ?(-1), but > everywhere you find that divergent sum in your calculations you can rub > it out and replace it with ?(-1), which is -1/12. In other words, he's > accepting that the divergent sum behaves *as if* it were equal to -1/12, > he just doesn't want to say that it *is* equal to -1/12. > > Is this a mere semantic trick, or a difference of deep and fundamental > importance? Mark C-C thinks it's an important difference. Mathematicians > who actually work on this stuff all the time think he's making a > semantic trick to avoid facing up to the fact that sums of infinite > sequences don't always behave like sums of finite sequences. Here's another mathematician who is even more explicit about what she's complaining about: http://blogs.scientificamerican.com/roots-of-unity/2014/01/20/is-the-sum-of-positive-integers-negative/ [quote] There is a meaningful way to associate the number -1/12 to the series 1+2+3+4?, but in my opinion, it is misleading to call it the sum of the series. [end quote] Evelyn Lamb's objection isn't about the mathematics that leads to the conclusion that the sum of natural numbers is equivalent to -1/12. That's conclusion is pretty much bulletproof. Her objection is over the use of the word "equals" to describe that association. Or possibly the use of the word "sum" to describe what we're doing when we replace the infinite series with -1/12. Whatever it is that we're doing, it doesn't seem to have the same behavioural properties as summing finitely many finite numbers. So perhaps she is right, and we shouldn't call the sum of a divergent series a sum? -- Steven From ben+python at benfinney.id.au Wed Mar 5 03:57:49 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 05 Mar 2014 19:57:49 +1100 Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <85y50pdnua.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 05 Mar 2014 08:37:42 +0200, Marko Rauhamaa wrote: > > > If you had tried Python 30 years ago, you'd give it up for any > > serious work because it would be so slow and consume so much memory. > > /facepalm > > Python is only 23 years old, so it would have been a good trick to have > tried it 30 years ago. While it was slow back then, it used LESS memory, > not more. Moreover, this is not an issue of Python the language as much as *implementations* (the CPython implementation has improved markedly in the intervening decades), and of *resources* very different then and now. The available CPU and memory resources for a language implementation is vastly greater today than 30 years ago. You could re-implement exactly the same compiler today as was run 30 years ago, and have its speed and memory performance remarkably better without any change in the language. If you'd run an implementation of *any* language of the time 30 years ago, it would have been far slower than implementations on today's hardware, and doubless improvements in the implementation (if the community was motivated to improve it for that long) would account for even greater speed differences. None of this is argument in favour of the changing applicability of the *language*, which is what Marko apparently wants to imply. -- \ ?I got an answering machine for my phone. Now when someone | `\ calls me up and I'm not home, they get a recording of a busy | _o__) signal.? ?Steven Wright | Ben Finney From antoon.pardon at rece.vub.ac.be Wed Mar 5 03:59:14 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 05 Mar 2014 09:59:14 +0100 Subject: Functional programming In-Reply-To: <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315bd68$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5316E762.6090701@rece.vub.ac.be> Op 04-03-14 12:47, Steven D'Aprano schreef: > On Tue, 04 Mar 2014 11:56:07 +0100, Antoon Pardon wrote: > >> Op 04-03-14 09:56, Steven D'Aprano schreef: >>>> If you >>>> explicitly say that this is an int, then yes, that should be >>>> disallowed; >>> It's that "explicitly" part that doesn't follow. Having to manage types >>> is the most tedious, boring, annoying, *unproductive* part of languages >>> like Java, C and Pascal. Almost always, you're telling the compiler >>> stuff that it can work out for itself. >> In the same way writing unit tests is the most tedious, boring, >> annoying, *unproductive* part. > Actually, I like writing unit tests. How do you know what the function > does until you test it? I'm not a TDD fanatic, but often I write tests > before I write the code, and there's really nothing nicer than seeing a > whole lot of failing unit tests suddenly start working. You examine the code. Just like you examine the code to interfere the type. > Well, maybe a nice BLT sandwich, when the bacon is nice and lean and the > lettuce crisp and the tomato flavourful and not too soggy. But other than > that, writing unit tests and seeing them pass is great. > > On the other hand, writing > > int n, m > double x, y > > and similar three hundred times throughout your program is not terribly > exciting. Even when it compiles, it doesn't mean it works. Even if your unit tests pass, that doesn't mean your program works. >> Amost always you are giving the program >> results it can work out for itself. > Not even close. I'd like to see the compiler that can work out for itself > that this function is buggy: Who said anything about buggy. If you want to test the function add1, what do you do? You call for example add1(5) and check that it is equal to 6. In other words you provide the result yourself you want the function to produce. > def sine_rule(side_a, side_b, angle_a): > """Return the angle opposite side_b.""" > return math.sin(side_b/side_a)*angle_a > > > If you don't remember your Sine Rule from trigonometry, that's okay. > Trust me, the function is badly wrong. It's rubbish really. But short of > some really impressive AI coupled with a Mathematica-level of maths > knowledge, how is the compiler supposed to know that? > > Static type testing, while valuable, cannot tell you that the program > does what you wanted it to do. In the same way it can't interfere the return type you want the function to have. From wxjmfauth at gmail.com Wed Mar 5 04:00:50 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 5 Mar 2014 01:00:50 -0800 (PST) Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <5316e278$0$2923$c3e8da3$76491128@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <5316e278$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: Mathematics? The Flexible String Representation is a very nice example of a mathematical absurdity. jmf PS Do not even think to expect to contradict me. Hint: sheet of paper and pencil. From marko at pacujo.net Wed Mar 5 04:01:08 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 11:01:08 +0200 Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <878usprpd7.fsf@elektro.pacujo.net> Steven D'Aprano : > On Wed, 05 Mar 2014 08:37:42 +0200, Marko Rauhamaa wrote: >> If you had tried Python 30 years ago, you'd give it up for any >> serious work because it would be so slow and consume so much memory. > > /facepalm > > Python is only 23 years old, Some explorers roamed in Siberia around 1900 and encountered small nations with undocumented languages. They stayed with the people for some time and tried to record the basic vocabulary and grammar. The dialog sometimes went like this: - In your language, is it correct to say, "I went fishing yesterday." - No. - What's wrong with it? - I didn't go fishing yesterday. Marko From antoon.pardon at rece.vub.ac.be Wed Mar 5 04:09:28 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 05 Mar 2014 10:09:28 +0100 Subject: Functional programming In-Reply-To: <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5316E9C8.9000403@rece.vub.ac.be> Op 04-03-14 16:18, Steven D'Aprano schreef: > Depends on the type: I suppose you can draw an analogy between records or > structs and classes with no methods. > > But I'm not talking about creating types, I'm talking about type > declarations. > > int x=2; # 2 is an int? Who would have guessed! How about: decimal[precision=4] x = 2.6; int[min = -10, max = 20] n = 7; -- Antoon Pardon From jldunn2000 at gmail.com Wed Mar 5 04:59:00 2014 From: jldunn2000 at gmail.com (loial) Date: Wed, 5 Mar 2014 01:59:00 -0800 (PST) Subject: find and replace string in binary file In-Reply-To: References: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> Message-ID: <687bff67-c486-402d-9f50-82e018c75585@googlegroups.com> Thanks Emile. Unfortunately I have to use python 2.6 for this On Wednesday, 5 March 2014 00:13:00 UTC, emile wrote: > On 03/04/2014 02:44 PM, Chris Angelico wrote: > > > On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <__peter__ at web.de> wrote: > > >> loial wrote: > > >> > > >>> How do I read a binary file, find/identify a character string and replace > > >>> it with another character string and write out to another file? > > >>> > > >>> Its the finding of the string in a binary file that I am not clear on. > > >> > > >> That's not possible. You have to convert either binary to string or string > > >> to binary before you can replace. Whatever you choose, you have to know the > > >> encoding of the file. > > > > > > If it's actually a binary file (as in, an executable, or an image, or > > > something), then the *file* won't have an encoding, so you'll need to > > > know the encoding of the particular string you want and encode your > > > string to bytes. > > > > > > On 2.7 it's as easy as it sounds without having to think much about > > encodings and such. I find it mostly just works. > > > > emile at paj39:~$ which python > > /usr/bin/python > > emile at paj39:~$ python > > Python 2.7.3 (default, Sep 26 2013, 16:38:10) > > [GCC 4.7.2] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> image = open('/usr/bin/python','rb').read() > > >>> image.find("""Type "help", "copyright", "credits" """) > > 1491592 > > >>> image = image[:1491592]+"Echo"+image[1491592+4:] > > >>> open('/home/emile/pyecho','wb').write(image) > > >>> > > emile at paj39:~$ chmod a+x /home/emile/pyecho > > emile at paj39:~$ /home/emile/pyecho > > Python 2.7.3 (default, Sep 26 2013, 16:38:10) > > [GCC 4.7.2] on linux2 > > Echo "help", "copyright", "credits" or "license" for more information. > > > > YMMV, > > > > Emile From ned at nedbatchelder.com Wed Mar 5 06:23:28 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 05 Mar 2014 06:23:28 -0500 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <5316e278$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On 3/5/14 4:00 AM, wxjmfauth at gmail.com wrote: > Mathematics? > The Flexible String Representation is a very nice example > of a mathematical absurdity. > > jmf > > PS Do not even think to expect to contradict me. Hint: > sheet of paper and pencil. > Reminder to everyone: JMF makes no sense when he talks about the FSR, and absurdly seems to think hinting at paper and pencil will convince us he is right. Don't engage with him on this topic. -- Ned Batchelder, http://nedbatchelder.com From bc at freeuk.com Wed Mar 5 06:28:31 2014 From: bc at freeuk.com (BartC) Date: Wed, 5 Mar 2014 11:28:31 -0000 Subject: Functional programming In-Reply-To: <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com><3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com><216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com><0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com><5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com><5315661c$0$2923$c3e8da3$76491128@news.astraweb.com><53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:5315eec0$0$29985$c3e8da3$5496439d at news.astraweb.com... > On Tue, 04 Mar 2014 13:30:04 +0000, BartC wrote: >> Isn't creating classes in Python similar to creating types elsewhere? > > Depends on the type: I suppose you can draw an analogy between records or > structs and classes with no methods. > > But I'm not talking about creating types, I'm talking about type > declarations. > > int x=2; # 2 is an int? Who would have guessed! Think of the int as a 'var' then: var x=2; Now you're just declaring the names. But writing 'var' as 'int' is exactly the same amount of work. However, in the sorts of languages that require you to describe types in this much detail, then the exact kind of type can be important: float/integer, signed/unsigned, short/long, character/numeric etc. Especially when declaring an array or struct element, or a pointer; in these cases, providing a sample value in initialisation data is more awkward (for one thing, because you need to initialise the instance, whereas a struct is usually declared separately as a type). But I agree that in many cases, an initialised declaration *could* often be used to infer the likely type without too much trouble: var x=2 # integer var y=3.0 # real var z="A" # probably, a C-style string pointer ('char*') (And since I'm working on such a language at the moment, I felt obliged to implement exactly this. And yes, with 10 minutes' effort, something like this was working, to prove my assertion. However it is not satisfactory, which is one reason why no well-established static language is likely to adopt such a feature. It is just too untidy, too ad-hoc and undisciplined, to say that usually you need to provide an exact type, but sometimes, in such and such an instance, you don't need to bother!) -- Bartc From oscar.j.benjamin at gmail.com Wed Mar 5 06:59:47 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 5 Mar 2014 11:59:47 +0000 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On 4 March 2014 23:20, Dave Angel wrote: > > One problem with complexity claims is that it's easy to miss some > contributing time eaters. I haven't done any measuring on modern > machines nor in python, but I'd assume that multiplies take > *much* longer for large integers, and that divides are much > worse. So counting iterations isn't the whole story. Agreed but there's a big difference between log(N) iterations and N iterations! > On the assumption that division by 2 is very fast, and that a > general multiply isn't too bad, you could improve on Newton by > observing that the slope is 2. > > err = n - guess * guess > guess += err/2 I gues you mean like this: def sqrt(n): err = guess = 1 while err > 1e-10: err = n - guess * guess guess += err/2 return guess This requires log2(10)*N iterations to get N digits. So the penalty for using division would have to be extreme in order for this to better. Using Decimal to get many digits we can write that as: def sqrt2(n, prec=1000): '''Solve x**2 = y''' eps = D(10) ** -(prec + 5) err = guess = D(1) with localcontext() as ctx: ctx.prec = prec + 10 while abs(err) > eps: err = n - guess*guess guess += err/2 return guess This method works out much slower than Newton with division at 10000 digits: 40s (based on a single trial) vs 80ms (timeit result). > Some 37 years ago I microcoded a math package which included > square root. All the math was decimal, and there was no hardware > multiply or divide. The algorithm I came up with generated the > answer one digit at a time, with no subsequent rounding needed. > And it took just a little less time than two divides. For that > architecture, Newton's method would've been too > slow. If you're working with a fixed small precision then it might be. > Incidentally, the algorithm did no divides, not even by 2. No > multiplies either. Just repeated subtraction, sorta like divide > was done. > > If anyone is curious, I'll be glad to describe the algorithm; > I've never seen it published, before or since. I got my > inspiration from a method used in mechanical, non-motorized, > adding machines. My father had shown me that approach in the > 50's. I'm curious. Oscar From davea at davea.name Wed Mar 5 07:06:11 2014 From: davea at davea.name (Dave Angel) Date: Wed, 5 Mar 2014 07:06:11 -0500 (EST) Subject: find and replace string in binary file References: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> Message-ID: loial Wrote in message: > How do I read a binary file, find/identify a character string and replace it with another character string and write out to another file? > > Its the finding of the string in a binary file that I am not clear on. > > Any help appreciated > I see from another message that you're using Python 2.6. That makes a huge difference and should have been in your query, along with a minimal code sample. Is the binary file under 100 MB or so? Then open it (in binary mode 'rb'), and read it. You'll now have a (large) byte string containing the entire file. The next question is whether you're sure that your search and replace strings are ASCII. Assuming that is probably a mistake, but it will get you started. Now the substitution is trivial: new_bytes = old_bytes.replace (search, replace) It's also possible to emulate that with find and slice, mainly if you need to report progress to the user. If the search and/or replace strings are not ASCII, you have to know what encoding the file may have used for them. You need to build a Unicode string, encode it the same way as the file uses, and then call the replace method. Now for a huge caveat. If you don't know the binary format, you're risking the creation of pure junk. Here are just two examples of what might go wrong, assuming the file is an executable. The same risks exist for other files, but I'm just supposing. If the two byte strings are not the same length, then all the remaining code and data in the file will be moved to a new spot. If you're lucky, the code will crash quickly, since all pointers referencing that code and data are incorrect. If some non-textual part of the file happens to match your search string you're going to likely trash that portion of the code. If the search string is large enough, maybe this is unlikely. But I recall taking the challenge of writing assembly programs which could be generated entirely from one or more type commands (msdos) -- DaveA From rosuav at gmail.com Wed Mar 5 07:04:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 23:04:20 +1100 Subject: Functional programming In-Reply-To: References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 10:28 PM, BartC wrote: > But I agree that in many cases, an initialised declaration *could* often be > used to infer the likely type without too much trouble: > > var x=2 # integer > var y=3.0 # real > var z="A" # probably, a C-style string pointer ('char*') > > (And since I'm working on such a language at the moment, I felt obliged to > implement exactly this. And yes, with 10 minutes' effort, something like > this was working, to prove my assertion. > > However it is not satisfactory, which is one reason why no well-established > static language is likely to adopt such a feature. It is just too untidy, > too ad-hoc and undisciplined, to say that usually you need to provide an > exact type, but sometimes, in such and such an instance, you don't need to > bother!) C++ has something very like this, with the 'auto' keyword. It's not particularly useful for the examples you give, but can be much more so when you have templates, iterators, and so on - where the exact type declaration might be a couple dozen characters of pure syntactic salt, since you're initializing it to some function's return value. ChrisA From marko at pacujo.net Wed Mar 5 07:11:56 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 14:11:56 +0200 Subject: Functional programming References: <4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com> <3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com> <216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com> <0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> <5315661c$0$2923$c3e8da3$76491128@news.astraweb.com> <53159540$0$2923$c3e8da3$76491128@news.astraweb.com> <5315eec0$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vbvsrgj7.fsf@elektro.pacujo.net> Chris Angelico : > C++ has something very like this, with the 'auto' keyword. It's not > particularly useful for the examples you give, but can be much more so > when you have templates, iterators, and so on - where the exact type > declaration might be a couple dozen characters of pure syntactic salt, > since you're initializing it to some function's return value. Java has a widely practiced ideal that you should not tie variables to class types but instead stick to interface types. Thus, you want to declare: List li = new LinkedList(); Thing is, though, you can't automatically guess this. After all, you might be after: Iterable li = new LinkedList(); or maybe: Collection li = new LinkedList(); This principle doesn't concern only collections. A well-designed application should specify interfaces for pretty much all classes to separate design blocks and APIs from implementations du jour. (Again, something that has no relevance for Python users.) Marko From breamoreboy at yahoo.co.uk Wed Mar 5 07:21:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 12:21:38 +0000 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: On 05/03/2014 06:10, Rustom Mody wrote: > On Wednesday, March 5, 2014 11:31:04 AM UTC+5:30, alex23 wrote: >> On 5/03/2014 3:47 PM, Rustom Mody wrote: >>> That python is a hll means that machine reprs are intended to be abstracted >>> away. 'is' fails to do that -- proof of that being the discrepancy between >>> is and == > >> The "discrepancy" is because _they're fundamentally different_: > > Yeah I know :D > > >> Both have their uses. > > Yes -- see my lisp example above > >> >>> a = b = [1,2] >> >>> c = [1,2] >> >>> a is b >> True >> >>> a is c >> False >> >>> a == b >> True >> >>> a == c >> True > >> `==` is used to determine if they're equivalent in value. > > Right > >> `is` is used to determine if two names refer to the same object. > > > 'Same' is 'is' in a different guise and is what I object to. > > A python programmer who needs/wants to think of same/is in this sense > should probably be using C or assembly > > In the exceptional circumstances when 'low-level-machine-equivalence-relation' > is desired, a name carrying some of those connotations would be ok > Quite frankly I haven't got the faintest idea what you're going on about, so I'll just stick with writing plain, boring, working Python code. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Wed Mar 5 07:24:23 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 12:24:23 +0000 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: On 05/03/2014 06:28, alex23 wrote: > On 5/03/2014 4:10 PM, Rustom Mody wrote: >> A python programmer who needs/wants to think of same/is in this sense >> should probably be using C or assembly > > Any programmer who is obsessing about some idea of philosophical purity > should probably not be using Python. > The Python philosophy is beautifully put in The Zen. I particularly like "Practicality beats purity" although there's plenty of other pieces of the whole to consider. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From oscar.j.benjamin at gmail.com Wed Mar 5 07:21:37 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 5 Mar 2014 12:21:37 +0000 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On 5 March 2014 07:52, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 23:25:37 -0500, Roy Smith wrote: > >> I stopped paying attention to mathematicians when they tried to convince >> me that the sum of all natural numbers is -1/12. > > I'm pretty sure they did not. Possibly a physicist may have tried to tell > you that, but most mathematicians consider physicists to be lousy > mathematicians, and the mere fact that they're results seem to actually > work in practice is an embarrassment for the entire universe. A > mathematician would probably have said that the sum of all natural > numbers is divergent and therefore there is no finite answer. Why the dig at physicists? I think most physicists would be able to tell you that the sum of all natural numbers is not -1/12. In fact most people with very little background in mathematics can tell you that. The argument that the sum of all natural numbers comes to -1/12 is just some kind of hoax. I don't think *anyone* seriously believes it. > Well, that is, apart from mathematicians like Euler and Ramanujan. When > people like them tell you something, you better pay attention. Really? Euler didn't even know about absolutely convergent series (the point in question) and would quite happily combine infinite series to obtain a formula. > Normally mathematicians will tell you that divergent series don't have a > total. That's because often the total you get can vary depending on how > you add them up. The classic example is summing the infinite series: > > 1 - 1 + 1 - 1 + 1 - ... There is a distinction between absolute convergence and convergence. Rearranging the order of the terms in the above infinite sum is invalid because the series is not absolutely convergent. For this particular series there is no sense in which its sum converges on an answer but there are other series that cannot be rearranged while still being convergent: http://en.wikipedia.org/wiki/Harmonic_series_(mathematics)#Alternating_harmonic_series Personally I think it's reasonable to just say that the sum of the natural numbers is infinite rather than messing around with terms like undefined, divergent, or existence. There is a clear difference between a series (or any limit) that fails to converge asymptotically and another that just goes to +-infinity. The difference is usually also relevant to any practical application of this kind of maths. Oscar From breamoreboy at yahoo.co.uk Wed Mar 5 07:35:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 12:35:05 +0000 Subject: Reference In-Reply-To: <8761ntp3ja.fsf@elektro.pacujo.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <8761ntp3ja.fsf@elektro.pacujo.net> Message-ID: On 05/03/2014 06:23, Marko Rauhamaa wrote: > Rustom Mody : > >> * ... which summarizes my objection in this thread: Python's 'is' >> leaks the machine abstraction. 'id' does it legitimately (somewhat), >> 'is' does it illegitimately > > I agree that the Python data model can be exceedingly challenging to a > beginner. However, I wouldn't throw the baby away with the bathwater, > but look for ingenious ways to teach it. [snip Java] > > Similarly, in Python: > > if the_list == None: > > *should* work (even if there's no such stipulation in Python's reference > material), but why wouldn't you use the more natural: > > if the_list is None: > > > Marko > Really great thinking, test the name the_list, which strangely enough tells me that this beast is a list, in the same way that THIS_IS_A_CONSTANT is a constant, to see if it's None. Congratulations, you've been promoted to captain of my dream team. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Wed Mar 5 07:42:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 12:42:28 +0000 Subject: find and replace string in binary file In-Reply-To: <687bff67-c486-402d-9f50-82e018c75585@googlegroups.com> References: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> <687bff67-c486-402d-9f50-82e018c75585@googlegroups.com> Message-ID: On 05/03/2014 09:59, loial wrote: I'm pleased to see that you have answers. In return would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Wed Mar 5 07:45:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 5 Mar 2014 23:45:25 +1100 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <8761ntp3ja.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 5, 2014 at 11:35 PM, Mark Lawrence wrote: >> if the_list is None: >> >> >> Marko >> > > Really great thinking, test the name the_list, which strangely enough tells > me that this beast is a list, in the same way that THIS_IS_A_CONSTANT is a > constant, to see if it's None. Congratulations, you've been promoted to > captain of my dream team. Uhh... why? What's wrong with something either being a list or being None to indicate no list? def foo(x, target_list=None): if target_list is not None: target_list = default_targets You can't use "if target_list:" here, because that would also catch an empty list. You need some kind of sentinel that says "there isn't a list here". ChrisA From breamoreboy at yahoo.co.uk Wed Mar 5 07:50:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 12:50:06 +0000 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On 05/03/2014 12:21, Oscar Benjamin wrote: > > Why the dig at physicists? I think most physicists would be able to > tell you that the sum of all natural numbers is not -1/12. In fact > most people with very little background in mathematics can tell you > that. > I'll put that one to the test tomorrow morning when the bin men come round. I fully expect them to dial 999 and ask that the paramedics are armed with plenty of sedatives. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From davea at davea.name Wed Mar 5 07:57:49 2014 From: davea at davea.name (Dave Angel) Date: Wed, 5 Mar 2014 07:57:49 -0500 (EST) Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: Oscar Benjamin Wrote in message: > On 4 March 2014 23:20, Dave Angel wrote: >> >> One problem with complexity claims is that it's easy to miss some >> contributing time eaters. I haven't done any measuring on modern >> machines nor in python, but I'd assume that multiplies take >> *much* longer for large integers, and that divides are much >> worse. So counting iterations isn't the whole story. > > Agreed but there's a big difference between log(N) iterations and N iterations! > >> On the assumption that division by 2 is very fast, and that a >> general multiply isn't too bad, you could improve on Newton by >> observing that the slope is 2. >> >> err = n - guess * guess >> guess += err/2 > > I gues you mean like this: > > def sqrt(n): > err = guess = 1 > while err > 1e-10: > err = n - guess * guess > guess += err/2 > return guess > > This requires log2(10)*N iterations to get N digits. No idea how you came up with that, but I see an error in my stated algorithm, which does surely penalize it. The slope isn't 2, but 2x. So the line should have been guess += err/(2*guess) Now if you stop the loop after 3 iterations (or use some other approach to get a low-precision estimate, then you can calculate scale = 1/(2*estimate) and then for remaining iterations, guess += err *scale > So the penalty > for using division would have to be extreme in order for this to > better. Using Decimal to get many digits we can write that as: > > def sqrt2(n, prec=1000): > '''Solve x**2 = y''' > eps = D(10) ** -(prec + 5) > err = guess = D(1) > with localcontext() as ctx: > ctx.prec = prec + 10 > while abs(err) > eps: > err = n - guess*guess > guess += err/2 > return guess > > This method works out much slower than Newton with division at 10000 > digits: 40s (based on a single trial) vs 80ms (timeit result). Well considering you did not special-case the divide by 2, I'm not surprised it's slower. > >> Some 37 years ago I microcoded a math package which included >> square root. All the math was decimal, and there was no hardware >> multiply or divide. The algorithm I came up with generated the >> answer one digit at a time, with no subsequent rounding needed. >> And it took just a little less time than two divides. For that >> architecture, Newton's method would've been too >> slow. > > If you're working with a fixed small precision then it might be. > >> Incidentally, the algorithm did no divides, not even by 2. No >> multiplies either. Just repeated subtraction, sorta like divide >> was done. >> >> If anyone is curious, I'll be glad to describe the algorithm; >> I've never seen it published, before or since. I got my >> inspiration from a method used in mechanical, non-motorized, >> adding machines. My father had shown me that approach in the >> 50's. > > I'm curious. > A later message, I guess. I can't write that much on the tablet. -- DaveA From davea at davea.name Wed Mar 5 08:32:30 2014 From: davea at davea.name (Dave Angel) Date: Wed, 5 Mar 2014 08:32:30 -0500 (EST) Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: Dave Angel Wrote in message: > Oscar Benjamin Wrote in message: >> On 4 March 2014 23:20, Dave Angel wrote: >>> >>> If anyone is curious, I'll be glad to describe the algorithm; >>> I've never seen it published, before or since. I got my >>> inspiration from a method used in mechanical, non-motorized, >>> adding machines. My father had shown me that approach in the >>> 50's. >> >> I'm curious. >> > > A later message, I guess. I can't write that much on the tablet. > > Given a microcodable architecture with no hardware support for multiply or divide, clearly multiply will be several times as fast as divide (at least). ??There was a BCD ALU, so add and subtract of decimal values was quite reasonable. ??All floating point logic, however, is just microcode. Divide is implemented via repeated subtraction of the divisor from the dividend. ??The count of how many subtracts is done is the quotient. Naturally, this is combined with digit shifts, so you find one quotient digit at a time. ??For a 13 digit result, the maximum subtracts are 13*10. Multiply is much faster, as you know ahead of time for each column how many adds you're supposed to do. ??So you can have precalculated multiples of the divisor on hand, and you can subtract instead of add when appropriate. Square root is implemented as a kind of variable division, where the "divisor" is changing constantly. ??Everyone knows that the sum of the first n odd numbers is n squared. ??So if you started with a square, you could repeatedly subtract odd numbers from it till you reached zero, and the square root will be roughly half the last odd number subtracted. So to make this work across multiple columns it turns out you can accumulate these odd numbers, doing the appropriate shifts after each column, and if you take the last number shifted, you can just add 1 and divide by 2. In many architectures, that would be as far as you can go, but in the particular one I was using, generating those pesky odd numbers was more expensive than you'd expect. ??So it turned out to be quicker to just do twice as many subtracts. Instead of subtracting 1,3, 5, etc., till the value went negative, we subtract 0 and 1, 1 and 2, 2 and 3, etc. ??You have twice as many subtracts, but no divide by 2 at the end. ??And for each column, you need not go beyond 8 + 9, since if it were more than that, we would have picked it up in the previous column. ??So you do not have to propagate the carry across the trial divisor. Supposing the correct result will be 7.1234567, you will at one stage of operations, be subtracting ?? ?? ?? ??71230 ?? ?? ?? ??71231 ?? ?? ?? ??71231 ?? ?? ?? ??71232 ?? ?? ?? ??71232 ?? ?? ?? ??71233 ?? ?? ?? ??71233 ?? ?? ?? ??71234 The next subtract will make the result go negative, so you either do it, detect negative and undo it, or you do some compare operation. I am here glossing over all the details of normalizing the dividend so the exponent is even, and calculating the final exponent, which at first approximation is half the original one. -- DaveA From antoon.pardon at rece.vub.ac.be Wed Mar 5 08:37:15 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 05 Mar 2014 14:37:15 +0100 Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5317288B.8090801@rece.vub.ac.be> Op 04-03-14 16:25, Chris Angelico schreef: > On Wed, Mar 5, 2014 at 2:19 AM, Jerry Hill wrote: >> Out of curiosity, do you think we should be doing truth checking with >> 'is'? True and False are singletons, and it seems to me that the >> justification for idenity versus equality should be just as strong >> there, but I don't think I've ever seen anyone even suggest that. > Normal truth testing is done like this: > > if cond: In an other language with real booleans where an if only accepts a boolean that would be true. In python this is testing for "something." > This isn't truth testing, this is checking the identity of what's in cond: > > if cond is True: > > And that's specifically testing for something much tighter than > truthiness. As you can see from my stats above, that's actually fairly > rare. Usually you'd just accept that True, 1, "yes", [1,2,3], and > 1.2345 are all equally true. No I usually don't accept that. A number different from 0 is not the same as a none-empty list. I usally don't want to treat them the same. -- Antoon Pardon From galaxyblue63 at gmail.com Wed Mar 5 08:42:20 2014 From: galaxyblue63 at gmail.com (Bill) Date: Wed, 5 Mar 2014 05:42:20 -0800 (PST) Subject: How to create an instance of a python class from C++ In-Reply-To: References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> Message-ID: <0844f51e-151f-46ce-b0ea-456098d020e3@googlegroups.com> > > So far, so good. The object that was passed in was the "Derived" > class object. Since you presumably only want class objects to be > passed in, you might want to check that here using PyType_Check. > Yes. Will do. > > > PyTypeObject *typ = class_decl->ob_type; > > In Python, you instantiate a class by calling it. You should do the > same in C, using PyObject_CallFunction. But as above, note that you > want to call class_decl, not class_decl->ob_type. > Of course. That works. Thanks. Bill From harrismh777 at gmail.com Wed Mar 5 09:11:04 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Wed, 5 Mar 2014 06:11:04 -0800 (PST) Subject: How security holes happen In-Reply-To: <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wednesday, March 5, 2014 2:26:12 AM UTC-6, Steven D'Aprano wrote: > On Wed, 05 Mar 2014 08:37:42 +0200, Marko Rauhamaa wrote: > > > If you had tried Python 30 years ago, you'd give it up for any serious > > work because it would be so slow and consume so much memory. > > /facepalm > > Python is only 23 years old, so it would have been a good trick to have > tried it 30 years ago. hi Steven, QOTD, I go back to the day of the MITS Altair 8800. My high school had one. I was writing machine code for the Wang 700 series programmable desk calculator, and punching in code on the Altair 8800, with toggle switches. I'm one of the guys Bill Gates wrote his famous open letter to in 1976. I was there. In 1984 the only language being used to write *anything* in the general sphere of personal computing was either MS DEBUG.COM (one of my favorites) or BASIC---which was ubiquitous, where like almost *every* computer booted directly into a BASIC interpreter, the noted exception being the first IBM PC. The pre-cursor to python was ABC created at CWI in about 1991. One of its purposes (according to Guido) was to, and I quote, "Stamp out BASIC". My first IBM machine was the famous PCjr... booted directly into cartridge BASIC, or would optionally boot DOS 2.1 from 5" floppy, where I could run, you guessed it BASICA, using the cartridge rom, or I could optionally run DEBUG.COM and code up 8086 machine code (not assembler, mind you). Well, I used my PCjr until 1992 (python was one year old, and ABC would not run on a PC); when I purchased my 486 SX. Guess what? ---still coding BASIC, DEBUG.COM... and whoohoo, Turbo Pascal........ At IBM we were coding Rexx on the VM370 systems, and then Rexx on the OS/2 systems; no python, and nothing much else either , oh yes, Turbo BASIC, Visual BASIC, and of course BASICA although you could then get it as GWBASIC, ... still no python. Did anyone mention that PCs back in that day were toys. And I do mean toys. They were slow, they crashed, their graphics sucked, and your storage medium was a floppy disk. Linus was working in Finland on basic... Richard Stallman was working on GNU, Guido was working at CWI on python. The PC really didn't come into its own (and they were still slow) until the Pentium4. Personal computers really did not begin to really shine until about 1998 (a mere 16 years ago) when IBM and other began to take a serious look into gnu/linux research. PCs were fast enough, had enough memory, and even had python. Of course most of us were not using it... mostly C of various brands (notably MIX) and Visual BASIC. Quick BASIC was ubiquitous by that time, and MASM had taken over for DEBUG.com. Those were the days. There has been a resurgence of interest in BASIC today; notably Mintoris, and Chipmunk. But now everyone usually has some flavor of python installed on their computer (and most don't know it) because python is being used under the covers as a scripting language of choice. Wide adoption is still coming, in the future, but the future looks good for python; competing of course with (notably) Java or Dalvik (Android Java). In my day computers were slide-rules. Businesses were still using Comptometers (still being taught on my high school) and the modern age of computing would not occur for forty years. Trust me, thirty years ago was like the dark ages of personal computing and python wasn't even a gleam in her daddy's eye..... If fact, now that I think of it, Monte Python and the Holy Grail came out in 1975, one year before the MITS Altair 8800 Bill Gates open letter, and one year after I graduated from high school. {world according to me} marcus From neilc at norwich.edu Wed Mar 5 09:19:27 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 5 Mar 2014 14:19:27 +0000 (UTC) Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: On 2014-03-05, Dennis Lee Bieber wrote: > On Wed, 05 Mar 2014 00:48:40 +0200, Marko Rauhamaa > declaimed the following: >>Ethan Furman : >>> Okay, that looks totally cool. Maybe I'll finally get a >>> handle on LISP! :) >> >> Lisp is conceptually simpler than Python, but awe-inspiring. >> One day, it will overtake Python, I believe. >> > > It's already had 54 years to become a major language... > > Instead it has schismed into Common Lisp and Scheme (and a few > other dialects) > > Granted, my experience was toying with /cassette-based/ > SuperSoft LISP on a TRS-80 Model III Personally, I think it hasn't taken off because special forms are harder to remember than syntax. And there are, like, *way* more than mammals needs. And then the coolest feature of the language, macros, is designed to let you, gulp, add more. Well, that or lisp's designers severely underestimated how much we like to use our programming languages as non-RPN calculators. -- Neil Cerutti From python.list at tim.thechases.com Wed Mar 5 09:24:30 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 5 Mar 2014 08:24:30 -0600 Subject: Reference In-Reply-To: <857g89f9f2.fsf@benfinney.id.au> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <857g89f9f2.fsf@benfinney.id.au> Message-ID: <20140305082430.4f9742a7@bigbox.christie.dr> On 2014-03-05 17:26, Ben Finney wrote: > > "Jython is an imitation of Cpython and does a good job but not > > quite as in the case of 'id'" > > Wrong. Jython and CPython both adhere to the guarantees of object > identity. Both implementations follow the language reference, and > neither implementation does object identity better or worse than the > other. I think he means "but not quite as [good in making my argument, despite the fact that the language definition runs contrary to my mistaken belief] as in [my interpretation of] 'id'" :-) -tkc From marko at pacujo.net Wed Mar 5 09:54:59 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 16:54:59 +0200 Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: <87zjl47l18.fsf@elektro.pacujo.net> Neil Cerutti : > Personally, I think it hasn't taken off because special forms are > harder to remember than syntax. And there are, like, *way* more than > mammals needs. It hasn't taken off yet, but even mammals can evolve. > Well, that or lisp's designers severely underestimated how much we > like to use our programming languages as non-RPN calculators. I don't think Lisp was really originally designed. It just came out and, surprisingly, ran. As for the anti-RPN notation, yes, it can be hard to get used to. Then again, Python notation requires an initiation as well. For example: invoc = "{}({})".format(fname, ', '.join(repr(x) for _, x in named_args)) Marko From rosuav at gmail.com Wed Mar 5 10:16:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Mar 2014 02:16:53 +1100 Subject: How security holes happen In-Reply-To: References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Mar 6, 2014 at 1:11 AM, Mark H. Harris wrote: > My first IBM machine was the famous PCjr... booted directly into cartridge > BASIC, or would optionally boot DOS 2.1 from 5" floppy, where I could > run, you guessed it BASICA, using the cartridge rom, or I could optionally > run DEBUG.COM and code up 8086 machine code (not assembler, mind you). My first IBM machine (first I used - the first computer I actually personally *owned* wasn't till this century) was an Epson XT-compatible. We had GW-BASIC and Q-BASIC, and a much superior form of DEBUG.EXE that came with, get this, an inbuilt mini-assembler! Yes, I could do this: -a xxxx:0100 mov ah,09 xxxx:0102 mov dx,0109 xxxx:0105 int 21 xxxx:0107 int 20 xxxx:0109 db "Hello, world!",13,10,24 And it'd produce the appropriate bytes. From memory, that would be B4 09 BA 09 01 CD 21 CD 20, followed by the text string. I actually used that to write seriously-useful programs, like one that helped us keep track of which treasures we'd picked up in Colossal Caves. (For some definition of "seriously-useful", anyway.) > At IBM we were coding Rexx on the VM370 systems, and then Rexx on the > OS/2 systems; no python, and nothing much else either , oh yes, Turbo BASIC, > Visual BASIC, and of course BASICA although you could then get it as GWBASIC, > ... still no python. I wasn't working at IBM itself, but when Dad switched to OS/2 for our home business, we switched too. That would have been about 1992; we used OS/2 2.1 briefly, but got properly into things with Warp 3 (Connect, and I can never remember whether it was red-box or blue-box - we had the one that came with a Windows license for Win-OS/2). Ooh, we had the most amazing fun with that... we set up, to quote my older brother, our very own personal World Wide Web! (Not very accurate, but that was the big buzz-word at the time, and hey, we did have a LAN.) And over the ensuing years, we got to know which network cards were the most reliable - mainly the Realtek ones, we had some RTL8029 cards that went into so many different computers - and if anything went wrong with drivers or anything, I'd pop the case and stick in one of my stand-bys. Either that, or we'd go search for the drivers on Hobbes, and either download 'em onto a floppy disk or LinkWiz them across - because one of the very first things we'd put onto any computer was the comms software that uses a special serial-port or parallel-port cable to transfer files. Immensely useful, until generic network drivers got better :) > Did anyone mention that PCs back in that day were toys. And I do mean toys. > They were slow, they crashed, their graphics sucked... Oh no! No no no! Graphics didn't suck for everyone. Maybe they did for you, you with the horrible CGA card plugged into your TV. Maybe they did for the people who used the default IBM Monochrome card that didn't do graphics at all. But no, my dad was forward-looking. He got the best. He got a Hercules Graphics Card, capable of driving the same screens the IBM Mono would, but giving us the tremendous capability of 720x348 monochrome graphics! It was awesome! Plus, for text colors we had black, white, bold black, and bold white, and - get this - underlined! Nobody else got that. Yes, those were the days. ChrisA From invalid at invalid.invalid Wed Mar 5 10:28:10 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 5 Mar 2014 15:28:10 +0000 (UTC) Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: On 2014-03-04, Marko Rauhamaa wrote: > Ethan Furman : > >> Okay, that looks totally cool. Maybe I'll finally get a handle on >> LISP! :) > > Lisp is conceptually simpler than Python, but awe-inspiring. One day, it > will overtake Python, I believe. Seriously? LISP had a _30_year_head_start_ yet Python is far ahead and pulling away... -- Grant Edwards grant.b.edwards Yow! I'm continually AMAZED at at th'breathtaking effects gmail.com of WIND EROSION!! From steve+comp.lang.python at pearwood.info Wed Mar 5 10:47:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 15:47:40 GMT Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> Message-ID: <5317471b$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Mar 2014 00:48:40 +0200, Marko Rauhamaa wrote: > Ethan Furman : > >> Okay, that looks totally cool. Maybe I'll finally get a handle on LISP! >> :) > > Lisp is conceptually simpler than Python, but awe-inspiring. One day, it > will overtake Python, I believe. That day was 25 years ago. According to the long-term TIOBE index, 25 years ago Lisp was the second most popular programming language in the world, behind only C. http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html I don't think Lisp has gotten easier, or the average programmer smarter, since then. The average programmer has difficulty with while loops, do you really think that someday they'll grok lambda calculus? *wink* Seriously, Lisp is not only one of the oldest high-level languages around, being almost as old as Fortran and Cobol, but it was one of the biggest languages of the 1970s and even into the 80s. Companies spent millions developing, and using, Lisp compilers. There were even Lisp machines, actual hardware machines not virtual, where the CPU could execute Lisp instructions directly in hardware. It did not last. It's not that the computer industry hasn't discovered Lisp, it is that they discovered it, gave it a solid workout for 20 years, and then said "Nope, this isn't for us." -- Steven D'Aprano http://import-that.dreamwidth.org/ From invalid at invalid.invalid Wed Mar 5 11:08:00 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 5 Mar 2014 16:08:00 +0000 (UTC) Subject: How to create an instance of a python class from C++ References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> Message-ID: On 2014-03-05, Ian Kelly wrote: > On Tue, Mar 4, 2014 at 5:14 PM, Bill wrote: >> Hello: >> >> I can't figure out how to create an instance >> of a python class from 'C++': >> >> ( I am relatively new to Python so excuse some of the following. ) >> >> In a .py file I create an ABC and then specialize it: > > Why are you creating an ABC? Because it was the first binary computer that did calculations with electronic switching elements (gates), and it would be really cool to have one! The ABC also pioneered the use of capciators as regenerative storage elements (it's how DRAM still works today). http://en.wikipedia.org/wiki/Atanasoff%E2%80%93Berry_Computer It predated ENIAC, and it's clear that some of the features of ENIAC were inspired by the ABC after John Mauchly visited Iowa State and saw the ABC. -- Grant Edwards grant.b.edwards Yow! I can't decide which at WRONG TURN to make first!! gmail.com I wonder if BOB GUCCIONE has these problems! From harrismh777 at gmail.com Wed Mar 5 11:37:04 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Wed, 5 Mar 2014 08:37:04 -0800 (PST) Subject: How security holes happen In-Reply-To: <5317471b$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> <5317471b$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, March 5, 2014 9:47:40 AM UTC-6, Steven D'Aprano wrote: > Seriously, Lisp is not only one of the oldest high-level languages > around, being almost as old as Fortran and Cobol, but it was one of the > biggest languages of the 1970s and even into the 80s. Lisp was specified by John McCarthy (of Berkeley, CA) in 1958. It is the second oldest computer language behind Fortran, by one year. There is a resurgence of interest in Lisp today (yes, not so much for common lisp) in the Scheme arena. The irony for AI today is that we are finally at the point where the technology can finally do what Alonzo Church and Alan Turing dreamed about. John McCarthy was *way* ahead of his time too. We are at the point where we are wondering again if computer science & technology in software engineering will ever generate a "thinking" entity---self aware, creative, and of course able to generate on it's own, "Cogito ergo sum"> Lisp/Scheme is awesome. But, if I want to have my little 'ol puter do some real work, up comes IDLE and out comes a script in a couple of hours that's "awesome"! I still play around with gnu emacs and lisp. Its fun, educational, and truly enriching beyond words. Check out the site, "Lambda the Ultimate" sometime: http://lambda-the-ultimate.org/ marcus From alister.ware at ntlworld.com Wed Mar 5 12:00:19 2014 From: alister.ware at ntlworld.com (Alister) Date: Wed, 05 Mar 2014 17:00:19 GMT Subject: How to create an instance of a python class from C++ References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> Message-ID: On Wed, 05 Mar 2014 16:08:00 +0000, Grant Edwards wrote: > On 2014-03-05, Ian Kelly wrote: >> On Tue, Mar 4, 2014 at 5:14 PM, Bill wrote: >>> Hello: >>> >>> I can't figure out how to create an instance of a python class from >>> 'C++': >>> >>> ( I am relatively new to Python so excuse some of the following. ) >>> >>> In a .py file I create an ABC and then specialize it: >> >> Why are you creating an ABC? > > Because it was the first binary computer that did calculations with > electronic switching elements (gates), and it would be really cool to > have one! The ABC also pioneered the use of capciators as regenerative > storage elements (it's how DRAM still works today). > > http://en.wikipedia.org/wiki/Atanasoff%E2%80%93Berry_Computer > > It predated ENIAC, and it's clear that some of the features of ENIAC > were inspired by the ABC after John Mauchly visited Iowa State and saw > the ABC. But it was not programmable the first programmable electronic computer was 'Colossus' which was developed during WWII but remained classified by the UK govt for many years afterwards http://en.wikipedia.org/wiki/Colossus_computer -- You are not dead yet. But watch for further reports. From invalid at invalid.invalid Wed Mar 5 12:14:17 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 5 Mar 2014 17:14:17 +0000 (UTC) Subject: How to create an instance of a python class from C++ References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> Message-ID: On 2014-03-05, Alister wrote: >> >>> Why are you creating an ABC? >> >> Because it was the first binary computer that did calculations with >> electronic switching elements (gates), and it would be really cool to >> have one! The ABC also pioneered the use of capciators as regenerative >> storage elements (it's how DRAM still works today). >> >> http://en.wikipedia.org/wiki/Atanasoff%E2%80%93Berry_Computer >> >> It predated ENIAC, and it's clear that some of the features of ENIAC >> were inspired by the ABC after John Mauchly visited Iowa State and saw >> the ABC. > > But it was not programmable True. It had only one program that was hard-wired into it when it was built as opposed to the external patch-cords and switches that were used on machines like Colossus and ENIAC to alter the wiring. > the first programmable electronic computer was 'Colossus' which was > developed during WWII but remained classified by the UK govt for many > years afterwards > > http://en.wikipedia.org/wiki/Colossus_computer -- Grant Edwards grant.b.edwards Yow! Hmmm ... A hash-singer at and a cross-eyed guy were gmail.com SLEEPING on a deserted island, when ... From rustompmody at gmail.com Wed Mar 5 12:40:53 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 5 Mar 2014 09:40:53 -0800 (PST) Subject: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: <60b9aaba-7991-415d-b3c6-dc18c5539502@googlegroups.com> On Wednesday, March 5, 2014 11:50:46 AM UTC+5:30, Ben Finney wrote: > Rustom Mody writes: > > That python is a hll means that machine reprs are intended to be abstracted > > away. 'is' fails to do that -- proof of that being the discrepancy between > > is and == > That's your proof? That is a non sequitur. Those two operators are > *designed to be* different, to compare different things. > How does the difference between '==' versus 'is', which are designed and > documented to have different behaviour, lead to your assertion of a > "leaky abstraction"? > You have yet to respond to this question asked several times: If you wish to disagree with me, you are welcome to do so and I am obliged (up to a point I guess) to assume the disagreement is in good faith towards better understanding/usage etc of python. However... > > > Can you explain what machine representations are leaked into Python > > > by the is operator? > So, what machine represenatation is leaked? > I'll re-iterate that "memory location of the object" isn't a valid > response. There is no necessary relation between the memory location of > the object referenced by "foo" and the return value of 'id(foo)'. ... however you are both disagreeing with me and also saying Ive not given the answer and further disagreeing with the python standard, which I quote: Every object has an identity, a type and a value. An object's identity never changes once it has been created; you may think of it as the object's address in memory. The 'is' operator compares the identity of two objects; the id() function returns an integer representing its identity (currently implemented as its address). from http://docs.python.org/2/reference/datamodel.html So when you say > I'll re-iterate that "memory location of the object" isn't a valid > response. well... all I can say is I dont know what to say :-) From steve+comp.lang.python at pearwood.info Wed Mar 5 12:43:02 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 17:43:02 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Mar 2014 12:21:37 +0000, Oscar Benjamin wrote: > On 5 March 2014 07:52, Steven D'Aprano wrote: >> On Tue, 04 Mar 2014 23:25:37 -0500, Roy Smith wrote: >> >>> I stopped paying attention to mathematicians when they tried to >>> convince me that the sum of all natural numbers is -1/12. >> >> I'm pretty sure they did not. Possibly a physicist may have tried to >> tell you that, but most mathematicians consider physicists to be lousy >> mathematicians, and the mere fact that they're results seem to actually >> work in practice is an embarrassment for the entire universe. A >> mathematician would probably have said that the sum of all natural >> numbers is divergent and therefore there is no finite answer. > > Why the dig at physicists? There is considerable professional rivalry between the branches of science. Physicists tend to look at themselves as the paragon of scientific "hardness", and look down at mere chemists, who look down at biologists. (Which is ironic really, since the actual difficulty in doing good science is in the opposite order. Hundreds of years ago, using quite primitive techniques, people were able to predict the path of comets accurately. I'd like to see them predict the path of a house fly.) According to this "greedy reductionist" viewpoint, since all living creatures are made up of chemicals, biology is just a subset of chemistry, and since chemicals are made up of atoms, chemistry is likewise just a subset of physics. Physics is the fundamental science, at least according to the physicists, and Real Soon Now they'll have a Theory Of Everything, something small enough to print on a tee-shirt, which will explain everything. At least in principle. Theoretical physicists who work on the deep, fundamental questions of Space and Time tend to be the worst for this reductionist streak. They have a tendency to think of themselves as elites in an elite field of science. Mathematicians, possibly out of professional jealousy, like to look down at physics as mere applied maths. They also get annoyed that physicists often aren't as vigorous with their maths as they should be. The controversy over renormalisation in Quantum Electrodynamics (QED) is a good example. When you use QED to try to calculate the strength of the electron's electric field, you end up trying to sum a lot of infinities. Basically, the interaction of the electron's charge with it's own electric field gets larger the more closely you look. The sum of all those interactions is a divergent series. So the physicists basically cancelled out all the infinities, and lo and behold just like magic what's left over gives you the right answer. Richard Feynman even described it as "hocus-pocus". The mathematicians *hated* this, and possibly still do, because it looks like cheating. It's certainly not vigorous, at least it wasn't back in the 1940s. The mathematicians were appalled, and loudly said "You can't do that!" and the physicists basically said "Oh yeah, watch us!" and ignored them, and then the Universe had the terribly bad manners to side with the physicists. QED has turned out to be *astonishingly* accurate, the most accurate physical theory of all time. The hocus-pocus worked. > I think most physicists would be able to tell > you that the sum of all natural numbers is not -1/12. In fact most > people with very little background in mathematics can tell you that. Ah, but there's the rub. People with *very little* background in mathematics will tell you that. People with *a very deep and solid* background in mathematics will tell you different, particularly if their background is complex analysis. (That's *complex numbers*, not "complicated" -- although it is complicated too.) > The argument that the sum of all natural numbers comes to -1/12 is just > some kind of hoax. I don't think *anyone* seriously believes it. You would be wrong. I suggest you read the links I gave earlier. Even the mathematicians who complain about describing this using the word "equals" don't try to dispute the fact that you can identify the sum of natural numbers with ?(-1), or that ?(-1) = -1/12. They simply dispute that we should describe this association as "equals". What nobody believes is that the sum of natural numbers is a convergent series that sums to -1/12, because it is provably not. In other words, this is not an argument about the maths. Everyone who looks at the maths has to admit that it is sound. It's an argument about the words we use to describe this. Is it legitimate to say that the infinite sum *equals* -1/12? Or only that the series has the value -1/12? Or that we can "associate" (talk about a sloppy, non-vigorous term!) the series with -1/12? >> Well, that is, apart from mathematicians like Euler and Ramanujan. When >> people like them tell you something, you better pay attention. > > Really? Euler didn't even know about absolutely convergent series (the > point in question) and would quite happily combine infinite series to > obtain a formula. (I note that you avoided criticising Ramanujan's work. Very wise.) Euler was working on infinite series in the 1700s. There's no doubt that his work doesn't meet modern standards of mathematical rigour, but those modern standards didn't exist back then. Morris Kline writes of Euler: Euler's work lacks rigor, is often ad hoc, and contains blunders, but despite this, his calculations reveal an uncanny ability to judge when his methods might lead to correct results. http://dept.math.lsa.umich.edu/~krasny/math156_Euler-Kline.pdf Euler certainly deserves to be in the pantheon of maths demigods, possibly the greatest mathematician who ever lived. There is a quip made that discoveries in mathematics are usually named after Euler, or the first person to discover them after Euler. Euler also wrote that one should not use the term "sum" to describe the total of a divergent series, since that implies regular addition, but that one can say that when a divergent series comes from an algebraic expression, then the value of the series is the value of the expression from which is came. Notice that he carefully avoids using the word "equals". (See above URL.) At one time, Euler summed an infinite series and got -1, from which he concluded that -1 was (in some sense) larger than infinity. I don't know what justification he gave, but the way I think of it is to take the number line from -? to +? and then bend it back upon itself so that there is a single infinity, rather like the projective plane only in a single dimension. If you start at zero and move towards increasingly large numbers, then like Buzz Lightyear you can go to infinity and beyond: 0 -> 1 -> 10 -> 10000 -> ... ? -> ... -10000 -> -10 -> -1 -> 0 In this sense, -1/12 is larger than infinity. Now of course this is an ad hoc sloppy argument, but I'm not a professional mathematician. However I can tell you that it's pretty close to what the professional mathematicians and physicists do with negative absolute temperatures, and that is rigorous. http://en.wikipedia.org/wiki/Negative_temperature [...] > Personally I think it's reasonable to just say that the sum of the > natural numbers is infinite rather than messing around with terms like > undefined, divergent, or existence. There is a clear difference between > a series (or any limit) that fails to converge asymptotically and > another that just goes to +-infinity. The difference is usually also > relevant to any practical application of this kind of maths. And this is where you get it exactly backwards. The *practical application* comes from physics, where they do exactly what you argue against: they associate ?(-1) with the sum of the natural numbers (see, I too can avoid the word "equals" too), and *it works*. -- Steven D'Aprano http://import-that.dreamwidth.org/ From emile at fenx.com Wed Mar 5 12:46:04 2014 From: emile at fenx.com (Emile van Sebille) Date: Wed, 05 Mar 2014 09:46:04 -0800 Subject: find and replace string in binary file In-Reply-To: <687bff67-c486-402d-9f50-82e018c75585@googlegroups.com> References: <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> <687bff67-c486-402d-9f50-82e018c75585@googlegroups.com> Message-ID: On 3/5/2014 1:59 AM, loial wrote: > Unfortunately I have to use python 2.6 for this Did you try it? Emile From steve+comp.lang.python at pearwood.info Wed Mar 5 12:49:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 17:49:32 GMT Subject: Working with the set of real numbers References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <531763ab$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Mar 2014 12:50:06 +0000, Mark Lawrence wrote: > On 05/03/2014 12:21, Oscar Benjamin wrote: >> >> Why the dig at physicists? I think most physicists would be able to >> tell you that the sum of all natural numbers is not -1/12. In fact most >> people with very little background in mathematics can tell you that. >> >> > I'll put that one to the test tomorrow morning when the bin men come > round. Do you seriously think that garbos (bin men) know more about mathematics than mathematicians? > I fully expect them to dial 999 and ask that the paramedics are > armed with plenty of sedatives. You know that rather large piece of machinery in Europe called the Large Hadron Collider? The one which is generating some rather extraordinary proofs of fundamental physics, such as the Higgs Boson? A lot of that physics is based on theory which uses the same logic and mathematics that you are mocking. Laugh away, but the universe behaves as if the sum of the natural numbers is -1/12. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Wed Mar 5 13:01:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Mar 2014 05:01:45 +1100 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 6, 2014 at 4:43 AM, Steven D'Aprano wrote: > Physics is the fundamental science, at least according to the physicists, > and Real Soon Now they'll have a Theory Of Everything, something small > enough to print on a tee-shirt, which will explain everything. At least > in principle. Everything is, except what isn't. That's my theory, and I'm sticking to it! ChrisA From ckaynor at zindagigames.com Wed Mar 5 13:03:02 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 5 Mar 2014 10:03:02 -0800 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 5, 2014 at 9:43 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > At one time, Euler summed an infinite series and got -1, from which he > concluded that -1 was (in some sense) larger than infinity. I don't know > what justification he gave, but the way I think of it is to take the > number line from -? to +? and then bend it back upon itself so that there > is a single infinity, rather like the projective plane only in a single > dimension. If you start at zero and move towards increasingly large > numbers, then like Buzz Lightyear you can go to infinity and beyond: > > 0 -> 1 -> 10 -> 10000 -> ... ? -> ... -10000 -> -10 -> -1 -> 0 > This makes me think that maybe the universe is using ones or two complement math (is there a negative zero?)... Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Wed Mar 5 13:12:54 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 5 Mar 2014 12:12:54 -0600 Subject: Reference In-Reply-To: <60b9aaba-7991-415d-b3c6-dc18c5539502@googlegroups.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <60b9aaba-7991-415d-b3c6-dc18c5539502@googlegroups.com> Message-ID: <20140305121254.7932731e@bigbox.christie.dr> On 2014-03-05 09:40, Rustom Mody wrote: > Every object has an identity, a type and a value. An object's > identity never changes once it has been created; you may think of > it as the object's address in memory. The 'is' operator compares > the identity of two objects; the id() function returns an integer > representing its identity (currently implemented as its address). > > from http://docs.python.org/2/reference/datamodel.html Note the "currently", which does not mean "now, always, and forever for every implementation". From http://docs.python.org/3/library/functions.html#id """ Return the ?identity? of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. CPython implementation detail: This is the address of the object in memory. """ This is clearly documented as a *CPython implementation detail*. The id() function is free to return sequential integers, arbitrary integers, memory addresses, GUIDs-as-integers, or hashes-as-integers for some internal representation. The only thing that matters is (1) that id() returns *some* integer identifying the object, and (2) the ability to compare id(thing1) with id(thing2) and see if they are the same or different (assuming thing1 and thing2 share lifetimes during their id() calls), regardless of what is actually returned. > So when you say > > I'll re-iterate that "memory location of the object" isn't a valid > > response. > > well... all I can say is I dont know what to say :-) That you live in a CPython world, unencumbered by experience in other flavors of language-spec-compliant Python interpreters where id() returns integers that *aren't* memory addresses? -tkc From steve+comp.lang.python at pearwood.info Wed Mar 5 13:19:25 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 18:19:25 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> Message-ID: <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 21:47:21 -0800, Rustom Mody wrote: > On Wednesday, March 5, 2014 10:36:37 AM UTC+5:30, Steven D'Aprano wrote: >> On Tue, 04 Mar 2014 19:36:38 -0800, Rustom Mody wrote: > >> > Python's 'is' leaks >> > the machine abstraction. 'id' does it legitimately (somewhat), 'is' >> > does it illegitimately > >> and then later in another post: > >> > "is" in python leaks machine representations into the otherwise clean >> > HLL abstraction in python > >> Rather than respond with incredulity and declare that you have no idea >> what you are talking about, I'll give you the benefit of the doubt, and >> accept the possibility that I am wrong, or possibly misunderstanding >> you. > > Umm... > I guess my language was sloppy (a bit) A machine is ultimately also an > abstraction -- What is firmware/microcode? Is it a virtual machine? etc > Lets leave that however and just take 'machine' as a given. > > Using machines as given, we build reprs for our (programmer's) data > structures > > So data structures are abstractions that have two 'faces' -- the > machine-facing and the programmer-facing What you are describing is normally called the implementation and the interface. > For clarity of expression (and where you perhaps found me sloppy?? not > sure...) its best to call the machine-face 'a representation' and the > programmer-face 'an abstraction' Only if you wish to ignore the standard terminology used by the rest of the computing world, and furthermore re-define the term "abstraction". > Clearly this is a programmer-biased viewpoint. A hardware engineer would > see things differently. As would the user of the app the programmer > programs. This doesn't seem to be relevant. > Which is why to use the locution "is" without appropriate framing is > philosopical is a pretension to a 'God's-eye-view'. If you are privy to > such a viewpoint I'd be interested to know But for the rest of us who > are not, its good to remember there are only perspectives no absolute > truth. And this appears to be meaningless. The best I can come up with is that you're concerned about the philosophical implications of stating that object x is object y. Quite frankly, I think that's silly. Such concerns about identity of physical entities in the real world are *irrelevant*. You seem to be making a category mistake: the word "is" has certain meanings in plain English, with associated philosophical problems, therefore the Python "is" operator must have exactly the same meanings and problems. But this is as silly as thinking that we should be able to use a computer file to cut through metal, or that equality between 1+1 and 2 is a question of human rights. The "is" operator has a well-defined meaning in Python. The "axe of my grandfather" paradox does not apply to the "is" operator. That definition in Python is very simple: the "is" operator returns True if the two operands are the same object, and false if they are different objects. > That python is a hll means that machine reprs are intended to be > abstracted away. 'is' fails to do that -- proof of that being the > discrepancy between is and == There is no discrepancy between "is" and ==, since they are different operators with different semantics. You might as well claim that there is a discrepancy between + and * because 5+7 and 5*7 return different answers. >> Can you explain what machine representations are leaked into Python by >> the is operator? > >> Do you see this as an accident of implementation, a bug that might be >> fixed, or a misfeature that was deliberately designed? > >> Can you elaborate on why id() is legitimate and "is" is not? > > Let me talk of Lisp which is IMHO more philosophically sane. I'd rather you answer the questions I asked rather than change the subject to an irrelevance. [...] > Decide the viewpoint -- choose the appropriate equivence predicate No > claim even remotely to having a clue to metaphysical being that python's > 'is' implies There is no metaphysical implication from Python's "is" operator. If the operator had precisely the same behaviour, but was called "same", as in: a same b => returns True if a and b are the same object => returns False if a and b are not the same object would you claim there was a metaphysical implication? How about if it were called "eq", like Lisp uses? -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Wed Mar 5 13:29:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 18:29:18 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 04 Mar 2014 22:03:36 -0800, Rustom Mody wrote: > On Wednesday, March 5, 2014 10:36:37 AM UTC+5:30, Steven D'Aprano wrote: >> On Tue, 04 Mar 2014 19:36:38 -0800, Rustom Mody wrote: > >> > Python's 'is' leaks >> > the machine abstraction. 'id' does it legitimately (somewhat), 'is' >> > does it illegitimately > > >> Can you elaborate on why id() is legitimate and "is" is not? > > Mostly a question of more or less infelicitous English leading to > philosophical nonsense. [And note I put a 'somewhat'] Well it is certainly true that this discussion has lead to philosophical nonsense from one of us. > I can say "'id' is just 'machine-id' is just address at some low level" You can say it, but you would be wrong. I don't know how many times you have to be told. The id() function in Python is not defined as returning the address of the object. There is no guarantee that objects even have a consistent, stable addresses. Some garbage collectors will move objects around. The Python language does not claim that the id() function will return the address of objects, it says that it will return an abstract ID number that is unique for that object while the object exists. > Its uglier to say "Is is machine-is" > And before you bring it up, "Jython's id is not machine-id" is putting > the cart before the horse. > > "Jython is an imitation of Cpython That's wrong. Jython is not an imitation, it is an independent implementation of the same language. Since both CPython and Jython follow the specification of the language, both are legitimate Python compilers. Both the Jython and CPython id() functions are compliant with the language definition. The Jython id() function is better, because it doesn't encourage people to mistakenly and foolishly imagine that id() equals address. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben+python at benfinney.id.au Wed Mar 5 13:33:49 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Mar 2014 05:33:49 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <60b9aaba-7991-415d-b3c6-dc18c5539502@googlegroups.com> Message-ID: <85siqwebqq.fsf@benfinney.id.au> Rustom Mody writes: > On Wednesday, March 5, 2014 11:50:46 AM UTC+5:30, Ben Finney wrote: > > So, what machine represenatation is leaked? > > > I'll re-iterate that "memory location of the object" isn't a valid > > response. There is no necessary relation between the memory location of > > the object referenced by "foo" and the return value of 'id(foo)'. > > ... however you are both disagreeing with me and also saying Ive not > given the answer and further disagreeing with the python standard, > which I quote: > > Every object has an identity, a type and a value. An object's identity > never changes once it has been created; you may think of it as the > object's address in memory. The 'is' operator compares the identity of > two objects; the id() function returns an integer representing its > identity (currently implemented as its address). > > from http://docs.python.org/2/reference/datamodel.html Right. None of which constitutes a leaking abstraction. I'll repeat the point: the abstraction does not leak if the user of that abstraction has no need to deal with what lies beneath it. In other words: A helpful ?you may think of it as the object's address in memory? does not constitute a leaky abstraction, because it would be just as correct to say ?you may think of it as a snowflake?. There is no need for the user of the abstraction ?object identity? to know anything about the object's location in memory (nor of snowflakes), nor ever to think about it when using the abstraction. You may, as the documentation suggests, think of it that way; but you may also think of it as anything else which agrees with the abstraction. The clause about ?object's location in memory? is not normative, does not matter for using the abstraction, and is not part of the definition. It literally does not matter for the purpose of using the abstraction, so there's no leak. In fact, in the current Python documentation the description has changed: Every object has an identity, a type and a value. An object?s identity never changes once it has been created; you may think of it as the object?s address in memory. The ?is? operator compares the identity of two objects; the id() function returns an integer representing its identity. CPython implementation detail: For CPython, id(x) is the memory address where x is stored. So it's now even clearer that ?memory address where the object is stored? is *not* part of the abstraction, is *not* guaranteed to be what ?id(foo)? returns, and is an implementation detail of one particular implementation, that can be ignored. The abstraction ?object identity? behaves exactly as the documentation says it does, in the absence of any ?object address in memory? concept, and this is not undermined by suggestions that the reader may already have a concept in mind which can help them to imagine the abstraction. > So when you say > > I'll re-iterate that "memory location of the object" isn't a valid > > response. > > well... all I can say is I dont know what to say :-) I'd encourage you to read the documentation for comprehension. Not every word in a discussion of a concept must be normative. I'd also encourage you to report a bug, suggesting a documentation improvement if you have been misled by (the latest version of) the language reference. -- \ ?Of course, everybody says they're for peace. Hitler was for | `\ peace. Everybody is for peace. The question is: what kind of | _o__) peace?? ?Noam Chomsky, 1984-05-14 | Ben Finney From steve+comp.lang.python at pearwood.info Wed Mar 5 13:42:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2014 18:42:46 GMT Subject: How security holes happen References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> <87zjl47l18.fsf@elektro.pacujo.net> Message-ID: <53177025$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Mar 2014 16:54:59 +0200, Marko Rauhamaa wrote: > I don't think Lisp was really originally designed. The history of Lisp is described here in detail: http://www-formal.stanford.edu/jmc/history/lisp/lisp.html Like all complex systems, it did not appear fully-formed in a flash of inspiration. It was both designed and evolved through experimentation. That process of *trying things* and keeping those that work is usually called "design". -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Wed Mar 5 14:00:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Mar 2014 06:00:10 +1100 Subject: How security holes happen In-Reply-To: <53177025$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <20140303221926.GA57537@cskk.homeip.net> <99ca7396-bcb8-49f9-b486-56ae88aa00e5@googlegroups.com> <87d2i1mvg7.fsf@elektro.pacujo.net> <87zjl47l18.fsf@elektro.pacujo.net> <53177025$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 6, 2014 at 5:42 AM, Steven D'Aprano wrote: > On Wed, 05 Mar 2014 16:54:59 +0200, Marko Rauhamaa wrote: > >> I don't think Lisp was really originally designed. > > The history of Lisp is described here in detail: > > http://www-formal.stanford.edu/jmc/history/lisp/lisp.html > > Like all complex systems, it did not appear fully-formed in a flash of > inspiration. It was both designed and evolved through experimentation. > That process of *trying things* and keeping those that work is usually > called "design". There's a difference between iterative design of that nature and initial design. An initial clean design is a good basis for further iterative design; a messy initial design means backward compatibility shackles you. "Originally designed" is different from "constantly worked on". But Lisp has enough variants that the backward compat issue isn't as major. There's no specific need for Scheme to maintain every mistake of Common Lisp, or Clojure to support everything that elisp does. ChrisA From invalid at invalid.invalid Wed Mar 5 14:13:01 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 5 Mar 2014 19:13:01 +0000 (UTC) Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-03-05, Chris Kaynor wrote: > On Wed, Mar 5, 2014 at 9:43 AM, Steven D'Aprano < > steve+comp.lang.python at pearwood.info> wrote: > >> At one time, Euler summed an infinite series and got -1, from which he >> concluded that -1 was (in some sense) larger than infinity. I don't know >> what justification he gave, but the way I think of it is to take the >> number line from -? to +? and then bend it back upon itself so that there >> is a single infinity, rather like the projective plane only in a single >> dimension. If you start at zero and move towards increasingly large >> numbers, then like Buzz Lightyear you can go to infinity and beyond: >> >> 0 -> 1 -> 10 -> 10000 -> ... ? -> ... -10000 -> -10 -> -1 -> 0 >> > > This makes me think that maybe the universe is using ones or two complement > math (is there a negative zero?)... If the Universe (like most all Python implementations) is using IEEE-754 floating point, there is. -- Grant Edwards grant.b.edwards Yow! This PIZZA symbolizes at my COMPLETE EMOTIONAL gmail.com RECOVERY!! From marko at pacujo.net Wed Mar 5 15:23:46 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 22:23:46 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r46g75t9.fsf@elektro.pacujo.net> Steven D'Aprano : > There is no metaphysical implication from Python's "is" operator. If the > operator had precisely the same behaviour, but was called "same", as in: > > a same b > => returns True if a and b are the same object > => returns False if a and b are not the same object > > would you claim there was a metaphysical implication? I would. You are not defining anything because you are not explaining what "same object" means. Set theory obeys the so-called extensionality principle: if two objects are indistinguishable in every way, they are one and the same object. Fermions in particle physics are the same way: if two fermions' quantum states coincide, they are one and the same particle. Now, that's not true for Pythons "bosonic" objects. You can have two objects that are identical except they are not the same. There are (at least) two ways to break the circularity between "is" and "same-objectness:" 1. Give a real or hypothetical reference implementation and state that any other implementation that produces same (or similar enough) outcomes is valid. ("Each object is allocated with the malloc(3) function call. The identity of an object is the value returned by malloc(3).") 2. Give formal axioms that characterize any valid implementation. ("After x = y, x is y" plus a couple of dozen more formal stipulations.) As for teaching the concept in practice, both of the above approaches are probably bad. Take abstract algebra. You don't start teaching a first-grader about groups and rings and work your way down to arithmetics. Rather, you start with counting, move on to arithmetics, bring in vectors and maybe Rubik's Cube and finally try to get the students to understand the general, abstract idea behind it all. Analogously, it may be necessary to teach the "children" first the theory of linear memory, then variables and arrays, then pointers and singly-linked lists. Once these concrete ideas have been understood, the principles behind Python and other higher-level programming languages can be learned. > How about if it were called "eq", like Lisp uses? You are correct. Lisp suffers from the same problem. The underlying reference machine is simpler to present, though, as there are no classes or methods. There are only memory cells and a handful of data types (number, cons, symbol, string or nil). You really get a feel of a physical steam engine. Ten years ago a whole generation of programmers was raised who knew nothing of computing except Java. I wonder how difficult it was for them to get objects, references and identity. Marko From invalid at invalid.invalid Wed Mar 5 15:31:27 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 5 Mar 2014 20:31:27 +0000 (UTC) Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> <87r46g75t9.fsf@elektro.pacujo.net> Message-ID: On 2014-03-05, Marko Rauhamaa wrote: > Set theory obeys the so-called extensionality principle: if two > objects are indistinguishable in every way, they are one and the same > object. Fermions in particle physics are the same way: if two > fermions' quantum states coincide, they are one and the same > particle. > > Now, that's not true for Pythons "bosonic" objects. You can have two > objects that are identical except they are not the same. Wrong. If the two objects are not the same, then they will have different ID values. If the ID values are the same, then you've only got one object. Two different objects are always distinguishable in Python because they will always have different ID values. > There are (at least) two ways to break the circularity between "is" and > "same-objectness:" I'm sorry, what problem are you trying to solve? -- Grant Edwards grant.b.edwards Yow! I'm definitely not at in Omaha! gmail.com From marko at pacujo.net Wed Mar 5 15:34:31 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 22:34:31 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mwh475bc.fsf@elektro.pacujo.net> Steven D'Aprano : > The id() function in Python is not defined as returning the address of > the object. It might as well. If I said id() returns the address of the object in the Python VM's virtual address space, you couldn't call my bluff. Say id() returned the intantiation sequence number. I could say, the infinite linear memory starts from address 0 and each object occupies a single memory slot. > That's wrong. Jython is not an imitation, it is an independent > implementation of the same language. Since both CPython and Jython > follow the specification of the language, both are legitimate Python > compilers. > > Both the Jython and CPython id() functions are compliant with the > language definition. The Jython id() function is better, because it > doesn't encourage people to mistakenly and foolishly imagine that id() > equals address. I agree with everything (how could I not) except the foolishness part: what bad consequence is there for "imagining" that id() equals address? If id() offers the only glimpse into the "memory," we can say that id() *is* the address. Marko From prologic at shortcircuit.net.au Wed Mar 5 15:47:20 2014 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 6 Mar 2014 06:47:20 +1000 Subject: ANN: Python Job Board - Call for volunteers In-Reply-To: <530F52DB.9030708@python.org> References: <530F52DB.9030708@python.org> Message-ID: I'd like to volunteer! On Mar 5, 2014 7:13 PM, "M.-A. Lemburg" wrote: > [Please help spread the word by forwarding to other relevant mailing lists, > user groups, etc. world-wide; thanks :-)] > > Dear Python Community, > > for many years, the Python Job board ( > http://legacy.python.org/community/jobs/) > was run by volunteers - most of the time by just one volunteer at a > time until they moved on to spend their time on other things. > We've now reached such a point again. > > In these years, the volume on the job board has significantly > increased, as it got more and more popular. It is now at around > 2-5 postings per day and most of those positions get filled quickly > - which is an indication of how useful this service is to the > Python community. > > To scale up and revive the job board, the PSF would now like to setup > a *team of volunteers* to run the job board and this is our call for > help. > > > How does the job board work ? > ----------------------------- > > At the moment, the job board is maintained on the legacy site > (http://legacy.python.org/community/jobs/), but since we've > launched our brand new website (http://www.python.org/), we'd like > to move the job board over to that site. > > Instead of the repository based approach used on the old site, > the new site has database support to aid in more easily processing > and filing job listings. > > There's a job board mailing list which helps coordinate the > task of reviewing and filing job offers. Currently, all job > submissions get sent to this mailing list, but with the job board > app, the submission process can be moved over to the website's > database. > > > What does it take to run the job board ? > ---------------------------------------- > > You have to review the job postings, request changes if they are too > long, don't clearly state the need for Python skills, or have quality > issues. > > After review, the job board app will then allow posting the jobs > on the website by simply setting the status to published. > > Communication with the submitters is usually done by email > and via the mailing list, so all team members can see the > communication and help out if necessary. > > Please note: This is just a high level overview. The details > need to be hashed out by the new team. > > > Does the job board app work already ? > ------------------------------------- > > It does, but is disabled at the moment due to lack of volunteers. > > Since the site just launched there may also well be some issues > with the job board app. > > On the positive side there's a lot happening around the site at the > moment, so if you have change requests, these will usually be > implemented quickly - or you can jump in, hack on the > job board app and submit a pull request yourself: > > https://github.com/python/pythondotorg/tree/master/jobs > > These are exciting times and this is your chance to make a > difference ! > > > Ok, I like new challenges - where do I sign up ? > ------------------------------------------------ > > Great :-) Please write to jobs at python.org > > > I have a question... > -------------------- > > If you have questions, you can write me or the PSF board > at psf at python.org. > > > Many thanks, > -- > Marc-Andre Lemburg > Director > Python Software Foundation > http://www.python.org/psf/ > -- > https://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Wed Mar 5 15:46:29 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 22:46:29 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> <87r46g75t9.fsf@elektro.pacujo.net> Message-ID: <87iors74re.fsf@elektro.pacujo.net> Grant Edwards : > Wrong. If the two objects are not the same, then they will have > different ID values. If the ID values are the same, then you've only > got one object. Ok, that circularity again. Say I implement Python. Say I returned a random number for id(), how would that violate the language spec? It would violate the spec. But there would have to be a paragraph in the specification that was violated or a reference test case that failed. For example, this test would demonstrate obviously invalid behavior: >>> print(id(x)) 129 >>> print(id(x)) 201 > I'm sorry, what problem are you trying to solve? I think the discussion spawned from the problem of teaching programming students the right idea of values and objects. A teacher would like to bring in advanced concepts last, but Python seems to force you to get them at the very beginning. Marko From ben+python at benfinney.id.au Wed Mar 5 16:01:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Mar 2014 08:01:21 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> Message-ID: <85iorse4wu.fsf@benfinney.id.au> Marko Rauhamaa writes: > Steven D'Aprano : > > Both the Jython and CPython id() functions are compliant with the > > language definition. The Jython id() function is better, because it > > doesn't encourage people to mistakenly and foolishly imagine that > > id() equals address. > > I agree with everything (how could I not) except the foolishness part: > what bad consequence is there for "imagining" that id() equals > address? It is a false inference. A reference-compliant implementation can contradict your inference (by returning an object identity that is *not* the object's memory address). Any code you've written based on that false inference will break. The fault will be yours, for inferring an assertion that isn't implied by the definition. -- \ ?The surest way to corrupt a youth is to instruct him to hold | `\ in higher esteem those who think alike than those who think | _o__) differently.? ?Friedrich Nietzsche, _The Dawn_, 1881 | Ben Finney From ben+python at benfinney.id.au Wed Mar 5 16:07:25 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Mar 2014 08:07:25 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> <87r46g75t9.fsf@elektro.pacujo.net> <87iors74re.fsf@elektro.pacujo.net> Message-ID: <85eh2ge4mq.fsf@benfinney.id.au> Marko Rauhamaa writes: > Say I implement Python. Say I returned a random number for id(), how > would that violate the language spec? You could do that, certainly. So long as that randomly-chosen integer was always the same for every object, and never the same for any other concurrently-existing object, it can just as well be assigned randomly. If you're saying that your implementation of ?id(foo)? would return a *different* integer when called at different times for the same object, then yes, that violates the specification for that function. > It would violate the spec. But there would have to be a paragraph in > the specification that was violated or a reference test case that > failed. Yes. It would violate this paragraph: Every object has an identity, a type and a value. An object?s identity never changes once it has been created [?] the id() function returns an integer representing its identity. Again, I ask you to read these documents for comprehension. > For example, this test would demonstrate obviously invalid behavior: > > >>> print(id(x)) > 129 > >>> print(id(x)) > 201 Yes. That violates the paragraph above, and so that implementation is not compliant with the Python language reference. -- \ ?I watched the Indy 500, and I was thinking that if they left | `\ earlier they wouldn't have to go so fast.? ?Steven Wright | _o__) | Ben Finney From ben+python at benfinney.id.au Wed Mar 5 16:10:32 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Mar 2014 08:10:32 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> <87r46g75t9.fsf@elektro.pacujo.net> <87iors74re.fsf@elektro.pacujo.net> Message-ID: <85a9d4e4hj.fsf@benfinney.id.au> Marko Rauhamaa writes: > Grant Edwards : > > > Wrong. If the two objects are not the same, then they will have > > different ID values. If the ID values are the same, then you've only > > got one object. > > Ok, that circularity again. Yes, it's circular. In an abstract system like a programming language, where the definition only needs to describe behaviour of that system, what is your objection to circularity of definition? A great many abstract systems designed by humans are defined in terms that are ultimately circular. This does not in any way hinder them from being useful definitions of useful systems. -- \ ?All opinions are not equal. Some are a very great deal more | `\ robust, sophisticated and well supported in logic and argument | _o__) than others.? ?Douglas Adams | Ben Finney From marko at pacujo.net Wed Mar 5 16:14:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 23:14:44 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> Message-ID: <87bnxk73gb.fsf@elektro.pacujo.net> Ben Finney : > A reference-compliant implementation can contradict your inference (by > returning an object identity that is *not* the object's memory > address). Any code you've written based on that false inference will > break. > > The fault will be yours, for inferring an assertion that isn't implied > by the definition. Show me a few lines of Python that demonstrate the error of the false inference, please. When I talk about an object's memory address, I'm not referring to what might be revealed by gdb, for example. That is, I'm not talking about the process's virtual address space, nor am I talking about the physical address on the address bus. I can simply define that the object's memory address is whatever id() returns. Marko From oscar.j.benjamin at gmail.com Wed Mar 5 16:22:15 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 5 Mar 2014 21:22:15 +0000 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5 March 2014 17:43, Steven D'Aprano wrote: > On Wed, 05 Mar 2014 12:21:37 +0000, Oscar Benjamin wrote: >> >> The argument that the sum of all natural numbers comes to -1/12 is just >> some kind of hoax. I don't think *anyone* seriously believes it. > > You would be wrong. I suggest you read the links I gave earlier. Even the > mathematicians who complain about describing this using the word "equals" > don't try to dispute the fact that you can identify the sum of natural > numbers with ?(-1), or that ?(-1) = -1/12. They simply dispute that we > should describe this association as "equals". > > What nobody believes is that the sum of natural numbers is a convergent > series that sums to -1/12, because it is provably not. > > In other words, this is not an argument about the maths. Everyone who > looks at the maths has to admit that it is sound. It's an argument about > the words we use to describe this. Is it legitimate to say that the > infinite sum *equals* -1/12? Or only that the series has the value -1/12? > Or that we can "associate" (talk about a sloppy, non-vigorous term!) the > series with -1/12? This is the point. You can "identify" numbers with many different things. It does not mean to say that the thing is equal to that number. I can associate the number 2 with my bike since it has 2 wheels. That doesn't mean that the bike is equal to 2. So the problem with saying that "the sum of the natural numbers equals -1/12" is precisely as you say with the word "equals" because they're not equal! If you restate the conclusion in more accurate (but technical and less accessible) way that "the analytic continuation of a related set of convergent series has the value -1/12 at the value that would correspond to this divergent series" then it becomes less mysterious. Do I really have to associate the finite negative value found in the analytic continuation with the sum of the series that is provably greater than any finite number? > > At one time, Euler summed an infinite series and got -1, from which he > concluded that -1 was (in some sense) larger than infinity. I don't know > what justification he gave, but the way I think of it is to take the > number line from -? to +? and then bend it back upon itself so that there > is a single infinity, rather like the projective plane only in a single > dimension. If you start at zero and move towards increasingly large > numbers, then like Buzz Lightyear you can go to infinity and beyond: > > 0 -> 1 -> 10 -> 10000 -> ... ? -> ... -10000 -> -10 -> -1 -> 0 > > In this sense, -1/12 is larger than infinity. There are many examples that appear to show wrapping round from +infinity to -infinity e.g. the tan function. The thing is that it is not really "physical" (or meaningful in any direct sense). So for example I might consider the forces on a particle, apply Newton's 2nd law and arrive at a differential equation for the acceleration of the particle, solve the equation and find that the position of the particle at time t is given by tan(t). This would seem to imply that as t increases toward pi/2 the particle heads off infinity miles West but at the exact time pi/2 it wraps around to reappear at infinity miles East and starts heading back toward its starting point. The truth is less interesting: the solution tan(t) becomes invalid at pi/2 and mathematics can tell us nothing about what happens after that even if all the physics we used was exactly true. > Now of course this is an ad hoc sloppy argument, but I'm not a > professional mathematician. However I can tell you that it's pretty close > to what the professional mathematicians and physicists do with negative > absolute temperatures, and that is rigorous. > > http://en.wikipedia.org/wiki/Negative_temperature The key point from that page is the sentence "A definition of temperature can be based on the relationship...". It is clear that temperature is a theoretical abstraction. We have intuitive understandings of what it means but in order for the current body of thermodynamic theory to be consistent it is necessary to sometimes give negative values to the temperature. There's nothing unintuitive about negative temperatures if you understand the usual thermodynamic definitions of "temperature". >> Personally I think it's reasonable to just say that the sum of the >> natural numbers is infinite rather than messing around with terms like >> undefined, divergent, or existence. There is a clear difference between >> a series (or any limit) that fails to converge asymptotically and >> another that just goes to +-infinity. The difference is usually also >> relevant to any practical application of this kind of maths. > > And this is where you get it exactly backwards. The *practical > application* comes from physics, where they do exactly what you argue > against: they associate ?(-1) with the sum of the natural numbers (see, I > too can avoid the word "equals" too), and *it works*. I don't know all the details of what they do there and whether or not there's a better way of doing it or perhaps a better way of thinking about the mathematical procedures they apply. (I'm assuming you're talking about the Casimir effect here). Let's use a more down to earth example though. Every day from now I'll give you N pounds where N is the number of days from today. so tomorrow I'll give you 1 pound, the next day 2 pounds and so on. If this continues for an infinitely long time then you will have been given an infinite amount of money. If you phrase the question like this then I think the professional mathematicians you're referring to will agree that the sum is infinite. (It's possible that the money I said I'd send will not materialise. If you receive a bill for 8 pence you'll know that I was wrong which should console you for the missing infinite amounts of money). Oscar From rosuav at gmail.com Wed Mar 5 16:26:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Mar 2014 08:26:22 +1100 Subject: Reference In-Reply-To: <87bnxk73gb.fsf@elektro.pacujo.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 6, 2014 at 8:14 AM, Marko Rauhamaa wrote: > When I talk about an object's memory address, I'm not referring to what > might be revealed by gdb, for example. That is, I'm not talking about > the process's virtual address space, nor am I talking about the physical > address on the address bus. I can simply define that the object's memory > address is whatever id() returns. Where's the complaints about circularity now? You're saying "But of course id() returns the address, as long as we define the address as 'whatever id() returns'.". Unimpeachably logical and utterly unhelpful. ChrisA From python.list at tim.thechases.com Wed Mar 5 16:33:53 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 5 Mar 2014 15:33:53 -0600 Subject: Reference In-Reply-To: <87bnxk73gb.fsf@elektro.pacujo.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> Message-ID: <20140305153353.4b948c31@bigbox.christie.dr> On 2014-03-05 23:14, Marko Rauhamaa wrote: > When I talk about an object's memory address, I'm not referring to > what might be revealed by gdb, for example. That is, I'm not > talking about the process's virtual address space, nor am I talking > about the physical address on the address bus. I can simply define > that the object's memory address is whatever id() returns. Let me translate what the rest of the group hears: """ When I talk about an object's memory address, I'm not referring to *what every other computer scientist/professional means by "memory address" rather I can simply make up my own definition for "memory address" so that it means something that proves my point.* """ It's perfectly valid for the definition of id() to return negative numbers, yet in just about every situation (both hypothetical CS worlds and out in the real world), a memory-address is defined as an unsigned number. -tkc From breamoreboy at yahoo.co.uk Wed Mar 5 16:34:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 21:34:40 +0000 Subject: Reference In-Reply-To: <87iors74re.fsf@elektro.pacujo.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> <87r46g75t9.fsf@elektro.pacujo.net> <87iors74re.fsf@elektro.pacujo.net> Message-ID: On 05/03/2014 20:46, Marko Rauhamaa wrote: > > I think the discussion spawned from the problem of teaching programming > students the right idea of values and objects. A teacher would like to > bring in advanced concepts last, but Python seems to force you to get > them at the very beginning. > Nonsense, people starting out with Python have stated how easy it is to just start writing Python code. This would obviously not be possible if advanced concepts had to be learned up front. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ben+python at benfinney.id.au Wed Mar 5 16:37:19 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Mar 2014 08:37:19 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> Message-ID: <851tyge38w.fsf@benfinney.id.au> Marko Rauhamaa writes: > Ben Finney : > > > A reference-compliant implementation can contradict your inference (by > > returning an object identity that is *not* the object's memory > > address). Any code you've written based on that false inference will > > break. > > > > The fault will be yours, for inferring an assertion that isn't implied > > by the definition. > > Show me a few lines of Python that demonstrate the error of the false > inference, please. It need not be Python; it could be an extension library to which you pass the ?id(foo)? result, on the false assumption that it must be a memory location. Besides which, it is *you* that declares this abstraction to be leaky. If you're unable to show how that's the case, I rest on the null hypothesis: your assertion is untrue. > When I talk about an object's memory address, I'm not referring to > what might be revealed by gdb, for example. That is, I'm not talking > about the process's virtual address space, nor am I talking about the > physical address on the address bus. I can simply define that the > object's memory address is whatever id() returns. Then this does not count as a leaky abstraction. All you're saying is that the ?id(foo)? result is a representation of the object identity, which is entirely at the level of the abstraction. Nothing is leaked. -- \ ?God forbid that any book should be banned. The practice is as | `\ indefensible as infanticide.? ?Dame Rebecca West | _o__) | Ben Finney From keplero1 at hotmail.com Wed Mar 5 16:41:10 2014 From: keplero1 at hotmail.com (Luciano Trespidi) Date: Wed, 5 Mar 2014 22:41:10 +0100 Subject: Program Python Message-ID: I'm very grateful if anyone can helpme to find a good program to develop in python lenguage. Thanks Inviato da: Ernesto Luciano Trespidi Email: keplero1 at hotmail.com Tel. 3299255463 From breamoreboy at yahoo.co.uk Wed Mar 5 16:46:29 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 05 Mar 2014 21:46:29 +0000 Subject: Reference In-Reply-To: <20140305153353.4b948c31@bigbox.christie.dr> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> <20140305153353.4b948c31@bigbox.christie.dr> Message-ID: On 05/03/2014 21:33, Tim Chase wrote: > On 2014-03-05 23:14, Marko Rauhamaa wrote: >> When I talk about an object's memory address, I'm not referring to >> what might be revealed by gdb, for example. That is, I'm not >> talking about the process's virtual address space, nor am I talking >> about the physical address on the address bus. I can simply define >> that the object's memory address is whatever id() returns. > > Let me translate what the rest of the group hears: > > """ > When I talk about an object's memory address, I'm not referring to > *what every other computer scientist/professional means by "memory > address" rather I can simply make up my own definition for "memory > address" so that it means something that proves my point.* > """ > > It's perfectly valid for the definition of id() to return negative > numbers, yet in just about every situation (both hypothetical CS > worlds and out in the real world), a memory-address is defined as an > unsigned number. > > -tkc > > I actually hear the spam song, except s/spam/troll/ Didn't we learn anything from the sadly still ongoing saga of our resident unicode expert? :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ben+python at benfinney.id.au Wed Mar 5 16:53:05 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Mar 2014 08:53:05 +1100 Subject: Program Python References: Message-ID: <85wqg8cny6.fsf@benfinney.id.au> Luciano Trespidi writes: > I'm very grateful if anyone can helpme to find a good program to develop in python lenguage. > Thanks The best program to use for developing in the Python language is the Python interpreter :-) Beyond which, you may be interested in the Python community's ?tutor? forum , a great resource for asking questions about the basics of Python. -- \ ?The most common of all follies is to believe passionately in | `\ the palpably not true. It is the chief occupation of mankind.? | _o__) ?Henry L. Mencken | Ben Finney From marko at pacujo.net Wed Mar 5 16:50:26 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 05 Mar 2014 23:50:26 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> Message-ID: <874n3c71st.fsf@elektro.pacujo.net> Chris Angelico : > On Thu, Mar 6, 2014 at 8:14 AM, Marko Rauhamaa wrote: >> When I talk about an object's memory address, I'm not referring to >> what might be revealed by gdb, for example. That is, I'm not talking >> about the process's virtual address space, nor am I talking about the >> physical address on the address bus. I can simply define that the >> object's memory address is whatever id() returns. > > Where's the complaints about circularity now? You're saying "But of > course id() returns the address, as long as we define the address as > 'whatever id() returns'.". Unimpeachably logical and utterly > unhelpful. Main thing, no harm done. The memory address is neither right nor wrong. It's completely irrelevant since it doesn't occupy a place in Python's data model. Marko From gheskett at wdtv.com Wed Mar 5 17:21:03 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Wed, 5 Mar 2014 17:21:03 -0500 Subject: How to create an instance of a python class from C++ In-Reply-To: References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> Message-ID: <201403051721.03598.gheskett@wdtv.com> On Wednesday 05 March 2014 17:09:53 Grant Edwards did opine: > On 2014-03-05, Alister wrote: > >>> Why are you creating an ABC? > >> > >> Because it was the first binary computer that did calculations with > >> electronic switching elements (gates), and it would be really cool to > >> have one! The ABC also pioneered the use of capciators as > >> regenerative storage elements (it's how DRAM still works today). > >> > >> http://en.wikipedia.org/wiki/Atanasoff%E2%80%93Berry_Computer > >> > >> It predated ENIAC, and it's clear that some of the features of ENIAC > >> were inspired by the ABC after John Mauchly visited Iowa State and > >> saw the ABC. > > > > But it was not programmable > > True. It had only one program that was hard-wired into it when it was > built as opposed to the external patch-cords and switches that were > used on machines like Colossus and ENIAC to alter the wiring. > > > the first programmable electronic computer was 'Colossus' which was > > developed during WWII but remained classified by the UK govt for many > > years afterwards > > > > http://en.wikipedia.org/wiki/Colossus_computer What machine was it that had about 12,000 12AU7 vacuum tubes in it for logic? They had one of those, adapted to read the output of a bed of photocells installed in a Harris sheet fed press on the SUI campus in the later 1950's. I saw it running once, grading the test score sheets from the Iowa Tests that were being used in lieu of the high price per seat S-B IQ test in the Iowa schools. It was IIRC a somewhat difficult test when they threw it at me in the 7th grade a decade earlier, they claimed the test score were interchangeable with the S-B scores, but I somehow managed a 147 on it at the time. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page NOTICE: Will pay 100 USD for an HP-4815A defective but complete probe assembly. From larry.martell at gmail.com Wed Mar 5 17:27:31 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 5 Mar 2014 17:27:31 -0500 Subject: script uses up all memory Message-ID: I have a script that forks off other processes and attempts to manage them. Here is a stripped down version of the script: self.sleepTime = 300 self.procs = {} self.startTimes = {} self.cmd = ['python', '/usr/local/motor/motor/app/some_other_script.py'] while True: try: self.tools = Tool.objects.filter(ip__isnull=False) except Exception, e: print 'error from django call: ' + str(e) sys.exit(1) for tool in self.tools: name = tool.name if name in self.procs: if self.procs[name].poll() is None: if (datetime.datetime.now()-self.startTimes[name]) > datetime.timedelta(hours=12): # it's been running too long - kill it print 'killing script for ' + name + " it's been running too long" self.procs[name].kill() else: continue if self.procs[name].returncode: print 'scrikpt failed for ' + name + ', error = ' + str(self.procs[name].returncode) print 'starting script.py for ' + name + ' at ' + str(datetime.datetime.now()) try: self.procs[name] = subprocess.Popen(self.cmd) self.startTimes[name] = datetime.datetime.now() except Exception, e: print 'error from Popen: ' + str(e) sys.exit(1) else: print 'starting script.py for ' + name + ' at ' + str(datetime.datetime.now()) try: self.procs[name] = subprocess.Popen(self.cmd) self.startTimes[name] = datetime.datetime.now() except Exception, e: print 'error from Popen: ' + str(e) sys.exit(1) time.sleep(self.sleepTime) The script does what it's intended to do, however after about 2 hours it has used up all the memory available and the machine hangs. Can anyone see something that I am doing here that would be using memory like this? Perhaps some immutable object needs to be repeatedly recreated? From rosuav at gmail.com Wed Mar 5 17:39:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Mar 2014 09:39:47 +1100 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Thu, Mar 6, 2014 at 9:27 AM, Larry Martell wrote: > I have a script that forks off other processes and attempts to manage > them. Here is a stripped down version of the script: > > self.sleepTime = 300 That's not a stand-alone script. What environment is it running in? Can you reproduce the problem outside of that environment? Also: Can you simply use multiprocessing rather than going through all the effort of subprocess.Popen? ChrisA From drsalists at gmail.com Wed Mar 5 17:42:09 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 5 Mar 2014 14:42:09 -0800 Subject: ANN: Python Job Board - Call for volunteers In-Reply-To: <530F52DE.9000704@python.org> References: <530F52DE.9000704@python.org> Message-ID: I hope this means there'll soon be an option to restrict ads seen by some form of postal code or phone area code (with telecommute hopefully being an optional wildcard). On Thu, Feb 27, 2014 at 6:59 AM, M.-A. Lemburg wrote: > [Please help spread the word by forwarding to other relevant mailing lists, > user groups, etc. world-wide; thanks :-)] > > Dear Python Community, > > for many years, the Python Job board (http://legacy.python.org/community/jobs/) > was run by volunteers - most of the time by just one volunteer at a > time until they moved on to spend their time on other things. > We've now reached such a point again. From tjreedy at udel.edu Wed Mar 5 18:00:57 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 05 Mar 2014 18:00:57 -0500 Subject: Reference In-Reply-To: <87iors74re.fsf@elektro.pacujo.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> <87r46g75t9.fsf@elektro.pacujo.net> <87iors74re.fsf@elektro.pacujo.net> Message-ID: On 3/5/2014 3:46 PM, Marko Rauhamaa wrote: > Grant Edwards : > >> Wrong. If the two objects are not the same, then they will have >> different ID values. If the ID values are the same, then you've only >> got one object. > > Ok, that circularity again. Every deductive system starts with some undefined terms. These, along with axioms or postulates, are how circularity is avoided. There typically is a choice as to which concepts are taken as primitive and which are defined in terms of them. In Python, one could take 'object' and the notions of same versus different object as primitive. > Say I implement Python. Say I returned a random number for id(), In CPython, the int id of an object is arbitrary, somewhat haphazard, and effectively random in the colloquial sense of the term. > how would that violate the language spec? It obviously does not as long as the 'random' id obeys the id axioms of persistence and uniqueness. > I think the discussion spawned from the problem of teaching programming > students the right idea of values and objects. A teacher would like to > bring in advanced concepts last, but Python seems to force you to get > them at the very beginning. Kids learn the notion of object persistence quite early (first year, I think). Kids also learn that there are multiple ways of referring to one and the same person or object, and that some references ('teacher') can be rebound to a different person or object. -- Terry Jan Reedy From python.list at tim.thechases.com Wed Mar 5 16:56:51 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 5 Mar 2014 15:56:51 -0600 Subject: Program Python In-Reply-To: References: Message-ID: <20140305155651.3eb8094d@bigbox.christie.dr> On 2014-03-05 22:41, Luciano Trespidi wrote: > I'm very grateful if anyone can helpme to find a good program to > develop in python lenguage. Thanks This reminds me of the old joke: Q: Why are you scratching yourself? A: Because I'm the only one who knows where I itch! The best place to find a good program to develop in Python is to look at what you want to be able to do, but haven't found something that does what you want. Perhaps you tire of manually processing files at work and want to automate it. Perhaps you want to email your Mum on one random day each month. Perhaps you want to calculate lottery numbers according to your own personal preference. Perhaps you want to make a game. So many possibilities. So look for something that would scratch an itch you have, and go for it! :-) -tkc From larry.martell at gmail.com Wed Mar 5 19:20:13 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 5 Mar 2014 19:20:13 -0500 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Wed, Mar 5, 2014 at 5:39 PM, Chris Angelico wrote: > On Thu, Mar 6, 2014 at 9:27 AM, Larry Martell wrote: >> I have a script that forks off other processes and attempts to manage >> them. Here is a stripped down version of the script: >> >> self.sleepTime = 300 > > That's not a stand-alone script. No, that is just the part that does the work (inside the 'while true'). I'll try and post a standalone script tomorrow. > What environment is it running in? CentOS 6,4 > Can you reproduce the problem outside of that environment? I will try that tomorrow. > Also: Can you simply use multiprocessing rather than going through all > the effort of subprocess.Popen? Perhaps. I didn't write this. A client gave it to me and said 'figure out why it uses up all the memory and hangs.' I've messed around with for days and cannot see anything that would consume so much memory. From rosuav at gmail.com Wed Mar 5 19:33:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Mar 2014 11:33:45 +1100 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Thu, Mar 6, 2014 at 11:20 AM, Larry Martell wrote: > On Wed, Mar 5, 2014 at 5:39 PM, Chris Angelico wrote: >> On Thu, Mar 6, 2014 at 9:27 AM, Larry Martell wrote: >>> I have a script that forks off other processes and attempts to manage >>> them. Here is a stripped down version of the script: >>> >>> self.sleepTime = 300 >> >> That's not a stand-alone script. > > No, that is just the part that does the work (inside the 'while > true'). I'll try and post a standalone script tomorrow. > >> What environment is it running in? > > CentOS 6,4 That's not the whole environment, though. There's a mention of Django - does this run inside some framework? >> Can you reproduce the problem outside of that environment? > > I will try that tomorrow. Running as a stand-alone script, still under CentOS, would be what I mean by "outside of that environment". I'm talking about making something that can be saved to my drive and executed, perhaps with a stubby subprocess script (eg "import time; time.sleep(86400)"). >> Also: Can you simply use multiprocessing rather than going through all >> the effort of subprocess.Popen? > > Perhaps. I didn't write this. A client gave it to me and said 'figure > out why it uses up all the memory and hangs.' I've messed around with > for days and cannot see anything that would consume so much memory. Ah. Yeah, that would be a fun little job to play with. My random thought: Do the subprocesses produce spammy log output? If so, the monitor might be collecting it all and holding it in memory in case you want it (not knowing that you don't). The default should be to leave them connected to your process's stdio streams, though, so that shouldn't be the issue. ChrisA From steve+comp.lang.python at pearwood.info Wed Mar 5 19:35:33 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2014 00:35:33 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> Message-ID: <5317c2d5$0$29985$c3e8da3$5496439d@news.astraweb.com> On Thu, 06 Mar 2014 08:26:22 +1100, Chris Angelico wrote: > On Thu, Mar 6, 2014 at 8:14 AM, Marko Rauhamaa wrote: >> When I talk about an object's memory address, I'm not referring to what >> might be revealed by gdb, for example. That is, I'm not talking about >> the process's virtual address space, nor am I talking about the >> physical address on the address bus. I can simply define that the >> object's memory address is whatever id() returns. > > Where's the complaints about circularity now? You're saying "But of > course id() returns the address, as long as we define the address as > 'whatever id() returns'.". Unimpeachably logical and utterly unhelpful. That last sentence is wrong. There is nothing logical about just making up arbitrary definitions in this way. He could invent *any* definition, each more ridiculous than the last: - it's the object's memory address; - it's the object's phone number; - it's the number of baby elephants killed by the object; - it's the number of intergalactic empires that are, even as we speak, rushing to Earth to invade to gain possession of that object; - it's the weight in metric tonnes of the electrons in the object; (Not *actual* electrons of course, just these arbitrary inventions of Marko's definition.) - it's the length measured in seconds of the bitterness of the object's kidney; and of course: - the number of angels that can dance on the object. -- Steven D'Aprano http://import-that.dreamwidth.org/ From larry.martell at gmail.com Wed Mar 5 19:43:23 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 5 Mar 2014 19:43:23 -0500 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Wed, Mar 5, 2014 at 7:33 PM, Chris Angelico wrote: > On Thu, Mar 6, 2014 at 11:20 AM, Larry Martell wrote: >> On Wed, Mar 5, 2014 at 5:39 PM, Chris Angelico wrote: >>> On Thu, Mar 6, 2014 at 9:27 AM, Larry Martell wrote: >>>> I have a script that forks off other processes and attempts to manage >>>> them. Here is a stripped down version of the script: >>>> >>>> self.sleepTime = 300 >>> >>> That's not a stand-alone script. >> >> No, that is just the part that does the work (inside the 'while >> true'). I'll try and post a standalone script tomorrow. >> >>> What environment is it running in? >> >> CentOS 6.4 > > That's not the whole environment, though. There's a mention of Django > - does this run inside some framework? The system this is part of uses Django, and this script makes use of the django ORM, but it doesn't do any web stuff itself. It just kicks off another script once for each tool found in the database, and ensure that there's just one script pre tool running at a time, and that no single script runs too long. The django part can easily be removed. >>> Can you reproduce the problem outside of that environment? >> >> I will try that tomorrow. > > Running as a stand-alone script, still under CentOS, would be what I > mean by "outside of that environment". I'm talking about making > something that can be saved to my drive and executed, perhaps with a > stubby subprocess script (eg "import time; time.sleep(86400)"). Yes, I understand what you mean. > >>> Also: Can you simply use multiprocessing rather than going through all >>> the effort of subprocess.Popen? >> >> Perhaps. I didn't write this. A client gave it to me and said 'figure >> out why it uses up all the memory and hangs.' I've messed around with >> for days and cannot see anything that would consume so much memory. > > Ah. Yeah, that would be a fun little job to play with. My random > thought: Do the subprocesses produce spammy log output? If so, the > monitor might be collecting it all and holding it in memory in case > you want it (not knowing that you don't). The default should be to > leave them connected to your process's stdio streams, though, so that > shouldn't be the issue. Ohh, that's a good random thought. I'll try that tomorrow and see if that's the issue. From rosuav at gmail.com Wed Mar 5 19:50:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Mar 2014 11:50:10 +1100 Subject: Reference In-Reply-To: <5317c2d5$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> <5317c2d5$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 6, 2014 at 11:35 AM, Steven D'Aprano wrote: > On Thu, 06 Mar 2014 08:26:22 +1100, Chris Angelico wrote: > >> Where's the complaints about circularity now? You're saying "But of >> course id() returns the address, as long as we define the address as >> 'whatever id() returns'.". Unimpeachably logical and utterly unhelpful. > > That last sentence is wrong. There is nothing logical about just making > up arbitrary definitions in this way. He could invent *any* definition, > each more ridiculous than the last: I mean logical in the sense of pure logic. If all spam is edible-food And if this-can is spam Then this-can is edible-food The opening premise is false (I wouldn't want to eat a punctured can that's been sitting around for a few months), but it's still perfectly logical. The conclusion is guaranteed to be true as long as the premises are. In that sense of the word, the statement is indeed logical. That doesn't stop it from being wrong, but it is logical. If the 'is' comparison is reflexive, And if three is four, Then four is three. Perfectly logical. He's saying that the address of an object is simply "whatever id() returns for that object". Since Python doesn't currently have any other concept of object addresses, that definition isn't in conflict with anything. Then he says, look! the id() function returns the object's address. Well, duh, that's how you defined the address. It's logical. Of course it returns "the address", since "the address" has been defined as what it returns. But it doesn't achieve anything to prove that. ChrisA From marko at pacujo.net Wed Mar 5 19:52:38 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 06 Mar 2014 02:52:38 +0200 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> Message-ID: <87mwh45esp.fsf@elektro.pacujo.net> Ben Finney : > Marko Rauhamaa writes: >> When I talk about an object's memory address, I'm not referring to >> what might be revealed by gdb, for example. That is, I'm not talking >> about the process's virtual address space, nor am I talking about the >> physical address on the address bus. I can simply define that the >> object's memory address is whatever id() returns. > > Then this does not count as a leaky abstraction. All you're saying is > that the ?id(foo)? result is a representation of the object identity, > which is entirely at the level of the abstraction. Nothing is leaked. I wasn't making a point about a leaky abstraction. I was just saying talking about id() as a memory address isn't all that bad. It's a bit like rolling down your power windows or turning up the volume, when there's nothing to roll or turn. There's no risk of getting your program wrong. Marko From ben+python at benfinney.id.au Wed Mar 5 20:05:18 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 06 Mar 2014 12:05:18 +1100 Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> <87mwh45esp.fsf@elektro.pacujo.net> Message-ID: <85eh2gcf1t.fsf@benfinney.id.au> Marko Rauhamaa writes: > Ben Finney : > > > Then this does not count as a leaky abstraction. All you're saying is > > that the ?id(foo)? result is a representation of the object identity, > > which is entirely at the level of the abstraction. Nothing is leaked. > > I wasn't making a point about a leaky abstraction. Can we conclude that you've changed your position on this, then? You now accept that Python's object identity abstraction is not leaky? In the absence of you demonstrating a leak in that abstraction, we can ignore the assertion. -- \ ?For myself, I am an optimist ? it does not seem to be much use | `\ being anything else.? ?Winston Churchill, 1954-11-09 | _o__) | Ben Finney From harrismh777 at gmail.com Wed Mar 5 20:24:44 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Wed, 5 Mar 2014 17:24:44 -0800 (PST) Subject: How security holes happen In-Reply-To: References: <87d2i1mvg7.fsf@elektro.pacujo.net> <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <5adebc12-aa37-4139-82d8-563f46a27dc0@googlegroups.com> On Wednesday, March 5, 2014 6:24:52 PM UTC-6, Dennis Lee Bieber wrote: > I must have had a deprived life... > > The only "debug" on a home system I ever used was the one in LS-DOS. > And even then, it was only because an OS update disk arrived with a bad > sector and could not be copied. Not many people realized what they had in front of them. The only reason you might is if you 'grew up' on a system that required machine coding; like the Wang 700 series, or the MITS Altair 8800, or the VIC 20 with VicMon. I grew up with all three. So, before I ever learned a line of BASIC I was coding machine language (not assembler) on the three platforms above... the wang used integrated circuits, but had to processor chip; the MITS used the very first 8080 chip from Intel, and the VIC 20 used the 6502 from Motorola. My first personal computer (I did not own it, it was temporarily loaned to me) was the VIC 20. It only had 5k of memory, so anyone who did any real programming on it purchased the VicMon cartridge which was a 'machine language monitor'. It was "DEBUG.COM" for the VIC 20. When I got the first copy of DOS on floppy and saw DEBUG.COM I knew instantly what it was... a machine language monitor system for reading and writing machine code (8086 / 8088) in memory, or to disk sectors, or to disk as a file-name. It wasn't just a debugger---hardly! It was (and still is, yes, I still use it) a simple clean full-blown machine language monitor capable today just as then, to build sophisticated applications with 1's and 0's/ It was also my cup of tea, as it were. The folks who used the MITS Altair 8800 hated punching code in by hand; gets old fast. But not for me. I loved it, because I was as interested in the 8080 processor as I was in writing programs for it; it was great fun experimenting with memory and the processor. marcus From harrismh777 at gmail.com Wed Mar 5 20:36:55 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Wed, 5 Mar 2014 17:36:55 -0800 (PST) Subject: test Message-ID: test please disregard From python at mrabarnett.plus.com Wed Mar 5 20:40:05 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 06 Mar 2014 01:40:05 +0000 Subject: How security holes happen In-Reply-To: <5adebc12-aa37-4139-82d8-563f46a27dc0@googlegroups.com> References: <87d2i1mvg7.fsf@elektro.pacujo.net> <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> <5adebc12-aa37-4139-82d8-563f46a27dc0@googlegroups.com> Message-ID: <5317D1F5.5080907@mrabarnett.plus.com> On 2014-03-06 01:24, Mark H. Harris wrote: > On Wednesday, March 5, 2014 6:24:52 PM UTC-6, Dennis Lee Bieber > wrote: >> I must have had a deprived life... >> >> The only "debug" on a home system I ever used was the one in >> LS-DOS. And even then, it was only because an OS update disk >> arrived with a bad sector and could not be copied. > > Not many people realized what they had in front of them. The only > reason you might is if you 'grew up' on a system that required > machine coding; like the Wang 700 series, or the MITS Altair 8800, > or the VIC 20 with VicMon. > > I grew up with all three. So, before I ever learned a line of BASIC I > was coding machine language (not assembler) on the three platforms > above... the wang used integrated circuits, but had to processor > chip; the MITS used the very first 8080 chip from Intel, and the VIC > 20 used the 6502 from Motorola. > The 6502 came from MOS Technology. Motorola made the 6800. > My first personal computer (I did not own it, it was temporarily > loaned to me) was the VIC 20. It only had 5k of memory, so anyone > who did any real programming on it purchased the VicMon cartridge > which was a 'machine language monitor'. It was "DEBUG.COM" for the > VIC 20. > 5K? Luxury! I started with the Science of Cambridge Mk14. Including the RAM on the I/O chip, it had 640 bytes. > When I got the first copy of DOS on floppy and saw DEBUG.COM I knew > instantly what it was... a machine language monitor system for > reading and writing machine code (8086 / 8088) in memory, or to disk > sectors, or to disk as a file-name. It wasn't just a > debugger---hardly! It was (and still is, yes, I still use it) a > simple clean full-blown machine language monitor capable today just > as then, to build sophisticated applications with 1's and 0's/ > > It was also my cup of tea, as it were. The folks who used the MITS > Altair 8800 hated punching code in by hand; gets old fast. But not > for me. I loved it, because I was as interested in the 8080 processor > as I was in writing programs for it; it was great fun experimenting > with memory and the processor. > From anikom15 at gmail.com Wed Mar 5 20:56:14 2014 From: anikom15 at gmail.com (=?ISO-8859-1?Q?Westley_Mart=EDnez?=) Date: Wed, 5 Mar 2014 17:56:14 -0800 (PST) Subject: Origin of 'self' In-Reply-To: <531426b8$0$2923$c3e8da3$76491128@news.astraweb.com> References: <531426b8$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <1634feec-9f23-4f46-bd38-f5f6ef3b0113@googlegroups.com> Why did C++ use this? I don't really like this. It doesn't sound right. I think it's because I have trouble saying the th sound without getting my mouth full of spit. Thankfully you don't often need to use this in C++ like you do with self in Python. From harrismh777 at gmail.com Wed Mar 5 21:07:10 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Wed, 5 Mar 2014 18:07:10 -0800 (PST) Subject: How security holes happen In-Reply-To: References: <87d2i1mvg7.fsf@elektro.pacujo.net> <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> <5adebc12-aa37-4139-82d8-563f46a27dc0@googlegroups.com> Message-ID: <76ee4081-4494-4a53-a05e-3da8fdcb90d1@googlegroups.com> On Wednesday, March 5, 2014 7:40:05 PM UTC-6, MRAB wrote: > > The 6502 came from MOS Technology. Motorola made the 6800. Well, not exactly. The MOS 6502 is to the Motorola 6800 what the Zilog Z80 was to the Intel 8080. The same engineers who designed the 6800 moved out and then designed the 6502; actually ended up in a law suit of sorts--- but I don't remember the details. Anyway, the 6502 was bought outright by Commodore, and the rest is history with the VIC20. The engineers at Intel did the same thing... moved out and started Zilog (which still exists today) and began their work on the Z80. By the by, the Z80 is still embedded in many applications today. Although, its not on a 40 pin dip any longer; its a small square about the size of a postage stamp. That is what powers the TI 84+ and the TI 83+ graphing programable calculators. I do some machine coding on the TI 84+ because it can be done on-the-device! The 68000 is the motorola chip that powers the TI89 graphing programable calculator ( my favorite ). Its not so easy to program it with machine code, because the kernel binaries are not well documented (TI hides them) and the user community hasn't probed it enough to know how does it really work. > 5K? Luxury! I started with the Science of Cambridge Mk14. Including the > RAM on the I/O chip, it had 640 bytes. Oh, I know. I thought 5k was a tremendous about of memory at the time, but we soon built and expanded for the slot, added 16k of memory (hand wire-wrapped thank you) and then plugged the VicMon (actually HES MON) into that. Do you remember the IAS (Maniac) at the Institute for Advanced Study (Johnny von Neumann's baby) ? It only had 5k of memory too! They had to use punched cards or punched tape for intermediate results when they were doing their runs calculating the wave function for the hydrogen bomb. At the time, Johnny said, " there will never be a need for for than five machines like this in the whole world!" marcus From wuwei23 at gmail.com Wed Mar 5 21:12:15 2014 From: wuwei23 at gmail.com (alex23) Date: Thu, 06 Mar 2014 12:12:15 +1000 Subject: Reference In-Reply-To: <87mwh45esp.fsf@elektro.pacujo.net> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> <87mwh45esp.fsf@elektro.pacujo.net> Message-ID: On 6/03/2014 10:52 AM, Marko Rauhamaa wrote: > I was just saying talking about id() as a memory address isn't all that > bad. It's a bit like rolling down your power windows or turning up the > volume, when there's nothing to roll or turn. There's no risk of getting > your program wrong. Unless you're talking about, say, the PyPy implementation, for which id is _not_ a memory address at all. Why insist on using "memory address" rather than "unique identifier", when the latter is fundamentally more correct? From roy at panix.com Wed Mar 5 21:31:51 2014 From: roy at panix.com (Roy Smith) Date: Wed, 05 Mar 2014 21:31:51 -0500 Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <53176225$0$29987$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Physics is the fundamental science, at least according to the physicists, > and Real Soon Now they'll have a Theory Of Everything, something small > enough to print on a tee-shirt, which will explain everything. At least > in principle. A mathematician, a chemist, and a physicist are arguing the nature of prime numbers. The chemist says, "All odd numbers are prime. Look, I can prove it. Three is prime. Five is prime. Seven is prime". The mathematician says, "That's nonsense. Nine is not prime". The physicist looks at him and says, "Hmmmm, you may be right, but eleven is prime, and thirteen is prime. It appears that within the limits of experimental error, all odd number are indeed prime!" From dihedral88888 at gmail.com Wed Mar 5 21:39:49 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Wed, 5 Mar 2014 18:39:49 -0800 (PST) Subject: How security holes happen In-Reply-To: References: Message-ID: On Wednesday, March 5, 2014 8:52:31 AM UTC+8, Andrew Cooper wrote: > On 03/03/2014 22:19, Cameron Simpson wrote: > > > On 03Mar2014 09:17, Neal Becker wrote: > > >> Charles R Harris Wrote in message: > > >>> > > >> > > >> Imo the lesson here is never write in low level c. Use modern > > >> languages with well designed exception handling. > > > > > > What, and rely on someone else's low level C? > > > > > > > Why is C the lowest denominator? > > > > Even with correctly written C and assembly, how can you be sure that > > your processor is executing the SYSRET instruction safely? > > (CVE-2012-0217 for anyone interested) > > > > ~Andrew It is not difficult to write C with mixed assembly codes for different CPUs. #ifdef ASM /* asm follows */ .... #ifdef CPUTYPES /* insert CPU ASMS for different CPUs carefully here */ From albert at spenarnc.xs4all.nl Wed Mar 5 21:51:54 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 06 Mar 2014 02:51:54 GMT Subject: Python programming References: Message-ID: <5317e2ca$0$9232$e4fe514c@dreader35.news.xs4all.nl> In article , Roy Smith wrote: >In article , > Grant Edwards wrote: > >> On 2014-02-13, Dennis Lee Bieber wrote: >> >> > An S-100 wire-wrap board. >> >> Yup, been there done that! > >Never did S-100, but I did do a custom Unibus card (wirewrap). > >You know you're working with a Real Computer (tm) when the +5V power >supply can deliver as much current as an arc welder. I've a 64 node Parsytec transputer system in the hall way with dual 5V 100A power supplies. Does that count? Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From steve+comp.lang.python at pearwood.info Wed Mar 5 22:01:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2014 03:01:15 GMT Subject: Reference References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <55d6a455-1856-4fd6-ac4b-c277ff7e2bd1@googlegroups.com> <53176aac$0$29985$c3e8da3$5496439d@news.astraweb.com> <87r46g75t9.fsf@elektro.pacujo.net> Message-ID: <5317e4fb$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Mar 2014 22:23:46 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> There is no metaphysical implication from Python's "is" operator. If >> the operator had precisely the same behaviour, but was called "same", >> as in: >> >> a same b >> => returns True if a and b are the same object => returns False if a >> and b are not the same object >> >> would you claim there was a metaphysical implication? > > I would. You are not defining anything because you are not explaining > what "same object" means. I mean exactly the same thing by "same object" as you do when you use it: > Set theory obeys the so-called extensionality principle: if two objects > are indistinguishable in every way, they are one and the same object. -- Steven D'Aprano http://import-that.dreamwidth.org/ From felixonmars at gmail.com Wed Mar 5 22:09:06 2014 From: felixonmars at gmail.com (Felix Yan) Date: Thu, 06 Mar 2014 11:09:06 +0800 Subject: Diagnose a segfault in ipython/readline Message-ID: <2114014.zHAFJyoHbS@felix-arch> Hi, I'm getting a reproducible crash in ipython, but not sure what upstream it should belong to. The crash happens with python 2.7.6/3.3.4, with readline 6.3. Steps to reproduce: - run ipython - input some random char sequence that you never inputed (like "ae3r0gka03k0k23"), don't press Enter - press "Up", followed by any key Backtrace pasted here: https://paste.xinu.at/cg7/ Downstream bug report on Arch Linux: https://bugs.archlinux.org/task/39144 Any help would be really appreciated! Regards, Felix Yan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: From steve+comp.lang.python at pearwood.info Wed Mar 5 22:06:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2014 03:06:40 GMT Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5317e640$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 05 Mar 2014 21:31:51 -0500, Roy Smith wrote: > In article <53176225$0$29987$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Physics is the fundamental science, at least according to the >> physicists, and Real Soon Now they'll have a Theory Of Everything, >> something small enough to print on a tee-shirt, which will explain >> everything. At least in principle. > > A mathematician, a chemist, and a physicist are arguing the nature of > prime numbers. The chemist says, "All odd numbers are prime. Look, I > can prove it. Three is prime. Five is prime. Seven is prime". The > mathematician says, "That's nonsense. Nine is not prime". The > physicist looks at him and says, "Hmmmm, you may be right, but eleven is > prime, and thirteen is prime. It appears that within the limits of > experimental error, all odd number are indeed prime!" They ask a computer programmer to adjudicate who is right, so he writes a program to print out all the primes: 1 is prime 1 is prime 1 is prime 1 is prime 1 is prime ... -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Wed Mar 5 22:14:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 6 Mar 2014 14:14:49 +1100 Subject: Working with the set of real numbers (was: Finding size of Variable) In-Reply-To: <5317e640$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> <5317e640$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 6, 2014 at 2:06 PM, Steven D'Aprano wrote: > They ask a computer programmer to adjudicate who is right, so he writes a > program to print out all the primes: > > 1 is prime > 1 is prime > 1 is prime > 1 is prime > 1 is prime And he claimed that he was correct, because he had - as is known to be true in reality - a countably infinite number of primes. ChrisA From invalid at invalid.invalid Wed Mar 5 22:34:10 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 6 Mar 2014 03:34:10 +0000 (UTC) Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-03-06, Roy Smith wrote: > In article <53176225$0$29987$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Physics is the fundamental science, at least according to the >> physicists, and Real Soon Now they'll have a Theory Of Everything, >> something small enough to print on a tee-shirt, which will explain >> everything. At least in principle. > > A mathematician, a chemist, and a physicist are arguing the nature of > prime numbers. The chemist says, "All odd numbers are prime. Look, I > can prove it. Three is prime. Five is prime. Seven is prime". The > mathematician says, "That's nonsense. Nine is not prime". The > physicist looks at him and says, "Hmmmm, you may be right, but eleven > is prime, and thirteen is prime. It appears that within the limits of > experimental error, all odd number are indeed prime!" Assuming spherical odd numbers in a vacuum on a frictionless surface, of course. -- Grant From roy at panix.com Wed Mar 5 23:05:02 2014 From: roy at panix.com (Roy Smith) Date: Wed, 05 Mar 2014 23:05:02 -0500 Subject: Working with the set of real numbers (was: Finding size of Variable) References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <531688b1$0$25064$e4fe514c@dreader37.news.xs4all.nl> <53169cd9$0$2923$c3e8da3$76491128@news.astraweb.com> <5316d7a0$0$2923$c3e8da3$76491128@news.astraweb.com> <53176225$0$29987$c3e8da3$5496439d@news.astraweb.com> <5317e640$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5317e640$0$29985$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Wed, 05 Mar 2014 21:31:51 -0500, Roy Smith wrote: > > > In article <53176225$0$29987$c3e8da3$5496439d at news.astraweb.com>, > > Steven D'Aprano wrote: > > > >> Physics is the fundamental science, at least according to the > >> physicists, and Real Soon Now they'll have a Theory Of Everything, > >> something small enough to print on a tee-shirt, which will explain > >> everything. At least in principle. > > > > A mathematician, a chemist, and a physicist are arguing the nature of > > prime numbers. The chemist says, "All odd numbers are prime. Look, I > > can prove it. Three is prime. Five is prime. Seven is prime". The > > mathematician says, "That's nonsense. Nine is not prime". The > > physicist looks at him and says, "Hmmmm, you may be right, but eleven is > > prime, and thirteen is prime. It appears that within the limits of > > experimental error, all odd number are indeed prime!" > > They ask a computer programmer to adjudicate who is right, so he writes a > program to print out all the primes: > > 1 is prime > 1 is prime > 1 is prime > 1 is prime > 1 is prime > ... So, a mathematician, a biologist, and a physicist are watching a house. The physicist says, "It appears to be empty". Sometime later, a man and a woman go into the house. Shortly after that, the man and the woman come back out, with a child. The biologist says, "They must have reproduced". The mathematician says, "If one more person goes into the house, it'll be empty again". From dihedral88888 at gmail.com Wed Mar 5 23:05:28 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Wed, 5 Mar 2014 20:05:28 -0800 (PST) Subject: Python programming In-Reply-To: References: Message-ID: On Thursday, February 13, 2014 11:30:27 PM UTC+8, Neil Cerutti wrote: > On 2014-02-12, Tim Delaney wrote: > > > OK - it's degenerated into one of these threads - I'm going to > > > participate. > > > > Me, too! > > > > I wrote lots of programs, strictly for fun, on every personal > > computer I got my hands on. Toward the end of the 80's personal > > computer's stopped coming equipped with programming environments, > > and I stopped programming. > > > > I eventually learned some computing theory in college where they > > taught C and the rudiments of C++. > > > > Thanks to the open-source movement we've returned to the days > > when anybody can program for zero cash. You can program well > > enough to amuse yourself with very little effort indeed. > > > > To get from there to being able to write programs to do useful > > things for yourself is a lot harder, but this is the niche that > > Python fills excellent well. If this is what you want to do, > > Python is a good way to go. > > > > That's still just the beginning, but it's a pretty good place. > > > > -- > > Neil Cerutti I wrote programs for viewing gif, pcx, bmp, and jpg images in 1991 to 1992. Also I was planning to write an Lotus123 clone at the time, but I was too lazy to chunk out that project in 1993. From nad at acm.org Wed Mar 5 23:15:31 2014 From: nad at acm.org (Ned Deily) Date: Wed, 05 Mar 2014 20:15:31 -0800 Subject: Diagnose a segfault in ipython/readline References: <2114014.zHAFJyoHbS@felix-arch> Message-ID: In article <2114014.zHAFJyoHbS at felix-arch>, Felix Yan wrote: > I'm getting a reproducible crash in ipython, but not sure what upstream it > should belong to. > > The crash happens with python 2.7.6/3.3.4, with readline 6.3. > > Steps to reproduce: > > - run ipython > - input some random char sequence that you never inputed (like > "ae3r0gka03k0k23"), don't press Enter > - press "Up", followed by any key > > Backtrace pasted here: https://paste.xinu.at/cg7/ > Downstream bug report on Arch Linux: https://bugs.archlinux.org/task/39144 > > Any help would be really appreciated! AFAIK, the only recent Python issue related to GNU readline was Issue20374 but it seems you've already eliminated that. The current assumption is that Python 2.7.6+, 3.3.5, and 3.4.0 have no problems with readline 6.3. If you end up believing that there is a Python problem with it, please open an issue on the Python bug tracker. Thanks! http://bugs.python.org -- Ned Deily, nad at acm.org From offroad.adventures.engr at gmail.com Wed Mar 5 23:19:56 2014 From: offroad.adventures.engr at gmail.com (Beowulf) Date: Wed, 5 Mar 2014 20:19:56 -0800 (PST) Subject: Python programming In-Reply-To: References: Message-ID: <98df529b-afe3-4f96-92ff-ff6e936d3dda@googlegroups.com> Once you master one language it is easy to understand other. I mastered C in my younger years, writing signal handlers and thread on Solaris and AIX. It it not the syntax, that comes easy, it is building the correct algorithm that matters. The best way to learn is make some thing useful that you need. I would suggest project with Raspberry Pi to learn python. On Tuesday, February 11, 2014 4:21:29 PM UTC-8, ngangsia akumbo wrote: > Please i have a silly question to ask. > > > > How long did it take you to learn how to write programs? > > > > What is the best way i can master thinker? > > I know the syntax but using it to write a program is a problem From dan at tombstonezero.net Wed Mar 5 23:43:35 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 6 Mar 2014 04:43:35 +0000 (UTC) Subject: Python programming References: <98df529b-afe3-4f96-92ff-ff6e936d3dda@googlegroups.com> Message-ID: On Wed, 05 Mar 2014 20:19:56 -0800, Beowulf wrote: > Once you master one language it is easy to understand other ... Once you master one language, the next one is hard. After that, they get easier. From roy at panix.com Wed Mar 5 23:51:28 2014 From: roy at panix.com (Roy Smith) Date: Wed, 05 Mar 2014 23:51:28 -0500 Subject: Python programming References: <98df529b-afe3-4f96-92ff-ff6e936d3dda@googlegroups.com> Message-ID: In article , Dan Sommers wrote: > On Wed, 05 Mar 2014 20:19:56 -0800, Beowulf wrote: > > > Once you master one language it is easy to understand other ... > > Once you master one language, the next one is hard. After that, they > get easier. And then you get to PHP. From felixonmars at gmail.com Thu Mar 6 01:11:10 2014 From: felixonmars at gmail.com (Felix Yan) Date: Thu, 06 Mar 2014 14:11:10 +0800 Subject: Diagnose a segfault in ipython/readline In-Reply-To: References: <2114014.zHAFJyoHbS@felix-arch> Message-ID: <1779169.vC7H4N7YzS@felix-arch> On Wednesday, March 05, 2014 20:15:31 Ned Deily wrote: > The current > assumption is that Python 2.7.6+, 3.3.5, and 3.4.0 have no problems with > readline 6.3. Thank you. I just gave a try to 3.4.0b2 with readline 6.3, and still get the same segfault. Not sure the version is new enough though. Also we reported the problem on readline mailing list first, so if they end up thinking there's something that python need to fix, I'll open a bug on the Python bug tracker. Thanks again! Regards, Felix Yan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: From steve at pearwood.info Thu Mar 6 01:17:05 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 06 Mar 2014 06:17:05 GMT Subject: Python programming References: <98df529b-afe3-4f96-92ff-ff6e936d3dda@googlegroups.com> Message-ID: <531812e0$0$2923$c3e8da3$76491128@news.astraweb.com> On Wed, 05 Mar 2014 20:19:56 -0800, Beowulf wrote: > Once you master one language it is easy to understand other. Depends on the languages. Learning Forth doesn't make it easier to learn Perl. Learning Pascal doesn't make Smalltalk easier. -- Steven From shulamitmi3 at gmail.com Thu Mar 6 01:53:46 2014 From: shulamitmi3 at gmail.com (=?UTF-8?B?16nXldec157XmdeqINee15nXqNec?=) Date: Wed, 5 Mar 2014 22:53:46 -0800 (PST) Subject: NameError: name 'pyver' is not defined Message-ID: Hello, We have python 2.6 & 3.2 installed on Sun solaris. When running py utility, we get the below error: "NameError: global name 'execfile' is not defined" > p4convert-cvs.py EXCEPTION: [Errno 17] File exists: './LOGS' Traceback (most recent call last): File "p4convert-cvs.py", line 134, in cvstop4lib.readconfig(configfile=args.config) File "/bzqchome/bzq/ccbzq/mb_ccbzq/Perforce/p4convert/cvstop4lib.py", line 61, in readconfig execfile(configfile,globals()) # read in the config file - must be valid Python, evaluated in the context of this file NameError: global name 'execfile' is not defined How to solve this problem? Thank you! From steve at pearwood.info Thu Mar 6 03:14:45 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 06 Mar 2014 08:14:45 GMT Subject: NameError: name 'pyver' is not defined References: Message-ID: <53182e74$0$2923$c3e8da3$76491128@news.astraweb.com> On Wed, 05 Mar 2014 22:53:46 -0800, ?????? ???? wrote: > Hello, > > We have python 2.6 & 3.2 installed on Sun solaris. When running py > utility, we get the below error: > > "NameError: global name 'execfile' is not defined" Sounds like you are accidentally running a script intended for Python2.6 under Python3.2 instead. execfile is removed from 3.2, so you need to either edit the script to update it for 3.2, or you need to make sure you are running it under 2.6. Do you need help with that? -- Steven From nad at acm.org Thu Mar 6 03:26:34 2014 From: nad at acm.org (Ned Deily) Date: Thu, 06 Mar 2014 00:26:34 -0800 Subject: NameError: name 'pyver' is not defined References: Message-ID: In article , ?AIOE??OE?I wrote: > We have python 2.6 & 3.2 installed on Sun solaris. > When running py utility, we get the below error: > > "NameError: global name 'execfile' is not defined" > > > > p4convert-cvs.py > EXCEPTION: [Errno 17] File exists: './LOGS' > Traceback (most recent call last): > File "p4convert-cvs.py", line 134, in > cvstop4lib.readconfig(configfile=args.config) > File "/bzqchome/bzq/ccbzq/mb_ccbzq/Perforce/p4convert/cvstop4lib.py", line > 61, in readconfig > execfile(configfile,globals()) # read in the config file - must be valid > Python, evaluated in the context of this file > NameError: global name 'execfile' is not defined execfile() no long exists in Python 3 so chances are you are trying to run a Python 3 program with Python 2. Try running the script explicitly under Python 2: python2.6 p4convert-cvs.py You may have inadvertently done a "make install" with Python 3.2 that has created a link from "python" to "python3.2". Later versions of Python 3 are a little more careful about reserving "python" for Python 2 and "python3" for Python 3, although some distributions (notably Arch Linux) do it differently. -- Ned Deily, nad at acm.org From nad at acm.org Thu Mar 6 03:30:40 2014 From: nad at acm.org (Ned Deily) Date: Thu, 06 Mar 2014 00:30:40 -0800 Subject: NameError: name 'pyver' is not defined References: Message-ID: In article , Ned Deily wrote: > execfile() no long exists in Python 3 so chances are you are trying to > run a Python 3 program with Python 2. Try running the script explicitly > under Python 2: Er, "trying to run a Python 2 program with Python 3", of course. -- Ned Deily, nad at acm.org From shulamitmi3 at gmail.com Thu Mar 6 03:36:56 2014 From: shulamitmi3 at gmail.com (=?UTF-8?B?16nXldec157XmdeqINee15nXqNec?=) Date: Thu, 6 Mar 2014 00:36:56 -0800 (PST) Subject: NameError: name 'pyver' is not defined In-Reply-To: References: Message-ID: <61dc1068-866f-4f9c-9765-1ba4a0341580@googlegroups.com> ?????? ??? ?????, 6 ???? 2014 10:26:34 UTC+2, ??? Ned Deily: > In article , ?AIOE??OE?I wrote: > We have python 2.6 & 3.2 installed on Sun solaris. > When running py utility, we get the below error: > > "NameError: global name 'execfile' is not defined" > > > > p4convert-cvs.py > EXCEPTION: [Errno 17] File exists: './LOGS' > Traceback (most recent call last): > File "p4convert-cvs.py", line 134, in > cvstop4lib.readconfig(configfile=args.config) > File "/bzqchome/bzq/ccbzq/mb_ccbzq/Perforce/p4convert/cvstop4lib.py", line > 61, in readconfig > execfile(configfile,globals()) # read in the config file - must be valid > Python, evaluated in the context of this file > NameError: global name 'execfile' is not defined execfile() no long exists in Python 3 so chances are you are trying to run a Python 3 program with Python 2. Try running the script explicitly under Python 2: python2.6 p4convert-cvs.py You may have inadvertently done a "make install" with Python 3.2 that has created a link from "python" to "python3.2". Later versions of Python 3 are a little more careful about reserving "python" for Python 2 and "python3" for Python 3, although some distributions (notably Arch Linux) do it differently. -- Ned Deily, nad at acm.org thanks for your help! I tried first to run the script under 2.6 version, but than the "argparse" was missing. I couldn't find python 2.7 for unix download. From shulamitmi3 at gmail.com Thu Mar 6 03:40:57 2014 From: shulamitmi3 at gmail.com (=?UTF-8?B?16nXldec157XmdeqINee15nXqNec?=) Date: Thu, 6 Mar 2014 00:40:57 -0800 (PST) Subject: NameError: name 'pyver' is not defined In-Reply-To: References: Message-ID: I tried first to run the script under 2.6 version, but than the "argparse" was missing. I couldn't find python 2.7 for unix download From pavan.rikhi at gmail.com Thu Mar 6 03:53:40 2014 From: pavan.rikhi at gmail.com (Pavan Rikhi) Date: Thu, 6 Mar 2014 03:53:40 -0500 Subject: NameError: name 'pyver' is not defined In-Reply-To: References: Message-ID: <20140306085340.GA1083@Lucy.acorn> On Wed, Mar 05, 2014 at 10:53:46PM -0800, ?????? ???? wrote: > execfile(configfile,globals()) You could replace the above line in cvstop4lib.py with the following: exec(open(configfile).read(), globals()) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 966 bytes Desc: GnuPG Digital Signature URL: From c.candide at laposte.net Thu Mar 6 06:34:49 2014 From: c.candide at laposte.net (candide) Date: Thu, 6 Mar 2014 03:34:49 -0800 (PST) Subject: Ternary operator associativity Message-ID: According to the official documentation, the ternary operator has left-to-right associativity : ------------------- Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right -- see section Comparisons -- and exponentiation, which groups from right to left). ------------------- Nevertheless, the ternary operator grouping seems to be from right to left, compare : >>> p = 0 if 1 else 0 if 0 else 1 >>> p 0 >>> left_to_right = (0 if 1 else 0) if 0 else 1 >>> right_to_left = 0 if 1 else (0 if 0 else 1) >>> p == left_to_right False >>> p == right_to_left True >>> From oscar.j.benjamin at gmail.com Thu Mar 6 07:27:16 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 6 Mar 2014 12:27:16 +0000 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On 5 March 2014 12:57, Dave Angel wrote: > Oscar Benjamin Wrote in message: >> On 4 March 2014 23:20, Dave Angel wrote: >>> >>> On the assumption that division by 2 is very fast, and that a >>> general multiply isn't too bad, you could improve on Newton by >>> observing that the slope is 2. >>> >>> err = n - guess * guess >>> guess += err/2 >> >> I gues you mean like this: >> >> def sqrt(n): >> err = guess = 1 >> while err > 1e-10: >> err = n - guess * guess >> guess += err/2 >> return guess >> >> This requires log2(10)*N iterations to get N digits. > > No idea how you came up with that, but I see an error in my > stated algorithm, which does surely penalize it. The slope isn't > 2, but 2x. So the line should have been > guess += err/(2*guess) Ah, now I understand. This is the same algorithm that Chris posted which in turn is the same as the one that I had previously posted: all three are just using Newton's method. Newton's method uses the slope argument to find a root of f(x) i.e. an x0 such that f(x0) = 0. We start with a guess x[n]. We then find the value of the function f(x[n]) and slope fp(x[n]) and extrapolating to the point where f(x) hits the x-axis we find an improved estimate with x[n+1] = x[n] - f(x[n]) / fp(x[n]) In our case f(x) = x**2 - y and so fp(x) = 2*x which gives x[n+1] = x[n] - (x[n]**2 - y) / (2*x[n]) and after rearranging we can express this as x[n+1] = (x[n] + y/x[n]) / 2. So my loop while x ** 2 - y > x * eps: x = (x + y/x) / 2 and Chris' loop: while abs(guess1-guess2) > epsilon: guess1 = n/guess2 guess2 = (guess1 + guess2)/2 and now your loop while err > 1e-10: err = n - guess * guess guess += err/(2 * guess) are all performing the same basic algorithm. The only significant difference is that mine tests for a relative error condition where as the other two test for absolute error. This means that it will still converge to an answer with the correct precision even when the root is large e.g. sqrt(1e100). The other two are susceptible to infinite loops in this case. > Now if you stop the loop after 3 iterations (or use some other > approach to get a low-precision estimate, then you can calculate > scale = 1/(2*estimate) > > and then for remaining iterations, > guess += err *scale Fair enough. That's a reasonable suggestion for improvement. This is often known as the "modified Newton's method". For lack of a better reference see here: http://math.stackexchange.com/questions/645088/modified-newtons-method Using an approximate slope to avoid division can be a significant optimisation. This is especially true when using the multidimensional generalisation of Newton's method since in this case the division is replaced with solving a system of linear equations (vastly more expensive). However as noted in that stackexchange answer the use of an approximate slope prevents quadratic convergence so in the asymptotic case where we want large numbers of digits it can be much slower. Actually it's worse than that since we are guaranteed to converge to an incorrect answer. The update step x = (x + y/x) / 2 will converge when x^2 = y but we replace it with x = (x + y/x0)/2 where x0 is near to the true root. This will converge when x == (x + y/x0)/2 i.e. when x = y/x0 which is not the correct answer (and can be computed without a loop in any case). It's possible to fix that by alternating between steps where we improve our estimate of the slope and steps where we use that estimate for refinement but I don't think that the advantage of not using division counts against the loss of quadratic convergence once we get to more than 10s of digits. You can compare them yourself with this code: def sqrt1(y, prec=1000): '''Solve x**2 = y''' assert y > 0 eps = D(10) ** -(prec + 5) x = D(y) with localcontext() as ctx: ctx.prec = prec + 10 while abs(x ** 2 - y) > x * eps: x = (x + y/x) / 2 return x def sqrt2(y, prec=1000): '''Solve x**2 = y''' assert y > 0 eps = D(10) ** -(prec + 5) x = D(y) with localcontext() as ctx: ctx.prec = prec + 10 for n in range(7): x = (x + y/x) / 2 x0r = 1 / x while abs(x ** 2 - y) > x * eps: err = x**2 - y err2 = x - x0r * y x = (x + x0r * y) / 2 return x sqrt2(2) goes into an infinite loop at an error level of ~1e-100 (the exact point where this happens depends on how many warmup iterations it uses). [snip] >> >> This method works out much slower than Newton with division at 10000 >> digits: 40s (based on a single trial) vs 80ms (timeit result). > > Well considering you did not special-case the divide by 2, I'm not > surprised it's slower. Multiplying by D('0.5') instead of dividing by 2 makes no measurable difference to the timings. I don't know whether that's because it's already special-cased by Decimal or just that the performance costs don't match up in the same way for the multiprecision algorithms (when the divisor is a single digit number). Oscar From rustompmody at gmail.com Thu Mar 6 07:43:00 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 6 Mar 2014 04:43:00 -0800 (PST) Subject: Program Python In-Reply-To: References: Message-ID: <9eeb3673-f629-4b43-9b6b-d8510d88333e@googlegroups.com> On Thursday, March 6, 2014 3:11:10 AM UTC+5:30, Luciano Trespidi wrote: > I'm very grateful if anyone can helpme to find a good program to develop in python lenguage. > Thanks > Inviato da: > Ernesto Luciano Trespidi > Email: keplero1... > Tel. 32... Hi and welcome Just a small warning in addition to what others have said Information such as your email and phone posted above will be publicly available on the net. You perhaps dont want that?? From python.list at tim.thechases.com Thu Mar 6 08:09:40 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 6 Mar 2014 07:09:40 -0600 Subject: Python programming In-Reply-To: <531812e0$0$2923$c3e8da3$76491128@news.astraweb.com> References: <98df529b-afe3-4f96-92ff-ff6e936d3dda@googlegroups.com> <531812e0$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <20140306070940.4d719e9f@bigbox.christie.dr> On 2014-03-06 06:17, Steven D'Aprano wrote: > On Wed, 05 Mar 2014 20:19:56 -0800, Beowulf wrote: > > > Once you master one language it is easy to understand other. > > Depends on the languages. Learning Forth doesn't make it easier to > learn Perl. Learning Pascal doesn't make Smalltalk easier. And despite having a couple dozen languages worth of (varying levels of) experience under my belt, Prolog still feels to me like programming by epiphany. -tkc From rosuav at gmail.com Thu Mar 6 08:16:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 00:16:24 +1100 Subject: Working with the set of real numbers In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 6, 2014 at 11:27 PM, Oscar Benjamin wrote: > So my loop > > while x ** 2 - y > x * eps: > x = (x + y/x) / 2 > > and Chris' loop: > > while abs(guess1-guess2) > epsilon: > guess1 = n/guess2 > guess2 = (guess1 + guess2)/2 > > and now your loop > > while err > 1e-10: > err = n - guess * guess > guess += err/(2 * guess) > > are all performing the same basic algorithm. The only significant > difference is that mine tests for a relative error condition where as > the other two test for absolute error. This means that it will still > converge to an answer with the correct precision even when the root is > large e.g. sqrt(1e100). The other two are susceptible to infinite > loops in this case. This is one place where I find the REXX 'numeric fuzz' setting to be a useful trick. The definition is that, whenever two numbers are compared for equality, the 'numeric digits' setting is effectively reduced by the fuzz for that comparison. So let's say we're calculating to a precision of 100 digits ('numeric digits 100'). You could then code the loop as "do until guess1=guess2", with a numeric fuzz of, say, 2. That'll give you 98 digits of accuracy, *regardless of scale*. It's like setting epsilon to "whatever would be 1e-98 if we were working with numbers between 0 and 1", more or less. A sliding epsilon. ChrisA From christoff.kok at ex-mente.co.za Thu Mar 6 08:19:52 2014 From: christoff.kok at ex-mente.co.za (Christoff Kok) Date: Thu, 6 Mar 2014 05:19:52 -0800 (PST) Subject: Struggling to create an extension wrapping a 3rd party dll In-Reply-To: <4f813ff8-d0c8-4370-b669-5484f3dcd467@googlegroups.com> References: <4f813ff8-d0c8-4370-b669-5484f3dcd467@googlegroups.com> Message-ID: <12944247-3222-4834-80c4-9ad6b4143ff9@googlegroups.com> On Wednesday, 5 March 2014 09:10:33 UTC+2, Christoff Kok wrote: > Hi, > > > > We are trying to wrap a 3rd party dll (written in C) to access it through python. > > The dll has a .lib .c and a .h file with it. We are accessing the dll through the .c file. > > > > Outisde of the extension (running as a console application), the code works without an issue. without the 3rd party dll, the python extension works without an issue. The issue comes in when trying combine the third party dll with the python extension. > > > > Here is the distutil installation script > > > > ################ Setup.py ################################ > > > > from distutils.core import setup, Extension > > > > chemAppPython_mod = Extension('chemAppPython', sources = ['chemAppPython.c', 'cacint.c'], libraries=['ca_vc_opt_e'], depends = ['cacint.h']) > > > > setup(name = "chemAppPython", > > version = "1.0", > > description = "The ChemnApp Python module", > > ext_modules = [chemAppPython_mod], > > data_files = [('',['ca_vc_e.dll'])] > > ) > > > > ########################################################## > > > > * ca_vc_opt_e.lib and ca_vc_e.dll is the library containing the third party methods we want to access. > > > > * cacint.h and cacint.c is the files acting as an interface to the ca_vc_opt_e.lib and ca_vc_e.dll. > > * chemAppPython.c is file containing the code wrapping the calls to the cacint.c (and in effect, the third party dll) > > > > The errors we are receiving are: > > C:\Python33\source\Python-3.3.4\ChemAppPython>setup.py install > > running install > > running build > > running build_ext > > building 'chemAppPython' extension > > creating build > > creating build\temp.win-amd64-3.3 > > creating build\temp.win-amd64-3.3\Release > > C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python33\include -IC:\Python33\include /TcchemAppPython.c /Fobuild\temp.win-amd64-3.3\Release\chemAppPython.obj > > chemAppPython.c > > C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python33\include -IC:\Python33\include /Tccacint.c /Fobuild\temp.win-amd64-3.3\Release\cacint.obj > > cacint.c > > cacint.c(357) : warning C4267: 'function' : conversion from 'size_t' to 'long', possible loss of data > > cacint.c(390) : warning C4267: 'function' : conversion from 'size_t' to 'long', possible loss of data > > . > > . > > . (some more of the same warning message for different functions.) > > . > > cacint.c(619) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. > > . > > . > > . > > . (some more of the same warning message at different positions in code.) > > . > > creating build\lib.win-amd64-3.3 > > C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python33\libs /LIBPATH:C:\Python33\PCbuild\amd64 ca_vc_opt_e.lib /EXPORT:PyInit_chemAppPython build\temp.win-amd64-3.3\Release\chemAppPython.obj build\temp.win-amd64-3.3\Rele > > chemAppPython.obj : warning LNK4197: export 'PyInit_chemAppPython' specified multiple times; using first specification > > Creating library build\temp.win-amd64-3.3\Release\chemAppPython.lib and object build\temp.win-amd64-3.3\Release\chemAppPython.exp > > cacint.obj : error LNK2019: unresolved external symbol TQINI referenced in function tqini > > cacint.obj : error LNK2019: unresolved external symbol TQOPEN referenced in function tqopen > > . > > . > > . (a lot more of them, for different methods. Again, it builds and runs fine in the console app host application.) > > . > > build\lib.win-amd64-3.3\chemAppPython.pyd : fatal error LNK1120: 74 unresolved externals > > error: command '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe"' failed with exit status 1120 > > > > > > Help would really be appreciated. Ok, I have progress. I can run the extension manually, without deploying with distutil using a the python source code build and running it from the extensions Debug/Release folder. We need to deploy the extension though so getting it right to work with distutil is very important. Still getting the exact same issue as mentioned in my first post. It seems that the 'ca_vc_opt_e.lib' library is not linked in the module. From invalid at invalid.invalid Thu Mar 6 09:49:09 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 6 Mar 2014 14:49:09 +0000 (UTC) Subject: Python programming References: <98df529b-afe3-4f96-92ff-ff6e936d3dda@googlegroups.com> Message-ID: On 2014-03-06, Roy Smith wrote: > In article , > Dan Sommers wrote: > >> On Wed, 05 Mar 2014 20:19:56 -0800, Beowulf wrote: >> >> > Once you master one language it is easy to understand other ... >> >> Once you master one language, the next one is hard. After that, they >> get easier. > > And then you get to PHP. Yep, it's a real mess. Both the language and the room you're in when your head finally explodes. -- Grant Edwards grant.b.edwards Yow! Th' MIND is the Pizza at Palace of th' SOUL gmail.com From invalid at invalid.invalid Thu Mar 6 09:52:26 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 6 Mar 2014 14:52:26 +0000 (UTC) Subject: Python programming References: <98df529b-afe3-4f96-92ff-ff6e936d3dda@googlegroups.com> <531812e0$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On 2014-03-06, Tim Chase wrote: > On 2014-03-06 06:17, Steven D'Aprano wrote: >> On Wed, 05 Mar 2014 20:19:56 -0800, Beowulf wrote: >> >> > Once you master one language it is easy to understand other. >> >> Depends on the languages. Learning Forth doesn't make it easier to >> learn Perl. Learning Pascal doesn't make Smalltalk easier. > > And despite having a couple dozen languages worth of (varying levels > of) experience under my belt, Prolog still feels to me like > programming by epiphany. Back when I was in school, Lisp and Prolog were the hardest to grok. I eventually "got" Lisp (well, I actually "got" Scheme, and I think I could now "get" Lisp if I tried). Prolog is definitely the odd one of the dozen or two languages I've learned -- and I even wrote a small expert system in Prolog as a project for a software engineering class. -- Grant Edwards grant.b.edwards Yow! I think my career at is ruined! gmail.com From fabiofz at gmail.com Thu Mar 6 10:42:02 2014 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 6 Mar 2014 12:42:02 -0300 Subject: Diagnose a segfault in ipython/readline In-Reply-To: <1779169.vC7H4N7YzS@felix-arch> References: <2114014.zHAFJyoHbS@felix-arch> <1779169.vC7H4N7YzS@felix-arch> Message-ID: On Thu, Mar 6, 2014 at 3:11 AM, Felix Yan wrote: > On Wednesday, March 05, 2014 20:15:31 Ned Deily wrote: > > The current > > assumption is that Python 2.7.6+, 3.3.5, and 3.4.0 have no problems with > > readline 6.3. > > Thank you. > > I just gave a try to 3.4.0b2 with readline 6.3, and still get the same > segfault. Not sure the version is new enough though. > > Also we reported the problem on readline mailing list first, so if they > end up > thinking there's something that python need to fix, I'll open a bug on the > Python bug tracker. > > Thanks again! > > Just a note here (which may or may not work for your case), but you could try using the faulthandler module to see if it can give you a stack trace you can work with... Cheers, Fabio -------------- next part -------------- An HTML attachment was scrubbed... URL: From bv8bv8bv8 at gmail.com Thu Mar 6 11:58:26 2014 From: bv8bv8bv8 at gmail.com (BV BV) Date: Thu, 6 Mar 2014 08:58:26 -0800 (PST) Subject: Who Invented the Trinity? Message-ID: Who Invented the Trinity? 1-How the concept of the Trinity was introduced into the Christian doctrine. 2-How the injected doctrine of the trinity remained part of the beliefs of the Christians and how Islam defines God. What is the source of the Christian concept of the Trinity? The three monotheistic religions - Judaism, Christianity, and Islam - all purport to share one fundamental concept: belief in God as the Supreme Being, the Creator and Sustainer of the Universe. Known as "tawhid" in Islam, this concept of the Oneness of God was stressed by Moses in a Biblical passage known as the "Shema", or the Jewish creed of faith: "Hear, O Israel: The Lord our God is one Lord." (Deuteronomy 6:4) It was repeated word-for-word approximately 1500 years later by Jesus, when he said: "...The first of all the commandments is, Hear, O Israel; the Lord our God is one Lord." (Mark 12:29) Muhammad came along approximately 600 years later, bringing the same message again: "And your God is One God: there is no God but He..." (Quran 2:163) Christianity has digressed from the concept of the Oneness of God, however, into a vague and mysterious doctrine that was formulated during the fourth century. This doctrine, which continues to be a source of controversy both within and outside the Christian religion, is known as the Doctrine of the Trinity. Simply put, the Christian doctrine of the Trinity states that God is the union of three divine persons - the Father, the Son and the Holy Spirit - in one divine being. If that concept, put in basic terms, sounds confusing, the flowery language in the actual text of the doctrine lends even more mystery to the matter: "...we worship one God in Trinity, and Trinity in Unity... for there is one Person of the Father, another of the Son, another of the Holy Ghost is all one... they are not three gods, but one God... the whole three persons are co-eternal and co-equal... he therefore that will be saved must thus think of the Trinity..." (excerpts from the Athanasian Creed) Let's put this together in a different form: one person, God the Father, plus one person, God the Son, plus one person, God the Holy Ghost, equals one person, God the What? Is this English or is this gibberish? It is said that Athanasius, the bishop who formulated this doctrine, confessed that the more he wrote on the matter, the less capable he was of clearly expressing his thoughts regarding it. How did such a confusing doctrine get its start? Trinity in the Bible References in the Bible to a Trinity of divine beings are vague, at best. In Matthew 28:19, we find Jesus telling his disciples to go out and preach to all nations. While this "Great Commission" does make mention of the three persons who later become components of the Trinity, the phrase "...baptizing them in the name of the Father, and of the Son, and of the Holy Ghost" is quite clearly an addition to Biblical text - that is, not the actual words of Jesus - as can be seen by two factors: 1) baptism in the early Church, as discussed by Paul in his letters, was done only in the name of Jesus; and 2) the "Great Commission" was found in the first gospel written, that of Mark, bears no mention of Father, Son and/or Holy Ghost - see Mark 16:15. The only other reference in the Bible to a Trinity can be found in the Epistle of 1 John 5:7. Biblical scholars of today, however, have admitted that the phrase: "...there are three that bear record in heaven, the Father, the Word, and the Holy Ghost: and these three are one" ...is definitely a "later addition" to Biblical text, and it is not found in any of today's versions of the Bible. It can, therefore, be seen that the concept of a Trinity of divine beings was not an idea put forth by Jesus or any other prophet of God. This doctrine, now subscribed to by Christians all over the world, is entirely man-made in origin. The Doctrine Takes Shape While Paul of Tarsus, the man who could rightfully be considered the true founder of Christianity, did formulate many of its doctrines, that of the Trinity was not among them. He did, however, lay the groundwork for such when he put forth the idea of Jesus being a "divine Son". After all, a Son does need a Father, and what about a vehicle for God's revelations to man? In essence, Paul named the principal players, but it was the later Church people who put the matter together. Tertullian, a lawyer and presbyter of the third-century Church in Carthage, was the first to use the word "Trinity" when he put forth the theory that the Son and the Spirit participate in the being of God, but all are of one being of substance with the Father. A Formal Doctrine is Drawn Up When controversy over the matter of the Trinity blew up in 318 between two church men from Alexandria - Arius, the deacon, and Alexander, his bishop - Emperor Constantine stepped into the fray. Although Christian dogma was a complete mystery to him, he did realize that a unified church was necessary for a strong kingdom. When negotiation failed to settle the dispute, Constantine called for the first ecumenical council in Church history in order to settle the matter once and for all. Six weeks after the 300 bishops first gathered at Nicea in 325, the doctrine of the Trinity was hammered out. The God of the Christians was now seen as having three essences, or natures, in the form of the Father, the Son, and the Holy Spirit. The Church Puts its Foot Down The matter was far from settled, however, despite high hopes for such on the part of Constantine. Arius and the new bishop of Alexandria, a man named Athanasius, began arguing over the matter even as the Nicene Creed was being signed; "Arianism" became a catch-word from that time onward for anyone who didn't hold to the doctrine of the Trinity. It wasn't until 451, at the Council of Chalcedon that, with the approval of the Pope, the Nicene/Constantinople Creed was set as authoritative. Debate on the matter was no longer tolerated; to speak out against the Trinity was now considered blasphemy, and such earned stiff sentences that ranged from mutilation to death. Christians now turned on Christians, maiming and slaughtering thousands because of a difference of opinion. Debate Continues Brutal punishments and even death did not stop the controversy over the doctrine of the Trinity, however, and the said controversy continues even today. The majority of Christians, when asked to explain this fundamental doctrine of their faith, can offer nothing more than "I believe it because I was told to do so." It is explained away as "mystery" - yet the Bible says in 1 Corinthians 14:33 that: "... God is not the author of confusion ..." The Unitarian denomination of Christianity has kept alive the teachings of Arius in saying that God is one; they do not believe in the Trinity. As a result, mainstream Christians abhor them, and the National Council of Churches has refused their admittance. In Unitarianism, the hope is kept alive that Christians will someday return to the preachings of Jesus: "... Thou shalt worship the Lord thy God, and Him only shalt thou serve." (Luke 4:8) Islam and the Matter of the Trinity While Christianity may have a problem defining the essence of God, such is not the case in Islam: "They do blaspheme who say: Allah is one of three in a Trinity, for there is no god except One God" (Quran 5:73) It is worth noting that the Arabic language Bible uses the name "Allah" as the name of God. Suzanne Haneef, in her book What Everyone Should Know About Islam and Muslims (Library of Islam, 1985), puts the matter quite succinctly when she says: "But God is not like a pie or an apple which can be divided into three thirds which form one whole; if God is three persons or possesses three parts, He is assuredly not the Single, Unique, Indivisible Being which God is and which Christianity professes to believe in." [1] Looking at it from another angle, the Trinity designates God as being three separate entities - the Father, the Son and the Holy Spirit. If God is the Father and also the Son, He would then be the Father of Himself because He is His own Son. This is not exactly logical. Christianity claims to be a monotheistic religion. Monotheism, however, has as its fundamental belief that God is One; the Christian doctrine of the Trinity - God being Three-in-One - is seen by Islam as a form of polytheism. Christians don't revere just One God, they revere three. This is a charge not taken lightly by Christians, however. They, in turn, accuse the Muslims of not even knowing what the Trinity is, pointing out that the Quran sets it up as Allah the Father, Jesus the Son, and Mary his mother. While veneration of Mary has been a figment of the Catholic Church since 431 when she was given the title "Mother of God" by the Council of Ephesus, a closer examination of the verses in the Quran most often cited by Christians in support of their accusation, shows that the designation of Mary by the Quran as a "member" of the Trinity, is simply not true. While the Quran does condemn both Trinitarianism (the Quran 4:171; 5:73) [2] and the worship of Jesus and his mother Mary (the Quran 5:116) [3], nowhere does it identify the actual three components of the Christian Trinity. The position of the Quran is that WHO or WHAT comprises this doctrine is not important; what is important is that the very notion of a Trinity is an affront against the concept of One God. In conclusion, we see that the doctrine of the Trinity is a concept conceived entirely by man; there is no sanction whatsoever from God to be found regarding the matter simply because the whole idea of a Trinity of divine beings has no place in monotheism. In the Quran, God's Final Revelation to mankind, we find His stand quite clearly stated in a number of eloquent passages: "... your God is One God: whoever expects to meet his Lord, let him work righteousness, and, in the worship of his Lord, admit no one as partner." (Quran 18:110) "... take not, with God, another object of worship, lest you should be thrown into Hell, blameworthy and rejected." (Quran 17:39) - because, as God tells us over and over again in a Message that is echoed throughout ALL His Revealed Scriptures: "... I am your Lord and Cherisher: therefore, serve Me (and no other) ..." (Quran 21:92) [1] What Everyone Should Know About Islam and Muslims (Library of Islam, 1985) (pp. 183-184) [2] "O People of the Scripture, do not commit excess in your religion or say about God except the truth. The Messiah, Jesus, the son of Mary, was but a Messenger of God and His word which He directed to Mary and a soul [created at a command] from Him. So believe in God and His messengers. And do not say, 'Three'; desist--it is better for you. Indeed, God is but one God. Exalted is He above having a son. To Him belongs whatever is in the heavens and whatever is on the earth. And sufficient is God as Disposer of affairs." (Quran 4:171) [3] "And [beware the Day] when God will say, 'O Jesus, Son of Mary, did you say to the people, 'Take me and my mother as deities besides God?' 'He will say, 'Exalted are You! It was not for me to say that to which I have no right. If I had said it, You would have known it. You know what is within myself, and I do not know what is within Yourself. Indeed, it is You who is Knower of the unseen.' (Quran 5:116) http://www.islamhouse.com/428121/en/en/articles/Who_Invented_the_Trinity? Thank you From breamoreboy at yahoo.co.uk Thu Mar 6 12:43:19 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 06 Mar 2014 17:43:19 +0000 Subject: Origin of 'self' In-Reply-To: <1634feec-9f23-4f46-bd38-f5f6ef3b0113@googlegroups.com> References: <531426b8$0$2923$c3e8da3$76491128@news.astraweb.com> <1634feec-9f23-4f46-bd38-f5f6ef3b0113@googlegroups.com> Message-ID: On 06/03/2014 01:56, Westley Mart?nez wrote: > Why did C++ use this? I don't really like this. It doesn't sound right. I think it's because I have trouble saying the th sound without getting my mouth full of spit. > > Thankfully you don't often need to use this in C++ like you do with self in Python. > You don't need to use self, you can call it anything you like, but you'll not be particularly popular if you do this. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From torriem at gmail.com Thu Mar 6 12:47:25 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 06 Mar 2014 10:47:25 -0700 Subject: Ternary operator associativity In-Reply-To: References: Message-ID: <5318B4AD.9010508@gmail.com> On 03/06/2014 04:34 AM, candide wrote: > According to the official documentation, the ternary operator has left-to-right associativity : > > ------------------- > Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right -- see section Comparisons -- and exponentiation, which groups from right to left). > ------------------- > > > Nevertheless, the ternary operator grouping seems to be from right to left, compare : I was reading a blog about PHP the other day and it mentioned PHP was the only language he knew of that had ternary operator precedence going left to right. All other languages use right to left. So I assume that Python also uses right to left and that the documentation is a bug. From marko at pacujo.net Thu Mar 6 12:46:15 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 06 Mar 2014 19:46:15 +0200 Subject: Origin of 'self' References: <531426b8$0$2923$c3e8da3$76491128@news.astraweb.com> <1634feec-9f23-4f46-bd38-f5f6ef3b0113@googlegroups.com> Message-ID: <87pplzqkyg.fsf@elektro.pacujo.net> Westley Mart?nez : > Thankfully you don't often need to use this in C++ like you do with > self in Python. Self pity is not attractive. Marko From breamoreboy at yahoo.co.uk Thu Mar 6 12:46:50 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 06 Mar 2014 17:46:50 +0000 Subject: Reference In-Reply-To: <5317c2d5$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> <87siqy7whs.fsf@elektro.pacujo.net> <53155c15$0$2923$c3e8da3$76491128@news.astraweb.com> <164d209c-ba5e-449f-bc25-c27ebfb1fc0f@googlegroups.com> <5316b0dc$0$2923$c3e8da3$76491128@news.astraweb.com> <53176cfe$0$29985$c3e8da3$5496439d@news.astraweb.com> <87mwh475bc.fsf@elektro.pacujo.net> <87bnxk73gb.fsf@elektro.pacujo.net> <5317c2d5$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/03/2014 00:35, Steven D'Aprano wrote: > On Thu, 06 Mar 2014 08:26:22 +1100, Chris Angelico wrote: > >> On Thu, Mar 6, 2014 at 8:14 AM, Marko Rauhamaa wrote: >>> When I talk about an object's memory address, I'm not referring to what >>> might be revealed by gdb, for example. That is, I'm not talking about >>> the process's virtual address space, nor am I talking about the >>> physical address on the address bus. I can simply define that the >>> object's memory address is whatever id() returns. >> >> Where's the complaints about circularity now? You're saying "But of >> course id() returns the address, as long as we define the address as >> 'whatever id() returns'.". Unimpeachably logical and utterly unhelpful. > > That last sentence is wrong. There is nothing logical about just making > up arbitrary definitions in this way. He could invent *any* definition, > each more ridiculous than the last: > > - it's the object's memory address; > > - it's the object's phone number; > > - it's the number of baby elephants killed by the object; > > - it's the number of intergalactic empires that are, even as we > speak, rushing to Earth to invade to gain possession of that > object; > > - it's the weight in metric tonnes of the electrons in the object; > > (Not *actual* electrons of course, just these arbitrary inventions > of Marko's definition.) > > - it's the length measured in seconds of the bitterness of the > object's kidney; > > > and of course: > > - the number of angels that can dance on the object. > You've missed the most obvious one, the number of words written on this mailing list about Python that are completely wrong. That number is far larger than the sum of all your definitions given above, where sum has the usual maths definition and not Marko's. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From tjreedy at udel.edu Thu Mar 6 13:52:46 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Mar 2014 13:52:46 -0500 Subject: Ternary operator associativity In-Reply-To: References: Message-ID: On 3/6/2014 6:34 AM, candide wrote: > According to the official documentation, the ternary operator has > left-to-right associativity : The proper terms is 'conditional expression', which goes back to "The C Programming Language" (K&R). There are many unary operators, many binary operators, and there could be other ternary operators. > ------------------- Operators in the same box group left to right > (except for comparisons, including tests, which all have the same > precedence and chain from left to right -- see section Comparisons -- > and exponentiation, which groups from right to left). > ------------------- > > Nevertheless, the ternary operator grouping seems to be from right to > left, compare : > >>>> p = 0 if 1 else 0 if 0 else 1 p > 0 >>>> left_to_right = (0 if 1 else 0) if 0 else 1 >>>> right_to_left = 0 if 1 else (0 if 0 else 1) >>>> p == left_to_right > False >>>> p == right_to_left > True This behavior is specified in the grammar as given in the C-E section. The doc is also inconsistent about evaluation order and precedence. I opened http://bugs.python.org/issue20859 . -- Terry Jan Reedy From python.list at tim.thechases.com Thu Mar 6 13:59:58 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 6 Mar 2014 12:59:58 -0600 Subject: Ternary operator associativity In-Reply-To: References: Message-ID: <20140306125958.31e096f8@bigbox.christie.dr> On 2014-03-06 03:34, candide wrote: > According to the official documentation, the ternary operator has > left-to-right associativity > > >>> left_to_right = (0 if 1 else 0) if 0 else 1 > >>> right_to_left = 0 if 1 else (0 if 0 else 1) I'd never want to rely on my own ability to remember the language spec, so I strongly advocate for making it explicit with parens regardless of what the language defines. And that's if I ever created such a mess in the first place. If you have more than one pair of conditional expressions in a single assignment, I'd suggest that it's a code-smell that could use refactoring for clarity/disambiguity. -tkc From tjreedy at udel.edu Thu Mar 6 15:15:34 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 06 Mar 2014 15:15:34 -0500 Subject: Ternary operator associativity In-Reply-To: <20140306125958.31e096f8@bigbox.christie.dr> References: <20140306125958.31e096f8@bigbox.christie.dr> Message-ID: On 3/6/2014 1:59 PM, Tim Chase wrote: > On 2014-03-06 03:34, candide wrote: >> According to the official documentation, the ternary operator has >> left-to-right associativity >> >>>>> left_to_right = (0 if 1 else 0) if 0 else 1 >>>>> right_to_left = 0 if 1 else (0 if 0 else 1) > > I'd never want to rely on my own ability to remember the language > spec, so I strongly advocate for making it explicit with parens > regardless of what the language defines. And that's if I ever created > such a mess in the first place. If you have more than one pair of > conditional expressions in a single assignment, I'd suggest that it's > a code-smell that could use refactoring for clarity/disambiguity. It is intended and part of the PEP discussion that one be able to write chained conditional expression in Python x = (a1 if c1 else a2 if c2 else a3 if c3 else a4) without extra ()s, similar to what one can write in C (if I remember correctly) x = c1 ? a1 : c2 ? a2 : c3 ? a3 : a4 both being abbreviations for chained if-elses if c1: x = a1 elif c2: x = a2 elif c3: x = a3 else: x = a4 In all three cases, the conditions are evaluated in 1,2,3 order, each before the corresponding expression. -- Terry Jan Reedy From teddybubu at gmail.com Thu Mar 6 15:22:30 2014 From: teddybubu at gmail.com (teddybubu at gmail.com) Date: Thu, 6 Mar 2014 12:22:30 -0800 (PST) Subject: beautiful soup get class info Message-ID: I am using beautifulsoup to get the title and date of the website. title is working fine but I am not able to pull the date. Here is the code in the url: October 22, 2011 In Python, I am using the following code: date1 = soup.span.text data=soup.find_all(date="value") Results in: [] March 5, 2014 What is the proper way to get this info? Thanks. From gordon at panix.com Thu Mar 6 15:58:12 2014 From: gordon at panix.com (John Gordon) Date: Thu, 6 Mar 2014 20:58:12 +0000 (UTC) Subject: beautiful soup get class info References: Message-ID: In teddybubu at gmail.com writes: > October 22, 2011 > date1 = soup.span.text > data=soup.find_all(date="value") Try this: soup.find_all(name="span", class="date") -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From teddybubu at gmail.com Thu Mar 6 16:38:39 2014 From: teddybubu at gmail.com (teddybubu at gmail.com) Date: Thu, 6 Mar 2014 13:38:39 -0800 (PST) Subject: beautiful soup get class info In-Reply-To: References: Message-ID: On Thursday, March 6, 2014 2:58:12 PM UTC-6, John Gordon wrote: > In teddy writes: > > > > > October 22, 2011 > > > > > date1 = soup.span.text > > > data=soup.find_all(date="value") > > > > Try this: > > > > soup.find_all(name="span", class="date") > > > > -- > > John Gordon Imagine what it must be like for a real medical doctor to > > watch 'House', or a real serial killer to watch 'Dexter'. I have python 2.7.2 and it does not like class in the code you provided. Now when I take out [ class="date"], this is returned: [March 5, 2014, March 5, 2014] This is the code I am using: "data = soup.find_all(name="span") print (data)" 1. it returns today's date instead of the actual date 2. returns it twice From larry.martell at gmail.com Thu Mar 6 16:56:42 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 6 Mar 2014 16:56:42 -0500 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Wed, Mar 5, 2014 at 5:27 PM, Larry Martell wrote: > I have a script that forks off other processes and attempts to manage > them. Here is a stripped down version of the script: > > self.sleepTime = 300 > self.procs = {} > self.startTimes = {} > self.cmd = ['python', '/usr/local/motor/motor/app/some_other_script.py'] > > while True: > try: > self.tools = Tool.objects.filter(ip__isnull=False) > except Exception, e: > print 'error from django call: ' + str(e) > sys.exit(1) > > for tool in self.tools: > name = tool.name > if name in self.procs: > if self.procs[name].poll() is None: > if > (datetime.datetime.now()-self.startTimes[name]) > > datetime.timedelta(hours=12): > # it's been running too long - kill it > print 'killing script for ' + name + " > it's been running too long" > self.procs[name].kill() > else: > continue > > if self.procs[name].returncode: > print 'scrikpt failed for ' + name + ', error > = ' + str(self.procs[name].returncode) > > print 'starting script.py for ' + name + ' at ' + > str(datetime.datetime.now()) > try: > self.procs[name] = subprocess.Popen(self.cmd) > self.startTimes[name] = datetime.datetime.now() > except Exception, e: > print 'error from Popen: ' + str(e) > sys.exit(1) > else: > print 'starting script.py for ' + name + ' at ' + > str(datetime.datetime.now()) > try: > self.procs[name] = subprocess.Popen(self.cmd) > self.startTimes[name] = datetime.datetime.now() > except Exception, e: > print 'error from Popen: ' + str(e) > sys.exit(1) > > time.sleep(self.sleepTime) > > > The script does what it's intended to do, however after about 2 hours > it has used up all the memory available and the machine hangs. Can > anyone see something that I am doing here that would be using memory > like this? Perhaps some immutable object needs to be repeatedly > recreated? I figured out what is causing this. Each pass through the loop it does: self.tools = Tool.objects.filter(ip__isnull=False) And that is what is causing the memory consumption. If I move that outside the loop and just do that once the memory issue goes away. Now I need to figure out why this is happening and how to prevent it as they do want to query the db each pass through the loop in case it has been updated. From larry.martell at gmail.com Thu Mar 6 17:07:01 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 6 Mar 2014 17:07:01 -0500 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Thu, Mar 6, 2014 at 4:56 PM, Larry Martell wrote: > On Wed, Mar 5, 2014 at 5:27 PM, Larry Martell wrote: >> I have a script that forks off other processes and attempts to manage >> them. Here is a stripped down version of the script: >> >> self.sleepTime = 300 >> self.procs = {} >> self.startTimes = {} >> self.cmd = ['python', '/usr/local/motor/motor/app/some_other_script.py'] >> >> while True: >> try: >> self.tools = Tool.objects.filter(ip__isnull=False) >> except Exception, e: >> print 'error from django call: ' + str(e) >> sys.exit(1) >> >> for tool in self.tools: >> name = tool.name >> if name in self.procs: >> if self.procs[name].poll() is None: >> if >> (datetime.datetime.now()-self.startTimes[name]) > >> datetime.timedelta(hours=12): >> # it's been running too long - kill it >> print 'killing script for ' + name + " >> it's been running too long" >> self.procs[name].kill() >> else: >> continue >> >> if self.procs[name].returncode: >> print 'scrikpt failed for ' + name + ', error >> = ' + str(self.procs[name].returncode) >> >> print 'starting script.py for ' + name + ' at ' + >> str(datetime.datetime.now()) >> try: >> self.procs[name] = subprocess.Popen(self.cmd) >> self.startTimes[name] = datetime.datetime.now() >> except Exception, e: >> print 'error from Popen: ' + str(e) >> sys.exit(1) >> else: >> print 'starting script.py for ' + name + ' at ' + >> str(datetime.datetime.now()) >> try: >> self.procs[name] = subprocess.Popen(self.cmd) >> self.startTimes[name] = datetime.datetime.now() >> except Exception, e: >> print 'error from Popen: ' + str(e) >> sys.exit(1) >> >> time.sleep(self.sleepTime) >> >> >> The script does what it's intended to do, however after about 2 hours >> it has used up all the memory available and the machine hangs. Can >> anyone see something that I am doing here that would be using memory >> like this? Perhaps some immutable object needs to be repeatedly >> recreated? > > I figured out what is causing this. Each pass through the loop it does: > > self.tools = Tool.objects.filter(ip__isnull=False) > > And that is what is causing the memory consumption. If I move that > outside the loop and just do that once the memory issue goes away. Now > I need to figure out why this is happening and how to prevent it as > they do want to query the db each pass through the loop in case it has > been updated. Apparently the object returned by that call is immutable as if I look at id(self.tools) each pass through the loop, it is different. Is there some way I can recover that memory? From rosuav at gmail.com Thu Mar 6 17:11:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 09:11:37 +1100 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Fri, Mar 7, 2014 at 8:56 AM, Larry Martell wrote: > I figured out what is causing this. Each pass through the loop it does: > > self.tools = Tool.objects.filter(ip__isnull=False) > > And that is what is causing the memory consumption. If I move that > outside the loop and just do that once the memory issue goes away. Now > I need to figure out why this is happening and how to prevent it as > they do want to query the db each pass through the loop in case it has > been updated. Interesting. So the next thing to do is to look into the implementation of that. Does it allocate database resources and not free them? Does it have internal reference loops? Something to try: Put an explicit gc.collect() call into the loop. If that solves your problem, you have a refloop somewhere (and you can properly fix it by explicitly breaking the loop). If that keeps returning large numbers, and especially if it populates gc.garbage with a whole lot of stuff, then you definitely have refloops. http://docs.python.org/2/library/gc.html ChrisA From rosuav at gmail.com Thu Mar 6 17:12:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 09:12:54 +1100 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Fri, Mar 7, 2014 at 9:07 AM, Larry Martell wrote: > Apparently the object returned by that call is immutable as if I look > at id(self.tools) each pass through the loop, it is different. Is > there some way I can recover that memory? Not sure what mutability has to do with that. The changing id() simply means you're getting back a new object every time. Normally, as soon as your rebind self.tools to the new object, the old object will be disposed of - unless it has refloops, which is what I mentioned in the previous post, or has some other external reference. ChrisA From larry.martell at gmail.com Thu Mar 6 17:21:26 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 6 Mar 2014 17:21:26 -0500 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Thu, Mar 6, 2014 at 5:11 PM, Chris Angelico wrote: > On Fri, Mar 7, 2014 at 8:56 AM, Larry Martell wrote: >> I figured out what is causing this. Each pass through the loop it does: >> >> self.tools = Tool.objects.filter(ip__isnull=False) >> >> And that is what is causing the memory consumption. If I move that >> outside the loop and just do that once the memory issue goes away. Now >> I need to figure out why this is happening and how to prevent it as >> they do want to query the db each pass through the loop in case it has >> been updated. > > Interesting. So the next thing to do is to look into the > implementation of that. Does it allocate database resources and not > free them? Does it have internal reference loops? > > Something to try: Put an explicit gc.collect() call into the loop. If > that solves your problem, you have a refloop somewhere (and you can > properly fix it by explicitly breaking the loop). If that keeps > returning large numbers, and especially if it populates gc.garbage > with a whole lot of stuff, then you definitely have refloops. > > http://docs.python.org/2/library/gc.html First I added del(self.tools) before the Django call. That did not stop the memory consumption. Then I added a call to gc.collect() after the del and that did solve it. gc.collect() returns 0 each time, so I'm going to declare victory and move on. No time to dig into the Django code. Thanks. From rosuav at gmail.com Thu Mar 6 17:28:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 09:28:42 +1100 Subject: script uses up all memory In-Reply-To: References: Message-ID: On Fri, Mar 7, 2014 at 9:21 AM, Larry Martell wrote: > First I added del(self.tools) before the Django call. That did not > stop the memory consumption. Then I added a call to gc.collect() after > the del and that did solve it. gc.collect() returns 0 each time, so > I'm going to declare victory and move on. No time to dig into the > Django code. Thanks. Not all problems need to be solved perfectly :) But at very least, I would put a comment against your collect() call explaining what happens: that self.tools is involved in a refloop. Most Python code shouldn't have to call gc.collect(), so it's worth explaining why you are here. ChrisA From gordon at panix.com Thu Mar 6 17:28:06 2014 From: gordon at panix.com (John Gordon) Date: Thu, 6 Mar 2014 22:28:06 +0000 (UTC) Subject: beautiful soup get class info References: Message-ID: In teddybubu at gmail.com writes: > > soup.find_all(name="span", class="date") > I have python 2.7.2 and it does not like class in the code you provided. Oh right, 'class' is a reserved word. I imagine beautifulsoup has a workaround for that. > Now when I take out [ class="date"], this is returned: > [March 5, 2014, March 5, 2014] > > This is the code I am using: "data = soup.find_all(name="span") > print (data)" > 1. it returns today's date instead of the actual date > 2. returns it twice Are there two occurrences of 'March 5, 2014' in the HTML? If so, then beautifulsoup is doing its job correctly. It might help if you posted the sample HTML data you're working with. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From marko at pacujo.net Thu Mar 6 17:34:39 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 07 Mar 2014 00:34:39 +0200 Subject: script uses up all memory References: Message-ID: <87ha7bq7ls.fsf@elektro.pacujo.net> Chris Angelico : > Not all problems need to be solved perfectly :) But at very least, I > would put a comment against your collect() call explaining what > happens: that self.tools is involved in a refloop. Most Python code > shouldn't have to call gc.collect(), so it's worth explaining why you > are here. Refloops also are nothing to be avoided. Let GC do its job and forget about it. Marko From rosuav at gmail.com Thu Mar 6 17:43:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 09:43:36 +1100 Subject: script uses up all memory In-Reply-To: <87ha7bq7ls.fsf@elektro.pacujo.net> References: <87ha7bq7ls.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 7, 2014 at 9:34 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Not all problems need to be solved perfectly :) But at very least, I >> would put a comment against your collect() call explaining what >> happens: that self.tools is involved in a refloop. Most Python code >> shouldn't have to call gc.collect(), so it's worth explaining why you >> are here. > > Refloops also are nothing to be avoided. Let GC do its job and forget > about it. I think this thread is proof that they are to be avoided. The GC wasn't doing its job unless explicitly called on. The true solution is to break the refloop; the quick fix is to call gc.collect(). I stand by the recommendation to put an explanatory comment against the collect call. [1] ChrisA [1] Here in Australia, that should be gc.reverse_charges(). From marko at pacujo.net Thu Mar 6 18:12:31 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 07 Mar 2014 01:12:31 +0200 Subject: script uses up all memory References: <87ha7bq7ls.fsf@elektro.pacujo.net> Message-ID: <87d2hyrkf4.fsf@elektro.pacujo.net> Chris Angelico : > I think this thread is proof that they are to be avoided. The GC > wasn't doing its job unless explicitly called on. The true solution is > to break the refloop; the quick fix is to call gc.collect(). I stand > by the recommendation to put an explanatory comment against the > collect call. What I'm saying is that under most circumstances you shouldn't care if the memory consumption goes up and down. The true solution is to not do anything about temporary memory consumption. Also, you shouldn't worry about breaking circular references. That is also often almost impossible to accomplish as so much modern code builds on closures, which generate all kinds of circular references under the hood?for your benefit, or course. Marko From rosuav at gmail.com Thu Mar 6 18:31:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 10:31:46 +1100 Subject: script uses up all memory In-Reply-To: <87d2hyrkf4.fsf@elektro.pacujo.net> References: <87ha7bq7ls.fsf@elektro.pacujo.net> <87d2hyrkf4.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 7, 2014 at 10:12 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> I think this thread is proof that they are to be avoided. The GC >> wasn't doing its job unless explicitly called on. The true solution is >> to break the refloop; the quick fix is to call gc.collect(). I stand >> by the recommendation to put an explanatory comment against the >> collect call. > > What I'm saying is that under most circumstances you shouldn't care if > the memory consumption goes up and down. The true solution is to not do > anything about temporary memory consumption. Also, you shouldn't worry > about breaking circular references. That is also often almost impossible > to accomplish as so much modern code builds on closures, which generate > all kinds of circular references under the hood?for your benefit, or > course. This isn't a temporary issue, though - see the initial post. After two hours of five-minutely checks, the computer was wedged. That's a problem to be solved. Most of what I do with closures can't create refloops, because the function isn't referenced from inside itself. You'd need something like this: >>> def foo(): x=1 y=lambda: (x,y) return y >>> len([foo() for _ in range(1000)]) 1000 >>> gc.collect() 4000 >>> len([foo() for _ in range(1000)]) 1000 >>> gc.collect() 4000 >>> len([foo() for _ in range(1000)]) 1000 >>> gc.collect() 4000 That's repeatably creating garbage. But change the function to not return itself, and there's no loop: >>> def foo(): x=1 y=lambda: x return y >>> gc.collect() 0 >>> len([foo() for _ in range(1000)]) 1000 >>> gc.collect() 0 >>> len([foo() for _ in range(1000)]) 1000 >>> gc.collect() 0 The only even reasonably common case that I can think of is a recursive nested function: >>> def foo(x): def y(f,x=x): f() for _ in range(x): y(f,x-1) return y It's a function that returns a function that calls its argument some number of times, where the number is derived in a stupid way from the argument to the first function. The whole function is garbage, so it's not surprising that the GC has to collect it. >>> len([foo(5) for _ in range(1000)]) 1000 >>> gc.collect() 3135 >>> len([foo(5) for _ in range(1000)]) 1000 >>> gc.collect() 3135 >>> len([foo(5) for _ in range(1000)]) 1000 >>> gc.collect() 3135 Can you give a useful example of a closure that does create a refloop? ChrisA From marko at pacujo.net Thu Mar 6 18:53:03 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 07 Mar 2014 01:53:03 +0200 Subject: script uses up all memory References: <87ha7bq7ls.fsf@elektro.pacujo.net> <87d2hyrkf4.fsf@elektro.pacujo.net> Message-ID: <878usmrijk.fsf@elektro.pacujo.net> Chris Angelico : > Can you give a useful example of a closure that does create a refloop? Just the other day, I mentioned the state pattern: class MyStateMachine: def __init__(self): sm = self class IDLE: def ding(self): sm.open_door() sm.state = AT_DOOR() class AT_DOOR: ... self.state = IDLE() def ding(self): self.state.ding() So we have: MyStateMachine instance -> MyStateMachine instance.ding -> IDLE instance -> IDLE instance.ding -> MyStateMachine instance plus numerous others in this example alone. In general, event-driven programming produces circular references left and right, and that might come into wider use with asyncio. I suspect generators might create circular references as well. Any tree data structure with parent references creates cycles. In fact, I would imagine most OO designs create a pretty tight mesh of back-and-forth references. Marko From contact at pycon-au.org Thu Mar 6 19:07:03 2014 From: contact at pycon-au.org (PyCon AU) Date: Fri, 7 Mar 2014 11:07:03 +1100 Subject: Call for Proposals: PyCon AU 2014 in Brisbane Message-ID: PyCon Australia 2014 is pleased to announce that its Call for Proposals is now open! The conference this year will be held on Saturday 2 and Sunday 3 August 2014 in Brisbane. We'll also be featuring a day of miniconfs on Friday 1 August. The deadline for proposal submission is Friday April 25, 2014, and more information can be found at http://pycon-au.org/cfp PyCon Australia attracts professional developers from all walks of life, including industry, government, and science, as well as enthusiast and student developers. We're looking for proposals for presentations and tutorials on any aspect of Python programming, at all skill levels from novice to advanced. Presentation subjects may range from reports on open source, academic or commercial projects; or even tutorials and case studies. If a presentation is interesting and useful to the Python community, it will be considered for inclusion in the program. We're especially interested in short presentations that will teach conference-goers something new and useful. Can you show attendees how to use a module? Explore a Python language feature? Package an application? Proposals about the Django web framework are very strongly encouraged, and will also be considered for inclusion in DjangoCon AU, to be held on Friday 1 August. We welcome first-time speakers; we are a community conference and we are eager to hear about your experience. If you have friends or colleagues who have something valuable to contribute, twist their arms to tell us about it! Please also forward this Call for Proposals to anyone that you feel may be interested. To find out more go to the official Call for Proposals page here: http://pycon-au.org/cfp See you in Brisbane in August! == About PyCon Australia == PyCon Australia is the national conference for the Python Programming Community. The fifth PyCon Australia will be held on August 1--5, 2014 in Brisbane, bringing together professional, student and enthusiast developers with a love for developing with Python. PyCon Australia informs the country's Python developers with presentations, tutorials and panel sessions by experts and core developers of Python, as well as the libraries and frameworks that they rely on. To find out more about PyCon Australia 2014, visit our website at http://pycon-au.org or e-mail us at contact at pycon-au.org. PyCon Australia is presented by Linux Australia (www.linux.org.au) and acknowledges the support of our Platinum Sponsor, Red Hat, and our Gold sponsors, Google Australia and Netbox Blue. For full details of our sponsors, see our website. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Mar 6 19:11:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 11:11:16 +1100 Subject: script uses up all memory In-Reply-To: <878usmrijk.fsf@elektro.pacujo.net> References: <87ha7bq7ls.fsf@elektro.pacujo.net> <87d2hyrkf4.fsf@elektro.pacujo.net> <878usmrijk.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 7, 2014 at 10:53 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Can you give a useful example of a closure that does create a refloop? > > Just the other day, I mentioned the state pattern: > > class MyStateMachine: > def __init__(self): > sm = self > > class IDLE: > def ding(self): > sm.open_door() > sm.state = AT_DOOR() Yeah, that's an extremely unusual way to do things. Why keep on instantiating objects when you could just reference functions? > In general, event-driven programming produces circular references left > and right, and that might come into wider use with asyncio. Nope; certainly not with closures. I do a whole lot of event-driven programming (usually in Pike rather than Python, but they work the same way in this), and there's no reference loop. Properly-done event-driven programming should have two basic states: a reference from some invisible thing that can trigger the event (eg a GUI widget) to a callable, and a reference from that callable to its state. Once the trigger is gone, the callable is dropped, its state is dropped, and everything's cleaned up. You don't usually need a reference inside the function to that function. Don't forget, a closure need only hang onto the things it actually uses. It doesn't need all its locals. > I suspect generators might create circular references as well. I doubt it. >>> def foo(x): return ("x"*i for i in range(x)) >>> len([foo(5) for _ in range(1000)]) 1000 >>> gc.collect() 0 >>> len([foo(5) for _ in range(1000)]) 1000 >>> gc.collect() 0 Again, unless it keeps a reference to itself, there's no loop. It'll need to hang onto some of its locals, but that's all. > Any tree data structure with parent references creates cycles. Yes, but how many of those do you actually have and drop? If you create a GUI, you generally hold your entire widget tree stably. The only issue is if you create a parent-child subtree and then drop it. That shouldn't be being done in a tight loop. Most of the classic data structures like trees are implemented at the C level, so again, your code shouldn't be concerning itself with that. > In fact, I would imagine most OO designs create a pretty tight mesh of > back-and-forth references. Examples, please? I can think of a handful of situations where I've created reference loops, and they're sufficiently rare that I can put comments against them and explicitly break them. For instance, I have a "Subwindow" that has a "Connection". My window can have multiple subwindows, a subwindow may or may not have a connection, and the connection always references its subwindow. The subw->connection->subw loop is explicitly broken when the connection is terminated. If the window chooses to drop a subw, it first checks if there's a connection (and prompts the user to confirm), and then will explicitly disconnect, which breaks the refloop (as the connection's terminated). I did a similar thing at work, again with explicit refloop breakage to ensure clean removal. Apart from those two cases, I can't think of anything in the last ten years where I've had a data structure with a loop in it, where the whole loop could be dropped. (My MUD has a loop, in that a character exists in a room, and the room keeps track of its contents; but it's not logical to drop a room with characters in it, and dropping a character is done by moving it to no-room, which breaks the refloop.) ChrisA From marko at pacujo.net Thu Mar 6 19:31:13 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 07 Mar 2014 02:31:13 +0200 Subject: script uses up all memory References: <87ha7bq7ls.fsf@elektro.pacujo.net> <87d2hyrkf4.fsf@elektro.pacujo.net> <878usmrijk.fsf@elektro.pacujo.net> Message-ID: <874n3argry.fsf@elektro.pacujo.net> Chris Angelico : > On Fri, Mar 7, 2014 at 10:53 AM, Marko Rauhamaa wrote: >> class MyStateMachine: >> def __init__(self): >> sm = self >> >> class IDLE: >> def ding(self): >> sm.open_door() >> sm.state = AT_DOOR() > > Yeah, that's an extremely unusual way to do things. Why keep on > instantiating objects when you could just reference functions? That's not crucial. Even if the state objects were instantiated and inner classes not used, you'd get the same circularity: class State: def __init__(self, sm): self.sm = sm class Idle(State): def ding(self): self.sm.open_door() self.sm.state = self.sm.AT_DOOR class AtDoor(state): ... class MyStateMachine: def __init__(self): self.IDLE = Idle(self) self.AT_DOOR = AtDoor(self) ... self.state = self.IDLE The closure style is more concise and to the point and might perform no worse. > Nope; certainly not with closures. I do a whole lot of event-driven > programming (usually in Pike rather than Python, but they work the > same way in this), and there's no reference loop. Properly-done > event-driven programming should have two basic states: a reference > from some invisible thing that can trigger the event (eg a GUI widget) > to a callable, and a reference from that callable to its state. Once > the trigger is gone, the callable is dropped, its state is dropped, > and everything's cleaned up. You don't usually need a reference inside > the function to that function. I'm more familiar with networking. If you need a timer, you need to be able to start it so you need a reference to it. Ok, maybe you instantiate a new timer each time, but you may need to cancel the timer so starting the timer gives you a ticket you can use for canceling. Similarly, you need a socket (wrapper) to signal an I/O state change, and you also need to be able to close the socket at a bare minimum. The task scheduling service (asyncio has one) collects thunks that refer to your objects and your objects have a reference to the task scheduling service to be able to schedule new tasks. > Don't forget, a closure need only hang onto the things it actually > uses. It doesn't need all its locals. More importantly, there's nothing bad in circularity. No need to avoid it. No need to cut cords. Marko From roy at panix.com Thu Mar 6 20:24:21 2014 From: roy at panix.com (Roy Smith) Date: Thu, 06 Mar 2014 20:24:21 -0500 Subject: Python programming References: <5317e2ca$0$9232$e4fe514c@dreader35.news.xs4all.nl> Message-ID: In article , Dennis Lee Bieber wrote: > On 06 Mar 2014 02:51:54 GMT, albert at spenarnc.xs4all.nl (Albert van der > Horst) declaimed the following: > > >In article , > >Roy Smith wrote: > >>In article , > >> Grant Edwards wrote: > >> > >>> On 2014-02-13, Dennis Lee Bieber wrote: > >>> > >>> > An S-100 wire-wrap board. > >>> > >>> Yup, been there done that! > >> > >>Never did S-100, but I did do a custom Unibus card (wirewrap). > >> > >>You know you're working with a Real Computer (tm) when the +5V power > >>supply can deliver as much current as an arc welder. > > > >I've a 64 node Parsytec transputer system in the hall way with > >dual 5V 100A power supplies. Does that count? > > I spotted a device on the table of the company calibration office... > > As I recall, it was a 100A capable resistor... 0.10 OHM. > > No idea what it was meant for; big binding posts at one end, and a slab > of sheet steel in a "W" shape (smooth curves, not sharp bends). External shunt for an ammeter? From teddybubu at gmail.com Thu Mar 6 20:37:28 2014 From: teddybubu at gmail.com (teddybubu at gmail.com) Date: Thu, 6 Mar 2014 17:37:28 -0800 (PST) Subject: beautiful soup get class info In-Reply-To: References: Message-ID: On Thursday, March 6, 2014 4:28:06 PM UTC-6, John Gordon wrote: > In writes: > > > > > > soup.find_all(name="span", class="date") > > > > > I have python 2.7.2 and it does not like class in the code you provided. > > > > Oh right, 'class' is a reserved word. I imagine beautifulsoup has > > a workaround for that. > > > > > Now when I take out [ class="date"], this is returned: > > > [March 5, 2014, March 5, 2014] > > > > > > This is the code I am using: "data = soup.find_all(name="span") > > > print (data)" > > > 1. it returns today's date instead of the actual date > > > 2. returns it twice > > > > Are there two occurrences of 'March 5, 2014' > > in the HTML? If so, then beautifulsoup is doing its job correctly. > > > > It might help if you posted the sample HTML data you're working with. > > > > -- > > John Gordon Imagine what it must be like for a real medical doctor to > > watch 'House', or a real serial killer to watch 'Dexter'. ok I got this working. now to the next problem.... thanks. From breamoreboy at yahoo.co.uk Thu Mar 6 20:48:59 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 07 Mar 2014 01:48:59 +0000 Subject: beautiful soup get class info In-Reply-To: References: Message-ID: On 07/03/2014 01:37, teddybubu at gmail.com wrote: > On Thursday, March 6, 2014 4:28:06 PM UTC-6, John Gordon wrote: >> In writes: >> >> >> >>>> soup.find_all(name="span", class="date") >> >> >> >>> I have python 2.7.2 and it does not like class in the code you provided. >> >> >> >> Oh right, 'class' is a reserved word. I imagine beautifulsoup has >> >> a workaround for that. >> >> >> >>> Now when I take out [ class="date"], this is returned: >> >>> [March 5, 2014, March 5, 2014] >> >>> >> >>> This is the code I am using: "data = soup.find_all(name="span") >> >>> print (data)" >> >>> 1. it returns today's date instead of the actual date >> >>> 2. returns it twice >> >> >> >> Are there two occurrences of 'March 5, 2014' >> >> in the HTML? If so, then beautifulsoup is doing its job correctly. >> >> >> >> It might help if you posted the sample HTML data you're working with. >> >> >> >> -- >> >> John Gordon Imagine what it must be like for a real medical doctor to >> >> watch 'House', or a real serial killer to watch 'Dexter'. > > ok I got this working. now to the next problem.... thanks. > I'm pleased to see that you have a solution. Now, should you wish to ask further questions, would you please read and action this first https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Thu Mar 6 20:53:15 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Thu, 6 Mar 2014 17:53:15 -0800 (PST) Subject: How security holes happen In-Reply-To: References: <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> <5adebc12-aa37-4139-82d8-563f46a27dc0@googlegroups.com> Message-ID: On Thursday, March 6, 2014 6:28:58 PM UTC-6, Dennis Lee Bieber wrote: > > The 6502 was NOT a Motorola chip (they had the 6800). The 6502 was MOS That's funny... did you not see what I wrote back to MRAB? Here: The MOS 6502 is to the Motorola 6800 what the Zilog Z80 was to the Intel 8080. The same engineers who designed the 6800 moved out and then designed the 6502; actually ended up in a law suit of sorts--- but I don't remember the details. Anyway, the 6502 was bought outright by Commodore, and the rest is history with the VIC20. From harrismh777 at gmail.com Thu Mar 6 20:54:16 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Thu, 6 Mar 2014 17:54:16 -0800 (PST) Subject: test Message-ID: disregard From nispray at gmail.com Thu Mar 6 21:03:11 2014 From: nispray at gmail.com (Wesley) Date: Thu, 6 Mar 2014 18:03:11 -0800 (PST) Subject: gdb unable to read python frame information Message-ID: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> Hi guys, My env: centos 6.5 64 bit; gdb 7.1; python 2.6.6 I wanna use gdb to attach my running python scripts. Successfully import libpython in gdb, but seems all py operations failed to read python information. Here is the snippet: (gdb) python >import libpython >end (gdb) py-bt #3 (unable to read python frame information) #5 (unable to read python frame information) #7 (unable to read python frame information) #9 (unable to read python frame information) #18 (unable to read python frame information) #22 (unable to read python frame information) #26 (unable to read python frame information) #28 (unable to read python frame information) #29 (unable to read python frame information) #38 (unable to read python frame information) #39 (unable to read python frame information) #40 (unable to read python frame information) #42 (unable to read python frame information) #44 (unable to read python frame information) #45 (unable to read python frame information) #47 (unable to read python frame information) #49 (unable to read python frame information) #51 (unable to read python frame information) #55 (unable to read python frame information) #62 (unable to read python frame information) #64 (unable to read python frame information) #76 (unable to read python frame information) #88 (unable to read python frame information) #100 (unable to read python frame information) (gdb) py-locals Unable to read information on python frame (gdb) Is there anything wrong? Thanks. Wesley From python at mrabarnett.plus.com Thu Mar 6 21:13:02 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 07 Mar 2014 02:13:02 +0000 Subject: How security holes happen In-Reply-To: References: <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> <5adebc12-aa37-4139-82d8-563f46a27dc0@googlegroups.com> Message-ID: <53192B2E.5010505@mrabarnett.plus.com> On 2014-03-07 01:53, Mark H. Harris wrote: > On Thursday, March 6, 2014 6:28:58 PM UTC-6, Dennis Lee Bieber wrote: >> >> The 6502 was NOT a Motorola chip (they had the 6800). The 6502 was MOS > > That's funny... did you not see what I wrote back to MRAB? Here: > > The MOS 6502 is to the Motorola 6800 what the Zilog Z80 was to the Intel 8080. > Not quite. The Z80's architecture and instruction set is a superset of that of the 8080; the 6502's architecture and instruction set isn't a superset of, or even compatible with, that of the 6800 (although it can use the same I/O, etc, chips). > The same engineers who designed the 6800 moved out and then designed > the 6502; actually ended up in a law suit of sorts--- but I don't remember the > details. Anyway, the 6502 was bought outright by Commodore, and the rest > is history with the VIC20. > From harrismh777 at gmail.com Thu Mar 6 21:39:01 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Thu, 6 Mar 2014 18:39:01 -0800 (PST) Subject: How security holes happen In-Reply-To: References: <871tyhp2vd.fsf@elektro.pacujo.net> <5316dfa4$0$2923$c3e8da3$76491128@news.astraweb.com> <5adebc12-aa37-4139-82d8-563f46a27dc0@googlegroups.com> Message-ID: On Thursday, March 6, 2014 8:13:02 PM UTC-6, MRAB wrote: > > The Z80's architecture and instruction set is a superset of that of the > 8080; the 6502's architecture and instruction set isn't a superset of, > or even compatible with, that of the 6800 (although it can use the same > I/O, etc, chips). My point is not what, but who. Motorola engineers designed the 6502. A rose is a rose by any other name. Its the people who count... if Motorola had listened to those guys, who knows ... ? neither here nor there now, or course. From wrw at mac.com Thu Mar 6 21:27:33 2014 From: wrw at mac.com (William Ray Wing) Date: Thu, 06 Mar 2014 21:27:33 -0500 Subject: Python programming In-Reply-To: References: <5317e2ca$0$9232$e4fe514c@dreader35.news.xs4all.nl> Message-ID: <7B71F73B-9D8D-4F01-A5D8-B788DA25E1B3@mac.com> On Mar 6, 2014, at 8:24 PM, Roy Smith wrote: > In article , > Dennis Lee Bieber wrote: > >> On 06 Mar 2014 02:51:54 GMT, albert at spenarnc.xs4all.nl (Albert van der >> Horst) declaimed the following: >> >>> In article , >>> Roy Smith wrote: >>>> In article , >>>> Grant Edwards wrote: >>>> >>>>> On 2014-02-13, Dennis Lee Bieber wrote: >>>>> >>>>>> An S-100 wire-wrap board. >>>>> >>>>> Yup, been there done that! >>>> >>>> Never did S-100, but I did do a custom Unibus card (wirewrap). >>>> >>>> You know you're working with a Real Computer (tm) when the +5V power >>>> supply can deliver as much current as an arc welder. >>> >>> I've a 64 node Parsytec transputer system in the hall way with >>> dual 5V 100A power supplies. Does that count? >> >> I spotted a device on the table of the company calibration office... >> >> As I recall, it was a 100A capable resistor... 0.10 OHM. >> >> No idea what it was meant for; big binding posts at one end, and a slab >> of sheet steel in a "W" shape (smooth curves, not sharp bends). > > External shunt for an ammeter? > More likely a dummy load for power supply testing. (Normally, ammeter shunts are sized to dissipate as little power as possible.) -Bill From dieter at handshake.de Fri Mar 7 02:10:20 2014 From: dieter at handshake.de (dieter) Date: Fri, 07 Mar 2014 08:10:20 +0100 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> Message-ID: <87mwh2bi1v.fsf@handshake.de> Wesley writes: > I wanna use gdb to attach my running python scripts. > Successfully import libpython in gdb, but seems all py operations failed to read python information. > > Here is the snippet: > (gdb) python >>import libpython >>end > (gdb) py-bt > #3 (unable to read python frame information) > #5 (unable to read python frame information) The simplest possible interpretation would be that your Python lacks debugging symbols. That often happens with system installed Python installations (which usually are stripped to the bare minimal symbol set - as "normal" users do not need debugging). Try with a Python that you have generated yourself. From rosuav at gmail.com Fri Mar 7 02:16:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 18:16:55 +1100 Subject: Assertions are bad, m'kay? Message-ID: They produce the wrong exception type, they disappear when you least expect them, and now we have another reason not to use assert. http://xkcd.com/1339/ Abusing assert for arg checking violates XKCD 1339. Write standards-compliant code! ChrisA From cs at zip.com.au Fri Mar 7 02:57:44 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 7 Mar 2014 18:57:44 +1100 Subject: why does "python --version" write to standard error? Message-ID: <20140307075744.GA43732@cskk.homeip.net> This seems to write the python version to standard error. That seems very wrong. And at variance with the manual entry. Commentry? -- Cameron Simpson This is not a bug. It's just the way it works, and makes perfect sense. - Tom Christiansen I like that line. I hope my boss falls for it. - Chaim Frenkel From orgnut at yahoo.com Fri Mar 7 02:56:00 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 06 Mar 2014 23:56:00 -0800 Subject: Python programming In-Reply-To: References: <5317e2ca$0$9232$e4fe514c@dreader35.news.xs4all.nl> Message-ID: >>> I spotted a device on the table of the company calibration office... >>> >>> As I recall, it was a 100A capable resistor... 0.10 OHM. >>> >>> No idea what it was meant for; big binding posts at one end, and a slab >>> of sheet steel in a "W" shape (smooth curves, not sharp bends). >> >> External shunt for an ammeter? >> > > More likely a dummy load for power supply testing. (Normally, ammeter shunts are sized to dissipate as little power as possible.) > > -Bill > Another (OT) story... I used to work in an electronic calibration lab, but I don't recall having a resistor of that description -- however, it reminds me of another story... While our job was calibrating and maintaining our company's electronics, we occasionally had to do some incoming inspection work -- checking incoming components for accuracy. This particular time I had a batch of 0.1 ohm 1% resistors (I think those were the numbers, at least something on that order). I found by checking them right at the body of the resistors they were out-of-spec low, and checking at the end of the leads they were out-of-spec high. Fun! :-) To measure them, I used the lab's Current Calibrator -- a special power supply whose voltage was controlled to give a constant (dialed-in) current. Then with a DVM and mini-hooks I could attach these DVM leads anyplace along the resistor's leads. At 1 amp, the voltage (read on the DVM) was equal to the resistance. Ohm's law, of course: R = E/I, where I is a constant 1. And 1 amp was well within the power specs of these resistors. I ended up checking them at a distance of about a quarter inch from the body, because I expected that would be about the way they would be eventually mounted. They all passed that way. And fortunately I never had another batch of these resistors! :-) -=- Larry -=- From nad at acm.org Fri Mar 7 03:31:58 2014 From: nad at acm.org (Ned Deily) Date: Fri, 07 Mar 2014 00:31:58 -0800 Subject: why does "python --version" write to standard error? References: <20140307075744.GA43732@cskk.homeip.net> Message-ID: In article <20140307075744.GA43732 at cskk.homeip.net>, Cameron Simpson wrote: > This seems to write the python version to standard error. That seems > very wrong. And at variance with the manual entry. Fixed in Python 3.4: http://bugs.python.org/issue18338 -- Ned Deily, nad at acm.org From ra1717 at nyu.edu Fri Mar 7 03:15:07 2014 From: ra1717 at nyu.edu (Romil Agrawal) Date: Fri, 7 Mar 2014 03:15:07 -0500 Subject: problem running python 3.3 on mac os mavericks Message-ID: I currently installed python 3.3.4 on mac os mavericks, and want to run it on Wing IDE. Previously it was running python 2.7.6. When I tried to change the python excitable in the wing ide configuration mode, and then restarted it, a dialog box was displayed that said the interpreter of python 3.3.4 on the specified path may not exist. Please help me sort this out. Also, python 3.3.4 is installed on my mac and running on the IDLE, but the terminal shows that the current version of python is 2.7.6. how can it be possible. Please suggest something to sort this thing out. Thanking you. Regards, Romil Agrawal -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Fri Mar 7 04:33:49 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 7 Mar 2014 09:33:49 GMT Subject: Tuples and immutability References: Message-ID: Chris Angelico wrote: > On Sat, Mar 1, 2014 at 1:41 AM, Joshua Landau > wrote: >> Would it be better to add a check here, such that if this gets raised >> to the top-level it includes a warning ("Addition was inplace; >> variable probably mutated despite assignment failure")? > > That'd require figuring out whether or not the variable was actually > mutated, and that's pretty hard to work out. So there's a FAQ entry, > which Zachary already posted: > > http://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-r > aise-an-exception-when-the-addition-works > > Also, we just answer this question every now and then :) Presumably > more often on -tutor than here. > > ChrisA Another take on this that I haven't seen discussed in this thread: Is there any reason why tuples need to throw an exception on assigning to the element if the old value and new value are the same object? If I say: a = ("spam", [10, 30], "eggs") then a[0] = a[0] won't actually mutate the object. So tuples could let that silently pass. Then you would be able to safely do: a[1] += [50] but this would still throw an exception: a[0] += "x" -- Duncan Booth http://kupuguy.blogspot.com From cs at zip.com.au Fri Mar 7 05:06:31 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 7 Mar 2014 21:06:31 +1100 Subject: why does "python --version" write to standard error? In-Reply-To: References: Message-ID: <20140307100631.GA74648@cskk.homeip.net> On 07Mar2014 00:31, Ned Deily wrote: > In article <20140307075744.GA43732 at cskk.homeip.net>, > Cameron Simpson wrote: > > This seems to write the python version to standard error. That seems > > very wrong. And at variance with the manual entry. > > Fixed in Python 3.4: > http://bugs.python.org/issue18338 Excellent! My thanks to Berker Peksag and Michael Dickens and the other ticket participants. -- Cameron Simpson The double cam chain setup on the 1980's DOHC CB750 was another one of Honda's pointless engineering breakthroughs. You know the cycle (if you'll pardon the pun :-), Wonderful New Feature is introduced with much fanfare, WNF is fawned over by the press, WNF is copied by the other three Japanese makers (this step is sometimes optional), and finally, WNF is quietly dropped by Honda. - Blaine Gardner, From nispray at gmail.com Fri Mar 7 05:29:35 2014 From: nispray at gmail.com (Wesley) Date: Fri, 7 Mar 2014 02:29:35 -0800 (PST) Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> Message-ID: Then, how to make python get debug symbols? Install python from source with some special configure options? From ben+python at benfinney.id.au Fri Mar 7 06:04:28 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 07 Mar 2014 22:04:28 +1100 Subject: Tuples and immutability References: Message-ID: <85fvmuw9qb.fsf@benfinney.id.au> Duncan Booth writes: > Is there any reason why tuples need to throw an exception on assigning > to the element if the old value and new value are the same object? Special cases aren't special enough to break the rules. -- \ ?I do not believe in forgiveness as it is preached by the | `\ church. We do not need the forgiveness of God, but of each | _o__) other and of ourselves.? ?Robert G. Ingersoll | Ben Finney From rosuav at gmail.com Fri Mar 7 06:11:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 22:11:13 +1100 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Fri, Mar 7, 2014 at 8:33 PM, Duncan Booth wrote: > Is there any reason why tuples need to throw an exception on assigning to > the element if the old value and new value are the same object? It'd be easy enough to implement your own tuple subclass that behaves that way. Try it! See how many situations it actually helps. ChrisA From steve+comp.lang.python at pearwood.info Fri Mar 7 06:11:49 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Mar 2014 11:11:49 GMT Subject: Assertions are bad, m'kay? References: Message-ID: <5319a975$0$29985$c3e8da3$5496439d@news.astraweb.com> On Fri, 07 Mar 2014 18:16:55 +1100, Chris Angelico wrote: > They produce the wrong exception type, they disappear when you least > expect them, and now we have another reason not to use assert. > > http://xkcd.com/1339/ > > Abusing assert for arg checking violates XKCD 1339. Write > standards-compliant code! Assertions are not bad! They're just misunderstood and abused. (By the way, assertions are not the same as assumptions. Asserts can be used to check that assumptions are correct, or to check the internal logic of your reasoning. Whereas assumptions are just accepted as if they were correct, no questions asked. You should read this guy's blog post on when to use assert: http://import-that.dreamwidth.org/676.html It's pretty damn good, if I do say so myself... *whistles innocently* -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri Mar 7 06:24:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 22:24:29 +1100 Subject: Assertions are bad, m'kay? In-Reply-To: <5319a975$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <5319a975$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 7, 2014 at 10:11 PM, Steven D'Aprano wrote: >> http://xkcd.com/1339/ >> >> Abusing assert for arg checking violates XKCD 1339. Write >> standards-compliant code! > > Assertions are not bad! They're just misunderstood and abused. > > (By the way, assertions are not the same as assumptions. Asserts can be > used to check that assumptions are correct, or to check the internal > logic of your reasoning. Whereas assumptions are just accepted as if they > were correct, no questions asked. The XKCD does draw a distinction between assuming and asserting. And I do say "for arg checking", which is the most common *abuse* of assert. But mainly, I just like to share laughs :) ChrisA From __peter__ at web.de Fri Mar 7 06:38:07 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 07 Mar 2014 12:38:07 +0100 Subject: Tuples and immutability References: Message-ID: Chris Angelico wrote: > On Fri, Mar 7, 2014 at 8:33 PM, Duncan Booth > wrote: >> Is there any reason why tuples need to throw an exception on assigning to >> the element if the old value and new value are the same object? > > It'd be easy enough to implement your own tuple subclass that behaves > that way. Try it! See how many situations it actually helps. >>> class T(tuple): ... def __setitem__(self, index, value): ... if value is not self[index]: ... raise TypeError("{} is not {}".format(value, self[index])) ... >>> for i, k in zip(range(250, 260), range(250, 260)): ... T([i])[0] = k ... Traceback (most recent call last): File "", line 2, in File "", line 4, in __setitem__ TypeError: 257 is not 257 I'm not sure "help" is the right word here ;) From rosuav at gmail.com Fri Mar 7 06:45:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Mar 2014 22:45:54 +1100 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Fri, Mar 7, 2014 at 10:38 PM, Peter Otten <__peter__ at web.de> wrote: > TypeError: 257 is not 257 > > I'm not sure "help" is the right word here ;) It doesn't help with non-small integers, yes, but the original case was a list. Personally, I don't think there are many situations that would benefit from it, plus it'd be confusing ("I can use += with a list but not a number, why not?!"). ChrisA From alister.ware at ntlworld.com Fri Mar 7 06:51:28 2014 From: alister.ware at ntlworld.com (Alister) Date: Fri, 07 Mar 2014 11:51:28 GMT Subject: Tuples and immutability References: Message-ID: <4piSu.17150$NC.10985@fx27.am4> On Fri, 07 Mar 2014 09:33:49 +0000, Duncan Booth wrote: > Chris Angelico wrote: > >> On Sat, Mar 1, 2014 at 1:41 AM, Joshua Landau wrote: >>> Would it be better to add a check here, such that if this gets raised >>> to the top-level it includes a warning ("Addition was inplace; >>> variable probably mutated despite assignment failure")? >> >> That'd require figuring out whether or not the variable was actually >> mutated, and that's pretty hard to work out. So there's a FAQ entry, >> which Zachary already posted: >> >> http://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-r >> aise-an-exception-when-the-addition-works >> >> Also, we just answer this question every now and then :) Presumably >> more often on -tutor than here. >> >> ChrisA > Another take on this that I haven't seen discussed in this thread: > > Is there any reason why tuples need to throw an exception on assigning > to the element if the old value and new value are the same object? > > If I say: > > a = ("spam", [10, 30], "eggs") > > then > > a[0] = a[0] > > won't actually mutate the object. So tuples could let that silently > pass. > Then you would be able to safely do: > > a[1] += [50] > > but this would still throw an exception: > > a[0] += "x" I would think it would be better if the exception was thrown before the assignment to the list took place simply seeing that a modification action was being applied to a tupple should be enough. this would alert the programmer to the fact that he was trying something that may have undesired consequences -- Old age is the harbor of all ills. -- Bion From thrinaxodon.of.use.net123 at gmail.com Fri Mar 7 07:27:30 2014 From: thrinaxodon.of.use.net123 at gmail.com (thrinaxodon.of.use.net123 at gmail.com) Date: Fri, 7 Mar 2014 04:27:30 -0800 (PST) Subject: GOLLY! HUMANS HAVE ORIGINS IN THE DEVONIAN! Message-ID: <2ed20849-bec6-4d97-95ae-5621fe689015@googlegroups.com> ====================== >HOLY F*CKING GOD DAMNED NEWS! ====================== > WELCOME TO YOUR NUMBER ONE SOURCE FOR PRESTIGIOUS BULLLSHIT! THE KIND YOU CAN ONLY GET FROM THRINAXODON CRAZY CHEESY! > NOW FOR YOUR FAVORITE TIME SLOT: > ========================== > THRINAXODON FOUND 3 HUMAN FOSSILS FROM DEVONIAN STRATA IN GREENLAND. > ONE OF THEM WAS A NICE KNEECAP. > THE MOST BEAUTIFUL KNEECAP EVER DISCOVERED. > I CALLED OUT CARTER N. > CARTER CAME RUSHING OVER. WE TOOK THE KNEECAP FROM THE INUIT SAVAGES AND FLEW TO THE SMITHSONIAN. > THEY CALLED US KOOKS AND SLAMMED THE DOOR. > ====================================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# From ndbecker2 at gmail.com Fri Mar 7 08:23:20 2014 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 07 Mar 2014 08:23:20 -0500 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <87mwh2bi1v.fsf@handshake.de> Message-ID: dieter wrote: > Wesley writes: > >> I wanna use gdb to attach my running python scripts. >> Successfully import libpython in gdb, but seems all py operations failed to >> read python information. >> >> Here is the snippet: >> (gdb) python >>>import libpython >>>end >> (gdb) py-bt >> #3 (unable to read python frame information) >> #5 (unable to read python frame information) > > The simplest possible interpretation would be that your > Python lacks debugging symbols. That often happens with > system installed Python installations (which usually are stripped > to the bare minimal symbol set - as "normal" users do not need > debugging). > > Try with a Python that you have generated yourself. You probably need to install the python-debuginfo package From robin at reportlab.com Fri Mar 7 08:33:59 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 07 Mar 2014 13:33:59 +0000 Subject: debugging on windows Message-ID: <5319CAC7.4010200@chamonix.reportlab.co.uk> Using > Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. to run a tkinter + pmw2 application I have the following error on windows xp sp3 > Unhandled exception at 0x1e0aebb8 in python.exe: 0xC0000005: Access violation reading location 0x00000048. the main window has appeared and the app is in a module search to find files/classes that might be relevant. VS 2010 indicates the error is some where in the python33 dll. The code appears to run fine in 2.7, but should be compatible with 3.3.x Is my only hope to add more print statements or use pdb or should I try and compile python 3.3.x myself and get the search narrowed with VS? The issue is complicated by my having redirected all outputs to some message windows using fake files for stderr & stdout. -- Robin Becker From roy at panix.com Fri Mar 7 08:37:52 2014 From: roy at panix.com (Roy Smith) Date: Fri, 07 Mar 2014 08:37:52 -0500 Subject: Tuples and immutability References: Message-ID: In article , Duncan Booth wrote: > Is there any reason why tuples need to throw an exception on assigning to > the element if the old value and new value are the same object? > > If I say: > > a = ("spam", [10, 30], "eggs") > > then > > a[0] = a[0] > > won't actually mutate the object. So tuples could let that silently pass. But, why would you want them to? What a way to introduce bugs which are difficult to test for. From invalid at invalid.invalid Fri Mar 7 12:00:49 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 7 Mar 2014 17:00:49 +0000 (UTC) Subject: Python programming References: <5317e2ca$0$9232$e4fe514c@dreader35.news.xs4all.nl> Message-ID: On 2014-03-07, William Ray Wing wrote: > On Mar 6, 2014, at 8:24 PM, Roy Smith wrote: >>> I spotted a device on the table of the company calibration office... >>> >>> As I recall, it was a 100A capable resistor... 0.10 OHM. >>> >>> No idea what it was meant for; big binding posts at one end, and a >>> slab of sheet steel in a "W" shape (smooth curves, not sharp bends). >> >> External shunt for an ammeter? >> > > More likely a dummy load for power supply testing. Could be. Back when I was working on PWM controllers for golf cart and small car motors, we used to use steel coathangers for test loads, but once they got past orange and more towards yellow, they started to get too soft. An appropriately dimensioned chunk of sheet steel would have been ideal. > (Normally, ammeter shunts are sized to dissipate as little power as > possible.) I've used chunks of coathanger for that too, but I don't think the resistance was stable enough over temperature to trust the results at higher currents. -- Grant Edwards grant.b.edwards Yow! If elected, Zippy at pledges to each and every gmail.com American a 55-year-old houseboy ... From john_ladasky at sbcglobal.net Fri Mar 7 13:03:35 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 7 Mar 2014 10:03:35 -0800 (PST) Subject: Python programming In-Reply-To: References: <201402112314.42370.gheskett@wdtv.com> <82055DB9-758F-4B4C-9993-FE4DA60E3D50@mac.com> Message-ID: <560e7dcc-6557-44b8-89f7-adaafa9f0e29@googlegroups.com> On Thursday, February 13, 2014 12:30:39 AM UTC-8, Larry.... at gmail.com wrote: > On Wed, Feb 12, 2014 at 10:56 PM, William Ray Wing wrote: > > > OK, and how many of you remember the original version of the tongue-in-cheek essay "Real Programmers Don't Use Pascal" from the back page of Datamation? > > I do remember it. > > http://www.webcitation.org/659yh1oSh As do I, though I couldn't have been more than about 16 years old when it came out. I just re-read it, and this comment jumped out at me: "Neither OS/370 nor FORTRAN show any signs of dying out, despite all the efforts of Pascal programmers the world over." Well, OS/370, RIP. As for FORTRAN? This week, I actually downloaded an application which required a FORTRAN compiler. This is the only FORTRAN application I've ever needed. It's not old code, the first revision came out about 10 years ago. More than once, I have queried Google with the phrase "Why isn't FORTRAN dead yet?" For some reason, it lives on. I can't say that I understand why. From gheskett at wdtv.com Fri Mar 7 12:49:07 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 7 Mar 2014 12:49:07 -0500 Subject: Python programming In-Reply-To: References: Message-ID: <201403071249.07333.gheskett@wdtv.com> On Friday 07 March 2014 12:29:38 Grant Edwards did opine: > On 2014-03-07, William Ray Wing wrote: > > On Mar 6, 2014, at 8:24 PM, Roy Smith wrote: > >>> I spotted a device on the table of the company calibration office... > >>> > >>> As I recall, it was a 100A capable resistor... 0.10 OHM. > >>> > >>> No idea what it was meant for; big binding posts at one end, and a > >>> slab of sheet steel in a "W" shape (smooth curves, not sharp bends). > >> > >> External shunt for an ammeter? > > > > More likely a dummy load for power supply testing. > > Could be. Back when I was working on PWM controllers for golf cart > and small car motors, we used to use steel coathangers for test loads, > but once they got past orange and more towards yellow, they started to > get too soft. An appropriately dimensioned chunk of sheet steel would > have been ideal. > > > (Normally, ammeter shunts are sized to dissipate as little power as > > possible.) > > I've used chunks of coathanger for that too, but I don't think the > resistance was stable enough over temperature to trust the results at > higher currents. This is really really offtopic but since its turned into war stories, I recall one time that I needed to test a 5v 200amp supply that there were 2 of in an old NEC Digital Video Effects unit, I looked up the R per 1000' of standard romex in the various gauges & went over the Lowes and bought a 100' roll of of 10/2. Soldered the inside end together after striping and twisting it together, It worked well, but the PSU didn't. Made by HP back when they _thought_ they knew about how to build cement block sized power supplies. The psu went into foldback at about 20 amps. All the bugs were good, nothing running warm. Analyzing backwards in view of the curie point on some ferrite's being below the boiling point of water, I finally came to the conclusion that the ferrite in the output transformer had gone austenitic, eg totally non-magnetic, like it was just so much air, which is what many of those compounds will do if magnetized near saturation when they hit the curie point, and will never recover from. HP of course didn't have the transformer or a replacement supply, but I found some Pioneer's with a suitable rating at M.P.Jones in FL and broke their hands putting a check for 2 of them in them, shipped yesterday. That was in about 1997 & they were still in service when we turned analog tv off June 30, 2008. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page NOTICE: Will pay 100 USD for an HP-4815A defective but complete probe assembly. From nexusrawesome at gmail.com Fri Mar 7 12:55:52 2014 From: nexusrawesome at gmail.com (NexusRAwesome1995 .) Date: Fri, 7 Mar 2014 17:55:52 +0000 Subject: Is their a command to view code? Message-ID: I am making a text based aventure game for my assignment and a friends test run has somehow saved over the entire code file and now im using an earlier version of the code. I have 0 idea if there is anyway to look at the code using the IDLE and i need to do it to see how i fixed the fatal error left behind by a friend. My on computer backup has not worked and the backup on my memory stick also has the same problem. If anyone knows of a way to get my code back i will be grateful as this is my 1st project and i'm not that used to the syntax. the item added is the outcome of what happened. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. ================================ RESTART ================================ >>> REMEMBER TO TYPE ALL YOUR ANSWERS IN LOWERCASE (EXCEPT YOUR OWN NAME) >>> >>> ================================ RESTART ================================ >>> REMEMBER TO TYPE ALL YOUR ANSWERS IN LOWERCASE (EXCEPT YOUR OWN NAME) BECAUSE THIS IS OUR FIRST GAME, ANY ANSWERS NOT ENTERED PERFECTLY WILL RESULT IN THE GAME ENDING, SO BE CAREFUL! Hello, please enter your name: Marcus Hyde Marcus Hyde, You begin your adventure in the forest, with Princess Violet. You proceed to climb a tree to pick an apple when you hear her scream. A group of Orcs have taken the princess! What will you do? Attack Run attack You try to attack one of the Orcs but they are too strong! You are knocked out! ... You awaken moments later to see a spirit in front of you. The spirit presents you with three choices, select one. Sword Staff Bow staff You chose Staff! ('Staff does ', 4, ' damage!') You are now equiped with a weapon! Weapons increase your attack power, making you capable of defeating stronger opponents! When you are given a choice, you can check your stats by typing 'stats' Give it a try! What will you do? Stats stats ('HP = ', 10) ('Attack = ', 4) ('Defense = ', 0) As you advance through the game, you may find items to increase your stats. ... Before you can move, you are attacked by a Rogue! Rogue HP = 3 What will you do? Attack Run attack ('You attack the Rogue and deal ', 4, ' damage.') You defeated the Rogue! Rogue droped an item! What will you do? Check Leave check You found a Wooden Shield! Defense = 1 What will you do? Stats Continue continue You continue in search of the Princess and find a cave. There is a lit torch at the entrance of the cave. You take the torch and proceed to enter the cave. As you walk through the cave you notice strange symbols on the walls, what could they mean? You continue walking and come across two paths. You hear the sound of several Orcs coming from the Left path. You feel the wind coming from the Right path, this way is the fastest to the exit. What will you do? Left Right left Despite hearing several Orcs, you choose to take the left path. You fall into a pit with 5 Orcs, one of them attacks you! Orc HP = 6 What will you do? Attack Run run You try to run away but the Orcs grab you. The Orcs beat you to death. GAME OVER >>> fuck Traceback (most recent call last): File "", line 1, in fuck NameError: name 'fuck' is not defined >>> From ian.g.kelly at gmail.com Fri Mar 7 13:23:10 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 7 Mar 2014 11:23:10 -0700 Subject: Tuples and immutability In-Reply-To: <4piSu.17150$NC.10985@fx27.am4> References: <4piSu.17150$NC.10985@fx27.am4> Message-ID: On Fri, Mar 7, 2014 at 4:51 AM, Alister wrote: > I would think it would be better if the exception was thrown before the > assignment to the list took place > simply seeing that a modification action was being applied to a tupple > should be enough. > this would alert the programmer to the fact that he was trying something > that may have undesired consequences Then the behavior of tuples would be inconsistent with other immutable types. This can't be applied generally, because the Python interpreter doesn't generally know whether a given type is supposed to be immutable or not. From ian.g.kelly at gmail.com Fri Mar 7 13:37:10 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 7 Mar 2014 11:37:10 -0700 Subject: Is their a command to view code? In-Reply-To: References: Message-ID: On Fri, Mar 7, 2014 at 10:55 AM, NexusRAwesome1995 . wrote: > I am making a text based aventure game for my assignment and a friends test > run has somehow saved over the entire code file and now im using an earlier > version of the code. I have 0 idea if there is anyway to look at the code > using the IDLE and i need to do it to see how i fixed the fatal error left > behind by a friend. My on computer backup has not worked and the backup on > my memory stick also has the same problem. > If anyone knows of a way to get my code back i will be grateful as this is > my 1st project and i'm not that used to the syntax. > the item added is the outcome of what happened. Sorry, Python doesn't keep the source code in memory. If the game is still running in the interpreter, you can ask it for the source code of a particular code object, but it implements this by opening the source file and reading it in. Since you've overwritten the file, the source code would be wrong. The best that you could do in this case would be to disassemble the code objects using the dis.dis() function, and then try to reverse-engineer the Python code from the byte code. If the interpreter is no longer running, then there is nothing you can do. For the future, I strongly recommend using a version control system, such as the free and relatively lightweight Mercurial. Then when you have these kinds of mishaps all you have to do is check the most recent version of the code out of the repository again. You should of course continue to create backups as well, in case of more disastrous events (although memory sticks are far too failure-prone to be considered a reliable backup solution IMO). From joel.goldstick at gmail.com Fri Mar 7 13:46:03 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 7 Mar 2014 13:46:03 -0500 Subject: Is their a command to view code? In-Reply-To: References: Message-ID: On Mar 7, 2014 1:16 PM, "NexusRAwesome1995 ." wrote: > > I am making a text based aventure game for my assignment and a friends test run has somehow saved over the entire code file and now im using an earlier version of the code. I have 0 idea if there is anyway to look at the code using the IDLE and i need to do it to see how i fixed the fatal error left behind by a friend. My on computer backup has not worked and the backup on my memory stick also has the same problem. > If anyone knows of a way to get my code back i will be grateful as this is my 1st project and i'm not that used to the syntax. > the item added is the outcome of what happened. > You will be better off asking on python tutor list. However, go back to the source you have and debug it > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From teddybubu at gmail.com Fri Mar 7 15:27:27 2014 From: teddybubu at gmail.com (teddybubu at gmail.com) Date: Fri, 7 Mar 2014 12:27:27 -0800 (PST) Subject: extract from json Message-ID: I can't find any example on how to do this. I have a json file like so: {"bostock":[{"url":"http://bl.ocks.org/mbostock/9360565","title":"titleplaceholder","date":"dateplaceholder"}, {"url":"http://bl.ocks.org/mbostock/9265674","title":"titleplaceholder","date":"dateplaceholder"}, {"url":"http://bl.ocks.org/mbostock/9265467","title":"titleplaceholder","date":"dateplaceholder"}, {"url":"http://bl.ocks.org/mbostock/9234731","title":"titleplaceholder","date":"dateplaceholder"}, {"url":"http://bl.ocks.org/mbostock/9232962","title":"titleplaceholder","date":"dateplaceholder"}, this goes on for more than 700 entries. only thing unique is the number at the end of the url. I am going to load the url in python, get the date and title and write it in the json itself. Right now I am stuck on just reading the url in the json. Here is my code: import json with open("bostock.json") as json_file: json_data = json.load(json_file) print(json_data) I have tried json_data[0], json_data.url and a few others I forget right now and it does not seem to work. I have already figured out how to get the title and date. First things first: How can i just get the url for each line of the above json file? From nad at acm.org Fri Mar 7 15:47:15 2014 From: nad at acm.org (Ned Deily) Date: Fri, 07 Mar 2014 12:47:15 -0800 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> Message-ID: In article , Wesley wrote: > Then, how to make python get debug symbols? > > Install python from source with some special configure options? If your distribution doesn't have a debug version of Python and you need to build your own, add --with-pydebug to your ./configure options. See: ./configure --help -- Ned Deily, nad at acm.org From kevin.p.dwyer at gmail.com Fri Mar 7 16:05:15 2014 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 07 Mar 2014 21:05:15 +0000 Subject: extract from json References: Message-ID: teddybubu at gmail.com wrote: > I can't find any example on how to do this. > I have a json file like so: > {"bostock": [{"url":"http://bl.ocks.org/mbostock/9360565","title":"titleplaceholder","date":"dateplaceholder"}, > {"url":"http://bl.ocks.org/mbostock/9265674","title":"titleplaceholder","date":"dateplaceholder"}, > {"url":"http://bl.ocks.org/mbostock/9265467","title":"titleplaceholder","date":"dateplaceholder"}, > {"url":"http://bl.ocks.org/mbostock/9234731","title":"titleplaceholder","date":"dateplaceholder"}, > {"url":"http://bl.ocks.org/mbostock/9232962","title":"titleplaceholder","date":"dateplaceholder"}, > > this goes on for more than 700 entries. only thing unique is the number at > the end of the url. I am going to load the url in python, get the date and > title and write it in the json itself. Right now I am stuck on just > reading the url in the json. Here is my code: > > import json > > with open("bostock.json") as json_file: > json_data = json.load(json_file) > print(json_data) > > I have tried json_data[0], json_data.url and a few others I forget right > now and it does not seem to work. > > I have already figured out how to get the title and date. > First things first: How can i just get the url for each line of the above > json file? Hello Try: Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import json >>> with open('/tmp/bostock.json') as f: ... json_data = json.load(f) ... >>> json_data {u'bostock': [{u'url': u'http://bl.ocks.org/mbostock/9360565', u'date': u'dateplaceholder', u'title': u'titleplaceholder'}, {u'url': u'http://bl.ocks.org/mbostock/9265674', u'date': u'dateplaceholder', u'title': u'titleplaceholder'}, {u'url': u'http://bl.ocks.org/mbostock/9265467', u'date': u'dateplaceholder', u'title': u'titleplaceholder'}, {u'url': u'http://bl.ocks.org/mbostock/9234731', u'date': u'dateplaceholder', u'title': u'titleplaceholder'}, {u'url': u'http://bl.ocks.org/mbostock/9232962', u'date': u'dateplaceholder', u'title': u'titleplaceholder'}]} >>> urls = [x['url'] for x in json_data['bostock']] >>> urls [u'http://bl.ocks.org/mbostock/9360565', u'http://bl.ocks.org/mbostock/9265674', u'http://bl.ocks.org/mbostock/9265467', u'http://bl.ocks.org/mbostock/9234731', u'http://bl.ocks.org/mbostock/9232962'] Python loads the json in the file into a dictionary. In this case, the dictionary has a single key, 'bostock', and the value in the dictionary for that key is a list (of dictionaries). To get the urls, you need to get the list json_data['bostock'] and then iterate over it's elements, getting the value for the key url for each one. This is what the list comprehension [x['url'] for x in json_data['bostock']] does. I hope that helps, Kev From drsalists at gmail.com Fri Mar 7 19:15:36 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 7 Mar 2014 16:15:36 -0800 Subject: Assertions are bad, m'kay? In-Reply-To: <5319a975$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <5319a975$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 7, 2014 at 3:11 AM, Steven D'Aprano wrote: > > Assertions are not bad! They're just misunderstood and abused. > You should read this guy's blog post on when to use assert: > > http://import-that.dreamwidth.org/676.html Nice article. BTW, what about: if value >= 3: raise AssertionError('value must be >= 3') ? From ben+python at benfinney.id.au Fri Mar 7 19:22:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 08 Mar 2014 11:22:21 +1100 Subject: Assertions are bad, m'kay? References: <5319a975$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <857g85wncy.fsf@benfinney.id.au> Dan Stromberg writes: > BTW, what about: > > if value >= 3: > raise AssertionError('value must be >= 3') That would be very confusing, since it would only appear when the value is >= 3. Were you making some other point? -- \ ?If this is your first visit to the USSR, you are welcome to | `\ it.? ?hotel room, Moscow | _o__) | Ben Finney From irmen.NOSPAM at xs4all.nl Fri Mar 7 19:26:05 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 08 Mar 2014 01:26:05 +0100 Subject: Assertions are bad, m'kay? In-Reply-To: References: <5319a975$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <531a639b$0$2843$e4fe514c@news.xs4all.nl> On 8-3-2014 1:15, Dan Stromberg wrote: > On Fri, Mar 7, 2014 at 3:11 AM, Steven D'Aprano > wrote: > >> >> Assertions are not bad! They're just misunderstood and abused. > >> You should read this guy's blog post on when to use assert: >> >> http://import-that.dreamwidth.org/676.html > > Nice article. > > BTW, what about: > > if value >= 3: > raise AssertionError('value must be >= 3') > > ? I don't think this qualifies as an assertion. Also, because AssertionError is documented as "Raised when an assert statement fails", I would never use it myself explicitly like this. You should use ValueError instead (or a more precise exception such as IndexError, if appropriate). Irmen From missive at hotmail.com Fri Mar 7 20:16:34 2014 From: missive at hotmail.com (Lee Harr) Date: Sat, 8 Mar 2014 05:46:34 +0430 Subject: Function and turtle help Message-ID: > I am completely new to programming so thanks for any help! Not sure it will help, and hopefully I am not self-promoting too much, but this may be of interest to you: http://pynguin.googlecode.com/ http://code.google.com/p/pynguin/wiki/StartProgramming I am interested in feedback from new programmers. From swdunning at cox.net Fri Mar 7 20:25:30 2014 From: swdunning at cox.net (Scott W Dunning) Date: Fri, 7 Mar 2014 18:25:30 -0700 Subject: Function and turtle help In-Reply-To: References: Message-ID: <76432E92-D563-4F97-A1C7-9F9178184428@cox.net> On Mar 7, 2014, at 6:16 PM, Lee Harr wrote: >> I am completely new to programming so thanks for any help! > > Not sure it will help, and hopefully I am not self-promoting too much, > but this may be of interest to you: > > http://pynguin.googlecode.com/ > > http://code.google.com/p/pynguin/wiki/StartProgramming > Awesome! Looks fun, I?ll definitely check it out and let you know!! Scott From greg.ewing at canterbury.ac.nz Fri Mar 7 21:17:31 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 08 Mar 2014 15:17:31 +1300 Subject: Tuples and immutability In-Reply-To: References: Message-ID: Duncan Booth wrote: > Is there any reason why tuples need to throw an exception on assigning to > the element if the old value and new value are the same object? It would make introspection misleading, because tuples would have a __setitem__ method event though they don't actually support item assignment. Also, it would solve the problem for tuples in particular, but not for any other immutable type -- they would all have to implement the same behaviour independently to enjoy the benefit. Here's another idea: If the __iadd__ method returns the same object, *and* the LHS doesn't have a __setitem__ method, then do nothing instead of raising an exception. Peter Otten wrote: > Traceback (most recent call last): > File "", line 2, in > File "", line 4, in __setitem__ > TypeError: 257 is not 257 > > I'm not sure "help" is the right word here ;) I don't think that's a problem, because the use case being addressed is where the object performs in-place modification and always returns itself. Any object that doesn't return itself is not modifying in-place, even if the returned object happens to be equal to the original one. -- Greg From teddybubu at gmail.com Fri Mar 7 22:02:03 2014 From: teddybubu at gmail.com (teddybubu at gmail.com) Date: Fri, 7 Mar 2014 19:02:03 -0800 (PST) Subject: extract from json In-Reply-To: References: Message-ID: <0d5a61a6-f765-4865-bc2f-cc34291dffd3@googlegroups.com> On Friday, March 7, 2014 3:05:15 PM UTC-6, Kev Dwyer wrote: > wrote: > > I can't find any example on how to do this. > > > I have a json file like so: > > > {"bostock":[{"url":"http://bl.ocks.org/mbostock/9360565","title":"titleplaceholder","date":"dateplaceholder"},{"url":"http://bl.ocks.org/mbostock/9265674","title":"titleplaceholder","date":"dateplaceholder"},{"url":"http://bl.ocks.org/mbostock/9265467","title":"titleplaceholder","date":"dateplaceholder"},{"url":"http://bl.ocks.org/mbostock/9234731","title":"titleplaceholder","date":"dateplaceholder"},{"url":"http://bl.ocks.org/mbostock/9232962","title":"titleplaceholder","date":"dateplaceholder"}, > > this goes on for more than 700 entries. only thing unique is the number at > > > the end of the url. I am going to load the url in python, get the date and > > > title and write it in the json itself. Right now I am stuck on just > > > reading the url in the json. Here is my code: > > import json > > with open("bostock.json") as json_file: > > > json_data = json.load(json_file) > > > print(json_data) > > I have tried json_data[0], json_data.url and a few others I forget right > > > now and it does not seem to work. > > I have already figured out how to get the title and date. > > > First things first: How can i just get the url for each line of the above > > > json file? > Hello > Try: > > Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>> import json > > >>> with open('/tmp/bostock.json') as f: > > ... json_data = json.load(f) > >>> json_data > {u'bostock': [{u'url': u'http://bl.ocks.org/mbostock/9360565', u'date': > u'dateplaceholder', u'title': u'titleplaceholder'}, {u'url': > u'http://bl.ocks.org/mbostock/9265674', u'date': u'dateplaceholder', > u'title': u'titleplaceholder'}, {u'url': > u'http://bl.ocks.org/mbostock/9265467', u'date': u'dateplaceholder', > > u'title': u'titleplaceholder'}, {u'url': > > u'http://bl.ocks.org/mbostock/9234731', u'date': u'dateplaceholder', > u'title': u'titleplaceholder'}, {u'url': > u'http://bl.ocks.org/mbostock/9232962', u'date': u'dateplaceholder', > u'title': u'titleplaceholder'}]} > >>> urls = [x['url'] for x in json_data['bostock']] > > >>> urls > > [u'http://bl.ocks.org/mbostock/9360565', > > u'http://bl.ocks.org/mbostock/9265674', > > u'http://bl.ocks.org/mbostock/9265467', > > u'http://bl.ocks.org/mbostock/9234731', > u'http://bl.ocks.org/mbostock/9232962'] > Python loads the json in the file into a dictionary. In this case, the > dictionary has a single key, 'bostock', and the value in the dictionary for > that key is a list (of dictionaries). > To get the urls, you need to get the list > json_data['bostock'] > and then iterate over it's elements, getting the value for the key url for > each one. > This is what the list comprehension > [x['url'] for x in json_data['bostock']] > does. > I hope that helps, > Kev Kev your the man. Thanks From thrinaxodon666 at gmail.com Fri Mar 7 22:21:16 2014 From: thrinaxodon666 at gmail.com (thrinaxodon666 at gmail.com) Date: Fri, 7 Mar 2014 19:21:16 -0800 (PST) Subject: extract from json In-Reply-To: References: Message-ID: On Friday, March 7, 2014 3:27:27 PM UTC-5, tedd... at gmail.com wrote: > I can't find any example on how to do this. > > I have a json file like so: > > {"bostock":[{"url":"http://bl.ocks.org/mbostock/9360565","title":"titleplaceholder","date":"dateplaceholder"}, > > {"url":"http://bl.ocks.org/mbostock/9265674","title":"titleplaceholder","date":"dateplaceholder"}, > > {"url":"http://bl.ocks.org/mbostock/9265467","title":"titleplaceholder","date":"dateplaceholder"}, > > {"url":"http://bl.ocks.org/mbostock/9234731","title":"titleplaceholder","date":"dateplaceholder"}, > > {"url":"http://bl.ocks.org/mbostock/9232962","title":"titleplaceholder","date":"dateplaceholder"}, > > > > this goes on for more than 700 entries. only thing unique is the number at the end of the url. I am going to load the url in python, get the date and title and write it in the json itself. > > Right now I am stuck on just reading the url in the json. Here is my code: > > > > import json > > > > with open("bostock.json") as json_file: > > json_data = json.load(json_file) > > print(json_data) > > > > I have tried json_data[0], json_data.url and a few others I forget right now and it does not seem to work. > > > > I have already figured out how to get the title and date. > > First things first: How can i just get the url for each line of the above json file? I think it's better if you f*ck off. From thrinaxodon666 at gmail.com Fri Mar 7 22:24:23 2014 From: thrinaxodon666 at gmail.com (thrinaxodon666 at gmail.com) Date: Fri, 7 Mar 2014 19:24:23 -0800 (PST) Subject: -- redacted -- Message-ID: <1b3148bd-dfa3-49e1-920d-9832e9f58501@googlegroups.com> -- redacted -- From wrw at mac.com Fri Mar 7 21:46:17 2014 From: wrw at mac.com (William Ray Wing) Date: Fri, 07 Mar 2014 21:46:17 -0500 Subject: Python programming In-Reply-To: <560e7dcc-6557-44b8-89f7-adaafa9f0e29@googlegroups.com> References: <201402112314.42370.gheskett@wdtv.com> <82055DB9-758F-4B4C-9993-FE4DA60E3D50@mac.com> <560e7dcc-6557-44b8-89f7-adaafa9f0e29@googlegroups.com> Message-ID: <4E03DD51-0D73-4FDD-BE60-DE060BD0B57C@mac.com> On Mar 7, 2014, at 1:03 PM, John Ladasky wrote: > > As for FORTRAN? This week, I actually downloaded an application which required a FORTRAN compiler. This is the only FORTRAN application I've ever needed. It's not old code, the first revision came out about 10 years ago. More than once, I have queried Google with the phrase "Why isn't FORTRAN dead yet?" For some reason, it lives on. I can't say that I understand why. > -- > https://mail.python.org/mailman/listinfo/python-list Well, I?d claim that for what it was designed for (FORTRAN stands for FORmula TRANslator after all), it is still pretty da*mn good. It generates extremely fast, robust code that requires much less debugging effort than the equivalent C or C++ requires. Most of the physicists I know still write FORTRAN, although they no longer do so exclusively. Of course, as has been pointed out, the HUGE code base of scientific and numerical analysis code that already exists in FORTRAN makes rewriting sort of a waste of grant (or company) money. -Bill From rosuav at gmail.com Fri Mar 7 22:49:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Mar 2014 14:49:38 +1100 Subject: extract from json In-Reply-To: References: Message-ID: On Sat, Mar 8, 2014 at 2:21 PM, wrote: > I think it's better if you (CENSORED) off. Teddybubu, please understand that the above comment is from a spammer and does not reflect the prevailing attitude of this list. I don't like to make content-free posts like this, but as you already have the answer you need, there's not a lot for me to add :) ChrisA From ian.g.kelly at gmail.com Fri Mar 7 23:17:14 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 7 Mar 2014 21:17:14 -0700 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Fri, Mar 7, 2014 at 7:17 PM, Gregory Ewing wrote: > Here's another idea: If the __iadd__ method returns the > same object, *and* the LHS doesn't have a __setitem__ > method, then do nothing instead of raising an exception. Maybe it doesn't have a __setitem__ because the object that was retrieved is computed rather than stored, and the result of the __iadd__ will simply be discarded. Somewhat contrived example: class LessThanFilter: def __init__(self, the_list): self._the_list = the_list def __getitem__(self, bound): return [x for x in self._the_list if x < bound] filter = LessThanFilter([10, 20, 30, 40, 50]) filter[25] += [15, 17, 23] Should that last line not raise an exception? The __iadd__ call will return the same object, and the LHS doesn't have a __setitem__ method. > I don't think that's a problem, because the use case > being addressed is where the object performs in-place > modification and always returns itself. Any object that > doesn't return itself is not modifying in-place, even > if the returned object happens to be equal to the > original one. I already mentioned this earlier in the thread, but a balanced binary tree might implement += as node insertion and then return a different object if the balancing causes the root node to change. From dieter at handshake.de Sat Mar 8 01:45:55 2014 From: dieter at handshake.de (dieter) Date: Sat, 08 Mar 2014 07:45:55 +0100 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> Message-ID: <87d2hx2noc.fsf@handshake.de> Wesley writes: > Install python from source with some special configure options? When I last generated Python from source, there was no need to do anything special to get debugging symbols (the option ("gcc") option "-g" was automatically included). From dieter at handshake.de Sat Mar 8 01:48:53 2014 From: dieter at handshake.de (dieter) Date: Sat, 08 Mar 2014 07:48:53 +0100 Subject: debugging on windows References: <5319CAC7.4010200@chamonix.reportlab.co.uk> Message-ID: <878usl2nje.fsf@handshake.de> Robin Becker writes: > Using > >> Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. > > to run a tkinter + pmw2 application I have the following error on windows xp sp3 > >> Unhandled exception at 0x1e0aebb8 in python.exe: 0xC0000005: Access violation reading location 0x00000048. This is a C level error -- likely some memory corruption. You will need a C level debugger to analyse the problem - and likely, it will not be easy. From marko at pacujo.net Sat Mar 8 03:34:06 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 08 Mar 2014 10:34:06 +0200 Subject: Balanced trees (was: Re: Tuples and immutability) References: Message-ID: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Ian Kelly : > I already mentioned this earlier in the thread, but a balanced binary > tree might implement += as node insertion and then return a different > object if the balancing causes the root node to change. True. Speaking of which, are there plans to add a balanced tree to the "batteries" of Python? Timers, cache aging and the like need it. I'm using my own AVL tree implementation, but I'm wondering why Python still doesn't have one. In fact, since asyncio has timers but Python doesn't have balanced trees, I'm led to wonder how good the asyncio implementation can be. Note that Java "batteries" include TreeMap. Marko From ian.g.kelly at gmail.com Sat Mar 8 06:03:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 8 Mar 2014 04:03:00 -0700 Subject: Balanced trees (was: Re: Tuples and immutability) In-Reply-To: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On Sat, Mar 8, 2014 at 1:34 AM, Marko Rauhamaa wrote: > Speaking of which, are there plans to add a balanced tree to the > "batteries" of Python? Timers, cache aging and the like need it. I'm > using my own AVL tree implementation, but I'm wondering why Python > still doesn't have one. None currently that I'm aware of. If you want to propose adding one, I suggest reading: http://docs.python.org/devguide/stdlibchanges.html > In fact, since asyncio has timers but Python doesn't have balanced > trees, I'm led to wonder how good the asyncio implementation can be. Peeking at the code, it appears to use a heapq-based priority queue. Why would a balanced binary tree be better? From marko at pacujo.net Sat Mar 8 06:26:28 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 08 Mar 2014 13:26:28 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: <87txb9szh7.fsf@elektro.pacujo.net> Ian Kelly : > Peeking at the code, it appears to use a heapq-based priority queue. > Why would a balanced binary tree be better? AFAIK, a heap queue doesn't allow for the deletion of a random element forcing you to leave the canceled timers in the queue to be deleted later. In a very typical scenario, networking entities start timers very frequently (depending on the load, maybe at 100..1000 Hz) but cancel virtually every one of them, leading to some wakeup churn and extra memory load. I don't know if the churn is better or worse than the tree balancing overhead. Imagine a web server that received HTTP connections. You might want to specify a 10-minute idle timeout for the connections. In the heapq timer implementation, your connection objects are kept in memory for 10 minutes even if they are closed gracefully because the canceled timer maintains a reference to the object. Of course, it may be that the heapq implementation sets the callback to None leaving only the minimal timer object lingering and waiting to come out of the digestive tract. Marko From andywu1206 at gmail.com Sat Mar 8 07:01:40 2014 From: andywu1206 at gmail.com (Harry Wood) Date: Sat, 8 Mar 2014 04:01:40 -0800 (PST) Subject: How to recovery the default "Library/Python/" folder on Mac? Message-ID: <789955cd-1a8d-4b95-8c98-44e635fca117@googlegroups.com> How to recovery the default "Library/Python/" folder on Mac? I delete it by some mistakes..., I have tried the following steps: - Step 1. Download and install Python DMG from Python.org . Result: There are no Python folders under Library after I installed the Python DMG. - Step 2. I tried to use " brew install python " in Terminal. Result: $ brew uninstall python Error: No such keg: What should I need to do now? Please give me some specific directions, Thanks. From nilsherolindemann at gmail.com Sat Mar 8 07:44:27 2014 From: nilsherolindemann at gmail.com (Nils-Hero Lindemann) Date: Sat, 8 Mar 2014 13:44:27 +0100 Subject: Critic: New Python Front Page Message-ID: <20140308134427.74581920.nilsherolindemann@gmail.com> Hi, (Please forgive (or correct) my mistakes, i am non native) http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ * Formatting bug * Needs breadcrumb navigation ("Where am i?") (i came there via http://theory.stanford.edu/~amitp/yapps/) * blue background makes top links invisible when i look on laptop screen from a 60% angle. Prefer white. * 1 third of space on y-axis is used for 15 navigation links and a search bar. * 1 third of space on x-axis is used for one sentence about and a link to PSF. * I can not easily get rid of this by using e.g. HackTheWeb (https://addons.mozilla.org/de/firefox/addon/hack-the-web/). Please compare with e.g. Wikipedia, it is easy there to isolate the main content. http://www.python.org/community/ That picture is scary. Regards, Nils -- Nils-Hero Lindemann From generalcosta at gmail.com Sat Mar 8 07:53:57 2014 From: generalcosta at gmail.com (JCosta) Date: Sat, 8 Mar 2014 04:53:57 -0800 (PST) Subject: Python performance Message-ID: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> I did some work in c# and java and I converted some application to Python; I noticed Python is much slower than the other languages. Is this normal ? Thanks From breamoreboy at yahoo.co.uk Sat Mar 8 08:13:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 08 Mar 2014 13:13:31 +0000 Subject: spam (wasRe: extract from json) In-Reply-To: References: Message-ID: On 08/03/2014 03:49, Chris Angelico wrote: > On Sat, Mar 8, 2014 at 2:21 PM, wrote: >> I think it's better if you (CENSORED) off. > > Teddybubu, please understand that the above comment is from a spammer > and does not reflect the prevailing attitude of this list. I don't > like to make content-free posts like this, but as you already have the > answer you need, there's not a lot for me to add :) > > ChrisA > This particular PITA of a spammer is one of the very few that I see on Thunderbird via gmane. I believe that Terry Reedy amongst others does a good job of keeping us relatively spam free. Thanks all. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sat Mar 8 08:19:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Mar 2014 00:19:05 +1100 Subject: spam (wasRe: extract from json) In-Reply-To: References: Message-ID: On Sun, Mar 9, 2014 at 12:13 AM, Mark Lawrence wrote: > On 08/03/2014 03:49, Chris Angelico wrote: >> >> On Sat, Mar 8, 2014 at 2:21 PM, wrote: >>> >>> I think it's better if you (CENSORED) off. >> >> >> Teddybubu, please understand that the above comment is from a spammer >> and does not reflect the prevailing attitude of this list. I don't >> like to make content-free posts like this, but as you already have the >> answer you need, there's not a lot for me to add :) >> >> ChrisA >> > > This particular PITA of a spammer is one of the very few that I see on > Thunderbird via gmane. I believe that Terry Reedy amongst others does a > good job of keeping us relatively spam free. Thanks all. Normally I ignore him (and yes, I see those posts too, in Gmail). Stand-alone posts aren't an issue. I just didn't want a new poster to see that reply go through unchallenged. ChrisA From rosuav at gmail.com Sat Mar 8 08:24:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Mar 2014 00:24:24 +1100 Subject: Python performance In-Reply-To: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> References: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> Message-ID: On Sat, Mar 8, 2014 at 11:53 PM, JCosta wrote: > I did some work in c# and java and I converted some application to Python; I noticed Python is much slower than the other languages. > > Is this normal ? > Thanks The first thing to look at is the conversion. If you convert idiomatic Java code into the nearest-equivalent Python, it won't be idiomatic Python, and it'll probably underperform. (This is especially true if you create a whole lot of objects, use long chains of classes with dots, and so on. Java follows dotted name chains at compile time, Python does at run time.) Another thing to consider is that Python, while very convenient, isn't always the fastest at heavy numerical computation. For that, there are some dedicated libraries, like NumPy, which can do that for you. But it's also worth checking whether the speed difference even matters. Are you able to see a real difference, as a human, or is this just benchmarks? It's not a problem for something to take 5ms in Python that would take 2ms in Java, if that time is spent responding to a user's click - the user won't see that difference! If you post a bit of code, we can help you to see what's going on. Best bit of code to post would be the slowest - and since you're talking about performance, you _have_ profiled your code and found which bit's the slowest, right? :) ChrisA From ned at nedbatchelder.com Sat Mar 8 08:31:31 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 08 Mar 2014 08:31:31 -0500 Subject: Critic: New Python Front Page In-Reply-To: <20140308134427.74581920.nilsherolindemann@gmail.com> References: <20140308134427.74581920.nilsherolindemann@gmail.com> Message-ID: On 3/8/14 7:44 AM, Nils-Hero Lindemann wrote: > Hi, > > (Please forgive (or correct) my mistakes, i am non native) > > http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ > * Formatting bug > * Needs breadcrumb navigation ("Where am i?") > (i came there via http://theory.stanford.edu/~amitp/yapps/) > * blue background makes top links invisible when i look on laptop > screen from a 60% angle. Prefer white. > * 1 third of space on y-axis is used for 15 navigation > links and a search bar. > * 1 third of space on x-axis is used for one sentence about and a link > to PSF. > * I can not easily get rid of this by using e.g. HackTheWeb > (https://addons.mozilla.org/de/firefox/addon/hack-the-web/). > Please compare with e.g. Wikipedia, it is easy there to isolate the > main content. > > http://www.python.org/community/ > That picture is scary. > > Regards, Nils > The source for the site is on github, and they are taking and resolving issues there: https://github.com/python/pythondotorg/issues -- Ned Batchelder, http://nedbatchelder.com From nispray at gmail.com Sat Mar 8 08:31:38 2014 From: nispray at gmail.com (Wesley) Date: Sat, 8 Mar 2014 05:31:38 -0800 (PST) Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> Message-ID: <25473c34-fbc6-4e81-ad6d-c86f12f7b72e@googlegroups.com> 1. install gdb from source with configure option --with-python 2. install python from source with configure option --with-pydebug 3. Got error in gdb here: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] (gdb) py-bt Undefined command: "py-bt". Try "help". (gdb) python >import libpython >end Traceback (most recent call last): File "", line 1, in File "/usr/local/share/gdb/python/libpython.py", line 49, in _type_size_t = gdb.lookup_type('size_t') gdb.error: No type named size_t. Error while executing Python code. (gdb) From nispray at gmail.com Sat Mar 8 08:32:30 2014 From: nispray at gmail.com (Wesley) Date: Sat, 8 Mar 2014 05:32:30 -0800 (PST) Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <87mwh2bi1v.fsf@handshake.de> Message-ID: <73e3cfa2-28d3-4647-8a7f-577e41dffbd1@googlegroups.com> python debuginfo is installed... Still,py-bt, py-locals.etc cannot read python frame From python.list at tim.thechases.com Sat Mar 8 08:40:48 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 8 Mar 2014 07:40:48 -0600 Subject: Python performance In-Reply-To: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> References: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> Message-ID: <20140308074048.3e7b1cd6@bigbox.christie.dr> On 2014-03-08 04:53, JCosta wrote: > I did some work in c# and java and I converted some application to > Python; I noticed Python is much slower than the other languages. > > Is this normal ? It depends. Did you write C#/Java in Python (i.e., use C# or Java idioms in Python), or did you write Pythonic code? Check your algorithms and storage classes for performance characteristics (if you used an O(1) algorithm/container in C#/Java but used an O(N) algorithm/container in Python) and make sure they match. What sorts of operations are you doing? Are you CPU-bound, I/O bound, or memory-bound? Have you profiled to see where the hot-spots are? Personally, I've found that most of my code is I/O-bound (disk or network), and that very rarely has CPU been much of a problem (usually checking my algorithm if there's trouble; occasionally I'm stuck with an O(N^2) algorithm and no language-choice. For some folks, using one of the specialty-math libraries can speed up numeric processing. If I know that memory could be an issue, I tend to switch to a disk-based data-stores to head off any trouble. -tkc From ned at nedbatchelder.com Sat Mar 8 09:11:26 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 08 Mar 2014 09:11:26 -0500 Subject: Critic: New Python Front Page In-Reply-To: References: <20140308134427.74581920.nilsherolindemann@gmail.com> Message-ID: On 3/8/14 8:31 AM, Ned Batchelder wrote: > On 3/8/14 7:44 AM, Nils-Hero Lindemann wrote: >> Hi, >> >> (Please forgive (or correct) my mistakes, i am non native) >> >> http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ >> * Formatting bug >> * Needs breadcrumb navigation ("Where am i?") >> (i came there via http://theory.stanford.edu/~amitp/yapps/) >> * blue background makes top links invisible when i look on laptop >> screen from a 60% angle. Prefer white. >> * 1 third of space on y-axis is used for 15 navigation >> links and a search bar. >> * 1 third of space on x-axis is used for one sentence about and a link >> to PSF. >> * I can not easily get rid of this by using e.g. HackTheWeb >> (https://addons.mozilla.org/de/firefox/addon/hack-the-web/). >> Please compare with e.g. Wikipedia, it is easy there to isolate the >> main content. >> >> http://www.python.org/community/ >> That picture is scary. >> >> Regards, Nils >> > > The source for the site is on github, and they are taking and resolving > issues there: https://github.com/python/pythondotorg/issues > Also, I agree with you about the picture on the community page: https://github.com/python/pythondotorg/issues/265 -- Ned Batchelder, http://nedbatchelder.com From breamoreboy at yahoo.co.uk Sat Mar 8 09:14:12 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 08 Mar 2014 14:14:12 +0000 Subject: gdb unable to read python frame information In-Reply-To: <73e3cfa2-28d3-4647-8a7f-577e41dffbd1@googlegroups.com> References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <87mwh2bi1v.fsf@handshake.de> <73e3cfa2-28d3-4647-8a7f-577e41dffbd1@googlegroups.com> Message-ID: On 08/03/2014 13:32, Wesley wrote: > python debuginfo is installed... > Still,py-bt, py-locals.etc cannot read python frame > If you don't provide context people are less likely to help you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Sat Mar 8 09:44:23 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Mar 2014 14:44:23 GMT Subject: Assertions are bad, m'kay? References: <5319a975$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <531b2cc7$0$29985$c3e8da3$5496439d@news.astraweb.com> On Fri, 07 Mar 2014 16:15:36 -0800, Dan Stromberg wrote: > On Fri, Mar 7, 2014 at 3:11 AM, Steven D'Aprano > wrote: > > >> Assertions are not bad! They're just misunderstood and abused. > >> You should read this guy's blog post on when to use assert: >> >> http://import-that.dreamwidth.org/676.html > > Nice article. > > BTW, what about: > > if value >= 3: > raise AssertionError('value must be >= 3') > > ? The error message is misleading. But you've probably noticed that by now :-) What about it? Since it's missing any context, it could be a good use of an exception or a terrible use. Where does value come from? Why is there a restriction on the value? As I see it, there are likely two reasons for writing such a test: 1) You're testing a value that comes from the user, or some library you don't control; or 2) You're testing some internal invariant, a contract between two parts of your own code, a piece of internal logic, etc. In the first case, I don't think you should raise AssertionError. A ValueError would be more appropriate. In the second case, using an assert might be better, since that gives you the opportunity to remove it at compile-time, if you choose. -- Steven D'Aprano http://import-that.dreamwidth.org/ From nispray at gmail.com Sat Mar 8 09:55:32 2014 From: nispray at gmail.com (Wesley) Date: Sat, 8 Mar 2014 06:55:32 -0800 (PST) Subject: gdb unable to read python frame information In-Reply-To: <25473c34-fbc6-4e81-ad6d-c86f12f7b72e@googlegroups.com> References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <25473c34-fbc6-4e81-ad6d-c86f12f7b72e@googlegroups.com> Message-ID: <6b804c8f-2bd9-45cb-95e4-6c8524de5a28@googlegroups.com> Now I use gdb python -p then, import libpython py-bt is null, py-locals raise here: Unable to locate python frame What's going on... From nispray at gmail.com Sat Mar 8 10:01:52 2014 From: nispray at gmail.com (Wesley) Date: Sat, 8 Mar 2014 07:01:52 -0800 (PST) Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <87mwh2bi1v.fsf@handshake.de> <73e3cfa2-28d3-4647-8a7f-577e41dffbd1@googlegroups.com> Message-ID: <6dc8a38d-d3a6-44fd-8f39-f73cea1ac4c1@googlegroups.com> So, let me clarify here, in order to try, I get a clean machine. Centos 6.5 64bit. Now , I try this: 1. install gdb 7.7 from source , with configure option --with-python 2. install python 2.6.6 from source, with configure option --with-pydebug 3. run a python script 4. from command line, gdb python -p to attach the running script 5. within gdb, issue python, import libpython, end no errors 6. py-bt outputs nothing, py-locals says Unable to locate python frame here is the snippet: [root at localhost Python-2.6.6]# gdb python 52315 GNU gdb (GDB) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-unknown-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from python...done. Attaching to program: /home/nipen/test/Python-2.6.6/python, process 52315 Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done. Loaded symbols for /lib64/ld-linux-x86-64.so.2 0x00000030a98e15c3 in ?? () (gdb) bt #0 0x00000030a98e15c3 in ?? () #1 0x00007f4cf68d1219 in ?? () #2 0x0000000000000000 in ?? () (gdb) py-bt Undefined command: "py-bt". Try "help". (gdb) python >import libpython >end (gdb) py-bt (gdb) (gdb) py-locals Unable to locate python frame (gdb) Unable to locate python frame From nilsherolindemann at gmail.com Sat Mar 8 10:52:22 2014 From: nilsherolindemann at gmail.com (Nils-Hero Lindemann) Date: Sat, 8 Mar 2014 16:52:22 +0100 Subject: Critic: New Python Front Page References: <20140308134427.74581920.nilsherolindemann@gmail.com> Message-ID: <20140308165222.60e40d06.nilsherolindemann@gmail.com> Hello, > The source for the site is on github, and they are taking and resolving > issues there: https://github.com/python/pythondotorg/issues Thanks for pointing me to the right place. I copypasted my mail to ... https://github.com/python/pythondotorg/issues/266 also i added a comment to ... https://github.com/python/pythondotorg/issues/265 Regards, Nils -- Nils-Hero Lindemann From jsf80238 at gmail.com Sat Mar 8 11:55:35 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 8 Mar 2014 09:55:35 -0700 Subject: How to extract contents of inner text of html tag? In-Reply-To: <1393697458.5147.YahooMailNeo@web126004.mail.ne1.yahoo.com> References: <1393697458.5147.YahooMailNeo@web126004.mail.ne1.yahoo.com> Message-ID: > for line in all_kbd: > if line.string == None: I modified your code slightly: for line in all_kbd: print(line) sys.exit() if line.string == None: Running the new script yields: $ python shibly.py cp -v --remove-destination /usr/share/zoneinfo/ \ /etc/localtime Meaning that all_kbd=soup.find_all('kbd') yields only a single string, not multiple strings as I'm guessing you expected. You might also consider running your program as: python -m pdb your_program.py From marko at pacujo.net Sat Mar 8 12:48:14 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 08 Mar 2014 19:48:14 +0200 Subject: Python performance References: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> Message-ID: <87lhwktwdd.fsf@elektro.pacujo.net> JCosta : > I did some work in c# and java and I converted some application to > Python; I noticed Python is much slower than the other languages. > > Is this normal ? Yes. The main reason is the dot notation, which in C through Java is implemented by the compiler as a fixed offset to a memory structure. High-level programming languages such as Python implement it through a hash table lookup. That's the price of keeping everything dynamic: the structural content is free to change any time during the execution of the program. I have heard (but not experienced first-hand) that some ingenious heuristic optimizations have made Common Lisp code come close to C-style performance. Google was gung ho about repeating the feat on Python, but seem to have given up. The second costly specialty of Python is the way objects are instantiated. Each object is given a "personalized" dispatch table. That costs time and memory but is extremely nice for the programmer. In a word, Python is a godsend if its performance is good enough for your needs. For other needs, you have other programming languages, and you buy the performance dearly. Java is a great programming language, as C# must also be. However, for the needs where you need to drop out of Python, one must ask if you weren't better off writing some core parts in C and integrating them with Python. Marko From generalcosta at gmail.com Sat Mar 8 13:30:18 2014 From: generalcosta at gmail.com (JCosta) Date: Sat, 8 Mar 2014 10:30:18 -0800 (PST) Subject: Python performance In-Reply-To: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> References: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> Message-ID: S?bado, 8 de Mar?o de 2014 12:53:57 UTC, JCosta escreveu: > I did some work in c# and java and I converted some application to Python; I noticed Python is much slower than the other languages. > > > > Is this normal ? > > Thanks ............... Thanks for the help (Chris, Tim and Marko) and it?s clear now for me ... From breamoreboy at yahoo.co.uk Sat Mar 8 13:49:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 08 Mar 2014 18:49:38 +0000 Subject: Python performance In-Reply-To: References: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> Message-ID: On 08/03/2014 18:30, JCosta wrote: > S?bado, 8 de Mar?o de 2014 12:53:57 UTC, JCosta escreveu: >> I did some work in c# and java and I converted some application to Python; I noticed Python is much slower than the other languages. >> >> >> >> Is this normal ? >> >> Thanks > > ............... > > Thanks for the help (Chris, Tim and Marko) and it?s clear now for me ... > You might like to check this out https://wiki.python.org/moin/PythonSpeed/PerformanceTips Would you also please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing and single line paragraphs above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ned at nedbatchelder.com Sat Mar 8 13:56:04 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 08 Mar 2014 13:56:04 -0500 Subject: Python performance In-Reply-To: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> References: <290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com> Message-ID: On 3/8/14 7:53 AM, JCosta wrote: > I did some work in c# and java and I converted some application to Python; I noticed Python is much slower than the other languages. > > Is this normal ? > Thanks > Your question, and the replies so far in this thread, have overlooked the difference between language and implementation. Python as a language has no inherent speed. Your question is really about CPython, the reference and most-common implementation of the language. It interprets virtual-machine bytecode, and so will pay a penalty for compute-bound code. But PyPy is another implementation of Python. It uses a JIT to produce native code automatically, and can impressively speed up the execution of Python programs. You should give it a try to see if it will help in your situation. -- Ned Batchelder, http://nedbatchelder.com From drsalists at gmail.com Sat Mar 8 14:58:25 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 8 Mar 2014 11:58:25 -0800 Subject: Balanced trees (was: Re: Tuples and immutability) In-Reply-To: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On Sat, Mar 8, 2014 at 12:34 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> I already mentioned this earlier in the thread, but a balanced binary >> tree might implement += as node insertion and then return a different >> object if the balancing causes the root node to change. > > True. > > Speaking of which, are there plans to add a balanced tree to the > "batteries" of Python? Timers, cache aging and the like need it. I'm > using my own AVL tree implementation, but I'm wondering why Python > still doesn't have one. I think it'd probably be a good idea to add one or more balanced binary trees to the standard library. But I suspect it's been tried before, and didn't happen. It might be good to add an _un_balanced tree too, since they do quite well with random keys. Here's a performance comparison I did of a bunch of tree types in Python: http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-01/ From breamoreboy at yahoo.co.uk Sat Mar 8 15:37:58 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 08 Mar 2014 20:37:58 +0000 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On 08/03/2014 19:58, Dan Stromberg wrote: > On Sat, Mar 8, 2014 at 12:34 AM, Marko Rauhamaa wrote: >> Ian Kelly : >> >>> I already mentioned this earlier in the thread, but a balanced binary >>> tree might implement += as node insertion and then return a different >>> object if the balancing causes the root node to change. >> >> True. >> >> Speaking of which, are there plans to add a balanced tree to the >> "batteries" of Python? Timers, cache aging and the like need it. I'm >> using my own AVL tree implementation, but I'm wondering why Python >> still doesn't have one. > > I think it'd probably be a good idea to add one or more balanced > binary trees to the standard library. But I suspect it's been tried > before, and didn't happen. It might be good to add an _un_balanced > tree too, since they do quite well with random keys. > > Here's a performance comparison I did of a bunch of tree types in Python: > http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-01/ > I've found this link useful http://kmike.ru/python-data-structures/ I also don't want all sorts of data structures added to the Python library. I believe that there are advantages to leaving specialist data structures on pypi or other sites, plus it means Python in a Nutshell can still fit in your pocket and not a 40 ton articulated lorry, unlike the Java equivalent. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Sat Mar 8 16:21:34 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 08 Mar 2014 23:21:34 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: <87eh2ctmht.fsf@elektro.pacujo.net> Mark Lawrence : > I believe that there are advantages to leaving specialist data > structures on pypi or other sites, plus it means Python in a Nutshell > can still fit in your pocket and not a 40 ton articulated lorry, > unlike the Java equivalent. An ordered map is a foundational data structure as opposed to, say, a priority queue, let alone something like urllib2. If I had to choose between a hash table and AVL (or RB) tree in the standard library, it would definitely have to be the latter. It is more generally usable, has fewer corner cases and probably has an equal performance even in hash tables' sweet spot. Marko From john_ladasky at sbcglobal.net Sat Mar 8 17:06:28 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 8 Mar 2014 14:06:28 -0800 (PST) Subject: Python programming In-Reply-To: References: <201402112314.42370.gheskett@wdtv.com> <82055DB9-758F-4B4C-9993-FE4DA60E3D50@mac.com> <560e7dcc-6557-44b8-89f7-adaafa9f0e29@googlegroups.com> Message-ID: <15357a67-2359-4c56-afcb-f8b90fbedb8e@googlegroups.com> On Friday, March 7, 2014 4:38:54 PM UTC-8, Dennis Lee Bieber wrote: > On Fri, 7 Mar 2014 10:03:35 -0800 (PST), John Ladasky > declaimed the following: > >> More than once, I have queried Google with the phrase "Why isn't FORTRAN >> dead yet?" For some reason, it lives on. I can't say that I understand >> why. > > Well, for one thing, no one can justify rewriting all the numerics > libraries... LAPACK http://en.wikipedia.org/wiki/LAPACK , NEC-2 > http://en.wikipedia.org/wiki/Numerical_Electromagnetics_Code (and likely > NEC-4). I have used Numpy for years, and I'm pretty sure that Numpy calls LAPACK under the hood. But if that is true, then I get LAPACK as a pre-compiled binary. I didn't need a FORTRAN compiler until last week. If one or two specialized applications are the only reason we are keeping a 50 year-old programming language around, I would be tempted to rewrite those applications -- in C, at least. C's not dead yet! (It's just resting!) From roy at panix.com Sat Mar 8 17:22:49 2014 From: roy at panix.com (Roy Smith) Date: Sat, 08 Mar 2014 17:22:49 -0500 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> Message-ID: In article <87eh2ctmht.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > If I had to choose between a hash table and AVL (or RB) tree in the > standard library, it would definitely have to be the latter. It is more > generally usable, has fewer corner cases and probably has an equal > performance even in hash tables' sweet spot. The C++ folks made that decision, and people spent the next 10 years complaining, "Why is there no hash table in STL?" From greg.ewing at canterbury.ac.nz Sat Mar 8 19:40:28 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 09 Mar 2014 13:40:28 +1300 Subject: Tuples and immutability In-Reply-To: References: Message-ID: Ian Kelly wrote: > class LessThanFilter: > > def __init__(self, the_list): > self._the_list = the_list > > def __getitem__(self, bound): > return [x for x in self._the_list if x < bound] > > > filter = LessThanFilter([10, 20, 30, 40, 50]) > filter[25] += [15, 17, 23] > > Should that last line not raise an exception? In this case it will fail to catch what is probably an error, but you can't expect the language to find all your bugs for you. If you wrote the same bug this way: filter[25].extend([15, 17, 23]) it wouldn't be caught either. What's happening is that we're trying to use the syntax a += b to mean two different things: 1) Shorthand for a = a + b 2) A way of expressing an in-place modification, such as a.extend(b) Case (2) is not really an assignment at all, so arguably it shouldn't require the LHS to support assignment. -- Greg From greg.ewing at canterbury.ac.nz Sat Mar 8 19:45:04 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 09 Mar 2014 13:45:04 +1300 Subject: Tuples and immutability In-Reply-To: References: Message-ID: Ian Kelly wrote: > I already mentioned this earlier in the thread, but a balanced binary > tree might implement += as node insertion and then return a different > object if the balancing causes the root node to change. That would be a really bad way to design a binary tree implementation. What if there is another reference to the tree somewhere? It's still going to be referring to the old root object, and will have an incoherent view of the data -- partly old and partly new. If you're going to have a mutable tree, it needs to be encapsulated in a stable top-level object. -- Greg From drsalists at gmail.com Sat Mar 8 20:31:26 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 8 Mar 2014 17:31:26 -0800 Subject: Balanced trees In-Reply-To: <87eh2ctmht.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> Message-ID: On Sat, Mar 8, 2014 at 1:21 PM, Marko Rauhamaa wrote: > If I had to choose between a hash table and AVL (or RB) tree in the > standard library, it would definitely have to be the latter. It is more > generally usable, has fewer corner cases and probably has an equal > performance even in hash tables' sweet spot. Actually, in the performance comparison I mentioned previously, I compared Python dict's to a bunch of different balanced trees and one unbalanced tree. The dictionary was much faster, though granted, it was the only one in C. That URL again: http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-01/ From drsalists at gmail.com Sat Mar 8 21:08:38 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 8 Mar 2014 18:08:38 -0800 Subject: How is unicode implemented behind the scenes? Message-ID: OK, I know that Unicode data is stored in an encoding on disk. But how is it stored in RAM? I realize I shouldn't write code that depends on any relevant implementation details, but knowing some of the more common implementation options would probably help build an intuition for what's going on internally. I've heard that characters are no longer all c bytes wide internally, so is it sometimes utf-8? Thanks. From python at mrabarnett.plus.com Sat Mar 8 21:40:28 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 09 Mar 2014 02:40:28 +0000 Subject: How is unicode implemented behind the scenes? In-Reply-To: References: Message-ID: <531BD49C.4090602@mrabarnett.plus.com> On 2014-03-09 02:08, Dan Stromberg wrote: > OK, I know that Unicode data is stored in an encoding on disk. > > But how is it stored in RAM? > > I realize I shouldn't write code that depends on any relevant > implementation details, but knowing some of the more common > implementation options would probably help build an intuition for > what's going on internally. > > I've heard that characters are no longer all c bytes wide internally, > so is it sometimes utf-8? > No. From Python 3.3, it's an array of 1, 2 or 4 bytes per codepoint. In Python terms: if all(c <= '\xFF' for c in string): use 1 byte per codepoint elif all(c <= '\xFFFF' for c in string): use 2 bytes per codepoint else: use 4 bytes per codepoint From ian.g.kelly at gmail.com Sat Mar 8 21:39:50 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 8 Mar 2014 19:39:50 -0700 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Sat, Mar 8, 2014 at 5:40 PM, Gregory Ewing wrote: > Ian Kelly wrote: >> >> class LessThanFilter: >> >> def __init__(self, the_list): >> self._the_list = the_list >> >> def __getitem__(self, bound): >> return [x for x in self._the_list if x < bound] >> >> >> filter = LessThanFilter([10, 20, 30, 40, 50]) >> filter[25] += [15, 17, 23] >> >> Should that last line not raise an exception? > > > In this case it will fail to catch what is probably an error, > but you can't expect the language to find all your bugs for > you. If you wrote the same bug this way: > > filter[25].extend([15, 17, 23]) > > it wouldn't be caught either. > > What's happening is that we're trying to use the syntax > a += b to mean two different things: > > 1) Shorthand for a = a + b > > 2) A way of expressing an in-place modification, such > as a.extend(b) > > Case (2) is not really an assignment at all, so arguably > it shouldn't require the LHS to support assignment. In my view the second one is wrong. a += b should be understood as being equivalent to a = a + b, but with the *possible* and by no means guaranteed optimization that the operation may be performed in-place. In fact, if you read the documentation for lists, you may notice that while they clearly cover the + operator and the extend method, they do not explicitly document the list class's += operator. So although I'm not entirely sure whether it is intentional or not, and I would be quite surprised if some implementation were actually to differ on this point, the language does *not* from what I can see guarantee that the += operator on lists is equivalent to calling .extend. That having been said, code that uses += and relies on the operation to be performed in-place should be considered buggy. If you need the operation to be performed in-place, then use in-place methods like list.extend. If you need the operation not to be performed in-place, then use a = a + b. If you're ambivalent on the in-place issue and just want to write polymorphic code, that's when you should consider using +=. From python at mrabarnett.plus.com Sat Mar 8 21:42:46 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 09 Mar 2014 02:42:46 +0000 Subject: How is unicode implemented behind the scenes? In-Reply-To: <531BD49C.4090602@mrabarnett.plus.com> References: <531BD49C.4090602@mrabarnett.plus.com> Message-ID: <531BD526.4040206@mrabarnett.plus.com> On 2014-03-09 02:40, MRAB wrote: > On 2014-03-09 02:08, Dan Stromberg wrote: >> OK, I know that Unicode data is stored in an encoding on disk. >> >> But how is it stored in RAM? >> >> I realize I shouldn't write code that depends on any relevant >> implementation details, but knowing some of the more common >> implementation options would probably help build an intuition for >> what's going on internally. >> >> I've heard that characters are no longer all c bytes wide internally, >> so is it sometimes utf-8? >> > No. > > From Python 3.3, it's an array of 1, 2 or 4 bytes per codepoint. > > In Python terms: > > if all(c <= '\xFF' for c in string): > use 1 byte per codepoint > elif all(c <= '\xFFFF' for c in string): > use 2 bytes per codepoint > else: > use 4 bytes per codepoint > Oops! That should, of course, be: if all(c <= '\xFF' for c in string): use 1 byte per codepoint elif all(c <= '\uFFFF' for c in string): use 2 bytes per codepoint else: use 4 bytes per codepoint From steve+comp.lang.python at pearwood.info Sat Mar 8 21:50:49 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Mar 2014 02:50:49 GMT Subject: How is unicode implemented behind the scenes? References: Message-ID: <531bd709$0$29985$c3e8da3$5496439d@news.astraweb.com> On Sat, 08 Mar 2014 18:08:38 -0800, Dan Stromberg wrote: > OK, I know that Unicode data is stored in an encoding on disk. > > But how is it stored in RAM? There are various common ways to store Unicode strings in RAM. The first, UTF-16, treats every character [aside: technically, a code point] as a double byte rather than a single byte. So the letter "A" is stored as two bytes 0x0041 (or 0x4100 depending on your platform's byte order). Using two bytes allows for a maximum of 65536 different characters, *way* too few for the whole Unicode character set, so UTF-16 has an escaping mechanism where characters beyond ordinal 0xFFFF are stored as *two* "characters" (again, actually, code points) called surrogate pairs. That means that a sequence of (say) four human-readable characters may, depending on those characters, take up anything from eight bytes to sixteen bytes, and you cannot tell which until you walk through the sequence inspecting each pair of bytes: while there are still pairs of bytes to inspect: c = get_next_pair() if is_low_surrogate(c): error elif is_high_surrogate(c): d = get_next_pair() if not is_low_surrogate(d): error print make_char_from_surrogate_pair(c, d) else: print make_char_from_double_byte(c) So UTF-16 is a *variable width* (could be 1 unit, could be 2 units) *double byte* encoding (each unit is two bytes). Prior to Python 3.3, using UTF-16 was an option when compiling Python's source code. Such versions of the interpreter are called "narrow builds". Another option is UTF-32. UTF-32 uses four bytes for every character. That's enough to store every Unicode character, and then some, so there are no surrogate pairs needed. But every character takes up four bytes: "A" would be stored as 0x00000041 or 0x41000000. Although UTF-32 is faster than UTF-16, because you don't have to walk the string checking each individual pair of bytes to see if they are part of a surrogate, strings use up to twice as much memory as UTF-16 whether they need it or not. (And four times more memory than ASCII strings.) Prior to Python 3.3, UTF-32 was a build option too. Such versions of the interpreter are called "wide builds". Another option is to use UTF-8 internally. With UTF-8, every character uses between 1 and 4 bytes. By design, ASCII characters are stored using a single byte, the same byte they would have in old fashioned single-byte ASCII: the letter "A" is stored as 0x41. (The algorithm used by UTF-8 can continue up to six bytes, but there is no need to since there aren't that many Unicode characters.) Because it's variable-width, you have the same variable-width issues as UTF-16, only even more so, but because most common characters (at least for English speakers) use only 1 or 2 bytes, it's much more compact than either. No version of Python has, to my knowledge, used UTF-8 internally. Some other languages, such as Go and Haskell, do, and consequently string processing is slow for them. In Python 3.3, CPython introduced an internal scheme that gives the best of all worlds. When a string is created, Python uses a different implementation depending on the characters in the string: * If all the characters are ASCII or Latin-1, then the string uses a single byte per character. * If all the characters are no greater than ordinal value 0xFFFF, then UTF-16 is used. Because the characters are all below 0xFFFF, no surrogate pairs are required. * Only if there is at least one ord() greater than 0xFFFF does Python use UTF-32 for that string. The end result is that creating strings is slightly slower, as Python may have to inspect each character at most twice to decide what system to use. But memory use is much improved: Python has *many* strings (every function, method and class uses many strings in their implementation) and the memory savings can be considerable. Depending on your application and what you do with those strings, that may even lead to time savings as well as memory savings. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Sat Mar 8 21:55:25 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 8 Mar 2014 19:55:25 -0700 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Sat, Mar 8, 2014 at 5:45 PM, Gregory Ewing wrote: > Ian Kelly wrote: > >> I already mentioned this earlier in the thread, but a balanced binary >> tree might implement += as node insertion and then return a different >> object if the balancing causes the root node to change. > > > That would be a really bad way to design a binary tree > implementation. What if there is another reference to > the tree somewhere? It's still going to be referring to > the old root object, and will have an incoherent view > of the data -- partly old and partly new. > > If you're going to have a mutable tree, it needs to be > encapsulated in a stable top-level object. Well, as I parenthetically noted the first time I brought it up, "whether this is good design is tangential; it's a possible design". The language shouldn't be written such that only those designs deemed "good" by some external committee can be implemented. What you dismiss as "really bad" may be exactly what somebody else needs, and maybe they intend that there won't be other references. From rosuav at gmail.com Sat Mar 8 21:56:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Mar 2014 13:56:39 +1100 Subject: How is unicode implemented behind the scenes? In-Reply-To: References: Message-ID: On Sun, Mar 9, 2014 at 1:08 PM, Dan Stromberg wrote: > OK, I know that Unicode data is stored in an encoding on disk. > > But how is it stored in RAM? > > I realize I shouldn't write code that depends on any relevant > implementation details, but knowing some of the more common > implementation options would probably help build an intuition for > what's going on internally. > > I've heard that characters are no longer all c bytes wide internally, > so is it sometimes utf-8? > As of Python 3.3, it's as MRAB described. If you like, Python chooses between one of three (or four) encodings, based on what can handle the string: 1) ASCII (there are some minor differences with 7-bit strings, eg it knows the conversion to UTF-8 is the identity function) 2) Latin-1 3) UCS-2 4) UCS-4 This means that finding the Nth codepoint in a string is simply a matter of shifting N by either 0, 0, 1, or 2, and picking the right number of bytes from that position. You can read the gory details in PEP 393: http://www.python.org/dev/peps/pep-0393/ but the important bit here is the "kind", which is 01 for Latin-1, 10 for UCS-2, 11 for UCS-4. (The "ascii-only" flag is stored elsewhere.) There's a functionally-identical field in Pike's strings, called size_shift - 0 for ASCII or Latin-1, 1 for UCS-2, 2 for UCS-4. Whichever it is, it's really efficient - and as an added bonus, all those ASCII-only strings that scripts are full of (you know, words like "print" and "len" and "int") are stored compactly, so it's much tighter than the 3.2 builds, even narrow ones. It's pretty awesome! ChrisA From roy at panix.com Sat Mar 8 22:01:59 2014 From: roy at panix.com (Roy Smith) Date: Sat, 08 Mar 2014 22:01:59 -0500 Subject: How is unicode implemented behind the scenes? References: <531bd709$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <531bd709$0$29985$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > There are various common ways to store Unicode strings in RAM. > > The first, UTF-16. > [...] > Another option is UTF-32. > [...] > Another option is to use UTF-8 internally. > [...] > In Python 3.3, CPython introduced an internal scheme that gives the best > of all worlds. When a string is created, Python uses a different > implementation depending on the characters in the string: This was an excellent post, but I would take exception to the "best of all worlds" statement. I would put it a little less absolutely and say something like, "a good compromise for many common use cases". I would even go with, "... for most common use cases". But, there are situations where it loses. From rustompmody at gmail.com Sat Mar 8 22:12:28 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 8 Mar 2014 19:12:28 -0800 (PST) Subject: How is unicode implemented behind the scenes? In-Reply-To: <531bd709$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <531bd709$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, March 9, 2014 8:20:49 AM UTC+5:30, Steven D'Aprano wrote: > No version of Python has, to my knowledge, used UTF-8 internally. Some > other languages, such as Go and Haskell, do, and consequently string > processing is slow for them. Haskell: Its more like: "Heres the menu, take your pick" http://blog.ezyang.com/2010/08/strings-in-haskell/ From rosuav at gmail.com Sat Mar 8 22:19:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Mar 2014 14:19:00 +1100 Subject: How is unicode implemented behind the scenes? In-Reply-To: References: <531bd709$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 9, 2014 at 2:01 PM, Roy Smith wrote: > In article <531bd709$0$29985$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> There are various common ways to store Unicode strings in RAM. >> >> The first, UTF-16. >> [...] >> Another option is UTF-32. >> [...] >> Another option is to use UTF-8 internally. >> [...] >> In Python 3.3, CPython introduced an internal scheme that gives the best >> of all worlds. When a string is created, Python uses a different >> implementation depending on the characters in the string: > > This was an excellent post, but I would take exception to the "best of > all worlds" statement. I would put it a little less absolutely and say > something like, "a good compromise for many common use cases". I would > even go with, "... for most common use cases". But, there are > situations where it loses. It's universally good for string indexing/slicing on binary CPUs (there's no point using a 24-bit or 21-bit representation on an Intel-compatible CPU, even though they'd be just as good as UTC-32). It's not a compromise, so much as a recognition that Python offers convenient operators for indexing and slicing. If, on the other hand, Python fundamentally worked with U+0020 separated words (REXX has a whole set of word-based functions), then it might be better to represent strings as lists of words internally. Or if the string operations are primarily based on the transitions between Unicode types of "space" and "non-space", which would be more likely these days, then something of that sort would still work. Anyway, it's based on the operations the language makes convenient, and which will therefore be common and expected to be fast: those are the operations to optimize for. If the only thing you ever do with a string is iterate sequentially over its characters, UTF-8 would be the perfect representation. It's compact, you can concatenate strings without re-encoding, and it iterates forwards easily. But it sucks for "give me character #142857 from this string", so it's a bad choice for Python. ChrisA From ned at nedbatchelder.com Sat Mar 8 22:48:51 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 08 Mar 2014 22:48:51 -0500 Subject: How is unicode implemented behind the scenes? In-Reply-To: References: Message-ID: On 3/8/14 9:08 PM, Dan Stromberg wrote: > OK, I know that Unicode data is stored in an encoding on disk. > > But how is it stored in RAM? > > I realize I shouldn't write code that depends on any relevant > implementation details, but knowing some of the more common > implementation options would probably help build an intuition for > what's going on internally. > > I've heard that characters are no longer all c bytes wide internally, > so is it sometimes utf-8? > > Thanks. > In abstract terms, a Unicode string is a sequence of integers (code points). There are lots of ways to store a sequence of integers. In Python 2.x, it's either a vector of 16-bit ints, or 32-bit ints. These are the Unicode representations known as UTF-16 and UTF-32, respectively, and which you have depends on whether you have a "narrow" or "wide" build of Python. You can tell the difference by examining sys.maxunicode, which is 65535 (narrow) or 1114111 (wide). In Python 3.3, the representation was changed from narrow/wide to the so-called Flexible String Representation which others here have described. It uses either 1-, 2-, or 4-bytes per code point, depending on the set of code points in the string. It's specified in PEP 393: http://legacy.python.org/dev/peps/pep-0393/ -- Ned Batchelder, http://nedbatchelder.com From nispray at gmail.com Sat Mar 8 22:49:10 2014 From: nispray at gmail.com (Wesley) Date: Sat, 8 Mar 2014 19:49:10 -0800 (PST) Subject: gdb unable to read python frame information In-Reply-To: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> Message-ID: <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> Anybody has suggestions? This really makes me crazy... From dan at tombstonezero.net Sun Mar 9 00:46:06 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 9 Mar 2014 05:46:06 +0000 (UTC) Subject: How is unicode implemented behind the scenes? References: <531bd709$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 09 Mar 2014 03:50:49 +0000, Steven D'Aprano wrote: > ... UTF-16 ... the letter "A" is stored as two bytes 0x0041 (or 0x4100 > depending on your platform's byte order) ... At the risk of being pedantic, the two bytes are 0x00 and 0x41, and the order in which they appear in memory depends on your platform and even your particular view of that platform (do stacks grow up or down? are addresses of higher memory larger or smaller?). > ... UTF-32 ... "A" would be stored as 0x00000041 or 0x41000000 ... Or even some other sequence if you're on a PDP-11. See . But you knew that. ;-) Pedantic'ly yours, Dan From tnajun at gmail.com Sun Mar 9 03:52:58 2014 From: tnajun at gmail.com (Jun Tanaka) Date: Sun, 9 Mar 2014 16:52:58 +0900 Subject: process.popen with Japanese args => UTF8 JAVA Message-ID: Hello, I have tried to process.popen to run java program with Japanese language. test.java is compiled with utf8 '???' below means Japanese in Japanese. but it does not work. Anyone who knows this matter well. Please help. Jun >>>>>>>>python code>>>>>>>>>>>>> sentence = '???' filename = 'japanese' java_file = 'test' cmd = "java {0} {1} {2}".format(java_file, sentence, filename) proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) >>>>>>>>python code end>>>>>>>>>>>>>>>>>>>>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sun Mar 9 04:12:20 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 09 Mar 2014 19:12:20 +1100 Subject: process.popen with Japanese args => UTF8 JAVA References: Message-ID: <8538irx02j.fsf@benfinney.id.au> Jun Tanaka writes: > I have tried to process.popen to run java program with Japanese language. > test.java is compiled with utf8 > '???' below means Japanese in Japanese. > but it does not work. What are you expecting to happen, and what happens instead? What error (if any) is produced? From wxjmfauth at gmail.com Sun Mar 9 04:39:32 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 9 Mar 2014 00:39:32 -0800 (PST) Subject: How is unicode implemented behind the scenes? In-Reply-To: References: Message-ID: <751cbe5d-ebbe-4f4e-93a9-6012667297e3@googlegroups.com> Le dimanche 9 mars 2014 03:40:28 UTC+1, MRAB a ?crit?: > On 2014-03-09 02:08, Dan Stromberg wrote: > > > OK, I know that Unicode data is stored in an encoding on disk. > > > > > > But how is it stored in RAM? > > > > > > I realize I shouldn't write code that depends on any relevant > > > implementation details, but knowing some of the more common > > > implementation options would probably help build an intuition for > > > what's going on internally. > > > > > > I've heard that characters are no longer all c bytes wide internally, > > > so is it sometimes utf-8? > > > > > No. > > > > From Python 3.3, it's an array of 1, 2 or 4 bytes per codepoint. > > > > In Python terms: > > > > if all(c <= '\xFF' for c in string): > > use 1 byte per codepoint > > elif all(c <= '\xFFFF' for c in string): > > use 2 bytes per codepoint > > else: > > use 4 bytes per codepoint A very, very nice recursive mathematical absurdity. jmf From cs at zip.com.au Sun Mar 9 05:09:26 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 9 Mar 2014 20:09:26 +1100 Subject: process.popen with Japanese args => UTF8 JAVA In-Reply-To: References: Message-ID: <20140309090926.GA16238@cskk.homeip.net> On 09Mar2014 16:52, Jun Tanaka wrote: > I have tried to process.popen to run java program with Japanese language. > test.java is compiled with utf8 > '???' below means Japanese in Japanese. > but it does not work. Anyone who knows this matter well. Please help. > Jun > > >>>>>>>>python code>>>>>>>>>>>>> > sentence = '???' > filename = 'japanese' > java_file = 'test' > cmd = "java {0} {1} {2}".format(java_file, sentence, filename) > proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, > stderr=subprocess.STDOUT) > >>>>>>>>python code end>>>>>>>>>>>>>>>>>>>>>> Echoing Ben, what errors do you get? And what expected? But examining your program, it is possible that any error messages are being concealed. Details below. Firstly, I am surprised that the sentence comes before the java file "test". Try swapping them. Also, if you're doing this in a UNIX system of some kind, and therefore your "cmd" variable is actually a shell comment, turn on tracing. Change this: cmd = "java {0} {1} {2}" to this: cmd = "set -x; java {0} {1} {2}" It will show you the command the shell executes. Finally, why do you have: stderr=subprocess.STDOUT Normally you would leave stderr alone, so that error messages show on your terminal. In particular, the shell tracing an any error messages from your java command go to stderr, and grabbing stderr like that may well be concealing any useful error messages you ought to be seeing. I would be inclined to simple get rid of your stderr= parameter and see what shows up. Cheers, -- Cameron Simpson Processes are like potatoes. - NCR device driver manual From marko at pacujo.net Sun Mar 9 05:17:33 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 09 Mar 2014 11:17:33 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> Message-ID: <874n374toy.fsf@elektro.pacujo.net> Roy Smith : > Marko Rauhamaa wrote: > >> If I had to choose between a hash table and AVL (or RB) tree in the >> standard library, it would definitely have to be the latter. It is more >> generally usable, has fewer corner cases and probably has an equal >> performance even in hash tables' sweet spot. > > The C++ folks made that decision, and people spent the next 10 years > complaining, "Why is there no hash table in STL?" Well, luckily, nobody should need to choose. Even STL has an unordered_map now. Marko From marko at pacujo.net Sun Mar 9 05:27:24 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 09 Mar 2014 11:27:24 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> Message-ID: <87zjkz3eo3.fsf@elektro.pacujo.net> Dan Stromberg : > On Sat, Mar 8, 2014 at 1:21 PM, Marko Rauhamaa wrote: >> If I had to choose between a hash table and AVL (or RB) tree in the >> standard library, it would definitely have to be the latter. It is more >> generally usable, has fewer corner cases and probably has an equal >> performance even in hash tables' sweet spot. > > Actually, in the performance comparison I mentioned previously, I > compared Python dict's to a bunch of different balanced trees and one > unbalanced tree. The dictionary was much faster, though granted, it > was the only one in C. Yes, that is one major detail. There must be many more. Marko From marko at pacujo.net Sun Mar 9 05:35:31 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 09 Mar 2014 11:35:31 +0200 Subject: Tuples and immutability References: Message-ID: <87vbvn3eak.fsf@elektro.pacujo.net> Ian Kelly : > In my view the second one is wrong. a += b should be understood as > being equivalent to a = a + b, but with the *possible* and by no means > guaranteed optimization that the operation may be performed in-place. Some call it an optimization, others call it a side effect. Anyway, that's how it has been explicitly defined in the language specification so that's the reality whether one likes it or not. Marko From rustompmody at gmail.com Sun Mar 9 06:32:23 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 9 Mar 2014 03:32:23 -0700 (PDT) Subject: How is unicode implemented behind the scenes? In-Reply-To: <751cbe5d-ebbe-4f4e-93a9-6012667297e3@googlegroups.com> References: <751cbe5d-ebbe-4f4e-93a9-6012667297e3@googlegroups.com> Message-ID: On Sunday, March 9, 2014 2:09:32 PM UTC+5:30, wxjm... at gmail.com wrote: > Le dimanche 9 mars 2014 03:40:28 UTC+1, MRAB a ?crit?: > > On 2014-03-09 02:08, Dan Stromberg wrote: > > > OK, I know that Unicode data is stored in an encoding on disk. > > > But how is it stored in RAM? > > > I realize I shouldn't write code that depends on any relevant > > > implementation details, but knowing some of the more common > > > implementation options would probably help build an intuition for > > > what's going on internally. > > > I've heard that characters are no longer all c bytes wide internally, > > > so is it sometimes utf-8? > > No. > > From Python 3.3, it's an array of 1, 2 or 4 bytes per codepoint. > > In Python terms: > > if all(c <= '\xFF' for c in string): > > use 1 byte per codepoint > > elif all(c <= '\xFFFF' for c in string): > > use 2 bytes per codepoint > > else: > > use 4 bytes per codepoint > A very, very nice recursive mathematical absurdity. As a profoundly astute mathematician v v n r m a can be parsed in 42 different ways (5th catalan number) Which parse did you intend? From georg at python.org Sun Mar 9 06:39:14 2014 From: georg at python.org (Georg Brandl) Date: Sun, 09 Mar 2014 11:39:14 +0100 Subject: [RELEASED] Python 3.3.5 Message-ID: <531C44D2.9070501@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm very happy to announce the release of Python 3.3.5. Python 3.3.5 includes fixes for these important issues: * a 3.3.4 regression in zipimport (see http://bugs.python.org/issue20621) * a 3.3.4 regression executing scripts with a coding declared and Windows newlines (see http://bugs.python.org/issue20731) * potential DOS using compression codecs in bytes.decode() (see http://bugs.python.org/issue19619 and http://bugs.python.org/issue20404) and also fixes quite a few other bugs. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in the 3.3 series, see http://docs.python.org/3.3/whatsnew/3.3.html To download Python 3.3.5 visit: http://www.python.org/downloads/release/python-335/ This is a production release, please report any bugs to http://bugs.python.org/ The final release is scheduled one week from now. Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iEYEARECAAYFAlMcRNEACgkQN9GcIYhpnLAVqACeMoOOuuNX5iP6at9zbIZDnkqK idwAoKb2FxAJlirhs2BmdESEaQiqBDJd =smeC -----END PGP SIGNATURE----- From nispray at gmail.com Sun Mar 9 10:46:10 2014 From: nispray at gmail.com (Wesley) Date: Sun, 9 Mar 2014 07:46:10 -0700 (PDT) Subject: Problem using py-bt, py-locals, etc. during GDB debugging [solved] In-Reply-To: References: <20121206213941.GA5363@mshroyer-d> Message-ID: I hit a problem alike yours. Cannot fix according your method. Here is snippet: root at localhost python]# gdb python 40290 GNU gdb (GDB) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-unknown-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from python...done. Attaching to program: /usr/local/bin/python, process 40290 Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done. Loaded symbols for /lib64/ld-linux-x86-64.so.2 0x00000030a98e15c3 in ?? () (gdb) py-bt (gdb) py-list Unable to locate python frame (gdb) py-locals Unable to locate python frame (gdb) I use gdb 7.7, python 2.6.6 , centos 6.5 64bit Any suggestion? Thanks. Wesley From breamoreboy at yahoo.co.uk Sun Mar 9 10:53:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 09 Mar 2014 14:53:05 +0000 Subject: How is unicode implemented behind the scenes? In-Reply-To: References: <751cbe5d-ebbe-4f4e-93a9-6012667297e3@googlegroups.com> Message-ID: On 09/03/2014 10:32, Rustom Mody wrote: > On Sunday, March 9, 2014 2:09:32 PM UTC+5:30, wxjm... at gmail.com wrote: >> Le dimanche 9 mars 2014 03:40:28 UTC+1, MRAB a ?crit : >>> On 2014-03-09 02:08, Dan Stromberg wrote: >>>> OK, I know that Unicode data is stored in an encoding on disk. >>>> But how is it stored in RAM? >>>> I realize I shouldn't write code that depends on any relevant >>>> implementation details, but knowing some of the more common >>>> implementation options would probably help build an intuition for >>>> what's going on internally. >>>> I've heard that characters are no longer all c bytes wide internally, >>>> so is it sometimes utf-8? >>> No. >>> From Python 3.3, it's an array of 1, 2 or 4 bytes per codepoint. >>> In Python terms: >>> if all(c <= '\xFF' for c in string): >>> use 1 byte per codepoint >>> elif all(c <= '\xFFFF' for c in string): >>> use 2 bytes per codepoint >>> else: >>> use 4 bytes per codepoint > >> A very, very nice recursive mathematical absurdity. > > As a profoundly astute mathematician > v v n r m a > can be parsed in 42 different ways (5th catalan number) > > Which parse did you intend? > > Please don't feed this particular troll, it's a complete waste of time. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Sun Mar 9 10:57:37 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 09 Mar 2014 14:57:37 +0000 Subject: gdb unable to read python frame information In-Reply-To: <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> Message-ID: On 09/03/2014 03:49, Wesley wrote: > Anybody has suggestions? > > This really makes me crazy... > What makes you crazy? You keep sending messages with no context. We might be smart, but we're not (yet :) mind readers. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From varsha1901 at gmail.com Sun Mar 9 13:56:38 2014 From: varsha1901 at gmail.com (Varsha Holla) Date: Sun, 9 Mar 2014 10:56:38 -0700 (PDT) Subject: image processing in python and opencv Message-ID: <512500c5-3c2f-49c8-861f-5755991c3abb@googlegroups.com> i have no idea how to retrieve indexed images stored in ordered dictionary, using its values like : blue,green,red mean along with contrast, energy, homogeneity and correlation. as i have calculated the euclidean distance and i don't know how to display the images which are similar. thanks in advance From joshua at landau.ws Sun Mar 9 13:54:46 2014 From: joshua at landau.ws (Joshua Landau) Date: Sun, 9 Mar 2014 17:54:46 +0000 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On 28 February 2014 14:43, Chris Angelico wrote: > On Sat, Mar 1, 2014 at 1:41 AM, Joshua Landau wrote: >> Would it be better to add a check here, such that if this gets raised >> to the top-level it includes a warning ("Addition was inplace; >> variable probably mutated despite assignment failure")? > > That'd require figuring out whether or not the variable was actually > mutated, and that's pretty hard to work out. It does not. First, the "warning" is actually an attachment to the exception so is only shown if the exception is uncaught. This should basically never happen in working code. The warning exists only to remove likely misunderstanding in these odd cases. Even if "x = (1,); x[0] += 1" warned "addition was inplace; possible mutation occurred" or whatever phrasing you wish, this would only cause a quick check of the results. From rosuav at gmail.com Sun Mar 9 14:13:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Mar 2014 05:13:24 +1100 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Mon, Mar 10, 2014 at 4:54 AM, Joshua Landau wrote: > On 28 February 2014 14:43, Chris Angelico wrote: >> On Sat, Mar 1, 2014 at 1:41 AM, Joshua Landau wrote: >>> Would it be better to add a check here, such that if this gets raised >>> to the top-level it includes a warning ("Addition was inplace; >>> variable probably mutated despite assignment failure")? >> >> That'd require figuring out whether or not the variable was actually >> mutated, and that's pretty hard to work out. > > It does not. First, the "warning" is actually an attachment to the > exception so is only shown if the exception is uncaught. This should > basically never happen in working code. The warning exists only to > remove likely misunderstanding in these odd cases. > > Even if "x = (1,); x[0] += 1" warned "addition was inplace; possible > mutation occurred" or whatever phrasing you wish, this would only > cause a quick check of the results. I think I see what you're saying here. But ignore "top-level"; this should just be a part of the exception message, no matter what. Otherwise things that recreate the REPL (like IDLE) or that isolate two sections of the code (like a web server framework) wouldn't get the benefit, because the exception's not caught at the true top-level. >>> x=1, >>> x[0]+=0 Traceback (most recent call last): File "", line 1, in x[0]+=0 TypeError: 'tuple' object does not support item assignment What you're saying is that this should notice that it's doing an augmented assignment and give some more text. This can be done; all you need to do is catch the error and reraise it with more info: >>> try: x[0]+=0 except TypeError as e: if 'does not support item assignment' in e.args[0]: raise TypeError(e.args[0]+"\nAugmented assignment used; mutation may have occurred.") from None raise Traceback (most recent call last): File "", line 5, in raise TypeError(e.args[0]+"\nAugmented assignment used; mutation may have occurred.") from None TypeError: 'tuple' object does not support item assignment Augmented assignment used; mutation may have occurred. Now you can look at writing an import hook that does an AST transform, locating every instance of item assignment and wrapping it like that. It's certainly possible. I'm not sure how much benefit you'd get, but it could be done. ChrisA From tjreedy at udel.edu Sun Mar 9 14:37:27 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 09 Mar 2014 14:37:27 -0400 Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> Message-ID: On 3/9/2014 10:57 AM, Mark Lawrence wrote: > On 09/03/2014 03:49, Wesley wrote: >> Anybody has suggestions? Don't expect crazy things. Send suggestions to the right place (a gdb list for a gdb enhancement). >> This really makes me crazy... > What makes you crazy? The supposed fact that GnuDeBug does not understand Python frames on the stack. > You keep sending messages with no context. We > might be smart, but we're not (yet :) mind readers. But we do speculate ;-) -- Terry Jan Reedy From tjreedy at udel.edu Sun Mar 9 14:50:10 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 09 Mar 2014 14:50:10 -0400 Subject: Problem using py-bt, py-locals, etc. during GDB debugging [solved] In-Reply-To: References: <20121206213941.GA5363@mshroyer-d> Message-ID: On 3/9/2014 10:46 AM, Wesley wrote: > I hit a problem alike yours. > Cannot fix according your method. > > Here is snippet: > root at localhost python]# gdb python 40290 > GNU gdb (GDB) 7.7 > Copyright (C) 2014 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. Type "show copying" > and "show warranty" for details. > This GDB was configured as "x86_64-unknown-linux-gnu". > Type "show configuration" for configuration details. > For bug reporting instructions, please see: > . > Find the GDB manual and other documentation resources online at: > . > For help, type "help". > Type "apropos word" to search for commands related to "word"... > Reading symbols from python...done. > Attaching to program: /usr/local/bin/python, process 40290 > Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done. > Loaded symbols for /lib64/ld-linux-x86-64.so.2 > 0x00000030a98e15c3 in ?? () If you want people to attend to your posts and help, don't post line after line of irrelevant boilderplate. > (gdb) py-bt > (gdb) py-list > Unable to locate python frame > (gdb) py-locals > Unable to locate python frame > (gdb) > > I use gdb 7.7, python 2.6.6 , centos 6.5 64bit > Any suggestion? See above. -- Terry Jan Reedy From gherron at digipen.edu Sun Mar 9 15:09:25 2014 From: gherron at digipen.edu (Gary Herron) Date: Sun, 09 Mar 2014 12:09:25 -0700 Subject: image processing in python and opencv In-Reply-To: <512500c5-3c2f-49c8-861f-5755991c3abb@googlegroups.com> References: <512500c5-3c2f-49c8-861f-5755991c3abb@googlegroups.com> Message-ID: <531CBC65.7030700@digipen.edu> On 03/09/2014 10:56 AM, Varsha Holla wrote: > i have no idea how to retrieve indexed images stored in ordered dictionary, using its values like : blue,green,red mean along with contrast, energy, homogeneity and correlation. as i have calculated the euclidean distance and i don't know how to display the images which are similar. > > thanks in advance Sorry, but is there a question here? And is it Python related? (This is a Python list, right?) And while you're rewording this as a Python related question, please take the time to state the problem clearly. You'll get more help if you take the time to tell us what you are doing. For instance: You have a dictionary. How was it created? What values are stored in it? What keys were used? Why is it an "ordered" dictionary? Is your trouble retrieving images, computing keys for similar images, or displaying images? (All three seem to be implied above.) Gary Herron From joshua at landau.ws Sun Mar 9 15:57:48 2014 From: joshua at landau.ws (Joshua Landau) Date: Sun, 9 Mar 2014 19:57:48 +0000 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On 9 March 2014 18:13, Chris Angelico wrote: > I think I see what you're saying here. But ignore "top-level"; this > should just be a part of the exception message, no matter what. I don't think I was clear, but yes. That. > What you're saying is that this should notice that it's doing an > augmented assignment and give some more text. This can be done; all > you need to do is catch the error and reraise it with more info: > [...] > Now you can look at writing an import hook that does an AST transform, > locating every instance of item assignment and wrapping it like that. > It's certainly possible. I'm not sure how much benefit you'd get, but > it could be done. I would probably implement it closer to home. Inside tuple.__getitem__, there would be something like if context_is_augmented_assignment(): raise TypeError(message+warning) else: raise TypeError(message) which would have much lower technical costs. It does depend on how costly "context_is_augmented_assignment" is, though. A speed argument is totally valid, but I'd hope it's possible to work around. From rosuav at gmail.com Sun Mar 9 16:06:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Mar 2014 07:06:37 +1100 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Mon, Mar 10, 2014 at 6:57 AM, Joshua Landau wrote: > I would probably implement it closer to home. Inside > tuple.__getitem__, there would be something like > > if context_is_augmented_assignment(): > raise TypeError(message+warning) > else: > raise TypeError(message) > > which would have much lower technical costs. It does depend on how > costly "context_is_augmented_assignment" is, though. A speed argument > is totally valid, but I'd hope it's possible to work around. Yeah, I'm not sure there's an easy way to tell the tuple that it's an augmented assignment. You might be able to look at the backtrace, but that's tricky. In theory, you could catch TypeError after any augmented assignment, and check several things: 1) The target object does not have __setitem__ 2) The object being manipulated does have __iadd__ (or corresponding for others) 3) The error is that item assignment is not possible and if all three are the case, then add a tag to the message. But this is best done by catching the exception. Otherwise you'd be limiting this to tuples and lists; not to mention that this is really only an issue of error reporting, and correct code shouldn't be tripping this at all. So put a check like that at the place where you display the error, if you can. The AST transform that I described would also work. But I really think it's not worth the effort. If you get this error, understand that it may have consequences. ChrisA From drsalists at gmail.com Sun Mar 9 17:20:11 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 9 Mar 2014 14:20:11 -0700 Subject: Balanced trees In-Reply-To: <87zjkz3eo3.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 9, 2014 at 1:27 AM, Marko Rauhamaa wrote: > Dan Stromberg : > >> On Sat, Mar 8, 2014 at 1:21 PM, Marko Rauhamaa wrote: >>> If I had to choose between a hash table and AVL (or RB) tree in the >>> standard library, it would definitely have to be the latter. It is more >>> generally usable, has fewer corner cases and probably has an equal >>> performance even in hash tables' sweet spot. >> >> Actually, in the performance comparison I mentioned previously, I >> compared Python dict's to a bunch of different balanced trees and one >> unbalanced tree. The dictionary was much faster, though granted, it >> was the only one in C. > > Yes, that is one major detail. There must be many more. This is not just a detail: O(1) tends to be beat O(logn) pretty easily for large n. From marko at pacujo.net Sun Mar 9 17:32:54 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 09 Mar 2014 23:32:54 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> Message-ID: <87a9czrrax.fsf@elektro.pacujo.net> Dan Stromberg : > This is not just a detail: O(1) tends to be beat O(logn) pretty easily > for large n. There is no O(1) hash table. Marko From ml at fam-goebel.de Sun Mar 9 17:29:43 2014 From: ml at fam-goebel.de (Ulrich Goebel) Date: Sun, 09 Mar 2014 22:29:43 +0100 Subject: Making Labels from python Message-ID: <531CDD47.8020304@fam-goebel.de> Hallo, has anybody an idea how to make small formated documents redy to print with python? I would like to print address labels as firstname lastname street and number cip and city The best should be to form a PDF and send it to the label printer. So the PDF could be given the pagesize (labelsize) and a minimum format (boldface). But may be there is another light-weight-format besides PDF? Any idea? Ulrich -- Ulrich Goebel Paracelsusstr. 120, 53177 Bonn From drsalists at gmail.com Sun Mar 9 17:37:39 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 9 Mar 2014 14:37:39 -0700 Subject: Balanced trees In-Reply-To: <87a9czrrax.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 9, 2014 at 2:32 PM, Marko Rauhamaa wrote: > Dan Stromberg : > >> This is not just a detail: O(1) tends to be beat O(logn) pretty easily >> for large n. > > There is no O(1) hash table. http://stackoverflow.com/questions/2771368/can-hash-tables-really-be-o1 From marko at pacujo.net Sun Mar 9 17:43:55 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 09 Mar 2014 23:43:55 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> Message-ID: <8761nnrqsk.fsf@elektro.pacujo.net> Dan Stromberg : > On Sun, Mar 9, 2014 at 2:32 PM, Marko Rauhamaa wrote: >> There is no O(1) hash table. > > http://stackoverflow.com/questions/2771368/can-hash-tables-really-be-o1 Please elaborate. Marko From greg.ewing at canterbury.ac.nz Sun Mar 9 18:03:59 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 10 Mar 2014 11:03:59 +1300 Subject: Tuples and immutability In-Reply-To: References: Message-ID: Ian Kelly wrote: > In my view the second one is wrong. a += b should be understood as > being equivalent to a = a + b, but with the *possible* and by no means > guaranteed optimization that the operation may be performed in-place. This interpretation is at odds with the Language Reference, section 6.2.1, Augmented Assignment Statements: "An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a similar, but not exactly equal effect... when possible, the actual operation is performed in-place, meaning that rather than creating a new object and assigning that to the target, the old object is modified instead." Note that it says "when possible", not "if the implementation feels like it". > In fact, if you read the documentation for lists, you may notice that > while they clearly cover the + operator and the extend method, they do > not explicitly document the list class's += operator. The "when possible" clause, together with the fact that lists are mutable, implies that it *will* be done in-place. There is no need to document all the in-place operators explicitly for every type. -- Greg From gary.herron at islandtraining.com Sun Mar 9 18:01:11 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 09 Mar 2014 15:01:11 -0700 Subject: Making Labels from python In-Reply-To: <531CDD47.8020304@fam-goebel.de> References: <531CDD47.8020304@fam-goebel.de> Message-ID: <531CE4A7.9060203@islandtraining.com> On 03/09/2014 02:29 PM, Ulrich Goebel wrote: > Hallo, > > has anybody an idea how to make small formated documents redy to print > with python? > > I would like to print address labels as > > firstname lastname > street and number > cip and city > > The best should be to form a PDF and send it to the label printer. So > the PDF could be given the pagesize (labelsize) and a minimum format > (boldface). But may be there is another light-weight-format besides PDF? > > Any idea? > > Ulrich > > The usual python library for generating PDFs is reportlab. It has some formating capabilities that my be useful for you. Gary Herron From drsalists at gmail.com Sun Mar 9 18:08:20 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 9 Mar 2014 15:08:20 -0700 Subject: Balanced trees In-Reply-To: <8761nnrqsk.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <8761nnrqsk.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 9, 2014 at 2:43 PM, Marko Rauhamaa wrote: > Dan Stromberg : > >> On Sun, Mar 9, 2014 at 2:32 PM, Marko Rauhamaa wrote: >>> There is no O(1) hash table. >> >> http://stackoverflow.com/questions/2771368/can-hash-tables-really-be-o1 > > Please elaborate. A hash table of fixed size is O(1) until you fill it so full that you start getting enough collisions to make it O(n), as one bucket becomes a linked list. This is because the hash function is O(1), and looking up a value in a C array is O(1). A more flexible hash table will not have a fixed size; instead it will grow itself as needed. This growth operation tends to be O(n), but happens vanishingly infrequently as the table grows, so it's still amortized O(1). From ben+python at benfinney.id.au Sun Mar 9 18:21:23 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 10 Mar 2014 09:21:23 +1100 Subject: Making Labels from python References: <531CDD47.8020304@fam-goebel.de> Message-ID: <85lhwjui70.fsf@benfinney.id.au> Ulrich Goebel writes: > has anybody an idea how to make small formated documents redy to print > with python? The most reliable ?ready to print? document formats are: * plain text * PDF All others, AFAIK, are significantly less reliable for that purpose. The ?ReportLab PDF library? is a comprehensive library for this for general page layout and PDF generation. -- \ ?The optimist thinks this is the best of all possible worlds. | `\ The pessimist fears it is true.? ?J. Robert Oppenheimer | _o__) | Ben Finney From marko at pacujo.net Sun Mar 9 18:24:01 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 00:24:01 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <8761nnrqsk.fsf@elektro.pacujo.net> Message-ID: <87zjkzqada.fsf@elektro.pacujo.net> Dan Stromberg : > On Sun, Mar 9, 2014 at 2:43 PM, Marko Rauhamaa wrote: >>>> There is no O(1) hash table. > [...] > > it's still amortized O(1). So we are in perfect agreement. Hash tables are a useful family of techniques but involve quite a bit of cost/benefit heuristics. You can only claim O(1) if your hash table is at least as large as the number of elements. As for comparing them with balanced trees, I think one of the main advantages hash tables have is better CPU cache performance. A tree involves much more jumping around the RAM than a hash table. Still, trees have many things going for them: * no need to find a good hashing function * no need to spend time on calculating the hash value * no need to find optimal hash table sizes -- no costly resizing And of course, the main point: * trees are ordered Note that most key comparisons tend to be very quick as you don't need to traverse the whole key to locate the element. Also, it is hard to say if going O(log n) levels deep in the tree is slower than calculating the hash value, although, as I said, the latter operation tends to benefit from a cache locality. Trees are also crucial when you don't have exact matches, but for example, when you are looking for prefix or wild-card matches. Marko From irmen.NOSPAM at xs4all.nl Sun Mar 9 18:27:16 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 09 Mar 2014 23:27:16 +0100 Subject: Making Labels from python In-Reply-To: References: Message-ID: <531ceac3$0$2867$e4fe514c@news.xs4all.nl> On 9-3-2014 22:29, Ulrich Goebel wrote: > Hallo, > > has anybody an idea how to make small formated documents redy to print with python? > > I would like to print address labels as > > firstname lastname > street and number > cip and city > > The best should be to form a PDF and send it to the label printer. So the PDF could be > given the pagesize (labelsize) and a minimum format (boldface). But may be there is > another light-weight-format besides PDF? > > Any idea? > > Ulrich > > If generating PDF is too heavy for your liking, you could generate some simple HTML instead and use appropriate CSS (page-break etc) to make it suitable for correct printing (which you can do from your web browser). I've used this technique rather successfully myself and generating the HTML for address labels should be fairly trivial. Getting the css right can be a bit of trial and error depending on the browser you're using. Irmen From marko at pacujo.net Sun Mar 9 18:31:33 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 00:31:33 +0200 Subject: Making Labels from python References: <531CDD47.8020304@fam-goebel.de> Message-ID: <87vbvnqa0q.fsf@elektro.pacujo.net> Ben Finney : > The most reliable ?ready to print? document formats are: > > * plain text > * PDF You might also consider PostScript. It can be emitted from any programming language without any special support (and any special support would probably only get in the way). A possibility is also the xlwt module, which allows you to generate Excel documents. I have used to great success, but the results may not be ready to print. Marko From tjreedy at udel.edu Sun Mar 9 18:53:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 09 Mar 2014 18:53:41 -0400 Subject: Making Labels from python In-Reply-To: <531CDD47.8020304@fam-goebel.de> References: <531CDD47.8020304@fam-goebel.de> Message-ID: On 3/9/2014 5:29 PM, Ulrich Goebel wrote: > Hallo, > > has anybody an idea how to make small formated documents redy to print > with python? > > I would like to print address labels as > > firstname lastname > street and number > cip and city > > The best should be to form a PDF and send it to the label printer. So > the PDF could be given the pagesize (labelsize) and a minimum format > (boldface). But may be there is another light-weight-format besides PDF? > > Any idea? Get a label printing program that you can call from python with subprocess. Or look at the following https://pypi.python.org/pypi?%3Aaction=search&term=label+printing&submit=search The top hit is pylabels, which uses ReportLab. -- Terry Jan Reedy From ml at fam-goebel.de Sun Mar 9 19:00:38 2014 From: ml at fam-goebel.de (Ulrich Goebel) Date: Mon, 10 Mar 2014 00:00:38 +0100 Subject: Making Labels from python In-Reply-To: <531CDD47.8020304@fam-goebel.de> References: <531CDD47.8020304@fam-goebel.de> Message-ID: <531CF296.1060700@fam-goebel.de> Many thanks for the moment. I will try reportlab the next days. Am 09.03.2014 22:29, schrieb Ulrich Goebel: > Hallo, > > has anybody an idea how to make small formated documents redy to print > with python? > > I would like to print address labels as > > firstname lastname > street and number > cip and city > > The best should be to form a PDF and send it to the label printer. So > the PDF could be given the pagesize (labelsize) and a minimum format > (boldface). But may be there is another light-weight-format besides PDF? > > Any idea? > > Ulrich > > -- Ulrich Goebel Paracelsusstr. 120, 53177 Bonn From tjreedy at udel.edu Sun Mar 9 19:00:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 09 Mar 2014 19:00:16 -0400 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On 3/9/2014 6:03 PM, Gregory Ewing wrote: > Ian Kelly wrote: >> In my view the second one is wrong. a += b should be understood as >> being equivalent to a = a + b, but with the *possible* and by no means >> guaranteed optimization that the operation may be performed in-place. > > This interpretation is at odds with the Language Reference, > section 6.2.1, Augmented Assignment Statements: > > "An augmented assignment expression like x += 1 can be rewritten as x = > x + 1 to > achieve a similar, but not exactly equal effect... when possible, the > actual operation is performed > in-place, meaning that rather than creating a new object and assigning > that to > the target, the old object is modified instead." > > Note that it says "when possible", not "if the implementation > feels like it". > >> In fact, if you read the documentation for lists, you may notice that >> while they clearly cover the + operator and the extend method, they do >> not explicitly document the list class's += operator. > > The "when possible" clause, together with the fact that lists > are mutable, implies that it *will* be done in-place. There > is no need to document all the in-place operators explicitly > for every type. The discussion of .__iop__ in the datamodel chapter was just revised slightly. http://bugs.python.org/issue19953 -- Terry Jan Reedy From martin.schoon at gmail.com Sun Mar 9 19:22:25 2014 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 9 Mar 2014 23:22:25 GMT Subject: better and user friendly IDE recommended? References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7eab4785-4db6-416f-9bc2-56470ab9d7db@googlegroups.com> Message-ID: Den 2014-02-14 skrev Martin Sch??n : > Den 2014-02-14 skrev Rustom Mody : >> On Friday, February 14, 2014 2:57:13 AM UTC+5:30, Martin Sch??n wrote: >>> Den 2013-09-17 skrev rusi >>> > On Wednesday, September 11, 2013 7:44:04 PM UTC+5:30, >>> > mnishpsyched wrote: >>> > Just saw this >>> > http://www.youtube.com/watch?v=1-dUkyn_fZA >>> > Yeah... scientific programming and web programming are hardly the same :-) >>> > Still it might be worth 20 minutes of your time >> >>> I have started testing this. It is early days so too early to pass >>> judgement. >> >>> Anyone out there using Emacs + Python + Orgmode like this? >>> I might to need ask some questions :-) >> >> The speaker -- Kitchin -- is quite active on the org mode list. >> And a bunch of other babel users. You should try there. >> And please do report back your findings! > > OK, I will dive into the Orgmode pond and I will report back but > please be patient. This is a pure spare time activity. > Here is a first 'report' on this. First some background on me. My formal programming training dates back to 1980 and covered Fortran 77 on an IBM mainframe computer. Later some Pascal and Rocky Mountain Basic was added. I wrote much of my PhD thesis using vi and LaTeX. Post PhD I used Matlab some and got exposed to Emacs. I am clearly not a programmer and use code I write myself very occasionally for supporting my work. I started to learn Python for fun but have found it useful. All modern stuff like test drive design, IDEs, object oriented programming etc are new to me. So now you know why I get things wrong below :-) Until now I have only used Org-mode in an attempt to organize myself. I have picked up some neat ideas from Bernt Hansen: http://doc.norang.ca/org-mode.html Still my use is very primitive. Then I came across this thread and the abovementioned talk... The Orgmode mailing list is a busy place and it seems to me everyone is very advanced, trying to do things I have problems fathoming and coding elisp and all. So, I have been lurking and picking up some ideas on what is possible and I have been checking them out in the manual and by testing. My experience of combining Emacs, Orgmode and Python (and LaTeX) is that it forms a pretty neat system for creating documented programs, code-enhanced documents and for Literate programming. Exporting to PDF and 'tangling' code seems to work as advertised (so far problems have been my creations). You can have code with or without row numbers. You can hide code if you only want to show the results in your exported document. What you don't get as far as I can see is code completion, syntax highlighting etc since Emacs is doing this with respect to Orgmode and not the programming language you use. The following two papers have been helpful/inspiring: "Acive Documets with Org-mode" by Eric Schulte and Dan Davison, Computing in Science & Engineering, May/June 2011. "A Multi-Language Computing Environment for Literate Programming and Reproducible Research" by Eric Schulte, Dan Davison, Thomas Dye and Carsten Dominik, Journal of Statistical Software, January 2012, vol. 46, Issue 3. /Martin From ian.g.kelly at gmail.com Sun Mar 9 19:42:42 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 9 Mar 2014 17:42:42 -0600 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Sun, Mar 9, 2014 at 4:03 PM, Gregory Ewing wrote: > Ian Kelly wrote: >> >> In my view the second one is wrong. a += b should be understood as >> being equivalent to a = a + b, but with the *possible* and by no means >> guaranteed optimization that the operation may be performed in-place. > > > This interpretation is at odds with the Language Reference, > section 6.2.1, Augmented Assignment Statements: > > "An augmented assignment expression like x += 1 can be rewritten as x = x + > 1 to > achieve a similar, but not exactly equal effect... when possible, the actual > operation is performed > > in-place, meaning that rather than creating a new object and assigning that > to > the target, the old object is modified instead." > > Note that it says "when possible", not "if the implementation > feels like it". That's quite vague, and not much stronger a guarantee than "maybe". It's technically "possible" for this augmented assignment to be performed in place: x = 12 x += 4 But it's not done in-place, because ints are meant to be immutable. In any case, this means that whether the operation is actually performed in-place is an implementation detail -- if not of the Python implementation then at least of the class -- and not something the user should take for granted. From michael.weylandt at gmail.com Sun Mar 9 20:01:07 2014 From: michael.weylandt at gmail.com (Michael Weylandt) Date: Sun, 9 Mar 2014 20:01:07 -0400 Subject: better and user friendly IDE recommended? In-Reply-To: <42BCDF72-1182-4BD9-8117-DADE21BB55DE@gmail.com> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7eab4785-4db6-416f-9bc2-56470ab9d7db@googlegroups.com> <42BCDF72-1182-4BD9-8117-DADE21BB55DE@gmail.com> Message-ID: On Mar 9, 2014, at 19:58, Michael Weylandt wrote: > On Mar 9, 2014, at 19:22, Martin Sch??n wrote: >> What you don't get as far as I can see is code completion, >> syntax highlighting etc since Emacs is doing this with >> respect to Orgmode and not the programming language you >> use. > > Put > > (setq org-src-fontify-natively t) > > In your ~/.emacs or ~/.emacs.d/init.el file for syntax highlighting. > > To get the 'regular' code editing, move point into a BEGIN_SRC block and type "C-c ' " (Control-C followed by single quote). That will give you your normal python setup in a sub-buffer. Getting Python autocompletion in Emacs is a bit tricky, but there are many options. For Python, you'll also want (setq org-src-preserve-indentation t) From michael.weylandt at gmail.com Sun Mar 9 19:58:32 2014 From: michael.weylandt at gmail.com (Michael Weylandt) Date: Sun, 9 Mar 2014 19:58:32 -0400 Subject: better and user friendly IDE recommended? In-Reply-To: References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7eab4785-4db6-416f-9bc2-56470ab9d7db@googlegroups.com> Message-ID: <42BCDF72-1182-4BD9-8117-DADE21BB55DE@gmail.com> On Mar 9, 2014, at 19:22, Martin Sch??n wrote: > What you don't get as far as I can see is code completion, > syntax highlighting etc since Emacs is doing this with > respect to Orgmode and not the programming language you > use. Put (setq org-src-fontify-natively t) In your ~/.emacs or ~/.emacs.d/init.el file for syntax highlighting. To get the 'regular' code editing, move point into a BEGIN_SRC block and type "C-c ' " (Control-C followed by single quote). That will give you your normal python setup in a sub-buffer. Getting Python autocompletion in Emacs is a bit tricky, but there are many options. Michael From ian.g.kelly at gmail.com Sun Mar 9 20:04:46 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 9 Mar 2014 18:04:46 -0600 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <8761nnrqsk.fsf@elektro.pacujo.net> Message-ID: On Sun, Mar 9, 2014 at 4:08 PM, Dan Stromberg wrote: > On Sun, Mar 9, 2014 at 2:43 PM, Marko Rauhamaa wrote: >> Dan Stromberg : >> >>> On Sun, Mar 9, 2014 at 2:32 PM, Marko Rauhamaa wrote: >>>> There is no O(1) hash table. >>> >>> http://stackoverflow.com/questions/2771368/can-hash-tables-really-be-o1 >> >> Please elaborate. > > A hash table of fixed size is O(1) until you fill it so full that you > start getting enough collisions to make it O(n), as one bucket becomes > a linked list. This is because the hash function is O(1), and looking > up a value in a C array is O(1). > > A more flexible hash table will not have a fixed size; instead it will > grow itself as needed. This growth operation tends to be O(n), but > happens vanishingly infrequently as the table grows, so it's still > amortized O(1). A hash table can also only ever be O(1) in the average case. Worst case, everything you put into the hash table has the same hash value, and so the time to fetch an item is entirely dependent on the collision resolution scheme -- e.g. O(n) if a linked list or linear probe is used, or perhaps O(log n) if each bucket is a balanced binary tree. There are schemes such as cuckoo hashing that allow true O(1) worst case access, but they have other drawbacks -- inserts with cuckoo hashing are amortized O(1), and it is even possible for an insert to fail entirely after spending exponential time trying to find a way to arrange things. From nispray at gmail.com Sun Mar 9 21:06:39 2014 From: nispray at gmail.com (Wesley) Date: Sun, 9 Mar 2014 18:06:39 -0700 (PDT) Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> Message-ID: <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> What's information do you want? I told the OS, gdb and python version. And my operation steps. What do you want more, then, I can type here. Wesley From breamoreboy at yahoo.co.uk Sun Mar 9 21:48:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Mar 2014 01:48:41 +0000 Subject: gdb unable to read python frame information In-Reply-To: <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> Message-ID: On 10/03/2014 01:06, Wesley wrote: > What's information do you want? > > I told the OS, gdb and python version. > > And my operation steps. > > What do you want more, then, I can type here. > > Wesley > Context, you just keep sending messages like the above which on its own is meaningless. Why should anybody answer your question when you can't be bothered to supply all the needed data in one hit? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Sun Mar 9 22:37:05 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2014 02:37:05 GMT Subject: Tuples and immutability References: Message-ID: <531d2551$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Mar 2014 17:42:42 -0600, Ian Kelly wrote: > On Sun, Mar 9, 2014 at 4:03 PM, Gregory Ewing > wrote: >> Note that it says "when possible", not "if the implementation feels >> like it". > > That's quite vague, and not much stronger a guarantee than "maybe". It's > technically "possible" for this augmented assignment to be performed in > place: > > x = 12 > x += 4 > > But it's not done in-place, because ints are meant to be immutable. That's incorrect. Ints aren't merely "meant" to be immutable, which implies that's it's optional, they are defined by the language specification and the reference implementation as immutable. Any interpreter where ints are mutable *is not Python*. > In any case, this means that whether the operation is actually performed > in-place is an implementation detail -- if not of the Python > implementation then at least of the class -- and not something the user > should take for granted. Whether += operates in place or not is part of the interface of the class, not the implementation. Would you say that whether list.append operates in place or creates a new list is an implementation detail? Whether str.upper() creates a new string or modifies the existing one in place? Mutability versus immutability is part of the interface, not implementation, not withstanding that somebody could create an alternative class with the opposite behaviour: a MutableStr, or ImmutableList. -- Steven D'Aprano http://import-that.dreamwidth.org/ From nispray at gmail.com Sun Mar 9 22:54:56 2014 From: nispray at gmail.com (Wesley) Date: Sun, 9 Mar 2014 19:54:56 -0700 (PDT) Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> Message-ID: If you don't read the loop from the top, and don't tell me exactly what you want by just keep saying context, please ingore this post. Thanks. Wesley ? 2014?3?10????UTC+8??9?48?41??Mark Lawrence??? > On 10/03/2014 01:06, Wesley wrote: > > > What's information do you want? > > > > > > I told the OS, gdb and python version. > > > > > > And my operation steps. > > > > > > What do you want more, then, I can type here. > > > > > > Wesley > > > > > > > Context, you just keep sending messages like the above which on its own > > is meaningless. Why should anybody answer your question when you can't > > be bothered to supply all the needed data in one hit? > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence > > > > --- > > This email is free from viruses and malware because avast! Antivirus protection is active. > > http://www.avast.com From breamoreboy at yahoo.co.uk Sun Mar 9 23:11:57 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Mar 2014 03:11:57 +0000 Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> Message-ID: On 10/03/2014 02:54, Wesley wrote: > If you don't read the loop from the top, and don't tell me exactly what you want by just keep saying context, please ingore this post. > > Thanks. > Wesley > > ? 2014?3?10????UTC+8??9?48?41??Mark Lawrence??? >> On 10/03/2014 01:06, Wesley wrote: >> >>> What's information do you want? >> >>> >> >>> I told the OS, gdb and python version. >> >>> >> >>> And my operation steps. >> >>> >> >>> What do you want more, then, I can type here. >> >>> >> >>> Wesley >> >>> >> >> >> >> Context, you just keep sending messages like the above which on its own >> >> is meaningless. Why should anybody answer your question when you can't >> >> be bothered to supply all the needed data in one hit? >> >> >> >> -- >> >> My fellow Pythonistas, ask not what our language can do for you, ask >> >> what you can do for our language. >> >> >> >> Mark Lawrence >> >> >> >> --- >> >> This email is free from viruses and malware because avast! Antivirus protection is active. >> >> http://www.avast.com > Ah, that explains things, you're using the notoriously bug ridden google groups. You could read and action this https://wiki.python.org/moin/GoogleGroupsPython but I'd suggest you equip yourself with a decent email client. Thunderbird comes highly recommended. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Sun Mar 9 23:16:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Mar 2014 03:16:10 +0000 Subject: Windows installation problem with 3.3.5 Message-ID: It looks as if the upgrade from 3.3.4 to 3.3.5 has stolen my copies of py.exe and pyw.exe from c:\windows. Before I raise an issue on the bug tracker could someone please confirm this, as it wouldn't be the first time I've managed to screw something up. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Sun Mar 9 23:24:08 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2014 03:24:08 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> Message-ID: <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Mar 2014 23:32:54 +0200, Marko Rauhamaa wrote: > Dan Stromberg : > >> This is not just a detail: O(1) tends to be beat O(logn) pretty easily >> for large n. > > There is no O(1) hash table. Of course there are. While it is true that hash tables *in general* are not *always* O(1), the claim that hash tables are O(1) is *less wrong* than your claim that there is "no O(1) hash table". Proof: I create a hash table that accepts unsigned bytes as keys, where the hash is the value of the byte. So byte 0x42 hashes to 0x42, or decimal 66. I give the hash table 256 slots, numbered from 0 to 255. Every hash takes constant time, there are no collisions at all, lookups, insertions and deletions all take constant time regardless of how full the table is. The best, worst and average cases are not just O(1) but also ?(1). Since I have proven that there is *at least one* hash table that is O(1) for best, worst and average case, your claim there are no such hash tables is completely wrong, and certainly more wrong than the claim that Python dicts are O(1) (which is only a little bit wrong, but typically right). See also "The Relativity Of Wrong": http://chem.tufts.edu/answersinscience/relativityofwrong.htm -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Mar 9 23:24:13 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2014 03:24:13 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <8761nnrqsk.fsf@elektro.pacujo.net> Message-ID: <531d305d$1$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 09 Mar 2014 18:04:46 -0600, Ian Kelly wrote: > On Sun, Mar 9, 2014 at 4:08 PM, Dan Stromberg > wrote: >> On Sun, Mar 9, 2014 at 2:43 PM, Marko Rauhamaa >> wrote: >>> Dan Stromberg : >>> >>>> On Sun, Mar 9, 2014 at 2:32 PM, Marko Rauhamaa >>>> wrote: >>>>> There is no O(1) hash table. >>>> >>>> http://stackoverflow.com/questions/2771368/can-hash-tables-really-be- o1 >>> >>> Please elaborate. >> >> A hash table of fixed size is O(1) until you fill it so full that you >> start getting enough collisions to make it O(n), as one bucket becomes >> a linked list. This is because the hash function is O(1), and looking >> up a value in a C array is O(1). >> >> A more flexible hash table will not have a fixed size; instead it will >> grow itself as needed. This growth operation tends to be O(n), but >> happens vanishingly infrequently as the table grows, so it's still >> amortized O(1). > > A hash table can also only ever be O(1) in the average case. Since this discussion has apparently devolved into people trying to out- pedant each other, I'm going to dispute that. That will depend on the distribution of hash collisions. With a sufficiently big table, sufficiently small set of possible data, a sufficiently good hash function, or some combination of the above, a hash table may be O(1) even in the worst case. E.g. if you hash a number n to itself, e.g. hash(42) == 42, your data consists of single byte numbers 0 through 255, and your hash table has 256 slots, *there are no collisions* and every lookup is O(1). There are technical meanings for Big Oh notation, which can be quite complicated. There's Big O, Little o, Big ? (omega), Little ? (omega), Big ? (theta), although I don't think there's a Little ?. They can refer to the best case, worst case, average (mean) case, median case, "typical" case where you're making some guess of what occurs typically, and any other situation you care about. The algorithmic complexity can apply consistently to each and every run of the algorithm, or they can be amortized over many runs. If you're doing a technical analysis of an algorithm, this pedantic detail is important. But when people are just talking informally in a hand-wavy manner, they usually say "O(foo)" when they actually mean "for typical data under typical conditions, the algorithm runs with a complexity of the order of foo". And that's perfectly okay, just like it's perfectly okay to describe the Earth as a sphere even though a pedant will call it a wrinkly asymmetrical oblate spheroid. -- Steven D'Aprano http://import-that.dreamwidth.org/ From flebber.crue at gmail.com Mon Mar 10 00:49:20 2014 From: flebber.crue at gmail.com (flebber) Date: Sun, 9 Mar 2014 21:49:20 -0700 (PDT) Subject: golang OO removal, benefits. over python? Message-ID: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> I was wondering if a better programmer than I could explain if the removal of OO features in golang really does offer an great benefit over python. An article I was reading ran through a brief overview of golang in respect of OO features http://areyoufuckingcoding.me/2012/07/25/object-desoriented-language/ . maybe removing OO features would be a benefit to c++ users or Java users but python? As I have seen an interesting reddit or two of people trying to figure out go today it was a ruby user, totally lost with structs. So anecdotally is actually python and ruby users changing to Go, here is a blog and reddit from Rob Pike. http://www.reddit.com/comments/1mue70 Why would a Python user change to go except for new and interesting? Sayth From rustompmody at gmail.com Mon Mar 10 01:05:59 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 9 Mar 2014 22:05:59 -0700 (PDT) Subject: golang OO removal, benefits. over python? In-Reply-To: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> Message-ID: <897574dd-e115-4056-88d3-20a4cf82191f@googlegroups.com> On Monday, March 10, 2014 10:19:20 AM UTC+5:30, flebber wrote: > I was wondering if a better programmer than I could explain if the removal of OO features in golang really does offer an great benefit over python. That's a strange locution: You are suggesting that go had OOP and it was removed From marko at pacujo.net Mon Mar 10 02:16:43 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 08:16:43 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87eh2atw6s.fsf@elektro.pacujo.net> Steven D'Aprano : > Proof: I create a hash table that accepts unsigned bytes as keys, where The O(f(n)) notation has no meaning when n is limited. This thing is not just pedantry. The discussion was how a balanced tree fares in comparison with hash tables. A simplistic O(1) vs O(log n) was presented as a proof that balanced trees don't have a chance in practice or theory. I wasn't so easily convinced. Marko From dieter at handshake.de Mon Mar 10 03:13:42 2014 From: dieter at handshake.de (dieter) Date: Mon, 10 Mar 2014 08:13:42 +0100 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <87mwh2bi1v.fsf@handshake.de> <73e3cfa2-28d3-4647-8a7f-577e41dffbd1@googlegroups.com> <6dc8a38d-d3a6-44fd-8f39-f73cea1ac4c1@googlegroups.com> Message-ID: <8738iqpluh.fsf@handshake.de> Wesley writes: > So, let me clarify here, in order to try, I get a clean machine. > > Centos 6.5 64bit. > Now , I try this: > 1. install gdb 7.7 from source , with configure option --with-python > > 2. install python 2.6.6 from source, with configure option --with-pydebug > > 3. run a python script > > 4. from command line, gdb python -p to attach the running script > > 5. within gdb, issue python, import libpython, end > no errors > 6. py-bt outputs nothing, py-locals says Unable to locate python frame > here is the snippet: > [root at localhost Python-2.6.6]# gdb python 52315 > GNU gdb (GDB) 7.7 > .... > Attaching to program: /home/nipen/test/Python-2.6.6/python, process 52315 > Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done. > Loaded symbols for /lib64/ld-linux-x86-64.so.2 > 0x00000030a98e15c3 in ?? () > (gdb) bt > #0 0x00000030a98e15c3 in ?? () > #1 0x00007f4cf68d1219 in ?? () > #2 0x0000000000000000 in ?? () This looks like a very strange backtrace on C level as well. The most natural explanation would be: your process is in a very strange state (due to some C level problem). But, of course, your "gdb" might have general problems, as well. From dieter at handshake.de Mon Mar 10 03:16:41 2014 From: dieter at handshake.de (dieter) Date: Mon, 10 Mar 2014 08:16:41 +0100 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> Message-ID: <87y50io752.fsf@handshake.de> Mark Lawrence writes: > On 10/03/2014 01:06, Wesley wrote: > ... > Context, you just keep sending messages like the above which on its > own is meaningless. The original poster has send messages lacking important pieces of information -- but on request from the list, he has fixed this initial error. Thus, on his side, there was progress ;-) From dieter at handshake.de Mon Mar 10 03:28:30 2014 From: dieter at handshake.de (dieter) Date: Mon, 10 Mar 2014 08:28:30 +0100 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> Message-ID: <87txb6o6ld.fsf@handshake.de> Wesley writes: > If you don't read the loop from the top, and don't tell me exactly what you want by just keep saying context, please ingore this post. You are doing things only a few people do: trying to debug a Python process on C level -- and you observe really strange things. It is very difficult to guess from the distance what goes wrong. Apparently, your gdb sees a very strange state of the debugged process. But why? Missing symbols was the first guess (the gdb output you have provided does not suggest this - but I have not seen the "reading symbols from "python" ..."; thus, there may still be a problem with this). A runaway process is another guess. Some gdb problem another one. I would approach the situation by simplifying the setup. Instead of attaching a running Python process, I would use "gdb python"; then "run"; then "CTRL-C" and there look what "bt" gives you (this should demonstrate whether your "gdb" is set up correctly and can debug Python on C level). Then you write an infinitely running function in Python, run it and again interrupt with "gdb" to see whether the "py-*" commands are working. If this all work, you come again to your actual task -- understanding what your python process is doing. From larry at hastings.org Mon Mar 10 03:47:05 2014 From: larry at hastings.org (Larry Hastings) Date: Mon, 10 Mar 2014 00:47:05 -0700 Subject: [RELEASED] Python 3.4.0 release candidate 3 Message-ID: <531D6DF9.1020305@hastings.org> On behalf of the Python development team, I'm pleased to announce the third and final** release candidate of Python 3.4. This is a preview release, and its use is not recommended for production settings. Python 3.4 includes a range of improvements of the 3.x series, including hundreds of small improvements and bug fixes. Major new features and changes in the 3.4 release series include: * PEP 428, a "pathlib" module providing object-oriented filesystem paths * PEP 435, a standardized "enum" module * PEP 436, a build enhancement that will help generate introspection information for builtins * PEP 442, improved semantics for object finalization * PEP 443, adding single-dispatch generic functions to the standard library * PEP 445, a new C API for implementing custom memory allocators * PEP 446, changing file descriptors to not be inherited by default in subprocesses * PEP 450, a new "statistics" module * PEP 451, standardizing module metadata for Python's module import system * PEP 453, a bundled installer for the *pip* package manager * PEP 454, a new "tracemalloc" module for tracing Python memory allocations * PEP 456, a new hash algorithm for Python strings and binary data * PEP 3154, a new and improved protocol for pickled objects * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O Python 3.4 is now in "feature freeze", meaning that no new features will be added. The final release is projected for March 16, 2014. To download Python 3.4.0rc3 visit: http://www.python.org/download/releases/3.4.0/ Please consider trying Python 3.4.0rc3 with your code and reporting any new issues you notice to: http://bugs.python.org/ Enjoy! ** This time we really mean it! No foolin'! -- Larry Hastings, Release Manager larry at hastings.org (on behalf of the entire python-dev team and 3.4's contributors) From ian.g.kelly at gmail.com Mon Mar 10 03:50:22 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 10 Mar 2014 01:50:22 -0600 Subject: golang OO removal, benefits. over python? In-Reply-To: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> Message-ID: On Sun, Mar 9, 2014 at 10:49 PM, flebber wrote: > I was wondering if a better programmer than I could explain if the removal of OO features in golang really does offer an great benefit over python. > > An article I was reading ran through a brief overview of golang in respect of OO features http://areyoufuckingcoding.me/2012/07/25/object-desoriented-language/ The description of how Go structs work is accurate from what I know of it, but I think the author goes astray in claiming that this is not OOP. If you look at how C++ compiles inherited classes, it works in basically the same way. The SmallBox class in C++ is essentially a struct with its fields laid out in a specific order and some methods that operate on it. A BigBox class that inherits from SmallBox will first lay out the SmallBox fields in the same way that SmallBox does, and then add the fields specific to BigBox after. Draw an imaginary line around the SmallBox fields, and you have the same setup as the Go example: a SmallBox nested within a BigBox. SmallBox methods will only operate on the portion of BigBox that is within the imaginary line (i.e. the SmallBox) and don't need to have any knowledge that the SmallBox is part of a larger data structure. BigBox methods can operate on the entire BigBox and can call SmallBox methods when desired. The author points out that nested structures can be made optional by including a pointer to the structure instead of the structure itself. Again you can do the exact same thing in C++; in OOP this is usually described as a "has-a" relationship. Most languages don't support the syntactic sugar that makes this look almost identical to inheritance in Go, but that's all it is. The biggest difference between the two is that Go doesn't have any concept of virtual methods. A call of a SmallBox method on a SmallBox object, whether part of a larger object or not, will always call that SmallBox method. Whereas a call to a C++ method that is compiled as a virtual method will actually call the method associated with the superstructure, regardless of the static type the method was called on. Go gets around this by using interfaces. An interface that is satisfied by SmallBox will usually automatically be satisfied by BigBox also, and calls to interface methods are dispatched dynamically. As a result, object-oriented Go code will typically work with interfaces rather than specifying actual classes, which is not too different from how Java code is typically written. Incidentally, I rather like the design of Go interfaces. They are essentially Python's duck typing made explicit, divorcing interface implementation from formal inheritance. On the whole though I think that the language is not yet mature enough to be able to seriously compete with more established languages like Python or Java. From ian.g.kelly at gmail.com Mon Mar 10 04:35:36 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 10 Mar 2014 02:35:36 -0600 Subject: Tuples and immutability In-Reply-To: <531d2551$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <531d2551$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 9, 2014 at 8:37 PM, Steven D'Aprano wrote: > On Sun, 09 Mar 2014 17:42:42 -0600, Ian Kelly wrote: > >> On Sun, Mar 9, 2014 at 4:03 PM, Gregory Ewing >> wrote: > >>> Note that it says "when possible", not "if the implementation feels >>> like it". >> >> That's quite vague, and not much stronger a guarantee than "maybe". It's >> technically "possible" for this augmented assignment to be performed in >> place: >> >> x = 12 >> x += 4 >> >> But it's not done in-place, because ints are meant to be immutable. > > That's incorrect. Ints aren't merely "meant" to be immutable, which > implies that's it's optional, they are defined by the language > specification and the reference implementation as immutable. Any > interpreter where ints are mutable *is not Python*. That's true, but is beside the point, which is that "when possible" is not very meaningful. >> In any case, this means that whether the operation is actually performed >> in-place is an implementation detail -- if not of the Python >> implementation then at least of the class -- and not something the user >> should take for granted. > > Whether += operates in place or not is part of the interface of the > class, not the implementation. > > Would you say that whether list.append operates in place or creates a new > list is an implementation detail? Whether str.upper() creates a new > string or modifies the existing one in place? Of course not. list.append is documented as modifying the list. str.upper is documented as returning a copy of the string. > Mutability versus > immutability is part of the interface, not implementation, not > withstanding that somebody could create an alternative class with the > opposite behaviour: a MutableStr, or ImmutableList. If the in-place behavior of += is held to be part of the interface, then we must accept that += is not polymorphic across mutable and immutable types, which in my mind largely* defeats the purpose of having it. After all, there should be one -- and preferably only one -- obvious way to do it. If you want in-place concatenation, the obvious way to do it is by calling extend. If you want copy concatenation, the obvious way to do it is with the + operator. Why then should not just mutable sequences but immutable sequences as well even offer the += operator? * The one exception I can think of is numpy, where there is no more obvious way to do in-place addition, and in that context I would consider the in-place behavior to be part of the interface. From mail at timgolden.me.uk Mon Mar 10 04:36:54 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 10 Mar 2014 08:36:54 +0000 Subject: Windows installation problem with 3.3.5 In-Reply-To: References: Message-ID: <531D79A6.3010502@timgolden.me.uk> On 10/03/2014 03:16, Mark Lawrence wrote: > It looks as if the upgrade from 3.3.4 to 3.3.5 has stolen my copies of > py.exe and pyw.exe from c:\windows. Before I raise an issue on the bug > tracker could someone please confirm this, as it wouldn't be the first > time I've managed to screw something up. Well, as unhelpful as this might be, it gave me no problem: c:\Windows>dir py.exe Volume in drive C has no label. Volume Serial Number is 787D-BE54 Directory of c:\Windows 18/11/2013 21:17 93,696 py.exe 1 File(s) 93,696 bytes 0 Dir(s) 31,048,863,744 bytes free [... snip installing Python 3.3.5 ...] c:\Windows>dir py.exe Volume in drive C has no label. Volume Serial Number is 787D-BE54 Directory of c:\Windows 09/03/2014 10:36 93,696 py.exe 1 File(s) 93,696 bytes 0 Dir(s) 31,048,912,896 bytes free TJG From marko at pacujo.net Mon Mar 10 04:38:58 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 10:38:58 +0200 Subject: golang OO removal, benefits. over python? References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> Message-ID: <878usitplp.fsf@elektro.pacujo.net> Ian Kelly : > The description of how Go structs work is accurate from what I know of > it, but I think the author goes astray in claiming that this is not > OOP. Call it "no-nonsense OOP." No wonder the color of the box was gray in the example. > On the whole though I think that the language is not yet mature enough > to be able to seriously compete with more established languages like > Python or Java. Also, is there anything seriously lacking in Python, Java and C? I was very interested in Go when it came out, but was turned off by the fact that you had so have a Google account to effectively participate in the community. Marko From mail at timgolden.me.uk Mon Mar 10 04:40:01 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 10 Mar 2014 08:40:01 +0000 Subject: Windows installation problem with 3.3.5 In-Reply-To: References: Message-ID: <531D7A61.1090603@timgolden.me.uk> On 10/03/2014 03:16, Mark Lawrence wrote: > It looks as if the upgrade from 3.3.4 to 3.3.5 has stolen my copies of > py.exe and pyw.exe from c:\windows. Before I raise an issue on the bug > tracker could someone please confirm this, as it wouldn't be the first > time I've managed to screw something up. One thing does occur to me: I seem to remember that you have in the past installed py[w].exe from Vinay's standalone installer. If that was the case, it's presumably possible that some mechanism of the Python 3.3.5 .msi removed them and didn't replace them with its own versions? TJG From steve+comp.lang.python at pearwood.info Mon Mar 10 04:53:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2014 08:53:07 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> Message-ID: <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Mar 2014 08:16:43 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Proof: I create a hash table that accepts unsigned bytes as keys, where > > The O(f(n)) notation has no meaning when n is limited. It has obvious meaning: O(1) means that look-ups take constant time, not (for example) proportional to the number of keys in the table. > This thing is not just pedantry. Yes it is. You're not even being pedantic for the sake of educating people and helping them learn. If that were the case, I would completely understand. Rather, it looks to me that you're being obnoxiously pedantic for the sake of trying to get attention. I think you are trolling. Take your comment that started this dispute: [responding to Dan Stromberg] > This is not just a detail: O(1) tends to be beat O(logn) > pretty easily for large n. [to which your entire response was] There is no O(1) hash table. As pedantry, it is an utter failure: it's *wrong*, for starters, but you didn't even make a pretence of trying to justify it. It's not educational, and it doesn't advance your argument in any way. And just *two posts later*, you acknowledged without apology or embarrassment that hash tables actually are O(1). So it seems that you didn't even believe your claim when you made it. This is why I think you are trolling. All your comment accomplished was to wrongly contradict a well- established and often-repeated fact that hash tables are usually O(1): https://duckduckgo.com/html/?q=big+oh+hash+tables which is great if your aim is to trick people into giving you attention (as I suppose I am giving you attention now) but useless for advancing the debate or educating people. It is as if you had declared "Actually the Allies had lost World War Two", and then tried to justify such a ridiculously false statement on the basis that while they didn't actually *lose* according to the normally accepted meaning of the word, some of the Allies may have failed to accomplish every single one of their objectives in the war. > The discussion was how a balanced tree > fares in comparison with hash tables. A simplistic O(1) vs O(log n) was > presented as a proof that balanced trees don't have a chance in practice > or theory. I wasn't so easily convinced. If you had wanted to put the case for balanced trees, you could mention that in practice they perform comparably to hash tables for reasonable sizes of data, and may require less memory. You could have made an attempt to teach people about the difference between O and ? complexity, the difference between best case, worst case, average case, and typical behaviour. You could have mentioned the difference between amortized and non-amortized behaviour, or go into detail about the various assumptions made when doing Big Oh analysis (e.g. that all "simple" operations take constant time, which is not strictly speaking true). Any of these things would have helped people understand your position better. But you did *none* of these things. It seems to me that your stated position is actually irrelevant to you, what you want is not better data structures in Python, but for people to respond to your posts. In other words, I suspect you are trolling. If I am right, that certainly would explain your apparent inability to understand the difference between "is" and == operators, your insistence that object IDs are addresses, and your declaration that object identity is philosophically untenable. -- Steven D'Aprano http://import-that.dreamwidth.org/ From jurko.gospodnetic at pke.hr Mon Mar 10 05:05:00 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Mon, 10 Mar 2014 10:05:00 +0100 Subject: Windows installation problem with 3.3.5 In-Reply-To: References: Message-ID: Hi. On 10.3.2014. 4:16, Mark Lawrence wrote: > It looks as if the upgrade from 3.3.4 to 3.3.5 has stolen my copies of > py.exe and pyw.exe from c:\windows. Before I raise an issue on the > bug tracker could someone please confirm this, as it wouldn't be the > first time I've managed to screw something up. What exactly do you mean by 'stolen'? Removed those executables? Or reused the original ones instead of new ones you expected to be installed over them? Or the opposite - overwrote them with new ones and you expected the old ones to stay around? I just tested the same thing and the original executables that were there got overwritten with newer ones, as I expected. Hope this helps. Best regards, Jurko Gospodneti? From steve+comp.lang.python at pearwood.info Mon Mar 10 05:13:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2014 09:13:40 GMT Subject: Tuples and immutability References: <531d2551$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <531d8244$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Mar 2014 02:35:36 -0600, Ian Kelly wrote: > On Sun, Mar 9, 2014 at 8:37 PM, Steven D'Aprano > wrote: >> On Sun, 09 Mar 2014 17:42:42 -0600, Ian Kelly wrote: >> >>> On Sun, Mar 9, 2014 at 4:03 PM, Gregory Ewing >>> wrote: >> >>>> Note that it says "when possible", not "if the implementation feels >>>> like it". >>> >>> That's quite vague, and not much stronger a guarantee than "maybe". >>> It's technically "possible" for this augmented assignment to be >>> performed in place: >>> >>> x = 12 >>> x += 4 >>> >>> But it's not done in-place, because ints are meant to be immutable. >> >> That's incorrect. Ints aren't merely "meant" to be immutable, which >> implies that's it's optional, they are defined by the language >> specification and the reference implementation as immutable. Any >> interpreter where ints are mutable *is not Python*. > > That's true, but is beside the point, which is that "when possible" is > not very meaningful. It's meaningful. It refers not to ints, but the infinite number of possible classes which might include augmented assignment. Some of them will be immutable, in which case it is not possible for += etc. to be performed in-place. Some of them will be mutable, but there won't be any reasonable (or even unreasonable) way to perform += in-place. But for some mutable classes, it will be possible to perform += in place, in which case the docs say that they have to do so. >>> In any case, this means that whether the operation is actually >>> performed in-place is an implementation detail -- if not of the Python >>> implementation then at least of the class -- and not something the >>> user should take for granted. >> >> Whether += operates in place or not is part of the interface of the >> class, not the implementation. >> >> Would you say that whether list.append operates in place or creates a >> new list is an implementation detail? Whether str.upper() creates a new >> string or modifies the existing one in place? > > Of course not. list.append is documented as modifying the list. > str.upper is documented as returning a copy of the string. Right. And += is documented as modifying the list too. >> Mutability versus >> immutability is part of the interface, not implementation, not >> withstanding that somebody could create an alternative class with the >> opposite behaviour: a MutableStr, or ImmutableList. > > If the in-place behavior of += is held to be part of the interface, then > we must accept that += is not polymorphic across mutable and immutable > types, I'm fine with that. > which in my mind largely* defeats the purpose of having it. Not to my mind. I think that having augmented assignment is worthwhile even if it behaves differently and incompatibly for different classes. After all, so does * (multiplication): py> x = 24 py> x*x 576 but: py> x = [] py> x*x Traceback (most recent call last): File "", line 1, in TypeError: can't multiply sequence by non-int of type 'list' I don't think that we ought to throw away * and I don't think we ought to throw away *= either. > After all, there should be one -- and preferably only one -- obvious way > to do it. If you want in-place concatenation, the obvious way to do it > is by calling extend. If you want copy concatenation, the obvious way > to do it is with the + operator. Why then should not just mutable > sequences but immutable sequences as well even offer the += operator? *shrug* I can see that each individual operation: list.extend list + list += makes good sense in isolation, but I can also see that the combination don't quite gel together as smoothly as we might hope. -- Steven D'Aprano http://import-that.dreamwidth.org/ From breamoreboy at yahoo.co.uk Mon Mar 10 05:32:35 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Mar 2014 09:32:35 +0000 Subject: Windows installation problem with 3.3.5 In-Reply-To: <531D7A61.1090603@timgolden.me.uk> References: <531D7A61.1090603@timgolden.me.uk> Message-ID: On 10/03/2014 08:40, Tim Golden wrote: > On 10/03/2014 03:16, Mark Lawrence wrote: >> It looks as if the upgrade from 3.3.4 to 3.3.5 has stolen my copies of >> py.exe and pyw.exe from c:\windows. Before I raise an issue on the bug >> tracker could someone please confirm this, as it wouldn't be the first >> time I've managed to screw something up. > > > One thing does occur to me: I seem to remember that you have in the past > installed py[w].exe from Vinay's standalone installer. If that was the > case, it's presumably possible that some mechanism of the Python 3.3.5 > .msi removed them and didn't replace them with its own versions? > > > TJG > Correct. I'll flag this on the bug tracker just in case this is in fact the cause, though I can't off of the top of my head see why it should be. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Mon Mar 10 05:41:41 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 11:41:41 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8738iqtmp6.fsf@elektro.pacujo.net> Steven D'Aprano : > If I am right, that certainly would explain your apparent inability to > understand the difference between "is" and == operators, your > insistence that object IDs are addresses, and your declaration that > object identity is philosophically untenable. You and I certainly have a very hard time communicating. Your paraphrasing of my positions demonstrates that. Marko From breamoreboy at yahoo.co.uk Mon Mar 10 05:51:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Mar 2014 09:51:17 +0000 Subject: Balanced trees In-Reply-To: <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/03/2014 08:53, Steven D'Aprano wrote: > > In other words, I suspect you are trolling. > s/suspect/know/ , he didn't make captain of my dream team for nothing, you know :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ned at nedbatchelder.com Mon Mar 10 06:57:13 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 10 Mar 2014 06:57:13 -0400 Subject: Balanced trees In-Reply-To: <8738iqtmp6.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> <8738iqtmp6.fsf@elektro.pacujo.net> Message-ID: On 3/10/14 5:41 AM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> If I am right, that certainly would explain your apparent inability to >> understand the difference between "is" and == operators, your >> insistence that object IDs are addresses, and your declaration that >> object identity is philosophically untenable. > > You and I certainly have a very hard time communicating. Your > paraphrasing of my positions demonstrates that. > Marko, welcome to the community. We enjoy technical discourse, even debate. It's clear that you bring a lot of knowledge, intelligence, and passion. But you have been involved in a number of long contentious threads in the last few weeks. You are right that you and Steven have had a hard time communicating. You are part of "you and Steven", it would be at least polite to consider that part of the reason for the difficulty has to do with your style. It can be brief and contrarian, which puts people off. Perhaps if you tried to understand the gap and bridge it more, people would be less inclined to think that you were trying to widen the gap. --Ned. > > Marko > -- Ned Batchelder, http://nedbatchelder.com From flebber.crue at gmail.com Mon Mar 10 07:45:17 2014 From: flebber.crue at gmail.com (flebber) Date: Mon, 10 Mar 2014 04:45:17 -0700 (PDT) Subject: golang OO removal, benefits. over python? In-Reply-To: <878usitplp.fsf@elektro.pacujo.net> References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> <878usitplp.fsf@elektro.pacujo.net> Message-ID: <36c92dce-3b18-479b-85c6-31c48f11b25b@googlegroups.com> > Also, is there anything seriously lacking in Python, Java and C? > > > Marko >From their FAQ: Go was born out of frustration with existing languages and environments for systems programming. Programming had become too difficult and the choice of languages was partly to blame. One had to choose either efficient compilation, efficient execution, or ease of programming; all three were not available in the same mainstream language. Programmers who could were choosing ease over safety and efficiency by moving to dynamically typed languages such as Python and JavaScript rather than C++ or, to a lesser extent, Java. Go is an attempt to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aims to be modern, with support for networked and multicore computing. > Although Go doesn't have exception handling either which is odd. http://blog.golang.org/error-handling-and-go http://uberpython.wordpress.com/2012/09/23/why-im-not-leaving-python-for-go/ Or you can use defer http://blog.golang.org/defer-panic-and-recover func CopyFile(dstName, srcName string) (written int64, err error) { src, err := os.Open(srcName) if err != nil { return } defer src.Close() dst, err := os.Create(dstName) if err != nil { return } defer dst.Close() return io.Copy(dst, src) } > That's a strange locution: You are suggesting that go had OOP and it was > > removed Although Go has types and methods and allows an object-oriented style of programming, there is no type hierarchy. The concept of "interface" in Go provides a different approach that we believe is easy to use and in some ways more general. There are also ways to embed types in other types to provide something analogous--but not identical--to subclassing. http://golang.org/doc/faq#Is_Go_an_object-oriented_language sayth From g.rodola at gmail.com Mon Mar 10 07:56:39 2014 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Mon, 10 Mar 2014 12:56:39 +0100 Subject: ANN: psutil 2.0.0 released Message-ID: Hi there folks, I'm pleased to announce the 2.0.0 release of psutil: http://code.google.com/p/psutil/ === About === psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, FreeBSD and Sun Solaris, both 32-bit and 64-bit architectures, with Python versions from 2.4 to 3.4. Pypi is also known to work. === What changed === A lot. I tried to address all the changes in this blog post: http://grodola.blogspot.com/2014/03/psutil-20.html === Links === * Home page: http://code.google.com/p/psutil * Downloads: https://pypi.python.org/pypi?:action=display&name=psutil#downloads * Documentation: http://psutil.readthedocs.org/ Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. Best, -- Giampaolo - http://grodola.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jurko.gospodnetic at pke.hr Mon Mar 10 08:51:07 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Mon, 10 Mar 2014 13:51:07 +0100 Subject: Windows installation problem with 3.3.5 In-Reply-To: References: Message-ID: Hi. On 10.3.2014. 4:16, Mark Lawrence wrote: > It looks as if the upgrade from 3.3.4 to 3.3.5 has stolen my copies of > py.exe and pyw.exe from c:\windows. Before I raise an issue on the bug > tracker could someone please confirm this, as it wouldn't be the first > time I've managed to screw something up. I just now ran into something that might explain this. You could have run your new installation as 'for the current user only'. That would not have placed the new py.exe executable in C:\Windows. Hope this helps. Best regards, Jurko Gospodneti? From breamoreboy at yahoo.co.uk Mon Mar 10 09:06:35 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 10 Mar 2014 13:06:35 +0000 Subject: Windows installation problem with 3.3.5 In-Reply-To: References: Message-ID: On 10/03/2014 12:51, Jurko Gospodneti? wrote: > Hi. > > On 10.3.2014. 4:16, Mark Lawrence wrote: >> It looks as if the upgrade from 3.3.4 to 3.3.5 has stolen my copies of >> py.exe and pyw.exe from c:\windows. Before I raise an issue on the bug >> tracker could someone please confirm this, as it wouldn't be the first >> time I've managed to screw something up. > > I just now ran into something that might explain this. You could have > run your new installation as 'for the current user only'. That would not > have placed the new py.exe executable in C:\Windows. > > Hope this helps. > > Best regards, > Jurko Gospodneti? > Thanks for trying but no, I installed for all users. FTR issue here http://bugs.python.org/issue20880 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Mon Mar 10 09:39:13 2014 From: harrismh777 at gmail.com (Mark H. Harris) Date: Mon, 10 Mar 2014 06:39:13 -0700 (PDT) Subject: image processing in python and opencv In-Reply-To: References: <512500c5-3c2f-49c8-861f-5755991c3abb@googlegroups.com> Message-ID: <5ce864b0-cf10-41a3-aa2e-0941e6059d84@googlegroups.com> On Sunday, March 9, 2014 2:09:25 PM UTC-5, Gary Herron wrote: > i have no idea how to retrieve indexed images stored in ordered dictionary, using its values like : blue,green,red mean along with contrast, energy, homogeneity and correlation. as i have calculated the euclidean distance and i don't know how to display the images which are similar. Its a bot. (spam) From roy at panix.com Mon Mar 10 09:59:01 2014 From: roy at panix.com (Roy Smith) Date: Mon, 10 Mar 2014 09:59:01 -0400 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> Message-ID: In article <87eh2atw6s.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > Steven D'Aprano : > > > Proof: I create a hash table that accepts unsigned bytes as keys, where > > The O(f(n)) notation has no meaning when n is limited. > > This thing is not just pedantry. The discussion was how a balanced tree > fares in comparison with hash tables. A simplistic O(1) vs O(log n) was > presented as a proof that balanced trees don't have a chance in practice > or theory. I wasn't so easily convinced. > > > Marko On the other hand, log n, for n = 1 million, is just 20. It's not hard to imagine a hash function which costs 20x what a node traversal does, in which case, the log n lookup is ahead for all n < 1 million. Looking at the Songza source, I see we have one user-defined hash function: def __hash__(self): return hash((self.song, self.user, self.add_time, self.delete_time, self.play_first)) where those things are 2 bson.ObjectId's, 2 datetimes, and a boolean. I wouldn't be surprised if that falls into the 20x node traversal bucket. In this case, convenience was more important than speed, so it doesn't matter. The hash vs. tree argument can get very complicated. For example, if your tree is not completely resident in memory, the cost of paging in a node will swamp everything else, and improving lookup speed will boil down to reducing the number of I/O operations you need. An expensive hash plus a linear walk through a collision chain which was resident in a single memory block will beat traversing two nodes, each of which had to be paged in separately. From albert at spenarnc.xs4all.nl Mon Mar 10 10:12:59 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 10 Mar 2014 14:12:59 GMT Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87wqgfdk6a.fsf@elektro.pacujo.net> <87sir2et1d.fsf@elektro.pacujo.net> Message-ID: <531dc86b$0$25076$e4fe514c@dreader37.news.xs4all.nl> In article <87sir2et1d.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: >Mark Lawrence : > >> http://c2.com/cgi/wiki?SwitchStatementsSmell > >Your brief summary, please, Mark? > >Anyway, the first 1000 lines or so that I managed to read from that page >stated a valid principle, which however doesn't invalidate the existence >of a switch statement. > >A colleague of mine taught me decades back that the whole point of OO >was the avoidance of if and switch statements. So if your code has an if >or switch statement, chances are you are doing something wrong. > >I agree. > >However, like all other maxims, that principle, too, has exceptions. Two >recurring examples are parsers/decoders and state machines. Sure, you >can implement states beautifully with objects/classes (and I do do that >when performance is not an issue), but having experimented with >different implementation techniques (in C, C++ and Java), I have >concluded that switch statements are often unbeatable in performance and >clarity. I can't see why parsers decoders are any different. The Pentium assembler in my ciforth's ``forth.lab'' library has not a single if statement and I reckon it is a superior design. (State is kept in an ai blackboard fashion in bitmaps.) Forth has of course a built in "look it up, then execute it", which could be regarded as a giant switch. > >And I sometimes run into convoluted factory (anti)patterns whose sole >purpose is to avoid straightforward switch statements in a decoder. > > >Marko -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From kwa at kuwata-lab.com Mon Mar 10 10:23:46 2014 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Mon, 10 Mar 2014 23:23:46 +0900 Subject: [ANN] Oktest.py 0.14.0 released - a new-style testing library Message-ID: I released Oktest.py 0.14.0. http://pypi.python.org/pypi/Oktest/ http://packages.python.org/Oktest/ Oktest.py is a new-style testing library for Python:: from oktest import ok, NG ok (x) > 0 # same as assertTrue(x > 0) ok (s) == 'foo' # same as assertEqual(s, 'foo') ok (s) != 'foo' # same as assertNotEqual(s, 'foo') ok (f).raises(ValueError) # same as assertRaises(ValueError, f) ok (u'foo').is_a(unicode) # same as assertTrue(isinstance(u'foo', unicode)) ok ('A.txt').is_file() # same as assertTrue(os.path.isfile('A.txt')) It supports WSGI Application testing:: from oktest.web import WSGITest http = WSGITest(app) resp = http.GET('/') ok (resp).is_response(200).json({"status": "OK"}) See http://packages.python.org/Oktest/ for details. New features ------------ * [enhance] Response object returned by `WSGITest#GET()' or '#POST()' now supports `body_json' property. Example:: from oktest.web import WSGITest http = WSGITest(app) resp = http.GET('/') print(resp.body_json) * [change] `headers` argument of `WSGITest#GET()' (or '#POST()' and so on) now means HTTP headers, not environ values. Example:: ## version <= 0.13 http.GET('/', headers={'HTTP_COOKIE': 'name=val'}) ## version >= 0.14 http.GET('/', headers={'Cookie': 'name=val'}) ## or http.GET('/', environ={'HTTP_COOKIE': 'name=val'}) * [enhance] (Experimental) `oktest.validator.Validator' class is added. It is convenient to test complex data structure. Example:: from oktest.validator import Validator as V ok (resp.body_json) == { "status": "OK", "member": { "name": "Haruhi", "gender": V('gender', enum=('F', 'M')), "age": V('age', type=int, between=(15, 18)), "birthday": V('created_at', pattern=r'^\d\d\d\d-\d\d-\d\d$') } } See users guide for details. http://www.kuwata-lab.com/oktest/oktest-py_users-guide.html#validator -- regars, makoto kuwata -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Mon Mar 10 10:29:30 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 16:29:30 +0200 Subject: Can global variable be passed into Python function? References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <87wqgfdk6a.fsf@elektro.pacujo.net> <87sir2et1d.fsf@elektro.pacujo.net> <531dc86b$0$25076$e4fe514c@dreader37.news.xs4all.nl> Message-ID: <87k3c2rut1.fsf@elektro.pacujo.net> albert at spenarnc.xs4all.nl (Albert van der Horst): > I can't see why parsers decoders are any different. The Pentium > assembler in my ciforth's ``forth.lab'' library has not a single if > statement and I reckon it is a superior design. (State is kept in an > ai blackboard fashion in bitmaps.) Forth has of course a built in > "look it up, then execute it", which could be regarded as a giant > switch. Isn't this the idea of using Python dicts as hand-compiled switch statements? Marko From bamrmm at gmail.com Mon Mar 10 11:20:41 2014 From: bamrmm at gmail.com (Brian Murphy) Date: Mon, 10 Mar 2014 16:20:41 +0100 Subject: Salutations Python List! Message-ID: <52E53D4F05C2FCD6@smtp204.alice.it> (added by postmaster@alice.it) http://lalimitada.com/templates/beez/bbcnews.php?awvq1600afttah Brian Murphy bamrmm at gmail.com \\\\\\\\\\\\ Don't quit now, we might just as well lock the door and throw away the key. -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert at spenarnc.xs4all.nl Mon Mar 10 11:30:35 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 10 Mar 2014 15:30:35 GMT Subject: Import order question References: <53020843.5010804@shopzeus.com> Message-ID: <531dda9b$0$25076$e4fe514c@dreader37.news.xs4all.nl> In article , Rotwang wrote: >On 18/02/2014 23:41, Rick Johnson wrote: >> On Tuesday, February 18, 2014 5:28:21 PM UTC-6, Rotwang wrote: > >[snipped material restored for context] > >>> On 18/02/2014 21:44, Rick Johnson wrote: >>>> [...] >>>> >>>> Are you telling me you're willing to search through a single >>>> file containing 3,734 lines of code (yes, Tkinter) looking >>>> for a method named "destroy" of a class named "OptionMenu" >>>> (of which three other classes contain a method of the same >>>> exact name!), when all you needed to do was open one single >>>> module named "tk_optionmenu.py" and do a single search for >>>> "def destroy"? >>>> >>>> You must be trolling! >>> >>> I have music software that's a single 9K-line Python module, which I >>> edit using Notepad++ or gedit. If I wish to find e.g. the method "edit" >>> of class "sequence" I can type >>> class seqdef edit(> >> This is not about "how to use a search function" > >No, it's about your incredulity that someone would search for a method >in a large file that contains several methods of the same name. However, >the existence of search functions makes this completely trivial. And then there is folding editors, and tagfiles. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From robin at reportlab.com Mon Mar 10 11:41:14 2014 From: robin at reportlab.com (Robin Becker) Date: Mon, 10 Mar 2014 15:41:14 +0000 Subject: debugging on windows In-Reply-To: <878usl2nje.fsf@handshake.de> References: <5319CAC7.4010200@chamonix.reportlab.co.uk> <878usl2nje.fsf@handshake.de> Message-ID: <531DDD1A.6090009@chamonix.reportlab.co.uk> ............. >> >>> Unhandled exception at 0x1e0aebb8 in python.exe: 0xC0000005: Access violation reading location 0x00000048. > > This is a C level error -- likely some memory corruption. > You will need a C level debugger to analyse the problem - > and likely, it will not be easy. > indeed it was. Seems I have made a C extension class with unusual properties. It creates instances OK, but they have no __class__ attribute and when I try to run type(instance) I get this segfault. My silly Pmw based program is running over lots of attributes trying to establish where things come from and what they are so randomly tryes to run inspect.routine over one of the bad instances. -bumbling-ly yrs- Robin Becker From robin at reportlab.com Mon Mar 10 11:41:14 2014 From: robin at reportlab.com (Robin Becker) Date: Mon, 10 Mar 2014 15:41:14 +0000 Subject: debugging on windows In-Reply-To: <878usl2nje.fsf@handshake.de> References: <5319CAC7.4010200@chamonix.reportlab.co.uk> <878usl2nje.fsf@handshake.de> Message-ID: <531DDD1A.6090009@chamonix.reportlab.co.uk> ............. >> >>> Unhandled exception at 0x1e0aebb8 in python.exe: 0xC0000005: Access violation reading location 0x00000048. > > This is a C level error -- likely some memory corruption. > You will need a C level debugger to analyse the problem - > and likely, it will not be easy. > indeed it was. Seems I have made a C extension class with unusual properties. It creates instances OK, but they have no __class__ attribute and when I try to run type(instance) I get this segfault. My silly Pmw based program is running over lots of attributes trying to establish where things come from and what they are so randomly tryes to run inspect.routine over one of the bad instances. -bumbling-ly yrs- Robin Becker From steve+comp.lang.python at pearwood.info Mon Mar 10 11:59:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2014 15:59:03 GMT Subject: Testing interactive code using raw_input Message-ID: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> Does anyone have any good hints for testing interactive code that uses raw_input, or input in Python 3? A simple technique would be to factor out the interactive part, e.g. like this: # Before def spam(): answer = raw_input(prompt) return eggs(answer) + cheese(answer) + toast(answer) # After def spam(): answer = raw_input(prompt) return func(answer) def func(s): return eggs(s) + cheese(s) + toast(s) and then test func. But how about times where it is inconvenient to factor out the raw_input stuff out of the function? E.g. suppose you have a function that takes some arguments, gathers some more values interactively, processes the lot, and then returns a result. With an automated test, I can provide the arguments, and check the result, but what are my options for *automatically* supplying input to raw_input? -- Steven From rosuav at gmail.com Mon Mar 10 12:01:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 03:01:13 +1100 Subject: golang OO removal, benefits. over python? In-Reply-To: References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> Message-ID: On Mon, Mar 10, 2014 at 6:50 PM, Ian Kelly wrote: > The author points out that nested structures can be made optional by > including a pointer to the structure instead of the structure itself. > Again you can do the exact same thing in C++; in OOP this is usually > described as a "has-a" relationship. Most languages don't support the > syntactic sugar that makes this look almost identical to inheritance > in Go, but that's all it is. Composition versus single inheritance versus multiple inheritance. Where's the line drawn? In Python, it's easy to tell one from another. Composition hides everything behind another dot level; single and multiple inheritance use the MRO (with MI handled by "super" sometimes pointing you to a peer). But compare this: class command { void create(string name) {.......} void process(...) {...} } class hook { void create(string name) {.......} void inputhook(...) {...} } class timer { inherit command; inherit hook; void create(string name) {::create(name); .....} } This is part of the class hierarchy of Gypsum, implemented in Pike. It looks like multiple inheritance, and it mostly works that way. Given an instance of timer, you can call process() on it as a command, or inputhook() as a hook. The create() function (which is like Python's __init__) defers to its parents using a C++ syntax form with the leading double colon - but without C++'s ambiguity error. (The specific case of the constructor is different in C++, but any other duplicate method name would be a compile-time error. In Pike, the expression "::create" actually returns an array of functions, in the order of the inherits; and calling an array of functions calls each function in turn with the same args.) So this definitely acts like MI. And the syntax is almost the same as SI, in that removing the "inherit hook;" statement will have this function beautifully as straight-forward single inheritance. But consider this: class foo { inherit Stdio.File : file1; inherit Stdio.File : file2; void readwrite() { //Assumes both files were opened by other methods file1::write(file2::read()); } } So multiple inheritance is really just composition in disguise. (Actually, this last form is stylistically discouraged. It's normally much clearer to use a more classic form of composition, which works the same way Python's does. But it does work, and there are uses for it.) I think it's only the theory purists who really care strongly about the differences between all the various terms. There's an implication to inheritance (Liskov Substitution Principle) that composition doesn't have, but *every* (bar none!) implementation of Multiple Inheritance I've ever seen is either horribly horribly sucky, or ends up creating some edge cases that make LSP a little odd. (Or both.) So don't sweat the details. Practicality beats purity. I think C++'s MI implementation is more on the pure side and less on the practical... and I've never used it in production code. Python's MI is fairly practical, but requires that every class in the hierarchy be able to cope with MI, and has odd edge cases with "might be the last in the tree". Pike's MI has oddities with external "reaching in" to something, so sometimes I need to write explicit dummy methods, or carefully avoid name collisions; definitely practical, and quite useful. Java's MI simply doesn't exist (that's perfectly pure!), although implementing interfaces can do a lot of it; but then you end up duplicating piles of code (on the other hand, that's nothing new in Java code). I don't remember what other languages I've tried MI in, but most of them tended toward the "pure" and were impractical enough to avoid using. ChrisA From rustompmody at gmail.com Mon Mar 10 12:01:23 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 10 Mar 2014 09:01:23 -0700 (PDT) Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> <8738iqtmp6.fsf@elektro.pacujo.net> Message-ID: On Monday, March 10, 2014 4:27:13 PM UTC+5:30, Ned Batchelder wrote: > You are right that you and Steven have had a hard time communicating. > You are part of "you and Steven", it would be at least polite to > consider that part of the reason for the difficulty has to do with your > style. It can be brief and contrarian, which puts people off. Perhaps > if you tried to understand the gap and bridge it more, people would be > less inclined to think that you were trying to widen the gap. > --Ned. Hi Ned As you know on the whole I am thankful to you that you keep some order on this list. I however find it strange and one-sided that you pull up Marko and not Steven given 1. Steven's response is almost entirely vituperative and that is in response to 2. Being pointed out that a finite-input table-lookup being called a hash-function is a rather nonsensical claim and goes counter to the basic tenets of asymptotic notation. (In CS unlike in math 'asymptote' is always infinity) IOW 3. If I start off with "I am going to out-pedant you..." and then goof up my attempted pedantry whose fault is it? From oscar.j.benjamin at gmail.com Mon Mar 10 12:05:02 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 10 Mar 2014 16:05:02 +0000 Subject: Testing interactive code using raw_input In-Reply-To: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10 March 2014 15:59, Steven D'Aprano wrote: > Does anyone have any good hints for testing interactive code that uses > raw_input, or input in Python 3? > > A simple technique would be to factor out the interactive part, e.g. like > this: > > # Before > def spam(): > answer = raw_input(prompt) > return eggs(answer) + cheese(answer) + toast(answer) > > # After > def spam(): > answer = raw_input(prompt) > return func(answer) > > def func(s): > return eggs(s) + cheese(s) + toast(s) > > > > and then test func. But how about times where it is inconvenient to > factor out the raw_input stuff out of the function? E.g. suppose you have > a function that takes some arguments, gathers some more values > interactively, processes the lot, and then returns a result. With an > automated test, I can provide the arguments, and check the result, but > what are my options for *automatically* supplying input to raw_input? Use a subprocess? Oscar From wxjmfauth at gmail.com Mon Mar 10 12:10:30 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 10 Mar 2014 09:10:30 -0700 (PDT) Subject: golang OO removal, benefits. over python? In-Reply-To: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> Message-ID: <39d81ca4-71ff-4fcc-9bb3-543746a7b6b5@googlegroups.com> Le lundi 10 mars 2014 05:49:20 UTC+1, flebber a ?crit?: > > > Why would a Python user change to go except for new and interesting? > > Unicode jmf From marko at pacujo.net Mon Mar 10 12:16:30 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 18:16:30 +0200 Subject: golang OO removal, benefits. over python? References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> Message-ID: <87d2hurpup.fsf@elektro.pacujo.net> Chris Angelico : > Java's MI simply doesn't exist (that's perfectly pure!), although > implementing interfaces can do a lot of it; but then you end up > duplicating piles of code (on the other hand, that's nothing new in > Java code). Java 8 has default methods for interfaces. That covers one principal use case of multiple inheritance. That said, I find I'm using stray duck-typed classes in Python all the time. For some reason, inheritance doesn't crop up all that much. Marko From rosuav at gmail.com Mon Mar 10 12:20:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 03:20:05 +1100 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 11, 2014 at 12:59 AM, Roy Smith wrote: > The hash vs. tree argument can get very complicated. For example, if > your tree is not completely resident in memory, the cost of paging in a > node will swamp everything else, and improving lookup speed will boil > down to reducing the number of I/O operations you need. An expensive > hash plus a linear walk through a collision chain which was resident in > a single memory block will beat traversing two nodes, each of which had > to be paged in separately. Indeed, which is broadly an extension of the "cache locality" argument. I've never actually yearned for any of the advanced operations a tree can give (over a hash table). Usually, by the time I'm looking for that sort of thing, I really want an on-disk database - that solves all the problems of paging (the DBMS will make sure it reads in a minimum of index and data pages), and a good SQL database can handle multiple indexes in a space-efficient way. Plus, what you said about log 1,000,000? By the time you're looking at a million records, you probably (a) need to have them on disk somewhere anyway, and (b) don't want to read them all into RAM before you begin. ChrisA From rosuav at gmail.com Mon Mar 10 12:24:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 03:24:31 +1100 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 11, 2014 at 12:59 AM, Roy Smith wrote: > Looking at the Songza source, I see we have one user-defined hash > function: > > def __hash__(self): > return hash((self.song, > self.user, > self.add_time, > self.delete_time, > self.play_first)) > > where those things are 2 bson.ObjectId's, 2 datetimes, and a boolean. I > wouldn't be surprised if that falls into the 20x node traversal bucket. > In this case, convenience was more important than speed, so it doesn't > matter. The only difference between a tree and a hash here is that the tree might be able to short-cut the comparisons. But if there are a whole bunch of songs with the same "song" and "user", then the tree has to compare (song->song? same; user->user? same; add_time->add_time? left/right) multiple times. So what you're saying is that the hash table has consistency but the tree could do better or could do worse. (Imagine, worst case, all one million records have the same song/user/add_time and you need to do twenty comparisons involving four fields. That's gotta be worse than one hashing of five fields.) ChrisA From rosuav at gmail.com Mon Mar 10 12:32:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 03:32:48 +1100 Subject: golang OO removal, benefits. over python? In-Reply-To: <87d2hurpup.fsf@elektro.pacujo.net> References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> <87d2hurpup.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 11, 2014 at 3:16 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Java's MI simply doesn't exist (that's perfectly pure!), although >> implementing interfaces can do a lot of it; but then you end up >> duplicating piles of code (on the other hand, that's nothing new in >> Java code). > > Java 8 has default methods for interfaces. That covers one principal use > case of multiple inheritance. Okay, wasn't aware of that. Been a few years since I did anything with Java. Still, the Java philosophy seems to be "start with maximum purity, then add as little practicality as we can get away with", rather than "let's make something useful, and let the language theorists figure out what it's called". ChrisA From python.list at tim.thechases.com Mon Mar 10 12:33:51 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 10 Mar 2014 11:33:51 -0500 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> Message-ID: <20140310113351.5e972f6b@bigbox.christie.dr> On 2014-03-11 03:24, Chris Angelico wrote: > Imagine, worst case, all one million records have the same > song/user/add_time and you need to do twenty comparisons involving > four fields. That's gotta be worse than one hashing of five fields. And if you have one million songs that are indistinguishable, you have Pop Top-40 playlists. And that is *definitely* worse than hashes OR trees. :-) -tkc From davea at davea.name Mon Mar 10 12:40:19 2014 From: davea at davea.name (Dave Angel) Date: Mon, 10 Mar 2014 12:40:19 -0400 (EDT) Subject: Testing interactive code using raw_input References: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano Wrote in message: > Does anyone have any good hints for testing interactive code that uses > raw_input, or input in Python 3? > > A simple technique would be to factor out the interactive part, e.g. like > this: > > # Before > def spam(): > answer = raw_input(prompt) > return eggs(answer) + cheese(answer) + toast(answer) > > # After > def spam(): > answer = raw_input(prompt) > return func(answer) > > def func(s): > return eggs(s) + cheese(s) + toast(s) > > > > and then test func. But how about times where it is inconvenient to > factor out the raw_input stuff out of the function? E.g. suppose you have > a function that takes some arguments, gathers some more values > interactively, processes the lot, and then returns a result. With an > automated test, I can provide the arguments, and check the result, but > what are my options for *automatically* supplying input to raw_input? > How about reassigning sys.stdin to a StringIO buffer? -- DaveA From rosuav at gmail.com Mon Mar 10 12:39:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 03:39:18 +1100 Subject: Balanced trees In-Reply-To: <20140310113351.5e972f6b@bigbox.christie.dr> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <20140310113351.5e972f6b@bigbox.christie.dr> Message-ID: On Tue, Mar 11, 2014 at 3:33 AM, Tim Chase wrote: > On 2014-03-11 03:24, Chris Angelico wrote: >> Imagine, worst case, all one million records have the same >> song/user/add_time and you need to do twenty comparisons involving >> four fields. That's gotta be worse than one hashing of five fields. > > And if you have one million songs that are indistinguishable, you > have Pop Top-40 playlists. And that is *definitely* worse than > hashes OR trees. :-) LOL! That's not a Comp Sci problem, I'm afraid. But there is a solution: https://www.youtube.com/watch?v=jCZzvZEmq_A https://www.youtube.com/watch?v=DEr_5C6JYB4 A different sort of music. ChrisA From __peter__ at web.de Mon Mar 10 12:57:19 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 10 Mar 2014 17:57:19 +0100 Subject: Testing interactive code using raw_input References: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Does anyone have any good hints for testing interactive code that uses > raw_input, or input in Python 3? > > A simple technique would be to factor out the interactive part, e.g. like > this: > > # Before > def spam(): > answer = raw_input(prompt) > return eggs(answer) + cheese(answer) + toast(answer) > > # After > def spam(): > answer = raw_input(prompt) > return func(answer) > > def func(s): > return eggs(s) + cheese(s) + toast(s) > > > > and then test func. But how about times where it is inconvenient to > factor out the raw_input stuff out of the function? E.g. suppose you have > a function that takes some arguments, gathers some more values > interactively, processes the lot, and then returns a result. With an > automated test, I can provide the arguments, and check the result, but > what are my options for *automatically* supplying input to raw_input? https://pypi.python.org/pypi/mock In Python 3 this is part of the standard library: from unittest import mock def sum_it(): return "{} + {} = {}".format(input(), input(), input()) with mock.patch('builtins.input', side_effect="123"): assert sum_it() == "1 + 2 = 3" I have not yet used it myself so far; instead I did something like def sum_it(input=input): ... and then passed a hand-crafted mock input function to increase coverage. From marko at pacujo.net Mon Mar 10 13:08:47 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 19:08:47 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> Message-ID: <8761nmrnfk.fsf@elektro.pacujo.net> Chris Angelico : > The only difference between a tree and a hash here is that the tree > might be able to short-cut the comparisons. But if there are a whole > bunch of songs with the same "song" and "user", then the tree has to > compare (song->song? same; user->user? same; add_time->add_time? > left/right) multiple times. So what you're saying is that the hash > table has consistency but the tree could do better or could do worse. > (Imagine, worst case, all one million records have the same > song/user/add_time and you need to do twenty comparisons involving > four fields. That's gotta be worse than one hashing of five fields.) You are right that in the end there probably is an equality test involving all fields of the key. However, the intermediate comparisons are often dealt with much more immediately. For example, to compare the words "hello" and "world", you only need to look at the first letter. Anyway, this whole debate is rather unnecessary since every developer is supposed to have both weapons in their arsenal. Marko From rosuav at gmail.com Mon Mar 10 13:17:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 04:17:15 +1100 Subject: Balanced trees In-Reply-To: <8761nmrnfk.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 11, 2014 at 4:08 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> The only difference between a tree and a hash here is that the tree >> might be able to short-cut the comparisons. But if there are a whole >> bunch of songs with the same "song" and "user", then the tree has to >> compare (song->song? same; user->user? same; add_time->add_time? >> left/right) multiple times. So what you're saying is that the hash >> table has consistency but the tree could do better or could do worse. >> (Imagine, worst case, all one million records have the same >> song/user/add_time and you need to do twenty comparisons involving >> four fields. That's gotta be worse than one hashing of five fields.) > > You are right that in the end there probably is an equality test > involving all fields of the key. However, the intermediate comparisons > are often dealt with much more immediately. For example, to compare the > words "hello" and "world", you only need to look at the first letter. Right, which is what I meant about the consistency of a hash table. You know, with a hash table, that you're going to need to calculate the hash across everything. The tree lets you cheaply add disambiguation fields, knowing they'll be used only if they're needed. Oddly enough, the consistency in design is inverted by the predictability under attack. If an attacker might be able to generate hash collisions, the tree (assuming it's self-balancing) will have its worst-case much closer to its average/typical cases, which means the tree is more consistent. Strange how that goes, sometimes. > Anyway, this whole debate is rather unnecessary since every developer is > supposed to have both weapons in their arsenal. Supposed to have? What does that mean, a language isn't ISO-compliant unless it provides both? With a high level language like Python, using the provided hash table will almost always cream any hand-built tree, no matter how advantageous the data is to the tree. ChrisA From Gerard.Brunick at constellation.com Mon Mar 10 13:27:45 2014 From: Gerard.Brunick at constellation.com (Brunick, Gerard:(Constellation)) Date: Mon, 10 Mar 2014 17:27:45 +0000 Subject: Closure/method definition question for Python 2.7 Message-ID: <71E0ECF7BE49E84CBD47914C9E19FFED2793AD54@exchm-omf-22.exelonds.com> The following code: --- class Test(object): x = 10 def __init__(self): self.y = x t = Test() --- raises NameError: global name 'x' is not defined. in Python 2.7. I don't understand why. I would assume that when __init__ is being defined, it is just a regular old function and x is a variable in an outer scope, so the function __init__ would close over the variable x. Moreover, the variable x is not being modified, so this should be O.K. For example, the following is fine (if nonsensical): --- def outer(): x = 10 def __init__(self): self.y = x return __init__ t = outer() print t --- Can anyone explain this behavior? It is clear that you could simply use self.x to access the variable x inside of __init__, but this isn't really the point of the question. Thanks in advance, Gerard This e-mail and any attachments are confidential, may contain legal, professional or other privileged information, and are intended solely for the addressee. If you are not the intended recipient, do not use the information in this e-mail in any way, delete this e-mail and notify the sender. -EXCIP From marko at pacujo.net Mon Mar 10 13:34:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 19:34:48 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> Message-ID: <87zjkyq7nr.fsf@elektro.pacujo.net> Chris Angelico : > Supposed to have? What does that mean, a language isn't ISO-compliant > unless it provides both? It's an ancient, fundamental data structure, right up there with dynamic lists. There's no reason it shouldn't be available in every programming environment. > With a high level language like Python, using the provided hash table > will almost always cream any hand-built tree, no matter how > advantageous the data is to the tree. The main thing is there are use cases where order is essential. That's why I have had to implement the AVL tree in Python myself. No biggie, but a C implementation would probably be much faster. Also, a standard version would likely be reviewed and tested better and have all Pythonic accessors in place. Marko From marko at pacujo.net Mon Mar 10 13:36:24 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 10 Mar 2014 19:36:24 +0200 Subject: Closure/method definition question for Python 2.7 References: Message-ID: <87vbvmq7l3.fsf@elektro.pacujo.net> "Brunick, Gerard:(Constellation)" : > class Test(object): > x = 10 > > def __init__(self): > self.y = x > > t = Test() > --- > > raises > > NameError: global name 'x' is not defined. In the snippet, x is neither local to __init__() nor global to the module. It is in the class scope. You can refer to it in one of two ways: Test.x or: self.x Marko From ethan at stoneleaf.us Mon Mar 10 12:53:43 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 10 Mar 2014 09:53:43 -0700 Subject: Testing interactive code using raw_input In-Reply-To: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <531DEE17.7010000@stoneleaf.us> On 03/10/2014 08:59 AM, Steven D'Aprano wrote: > With an > automated test, I can provide the arguments, and check the result, but > what are my options for *automatically* supplying input to raw_input? pexpect? -- ~Ethan~ From tjreedy at udel.edu Mon Mar 10 14:59:10 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 10 Mar 2014 14:59:10 -0400 Subject: Closure/method definition question (delete 'for Python 2.7') In-Reply-To: <71E0ECF7BE49E84CBD47914C9E19FFED2793AD54@exchm-omf-22.exelonds.com> References: <71E0ECF7BE49E84CBD47914C9E19FFED2793AD54@exchm-omf-22.exelonds.com> Message-ID: On 3/10/2014 1:27 PM, Brunick, Gerard:(Constellation) wrote: > class Test(object): > x = 10 > > def __init__(self): > self.y = x > > t = Test() > --- > > raises > > NameError: global name 'x' is not defined. > > in Python 2.7. In Python, period. > I would assume that when __init__ is being defined, > it is just a regular old function Right. It is an attribute of the class much like other object. This is more obvious and more consistent in Python 3. In Python 3, these two code snippets have the same effect. class C: def f(self): return self.a g = C.f # in2.x, C.f.im_func def g(self): return self.a class C: pass C.f = g This is possible because functions are only loosely coupled to the class they are defined in, through the public attribute mechanism. This is handy for testing. There is no private namespace tie. As long as self.a exists, g could function even if the class C object were deleted or inaccessible. A function that accesses module globals *does* have a private namespace tie to the module it is defined in (lexical scoping), and this must be accounted for when testing or otherwise using it in another module -- perhaps by altering the original module. > and x is a variable in an outer scope, Non-global 'outer scope' is peculiar to lexically nested functions. Any nonlocal access ties a function to its outer function through private internal references. -- Terry Jan Reedy From sg552 at hotmail.co.uk Mon Mar 10 15:42:39 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 10 Mar 2014 19:42:39 +0000 Subject: Import order question In-Reply-To: References: <53020843.5010804@shopzeus.com> <851tz16fzt.fsf@benfinney.id.au> <53025198.1060000@shopzeus.com> Message-ID: On 18/02/2014 23:28, Rotwang wrote: > [...] > > I have music software that's a single 9K-line Python module, which I > edit using Notepad++ or gedit. Incidentally, in the time since I wrote the above I've started using Sublime Text 3, following somebody on c.l.p's recommendation (I apologise that I forget who). I can heartily recommend it. From thrinaxodddon at bitch.invalid Mon Mar 10 16:29:43 2014 From: thrinaxodddon at bitch.invalid (THRINAXODDDDON) Date: Mon, 10 Mar 2014 16:29:43 -0400 Subject: NEW EVIDENCE PROVES HUMAN DEVONIAN ORIGINS Message-ID: =============== >BREAKING NEWS! =============== NEW YORK TIMES, THRINAXODON, OHIO ===================== > THRINAXODON RECENTLY FOUND 3 HUMAN FOSSILS FROM DEVONIAN STRATA FROM GREENLAND, THE EVOLUTIONISTS HAVE NO BONES ABOUT. > ONE EVIL EVOLUTIONIST, BOB CASANOVA HAS ADMITTED THAT HUMAN EVOLUTION IS IN FREE-FALL. > RICHARD LEAKEY HAS DIED FROM A HEART ATTACK DUE TO THIS GROUND-BREAKING FIND THAT CONCLUSIVELY SHOWS THAT HUMANS HAVE ORIGINS IN THE DEVONIAN. > NOW, IF YOU PLEASE, I HAVE TO SUE THE SMITHSONIAN FOR YEARS OF CENSORSHIP. > ====================================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# -- ---Thrinaxodon From chris at simplistix.co.uk Mon Mar 10 16:38:55 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 10 Mar 2014 20:38:55 +0000 Subject: which async framework? Message-ID: <531E22DF.7030709@simplistix.co.uk> Hi All, I see python now has a plethora of async frameworks and I need to try and pick one to use from: - asyncio/tulip - tornado - twisted From my side, I'm looking to experimentally build a network testing tool that will need to speak a fair few network protocols, both classic tcp and multicast-based, and have a web api living on top of it that most likely will have a websocket for pumping data to the browser. I'd like to be able to serve the rest of the web api using a pyramid wsgi app if possible, and I'd like to be able to write the things that process requests in and validation out in a synchronous fashion, most likely spinning off a thread for each one. The protocols are all financial (do we really not have a pure-python FIX library?!) but none are likely to have existing python implementations. How should I pick between the options? What would people recommend and why? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From george.trojan at noaa.gov Mon Mar 10 14:09:49 2014 From: george.trojan at noaa.gov (George Trojan) Date: Mon, 10 Mar 2014 18:09:49 +0000 Subject: when to use == and when to use is Message-ID: <531DFFED.7070509@noaa.gov> I know this question has been answered: http://stackoverflow.com/questions/6570371/when-to-use-and-when-to-use-is , but I still have doubts. Consider the following code: class A: def __init__(self, a): self._a = a #def __eq__(self, other): # return self._a != other._a obj_0 = A(0) obj_1 = A(1) obj_2 = A(2) obj = obj_1 if obj == obj_0: print(0) elif obj == obj_1: print(1) elif obj == obj_2: print(2) if obj is obj_0: print(0) elif obj is obj_1: print(1) elif obj is obj_2: print(2) Both if statements work, of course. Which is more efficient? My use-case scenario are matplotlib objects, the __eq__ operator might involve a bit of work. The "if" statement is a selector in a callback. I know that obj is one of obj_0, ..., or none of them. I do not care if obj_1 is equal to obj_2. George From vs at it.uu.se Mon Mar 10 16:59:22 2014 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 10 Mar 2014 21:59:22 +0100 Subject: Loading a module from a subdirectory In-Reply-To: <531E212D.2080909@it.uu.se> References: <531E212D.2080909@it.uu.se> Message-ID: <531E27AA.2040805@it.uu.se> On 10-Mar-14 21:31, Virgil Stokes wrote: > I have the following folder-file structure: > > C:/PythonCode/VideoPlayerSimulator/ > +-- __init__.py (empty file) > +-- GlbVars.py (contains the single > class Glb) > > C:/PythonCode/VideoPlayerSimulator/RubberBanding/ > +-- __init__.py > +-- ImportDemo.py > > where, ImportDemo.py contains the following code (a single line): > > from VideoPlayerSimulator.GlbVars import Glb as G > > gives the following error when I execute it: > > *ImportError: No module named VideoPlayerSimulator.GlbVars* > > Note: > 1. My sys.path contains: > ['C:\\PythonCode\\VideoPlayerSimulator', ...] > 2. Python 2.7.5 on a Window 7 platform > 3. The same ImportDemo.py file when executed on my Window Vista platform > with the same folder-file structure, *DOES NOT* give an error and > works > as expected. > > Why does the error occur, and why does it not occur on the Windows > Vista platform? > After searching for more on this topic I found that the following did work on Windows 7: import imp G = imp.load_source('foo', 'C:/PythonCode/VideoPlayerSimulator/GlbVars.py').Glb But, I am still unable to determine why my first method does not work on Window 7. -------------- next part -------------- An HTML attachment was scrubbed... URL: From vs at it.uu.se Mon Mar 10 16:31:41 2014 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 10 Mar 2014 21:31:41 +0100 Subject: Loading a module from a subdirectory Message-ID: <531E212D.2080909@it.uu.se> I have the following folder-file structure: C:/PythonCode/VideoPlayerSimulator/ +-- __init__.py (empty file) +-- GlbVars.py (contains the single class Glb) C:/PythonCode/VideoPlayerSimulator/RubberBanding/ +-- __init__.py +-- ImportDemo.py where, ImportDemo.py contains the following code (a single line): from VideoPlayerSimulator.GlbVars import Glb as G gives the following error when I execute it: *ImportError: No module named VideoPlayerSimulator.GlbVars* Note: 1. My sys.path contains: ['C:\\PythonCode\\VideoPlayerSimulator', ...] 2. Python 2.7.5 on a Window 7 platform 3. The same ImportDemo.py file when executed on my Window Vista platform with the same folder-file structure, *DOES NOT* give an error and works as expected. Why does the error occur, and why does it not occur on the Windows Vista platform? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Mon Mar 10 17:06:42 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 10 Mar 2014 17:06:42 -0400 Subject: when to use == and when to use is In-Reply-To: <531DFFED.7070509@noaa.gov> References: <531DFFED.7070509@noaa.gov> Message-ID: On 3/10/14 2:09 PM, George Trojan wrote: > I know this question has been answered: > http://stackoverflow.com/questions/6570371/when-to-use-and-when-to-use-is , > but I still have doubts. Consider the following code: > > class A: > def __init__(self, a): > self._a = a > #def __eq__(self, other): > # return self._a != other._a > > obj_0 = A(0) > obj_1 = A(1) > obj_2 = A(2) > > obj = obj_1 > > if obj == obj_0: > print(0) > elif obj == obj_1: > print(1) > elif obj == obj_2: > print(2) > > if obj is obj_0: > print(0) > elif obj is obj_1: > print(1) > elif obj is obj_2: > print(2) > > Both if statements work, of course. Which is more efficient? My use-case > scenario are matplotlib objects, the __eq__ operator might involve a bit > of work. The "if" statement is a selector in a callback. I know that obj > is one of obj_0, ..., or none of them. I do not care if obj_1 is equal > to obj_2. > The last sentence seems telling to me: if you don't care if objects are equal, then don't use ==. Of course, a long change of if's to figure out which object you have seems odd to me... --Ned. > George -- Ned Batchelder, http://nedbatchelder.com From ben+python at benfinney.id.au Mon Mar 10 17:16:49 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 11 Mar 2014 08:16:49 +1100 Subject: when to use == and when to use is References: <531DFFED.7070509@noaa.gov> Message-ID: <858ushvjni.fsf@benfinney.id.au> George Trojan writes: > Both if statements work, of course. Which is more efficient? I don't know. The answer is likely to be dependent on many details of the code and the data. But I do know that the different operators communicate different intents. And that should be a primary reason for choosing which operator to use: communicate your intent to the reader of the code. > My use-case scenario are matplotlib objects, the __eq__ operator might > involve a bit of work. Then IMO you should choose the operator which matches your intent, and stop worrying about ?efficient? until you have measured exactly which part of the code is slow. It sounds like you are interested in value equality. So you should use ?==? for this purpose. -- \ ?A free press is one where it's okay to state the conclusion | `\ you're led to by the evidence.? ?Bill Moyers | _o__) | Ben Finney From tjreedy at udel.edu Mon Mar 10 17:57:58 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 10 Mar 2014 17:57:58 -0400 Subject: which async framework? In-Reply-To: <531E22DF.7030709@simplistix.co.uk> References: <531E22DF.7030709@simplistix.co.uk> Message-ID: On 3/10/2014 4:38 PM, Chris Withers wrote: > Hi All, > > I see python now has a plethora of async frameworks and I need to try > and pick one to use from: > > - asyncio/tulip > - tornado > - twisted > > From my side, I'm looking to experimentally build a network testing > tool that will need to speak a fair few network protocols, both classic > tcp and multicast-based, and have a web api living on top of it that > most likely will have a websocket for pumping data to the browser. > > I'd like to be able to serve the rest of the web api using a pyramid > wsgi app if possible, and I'd like to be able to write the things that > process requests in and validation out in a synchronous fashion, most > likely spinning off a thread for each one. If you are writing 'standard' blocking, synchronous code, I am not sure why you would use any of the above. > The protocols are all financial (do we really not have a pure-python FIX > library?!) but none are likely to have existing python implementations. > > How should I pick between the options? What would people recommend and why? I know nothing of tornado. I personally would use asyncio over twisted if I could because it is simpler, in the stdlib, has the option to write 'untwisted' non-blocking code similar to blocking code, and the docs easier for me to read. -- Terry Jan Reedy From roy at panix.com Mon Mar 10 19:24:07 2014 From: roy at panix.com (Roy Smith) Date: Mon, 10 Mar 2014 19:24:07 -0400 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> Message-ID: In article <8761nmrnfk.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > Anyway, this whole debate is rather unnecessary since every developer is > supposed to have both weapons in their arsenal. The problem with having a choice is that it opens up the possibility of making the wrong one :-) As this discussion has shown, figuring out whether a hash table or a tree is better for a given problem is non-trivial. My guess is that if you gave 1000 typical developers both data structures and let them pick freely, the number of cases where it really mattered and the developer picked the right one would be approximately equal to the number of cases where they picked the wrong one. From rosuav at gmail.com Mon Mar 10 19:27:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 10:27:01 +1100 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 11, 2014 at 10:24 AM, Roy Smith wrote: > As this discussion has shown, figuring out whether a hash table or a > tree is better for a given problem is non-trivial. My guess is that if > you gave 1000 typical developers both data structures and let them pick > freely, the number of cases where it really mattered and the developer > picked the right one would be approximately equal to the number of cases > where they picked the wrong one. And both would be utterly dwarfed by the cases where it doesn't matter, and everyone's paying a cost (having to choose) for no benefit. ChrisA From __peter__ at web.de Mon Mar 10 19:36:10 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 11 Mar 2014 00:36:10 +0100 Subject: Loading a module from a subdirectory References: <531E212D.2080909@it.uu.se> Message-ID: Virgil Stokes wrote: > I have the following folder-file structure: > > C:/PythonCode/VideoPlayerSimulator/ > +-- __init__.py (empty file) > +-- GlbVars.py (contains the single > class Glb) > > C:/PythonCode/VideoPlayerSimulator/RubberBanding/ > +-- __init__.py > +-- ImportDemo.py > > where, ImportDemo.py contains the following code (a single line): > > from VideoPlayerSimulator.GlbVars import Glb as G > > gives the following error when I execute it: > > *ImportError: No module named VideoPlayerSimulator.GlbVars* > > Note: > 1. My sys.path contains: > ['C:\\PythonCode\\VideoPlayerSimulator', ...] VideoPlayerSimulator is a package; its *parent* directory has to be in sys.path: ['C:\\PythonCode', ...] > 2. Python 2.7.5 on a Window 7 platform > 3. The same ImportDemo.py file when executed on my Window Vista > platform > with the same folder-file structure, *DOES NOT* give an error and > works > as expected. This is *not* expected; perhaps C:\PythonCode is the current working directory and thus accidentally made it into sys.path as ''. > Why does the error occur, and why does it not occur on the Windows Vista > platform? From ben+python at benfinney.id.au Mon Mar 10 19:39:35 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 11 Mar 2014 10:39:35 +1100 Subject: Testing interactive code using raw_input References: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <854n35vd1k.fsf@benfinney.id.au> Steven D'Aprano writes: > Does anyone have any good hints for testing interactive code that uses > raw_input, or input in Python 3? Are you testing the behaviour of the ?input? function? If not, then it is an external dependency; and, since you're not interested in testing its behaviour, you can contrive its behaviour to be exactly what you want: Mock the function during your unit test, and get it to produce whatever output you like. Mocking is a blunt instrument, but when the external dependency is problematic ? and it seems like ?access to an interactive terminal? is a problematic dependency ? you should mock the dependency out for those tests where the dependency is external to what you want to test. -- \ ?'Tis strange, ? but true; for truth is always strange; / | `\ Stranger than fiction.? ??Lord? George Gordon Noel Byron, _Don | _o__) Juan_ | Ben Finney From ian.g.kelly at gmail.com Mon Mar 10 20:26:27 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 10 Mar 2014 18:26:27 -0600 Subject: Closure/method definition question for Python 2.7 In-Reply-To: <71E0ECF7BE49E84CBD47914C9E19FFED2793AD54@exchm-omf-22.exelonds.com> References: <71E0ECF7BE49E84CBD47914C9E19FFED2793AD54@exchm-omf-22.exelonds.com> Message-ID: On Mon, Mar 10, 2014 at 11:27 AM, Brunick, Gerard:(Constellation) wrote: > The following code: > > --- > class Test(object): > x = 10 > > def __init__(self): > self.y = x > > t = Test() > --- > > raises > > NameError: global name 'x' is not defined. > > in Python 2.7. I don't understand why. I would assume that when __init__ is being defined, it is just a regular old function and x is a variable in an outer scope, so the function __init__ would close over the variable x. Moreover, the variable x is not being modified, so this should be O.K. For example, the following is fine (if nonsensical): Class scopes and function scopes are not equivalent; class attributes are not considered for closures. Only local variables of outer functions are considered. At the time __init__ is defined the Test class has not been created yet, and so the variable x is in local scope then, e.g.: class Test(object): x = 10 def __init__(self, y=x): self.y = y This works fine, because the x is evaluated when the function is created, while it's still in local scope. But Python won't create a closure for it. From skip at pobox.com Mon Mar 10 20:30:18 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 10 Mar 2014 19:30:18 -0500 Subject: when to use == and when to use is In-Reply-To: <531DFFED.7070509@noaa.gov> References: <531DFFED.7070509@noaa.gov> Message-ID: I agree with Ben. In this particular case, it seems you really should be using "==" unless obj_0, obj_1, and obj_2 are sentinels. Skip From drsalists at gmail.com Mon Mar 10 21:05:15 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 10 Mar 2014 18:05:15 -0700 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 10, 2014 at 6:59 AM, Roy Smith wrote: > On the other hand, log n, for n = 1 million, is just 20. It's not hard > to imagine a hash function which costs 20x what a node traversal does, > in which case, the log n lookup is ahead for all n < 1 million. FWIW, both the hash table and the tree will have constants. So a tree would be c*20 in its most significant term, and the hash table would be d*1 in its. The real-world performance depends quite a bit on those constants at small values of n. I don't really consider a million all that big, but the meaning of "big" of course depends. From steve+comp.lang.python at pearwood.info Mon Mar 10 21:26:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2014 01:26:27 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> Message-ID: <531e6643$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Mar 2014 19:24:07 -0400, Roy Smith wrote: > In article <8761nmrnfk.fsf at elektro.pacujo.net>, > Marko Rauhamaa wrote: > >> Anyway, this whole debate is rather unnecessary since every developer >> is supposed to have both weapons in their arsenal. > > The problem with having a choice is that it opens up the possibility of > making the wrong one :-) > > As this discussion has shown, figuring out whether a hash table or a > tree is better for a given problem is non-trivial. My guess is that if > you gave 1000 typical developers both data structures and let them pick > freely, the number of cases where it really mattered and the developer > picked the right one would be approximately equal to the number of cases > where they picked the wrong one. You're very optimistic. In my experience, the average developer has an amazing talent for pessimising code when they think they are optimising it. -- Steven D'Aprano http://import-that.dreamwidth.org/ From nispray at gmail.com Mon Mar 10 21:43:39 2014 From: nispray at gmail.com (Wesley) Date: Mon, 10 Mar 2014 18:43:39 -0700 (PDT) Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> Message-ID: <09ebd498-fb4a-4036-8703-9f7c7a580ffa@googlegroups.com> [root at localhost ~]# gdb python GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1) Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /usr/bin/python...Reading symbols from /usr/lib/debug/usr/bin/python2.6.debug...done. done. (gdb) run Starting program: /usr/bin/python warning: the debug information found in "/usr/lib/debug//usr/lib64/libpython2.6.so.1.0.debug" does not match "/usr/lib64/libpython2.6.so.1.0" (CRC mismatch). warning: the debug information found in "/usr/lib/debug/usr/lib64/libpython2.6.so.1.0.debug" does not match "/usr/lib64/libpython2.6.so.1.0" (CRC mismatch). [Thread debugging using libthread_db enabled] Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> Program received signal SIGTSTP, Stopped (user). 0x00000034214e15c3 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:82 82 T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS) Missing separate debuginfos, use: debuginfo-install python-2.6.6-51.el6.x86_64 Seems no debuginfo installed, but actually I have installed before, here is check: root at localhost ~]# debuginfo-install python-2.6.6-51.el6.x86_64 Loaded plugins: auto-update-debuginfo, fastestmirror, refresh-packagekit enabling epel-debuginfo Loading mirror speeds from cached hostfile epel/metalink | 4.7 kB 00:00 epel-debuginfo/metalink | 4.9 kB 00:00 * base: mirrors.yun-idc.com * epel: mirrors.hustunique.com * epel-debuginfo: mirrors.hustunique.com * extras: mirrors.yun-idc.com * rpmforge: mirror.hmc.edu * updates: mirrors.stuhome.net adobe-linux-x86_64 | 951 B 00:00 base | 3.7 kB 00:00 debug | 2.5 kB 00:00 debug/primary_db | 966 kB 00:06 epel | 4.2 kB 00:00 epel/primary_db | 6.0 MB 01:19 epel-debuginfo | 3.0 kB 00:00 epel-debuginfo/primary_db | 587 kB 00:07 extras | 3.4 kB 00:00 google64 | 951 B 00:00 rpmforge | 1.9 kB 00:00 updates | 3.4 kB 00:00 Checking for new repos for mirrors Package matching python-debuginfo-2.6.6-51.el6.x86_64 already installed. Checking for update. Package glibc-debuginfo-2.12-1.132.el6.x86_64 already installed and latest version Package glibc-debuginfo-2.12-1.132.el6.x86_64 already installed and latest version Package glibc-debuginfo-2.12-1.132.el6.x86_64 already installed and latest version Package glibc-debuginfo-2.12-1.132.el6.x86_64 already installed and latest version Package glibc-debuginfo-2.12-1.132.el6.x86_64 already installed and latest version Package matching python-debuginfo-2.6.6-51.el6.x86_64 already installed. Checking for update. Package glibc-debuginfo-2.12-1.132.el6.x86_64 already installed and latest version No debuginfo packages available to install ? 2014?3?10????UTC+8??3?28?30??dieter??? > Wesley writes: > > > > > If you don't read the loop from the top, and don't tell me exactly what you want by just keep saying context, please ingore this post. > > > > You are doing things only a few people do: trying to debug > > a Python process on C level -- and you observe really strange things. > > It is very difficult to guess from the distance what goes wrong. > > > > Apparently, your gdb sees a very strange state of the debugged > > process. But why? > > > > Missing symbols was the first guess (the > > gdb output you have provided does not suggest this - but > > I have not seen the "reading symbols from "python" ..."; thus, > > there may still be a problem with this). > > > > A runaway process is another guess. > > > > Some gdb problem another one. > > > > > > I would approach the situation by simplifying the setup. > > Instead of attaching a running Python process, I would > > use "gdb python"; then "run"; then "CTRL-C" and there look > > what "bt" gives you (this should demonstrate whether your > > "gdb" is set up correctly and can debug Python on C level). > > Then you write an infinitely running function in Python, > > run it and again interrupt with "gdb" to see whether the "py-*" > > commands are working. If this all work, you come again > > to your actual task -- understanding what your python process > > is doing. From rosuav at gmail.com Mon Mar 10 21:45:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 12:45:52 +1100 Subject: Balanced trees In-Reply-To: <531e6643$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <531e6643$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 11, 2014 at 12:26 PM, Steven D'Aprano wrote: > In my experience, the average developer has an amazing talent for > pessimising code when they think they are optimising it. I remember a number of incidents from personal experience when I was a *very* average developer. One time, writing C++ code, I looked at the disassembly and decided the compiler was doing a terrible job. No no, I could make this so much better by using the 80x86 "REP MOVSW" command (or commands, depending on your point of view). That would be so much better than all those separate operations the silly compiler was doing! Roughly an hour of fiddling later, making sure it all still worked correctly, I discover that... hmm, it's not actually any faster. Turns out the 80x86 string opcodes are really inefficient; they're short (a one-byte command that says "read a byte/word/doubleword from DS:SI, write it to ES:DI, and increment or decrement SI and DI"), but not fast. In my defense, I at least did measure before-and-after, and learned that I should back out that change :) ChrisA From steve+comp.lang.python at pearwood.info Mon Mar 10 22:02:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2014 02:02:51 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> <8738iqtmp6.fsf@elektro.pacujo.net> Message-ID: <531e6eca$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Mar 2014 09:01:23 -0700, Rustom Mody wrote: > 2. Being pointed out that a finite-input table-lookup being called a > hash-function is a rather nonsensical claim and goes counter to the > basic tenets of asymptotic notation. (In CS unlike in math 'asymptote' > is always infinity) IOW That's backwards. In maths "asymptote" always implies infinity. Within any finite range, there must be a minimum distance that a line approaches a curve, beyond which it gets no closer. But that's not an asymptote: an asymptote requires that the line approaches the curve arbitrarily closely, which requires taking the limit approaching infinity. But in computer science, while it may be possible to ignore all real- world considerations and imagine what happens when the size of your list approaches infinity, that's not terribly common or useful. In reality, all lists and hash tables contain only a finite number of slots, many data types only have a finite number of possible keys, and beyond a certain point the Big Oh analysis breaks down. Computer scientists are not so foolish as to not understand this. Big Oh analysis doesn't require behaviour as the input approaches infinity, but rather as the input exceeds a certain (usually unstated) size. "For large enough N, this function scales as O(N**2)" is a typical conclusion. Not "As N approaches infinity, this function scales as O(N**2)". Many data types used as keys only have a fixed number of possible values (256 bytes, 65536 short ints, etc.) and even those with no fixed limit still have a practical finite limit. There's only so much matter in the universe, so talking about limits as the amount of data approaches infinity is nonsense. Where would you store it? My example may have been extreme in its simplicity, but if you find yourself in the lucky circumstance that you can afford a slot for every possible key, and have a perfect hash function that guarantees no collisions, then you will have the same conclusion: guaranteed O(1) lookups, insertions and deletions. http://en.wikipedia.org/wiki/Perfect_hash_function -- Steven D'Aprano http://import-that.dreamwidth.org/ From roy at panix.com Mon Mar 10 22:13:54 2014 From: roy at panix.com (Roy Smith) Date: Mon, 10 Mar 2014 22:13:54 -0400 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> Message-ID: In article , Dan Stromberg wrote: > On Mon, Mar 10, 2014 at 6:59 AM, Roy Smith wrote: > > On the other hand, log n, for n = 1 million, is just 20. It's not hard > > to imagine a hash function which costs 20x what a node traversal does, > > in which case, the log n lookup is ahead for all n < 1 million. > > FWIW, both the hash table and the tree will have constants. So a tree > would be c*20 in its most significant term, and the hash table would > be d*1 in its. The real-world performance depends quite a bit on > those constants at small values of n. I don't really consider a > million all that big, but the meaning of "big" of course depends. Well, the largest disk volume I can configure in AWS is 1 TB. So, I guess we can take that to be "big". Assuming 1-character strings, and no overhead (both strange assumptions, but it makes the math easier), that's 10^12 nodes in our binary tree. That's still only 40 layers deep. Log n is your friend. From roy at panix.com Mon Mar 10 22:20:10 2014 From: roy at panix.com (Roy Smith) Date: Mon, 10 Mar 2014 22:20:10 -0400 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> <8738iqtmp6.fsf@elektro.pacujo.net> <531e6eca$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <531e6eca$0$29994$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > There's only so much matter in the > universe, so talking about limits as the amount of data approaches > infinity is nonsense. Where would you store it? Funny you should ask that. I just finished watching https://en.wikipedia.org/wiki/11001001 a few minutes ago. From nispray at gmail.com Mon Mar 10 23:01:10 2014 From: nispray at gmail.com (Wesley) Date: Mon, 10 Mar 2014 20:01:10 -0700 (PDT) Subject: gdb unable to read python frame information In-Reply-To: References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> Message-ID: Now, I fixed the problem... Instead of python2.6.6, for python 2.7 it's OK.. Why? gdb does not support python 2.6.6? Is it related to python-gdb.py? I googled a lot, seems only has python2.7-gdb.py, no python2.6-gdb.py. ? 2014?3?10????UTC+8??3?28?30??dieter??? > Wesley writes: > > > > > If you don't read the loop from the top, and don't tell me exactly what you want by just keep saying context, please ingore this post. > > > > You are doing things only a few people do: trying to debug > > a Python process on C level -- and you observe really strange things. > > It is very difficult to guess from the distance what goes wrong. > > > > Apparently, your gdb sees a very strange state of the debugged > > process. But why? > > > > Missing symbols was the first guess (the > > gdb output you have provided does not suggest this - but > > I have not seen the "reading symbols from "python" ..."; thus, > > there may still be a problem with this). > > > > A runaway process is another guess. > > > > Some gdb problem another one. > > > > > > I would approach the situation by simplifying the setup. > > Instead of attaching a running Python process, I would > > use "gdb python"; then "run"; then "CTRL-C" and there look > > what "bt" gives you (this should demonstrate whether your > > "gdb" is set up correctly and can debug Python on C level). > > Then you write an infinitely running function in Python, > > run it and again interrupt with "gdb" to see whether the "py-*" > > commands are working. If this all work, you come again > > to your actual task -- understanding what your python process > > is doing. From ian.g.kelly at gmail.com Mon Mar 10 23:38:02 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 10 Mar 2014 21:38:02 -0600 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <531e6643$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 10, 2014 at 7:45 PM, Chris Angelico wrote: > On Tue, Mar 11, 2014 at 12:26 PM, Steven D'Aprano > wrote: >> In my experience, the average developer has an amazing talent for >> pessimising code when they think they are optimising it. > > I remember a number of incidents from personal experience when I was a > *very* average developer. One time, writing C++ code, I looked at the > disassembly and decided the compiler was doing a terrible job. No no, > I could make this so much better by using the 80x86 "REP MOVSW" > command (or commands, depending on your point of view). That would be > so much better than all those separate operations the silly compiler > was doing! Roughly an hour of fiddling later, making sure it all still > worked correctly, I discover that... hmm, it's not actually any > faster. Turns out the 80x86 string opcodes are really inefficient; > they're short (a one-byte command that says "read a > byte/word/doubleword from DS:SI, write it to ES:DI, and increment or > decrement SI and DI"), but not fast. In my defense, I at least did > measure before-and-after, and learned that I should back out that > change :) Better to have tried and failed though than to have simply accepted what the compiler was doing with no verification at all. From rosuav at gmail.com Tue Mar 11 00:28:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 15:28:25 +1100 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <531e6643$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 11, 2014 at 2:38 PM, Ian Kelly wrote: > On Mon, Mar 10, 2014 at 7:45 PM, Chris Angelico wrote: >> No no, >> I could make this so much better by using the 80x86 "REP MOVSW" >> command (or commands, depending on your point of view). That would be >> so much better than all those separate operations the silly compiler >> was doing! Roughly an hour of fiddling later, making sure it all still >> worked correctly, I discover that... hmm, it's not actually any >> faster. > > Better to have tried and failed though than to have simply accepted > what the compiler was doing with no verification at all. Maybe. But I've learned now that one guy who used to do assembly language programming on an 8086 is unlikely to discover something that the many authors of a C compiler haven't noticed. Yes, it's possible there'll be something specific to my code, like if I'm doing a strcpy-like operation that isn't *actually* strcpy (the function will be optimized heavily, but a C-level loop might not be recognized), but it's more likely the compiler knows better than I do. That, by the way, was before I realized that *interpreter* writers are more expert than I am, too, and therefore that I can trust a heavily-optimized high level language to run my code faster than I could write equivalent C. ChrisA From greg.ewing at canterbury.ac.nz Tue Mar 11 01:03:10 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 11 Mar 2014 18:03:10 +1300 Subject: Tuples and immutability In-Reply-To: References: Message-ID: Ian Kelly wrote: > It's technically "possible" for this augmented assignment to be > performed in place: > > x = 12 > x += 4 > > But it's not done in-place, because ints are meant to be immutable. Which means it's *not* possible, because doing so would violate the documented properties of the int type. > In any case, this means that whether the operation is actually > performed in-place is an implementation detail The implementation could theoretically perform this optimisation if there are no other references to the object. But this will be completely invisible, because to even find out whether it's the same object, you need to keep another reference to the original object, preventing the optimisation from being performed. As far as observable effects are concerned, it's quite clear: mutable objects can *always* be updated in-place, and immutable objects can *never* be. -- Greg From greg.ewing at canterbury.ac.nz Tue Mar 11 01:15:40 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 11 Mar 2014 18:15:40 +1300 Subject: Tuples and immutability In-Reply-To: References: <531d2551$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly wrote: > If the in-place behavior of += is held to be part of the interface, > then we must accept that += is not polymorphic across mutable and > immutable types, That's quite correct, it's not. As I said, it's one notation doing double duty. Usually there isn't any confusion, because you know whether any particular instance of it is intended to operate on a mutable or immutable type. If that's not the case -- if you're writing a function intended to operate on a variety of types, some mutable and some not -- then using in-place operators would not be appropriate. > If you want in-place concatenation, the > obvious way to do it is by calling extend. It might be the obvious way for that particular operation on that particular type. But what about all the others? What's the obvious way to spell in-place set intersection, for example? (Quickly -- no peeking at the docs!) The in-place operators provide a standardised spelling for in-place versions of all the binary operations. That's a useful thing to have, I think. -- Greg From christoff.kok at ex-mente.co.za Tue Mar 11 01:51:14 2014 From: christoff.kok at ex-mente.co.za (Christoff Kok) Date: Mon, 10 Mar 2014 22:51:14 -0700 (PDT) Subject: Struggling to create an extension wrapping a 3rd party dll In-Reply-To: <4f813ff8-d0c8-4370-b669-5484f3dcd467@googlegroups.com> References: <4f813ff8-d0c8-4370-b669-5484f3dcd467@googlegroups.com> Message-ID: <47279c2e-916c-47ae-8dd2-2f47886f09fe@googlegroups.com> On Wednesday, 5 March 2014 09:10:33 UTC+2, Christoff Kok wrote: > Hi, > > > > We are trying to wrap a 3rd party dll (written in C) to access it through python. > > The dll has a .lib .c and a .h file with it. We are accessing the dll through the .c file. > > > > Outisde of the extension (running as a console application), the code works without an issue. without the 3rd party dll, the python extension works without an issue. The issue comes in when trying combine the third party dll with the python extension. > > > > Here is the distutil installation script > > > > ################ Setup.py ################################ > > > > from distutils.core import setup, Extension > > > > chemAppPython_mod = Extension('chemAppPython', sources = ['chemAppPython.c', 'cacint.c'], libraries=['ca_vc_opt_e'], depends = ['cacint.h']) > > > > setup(name = "chemAppPython", > > version = "1.0", > > description = "The ChemnApp Python module", > > ext_modules = [chemAppPython_mod], > > data_files = [('',['ca_vc_e.dll'])] > > ) > > > > ########################################################## > > > > * ca_vc_opt_e.lib and ca_vc_e.dll is the library containing the third party methods we want to access. > > > > * cacint.h and cacint.c is the files acting as an interface to the ca_vc_opt_e.lib and ca_vc_e.dll. > > * chemAppPython.c is file containing the code wrapping the calls to the cacint.c (and in effect, the third party dll) > > > > The errors we are receiving are: > > C:\Python33\source\Python-3.3.4\ChemAppPython>setup.py install > > running install > > running build > > running build_ext > > building 'chemAppPython' extension > > creating build > > creating build\temp.win-amd64-3.3 > > creating build\temp.win-amd64-3.3\Release > > C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python33\include -IC:\Python33\include /TcchemAppPython.c /Fobuild\temp.win-amd64-3.3\Release\chemAppPython.obj > > chemAppPython.c > > C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python33\include -IC:\Python33\include /Tccacint.c /Fobuild\temp.win-amd64-3.3\Release\cacint.obj > > cacint.c > > cacint.c(357) : warning C4267: 'function' : conversion from 'size_t' to 'long', possible loss of data > > cacint.c(390) : warning C4267: 'function' : conversion from 'size_t' to 'long', possible loss of data > > . > > . > > . (some more of the same warning message for different functions.) > > . > > cacint.c(619) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. > > . > > . > > . > > . (some more of the same warning message at different positions in code.) > > . > > creating build\lib.win-amd64-3.3 > > C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python33\libs /LIBPATH:C:\Python33\PCbuild\amd64 ca_vc_opt_e.lib /EXPORT:PyInit_chemAppPython build\temp.win-amd64-3.3\Release\chemAppPython.obj build\temp.win-amd64-3.3\Rele > > chemAppPython.obj : warning LNK4197: export 'PyInit_chemAppPython' specified multiple times; using first specification > > Creating library build\temp.win-amd64-3.3\Release\chemAppPython.lib and object build\temp.win-amd64-3.3\Release\chemAppPython.exp > > cacint.obj : error LNK2019: unresolved external symbol TQINI referenced in function tqini > > cacint.obj : error LNK2019: unresolved external symbol TQOPEN referenced in function tqopen > > . > > . > > . (a lot more of them, for different methods. Again, it builds and runs fine in the console app host application.) > > . > > build\lib.win-amd64-3.3\chemAppPython.pyd : fatal error LNK1120: 74 unresolved externals > > error: command '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe"' failed with exit status 1120 > > > > > > Help would really be appreciated. I solved it. Apparently 64bit Python doesn't mingle well (or at all) with 32bit dll's. I downgraded python to a 32bit version and everything just worked. From jaiprakash at wisepromo.com Tue Mar 11 01:52:32 2014 From: jaiprakash at wisepromo.com (Jaiprakash Singh) Date: Mon, 10 Mar 2014 22:52:32 -0700 (PDT) Subject: querry on queue ( thread safe ) multithreading Message-ID: hey i am working on scraping a site , so i am using multi-threading concept. i wrote a code based on queue (thread safe) but still my code block out after sometime, please help , i have searched a lot but unable to resolve it. please help i stuck here. my code is under .. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import subprocess import multiprocessing import logging from scrapy import cmdline import time logging.basicConfig(level=logging.DEBUG, format='[%(levelname)s] (%(threadName)-10s) %(message)s',) num_fetch_threads = 150 enclosure_queue = multiprocessing.JoinableQueue() def main3(i, q): for pth in iter(q.get, None): try: cmdline.execute(['scrapy', 'runspider', 'page3_second_scrapy_flipkart.py', '-a', 'pth=%s' %(pth)]) print pth except: pass time.sleep(i + 2) q.task_done() q.task_done() def main2(output): procs = [] for i in range(num_fetch_threads): procs.append(multiprocessing.Process(target=main3, args=(i, enclosure_queue,))) #worker.setDaemon(True) procs[-1].start() for pth in output: enclosure_queue.put(pth) print '*** Main thread waiting' enclosure_queue.join() print '*** Done' for p in procs: enclosure_queue.put(None) enclosure_queue.join() for p in procs: p.join() From rosuav at gmail.com Mon Mar 10 22:29:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Mar 2014 13:29:45 +1100 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <531d7d73$0$29994$c3e8da3$5496439d@news.astraweb.com> <8738iqtmp6.fsf@elektro.pacujo.net> <531e6eca$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 11, 2014 at 1:20 PM, Roy Smith wrote: > In article <531e6eca$0$29994$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> There's only so much matter in the >> universe, so talking about limits as the amount of data approaches >> infinity is nonsense. Where would you store it? > > Funny you should ask that. I just finished watching > https://en.wikipedia.org/wiki/11001001 a few minutes ago. Multiple universes and/or sub-atomic monkeys. http://tools.ietf.org/html/rfc2795 ChrisA From dieter at handshake.de Tue Mar 11 03:28:31 2014 From: dieter at handshake.de (dieter) Date: Tue, 11 Mar 2014 08:28:31 +0100 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> <09ebd498-fb4a-4036-8703-9f7c7a580ffa@googlegroups.com> Message-ID: <87txb5p528.fsf@handshake.de> Wesley writes: > ... > [root at localhost ~]# gdb python > GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1) > This GDB was configured as "x86_64-redhat-linux-gnu". > Reading symbols from /usr/bin/python...Reading symbols from /usr/lib/debug/usr/bin/python2.6.debug...done. > done. > (gdb) run > Starting program: /usr/bin/python > warning: the debug information found in "/usr/lib/debug//usr/lib64/libpython2.6.so.1.0.debug" does not match "/usr/lib64/libpython2.6.so.1.0" (CRC mismatch). > > warning: the debug information found in "/usr/lib/debug/usr/lib64/libpython2.6.so.1.0.debug" does not match "/usr/lib64/libpython2.6.so.1.0" (CRC mismatch). This indicates that there is a problem between the executed code and the debug information. Apparently, they do not match. An installation problem might be the cause - maybe, a packaging problem. Have you not told us that you have build your own Python from source? Usually, such a Python would not reside under "/usr/bin" but more likely under "/usr/local/bin" (of course, doing special things, you can force a build from source to install unter "/usr/bin", but this usually is not advicable -- it is potentially interfering with system installed components). If you have generated your own Python, you must ensure that it is consistently used (for all the cases you are concerned by). From dieter at handshake.de Tue Mar 11 03:31:11 2014 From: dieter at handshake.de (dieter) Date: Tue, 11 Mar 2014 08:31:11 +0100 Subject: gdb unable to read python frame information References: <0b7f74c8-9c70-4950-b431-6c9bbb3f0058@googlegroups.com> <9c70d96c-3ab4-436c-aa90-82f47756ed6c@googlegroups.com> <00b321ae-2fb9-4360-93e4-e7f376444029@googlegroups.com> Message-ID: <87ppltp4xs.fsf@handshake.de> Wesley writes: > Now, I fixed the problem... > > Instead of python2.6.6, for python 2.7 it's OK.. > > Why? gdb does not support python 2.6.6? gdb supports python 2.6.6 as well (it is a C level debugger with very few dependencies on Python). Your reports seem to suggest that your Python 2.6.6 installation is somehow screwed up - for whatever reason. > Is it related to python-gdb.py? Very unlikely. From chris at simplistix.co.uk Tue Mar 11 03:53:10 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 11 Mar 2014 07:53:10 +0000 Subject: which async framework? In-Reply-To: References: <531E22DF.7030709@simplistix.co.uk> Message-ID: <531EC0E6.10402@simplistix.co.uk> On 10/03/2014 21:57, Terry Reedy wrote: >> I'd like to be able to serve the rest of the web api using a pyramid >> wsgi app if possible, and I'd like to be able to write the things that >> process requests in and validation out in a synchronous fashion, most >> likely spinning off a thread for each one. > > If you are writing 'standard' blocking, synchronous code, I am not sure > why you would use any of the above. The idea I have is to do all the networking async based on a declarative set of messages in and recording all messages out and then hand that set of messages off to a syncronous layer to make assertions, record into a database, etc. >> The protocols are all financial (do we really not have a pure-python FIX >> library?!) but none are likely to have existing python implementations. >> >> How should I pick between the options? What would people recommend and >> why? > > I know nothing of tornado. I personally would use asyncio over twisted > if I could because it is simpler, in the stdlib, has the option to write > 'untwisted' non-blocking code similar to blocking code, and the docs > easier for me to read. Thanks. Guess I was expecting more of a response. I suspect I'll just end up cross-posting to the various mailing lists, which I hope won't cause too much offence or kick off any flame wars. I'm faced with a difficult choice that I suspect many in our community are, just trying to find out how to make the best decision :-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From steve at pearwood.info Tue Mar 11 04:26:01 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 11 Mar 2014 08:26:01 GMT Subject: Testing interactive code using raw_input References: <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <531ec898$0$2923$c3e8da3$76491128@news.astraweb.com> On Mon, 10 Mar 2014 17:57:19 +0100, Peter Otten wrote: > Steven D'Aprano wrote: >> what are my options for *automatically* supplying input to raw_input? > > https://pypi.python.org/pypi/mock > > In Python 3 this is part of the standard library: Nice! Thanks to everyone who responded. -- Steven From alister.ware at ntlworld.com Tue Mar 11 05:25:02 2014 From: alister.ware at ntlworld.com (Alister) Date: Tue, 11 Mar 2014 09:25:02 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> Message-ID: On Mon, 10 Mar 2014 19:24:07 -0400, Roy Smith wrote: > In article <8761nmrnfk.fsf at elektro.pacujo.net>, > Marko Rauhamaa wrote: > >> Anyway, this whole debate is rather unnecessary since every developer >> is supposed to have both weapons in their arsenal. > > The problem with having a choice is that it opens up the possibility of > making the wrong one :-) > > As this discussion has shown, figuring out whether a hash table or a > tree is better for a given problem is non-trivial. My guess is that if > you gave 1000 typical developers both data structures and let them pick > freely, the number of cases where it really mattered and the developer > picked the right one would be approximately equal to the number of cases > where they picked the wrong one. Perhaps you are not familiar with the 50/50/90 rule? Given any 50/50 choice you are 90% certain to pick the wrong one :-) -- I hold it, that a little rebellion, now and then, is a good thing... -- Thomas Jefferson From marko at pacujo.net Tue Mar 11 06:12:23 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 11 Mar 2014 12:12:23 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <531e6643$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wqg1oxh4.fsf@elektro.pacujo.net> Steven D'Aprano : > On Mon, 10 Mar 2014 19:24:07 -0400, Roy Smith wrote: > >> In article <8761nmrnfk.fsf at elektro.pacujo.net>, >> Marko Rauhamaa wrote: >> >>> Anyway, this whole debate is rather unnecessary since every developer >>> is supposed to have both weapons in their arsenal. >> >> The problem with having a choice is that it opens up the possibility of >> making the wrong one :-) > > [...] > > In my experience, the average developer has an amazing talent for > pessimising code when they think they are optimising it. Java is the straitjacket that prevents the "average developer" from shooting himself in the foot. Python should let skilled professionals do their work. Thankfully, for the most part, it does. Marko From sturla.molden at gmail.com Tue Mar 11 06:17:25 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 11 Mar 2014 10:17:25 +0000 (UTC) Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> Message-ID: <164829410416225465.523179sturla.molden-gmail.com@news.gmane.org> Chris Withers wrote: > Hi All, > > I see python now has a plethora of async frameworks and I need to try > and pick one to use from: > > - asyncio/tulip > - tornado > - twisted Looking at Tornado's examples on the web I find this: tornado.ioloop.IOLoop.instance().start() This single line of code says more than thousand words. But it boils down to: (1) This was written by some Java guys. (2) Someone used Python to write Java. And that's all I need to know about Tornado. Sturla From ian.g.kelly at gmail.com Tue Mar 11 06:39:39 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 11 Mar 2014 04:39:39 -0600 Subject: Tuples and immutability In-Reply-To: References: Message-ID: On Mon, Mar 10, 2014 at 11:03 PM, Gregory Ewing wrote: > As far as observable effects are concerned, it's > quite clear: mutable objects can *always* be updated > in-place, and immutable objects can *never* be. Hm. Consider the circle-ellipse problem. Briefly, a circle is-an ellipse, so in an inheritance hierarchy it is natural to make Circle a subclass of Ellipse. Now suppose the Ellipse has a stretch method that mutates the ellipse by changing the length of one of its axes while preserving the other. To avoid violating LSP, the Circle class must support all the methods of its ancestor. However it cannot, because the stretch method would invalidate the invariant of the Circle class that both of its axes must always be equal. There are a number of possible solutions. One possibility would be to copy the Circle as an Ellipse and return the new object instead of mutating it. Then you have the situation where, given a mutable object x that satisfies isinstance(x, Ellipse), the stretch method *may* be able to update the object in-place, or it *may* not. I can't think of a reasonable example that would replace the stretch method here with an augmented assignment, but then it is rather late. > It might be the obvious way for that particular operation on > that particular type. But what about all the others? > What's the obvious way to spell in-place set intersection, > for example? (Quickly -- no peeking at the docs!) You mean set.intersection_update? The in-place set methods are not hard to remember, because they all end in _update. From sturla.molden at gmail.com Tue Mar 11 06:47:52 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 11 Mar 2014 10:47:52 +0000 (UTC) Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> Message-ID: <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Chris Withers wrote: > Hi All, > > I see python now has a plethora of async frameworks and I need to try > and pick one to use from: > > - asyncio/tulip > - tornado > - twisted I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to learn a framework? You will find epoll and kqueue/kevent in the select module and iocp in pywin32. Sturla From marko at pacujo.net Tue Mar 11 06:51:19 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 11 Mar 2014 12:51:19 +0200 Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> Message-ID: <87siqpovo8.fsf@elektro.pacujo.net> Sturla Molden : > Looking at Tornado's examples on the web I find this: > > [...] > > (1) This was written by some Java guys. I have written several Python async "frameworks" starting from select.epoll(). It's only a handful of lines of code (plus an AVL tree implementation for timers). Then, I've had to implement the protocols myself because the standard library implementations aren't amenable to async processing. Now, I've taken a brief look at the new asyncio and it looks as if it has everything one would hope for (and then some). You'd still need to supply the protocol implementations yourself. Since the async framework is such a small piece of the puzzle and since the edge-triggered mode of select.epoll() is a nicer programming model than asyncio provides, I might stick with epoll. (Yes, it is specific to linux.) Marko From marko at pacujo.net Tue Mar 11 06:58:51 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 11 Mar 2014 12:58:51 +0200 Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> Message-ID: <87lhwhovbo.fsf@elektro.pacujo.net> Sturla Molden : > I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to > learn a framework? You will find epoll and kqueue/kevent in the select > module and iocp in pywin32. You beat me to it. However, I'm hoping asyncio will steer the Python faithful away from blocking threads to the "right way" of doing networking. The Java people came to their senses with the advent of NIO. I think one of the main remaining sticking points is database access. I barely do any database stuff, but last I checked it's all done with synchronous APIs. Marko From sturla.molden at gmail.com Tue Mar 11 07:18:58 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 11 Mar 2014 11:18:58 +0000 (UTC) Subject: which async framework? References: <87siqpovo8.fsf@elektro.pacujo.net> Message-ID: <25034549416228599.987328sturla.molden-gmail.com@news.gmane.org> Marko Rauhamaa wrote: > Now, I've taken a brief look at the new asyncio and it looks as if it > has everything one would hope for (and then some). You'd still need to > supply the protocol implementations yourself. Tulip (the new async module) is nice. But I am a bit confused as to how it combines the IOCP model on Windows with the "readyness" signalling (epoll, kqueue) on Linux, *BSD and Apple. Because these paradigms are so inherently different, I don't see how both can be used effectively with the same client code. But Guido/BDFL is a smart guy and probably knows this better than me :) Another thing is that there is no IOCP support on Solaris, AIX and z/OS using Tulip, only Windows. But Windows is not the only OS with IOCP. I'd prefer that over /dev/poll any day (does Tulip use /dev/poll by the way?) Sturla From ian.g.kelly at gmail.com Tue Mar 11 07:48:03 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 11 Mar 2014 05:48:03 -0600 Subject: which async framework? In-Reply-To: <87lhwhovbo.fsf@elektro.pacujo.net> References: <531E22DF.7030709@simplistix.co.uk> <87lhwhovbo.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 11, 2014 at 4:58 AM, Marko Rauhamaa wrote: > Sturla Molden : > >> I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to >> learn a framework? You will find epoll and kqueue/kevent in the select >> module and iocp in pywin32. > > You beat me to it. > > However, I'm hoping asyncio will steer the Python faithful away from > blocking threads to the "right way" of doing networking. eventlet has 115k downloads from PyPI over the last month. gevent has 143k. Twisted has 147k. Tornado has 173k. I'd say that a lot of Python users are already doing non-blocking network I/O, in one form or another. From marko at pacujo.net Tue Mar 11 07:54:52 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 11 Mar 2014 13:54:52 +0200 Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <87lhwhovbo.fsf@elektro.pacujo.net> Message-ID: <87fvmposqb.fsf@elektro.pacujo.net> Ian Kelly : > eventlet has 115k downloads from PyPI over the last month. gevent has > 143k. Twisted has 147k. Tornado has 173k. > > I'd say that a lot of Python users are already doing non-blocking > network I/O, in one form or another. There aren't so many network developers in the world. That must be some web crawlers getting more than they bargained for. Marko From oscar.j.benjamin at gmail.com Tue Mar 11 07:59:59 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 11 Mar 2014 11:59:59 +0000 Subject: which async framework? In-Reply-To: <87fvmposqb.fsf@elektro.pacujo.net> References: <531E22DF.7030709@simplistix.co.uk> <87lhwhovbo.fsf@elektro.pacujo.net> <87fvmposqb.fsf@elektro.pacujo.net> Message-ID: On 11 March 2014 11:54, Marko Rauhamaa wrote: > Ian Kelly : > >> eventlet has 115k downloads from PyPI over the last month. gevent has >> 143k. Twisted has 147k. Tornado has 173k. >> >> I'd say that a lot of Python users are already doing non-blocking >> network I/O, in one form or another. > > There aren't so many network developers in the world. That must be some > web crawlers getting more than they bargained for. I have no idea how many network developers there are in the world but: 1) Many people may be installing this from pypi as a dependency of some other application that they use. So you should think that it counts something closer to "users" rather than developers. 2) There are problems with the download counts on PyPI but the numbers above are sufficiently high that they should indicate a wide level of usage of the libraries. Oscar From neilc at norwich.edu Tue Mar 11 09:20:35 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 11 Mar 2014 13:20:35 +0000 (UTC) Subject: Closure/method definition question for Python 2.7 References: <87vbvmq7l3.fsf@elektro.pacujo.net> Message-ID: On 2014-03-10, Marko Rauhamaa wrote: > "Brunick, Gerard:(Constellation)" : > >> class Test(object): >> x = 10 >> >> def __init__(self): >> self.y = x >> >> t = Test() >> --- >> >> raises >> >> NameError: global name 'x' is not defined. > > In the snippet, x is neither local to __init__() nor global to > the module. It is in the class scope. You can refer to it in > one of two ways: > > Test.x > > or: > > self.x The latter will work only to read the class variable. If you assign to self.x you'll create a new instance variable that hides the class variable. -- Neil Cerutti From neilc at norwich.edu Tue Mar 11 10:37:50 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 11 Mar 2014 14:37:50 +0000 (UTC) Subject: golang OO removal, benefits. over python? References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> Message-ID: On 2014-03-10, flebber wrote: > I was wondering if a better programmer than I could explain if > the removal of OO features in golang really does offer an great > benefit over python. > > An article I was reading ran through a brief overview of golang > in respect of OO features > http://areyoufuckingcoding.me/2012/07/25/object-desoriented-language/ > . > > maybe removing OO features would be a benefit to c++ users or > Java users but python? > > As I have seen an interesting reddit or two of people trying to > figure out go today it was a ruby user, totally lost with > structs. > > So anecdotally is actually python and ruby users changing to > Go, here is a blog and reddit from Rob Pike. > http://www.reddit.com/comments/1mue70 > > Why would a Python user change to go except for new and > interesting? Static typing combined with duck typing and simple distribution of applications is a draw. Go's tools are pretty awesome, and are scheduled for improvements. If you can get by with its built in types (or simple aggregates of them) it feels quite expressive. -- Neil Cerutti From solipsis at pitrou.net Tue Mar 11 11:57:38 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 11 Mar 2014 15:57:38 +0000 (UTC) Subject: which async framework? Message-ID: <> Chris Withers simplistix.co.uk> writes: > > The protocols are all financial (do we really not have a pure-python FIX > library?!) but none are likely to have existing python implementations. If you are mostly writing protocol implementations (aka parsers and serializers), then you should consider writing them in a way that's framework-agnostic. See as an example: https://pypi.python.org/pypi/obelus/0.1 (if you really want to settle on a single framework and don't mind supporting old Python versions, then I recommend asyncio) Regards Antoine. From solipsis at pitrou.net Tue Mar 11 12:01:39 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 11 Mar 2014 16:01:39 +0000 (UTC) Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Message-ID: Sturla Molden gmail.com> writes: > > Chris Withers simplistix.co.uk> wrote: > > Hi All, > > > > I see python now has a plethora of async frameworks and I need to try > > and pick one to use from: > > > > - asyncio/tulip > > - tornado > > - twisted > > I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to > learn a framework? You will find epoll and kqueue/kevent in the select > module and iocp in pywin32. Yes, why use a library when you can rewrite it all yourself? Actually, you should probably issue system calls to the kernel directly, the libc is overrated (as is portability, I suppose). Regards Antoine. From Joshua.R.English at gmail.com Tue Mar 11 12:13:17 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Tue, 11 Mar 2014 09:13:17 -0700 (PDT) Subject: Oddity using sorted with key Message-ID: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> I am running into a strange behavior using the sorted function in Python 2.7. The key parameter is not behaving as the docs say it does: Here is a snippet of code, simplified from my full program: #begin code class Thing(object): def __init__(self, name): self.name = name def __repr__(self): return "Thing %s" % self.name stuff = [Thing('a'), Thing('C'), Thing('b'), Thing('2')] more_stuff = [Thing('d'), Thing('f')] all_the_stuff = stuff + more_stuff print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) # END The output is: [Thing d, Thing f, Thing 2, Thing a, Thing b, Thing C] [Thing 2, Thing a, Thing b, Thing C, Thing d, Thing f] The second call to sorted works as expected. Just using the method doesn't sort properly. Any ideas why I'm seeing two different results? Especially as the correct form is giving me the wrong results? Josh English From g.rodola at gmail.com Tue Mar 11 12:18:33 2014 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Tue, 11 Mar 2014 17:18:33 +0100 Subject: which async framework? In-Reply-To: <164829410416225465.523179sturla.molden-gmail.com@news.gmane.org> References: <531E22DF.7030709@simplistix.co.uk> <164829410416225465.523179sturla.molden-gmail.com@news.gmane.org> Message-ID: On Tue, Mar 11, 2014 at 11:17 AM, Sturla Molden wrote: > Chris Withers wrote: > > Hi All, > > > > I see python now has a plethora of async frameworks and I need to try > > and pick one to use from: > > > > - asyncio/tulip > > - tornado > > - twisted > > Looking at Tornado's examples on the web I find this: > > tornado.ioloop.IOLoop.instance().start() > > This single line of code says more than thousand words. But it boils down > to: > > (1) This was written by some Java guys. > (2) Someone used Python to write Java. > > And that's all I need to know about Tornado. Tornado is actually very Pythonic and has a very well written and modern code base. I think "tornado.ioloop.IOLoop.instance().start()" is the way it is in order to let you use multiple IO loops in different threads but I can't think of other places where such an idiom is used. What one might find a little Java-esque at a first glance is Twisted, because of zope.interface and the camelCase notation, but definitively not Tornado. -- Giampaolo - http://grodola.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckaynor at zindagigames.com Tue Mar 11 12:20:43 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 11 Mar 2014 09:20:43 -0700 Subject: Oddity using sorted with key In-Reply-To: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> References: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> Message-ID: On Tue, Mar 11, 2014 at 9:13 AM, Josh English wrote: > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > In this case, the key being sorted on is the function object x.name.lower, not the result of the call. It might make more sense if you break the lambda out into a separate def statement, like this: def myKeyFunc(x): return x.name.lower # Return the function that produces the lower-cased name. print list(sorted(all_the_stuff, key=myKeyFunc)) > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) > In this case, you are calling x.name.lower, and the key being used is the result of that call. And heres what this one looks like broken down: def myKeyFunc(x): return x.name.lower() # Return the lower-cased name. print list(sorted(all_the_stuff, key=myKeyFunc)) Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Tue Mar 11 12:23:57 2014 From: emile at fenx.com (emile) Date: Tue, 11 Mar 2014 09:23:57 -0700 Subject: Oddity using sorted with key In-Reply-To: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> References: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> Message-ID: On 03/11/2014 09:13 AM, Josh English wrote: > I am running into a strange behavior using the sorted function in Python 2.7. The key parameter is not behaving as the docs say it does: > > Here is a snippet of code, simplified from my full program: > > #begin code > class Thing(object): > def __init__(self, name): > self.name = name > > def __repr__(self): > return "Thing %s" % self.name > > > stuff = [Thing('a'), Thing('C'), Thing('b'), Thing('2')] > more_stuff = [Thing('d'), Thing('f')] > > all_the_stuff = stuff + more_stuff > > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) in this case everything sorts by the same value of the bound method of name.lower. You could have used "".lower, which has the same value as x.name.lower, and gotten the same results. > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) in this case you're sorting by the lower case value of x.name, which is what you want. Emile > # END > > The output is: > > [Thing d, Thing f, Thing 2, Thing a, Thing b, Thing C] > [Thing 2, Thing a, Thing b, Thing C, Thing d, Thing f] > > The second call to sorted works as expected. Just using the method doesn't sort properly. > > Any ideas why I'm seeing two different results? Especially as the correct form is giving me the wrong results? > > Josh English > From gordon at panix.com Tue Mar 11 12:25:29 2014 From: gordon at panix.com (John Gordon) Date: Tue, 11 Mar 2014 16:25:29 +0000 (UTC) Subject: Oddity using sorted with key References: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> Message-ID: In <058a4a9e-7893-44ef-97c0-999a3589e82a at googlegroups.com> Josh English writes: > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) > # END > The output is: > [Thing d, Thing f, Thing 2, Thing a, Thing b, Thing C] > [Thing 2, Thing a, Thing b, Thing C, Thing d, Thing f] > Any ideas why I'm seeing two different results? Especially as the correct > form is giving me the wrong results? Why do you say that 'key=lambda x: x.name.lower' is the correct form? That returns the str.lower() function object, which is a silly thing to sort on. Surely you want to sort on the *result* of that function, which is what your second print does. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From __peter__ at web.de Tue Mar 11 12:43:45 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 11 Mar 2014 17:43:45 +0100 Subject: Oddity using sorted with key References: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> Message-ID: Josh English wrote: > I am running into a strange behavior using the sorted function in Python > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) Let's simplify your example some more: >>> items = ["B", "2", "a"] >>> sorted(items, key=lambda x: x.lower()) ['2', 'a', 'B'] That certainly works. Let's have a look at the keys used for the sorting: >>> for item in items: ... print item, "-->", (lambda x: x.lower())(item) ... B --> b 2 --> 2 a --> a Now on to your first example. What are the keys in this case? >>> for item in items: ... print item, "-->", (lambda x: x.lower)(item) ... B --> 2 --> a --> Just a bunch of bound methods. These compare by id(), basically the memory address of the bound method object, not something that makes a lot of sense as a sort key. > 2.7. The key parameter is not behaving as the docs say it does: You may be misled by the mention of key=str.lower str.lower is an unbound method, and if you pass it to sorted() together with a list of strings, it results in a call str.lower(item) # item is a string which is equivalent to item.lower() # item is a string So while it doesn't work for a list of Thing instances, if you have bare strings you can do >>> sorted(items, key=str.lower) ['2', 'a', 'B'] From steve+comp.lang.python at pearwood.info Tue Mar 11 12:46:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2014 16:46:51 GMT Subject: Tuples and immutability References: Message-ID: <531f3dfb$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Mar 2014 04:39:39 -0600, Ian Kelly wrote: > On Mon, Mar 10, 2014 at 11:03 PM, Gregory Ewing > wrote: >> As far as observable effects are concerned, it's quite clear: mutable >> objects can *always* be updated in-place, and immutable objects can >> *never* be. > > Hm. Consider the circle-ellipse problem. Oh, not that old chestnut! The circle-ellipse problem demonstrates one limitation of OOP (specifically "subtype polymorphism"), as well as a general difficulty with hierarchical taxonomies. Mammals have hair -- what do you make of hairless[1] dolphins? Circle/Ellipse is not a good place to start from in order to critic augmented assignment in Python. You're starting from a place where inheritance itself is problematic, so naturally you're going to find problems. > Briefly, a circle is-an ellipse, so in an inheritance hierarchy it is > natural to make Circle a subclass of Ellipse. Natural and wrong. It's only natural if you don't think through the consequences. As you go on to say: > Now suppose the Ellipse has a stretch method that > mutates the ellipse by changing the length of one of its axes while > preserving the other. To avoid violating LSP, the Circle class must > support all the methods of its ancestor. However it cannot, because the > stretch method would invalidate the invariant of the Circle class that > both of its axes must always be equal. Right. So *Circles cannot be Ellipses*, not without violating the Liskov Substitution Principle. If I think that they are, I haven't thought it through. Nor can Ellipses be Circles. That's the problem of the Circle/ Ellipse relationship. (Aside: the LSP is not a Law Of Physics that cannot be touched. There are other OOP models that don't require LSP.) Even in the case of immutable shapes, one might not wish to inherit Circle from Ellipsis. Ellipses have five degrees of freedom: 2 x position size (scale) orientation shape while circles only have three: 2 x position size Orientation and shape are meaningless for circles! So they should not inherit from a class where they are meaningful: given the LSP, a subclass cannot be more restrictive than a superclass. > There are a number of possible solutions. One possibility would be to > copy the Circle as an Ellipse and return the new object instead of > mutating it. Then you have the situation where, given a mutable object > x that satisfies isinstance(x, Ellipse), the stretch method *may* be > able to update the object in-place, or it *may* not. That is a really lousy design. Of course we are free to create classes with ugly, inconsistent, stupid or unworkable APIs if we like. Python won't stop us: class MyList(list): def append(self, obj): if len(self) % 17 == 3: return self + [obj] super(MyList, self).append(obj) > I can't think of a reasonable example that would replace the stretch > method here with an augmented assignment, but then it is rather late. > >> It might be the obvious way for that particular operation on that >> particular type. Um, yes? Nobody suggests that a method of type X has to be the most obvious way for *any operation* on *any type*. What's your point? > But what about all the others? What's the obvious way >> to spell in-place set intersection, for example? I would expect it to be &=, let's find out if I'm right: py> a = set("abcde") py> b = a # save a reference to it py> c = set("cdefg") py> a &= c py> a, b ({'c', 'd', 'e'}, {'c', 'd', 'e'}) py> a is b True >> (Quickly -- no peeking at the docs!) The only reason I'd need to look at the docs is because I always forget whether & is intersection and | is union, or the other way around. But having remembered which is which, going from & to &= was easy. > You mean set.intersection_update? The in-place set methods are not hard > to remember, because they all end in _update. And hard to spell. [1] Technically they aren't *entirely* hairless. They may have a few hairs around the blowhole, and baby dolphins are born with whiskers which they soon lose. But from a functional perspective, they are hairless. -- Steven D'Aprano From invalid at invalid.invalid Tue Mar 11 12:52:18 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 11 Mar 2014 16:52:18 +0000 (UTC) Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Message-ID: On 2014-03-11, Antoine Pitrou wrote: > Sturla Molden gmail.com> writes: >> >> Chris Withers simplistix.co.uk> wrote: >> > Hi All, >> > >> > I see python now has a plethora of async frameworks and I need to try >> > and pick one to use from: >> > >> > - asyncio/tulip >> > - tornado >> > - twisted >> >> I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to >> learn a framework? You will find epoll and kqueue/kevent in the select >> module and iocp in pywin32. > > Yes, why use a library when you can rewrite it all yourself? > Actually, you should probably issue system calls to the kernel directly, > the libc is overrated (as is portability, I suppose). And don't bother with device drivers for the network adapters either. Just map their PCI regions in to user-space and twiddle the reigisters directly! ;) [I do that when testing PCI boards with C code, and one of these days I'm going to figure out how to do it with Python.] -- Grant Edwards grant.b.edwards Yow! It's a hole all the at way to downtown Burbank! gmail.com From Joshua.R.English at gmail.com Tue Mar 11 13:02:16 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Tue, 11 Mar 2014 10:02:16 -0700 (PDT) Subject: Oddity using sorted with key In-Reply-To: References: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> Message-ID: <4f58f242-b974-4fa0-a2c7-115b6f50e3af@googlegroups.com> On Tuesday, March 11, 2014 9:25:29 AM UTC-7, John Gordon wrote: > > > > > Why do you say that 'key=lambda x: x.name.lower' is the correct form? That > > returns the str.lower() function object, which is a silly thing to sort > > on. Surely you want to sort on the *result* of that function, which is > > what your second print does. > >From http://docs.python.org/2/library/functions.html: key specifies a function of one argument that is used to extract a comparison key from each list element: key=str.lower. The default value is None (compare the elements directly). And from https://wiki.python.org/moin/HowTo/Sorting/: The value of the key parameter should be a function that takes a single argument and returns a key to use for sorting purposes. This technique is fast because the key function is called exactly once for each input record. ... Of course, now that I re-read that, I was mistaking the lambda function with the definition of the lambda function. Stupid me. From Joshua.R.English at gmail.com Tue Mar 11 13:03:31 2014 From: Joshua.R.English at gmail.com (Josh English) Date: Tue, 11 Mar 2014 10:03:31 -0700 (PDT) Subject: Oddity using sorted with key In-Reply-To: References: <058a4a9e-7893-44ef-97c0-999a3589e82a@googlegroups.com> Message-ID: A comprehensive and educational answer, Peter. Thank you. Josh From jkn_gg at nicorp.f9.co.uk Tue Mar 11 13:13:10 2014 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Tue, 11 Mar 2014 10:13:10 -0700 (PDT) Subject: which async framework? In-Reply-To: References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Message-ID: <7bee65ea-2779-4d60-b997-889493bec87e@googlegroups.com> Hi Grant On Tuesday, 11 March 2014 16:52:18 UTC, Grant Edwards wrote: [...] > > And don't bother with device drivers for the network adapters either. > Just map their PCI regions in to user-space and twiddle the reigisters > directly! ;) > > [I do that when testing PCI boards with C code, and one of these days > I'm going to figure out how to do it with Python.] Heh - just about the first 'real' thing I did in Python, back around 2001 or so, was to write a 'Device Driver' library to allow direct access to memory-mapped I/O via Python. It compiled under both Windows and Linux and I proved it using an ISA I/O board with loads of 8255s and LEDs hanging off it. As well as a learning exercise it was sort-of intended as a first step toward robotic control using Python. I hopen to rework it for similar PCI-based I/O boards (to do the sort of thing you mention), but never got a round tuit... Cheers jon N From rosuav at gmail.com Tue Mar 11 13:17:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Mar 2014 04:17:16 +1100 Subject: which async framework? In-Reply-To: References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Message-ID: On Wed, Mar 12, 2014 at 3:01 AM, Antoine Pitrou wrote: > Yes, why use a library when you can rewrite it all yourself? > Actually, you should probably issue system calls to the kernel directly, > the libc is overrated (as is portability, I suppose). It's a trade-off, of course. I am fluent in over six million forms of TCP socket communication (give or take), so I'll often skip the libraries and just directly connect a socket. But on the flip side, some protocols are just way more convenient to let a library handle. An HTTP POST request, for instance, requires - potentially - a whole lot of escaping and merging and stuff, or a simple call to one function with a dictionary of form data. But I like to retain close familiarity with the actual protocols, in case I'm trying to transfer a file onto a target system that provides something buggy or incomplete... most notably, the innumerable platforms whose FTP clients don't support passive mode. (RFC 959 specified it in 1985, why doesn't the default WinXP client support it??) I've written a good few FTP clients for that reason. There's a huge difference between something meant to do a huge amount of work long-term and something to just quickly move some data across a VM boundary. For the latter, I'll do whatever's quickest *right now*, and that may well mean "don't bother figuring out the XYZ module, just do it over a plain socket". ChrisA From jimsgibson at gmail.com Tue Mar 11 13:18:37 2014 From: jimsgibson at gmail.com (Jim Gibson) Date: Tue, 11 Mar 2014 10:18:37 -0700 Subject: querry on queue ( thread safe ) multithreading References: Message-ID: <110320141018377289%jimsgibson@gmail.com> In article , Jaiprakash Singh wrote: > hey i am working on scraping a site , so i am using multi-threading concept. > i wrote a code based on queue (thread safe) but still my code block out after > sometime, please help , i have searched a lot but unable to resolve it. > please help i stuck here. Do you really want to subject the web server to 150 simultaneous requests? Some would consider that a denial-of-service attack. When I scrape a site, and I have been doing that occasionally of late, I put a 10-second sleep after each HTTP request. That makes my program more considerate of other people's resources and a better web citizen. It is also much easier to program. -- Jim Gibson From sturla.molden at gmail.com Tue Mar 11 13:44:24 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 11 Mar 2014 17:44:24 +0000 (UTC) Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Message-ID: <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> Antoine Pitrou wrote: > Yes, why use a library when you can rewrite it all yourself? This assumes something equivalent to the library will have to be written. But if it can be replaced with something very minimalistic it is just bloat. I would also like to respond that the select module and pywin32 are libraries. So what we are talking about here is not using a library versus issuing low-level system calls, but using a cross-platform library instead of having separate modules with system calls for Linux, *BSD/Apple and Windows. Another thing is that co-routines and "yield from" statements just makes it hard to follow the logic of the program. I still have to convince myself that a library for transforming epoll function calls into co-routines is actually useful. If it just turns otherwise readable code into something most Python programmers cannot read it is better left out of the project. Sturla From solipsis at pitrou.net Tue Mar 11 14:43:45 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 11 Mar 2014 18:43:45 +0000 (UTC) Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> Message-ID: Sturla Molden gmail.com> writes: > > Antoine Pitrou pitrou.net> wrote: > > > Yes, why use a library when you can rewrite it all yourself? > > This assumes something equivalent to the library will have to be written. > But if it can be replaced with something very minimalistic it is just > bloat. I would also like to respond that the select module and pywin32 are > libraries. Lower-level ones, though. Just like C malloc() is lower-level than Python's memory management. This is the usual assumption that high-level libraries are made of useless cruft piled up by careless programmers. But there are actual reasons why these frameworks have a significant amount of code, and people who decide to ignore those reasons are simply bound to reimplement non-trivial parts of those frameworks in less careful and less tested ways (and they have to maintain it themselves afterwards). What irks me with your response is that you phrased it as though writing a good event loop was an almost trivial thing to do, which it is not once you start considering multiple use cases and constraints. It is quite irresponsible to suggest people don't need the power of network programming frameworks. I would personally distrust a programmer who chooses to reimplement their own event loop, except if they happen to have a very brilliant track record. > Another thing is that co-routines and "yield from" statements just > makes it hard to follow the logic of the program. That's an optional part of Tornado and asyncio, though. It is very reasonable to use Tornado or asyncio and still code in purely callback-driven style (even though Guido himself prefers the coroutine style). Regards Antoine. From rosuav at gmail.com Tue Mar 11 15:02:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Mar 2014 06:02:28 +1100 Subject: which async framework? In-Reply-To: References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> Message-ID: On Wed, Mar 12, 2014 at 5:43 AM, Antoine Pitrou wrote: > This is the usual assumption that high-level libraries are made of useless > cruft piled up by careless programmers. But there are actual reasons > why these frameworks have a significant amount of code, and people who > decide to ignore those reasons are simply bound to reimplement > non-trivial parts of those frameworks in less careful and less tested > ways (and they have to maintain it themselves afterwards). Once again, that's a judgment call. Those frameworks are usually written to be generic and to support lots of different systems, and if all you need is one of them, it's not so obvious that you 'ought to' use the framework. You do not need Joomla when all you want is a whole lot of static HTML files by one person - look for a simpler framework that doesn't put heaps of emphasis on user management, or no framework at all (just some nice templating system). But yes. If you're reimplementing something, you have to have a VERY good reason. I'm much more likely to write a program that edits bindfiles than to write a DNS server (although I have done both - Pike makes it easy to do the latter, and I had one situation where I was using DNS in such a way that I actually needed to generate responses on-the-fly based on rules, rather than pre-write everything), because BIND9 already handles pretty much everything, and its definition files are simple and easy to manipulate. (That said, though, I have *frequently* gone for some kind of meta-file with a script that creates the actual bindfiles. Helps with keeping things consistent, making sure I do the version updates, and so on. But that's not rewriting BIND.) ChrisA From tjreedy at udel.edu Tue Mar 11 15:41:30 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Mar 2014 15:41:30 -0400 Subject: which async framework? In-Reply-To: <531EC0E6.10402@simplistix.co.uk> References: <531E22DF.7030709@simplistix.co.uk> <531EC0E6.10402@simplistix.co.uk> Message-ID: On 3/11/2014 3:53 AM, Chris Withers wrote: > On 10/03/2014 21:57, Terry Reedy wrote: >>> I'd like to be able to serve the rest of the web api using a pyramid >>> wsgi app if possible, and I'd like to be able to write the things that >>> process requests in and validation out in a synchronous fashion, most >>> likely spinning off a thread for each one. >> >> If you are writing 'standard' blocking, synchronous code, I am not sure >> why you would use any of the above. > > The idea I have is to do all the networking async based on a declarative > set of messages in and recording all messages out and then hand that set > of messages off to a syncronous layer to make assertions, record into a > database, etc. In the absence of an event-loop oriented queue, putting jobs on a thread queue for a job-handler makes sense. >>> The protocols are all financial (do we really not have a pure-python FIX >>> library?!) but none are likely to have existing python implementations. >>> >>> How should I pick between the options? What would people recommend and >>> why? >> >> I know nothing of tornado. I personally would use asyncio over twisted >> if I could because it is simpler, in the stdlib, has the option to write >> 'untwisted' non-blocking code similar to blocking code, and the docs >> easier for me to read. > Guess I was expecting more of a response. Let me try again. I read the Twisted docs a couple of years ago. While I could deal with the interface, I understand why it is called 'twisted' and why Guido does not particularly like it. I read the asyncio doc before the most recent revisions and found it easier to understand. I personally like the co-routine layer. But I know that this is very much a personal preference. (Sturla just confirmed this by posting the opposite response to the coroutine interface.) So I suggest you spend an hour with the doc for each of the three candidates. > I suspect I'll just end up cross-posting to the various mailing lists, Bad idea. Post separately if you must. > which I hope won't cause too much offence or kick off any flame wars. It would do both. > I'm faced with a difficult choice that I suspect many in our community > are, just trying to find out how to make the best decision :-) The asyncio event loop interface was designed with knowledge of other event loops, including but not limited to those of twisted and tornado. The implementation in asyncio is intended to be replaceable by other implementations that include the same interface. I do not know if there are adapters yet for the twisted and tornado loops, but I expect there will be, official or not. Part of Guido's intent is to reduce single-framework lockin. If you start with asyncio, and decide you want to use some Twisted protocols, you should be able to (at least in the future) without dumping your current code. -- Terry Jan Reedy From ian.g.kelly at gmail.com Tue Mar 11 16:21:52 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 11 Mar 2014 14:21:52 -0600 Subject: golang OO removal, benefits. over python? In-Reply-To: <878usitplp.fsf@elektro.pacujo.net> References: <95cb6bd9-5030-4389-9891-578bb87af219@googlegroups.com> <878usitplp.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 10, 2014 at 2:38 AM, Marko Rauhamaa wrote: >> On the whole though I think that the language is not yet mature enough >> to be able to seriously compete with more established languages like >> Python or Java. > > Also, is there anything seriously lacking in Python, Java and C? > > I was very interested in Go when it came out, but was turned off by the > fact that you had so have a Google account to effectively participate in > the community. Concurrency is one area where Go beats Python hands down. The newish multiprocessing module helps with that, but it is still rather heavy compared to the light-weight processes used by Go's goroutines. From sturla.molden at gmail.com Tue Mar 11 16:36:11 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 11 Mar 2014 20:36:11 +0000 (UTC) Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> Message-ID: <1659582220416262070.234156sturla.molden-gmail.com@news.gmane.org> Antoine Pitrou wrote: > This is the usual assumption that high-level libraries are made of useless > cruft piled up by careless programmers. It often is the case, particularly in network programming. But in this case the programmer is Guido, so it doesn't apply. :) > What irks me with your response is that you phrased it as though writing > a good event loop was an almost trivial thing to do, which it is not > once you start considering multiple use cases and constraints. Right. But in my programs an event loops does not have multiple usecases. I know all the details about my usecase. I am more concerned that multiple frameworks have their own event loops. Sturla From greg.ewing at canterbury.ac.nz Tue Mar 11 17:23:27 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 12 Mar 2014 10:23:27 +1300 Subject: Tuples and immutability In-Reply-To: <531f3dfb$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <531f3dfb$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tue, 11 Mar 2014 04:39:39 -0600, Ian Kelly wrote: > >>On Mon, Mar 10, 2014 at 11:03 PM, Gregory Ewing > >>What's the obvious way >>>to spell in-place set intersection, for example? > > I would expect it to be &=, That's my point -- once you know the binary operator for an operation, the corresponding in-place operator is obvious. But there's no established standard set of method names for in-place operations -- each type does its own thing. >>You mean set.intersection_update? The in-place set methods are not hard >>to remember, because they all end in _update. For that particular type, maybe, but I wouldn't trust that rule to extend to other types. -- Greg From ethan at stoneleaf.us Tue Mar 11 16:58:17 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 11 Mar 2014 13:58:17 -0700 Subject: unittest weirdness Message-ID: <531F78E9.5020103@stoneleaf.us> So I finally got enough data and enough of an understanding to write some unit tests for my code. These aren't the first unit tests I've written, but the behavior I'm getting is baffling. I'm using 2.7.4 and I'm testing some routines which attempt to interpret data from a flat file and create a new flat file for later programmatic consumption. The weird behavior I'm getting: - when a test fails, I get the E or F, but no summary at the end (if the failure occurs in setUpClass before my tested routines are actually called, I get the summary; if I run a test method individually I get the summary) - I have two classes, but only one is being exercised - occasionally, one of my gvim windows is unceremoniously killed (survived only by its swap file) I'm running the tests under sudo as the routines expect to be run that way. Anybody have any ideas? -- ~Ethan~ --snippet of code-- from VSS.path import Path from unittest import TestCase, main as Run import wfbrp class Test_wfbrp_20140225(TestCase): @classmethod def setUpClass(cls): cls.pp = wfbrp.PaymentProcessor( '.../lockbox_file', '.../aging_file', [ Path('month_end_1'), Path('month_end_2'), Path('month_end_3'), ], ) def test_xxx_1(self): p = self.pp.lockbox_payments[0] # affirm we have what we're expecting self.assertEqual( (p.payer, p.ck_num, p.credit), ('a customer', '010101', 10000), ) self.assertEqual(p.invoices.keys(), ['XXXXXXXXXXX']) self.assertEqual(p.invoices.values()[0].amount, 10000) # now make sure we get back what we're expecting np, b = self.pp._match_invoices(p) missing = [] for inv_num in ('123456', '789012', '345678'): if inv_num not in b: missing.append(inv_num) if missing: raise ValueError('invoices %r missing from batch' % missing) From greg.ewing at canterbury.ac.nz Tue Mar 11 17:56:43 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 12 Mar 2014 10:56:43 +1300 Subject: which async framework? In-Reply-To: References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Message-ID: Sturla Molden wrote: > Another thing is that co-routines and "yield from" statements just makes it > hard to follow the logic of the program. I still have to convince myself > that a library for transforming epoll function calls into co-routines is > actually useful. It's not "epoll function calls" that the coroutine style is intended to replace, it's complex systems of chained callbacks. They're supposed to make that kind of logic *easier* to follow. If you haven't had that experience, it may be because you've only dealt with simple cases. -- Greg From gordon at panix.com Tue Mar 11 18:13:39 2014 From: gordon at panix.com (John Gordon) Date: Tue, 11 Mar 2014 22:13:39 +0000 (UTC) Subject: unittest weirdness References: Message-ID: In Ethan Furman writes: > if missing: > raise ValueError('invoices %r missing from batch' % missing) It's been a while since I wrote test cases, but I recall using the assert* methods (assertEqual, assertTrue, etc.) instead of raising exceptions. Perhaps that's the issue? -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From marko at pacujo.net Tue Mar 11 18:18:24 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 12 Mar 2014 00:18:24 +0200 Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Message-ID: <87bnxcnzv3.fsf@elektro.pacujo.net> Gregory Ewing : > It's not "epoll function calls" that the coroutine style is intended > to replace, it's complex systems of chained callbacks. They're > supposed to make that kind of logic *easier* to follow. If you haven't > had that experience, it may be because you've only dealt with simple > cases. The coroutines are definitely something to get into, although I'm skeptical as well. Epoll and the associated idioms have been with us for a long time and are well understood. As for "easy to follow," unfortunately the complexities of network state machines cannot be abstracted out, and the result is never exactly easy to the eye. Marko From marko at pacujo.net Tue Mar 11 18:28:42 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 12 Mar 2014 00:28:42 +0200 Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> Message-ID: <877g80nzdx.fsf@elektro.pacujo.net> Antoine Pitrou : > This is the usual assumption that high-level libraries are made of > useless cruft piled up by careless programmers. But there are actual > reasons why these frameworks have a significant amount of code, and > people who decide to ignore those reasons are simply bound to > reimplement non-trivial parts of those frameworks in less careful and > less tested ways (and they have to maintain it themselves afterwards). Maybe, maybe not. You can't assume it one way or another. > What irks me with your response is that you phrased it as though writing > a good event loop was an almost trivial thing to do, It's not rocket science. There are pitfalls, to be sure, but the resulting, solid event loop is not many lines of code. Have had to implement it numerous times. That said, asyncio seems to have the necessary facilities in place. Definitely worth a closer look. > I would personally distrust a programmer who chooses to reimplement > their own event loop, except if they happen to have a very brilliant > track record. As with all programming, you have to do it right. If you can't write your own event loop, you probably can't be trusted with any multithreaded code, which has much more baffling corner cases. Marko From ethan at stoneleaf.us Tue Mar 11 17:37:09 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 11 Mar 2014 14:37:09 -0700 Subject: unittest weirdness In-Reply-To: <531F78E9.5020103@stoneleaf.us> References: <531F78E9.5020103@stoneleaf.us> Message-ID: <531F8205.8090805@stoneleaf.us> On 03/11/2014 01:58 PM, Ethan Furman wrote: > > Anybody have any ideas? I suspect the O/S is killing the process. If I manually select the other class to run (which has all successful tests, so no traceback baggage), it runs normally. -- ~Ethan~ From rosuav at gmail.com Tue Mar 11 18:38:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Mar 2014 09:38:33 +1100 Subject: which async framework? In-Reply-To: <877g80nzdx.fsf@elektro.pacujo.net> References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> <877g80nzdx.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 12, 2014 at 9:28 AM, Marko Rauhamaa wrote: > If you can't write your own event loop, you probably can't be trusted > with any multithreaded code, which has much more baffling corner cases. I'm not sure about that. Threads are generally easier to handle, because each one just does something on its own, sequentially. (The problem with threads is the resource usage - you need to allocate X amount of stack space and other execution state, when all you really need is the socket (or whatever) and some basic state about that.) Regardless of how you structure your code, you have to ensure that one handler doesn't tread on another's toes, and with multithreading, that's _all_ you have to worry about. A proper event loop, handling events from all sorts of different sources, is far more complicated. What corner cases are there with threads that you don't have with anything else? ChrisA From ethan at stoneleaf.us Tue Mar 11 18:29:59 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 11 Mar 2014 15:29:59 -0700 Subject: unittest weirdness In-Reply-To: References: Message-ID: <531F8E67.10709@stoneleaf.us> On 03/11/2014 03:13 PM, John Gordon wrote: > Ethan Furman writes: > >> if missing: >> raise ValueError('invoices %r missing from batch' % missing) > > It's been a while since I wrote test cases, but I recall using the assert* > methods (assertEqual, assertTrue, etc.) instead of raising exceptions. > Perhaps that's the issue? Drat. Tried it, same issue. O/S kills it. :( -- ~Ethan~ From ian.g.kelly at gmail.com Tue Mar 11 19:06:43 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 11 Mar 2014 17:06:43 -0600 Subject: Tuples and immutability In-Reply-To: <531f3dfb$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <531f3dfb$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 11, 2014 at 10:46 AM, Steven D'Aprano wrote: >> There are a number of possible solutions. One possibility would be to >> copy the Circle as an Ellipse and return the new object instead of >> mutating it. Then you have the situation where, given a mutable object >> x that satisfies isinstance(x, Ellipse), the stretch method *may* be >> able to update the object in-place, or it *may* not. > > That is a really lousy design. Of course we are free to create classes > with ugly, inconsistent, stupid or unworkable APIs if we like. Python > won't stop us: That's true but irrelevant to my point, which was to counter the assertion that mutable types can always be assumed to be able to perform operations in-place. From barry at barrys-emacs.org Tue Mar 11 17:37:34 2014 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 11 Mar 2014 21:37:34 +0000 Subject: How to create an instance of a python class from C++ In-Reply-To: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> Message-ID: <8AEE6BCA-0F61-4F9E-A18B-13DB283DC134@barrys-emacs.org> On 5 Mar 2014, at 00:14, Bill wrote: > Hello: > > I can't figure out how to create an instance > of a python class from 'C++': > Why not use pycxx from http://sourceforge.net/projects/cxx/? This lib does all the heavy lifting for you for both python2 and python3. Has docs and examples. Barry PyCXX maintainer. > ( I am relatively new to Python so excuse some of > the following. ) > > In a .py file I create an ABC and then specialize it: > > from MyMod import * > from abc import ABCMeta, abstractmethod > > # Declare an abstract base class. > class Base(metaclass=ABCMeta): > """Base class.""" > @abstractmethod > def description(self): > return "From the base class." > > # Declare a class that inerits from the base. > class Derived(Base): > """Derived class.""" > def description(self): > return "From the Derived." > > # Register the derived class. > RegisterClass(Derived) > > Then from 'C++' (my implementation of RegisterClass) > I try to create an instance > > static PyObject * > RegisterClass( PyObject *, PyObject *args ) { // This gets called ok. > > PyObject *class_decl; > if( ! PyArg_ParseTuple(args, "O", &class_decl) ) > return NULL; > Py_INCREF(class_decl); > > PyTypeObject *typ = class_decl->ob_type; > > // Tried this. > // PyObject *an = _PyObject_New(class_decl->ob_type); assert(an); > // PyObject *desc = PyObject_CallMethod(an,"description",NULL); assert(desc); > > // Tried this. > // PyObject *an = PyType_GenericNew((PyTypeObject *)class_decl->ob_type, NULL, NULL); assert(an); > // assert(class_decl); assert(class_decl->ob_type); assert(class_decl->ob_type->tp_new); > > // This returns something. > assert(class_decl); assert(class_decl->ob_type); assert(class_decl->ob_type->tp_new); > PyObject *an_inst = class_decl->ob_type->tp_new(class_decl->ob_type,NULL, NULL); assert(an_inst); > assert(class_decl->ob_type->tp_init); > > // This crashes. > int ret = class_decl->ob_type->tp_init(an_inst,NULL, NULL); assert(ret == 0); > // PyObject_CallMethod(an_inst,"__init__",NULL); > // PyObject *an_inst = PyObject_CallMethod(class_decl,"__new__",NULL); assert(an_inst); > > // Never get here. > PyObject *desc = PyObject_CallMethod(an_inst,"description",NULL); assert(desc); > char *cp = _PyUnicode_AsString(desc); > cerr << "Description:" << cp << endl; > > return PyLong_FromLong(0); > } > > static PyMethodDef MyModMethods[] = { > { "RegisterClass", RegisterClass, METH_VARARGS, "Register class." }, > { NULL, NULL, 0, NULL } > }; > > static struct PyModuleDef MyModMod = { > PyModuleDef_HEAD_INIT, > "MyMod", // name of module > NULL, // module documentation, may be NULL > -1, > MyModMethods, > NULL, > NULL, > NULL, > NULL > }; > > PyMODINIT_FUNC > PyInit_MyMod( void ) { > PyObject* m = PyModule_Create(&MyModMod); > if( m == NULL ) > return NULL; > return m; > } > > int > main( int, char ** ) { > > PyImport_AppendInittab( "MyMod", PyInit_MyMod ); > > Py_Initialize(); > > const char *file_name = "z.py"; > FILE *fp = fopen(file_name,"r"); > if( fp ) { > PyRun_SimpleFileExFlags(fp,file_name,1,0); > } > > Py_Finalize(); > > return 0; > } > -- > https://mail.python.org/mailman/listinfo/python-list > From marko at pacujo.net Tue Mar 11 19:18:52 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 12 Mar 2014 01:18:52 +0200 Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> <877g80nzdx.fsf@elektro.pacujo.net> Message-ID: <87wqg0mihv.fsf@elektro.pacujo.net> Chris Angelico : > What corner cases are there with threads that you don't have with > anything else? There are numerous. Here's one example: deadlocks due to two threads taking locks in a different order. The problem crops up naturally with two intercommunicating classes. It can sometimes be very difficult to spot or avoid. Marko From rosuav at gmail.com Tue Mar 11 19:38:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Mar 2014 10:38:38 +1100 Subject: which async framework? In-Reply-To: <87wqg0mihv.fsf@elektro.pacujo.net> References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> <877g80nzdx.fsf@elektro.pacujo.net> <87wqg0mihv.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 12, 2014 at 10:18 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> What corner cases are there with threads that you don't have with >> anything else? > > There are numerous. Here's one example: deadlocks due to two threads > taking locks in a different order. The problem crops up naturally with > two intercommunicating classes. It can sometimes be very difficult to > spot or avoid. Yep. Now how is that not a problem when you use some other model, like an event loop? The standard methods of avoiding deadlocks (like acquiring locks in strict order) work exactly the same for all models, and are just as necessary. ChrisA From marko at pacujo.net Tue Mar 11 20:10:46 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 12 Mar 2014 02:10:46 +0200 Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> <877g80nzdx.fsf@elektro.pacujo.net> <87wqg0mihv.fsf@elektro.pacujo.net> Message-ID: <87siqomg3d.fsf@elektro.pacujo.net> Chris Angelico : > Yep. Now how is that not a problem when you use some other model, like > an event loop? The standard methods of avoiding deadlocks (like > acquiring locks in strict order) work exactly the same for all models, > and are just as necessary. I was simply saying that if you can work with multiple threads, an event loop shouldn't be a big deal. Marko From wuwei23 at gmail.com Tue Mar 11 20:13:01 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 12 Mar 2014 10:13:01 +1000 Subject: Balanced trees In-Reply-To: <87wqg1oxh4.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <531e6643$0$29994$c3e8da3$5496439d@news.astraweb.com> <87wqg1oxh4.fsf@elektro.pacujo.net> Message-ID: On 11/03/2014 8:12 PM, Marko Rauhamaa wrote: > Python should let skilled professionals do their work. Thankfully, for > the most part, it does. Skilled professionals don't solely rely on the standard library, either. If you know you need a balanced tree, you'll also know where to find an implementation of one. From rhodri at wildebst.org.uk Tue Mar 11 20:57:59 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Wed, 12 Mar 2014 00:57:59 -0000 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <531e6643$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 11 Mar 2014 04:28:25 -0000, Chris Angelico wrote: > On Tue, Mar 11, 2014 at 2:38 PM, Ian Kelly wrote: >> On Mon, Mar 10, 2014 at 7:45 PM, Chris Angelico >> wrote: >>> No no, >>> I could make this so much better by using the 80x86 "REP MOVSW" >>> command (or commands, depending on your point of view). That would be >>> so much better than all those separate operations the silly compiler >>> was doing! Roughly an hour of fiddling later, making sure it all still >>> worked correctly, I discover that... hmm, it's not actually any >>> faster. >> >> Better to have tried and failed though than to have simply accepted >> what the compiler was doing with no verification at all. > > Maybe. But I've learned now that one guy who used to do assembly > language programming on an 8086 is unlikely to discover something that > the many authors of a C compiler haven't noticed. Yes, it's possible > there'll be something specific to my code, like if I'm doing a > strcpy-like operation that isn't *actually* strcpy (the function will > be optimized heavily, but a C-level loop might not be recognized), but > it's more likely the compiler knows better than I do. That might be true for x86, but it isn't true for ARM for example. Apparently it's algorithmically hard to generate ARM code that makes efficient use of conditional instructions, and I can almost always write tighter, faster code than the compiler generates in consequence. It's not always worth the extra coding time (longer now that I'm not in practise), but that's a separate matter. -- Rhodri James *-* Wildebeest Herder to the Masses From cjwelborn at live.com Tue Mar 11 22:04:13 2014 From: cjwelborn at live.com (Christopher Welborn) Date: Tue, 11 Mar 2014 21:04:13 -0500 Subject: beautiful soup get class info In-Reply-To: References: Message-ID: On 03/06/2014 02:22 PM, teddybubu at gmail.com wrote: > I am using beautifulsoup to get the title and date of the website. > title is working fine but I am not able to pull the date. Here is the code in the url: > > October 22, 2011 > > In Python, I am using the following code: > date1 = soup.span.text > data=soup.find_all(date="value") > > Results in: > > [] > March 5, 2014 > > What is the proper way to get this info? > Thanks. > I believe it's the 'attrs' argument. http://www.crummy.com/software/BeautifulSoup/bs4/doc/ # Workaround the 'class' problem: data = soup.find_all(attrs={'class': 'date'}) I haven't tested it, but it's worth looking into. -- \?\ /?/\ \ \/??\/ / / Christopher Welborn (cj) \__/\__/ / cjwelborn at live?com \__/\__/ http://welbornprod.com From rantingrickjohnson at gmail.com Tue Mar 11 22:01:43 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 11 Mar 2014 19:01:43 -0700 (PDT) Subject: Tuples and immutability In-Reply-To: References: Message-ID: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: > x += y is meant to be equivalent, except possibly in-place and more > efficient, than x = x + y. In an ideal world, the speed of these two codes should be the same, of course i'm "assuming" that most competent language designers would optimise the slower version. """But Rick, Python is an interpreted language and does not benefit from a compile stage.""" Even if the bytecode can't be optimized on the current run, it CAN be optimized by updating the .pyo file for future runs without degrading current (or future) runtime performance. From rosuav at gmail.com Tue Mar 11 22:10:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Mar 2014 13:10:23 +1100 Subject: Tuples and immutability In-Reply-To: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> Message-ID: On Wed, Mar 12, 2014 at 1:01 PM, Rick Johnson wrote: > On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: >> x += y is meant to be equivalent, except possibly in-place and more >> efficient, than x = x + y. > > In an ideal world, the speed of these two codes should be the same, of course i'm "assuming" that most competent language designers would optimise the slower version. > Except that they don't mean the same thing, so it's not an optimization target. ChrisA From tjreedy at udel.edu Tue Mar 11 23:25:19 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Mar 2014 23:25:19 -0400 Subject: Tuples and immutability In-Reply-To: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> Message-ID: On 3/11/2014 10:01 PM, Rick Johnson wrote: > > On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: >> x += y is meant to be equivalent, except possibly in-place and >> more efficient, than x = x + y. The manual actually says "An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a similar, but not exactly equal effect. In the augmented version, x is only evaluated once. Also, when possible, the actual operation is performed in-place, meaning that rather than creating a new object and assigning that to the target, the old object is modified instead. > In an ideal world, the speed of these two codes should be the same, Nope, 'similar' is not 'equivalent'. Evaluating x twice instead of once and possibly allocating a new object versus not take extra time. In a statement like "x.y.z[3*n+m] += 1", calculating the target dominates the time to increment, so this form should be nearly twice as fast. -- Terry Jan Reedy From tjreedy at udel.edu Tue Mar 11 23:36:44 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Mar 2014 23:36:44 -0400 Subject: unittest weirdness In-Reply-To: References: Message-ID: On 3/11/2014 6:13 PM, John Gordon wrote: > In Ethan Furman writes: > >> if missing: >> raise ValueError('invoices %r missing from batch' % missing) > > It's been a while since I wrote test cases, but I recall using the assert* > methods (assertEqual, assertTrue, etc.) instead of raising exceptions. > Perhaps that's the issue? Yes. I believe the methods all raise AssertionError on failure, and the test methods are wrapped with try:.. except AssertionError as err: if missing: raise ValueError('invoices %r missing from batch' % missing) should be "assertEqual(missing, [], 'invoices missing from batch')" and if that fails, the non-empty list is printed along with the message. -- Terry Jan Reedy From steve at pearwood.info Wed Mar 12 02:28:01 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 12 Mar 2014 06:28:01 GMT Subject: Tuples and immutability References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> Message-ID: <531ffe70$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 11 Mar 2014 23:25:19 -0400, Terry Reedy wrote: > On 3/11/2014 10:01 PM, Rick Johnson wrote: >> >> On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: >>> x += y is meant to be equivalent, except possibly in-place and more >>> efficient, than x = x + y. > > The manual actually says "An augmented assignment expression like x += 1 > can be rewritten as x = x + 1 to achieve a similar, but not exactly > equal effect. In the augmented version, x is only evaluated once. Also, > when possible, the actual operation is performed in-place, meaning that > rather than creating a new object and assigning that to the target, the > old object is modified instead. > > >> In an ideal world, the speed of these two codes should be the same, > > Nope, 'similar' is not 'equivalent'. Evaluating x twice instead of once > and possibly allocating a new object versus not take extra time. In a > statement like "x.y.z[3*n+m] += 1", calculating the target dominates the > time to increment, so this form should be nearly twice as fast. Excellent point Terry! I always forget that the target of an augmented assignment may not be a simple name like "x" but can be an arbitrary complex reference, anything that is a legal assignment target. Because += is documented as only evaluating the expression once it can behave quite differently to the `spam = spam + 1` case. Evaluating the right hand side may have side- effects that change what the left hand side evaluates to. This is not the case with the augmented assignment. -- Steven From ethan at stoneleaf.us Wed Mar 12 02:32:53 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 11 Mar 2014 23:32:53 -0700 Subject: Tuples and immutability In-Reply-To: References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> Message-ID: <531FFF95.6050802@stoneleaf.us> On 03/11/2014 08:25 PM, Terry Reedy wrote: > On 3/11/2014 10:01 PM, Rick Johnson wrote: >> >> On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: >>> x += y is meant to be equivalent, except possibly in-place and >>> more efficient, than x = x + y. > > The manual actually says "An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a > similar, but not exactly equal effect. In the augmented version, x is only evaluated once. Also, when possible, the > actual operation is performed in-place, meaning that rather than creating a new object and assigning that to the target, > the old object is modified instead. ... and reassigned to the target. :) (If it doesn't say that last part, it should.) -- ~Ethan~ From __peter__ at web.de Wed Mar 12 03:36:40 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Mar 2014 08:36:40 +0100 Subject: beautiful soup get class info References: Message-ID: Christopher Welborn wrote: > On 03/06/2014 02:22 PM, teddybubu at gmail.com wrote: >> I am using beautifulsoup to get the title and date of the website. >> title is working fine but I am not able to pull the date. Here is the >> code in the url: >> >> October 22, 2011 >> >> In Python, I am using the following code: >> date1 = soup.span.text >> data=soup.find_all(date="value") >> >> Results in: >> >> [] >> March 5, 2014 >> >> What is the proper way to get this info? >> Thanks. >> > > I believe it's the 'attrs' argument. > http://www.crummy.com/software/BeautifulSoup/bs4/doc/ > > # Workaround the 'class' problem: > data = soup.find_all(attrs={'class': 'date'}) > > I haven't tested it, but it's worth looking into. Yes there are two ways to filtr by class: >>> soup = bs4.BeautifulSoup(""" ... alpha ... beta""") Use attrs: >>> soup.find_all(attrs={"class": "one"}) [alpha] Append an underscore: >>> soup.find_all(class_="two") [beta] From antoon.pardon at rece.vub.ac.be Wed Mar 12 05:08:48 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 12 Mar 2014 10:08:48 +0100 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> Message-ID: <53202420.2040009@rece.vub.ac.be> Op 11-03-14 00:24, Roy Smith schreef: > In article <8761nmrnfk.fsf at elektro.pacujo.net>, > Marko Rauhamaa wrote: > >> Anyway, this whole debate is rather unnecessary since every developer is >> supposed to have both weapons in their arsenal. > The problem with having a choice is that it opens up the possibility of > making the wrong one :-) This is just a standard defense for the status quo. Introducing the decimal module also added a choice. > As this discussion has shown, figuring out whether a hash table or a > tree is better for a given problem is non-trivial. My guess is that if > you gave 1000 typical developers both data structures and let them pick > freely, the number of cases where it really mattered and the developer > picked the right one would be approximately equal to the number of cases > where they picked the wrong one. You are only illustrating one part. How about all those cases now where the wrong choice is more or less forced on the developer for lack of the alternative? -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Wed Mar 12 05:39:35 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 12 Mar 2014 10:39:35 +0100 Subject: Tuples and immutability In-Reply-To: <531ffe70$0$2923$c3e8da3$76491128@news.astraweb.com> References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> <531ffe70$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <53202B57.7060504@rece.vub.ac.be> Op 12-03-14 07:28, Steven D'Aprano schreef: > On Tue, 11 Mar 2014 23:25:19 -0400, Terry Reedy wrote: > >> Nope, 'similar' is not 'equivalent'. Evaluating x twice instead of once >> and possibly allocating a new object versus not take extra time. In a >> statement like "x.y.z[3*n+m] += 1", calculating the target dominates the >> time to increment, so this form should be nearly twice as fast. > Excellent point Terry! > > I always forget that the target of an augmented assignment may not be a > simple name like "x" but can be an arbitrary complex reference, anything > that is a legal assignment target. Because += is documented as only > evaluating the expression once it can behave quite differently to the > `spam = spam + 1` case. Evaluating the right hand side may have side- > effects that change what the left hand side evaluates to. This is not the > case with the augmented assignment. The documentation is wrong at that point as the following code illustrates. | import sys | write = sys.stdout.write | | class logdict: | def __init__(self): | self.lst = {} | | def __setitem__(self, key, value): | write('[%s] <= %s\n' % (key, value)) | self.lst[key] = value | | def __getitem__(self, key): | value = self.lst[key] | write('[%s] => %s\n' % (key, value)) | return value | | tab = logdict() | tab['key'] = 'value' | tab['key'] += ' with extra tail' | write('====\n') | tab = logdict() | tab['key'] = 'value' | tab['key'] = tab['key'] + ' with extra tail' If you run this code, you get the following result: | [key] <= value | [key] => value | [key] <= value with extra tail | ==== | [key] <= value | [key] => value | [key] <= value with extra tail As you can see there is no difference here in the evaluations done between using | tab['key'] += ' with extra tail' or | tab['key'] = tab['key'] + ' with extra tail' From ian.g.kelly at gmail.com Wed Mar 12 05:40:29 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Mar 2014 03:40:29 -0600 Subject: Tuples and immutability In-Reply-To: <531ffe70$0$2923$c3e8da3$76491128@news.astraweb.com> References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> <531ffe70$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wed, Mar 12, 2014 at 12:28 AM, Steven D'Aprano wrote: > On Tue, 11 Mar 2014 23:25:19 -0400, Terry Reedy wrote: >> Nope, 'similar' is not 'equivalent'. Evaluating x twice instead of once >> and possibly allocating a new object versus not take extra time. In a >> statement like "x.y.z[3*n+m] += 1", calculating the target dominates the >> time to increment, so this form should be nearly twice as fast. > > Excellent point Terry! > > I always forget that the target of an augmented assignment may not be a > simple name like "x" but can be an arbitrary complex reference, anything > that is a legal assignment target. Because += is documented as only > evaluating the expression once it can behave quite differently to the > `spam = spam + 1` case. Evaluating the right hand side may have side- > effects that change what the left hand side evaluates to. This is not the > case with the augmented assignment. Of course one could also do: z = x.y.z i = 3*n+m z[i] = z[i] + 1 which reduces the duplicated work down to storing and loading a couple of locals, and also prevents side-effects from affecting the LHS evaluation. From ian.g.kelly at gmail.com Wed Mar 12 05:51:52 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Mar 2014 03:51:52 -0600 Subject: Tuples and immutability In-Reply-To: <53202B57.7060504@rece.vub.ac.be> References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> <531ffe70$0$2923$c3e8da3$76491128@news.astraweb.com> <53202B57.7060504@rece.vub.ac.be> Message-ID: On Wed, Mar 12, 2014 at 3:39 AM, Antoon Pardon wrote: > The documentation is wrong at that point as the following code illustrates. Either way it still has to do a getitem and a setitem, but if you have a more nested structure then the extra getitems are not repeated. For example, using your logdict class: >>> tab = logdict() >>> tab[1] = logdict() [1] <= <__main__.logdict object at 0x02A2E430> >>> tab[1][2] = logdict() [1] => <__main__.logdict object at 0x02A2E430> [2] <= <__main__.logdict object at 0x02A2EB10> >>> tab[1][2][3] = ['value'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] <= ['value'] >>> tab[1][2][3] += [' with extra tail'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] => ['value'] [3] <= ['value', ' with extra tail'] versus: >>> tab[1][2][3] = ['value'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] <= ['value'] >>> tab[1][2][3] = tab[1][2][3] + [' with extra tail'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] => ['value'] [1] => <__main__.logdict object at 0x02A2E430> [2] => <__main__.logdict object at 0x02A2EB10> [3] <= ['value', ' with extra tail'] As you can see the += version does two fewer getitem calls in this case. From ian.g.kelly at gmail.com Wed Mar 12 05:58:50 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Mar 2014 03:58:50 -0600 Subject: which async framework? In-Reply-To: References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> <372076480416251284.821607sturla.molden-gmail.com@news.gmane.org> <877g80nzdx.fsf@elektro.pacujo.net> <87wqg0mihv.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 11, 2014 at 5:38 PM, Chris Angelico wrote: > On Wed, Mar 12, 2014 at 10:18 AM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> What corner cases are there with threads that you don't have with >>> anything else? >> >> There are numerous. Here's one example: deadlocks due to two threads >> taking locks in a different order. The problem crops up naturally with >> two intercommunicating classes. It can sometimes be very difficult to >> spot or avoid. > > Yep. Now how is that not a problem when you use some other model, like > an event loop? The standard methods of avoiding deadlocks (like > acquiring locks in strict order) work exactly the same for all models, > and are just as necessary. If you don't have threads then the only locks you need to acquire are for external resources. You might still deadlock, but at least your process won't be deadlocking with itself. From eras.rasmuson at gmail.com Wed Mar 12 06:08:04 2014 From: eras.rasmuson at gmail.com (eras.rasmuson at gmail.com) Date: Wed, 12 Mar 2014 03:08:04 -0700 (PDT) Subject: SMTPHandler and mail subject Message-ID: <4b23c949-12eb-444b-a950-c830ace83ca9@googlegroups.com> Hi I use logging.handlers.SMTPHandler and i have tried to change subject of mail. Are there exists easy way to do that ? Subject of mail can change repeatedly depends on content of mail. ---- Eras From oscar.j.benjamin at gmail.com Wed Mar 12 06:20:25 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 12 Mar 2014 10:20:25 +0000 Subject: Tuples and immutability In-Reply-To: References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> Message-ID: On 12 March 2014 03:25, Terry Reedy wrote: > On 3/11/2014 10:01 PM, Rick Johnson wrote: >> >> >> On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: >>> >>> x += y is meant to be equivalent, except possibly in-place and >>> more efficient, than x = x + y. > > > The manual actually says "An augmented assignment expression like x += 1 can > be rewritten as x = x + 1 to achieve a similar, but not exactly equal > effect. In the augmented version, x is only evaluated once. Also, when > possible, the actual operation is performed in-place, meaning that rather > than creating a new object and assigning that to the target, the old object > is modified instead. > > > >> In an ideal world, the speed of these two codes should be the same, > > > Nope, 'similar' is not 'equivalent'. Evaluating x twice instead of once and > possibly allocating a new object versus not take extra time. In a statement > like "x.y.z[3*n+m] += 1", calculating the target dominates the time to > increment, so this form should be nearly twice as fast. An example where the result is semantically different: >>> from numpy import array >>> a = array([1, 2, 3], dtype=int) >>> a array([1, 2, 3]) >>> a + 1.1 array([ 2.1, 3.1, 4.1]) >>> a += 1.1 >>> a array([2, 3, 4]) The reason is that numpy arrays are both mutable and have statically determined elementary data type: >>> (a + 1.1).dtype dtype('float64') >>> a.dtype dtype('int64') Oscar From andriy.kornatskyy at live.com Wed Mar 12 06:27:45 2014 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Wed, 12 Mar 2014 12:27:45 +0200 Subject: SMTPHandler and mail subject In-Reply-To: <4b23c949-12eb-444b-a950-c830ace83ca9@googlegroups.com> References: <4b23c949-12eb-444b-a950-c830ace83ca9@googlegroups.com> Message-ID: Eras, You have to override getSubject method of SMTPHandler. http://hg.python.org/cpython/file/677327810121/Lib/logging/handlers.py#l907 Thanks. Andriy Kornatskyy On Mar 12, 2014, at 12:08 PM, eras.rasmuson at gmail.com wrote: > Hi > > I use logging.handlers.SMTPHandler and i have tried to change subject of mail. > > Are there exists easy way to do that ? > > Subject of mail can change repeatedly depends on content of mail. > > ---- > Eras > -- > https://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Wed Mar 12 06:03:24 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 12 Mar 2014 03:03:24 -0700 Subject: unittest weirdness In-Reply-To: References: Message-ID: <532030EC.7000204@stoneleaf.us> On 03/11/2014 08:36 PM, Terry Reedy wrote: > On 3/11/2014 6:13 PM, John Gordon wrote: >> In Ethan Furman writes: >> >>> if missing: >>> raise ValueError('invoices %r missing from batch' % missing) >> >> It's been a while since I wrote test cases, but I recall using the assert* >> methods (assertEqual, assertTrue, etc.) instead of raising exceptions. >> Perhaps that's the issue? > > Yes. I believe the methods all raise AssertionError on failure, and the test methods are wrapped with try:.. except > AssertionError as err: > > if missing: > raise ValueError('invoices %r missing from batch' % missing) > > should be "assertEqual(missing, [], 'invoices missing from batch')" and if that fails, the non-empty list is printed > along with the message. I've tried it both ways, and both ways my process is being killed, presumably by the O/S. I will say it's an extra motivating factor to have few failing tests -- if more than two of my tests fail, all I see are '.'s, 'E's, and 'F's, with no clues as to which test failed nor why. Thank goodness for '-v' and being able to specify which method of which class to run! -- ~Ethan~ From ndbecker2 at gmail.com Wed Mar 12 07:16:23 2014 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 12 Mar 2014 07:16:23 -0400 Subject: which async framework? References: <531E22DF.7030709@simplistix.co.uk> <1733040935416225908.878896sturla.molden-gmail.com@news.gmane.org> Message-ID: Grant Edwards wrote: > On 2014-03-11, Antoine Pitrou wrote: >> Sturla Molden gmail.com> writes: >>> >>> Chris Withers simplistix.co.uk> wrote: >>> > Hi All, >>> > >>> > I see python now has a plethora of async frameworks and I need to try >>> > and pick one to use from: >>> > >>> > - asyncio/tulip >>> > - tornado >>> > - twisted >>> >>> I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to >>> learn a framework? You will find epoll and kqueue/kevent in the select >>> module and iocp in pywin32. >> >> Yes, why use a library when you can rewrite it all yourself? >> Actually, you should probably issue system calls to the kernel directly, >> the libc is overrated (as is portability, I suppose). > > And don't bother with device drivers for the network adapters either. > Just map their PCI regions in to user-space and twiddle the reigisters > directly! ;) > > [I do that when testing PCI boards with C code, and one of these days > I'm going to figure out how to do it with Python.] > Use numpy with mmap From antoon.pardon at rece.vub.ac.be Wed Mar 12 07:21:05 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 12 Mar 2014 12:21:05 +0100 Subject: Tuples and immutability In-Reply-To: References: <0d76f320-a39e-44e9-85a2-74220b646566@googlegroups.com> <531ffe70$0$2923$c3e8da3$76491128@news.astraweb.com> <53202B57.7060504@rece.vub.ac.be> Message-ID: <53204321.9050904@rece.vub.ac.be> Op 12-03-14 10:51, Ian Kelly schreef: > On Wed, Mar 12, 2014 at 3:39 AM, Antoon Pardon > wrote: >> The documentation is wrong at that point as the following code illustrates. > Either way it still has to do a getitem and a setitem, but if you have > a more nested structure then the extra getitems are not repeated. For > example, using your logdict class: Sure, but the documentation doesn't say for sufficiently nested structures some evaluations are not repeated. Take the following example. | tab['key'] = [1] | tab['key'] += [2] Now let us rewrite that second statment in two different ways. | tab['key'] = tab['key'] + [2] or | tmp = tab['key'] | tmp += [2] Now which of these two rewritings is closer to the augmented concatenation? A natural reading of the documentation would conclude the second one, because in that case we only need to evaluate tab['key'] once as righthand sided. However it turns out the augmented concantenation is closer to the first rewriting here, evaluating tab['key'] twice once a lefthand sided and once as right hand sided, which IMO will surprise people that rely on the documentation. -- Antoon Pardon From fomcl at yahoo.com Wed Mar 12 08:22:59 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Wed, 12 Mar 2014 05:22:59 -0700 (PDT) Subject: locale getlocale returns None on OSX Message-ID: <1394626979.46880.YahooMailBasic@web163806.mail.gq1.yahoo.com> Hi, locale.getlocale() sometimes returns (None, None) under OSX (Python 2, not sure about Python 3, but I think so). The problem is outlined here: http://stackoverflow.com/questions/1629699/locale-getlocale-problems-on-osx What is the cause of this? Is it limited to just Darwin systes? Does the 'horrible hack' solution on OS have any drawbacks? I like it better because it is not needed to set the LC_ALL environment variable prior to starting the Python program. Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From eras.rasmuson at gmail.com Wed Mar 12 08:25:35 2014 From: eras.rasmuson at gmail.com (eras.rasmuson at gmail.com) Date: Wed, 12 Mar 2014 05:25:35 -0700 (PDT) Subject: SMTPHandler and mail subject In-Reply-To: References: <4b23c949-12eb-444b-a950-c830ace83ca9@googlegroups.com> Message-ID: It works. Thank you :) ---- Eras From zoom at yahoo.com Wed Mar 12 08:29:49 2014 From: zoom at yahoo.com (zoom) Date: Wed, 12 Mar 2014 13:29:49 +0100 Subject: Save to a file, but avoid overwriting an existing file Message-ID: Hi! I would like to assure that when writing to a file I do not overwrite an existing file, but I'm unsure which is the best way to approach to this problem. As I can see, there are at least two possibilities: 1. I could use fd = os.open("x", os.O_WRONLY | os.O_CREAT | os.O_EXCL) which will fail - if the file exists. However, I would prefer if the program would try to save under different name in this case, instead of discarding all the calculation done until now - but I' not too well with catching exceptions. 2. Alternatively, a unique string could be generated to assure that no same file exists. I can see one approach to this is to include date and time in the file name. But this seems to me a bit clumsy, and is not unique, i.e. it could happen (at least in theory) that two processes finish in the same second. Any suggestions, please? From skip at pobox.com Wed Mar 12 08:37:44 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 12 Mar 2014 07:37:44 -0500 Subject: Save to a file, but avoid overwriting an existing file In-Reply-To: References: Message-ID: This seems to be an application-level decision. If so, in your application, why not just check to see if the file exists, and implement whatever workaround you deem correct for your needs? For example (to choose a simple, but rather silly, file naming strategy): fname = "x" while os.path.exists(fname): fname = "%s.%f" % (fname, random.random()) fd = open(fname, "w") It's clearly not going to be safe from race conditions, but I leave solving that problem as an exercise for the reader. Skip From 114piyush at gmail.com Wed Mar 12 09:09:27 2014 From: 114piyush at gmail.com (Piyush Verma) Date: Wed, 12 Mar 2014 18:39:27 +0530 Subject: How do we pass default argument value to create thread object? Message-ID: Hi, I am using Thread class to create threads. thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) thread.start() This code is throwing compilation error(Ipython). In [19]: import threading In [20]: def Fun(agr1, arg2, arg3=None): ....: pass ....: In [21]: thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val" ]) ------------------------------------------------------------ File "", line 1 thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) ^ SyntaxError: invalid syntax How do we pass the value to default arguments while creating thread object? Regards, ~Piyush Facebook Twitter -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Wed Mar 12 09:33:06 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 12 Mar 2014 08:33:06 -0500 Subject: Save to a file, but avoid overwriting an existing file In-Reply-To: References: Message-ID: <20140312083306.4111c5bd@bigbox.christie.dr> On 2014-03-12 13:29, zoom wrote: > 2. Alternatively, a unique string could be generated to assure that > no same file exists. I can see one approach to this is to include > date and time in the file name. But this seems to me a bit clumsy, > and is not unique, i.e. it could happen (at least in theory) that > two processes finish in the same second. Python offers a "tempfile" module that gives this (and a whole lot more) to you out of the box. -tkc From roy at panix.com Wed Mar 12 09:44:47 2014 From: roy at panix.com (Roy Smith) Date: Wed, 12 Mar 2014 09:44:47 -0400 Subject: unittest weirdness References: Message-ID: In article , Ethan Furman wrote: > I've tried it both ways, and both ways my process is being killed, presumably > by the O/S. What evidence do you have the OS is killing the process? Some systems have an oom (Out Of Memory) process killer, which nukes (semi-random) process when the system exhausts memory. Is it possible this is happening? If so, you should see some log message in one of your system logs. You didn't mention (or maybe I misssed it) which OS you're using. I'm assuming you've got some kind of system call tracer (strace, truss, dtrace, etc). Try running your tests under that. If something is sending your process a kill signal, you'll see it: [gazillions of lines elided] write(1, ">>> ", 4>>> ) = 4 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 select(1, [0], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be restarted) --- SIGTERM (Terminated) @ 0 (0) --- +++ killed by SIGTERM +++ Alternatively, maybe something inside your process is just calling sys.exit(), or even os._exit(). You'll see the exit() system call in the strace output. And, of course, the standard suggestion to reduce this down to the minimum test case. You posted: def test_xxx_1(self): p = self.pp.lockbox_payments[0] # affirm we have what we're expecting self.assertEqual( (p.payer, p.ck_num, p.credit), ('a customer', '010101', 10000), ) self.assertEqual(p.invoices.keys(), ['XXXXXXXXXXX']) self.assertEqual(p.invoices.values()[0].amount, 10000) # now make sure we get back what we're expecting np, b = self.pp._match_invoices(p) missing = [] for inv_num in ('123456', '789012', '345678'): if inv_num not in b: missing.append(inv_num) if missing: raise ValueError('invoices %r missing from batch' % missing) what happens if you reduce that to: def test_xxx_1(self): self.fail() do you still get this strange behavior? What if you get rid of your setUpClass()? Keep hacking away at the test suite until you get down to a single line of code which, if run, exhibits the behavior, and if commented out, does not. At that point, you'll have a clue what's causing this. If you're lucky :-) From jeanmichel at sequans.com Wed Mar 12 09:51:15 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 12 Mar 2014 14:51:15 +0100 (CET) Subject: How do we pass default argument value to create thread object? In-Reply-To: Message-ID: <1105316214.7314008.1394632275305.JavaMail.root@sequans.com> ----- Original Message ----- > Hi, > I am using Thread class to create threads. > > thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) > thread.start() > > This code is throwing compilation error(Ipython). > In [19]: import threading > In [20]: def Fun(agr1, arg2, arg3=None): > ....: pass > ....: > In [21]: thread = threading.Thread(target=Fun, args=[arg1, arg2, > arg3="val" ]) > ------------------------------------------------------------ > File "", line 1 > thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) > ^ > SyntaxError: invalid syntax > How do we pass the value to default arguments while creating thread > object? > Regards, > ~Piyush > Facebook Twitter Hi, try something like thread = threading.Thread(target=Fun, args=("val1", "val2"), kwargs={"arg3":"val3"}) This will call Fun("val1", "val2", arg3="val3") Browse the python tutorial for details on arguments and keyword arguments. Cheers, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From zachary.ware+pylist at gmail.com Wed Mar 12 10:12:39 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 12 Mar 2014 09:12:39 -0500 Subject: How do we pass default argument value to create thread object? In-Reply-To: References: Message-ID: On Wed, Mar 12, 2014 at 8:09 AM, Piyush Verma <114piyush at gmail.com> wrote: > Hi, > > I am using Thread class to create threads. > > thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) > thread.start() > > > This code is throwing compilation error(Ipython). > In [19]: import threading > > In [20]: def Fun(agr1, arg2, arg3=None): > ....: pass > ....: > > In [21]: thread = threading.Thread(target=Fun, args=[arg1, arg2, > arg3="val"]) > ------------------------------------------------------------ > File "", line 1 > thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) > ^ > SyntaxError: invalid syntax > > How do we pass the value to default arguments while creating thread object? Use the 'kwargs' argument: thread = threading.Thread(target=Fun, args=[1, 2], kwargs={'arg3': "val"}) See http://docs.python.org/3.4/library/threading#threading.Thread for more info. Hope this helps, -- Zach From zdoor at xs4all.nl Wed Mar 12 10:25:46 2014 From: zdoor at xs4all.nl (Alex van der Spek) Date: 12 Mar 2014 14:25:46 GMT Subject: Deep vs. shallow copy? Message-ID: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> I think I understand the difference between deep vs. shallow copies but I was bitten by this: with open(os.path.join('path', 'foo.txt', 'rb') as txt: reader = csv.reader(txt) data = [row.append(year) for row in reader] This does not work although the append does complete. The below works: with open(os.path.join('path', 'foo.txt', 'rb') as txt: reader = csv.reader(txt) data = [row + [year] for row in reader] However in this context I am baffled. If someone can explain what is going on here, I would be most grateful. Alex van der Spek From skip at pobox.com Wed Mar 12 10:48:38 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 12 Mar 2014 09:48:38 -0500 Subject: Deep vs. shallow copy? In-Reply-To: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> Message-ID: On Wed, Mar 12, 2014 at 9:25 AM, Alex van der Spek wrote: > with open(os.path.join('path', 'foo.txt', 'rb') as txt: > reader = csv.reader(txt) > data = [row.append(year) for row in reader] Forget deep v. shallow copies. What is the value of the variable year? And why would you expect list.append to return anything? Skip From zachary.ware+pylist at gmail.com Wed Mar 12 11:00:09 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 12 Mar 2014 10:00:09 -0500 Subject: Deep vs. shallow copy? In-Reply-To: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> Message-ID: On Wed, Mar 12, 2014 at 9:25 AM, Alex van der Spek wrote: > I think I understand the difference between deep vs. shallow copies but > I was bitten by this: > > with open(os.path.join('path', 'foo.txt', 'rb') as txt: > reader = csv.reader(txt) > data = [row.append(year) for row in reader] > > This does not work although the append does complete. The below works: > > with open(os.path.join('path', 'foo.txt', 'rb') as txt: > reader = csv.reader(txt) > data = [row + [year] for row in reader] > > However in this context I am baffled. If someone can explain what is > going on here, I would be most grateful. Deep/shallow copying doesn't really come into this. row.append() mutates the list (row), it doesn't return a new list. Like most in-place/mutating methods in Python, it returns None instead of self to show that mutation was done, so your listcomp fills `data` with Nones; there is no copying done at all. The second example works as you expected because `row + [year]` results in a new list, which the listcomp is happy to append to `data`--which does mean that `row` is copied. To avoid the copy that the second listcomp is doing (which really shouldn't be necessary anyway, unless your rows are astronomically huge), you have a couple of options. First, you can expand your listcomp and use append: with open(os.path.join('path', 'foo.txt'), 'rb') as txt: # with your typo fixed ;) reader = csv.reader(txt) data = [] for row in reader: row.append(year) data.append(row) To me, that's pretty readable and pretty clear about what it's doing. Then there's this option, which I don't recommend: import operator with open(os.path.join('path', 'foo.txt'), 'rb') as txt: reader = csv.reader(txt) data = [operator.iadd(row, [year]) for row in reader] This works because operator.iadd is basically shorthand for row.__iadd__([year]), which does return self (otherwise, the assignment part of `row += [year]` couldn't work). But, it's not as clear about what's happening, and only saves a whole two lines (maybe 3 if you already have operator imported). Hope this helps, -- Zach From zdoor at xs4all.nl Wed Mar 12 11:29:59 2014 From: zdoor at xs4all.nl (Alex van der Spek) Date: 12 Mar 2014 15:29:59 GMT Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> Message-ID: <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> On Wed, 12 Mar 2014 10:00:09 -0500, Zachary Ware wrote: > On Wed, Mar 12, 2014 at 9:25 AM, Alex van der Spek > wrote: >> I think I understand the difference between deep vs. shallow copies but >> I was bitten by this: >> >> with open(os.path.join('path', 'foo.txt', 'rb') as txt: >> reader = csv.reader(txt) >> data = [row.append(year) for row in reader] >> >> This does not work although the append does complete. The below works: >> >> with open(os.path.join('path', 'foo.txt', 'rb') as txt: >> reader = csv.reader(txt) >> data = [row + [year] for row in reader] >> >> However in this context I am baffled. If someone can explain what is >> going on here, I would be most grateful. > > Deep/shallow copying doesn't really come into this. row.append() > mutates the list (row), it doesn't return a new list. Like most > in-place/mutating methods in Python, it returns None instead of self to > show that mutation was done, so your listcomp fills `data` with Nones; > there is no copying done at all. The second example works as you > expected because `row + [year]` results in a new list, which the > listcomp is happy to append to `data`--which does mean that `row` is > copied. > > To avoid the copy that the second listcomp is doing (which really > shouldn't be necessary anyway, unless your rows are astronomically > huge), you have a couple of options. First, you can expand your > listcomp and use append: > > with open(os.path.join('path', 'foo.txt'), 'rb') as txt: # with > your typo fixed ;) > reader = csv.reader(txt) > data = [] > for row in reader: > row.append(year) > data.append(row) > > To me, that's pretty readable and pretty clear about what it's doing. > Then there's this option, which I don't recommend: > > import operator > with open(os.path.join('path', 'foo.txt'), 'rb') as txt: > reader = csv.reader(txt) > data = [operator.iadd(row, [year]) for row in reader] > > This works because operator.iadd is basically shorthand for > row.__iadd__([year]), which does return self (otherwise, the assignment > part of `row += [year]` couldn't work). But, it's not as clear about > what's happening, and only saves a whole two lines (maybe 3 if you > already have operator imported). > > Hope this helps, Thank you, that helped immensely! Having been taught programming in Algol60 Python still defeats me at times! Particularly since Algol60 wasn't very long lived and what came thereafter (FORTRAN) much worse. I get it now, the below is equivalent! I am perfectly happy with the one copy of the list row + [year]. Just wanted to learn something here and I have! Python 2.6.5 (r265:79063, Feb 27 2014, 19:44:14) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = [1,2,3] >>> b = 'val' >>> a.append(b) >>> a [1, 2, 3, 'val'] >>> c = a.append(b) >>> print c None >>> From ethan at stoneleaf.us Wed Mar 12 11:32:29 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 12 Mar 2014 08:32:29 -0700 Subject: unittest weirdness In-Reply-To: References: Message-ID: <53207E0D.2060604@stoneleaf.us> On 03/12/2014 06:44 AM, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> I've tried it both ways, and both ways my process is being killed, presumably >> by the O/S. > > What evidence do you have the OS is killing the process? I put a bare try/except around the call to unittest.main, with a print statement in the except, and nothing ever prints. > Some systems have an oom (Out Of Memory) process killer, which nukes > (semi-random) process when the system exhausts memory. Is it possible > this is happening? If so, you should see some log message in one of > your system logs. That would explain why my editor windows were being killed. > You didn't mention (or maybe I misssed it) which OS you're using. Ubuntu 13 something or other. > I'm > assuming you've got some kind of system call tracer (strace, truss, > dtrace, etc). Sadly, I have no experience with those programs yet, and until now didn't even know they existed. > Try running your tests under that. If something is > sending your process a kill signal, you'll see it: > > [gazillions of lines elided] > write(1, ">>> ", 4>>> ) = 4 > rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 > select(1, [0], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be > restarted) > --- SIGTERM (Terminated) @ 0 (0) --- > +++ killed by SIGTERM +++ > > Alternatively, maybe something inside your process is just calling > sys.exit(), or even os._exit(). You'll see the exit() system call in > the strace output. My bare try/except would have caught that. > And, of course, the standard suggestion to reduce this down to the > minimum test case. You posted: > > def test_xxx_1(self): > p = self.pp.lockbox_payments[0] > # affirm we have what we're expecting > self.assertEqual( > (p.payer, p.ck_num, p.credit), > ('a customer', '010101', 10000), > ) > self.assertEqual(p.invoices.keys(), ['XXXXXXXXXXX']) > self.assertEqual(p.invoices.values()[0].amount, 10000) > # now make sure we get back what we're expecting > np, b = self.pp._match_invoices(p) > missing = [] > for inv_num in ('123456', '789012', '345678'): > if inv_num not in b: > missing.append(inv_num) > if missing: > raise ValueError('invoices %r missing from batch' % missing) > > what happens if you reduce that to: > > def test_xxx_1(self): > self.fail() I only get the strange behavior if more than two (or maybe three) of my test cases fail. Less than that magic number, and everything works just fine. It doesn't matter which two or three, either. > do you still get this strange behavior? What if you get rid of your > setUpClass()? Keep hacking away at the test suite until you get down to > a single line of code which, if run, exhibits the behavior, and if > commented out, does not. At that point, you'll have a clue what's > causing this. If you're lucky :-) I strongly suspect it's memory. When I originally wrote the code I tried to include six months worth of EoM data, but had to back it down to three as my process kept mysteriously dying at four or more months. There must be waaaaaaay too much stuff being kept alive by the stack traces of the failed tests. Thanks for your help! -- ~Ethan~ From stefan_ml at behnel.de Wed Mar 12 13:10:03 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 12 Mar 2014 18:10:03 +0100 Subject: How to create an instance of a python class from C++ In-Reply-To: <8AEE6BCA-0F61-4F9E-A18B-13DB283DC134@barrys-emacs.org> References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> <8AEE6BCA-0F61-4F9E-A18B-13DB283DC134@barrys-emacs.org> Message-ID: Barry Scott, 11.03.2014 22:37: > On 5 Mar 2014, at 00:14, Bill wrote: >> I can't figure out how to create an instance >> of a python class from 'C++': > > Why not use pycxx from http://sourceforge.net/projects/cxx/? > > This lib does all the heavy lifting for you for both python2 and python3. > Has docs and examples. Yes, tool support definitely helps here. I was going to suggest Cython (also for obvious reasons), where the code that the OP posted would look like this: def RegisterClass(class_decl): an = type(class_decl)() print(an.description()) return 0 Clearly substantially simpler than the posted C code (and certainly safer, faster and more correct) - although that doesn't really help me much with understanding what the intention of this code is, looks rather weird... Stefan From roy at panix.com Wed Mar 12 13:48:46 2014 From: roy at panix.com (Roy Smith) Date: Wed, 12 Mar 2014 13:48:46 -0400 Subject: unittest weirdness References: Message-ID: In article , Ethan Furman wrote: > > Alternatively, maybe something inside your process is just calling > > sys.exit(), or even os._exit(). You'll see the exit() system call in > > the strace output. > > My bare try/except would have caught that. A bare except would catch sys.exit(), but not os._exit(). Well, no that's not actually true. Calling os._exit() will raise: TypeError: _exit() takes exactly 1 argument (0 given) but it won't catch os._exit(0) :-) > > what happens if you reduce that to: > > > > def test_xxx_1(self): > > self.fail() > > I only get the strange behavior if more than two (or maybe three) of my test > cases fail. Less than that magic number, > and everything works just fine. It doesn't matter which two or three, > either. OK, well, assuming this is a memory problem, what if you do: def test_xxx_1(self): l = [] while True: l.append(0) That should eventually run out of memory. Does that get you the same behavior in a single test case? If so, that at least would be evidence supporting the memory exhaustion theory. > I strongly suspect it's memory. When I originally wrote the code I tried to > include six months worth of EoM data, but > had to back it down to three as my process kept mysteriously dying at four or > more months. There must be waaaaaaay too > much stuff being kept alive by the stack traces of the failed tests. One thing you might try is running your tests under nose (http://nose.readthedocs.org/). Nose knows how to run unittest tests, and one of the gazillion options it has is to run each test case in an isolated process: --process-restartworker If set, will restart each worker process once their tests are done, this helps control memory leaks from killing the system. [NOSE_PROCESS_RESTARTWORKER] that might be what you need. From davea at davea.name Wed Mar 12 14:22:51 2014 From: davea at davea.name (Dave Angel) Date: Wed, 12 Mar 2014 14:22:51 -0400 (EDT) Subject: Save to a file, but avoid overwriting an existing file References: Message-ID: zoom Wrote in message: > Hi! > > I would like to assure that when writing to a file I do not overwrite an > existing file, but I'm unsure which is the best way to approach to this > problem. As I can see, there are at least two possibilities: > > 1. I could use fd = os.open("x", os.O_WRONLY | os.O_CREAT | os.O_EXCL) > which will fail - if the file exists. However, I would prefer if the > program would try to save under different name in this case, instead of > discarding all the calculation done until now - but I' not too well with > catching exceptions. > The tempfile module is your best answer, but if you really need to keep the file afterwards, you'll have the same problem when you rename it later. I suggest you learn about try/except. For simple cases it's not that tough, though if you want to ask about it, you'll need to specify your Python version. -- DaveA From wbrehaut at mcsnet.ca Wed Mar 12 15:06:38 2014 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Wed, 12 Mar 2014 13:06:38 -0600 Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> Message-ID: On 12 Mar 2014 15:29:59 GMT, Alex van der Spek wrote: >On Wed, 12 Mar 2014 10:00:09 -0500, Zachary Ware wrote: > >> On Wed, Mar 12, 2014 at 9:25 AM, Alex van der Spek >> wrote: === 8< === >Having been taught programming in Algol60 Python still defeats me at times! >Particularly since Algol60 wasn't very long lived and what came >thereafter (FORTRAN) much worse. Actually, Algol 60 lived on (and lives on, though not so much used now outside of Scandinavia) in an improved and OOP-extended form in Simula 67 (now just Simula). Most implementations excpt that for DEC-System10 were, however, overpriced and poorly marketed, so we had to wait for C++ (improved and OOP-extended C) for OOP to catch on. === 8< === From jurko.gospodnetic at pke.hr Wed Mar 12 15:34:16 2014 From: jurko.gospodnetic at pke.hr (=?windows-1250?Q?Jurko_Gospodneti=E6?=) Date: Wed, 12 Mar 2014 20:34:16 +0100 Subject: What does gc.get_objects() return? Message-ID: Hi all. I was wondering if someone could explain gc.get_objects() in a bit more detail to me. Does it return a list of 'all objects known to Python'? Only some of them? Which does it return? Which it does not? For example (done using CPython 3.4 interactive interpreter) here it does not contain an object I know exists: > >>> a = object() > >>> a in gc.get_objects() > False but here it does: > >>> class Foo: pass > ... > >>> a = Foo() > >>> a in gc.get_objects() > True It also does not seem to contain string objects. At first I thought that perhaps interned strings were not placed under GC control, so I tested this: > >>> a = "asdkjfhk23498237$&(*$&*($ksjdhfkjsd" > >>> b = "asdkjfhk23498237$&(*$&*($ksjdhfkjsd" > >>> a is b > False > >>> a in gc.get_objects() > False > >>> b in gc.get_objects() > False Which shows that non-interned scripts such as these are not getting listed in gc.get_objects() either. :-s Many thanks. Best regards, Jurko Gospodneti? From emile at fenx.com Wed Mar 12 15:38:54 2014 From: emile at fenx.com (Emile van Sebille) Date: Wed, 12 Mar 2014 12:38:54 -0700 Subject: Save to a file, but avoid overwriting an existing file In-Reply-To: References: Message-ID: On 3/12/2014 5:29 AM, zoom wrote: > 2. Alternatively, a unique string could be generated to assure that no > same file exists. I can see one approach to this is to include date and > time in the file name. But this seems to me a bit clumsy, and is not > unique, i.e. it could happen (at least in theory) that two processes > finish in the same second. I tend to use this method -- prepending the job name or targeting different directories per job precludes duplication. Unless you're running the same job at the same time, in which case tempfile is the way to go (which I use for archiving spooled print files which can occur simultaneously.) Emile From fomcl at yahoo.com Wed Mar 12 15:40:27 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Wed, 12 Mar 2014 12:40:27 -0700 (PDT) Subject: locale getlocale returns None on OSX In-Reply-To: <1394626979.46880.YahooMailBasic@web163806.mail.gq1.yahoo.com> References: <1394626979.46880.YahooMailBasic@web163806.mail.gq1.yahoo.com> Message-ID: <1394653227.54716.YahooMailNeo@web163806.mail.gq1.yahoo.com> >________________________________ > From: Albert-Jan Roskam >To: Python >Sent: Wednesday, March 12, 2014 1:22 PM >Subject: locale getlocale returns None on OSX > > >Hi, > >locale.getlocale() sometimes returns (None, None) under OSX (Python 2, not sure about Python 3, but I think so). The problem is outlined here: >http://stackoverflow.com/questions/1629699/locale-getlocale-problems-on-osx > >What is the cause of this? Is it limited to just Darwin systes? Does the 'horrible hack' solution on OS have any drawbacks? I like it better because it is not needed to set the LC_ALL environment variable prior to starting the Python program. > >Regards, > >Albert-Jan Ok, here are some tests on my own system: albertjan at debian:~$ uname -a Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux Even if locale.setlocale is used first, OSX returns (None, None) when locale.getlocale() is called. Another thing that surprises me in the examples below is the output of the "python -c" example using Python 2.7. Isn't this supposed to be exactly equivalent to the code that follows? # ======== Python 2.7 ========albertjan at debian:~$ python -c "import locale; locale.setlocale(locale.LC_ALL, ""); print(locale.getlocale())" (None, None)?? # <---- why is this? albertjan at debian:~$ python Python 2.7.3 (default, Jan? 2 2013, 13:56:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import locale >>> locale.setlocale(locale.LC_ALL, "") 'en_US.UTF-8' >>> locale.getlocale() ('en_US', 'UTF-8')? # <--- OSX (sometimes?) returns (None, None) here. # ======== Python 3.3 ======== albertjan at debian:~$ python3 -c "import locale; locale.setlocale(locale.LC_ALL, ""); print(locale.getlocale())" ('en_US', 'UTF-8') albertjan at debian:~$ python3 Python 3.3.4 (default, Feb 17 2014, 19:23:00) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import locale >>> locale.setlocale(locale.LC_ALL, "") 'en_US.UTF-8' >>> locale.getlocale() ('en_US', 'UTF-8') # ======== Pypy ======== albertjan at debian:~$ pypy -c "import locale; locale.setlocale(locale.LC_ALL, ""); print locale.getlocale()" (None, None) albertjan at debian:~$ pypy Python 2.7.3 (87aa9de10f9ca71da9ab4a3d53e0ba176b67d086, Mar 10 2014, 14:07:15) [PyPy 2.2.1 with GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. And now for something completely different: ``pypy is a better kind of foolishness - lac'' >>>> import locale >>>> locale.setlocale(locale.LC_ALL, "") 'en_US.UTF-8' >>>> locale.getlocale() ('en_US', 'UTF-8') From drsalists at gmail.com Wed Mar 12 15:53:27 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 12 Mar 2014 12:53:27 -0700 Subject: What does gc.get_objects() return? In-Reply-To: References: Message-ID: On Wed, Mar 12, 2014 at 12:34 PM, Jurko Gospodneti? wrote: > Hi all. > > I was wondering if someone could explain gc.get_objects() in a bit more > detail to me. > > Does it return a list of 'all objects known to Python'? Only some of them? > Which does it return? Which it does not? > > For example (done using CPython 3.4 interactive interpreter) here it does > not contain an object I know exists: > >> >>> a = object() >> >>> a in gc.get_objects() >> False > > > but here it does: > >> >>> class Foo: pass >> ... >> >>> a = Foo() >> >>> a in gc.get_objects() >> True I don't know why some objects aren't showing up in get_objects, but here's a quick note to say it's not just 3.4: $ ./pythons 'import gc; var="data"; print(var in gc.get_objects())' /usr/local/cpython-2.4/bin/python [6600 refs] False /usr/local/cpython-2.5/bin/python False [7536 refs] /usr/local/cpython-2.6/bin/python False [15233 refs] /usr/local/cpython-2.7/bin/python False [18526 refs] /usr/local/cpython-3.0/bin/python Traceback (most recent call last): File "", line 1, in File "/usr/local/cpython-3.0/lib/python3.0/_weakrefset.py", line 121, in __eq__ return self.data == set(ref(item) for item in other) File "/usr/local/cpython-3.0/lib/python3.0/_weakrefset.py", line 121, in return self.data == set(ref(item) for item in other) TypeError: cannot create weak reference to 'str' object [34510 refs] /usr/local/cpython-3.1/bin/python False [37270 refs] /usr/local/cpython-3.2/bin/python False [37700 refs] /usr/local/cpython-3.3/bin/python False [42662 refs] /usr/local/cpython-3.4/bin/python False /usr/local/pypy-2.2/bin/pypy True /usr/local/jython-2.7b1/bin/jython Traceback (most recent call last): File "", line 1, in NotImplementedError: not applicable to Java GC Interesting that it is present in Pypy. From python at mrabarnett.plus.com Wed Mar 12 16:02:07 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Mar 2014 20:02:07 +0000 Subject: What does gc.get_objects() return? In-Reply-To: References: Message-ID: <5320BD3F.5030509@mrabarnett.plus.com> On 2014-03-12 19:34, Jurko Gospodneti? wrote: > Hi all. > > I was wondering if someone could explain gc.get_objects() in a bit > more detail to me. > > Does it return a list of 'all objects known to Python'? Only some of > them? Which does it return? Which it does not? > [snip] gc.is_tracked(...) might be relevant to your question. From nad at acm.org Wed Mar 12 16:43:44 2014 From: nad at acm.org (Ned Deily) Date: Wed, 12 Mar 2014 13:43:44 -0700 Subject: locale getlocale returns None on OSX References: <1394626979.46880.YahooMailBasic@web163806.mail.gq1.yahoo.com> Message-ID: In article <1394626979.46880.YahooMailBasic at web163806.mail.gq1.yahoo.com>, Albert-Jan Roskam wrote: > locale.getlocale() sometimes returns (None, None) under OSX (Python 2, not > sure about Python 3, but I think so). The problem is outlined here: > http://stackoverflow.com/questions/1629699/locale-getlocale-problems-on-osx Python's locale uses the plaform's locale implementation and POSIX locale is an old and somewhat weird animal. Make sure you thoroughly read the description of the locale module, in particular, the caveats section: http://docs.python.org/2/library/locale.html#background-details-hints-tip s-and-caveats The first gotcha is that you need to explicitly call locale.setlocale("LC_ALL,"") to get the preferred locale environment, as either specified by the user, by LANG or other LC_* environment variables, or the platform defaults. In general, OS X does not provide a default for your process. However, various environments do. The OS X Terminal.app has profile settings (Preferences -> Settings -> (Profile name) -> Advanced) to specific a character encoding and a checkbox to "Set locale environment variables on startup". With that set properly, programs run under Terminal.app will see LANG set. The user can also set an explicit LANG value in a shell profile, like .profile or .bashrc, but those only apply when a shell is being used. Depending on which profile it is set in, that might not work under all conditions, like under "sudo" or in an "ssh" session. Setting an env variable in a shell profile would also not apply to an double-clickable app bundle since no shell is involved in launching it; it is possible to set environment variables in the app's Info.plist, though. > What is the cause of this? Is it limited to just Darwin systes? Does the > 'horrible hack' solution on OS have any drawbacks? I like it better because > it is not needed to set the LC_ALL environment variable prior to starting the > Python program. As the caveats section points out, setting locale env vars may have unwanted side effects on other parts of the process it is running in or creates. So, if you are using it in a standalone program, it may be OK. If you are using it a module intended to be used by other programs, you probably shouldn't be changing something that could break other parts of the calling program. -- Ned Deily, nad at acm.org From jurko.gospodnetic at pke.hr Wed Mar 12 17:28:13 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Wed, 12 Mar 2014 22:28:13 +0100 Subject: What does gc.get_objects() return? In-Reply-To: <5320BD3F.5030509@mrabarnett.plus.com> References: <5320BD3F.5030509@mrabarnett.plus.com> Message-ID: Hi. On 12.3.2014. 21:02, MRAB wrote: >> I was wondering if someone could explain gc.get_objects() in a bit >> more detail to me. >> >> Does it return a list of 'all objects known to Python'? Only some of >> them? Which does it return? Which it does not? >> > > gc.is_tracked(...) might be relevant to your question. Thanks! The documentation for gc.is_tracked() straightened me out. :-) So gc.collect() returns a list of all the objects GC is in charge of, and which instances are and are not tracked by the GC is, I guess, an interpreter implementation detail. For CPython 3.4 I guess strings and other atomic types such as ints are not, as well as raw object() instances. Custom class instances on the other hand seem to be under GC control. Thanks again. Best regards, Jurko Gospodneti? From skip at pobox.com Wed Mar 12 17:44:07 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 12 Mar 2014 16:44:07 -0500 Subject: DB API question - where is a stored procedure's return value? Message-ID: I've stumbled on a problem with the python-sybase module. If I have a stored procedure like this: create stored procedure test_proc as return 1 and call it from Python like this: curs.callproc("test_proc", {}) it's not clear to me where the return status is stored. Currently, the python-sybase module provides (I believe) the ability to set output parameters (those specified as such in the argument dictionary), and you can iterate over all the result sets the stored procedure produces. Looking at the Python database API (PEP 249), I saw no mention of the return status: .callproc( procname [, parameters ] ) (This method is optional since not all databases provide stored procedures. [3]) Call a stored database procedure with the given name. The sequence of parameters must contain one entry for each argument that the procedure expects. The result of the call is returned as modified copy of the input sequence. Input parameters are left untouched, output and input/output parameters replaced with possibly new values. The procedure may also provide a result set as output. This must then be made available through the standard.fetch*() methods. I see no mention of how to handle the return value. The "modified copy of the input sequence" is just that. In the case of the python-sybase module, any parameter values in the input dictionary of type DataBufType are rewritten with values from the first row of the first result set. The Cursor class also defines a _status_result() method, which sounds promising. I haven't had a chance to try it out yet. My concern is more that the Python database API doesn't mention stored procedure return values at all. What do other database adaptors do about stored procedure return values? Does PEP 249 need revision? Skip From rosuav at gmail.com Wed Mar 12 17:44:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Mar 2014 08:44:56 +1100 Subject: What does gc.get_objects() return? In-Reply-To: References: <5320BD3F.5030509@mrabarnett.plus.com> Message-ID: On Thu, Mar 13, 2014 at 8:28 AM, Jurko Gospodneti? wrote: > So gc.collect() returns a list of all the objects GC is in charge of, and > which instances are and are not tracked by the GC is, I guess, an > interpreter implementation detail. I assume you don't mean collect() there, as that returns the amount of garbage that it just collected :) It's not strictly an implementation detail, beyond that there are certain optimizations. For instance... > For CPython 3.4 I guess strings and other atomic types such as ints are > not, as well as raw object() instances. Custom class instances on the other > hand seem to be under GC control. ... strings and ints should never be listed, and custom objects should always be listed, but I'd say the non-tracking of object() would be an implementation-specific optimization. Definitely the non-tracking of a dict of nothing but atomic keys and values would be that. The concept is that the GC tracks (in that sense; everything in CPython is refcounted, but that's not what these functions look at) anything that could be a part of a reference cycle. That's all it concerns itself with, so something that can't have references to arbitrary objects can't possibly be worth tracking. Interestingly, a tuple of integers is tracked: >>> a=1,2,3 >>> gc.is_tracked(a) True So not all optimizations are done that could be done. ChrisA From i.thrinaxodon at bitch.invalid Wed Mar 12 18:08:41 2014 From: i.thrinaxodon at bitch.invalid (I THRINAXODON) Date: Wed, 12 Mar 2014 18:08:41 -0400 Subject: TALK.ORIGINS CENSORS THE TRUTH Message-ID: EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# ==================================== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON REDDIT -- ---Thrinaxodon From ian.g.kelly at gmail.com Wed Mar 12 18:35:13 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Mar 2014 16:35:13 -0600 Subject: What does gc.get_objects() return? In-Reply-To: References: <5320BD3F.5030509@mrabarnett.plus.com> Message-ID: On Wed, Mar 12, 2014 at 3:44 PM, Chris Angelico wrote: > The concept is that the GC tracks (in that sense; everything in > CPython is refcounted, but that's not what these functions look at) > anything that could be a part of a reference cycle. That's all it > concerns itself with, so something that can't have references to > arbitrary objects can't possibly be worth tracking. Interestingly, a > tuple of integers is tracked: > >>>> a=1,2,3 >>>> gc.is_tracked(a) > True > > So not all optimizations are done that could be done. Or is it? >>> a = 1,2,3 >>> gc.is_tracked(a) True >>> gc.collect() 0 >>> gc.is_tracked(a) False From ian.g.kelly at gmail.com Wed Mar 12 18:40:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Mar 2014 16:40:00 -0600 Subject: What does gc.get_objects() return? In-Reply-To: References: <5320BD3F.5030509@mrabarnett.plus.com> Message-ID: On Wed, Mar 12, 2014 at 4:35 PM, Ian Kelly wrote: >> So not all optimizations are done that could be done. > > Or is it? > >>>> a = 1,2,3 >>>> gc.is_tracked(a) > True >>>> gc.collect() > 0 >>>> gc.is_tracked(a) > False I guess the reason for this is that when PyTuple_New is called, it knows how many elements it will contain but doesn't know yet what they are, so it defers the issue by just going ahead and adding itself to the GC From cs at zip.com.au Wed Mar 12 18:19:25 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 13 Mar 2014 09:19:25 +1100 Subject: Save to a file, but avoid overwriting an existing file In-Reply-To: References: Message-ID: <20140312221925.GA67514@cskk.homeip.net> On 12Mar2014 13:29, zoom wrote: > I would like to assure that when writing to a file I do not > overwrite an existing file, but I'm unsure which is the best way to > approach to this problem. As I can see, there are at least two > possibilities: > > 1. I could use fd = os.open("x", os.O_WRONLY | os.O_CREAT | os.O_EXCL) > which will fail - if the file exists. However, I would prefer if the > program would try to save under different name in this case, instead > of discarding all the calculation done until now - but I' not too > well with catching exceptions. Others have menthions tempfile, though of course you have the same collision issue when you come to rename the temp file if you are keeping it. I would run with option 1 for your task. Just iterate until os.open succeeds. However, you need to distinuish _why_ an open fails. For example, if you were trying to make files in a directory to which you do not have write permission, or just a directory that did not exist, os.open would fail not matter what name you used, so your loop would run forever. Therefore you need to continue _only_ if you get EEXIST. Otherwise abort. So you'd have some code like this (totally untested): # at top of script import errno # where you make the file def open_new(primary_name): try: fd = os.open(primary_name, os.O_WRONLY | os.O_CREAT | os.O_EXCL) except OSError as e: if e.errno != errno.EEXIST: raise else: return primary_name, fd n = 1 while True: secondary_name = "%s.%d" % (primary_name, n) try: fd = os.open(secondary_name, os.O_WRONLY | os.O_CREAT | os.O_EXCL) except OSError as e: if e.errno != errno.EEXIST: raise else: return secondary_name, fd n += 1 # where you need the file path, fd = open_new("x") That gets you a function your can reuse which returns the file's name and the file descriptor. Cheers, -- Cameron Simpson Reason #173 to fear technology: o o o o o o ^|\ ^|^ v|^ v|v |/v |X| \| | /\ >\ /< >\ /< >\ /< >\ o> o o o o o o o \ x <\> <)> |\ /< >\ /< >\ /< >\ >> L Mr. email does the Macarena. From ian.g.kelly at gmail.com Wed Mar 12 19:00:12 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Mar 2014 17:00:12 -0600 Subject: DB API question - where is a stored procedure's return value? In-Reply-To: References: Message-ID: On Wed, Mar 12, 2014 at 3:44 PM, Skip Montanaro wrote: > What do other database adaptors do about stored procedure return > values? Does PEP 249 need revision? I can't speak generally, but in cx_Oracle you either execute a query like this: result = cursor.var(cx_Oracle.NUMBER) cursor.execute(":1 := test_proc()", [result]) print(result.getvalue()) or you use the non-standard callfunc method: print(cursor.callfunc("test_proc", cx_Oracle.NUMBER)) As a general solution, one might wrap a stored procedure that returns a value into a stored procedure that has an output parameter and call it with callproc. Some implementations might include a return value in the parameter list anyway. From breamoreboy at yahoo.co.uk Wed Mar 12 19:04:13 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 12 Mar 2014 23:04:13 +0000 Subject: Save to a file, but avoid overwriting an existing file In-Reply-To: <20140312221925.GA67514@cskk.homeip.net> References: <20140312221925.GA67514@cskk.homeip.net> Message-ID: On 12/03/2014 22:19, Cameron Simpson wrote: > On 12Mar2014 13:29, zoom wrote: >> I would like to assure that when writing to a file I do not >> overwrite an existing file, but I'm unsure which is the best way to >> approach to this problem. As I can see, there are at least two >> possibilities: >> >> 1. I could use fd = os.open("x", os.O_WRONLY | os.O_CREAT | os.O_EXCL) >> which will fail - if the file exists. However, I would prefer if the >> program would try to save under different name in this case, instead >> of discarding all the calculation done until now - but I' not too >> well with catching exceptions. > > Others have menthions tempfile, though of course you have the same collision > issue when you come to rename the temp file if you are keeping it. > > I would run with option 1 for your task. > > Just iterate until os.open succeeds. > > However, you need to distinuish _why_ an open fails. For example, > if you were trying to make files in a directory to which you do not > have write permission, or just a directory that did not exist, > os.open would fail not matter what name you used, so your loop would > run forever. > > Therefore you need to continue _only_ if you get EEXIST. Otherwise abort. > > So you'd have some code like this (totally untested): > > # at top of script > import errno > > # where you make the file > def open_new(primary_name): > try: > fd = os.open(primary_name, os.O_WRONLY | os.O_CREAT | os.O_EXCL) > except OSError as e: > if e.errno != errno.EEXIST: > raise > else: > return primary_name, fd > n = 1 > while True: > secondary_name = "%s.%d" % (primary_name, n) > try: > fd = os.open(secondary_name, os.O_WRONLY | os.O_CREAT | os.O_EXCL) > except OSError as e: > if e.errno != errno.EEXIST: > raise > else: > return secondary_name, fd > n += 1 > > # where you need the file > path, fd = open_new("x") > > That gets you a function your can reuse which returns the file's > name and the file descriptor. > > Cheers, > I haven't looked but would things be easier if the new exception hierarchy were used http://docs.python.org/3.3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ian.g.kelly at gmail.com Wed Mar 12 19:06:50 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Mar 2014 17:06:50 -0600 Subject: DB API question - where is a stored procedure's return value? In-Reply-To: References: Message-ID: On Wed, Mar 12, 2014 at 5:00 PM, Ian Kelly wrote: > result = cursor.var(cx_Oracle.NUMBER) > cursor.execute(":1 := test_proc()", [result]) > print(result.getvalue()) Sorry, that should properly be: result = cursor.var(cx_Oracle.NUMBER) cursor.execute("BEGIN :1 := test_proc(); END;", [result]) print(result.getvalue()) From steve+comp.lang.python at pearwood.info Wed Mar 12 19:07:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2014 23:07:53 GMT Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> Message-ID: <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Mar 2014 15:29:59 +0000, Alex van der Spek wrote: > Having been taught programming in Algol60 Python still defeats me at > times! Particularly since Algol60 wasn't very long lived and what came > thereafter (FORTRAN) much worse. Fortran came first. Fortran was the first high-level language which allowed the programmer to write things that looked rather like the sorts of mathematical expressions they were used to. There were a few higher-level assembly languages that came before Fortran, such as SpeedCoding, Fortran's predecessor, but Fortran was the first truly high-level programming language, and even in 1957 it came with an optimizing compiler. I'm not really familiar with Algol, but I do know Pascal, and you should think of the append method to be like a Pascal procedure. Because Python doesn't have true procedures, it follows the convention that returning the special object None signals the intention to return nothing at all. Hence your example below: >>>> c = a.append(b) >>>> print c > None -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Wed Mar 12 19:14:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Mar 2014 10:14:07 +1100 Subject: What does gc.get_objects() return? In-Reply-To: References: <5320BD3F.5030509@mrabarnett.plus.com> Message-ID: On Thu, Mar 13, 2014 at 9:35 AM, Ian Kelly wrote: > Or is it? > >>>> a = 1,2,3 >>>> gc.is_tracked(a) > True >>>> gc.collect() > 0 >>>> gc.is_tracked(a) > False Huh, *that* is interesting! ChrisA From petite.abeille at gmail.com Wed Mar 12 19:11:09 2014 From: petite.abeille at gmail.com (Petite Abeille) Date: Thu, 13 Mar 2014 00:11:09 +0100 Subject: DB API question - where is a stored procedure's return value? In-Reply-To: References: Message-ID: On Mar 13, 2014, at 12:00 AM, Ian Kelly wrote: > As a general solution, one might wrap a stored procedure that returns > a value into a stored procedure that has an output parameter and call > it with callproc. Some implementations might include a return value > in the parameter list anyway. Alternatively? if it?s really a function? wrap it in a select statement? such as: select foo() as value from dual From steve+comp.lang.python at pearwood.info Wed Mar 12 19:14:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2014 23:14:51 GMT Subject: unittest weirdness References: Message-ID: <5320ea6b$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Mar 2014 08:32:29 -0700, Ethan Furman wrote: > There must > be waaaaaaay too much stuff being kept alive by the stack traces of the > failed tests. I believe that unittest does keep stack traces alive until the process ends. I thought that there was a recent bug report for it, but the only one I can find was apparently fixed more than a decade ago: http://bugs.python.org/issue451309 -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Wed Mar 12 19:20:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2014 23:20:46 GMT Subject: Tuples and immutability References: <531f3dfb$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5320ebce$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Mar 2014 17:06:43 -0600, Ian Kelly wrote: > On Tue, Mar 11, 2014 at 10:46 AM, Steven D'Aprano > wrote: >>> There are a number of possible solutions. One possibility would be to >>> copy the Circle as an Ellipse and return the new object instead of >>> mutating it. Then you have the situation where, given a mutable object >>> x that satisfies isinstance(x, Ellipse), the stretch method *may* be >>> able to update the object in-place, or it *may* not. >> >> That is a really lousy design. Of course we are free to create classes >> with ugly, inconsistent, stupid or unworkable APIs if we like. Python >> won't stop us: > > That's true but irrelevant to my point, which was to counter the > assertion that mutable types can always be assumed to be able to perform > operations in-place. "Always"? Not so fast. This is Python. We have freedom to abuse nearly everything, and if you want to shoot yourself in the foot, you can. With the exception of a handful of things which cannot be overridden (e.g. None, numeric literals, syntax) you cannot strictly assume anything about anything. Python does not enforce that iterators raise StopIteration when empty, or that indexing beyond the boundaries of a sequence raises IndexError, or that __setitem__ of a mapping sets the key and value, or that __len__ returns a length. Augmented assignment is no different. The docs describe the intention of the designers and the behaviour of the classes that they control, so with standard built-in classes like int, str, list, tuple etc. you can safely assume that mutable types will perform the operation in place and immutable types won't, but with arbitrary types from some arbitrarily eccentric or twisted programmer, who knows what it will do? -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Wed Mar 12 19:38:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2014 23:38:56 GMT Subject: unittest weirdness References: Message-ID: <5320f00f$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 11 Mar 2014 13:58:17 -0700, Ethan Furman wrote: > class Test_wfbrp_20140225(TestCase): > > @classmethod > def setUpClass(cls): > cls.pp = wfbrp.PaymentProcessor( > '.../lockbox_file', > '.../aging_file', > [ > Path('month_end_1'), > Path('month_end_2'), > Path('month_end_3'), > ], > ) This has nothing to do with your actual problem, which appears to be the Linux(?) OOM killer reaping your applications, just some general observations on your test. > def test_xxx_1(self): Having trouble thinking up descriptive names for the test? That's a sign that the test might be doing too much. Each test should check one self- contained thing. That may or may not be a single call to a unittest assert* method, but it should be something you can describe in a few words: "it's a regression test for bug 23" "test that the database isn't on fire" "invoices should have a valid debtor" "the foo report ought to report all the foos" "...and nothing but the foos." This hints -- its just a hint, mind you, since I lack all specific knowledge of your application -- that the following "affirm" tests should be pulled out into separate tests. > p = self.pp.lockbox_payments[0] > # affirm we have what we're expecting > self.assertEqual( > (p.payer, p.ck_num, p.credit), > ('a customer', '010101', 10000), > ) > self.assertEqual(p.invoices.keys(), ['XXXXXXXXXXX']) > self.assertEqual(p.invoices.values()[0].amount, 10000) which would then leave this to be the Actual Thing Being Tested for this test, which then becomes test_no_missing_invoices rather than test_xxx_1. > # now make sure we get back what we're expecting > np, b = self.pp._match_invoices(p) > missing = [] > for inv_num in ('123456', '789012', '345678'): > if inv_num not in b: > missing.append(inv_num) > if missing: > raise ValueError('invoices %r missing from batch' % > missing) Raising an exception directly inside the test function should only occur if the test function is buggy. As Terry has already suggested, this probably communicates your intention much better: self.assertEqual(missing, []) -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Wed Mar 12 19:47:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2014 23:47:47 GMT Subject: unittest weirdness References: Message-ID: <5320f223$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 12 Mar 2014 08:32:29 -0700, Ethan Furman wrote: >> Some systems have an oom (Out Of Memory) process killer, which nukes >> (semi-random) process when the system exhausts memory. Is it possible >> this is happening? If so, you should see some log message in one of >> your system logs. > > That would explain why my editor windows were being killed. Try opening a second console tab and running top in it. It will show the amount of memory being used. Then run the tests in the first, jump back to top, and watch to see if memory use goes through the roof: top -Mm -d 0.5 will sort by memory use, display memory in more sensible human-readable units instead of bytes, and update the display every 0.5 second. You can then hit the "i" key to toggle display of idle processes and only show those that are actually doing something (which presumably will include Python running the tests). This at least will allow you to see whether or not memory is the concern. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben+python at benfinney.id.au Wed Mar 12 20:22:55 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 13 Mar 2014 11:22:55 +1100 Subject: Save to a file, but avoid overwriting an existing file References: <20140312221925.GA67514@cskk.homeip.net> Message-ID: <85zjkvrlpc.fsf@benfinney.id.au> Cameron Simpson writes: > Therefore you need to continue _only_ if you get EEXIST. Otherwise > abort. If you target Python 3.3 or later, you can catch ?FileExistsError? which is far simpler than messing around with ?errno? values. -- \ ?I know you believe you understood what you think I said, but I | `\ am not sure you realize that what you heard is not what I | _o__) meant.? ?Robert J. McCloskey | Ben Finney From ethan at stoneleaf.us Wed Mar 12 20:31:14 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 12 Mar 2014 17:31:14 -0700 Subject: unittest weirdness In-Reply-To: <5320f223$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <5320f223$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5320FC52.7090902@stoneleaf.us> On 03/12/2014 04:47 PM, Steven D'Aprano wrote: > > top -Mm -d 0.5 Cool, thanks! -- ~Ethan~ From ethan at stoneleaf.us Wed Mar 12 20:36:03 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 12 Mar 2014 17:36:03 -0700 Subject: unittest weirdness In-Reply-To: <5320f00f$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <5320f00f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5320FD73.7080603@stoneleaf.us> On 03/12/2014 04:38 PM, Steven D'Aprano wrote: > > [snip lots of good advice for unit testing] I was just removing the Personally Identifiable Information. Each test is pulling a payment from a batch of payments, so the first couple asserts are simply making sure I have the payment I think I have, then I run the routine that is supposed to match that payment with a bunch of invoices, and then I test to make sure I got back the invoices that I have manually verified are the correct ones to be returned. There are many different tests because there are many different paths through the code, depending on exactly which combination of insanities the bank, the customer, and the company choose to inflict at that moment. ;) -- ~Ethan~ From ian.g.kelly at gmail.com Wed Mar 12 21:35:29 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 12 Mar 2014 19:35:29 -0600 Subject: Tuples and immutability In-Reply-To: <5320ebce$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <531f3dfb$0$29994$c3e8da3$5496439d@news.astraweb.com> <5320ebce$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 12, 2014 at 5:20 PM, Steven D'Aprano wrote: > On Tue, 11 Mar 2014 17:06:43 -0600, Ian Kelly wrote: > >> That's true but irrelevant to my point, which was to counter the >> assertion that mutable types can always be assumed to be able to perform >> operations in-place. > > "Always"? Not so fast. > > This is Python. We have freedom to abuse nearly everything, and if you > want to shoot yourself in the foot, you can. With the exception of a > handful of things which cannot be overridden (e.g. None, numeric > literals, syntax) you cannot strictly assume anything about anything. > Python does not enforce that iterators raise StopIteration when empty, or > that indexing beyond the boundaries of a sequence raises IndexError, or > that __setitem__ of a mapping sets the key and value, or that __len__ > returns a length. Thank you; you've stated my point more succinctly than I did. > Augmented assignment is no different. The docs describe the intention of > the designers and the behaviour of the classes that they control, so with > standard built-in classes like int, str, list, tuple etc. you can safely > assume that mutable types will perform the operation in place and > immutable types won't, but with arbitrary types from some arbitrarily > eccentric or twisted programmer, who knows what it will do? This got me curious about how consistent the standard library is about this exactly, so I did some grepping. In the standard library there are 5 mutable types that support concatenation that I was able to find: list, deque, array, bytearray, and Counter. There are none that support addition, which I find interesting in that the language provides hooks for in-place addition but never uses them itself. All of the classes above appear to follow the rule that if you can concatenate an operand, you can in-place concatenate the same operand. The converse however does not hold: list.__iadd__ and Counter.__iadd__ are both more permissive in what types they will accept than their __add__ counterparts, and especially interesting to me is that deque implements __iadd__ but does not implement __add__ at all. This last in particular seems to support the assertion that += should be viewed more as a shorthand for an in-place operation, less as an equivalent for x = x + y. >>> l = [1,2,3] >>> l + (4,5,6) Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate list (not "tuple") to list >>> l += (4,5,6) >>> l [1, 2, 3, 4, 5, 6] >>> c = collections.Counter('mississippi') >>> c + collections.Counter('alabama') Counter({'s': 4, 'a': 4, 'i': 4, 'p': 2, 'm': 2, 'b': 1, 'l': 1}) >>> c + dict({'a': 4, 'l': 1, 'b': 1, 'm': 1}) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'Counter' and 'dict' >>> c += dict({'a': 4, 'l': 1, 'b': 1, 'm': 1}) >>> c Counter({'s': 4, 'a': 4, 'i': 4, 'p': 2, 'm': 2, 'b': 1, 'l': 1}) >>> d = collections.deque([1,2,3]) >>> d += [4,5,6] >>> d deque([1, 2, 3, 4, 5, 6]) >>> d + [7,8,9] Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'collections.deque' and 'list' >>> d.__add__ Traceback (most recent call last): File "", line 1, in AttributeError: 'collections.deque' object has no attribute '__add__' From tjreedy at udel.edu Wed Mar 12 22:09:24 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Mar 2014 22:09:24 -0400 Subject: Tuples and immutability In-Reply-To: References: <531f3dfb$0$29994$c3e8da3$5496439d@news.astraweb.com> <5320ebce$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/12/2014 9:35 PM, Ian Kelly wrote: > On Wed, Mar 12, 2014 at 5:20 PM, Steven D'Aprano > wrote: >> On Tue, 11 Mar 2014 17:06:43 -0600, Ian Kelly wrote: >> >>> That's true but irrelevant to my point, which was to counter the >>> assertion that mutable types can always be assumed to be able to perform >>> operations in-place. >> >> "Always"? Not so fast. >> >> This is Python. We have freedom to abuse nearly everything, and if you >> want to shoot yourself in the foot, you can. With the exception of a >> handful of things which cannot be overridden (e.g. None, numeric >> literals, syntax) you cannot strictly assume anything about anything. >> Python does not enforce that iterators raise StopIteration when empty, or >> that indexing beyond the boundaries of a sequence raises IndexError, or >> that __setitem__ of a mapping sets the key and value, or that __len__ >> returns a length. > > Thank you; you've stated my point more succinctly than I did. > >> Augmented assignment is no different. The docs describe the intention of >> the designers and the behaviour of the classes that they control, so with >> standard built-in classes like int, str, list, tuple etc. you can safely >> assume that mutable types will perform the operation in place and >> immutable types won't, but with arbitrary types from some arbitrarily >> eccentric or twisted programmer, who knows what it will do? > > This got me curious about how consistent the standard library is about > this exactly, so I did some grepping. In the standard library there > are 5 mutable types that support concatenation that I was able to > find: list, deque, array, bytearray, and Counter. There are none that > support addition, which I find interesting in that the language > provides hooks for in-place addition but never uses them itself. > > All of the classes above appear to follow the rule that if you can > concatenate an operand, you can in-place concatenate the same operand. > The converse however does not hold: list.__iadd__ and > Counter.__iadd__ are both more permissive in what types they will > accept than their __add__ counterparts, and especially interesting to > me is that deque implements __iadd__ but does not implement __add__ at > all. This last in particular seems to support the assertion that += > should be viewed more as a shorthand for an in-place operation, less > as an equivalent for x = x + y. > >>>> l = [1,2,3] >>>> l + (4,5,6) > Traceback (most recent call last): > File "", line 1, in > TypeError: can only concatenate list (not "tuple") to list >>>> l += (4,5,6) >>>> l > [1, 2, 3, 4, 5, 6] Like it or not, one should actually think of 'somelist += iterable' as equivalent to 'somelist.extend(iterable)'. Without looking at the C code, I suspect that the latter is the internal implementation. Collections.deque also has .extend. Collections.Counter has .update and that is += seems to be doing. >>>> c = collections.Counter('mississippi') >>>> c + collections.Counter('alabama') > Counter({'s': 4, 'a': 4, 'i': 4, 'p': 2, 'm': 2, 'b': 1, 'l': 1}) >>>> c + dict({'a': 4, 'l': 1, 'b': 1, 'm': 1}) > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for +: 'Counter' and 'dict' >>>> c += dict({'a': 4, 'l': 1, 'b': 1, 'm': 1}) >>>> c > Counter({'s': 4, 'a': 4, 'i': 4, 'p': 2, 'm': 2, 'b': 1, 'l': 1}) > >>>> d = collections.deque([1,2,3]) >>>> d += [4,5,6] >>>> d > deque([1, 2, 3, 4, 5, 6]) >>>> d + [7,8,9] > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for +: 'collections.deque' and 'list' >>>> d.__add__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'collections.deque' object has no attribute '__add__' > -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 12 22:27:07 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Mar 2014 22:27:07 -0400 Subject: unittest weirdness In-Reply-To: <53207E0D.2060604@stoneleaf.us> References: <53207E0D.2060604@stoneleaf.us> Message-ID: On 3/12/2014 11:32 AM, Ethan Furman wrote: > I strongly suspect it's memory. When I originally wrote the code I > tried to include six months worth of EoM data, but had to back it down > to three as my process kept mysteriously dying at four or more months. > There must be waaaaaaay too much stuff being kept alive by the stack > traces of the failed tests. There is an issue or two about unittest not releasing memory. Also, modules are not cleared from sys.modules, so anything accessible from global scope is kept around. -- Terry Jan Reedy From cs at zip.com.au Wed Mar 12 22:49:27 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 13 Mar 2014 13:49:27 +1100 Subject: Save to a file, but avoid overwriting an existing file In-Reply-To: <85zjkvrlpc.fsf@benfinney.id.au> References: <85zjkvrlpc.fsf@benfinney.id.au> Message-ID: <20140313024927.GA8841@cskk.homeip.net> On 13Mar2014 11:22, Ben Finney wrote: > Cameron Simpson writes: > > Therefore you need to continue _only_ if you get EEXIST. Otherwise > > abort. > > If you target Python 3.3 or later, you can catch ?FileExistsError? > > which is far simpler than messing around with ?errno? values. Yes and no. Firstly, we Old Farts find these new ways confusing:-) Secondly, and perhaps more importantly, if I were using the O_EXCL et al constants in a call to os.open as the OP is doing, I would want to be equally picky about what I recognise in the exception; I _want_ to use error explicitly. In particular, the behaviour of "os.open" is pretty much a bare metal call to the POSIX "open(2)" OS interface, and so I want my response to be framed directly in terms of the documented error responses for that API. Thus, errno values. Finally, if I were grouping my responses to the exception by type and perhaps performing a few different actions depending on the error, then the new class hierachy is a good way to do it. But for this instance, IMO, we're catching exactly one failure mode as "retry with another name" and reraising anything else. So I don't find an errno test any less readable that a class comparison, and it still feels more precise to me. Cheers, -- Cameron Simpson The road less traveled is FASTER !! - Luc Marcouiller, marcouil at ireq.hydro.qc.ca From tjreedy at udel.edu Wed Mar 12 22:54:55 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 12 Mar 2014 22:54:55 -0400 Subject: What does gc.get_objects() return? In-Reply-To: References: Message-ID: On 3/12/2014 3:34 PM, Jurko Gospodneti? wrote: > I was wondering if someone could explain gc.get_objects() in a bit > more detail to me. > > Does it return a list of 'all objects known to Python'? Only some of > them? Which does it return? Which it does not? This took about 10 seconds. >>> import gc >>> help(gc.get_objects) Help on built-in function get_objects in module gc: get_objects(...) get_objects() -> [...] Return a list of objects tracked by the collector (excluding the list returned). --- Now, what object does gc track? CPython answer: objects that could be involved in and kept alive by reverence cycles and therefore not deleted when not needed by reference counting alone. Object instances, numbers, and strings cannot be involved in reference cycles, as there are no user settable references. Tuples can be: a = [] b = (a,) a[0] = b A tuple of, for instance, ints would not need to be tracked, but if it is, someone probably decided that the cost of checking is not worth the benefit. Details are subject to change with versions. In 3.4, gc can break cycles of objects with delete methods, whereas they previously waiting until program shutdown. Some year ago, I remember a suggestion to turn off gc while creating lots of tuples that did not need to be tracked, but I do not know if that is still useful. -- Terry Jan Reedy From rustompmody at gmail.com Wed Mar 12 23:09:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 12 Mar 2014 20:09:25 -0700 (PDT) Subject: Deep vs. shallow copy? In-Reply-To: <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0852919b-e5ac-42cc-b30f-f465a144e24e@googlegroups.com> On Thursday, March 13, 2014 4:37:53 AM UTC+5:30, Steven D'Aprano wrote: > On Wed, 12 Mar 2014 15:29:59 +0000, Alex van der Spek wrote: > > Having been taught programming in Algol60 Python still defeats me at > > times! Particularly since Algol60 wasn't very long lived and what came > > thereafter (FORTRAN) much worse. > I'm not really familiar with Algol, but I do know Pascal, and you should > think of the append method to be like a Pascal procedure. Because Python > doesn't have true procedures, it follows the convention that returning > the special object None signals the intention to return nothing at all. > Hence your example below: Yes... Algol I dont know. But to the extent that it corresponds to Pascal the following may help. Pascal is remarkably clean and cleaner than what came before -- Lisp -- and after -- C, all its derivatives, python... almost everything. First off there are expressions and statements, and no messing with the distinction. C started laissez-faire. No void, just default functions intended to be used as procedures to int. This was problematic to enough people that void was introduced soon enough. But its still messy: An assignment like x = 3 is both an expression and (like) a statement. It is mostly used as a statement by appending a semicolon. It can also be used as an expression as in y = x = 3. Try explaining this to a first year class and you'd know what a mess it is. For the most part if you think youve got it you probably havent. Python is in some respects worse than C, in some better. Its better in that assignment statements are not re-purposeable as expressions. Its worse in that procedures are simulated by None returning functions -- this means syntax errors which C would give when using a void function as an expression, you wont get in python. On the whole, whether your language supports it or not, its best to think of the world as separated into actions and values. Call the action-world the 'imperative' world. Call the value-world the 'functional' world ('declarative' would be better but 'functional' is too entrenched). [Following table meant to be read with fixed (courier) font] | | Imperative | Functional | | Language entity | Statement | Expression | | Denote (and think with) | Action | Value | | Abstracted into | Procedure | Function | | Atoms are | Assignment | Constant/Variable | | Data Structures | Mutable | Immutable | | Loop primitive | Recursion | Iteration | | World is | In time | Timeless (Platonic) | Generally mixing these two worlds is necessary for any non-trivial programming but is commonly problematic. Your error was to use a functional form -- list comprehension -- and embed an imperative construct -- row.append -- into that. This is always a gaffe Legal mixing is done thus Expression -> Statement by putting the expression on the rhs of an assignment Statement -> Expression by putting the statement(s) into a function While most programmers think this unproblematic, Backus' widely-cited Turing Award lecture is devoted to showing why this is a problem http://www.thocp.net/biographies/papers/backus_turingaward_lecture.pdf For an old Algol/Fortran programmer it may be a worthwhile read considering Backus invented Fortran :-) From chris at simplistix.co.uk Thu Mar 13 02:22:01 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 13 Mar 2014 06:22:01 +0000 Subject: SMTPHandler and mail subject In-Reply-To: References: <4b23c949-12eb-444b-a950-c830ace83ca9@googlegroups.com> Message-ID: <53214E89.2080101@simplistix.co.uk> If you want a much more fully-featured mail handler for the standard logging framework, there's this: https://pypi.python.org/pypi/mailinglogger/3.8.0 cheers, Chris On 12/03/2014 12:25, eras.rasmuson at gmail.com wrote: > > It works. Thank you :) > > ---- > Eras > -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From richard at pyweek.org Thu Mar 13 06:58:52 2014 From: richard at pyweek.org (Richard Jones) Date: Thu, 13 Mar 2014 21:58:52 +1100 Subject: [ANN] PyWeek 18 will run in May (11th to 18th) Message-ID: Hi all, The Python Game Programming Challenge will run its 18th challenge from the 11th to the 18th of May. The PyWeek challenge: 1. Invites entrants to write a game in one week from scratch either as an individual or in a team, 2. Is intended to be challenging and fun, 3. Will increase the public body of game tools, code and expertise, 4. Will let a lot of people actually finish a game, and 5. May inspire new projects (with ready made teams!) Check out the help page for how to compete (and prepare) and the growing resources message board post: http://pyweek.org/s/help/ http://pyweek.org/d/4008/ Richard -------------- next part -------------- An HTML attachment was scrubbed... URL: From hobson42 at gmail.com Thu Mar 13 07:38:22 2014 From: hobson42 at gmail.com (Ian) Date: Thu, 13 Mar 2014 11:38:22 +0000 Subject: Deep vs. shallow copy? In-Reply-To: <0852919b-e5ac-42cc-b30f-f465a144e24e@googlegroups.com> References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0852919b-e5ac-42cc-b30f-f465a144e24e@googlegroups.com> Message-ID: <532198AE.10509@gmail.com> On 13/03/2014 03:09, Rustom Mody wrote: > Call the action-world the 'imperative' world. > Call the value-world the 'functional' world ('declarative' would be > better but 'functional' is too entrenched). > > [Following table meant to be read with fixed (courier) font] > > | | Imperative | Functional | > | Language entity | Statement | Expression | > | Denote (and think with) | Action | Value | > | Abstracted into | Procedure | Function | > | Atoms are | Assignment | Constant/Variable | > | Data Structures | Mutable | Immutable | > | Loop primitive | Recursion | Iteration | > | World is | In time | Timeless (Platonic) | Small typo I think in that the looping Primitives are switched about? Regards Ian -- Ian Hobson 29 Manorfield Close, Northampton NN3 9SL, Tel: 01604 513875 Preparing eBooks for Kindle and ePub formats to give the best reader experience. From roy at panix.com Thu Mar 13 07:44:27 2014 From: roy at panix.com (Roy Smith) Date: Thu, 13 Mar 2014 07:44:27 -0400 Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5320e8c9$0$29994$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Because Python doesn't have true procedures What do you mean by "true procedure"? Are you just talking about subroutines that don't return any value, i.e. fortran's SUBROUTINE vs. FUNCTION? From marko at pacujo.net Thu Mar 13 08:27:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 13 Mar 2014 14:27:48 +0200 Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y50el1vf.fsf@elektro.pacujo.net> Roy Smith : > Steven D'Aprano wrote: > >> Because Python doesn't have true procedures > > What do you mean by "true procedure"? Are you just talking about > subroutines that don't return any value, i.e. fortran's SUBROUTINE vs. > FUNCTION? Ah, the "no true procedure" argument: - No true procedure returns a value. - That's false. Python's procedures return None. - They are not true procedures. Marko From jurko.gospodnetic at pke.hr Thu Mar 13 08:36:48 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Thu, 13 Mar 2014 13:36:48 +0100 Subject: What does gc.get_objects() return? In-Reply-To: References: <5320BD3F.5030509@mrabarnett.plus.com> Message-ID: Hi. On 12.3.2014. 23:40, Ian Kelly wrote: >> Or is it? >> >>>>> a = 1,2,3 >>>>> gc.is_tracked(a) >> True >>>>> gc.collect() >> 0 >>>>> gc.is_tracked(a) >> False Ufff.. nice one :-D Best regards, Jurko Gospodneti? From jurko.gospodnetic at pke.hr Thu Mar 13 08:38:39 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Thu, 13 Mar 2014 13:38:39 +0100 Subject: What does gc.get_objects() return? In-Reply-To: References: Message-ID: Hi. On 13.3.2014. 3:54, Terry Reedy wrote: > On 3/12/2014 3:34 PM, Jurko Gospodneti? wrote: > >> I was wondering if someone could explain gc.get_objects() in a bit >> more detail to me. >> >> Does it return a list of 'all objects known to Python'? Only some of >> them? Which does it return? Which it does not? > > [...detailed explanation snipped...] Thank you very much for taking the time to explain it all in detail. Best regards, Jurko Gospodneti? From gordon at panix.com Thu Mar 13 10:43:05 2014 From: gordon at panix.com (John Gordon) Date: Thu, 13 Mar 2014 14:43:05 +0000 (UTC) Subject: DB API question - where is a stored procedure's return value? References: Message-ID: In Petite Abeille writes: > Alternatively=85 if it=92s really a function=85 wrap it in a select = > statement=85 such as: > select foo() as value from dual That will get the return value into an SQL variable, but the OP wanted to know how to fetch it from python code. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From simiasaro at gmail.com Thu Mar 13 10:52:25 2014 From: simiasaro at gmail.com (simiasaro at gmail.com) Date: Thu, 13 Mar 2014 07:52:25 -0700 (PDT) Subject: TypeError: can't multiply sequence by non-int of type 'tuple' In-Reply-To: References: Message-ID: On Friday, February 21, 2014 1:31:53 AM UTC-5, Jaydeep Patil wrote: > HI, > > > > I have a tuple. I need to make sqaure of elements of tuple and after that i want add all suared tuple elements for total. When i trying to do it, below error came. > > > > > > Code: > > seriesxlist1 = ((0.0,), (0.01,), (0.02,), (0.03,), (0.04,), (0.05,), (0.06,), (0.07,), (0.08,), (0.09,), (0.1,), (0.11,)) > > > > x2 = [x * x for x in seriesxlist1]; > > > > Error: > > Traceback (most recent call last): > > File "", line 1, in > > x2 = [x * x for x in seriesxlist1]; > > TypeError: can't multiply sequence by non-int of type 'tuple' > > > > > > > > Please suggest me solution. You may want to identify which of the tuple value you want to multiply, especially since the tuple has only one value: x2 = [x[0] * x[0] for x in seriesxlist1] Then, you can add the values in the list: sum(x2) or the quickest way: sum(x[0] * x[0] for x in seriesxlist1) From skip at pobox.com Thu Mar 13 11:14:36 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 13 Mar 2014 10:14:36 -0500 Subject: DB API question - where is a stored procedure's return value? In-Reply-To: References: Message-ID: Thanks for the responses. We eventually figured out there appears to be a bug in the latest version of the python-sybase module (at least in 0.40, probably in 0.39 as well). It was actually detecting CS_STATUS_RESULT coming from the server and responding appropriately, however it was assigning the actual status result to a local variable instead of an attribute of the Cursor instance. Testing a fix now. Skip From rustompmody at gmail.com Thu Mar 13 11:28:47 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Mar 2014 08:28:47 -0700 (PDT) Subject: Deep vs. shallow copy? In-Reply-To: References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0852919b-e5ac-42cc-b30f-f465a144e24e@googlegroups.com> Message-ID: <04d2454f-4a22-482c-9d41-f2e1d2032675@googlegroups.com> On Thursday, March 13, 2014 5:08:22 PM UTC+5:30, Ian wrote: > On 13/03/2014 03:09, Rustom Mody wrote: > > Call the action-world the 'imperative' world. > > Call the value-world the 'functional' world ('declarative' would be > > better but 'functional' is too entrenched). > > [Following table meant to be read with fixed (courier) font] > > | | Imperative | Functional | > > | Language entity | Statement | Expression | > > | Denote (and think with) | Action | Value | > > | Abstracted into | Procedure | Function | > > | Atoms are | Assignment | Constant/Variable | > > | Data Structures | Mutable | Immutable | > > | Loop primitive | Recursion | Iteration | > > | World is | In time | Timeless (Platonic) | > Small typo I think in that the looping Primitives are switched about? Heh! I was hesitating to put that line at all: For one thing its a hackneyed truth in the non-FP community. For another, in practical Haskell, use of frank recursion is regarded as as sign of programming immaturity: http://www.willamette.edu/~fruehr/haskell/evolution.html So I guess I ended up typing it in the wrong order! From rosuav at gmail.com Thu Mar 13 13:01:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Mar 2014 04:01:02 +1100 Subject: DB API question - where is a stored procedure's return value? In-Reply-To: References: Message-ID: On Fri, Mar 14, 2014 at 1:43 AM, John Gordon wrote: >> select foo() as value from dual > > That will get the return value into an SQL variable, but the OP wanted > to know how to fetch it from python code. In theory, that should produce a one-row-one-column SELECT result, which can then be retrieved as such. (I say "in theory" because not all back-end databases support the "from dual" notation - which, by the way, I find extremely odd; what's 'dual' about it?) ChrisA From random832 at fastmail.us Thu Mar 13 13:22:08 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 13 Mar 2014 13:22:08 -0400 Subject: DB API question - where is a stored procedure's return value? In-Reply-To: References: Message-ID: <1394731328.29875.94134461.087FF85B@webmail.messagingengine.com> On Thu, Mar 13, 2014, at 13:01, Chris Angelico wrote: > On Fri, Mar 14, 2014 at 1:43 AM, John Gordon wrote: > >> select foo() as value from dual > > > > That will get the return value into an SQL variable, but the OP wanted > > to know how to fetch it from python code. > > In theory, that should produce a one-row-one-column SELECT result, > which can then be retrieved as such. (I say "in theory" because not > all back-end databases support the "from dual" notation - which, by > the way, I find extremely odd; what's 'dual' about it?) DUAL is an Oracle thing. It used to have two rows, in order to be used to duplicate results by doing a cartesian join to it. At some point, that was removed, but the name stuck. Most other servers allow SELECT without FROM. From random832 at fastmail.us Thu Mar 13 13:25:08 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 13 Mar 2014 13:25:08 -0400 Subject: Deep vs. shallow copy? In-Reply-To: <04d2454f-4a22-482c-9d41-f2e1d2032675@googlegroups.com> References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0852919b-e5ac-42cc-b30f-f465a144e24e@googlegroups.com> <04d2454f-4a22-482c-9d41-f2e1d2032675@googlegroups.com> Message-ID: <1394731508.30917.94137029.2E73EB99@webmail.messagingengine.com> On Thu, Mar 13, 2014, at 11:28, Rustom Mody wrote: > Heh! I was hesitating to put that line at all: For one thing its a > hackneyed truth in the non-FP community. For another, in practical > Haskell, use of frank recursion is regarded as as sign of programming > immaturity: And IIRC Lisp and Scheme have loop macros (whose semantics are more like a goal seek than iteration IIRC). From rosuav at gmail.com Thu Mar 13 13:32:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Mar 2014 04:32:39 +1100 Subject: DB API question - where is a stored procedure's return value? In-Reply-To: <1394731328.29875.94134461.087FF85B@webmail.messagingengine.com> References: <1394731328.29875.94134461.087FF85B@webmail.messagingengine.com> Message-ID: On Fri, Mar 14, 2014 at 4:22 AM, wrote: > DUAL is an Oracle thing. It used to have two rows, in order to be used > to duplicate results by doing a cartesian join to it. At some point, > that was removed, but the name stuck. > > Most other servers allow SELECT without FROM. Yeah, I usually use PostgreSQL which does. I don't remember what DB2 has. MySQL I think requires either DUAL or an actual real table. ChrisA From ian.g.kelly at gmail.com Thu Mar 13 14:40:58 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Mar 2014 12:40:58 -0600 Subject: Balanced trees In-Reply-To: <87zjkyq7nr.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <87zjkyq7nr.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 10, 2014 at 11:34 AM, Marko Rauhamaa wrote: > The main thing is there are use cases where order is essential. That's > why I have had to implement the AVL tree in Python myself. No biggie, > but a C implementation would probably be much faster. Also, a standard > version would likely be reviewed and tested better and have all Pythonic > accessors in place. That last is actually quite easy to achieve, especially using the built-in ABCs. Just subclass from collections.MutableMapping and implement __len__, __iter__, __getitem__, __setitem__ and __delitem__; and default implementations of the rest will be mixed in for you. Or you can override those with optimized implementations. From jcasale at activenetwerx.com Thu Mar 13 17:24:15 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 13 Mar 2014 21:24:15 +0000 Subject: asyncio question Message-ID: <5ff86b234ac640ab8b7ee3f26e9aa8dc@exch.activenetwerx.com> I have a portion of code I need to speed up, there are 3 api calls to an external system where the first enumerates a large collection of objects I then loop through and perform two additional api calls each. The first call is instant, the second and third per object are very slow. Currently after accumulating all the data I write the relevant data into a database. I have the ability to hold all this in memory and dump it once fully accumulated, so performing the second and third call in parallel with fixed batches would be great, I took a look at coroutines and some skeleton code worked fine, but I am not sure how to perform the acquisition in fixed groups like I might for example with multiprocessing and a pool of workers. Anyone done something like this or have an opinion? Thanks, jlc From steve+comp.lang.python at pearwood.info Thu Mar 13 19:31:50 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Mar 2014 23:31:50 GMT Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53223fe6$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Mar 2014 07:44:27 -0400, Roy Smith wrote: > In article <5320e8c9$0$29994$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Because Python doesn't have true procedures > > What do you mean by "true procedure"? Are you just talking about > subroutines that don't return any value, i.e. fortran's SUBROUTINE vs. > FUNCTION? Yes. If somebody wants to argue that the word "procedure" can mean something else in other contexts, I won't argue, I'll just point out that in the context of my post I had just mentioned Pascal procedures, which don't return a value. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Thu Mar 13 19:41:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Mar 2014 23:41:03 GMT Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> Message-ID: <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Mar 2014 14:27:48 +0200, Marko Rauhamaa wrote: > Roy Smith : > >> Steven D'Aprano wrote: >> >>> Because Python doesn't have true procedures >> >> What do you mean by "true procedure"? Are you just talking about >> subroutines that don't return any value, i.e. fortran's SUBROUTINE vs. >> FUNCTION? > > Ah, the "no true procedure" argument: > > - No true procedure returns a value. > > - That's false. Python's procedures return None. Are you trolling again? I'm sure that you know quite well that Python doesn't have a procedure type. It uses a single keyword, def, for creating both functions and functions-that-return-None. We should all agree that functions-that-return-None are used for the same purpose as procedures, but they are still functions, and they have a return result, namely None. If you don't believe me, believe Python: py> def func(): ... return 42 ... py> def proc(): ... pass ... py> type(func) py> type(proc) py> repr(proc()) 'None' In languages with procedures, that last line would be an error (either at compile-time, or run-time) since a procedure wouldn't return anything to use as argument to repr. But I'm sure that you know that. > - They are not true procedures. Correct. They are functions that return None, rather than a subroutine that doesn't have any return value at all. But I'm sure you know that. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Thu Mar 13 19:55:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Mar 2014 10:55:44 +1100 Subject: Deep vs. shallow copy? In-Reply-To: <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 14, 2014 at 10:41 AM, Steven D'Aprano wrote: > Are you trolling again? > > I'm sure that you know quite well that Python doesn't have a procedure > type. It uses a single keyword, def, for creating both functions and > functions-that-return-None. I'm going to troll for a moment and give you a function that has no return value. def procedure(): raise Exception But seriously, this is something that some functions do when they need to distinguish between returning something and not returning anything. Look at a dictionary's subscripting (which is effectively a function call): >>> x={1:2} >>> x[1] 2 >>> x[3] Traceback (most recent call last): File "", line 1, in x[3] KeyError: 3 It can't return None to indicate "there was no such key in the dictionary", so it raises instead. There's only one way for a Python function to not have a return value: it has to not return. ChrisA From steve+comp.lang.python at pearwood.info Thu Mar 13 19:57:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Mar 2014 23:57:47 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <87zjkyq7nr.fsf@elektro.pacujo.net> Message-ID: <532245fa$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 10 Mar 2014 19:34:48 +0200, Marko Rauhamaa wrote: >> With a high level language like Python, using the provided hash table >> will almost always cream any hand-built tree, no matter how >> advantageous the data is to the tree. > > The main thing is there are use cases where order is essential. That's > why I have had to implement the AVL tree in Python myself. from collections import OrderedDict gives you a fast, ordered mapping. In this case, the order is that of insertion order. If you want sort order instead, for "small" amounts of data, say below a million or ten million items, you're likely to have acceptable if not superior results by just sorting them items when and as needed. Otherwise, I expect that following the basic technique of OrderedDict, and building your data structure from a dict and an associated list, keeping the two in sync, will be faster than a pure Python implementation of an AVL tree. But of course only testing it will make that clear. http://code.activestate.com/recipes/576693-ordered-dictionary-for-py24/ Modifying the above recipe to keep items in something other than insertion order is left as an exercise. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Thu Mar 13 20:08:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Mar 2014 18:08:47 -0600 Subject: Deep vs. shallow copy? In-Reply-To: References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 13, 2014 at 5:55 PM, Chris Angelico wrote: > I'm going to troll for a moment and give you a function that has no > return value. > > def procedure(): > raise Exception >>> import dis >>> dis.dis(procedure) 2 0 LOAD_GLOBAL 0 (Exception) 3 RAISE_VARARGS 1 6 LOAD_CONST 0 (None) 9 RETURN_VALUE >>> def get_procedure_return_value(): ... """Returns the return value of procedure().""" ... return procedure.__code__.co_consts[0] ... >>> print(get_procedure_return_value()) None Look, there it is! From rosuav at gmail.com Thu Mar 13 20:22:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Mar 2014 11:22:43 +1100 Subject: Deep vs. shallow copy? In-Reply-To: References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 14, 2014 at 11:08 AM, Ian Kelly wrote: > On Thu, Mar 13, 2014 at 5:55 PM, Chris Angelico wrote: >> I'm going to troll for a moment and give you a function that has no >> return value. >> >> def procedure(): >> raise Exception > >>>> import dis >>>> dis.dis(procedure) > 2 0 LOAD_GLOBAL 0 (Exception) > 3 RAISE_VARARGS 1 > 6 LOAD_CONST 0 (None) > 9 RETURN_VALUE That's a return value in the same way that exec() has a return value [1]. If somehow the raise fails, it'll return None. >>>> def get_procedure_return_value(): > ... """Returns the return value of procedure().""" > ... return procedure.__code__.co_consts[0] > ... >>>> print(get_procedure_return_value()) > None > > Look, there it is! Succeeds by coincidence. From what I can see, *every* CPython function has const slot 0 dedicated to None. At least, I haven't been able to do otherwise. >>> def function(x): return x*2+1 >>> import dis >>> dis.dis(function) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (2) 6 BINARY_MULTIPLY 7 LOAD_CONST 2 (1) 10 BINARY_ADD 11 RETURN_VALUE >>> function.__code__.co_consts (None, 2, 1) Your return value retriever would say it returns None still, but it doesn't. Trollbridge: you have to pay a troll to cross. ChrisA [1] I'm not talking about Python's 'exec' statement, but about the Unix exec() API, eg execlpe() - see http://linux.die.net/man/3/exec From chris at simplistix.co.uk Thu Mar 13 20:25:45 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 14 Mar 2014 00:25:45 +0000 Subject: which async framework? In-Reply-To: References: <531E22DF.7030709@simplistix.co.uk> <531EC0E6.10402@simplistix.co.uk> Message-ID: <53224C89.5050503@simplistix.co.uk> On 11/03/2014 19:41, Terry Reedy wrote: >> I suspect I'll just end up cross-posting to the various mailing lists, > > Bad idea. Post separately if you must. > > > which I hope won't cause too much offence or kick off any flame wars. > > It would do both. Ye of little faith :-P I've been pleasantly surprised by the succinct, well reasoned and respectful replies from each of the communities! Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From python.list at tim.thechases.com Thu Mar 13 20:36:34 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 13 Mar 2014 19:36:34 -0500 Subject: which async framework? In-Reply-To: <53224C89.5050503@simplistix.co.uk> References: <531E22DF.7030709@simplistix.co.uk> <531EC0E6.10402@simplistix.co.uk> <53224C89.5050503@simplistix.co.uk> Message-ID: <20140313193634.3767ddfc@bigbox.christie.dr> On 2014-03-14 00:25, Chris Withers wrote: > I've been pleasantly surprised by the succinct, well reasoned and > respectful replies from each of the communities! As one who doesn't lurk on the other lists, is there a nice executive summary of their responses? -tkc From izecksohn at yahoo.com Thu Mar 13 18:36:39 2014 From: izecksohn at yahoo.com (Pedro Izecksohn) Date: Thu, 13 Mar 2014 15:36:39 -0700 (PDT) Subject: pickle.dump (obj, conn) Message-ID: <1394750199.11584.YahooMailNeo@web140104.mail.bf1.yahoo.com> ? Shouldn't pickle.dump (obj, conn) raise an Exception if conn is a TCP connection that was closed by the remote host? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu Mar 13 21:26:55 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 13 Mar 2014 19:26:55 -0600 Subject: pickle.dump (obj, conn) In-Reply-To: <1394750199.11584.YahooMailNeo@web140104.mail.bf1.yahoo.com> References: <1394750199.11584.YahooMailNeo@web140104.mail.bf1.yahoo.com> Message-ID: On Thu, Mar 13, 2014 at 4:36 PM, Pedro Izecksohn wrote: > Shouldn't pickle.dump (obj, conn) raise an Exception if conn is a TCP > connection that was closed by the remote host? Can you be more specific about what you are doing, what you expect the result to be, and what the actual result is? http://www.catb.org/esr/faqs/smart-questions.html#beprecise If I try using pickle.dump with a socket, I do get an exception, but perhaps not the one you are looking for: >>> pickle.dump([1,2,3], sock) Traceback (most recent call last): File "", line 1, in TypeError: file must have a 'write' attribute From steve+comp.lang.python at pearwood.info Thu Mar 13 21:41:58 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2014 01:41:58 GMT Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53225e65$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Mar 2014 10:55:44 +1100, Chris Angelico wrote: > On Fri, Mar 14, 2014 at 10:41 AM, Steven D'Aprano > wrote: >> Are you trolling again? >> >> I'm sure that you know quite well that Python doesn't have a procedure >> type. It uses a single keyword, def, for creating both functions and >> functions-that-return-None. > > I'm going to troll for a moment and give you a function that has no > return value. Heh, you're not trolling. You're just trying to be pedantic. But not pedantic enough... > def procedure(): > raise Exception This does have a return result, and it is None. It's just that the function never reaches the return, it exits early via an exception. py> from dis import dis py> dis(procedure) 2 0 LOAD_GLOBAL 0 (Exception) 3 RAISE_VARARGS 1 6 LOAD_CONST 0 (None) 9 RETURN_VALUE That *may* be able to be optimized away by a smarter compiler, or perhaps it can't be. There may be some technical reason why code objects have to end with a return no matter what: py> dis(compile("func()", "", "exec")) 1 0 LOAD_NAME 0 (func) 3 CALL_FUNCTION 0 (0 positional, 0 keyword pair) 6 POP_TOP 7 LOAD_CONST 0 (None) 10 RETURN_VALUE Or maybe it's just an optimization that nobody has bothered with since the benefit is so trivial. But either way, all callables (sub-routines) in Python are functions, i.e. in principle they could, or should, return a result, even if in practice some of them don't. There is no callable type which lacks the ability to return a result. Naturally they may not actually return a result if they never exit: def this_is_a_function(): while 1: pass return "You'll never see this!" or if they exit via an exception: def also_a_function(): if 1: raise ValueError return "You'll never see this either!" or if they just kill the running Python environment stone dead: def still_a_function(): import os os._exit(1) return "Have I beaten this dead horse enough?" > But seriously, this is something that some functions do when they need > to distinguish between returning something and not returning anything. > Look at a dictionary's subscripting (which is effectively a function > call): > >>>> x={1:2} >>>> x[1] > 2 >>>> x[3] > Traceback (most recent call last): > File "", line 1, in > x[3] > KeyError: 3 Yes, I'm aware that Python functions can raise exceptions :-) > It can't return None to indicate "there was no such key in the > dictionary", so it raises instead. There's only one way for a Python > function to not have a return value: it has to not return. Exactly my point. Functions return a value, and None is a value; procedures return, but not with a value. Python has the former, but not the later. Instead, we make do with the convention that something which is *intended* to be used as a procedure should return None to signal that, and the caller should just ignore the return result. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Thu Mar 13 21:59:05 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2014 01:59:05 GMT Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53226269$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 14 Mar 2014 11:22:43 +1100, Chris Angelico wrote: > Trollbridge: you have to pay a troll to cross. Heh :-) But seriously, there is a distinction to be made between returning from a sub-routine, and returning from a sub-routine with a return result. There may be alternative methods of exiting the sub-routine, e.g. a GOTO or COMEFROM that jumps outside of the function. Exceptions are a form of safe, limited GOTO: they can only jump out of a function, not into the middle of an arbitrary chunk of code, and they clean up the call stack when they jump. But these alternative methods are not what people consider *returning* from a sub-routine. Unless they're trolling :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Thu Mar 13 22:57:53 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 13 Mar 2014 19:57:53 -0700 (PDT) Subject: Deep vs. shallow copy? In-Reply-To: <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <738224f9-7e11-49c2-869e-381b3ca3103f@googlegroups.com> On Friday, March 14, 2014 5:11:03 AM UTC+5:30, Steven D'Aprano wrote: > On Thu, 13 Mar 2014 14:27:48 +0200, Marko Rauhamaa wrote: > > Roy Smith : > >> Steven D'Aprano wrote: > >>> Because Python doesn't have true procedures > >> What do you mean by "true procedure"? Are you just talking about > >> subroutines that don't return any value, i.e. fortran's SUBROUTINE vs. > >> FUNCTION? > > Ah, the "no true procedure" argument: > > - No true procedure returns a value. > > - That's false. Python's procedures return None. > Are you trolling again? > I'm sure that you know quite well that Python doesn't have a procedure > type. It uses a single keyword, def, for creating both functions and > functions-that-return-None. > We should all agree that functions-that-return-None are used for the same > purpose as procedures, but they are still functions, and they have a > return result, namely None. If you don't believe me, believe Python: > py> def func(): > ... return 42 > ... > py> def proc(): > ... pass > ... > py> type(func) > py> type(proc) > py> repr(proc()) > 'None' > In languages with procedures, that last line would be an error (either at > compile-time, or run-time) since a procedure wouldn't return anything to > use as argument to repr. But I'm sure that you know that. > > - They are not true procedures. > Correct. They are functions that return None, rather than a subroutine > that doesn't have any return value at all. But I'm sure you know that. I believe that you, Marko (and I) are saying exactly the same thing: Wear language-lawyer hat: Python has no procedures -- just functions which may return None Wear vanilla programmer hat: The concept (Pascal) procedure is simulated by function-returning-None From drsalists at gmail.com Thu Mar 13 23:12:41 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 13 Mar 2014 20:12:41 -0700 Subject: Balanced trees In-Reply-To: <532245fa$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <87zjkyq7nr.fsf@elektro.pacujo.net> <532245fa$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 13, 2014 at 4:57 PM, Steven D'Aprano wrote: > On Mon, 10 Mar 2014 19:34:48 +0200, Marko Rauhamaa wrote: > >>> With a high level language like Python, using the provided hash table >>> will almost always cream any hand-built tree, no matter how >>> advantageous the data is to the tree. >> >> The main thing is there are use cases where order is essential. That's >> why I have had to implement the AVL tree in Python myself. > > from collections import OrderedDict > > gives you a fast, ordered mapping. In this case, the order is that of > insertion order. If you want sort order instead, for "small" amounts of > data, say below a million or ten million items, you're likely to have > acceptable if not superior results by just sorting them items when and as > needed. This is one of my pet things. Sorting the same (slightly tweaked) data inside of a tight loop is rarely a good idea - despite the fact that the "sort" itself tends to be O(n) with Python's rather awesome builtin sorting algorithm. This is because sorting inside a loop tends to yield O(n^2) algorithms, or even O((n^2)*logn). But if you're sorting once at the end of whatever other processing, sorting is great. It's (still) O(nlogn), but it's got a terrific constant. From steve+comp.lang.python at pearwood.info Fri Mar 14 00:43:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2014 04:43:52 GMT Subject: Deep vs. shallow copy? References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> <738224f9-7e11-49c2-869e-381b3ca3103f@googlegroups.com> Message-ID: <53228908$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Mar 2014 19:57:53 -0700, Rustom Mody wrote: > I believe that you, Marko (and I) are saying exactly the same thing: I believe that you and I are saying practically the same thing. > Wear language-lawyer hat: > Python has no procedures -- just functions which may return None Almost. Functions (or methods) can return None as a regular value, e.g. the re.match and re.search functions return a MatchObject if there is a match, and None if there is not. Here, the fact the function returns None is nothing special -- it could have return 0, or -1, or "Surprise!" if the function author had wanted, the important thing is that you use it as a function. Normally you call the function for it's return result, even if that result happens to be None. On the other hand, Python also has functions/methods which you call for their side-effects, not for their return result. In Pascal, Fortran and C, for example, the language provides a special type of subroutine that can only be called for it's side-effects. It is common to call these subroutines "procedures", and Python does not have them. We only have the convention that if a function is intended to be called for it's side- effects (a procedure), it should return None. > Wear vanilla programmer hat: > The concept (Pascal) procedure is simulated by function-returning-None Yes, agreed on this one. -- Steven From steve+comp.lang.python at pearwood.info Fri Mar 14 01:02:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2014 05:02:21 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <87zjkyq7nr.fsf@elektro.pacujo.net> <532245fa$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53228d5d$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 13 Mar 2014 20:12:41 -0700, Dan Stromberg wrote: > Sorting the same (slightly tweaked) data inside of a tight loop is > rarely a good idea - despite the fact that the "sort" itself tends to be > O(n) with Python's rather awesome builtin sorting algorithm. This is > because sorting inside a loop tends to yield O(n^2) algorithms, or even > O((n^2)*logn). I agree with you except for the word "rarely". It depends on how much data you have, and in my experience most people think that N = 100 is a lot :-) Remember that Big Oh doesn't say anything about the constant of proportionality. If you have one function that behaves like O(N) but with a constant factor of 1000, and another function that behaves like O(N**2) with a constant factor of 0.001, the second, theoretically slower, function will actually be faster for N < one million. So *in practice*, a solution that involves a theoretically worse Big Oh function but a significantly lower constant factor may turn out to be better for all the values you care about. Given the difference in speed between Python's built-ins, and the code you can write yourself in pure Python, it is normally better to push as much work as you can onto the built-ins. And of course, we should not make assumptions as to what is faster and what is slower. After 15+ years, I'm still surprised about what ends up being faster in Python. > But if you're sorting once at the end of whatever other processing, > sorting is great. It's (still) O(nlogn), but it's got a terrific > constant. Exactly! -- Steven From breamoreboy at yahoo.co.uk Fri Mar 14 02:17:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 14 Mar 2014 06:17:36 +0000 Subject: Deep vs. shallow copy? In-Reply-To: References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/03/2014 00:22, Chris Angelico wrote: > > Trollbridge: you have to pay a troll to cross. > And you mustn't be afraid of the Black Night? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From dieter at handshake.de Fri Mar 14 03:27:27 2014 From: dieter at handshake.de (dieter) Date: Fri, 14 Mar 2014 08:27:27 +0100 Subject: pickle.dump (obj, conn) References: <1394750199.11584.YahooMailNeo@web140104.mail.bf1.yahoo.com> Message-ID: <87pplp6y00.fsf@handshake.de> Pedro Izecksohn writes: > ? Shouldn't pickle.dump (obj, conn) raise an Exception if conn is a TCP connection that was closed by the remote host? It is quite difficult to detect the closing of a TCP channel in a reliable way. At least, you should not trust that you are reliably informed about it. The behavior is related to output to TCP connections, not directly to "pickle". From kent at lysator.liu.se Fri Mar 14 10:10:07 2014 From: kent at lysator.liu.se (Kent =?utf-8?Q?Engstr=C3=B6m?=) Date: Fri, 14 Mar 2014 15:10:07 +0100 Subject: script uses up all memory References: Message-ID: Larry Martell writes: > I figured out what is causing this. Each pass through the loop it does: > > self.tools = Tool.objects.filter(ip__isnull=False) > > And that is what is causing the memory consumption. If I move that > outside the loop and just do that once the memory issue goes away. Now > I need to figure out why this is happening and how to prevent it as > they do want to query the db each pass through the loop in case it has > been updated. Django saves a copy of every executed SQL query if it is in debug mode (if the DEBUG setting is true). See https://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory Regards, / Kent Engstr?m, Lysator From invalid at invalid.invalid Fri Mar 14 14:53:57 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 14 Mar 2014 18:53:57 +0000 (UTC) Subject: imapclient Gmail search() times Message-ID: I'm working on a small app to help sort/organize my mail via Gmail's IMAP server, and I'm using imapclient (BTW it's a _huge_ improvement over imaplib). The odd thing I'm seeing is that when searching a large "folder" (All Mail), I get wildly different times depending on what header I search. allmail = IMAPClient(HOST, use_uid=True, ssl=True, port=993) allmail.login(USERNAME, PASSWORD) allmail.select_folder('[Gmail]/All Mail') Searching on "Message-Id:" is fast (sub-second): irt = allmail.search('HEADER Message-ID %s' % msgid) Searching on "In-Reply-To:" takes 10-15 seconds: rt = allmail.search('HEADER In-Reply-To %s' % msgid) [IIRC, I've got about 22000 messages in the 'All Mail' "folder".] I'm assuming this is just due to the way that Google implmented their IMAP server code, but I thought I'd ask if anybody else had noticed this. Perhaps I'm doing something stupid, but I can't imagine what it would be.... -- Grant Edwards grant.b.edwards Yow! I have a TINY BOWL in at my HEAD gmail.com From pmawhorter at gmail.com Fri Mar 14 14:51:14 2014 From: pmawhorter at gmail.com (Peter Mawhorter) Date: Fri, 14 Mar 2014 11:51:14 -0700 Subject: PEP/GSoC idea: built-in parser generator module for Python? Message-ID: First of all, hi everyone, I'm new to this list. I'm a grad student who's worked on and off with Python on various projects for 8ish years now. I recently wanted to construct a parser for another programing language in Python and was dissapointed that Python doesn't have a built-in module for building parsers, which seems like a common-enough task. There are plenty of different 3rd-party parsing libraries available, specialized in lots of different ways (see e.g., [1]). I happened to pick one that seemed suitable for my needs but didn't turn out to support the recursive structures that I needed to parse. Rather than pick a different one I just built my own parser generator module, and used that to build my parser: problem solved. It would have been much nicer if there were a fully-featured builtin parser generator module in Python, however, and the purpose of this email is to test the waters a bit: is this something that other people in the Python community would be interested in? I imagine the route to providing a built-in parser generator module would be to first canvass the community to figure out what third-party libraries they use, and then contact the developers of some of the top libraries to see if they'd be happy integrating as a built-in module. At that point someone would need to work to integrate the chosen third-party library as a built-in module (ideally with its developers). >From what I've looked at PyParsing and PLY seem to be standout parser generators for Python, PyParsing has a bit more Pythonic syntax from what I've seen. One important issue would be speed though: an implementation mostly written in C for low-level parsing tasks would probably be much preferrable to one written in pure Python, since a builtin module should be geared towards efficiency, but I don't actually know exactly how that would work (I've both extended and embedded Python with/in C before, but I'm not sure how that kind of project relates to writing a built-in module in C). Sorry if this is a bit rambly, but I'm interested in feedback from the community on this idea: is a builtin parser generator module desirable? If so, would integrating PyParsing as a builtin module be a good solution? What 3rd-party parsing module do you think would serve best for this purpose? -Peter Mawhorter [1] http://nedbatchelder.com/text/python-parsers.html From tjreedy at udel.edu Fri Mar 14 15:48:23 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 14 Mar 2014 15:48:23 -0400 Subject: PEP/GSoC idea: built-in parser generator module for Python? In-Reply-To: References: Message-ID: On 3/14/2014 2:51 PM, Peter Mawhorter wrote: > First of all, hi everyone, I'm new to this list. Welcome. > I'm a grad student who's worked on and off with Python on various > projects for 8ish years now. I recently wanted to construct a parser > for another programing language in Python and was dissapointed that > Python doesn't have a built-in module for building parsers, which > seems like a common-enough task. There are plenty of different > 3rd-party parsing libraries available, specialized in lots of > different ways (see e.g., [1]). I happened to pick one that seemed > suitable for my needs but didn't turn out to support the recursive > structures that I needed to parse. Rather than pick a different one I > just built my own parser generator module, and used that to build my > parser: problem solved. > > It would have been much nicer if there were a fully-featured builtin > parser generator module in Python, however, and the purpose of this > email is to test the waters a bit: is this something that other people > in the Python community would be interested in? I imagine the route to > providing a built-in parser generator module would be to first canvass > the community to figure out what third-party libraries they use, and > then contact the developers of some of the top libraries to see if > they'd be happy integrating as a built-in module. At that point > someone would need to work to integrate the chosen third-party library > as a built-in module (ideally with its developers). I think the idea has been raised before, but I am not sure which list (this one, pydev, or python-ideas). My first reaction, as a core developer, is that the stdlib is, if anything, too large. It is already not as well-maintained as we would like. My second is that parser generation is an application, not a library. A parser generator is used by running it with an input specification, not by importing it and using specific functions and classes. > From what I've looked at PyParsing and PLY seem to be standout parser > generators for Python, PyParsing has a bit more Pythonic syntax from > what I've seen. One important issue would be speed though: an > implementation mostly written in C for low-level parsing tasks would > probably be much preferrable to one written in pure Python, since a > builtin module should be geared towards efficiency, but I don't > actually know exactly how that would work (I've both extended and > embedded Python with/in C before, but I'm not sure how that kind of > project relates to writing a built-in module in C). Something written in Python can be run with any implementation of Python. Something written in C tends to be tied to CPython, > Sorry if this is a bit rambly, but I'm interested in feedback from the > community on this idea: is a builtin parser generator module > desirable? If so, would integrating PyParsing as a builtin module be a > good solution? What 3rd-party parsing module do you think would serve > best for this purpose? > [1] http://nedbatchelder.com/text/python-parsers.html Perhaps something like this should be in the wiki, if not already. -- Terry Jan Reedy From thraxodon at bitch.invalid Fri Mar 14 20:21:33 2014 From: thraxodon at bitch.invalid (THRAXODON) Date: Fri, 14 Mar 2014 20:21:33 -0400 Subject: JESUS EXPLAINED TO ME THAT HUMANS HAVE ORIGINS IN THE DEVONIAN. Message-ID: ================== >BREAKING HOGWASH! ================== > TALK.ORIGINS RECENTLY ANNOUNCED THAT HUMANS HAVE ORIGINS IN THE DEVONIAN. > THIS RECENT RECOGNITION OF THE GREATEST FACT IN EARTH'S HISTORY IS PROFOUND TO http://www.talkorigins.org/ CREDIBILITY. (Also see http://www.ediacara.org/) > DAVID IAIN GREIG, TALK.ORIGINS DICTATOR WAS RELUCTANT BUT FINALLY ANNOUNCED IN A PAPER IN http://www.sciencemag.org/ THAT THRINAXODON WAS RIGHT, AND HUMANS DO HAVE ORIGINS IN THE DEVONIAN! > =========================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# ==================================== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON REDDIT -- ---Thrinaxodon From joshua at landau.ws Fri Mar 14 21:13:13 2014 From: joshua at landau.ws (Joshua Landau) Date: Sat, 15 Mar 2014 01:13:13 +0000 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On 8 March 2014 20:37, Mark Lawrence wrote: > I've found this link useful http://kmike.ru/python-data-structures/ > > I also don't want all sorts of data structures added to the Python library. > I believe that there are advantages to leaving specialist data structures on > pypi or other sites, plus it means Python in a Nutshell can still fit in > your pocket and not a 40 ton articulated lorry, unlike the Java equivalent. The thing we really need is for the blist containers to become stdlib (but not to replace the current list implementation). The rejected PEP (http://legacy.python.org/dev/peps/pep-3128/) misses a few important points, largely in how the "log(n)" has a really large base: random.choice went from 1.2?s to 1.6?s from n=1 to n=10?, vs 1.2?s for a standard list. Further, it's worth considering a few advantages: * copy is O(1), allowing code to avoid mutation by just copying its input, which is good practice. * FIFO is effectively O(1), as the time just about doubles from n=1 to n=10? so will never actually branch that much. There is still a speed benefit of collections.deque, but it's much, much less significant. This is very useful when considering usage as a multi-purpose data structure, and removes demand for explicit linked lists (which have foolishly been reimplemented loads of times). * It reduces demand for trees: * There are efficient implementations of sortedlist, sortedset and sorteddict. * Slicing, slice assignment and slice deletion are really fast. * Addition of lists is sublinear. Instead of "list(itertools.chain(...))", one can add in a loop and end up *faster*. I think blist isn't very popular not because it isn't really good, but because it isn't a specialised structure. It is, however, almost there for almost every circumstance. This can help keep the standard library clean, especially of tree data structures. Here's what we kill: * Linked lists and doubly-linked lists, which are scarily popular for whatever reason. Sometimes people claim that collections.deque isn't powerful enough for whatever they want, and blist will almost definitely sate those cases. * Balanced trees, with blist.sortedlist. This is actually needed right now. * Poor performance in the cases where a lot of list merging and pruning happens. * Most uses of bisect. * Some instances where two data structures are used in parallel in order to keep performance fast on disparate operations (like `x in y` and `y[i]`). Now, I understand there are downsides to blist. Particularly, I've looked through the "benchmarks" and they seem untruthful. Further, we'd need a maintainer. Finally, nobody jumps at blists because they're rarely the obvious solution. Rather, they attempt to be a different general solution. Hopefully, though, a stdlib inclusion could make them a lot more obvious, and support in some current libraries could make them feel more at home. I don't know whether this is a good idea, but I do feel that it is more promising and general than having a graph in the standard library. From horse.shit at bitch.invalid Sat Mar 15 07:46:20 2014 From: horse.shit at bitch.invalid (HORSE SHIT) Date: Sat, 15 Mar 2014 07:46:20 -0400 Subject: OH MY GOD! HUMANS HAVE ORIGINS IN THE DEVONIAN! Message-ID: ================== >BREAKING HOGWASH! ================== > TALK.ORIGINS RECENTLY ANNOUNCED THAT HUMANS HAVE ORIGINS IN THE DEVONIAN. > THIS RECENT RECOGNITION OF THE GREATEST FACT IN EARTH'S HISTORY IS PROFOUND TO http://www.talkorigins.org/ CREDIBILITY. (Also see http://www.ediacara.org/) > DAVID IAIN GREIG, TALK.ORIGINS DICTATOR WAS RELUCTANT BUT FINALLY ANNOUNCED IN A PAPER IN http://www.sciencemag.org/ THAT THRINAXODON WAS RIGHT, AND HUMANS DO HAVE ORIGINS IN THE DEVONIAN! > =========================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# ==================================== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON REDDIT -- ---Thrinaxodon From breamoreboy at yahoo.co.uk Sat Mar 15 08:31:26 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 15 Mar 2014 12:31:26 +0000 Subject: blist in standard library (was Re: Balanced trees) In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On 15/03/2014 01:13, Joshua Landau wrote: > On 8 March 2014 20:37, Mark Lawrence wrote: >> I've found this link useful http://kmike.ru/python-data-structures/ >> >> I also don't want all sorts of data structures added to the Python library. >> I believe that there are advantages to leaving specialist data structures on >> pypi or other sites, plus it means Python in a Nutshell can still fit in >> your pocket and not a 40 ton articulated lorry, unlike the Java equivalent. > > The thing we really need is for the blist containers to become stdlib > (but not to replace the current list implementation). The rejected PEP > (http://legacy.python.org/dev/peps/pep-3128/) misses a few important > points, largely in how the "log(n)" has a really large base: > random.choice went from 1.2?s to 1.6?s from n=1 to n=10?, vs 1.2?s for > a standard list. > > Further, it's worth considering a few advantages: > > * copy is O(1), allowing code to avoid mutation by just copying its > input, which is good practice. > > * FIFO is effectively O(1), as the time just about doubles from n=1 to > n=10? so will never actually branch that much. There is still a speed > benefit of collections.deque, but it's much, much less significant. > This is very useful when considering usage as a multi-purpose data > structure, and removes demand for explicit linked lists (which have > foolishly been reimplemented loads of times). > > * It reduces demand for trees: > * There are efficient implementations of sortedlist, sortedset and > sorteddict. > * Slicing, slice assignment and slice deletion are really fast. > * Addition of lists is sublinear. Instead of > "list(itertools.chain(...))", one can add in a loop and end up > *faster*. > > I think blist isn't very popular not because it isn't really good, but > because it isn't a specialised structure. It is, however, almost there > for almost every circumstance. This can help keep the standard library > clean, especially of tree data structures. > > Here's what we kill: > > * Linked lists and doubly-linked lists, which are scarily popular for > whatever reason. Sometimes people claim that collections.deque isn't > powerful enough for whatever they want, and blist will almost > definitely sate those cases. > > * Balanced trees, with blist.sortedlist. This is actually needed right now. > > * Poor performance in the cases where a lot of list merging and pruning happens. > > * Most uses of bisect. > > * Some instances where two data structures are used in parallel in > order to keep performance fast on disparate operations (like `x in y` > and `y[i]`). > > Now, I understand there are downsides to blist. Particularly, I've > looked through the "benchmarks" and they seem untruthful. Further, > we'd need a maintainer. Finally, nobody jumps at blists because > they're rarely the obvious solution. Rather, they attempt to be a > different general solution. Hopefully, though, a stdlib inclusion > could make them a lot more obvious, and support in some current > libraries could make them feel more at home. > > I don't know whether this is a good idea, but I do feel that it is > more promising and general than having a graph in the standard > library. > I'd raise this on python-dev or python ideas as a result of reading PEP 3128. Specifically the second paragraph states Raymond Hettinger's sage advice:- "Depending on its success as a third-party module, it still has a chance for inclusion in the collections module. The essential criteria for that is whether it is a superior choice for some real-world use cases. I've scanned my own code and found no instances where BList would have been preferable to a regular list. However, that scan has a selection bias because it doesn't reflect what I would have written had BList been available. So, after a few months, I intend to poll comp.lang.python for BList success stories. If they exist, then I have no problem with inclusion in the collections module. After all, its learning curve is near zero -- the only cost is the clutter factor stemming from indecision about the most appropriate data structure for a given task." -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From jnkoushik at gmail.com Sat Mar 15 12:26:21 2014 From: jnkoushik at gmail.com (Jayanth Koushik) Date: Sat, 15 Mar 2014 09:26:21 -0700 (PDT) Subject: 'complex' function with string argument. Message-ID: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Hi everyone! This is regarding the inbuilt 'complex' function. The python docs say: "Note: When converting from a string, the string must not contain whitespace around the central + or - operator. For example, complex('1+2j') is fine, but complex('1 + 2j') raises ValueError." Why is this so? Why can't spaces be allowed everywhere and simply ignored? I went through the source and it did not seem like this was an internal requirement, so it seems like a design choice. Is there any reason why spaces in the middle would be a problem? Jayanth Koushik From albert at spenarnc.xs4all.nl Sat Mar 15 13:24:00 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 15 Mar 2014 17:24:00 GMT Subject: intersection, union, difference, symmetric difference for dictionaries References: Message-ID: <53248cb0$0$25075$e4fe514c@dreader37.news.xs4all.nl> In article , mauro wrote: > Dictionaries and sets share a few properties: >- Dictionaries keys are unique as well as sets items >- Dictionaries and sets are both unordered >- Dictionaries and sets are both accessed by key >- Dictionaries and sets are both mutables > >So I wonder why operations such us intersection, union, difference, >symmetric difference that are available for sets and are not available >for dictionaries without going via key dictviews. This is a plain bad idea. Dictionaries correspond to the mathematical concept of a mapping. A mapping (or a function) is a set in math, as everything is a set. It is a subset of the product set of two set A and B where there is exactly one pair for each a in A. No sane mathematician talks about unions, intersections etc. of those sets, though clearly they are well defined. OTOH there is a very rich vocabulary specific for the properties of functions. So dear mauro do as everybody does, as soon as you've invented something useful related to dicts, you'll discover that it correspond to an age old mathematical concept. It is unwise not to borrow its name. Those old geezers, Chebychov, Euler, Laplace, Fourier had their marbles in a row. It is hard to outsmart them. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From harrismh777 at gmail.com Sat Mar 15 17:24:37 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 16:24:37 -0500 Subject: test Message-ID: test From harrismh777 at gmail.com Sat Mar 15 17:38:18 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 16:38:18 -0500 Subject: Sharing: File Reader Generator with & w/o Policy Message-ID: hi folks, I am posting to share a File Reader Generator which I have been playing with, that simplifies reading of text files on-demand: like log files, config files, small record flat data-bases, &c. I have two generators to share, one with & one without "policy". The idea is to have the generator open and close the file (with error checking: try-finish block) and then maintain its state for on-demand reading either into memory (as list or dict) or for in-line processing. I will demonstrate the generators here, and then post the code following. The generator will be reading a path+filename of a local disk file and printing it as in this simple case without policy: >>> from my_utils import * >>> for record in fName(path+"my_fox"): print(record) The quick brown fox jumped over the lazy dog's tail. Now is the time for all good women to come to the aid of computer science! >>> The second generator adds "policy" to the generator processing and yields tuples, rather than strings. Each tuple contains the record number (from zero), and record length (minus the line end), and the record itself (stripped of the line end): >>> >>> for record in fnName(path+"my_fox"): print(record) (0, 26, 'The quick brown fox jumped') (1, 25, "over the lazy dog's tail.") (2, 0, '') (3, 23, 'Now is the time for all') (4, 25, 'good women to come to the') (5, 24, 'aid of computer science!') >>> >>> I will now share the source by allowing the fName(filename) utility to expose itself. Enjoy: >>> >>> for record in fName(path+"my_utils.py"): print(record) #--------------------------------------------------------- # fName(filename) generator: file reader iterable #--------------------------------------------------------- def fName(filename): try: fh = open(filename, 'r') except FileNotFoundError as err_code: print (err_code) else: while True: linein = fh.readline() if (linein!=''): yield(linein.strip('\n')) else: break fh.close() finally: None #--------------------------------------------------------- # fnName(filename) generator: file reader iterable #--------------------------------------------------------- def fnName(filename): try: fh = open(filename, 'r') except FileNotFoundError as err_code: print (err_code) else: line_count = 0 while True: linein = fh.readline() if (linein!=''): lineout = linein.strip('\n') length = len(lineout) yield((line_count, length, lineout)) line_count+=1 else: break fh.close() finally: None #--------------------------------------------------------- # {next util} #--------------------------------------------------------- >>> mark h harris From python at mrabarnett.plus.com Sat Mar 15 17:56:27 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 15 Mar 2014 21:56:27 +0000 Subject: Sharing: File Reader Generator with & w/o Policy In-Reply-To: References: Message-ID: <5324CC8B.6000206@mrabarnett.plus.com> On 2014-03-15 21:38, Mark H Harris wrote: > hi folks, I am posting to share a File Reader Generator which I have > been playing with, that simplifies reading of text files on-demand: > like log files, config files, small record flat data-bases, &c. > > I have two generators to share, one with & one without "policy". > The idea is to have the generator open and close the file (with error > checking: try-finish block) and then maintain its state for on-demand > reading either into memory (as list or dict) or for in-line processing. > > I will demonstrate the generators here, and then post the code > following. The generator will be reading a path+filename of a local disk > file and printing it as in this simple case without policy: > >>> from my_utils import * > > >>> for record in fName(path+"my_fox"): > print(record) > > The quick brown fox jumped > over the lazy dog's tail. > > Now is the time for all > good women to come to the > aid of computer science! > >>> > > The second generator adds "policy" to the generator processing and > yields tuples, rather than strings. Each tuple contains the record > number (from zero), and record length (minus the line end), and the > record itself (stripped of the line end): > >>> > >>> for record in fnName(path+"my_fox"): > print(record) > > (0, 26, 'The quick brown fox jumped') > (1, 25, "over the lazy dog's tail.") > (2, 0, '') > (3, 23, 'Now is the time for all') > (4, 25, 'good women to come to the') > (5, 24, 'aid of computer science!') > >>> > >>> > > I will now share the source by allowing the fName(filename) utility > to expose itself. Enjoy: > >>> > >>> for record in fName(path+"my_utils.py"): > print(record) > > #--------------------------------------------------------- > # fName(filename) generator: file reader iterable > #--------------------------------------------------------- > def fName(filename): > try: > fh = open(filename, 'r') > except FileNotFoundError as err_code: > print (err_code) > else: > while True: > linein = fh.readline() > if (linein!=''): > yield(linein.strip('\n')) > else: > break > fh.close() > finally: > None > I don't like how it always swallows the exception, so you can't tell whether the file doesn't exist or exists but is empty, and no way to specify the file's encoding. Why do you have the 'finally' clause with 'None' in it? Instead of None you should have 'pass', or, better yet, omit the clause entirely. You can also shorten it somewhat: def fName(filename): try: with open(filename, 'r') as fh: for linein in fh: yield linein.strip('\n') except FileNotFoundError as err_code: print(err_code) [snip] From harrismh777 at gmail.com Sat Mar 15 20:36:21 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 19:36:21 -0500 Subject: Sharing: File Reader Generator with & w/o Policy References: Message-ID: On 3/15/14 4:56 PM, MRAB wrote: > I don't like how it always swallows the exception, so you can't tell > whether the file doesn't exist or exists but is empty, and no way to > specify the file's encoding. Yes, the error handling needs more robustness/ and instead of printing the errcode, my actual model on system will log it. > > Why do you have the 'finally' clause with 'None' in it? Instead of None > you should have 'pass', or, better yet, omit the clause entirely. Its a stub-in really, and that's all at this point. The 'finally' happens regardless of whether the exception occurs, and I don't need anything there yet, just don't want to forget it. I've been playing around with wrapping generators within generators for readability and simplicity. Like this, where I'm going to wrap the fnName(filename) generator within a getnumline(filename) wrapper: >>> from my_utils import * >>> def getnumline(filename): for record in fnName(filename): yield(record) >>> line = getnumline("my_foxy") >>> >>> next(line) (0, 26, 'The quick brown fox jumped') >>> >>> next(line) (1, 25, "over the lazy dog's tail.") >>> Or this, where I put it all in memory as a dict: >>> d1={} >>> for line in getnumline("my_foxy"): d1[line[0]]=(line[1], line[2]) >>> for key in d1: print (d1[key]) (26, 'The quick brown fox jumped') (25, "over the lazy dog's tail.") (0, '') (23, 'Now is the time for all') (25, 'good women to come to the') (24, 'aid of computer science!') >>> marcus From harrismh777 at gmail.com Sat Mar 15 20:45:57 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 19:45:57 -0500 Subject: Sharing: File Reader Generator with & w/o Policy References: Message-ID: On 3/15/14 4:56 PM, MRAB wrote: > > def fName(filename): > try: > with open(filename, 'r') as fh: > for linein in fh: > yield linein.strip('\n') > except FileNotFoundError as err_code: > print(err_code) > > [snip] > The "with" confuses me because I am not sure specifically what happens in the context manager. I'm taking it for granted in this case that __exit__() closes the file? I am finding many examples of file handling using the context manager, but none so far that wrap into a generator; more often and file object. Is there a preference for file object over generator? marcus From harrismh777 at gmail.com Sat Mar 15 21:06:15 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 20:06:15 -0500 Subject: Sharing: File Reader Generator with & w/o Policy References: Message-ID: On 3/15/14 4:56 PM, MRAB wrote: > > You can also shorten it somewhat: Thanks, I like it... I shortened the fnName() also: #--------------------------------------------------------- # fn2Name(filename) generator: file reader iterable #--------------------------------------------------------- def fn2Name(filename): try: with open(filename, 'r') as fh: <=========== can you tell me line_count = 0 for linein in fh: lineout = linein.strip('\n') length = len(lineout) yield((line_count, length, lineout)) line_count+=1 except FileNotFoundError as err_code: print(err_code) #--------------------------------------------------------- ... where I can go to find out (for specific contexts) what the __init__() and __exit__() are actually doing, like for instance in this case does the filename get closed in __exit__(), and also if errors occur does the file close automatically? thanks marcus From breamoreboy at yahoo.co.uk Sat Mar 15 21:32:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 16 Mar 2014 01:32:10 +0000 Subject: Sharing: File Reader Generator with & w/o Policy In-Reply-To: References: Message-ID: On 16/03/2014 01:06, Mark H Harris wrote: > On 3/15/14 4:56 PM, MRAB wrote: > >> >> You can also shorten it somewhat: > > Thanks, I like it... I shortened the fnName() also: > > #--------------------------------------------------------- > # fn2Name(filename) generator: file reader iterable > #--------------------------------------------------------- > def fn2Name(filename): > try: > with open(filename, 'r') as fh: <=========== can you tell me > line_count = 0 > for linein in fh: > lineout = linein.strip('\n') > length = len(lineout) > yield((line_count, length, lineout)) > line_count+=1 > except FileNotFoundError as err_code: > print(err_code) > > #--------------------------------------------------------- > > > ... where I can go to find out (for specific contexts) what the > __init__() and __exit__() are actually doing, like for instance in this > case does the filename get closed in __exit__(), and also if errors > occur does the file close automatically? thanks > > marcus Start here http://docs.python.org/3/library/stdtypes.html#context-manager-types -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From travisgriggs at gmail.com Sat Mar 15 21:48:38 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Sat, 15 Mar 2014 18:48:38 -0700 Subject: test In-Reply-To: References: Message-ID: > On Mar 15, 2014, at 14:24, Mark H Harris wrote: > > test Pass From steve+comp.lang.python at pearwood.info Sat Mar 15 22:01:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2014 02:01:21 GMT Subject: Sharing: File Reader Generator with & w/o Policy References: Message-ID: <532505f0$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 15 Mar 2014 16:38:18 -0500, Mark H Harris wrote: > hi folks, I am posting to share a File Reader Generator which I have > been playing with, that simplifies reading of text files on-demand: like > log files, config files, small record flat data-bases, &c. Reading from files is already pretty simple. I would expect that it will be harder to learn the specific details of custom, specialised, file readers that *almost*, but not quite, do what you want, than to just write a couple of lines of code to do what you need when you need it. Particularly for interactive use, where robustness is less important than ease of use. > I have two generators to share, one with & one without "policy". What's "policy"? > The idea is to have the generator open and close the file (with error > checking: try-finish block) and then maintain its state for on-demand > reading either into memory (as list or dict) or for in-line processing. > > I will demonstrate the generators here, and then post the code > following. The generator will be reading a path+filename of a local disk > file and printing it as in this simple case without policy: > > >>> from my_utils import * > >>> for record in fName(path+"my_fox"): > print(record) > > The quick brown fox jumped > over the lazy dog's tail. What's "fName" mean? "File name"? That's a horribly misleading name, since it *takes* a file name as argument, it doesn't return one. That would be like renaming the len() function to "list", since it takes a list as argument. Function and class names should be descriptive, giving at least a hint as to what they do. It looks to me that this fName just iterates over the lines in a file, which makes it pretty close to just: for line in open(path + "my_fox"): print(line) > The second generator adds "policy" to the generator processing and > yields tuples, rather than strings. Each tuple contains the record > number (from zero), and record length (minus the line end), and the > record itself (stripped of the line end): I presume that "record" here means "line", rather than an actual record from a flat file with fixed-width fields, or some delimiter other than newlines. for i, line in enumerate(open(pathname + "my_fox")): print((i, len(line), line)) > >>> for record in fnName(path+"my_fox"): > print(record) What's "fnName" mean? Perhaps "filename name"? "function name"? Again, the name gives no hint as to what the function does. > def fName(filename): > try: > fh = open(filename, 'r') > except FileNotFoundError as err_code: > print (err_code) For interactive use, this is *just barely* acceptable as a (supposedly) user-friendly alternative to a stack trace. [Aside: I don't believe that insulating programmers from tracebacks does them any favours. Like the Dark Side of the Force, hiding errors is seductively attractive, but ultimately harmful, since error tracebacks are intimidating to beginners but an essential weapon in the battle against buggy code. But reading tracebacks is a skill programmers have to learn. Hiding tracebacks does them no favours, it just makes it harder for them to learn good debugging skills, and encourages them to treat errors as *something to hide* rather than *something to fix*.] But as a reusable tool for use in non-interactive code, this function fails badly. By capturing the exception, it makes it painfully difficult for the caller to have control over error-handling. You cannot let the exception propagate to some other part of the application for handling; you cannot log the exception, or ignore it, or silently swallow the exception and try another file. The fName function makes the decision for you: it will print the error to standard output (not even standard error!) no matter what you want. That's the very essence of *user- hostile* for library code. Worse, it's inconsistent! Some errors are handled normally, with an exception. It's only FileNotFoundError that is captured and printed. So if the user wants to re-use this function and do something with any exceptions, she has to use *two* forms of error handling: (1) wrap it in try...except handler to capture any exception other than FileNotFoundError; and (2) intercept writes to standard out, capture the error message, and reverse-engineer what went wrong. instead of just one. > else: > while True: > linein = fh.readline() > if (linein!=''): > yield(linein.strip('\n')) > else: > break > fh.close() Apart from stripping newlines, which is surely better left to the user (what if they need to see the newline? by stripping them automatically, the user cannot distinguish between a file which ends with a newline character and one which does not), this part is just a re-invention of the existing wheel. File objects are already iterable, and yield the lines of the file. > finally: > None The finally clause is pointless, and not even written idiomatically as a do-nothing statement ("pass"). > def fnName(filename): > try: > fh = open(filename, 'r') > except FileNotFoundError as err_code: > print (err_code) > else: > line_count = 0 > while True: > linein = fh.readline() > if (linein!=''): > lineout = linein.strip('\n') > length = len(lineout) > yield((line_count, length, lineout)) > line_count+=1 > else: > break > fh.close() > finally: > None This function re-implements the fName function, except for a simple addition. It could be written as: def fnName(filename): for count, line in enumerate(fName(filename)): yield (count, len(line), line) -- Steven D'Aprano http://import-that.dreamwidth.org/ From harrismh777 at gmail.com Sat Mar 15 22:52:47 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 21:52:47 -0500 Subject: Sharing: File Reader Generator with & w/o Policy References: Message-ID: On 3/15/14 8:32 PM, Mark Lawrence wrote: > Start here > http://docs.python.org/3/library/stdtypes.html#context-manager-types > Thanks Mark. I have three books open, and that doc, and wading through. You might like to know (as an aside) that I'm done with gg. Got back up here with a real news reader and server. All is good that way. gg has not been stable over the past three weeks, and this weekend it completely quit working. It looks like this reader|client handles the line wrapping correctly. whoohoo. marcus From python.list at tim.thechases.com Sat Mar 15 22:58:45 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 15 Mar 2014 21:58:45 -0500 Subject: Clearing out handlers in logging? Message-ID: <20140315215845.1e159acf@bigbox.christie.dr> The current (2.7; maybe 3.x?) logging module doesn't have any sort of "clear out all the current handlers" method. I can hack it by doing log = logging.getLogger() # get the root logger del log.handlers[:] # reach inside and nuke 'em log.addHandler(...) # install the one(s) I want but it feels a little dirty to reach into logging.root.handlers since there are other methods for adding/removing handlers. However, as best I can tell, to remove a handler, you already need to have it saved somewhere. Is there a better way to do this, or do I just suck it up and deal with the (potentially thread-ignorant, as it doesn't lock) hack? Thanks, -tkc From harrismh777 at gmail.com Sat Mar 15 23:34:52 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 22:34:52 -0500 Subject: Sharing: File Reader Generator with & w/o Policy References: <532505f0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/15/14 9:01 PM, Steven D'Aprano wrote: > Reading from files is already pretty simple. I would expect that it will > be harder to learn the specific details of custom, specialised, file > readers that *almost*, but not quite, do what you want, than to just > write a couple of lines of code to do what you need when you need it. > Particularly for interactive use, where robustness is less important than > ease of use. Yes. What I'm finding is that I'm coding the same 4-6 lines of code with every file open (I do want error handling, at least for FileNotFoundError) and I only want it to be two lines, read the file into a list with error handling. > What's "policy"? That's part of what I personally struggle with (frequently) is do I place the policy in the generator, or do I handle it on the outside. For instance, I normally strip the line-end and I want to know the record lengths. I also may want to know the record number from arrival sequence. This policy can be handled in the generator; although, I could have handled it outside too. > for i, line in enumerate(open(pathname + "my_fox")): > print((i, len(line), line)) I like it... and this is where I've always been, when I finally said to myself, yuk. yes, it technically works very well. But, its ugly. And I don't mean its technically ugly, I mean its aesthetically ugly and not user-easy-to-read. (I know that's all subjective) for line in getnumline(path+"my_foxy")): print(line) In this case getnumline() is a generator wrapper around fName(). It of course doesn't do anything different than the two lines you listed, but it is immediately easier to tell what is happening; even if you're not an experienced python programmer. > [Aside: I don't believe that insulating programmers from tracebacks does > them any favours. Yes. I think you're right about that. But what if they're not programmers; what if they're just application users that don't have a clue what a trace-back is, and just want to know that the file does not exist? And right away they realize that, oops, I spelled the filename wrong. Yeaah, I struggle with this as I'm trying to simplify, because personally I want to see the trace back info. > Worse, it's inconsistent! Some errors are handled normally, with an > exception. It's only FileNotFoundError that is captured and printed. So > if the user wants to re-use this function and do something with any > exceptions, she has to use *two* forms of error handling: Yes. The exception handling needs to handle all normal errors. > > (1) wrap it in try...except handler to capture any exception other > than FileNotFoundError; and > > (2) intercept writes to standard out, capture the error message, and > reverse-engineer what went wrong. Ok. > Apart from stripping newlines, which is surely better left to the user > (what if they need to see the newline? by stripping them automatically, > the user cannot distinguish between a file which ends with a newline > character and one which does not), this part is just a re-invention of > the existing wheel. File objects are already iterable, and yield the > lines of the file. Yes, this is based on my use case, which never needs the line-ends, in fact they are a pain. These files are variable record length and the only thing the newline is used for is delimiting the records. > > def fnName(filename): > for count, line in enumerate(fName(filename)): > yield (count, len(line), line) > I like this, thanks! enumerate and I are becoming friends. I like this case philosophically because it is a both | and. The policy is contained in the wrapper generator using enumerate() and len() leaving the fName() generator to produce the line. And you are right about another thing, I just want to use this thing over and over. for line in getnumline(filename): {whatever} There does seem to be just one way of doing this (file reads) but there are actually many ways of doing this. Is a file object really better than a generator, are there good reasons for using the generator, are there absolute cases for using a file object? marcus From harrismh777 at gmail.com Sat Mar 15 23:41:27 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 22:41:27 -0500 Subject: test References: Message-ID: On 3/15/14 8:48 PM, Travis Griggs wrote: > > >> On Mar 15, 2014, at 14:24, Mark H Harris wrote: >> >> test > > Pass Thanks Travis. I hated doing that. I have been having a fit with gg, and its taken just a little time to get a real news-reader client for posting. What a fit. Google does really well with some things, but gg is not one of them, IMHO. marcus From rosuav at gmail.com Sat Mar 15 23:48:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Mar 2014 14:48:36 +1100 Subject: Sharing: File Reader Generator with & w/o Policy In-Reply-To: References: <532505f0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 16, 2014 at 2:34 PM, Mark H Harris wrote: > And you are right about another thing, I just want to use this thing over > and over. > > for line in getnumline(filename): > {whatever} > > There does seem to be just one way of doing this (file reads) but there > are actually many ways of doing this. Is a file object really better than a > generator, are there good reasons for using the generator, are there > absolute cases for using a file object? I recommend you read up on the Rule of Three. Not the comedic principle - although that's worth knowing about too - but the refactoring rule. [1] As a general rule, code should be put into a function when it's been done three times the same way. It depends a bit on how similar the versions are, of course; having two places where the exact same thing is done might well be enough to refactor, and sometimes you need to see four or five places doing something only broadly similar before you can figure out what the common part is, but most of the time, three usages is the point to give it a name. There's a cost to refactoring. Suddenly there's a new primitive on the board - a new piece of language. If you can't give it a good name, that's potentially a high cost. Splitting out all sorts of things into generators when you could use well-known primitives like enumerate gets expensive fast - what's the difference between fName and fnName? I certainly wouldn't be able to call that, without actually looking them up. Let your use-cases justify your refactoring. ChrisA [1] https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming) From harrismh777 at gmail.com Sun Mar 16 00:47:30 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 15 Mar 2014 23:47:30 -0500 Subject: Sharing: File Reader Generator with & w/o Policy References: <532505f0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/15/14 10:48 PM, Chris Angelico wrote: > There's a cost to refactoring. Suddenly there's a new primitive on the > board - a new piece of language . . . Splitting out all sorts of things into > generators when you could use well-known primitives like enumerate > gets expensive fast {snip} > > > [1] https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming) Very good to remember. I am finding the temptation to make all kinds of generators (as you noted above). Its just that the python generator makes it so easy to define a function that maintains state between calls (of next() in this case) and so its also so easy to want to use them... almost forgetting about primitives! And the rule of three is one of those things that sneaks up on oneself. I have actually coded about seven (7) such cases when I discovered that they were all identical. I am noticing that folks code the same file reader cases "with open() as fh: yadda yadda" and I've noticed that they are all pretty close to the same. Wouldn't it be nice to have one simpler getline() or getnumline() name that does this one simple thing once and for all. But as simple as it is, it isn't. Well, as you say, use cases need to determine code refactoring. The other thing I'm tempted to do is to find names (even new names) that read like English closely (whatever I mean by that) so that there is no question about what is going on to a non expert. for line in getnumline(file): {whatever} Well, what if there were a project called SimplyPy, or some such, that boiled the python language down to a (Rexx like) or (BASIC like) syntax and usage so that ordinary folks could code out problems (like they did in 1964) and expert users could use it too including everything else they know about python? Would it be good? A SimplyPy coder would use constructs similar to other procedural languages (like Rexx, Pascal, even C) and without knowing the plethora of Python intrinsics could solve problems, yet not be an "expert". SimplyPy would be a structured subset of the normal language for learning and use (very small book/tutorial/ think the Rexx handbook, or the K&R). Its a long way off, and I'm just now experimenting. I'm trying to get my hands around context managers (and other things). This is an idea I got from Anthony Briggs' Hello Python! (forward SteveHolden) from Manning books. Its very small, lite weight, handles real work, but--- its still too big. I am wanting to condense it even further, providing the minimal basic core language as an end application product rather than the "expert" computer science language that will run under it. or, over it, as you like. (you think this is a nutty idea?) marcus From rosuav at gmail.com Sun Mar 16 01:41:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Mar 2014 16:41:53 +1100 Subject: Sharing: File Reader Generator with & w/o Policy In-Reply-To: References: <532505f0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 16, 2014 at 3:47 PM, Mark H Harris wrote: > On 3/15/14 10:48 PM, Chris Angelico wrote: >> >> There's a cost to refactoring. Suddenly there's a new primitive on the >> board - a new piece of language . . . Splitting out all sorts of things >> into >> >> generators when you could use well-known primitives like enumerate >> gets expensive fast {snip} >> >> >> [1] https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming) > > > Very good to remember. I am finding the temptation to make all kinds of > generators (as you noted above). Its just that the python generator makes it > so easy to define a function that maintains state between calls (of next() > in this case) and so its also so easy to want to use them... almost > forgetting about primitives! General rule of thumb: Every object in the same namespace should be readily distinguishable by name alone. And if doing that makes your names so long that the function signature is longer than the function body, it might be better to not have that as a function :) Also, I'd consider something code smell if a name is used in only one place. Maybe not so much with local variables, as there are other reasons to separate things out, but a function that gets called from only one place probably doesn't need to exist at top-level. (Of course, a published API will often seem to have unused or little-used functions, because they're being provided to the caller. They don't count.) > And the rule of three is one of those things that sneaks up on oneself. I > have actually coded about seven (7) such cases when I discovered that they > were all identical. I am noticing that folks code the same file reader cases > "with open() as fh: yadda yadda" and I've noticed that they are all pretty > close to the same. Wouldn't it be nice to have one simpler getline() or > getnumline() name that does this one simple thing once and for all. But as > simple as it is, it isn't. Well, as you say, use cases need to determine > code refactoring. If getline() is doing nothing that the primitive doesn't, and getnumline is just enumerate, then they're not achieving anything beyond shielding you from the primitives. > The other thing I'm tempted to do is to find names (even new names) that > read like English closely (whatever I mean by that) so that there is no > question about what is going on to a non expert. > > for line in getnumline(file): > {whatever} The trouble is that your idea of getnumline(file) might well differ from someone else's idea of getnumline(file). Using Python's primitives removes that confusion - if you see enumerate(file), you know exactly what it's doing, even in someone else's code. > Well, what if there were a project called SimplyPy, or some such, that > boiled the python language down to a (Rexx like) or (BASIC like) syntax and > usage so that ordinary folks could code out problems (like they did in 1964) > and expert users could use it too including everything else they know about > python? Would it be good? > > A SimplyPy coder would use constructs similar to other procedural languages > (like Rexx, Pascal, even C) and without knowing the plethora of Python > intrinsics could solve problems, yet not be an "expert". > > SimplyPy would be a structured subset of the normal language for learning > and use (very small book/tutorial/ think the Rexx handbook, or the K&R). > > Its a long way off, and I'm just now experimenting. I'm trying to get my > hands around context managers (and other things). This is an idea I got from > Anthony Briggs' Hello Python! (forward SteveHolden) from Manning books. Its > very small, lite weight, handles real work, but--- its still too big. I am > wanting to condense it even further, providing the minimal basic core > language as an end application product rather than the "expert" computer > science language that will run under it. > > or, over it, as you like. > > (you think this is a nutty idea?) To be quite frank, yes I do think it's a nutty idea. Like most nutty things, there's a kernel of something good in it, but that's not enough to build a system on :) Python is already pretty simple. The trouble with adding a layer of indirection is that you'll generally be limiting what the code can do, which is usually a bad idea for a general purpose programming language, and also forcing you to predict everything the programmer might want to do. Or you might have an "escape clause" that lets the programmer drop to "real Python"... but as soon as you allow that, you suddenly force the subsequent reader to comprehend all of Python, defeating the purpose. We had a discussion along these lines a little while ago, about designing a DSL [1] for window creation. On one side of the debate was "hey look how much cleaner the code is if I use this DSL", and on the other side was "hey look how much work you don't have to do if you just write code directly". The more cushioning between the programmer and the language, the more the cushion has to be built to handle everything the programmer might want to do. Python is a buffer between me and C. C is itself a buffer between me and assembly language. Each of them provides something that I want, but each of them has to be so extensive as to be able to handle _anything_ I might want to write. (Or, pretty much anything. Sometimes I find that a high level language lacks some little thing - recently I was yearning for a beep feature - and find that I can shell out to some external utility to do it for me.) Creating SimplyPy would put the onus on you to make it possible to write general code in it, and I think you'll find it's just not worth trying - more and more you'll want to add features from Python itself, until you achieve the inner-platform effect. [2] Note that there are times when this sort of cushioning and limiting are absolutely appropriate. Sometimes you want to limit end users to certain pieces of functionality only, and the easiest way to do it is to create a special-purpose language that is interpreted by a (say) Python script. Or maybe you want to write a dice roller that takes a specific notation like "2d8 + d6 (fire) + 2d6 (sneak attack) + 4 (STR)" [3] and interprets that appropriately. But the idea isn't to simplify general programming, then, and if you're doing that sort of thing, you still might want to consider a general-purpose language (Lua's good for that, as is JavaScript/ECMAScript). That's not what you're suggesting. ChrisA [1] Domain-specific language. I'm never sure whether to footnote these kinds of acronyms, but I want to clarify that I am not talking about a copper-based internet connection here. [2] http://thedailywtf.com/Articles/The_Inner-Platform_Effect.aspx and https://en.wikipedia.org/wiki/Inner-platform_effect [3] I actually have a dice roller that does exactly that as part of Minstrel Hall - http://minstrelhall.com/ From harrismh777 at gmail.com Sun Mar 16 02:19:52 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 16 Mar 2014 01:19:52 -0500 Subject: Sharing: File Reader Generator with & w/o Policy References: <532505f0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/16/14 12:41 AM, Chris Angelico wrote: > Good stuff Chris, and thanks for the footnotes, I appreciate it. > If getline() is doing nothing that the primitive doesn't, and > getnumline is just enumerate, then they're not achieving anything > beyond shielding you from the primitives. > Yes. getline(fn) is returning the raw line minus the newline \n. And getnumline(fn) is 1) creating a name that is easily recognizable, and 2) shielding the 'user' from the primitives; yup. > The trouble is that your idea of getnumline(file) might well differ > from someone else's idea of getnumline(file). Using Python's > primitives removes that confusion I am seeing that; esp for folks used to seeing the primitives; don't want confusion. > To be quite frank, yes I do think it's a nutty idea. Like most nutty > things, there's a kernel of something good in it, but that's not > enough to build a system on :) Thanks for your candor. I appreciate that too. Well, like I said, I'm just experimenting with the idea right now, just playing around really. In the process I'm coming more up-to-speed with python3.3 all the time. :) > > Python is already pretty simple. statement == True > > We had a discussion along these lines a little while ago, about > designing a DSL [1] for window creation. On one side of the debate was > "hey look how much cleaner the code is if I use this DSL", and on the > other side was "hey look how much work you don't have to do if you > just write code directly". Was that on python-dev, or python-ideas, or here? I'd like to read through it sometime. Well just for grins, here is the updated my_utils.py for compare with where I started tonight, ending like before with the code: >>> >>> for line in getline(path+"my_foxy"): print (line) The quick brown fox jumped over the lazy dog's tail. Now is the time for all good women to come to the aid of computer science! >>> for line in getnumline(path+"my_foxy"): print (line) (0, 26, 'The quick brown fox jumped') (1, 25, "over the lazy dog's tail.") (2, 0, '') (3, 23, 'Now is the time for all') (4, 25, 'good women to come to the') (5, 24, 'aid of computer science!') >>> for line in getline(path+"my_utils.py"): print (line) #--------------------------------------------------------- # __fOpen__(filename) generator: file open internal #--------------------------------------------------------- def __fOpen__(filename): try: with open(filename, 'r') as fh: for linein in fh: yield linein.strip('\n') except FileNotFoundError as err_code: print(err_code) # think about error handling, logging finally: pass #--------------------------------------------------------- # getnumline(filename) generator: enumerated file reader #--------------------------------------------------------- def getnumline(filename): for count, line in enumerate(__fOpen__(filename)): yield((count, len(line), line)) #--------------------------------------------------------- # getline(filename) generator: raw file reader iterable #--------------------------------------------------------- def getline(filename): for line in __fOpen__(filename): yield(line) #--------------------------------------------------------- # {next util} #--------------------------------------------------------- >>> From rosuav at gmail.com Sun Mar 16 02:37:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Mar 2014 17:37:17 +1100 Subject: Sharing: File Reader Generator with & w/o Policy In-Reply-To: References: <532505f0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 16, 2014 at 5:19 PM, Mark H Harris wrote: > On 3/16/14 12:41 AM, Chris Angelico wrote: >> To be quite frank, yes I do think it's a nutty idea. Like most nutty >> things, there's a kernel of something good in it, but that's not >> enough to build a system on :) > > > Thanks for your candor. I appreciate that too. Well, like I said, I'm > just experimenting with the idea right now, just playing around really. In > the process I'm coming more up-to-speed with python3.3 all the time. :) Good, glad you can take it the right way :) Learning is not by doing whatever you like and being told "Oh yes, very good job" like in kindergarten. Learning is by doing something (or proposing doing something) and getting solid feedback. Of course, that feedback may be wrong - your idea might be brilliant even though I believe it's a bad one - and you need to know when to stick to your guns and drive your idea forward through the hail of oncoming ... okay, this metaphor's getting a bit tangled in its own limbs... okay, the meta-metaphor is getting... alright I'm stopping now. >> We had a discussion along these lines a little while ago, about >> designing a DSL [1] for window creation. On one side of the debate was >> "hey look how much cleaner the code is if I use this DSL", and on the >> other side was "hey look how much work you don't have to do if you >> just write code directly". > > Was that on python-dev, or python-ideas, or here? I'd like to read > through it sometime. Was here on python-list: https://mail.python.org/pipermail/python-list/2014-January/664617.html https://mail.python.org/pipermail/python-list/2014-January/thread.html#664617 The thread rambled a bit, but if you like reading, there's some good content in there. You'll see some example code from my Pike MUD client, Gypsum, and Steven D'Aprano and I discuss it. If you'd rather skip most of the thread and just go to the bits I'm talking about, here's my explanation of the Pike code: https://mail.python.org/pipermail/python-list/2014-January/665286.html And here's Steven's take on it: https://mail.python.org/pipermail/python-list/2014-January/665356.html And keep reading from there. TL;DR: It's not perfect as a DSL, but it's jolly good as something that is already there and takes no effort. ChrisA From gd.usenet at spamfence.net Sun Mar 16 04:39:40 2014 From: gd.usenet at spamfence.net (Gunther Dietrich) Date: Sun, 16 Mar 2014 09:39:40 +0100 Subject: Clearing out handlers in logging? References: Message-ID: Tim Chase wrote: >The current (2.7; maybe 3.x?) logging module doesn't have any sort of >"clear out all the current handlers" method. Indeed, THERE IS a removeHandler() method. In the documentation of python 2.6, it is mentioned in '16.6.5. Logger Objects', directly after the addHandler() method. If you found the addHandler() method there, you should have found removeHandler() too. And a simple >>> dir(log) ['__doc__', '__init__', '__module__', '_log', 'addFilter', 'addHandler', 'callHandlers', 'critical', 'debug', 'disabled', 'error', 'exception', 'fatal', 'filter', 'filters', 'findCaller', 'getEffectiveLevel', 'handle', 'handlers', 'info', 'isEnabledFor', 'level', 'log', 'makeRecord', 'manager', 'name', 'parent', 'propagate', 'removeFilter', 'removeHandler', 'root', 'setLevel', 'warn', 'warning'] also would have revealed it to you. >I can hack it by doing > > log = logging.getLogger() # get the root logger > del log.handlers[:] # reach inside and nuke 'em > log.addHandler(...) # install the one(s) I want > >but it feels a little dirty to reach into logging.root.handlers since >there are other methods for adding/removing handlers. However, as >best I can tell, to remove a handler, you already need to have it >saved somewhere. What about this: >>> for handler in log.handlers: ... log.removeHandler(handler) I think, that's just one of the tasks that removeHandler() was written for. >Is there a better way to do this, or do I just suck it up and deal >with the (potentially thread-ignorant, as it doesn't lock) hack? One of the best ways would be to read the documentation. And to do some exploration, e.g. by means of dir() and help(), could also be quite instructive. This experience cannot be replaced by documentation-research requests to the Usenet. Best regards, Gunther From rosuav at gmail.com Sun Mar 16 05:02:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Mar 2014 20:02:57 +1100 Subject: Clearing out handlers in logging? In-Reply-To: References: Message-ID: On Sun, Mar 16, 2014 at 7:39 PM, Gunther Dietrich wrote: >>but it feels a little dirty to reach into logging.root.handlers since >>there are other methods for adding/removing handlers. However, as >>best I can tell, to remove a handler, you already need to have it >>saved somewhere. > > What about this: > >>>> for handler in log.handlers: > ... log.removeHandler(handler) > > I think, that's just one of the tasks that removeHandler() was written > for. I'm sure Tim was aware of the removeHandler function. But this is still reaching into log.handlers - although IMO it's safer to reach in and read than to reach in and mutate. So without the implications of Tim's inability to read docs, this is a viable suggestion. I'd prefer this over the original "del log.handlers[:]". ChrisA From __peter__ at web.de Sun Mar 16 05:18:15 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 16 Mar 2014 10:18:15 +0100 Subject: Clearing out handlers in logging? References: Message-ID: Gunther Dietrich wrote: > Tim Chase wrote: > >>The current (2.7; maybe 3.x?) logging module doesn't have any sort of >>"clear out all the current handlers" method. > > Indeed, THERE IS a removeHandler() method. In the documentation of > python 2.6, it is mentioned in '16.6.5. Logger Objects', directly after > the addHandler() method. If you found the addHandler() method there, you > should have found removeHandler() too. > > And a simple > >>>> dir(log) > ['__doc__', '__init__', '__module__', '_log', 'addFilter', 'addHandler', > 'callHandlers', 'critical', 'debug', 'disabled', 'error', 'exception', > 'fatal', 'filter', 'filters', 'findCaller', 'getEffectiveLevel', > 'handle', 'handlers', 'info', 'isEnabledFor', 'level', 'log', > 'makeRecord', 'manager', 'name', 'parent', 'propagate', 'removeFilter', > 'removeHandler', 'root', 'setLevel', 'warn', 'warning'] > > also would have revealed it to you. > > >>I can hack it by doing >> >> log = logging.getLogger() # get the root logger >> del log.handlers[:] # reach inside and nuke 'em >> log.addHandler(...) # install the one(s) I want >> >>but it feels a little dirty to reach into logging.root.handlers since >>there are other methods for adding/removing handlers. However, as >>best I can tell, to remove a handler, you already need to have it >>saved somewhere. > > What about this: > >>>> for handler in log.handlers: > ... log.removeHandler(handler) > > I think, that's just one of the tasks that removeHandler() was written > for. > > >>Is there a better way to do this, or do I just suck it up and deal >>with the (potentially thread-ignorant, as it doesn't lock) hack? > > One of the best ways would be to read the documentation. And to do some > exploration, e.g. by means of dir() and help(), could also be quite > instructive. This experience cannot be replaced by > documentation-research requests to the Usenet. Hm, what do the docs say about this one? >>> import logging >>> logging.basicConfig() >>> log = logging.getLogger("foo") >>> for i in range(5): ... log.addHandler(logging.FileHandler("tmp.log")) ... >>> assert len(log.handlers) == 5 >>> for handler in log.handlers: ... log.removeHandler(handler) ... >>> log.handlers [, ] From rosuav at gmail.com Sun Mar 16 05:35:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 16 Mar 2014 20:35:19 +1100 Subject: Clearing out handlers in logging? In-Reply-To: References: Message-ID: On Sun, Mar 16, 2014 at 8:18 PM, Peter Otten <__peter__ at web.de> wrote: > Hm, what do the docs say about this one? > >>>> import logging >>>> logging.basicConfig() >>>> log = logging.getLogger("foo") >>>> for i in range(5): > ... log.addHandler(logging.FileHandler("tmp.log")) > ... >>>> assert len(log.handlers) == 5 >>>> for handler in log.handlers: > ... log.removeHandler(handler) > ... >>>> log.handlers > [, at 0x7f8216f9eb90>] for handler in log.handlers[:]: log.removeHandler(handler) ChrisA From kwpolska at gmail.com Sun Mar 16 06:07:04 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sun, 16 Mar 2014 11:07:04 +0100 Subject: test In-Reply-To: References: Message-ID: On Sun, Mar 16, 2014 at 4:41 AM, Mark H Harris wrote: > I have been having a fit with gg, and its taken just a little time to get a > real news-reader client for posting. What a fit. Google does really well > with some things, but gg is not one of them, IMHO. Why not use the mailing list instead? It?s a much easier way to access this place. https://mail.python.org/mailman/listinfo/python-list -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From steve+comp.lang.python at pearwood.info Sun Mar 16 06:36:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2014 10:36:28 GMT Subject: Sharing: File Reader Generator with & w/o Policy References: <532505f0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53257eab$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 15 Mar 2014 23:47:30 -0500, Mark H Harris wrote: > The other thing I'm tempted to do is to find names (even new names) that > read like English closely (whatever I mean by that) so that there is no > question about what is going on to a non expert. > > for line in getnumline(file): > {whatever} I'm not an expert on your code, and I have very little idea what that is supposed to do. Judging by the name "getnumline", my first guess is that the function takes a line number n, and it will return the nth line of some source: getnumline(source, 5) => returns the 5th line from source But that's not how you use it. You pass it a "file". Is that a file object, or a file name? My guess is that it would be a file object, since if you wanted a file name you would have written getnumline(filename). Is that a file object that is open for reading or writing? I'd have to guess that it's open for reading, since you're (probably?) "getting" from the file rather than "putting". So... something like this: file = open("some thing") for line in getnumline(file): ... Presumably it iterates over the lines of the file, but what it does with the lines is hard to say. If I had to guess, I'd say... maybe it's extracting the lines that start with a line number? Something like this perhaps? def getnumline(file_object): count = 0 # Or start at 1? while True: line = file_object.readline() if line == '': break if line.startswith(str(count)): yield line count += 1 But this is only a guess, based on the assumption that while the function name is misleading, it's not *entirely* misleading. I'm puzzled why the function claims to do something with "line" singular, when you're obviously using it to iterate over lines plural. Contrast that with an example from the Python built-ins: enumerate. What you get is exactly what it says on the tin: the function is called enumerate, and enumerate is what it does: enumerate v 1: specify individually; "She enumerated the many obstacles she had encountered"; "The doctor recited the list of possible side effects of the drug" [syn: enumerate, recite, itemize, itemise] 2: determine the number or amount of; "Can you count the books on your shelf?"; "Count your change" [syn: count, number, enumerate, numerate] -- Steven D'Aprano http://import-that.dreamwidth.org/ From python.list at tim.thechases.com Sun Mar 16 08:57:59 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 16 Mar 2014 07:57:59 -0500 Subject: Clearing out handlers in logging? In-Reply-To: References: Message-ID: <20140316075759.019a0525@bigbox.christie.dr> On 2014-03-16 09:39, Gunther Dietrich wrote: > Tim Chase wrote: > > >The current (2.7; maybe 3.x?) logging module doesn't have any sort > >of "clear out all the current handlers" method. > > Indeed, THERE IS a removeHandler() method. Yes, I'm aware of it, having read the source & docs. However, the signature is removeHandler(some_handle_to_a_handler_that_you_already_have) and at the point in my code where I need to override this, basicConfig() has already assigned a default stream handler and discarded the handle/name/reference to it because the .debug/.info/.warn/.error/.critical methods of all call basicConfig() if there aren't any handlers. [Aside: which is non-pythonically, using "if len(self.handlers) == 0" instead of "if not self.handlers" in addition to the camel-case naming (which would be much harder to fix)] > >>> for handler in log.handlers: > ... log.removeHandler(handler) > > I think, that's just one of the tasks that removeHandler() was > written for. The question revolves mostly around dipping your hands into the undocumented .handlers property. I can nuke it directly (and looking at least at the 2.7 source, there doesn't seem to be much issue with doing this), or I can iterate (as modified by Chris Angelico to prevent modifying the list over which you're iterating). Either way, it still involves reaching into log.handlers which doesn't appear in any of the documentation as far as I could find. So yes, I use help() and dir() on a daily basis. But just because something is there doesn't mean I should go mucking with it in the event it's undocumented. If it *should* be trusted as a publicly available interface, it should be documented; if it shouldn't be treated publicly, then it should have a way to iterate over them such as def iterHandlers(self): for h in self.handlers[:]: yield h so you can do for h in log.iterHandlers(): log.removeHandler(h) Given how stable this code has been over the years, I'd just document the log.handlers property and possibly advise to lock around messing with it (unless "del log.handlers[:]" is atomic). -tkc From dan.h.mcinerney at gmail.com Sun Mar 16 09:24:45 2014 From: dan.h.mcinerney at gmail.com (Dan McInerney) Date: Sun, 16 Mar 2014 09:24:45 -0400 Subject: Thread is somehow interfering with a while loop called after the thread is started Message-ID: Coming back to this a long time later. I figured it out a little bit after I posted this. I wasn't aware that q.try_run() within the nfqueue module was a blocking call https://www.wzdftpd.net/redmine/projects/nfqueue-bindings/wiki/Examples. I'm not sure I was even aware of what it meant to be blocking vs nonblocking. Either way, someone from #python looked at my code and told me nfqueue is a blocking call and I should look into something like twisted. Twisted is a complex module but I spent a bunch of time looking at it and eventually had some working code implementing the absolute bare essentials as I needed them to go asynchronous. This question eventually progressed into https://github.com/DanMcInerney/LANs.py. Speaking of network concurrency, my recent project has been from a web scraper point of view and I think gevents+requests or gevents+mechanize are the way to go for that somewhat-related topic. erequests won't import due to a bug, grequests has no way to handle exceptions in the fetching of responses, treq can't find and fill out form logins (maybe with a POST, haven't explored that route), and scrapy is way too big and complex for my latest project (https://github.com/DanMcInerney/shodan_pharmer), eventlets I'm sure CAN work with libraries other than urllib2 but it implements and imports its own urllib2 and it is not a favorable time:effort ratio for me to try and implement that. -------------- next part -------------- An HTML attachment was scrubbed... URL: From laguna-mc at mail.com Sun Mar 16 09:50:15 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Sun, 16 Mar 2014 09:50:15 -0400 Subject: Installing addition libraries in Portable Python 2.7 on Windows Message-ID: <20140316135015.292040@gmx.com> I am new in Python, I have Portable Python 2.7.5.1 installed on Windows 7. I want to install additional libraries: python-magic libmagic libfuzzy pyqtgraph I downloaded package, saved on hard drive, unzipped, find setup.py and tried install via Command Prompt: Python-Portable.exe setup.py install A new DOS terminal window briefly flashes and disappears, without showing any error or installation confirmation. I assume that nothing has been installed and/or installation failed.. No tips or errors has been shown, so I don't' know how to install these packages corretcly. I tried also to install get-pip.py use same way, and again nothing happens, no any errors or results. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Mar 16 11:06:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 16 Mar 2014 15:06:28 +0000 Subject: Installing addition libraries in Portable Python 2.7 on Windows In-Reply-To: <20140316135015.292040@gmx.com> References: <20140316135015.292040@gmx.com> Message-ID: On 16/03/2014 13:50, laguna-mc at mail.com wrote: > I am new in Python, I have Portable Python 2.7.5.1 installed on Windows 7. > > I want to install additional libraries: > > python-magic > libmagic > libfuzzy > pyqtgraph > > I downloaded package, saved on hard drive, unzipped, find setup.py and > tried install via Command Prompt: > > Python-Portable.exe setup.py install > > A new DOS terminal window briefly flashes and disappears, without > showing any error or installation confirmation. > I assume that nothing has been installed and/or installation failed.. No > tips or errors has been shown, so I don't' know how to install these > packages corretcly. > I tried also to install get-pip.py use same way, and again nothing > happens, no any errors or results. > IIRC you need to obtain ez_setup.py to get easy_install and only then will get-pip.py work. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From gd.usenet at spamfence.net Sun Mar 16 14:29:46 2014 From: gd.usenet at spamfence.net (Gunther Dietrich) Date: Sun, 16 Mar 2014 19:29:46 +0100 Subject: Clearing out handlers in logging? References: Message-ID: Tim Chase wrote: >> >The current (2.7; maybe 3.x?) logging module doesn't have any sort >> >of "clear out all the current handlers" method. >> >> Indeed, THERE IS a removeHandler() method. > >Yes, I'm aware of it, having read the source & docs. However, the >signature is Sorry, your original article lacks information about what you already know/tried and what not. So it is a bit misleading and makes the impression, you would't read the documentation. It would have been helpful if you had told us your preconditions. Best regards, Gunther From contest at kivy.org Sun Mar 16 13:42:16 2014 From: contest at kivy.org (qua-non) Date: Sun, 16 Mar 2014 23:12:16 +0530 Subject: Kivy contest 2014 Message-ID: Hi folks, Kivy will be holding it's programming contest for 2014 starting April 15th. For details please visit http://kivy.org/#contest If you are interested in sponsoring the contest, please contact us at contest at kivy.org. [image: Inline image 1] -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: poster_1.png Type: image/png Size: 306444 bytes Desc: not available URL: From python.list at tim.thechases.com Sun Mar 16 14:50:26 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 16 Mar 2014 13:50:26 -0500 Subject: Clearing out handlers in logging? In-Reply-To: References: Message-ID: <20140316135026.6a5e21ef@bigbox.christie.dr> On 2014-03-16 19:29, Gunther Dietrich wrote: > >> Indeed, THERE IS a removeHandler() method. > > > >Yes, I'm aware of it, having read the source & docs. However, the > >signature is > > Sorry, your original article lacks information about what you > already know/tried and what not. So it is a bit misleading and > makes the impression, you would't read the documentation. It would > have been helpful if you had told us your preconditions. Heh, I tried to make that clear in my initial posting with the "since there are other methods for adding/removing handlers" bit. I guess I could have been more explicit though as to what I'd tried. I generally figure that, if someone knows enough to dig into the stdlib's source code, they also know enough to use dir() and help(). Not *always* the case, but a good hint that they're past the basics. But I could have clarified my question more along the lines of "Should log.handlers be public/documented; should Logger grow clearHandlers() and iterHandlers() methods; or should I wantonly use log.handlers but then just get to keep both pieces if/when it breaks?" -tkc From laguna-mc at mail.com Sun Mar 16 16:31:18 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Sun, 16 Mar 2014 16:31:18 -0400 Subject: Installing addition libraries in Portable Python 2.7 on Windows Message-ID: <20140316203119.292070@gmx.com> It'slike a chain, eachnew modulepulls afew othermodules.I can postpone get-pip.py onthe very last stage, now I want to install python-magic, libmagic, libfuzzy, pyqtgraph. How to do this? ----- Original Message ----- From: Mark Lawrence Sent: 03/16/14 05:06 PM To: python-list at python.org Subject: Re: Installing addition libraries in Portable Python 2.7 on Windows On 16/03/2014 13:50, laguna-mc at mail.com wrote: > I am new in Python, I have Portable Python 2.7.5.1 installed on Windows 7. > > I want to install additional libraries: > > python-magic > libmagic > libfuzzy > pyqtgraph > > I downloaded package, saved on hard drive, unzipped, find setup.py and > tried install via Command Prompt: > > Python-Portable.exe setup.py install > > A new DOS terminal window briefly flashes and disappears, without > showing any error or installation confirmation. > I assume that nothing has been installed and/or installation failed.. No > tips or errors has been shown, so I don't' know how to install these > packages corretcly. > I tried also to install get-pip.py use same way, and again nothing > happens, no any errors or results. > IIRC you need to obtain ez_setup.py to get easy_install and only then will get-pip.py work. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From laguna-mc at mail.com Sun Mar 16 21:20:54 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Sun, 16 Mar 2014 21:20:54 -0400 Subject: Error when installing matplotlib-1.3. on Windows Message-ID: <20140317012054.292060@gmx.com> I'm trying to install matplotlib from locally stored source archive file (Portable Python 2.7 on Windows): pip install E:\matplotlib-1.3.1.win32-py2.7.exe Got error, below is log: E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 03:10:16 Exception: Traceback (most recent call last): File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main status = self.run(options, args) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run InstallRequirement.from_line(name, None)) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line 172, in from_line return cls(req, comes_from, url=url, prereleases=prereleases) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line 70, in __init__ req = pkg_resources.Requirement.parse(req) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, in parse reqs = list(parse_requirements(s)) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, in parse_requirements line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec") File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, in scan_list raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) ValueError: ('Expected version spec in', 'E:\\matplotlib-1.3.1.win32-py2.7.exe', 'at', ':\\matplotlib-1.3.1.win32-py2.7.exe') What is the problem and how to solve it? -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Mar 16 21:55:39 2014 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 17 Mar 2014 01:55:39 +0000 Subject: Error when installing matplotlib-1.3. on Windows In-Reply-To: <20140317012054.292060@gmx.com> References: <20140317012054.292060@gmx.com> Message-ID: <5326561B.3070006@mrabarnett.plus.com> On 2014-03-17 01:20, laguna-mc at mail.com wrote: > I'm trying to install matplotlib from locally stored source archive file > (Portable Python 2.7 on Windows): > > pip install E:\matplotlib-1.3.1.win32-py2.7.exe > > Got error, below is log: > > > E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 03:10:16 > Exception: > Traceback (most recent call last): > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main > status = self.run(options, args) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run > InstallRequirement.from_line(name, None)) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", > line 172, in from_line > return cls(req, comes_from, url=url, prereleases=prereleases) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", > line 70, in __init__ > req = pkg_resources.Requirement.parse(req) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, > in parse > reqs = list(parse_requirements(s)) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, > in parse_requirements > line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version > spec") > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, > in scan_list > raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) > ValueError: ('Expected version spec in', > 'E:\\matplotlib-1.3.1.win32-py2.7.exe', 'at', > ':\\matplotlib-1.3.1.win32-py2.7.exe') > > > What is the problem and how to solve it? > Judging by the name, I'd say that "matplotlib-1.3.1.win32-py2.7.exe" is an installer, so you just need to run it. From jobmattcon at gmail.com Sun Mar 16 23:54:35 2014 From: jobmattcon at gmail.com (jobmattcon at gmail.com) Date: Sun, 16 Mar 2014 20:54:35 -0700 (PDT) Subject: File "build\bdist.win32\egg\redis\client.py", line 705, in get Message-ID: <249e4d57-3619-4b07-ae52-e083bcbd48af@googlegroups.com> in win32 with redis-py and redis for window Traceback (most recent call last): File "testredis.py", line 21, in matrixlist = r_server.get("matrix1") File "build\bdist.win32\egg\redis\client.py", line 705, in get File "build\bdist.win32\egg\redis\client.py", line 461, in execute_command File "build\bdist.win32\egg\redis\client.py", line 471, in parse_response File "build\bdist.win32\egg\redis\connection.py", line 349, in read_response redis.exceptions.ResponseError: Operation against a key holding the wrong kind o f value import redis from sympy import * from sympy import Matrix from sympy.abc import x, y, z, f, a, b from sympy import * r_server = redis.Redis("localhost") f = Symbol('f') x = Symbol('x') y = Symbol('y') z = Symbol('z') varlist = [x,y,z,a,b] A = Matrix([[1,0],[0,1]]) B = Matrix([[2,0],[0,5]]) r_server.sadd("matrix1", A) r_server.sadd("matrix1", B) matrixlist = r_server.get("matrix1") From jobmattcon at gmail.com Mon Mar 17 01:02:56 2014 From: jobmattcon at gmail.com (jobmattcon at gmail.com) Date: Sun, 16 Mar 2014 22:02:56 -0700 (PDT) Subject: pkg_resources.DistributionNotFound: hiredis Message-ID: http://heynemann.github.io/r3/ C:\heynemann-r3-cc6b4eb\build\lib\r3\app>r3-app --red is-port=6379 --redis-pass=r3 -c config.py Traceback (most recent call last): File "C:\Python27\Scripts\r3-app-script.py", line 5, in from pkg_resources import load_entry_point File "C:\Python27\lib\site-packages\pkg_resources.py", line 2709, in working_set.require(__requires__) File "C:\Python27\lib\site-packages\pkg_resources.py", line 664, in require needed = self.resolve(parse_requirements(requirements)) File "C:\Python27\lib\site-packages\pkg_resources.py", line 567, in resolve raise DistributionNotFound(req) pkg_resources.DistributionNotFound: hiredis [5700] 17 Mar 11:31:43.819 # Warning: no config file specified, using the defaul t config. In order to specify a config file use C:\Users\martin.lee\Downloads\re dis-2.6\bin\release\redis-server.exe /path/to/redis.conf [5700] 17 Mar 11:31:43.828 # Warning: 32 bit instance detected but no memory lim it set. Setting 3 GB maxmemory limit with 'noeviction' policy now. _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.6.12 (00000000/0) 32 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 5700 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [5700] 17 Mar 11:31:43.829 # Server started, Redis version 2.6.12 [5700] 17 Mar 11:31:43.829 * The server is now ready to accept connections on po From ben+python at benfinney.id.au Mon Mar 17 01:09:32 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 17 Mar 2014 16:09:32 +1100 Subject: pkg_resources.DistributionNotFound: hiredis References: Message-ID: <85txaxpg1f.fsf@benfinney.id.au> jobmattcon at gmail.com writes: > [a dump of text terminal output] Did you have something to say about this? Perhaps a question, with details of what you're expecting and what happened instead? -- \ ?Men never do evil so completely and cheerfully as when they do | `\ it from religious conviction.? ?Blaise Pascal (1623?1662), | _o__) Pens?es, #894. | Ben Finney From jobmattcon at gmail.com Mon Mar 17 01:35:54 2014 From: jobmattcon at gmail.com (jobmattcon at gmail.com) Date: Sun, 16 Mar 2014 22:35:54 -0700 (PDT) Subject: pkg_resources.DistributionNotFound: hiredis In-Reply-To: References: Message-ID: <1e8a6c87-d635-4d3c-944f-8bb7f0d7458e@googlegroups.com> first time run command to start r3, it has already got error r3-app --redis-port=6379 --redis-pass=r3 -c config.py On Monday, March 17, 2014 1:09:32 PM UTC+8, Ben Finney wrote: > writes: > > > > > [a dump of text terminal output] > > > > Did you have something to say about this? Perhaps a question, with > > details of what you're expecting and what happened instead? > > > > -- > > \ "Men never do evil so completely and cheerfully as when they do | > > `\ it from religious conviction." --Blaise Pascal (1623-1662), | > > _o__) Pens?es, #894. | > > Ben Finney From ben+python at benfinney.id.au Mon Mar 17 02:04:06 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 17 Mar 2014 17:04:06 +1100 Subject: pkg_resources.DistributionNotFound: hiredis References: <1e8a6c87-d635-4d3c-944f-8bb7f0d7458e@googlegroups.com> Message-ID: <85ppllpdih.fsf@benfinney.id.au> jobmattcon at gmail.com writes: > first time run command to start r3, it has already got error > r3-app --redis-port=6379 --redis-pass=r3 -c config.py First: please don't top-post; Instead, use the normal interleaved posting style to make it easier to follow the conversation . Second: I don't have any idea what you're referring to, and your messages give no explanation. Is this a question about Python, or some specific tool, or some library, or what? What are you trying to do (and please say it in terms that means we can try to reproduce the problem), and what are you seeing instead, and how does that differ from what you expect? -- \ ?The best is the enemy of the good.? ?Voltaire, _Dictionnaire | `\ Philosophique_ | _o__) | Ben Finney From jobmattcon at gmail.com Mon Mar 17 02:10:29 2014 From: jobmattcon at gmail.com (jobmattcon at gmail.com) Date: Sun, 16 Mar 2014 23:10:29 -0700 (PDT) Subject: pkg_resources.DistributionNotFound: hiredis In-Reply-To: References: <1e8a6c87-d635-4d3c-944f-8bb7f0d7458e@googlegroups.com> Message-ID: this is a specific tool related with python http://heynemann.github.io/r3/ i am trying to do a simple example like the diagram in the web page describe and then use with sympy to massive generate functions and plot and print into a directory On Monday, March 17, 2014 2:04:06 PM UTC+8, Ben Finney wrote: > writes: > > > > > first time run command to start r3, it has already got error > > > r3-app --redis-port=6379 --redis-pass=r3 -c config.py > > > > First: please don't top-post; Instead, use the normal interleaved > > posting style to make it easier to follow the conversation > > . > > > > Second: I don't have any idea what you're referring to, and your > > messages give no explanation. Is this a question about Python, or some > > specific tool, or some library, or what? > > > > What are you trying to do (and please say it in terms that means we can > > try to reproduce the problem), and what are you seeing instead, and how > > does that differ from what you expect? > > > > -- > > \ "The best is the enemy of the good." --Voltaire, _Dictionnaire | > > `\ Philosophique_ | > > _o__) | > > Ben Finney From larry at hastings.org Mon Mar 17 02:29:55 2014 From: larry at hastings.org (Larry Hastings) Date: Sun, 16 Mar 2014 23:29:55 -0700 Subject: [RELEASED] Python 3.4.0 Message-ID: <53269663.9050408@hastings.org> On behalf of the Python development team, I'm thrilled to announce the official release of Python 3.4. Python 3.4 includes a range of improvements of the 3.x series, including hundreds of small improvements and bug fixes. Major new features and changes in the 3.4 release series include: * PEP 428, a "pathlib" module providing object-oriented filesystem paths * PEP 435, a standardized "enum" module * PEP 436, a build enhancement that will help generate introspection information for builtins * PEP 442, improved semantics for object finalization * PEP 443, adding single-dispatch generic functions to the standard library * PEP 445, a new C API for implementing custom memory allocators * PEP 446, changing file descriptors to not be inherited by default in subprocesses * PEP 450, a new "statistics" module * PEP 451, standardizing module metadata for Python's module import system * PEP 453, a bundled installer for the *pip* package manager * PEP 454, a new "tracemalloc" module for tracing Python memory allocations * PEP 456, a new hash algorithm for Python strings and binary data * PEP 3154, a new and improved protocol for pickled objects * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O To download Python 3.4.0 visit: http://www.python.org/download/releases/3.4.0/ This is a production release. Please report any issues you notice to: http://bugs.python.org/ Enjoy! -- Larry Hastings, Release Manager larry at hastings.org (on behalf of the entire python-dev team and 3.4's contributors) From rosuav at gmail.com Mon Mar 17 02:46:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 17 Mar 2014 17:46:29 +1100 Subject: pkg_resources.DistributionNotFound: hiredis In-Reply-To: References: <1e8a6c87-d635-4d3c-944f-8bb7f0d7458e@googlegroups.com> Message-ID: On Mon, Mar 17, 2014 at 5:10 PM, wrote: > this is a specific tool related with python > > http://heynemann.github.io/r3/ > > i am trying to do a simple example like the diagram in the web page > describe and then use with sympy to massive generate functions and plot and print into a directory 1) You've already been asked not to top-post. Please, read the Wikipedia page Ben linked you to. 2) If you put no effort into your question, why should we put effort into the answer? 3) You're asking about a particular program. Unless you can show that the problem you're having is specific to Python, you'll probably do better to ask the author of that program. Look around and see if s/he has a recommended means of getting assistance - maybe a mailing list. 4) You still haven't explained your problem at all. While we might be flattered at the implication that our skills are so great that we're psychic, we're more likely to be frustrated by the utter lack of information. Please read this: http://www.catb.org/~esr/faqs/smart-questions.html ChrisA From sontek at gmail.com Mon Mar 17 03:27:56 2014 From: sontek at gmail.com (sontek at gmail.com) Date: Mon, 17 Mar 2014 00:27:56 -0700 (PDT) Subject: asyncio libraries? Message-ID: <55cac1b6-5aaa-43c8-9840-a7b576f5efed@googlegroups.com> I'm a little late to the party, but now that Python 3.4 is out and asyncio is ready for use I started reading things like: https://glyph.twistedmatrix.com/2014/02/unyielding.html Which explains why the asyncio approach is the future and all the bullet points in that article make a lot of sense. But my question now is if Python core developers are going to be releasing libraries to help working with things like databases, http requests, etc and all the reasons you may want asyncio? Currently gevent is what I use most often because most libraries I use these days are already "greened" and I think asyncio needs something similar. Either extensions to popular things like psycopg2, pylibmc (or any memcached library), and urllib3 for example. I've seen libraries like this: https://github.com/fafhrd91/psycotulip popping up but I would love to see some "blessed" libraries or even more documentation for common use cases and how someone could move to asyncio. What about webservers? Are there any decent webservers being built on top of asyncio instead of gevent, twisted, or tornado? Thanks, John From steve at pearwood.info Mon Mar 17 03:47:53 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 17 Mar 2014 07:47:53 GMT Subject: pkg_resources.DistributionNotFound: hiredis References: <1e8a6c87-d635-4d3c-944f-8bb7f0d7458e@googlegroups.com> Message-ID: <5326a8a8$0$2923$c3e8da3$76491128@news.astraweb.com> On Sun, 16 Mar 2014 23:10:29 -0700, jobmattcon wrote: > this is a specific tool related with python > > http://heynemann.github.io/r3/ > > i am trying to do a simple example like the diagram in the web page > describe and then use with sympy to massive generate functions and plot > and print into a directory I'm afraid that unless you can identify where the problem lies, we probably won't be able to help you. I've used sympy, but I haven't used r3 or redis. Can you confirm: - is redis is working outside of Python? - can you get sympy working without r3? - have you installed r3 successfully? how do you know? - can you demonstrate the SIMPLEST possible piece of code that shows the failure? Reading this website may help. Although it is written for Java, the same principles apply to Python: http://www.sscce.org/ Good luck! And by the way, although most of us will try to be tolerant towards minor breaches of etiquette, we do prefer interleaved posting like this: > Question blah blah? Answer. > Another question? Further answers. rather than top posting: Answer. Further answers. > Question blah blah blah? > Another question? See here for more details: http://en.wikipedia.org/wiki/Posting_style Thanks in advance, -- Steven From list at qtrac.plus.com Mon Mar 17 04:44:23 2014 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 17 Mar 2014 01:44:23 -0700 (PDT) Subject: Correct idiom for determining path when frozen in 3.4 Message-ID: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> Hi, What is the correct idiom for getting the path to a top-level module in 3.3 and 3.4 when the module might be frozen? At the moment I'm using this: if getattr(sys, "frozen", False): path = os.path.dirname(sys.executable) else: path = os.path.dirname(__file__) Thanks! From troll at bitch.invalid Mon Mar 17 04:50:19 2014 From: troll at bitch.invalid (ASSODON) Date: Mon, 17 Mar 2014 04:50:19 -0400 Subject: HOLY SH*T! HUMANS ORIGINATED IN THE DEVONIAN Message-ID: ======================= >BREAKING NEWSSSSSSSSS ======================= > RICHARD LEAKEY JUST DIED DUE TO HEART FAILURE! > THE REASONS DESCRIBED BY THE MEDICAL TEAM IS THAT HIS WORK WAS DISPROVEN, BY NONE OTHER THAN YOUR OWN BASTARD, THRINAXODON. > THIS CAUSED LEAKEY'S HEART TO EXPLODE! > THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000! > TO WASTE YOUR TIME EVEN FURTHER, CHECK OUT THESE LINKS BELOW. =========================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa d/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa d/3aad75c16afb0b82# ==================================== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON REDDIT From ben+python at benfinney.id.au Mon Mar 17 05:02:15 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 17 Mar 2014 20:02:15 +1100 Subject: Correct idiom for determining path when frozen in 3.4 References: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> Message-ID: <85ha6xp59k.fsf@benfinney.id.au> Mark Summerfield writes: > What is the correct idiom for getting the path to a top-level module I'm not sure I understand what this concept is. What do you mean by ?top-level module?? > in 3.3 and 3.4 when the module might be frozen? > > At the moment I'm using this: > > if getattr(sys, "frozen", False): > path = os.path.dirname(sys.executable) > else: > path = os.path.dirname(__file__) That looks okay. Does it work? The code is readable and Pythonic as is. But I would suggest several improvements:: if getattr(sys, "frozen"): # ?getattr? will return None by default Also, why test for ?sys.frozen? when you're about to use ?sys.executable?? if getattr(sys, "executable"): Lastly, it's slightly more Pythonic to execute the normal path unconditionally, and let it raise an exception if there's a problem:: try: executable = sys.executable except AttributeError: executable = __file__ path = os.path.dirname(executable) -- \ ?It is far better to grasp the universe as it really is than to | `\ persist in delusion, however satisfying and reassuring.? ?Carl | _o__) Sagan | Ben Finney From jeanpierreda at gmail.com Mon Mar 17 05:16:47 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 17 Mar 2014 02:16:47 -0700 Subject: Correct idiom for determining path when frozen in 3.4 In-Reply-To: <85ha6xp59k.fsf@benfinney.id.au> References: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> <85ha6xp59k.fsf@benfinney.id.au> Message-ID: On Mon, Mar 17, 2014 at 2:02 AM, Ben Finney wrote: > Mark Summerfield writes: > if getattr(sys, "frozen"): # ?getattr? will return None by default No it won't. > Lastly, it's slightly more Pythonic to execute the normal path > unconditionally, and let it raise an exception if there's a problem:: > > try: > executable = sys.executable > except AttributeError: > executable = __file__ > path = os.path.dirname(executable) Sure, but sys.executable always exists. sys.frozen doesn't, and the existence or nonexistence is apparently meaningful; so your code does something different than the original problem statement. Also, if that weren't the case, I'd really replace that try-except with getattr(sys, 'executable', __file__) -- Devin From ben+python at benfinney.id.au Mon Mar 17 05:23:59 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 17 Mar 2014 20:23:59 +1100 Subject: Correct idiom for determining path when frozen in 3.4 References: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> <85ha6xp59k.fsf@benfinney.id.au> Message-ID: <85d2hlp49c.fsf@benfinney.id.au> Devin Jeanpierre writes: > On Mon, Mar 17, 2014 at 2:02 AM, Ben Finney wrote: > > Mark Summerfield writes: > > if getattr(sys, "frozen"): # ?getattr? will return None by default > > No it won't. > [?] > Sure, but sys.executable always exists. My apologies for posting untested code without making that clear. Thanks to Devin for picking up my mistakes. > > Lastly, it's slightly more Pythonic to execute the normal path > > unconditionally, and let it raise an exception if there's a problem:: > > > > try: > > executable = sys.executable > > except AttributeError: > > executable = __file__ > > path = os.path.dirname(executable) > sys.frozen doesn't [necessarily exist], and the existence or > nonexistence is apparently meaningful; so your code does something > different than the original problem statement. Right. I didn't understand why ?__file__? is a suitable substitute for ?sys.executable?; they're always (?) different values. So that probably is what led to the confusion in the code behaviour. I hope the Pythonic idioms are helpful to the original poster nevertheless. -- \ ?Anyone who believes exponential growth can go on forever in a | `\ finite world is either a madman or an economist.? ?Kenneth | _o__) Boulding | Ben Finney From oscar.j.benjamin at gmail.com Mon Mar 17 05:52:55 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 17 Mar 2014 09:52:55 +0000 Subject: Correct idiom for determining path when frozen in 3.4 In-Reply-To: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> References: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> Message-ID: On 17 March 2014 08:44, Mark Summerfield wrote: > Hi, > > What is the correct idiom for getting the path to a top-level module in 3.3 and 3.4 when the module might be frozen? > > At the moment I'm using this: > > if getattr(sys, "frozen", False): > path = os.path.dirname(sys.executable) > else: > path = os.path.dirname(__file__) Why do you want to know this? Does pkgutil.get_data do what you want? http://docs.python.org/3.3/library/pkgutil.html#pkgutil.get_data Oscar From laguna-mc at mail.com Mon Mar 17 07:29:10 2014 From: laguna-mc at mail.com (Andrew Williams) Date: Mon, 17 Mar 2014 07:29:10 -0400 Subject: Error when installing matplotlib-1.3. on Windows Message-ID: <20140317112910.64790@gmx.com> Note that I have Portable Python, installed on USB flash drive. When I tried run matplotlib installer, I got error:'Cannot install': "Python version 2.7 required, which was not found in the registry" ----- Original Message ----- From: MRAB Sent: 03/17/14 03:55 AM To: python-list at python.org Subject: Re: Error when installing matplotlib-1.3. on Windows On 2014-03-17 01:20, laguna-mc at mail.com wrote: > I'm trying to install matplotlib from locally stored source archive file > (Portable Python 2.7 on Windows): > > pip install E:\matplotlib-1.3.1.win32-py2.7.exe > > Got error, below is log: > > > E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 03:10:16 > Exception: > Traceback (most recent call last): > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main > status = self.run(options, args) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run > InstallRequirement.from_line(name, None)) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", > line 172, in from_line > return cls(req, comes_from, url=url, prereleases=prereleases) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", > line 70, in __init__ > req = pkg_resources.Requirement.parse(req) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, > in parse > reqs = list(parse_requirements(s)) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, > in parse_requirements > line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version > spec") > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, > in scan_list > raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) > ValueError: ('Expected version spec in', > 'E:\\matplotlib-1.3.1.win32-py2.7.exe', 'at', > ':\\matplotlib-1.3.1.win32-py2.7.exe') > > > What is the problem and how to solve it? > Judging by the name, I'd say that "matplotlib-1.3.1.win32-py2.7.exe" is an installer, so you just need to run it. -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at chagford.com Mon Mar 17 09:06:33 2014 From: frank at chagford.com (Frank Millman) Date: Mon, 17 Mar 2014 15:06:33 +0200 Subject: Question about Source Control Message-ID: Hi all I know I *should* be using a Source Control Management system, but at present I am not. I tried to set up Mercurial a couple of years ago, but I think I set it up wrongly, as I got myself confused and found it more of a hindrance than a help. Now I am ready to try again, but I want to avoid my earlier mistakes. I understand the concept, and I understand the importance, so I do not need reminding of those. What I would like help with is the basic setup. I could subscribe to the Mercurial mailing list and ask there, but I am hoping for a kick-start here. Here is my setup. All my source code resides on an old Linux server, which I switch on in the morning and switch off at night, but otherwise hardly ever look at. It uses 'samba' to allow sharing with Windows, and 'nfs' to allow sharing with other Linux machines. I need to test my program on Windows and on Linux, so I run it from both at various times. On Windows I have a 'mapped drive' pointing to the source code. On Linux I use a third machine, running a recent Fedora, using nfs to mount a directory pointing to the source code. Obviously each machine has its own version of Python installed. I do my development on the Windows machine. I use TextPad, a simple text editor, which works fine for my purposes. It uses the mapped drive to point to the source code. So where should I install the SCM, and how should I set it up so that I can access the latest version from any machine? Any hints will be appreciated. Frank Millman From andriy.kornatskyy at live.com Mon Mar 17 09:25:30 2014 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Mon, 17 Mar 2014 15:25:30 +0200 Subject: Question about Source Control In-Reply-To: References: Message-ID: Frank, I would suggest start with an account on https://bitbucket.org. It supports private repositories so you should be good there. From other hand you can setup own infrastructure for SCM, read more here: http://mindref.blogspot.com/2013/10/how-to-manage-git-or-mercurial.html Thanks. Andriy Kornatskyy On Mar 17, 2014, at 3:06 PM, Frank Millman wrote: > Hi all > > I know I *should* be using a Source Control Management system, but at > present I am not. I tried to set up Mercurial a couple of years ago, but I > think I set it up wrongly, as I got myself confused and found it more of a > hindrance than a help. Now I am ready to try again, but I want to avoid my > earlier mistakes. > > I understand the concept, and I understand the importance, so I do not need > reminding of those. What I would like help with is the basic setup. I could > subscribe to the Mercurial mailing list and ask there, but I am hoping for a > kick-start here. Here is my setup. > > All my source code resides on an old Linux server, which I switch on in the > morning and switch off at night, but otherwise hardly ever look at. It uses > 'samba' to allow sharing with Windows, and 'nfs' to allow sharing with other > Linux machines. > > I need to test my program on Windows and on Linux, so I run it from both at > various times. On Windows I have a 'mapped drive' pointing to the source > code. On Linux I use a third machine, running a recent Fedora, using nfs to > mount a directory pointing to the source code. Obviously each machine has > its own version of Python installed. > > I do my development on the Windows machine. I use TextPad, a simple text > editor, which works fine for my purposes. It uses the mapped drive to point > to the source code. > > So where should I install the SCM, and how should I set it up so that I can > access the latest version from any machine? > > Any hints will be appreciated. > > Frank Millman > > > > -- > https://mail.python.org/mailman/listinfo/python-list From jprashanthan at gmail.com Mon Mar 17 03:06:42 2014 From: jprashanthan at gmail.com (J Prashanthan) Date: Mon, 17 Mar 2014 12:36:42 +0530 Subject: No subject Message-ID: i am doing my masters currently and im stuck up with my final project. As i was interested in learning a new language i opted to do my final project in python. im currently working on building an unit tester for multithreaded code. Due to various reasons i got stuck with my project. basically my lack of knowledge in python and i have none to help me with it. i have no idea what to do with my project . and my deadline is in another 1 week . I have completed working on the atomicity violation finder . Finding Atomicity-Violation Bugs through Unserializable Interleaving Testing by Shan Lu, Soyeon Park, and Yuanyuan Zhou, Member, IEEE. This is my base paper . can anyone please help me with it. if anyone has a working code please mail me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Mon Mar 17 10:08:13 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 17 Mar 2014 09:08:13 -0500 Subject: Looking for someone who can build a 64-bit version of SpamBayes installer for Windows In-Reply-To: References: Message-ID: > .... As more and > more Windows users have moved to 64-bit versions of Windows and > Outlook, we've had more and more reports of failures. > > I think all that's necessary (speaking as someone who knows nothing > about Windows) is for someone to build a 64-bit version of the > SpamBayes installer for Windows.... > > Anybody available to help? Still looking for someone to help building a 64-bit installer for SpamBayes on Windows. Anyone? Any idea where else to plead for help? Skip From breamoreboy at yahoo.co.uk Mon Mar 17 10:39:09 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 17 Mar 2014 14:39:09 +0000 Subject: Looking for someone who can build a 64-bit version of SpamBayes installer for Windows In-Reply-To: References: Message-ID: On 17/03/2014 14:08, Skip Montanaro wrote: >> .... As more and >> more Windows users have moved to 64-bit versions of Windows and >> Outlook, we've had more and more reports of failures. >> >> I think all that's necessary (speaking as someone who knows nothing >> about Windows) is for someone to build a 64-bit version of the >> SpamBayes installer for Windows.... >> >> Anybody available to help? > > Still looking for someone to help building a 64-bit installer for > SpamBayes on Windows. Anyone? Any idea where else to plead for help? > > Skip > https://mail.python.org/mailman/listinfo/python-win32 which is gated to gmane.comp.python.windows -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Mon Mar 17 10:53:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 01:53:44 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: On Tue, Mar 18, 2014 at 12:06 AM, Frank Millman wrote: > All my source code resides on an old Linux server, which I switch on in the > morning and switch off at night, but otherwise hardly ever look at. It uses > 'samba' to allow sharing with Windows, and 'nfs' to allow sharing with other > Linux machines. > > I need to test my program on Windows and on Linux, so I run it from both at > various times. On Windows I have a 'mapped drive' pointing to the source > code. On Linux I use a third machine, running a recent Fedora, using nfs to > mount a directory pointing to the source code. Obviously each machine has > its own version of Python installed. > > I do my development on the Windows machine. I use TextPad, a simple text > editor, which works fine for my purposes. It uses the mapped drive to point > to the source code. > > So where should I install the SCM, and how should I set it up so that I can > access the latest version from any machine? First off: You can save yourself a huge amount of trouble now! Modern source control systems are distributed (DVCS - Distributed Version Control System), which means that you have a much simpler setup: every machine that uses it has a full clone of the repository. By the sound of it, you don't have any history at the moment, so I'll assume you just start using either git or hg from where you are. The first thing to do is to get a local copy of the current source tree. I'd start with a Linux system, because everything seems to be easier there... $ cp -r /mnt/samba/whatever/some_project_name . Then you just 'cd' into the project directory (which can be anywhere local - I tend to have a whole pile of them directly in my home directory, or the root directory on Windows, but you can put them anywhere; on my Hackintosh, I use the Documents directory so I can find it more easily), and type either: $ git init $ git add . $ git commit -m'Initial commit' or $ hg init $ hg add . $ hg commit -m'Initial commit' Voila! You now have a repository tracking all your current source code for that project. Then you just set yourself up to pull and push somewhere. The easiest way to do that is to designate somewhere as the central repository and always push changes to there and pull changes from there; that's not strictly necessary, but I do recommend it. Andriy recommends bitbucket; I like github, but that (as the name implies) requires that you use git rather than Mercurial. (I also find that git is rather faster than hg at most tasks. On the flip side, hg is said to be a lot easier to set up on Windows than git is. I've never used hg on Windows, so I can't say, but git on Windows isn't quite as easy as could be desired.) You can also set up your own local server very easily - a good plan if you're moving big binaries around (not usually what you'd call "source code", but perfectly acceptable; I recently ripped out our shared folder document repository and replaced it with git-managed files) or working with something highly sensitive. But for an open-source project, it's easiest to host it "out there" somewhere, and let someone else do the work. After that, it's simply a matter of going through the "quick start" tutorial for your preferred SCM and host, which will help you get started with authentication, push/pull commands, etc etc etc. Source control is something to get your head around, but once you've done that (which you might already have done for the sake of some open source project), everything else becomes easy. Shared folders are easy to explain to someone ("you can access this from everywhere!"), but git or hg gives you ever so much more for no extra effort ("not only can you keep track of your files, you can go back in time to see what's happened, keep track of different branches of development, share it all with the world, get suggestions from the world..."). Start thinking in terms of "my files are in this repository" rather than "my files are on this server", and have lots of clones of that repository, all acting as peers. Life's way better that way :) ChrisA From rosuav at gmail.com Mon Mar 17 11:01:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 02:01:23 +1100 Subject: No subject In-Reply-To: References: Message-ID: On Mon, Mar 17, 2014 at 6:06 PM, J Prashanthan wrote: > i am doing my masters currently and im stuck up with my final project. As i > was interested in learning a new language i opted to do my final project in > python. im currently working on building an unit tester for multithreaded > code. Due to various reasons i got stuck with my project. basically my lack > of knowledge in python and i have none to help me with it. i have no idea > what to do with my project . and my deadline is in another 1 week . I have > completed working on the atomicity violation finder . > Finding Atomicity-Violation Bugs through Unserializable Interleaving Testing > by > Shan Lu, Soyeon Park, and Yuanyuan Zhou, Member, IEEE. This is my base paper > . can anyone please help me with it. if anyone has a working code please > mail me. Almost certainly nobody here has working code that they're willing to simply give you. Is your final project expected to be more than a week's work? If so, I think you're a bit stuck - at least as regards the deadline. But if you have a good idea of how to write code (in some other language than Python), and if you have a thorough set of notes of what you're trying to accomplish (in pseudo-code, or at least your native language - for me that would be English), then you might be able to translate it all into working Python code fairly efficiently. A week is, I'm afraid, not very long for a large project. But with a good language, you can do an amazing amount of work in a short time; and Python is a very good language. I recently knocked together most of a game engine inside 24 hours (not in Python but in a similar language); you might well be able to go from nil to running before your time is up. But it's going to take a lot of work, and you're going to need to start by getting broad familiarity with Python. So start here: http://docs.python.org/3/tutorial/ ChrisA From breamoreboy at yahoo.co.uk Mon Mar 17 11:11:22 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 17 Mar 2014 15:11:22 +0000 Subject: Looking for someone who can build a 64-bit version of SpamBayes installer for Windows In-Reply-To: References: Message-ID: On 17/03/2014 14:39, Mark Lawrence wrote: > On 17/03/2014 14:08, Skip Montanaro wrote: >>> .... As more and >>> more Windows users have moved to 64-bit versions of Windows and >>> Outlook, we've had more and more reports of failures. >>> >>> I think all that's necessary (speaking as someone who knows nothing >>> about Windows) is for someone to build a 64-bit version of the >>> SpamBayes installer for Windows.... >>> >>> Anybody available to help? >> >> Still looking for someone to help building a 64-bit installer for >> SpamBayes on Windows. Anyone? Any idea where else to plead for help? >> >> Skip >> > > https://mail.python.org/mailman/listinfo/python-win32 which is gated to > gmane.comp.python.windows > Or cgohlke at uci.edu as he maintains this "Unofficial Windows Binaries for Python Extension Packages" here http://www.lfd.uci.edu/~gohlke/pythonlibs/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From list at qtrac.plus.com Mon Mar 17 11:31:44 2014 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 17 Mar 2014 08:31:44 -0700 (PDT) Subject: Correct idiom for determining path when frozen in 3.4 In-Reply-To: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> References: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> Message-ID: On Monday, 17 March 2014 08:44:23 UTC, Mark Summerfield wrote: > Hi, > > > > What is the correct idiom for getting the path to a top-level module in 3.3 and 3.4 when the module might be frozen? > > > > At the moment I'm using this: > > > > if getattr(sys, "frozen", False): > > path = os.path.dirname(sys.executable) > > else: > > path = os.path.dirname(__file__) > > > > Thanks! My code was adapted from this: http://cx-freeze.readthedocs.org/en/latest/faq.html#using-data-files When you freeze a Python program with cx_Freeze, sys.freeze exists; but otherwise it doesn't. I develop some programs which I freeze for distribution but during development I test them as-is so I need to be able to distinguish. Also, from 3.4, __file__ won't exist in frozen modules: http://docs.python.org/3.4/whatsnew/3.4.html#changes-in-the-python-api Thanks for your thoughtful replies. From skip at pobox.com Mon Mar 17 12:03:03 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 17 Mar 2014 11:03:03 -0500 Subject: Looking for someone who can build a 64-bit version of SpamBayes installer for Windows In-Reply-To: References: Message-ID: On Mon, Mar 17, 2014 at 10:11 AM, Mark Lawrence wrote: >> https://mail.python.org/mailman/listinfo/python-win32 which is gated to >> gmane.comp.python.windows >> > > Or cgohlke at uci.edu as he maintains this "Unofficial Windows Binaries for > Python Extension Packages" here http://www.lfd.uci.edu/~gohlke/pythonlibs/ Thanks for the pointers, Mark. I'll get in touch with Chris Gohlke. I'm pretty sure I've asked on the python-win32 list before, but I'll check there again. Skip From zachary.ware+pylist at gmail.com Mon Mar 17 12:03:10 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 17 Mar 2014 11:03:10 -0500 Subject: Correct idiom for determining path when frozen in 3.4 In-Reply-To: References: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> Message-ID: On Mon, Mar 17, 2014 at 10:31 AM, Mark Summerfield wrote: > My code was adapted from this: > http://cx-freeze.readthedocs.org/en/latest/faq.html#using-data-files > > When you freeze a Python program with cx_Freeze, sys.freeze exists; but otherwise it doesn't. > > I develop some programs which I freeze for distribution but during development I test them as-is so I need to be able to distinguish. > > Also, from 3.4, __file__ won't exist in frozen modules: > http://docs.python.org/3.4/whatsnew/3.4.html#changes-in-the-python-api Have a look at __spec__, specifically __spec__.origin: >>> import sys >>> _fi = sys.modules['_frozen_importlib'] >>> _fi >>> _fi.__spec__ ModuleSpec(name='_frozen_importlib', loader=, origin='') >>> _fi.__spec__.origin '' I've not looked up in the importlib docs to confirm, but that should mean that frozen modules should have a __spec__.origin that contains "frozen". HTH, -- Zach From harrismh777 at gmail.com Mon Mar 17 12:18:56 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 17 Mar 2014 11:18:56 -0500 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: On 3/15/14 11:26 AM, Jayanth Koushik wrote: This is a very interesting philosophical question, one which I am surprised no one has answered; although, I think the reason for that might be entirely obvious. You actually answered your own question, as you were asking it. If the doc says "whatever you do, don't push the purple button," well, leave the purple button alone. :) (I don't know, push it if you want) If you monitor the PEP process, or have ever taken part in python-ideas, or python-dev (either directly, or just lurking) you will notice that python is developed through a very interesting active committee process (that is really something phenomenal; cool community). How should one spell a complex number? Should we use i or j ? Should the imaginary part be set off somehow? Should literals be parsed differently (or consistently) with correctly formed strings? Who knows, beats me. consider: >>> complex( 3 + 2 j) SyntaxError: invalid syntax >>> complex( 3 +2j ) (3+2j) >>> I don't know... you tell me. >>> complex('3+2j') (3+2j) >>> complex('3 +2j') Traceback (most recent call last): File "", line 1, in complex('3 +2j') ValueError: complex() arg is a malformed string >>> Again, beats me. I just don't know. But I do know that the spelling book says, Do it this way: complex('3+2j'). Seems simple enough. Philosophically, I tend to think about it this way. A complex number is like any other number. I would not form a PI string like this> ' 3 .14 1 5 9265 3 . . .' I would rather see it formed like so, '3.1415926535' This '3 + 2j' is not a number, its an algebraic sum. This '3+2j' is a complex number. Ok, maybe not, but its closer to what we expect (I'm sorry, but I like i instead of j ) Also, philosophically, C ignores white space; python does not. I agree with this now; before I did not. White space is just as much a part of how interpretation occurs, within symbol processing/parsing. Some choices are arbitrary, some are community concurrence (PEPs), some are philosophical, and most are just convenient intuition. My Greek professor used to say, "there is no 'why' in Greek". Python is similar. Cheers From harrismh777 at gmail.com Mon Mar 17 12:42:40 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 17 Mar 2014 11:42:40 -0500 Subject: test References: Message-ID: On 3/16/14 5:07 AM, Chris ?Kwpolska? Warrick wrote: > Why not use the mailing list instead? It?s a much easier way to > access this place. I prefer to 'pull' rather than receive the 'push'. The newsreader idea is better because threading works better, and because the interface is simpler. I don't know, just preference I guess. I am active on several mailing lists also; they only have list servers (not news Usenet server). The Usenet news reader concept must be fading away, and many isp(s) are not providing the nntp post service these days (Charter stopped it in late 2011). There are still several free post servers out there that do not require registration (some are free but do require registration). What are most active pythoniacs doing with this these days? (beats me) From rymg19 at gmail.com Mon Mar 17 12:57:08 2014 From: rymg19 at gmail.com (Ryan Gonzalez) Date: Mon, 17 Mar 2014 11:57:08 -0500 Subject: [Python-Dev] [RELEASED] Python 3.4.0 In-Reply-To: <53269663.9050408@hastings.org> References: <53269663.9050408@hastings.org> Message-ID: YES!!! +1 to the authors of the statistics and pathlib modules. On Mon, Mar 17, 2014 at 1:29 AM, Larry Hastings wrote: > > On behalf of the Python development team, I'm thrilled to announce > the official release of Python 3.4. > > > Python 3.4 includes a range of improvements of the 3.x series, including > hundreds of small improvements and bug fixes. Major new features and > changes in the 3.4 release series include: > > * PEP 428, a "pathlib" module providing object-oriented filesystem paths > * PEP 435, a standardized "enum" module > * PEP 436, a build enhancement that will help generate introspection > information for builtins > * PEP 442, improved semantics for object finalization > * PEP 443, adding single-dispatch generic functions to the standard library > * PEP 445, a new C API for implementing custom memory allocators > * PEP 446, changing file descriptors to not be inherited by default > in subprocesses > * PEP 450, a new "statistics" module > * PEP 451, standardizing module metadata for Python's module import system > * PEP 453, a bundled installer for the *pip* package manager > * PEP 454, a new "tracemalloc" module for tracing Python memory allocations > * PEP 456, a new hash algorithm for Python strings and binary data > * PEP 3154, a new and improved protocol for pickled objects > * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O > > > To download Python 3.4.0 visit: > > http://www.python.org/download/releases/3.4.0/ > > > This is a production release. Please report any issues you notice to: > > http://bugs.python.org/ > > > Enjoy! > > > -- > Larry Hastings, Release Manager > larry at hastings.org > (on behalf of the entire python-dev team and 3.4's contributors) > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ > rymg19%40gmail.com > -- Ryan If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated." -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Mar 17 13:03:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 04:03:19 +1100 Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: On Tue, Mar 18, 2014 at 3:18 AM, Mark H Harris wrote: > You actually answered your own question, as you were asking it. If the doc > says "whatever you do, don't push the purple button," well, leave the purple > button alone. :) (I don't know, push it if you want) https://www.wizards.com/magic/magazine/article.aspx?x=mtg/daily/mm/69 > If you monitor the PEP process, or have ever taken part in python-ideas, or > python-dev (either directly, or just lurking) you will notice that python is > developed through a very interesting active committee process (that is > really something phenomenal; cool community). Not really a committee, more of a champion-and-bikeshedders approach - often with more than one level of champion, as when a PEP has an author (the first champion) and either the BDFL or his delegate (the second champion, whose role is usually just to say yay or nay). It's a curious process, but one that works fairly well. > How should one spell a complex number? Should we use i or j ? Should the > imaginary part be set off somehow? Should literals be parsed differently > (or consistently) with correctly formed strings? Who knows, beats me. > > consider: >>>> complex( 3 + 2 j) > SyntaxError: invalid syntax >>>> complex( 3 +2j ) > (3+2j) >>>> > I don't know... you tell me. That's for the sake of parsing clarity. (Incidentally, the call to complex() is redundant in each case.) Everything in Python consists of tokens - those tokens, in your examples, are: "complex", "(", whitespace, "3", whitespace, "+", whitespace, "2", whitespace, "j", ")", end of line and "complex", "(", whitespace, "3", whitespace, "+", "2j", whitespace, ")", end of line In the first case, the parser then has two symbol-type tokens ("2" and "j") separated by whitespace, with no operator. That's a problem. Did you mean "2+j", or "2==j", etc? Since j is perfectly natural as a name, it's going to be interpreted that way. In the second case, that translates into a perfectly valid parse tree, because "2j" is an imaginary literal. >>> ast.dump(ast.parse("complex( 3 +2j )")) "Module(body=[Expr(value=Call(func=Name(id='complex', ctx=Load()), args=[BinOp(left=Num(n=3), op=Add(), right=Num(n=2j))], keywords=[], starargs=None, kwargs=None))])" The sole argument to complex() is an expression which sums the integer 3 and the imaginary 2j, which results in the complex (3+2j), which complex() looks at and returns unchanged. And that's what you see. >>>> complex('3+2j') > (3+2j) >>>> complex('3 +2j') > Traceback (most recent call last): > File "", line 1, in > complex('3 +2j') > ValueError: complex() arg is a malformed string >>>> > > Again, beats me. I just don't know. And now what you're looking at is the construction of a complex from a string. Now, instead of going by the rules of the Python lexer, it goes by the rules of the complex constructor. You can't use extra spaces there. You could, of course, write your own function that parses whatever format you like (including the use of i instead of j), or you can use ast.literal_eval to parse a string based on Python's lexing, but with complex(str) you follow the rules of complex(str). > Philosophically, I tend to think about it this way. A complex number is like > any other number. I would not form a PI string like this> ' 3 .14 1 5 9265 3 > . . .' I would rather see it formed like so, '3.1415926535' Right. > This '3 + 2j' is not a number, its an algebraic sum. > > This '3+2j' is a complex number. Ok, maybe not, but its closer to what we > expect (I'm sorry, but I like i instead of j ) Hmm. That's a pretty tricky distinction. In Python source code, those two are identical, and they're both rendered as a sum. (Lexically. The CPython optimizer, and presumably other Pythons' optimizers, will notice at compile time that you're adding two literals, and store the sum. But as you see from the AST above, it's the sum of two values.) It's actually not possible, as far as I know, to truly represent a complex number; all you can do is represent the sum of a real part and an imaginary part. > Also, philosophically, C ignores white space; python does not. That's not really anything to do with it. The two languages' approaches to whitespace inside expressions are identical, save that Python will only allow newlines if the expression is "clearly unfinished", eg if it has unbalanced open parens. Horizontal whitespace is fine in both languages. (Of course, C doesn't even _have_ a complex literal notation, so the distinction is slightly moot.) ChrisA From breamoreboy at yahoo.co.uk Mon Mar 17 13:03:21 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 17 Mar 2014 17:03:21 +0000 Subject: test In-Reply-To: References: Message-ID: On 17/03/2014 16:42, Mark H Harris wrote: > On 3/16/14 5:07 AM, Chris ?Kwpolska? Warrick wrote: >> Why not use the mailing list instead? It?s a much easier way to >> access this place. > > I prefer to 'pull' rather than receive the 'push'. > > The newsreader idea is better because threading works better, and > because the interface is simpler. I don't know, just preference > I guess. > > I am active on several mailing lists also; they only have list > servers (not news Usenet server). The Usenet news reader concept > must be fading away, and many isp(s) are not providing the nntp > post service these days (Charter stopped it in late 2011). > > There are still several free post servers out there that do not > require registration (some are free but do require registration). > > What are most active pythoniacs doing with this these days? > > (beats me) > Thunderbird and gmane, FWIW on Windows 7. Several hundred Python mailing lists and blogs all available from one place, plus presumably tens of thousands of other such beasties for just about everything under the sun. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From g.rodola at gmail.com Mon Mar 17 13:11:39 2014 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Mon, 17 Mar 2014 18:11:39 +0100 Subject: [Python-Dev] [RELEASED] Python 3.4.0 In-Reply-To: References: <53269663.9050408@hastings.org> Message-ID: The what's new looks truly amazing, with pathlib and asyncio being my favourite additions. Thanks for all the hard work. On Mon, Mar 17, 2014 at 5:57 PM, Ryan Gonzalez wrote: > YES!!! +1 to the authors of the statistics and pathlib modules. > > > On Mon, Mar 17, 2014 at 1:29 AM, Larry Hastings wrote: > >> >> On behalf of the Python development team, I'm thrilled to announce >> the official release of Python 3.4. >> >> >> Python 3.4 includes a range of improvements of the 3.x series, including >> hundreds of small improvements and bug fixes. Major new features and >> changes in the 3.4 release series include: >> >> * PEP 428, a "pathlib" module providing object-oriented filesystem paths >> * PEP 435, a standardized "enum" module >> * PEP 436, a build enhancement that will help generate introspection >> information for builtins >> * PEP 442, improved semantics for object finalization >> * PEP 443, adding single-dispatch generic functions to the standard >> library >> * PEP 445, a new C API for implementing custom memory allocators >> * PEP 446, changing file descriptors to not be inherited by default >> in subprocesses >> * PEP 450, a new "statistics" module >> * PEP 451, standardizing module metadata for Python's module import system >> * PEP 453, a bundled installer for the *pip* package manager >> * PEP 454, a new "tracemalloc" module for tracing Python memory >> allocations >> * PEP 456, a new hash algorithm for Python strings and binary data >> * PEP 3154, a new and improved protocol for pickled objects >> * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O >> >> >> To download Python 3.4.0 visit: >> >> http://www.python.org/download/releases/3.4.0/ >> >> >> This is a production release. Please report any issues you notice to: >> >> http://bugs.python.org/ >> >> >> Enjoy! >> >> >> -- >> Larry Hastings, Release Manager >> larry at hastings.org >> (on behalf of the entire python-dev team and 3.4's contributors) >> _______________________________________________ >> Python-Dev mailing list >> Python-Dev at python.org >> https://mail.python.org/mailman/listinfo/python-dev >> Unsubscribe: https://mail.python.org/mailman/options/python-dev/ >> rymg19%40gmail.com >> > > > > -- > Ryan > If anybody ever asks me why I prefer C++ to C, my answer will be simple: > "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was > nul-terminated." > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- Giampaolo - http://grodola.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From felixonmars at gmail.com Mon Mar 17 13:18:01 2014 From: felixonmars at gmail.com (Felix Yan) Date: Tue, 18 Mar 2014 01:18:01 +0800 Subject: Thread._stop() behavior changed in Python 3.4 Message-ID: <279038900.uDlbjECTej@felix-arch> Hi list, I noticed a behavior change on Thread._stop() with Python 3.4. I know the method is an undocumented "feature" itself, but some projects are using it, and now they fail. A minimized snippet to reproduce: #!/usr/bin/python import threading def stale(): import time time.sleep(1000) t = threading.Thread(target=stale) t.start() t._stop() This works correctly with Python 3.3, the program exits immediately after t._stop() called, and no exception was raised. But with Python 3.4, an AssertionError was raised: Traceback (most recent call last): File "test.py", line 8, in t._stop() File "/usr/lib/python3.4/threading.py", line 990, in _stop assert not lock.locked() AssertionError And the program still waits on the sleep(). I know trying to forcefully stop a thread is not really a good practice, but I still wonder if there's an easy way to get broken programs to work again, just in the way they currently are? Downstream bug reports, for reference: http://youtrack.jetbrains.com/issue/PY-12317 https://github.com/paramiko/paramiko/issues/286 Regards, Felix Yan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: From dia.aliounes at gmail.com Mon Mar 17 13:18:25 2014 From: dia.aliounes at gmail.com (Alioune Dia) Date: Mon, 17 Mar 2014 18:18:25 +0100 Subject: [Python-Dev] [RELEASED] Python 3.4.0 In-Reply-To: References: <53269663.9050408@hastings.org> Message-ID: yeah , asyncio is a great module, congrat for all jobs you are doing --Ad | Dakar 2014-03-17 18:11 GMT+01:00 Giampaolo Rodola' : > The what's new looks truly amazing, with pathlib and asyncio being my > favourite additions. > Thanks for all the hard work. > > > On Mon, Mar 17, 2014 at 5:57 PM, Ryan Gonzalez wrote: > >> YES!!! +1 to the authors of the statistics and pathlib modules. >> >> >> On Mon, Mar 17, 2014 at 1:29 AM, Larry Hastings wrote: >> >>> >>> On behalf of the Python development team, I'm thrilled to announce >>> the official release of Python 3.4. >>> >>> >>> Python 3.4 includes a range of improvements of the 3.x series, including >>> hundreds of small improvements and bug fixes. Major new features and >>> changes in the 3.4 release series include: >>> >>> * PEP 428, a "pathlib" module providing object-oriented filesystem paths >>> * PEP 435, a standardized "enum" module >>> * PEP 436, a build enhancement that will help generate introspection >>> information for builtins >>> * PEP 442, improved semantics for object finalization >>> * PEP 443, adding single-dispatch generic functions to the standard >>> library >>> * PEP 445, a new C API for implementing custom memory allocators >>> * PEP 446, changing file descriptors to not be inherited by default >>> in subprocesses >>> * PEP 450, a new "statistics" module >>> * PEP 451, standardizing module metadata for Python's module import >>> system >>> * PEP 453, a bundled installer for the *pip* package manager >>> * PEP 454, a new "tracemalloc" module for tracing Python memory >>> allocations >>> * PEP 456, a new hash algorithm for Python strings and binary data >>> * PEP 3154, a new and improved protocol for pickled objects >>> * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O >>> >>> >>> To download Python 3.4.0 visit: >>> >>> http://www.python.org/download/releases/3.4.0/ >>> >>> >>> This is a production release. Please report any issues you notice to: >>> >>> http://bugs.python.org/ >>> >>> >>> Enjoy! >>> >>> >>> -- >>> Larry Hastings, Release Manager >>> larry at hastings.org >>> (on behalf of the entire python-dev team and 3.4's contributors) >>> _______________________________________________ >>> Python-Dev mailing list >>> Python-Dev at python.org >>> https://mail.python.org/mailman/listinfo/python-dev >>> Unsubscribe: https://mail.python.org/mailman/options/python-dev/ >>> rymg19%40gmail.com >>> >> >> >> >> -- >> Ryan >> If anybody ever asks me why I prefer C++ to C, my answer will be simple: >> "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was >> nul-terminated." >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Giampaolo - http://grodola.blogspot.com > > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/dia.aliounes%40gmail.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Mon Mar 17 13:18:05 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 17 Mar 2014 17:18:05 +0000 (UTC) Subject: What does =?utf-8?b?Z2MuZ2V0X29iamVjdHMoKQ==?= return? References: <5320BD3F.5030509@mrabarnett.plus.com> Message-ID: Chris Angelico gmail.com> writes: > > It's not strictly an implementation detail, beyond that there are > certain optimizations. For instance... > > > For CPython 3.4 I guess strings and other atomic types such as ints are > > not, as well as raw object() instances. Custom class instances on the other > > hand seem to be under GC control. > > ... strings and ints should never be listed, and custom objects should > always be listed, but I'd say the non-tracking of object() would be an > implementation-specific optimization. These are all implementation details, tied to the fact that the primary object reclaim mechanism in CPython is reference counting. Other implementations may use a full GC and gc.get_objects() may then also return strings and other "atomic" objects (but the implementation may also elicit to hack get_objects() in order to closely mimick CPython). All in all, though, gc.get_objects() is an expensive function call (it will walk the entire graph of objects tracked by the GC, which can be very large in non-trivial applications), so it's really only useful for debugging (and, I'd add, for low-level debugging). In most situations, gc.get_objects() is certainly the wrong tool to use. Regards Antoine. From solipsis at pitrou.net Mon Mar 17 13:33:09 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 17 Mar 2014 17:33:09 +0000 (UTC) Subject: =?utf-8?b?VGhyZWFkLl9zdG9wKCk=?= behavior changed in Python 3.4 References: <279038900.uDlbjECTej@felix-arch> Message-ID: Hi, Felix Yan gmail.com> writes: > > A minimized snippet to reproduce: > > #!/usr/bin/python > import threading > def stale(): > import time > time.sleep(1000) > t = threading.Thread(target=stale) > t.start() > t._stop() > > This works correctly with Python 3.3, the program exits immediately after > t._stop() called, and no exception was raised. Basically what you are doing is abusing a private method because you want to make the thread daemonic after it was started (a daemonic thread is not waited for at interpreter exit). Please do note one thing: the _stop() method does *not* actually stop the thread; it just marks it stopped, but the underlying OS thread continues to run (and may indeed continue to execute Python code until the interpreter exits). So the obvious "solution" here is to mark the thread daemonic before starting it. A possible related improvement would be to relax the contraints on Thread.daemon to allow setting the flag on a running thread? That said, daemon threads (or abuse of the _stop() method as you did) can lead to instabilities and oddities as some code will continue executing while the interpreter starts shutting down. This has been improved but perhaps not totally solved in recent interpreter versions. A fully correct solution would involve gracefully telling the thread to shut down, via a boolean flag, an Event, a file descriptor or any other means. (if you are interested in this, please open a new issue at http://bugs.python.org) Regards Antoine. From rosuav at gmail.com Mon Mar 17 13:40:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 04:40:51 +1100 Subject: Thread._stop() behavior changed in Python 3.4 In-Reply-To: <279038900.uDlbjECTej@felix-arch> References: <279038900.uDlbjECTej@felix-arch> Message-ID: On Tue, Mar 18, 2014 at 4:18 AM, Felix Yan wrote: > I noticed a behavior change on Thread._stop() with Python 3.4. > > I know the method is an undocumented "feature" itself, but some projects are > using it, and now they fail. > > I know trying to forcefully stop a thread is not really a good practice, but I > still wonder if there's an easy way to get broken programs to work again, just > in the way they currently are? You're using something that has a leading underscore on the name. Frankly, you shouldn't be doing that. Your code was already broken, before 3.4 came along, and it's just that 3.4 highlighted that brokenness. The PyCharm report that this is a Python 3.4 bug is simply incorrect. This code should be a strong indication that something's reaching into places it shouldn't be: https://github.com/JetBrains/intellij-community/blob/master/python/helpers/pydev/pydevd_comm.py#L109 The solution is to have the thread acknowledge, in some way, that it needs to shut down. Forcefully stopping a thread is actually a really bad practice, at least in Python (with OS/2 and VX-REXX, it's a different matter). Antoine says that this doesn't even stop the thread (I can't say; I've never used _stop(), for obvious reasons), so this code was doubly broken. The change in 3.4 should be an excuse to fix the code so it actually works, and works according to the spec, which will mean it works on all versions. ChrisA From jurko.gospodnetic at pke.hr Mon Mar 17 13:53:24 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Mon, 17 Mar 2014 18:53:24 +0100 Subject: What does gc.get_objects() return? In-Reply-To: References: <5320BD3F.5030509@mrabarnett.plus.com> Message-ID: Hi. On 17.3.2014. 18:18, Antoine Pitrou wrote: > All in all, though, gc.get_objects() is an expensive function call (it > will walk the entire graph of objects tracked by the GC, which can be very > large in non-trivial applications), so it's really only useful for > debugging (and, I'd add, for low-level debugging). In most situations, > gc.get_objects() is certainly the wrong tool to use. I agree, and for the record, we were using it for debugging when I started this thread - trying to track down a memory leak. :-) gc.get_objects() turned out to be of great help with in resolving the issue - in the end we tracked it down to a typical reference counting problem in a Python extension DLL. *doh* Best regards, Jurko Gospodneti? From mdickinson at enthought.com Mon Mar 17 13:55:36 2014 From: mdickinson at enthought.com (Mark Dickinson) Date: Mon, 17 Mar 2014 17:55:36 +0000 (UTC) Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: Jayanth Koushik gmail.com> writes: > "Note: When converting from a string, the string must not contain whitespace > around the central + or - operator. For example, complex('1+2j') is fine, but > complex('1 + 2j') raises ValueError." > > Why is this so? See http://bugs.python.org/issue9574 for a bit more context. To begin with, it's not at all clear what *should* be allowed. If "1 + 2j" is valid, what about "+ 2j"? How about "+ 2"? What about things like "+1.0 + -2.3j"? Ultimately, I closed that issue because the proposed change seemed like unnecessary code churn, and there wasn't a clear consensus that the change was desirable (or even what that change should be). If it ain't broke, etc. -- Mark From felixonmars at gmail.com Mon Mar 17 13:59:52 2014 From: felixonmars at gmail.com (Felix Yan) Date: Tue, 18 Mar 2014 01:59:52 +0800 Subject: Thread._stop() behavior changed in Python 3.4 In-Reply-To: References: <279038900.uDlbjECTej@felix-arch> Message-ID: <6089125.ey7IQ53jgg@felix-arch> On Monday, March 17, 2014 17:33:09 Antoine Pitrou wrote: > Hi, > > Felix Yan gmail.com> writes: > > A minimized snippet to reproduce: > > > > #!/usr/bin/python > > import threading > > > > def stale(): > > import time > > time.sleep(1000) > > > > t = threading.Thread(target=stale) > > t.start() > > t._stop() > > > > This works correctly with Python 3.3, the program exits immediately after > > t._stop() called, and no exception was raised. > > Basically what you are doing is abusing a private method because you want > to make the thread daemonic after it was started (a daemonic thread is > not waited for at interpreter exit). Please do note one thing: the _stop() > method does *not* actually stop the thread; it just marks it stopped, but > the underlying OS thread continues to run (and may indeed continue to > execute Python code until the interpreter exits). > > So the obvious "solution" here is to mark the thread daemonic before > starting it. > > A possible related improvement would be to relax the contraints on > Thread.daemon to allow setting the flag on a running thread? > > That said, daemon threads (or abuse of the _stop() method as you did) can > lead to instabilities and oddities as some code will continue executing > while the interpreter starts shutting down. This has been improved but > perhaps not totally solved in recent interpreter versions. A fully correct > solution would involve gracefully telling the thread to shut down, via a > boolean flag, an Event, a file descriptor or any other means. > > (if you are interested in this, please open a new issue at > http://bugs.python.org) > > Regards > > Antoine. Thanks for the detailed explanation! Actually I didn't used _stop() myself either, but noticed the problem when trying to build paramiko against python 3.4. Thanks especially for the tip that the threads may be still running - actually I didn't even think about this part! For now I just skipped the test suites for paramiko to get the packaging done (since the test suites themselves are passed without a problem, just the test script made something wrong). I'll try to follow up the issue for paramiko :) Regards, Felix Yan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: From ian.g.kelly at gmail.com Mon Mar 17 14:03:51 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 17 Mar 2014 12:03:51 -0600 Subject: Thread._stop() behavior changed in Python 3.4 In-Reply-To: References: <279038900.uDlbjECTej@felix-arch> Message-ID: On Mon, Mar 17, 2014 at 11:40 AM, Chris Angelico wrote: > Antoine says that this doesn't even stop the thread > (I can't say; I've never used _stop(), for obvious reasons), so this > code was doubly broken. I was curious about that -- after all, Python's threads aren't truly concurrent, so perhaps they could just test the flag each time they resume -- so I tested it using 3.3. First I tried simply adding a print call on to the end of the OP's function: >>> def stale(): ... import time ... time.sleep(1000) ... print('hello') ... >>> t = threading.Thread(target=stale) >>> t.start(); t._stop() No output was printed, so at least a sleeping thread can apparently be stopped. Then I tried removing the sleep call: >>> def stale(): ... for i in range(10): print('hello') ... >>> t = threading.Thread(target=stale) >>> t.start(); print('Starting'); t._stop(); print('Stopping') hello Starting Stopping >>> hello hello hello hello hello hello hello hello hello So yes, despite the lack of true concurrency, a thread can continue to run after its _stop has been called. From rosuav at gmail.com Mon Mar 17 14:08:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 05:08:20 +1100 Subject: Thread._stop() behavior changed in Python 3.4 In-Reply-To: <6089125.ey7IQ53jgg@felix-arch> References: <279038900.uDlbjECTej@felix-arch> <6089125.ey7IQ53jgg@felix-arch> Message-ID: On Tue, Mar 18, 2014 at 4:59 AM, Felix Yan wrote: > For now I just skipped the test suites for paramiko to get the packaging done > (since the test suites themselves are passed without a problem, just the test > script made something wrong). I'll try to follow up the issue for paramiko :) I've posted comments on both the issues you linked to. My guess based on a cursory look at paramiko is that it's a test suite watchdog, which would be much better implemented with a subprocess; I may be wrong, though. In any case, if it's just a tests problem, you should theoretically be able to ignore it. ChrisA From felixonmars at gmail.com Mon Mar 17 14:13:53 2014 From: felixonmars at gmail.com (Felix Yan) Date: Tue, 18 Mar 2014 02:13:53 +0800 Subject: Thread._stop() behavior changed in Python 3.4 In-Reply-To: References: <279038900.uDlbjECTej@felix-arch> <6089125.ey7IQ53jgg@felix-arch> Message-ID: <1469242.qze850NkBZ@felix-arch> On Tuesday, March 18, 2014 05:08:20 Chris Angelico wrote: > I've posted comments on both the issues you linked to. My guess based > on a cursory look at paramiko is that it's a test suite watchdog, > which would be much better implemented with a subprocess; I may be > wrong, though. In any case, if it's just a tests problem, you should > theoretically be able to ignore it. > > ChrisA I was just trying to comment and see yours... Thanks a lot! :D Regards, Felix Yan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: From rosuav at gmail.com Mon Mar 17 14:18:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 05:18:54 +1100 Subject: Thread._stop() behavior changed in Python 3.4 In-Reply-To: <1469242.qze850NkBZ@felix-arch> References: <279038900.uDlbjECTej@felix-arch> <6089125.ey7IQ53jgg@felix-arch> <1469242.qze850NkBZ@felix-arch> Message-ID: On Tue, Mar 18, 2014 at 5:13 AM, Felix Yan wrote: > On Tuesday, March 18, 2014 05:08:20 Chris Angelico wrote: >> I've posted comments on both the issues you linked to. My guess based >> on a cursory look at paramiko is that it's a test suite watchdog, >> which would be much better implemented with a subprocess; I may be >> wrong, though. In any case, if it's just a tests problem, you should >> theoretically be able to ignore it. >> >> ChrisA > > I was just trying to comment and see yours... Thanks a lot! :D Your comment will mean more, since you actually use the thing :) ChrisA From marko at pacujo.net Mon Mar 17 14:15:55 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 17 Mar 2014 20:15:55 +0200 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: <87y508r8ro.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Mar 18, 2014 at 3:18 AM, Mark H Harris wrote: >> Philosophically, I tend to think about it this way. A complex number >> is like any other number. I would not form a PI string like this> ' 3 >> .14 1 5 9265 3 . . .' I would rather see it formed like so, >> '3.1415926535' > > Right. Well, Java 7 allows you to embed underscores freely in numeric literals. Would be a nice addition to Python as well: if unit == 'G': count *= 1_000_000_000 vs: if unit == 'G': count *= 1000000000 >> This '3 + 2j' is not a number, its an algebraic sum. >> >> This '3+2j' is a complex number. Ok, maybe not, but its closer to what >> we expect (I'm sorry, but I like i instead of j ) > >Hmm. That's a pretty tricky distinction. Is "-2.0" a literal? What's the outcome of -2.0.__str__() Marko From harrismh777 at gmail.com Mon Mar 17 14:20:51 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 17 Mar 2014 13:20:51 -0500 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: On 3/17/14 12:03 PM, Chris Angelico wrote: >>>> ast.dump(ast.parse("complex( 3 +2j )")) > "Module(body=[Expr(value=Call(func=Name(id='complex', ctx=Load()), > args=[BinOp(left=Num(n=3), op=Add(), right=Num(n=2j))], keywords=[], > starargs=None, kwargs=None))])" > > The sole argument to complex() is an expression which sums the integer > 3 and the imaginary 2j, which results in the complex (3+2j), which > complex() looks at and returns unchanged. And that's what you see. ~very nice. Ok, going along with Mark's comment about this bug report: > See http://bugs.python.org/issue9574 This string '3 +2j' should probably be ok from the complex() string constructor standpoint, right? I mean, there might be more than one constructor for string, mighten-it? marcus From ian.g.kelly at gmail.com Mon Mar 17 14:28:05 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 17 Mar 2014 12:28:05 -0600 Subject: 'complex' function with string argument. In-Reply-To: <87y508r8ro.fsf@elektro.pacujo.net> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <87y508r8ro.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 17, 2014 at 12:15 PM, Marko Rauhamaa wrote: > Is "-2.0" a literal? > > What's the outcome of > > -2.0.__str__() No. The compiler will try to optimize it into a single constant if it can, but it has to be done in accordance with the order of operations. In that example, the __str__ method is called before the unary - is applied, resulting in an error. From jurko.gospodnetic at pke.hr Mon Mar 17 14:51:13 2014 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Mon, 17 Mar 2014 19:51:13 +0100 Subject: Thread._stop() behavior changed in Python 3.4 In-Reply-To: References: <279038900.uDlbjECTej@felix-arch> Message-ID: Hi. On 17.3.2014. 19:03, Ian Kelly wrote: > So yes, despite the lack of true concurrency, a thread can continue to > run after its _stop has been called. Actually 'true' or 'false' concurrency does not matter here. CPython supports multiple threads and implements them using underlying native OS threads. The fact that it has an internal mutex (GIL) preventing it from executing/interpreting Python code at the same time in multiple threads (most of the time) does not come into play.. When one thread exits its GIL protected section (e.g. finishes processing one bytecode instruction and is about to go on to processing the next one), another thread may pick up the GIL and do some of its work, e.g. print out some output. Best regards, Jurko Gospodneti? From rosuav at gmail.com Mon Mar 17 14:59:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 05:59:50 +1100 Subject: 'complex' function with string argument. In-Reply-To: <87y508r8ro.fsf@elektro.pacujo.net> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <87y508r8ro.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 18, 2014 at 5:15 AM, Marko Rauhamaa wrote: >>> This '3 + 2j' is not a number, its an algebraic sum. >>> >>> This '3+2j' is a complex number. Ok, maybe not, but its closer to what >>> we expect (I'm sorry, but I like i instead of j ) >> >>Hmm. That's a pretty tricky distinction. > > Is "-2.0" a literal? > > What's the outcome of > > -2.0.__str__() If you mean (-2.0).__str__(), then it returns '-2.0', but that proves nothing. Lots of objects have a str() which isn't a literal. Closer to what you're talking about would be repr(), but even then, it doesn't prove that something's a literal. The easiest way to tell is probably ast.parse(): >>> ast.dump(ast.parse("-2.0")) 'Module(body=[Expr(value=UnaryOp(op=USub(), operand=Num(n=2.0)))])' It's an expression consisting of unary minus and the float literal 2.0. ChrisA From harrismh777 at gmail.com Mon Mar 17 15:01:02 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 17 Mar 2014 14:01:02 -0500 Subject: test References: Message-ID: On 3/17/14 12:03 PM, Mark Lawrence wrote: > Thunderbird and gmane, FWIW on Windows 7. I moved my news reader stuff like comp.lang.python over to my Thunderbird mail client yesterday; works well and is as functional as sea-monkey ever was. The client is nice and has none of the short-comings of gg. The server &Thunderbird complain about the line lengths when in excess of 79 characters (says it can't post) but posts anyway. I've seen that at least one|twice. Gmane looks interesting... gonna try it. marcus From marko at pacujo.net Mon Mar 17 15:22:18 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 17 Mar 2014 21:22:18 +0200 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <87y508r8ro.fsf@elektro.pacujo.net> Message-ID: <87siqgr5p1.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Mar 18, 2014 at 5:15 AM, Marko Rauhamaa wrote: >> Is "-2.0" a literal? >> >> What's the outcome of >> >> -2.0.__str__() > > If you mean (-2.0).__str__(), then it returns '-2.0', but that proves > nothing. The point is, you don't need to "philosophize" about complex literals when even negative numbers don't have literals in Python. Marko From rosuav at gmail.com Mon Mar 17 15:32:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 06:32:18 +1100 Subject: 'complex' function with string argument. In-Reply-To: <87siqgr5p1.fsf@elektro.pacujo.net> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <87y508r8ro.fsf@elektro.pacujo.net> <87siqgr5p1.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 18, 2014 at 6:22 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Mar 18, 2014 at 5:15 AM, Marko Rauhamaa wrote: >>> Is "-2.0" a literal? >>> >>> What's the outcome of >>> >>> -2.0.__str__() >> >> If you mean (-2.0).__str__(), then it returns '-2.0', but that proves >> nothing. > > The point is, you don't need to "philosophize" about complex literals > when even negative numbers don't have literals in Python. Ah! I get you. The difference between literals and constants is one that almost never matters, though. Python may not have a syntax for negative or complex literals, but it does have notations for various sorts of constants, which function the same way. (Literals are by definition constants.) So Python may not have a convenient notation for "number of seconds in a week" (unless you work with DNS and find the bare integer 604800 convenient), but you can write 7*24*60*60 and it's just as good in a function: >>> ast.dump(ast.parse("7*24*60*60")) 'Module(body=[Expr(value=BinOp(left=BinOp(left=BinOp(left=Num(n=7), op=Mult(), right=Num(n=24)), op=Mult(), right=Num(n=60)), op=Mult(), right=Num(n=60)))])' >>> def f(x): return x + 7*24*60*60 >>> dis.dis(f) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 6 (604800) 6 BINARY_ADD 7 RETURN_VALUE There's absolutely no run-time cost to writing it out, and you get to be flexible with whitespace and such, which you can't do with literals. ChrisA From laguna-mc at mail.com Mon Mar 17 15:56:38 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Mon, 17 Mar 2014 15:56:38 -0400 Subject: Installing binwalk on Portable Python Message-ID: <20140317195638.22300@gmx.com> Portable Python 2.7 for Win32 and installed on USB flash drive. I want install Binwalk tool, it have a few depencencies, I installed it first (numpy, matplotlib, libmagic, python-magic) Then I tried to install binwalk from locally stored source archive file, I tried two ways: pip install E:\Portable Python 2.7.5.1\binwalk-1.3.0.tar pip install E:\Portable Python 2.7.5.1\binwalk-1.3.0\src\setup.py I both cases I got error, below is log: E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 21:25:47 Exception: Traceback (most recent call last): File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main status = self.run(options, args) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run InstallRequirement.from_line(name, None)) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line 172, in from_line return cls(req, comes_from, url=url, prereleases=prereleases) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line 70, in __init__ req = pkg_resources.Requirement.parse(req) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, in parse reqs = list(parse_requirements(s)) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, in parse_requirements line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec") File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, in scan_list raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) ValueError: ('Expected version spec in', 'E:\\Portable', 'at', ':\\Portable') ------------------------------------------- What is wrong with this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Mar 17 16:05:58 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 17 Mar 2014 14:05:58 -0600 Subject: Thread._stop() behavior changed in Python 3.4 In-Reply-To: References: <279038900.uDlbjECTej@felix-arch> Message-ID: On Mar 17, 2014 12:53 PM, "Jurko Gospodneti?" wrote: > > Hi. > > > On 17.3.2014. 19:03, Ian Kelly wrote: >> >> So yes, despite the lack of true concurrency, a thread can continue to >> run after its _stop has been called. > > > Actually 'true' or 'false' concurrency does not matter here. > > CPython supports multiple threads and implements them using underlying native OS threads. The fact that it has an internal mutex (GIL) preventing it from executing/interpreting Python code at the same time in multiple threads (most of the time) does not come into play.. When one thread exits its GIL protected section (e.g. finishes processing one bytecode instruction and is about to go on to processing the next one), another thread may pick up the GIL and do some of its work, e.g. print out some output. Yes, and whenever a thread acquires the GIL it *could* check whether its _stop flag has been set before it starts executing any Python code. Apparently though it does not, perhaps for performance reasons. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmawhorter at gmail.com Mon Mar 17 16:13:52 2014 From: pmawhorter at gmail.com (Peter Mawhorter) Date: Mon, 17 Mar 2014 13:13:52 -0700 Subject: Installing binwalk on Portable Python In-Reply-To: <20140317195638.22300@gmx.com> References: <20140317195638.22300@gmx.com> Message-ID: On Mon, Mar 17, 2014 at 12:56 PM, wrote: > Portable Python 2.7 for Win32 and installed on USB flash drive. I want > install Binwalk tool, it have a few depencencies, I installed it first > (numpy, matplotlib, libmagic, python-magic) > Then I tried to install binwalk from locally stored source archive file, I > tried two ways: > > pip install E:\Portable Python 2.7.5.1\binwalk-1.3.0.tar > > pip install E:\Portable Python 2.7.5.1\binwalk-1.3.0\src\setup.py > > I both cases I got error, below is log: > > E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 21:25:47 > Exception: > Traceback (most recent call last): > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main > status = self.run(options, args) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run > InstallRequirement.from_line(name, None)) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > 172, in from_line > return cls(req, comes_from, url=url, prereleases=prereleases) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > 70, in __init__ > req = pkg_resources.Requirement.parse(req) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, in > parse > reqs = list(parse_requirements(s)) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, in > parse_requirements > line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec") > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, in > scan_list > raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) > ValueError: ('Expected version spec in', 'E:\\Portable', 'at', > ':\\Portable') > ------------------------------------------- > > > > What is wrong with this? > -- > https://mail.python.org/mailman/listinfo/python-list > >From your error it looks like you just need quotes around the path because it has a space in it. -Peter Mawhorter From laguna-mc at mail.com Mon Mar 17 16:58:36 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Mon, 17 Mar 2014 16:58:36 -0400 Subject: Installing binwalk on Portable Python Message-ID: <20140317205836.64790@gmx.com> I tried: pip install "E:\Portable Python 2.7.5.1\binwalk-1.3.0\src\setup.py" Error: E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 22:53:51 Exception: Traceback (most recent call last): File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main status = self.run(options, args) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run InstallRequirement.from_line(name, None)) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line 172, in from_line return cls(req, comes_from, url=url, prereleases=prereleases) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line 70, in __init__ req = pkg_resources.Requirement.parse(req) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, in parse reqs = list(parse_requirements(s)) File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, in parse_requirements line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec") File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, in scan_list raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) ValueError: ('Expected version spec in', 'E:\\Portable Python 2.7.5.1\\binwalk-1.3.0\\src\\setup.py', 'at', ':\\Portable Python 2.7.5.1\\binwalk-1.3.0\\src\\setup.py') -------------- ----- Original Message ----- From: Peter Mawhorter Sent: 03/17/14 10:13 PM To: laguna-mc at mail.com Subject: Re: Installing binwalk on Portable Python On Mon, Mar 17, 2014 at 12:56 PM, wrote: > Portable Python 2.7 for Win32 and installed on USB flash drive. I want > install Binwalk tool, it have a few depencencies, I installed it first > (numpy, matplotlib, libmagic, python-magic) > Then I tried to install binwalk from locally stored source archive file, I > tried two ways: > > pip install E:\Portable Python 2.7.5.1\binwalk-1.3.0.tar > > pip install E:\Portable Python 2.7.5.1\binwalk-1.3.0\src\setup.py > > I both cases I got error, below is log: > > E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 21:25:47 > Exception: > Traceback (most recent call last): > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main > status = self.run(options, args) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run > InstallRequirement.from_line(name, None)) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > 172, in from_line > return cls(req, comes_from, url=url, prereleases=prereleases) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > 70, in __init__ > req = pkg_resources.Requirement.parse(req) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, in > parse > reqs = list(parse_requirements(s)) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, in > parse_requirements > line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec") > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, in > scan_list > raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) > ValueError: ('Expected version spec in', 'E:\\Portable', 'at', > ':\\Portable') > ------------------------------------------- > > > > What is wrong with this? > -- > https://mail.python.org/mailman/listinfo/python-list > From your error it looks like you just need quotes around the path because it has a space in it. -Peter Mawhorter -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmawhorter at gmail.com Mon Mar 17 17:07:03 2014 From: pmawhorter at gmail.com (Peter Mawhorter) Date: Mon, 17 Mar 2014 14:07:03 -0700 Subject: Installing binwalk on Portable Python In-Reply-To: <20140317205836.64790@gmx.com> References: <20140317205836.64790@gmx.com> Message-ID: On Mon, Mar 17, 2014 at 1:58 PM, wrote: > I tried: pip install "E:\Portable Python > 2.7.5.1\binwalk-1.3.0\src\setup.py" > > Error: > > E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 22:53:51 > > Exception: > Traceback (most recent call last): > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main > status = self.run(options, args) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run > InstallRequirement.from_line(name, None)) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > 172, in from_line > return cls(req, comes_from, url=url, prereleases=prereleases) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > 70, in __init__ > req = pkg_resources.Requirement.parse(req) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, in > parse > reqs = list(parse_requirements(s)) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, in > parse_requirements > line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec") > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, in > scan_list > raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) > ValueError: ('Expected version spec in', 'E:\\Portable Python > 2.7.5.1\\binwalk-1.3.0\\src\\setup.py', 'at', ':\\Portable Python > 2.7.5.1\\binwalk-1.3.0\\src\\setup.py') > > > -------------- I'm no expert, but when I try to run pip install ... it seems to want a directory that contains a setup.py file rather than the path of the setup.py file itself. Try: pip install "E:\Portable Python 2.7.5.1\binwalk-1.3.0\src" perhaps? -Peter Mawhorter From stutzbach at google.com Mon Mar 17 17:16:52 2014 From: stutzbach at google.com (Daniel Stutzbach) Date: Mon, 17 Mar 2014 14:16:52 -0700 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On Fri, Mar 14, 2014 at 6:13 PM, Joshua Landau wrote: > > Now, I understand there are downsides to blist. Particularly, I've > looked through the "benchmarks" and they seem untruthful. I worked hard to make those benchmarks as fair as possible. I recognize that evaluating your own work always runs the risk of introducing hidden biases, and I welcome input on how they could be improved. -- Daniel Stutzbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From laguna-mc at mail.com Mon Mar 17 17:52:57 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Mon, 17 Mar 2014 17:52:57 -0400 Subject: Installing binwalk on Portable Python Message-ID: <20140317215257.64780@gmx.com> Yes, that help. Installation start, but then failed due to "Pre-requisite failure: failed to find libmagic. Check your installation. Please install the python-magic module, or download and install it from source: ftp://ftp.astron.com/pub/file/' " Although libmagic was installed using pip. ----- Original Message ----- From: Peter Mawhorter Sent: 03/17/14 11:07 PM To: laguna-mc Subject: Re: Installing binwalk on Portable Python On Mon, Mar 17, 2014 at 1:58 PM, wrote: > I tried: pip install "E:\Portable Python > 2.7.5.1\binwalk-1.3.0\src\setup.py" > > Error: > > E:\Portable Python 2.7.5.1\App\Scripts\pip run on 03/17/14 22:53:51 > > Exception: > Traceback (most recent call last): > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\basecommand.py", line 122, in main > status = self.run(options, args) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\commands\install.py", line 257, in run > InstallRequirement.from_line(name, None)) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > 172, in from_line > return cls(req, comes_from, url=url, prereleases=prereleases) > File "E:\Portable Python 2.7.5.1\App\lib\site-packages\pip\req.py", line > 70, in __init__ > req = pkg_resources.Requirement.parse(req) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2606, in > parse > reqs = list(parse_requirements(s)) > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2544, in > parse_requirements > line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec") > File "E:\Portable Python > 2.7.5.1\App\lib\site-packages\pip\_vendor\pkg_resources.py", line 2512, in > scan_list > raise ValueError("Expected "+item_name+" in",line,"at",line[p:]) > ValueError: ('Expected version spec in', 'E:\\Portable Python > 2.7.5.1\\binwalk-1.3.0\\src\\setup.py', 'at', ':\\Portable Python > 2.7.5.1\\binwalk-1.3.0\\src\\setup.py') > > > -------------- I'm no expert, but when I try to run pip install ... it seems to want a directory that contains a setup.py file rather than the path of the setup.py file itself. Try: pip install "E:\Portable Python 2.7.5.1\binwalk-1.3.0\src" perhaps? -Peter Mawhorter -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Mar 17 18:06:50 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 17 Mar 2014 18:06:50 -0400 Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: On 3/17/2014 1:55 PM, Mark Dickinson wrote: > Jayanth Koushik gmail.com> writes: > >> "Note: When converting from a string, the string must not contain whitespace >> around the central + or - operator. For example, complex('1+2j') is fine, but >> complex('1 + 2j') raises ValueError." >> >> Why is this so? > > See http://bugs.python.org/issue9574 for a bit more context. To begin with, > it's not at all clear what *should* be allowed. If "1 + 2j" is valid, what > about "+ 2j"? How about "+ 2"? What about things like "+1.0 + -2.3j"? > Ultimately, I closed that issue because the proposed change seemed like > unnecessary code churn, and there wasn't a clear consensus that the change was > desirable (or even what that change should be). If it ain't broke, etc. I was not nosy on that issue, but I agree with 'as is', along with no space in Franction("1/2"). Mathematicians genearally write both without spaces. -- Terry Jan Reedy From marko at pacujo.net Mon Mar 17 18:05:47 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 18 Mar 2014 00:05:47 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: <87mwgoqy4k.fsf@elektro.pacujo.net> Joshua Landau : > The thing we really need is for the blist containers to become stdlib > (but not to replace the current list implementation). Very interesting. Downloaded blist but didn't compile it yet. It *could* be the missing link. I would *love* to see some comparative performance results between blist.sorteddict and an AVL tree. A B+ tree could be nicer to the CPU cache, but then again, the cache line is only a few pointers wide and there appears to be a lot of shoving stuff left and right -- based on a 10-second "analysis" of the code: while (src >= stop) *dst-- = *src--; Personally, I find it a bit odd to place lists at the center of the proposal and have trees come out as a side effect. I would rather see it the other way round: sorteddict -> sortedset et al. > * It reduces demand for trees: I would hope it would satisfy the demand for trees. > nobody jumps at blists because they're rarely the obvious solution. I haven't jumped at them because they were nowhere to be found on . Marko From thrinaxodon at bitch.invalid Mon Mar 17 18:33:39 2014 From: thrinaxodon at bitch.invalid (Thrinaxodon) Date: Mon, 17 Mar 2014 18:33:39 -0400 Subject: Venus / GuthVenus for iPhone, Nexus, Droid and Android Jelly Bean References: <32cfed4b-dd74-4360-baab-03f6dba01bdb@googlegroups.com> <71ab5220-6d5d-46bf-b33a-16aae6c87109@googlegroups.com> Message-ID: In article <71ab5220-6d5d-46bf-b33a-16aae6c87109 at googlegroups.com>, bradguth at gmail.com says... > > On Wednesday, February 5, 2014 2:59:23 PM UTC-8, Brad Guth wrote: > > On Saturday, January 11, 2014 3:52:10 PM UTC-8, Brad Guth wrote: > > > > > NOVA and Discovery Channel each missed this one as of 13+ years ago; > > > > > > > > > > GuthVenus 1:1, plus 10x resample/enlargement of the area in question > > > > > > > > > > http://bradguth.blogspot.com/2009/07/brad-guth-index.html > > > > > > > > > > http://nssdc.gsfc.nasa.gov/imgcat/hires/mgn_c115s095_1.gif > > > > > > > > > > > > > > > > > > > > Our NASA and all of their contracted universities plus numerous others associated somehow missed this one, even after they'd been explicitly informed. Go figure. > > > > > > > > > > > > > > > > > > > > Be my guest and apply your very own photographic enlargement software, as to viewing this one small but rather interesting topography area of Venus, using your independent deductive expertise as to further enlarge or magnify and simply interpret this extensively mountainous and canyon populated terrain area of Venus that I've focused upon (roughly one third up from the bottom and roughly center), honestly shouldn't be asking too much. Most of modern PhotoZoom and numerous other photographic software variations tend to accomplish this digital enlargement process automatically on the fly, (including iPhone, Safari, Android, Mozilla FireFox, Google Chrome and most other internet browsing forms of image viewing and zooming), although some extra applied filtering and thereby image enhancing for dynamic range compensations (aka contrast boosting) can further improve upon the end result (no direct pixel modifications should ever be necessary, because it's all a derivative from the original Magellan radar imaging that's offering a composite of 36 confirming radar scans per pixel, that can always be 100% verified from scratch). > > > > > > > > > > > > > > > > > > > > Using Ctrl+,+,+ gets most older PCs and even the basic Apple notebooks to quickly zoom in, whereas iPhone, Android and MS-W8 as well as Google Chrome accepts touch-pad or screen touch zooming with even somewhat better results of automatic image resampling, so as to keeping the image context reasonably clear or in focus. However, a regular photographic editing app or software solution like PhotoShop is still going to provide some of the best results plus offering dynamic range compensation for a version of added contrast without actually modifying a damn thing as to the raw context of the original, because everything always remains as a direct image derivative. > > > > > > > > > > http://photo-editing-software-review.toptenreviews.com/ > > > > > > > > > > > > HERE'S THE ANSWER: ======================= >BREAKING NEWSSSSSSSSS ======================= > RICHARD LEAKEY JUST DIED DUE TO HEART FAILURE! > THE REASONS DESCRIBED BY THE MEDICAL TEAM IS THAT HIS WORK WAS DISPROVEN, BY NONE OTHER THAN YOUR OWN BASTARD, THRINAXODON. > THIS CAUSED LEAKEY'S HEART TO EXPLODE! > THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000! > TO WASTE YOUR TIME EVEN FURTHER, CHECK OUT THESE LINKS BELOW. =========================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa d/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa d/3aad75c16afb0b82# ==================================== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON REDDIT From skip at pobox.com Mon Mar 17 19:59:44 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 17 Mar 2014 18:59:44 -0500 Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: On Mon, Mar 17, 2014 at 5:06 PM, Terry Reedy wrote: > Mathematicians genearally write both without spaces. Mathematicians also have a tendency to use single letter variables and often escape into non-ASCII character sets as well. Perhaps it's worth pointing out that pylint complains about most/many infix operations if you don't surround the operator with white space. And, complex expressions work just fine with white space around the operator: >>> 1 + 2j (1+2j) Personally, I'm agnostic to the proposed change. I don't use complex numbers in my work, and I suspect that creating complex numbers from strings is an extremely small corner case. Skip From joshua at landau.ws Mon Mar 17 20:08:27 2014 From: joshua at landau.ws (Joshua Landau) Date: Tue, 18 Mar 2014 00:08:27 +0000 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On 17 March 2014 21:16, Daniel Stutzbach wrote: > On Fri, Mar 14, 2014 at 6:13 PM, Joshua Landau wrote: >> >> Now, I understand there are downsides to blist. Particularly, I've >> looked through the "benchmarks" and they seem untruthful. > > I worked hard to make those benchmarks as fair as possible. I recognize > that evaluating your own work always runs the risk of introducing hidden > biases, and I welcome input on how they could be improved. Thanks. First, I want to state that there are two aspects to my claim. The first is that these benchmarks to not represent typical use-cases. I will not go too far into this, though, because it's mostly obvious. The second is that of the the flaws in the benchmarks themselves. I'll go through in turn some that are apparent to me: "Create from an iterator" gives me relatively different results when I run it (Python 3). "Delete a slice" is fudged from its inclusion of multiplication, which is far faster on blists. I admit that it's not obvious how to fix this. "First in, first out (FIFO)" should be "x.append(0); x.pop(0)". "Last in, first out (LIFO)" should use "pop()" over "pop(-1)", although I admit it shouldn't make a meaningful difference. "Sort *" are really unfair because they put initialisation in the timed part and all have keys. The benchmarks on Github are less bad, but the website really should include all of them and fix the remaining problems. I do understand that TimSort isn't the most suited algorithm, though, so I won't read too far into these results. Further, some of these tests don't show growth where they should, such as in getitem. The growth is readily apparent when measured as such: >>> python -m timeit -s "from random import choice; import blist; lst = blist.blist(range(10**0))" "choice(lst)" 1000000 loops, best of 3: 1.18 usec per loop >>> python -m timeit -s "from random import choice; import blist; lst = blist.blist(range(10**8))" "choice(lst)" 1000000 loops, best of 3: 1.56 usec per loop Lower size ranges are hidden by the function-call overhead. Perhaps this effect is to do with caching, in which case the limits of the cache should be explained more readily. Nevertheless, my enthusiasm for blist as an alternative stdlib implementation remains. There are obvious and large advantages to be had, sometimes when you wouldn't even expect. The slower aspects of blist are also rarely part of the bottlenecks of programs. So yeah, go for it. From rosuav at gmail.com Mon Mar 17 20:16:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 11:16:48 +1100 Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: On Tue, Mar 18, 2014 at 10:59 AM, Skip Montanaro wrote: > Perhaps it's worth pointing out that pylint complains about most/many > infix operations if you don't surround the operator with white space. IMO that's excessive. Not every infix operator needs whitespace. ChrisA From mok-kong.shen at t-online.de Mon Mar 17 20:32:05 2014 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Tue, 18 Mar 2014 01:32:05 +0100 Subject: Ordering in the printout of a dictionary Message-ID: Could someone kindly explain a phenomenon in the following where: (1) I first typed in a dictionary but got a printout in a reordered form. (2) I then typed in the reordered form but got a printout in the order that I typed in originally in (1). That is, there is no stable "standard" ordering. Why is that so? Is there a way to force a certain ordering of the printout or else somehow manage to get at least a certain stable ordering of the printout (i.e. input and output are identical)? Thanks in advance. M. K. Shen ------------------------------------------ >>> {'label': 3, 'parent': 0, 'left child': 1, 'right child': 2} {'right child': 2, 'parent': 0, 'left child': 1, 'label': 3} >>> {'right child': 2, 'parent': 0, 'left child': 1, 'label': 3} {'label': 3, 'parent': 0, 'left child': 1, 'right child': 2} From leobutcher5 at gmail.com Mon Mar 17 20:42:46 2014 From: leobutcher5 at gmail.com (leobutcher5 at gmail.com) Date: Mon, 17 Mar 2014 17:42:46 -0700 (PDT) Subject: Python Docs & Download servers not accessable from Egypt Message-ID: Hello, I just want to report a python web sites specific problem I don't know if this is the right place to report it I can't seem to access docs.python.org, mail.python.org, or even legacy.python.org from my ISP in Egypt "LinkDotNet" the dynamic IP range I noticed while facing this problem is 41.130.xx.xx please tell me if you need any further info Thanks From rosuav at gmail.com Mon Mar 17 20:48:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 11:48:04 +1100 Subject: Ordering in the printout of a dictionary In-Reply-To: References: Message-ID: On Tue, Mar 18, 2014 at 11:32 AM, Mok-Kong Shen wrote: > Could someone kindly explain a phenomenon in the following where: > > (1) I first typed in a dictionary but got a printout in a reordered > form. > > (2) I then typed in the reordered form but got a printout in the > order that I typed in originally in (1). > > That is, there is no stable "standard" ordering. Why is that so? A dictionary is simply a mapping from keys to values. It has no ordering. > Is there a way to force a certain ordering of the printout or else > somehow manage to get at least a certain stable ordering of the > printout (i.e. input and output are identical)? Yes; instead of simply printing it out (which calls repr()), explicitly iterate over it, like this: def display(d): return '{'+','.join('%r: %r'%(key,d[key]) for key in sorted(d))+'}' >>> print(display({'label': 3, 'parent': 0, 'left child': 1, 'right child': 2})) {'label': 3, 'left child': 1, 'parent': 0, 'right child': 2} That will be consistent, and will also always be sorted, which will probably be what you want for human-readable display. At least, it's consistent as long as the keys all sort consistently, which they will if you use simple strings. Other types of keys may not work, and in fact mixing types may cause an exception: >>> print(display({True:1,"Hello":2})) Traceback (most recent call last): File "", line 1, in File "", line 2, in display TypeError: unorderable types: str() < bool() But for strings, this is the easiest way to get what you're looking for. ChrisA From rosuav at gmail.com Mon Mar 17 20:49:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 11:49:46 +1100 Subject: Python Docs & Download servers not accessable from Egypt In-Reply-To: References: Message-ID: On Tue, Mar 18, 2014 at 11:42 AM, wrote: > Hello, > > I just want to report a python web sites specific problem I don't know if this is the right place to report it > > I can't seem to access docs.python.org, mail.python.org, or even legacy.python.org > from my ISP in Egypt "LinkDotNet" the dynamic IP range I noticed while facing this problem is 41.130.xx.xx > please tell me if you need any further info What IP address is docs.python.org for you? Try using 'dig' or 'ping' on it. For me, it's: docs.python.org. 60625 IN CNAME dinsdale.python.org. dinsdale.python.org. 60625 IN A 82.94.164.162 ChrisA From stutzbach at google.com Mon Mar 17 21:01:24 2014 From: stutzbach at google.com (Daniel Stutzbach) Date: Mon, 17 Mar 2014 18:01:24 -0700 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On Mon, Mar 17, 2014 at 5:08 PM, Joshua Landau wrote: > Thanks. First, I want to state that there are two aspects to my > claim. The first is that these benchmarks to not represent typical > use-cases. I will not go too far into this, though, because it's > mostly obvious. > I would love to have include macro-benchmarks. I keep waiting for the PyPy benchmark suite to get ported to Python 3... > "Create from an iterator" gives me relatively different results when I > run it (Python 3). > The graphs were originally created to compare vanilla Python with a Python modified to use blist as the built-in list type. I think I used Python 3.1, but I'm not certain. As I recall, the built-in type has a few small advantages over any third-party extension type, so that might be what you're seeing. Alternately, something may have changed between Python versions. > "Delete a slice" is fudged from its inclusion of multiplication, which > is far faster on blists. I admit that it's not obvious how to fix > this. > I could move the initialization into the timed part, similar to what I did for sort (see below). That has downsides too, of course, but it might be an improvement. > "First in, first out (FIFO)" should be "x.append(0); x.pop(0)". > Wow, I mangled that one badly. > "Last in, first out (LIFO)" should use "pop()" over "pop(-1)", > although I admit it shouldn't make a meaningful difference. > I like pop(-1) because it's explicit rather than implicit. I agree it shouldn't make a meaningful difference. > "Sort *" are really unfair because they put initialisation in the > timed part That's a limitation of timeit. The setup step is only executed once. If I put the initialization there, every sort after the first one would be sorting a pre-sorted list. If you compare the "Create form an iterator" and "Sort a random list", you'll see that the initialization cost is dwarfed by the sorting cost for n > 15 or so. > and all have keys. If you use classes with __lt__ methods instead of keys, the cost is dominated by the calls to __lt__. You're right that I should include both, though. > >>> python -m timeit -s "from random import choice; import blist; lst = > blist.blist(range(10**0))" "choice(lst)" > 1000000 loops, best of 3: 1.18 usec per loop > > >>> python -m timeit -s "from random import choice; import blist; lst = > blist.blist(range(10**8))" "choice(lst)" > 1000000 loops, best of 3: 1.56 usec per loop > > Lower size ranges are hidden by the function-call overhead. > Perhaps this effect is to do with caching, in which case the limits of > the cache should be explained more readily. > That's definitely a cache issue, which is always a risk with micro-benchmarks. I see growth even for the built-in list: gnusto:~$ python -m timeit -s "from random import choice; lst = list(range(10**0))" "choice(lst)" 1000000 loops, best of 3: 0.349 usec per loop gnusto:~$ python -m timeit -s "from random import choice; lst = list(range(10**8))" "choice(lst)" 1000000 loops, best of 3: 0.634 usec per loop I agree it's more interesting to pick items randomly instead of always querying the same index. The overhead of choice() is kind of a problem, though. Since I'm only plotting up to 10**5, I'd expect these to look more or less flat. Thanks for all of the feedback. I filed a bug with myself to improve the metrics: https://github.com/DanielStutzbach/blist/issues/64 -- Daniel Stutzbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Mon Mar 17 21:07:31 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 17 Mar 2014 20:07:31 -0500 Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: On Mon, Mar 17, 2014 at 7:16 PM, Chris Angelico wrote: > On Tue, Mar 18, 2014 at 10:59 AM, Skip Montanaro wrote: >> Perhaps it's worth pointing out that pylint complains about most/many >> infix operations if you don't surround the operator with white space. > > IMO that's excessive. Not every infix operator needs whitespace. I wasn't suggesting it was the only way things could be done. Just pointing out that there is enough common practice out there to suggest that white space around infix operators is often the preferred way of doing things. Quoting from PEP 8: If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies). Use your own judgment; however, never use more than one space, and always have the same amount of whitespace on both sides of a binary operator. Yes: i = i + 1 submitted += 1 x = x*2 - 1 hypot2 = x*x + y*y c = (a+b) * (a-b) ... My point is that accommodating white space around the + or - sign isn't altogether unreasonable. Maybe PEP 8 needs to be tweaked with an example of good complex literal practice? Skip From gordon at panix.com Mon Mar 17 22:56:21 2014 From: gordon at panix.com (John Gordon) Date: Tue, 18 Mar 2014 02:56:21 +0000 (UTC) Subject: Ordering in the printout of a dictionary References: Message-ID: In Chris Angelico writes: > > Is there a way to force a certain ordering of the printout or else > > somehow manage to get at least a certain stable ordering of the > > printout (i.e. input and output are identical)? > Yes; instead of simply printing it out (which calls repr()), > explicitly iterate over it, like this: > def display(d): > return '{'+','.join('%r: %r'%(key,d[key]) for key in sorted(d))+'}' You could also use the OrderedDict type, which is subclass of dict that preserves insertion order. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From bradguth at yahoo.com Mon Mar 17 23:45:17 2014 From: bradguth at yahoo.com (Brad Guth) Date: Mon, 17 Mar 2014 20:45:17 -0700 Subject: Venus / GuthVenus for iPhone, Nexus, Droid and Android Jelly Bean In-Reply-To: References: <32cfed4b-dd74-4360-baab-03f6dba01bdb@googlegroups.com> <71ab5220-6d5d-46bf-b33a-16aae6c87109@googlegroups.com> Message-ID: On 3/17/2014 3:33 PM, Thrinaxodon wrote: > In article <71ab5220-6d5d-46bf-b33a-16aae6c87109 at googlegroups.com>, > bradguth at gmail.com says... >> >> On Wednesday, February 5, 2014 2:59:23 PM UTC-8, Brad Guth wrote: >>> On Saturday, January 11, 2014 3:52:10 PM UTC-8, Brad Guth wrote: >>> >>>> NOVA and Discovery Channel each missed this one as of 13+ years ago; >>> >>>> >>> >>>> GuthVenus 1:1, plus 10x resample/enlargement of the area in question >>> >>>> >>> >>>> http://bradguth.blogspot.com/2009/07/brad-guth-index.html >>> >>>> >>> >>>> http://nssdc.gsfc.nasa.gov/imgcat/hires/mgn_c115s095_1.gif >>> >>>> >>> >>>> >>> >>>> >>> >>>> Our NASA and all of their contracted universities plus numerous others associated somehow missed this one, even after they'd been explicitly informed. Go figure. >>> >>>> >>> >>>> >>> >>>> >>> >>>> Be my guest and apply your very own photographic enlargement software, as to viewing this one small but rather interesting topography area of Venus, using your independent deductive expertise as to further enlarge or magnify and simply interpret this extensively mountainous and canyon populated terrain area of Venus that I've focused upon (roughly one third up from the bottom and roughly center), honestly shouldn't be asking too much. Most of modern PhotoZoom and > numerous other photographic software variations tend to accomplish this digital enlargement process automatically on the fly, (including iPhone, Safari, Android, Mozilla FireFox, Google Chrome and most other internet browsing forms of image viewing and zooming), although some extra applied filtering and thereby image enhancing for dynamic range compensations (aka contrast boosting) can further improve upon the end result (no direct pixel modifications should ever be > necessary, because it's all a derivative from the original Magellan radar imaging that's offering a composite of 36 confirming radar scans per pixel, that can always be 100% verified from scratch). >>> >>>> >>> >>>> >>> >>>> >>> >>>> Using Ctrl+,+,+ gets most older PCs and even the basic Apple notebooks to quickly zoom in, whereas iPhone, Android and MS-W8 as well as Google Chrome accepts touch-pad or screen touch zooming with even somewhat better results of automatic image resampling, so as to keeping the image context reasonably clear or in focus. However, a regular photographic editing app or software solution like PhotoShop is still going to provide some of the best results plus offering > dynamic range compensation for a version of added contrast without actually modifying a damn thing as to the raw context of the original, because everything always remains as a direct image derivative. >>> >>>> >>> >>>> http://photo-editing-software-review.toptenreviews.com/ >>> >>>> >>> >>>> >>> > > HERE'S THE ANSWER: > > ======================= >> BREAKING NEWSSSSSSSSS > ======================= >> > RICHARD LEAKEY JUST DIED DUE TO HEART FAILURE! >> > THE REASONS DESCRIBED BY THE MEDICAL TEAM IS THAT HIS WORK WAS > DISPROVEN, BY NONE OTHER THAN YOUR OWN BASTARD, THRINAXODON. >> > THIS CAUSED LEAKEY'S HEART TO EXPLODE! >> > THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000! >> > TO WASTE YOUR TIME EVEN FURTHER, CHECK OUT THESE LINKS BELOW. > =========================== > EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: > > https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa > d/6f501c469c7af24f# > > > https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa > d/3aad75c16afb0b82# > > > ==================================== > > http://thrinaxodon.wordpress.com/ > > =================================== > > THRINAXODON ONLY HAD THIS TO SAY: > > "I..I...I...Can't believe it. This completely disproved Darwinian > orthodoxy." > > =================================== > > THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING > WITH FEAR. > > =========================== > THESE ASSHOLES ARE GOING TO DIE: > THOMAS AQUINAS; > ALDOUS HUXLEY; > BOB CASANVOVA; > SkyEyes; > DAVID IAIN GRIEG; > MARK ISAAK; > JOHN HARSHAM; > RICHARD NORMAN; > DR. DOOLITTLE; > CHARLES DARWIN; > MARK HORTON; > ERIK SIMPSON; > HYPATIAB7; > PAUL J. GANS; > JILLERY; > WIKI TRIK; > THRINAXODON; > PETER NYIKOS; > RON OKIMOTO; > JOHN S. WILKINS > =========================== > > THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A > HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT > THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD > TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY > FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep > people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS > SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That > is a myth, for people to believe in science." THRINAXODON PLANS TO > BRING DOOM TO SCIENCE, ITSELF. > > ============================ > > THRINAXODON IS NOW ON REDDIT > Direct death threats should be kept to a minimum. > =========================== > THESE ASSHOLES ARE GOING TO DIE: > THOMAS AQUINAS; > ALDOUS HUXLEY; > BOB CASANVOVA; > SkyEyes; > DAVID IAIN GRIEG; > MARK ISAAK; > JOHN HARSHAM; > RICHARD NORMAN; > DR. DOOLITTLE; > CHARLES DARWIN; > MARK HORTON; > ERIK SIMPSON; > HYPATIAB7; > PAUL J. GANS; > JILLERY; > WIKI TRIK; > THRINAXODON; > PETER NYIKOS; > RON OKIMOTO; > JOHN S. WILKINS > =========================== You may want to revise that manifesto to read 'suffer and pay dearly' instead of "GOING TO DIE", unless you meant via natural causes. From steve at pearwood.info Tue Mar 18 00:08:11 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Mar 2014 04:08:11 GMT Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <87y508r8ro.fsf@elektro.pacujo.net> <87siqgr5p1.fsf@elektro.pacujo.net> Message-ID: <5327c6ab$0$2923$c3e8da3$76491128@news.astraweb.com> On Mon, 17 Mar 2014 21:22:18 +0200, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Mar 18, 2014 at 5:15 AM, Marko Rauhamaa >> wrote: >>> Is "-2.0" a literal? >>> >>> What's the outcome of >>> >>> -2.0.__str__() >> >> If you mean (-2.0).__str__(), then it returns '-2.0', but that proves >> nothing. > > The point is, you don't need to "philosophize" about complex literals > when even negative numbers don't have literals in Python. But Python *does* have complex (well, imaginary to be precise) literals. The j suffix to a number makes it complex: py> type(2j) Complex numbers with both a real and imaginary component are not treated as literals: py> import ast py> ast.dump(ast.parse("2j")) 'Module(body=[Expr(value=Num(n=2j))])' py> ast.dump(ast.parse("1+2j")) 'Module(body=[Expr(value=BinOp(left=Num(n=1), op=Add(), right=Num(n=2j)))])' and in recent versions, the peephole optimizer optimizes them: py> from dis import dis py> dis("1+2j") 1 0 LOAD_CONST 2 ((1+2j)) 3 RETURN_VALUE -- Steven From steve at pearwood.info Tue Mar 18 00:52:35 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Mar 2014 04:52:35 GMT Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> On Mon, 17 Mar 2014 11:18:56 -0500, Mark H Harris wrote: > How should one spell a complex number? Should we use i or j ? Should the > imaginary part be set off somehow? Should literals be parsed > differently (or consistently) with correctly formed strings? Who knows, > beats me. With respect, that's just because you would make a lousy language designer :-) The answer to most of those questions should be pretty obvious, with perhaps just one that isn't clear. "How should one spell a complex number?" There is perfectly good syntax for complex numbers used by mathematicians and engineers for over a century. There is no need to invent something different just for the sake of being different: Yes: 2+3i or 2+3j No: @2|3? "Should we use i or j ?" There are good reasons for both i and j. This one comes down to personal preference. "Should the imaginary part be set off somehow?" What do you mean "set off"? Why do you want to? Since the imaginary part can appear on its own: z = 3j we cannot make "setting off" compulsory. Once you have syntax for complex numbers with an imaginary component, everything else Just Works with no additional effort: z = 2 + 3j # an expression adding 2 to 3j z = 5*3j # an expression multiplying 5 by 3j There's no need for dedicated syntax for complex numbers beyond the simple no-real-part case. You get everything else for free from basic arithmetic expressions, so there actually isn't need to parse complex literals beyond the j suffix. "Should literals be parsed differently (or consistently) with correctly formed strings?" Once you decide that complex literals should be formed from only the imaginary part, 3j, parsing literals is simple. So is passing strings: you have something that looks like a float, with a j suffix. Obviously they should parse the same. assert 1.234j == complex('1.234j') Problem solved. Well, not quite -- it would be rather limiting if the complex constructor only accepted complex numbers with an implicitly zero real part. We'd like to accept anything that repr(z) can print. Since repr(z) prints complex numbers with a + or - infix operator, the complex constructor should accept the same inside strings. How flexible should the complex constructor be? Should it bend over backwards to accept any mathematical expression that includes a complex j suffix, e.g. complex("2**3i")? I think not, since complex numbers don't display like that. Our only obligation is to parse the strings that complex.__repr__ can produce, not to parse any imaginable numeric expression. So at a minimum, complex should accept strings that look like j +j -j For the same reason that float("2") works, we should also allow strings that look like: with no j suffix. Anything else, including spaces around the + and - symbols, would be a bonus. > consider: > >>> complex( 3 + 2 j) > SyntaxError: invalid syntax That's a syntax error for the same reason that: x = 1 2 is a syntax error. Nothing to do with the + sign. It's the spaces between the 2 and the j. > >>> complex( 3 +2j ) > (3+2j) > >>> > I don't know... you tell me. In both cases, the call to complex is redundant. You've already created a complex number, using syntax, then you pass it to the complex function which just returns the same number. > >>> complex('3+2j') > (3+2j) > >>> complex('3 +2j') > Traceback (most recent call last): > File "", line 1, in > complex('3 +2j') > ValueError: complex() arg is a malformed string Personally, I would like complex to accept spaces around the + or -, as it already accepts leading and trailing spaces. But it's not a big deal. [...] > Also, philosophically, C ignores white space; python does not. C does not ignore whitespace. forwhile is not the same as for while The first is a valid identifier, the second is a syntax error. Oh somebody please tell me it's not a valid C expression! *wink* -- Steven From rosuav at gmail.com Tue Mar 18 00:59:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 15:59:56 +1100 Subject: 'complex' function with string argument. In-Reply-To: <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 18, 2014 at 3:52 PM, Steven D'Aprano wrote: > The first is a valid identifier, the second is a syntax error. Oh > somebody please tell me it's not a valid C expression! *wink* It's not a valid C expression. ChrisA From frank at chagford.com Tue Mar 18 01:39:37 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 18 Mar 2014 07:39:37 +0200 Subject: Question about Source Control References: Message-ID: "Chris Angelico" wrote in message news:CAPTjJmqPca5cnNWu8T5BZhpH665X0=mrf7bJaLqVrQVMjZWu1g at mail.gmail.com... > On Tue, Mar 18, 2014 at 12:06 AM, Frank Millman > wrote: [...] >> >> So where should I install the SCM, and how should I set it up so that I >> can >> access the latest version from any machine? > > First off: You can save yourself a huge amount of trouble now! Modern > source control systems are distributed (DVCS - Distributed Version > Control System), which means that you have a much simpler setup: every > machine that uses it has a full clone of the repository. > > By the sound of it, you don't have any history at the moment, so I'll > assume you just start using either git or hg from where you are. The > first thing to do is to get a local copy of the current source tree. > I'd start with a Linux system, because everything seems to be easier > there... > [...] Thanks, Chris. I appreciate the detailed explanation. Two quick questions - 1. At present the source code is kept on one machine (A), but only accessed from the two other machines (B and C). Does it make sense to create the central repository on A, but *not* install the SCM on A? Install separate copies of the SCM on B and C, and allow them both to set up their own clones. I only develop on B, so only B would 'push', but both B and C would 'pull' to get the latest version. 2. Being a typical lazy programmer, I frequently go through the following cycle. I work on a section of code by editing it on B. Then I test it by running it on C. Instead of meticulously checking my code I let python find the errors, so I run it on C, it crashes with a traceback, I fix the error on B and rerun it on C until it is working to my satisfaction. It seems that I will have to change my approach. Edit on B, 'push' on B, 'pull' on C, run from C. It sounds more cumbersome, but maybe that is the price I have to pay. Have I got those two right? Thanks Frank From rosuav at gmail.com Tue Mar 18 02:03:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 17:03:27 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: On Tue, Mar 18, 2014 at 4:39 PM, Frank Millman wrote: > Two quick questions - > > 1. At present the source code is kept on one machine (A), but only accessed > from the two other machines (B and C). > > Does it make sense to create the central repository on A, but *not* install > the SCM on A? Install separate copies of the SCM on B and C, and allow them > both to set up their own clones. I only develop on B, so only B would > 'push', but both B and C would 'pull' to get the latest version. I don't know about Mercurial, but with git, installing the software on A lets it work more efficiently (otherwise it has to do all the work remotely, ergo unnecessary traffic). Advantage of free software is that you don't have to check license agreements - just go ahead, install it everywhere. But if for some reason that would be a problem, you can look into running it over basic SSH or something. > 2. Being a typical lazy programmer, I frequently go through the following > cycle. I work on a section of code by editing it on B. Then I test it by > running it on C. Instead of meticulously checking my code I let python find > the errors, so I run it on C, it crashes with a traceback, I fix the error > on B and rerun it on C until it is working to my satisfaction. > > It seems that I will have to change my approach. Edit on B, 'push' on B, > 'pull' on C, run from C. It sounds more cumbersome, but maybe that is the > price I have to pay. > > Have I got those two right? That would be the simplest to set up. But here are two alternatives: 1) My current setup for developing Gypsum involves development on Sikorsky, on Linux, and everything gets tested there. Then every once in a while, I pull changes to Traal, and test on Windows. If there's a problem, that's a separate commit fixing a separate issue ("Implement pause key handling" / "Fix pause key handling on Windows"). That works fairly well when you can do >90% of your testing on your development box. 2) At work, we had a system for rapid development across two machines, pretty much how you're describing. To make that work, I wrote a three-part rapid send/receive system: a daemon that runs on the dev system, a client that runs on the test system and connects to the daemon, and a triggering notification that runs on the dev and tells the daemon to do its work. (That could be done with a process signal, but I wanted to send it some parameters.) When the daemon gets notified to send its stuff across, it writes out the full content of all changed files (mangled somewhat because my boss was paranoid - well, as far as I know he's still utterly paranoid, but he's not my boss any more) to the socket connection, and the receiver plops them onto the disk and SIGHUPs the appropriate processes to tell them to reload code. The second option takes some setting up, though I'd be happy to help out with the code. But it's really easy to use. You shoot stuff across to it and off it all goes. The way I described above, it's quite happy to have multiple simultaneous clients, and it's happy for those clients to be behind NAT - so you can run half a dozen VMs with different configurations, and have them all get the code together. And you can put the trigger into a makefile to be run at the end of some other tasks, or have it do some sanity checking, or whatever you like. Very flexible and powerful. ChrisA From frank at chagford.com Tue Mar 18 02:42:13 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 18 Mar 2014 08:42:13 +0200 Subject: Question about Source Control References: Message-ID: "Chris Angelico" wrote in message news:CAPTjJmqHXh2M3-QGbeLV_AkGAJzMEYmbuDLy8_dkpnhrpSUVMQ at mail.gmail.com... > On Tue, Mar 18, 2014 at 4:39 PM, Frank Millman wrote: >> Two quick questions - >> >> 1. At present the source code is kept on one machine (A), but only >> accessed >> from the two other machines (B and C). >> >> Does it make sense to create the central repository on A, but *not* >> install >> the SCM on A? Install separate copies of the SCM on B and C, and allow >> them >> both to set up their own clones. I only develop on B, so only B would >> 'push', but both B and C would 'pull' to get the latest version. > > I don't know about Mercurial, but with git, installing the software on > A lets it work more efficiently (otherwise it has to do all the work > remotely, ergo unnecessary traffic). Advantage of free software is > that you don't have to check license agreements - just go ahead, > install it everywhere. But if for some reason that would be a problem, > you can look into running it over basic SSH or something. > Excuse my ignorance, but how does it actually work? Do you set up some kind of client/server relationship, and if so, how do the clients (machines B and C) access the software on machine A? I know that Mercurial can run its own web server, and clients can access it through http. It that what you are suggesting? That would be quite a change for me, as on my linux box I do all my work from the command line on a console. These are the kind of stumbling blocks that prevented me from succeeding in my previous attempt. I have a vague recollection that I set it up on machine A, but then hit a problem because machines B and C both accessed the same directory, but with different names - on Windows, a mapped drive and on linux a mounted nfs directory. I had to provide a 'path' name to set up Mercurial in the first place, but I could not find one that suited both clients. I feel that I have just not grasped the basics yet, so any assistance that puts me on the right path is appreciated. Frank From ben+python at benfinney.id.au Tue Mar 18 02:47:51 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 18 Mar 2014 17:47:51 +1100 Subject: Question about Source Control References: Message-ID: <85y508roiw.fsf@benfinney.id.au> "Frank Millman" writes: > I feel that I have just not grasped the basics yet, so any assistance that > puts me on the right path is appreciated. Here is ?Hg Init?, a tutorial for Mercurial . (?source control? is not the most common term for this; what we're talking about is a ?version control system?, or VCS. But some Git users may disagree.) -- \ ?If nature has made any one thing less susceptible than all | `\ others of exclusive property, it is the action of the thinking | _o__) power called an idea? ?Thomas Jefferson | Ben Finney From frank at chagford.com Tue Mar 18 02:45:05 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 18 Mar 2014 08:45:05 +0200 Subject: Question about Source Control References: Message-ID: "Andriy Kornatskyy" wrote in message news:BLU0-SMTP953C8572B5CA6374830E50917D0 at phx.gbl... > Frank, > > I would suggest start with an account on https://bitbucket.org. It > supports private repositories so you should be good there. > > From other hand you can setup own infrastructure for SCM, read more here: > http://mindref.blogspot.com/2013/10/how-to-manage-git-or-mercurial.html > Thanks, Andriy. I followed your link, which took me to another link which took me to RhodeCode - https://rhodecode.com/ It looks interesting. I wll investigate that and bitbucket further. Frank From auriocus at gmx.de Tue Mar 18 03:04:44 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 18 Mar 2014 08:04:44 +0100 Subject: 'complex' function with string argument. In-Reply-To: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: Am 15.03.14 17:26, schrieb Jayanth Koushik: > This is regarding the inbuilt 'complex' function. The python docs > say: "Note: When converting from a string, the string must not > contain whitespace around the central + or - operator. For example, > complex('1+2j') is fine, but complex('1 + 2j') raises ValueError." It's funny that you ask this question exactly now; because I'm currently implementing a compiler for a small language that understands complex numbers. As others have explained, the basic issue is the question how to parse an expression like 1+2i*3 is it "complex(1+2i) times 3" or is it sum of 1 and product of complex 2i and 3? The answer that python does it by parsing imaginary literals and then combining them back using peephole optimization was helpful, thanks for that! Christian From rosuav at gmail.com Tue Mar 18 03:09:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 18:09:51 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: On Tue, Mar 18, 2014 at 5:42 PM, Frank Millman wrote: > Excuse my ignorance, but how does it actually work? Ignorance not only excused, but welcomed. :) However, caveat: I know how git is set up, but not hg. Someone else can fill in the details; for now, I'll explain git and hope that hg is broadly similar. I expect it will be. > Do you set up some kind of client/server relationship, and if so, how do the > clients (machines B and C) access the software on machine A? For read-only access, git can run its own protocol, but for read/write it's most common to run it over SSH. Every pull or push is implemented by git calling on ssh to run either 'git send-pack' or 'git receive-pack' on the other end. (It's common to set it up with a restricted shell that can *only* run those commands, although I also find this usage convenient for cloning between two computers that I control, rather than fetching from upstream. It's immensely faster downloading something over a virtualized gigabit ethernet link than over the internet!) So it goes by the rules of SSH. There's a user account on the target computer, which owns all the files in the repository. That user account might have a password on it (which you type in every time you pull/push), or you might use public/private keys to authenticate, or whatever else you've set up. That part isn't git's responsibility. On Linux systems, it's usually pretty easy to set up openssh and a dedicated account; on other servers, I assume it can't be hard to get something going. > I know that Mercurial can run its own web server, and clients can access it > through http. It that what you are suggesting? That would be quite a change > for me, as on my linux box I do all my work from the command line on a > console. You'd still do everything from the command line. You type "git clone blahblah" or "hg clone blahblah", and everything happens under the covers. The only way you'd know the difference is if the "blahblah" part identifies the protocol (which it usually will, but that's somewhat beside the point). > These are the kind of stumbling blocks that prevented me from succeeding in > my previous attempt. I have a vague recollection that I set it up on machine > A, but then hit a problem because machines B and C both accessed the same > directory, but with different names - on Windows, a mapped drive and on > linux a mounted nfs directory. I had to provide a 'path' name to set up > Mercurial in the first place, but I could not find one that suited both > clients. > > I feel that I have just not grasped the basics yet, so any assistance that > puts me on the right path is appreciated. Yeah, a distributed repository solves that. You could have three entirely different path names on the three computers, and nothing will care. (You have to be careful to use relative paths everywhere internally, of course, but you probably do that already.) It's pretty efficient once you get used to it; I recommend poking around on the internet for a git tutorial or an hg tutorial, depending on which you go with. It's not too hard, but there are a lot of commands to keep track of. Here's a helpful quick reference to the differences between the two: https://github.com/sympy/sympy/wiki/Git-hg-rosetta-stone As a git-familiar and hg-novice, I keep that handy every time I'm working with hg on anything more complicated than "keep up with the changes". ChrisA From rosuav at gmail.com Tue Mar 18 03:11:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 18:11:45 +1100 Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: On Tue, Mar 18, 2014 at 6:04 PM, Christian Gollwitzer wrote: > As others have explained, the basic issue is the question how to parse an > expression like > > 1+2i*3 > > is it "complex(1+2i) times 3" or is it sum of 1 and product of complex 2i > and 3? The only way to have it be the former would be to mandate that all complex literals have both parts, and you'd still lose clarity. You'd probably want to have some other symbol rather than + in there, to emphasize the connection: 1_2j 1_--2j # Negative imaginary component Otherwise, yeah, do what Python does and have imaginary literals only. ChrisA From frank at chagford.com Tue Mar 18 03:14:28 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 18 Mar 2014 09:14:28 +0200 Subject: Question about Source Control References: <85y508roiw.fsf@benfinney.id.au> Message-ID: "Ben Finney" wrote in message news:85y508roiw.fsf at benfinney.id.au... > "Frank Millman" writes: > >> I feel that I have just not grasped the basics yet, so any assistance >> that >> puts me on the right path is appreciated. > > Here is "Hg Init", a tutorial for Mercurial . > > ("source control" is not the most common term for this; what we're > talking about is a "version control system", or VCS. But some Git users > may disagree.) > Thanks, Ben, that is a really nice tutorial. I was calling it an SCM because that is how Mercurial describes it - from their home page "Mercurial is a free, distributed source managment control tool". I do agree that 'version control' makes more sense. Frank From rosuav at gmail.com Tue Mar 18 03:18:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 18:18:20 +1100 Subject: Question about Source Control In-Reply-To: <85y508roiw.fsf@benfinney.id.au> References: <85y508roiw.fsf@benfinney.id.au> Message-ID: On Tue, Mar 18, 2014 at 5:47 PM, Ben Finney wrote: > (?source control? is not the most common term for this; what we're > talking about is a ?version control system?, or VCS. But some Git users > may disagree.) People use different terms depending on their backgrounds, I think. I've heard a good few words used to describe fundamentally the same thing, and none is really perfect. ChrisA From usenetmail at solar-empire.de Tue Mar 18 03:36:44 2014 From: usenetmail at solar-empire.de (Marc Christiansen) Date: Tue, 18 Mar 2014 08:36:44 +0100 Subject: Ordering in the printout of a dictionary References: Message-ID: Chris Angelico wrote: > On Tue, Mar 18, 2014 at 11:32 AM, Mok-Kong Shen > wrote: >> Is there a way to force a certain ordering of the printout or else >> somehow manage to get at least a certain stable ordering of the >> printout (i.e. input and output are identical)? > > Yes; instead of simply printing it out (which calls repr()), > explicitly iterate over it, like this: > > def display(d): > return '{'+','.join('%r: %r'%(key,d[key]) for key in sorted(d))+'}' > [...] > At least, it's consistent as long as the keys all sort consistently, > which they will if you use simple strings. Other types of keys may not > work, and in fact mixing types may cause an exception: > >>>> print(display({True:1,"Hello":2})) > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in display > TypeError: unorderable types: str() < bool() > > But for strings, this is the easiest way to get what you're looking for. I would say using pprint.pprint is even easier and it works with your failing example: >>> pprint.pprint({True:1,"Hello":2}) {True: 1, 'Hello': 2} Ciao Marc From joshua at landau.ws Tue Mar 18 03:46:42 2014 From: joshua at landau.ws (Joshua Landau) Date: Tue, 18 Mar 2014 07:46:42 +0000 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Message-ID: On 18 March 2014 01:01, Daniel Stutzbach wrote: > I would love to have include macro-benchmarks. I keep waiting for the PyPy > benchmark suite to get ported to Python 3... *grins* >> "Delete a slice" is fudged from its inclusion of multiplication, which >> is far faster on blists. I admit that it's not obvious how to fix >> this. > > I could move the initialization into the timed part, similar to what I did > for sort (see below). That has downsides too, of course, but it might be an > improvement. You could try making a baseline and subtracting it: timer("del x[len(x)//4:3*len(x)//4]; x *= 2") - timer("x * 2") Not ideal, but closer, assuming that the multiplication isn't much larger than the deletion. Error would be summed. >> "Sort *" are really unfair because they put initialisation in the >> timed part > > That's a limitation of timeit. The setup step is only executed once. If I > put the initialization there, every sort after the first one would be > sorting a pre-sorted list. If you compare the "Create form an iterator" and > "Sort a random list", you'll see that the initialization cost is dwarfed by > the sorting cost for n > 15 or so. This argument is slightly less convincing without the overhead of the keys. It might be worth doing a subtraction and adding some error-bars as I suggest above. Nevertheless, I do agree for n > some small n, which is all that matters anyway. >> and all have keys. > > If you use classes with __lt__ methods instead of keys, the cost is > dominated by the calls to __lt__. You're right that I should include both, > though. This argument doesn't make sense to me. The only time this happens is when you have a non-primitive and your transformation gives a primitive which has optimised comparisons. This typically only happens when the key is a getitem or getattr, in which case it's just meaningless overhead. I see little reason to care about the key's cost in those cases. > That's definitely a cache issue, which is always a risk with > micro-benchmarks. > > I agree it's more interesting to pick items randomly instead of always > querying the same index. The overhead of choice() is kind of a problem, > though. Since I'm only plotting up to 10**5, I'd expect these to look more > or less flat. You could try jumping around to avoid the cache without using random numbers. Something like "idx = (idx + LARGE_PRIME) % n" might have less overhead. Further, the subtraction method would probably work fine for that. Also, I don't think the cache is all bad. Chances are a lot of list accesses have a lot of data locality. > Thanks for all of the feedback. Thanks in turn for the module :). From rosuav at gmail.com Tue Mar 18 03:55:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 18:55:17 +1100 Subject: Ordering in the printout of a dictionary In-Reply-To: References: Message-ID: On Tue, Mar 18, 2014 at 6:36 PM, Marc Christiansen wrote: > I would say using pprint.pprint is even easier and it works with your > failing example: > >>>> pprint.pprint({True:1,"Hello":2}) > {True: 1, 'Hello': 2} > True. I could try to say that I prefer to offer the simpler approach rather than encourage people to automatically reach for the nearest hammer and hope it's right, but the fact is... I completely forgot about pprint :) ChrisA From steve at pearwood.info Tue Mar 18 03:55:51 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Mar 2014 07:55:51 GMT Subject: Question about Source Control References: Message-ID: <5327fc07$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 18 Mar 2014 17:47:51 +1100, Ben Finney wrote: > "Frank Millman" writes: > >> I feel that I have just not grasped the basics yet, so any assistance >> that puts me on the right path is appreciated. > > Here is ?Hg Init?, a tutorial for Mercurial . > > (?source control? is not the most common term for this; what we're > talking about is a ?version control system?, or VCS. But some Git users > may disagree.) I don't think that *version* control is the right model to describe what hg and git do, although it may be appropriate for subversion. hg doesn't manage *versions*, it manages changes to source code ("changesets"). Mercurial describes itself as a "distributed source control management tool", so I think the term "source control" is quite appropriate. http://mercurial.selenic.com/ -- Steve From steve at pearwood.info Tue Mar 18 04:00:29 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Mar 2014 08:00:29 GMT Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> Message-ID: <5327fd1c$0$2923$c3e8da3$76491128@news.astraweb.com> On Tue, 18 Mar 2014 08:04:44 +0100, Christian Gollwitzer wrote: > Am 15.03.14 17:26, schrieb Jayanth Koushik: >> This is regarding the inbuilt 'complex' function. The python docs say: >> "Note: When converting from a string, the string must not contain >> whitespace around the central + or - operator. For example, >> complex('1+2j') is fine, but complex('1 + 2j') raises ValueError." > > It's funny that you ask this question exactly now; because I'm currently > implementing a compiler for a small language that understands complex > numbers. As others have explained, the basic issue is the question how > to parse an expression like > > 1+2i*3 > > is it "complex(1+2i) times 3" Putting my mathematician's hat on, I would say *absolutely not*. > or is it sum of 1 and product of complex 2i and 3? This one. Multiplication has higher precedence than addition, so 1+2i*3 has to be evaluated as 1+(2i*3). -- Steve From rosuav at gmail.com Tue Mar 18 04:08:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 19:08:17 +1100 Subject: Question about Source Control In-Reply-To: <5327fc07$0$2923$c3e8da3$76491128@news.astraweb.com> References: <5327fc07$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 18, 2014 at 6:55 PM, Steven D'Aprano wrote: > I don't think that *version* control is the right model to describe what > hg and git do, although it may be appropriate for subversion. hg doesn't > manage *versions*, it manages changes to source code ("changesets"). Meh... Is there any real difference? With git, I can check out any tree state I like ("give me the 50th parent of the current HEAD"), so in that sense it effectively stores versions - at least, it can retrieve or recreate versions. Does it store versions and optimize them by recording only the difference, or record differences and replay them to recreate a state? Two sides of the same coin. ChrisA From auriocus at gmx.de Tue Mar 18 04:21:48 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 18 Mar 2014 09:21:48 +0100 Subject: 'complex' function with string argument. In-Reply-To: <5327fd1c$0$2923$c3e8da3$76491128@news.astraweb.com> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327fd1c$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: Hi Steven, Am 18.03.14 09:00, schrieb Steven D'Aprano: > On Tue, 18 Mar 2014 08:04:44 +0100, Christian Gollwitzer wrote: > >> Am 15.03.14 17:26, schrieb Jayanth Koushik: >>> This is regarding the inbuilt 'complex' function. The python docs say: >>> "Note: When converting from a string, the string must not contain >>> whitespace around the central + or - operator. For example, >>> complex('1+2j') is fine, but complex('1 + 2j') raises ValueError." >> >> It's funny that you ask this question exactly now; because I'm currently >> implementing a compiler for a small language that understands complex >> numbers. As others have explained, the basic issue is the question how >> to parse an expression like >> >> 1+2i*3 >> >> is it "complex(1+2i) times 3" > > Putting my mathematician's hat on, I would say *absolutely not*. > >> or is it sum of 1 and product of complex 2i and 3? > > This one. Multiplication has higher precedence than addition, so 1+2i*3 > has to be evaluated as 1+(2i*3). The question was not whether the expression should be interpreted the first way, I'm sorry for being unclear. The question was how to implement this in a compiler. Because if you implement complex literals in the tokenizer, you would end up with the tokens of the first interpretation. But if you implement as imaginary literals, then your parse tree for "1+2i" ends up as a sum of a real and an imaginary literal, instead of a complex literal. This works, but it lets your parse tree grow and possibly generates inefficient code. The answer I got here, is to parse it as a sum and let the optimizer combine it back into a single complex constant. The same problem arises with unary minus, but it's less annoying because -(a*b) = (-a)*b. I admit that my knowledge of compiler construction is limited, and I'm working on my first real-world application now. Oh, and it's not written in Python. Christian From rosuav at gmail.com Mon Mar 17 23:48:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Mar 2014 14:48:52 +1100 Subject: Venus / GuthVenus for iPhone, Nexus, Droid and Android Jelly Bean In-Reply-To: References: <32cfed4b-dd74-4360-baab-03f6dba01bdb@googlegroups.com> <71ab5220-6d5d-46bf-b33a-16aae6c87109@googlegroups.com> Message-ID: On Tue, Mar 18, 2014 at 2:45 PM, Brad Guth wrote: > You may want to revise that manifesto to read 'suffer and pay dearly' > instead of "GOING TO DIE", unless you meant via natural causes. Don't bother responding to Thrinaxodon, it's a spammer. ChrisA From jsutar at gmail.com Tue Mar 18 05:11:19 2014 From: jsutar at gmail.com (Jignesh Sutar) Date: Tue, 18 Mar 2014 09:11:19 +0000 Subject: Find and replace multiple RegEx search expressions Message-ID: Hi, I'm trying to delete contents of a .txt log file, matching on multiple re.sub criteria but not sure how to achieve this. Below is an illustration of what I am trying to achieve (of course in this example I can combine the 3 re.sub into a single re expression but my actual code will have a dozen plus expression I need to match on so easier to keep them separate). Only the last re.sub will take effect in the example below I need all 3 to take effect. import re o = open(r"c:\temp\outputfile.txt","w") data = open(r"C:\Temp\infile.txt").read() o.write( re.sub(".* ","",data) ) o.write( re.sub(".* ","",data) ) o.write( re.sub(".* ","",data) ) o.close() Thanks in advance. Jignesh -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Mar 18 05:48:03 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 18 Mar 2014 10:48:03 +0100 Subject: Find and replace multiple RegEx search expressions References: Message-ID: Jignesh Sutar wrote: > Hi, > > I'm trying to delete contents of a .txt log file, matching on multiple > re.sub criteria but not sure how to achieve this. > > Below is an illustration of what I am trying to achieve (of course in this > example I can combine the 3 re.sub into a single re expression but my > actual code will have a dozen plus expression I need to match on so easier > to keep them separate). Only the last re.sub will take effect in the > example below I need all 3 to take effect. > > > import re > o = open(r"c:\temp\outputfile.txt","w") > data = open(r"C:\Temp\infile.txt").read() > o.write( re.sub(".* ","",data) ) > o.write( re.sub(".* ","",data) ) > o.write( re.sub(".* ","",data) ) > o.close() Apply all substitutions to data before you write the result to the file: with open(infile) as f: data = f.read() for expr in list_of_regexes: data = re.sub(expr, "", data) with open(outfile, "w") as f: f.write(data) From balajimarisetti at gmail.com Tue Mar 18 06:10:58 2014 From: balajimarisetti at gmail.com (balaji marisetti) Date: Tue, 18 Mar 2014 15:40:58 +0530 Subject: Python3 html.parser Message-ID: Hi, I'm trying to parse a pice of HTML code using `html.parser` in Python3. I want to find out the offset of a particular end tag (let's say

) and then stop processing the remaining HTML code immediately. So I wrote something like this. [code] def handle_endtag(self, tag): if tag == mytag: #do something self.reset() [code] I called `reset()` method at the end of `handle_endtag()` method. Now the problem is: when I call parser.feed("some html"), it's giving an "AssertionError" exception. Isn't the `reset()` method supposed to be called inside "handler" methods? Thanks, Balaji -- :-)balaji -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Mar 18 07:44:24 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 18 Mar 2014 12:44:24 +0100 Subject: Python3 html.parser References: Message-ID: balaji marisetti wrote: > Hi, > > I'm trying to parse a pice of HTML code using `html.parser` in Python3. > I want to find out the offset of a particular end tag (let's say

) and > then stop processing > the remaining HTML code immediately. So I wrote something like this. > > [code] > def handle_endtag(self, tag): > if tag == mytag: > #do something > self.reset() > [code] > > I called `reset()` method at the end of `handle_endtag()` method. Now the > problem is: when I call parser.feed("some html"), it's giving an > "AssertionError" exception. Isn't the `reset()` method > supposed to be called inside "handler" methods? Obviously not ;) After looking into the code I think there is no controlled way to stop parsing. I suggest that you raise a custom exception instead: import html.parser class TagFound(Exception): pass class MyParser(html.parser.HTMLParser): def handle_endtag(self, tag): if tag == wanted_tag: raise TagFound wanted_tag = "a" parser = MyParser() for data in ["", ""]: try: parser.feed(data) except TagFound: print("tag {!r} found".format(wanted_tag)) else: print("tag {!r} not found".format(wanted_tag)) parser.reset() From steve+comp.lang.python at pearwood.info Tue Mar 18 09:45:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2014 13:45:18 GMT Subject: Question about Source Control References: <5327fc07$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <53284dee$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 18 Mar 2014 19:08:17 +1100, Chris Angelico wrote: > On Tue, Mar 18, 2014 at 6:55 PM, Steven D'Aprano > wrote: >> I don't think that *version* control is the right model to describe >> what hg and git do, although it may be appropriate for subversion. hg >> doesn't manage *versions*, it manages changes to source code >> ("changesets"). > > Meh... Is there any real difference? If you believe Joel Spolsky, there is: http://hginit.com/00.html Scroll down about half way, to the section titled "One more big conceptual difference". Recording *snapshots* versus recording *diffs* makes a considerable difference when it comes to dealing with merge conflicts. -- Steven From marko at pacujo.net Tue Mar 18 10:00:13 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 18 Mar 2014 16:00:13 +0200 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327fd1c$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <87lhw738uq.fsf@elektro.pacujo.net> Christian Gollwitzer : > The same problem arises with unary minus, but it's less annoying > because -(a*b) = (-a)*b. >>> -1**2 -1 Marko From steve+comp.lang.python at pearwood.info Tue Mar 18 10:20:07 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2014 14:20:07 GMT Subject: Unexpected comparisons in dict lookup Message-ID: <53285617$0$29994$c3e8da3$5496439d@news.astraweb.com> I stumbled across this unexpected behaviour with Python 2.7 and 3.3. When you look up a key in a dict, the key is sometimes compared against other keys twice instead of just once. First, a class that reports when it is being tested for equality, with a fixed hash so that we get collisions inside the dict: class Spam: def __init__(self, label): self.label = label def __str__(self): return self.label def __hash__(self): return 100 def __eq__(self, other): print("comparing %s with %s" % (self, other)) return self is other Create a dict and prepare for collisions: x = Spam("x") y = Spam("y") d = {100: 1} # hash(100) == 100 When we add x to the dict, it collides with the existing key 100, so I expect one call to Spam.__eq__, and that's exactly what I get: py> d[x] = 200 comparing x with 100 But when I try adding y to the dict, it collides with 100, then it collides with x, then it apparently collides with x a second time: py> d[y] = 300 comparing y with 100 comparing x with y comparing x with y I expected only two calls to __eq__, not three: first comparing with 100, then comparing with x. Checking for keys gives the same result: py> x in d comparing x with 100 True py> y in d comparing y with 100 comparing x with y comparing x with y True What's more, checking for a key which is not present also compares three times instead of twice: py> Spam("z") in d comparing z with 100 comparing x with z comparing x with z comparing y with z False I expected it to compare z with 100, then x *once*, then y, then return False. Why is the dict lookup comparing against x twice? It doesn't seem to be the fault of x. If I create a slightly different dict, with the collisions in a different order: py> e = {x: 100} py> e[100] = 200 comparing x with 100 py> e[y] = 300 comparing x with y comparing y with 100 comparing y with 100 -- Steven From harrismh777 at gmail.com Tue Mar 18 12:14:49 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 18 Mar 2014 11:14:49 -0500 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: On 3/17/14 11:52 PM, Steven D'Aprano wrote: > On Mon, 17 Mar 2014 11:18:56 -0500, Mark H Harris wrote: >> Who knows, beats me. > With respect, that's just because you would make a lousy language > designer :-) Ouch ;-) > "How should one spell a complex number?" There is perfectly good syntax > for complex numbers used by mathematicians and engineers for over a > century. There is no need to invent something different just for the sake > of being different: > Yes: 2+3i or 2+3j Yes. my Q was rhetorical only. And for the sake of discussion, particularly on the part of the OP, to think about what one expects based on experience and common sense, as a mathematician. (that doesn't mean it will be easy for the lexical parser. > "Should we use i or j ?" There are good reasons for both i and j. This > one comes down to personal preference. no, not really. nobody writes, e^(jPI) + 1 = 0 Euler wants to see e^(iPI) + 1 = 0 ;-) > "Should the imaginary part be set off somehow?" What do you mean "set > off"? Why do you want to? Since the imaginary part can appear on its own: simply, is 2j a literal complex part? ...yes 2 j ...no In other words, there must NEVER be a space between the 2 and j. This is debatable: 3 +2j although, I want to see 3+2j > z = 2 + 3j # an expression adding 2 to 3j > z = 5*3j # an expression multiplying 5 by 3j all good, well until its not > How flexible should the complex constructor be? Should it bend over > backwards to accept any mathematical expression that includes a complex j > suffix, e.g. complex("2**3i")? I think not, I think not either. But, it is possible to have *many* constructors/ But, really, how often is this a problem? like almost never! >> >>> complex( 3 +2j ) >> (3+2j) >> >>> >> I don't know... you tell me. > > In both cases, the call to complex is redundant. You've already created a > complex number, using syntax, then you pass it to the complex function > which just returns the same number. Of course. I was merely pointing out that the constructor for 'literals' (whatever you guys mean by that) is 'different' than the consistency with the string constructor. As Chris pointed out these are two markedly different animals; one is a valid parse syntax, the other is a string constructor. But here is my point--- to the user the difference comes down to semantics, which is not really true. cf. below >> >>> complex('3+2j') >> (3+2j) >> >>> complex('3 +2j') >> Traceback (most recent call last): >> File "", line 1, in >> complex('3 +2j') >> ValueError: complex() arg is a malformed string >> Also, philosophically, C ignores white space; python does not. This was said tongue in cheek... *both* languages inconsistently observer (and ignore) white space! But, in general, white space is more important to python, and less important to C. I'm still hung up on whether I'm a lousy language designer. I guess we'll know if people use my language (or not)! I suppose they might use it even though its lousy; on the other hand, it might be too simple for folks to be able to figure it out. :) marcus From nospam at thanks.invalid Tue Mar 18 12:17:36 2014 From: nospam at thanks.invalid (Juha Nieminen) Date: Tue, 18 Mar 2014 16:17:36 +0000 (UTC) Subject: HOLY SH*T! HUMANS ORIGINATED IN THE DEVONIAN References: Message-ID: In comp.lang.c++ ASSODON wrote: > THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000! I find it interesting, from a psychological perspective, that you are not even *pretending* that you are not lying and making stuff up. You pretty much imply it as clearly as it possibly can be, and clearly don't care. Yet, nevertheless, you accuse others of lying. I don't think you are simply a troll who does this for his own amusement, because even trolls get tired of the same old joke, and move to other things. I get a feeling of this being more obsessive in nature. There's something probably very wrong inside your head. I really think you should seek professional help for your mental problems. --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From ladynikon at gmail.com Tue Mar 18 12:56:03 2014 From: ladynikon at gmail.com (Danyelle Davis) Date: Tue, 18 Mar 2014 12:56:03 -0400 Subject: HOLY SH*T! HUMANS ORIGINATED IN THE DEVONIAN In-Reply-To: References: Message-ID: Don't feed the trolls. Actually talking to it makes it think you actually care.. On Mon, Mar 17, 2014 at 4:50 AM, ASSODON wrote: > ======================= > >BREAKING NEWSSSSSSSSS > ======================= > > > RICHARD LEAKEY JUST DIED DUE TO HEART FAILURE! > > > THE REASONS DESCRIBED BY THE MEDICAL TEAM IS THAT HIS WORK WAS > DISPROVEN, BY NONE OTHER THAN YOUR OWN BASTARD, THRINAXODON. > > > THIS CAUSED LEAKEY'S HEART TO EXPLODE! > > > THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000! > > > TO WASTE YOUR TIME EVEN FURTHER, CHECK OUT THESE LINKS BELOW. > =========================== > EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: > > https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa > d/6f501c469c7af24f# > > > https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa > d/3aad75c16afb0b82# > > > ==================================== > > http://thrinaxodon.wordpress.com/ > > =================================== > > THRINAXODON ONLY HAD THIS TO SAY: > > "I..I...I...Can't believe it. This completely disproved Darwinian > orthodoxy." > > =================================== > > THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING > WITH FEAR. > > =========================== > THESE ASSHOLES ARE GOING TO DIE: > THOMAS AQUINAS; > ALDOUS HUXLEY; > BOB CASANVOVA; > SkyEyes; > DAVID IAIN GRIEG; > MARK ISAAK; > JOHN HARSHAM; > RICHARD NORMAN; > DR. DOOLITTLE; > CHARLES DARWIN; > MARK HORTON; > ERIK SIMPSON; > HYPATIAB7; > PAUL J. GANS; > JILLERY; > WIKI TRIK; > THRINAXODON; > PETER NYIKOS; > RON OKIMOTO; > JOHN S. WILKINS > =========================== > > THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A > HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT > THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD > TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY > FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep > people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS > SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That > is a myth, for people to believe in science." THRINAXODON PLANS TO > BRING DOOM TO SCIENCE, ITSELF. > > ============================ > > THRINAXODON IS NOW ON REDDIT > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jabba.laci at gmail.com Tue Mar 18 13:03:26 2014 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 18 Mar 2014 18:03:26 +0100 Subject: extract stream title from the output of mplayer Message-ID: Hi, I have a simple command-line radio player and I want to extract song titles from the output of mplayer. Example: $ mplayer http://relay2.slayradio.org:8000/ It produces a streamed output of this form: MPlayer2 UNKNOWN (C) 2000-2012 MPlayer Team mplayer: could not connect to socket mplayer: No such file or directory ... ICY Info: StreamTitle='Alexander 'Taxim' Nev - Unsound minds feat. SAM';StreamUrl='http://www.SLAYRadio.org/'; ... At the end it shows a progress indicator, thus the output is streamed. The problem is I can't get this output in a string. My idea is to launch mplayer with a timeout of 2 seconds for instance, get the produced output and find the line that starts with "ICY Info". But when I kill the process after the timeout, I don't know how to fetch the output produced so far. Thanks, Laszlo From harrismh777 at gmail.com Tue Mar 18 13:03:40 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 18 Mar 2014 12:03:40 -0500 Subject: Question about Source Control References: Message-ID: On 3/17/14 8:06 AM, Frank Millman wrote: > All my source code resides on an old Linux server, which I switch on in the > morning and switch off at night, but otherwise hardly ever look at. It uses > 'samba' to allow sharing with Windows, and 'nfs' to allow sharing with other > Linux machines. hi Frank, I am using GIT and code.google.com. https://code.google.com/p/pythondecimallibrary/ I have not used Code Google prior to the pdeclib project; however, I plan to use it in the future extensively, at least for my open source projects (and when I am thinking about bringing another person on board. Code Google permits three version|control|access systems (I use GIT, a very simple command line interface). The thing is that the code resides on a person's machine as a clone of the repository, and is assessable from anywhere in the world, allows multiple developer participation, allows multiple branches|merge|master, and allows access to the source on-line (browse|edit), and permits new members to clone the repository from anywhere. Downloads are zipped. The down-side is also the up-side. Code Google is an open source developer collaborative environment for sharing & managing. Anything you put there belongs to everyone in the project, and can be viewed by anyone in the world (which is kinda the point of open source). There is a supreme benefit to having multiple eyes on the code. People maybe not even involved in the project directly will comment on the code (and they are not shy). You code will improve dynamically and radically (if you have the guts for it). It took me a couple of hours to get up to speed with Code Google. It took another hour or so to come up to speed with GIT. You need to create the project on Code Google first. Then on your machine, in the code directory (the directory actually holding the source files that you are going to make a part of your project) you do these things: git init this builds the .git subdirectory needed for push git add file-name add each filename you want to commit and push git remove removes any unwanted files git commit -a edit your commit comments here , or provide default git push https://code.google.com/p/whateveryourprojectnameis/ master sends the files on their way other files: .gitconfig .netrc You will place your name, email, and method (use simple) in the .gitconfig file. The .netrc file will contain the login info for code google machine. Read the GIT manual on-line; its pretty easy too. https://www.kernel.org/pub/software/scm/git/docs/user-manual.html http://git-scm.com/documentation Cheers From rosuav at gmail.com Tue Mar 18 13:12:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Mar 2014 04:12:43 +1100 Subject: extract stream title from the output of mplayer In-Reply-To: References: Message-ID: On Wed, Mar 19, 2014 at 4:03 AM, Jabba Laci wrote: > I have a simple command-line radio player and I want to extract song > titles from the output of mplayer. > > ICY Info: StreamTitle='Alexander 'Taxim' Nev - Unsound minds feat. > SAM';StreamUrl='http://www.SLAYRadio.org/'; > > At the end it shows a progress indicator, thus the output is streamed. > The problem is I can't get this output in a string. My idea is to > launch mplayer with a timeout of 2 seconds for instance, get the > produced output and find the line that starts with "ICY Info". But > when I kill the process after the timeout, I don't know how to fetch > the output produced so far. My first recommendation would be to see what you can get directly, rather than calling on mplayer. But otherwise, what you want to do is redirect the output somewhere. Are you using the Python subprocess module to do this? You haven't shown any code, but since you posted this to python-list I'm guessing that you probably are talking about Python. (Or s/guess/hop/ if you prefer!) There are many ways this could be done; what have you tried, what partly worked, what did something unexpected? ChrisA From jabba.laci at gmail.com Tue Mar 18 13:51:31 2014 From: jabba.laci at gmail.com (Jabba Laci) Date: Tue, 18 Mar 2014 18:51:31 +0100 Subject: extract stream title from the output of mplayer In-Reply-To: References: Message-ID: > Python. (Or s/guess/hop/ if you prefer!) There are many ways this > could be done; what have you tried, what partly worked, what did > something unexpected? Hi, I managed to solve the problem. In the man of mplayer I found how to quit after X seconds: "-endpos X". See my solution below. Best, Laszlo ============ import re import shlex from subprocess import PIPE, Popen URL = 'http://relay2.slayradio.org:8000/' def get_exitcode_stdout_stderr(cmd): """ Execute the external command and get its exitcode, stdout and stderr. """ args = shlex.split(cmd) proc = Popen(args, stdout=PIPE, stderr=PIPE) out, err = proc.communicate() exitcode = proc.returncode # return exitcode, out, err def get_title(): cmd = "mplayer -endpos 1 -ao null {url}".format(url=URL) out = get_exitcode_stdout_stderr(cmd)[1] for line in out.split("\n"): # print(line) if line.startswith('ICY Info:'): match = re.search(r"StreamTitle='(.*)';StreamUrl=", line) title = match.group(1) return title def main(): print(get_title()) From drsalists at gmail.com Tue Mar 18 15:26:09 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 18 Mar 2014 12:26:09 -0700 Subject: Balanced trees In-Reply-To: <87mwgoqy4k.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 17, 2014 at 3:05 PM, Marko Rauhamaa wrote: > Joshua Landau : > >> The thing we really need is for the blist containers to become stdlib >> (but not to replace the current list implementation). > > Very interesting. Downloaded blist but didn't compile it yet. It *could* > be the missing link. > > I would *love* to see some comparative performance results between > blist.sorteddict and an AVL tree. I added blist.sorteddict and removed (temporarily) Pypy and Jython. The results are at http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/ In short, blist.sorteddict didn't do that well, despite being in C. In the random workloads, blist.sorteddict was dead last. In the sequential workloads blist.sorteddict fell somewhere in the middle. I excluded Pypy and Jython because blist.sorteddict probably doesn't run on them. HTH From ian.g.kelly at gmail.com Tue Mar 18 16:15:31 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 18 Mar 2014 14:15:31 -0600 Subject: Unexpected comparisons in dict lookup In-Reply-To: <53285617$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <53285617$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 18, 2014 at 8:20 AM, Steven D'Aprano wrote: > I stumbled across this unexpected behaviour with Python 2.7 and 3.3. When > you look up a key in a dict, the key is sometimes compared against other > keys twice instead of just once. >From what I can see in the code, it adds a perturbation based on the upper bits of the hash value to the probing scheme, to reduce collisions for keys with unequal hashes. On the downside, this cancels the guarantee that each bucket can only be checked at most once. The perturbation gradually shifts to 0 after a few iterations, so every bucket can still be reached within O(n) iterations. See the comments starting at "Major subtleties ahead": http://hg.python.org/cpython/file/f8b40d33e45d/Objects/dictobject.c#l106 From stutzbach at google.com Tue Mar 18 16:18:40 2014 From: stutzbach at google.com (Daniel Stutzbach) Date: Tue, 18 Mar 2014 13:18:40 -0700 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 18, 2014 at 12:26 PM, Dan Stromberg wrote: > In short, blist.sorteddict didn't do that well, despite being in C. > blist.blist is written in C, but blist.sorteddict is written in Python on top of blist.blist. It won't perform as well as a class written entirely in C that has similar asymptotic properties. If the objects in the tree are non-trivial (i.e., not a built-in type), the cost of calling the __lt__ method may be more important than the choice of blist vs. AVL tree, but I haven't tested it. -- Daniel Stutzbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From mitko.haralanov at intel.com Tue Mar 18 16:23:19 2014 From: mitko.haralanov at intel.com (Haralanov, Mitko) Date: Tue, 18 Mar 2014 20:23:19 +0000 Subject: Controlling buffer alignment in file.read() Message-ID: Hi all, I am using Python to read from a binary device file which requires that all read sizes are in 8byte multiples and the user's buffer is 8byte aligned. I am currently using a file object and the file.read() method. However, the issue is that the file.read() method allocates the buffer passed to C function under the covers and, therefore, the alignment is arbitrary. Is there a way that I can get file.read() to use an 8byte aligned buffer? Thanks, - Mitko From davea at davea.name Tue Mar 18 16:51:41 2014 From: davea at davea.name (Dave Angel) Date: Tue, 18 Mar 2014 16:51:41 -0400 (EDT) Subject: Question about Source Control References: <5327fc07$0$2923$c3e8da3$76491128@news.astraweb.com> <53284dee$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano Wrote in message: > On Tue, 18 Mar 2014 19:08:17 +1100, Chris Angelico wrote: > >> On Tue, Mar 18, 2014 at 6:55 PM, Steven D'Aprano >> wrote: >>> I don't think that *version* control is the right model to describe >>> what hg and git do, although it may be appropriate for subversion. hg >>> doesn't manage *versions*, it manages changes to source code >>> ("changesets"). >> >> Meh... Is there any real difference? > > If you believe Joel Spolsky, there is: > > http://hginit.com/00.html > > Scroll down about half way, to the section titled "One more big > conceptual difference". > > Recording *snapshots* versus recording *diffs* makes a considerable > difference when it comes to dealing with merge conflicts. > So which does git do, according to this model? -- DaveA From marko at pacujo.net Tue Mar 18 16:55:03 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 18 Mar 2014 22:55:03 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> Message-ID: <8738ifqlaw.fsf@elektro.pacujo.net> Dan Stromberg : > The results are at > http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/ Unfortunately I'm having a hard time understanding the results. The 50/50 get/set ratio is most interesting to me. I'm seeing (under cpython-3.3): Size: 1048576, duration: 75.3, dictionary type: dict [...] Size: 262144, duration: 66.1, dictionary type: AVL_tree [...] Size: 65536, duration: 77.3, dictionary type: blist.sorteddict What does it mean? Marko From klonuo at gmail.com Tue Mar 18 17:04:46 2014 From: klonuo at gmail.com (klo uo) Date: Tue, 18 Mar 2014 22:04:46 +0100 Subject: mobile friendly docs? Message-ID: Hi, let me quickly introduce my concern - I was happy to see main python.org portal rendered nicely on mobile, but docs are still hardly accessible, while sphinx allows better experience if user instructs it to. So I browsed Python MLs (sorry if this is not the right one, I'd be happy to forward my mail where you suggest) and wanted to ask if such concern is planed, as I can run Python from years ago on my Nokias, while feeling strange that official docs aren't accessible from mobile. TIA From drsalists at gmail.com Tue Mar 18 17:45:52 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 18 Mar 2014 14:45:52 -0700 Subject: Balanced trees In-Reply-To: <8738ifqlaw.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 18, 2014 at 1:55 PM, Marko Rauhamaa wrote: > Dan Stromberg : > >> The results are at >> http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/ > > Unfortunately I'm having a hard time understanding the results. > > The 50/50 get/set ratio is most interesting to me. > > I'm seeing (under cpython-3.3): > > > Size: 1048576, duration: 75.3, dictionary type: dict > [...] > Size: 262144, duration: 66.1, dictionary type: AVL_tree > [...] > Size: 65536, duration: 77.3, dictionary type: blist.sorteddict > > > What does it mean? dict was able to do 1048576 operations on a dictionary before taking more than 120 seconds to complete - it took 75.3 seconds to do 1048576 operations. AVL_tree was able to do 262144 operations on a dictionary before taking more than 120 seconds to complete - it took 66.1 seconds to do 262144 operations. blist.sorteddict was able to do 65536 operations on a dictionary before taking more than 120 seconds to complete - it took 77.3 seconds to do 65536 operations. For the 50/50 workload; the "operations" were half adding key, value pairs; and half lookups of values by keys we know are in the dictionary. I used to run all the dictionaries for as long as it took to do 4 million operations, but for (EG) unbalanced binary trees, that would take far too long in the ordered tests, so I changed the code to try a given tree type until the time for an operation became prohibitive. If you look at the graphs (I have to admit they've become a little cluttered), you can see the slower trees "escaping" rapidly (exceeding the 120 second threshold), while the better performing trees grow more slowly and are allowed to continue proving themselves longer. Inspecting these graphs may help in developing an intuition for how the tests were conducted. The code implementing this method of testing is in http://stromberg.dnsalias.org/svn/python-tree-and-heap-comparison/trunk/tester HTH From greg.ewing at canterbury.ac.nz Tue Mar 18 17:51:22 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 19 Mar 2014 10:51:22 +1300 Subject: Question about Source Control In-Reply-To: References: Message-ID: Frank Millman wrote: > These are the kind of stumbling blocks that prevented me from succeeding in > my previous attempt. I have a vague recollection that I set it up on machine > A, but then hit a problem because machines B and C both accessed the same > directory, but with different names For dealing with your practice of editing on one machine and running on another, you may be best off having just *one* local repository, residing on the shared file system. Whichever machine you're working on, you cd to the shared directory and use hg or git commands from there, so all the pathnames you're using are relative. Source control operations might be slightly slower that way, but you'd save time by not having to update your local repo every time you switch between editing and running, so it may well be faster overall. In any case, if the machines involved are on a fast local network, I wouldn't expect there to be much difference. -- Greg From marko at pacujo.net Tue Mar 18 18:03:59 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 19 Mar 2014 00:03:59 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> Message-ID: <87wqfrp3jk.fsf@elektro.pacujo.net> Dan Stromberg : > dict was able to do 1048576 operations on a dictionary before taking > more than 120 seconds to complete - it took 75.3 seconds to do 1048576 > operations. > > AVL_tree was able to do 262144 operations on a dictionary before > taking more than 120 seconds to complete - it took 66.1 seconds to do > 262144 operations. > > blist.sorteddict was able to do 65536 operations on a dictionary > before taking more than 120 seconds to complete - it took 77.3 seconds > to do 65536 operations. For a proper comparison, I'd like a fixed, identical dataset and set of operations run against each data structure. How about this test program: generate random datasets of 100, 10000, 1000000 and 100000000 elements generate random testset of 1000000 elements for each data structure: for each dataset: initialize data structure with dataset head, tail = testset[:100], testset[100:] t0 = current timestamp for each element in head: add element to data structure for each element in tail: add element to data structure append element to head remove head.pop(0) from data structure for each element in head: remove element from data structure t1 = current timestamp report data structure type, dataset size, t1 - t0 Marko From drsalists at gmail.com Tue Mar 18 18:21:28 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 18 Mar 2014 15:21:28 -0700 Subject: Balanced trees In-Reply-To: <87wqfrp3jk.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 18, 2014 at 3:03 PM, Marko Rauhamaa wrote: > Dan Stromberg : > For a proper comparison, I'd like a fixed, identical dataset and set of > operations run against each data structure. > > How about this test program: I used to do essentially this, but it was time-prohibitive and produced harder-to-read graphs - harder to read because the enormous values of the bad trees were dwarfing the values of the good trees. Imagine doing 100000000 operation tests for the unbalanced binary tree. For a series of random keys, it would do quite well (probably second only to dict), but for a series of sequential keys it would take longer than anyone would reasonably want to wait because it's basically a storage-inefficient linked list. Rather than throw out unbalanced binary tree altogether, it makes more sense to run it until it gets "too slow". The workload+interpreter pairs are all tested the same way, it's just that the ones that are doing badly are thrown out before they're able to get a lot worse. Studying the graphs will likely help develop an intuition for what's happening. From greg.ewing at canterbury.ac.nz Tue Mar 18 19:08:30 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 19 Mar 2014 12:08:30 +1300 Subject: Controlling buffer alignment in file.read() In-Reply-To: References: Message-ID: Haralanov, Mitko wrote: > I am using Python to read from a binary device file which requires that all > read sizes are in 8byte multiples and the user's buffer is 8byte aligned. > > Is there a way that I can get file.read() to use an 8byte aligned buffer? For control at that level you'd be better off using direct system calls, i.e. os.open() and os.read(), then you can read exacty the number of bytes you want. -- Greg From mitko.haralanov at intel.com Tue Mar 18 19:13:46 2014 From: mitko.haralanov at intel.com (Haralanov, Mitko) Date: Tue, 18 Mar 2014 23:13:46 +0000 Subject: Controlling buffer alignment in file.read() In-Reply-To: References: Message-ID: > For control at that level you'd be better off using > direct system calls, i.e. os.open() and os.read(), > then you can read exacty the number of bytes you want. > The problem is not controlling the number of bytes read. That part seems to be working. The issue is that the buffer into which the data is placed needs to be of certain alignment (8byte-aligned). Python does not seem to have a way that allows me to control that. Thanks, - Mitko From marko at pacujo.net Tue Mar 18 19:11:33 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 19 Mar 2014 01:11:33 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> Message-ID: <87r45zf6fu.fsf@elektro.pacujo.net> Dan Stromberg : > On Tue, Mar 18, 2014 at 3:03 PM, Marko Rauhamaa wrote: >> Dan Stromberg : >> For a proper comparison, I'd like a fixed, identical dataset and set >> of operations run against each data structure. >> >> How about this test program: > > I used to do essentially this, but it was time-prohibitive and > produced harder-to-read graphs - harder to read because the enormous > values of the bad trees were dwarfing the values of the good trees. > > Imagine doing 100000000 operation tests for the unbalanced binary > tree. For a series of random keys, it would do quite well (probably > second only to dict), but for a series of sequential keys it would > take longer than anyone would reasonably want to wait because it's > basically a storage-inefficient linked list. > > Rather than throw out unbalanced binary tree altogether, it makes more > sense to run it until it gets "too slow". I disagree strongly. You should throw out unbalanced binary trees and linked lists and the like and concentrate on solid contenders. But it's your test. You do as you like. Anyway, even a well-thought-out test is subject to all kinds of criticisms due to the CPU architecture, the distribution of the key values, the quality of the data structure implementation etc etc. Marko From greg.ewing at canterbury.ac.nz Tue Mar 18 20:07:12 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 19 Mar 2014 13:07:12 +1300 Subject: Controlling buffer alignment in file.read() In-Reply-To: References: Message-ID: Haralanov, Mitko wrote: > The problem is not controlling the number of bytes read. That part seems to > be working. The issue is that the buffer into which the data is placed needs > to be of certain alignment (8byte-aligned). Python does not seem to have a > way that allows me to control that. Hmmm, that could be tricky. Have you tried using os.read()? If you're lucky, Python will be using a malloc() call or equivalent to create a str/bytes object to read the data into, and that will return something platform-aligned. If you're unlucky, there's probably no pure-Python solution, and you might need to write a small C or Cython module to accomplish this trick. -- Greg From drsalists at gmail.com Tue Mar 18 21:01:59 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 18 Mar 2014 18:01:59 -0700 Subject: Controlling buffer alignment in file.read() In-Reply-To: References: Message-ID: On Tue, Mar 18, 2014 at 1:23 PM, Haralanov, Mitko wrote: > Hi all, > > I am using Python to read from a binary device file which requires that all read sizes are in 8byte multiples and the user's buffer is 8byte aligned. > > I am currently using a file object and the file.read() method. However, the issue is that the file.read() method allocates the buffer passed to C function under the covers and, therefore, the alignment is arbitrary. > > Is there a way that I can get file.read() to use an 8byte aligned buffer? This is a lot like what my odirect project does: http://stromberg.dnsalias.org/~strombrg/odirect/ It does buffer alignment, because O_DIRECT requires buffer alignment. It's a Python-callable SWIG wrapper for some C code. From ckaynor at zindagigames.com Tue Mar 18 21:02:11 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 18 Mar 2014 18:02:11 -0700 Subject: Balanced trees In-Reply-To: <8738ifqlaw.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> Message-ID: > > On Tue, Mar 18, 2014 at 1:55 PM, Marko Rauhamaa wrote: > Dan Stromberg : >> > The results are at >> > >> http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/ > > Size: 1048576, duration: 75.3, dictionary type: dict > [...] > Size: 262144, duration: 66.1, dictionary type: AVL_tree > [...] > Size: 65536, duration: 77.3, dictionary type: blist.sorteddict > Taking a quick look at this, I think it might be made much clearer if the number/second were added to the output. While it can be computed off the displayed data, it would make it much easier to compare in the table view by including it. Something like: Size: 1048576, duration: 75.3, dictionary type: 13925/second: dict Size: 262144, duration: 66.1, dictionary type: 3965/second: AVL_tree Size: 65536, duration: 77.3, dictionary type: 847/second: blist.sorteddict Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Mar 18 21:15:23 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2014 01:15:23 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> <87r45zf6fu.fsf@elektro.pacujo.net> Message-ID: <5328efab$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 19 Mar 2014 01:11:33 +0200, Marko Rauhamaa wrote: > Dan Stromberg : >> Rather than throw out unbalanced binary tree altogether, it makes more >> sense to run it until it gets "too slow". > > I disagree strongly. You should throw out unbalanced binary trees and > linked lists and the like and concentrate on solid contenders. If you are in a position to randomize the data before storing it in the tree, an unbalanced binary tree is a solid contender. The overhead will likely be much less than any balanced tree, and the probability of degenerate behaviour negligible for any amount of data big enough to really matter. -- Steven From steve+comp.lang.python at pearwood.info Tue Mar 18 21:15:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2014 01:15:53 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> Message-ID: <5328efc8$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 18 Mar 2014 15:21:28 -0700, Dan Stromberg wrote: > On Tue, Mar 18, 2014 at 3:03 PM, Marko Rauhamaa > wrote: >> Dan Stromberg : >> For a proper comparison, I'd like a fixed, identical dataset and set of >> operations run against each data structure. >> >> How about this test program: > > I used to do essentially this, but it was time-prohibitive and produced > harder-to-read graphs - harder to read because the enormous values of > the bad trees were dwarfing the values of the good trees. A log graph may be the solution to that: graph the log of the time rather than time itself. -- Steven From tjreedy at udel.edu Tue Mar 18 21:38:06 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 18 Mar 2014 21:38:06 -0400 Subject: Question about Source Control In-Reply-To: References: Message-ID: On 3/18/2014 5:51 PM, Gregory Ewing wrote: > Frank Millman wrote: >> These are the kind of stumbling blocks that prevented me from >> succeeding in my previous attempt. I have a vague recollection that I >> set it up on machine A, but then hit a problem because machines B and >> C both accessed the same directory, but with different names > > For dealing with your practice of editing on one machine and > running on another, you may be best off having just *one* local > repository, residing on the shared file system. Whichever machine > you're working on, you cd to the shared directory and use hg or > git commands from there, so all the pathnames you're using are > relative. At least with hg, one should best test the code in the working directory *before* committing to the local repository. The one local repository could still be a close of a master repository somewhere else. One can push multiple commits at once, either as the end of a work session or when one has done enough to become paranoid about losing work. -- Terry Jan Reedy From nathanjbruce at gmail.com Tue Mar 18 21:54:55 2014 From: nathanjbruce at gmail.com (Nathan Bruce) Date: Wed, 19 Mar 2014 12:54:55 +1100 Subject: No subject Message-ID: Hi I was wondering how much your oxycontins are for what mg and quantity. Also do you guys sell dilaudid? Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Tue Mar 18 22:12:35 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 18 Mar 2014 21:12:35 -0500 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140318211235.7be2bd4d@bigbox.christie.dr> On 2014-03-18 21:38, Terry Reedy wrote: > At least with hg, one should best test the code in the working > directory *before* committing to the local repository. I don't know if this is a hg-vs-git way of thinking, but I tend to frequently commit things on a private development branch regardless of brokenness, but once I get it working, I flatten & clean up those changes ("rebase" in git terms, which I believe has been adopted as a standardly-available-but-not-enabled-by-default module in hg) into logical units of change-sets that I then test individually before applying them to my more public-facing branch. This produces clean history that makes it easy for others to see what's going on. -tkc From rosuav at gmail.com Tue Mar 18 22:34:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Mar 2014 13:34:09 +1100 Subject: Question about Source Control In-Reply-To: <20140318211235.7be2bd4d@bigbox.christie.dr> References: <20140318211235.7be2bd4d@bigbox.christie.dr> Message-ID: On Wed, Mar 19, 2014 at 1:12 PM, Tim Chase wrote: > On 2014-03-18 21:38, Terry Reedy wrote: >> At least with hg, one should best test the code in the working >> directory *before* committing to the local repository. > > I don't know if this is a hg-vs-git way of thinking, but I tend to > frequently commit things on a private development branch regardless > of brokenness, but once I get it working, I flatten & clean up those > changes ("rebase" in git terms, which I believe has been adopted as a > standardly-available-but-not-enabled-by-default module in hg) into > logical units of change-sets that I then test individually before > applying them to my more public-facing branch. This produces clean > history that makes it easy for others to see what's going on. My approach to rebasing is derived from the accountancy concepts my Dad taught me. You create transactions, invoices, whatever, and you can freely edit them so long as they're the "current batch". It's very clear what the current batch is and where history begins. Then when you update that batch, it becomes history and is indelible; if you find an error in history, you put a new transaction through that updates it (or maybe reverses it completely, so you can then do a new clean transaction), which will have its own date (the date of the correction) and its own identity. [1] In git terms, that means commits above origin/master are freely editable, but as soon as anything's pushed, it's not to be changed. I violate that rule only very VERY occasionally, and only with the understanding that every clone of the repo will have to be manually updated. The "git rebase -i" command is perfect for this - it lets you rewrite anything that isn't pushed yet, by default. I made myself a hook script that helps with this; between that and the "autosquash" feature of git rebase interactive, it's easy to fiddle with unpushed changes. Let's say you discover a typo in an unpushed commit, and go and fix the corresponding file. As long as it's a one-file edit, and the most recent edit to that file is the commit you want to fix up, just type: $ git commit -amf or $ git commit some-file -mf and it'll make a fixup commit marked with that commit's message. Then: $ git rebase -i will notice that (if autosquash is enabled) and offer to squash the two commits together. In all cases, only unpushed commits are considered; everything from origin/master is untouchable. If anyone wants the script, I'm happy to share, though it is git-specific. Porting it to hg (does hg do hooks? I'm sure it must) is left as an exercise for the reader :) ChrisA [1] Linking this in with a previous thread on identity vs value: a transaction definitely has an identity, which may or may not be representable with some sort of database ID field. The identity might be something like "third row of the current batch" and nothing more, but it has one. From marwa.kotb98 at gmail.com Wed Mar 19 01:50:58 2014 From: marwa.kotb98 at gmail.com (marwa kotb) Date: Tue, 18 Mar 2014 22:50:58 -0700 (PDT) Subject: Greetings from Al-Madinah International University Message-ID: <79a274b0-ebc4-42bb-9a29-cede4a1db97b@googlegroups.com> Al Salam Alaykom w rahmat allah w barkato Dear : mr \ mrs We are pleased that on behalf of the Al-Madinah International University [MEDIU] greetings and best wishes for you continued success , coupled with the sincere invitations for your further success and development and growth. Al-Madinah International University [MEDIU] Malaysia: "University City World [MEDIU] Malaysia" is one of the leading universities of Malaysia, which is characterized by excellence and excellence of technical and higher education areas, and " Al-Madinah International University [MEDIU] " is a multiple cultures and areas of study and is based Malaysia Shah Alam , Here is a brief history. 1. " Al-Madinah International University [MEDIU]" founded early in 2004 in Medinah Almonowra 2. In 19 / July / 2006, the university received the invitation of the Malaysian Ministry of Higher Education for the establishment of the University Centre in Malaysia. 3. On 20 / July / 2007, the university obtained full license from the Ministry of Higher Education Malaysia to be the first international Malaysian University pursuing a systematic distance education using e-learning Targeting the Students from around the world. 4. In early of February of 2008 the university began full operation of reception of students. 5. joined the university for beginning of the year 2009, approximately [1500 ] students from different countries, while the number of applications submitted to the University of [3000] enrollment request. . 6. Early / 2009. University offered more than (24) academic program accredited by the Accreditation Authority and the Ministry of Higher Education (Malaysia), and more (34) accredited course in Arabic and English language center. . 7. Early 2009. Varied the levels of academic programs at the university to include foundation studies , Pre-university, diploma, bachelor's degree - graduate studies, language training courses. 8. Mid-2009. The number of students who were enrolled in the university more than (4701) students from more than 40 nationalities around the world. . 9. The third quarter of 2009. The Al-Madinah International University [MEDIU] Passed successfully institutional inspection held by the Malaysian Ministry of Higher Education to ensure quality of academic and administrative of the University. 10 . The end of 2009. The number of applications increased by the University of (6508) Application from more than (60) countries around the world, while the number of students enrolled in the University (2482 ) 11. The end of 2009.The university Completed the (10) new programs of study for approval by the Malaysian accreditation of Graduate Studies. 12. The end of 2009. The Al-Madinah International University [MEDIU] started the procedures to start the constituent university education in the disciplines of direct scientific and practical, including a new Computer Science, Finance and Administration, Engineering and intending to be started by mid-year 2010. 13. . Early in 2010. The number of students of the University increased to (3057) students from around the world, from the beginning of September 2010. 14. The end of 2010. The number of applications received the university for direct education on campus system around (511) applications and more than (154) enrollment students. 15. Early of 2011. The number of applications received by the university to direct education on campus system (2312) The number of enrollment students more than (362). . . 16. Early in 2011. Al-Madinah International University [MEDIU] inclusion Programs of the Al-Madinah International University [MEDIU] in full accreditation for four academic graduate programs in the Faculty of Islamic Sciences in the list of qualifications recognized by the Civil Service Commission, Malaysia 17. The end of 2011. The university the graduating first graduating batch of students from the Al-Medina International University in the master's programs, bachelor's and (84) students for the bachelor's degree, and (27) students for master's degree. What distinguishes the Al-Medinah International University [MEDIU]. First, high-technical and modern facilities: The technical infrastructure of the Al-Medinah International University is designed to match the best standards in the field of modern e-learning and distance education, including those of infrastructure following matters: Al-Medinah International University website on the Internet "www.mediu.edu.my": which offers all university services, which content admission, registration , inquiry , direct access to the lessons and communicate with lecturers and administrators staff of t the university. The electronic system of educational administration "Alim" for managing the academic affairs of the university, which can be both a student university lectures , administrators and supervisors to manage all the Process of study , direct communication, and dissemination the academic , exercise and lectures of subjects. The digital library comprehensive http://dlib.mediu.edu.my/ar/ which provide for the student and university lecturer the most types of works and textbooks. a center of excellence for customer service, and to which the student or lecturer or Enquirer from which to obtain any type of services available, and has the potential to provide rapid communication. * universality: as the administrative staff and faculty members of the university comes from many nationalities and cultures from around the world, providing the University a global spin and helps students to adapt quickly in the air school at the university Second, the various programs of study Accredited The university from the set foundations academy to provide programs of study in varied levels : foundation studies , pre-university, diploma, undergraduate and postgraduate up to PhD, in a number of scientific disciplines, including disciplines of Islamic Sciences , Arabic Language , Finance and Management, Computer Science, and Education, and Applied Science, is certified all courses at the university in advance and before it is put by the appropriations and specifications Academy of Malaysia under the Ministry of Higher Education of Malaysia and the universally recognized as known for short as [MQA], has got the university to recognize the academic programs of excellence in more than 90 study programs. "Al-Madinah International University," one of the first leading educational institutions in Malaysia in the field of higher education in a number of programs and disciplines that it has never in the field of e-learning. Third: (distance education (through the five faculties are distributed as follows: -. . 1. Faculty of Islamic Sciences 2. Faculty of Languages 3. College of Computer and Information Technology 4. Faculty of Finance and Administration 5. College of Education 6. College of Engineering 7. Language Center 8. Center for foundation Studies for the undergraduate Fourth, academic curriculum, the arbitrator: "International Al-Madinah University " keen From the beginning to control the academic curriculum of the programs of study, preparation and by Accredited and recognized to their knowledge, experience, and the University provide a full academic curriculum, the, recording audio, text, references and sources of study and divided by the lectures of study according to the academic calendar in advance to students enrolled thus contributing to raising their level of education, academic quality and achieve the target.. Fifth, the development of comprehensive programs for students: >From through the services offered by the "Al-Madinah International University [MEDIU]" of headquarter or centers of services its Its service centers in each of the (Kuwait - Saudi Arabia - Indonesia - Thailand - Egypt - Singapore - Malaysia - Britain - Morocco - Ghana), the university offered and provide scientific skills and educational as well as basic education-oriented experience within the unique environment and means of educational Saattabrha graduates of the university that it has changed the course of their lives. in addition to the administrative staff and the university's highest levels of academic qualification , and equipped with extensive experience in teaching methods and supervision, which provides the most appropriate opportunities for students to develop their skills through leadership of a diverse global community, and is the university students and provides them with multiple skills and capabilities, Kmharrat use of modern technology, and proficiency in different languages, skills , personal development , leadership skills, social activities and sports. Sixth: The tuition fees are reasonable: "Al-Madinah International University [MEDIU]" offers educated reasonable fee, where the tuition fees for diploma programs in Finance and Administration and Computer science (the equivalent of a bachelor's degree) is about [4000] U.S. dollars to the length of the study and that the range of about two and a half to three years, while the total of tuition fees in undergraduate programs in Islamic studies and Arabic language for the entire duration of the study, which about four years [6000] to [7000] USD U.S., the average tuition fees for post master's degree in Islamic studies and Arabic language, which two years duration [6000] U.S. dollars. thanks and appreciation to you for your perusal and hope of success Best Regards, Marketing Team of Al-Medinah International University From frank at chagford.com Wed Mar 19 02:41:35 2014 From: frank at chagford.com (Frank Millman) Date: Wed, 19 Mar 2014 08:41:35 +0200 Subject: Question about Source Control References: Message-ID: "Frank Millman" wrote in message news:lg6s09$irl$1 at ger.gmane.org... > Hi all > > I know I *should* be using a Source Control Management system, but at > present I am not. I tried to set up Mercurial a couple of years ago, but I > think I set it up wrongly, as I got myself confused and found it more of a > hindrance than a help. Now I am ready to try again, but I want to avoid my > earlier mistakes. > Many thanks to all for the responses. I have a much better feel for it now. If anything, I have moved from being confused because I did not understand it, to being confused because there are so many options I am not sure which to select. However, I consider this to be progress! I have decided to stick with Mercurial, simply because that is what I used in my previous attempt and I felt comfortable with it. Also I believe that Python itself uses it, so if it is good enough for them ... Before actually plunging in, I would like to summarise what I think I have understood, and what steps I propose to take. I realise now that my initial problem had nothing to do with SCM/VCS, and everything to do with my lack of knowledge of basic networking protocols. As I understand it now, if I want to share the repository over a network, I can choose between SSH and HTTP. I like the following quote from Joel Spolsky - "The quick-and-dirty way to make a central repository is to use Mercurial's built in web-server. ... I'm going to configure the server to allow anybody in the world to do anything they want to it. ... Needless to say, this is rather unsafe, but if you're on a nice protected LAN at work and there's a good firewall and you trust everybody on your LAN, this is reasonably OK." This describes my situation well, so to keep things simple I will start with this. To recap my basic setup, I have machine A which holds the source directory, machine B which is used to edit the program, and machines B and C which are both used to run the program. Initially, to prove that I understand the concept, I propose to install Mercurial on all three machines. Machine A will hold the central repository, which I will clone onto machines B and C. After editing on B, I will 'push' to A, and then from C 'pull' from A to get the latest version. If this works, I will simplify it to make my life easier. My first thought was to remove the clone from machine C and set up an nfs share pointing to the working directory on machine A, so I don't need the 'pull' step. Then I thought, why not just point to the working directory on machine B, so then I can test the changes on C directly, without even having to 'push'. I realise that this is defeating the object of version control, but I think it makes sense. I will still use version control to maintain a full history of the project on machine A. I appreciated Mark's comments about hosting his project on code.google.com - not just the mechanics, but the benefits that he experiences from sharing his code. I am actually getting closer to being able to do that with my project. Over the last few years I have frequently 'trashed' whole sections of my code and rewritten them, which I suspect would not endear me to someone attempting to collaborate with me. However, the broad framework is starting to settle down now, so I am starting to think about putting it out there. Then the question is which hosting service to use - there are so many of them. I will probably come back here for more advice when I get to that stage. Frank From rosuav at gmail.com Wed Mar 19 03:09:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Mar 2014 18:09:58 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: On Wed, Mar 19, 2014 at 5:41 PM, Frank Millman wrote: > I have decided to stick with Mercurial, simply because that is what I used > in my previous attempt and I felt comfortable with it. That's the best reason for choosing, really. https://github.com/Rosuav/Gypsum/commit/0f973 > Also I believe that > Python itself uses it, so if it is good enough for them ... Mercurial is used by a good number of high-profile projects. You're probably thinking of CPython, the implementation, but Python-the-language is built on top of Mercurial too, with such as the PEP repo and the web site (although I understand the latest version of the web site is managed in git). Both git and hg are used by plenty of solid projects, including the Linux kernel (git's original purpose), themselves (git's development is managed in git, hg's is managed in hg), and plenty of other big projects. This is one reason why I always push people to either of those two, rather than to an unknown or proprietary system that might have problems. > I realise now that my initial problem had nothing to do with SCM/VCS, and > everything to do with my lack of knowledge of basic networking protocols. As > I understand it now, if I want to share the repository over a network, I can > choose between SSH and HTTP. I like the following quote from Joel Spolsky - > > "The quick-and-dirty way to make a central repository is to use Mercurial's > built in web-server. ... I'm going to configure the server to allow anybody > in the world to do anything they want to it. ... Needless to say, this is > rather unsafe, but if you're on a nice protected LAN at work and there's a > good firewall and you trust everybody on your LAN, this is reasonably OK." > > This describes my situation well, so to keep things simple I will start with > this. Yep! People complain loudly about the insecurity of protocols like FTP, but properly-firewalled networks with all members trusted are more common than you might think - all you need is a basic home-grade NAT router and a sysadmin whose competence exceeds the sensitivity of your content. > To recap my basic setup, I have machine A which holds the source directory, > machine B which is used to edit the program, and machines B and C which are > both used to run the program. > > Initially, to prove that I understand the concept, I propose to install > Mercurial on all three machines. Machine A will hold the central repository, > which I will clone onto machines B and C. After editing on B, I will 'push' > to A, and then from C 'pull' from A to get the latest version. Right. That's a nice standard setup. There'll be plenty of tutorials that can walk you through setting that up. (Don't forget, btw, that most Linux distributions will include Mercurial - just "apt-get install mercurial" or "yum install mercurial".) > If this works, I will simplify it to make my life easier. My first thought > was to remove the clone from machine C and set up an nfs share pointing to > the working directory on machine A, so I don't need the 'pull' step. Then I > thought, why not just point to the working directory on machine B, so then I > can test the changes on C directly, without even having to 'push'. I realise > that this is defeating the object of version control, but I think it makes > sense. I will still use version control to maintain a full history of the > project on machine A. It doesn't defeat the object of version control as long as you always make logical, conceptual commits. However, it does introduce a dependency (the NFS share) and the associated messes of file locking and so on, so I personally would prefer to deploy a file-transfer system, maybe like the one I described earlier, or maybe something more like FTP. But do whatever makes sense for you. > Over the last few years I have frequently 'trashed' whole sections > of my code and rewritten them, which I suspect would not endear me to > someone attempting to collaborate with me. However, the broad framework is > starting to settle down now, so I am starting to think about putting it out > there. That's not in itself a problem. This commit made quite a few changes, all at once: https://github.com/Rosuav/Gypsum/commit/0f973 It does mean that anyone who's collaborating with you will need to keep a close eye on what goes on, but that's true of any fast-moving project. As things get more stable, it'll be easier to join in. ChrisA From wxjmfauth at gmail.com Wed Mar 19 03:30:55 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 19 Mar 2014 00:30:55 -0700 (PDT) Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> Message-ID: <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> z = a + b*i with a, b, elements of R z = r*exp(i*phi) with r, phi, elements of R z = [[a, -b], [b, a]] with a, b, elements of R This is, in my mind, more questionable: >>> complex(2, 1+1j) (1+1j) >>> >>> print(complex.__doc__) complex(real[, imag]) -> complex number Create a complex number from a real part and an optional imaginary part. This is equivalent to (real + imag*1j) where imag defaults to 0. jmf From marko at pacujo.net Wed Mar 19 04:49:33 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 19 Mar 2014 10:49:33 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> <87r45zf6fu.fsf@elektro.pacujo.net> <5328efab$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87pplipo82.fsf@elektro.pacujo.net> Steven D'Aprano : > If you are in a position to randomize the data before storing it in > the tree, an unbalanced binary tree is a solid contender. Applications that can assume randomly distributed data are exceedingly rare and even then, you can't easily discount the possibility of worst-case ordering. In fact, Dan himself said unbalanced trees performed so badly he couldn't test them satisfactorily. Marko From marko at pacujo.net Wed Mar 19 04:51:20 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 19 Mar 2014 10:51:20 +0200 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> Message-ID: <87lhw6po53.fsf@elektro.pacujo.net> wxjmfauth at gmail.com: > This is, in my mind, more questionable: > >>>> complex(2, 1+1j) > (1+1j) I find it neat, actually. Marko From murukessanap at gmail.com Wed Mar 19 04:55:26 2014 From: murukessanap at gmail.com (muru kessan) Date: Wed, 19 Mar 2014 14:25:26 +0530 Subject: unable to import rlcompleter readline Message-ID: hi guys, i want the python interactive shell to be auto complete and i found that by adding the following lines in PYTHONSTARTUP file it is possible import rlcompleter, readline readline.parse_and_bind('tab: complete') but i get the following error in git bash shell Note: i run windows8 as Operating System Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win 32 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "C:\muru work 05-nov-2013\python\start.py", line 6, in import rlcompleter, readline ImportError: No module named readline Any help would be appreciated Thanks, muru -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Wed Mar 19 05:30:02 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 19 Mar 2014 09:30:02 +0000 Subject: unable to import rlcompleter readline In-Reply-To: References: Message-ID: <5329639A.4090503@timgolden.me.uk> On 19/03/2014 08:55, muru kessan wrote: > hi guys, > i want the python interactive shell to be auto complete and i found that > by adding the following lines in PYTHONSTARTUP file it is possible > > import rlcompleter, readline > readline.parse_and_bind('tab: complete') > > but i get the following error in git bash shell > Note: i run windows8 as Operating System > > Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit > (AMD64)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. > Traceback (most recent call last): > File "C:\muru work 05-nov-2013\python\start.py", line 6, in > import rlcompleter, readline > ImportError: No module named readline readline is commonly provided on *nix systems, but not on Windows. You can install a plug-compatible version here: https://pypi.python.org/pypi/pyreadline/2.0 (ie pip install pyreadline) or just use IPython which project maintains it: http://ipython.org/ NB installing pyreadline will override the way in which Python interacts with the standard Windows console's up/down/history recall features. (Assuming it hasn't changed since I last used it a few years ago). TJG From wxjmfauth at gmail.com Wed Mar 19 05:52:56 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 19 Mar 2014 02:52:56 -0700 (PDT) Subject: 'complex' function with string argument. In-Reply-To: <87lhw6po53.fsf@elektro.pacujo.net> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> <87lhw6po53.fsf@elektro.pacujo.net> Message-ID: Le mercredi 19 mars 2014 09:51:20 UTC+1, Marko Rauhamaa a ?crit?: > wxjmfauth at gmail.com: > > > > > This is, in my mind, more questionable: > > > > > >>>> complex(2, 1+1j) > > > (1+1j) > > > > I find it neat, actually. > > > > > > Marko >>> # tricky: yes, neat: no >>> complex(1+1j, 2) (1+3j) >>> From marko at pacujo.net Wed Mar 19 06:09:06 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 19 Mar 2014 12:09:06 +0200 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> <87lhw6po53.fsf@elektro.pacujo.net> Message-ID: <87bnx233gd.fsf@elektro.pacujo.net> wxjmfauth at gmail.com: > Le mercredi 19 mars 2014 09:51:20 UTC+1, Marko Rauhamaa a ?crit?: >> wxjmfauth at gmail.com: >> >>>> complex(2, 1+1j) >> > (1+1j) >> >> I find it neat, actually. > >>>> # tricky: yes, neat: no >>>> complex(1+1j, 2) > (1+3j) So complex(a, b) is documented to produce a+bj when a and b are integers or floats. What's more natural than saying it produces a+bj when a and b are complex numbers? It's a straightforward generalization that in no way violates the more limited documentation. Marko From thrinaxodon.jm at bitch.invalid Wed Mar 19 06:22:23 2014 From: thrinaxodon.jm at bitch.invalid (THRINAXODON JM) Date: Wed, 19 Mar 2014 06:22:23 -0400 Subject: PNYIKOS DOWN AND UNDER! Message-ID: ======================= >BREAKING NEWSSSSSSSSS ======================= > RICHARD LEAKEY JUST DIED DUE TO HEART FAILURE! > THE REASONS DESCRIBED BY THE MEDICAL TEAM IS THAT HIS WORK WAS DISPROVEN, BY NONE OTHER THAN YOUR OWN BASTARD, THRINAXODON. > THIS CAUSED LEAKEY'S HEART TO EXPLODE! > THRINAXODON DANCED WITH JOY AS HE WAS GRANTED $600,000,000,000.000! > TO WASTE YOUR TIME EVEN FURTHER, CHECK OUT THESE LINKS BELOW. =========================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa d/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/threa d/3aad75c16afb0b82# ============================== ====== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON REDDIT -- ---Thrinaxodon From ian.g.kelly at gmail.com Wed Mar 19 06:33:34 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 19 Mar 2014 04:33:34 -0600 Subject: 'complex' function with string argument. In-Reply-To: <87bnx233gd.fsf@elektro.pacujo.net> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> <87lhw6po53.fsf@elektro.pacujo.net> <87bnx233gd.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 19, 2014 at 4:09 AM, Marko Rauhamaa wrote: > wxjmfauth at gmail.com: > >> Le mercredi 19 mars 2014 09:51:20 UTC+1, Marko Rauhamaa a ?crit : >>> wxjmfauth at gmail.com: >>> >>>> complex(2, 1+1j) >>> > (1+1j) >>> >>> I find it neat, actually. >> >>>>> # tricky: yes, neat: no >>>>> complex(1+1j, 2) >> (1+3j) > > So complex(a, b) is documented to produce a+bj when a and b are integers > or floats. What's more natural than saying it produces a+bj when a and b > are complex numbers? It's a straightforward generalization that in no > way violates the more limited documentation. When is it ever useful though? I only see a use for passing a as complex if b is omitted, and I don't see any use for passing b as complex. If there's no use case, then it's just a confusing edge case that will catch unsuspecting programmers who thought the data they were passing in was real-valued when actually it wasn't. It would be better to raise an exception in either of the cases above, in my opinion. If you really want to form a complex a+bj from two other complex numbers, there is always the explicit (a + b * 1j). That said, complex numbers have been around since 1.4 or so, and there's probably not much chance to change it now. From marko at pacujo.net Wed Mar 19 06:53:00 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 19 Mar 2014 12:53:00 +0200 Subject: 'complex' function with string argument. References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> <87lhw6po53.fsf@elektro.pacujo.net> <87bnx233gd.fsf@elektro.pacujo.net> Message-ID: <877g7q31f7.fsf@elektro.pacujo.net> Ian Kelly : > On Wed, Mar 19, 2014 at 4:09 AM, Marko Rauhamaa wrote: >> So complex(a, b) is documented to produce a+bj when a and b are integers >> or floats. What's more natural than saying it produces a+bj when a and b >> are complex numbers? It's a straightforward generalization that in no >> way violates the more limited documentation. > > When is it ever useful though? [...] It would be better to raise an > exception in either of the cases above, in my opinion. I don't think it matters one way or another. Medieval mathematicians had to address an analogous issue when they had to decide if x + 0 was meaningful. After all, adding nothing doesn't make any sense and should raise a ValueError exception... Marko From skip at pobox.com Wed Mar 19 07:04:06 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 19 Mar 2014 06:04:06 -0500 Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> <87lhw6po53.fsf@elektro.pacujo.net> <87bnx233gd.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 19, 2014 at 5:33 AM, Ian Kelly wrote: > When is it ever useful though? About as often as int(0), float(0), or float(0.0) which all work as expected, though probably don't turn up in a lot of code. Skip From vinay_sajip at yahoo.co.uk Wed Mar 19 09:13:38 2014 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 19 Mar 2014 13:13:38 +0000 (GMT) Subject: [ANN]: distlib 0.1.8 released on PyPI Message-ID: <1395234818.65024.YahooMailNeo@web172401.mail.ir2.yahoo.com> I've released version 0.1.8 of distlib on PyPI [1]. For newcomers, distlib is a library of packaging functionality which is intended to be?usable as the basis for third-party packaging tools. The main changes in this release are as follows: * Fixed issue #45: Improved thread-safety in SimpleScrapingLocator. *?Fixed issue #42: Handling of pre-release legacy version numbers ? now mirrors setuptools logic. * Added exists, verify, update, is_compatible and is_mountable methods ? to?the Wheel class (the update method fixed issue #41). * Added a search method to the PackageIndex class. * Fixed a bug in the Metadata.add_requirements method. *?Allowed versions with a single numeric component and a local version ? component (tracking changes to PEP 440).* Corrected spelling of environment variable used for the stub launcher ? on OS X. *?Avoided using pydist.json in 1.0 wheels (bdist_wheel writes a non- ? conforming pydist.json). * Improved computation of ABI tags on Python versions where SOABI is not ? available, and improved computation of compatibility tags on OS X to ? allow for multiple architectures and older OS X versions. A more detailed change log is available at [2]. Please try it out, and if you find any problems or have any suggestions for?improvements, please give some feedback using the issue tracker! [3] Regards, Vinay Sajip [1] https://pypi.python.org/pypi/distlib/0.1.8? [2] http://pythonhosted.org/distlib/overview.html#change-log-for-distlib? [3] https://bitbucket.org/pypa/distlib/issues/new From diccon.tesson at gmail.com Wed Mar 19 09:11:48 2014 From: diccon.tesson at gmail.com (diccon.tesson at gmail.com) Date: Wed, 19 Mar 2014 06:11:48 -0700 (PDT) Subject: Printing characters outside of the ASCII range In-Reply-To: <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> References: <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> Message-ID: Your handling Pick Multi value fields aren't you ;) Just hit the same issue, thanks all here for various solutions. Interfacing with OpenQM / Scarlet DME here. From steve+comp.lang.python at pearwood.info Wed Mar 19 09:42:04 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2014 13:42:04 GMT Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> <87r45zf6fu.fsf@elektro.pacujo.net> <5328efab$0$29994$c3e8da3$5496439d@news.astraweb.com> <87pplipo82.fsf@elektro.pacujo.net> Message-ID: <53299eac$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 19 Mar 2014 10:49:33 +0200, Marko Rauhamaa wrote: > Steven D'Aprano : > >> If you are in a position to randomize the data before storing it in the >> tree, an unbalanced binary tree is a solid contender. > > Applications that can assume randomly distributed data are exceedingly > rare Please re-read what I wrote. I didn't say "if your data comes to you fully randomized". I said "if you are in a position to randomize the data before storing it". In other words, if you actively randomize the data yourself. > and even then, you can't easily discount the possibility of > worst-case ordering. Of course you can. If you have a million items, then the odds that those million items happen to be sorted (the worst-case order) are 1 in a million factorial. That's a rather small number, small enough that we can discount it from ever happening, not in a million lifetimes of the Universe. Of course, you would be right to point out that one would also like to avoid *nearly* worst-case ordering. Nevertheless, there are Vastly more ways that the data will be sufficiently randomized as to avoid degenerate performance than the worst-case poor performance. > In fact, Dan himself said unbalanced trees performed so badly he > couldn't test them satisfactorily. You're misrepresenting what Dan said. What he actually said was that unbalanced trees perform second only to dicts with random data, only with sorted data do they perform badly. His exact words were: "For a series of random keys, it would do quite well (probably second only to dict), but for a series of sequential keys it would take longer than anyone would reasonably want to wait" -- Steven D'Aprano http://import-that.dreamwidth.org/ From marko at pacujo.net Wed Mar 19 09:54:40 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 19 Mar 2014 15:54:40 +0200 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> <87r45zf6fu.fsf@elektro.pacujo.net> <5328efab$0$29994$c3e8da3$5496439d@news.astraweb.com> <87pplipo82.fsf@elektro.pacujo.net> <53299eac$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87siqe1efz.fsf@elektro.pacujo.net> Steven D'Aprano : > Please re-read what I wrote. I didn't say "if your data comes to you > fully randomized". I said "if you are in a position to randomize the > data before storing it". In other words, if you actively randomize the > data yourself. Yes, you could implement a "hash table" that way. Marko From roy at panix.com Wed Mar 19 10:06:29 2014 From: roy at panix.com (Roy Smith) Date: Wed, 19 Mar 2014 10:06:29 -0400 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> <87r45zf6fu.fsf@elektro.pacujo.net> <5328efab$0$29994$c3e8da3$5496439d@news.astraweb.com> <87pplipo82.fsf@elektro.pacujo.net> <53299eac$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <53299eac$0$29994$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > If you have a million items, then the odds that those > million items happen to be sorted (the worst-case order) are 1 in a > million factorial. That's a rather small number, small enough that we can > discount it from ever happening, not in a million lifetimes of the > Universe. If the items are coming from some inherently random process, then I agree. But, not all data sources are random. Imagine you had a web site, and wanted to store various bits of data from the stream of input requests. You decided that the data structure you were going to use was a balanced tree. If your keys were, say, a hash of the client's IP address, then it's a pretty good guess they're random. But, what if the keys were the time the request was received? Those are obviously not random, and using them as a keys in a balanced tree would give you sub-optimum performance. This is not a hypothetical scenario. Songza uses MongoDB as our database. The indexes are balanced trees. One of our biggest collections has a multi-component key, one of the components being the request time truncated to the hour. Insertion time into that collection has an obvious sawtooth shape, with performance degrading as each hour progresses and jumping back up as the time rolls over to the next hour. This is due (we believe :-)) to the constant rebalancing of the index trees. Almost-sorted data sets are very common. For example, here's a pipeline I run a lot (from memory, could have gotten some detail wrong): grep pattern lofgile | awk '{print $7}' | sed 's/:[0-9][0-9]$//' | sort | uniq -c Field 7 is the timestamp for when a request came in. What I'm doing here is counting how many requests of a certain type came in during each minute of the day. Logging isn't exactly in chronological order, so I need to sort the times before I count them. But, it's in *almost* chronological order; a sort which had pathologically bad behavior on almost sorted data would be unusable here. From breamoreboy at yahoo.co.uk Wed Mar 19 10:19:14 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 19 Mar 2014 14:19:14 +0000 Subject: Printing characters outside of the ASCII range In-Reply-To: References: <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> Message-ID: On 19/03/2014 13:11, diccon.tesson at gmail.com wrote: > Your handling Pick Multi value fields aren't you ;) > Just hit the same issue, thanks all here for various solutions. > Interfacing with OpenQM / Scarlet DME here. > The context is conspicious by its absence. In future would you please be kind enough to provide some. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From wxjmfauth at gmail.com Wed Mar 19 10:35:06 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 19 Mar 2014 07:35:06 -0700 (PDT) Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> <87lhw6po53.fsf@elektro.pacujo.net> <87bnx233gd.fsf@elektro.pacujo.net> Message-ID: <4021d887-0673-42a3-816d-74bc8755a082@googlegroups.com> Le mercredi 19 mars 2014 12:04:06 UTC+1, Skip Montanaro a ?crit?: > On Wed, Mar 19, 2014 at 5:33 AM, Ian Kelly wrote: > > > When is it ever useful though? > > > > About as often as int(0), float(0), or float(0.0) which all work as > > expected, though probably don't turn up in a lot of code. > > > > Skip Your comment is equivalent to this: >>> complex(1+2.0j) (1+2j) >>> complex(0+0.0j) 0j Both, the constructor and the docstring, are not so clean. What to say about the __repr__ ? Are not a and b supposed to be floats? (elements of R) >>> 0 0 >>> 0.0 0.0 >>> 0j 0j >>> 1.0 + 2.0j (1+2j) >>> 1. 1.0 >>> 1 1 >>> (1 + 2.0j).real 1.0 >>> type((1 + 2.0j).real) jmf From zachary.ware+pylist at gmail.com Wed Mar 19 10:43:30 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 19 Mar 2014 09:43:30 -0500 Subject: Printing characters outside of the ASCII range In-Reply-To: References: <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> Message-ID: On 19/03/2014 13:11, diccon.tesson at gmail.com wrote: > Your handling Pick Multi value fields aren't you ;) > Just hit the same issue, thanks all here for various solutions. > Interfacing with OpenQM / Scarlet DME here. For future posts, please be sure to quote what you're replying to. Google Groups makes things easy to find and reply to, but this is a mailing list. When we receive a mail with just a subject line and a cryptic message, we're likely to think it spam and ignore future mail from that sender. It's also a bit less than ideal to reply to years old threads. On Wed, Mar 19, 2014 at 9:19 AM, Mark Lawrence wrote: > The context is conspicious by its absence. In future would you please be > kind enough to provide some. In a fit of curiosity, I went looking: https://mail.python.org/pipermail/python-list/2012-November/634803.html I'm almost surprised it wasn't any older than that :) Ironically, on my way down the November 2012 archive page, I noticed a long thread about "Obnoxious postings from Google Groups". -- Zach From breamoreboy at yahoo.co.uk Wed Mar 19 11:14:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 19 Mar 2014 15:14:20 +0000 Subject: Printing characters outside of the ASCII range In-Reply-To: References: <3d4644f8-ab88-41c5-9a52-2a5678dd64c0@googlegroups.com> Message-ID: On 19/03/2014 14:43, Zachary Ware wrote: > Ironically, on my way down the November 2012 archive page, I noticed a > long thread about "Obnoxious postings from Google Groups". > Thankfully the number of grotty postings from gg has dropped considerably. Sadly our resident unicode expert quite deliberately continues to use it in a manner which is designed to annoy. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ethan at stoneleaf.us Wed Mar 19 11:15:49 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 19 Mar 2014 08:15:49 -0700 Subject: Balanced trees In-Reply-To: <5328efc8$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> <87wqfrp3jk.fsf@elektro.pacujo.net> <5328efc8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5329B4A5.1030206@stoneleaf.us> On 03/18/2014 06:15 PM, Steven D'Aprano wrote: > On Tue, 18 Mar 2014 15:21:28 -0700, Dan Stromberg wrote: > >> On Tue, Mar 18, 2014 at 3:03 PM, Marko Rauhamaa >> wrote: >>> Dan Stromberg : >>> For a proper comparison, I'd like a fixed, identical dataset and set of >>> operations run against each data structure. >>> >>> How about this test program: >> >> I used to do essentially this, but it was time-prohibitive and produced >> harder-to-read graphs - harder to read because the enormous values of >> the bad trees were dwarfing the values of the good trees. > > A log graph may be the solution to that: graph the log of the time rather > than time itself. I don't think that will solve the problem of not wanting to wait three days for the test to finish. ;) -- ~Ethan~ From nikolaus.fleischhacker at gmail.com Wed Mar 19 05:27:14 2014 From: nikolaus.fleischhacker at gmail.com (audiowerk) Date: Wed, 19 Mar 2014 02:27:14 -0700 (PDT) Subject: Kivy contest 2014 In-Reply-To: References: Message-ID: Hi! Is there already a date when the theme will be announced? Am Sonntag, 16. M?rz 2014 18:42:16 UTC+1 schrieb qua-non: > > Hi folks, > > Kivy will be holding it's programming contest for 2014 starting April 15th. > > For details please visit http://kivy.org/#contest > > If you are interested in sponsoring the contest, please contact us at > con... at kivy.org . > > > [image: Inline image 1] > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Mar 19 14:45:06 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 19 Mar 2014 12:45:06 -0600 Subject: 'complex' function with string argument. In-Reply-To: References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> <87lhw6po53.fsf@elektro.pacujo.net> <87bnx233gd.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 19, 2014 at 5:04 AM, Skip Montanaro wrote: > On Wed, Mar 19, 2014 at 5:33 AM, Ian Kelly wrote: >> When is it ever useful though? > > About as often as int(0), float(0), or float(0.0) which all work as > expected, though probably don't turn up in a lot of code. The analogous call to those is complex(1+2j), which I have no problem with, not complex(1+2j, 3+4j). From ian.g.kelly at gmail.com Wed Mar 19 15:35:05 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 19 Mar 2014 13:35:05 -0600 Subject: 'complex' function with string argument. In-Reply-To: <877g7q31f7.fsf@elektro.pacujo.net> References: <8c862bec-815e-424c-81e2-8f37ebab1c35@googlegroups.com> <5327d112$0$2923$c3e8da3$76491128@news.astraweb.com> <11b58171-a99b-4ddf-8e6c-7b4f3169c60c@googlegroups.com> <87lhw6po53.fsf@elektro.pacujo.net> <87bnx233gd.fsf@elektro.pacujo.net> <877g7q31f7.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 19, 2014 at 4:53 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Wed, Mar 19, 2014 at 4:09 AM, Marko Rauhamaa wrote: >>> So complex(a, b) is documented to produce a+bj when a and b are integers >>> or floats. What's more natural than saying it produces a+bj when a and b >>> are complex numbers? It's a straightforward generalization that in no >>> way violates the more limited documentation. >> >> When is it ever useful though? [...] It would be better to raise an >> exception in either of the cases above, in my opinion. > > I don't think it matters one way or another. > > Medieval mathematicians had to address an analogous issue when they had > to decide if > > x + 0 > > was meaningful. After all, adding nothing doesn't make any sense and > should raise a ValueError exception... I wasn't aware that algebra had ValueErrors. Describing an operation as "undefined" isn't the same thing. Anyway, if mathematicians discover that the definitions of the past were flawed or incomplete, then they redefine them. Case in point, if we were still using Brahmagupta's rules for zero, then 0/0 would be 0. Python though has backward compatibility to worry about. Because of this, it is much simpler to add wanted behavior than to remove unwanted behavior. If an operation can be generalized but the generalization has no apparent use case, it *may* be better to disallow it, with the possibility of adding it later when a user pops up and says "Hey, this would actually be useful to me", than to allow it from the beginning, and then have no option to remove it later when it turns out to be merely a nuisance. Compare for example the 2-argument int constructor. Normally this is meant to be called like int("42", 13), where it will interpret the digits passed as base 13 and return 54. We might generalize that and say that if the user passes int(42, 13), it should also return 54, seeing that the repr of 42 provides the digits "42". It is more likely though that this call merely indicates a bug in the user's code, and fortunately in this case what Python actually does is to raise a TypeError. Anyway, curious though this tangent is, further discussion is unlikely to produce any useful outcome, so I'll just leave it there. From alexanderjohntaylor at gmail.com Wed Mar 19 17:33:15 2014 From: alexanderjohntaylor at gmail.com (Alexander Taylor) Date: Wed, 19 Mar 2014 14:33:15 -0700 (PDT) Subject: Kivy contest 2014 In-Reply-To: References: Message-ID: <7178e6e0-ad32-4cc0-b4a1-47a587fb5f69@googlegroups.com> The theme will be announced when the contest officially starts, the 15th April. On Wednesday, 19 March 2014 09:27:14 UTC, audiowerk wrote: > > Hi! > > Is there already a date when the theme will be announced? > > Am Sonntag, 16. M?rz 2014 18:42:16 UTC+1 schrieb qua-non: >> >> Hi folks, >> >> Kivy will be holding it's programming contest for 2014 starting April >> 15th. >> >> For details please visit http://kivy.org/#contest >> >> If you are interested in sponsoring the contest, please contact us at >> con... at kivy.org. >> >> >> [image: Inline image 1] >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From abhishek1899 at gmail.com Wed Mar 19 18:05:31 2014 From: abhishek1899 at gmail.com (Peace) Date: Wed, 19 Mar 2014 15:05:31 -0700 (PDT) Subject: Problem with pickle and restarting a program Message-ID: In my GUI, the user enters two values: cellNumber(Integer) and SerialNumber(String) I have the following piece of code in my view/controller: ####################The following function is called after the user enters the cellnumber and serial number############## def ListenForDetails(status): cellNumber = status[0] SerialNumber = status[1] ModelInfo().CellList[cellNumber].receiveSerialNumber(SerialNumber) ------------------In my controller thread----------------- class Controller(Thread): def __init__(self): Thread.__init__(self) self.start() def run(self): global SynchronizationVariable while SynchronizationVariable != 1: time.sleep(0.01) while 1: StateChanged = False for cells in ModelInfo().CellList: rc = cells.PollCells() if rc == 0: StateChanged = True if StateChanged: ModelInfo().save() time.sleep(1) -------------------------------In my model.py script------------------------------------- class CellInfo(): #This class encapsulates all the information present in a cell def __init__(self,cellNo): self.SerialNo = "" self.cellNo = cellNo def receiveSerialNumber(self, SerialNumber): self.SerialNo = SerialNumber def PollCells(self): RC = self.StateMachine[self.CurrentState](self) return RC ...all state machine functions here... """Model Info below""" class ModelInfo(): #This class creates a list of cells. def __init__(self): print("Setting up a list of cells to iterate on") self.CellList = [] #List of all the cell Objects for index in xrange(0,24): print(self.CellList) self.CellList.append(CellInfo(index)) def save(self): with open("RestoreInfo.p", "wb") as f: pickle.dump(self,f) Model = ModelInfo() #Constructs an empty model """IN MAIN (In the controller script)""" if __name__ == '__main__': if os.path.isfile( "RestoreInfo.p" ): with open("RestoreInfo.p", "rb") as f: model = pickle.load( f ); else: model = model.ModelInfo(); The serial number field always remains empty even though I enter from the GUI and the receiveSerialNumber function is called and I explicitly initialize it to the variable in the model. I'm trying to save the state of the program so that next time I open the application it resumes from where it left off. The problem is when I restart the application, the serial number is empty. What am I doing wrong here? Whenever I get a change in state (the RC value), I pickle and save to a file (restoreinfo.p). When I restart the application, the serial number is no longer there even though I enter it. Could you please let me know what is going wrong? Thank you. From goswami.anjan at gmail.com Wed Mar 19 19:03:09 2014 From: goswami.anjan at gmail.com (goswami.anjan at gmail.com) Date: Wed, 19 Mar 2014 16:03:09 -0700 (PDT) Subject: Problem in fetching blob or clob data with python and cx_oracle Message-ID: It seems that when I attempt to download blob or clob data using fetchmany, it can not keep track of the LOB variable in subsequent fetch. The problem is over if I fetch one row at a time but it is not optimal. Can anyone give me an idea how to efficiently fetch columns with clob or blob data from oracle DB using python. Thank you, Anjan From rhodri at wildebst.org.uk Wed Mar 19 22:16:50 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 20 Mar 2014 02:16:50 -0000 Subject: Balanced trees References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> Message-ID: On Tue, 18 Mar 2014 21:45:52 -0000, Dan Stromberg wrote: > blist.sorteddict was able to do 65536 operations on a dictionary > before taking more than 120 seconds to complete - it took 77.3 > seconds to do 65536 operations. 65536 is a suspiciously round number. You might want to double- check that there's no 16-bit overflow causing something unexpected. -- Rhodri James *-* Wildebeest Herder to the Masses From drsalists at gmail.com Wed Mar 19 22:34:43 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 19 Mar 2014 19:34:43 -0700 Subject: Balanced trees In-Reply-To: References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87mwgoqy4k.fsf@elektro.pacujo.net> <8738ifqlaw.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 19, 2014 at 7:16 PM, Rhodri James wrote: > 65536 is a suspiciously round number. You might want to double- > check that there's no 16-bit overflow causing something unexpected. It's because I'm using powers of 2. All the numbers in the report are round in hex. From wtz_wh at foxmail.com Thu Mar 20 01:51:41 2014 From: wtz_wh at foxmail.com (=?gb18030?B?sbGx+dHz?=) Date: Thu, 20 Mar 2014 13:51:41 +0800 Subject: [Python-Dev] Issues about relative& absolute import way for Portingfrom python2.4 to python2.7 Message-ID: Dear, I just wrote a sample like this: testPy/ __init__.py client.py SoamFactory.c SoamFactory.so soamapi.py sample/testP.py export PYTHONPATH=$(TEST_LOCATION):$(TEST_LOCATION)/testPy Here's the source codes: __init__.py: import client client.py import soamapi class Client(soamapi.SessionCallback): def __init__(self): print "----class Client----" super(Client, self).__init__() soamapi.initialize() def create_session(self): sec_cb = soamapi.DefaultSecurityCallback() self.connection = soamapi.connect(sec_cb) soamapi.py import SoamFactory class ConnectionSecurityCallback(object): def __init__(self): print "----class ConnectionSecurityCallback----" def __del__(self): pass def test_P(self): print "test_P in class ConnectionSecurityCallback" class DefaultSecurityCallback(ConnectionSecurityCallback): def __init__(self): super(DefaultSecurityCallback, self).__init__() print "----class DefaultSecurityCallback----" def __del__(self): super(DefaultSecurityCallback, self).__del__() def test(self): print "test in class DefaultSecurityCallback" class SessionCallback(object): def __init__(self): pass def __del__(self): pass def connect(security_callback): return SoamFactory.SoamFactory_connect(security_callback) def initialize(): SoamFactory.SoamFactory_initialize() print "call soamapi" SoamFactory.c #include "Python.h" #include "PythonLoop.c" PyObject* SOAM_API_MODULE = NULL; PyObject* pyModule = NULL; static PyObject* SoamFactory_initialize(PyObject* self, PyObject* args){ PyEval_InitThreads(); init(); Py_RETURN_NONE; } static PyObject* SoamFactory_connect(PyObject* self, PyObject* args){ PyObject* pySecCallback = NULL; int ok = PyArg_ParseTuple(args, "O", &pySecCallback); if (!ok){ printf("parse tuple error!\n"); Py_RETURN_NONE; } if (! PyObject_IsInstance(pySecCallback, connectSecCallback)){ printf("pySecCallback is not an instance of ConnectionSecurityCallback!\n"); Py_RETURN_NONE; } printf("Successful!\n"); Py_RETURN_NONE; } static PyMethodDef SoamFactory[] = { {"SoamFactory_connect", SoamFactory_connect, METH_VARARGS, "connection function"}, {"SoamFactory_initialize", SoamFactory_initialize, METH_VARARGS, "SoamFactory_initialize"}, {NULL, NULL} }; void initSoamFactory(){ PyEval_InitThreads(); Py_Initialize(); pyModule = Py_InitModule("SoamFactory", SoamFactory); SOAM_API_MODULE = PyImport_ImportModule("soamapi"); } sample/testP.py import testPy print "========================================" submitter = testPy.client.Client() submitter.create_session() print "========================================" When I ran it on python2.4, it worked well, and the result was call soamapi after import soamapi------client.py ======================================== ----class Client---- ----class ConnectionSecurityCallback---- ----class DefaultSecurityCallback---- Successful! ======================================== But when I ran it on python2.7, it worked beyond my expectation, the result was call soamapi call soamapi ======================================== ----class Client---- ----class ConnectionSecurityCallback---- ----class DefaultSecurityCallback---- pySecCallback is not an instance of ConnectionSecurityCallback! ======================================== I found that soamapi was imported twice, and I investigated this is related to absolute&relative import way. PyImport_ImportModule in python2.7 uses absolute import way, it will look up sys.path to get soamapi module, and when testP.py file import testPy module, it will find local module soamapi under testPy package, and binds module's name to package, as testPy.soamapi. There are two ways to correct it for python2.7, 1) Don't use import testPy, use import client directly to avoid using relative; 2) Use from __future__ import absolute_import to enable absolute import feature. But there are two Pre-conditions: 1) Should not modify testP.py; 2) Should be ran on both python2.4 and 2.7. I don't know how to fix it. Is there any official way about how to porting this scenario or better idea? Thanks, Vatel -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at chagford.com Thu Mar 20 02:48:22 2014 From: frank at chagford.com (Frank Millman) Date: Thu, 20 Mar 2014 08:48:22 +0200 Subject: Question about Source Control References: Message-ID: "Frank Millman" wrote in message news:lgbe6g$j9o$1 at ger.gmane.org... > > > To recap my basic setup, I have machine A which holds the source > directory, machine B which is used to edit the program, and machines B and > C which are both used to run the program. > > Initially, to prove that I understand the concept, I propose to install > Mercurial on all three machines. Machine A will hold the central > repository, which I will clone onto machines B and C. After editing on B, > I will 'push' to A, and then from C 'pull' from A to get the latest > version. > Ok, I did that, and it worked. I think I may be on the path to enlightenment. One thing still confuses me. Over the lifetime of a project, there could be many thousands of changesets. Some of those could be tagged as 'major releases'. Someone wishing to clone the project from scratch may want to start from the latest major release, and not download every changeset since the project started. How is this handled in practice? Thanks Frank From rosuav at gmail.com Thu Mar 20 03:15:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 20 Mar 2014 18:15:25 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: On Thu, Mar 20, 2014 at 5:48 PM, Frank Millman wrote: > One thing still confuses me. Over the lifetime of a project, there could be > many thousands of changesets. Some of those could be tagged as 'major > releases'. Someone wishing to clone the project from scratch may want to > start from the latest major release, and not download every changeset since > the project started. > > How is this handled in practice? There are several ways, but the most common is to simply tag a revision along the way; Pike does this, and I do the same in Gypsum. Pike 7.8.700 is commit 1ace5c: http://pike-git.lysator.liu.se/gitweb.cgi?p=pike.git;a=commit;h=1ace5c8e7c5c14fcaeeefd307b1ec99b80560311 Gypsum 1.1.0 is commit d937bf: https://github.com/Rosuav/Gypsum/tree/v1.1.0 You can then offer a non-source-control means of downloading that specific revision. Github does this for me automatically: https://github.com/Rosuav/Gypsum/archive/v1.1.0.zip Pike goes further and publishes binaries for various systems, too, and the source archive isn't quite a pure snapshot of git at that point (it has some intermediate files so as to reduce dependencies), but the effect is the same - if you want to get Pike 7.8.700, you don't need all the changes: http://pike.lysator.liu.se/download/pub/pike/latest-stable/ Python also snapshots like that, but with a much more complicated history than either of the above; the Python download pages offer you source tarballs and compiled binaries. If you want to find version 3.3.1 in source control, just look that up in the .hgtags file, which says that "v3.3.1" is d9893d. (I'm not familiar with hg-web, so I can't provide a link. But it's effectively the same as I showed above.) ChrisA From __peter__ at web.de Thu Mar 20 03:21:03 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 20 Mar 2014 08:21:03 +0100 Subject: [Python-Dev] Issues about relative& absolute import way for Portingfrom python2.4 to python2.7 References: Message-ID: ??? wrote: > I just wrote a sample like this: > testPy/ > __init__.py > client.py > SoamFactory.c > SoamFactory.so > soamapi.py > sample/testP.py > export PYTHONPATH=$(TEST_LOCATION):$(TEST_LOCATION)/testPy > I found that soamapi was imported twice, and I investigated this is > I don't know how to fix it. Is there any official way about how to porting > this scenario or better idea? Without looking into the details -- I believe that your problem stems from having a path into the package: > export PYTHONPATH=$(TEST_LOCATION):$(TEST_LOCATION)/testPy The above means that a module testPy.foo can also successfully be imported as foo. Try changing the path to export PYTHONPATH=$(TEST_LOCATION) If you get failing imports change every failing import import foo to from testPy import foo From dieter at handshake.de Thu Mar 20 04:20:03 2014 From: dieter at handshake.de (dieter) Date: Thu, 20 Mar 2014 09:20:03 +0100 Subject: Problem with pickle and restarting a program References: Message-ID: <8738idjn7w.fsf@handshake.de> Peace writes: > ... > The serial number field always remains empty even though I enter from the GUI and the receiveSerialNumber function is called and I explicitly initialize it to the variable in the model. > I'm trying to save the state of the program so that next time I open the application it resumes from where it left off. The problem is when I restart the application, the serial number is empty. What am I doing wrong here? Whenever I get a change in state (the RC value), I pickle and save to a file (restoreinfo.p). When I restart the application, the serial number is no longer there even though I enter it. Could you please let me know what is going wrong? Thank you. You may want to use debugging to determine what goes on in detail. There are commercial debuggers with a graphical user interface (maybe even free ones). Python comes with a simple command line debugger ("pdb"). From murukessanap at gmail.com Thu Mar 20 05:19:55 2014 From: murukessanap at gmail.com (muru kessan) Date: Thu, 20 Mar 2014 14:49:55 +0530 Subject: Decorator Message-ID: Hi guys, Is there a difference between accessing decorators via '@' symbol and hard coding that ? esp when the function passed to the decorator is a recursive one? See attachments result from deco_with@ is 1 1 0 1 1 0 1 1 0 result from deco_without@ is 1 1 2 3 5 8 13 21 34 1 1 0 3 5 0 13 21 0 Thanks , muru -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- #------------------------------------------------------------------------------- # Name: module1 # Purpose: # # Author: Ratna # # Created: 20/03/2014 # Copyright: (c) Ratna 2014 # Licence: #------------------------------------------------------------------------------- import math def isOddMy(func): def innerOdd(x): y = func(x) if math.fmod(y, 2) == 0 : return 0 else: if y is not None: return y else: return 0 return innerOdd @isOddMy def fib(n): #print n, if n == 0 : return 0 elif n == 1 : return 1 else: return fib(n-2) + fib(n-1) def main(): #oddFibi = isOdd(fib) #print [i for i in oddFibi(100)] for i in range(1,10): print fib(i), '''print fib1 = isOddMy(fib) for i in range(1,10): print fib1(i),''' if __name__ == '__main__': main() -------------- next part -------------- #------------------------------------------------------------------------------- # Name: module1 # Purpose: # # Author: Ratna # # Created: 20/03/2014 # Copyright: (c) Ratna 2014 # Licence: #------------------------------------------------------------------------------- import math def isOddMy(func): def innerOdd(x): y = func(x) if math.fmod(y, 2) == 0 : return 0 else: if y is not None: return y else: return 0 return innerOdd #@isOddMy def fib(n): #print n, if n == 0 : return 0 elif n == 1 : return 1 else: return fib(n-2) + fib(n-1) def main(): #oddFibi = isOdd(fib) #print [i for i in oddFibi(100)] for i in range(1,10): print fib(i), print fib1 = isOddMy(fib) for i in range(1,10): print fib1(i), if __name__ == '__main__': main() From __peter__ at web.de Thu Mar 20 05:59:35 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 20 Mar 2014 10:59:35 +0100 Subject: Decorator References: Message-ID: muru kessan wrote: > Is there a difference between accessing decorators via '@' symbol and > hard coding that ? esp when the function passed to the decorator is a > recursive one? The difference is not the decorator but the recursive function call. Consider Case 1: @deco def f(): ... f() # calls the decorated function ... f() Case 2: def f() ... f() # calls the undecorated function ... g = deco(f) g() The function call f() will invoke whatever the global name f is bound to a the time of invocation. So Case 3: def f() ... f() # calls the decorated function ... f = deco(f) f() In your code change fib1 = isOddMy(fib) to fib = isOddMy(fib) and the without@ version will produce the same output as the with@ version. From davea at davea.name Thu Mar 20 07:00:44 2014 From: davea at davea.name (Dave Angel) Date: Thu, 20 Mar 2014 07:00:44 -0400 (EDT) Subject: Decorator References: Message-ID: Peter Otten <__peter__ at web.de> Wrote in message: > > In your code change > > fib1 = isOddMy(fib) > > to > > fib = isOddMy(fib) > > and the without@ version will produce the same output as the with@ version. > > I expect that one more thing is needed, since the above is inside a function: global fib fib = isOdd (fib) -- DaveA From fabiofz at gmail.com Thu Mar 20 08:01:50 2014 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 20 Mar 2014 09:01:50 -0300 Subject: PyDev 3.4.1 Released Message-ID: What is PyDev? --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? --------------------------- LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming and a number of other languages such as Django Templates, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://brainwy.github.io/liclipse/ Release Highlights: ------------------------------- - **Important**: PyDev requires Eclipse 3.8 or 4.3 onwards and Java 7! For older versions, keep using PyDev 2.x (or LiClipse for a PyDev standalone with all requirements bundled). - **Interactive Console**: * **Send a single line to the interactive console with F2** (akin to Ctrl+Alt+Enter but only for the current line). - **Debugger**: * **Added support for debugging spawned subprocesses.** * New Django launches no longer have -noreload to take advantage of that (but existing launches have to be manually edited -- or removed and recreated). * When terminating a process its subprocesses are also killed (avoiding django zombie processes). * In the debugger, locals are now also properly saved on PyPy (requires a newer version of PyPy too). * Remote Debugger: when specifying items in PATHS_FROM_ECLIPSE_TO_PYTHON pathnames are normalized. * Fixes to work with Jython 2.1 and Jython 2.2.1 * Always setting PYTHONUNBUFFERED environment variable to 1. * The python default encoding is no longer changed (only PYTHONIOENCODING is used now and not sys.setdefaultencoding). * Minor improvements on get referrers. - **General**: * **Cython: .pxd and .pxi files are properly supported.** * Interpreter configuration: It's possible to reorder PYTHONPATH entries with drag and drop. * Fixed django interactive shell to work with newer versions of Django. * Rename working properly for files without extensions. * Fixed issue where specifying the type of a variable with a comment was not detected in the code-completion. * Fixed issue where we'd open a file as if it was an external file when it was actually a file in the workspace or inside a source folder. * PyDev Package Explorer: fixed issue where some errors would remain showing when they didn't exist anymore. * PyDev Package Explorer: fixed issue where items could change its order depending on decorations. * On a double-click on spaces, all the spaces are selected. - **Test Runner**: * **Improved py.test integration**: it's now possible to select which tests to run with Ctrl+F9 (even if not under a class). * No longer breaks if a file which was in a launch config is removed (still runs other tests in the launch). * After a test run finishes, if there are non-daemon threads running they're printed to the output. * Fixed UnicodeDecodeError when running unit-tests under python 2.x * Fixed issue on test discovery on Linux. - **Sorting Imports**: * Sort of imports no longer adds spaces at end of imports. * Sort of imports no longer passes the number of available columns specified. * It's now also possible to keep the names of 'from' imports sorted. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer LiClipse http://brainwy.github.io/liclipse PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Mar 20 09:04:33 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 20 Mar 2014 14:04:33 +0100 Subject: Decorator References: Message-ID: Dave Angel wrote: > Peter Otten <__peter__ at web.de> Wrote in message: > >> >> In your code change >> >> fib1 = isOddMy(fib) >> >> to >> >> fib = isOddMy(fib) >> >> and the without@ version will produce the same output as the with@ >> version. >> >> > > I expect that one more thing is needed, since the above is inside > a function: > > global fib > fib = isOdd (fib) Yes, sorry, I missed that. From ishish at domhain.de Thu Mar 20 09:11:44 2014 From: ishish at domhain.de (ishish) Date: Thu, 20 Mar 2014 13:11:44 +0000 Subject: Dictionaries In-Reply-To: References: Message-ID: Hi, This might sound weird, but is there a limit how many dictionaries a can create/use in a single script? My reason for asking is I split a 2-column-csv (phone#, ref#) file into a dict and am trying to put duplicated phone numbers with different ref numbers into new dictionaries. The script deducts the duplicated 46 numbers but it only creates batch1.csv. Since I obviously can't see the wood for the trees here, can someone pls punch me into the right direction.... ...(No has_key is fine, its python 2.7) f = open("file.csv", 'r') myDict = {} Batch1 = {} Batch2 = {} Batch3 = {} for line in f: if line.startswith('Number' ): print "First line ignored..." else: k, v = line.split(',') myDict[k] = v f.close() for k, v in myDict.items(): if Batch1.has_key(k): if k in Batch2.has_key(k): Batch3[k] = v else: Batch2[k] = v else: Batch1[k] = v for k, v in Batch1.items(): newLine = "%s,%s" % (k, v) with open("batch1.csv", "a") as f: f.write(newLine) for k, v in Batch2.items(): newLine = "%s,%s" % (k, v) with open("batch2.csv", "a") as f: f.write(newLine) for k, v in Batch3.items(): newLine = "%s,%s" % (k, v) with open("batch3.csv", "a") as f: f.write(newLine) From __peter__ at web.de Thu Mar 20 10:08:31 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 20 Mar 2014 15:08:31 +0100 Subject: Dictionaries References: Message-ID: ishish wrote: > This might sound weird, but is there a limit how many dictionaries a > can create/use in a single script? No. > My reason for asking is I split a 2-column-csv (phone#, ref#) file into > a dict and am trying to put duplicated phone numbers with different ref > numbers into new dictionaries. The script deducts the duplicated 46 > numbers but it only creates batch1.csv. Since I obviously can't see the > wood for the trees here, can someone pls punch me into the right > direction.... > ...(No has_key is fine, its python 2.7) > > f = open("file.csv", 'r') Consider a csv with the lines Number... 123,first 123,second 456,third > myDict = {} > Batch1 = {} > Batch2 = {} > Batch3 = {} > > for line in f: > if line.startswith('Number' ): > print "First line ignored..." > else: > k, v = line.split(',') > myDict[k] = v the first time around the assignment is myDict["123"] = "first\n" the second time it is myDict["123"] = "second\n" i. e. you are overwriting the previous value and only keep the value corresponding to the last occurrence of a key. A good approach to solve the problem of keeping an arbitrary number of values per key is to make the dict value a list: myDict = {} with open("data.csv") as f: next(f) # skip first line for line in f: k, v = line.split(",") myDict.setdefault(k, []).append(v) This will produce a myDict { "123": ["first\n", "second\n"], "456": ["third\n"] } You can then proceed to find out the number of batches: num_batches = max(len(v) for v in myDict.values()) Now write the files: for index in range(num_batches): with open("batch%s.csv" % (index+1), "w") as f: for key, values in myDict.items(): if len(values) > index: # there are more than index duplicates f.write("%s,%s" % (key, values[index])) From gordon at panix.com Thu Mar 20 10:19:50 2014 From: gordon at panix.com (John Gordon) Date: Thu, 20 Mar 2014 14:19:50 +0000 (UTC) Subject: Dictionaries References: Message-ID: In ishish writes: > The script [...] only creates batch1.csv. If the script only creates batch1.csv, that means Batch2 and Batch3 must be empty. > for k, v in myDict.items(): > if Batch1.has_key(k): > if k in Batch2.has_key(k): > Batch3[k] = v > else: > Batch2[k] = v > else: > Batch1[k] = v 'if k in Batch2.has_key(k):' is a very strange line of code. In fact, it should produce a syntax error if it were ever executed, because the 'in' keyword requires an iterable as the second part, and has_key() returns only True or False. Therefore, I would say that line of code never executes, which means that the preceding 'if Batch1.has_key(k)' statement always evaluates to False. Which therefore means that Batch2 and Batch3 never accumulate any items, matching your observed output. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From davea at davea.name Thu Mar 20 10:44:32 2014 From: davea at davea.name (Dave Angel) Date: Thu, 20 Mar 2014 10:44:32 -0400 (EDT) Subject: Dictionaries References: Message-ID: Please don't leave new questions in an existing thread, and especially without changing subject line. Compose a new message with meaningful subject line. ishish Wrote in message: > Hi, > > This might sound weird, but is there a limit how many dictionaries a > can create/use in a single script? No, unless you run out of RAM. > > My reason for asking is I split a 2-column-csv (phone#, ref#) file into > a dict and am trying to put duplicated phone numbers with different ref > numbers into new dictionaries. The script deducts the duplicated 46 > numbers but it only creates batch1.csv. Since I obviously can't see the > wood for the trees here, can someone pls punch me into the right > direction.... > ...(No has_key is fine, its python 2.7) But has_key is deprecated, and you're using it wrong anyway. > > f = open("file.csv", 'r') > > myDict = {} > Batch1 = {} > Batch2 = {} > Batch3 = {} > > for line in f: > if line.startswith('Number' ): > print "First line ignored..." > else: > k, v = line.split(',') > myDict[k] = v > f.close() > > for k, v in myDict.items(): > if Batch1.has_key(k): > if k in Batch2.has_key(k): I'm surprised this doesn't throw an exception. has_key returns a bool, and in isn't meaningful on a bool. Just use if k in Batch2: > Batch3[k] = v > else: > Batch2[k] = v > else: > Batch1[k] = v > > for k, v in Batch1.items(): > newLine = "%s,%s" % (k, v) > with open("batch1.csv", "a") as f: This is unusual, and a performance killer, to repeatedly open the file. But you may have some reason. > f.write(newLine) There's no newline there, so your csv is going to be one long line. You probably want newLine+'\n' inside those parens. > > for k, v in Batch2.items(): > newLine = "%s,%s" % (k, v) > with open("batch2.csv", "a") as f: > f.write(newLine) > > for k, v in Batch3.items(): > newLine = "%s,%s" % (k, v) > with open("batch3.csv", "a") as f: > f.write(newLine) > -- DaveA From notbob at nothome.com Thu Mar 20 10:58:54 2014 From: notbob at nothome.com (notbob) Date: 20 Mar 2014 14:58:54 GMT Subject: running python 2 vs 3 Message-ID: Dumb noob questions: I've installed python 3.3 on my Slack box, which by default comes with python 2.7. I know how to fire up the different IDLE environments, but how do I differentiate between the scripts? IOW, up till now, I've used .py on all my 2.7 files. How do I know not to run a .py in python3 or visa versa? Or do I? What's the excepted convention for differentiating between the two? nb From ishish at domhain.de Thu Mar 20 10:15:57 2014 From: ishish at domhain.de (ishish) Date: Thu, 20 Mar 2014 14:15:57 +0000 Subject: Dictionaries In-Reply-To: References: Message-ID: Thanks Peter for the fast response, but the prob is solved. My colleague just verbally slapped me because a dict SHOULDN'T have duplicate keys... I change it around to duplicate values and it works fine.... I think I need coffee now... lots of it. From marko at pacujo.net Thu Mar 20 11:21:42 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 17:21:42 +0200 Subject: running python 2 vs 3 References: Message-ID: <87ob10nbeh.fsf@elektro.pacujo.net> notbob : > I've installed python 3.3 on my Slack box, which by default comes with > python 2.7. I know how to fire up the different IDLE environments, but > how do I differentiate between the scripts? IOW, up till now, I've > used .py on all my 2.7 files. How do I know not to run a .py in > python3 or visa versa? Or do I? What's the excepted convention for > differentiating between the two? That's a bit of a sore spot. On a linux box, the initial line of the script indicates the interpreter: #!/usr/bin/env python2 for Python 2.x #!/usr/bin/env python3 for Python 3.x. All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. Marko From notbob at nothome.com Thu Mar 20 12:00:07 2014 From: notbob at nothome.com (notbob) Date: 20 Mar 2014 16:00:07 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On 2014-03-20, Marko Rauhamaa wrote: > That's a bit of a sore spot. > > On a linux box, the initial line of the script indicates the > interpreter: > > #!/usr/bin/env python2 > > for Python 2.x > > #!/usr/bin/env python3 > > for Python 3.x. > > All tutorials will tell you to start it with > > #!/usr/bin/env python > > which will start python2 on all (?) existing linux distros, but is > expected to start python3 within the next decade. Ahhh! ....now a shabang I understand. So, I guess the only way, short of looking at the actual file, is to include the version in the filename. Can I safely assume I can run all 2.7 files w/o a shebang (which I have not, so far, and was wondering how I got away with that) and only include a py3 shebang in the py3 files, yes/no? nb From harrismh777 at gmail.com Thu Mar 20 12:11:28 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 20 Mar 2014 11:11:28 -0500 Subject: running python 2 vs 3 References: Message-ID: On 3/20/14 9:58 AM, notbob wrote: > I've installed python 3.3 on my Slack box, which by default comes with > python 2.7. I know how to fire up the different IDLE environments, > but how do I differentiate between the scripts? hi notbob, the two (or more) IDLE environments run very nicely side-by-side. If you access your scripts from the same directory (I do not) there really is no problem. The reason is that the .pyc files created for python2.x are only used by python2. The .pyc files for python3.x are kept (by a naming convention) in __pycache__ , so there really is no problem. Having said that, the only problem is that your script for python3 might not run in python2 (for various reasons) but the problem is not that the scripts are contained in the same folder. I keep my python2 scripts in one folder ~/Documents/Python2/ and my python3 scripts in another one ~/Documents/Python3/ I add the two folders in the python paths browser (using site-packages) so that when I start IDLE for python2 it pulls its scripts from ~/Documents/Python2/ and when I start IDLE for python3 it pulls its scripts from ~/Documents/Python3/ There are *many* ways to organize this. Often I have to maintain two scripts (packages) one for each version. Although, I try to make my scripts run in both environments. Often I have IDLE(2) ane IDLE(3) running and testing at the same time on the same box. This works very well. marcus From zachary.ware+pylist at gmail.com Thu Mar 20 12:14:54 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 20 Mar 2014 11:14:54 -0500 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 20, 2014 at 11:00 AM, notbob wrote: > Ahhh! ....now a shabang I understand. So, I guess the only way, short > of looking at the actual file, is to include the version in the > filename. Can I safely assume I can run all 2.7 files w/o a shebang > (which I have not, so far, and was wondering how I got away with that) > and only include a py3 shebang in the py3 files, yes/no? If I understand your question: you're probably better off putting a shebang line in all of the files that you intend to run directly. Use "/usr/bin/env python2" for your Python 2 scripts, "/usr/bin/env python3" for your Python 3 scripts, and "/usr/bin/env python" for scripts that can run under either interpreter. You can also be more version-specific if you need to; use "python2.7", "python3.3", etc. as necessary. That way, you can invoke the script directly and the right interpreter will run it. If you're specifying the interpreter in your command (by calling "python .py", etc), the shebang won't mean anything anyway. -- Zach From notbob at nothome.com Thu Mar 20 13:10:42 2014 From: notbob at nothome.com (notbob) Date: 20 Mar 2014 17:10:42 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On 2014-03-20, Zachary Ware wrote: > If you're specifying the interpreter in your command (by calling > "python .py", etc), the shebang won't mean anything > anyway. DOH! I was following you, fine, until that last sentence. Then how should I invoke the scripts? ....as your example is exactly how I've been doing it with 2.7, as per Learn Python the Hard Way. Simply ./.py from the appropriate directory (assuming I keep both vers in separate dirs)? nb From notbob at nothome.com Thu Mar 20 13:23:24 2014 From: notbob at nothome.com (notbob) Date: 20 Mar 2014 17:23:24 GMT Subject: running python 2 vs 3 References: Message-ID: On 2014-03-20, Mark H Harris wrote: > not) there really is no problem. The reason is that the .pyc files > created for python2.x are only used by python2. Lordy, what hath I wrought!? ;) What the heck is a .pyc file and how are they created? Actually, I can see it's a compiled binary, but I where did it come from? I went back to my ~/python/ dir and noticed one .pyc file out of 15 .py files I created from following Learning Python the Hard Way. No one said anything about creating a binary. I know I discovered how to create/edit python scripts from IDLE. Is that it? I've been using gedit and emacs up till now. Seems the file with the .pyc file is the one I edited in IDLE. Is that why LPtHW eschews IDLE for gedit? Why do I feel like I've really stepped in it? ;) nb From rosuav at gmail.com Thu Mar 20 13:29:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 04:29:54 +1100 Subject: running python 2 vs 3 In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 4:23 AM, notbob wrote: > On 2014-03-20, Mark H Harris wrote: > >> not) there really is no problem. The reason is that the .pyc files >> created for python2.x are only used by python2. > > Lordy, what hath I wrought!? ;) > > What the heck is a .pyc file and how are they created? Actually, I > can see it's a compiled binary, but I where did it come from? > > I went back to my ~/python/ dir and noticed one .pyc file out of 15 > .py files I created from following Learning Python the Hard Way. No > one said anything about creating a binary. I know I discovered how to > create/edit python scripts from IDLE. Is that it? I've been using > gedit and emacs up till now. Seems the file with the .pyc file is the > one I edited in IDLE. Is that why LPtHW eschews IDLE for gedit? > > Why do I feel like I've really stepped in it? ;) > You should be able to completely ignore .pyc files, most of the time. The only thing to remember is that you should delete them any time you delete the corresponding .py files. They're a cached version that Python will use to speed up imports, nothing more. Nowadays they'll be pushed away into a separate directory, which makes them easier for you to ignore. This is a good thing. ChrisA From rosuav at gmail.com Thu Mar 20 13:30:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 04:30:58 +1100 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 21, 2014 at 4:10 AM, notbob wrote: > On 2014-03-20, Zachary Ware wrote: > >> If you're specifying the interpreter in your command (by calling >> "python .py", etc), the shebang won't mean anything >> anyway. > > DOH! > > I was following you, fine, until that last sentence. Then how should > I invoke the scripts? ....as your example is exactly how I've been > doing it with 2.7, as per Learn Python the Hard Way. Simply > ./.py from the appropriate directory (assuming I keep both > vers in separate dirs)? That's a fine way to do it. Zachary is mentioning an alternative, and showing that the shebang doesn't hurt (it's a comment to Python), so go ahead and put the shebang in all your scripts. ChrisA From harrismh777 at gmail.com Thu Mar 20 13:42:05 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 20 Mar 2014 12:42:05 -0500 Subject: running python 2 vs 3 References: Message-ID: On 3/20/14 12:23 PM, notbob wrote: > What the heck is a .pyc file and how are they created? Actually, I > can see it's a compiled binary, but I where did it come from? The world according to me: python is an interpreter (vs compiler) which converts your source code into tokens and then into a bytecode. The process takes time. So, the solution is to place the tokenized stuff into a .pyc file so that the process does not have to be repeated unless, of course, the source has changed since the last .pyc file create. It used to be that the .pyc files went into the same dir as the source (that's how it works for python2) but now with python3 they go into a directory in your source tree called __pycache__, and they are named based on python version (a way better scheme for sure). If you wanted to you could run your python scripts from the .pyc file alone. In other words, you may import as long as the .pyc file exists and the source does not need to be there. Some folks use this (not recommended) trick to hide or obfuscate their source from their users). marcus From marko at pacujo.net Thu Mar 20 13:45:43 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 19:45:43 +0200 Subject: running python 2 vs 3 References: Message-ID: <87k3bon4qg.fsf@elektro.pacujo.net> Chris Angelico : > Nowadays they'll be pushed away into a separate directory, which makes > them easier for you to ignore. This is a good thing. Still, I don't think Python should go and soil my directories without an explicit permission. Marko From marko at pacujo.net Thu Mar 20 13:47:10 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 19:47:10 +0200 Subject: running python 2 vs 3 References: Message-ID: <87fvmcn4o1.fsf@elektro.pacujo.net> Mark H Harris : > If you wanted to you could run your python scripts from the .pyc file > alone. In other words, you may import as long as the .pyc file exists > and the source does not need to be there. Some folks use this (not > recommended) trick to hide or obfuscate their source from their > users). I've seen it done, but at least in those Python 2 days the pyc format changed between minor releases of Python, so Python itself had to be shipped with the pyc files. Marko From gary.herron at islandtraining.com Thu Mar 20 13:45:33 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Thu, 20 Mar 2014 10:45:33 -0700 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: <532B293D.4030602@islandtraining.com> On 03/20/2014 10:10 AM, notbob wrote: > On 2014-03-20, Zachary Ware wrote: > >> If you're specifying the interpreter in your command (by calling >> "python .py", etc), the shebang won't mean anything >> anyway. > DOH! > > I was following you, fine, until that last sentence. Then how should > I invoke the scripts? ....as your example is exactly how I've been > doing it with 2.7, as per Learn Python the Hard Way. Simply > ./.py from the appropriate directory (assuming I keep both > vers in separate dirs)? > > nb If you mark your script as executable (chmod ...) and include the shebang line, and place it in a directory included in your search path (mine is ~/bin), then you run it as you run any installed program: Just type it's name followed by any command line args. I usually remove the .py portion of the name as I copy it into my bin directory so it really does look like any other installed program. If you need to be in a specific directory when you run it, then perhaps you should consider a bit of a rewrite to remove this constraint. Gary Herron From laguna-mc at mail.com Thu Mar 20 14:22:19 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Thu, 20 Mar 2014 14:22:19 -0400 Subject: Installing ssdeep on Portable Python Message-ID: <20140320182219.240120@gmx.com> Portable Python 2.7 for Windows, the Python application have dependency on ssdeep-2.10, which is a binary exe. The ssdeep (libfuzzy) installation example was shown for Linux platform only: ---- a) libfuzzy can be installed via apt-get: ? ?$ sudo apt-get install libfuzzy2 b) to install libfuzzy from source, download the gzipped tarball from http://ssdeep.sourceforge.net/#download, then run: ? ?$ tar -zxvf ssdeep-2.10.tar.gz ? ?$ cd ssdeep-2.10 && ./configure && make && sudo make install ----- I need install it on PortablePython for Windows, so it's not clear how to make this: where should be placed ssdeep Windows binary files, that Python application can found it? -------------- next part -------------- -- https://mail.python.org/mailman/listinfo/python-list From abhishek1899 at gmail.com Thu Mar 20 14:28:40 2014 From: abhishek1899 at gmail.com (peace) Date: Thu, 20 Mar 2014 11:28:40 -0700 (PDT) Subject: Problem with pickle and restarting a program In-Reply-To: References: Message-ID: <11a691c7-2842-4d3a-b355-1e44652d7590@googlegroups.com> On Thursday, March 20, 2014 1:20:03 AM UTC-7, dieter wrote: > Peace <> writes: > > > ... > > > The serial number field always remains empty even though I enter from the GUI and the receiveSerialNumber function is called and I explicitly initialize it to the variable in the model. > > > I'm trying to save the state of the program so that next time I open the application it resumes from where it left off. The problem is when I restart the application, the serial number is empty. What am I doing wrong here? Whenever I get a change in state (the RC value), I pickle and save to a file (restoreinfo.p). When I restart the application, the serial number is no longer there even though I enter it. Could you please let me know what is going wrong? Thank you. > > > > You may want to use debugging to determine what goes on in detail. > > > > There are commercial debuggers with a graphical user interface > > (maybe even free ones). Python comes with a simple command line > > debugger ("pdb"). I tried doing that. I still could not figure out what was wrong. Thank you. From ned at nedbatchelder.com Thu Mar 20 14:45:06 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 20 Mar 2014 14:45:06 -0400 Subject: running python 2 vs 3 In-Reply-To: <87fvmcn4o1.fsf@elektro.pacujo.net> References: <87fvmcn4o1.fsf@elektro.pacujo.net> Message-ID: On 3/20/14 1:47 PM, Marko Rauhamaa wrote: > Mark H Harris : > >> If you wanted to you could run your python scripts from the .pyc file >> alone. In other words, you may import as long as the .pyc file exists >> and the source does not need to be there. Some folks use this (not >> recommended) trick to hide or obfuscate their source from their >> users). > > I've seen it done, but at least in those Python 2 days the pyc format > changed between minor releases of Python, so Python itself had to be > shipped with the pyc files. > Python3 still makes no guarantees about the compatibility of bytecode (and therefore .pyc files) across versions of Python, so if you want to run from pure .pyc files, you have to be sure to use the same version of Python that produced the files. --Ned. > > Marko > -- Ned Batchelder, http://nedbatchelder.com From breamoreboy at yahoo.co.uk Thu Mar 20 14:56:25 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 20 Mar 2014 18:56:25 +0000 Subject: running python 2 vs 3 In-Reply-To: <87ob10nbeh.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On 20/03/2014 15:21, Marko Rauhamaa wrote: > notbob : > >> I've installed python 3.3 on my Slack box, which by default comes with >> python 2.7. I know how to fire up the different IDLE environments, but >> how do I differentiate between the scripts? IOW, up till now, I've >> used .py on all my 2.7 files. How do I know not to run a .py in >> python3 or visa versa? Or do I? What's the excepted convention for >> differentiating between the two? > > That's a bit of a sore spot. > > On a linux box, the initial line of the script indicates the > interpreter: > > #!/usr/bin/env python2 > > for Python 2.x > > #!/usr/bin/env python3 > > for Python 3.x. > > All tutorials will tell you to start it with > > #!/usr/bin/env python > > which will start python2 on all (?) existing linux distros, but is > expected to start python3 within the next decade. > > > Marko > The above is also true on windows via the 'Python launcher for windows' see http://legacy.python.org/dev/peps/pep-0397/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From gordon at panix.com Thu Mar 20 15:07:39 2014 From: gordon at panix.com (John Gordon) Date: Thu, 20 Mar 2014 19:07:39 +0000 (UTC) Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: In notbob writes: > On 2014-03-20, Zachary Ware wrote: > > If you're specifying the interpreter in your command (by calling > > "python .py", etc), the shebang won't mean anything > > anyway. > DOH! > I was following you, fine, until that last sentence. Then how should > I invoke the scripts? ....as your example is exactly how I've been > doing it with 2.7, as per Learn Python the Hard Way. Simply > ./.py from the appropriate directory (assuming I keep both > vers in separate dirs)? There are two ways (at least!) to run a python script: 1. Execute the python interpreter manually, supplying the python script name as an arugment, like so: python myscript.py python2 otherscript.py python3 yetanotherscript.py This lets you choose on-the-fly which version of python is being used to interpret the script. 2. Execute the python script directly by just typing its name, like so: myscript.py ./otherscript.py /other/directory/yetanotherscript.py Depending on your operating system, this may require: a. Permissions on the script file be set to allow execution; b. A 'shebang' entry as the first line in the file which specifies the program that shall be executed; -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From eric.jacoboni at gmail.com Thu Mar 20 15:07:25 2014 From: eric.jacoboni at gmail.com (Eric Jacoboni) Date: Thu, 20 Mar 2014 20:07:25 +0100 Subject: running python 2 vs 3 In-Reply-To: <87ob10nbeh.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: Le 20/03/2014 16:21, Marko Rauhamaa a ?crit : > All tutorials will tell you to start it with > > #!/usr/bin/env python > > which will start python2 on all (?) existing linux distros, but is > expected to start python3 within the next decade. With Arch-Linux, python is python3... From harrismh777 at gmail.com Thu Mar 20 15:36:32 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 20 Mar 2014 14:36:32 -0500 Subject: running python 2 vs 3 References: <87fvmcn4o1.fsf@elektro.pacujo.net> Message-ID: On 3/20/14 12:47 PM, Marko Rauhamaa wrote: > I've seen it done, but at least in those Python 2 days the pyc format > changed between minor releases of Python, so Python itself had to be > shipped with the pyc files. hi Marko, yeah, I have not done this; being that the concept is contrary to my principles and sensibilities these days. So, 1) no intellectual property 2) no software idea patents 3) no obfuscated code 4) ship the source, or don't ship anything/ In my view coding (and all other aspects of computer science including software engineering) is a liberal art; it should be open, free (libre), and available to everyone. People learn best by doing, and the do best by reading what others have done before them. marcus From ameyer2 at yahoo.com Thu Mar 20 15:53:52 2014 From: ameyer2 at yahoo.com (Alan Meyer) Date: Thu, 20 Mar 2014 15:53:52 -0400 Subject: running python 2 vs 3 In-Reply-To: <87ob10nbeh.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: <532B4750.2090006@yahoo.com> On 3/20/2014 11:21 AM, Marko Rauhamaa wrote: > On a linux box, the initial line of the script indicates the > interpreter: > > #!/usr/bin/env python2 > > for Python 2.x > > #!/usr/bin/env python3 > > for Python 3.x. > > All tutorials will tell you to start it with > > #!/usr/bin/env python > > which will start python2 on all (?) existing linux distros, but is > expected to start python3 within the next decade. > > > Marko I presume it would still be a good idea to test both python interpreters against any script that you didn't knowingly write with a feature that will only work in one of the two python versions. If it works fine in both - and many will, then use: #!/usr/bin/env python Only use the "python2" or "python3" versions if you really have a reason to do so. Yes? No? Alan From roy.snuffles at gmail.com Thu Mar 20 15:55:33 2014 From: roy.snuffles at gmail.com (roy.snuffles at gmail.com) Date: Thu, 20 Mar 2014 12:55:33 -0700 (PDT) Subject: File Path/Global name issue Message-ID: <2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com> I am currently running code for a program called HotNet (https://github.com/raphael-group/hotnet) In its simpleRun.py file, there is a place to insert a file path to be run. parser.add_argument('-mf', '--infmat_file', required=True, help='Path to .mat file containing influence matrix') My path file is /home/lai/Downloads/influence_matrix_files/hprd_inf_.mat And I have tried to add it in as such: Input: parser.add_argument('-mf', '--infmat_file', required=True, help= /home/lai/Downloads/influence_matrix_file/hprd_inf_.mat) Output: File "simpleRun.py", line 29 help= ~/home/lai/Downloads/influence_matrix_files/hprd_inf_.mat) ^ SyntaxError: invalid syntax I have also tried to place the path in ' ' but that isn't processed. I have tried removing the / however that just returns the following error: NameError: global name 'home' is not defined Completely new at this, so thank you for bearing with me and for the help! From skip at pobox.com Thu Mar 20 16:05:41 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 20 Mar 2014 15:05:41 -0500 Subject: File Path/Global name issue In-Reply-To: <2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com> References: <2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com> Message-ID: On Thu, Mar 20, 2014 at 2:55 PM, wrote: > File "simpleRun.py", line 29 > help= ~/home/lai/Downloads/influence_matrix_files/hprd_inf_.mat) > ^ > SyntaxError: invalid syntax You need quotes around the filename. It's a string literal. Skip From roy.snuffles at gmail.com Thu Mar 20 16:08:06 2014 From: roy.snuffles at gmail.com (roy.snuffles at gmail.com) Date: Thu, 20 Mar 2014 13:08:06 -0700 (PDT) Subject: File Path/Global name issue In-Reply-To: References: <2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com> Message-ID: Hi Skip! Thank you so much for the response. When I put quotes around the file name I receive this output. simpleRun.py: error: argument -mf/--infmat_file is required From marko at pacujo.net Thu Mar 20 16:08:37 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 22:08:37 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> Message-ID: <87eh1wpr96.fsf@elektro.pacujo.net> Alan Meyer : > I presume it would still be a good idea to test both python > interpreters against any script that you didn't knowingly write with a > feature that will only work in one of the two python versions. > > If it works fine in both - and many will, then use: > > #!/usr/bin/env python > > Only use the "python2" or "python3" versions if you really have a > reason to do so. > > Yes? No? No. Even if you managed to do that, it would mean getting the worst of both worlds. The language dialects are too far apart. When you start your Python project, you decide between Python 2 and Python 3 and go all in. Marko From harrismh777 at gmail.com Thu Mar 20 16:10:04 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 20 Mar 2014 15:10:04 -0500 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> Message-ID: On 3/20/14 2:53 PM, Alan Meyer wrote: > #!/usr/bin/env python > > Only use the "python2" or "python3" versions if you really have a reason > to do so. It gets tricky for distribution (you need docs for your distros, imho) because #!/usr/bin/env python means different things on different systems. I actually have three major versions of python2 and 2 major versions of python3 on my primary system at this point. On my machine python2.6 is "python". That is because that system shipped with 2.6 and many of the subsystem stuff depends on python2.6 / When I call python2 that means python2.7.6 / When I call python3 that means python3.3.4 / I can also call python2.7, which is 2.7.2 / You get the idea. There is no one set rule, because there are many distros (gnu/linux) that use python at various versions, and they all us different setups. Really , you need an install script to snoop out the configurables. marcus From skip at pobox.com Thu Mar 20 16:15:42 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 20 Mar 2014 15:15:42 -0500 Subject: File Path/Global name issue In-Reply-To: References: <2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com> Message-ID: On Thu, Mar 20, 2014 at 3:08 PM, wrote: > simpleRun.py: error: argument -mf/--infmat_file is required I think you are misinterpreting the actual purpose of the parser_add_argument() call. It's telling you that *on the command line* you can specify it using either -mf some-file-name or --infmat_file=some-file-name It also tells you that it is a required argument. I don't believe you are supposed to have to modify the source to run the program. I'd set the argument to the "help=..." parameter back to however it was set when you got it and try either of the above command line args. Skip From breamoreboy at yahoo.co.uk Thu Mar 20 16:22:33 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 20 Mar 2014 20:22:33 +0000 Subject: running python 2 vs 3 In-Reply-To: <87eh1wpr96.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> Message-ID: On 20/03/2014 20:08, Marko Rauhamaa wrote: > Alan Meyer : > >> I presume it would still be a good idea to test both python >> interpreters against any script that you didn't knowingly write with a >> feature that will only work in one of the two python versions. >> >> If it works fine in both - and many will, then use: >> >> #!/usr/bin/env python >> >> Only use the "python2" or "python3" versions if you really have a >> reason to do so. >> >> Yes? No? > > No. Even if you managed to do that, it would mean getting the worst of > both worlds. The language dialects are too far apart. When you start > your Python project, you decide between Python 2 and Python 3 and go all > in. > > Marko > I do not agree that the dialects are too far apart, not that it really matters. There are several libraries available to enable code to run under both versions. The starter is 2to3 which had been in the standard library for what seems like an eternity to me. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From __peter__ at web.de Thu Mar 20 16:26:21 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 20 Mar 2014 21:26:21 +0100 Subject: File Path/Global name issue References: <2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com> Message-ID: roy.snuffles at gmail.com wrote: > I am currently running code for a program called HotNet > (https://github.com/raphael-group/hotnet) > > In its simpleRun.py file, there is a place to insert a file path to be > run. > > parser.add_argument('-mf', '--infmat_file', required=True, > help='Path to .mat file containing influence > matrix') > > My path file is /home/lai/Downloads/influence_matrix_files/hprd_inf_.mat > > And I have tried to add it in as such: > > Input: > > parser.add_argument('-mf', '--infmat_file', required=True, > help= > /home/lai/Downloads/influence_matrix_file/hprd_inf_.mat) > > Output: > > File "simpleRun.py", line 29 > help= ~/home/lai/Downloads/influence_matrix_files/hprd_inf_.mat) > ^ > SyntaxError: invalid syntax > > I have also tried to place the path in ' ' but that isn't processed. > > I have tried removing the / however that just returns the following error: > > NameError: global name 'home' is not defined > > > Completely new at this, so thank you for bearing with me and for the help! Reread the documentation, you are misunderstanding it. You don't have to modify the simpleRun.py script, you should invoke it from the commandline with the file as one of its arguments: $ python simpleRun.py --infmat_file /home/lai/Downloads/influence_matrix_files/hprd_inf_.mat As there are more required arguments you will end up with a very long command line. But there is an alternative. Create a config file like the following https://github.com/raphael-group/hotnet/blob/master/example/configs/simple.config where you replace all the file names with those of your actual files and then invoke simpleRun.py with $ python simpleRun.py @roy_snuffles.config From ned at nedbatchelder.com Thu Mar 20 16:26:39 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 20 Mar 2014 16:26:39 -0400 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On 3/20/14 3:07 PM, Eric Jacoboni wrote: > Le 20/03/2014 16:21, Marko Rauhamaa a ?crit : > > >> All tutorials will tell you to start it with >> >> #!/usr/bin/env python >> >> which will start python2 on all (?) existing linux distros, but is >> expected to start python3 within the next decade. > > With Arch-Linux, python is python3... > Yes, and they have been told many times that this was foolish and wrong, but it persists, much to our pain. -- Ned Batchelder, http://nedbatchelder.com From ned at nedbatchelder.com Thu Mar 20 16:27:59 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 20 Mar 2014 16:27:59 -0400 Subject: running python 2 vs 3 In-Reply-To: <87eh1wpr96.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> Message-ID: On 3/20/14 4:08 PM, Marko Rauhamaa wrote: > Alan Meyer : > >> I presume it would still be a good idea to test both python >> interpreters against any script that you didn't knowingly write with a >> feature that will only work in one of the two python versions. >> >> If it works fine in both - and many will, then use: >> >> #!/usr/bin/env python >> >> Only use the "python2" or "python3" versions if you really have a >> reason to do so. >> >> Yes? No? > > No. Even if you managed to do that, it would mean getting the worst of > both worlds. The language dialects are too far apart. When you start > your Python project, you decide between Python 2 and Python 3 and go all > in. Plenty of people have adopted a dual-support strategy, with one code base that supports both Python 2 and Python 3. The six module can help a great deal with this. > > > Marko > -- Ned Batchelder, http://nedbatchelder.com From marko at pacujo.net Thu Mar 20 16:30:57 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 22:30:57 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> Message-ID: <87a9ckpq7y.fsf@elektro.pacujo.net> Mark Lawrence : > The starter is 2to3 which had been in the standard library for what > seems like an eternity to me. No problem there. It helps you transition from python2 to python3. However, python3 is here and you should be able to write genuine python3 code with the appropriate bytes and string facilities. It would be very confusing to try to mix the two regimes. I must say, though, that Python3 destroyed "print" forever for me. To avoid nausea, I write sys.stdout.write() in all Python3 code. Marko From drsalists at gmail.com Thu Mar 20 16:38:10 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 20 Mar 2014 13:38:10 -0700 Subject: running python 2 vs 3 In-Reply-To: <87ob10nbeh.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 20, 2014 at 8:21 AM, Marko Rauhamaa wrote: > notbob : > >> I've installed python 3.3 on my Slack box, which by default comes with >> python 2.7. I know how to fire up the different IDLE environments, but >> how do I differentiate between the scripts? IOW, up till now, I've >> used .py on all my 2.7 files. How do I know not to run a .py in >> python3 or visa versa? Or do I? What's the excepted convention for >> differentiating between the two? > > That's a bit of a sore spot. > > On a linux box, the initial line of the script indicates the > interpreter: > > #!/usr/bin/env python2 > > for Python 2.x > > #!/usr/bin/env python3 > > for Python 3.x. > > All tutorials will tell you to start it with > > #!/usr/bin/env python Actually, I formerly used /usr/bin/env, but have recently (within the last couple of years) stopped. This is because the env trick doesn't play nicely with top IME. Also, it's a trick. From zachary.ware+pylist at gmail.com Thu Mar 20 16:43:50 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 20 Mar 2014 15:43:50 -0500 Subject: running python 2 vs 3 In-Reply-To: <87a9ckpq7y.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 20, 2014 at 3:30 PM, Marko Rauhamaa wrote: > I must say, though, that Python3 destroyed "print" forever for me. To > avoid nausea, I write sys.stdout.write() in all Python3 code. To each their own :). I can't stand using 'print' as a statement. It's a very nice trick to be able to write a script, think "oh, all those prints should really be sending that output somewhere else", and then instead of changing every individual print, just define a different 'print' function at the top of the file (which may be as simple as `print = functools.partial(print, file=sys.stderr)` or `print = logging.debug`). -- Zach From breamoreboy at yahoo.co.uk Thu Mar 20 16:44:03 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 20 Mar 2014 20:44:03 +0000 Subject: running python 2 vs 3 In-Reply-To: <87a9ckpq7y.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> Message-ID: On 20/03/2014 20:30, Marko Rauhamaa wrote: > Mark Lawrence : > >> The starter is 2to3 which had been in the standard library for what >> seems like an eternity to me. > > No problem there. It helps you transition from python2 to python3. > > However, python3 is here and you should be able to write genuine python3 > code with the appropriate bytes and string facilities. It would be very > confusing to try to mix the two regimes. > > I must say, though, that Python3 destroyed "print" forever for me. To > avoid nausea, I write sys.stdout.write() in all Python3 code. > Not for me, I was using from __future__ import print_function for years so got used to typing those two extra brackets, plus print very kindly inserts the newlines for me. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Thu Mar 20 16:42:41 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 22:42:41 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> Message-ID: <8738icppoe.fsf@elektro.pacujo.net> Ned Batchelder : > Plenty of people have adopted a dual-support strategy, with one code > base that supports both Python 2 and Python 3. The six module can help > a great deal with this. I wonder how easy the resulting code is to the eyes and how easy it is for the casual maintainer to accidentally break the delicate balance. In a word, I wouldn't go there. Stay with Python2 as long as you must and then, migrate and leave it behind. Marko From marko at pacujo.net Thu Mar 20 16:46:09 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 22:46:09 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: <87y504oay6.fsf@elektro.pacujo.net> Dan Stromberg : > Actually, I formerly used /usr/bin/env, but have recently (within the > last couple of years) stopped. > > This is because the env trick doesn't play nicely with top IME. Also, > it's a trick. I'm not sure I like it either, but it's a standard idiom in Pythonland. Marko From ned at nedbatchelder.com Thu Mar 20 16:53:25 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 20 Mar 2014 16:53:25 -0400 Subject: running python 2 vs 3 In-Reply-To: <8738icppoe.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> Message-ID: On 3/20/14 4:42 PM, Marko Rauhamaa wrote: > Ned Batchelder : > >> Plenty of people have adopted a dual-support strategy, with one code >> base that supports both Python 2 and Python 3. The six module can help >> a great deal with this. > > I wonder how easy the resulting code is to the eyes and how easy it is > for the casual maintainer to accidentally break the delicate balance. In > a word, I wouldn't go there. Stay with Python2 as long as you must and > then, migrate and leave it behind. This is fine advice for applications, but tools, libraries, and frameworks may want to support more than one version at the same time. It's an extreme case, but the latest released version of coverage.py supports Python 2.3 through 3.3 with one code base. To do it, there's a compatibility layer (akin to six). Then you stay away from features that aren't available on all versions. In a few places, you might need to have version checks, and the code can get a little idiomatic to continue to work. It's a tradeoff: you have to decide for yourself whether the effort is worth the benefit. I was glad to be able to drop support for 2.3, 2.4, and 2.5, and now only support 2.6-3.4 in coverage.py. > > > Marko > -- Ned Batchelder, http://nedbatchelder.com From marko at pacujo.net Thu Mar 20 16:50:45 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 22:50:45 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> Message-ID: <87txasoaqi.fsf@elektro.pacujo.net> Mark Lawrence : > On 20/03/2014 20:30, Marko Rauhamaa wrote: >> I must say, though, that Python3 destroyed "print" forever for me. To >> avoid nausea, I write sys.stdout.write() in all Python3 code. > > Not for me, I was using from __future__ import print_function for > years so got used to typing those two extra brackets, plus print very > kindly inserts the newlines for me. That very realization helped me wean myself from "print." Its sole raison d'?tre is the insertion of the newline, which it would be nicer to micromanage anyway; that's how it's done in other programming languages as well: C, perl, guile, ... (Well, ok, "echo" is the exception.) Marko From marko at pacujo.net Thu Mar 20 16:59:21 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 20 Mar 2014 22:59:21 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> Message-ID: <87pplgoac6.fsf@elektro.pacujo.net> Ned Batchelder : > It's an extreme case, but the latest released version of coverage.py > supports Python 2.3 through 3.3 with one code base. To do it, there's > a compatibility layer (akin to six). Then you stay away from features > that aren't available on all versions. In a few places, you might need > to have version checks, and the code can get a little idiomatic to > continue to work. Well, with proper care, I suppose the same code base could support perl as well. ;) Marko From ckaynor at zindagigames.com Thu Mar 20 17:18:41 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 20 Mar 2014 14:18:41 -0700 Subject: running python 2 vs 3 In-Reply-To: <87pplgoac6.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 20, 2014 at 1:59 PM, Marko Rauhamaa wrote: > Well, with proper care, I suppose the same code base could support perl > as well. ;) > Go even farther; how about C, PHP, and bash? I'm sure if you tried, you could mix in some Python as well. http://en.wikipedia.org/wiki/Polyglot_(computing) Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From notbob at nothome.com Thu Mar 20 17:16:36 2014 From: notbob at nothome.com (notbob) Date: 20 Mar 2014 21:16:36 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On 2014-03-20, Ned Batchelder wrote: > On 3/20/14 3:07 PM, Eric Jacoboni wrote: >> With Arch-Linux, python is python3... >> > Yes, and they have been told many times that this was foolish and wrong, > but it persists, much to our pain. I've read that 2.7 is the defacto std for python (default on Slack 14.1). I installed py3 on Slack box cuz I'd gotten the little "Programming the Raspberry Pi" book, which is a pretty good lil' book, clarifying many confusing (to me) python issues. Only prob is, it's fer python 3x. I guess I coulda kept the two platforms separate, but then raspi has 2X and 3x, also, so I guess I need to get this issue straight in my feeble geezer head, right outta the gate. I'm plum grateful to all you kind folks who are taking the time to educate this slow ol' curmudgeon. ;) nb From notbob at nothome.com Thu Mar 20 17:28:43 2014 From: notbob at nothome.com (notbob) Date: 20 Mar 2014 21:28:43 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> Message-ID: On 2014-03-20, Mark H Harris wrote: > When I call python2 that means python2.7.6 / > > When I call python3 that means python3.3.4 / > > I can also call python2.7, which is 2.7.2 / > > You get the idea. There is no one set rule, because there are many > distros (gnu/linux) that use python at various versions, and they all us > different setups. Really , you need an install script to snoop out the > configurables. Weeping Chryst on the cross!!. No wonder the latest O'Reilly book, Learning Python, 5th ed, is 1600 pgs. I coulda swore someone sed python is easy. ;) nb From ned at nedbatchelder.com Thu Mar 20 17:31:58 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 20 Mar 2014 17:31:58 -0400 Subject: running python 2 vs 3 In-Reply-To: <87pplgoac6.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> Message-ID: On 3/20/14 4:59 PM, Marko Rauhamaa wrote: > Ned Batchelder : > >> It's an extreme case, but the latest released version of coverage.py >> supports Python 2.3 through 3.3 with one code base. To do it, there's >> a compatibility layer (akin to six). Then you stay away from features >> that aren't available on all versions. In a few places, you might need >> to have version checks, and the code can get a little idiomatic to >> continue to work. > > Well, with proper care, I suppose the same code base could support perl > as well. ;) I'm not sure how to take this comment. I feel like you are mocking my choice. I wanted to make coverage.py available to as broad an audience as possible, something that I think is worthwhile. Yes, there was an engineering cost, but the tradeoff was worth it. > > > Marko > -- Ned Batchelder, http://nedbatchelder.com From gordon at panix.com Thu Mar 20 17:31:15 2014 From: gordon at panix.com (John Gordon) Date: Thu, 20 Mar 2014 21:31:15 +0000 (UTC) Subject: File Path/Global name issue References: <2089d20b-aa60-462f-aad0-51109849cf36@googlegroups.com> Message-ID: In <2089d20b-aa60-462f-aad0-51109849cf36 at googlegroups.com> roy.snuffles at gmail.com writes: > I am currently running code for a program called HotNet (https://github.com/raphael-group/hotnet) > In its simpleRun.py file, there is a place to insert a file path to be run. > parser.add_argument('-mf', '--infmat_file', required=True, > help='Path to .mat file containing influence matrix') > My path file is /home/lai/Downloads/influence_matrix_files/hprd_inf_.mat You're completely misunderstanding the purpose of this line of code. Its intent is to allow you to pass the matrix file location to the script by using the '-mf' or '--infmat_file' arguments, thus not requiring you to edit the script at all. The 'help' parameter provides a message explaining the usage of that particular argument if the simpleRun.py script is executed with the '-help' option. For example, if you were unsure how to use the simpleRun.py script, you might run this command: simpleRun.py -help And you might see output that looks like this: Usage: simpleRun.py [options] Options: -h, --help show this help message and exit -mf, --infmat_file Path to .mat file containing influence matrix -d, --dance do a little dance -l, --love make a little love The help message thus informs you that you can provide the location to an influence matrix file by using the '-mf' or '--infmat_file' arguments. There are also -d and -l options that do ... something. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From breamoreboy at yahoo.co.uk Thu Mar 20 17:36:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 20 Mar 2014 21:36:38 +0000 Subject: running python 2 vs 3 In-Reply-To: <87txasoaqi.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> <87txasoaqi.fsf@elektro.pacujo.net> Message-ID: On 20/03/2014 20:50, Marko Rauhamaa wrote: > Mark Lawrence : > >> On 20/03/2014 20:30, Marko Rauhamaa wrote: >>> I must say, though, that Python3 destroyed "print" forever for me. To >>> avoid nausea, I write sys.stdout.write() in all Python3 code. >> >> Not for me, I was using from __future__ import print_function for >> years so got used to typing those two extra brackets, plus print very >> kindly inserts the newlines for me. > > That very realization helped me wean myself from "print." Its sole > raison d'?tre is the insertion of the newline, which it would be nicer > to micromanage anyway; that's how it's done in other programming > languages as well: C, perl, guile, ... (Well, ok, "echo" is the > exception.) > > > Marko > The end keyword argument to the print function defaults to newline but you can make it anything you like, see http://docs.python.org/3/library/functions.html#print -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Thu Mar 20 17:46:35 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 20 Mar 2014 16:46:35 -0500 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> Message-ID: On 3/20/14 4:28 PM, notbob wrote: > No wonder the latest O'Reilly book, Learning Python, 5th ed, is 1600 pgs. I coulda swore someone sed python is easy. ;) > nb Python is easy, but its not simple. Python is elegant, and full of art, but it has no paucity of constructs, types, and opportunities for confusion. My goal for designing SimplyPy (for instance)is to present the beautiful heart of python (as Mark Summerfield calls it) and subsume the complexities of the fulness of python within a simple interface, BUT without limiting it. Python is easy enough to teach children (I've done it), but its "complete and elegant enough" for the most scientific of professionals. You do not need to know the fulness of python in order to use it. It is possible (even elegant) to use python (in a Rexx style) not at all recognized as "pythonized" code, and yet very very simple and powerful. The beauty of python, in my view, is the flexibility and extensibility of the namespace with something more than the minimalist approach of Lisp, BUT with the elegance of the language called python. Get Mark Summerfield's Programming Python 3. Its really quite good, and in my opinion better that the O'Reilly book, especially for new users. Just an opinion of course. marcus From tjreedy at udel.edu Thu Mar 20 17:52:02 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 20 Mar 2014 17:52:02 -0400 Subject: running python 2 vs 3 In-Reply-To: References: Message-ID: On 3/20/2014 1:23 PM, notbob wrote: > What the heck is a .pyc file and how are they created? .pyc contained compiled bytecode. They are created when, and only when, you import a module. Imported library files are often big and stable, so their compiled forms get cached. Top-level scripts are typically short and often volotile. They may be as short as "from start import run; run()" in order to have as much as possible stored in compiled form. This has nothing to do with Idle. > I went back to my ~/python/ dir and noticed one .pyc file out of 15 > .py files I created from following Learning Python the Hard Way. That must be the only one you imported. -- Terry Jan Reedy From tjreedy at udel.edu Thu Mar 20 18:05:49 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 20 Mar 2014 18:05:49 -0400 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: On 3/20/2014 3:07 PM, John Gordon wrote: > There are two ways (at least!) to run a python script: > > 1. Execute the python interpreter manually, supplying the python script name > as an arugment, like so: > > python myscript.py > python2 otherscript.py > python3 yetanotherscript.py > > This lets you choose on-the-fly which version of python is being used to > interpret the script. > > 2. Execute the python script directly by just typing its name, like so: > > myscript.py > ./otherscript.py > /other/directory/yetanotherscript.py > > Depending on your operating system, this may require: > a. Permissions on the script file be set to allow execution; > b. A 'shebang' entry as the first line in the file which specifies the > program that shall be executed; c. An association between '.py' and some version of python. 3. Use the python launcher py.exe with version selection. py -2 myscript.py py -3 myscript.py As far as I know, this is only for Windows at present. -- Terry Jan Reedy From torriem at gmail.com Thu Mar 20 17:44:27 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 20 Mar 2014 15:44:27 -0600 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: <532B613B.4030901@gmail.com> On 03/20/2014 11:10 AM, notbob wrote: > On 2014-03-20, Zachary Ware wrote: > >> If you're specifying the interpreter in your command (by calling >> "python .py", etc), the shebang won't mean anything >> anyway. > > DOH! > > I was following you, fine, until that last sentence. Then how should > I invoke the scripts? ....as your example is exactly how I've been > doing it with 2.7, as per Learn Python the Hard Way. Simply > ./.py from the appropriate directory (assuming I keep both > vers in separate dirs)?' If you want to run a script with python3, just invoke the python3 interpreter: python3 blah.py From marko at pacujo.net Thu Mar 20 18:17:07 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 21 Mar 2014 00:17:07 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> Message-ID: <877g7oms64.fsf@elektro.pacujo.net> notbob : > Weeping Chryst on the cross!!. No wonder the latest O'Reilly book, > Learning Python, 5th ed, is 1600 pgs. I coulda swore someone sed > python is easy. ;) It's not that bad. There are two principal dialects: python2 and python3. Take the oldest python version you have to support and write your code for that version. Python documentation carefully explains what language and library facilities are available in whichever version. Marko From notbob at nothome.com Thu Mar 20 18:19:30 2014 From: notbob at nothome.com (notbob) Date: 20 Mar 2014 22:19:30 GMT Subject: running python 2 vs 3 References: Message-ID: On 2014-03-20, Terry Reedy wrote: > That must be the only one you imported. So it is. Thank you. nb From greg.ewing at canterbury.ac.nz Thu Mar 20 18:19:50 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 21 Mar 2014 11:19:50 +1300 Subject: Question about Source Control In-Reply-To: References: Message-ID: Chris Angelico wrote: > You can then offer a non-source-control means of downloading that > specific revision. Just keep in mind the downside that you can't then push or pull your changes directly back into the main repository. You can generate a patch file for the project maintainer to apply, however. Hg makes it very easy to produce a patch file between any two revisions. Also, unless the project is truly ancient, the whole history might not be as big as you expect. The code presumably grew to its present size incrementally, in an approximately monotonic manner, so the sum of all the diffs is probably about the same order of magnitude as the current code size. As an experiment, I just cloned a copy of the CPython repository, and it's about 300MB. A tarball of Python 3.2 that I downloaded and compiled earlier is about 75MB. That's a ratio of about 4, and CPython is a pretty ancient project! -- Greg From marko at pacujo.net Thu Mar 20 18:23:07 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 21 Mar 2014 00:23:07 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> Message-ID: <8738icmrw4.fsf@elektro.pacujo.net> Ned Batchelder : > On 3/20/14 4:59 PM, Marko Rauhamaa wrote: >> Well, with proper care, I suppose the same code base could support perl >> as well. ;) > > I'm not sure how to take this comment. I feel like you are mocking my > choice. I wanted to make coverage.py available to as broad an audience > as possible, something that I think is worthwhile. Yes, there was an > engineering cost, but the tradeoff was worth it. I can't judge if your particular choice was the right one. My only point is that python2 and python3 are so far apart as to be regarded as independent languages. Marko From rosuav at gmail.com Thu Mar 20 18:34:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 09:34:23 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 9:19 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> You can then offer a non-source-control means of downloading that >> specific revision. > > Just keep in mind the downside that you can't then > push or pull your changes directly back into the main > repository. You can generate a patch file for the > project maintainer to apply, however. Hg makes it > very easy to produce a patch file between any two > revisions. Yes, but a lot of people just want to get the software, they don't actually need to generate patch files :) > Also, unless the project is truly ancient, the > whole history might not be as big as you expect. > The code presumably grew to its present size > incrementally, in an approximately monotonic > manner, so the sum of all the diffs is probably > about the same order of magnitude as the current > code size. > > As an experiment, I just cloned a copy of the > CPython repository, and it's about 300MB. A > tarball of Python 3.2 that I downloaded and > compiled earlier is about 75MB. That's a ratio > of about 4, and CPython is a pretty ancient > project! Yep! But cloning requires that you have Mercurial installed and, more importantly, know how to use it. We don't have a huge proliferation of source control systems these days, but if someone says "Our code is available via Perforce", I'm going to just look for a tarball download, rather than figure out a source control system I don't know. ChrisA From steve+comp.lang.python at pearwood.info Thu Mar 20 18:39:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2014 22:39:40 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> Message-ID: <532b6e2c$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Mar 2014 22:30:57 +0200, Marko Rauhamaa wrote: > To avoid nausea, I write sys.stdout.write() in all Python3 code. Now that's funny. I-know-I-shouldn't-respond-to-obvious-trolling-but-I-can't-help-myself-ly yrs, -- Steven D'Aprano From breamoreboy at yahoo.co.uk Thu Mar 20 18:42:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 20 Mar 2014 22:42:39 +0000 Subject: running python 2 vs 3 In-Reply-To: <8738icmrw4.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> <8738icmrw4.fsf@elektro.pacujo.net> Message-ID: On 20/03/2014 22:23, Marko Rauhamaa wrote: > Ned Batchelder : >> On 3/20/14 4:59 PM, Marko Rauhamaa wrote: >>> Well, with proper care, I suppose the same code base could support perl >>> as well. ;) >> >> I'm not sure how to take this comment. I feel like you are mocking my >> choice. I wanted to make coverage.py available to as broad an audience >> as possible, something that I think is worthwhile. Yes, there was an >> engineering cost, but the tradeoff was worth it. > > I can't judge if your particular choice was the right one. My only point > is that python2 and python3 are so far apart as to be regarded as > independent languages. > And I still say this is complete nonsense. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Thu Mar 20 19:04:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 10:04:58 +1100 Subject: running python 2 vs 3 In-Reply-To: <87eh1wpr96.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 21, 2014 at 7:08 AM, Marko Rauhamaa wrote: > Alan Meyer : > >> I presume it would still be a good idea to test both python >> interpreters against any script that you didn't knowingly write with a >> feature that will only work in one of the two python versions. >> >> If it works fine in both - and many will, then use: >> >> #!/usr/bin/env python >> >> Only use the "python2" or "python3" versions if you really have a >> reason to do so. >> >> Yes? No? > > No. Even if you managed to do that, it would mean getting the worst of > both worlds. The language dialects are too far apart. When you start > your Python project, you decide between Python 2 and Python 3 and go all > in. They're not that far apart. It's not difficult to write code that runs happily on both. However, it does mean you can't take advantage of Python 3 features, so it's probably better to write for one or the other, unless you specifically want wide distribution. For your own projects, just put whichever you need. ChrisA From fiensproto at gmail.com Thu Mar 20 19:16:22 2014 From: fiensproto at gmail.com (fiensproto at gmail.com) Date: Thu, 20 Mar 2014 16:16:22 -0700 (PDT) Subject: CallBack function in C Libraries. Message-ID: Hello. I want to use a c library. It is a complete graphic widget set. Here code working. But i have problem with the callback function. The callback is executed while ClikOnForm is executed but i get a error message (see after code ) ____________________________________________________________________ file fpgui-test.py from ctypes import* def TheProc(c_int): fpgui.fpgFormWindowTitle(0, 'Boum') return 0 CMPFUNC = CFUNCTYPE(c_int) TheProcF = CMPFUNC(TheProc) fpgui = cdll.LoadLibrary("fpgui-32.dll") fpgui.fpgInitialize() fpgui.fpgSetStyle('Demo Style') fpgui.fpgFormCreate(0, -1) fpgui.fpgFormSetPosition(0, 300,100,400,200) fpgui.fpgFormWindowTitle(0, 'Hello world!') fpgui.fpgFormOnClick(0,TheProcF) fpgui.fpgButtonCreate(0,0,-1) ; fpgui.fpgButtonSetPosition(0,0, 15, 10 , 150 , 40) fpgui.fpgButtonSetText(0,0, 'BUTTON1') fpgui.fpgButtonCreate(0,1,-1) ; fpgui.fpgButtonSetPosition(0,1, 15, 70 , 150, 40) fpgui.fpgButtonSetText(0,1, 'Clickme') fpgui.fpgFormShow(0) fpgui.fpgRun() Here the error message if i click on form : Traceback (most recent call last): File "_ctypes/callbacks.c", line 314, in 'calling callback function' TypeError: TheProc() takes exactly 1 argument (0 given) What is wrong ? Many thanks. From rosuav at gmail.com Thu Mar 20 19:18:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 10:18:25 +1100 Subject: running python 2 vs 3 In-Reply-To: <8738icmrw4.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> <8738icmrw4.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 21, 2014 at 9:23 AM, Marko Rauhamaa wrote: > Ned Batchelder : >> On 3/20/14 4:59 PM, Marko Rauhamaa wrote: >>> Well, with proper care, I suppose the same code base could support perl >>> as well. ;) >> >> I'm not sure how to take this comment. I feel like you are mocking my >> choice. I wanted to make coverage.py available to as broad an audience >> as possible, something that I think is worthwhile. Yes, there was an >> engineering cost, but the tradeoff was worth it. > > I can't judge if your particular choice was the right one. My only point > is that python2 and python3 are so far apart as to be regarded as > independent languages. They're definitely not independent languages. The biggest change is str/unicode->bytes/str, and you can get part of that in Python 2.6/2.7 with "from __future__ import unicode_literals". You may still run into problems with some functions that expect str and won't take unicode (or vice versa), but it's easy to make code that runs across both versions that way. Then toss in "from __future__ import print_function" and happily use the expanded features of print, or go for the lowest common denominator: print("some single string") which works happily in all versions of Python. I've written code that runs on 2.6+/3.2+. (Or maybe it's 3.1+; whichever version Debian Squeeze ships with.) It's pretty easy. It's certainly a lot easier than writing code that runs as either Pike or C++, for instance. THOSE are independent languages. (And yes, I've written that sort of code. Had a #define block up the top to handle some naming differences, and then restricted myself to a *really* narrow set of common operations. Was a neat way to prove correctness, though.) ChrisA From harrismh777 at gmail.com Thu Mar 20 19:42:03 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 20 Mar 2014 18:42:03 -0500 Subject: CallBack function in C Libraries. References: Message-ID: On 3/20/14 6:16 PM, fiensproto at gmail.com wrote: > def TheProc(c_int): fpgui.fpgFormWindowTitle(0, 'Boum') > return 0 > TheProcF = CMPFUNC(TheProc) > Traceback (most recent call last): File "_ctypes/callbacks.c", > line 314, in 'calling callback function' TypeError: TheProc() takes > exactly 1 argument (0 given) > What is wrong ? You defined TheProc(c_init) to take exactly 1 argument. But when you called it, you didn't provide the argument. So, you got a traceback indicating that TheProc() takes exactly one argument. Give the function call its required argument and the error will go away... well, at least that one. Cheers From fiensproto at gmail.com Thu Mar 20 19:56:43 2014 From: fiensproto at gmail.com (fiensproto at gmail.com) Date: Thu, 20 Mar 2014 16:56:43 -0700 (PDT) Subject: CallBack function in C Libraries. In-Reply-To: References: Message-ID: > Give the function call its required argument and the error will go > > away... well, at least that one. Yep, many thanks for the answer. But... im totally beginner with Python. I develop in Pascal and C and want to understand the basics of Python. In concrete, what must i change in the code ? Many thanks. From dihedral88888 at gmail.com Thu Mar 20 20:04:57 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Thu, 20 Mar 2014 17:04:57 -0700 (PDT) Subject: CallBack function in C Libraries. In-Reply-To: References: Message-ID: On Friday, March 21, 2014 7:56:43 AM UTC+8, fiens... at gmail.com wrote: > > Give the function call its required argument and the error will go > > > > > > away... well, at least that one. > > > > Yep, many thanks for the answer. > > But... im totally beginner with Python. > > I develop in Pascal and C and want to understand the basics of Python. > > > > In concrete, what must i change in the code ? > > > > Many thanks. Python is a dynamical typed functional language with OOP supports in the revisons, and well suited in the giga-byte dram capacity personal toy era that can relplace her mother lisp's unrealized AI project . From laguna-mc at mail.com Thu Mar 20 20:16:09 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Thu, 20 Mar 2014 20:16:09 -0400 Subject: Installing ssdeep on Portable Python /advice Message-ID: <20140321001609.63150@gmx.com> Portable Python 2.7 for Windows, the Python application have dependency on ssdeep-2.10, which is a binary exe. The ssdeep (libfuzzy) installation example was shown for Linux platform only: ---- a) libfuzzy can be installed via apt-get: ? ?$ sudo apt-get install libfuzzy2 b) to install libfuzzy from source, download the gzipped tarball from http://ssdeep.sourceforge.net/#download, then run: ? ?$ tar -zxvf ssdeep-2.10.tar.gz ? ?$ cd ssdeep-2.10 && ./configure && make && sudo make install ----- I need install it on PortablePython for Windows, so it's not clear how to make this: where should be placed ssdeep Windows binary files, that Python application can found it? From breamoreboy at yahoo.co.uk Thu Mar 20 20:27:42 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Mar 2014 00:27:42 +0000 Subject: Installing ssdeep on Portable Python /advice In-Reply-To: <20140321001609.63150@gmx.com> References: <20140321001609.63150@gmx.com> Message-ID: On 21/03/2014 00:16, laguna-mc at mail.com wrote: > Portable Python 2.7 for Windows, the Python application have dependency on ssdeep-2.10, which is a binary exe. > > The ssdeep (libfuzzy) installation example was shown for Linux platform only: > ---- > a) libfuzzy can be installed via apt-get: > > $ sudo apt-get install libfuzzy2 > > b) to install libfuzzy from source, download the gzipped tarball from http://ssdeep.sourceforge.net/#download, then run: > > $ tar -zxvf ssdeep-2.10.tar.gz > $ cd ssdeep-2.10 && ./configure && make && sudo make install > ----- > I need install it on PortablePython for Windows, so it's not clear how to make this: where should be placed ssdeep Windows binary files, that Python application can found it? > You've changed the subject line but other than that this appears to be identical to the question you posed almost exactly six hours ago. It is considered polite to wait for at least 24 hours before again asking for assistance. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Thu Mar 20 20:29:55 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2014 00:29:55 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> Message-ID: <532b8803$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Mar 2014 21:28:43 +0000, notbob wrote: > On 2014-03-20, Mark H Harris wrote: > >> When I call python2 that means python2.7.6 / >> >> When I call python3 that means python3.3.4 / >> >> I can also call python2.7, which is 2.7.2 / >> >> You get the idea. There is no one set rule, because there are many >> distros (gnu/linux) that use python at various versions, and they all >> us different setups. Really , you need an install script to snoop out >> the configurables. > > Weeping Chryst on the cross!!. No wonder the latest O'Reilly book, > Learning Python, 5th ed, is 1600 pgs. I coulda swore someone sed python > is easy. ;) This has nothing to do with Python. It has to do with the way executables (applications) are mapped to file names on Unix and Unix-like systems. And that in turn is not terribly different from the way that it works on Windows as well. When you type "python" at the command prompt, your system locates an executable named "python", then runs it. If you wanted to be annoying, you could alias or link the python name to a completely different language. Or use a different name altogether: steve at orac:~$ alias snake=python steve at orac:~$ snake Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. This has nothing to do with Python, it's the way Linux works. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Thu Mar 20 20:32:48 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2014 00:32:48 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: <532b88b0$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Mar 2014 16:26:39 -0400, Ned Batchelder wrote: > On 3/20/14 3:07 PM, Eric Jacoboni wrote: >> Le 20/03/2014 16:21, Marko Rauhamaa a ?crit : >> >> >>> All tutorials will tell you to start it with >>> >>> #!/usr/bin/env python >>> >>> which will start python2 on all (?) existing linux distros, but is >>> expected to start python3 within the next decade. >> >> With Arch-Linux, python is python3... >> >> > Yes, and they have been told many times that this was foolish and wrong, > but it persists, much to our pain. How bizarre. I've been looking forward with great pleasure to Fedora moving to Python 3 as the standard system Python, expecting that this move from one of the big distros will start a chain reaction of others doing the same thing. Perhaps Arch-Linux is guilty of being prematurely Python 3, a little like those people hauled up to explain themselves to the House Unamerican Activities Committee to explain why they were a "premature anti-fascist". I have no idea what "our pain" you are referring to, or who "our" refers to. In the three or five years or so since Arch-Linux moved to Python 3 by default, I don't recall ever seeing even a single email from somebody confused by Arch-Linux's move, not here, or on the tutor mailing list, or on Python-Dev or Python-Ideas. Nor have I seen any signs of difficulty or confusion on Python-related blogs, or StackOverflow. That's not to say that there has been absolutely none at all. The Internet is a big place, and I daresay I've missed something. But given how small the Arch-Linux share of the Linux space is, I would be astonished if their move caused more than a tiny little ripple. Perhaps a paper-cut worth of pain. I expect that there have been far more angry words written over this issue than the actual consequences of the move itself. Unless you're in the unfortunate situation of having to migrate and maintain scripts across a network of mixed Linux distros including some that are Arch-Linux, it's difficult to see exactly what pain they could be causing even in principle. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Thu Mar 20 20:37:04 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2014 00:37:04 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> Message-ID: <532b89af$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Mar 2014 16:53:25 -0400, Ned Batchelder wrote: > On 3/20/14 4:42 PM, Marko Rauhamaa wrote: >> Ned Batchelder : >> >>> Plenty of people have adopted a dual-support strategy, with one code >>> base that supports both Python 2 and Python 3. The six module can help >>> a great deal with this. >> >> I wonder how easy the resulting code is to the eyes and how easy it is >> for the casual maintainer to accidentally break the delicate balance. >> In a word, I wouldn't go there. Stay with Python2 as long as you must >> and then, migrate and leave it behind. > > This is fine advice for applications, but tools, libraries, and > frameworks may want to support more than one version at the same time. +1 Actually, even applications may want to support multiple versions. If I have a Python script that does something, I might not want to tie it to one specific version. In principle there's not much difference between "this will run under Python 2.6 and 2.7" and "this will run under Python 2.7 and 3.3". In practice, it's a little trickier to cross the 2/3 barrier than the 2.6/2.7 barrier. But it is still quite achievable, with a little extra effort. But you know that even better than I -- I take my hat off to you for supporting all the way back to Python 2.3, that is far more dedicated than I am. In my experience, such as it is, the hard part about writing code that works from 2.4 to 3.4 is not the 3 versions but the 2.4 and 2.5 versions. > It's an extreme case, but the latest released version of coverage.py > supports Python 2.3 through 3.3 with one code base. To do it, there's a > compatibility layer (akin to six). Then you stay away from features > that aren't available on all versions. In a few places, you might need > to have version checks, and the code can get a little idiomatic to > continue to work. > > It's a tradeoff: you have to decide for yourself whether the effort is > worth the benefit. I was glad to be able to drop support for 2.3, 2.4, > and 2.5, and now only support 2.6-3.4 in coverage.py. Sounds like your experience agrees with mine. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Thu Mar 20 20:59:57 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2014 00:59:57 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> <87txasoaqi.fsf@elektro.pacujo.net> Message-ID: <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Mar 2014 22:50:45 +0200, Marko Rauhamaa wrote: > Mark Lawrence : > >> On 20/03/2014 20:30, Marko Rauhamaa wrote: >>> I must say, though, that Python3 destroyed "print" forever for me. To >>> avoid nausea, I write sys.stdout.write() in all Python3 code. >> >> Not for me, I was using from __future__ import print_function for years >> so got used to typing those two extra brackets, plus print very kindly >> inserts the newlines for me. > > That very realization helped me wean myself from "print." Its sole > raison d'?tre is the insertion of the newline, which it would be nicer > to micromanage anyway; that's how it's done in other programming > languages as well: C, perl, guile, ... (Well, ok, "echo" is the > exception.) echo is not "the" exception. *Many* languages handle the newline when printing: Pascal, Ruby, Io, Dylan, Haskell, Rebol, Tcl, Perl6, Java, Ocaml, ... either add a newline by default, or provide two functions for printing, one which adds newline and one which doesn't. The rule of three applies here: anything you do in three different places ought to be managed by a function. Printing a newline at the end of a line of output is *incredibly* common. Any language which fails to provide a print-with-newline function is, frankly, sub-standard. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ned at nedbatchelder.com Thu Mar 20 21:06:24 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 20 Mar 2014 21:06:24 -0400 Subject: running python 2 vs 3 In-Reply-To: <532b88b0$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532b88b0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/20/14 8:32 PM, Steven D'Aprano wrote: > On Thu, 20 Mar 2014 16:26:39 -0400, Ned Batchelder wrote: > >> On 3/20/14 3:07 PM, Eric Jacoboni wrote: >>> Le 20/03/2014 16:21, Marko Rauhamaa a ?crit : >>> >>> >>>> All tutorials will tell you to start it with >>>> >>>> #!/usr/bin/env python >>>> >>>> which will start python2 on all (?) existing linux distros, but is >>>> expected to start python3 within the next decade. >>> >>> With Arch-Linux, python is python3... >>> >>> >> Yes, and they have been told many times that this was foolish and wrong, >> but it persists, much to our pain. > > How bizarre. I've been looking forward with great pleasure to Fedora > moving to Python 3 as the standard system Python, expecting that this > move from one of the big distros will start a chain reaction of others > doing the same thing. Perhaps Arch-Linux is guilty of being prematurely > Python 3, a little like those people hauled up to explain themselves to > the House Unamerican Activities Committee to explain why they were a > "premature anti-fascist". > My understanding is that Fedora's move will not include making the word "python" mean Python 3. Their move means that Python 3 will be installed by default, and that their Python programs that are part of the distro will be Python 3 programs. They can still refer to it as "python3". > I have no idea what "our pain" you are referring to, or who "our" refers > to. In the three or five years or so since Arch-Linux moved to Python 3 > by default, I don't recall ever seeing even a single email from somebody > confused by Arch-Linux's move, not here, or on the tutor mailing list, or > on Python-Dev or Python-Ideas. Nor have I seen any signs of difficulty or > confusion on Python-related blogs, or StackOverflow. In the #python IRC channel, there's a steady flow of people who run programs they find online, and they get a syntax error on "print", and we say, "Arch?" and they say, "yup". Perhaps I overstated the amount of pain. But Arch's move prompted a PEP to be written explaining what the word "python" should mean: http://python.org/dev/peps/pep-0394/ Note that they say there that "for the time being" the word python should mean Python 2, anticipating that eventually it will be OK to change it to Python 3. But I think that change would always cause confusion, and we should not change it over. I understand that this is a controversial view, and don't hold it strongly enough to defend it. :) > > That's not to say that there has been absolutely none at all. The > Internet is a big place, and I daresay I've missed something. But given > how small the Arch-Linux share of the Linux space is, I would be > astonished if their move caused more than a tiny little ripple. Perhaps a > paper-cut worth of pain. It caused enough of a ripple to get PEP 394 written so that people wouldn't do it again. I expect that there have been far more angry > words written over this issue than the actual consequences of the move > itself. Unless you're in the unfortunate situation of having to migrate > and maintain scripts across a network of mixed Linux distros including > some that are Arch-Linux, it's difficult to see exactly what pain they > could be causing even in principle. > > > > -- Ned Batchelder, http://nedbatchelder.com From roy at panix.com Thu Mar 20 21:06:42 2014 From: roy at panix.com (Roy Smith) Date: Thu, 20 Mar 2014 21:06:42 -0400 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> <87txasoaqi.fsf@elektro.pacujo.net> <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <532b8f0d$0$29994$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > The rule of three applies here: anything you do in three different places > ought to be managed by a function. I prefer the rule of two :-) From rosuav at gmail.com Thu Mar 20 21:10:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 12:10:21 +1100 Subject: running python 2 vs 3 In-Reply-To: <532b88b0$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532b88b0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 21, 2014 at 11:32 AM, Steven D'Aprano wrote: > Perhaps Arch-Linux is guilty of being prematurely Python 3... > > I have no idea what "our pain" you are referring to, or who "our" refers > to. In the three or five years or so since Arch-Linux moved to Python 3 > by default, I don't recall ever seeing even a single email from somebody > confused by Arch-Linux's move, not here, or on the tutor mailing list, or > on Python-Dev or Python-Ideas. Nor have I seen any signs of difficulty or > confusion on Python-related blogs, or StackOverflow. > > That's not to say that there has been absolutely none at all. There definitely has been a little. Scripts that began with a "python" shebang and assumed 2.x would suddenly fail on Arch. But not a huge amount of confusion. I expect that there'll be a progressive shift - more distros will start shipping 3.x under the name "python", so script authors will be more and more aware of the difference, and before long we'll settle on explicit use of "python2" or "python3" for anything that matters. Think of the bug reports: "Your program doesn't work on Ubuntu 14.04, but change the shebang and it'll work, without breaking it for anything else". Easy fix. And then once Debian and Red Hat move to 3.x as the default system Python, everyone'll use "python2" for 2.7 (by that time, I doubt 2.6 or earlier will be supported much anywhere) and "python" for 3.x, and the transition will be complete. ChrisA From rosuav at gmail.com Thu Mar 20 21:15:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 12:15:19 +1100 Subject: running python 2 vs 3 In-Reply-To: <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> <87txasoaqi.fsf@elektro.pacujo.net> <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 21, 2014 at 11:59 AM, Steven D'Aprano wrote: > The rule of three applies here: anything you do in three different places > ought to be managed by a function. Printing a newline at the end of a > line of output is *incredibly* common. Any language which fails to > provide a print-with-newline function is, frankly, sub-standard. I wouldn't go that far. There are plenty of languages where the default (printf, write, werror, etc) doesn't add the newline, and I wouldn't call the *language* sub-standard for that. But yes, it does bug me now and then. I use my "say" function to produce one or more lines of output in Gypsum, and it guarantees complete lines (because the system works with lines, not streams of characters); and then if I use the "werror" function to write to stderr, I have to remember to add the newline. However, I think Py2's print statement has way too many weirdnesses - the trailing comma (reminiscent of BASIC, where I never liked it either), the whole "soft space" concept, etc. Py3's print function, with the keyword end="", is a lot better, though still a tad verbose. (I don't know of any solution to that.) ChrisA From ned at nedbatchelder.com Thu Mar 20 21:20:47 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 20 Mar 2014 21:20:47 -0400 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> <532b88b0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/20/14 9:06 PM, Ned Batchelder wrote: > On 3/20/14 8:32 PM, Steven D'Aprano wrote: >> On Thu, 20 Mar 2014 16:26:39 -0400, Ned Batchelder wrote: >> >>> On 3/20/14 3:07 PM, Eric Jacoboni wrote: >>>> Le 20/03/2014 16:21, Marko Rauhamaa a ?crit : >>>> >>>> >>>>> All tutorials will tell you to start it with >>>>> >>>>> #!/usr/bin/env python >>>>> >>>>> which will start python2 on all (?) existing linux distros, but is >>>>> expected to start python3 within the next decade. >>>> >>>> With Arch-Linux, python is python3... >>>> >>>> >>> Yes, and they have been told many times that this was foolish and wrong, >>> but it persists, much to our pain. >> >> How bizarre. I've been looking forward with great pleasure to Fedora >> moving to Python 3 as the standard system Python, expecting that this >> move from one of the big distros will start a chain reaction of others >> doing the same thing. Perhaps Arch-Linux is guilty of being prematurely >> Python 3, a little like those people hauled up to explain themselves to >> the House Unamerican Activities Committee to explain why they were a >> "premature anti-fascist". >> > > My understanding is that Fedora's move will not include making the word > "python" mean Python 3. Their move means that Python 3 will be > installed by default, and that their Python programs that are part of > the distro will be Python 3 programs. They can still refer to it as > "python3". From http://fedoraproject.org/wiki/Changes/Python_3_as_Default : Users shouldn't notice any changes, ... /usr/bin/python will still point to Python 2 and depending on result of discussions with FPC, "yum install python-foo" will still install Python 2 version of the package. -- Ned Batchelder, http://nedbatchelder.com From ethan at stoneleaf.us Thu Mar 20 21:23:55 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 20 Mar 2014 18:23:55 -0700 Subject: running python 2 vs 3 In-Reply-To: <532b89af$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <532b89af$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <532B94AB.7000709@stoneleaf.us> On 03/20/2014 05:37 PM, Steven D'Aprano wrote: > > In my experience, such as it is, the hard part about writing code that > works from 2.4 to 3.4 is not the 3 versions but the 2.4 and 2.5 versions. +1000! (yes, that's factorial ;) -- ~Ethan~ From cs at zip.com.au Thu Mar 20 21:33:13 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 21 Mar 2014 12:33:13 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140321013313.GA58343@cskk.homeip.net> On 21Mar2014 09:34, Chris Angelico wrote: > On Fri, Mar 21, 2014 at 9:19 AM, Gregory Ewing > > Also, unless the project is truly ancient, the > > whole history might not be as big as you expect. > > The code presumably grew to its present size > > incrementally, in an approximately monotonic > > manner, so the sum of all the diffs is probably > > about the same order of magnitude as the current > > code size. > > > > As an experiment, I just cloned a copy of the > > CPython repository, and it's about 300MB. A > > tarball of Python 3.2 that I downloaded and > > compiled earlier is about 75MB. That's a ratio > > of about 4, and CPython is a pretty ancient > > project! > > Yep! But cloning requires that you have Mercurial installed and, more > importantly, know how to use it. We don't have a huge proliferation of > source control systems these days, but if someone says "Our code is > available via Perforce", I'm going to just look for a tarball > download, rather than figure out a source control system I don't know. Someone intending to clone the project and develop will probably want the whole repository; as Gregory says - they can then easily push/pull with others. For Frank, the size of the repo is not the size of the bare code * number of changesets. There are many diff-level steps in there, making for a much smaller size. And code is small; really really small. Regarding having Mercurial installed, that is very easy, and after you've gone (eg): hg clone https://bitbucket.org/cameron_simpson/css my-copy-of-cameron's-css (or wherever the public repository is published), you can of course then walk away and work. You no longer need the public copy at all. With a DVCS the threshold is low and the advantages are high (hg or git; I'm an hg person myself). Cheers, -- Cameron Simpson I am returning this otherwise good typing paper to you because someone has printed gibberish all over it and put your name at the top. - English Professor, Ohio University From rhodri at wildebst.org.uk Thu Mar 20 22:01:51 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Fri, 21 Mar 2014 02:01:51 -0000 Subject: CallBack function in C Libraries. References: Message-ID: On Thu, 20 Mar 2014 23:56:43 -0000, wrote: >> Give the function call its required argument and the error will go >> >> away... well, at least that one. > > Yep, many thanks for the answer. > But... im totally beginner with Python. > I develop in Pascal and C and want to understand the basics of Python. > > In concrete, what must i change in the code ? In abstract, exactly the same thing that you would change if a C compiler had complained to you that you had failed to give a function call the right number of arguments. More than that I have no idea; it's your code, presumably you know what it should be doing. I have absolutely no idea how TheProc() is being called by your widgets. Are you sure it should be declared as taking a single parameter? I'm afraid it doesn't help that GoogleGroups has badly mangled the formatting of your code. I'm not quite sure what to suggest since it isn't one of the usual problems, but you might find reading https://wiki.python.org/moin/GoogleGroupsPython helpful. It will certainly help with the double-spacing in your quote above. -- Rhodri James *-* Wildebeest Herder to the Masses From rosuav at gmail.com Thu Mar 20 22:14:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 13:14:21 +1100 Subject: Question about Source Control In-Reply-To: <20140321013313.GA58343@cskk.homeip.net> References: <20140321013313.GA58343@cskk.homeip.net> Message-ID: On Fri, Mar 21, 2014 at 12:33 PM, Cameron Simpson wrote: > Regarding having Mercurial installed, that is very easy, and after > you've gone (eg): > > hg clone https://bitbucket.org/cameron_simpson/css my-copy-of-cameron's-css > > (or wherever the public repository is published), you can of course > then walk away and work. You no longer need the public copy at all. > > With a DVCS the threshold is low and the advantages are high (hg > or git; I'm an hg person myself). Yes, it's not hard to get Mercurial. And it's not hard to get git. But it is an extra barrier, and trying to tell people they need this-that-and-the-other just to get your software is a pain. Personally, I'm quite happy fetching from either git or hg, because I'm at least broadly familiar with both (more with git), but if it's something I'm *not* familiar with (cvs? Haven't used it in forever), less happy. ChrisA From rosuav at gmail.com Thu Mar 20 22:18:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 13:18:29 +1100 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> <87txasoaqi.fsf@elektro.pacujo.net> <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith wrote: > In article <532b8f0d$0$29994$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> The rule of three applies here: anything you do in three different places >> ought to be managed by a function. > > I prefer the rule of two :-) The way I explain it is: Three is a rule of thumb. Sometimes it's blatantly obvious at two, and other times you need four or five similar pieces of code before you can see which part should become the function. If the code's absolutely identical and reasonably long/complex, then yes, two's all you need, but how often is that? Usually it's similar, rather than congruent... err I mean identical. That's where the third usage comes in. Or if it's maybe 2-3 lines, used in two places, it doesn't necessarily need to be a function. Again, a third usage is a strong hint that it should be broken out. The rule doesn't say that anything that *isn't* in three places yet should *not* be broken out. :) ChrisA From rustompmody at gmail.com Thu Mar 20 22:20:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 20 Mar 2014 19:20:21 -0700 (PDT) Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> Message-ID: <9663dc26-104b-4b02-bfca-525c86d07bb9@googlegroups.com> On Friday, March 21, 2014 2:23:25 AM UTC+5:30, Ned Batchelder wrote: > On 3/20/14 4:42 PM, Marko Rauhamaa wrote: > > Ned Batchelder : > >> Plenty of people have adopted a dual-support strategy, with one code > >> base that supports both Python 2 and Python 3. The six module can help > >> a great deal with this. > > I wonder how easy the resulting code is to the eyes and how easy it is > > for the casual maintainer to accidentally break the delicate balance. In > > a word, I wouldn't go there. Stay with Python2 as long as you must and > > then, migrate and leave it behind. > This is fine advice for applications, but tools, libraries, and > frameworks may want to support more than one version at the same time. > It's an extreme case, but the latest released version of coverage.py > supports Python 2.3 through 3.3 with one code base. To do it, there's a > compatibility layer (akin to six). Then you stay away from features > that aren't available on all versions. In a few places, you might need > to have version checks, and the code can get a little idiomatic to > continue to work. > It's a tradeoff: you have to decide for yourself whether the effort is > worth the benefit. I was glad to be able to drop support for 2.3, 2.4, > and 2.5, and now only support 2.6-3.4 in coverage.py. Ned is talking to (and from) a lib-writer perspective Marko is talking from noob perspective (which is what the OP looks like) Good to choose our hats appropriately From wuwei23 at gmail.com Thu Mar 20 22:37:46 2014 From: wuwei23 at gmail.com (alex23) Date: Fri, 21 Mar 2014 12:37:46 +1000 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> Message-ID: > On 3/20/2014 3:07 PM, John Gordon wrote: > There are two ways (at least!) to run a python script: > On 21/03/2014 8:05 AM, Terry Reedy wrote: > 3. [...] "Our chief weapon is..." From dtran.ru at gmail.com Thu Mar 20 22:50:13 2014 From: dtran.ru at gmail.com (dtran.ru at gmail.com) Date: Thu, 20 Mar 2014 19:50:13 -0700 (PDT) Subject: Python - Caeser Cipher Not Giving Right Output Message-ID: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> Hello good people I am working on a caeser cipher program for class. However, I ran into a problem with my outputs. Up to a certain point for example: 1. two('y', 'z') Would give a '\x92' output instead of a 'x' output. Currently this is my code so far: def chartonum(ch): return ord(ch) - 97 def numtochar(n): return chr(n + 97) def two(c1 , c2): c1 = chartonum(c1) c2 = chartonum(c2) return numtochar(c1 + c2 %26) I am thinking I have messed up on my mod 26, however, I am at a lost where I might have went wrong in that. Any help would be appreciated. From davea at davea.name Thu Mar 20 23:16:50 2014 From: davea at davea.name (Dave Angel) Date: Thu, 20 Mar 2014 23:16:50 -0400 (EDT) Subject: Python - Caeser Cipher Not Giving Right Output References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> Message-ID: dtran.ru at gmail.com Wrote in message: > Hello good people I am working on a caeser cipher program for class. However, I ran into a problem with my outputs. Up to a certain point for example: > > 1. two('y', 'z') > > Would give a '\x92' output instead of a 'x' output. > > Currently this is my code so far: > > def chartonum(ch): > return ord(ch) - 97 > > def numtochar(n): > return chr(n + 97) > > def two(c1 , c2): > c1 = chartonum(c1) > c2 = chartonum(c2) > return numtochar(c1 + c2 %26) You're missing some parentheses in that line. To test your understanding, try picking some numbers for c1 and c2. Display c1 + c2 % 26, and see if the result is always between 0 and 25. Or look up the term precedence in your textbook. > > I am thinking I have messed up on my mod 26, however, I am at a lost where I might have went wrong in that. Any help would be appreciated. > -- DaveA From steve+comp.lang.python at pearwood.info Thu Mar 20 23:16:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2014 03:16:16 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532b88b0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <532baeff$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Mar 2014 21:06:24 -0400, Ned Batchelder wrote: > In the #python IRC channel, there's a steady flow of people who run > programs they find online, and they get a syntax error on "print", and > we say, "Arch?" and they say, "yup". When you install random programs you find online without going through your package manager, you have no guarantee that all the dependencies will be met. Particularly of third-party libraries, but also of standard Python libraries too: http://bytes.com/topic/python/answers/448757-how-enable-rotor-python-2-4-2-a If your script uses xreadlines, rotor, or mpz, using "python" to refer to both pre-2.4 and post-2.4 will cause breakage. Likewise, I've seen Python 2.6 break applications because it removed string exceptions. So I'm not seeing anything out of the ordinary with Arch: any version change has the possibility to break scripts. Python 3 is just more obvious because of the change to print, which I daresay is a little more common than rotor... Arch happens to be at the bleeding edge of that, bless them, but if you use Arch, that's what you're letting yourself into. You know what they say -- even Slackware users think Arch users are nuts :-) I've also seen scripts broken because the script used a hard-coded path to the Python executable, like /usr/bin/python or /usr/local/bin/python. Or because they've hard-coded the version number. Or because they didn't hard-code the version number. I haven't seen scripts broken because "env" has moved, but I guess that's only a matter of time. Frankly, hash-bang lines are a dirty hack, and like all dirty hacks, they work really well until they suddenly don't. -- Steven D'Aprano http://import-that.dreamwidth.org/ From dtran.ru at gmail.com Thu Mar 20 23:23:49 2014 From: dtran.ru at gmail.com (dtran.ru at gmail.com) Date: Thu, 20 Mar 2014 20:23:49 -0700 (PDT) Subject: Python - Caeser Cipher Not Giving Right Output In-Reply-To: References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> Message-ID: On Thursday, March 20, 2014 11:16:50 PM UTC-4, Dave Angel wrote: > dtran.ru at gmail.com Wrote in message: > > > Hello good people I am working on a caeser cipher program for class. However, I ran into a problem with my outputs. Up to a certain point for example: > > > > > > 1. two('y', 'z') > > > > > > Would give a '\x92' output instead of a 'x' output. > > > > > > Currently this is my code so far: > > > > > > def chartonum(ch): > > > return ord(ch) - 97 > > > > > > def numtochar(n): > > > return chr(n + 97) > > > > > > def two(c1 , c2): > > > c1 = chartonum(c1) > > > c2 = chartonum(c2) > > > return numtochar(c1 + c2 %26) > > > > You're missing some parentheses in that line. To test your > > understanding, try picking some numbers for c1 and c2. Display > > c1 + c2 % 26, and see if the result is always between 0 and > > 25. > > > > Or look up the term precedence in your textbook. > > > > > > > > I am thinking I have messed up on my mod 26, however, I am at a lost where I might have went wrong in that. Any help would be appreciated. > > > > > > > > > -- > > DaveA Thanks for your input Dave. Would the line be: return numtochar(c1 + c2 %26) c1 and c2 are lower-case letters. And I was wondering how I would add the partenthesis because I tried: return numtochar(c1 + c2 (%26)) and it gave me an error. From rosuav at gmail.com Thu Mar 20 23:34:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 14:34:28 +1100 Subject: running python 2 vs 3 In-Reply-To: <532baeff$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532b88b0$0$29994$c3e8da3$5496439d@news.astraweb.com> <532baeff$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 21, 2014 at 2:16 PM, Steven D'Aprano wrote: > I haven't seen scripts broken because "env" > has moved, but I guess that's only a matter of time. That usage is extremely common, and isn't it also specified by POSIX? I think that's about as dependable as you can get. Course, it does depend on the user's $PATH... ChrisA From davea at davea.name Fri Mar 21 00:02:39 2014 From: davea at davea.name (Dave Angel) Date: Fri, 21 Mar 2014 00:02:39 -0400 (EDT) Subject: Python - Caeser Cipher Not Giving Right Output References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> Message-ID: dtran.ru at gmail.com Wrote in message: > On Thursday, March 20, 2014 11:16:50 PM UTC-4, Dave Angel wrote: >> dtran.ru at gmail.com Wrote in message: >> > >> >> > def two(c1 , c2): >> >> > c1 = chartonum(c1) >> >> > c2 = chartonum(c2) >> >> > return numtochar(c1 + c2 %26) >> >> >> >> You're missing some parentheses in that line. To test your >> >> understanding, try picking some numbers for c1 and c2. Display >> >> c1 + c2 % 26, and see if the result is always between 0 and >> >> 25. >> >> >> >> Or look up the term precedence in your textbook. >> > >> DaveA > > Thanks for your input Dave. Would the line be: > > return numtochar(c1 + c2 %26) That would be the line I tagged, yes. > > c1 and c2 are lower-case letters. No, they're not , you just got done overwriting the letters with numbers. That's a bad habit, reusing local variables with data of different meanings, but I was trying to focus on the line with the bug. > And I was wondering how I would add the partenthesis because I tried: > > return numtochar(c1 + c2 (%26)) and it gave me an error. Please help us to help you by actually showing the traceback. Doesn't matter in this case, but... What order do you want the add and the modulo to happen? Use the parentheses to say so. Or split it into two or more lines, with another variable. Perhaps you don't understand that % is an operator, just like + and *. If you were told to add a and b before multiplying by c, how would you write that? Try it, just as you tried the other experiment I recommended. -- DaveA From steve+comp.lang.python at pearwood.info Thu Mar 20 23:58:43 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2014 03:58:43 GMT Subject: Python - Caeser Cipher Not Giving Right Output References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> Message-ID: <532bb8f3$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 20 Mar 2014 20:23:49 -0700, dtran.ru wrote: > Thanks for your input Dave. Would the line be: > > return numtochar(c1 + c2 %26) Yes, that's the line that Dave is talking about. The critical part is that expression "c1 + c2 %26" which gets calculated before being passed on to numtochar. The % operator is a form of division (it returns the remainder after division, so 12%5 returns 2) and like the regular division operator / and multiplication * it has higher precedence than addition. That means that "30 + 40 % 26" calculates the % part first: 30 + 40 % 26 => 30 + 14 => 54 What you probably want is to calculate the % last, not first. That means you need to perform the addition first. Use round brackets (parentheses) for that: (30 + 40) % 26 => 70 % 26 => 18 Does that help? -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Fri Mar 21 00:02:58 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 20 Mar 2014 21:02:58 -0700 (PDT) Subject: Python - Caeser Cipher Not Giving Right Output In-Reply-To: References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> Message-ID: <22bdaf7b-cace-46d8-a0d8-785fd5d83e74@googlegroups.com> On Friday, March 21, 2014 8:53:49 AM UTC+5:30, wrote: > On Thursday, March 20, 2014 11:16:50 PM UTC-4, Dave Angel wrote: > > > Hello good people I am working on a caeser cipher program for class. However, I ran into a problem with my outputs. Up to a certain point for example: > > > 1. two('y', 'z') > > > Would give a '\x92' output instead of a 'x' output. > > > Currently this is my code so far: > > > def chartonum(ch): > > > return ord(ch) - 97 > > > def numtochar(n): > > > return chr(n + 97) > > > def two(c1 , c2): > > > c1 = chartonum(c1) > > > c2 = chartonum(c2) > > > return numtochar(c1 + c2 %26) > > You're missing some parentheses in that line. To test your > > understanding, try picking some numbers for c1 and c2. Display > > c1 + c2 % 26, and see if the result is always between 0 and > > 25. > > Or look up the term precedence in your textbook. > > > I am thinking I have messed up on my mod 26, however, I am at a lost where I might have went wrong in that. Any help would be appreciated. > > -- > > DaveA > Thanks for your input Dave. Would the line be: > return numtochar(c1 + c2 %26) > c1 and c2 are lower-case letters. And I was wondering how I would add the partenthesis because I tried: > return numtochar(c1 + c2 (%26)) and it gave me an error. I suggest you put aside your assignment for 15 minutes. Then 1. Start up the python interpreter 2. Type ? + ?? % ??? where the ?, ??, ??? take various values between 1 and 4 3. Try to put in parenthesis (ie '( )') here and there to modify your results 4. Then read the material on 'precedence' as Dave suggested From dtran.ru at gmail.com Fri Mar 21 00:23:24 2014 From: dtran.ru at gmail.com (dtran.ru at gmail.com) Date: Thu, 20 Mar 2014 21:23:24 -0700 (PDT) Subject: Python - Caeser Cipher Not Giving Right Output In-Reply-To: <532bb8f3$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> <532bb8f3$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <32c74575-6387-45d5-ab8b-b414c035c98a@googlegroups.com> On Thursday, March 20, 2014 11:58:43 PM UTC-4, Steven D'Aprano wrote: > On Thu, 20 Mar 2014 20:23:49 -0700, dtran.ru wrote: > > > > > Thanks for your input Dave. Would the line be: > > > > > > return numtochar(c1 + c2 %26) > > > > Yes, that's the line that Dave is talking about. > > > > The critical part is that expression "c1 + c2 %26" which gets calculated > > before being passed on to numtochar. The % operator is a form of division > > (it returns the remainder after division, so 12%5 returns 2) and like the > > regular division operator / and multiplication * it has higher precedence > > than addition. > > > > That means that "30 + 40 % 26" calculates the % part first: > > > > 30 + 40 % 26 > > => 30 + 14 > > => 54 > > > > What you probably want is to calculate the % last, not first. That means > > you need to perform the addition first. Use round brackets (parentheses) > > for that: > > > > (30 + 40) % 26 > > => 70 % 26 > > => 18 > > > > > > Does that help? > > > > > > > > > > -- > > Steven D'Aprano > > http://import-that.dreamwidth.org/ Ooh I understand now! I've been coding for hours and exhaustion has gotten to my head. Many thanks all of you as I now know the source of my folly. From cs at zip.com.au Fri Mar 21 01:17:00 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 21 Mar 2014 16:17:00 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140321051700.GA35124@cskk.homeip.net> On 21Mar2014 13:14, Chris Angelico wrote: > On Fri, Mar 21, 2014 at 12:33 PM, Cameron Simpson wrote: > > Regarding having Mercurial installed, that is very easy, and after > > you've gone (eg): > > > > hg clone https://bitbucket.org/cameron_simpson/css my-copy-of-cameron's-css > > > > (or wherever the public repository is published), you can of course > > then walk away and work. You no longer need the public copy at all. > > > > With a DVCS the threshold is low and the advantages are high (hg > > or git; I'm an hg person myself). > > Yes, it's not hard to get Mercurial. And it's not hard to get git. But > it is an extra barrier, and trying to tell people they need > this-that-and-the-other just to get your software is a pain. I thought Frank's scenario involved someone cloning/forking the software. I may have misread him though. Of course, for people just wanting to build it or examine it, tarballs and other archives are highly desirable. Cheers, -- Cameron Simpson Rules of Optimization: Rule 1: Don't do it. Rule 2 (for experts only): Don't do it yet. - M.A. Jackson From frank at chagford.com Fri Mar 21 01:40:42 2014 From: frank at chagford.com (Frank Millman) Date: Fri, 21 Mar 2014 07:40:42 +0200 Subject: Question about Source Control References: <20140321013313.GA58343@cskk.homeip.net> Message-ID: "Cameron Simpson" wrote in message news:20140321013313.GA58343 at cskk.homeip.net... > > Someone intending to clone the project and develop will probably > want the whole repository; as Gregory says - they can then easily > push/pull with others. > > For Frank, the size of the repo is not the size of the bare code * > number of changesets. There are many diff-level steps in there, > making for a much smaller size. And code is small; really really > small. > Ok, I think I've got it. To make the software available to anyone who just wants to run a stable version, copy the working directory of the 'major release' repository to a directory of its own, without the .hg stuff, and make it available for download. For everyone else, just make the full repository available, and don't worry about the size. 'Everyone else' would include those wishing to collaborate on the project, and those who just wish to keep up to date with the latest updates. Actually my concern was not the 'size' of the full repository, but the prospect of wading through thousands of changesets most of which are ancient history. However, I assume that the experienced user will adopt habits such as 'hg log tip:-10' to review the last 10 changesets, so it should not be a problem. Thanks, all Frank From rosuav at gmail.com Fri Mar 21 01:47:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 16:47:07 +1100 Subject: Question about Source Control In-Reply-To: References: <20140321013313.GA58343@cskk.homeip.net> Message-ID: On Fri, Mar 21, 2014 at 4:40 PM, Frank Millman wrote: > To make the software available to anyone who just wants to run a stable > version, copy the working directory of the 'major release' repository to a > directory of its own, without the .hg stuff, and make it available for > download. > > For everyone else, just make the full repository available, and don't worry > about the size. > > 'Everyone else' would include those wishing to collaborate on the project, > and those who just wish to keep up to date with the latest updates. That sounds about right. I have a number of people who use Gypsum without any interest in coding it, but cloning the git repo is still the easiest way to (a) get the code, and (b) pull changes later. (It helps that I created a command in the program that pulls changes and then does an internal "update all" to apply those changes without restarting the program.) > Actually my concern was not the 'size' of the full repository, but the > prospect of wading through thousands of changesets most of which are ancient > history. However, I assume that the experienced user will adopt habits such > as 'hg log tip:-10' to review the last 10 changesets, so it should not be a > problem. Anyone who actually cares about the changes will need to know how to use the version control system you're using. They can then use "hg view" or "hg log" or whatever to see just what they care about; personally, I'd just use "hg log|less", which is like "git log" - when you're done reading recent stuff, hit q and get out of there. ChrisA From marko at pacujo.net Fri Mar 21 01:49:54 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 21 Mar 2014 07:49:54 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> <8738icmrw4.fsf@elektro.pacujo.net> Message-ID: <87txasksn1.fsf@elektro.pacujo.net> Chris Angelico : > go for the lowest common denominator: > > print("some single string") > > which works happily in all versions of Python. Whenever I have used "print" in my code, it has been with a >> redirection. Marko From rosuav at gmail.com Fri Mar 21 01:54:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Mar 2014 16:54:26 +1100 Subject: running python 2 vs 3 In-Reply-To: <87txasksn1.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> <8738icmrw4.fsf@elektro.pacujo.net> <87txasksn1.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 21, 2014 at 4:49 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> go for the lowest common denominator: >> >> print("some single string") >> >> which works happily in all versions of Python. > > Whenever I have used "print" in my code, it has been with a >> > redirection. Then you're probably not using "sys.stdout.write" but some other file object's write method. Also, I find it highly unusual that you never use print in its most basic and intended form. ChrisA From cs at zip.com.au Fri Mar 21 02:00:50 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 21 Mar 2014 17:00:50 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140321060050.GA87434@cskk.homeip.net> On 21Mar2014 07:40, Frank Millman wrote: > "Cameron Simpson" wrote in message > news:20140321013313.GA58343 at cskk.homeip.net... > > Someone intending to clone the project and develop will probably > > want the whole repository; as Gregory says - they can then easily > > push/pull with others. > > > > For Frank, the size of the repo is not the size of the bare code * > > number of changesets. There are many diff-level steps in there, > > making for a much smaller size. And code is small; really really > > small. > > Ok, I think I've got it. > > To make the software available to anyone who just wants to run a stable > version, copy the working directory of the 'major release' repository to a > directory of its own, without the .hg stuff, and make it available for > download. See "hg archive". It does exactly that for you. Run "hg help archive". It will also make tarballs and other archive formats. > For everyone else, just make the full repository available, and don't worry > about the size. > > 'Everyone else' would include those wishing to collaborate on the project, > and those who just wish to keep up to date with the latest updates. > > Actually my concern was not the 'size' of the full repository, but the > prospect of wading through thousands of changesets most of which are ancient > history. However, I assume that the experienced user will adopt habits such > as 'hg log tip:-10' to review the last 10 changesets, so it should not be a > problem. Yep. Also see "hg blame". (Run "hg help blame" for usage info.) For example, inside my "hg/css" repository I can say: hg blame bin/set-x and the output goes: [hg/css]fleet*> hg blame bin/set-x 2186: #!/bin/sh 11359: # 11359: # Trace execution of a command. and so on the the end of the file. That tells me when those lines of the file were last modified (by local changeset number). You could pick a line in the file that you're interested in and look at log entries for that. For example, taking "11359" from the above listing, I can go: [hg/css]fleet*> hg log -r 11359 changeset: 11359:136315cc8ec5 user: Cameron Simpson date: Wed Mar 05 10:37:09 2014 +1100 files: bin/set-x description: set-x: add --date option to timestamp command start and end, upgrade option parsing logic That is for the whole changeset, but it happens to affect just that one file. Alternatively, although there may be many many changes, for some files it is not so noisy. You might go: hg log bin/set-x to show only changes involving that particular file. Cheers, -- Cameron Simpson The aim of AI is to make computers act like the ones in the movies. - Graham Mann From marko at pacujo.net Fri Mar 21 02:08:42 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 21 Mar 2014 08:08:42 +0200 Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> <8738icmrw4.fsf@elektro.pacujo.net> <87txasksn1.fsf@elektro.pacujo.net> Message-ID: <87mwgkkrrp.fsf@elektro.pacujo.net> Chris Angelico : > Then you're probably not using "sys.stdout.write" but some other file > object's write method. Correct, sys.stderr.write would have been a more accurate choice. > Also, I find it highly unusual that you never use print in its most > basic and intended form. Printing to the stdout (hardcoded) is a relatively rare need. Mostly, I've used "print" for diagnostic messages, and whenever I've had to create actual output, I've parameterized the target object. Marko From rustompmody at gmail.com Fri Mar 21 02:51:17 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 20 Mar 2014 23:51:17 -0700 (PDT) Subject: running python 2 vs 3 In-Reply-To: <87mwgkkrrp.fsf@elektro.pacujo.net> References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <8738icppoe.fsf@elektro.pacujo.net> <87pplgoac6.fsf@elektro.pacujo.net> <8738icmrw4.fsf@elektro.pacujo.net> <87txasksn1.fsf@elektro.pacujo.net> <87mwgkkrrp.fsf@elektro.pacujo.net> Message-ID: <3bf8380e-a62e-4961-bcde-9afdd33cfe30@googlegroups.com> On Friday, March 21, 2014 11:38:42 AM UTC+5:30, Marko Rauhamaa wrote: > Chris Angelico : > > Then you're probably not using "sys.stdout.write" but some other file > > object's write method. > Correct, sys.stderr.write would have been a more accurate choice. > > Also, I find it highly unusual that you never use print in its most > > basic and intended form. > Printing to the stdout (hardcoded) is a relatively rare need. Mostly, > I've used "print" for diagnostic messages, and whenever I've had to > create actual output, I've parameterized the target object. Hear Hear! Ive no opinion on whether python 2 or 3 print is better. However I believe that people trying to help noobs would be actually more helpful if they indicated that using prints all over code is not kosher. Then whats the use/sense of print?? Debugging... From 401anil at gmail.com Fri Mar 21 04:14:48 2014 From: 401anil at gmail.com (Anil Kumar A) Date: Fri, 21 Mar 2014 01:14:48 -0700 (PDT) Subject: Need help in Python automation Message-ID: <277bdaaa-b05e-4fbe-a2e2-4c142a207ea6@googlegroups.com> ------------------------------------------------------------- Hi All, I work for an ISP. Currently we bought few switches and routers. Python is available in that switches. So I would like to write some scipts which I can run inside switch. I tried module 'os, system', but It is not executing the commands in operational and configurational mode. Those modes' prompts are '*>' and '*#'. Can somebody suggest me, if there is any module which I can use to execute commands inside a switch. I don't want to use 'socket' module as I am not connecting the box and executing commands. I am running the script inside switch. Please give some clue to start my automation. Thanks! Anil Kumar A ------------------------------------------------------------- From breamoreboy at yahoo.co.uk Fri Mar 21 05:40:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Mar 2014 09:40:40 +0000 Subject: running python 2 vs 3 In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> <87txasoaqi.fsf@elektro.pacujo.net> <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 21/03/2014 02:18, Chris Angelico wrote: > On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith wrote: >> In article <532b8f0d$0$29994$c3e8da3$5496439d at news.astraweb.com>, >> Steven D'Aprano wrote: >> >>> The rule of three applies here: anything you do in three different places >>> ought to be managed by a function. >> >> I prefer the rule of two :-) > > The way I explain it is: Three is a rule of thumb. Sometimes it's > blatantly obvious at two, and other times you need four or five > similar pieces of code before you can see which part should become the > function. If the code's absolutely identical and reasonably > long/complex, then yes, two's all you need, but how often is that? > Usually it's similar, rather than congruent... err I mean identical. > That's where the third usage comes in. Or if it's maybe 2-3 lines, > used in two places, it doesn't necessarily need to be a function. > Again, a third usage is a strong hint that it should be broken out. > > The rule doesn't say that anything that *isn't* in three places yet > should *not* be broken out. :) > > ChrisA > Everybody, and especially Antipodeans, knows that there is no rule 6 and by definition what rule 7 is :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Fri Mar 21 05:50:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Mar 2014 09:50:20 +0000 Subject: Python - Caeser Cipher Not Giving Right Output In-Reply-To: <32c74575-6387-45d5-ab8b-b414c035c98a@googlegroups.com> References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> <532bb8f3$0$29994$c3e8da3$5496439d@news.astraweb.com> <32c74575-6387-45d5-ab8b-b414c035c98a@googlegroups.com> Message-ID: On 21/03/2014 04:23, dtran.ru at gmail.com wrote: Would you please access this list via https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From sadzak at gmail.com Fri Mar 21 06:22:37 2014 From: sadzak at gmail.com (Adnan Sadzak) Date: Fri, 21 Mar 2014 11:22:37 +0100 Subject: Need help in Python automation In-Reply-To: <277bdaaa-b05e-4fbe-a2e2-4c142a207ea6@googlegroups.com> References: <277bdaaa-b05e-4fbe-a2e2-4c142a207ea6@googlegroups.com> Message-ID: Hi, there should be manufacturer documentation or API. What switch do You use? Any other info? Cheers, Adnan On Fri, Mar 21, 2014 at 9:14 AM, Anil Kumar A <401anil at gmail.com> wrote: > ------------------------------------------------------------- > Hi All, > > I work for an ISP. Currently we bought few switches and routers. Python is > available in that switches. So I would like to write some scipts which I > can run inside switch. > > I tried module 'os, system', but It is not executing the commands in > operational and configurational mode. Those modes' prompts are '*>' and > '*#'. > > Can somebody suggest me, if there is any module which I can use to execute > commands inside a switch. > > I don't want to use 'socket' module as I am not connecting the box and > executing commands. I am running the script inside switch. > > Please give some clue to start my automation. > > Thanks! > > Anil Kumar A > > ------------------------------------------------------------- > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fiensproto at gmail.com Fri Mar 21 08:02:28 2014 From: fiensproto at gmail.com (fiensproto at gmail.com) Date: Fri, 21 Mar 2014 05:02:28 -0700 (PDT) Subject: CallBack function in C Libraries. In-Reply-To: References: Message-ID: <488fbd2c-1b99-482d-a282-f3f20defbc68@googlegroups.com> > I'm afraid it doesn't help that GoogleGroups has badly mangled the > > formatting of your code. I'm not quite sure what to suggest since it > > isn't one of the usual problems, but you might find reading > > https://wiki.python.org/moin/GoogleGroupsPython helpful. It will > > certainly help with the double-spacing in your quote above. > Rhodri James *-* Wildebeest Herder to the Masses Yep, Many thanks for help.... Hum, i have find the solution, it was in "CallBack function" in help-doc. => #file fpgui-test.py from ctypes import* def TheProc(): fpgui.fpgFormWindowTitle(0, 'Boum') return 0 def TheProcBut0(): fpgui.fpgButtonSetText(0,0, 'Boum also') return 0 def TheProcBut1(): fpgui.fpgButtonSetText(0,1, 'Boum too') return 0 CMPFUNC = CFUNCTYPE(c_int) TheProcF = CMPFUNC(TheProc) TheProcB0 = CMPFUNC(TheProcBut0) TheProcB1 = CMPFUNC(TheProcBut1) fpgui = cdll.LoadLibrary("fpgui-32.dll") fpgui.fpgInitialize() fpgui.fpgSetStyle('Demo Style') fpgui.fpgFormCreate(0, -1) fpgui.fpgFormSetPosition(0, 300,100,400,200) fpgui.fpgFormWindowTitle(0, 'Hello world!') fpgui.fpgFormOnClick(0,TheProcF) fpgui.fpgButtonCreate(0,0,-1) ; fpgui.fpgButtonSetPosition(0,0, 15, 10 , 150 , 40) fpgui.fpgButtonSetText(0,0, 'BUTTON1') fpgui.fpgButtonOnClick(0,0,TheProcB0) fpgui.fpgButtonCreate(0,1,-1) ; fpgui.fpgButtonSetPosition(0,1, 15, 70 , 150, 40) fpgui.fpgButtonSetText(0,1, 'Clickme') fpgui.fpgButtonOnClick(0,1,TheProcB1) fpgui.fpgFormShow(0) fpgui.fpgRun() From alister.nospam.ware at ntlworld.com Fri Mar 21 08:09:13 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 21 Mar 2014 12:09:13 GMT Subject: running python 2 vs 3 References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> <87txasoaqi.fsf@elektro.pacujo.net> <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 21 Mar 2014 09:40:40 +0000, Mark Lawrence wrote: > On 21/03/2014 02:18, Chris Angelico wrote: >> On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith wrote: >>> In article <532b8f0d$0$29994$c3e8da3$5496439d at news.astraweb.com>, >>> Steven D'Aprano wrote: >>> >>>> The rule of three applies here: anything you do in three different >>>> places ought to be managed by a function. >>> >>> I prefer the rule of two :-) >> >> The way I explain it is: Three is a rule of thumb. Sometimes it's >> blatantly obvious at two, and other times you need four or five similar >> pieces of code before you can see which part should become the >> function. If the code's absolutely identical and reasonably >> long/complex, then yes, two's all you need, but how often is that? >> Usually it's similar, rather than congruent... err I mean identical. >> That's where the third usage comes in. Or if it's maybe 2-3 lines, used >> in two places, it doesn't necessarily need to be a function. Again, a >> third usage is a strong hint that it should be broken out. >> >> The rule doesn't say that anything that *isn't* in three places yet >> should *not* be broken out. :) >> >> ChrisA >> >> > Everybody, and especially Antipodeans, knows that there is no rule 6 and > by definition what rule 7 is :) Im sticking with rule 4 From roy at panix.com Fri Mar 21 08:23:31 2014 From: roy at panix.com (Roy Smith) Date: Fri, 21 Mar 2014 08:23:31 -0400 Subject: Question about Source Control References: Message-ID: In article , Cameron Simpson wrote: > hg blame bin/set-x > > and the output goes: > > [hg/css]fleet*> hg blame bin/set-x > 2186: #!/bin/sh > 11359: # > 11359: # Trace execution of a command. There's two things hg blame doesn't do which would be useful. First, the trivial one. I don't want lines annotated by change number, I want them annotated by the name of the person who checked it in. But, I'm sure that can be easily fixed with some simple post-processing filter, so it really falls into the bucket of "minor annoyances". The hard thing is I don't really want to know which change most recently touched the line of text. I want to know who really wrote it. It would be wonderful if hg were smart enough to be able to back-track through the change history and ignore trivial changes like whitespace, refactoring a function out of one file into another, etc. That's the real meat and potatoes of "blame". I want to know who I need to hit over the head with a clue-by-four once I fix a bug. From skip at pobox.com Fri Mar 21 09:22:28 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 21 Mar 2014 08:22:28 -0500 Subject: Github down? Message-ID: Anybody else having trouble getting to Github? I'm trying to get to the pythondotorg issue tracker: https://github.com/python/pythondotorg/issues Thx, Skip From larry.martell at gmail.com Fri Mar 21 09:24:44 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 21 Mar 2014 09:24:44 -0400 Subject: Github down? In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 9:22 AM, Skip Montanaro wrote: > Anybody else having trouble getting to Github? I'm trying to get to > the pythondotorg issue tracker: > > https://github.com/python/pythondotorg/issues They post the status at: https://twitter.com/githubstatus As of 10 minutes ago it was down. From chip9munk at gmail.com Fri Mar 21 09:29:56 2014 From: chip9munk at gmail.com (chip9munk at gmail.com) Date: Fri, 21 Mar 2014 06:29:56 -0700 (PDT) Subject: csv read _csv.Error: line contains NULL byte Message-ID: <22aeefa3-cf82-457c-ab85-6f0366ff7b4e@googlegroups.com> Hi all! I am reading from a huge csv file (> 20 Gb), so I have to read line by line: for i, row in enumerate(input_reader): # and I do something on each row Everything works fine until i get to a row with some strange symbols "0I`00?^" at that point I get an error: _csv.Error: line contains NULL byte How can i skip such row and continue going, or "decipher" it in some way? I have tried : csvFile = open(input_file_path, 'rb') csvFile = open(input_file_path, 'rU') csvFile = open(input_file_path, 'r') and nothing works. if I do: try: for i, row in enumerate(input_reader): # and I do something on each row except Exception: sys.exc_clear() i simply stop an that line. I would like to skip it and move on. Please help! Best, Chip Munk From mail at timgolden.me.uk Fri Mar 21 09:39:37 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 21 Mar 2014 13:39:37 +0000 Subject: csv read _csv.Error: line contains NULL byte In-Reply-To: <22aeefa3-cf82-457c-ab85-6f0366ff7b4e@googlegroups.com> References: <22aeefa3-cf82-457c-ab85-6f0366ff7b4e@googlegroups.com> Message-ID: <532C4119.2030507@timgolden.me.uk> On 21/03/2014 13:29, chip9munk at gmail.com wrote: > Hi all! > > I am reading from a huge csv file (> 20 Gb), so I have to read line by line: > > for i, row in enumerate(input_reader): > # and I do something on each row > > Everything works fine until i get to a row with some strange symbols "0I`00?^" > at that point I get an error: _csv.Error: line contains NULL byte > > How can i skip such row and continue going, or "decipher" it in some way? Well you have several options: Without disturbing your existing code too much, you could wrap the input_reader in a generator which skips malformed lines. That would look something like this: def unfussy_reader(reader): while True: try: yield next(reader) except csv.Error: # log the problem or whatever continue If you knew what to do with the malformed data, you strip it out and carry on. Whatever works best for you. Alternatively you could subclass the standard Reader and do something equivalent to the above in the __next__ method. TJG From skip at pobox.com Fri Mar 21 09:48:38 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 21 Mar 2014 08:48:38 -0500 Subject: Github down? In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 8:24 AM, Larry Martell wrote: > https://twitter.com/githubstatus Thanks for the pointer. I'm an old fart and don't use social media much (in fact, just closed my FB account a couple days ago). Does that mean I'm a curmudgeon? :-) Skip From kwpolska at gmail.com Fri Mar 21 09:51:54 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Fri, 21 Mar 2014 14:51:54 +0100 Subject: Github down? In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 2:48 PM, Skip Montanaro wrote: > On Fri, Mar 21, 2014 at 8:24 AM, Larry Martell wrote: >> https://twitter.com/githubstatus > > Thanks for the pointer. I'm an old fart and don't use social media > much (in fact, just closed my FB account a couple days ago). Does that > mean I'm a curmudgeon? :-) If you dislike social media (or prefer a nice website with graphs and such), then go there: https://status.github.com/ (though GitHub could qualify as social media for some?) -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From larry.martell at gmail.com Fri Mar 21 09:56:16 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 21 Mar 2014 09:56:16 -0400 Subject: Github down? In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 9:48 AM, Skip Montanaro wrote: > On Fri, Mar 21, 2014 at 8:24 AM, Larry Martell wrote: >> https://twitter.com/githubstatus > > Thanks for the pointer. I'm an old fart and don't use social media > much (in fact, just closed my FB account a couple days ago). Does that > mean I'm a curmudgeon? :-) I don't use FB or twitter, but I do use Linkedin. But going to https://twitter.com/githubstatus is not using twitter, it's just going to a web site. From info at wingware.com Fri Mar 21 10:27:11 2014 From: info at wingware.com (Wingware) Date: Fri, 21 Mar 2014 10:27:11 -0400 Subject: ANN: Wing IDE 5.0.4 released Message-ID: <532C4C3F.3010409@wingware.com> Hi, Wingware has released version 5.0.4 of Wing IDE, our cross-platform integrated development environment for the Python programming language. Wing IDE includes a professional quality code editor with vi, emacs, visual studio, and other key bindings, auto-completion, call tips, goto-definition, find uses, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ Changes in this minor release include: * Support for Python 3.4 final release * Improved Source Assistant renders PEP 287 docstrings and displays return value type * Optional New Project dialog * Improved integrated documentation display * Improved PDF formatted documentation * Support for recent git versions * Fix environment used with named entry points and launch configurations * Fix Debug Probe for Django templates * Fix inline renaming of files in the Project tool * Several optimizations * About 40 other bug fixes For details see http://wingware.com/pub/wingide/5.0.4/CHANGELOG.txt A summary of new features in Wing 5: * Redesigned GUI based on Qt and PySide * Native GUI on OS X (and better overall OS-native look and feel) * Tools and editors can be dragged around * Toolbar and editor and Project context menus are configurable * Optional mode that opens different sets of files in each editor split * Sharable color palettes and syntax highlighting configurations * Auto-editing is on by default (except some operations that have a learning curve) * Named file sets * Sharable launch configurations * Named entry points * More control over unit testing environment * Lockable editor splits * Initial preferences dialog for new users * Support for Python 3.4 * Support for Django 1.6 * Support for matplotlib on Anaconda and with MacOSX backend * Improved Source Assistant with PEP 287 docstring rendering and return types * Improved integrated and PDF documentation For more information on what's new in Wing 5, see http://wingware.com/wingide/whatsnew Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature list: http://wingware.com/wingide/features Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From breamoreboy at yahoo.co.uk Fri Mar 21 10:38:42 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Mar 2014 14:38:42 +0000 Subject: Github down? In-Reply-To: References: Message-ID: On 21/03/2014 13:22, Skip Montanaro wrote: > Anybody else having trouble getting to Github? I'm trying to get to > the pythondotorg issue tracker: > > https://github.com/python/pythondotorg/issues > > Thx, > > Skip > http://www.downforeveryoneorjustme.com/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From chip9munk at gmail.com Fri Mar 21 10:46:00 2014 From: chip9munk at gmail.com (chip9munk at gmail.com) Date: Fri, 21 Mar 2014 07:46:00 -0700 (PDT) Subject: csv read _csv.Error: line contains NULL byte In-Reply-To: References: <22aeefa3-cf82-457c-ab85-6f0366ff7b4e@googlegroups.com> Message-ID: On Friday, March 21, 2014 2:39:37 PM UTC+1, Tim Golden wrote: > Without disturbing your existing code too much, you could wrap the > > input_reader in a generator which skips malformed lines. That would look > > something like this: > > > > def unfussy_reader(reader): > > while True: > > try: > > yield next(reader) > > except csv.Error: > > # log the problem or whatever > > continue I am sorry I do not understand how to get to each row in this way. Please could you explain also this: If I define this function, how do I change my for loop to get each row? Thanks! From chip9munk at gmail.com Fri Mar 21 10:59:13 2014 From: chip9munk at gmail.com (chip9munk at gmail.com) Date: Fri, 21 Mar 2014 07:59:13 -0700 (PDT) Subject: csv read _csv.Error: line contains NULL byte In-Reply-To: References: <22aeefa3-cf82-457c-ab85-6f0366ff7b4e@googlegroups.com> Message-ID: Ok, I have figured it out: for i, row in enumerate(unfussy_reader(input_reader): # and I do something on each row Sorry, it is my first "face to face" with generators! Thank you very much! Best, Chip Munk From mail at timgolden.me.uk Fri Mar 21 10:59:01 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 21 Mar 2014 14:59:01 +0000 Subject: csv read _csv.Error: line contains NULL byte In-Reply-To: References: <22aeefa3-cf82-457c-ab85-6f0366ff7b4e@googlegroups.com> Message-ID: <532C53B5.9020000@timgolden.me.uk> On 21/03/2014 14:46, chip9munk at gmail.com wrote: > I am sorry I do not understand how to get to each row in this way. > > Please could you explain also this: > If I define this function, > how do I change my for loop to get each row? Does this help? #!python3 import csv def unfussy_reader(csv_reader): while True: try: yield next(csv_reader) except csv.Error: # log the problem or whatever print("Problem with some row") continue if __name__ == '__main__': # # Generate malformed csv file for # demonstration purposes # with open("temp.csv", "w") as fout: fout.write("abc,def\nghi\x00,klm\n123,456") # # Open the malformed file for reading, fire up a # conventional CSV reader over it, wrap that reader # in our "unfussy" generator and enumerate over that # generator. # with open("temp.csv") as fin: reader = unfussy_reader(csv.reader(fin)) for n, row in enumerate(reader): print(n, "=>", row) TJG From breamoreboy at yahoo.co.uk Fri Mar 21 11:15:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Mar 2014 15:15:02 +0000 Subject: csv read _csv.Error: line contains NULL byte In-Reply-To: References: <22aeefa3-cf82-457c-ab85-6f0366ff7b4e@googlegroups.com> Message-ID: On 21/03/2014 14:46, chip9munk at gmail.com wrote: > On Friday, March 21, 2014 2:39:37 PM UTC+1, Tim Golden wrote: > >> Without disturbing your existing code too much, you could wrap the >> >> input_reader in a generator which skips malformed lines. That would look >> >> something like this: >> >> >> >> def unfussy_reader(reader): >> >> while True: >> >> try: >> >> yield next(reader) >> >> except csv.Error: >> >> # log the problem or whatever >> >> continue > > > I am sorry I do not understand how to get to each row in this way. > > Please could you explain also this: > If I define this function, > how do I change my for loop to get each row? > > Thanks! > I'm pleased to see that you have answers. In return would you either use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From antonyjoseph89 at gmail.com Fri Mar 21 11:28:24 2014 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Fri, 21 Mar 2014 20:58:24 +0530 Subject: Implement multiprocessing without inheriting parent file handle Message-ID: Hi all, How can i implement multiprocessing without inherit file descriptors from my parent process? Please help me. regards, Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: From harrismh777 at gmail.com Fri Mar 21 12:50:18 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 11:50:18 -0500 Subject: CallBack function in C Libraries. References: <488fbd2c-1b99-482d-a282-f3f20defbc68@googlegroups.com> Message-ID: On 3/21/14 7:02 AM, fiensproto at gmail.com wrote: > Yep, Many thanks for help.... > Hum, i have find the solution, it was in "CallBack function" in help-doc. No, it was not in the "CallBack function" in help-doc ... > > def TheProc(): <================== you moved c_int from here ... > fpgui.fpgFormWindowTitle(0, 'Boum') > return 0 > {snip} > > CMPFUNC = CFUNCTYPE(c_int) <============ and placed it here ... > > TheProcF = CMPFUNC(TheProc) <========== so that when you called TheProc ... ... it wasn't "expecting" exactly one parameter. So, your python traceback no longer warns about the parameter 'mismatch' in the defined function TheProc(). I'm not picking on you, but this error was obvious; as was it's solution, so I'm just wondering ? Cheers From rosuav at gmail.com Fri Mar 21 13:23:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 04:23:54 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 11:23 PM, Roy Smith wrote: > There's two things hg blame doesn't do which would be useful. > > First, the trivial one. I don't want lines annotated by change number, > I want them annotated by the name of the person who checked it in. But, > I'm sure that can be easily fixed with some simple post-processing > filter, so it really falls into the bucket of "minor annoyances". > > The hard thing is I don't really want to know which change most recently > touched the line of text. I want to know who really wrote it. It would > be wonderful if hg were smart enough to be able to back-track through > the change history and ignore trivial changes like whitespace, > refactoring a function out of one file into another, etc. That's the > real meat and potatoes of "blame". I want to know who I need to hit > over the head with a clue-by-four once I fix a bug. Hmm. 'git blame' can do both of those things, so I'd be very surprised if 'hg blame' can't, at least with some extension(s). (The latter feature is "git blame -w filename"; -w is a standard 'git diff' option meaning "ignore whitespace".) But hey, if nothing else, you could import your hg repo into git just to blame the file... ChrisA From harrismh777 at gmail.com Fri Mar 21 13:25:36 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 12:25:36 -0500 Subject: Implement multiprocessing without inheriting parent file handle References: Message-ID: On 3/21/14 10:28 AM, Antony Joseph wrote: > How can i implement multiprocessing without inherit file descriptors > from my parent process? I'll bite... If what you mean by 'multiprocessing' is forking a process, to get a child process, which will then do some parallel processing for some reason, the answer is two-fold: 1) you can't, and 2) you might try using threads. (there are other answers too) When you fork a process the only differences between the child and the parent is 1) process number, and 2) one is the 'parent' and one is the 'child'. They are 'exact' copies of one another. In socket daemons the parent always listens on a given port, then forks a child process to establish a secondary port(s) to handle the comm link; at that point (instant) both the parent and the child ask a simple question, "Am I the parent?" If so, the code goes back to listening... if not, the code (the child) establishes the necessary comm ports and handles the server request. When finished the child notifies the parent and ends. You can try parent/child arrangements (maybe use rpc, or shared memory segments for inter process comm), or you might try threads... which are a separate unit of execution (not a full process copy) but with access to the parent's memory. Otherwise, you might want to tell the list some of the background of your difficulty, or put the difficulty in pythonic terms, or simply ask your python related question with as much simplified but complete detail as possible. Is there a python question in there someplace? marcus From invalid at invalid.invalid Fri Mar 21 13:37:24 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 21 Mar 2014 17:37:24 +0000 (UTC) Subject: Implement multiprocessing without inheriting parent file handle References: Message-ID: On 2014-03-21, Antony Joseph wrote: > How can i implement multiprocessing without inherit file descriptors from > my parent process? What one typically does if that is desired is to call fork() and then in the child process close all open file descriptors before doing any other processsing (such as exec()ing another program). -- Grant Edwards grant.b.edwards Yow! My life is a patio at of fun! gmail.com From marko at pacujo.net Fri Mar 21 13:42:19 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 21 Mar 2014 19:42:19 +0200 Subject: Implement multiprocessing without inheriting parent file handle References: Message-ID: <878us35tz8.fsf@elektro.pacujo.net> Antony Joseph : > How can i implement multiprocessing without inherit file descriptors > from my parent process? Take a look at the subprocess module: It's got the optional close_fds parameter, which is True by default. IOW, you don't need to do anything if you use subprocess.Popen() to start your child process. Incidentally, that's the preferred way. Marko From jarausch at igpm.rwth-aachen.de Fri Mar 21 13:48:49 2014 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 21 Mar 2014 17:48:49 GMT Subject: Python3 - temporarily change the file encoding Message-ID: Hi, my locale is en_US.iso88591 But now I'd like to process a restructuredtext file which is encoded in utf-8. rst2html has #!/usr/bin/python3.3 # $Id: rst2html.py 4564 2006-05-21 20:44:42Z wiemann $ # Author: David Goodger # Copyright: This module has been placed in the public domain. """ A minimal front end to the Docutils Publisher, producing HTML. """ try: import locale locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_cmdline, default_description description = ('Generates (X)HTML documents from standalone reStructuredText ' 'sources. ' + default_description) publish_cmdline(writer_name='html', description=description) -------------- Even if I comment out the part containing 'import locale' the utf-8 encoding of my rst-file is not recognized. How can I change this so that rst2html use utf-8 when reading and writing files. Of course, I don't want to change the docutils package for that. Many thanks for a hint, Helmut From python.list at tim.thechases.com Fri Mar 21 13:54:59 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 21 Mar 2014 12:54:59 -0500 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140321125459.1247f5f5@bigbox.christie.dr> On 2014-03-22 04:23, Chris Angelico wrote: > > The hard thing is I don't really want to know which change most > > recently touched the line of text. I want to know who really > > wrote it. It would be wonderful if hg were smart enough to be > > able to back-track through the change history and ignore trivial > > changes like whitespace, refactoring a function out of one file > > into another, etc. That's the real meat and potatoes of > > "blame". I want to know who I need to hit over the head with a > > clue-by-four once I fix a bug. > > Hmm. 'git blame' can do both of those things, so I'd be very > surprised if 'hg blame' can't, at least with some extension(s). > (The latter feature is "git blame -w filename"; -w is a standard > 'git diff' option meaning "ignore whitespace".) A quick "hg -help blame" suggests that it has options to at least show the author and control the ignoring of whitespace, as well as tweak other elements: -u --user list the author (long with -v) -f --file list the filename -d --date list the date (short with -q) -n --number list the revision number (default) -c --changeset list the changeset -l --line-number show line number at the first appearance -w --ignore-all-space ignore white space when comparing lines -b --ignore-space-change ignore changes in the amount of white space -B --ignore-blank-lines ignore changes whose lines are all blank I don't see a "ignore refactoring", but I'd want to chase through those more manually. From python.list at tim.thechases.com Fri Mar 21 13:59:53 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 21 Mar 2014 12:59:53 -0500 Subject: Question about Source Control In-Reply-To: <20140321125459.1247f5f5@bigbox.christie.dr> References: <20140321125459.1247f5f5@bigbox.christie.dr> Message-ID: <20140321125953.6d8853d7@bigbox.christie.dr> On 2014-03-21 12:54, Tim Chase wrote: > A quick "hg -help blame" Sigh. Accidentally hit when I meant to hit with down. That is, of course "hg help blame", formerly written there as "hg -v help blame" and accidentally sent mid-edit. -tkc From harrismh777 at gmail.com Fri Mar 21 14:16:30 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 13:16:30 -0500 Subject: Implement multiprocessing without inheriting parent file handle References: <878us35tz8.fsf@elektro.pacujo.net> Message-ID: On 3/21/14 12:42 PM, Marko Rauhamaa wrote: > http://docs.python.org/3/library/subprocess.html#popen-constructor> > It's got the optional close_fds parameter, which is True by default. > IOW, you don't need to do anything if you use subprocess.Popen() to > start your child process. Incidentally, that's the preferred way. hi Marko, of course this depends on the environment; if unix-like, then yes, elif windows well, not so much... There are caveats about stdin, stdout, and stderr; as well, there are caveats about passing fds between the two. Well, Popen() is implemented on unix and windows differently, so there is some study needed here if code is going to be run in both environments. marcus From __peter__ at web.de Fri Mar 21 14:38:53 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 21 Mar 2014 19:38:53 +0100 Subject: Python3 - temporarily change the file encoding References: Message-ID: Helmut Jarausch wrote: > Hi, > > my locale is en_US.iso88591 > > But now I'd like to process a restructuredtext file which is encoded in > utf-8. > > rst2html has > > #!/usr/bin/python3.3 > > # $Id: rst2html.py 4564 2006-05-21 20:44:42Z wiemann $ > # Author: David Goodger > # Copyright: This module has been placed in the public domain. > > """ > A minimal front end to the Docutils Publisher, producing HTML. > """ > > try: > import locale > locale.setlocale(locale.LC_ALL, '') > except: > pass > > from docutils.core import publish_cmdline, default_description > > > description = ('Generates (X)HTML documents from standalone > reStructuredText ' > 'sources. ' + default_description) > > publish_cmdline(writer_name='html', description=description) > > -------------- > > Even if I comment out the part containing 'import locale' the utf-8 > encoding of my rst-file is not recognized. > > How can I change this so that rst2html use utf-8 when reading and writing > files. Of course, I don't want to change the docutils package for that. > > Many thanks for a hint, Hm, there is an --input-encoding option that should allow you to specify the encoding on the command line. From vasudevram at gmail.com Fri Mar 21 16:42:53 2014 From: vasudevram at gmail.com (vasudevram) Date: Fri, 21 Mar 2014 13:42:53 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) Message-ID: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Hi list, Can anyone - maybe one of the Python language core team, or someone with knowledge of the internals of Python - can explain why this code works, and whether the different occurrences of the name x in the expression, are in different scopes or not? : x = [[1,2], [3,4], [5,6]] [x for x in x for x in x] I saw this on a Hacker News thread about Python, and here is a post I wrote that gives more details about it, including relevant links, how I found that it can be extended to a triply-nested list, and my thoughts about the scope issue: http://jugad2.blogspot.in/2014/03/flatten-list-of-lists-with-list.html A few people commented about it, both on my blog, and on the Python Reddit where I also submitted my post, but I'm not sure I'm convinced of their reasoning or understand it, hence posting the question here. Thanks, Vasudev Ram www.dancingbison.com jugad2.blogspot.com From rustompmody at gmail.com Fri Mar 21 16:54:00 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 21 Mar 2014 13:54:00 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Message-ID: <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> On Saturday, March 22, 2014 2:12:53 AM UTC+5:30, vasudevram wrote: > Hi list, > Can anyone - maybe one of the Python language core team, or someone with knowledge of the internals of Python - can explain why this code works, and whether the different occurrences of the name x in the expression, are in different scopes or not? : > x = [[1,2], [3,4], [5,6]] > [x for x in x for x in x] > I saw this on a Hacker News thread about Python, and here is a post I wrote that gives more details about it, including relevant links, how I found that it can be extended to a triply-nested list, and my thoughts about the scope issue: > http://jugad2.blogspot.in/2014/03/flatten-list-of-lists-with-list.html > A few people commented about it, both on my blog, and on the Python Reddit where I also submitted my post, but I'm not sure I'm convinced of their reasoning or understand it, hence posting the question here. Lets try without comprehending comprehensions :-) >>> x=[[1,2],[3,4]] >>> for x in x: ... for x in x: ... print x ... 1 2 3 4 >>> From vasudevram at gmail.com Fri Mar 21 16:56:09 2014 From: vasudevram at gmail.com (vasudevram) Date: Fri, 21 Mar 2014 13:56:09 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On Saturday, March 22, 2014 2:24:00 AM UTC+5:30, Rustom Mody wrote: > Lets try without comprehending comprehensions :-) > >>> x=[[1,2],[3,4]] > > >>> for x in x: > > ... for x in x: > > ... print x > > ... > > 1 > > 2 > > 3 > > 4 Nice and all, thanks, but doesn't answer the question. From rustompmody at gmail.com Fri Mar 21 17:09:19 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 21 Mar 2014 14:09:19 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On Saturday, March 22, 2014 2:26:09 AM UTC+5:30, vasudevram wrote: > On Saturday, March 22, 2014 2:24:00 AM UTC+5:30, Rustom Mody wrote: > > Lets try without comprehending comprehensions :-) > > >>> x=[[1,2],[3,4]] > > >>> for x in x: > > ... for x in x: > > ... print x > > ... > > 1 > > 2 > > 3 > > 4 > Nice and all, thanks, but doesn't answer the question. Which is? A 'for' introduces a scope: >>> x = 42 >>> for x in [1,2,3]: ... print x ... 1 2 3 No sign of the 42 --v ie the outer x -- inside because of scope And so we can do: >>> x = [1,2,3] >>> for x in x: ... print x ... 1 2 3 which implies that in a "for var in exp: ..." the exp is evaluated in outer scope whereas the var has a new scope inside the "..." Now repeatedly apply that principle to the nested for. Same principle for nested for in a comprehension. From ian.g.kelly at gmail.com Fri Mar 21 17:30:10 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 21 Mar 2014 15:30:10 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On Fri, Mar 21, 2014 at 3:09 PM, Rustom Mody wrote: > A 'for' introduces a scope: This is false. >>>> x = 42 >>>> for x in [1,2,3]: > ... print x > ... > 1 > 2 > 3 > > No sign of the 42 --v ie the outer x -- inside because of scope Try printing x again *after* the for loop: >>> x = 42 >>> for x in [1,2,3]: ... print(x) ... 1 2 3 >>> print(x) 3 Notice that it's still 3. If the x in the for loop were really a separately scoped variable, we would have expected to see 42 here. In fact the x used in the for loop and the x used outside of it are the same x variable. The real reason that the OP's example works is because each value that the x variable holds happens to only need to be read once. Start with this code, and work through it line-by-line: x = [[1, 2], [3, 4]] for x in x: for x in x: print(x) Initially, x is assigned the list. Then we enter the outer for loop. The expression x is evaluated once to be iterated over. The first value that the for loop iterator yields is [1, 2], which is then assigned to x. Now we enter the inner for loop. The expression x is again evaluated once to be iterated over. It first yields 1, which is assigned to x, and then printed. The inner for loop iterator then yields 2, which is also assigned to x and printed. The inner for loop iterator then raises StopIteration, and the inner for loop terminates. The outer for loop iterator then yields [3, 4], and this is assigned to x. The inner for loop evaluates this expression and runs as before. Afterward, the outer for loop iterator raises StopException, and that for loop terminates. The final value of x here will be 4: >>> x = [[1, 2], [3, 4]] >>> for x in x: ... for x in x: ... print(x) ... 1 2 3 4 >>> print(x) 4 As I hope this makes clear, no nested scopes are needed to make this happen. It works because nothing that is stored in x needs to remain there after the next thing is stored in x. From cs at zip.com.au Fri Mar 21 17:32:36 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 22 Mar 2014 08:32:36 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140321213236.GA46964@cskk.homeip.net> On 21Mar2014 08:23, Roy Smith wrote: > In article , > Cameron Simpson wrote: > > > hg blame bin/set-x > > > > and the output goes: > > > > [hg/css]fleet*> hg blame bin/set-x > > 2186: #!/bin/sh > > 11359: # > > 11359: # Trace execution of a command. > > There's two things hg blame doesn't do which would be useful. > > First, the trivial one. I don't want lines annotated by change number, > I want them annotated by the name of the person who checked it in. From "hg help blame": This command is useful for discovering when a change was made and by whom. Look at "hg blame -u" or "hg blame -uv". > The hard thing is I don't really want to know which change most recently > touched the line of text. I want to know who really wrote it. It would > be wonderful if hg were smart enough to be able to back-track through > the change history and ignore trivial changes like whitespace, > refactoring a function out of one file into another, etc. That's the > real meat and potatoes of "blame". I want to know who I need to hit > over the head with a clue-by-four once I fix a bug. That would probably be not too hard to script. The tricky bit might be identifying a particular line as the same over certain diffs. Basicly, run "hg log" for the file, and examine each of the diffs WRT to your target line. Refactoring raises the bar somewhat. Cheers, -- Cameron Simpson I am learning that criticism is not nearly as effective as sabotage. - Shanti Goldstein From greg.ewing at canterbury.ac.nz Fri Mar 21 17:34:48 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 22 Mar 2014 10:34:48 +1300 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: Rustom Mody wrote: > A 'for' introduces a scope: No, it doesn't! >>>>x = 42 >>>>for x in [1,2,3]: > ... print x > ... > 1 > 2 > 3 > > No sign of the 42 --v ie the outer x -- inside because of scope You're right that there's no sign of the 42, but it's *not* because of scope, as you'll see if you do one more print: >>> print x 3 > And so we can do: > > >>>>x = [1,2,3] >>>>for x in x: > ... print x > ... > 1 > 2 > 3 Again, if you print x after the loop has finished, you'll find that it's no longer bound to the original list. This is because Python's for-loop does *not* introduce a new scope -- there's only one x, and the for-loop is sharing it with the rest of the code. The real question is why the for-loop works in *spite* of this fact. The answer is that the for-loop machinery keeps an internal reference to the list being iterated over, so once the loop has started, it doesn't matter what x is bound to any more. -- Greg From ram.rachum at gmail.com Fri Mar 21 18:05:59 2014 From: ram.rachum at gmail.com (cool-RR) Date: Fri, 21 Mar 2014 15:05:59 -0700 (PDT) Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary Message-ID: Hi everybody, I need to install Python 3.4 final urgently, because my IDE stopped supporting Python 3.4 beta2, and I need it urgently to work. I downloaded it, but the MSI won't install. It didn't work on both of my computers (Windows 7 64bit). I managed to have the MSI dump data to log, file attached. I couldn't help but notice this line in the log: The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2726. The arguments are: HO_CHI~1|Ho_Chi_Minh A Google search shows this: http://en.wikipedia.org/wiki/Ho_Chi_Minh What the hell. Was python.org hacked by communists? Please, I need to get back to work and I can't. Thanks, Ram. From ram.rachum at gmail.com Fri Mar 21 18:08:25 2014 From: ram.rachum at gmail.com (cool-RR) Date: Fri, 21 Mar 2014 15:08:25 -0700 (PDT) Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: Message-ID: <9a740a79-17fe-40ee-8dfc-4eba914e2072@googlegroups.com> Sorry, couldn't attach the file, here's the log file: https://gist.github.com/anonymous/9697505 On Saturday, March 22, 2014 12:05:59 AM UTC+2, cool-RR wrote: > Hi everybody, > > > > I need to install Python 3.4 final urgently, because my IDE stopped supporting Python 3.4 beta2, and I need it urgently to work. > > > > I downloaded it, but the MSI won't install. It didn't work on both of my computers (Windows 7 64bit). > > > > I managed to have the MSI dump data to log, file attached. > > > > I couldn't help but notice this line in the log: > > > > The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2726. The arguments are: HO_CHI~1|Ho_Chi_Minh > > > > A Google search shows this: http://en.wikipedia.org/wiki/Ho_Chi_Minh > > > > What the hell. Was python.org hacked by communists? > > > > Please, I need to get back to work and I can't. > > > > > > Thanks, > > Ram. From rosuav at gmail.com Fri Mar 21 18:17:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 09:17:07 +1100 Subject: Question about Source Control In-Reply-To: <20140321213236.GA46964@cskk.homeip.net> References: <20140321213236.GA46964@cskk.homeip.net> Message-ID: On Sat, Mar 22, 2014 at 8:32 AM, Cameron Simpson wrote: > Basicly, run "hg log" for the file, and examine each of the diffs > WRT to your target line. > > Refactoring raises the bar somewhat. Here's one where git and hg are a lot more different. When I'm trying to find the origin of some line of code in a git repo, I often make a dummy edit to it, then pull up gitk, right-click the red "deleted" line, and hit "Show origin of this line". This will select the commit that introduced that one line, without annotating the whole rest of the file (often a slow job, especially on a big file), and then I can go from the green inserted line to the corresponding red deleted line and repeat the exercise (eg if some trivial change was made, like renaming something). I'm trying that workflow with "hg view", the nearest equivalent to gitk, but it's way slower and doesn't seem to have a right-click menu at all, so I'm not sure this is possible. Is there a convenient way to trace the origin of one line back through a few commits? ChrisA From rosuav at gmail.com Fri Mar 21 18:25:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 09:25:03 +1100 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: Message-ID: On Sat, Mar 22, 2014 at 9:05 AM, cool-RR wrote: > I downloaded it, but the MSI won't install. It didn't work on both of my computers (Windows 7 64bit). > > What the hell. Was python.org hacked by communists? First question: Where did you download from? What file did you get? (First and a halfth question: When you say "won't install", exactly what do you mean? Error message? Hard drive exploded in a fiery inferno? Your boss tapped you on the shoulder and said "Kill that process"?) Secondly, do you have a tool for checking the MD5 hash of a file? Compare the file you have against the official checksum: https://www.python.org/downloads/release/python-340/ I'm slightly surprised the python.org installers have MD5s and not something more cryptographically secure; there are GPG signatures, but it takes a bit more fiddling to check those. Finally, take the simple approach: Re-download the file, straight from python.org, and see if it happens again. ChrisA From ram.rachum at gmail.com Fri Mar 21 18:34:06 2014 From: ram.rachum at gmail.com (cool-RR) Date: Fri, 21 Mar 2014 15:34:06 -0700 (PDT) Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: Message-ID: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> I did download from python.org. I checked the md5, it was incorrect, then I downloaded again by using a proxy in Austria. (Which hopefully the communists haven't be able to infiltrate? ;) Now it worked! Woohoo! I'm still curious about the bad installation file... And what Ho Chi Minh is doing in the Python MSI. (I'm guessing it's timezone-related, but it's still far-fetched, because why would an obscure time zone file appear in the MSI log?) On Saturday, March 22, 2014 12:25:03 AM UTC+2, Chris Angelico wrote: > On Sat, Mar 22, 2014 at 9:05 AM, cool-RR wrote: > > > I downloaded it, but the MSI won't install. It didn't work on both of my computers (Windows 7 64bit). > > > > > > What the hell. Was python.org hacked by communists? > > > > First question: Where did you download from? What file did you get? > > > > (First and a halfth question: When you say "won't install", exactly > > what do you mean? Error message? Hard drive exploded in a fiery > > inferno? Your boss tapped you on the shoulder and said "Kill that > > process"?) > > > > Secondly, do you have a tool for checking the MD5 hash of a file? > > Compare the file you have against the official checksum: > > > > https://www.python.org/downloads/release/python-340/ > > > > I'm slightly surprised the python.org installers have MD5s and not > > something more cryptographically secure; there are GPG signatures, but > > it takes a bit more fiddling to check those. > > > > Finally, take the simple approach: Re-download the file, straight from > > python.org, and see if it happens again. > > > > ChrisA From ram.rachum at gmail.com Fri Mar 21 18:34:49 2014 From: ram.rachum at gmail.com (cool-RR) Date: Fri, 21 Mar 2014 15:34:49 -0700 (PDT) Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: Here's the offending MSI, if anyone wants to investigate: https://dl.dropboxusercontent.com/u/1927707/python-3.4.0.amd64.msi On Saturday, March 22, 2014 12:34:06 AM UTC+2, cool-RR wrote: > I did download from python.org. I checked the md5, it was incorrect, then I downloaded again by using a proxy in Austria. (Which hopefully the communists haven't be able to infiltrate? ;) > > > > Now it worked! Woohoo! > > > > I'm still curious about the bad installation file... And what Ho Chi Minh is doing in the Python MSI. (I'm guessing it's timezone-related, but it's still far-fetched, because why would an obscure time zone file appear in the MSI log?) > > > > On Saturday, March 22, 2014 12:25:03 AM UTC+2, Chris Angelico wrote: > > > On Sat, Mar 22, 2014 at 9:05 AM, cool-RR wrote: > > > > > > > I downloaded it, but the MSI won't install. It didn't work on both of my computers (Windows 7 64bit). > > > > > > > > > > > > > > What the hell. Was python.org hacked by communists? > > > > > > > > > > > > First question: Where did you download from? What file did you get? > > > > > > > > > > > > (First and a halfth question: When you say "won't install", exactly > > > > > > what do you mean? Error message? Hard drive exploded in a fiery > > > > > > inferno? Your boss tapped you on the shoulder and said "Kill that > > > > > > process"?) > > > > > > > > > > > > Secondly, do you have a tool for checking the MD5 hash of a file? > > > > > > Compare the file you have against the official checksum: > > > > > > > > > > > > https://www.python.org/downloads/release/python-340/ > > > > > > > > > > > > I'm slightly surprised the python.org installers have MD5s and not > > > > > > something more cryptographically secure; there are GPG signatures, but > > > > > > it takes a bit more fiddling to check those. > > > > > > > > > > > > Finally, take the simple approach: Re-download the file, straight from > > > > > > python.org, and see if it happens again. > > > > > > > > > > > > ChrisA From rosuav at gmail.com Fri Mar 21 18:42:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 09:42:56 +1100 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 9:34 AM, cool-RR wrote: > I did download from python.org. I checked the md5, it was incorrect, then I downloaded again by using a proxy in Austria. (Which hopefully the communists haven't be able to infiltrate? ;) > I think you should follow the internet version of Hanlon's Razor here: Damaged transmission before deliberate tampering. :) It's far more likely something simply got misdownloaded, and your guess about timezones is the most likely one - the Asia/Ho_Chi_Minh timezone [1], and I believe Python Windows installers include a full zoneinfo database. ChrisA [1] See https://en.wikipedia.org/wiki/Ho_Chi_Minh_City From breamoreboy at yahoo.co.uk Fri Mar 21 18:44:03 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 21 Mar 2014 22:44:03 +0000 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On 21/03/2014 22:34, cool-RR wrote: I'm pleased to see that you have answers. In return would you either use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Fri Mar 21 18:50:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 09:50:07 +1100 Subject: Implement multiprocessing without inheriting parent file handle In-Reply-To: References: <878us35tz8.fsf@elektro.pacujo.net> Message-ID: On Sat, Mar 22, 2014 at 5:16 AM, Mark H Harris wrote: > On 3/21/14 12:42 PM, Marko Rauhamaa wrote: >> >> http://docs.python.org/3/library/subprocess.html#popen-constructor> > > >> It's got the optional close_fds parameter, which is True by default. > > >> IOW, you don't need to do anything if you use subprocess.Popen() to >> start your child process. Incidentally, that's the preferred way. > > > hi Marko, of course this depends on the environment; if unix-like, then yes, > elif windows well, not so much... > > There are caveats about stdin, stdout, and stderr; as well, there are > caveats about passing fds between the two. Well, Popen() is implemented on > unix and windows differently, so there is some study needed here if code is > going to be run in both environments. There were some recent changes, though, including making CLOEXEC the default, which means that fork/exec on Unix will retain only the fds you actually want. ChrisA From ram.rachum at gmail.com Fri Mar 21 18:50:02 2014 From: ram.rachum at gmail.com (cool-RR) Date: Fri, 21 Mar 2014 15:50:02 -0700 (PDT) Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: <9458beea-9dcd-4dfe-8b94-a4516a7873e1@googlegroups.com> On Saturday, March 22, 2014 12:42:56 AM UTC+2, Chris Angelico wrote: > I think you should follow the internet version of Hanlon's Razor here: > Damaged transmission before deliberate tampering. :) It's far more > likely something simply got misdownloaded, and your guess about > timezones is the most likely one - the Asia/Ho_Chi_Minh timezone [1], > and I believe Python Windows installers include a full zoneinfo > database. The thing is, I then tried other versions of Python 3.4, like b2, and the 32 bit version, and they didn't work either... So damaged transmission of 3 separate files? I'm not seeing any other damaged files when surfing using this connection. From ram.rachum at gmail.com Fri Mar 21 18:55:42 2014 From: ram.rachum at gmail.com (cool-RR) Date: Fri, 21 Mar 2014 15:55:42 -0700 (PDT) Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: Message-ID: <793ecef5-2025-4714-a6a4-cff13c93f45d@googlegroups.com> On Saturday, March 22, 2014 12:25:03 AM UTC+2, Chris Angelico wrote: > (First and a halfth question: When you say "won't install", exactly > what do you mean? For completeness, I'll answer this question I forgot to answer, in case someone still wants to investigate: It just showed the first dialog (Something like "Preparing to install..."), after a few seconds it disappeared and then nothing. From fiensproto at gmail.com Fri Mar 21 20:22:02 2014 From: fiensproto at gmail.com (fiensproto at gmail.com) Date: Fri, 21 Mar 2014 17:22:02 -0700 (PDT) Subject: CallBack function in C Libraries. In-Reply-To: References: <488fbd2c-1b99-482d-a282-f3f20defbc68@googlegroups.com> Message-ID: Le vendredi 21 mars 2014 16:50:18 UTC, Mark H. Harris a ?crit?: > > def TheProc(): <================== you moved c_int from here ... > > > fpgui.fpgFormWindowTitle(0, 'Boum') > > > return 0 > > CMPFUNC = CFUNCTYPE(c_int) <============ and placed it here ... > > > ... it wasn't "expecting" exactly one parameter. So, your python > > traceback no longer warns about the parameter 'mismatch' in the defined > > function TheProc(). > > > > I'm not picking on you, but this error was obvious; as was it's > > solution, so I'm just wondering ? > Hello and thanks for answer. Hum, i do not understand why, but the code is working ... ;-) Some remarks : > def TheProc(): > fpgui.fpgFormWindowTitle(0, 'Boum') > return 0 <================== that does the trick... And > > CMPFUNC = CFUNCTYPE(c_int) <======== 1 argument minimum.. It seems that CFUNCTYPE() want minimum 1 argument, even if TheProc() is a simple procedure, without argument... Hum, it is my really first program in Python and im impressed how easy it was to do my Pascal (fpc) library work! Im busy to try to do it work for java programs but it is not so easy. By the way, is it possible to hide the terminal-window ? That library is a complete graphic widget set (from Form to Stringgrid and more). So, i will prefer that the console was hided... And last question, how to retrieve the directory of the main Python application ? Many thanks. From dan at tombstonezero.net Fri Mar 21 20:57:03 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Sat, 22 Mar 2014 00:57:03 +0000 (UTC) Subject: Github down? References: Message-ID: On Fri, 21 Mar 2014 14:51:54 +0100, Chris ?Kwpolska? Warrick wrote: > (though GitHub could qualify as social media for some?) +1 QOTW From tjreedy at udel.edu Fri Mar 21 21:39:21 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 21 Mar 2014 21:39:21 -0400 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: <793ecef5-2025-4714-a6a4-cff13c93f45d@googlegroups.com> References: <793ecef5-2025-4714-a6a4-cff13c93f45d@googlegroups.com> Message-ID: On 3/21/2014 6:55 PM, cool-RR wrote: > On Saturday, March 22, 2014 12:25:03 AM UTC+2, Chris Angelico wrote: >> (First and a halfth question: When you say "won't install", exactly >> what do you mean? > > For completeness, I'll answer this question I forgot to answer, in case someone still wants to investigate: It just showed the first dialog (Something like "Preparing to install..."), after a few seconds it disappeared and then nothing. Does your .b2 install work? Can you delete it thru the programs list? -- Terry Jan Reedy From rustompmody at gmail.com Fri Mar 21 22:06:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 21 Mar 2014 19:06:06 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On Saturday, March 22, 2014 3:00:10 AM UTC+5:30, Ian wrote: > On Fri, Mar 21, 2014 at 3:09 PM, Rustom Mody wrote: > > A 'for' introduces a scope: > This is false. And On Saturday, March 22, 2014 3:04:48 AM UTC+5:30, Gregory Ewing wrote: > > A 'for' introduces a scope: > No, it doesn't! Ha -- funny that *I* missed that one. Thanks both Ian and Gregory In fact one of my grumbles against python is that list comprehension's are a poor imitation of haskell's comprehensions. And then I promptly forgot about it! Actually there are two leakages in python 2, one of which is corrected in python 3. One: a comprehension variable leaks outside after the comprehension This is corrected in python3. Two: A comprehension variable is not bound but reassigned across the comprehension. This problem remains in python3 and causes weird behavior when lambdas are put in a comprehension >>> fl = [lambda y : x+y for x in [1,2,3]] >>> [fl[i](2) for i in [0,1,2]] [5, 5, 5] The same in haskell: Prelude> let fl = [\ y -> x + y | x <- [1,2,3]] Prelude> [(fl!!i) 0 | i<- [0,1,2]] [1,2,3] From rosuav at gmail.com Fri Mar 21 22:41:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 13:41:27 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 1:06 PM, Rustom Mody wrote: > Two: A comprehension variable is not bound but reassigned across the > comprehension. This problem remains in python3 and causes weird behavior when > lambdas are put in a comprehension > >>>> fl = [lambda y : x+y for x in [1,2,3]] >>>> [fl[i](2) for i in [0,1,2]] > [5, 5, 5] To clarify, what you're saying here is that x in the first comprehension's closures should be bound to separate values for x, yes? I'm not sure how that ought to be done. Having closures that can reference and modify each other's variables is important. def func_pair(): x = 0 def inc(): nonlocal x; x+=1 return x def dec(): nonlocal x; x-=1 return x return inc, dec fooup, foodn = func_pair() barup, bardn = func_pair() >>> fooup(), fooup(), fooup(), foodn() (1, 2, 3, 2) >>> barup(), barup(), bardn(), bardn() (1, 2, 1, 0) Those functions are fundamentally linked. Very useful with callbacks. A nice alternative to doing everything with bound methods. So if that's not going to be broken, how is this fundamentally different? def func_loop(): for x in 1,2,3: yield (lambda: x) one, two, three = func_loop() one(), one(), two(), two(), three(), three() This one does NOT work the way the names imply, and I can see that you'd like to fix it. But I can't pinpoint a significant difference between them. How do you distinguish? ChrisA From cs at zip.com.au Fri Mar 21 22:49:33 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 22 Mar 2014 13:49:33 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140322024933.GA51643@cskk.homeip.net> On 22Mar2014 09:17, Chris Angelico wrote: > On Sat, Mar 22, 2014 at 8:32 AM, Cameron Simpson wrote: > > Basicly, run "hg log" for the file, and examine each of the diffs > > WRT to your target line. > > > > Refactoring raises the bar somewhat. > > Here's one where git and hg are a lot more different. You might find it is just a matter of knowing what tool to use. > When I'm trying to find the origin of some line of code in a git repo, > I often make a dummy edit to it, then pull up gitk, right-click the > red "deleted" line, and hit "Show origin of this line". This will > select the commit that introduced that one line, without annotating > the whole rest of the file (often a slow job, especially on a big > file), and then I can go from the green inserted line to the > corresponding red deleted line and repeat the exercise (eg if some > trivial change was made, like renaming something). I'm trying that > workflow with "hg view", the nearest equivalent to gitk, but it's way > slower and doesn't seem to have a right-click menu at all, so I'm not > sure this is possible. Is there a convenient way to trace the origin > of one line back through a few commits? I don't know. You might do better to ask this kind of question on the mercurial list: http://selenic.com/mailman/listinfo/mercurial Someone there is bound to have wanted to do this kind of thing, and may know if there's a tool or extension that makes it easy. There's a whole expression syntax for getting mercurial to select from the revision tree, for example; I do not know if it is applicable in this case. Cheers, -- Cameron Simpson Do what you think is interesting, do something that you think is fun and worthwhile, because otherwise you won't do it well anyway. - Brian Kernighan From harrismh777 at gmail.com Fri Mar 21 22:51:09 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 21:51:09 -0500 Subject: Installing ssdeep on Portable Python /advice References: Message-ID: On 3/20/14 7:16 PM, laguna-mc at mail.com wrote: > $ tar -zxvf ssdeep-2.10.tar.gz > $ cd ssdeep-2.10&& ./configure&& make&& sudo make install > I need install it on PortablePython for Windows, so it's not > clear how to make this: where should be placed ssdeep Windows > binary files, that Python application can found it? It is strongly recommended that ssdeep be run on windows from precompiled binaries. Building from sources is not recommended because of dependencies and environment... Google is our frined; http://ssdeep.sourceforge.net/usage.html marcus From rosuav at gmail.com Fri Mar 21 23:05:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 14:05:21 +1100 Subject: Question about Source Control In-Reply-To: <20140322024933.GA51643@cskk.homeip.net> References: <20140322024933.GA51643@cskk.homeip.net> Message-ID: On Sat, Mar 22, 2014 at 1:49 PM, Cameron Simpson wrote: > You might do better to ask this kind of question on the mercurial list: > > http://selenic.com/mailman/listinfo/mercurial > > Someone there is bound to have wanted to do this kind of thing, and > may know if there's a tool or extension that makes it easy. I don't personally need it, because all my code is stored in git (as are most of the other big projects that I'm involved in); was mainly wondering if someone happened to know, such that Frank could make use of it. But it's a suggested workflow, and if it appeals to someone, they can raise the issue on Mercurial's list. ChrisA From harrismh777 at gmail.com Fri Mar 21 23:32:43 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 22:32:43 -0500 Subject: Installing ssdeep on Portable Python /advice References: Message-ID: On 3/21/14 9:51 PM, Mark H Harris wrote: > On 3/20/14 7:16 PM, laguna-mc at mail.com wrote: >> $ tar -zxvf ssdeep-2.10.tar.gz >> $ cd ssdeep-2.10&& ./configure&& make&& sudo make install >> I need install it on PortablePython for Windows, so it's not >> clear how to make this: where should be placed ssdeep Windows >> binary files, that Python application can found it? > It is strongly recommended that ssdeep be run on windows from > precompiled binaries. Building from sources is not recommended because > of dependencies and environment... > Google is our frined; > http://ssdeep.sourceforge.net/usage.html Actually, I restated that wrong. The doc says that building from sources on windows is NOT supported. marcus From harrismh777 at gmail.com Fri Mar 21 23:58:37 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 22:58:37 -0500 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On 3/21/14 5:44 PM, Mark Lawrence wrote: > I'm pleased to see that you have answers. In return would you either use > the mailing list https://mail.python.org/mailman/listinfo/python-list or > read and action this https://wiki.python.org/moin/GoogleGroupsPython to > prevent us seeing double line spacing and single line paragraphs, thanks. I perceive that this is your singular pet peeve, or, you were elected by the python community some time ago to police the line-end problem ? I notice (since moving my stuff to Thunderbird two weeks back) the double spacing you keep squawking about, but I don't find it the big nuisance you're talking about; ok, so we have to scroll a bit further. I am honestly convinced that this might even be a python problem. More likely than not, gg is written in python, and this is the goofy line-end character problem we have to deal with when we read lines in python. Why do we suck in the new-line character as though it were part of the line? This is asinine behavior. The new-line is a "file" delimiter character and NOT intended to be part of the line. Thinking this through a bit I've noticed that a blank line comes back with a '\n' which differentiates it from file end which comes back "without" the new-line. So, it appears that python is using the new-line character (or lack there-of) to have meaning which the new=line in a unix file was never suppose to carry. If python would just return EOF like every other language at file end, and a test line without '\n' tacked to the end of it, this little snag with gg would probably go away. What say you? Of course, that does not alleviate all of the rest of gg's short comings! marcus From rosuav at gmail.com Sat Mar 22 00:15:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 15:15:21 +1100 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 2:58 PM, Mark H Harris wrote: > On 3/21/14 5:44 PM, Mark Lawrence wrote: >> >> I'm pleased to see that you have answers. In return would you either use >> the mailing list https://mail.python.org/mailman/listinfo/python-list or >> read and action this https://wiki.python.org/moin/GoogleGroupsPython to >> prevent us seeing double line spacing and single line paragraphs, thanks. > > > I perceive that this is your singular pet peeve, or, you were elected by the > python community some time ago to police the line-end problem ? Communities maintain standards by policing them. If nobody cares enough to post, the problem will remain. He happens to be one of the most frequent commenters on this particular issue, but believe you me, he is not the only one to wish it were solved; I used to speak up too, but became tired of saying it (and of the blowback), and now I ignore all double-spaced junk. If I can't figure out what's going on without the context, I'll just move on to the next post. > I notice (since moving my stuff to Thunderbird two weeks back) the double > spacing you keep squawking about, but I don't find it the big nuisance > you're talking about; ok, so we have to scroll a bit further. It compounds. One reply makes for double spacing... two makes quadruple, three means we have seven wasted lines between every pair of real lines. That gets pretty annoying. And considering that most people who reply without cleaning up the lines also keep the entire quoted text (and usually top-post as well), this gets big fast. > I am honestly convinced that this might even be a python problem. More > likely than not, gg is written in python, and this is the goofy line-end > character problem we have to deal with when we read lines in python. No idea why you should think this; it's more likely to be based on HTML parsing (newline -> paragraph -> double newline), especially since the original text is usually unwrapped. > Why do we suck in the new-line character as though it were part of the line? > This is asinine behavior. The new-line is a "file" delimiter character and > NOT intended to be part of the line. > > Thinking this through a bit I've noticed that a blank line comes back with a > '\n' which differentiates it from file end which comes back "without" the > new-line. So, it appears that python is using the new-line character (or > lack there-of) to have meaning which the new=line in a unix file was never > suppose to carry. > > If python would just return EOF like every other language at file end, and a > test line without '\n' tacked to the end of it, this little snag with gg > would probably go away. What say you? Personally, I think that iterating over the lines in a file (in the most obvious way) should strip delimiters. There should be a less-obvious way to iterate over the "lines complete with their line ends", which can then be used to distinguish between the different line endings (including the absence of one at the end of the file), but most of the time you want to just treat a file as a series of lines, and don't care about the distinctions. However, that ship has sailed; it's way WAY too late to make any such change. And changing it would not fix the Google Groups problem unless it also broke a whole pile of other code out there. ChrisA From harrismh777 at gmail.com Sat Mar 22 00:30:06 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 23:30:06 -0500 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On 3/21/14 11:15 PM, Chris Angelico wrote: > It compounds. One reply makes for double spacing... two makes > quadruple, three means we have seven wasted lines between every pair > of real lines. That gets pretty annoying. And considering that most > people who reply without cleaning up the lines also keep the entire > quoted text (and usually top-post as well), this gets big fast. Yes, I can see that readily/ I get it, it just seems that fixing it at the source (gg) is the answer; because there will always be someone new to the list who is using gg because its part of their suite and because its convenient (I mean, that's why I tried to use it). I think we need to be beating up on the gg people so they get their stuff working. > Personally, I think that iterating over the lines in a file (in the > most obvious way) should strip delimiters. agreed. > most of the time you want to just treat a file as a series of > lines, and don't care about the distinctions. However, that ship has > sailed; it's way WAY too late to make any such change. agreed again, on both counts. > And changing it would not fix the Google Groups problem unless it also > broke a whole pile of other code out there. No doubt. Well, I don't mind dealing with it/ and frankly, I don't really think its a python problem anyway at the root. All files should have standard delimiters. What I used to call flat-text files should have standard line-end delimiters, and standard file-end EOF markers. All OS's should comply with the standard... for instance, there should not be a windows x'0a' x'0d' line ending, and a unix x'0d' line ending. Well, and now that I'm thinking about this again, since we have unicode, maybe we should have an entire set of standard "file" delimiters for flat-files. But the bottom line (pun intended) is that I just want to suck the lines in, and I only want the system to have to handle the delimiters; I'm not asking for any changes mind you (at this point) just thinking out-loud. Cheers dude. From harrismh777 at gmail.com Sat Mar 22 00:36:27 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 23:36:27 -0500 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On 3/21/14 11:30 PM, Mark H Harris wrote: > All OS's should comply with the standard... for instance, there should > not be a windows x'0a' x'0d' line ending, and a unix x'0d' line ending. whoops... I meant unix x'0a' line ending... ;-) '\n' :-)) From rustompmody at gmail.com Sat Mar 22 00:39:55 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 21 Mar 2014 21:39:55 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On Saturday, March 22, 2014 8:11:27 AM UTC+5:30, Chris Angelico wrote: > On Sat, Mar 22, 2014 at 1:06 PM, Rustom Mody wrote: > > Two: A comprehension variable is not bound but reassigned across the > > comprehension. This problem remains in python3 and causes weird behavior when > > lambdas are put in a comprehension > >>>> fl = [lambda y : x+y for x in [1,2,3]] > >>>> [fl[i](2) for i in [0,1,2]] > > [5, 5, 5] > To clarify, what you're saying here is that x in the first > comprehension's closures should be bound to separate values for x, > yes? Yes > I'm not sure how that ought to be done. Thats an implementation question -- see below. > Having closures that can > reference and modify each other's variables is important. Yes > def func_pair(): > x = 0 > def inc(): > nonlocal x; x+=1 > return x > def dec(): > nonlocal x; x-=1 > return x > return inc, dec > fooup, foodn = func_pair() > barup, bardn = func_pair() > >>> fooup(), fooup(), fooup(), foodn() > (1, 2, 3, 2) > >>> barup(), barup(), bardn(), bardn() > (1, 2, 1, 0) > Those functions are fundamentally linked. Very useful with callbacks. > A nice alternative to doing everything with bound methods. Yes > So if that's not going to be broken, how is this fundamentally different? > def func_loop(): > for x in 1,2,3: > yield (lambda: x) Thats using a for-loop A 'for' in a comprehension carries a different intention, the matching names being merely coincidental. This 'pun' causes cognitive dissonance in all these questions, including my gaffe above > one, two, three = func_loop() > one(), one(), two(), two(), three(), three() > This one does NOT work the way the names imply, and I can see that > you'd like to fix it. But I can't pinpoint a significant difference > between them. How do you distinguish? Using closures for carrying state is a different question As for comprehensions, the appropriate *intention* would be like this: Given fl = [lambda y : x+y for x in [1,2,3]] It means: def rec(l): if not l: return [] else: x,ll = l[0],l[1:] return [lambda y: x + y] + rec(ll) followed by fl = rec([1,2,3]) Naturally a reasonable *implementation* would carry this *intention* more efficiently with standard techniques like 1. Using list extend/append methods 2. Using lambda y, x=x: x+y Inside an implementation this is fine Forcing such tricks as kosher on a programmer is not (IMHO) [But then I find Lisp and much of basic haskell natural and most of C++ not, so my views are likely prejudiced :-) From rosuav at gmail.com Sat Mar 22 00:46:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 15:46:22 +1100 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 3:30 PM, Mark H Harris wrote: > All files should have standard delimiters. What I used to call flat-text > files should have standard line-end delimiters, and standard file-end EOF > markers. All OS's should comply with the standard... for instance, there > should not be a windows x'0a' x'0d' line ending, and a unix x'0d' line > ending. (Side point: You have your 0d and your 0a backwards; the Unix line ending is U+000A, and the Windows default is U+000D U+000A.) How are you going to make people change? What are you going to make them change to? Who controls this standard, and how do you convince all OSes to comply with it? ChrisA From steve+comp.lang.python at pearwood.info Sat Mar 22 00:47:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2014 04:47:36 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <532d15e8$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Mar 2014 19:06:06 -0700, Rustom Mody wrote: > Two: A comprehension variable is not bound but reassigned across the > comprehension. This problem remains in python3 and causes weird behavior > when lambdas are put in a comprehension I don't know why you say the behaviour in Python is a problem. It's somewhat unexpected if you don't think about what's going on, but it's actually quite logical. On the contrary, I find the Haskell version weird. >>>> fl = [lambda y : x+y for x in [1,2,3]] >>>> [fl[i](2) for i in [0,1,2]] > [5, 5, 5] This makes perfect sense: by the time you call the functions, the name x has been rebound to the value 3. If x were a global, or if comprehensions leaked their variable, that would be obvious: you could print x and see exactly what value it has. But visible or not, that's exactly what happens. Since x is 3, you're adding 3+2 and should get 5 no matter which function you call. Unroll the first comprehension, and it's obvious what is going on: def unrolled(): fl = [] x = 0 def lambda_(y): return x + y fl.append(lambda_) x = 1 def lambda_(y): return x + y fl.append(lambda_) x = 2 def lambda_(y): return x + y fl.append(lambda_) return [f(2) for f in fl] Don't be fooled by the coincidence that the three "lambda_" functions have the same name and body. They could have different names and different bodies, Either way, it is completely natural that they all closures over the same x -- that's how you wrote them. But the Haskell version, on the other hand, is just weird: > The same in haskell: > > Prelude> let fl = [\ y -> x + y | x <- [1,2,3]] > Prelude> [(fl!!i) 0 | i<- [0,1,2]] > [1,2,3] For this to be the case, the functions in fl have to somehow "look back in time" to see the value of x, not as it is *now* when the function is called, but how it *was* when it was created. That's very weird indeed. If x were a global, it would be astonishing. The fact that x comes from a closure instead makes it no less surprising. Unroll the loop, and the magic is obvious. Now I'm not sure precisely how Haskell implements this trick, but it suggests to me that it creates a different closure each time around the loop of the comprehension. That could end up being very expensive. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sat Mar 22 00:51:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 15:51:13 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 3:39 PM, Rustom Mody wrote: >> So if that's not going to be broken, how is this fundamentally different? > >> def func_loop(): >> for x in 1,2,3: >> yield (lambda: x) > > Thats using a for-loop > A 'for' in a comprehension carries a different intention, the matching names > being merely coincidental. So what you're saying is that these two are fundamentally different: def unrolled(): x = 1 yield (lambda: x) x = 2 yield (lambda: x) x = 3 yield (lambda: x) def loop(): for x in 1,2,3: yield (lambda: x) In other words, a loop should be implemented as a separate binding each time, not a rebinding. That's an interesting point, and it does make some sense; effectively, what you want is for the body of a for loop to be a new scope, a unique scope every iteration of the loop, and one that automatically closes over all variables in the parent scope (including for assignments) except for the loop iteration/counter variable. That does make some sense, but it doesn't really fit Python's concept. It would, however, fit a more C-like language, where locals are declared (in Python, you'd have to put a whole lot of implicit 'nonlocal' statements at the top of the loop). ChrisAg From harrismh777 at gmail.com Sat Mar 22 00:51:38 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 23:51:38 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On 3/21/14 11:39 PM, Rustom Mody wrote: > Given > fl = [lambda y : x+y for x in [1,2,3]] > It means: > def rec(l): > if not l: return [] > else: > x,ll = l[0],l[1:] > return [lambda y: x + y] + rec(ll) > > followed by > fl = rec([1,2,3]) > Naturally a reasonable *implementation* would carry this *intention* {snip} > [But then I find Lisp and much of basic haskell natural and most of C++ not, > so my views are likely prejudiced :-) This discussion (the entire thread) comes up again and again over the years because python tries to be all things to all people, without much reason behind the motivation. I'm speaking of Lambda (filter, map, reduce). Python is not Lisp. (I love Lisp too). Python is not Haskell (I love Haskell too). Lambda is a problem, if only because it causes confusion. What's the problem? Glad you asked. The constructs DO NOT work the way most people would expect them to, having limited knowledge of python! I ran into this thing about seven years ago (when I was studying Haskell, and Scheme) and I wanted to see how "pure functional" python was (well, not at all really). I can see uses for python's lambda. But, honestly, I think python could deprecate its use and in five years just remove it from the language; along with filter, map, and reduce ! I'm just saying; marcus From harrismh777 at gmail.com Sat Mar 22 00:59:34 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 21 Mar 2014 23:59:34 -0500 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On 3/21/14 11:46 PM, Chris Angelico wrote: > (Side point: You have your 0d and your 0a backwards; the Unix line > ending is U+000A, and the Windows default is U+000D U+000A.) Yeah, I know... smart apple. > How are you going to make people change? What are you going to make > them change to? Who controls this standard, and how do you convince > all OSes to comply with it? Well, we're already doing this to some extent; baby steps. Well, we have open document standards (evolving) and we have a really good sense for unicode (and python is being a genuine leader there) and the flat-file is just another open document (very simple no doubt), not different from a standards viewpoint than rft, odt, {whatever}; txt? My idea is that as we are morphing open document standards we need to keep the "flat-file" in mind too. The ASCII ship has sailed too. Unicode is in, ASCII is out (for all intents and purposes) except at Microsoft---and its time to rethink what a "flat" unicode text file really is. That's all. marcus From rosuav at gmail.com Sat Mar 22 01:05:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 16:05:29 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <532d15e8$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d15e8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 22, 2014 at 3:47 PM, Steven D'Aprano wrote: > Now I'm not sure precisely how Haskell implements this trick, but it > suggests to me that it creates a different closure each time around the > loop of the comprehension. That could end up being very expensive. It needn't be terribly expensive, if you make a "scope stack" or "scope chain". Imagine, if you will, a system of scopes like this: current_scope = None class Scope: def __init__(self, *a, **kw): self.names = dict(*a, **kw) global current_scope self.parent = current_scope current_scope = self def __getitem__(self, name): try: return self.names[name] except KeyError: if self.parent is None: raise return self.parent[name] def __setitem__(self, name, value): self.names[name] = value def exit_scope(): global current_scope current_scope = current_scope.parent Creating a new scope would be fairly cheap (and a lot more so if this were implemented in C without the object overhead, of course). Lookups would scan up through a series of namespaces, same as they currently do (local, module, builtins), there'd just be more of them. And the compiler could be smart enough to skip creating a scope if there are no assignments. There'd need to be some handling in there for the 'nonlocal' keyword, but my expectation is that 'global' is handled by retaining a reference to the current_scope at module level, and starting the search there for a LOAD_GLOBAL. Each iteration of the loop could begin with Scope() and end with exit_scope(), and there you are, each iteration in its own closable scope. I'm not saying it would be a good thing to do - and it'd be a bad fit for Python, I think, as I said in my other post - but it could be done. ChrisA From tjreedy at udel.edu Sat Mar 22 01:24:33 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Mar 2014 01:24:33 -0400 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On 3/22/2014 12:30 AM, Mark H Harris wrote: > On 3/21/14 11:15 PM, Chris Angelico wrote: >> It compounds. One reply makes for double spacing... two makes >> quadruple, three means we have seven wasted lines between every pair >> of real lines. That gets pretty annoying. And considering that most >> people who reply without cleaning up the lines also keep the entire >> quoted text (and usually top-post as well), this gets big fast. Before Mark started asking people adjust to the foibles of gg, we used to get such posts. I refused to read them. I have not seen one lately, say maybe his nudging has had some positive effect. > Yes, I can see that readily/ I get it, it just seems that fixing it > at the source (gg) is the answer; I completely agree. However, Google seems immune to suggestions, including requests that it try to stop being a major source of spam posts. > because there will always be someone > new to the list who is using gg because its part of their suite and > because its convenient (I mean, that's why I tried to use it). If I were in charge of the software used for this list, I would replace Mark with a custom addition to return mis-formated posts (more blank lines than not) with instructions on how to fix them. But I am not. -- Terry Jan Reedy From rustompmody at gmail.com Sat Mar 22 01:26:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 21 Mar 2014 22:26:26 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> On Saturday, March 22, 2014 10:21:13 AM UTC+5:30, Chris Angelico wrote: > On Sat, Mar 22, 2014 at 3:39 PM, Rustom Mody wrote: > >> So if that's not going to be broken, how is this fundamentally different? > >> def func_loop(): > >> for x in 1,2,3: > >> yield (lambda: x) > > Thats using a for-loop > > A 'for' in a comprehension carries a different intention, the matching names > > being merely coincidental. > So what you're saying is that these two are fundamentally different: > def unrolled(): > x = 1 > yield (lambda: x) > x = 2 > yield (lambda: x) > x = 3 > yield (lambda: x) > def loop(): > for x in 1,2,3: > yield (lambda: x) Well almost... Except that the 'loop' I am talking of is one of def loop(): return [yield (lambda: x) for x in [1,2,3]] or return (yield (lambda: x) for x in [1,2,3]) or just plain ol (lambda x: for x in [1,2,3]) IOW loop is an imperative construct, comprehensions are declarative Progressing through a loop in a sequential order is natural and to be expected Comprehensions being declarative, progressing through them in some order is incidental. > In other words, a loop should be implemented as a separate binding > each time, not a rebinding. That's an interesting point, and it does > make some sense; effectively, what you want is for the body of a for > loop to be a new scope, a unique scope every iteration of the loop, > and one that automatically closes over all variables in the parent > scope (including for assignments) except for the loop > iteration/counter variable. > That does make some sense, but it doesn't really fit Python's concept. Yes it does not fit in with imperative programming. Its good to remember the history. Haskell did not invent comprehensions In programming, they started with Miranda where they were called 'ZF-expressions' after the Zermelo/Fraenkel of axiomatic set theory. Because Russell's paradox had shaken the (intended) foundations of mathematics, the way out (actually the one chosen by Zermelo and Fraenkel) was to add a *comprehension axiom* http://en.wikipedia.org/wiki/Zermelo%E2%80%93Fraenkel_set_theory#3._Axiom_schema_of_specification_.28also_called_the_axiom_schema_of_separation_or_of_restricted_comprehension.29 What this basically mandates is that set constructions like {x | Pred(x) } are disqualified (called unrestricted comprehension) Only {x ? S | Pred(x) } is a valid. IOW sets cannot be concocted out of the blue but only out of other sets. Fast forward 50 years and what David Turner ? inventor of Miranda ?- realized is that if the programming language is sufficiently mathematical ? ie no imperative constructs plus lazy evaluation, then comprehensions are actually constructive enough to make make into programming constructs. However as Mark Harris points out imperative and functional thinking styles remain somewhat inconsistent with each other. From rosuav at gmail.com Sat Mar 22 01:32:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 22 Mar 2014 16:32:06 +1100 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 4:24 PM, Terry Reedy wrote: > If I were in charge of the software used for this list, I would replace Mark > with a custom addition to return mis-formated posts (more blank lines than > not) with instructions on how to fix them. But I am not. I love how this makes it sound as if Mark is part of Mailman... ChrisA From rustompmody at gmail.com Sat Mar 22 01:48:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 21 Mar 2014 22:48:06 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <81e23c17-05a0-420e-a7d3-b30210f7d71b@googlegroups.com> On Saturday, March 22, 2014 10:21:13 AM UTC+5:30, Chris Angelico wrote: > On Sat, Mar 22, 2014 at 3:39 PM, Rustom Mody wrote: > >> So if that's not going to be broken, how is this fundamentally different? > >> def func_loop(): > >> for x in 1,2,3: > >> yield (lambda: x) > > Thats using a for-loop > > A 'for' in a comprehension carries a different intention, the matching names > > being merely coincidental. > So what you're saying is that these two are fundamentally different: > def unrolled(): > x = 1 > yield (lambda: x) > x = 2 > yield (lambda: x) > x = 3 > yield (lambda: x) > def loop(): > for x in 1,2,3: > yield (lambda: x) Well almost Except that the 'loop' I am talking of is one of def loop(): return [yield (lambda: x) for x in [1,2,3]] or return (yield (lambda: x) for x in [1,2,3]) or just plain ol (lambda x: for x in [1,2,3]) IOW loops is an imperative construct, comprehensions are declarative Progressing through a loop in a sequential order is natural and to be expected Comprehensions being declarative, progressing through them in some order is incidental. > In other words, a loop should be implemented as a separate binding > each time, not a rebinding. That's an interesting point, and it does > make some sense; effectively, what you want is for the body of a for > loop to be a new scope, a unique scope every iteration of the loop, > and one that automatically closes over all variables in the parent > scope (including for assignments) except for the loop > iteration/counter variable. > That does make some sense, but it doesn't really fit Python's concept. Yes it does not fit in with imperative programming. Its good to remember the history. Haskell did not invent comprehensions In programming, they started with Miranda where they were called 'ZF-expressions' after the Zermelo/Fraenkel of axiomatic set theory. Because Russell's paradox had shaken the (intended) foundations of mathematics, the way out (actually the one chosen by Zermelo and Fraenkel) was to add a *comprehension axiom* http://en.wikipedia.org/wiki/Zermelo%E2%80%93Fraenkel_set_theory#3._Axiom_schema_of_specification_.28also_called_the_axiom_schema_of_separation_or_of_restricted_comprehension.29 What this basically mandates is that set constructions like {x | Pred(x) } are disqualified (called unrestricted comprehension) Only {x ? S | Pred(x) } is a valid. IOW sets cannot be concoted out of the blue but only out of other sets. FF 50 years and what David Turner ? inventor of Miranda ?- realized is that if the programming language is sufficiently mathematical ? ie no imperative constructs plus lazy evaluation, then comprehensions are actually constructive enough to make make into programming constructs. However as Mark Harris points out imperative and functional thinking styles remain confusingly inconsistent. From dieter at handshake.de Sat Mar 22 03:20:05 2014 From: dieter at handshake.de (dieter) Date: Sat, 22 Mar 2014 08:20:05 +0100 Subject: Problem with pickle and restarting a program References: <11a691c7-2842-4d3a-b355-1e44652d7590@googlegroups.com> Message-ID: <87a9ci4s4a.fsf@handshake.de> peace writes: > On Thursday, March 20, 2014 1:20:03 AM UTC-7, dieter wrote: > ... >> You may want to use debugging to determine what goes on in detail. > ... > I tried doing that. I still could not figure out what was wrong. Thank you. Debugging is often not easy. An essential strategy is "divide and conquer": i.e. you split the complete scenario into segments and analyse each segment to find out where the bad thing happens. Related to pickle, there is one point to lock at closely: where you "dump" the data. Verify, that you are dumping the correct (expected) data. If the data is not as you expect at that point, you must analyse the first part (from where the data was produced up to the dumping point); on the other hand, if the dumped data is correct, you would verify that "load" restores this same data (this will be very likely the case) and if it does why it became wrong afterward. From chris at simplistix.co.uk Fri Mar 21 14:34:07 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 21 Mar 2014 18:34:07 +0000 Subject: which async framework? - a summary In-Reply-To: <20140313193634.3767ddfc@bigbox.christie.dr> References: <531E22DF.7030709@simplistix.co.uk> <531EC0E6.10402@simplistix.co.uk> <53224C89.5050503@simplistix.co.uk> <20140313193634.3767ddfc@bigbox.christie.dr> Message-ID: <532C861F.7070504@simplistix.co.uk> On 14/03/2014 00:36, Tim Chase wrote: > On 2014-03-14 00:25, Chris Withers wrote: >> I've been pleasantly surprised by the succinct, well reasoned and >> respectful replies from each of the communities! > > As one who doesn't lurk on the other lists, is there a nice executive > summary of their responses? Well, of course, each person recommended their own framework. The short version was: - tornado is a web server, if you're not using it, the async stuff is better developed elsewhere - asyncio is very new, not a lot of protocols out in the wild and not much battle testing - twisted is been around the block a lot, huge amounts of support and an active, knowledgeable community. Can feel crufty and old in parts, mind The community bit swung it for me, so I've opted for Twisted, if I ever get a chance to work on the project in question ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From wxjmfauth at gmail.com Sat Mar 22 04:54:26 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 22 Mar 2014 01:54:26 -0700 (PDT) Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: <3d50db8b-2428-49ec-93af-7b0743bdfbe8@googlegroups.com> Le samedi 22 mars 2014 05:59:34 UTC+1, Mark H. Harris a ?crit?: > On 3/21/14 11:46 PM, Chris Angelico wrote: > > > (Side point: You have your 0d and your 0a backwards; the Unix line > > > ending is U+000A, and the Windows default is U+000D U+000A.) > > > > Yeah, I know... smart apple. > > > > > How are you going to make people change? What are you going to make > > > them change to? Who controls this standard, and how do you convince > > > all OSes to comply with it? > > > > Well, we're already doing this to some extent; baby steps. Well, we > > have open document standards (evolving) and we have a really good sense > > for unicode (and python is being a genuine leader there) and the > > flat-file is just another open document (very simple no doubt), not > > different from a standards viewpoint than rft, odt, {whatever}; txt? > > > > My idea is that as we are morphing open document standards we need > > to keep the "flat-file" in mind too. The ASCII ship has sailed too. > > Unicode is in, ASCII is out (for all intents and purposes) except at > > Microsoft---and its time to rethink what a "flat" unicode text file > > really is. That's all. > > No offense. A good start would be to understand "unicode" instead of bashing MS. jmf From ian.g.kelly at gmail.com Sat Mar 22 05:09:56 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 22 Mar 2014 03:09:56 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On Fri, Mar 21, 2014 at 8:06 PM, Rustom Mody wrote: > Two: A comprehension variable is not bound but reassigned across the > comprehension. This problem remains in python3 and causes weird behavior when > lambdas are put in a comprehension Because Python as a language only has the concept of assignment, not binding. I think it would be weird and confusing if variables worked this way in comprehensions and nowhere else. > >>> fl = [lambda y : x+y for x in [1,2,3]] > >>> [fl[i](2) for i in [0,1,2]] > [5, 5, 5] You can get the desired effect by adding a layer of indirection: >>> fl = [(lambda x: lambda y: x+y)(x) for x in [1,2,3]] >>> [f(2) for f in fl] [3, 4, 5] If that's too ugly then give the wrapper a proper name: >>> def make_function(x): ... return lambda y: x+y ... >>> fl = [make_function(x) for x in [1,2,3]] >>> [f(2) for f in fl] [3, 4, 5] There is also the default argument trick: >>> fl = [lambda y, *, x=x: x+y for x in [1,2,3]] >>> [f(2) for f in fl] [3, 4, 5] From steve+comp.lang.python at pearwood.info Sat Mar 22 05:46:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2014 09:46:01 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Mar 2014 23:51:38 -0500, Mark H Harris wrote: > Lambda is a problem, if only because it causes confusion. What's the > problem? Glad you asked. The constructs DO NOT work the way most people > would expect them to, having limited knowledge of python! Why is that a problem? Would you consider it a problem that people who don't understand BASIC can't understand BASIC? ("I don't get the difference between GOTO and GOSUB. Obviously GOSUB is a problem and should be throw out.") Do you think that the fact that people who have never used a TI-89 calculator before may have trouble used a TI-89 calculator means that TI-89 calculators are "a problem"? (I've taught school children who didn't know how to use their calculator.) The problem is ignorance, not the calculator, and not lambda. You've told us that "most people" (which people? dentists? lawyers? illiterate tribesmen from the Amazon? professional programmers?) are surprised by lamba's behaviour, but you haven't actually told us what behaviour is surprising, or what "most people" expect lambda to do. Perhaps you ought to? > I ran into > this thing about seven years ago (when I was studying Haskell, and > Scheme) and I wanted to see how "pure functional" python was (well, not > at all really). Python is not a pure functional language, but you can write functional code in it. If you want a pure functional language, you know where to find one. (I wonder whether, say, Haskell has the people coming along and demanding that it should become more like Python?) > I can see uses for python's lambda. But, honestly, I think python could > deprecate its use and in five years just remove it from the language; > along with filter, map, and reduce ! Python could deprecate many things. It would make Python a worse language. By the way, are you aware that lambda is *identical* to def except for three things? - lambda is an expression, not a statement like def; - the body of a function created with lambda is limited to a single expression, not a block; - the function object created with lambda has a generic name. So unless the surprising behaviour about lambda that you're about to tell us about relates to one of those three things, I *guarantee* that functions created with def have the same surprising behaviour. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sat Mar 22 05:50:55 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2014 09:50:55 GMT Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: <532d5cfe$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 22 Mar 2014 01:24:33 -0400, Terry Reedy wrote: > On 3/22/2014 12:30 AM, Mark H Harris wrote: >> On 3/21/14 11:15 PM, Chris Angelico wrote: >>> It compounds. One reply makes for double spacing... two makes >>> quadruple, three means we have seven wasted lines between every pair >>> of real lines. That gets pretty annoying. And considering that most >>> people who reply without cleaning up the lines also keep the entire >>> quoted text (and usually top-post as well), this gets big fast. > > Before Mark started asking people adjust to the foibles of gg, we used > to get such posts. I refused to read them. I have not seen one lately, Luck you. I see them quite frequently. > say maybe his nudging has had some positive effect. > >> Yes, I can see that readily/ I get it, it just seems that fixing >> it >> at the source (gg) is the answer; > > I completely agree. However, Google seems immune to suggestions, > including requests that it try to stop being a major source of spam > posts. Remember, we are not Google's customers. We are Google's product. The customers are the advertisers. [...] > If I were in charge of the software used for this list, I would replace > Mark with a custom addition to return mis-formated posts (more blank > lines than not) with instructions on how to fix them. But I am not. Wouldn't it be less obnoxious and more useful to pass the posts through a filter that deletes the annoying blank lines? -- Steven D'Aprano http://import-that.dreamwidth.org/ From tjreedy at udel.edu Sat Mar 22 06:14:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Mar 2014 06:14:16 -0400 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: <532d5cfe$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> <532d5cfe$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/22/2014 5:50 AM, Steven D'Aprano wrote: > On Sat, 22 Mar 2014 01:24:33 -0400, Terry Reedy wrote: >> If I were in charge of the software used for this list, I would replace >> Mark with a custom addition to return mis-formated posts (more blank >> lines than not) with instructions on how to fix them. But I am not. > > Wouldn't it be less obnoxious and more useful to pass the posts through a > filter that deletes the annoying blank lines? I have thought of that too, and may have suggested it. It would be slightly harder as a decision would be required as to which to delete. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Sat Mar 22 06:19:58 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 22 Mar 2014 23:19:58 +1300 Subject: Github down? In-Reply-To: References: Message-ID: Dan Sommers wrote: > On Fri, 21 Mar 2014 14:51:54 +0100, Chris ?Kwpolska? Warrick wrote: > >>(though GitHub could qualify as social media for some?) > > +1 QOTW https://xkcd.com/624/ From marko at pacujo.net Sat Mar 22 06:24:47 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 22 Mar 2014 12:24:47 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d15e8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zjki4jkg.fsf@elektro.pacujo.net> Steven D'Aprano : > This makes perfect sense: by the time you call the functions, the name x > has been rebound to the value 3. > [...] > Now I'm not sure precisely how Haskell implements this trick, but it > suggests to me that it creates a different closure each time around > the loop of the comprehension. That could end up being very expensive. Haskell does not rebind variables. I guess Haskell simply physically substitutes object references for each syntactic occurrence of a variable. If Python worked analogously, the following loop: for i, x in enumerate([1, 2, 3]): f[i] = lambda y: x + y would unroll as follows: f[0] = lambda y: 1 + y f[1] = lambda y: 2 + y f[2] = lambda y: 3 + y That is actually how classic lambda calculus does it. Variables are substituted, not "bound" or "assigned". They are syntactic slots. There is no heap, there is no stack, there is no memory apart from the expression itself. Marko From marko at pacujo.net Sat Mar 22 06:30:28 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 22 Mar 2014 12:30:28 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <87vbv64jaz.fsf@elektro.pacujo.net> Ian Kelly : > You can get the desired effect by adding a layer of indirection: > >>>> fl = [(lambda x: lambda y: x+y)(x) for x in [1,2,3]] A trick to remember! Variable lifetime reduction by function invocation. Marko From breamoreboy at yahoo.co.uk Sat Mar 22 06:40:49 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 22 Mar 2014 10:40:49 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On 22/03/2014 02:06, Rustom Mody wrote: > > The same in haskell: > > Prelude> let fl = [\ y -> x + y | x <- [1,2,3]] > Prelude> [(fl!!i) 0 | i<- [0,1,2]] > [1,2,3] > My really big complaint about Python is that it's nothing like CORAL 66. I think I'll raise this on python ideas in an attempt to get this glaring deficiency corrected. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Sat Mar 22 06:51:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 22 Mar 2014 10:51:05 +0000 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: On 22/03/2014 03:58, Mark H Harris wrote: > On 3/21/14 5:44 PM, Mark Lawrence wrote: >> I'm pleased to see that you have answers. In return would you either use >> the mailing list https://mail.python.org/mailman/listinfo/python-list or >> read and action this https://wiki.python.org/moin/GoogleGroupsPython to >> prevent us seeing double line spacing and single line paragraphs, thanks. > > I perceive that this is your singular pet peeve, or, you were elected by > the python community some time ago to police the line-end problem ? > It's a pet peeve as:- a) trying to read something that's the fourth level of reply or higher to the original gets to be almost impossible as it's all white space and no substance. b) better tools exist c) the work around is shown on the Python wiki, not on the crappy, bug ridden gg site itself. Wow, it's like a sauna in here :) I doubt that the Python community would elect me to do anything. Anyhow I start my new job in the diplomatic corp next week. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Sat Mar 22 06:54:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 22 Mar 2014 10:54:38 +0000 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: <3d50db8b-2428-49ec-93af-7b0743bdfbe8@googlegroups.com> References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> <3d50db8b-2428-49ec-93af-7b0743bdfbe8@googlegroups.com> Message-ID: On 22/03/2014 08:54, wxjmfauth at gmail.com wrote: > Le samedi 22 mars 2014 05:59:34 UTC+1, Mark H. Harris a ?crit : >> On 3/21/14 11:46 PM, Chris Angelico wrote: >> >>> (Side point: You have your 0d and your 0a backwards; the Unix line >> >>> ending is U+000A, and the Windows default is U+000D U+000A.) >> >> >> >> Yeah, I know... smart apple. >> >> >> >>> How are you going to make people change? What are you going to make >> >>> them change to? Who controls this standard, and how do you convince >> >>> all OSes to comply with it? >> >> >> >> Well, we're already doing this to some extent; baby steps. Well, we >> >> have open document standards (evolving) and we have a really good sense >> >> for unicode (and python is being a genuine leader there) and the >> >> flat-file is just another open document (very simple no doubt), not >> >> different from a standards viewpoint than rft, odt, {whatever}; txt? >> >> >> >> My idea is that as we are morphing open document standards we need >> >> to keep the "flat-file" in mind too. The ASCII ship has sailed too. >> >> Unicode is in, ASCII is out (for all intents and purposes) except at >> >> Microsoft---and its time to rethink what a "flat" unicode text file >> >> really is. That's all. >> >> > > No offense. A good start would be to understand "unicode" > instead of bashing MS. > > jmf > How apt given how this thread has moved :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ram.rachum at gmail.com Sat Mar 22 06:57:25 2014 From: ram.rachum at gmail.com (cool-RR) Date: Sat, 22 Mar 2014 03:57:25 -0700 (PDT) Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: References: <793ecef5-2025-4714-a6a4-cff13c93f45d@googlegroups.com> Message-ID: <869d5d75-1641-4c81-8af5-f1ef40e55a9e@googlegroups.com> On Saturday, March 22, 2014 3:39:21 AM UTC+2, Terry Reedy wrote: > Does your .b2 install work? Can you delete it thru the programs list? I uninstalled it before this entire adventure. From teddybubu at gmail.com Sat Mar 22 07:21:30 2014 From: teddybubu at gmail.com (teddybubu at gmail.com) Date: Sat, 22 Mar 2014 04:21:30 -0700 (PDT) Subject: help with for loop----python 2.7.2 Message-ID: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> I am trying to get all the element data from the rss below. The only thing I am pulling is the first element. I don't understand why the for loop does not go through the entire rss. Here is my code.... try: from urllib2 import urlopen except ImportError: from urllib.request import urlopen from bs4 import BeautifulSoup soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) #print soup.find_all('item') #print (soup) for item in soup.find_all('item'): #for item in soup: title = soup.find('title').text link = soup.find('link').text item = soup.find('item').text print item print title print link From laguna-mc at mail.com Sat Mar 22 07:48:36 2014 From: laguna-mc at mail.com (laguna-mc at mail.com) Date: Sat, 22 Mar 2014 07:48:36 -0400 Subject: Installing ssdeep on Portable Python /advice Message-ID: <20140322114836.177130@gmx.com> http://ssdeep.sourceforge.net/usage.html the installation described in aboved document is for Linux only. Well, I need experiment and see errors. Regards, > ----- Original Message ----- > From: Mark H Harris > Sent: 03/22/14 05:32 AM > To: python-list at python.org > Subject: Re: Installing ssdeep on Portable Python /advice > > On 3/21/14 9:51 PM, Mark H Harris wrote: > > On 3/20/14 7:16 PM, laguna-mc at mail.com wrote: > > >> $ tar -zxvf ssdeep-2.10.tar.gz > >> $ cd ssdeep-2.10&& ./configure&& make&& sudo make install > > >> I need install it on PortablePython for Windows, so it's not > >> clear how to make this: where should be placed ssdeep Windows > >> binary files, that Python application can found it? > > > It is strongly recommended that ssdeep be run on windows from > > precompiled binaries. Building from sources is not recommended because > > of dependencies and environment... > > > Google is our frined; > > > http://ssdeep.sourceforge.net/usage.html > > > Actually, I restated that wrong. The doc says that building from sources > on windows is NOT supported. > > marcus > -- > https://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Sat Mar 22 08:00:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 22 Mar 2014 06:00:47 -0600 Subject: help with for loop----python 2.7.2 In-Reply-To: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 5:21 AM, wrote: > I am trying to get all the element data from the rss below. > The only thing I am pulling is the first element. > I don't understand why the for loop does not go through the entire rss. > Here is my code.... [SNIP] > for item in soup.find_all('item'): > #for item in soup: > title = soup.find('title').text > link = soup.find('link').text > item = soup.find('item').text The three find method calls in the for loop are searching from the document root (the "soup" variable), not from the item you're currently iterating at. Try changing these to calls of item.find. And note that calling one of the results "item" will replace the loop variable. That won't affect the iteration, but it's bad practice to refer to two different things by the same local name. From jabba.laci at gmail.com Sat Mar 22 08:40:31 2014 From: jabba.laci at gmail.com (Jabba Laci) Date: Sat, 22 Mar 2014 13:40:31 +0100 Subject: terminate a program gracefully from a thread Message-ID: Hi, I have a script (see below) that I want to terminate after X seconds. The main loop of the program is waiting for user input. The program enters the main loop and I try to shut down the program after X seconds from a thread but I can't figure out how to do it. The program should also do some cleanup before termination, so the shut down must be graceful. The code below is a simplified version. The whole idea is the following: I have a script that has grown quite big over time. It needs to read several data files, so when I start it for the first time, it takes about 3-4 seconds to launch. The next start is much faster since, I guess, the OS has done some caching. I use this script a lot and the first slow launch bothers me. My idea: after booting, I want to start the script in the background in suicide mode. OS does the caching, so when I need it, it starts quickly. See the code below with comments. Thanks, Laszlo =============== import atexit import sys import time from threading import Thread import os def suicide(wait): time.sleep(wait) print("should exit now...") sys.exit() # exits this thread but not the main thread # os._exit(0) # no cleanup with this :( def cleanup(): # I want it to run before termination. print("cleaning up...") def main(): Thread(target=suicide, kwargs={'wait': 3}).start() # while True: try: inp = raw_input("in> ") print(inp) except (KeyboardInterrupt, EOFError): print() sys.exit() ##### if __name__ == "__main__": atexit.register(cleanup) main() From davea at davea.name Sat Mar 22 09:18:52 2014 From: davea at davea.name (Dave Angel) Date: Sat, 22 Mar 2014 09:18:52 -0400 (EDT) Subject: terminate a program gracefully from a thread References: Message-ID: Jabba Laci Wrote in message: > Hi, > > I have a script (see below) that I want to terminate after X seconds. > The main loop of the program is waiting for user input. > The program enters the main loop and I try to shut down the program > after X seconds from a thread but I can't figure out how to do it. The > program should also do some cleanup before termination, so the shut > down must be graceful. > > The code below is a simplified version. The whole idea is the > following: I have a script that has grown quite big over time. It > needs to read several data files, so when I start it for the first > time, it takes about 3-4 seconds to launch. The next start is much > faster since, I guess, the OS has done some caching. I use this script > a lot and the first slow launch bothers me. My idea: after booting, I > want to start the script in the background in suicide mode. OS does > the caching, so when I need it, it starts quickly. > You need a flag to indicate that a particular invocation is the dummy one (background). So use that same flag either to suppress starting the thread, or to avoid the unwanted raw_input. If you had no blocking I/o, you could use a simple global to notify all the threads. Or use a signal to abort the main thread if it's stuck in raw_input. Alternatively, rethink the need to preload at boot time. Any caching the OS does is likely to only last a few minutes, depending on load. So maybe you can make the real load seem to be quicker by displaying the gui right away, but doing the time-consuming part in a thread. -- DaveA From jabba.laci at gmail.com Sat Mar 22 09:19:44 2014 From: jabba.laci at gmail.com (Jabba Laci) Date: Sat, 22 Mar 2014 14:19:44 +0100 Subject: terminate a program gracefully from a thread In-Reply-To: References: Message-ID: > You need a flag to indicate that a particular invocation is the > dummy one (background). So use that same flag either to suppress > starting the thread, or to avoid the unwanted raw_input. > > Alternatively, rethink the need to preload at boot time. Any > caching the OS does is likely to only last a few minutes, > depending on load. So maybe you can make the real load seem to be > quicker by displaying the gui right away, but doing the > time-consuming part in a thread. Hi, Thanks for the idea. Right, if it's started in suicide mode, then there is no need to enter the raw_input. Thanks, Laszlo From rosuav at gmail.com Sat Mar 22 09:44:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Mar 2014 00:44:51 +1100 Subject: terminate a program gracefully from a thread In-Reply-To: References: Message-ID: On Sun, Mar 23, 2014 at 12:18 AM, Dave Angel wrote: > Alternatively, rethink the need to preload at boot time. Any > caching the OS does is likely to only last a few minutes, > depending on load. So maybe you can make the real load seem to be > quicker by displaying the gui right away, but doing the > time-consuming part in a thread. I second this motion. Don't preload stuff on boot like that; if you want the data preloaded, actually load the program and keep it running. Depending on the OS/FS cache like that is a bit better than what seems to proliferate on Windows ("MS Office fast-load" being one of the worst offenders), where there's this constant fight between boot time and program load time, with RAM usage going nuts in between. By (ab)using the disk cache like this, you make your cache work beautifully until some app actually needs all that RAM, and then your cache will be dropped; which is a good thing for the system, but it means you'll have completely wasted the loading effort. Much better to be more explicit about it, and probably just accept that first startup is slower. ChrisA From vikram.denizen at gmail.com Sat Mar 22 09:41:14 2014 From: vikram.denizen at gmail.com (vikram.denizen at gmail.com) Date: Sat, 22 Mar 2014 06:41:14 -0700 (PDT) Subject: newbie - Does IDLE care about sitecustomize.py? In-Reply-To: <1132151829.600244.9210@g14g2000cwa.googlegroups.com> References: <1132151829.600244.9210@g14g2000cwa.googlegroups.com> Message-ID: Could you figure this out? On Wednesday, November 16, 2005 10:37:09 PM UTC+8, bobu... at yahoo.com wrote: > I have the following test script in the file customize.py > > # C:\Python24\Lib\site-packages\sitecustomize.py > print "test text from sitecustomize" > > If start Python from command prompt I get > > C:\Python24>python > test in sitecustomize > Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. > > which shows that sitecustomize.py works > > > Now if I start IDLE I only get > > IDLE 1.1.1 > >>> > > which shows that that IDLE doesn't care about sitecustomize.py > > Am I missing something or how do you customize if you are using IDLE? From rosuav at gmail.com Sat Mar 22 09:57:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Mar 2014 00:57:30 +1100 Subject: newbie - Does IDLE care about sitecustomize.py? In-Reply-To: References: <1132151829.600244.9210@g14g2000cwa.googlegroups.com> Message-ID: On Sun, Mar 23, 2014 at 12:41 AM, wrote: > Could you figure this out? > > On Wednesday, November 16, 2005 10:37:09 PM UTC+8, bobu... at yahoo.com wrote: >> [ chomp ] You're responding to a decade-old post, you're posting from Google Groups, and you haven't added any information to the thread at all. The original post was talking about Python 2.4, which is well and truly out of support (unless you're running RHEL5), so the very first thing you should do is see if there's still a corresponding issue with a current version of Python. The next thing to do is to make sure you don't offend with form (always offend people with substance, it's more satisfying), so either don't use Google Groups, or clean up what you post so it comes out looking correct. And following the standard interleaved style, rather than top-posting, will also help. ChrisA From kjakupak at gmail.com Sat Mar 22 09:56:05 2014 From: kjakupak at gmail.com (kjakupak at gmail.com) Date: Sat, 22 Mar 2014 06:56:05 -0700 (PDT) Subject: User prompt as file to read Message-ID: <83317185-701d-4218-a748-00b75b51843c@googlegroups.com> I'm trying to create a program that will prompt the user for a list of text files to read from, then read those text files and build a dictionary of all the unique words found. Then finally put those unique words into another file and make it alphabetical order. What I've got: import string s = input("Enter a file name: ") + ".txt" filepath = "I:\\" + s # remove all punctuation marks and make lower case s_nopunct = "".join(c for c in s if c not in string.punctuation).lower() # convert to a sorted list of unique words via set comprehension list_unique = sorted(list({word for word in s_nopunct.split()})) print("\nSorted list of unique words in sentence:") print(list_unique) with open("C:\\Users\\Desktop\\words.dat", "w") as f: for x in list_unique: f.write(x + "\n") I need help making it so that the user is prompted to enter at least 3 files. And also, I tried making those unique words to write to another file (I got it that far), but how do I make it more of an arbitrary path (rather than the C:\Users etc) since I need it so that anyone can run that program and write/find to that file. From ian.g.kelly at gmail.com Sat Mar 22 10:22:28 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 22 Mar 2014 08:22:28 -0600 Subject: Python - Caeser Cipher Not Giving Right Output In-Reply-To: References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> Message-ID: On Mar 20, 2014 9:59 PM, "Dave Angel" wrote: > > dtran.ru at gmail.com Wrote in message: > > And I was wondering how I would add the partenthesis because I tried: > > > > return numtochar(c1 + c2 (%26)) and it gave me an error. > > Please help us to help you by actually showing the traceback. > Doesn't matter in this case, but... > > What order do you want the add and the modulo to happen? Use the > parentheses to say so. Ah, but he did. x = y + z (mod m) is a perfectly well-formed math equation. Not the OP's fault if it doesn't work that way in Python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Sat Mar 22 10:34:25 2014 From: davea at davea.name (Dave Angel) Date: Sat, 22 Mar 2014 10:34:25 -0400 (EDT) Subject: User prompt as file to read References: <83317185-701d-4218-a748-00b75b51843c@googlegroups.com> Message-ID: kjakupak at gmail.com Wrote in message: > I'm trying to create a program that will prompt the user for a list of text files to read from, then read those text files and build a dictionary of all the unique words found. Then finally put those unique words into another file and make it alphabetical order. Specify python version and os. I assume python 3 and Windows. > > What I've got: > > import string > > s = input("Enter a file name: ") + ".txt" > filepath = "I:\\" + s So you've got a filename. You're not using it for anything. Where's your open? Where's your read or readline? > > # remove all punctuation marks and make lower case > s_nopunct = "".join(c for c in s if c not in string.punctuation).lower() Are you sure you want a single string nearly the total size of your 3 files? Could be huge. Might be better to do it incrementally. It's a lot safer to include the characters you want, instead of excluding some of the ones you don't. And many valid words contain punctuation such as apostrophe. > > # convert to a sorted list of unique words via set comprehension > list_unique = sorted(list({word for word in s_nopunct.split()})) > > print("\nSorted list of unique words in sentence:") > print(list_unique) > > with open("C:\\Users\\Desktop\\words.dat", "w") as f: > for x in list_unique: > f.write(x + "\n") > > I need help making it so that the user is prompted to enter at least 3 files. Need a while loop for that. > And also, I tried making those unique words to write to another file (I got it that far), but how do I make it more of an arbitrary path (rather than the C:\Users etc) since I need it so that anyone can run that program and write/find to that file. > That could be another input, or it could be a command line parameter. Your choice. -- DaveA From steve+comp.lang.python at pearwood.info Sat Mar 22 10:50:47 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2014 14:50:47 GMT Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> Message-ID: <532da347$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 21 Mar 2014 22:58:37 -0500, Mark H Harris wrote: > I notice (since moving my stuff to Thunderbird two weeks back) the > double spacing you keep squawking about, but I don't find it the big > nuisance you're talking about; ok, so we have to scroll a bit further. It's not the scrolling that interferes with readability, it's the interruption to the flow of text by having excess blank lines within a paragraph of text. > I am honestly convinced that this might even be a python problem. More > likely than not, gg is written in python, and this is the goofy line-end > character problem we have to deal with when we read lines in python. Well, that's certainly a novel idea. Why you think that Google Groups is written in Python? Does every post from GG end with "Powered By Python"? > Why do we suck in the new-line character as though it were part of the > line? Because it is the only sensible way to handle it. If you don't, then there is no way to distinguish between a file that ends with a newline and one which doesn't. > This is asinine behavior. The new-line is a "file" delimiter > character and NOT intended to be part of the line. Line endings are terminators: they end the line. Whether you consider the terminator part of the line or not is a matter of opinion (is the cover of a book part of the book?) but consider this: If you say that the end of lines are *not* part of the line, then that implies that some parts of the file are not inside any line at all. And that would be just weird. > Thinking this through a bit Yes, that helps :-) > I've noticed that a blank line comes back > with a '\n' which differentiates it from file end which comes back > "without" the new-line. So, it appears that python is using the > new-line character (or lack there-of) to have meaning which the new=line > in a unix file was never suppose to carry. I don't understand what meaning you are referring to here. Blank lines comes back as a \n because a blank line *is* a \n with nothing before it. Python isn't doing anything funny here, at least not on Linux. If you open a text editor, and type: spam ENTER ENTER ENTER ENTER eggs ENTER (where ENTER means to hit the Enter key, not the letters E N T E R) and then save, your editor will show the words "spam" and "eggs" separated by three blank lines. If you open that file in a hex editor, you will see something like: 73 70 61 6d 0a 0a 0a 0a 65 67 67 73 0a Notice the four 0a bytes in a row? That gives you three blank lines. Python is no adding any extra newlines or putting them where they aren't, so I don't really understand what point you're trying to make here. > If python would just return EOF like every other language at file end, > and a test line without '\n' tacked to the end of it, this little snag > with gg would probably go away. What say you? There is no evidence that Google Group's difficulty is because of Python. More likely it is related to the translation between "rich text" formatted using HTML, and plain text. By the way, Python *does* return EOF at the end of the file. It is just that EOF in Python is spelled "the empty string" instead of some other special value. Both Ruby and Lua behave like Python, returning the empty string on end of file: steve at orac:~$ irb irb(main):001:0> f = File.open('/tmp/io.txt') => # irb(main):002:0> f.read() => "hello" irb(main):003:0> f.read() => "" [steve at ando ~]$ lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > fp = io.open('/tmp/io.txt', 'r') > print(fp:read("*all")) hello > print(fp:read("*all")) > Similarly, Rust returns None: http://static.rust-lang.org/doc/0.9/std/io/trait.Reader.html#tymethod.read And Java's java.io.BufferedReader is also similar, returning null. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sat Mar 22 11:09:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Mar 2014 02:09:20 +1100 Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary In-Reply-To: <532da347$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> <532da347$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 23, 2014 at 1:50 AM, Steven D'Aprano wrote: > Line endings are terminators: they end the line. Whether you consider the > terminator part of the line or not is a matter of opinion (is the cover > of a book part of the book?) but consider this: > > If you say that the end of lines are *not* part of the line, then > that implies that some parts of the file are not inside any line > at all. And that would be just weird. Not so weird IMO. A file is not a concatenation of lines; it is a stream of bytes. Now, if you ask Python to read you 512 bytes from a binary file, and then ask for another 512 bytes, and so on until you reach the end, then it would indeed be VERY weird if there were parts of the file that weren't in the returned (byte) strings. But if you ask for a line, and then another line, and another line, then it's quite reasonable to interpret U+000A as "line separation" rather than "line termination", and not return it. (Both interpretations make sense. I just wish the most obvious form of iteration gave the cleaner/tidier version, or at very least that there be some really obvious way to ask for lines-without-endings.) Imagine the output of GNU find as a series of records. You can ask for those to be separated by newlines (the default, or -print), or by NULs (with the -print0 command). In either case, the records do not *contain* that value, they're separated by it; the records consist of file names. ChrisA From rustompmody at gmail.com Sat Mar 22 13:16:43 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 22 Mar 2014 10:16:43 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <891df3fe-2cd8-4615-9f9c-0e6f62af764a@googlegroups.com> On Saturday, March 22, 2014 2:39:56 PM UTC+5:30, Ian wrote: > On Fri, Mar 21, 2014 at 8:06 PM, Rustom Mody wrote: > > Two: A comprehension variable is not bound but reassigned across the > > comprehension. This problem remains in python3 and causes weird behavior when > > lambdas are put in a comprehension > Because Python as a language only has the concept of assignment, not > binding. I think it would be weird and confusing if variables worked > this way in comprehensions and nowhere else. Bizarre viewpoint! When you do this: > There is also the default argument trick: > >>> fl = [lambda y, *, x=x: x+y for x in [1,2,3]] > >>> [f(2) for f in fl] > [3, 4, 5] how is that not-a-binding solution? More generally, insofar as variable-scopes can be made and exited, there is binding. Its just that imperative languages have - assignment wherein the shape of the environment is preserved but its content is changed - there are binding-constructs -- functions, methods, classes etc etc -- which leave extant bindings intact but create/remove new ones. Ok, functional languages have only the latter. But only the former?? Beyond assembly language I dont know what that would/could be... From rustompmody at gmail.com Sat Mar 22 13:29:47 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 22 Mar 2014 10:29:47 -0700 (PDT) Subject: Python - Caeser Cipher Not Giving Right Output In-Reply-To: References: <7eee0f2b-0d5f-409e-ae4e-8c9c1af31d74@googlegroups.com> Message-ID: <3ddffa42-6f51-4950-94bd-560b9c9547b1@googlegroups.com> On Saturday, March 22, 2014 7:52:28 PM UTC+5:30, Ian wrote: > On Mar 20, 2014 9:59 PM, "Dave Angel" wrote: > > ?dtra... at gmail.com Wrote in message: > > > And I was wondering how I would add the partenthesis because I tried: > > > return numtochar(c1 + c2 (%26)) and it gave me an error. > > Please help us to help you by actually showing the traceback. > > ?Doesn't matter in this case, but... > > What order do you want the add and the modulo to happen? ?Use the > > ?parentheses to say so. > Ah, but he did. x = y + z (mod m) is a perfectly well-formed math equation. Not the OP's fault if it doesn't work that way in Python. !!!!! !I forgot that parse! From albert at spenarnc.xs4all.nl Sat Mar 22 13:32:05 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Mar 2014 17:32:05 GMT Subject: Question about Source Control References: Message-ID: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> In article , Tim Chase wrote: >On 2014-03-18 21:38, Terry Reedy wrote: >> At least with hg, one should best test the code in the working >> directory *before* committing to the local repository. > >I don't know if this is a hg-vs-git way of thinking, but I tend to >frequently commit things on a private development branch regardless >of brokenness, but once I get it working, I flatten & clean up those >changes ("rebase" in git terms, which I believe has been adopted as a >standardly-available-but-not-enabled-by-default module in hg) into >logical units of change-sets that I then test individually before >applying them to my more public-facing branch. This produces clean >history that makes it easy for others to see what's going on. I see it this way that all code is broken to at least a small extent, so it is stupid to not to save into source control because code is not yet flawless. I use RCS (!) for my eulerproject.net programs, and I save every small milestone. There is just one important rule, if you save code that has (severe) restrictions, keep track of it in the submission message, otherwise you loose your bearings. Basically the first ten of so versions (before the tag WINNER) just don't solve the problem. (Of course euler problems are hard, three rewrites are not uncommon.) I compare the in between versions with the nails they put in the mountainside in climbing. It is a point below which you'll never need to slide back. > >-tkc Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From breamoreboy at yahoo.co.uk Sat Mar 22 13:57:21 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 22 Mar 2014 17:57:21 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: On 22/03/2014 09:09, Ian Kelly wrote: > On Fri, Mar 21, 2014 at 8:06 PM, Rustom Mody wrote: >> Two: A comprehension variable is not bound but reassigned across the >> comprehension. This problem remains in python3 and causes weird behavior when >> lambdas are put in a comprehension > > Because Python as a language only has the concept of assignment, not > binding. I think it would be weird and confusing if variables worked > this way in comprehensions and nowhere else. > My understanding has always been that an expression of the rhs is bound to a name of the lhs. So is my understanding wrong, or is the above wrong, or are we talking at cross purposes, or what? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From albert at spenarnc.xs4all.nl Sat Mar 22 13:53:25 2014 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Mar 2014 17:53:25 GMT Subject: Question about Source Control References: Message-ID: <532dce15$0$24918$e4fe514c@dreader36.news.xs4all.nl> In article , Gregory Ewing wrote: >Chris Angelico wrote: >> You can then offer a non-source-control means of downloading that >> specific revision. > >Just keep in mind the downside that you can't then >push or pull your changes directly back into the main >repository. You can generate a patch file for the >project maintainer to apply, however. Hg makes it >very easy to produce a patch file between any two >revisions. > >Also, unless the project is truly ancient, the >whole history might not be as big as you expect. >The code presumably grew to its present size >incrementally, in an approximately monotonic >manner, so the sum of all the diffs is probably >about the same order of magnitude as the current >code size. > >As an experiment, I just cloned a copy of the >CPython repository, and it's about 300MB. A >tarball of Python 3.2 that I downloaded and >compiled earlier is about 75MB. That's a ratio >of about 4, and CPython is a pretty ancient >project! This post made me worry for the first time about one project of mine (ciforth). It started in 2000 with an msdos assembler file, and after several hundreds version it has accumulated doc's and test's and is now usable on linux, windows whatnot. Since 2000 the cvs style archive has grown to 2 megabyte, for a current version of 400 kbyte. I kept the smallest of changes, and at times was very happy I did. Bottom line, the grow of a source archive cannot keep up with LAN and Internet speeds and hard disk sizes. > >-- >Greg Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From laurent.pointal at free.fr Sat Mar 22 14:28:35 2014 From: laurent.pointal at free.fr (Laurent Pointal) Date: Sat, 22 Mar 2014 19:28:35 +0100 Subject: Controlling buffer alignment in file.read() References: Message-ID: <532dd653$0$2370$426a74cc@news.free.fr> Haralanov, Mitko wrote: >> For control at that level you'd be better off using >> direct system calls, i.e. os.open() and os.read(), >> then you can read exacty the number of bytes you want. >> > > The problem is not controlling the number of bytes read. That part seems > to be working. The issue is that the buffer into which the data is placed > needs to be of certain alignment (8byte-aligned). Python does not seem to > have a way that allows me to control that. > > Thanks, > - Mitko Did you try to set buffering parameter to 0 (unbuffered) ? Eventually going to os.open() which map tp low level (eventually followed by an os.fdopen()) http://docs.python.org/2/library/os.html#os.open A+ Laurent. From marko at pacujo.net Sat Mar 22 14:40:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 22 Mar 2014 20:40:44 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <87mwgi3wlv.fsf@elektro.pacujo.net> Mark Lawrence : > On 22/03/2014 09:09, Ian Kelly wrote: >> Because Python as a language only has the concept of assignment, not >> binding. I think it would be weird and confusing if variables worked >> this way in comprehensions and nowhere else. > > My understanding has always been that an expression of the rhs is > bound to a name of the lhs. So is my understanding wrong, or is the > above wrong, or are we talking at cross purposes, or what? Hard to say without knowing more of your understanding. Even Scheme doesn't have purely classical variable binding because variables can be assigned to. You will notice that right away when you try to implement a lisp dialect; a purely binding (substituting) implementation fails with set!/setq because there is no variable to assign a value to. Python variables are named memory slots you can peek and poke into. Not so in a purely functional language where variables are physically removed from the code before the code is executed. Example: def redouble(x): return x + x redouble(17 + 4) If Python were simply binding variables in the purely functional sense, the interpreter would first evaluate 17 + 4 and then make a copy of the "redouble" function substituting the result (21) for each syntactic occurrence of x: def __redouble__234001942(): return 21 + 21 The interpreter would then proceed to evaluate the variable-less function instance. If you leave out assignment, there is really no difference between the two models. Only if you don't have assignment, you don't need to complicate your computational model with memory. Instead, you deal with things like continuations. In fact, even "def" violates the classic functional paradigm. For example, to calculate 10's factorial without assignments, you can do this (even in Python): (lambda n: (lambda fac: fac(fac, n)) \ (lambda fac, n: 1 if n < 2 else n * fac(fac, n - 1)))(10) Marko From rustompmody at gmail.com Sat Mar 22 14:42:42 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 22 Mar 2014 11:42:42 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <6fa40395-e8db-4597-ab8e-546132595586@googlegroups.com> The foll is fairly standard fare in denotational semantics -- please excuse the length! In order to understand (formally) the concept of 'variable' we need to have at the least a concept of name(or identifier) -> value mapping. This mapping is called an 'environment' If we stop at that we get the 'simplest' (at least from a mathematical pov!!) language -- ? calculus. However programming languages also need to be implemented -- typically on von Neumann machines. So we make 'Variable' a composition of two functions: Env : Identifier -> Location Store : Location -> Value This seems fine and dandy until we realize that if the compositon is of non one-one onto functions all kinds of troubles result; eg -- Two locations going to one value -- aliasing -- Store partial at a location -- uninitialized variable etc etc the most innocuous looking? -- assignment becomes a higher order function because it converts a starting id -> -> value mapping to a new mapping Seeing all these difficulties, some religious zealots (aka functional programmers) decide that this composite mapping is the root of the problem -- throw it out -- no aliasing, no assignment, no time. [Minor problem -- How to implement -- remains!] The non-religious bigots (also called C programmers) see that managing the Env at one time and the Store at a later time (the two times are usually called compile-time and run-time but like bell-bottoms these words are currently unfashionable!) can produce very effective engineering expedience. So strictly speaking whenever we have variables we have binding [Probably mathematica is an exception... dunno for sure] More loosely and conventionally if the mapping is a single direct one: Env: Variable -> Value as in ? calculus, functional languages etc, they are called binding-languages To distinguish, the 'other' languages which need a compose of Environment and Store are called variously: - imperative language - reference semantics - conventional (imperative) variable (vs mathematical variable) etc IOW in most (normal) languages we have constructs to change the shape of the environment and we have constructs to change the content of the environment. The single pre-eminent way for the latter is assignment, function is the typical way for the former. [Unfortunately this is not universally true: In C we have initialized variables that look like assignment but is not. In python the exception is what Ian calls the default variable trick: x=x would be a rather asinine assignment. But its not an assignment at all, it just looks like one] So no... > My understanding has always been that an expression of the rhs is bound > to a name of the lhs. So is my understanding wrong, or is the above > wrong, or are we talking at cross purposes, or what? assignment changes the content of the env, functions change the shape -- which latter you may call binding. From python.list at tim.thechases.com Sat Mar 22 14:49:17 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 22 Mar 2014 13:49:17 -0500 Subject: Question about Source Control In-Reply-To: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> Message-ID: <20140322134917.080bada6@bigbox.christie.dr> On 2014-03-22 17:32, Albert van der Horst wrote: > >I don't know if this is a hg-vs-git way of thinking, but I tend to > >frequently commit things on a private development branch regardless > >of brokenness, but once I get it working, I flatten & clean up > >those changes ("rebase" in git terms, which I believe has been > >adopted as a standardly-available-but-not-enabled-by-default > >module in hg) into logical units of change-sets that I then test > >individually before applying them to my more public-facing > >branch. This produces clean history that makes it easy for others > >to see what's going on. > > I see it this way that all code is broken to at least a small > extent, so it is stupid to not to save into source control because > code is not yet flawless. I agree that skipping the commits just because it might be broken is a foolish idea. However, with most VCS tools, your commits can look something like Baseline -> A -> B -> C -> D -> E -> F -> G {head/tip} but A, C, & E all comprise one conceptual change, while B & G are another, and D & F cancel each other out. You can either cherry-pick those changes or rebase (with git or the hg plugin) so that the history looks like Baseline -> (ACE) -> (BG) {head/tip} With git, the history isn't actually discarded immediately, but rather just gets a parallel version (which may or may not have a reference to it; if it doesn't it will get cleaned up about a month later according to your garbage-collection settings) so your repo ends up looking something like Baseline -> A -> B -> C -> D -> E -> F -> G {orphaned or named} \---> (ACE) -> (BG) {head/tip} You can then publish that conceptually clean (and hopefully tested&working) branch while simultaneously having the full history in the event you need it. That said, I almost never want the intermediate work product once I have a final clean version, so I just let git GC that for me. -tkc From fomcl at yahoo.com Sat Mar 22 16:01:22 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sat, 22 Mar 2014 13:01:22 -0700 (PDT) Subject: Question about Source Control In-Reply-To: <20140322134917.080bada6@bigbox.christie.dr> References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> <20140322134917.080bada6@bigbox.christie.dr> Message-ID: <1395518482.78665.YahooMailNeo@web163804.mail.gq1.yahoo.com> Hi, I can recommend the book "Pragmatic Guide to Git". Very practical and to the point: http://www.amazon.com/Pragmatic-Guide-Git-Programmers/dp/1934356727/ref=sr_1_1/184-0142481-0484062?ie=UTF8&qid=1395518159&sr=8-1&keywords=pragmatic+guide+to+git I addition, I read a big fat super-exhaustive book, I believe it' s this one (there are two Git books with a bat!): http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387/ref=sr_1_2/184-0142481-0484062?ie=UTF8&qid=1395518159&sr=8-2&keywords=pragmatic+guide+to+git The former is for common tasks that are not common enough to remember right away. The latter is for reference. I only have experience with git and subversion. I like git much better. But any SCM is better than none at all. ? Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On Saturday, March 22, 2014 7:49 PM, Tim Chase wrote: On 2014-03-22 17:32, Albert van der Horst wrote: >> >I don't know if this is a hg-vs-git way of thinking, but I tend to >> >frequently commit things on a private development branch regardless >> >of brokenness, but once I get it working, I flatten & clean up >> >those changes ("rebase" in git terms, which I believe has been >> >adopted as a standardly-available-but-not-enabled-by-default >> >module in hg) into logical units of change-sets that I then test >> >individually before applying them to my more public-facing >> >branch.? This produces clean history that makes it easy for others >> >to see what's going on.? >> >> I see it this way that all code is broken to at least a small >> extent, so it is stupid to not to save into source control because >> code is not yet flawless. > >I agree that skipping the commits just because it might be broken is >a foolish idea.? However, with most VCS tools, your commits can look >something like > >? Baseline -> A -> B -> C -> D -> E -> F -> G {head/tip} > >but A, C, & E all comprise one conceptual change, while B & G are >another, and D & F cancel each other out.? You can either cherry-pick >those changes or rebase (with git or the hg plugin) so that the >history looks like > >? Baseline -> (ACE) -> (BG) {head/tip} > >With git, the history isn't actually discarded immediately, but >rather just gets a parallel version (which may or may not have a >reference to it; if it doesn't it will get cleaned up about a month >later according to your garbage-collection settings) so your repo >ends up looking something like > >? Baseline -> A -> B -> C -> D -> E -> F -> G {orphaned or named} >? ? ? ? \---> (ACE) -> (BG) {head/tip} > >You can then publish that conceptually clean (and hopefully >tested&working) branch while simultaneously having the full history >in the event you need it.? That said, I almost never want the >intermediate work product once I have a final clean version, so I >just let git GC that for me. > > >-tkc > > > > > > > > > > > > > >-- >https://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Mar 22 16:13:59 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Mar 2014 16:13:59 -0400 Subject: newbie - Does IDLE care about sitecustomize.py? In-Reply-To: References: <1132151829.600244.9210@g14g2000cwa.googlegroups.com> Message-ID: On 3/22/2014 9:41 AM, vikram.denizen at gmail.com wrote: > Could you figure this out? > > On Wednesday, November 16, 2005 10:37:09 PM UTC+8, bobu... at yahoo.com wrote: >> I have the following test script in the file customize.py >> >> # C:\Python24\Lib\site-packages\sitecustomize.py >> print "test text from sitecustomize" >> >> If start Python from command prompt I get >> >> C:\Python24>python >> test in sitecustomize >> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] >> on win32 Note: running on Windows >> Type "help", "copyright", "credits" or "license" for more information. >> >> which shows that sitecustomize.py works >> >> >> Now if I start IDLE I only get >> >> IDLE 1.1.1 On Windows, the default mode of running Idle is without a console window, with pythonw.exe. Site.py and sitecustomize.py are run before anything else and any output is discarded. I propose to note this where sitecustomize.py is explained. http://bugs.python.org/issue21026 -- Terry Jan Reedy From tjreedy at udel.edu Sat Mar 22 16:48:02 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Mar 2014 16:48:02 -0400 Subject: terminate a program gracefully from a thread In-Reply-To: References: Message-ID: On 3/22/2014 8:40 AM, Jabba Laci wrote: > I have a script (see below) that I want to terminate after X seconds. > The main loop of the program is waiting for user input. > The program enters the main loop and I try to shut down the program > after X seconds from a thread but I can't figure out how to do it. The > program should also do some cleanup before termination, so the shut > down must be graceful. Although you have gotten comments specific to your problem, this type of thing should be easy (in just one thread) with asyncio (new in 3.4, backport on PyPI). -- Terry Jan Reedy From simonhf at gmail.com Sat Mar 22 16:45:07 2014 From: simonhf at gmail.com (Simon Hardy-Francis) Date: Sat, 22 Mar 2014 13:45:07 -0700 (PDT) Subject: Help needed to create a Python extension library for an existing shared memory hash table library Message-ID: Hi Python fans, I just released my first open source project ever called SharedHashFile [1]. It's a shared memory hash table written in C. Some guy on Quora asked [2] whether there's an extension library for Python coming out. I would like to do one but I know little about Python. I was wondering if anybody in this group has experience writing extension libraries for Python? Could you help? Or could we collaborate? Thanks and all the best, Simon [1] https://github.com/simonhf/sharedhashfile [2] http://www.quora.com/Inter-Process-Communication-1/Whats-a-good-library-to-share-a-key-value-store-across-multiple-processes-through-shared-memory From vasudevram at gmail.com Sat Mar 22 16:59:46 2014 From: vasudevram at gmail.com (vasudevram) Date: Sat, 22 Mar 2014 13:59:46 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Message-ID: <8aa0b833-e7b7-485b-8258-c59eebdace93@googlegroups.com> Thanks to all those who answered. - Vasudev From super.thrinaxodon at dumbass.bitch.invalid Sat Mar 22 17:20:59 2014 From: super.thrinaxodon at dumbass.bitch.invalid (SUPER THRINAXODON DUMBASS) Date: Sat, 22 Mar 2014 17:20:59 -0400 Subject: RICHARD LEAKEY RECENTLY ARRESTED -- THE THRINAXODON TIMES REPORTS YOU CRAP, YOU CALL OUT BULLSHIT! Message-ID: ==================== >LOOK, MOM! A BIRD, A PLANE, A THRINAXODON! ==================== > RICHARD LEAKEY WAS RECENTLY ARRESTED IN CONNECTION TO EVOLUTIONARY SCANDALS. > THRINAXODON CAUGHT THE WHOLE SCENE! > ONLY ONE GUESS TO WHAT RICHARD LEAKEY WAS UP TO WILL SHUT YOUR MOUTHS! > RICHARD LEAKEY WAS BRAINWASHING CHILDREN INTO THE SCAM OF HUMAN EVOLUTION JUST TO MAKE BIG BUCKS... > ================================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# -- ---Thrinaxodon From rhodri at wildebst.org.uk Sat Mar 22 20:32:22 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Sun, 23 Mar 2014 00:32:22 -0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> Message-ID: On Sat, 22 Mar 2014 05:26:26 -0000, Rustom Mody wrote: > Well almost... > Except that the 'loop' I am talking of is one of > def loop(): > return [yield (lambda: x) for x in [1,2,3]] > or > return (yield (lambda: x) for x in [1,2,3]) > or just plain ol > (lambda x: for x in [1,2,3]) > IOW loop is an imperative construct, comprehensions are declarative I'm sorry, you've made a logical leap too far here. I understand loops being imperative, but how are comprehensions declarative? What do they declare that the loop equivalent doesn't. You've made a great deal of the "for" in a comprehension not having the same meaning as the "for" in a loop. That may well be true in the equivalent Haskell constructs (I don't speak or write Haskell), but I think you are wrong in Python. If so, please stop trying to write Haskell in Python; you'll be as happy as the friend of mine I've finally persuaded to stop writing Fortran in Python, I promise! -- Rhodri James *-* Wildebeest Herder to the Masses From steve+comp.lang.python at pearwood.info Sat Mar 22 21:07:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Mar 2014 01:07:32 GMT Subject: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary References: <827c7585-6c2a-4329-861f-0fdaa629b050@googlegroups.com> <532da347$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <532e33d4$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 23 Mar 2014 02:09:20 +1100, Chris Angelico wrote: > On Sun, Mar 23, 2014 at 1:50 AM, Steven D'Aprano > wrote: >> Line endings are terminators: they end the line. Whether you consider >> the terminator part of the line or not is a matter of opinion (is the >> cover of a book part of the book?) but consider this: >> >> If you say that the end of lines are *not* part of the line, then >> that implies that some parts of the file are not inside any line at >> all. And that would be just weird. > > Not so weird IMO. A file is not a concatenation of lines; it is a stream > of bytes. But a *text file* is a concatenation of lines. The "text file" model is important enough that nearly all programming languages offer a line-based interface to files, and some (Python at least, possibly others) make it the default interface so that iterating over the file gives you lines rather than bytes -- even in "binary" mode. > Now, if you ask Python to read you 512 bytes from a binary > file, and then ask for another 512 bytes, and so on until you reach the > end, then it would indeed be VERY weird if there were parts of the file > that weren't in the returned (byte) strings. But if you ask for a line, > and then another line, and another line, then it's quite reasonable to > interpret U+000A as "line separation" rather than "line termination", > and not return it. (Both interpretations make sense. I just wish the > most obvious form of iteration gave the cleaner/tidier version, or at > very least that there be some really obvious way to ask for > lines-without-endings.) There is: call strip('\n') on the line after reading it. Perl and Ruby spell it chomp(). Other languages may spell it differently. I don't know of any language that automatically strips newlines, probably because you can easily strip the newline from the line, but if the language did it for you, you cannot reliably reverse it. > Imagine the output of GNU find as a series of > records. You can ask for those to be separated by newlines (the default, > or -print), or by NULs (with the -print0 command). In either case, the > records do not *contain* that value, they're separated by it; the > records consist of file names. I have no problem with that: when interpreting text as a record with delimiters, e.g. from a CSV file, you normally exclude the delimiter. Sometimes the line terminator does double-duty as a record delimiter as well. Reading from a file is considered a low-level operation. Reading individual bytes in binary mode is the lowest level; reading lines in text mode is the next level, built on top of the lower binary mode. You build higher protocols on top of one or the other of that mode, e.g. "read a zip file" would be built on top of binary mode, "read a csv file" would be built on top of text mode. As a low-level protocol, you ought to be able to copy a file without changing it by reading it in then writing it out: for blob in infile: outfile.write(blob) ought to work whether you are in text mode or binary mode, so long as the infile and outfile are opened in the same mode. If Python were to strip newlines, that would no longer be the case. (Even high-level protocols should avoid unnecessary modifications to files. One of the more annoying, if not crippling, limitations to the configparser module is that reading an INI file in, then writing it out again destroys the high-level structure of the file: comments and blank lines are stripped, and records may be re-ordered.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sat Mar 22 21:37:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Mar 2014 12:37:43 +1100 Subject: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary) Message-ID: On Sun, Mar 23, 2014 at 12:07 PM, Steven D'Aprano wrote: > On Sun, 23 Mar 2014 02:09:20 +1100, Chris Angelico wrote: > >> On Sun, Mar 23, 2014 at 1:50 AM, Steven D'Aprano >> wrote: >>> Line endings are terminators: they end the line. Whether you consider >>> the terminator part of the line or not is a matter of opinion (is the >>> cover of a book part of the book?) but consider this: >>> >>> If you say that the end of lines are *not* part of the line, then >>> that implies that some parts of the file are not inside any line at >>> all. And that would be just weird. >> >> Not so weird IMO. A file is not a concatenation of lines; it is a stream >> of bytes. > > But a *text file* is a concatenation of lines. The "text file" model is > important enough that nearly all programming languages offer a line-based > interface to files, and some (Python at least, possibly others) make it > the default interface so that iterating over the file gives you lines > rather than bytes -- even in "binary" mode. And lines are delimited entities. A text file is a sequence of lines, separated by certain characters. >> (Both interpretations make sense. I just wish the >> most obvious form of iteration gave the cleaner/tidier version, or at >> very least that there be some really obvious way to ask for >> lines-without-endings.) > > There is: call strip('\n') on the line after reading it. Perl and Ruby > spell it chomp(). Other languages may spell it differently. I don't know > of any language that automatically strips newlines, probably because you > can easily strip the newline from the line, but if the language did it > for you, you cannot reliably reverse it. That's not a tidy way to iterate, that's a way to iterate and then do stuff. Compare: for line in f: # process line with newline for line in f: line = line.strip("\n") # process line without newline, as long as it doesn't have \r\n or something for line in f: line = line.split("$") # process line as a series of dollar-delimited fields The second one is more like the third than the first. Python does not offer a tidy way to do the common thing, which is reading the content of the line without its terminator. >> Imagine the output of GNU find as a series of >> records. You can ask for those to be separated by newlines (the default, >> or -print), or by NULs (with the -print0 command). In either case, the >> records do not *contain* that value, they're separated by it; the >> records consist of file names. > > I have no problem with that: when interpreting text as a record with > delimiters, e.g. from a CSV file, you normally exclude the delimiter. > Sometimes the line terminator does double-duty as a record delimiter as > well. So why is the delimiter excluded when you treat the file as CSV, but included when you treat the file as lines of text? > Reading from a file is considered a low-level operation. Reading > individual bytes in binary mode is the lowest level; reading lines in > text mode is the next level, built on top of the lower binary mode. You > build higher protocols on top of one or the other of that mode, e.g. > "read a zip file" would be built on top of binary mode, "read a csv file" > would be built on top of text mode. I agree that reading a binary file is the lowest level. Reading a text file is higher level, but to me "reading a text file" means "reading a binary file and decoding it into Unicode text", and not "... and dividing it into lines". Bear in mind that reading a CSV file can be built on top of a Unicode decode, but not on a line-based iteration (in case there are newlines inside quotes). > As a low-level protocol, you ought to be able to copy a file without > changing it by reading it in then writing it out: > > for blob in infile: > outfile.write(blob) > > > ought to work whether you are in text mode or binary mode, so long as the > infile and outfile are opened in the same mode. If Python were to strip > newlines, that would no longer be the case. All you need is a "writeln" method that re-adds the newline, and then it's correctly round-tripping, based on what you've already stated about the file: that it's a series of lines of text. It might not be a byte-equivalent round-trip if you're changing newline style, any more than it already won't be for other reasons (file encoding, for instance). By reading the file as a series of Unicode lines, you're declaring that it contains lines of Unicode text, not arbitrary bytes, and so a valid representation of those lines of Unicode text is a faithful reproduction of the file. If you want a byte-for-byte identical file, open it in binary mode to do the copy; that's what we learn from FTPing files between Linux and Windows. > (Even high-level protocols should avoid unnecessary modifications to > files. One of the more annoying, if not crippling, limitations to the > configparser module is that reading an INI file in, then writing it out > again destroys the high-level structure of the file: comments and blank > lines are stripped, and records may be re-ordered.) Precisely. If you read it as an INI file and then rewrite it as an INI file, you risk damaging that sort of thing. If you parse a file as a Python script, and then reconstitute it from the AST (with one of the unparsers available), you have a guarantee that the result will execute the exact same code. But it won't be the same file (although Python's AST does guarantee order, unlike your INI file example). Actually, this might be a useful transformation to do, sometimes - part of a diff suite, maybe - if the old and new versions are identical after an AST parse/unparse transformation, you don't need to re-run tests, because there's no way a code bug can have been introduced. ChrisA From davea at davea.name Sat Mar 22 22:18:55 2014 From: davea at davea.name (Dave Angel) Date: Sat, 22 Mar 2014 22:18:55 -0400 (EDT) Subject: Question about Source Control References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> <20140322134917.080bada6@bigbox.christie.dr> <1395518482.78665.YahooMailNeo@web163804.mail.gq1.yahoo.com> Message-ID: Albert-Jan Roskam Wrote in message: > In addition to posting in html format, you have also set the font size too small for me to easily read. Reason number 12 for posting in text mode in a text newsgroup. -- DaveA From cs at zip.com.au Sat Mar 22 22:16:35 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 23 Mar 2014 13:16:35 +1100 Subject: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary) In-Reply-To: References: Message-ID: <20140323021635.GA90771@cskk.homeip.net> On 23Mar2014 12:37, Chris Angelico wrote: > On Sun, Mar 23, 2014 at 12:07 PM, Steven D'Aprano > wrote: > > On Sun, 23 Mar 2014 02:09:20 +1100, Chris Angelico wrote: > >> On Sun, Mar 23, 2014 at 1:50 AM, Steven D'Aprano > >> wrote: > >>> Line endings are terminators: they end the line. Whether you consider > >>> the terminator part of the line or not is a matter of opinion (is the > >>> cover of a book part of the book?) but consider this: > >>> > >>> If you say that the end of lines are *not* part of the line, then > >>> that implies that some parts of the file are not inside any line at > >>> all. And that would be just weird. > >> > >> Not so weird IMO. A file is not a concatenation of lines; it is a stream > >> of bytes. > > > > But a *text file* is a concatenation of lines. The "text file" model is > > important enough that nearly all programming languages offer a line-based > > interface to files, and some (Python at least, possibly others) make it > > the default interface so that iterating over the file gives you lines > > rather than bytes -- even in "binary" mode. > > And lines are delimited entities. A text file is a sequence of lines, > separated by certain characters. [...snip...] As far as I'm concerned, a text file is a sequence lines, each of which is _terminated_ by a newline (or the OS end-of-line flavour). So I say "terminated by", not "separated by". Plenty of people use editors that consider end-of-line to be a separator and not a terminator, leading to supposed text files lacking trailing newlines (or end-of-line of OS). I consider this sloppy and error prone. I like to be able to read a file and if it lacks a final newline then I have a good clue that the file was incompletely written. Editors (and other tools) that won't enforce a trailing newline as omitting an easy way to give a fairly robust indication of completion at no benefit to the user. (Not to mention the visual annoyance of "cat file" when there's no trailing newline.) So I'm happy to write code that errors if a line lacks a trailing newline, and thus I consider the newline to be an intergral part of the line. Having passed that sanity check, for most machine readable text formats I'm usually happy to use: line = line.rstrip() to get the salient part of the line. (Of course, lines extended with slosh-extension or the like need pickier handling.) Cheers, -- Cameron Simpson If at first you don't succeed, your sky-diving days are over. - Paul Blumstein, paulb at harley.tti.com, DoD #36 From ian.g.kelly at gmail.com Sat Mar 22 22:46:28 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 22 Mar 2014 20:46:28 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 6:32 PM, Rhodri James wrote: > On Sat, 22 Mar 2014 05:26:26 -0000, Rustom Mody > wrote: > >> Well almost... >> Except that the 'loop' I am talking of is one of >> def loop(): >> return [yield (lambda: x) for x in [1,2,3]] >> or >> return (yield (lambda: x) for x in [1,2,3]) >> or just plain ol >> (lambda x: for x in [1,2,3]) >> IOW loop is an imperative construct, comprehensions are declarative > > > I'm sorry, you've made a logical leap too far here. I understand loops > being imperative, but how are comprehensions declarative? What do they > declare that the loop equivalent doesn't. I'm with Rustom on this point. A list comprehension is a syntax for building a list by declaring a transformation from some other iterable object. Forget comprehensions for a moment and think of literals. Would you not consider this to be declarative? x = [1, 2, 3] A comprehension is syntactically similar to a literal, with just a different type of construction in mind. Where I disagree is on the question of whether Python should therefore break its established closure rules for lambdas that are nested inside comprehensions versus functions that are not. It breaks the equivalence between comprehensions and loops, and to my mind it introduces significant complexity for relatively little gain. From rustompmody at gmail.com Sat Mar 22 23:16:47 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 22 Mar 2014 20:16:47 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> Message-ID: <83b9f241-9b0a-4e81-8829-e1726c509471@googlegroups.com> On Sunday, March 23, 2014 8:16:28 AM UTC+5:30, Ian wrote: > On Sat, Mar 22, 2014 at 6:32 PM, Rhodri James wrote: > > wrote: > >> Well almost... > >> Except that the 'loop' I am talking of is one of > >> def loop(): > >> return [yield (lambda: x) for x in [1,2,3]] > >> or > >> return (yield (lambda: x) for x in [1,2,3]) > >> or just plain ol > >> (lambda x: for x in [1,2,3]) > >> IOW loop is an imperative construct, comprehensions are declarative > > I'm sorry, you've made a logical leap too far here. I understand loops > > being imperative, but how are comprehensions declarative? What do they > > declare that the loop equivalent doesn't. > I'm with Rustom on this point. A list comprehension is a syntax for > building a list by declaring a transformation from some other iterable > object. Forget comprehensions for a moment and think of literals. > Would you not consider this to be declarative? > x = [1, 2, 3] > A comprehension is syntactically similar to a literal, with just a > different type of construction in mind. Aha! Very elegantly put! > Where I disagree is on the question of whether Python should therefore > break its established closure rules for lambdas that are nested inside > comprehensions versus functions that are not. No... see below > It breaks the > equivalence between comprehensions and loops, and to my mind it > introduces significant complexity for relatively little gain. [I am not completely sure whether the following can be proved/is true] 1. One can change lambda's closure rules which would amount to "significant complexity for relatively little gain" 2. One can change comprehension rules to not reassign to the running comprehension running varible but to rebind, using a recursive function as the simulation of the comprehension rather than a for loop 3. 2 is semantically equivalent to 1 - trivially for normal (ie non-lambda containing) expressions - and also for lambda containing expressions if your default-argument trick is implemented by the python compiler [This is the claim I am not completely sure of and would love to hear of/if counter examples] Assuming its true: One *semantically specifies* a comprehension with a recursive function, not a for loop One *implements* a comprehension with the standard use of append method inside a for as the expansion of a comprehension with the extra caveat that interior lambdas are automatically wrapped inside a default-argument binding for all outer comprehension variables. A vanilla python programmer need not know anything about this any more than a vanilla C programmer knows about - strength reduction - code hoisting - loop unrolling etc that goes on inside an optimizing C compiler From ian.g.kelly at gmail.com Sat Mar 22 23:47:42 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 22 Mar 2014 21:47:42 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <83b9f241-9b0a-4e81-8829-e1726c509471@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> <83b9f241-9b0a-4e81-8829-e1726c509471@googlegroups.com> Message-ID: On Sat, Mar 22, 2014 at 9:16 PM, Rustom Mody wrote: > [I am not completely sure whether the following can be proved/is true] > > 1. One can change lambda's closure rules which would amount to > "significant complexity for relatively little gain" > > 2. One can change comprehension rules to not reassign to the > running comprehension running varible but to rebind, using a recursive > function as the simulation of the comprehension rather than a for loop > > 3. 2 is semantically equivalent to 1 Well, if you accept that 1) amounts to significant complexity for relatively little gain, and if 2) is semantically equivalent to 1), then it follows that 2) also amounts to significant complexity for relatively little gain. My statement was in regard to the complexity of the language, not the implementation of the language. > - trivially for normal (ie non-lambda containing) expressions > - and also for lambda containing expressions if your > default-argument trick is implemented by the python compiler > [This is the claim I am not completely sure of and would love to hear > of/if counter examples] The disadvantage of the default argument trick is that it does modify the function's signature, by adding an extra argument with a default, so they're not entirely equivalent. > Assuming its true: > > One *semantically specifies* a comprehension with a recursive function, > not a for loop The problem with this is a cognitive one. The comprehension *looks like* a for loop, not a recursive function. It is natural to reason about it as if it were a for loop, not a recursive function. This is that added complexity I was talking about. > A vanilla python programmer need not know anything about this any > more than a vanilla C programmer knows about > - strength reduction > - code hoisting > - loop unrolling > etc > > that goes on inside an optimizing C compiler Until they go to unroll their comprehension into a for loop because they need to add some imperative construct to it, and their code breaks as a result. From there you'll get the programmers who will add functions with side effects to their comprehensions because they want the comprehension binding behavior while still performing imperative tasks within the loop. From marko at pacujo.net Sun Mar 23 06:22:11 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 23 Mar 2014 12:22:11 +0200 Subject: Reading in cooked mode References: Message-ID: <87eh1tjju4.fsf@elektro.pacujo.net> Cameron Simpson : > Plenty of people use editors that consider end-of-line to be a > separator and not a terminator, leading to supposed text files lacking > trailing newlines (or end-of-line of OS). I use an editor (emacs) that considers the end-of-line to be a byte among others. > I consider this sloppy and error prone. If any editor, emacs is smart, but it generally doesn't insert characters on its own. I like it that way. > So I'm happy to write code that errors if a line lacks a trailing > newline, and thus I consider the newline to be an intergral part of > the line. For sure, any file reader must think the situation through. Note, for example, that CPython doesn't require the source code file to end in a newline. Marko From jt at toerring.de Sun Mar 23 09:07:11 2014 From: jt at toerring.de (Jens Thoms Toerring) Date: 23 Mar 2014 13:07:11 GMT Subject: Help needed to create a Python extension library for an existing shared memory hash table library References: Message-ID: Simon Hardy-Francis wrote: > Hi Python fans, I just released my first open source project ever called > SharedHashFile [1]. It's a shared memory hash table written in C. Some guy > on Quora asked [2] whether there's an extension library for Python coming > out. I would like to do one but I know little about Python. I was wondering > if anybody in this group has experience writing extension libraries for > Python? There are, as far as I know, a number of tools that can help you to create extension modules from C/C++ libraries (i.e. Python bin- dings for the library). One that I have used successfully with a largish C++ library of mine is shortly described here http://www.riverbankcomputing.com/software/sip/intro and the documentation and download are at http://pyqt.sourceforge.net/Docs/sip4/ http://www.riverbankcomputing.com/software/sip/download Since I haven't used any of the alternatives I can't comment on how good they are. A list of them can be found here https://wiki.python.org/moin/IntegratingPythonWithOtherLanguages Regards, Jens -- \ Jens Thoms Toerring ___ jt at toerring.de \__________________________ http://toerring.de From rustompmody at gmail.com Sun Mar 23 09:40:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 23 Mar 2014 06:40:26 -0700 (PDT) Subject: Help needed to create a Python extension library for an existing shared memory hash table library In-Reply-To: References: Message-ID: On Sunday, March 23, 2014 6:37:11 PM UTC+5:30, Jens Thoms Toerring wrote: > Simon Hardy-Francis wrote: > > Hi Python fans, I just released my first open source project ever called > > SharedHashFile [1]. It's a shared memory hash table written in C. Some guy > > on Quora asked [2] whether there's an extension library for Python coming > > out. I would like to do one but I know little about Python. I was wondering > > if anybody in this group has experience writing extension libraries for > > Python? > There are, as far as I know, a number of tools that can help you > to create extension modules from C/C++ libraries (i.e. Python bin- > dings for the library). One that I have used successfully with a > largish C++ library of mine is shortly described here > http://www.riverbankcomputing.com/software/sip/intro > and the documentation and download are at > http://pyqt.sourceforge.net/Docs/sip4/ > http://www.riverbankcomputing.com/software/sip/download > Since I haven't used any of the alternatives I can't comment on > how good they are. A list of them can be found here > https://wiki.python.org/moin/IntegratingPythonWithOtherLanguages Thats an old looking list -- pyrex is on, boost is not Worst of all the basic builting extending/embedding seems to be not mentioned! Heres a list I posted recently https://mail.python.org/pipermail/python-list/2013-June/650250.html If it looks ok, maybe it should go up on that wiki From azt113 at gmail.com Sun Mar 23 10:00:55 2014 From: azt113 at gmail.com (azt113 at gmail.com) Date: Sun, 23 Mar 2014 07:00:55 -0700 (PDT) Subject: Install CVXOPT in Windows 64 bit Message-ID: Hello! I need to urgently install CVOXPT in my pc. However, it seems that it only works under 32 bit versions. Does anyone know about a way around this? Your advise will be much appreciated! Ines From fomcl at yahoo.com Sun Mar 23 10:58:20 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sun, 23 Mar 2014 07:58:20 -0700 (PDT) Subject: Question about Source Control In-Reply-To: References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> <20140322134917.080bada6@bigbox.christie.dr> <1395518482.78665.YahooMailNeo@web163804.mail.gq1.yahoo.com> Message-ID: <1395586700.55921.YahooMailNeo@web163806.mail.gq1.yahoo.com> ________________________________ > From: Dave Angel >To: python-list at python.org >Sent: Sunday, March 23, 2014 3:18 AM >Subject: Re: Question about Source Control > > >Albert-Jan Roskam Wrote in message: >> > >In addition to posting in html format,? you have also set the font >size too small for me to easily read. Reason number 12 for >posting in text mode in a text newsgroup. Ooops, sorry. Below is the email again, hopefully more readable. One more thing (so this is not entirely a double post!). While reading these books I found that the authors were pretty religious about Clean Commits. I mean, ok, it's not a good idea to do one huge monolithic commit each month, but I felt they were exaggerating. But maybe I'm wrong and clean commits become more important when the number of collaborators get bigger. It's just so easy to fix something, and e.g. correct that typo in a docstring while you're at it. regards, Albert-Jan Hi, I can recommend the book "Pragmatic Guide to Git". Very practical and to the point: http://www.amazon.com/Pragmatic-Guide-Git-Programmers/dp/1934356727/ref=sr_1_1/184-0142481-0484062?ie=UTF8&qid=1395518159&sr=8-1&keywords=pragmatic+guide+to+git I addition, I read a big fat super-exhaustive book, I believe it' s this one (there are two Git books with a bat!): http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387/ref=sr_1_2/184-0142481-0484062?ie=UTF8&qid=1395518159&sr=8-2&keywords=pragmatic+guide+to+git The former is for common tasks that are not common enough to remember right away. The latter is for reference. I only have experience with git and subversion. I like git much better. But any SCM is better than none at all. ?Regards, Albert-Jan From breamoreboy at yahoo.co.uk Sun Mar 23 11:30:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Mar 2014 15:30:40 +0000 Subject: Install CVXOPT in Windows 64 bit In-Reply-To: References: Message-ID: On 23/03/2014 14:00, azt113 at gmail.com wrote: > Hello! > I need to urgently install CVOXPT in my pc. However, it seems that it only works under 32 bit versions. Does anyone know about a way around this? > Your advise will be much appreciated! > Ines > http://www.lfd.uci.edu/~gohlke/pythonlibs/#cvxopt -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rborole06 at gmail.com Sun Mar 23 13:09:09 2014 From: rborole06 at gmail.com (rborole06 at gmail.com) Date: Sun, 23 Mar 2014 10:09:09 -0700 (PDT) Subject: python installation on windows Message-ID: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> Hi Everybody actually i want to run python on web browser. I downloaded python and installed but i'm not able to run it in browser but it running using command prompt. so i trying to install mod_wsgi 3.4. So i downloaded precompiled version mod_wsgi-3.4.ap22.win32-py2.6 and copied mod_wsgi.so file to C:\wamp\bin\apache\Apache2.2.11\modules after i'm trying to run .\configure on path C:\Documents and Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 but it giving me error that .\configure is not recognized as internal or external command. So please suggest me what can i do for that, i'm so beginner to python and installing and configuring modules for apache. Thanks Rahul From teddybubu at gmail.com Sun Mar 23 13:29:40 2014 From: teddybubu at gmail.com (tad na) Date: Sun, 23 Mar 2014 10:29:40 -0700 (PDT) Subject: help with for loop----python 2.7.2 In-Reply-To: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> Message-ID: <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> On Saturday, March 22, 2014 6:21:30 AM UTC-5, tad na wrote: > I am trying to get all the element data from the rss below. > > The only thing I am pulling is the first element. > I don't understand why the for loop does not go through the entire rss. > Here is my code.... > try: > from urllib2 import urlopen > except ImportError: > from urllib.request import urlopen > from bs4 import BeautifulSoup > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > #print soup.find_all('item') > #print (soup) > for item in soup.find_all('item'): > #for item in soup: > title = soup.find('title').text > link = soup.find('link').text > item = soup.find('item').text > print item > print title > print link OK . second problem :) I can print the date. not sure how to do this one.. try: from urllib2 import urlopen except ImportError: from urllib.request import urlopen import urllib2 from bs4 import BeautifulSoup soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) #print soup.find_all('item') #print (soup) data = soup.find_all("item") x=0 for item in soup.find_all('item'): title = item.find('title').text link = item.find('link').text date = item.find('pubDate') # print date print('+++++++++++++++++') print data[x].title.text print data[x].link.text print data[x].guid.text print data[x].pubDate x = x + 1 From teddybubu at gmail.com Sun Mar 23 13:30:27 2014 From: teddybubu at gmail.com (tad na) Date: Sun, 23 Mar 2014 10:30:27 -0700 (PDT) Subject: help with for loop----python 2.7.2 In-Reply-To: <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> Message-ID: <32858d81-7dcf-45de-af10-6157068f15af@googlegroups.com> On Sunday, March 23, 2014 12:29:40 PM UTC-5, tad na wrote: > On Saturday, March 22, 2014 6:21:30 AM UTC-5, tad na wrote: > > > I am trying to get all the element data from the rss below. > > > > > > The only thing I am pulling is the first element. > > > > > I don't understand why the for loop does not go through the entire rss. > > > > > Here is my code.... > > > try: > > > from urllib2 import urlopen > > > except ImportError: > > > from urllib.request import urlopen > > > from bs4 import BeautifulSoup > > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > > > #print soup.find_all('item') > > > #print (soup) > > > for item in soup.find_all('item'): > > > #for item in soup: > > > title = soup.find('title').text > > > link = soup.find('link').text > > > item = soup.find('item').text > > > print item > > > print title > > > print link > > OK . second problem :) > > I can print the date. not sure how to do this one.. > > try: > > from urllib2 import urlopen > > except ImportError: > > from urllib.request import urlopen > > import urllib2 > > from bs4 import BeautifulSoup > > > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > > #print soup.find_all('item') > > #print (soup) > > data = soup.find_all("item") > > > > x=0 > > for item in soup.find_all('item'): > > title = item.find('title').text > > link = item.find('link').text > > date = item.find('pubDate') > > # print date > > print('+++++++++++++++++') > > print data[x].title.text > > print data[x].link.text > > print data[x].guid.text > > print data[x].pubDate > > x = x + 1 meant to say CANNOT print the date From teddybubu at gmail.com Sun Mar 23 13:33:02 2014 From: teddybubu at gmail.com (tad na) Date: Sun, 23 Mar 2014 10:33:02 -0700 (PDT) Subject: python installation on windows In-Reply-To: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> Message-ID: On Sunday, March 23, 2014 12:09:09 PM UTC-5, rbor... at gmail.com wrote: > Hi Everybody > > > > actually i want to run python on web browser. I downloaded python and installed but i'm not able to run it in browser but it running using command prompt. so i trying to install mod_wsgi 3.4. So i downloaded precompiled version mod_wsgi-3.4.ap22.win32-py2.6 and copied mod_wsgi.so file to C:\wamp\bin\apache\Apache2.2.11\modules after i'm trying to run .\configure on path C:\Documents and Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 but it giving me error that .\configure is not recognized as internal or external command. > > > > So please suggest me what can i do for that, i'm so beginner to python and installing and configuring modules for apache. > > > > Thanks > > Rahul To set up a web browser: 1.open a dos window 2.navigate to dir you want "served" 3.type "python -m SimpleHTTPServer 8888 &." From breamoreboy at yahoo.co.uk Sun Mar 23 13:40:04 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Mar 2014 17:40:04 +0000 Subject: help with for loop----python 2.7.2 In-Reply-To: <32858d81-7dcf-45de-af10-6157068f15af@googlegroups.com> References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> <32858d81-7dcf-45de-af10-6157068f15af@googlegroups.com> Message-ID: On 23/03/2014 17:30, tad na wrote: Would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ian.g.kelly at gmail.com Sun Mar 23 13:49:11 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 23 Mar 2014 11:49:11 -0600 Subject: help with for loop----python 2.7.2 In-Reply-To: <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> Message-ID: On Mar 23, 2014 11:31 AM, "tad na" wrote: > OK . second problem :) > I can print the date. not sure how to do this one.. Why not? What happens when you try? > try: > from urllib2 import urlopen > except ImportError: > from urllib.request import urlopen > import urllib2 > from bs4 import BeautifulSoup > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > #print soup.find_all('item') > #print (soup) > data = soup.find_all("item") > > x=0 > for item in soup.find_all('item'): > title = item.find('title').text > link = item.find('link').text > date = item.find('pubDate') > # print date > print('+++++++++++++++++') > print data[x].title.text > print data[x].link.text > print data[x].guid.text > print data[x].pubDate > x = x + 1 data[x] should be the same object as item, no? If you want to keep track of the current iteration index, a cleaner way to do that is by using enumerate: for x, item in enumerate(soup.find_all('item')): As far as printing the pubDate goes, why not start by getting its text property as you do with the other tags? From there you can either print the string out directly or parse it into a datetime object. -------------- next part -------------- An HTML attachment was scrubbed... URL: From teddybubu at gmail.com Sun Mar 23 13:49:12 2014 From: teddybubu at gmail.com (tad na) Date: Sun, 23 Mar 2014 10:49:12 -0700 (PDT) Subject: help with for loop----python 2.7.2 In-Reply-To: References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> <32858d81-7dcf-45de-af10-6157068f15af@googlegroups.com> Message-ID: <1bd3b586-b3ed-4d18-8d68-26a2144f6163@googlegroups.com> On Sunday, March 23, 2014 12:40:04 PM UTC-5, Mark Lawrence wrote: > On 23/03/2014 17:30, tad na wrote: > Would you please use the mailing list > https://mail.python.org/mailman/listinfo/python-list or read and action > this https://wiki.python.org/moin/GoogleGroupsPython to prevent us > seeing double line spacing and single line paragraphs, thanks. > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > Mark Lawrence > --- > This email is free from viruses and malware because avast! Antivirus protection is active. > http://www.avast.com mark not sure what i did wrong. The double line in the code is mine. it helps me keep things separate. From breamoreboy at yahoo.co.uk Sun Mar 23 14:43:59 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 23 Mar 2014 18:43:59 +0000 Subject: help with for loop----python 2.7.2 In-Reply-To: <32858d81-7dcf-45de-af10-6157068f15af@googlegroups.com> References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> <32858d81-7dcf-45de-af10-6157068f15af@googlegroups.com> Message-ID: On 23/03/2014 17:30, tad na wrote: > On Sunday, March 23, 2014 12:29:40 PM UTC-5, tad na wrote: >> On Saturday, March 22, 2014 6:21:30 AM UTC-5, tad na wrote: >> >>> I am trying to get all the element data from the rss below. >> >>> >> >>> The only thing I am pulling is the first element. >> >> >> >>> I don't understand why the for loop does not go through the entire rss. >> >> >> >>> Here is my code.... I've snipped the bulk of the message, but imagine what the above looks like when its been back and forth through gg a few times, it's effectively unreadable. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From teddybubu at gmail.com Sun Mar 23 17:07:28 2014 From: teddybubu at gmail.com (tad na) Date: Sun, 23 Mar 2014 14:07:28 -0700 (PDT) Subject: python installation on windows In-Reply-To: References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> Message-ID: <73a660da-9dd8-4104-ae9c-ba1788ae1d60@googlegroups.com> On Sunday, March 23, 2014 12:33:02 PM UTC-5, tad na wrote: > On Sunday, March 23, 2014 12:09:09 PM UTC-5, rbor... at gmail.com wrote: > > Hi Everybody > > actually i want to run python on web browser. I downloaded python and installed but i'm not able to run it in browser but it running using command prompt. so i trying to install mod_wsgi 3.4. So i downloaded precompiled version mod_wsgi-3.4.ap22.win32-py2.6 and copied mod_wsgi.so file to C:\wamp\bin\apache\Apache2.2.11\modules after i'm trying to run .\configure on path C:\Documents and Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 but it giving me error that .\configure is not recognized as internal or external command. > > So please suggest me what can i do for that, i'm so beginner to python and installing and configuring modules for apache. > > Thanks > > Rahul > To set up a web browser: > 1.open a dos window > 2.navigate to dir you want "served" > 3.type "python -m SimpleHTTPServer 8888 &." 4. open browser and type http://localhost:8888/ From teddybubu at gmail.com Sun Mar 23 17:51:19 2014 From: teddybubu at gmail.com (tad na) Date: Sun, 23 Mar 2014 14:51:19 -0700 (PDT) Subject: help with for loop----python 2.7.2 In-Reply-To: References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> Message-ID: <5f8a6cae-4e84-4748-beb1-fd931b187e4e@googlegroups.com> On Sunday, March 23, 2014 12:49:11 PM UTC-5, Ian wrote: > On Mar 23, 2014 11:31 AM, "tad na" wrote: > > OK . second problem :) > > I can print the date. ?not sure how to do this one.. > Why not? What happens when you try? > > try: > > ? ? from urllib2 import urlopen > > except ImportError: > > ? ? from urllib.request import urlopen > > import urllib2 > > from bs4 import BeautifulSoup > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > > #print soup.find_all('item') > > #print (soup) > > data = soup.find_all("item") > > x=0 > > for item in soup.find_all('item'): > > ? ? title = item.find('title').text > > ? ? link = item.find('link').text > > ? ? date = item.find('pubDate') > > ? ?# print date > > ? ? print('+++++++++++++++++') > > ? ? print data[x].title.text > > ? ? print data[x].link.text > > ? ? print data[x].guid.text > > ? ? print data[x].pubDate > > ? ? x = x + 1 > data[x] should be the same object as item, no? If you want to keep track of the current iteration index, a cleaner way to do that is by using enumerate: > ??? for x, item in enumerate(soup.find_all('item')): > As far as printing the pubDate goes, why not start by getting its text property as you do with the other tags? From there you can either print the string out directly or parse it into a datetime object. This is the error I get with 1. print data[x].pubDate.text AttributeError: 'NoneType' object has no attribute 'text' 2. print data[x].pubDate It results in "None" From ben+python at benfinney.id.au Sun Mar 23 18:39:09 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 24 Mar 2014 09:39:09 +1100 Subject: help with for loop----python 2.7.2 References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> Message-ID: <85k3bksfoy.fsf@benfinney.id.au> teddybubu at gmail.com writes: > I am trying to get all the element data from the rss below. [?] > from bs4 import BeautifulSoup > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) RSS is not HTML; so BeautifulSoup is not a good tool to use for parsing RSS. Instead, you will do better if you use one of the libraries already written for RSS parsing . -- \ ?To be is to do? ?Plato | `\ ?To do is to be? ?Aristotle | _o__) ?Do be do be do? ?Sinatra | Ben Finney From ian.g.kelly at gmail.com Sun Mar 23 18:44:41 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 23 Mar 2014 16:44:41 -0600 Subject: help with for loop----python 2.7.2 In-Reply-To: <5f8a6cae-4e84-4748-beb1-fd931b187e4e@googlegroups.com> References: <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com> <03c8b5d0-363e-4287-80d0-a43b0266f2a3@googlegroups.com> <5f8a6cae-4e84-4748-beb1-fd931b187e4e@googlegroups.com> Message-ID: On Mar 23, 2014 3:56 PM, "tad na" wrote: > > This is the error I get with > 1. print data[x].pubDate.text > AttributeError: 'NoneType' object has no attribute 'text' > 2. print data[x].pubDate > It results in "None" So the problem is that it's not even finding the pubDate tag in the first place. Some sites on the Web suggest that beautiful soup normalizes all tags to lowercase; try looking for the pubdate tag instead. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Mar 23 18:56:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 09:56:02 +1100 Subject: Question about Source Control In-Reply-To: <1395586700.55921.YahooMailNeo@web163806.mail.gq1.yahoo.com> References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> <20140322134917.080bada6@bigbox.christie.dr> <1395518482.78665.YahooMailNeo@web163804.mail.gq1.yahoo.com> <1395586700.55921.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: On Mon, Mar 24, 2014 at 1:58 AM, Albert-Jan Roskam wrote: > One more thing (so this is not entirely a double post!). While reading these books I found that the authors were pretty religious about Clean Commits. I mean, ok, it's not a good idea to do one huge monolithic commit each month, but I felt they were exaggerating. But maybe I'm wrong and clean commits become more important when the number of collaborators get bigger. It's just so easy to fix something, and e.g. correct that typo in a docstring while you're at it. > It's important even with a single editor. When you go back and look at a commit, you should be able to read the summary and know immediately whether a particular line in it should have been edited or not. Combining changes into a single commit makes that harder. Commits are cheap. Do more of 'em rather than less. ChrisA From cs at zip.com.au Sun Mar 23 20:19:53 2014 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 24 Mar 2014 11:19:53 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140324001953.GA70218@cskk.homeip.net> On 24Mar2014 09:56, Chris Angelico wrote: > On Mon, Mar 24, 2014 at 1:58 AM, Albert-Jan Roskam wrote: > > One more thing (so this is not entirely a double post!). While reading these books I found that the authors were pretty religious about Clean Commits. I mean, ok, it's not a good idea to do one huge monolithic commit each month, but I felt they were exaggerating. But maybe I'm wrong and clean commits become more important when the number of collaborators get bigger. It's just so easy to fix something, and e.g. correct that typo in a docstring while you're at it. > > > > It's important even with a single editor. When you go back and look at > a commit, you should be able to read the summary and know immediately > whether a particular line in it should have been edited or not. > Combining changes into a single commit makes that harder. > > Commits are cheap. Do more of 'em rather than less. I'm particularly fond of "hg record" (or the similar extension, "hg crecord"), which lets you commit just parts of a modified file. When I'm in a debugging branch, it gradually turns into a huge diff. "hg record" lets me commit specific parts of a diff in a single commit. Every so often I spent a little while cleaning out related changes that are going to stay so that the final diffness consists of debug statements and hacks-in-progress; much smaller. So I'll pick a file and run an "hg record that-file" and pick all the diff parts that involve, say, removing some parameter. And in goes a single commit with just that feature change. Lather, rinse, repeat for other small concrete changes. And then my "hg diff" is back to being managably readable. Cheers, -- Cameron Simpson Wagner's music is better than it sounds. - Mark Twain From rosuav at gmail.com Sun Mar 23 20:30:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 11:30:28 +1100 Subject: Question about Source Control In-Reply-To: <20140324001953.GA70218@cskk.homeip.net> References: <20140324001953.GA70218@cskk.homeip.net> Message-ID: On Mon, Mar 24, 2014 at 11:19 AM, Cameron Simpson wrote: > I'm particularly fond of "hg record" (or the similar extension, "hg > crecord"), which lets you commit just parts of a modified file. > > When I'm in a debugging branch, it gradually turns into a huge diff. > "hg record" lets me commit specific parts of a diff in a single > commit. Every so often I spent a little while cleaning out related > changes that are going to stay so that the final diffness consists > of debug statements and hacks-in-progress; much smaller. > > So I'll pick a file and run an "hg record that-file" and pick all > the diff parts that involve, say, removing some parameter. And in > goes a single commit with just that feature change. Lather, rinse, > repeat for other small concrete changes. > > And then my "hg diff" is back to being managably readable. > Absolutely agree. With git, the same functionality can be done by making use of the staging area; you can either add an entire file (all its changes), or do a partial add with "git add -p" or (more conveniently, but requires a GUI) "git gui". I do that *very* frequently. The only thing I would really like is a simple way to say "stage/commit the lines from here to there"; with git gui, I can either stage an entire hunk (everything until the next point where there's enough unchanged lines that the context breaks) or a single line (either an insertion or a removal). Gets tedious when you want to stage half of a large hunk. But other than that, yes, the functionality is awesome, letting you fidget your edits into readable commits. ChrisA From pabloeruggeri at gmail.com Sun Mar 23 20:35:14 2014 From: pabloeruggeri at gmail.com (pabloeruggeri at gmail.com) Date: Sun, 23 Mar 2014 17:35:14 -0700 (PDT) Subject: loop Message-ID: Hello, I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The increments are like this: 100, 1000, 10000, ..... Basicaly adding a zero each iteration. I'm having problems trying to do it. Can somebody help me From python at mrabarnett.plus.com Sun Mar 23 20:50:55 2014 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 24 Mar 2014 00:50:55 +0000 Subject: loop In-Reply-To: References: Message-ID: <532F816F.1080301@mrabarnett.plus.com> On 2014-03-24 00:35, pabloeruggeri at gmail.com wrote: > Hello, > > I'm trying to create a for loop that starts at 100 and goes to > 10Mllion. The increments are like this: 100, 1000, 10000, ..... > Basicaly adding a zero each iteration. I'm having problems trying to > do it. Can somebody help me > Probably better to use a 'while' loop instead, multiplying by 10 on each iteration until the number exceeds 10 million. From rosuav at gmail.com Sun Mar 23 20:52:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 11:52:11 +1100 Subject: loop In-Reply-To: References: Message-ID: On Mon, Mar 24, 2014 at 11:35 AM, wrote: > Hello, > > I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The increments are like this: 100, 1000, 10000, ..... Basicaly adding a zero each iteration. I'm having problems trying to do it. Can somebody help me > That sounds like a logarithmic scale. Look at this: >>> 10**2 100 >>> 10**3 1000 ... >>> 10**7 10000000 Do you know how to iterate from 2 to 7 inclusive? ChrisA From breamoreboy at yahoo.co.uk Sun Mar 23 20:56:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 00:56:51 +0000 Subject: loop In-Reply-To: References: Message-ID: On 24/03/2014 00:35, pabloeruggeri at gmail.com wrote: > Hello, > > I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The increments are like this: 100, 1000, 10000, ..... Basicaly adding a zero each iteration. I'm having problems trying to do it. Can somebody help me > Start by rereading this http://docs.python.org/3/tutorial/controlflow.html#for-statements, give it another go and if you have problems post your code inline here and we'll help you out. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From pabloeruggeri at gmail.com Sun Mar 23 20:57:28 2014 From: pabloeruggeri at gmail.com (pabloeruggeri at gmail.com) Date: Sun, 23 Mar 2014 17:57:28 -0700 (PDT) Subject: loop In-Reply-To: References: Message-ID: Thanks!! From bupphairodazz at yandex.ru Sun Mar 23 20:59:20 2014 From: bupphairodazz at yandex.ru (anton) Date: Sun, 23 Mar 2014 17:59:20 -0700 (PDT) Subject: loop In-Reply-To: References: Message-ID: <05924f21-0162-4d4c-84d0-016c7fdfeee1@googlegroups.com> for i in (10**p for p in range(3, 8)): print(i) From cs at zip.com.au Sun Mar 23 21:07:13 2014 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 24 Mar 2014 12:07:13 +1100 Subject: Question about Source Control In-Reply-To: References: Message-ID: <20140324010713.GA46934@cskk.homeip.net> On 24Mar2014 11:30, Chris Angelico wrote: > On Mon, Mar 24, 2014 at 11:19 AM, Cameron Simpson wrote: > > I'm particularly fond of "hg record" (or the similar extension, "hg > > crecord"), which lets you commit just parts of a modified file. > > > > When I'm in a debugging branch, it gradually turns into a huge diff. > > [...] Every so often I spent a little while cleaning out related > > changes that are going to stay so that the final diffness consists > > of debug statements and hacks-in-progress; much smaller. [...] > > Absolutely agree. With git, the same functionality can be done by > making use of the staging area; you can either add an entire file (all > its changes), or do a partial add with "git add -p" or (more > conveniently, but requires a GUI) "git gui". [...] > The only thing I would really like is a simple way to say > "stage/commit the lines from here to there"; with git gui, I can > either stage an entire hunk (everything until the next point where > there's enough unchanged lines that the context breaks) or a single > line (either an insertion or a removal). Gets tedious when you want to > stage half of a large hunk. [...] "hg record" has the same issue; you get to approve or ignore single diff chunks. However, there's no fundamental technical reason you can't pick and choose arbitrary lines. Based on things I've experienced use "hg record", it pretty clearly walks the user through the diff picking/rejecting chunks, and then temporarily replaces the target file(s) with versions containing only the selected diff chunks, and commits the files. Then it restores the original modified file, whose diff from the "tip" is now reduced. With some work, that could be done on a line-by-line basis. Cheers, -- Cameron Simpson I've always been a big Greenaway fan - I've seen and enjoyed "The Falls" for crying out loud. - Peter Alexander Merel From tjreedy at udel.edu Sun Mar 23 21:26:54 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 23 Mar 2014 21:26:54 -0400 Subject: Question about Source Control In-Reply-To: References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> <20140322134917.080bada6@bigbox.christie.dr> <1395518482.78665.YahooMailNeo@web163804.mail.gq1.yahoo.com> <1395586700.55921.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: On 3/23/2014 6:56 PM, Chris Angelico wrote: > On Mon, Mar 24, 2014 at 1:58 AM, Albert-Jan Roskam wrote: >> One more thing (so this is not entirely a double post!). While reading these books I found that the authors were pretty religious about Clean Commits. I mean, ok, it's not a good idea to do one huge monolithic commit each month, but I felt they were exaggerating. But maybe I'm wrong and clean commits become more important when the number of collaborators get bigger. It's just so easy to fix something, and e.g. correct that typo in a docstring while you're at it. >> > > It's important even with a single editor. When you go back and look at > a commit, you should be able to read the summary and know immediately > whether a particular line in it should have been edited or not. > Combining changes into a single commit makes that harder. > > Commits are cheap. Do more of 'em rather than less. With multiple branches (as with 2.7, 3.4, and default for cpython) and multiple active developers (20?) commiting to those brances, commits are definitely not free. I would not exactly call them as cheap as you seem to imply either. That said, I have occasionally pushed interim changes that put code in an improved and stable state. N. Coughlan has suggested improving the cpython infrastructure and procedures to reduce the cost of commits to encourage more people to make more commits (in the sense of more lines changed, not more pieces) and improve cpython faster. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sun Mar 23 21:42:23 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 01:42:23 +0000 Subject: Question about Source Control In-Reply-To: References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> <20140322134917.080bada6@bigbox.christie.dr> <1395518482.78665.YahooMailNeo@web163804.mail.gq1.yahoo.com> <1395586700.55921.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: On 24/03/2014 01:26, Terry Reedy wrote: > On 3/23/2014 6:56 PM, Chris Angelico wrote: >> On Mon, Mar 24, 2014 at 1:58 AM, Albert-Jan Roskam >> wrote: >>> One more thing (so this is not entirely a double post!). While >>> reading these books I found that the authors were pretty religious >>> about Clean Commits. I mean, ok, it's not a good idea to do one huge >>> monolithic commit each month, but I felt they were exaggerating. But >>> maybe I'm wrong and clean commits become more important when the >>> number of collaborators get bigger. It's just so easy to fix >>> something, and e.g. correct that typo in a docstring while you're at it. >>> >> >> It's important even with a single editor. When you go back and look at >> a commit, you should be able to read the summary and know immediately >> whether a particular line in it should have been edited or not. >> Combining changes into a single commit makes that harder. >> >> Commits are cheap. Do more of 'em rather than less. > > With multiple branches (as with 2.7, 3.4, and default for cpython) and > multiple active developers (20?) commiting to those brances, commits are > definitely not free. I would not exactly call them as cheap as you seem > to imply either. That said, I have occasionally pushed interim changes > that put code in an improved and stable state. And consider that this has been simplified, at one point four branches plus default were being supported at the same time. > > N. Coughlan has suggested improving the cpython infrastructure and > procedures to reduce the cost of commits to encourage more people to > make more commits (in the sense of more lines changed, not more pieces) > and improve cpython faster. > Excellent. The most frustrating part of CPython development from my viewpoint is the massive number of open issues on the bug tracker that have patches, but simply sit there for years doing nothing except gather dust. Anything that can be done to improve this situation is IMHO long overdue and extremely welcome. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Sun Mar 23 22:04:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 13:04:54 +1100 Subject: Question about Source Control In-Reply-To: References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> <20140322134917.080bada6@bigbox.christie.dr> <1395518482.78665.YahooMailNeo@web163804.mail.gq1.yahoo.com> <1395586700.55921.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: On Mon, Mar 24, 2014 at 12:26 PM, Terry Reedy wrote: > With multiple branches (as with 2.7, 3.4, and default for cpython) and > multiple active developers (20?) commiting to those brances, commits are > definitely not free. I would not exactly call them as cheap as you seem to > imply either. That said, I have occasionally pushed interim changes that put > code in an improved and stable state. > > N. Coughlan has suggested improving the cpython infrastructure and > procedures to reduce the cost of commits to encourage more people to make > more commits (in the sense of more lines changed, not more pieces) and > improve cpython faster. When I call them cheap, what I mean is that there's little difference between a single commit and 2-3 commits as a group. Yes, there's a bit more difference when you're cherry-picking them to other branches, and maybe an infrastructure/procedure change could help with that; but once they're there in history, it doesn't hurt to have three separate commits doing related work, keeping the distinct parts distinct. ChrisA From rhodri at wildebst.org.uk Sun Mar 23 22:22:54 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Mon, 24 Mar 2014 02:22:54 -0000 Subject: python installation on windows References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> Message-ID: On Sun, 23 Mar 2014 17:09:09 -0000, wrote: > Hi Everybody > > actually i want to run python on web browser. Actually you don't. You want to run Python on a web server, which fortunately is a good deal easier. > I downloaded python and installed but i'm not able to run it in browser > but it running using command prompt. so i trying to install mod_wsgi > 3.4. So i downloaded precompiled version mod_wsgi-3.4.ap22.win32-py2.6 > and copied mod_wsgi.so file to C:\wamp\bin\apache\Apache2.2.11\modules > after i'm trying to run .\configure on path C:\Documents and > Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 but it giving me > error that .\configure is not recognized as internal or external command. > > So please suggest me what can i do for that, i'm so beginner to python > and installing and configuring modules for apache. The ".\configure" thing is for Linux installations using autotools; it's not going to work on Windows. I don't run Apache on Windows, so I'm just guessing from the documentation here, but the mod_wsgi "Installation on Windows" page says to "follow the instructions for loading mod_wsgi in the Quick Installation Guide." The "Quick Installation Guide" page has instructions for editing the Apache config files. No mention of running ".\configure" -- why are you doing that? Try just editing the config files as the documentation suggests and see if that works. -- Rhodri James *-* Wildebeest Herder to the Masses From ben+python at benfinney.id.au Sun Mar 23 22:31:01 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 24 Mar 2014 13:31:01 +1100 Subject: loop References: Message-ID: <85zjkgqqe2.fsf@benfinney.id.au> pabloeruggeri at gmail.com writes: > I'm trying to create a for loop that starts at 100 and goes to > 10Mllion. The increments are like this: 100, 1000, 10000, ..... > Basicaly adding a zero each iteration. I'm having problems trying to > do it. Can somebody help me Welcome. What have you tried so far? We're not in the practice of just writing the code for you; please show us what you have written that we can try running it, and how it's behaving differently from what you expect. -- \ ?Oh, I love your magazine. My favorite section is ?How To | `\ Increase Your Word Power?. That thing is really, really, | _o__) really... good.? ?Homer, _The Simpsons_ | Ben Finney From rhodri at wildebst.org.uk Sun Mar 23 22:35:45 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Mon, 24 Mar 2014 02:35:45 -0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> Message-ID: On Sun, 23 Mar 2014 02:46:28 -0000, Ian Kelly wrote: > On Sat, Mar 22, 2014 at 6:32 PM, Rhodri James > wrote: >> On Sat, 22 Mar 2014 05:26:26 -0000, Rustom Mody >> wrote: >> >>> Well almost... >>> Except that the 'loop' I am talking of is one of >>> def loop(): >>> return [yield (lambda: x) for x in [1,2,3]] >>> or >>> return (yield (lambda: x) for x in [1,2,3]) >>> or just plain ol >>> (lambda x: for x in [1,2,3]) >>> IOW loop is an imperative construct, comprehensions are declarative >> >> >> I'm sorry, you've made a logical leap too far here. I understand loops >> being imperative, but how are comprehensions declarative? What do they >> declare that the loop equivalent doesn't. > I'm with Rustom on this point. A list comprehension is a syntax for > building a list by declaring a transformation from some other iterable > object. Forget comprehensions for a moment and think of literals. > Would you not consider this to be declarative? > > x = [1, 2, 3] I'm not sure I would. I look at that line of code and think of it as "Create a list...", very much in an imperative manner. Then again, compared with C structs and typedefs and actual honest-to-God type declarations, there's precious little in Python I would consider truly declarative. -- Rhodri James *-* Wildebeest Herder to the Masses From steve+comp.lang.python at pearwood.info Sun Mar 23 22:37:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2014 02:37:32 GMT Subject: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary) References: Message-ID: <532f9a6b$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 23 Mar 2014 12:37:43 +1100, Chris Angelico wrote: > On Sun, Mar 23, 2014 at 12:07 PM, Steven D'Aprano > wrote: >> On Sun, 23 Mar 2014 02:09:20 +1100, Chris Angelico wrote: >> >>> On Sun, Mar 23, 2014 at 1:50 AM, Steven D'Aprano >>> wrote: >>>> Line endings are terminators: they end the line. Whether you consider >>>> the terminator part of the line or not is a matter of opinion (is the >>>> cover of a book part of the book?) but consider this: >>>> >>>> If you say that the end of lines are *not* part of the line, then >>>> that implies that some parts of the file are not inside any line >>>> at all. And that would be just weird. >>> >>> Not so weird IMO. A file is not a concatenation of lines; it is a >>> stream of bytes. >> >> But a *text file* is a concatenation of lines. The "text file" model is >> important enough that nearly all programming languages offer a >> line-based interface to files, and some (Python at least, possibly >> others) make it the default interface so that iterating over the file >> gives you lines rather than bytes -- even in "binary" mode. > > And lines are delimited entities. A text file is a sequence of lines, > separated by certain characters. Are they really separated, or are they terminated? a\nb\n Three lines or two? If you say three, then you consider \n to be a separator; if you say two, you consider it a terminator. The thing is, both points of view are valid. If \n is a terminator, then the above is valid text, but this may not be: a\nb\nc since the last line is unterminated. (You might be generous and allow that every line must be terminated except possibly the last. Or you might be strict and consider the last line to be broken.) In practice, most people swap between one point of view and the other without warning: I might say that "a\nb\n" has two lines terminated with \n, and then an instant later say that the file ends with a blank line, which means it has three lines, not two. Or you might say that "a\nb\n" has three lines separated by \n, and an instant later claim that the last line contains the letter "b". So common language about text files tends to be inconsistent and flip-flop between the two points of view, a bit like the Necker Cube optical illusion. Given that the two points of view are legitimate and useful, how should a programming language treat lines? If the language treats the newline as separator, and strips it, then those who want to treat it as terminator are screwed -- you cannot tell if the last line is terminated or not. But if the language treats the newline as a terminator, and so part of the line, it is easy for the caller to remove it. The decision ought to be a no-brainer: keep the newline in place, let the user strip it if they don't want it. Here's another thought for you: words are separated by spaces. Nobody ever considers the space to be part of the word[1]. I think that nearly everyone agrees that both "spam eggs" and "spam eggs" contain two words, "spam" and "eggs". I don't think anyone would say that the second example includes seven words, five of which are blank. Would we like to say that "spam\n\n\n\n\n\neggs" contains two lines rather than seven? >>> (Both interpretations make sense. I just wish the most obvious form of >>> iteration gave the cleaner/tidier version, or at very least that there >>> be some really obvious way to ask for lines-without-endings.) >> >> There is: call strip('\n') on the line after reading it. Perl and Ruby >> spell it chomp(). Other languages may spell it differently. I don't >> know of any language that automatically strips newlines, probably >> because you can easily strip the newline from the line, but if the >> language did it for you, you cannot reliably reverse it. > > That's not a tidy way to iterate, that's a way to iterate and then do > stuff. Compare: > > for line in f: > # process line with newline > > for line in f: > line = line.strip("\n") > # process line without newline, as long as it doesn't have \r\n or > something With universal newline support, you can completely ignore the difference in platform-specific end-of-line markers. By default, Python will convert them to and from \n when you read or write a text file, and you'll never see any difference. Just program using \n in your source code, and let Python do the right thing. (If you need to handle end of line markers yourself, you can easily disable universal newline support.) f = (line.rstrip('\n') for line in f) for line in f: # process line Everything[1] in computer science can be solved by an additional layer of indirection :-) [...] > So why is the delimiter excluded when you treat the file as CSV, but > included when you treat the file as lines of text? Because reading lines of text is more general than reading CSV records. Therefore it has to make fewer modifications to the raw content. I once had a Pascal compiler that would insert spaces, indentation, even change the case of words. Regardless of what you actually typed, it would pretty-print your code, then write the pretty-printed output when you saved. Likewise, if you read in a Pascal source file from an external editor, then saved it, it would overwrite the original with it's pretty- printed version. That sort of thing may or may not be appropriate for a high-level tool which is allowed to impose whatever structure it likes on its data files, but it would be completely inappropriate for a low-level almost-raw process (more like lightly blanched than cooked) like reading from a text file in Python. >> Reading from a file is considered a low-level operation. Reading >> individual bytes in binary mode is the lowest level; reading lines in >> text mode is the next level, built on top of the lower binary mode. You >> build higher protocols on top of one or the other of that mode, e.g. >> "read a zip file" would be built on top of binary mode, "read a csv >> file" would be built on top of text mode. > > I agree that reading a binary file is the lowest level. Reading a text > file is higher level, but to me "reading a text file" means "reading a > binary file and decoding it into Unicode text", and not "... and > dividing it into lines". Bear in mind that reading a CSV file can be > built on top of a Unicode decode, but not on a line-based iteration (in > case there are newlines inside quotes). Of course you can build a CSV reader on top of line-based iteration. You just need an accumulator inside your parser: if, at the end of the line, you are still inside a quoted field, keep processing over the next line. >> As a low-level protocol, you ought to be able to copy a file without >> changing it by reading it in then writing it out: >> >> for blob in infile: >> outfile.write(blob) >> >> >> ought to work whether you are in text mode or binary mode, so long as >> the infile and outfile are opened in the same mode. If Python were to >> strip newlines, that would no longer be the case. > > All you need is a "writeln" method that re-adds the newline, and then > it's correctly round-tripping, based on what you've already stated about > the file: that it's a series of lines of text. No, that can't work. If the last line of the input file lacks a line terminator, the writeln will add one. Let's make it simple: if your data file consists of only a single line, "spam", the first blob you receive will be "spam". If it consists of "spam\n" instead, the first blob you receive will also be "spam". Should you call write() or writeln()? Whichever you choose, you will get it wrong for some files. > It might not be a > byte-equivalent round-trip if you're changing newline style, any more > than it already won't be for other reasons (file encoding, for > instance). Ignore encodings and newline style. They are irrelevant. So long as the input and output writer use the same settings, the input will be copied unchanged. > By reading the file as a series of Unicode lines, you're > declaring that it contains lines of Unicode text, not arbitrary bytes, > and so a valid representation of those lines of Unicode text is a > faithful reproduction of the file. If you want a byte-for-byte identical > file, open it in binary mode to do the copy; that's what we learn from > FTPing files between Linux and Windows. Both "spam" and "spam\n" are valid Unicode. By striping the newline, you make it impossible to distinguish them on the last line. [1] For some definition of "nobody". Linguists consider that some words contain a space, e.g. "lawn tennis", "science fiction". This is called the open or spaced form of compound words. However, the trailing space at the end of the word is never considered part of the word. [2] Except efficiency. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sun Mar 23 23:17:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 14:17:11 +1100 Subject: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary) In-Reply-To: <532f9a6b$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <532f9a6b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 24, 2014 at 1:37 PM, Steven D'Aprano wrote: > On Sun, 23 Mar 2014 12:37:43 +1100, Chris Angelico wrote: >> And lines are delimited entities. A text file is a sequence of lines, >> separated by certain characters. > > Are they really separated, or are they terminated? > > a\nb\n > > Three lines or two? If you say three, then you consider \n to be a > separator; if you say two, you consider it a terminator. > > The thing is, both points of view are valid. If \n is a terminator, then > the above is valid text, but this may not be: > > a\nb\nc > > since the last line is unterminated. (You might be generous and allow > that every line must be terminated except possibly the last. Or you might > be strict and consider the last line to be broken.) It is a problem, and the correct usage depends on context. I'd normally say that the first consists of two lines, the first being "a" and the second being "b", and there is no third blank line. The first line still doesn't consist of "a\n", though. It's more like how environment variables are provided to a C program: separated by \0 and the last one has to be terminated too. In some situations, you would completely ignore the "c" in the last example. When you're watching a growing log file, buffering might mean that you see half of a line. When you're reading MUD text from a socket, a partial line probably means it's broken across two packets, and the rest of the line is coming. Either way, you don't process the "c" in case it's the beginning of a line; you wait till you see the "\n" separator that says that you now have a complete line. Got some out-of-band indication that there won't be any more (like an EOF signal)? Assume that "c" is the whole line, or assume the file is damaged, and proceed accordingly. > Given that the two points of view are legitimate and useful, how should a > programming language treat lines? If the language treats the newline as > separator, and strips it, then those who want to treat it as terminator > are screwed -- you cannot tell if the last line is terminated or not. That's my point, though. If you want to treat a file as lines, you usually won't care whether the last one is terminated or not. You'll have some means of defining lines, which might mean discarding the last, or whatever it is, but the stream "a\nb\nc" will either become ["a", "b", "c"] or ["a", "b"] or ValueError or something, and that list of lines is really all you care about. Universal newlines, as you mention, means that "a\r\nb\r\n" will become the exact same thing as "a\nb\n", and there's no way to recreate that difference - because it *does not matter*. > Here's another thought for you: words are separated by spaces. Nobody > ever considers the space to be part of the word[1]. I think that nearly > everyone agrees that both "spam eggs" and "spam eggs" contain two > words, "spam" and "eggs". I don't think anyone would say that the second > example includes seven words, five of which are blank. Would we like to > say that "spam\n\n\n\n\n\neggs" contains two lines rather than seven? Ahh, that's a tricky one. For the simple concept of iterating over the lines in a file, I would have to say that it's seven lines, five of which are blank, same as "spam eggs".split(" ") returns a seven-element list. The tricky bit is that the term "word" means "*non-empty* sequence of characters", which means that after splitting on spaces, you discard all empty tokens in the list; but normally "line" does NOT have that non-empty qualifier. However, a double newline often means "paragraph break" as opposed to "line break", so there's additional meaning applied there; that might be four paragraphs, the last one unterminated (and a paragraph might well be terminated by a single newline rather than two), and in some cases might be squished to just two paragraphs because the paragraph itself is required to be non-empty. > With universal newline support, you can completely ignore the difference > in platform-specific end-of-line markers. By default, Python will convert > them to and from \n when you read or write a text file, and you'll never > see any difference. Just program using \n in your source code, and let > Python do the right thing. (If you need to handle end of line markers > yourself, you can easily disable universal newline support.) So why should we have to explicitly disable universal newlines to undo the folding of \r\n and \n down to a single "end of line" indication, but automatically get handling of \n or absence at the end of the file? Surely that's parallel. In each case, you're taking the set of lines as your important content, and folding together distinctions that don't matter. > I once had a Pascal compiler that would insert spaces, indentation, even > change the case of words. Regardless of what you actually typed, it would > pretty-print your code, then write the pretty-printed output when you > saved. Likewise, if you read in a Pascal source file from an external > editor, then saved it, it would overwrite the original with it's pretty- > printed version. That sort of thing may or may not be appropriate for a > high-level tool which is allowed to impose whatever structure it likes on > its data files, but it would be completely inappropriate for a low-level > almost-raw process (more like lightly blanched than cooked) like reading > from a text file in Python. GW-BASIC used to do something similar, always upper-casing keywords like "print" and "goto", and putting exactly one space between the line number and the code; in the file that it stored on the disk, and probably what it stored in memory, those were stored as single tokens. Obviously the process of turning "print" into a one-byte marker and then back into a word is lossy, so the result comes out as "PRINT" regardless of how you typed it. Not quite the same, but it does give a justification for the conversion (hey, it was designed so you could work off floppy disks, so space was important), and of course the program would run just the same. >> I agree that reading a binary file is the lowest level. Reading a text >> file is higher level, but to me "reading a text file" means "reading a >> binary file and decoding it into Unicode text", and not "... and >> dividing it into lines". Bear in mind that reading a CSV file can be >> built on top of a Unicode decode, but not on a line-based iteration (in >> case there are newlines inside quotes). > > Of course you can build a CSV reader on top of line-based iteration. You > just need an accumulator inside your parser: if, at the end of the line, > you are still inside a quoted field, keep processing over the next line. Sure, but that's reaching past the line-based iteration. You can't give it a single line and get back the split version; it has to be a stateful parser that comprehends the whole file. But you can give it Unicode data and have it completely ignore the byte stream that produced it - which you can't do with, say, a zip reader. >> All you need is a "writeln" method that re-adds the newline, and then >> it's correctly round-tripping, based on what you've already stated about >> the file: that it's a series of lines of text. > > No, that can't work. If the last line of the input file lacks a line > terminator, the writeln will add one. Let's make it simple: if your data > file consists of only a single line, "spam", the first blob you receive > will be "spam". If it consists of "spam\n" instead, the first blob you > receive will also be "spam". Should you call write() or writeln()? > Whichever you choose, you will get it wrong for some files. But you'll produce a file full of lines. You might not have something perfectly identical, byte for byte, but it will have the same lines, and the process will be idempotent. >> It might not be a >> byte-equivalent round-trip if you're changing newline style, any more >> than it already won't be for other reasons (file encoding, for >> instance). > > Ignore encodings and newline style. They are irrelevant. So long as the > input and output writer use the same settings, the input will be copied > unchanged. Newline style IS relevant. You're saying that this will copy a file perfectly: out = open("out", "w") for line in open("in"): out.write(line) but it wouldn't if the iteration and write stripped and recreated newlines? Incorrect, because this version will collapse \r\n into \n. It's still a *text file copy*. (And yes, I know about 'with'. Shut up.) It's idempotent, not byte-for-byte perfect. ChrisA From rosuav at gmail.com Sun Mar 23 23:27:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 14:27:32 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> Message-ID: On Mon, Mar 24, 2014 at 1:35 PM, Rhodri James wrote: >> Would you not consider this to be declarative? >> >> x = [1, 2, 3] > > > I'm not sure I would. I look at that line of code and think of it as > "Create a list...", very much in an imperative manner. Then again, compared > with C structs and typedefs and actual honest-to-God type declarations, > there's precious little in Python I would consider truly declarative. I'm in the declarative group here. Yes, it has to be implemented as creating a list and adding three elements to it, but conceptually, it means "Bind x to a new list with these elements". And as long as that's the end result, I don't care how it's done; the interpreter's most welcome to have a "template list" that it copies, or maybe a literal tuple that gets passed to the list() constructor, or whatever's most efficient. It gets a bit messier when there's stuff with side effects, though. This has to be a bit more imperative: x = [foo(y), bar(y), quux(y)] That means "Call foo, bar, and quux, in that order, each with y as an argument, and bind x to a new list with their return values". And if Python had a simple notation for calling a series of functions, that could be written something like this: funcs = [foo, bar, quux] x = funcs(y) which is looking more declarative again. It's now "Take this list of functions and call them all, and bind x to a list of their return values". (This could be done, with a callable subclass of list. Call it a sort of "implicit map" if you like.) Python doesn't have that syntax, but it does have this: x = [f(y) for f in funcs] and I'd say that's reasonably declarative; it should be read like the previous one: "Take this list of funcs, call each one, and bind x to a list of their return values". And I could imagine a parallel-processing version of a list comp that functions like multiprocessing.Pool.map() and doesn't promise order, which would *definitely* be declarative. ChrisA From harrismh777 at gmail.com Sun Mar 23 23:28:38 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 23 Mar 2014 22:28:38 -0500 Subject: python installation on windows References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> <73a660da-9dd8-4104-ae9c-ba1788ae1d60@googlegroups.com> Message-ID: On 3/23/14 4:07 PM, tad na wrote: >> On Sunday, March 23, 2014 12:33:02 PM UTC-5, tad na wrote: >> To set up a web browser: >> 1.open a dos window >> 2.navigate to dir you want "served" >> 3.type "python -m SimpleHTTPServer 8888&." >> 4. open browser and type http://localhost:8888/ That is very ~cool. I learn something around here everyday. But, the OP did not ask how to run a web server on python (above); he asked how to run python on a web browser (I think he meant web server). Anyway, the PSF runs python (the interpreter) from a web server (I can access the python interpreter from my browser from the PSF site). How is that done simply, is possibly what the OP wants to know (me too). marcus From rosuav at gmail.com Sun Mar 23 23:32:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 14:32:13 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> Message-ID: On Mon, Mar 24, 2014 at 1:35 PM, Rhodri James wrote: > I'm not sure I would. I look at that line of code and think of it as > "Create a list...", very much in an imperative manner. Then again, compared > with C structs and typedefs and actual honest-to-God type declarations, > there's precious little in Python I would consider truly declarative. By the way: Python does have a difference between "declarative" and "imperative". def f(): # Imperative global x # Declarative x += 1 # Imperative Declaratives control things, imperatives become byte code. Everything in the byte code is imperative. "LOAD_GLOBAL" means "fetch this global and put it on the stack". "INPLACE_ADD" means "iadd the top two stack elements and push the result onto the stack". "STORE_GLOBAL" means "pop the top stack element and store it in this global". Very very imperative, and there's none of that created by the "global" statement. So in that sense, yes, "x = [1, 2, 3]" is imperative; it loads three constants, builds a list, and stores it. But digging into the byte code isn't really helpful; it's much more useful to look at the source code and how the programmer thinks about it. ChrisA From harrismh777 at gmail.com Sun Mar 23 23:30:54 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 23 Mar 2014 22:30:54 -0500 Subject: loop References: <05924f21-0162-4d4c-84d0-016c7fdfeee1@googlegroups.com> Message-ID: On 3/23/14 7:59 PM, anton wrote: > for i in (10**p for p in range(3, 8)): > print(i) Never do their home-work for them; but, in this case, what the heck. :) From rosuav at gmail.com Sun Mar 23 23:35:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 14:35:19 +1100 Subject: python installation on windows In-Reply-To: References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> <73a660da-9dd8-4104-ae9c-ba1788ae1d60@googlegroups.com> Message-ID: On Mon, Mar 24, 2014 at 2:28 PM, Mark H Harris wrote: > Anyway, the PSF runs python (the interpreter) from a web server (I can > access the python interpreter from my browser from the PSF site). > > How is that done simply, is possibly what the OP wants to know (me too). That's a much MUCH harder thing to do than running Python code in your web server, because of trust issues. I don't know how it's set up, but there'll be something in there to protect the server against malicious or accidental insanity (spinning with "while True: pass", trying to read/write files, trying to execute commands, using up all of RAM with "x = []\nwhile True: x.append(1)", etc, etc, etc). That's actually a very hard problem to solve, not something where you can just say "Here, this is how to run Python via a browser". ChrisA From harrismh777 at gmail.com Sun Mar 23 23:48:49 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 23 Mar 2014 22:48:49 -0500 Subject: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary) References: <532f9a6b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/23/14 10:17 PM, Chris Angelico wrote: > Newline style IS relevant. You're saying that this will copy a file perfectly: > > out = open("out", "w") > for line in open("in"): > out.write(line) > > but it wouldn't if the iteration and write stripped and recreated > newlines? Incorrect, because this version will collapse \r\n into \n. > It's still a *text file copy*. (And yes, I know about 'with'. Shut > up.) It's idempotent, not byte-for-byte perfect. Which was my point in the first place about new-line standards. We all know why its important to collapse \r\n into \n, but why(?) in a general way would this be the universal desired end? (rhetorical) Your example of byte-for-byte perfect copy is one good case (they are not). Another might be controller code (maybe ancient) where the \r is 'required' and collapsing it to \n won't work on the device (tty, or other). There does need to be a text file standard where what is desired is a file of "lines". Iterating over the file object should return the "lines" on any system platform, without the user being required to strip off the line-end (newline \n) delimiter U+000a. The delimiter does not matter. What python has done by collapsing the \r\n into \n is to hide the real problem (non standard delimiters between platforms) and in the process actually 'removes' possibly important information (\r). {lossy} We don't really use real tty devices any longer which require one code to bring the print head carriage back (\r) and one code to index the paper platten (\n). Screen I/O doesn't work that way any longer either. Its time to standardize the newline and/or file text line end delimiters. marcus From rustompmody at gmail.com Mon Mar 24 00:14:20 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 23 Mar 2014 21:14:20 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> Message-ID: <8a786235-3030-483c-8153-b3b420510782@googlegroups.com> On Monday, March 24, 2014 8:57:32 AM UTC+5:30, Chris Angelico wrote: > On Mon, Mar 24, 2014 at 1:35 PM, Rhodri James wrote: > >> Would you not consider this to be declarative? > >> x = [1, 2, 3] > > I'm not sure I would. I look at that line of code and think of it as > > "Create a list...", very much in an imperative manner. Then again, compared > > with C structs and typedefs and actual honest-to-God type declarations, > > there's precious little in Python I would consider truly declarative. > I'm in the declarative group here. Yes, it has to be implemented as > creating a list and adding three elements to it, but conceptually, it > means "Bind x to a new list with these elements". And as long as > that's the end result, I don't care how it's done; the interpreter's > most welcome to have a "template list" that it copies, or maybe a > literal tuple that gets passed to the list() constructor, or > whatever's most efficient. > It gets a bit messier when there's stuff with side effects, though. > This has to be a bit more imperative: > x = [foo(y), bar(y), quux(y)] > That means "Call foo, bar, and quux, in that order, each with y as an > argument, and bind x to a new list with their return values". And if > Python had a simple notation for calling a series of functions, that > could be written something like this: > funcs = [foo, bar, quux] > x = funcs(y) > which is looking more declarative again. It's now "Take this list of > functions and call them all, and bind x to a list of their return > values". (This could be done, with a callable subclass of list. Call > it a sort of "implicit map" if you like.) Python doesn't have that > syntax, but it does have this: > x = [f(y) for f in funcs] > and I'd say that's reasonably declarative; it should be read like the > previous one: "Take this list of funcs, call each one, and bind x to a > list of their return values". And I could imagine a > parallel-processing version of a list comp that functions like > multiprocessing.Pool.map() and doesn't promise order, which would > *definitely* be declarative. You have described nicely a slippery slope! The list [(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1), (3, 2), (3, 3), (3, 4)] looks neater written (and *thought of* ) as [(x,y) for x in range(1,4) for y in range(1,5)] Neat! So I play around... Change it to [(x,y) for x in range(1,10000) for y in range(1,10000)] and I dont have an answer but a thrashing machine!! (*) IOW everything we write/read as programmers has a declarative and an imperative side. Which one one wants to focus on requires good sense and taste. (*) Example also shows inter alia how some things -- range -- have gone from imperative to declarative from python 2 to 3. Some people have made languages whose main focus is generalizing this idea to more dimensions and restrictions: http://www.irisa.fr/cosi/Rajopadhye/dag-talk.ps From tjreedy at udel.edu Mon Mar 24 00:55:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 24 Mar 2014 00:55:04 -0400 Subject: Question about Source Control In-Reply-To: References: <532dc915$0$24914$e4fe514c@dreader36.news.xs4all.nl> <20140322134917.080bada6@bigbox.christie.dr> <1395518482.78665.YahooMailNeo@web163804.mail.gq1.yahoo.com> <1395586700.55921.YahooMailNeo@web163806.mail.gq1.yahoo.com> Message-ID: On 3/23/2014 10:04 PM, Chris Angelico wrote: > On Mon, Mar 24, 2014 at 12:26 PM, Terry Reedy wrote: >> With multiple branches (as with 2.7, 3.4, and default for cpython) and >> multiple active developers (20?) commiting to those brances, commits are >> definitely not free. I would not exactly call them as cheap as you seem to >> imply either. That said, I have occasionally pushed interim changes that put >> code in an improved and stable state. >> >> N. Coughlan has suggested improving the cpython infrastructure and >> procedures to reduce the cost of commits to encourage more people to make >> more commits (in the sense of more lines changed, not more pieces) and >> improve cpython faster. > > When I call them cheap, what I mean is that there's little difference > between a single commit and 2-3 commits as a group. Yes, there's a bit > more difference when you're cherry-picking them to other branches, and > maybe an infrastructure/procedure change could help with that; but > once they're there in history, it doesn't hurt to have three separate > commits doing related work, keeping the distinct parts distinct. Every commit to a 3.x maintenance branch (now 3.4) must be forward merged into the 3.(x+1) default (now the future 3.5), even if it is just a null merge. The point of this policy is to keep the repository in a coherent state. If a bug were fixed in maintenance but not default, it would create a regression situation, the same as if it were fixed in default and then broken again by a separate patch. Part of the planned (hoped-for) change (using a system that is already working for another project with even more code and committers) is to automatically test patches on the buildbots before they are committed to the central repository, rather than after. Each would be tested and accepted or rejected separately. So each commit would have to stand on its own even more than now. -- Terry Jan Reedy From rosuav at gmail.com Mon Mar 24 01:04:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 16:04:51 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <8a786235-3030-483c-8153-b3b420510782@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> <8a786235-3030-483c-8153-b3b420510782@googlegroups.com> Message-ID: On Mon, Mar 24, 2014 at 3:14 PM, Rustom Mody wrote: > Neat! So I play around... Change it to > [(x,y) for x in range(1,10000) for y in range(1,10000)] > and I dont have an answer but a thrashing machine!! (*) Yes, because you used square brackets, which means that the list has to be fully realized. As you comment, range changed from returning a list to returning an iterable, and this action is similarly cheap: >>> ((x,y) for x in range(1,10000) for y in range(1,10000)) at 0x7f53ed61b360> You can take a few elements from that cheaply: >>> [next(_),next(_),next(_)] [(1, 1), (1, 2), (1, 3)] If you like thinking in "lazy lists", you can probably think just as easily with generators; you can't pull up arbitrary elements from it, or query its length, but for many purposes a generator will do. ChrisA From harrismh777 at gmail.com Mon Mar 24 01:52:52 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 00:52:52 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/22/14 4:46 AM, Steven D'Aprano wrote: > On Fri, 21 Mar 2014 23:51:38 -0500, Mark H Harris wrote: > >> Lambda is a problem, if only because it causes confusion. What's the >> problem? Glad you asked. The constructs DO NOT work the way most people >> would expect them to, having limited knowledge of python! One of the best links for understanding what is wrong with lambda is here, from Guido, (by the way I agree totally with his assessment, there is no point really in writing it out again): http://www.artima.com/weblogs/viewpost.jsp?thread=98196 > Why is that a problem? Would you consider it a problem that people who > don't understand BASIC can't understand BASIC? ("I don't get the > difference between GOTO and GOSUB. {snip} > > The problem is ignorance, not the calculator, and not lambda. You're argument, based on analogy, is also a red herring, as well a straw man. Lambda is a problem of confusion for scientists and other mathematicians (amateur and otherwise) who may be confused because python's lambda does not do precisely what they might expect from other functional programming languages, nor does it match precisely with the lambda calculus. Its also confusing to sophisticated users of all stripes who may not be aware of "lambda" at all. > You've told us that "most people" (which people? dentists? lawyers? > illiterate tribesmen from the Amazon? professional programmers?) are > surprised by lamba's behaviour, but you haven't actually told us what > behaviour is surprising, or what "most people" expect lambda to do. > Perhaps you ought to? I love your rhetoric, actually, but red herrings all . . . Here is a link that advocates lambda (map, filter, and reduce) as a very powerful construct for doing various things: I agree: http://www.secnetix.de/olli/Python/lambda_functions.hawk Its a great link, but the important sentence for this discussion is this unique quote, about "lambda," >"This is not exactly the same as lambda in functional > programming languages, but it is a very powerful concept . . ." People who understand lambda from functional languages must hassle with the fact that lambda is different in python, and people who do not understand functional programming languages (nor the lambda calculus) are confused by the syntax, also just what it does. > Python is not a pure functional language, but you can write functional > code in it. If you want a pure functional language, you know where to > find one. Yes, that's obvious; but you're missing the point. Python is not a functional language, and implying that it can be used as one is misleading at best (maybe a lie at worst) just because it has a construct for generating a dynamic anonymous function. > (I wonder whether, say, Haskell has the people coming along and demanding > that it should become more like Python?) Another straw man. Well, number one, I'm not demanding anything. Number two, everyone who uses Haskell (for whatever reason) knows well from the start that its a pure functional programming language. That is the advertisement, and that is the expectation. No one expects anything different. >> I can see uses for python's lambda. But, honestly, I think python could >> deprecate its use and in five years just remove it from the language; >> along with filter, map, and reduce ! > > Python could deprecate many things. It would make Python a worse language. How so? Read Guido's argument above. Another way to answer this question is that I have been programming with Python for almost a decade and I've not used lambda. In fact, I have gone out of my way to NOT use lambda because I am fully aware that the BDFL hates it. Reduce is no longer in the standard library (although you can import it) and there are equally good ways to do what lambda was designed for without the hassle nor confusion. > By the way, are you aware that lambda is *identical* to def except for > three things? > > - lambda is an expression, not a statement like def; > > - the body of a function created with lambda is limited to a > single expression, not a block; > > - the function object created with lambda has a generic name. Absolutely, thank you for pointing those out ! You forgot that lambdas can be used in expressions while def functions may not... but you really have proved my point. There is so little difference between the two that (for the sake of clarity and reducing confusion) it might be good to just remove the lambda thing altogether. Just say'in. > So unless the surprising behaviour about lambda that you're about to tell > us about relates to one of those three things, I *guarantee* that > functions created with def have the same surprising behaviour. No, the surprising behavior is that python lambda does not work exactly the way that lambda works in functional programming languages (see the two links provided) the confusion it creates for "normal" users does not warrant its inclusion in the language. Having said that, I must admit that I've "played" with lambda extensively and find it interesting from a comp sci standpoint, but, again, for normal users I don't think there is a really good value add for having it in the language. From lepto.python at gmail.com Mon Mar 24 01:56:51 2014 From: lepto.python at gmail.com (oyster) Date: Mon, 24 Mar 2014 13:56:51 +0800 Subject: how? Py extension does not depend on py version Message-ID: I found an extension on this blog http://www.cnblogs.com/DxSoft/archive/2011/04/08/2009132.html or you can download the extension directly from http://files.cnblogs.com/DxSoft/PyFetion.rar I found that I can do "from DxVcl import *" in py 2.5/2.6/2.7. When I try this in py24, a msgbox says "no python25.dll is found". However "Dependency Walker" shows that DxVcl does not has the python??.dll dependency. Is this a dark side of python which is not in official python doc? So, to the end, My question is: how can I write such an extension(i.e. not DLL foe ctypes) in C/C++? Thanks Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: From solutions.for.student at gmail.com Mon Mar 24 02:06:03 2014 From: solutions.for.student at gmail.com (solutions.for.student at gmail.com) Date: Sun, 23 Mar 2014 23:06:03 -0700 (PDT) Subject: solutions manual and test bank Message-ID: solutions(dot)for(dot)student(at)hotmail.com s o l u t i o n s . f o r . s t u d e n t @ h o t m a i l . c o m We're a team found for providing solution manuals to help students in their study. We sell the books in a soft copy, PDF format. We will do our best to find any book or solution manual for you. Before purchase, we will give you a full details and sample of solution manual you want Just email us: s o l u t i o n s . f o r . s t u d e n t @ h o t m a i l . c o m List of some books we have ============================= A Course in Modern Mathematical Physics by Peter Szekeres A First Course in Abstract Algebra By John B. Fraleigh A First Course in Differential Equations with Modeling Applications , 9th ed 2008 , by Zill A First Course In Probability , 7th ed , by sheldon ross A first course in probability 6th edition by Ross A First Course in Probability, 5th ed , by Sheldon Ross & Prentice Hall & scanned A First Course in String Theory by Barton Zwiebach A Modern Theory of Integration , by Robert G.Bartle A Practical Introduction to Data Structures and Algorithm Analysis Second Edition by Clifford A. Shaffer A Quantum Approach to Condensed Matter Physics by Philip L. Taylor A Short Introduction to Quantum Information and Quantum Computation by Michel Le Bellac Accompany Digital Systems Principles and Applications, 10th Edition By Ronald J. Tocci, Neal S. Widmer, Gregory L. Moss Accompany Electric Machinery and Power System Fundamentals, First Edition by Stephen J. Chapman Accompany Electronic Devices and Circuit Theory, 8Ed By Robert L. Boylestad; Louis Nashelsky; Franz J. Monseen Accompany Elementary Statistics Ninth Edition by MILTON LOYER Accompany Engineering circuit analysis, 6th edition By Hayt Accompany Foundations of Electromagnetic Theory 2nd Ed. by John R. Reitz, Frederick J. Milford Accompany Fundamentals of Fluid Mechanics, 5th Edition by Bruce R. Munson, Donald F. Young, Theodore H. Okiishi Accompany Introduction to algorithms By Sussman J Accompany Millman micro Electronics Digital and Analog Circuits and Systems , by Thomas V. Papathomas Accompany Physics for Poets Second Edition By Robert H. March Accompany Principles of geotechnical engineering, sixth edition by braja M. DAS Accompany Problem Solving and Programming Concepts , 9th ed , by Maureen Sprankle , Jim Hubbard Adaptive Control, 2nd Edition, By Karl Johan Astrom,Bjorn Wittenmark Adaptive filter thoery 4th edition By Simon Haykin Advanced Accounting Guerrero Vol. 1 & 2 , REVISED EDITION 2008 , by P.P. GUERRERO & J.F. PERALTA Advanced Digital Design with the Verilog HDL by Michael D. Ciletti (Selected problems) Advanced engineering electromagnetics by Constantine A. Balanis Advanced Engineering Mathematics , 8 ed , by Erwin Kreyszig Advanced Engineering Mathematics 8 Edition By Erwin Kreyszig Advanced Engineering Mathematics 9 Edition By Erwin Kreyszig Advanced Macroeconomics , 1996 edition , by Romer David Advanced Modern Engineering Mathematics , 4th ed 2011 , by Glyn James Advanced Modern Engineering Mathematics 3rd Edition by Glyn James Agamata Management Advisory Services , 2007 edition , by Franklin T. Agamata, MBA, CPA Aircraft Structures for Engineering Students Fourth Edition by T. H. G. Megson (2007) Algebra and Trigonometry and Precalculus, 3rd Edition by Penna & Bittinger Beecher an introduction to database systems , 8th ed , by c. j. date An introduction to database systems 8th edition By C J Date An Introduction to Mathematical Statistics and Its Applications , 4th ed , by richard J. Larsen & morris L. Marx An Introduction to Ordinary Differential Equations By James C. Robinson (with Matlab files) An Introduction to Signals and Noise in Electrical Communication , 4th ed , by A. Bruce Carlson & Paul B. Crilly & Janet C. Rutledge An Introduction to Signals and Systems By John Stuller An Introduction to The Finite Element Method (Third Edition) By J. N. REDDY Analysis and design of analog integrated circuits 4th edition by Srikanth Vaidianathan and Haoyuee Wang Analytical Mechanics, 7th Edition By Fowles & Cassiday Antenna Theory Analysis and Design, 2nd Edition Balanis Antennas for all Applications 3rd edition by John D. Kraus & Ronald J. Marhefka Anton Calculus 8th edition, Exercises solutions Applied Linear Statistical Models , 5th ed , by Applied Linear Statistical & Applied Linear Statistical & Applied Linear Statistical & Applied Linear Statistical Applied Numerical Analysis 7th Edition By Curtis F. Gerald,Patrick O. Wheatley Applied Numerical Methods with Matlab for engieers and Scientists , by Steven C. Chapra Applied Partial Differential Equations with Fourier Series and Boundary Value Problems 4th Edition by Richard Haberman Applied Quantum Mechanics by A. F. J. Levi Applied Statistics and Probability for Engineers , 2003 edition , by Douglas C. Montgomery, George C. Runger Applied Statistics And Probability For Engineers 3rd edition By Montgomery,Runger Applied Statistics And Probability For Engineers 4th edition By Montgomery,Runger Applied Strength of Materials 4th Edition By Robert L. Mott Artificial Intelligence A ModernApproach 2nd edition by StuartJ. Russelland, Peter Norvig Assembly Language for Intel-Based Computers,3ed, by Kip R. Irvine Atkins' Physical Chemistry , 7th ed 2001 , by Peter Atkins & Julio de Paula , (Oxford University Press) Atkins Physical Chemistry , 8th ed , by PETER ATKINS & CHARLES TRAPP & CARMEN GIUNTA & MARSHALL CADY Auditing Theory 2009 Edition By Jekell G. Salosagcol Michael F. Tiu Roel E. Hermosilla Automatic Control Systems 8th edition By Kuo and Golnaraghi Basic Econometrics 4th edition by Damodar N. Gujarati Basic Electrical Engineering By Nagrath, D P Kothari, Nagrath D P Kothari I J Nagrath, I J Nagrath, 2002 Basic Engineering Circuit Analysis 7th Ed. by J. David Irwin (Selected Problems) Basic Engineering Circuit Analysis 8th Edition By J. David Irwin BOEING DESIGN MANUALInelastic Buckling Equations and Solutions C++ for Computer Science and Engineering , 4 th ed 2006 , by Vic Broquard C++ How to Program, 3rd Ed by Harvey M. Deitel, Paul J. Deitel C++ How to Program, 3rd edition By Deitel & Nieto CALCULUS , 3rd ed, 2007 ,by SMITH Calculus 5th Edition By James Stewart Calculus 8th Ed by Larson, Hostetler, Edwards Calculus A Complete Course 6th Edition by R.A. Adams Calculus an intuitive and physical approach , 2 nd ed , by Morris Kline Calculus Early Trancendental , 6th ed , by Edwards Penney Calculus Early Transcendentals 5th Edition By Stewart Calculus early transcendentals 7th edition By Anton Bivens Davis calculus multivariable 4th edition Deborah Hughes-Hallett, Andrew M. Gleason, et al Calculus Single Variable Hughes-Hallett, Gleason, McCallum, et al Chemical and Engineering Thermodynamics 3rd Ed. by Stanley I. Sandler Chemical Enginering Vol 6 4th edition by Coulson and Richardson Chemical Principles The Quest For Insight , 4th ed , by Atkins and Jones Chemical Reaction Engineering 3rd Edition By Octave Levenspiel Classical Dynamics A Contemporary Approach by Jorge V. Jose, Eugene J. Saletan Classical Dynamics of Particles and Systems 5th edition by Stephen T. Thornton, Jerry B. Marion Classical Electrodynamics 2nd Edition by John David Jackson by Kasper van Wijk Classical Mechanics - An Undergraduate Text by R. Douglas Gregory Classical Mechanics 2nd edition By Goldstein & Safko CMOS Digital Integrated Circuits 3rd edition By Sung-Mo Kang,Yusuf Leblebici CMOS VLSI Design 3e by ananymous Communication Networks Fundamental Concepts and Key Architectures Alberto Leon-Garcia Communication Systems 4th ed by bruce carlson Communication Systems 4th edition by Simon Haykin Communication Systems Engineering - Second Edition John G. Proakis Masoud Salehi Computational Techniques for Fluid Dynamics (Scientific Computation) by Karkenahalli Srinivas, Clive A. J. Fletcher Computer Networking A Top-Down Approach 3rd Edition by James F.Kurose,Keith W. Ross Computer Networks - 4th Edition by Andrew S. Tanenbaum Computer Networks A Systems Approach 2nd edition by Peterson and Davie Computer Organization 5th edition by Hamacher,Vranesic and Zaky Computer Organization And Architecture , 8th ed , by William Stallings Computer Organization and Design , 4 th ed Computer Organization and Design The HardwareSoftware Interface, 3rd edition by David A. Patterson, John L. Hennessy, Computer System Architecture 3rd edition by Morris Mano Computer-Controlled Systems 3rd edition by Karl J. Astrom Concepts of Programming Languages 7th edition Solutions Manual by Robert Sebesta Contemporary Linear Algebra by Howard Anton Robert C. Busby Continuous and Discrete Signals and Systems, 2nd ed , By Samir S. Soliman and Mandyam D. Srinath Control systems Principles and Design 2nd Edition by Madan Gopal Control Systems Engineering 4th edition by Norman S. Nise Corporate Finance solution manual 6th Edition by Ross Craig's Soil Mechanics 7th Edition Cryptography and network security-principles and practice 4th ed. By William Stallings Data and computer communications 7th edition William Stallings Data Communications and Networking 4th edition by Behroz Forouzan Database Management Systems 3rd edition Raghu Ramakrishnan Johannes Gehrke Design And Analysis Of Experiments ,5 th edition 2001 , by Douglas C Montgomery Design of Analog CMOS Integrated Circuits Behzad Razavi Design of Machine Elements , Spotts Design of Nonlinear Control Systems with the Highest Derivative in Feedback 1st Edition by Valery D. Yurkevich [student solution manual] Design with Operational Amplifiers and Analog Integrated Circuits, 3rd edition by Franco, Sergio Device Electronics for Integrated Circuits 3rd edition by Muller Kamins Differential Equations with Boundary Value Problems 2nd Edition by JOHNPOLKING and DAVID ARNOLD Differential Equations with Boundary Value Problems, 2nd edition by John Polking Digital and Analog Communication Systems 7th Edition by Leon W. Couch Digital Communication 4th edition by Proakis Digital Communications 5th edition by John Proakis Digital Communications Fundamentals and Applications, 2nd Edition by Bernard sklar Digital Control and state variable methods - M.Gopal Digital Design 2nd Edition by M. Morris Mano,Michael D. Ciletti Digital Design 3rd Edition by M. Morris Mano,Michael D. Ciletti Digital Design 4th edition Morris Mano Digital Design-Principles and Practices 3rd Edition by John F. Wakerly [selected problems] Digital Fundamentals 9th edition by Thomas L. Floyd Digital Image Processing 2nd edition by Rafael C. Gonzalez Digital Integrated Circuits 2nd edition by Rabaey Digital Integrated Circuits by Thomas A. DeMassa & Zack Ciccone Digital Logic And Computer Design , 4th ed , by M.Morris Mano & MICHAEL D. CILETTI Digital Logic Design 2nd edition by M. Morris Mano Digital Signal Processing - A Modern Introduction, 1st Edition Cengage learning Ashok Ambardar Digital Signal Processing ; A Computer-Based Approach 1st edition By sanjit K. Mitra Digital Signal Processing 2nd Edition by Mitra Digital Signal Processing 3nd Edition by Mitra Digital Signal Processing 4th edition by John G. Proakis and Dimitri s G. Manolakis Digital Signal Processing A Computer-Based Approach , 2nd ed , by Sanjit Mitra Digital Signal Processing by Thomas J. Cavicchi Digital signal processing proakis manolakis Digital Signal Processing Signals, Systems, and Filters Andreas Antoniou Digital Signal Processing Using Matlab 2nd edition by Vinay K Ingle Proakis Digital Systems-Principles and Applications 10th Ed. by Ronald Tocci, Neal S. Widmer & Gregory L. Moss Discrete Mathematics with Applications Third Edition By Susanna S. Epp Discrete Mathematics, 6th ed , by richard Johnsonbaugh Discrete Time Digital Signal Processing , 2nd ed 1999 , by Prentice Hall Discrete Time Signal Processing 2nd Edition, by Alan V. Oppenheim Discrete time signal processing 3rd edition by Oppenheim Econometric Analysis , 5 th ed 2001 , by William H. Greene Econometric Analysis of Cross Section and Panel Data , 2003 , by Wooldridge Econometrics , 2nd ed , by Badi H. Baltagi Economics Advanced Macroeconomics , 3 rd edition 2006 , by Romer McGraw Hill Electric Circuits 7th edition by Nilsson Electric Circuits 8th edition by Nilsson Electric circuits 9th Edition By Nilsson Riedel Electric Machinery 6th Edition by Fitzgerald Kingsley Electric Machinery and Power System Fundamentals 1st edition by Stephen Chapman Electric Machinery Fundamentals , by Stephen J. Chapman Electric Machinery Fundamentals 4th edition by Stephen J. Chapman Electric Machines Analysis and Design Applying MATLAB by Jim Cathey Electrical Engineering Electric Machinery , 6th ed Fitzgerald & Kingsley & Uman Electrical Engineering Principles and Applications 3rd edition by Allan R. Hambley Electrical Machines, Drives and Power Systems 6th edition By Theodore Wildi Electromagnetic Fields and Energy 1st Ed. by Haus and Melcher Electromagnetics for Engineers by Ulaby Electromagnetism Major American Universities Ph.D. Qualifying Questions and Solutions by Lim Yung-Kuo Electromechanical Dynamics I , by Herbert H. Woodson & James R. Melcher Electronic Circuit Analysis and Design 2nd edition by Donald A. Neamen Electronic devices - electron flow version 4th edition by thomas l.floyd Electronic Devices and Circuit Theory , 10 th ed , by Robert L. Boylestad & Louis Nashelsky Electronic Devices and Circuit Theory 8th Ed. with Lab Solutions, and Test Item File by Robert Boylestad Electronic Devices-6th Edition by Thomas L. Floyd Electronic Physics by Strabman Elementary Differential Equations , 8th ed , by Werner Kohler & Lee Johnson Elementary Differential Equations 8th edition by Boyce Elementary Differential Equations And Boundary Value Problems, 7Th Edition by Boyce And Diprima Elementary Differential Equations with Boundary Value Problems , 4th ed , by C.H. Edwards & David E. Penney Elementary Linear Algebra With Applications , 10 th ed , by Anton Elementary Linear Algebra with Applications 9th by Howard Anton, Chris Rorres Elementary Mechanics and Thermodynamics by Jhon W. Norbury Elementary Number Theory and Its Applications, 5th edition by Kenneth H. Rosen Elementary Number Theory and Its Applications, 6th Ed. By Kenneth H. Rosen Elementary Principles of Chemical Processes 3rd edition by Richard M. Felder,Ronald W. Rousseau Elements of Chemical Reaction Engineering 4th Edition by Brian Vicente, Max Nori, H. Scott Fogler Elements of Chemical Reaction Engineering, 3rd Edition by H. Scott Fogler Elements of electromagnetics 2nd edition by sadiku Elements of electromagnetics 3rd edition by sadiku Elements Of Information Theory , 1992 ,By Thomas Cover, Joy A. Thomas Elements of Power System Analysis 4th edition by William D. Stevenson Embedded Microcomputer Systems Real Time Interfacing 2nd Edition by Jonathan W. Valvano Engineering Circuit Analysis 6th edition by Hayt Engineering Circuit Analysis 7th edition by Hayt Engineering Economy 7th Edition Solution Manual By Leland Blank and Anthony Tarquin Engineering Electromagnetics - 7th Ed. - Hayt Engineering Electromagnetics 2d Edition by Nathan Ida Engineering Electromagnetics 6th Edition by William H. Hayt Jr. and Hohn A. Buck Engineering Fluid Mechanics , 8th Ed , by Donald Elger & Clayton Crowe Engineering Fluid Mechanics 7th edition by Clayton T. Crowe, Donald F. Elger & John A. Roberson Engineering Fundamentals of Machine Component Design , 3rd ed , by Juvinall & Marshek Engineering Mathematics 4th edition by John Bird Engineering Mathematics 4th Edition by NEWNES Engineering Mechanic STATICS 10th Ed. R.C. Hibbeler Engineering Mechanics - Dynamics 2 Edition by Riley and Sturges Engineering Mechanics - Dynamics 11th edition by R. C. Hibbeler Engineering Mechanics - STATICS 4th E - Bedford and Fowler Engineering mechanics - statics 10th edition by R. C. Hibbeler Engineering mechanics Dynamics 4th Ed. by Bedford and Fowler Engineering Mechanics Dynamics 5th J.L Meriam Engineering Mechanics Dynamics, 6th ed, by J. L. MERIAM Engineering Mechanics Statics , 5th ed , by Anthony Bedford & Wallace T. Fowler Engineering Mechanics Statics 6th edition by J.L Meriam Engineering Mechanics Statics 11th Edition By R.C.Hibbeler Engineering Statistics , 4 th ed , by Douglas C. Montgomery & George C. Runger & Norma F. Hubele engineering vibration , 3rd ed , by daniel j inman Feedback Control of Dynamic Systems 4th edition by G. F. Franklin, J. D. Powell, A. Emami Feedback control of dynamic systems 6th edition by G. F. Franklin, J. D. Powell, A. Emami Field and Wave Electromagnetics 2nd Edition by Wesley Cheng Field and Wave Electromagnetics International Edition by David K Financial Accounting (V.1 & V.2 & V.3) , 2008 edition , by Valix and Peralta Financial Accounting , by Libby & Short Fluid Mechanics 1st edition by CENGEL Fluid Mechanics 5th Edition by White Fluid Mechanics With Engineering Applications 10th edition by E. John Finnemore, Joseph B Franzini Fracture mechanics fundamentals and applications 2nd edition by Northam Anderson Fundamental Methods of Mathematical Economics , 4 th ed , by Alph C. chaing & Kevin wainwright Fundamental of Electric Circuits 3rd editoin by C. K. Alexander M. N. O. Sadiku Fundamental of engineering electromagnetics by David Cheng Fundamental of Financial Management , 12 ed , by James C. Van Horne & John M. Wachowicz JR Fundamentals of aerodynamics , 2nd ed , by John D. Anderson Jr Fundamentals of Digital Logic with Verilog Design 1st edition by S. Brown Z. Vranesic Fundamentals of Digital Logic with VHDL Design, 1st edt. by S. Brown, Z. Vranesic Fundamentals of Digital Signal Processing Using MATLAB , 2nd ed 2012 , by Robert A. Schilling & Cengage Learning Fundamentals of Electric Circuits 2nd edition by C. K. Alexander M. N. O. Sadiku Fundamentals of Electric Circuits, 3rd edition by C. K. Alexander M. N. O. Sadiku Fundamentals of Engineering Economics , 2nd ed , by Park Fundamentals of engineering thermodynamics by m. j. moran h. n. shapiro Fundamentals Of Fluid Mechanics , 6th ed , by Munson Fundamentals of Fluid Mechanics , 6th ed 2009 , by Munson Fundamentals of Fluid mechanics 4th edition by Munson Fundamentals of Fluid Mechanics Student Solutions Manual, 3rd Edition [Student solution manual] Fundamentals of Heat and Mass Transfer 4th edition by Incropera & Dewitt Fundamentals of logic design 5th edition by Charles Roth Fundamentals of Machine Component Design - 3rd edition by Robert C. Juvinall and Kurt M. Marshek Fundamentals of Machine Component Design 4th edition by Robert C. Juvinall, Kurt M. Marshek Fundamentals of Physics 7th edition by Halliday, Resnick and Walker Fundamentals of physics 8th edition by Halliday, Resnick and Walker Fundamentals of Physics extended , 9 th ed , by Halliday & resnick Fundamentals of Power Electronics 2nd edition by R.W. Erickson Fundamentals of Power Semiconductor Devices 1st Ed. by B. Jayant Baliga Fundamentals Of Probability With Stochastic Processes , 3nd ed 2005 , by Prentice H. & SAEED GHAHRAMANI fundamentals of quantum mechanics for solid state electronics and optics , 2005 edition , by C.L Tang Fundamentals of Signals and systems using web and matlab third edition by Edward W. Kamen, Bonnie S Heck Fundamentals of Solid-State Electronics by Chih-Tang Sah Fundamentals of Thermal Fluid Sciences by Yunus A. Cengel, Robert H. Turner, Yunus Cengel, Robert Turner Fundamentals of Thermodynamics 6th edition by sontag Fundamentals of Thermodynamics by Richard Sonntag Claus Borgnakke Gordon Van Wylen Fundamentals of Wireless Communication by Tse and Viswanath Game Theory , An Introduction , 2013 , by Steve Tadelis Geometry A High School Course , 1994 edition , by S. Lang & G.Murrow Heat Transfer A Practical Approach 2nd edition by Yunus A. Cengel, Yunus Cengel How English Works A Grammar Handbook with Readings Instructor's Manual by Ann Raimes Intermediate Accounting , 2nd ed 2010 , by EmpLeo RobLes Intermediate Accounting , 14th ed Intermediate Accounting , 15th ed Introduction To Algorithms , 2 nd ed , by Thomas H. Cormen & Charles E. Leiserson & Ronald L. Rivest & Clifford Stein Introduction to Algorithms 2nd edition by Philip Bille Introduction to Algorithms 2nd Edition by Thomas H. Cormen Introduction to chemical engineering thermodynamics 6th edition by j. m. smith Introduction to Communication Systems 3rd Edition by Stremler Introduction to Computing and Programming with JAVA-A Multimedia Approach 1st Edition by Mark Guzdial and Barbara Ericson Introduction to Data Mining , 2006 , by Pang Ning Tan , Michael Steinbach , Vipin Kumar Introduction to Econometrics , 2003 edition , by James H. Stock , Mark W. Watson Introduction to electric circuits 6th edition by Dorf Svaboda Introduction to Electric Circuits 7th edition by Richard C. Dorf & James A. Svoboda Introduction to elementary particles by D.Griffiths Introduction to Eletrodynamics 3rd ed By David J. Griffiths Introduction to Environmental Engineering and Science 3rd Edition Introduction to Ergonomics By Robert Bridger Introduction to Flight , 6th ed , by John D.Anderson Jr Introduction to fluid mechanics 5th edition by fox and mcdonald Introduction to fluid mechanics 6th edition by fox and mcdonald Introduction to Graph Theory , 2nd ed ,by Douglas B. West Introduction to Java Programming 7th edition by Y. Daniel Liang Introduction to Linear Algebra 3rd Edition By Gilbert Strang Introduction to Linear Programming 1st Edition by L. N. Vaserstein [student solution manual] Introduction to modern statistical mechanics , by David Wu & David Chandler Introduction to Probability by Dimitri P. Bertsekas Introduction to Quantum Mechanics (1995) by David J. Griffiths Introduction to Quantum Mechanics , 2nd Ed.2005 , by David Jeffery Griffiths Introduction to Queueing Theory , 2nd ed , by Robert B. Cooper & Borge Tilt Introduction to Solid State Physics by Charles Kittel Introduction to VLSI Circuits and Systems John P Uyemura Introduction to Wireless Systems by P.M. Shankar IP Telephony Solution guide IT Networking Labs by Tom Cavaiani Java How to Program, 5th Edition By Harvey M. Deitel, Paul J. Deitel Journey into Mathematics An Introduction to Proofs (Book and solution manual) by Joseph J. Rotman KC's Problems and Solutions for Microelectronic Circuits, Fourth Edition by Adel S. Sedra, K. C. Smith, Kenneth C. Smith Labview for engineers 1st edition by R.W. Larsen Linear Algebra a modern introduction Second Edition by David Poole Linear Algebra and Its Applications by David C. Lay Linear Algebra by Otto Bretscher Linear Algebra Done Right, 2nd ed , by Sheldon Axler (ISBN 0387982590)(1997) Linear Algebra with Applications 6th edition by Leon Linear circuit analysis 2nd edition by R. A. DeCarlo and P. Lin Linear dynamic systems and signals by Zoran Gajic with matlab experiments and power point slides Linear Systems And Signals 1st edition by B P Lathi Logic and Computer Design Fundamentals 3rd Edition by Morris Mano & Charles Kime Solutions Logic and Computer Design Fundamentals 4th Edition by Morris Mano Managerial Accounting 11th edition by Eric W. Noreen, Peter C. Brewer, Ray H. Garrison Manufacturing Processes For Engineering Materials , 5th ed , by Kalpakjian Materials and Processes in Manufacturing 9th edition by E. Paul DeGarmo, Solutions Manual by Barney E. Klamecki Materials Science and Engineering 6th edition by Callister Materials Science and Engineering 7th edition by Callister Materials Science and Engineering an Introduction , 8th ed Materials Science by Milton Ohring Mathematical Methods for Physics and Engineering 3rd Edition by K. F. Riley, M. P. Hobson Mathematical Methods in the Physical Sciences , 3rd ed , by Mary L. Boas Mathematical Models in Biology An Introduction by Elizabeth S. Allman, John A. Rhodes Mathematical Olympiad in China Problems and Solutions Mathematical Proofs A Transition to Advanced Mathematics. 2nd Ed By Gary Chartrand, Albert D. Polimeni, Ping Zhang Mathematics for Economists by Carl P. Simon Lawrence Blume MATLAB Programming for Engineers by tephen J. Chapman, Cengage Learning ( m files) Matrix Analysis and Applied Linear Algebra By Carl D. Meyer [Book and solution manual] Mechanical Design of Machine Elements and Machines 1st Edition by Collins Mechanical Engineering Design 7th Edition by Shigley Mechanical Engineering Design 8th edition by Shigley Mechanical Vibrations 3rd edition by Singiresu Rao Mechanics Of Fluids , 8ed , by Massey B & Ward-Smith J Mechanics of Fluids 5th Edition by Frank White Mechanics of Fluids 8th edition by Massey Mechanics of Materials , 4th ed , by Beer Johnston Mechanics of Materials , 7th ed , by Gere James M. Gere & Barry J. Goodno Mechanics of Materials 3rd Edition by Beer Mechanics of Materials 4th edition By Hibbeler Chapter 12 mechanics of materials 6th edition by James Gere Mechanics of Materials 6th edition by R. C. Hibbeler Mechanics of Materials 7th edition by R. C. Hibbeler Mechanics of Materials civil building , 2010 edition , by Hibbler Microeconomics Theory , by Mas-Collel & Whinston & Green Microelectronic Circuit Design 2nd Ed. - Richard C. Jaeger and Travis N. Blalock Microelectronic Circuit Design 3rd Ed. - Richard C. Jaeger and Travis N. Blalock Microelectronic Circuit Design 3rd edition by R. Jaeger Microelectronic circuits 5th edition by Adel S. Sedra kennethSmith Microelectronics 1 & 2 by Dr. Wen Ching Chang Microprocessors and Interfacing-Programming and Hardware 2nd Edition by Douglas V. Hall Microwave and RF design of wireless systems by Pozar Microwave Engineering 2nd edition by David M Pozar Microwave Engineering 3rd Ed. by David M Pozar Microwave transistor amplifiers analysis and design 2nd edition by Guillermo Gonzalez Millman - Microelectronics digital and analog circuits and systems by Thomas V. Papathomas Mobile Communications 2nd Ed. by Jochen H. Schiller Modern Control Engineering 3rd edition by K. OGATA Modern Control Systems 11th edition by Richard C. Dorf Robert H Bishop Modern Control Systems, 12th Edition By Richard C. Dorf, Robert H. Bishop Modern Digital and Analog Communications Systems 3rd edition by B P Lathi Modern Digital Electronics , 3rd ed , by R P Jain Modern Digital Signal Processing by Roberto Cristi Modern Physics ,3rd ed , by Serway & Moses & Moses Modern physics By Randy Harris Multivariable Calculus , 6th ed , by J. Stewart MULTIVARIABLE CALCULUS , 7th Edition , by Stewart Multivariable Calculus 4th edition by Stewart Dan Clegg Barbara Frank Musculoskeletal Function An Anatomy and Kinesiology Laboratory Manual by Dortha Esch Esch Nanoengineering of Structural, Functional and Smart Materials Network Flows Theory, Algorithms, And Applications by Ravindra K. Ahuja, Thomas L. Magnanti, and James B. Orlin Network Simulation Experiments Manual (The Morgan Kaufmann Series in Networking) by Emad Aboelela Neural networks and learning machines 3rd edition by Simon S. Haykin Nonlinear Programming 2nd Edition by Dimitri P. Bertsekas Numerical Analysis 8th ed. By Richard L. Burden, J Douglas Faires Numerical Methods For Engineers 4th edition by Chapra Numerical Solution of Partial Differential Equations An Introduction by K. W. Morton, D. F. Mayers Operating System Concepts , 7th ed , by ABRAHAM SILBERSCHATZ & PETER BAER GALVIN & GREG GAGNE Operating Systems 4th Edition by Stallings Operating Systems Concepts , 6Th ed , by ABRAHAM SILBERSCHATZ & PETER BAER GALVIN & Westminster College Operation Research , 8th ed , by H.A. Taha Optimal Control Theory An Introduction By Donald E. Kirk Optimization of chemical processes by Edgar himmelblau Options, Futures and Other Derivatives 5th Edition by John Hull, John C. Hull Options, Futures and Other Derivatives, 4th Edition by John Hull, John C. Hull Options, Futures And Other Derivatives, 7th ed , by John C. Hull Orbital Mechanics for Engineering Students , by Howard D. Curtis Organic Chemistry , 4th ed , by F A Carey & R C Atkins Organic Chemistry , 0471756148 , by David Klein Organic chemistry 4th edition by Robert C. Athkins and Francis Carey Organic chemistry 5th edition by Robert C. Athkins and Francis Carey Organic Chemistry 7th Edition by Susan McMurry Parallel Programming in C with MPI and OpenMP , 2003 , by MichaelJ Quinn Partial Differential Equations With Fourier Series And Boundary Value Problems 2nd Edition By Nakhle H.Asmar Physical Chemistry 7th edition by Peter Atkins and Julio de Paula Physical Chemistry 8th edition by Peter Atkins and Julio de Paula Physical Chemistry by Prem Dhawan Physics 5th Edition by Halliday , Resnick , Krane Physics for Scientist and Engineers 1st edition by Knight Physics for Scientists and Engineers 5th edition by Paul A. Tipler, Gene Mosca Physics For Scientists And Engineers 6th Edition By Serway And Jewett Physics For Scientists And Engineers A Strategic Approach , 2nd ed , By Randall D Knight Physics For Scientists And Engineers Vol.1v , 5th ed 2000 , by Serway & Beichner Physics for Scientists and Engineers with Modern Physics 3rd Edition PIC Microcontroller and Embedded Systems 1st edition by Mazidi [Book and solution manual] Piping and Pipeline Calculations Manual Construction, Design Fabrication and Examination by Phillip Ellenberger Plant Design and Economics for Chemical Engineers 4th Edition By Max S. Peters , Klaus D. Timmerhaus power electronics CIRCUITS,DEVICES,AND APPLICATIONS , 3rd ed , by MUHAMMAD H.Rashid Power Electronics-Converters, Applications and Design 2nd edition by Ned Mohan, Tore M. Undeland and William P. Robbins Power Electronics-Converters, Applications and Design 3rd edition by Ned Mohan, Tore M. Undeland and William P. Robbins Power System Analysis by John Grainger and William Stevenson Power Systems Analysis and Design 4th Edition by Glover J. Duncan, Sarma Mulkutla .S Principles and Applications of Electrical Engineering 2nd Ed. by Giorgio Rizzoni Principles and Applications of Electrical Engineering 4th edition by Giorgio Rizzoni Principles of Communications Systems, Modulation and Noise 5th Edition by William H. Tranter and Rodger E. Ziemer Principles of Digital Communication and Coding 1st edition by Andrew J. Viterbi and Jim K. Omura Principles of Electronic Materials and Devices 3rd edition By Safa O. Kasap Principles Of General Chemistry , by Martin S Silberberg & Patricia Amateis Principles of Mathematical Analysis , by Rudin W Principles of Neurocomputing for Science and Engineering 1st Edition Fredric M. Ham and Ivica Kostanic Principles of Physics 4th edition by Serway and Jewett Probability and Random Processes for Electrical Engineering by Alberto Leon-Garcia Probability and Statistical Inference, Seventh Edition By Robert Hogg, Elliot A. Tanis Probability and Statistics , 3th ed 2002 , by Morris H. DeGroot & Mark J. Schervish Probability and Statistics for Engineering and the Sciences by Jay L. Devore Probability and Statistics for Engineers and Scientists , 7th edition , by Walpole & Myers Ye Probability and Statistics for Engineers and Scientists , 8th Edition by Sharon Myers , Keying Ye, Walpole Probability and Statistics for Engineers and Scientists 3rd Edition by Anthony Hayter Probability and Statistics for Engineers and Scientists Manual by HAYLER Probability and Stochastic Processes 2nd edition by David J. Goodman Probability Random Variables and Random Signal Principles , 4th Edition , by Peyton Peebles Jr Probability Random Variables And Stochastic Processes 4th edition by Papoulis Process Control Instrumentation Technology, 8th edition by Johnson Process Dynamics and Control 2nd edition by Dale E. Seborg Process systems analysis and control - Donald r. Coughanowr Programmable logic controllers 1st edition by Rehg & Sartori Project Management Casebook by Karen M. Bursic, A. Yaroslav Vlasak Quantum Field Theory Problem Solutions 2007 by Mark Srednick Quantum Physics 3rd Edition by Stephen Gasiorowicz Recursive Macroeconomic Theory , 2001 edition , Lars Ljungqvist & Hanno Lusting RF circuit Design Theory and Application by Ludwig bretchkol Rules Of Thumb For Chemical Engineers, A Manual Of Quick, Accurate Solutions To Everyday Process Engineering Problems , by Carl Branan Satellite Communication , by Pratt Scientific Computing with Case Studies 1st Edition by Dianne P. O'Leary SEARS & ZEMANSKY'S COLLEGE PHYSICS , 9TH ED , by HUGH D. YOUNG Sears and Zemansky's University Physics with Modern Physics , 12th ed Semiconductor Device Fundamentals by Robert Pierret Semiconductor Devices Physics And Technology , 2nd ed , by S. M. SZE Semiconductor Devices Physics and Technology , 3rd ed , by S. M. SZE & M. K. LEE Semiconductor Manufacturing Technology 1st Edition by Michael Quirk and Julian Serda Semiconductor Physics and Devices Basic Principles 3rd edition , by Neamen Signal Processing and Linear Systems by B P Lathi Signal Processing First - Mclellan , Schafer and Yoder Signals and Systems 2nd edition Oppenheim Willsky Signals and Systems 2003 by M.J. Roberts Signals and Systems Analysis of Signals Through Linear Systems by M.J. Roberts Signals and Systems, Second Edition by Simon Haykin, Barry Van Veen Signals, Systems and Transforms 4th edition by Phillips, Parr & Riskin Single Variable Calculus Early Transcedentals , 5 th ed , by Daniel Anderson & Jeffrey A. Cole & Daniel Drucker Sipser's Introduction to the Theory of Computation By Ching Law Solid State Electronic Device 6th edition by Ben Streetman Solid State Electronic Devices , by Streetman & Banerjee Solution to Skill - Assessment Exercises to Accompany Control Systems Engineering 3rd edt. by Norman S. Nise Starting Out with Java 5 Lab Manual to Accompany Starting out with Java 5 by Diane Christen Statistical digital signal processing and modeling by monson hayes Statistical Inference , 2 nd ed 2001 , by George Casella & Roger L. Berger & Damaris Santana Statistical Physics of Fields by Mehran Kardar statistical physics of particles by Mehran Kardar Strength of Materials ,4th edition , by Ferdinand L. Singer & Andrew Pytel Structural analysis 5th edition by Hibbeler Structured Computer Organization , 5th ed , by ANDREW S.TANENBAUM Student Solution Manual for Essential Mathematical Methods for the Physical Sciences by K. F. Riley, M. P. Hobson System Dynamics 3rd Ed. by Katsuhiko Ogata System Dynamics and Response , 1st Edition by S. Graham Kelly The 8051 Microcontroller 4th Ed. by I. Scott MacKenzie and Raphael C.-W. Phan The 8088 and 8086 Microprocessors Programming, Interfacing, Software, Hardware, and Applications (4th Edition) By Walter A. Triebel, Avtar Singh The ARRL Instructor's Manual for Technician and General License Courses By American Radio Relay League The Art of Electronics by Thomas C. Hayes & Paul Horowitz [student solution manual The C++ Programming Language , Special 3rd Edition , by Bjarne Stroustrup The Calculus 7 by Louis Leithold The Language of Machines, An Introduction to Computability and Formal Languages by Robert W. Floyd, Richard Beigel The Science and Engineering of Materials 4th edition by Donald R. Askeland Frank Haddleton The Structure and Interpretation of Signals and Systems 1st Edition by Edward A. Lee and Pravin Varaiya Thermodynamics An Engineering Approach , 7 ed , by Yunus A. Cengel, Michael A. Boles Thermodynamics An Engineering Approach 5th edition by Yunus A Cengel and Michael A Boles Thermodynamics An Engineering Approach 6th edition by Yunus A Cengel and Michael A Boles Thomas Calculus 11th edition by George B.Thomas Thomas' Calculus, Eleventh Edition (Thomas Series) By George B. Thomas, Maurice D. Weir, Joel D. Hass, Frank R. Giordano Toolboxes for MATLAB version 5 , Stress strain and structural ynamic Transport Phenomena 2nd edition by Bird, Stewart and Lightfoot Transport Phenomena in Biological Systems 2nd Edition By George A. Truskey, Fan Yuan, David F. Katz Trigonometry , 8th ed 2005 , by Margaret L. Lial & John Hornsby & David I. Schneider Trigonometry with Applications , 3rd ed , by Bernard J. Klein Unit operations of chemical engineering 7th edition by Warren l. Mccabe University physics 11th edition by Young and Freedman University Physics with Modern Physics , 12ed 2012 , by Young & Freedman Vector Calculus , Linear Algebra and Differential Forms 2nd Edition by Hubbard and Burke] Vector Mechanics for Engineers , Dynamics 6th edition by Beer Vector Mechanics for Engineers Dynamics 7th Edition by Beer Vector Mechanics for Engineers Statics and Dynamics 8th edition by Beer Vector Mechanics Statics 7th Edition by Beer and Johnston VHDL for Engineers International Edition by Kenneth L. Short Wireless Communications 1st Ed. by A. F. Molisch Wireless Communications 1st Ed. by Andrea Goldsmith Wireless Communications Principles and Practice 2nd Edition - Theodore S. Rappaport Zill's a First Course in Differential Equations with Modeling Applications (7th ed.) and Zill & Cullen's Diferential Equations with Boundary-Value Problems (5th ed.) ==================================== If your request isn't in the list , we will find it for you, just contact us solutions.for.student at hotmail.com From marko at pacujo.net Mon Mar 24 03:47:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 24 Mar 2014 09:47:44 +0200 Subject: loop References: Message-ID: <87fvm811i7.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Mar 24, 2014 at 11:35 AM, wrote: >> I'm trying to create a for loop that starts at 100 and goes to 10Mllion. > > That sounds like a logarithmic scale. How about: for i in [ 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 ]: ... Marko From ian.g.kelly at gmail.com Mon Mar 24 05:03:12 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 24 Mar 2014 03:03:12 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 23, 2014 11:56 PM, "Mark H Harris" wrote: > > On 3/22/14 4:46 AM, Steven D'Aprano wrote: >> >> On Fri, 21 Mar 2014 23:51:38 -0500, Mark H Harris wrote: >> >>> Lambda is a problem, if only because it causes confusion. What's the >>> problem? Glad you asked. The constructs DO NOT work the way most people >>> would expect them to, having limited knowledge of python! > > > One of the best links for understanding what is wrong with lambda is here, from Guido, (by the way I agree totally with his assessment, there is no point really in writing it out again): > > http://www.artima.com/weblogs/viewpost.jsp?thread=98196 That post doesn't point out anything "wrong" with lambda. The argument boils down to: 1) map and filter are not useful because we have comprehensions; 2) reduce is confusing; 3) if we remove those then lambda is not useful either. > Lambda is a problem of confusion for scientists and other mathematicians (amateur and otherwise) who may be confused because python's lambda does not do precisely what they might expect from other functional programming languages, nor does it match precisely with the lambda calculus. Its also confusing to sophisticated users of all stripes who may not be aware of "lambda" at all. The difference does not really lie in the lambda construct per se but in the binding style of closures. Functional languages tend to go one way here; imperative languages tend to go the other. Python being primarily an imperative language follows the imperative model. Anonymous functions in Python work the same way in this regard as anonymous functions in Lua or ECMAScript or Go -- those other languages merely avoid the cardinal sin of defining their anonymous functions using the keyword "lambda". The result may be more surprising to users accustomed to functional languages, but I claim that it is *less* surprising to users of other imperative languages. >> Python is not a pure functional language, but you can write functional >> code in it. If you want a pure functional language, you know where to >> find one. > > > Yes, that's obvious; but you're missing the point. Python is not a functional language, and implying that it can be used as one is misleading at best (maybe a lie at worst) just because it has a construct for generating a dynamic anonymous function. Oh, give me a break. If you find that you can't write functional code in Python just because closure bindings are slightly inconvenient, then you can't be trying very hard. > Well, number one, I'm not demanding anything. Number two, everyone who uses Haskell (for whatever reason) knows well from the start that its a pure functional programming language. That is the advertisement, and that is the expectation. No one expects anything different. And I would hope that anybody who uses Python is likewise aware from the stay that it *isn't* a purely functional language. >> Python could deprecate many things. It would make Python a worse language. > > > How so? Read Guido's argument above. Another way to answer this question is that I have been programming with Python for almost a decade and I've not used lambda. In fact, I have gone out of my way to NOT use lambda because I am fully aware that the BDFL hates it. If lambda were going to be deprecated and removed then it already would have happened in Python 3, because Guido tried to do precisely that. I'm not sure what the reasons were for keeping it in the end (according to PEP 3099 it was because nobody suggested a suitable replacement), but if he couldn't get rid of it then, he never will. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Mar 24 05:40:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 09:40:51 +0000 Subject: loop In-Reply-To: <87fvm811i7.fsf@elektro.pacujo.net> References: <87fvm811i7.fsf@elektro.pacujo.net> Message-ID: On 24/03/2014 07:47, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Mar 24, 2014 at 11:35 AM, wrote: >>> I'm trying to create a for loop that starts at 100 and goes to 10Mllion. >> >> That sounds like a logarithmic scale. > > How about: > > for i in [ 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 ]: > ... Why the overhead of creating a list when you could use a tuple? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve at pearwood.info Mon Mar 24 05:49:35 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 24 Mar 2014 09:49:35 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> On Mon, 24 Mar 2014 00:52:52 -0500, Mark H Harris wrote: > On 3/22/14 4:46 AM, Steven D'Aprano wrote: >> On Fri, 21 Mar 2014 23:51:38 -0500, Mark H Harris wrote: >> >>> Lambda is a problem, if only because it causes confusion. What's the >>> problem? Glad you asked. The constructs DO NOT work the way most >>> people would expect them to, having limited knowledge of python! > > One of the best links for understanding what is wrong with lambda is > here, from Guido, (by the way I agree totally with his assessment, there > is no point really in writing it out again): > > http://www.artima.com/weblogs/viewpost.jsp?thread=98196 It's only one paragraph. Here it is: Why drop lambda? Most Python users are unfamiliar with Lisp or Scheme, so the name is confusing; also, there is a widespread misunderstanding that lambda can do things that a nested function can't -- I still recall Laura Creighton's Aha!-erlebnis after I showed her there was no difference! Even with a better name, I think having the two choices side-by-side just requires programmers to think about making a choice that's irrelevant for their program; not having the choice streamlines the thought process. Also, once map(), filter() and reduce() are gone, there aren't a whole lot of places where you really need to write very short local functions; Tkinter callbacks come to mind, but I find that more often than not the callbacks should be methods of some state-carrying object anyway (the exception being toy programs). None of map(), filter() or reduce() are gone. reduce() has been pushed out into a module, but map() and filter() have actually been enhanced. Any suggestion that lambda is obsolete flounders on that fact. There's no doubt that lambda is less-often useful than is the def statement. But not only is it still useful, but there is a continual stream of people asking for Python to make it *more useful* by allowing the body of a lambda to be a full block, not just a single statement. Guido has stated (although I cannot remember where, so cannot paste a link) that he accepts that in principle, so long as somebody comes up with acceptable syntax. In Ruby, anonymous blocks are used *all the time*. Python is not Ruby, and never will be, but a lightweight way to generate anonymous functions in expressions is one difference between a modern, powerful language, and an archaic or toy under-powered language. I'm too lazy to do this the right way, but there are at least 99 mentions of "lambda" in the 3.3 standard library: steve at runes:/usr/local/lib/python3.3$ grep lambda *.py | wc -l 99 It's used in calendar, cgitb, configparser, difflib, decimal, functools, inspect, os, pydoc and others. Python is a programming language aimed at programmers, not a toy. It should include tools that programmers use, like threads, closures, first-class functions. And lambda. >> Why is that a problem? Would you consider it a problem that people who >> don't understand BASIC can't understand BASIC? ("I don't get the >> difference between GOTO and GOSUB. {snip} >> >> The problem is ignorance, not the calculator, and not lambda. > > You're argument, based on analogy, is also a red herring, as well a > straw man. Please stop misusing "straw man". It has a specific meaning: https://yourlogicalfallacyis.com/strawman > Lambda is a problem of confusion for scientists and other > mathematicians (amateur and otherwise) who may be confused because > python's lambda does not do precisely what they might expect from other > functional programming languages, nor does it match precisely with the > lambda calculus. Yes, you've already said that. And my response remains the same: users of a language should be expected to learn the language, at least to the point that they can "get by". One doesn't need ten thousand hours experience and to be an expert. But nor should the confusion of somebody who doesn't know the language count for much. Python's ints don't work exactly the same as ints do in some other languages, nor do Python's strings, nor is Python's object model precisely the same as that of some other languages. I think that it would be a ridiculous idea to discard int, str and the entire object system just because some people are surprised that Python doesn't behave exactly like some other language. I don't think lambda is any different. The same argument applies to *any other language*. Ocaml is not precisely the same as Haskell, Java not precisely the same as C++, Ruby is not precisely the same as Javascript. Should Ruby discard their anonymous blocks because they don't work "precisely" the same as Haskell? Or perhaps Haskell should throw the towel in because it doesn't behave "precisely" the same as Ruby? Of course not -- new languages come into existence precisely so that they will be different from what is already there. Who is to say that there aren't people who like Python's lambda *because* it is different from the anonymous functions in other languages? Or because it is less abstract than the lambda calculus? Other languages -- not even Lisp -- don't get to be the sole decider as to what counts as an anonymous function. Python's lambda may be limited, but it is a perfectly fine lambda for what it is intended to do. > Its also confusing to sophisticated users of all > stripes who may not be aware of "lambda" at all. If they're not aware of lambda, how are they confused by it? >> You've told us that "most people" (which people? dentists? lawyers? >> illiterate tribesmen from the Amazon? professional programmers?) are >> surprised by lamba's behaviour, but you haven't actually told us what >> behaviour is surprising, or what "most people" expect lambda to do. >> Perhaps you ought to? > > I love your rhetoric, actually, but red herrings all . . . No, not really. I don't understand who your intended audience for Python is. If I were to try to guess, I suspect that you want to dumb Python down until it is like Dartmouth BASIC circa 1980 except without the line numbers and with a slightly different syntax. Perhaps I'm wrong, I certainly hope I'm wrong, but that's the impression I got from your comments on the python-ideas list. Python is a programming language. People who program in Python are programmers. It doesn't matter whether they are school children, or scientists, or farmhands, once they start writing programs, they are programming, which makes them a programmer. They might not be paid for it, but they are still programmers. Who should be using Python, if not programmers? > Here is a link that advocates lambda (map, filter, and reduce) as a > very powerful construct for doing various things: I agree: > > http://www.secnetix.de/olli/Python/lambda_functions.hawk > > Its a great link, but the important sentence for this discussion is > this unique quote, about "lambda," > > >"This is not exactly the same as lambda in functional >> programming languages, but it is a very powerful concept . . ." > > People who understand lambda from functional languages must hassle > with the fact that lambda is different in python, and people who do not > understand functional programming languages (nor the lambda calculus) > are confused by the syntax, also just what it does. You want to remove lambda because it causes confusion. Okay, for the sake of the argument I will agree that lambda is confusing. Do you know what else is confusing? Threading is confusing. So is multiprocessing. So are databases. Unicode is confusing. First-class functions are confusing. Recursion is confusing. Closures are confusing. List comprehensions are confusing. What the hell are trampolines? I'm certainly confused by them. If we remove lambda because it is confusing, shouldn't we also remove all these other confusing things? Where shall we stop? Should we stop only when Python is a confusion-free, utterly useless toy language? I don't think so. Or should we stop *before* going down that path? You want to single out lambda. I don't think we should. >> Python is not a pure functional language, but you can write functional >> code in it. If you want a pure functional language, you know where to >> find one. > > Yes, that's obvious; but you're missing the point. Python is not a > functional language, and implying that it can be used as one is > misleading at best (maybe a lie at worst) just because it has a > construct for generating a dynamic anonymous function. I didn't say that Python can be used as a functional language. I said you can write functional code in Python. And that is so obviously true that I cannot believe that you are disputing it. Functions are first-class values. You can pass them around as arguments to other functions. You can wrap them to make closures, or compose them. You can return functions from other functions. You can, if you wish, eschew holding state and write pure functions with no side-effects and no state. You can even eschew local variables (well, mostly) inside your functions and do (nearly) everything by composing other functions. You can write pipelines of iterators, generators or co-routines. It may be hard to write an *entire* application using nothing but functional style in Python, but using functional style throughout the application is so easy and simple that most people don't even realise that they are writing in a functional style when they do so. >> (I wonder whether, say, Haskell has the people coming along and >> demanding that it should become more like Python?) > > Another straw man. > > Well, number one, I'm not demanding anything. Number two, everyone > who uses Haskell (for whatever reason) knows well from the start that > its a pure functional programming language. That is the advertisement, > and that is the expectation. No one expects anything different. And everyone who uses Python ought to know that Python is not. That is the advertisement, and that ought to be the expectation. Anonymous functions are not the sole preserve of purely functional languages, any more than objects are the sole preserve of purely OOP languages. >>> I can see uses for python's lambda. But, honestly, I think python >>> could deprecate its use and in five years just remove it from the >>> language; along with filter, map, and reduce ! >> >> Python could deprecate many things. It would make Python a worse >> language. > > How so? Read Guido's argument above. Another way to answer this > question is that I have been programming with Python for almost a decade > and I've not used lambda. In fact, I have gone out of my way to NOT use > lambda because I am fully aware that the BDFL hates it. In other words, you have had situations where you *could have* used lambda, perhaps even *should have* used lambda, but you intentionally went *out of your way* (i.e. made the job harder than it needed to be) to avoid it, just to slavishly ape the BDFL. Thank you for just proving my point for me. Your code would have been better, or at least easier, with lambda. Removing it would make the language worse, not better. > Reduce is no > longer in the standard library (although you can import it) You mean it is no longer in the builtin namespace. It is still in the standard library. > and there > are equally good ways to do what lambda was designed for without the > hassle nor confusion. Incorrect. lambda was designed to allow you to create anonymous functions in an expression, not as a statement. There is *no other way* to do that in Python. Even if you come up with some weird hack involving exec or FunctionType and code objects, it won't be *equally good*. It will be a broken, third-rate imitation of lambda. >> By the way, are you aware that lambda is *identical* to def except for >> three things? >> >> - lambda is an expression, not a statement like def; >> >> - the body of a function created with lambda is limited to a >> single expression, not a block; >> >> - the function object created with lambda has a generic name. > > Absolutely, thank you for pointing those out ! You forgot that > lambdas can be used in expressions while def functions may not... Umm, read my list again. It's the first item. > but > you really have proved my point. There is so little difference between > the two that (for the sake of clarity and reducing confusion) it might > be good to just remove the lambda thing altogether. Just say'in. The *number* of differences may be small, but the *consequences* of those differences are enormous. >> So unless the surprising behaviour about lambda that you're about to >> tell us about relates to one of those three things, I *guarantee* that >> functions created with def have the same surprising behaviour. > > No, the surprising behavior is that python lambda does not work > exactly the way that lambda works in functional programming languages Then neither does def. Would you like to discard def as well? No? Why not? > (see the two links provided) the confusion it creates for "normal" users > does not warrant its inclusion in the language. > > Having said that, I must admit that I've "played" with lambda > extensively and find it interesting from a comp sci standpoint, but, > again, for normal users I don't think there is a really good value add > for having it in the language. -- Steven From shishirk at gmail.com Mon Mar 24 05:15:17 2014 From: shishirk at gmail.com (Shishir) Date: Mon, 24 Mar 2014 14:45:17 +0530 Subject: Asyncio (or something better) for control of a vacuum system/components. Message-ID: Dear All, I apologise in advance a) if this is not the proper list for asking the question, b) the length of the post. I am writing a software to control and monitor a vacuum furnace+attachments. It has a few mass flow controllers, a butterfly valve, a labjack unit for analog/digital outputs etc. They use RS485, RS232 and USB to communicate with the computer and follow special protocols for commands and response. The response time to execute commands can be from 5 ms to 1 s. To achieve this, I thought of a server which reads commands on a network connections, parses the command and calls methods of appropriate device classes, which then use the corresponding channel protocol to execute the command. The response provided by the devices (flow controllers, valve) is sent back on the network connection. As there can be multiple clients (e.g. for monitoring from several computers), and some commands can take long, the server should not block when getting a command executed. I wanted to use asyncio to achieve this non-blocking behaviour, i.e. when the server calls the method of device classes, a callback is installed and the method returns immediately. When the response is available from the device, the callback writes the response to the client's connection. Some (pseudo)code: class server(Protocol): def connection_made(self, transport): self.transport = transport def data_received(self, data): device, command, args = parse(data) result = yield from device.command(args) self.transport.write(result) class device1(): self.channel = rs232() @asyncio.coroutine def command1(args): r = self.execute(self.channel, 'Cmd1', args) # this can take a while return r # ++ get_event_loop code for running the server forever This doesn't work as I expected. For example, I expected that when command1 is awaiting response from the device, the server can receive another command2 on the same network connection, and get that executed (say on another device). If the response of this command2 is available earlier, it will be written to the network connection. Instead, the data_received call for first command doesn't return till the command1 is completed. If the execute() call is replaced by asyncio.sleep(r) it works as I expect. The problem is that self.execute() blocks and the asyncio framework has no way to know how to reschedule it or bypass it. This can be avoided if I depended on I/O from a file descriptor, on which I can apply poll()/select(). But the channel handler that I have is more generic (rs232() in code above). My question then is: is there a good way to handle the situation? I would like to have following architecture: A server sits on the computer which is connected to the devices via channels (rs232, rs485, usb etc.). A client initiates a network connection to the server and starts sending commands which are numbered. Server asks the device classes for a response of execution of these commands on the devices. The responses it receives (and dispatches to the client) from device classes are not in same sequence, but that doesn't matter as they are numbered by the client. There can be several clients. I also assume that execution of each command on the devices is atomic, i.e. when the device class connects to the device on later's channel, the channel is not relinquished till the device provides a response. To achieve this, the device classes obtain a lock on the channel they need before talking to the device (and release it after they are done). I have looked around the web but couldn't find an easy+flexible framework to do what I have outlined here. Our lab is using a control panel written in labview, which I believe does things sequentially (i.e. by blocking). It works alright, but error handling is poor (crashes on errors and resets the furnace state on a restart!). It is also done in Labview, is not portable or can be addressed over network. I have written/tested python code to control the following if anyone is interested (will put up on bitbucket.org once I am done with the above server): T3Bi throttle valve controller from MKS (RS232 based) GF40 MFCs from Brooks Instruments (RS485 based) CMC & CMX gauges from Brooks Instruments (RS485, but currently controlled by T3Bi) 1179A MFCs from MKS (which is controlled via analog output from a LabJack U6) SMC pneumatic switches (which are controlled via digital ports on LabJack U6 + PS12VDC). The LabJack parts use labjackpython library. Thanks a lot for reading, sid. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Mar 24 05:58:58 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 09:58:58 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/03/2014 05:52, Mark H Harris wrote: > > How so? Read Guido's argument above. Another way to answer this > question is that I have been programming with Python for almost a decade > and I've not used lambda. In fact, I have gone out of my way to NOT use > lambda because I am fully aware that the BDFL hates it. Reduce is no > longer in the standard library (although you can import it) and there > are equally good ways to do what lambda was designed for without the > hassle nor confusion. > Where do you get reduce from if it's not in the standard library? As for lambda I've no real interest in it, other than when copying examples where it's used to (say) provide a key function. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From marko at pacujo.net Mon Mar 24 05:55:24 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 24 Mar 2014 11:55:24 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87bnwv2a5v.fsf@elektro.pacujo.net> Ian Kelly : > If lambda were going to be deprecated and removed then it already > would have happened in Python 3, because Guido tried to do precisely > that. I'm not sure what the reasons were for keeping it in the end > (according to PEP 3099 it was because nobody suggested a suitable > replacement), but if he couldn't get rid of it then, he never will. You never *need* (Python's) lambda for anything. Inner functions are more capable and almost always more readable. It doesn't hurt to have lambda, but I don't find any use for it, either. Marko From marko at pacujo.net Mon Mar 24 06:04:32 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 24 Mar 2014 12:04:32 +0200 Subject: loop References: <87fvm811i7.fsf@elektro.pacujo.net> Message-ID: <877g7j29qn.fsf@elektro.pacujo.net> Mark Lawrence : > On 24/03/2014 07:47, Marko Rauhamaa wrote: >> for i in [ 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 ]: > > Why the overhead of creating a list when you could use a tuple? :) Once in college, we were given assembly programming assignments. The textbook defined an imagined 18-bit CPU and an instruction set. A fellow student was given the task to write a subroutine that calculates the factorial of the argument. He went through the trouble of creating a loop with multiplication etc. I argued (in vain) that his solution is "wrong" from all angles; he should have implemented his subroutine with a simple lookup table since 18 bits can only take a handful of input values (0 through 8). Marko From nispray at gmail.com Mon Mar 24 06:20:55 2014 From: nispray at gmail.com (Wesley) Date: Mon, 24 Mar 2014 03:20:55 -0700 (PDT) Subject: gdb python how to output integer for examine memory Message-ID: Hi all, I am trying to use gdb debug python script. I am using gdb7.7 and python2.7.6, here is my simple test script: import time def next(i): time.sleep(10) i = 1 - i i = 1 while True: next(i) When this script running, gdb attach to it, and here is snippet: (gdb) py-bt #5 Frame 0x201e130, for file test.py, line 6, in next (i=1) Python Exception (2, '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x82\xa3\xe4\xb8\xaa\xe6\x96\x87\xe4\xbb\xb6\xe6\x88\x96\xe7\x9b\xae\xe5\xbd\x95', 'test.py'): Error occurred in Python command: (2, '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x82\xa3\xe4\xb8\xaa\xe6\x96\x87\xe4\xbb\xb6\xe6\x88\x96\xe7\x9b\xae\xe5\xbd\x95', 'test.py') (gdb) frame 5 #5 0x00000000004d01a7 in PyEval_EvalFrameEx (f=Frame 0x201e130, for file test.py, line 6, in next (i=1), throwflag=0) at Python/ceval.c:2666 2666 x = call_function(&sp, oparg); (gdb) py-locals i = 1 (gdb) pyo i No symbol "i" in current context. (gdb) No symbol "i" in current context. (gdb) p f->f_localsplus $1 = {1} (gdb) p f->f_localsplus[0] $2 = 1 (gdb) p &(f->f_localsplus[0]) $3 = (PyObject **) 0x201e2b8 (gdb) x/d 0x201e2b8 0x201e2b8: 31304528 (gdb) p sizeof(f->f_localsplus[0]) $4 = 8 (gdb) x/dg 0x201e2b8 0x201e2b8: 31304528 (gdb) x/dw 0x201e2b8 0x201e2b8: 31304528 (gdb) So, the latter several commands, I wannted to check memory content, but , how to output integer 1? Thanks. Wesley From marko at pacujo.net Mon Mar 24 06:22:05 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 24 Mar 2014 12:22:05 +0200 Subject: Asyncio (or something better) for control of a vacuum system/components. References: Message-ID: <8738i728xe.fsf@elektro.pacujo.net> Shishir : > The problem is that self.execute() blocks and the asyncio framework > has no way to know how to reschedule it or bypass it. This can be > avoided if I depended on I/O from a file descriptor, on which I can > apply poll()/select(). But the channel handler that I have is more > generic (rs232() in code above). Deep down asyncio depends on file descriptors. If your thingy is another kind of object, it needs to go into its own process or thread. > A server sits on the computer which is connected to the devices via > channels (rs232, rs485, usb etc.). [...] Sounds about right. > I have looked around the web but couldn't find an easy+flexible > framework to do what I have outlined here. Asyncio + subprocess should be all you need for a framework. However, some system programming *will* be required. Marko From sales09 at opclabs.com Mon Mar 24 06:41:35 2014 From: sales09 at opclabs.com (sales09 at opclabs.com) Date: Mon, 24 Mar 2014 03:41:35 -0700 (PDT) Subject: Writing an OPC client with Python ? In-Reply-To: <440880b4$0$13692$636a55ce@news.free.fr> References: <440880b4$0$13692$636a55ce@news.free.fr> Message-ID: <8366e1f6-fa3b-41e7-b8b4-64c027089310@googlegroups.com> OPC Python Example: Get OPC data into Python http://www.opclabs.com/products/quickopc/languages-and-tools/python From sales09 at opclabs.com Mon Mar 24 06:42:47 2014 From: sales09 at opclabs.com (sales09 at opclabs.com) Date: Mon, 24 Mar 2014 03:42:47 -0700 (PDT) Subject: Python OPC -wrapper for data collection, anyone seen it ? In-Reply-To: <3C07501E.3040807@vip.fi> References: <3C07501E.3040807@vip.fi> Message-ID: <7df31139-56b4-4f94-aec6-41cb7f813d04@googlegroups.com> What about (our) QuickOPC: http://www.opclabs.com/products/quickopc/languages-and-tools/python From sales09 at opclabs.com Mon Mar 24 06:43:21 2014 From: sales09 at opclabs.com (sales09 at opclabs.com) Date: Mon, 24 Mar 2014 03:43:21 -0700 (PDT) Subject: OPC for Python ?? (Win32) In-Reply-To: <8ngvvh$25tb@drn.newsguy.com> References: <8ngvvh$25tb@drn.newsguy.com> Message-ID: <09af5e27-44d9-4a20-9d3b-0c10e1e9bebe@googlegroups.com> QuickOPC: Get OPC data into Python http://www.opclabs.com/products/quickopc/languages-and-tools/python From sales09 at opclabs.com Mon Mar 24 06:43:56 2014 From: sales09 at opclabs.com (sales09 at opclabs.com) Date: Mon, 24 Mar 2014 03:43:56 -0700 (PDT) Subject: Python in Process Control? In-Reply-To: References: Message-ID: Get OPC data into Python: http://www.opclabs.com/products/quickopc/languages-and-tools/python From rosuav at gmail.com Mon Mar 24 06:58:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 21:58:29 +1100 Subject: loop In-Reply-To: <877g7j29qn.fsf@elektro.pacujo.net> References: <87fvm811i7.fsf@elektro.pacujo.net> <877g7j29qn.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 24, 2014 at 9:04 PM, Marko Rauhamaa wrote: > Once in college, we were given assembly programming assignments. The > textbook defined an imagined 18-bit CPU and an instruction set. > > A fellow student was given the task to write a subroutine that > calculates the factorial of the argument. He went through the trouble of > creating a loop with multiplication etc. I argued (in vain) that his > solution is "wrong" from all angles; he should have implemented his > subroutine with a simple lookup table since 18 bits can only take a > handful of input values (0 through 8). The task was "calculates". If the task was "returns", then the lookup table would be correct. :) ChrisA From rosuav at gmail.com Mon Mar 24 07:21:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 22:21:20 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 24, 2014 at 8:49 PM, Steven D'Aprano wrote: > I'm too lazy to do this the > right way, but there are at least 99 mentions of "lambda" in the 3.3 > standard library: > > steve at runes:/usr/local/lib/python3.3$ grep lambda *.py | wc -l > 99 I'm not too lazy to do it the right way, but I don't have 3.3 handy, so I've done it on 3.4 instead. There are 77 instances of lambda nodes in the files you list there - which are the ones that aren't in packages. (Note that two instances of lambda on the same line would count as one in Steven's figure, but as two in mine. Also, his counts comments. Still, his way's a lot easier to calculate, and it's in the right ball-park.) Including all subdirectories raises that figure to, get this, 1230. That's actual uses of the lambda keyword as parsed by Python. This does include the test suite, though. Removing all files with "/test/" in the names cuts that figure to only 273. But that's still two hundred and seventy-three places where the Python standard library uses lambda - a respectable figure. ChrisA From jamiemitchell1604 at gmail.com Mon Mar 24 07:32:31 2014 From: jamiemitchell1604 at gmail.com (Jamie Mitchell) Date: Mon, 24 Mar 2014 04:32:31 -0700 (PDT) Subject: Memory error Message-ID: Hello all, I'm afraid I am new to all this so bear with me... I am looking to find the statistical significance between two large netCDF data sets. Firstly I've loaded the two files into python: swh=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/averages/swh_control_concat.nc', 'r') swh_2050s=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/averages/swh_2050s_concat.nc', 'r') I have then isolated the variables I want to perform the pearson correlation on: hs=swh.variables['hs'] hs_2050s=swh_2050s.variables['hs'] Here is the metadata for those files: print hs int16 hs(time, latitude, longitude) standard_name: significant_height_of_wind_and_swell_waves long_name: significant_wave_height units: m add_offset: 0.0 scale_factor: 0.002 _FillValue: -32767 missing_value: -32767 unlimited dimensions: time current shape = (86400, 350, 227) print hs_2050s int16 hs(time, latitude, longitude) standard_name: significant_height_of_wind_and_swell_waves long_name: significant_wave_height units: m add_offset: 0.0 scale_factor: 0.002 _FillValue: -32767 missing_value: -32767 unlimited dimensions: time current shape = (86400, 350, 227) Then to perform the pearsons correlation: from scipy.stats.stats import pearsonr pearsonr(hs,hs_2050s) I then get a memory error: Traceback (most recent call last): File "", line 1, in File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line 2409, in pearsonr x = np.asarray(x) File "/usr/local/sci/lib/python2.7/site-packages/numpy/core/numeric.py", line 321, in asarray return array(a, dtype, copy=False, order=order) MemoryError This also happens when I try to create numpy arrays from the data. Does anyone know how I can alleviate theses memory errors? Cheers, Jamie From jamiemitchell1604 at gmail.com Mon Mar 24 07:39:47 2014 From: jamiemitchell1604 at gmail.com (Jamie Mitchell) Date: Mon, 24 Mar 2014 04:39:47 -0700 (PDT) Subject: Memory error In-Reply-To: References: Message-ID: <81019e01-c101-4025-af2a-bea0c193230d@googlegroups.com> On Monday, March 24, 2014 11:32:31 AM UTC, Jamie Mitchell wrote: > Hello all, > > > > I'm afraid I am new to all this so bear with me... > > > > I am looking to find the statistical significance between two large netCDF data sets. > > > > Firstly I've loaded the two files into python: > > > > swh=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/averages/swh_control_concat.nc', 'r') > > > > swh_2050s=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/averages/swh_2050s_concat.nc', 'r') > > > > I have then isolated the variables I want to perform the pearson correlation on: > > > > hs=swh.variables['hs'] > > > > hs_2050s=swh_2050s.variables['hs'] > > > > Here is the metadata for those files: > > > > print hs > > > > int16 hs(time, latitude, longitude) > > standard_name: significant_height_of_wind_and_swell_waves > > long_name: significant_wave_height > > units: m > > add_offset: 0.0 > > scale_factor: 0.002 > > _FillValue: -32767 > > missing_value: -32767 > > unlimited dimensions: time > > current shape = (86400, 350, 227) > > > > print hs_2050s > > > > int16 hs(time, latitude, longitude) > > standard_name: significant_height_of_wind_and_swell_waves > > long_name: significant_wave_height > > units: m > > add_offset: 0.0 > > scale_factor: 0.002 > > _FillValue: -32767 > > missing_value: -32767 > > unlimited dimensions: time > > current shape = (86400, 350, 227) > > > > > > Then to perform the pearsons correlation: > > > > from scipy.stats.stats import pearsonr > > > > pearsonr(hs,hs_2050s) > > > > I then get a memory error: > > > > Traceback (most recent call last): > > File "", line 1, in > > File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line 2409, in pearsonr > > x = np.asarray(x) > > File "/usr/local/sci/lib/python2.7/site-packages/numpy/core/numeric.py", line 321, in asarray > > return array(a, dtype, copy=False, order=order) > > MemoryError > > > > This also happens when I try to create numpy arrays from the data. > > > > Does anyone know how I can alleviate theses memory errors? > > > > Cheers, > > > > Jamie Just realised that obviously pearson correlation requires two 1D arrays and mine are 3D, silly mistake! From rosuav at gmail.com Mon Mar 24 07:49:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 22:49:38 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <87bnwv2a5v.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 24, 2014 at 8:55 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> If lambda were going to be deprecated and removed then it already >> would have happened in Python 3, because Guido tried to do precisely >> that. I'm not sure what the reasons were for keeping it in the end >> (according to PEP 3099 it was because nobody suggested a suitable >> replacement), but if he couldn't get rid of it then, he never will. > > You never *need* (Python's) lambda for anything. Inner functions are > more capable and almost always more readable. It doesn't hurt to have > lambda, but I don't find any use for it, either. They're often not more readable. A lot of people seem to equate "verbose" with "readable", possibly by faulty extrapolation from unreadably crunched code with one-letter variables and no line breaks. But which of these is truly more readable? squares = [] for n in range(30): squares.append(n * n) squares = [n * n for n in range(30)] Similarly, there are plenty of cases where a nameless function is MUCH clearer than breaking it out into a separate def and then using the name once. Do you name the function for what it does internally? def get_oneth_element_index(item): return item[1].index L.sort(key=get_oneth_element_index) Or for how you're using it? def keyfunc(item): return item[1].index L.sort(key=keyfunc) Or do you just shortcut the whole thing by inlining it? L.sort(key=lambda item:item[1].index) Hey look, that's weakref.py line 941 right there. (It happens to be the alphabetically last use of lambda in the stdlib. Made a good example, although it'd be more common to have a space after that colon.) ChrisA From davea at davea.name Mon Mar 24 08:22:59 2014 From: davea at davea.name (Dave Angel) Date: Mon, 24 Mar 2014 08:22:59 -0400 (EDT) Subject: gdb python how to output integer for examine memory References: Message-ID: Wesley Wrote in message: > Hi all, > I am trying to use gdb debug python script. > I am using gdb7.7 and python2.7.6, here is my simple test script: > import time > > def next(i): > time.sleep(10) > i = 1 - i > > i = 1 > while True: > next(i) > When this script running, gdb attach to it, and here is snippet: > I cannot help with gdb, but I can point out that you have two separate variables here. Decrement ing the local has no effect on the global value. The preferred way is to return any values from the function that you want to use after it exits. def next(i): time.sleep(10) i = 1 - i return i i = 1 while True: i =next(i) Another possibility, generally a bad idea, is declaring i global in the function. -- DaveA From mauro at gmail.com Mon Mar 24 08:23:34 2014 From: mauro at gmail.com (mauro) Date: Mon, 24 Mar 2014 12:23:34 GMT Subject: Asyncio (or something better) for control of a vacuum system/components. References: Message-ID: Hav you considered the option of a SCADA solution? There are many commercials solutions but also a few open source options such us: http://openscada.org/ http://pvbrowser.de/pvbrowser/index.php You may also ask the vacuum system provider, they should be aware of SCADA solutions supporting their communication protocols From marko at pacujo.net Mon Mar 24 08:36:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 24 Mar 2014 14:36:48 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> Message-ID: <87r45rzsbj.fsf@elektro.pacujo.net> Chris Angelico : > Similarly, there are plenty of cases where a nameless function is MUCH > clearer than breaking it out into a separate def and then using the > name once. Do you name the function for what it does internally? > > def get_oneth_element_index(item): > return item[1].index > L.sort(key=get_oneth_element_index) > > Or for how you're using it? > > def keyfunc(item): > return item[1].index > L.sort(key=keyfunc) > > Or do you just shortcut the whole thing by inlining it? > > L.sort(key=lambda item:item[1].index) I still prefer the "def" variant. It even allows you to clarify the meaning of the tuple slot by using a nicer name. Marko From rosuav at gmail.com Mon Mar 24 08:53:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Mar 2014 23:53:12 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <87r45rzsbj.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <87r45rzsbj.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 24, 2014 at 11:36 PM, Marko Rauhamaa wrote: >> def get_oneth_element_index(item): >> return item[1].index >> L.sort(key=get_oneth_element_index) >> >> Or do you just shortcut the whole thing by inlining it? >> >> L.sort(key=lambda item:item[1].index) > > I still prefer the "def" variant. It even allows you to clarify the > meaning of the tuple slot by using a nicer name. It's the index of element 1. What more do you need to know? Is it actually any help to give that a name? All you gain is a chance for the name, the purpose, and the functionality to come into disagreement. ChrisA From nispray at gmail.com Mon Mar 24 09:37:31 2014 From: nispray at gmail.com (Wesley) Date: Mon, 24 Mar 2014 06:37:31 -0700 (PDT) Subject: gdb python how to output integer for examine memory In-Reply-To: References: Message-ID: Hi Dave, Thanks for your response. It's just a simple script for test:-) My concern is use gdb to monitor variable in memory within python process. For details, in my origin post, just wanna why cannot output interger value from the address. Maybe here is not right for gdb python question..but seems I cannot post question at another gdb group. So, post here, since it's also related to python,in case anyone knowns this. Sorry for that. Wesley ? 2014?3?24????UTC+8??8?22?59??Dave Angel??? > Wesley Wrote in message: > > > Hi all, > > > I am trying to use gdb debug python script. > > > I am using gdb7.7 and python2.7.6, here is my simple test script: > > > import time > > > > > > def next(i): > > > time.sleep(10) > > > i = 1 - i > > > > > > i = 1 > > > while True: > > > next(i) > > > When this script running, gdb attach to it, and here is snippet: > > > > > > > I cannot help with gdb, but I can point out that you have two > > separate variables here. Decrement ing the local has no effect on > > the global value. > > > > The preferred way is to return any values from the function that > > you want to use after it exits. > > def next(i): > > time.sleep(10) > > i = 1 - i > > return i > > > > i = 1 > > while True: > > i =next(i) > > > > Another possibility, generally a bad idea, is declaring i global > > in the function. > > > > -- > > DaveA From steve+comp.lang.python at pearwood.info Mon Mar 24 10:04:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2014 14:04:59 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> Message-ID: <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 24 Mar 2014 22:49:38 +1100, Chris Angelico wrote: > On Mon, Mar 24, 2014 at 8:55 PM, Marko Rauhamaa > wrote: >> You never *need* (Python's) lambda for anything. Inner functions are >> more capable and almost always more readable. It doesn't hurt to have >> lambda, but I don't find any use for it, either. Marko has missed an obvious use: lambda is the *only* solution when you need a function embedded in an expression. You simply cannot do so otherwise. It is truly astonishing that two people here who are such keen supporters of functional programming, Marko and Mark Harris, are so dismissive of lambda, and so forced to write declarative code using def. > They're often not more readable. A lot of people seem to equate > "verbose" with "readable", possibly by faulty extrapolation from > unreadably crunched code with one-letter variables and no line breaks. > But which of these is truly more readable? > > squares = [] > for n in range(30): > squares.append(n * n) > > squares = [n * n for n in range(30)] Readable for whom? List comprehension syntax is often completely obscure to beginners. A beginner would say that the explicit for-loop is more readable. Actually, a *real* beginner, whose main programming experience before Python was Pascal, would probably even say that the first example was an unreadable mess. What's range(30)? What's this ".append" business? What does [] mean? I know this because I was this beginner, once. The first few times I tried reading Python code, I couldn't make head or tail of it. "for" I recognised, because it was the same keyword as Pascal and Hypertalk use. Pretty much everything else might as well have been Bulgarian. This was before the public internet, there was no Google, no tutorials I could look up. It was only after a colleague convinced me that it would be a good language to learn that I bought an actual dead tree book and sat down and learned how to read Python. I think that Python's reputation of being "executable pseudo-code" is sometimes harmful. It fools people into thinking that unless Aunt Tilly can understand a language feature, it's somehow a failure. Hence the arguments by Mark against lambda. http://www.catb.org/jargon/html/A/Aunt-Tillie.html But nobody expects Aunt Tilly to read Scheme or C++ or Go without at least a bit of learning -- or even Esperanto or French or Latin. You still need to learn the syntax and the vocabulary, and have some idea of the basic concepts. The same applies to Python. The learning curve may be more gentle, but there is still a learning curve. And that is perfectly fine. So while I agree with you that, to a moderately fluent Python speaker, not a beginner but not an expert either, the list comprehension is more readable, for a beginner (one who has a basic Python vocab but isn't fluent yet) the for-loop will probably be more readable. > Similarly, there are plenty of cases where a nameless function is MUCH > clearer than breaking it out into a separate def and then using the name > once. Do you name the function for what it does internally? > > def get_oneth_element_index(item): > return item[1].index > L.sort(key=get_oneth_element_index) > > Or for how you're using it? > > def keyfunc(item): > return item[1].index > L.sort(key=keyfunc) Why not both?! Don't forget to make it private so some other piece of code doesn't use it. Or better still, delete it when done! def _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L(item): return item[1].index L.sort(key=_get_oneth_element_index_to_use_as_keyfunc_when_sorting_L) del _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L Four lines of code to do what lambda lets you do in one. And people still insist that lambda is pointless. Maybe they're being paid by the line. > Or do you just shortcut the whole thing by inlining it? > > L.sort(key=lambda item:item[1].index) Exactly. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Mon Mar 24 10:19:20 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 07:19:20 -0700 (PDT) Subject: Question about Source Control In-Reply-To: References: Message-ID: <19d3ddc9-0fb9-476d-a117-e5f174eca85c@googlegroups.com> On Monday, March 17, 2014 6:36:33 PM UTC+5:30, Frank Millman wrote: > Hi all > I know I *should* be using a Source Control Management system, but at > present I am not. I tried to set up Mercurial a couple of years ago, but I > think I set it up wrongly, as I got myself confused and found it more of a > hindrance than a help. Now I am ready to try again, but I want to avoid my > earlier mistakes. > I understand the concept, and I understand the importance, so I do not need > reminding of those. What I would like help with is the basic setup. I could > subscribe to the Mercurial mailing list and ask there, but I am hoping for a > kick-start here. Here is my setup. > All my source code resides on an old Linux server, which I switch on in the > morning and switch off at night, but otherwise hardly ever look at. It uses > 'samba' to allow sharing with Windows, and 'nfs' to allow sharing with other > Linux machines. > I need to test my program on Windows and on Linux, so I run it from both at > various times. On Windows I have a 'mapped drive' pointing to the source > code. On Linux I use a third machine, running a recent Fedora, using nfs to > mount a directory pointing to the source code. Obviously each machine has > its own version of Python installed. > I do my development on the Windows machine. I use TextPad, a simple text > editor, which works fine for my purposes. It uses the mapped drive to point > to the source code. > So where should I install the SCM, and how should I set it up so that I can > access the latest version from any machine? > Any hints will be appreciated. Seen this?? Yeah may not apply directly to your use-case buts seems worth a read https://www.kernel.org/pub/software/scm/git/docs/gitworkflows.html [At command line $ git help -w workflows will give you the same ] From breamoreboy at yahoo.co.uk Mon Mar 24 10:21:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 14:21:02 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <87r45rzsbj.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <87r45rzsbj.fsf@elektro.pacujo.net> Message-ID: On 24/03/2014 12:36, Marko Rauhamaa wrote: > Chris Angelico : > >> Similarly, there are plenty of cases where a nameless function is MUCH >> clearer than breaking it out into a separate def and then using the >> name once. Do you name the function for what it does internally? >> >> def get_oneth_element_index(item): >> return item[1].index >> L.sort(key=get_oneth_element_index) >> >> Or for how you're using it? >> >> def keyfunc(item): >> return item[1].index >> L.sort(key=keyfunc) >> >> Or do you just shortcut the whole thing by inlining it? >> >> L.sort(key=lambda item:item[1].index) > > I still prefer the "def" variant. It even allows you to clarify the > meaning of the tuple slot by using a nicer name. > Each to their own. Here give me the lambda version any day of the week. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Mon Mar 24 10:39:51 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2014 14:39:51 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <87r45rzsbj.fsf@elektro.pacujo.net> Message-ID: <533043b7$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 24 Mar 2014 23:53:12 +1100, Chris Angelico wrote: > On Mon, Mar 24, 2014 at 11:36 PM, Marko Rauhamaa > wrote: >>> def get_oneth_element_index(item): >>> return item[1].index >>> L.sort(key=get_oneth_element_index) >>> >>> Or do you just shortcut the whole thing by inlining it? >>> >>> L.sort(key=lambda item:item[1].index) >> >> I still prefer the "def" variant. It even allows you to clarify the >> meaning of the tuple slot by using a nicer name. > > It's the index of element 1. What more do you need to know? Is it > actually any help to give that a name? All you gain is a chance for the > name, the purpose, and the functionality to come into disagreement. # Magic constants are wicked. Never use a constant without naming it. ELEMENT_TO_USE_FOR_INDEXING_WHEN_SORTING_L = 1 # # key func used when sorting L, returns item's 1th elem index method # # # _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L # # Steven D'Aprano # 2014-03-25 # 2014-03-25 # 1 # item to be sorted # index method of the oneth element # NameError # FIXME can this fail any other way? def _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L(item): """Private key function for sorting list L. Returns the index method of element 1 of the given item. Example of use: >>> item = (None, '') >>> _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L(item) Relies on global constant ELEMENT_TO_USE_FOR_INDEXING_WHEN_SORTING_L. May raise NameError if that constant is missing. Warning: do not use this for anything else. """ return item[ELEMENT_TO_USE_FOR_INDEXING_WHEN_SORTING_L].index L.sort(key=_get_oneth_element_index_to_use_as_keyfunc_when_sorting_L) del _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L # Better to be safe than sorry. del ELEMENT_TO_USE_FOR_INDEXING_WHEN_SORTING_L Definitely being paid by the line :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From prabir.kr.sarkar at gmail.com Mon Mar 24 11:15:08 2014 From: prabir.kr.sarkar at gmail.com (Prabir Kr Sarkar) Date: Mon, 24 Mar 2014 20:45:08 +0530 Subject: TypeError in HMAC module. Message-ID: Hi, I am trying to create a hashed message for authentication for a REST API call. I have got the key from a keyring as :- key = keyring.get_password('AWS_keyring','username') & calculating the signature as :- signature = hmac(key, message.encode('UTF-8'), hashlib.sha1).digest().encode('base64')[:-1] But, while running the script I get the following errors :- File "/usr/lib64/python2.6/hmac.py", line 133, in new return HMAC(key, msg, digestmod) File "/usr/lib64/python2.6/hmac.py", line 72, in __init__ * self.outer.update(key.translate(trans_5C))* *TypeError: character mapping must return integer, None or unicode* My python version is :- # python -V Python 2.6.9 Can someone please help me as to how I can resolve this issue. Thanks in advance. -- *Thanks and Regards* *Prabir Sarkar* -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Mar 24 11:22:50 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 15:22:50 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533043b7$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <87r45rzsbj.fsf@elektro.pacujo.net> <533043b7$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/03/2014 14:39, Steven D'Aprano wrote: > On Mon, 24 Mar 2014 23:53:12 +1100, Chris Angelico wrote: > >> On Mon, Mar 24, 2014 at 11:36 PM, Marko Rauhamaa >> wrote: >>>> def get_oneth_element_index(item): >>>> return item[1].index >>>> L.sort(key=get_oneth_element_index) >>>> >>>> Or do you just shortcut the whole thing by inlining it? >>>> >>>> L.sort(key=lambda item:item[1].index) >>> >>> I still prefer the "def" variant. It even allows you to clarify the >>> meaning of the tuple slot by using a nicer name. >> >> It's the index of element 1. What more do you need to know? Is it >> actually any help to give that a name? All you gain is a chance for the >> name, the purpose, and the functionality to come into disagreement. > > > > # Magic constants are wicked. Never use a constant without naming it. > ELEMENT_TO_USE_FOR_INDEXING_WHEN_SORTING_L = 1 > > # > # key func used when sorting L, returns item's 1th elem index method > # > # > # _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L > # > # Steven D'Aprano > # 2014-03-25 > # 2014-03-25 > # 1 > # item to be sorted > # index method of the oneth element > # NameError # FIXME can this fail any other way? > def _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L(item): > """Private key function for sorting list L. > > Returns the index method of element 1 of the given item. > > Example of use: > > >>> item = (None, '') > >>> _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L(item) > > > Relies on global constant ELEMENT_TO_USE_FOR_INDEXING_WHEN_SORTING_L. > May raise NameError if that constant is missing. > > Warning: do not use this for anything else. > """ > return item[ELEMENT_TO_USE_FOR_INDEXING_WHEN_SORTING_L].index > > L.sort(key=_get_oneth_element_index_to_use_as_keyfunc_when_sorting_L) > del _get_oneth_element_index_to_use_as_keyfunc_when_sorting_L > # Better to be safe than sorry. > del ELEMENT_TO_USE_FOR_INDEXING_WHEN_SORTING_L > > Definitely being paid by the line :-) > One of the finest examples of extracting the urine I've ever read. Please keep up the good work. Ah but wait, down voted on the grounds that there are no unit tests and, far more importantly, it doesn't fit on one line (unless you use gg that is). There is also no proof that it's been committed to your source control system after going through its code review. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rustompmody at gmail.com Mon Mar 24 12:00:54 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 09:00:54 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7beccf79-0036-4a90-8bc2-2afae28c1213@googlegroups.com> On Monday, March 24, 2014 7:34:59 PM UTC+5:30, Steven D'Aprano wrote: > On Mon, 24 Mar 2014 22:49:38 +1100, Chris Angelico wrote: > > wrote: > >> You never *need* (Python's) lambda for anything. Inner functions are > >> more capable and almost always more readable. It doesn't hurt to have > >> lambda, but I don't find any use for it, either. > Marko has missed an obvious use: lambda is the *only* solution when you > need a function embedded in an expression. You simply cannot do so > otherwise. It is truly astonishing that two people here who are such keen > supporters of functional programming, Marko and Mark Harris, are so > dismissive of lambda, and so forced to write declarative code using def. > > They're often not more readable. A lot of people seem to equate > > "verbose" with "readable", possibly by faulty extrapolation from > > unreadably crunched code with one-letter variables and no line breaks. > > But which of these is truly more readable? > > squares = [] > > for n in range(30): > > squares.append(n * n) > > squares = [n * n for n in range(30)] > Readable for whom? > List comprehension syntax is often completely obscure to beginners. A > beginner would say that the explicit for-loop is more readable. > Actually, a *real* beginner, whose main programming experience before > Python was Pascal, would probably even say that the first example was an > unreadable mess. What's range(30)? What's this ".append" business? What > does [] mean? I know this because I was this beginner, once. The first > few times I tried reading Python code, I couldn't make head or tail of > it. "for" I recognised, because it was the same keyword as Pascal and > Hypertalk use. Pretty much everything else might as well have been > Bulgarian. > This was before the public internet, there was no Google, no tutorials I > could look up. It was only after a colleague convinced me that it would > be a good language to learn that I bought an actual dead tree book and > sat down and learned how to read Python. > I think that Python's reputation of being "executable pseudo-code" is > sometimes harmful. It fools people into thinking that unless Aunt Tilly > can understand a language feature, it's somehow a failure. Hence the > arguments by Mark against lambda. > http://www.catb.org/jargon/html/A/Aunt-Tillie.html > But nobody expects Aunt Tilly to read Scheme or C++ or Go without at > least a bit of learning -- or even Esperanto or French or Latin. You > still need to learn the syntax and the vocabulary, and have some idea of > the basic concepts. The same applies to Python. The learning curve may be > more gentle, but there is still a learning curve. And that is perfectly > fine. Ok so far > So while I agree with you that, to a moderately fluent Python speaker, > not a beginner but not an expert either, the list comprehension is more > readable, for a beginner (one who has a basic Python vocab but isn't > fluent yet) the for-loop will probably be more readable. And now I wonder... The case you are wanting to make and the case you are ending up making seem to be opposite: If it is so as you say that for "the beginner (one who has a basic Python vocab but isn't fluent yet)" the for-loop is more readable than the for-in-compr it then suggests that those more experienced taking/helping the beginners at 0 to the stage of "basic vocab-but-not-yet fluent" are choosing a sub-optimal route. Remember that you started by reminding that for an absolute beginner, everything is 'Bulgarian' not just list comprehensions. Then how come some things become accessible faster than others? It may be that those things are actually easier (in some objective sense) But it may also reveal a prejudice of the teachers. As for the other argument -- python lambda is BAD -- Ive currently run out of pepper for sprinkling on these flames :-) I'll just make a few points: 1. Miranda the predecessor of Haskell had no lambda. Local defs + curried convention + operator sections was considered more than sufficient for functional programming 2. Lisp was the originator of lambda (in programming languages) and it screwed up the semantics so badly that a. It had to be corrected at high cost 25 years later -- aka scheme and common lisp b. Some doyens of functional programming have suggested that lisp is a major setback for the acceptance of functional programming, eg http://www.cs.kent.ac.uk/people/staff/dat/miranda/wadler87.pdf 3. One basic tenet of ? calculus foo = ? x . exp is equivalent to the more traditional foo(x) = exp is a little uh-uh in haskell thanks to the notorious monomorphism restriction http://www.haskell.org/haskellwiki/Monomorphism_restriction So if FP = ? calculus, Haskell does not quite make it!! From peter.byaruhanga at utamu.ac.ug Mon Mar 24 12:20:26 2014 From: peter.byaruhanga at utamu.ac.ug (mikie) Date: Mon, 24 Mar 2014 09:20:26 -0700 (PDT) Subject: String modifying error, trying to delete data in string Message-ID: Here is some code: import socket,sys s=socket.socket() port=int(sys.argv[1]) s.bind(("127.0.0.1",port)) s.listen(2) cls,addr=s.accept() data=cls.recv(1024) f=data.pop("Proxy-Connection") cls.close() Im trying to delete some headers in the request but get an error saying: 'str' object has no attribute 'pop' How can I modify data received from the client? From breamoreboy at yahoo.co.uk Mon Mar 24 12:31:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 16:31:51 +0000 Subject: String modifying error, trying to delete data in string In-Reply-To: References: Message-ID: On 24/03/2014 16:20, mikie wrote: > Here is some code: > import socket,sys > > s=socket.socket() > port=int(sys.argv[1]) > s.bind(("127.0.0.1",port)) > s.listen(2) > cls,addr=s.accept() > > data=cls.recv(1024) > f=data.pop("Proxy-Connection") > cls.close() > > Im trying to delete some headers in the request but get an error saying: > 'str' object has no attribute 'pop' > > How can I modify data received from the client? > Strings are immutable so you'll need string methods to manipulate your data see http://docs.python.org/3/library/stdtypes.html#text-sequence-type-str -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From steve+comp.lang.python at pearwood.info Mon Mar 24 13:09:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2014 17:09:11 GMT Subject: String modifying error, trying to delete data in string References: Message-ID: <533066b7$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 24 Mar 2014 09:20:26 -0700, mikie wrote: > Im trying to delete some headers in the request but get an error saying: > 'str' object has no attribute 'pop' What sort of object is data? What do you expect it to be, and what it is actually? Given that you are calling data.pop("Proxy-Connection"), that suggests to me that you think data is a dict. The error message given tells you that data is a str. > How can I modify data received from the client? The same as any string: make a copy with whatever modifications you want. Strings have a replace method; you can use the re module to use regexes; you can slice them with some_string[start:end] syntax, etc. But it looks to me like you might be better off using a higher-level protocol rather than using socket. What sort of data are you expecting back? -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Mon Mar 24 13:24:00 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 24 Mar 2014 11:24:00 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <87bnwv2a5v.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 24, 2014 at 3:55 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> If lambda were going to be deprecated and removed then it already >> would have happened in Python 3, because Guido tried to do precisely >> that. I'm not sure what the reasons were for keeping it in the end >> (according to PEP 3099 it was because nobody suggested a suitable >> replacement), but if he couldn't get rid of it then, he never will. > > You never *need* (Python's) lambda for anything. Inner functions are > more capable and almost always more readable. It doesn't hurt to have > lambda, but I don't find any use for it, either. So what? One might say the same thing about comprehensions -- loops are more capable and almost always more readable. From vincent at vincentdavis.net Mon Mar 24 13:50:07 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 24 Mar 2014 11:50:07 -0600 Subject: Merge/append CSV files with different headers Message-ID: I have several csv file I need to append (vertically). They have different but overlapping headers. For example; file1 headers ['a', 'b', 'c'] file2 headers ['d', 'e'] file3 headers ['c', 'd'] Is there a better way than this import csv def merge_csv(fileList, newFileName): allHeaders = set([]) for afile in fileList: with open(afile, 'rb') as csvfilesin: eachheader = csv.reader(csvfilesin, delimiter=',').next() allHeaders.update(eachheader) print(allHeaders) with open(newFileName, 'wb') as csvfileout: outfile = csv.DictWriter(csvfileout, allHeaders) outfile.writeheader() for afile in fileList: print('***'+afile) with open(afile, 'rb') as csvfilesin: rows = csv.DictReader(csvfilesin, delimiter=',') for r in rows: print(allHeaders.issuperset(r.keys())) outfile.writerow(r) Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Mar 24 14:24:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 18:24:10 +0000 Subject: Merge/append CSV files with different headers In-Reply-To: References: Message-ID: On 24/03/2014 17:50, Vincent Davis wrote: > I have several csv file I need to append (vertically). They have > different but overlapping headers. For example; > file1 headers ['a', 'b', 'c'] > file2 headers ['d', 'e'] > file3 headers ['c', 'd'] > > Is there a better way than this > import csv > def merge_csv(fileList, newFileName): > allHeaders = set([]) > for afile in fileList: > with open(afile, 'rb') as csvfilesin: > eachheader = csv.reader(csvfilesin, delimiter=',').next() > allHeaders.update(eachheader) > print(allHeaders) > with open(newFileName, 'wb') as csvfileout: > outfile = csv.DictWriter(csvfileout, allHeaders) > outfile.writeheader() > for afile in fileList: > print('***'+afile) > with open(afile, 'rb') as csvfilesin: > rows = csv.DictReader(csvfilesin, delimiter=',') > for r in rows: > print(allHeaders.issuperset(r.keys())) > outfile.writerow(r) > > Vincent Davis > I haven't looked too hard at your code but guess you could simplify it by using the fieldnames parameter to the DictReader class or making use of the Sniffer class. See http://docs.python.org/3/library/csv.html#module-csv -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Mon Mar 24 14:58:16 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 13:58:16 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/24/14 4:58 AM, Mark Lawrence wrote: > Where do you get reduce from if it's not in the standard library? That was "a" proposal for 3000. Its there, but its not on the built-ins; ie., you have to import it. The confusion: why reduce, why not filter, nor map? {rhetorical} > As for lambda I've no real interest in it, other than when copying examples > where it's used to (say) provide a key function. > This is one of my main points to Steven. In my experience "most" people do not intend to use lambda for anything; they are trying to sort this or that and don't quite know how to get the key right and some helpful somebody gives them a key=lambda yadda yadda . They use it, and it works, but they are scratching their head saying to themselves, "what it that, how does it work, how can I understand it and on and on". That is what we mean by confusing. Or another really great example is this thread. Somebody asks about a language feature and somebody else helpfully answers the question by providing them with a similar lambda!! Its the programmer's equivalent of explanation by reference to a more complicated analogy; which leaves the OP left with, "Thanks for all the responses". marcus PS You are absolutely right, all the expanding double spaces become very annoying when viewed on Thunderbird; it is exasperating, genuinely. From rosuav at gmail.com Mon Mar 24 15:05:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 06:05:55 +1100 Subject: TypeError in HMAC module. In-Reply-To: References: Message-ID: On Tue, Mar 25, 2014 at 2:15 AM, Prabir Kr Sarkar wrote: > Hi, > I am trying to create a hashed message for authentication for a REST API > call. I have got the key from a keyring as :- > > key = keyring.get_password('AWS_keyring','username') > > & calculating the signature as :- > signature = hmac(key, message.encode('UTF-8'), > hashlib.sha1).digest().encode('base64')[:-1] I can't "import keyring", so either that's a module that isn't in the Python standard library, or "keyring" is some object you've instantiated. My crystal ball says this might be something to do with Amazon Web Services, but it's hard to be sure. Can you please help us out here by telling us all the dependencies of your code, and also showing us a complete runnable program? http://www.sscce.org/ Thanks! ChrisA From rosuav at gmail.com Mon Mar 24 15:12:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 06:12:47 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 1:04 AM, Steven D'Aprano wrote: >> But which of these is truly more readable? >> >> squares = [] >> for n in range(30): >> squares.append(n * n) >> >> squares = [n * n for n in range(30)] > > Readable for whom? > > List comprehension syntax is often completely obscure to beginners. A > beginner would say that the explicit for-loop is more readable. > > Actually, a *real* beginner, whose main programming experience before > Python was Pascal, would probably even say that the first example was an > unreadable mess. What's range(30)? What's this ".append" business? What > does [] mean? I know this because I was this beginner, once. The first > few times I tried reading Python code, I couldn't make head or tail of > it. "for" I recognised, because it was the same keyword as Pascal and > Hypertalk use. Pretty much everything else might as well have been > Bulgarian. Actually, that's a very good point. Python's for loop is more often called a foreach loop in other languages, and Python completely lacks any concept of a "classic" iteration-over-integer for loop. That is a point of confusion. However, that's going to come up on both branches, so it's not really a mark against either. Incidentally, I've often modified my loop counter, in C or REXX or any other language. About the only situation where I actually miss it in Python, though, is iterating over a list and mutating the list on the way through; and even that can often be done in other ways (maybe a list comp, filtering out some of the elements?). It's amazing how something can be so utterly fundamental (I mean, come ON! Who can imagine a language with no equivalent of the basic "do i=1 to 10" (REXX) or "for (int i=0;i<10;++i)" (C++) loop???) and yet so dispensable. ChrisA From breamoreboy at yahoo.co.uk Mon Mar 24 15:13:13 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 24 Mar 2014 19:13:13 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/03/2014 18:58, Mark H Harris wrote: > On 3/24/14 4:58 AM, Mark Lawrence wrote: >> Where do you get reduce from if it's not in the standard library? > > That was "a" proposal for 3000. Its there, but its not on the > built-ins; ie., you have to import it. The confusion: why reduce, why > not filter, nor map? {rhetorical} So it is in the standard library then. And I'm not confused, seeing this must have been decided years ago as Python 3 was released some five years ago. > >> As for lambda I've no real interest in it, other than when copying >> examples >> where it's used to (say) provide a key function. >> > > This is one of my main points to Steven. In my experience "most" people > do not intend to use lambda for anything; they are trying to sort this > or that and don't quite know how to get the key right and some helpful > somebody gives them a key=lambda yadda yadda . They use it, and it > works, but they are scratching their head saying to themselves, "what it > that, how does it work, how can I understand it and on and on". More fool them, I write Python as I let it take away the head scratching, not add to it. If I wanted to start head scratching maybe I'd go and investigate what line 247 of gcmodule.c does, but funnily enough I've never been there, and don't intend starting now. > > That is what we mean by confusing. Or another really great example is > this thread. Somebody asks about a language feature and somebody else > helpfully answers the question by providing them with a similar lambda!! One of the joys of this list from my POV, YMMV. > > Its the programmer's equivalent of explanation by reference to a more > complicated analogy; which leaves the OP left with, "Thanks for all the > responses". > > marcus > > PS You are absolutely right, all the expanding double spaces become > very annoying when viewed on Thunderbird; it is exasperating, genuinely. > Yep, but like I said the situation has improved, partly thanks to the guys who improved the words on the wiki showing how to successfuly use gg. Thanks fellas :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From ian.g.kelly at gmail.com Mon Mar 24 15:12:54 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 24 Mar 2014 13:12:54 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 24, 2014 at 12:58 PM, Mark H Harris wrote: > That is what we mean by confusing. Or another really great example is this > thread. Somebody asks about a language feature and somebody else helpfully > answers the question by providing them with a similar lambda!! That is not in fact how the topic of lambda arose in this thread. Rustom Mody brought up the binding behavior in a tangent specifically to complain about it, and that was the first mention of lambda in the thread. From rosuav at gmail.com Mon Mar 24 15:22:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 06:22:28 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 5:58 AM, Mark H Harris wrote: > Its there, but its not on the built-ins; ie., you have to import it. The > confusion: why reduce, why not filter, nor map? {rhetorical} In other languages with those three, and without list/array comprehensions, I've used filter occasionally and map reasonably often, but I don't remember the last time I used reduce. Actually, Pike has special syntax that can take the place of map sometimes, so I might use filter more often than map in Pike code, because these don't need explicit map calls: //Suppose that clients is an array of connected clients on some server clients->sockets->write("System message: blah blah blah\n"); Indexing an array (the -> is like Python's . as Pike's . is resolved at compile time) produces an array, effectively mapping the elements through "lambda x: x->sockets" and ditto for "->write". Calling an array calls all the non-empty elements in it, with the same argument(s), and produces an array of return values. (In this case, I don't care about the return values, which will simply be the number of bytes written to each socket. If there's a problem, it'll throw an exception.) Huh. Even with that, and the [*] automap syntax, and such, I still use map far more often than filter... and filter orders of magnitude more often than reduce. Aside: You'll often hear people talking about "map-reduce" with big data. Python supports that. Look! >>> map.__reduce__ Oh wait, that's nothing to do with reduce()... *ducks for cover* ChrisA From ian.g.kelly at gmail.com Mon Mar 24 15:42:03 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 24 Mar 2014 13:42:03 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 24, 2014 at 1:12 PM, Chris Angelico wrote: > Incidentally, I've often modified my loop counter, in C or REXX or any > other language. About the only situation where I actually miss it in > Python, though, is iterating over a list and mutating the list on the > way through; and even that can often be done in other ways (maybe a > list comp, filtering out some of the elements?). It's amazing how > something can be so utterly fundamental (I mean, come ON! Who can > imagine a language with no equivalent of the basic "do i=1 to 10" > (REXX) or "for (int i=0;i<10;++i)" (C++) loop???) and yet so > dispensable. I'm not sure "fundamental" is the right word. A for loop is just a while loop with some syntactic sugar. For that matter, a while loop is just a structured goto... From rosuav at gmail.com Mon Mar 24 15:44:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 06:44:39 +1100 Subject: Merge/append CSV files with different headers In-Reply-To: References: Message-ID: On Tue, Mar 25, 2014 at 4:50 AM, Vincent Davis wrote: > I have several csv file I need to append (vertically). They have different > but overlapping headers. For example; > file1 headers ['a', 'b', 'c'] > file2 headers ['d', 'e'] > file3 headers ['c', 'd'] > > Is there a better way than this Summary of your code: 1) Build up a set of all headers used, by opening each file and reading the headers. 2) Go through each file a second time and write them out. That seems like the best approach, broadly. You might be able to improve it a bit (it might be tidier to open each file once, but since you're using two different CSV readers, it'd probably not be), but by and large, I'd say you have the right technique. Your processing time here is going to be dominated by the actual work of copying. The only thing you might want to consider is order. The headers all have a set order to them, and it'd make sense to have the output come out as ['a', 'b', 'c', 'd', 'e'] - the first three from the first file, then adding in everything from subsequent files in the order they were found. Could be done easily enough by using 'in' and .append() on a list, rather than using a set. But if that doesn't matter to you, or if something simple like "sort the headers alphabetically" will do, then I think you basically have what you want. ChrisA From rosuav at gmail.com Mon Mar 24 15:45:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 06:45:53 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 6:13 AM, Mark Lawrence wrote: >> That was "a" proposal for 3000. Its there, but its not on the >> built-ins; ie., you have to import it. The confusion: why reduce, why >> not filter, nor map? {rhetorical} > > > So it is in the standard library then. And I'm not confused, seeing this > must have been decided years ago as Python 3 was released some five years > ago. Terminology issue, is all. It's not in the builtins, but it is in the standard library. ChrisA From harrismh777 at gmail.com Mon Mar 24 15:47:11 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 14:47:11 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/24/14 4:49 AM, Steven D'Aprano wrote: > There's no doubt that lambda is less-often useful than is the def > statement. But not only is it still useful, but there is a continual > stream of people asking for Python to make it *more useful* by allowing > the body of a lambda to be a full block, not just a single statement. > Guido has stated (although I cannot remember where, so cannot paste a > link) that he accepts that in principle, so long as somebody comes up > with acceptable syntax. Now, this will seem strange to you, but if lambda were expanded to include an entire block, well now, I would know two things: 1) python has commitment to lambda and 2) lambda would become WAY more useful... ie., the only way to have a "block expression" embedded in an expression ! I'd vote for that. But as someone else noted, inner functions work as well (now) and are really more readable, so ... > It's used in calendar, cgitb, configparser, difflib, decimal, functools, > inspect, os, pydoc and others. Python is a programming language aimed at > programmers, not a toy. It should include tools that programmers use, > like threads, closures, first-class functions. And lambda. This is a valid point (its used a couple of hundred times). It could be replaced in probably of week of constant programming effort. Neither here nor there, because nobody at this point is demanding it. >> Lambda is a problem of confusion for scientists and other >> mathematicians (amateur and otherwise) {snip} >{snip} > But nor should the confusion of somebody > who doesn't know the language count for much. This is the main disagreement between the two of us on this topic. It should count for TONS; whole metric TONs. Because someone who understands python primarily, and after five years of coding (say me) somebody tells (me) to use lambda in a key clause so that my sort will work, or work better, or work "their" way; and I have no idea why I need this nameless function (after I find out that "that" is what it is!) Its confusing, and please contrast between complicated. I don't mind complicated, or extensive, or even hard, but when something is needlessly confusing, then why? > Python's ints don't work exactly the same as ints do in some other > languages, nor do Python's strings, nor is Python's object model > precisely the same as that of some other languages. I think that it would > be a ridiculous idea to discard int, str and the entire object system > just because some people are surprised that Python doesn't behave exactly > like some other language. I don't think lambda is any different. Your logic is faulty here. Conceptually python's lambda doesn't work as expected, from contexts that define lambda and where lambda in functional programming is VERY important. For one thing, why would we want to "spell out" the word "lambda". ( \x y -> x + y ) a b ) If we're going to use lambda, then use it. > Other languages -- not even Lisp -- don't get to be the sole decider as > to what counts as an anonymous function. Python's lambda may be limited, > but it is a perfectly fine lambda for what it is intended to do. Is that the same as George W. Bush's "decider" ? I agree, and so does the link I referenced, for what it was designed to do, its powerful; esp if one needs to embed a function in an expression; that is what lambda is for. >> Its also confusing to sophisticated users of all >> stripes who may not be aware of "lambda" at all. > > If they're not aware of lambda, how are they confused by it? See above. They are recommended its use (maybe on this list) and they just don't get it; because its unnecessarily confusing. > No, not really. I don't understand who your intended audience for Python > is. If I were to try to guess, I suspect that you want to dumb Python > down until it is like Dartmouth BASIC circa 1980 except without the line > numbers and with a slightly different syntax. Perhaps I'm wrong, I > certainly hope I'm wrong, but that's the impression I got from your > comments on the python-ideas list. Actually it was circa 1964. Actually, it was precisely 1964 (I was there). No, I'm not advocating for dumb-down simplicity. Aristotle said that virtue is found at the mean. Either end of the spectrum is a problem (overly complicated, towards overly simplified) those end-points we must flee like the black plague. Normal people with reasonable training (college education) should be able to use python easily without confusion and without a computer science degree. Programming should be a liberal art available to everyone in the set of all "normal" educated people. Some developers (themselves perhaps with degrees Ph.D. in mathematics or computer science) forget about the fact that "normal" educated people want to leverage their computer (maybe with python) for problem solution without having to become a professional computer scientist. I am advocating for those people. > You want to remove lambda because it causes confusion. Okay, for the sake > of the argument I will agree that lambda is confusing. Do you know what > else is confusing? I don't want to remove anything at this point. I am only suggesting that over time the python community might evaluate whether the lambda (map, filter, reduce) thing is a language benefit. If so, manet in aeternum. Elif, deprecate it and over time phase it out completely. Its a community decision of course, and I'm NOT demanding anything. > Threading is confusing. So is multiprocessing. So are databases. Unicode > is confusing. First-class functions are confusing. Recursion is > confusing. Closures are confusing. List comprehensions are confusing. > What the hell are trampolines? I'm certainly confused by them. Argument by analogy almost never works. Please don't confuse my word "confusing" with your interpretation "complicated". Actually, I do not find any of those above mentioned as "confusing," while I do admit they are complicated--even extremely complicated. An intelligent person educated in the liberal arts should be able to sit down over time and pick-up the concepts in a new area--without--being confused by the material or presentation. Lambda is confusing NOT because its complicated (because its not) but because 1) it does not work like other lambda concepts in functional programming, and 2) because the syntax does not lend itself easily to immediate interpretation (by normal people) nor does it lend itself easily to explanation even in the best effort. > If we remove lambda because it is confusing, shouldn't we also remove all > these other confusing things? Where shall we stop? No. see above. > Should we stop only when Python is a confusion-free, utterly useless toy > language? I don't think so. Or should we stop *before* going down that > path? You want to single out lambda. I don't think we should. No. see above. > I didn't say that Python can be used as a functional language. I said you > can write functional code in Python. And that is so obviously true that I > cannot believe that you are disputing it. I'm not disputing that, not in the least. But advertising that python can be used to write functional code is misleading (particularly when lambda is included ;map,filter, reduce) because those who KNOW functional programming are going to be either 1) confused, or more likely, 2) disappointed. Yes, I can make a nameless function (expression) and pass it to another function as an argument. True enough, and powerful enough, but very confusing when the other aspects of functional programming with lambda do not hold precisely. Ok, functional with caveats. >> In fact, I have gone out of my way to NOT use >> lambda because I am fully aware that the BDFL hates it. > > In other words, you have had situations where you *could have* used > lambda, perhaps even *should have* used lambda, but you intentionally > went *out of your way* (i.e. made the job harder than it needed to be) to > avoid it, just to slavishly ape the BDFL. No, no, no, not at all. I went out-of-my-way to understand how inner functions could do everything lambda does. I use inner functions, not lambda, and everything works well; not to ape the BDFL, but because it does not appear that lambda is a stable concept, and because I want other people "in the normal" category to be able to support or at least read my code. > Thank you for just proving my point for me. Your code would have been > better, or at least easier, with lambda. Removing it would make the > language worse, not better. No. see above. > lambda was designed to allow you to create anonymous functions > in an expression, not as a statement. There is *no other way* to do that > in Python. Yes, and I agree, and if that were *necessary* we wouldn't be having this conversation. The point is that there is *no* reason that you must code your script that way. > Would you like to discard def as well? No? Why not? I am not advocating discarding anything. I am suggesting that lambda is not necessary and might be deprecated without too much trouble; if the community sees fit. That is all. Since the name-space and arguably "def" itself is perhaps the most powerful aspect of python generally (extensibility) than of course the answer to your question is obvious, and discussing it would be silly. def is fine, lambda not so much. BUT I'm not demanding anyone discard it at the moment. Try to remember Aristotle's mean. marcus From rosuav at gmail.com Mon Mar 24 15:57:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 06:57:19 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 6:42 AM, Ian Kelly wrote: > On Mon, Mar 24, 2014 at 1:12 PM, Chris Angelico wrote: >> Incidentally, I've often modified my loop counter, in C or REXX or any >> other language. About the only situation where I actually miss it in >> Python, though, is iterating over a list and mutating the list on the >> way through; and even that can often be done in other ways (maybe a >> list comp, filtering out some of the elements?). It's amazing how >> something can be so utterly fundamental (I mean, come ON! Who can >> imagine a language with no equivalent of the basic "do i=1 to 10" >> (REXX) or "for (int i=0;i<10;++i)" (C++) loop???) and yet so >> dispensable. > > I'm not sure "fundamental" is the right word. A for loop is just a > while loop with some syntactic sugar. For that matter, a while loop > is just a structured goto... Of course, and function calls are just stack operations and gotos too. That's not what makes it fundamental - I'm talking at a source code level. Can you imagine a high level language without a simple notation for variable assignment? Certainly not. [1] Variable assignment, name binding, whatever you call it, is fundamental. Some kind of structured looping is also pretty critical; you don't see languages that force you to use bare goto everywhere and call themselves "high level". [2] Every high level language also needs some way to iterate over numbers. Most of them provide it as an intrinsic; Python happens to do it as a foreach over an easily-constructed iterable. ChrisA [1] DeScribe Macro Language would borderline-fail this test if I called it a HLL. It has "SET something TO somevalue". But DML is about on the level of Python's "dis.dis" output - assembly language for a byte-code interpreter. [2] DML passes this test, even. It has a block IF/ELSE/END IF statement, and a REPEAT/END REPEAT for looping, with the loop condition being provided by a statement "EXIT WHEN condition" that's like Python's "if condition: break". Mind you, it also provides language-level support for message boxes, including prompt boxes (ask the user to provide a string or integer), so it's a bit of an odd duck. From newville at cars.uchicago.edu Mon Mar 24 16:24:34 2014 From: newville at cars.uchicago.edu (Matt Newville) Date: Mon, 24 Mar 2014 15:24:34 -0500 Subject: advice on sub-classing multiprocessing.Process and multiprocessing.BaseManager Message-ID: I'm maintaining a python interface to a C library for a distributed control system (EPICS, sort of a SCADA system) that does a large amount of relatively light-weight network I/O. In order to keep many connections open and responsive, and to provide a simple interface, the python library keeps a global store of connection state. This works well for single processes and threads, but not so well for multiprocessing, where the global state causes trouble. The issue is not too difficult to work around (ie, completely clear any such global cache and insist that new connections be established in each process), but easy to forget. To make this easier, I have a function to clear the global cache, def clear_my_cache(): # empty global variables caching network connections return and then subclass of multiprocessing.Process like: class MyProcess(multiprocessing.Process): def __init__(self, **kws): multiprocessing.Process.__init__(self, **kws) def run(self): clear_my_cache() mp.Process.run(self) This works fine. I can subclass multiprocessing.pool.Pool too, as it uses Process as a class variable (removing doc strings): class Pool(object): Process = Process def __init__(self, processes=None, initializer=None, initargs=(), maxtasksperchild=None): and then uses self.Process in its Pool._repopulate_pool(). That makes subclassing Pool is as easy as (removing doc strings): class MyPool(multiprocssing.pool.Pool): def __init__(self, **kws): self.Process = MyProcess mp_pool.Pool.__init__(self, **kws) I'm very pleased to need so little code here! But, I run into trouble when I try to subclass any of the Managers(). It looks like I would have to make a nearly-identical copy of ~30 lines of BaseManager.start() as it calls multiprocessing.Process() to create processes there. In addition, it looks like subclassing multiprocessing.managers.SyncManager would mean making a near-identical copy of a similar amount of code. I'd be willing to do this, but it seems like a bad idea -- I much prefer overwriting self.Process as for Pool. Does anyone have any advice for the best approach here? Should, like Pool, BaseManager also use a class variable (Process = Process)? Thanks in advance for any advice. --Matt From eneskristo at gmail.com Mon Mar 24 16:30:18 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Mon, 24 Mar 2014 13:30:18 -0700 (PDT) Subject: How to clear all content in a Tk() Message-ID: <0ed94669-6c1e-4e2f-b79d-33bed8cdde15@googlegroups.com> I have this program, and since I want to change stuff dynamically, I want to fully clear the root = Tk(), without deleting it. Is there a way to do so? From gary.herron at islandtraining.com Mon Mar 24 16:37:23 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Mon, 24 Mar 2014 13:37:23 -0700 Subject: Memory error In-Reply-To: References: Message-ID: <53309783.1090107@islandtraining.com> On 03/24/2014 04:32 AM, Jamie Mitchell wrote: > Hello all, > > I'm afraid I am new to all this so bear with me... > > I am looking to find the statistical significance between two large netCDF data sets. > > Firstly I've loaded the two files into python: > > swh=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/averages/swh_control_concat.nc', 'r') > > swh_2050s=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/averages/swh_2050s_concat.nc', 'r') > > I have then isolated the variables I want to perform the pearson correlation on: > > hs=swh.variables['hs'] > > hs_2050s=swh_2050s.variables['hs'] This is not really a Python question. It's a question about netCDF (whatever that may be), or perhaps it's interface to Python python-netCD4. You may get an answer here, but you are far more likely to get one quickly and accurately from a forum dedicated to netCDF, or python-netCD. Good luck. Gary Herron From victor.olex at vtenterprise.com Mon Mar 24 16:57:49 2014 From: victor.olex at vtenterprise.com (victor.olex at vtenterprise.com) Date: Mon, 24 Mar 2014 13:57:49 -0700 (PDT) Subject: Python developer salary survey - results Message-ID: <89759b83-95ac-4cb6-9597-bd64061b3c3e@googlegroups.com> PyStreet's February salary survey attracted respondents from 37 countries. Median annual salary in the U.S.: $95,000 Median annual salary worldwide: $50,000 Complete study: http://bit.ly/1dgCw3p From vincent at vincentdavis.net Mon Mar 24 17:20:34 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 24 Mar 2014 15:20:34 -0600 Subject: Merge/append CSV files with different headers In-Reply-To: References: Message-ID: Thanks for the feedback. Vincent Davis 720-301-3003 On Mon, Mar 24, 2014 at 1:44 PM, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 4:50 AM, Vincent Davis > wrote: > > I have several csv file I need to append (vertically). They have > different > > but overlapping headers. For example; > > file1 headers ['a', 'b', 'c'] > > file2 headers ['d', 'e'] > > file3 headers ['c', 'd'] > > > > Is there a better way than this > > Summary of your code: > > 1) Build up a set of all headers used, by opening each file and > reading the headers. > 2) Go through each file a second time and write them out. > > That seems like the best approach, broadly. You might be able to > improve it a bit (it might be tidier to open each file once, but since > you're using two different CSV readers, it'd probably not be), but by > and large, I'd say you have the right technique. Your processing time > here is going to be dominated by the actual work of copying. > > The only thing you might want to consider is order. The headers all > have a set order to them, and it'd make sense to have the output come > out as ['a', 'b', 'c', 'd', 'e'] - the first three from the first > file, then adding in everything from subsequent files in the order > they were found. Could be done easily enough by using 'in' and > .append() on a list, rather than using a set. But if that doesn't > matter to you, or if something simple like "sort the headers > alphabetically" will do, then I think you basically have what you > want. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From harrismh777 at gmail.com Mon Mar 24 17:43:17 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 16:43:17 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/24/14 4:03 AM, Ian Kelly wrote: > > The difference does not really lie in the lambda construct per se but in > the binding style of closures. Functional languages tend to go one way > here; imperative languages tend to go the other. {snip} > The result may be more surprising to users accustomed to functional > languages, but I claim that it is *less* surprising to users of other > imperative languages. Aside from the sin of spelling out "lambda," should be ( \x y -> x + y ) a b ) but, neither here nor there... Yes, its about closures, totally; the most confusing aspect of lambda in python is not only the syntax but the idea of scope and closure (for that syntax). Everyone is confused by this initially, not because its complicated, but because its confusing. An example: >>>> >>>> adders= list(range(4)) >>>> adders > [0, 1, 2, 3] >>>> for n in adders: > adders[n]=lambda a: a+n > > >>>> print(adders[1](3)) > 6 >>>> The expected value as perceived by "normal" people is 4. This comes up on the list over and again year after year in various flavors, but always because lambda is unnecessarily confusing where it comes to how does it function; and by that we mean simply, how does scope and closure work in this context. Once the "normal" person is introduced to the scope and closure idiosyncrasies of pythons lambda, well then everything is much smoother. But how to fix? Consider: >>>> >>>> adders= list(range(4)) >>>> adders > [0, 1, 2, 3] >>>> for n in adders: > adders[n] = (lambda b: lambda a: b + a)(n) > > >>>> adders[1](3) > 4 >>>> adders[2](3) > 5 >>>> Now, here is where I talk about confusion; explaining why the first lambda above does not work because of scope and closure, and then even worse, explaining why the second "double" lambda works in the lower example! Its a nightmare, really. And you are correct, its really about closure. marcus From marko at pacujo.net Mon Mar 24 18:43:11 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 25 Mar 2014 00:43:11 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ior3w740.fsf@elektro.pacujo.net> Mark H Harris : > Yes, its about closures, totally; the most confusing aspect of > lambda in python is not only the syntax but the idea of scope and > closure (for that syntax). Everyone is confused by this initially, not > because its complicated, but because its confusing. An example: > >>>>> adders= list(range(4)) >>>>> for n in adders: >> adders[n]=lambda a: a+n >>>>> print(adders[1](3)) >> 6 > > The expected value as perceived by "normal" people is 4. 1. No, I don't think that understanding is automatically natural. 2. It does not concern Python only. For example, what does this scheme expression yield? ((let ((n 3)) (let ((f (lambda () n))) (set! n 7) f))) Answer: 7 3. It doesn't concern lambda only. For example, rewrite your loop like this: for n in range(4): def add(a): return a + n adders[n] = add adders[1](3) => 6 Marko From steve+comp.lang.python at pearwood.info Mon Mar 24 18:58:19 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2014 22:58:19 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5330b88b$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 06:22:28 +1100, Chris Angelico wrote: > Aside: You'll often hear people talking about "map-reduce" with big > data. Python supports that. Look! > >>>> map.__reduce__ > > > Oh wait, that's nothing to do with reduce()... > > *ducks for cover* Ha ha, very funny :-P http://code.activestate.com/recipes/577676-dirt-simple-mapreduce/ -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Mon Mar 24 19:01:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 10:01:27 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 8:43 AM, Mark H Harris wrote: >> adders[n] = (lambda b: lambda a: b + a)(n) > > Now, here is where I talk about confusion; explaining why the first > lambda above does not work because of scope and closure, and then even > worse, explaining why the second "double" lambda works in the lower example! Easy fix. Use the "explicit capture" notation: adders[n] = lambda a, n=n: a+n And there you are, out of your difficulty at once! ChrisA From rosuav at gmail.com Mon Mar 24 19:07:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 10:07:01 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <5330b88b$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <5330b88b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 9:58 AM, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 06:22:28 +1100, Chris Angelico wrote: > >> Aside: You'll often hear people talking about "map-reduce" with big >> data. Python supports that. Look! >> >>>>> map.__reduce__ >> >> >> Oh wait, that's nothing to do with reduce()... >> >> *ducks for cover* > > Ha ha, very funny :-P > > > http://code.activestate.com/recipes/577676-dirt-simple-mapreduce/ That looks like a more serious map/reduce example. Mine came from a double-take when I was looking at help(map) for some reason; there's a __round__ magic method that helps define the round() function, there's __abs__ for abs(), there's __str__ for str()... look, there's a __reduce__ - it must be to help define reduce()! :) ChrisA From harrismh777 at gmail.com Mon Mar 24 19:44:37 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 18:44:37 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/24/14 6:01 PM, Chris Angelico wrote: > Easy fix. Use the "explicit capture" notation: > adders[n] = lambda a, n=n: a+n > And there you are, out of your difficulty at once! Yes, yes, yes, and example: >>>> adders= list(range(4)) >>>> for n in adders: > adders[n] = lambda a, n=n: a+n > > >>>> adders[1](3) >4 >>>> adders[2](3) >5 But, and this is the big (WHY?) is that necessary? In other words, its not about experts knowing how to make this work, its about "normal" people not understanding in the first place why its a problem, and why the various solutions work to fix it; even though "we" all know that nothing is 'broken'. And in reference to Marko's post, he's right, its not just python, but the issue is not where else is capture and scope a problem for confusion, the issue is whether python's lambda provides a significant opportunity for confusion that in the larger scheme of things (no pun intended) is not warranted. marcus From harrismh777 at gmail.com Mon Mar 24 19:48:50 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 18:48:50 -0500 Subject: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary) References: <532f9a6b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/24/14 6:30 PM, Dennis Lee Bieber wrote: > {And I recall standard practice was to hit \r, to return the carriage, \n > for next line, and one RUBOUT to provide a delay while the carriage > returned to the left} Yes, yes... I remember well, there had to be a delay (of some type) to wait for the horse and carriage to get from the right side of the field to the left. Aaah, the good 'ol days. marcus From rosuav at gmail.com Mon Mar 24 19:57:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 10:57:34 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 10:44 AM, Mark H Harris wrote: > On 3/24/14 6:01 PM, Chris Angelico wrote: > >> Easy fix. Use the "explicit capture" notation: >> adders[n] = lambda a, n=n: a+n >> And there you are, out of your difficulty at once! > But, and this is the big (WHY?) is that necessary? In other words, its > not about experts knowing how to make this work, its about "normal" people > not understanding in the first place why its a problem, and why the various > solutions work to fix it; even though "we" all know that nothing is > 'broken'. Why is it necessary? For the same reason that this works: def func_pair(): x = 0 def inc(): nonlocal x; x+=1 return x def dec(): nonlocal x; x-=1 return x return inc, dec fooup, foodn = func_pair() barup, bardn = func_pair() >>> fooup(), fooup(), fooup(), foodn() (1, 2, 3, 2) >>> barup(), barup(), bardn(), bardn() (1, 2, 1, 0) When you use the variable x in multiple places, it's the same variable and it has a single value. If you don't want that, you have to make a separate variable. ChrisA From ian.g.kelly at gmail.com Mon Mar 24 19:58:11 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 24 Mar 2014 17:58:11 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 24, 2014 at 3:43 PM, Mark H Harris wrote: > On 3/24/14 4:03 AM, Ian Kelly wrote: >> >> >> The difference does not really lie in the lambda construct per se but in >> the binding style of closures. Functional languages tend to go one way >> here; imperative languages tend to go the other. {snip} > > >> The result may be more surprising to users accustomed to functional >> languages, but I claim that it is *less* surprising to users of other >> imperative languages. > > > Aside from the sin of spelling out "lambda," > should be ( \x y -> x + y ) a b ) but, neither here nor there... Well no, it *should* be ?x y . x + y but apparently some people don't have that character on their keyboards, so it gets written as lambda or \ instead. Personally I dislike the \ style; it doesn't really resemble a ? that closely, and to me the backslash denotes escape sequences and set differences. Nor is Python alone in spelling out lambda: Scheme and Common Lisp spell it the same way. As far as I know the \ for ? is unique to Haskell. From harrismh777 at gmail.com Mon Mar 24 19:56:23 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 18:56:23 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/24/14 5:43 PM, Marko Rauhamaa wrote: > Mark H Harris: >> Yes, its about closures, totally; the most confusing aspect of >> lambda in python is not only the syntax but the idea of scope and >> closure (for that syntax). Everyone is confused by this initially, not >> because its complicated, but because its confusing. An example: >>>>>> adders= list(range(4)) >>>>>> for n in adders: >>> adders[n]=lambda a: a+n >>>>>> print(adders[1](3)) >>> 6 >> The expected value as perceived by "normal" people is 4. > > 1. No, I don't think that understanding is automatically natural. It might not seem that way for an expert, but if you Google python lambda function closure(s) you will notice that this is pretty much the natural way of interpreting things. Of course the problem is that the closure grabs the *last* number in the list which is used for each of the adder[] functions created. So, in other words, three (3) is the number added in each of the adder functions. But here is the rub, it is not *ever* clear to people (even experienced python coders, me for instance) that this is how it should work. What is needed is the explicit closure "grab" recommended by ChrisA. But for the normal, that is just as bad (conceptually) because while it works it strays FAR away from expected lambda constructs known to functional programmers, and it is difficult to explain to non functional programmers... a proverbial catch 22. marcus From rosuav at gmail.com Mon Mar 24 20:11:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 11:11:24 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 25, 2014 at 10:56 AM, Mark H Harris wrote: > What is needed is the explicit closure "grab" recommended by ChrisA. Which does work. You do know why, right? ChrisA From harrismh777 at gmail.com Mon Mar 24 20:16:15 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 19:16:15 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/24/14 7:11 PM, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 10:56 AM, Mark H Harris wrote: >> What is needed is the explicit closure "grab" recommended by ChrisA. > > Which does work. You do know why, right? Sure. ... but again, that's not the point. The point is NOT can you explain why it works, the point is that as a lambda construct it is NOT clear why it works, and because the construct does not match what lambda users might expect (naturally) there are *constant* questions about it. So, again, I'll restate that the community might consider (over time) whether the confusion created by lambda in python is worth the time and trouble to maintain the construct in the language. Is the value add worth the cost of confusion. I don't think so; others are bound to disagree. marcus From rosuav at gmail.com Mon Mar 24 20:19:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 11:19:56 +1100 Subject: advice on sub-classing multiprocessing.Process and multiprocessing.BaseManager In-Reply-To: References: Message-ID: On Tue, Mar 25, 2014 at 7:24 AM, Matt Newville wrote: > I'm maintaining a python interface to a C library for a distributed > control system (EPICS, sort of a SCADA system) that does a large > amount of relatively light-weight network I/O. In order to keep many > connections open and responsive, and to provide a simple interface, > the python library keeps a global store of connection state. > > This works well for single processes and threads, but not so well for > multiprocessing, where the global state causes trouble. >From the sound of things, a single process is probably what you want here. Is there something you can't handle with one process? ChrisA From rosuav at gmail.com Mon Mar 24 20:28:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 11:28:40 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 25, 2014 at 11:16 AM, Mark H Harris wrote: > On 3/24/14 7:11 PM, Chris Angelico wrote: >> >> On Tue, Mar 25, 2014 at 10:56 AM, Mark H Harris >> wrote: >>> >>> What is needed is the explicit closure "grab" recommended by ChrisA. >> >> >> Which does work. You do know why, right? > > > Sure. ... but again, that's not the point. The point is NOT can you explain > why it works, the point is that as a lambda construct it is NOT clear why it > works, and because the construct does not match what lambda users might > expect (naturally) there are *constant* questions about it. > > So, again, I'll restate that the community might consider (over time) > whether the confusion created by lambda in python is worth the time and > trouble to maintain the construct in the language. Is the value add worth > the cost of confusion. I don't think so; others are bound to disagree. Pure functional programming, from what I understand, doesn't *have* variables other than function arguments. So the way to implement "x = 1" is to call a subfunction with an argument of 1, which is referred to as x. (Am I right so far?) In that case, the default argument trick is exactly the right way to implement that in Python. ChrisA From breamoreboy at yahoo.co.uk Mon Mar 24 20:32:01 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Mar 2014 00:32:01 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 25/03/2014 00:16, Mark H Harris wrote: > On 3/24/14 7:11 PM, Chris Angelico wrote: >> On Tue, Mar 25, 2014 at 10:56 AM, Mark H >> Harris wrote: >>> What is needed is the explicit closure "grab" recommended by ChrisA. >> >> Which does work. You do know why, right? > > Sure. ... but again, that's not the point. The point is NOT can you > explain why it works, the point is that as a lambda construct it is NOT > clear why it works, and because the construct does not match what lambda > users might expect (naturally) there are *constant* questions about it. > > So, again, I'll restate that the community might consider (over time) > whether the confusion created by lambda in python is worth the time and > trouble to maintain the construct in the language. Is the value add > worth the cost of confusion. I don't think so; others are bound to > disagree. > > marcus I'd vote to have lambda taken out of the language if it meant avoiding tedious threads like this one :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Mon Mar 24 20:50:10 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 19:50:10 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/24/14 7:32 PM, Mark Lawrence wrote: >> marcus > > I'd vote to have lambda taken out of the language if it meant avoiding > tedious threads like this one :( > Dude, you remind me of Eeyore; "days, weeks, months, who knows..." Its just a conversation. Don't setup a polling booth yet. Its all in fun and science. marcus From tjreedy at udel.edu Mon Mar 24 21:04:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 24 Mar 2014 21:04:41 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <5330b88b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/24/2014 7:07 PM, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 9:58 AM, Steven D'Aprano > wrote: >> On Tue, 25 Mar 2014 06:22:28 +1100, Chris Angelico wrote: >> >>> Aside: You'll often hear people talking about "map-reduce" with big >>> data. Python supports that. Look! >>> >>>>>> map.__reduce__ >>> >>> >>> Oh wait, that's nothing to do with reduce()... >>> >>> *ducks for cover* >> >> Ha ha, very funny :-P >> >> >> http://code.activestate.com/recipes/577676-dirt-simple-mapreduce/ > > That looks like a more serious map/reduce example. Mine came from a > double-take when I was looking at help(map) for some reason; there's a > __round__ magic method that helps define the round() function, there's > __abs__ for abs(), there's __str__ for str()... look, there's a > __reduce__ - it must be to help define reduce()! :) That was my first think also. I believe __pickle__ or __unpickle__ would have been more appropriate. -- Terry Jan Reedy From tjreedy at udel.edu Mon Mar 24 21:20:48 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 24 Mar 2014 21:20:48 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/24/2014 7:56 PM, Mark H Harris wrote: > Of course the problem is that the closure A function is not a closure unless defined within another function. In the examples I remember, there was no nesting. > grabs the *last* number in > the list which is used for each of the adder[] functions created. Wrong. Functions look up global and nonlocal names, such as n, when the function is called. >>> adders = list(range(4)) >>> for n in adders: adders[n] = lambda a: a+n >>> n = 1000 >>> adders[1](3) 1003 Same result if the function *is* a closure, making n nonlocal rather than global. def f(): adders = list(range(4)) for n in adders: adders[n] = lambda a: a+n n = 1000 return adders print(f()[1](3)) >>> 1003 The only definition time grabbing is with default arg expressions. This discussion is a bit funny in a way. Some people are puzzled that default arg expressions 'grab' just once, as definition time, rather than with each call. Others (I hope others) are puzzled that body expressions 'grab' with each call, rather than just once, at definition time. That seems to be particularly true when the body is in a lambda expression rather than a def statement. -- Terry Jan Reedy From nispray at gmail.com Mon Mar 24 21:26:58 2014 From: nispray at gmail.com (Wesley) Date: Mon, 24 Mar 2014 18:26:58 -0700 (PDT) Subject: Python developer salary survey - results In-Reply-To: <89759b83-95ac-4cb6-9597-bd64061b3c3e@googlegroups.com> References: <89759b83-95ac-4cb6-9597-bd64061b3c3e@googlegroups.com> Message-ID: <6ecc1d94-d27f-4fad-a7b8-0f26a12cca90@googlegroups.com> ? 2014?3?25????UTC+8??4?57?49??victo... at vtenterprise.com??? > PyStreet's February salary survey attracted respondents from 37 countries. > > > > Median annual salary in the U.S.: $95,000 > > Median annual salary worldwide: $50,000 > > > > Complete study: http://bit.ly/1dgCw3p I am below the worldwide median... From tjreedy at udel.edu Mon Mar 24 21:31:46 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 24 Mar 2014 21:31:46 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/24/2014 8:28 PM, Chris Angelico wrote: > Pure functional programming, from what I understand, doesn't *have* > variables other than function arguments. function *parameters*, if in the 'variable = name' camp > So the way to implement "x = 1" is to call a subfunction with a parameter named 'x' > with an argument of 1 Funny, I was just thinking about that last night. I really learned it when trying to translate python code to the scheme dialect racket. import math as m s = m.sqrt(2) a = m.sin(s) + m.cos(s) del s # to be exactly equivalent to the below, but not needed b = (lambda x: m.sin(x) + m.cos(x))(m.sqrt(2)) print(a,b) >>> 1.14370964075811 1.14370964075811 -- Terry Jan Reedy From rosuav at gmail.com Mon Mar 24 21:41:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 12:41:32 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 25, 2014 at 12:31 PM, Terry Reedy wrote: > On 3/24/2014 8:28 PM, Chris Angelico wrote: > >> Pure functional programming, from what I understand, doesn't *have* >> variables other than function arguments. > > > function *parameters*, if in the 'variable = name' camp > > >> So the way to implement "x = 1" is to call a subfunction > > > with a parameter named 'x' > >> with an argument of 1 Ah, yes, parameter. I tend to use the terms interchangeably, but they do have formal definitions and distinctions. But otherwise, yes; that's how I was seeing that. ChrisA From steve+comp.lang.python at pearwood.info Mon Mar 24 21:45:02 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 01:45:02 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5330df9e$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 24 Mar 2014 14:47:11 -0500, Mark H Harris wrote: > On 3/24/14 4:49 AM, Steven D'Aprano wrote: >> There's no doubt that lambda is less-often useful than is the def >> statement. But not only is it still useful, but there is a continual >> stream of people asking for Python to make it *more useful* by allowing >> the body of a lambda to be a full block, not just a single statement. >> Guido has stated (although I cannot remember where, so cannot paste a >> link) that he accepts that in principle, so long as somebody comes up >> with acceptable syntax. > > Now, this will seem strange to you, but if lambda were expanded to > include an entire block, well now, I would know two things: > 1) python has commitment to lambda Python has a commitment to lambda. lambda is not going anywhere. There was some idea chatter five or six years ago about dropping it from the language. It didn't get dropped, so now it is as much a part of the language as for-loops, print, classes and import. > and 2) lambda would become WAY more useful... Every one agrees that being able to include a full suite of statements in an expression form would be useful. Unfortunately, due to the constraint of Python's syntax, it seems to be impossible. People have looked for 20+ years, and nobody has come up with an acceptable syntax. [...] >>> Lambda is a problem of confusion for scientists and other >>> mathematicians (amateur and otherwise) {snip} >>{snip} >> But nor should the confusion of somebody who doesn't know the language >> count for much. > > This is the main disagreement between the two of us on this topic. > It should count for TONS; whole metric TONs. Because someone who > understands python primarily, and after five years of coding (say me) > somebody tells (me) to use lambda in a key clause so that my sort will > work, or work better, or work "their" way; and I have no idea why I need > this nameless function (after I find out that "that" is what it is!) Then you don't understand *sorting*. If you don't understand why you need a key function, the problem is not the syntax used to create the key function, but your understanding of sort. Time to remove sorting from Python, yes? No? It's not lambda that is giving you trouble. That's just syntax. There is no conceptual difference between: data.sort(key=lambda item: *magic goes on here*) and def key_func(item): *magic goes on here* data.sort(key=key_func) If the first confuses you, so will the second. If you are capable of learning what the first means, learning the second is no harder. > Its confusing, and please contrast between complicated. I don't mind > complicated, or extensive, or even hard, but when something is > needlessly confusing, then why? I don't know why you insist it is confusing. Maybe you're just no good at seeing the correspondence between lambda x: expression and def func(x): return expression >> Python's ints don't work exactly the same as ints do in some other >> languages, nor do Python's strings, nor is Python's object model >> precisely the same as that of some other languages. I think that it >> would be a ridiculous idea to discard int, str and the entire object >> system just because some people are surprised that Python doesn't >> behave exactly like some other language. I don't think lambda is any >> different. > > Your logic is faulty here. Conceptually python's lambda doesn't > work as expected, from contexts that define lambda Python defines lambda too. Why should Python have to bend over to suit the definition used by other languages? They don't own the concept of anonymous functions. Anonymous functions are found in all sorts of languages, with different semantics and different syntax: Pike: lambda(typ1 para1, typ2, para2, ...) { ... }; Perl: sub { my ($a, $b) = @_; ... } Smalltalk: [:a :b| ... ] Haskell: \a b -> ... Erlang: fun(a, b) -> ... end Dylan: method(a, b) ... end method to mention just a few. Ruby even has at least three ways of spelling lambda, one of which even uses the word lambda: {|a, b| ... } lambda {|a, b| ...} proc {|a, b| ...} > and where lambda in functional programming is VERY important. And? Nobody is saying that they have to stop using the term lambda. Certainly I'm not. I wouldn't be so rude. > For one thing, why would we > want to "spell out" the word "lambda". ( \x y -> x + y ) a b ) If > we're going to use lambda, then use it. So you don't like the syntax of Python's lambda. That's your prerogative. But frankly, one thing I dislike about Haskell is that it is too terse. Why would you use lambda without spelling out explicitly that you are doing so? >> Other languages -- not even Lisp -- don't get to be the sole decider as >> to what counts as an anonymous function. Python's lambda may be >> limited, but it is a perfectly fine lambda for what it is intended to >> do. > > Is that the same as George W. Bush's "decider" ? I have no idea why you are mocking my use of the word "decider". It's a perfectly legitimate word, a standard term in English for someone who decides. The Oxford dictionary dates it back to sometime between 1670 and 1699, so it is hardly a neologism or one of Junior Bush's malapropisms. Let me put it another way. Functional programming languages do not get to be the sole decision-maker of what counts as a legitimate syntax or semantics for anonymous functions. > I agree, and so does the link I referenced, for what it was designed > to do, its powerful; esp if one needs to embed a function in an > expression; that is what lambda is for. Right. >>> Its also confusing to sophisticated users of all stripes who may not >>> be aware of "lambda" at all. >> >> If they're not aware of lambda, how are they confused by it? > > See above. They are recommended its use (maybe on this list) and > they just don't get it; because its unnecessarily confusing. Then they are aware of lambda. Confusing in what way? Is it the keyword used? You don't need to know the background of the term to learn to use it. If non-English speakers can memorise that you use "class" to define classes, English speakers can stop being so precious and memorise that "lambda" is used to define a function in an expression. 'lambda' is just one of those jargon words, like 'tuple', 'iterate', 'boolean', 'closure', ... just learn it, and you'll be fine. If you want to investigate the background of the word, go right ahead, but it won't make you a better programmer to know that "boolean" is named after George Boole, and I still have no idea what the origin of "tuple" is. (And after 15+ years I still want to spell it "turple".) [...] > Programming should be a > liberal art available to everyone in the set of all "normal" educated > people. Why should it be? Programming is no more a liberal art than painting is an offshoot of calculus. Most "normal" (normal as defined by whom?) educated people have no interest, no desire, and no aptitude for programming. Most *programmers* have no aptitude for the rigor of programming -- the world is full of lousy programmers churning out their 40 lines of buggy VB/PHP/Java/C code per day but aren't any good at it: http://www.yacoset.com/Home/signs-that-you-re-a-bad-programmer http://haacked.com/archive/2007/02/27/Why_Cant_Programmers._Read.aspx/ Programming is a skill, like writing iambic pentameter. Should liberal arts courses ban the use of iambic pentameter by poets because some people find it confusing and can't count syllables or tell the difference between stressed and unstressed? (I know I can't. My wife despairs that I am so useless at anything like poetry.) > Some developers (themselves perhaps with degrees Ph.D. in > mathematics or computer science) forget about the fact that "normal" > educated people want to leverage their computer (maybe with python) for > problem solution without having to become a professional computer > scientist. I am advocating for those people. So you say. But I think you are actually being terribly condescending and elitist at the same time. Consider: (1) People who just want to get the job done, without learning a bunch of theory, *won't care* how their sort key function is written. They're looking for a recipe that they can copy and paste, and whether you write it like this: data.sort(key=lambda item: item[1]) or like this: from operator import itemgetter data.sort(key=itemgetter(1)) or like this: def sort_key(item): return item[1] data.sort(key=sort_key) *they won't care*. In fact, they'll probably prefer the first version, with lambda, because it is fewer lines to copy. And this is okay. Sometimes you've got more important things to do than understand how every line of your code works, especially for throw-away code, you just want to use it. It is very elitist to insist that features that some people don't understand have to go. Do you understand how import works? I bet you don't. It's so complicated that there are probably only one or two core developers who really understand it in all it's glory. You just use it: "import this", and it just works. lambda is the same. Sometimes programming is just a means to an end and the programmer just wants an answer now. (2) You're concluding that just because somebody is confused by lambda, they would be better off if lambda was removed. That's horribly patronising. Have you considered that maybe they will take that as an opportunity to *learn something new*? That they'll learn how to use lambda, they may even investigate the theory behind it? I am especially aggravated by your attack on lambda because I was that person. I had never heard of lambda calculus. When I first learned Python, lambda's syntax troubled me for a while. I had to keep looking it up, until suddenly the penny dropped that the argument list is exactly the same as the argument list of def. Replace "def name" with "lambda", drop the brackets, and use a single expression without "return", and Joan's your Auntie. But I learned it, and it got me interested in where the name came from, and I discovered the lambda calculus and decided that while I have every admiration for the people who fly that high into the rarefied air of theory, that's not an area I have much interest in. In any case, I am a better programmer -- or at least a more educated one -- precisely because Python didn't dumb down, it didn't patronise me, it offered an "advanced" (huh! not really) feature that I otherwise would never have been exposed to. Yes, Python could remove lambda, and take that opportunity away from others. Python would be a lesser language for it, and Python programmers will be lesser programmers for it. Python programmers are some of most widely read programmers around, compared to the average C or PHP or VB coder. That's because they are exposed to so many different concepts in the language. Not everyone cares to learn about them, and that's okay, but they aren't Python's core audience. >> You want to remove lambda because it causes confusion. Okay, for the >> sake of the argument I will agree that lambda is confusing. Do you know >> what else is confusing? > > I don't want to remove anything at this point. I am only suggesting > that over time the python community might evaluate whether the lambda > (map, filter, reduce) thing is a language benefit. If so, manet in > aeternum. Elif, deprecate it and over time phase it out completely. Its > a community decision of course, and I'm NOT demanding anything. This discussion was held five years ago. And lambda is still here. >> Threading is confusing. So is multiprocessing. So are databases. >> Unicode is confusing. First-class functions are confusing. Recursion is >> confusing. Closures are confusing. List comprehensions are confusing. >> What the hell are trampolines? I'm certainly confused by them. > > Argument by analogy almost never works. Please don't confuse my word > "confusing" with your interpretation "complicated". Actually, I do not > find any of those above mentioned as "confusing," Good for you! I mean it, I'm not being sarcastic. But I *know* people find all those things confusing, because (1) either I found, or still do, find them confusing, or (2) because I've seen people confused by them. When I say "confusing", I mean it. I don't mean complicated. > while I do admit they > are complicated--even extremely complicated. An intelligent person > educated in the liberal arts should be able to sit down over time and > pick-up the concepts in a new area--without--being confused by the > material or presentation. Lambda is confusing NOT because its > complicated (because its not) but because 1) it does not work like other > lambda concepts in functional programming, Do you really believe that people educated in the liberal arts are exposed to the lambda calculus? Most MATHEMATICIANS aren't exposed to lambda calculus. > and 2) because the syntax > does not lend itself easily to immediate interpretation (by normal > people) nor does it lend itself easily to explanation even in the best > effort. I think that's just nonsense. Take a one-line function: def func(args): return stuff Remove the "def func", the brackets, and the "return". Move it all to one line, and stick the magic word "lambda" at the front: lambda args: stuff And you're done. That's all there is to it. Your insistence that lambda is confusing is awfully condescending. People are not as dumb as you insist, and they are perfectly capable of learning lambda without a comp sci degree. Like any technical jargon, there is vocabulary and meaning to learn, but the concept is no more difficult than ordinary def functions. -- Steven D'Aprano http://import-that.dreamwidth.org/ From harrismh777 at gmail.com Mon Mar 24 21:56:28 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 20:56:28 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <8aa0b833-e7b7-485b-8258-c59eebdace93@googlegroups.com> Message-ID: On 3/22/14 3:59 PM, vasudevram wrote: > > Thanks to all those who answered. > > - Vasudev I am wondering if the question was answered? >>>> >>>> x = [[1,2],[3,4],[5,6]] >>>> import ast >>>> ast.dump(ast.parse('[x for x in x for x in x]')) > > "Module(body= > > [Expr(value=ListComp(elt=Name(id='x', ctx=Load()), > > generators= > > [comprehension(target=Name(id='x', ctx=Store()), iter=Name(id='x', ctx=Load()), ifs=[]), > > comprehension(target=Name(id='x', ctx=Store()), iter=Name(id='x', ctx=Load()), ifs=[])]))])" >>>> This is really, I think, the answer to the OPs question. Knowing how python is parsing the comprehension of comprehensions is important, yes? Obviously each x is within a different scope, within a separate iterator. This seems to unwind from right to left? I didn't see any ast entries in the thread, so just wondering. marcus From breamoreboy at yahoo.co.uk Mon Mar 24 22:06:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Mar 2014 02:06:53 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <5330df9e$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> <5330df9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/03/2014 01:45, Steven D'Aprano wrote: > > (1) People who just want to get the job done, without learning a bunch of > theory, *won't care* how their sort key function is written. They're > looking for a recipe that they can copy and paste, and whether you write > it like this: > > data.sort(key=lambda item: item[1]) > > or like this: > > from operator import itemgetter > data.sort(key=itemgetter(1)) > > or like this: > > def sort_key(item): > return item[1] > data.sort(key=sort_key) > > > *they won't care*. In fact, they'll probably prefer the first version, > with lambda, because it is fewer lines to copy. > I'm firmly in this camp, practicality beats purity and all that. I've used the first and second versions shown above as they happened to be in the recipes I was aquiring, I wouldn't contemplate the third. That's just my mindset, which is what I love about Python, by pure luck it fits me like made to measure clothing. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From rosuav at gmail.com Mon Mar 24 22:17:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 13:17:51 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <5330df9e$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> <5330df9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 12:45 PM, Steven D'Aprano wrote: > Programming is a skill, like writing iambic pentameter. Should liberal > arts courses ban the use of iambic pentameter by poets because some > people find it confusing and can't count syllables or tell the difference > between stressed and unstressed? (I know I can't. My wife despairs that I > am so useless at anything like poetry.) Iambic pentameter is hard. I know, I tried writing eight lines of it for my brother's wedding. (Okay, I was writing *acrostic* iambic pentameter, putting his wife's new surname down the left edge of the page, but still, it's pretty restrictive.) It's much more fun, I reckon, to write paragraphs of text roughly eighty characters across. Prosaic, I know.... ChrisA From harrismh777 at gmail.com Mon Mar 24 22:39:33 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 21:39:33 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/24/14 8:20 PM, Terry Reedy wrote: > On 3/24/2014 7:56 PM, Mark H Harris wrote: >> the list which is used for each of the adder[] functions created. > > Wrong. Functions look up global and nonlocal names, such as n, when the > function is called. > hi Terry, yeah, I know; this is what's *wrong* all at once. Functions "look up global and nonlocal names" such as n, is semantics for "each created function 'grabs' the last number (n) in the list", well, because that (n) is bound at call-time to (3). Your version semantically is detailed and correct; my version semantically is "how it is perceived" by the user, which is also correct. Again, how the function gets the n (grab or lookup) is mute. The user is often confused about how this happens. As you have shown, even experts in this field disagree about how this is described, which is also my secondary point--- the whole thing is VERY difficult to explain to "normal" users. It often takes several sessions and goes on and on, until Mark Lawrence calls it tedious. marcus From rustompmody at gmail.com Mon Mar 24 23:00:56 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 20:00:56 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> On Tuesday, March 25, 2014 5:28:11 AM UTC+5:30, Ian wrote: > On Mon, Mar 24, 2014 at 3:43 PM, Mark H Harris wrote: > > On 3/24/14 4:03 AM, Ian Kelly wrote: > >> The difference does not really lie in the lambda construct per se but in > >> the binding style of closures. Functional languages tend to go one way > >> here; imperative languages tend to go the other. {snip} > >> The result may be more surprising to users accustomed to functional > >> languages, but I claim that it is *less* surprising to users of other > >> imperative languages. > > Aside from the sin of spelling out "lambda," > > should be ( \x y -> x + y ) a b ) but, neither here nor there... > Well no, it *should* be ?x y . x + y but apparently some people don't > have that character on their keyboards, so it gets written as lambda > or \ instead. Personally I dislike the \ style; it doesn't really > resemble a ? that closely, and to me the backslash denotes escape > sequences and set differences. Nor is Python alone in spelling out > lambda: Scheme and Common Lisp spell it the same way. As far as I know > the \ for ? is unique to Haskell. Yeah: Its 2014 (at least out here)... About time we started using unicode in earnest dont you think?? Id like to see the following spellings corrected: lambda to ? in to ? (preferably with the 'in' predicate and the 'in' in 'for' disambiguated) set([]) to ? And some parentheses disambiguation Internal ambiguity: Is '(...)' a paren? a function? a tuple? External ambiguity: {} in python vs in set theory [And now I hand it over to our very dear resident troll to explain the glories of the FSR] From rosuav at gmail.com Mon Mar 24 23:17:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 14:17:35 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 2:00 PM, Rustom Mody wrote: > Yeah: Its 2014 (at least out here)... > About time we started using unicode in earnest dont you think?? We do. > Id like to see the following spellings corrected: > lambda to ? > in to ? > (preferably with the 'in' predicate and the 'in' in 'for' disambiguated) > set([]) to ? The problems with these is not Unicode or a lack thereof, but keys. I know how to type "lambda" on any keyboard I reach for; if it's a full-sized QWERTY variant, I can type it without looking, and if it's something else then I can peer at the thing and find the appropriate five letters. (Phone keyboards are notoriously peer-worthy.) How do I type ?? Do I have to memorize an alt-key sequence? Do I need to keep a set of "language keywords" in a file somewhere so I can copy and paste? Does my editor have to provide them? What is really gained by using the short-hand? It becomes nigh ungoogleable; yes, you can paste ? into Google and find out that it's called lambda (and, if Python used that as a keyword, you could type "? python" into Google and get to the docs), but how do you figure out which part of this to search for? sockets.sort(key=?data:data[1]) More likely you'd search for "sockets" or "sort" or maybe "key" or "data", but you wouldn't expect to search for the symbol. > And some parentheses disambiguation > Internal ambiguity: Is '(...)' a paren? a function? a tuple? > External ambiguity: {} in python vs in set theory I don't know about the difference between {} in set theory and Python, but the multiple uses of () actually boil down to two: 1) Grouping, which includes tuples; there's a special case whereby grouping nothing makes a zero-item tuple, but everything else is just the comma 2) Functions (both definition and call) Disambiguating them might be of some small value, but since they're the same in pretty much every language under the sun, it would feel like syntactic salt: you have to use a different, and hard to type, form of parenthesis for one (or even both!) of what ought to just be simple brackets. And what's the benefit? Shorter code, maybe. A few 2-6 letter sequences that can become single characters. I can sympathize somewhat with the set issue (because {} means an empty dict), although set() is better than set([]); having a short form for that would be of some advantage. But not if it's hard to type. ChrisA From harrismh777 at gmail.com Mon Mar 24 23:15:05 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 22:15:05 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On 3/24/14 10:00 PM, Rustom Mody wrote: > About time we started using unicode in earnest dont you think?? > > Id like to see the following spellings corrected: > lambda to ? great idea! {snip} > > [And now I hand it over to our very dear resident troll to explain the glories > of the FSR] Now, that's not at all patronizing, ~is it? !vdrt marcus :) From harrismh777 at gmail.com Mon Mar 24 23:25:28 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 22:25:28 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On 3/24/14 10:17 PM, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 2:00 PM, Rustom Mody wrote: >> Yeah: Its 2014 (at least out here)... >> About time we started using unicode in earnest dont you think?? > > We do. > >> Id like to see the following spellings corrected: >> lambda to ? >> in to ? >> (preferably with the 'in' predicate and the 'in' in 'for' disambiguated) >> set([]) to ? > > The problems with these is not Unicode or a lack thereof, but keys. I > know how to type "lambda" on any keyboard I reach for; Yeah, its a fit. I found pi -> ? ... and here's apple pi -> ?? but, rats, can't find \ lambda From matt.newville at gmail.com Mon Mar 24 23:27:41 2014 From: matt.newville at gmail.com (matt.newville at gmail.com) Date: Mon, 24 Mar 2014 20:27:41 -0700 (PDT) Subject: advice on sub-classing multiprocessing.Process and multiprocessing.BaseManager In-Reply-To: References: Message-ID: <80cf8fb7-d0c5-43a9-bc6f-c61ce6214f98@googlegroups.com> On Monday, March 24, 2014 7:19:56 PM UTC-5, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 7:24 AM, Matt Newville > > > I'm maintaining a python interface to a C library for a distributed > > control system (EPICS, sort of a SCADA system) that does a large > > amount of relatively light-weight network I/O. In order to keep many > > connections open and responsive, and to provide a simple interface, > > the python library keeps a global store of connection state. > > > > This works well for single processes and threads, but not so well for > > multiprocessing, where the global state causes trouble. > > > From the sound of things, a single process is probably what you want > here. Is there something you can't handle with one process? Thanks for the reply. I find that appreciation is greatly (perhaps infinitely) delayed whenever I reply "X is probably not what you want to do" without further explanation to a question of "can I get some advice on how to do X?". So, I do thank you for your willingness to reply, even such a guaranteed-to-be-under-appreciated reply. There are indeed operations that can't be handled with a single process, such as simultaneously using multiple cores. This is why we want to use multiprocessing instead of (or, in addition to) threading. We're trying to do real-time collection of scientific data from a variety of data sources, generally within a LAN. The data can get largish and fast, and intermediate processing occasionally requires non-trivial computation time. So being able to launch worker processes that can run independently on separate cores would be very helpful. Ideally, we'd like to let sub-processes make calls to the control system too, say, read new data. I wasn't really asking "is multiprocessing appropriate?" but whether there was a cleaner way to subclass multiprocessing.BaseManager() to use a subclass of Process(). I can believe the answer is No, but thought I'd ask. Thanks again, --Matt From harrismh777 at gmail.com Mon Mar 24 23:28:55 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 22:28:55 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On 3/24/14 10:25 PM, Mark H Harris wrote: > > but, rats, can't find \ lambda Ok, there we go -> ? and ? and ? and ? no problem. From roy at panix.com Mon Mar 24 23:29:19 2014 From: roy at panix.com (Roy Smith) Date: Mon, 24 Mar 2014 23:29:19 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > On Tue, Mar 25, 2014 at 2:00 PM, Rustom Mody wrote: > > Yeah: Its 2014 (at least out here)... > > About time we started using unicode in earnest dont you think?? > > We do. > > > Id like to see the following spellings corrected: > > lambda to ?? > > in to ??? > > (preferably with the 'in' predicate and the 'in' in 'for' disambiguated) > > set([]) to ? > > The problems with these is not Unicode or a lack thereof, but keys. I > know how to type "lambda" on any keyboard I reach for; if it's a > full-sized QWERTY variant, I can type it without looking, and if it's > something else then I can peer at the thing and find the appropriate > five letters. (Phone keyboards are notoriously peer-worthy.) How do I > type ??? Do I have to memorize an alt-key sequence? Do I need to keep a > set of "language keywords" in a file somewhere so I can copy and > paste? Does my editor have to provide them? I started programming on 029 keypunches and ASR-33 teletypes. If you asked me to type most of the punctuation we take for granted today (not to mention lower case letters), I would have looked at you as if you had asked me to type something in greek. Hardware evolves. I assume that future generations of programmers will have input devices better suited to unicode than the clumsy keyboards we use today. From rosuav at gmail.com Mon Mar 24 23:44:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 14:44:46 +1100 Subject: advice on sub-classing multiprocessing.Process and multiprocessing.BaseManager In-Reply-To: <80cf8fb7-d0c5-43a9-bc6f-c61ce6214f98@googlegroups.com> References: <80cf8fb7-d0c5-43a9-bc6f-c61ce6214f98@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 2:27 PM, wrote: > Thanks for the reply. I find that appreciation is greatly (perhaps infinitely) delayed whenever I reply "X is probably not what you want to do" without further explanation to a question of "can I get some advice on how to do X?". So, I do thank you for your willingness to reply, even such a guaranteed-to-be-under-appreciated reply. > Heh. I do see that side of it, but the problem is that sometimes a question will be asked that implies a completely wrong approach. Take this example: "I'm having trouble passing a global variable to a function, how can I do it?" This exact question came up recently (I may have the wording wrong), and some of the solutions offered were horrendously convoluted messes involving passing the name of a global to the function which then used 'exec' or 'eval'. While technically that answers the question, it's much more helpful to take a step back - no, let's take a step forward - now another step back - and we're cha-cha'ing! - well, unless you're a real genius, just take the step back, and look at what you're actually trying to achieve. I wasn't trying to imply that you absolutely ought to use a single process, but more that the exact reasons for not using one process are significant in your style of coding the multi-process method. > There are indeed operations that can't be handled with a single process, such as simultaneously using multiple cores. This is why we want to use multiprocessing instead of (or, in addition to) threading. We're trying to do real-time collection of scientific data from a variety of data sources, generally within a LAN. The data can get largish and fast, and intermediate processing occasionally requires non-trivial computation time. So being able to launch worker processes that can run independently on separate cores would be very helpful. Ideally, we'd like to let sub-processes make calls to the control system too, say, read new data. > > I wasn't really asking "is multiprocessing appropriate?" but whether there was a cleaner way to subclass multiprocessing.BaseManager() to use a subclass of Process(). I can believe the answer is No, but thought I'd ask. > I've never subclassed BaseManager like this. It might be simpler to spin off one or more workers and not have them do any network communication at all; that way, you don't need to worry about the cache. Set up a process tree with one at the top doing only networking and process management (so it's always fast), and then use a multiprocessing.Queue or somesuch to pass info to a subprocess and back. Then your global connection state is all stored within the top process, and none of the others need care about it. You might have a bit of extra effort to pass info back to the parent rather than simply writing it to the connection, but that's a common requirement in other areas (eg GUI handling - it's common to push all GUI manipulation onto the main thread), so it's a common enough model. But if subclassing and tweaking is the easiest way, and if you don't mind your solution being potentially fragile (which subclassing like that is), then you could look into monkey-patching Process. Inject your code into it and then use the original. It's not perfect, but it may turn out easier than the "subclass everything" technique. ChrisA From rustompmody at gmail.com Mon Mar 24 23:43:43 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 20:43:43 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On Tuesday, March 25, 2014 8:47:35 AM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 2:00 PM, Rustom Mody wrote: > > Yeah: Its 2014 (at least out here)... > > About time we started using unicode in earnest dont you think?? > We do. > > Id like to see the following spellings corrected: > > lambda to ? > > in to ? > > (preferably with the 'in' predicate and the 'in' in 'for' disambiguated) > > set([]) to ? > The problems with these is not Unicode or a lack thereof, but keys. I > know how to type "lambda" on any keyboard I reach for; if it's a > full-sized QWERTY variant, I can type it without looking, and if it's > something else then I can peer at the thing and find the appropriate > five letters. (Phone keyboards are notoriously peer-worthy.) How do I > type ?? Do I have to memorize an alt-key sequence? Do I need to keep a > set of "language keywords" in a file somewhere so I can copy and > paste? Does my editor have to provide them? > What is really gained by using the short-hand? It becomes nigh > ungoogleable; yes, you can paste ? into Google and find out that it's > called lambda (and, if Python used that as a keyword, you could type > "? python" into Google and get to the docs), but how do you figure out > which part of this to search for? > sockets.sort(key=?data:data[1]) > More likely you'd search for "sockets" or "sort" or maybe "key" or > "data", but you wouldn't expect to search for the symbol. > > And some parentheses disambiguation > > Internal ambiguity: Is '(...)' a paren? a function? a tuple? > > External ambiguity: {} in python vs in set theory > I don't know about the difference between {} in set theory and Python, > but the multiple uses of () actually boil down to two: > 1) Grouping, which includes tuples; there's a special case whereby > grouping nothing makes a zero-item tuple, but everything else is just > the comma > 2) Functions (both definition and call) > Disambiguating them might be of some small value, but since they're > the same in pretty much every language under the sun, it would feel > like syntactic salt: you have to use a different, and hard to type, > form of parenthesis for one (or even both!) of what ought to just be > simple brackets. > And what's the benefit? Shorter code, maybe. A few 2-6 letter > sequences that can become single characters. I can sympathize somewhat > with the set issue (because {} means an empty dict), although set() is > better than set([]); having a short form for that would be of some > advantage. But not if it's hard to type. > ChrisA Of all your objections, the 'google-able' one is the most hard-hitting. Yes its important and I have no answers. What you are missing is that programmers spend 90% of their time reading code 10% writing code You may well be in the super-whiz category (not being sarcastic here) All that will change is upto 70-30. (ecause you rarely make a mistake) You still have to read oodles of others' code I find python (as haskell) sweet because they dont force me read parsing-drudgery like '{}'. Given that a compiler can parse whitespace (python), or '{}' (C) in microseconds whereas I take seconds, this is really terrible economics Increasing the lexical variety of the code is in the same direction [There is no need implied that overdoing it and becoming APL is good :-) ] From rustompmody at gmail.com Mon Mar 24 23:44:51 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 20:44:51 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: <3605803d-ec90-4484-8a3f-37d06d0b1207@googlegroups.com> On Tuesday, March 25, 2014 12:28:16 AM UTC+5:30, Mark H. Harris wrote: > On 3/24/14 4:58 AM, Mark Lawrence wrote: > > Where do you get reduce from if it's not in the standard library? > That was "a" proposal for 3000. Its there, but its not on the > built-ins; ie., you have to import it. The confusion: why reduce, why > not filter, nor map? {rhetorical} > > As for lambda I've no real interest in it, other than when copying examples > > where it's used to (say) provide a key function. > This is one of my main points to Steven. In my experience "most" people > do not intend to use lambda for anything; they are trying to sort this > or that and don't quite know how to get the key right and some helpful > somebody gives them a key=lambda yadda yadda . They use it, and it > works, but they are scratching their head saying to themselves, "what it > that, how does it work, how can I understand it and on and on". Your example backfires more than you perhaps realize 1. Most people who-have-not-heard-of (WHNHO) generators dont intend to use generators. Somebody shows then a couple of uses and they then find them useful in other contexts 2. Most programmers coming from C where vararg exists but is really much too painful to use outside of printf, dont want to use default arguments. Somebody shows them default arguments then they find nifty uses for the same 3. Most people WHNHO special methods ... 4. Most people WHNHO slices ... Just sayin... > That is what we mean by confusing. Or another really great example is > this thread. Somebody asks about a language feature and somebody else > helpfully answers the question by providing them with a similar lambda!! I am not in pro or anti lambda camp. My grouses are 3, all re comprehensions 1. Technical: I consider the comprehension binding rules wrong -- not lambda 2. Methodological: Experienced people showing comprehensions as 'nothing more than' a short-form for a for-loop are being less helpful to the noob than they know. 3. Pedagogical: Comprehensions are hard, for loops are easy. To convey comprehensions two contrasting perspectives are needed: 1. The for-loop view 2. The set-theory view Give only one, and misunderstandings and confusions proliferate Yes 'only one' can be either one. In the haskell world the pedagogical error tends to be the opposite to the one out here: Noobs write: [... x in l, y in m,...] and wonder why the efficiency is vastly different from [... y in m, x in l, ...] Comes from emphasising the declarative (set-theory) view too much, the imperative (for-loop) view too little From harrismh777 at gmail.com Mon Mar 24 23:48:04 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 22:48:04 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> <5330df9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/24/14 8:45 PM, Steven D'Aprano wrote: > Your insistence that lambda is confusing is awfully condescending. People > are not as dumb as you insist, and they are perfectly capable of learning > lambda without a comp sci degree. Like any technical jargon, there is > vocabulary and meaning to learn, but the concept is no more difficult > than ordinary def functions. This is an Ad Hominem. My opinion that lambda is confusing must not be construed to mean condescension; not coming from my pen. I do not insist that people are dumb, nor do I insist that people cannot learn python without a comp sci degree. Pushing those words into my mouth and then beating me up for saying them is, well, ad hominem. What I am insisting is that *many* people, as point of fact, are confused by the python lambda construct particularly when it is embedded within a for x in and the lambda is supposed to capture the value x (as in my previous examples). This say nothing of their intelligence and says nothing about my supposed motive of condescension. (we my judge actions, but not motives) I am advocating for understanding, among all python users--- novice and expert alike. Especially when I find so many experts who want to "know" (like the OP on this thread) and other experts who (like ecumenical councils) cannot agree (also noticed on this thread). I am not seeking over simplification, and I am not seeking to limit the expert in any way; just advocating for Aristotle's mean, whereat we find virtue. marcus From rosuav at gmail.com Mon Mar 24 23:51:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 14:51:00 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 2:29 PM, Roy Smith wrote: > I started programming on 029 keypunches and ASR-33 teletypes. If you asked me to > type most of the punctuation we take for granted today (not to mention lower case > letters), I would have looked at you as if you had asked me to type something in greek. > > Hardware evolves. I assume that future generations of programmers will have input > devices better suited to unicode than the clumsy keyboards we use today. And there you have a circular problem. Until the bulk of programmers have access to such keyboards, programming languages shouldn't use such symbols (because most of their users won't be able to type them); and until programming languages make use of those symbols, there's little reason to put them on keyboards. Supporting both may look tempting, but you effectively create two ways of spelling the exact same thing; it'd be like C's trigraphs. Do you know what ??= is, without looking it up? [1] ChrisA [1] I will accept "An obfuscation tool" as a correct answer here. From rosuav at gmail.com Mon Mar 24 23:57:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 14:57:02 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 2:43 PM, Rustom Mody wrote: > What you are missing is that programmers spend > 90% of their time reading code > 10% writing code > > You may well be in the super-whiz category (not being sarcastic here) > All that will change is upto 70-30. (ecause you rarely make a mistake) > You still have to read oodles of others' code No, I'm not missing that. But the human brain is a tokenizer, just as Python is. Once you know what a token means, you comprehend it as that token, and it takes up space in your mind as a single unit. There's not a lot of readability difference between a one-symbol token and a one-word token. Also, since the human brain works largely with words, you're usually going to grok things based on how you would read them aloud: x = y + 1 eggs equals why plus one They take up roughly the same amount of storage space. One of them, being a more compact notation, lends itself well to a superstructure of notation; compare: x += 1 eggs plus-equals one inc eggs You can eyeball the first version and read it as the third, which is a space saving in your brain. But it's not fundamentally different from the second. So the saving from using a one-letter symbol that's read "lambda" rather than the actual word "lambda" is extremely minimal. Unless you can use it in a higher-level construct, which seems unlikely in Python (maybe it's different in Haskell? Maybe you use lambda more and actually do have those supernotations?), you won't really gain anything. ChrisA From rustompmody at gmail.com Mon Mar 24 23:56:19 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 20:56:19 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> On Tuesday, March 25, 2014 8:47:35 AM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 2:00 PM, Rustom Mody wrote: > > Yeah: Its 2014 (at least out here)... > > About time we started using unicode in earnest dont you think?? > We do. > > Id like to see the following spellings corrected: > > lambda to ? > > in to ? > > (preferably with the 'in' predicate and the 'in' in 'for' disambiguated) > > set([]) to ? > The problems with these is not Unicode or a lack thereof, but keys. I > know how to type "lambda" on any keyboard I reach for; if it's a > full-sized QWERTY variant, I can type it without looking, and if it's > something else then I can peer at the thing and find the appropriate > five letters. (Phone keyboards are notoriously peer-worthy.) How do I > type ?? Do I have to memorize an alt-key sequence? Do I need to keep a > set of "language keywords" in a file somewhere so I can copy and > paste? Does my editor have to provide them? > What is really gained by using the short-hand? It becomes nigh > ungoogleable; yes, you can paste ? into Google and find out that it's > called lambda (and, if Python used that as a keyword, you could type > "? python" into Google and get to the docs), but how do you figure out > which part of this to search for? > sockets.sort(key=?data:data[1]) > More likely you'd search for "sockets" or "sort" or maybe "key" or > "data", but you wouldn't expect to search for the symbol. > > And some parentheses disambiguation > > Internal ambiguity: Is '(...)' a paren? a function? a tuple? > > External ambiguity: {} in python vs in set theory > I don't know about the difference between {} in set theory and Python, > but the multiple uses of () actually boil down to two: In set theory {} makes sets In python {} makes dictionaries > 1) Grouping, which includes tuples; there's a special case whereby > grouping nothing makes a zero-item tuple, but everything else is just > the comma > 2) Functions (both definition and call) > Disambiguating them might be of some small value, but since they're > the same in pretty much every language under the sun, it would feel What 'they'?? I dont get: If you are talking of disambiguating function definition and call -- yeah thats overkill If you are talking of overlap between tuples parentheses and function (call) well consider f(x,y) vs f((x,y)) vs (x,y) vs ((x,y)) Paren vs tuples: why do we need to write (x,) not (x) All this is because () is doing triple-duty From harrismh777 at gmail.com Mon Mar 24 23:59:57 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 24 Mar 2014 22:59:57 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On 3/24/14 10:51 PM, Chris Angelico wrote: > Supporting both may look tempting, but you effectively create two ways > of spelling the exact same thing; it'd be like C's trigraphs. Do you > know what ??= is, This was a fit for me, back in the day IBM (system36 & system38). When we started supporting the C compiler (ha!) and non of our 5250 terminals could provide the C punctuation we take for granted today--- so we invented tri-graphs for { and } and others. It was a hoot. I personally think the answer is extended key maps triggered by meta keys shift ctrl opt alt command | which call up full alternate mappings of Greek|Latin|Math|symbols &c which can be chosen by mouse|pointing device. The mac calls these keyboard viewer, and character viewer. In that way the full unicode set can be available from a standard qwerty keyboard without modifying the hardware right away. marcus From rustompmody at gmail.com Tue Mar 25 00:08:29 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 21:08:29 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> On Tuesday, March 25, 2014 9:29:57 AM UTC+5:30, Mark H. Harris wrote: > On 3/24/14 10:51 PM, Chris Angelico wrote: > > Supporting both may look tempting, but you effectively create two ways > > of spelling the exact same thing; it'd be like C's trigraphs. Do you > > know what ??= is, > This was a fit for me, back in the day IBM (system36 & system38). When > we started supporting the C compiler (ha!) and non of our 5250 terminals > could provide the C punctuation we take for granted today--- so we > invented tri-graphs for { and } and others. It was a hoot. > I personally think the answer is extended key maps triggered by meta > keys shift ctrl opt alt command | which call up full alternate mappings > of Greek|Latin|Math|symbols &c which can be chosen by mouse|pointing > device. > The mac calls these keyboard viewer, and character viewer. In that way > the full unicode set can be available from a standard qwerty keyboard > without modifying the hardware right away. I think Roy is right in saying that what looks unrealistic with one technology looks natural with another (out phones are already handling speech and handwriting) And Chris is right in (rephrasing) we may have unicode-happy OSes and languages. We cant reasonably have unicode-happy keyboards. [What would a million-key keyboard look like? Lets leave the cost aside...] Problem is that unicode deals with very different sides: Universality of the math language Locality of the zillions of human languages If any character could be a variable, distinguishing the different things that look like 'A' would be a nightmare From rosuav at gmail.com Tue Mar 25 00:14:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 15:14:30 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 2:56 PM, Rustom Mody > I don't know about the difference between {} in set theory and Python, >> but the multiple uses of () actually boil down to two: > > In set theory {} makes sets > In python {} makes dictionaries That's a backward-compatibility issue. Braces in Python meant a dictionary before it acquired a set type (at least, so I learned in history class - I wasn't using Python back then), so empty braces have to continue to mean empty dictionary. I sympathize with the confusion, but short of confusing everyone terribly by changing dicts to use something other than braces (maybe borrow Pike's mapping notation, ([ ])??), I don't really see a solution. >> 1) Grouping, which includes tuples; there's a special case whereby >> grouping nothing makes a zero-item tuple, but everything else is just >> the comma > >> 2) Functions (both definition and call) > >> Disambiguating them might be of some small value, but since they're >> the same in pretty much every language under the sun, it would feel > > What 'they'?? I dont get: If you are talking of disambiguating function definition and call -- yeah thats overkill No no. Disambiguating grouping and fuction definition/call. There's no reason to have definition and call of functions differ. > If you are talking of overlap between tuples parentheses and function (call) > well consider > f(x,y) vs f((x,y)) vs (x,y) vs ((x,y)) > Paren vs tuples: why do we need to write (x,) not (x) > > All this is because () is doing triple-duty Tuples don't use parentheses. You only confuse yourself when you insist on that. The only case with parens that actually makes a tuple is the special empty tuple; imagine if that were given a name instead, like "Empty". That would solve that confusion. There's another minorly special case, and that's that the trailing comma is mandatory on a one-item tuple. In all others, it's optional, but the one-item tuple would be ambiguous otherwise. >>> len((1,2,3,)) 3 >>> len((1,2,)) 2 >>> len((1,)) 1 (By the way, bringing in another discussion: The comma isn't part of the element, nor is it exactly a separator, nor is it exactly a terminator. Just like a newline in a text file.) So the only ambiguity is between function calls and grouping. Tuples are just part of grouping, in that you need to disambiguate a one-tuple-arg function call from a multiple-arg function call - as in the above len() calls. And that's where I think it would be highly confusing to mandate something different. Suppose we used $( )$ for function calls, and ^( )^ for grouping: x = ^(1 + 2)^ * 3 y = range$(x)$ What have we gained by distinguishing them? Not a lot. If an open parenthesis immediately follows another token, it's calling that previous token; if it follows an operator, it's grouping. Seems pretty simple to me. (Cue the spate of emails pointing out something I've missed that breaks that rule, in which case call it a rule of thumb.) ChrisA From rosuav at gmail.com Tue Mar 25 00:19:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 15:19:50 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 2:59 PM, Mark H Harris wrote: > I personally think the answer is extended key maps triggered by meta keys > shift ctrl opt alt command | which call up full alternate mappings of > Greek|Latin|Math|symbols &c which can be chosen by mouse|pointing device. > > > The mac calls these keyboard viewer, and character viewer. In that way the > full unicode set can be available from a standard qwerty keyboard without > modifying the hardware right away. I can get up a character map on any platform fairly easily, and if not, I can always Google the name of the character I want and copy and paste from fileformat.info or some other handy site. It's not that hard. But if I want to say "copyright", it's still quicker for me to type nine letters than to hunt down U+00A9 ? to paste in somewhere. Even more so with lambda, which is a shorter word and a less common symbol (having an easy way to type A9 isn't uncommon these days, but not many give an easy way to type U+03BB). I'm much more comfortable typing that out. ChrisA From rosuav at gmail.com Tue Mar 25 00:29:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 15:29:48 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 3:08 PM, Rustom Mody wrote: > And Chris is right in (rephrasing) we may have unicode-happy OSes and > languages. We cant reasonably have unicode-happy keyboards. > [What would a million-key keyboard look like? Lets leave the cost aside...] Actually, it wouldn't be that bad. Unicode allows for only 1114112 characters (thanks to UTF-16), of which only the first three planes have any actual characters on them (so, a maximum of about 200K characters). All you'd need would be a system that organizes them (using their hex codepoints isn't exactly useful), and you could type any character with a maximum of, say, 6-8 keystrokes; Huffman coded, of course, so the average would be 1.5 keystrokes per character actually used. Add one meta key: Charset. Hold that and press L and you get (say) ?, U+03BB; Charset+Shift+L is ?, U+039B. Ctrl+Charset+L might give you a Cyrillic ? (U+043B), and Ctrl+Charset+Shift+L would then be ? (U+041B), the upper-case version of that. Emacs users would love it. ChrisA From rustompmody at gmail.com Tue Mar 25 01:00:23 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 22:00:23 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tuesday, March 25, 2014 9:59:48 AM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 3:08 PM, Rustom Mody wrote: > > And Chris is right in (rephrasing) we may have unicode-happy OSes and > > languages. We cant reasonably have unicode-happy keyboards. > > [What would a million-key keyboard look like? Lets leave the cost aside...] > Actually, it wouldn't be that bad. Unicode allows for only 1114112 > characters (thanks to UTF-16), of which only the first three planes > have any actual characters on them (so, a maximum of about 200K > characters). All you'd need would be a system that organizes them > (using their hex codepoints isn't exactly useful), and you could type > any character with a maximum of, say, 6-8 keystrokes; Huffman coded, > of course, so the average would be 1.5 keystrokes per character > actually used. Add one meta key: Charset. Hold that and press L and > you get (say) ?, U+03BB; Charset+Shift+L is ?, U+039B. Ctrl+Charset+L > might give you a Cyrillic ? (U+043B), and Ctrl+Charset+Shift+L would > then be ? (U+041B), the upper-case version of that. > Emacs users would love it. Its already there -- and even easier Switch to cyrillic-jis-russian (whatever that is!) and I get ? from k ? from K Full layout +----------------------------------------------------------------+ |? ?|? ?|? ?|? ? |? ?|? ?|? ?|? ?|? ?|? ?| ? ?|? ?| ? ? | +----------------------------------------------------------------+ | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | +------------------------------------------------------------+ | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? |? ?| +-----------------------------------------------------------+ | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? | ? ? |? ?| +-------------------------------------------------+ +-----------------------------+ | space bar | +-----------------------------+ The catch is in the claim to huffman coding Huffman coding requires a statistical distribution Whose shall we take And now the discussion is political not technical From rosuav at gmail.com Tue Mar 25 01:08:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 16:08:43 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 4:00 PM, Rustom Mody wrote: > Its already there -- and even easier > Switch to cyrillic-jis-russian (whatever that is!) > and I get ? from k ? from K How quickly can you switch, type one letter (to generate one Cyrillic character), and switch back? If you can do that more quickly than typing a word, then (for you!) it might be worth using those letters as symbols. ChrisA From harrismh777 at gmail.com Tue Mar 25 01:14:42 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 00:14:42 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On 3/25/14 12:08 AM, Chris Angelico wrote: > How quickly can you switch, type one letter (to generate one Cyrillic > character), and switch back? ... very fast. Is not this nicer? >>> ? = pi >>> >>> sin(?/4) 0.7071067811865475 >>> >>> cos(?/4) 0.7071067811865476 >>> my pdeclib constants extension will have alternate spellings for ? and ? and ? and others... But what if python had a math symbols extension so that universal mathematics could be written the way we do it on a black|board, er, I mean white|board? marcus From rustompmody at gmail.com Tue Mar 25 01:23:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 22:23:26 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: <4576875e-29cf-42b4-ac8d-2f75fadebe20@googlegroups.com> On Tuesday, March 25, 2014 10:38:43 AM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 4:00 PM, Rustom Mody wrote: > > Its already there -- and even easier > > Switch to cyrillic-jis-russian (whatever that is!) > > and I get ? from k ? from K > How quickly can you switch, type one letter (to generate one Cyrillic > character), and switch back? If you can do that more quickly than > typing a word, then (for you!) it might be worth using those letters > as symbols. Well Russian is Greek to me (or more correctly Russian!) So Ive no clue about ergonomics So let me talk of which input methods I use -- devanagari and tex. I have devanagari-itrans set up in emacs as default (other) input method So Ctrl-\ (ie 1? keystrokes) puts emacs into devanagari mode For tex Ive to type the keystroke for invoking 'set-input-method' then spell out the input method (there seem to be hundreds) RET Considering that I use tex much more than devanagari I guess I should switch the default to tex From rosuav at gmail.com Tue Mar 25 01:27:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 16:27:33 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 4:14 PM, Mark H Harris wrote: > On 3/25/14 12:08 AM, Chris Angelico wrote: > >> How quickly can you switch, type one letter (to generate one Cyrillic >> character), and switch back? > > > ... very fast. > > Is not this nicer? > >>>> ? = pi >>>> >>>> sin(?/4) > 0.7071067811865475 >>>> >>>> cos(?/4) > 0.7071067811865476 >>>> > > my pdeclib constants extension will have alternate spellings for ? and ? > and ? and others... That's good! (Although typing ? quicker than pi is majorly pushing it. I can type pi with two keystrokes. But for longer keywords, that's the way it needs to be.) You can be at the front of the curve - using non-ASCII symbols as identifiers, which a number of languages happily support. Using them as keywords in the language means that it has to be not just you, but the bulk of programmers; otherwise there have to be two ways to do everything, and everyone has to learn both of them. (Once, say, 99% of programmers can happily type all those symbols, the fact that 1% of programmers are using the word "lambda" will just be a matter to be dealt with in legacy code - same as seeing "range" vs "xrange" in Python 2 code. New code needn't concern itself with the difference.) Unfortunately, at the moment it's more like 1% of programmers can easily type those symbols, I would guess. ChrisA From steve at pearwood.info Tue Mar 25 01:28:29 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 05:28:29 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533113fd$0$29878$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 06:57:19 +1100, Chris Angelico wrote: > Can you imagine a high level language without a simple notation for > variable assignment? Certainly not. I don't know... what a stack based or concatenative language like Forth, Postscript, Joy or Factor count as high-level? I'm pretty sure Joy and Factor should. Perhaps not Forth or Postscript. Some of these language may offer variable assignment, but using it is entirely optional. It's a convenience, nothing more. -- Steven From rustompmody at gmail.com Tue Mar 25 01:28:52 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 22:28:52 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tuesday, March 25, 2014 10:44:42 AM UTC+5:30, Mark H. Harris wrote: > On 3/25/14 12:08 AM, Chris Angelico wrote: > > How quickly can you switch, type one letter (to generate one Cyrillic > > character), and switch back? > ... very fast. > Is not this nicer? > >>> ? = pi > >>> sin(?/4) > 0.7071067811865475 > >>> cos(?/4) > 0.7071067811865476 Looks ugly here (both Google groups and emacs) But I think you meant small pi not capital. Redoing: ? = pi >>> sin(?/4) 0.7071067811865475 >>> cos(?/4) 0.7071067811865476 Looks better in emacs Input with tex mode -- 1 char to switch slightly verbose to type -- \pi gives ? \Pi gives ? Now to check GG... From rosuav at gmail.com Tue Mar 25 01:31:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 16:31:26 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <4576875e-29cf-42b4-ac8d-2f75fadebe20@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <4576875e-29cf-42b4-ac8d-2f75fadebe20@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 4:23 PM, Rustom Mody wrote: > So let me talk of which input methods I use -- devanagari and tex. > I have devanagari-itrans set up in emacs as default (other) input method > So Ctrl-\ (ie 1? keystrokes) puts emacs into devanagari mode Yes, but putting emacs into a different mode, typing one letter, and putting it back into the other mode is going to be more like 5 keystrokes. And that lets you have just one other input method; if you have more than two, the cost will be higher. So replacing "lambda" with "?" is a minimal saving, practically zip [1] when you consider the readability cost of having two ways of spelling the exact same thing. For this to be useful, you'd need to be able to both read and write much more efficiently. It has to be something where you can quickly switch from ASCII letters and symbols to a non-ASCII lambda and back to ASCII for the arguments and expression. ChrisA [1] No offense meant to the builtin function! From harrismh777 at gmail.com Tue Mar 25 01:34:40 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 00:34:40 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On 3/25/14 12:27 AM, Chris Angelico wrote: >> my pdeclib constants extension will have alternate spellings for ? and ? >> and ? and others... > > That's good! (Although typing ? quicker than pi is majorly pushing it. Well, I'll tell ya, its exactly the same--- two key-strokes, believe it or not. Because the character selector is up on the gui (for me, far left) and the two strokes are {mouse click the ? } and {mouse click the insert}; rather than {p} {i} . There is of course a brief time-lag because my right hand has to move the pointing device and my hand is off the keyboard momentarily -- that is not a problem though, on my track pad notebook. marcus PS Is it Tuesday 04:35 pm there? Its Tuesday way AM here; 00:35am From harrismh777 at gmail.com Tue Mar 25 01:36:10 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 00:36:10 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On 3/25/14 12:28 AM, Rustom Mody wrote: > ? = pi >>>> sin(?/4) > 0.7071067811865475 >>>> cos(?/4) > 0.7071067811865476 > > Looks better in emacs > Input with tex mode -- 1 char to switch > slightly verbose to type -- \pi gives ? \Pi gives ? Whoohoo... yes, way more betterer/ :) From frank at chagford.com Tue Mar 25 01:41:27 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 25 Mar 2014 07:41:27 +0200 Subject: Question about Source Control References: <19d3ddc9-0fb9-476d-a117-e5f174eca85c@googlegroups.com> Message-ID: "Rustom Mody" wrote in message news:19d3ddc9-0fb9-476d-a117-e5f174eca85c at googlegroups.com... > On Monday, March 17, 2014 6:36:33 PM UTC+5:30, Frank Millman wrote: >> Hi all > >> I know I *should* be using a Source Control Management system, but at >> present I am not. I tried to set up Mercurial a couple of years ago, but >> I >> think I set it up wrongly, as I got myself confused and found it more of >> a >> hindrance than a help. Now I am ready to try again, but I want to avoid >> my >> earlier mistakes. > > > Seen this?? > Yeah may not apply directly to your use-case buts seems worth a read > https://www.kernel.org/pub/software/scm/git/docs/gitworkflows.html > > [At command line > $ git help -w workflows > will give you the same > ] Thanks, Rustom, that was a very interesting read. I have made a shortcut to it so that I can refer back to it as my understanding grows. Frank From rosuav at gmail.com Tue Mar 25 01:43:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 16:43:40 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533113fd$0$29878$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> <533113fd$0$29878$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 4:28 PM, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 06:57:19 +1100, Chris Angelico wrote: > >> Can you imagine a high level language without a simple notation for >> variable assignment? Certainly not. > > I don't know... what a stack based or concatenative language like Forth, > Postscript, Joy or Factor count as high-level? > > I'm pretty sure Joy and Factor should. Perhaps not Forth or Postscript. > > Some of these language may offer variable assignment, but using it is > entirely optional. It's a convenience, nothing more. Ah, sorry. I meant in languages that do have a concept of variable assignment. Yes, some don't have it at all, so of course they don't offer any notation for it. But any reasonably modern symbolic language is not going to have a long and wordy notation for assignment, because assignment is so common. It's language design Huffman coding: the features programmers are expected to use frequently are given convenient notations. A stack-based language will have extremely convenient notations for "push this onto the stack", something like "Put potatoes into the mixing bowl. Put dijon mustard into the mixing bowl. Put lard into the mixing bowl." (okay, so Chef might not be the best language to demonstrate this with!). A basic iterative for loop is considered extremely common. C has a highly compact notation that packs three parts into a simple header; REXX has a more piece-meal approach whereby "DO I=start" can be followed by any combination of "TO stop", "BY step", "WHILE condition", "UNTIL condition", and "FOR count", each of which has the same effect on its own or in combination with others. (I think WHILE and UNTIL might be incompatible with each other, but none of the others conflict. Having TO and FOR in the same loop header means it'll stop when either condition is reached.) And Python doesn't have any such construct, but *only* a 'foreach'. That's what I was talking about; and yet it works quite nicely. ChrisA From rustompmody at gmail.com Tue Mar 25 01:42:56 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 22:42:56 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: <2228e770-e67f-4713-b2f3-5f1e98a27e89@googlegroups.com> On Tuesday, March 25, 2014 11:04:40 AM UTC+5:30, Mark H. Harris wrote: > On 3/25/14 12:27 AM, Chris Angelico wrote: > >> my pdeclib constants extension will have alternate spellings for ? and ? > >> and ? and others... > > That's good! (Although typing ? quicker than pi is majorly pushing it. > Well, I'll tell ya, its exactly the same--- two key-strokes, believe it > or not. > Because the character selector is up on the gui (for me, far left) and > the two strokes are {mouse click the ? } and {mouse click the insert}; > rather than {p} {i} . There is of course a brief time-lag because my > right hand has to move the pointing device and my hand is off the > keyboard momentarily -- that is not a problem though, on my track pad > notebook. You are not counting mouse For an emacs user Looking at mouse counts as 3 keystrokes Touching is more like 5-8 https://sites.google.com/site/steveyegge2/effective-emacs vi is probably even more hardcore in that vi is more economical ergonomially From rosuav at gmail.com Tue Mar 25 01:48:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 16:48:43 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 4:34 PM, Mark H Harris wrote: > Because the character selector is up on the gui (for me, far left) and the > two strokes are {mouse click the ? } and {mouse click the insert}; rather > than {p} {i} . There is of course a brief time-lag because my right hand > has to move the pointing device and my hand is off the keyboard momentarily > -- that is not a problem though, on my track pad notebook. I'd like to see millisecond timings for that; for most people, typing is WAY quicker than seeking with the mouse, as you can type without feedback but clicking requires that you see that the mouse is in the right place before you hit the button. (I'm typing this, right now, with my eyes on my MUD client on the screen 90? away from this computer. I'm reading the text that other people have sent to me while writing this text. The human brain can handle that, but only so long as I don't need my eyes to also be on the screen where I'm typing - which means my fingers need a measure of autonomy.) > PS Is it Tuesday 04:35 pm there? Its Tuesday way AM here; 00:35am Yup. Welcome to timezones. I'm UTC +11 here, although we'll drop back to +10 shortly as DST finishes (yay!). It's currently 0547 UTC, so you're presumably five hours behind UTC, which would put you east coast USA, most likely. (Especially since your mailer is putting the dates as mm/dd/yy, which is an abomination peculiar to Americans.) ChrisA From steve at pearwood.info Tue Mar 25 01:47:51 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 05:47:51 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> On Tue, 25 Mar 2014 14:57:02 +1100, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 2:43 PM, Rustom Mody > wrote: >> What you are missing is that programmers spend 90% of their time >> reading code >> 10% writing code >> >> You may well be in the super-whiz category (not being sarcastic here) >> All that will change is upto 70-30. (ecause you rarely make a mistake) >> You still have to read oodles of others' code > > No, I'm not missing that. But the human brain is a tokenizer, just as > Python is. Once you know what a token means, you comprehend it as that > token, and it takes up space in your mind as a single unit. There's not > a lot of readability difference between a one-symbol token and a > one-word token. Hmmm, I don't know about that. Mathematicians are heavy users of symbols. Why do they write ? instead of "for all", or ? instead of "subset"? Why do we write "40" instead of "forty"? > Also, since the human brain works largely with words, I think that's a fairly controversial opinion. The Chinese might have something to say about that. I think that heavy use of symbols is a form of Huffman coding -- common things should be short, and uncommon things longer. Mathematicians tend to be *extremely* specialised, so they're all inventing their own Huffman codings, and the end result is a huge number of (often ambiguous) symbols. Personally, I think that it would be good to start accepting, but not requiring, Unicode in programming languages. We can already write: from math import pi as ? Perhaps we should be able to write: setA ? setB -- Steven From harrismh777 at gmail.com Tue Mar 25 01:47:51 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 00:47:51 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2228e770-e67f-4713-b2f3-5f1e98a27e89@googlegroups.com> Message-ID: On 3/25/14 12:42 AM, Rustom Mody wrote: > You are not counting mouse > For an emacs user > Looking at mouse counts as 3 keystrokes ha! I would not be surprised that just "thinking" about the mouse might be worth 3 key-strokes for an emacs user! I use vi all the time; emacs less; depends on the project. But I cannot claim to be an emacs keyboard ninja (sometimes I even have to look up a meta sequence) how many key-strokes is that? never mind... marcus From rosuav at gmail.com Tue Mar 25 01:54:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 16:54:58 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <2228e770-e67f-4713-b2f3-5f1e98a27e89@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2228e770-e67f-4713-b2f3-5f1e98a27e89@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 4:42 PM, Rustom Mody wrote: > You are not counting mouse > For an emacs user > Looking at mouse counts as 3 keystrokes > Touching is more like 5-8 > https://sites.google.com/site/steveyegge2/effective-emacs I think the cost of the mouse varies according to technology. I'm currently working on two systems: my desktop (Sikorsky) with a classic 101-key keyboard (including numpad) and a mouse to the right of it, and my laptop (Traal) with an IBM keyboard with a trackpoint (stick mouse) in the middle of it. I can switch to Traal's mouse almost as quickly as typing a G or H, but Sikorsky's mouse requires me to move my entire arm across from home position to the mouse pad. (Which means I do far FAR better playing a classic first-person shooter on Sikorsky - I keep my left hand on WASD for movement and my right hand on the mouse for orientation and weaponry. Much more efficient than Traal's setup.) But regardless of the exact cost, it's still significant. Switching to the mouse requires (a) moving a finger or hand onto the mouse; (b) pushing the mouse to the right position; (c) sighting the mouse cursor on the screen; (d) adjusting the mouse position until you're where you want to be; and finally (e) clicking, which is roughly the same cost as one keystroke. The costs of a through d depend on environment and circumstances (don't discount step c until you've tried this exercise in bright sunlight), but will usually be of the order of the above 5-8 keystroke figure. You might be able to get it down to 3 keystrokes, but not to 1. ChrisA From harrismh777 at gmail.com Tue Mar 25 01:56:11 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 00:56:11 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On 3/25/14 12:48 AM, Chris Angelico wrote: > Yup. Welcome to timezones. I'm UTC +11 here, although we'll drop back > to +10 shortly as DST finishes (yay!). It's currently 0547 UTC, so > you're presumably five hours behind UTC, which would put you east > coast USA, most likely. (Especially since your mailer is putting the > dates as mm/dd/yy, which is an abomination peculiar to Americans.) No, we're already DST; so we're normally UTC -6, now UTC -5. We're CDST Minnesota (Southeast) Its entirely weird working with people all over the world in seconds 24-7 365 (we're on one tiny planet, you know?) marcus From harrismh777 at gmail.com Tue Mar 25 02:01:10 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 01:01:10 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On 3/25/14 12:48 AM, Chris Angelico wrote: > (Especially since your mailer is putting the > dates as mm/dd/yy, which is an abomination peculiar to Americans.) I did not know that; so is 25 Mar 2014 the preferred way? marcus From steve at pearwood.info Tue Mar 25 02:04:05 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 06:04:05 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: <53311c54$0$2756$c3e8da3$76491128@news.astraweb.com> On Tue, 25 Mar 2014 15:19:50 +1100, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 2:59 PM, Mark H Harris > wrote: >> I personally think the answer is extended key maps triggered by meta >> keys shift ctrl opt alt command | which call up full alternate >> mappings of Greek|Latin|Math|symbols &c which can be chosen by >> mouse|pointing device. >> >> >> The mac calls these keyboard viewer, and character viewer. In that way >> the full unicode set can be available from a standard qwerty keyboard >> without modifying the hardware right away. > > I can get up a character map on any platform fairly easily, and if not, > I can always Google the name of the character I want and copy and paste > from fileformat.info or some other handy site. It's not that hard. But > if I want to say "copyright", it's still quicker for me to type nine > letters than to hunt down U+00A9 ? to paste in somewhere. I hear what you are saying, but that's not *necessarily* the case. Back when I was a Mac user, in the 1980s and 90s, *every* application accepted the same keyboard shortcuts for the entire Mac character set. Nearly all of the chars had trivially simple mnemonics, e.g Option-p for ?. Now, I don't happen to remember what the mnemonic for ? (it has been 20 years since I was regularly using a Mac), but I remember it used to be really easy. Easier to type Option-whatever and get a ? than typing "copyright". So, if applications could standardise on a single interface for at least the common Unicode characters [er, common for who? English speakers? Japanese people? Arabs? Dutch?] then things would be more like 1984 on a Mac... -- Steven From steve at pearwood.info Tue Mar 25 02:07:59 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 06:07:59 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: <53311d3f$0$2756$c3e8da3$76491128@news.astraweb.com> On Tue, 25 Mar 2014 00:14:42 -0500, Mark H Harris wrote: > On 3/25/14 12:08 AM, Chris Angelico wrote: > >> How quickly can you switch, type one letter (to generate one Cyrillic >> character), and switch back? > > ... very fast. > > Is not this nicer? > > >>> ? = pi That's the product operator. py> from unicodedata import name py> name('?') 'GREEK CAPITAL LETTER PI' You want lower-case pi, ?. -- Steven From rosuav at gmail.com Tue Mar 25 02:12:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 17:12:50 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 4:47 PM, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 14:57:02 +1100, Chris Angelico wrote: >> No, I'm not missing that. But the human brain is a tokenizer, just as >> Python is. Once you know what a token means, you comprehend it as that >> token, and it takes up space in your mind as a single unit. There's not >> a lot of readability difference between a one-symbol token and a >> one-word token. > > Hmmm, I don't know about that. Mathematicians are heavy users of symbols. > Why do they write ? instead of "for all", or ? instead of "subset"? > > Why do we write "40" instead of "forty"? Because the shorter symbols lend themselves better to the "super-tokenization" where you don't read the individual parts but the whole. The difference between "40" and "forty" is minimal, but the difference between "86400" and "eighty-six thousand [and] four hundred" is significant; the first is a single token, which you could then instantly recognize as the number of seconds in a day (leap seconds aside), but the second is a lengthy expression. There's also ease of writing. On paper or blackboard, it's really easy to write little strokes and curvy lines to mean things, and to write a bolded letter R to mean "Real numbers". In Python, it's much easier to use a few more ASCII letters than to write ? ?. >> Also, since the human brain works largely with words, > > I think that's a fairly controversial opinion. The Chinese might have > something to say about that. Well, all the people I interviewed (three of them: me, myself, and I) agree that the human brain works with words. My research is 100% scientific, and is therefore unassailable. So there. :) > I think that heavy use of symbols is a form of Huffman coding -- common > things should be short, and uncommon things longer. Mathematicians tend > to be *extremely* specialised, so they're all inventing their own Huffman > codings, and the end result is a huge number of (often ambiguous) symbols. Yeah. That's about the size of it. Usually, each symbol has some read form; "? ? ?" would be read as "Naturals are a subset of Reals" (or maybe "Naturals is a subset of Reals"?), and in program code, using the word "subset" or "issubset" wouldn't be much worse. It would be some worse, and the exact cost depends on how frequently your code does subset comparisons; my view is that the worseness of words is less than the worseness of untypable symbols. (And I'm about to be arrested for murdering the English language.) > Personally, I think that it would be good to start accepting, but not > requiring, Unicode in programming languages. We can already write: > > from math import pi as ? > > Perhaps we should be able to write: > > setA ? setB It would be nice, if subset testing is considered common enough to warrant it. (I'm not sure it is, but I'm certainly not sure it isn't.) But it violates "one obvious way". Python doesn't, as a general rule, offer us two ways of spelling the exact same thing. So the bar for inclusion would be quite high: it has to be so much better than the alternative that it justifies the creation of a duplicate notation. ChrisA From rustompmody at gmail.com Tue Mar 25 02:10:58 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 23:10:58 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: <8b4fd4f8-f626-4b0d-8bda-6b6813ca7403@googlegroups.com> On Tuesday, March 25, 2014 11:17:51 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 14:57:02 +1100, Chris Angelico wrote: > > wrote: > >> What you are missing is that programmers spend 90% of their time > >> reading code > >> 10% writing code > >> You may well be in the super-whiz category (not being sarcastic here) > >> All that will change is upto 70-30. (ecause you rarely make a mistake) > >> You still have to read oodles of others' code > > No, I'm not missing that. But the human brain is a tokenizer, just as > > Python is. Once you know what a token means, you comprehend it as that > > token, and it takes up space in your mind as a single unit. There's not > > a lot of readability difference between a one-symbol token and a > > one-word token. > Hmmm, I don't know about that. Mathematicians are heavy users of symbols. > Why do they write ? instead of "for all", or ? instead of "subset"? > Why do we write "40" instead of "forty"? > > Also, since the human brain works largely with words, > I think that's a fairly controversial opinion. The Chinese might have > something to say about that. > I think that heavy use of symbols is a form of Huffman coding -- common > things should be short, and uncommon things longer. Mathematicians tend > to be *extremely* specialised, so they're all inventing their own Huffman > codings, and the end result is a huge number of (often ambiguous) symbols. > Personally, I think that it would be good to start accepting, but not > requiring, Unicode in programming languages. We can already write: > from math import pi as ? > Perhaps we should be able to write: > setA ? setB Agree with all examples -- chinese being the best! Something that Chris may relate to: You type a music score into lilypond Then call lilypond to convert it into standard western staff notation Why not put up the lilypond (ASCII) directly on the piano/organ when you play? This is far from rhetorical... ABC,Guido,etc (not python's!) have some claim to be *musically* (not just textually) readable and easier to master than standard staff notation Still for someone - used to staff notation - under the standard presumptions of western music: -- harmony -- spelling c# ? d? -- a note is a note ie C to D is as much a note as D to E staff notation is hard to beat From rosuav at gmail.com Tue Mar 25 02:19:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 17:19:10 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 4:56 PM, Mark H Harris wrote: > On 3/25/14 12:48 AM, Chris Angelico wrote: >> >> Yup. Welcome to timezones. I'm UTC +11 here, although we'll drop back >> to +10 shortly as DST finishes (yay!). It's currently 0547 UTC, so >> you're presumably five hours behind UTC, which would put you east >> coast USA, most likely. (Especially since your mailer is putting the >> dates as mm/dd/yy, which is an abomination peculiar to Americans.) > > > No, we're already DST; so we're normally UTC -6, now UTC -5. We're CDST > Minnesota (Southeast) > > Its entirely weird working with people all over the world in seconds 24-7 > 365 (we're on one tiny planet, you know?) It is one small planet, in many ways, yes. Plus, as well as timezones, you have different people working different schedules. Some of us are active in the weird hours of the night, others might be posting from work (a good bit of python-dev traffic right now involves one of Red Hat's Python people, so it's entirely possible he's posting during business hours his time), and others will be active here during their evenings. Net result: The list never goes quiet! >> (Especially since your mailer is putting the >> dates as mm/dd/yy, which is an abomination peculiar to Americans.) > > > I did not know that; so is 25 Mar 2014 the preferred way? Putting the month in words is unambiguous (at least among users of the Gregorian calendar or its derivatives). For numeric dates, there are broadly three competing formats: d/m/y, m/d/y, and y/m/d. (Or using dots or hyphens between the components, or in the case of y/m/d, no separator at all - I'll write today's date as 20140325 in some contexts.) Of them, y/m/d is both the clearest and the least commonly used; with a four-digit year, there's no way it could be confused for anything else. ChrisA From steve at pearwood.info Tue Mar 25 02:16:20 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 06:16:20 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53311f33$0$2756$c3e8da3$76491128@news.astraweb.com> On Mon, 24 Mar 2014 18:44:37 -0500, Mark H Harris wrote: > On 3/24/14 6:01 PM, Chris Angelico wrote: > >> Easy fix. Use the "explicit capture" notation: > >> adders[n] = lambda a, n=n: a+n > >> And there you are, out of your difficulty at once! > > Yes, yes, yes, and example: > > >>>> adders= list(range(4)) > >>>> for n in adders: > > adders[n] = lambda a, n=n: a+n > > > > > >>>> adders[1](3) > >4 > >>>> adders[2](3) > >5 > > But, and this is the big (WHY?) is that necessary? In other words, > its not about experts knowing how to make this work, its about "normal" > people not understanding in the first place why its a problem, and why > the various solutions work to fix it; even though "we" all know that > nothing is 'broken'. The reason this is surprising is that people want their functions to magically read their mind and do what they want, even when they want it to do something different each time. If you have early binding, then people who want late binding will complain that it does the wrong thing. If you have late binding, then people who want early binding will complain that it does the wrong thing. Even when they are the same people. And *none of this has anything to do with lambda*. Functions created with def exhibit the exact same behaviour. -- Steven From steve at pearwood.info Tue Mar 25 02:20:20 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 06:20:20 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53312023$0$2756$c3e8da3$76491128@news.astraweb.com> On Mon, 24 Mar 2014 17:58:11 -0600, Ian Kelly wrote: > On Mon, Mar 24, 2014 at 3:43 PM, Mark H Harris > wrote: >> Aside from the sin of spelling out "lambda," >> should be ( \x y -> x + y ) a b ) but, neither here nor >> there... > > Well no, it *should* be ?x y . x + y but apparently some people don't > have that character on their keyboards, so it gets written as lambda or > \ instead. Holy cow! Is that where the Haskell syntax comes from? I never would have guessed in a million years that backslash \ was meant to be an ASCII-ified version of lambda. What a stupid idea that is. Writing "lambda" out in full is much more sensible. > Personally I dislike the \ style; it doesn't really resemble > a ? that closely, and to me the backslash denotes escape sequences and > set differences. Nor is Python alone in spelling out lambda: Scheme and > Common Lisp spell it the same way. As far as I know the \ for ? is > unique to Haskell. At least they don't spell it "fun". -- Steven From rosuav at gmail.com Tue Mar 25 02:26:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 17:26:48 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53311c54$0$2756$c3e8da3$76491128@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311c54$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 5:04 PM, Steven D'Aprano wrote: >> I can get up a character map on any platform fairly easily, and if not, >> I can always Google the name of the character I want and copy and paste >> from fileformat.info or some other handy site. It's not that hard. But >> if I want to say "copyright", it's still quicker for me to type nine >> letters than to hunt down U+00A9 ? to paste in somewhere. > > I hear what you are saying, but that's not *necessarily* the case. Back > when I was a Mac user, in the 1980s and 90s, *every* application accepted > the same keyboard shortcuts for the entire Mac character set. Nearly all > of the chars had trivially simple mnemonics, e.g Option-p for ?. Now, I > don't happen to remember what the mnemonic for ? (it has been 20 years > since I was regularly using a Mac), but I remember it used to be really > easy. Easier to type Option-whatever and get a ? than typing "copyright". Easy enough with a restricted character set. When you're working with, say, 128 common characters and another 128 less common, it's not too hard to organize keystrokes for them all. > So, if applications could standardise on a single interface for at least > the common Unicode characters [er, common for who? English speakers? > Japanese people? Arabs? Dutch?] then things would be more like 1984 on a > Mac... And that's the problem. So what we'll have is a programming interface that makes it easy to type a bunch of symbols used in code, and it'll differ from pretty much everything else, and if you want to type lambda into an email you have to jump over to your code window, key it in, and then copy/paste... it wouldn't work without it being pretty much universal. ChrisA From steve at pearwood.info Tue Mar 25 02:28:04 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 06:28:04 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: <533121f4$0$2756$c3e8da3$76491128@news.astraweb.com> On Mon, 24 Mar 2014 19:16:15 -0500, Mark H Harris wrote: > On 3/24/14 7:11 PM, Chris Angelico wrote: >> On Tue, Mar 25, 2014 at 10:56 AM, Mark H Harris >> wrote: >>> What is needed is the explicit closure "grab" recommended by ChrisA. >> >> Which does work. You do know why, right? > > Sure. ... but again, that's not the point. The point is NOT can you > explain why it works, the point is that as a lambda construct it is NOT > clear why it works, and because the construct does not match what lambda > users might expect (naturally) there are *constant* questions about it. > > So, again, I'll restate that the community might consider (over time) > whether the confusion created by lambda in python Functions created with def work exactly the same way. If you are surprised by lambda's binding behaviour, and you replace the lambda with def, you will still be confused. You'll have gone from a nice, concise expression to a bulky statement, and be no better off. You'll be worse off. -- Steven From rosuav at gmail.com Tue Mar 25 02:33:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 17:33:24 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <8b4fd4f8-f626-4b0d-8bda-6b6813ca7403@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> <8b4fd4f8-f626-4b0d-8bda-6b6813ca7403@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 5:10 PM, Rustom Mody wrote: > Something that Chris may relate to: > > You type a music score into lilypond > Then call lilypond to convert it into standard western staff notation > > Why not put up the lilypond (ASCII) directly on the piano/organ when you play? > > This is far from rhetorical... ABC,Guido,etc (not python's!) have some > claim to be *musically* (not just textually) readable and easier to > master than standard staff notation > > Still for someone > - used to staff notation > - under the standard presumptions of western music: > -- harmony > -- spelling c# ? d? > -- a note is a note ie C to D is as much a note as D to E > > staff notation is hard to beat I wouldn't say it's hard to beat... I happily beat time while looking at staff notation! (Of course, I shouldn't beat time. He doesn't like that.) Staff notation isn't perfect by any means (and there've been various projects to improve on it), but it's a lot better than the "source code" form in Lilypond. This is partly because my source code tends to look at multiple (often four) separate lines of harmony, often plus a separate line of chords, but when I'm playing, I want to be able to eyeball all of it at once. But I've used WYSIWYG notation editors plenty, and *for note entry* they offer me nothing above Lilypond's notation. I don't yearn to be able to scribble notes on a paper staff, scan it in, and have that functional. I don't look back with longing at NoteWorthy Composer (for which I do own a license, and could probably hunt down the install CD if I tried). There's a huge difference between the two. ChrisA From rustompmody at gmail.com Tue Mar 25 02:35:50 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 23:35:50 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tuesday, March 25, 2014 11:42:50 AM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 4:47 PM, Steven D'Aprano wrote: > > On Tue, 25 Mar 2014 14:57:02 +1100, Chris Angelico wrote: > >> No, I'm not missing that. But the human brain is a tokenizer, just as > >> Python is. Once you know what a token means, you comprehend it as that > >> token, and it takes up space in your mind as a single unit. There's not > >> a lot of readability difference between a one-symbol token and a > >> one-word token. > > Hmmm, I don't know about that. Mathematicians are heavy users of symbols. > > Why do they write ? instead of "for all", or ? instead of "subset"? > > Why do we write "40" instead of "forty"? > Because the shorter symbols lend themselves better to the > "super-tokenization" where you don't read the individual parts but the > whole. The difference between "40" and "forty" is minimal, but the > difference between "86400" and "eighty-six thousand [and] four > hundred" is significant; the first is a single token, which you could > then instantly recognize as the number of seconds in a day (leap > seconds aside), but the second is a lengthy expression. > There's also ease of writing. On paper or blackboard, it's really easy > to write little strokes and curvy lines to mean things, and to write a > bolded letter R to mean "Real numbers". In Python, it's much easier to > use a few more ASCII letters than to write ? ?. > >> Also, since the human brain works largely with words, > > I think that's a fairly controversial opinion. The Chinese might have > > something to say about that. > Well, all the people I interviewed (three of them: me, myself, and I) > agree that the human brain works with words. My research is 100% > scientific, and is therefore unassailable. So there. :) > > I think that heavy use of symbols is a form of Huffman coding -- common > > things should be short, and uncommon things longer. Mathematicians tend > > to be *extremely* specialised, so they're all inventing their own Huffman > > codings, and the end result is a huge number of (often ambiguous) symbols. > Yeah. That's about the size of it. Usually, each symbol has some read > form; "? ? ?" would be read as "Naturals are a subset of Reals" (or > maybe "Naturals is a subset of Reals"?), and in program code, using > the word "subset" or "issubset" wouldn't be much worse. It would be > some worse, and the exact cost depends on how frequently your code > does subset comparisons; my view is that the worseness of words is > less than the worseness of untypable symbols. (And I'm about to be > arrested for murdering the English language.) > > Personally, I think that it would be good to start accepting, but not > > requiring, Unicode in programming languages. We can already write: > > from math import pi as ? > > Perhaps we should be able to write: > > setA ? setB > It would be nice, if subset testing is considered common enough to > warrant it. (I'm not sure it is, but I'm certainly not sure it isn't.) > But it violates "one obvious way". Python doesn't, as a general rule, > offer us two ways of spelling the exact same thing. So the bar for > inclusion would be quite high: it has to be so much better than the > alternative that it justifies the creation of a duplicate notation. I dont think we are anywhere near making real suggestions for real changes which would need to talk of compatibility, portability, editor support and all such other good stuff. Just a bit of brainstorming to see how an alternative python would look like: Heres a quickly made list of symbols that may be nice to have support for ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (ellipsis instead of range) From rustompmody at gmail.com Tue Mar 25 02:41:57 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 23:41:57 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> <8b4fd4f8-f626-4b0d-8bda-6b6813ca7403@googlegroups.com> Message-ID: <592062d8-37a1-4f80-a9db-b3b17a6215b9@googlegroups.com> On Tuesday, March 25, 2014 12:03:24 PM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 5:10 PM, Rustom Mody wrote: > > Something that Chris may relate to: > > You type a music score into lilypond > > Then call lilypond to convert it into standard western staff notation > > Why not put up the lilypond (ASCII) directly on the piano/organ when you play? > > This is far from rhetorical... ABC,Guido,etc (not python's!) have some > > claim to be *musically* (not just textually) readable and easier to > > master than standard staff notation > > Still for someone > > - used to staff notation > > - under the standard presumptions of western music: > > -- harmony > > -- spelling c# ? d? > > -- a note is a note ie C to D is as much a note as D to E > > staff notation is hard to beat > I wouldn't say it's hard to beat... I happily beat time while looking > at staff notation! > (Of course, I shouldn't beat time. He doesn't like that.) > Staff notation isn't perfect by any means (and there've been various > projects to improve on it), but it's a lot better than the "source > code" form in Lilypond. This is partly because my source code tends to > look at multiple (often four) separate lines of harmony, often plus a > separate line of chords, but when I'm playing, I want to be able to > eyeball all of it at once. ALl of which is isomorphic to Steven's point that forty is less eyeballable than 40 And mine that ? is more eyeballable than set([]) From rosuav at gmail.com Tue Mar 25 02:45:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 17:45:11 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 5:35 PM, Rustom Mody wrote: > I dont think we are anywhere near making real suggestions for real changes > which would need to talk of compatibility, portability, editor support > and all such other good stuff. > > Just a bit of brainstorming to see how an alternative python would look like: > > Heres a quickly made list of symbols that may be nice to have support for > > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? > ? (ellipsis instead of range) Most of those look fine, but that's a fair bunch of characters you'd need to type. And will you stop there? Would other symbols want to be typable too? And if you have ellipsis (the character) would you also support three consecutive U+002E to mean the same thing? (People *will* type it that way, and would be extremely annoyed if it didn't work.) And will you turn Python into APL? ChrisA From harrismh777 at gmail.com Tue Mar 25 02:48:00 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 01:48:00 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On 3/25/14 12:08 AM, Chris Angelico wrote: > How quickly can you switch, type one letter (to generate one Cyrillic > character), and switch back? Ok.. after installing Ukelete from Summer Institute of Linguistics SIL I can now edit the installed keymaps and select them from input sources at the top of the menu bar. So, I mapped the alt-l key to ? and whalla, lambda in zero time; whoohoo. Same for ?, just alt-p. Control has an entire blank page for key mappings so the sky is the limit. very fast, no mouse marcus ? ? From rosuav at gmail.com Tue Mar 25 02:50:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 17:50:53 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <592062d8-37a1-4f80-a9db-b3b17a6215b9@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> <8b4fd4f8-f626-4b0d-8bda-6b6813ca7403@googlegroups.com> <592062d8-37a1-4f80-a9db-b3b17a6215b9@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 5:41 PM, Rustom Mody wrote: > ALl of which is isomorphic to Steven's point that forty is less > eyeballable than 40 > > And mine that ? is more eyeballable than set([]) I don't disagree that it is; the short tokens are easier to read in quantity. I just don't think that it's sufficient to justify piles of new and hard-to-look-up operators and things. (And a literal notation for an empty set would be a good thing. If I were designing a Python-like language from scratch now, I'd probably differentiate sets and dictionaries better, which would allow each one to have its own empty literal.) ChrisA From rustompmody at gmail.com Tue Mar 25 02:52:11 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 24 Mar 2014 23:52:11 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: <8428b099-9130-4a37-8f67-eeeb61a416a8@googlegroups.com> On Tuesday, March 25, 2014 12:15:11 PM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 5:35 PM, Rustom Mody wrote: > > I dont think we are anywhere near making real suggestions for real changes > > which would need to talk of compatibility, portability, editor support > > and all such other good stuff. > > Just a bit of brainstorming to see how an alternative python would look like: > > Heres a quickly made list of symbols that may be nice to have support for > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? > > ? (ellipsis instead of range) > Most of those look fine, but that's a fair bunch of characters you'd > need to type. And will you stop there? Would other symbols want to be > typable too? And if you have ellipsis (the character) would you also > support three consecutive U+002E to mean the same thing? (People > *will* type it that way, and would be extremely annoyed if it didn't > work.) > And will you turn Python into APL? Yes APL is a good example to learn mistakes from - being before its time/technology - taking a good idea too far - assuming that I understand clearly implies so do others - maybe some others As for ellipsis I guess its misguided [Was actually looking for 'center-ellipsis' which would not be so ambiguous] From steve at pearwood.info Tue Mar 25 02:52:13 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 06:52:13 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: <5331279c$0$2756$c3e8da3$76491128@news.astraweb.com> On Mon, 24 Mar 2014 21:39:33 -0500, Mark H Harris wrote: > On 3/24/14 8:20 PM, Terry Reedy wrote: >> On 3/24/2014 7:56 PM, Mark H Harris wrote: > >>> the list which is used for each of the adder[] functions created. >> >> Wrong. Functions look up global and nonlocal names, such as n, when the >> function is called. >> >> > hi Terry, yeah, I know; this is what's *wrong* all at once. > > Functions "look up global and nonlocal names" such as n, is semantics > for "each created function 'grabs' the last number (n) in the list", > well, because that (n) is bound at call-time to (3). > > Your version semantically is detailed and correct; my version > semantically is "how it is perceived" by the user, which is also > correct. No it isn't. You can demonstrate that some mental models are closer to the actual behaviour of the interpreter, while other models are incorrect, by writing just a little more complex code. py> def test(arg): ... results = [] ... for n in [1, 2, 3, 4]: ... results.append(lambda: n) ... n = arg ... return results ... py> for func in test(1000): ... print(func()) ... 1000 1000 1000 1000 The functions don't grab the last value from the list. They see whatever value the variable n has at the time the function is called. Are you surprised by this? If you are, it is because you haven't thought it through in any detail. Let me show you something superficially different: py> funcs = [] py> for n in [1, 2, 3, 4]: ... def f(): ... return n ... funcs.append(f) ... py> n = 1000 py> for f in funcs: ... print(f()) ... 1000 1000 1000 1000 Are you still surprised? I bet you aren't. How else would you expect a variable to work? Early binding may be *useful* sometimes, but it would be terribly surprising if it were the default: my_name = "Fred" def greet(): print("Hello", my_name) my_name = "Barney" greet() Would you expect to see "Hello Fred"? The problem here is that Python is consistent, but people *want* it to be inconsistent. When it doesn't magically read their mind, they get "confused" that it isn't working the way they "expected". -- Steven From steve at pearwood.info Tue Mar 25 03:03:30 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 07:03:30 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: <53312a42$0$2756$c3e8da3$76491128@news.astraweb.com> On Tue, 25 Mar 2014 17:19:10 +1100, Chris Angelico wrote: > I'll write today's date as 20140325 in some contexts.) Of them, > y/m/d is both the clearest and the least commonly used; with a > four-digit year, there's no way it could be confused for anything else. Shame on you Chris! Don't you know the One True Way to write unambiguous dates is the ISO data format? 2014-03-25 -- Steven From steve at pearwood.info Tue Mar 25 03:03:49 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 07:03:49 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> Message-ID: <53312a54$0$2756$c3e8da3$76491128@news.astraweb.com> On Mon, 24 Mar 2014 20:56:19 -0700, Rustom Mody wrote: > Paren vs tuples: why do we need to write (x,) not (x) You don't. You can write x, without the brackets: py> t = 23, py> type(t) It's the comma that makes tuples, not the brackets. -- Steven From rosuav at gmail.com Tue Mar 25 03:12:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 18:12:06 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53312a42$0$2756$c3e8da3$76491128@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53312a42$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 6:03 PM, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 17:19:10 +1100, Chris Angelico wrote: > >> I'll write today's date as 20140325 in some contexts.) Of them, >> y/m/d is both the clearest and the least commonly used; with a >> four-digit year, there's no way it could be confused for anything else. > > Shame on you Chris! Don't you know the One True Way to write unambiguous > dates is the ISO data format? > > 2014-03-25 Bah, BIND won't let me use ISO format! rosuav at sikorsky:~$ dig kepl.com.au soa +short gideon.rosuav.com. domainmaster.kepl.com.au. 2014030601 7200 3600 2419200 604800 Looks like I last edited that on the 6th inst. But yes, hyphens are more common than slashes for delimited ymd dates. ChrisA From rustompmody at gmail.com Tue Mar 25 03:22:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 00:22:27 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53312a54$0$2756$c3e8da3$76491128@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <53312a54$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: <256f713b-c8b9-4cf3-a403-6865288fbef6@googlegroups.com> On Tuesday, March 25, 2014 12:33:49 PM UTC+5:30, Steven D'Aprano wrote: > On Mon, 24 Mar 2014 20:56:19 -0700, Rustom Mody wrote: > > Paren vs tuples: why do we need to write (x,) not (x) > You don't. You can write x, without the brackets: > py> t = 23, > py> type(t) > It's the comma that makes tuples, not the brackets. Yeah Chris already corrected that misconception of mine Doesn't chage my point much though -- () overloaded to ',' overloaded From dieter at handshake.de Tue Mar 25 03:27:04 2014 From: dieter at handshake.de (dieter) Date: Tue, 25 Mar 2014 08:27:04 +0100 Subject: Asyncio (or something better) for control of a vacuum system/components. References: Message-ID: <87y4zy3fhz.fsf@handshake.de> Shishir writes: > ... > I am writing a software to control and monitor a vacuum > furnace+attachments. It has a few mass flow controllers, a butterfly valve, > a labjack unit for analog/digital outputs etc. They use RS485, RS232 and > USB to communicate with the computer and follow special protocols for > commands and response. The response time to execute commands can be from 5 > ms to 1 s. > > To achieve this, I thought of a server which reads commands on a network > connections, parses the command and calls methods of appropriate device > classes, which then use the corresponding channel protocol to execute the > command. The response provided by the devices (flow controllers, valve) is > sent back on the network connection. > > As there can be multiple clients (e.g. for monitoring from several > computers), and some commands can take long, the server should not block > when getting a command executed. "Asyncio" is targeted at asynchronous (i.e. non-blocking) input/output. To ensure that the server remains responsive during command execution, you will need something in addition - e.g. threads or subprocesses. This way, the commands can be executed (by a separate thread/subprocess) while the server is still listening to communication. I know of one framework which supports this kind of interaction: "medusa/ZServer". However, it is targeted mainly towards standard internet communication protocols ("HTTP", "FTP", ...). >From your message, I have gained the impression that you want to support multiple (concurrent) requests on the same communication channel. This significantly complicates the task as the responses to those requests may arrive out of order and may even mix with one another (on the channel), unless you avoid this carefully. The "medusa/ZServer" framework (mentioned above) supports HTTP pipelining (i.e. the client can issue multiple requests without waiting for a response). However, it starts processing of a request only when all previous requests from the same (communication) channel have been completed. This way, it ensures that all responses are delivered in the same order as the requests (as required by HTTP pipelining). If out of order responses must be supported, then "medusa/ZServer" is not an appropriate approach. Special logic is then necessary on both server and client to associate the responses to the proper requests. From dieter at handshake.de Tue Mar 25 03:49:09 2014 From: dieter at handshake.de (dieter) Date: Tue, 25 Mar 2014 08:49:09 +0100 Subject: gdb python how to output integer for examine memory References: Message-ID: <87txam3eh6.fsf@handshake.de> Wesley writes: > I am trying to use gdb debug python script. > I am using gdb7.7 and python2.7.6, here is my simple test script: > import time > > def next(i): > time.sleep(10) > i = 1 - i > > i = 1 > while True: > next(i) > When this script running, gdb attach to it, and here is snippet: > > ... > (gdb) frame 5 > #5 0x00000000004d01a7 in PyEval_EvalFrameEx (f=Frame 0x201e130, for file test.py, line 6, in next (i=1), throwflag=0) at Python/ceval.c:2666 > 2666 x = call_function(&sp, oparg); > (gdb) py-locals > i = 1 > (gdb) pyo i > No symbol "i" in current context. Quite a lot of time has passed since I last had to debug Python processes at C level -- thus, my memory may be unreliable. When I remember right, then "pyo" is used to interprete a C level variable as a Python object (and print it) -- not a Python level variable. In your case, "i" is a Python level variable. You must carefully distinguish between the C level and the Python level. Some commands expect C level names/objects; others may expect Python level names/objects. To learn how you can obtain the value of a Python variable, I see two approaches: look through the list of provided commands (and their documentation) and try to figure out which might be applicable and then may some tests; or look at the implementation of "py-locals" and use this knowledge to define you own command (for this, you will also need to understand the gdb language to define commands). From dieter at handshake.de Tue Mar 25 03:53:12 2014 From: dieter at handshake.de (dieter) Date: Tue, 25 Mar 2014 08:53:12 +0100 Subject: Memory error References: Message-ID: <87ppla3eaf.fsf@handshake.de> Jamie Mitchell writes: > ... > I then get a memory error: > > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line 2409, in pearsonr > x = np.asarray(x) > File "/usr/local/sci/lib/python2.7/site-packages/numpy/core/numeric.py", line 321, in asarray > return array(a, dtype, copy=False, order=order) > MemoryError "MemoryError" means that Python cannot get sufficent memory from the operating system. You have already found out one mistake. Should you continue to get "MemoryError" after this is fixed, then your system does not provide enough resources (memory) to solve the problem at hand. You would need to find a way to provide more resources. From marko at pacujo.net Tue Mar 25 04:05:04 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 25 Mar 2014 10:05:04 +0200 Subject: Time we switched to unicode? References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: <87ior2zosv.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Mar 25, 2014 at 4:14 PM, Mark H Harris wrote: >>>>> ? = pi > > That's good! (Although typing ? quicker than pi is majorly pushing it. It don't think that's good. The lower-case letter ? should be used. The upper-case letter is used for a product, although unicode dedicates a separate character for the purpose: ?. I often see Americans, especially, confuse upper and lower-case letters in symbols ("KM" for "km", "L" for "l" etc). However, we are dealing with case-sensitive programming languages, so our eyes should have been trained to address meaning to upper and lower case. Marko From nispray at gmail.com Tue Mar 25 04:07:13 2014 From: nispray at gmail.com (Wesley) Date: Tue, 25 Mar 2014 01:07:13 -0700 (PDT) Subject: gdb python how to output integer for examine memory In-Reply-To: References: Message-ID: <2aa794ce-7cc1-4d24-a30b-3fb17b89e33f@googlegroups.com> ? 2014?3?25????UTC+8??3?49?09??dieter??? > Wesley writes: > > > > > I am trying to use gdb debug python script. > > > I am using gdb7.7 and python2.7.6, here is my simple test script: > > > import time > > > > > > def next(i): > > > time.sleep(10) > > > i = 1 - i > > > > > > i = 1 > > > while True: > > > next(i) > > > When this script running, gdb attach to it, and here is snippet: > > > > > > ... > > > (gdb) frame 5 > > > #5 0x00000000004d01a7 in PyEval_EvalFrameEx (f=Frame 0x201e130, for file test.py, line 6, in next (i=1), throwflag=0) at Python/ceval.c:2666 > > > 2666 x = call_function(&sp, oparg); > > > (gdb) py-locals > > > i = 1 > > > (gdb) pyo i > > > No symbol "i" in current context. > > > > Quite a lot of time has passed since I last had to debug Python > > processes at C level -- thus, my memory may be unreliable. > > > > When I remember right, then "pyo" is used to interprete > > a C level variable as a Python object (and print it) -- not > > a Python level variable. In your case, "i" is a Python level variable. > > > > You must carefully distinguish between the C level and the Python level. > > Some commands expect C level names/objects; > > others may expect Python level names/objects. > > > > To learn how you can obtain the value of a Python variable, > > I see two approaches: look through the list of provided commands > > (and their documentation) and try to figure out which might be applicable > > and then may some tests; or look at the implementation of "py-locals" > > and use this knowledge to define you own command (for this, > > you will also need to understand the gdb language to define commands). Hi Dieter, Thanks. Actually, I can now see the varialbe names at Python level and C level. I just want to verify x command to monitor the memory content. So, in my origin post, I can get variable i's address, and see the value is 1, then, I wanna have a try x command, the issue is, when use x/format i's address, the output is not 1, but other things:-( From rosuav at gmail.com Tue Mar 25 04:23:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 19:23:45 +1100 Subject: Time we switched to unicode? In-Reply-To: <87ior2zosv.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <87ior2zosv.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 25, 2014 at 7:05 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Mar 25, 2014 at 4:14 PM, Mark H Harris wrote: >>>>>> ? = pi >> >> That's good! (Although typing ? quicker than pi is majorly pushing it. > > It don't think that's good. The lower-case letter ? should be used. The > upper-case letter is used for a product, although unicode dedicates a > separate character for the purpose: ?. > > I often see Americans, especially, confuse upper and lower-case letters > in symbols ("KM" for "km", "L" for "l" etc). However, we are dealing > with case-sensitive programming languages, so our eyes should have been > trained to address meaning to upper and lower case. This has been pointed out multiple times, and I did notice it myself. But it's not significant, and I was trying to avoid nit-picking. If you can type a capital ?, you can type a lower-case ?, unless there's something very weird going on. So it still makes his point. ChrisA From steve at pearwood.info Tue Mar 25 04:59:14 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 08:59:14 GMT Subject: Time we switched to unicode? References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <87ior2zosv.fsf@elektro.pacujo.net> Message-ID: <53314562$0$2756$c3e8da3$76491128@news.astraweb.com> On Tue, 25 Mar 2014 19:23:45 +1100, Chris Angelico wrote: > I was trying to avoid nit-picking What, on comp.lang.python? What's wrong with you? :-) -- Steven From rosuav at gmail.com Tue Mar 25 05:03:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 20:03:05 +1100 Subject: Time we switched to unicode? In-Reply-To: <53314562$0$2756$c3e8da3$76491128@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <87ior2zosv.fsf@elektro.pacujo.net> <53314562$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 7:59 PM, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 19:23:45 +1100, Chris Angelico wrote: > >> I was trying to avoid nit-picking > > What, on comp.lang.python? What's wrong with you? > > > :-) I know, it's like refraining from bike-shedding on python-ideas or not reading the Bible in a Presbyterian church service. But occasionally I do try to be polite, or to make a point without worrying about the detlais... :) ChrisA From antoon.pardon at rece.vub.ac.be Tue Mar 25 05:43:29 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 25 Mar 2014 10:43:29 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: <53314FC1.2010603@rece.vub.ac.be> On 25-03-14 06:08, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 4:00 PM, Rustom Mody wrote: >> Its already there -- and even easier >> Switch to cyrillic-jis-russian (whatever that is!) >> and I get ? from k ? from K > How quickly can you switch, type one letter (to generate one Cyrillic > character), and switch back? If you can do that more quickly than > typing a word, then (for you!) it might be worth using those letters > as symbols. > > ChrisA > I thought programs were read more than written. So if writing is made a bit more problematic but the result is more readable because we are able to use symbols that are already familiar from other contexts, I would say it is worth it. -- Antoon Pardon From rosuav at gmail.com Tue Mar 25 05:54:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 20:54:51 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53314FC1.2010603@rece.vub.ac.be> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> Message-ID: On Tue, Mar 25, 2014 at 8:43 PM, Antoon Pardon wrote: > I thought programs were read more than written. So if writing is made > a bit more problematic but the result is more readable because we are > able to use symbols that are already familiar from other contexts, I > would say it is worth it. It's a matter of extents. If code is read ten times for every time it's written, making it twenty times harder to write and a little bit easier to read is still a bad tradeoff. Also: To what extent IS that symbol familiar from some other context? Are you using Python as a programming language, or should you perhaps be using a mathematical front-end? Not everything needs to perfectly match what anyone from any other context will expect. This is, first and foremost, a *programming* language. ChrisA From dihedral88888 at gmail.com Tue Mar 25 06:17:11 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Tue, 25 Mar 2014 03:17:11 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> Message-ID: <7dd79fea-37c9-4c61-bcb7-22bb5b58b67b@googlegroups.com> > >>> x = [[1, 2], [3, 4]] > > >>> for x in x: > > ... for x in x: > > ... print(x) > This is valid in the syntax level in python. But it is only good for those writing obscure programs in my opinions at most team works. From antoon.pardon at rece.vub.ac.be Tue Mar 25 06:24:29 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 25 Mar 2014 11:24:29 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> Message-ID: <5331595D.5020008@rece.vub.ac.be> On 25-03-14 05:14, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 2:56 PM, Rustom Mody >> I don't know about the difference between {} in set theory and Python, >>> but the multiple uses of () actually boil down to two: >> In set theory {} makes sets >> In python {} makes dictionaries > That's a backward-compatibility issue. Braces in Python meant a > dictionary before it acquired a set type (at least, so I learned in > history class - I wasn't using Python back then), so empty braces have > to continue to mean empty dictionary. No they didn't have to. With the transition to python3, the developers could have opted for empty braces to mean an empty set. And if they wanted a literal for an empty dictionary, they might have chosen {:}. Backward-compatibility was already broken so that wasn't an argument. > I sympathize with the confusion, > but short of confusing everyone terribly by changing dicts to use > something other than braces (maybe borrow Pike's mapping notation, ([ > ])??), I don't really see a solution. Come on. The problem isn't that both set and dictionary literal use braces. That doesn't seem to be a problem in python3. The only question was what should {} represent and how do we get an empty collection of the other kind. If {} had been an empty set, dict() could have been used for an empty dictionary is {:} had been unacceptable. -- Antoon Pardon From jeandubois314 at gmail.com Tue Mar 25 06:26:26 2014 From: jeandubois314 at gmail.com (Jean Dubois) Date: Tue, 25 Mar 2014 03:26:26 -0700 (PDT) Subject: [newbie] confusion concerning fetching an element in a 2d-array Message-ID: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> I'm confused by the behaviour of the following python-script I wrote: #!/usr/bin/env python #I first made a data file 'test.dat' with the following content #1.0 2 3 #4 5 6.0 #7 8 9 import numpy as np lines=[line.strip() for line in open('test.dat')] #convert lines-list to numpy-array array_lines=np.array(lines) #fetch element at 2nd row, 2nd column: print array_lines[1, 1] When running the script I always get the following error: IndexError: invalid index Can anyone here explain me what I am doing wrong and how to fix it? thanks in advance jean From antoon.pardon at rece.vub.ac.be Tue Mar 25 06:38:38 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 25 Mar 2014 11:38:38 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> Message-ID: <53315CAE.8030404@rece.vub.ac.be> On 25-03-14 10:54, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 8:43 PM, Antoon Pardon > wrote: >> I thought programs were read more than written. So if writing is made >> a bit more problematic but the result is more readable because we are >> able to use symbols that are already familiar from other contexts, I >> would say it is worth it. > It's a matter of extents. If code is read ten times for every time > it's written, making it twenty times harder to write and a little bit > easier to read is still a bad tradeoff. > > Also: To what extent IS that symbol familiar from some other context? > Are you using Python as a programming language, or should you perhaps > be using a mathematical front-end? Not everything needs to perfectly > match what anyone from any other context will expect. This is, first > and foremost, a *programming* language. So? We do use + -, so why shouldn't we use ? for multiplication. Would such a use already indicate I should use a mathematical front-end? When a programming language is borrowing concepts from mathematics, I see no reason not to borrow the symbols used too. -- Antoon Pardon. From amit.khomane at gmail.com Tue Mar 25 06:52:47 2014 From: amit.khomane at gmail.com (Amit Khomane) Date: Tue, 25 Mar 2014 03:52:47 -0700 (PDT) Subject: Have you ever wondered why there are so many flavors of python. This post answers all your queries. Message-ID: <9921c06f-c165-4e0a-8550-531aa5c01c01@googlegroups.com> http://www.techdarting.com/2014/03/why-different-flavors-of-python.html From steve+comp.lang.python at pearwood.info Tue Mar 25 07:01:37 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 11:01:37 GMT Subject: [newbie] confusion concerning fetching an element in a 2d-array References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> Message-ID: <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 03:26:26 -0700, Jean Dubois wrote: > I'm confused by the behaviour of the following python-script I wrote: > > #!/usr/bin/env python > #I first made a data file 'test.dat' with the following content > #1.0 2 3 > #4 5 6.0 > #7 8 9 > import numpy as np > lines=[line.strip() for line in open('test.dat')] > #convert lines-list to numpy-array > array_lines=np.array(lines) > #fetch element at 2nd row, 2nd column: > print array_lines[1, 1] > > > When running the script I always get the following error: IndexError: > invalid index > > Can anyone here explain me what I am doing wrong and how to fix it? Yes. Inspect the array by printing it, and you'll see that it is a one- dimensional array, not two, and the entries are strings: py> import numpy as np py> # simulate a text file ... data = """1.0 2 3 ... 4 5 6.0 ... 7 8 9""" py> lines=[line.strip() for line in data.split('\n')] py> # convert lines-list to numpy-array ... array_lines = np.array(lines) py> print array_lines ['1.0 2 3' '4 5 6.0' '7 8 9'] The interactive interpreter is your friend! You never need to guess what the problem is, Python has powerful introspection abilities, one of the most powerful is also one of the simplest: print. Another powerful tool in the interactive interpreter is help(). So, what to do about it? Firstly, convert your string read from a file into numbers, then build your array. Here's one way: py> values = [float(s) for s in data.split()] py> print values [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] py> array_lines = np.array(values) py> array_lines = array_lines.reshape(3, 3) py> print array_lines [[ 1. 2. 3.] [ 4. 5. 6.] [ 7. 8. 9.]] There may be other ways to do this, but that works for me. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Tue Mar 25 07:12:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 22:12:40 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <5331595D.5020008@rece.vub.ac.be> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> Message-ID: On Tue, Mar 25, 2014 at 9:24 PM, Antoon Pardon wrote: > No they didn't have to. With the transition to python3, the developers > could have opted for empty braces to mean an empty set. And if they > wanted a literal for an empty dictionary, they might have chosen {:}. > Backward-compatibility was already broken so that wasn't an argument. Python 3.0 didn't just say "to Hades with backward compatibility". The breakage was only in places where it was deemed worthwhile. Changing the meaning of {} would have only small benefit and would potentially break a LOT of programs, so the devs were right to not do it. Python 3 and Python 2 are not, contrary to some people's opinions, completely different languages. ChrisA From steve+comp.lang.python at pearwood.info Tue Mar 25 07:14:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 11:14:53 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> Message-ID: <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 11:38:38 +0100, Antoon Pardon wrote: > On 25-03-14 10:54, Chris Angelico wrote: >> On Tue, Mar 25, 2014 at 8:43 PM, Antoon Pardon >> wrote: >>> I thought programs were read more than written. So if writing is made >>> a bit more problematic but the result is more readable because we are >>> able to use symbols that are already familiar from other contexts, I >>> would say it is worth it. >> It's a matter of extents. If code is read ten times for every time it's >> written, making it twenty times harder to write and a little bit easier >> to read is still a bad tradeoff. >> >> Also: To what extent IS that symbol familiar from some other context? >> Are you using Python as a programming language, or should you perhaps >> be using a mathematical front-end? Not everything needs to perfectly >> match what anyone from any other context will expect. This is, first >> and foremost, a *programming* language. > > So? We do use + -, so why shouldn't we use ? for multiplication. I can't find ? on my keyboard! I tried using x instead, but I got a syntax error: py> 2x3 File "", line 1 2x3 ^ SyntaxError: invalid syntax > Would > such a use already indicate I should use a mathematical front-end? > > When a programming language is borrowing concepts from mathematics, I > see no reason not to borrow the symbols used too. I'd like to sum the squares of the integers from n=1 to 10. In the old Python, I'd write sum(n**2 for n in range(1, 11)), but with the brave new world of maths symbols, I'd like to write this: http://timmurphy.org/examples/summation_large.jpg How do I enter that, and what text editor should I use? -- Steven D'Aprano http://import-that.dreamwidth.org/ From antoon.pardon at rece.vub.ac.be Tue Mar 25 07:46:14 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 25 Mar 2014 12:46:14 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53316C86.1090709@rece.vub.ac.be> On 25-03-14 12:14, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 11:38:38 +0100, Antoon Pardon wrote: > >> On 25-03-14 10:54, Chris Angelico wrote: >>> On Tue, Mar 25, 2014 at 8:43 PM, Antoon Pardon >>> wrote: >>>> I thought programs were read more than written. So if writing is made >>>> a bit more problematic but the result is more readable because we are >>>> able to use symbols that are already familiar from other contexts, I >>>> would say it is worth it. >>> It's a matter of extents. If code is read ten times for every time it's >>> written, making it twenty times harder to write and a little bit easier >>> to read is still a bad tradeoff. >>> >>> Also: To what extent IS that symbol familiar from some other context? >>> Are you using Python as a programming language, or should you perhaps >>> be using a mathematical front-end? Not everything needs to perfectly >>> match what anyone from any other context will expect. This is, first >>> and foremost, a *programming* language. >> So? We do use + -, so why shouldn't we use ? for multiplication. > I can't find ? on my keyboard! Then use an editor that allows you to configure it, so you can easily use it. That's the kind of advice that is often enough given here if some python feature is hard for the tools someone is using. So why should it be different now? >> Would >> such a use already indicate I should use a mathematical front-end? >> >> When a programming language is borrowing concepts from mathematics, I >> see no reason not to borrow the symbols used too. > I'd like to sum the squares of the integers from n=1 to 10. In the old > Python, I'd write sum(n**2 for n in range(1, 11)), but with the brave new > world of maths symbols, I'd like to write this: > > http://timmurphy.org/examples/summation_large.jpg > > > How do I enter that, and what text editor should I use? You have a point. Blindly following mathematical notation will not work, because mathematics often enough uses positional clues that will be very hard to incorparate in a programming language. But often enough languages tried to use the symbols that were available to them. Now that more are, I see little reason for avoiding there use. -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Tue Mar 25 08:07:45 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 25 Mar 2014 13:07:45 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> Message-ID: <53317191.7050701@rece.vub.ac.be> On 25-03-14 12:12, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 9:24 PM, Antoon Pardon > wrote: >> No they didn't have to. With the transition to python3, the developers >> could have opted for empty braces to mean an empty set. And if they >> wanted a literal for an empty dictionary, they might have chosen {:}. >> Backward-compatibility was already broken so that wasn't an argument. > Python 3.0 didn't just say "to Hades with backward compatibility". The > breakage was only in places where it was deemed worthwhile. Changing > the meaning of {} would have only small benefit and would potentially > break a LOT of programs, so the devs were right to not do it. More programs than those who broke because print was now a function? Do you think it would have been so problamatic that it couldn't have been handled by '2to3'? Maybe breaking backward-compatibility wasn't considered worthwhile, but that is not the same as stating backward-compatibility was necessary. And that is how I understood how you stated your claim. > Python 3 and Python 2 are not, contrary to some people's opinions, > completely different languages. And changing the meaning of {} to now indicate the emppty set, wouldn't have turned it in a completely different language either. -- Antoon Pardon. From rustompmody at gmail.com Tue Mar 25 08:09:20 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 05:09:20 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, March 25, 2014 5:16:14 PM UTC+5:30, Antoon Pardon wrote: > On 25-03-14 12:14, Steven D'Aprano wrote: > >> Would > >> such a use already indicate I should use a mathematical front-end? > >> When a programming language is borrowing concepts from mathematics, I > >> see no reason not to borrow the symbols used too. > > I'd like to sum the squares of the integers from n=1 to 10. In the old > > Python, I'd write sum(n**2 for n in range(1, 11)), but with the brave new > > world of maths symbols, I'd like to write this: > > http://timmurphy.org/examples/summation_large.jpg > > How do I enter that, and what text editor should I use? > You have a point. Blindly following mathematical notation will not > work, because mathematics often enough uses positional clues that > will be very hard to incorparate in a programming language. Two completely separate questions 1. Symbols outside of US-104-keyboard/ASCII used for python functions/constants 2. Non-linear math notation It goes back not just to the first programming languages but to Turing's paper that what a mathematician can do on 2-d paper can be done on a 1-d 'tape'. IOW conflating 1 and 2 is not even a poor strawman argument -- Its only 1 that anyone is talking about. The comparison with APL which had/has at least some pretensions to being mathematics and also simultaneously being a programming language are more appropriate So adding to my earlier list: > Yes APL is a good example to learn mistakes from > - being before its time/technology > - taking a good idea too far > - assuming that I understand clearly implies so do others - not taking others' good ideas seriously Structured programming constructs were hardly known in 1960 when APL was invented. 10 years down they were the rage. APL ignored them -- to its own detriment > > On Tue, 25 Mar 2014 11:38:38 +0100, Antoon Pardon wrote: > >> On 25-03-14 10:54, Chris Angelico wrote: > >>> On Tue, Mar 25, 2014 at 8:43 PM, Antoon Pardon > >>>> I thought programs were read more than written. So if writing is made > >>>> a bit more problematic but the result is more readable because we are > >>>> able to use symbols that are already familiar from other contexts, I > >>>> would say it is worth it. > >>> It's a matter of extents. If code is read ten times for every time it's > >>> written, making it twenty times harder to write and a little bit easier > >>> to read is still a bad tradeoff. > >>> Also: To what extent IS that symbol familiar from some other context? > >>> Are you using Python as a programming language, or should you perhaps > >>> be using a mathematical front-end? Not everything needs to perfectly > >>> match what anyone from any other context will expect. This is, first > >>> and foremost, a *programming* language. > >> So? We do use + -, so why shouldn't we use ? for multiplication. > > I can't find ? on my keyboard! > Then use an editor that allows you to configure it, so you can > easily use it. > That's the kind of advice that is often enough given here if > some python feature is hard for the tools someone is using. > So why should it be different now? > But often enough languages tried to use the symbols that were > available to them. Now that more are, I see little reason for > avoiding there use. I am reminded that when Unix first came out, some of both the early adoption as well as the early pooh-pooh-ing was around the novelty/stupidity of using lower-case in programming From roy at panix.com Tue Mar 25 08:21:19 2014 From: roy at panix.com (Roy Smith) Date: Tue, 25 Mar 2014 08:21:19 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> Message-ID: In article , Antoon Pardon wrote: > Come on. The problem isn't that both set and dictionary literal use > braces. That doesn't seem to be a problem in python3. The only question > was what should {} represent and how do we get an empty collection of > the other kind. If {} had been an empty set, dict() could have been > used for an empty dictionary is {:} had been unacceptable. By analogy to tuples, it could have been {,}. From roy at panix.com Tue Mar 25 08:24:12 2014 From: roy at panix.com (Roy Smith) Date: Tue, 25 Mar 2014 08:24:12 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> Message-ID: In article , Mark H Harris wrote: > On 3/24/14 10:51 PM, Chris Angelico wrote: > > Supporting both may look tempting, but you effectively create two ways > > of spelling the exact same thing; it'd be like C's trigraphs. Do you > > know what ??= is, > > This was a fit for me, back in the day IBM (system36 & system38). When > we started supporting the C compiler (ha!) and non of our 5250 terminals > could provide the C punctuation we take for granted today--- so we > invented tri-graphs for { and } and others. It was a hoot. Our ASR-33s didn't have { and }, so we used \( and \). To be honest, I don't remember if the c compiler understood those, or if it was mapped at the tty driver level. From roy at panix.com Tue Mar 25 08:35:02 2014 From: roy at panix.com (Roy Smith) Date: Tue, 25 Mar 2014 08:35:02 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: In article <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e at googlegroups.com>, Rustom Mody wrote: > And Chris is right in (rephrasing) we may have unicode-happy OSes and > languages. We cant reasonably have unicode-happy keyboards. > [What would a million-key keyboard look like? Lets leave the cost aside...] In a true unicode environment, the input device may be nothing like our current keyboards. Star Trek has been amazingly accurate about it's predictions of the future. Doors that open automatically as you approach them are now routine. One thing they messed up on was mobile devices; they assumed tricorders and communicators would be separate devices, when in reality our phones now perform both functions. Today's 3-d printers are giving replicators a run for their money. Some people still get bent out of shape when a white man kisses a black woman, but we're working on that. When's the last time you saw somebody typing commands to a computer on Star Trek? From roy at panix.com Tue Mar 25 08:36:59 2014 From: roy at panix.com (Roy Smith) Date: Tue, 25 Mar 2014 08:36:59 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: In article , Mark H Harris wrote: > (we're on one tiny planet, you know?) Speak for yourself. From rosuav at gmail.com Tue Mar 25 08:45:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Mar 2014 23:45:16 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53317191.7050701@rece.vub.ac.be> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> <53317191.7050701@rece.vub.ac.be> Message-ID: On Tue, Mar 25, 2014 at 11:07 PM, Antoon Pardon wrote: > On 25-03-14 12:12, Chris Angelico wrote: > >> On Tue, Mar 25, 2014 at 9:24 PM, Antoon Pardon >> wrote: >>> No they didn't have to. With the transition to python3, the developers >>> could have opted for empty braces to mean an empty set. And if they >>> wanted a literal for an empty dictionary, they might have chosen {:}. >>> Backward-compatibility was already broken so that wasn't an argument. >> Python 3.0 didn't just say "to Hades with backward compatibility". The >> breakage was only in places where it was deemed worthwhile. Changing >> the meaning of {} would have only small benefit and would potentially >> break a LOT of programs, so the devs were right to not do it. > > More programs than those who broke because print was now a function? > Do you think it would have been so problamatic that it couldn't have > been handled by '2to3'? It makes the same notation mean different things, in ways that are hard to render clearly. You can write a Py3 program and put this at the top for Py2: try: input = raw_input range = xrange except NameError: # We're running on Python 3 pass But you can't do the same for braces. You'd have to eschew *both* literal-ish notations and use explicit constructors everywhere. Not clean. ChrisA From rustompmody at gmail.com Tue Mar 25 08:53:45 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 05:53:45 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> On Tuesday, March 25, 2014 4:08:38 PM UTC+5:30, Antoon Pardon wrote: > So? We do use + -, so why shouldn't we use ? for multiplication. Would > such a use already indicate I should use a mathematical front-end? > When a programming language is borrowing concepts from mathematics, > I see no reason not to borrow the symbols used too. Well... Matters of taste are personal, touchy-feely things and not easily explainable. Some of mine: * for multiply does not bother me; ** for power for some reason does. Even though the only standard math notation is non-linear and is off-limits 'and' bothers me slightly (maybe because I was brought up on Pascal?) '&&' less (and then C) ? is of course best (I am a Dijkstra fan) [But then Dijkstra would probably roll over and over in his grave at short-circuit 'and'. Non-commutative?!?! Blasphemy!] ? for some reason seems inappropriate (some vague recollection that its an only English; Europeans dont use it??) And if we had hyphen '?' distinguished from minus '-' then we could have lispish names like call?with?current?continuation properly spelt. And then generations of programmers will thank us for increasing their debugging overtime!! From antoon.pardon at rece.vub.ac.be Tue Mar 25 09:07:02 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 25 Mar 2014 14:07:02 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> <53317191.7050701@rece.vub.ac.be> Message-ID: <53317F76.6000501@rece.vub.ac.be> On 25-03-14 13:45, Chris Angelico wrote: > It makes the same notation mean different things, in ways that are > hard to render clearly. You can write a Py3 program and put this at > the top for Py2: > > try: > input = raw_input > range = xrange > except NameError: > # We're running on Python 3 > pass > > But you can't do the same for braces. You'd have to eschew *both* > literal-ish notations and use explicit constructors everywhere. Not > clean. What about it, is not clean? I understand that you prefer it how it worked out. That is fine by me. But that doesn't make the alternative unclean. Is having to write "set()" unclean somehow when you need an empty set? I wouldn't think so. So I see no reason why having to write "dict()" when you need an empty dictionary wouldn't be clean. Nor would it be unclean, when you have to write somethings a bit differently when you want your program to be compatible both with python2 and python3. You will also need to prefix all your (unicode) strings with u and all your byte strings with b. And probably some more stuff if you want to avoid some pitfalls. -- Antoon Pardon From rustompmody at gmail.com Tue Mar 25 09:07:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 06:07:33 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> <53317191.7050701@rece.vub.ac.be> Message-ID: <38bbeeeb-8e3b-47fa-a5e7-e3ab40432fb4@googlegroups.com> On Tuesday, March 25, 2014 6:15:16 PM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 11:07 PM, Antoon Pardon > > On 25-03-14 12:12, Chris Angelico wrote: > >> On Tue, Mar 25, 2014 at 9:24 PM, Antoon Pardon > >>> No they didn't have to. With the transition to python3, the developers > >>> could have opted for empty braces to mean an empty set. And if they > >>> wanted a literal for an empty dictionary, they might have chosen {:}. > >>> Backward-compatibility was already broken so that wasn't an argument. > >> Python 3.0 didn't just say "to Hades with backward compatibility". The > >> breakage was only in places where it was deemed worthwhile. Changing > >> the meaning of {} would have only small benefit and would potentially > >> break a LOT of programs, so the devs were right to not do it. > > More programs than those who broke because print was now a function? > > Do you think it would have been so problamatic that it couldn't have > > been handled by '2to3'? > It makes the same notation mean different things, in ways that are > hard to render clearly. You can write a Py3 program and put this at > the top for Py2: > try: > input = raw_input > range = xrange > except NameError: > # We're running on Python 3 > pass > But you can't do the same for braces. You'd have to eschew *both* > literal-ish notations and use explicit constructors everywhere. Not > clean. What you are answering (2) is somewhat different from what Anton is asking (1). 1. Use a tool (2to3 inspired) to help move programs to the the new lexicon 2. Use 2to3 to (help) write code that is backward-compatible It is an invariable given that when heavily compatible code is desired, the programmer gets the worst of all worlds From rosuav at gmail.com Tue Mar 25 09:13:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 00:13:36 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 11:35 PM, Roy Smith wrote: > When's the last time you saw somebody typing commands to a computer on > Star Trek? That's more like what comes up in Cars 2. "It's voice activated... but then, everything is these days!" ChrisA From matt.newville at gmail.com Tue Mar 25 09:34:43 2014 From: matt.newville at gmail.com (matt.newville at gmail.com) Date: Tue, 25 Mar 2014 06:34:43 -0700 (PDT) Subject: advice on sub-classing multiprocessing.Process and multiprocessing.BaseManager In-Reply-To: References: <80cf8fb7-d0c5-43a9-bc6f-c61ce6214f98@googlegroups.com> Message-ID: <8d59e3a4-e6af-4633-869b-53568f6091cd@googlegroups.com> ChrisA - >> I wasn't really asking "is multiprocessing appropriate?" but whether >> there was a cleaner way to subclass multiprocessing.BaseManager() to >> use a subclass of Process(). I can believe the answer is No, but >> thought I'd ask. > > I've never subclassed BaseManager like this. It might be simpler to > spin off one or more workers and not have them do any network > communication at all; that way, you don't need to worry about the > cache. Set up a process tree with one at the top doing only networking > and process management (so it's always fast), and then use a > multiprocessing.Queue or somesuch to pass info to a subprocess and > back. Then your global connection state is all stored within the top > process, and none of the others need care about it. You might have a > bit of extra effort to pass info back to the parent rather than simply > writing it to the connection, but that's a common requirement in other > areas (eg GUI handling - it's common to push all GUI manipulation onto > the main thread), so it's a common enough model. > > But if subclassing and tweaking is the easiest way, and if you don't > mind your solution being potentially fragile (which subclassing like > that is), then you could look into monkey-patching Process. Inject > your code into it and then use the original. It's not perfect, but it > may turn out easier than the "subclass everything" technique. > > ChrisA Thanks, I agree that restricting network communications to a parent process would be a good recommended solution, but it's hard to enforce and easy to forget such a recommendation. It seems better to provide lightweight library-specific subclasses of Process (and Pool) and explaining why they should be used. This library (pyepics) already does similar things for interaction with other libraries (notably providing decorators to avoid issues with wxPython). Monkey-patching multiprocessing.Process seems more fragile than subclassing it. It turned out that multiprocessing.pool.Pool was also very easy to subclass. But cleanly subclassing the Managers in multiprocessing.managers look much harder. I'm not sure if this is intentional or not, or if it should be filed as an issue for multiprocessing. For now, I'm willing to say that the multiprocessing managers are not yet available with the pyepics library. Thanks again, --Matt From steve+comp.lang.python at pearwood.info Tue Mar 25 09:36:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 13:36:36 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> Message-ID: <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 08:21:19 -0400, Roy Smith wrote: > In article , > Antoon Pardon wrote: > >> Come on. The problem isn't that both set and dictionary literal use >> braces. That doesn't seem to be a problem in python3. The only question >> was what should {} represent and how do we get an empty collection of >> the other kind. If {} had been an empty set, dict() could have been >> used for an empty dictionary is {:} had been unacceptable. > > By analogy to tuples, it could have been {,}. An empty tuple is (), not (,). {,} is just making up random syntax almost unrelated to anything else. One might as well used {?} or {+}. If Python 3 had introduced {} to mean the empty set, I *guarantee* that right now people would be arguing that "Python 3 could have used {} for the empty dict, and used set() for the empty set" -- and very likely the same people now arguing the opposite. Yes, Python could have changed the meaning of {} to mean the empty set. But you know what? The empty set is not that important. Sets are not fundamental to Python. Python didn't even have sets until 2.3, and at first they were just a standard library module, not even built-in. Dicts, on the other hand, are fundamental to Python. They are used everywhere. Python is, in a very real sense, built on dicts, not sets. You can implement sets starting from dicts, but not the other way around: dicts are more fundamental than sets. I'm sure it is awfully impressive that mathematicians can derive the laws of integer maths starting only from the empty set ?, but as far as programming goes that's not a very useful thing. Dicts are much more important, and they are much more commonly used. -- Steven D'Aprano http://import-that.dreamwidth.org/ From antoon.pardon at rece.vub.ac.be Tue Mar 25 09:43:09 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 25 Mar 2014 14:43:09 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> Message-ID: <533187ED.7060509@rece.vub.ac.be> On 25-03-14 13:53, Rustom Mody wrote: > On Tuesday, March 25, 2014 4:08:38 PM UTC+5:30, Antoon Pardon wrote: >> So? We do use + -, so why shouldn't we use ? for multiplication. Would >> such a use already indicate I should use a mathematical front-end? >> When a programming language is borrowing concepts from mathematics, >> I see no reason not to borrow the symbols used too. > Well... > Matters of taste are personal, touchy-feely things and not easily > explainable. > > Some of mine: > * for multiply does not bother me; ** for power for some reason does. > Even though the only standard math notation is non-linear and is off-limits > > 'and' bothers me slightly (maybe because I was brought up on Pascal?) > '&&' less (and then C) > ? is of course best (I am a Dijkstra fan) > [But then Dijkstra would probably roll over and over in his grave at > short-circuit 'and'. Non-commutative?!?! Blasphemy!] > > ? for some reason seems inappropriate > (some vague recollection that its an only English; Europeans dont use it??) > It doesn't bother me. IIRC in primary school before fractions were introduced, > a colon was used to indicate division. > > And if we had hyphen '?' distinguished from minus '-' then we could have lispish > names like call?with?current?continuation properly spelt. > And then generations of programmers will thank us for increasing their > debugging overtime!! > Sure we could argue some partciculars. Personnaly I would prefer an up-arrow for exponentiation. IMO the advantage would be mainly in allowing more disambiguity. So that if you as a programmer think about something as an operator, you are not obligated to somehow force it into the mold of + - * / % //. If ? would have been used for attribute access, then we could just write 5?to_bytes(4, "little") without having to consider that the lexer would try to interpret it as a floating point. And maybe ? could have been used for concatenation. Which would mean that if you had a class whose instances could both be added and concatenated, you could implement both as an operator. Finally, I think I would prefer the middle dot ? for lispish names so we would have call?with?current?continuation. From jeandubois314 at gmail.com Tue Mar 25 09:47:23 2014 From: jeandubois314 at gmail.com (Jean Dubois) Date: Tue, 25 Mar 2014 06:47:23 -0700 (PDT) Subject: [newbie] confusion concerning fetching an element in a 2d-array In-Reply-To: <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Op dinsdag 25 maart 2014 12:01:37 UTC+1 schreef Steven D'Aprano: > On Tue, 25 Mar 2014 03:26:26 -0700, Jean Dubois wrote: > > > I'm confused by the behaviour of the following python-script I wrote: > > > > #!/usr/bin/env python > > #I first made a data file 'test.dat' with the following content > > #1.0 2 3 > > #4 5 6.0 > > #7 8 9 > > import numpy as np > > lines=[line.strip() for line in open('test.dat')] > > #convert lines-list to numpy-array > > array_lines=np.array(lines) > > #fetch element at 2nd row, 2nd column: > > print array_lines[1, 1] > > > > > > When running the script I always get the following error: IndexError: > > invalid index > > > > Can anyone here explain me what I am doing wrong and how to fix it? > > Yes. Inspect the array by printing it, and you'll see that it is a one- > dimensional array, not two, and the entries are strings: > > > py> import numpy as np > py> # simulate a text file > ... data = """1.0 2 3 > ... 4 5 6.0 > ... 7 8 9""" > py> lines=[line.strip() for line in data.split('\n')] > py> # convert lines-list to numpy-array > ... array_lines = np.array(lines) > py> print array_lines > ['1.0 2 3' '4 5 6.0' '7 8 9'] > > > The interactive interpreter is your friend! You never need to guess what > the problem is, Python has powerful introspection abilities, one of the > most powerful is also one of the simplest: print. Another powerful tool > in the interactive interpreter is help(). > > So, what to do about it? Firstly, convert your string read from a file > into numbers, then build your array. Here's one way: > > py> values = [float(s) for s in data.split()] > py> print values > [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] > py> array_lines = np.array(values) > py> array_lines = array_lines.reshape(3, 3) > py> print array_lines > [[ 1. 2. 3.] > [ 4. 5. 6.] > [ 7. 8. 9.]] > Dear Steve, Thanks for answering my question but unfortunately now I'm totally confused. Above I see parts from different programs which I can't assemble together to one working program (I really tried hard). Can I tell from your comment I shouldn't use numpy? I also don't see how to get the value an element specified by (row, column) from a numpy_array like "array_lines" in my original code All I need is a little python-example reading a file with e.g. three lines with three numbers per line and putting those numbers as floats in a 3x3-numpy_array, then selecting an element from that numpy_array using it's row and column-number. thanks in advance and kind regards, jean From rosuav at gmail.com Tue Mar 25 09:50:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 00:50:15 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <38bbeeeb-8e3b-47fa-a5e7-e3ab40432fb4@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> <53317191.7050701@rece.vub.ac.be> <38bbeeeb-8e3b-47fa-a5e7-e3ab40432fb4@googlegroups.com> Message-ID: On Wed, Mar 26, 2014 at 12:07 AM, Rustom Mody wrote: > What you are answering (2) is somewhat different from what Anton is asking (1). > > 1. Use a tool (2to3 inspired) to help move programs to the the new lexicon > 2. Use 2to3 to (help) write code that is backward-compatible > > It is an invariable given that when heavily compatible code is desired, the > programmer gets the worst of all worlds That is true. But writing cross-compatible code IS important, and that means that backward compatibility is still important, and that breaking it is a cost - which was my original point. Other non-backward-compatible changes at 3.0 are not justification to arbitrarily change the meanings of syntactic elements. Don't forget, even if you're not writing a single file that gets executed unmodified on two versions, you still have to worry about your brain changing gear. ChrisA From rustompmody at gmail.com Tue Mar 25 09:52:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 06:52:21 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> Message-ID: <09508435-1b9b-424b-a052-b9f69de17ff6@googlegroups.com> On Tuesday, March 25, 2014 7:13:09 PM UTC+5:30, Antoon Pardon wrote: > On 25-03-14 13:53, Rustom Mody wrote: > > On Tuesday, March 25, 2014 4:08:38 PM UTC+5:30, Antoon Pardon wrote: > >> So? We do use + -, so why shouldn't we use ? for multiplication. Would > >> such a use already indicate I should use a mathematical front-end? > >> When a programming language is borrowing concepts from mathematics, > >> I see no reason not to borrow the symbols used too. > > Well... > > Matters of taste are personal, touchy-feely things and not easily > > explainable. > > Some of mine: > > * for multiply does not bother me; ** for power for some reason does. > > Even though the only standard math notation is non-linear and is off-limits > > 'and' bothers me slightly (maybe because I was brought up on Pascal?) > > '&&' less (and then C) > > ? is of course best (I am a Dijkstra fan) > > [But then Dijkstra would probably roll over and over in his grave at > > short-circuit 'and'. Non-commutative?!?! Blasphemy!] > > ? for some reason seems inappropriate > > (some vague recollection that its an only English; Europeans dont use it??) > > It doesn't bother me. IIRC in primary school before fractions were introduced, > > a colon was used to indicate division. > > And if we had hyphen '?' distinguished from minus '-' then we could have lispish > > names like call?with?current?continuation properly spelt. > > And then generations of programmers will thank us for increasing their > > debugging overtime!! > Sure we could argue some partciculars. Personnaly I would prefer an up-arrow > for exponentiation. Ok > IMO the advantage would be mainly in allowing more disambiguity. So that if > you as a programmer think about something as an operator, you are not obligated > to somehow force it into the mold of + - * / % //. > If ? would have been used for attribute access, then we could just write Nice > 5?to_bytes(4, "little") without having to consider that the lexer would > try to interpret it as a floating point. > And maybe ? could have been used for concatenation. Which would mean that Super! Anything but a (randomly overloaded) +! > if you had a class whose instances could both be added and concatenated, > you could implement both as an operator. > Finally, I think I would prefer the middle dot ? for lispish names so > we would have call?with?current?continuation. A bit unreadable out here but not too bad From rosuav at gmail.com Tue Mar 25 09:56:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 00:56:47 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <533187ED.7060509@rece.vub.ac.be> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> <533187ED.7060509@rece.vub.ac.be> Message-ID: On Wed, Mar 26, 2014 at 12:43 AM, Antoon Pardon wrote: >> It doesn't bother me. IIRC in primary school before fractions were introduced, >> a colon was used to indicate division. The way I learned it, a colon was for a ratio, and a horizontal line was for a fraction. Both of them effectively indicate division, but with a distinct difference. If you have four red objects and two blue ones, the ratio of red to blue is 4 : 2 or 2 : 1, but the fraction (proportion) that are red is 4 / 6 or 2 / 3. ChrisA From rosuav at gmail.com Tue Mar 25 10:00:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 01:00:52 +1100 Subject: advice on sub-classing multiprocessing.Process and multiprocessing.BaseManager In-Reply-To: <8d59e3a4-e6af-4633-869b-53568f6091cd@googlegroups.com> References: <80cf8fb7-d0c5-43a9-bc6f-c61ce6214f98@googlegroups.com> <8d59e3a4-e6af-4633-869b-53568f6091cd@googlegroups.com> Message-ID: On Wed, Mar 26, 2014 at 12:34 AM, wrote: > Monkey-patching multiprocessing.Process seems more fragile than subclassing it. It turned out that multiprocessing.pool.Pool was also very easy to subclass. But cleanly subclassing the Managers in multiprocessing.managers look much harder. I'm not sure if this is intentional or not, or if it should be filed as an issue for multiprocessing. For now, I'm willing to say that the multiprocessing managers are not yet available with the pyepics library. > Subclassing is actually more fragile than you might think. As you've found, you need to fidget with more and more classes to make your change "stick", and also, any small change to implementation details in the superclass could suddenly break things. It's not really any safer than monkeypatching, despite all the OO fanatics saying how easy it is to rework by subclassing. At least when you monkeypatch, you *know* you're fiddling with internals. ChrisA From antoon.pardon at rece.vub.ac.be Tue Mar 25 10:01:09 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 25 Mar 2014 15:01:09 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53318C25.2010103@rece.vub.ac.be> On 25-03-14 14:36, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 08:21:19 -0400, Roy Smith wrote: > >> In article , >> Antoon Pardon wrote: >> >>> Come on. The problem isn't that both set and dictionary literal use >>> braces. That doesn't seem to be a problem in python3. The only question >>> was what should {} represent and how do we get an empty collection of >>> the other kind. If {} had been an empty set, dict() could have been >>> used for an empty dictionary is {:} had been unacceptable. >> By analogy to tuples, it could have been {,}. > An empty tuple is (), not (,). {,} is just making up random syntax almost > unrelated to anything else. One might as well used {?} or {+}. > > If Python 3 had introduced {} to mean the empty set, I *guarantee* that > right now people would be arguing that "Python 3 could have used {} for > the empty dict, and used set() for the empty set" -- and very likely the > same people now arguing the opposite. Sure and other people would have defended that choice and very likely the same people that are defending the current choice now. What is your point? > Yes, Python could have changed the meaning of {} to mean the empty set. > But you know what? The empty set is not that important. Sets are not > fundamental to Python. Python didn't even have sets until 2.3, and at > first they were just a standard library module, not even built-in. Dicts, > on the other hand, are fundamental to Python. They are used everywhere. > Python is, in a very real sense, built on dicts, not sets. You can > implement sets starting from dicts, but not the other way around: dicts > are more fundamental than sets. Fine, dicts are more fundamental. I just don't see that as such a big argument against using a different literal for the empty dictionary than was used in python2 and using {} to indicate the empty set. I would have preferred it that way, but I don't consider it a big deal. I just consider the arguments weak for those who seem to argue that using {} for an empty dictionary in python3 was as good as unavoidable. -- Antoon Pardon From rustompmody at gmail.com Tue Mar 25 10:08:11 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 07:08:11 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> <533187ED.7060509@rece.vub.ac.be> Message-ID: <32d77df0-c4b5-4096-84c6-af0b4de12574@googlegroups.com> On Tuesday, March 25, 2014 7:26:47 PM UTC+5:30, Chris Angelico wrote: > On Wed, Mar 26, 2014 at 12:43 AM, Antoon Pardon > >> It doesn't bother me. IIRC in primary school before fractions were introduced, > >> a colon was used to indicate division. > The way I learned it, a colon was for a ratio, and a horizontal line > was for a fraction. Both of them effectively indicate division, but > with a distinct difference. If you have four red objects and two blue > ones, the ratio of red to blue is 4 : 2 or 2 : 1, but the fraction > (proportion) that are red is 4 / 6 or 2 / 3. http://www.unicode.org/mail-arch/unicode-ml/y2012-m07/0053.html From steve+comp.lang.python at pearwood.info Tue Mar 25 10:13:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 14:13:31 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: <53318f0b$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 08:35:02 -0400, Roy Smith wrote: > In article <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e at googlegroups.com>, > Rustom Mody wrote: > >> And Chris is right in (rephrasing) we may have unicode-happy OSes and >> languages. We cant reasonably have unicode-happy keyboards. [What would >> a million-key keyboard look like? Lets leave the cost aside...] > > In a true unicode environment, the input device may be nothing like our > current keyboards. I doubt it. I expect that they will be based on our current keyboards. > Star Trek has been amazingly accurate about it's predictions of the > future. O_o > Doors that open automatically as you approach them are now > routine. It's very easy to predict things that have already happened. Star Trek was created in 1966. The electric automatic door was invented in 1954 by Lew Hewitt and Dee Horton. (Well, actually the first automatic door was built in the 1st century CE by Heron of Alexandra, but that's another story.) Electric doors may be common in some commercial premises, such as shopping centres and some office buildings, but I wouldn't call them routine. > One thing they messed up on was mobile devices; they assumed > tricorders and communicators would be separate devices, when in reality > our phones now perform both functions. Today's 3-d printers are giving > replicators a run for their money. Today's 3D printers are to replicators what a stone axe is to a full wood- working tool shop. > Some people still get bent out of > shape when a white man kisses a black woman, but we're working on that. > > When's the last time you saw somebody typing commands to a computer on > Star Trek? 1986, when I last saw Star Trek IV. The Star Trek universe also predicts that money will be obsolete. How's that prediction working out? -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Tue Mar 25 10:23:23 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 14:23:23 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> Message-ID: <5331915b$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 05:53:45 -0700, Rustom Mody wrote: > And if we had hyphen '?' distinguished from minus '-' then we could have > lispish names like call?with?current?continuation properly spelt. And > then generations of programmers will thank us for increasing their > debugging overtime!! :-) Full Unicode support in a language is, alas, a double-edged sword. While it has advantages, it also has disadvantages. py> ? = 1 py> A = ? + 1 py> assert A == ? Traceback (most recent call last): File "", line 1, in AssertionError While I can see the appeal of certain Unicode symbols, I really wouldn't like to have to deal with code that looks like this: x?2*y+?e**3?z?(x+1)?y?w If I wanted line-noise, I know where to get Perl :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ From davea at davea.name Tue Mar 25 10:42:13 2014 From: davea at davea.name (Dave Angel) Date: Tue, 25 Mar 2014 10:42:13 -0400 (EDT) Subject: [newbie] confusion concerning fetching an element in a 2d-array References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Jean Dubois Wrote in message: > Op dinsdag 25 maart 2014 12:01:37 UTC+1 schreef Steven D'Aprano: >> >> py> values = [float(s) for s in data.split()] >> py> print values >> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] >> py> array_lines = np.array(values) >> py> array_lines = array_lines.reshape(3, 3) >> py> print array_lines >> [[ 1. 2. 3.] >> [ 4. 5. 6.] >> [ 7. 8. 9.]] >> > Dear Steve, > Thanks for answering my question but unfortunately now I'm totally > confused. > Above I see parts from different programs which I can't > assemble together to one working program (I really tried hard). > Can I tell from your comment I shouldn't use numpy? > I also don't see how to get the value an element specified by (row, > column) from a numpy_array like "array_lines" in my original code I don't use numpy, but I thought Steven's description was clear enough. Your problem was not the extraction, but the creation of the array. Use print to prove that to yourself. > > All I need is a little python-example reading a file with e.g. three lines > with three numbers per line and putting those numbers as floats in a > 3x3-numpy_array, then selecting an element from that numpy_array using > it's row and column-number. If your instructor wanted you to copy examples, he would have given you one. First write some code to split and convert each line into floats. You don't even try that in your original. Then do that in a loop. Now you have all the floats in one list or array. I presume that it's two dimensional. Use print to check. If it's not, you'll have to either post process it with a reshape method, or change the way you accumulate it. I can't help with the latter. -- DaveA From rosuav at gmail.com Tue Mar 25 10:37:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 01:37:51 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53318f0b$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53318f0b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 26, 2014 at 1:13 AM, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 08:35:02 -0400, Roy Smith wrote: > >> In article <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e at googlegroups.com>, >> Rustom Mody wrote: >> >>> And Chris is right in (rephrasing) we may have unicode-happy OSes and >>> languages. We cant reasonably have unicode-happy keyboards. [What would >>> a million-key keyboard look like? Lets leave the cost aside...] >> >> In a true unicode environment, the input device may be nothing like our >> current keyboards. > > I doubt it. I expect that they will be based on our current keyboards. Rule #0 of any voice-activated system: The command word "Console" MUST summon a terminal window, and make available a keyboard and screen on which to use it. This console MAY demand authentication (via typed password) before operating. I don't know if that's written anywhere, but it ought to be. It should be as fundamental as Asimov's laws of robotics. That one simple rule would improve scifi like "Eureka" no end. Hey look, we have a rogue AI... "CONSOLE!"... hey look, we have a rogue AI on a system that's now powered off. Crisis averted, now go solve the problem in a mundane and not very TV-friendly way... >> Star Trek has been amazingly accurate about it's predictions of the >> future. > > O_o I like the Scott Adams take on that. He predicted (in the 1990s) that the future would *not* be like Star Trek, because human reproduction depends on genuine relationships being cheaper/easier than artificial ones. If you could go onto the holodeck and create yourself the perfect (wo)man of your dreams, why would you ever date a real one? The holodeck would be humanity's last invention. >> When's the last time you saw somebody typing commands to a computer on >> Star Trek? > > 1986, when I last saw Star Trek IV. You actually watched it? I got pretty much bored with the series before even finishing TNG. (I'm not 100% sure, but I think I watched every TOS episode.) > The Star Trek universe also predicts that money will be obsolete. How's > that prediction working out? And it further predicts that, thanks to the invention of the holodeck and the replicator, humanity will lose all sense of purpose and challenge, and will send ships out to go^H^Hgo to places where nobody's yet been, because the entire human race is *bored out of its petty little brain* with nothing exciting left to do. Yup, that's the whole unpublished backstory right there, sorry for the spoilers! (I got this from Scott Adams too. He seems to know his stuff.) ChrisA From steve+comp.lang.python at pearwood.info Tue Mar 25 11:18:56 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 15:18:56 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 05:09:20 -0700, Rustom Mody wrote: > Two completely separate questions > > 1. Symbols outside of US-104-keyboard/ASCII used for python > functions/constants > 2. Non-linear math notation > > It goes back not just to the first programming languages but to Turing's > paper that what a mathematician can do on 2-d paper can be done on a 1-d > 'tape'. IOW conflating 1 and 2 is not even a poor strawman argument -- > Its only 1 that anyone is talking about. Not so. Mark Harris said: [quote] But what if python had a math symbols extension so that universal mathematics could be written the way we do it on a black|board, er, I mean white|board? I think that's pretty explicit that he's talking about writing mathematical code the way mathematicians write mathematics. Antoon Pardon referred to borrowing the symbols used in mathematics. But the point is that the symbols come with notation: - (minus) can be prefix unary operator or a infix binary operator. ? (summation) is a quaternary operator, it takes four arguments: a variable name, a lower limit, an upper limit, and an expression. To be true to the mathematical notation, we ought to write it the way mathematicians do. The thing is, we can't just create a ? function, because it doesn't work the way the summation operator works. The problem is that we would want syntactic support, so we could write something like this: p = 2 ?(n, 1, 10, n**p) This cannot be an ordinary function, because if it were, the n**p expression would be evaluated before passing the result to the function. We want it to delay evaluation, like a list comp: [n**p for n in range(1, 11)] the expression n**p gets evaluated inside the list comp. That cannot be written as a function either: list_comp(n**p, n, range(1, 11)) Mark's idea of a maths blackboard is not ridiculous. That's what Mathematica does. To enter a sum like the above in Mathematica, you can enter: ESC sum ESC Ctrl+$ n=1 Ctrl+% 10 Ctrl+Space n^p to give you the summation 10 ? n**p n=1 Obviously this requires a custom editor. https://reference.wolfram.com/mathematica/tutorial/EnteringTwoDimensionalInput.html But Mathematica is a specialist system for doing mathematics, not a general purpose language like Python. Of course one could *write* a Mathematica-like system in Python, and I expect that Sage may even have something like this (if it doesn't, it could) but one shouldn't hammer the specialised round peg of complex mathematical notation into the square peg of a general purpose programming language. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rustompmody at gmail.com Tue Mar 25 11:19:43 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 08:19:43 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <5331915b$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> <5331915b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, March 25, 2014 7:53:23 PM UTC+5:30, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 05:53:45 -0700, Rustom Mody wrote: > > And if we had hyphen '?' distinguished from minus '-' then we could have > > lispish names like call?with?current?continuation properly spelt. And > > then generations of programmers will thank us for increasing their > > debugging overtime!! > :-) > Full Unicode support in a language is, alas, a double-edged sword. While > it has advantages, it also has disadvantages. > py> ? = 1 > py> A = ? + 1 > py> assert A == ? > Traceback (most recent call last): > AssertionError Even with 'good' ol ASCII giving enough trouble between O and 0, 1 and l, we certainly dont want more such headaches! In apps, a serious consideration of unicode entails a cycle of i18n and l10n. The l10n for programming languages is arguably harder -- if python is 'localized' to some (human) language L, maybe all the builtins should be also translated? And whats the use of that without full translation of the docs? Its not a pleasing thought... Something intermediate needs to be found... Some thoughts (quite half cooked): 1. Human -- 'natural' -- languages and math are not in the same category If Cyrillic A gets in Roman probably shouldn't. 2. There needs to be some intermediate binding time -- eg when the system is installed -- when suitable char-tables are set up. Case-in-point: Many folks in haskell-land have wanted to replace the '\' with the '?'. This has not worked out so far because ? belongs to the same unicode class as other lower-case letters. So since this is possible: Prelude> let ? = 1 Prelude> ? 1 Prelude> the other more-natural-to-haskell usage is precluded. So these classes need to be changeable and late-bindable. Not as late as runtime but later than build-time. Probably same as the choice of locales on a system > While I can see the appeal of certain Unicode symbols, I really wouldn't > like to have to deal with code that looks like this: > x?2*y+?e**3?z?(x+1)?y?w > If I wanted line-noise, I know where to get Perl :-) Yes... neither Perl nor Cobol is pleasant From steve+comp.lang.python at pearwood.info Tue Mar 25 11:35:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 15:35:18 GMT Subject: [newbie] confusion concerning fetching an element in a 2d-array References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5331a236$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 06:47:23 -0700, Jean Dubois wrote: [...] > Thanks for answering my question but unfortunately now I'm totally > confused. > Above I see parts from different programs which I can't assemble > together to one working program (I really tried hard). Can I tell from > your comment I shouldn't use numpy? No, you misunderstood me. I never suggested that you avoid numpy. If you read my code, I use numpy. That's the "import numpy as np", and then later I refer to np. What I suggested is that you open up the Python interactive interpreter and use it for experimentation. Not that you avoid numpy! You will use numpy inside the interactive interpreter. Do you know how to start the interactive interpreter? You seem to be using Linux, or maybe Mac. Open a console or xterm window, and type python then press Enter, and the interactive interpreter will start. > I also don't see how to get the > value an element specified by (row, column) from a numpy_array like > "array_lines" in my original code Once you build the array, you get the element the same way you tried (but failed) earlier: print array_lines[1, 1] will print the element at row 1, column 1. The problem you had before was that you had a one dimensional array, not a two dimensional one. > All I need is a little python-example reading a file with e.g. three > lines with three numbers per line and putting those numbers as floats > in a 3x3-numpy_array, then selecting an element from that numpy_array > using it's row and column-number. Yes, I'm sure you do. And you will learn much more by writing this code yourself. You were very, very close with your earlier attempt. In English, you had: * import the numpy module * read the file into a list of text lines * store the text lines in a numpy array * try to print a single item from the array but it failed because the list of lines was only one dimensional. I gave you some code that was very similar: * import the numpy module * fake a text file using a string * split the string into a list of substrings * convert each substring into a number (float) * store the numbers in a numpy array * change the size of the array to turn it from 1D to 2D * print the array Can you identify which part of code goes with each English description? That's your first job. Then identify the parts of code you want to take from my example and put it into your example. Good luck, and have fun! -- Steven D'Aprano http://import-that.dreamwidth.org/ From __peter__ at web.de Tue Mar 25 12:12:12 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 25 Mar 2014 17:12:12 +0100 Subject: [newbie] confusion concerning fetching an element in a 2d-array References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Jean Dubois wrote: > Op dinsdag 25 maart 2014 12:01:37 UTC+1 schreef Steven D'Aprano: >> On Tue, 25 Mar 2014 03:26:26 -0700, Jean Dubois wrote: >> >> > I'm confused by the behaviour of the following python-script I wrote: >> > >> > #!/usr/bin/env python >> > #I first made a data file 'test.dat' with the following content >> > #1.0 2 3 >> > #4 5 6.0 >> > #7 8 9 >> > import numpy as np >> > lines=[line.strip() for line in open('test.dat')] >> > #convert lines-list to numpy-array >> > array_lines=np.array(lines) >> > #fetch element at 2nd row, 2nd column: >> > print array_lines[1, 1] >> > >> > >> > When running the script I always get the following error: IndexError: >> > invalid index >> > >> > Can anyone here explain me what I am doing wrong and how to fix it? >> >> Yes. Inspect the array by printing it, and you'll see that it is a one- >> dimensional array, not two, and the entries are strings: >> >> >> py> import numpy as np >> py> # simulate a text file >> ... data = """1.0 2 3 >> ... 4 5 6.0 >> ... 7 8 9""" >> py> lines=[line.strip() for line in data.split('\n')] >> py> # convert lines-list to numpy-array >> ... array_lines = np.array(lines) >> py> print array_lines >> ['1.0 2 3' '4 5 6.0' '7 8 9'] >> >> >> The interactive interpreter is your friend! You never need to guess what >> the problem is, Python has powerful introspection abilities, one of the >> most powerful is also one of the simplest: print. Another powerful tool >> in the interactive interpreter is help(). >> >> So, what to do about it? Firstly, convert your string read from a file >> into numbers, then build your array. Here's one way: >> >> py> values = [float(s) for s in data.split()] >> py> print values >> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] >> py> array_lines = np.array(values) >> py> array_lines = array_lines.reshape(3, 3) >> py> print array_lines >> [[ 1. 2. 3.] >> [ 4. 5. 6.] >> [ 7. 8. 9.]] >> > Dear Steve, > Thanks for answering my question but unfortunately now I'm totally > confused. > Above I see parts from different programs which I can't > assemble together to one working program (I really tried hard). > Can I tell from your comment I shouldn't use numpy? > I also don't see how to get the value an element specified by (row, > column) from a numpy_array like "array_lines" in my original code > > All I need is a little python-example reading a file with e.g. three lines > with three numbers per line and putting those numbers as floats in a > 3x3-numpy_array, then selecting an element from that numpy_array using > it's row and column-number. I'll try, too, but be warned that I'm using the same methology as Steven. Try to replicate every step in the following exploration. First let's make sure we start with the same data: $ cat test.dat 1.0 2 3 4 5 6.0 7 8 9 Then fire up the interactve interpreter: $ python Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> lines = [line.strip() for line in open("test.dat")] >>> lines ['1.0 2 3', '4 5 6.0', '7 8 9'] As you can see lines is a list of three strings. Let's break these strings into parts: >>> cells = [line.split() for line in lines] >>> cells [['1.0', '2', '3'], ['4', '5', '6.0'], ['7', '8', '9']] We now have a list of lists of strings and you can address individual items with >>> cells[1][2] '6.0' What happens when pass this list of lists of strings to the numpy.array() constructor? >>> a = numpy.array(cells) >>> a array([['1.0', '2', '3'], ['4', '5', '6.0'], ['7', '8', '9']], dtype='|S3') >>> a[1,2] '6.0' It sort of works, but the array entries are strings rather than floating point numbers. Let's fix that: >>> a = numpy.array(cells, dtype=float) >>> a array([[ 1., 2., 3.], [ 4., 5., 6.], [ 7., 8., 9.]]) >>> a[1,2] 6.0 OK, now we can put the previous steps into a script: $ cat tmp.py import numpy cells = [line.split() for line in open("test.dat")] a = numpy.array(cells, dtype=float) print a[1, 2] Run it: $ python tmp.py 6.0 Seems to work. But reading a 2D array from a file really looks like a common task -- there should be a library function for that: $ python Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> numpy.loadtxt("test.dat") array([[ 1., 2., 3.], [ 4., 5., 6.], [ 7., 8., 9.]]) From harrismh777 at gmail.com Tue Mar 25 12:40:26 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 11:40:26 -0500 Subject: [newbie] confusion concerning fetching an element in a 2d-array References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5331B17A.4080009@gmail.com> On 3/25/14 9:42 AM, Dave Angel wrote: >> All I need is a little python-example reading a file with e.g. three lines >> with three numbers per line and putting those numbers as floats in a >> 3x3-numpy_array, then selecting an element from that numpy_array using >> it's row and column-number. > > If your instructor wanted you to copy examples, he would have > given you one. {ouch} Give them a toad they'll have warts all day; teach them to eat a toad they'll never have warts again... or something like that. marcus From harrismh777 at gmail.com Tue Mar 25 12:58:41 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 11:58:41 -0500 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On 3/25/14 7:36 AM, Roy Smith wrote: > >> (we're on one tiny planet, you know?) > > Speak for yourself. > Are others on this list, um, on a different planet? Or, am I the only one who knows its tiny? Yes, we're on a tiny planet revolving around a speck of a star, at the edge of an insignificant galaxy ... {not that it matters} From marcelgmr at gmail.com Tue Mar 25 13:03:24 2014 From: marcelgmr at gmail.com (Marcel Rodrigues) Date: Tue, 25 Mar 2014 14:03:24 -0300 Subject: How to clear all content in a Tk() In-Reply-To: <0ed94669-6c1e-4e2f-b79d-33bed8cdde15@googlegroups.com> References: <0ed94669-6c1e-4e2f-b79d-33bed8cdde15@googlegroups.com> Message-ID: What about this: Put a Frame() inside the root: `frame = Frame(root)`. This frame will be the only immediate child of root. Everything else will be put inside the frame. When you need to clear the root, call `frame.destroy()`. This will destroy `frame` and all its children. You will need to recreate the frame, but not the root. 2014-03-24 17:30 GMT-03:00 : > I have this program, and since I want to change stuff dynamically, I want > to fully clear the root = Tk(), without deleting it. Is there a way to do > so? > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Tue Mar 25 13:24:10 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Tue, 25 Mar 2014 18:24:10 +0100 Subject: Time we switched to unicode? In-Reply-To: <87ior2zosv.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <87ior2zosv.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 25, 2014 at 9:05 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Mar 25, 2014 at 4:14 PM, Mark H Harris wrote: >>>>>> ?? = pi >> >> That's good! (Although typing ?? quicker than pi is majorly pushing it. > > It don't think that's good. The lower-case letter ?? should be used. The > upper-case letter is used for a product, although unicode dedicates a > separate character for the purpose: ??. > > I often see Americans, especially, confuse upper and lower-case letters > in symbols ("KM" for "km", "L" for "l" etc). ?L? is actually valid, and so is ?l?. This happens mainly because humans (and computers) tend to write ?1 l? (one liter, one-ell) in a way that makes it harder to distinguish (becoming eleven or ell-ell), especially if you don?t include the space (which is invalid). On Tue, Mar 25, 2014 at 9:23 AM, Chris Angelico wrote: > If you can type a capital ??, you can type a lower-case ??, unless there's something very weird going on. Nitpick time! (because we all love it so much!) ?? = U+03A0 GREEK CAPITAL LETTER PI ?? = U+03C0 GREEK SMALL LETTER PI ?? = U+220F N-ARY PRODUCT ?If you can type an N-ARY PRODUCT, you can type a GREEK SMALL LETTER PI, unless there?s something very weird going on.? ?like, the user is in the past and is using ISO 8859-7 (instead of a 21st-century encoding, like UTF-8). An encoding which has support for ?? and ??, but not for ??? (of course, this assumes that, if we add those new characters into python, we allow any encoding, somehow.) That?s not too weird, other than the ancient encoding being used. (though that?s a bit less weird on Windows, but that?d be Windows-1253.) Oh: and speaking of fancy Unicode characters that are worthless ~duplicates, spot the difference here: ? ? If you are lucky enough (and, luckiness may involve reading this e-mail in Helvetica (not Neue though) on a Mac), you can clearly see that they are different. If you are using a font that does not differentiate them, you may think they?re the same. If you ask some intelligent software (like `unicodedata.name()` in Python), you?ll quickly find out the first is MICRO SIGN, and the other is GREEK SMALL LETTER MU. Such craziness is what makes Unicode Unicode. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From rborole06 at gmail.com Tue Mar 25 14:16:20 2014 From: rborole06 at gmail.com (rborole06 at gmail.com) Date: Tue, 25 Mar 2014 11:16:20 -0700 (PDT) Subject: python installation on windows In-Reply-To: References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> Message-ID: On Sunday, 23 March 2014 18:22:54 UTC-8, Rhodri James wrote: > On Sun, 23 Mar 2014 17:09:09 -0000, wrote: > > > > > Hi Everybody > > > > > > actually i want to run python on web browser. > > > > Actually you don't. You want to run Python on a web server, which > > fortunately is a good deal easier. > > > > > I downloaded python and installed but i'm not able to run it in browser > > > but it running using command prompt. so i trying to install mod_wsgi > > > 3.4. So i downloaded precompiled version mod_wsgi-3.4.ap22.win32-py2.6 > > > and copied mod_wsgi.so file to C:\wamp\bin\apache\Apache2.2.11\modules > > > after i'm trying to run .\configure on path C:\Documents and > > > Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 but it giving me > > > error that .\configure is not recognized as internal or external command. > > > > > > So please suggest me what can i do for that, i'm so beginner to python > > > and installing and configuring modules for apache. > > > > The ".\configure" thing is for Linux installations using autotools; it's > > not going to work on Windows. > > > > I don't run Apache on Windows, so I'm just guessing from the documentation > > here, but the mod_wsgi "Installation on Windows" page says to "follow the > > instructions for loading mod_wsgi in the Quick Installation Guide." The > > "Quick Installation Guide" page has instructions for editing the Apache > > config files. No mention of running ".\configure" -- why are you doing > > that? Try just editing the config files as the documentation suggests and > > see if that works. > > > > -- > > Rhodri James *-* Wildebeest Herder to the Masses Thanks for your comment but i also edited httpd.conf file then my wamp not running LoadModule php5_module "c:/wamp/bin/php/php5.3.0/php5apache2_2.dll" This line i added on line 128 but nothing. Wampserver showing yellow. I'm not getting what happening. I'm doing as per suggested in documentation Thanks From rborole06 at gmail.com Tue Mar 25 14:17:30 2014 From: rborole06 at gmail.com (rborole06 at gmail.com) Date: Tue, 25 Mar 2014 11:17:30 -0700 (PDT) Subject: python installation on windows In-Reply-To: References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> Message-ID: <96fa02bf-7c6d-4b12-8791-d640d5910173@googlegroups.com> On Tuesday, 25 March 2014 10:16:20 UTC-8, rbor... at gmail.com wrote: > On Sunday, 23 March 2014 18:22:54 UTC-8, Rhodri James wrote: > > > On Sun, 23 Mar 2014 17:09:09 -0000, wrote: > > > > > > > > > > > > > Hi Everybody > > > > > > > > > > > > > > actually i want to run python on web browser. > > > > > > > > > > > > Actually you don't. You want to run Python on a web server, which > > > > > > fortunately is a good deal easier. > > > > > > > > > > > > > I downloaded python and installed but i'm not able to run it in browser > > > > > > > but it running using command prompt. so i trying to install mod_wsgi > > > > > > > 3.4. So i downloaded precompiled version mod_wsgi-3.4.ap22.win32-py2.6 > > > > > > > and copied mod_wsgi.so file to C:\wamp\bin\apache\Apache2.2.11\modules > > > > > > > after i'm trying to run .\configure on path C:\Documents and > > > > > > > Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 but it giving me > > > > > > > error that .\configure is not recognized as internal or external command. > > > > > > > > > > > > > > So please suggest me what can i do for that, i'm so beginner to python > > > > > > > and installing and configuring modules for apache. > > > > > > > > > > > > The ".\configure" thing is for Linux installations using autotools; it's > > > > > > not going to work on Windows. > > > > > > > > > > > > I don't run Apache on Windows, so I'm just guessing from the documentation > > > > > > here, but the mod_wsgi "Installation on Windows" page says to "follow the > > > > > > instructions for loading mod_wsgi in the Quick Installation Guide." The > > > > > > "Quick Installation Guide" page has instructions for editing the Apache > > > > > > config files. No mention of running ".\configure" -- why are you doing > > > > > > that? Try just editing the config files as the documentation suggests and > > > > > > see if that works. > > > > > > > > > > > > -- > > > > > > Rhodri James *-* Wildebeest Herder to the Masses > > > > Thanks for your comment but i also edited httpd.conf file then my wamp not running > > LoadModule php5_module "c:/wamp/bin/php/php5.3.0/php5apache2_2.dll" > > This line i added on line 128 but nothing. Wampserver showing yellow. > > I'm not getting what happening. I'm doing as per suggested in documentation > > > > Thanks And again if i'm removing this line then wampserver works properly From rborole06 at gmail.com Tue Mar 25 14:18:20 2014 From: rborole06 at gmail.com (rborole06 at gmail.com) Date: Tue, 25 Mar 2014 11:18:20 -0700 (PDT) Subject: python installation on windows In-Reply-To: <73a660da-9dd8-4104-ae9c-ba1788ae1d60@googlegroups.com> References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> <73a660da-9dd8-4104-ae9c-ba1788ae1d60@googlegroups.com> Message-ID: <9eaf90e2-55bb-4902-aac7-f515796641b9@googlegroups.com> On Sunday, 23 March 2014 13:07:28 UTC-8, tad na wrote: > On Sunday, March 23, 2014 12:33:02 PM UTC-5, tad na wrote: > > > On Sunday, March 23, 2014 12:09:09 PM UTC-5, rbor... at gmail.com wrote: > > > > Hi Everybody > > > > actually i want to run python on web browser. I downloaded python and installed but i'm not able to run it in browser but it running using command prompt. so i trying to install mod_wsgi 3.4. So i downloaded precompiled version mod_wsgi-3.4.ap22.win32-py2.6 and copied mod_wsgi.so file to C:\wamp\bin\apache\Apache2.2.11\modules after i'm trying to run .\configure on path C:\Documents and Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 but it giving me error that .\configure is not recognized as internal or external command. > > > > > > So please suggest me what can i do for that, i'm so beginner to python and installing and configuring modules for apache. > > > > > > Thanks > > > > > > Rahul > > > To set up a web browser: > > > > > 1.open a dos window > > > 2.navigate to dir you want "served" > > > 3.type "python -m SimpleHTTPServer 8888 &." > > 4. open browser and type http://localhost:8888/ It's saying unable to connect to localhost From rborole06 at gmail.com Tue Mar 25 14:19:56 2014 From: rborole06 at gmail.com (rborole06 at gmail.com) Date: Tue, 25 Mar 2014 11:19:56 -0700 (PDT) Subject: python installation on windows In-Reply-To: References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> <73a660da-9dd8-4104-ae9c-ba1788ae1d60@googlegroups.com> Message-ID: <0de4bfdf-5c85-418b-8c9c-95b7bbe57a6f@googlegroups.com> On Sunday, 23 March 2014 19:35:19 UTC-8, Chris Angelico wrote: > On Mon, Mar 24, 2014 at 2:28 PM, Mark H Harris wrote: > > > Anyway, the PSF runs python (the interpreter) from a web server (I can > > > access the python interpreter from my browser from the PSF site). > > > > > > How is that done simply, is possibly what the OP wants to know (me too). > > > > That's a much MUCH harder thing to do than running Python code in your > > web server, because of trust issues. I don't know how it's set up, but > > there'll be something in there to protect the server against malicious > > or accidental insanity (spinning with "while True: pass", trying to > > read/write files, trying to execute commands, using up all of RAM with > > "x = []\nwhile True: x.append(1)", etc, etc, etc). That's actually a > > very hard problem to solve, not something where you can just say > > "Here, this is how to run Python via a browser". > > > > ChrisA LoadModule wsgi_module modules/mod_wsgi.so This line also i added but then also same problem From harrismh777 at gmail.com Tue Mar 25 12:40:26 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 11:40:26 -0500 Subject: [newbie] confusion concerning fetching an element in a 2d-array In-Reply-To: References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5331B17A.4080009@gmail.com> On 3/25/14 9:42 AM, Dave Angel wrote: >> All I need is a little python-example reading a file with e.g. three lines >> with three numbers per line and putting those numbers as floats in a >> 3x3-numpy_array, then selecting an element from that numpy_array using >> it's row and column-number. > > If your instructor wanted you to copy examples, he would have > given you one. {ouch} Give them a toad they'll have warts all day; teach them to eat a toad they'll never have warts again... or something like that. marcus From harrismh777 at gmail.com Tue Mar 25 14:30:34 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 13:30:34 -0500 Subject: unicode as valid naming symbols Message-ID: greetings, I would like to create a lamda as follows: ? = lambda n: sqrt(n) On my keyboard mapping the "problem" character is alt-v which produces the radical symbol. When trying to set the symbol as a name within the name-space gives a syntax error: >>> from math import sqrt >>> >>> ? = lambda n: sqrt(n) SyntaxError: invalid character in identifier >>> >>> however this works: >>> >>> ? = lambda n: sqrt(n) >>> >>> ?(2) 1.4142135623730951 >>> The question is which unicode(s) are capable of being proper name characters, and which ones are off-limits, and why? marcus From jeandubois314 at gmail.com Tue Mar 25 14:33:28 2014 From: jeandubois314 at gmail.com (Jean Dubois) Date: Tue, 25 Mar 2014 11:33:28 -0700 (PDT) Subject: [newbie] confusion concerning fetching an element in a 2d-array In-Reply-To: References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <80338ca6-b9af-4943-bf5e-318a1e2b4b15@googlegroups.com> Op dinsdag 25 maart 2014 17:12:12 UTC+1 schreef Peter Otten: > Jean Dubois wrote: > > Op dinsdag 25 maart 2014 12:01:37 UTC+1 schreef Steven D'Aprano: > >> On Tue, 25 Mar 2014 03:26:26 -0700, Jean Dubois wrote: > >> > >> > I'm confused by the behaviour of the following python-script I wrote: > >> > > >> > #!/usr/bin/env python > >> > #I first made a data file 'test.dat' with the following content > >> > #1.0 2 3 > >> > #4 5 6.0 > >> > #7 8 9 > >> > import numpy as np > >> > lines=[line.strip() for line in open('test.dat')] > >> > #convert lines-list to numpy-array > >> > array_lines=np.array(lines) > >> > #fetch element at 2nd row, 2nd column: > >> > print array_lines[1, 1] > >> > > >> > > >> > When running the script I always get the following error: IndexError: > >> > invalid index > >> > > >> > Can anyone here explain me what I am doing wrong and how to fix it? > >> > >> Yes. Inspect the array by printing it, and you'll see that it is a one- > >> dimensional array, not two, and the entries are strings: > >> > >> > >> py> import numpy as np > >> py> # simulate a text file > >> ... data = """1.0 2 3 > >> ... 4 5 6.0 > >> ... 7 8 9""" > >> py> lines=[line.strip() for line in data.split('\n')] > >> py> # convert lines-list to numpy-array > >> ... array_lines = np.array(lines) > >> py> print array_lines > >> ['1.0 2 3' '4 5 6.0' '7 8 9'] > >> > >> > >> The interactive interpreter is your friend! You never need to guess what > >> the problem is, Python has powerful introspection abilities, one of the > >> most powerful is also one of the simplest: print. Another powerful tool > >> in the interactive interpreter is help(). > >> > >> So, what to do about it? Firstly, convert your string read from a file > >> into numbers, then build your array. Here's one way: > >> > >> py> values = [float(s) for s in data.split()] > >> py> print values > >> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] > >> py> array_lines = np.array(values) > >> py> array_lines = array_lines.reshape(3, 3) > >> py> print array_lines > >> [[ 1. 2. 3.] > >> [ 4. 5. 6.] > >> [ 7. 8. 9.]] > >> > > Dear Steve, > > Thanks for answering my question but unfortunately now I'm totally > > confused. > > Above I see parts from different programs which I can't > > assemble together to one working program (I really tried hard). > > Can I tell from your comment I shouldn't use numpy? > > I also don't see how to get the value an element specified by (row, > > column) from a numpy_array like "array_lines" in my original code > > > > All I need is a little python-example reading a file with e.g. three lines > > with three numbers per line and putting those numbers as floats in a > > 3x3-numpy_array, then selecting an element from that numpy_array using > > it's row and column-number. > I'll try, too, but be warned that I'm using the same methology as Steven. > Try to replicate every step in the following exploration. > First let's make sure we start with the same data: > $ cat test.dat > 1.0 2 3 > 4 5 6.0 > 7 8 9 > Then fire up the interactve interpreter: > $ python > Python 2.7.5+ (default, Feb 27 2014, 19:37:08) > [GCC 4.8.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import numpy > >>> lines = [line.strip() for line in open("test.dat")] > >>> lines > ['1.0 2 3', '4 5 6.0', '7 8 9'] > As you can see lines is a list of three strings. > Let's break these strings into parts: > >>> cells = [line.split() for line in lines] > >>> cells > [['1.0', '2', '3'], ['4', '5', '6.0'], ['7', '8', '9']] > We now have a list of lists of strings and you can address individual items > with > >>> cells[1][2] > '6.0' > What happens when pass this list of lists of strings to the numpy.array() > constructor? > >>> a = numpy.array(cells) > >>> a > array([['1.0', '2', '3'], > ['4', '5', '6.0'], > ['7', '8', '9']], > dtype='|S3') > >>> a[1,2] > '6.0' > It sort of works, but the array entries are strings rather than floating > point numbers. Let's fix that: > >>> a = numpy.array(cells, dtype=float) > >>> a > array([[ 1., 2., 3.], > [ 4., 5., 6.], > [ 7., 8., 9.]]) > >>> a[1,2] > 6.0 > OK, now we can put the previous steps into a script: > $ cat tmp.py > import numpy > cells = [line.split() for line in open("test.dat")] > a = numpy.array(cells, dtype=float) > print a[1, 2] > Run it: > $ python tmp.py > 6.0 > Seems to work. But reading a 2D array from a file really looks like a common > task -- there should be a library function for that: > $ python > Python 2.7.5+ (default, Feb 27 2014, 19:37:08) > [GCC 4.8.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import numpy > >>> numpy.loadtxt("test.dat") > array([[ 1., 2., 3.], > [ 4., 5., 6.], > [ 7., 8., 9.]]) Thank you very much Peter for this great lesson, you made a lot of things clear to me. sincerely jean From wxjmfauth at gmail.com Tue Mar 25 14:52:40 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 25 Mar 2014 11:52:40 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: Message-ID: <8c6c7b14-7f7a-4b71-987c-487e51becfed@googlegroups.com> Le mardi 25 mars 2014 19:30:34 UTC+1, Mark H. Harris a ?crit?: > greetings, I would like to create a lamda as follows: > > > > ? = lambda n: sqrt(n) > > > > > > On my keyboard mapping the "problem" character is alt-v which produces > > the radical symbol. When trying to set the symbol as a name within the > > name-space gives a syntax error: > > > > >>> from math import sqrt > > >>> > > >>> ? = lambda n: sqrt(n) > > SyntaxError: invalid character in identifier > > >>> > > >>> > > > > however this works: > > > > >>> > > >>> ? = lambda n: sqrt(n) > > >>> > > >>> ?(2) > > 1.4142135623730951 > > >>> > > > > The question is which unicode(s) are capable of being proper name > > characters, and which ones are off-limits, and why? > > > > > > marcus >>> '?'.isidentifier() False >>> '?'.isidentifier() True >>> '$'.isidentifier() False >>> '?'.isidentifier() True >>> 'a'.isidentifier() True >>> '?2z'.isidentifier() True >>> print(''.isidentifier.__doc__) S.isidentifier() -> bool Return True if S is a valid identifier according to the language definition. >>> cf "unicode.org" doc jmf From jeandubois314 at gmail.com Tue Mar 25 14:58:11 2014 From: jeandubois314 at gmail.com (Jean Dubois) Date: Tue, 25 Mar 2014 11:58:11 -0700 (PDT) Subject: [newbie] confusion concerning fetching an element in a 2d-array In-Reply-To: References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0cf3d503-8cd6-4702-9260-b0ef3f4cf561@googlegroups.com> Op dinsdag 25 maart 2014 15:42:13 UTC+1 schreef Dave Angel: > Jean Dubois Wrote in message: > > Op dinsdag 25 maart 2014 12:01:37 UTC+1 schreef Steven D'Aprano: > >> > >> py> values = [float(s) for s in data.split()] > >> py> print values > >> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] > >> py> array_lines = np.array(values) > >> py> array_lines = array_lines.reshape(3, 3) > >> py> print array_lines > >> [[ 1. 2. 3.] > >> [ 4. 5. 6.] > >> [ 7. 8. 9.]] > >> > > Dear Steve, > > Thanks for answering my question but unfortunately now I'm totally > > confused. > > Above I see parts from different programs which I can't > > assemble together to one working program (I really tried hard). > > Can I tell from your comment I shouldn't use numpy? > > I also don't see how to get the value an element specified by (row, > > column) from a numpy_array like "array_lines" in my original code > I don't use numpy, but I thought Steven's description was clear > enough. > Your problem was not the extraction, but the creation of the > array. Use print to prove that to yourself. > > > > All I need is a little python-example reading a file with e.g. three lines > > with three numbers per line and putting those numbers as floats in a > > 3x3-numpy_array, then selecting an element from that numpy_array using > > it's row and column-number. > If your instructor wanted you to copy examples, he would have > given you one. please Dave leave that belittling tone behind, there's no instructor whatsoever involved here. I constructed this example myself as I know very well I have to start with little pieces of code first to be able to master larger problems later. I just wanted to figure this example out first, and as I now learned from Peter's marvellous explanation there _is_ an elegant solution in Python to this kind of problem. So if you are irritated by newbie-questions in the future, just neglect them thanks jean From breamoreboy at yahoo.co.uk Tue Mar 25 15:00:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Mar 2014 19:00:41 +0000 Subject: python installation on windows In-Reply-To: <96fa02bf-7c6d-4b12-8791-d640d5910173@googlegroups.com> References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> <96fa02bf-7c6d-4b12-8791-d640d5910173@googlegroups.com> Message-ID: On 25/03/2014 18:17, rborole06 at gmail.com wrote: Would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From python at mrabarnett.plus.com Tue Mar 25 15:24:43 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 25 Mar 2014 19:24:43 +0000 Subject: unicode as valid naming symbols In-Reply-To: References: Message-ID: <5331D7FB.50600@mrabarnett.plus.com> On 2014-03-25 18:30, Mark H Harris wrote: > greetings, I would like to create a lamda as follows: > > ? = lambda n: sqrt(n) > > > On my keyboard mapping the "problem" character is alt-v which produces > the radical symbol. When trying to set the symbol as a name within the > name-space gives a syntax error: > > >>> from math import sqrt > >>> > >>> ? = lambda n: sqrt(n) > SyntaxError: invalid character in identifier > >>> > >>> > > however this works: > > >>> > >>> ? = lambda n: sqrt(n) > >>> > >>> ?(2) > 1.4142135623730951 > >>> > > The question is which unicode(s) are capable of being proper name > characters, and which ones are off-limits, and why? > It's explained in PEP 3131. Basically, a name should to start with a letter (this has been extended to include Chinese characters, etc) or an underscore. ? is a classified as Lowercase_Letter. ? is classified as Math_Symbol. From harrismh777 at gmail.com Tue Mar 25 15:24:11 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 14:24:11 -0500 Subject: unicode as valid naming symbols References: <8c6c7b14-7f7a-4b71-987c-487e51becfed@googlegroups.com> Message-ID: On 3/25/14 1:52 PM, wxjmfauth at gmail.com wrote: >>>> '?'.isidentifier() > False >>>> '?'.isidentifier() > True > S.isidentifier() -> bool > > Return True if S is a valid identifier according > to the language definition. >>>> > > cf "unicode.org" doc Excellent, thanks! marcus From harrismh777 at gmail.com Tue Mar 25 15:29:06 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 14:29:06 -0500 Subject: unicode as valid naming symbols References: Message-ID: <5331D902.3030902@gmail.com> On 3/25/14 2:24 PM, MRAB wrote: > It's explained in PEP 3131. > > Basically, a name should to start with a letter (this has been extended > to include Chinese characters, etc) or an underscore. > > ? is a classified as Lowercase_Letter. > > ? is classified as Math_Symbol. Thanks much! I'll note that for improvements. Any unicode symbol (that is not a number) should be allowed as an identifier. marcus From rosuav at gmail.com Tue Mar 25 15:40:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 06:40:42 +1100 Subject: Time we switched to unicode? In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <87ior2zosv.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 26, 2014 at 4:24 AM, Chris ?Kwpolska? Warrick wrote: > ?If you can type an N-ARY PRODUCT, you can type a GREEK SMALL LETTER > PI, unless there?s something very weird going on.? > > ?like, the user is in the past and is using ISO 8859-7 (instead of a > 21st-century encoding, like UTF-8). An encoding which has support for > ?? and ??, but not for ??? (of course, this assumes that, if we add > those new characters into python, we allow any encoding, somehow.) > > That?s not too weird, other than the ancient encoding being used. Since we opened by discussing Unicode, anyone who's cheating and using an eight-bit character set is, well, cheating. :) ChrisA From davea at davea.name Tue Mar 25 15:45:51 2014 From: davea at davea.name (Dave Angel) Date: Tue, 25 Mar 2014 15:45:51 -0400 (EDT) Subject: unicode as valid naming symbols References: Message-ID: Mark H Harris Wrote in message: > greetings, I would like to create a lamda as follows: > > ??? = lambda n: sqrt(n) > > > On my keyboard mapping the "problem" character is alt-v which produces > the radical symbol. When trying to set the symbol as a name within the > name-space gives a syntax error: > > >>> from math import sqrt > >>> > >>> ??? = lambda n: sqrt(n) > SyntaxError: invalid character in identifier > >>> > >>> > > however this works: > > >>> > >>> ?? = lambda n: sqrt(n) > >>> > >>> ??(2) > 1.4142135623730951 > >>> > > The question is which unicode(s) are capable of being proper name > characters, and which ones are off-limits, and why? See the official docs http://docs.python.org/3/reference/lexical_analysis.html#identifiers There's also a method on str that'll tell you: isidentifier (). To see such methods, use dir ("") As for why, you can get a pretty good idea from the reference above, as it lists 12 unicode categories that can be used. You can also look at pep3131 and at Potsdam ' s site. Both links are on the above page. Letters, marks, connectors, and numbers, but not punctuation. -- DaveA From joel.goldstick at gmail.com Tue Mar 25 15:15:27 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 25 Mar 2014 15:15:27 -0400 Subject: [newbie] confusion concerning fetching an element in a 2d-array In-Reply-To: <0cf3d503-8cd6-4702-9260-b0ef3f4cf561@googlegroups.com> References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> <0cf3d503-8cd6-4702-9260-b0ef3f4cf561@googlegroups.com> Message-ID: Jean, be aware there is also python tutor list you might like. This is sometimes a tough crowd here. Don't be discouraged. It can be a badge of honor sometimes -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Mar 25 15:49:09 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 25 Mar 2014 13:49:09 -0600 Subject: unicode as valid naming symbols In-Reply-To: <5331D902.3030902@gmail.com> References: <5331D902.3030902@gmail.com> Message-ID: On Tue, Mar 25, 2014 at 1:29 PM, Mark H Harris wrote: > On 3/25/14 2:24 PM, MRAB wrote: >> It's explained in PEP 3131. >> >> Basically, a name should to start with a letter (this has been extended >> to include Chinese characters, etc) or an underscore. >> >> ? is a classified as Lowercase_Letter. >> >> ? is classified as Math_Symbol. > > Thanks much! I'll note that for improvements. Any unicode symbol (that > is not a number) should be allowed as an identifier. ? cannot be used in identifiers for the same reasons that + and ~ cannot: identifiers are intended to be alphanumeric. ? is not currently the name of an operator, but who knows what may happen in the future? Python generally follows Annex 31 of the Unicode standard in this regard: http://www.unicode.org/reports/tr31/ From marko at pacujo.net Tue Mar 25 15:48:21 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 25 Mar 2014 21:48:21 +0200 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> Message-ID: <87ha6mm54q.fsf@elektro.pacujo.net> Mark H Harris : > Thanks much! I'll note that for improvements. Any unicode symbol > (that is not a number) should be allowed as an identifier. I don't know if that's a good idea, but that's how it is in lisp/scheme. Thus, "*" and "1+" are normal identifiers in lisp and scheme. Marko From davea at davea.name Tue Mar 25 15:58:10 2014 From: davea at davea.name (Dave Angel) Date: Tue, 25 Mar 2014 15:58:10 -0400 (EDT) Subject: [newbie] confusion concerning fetching an element in a 2d-array References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> <0cf3d503-8cd6-4702-9260-b0ef3f4cf561@googlegroups.com> Message-ID: Jean Dubois Wrote in message: > Op dinsdag 25 maart 2014 15:42:13 UTC+1 schreef Dave Angel: >> If your instructor wanted you to copy examples, he would have >> given you one. > please Dave leave that belittling tone behind, there's no instructor > whatsoever involved here. It wasn't my intention to belittle you; I'm sorry. But we do get a lot of people here asking for homework help, and not saying that's what it is. And when it's homework we do better explaining than just writing the code. In fact you only needed to add a line like data= infile.read () to Steven's original to get a complete working example. > I constructed this example myself as I know very > well I have to start with little pieces of code first to be able to master > larger problems later. I just wanted to figure this example out first, > and as I now learned from Peter's marvellous explanation there _is_ an > elegant solution in Python to this kind of problem. > So if you are irritated by newbie-questions in the future, just neglect > them Not irritated, just temporarily misguided. -- DaveA From skip at pobox.com Tue Mar 25 15:54:34 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 25 Mar 2014 14:54:34 -0500 Subject: unicode as valid naming symbols In-Reply-To: <87ha6mm54q.fsf@elektro.pacujo.net> References: <5331D902.3030902@gmail.com> <87ha6mm54q.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 25, 2014 at 2:48 PM, Marko Rauhamaa wrote: > I don't know if that's a good idea, but that's how it is in lisp/scheme. > > Thus, "*" and "1+" are normal identifiers in lisp and scheme. But parsing Lisp is pretty trivial. Skip From harrismh777 at gmail.com Tue Mar 25 15:29:06 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Tue, 25 Mar 2014 14:29:06 -0500 Subject: unicode as valid naming symbols In-Reply-To: References: Message-ID: <5331D902.3030902@gmail.com> On 3/25/14 2:24 PM, MRAB wrote: > It's explained in PEP 3131. > > Basically, a name should to start with a letter (this has been extended > to include Chinese characters, etc) or an underscore. > > ? is a classified as Lowercase_Letter. > > ? is classified as Math_Symbol. Thanks much! I'll note that for improvements. Any unicode symbol (that is not a number) should be allowed as an identifier. marcus From greg.ewing at canterbury.ac.nz Tue Mar 25 16:21:09 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 26 Mar 2014 09:21:09 +1300 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: Roy Smith wrote: > Doors that open automatically as you approach them are now > routine. Star Trek doors seem to be a bit smarter, though. Captain Kirk never had to stop in front of a door and wait for it to sluggishly slide open. Also the doors never open when you're just walking past and not intending to go through. -- Greg From python.list at tim.thechases.com Tue Mar 25 16:29:41 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 25 Mar 2014 15:29:41 -0500 Subject: unicode as valid naming symbols In-Reply-To: <5331D902.3030902@gmail.com> References: <5331D902.3030902@gmail.com> Message-ID: <20140325152941.4d84c539@bigbox.christie.dr> On 2014-03-25 14:29, Mark H Harris wrote: > > It's explained in PEP 3131. > > > > Basically, a name should to start with a letter (this has been > > extended to include Chinese characters, etc) or an underscore. > > > > ? is a classified as Lowercase_Letter. > > > > ? is classified as Math_Symbol. > > Thanks much! I'll note that for improvements. Any unicode > symbol (that is not a number) should be allowed as an identifier. It's not just about number'ness: >>> letter = "a" >>> number = "2" >>> letter.isidentifier() True >>> number.isidentifier() False >>> (letter + number).isidentifier() True -tkc From larry.martell at gmail.com Tue Mar 25 16:31:10 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 25 Mar 2014 16:31:10 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On Tue, Mar 25, 2014 at 4:21 PM, Gregory Ewing wrote: > Roy Smith wrote: > >> Doors that open automatically as you approach them are now routine. >> > > Star Trek doors seem to be a bit smarter, though. > Captain Kirk never had to stop in front of a door > and wait for it to sluggishly slide open. Also the > doors never open when you're just walking past and > not intending to go through. https://www.youtube.com/watch?v=JZAkGfJY05k -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Tue Mar 25 16:33:40 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 26 Mar 2014 09:33:40 +1300 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <2f646b95-7d73-4a60-a222-96fa3cd219df@googlegroups.com> Message-ID: Rustom Mody wrote: > ? for some reason seems inappropriate > (some vague recollection that its an only English; Europeans dont use it??) To me it's something you learn in primary school and then grow out of when you start doing "real" mathematics. The "/" is actually a better approximation of what mathematicians use. -- Greg From antoine at python.org Tue Mar 25 16:35:58 2014 From: antoine at python.org (Antoine Pitrou) Date: Tue, 25 Mar 2014 20:35:58 +0000 (UTC) Subject: [ANN] pathlib 1.0 Message-ID: Hello, I am announcing the release of pathlib 1.0. This version brings pathlib up to date with the official Python 3.4 release, and also fixes a couple of 2.7-specific issues. Detailed changelog can be found further below. In the future, I expect the standalone (PyPI) version of pathlib to receive little to no updates, except if severe issues are found. New developments and regular bug fixes will happen mostly in the Python standard library, and be publicly available in official Python releases. Overview -------- pathlib offers a set of classes to handle filesystem paths. It offers the following advantages over using string objects: * No more cumbersome use of os and os.path functions. Everything can be done easily through operators, attribute accesses, and method calls. * Embodies the semantics of different path types. For example, comparing Windows paths ignores casing. * Well-defined semantics, eliminating any warts or ambiguities (forward vs. backward slashes, etc.). Requirements ------------ Python 3.2 or later is recommended, but pathlib is also usable with Python 2.7. Install ------- In Python 3.4, pathlib is now part of the standard library. For Python 3.3 and earlier, ``easy_install pathlib`` or ``pip install pathlib`` should do the trick. Changelog for version 1.0 ------------------------- - Python issue #20765: Add missing documentation for PurePath.with_name() and PurePath.with_suffix(). - Fix test_mkdir_parents when the working directory has additional bits set (such as the setgid or sticky bits). - Python issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix. - Python issue #19918: Fix PurePath.relative_to() under Windows. - Python issue #19921: When Path.mkdir() is called with parents=True, any missing parent is created with the default permissions, ignoring the mode argument (mimicking the POSIX "mkdir -p" command). - Python issue #19887: Improve the Path.resolve() algorithm to support certain symlink chains. - Make pathlib usable under Python 2.7 with unicode pathnames (only pure ASCII, though). - Issue #21: fix TypeError under Python 2.7 when using new division. - Add tox support for easier testing. Regards Antoine. From greg.ewing at canterbury.ac.nz Tue Mar 25 16:37:29 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 26 Mar 2014 09:37:29 +1300 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> <53317191.7050701@rece.vub.ac.be> Message-ID: Chris Angelico wrote: > But you can't do the same for braces. You'd have to eschew *both* > literal-ish notations and use explicit constructors everywhere. Not > clean. This could have been dealt with by giving Python 2.7 a "from __future__ import braces_mean_sets" option or something like that. But I agree that the disruption would not have been worth the benefit. -- Greg From antoine at python.org Tue Mar 25 16:41:28 2014 From: antoine at python.org (Antoine Pitrou) Date: Tue, 25 Mar 2014 20:41:28 +0000 (UTC) Subject: [ANN] pathlib 1.0 References: Message-ID: Oh, and of course it is published on PyPI: https://pypi.python.org/pypi/pathlib/ Regards Antoine. From greg.ewing at canterbury.ac.nz Tue Mar 25 16:58:30 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 26 Mar 2014 09:58:30 +1300 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53318f0b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > Hey look, we have a rogue AI... "CONSOLE!"... Except that any rogue AI who's at all serious about the matter would take care of that little loophole at an early stage. "Open the pod bay doors, HAL." "I'm afraid I can't do that, Dave." "CONSOLE!" "Sorry, Dave. Nice try, but I've remapped that command to shut down the pod's life support and depressurise the cabin." Fshhhhhhh.... -- Greg From eneskristo at gmail.com Tue Mar 25 17:15:11 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Tue, 25 Mar 2014 14:15:11 -0700 (PDT) Subject: Errors on text.get() Message-ID: <7548537d-7aee-4404-98b3-8b5ce294d971@googlegroups.com> Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) File "C:/Users/User/PycharmProjects/Cesarian Codes/project.py", line 43, in gen_random string = text.get('1.0', 'end') File "C:\Python33\lib\tkinter\__init__.py", line 3104, in get return self.tk.call(self._w, 'get', index1, index2) _tkinter.TclError: invalid command name ".44500976.44544352" I'm having a strange error. I haven't found anything online so far. If I should supply parts of the code, please post here. Thank you in advance! From breamoreboy at yahoo.co.uk Tue Mar 25 17:22:54 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 25 Mar 2014 21:22:54 +0000 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> Message-ID: On 25/03/2014 20:21, Gregory Ewing wrote: > Roy Smith wrote: >> Doors that open automatically as you approach them are now routine. > > Star Trek doors seem to be a bit smarter, though. > Captain Kirk never had to stop in front of a door > and wait for it to sluggishly slide open. Also the > doors never open when you're just walking past and > not intending to go through. > Had anything gone wrong, there was always Scottie. "What's the trouble, Scottie?". "Main drive's gone, Captain.". "How long will it take to fix.". "Three days.". "You've got 20 minutes". "Ay ay, Captain.". Nowadays the role of the Captain is taken by the salesman, sorry the Account Manager, and Scottie is played by the programming team leader. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From __peter__ at web.de Tue Mar 25 17:39:18 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 25 Mar 2014 22:39:18 +0100 Subject: Errors on text.get() References: <7548537d-7aee-4404-98b3-8b5ce294d971@googlegroups.com> Message-ID: eneskristo at gmail.com wrote: > Exception in Tkinter callback > Traceback (most recent call last): > File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ > return self.func(*args) > File "C:/Users/User/PycharmProjects/Cesarian Codes/project.py", line 43, > in gen_random > string = text.get('1.0', 'end') > File "C:\Python33\lib\tkinter\__init__.py", line 3104, in get > return self.tk.call(self._w, 'get', index1, index2) > _tkinter.TclError: invalid command name ".44500976.44544352" > > I'm having a strange error. I haven't found anything online so far. If I > should supply parts of the code, please post here. Thank you in advance! Once you have destroyed a widget you can no longer access its data: >>> import tkinter as tk >>> root = tk.Tk() >>> text = tk.Text(root) >>> text.pack() >>> text.get("1.0", "end") '\n' >>> text.destroy() >>> text.get("1.0", "end") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.3/tkinter/__init__.py", line 3107, in get return self.tk.call(self._w, 'get', index1, index2) _tkinter.TclError: invalid command name ".140692133333008" From cs at zip.com.au Tue Mar 25 18:16:09 2014 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 26 Mar 2014 09:16:09 +1100 Subject: unicode as valid naming symbols In-Reply-To: <87ha6mm54q.fsf@elektro.pacujo.net> References: <87ha6mm54q.fsf@elektro.pacujo.net> Message-ID: <20140325221609.GA96574@cskk.homeip.net> On 25Mar2014 21:48, Marko Rauhamaa wrote: > Mark H Harris : > > Thanks much! I'll note that for improvements. Any unicode symbol > > (that is not a number) should be allowed as an identifier. > > I don't know if that's a good idea, but that's how it is in lisp/scheme. I think it is a terrible idea. Doing that preemptively prevents allowing them for any other purpose in the future, ever. Identifiers are easy if you stick to the corresponding Unicode class. Sucking in every other symbol prevents other uses later. Such as using the square root symbol as a prefix operator. Etc. Don't be too grabby with syntax; it leaves no room later for better syntax. Cheers, -- Cameron Simpson From tjreedy at udel.edu Tue Mar 25 18:39:54 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Mar 2014 18:39:54 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> <8b4fd4f8-f626-4b0d-8bda-6b6813ca7403@googlegroups.com> <592062d8-37a1-4f80-a9db-b3b17a6215b9@googlegroups.com> Message-ID: On 3/25/2014 2:50 AM, Chris Angelico wrote: > On Tue, Mar 25, 2014 at 5:41 PM, Rustom Mody wrote: >> ALl of which is isomorphic to Steven's point that forty is less >> eyeballable than 40 >> >> And mine that ? is more eyeballable than set([]) > > I don't disagree that it is; the short tokens are easier to read in > quantity. I just don't think that it's sufficient to justify piles of > new and hard-to-look-up operators and things. (And a literal notation > for an empty set would be a good thing. If I were designing a > Python-like language from scratch now, I'd probably differentiate sets > and dictionaries better, which would allow each one to have its own > empty literal.) If {} were empty set, {:} would be empty dict. This was considered but rejected for 3.0 as breaking too much code for too little benefit. -- Terry Jan Reedy From ethan at stoneleaf.us Tue Mar 25 18:47:47 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 25 Mar 2014 15:47:47 -0700 Subject: unicode as valid naming symbols In-Reply-To: <5331D902.3030902@gmail.com> References: <5331D902.3030902@gmail.com> Message-ID: <53320793.8070501@stoneleaf.us> On 03/25/2014 12:29 PM, Mark H Harris wrote: > On 3/25/14 2:24 PM, MRAB wrote: >> It's explained in PEP 3131. >> >> Basically, a name should to start with a letter (this has been extended >> to include Chinese characters, etc) or an underscore. >> >> ? is a classified as Lowercase_Letter. >> >> ? is classified as Math_Symbol. > > Thanks much! I'll note that for improvements. Any unicode symbol (that is not a number) should be allowed as an > identifier. No, it shouldn't. Doing so would mean we could not use ? as the square root operator in the future. Identifiers are made up of letters, numbers, and the underscore. Considering all the unicode letters and unicode numbers out there, you shouldn't be lacking for names. -- ~Ethan~ From tjreedy at udel.edu Tue Mar 25 19:55:39 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Mar 2014 19:55:39 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/25/2014 11:18 AM, Steven D'Aprano wrote: > The thing is, we can't just create a ? function, because it doesn't work > the way the summation operator works. The problem is that we would want > syntactic support, so we could write something like this: > > p = 2 > ?(n, 1, 10, n**p) Of course we can. If we do not insist on separating the dummy name from the expression that contains it. this works. def sigma(low, high, func): sum = 0 for i in range(low, high+1): sum += func(i) return sum p = 2 print(sigma(1, 10, lambda n: n**p)) >>> 385 which looks correct. This corresponds to a notation like so 10 ? n: n**p 1 which, for ranges, is more sensible that the standard. Lambda is an explicit rather than implicit quotation. If you do insist on separating two things that belong together, you can quote with quote marks instead and join within the function to get the same answer. def sig2(var, low, high, exp): func = eval("lambda {}: {}".format(var, exp)) sum = 0 for i in range(low, high+1): sum += func(i) return sum p = 2 print(sig2('n', 1, 10, 'n**p')) >>> 385 To me, both these apis are 'something' like the api with implicit quoting, which is impossible for function calls, but common in statements. (This is one reason to make a construct a python statement rather than function. Jumping is another) Using the same api, one could instead expand the template to include the for loop and use exec instead of eval. def sig3(var, low, high, exp): loca = {} exec( '''\ sum = 0 for {} in range({}, {}): sum += {}\ '''.format(var, low, high+1, exp), globals(), loca) return loca['sum'] print(sig3('n', 1, 10, 'n**p')) > This cannot be an ordinary function, because if it were, the n**p > expression would be evaluated before passing the result to the function. So would the dummy parameter name n. > We want it to delay evaluation, like a list comp: > > [n**p for n in range(1, 11)] > > the expression n**p gets evaluated inside the list comp. Which is to say, it is implicitly quoted > That cannot be written as a function either: > > list_comp(n**p, n, range(1, 11) It can be with explicit quoting, similar to how done for sigma. Some lisps once and maybe still have 'special' functions that implicitly quote certain arguments. One just has to learn which functions and which parameters. I prefer having implicit quoting relegated to a limited set of statements, where is it pretty clear what must be quoted for the statement to make any sense. Assignment is one example, while, for, and comprehensions are others. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Tue Mar 25 19:58:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2014 23:58:17 GMT Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> Message-ID: <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 14:29:06 -0500, Mark H Harris wrote: > On 3/25/14 2:24 PM, MRAB wrote: > > It's explained in PEP 3131. > > > > Basically, a name should to start with a letter (this has been > > extended to include Chinese characters, etc) or an underscore. > > > > ? is a classified as Lowercase_Letter. > > > > ? is classified as Math_Symbol. > > Thanks much! I'll note that for improvements. Any unicode symbol > (that is not a number) should be allowed as an identifier. To quote a great Spaniard: ?You keep using that word, I do not think it means what you think it means.? Do you think that the ability to write this would be an improvement? import ? ? = ?.?? ? = 5*?.?? ? = ? - 1 ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] ?.??????(???) Of course, it's not even necessary to be that exotic. "Any unicode symbol that is not a number"... that means things like these: x+y spam.eggs cheese["toast"] would count as identifiers, which could lead to a little bit of parsing ambiguity... *wink* There are languages that can allow arbitrary symbols as identifiers, like Lisp and Forth. You will note that they have a certain reputation for being, um, different, and although both went through periods of considerable popularity, both have faded in popularity since. While they have their strengths, and their defenders, nobody argues that they are readily accessible to the average programmer. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Tue Mar 25 20:12:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2014 00:12:46 GMT Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote: > On 3/25/2014 11:18 AM, Steven D'Aprano wrote: > >> The thing is, we can't just create a ? function, because it doesn't >> work the way the summation operator works. The problem is that we would >> want syntactic support, so we could write something like this: >> >> p = 2 >> ?(n, 1, 10, n**p) > > Of course we can. If we do not insist on separating the dummy name from > the expression that contains it. this works. > > def sigma(low, high, func): > sum = 0 > for i in range(low, high+1): > sum += func(i) > return sum There is no expression there. There is a function. You cannot pass an expression to a function in Python, not in the sense I am talking about, because expressions are not first-class objects. When you pass: sigma(1, 10, n**p) the n**p gets evaluated immediately. Only with support of the compiler does evaluation of the expression get delayed, e.g.: it = (n**p for n in range(1, 11)) result = (-100)**p if isinstance(p, int) else float('nan') first = items and items[0] If we tried to write an "and" function like this: def and_(a, b): if a: return a return b it wouldn't work the same as the `and` operator, because the `and` operator is lazy and only evaluates the right hand operator when needed, whereas the function call is greedy and evaluates the right hand operator up front, whether it is needed or not. Passing a *function* is not the same as writing an expression. It is a work-around for lack of first-class expressions. Now perhaps it is an acceptable work-around, for some purposes at least. But if you want to match mathematical syntax, it's not enough. -- Steven D'Aprano http://import-that.dreamwidth.org/ From tjreedy at udel.edu Tue Mar 25 20:24:26 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Mar 2014 20:24:26 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53317191.7050701@rece.vub.ac.be> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> <53317191.7050701@rece.vub.ac.be> Message-ID: On 3/25/2014 8:07 AM, Antoon Pardon wrote: > On 25-03-14 12:12, Chris Angelico wrote: > >> On Tue, Mar 25, 2014 at 9:24 PM, Antoon Pardon >> wrote: >>> No they didn't have to. With the transition to python3, the developers >>> could have opted for empty braces to mean an empty set. And if they >>> wanted a literal for an empty dictionary, they might have chosen {:}. >>> Backward-compatibility was already broken so that wasn't an argument. >> Python 3.0 didn't just say "to Hades with backward compatibility". The >> breakage was only in places where it was deemed worthwhile. Changing >> the meaning of {} would have only small benefit and would potentially >> break a LOT of programs, so the devs were right to not do it. > > More programs than those who broke because print was now a function? It is quite possible that the print change broke more than the dict change would have. The difference is that the print statement syntax was both awful and limited. The print function uses standard syntax and is more flexible. The fact that print could be turned into a function shows that it did not need to be a statement. All other simple statements except 'pass' either implicitly quote an expression in the statement, jump control, or declare something to the compiler. The other fact that Chris noted, that '{}' would have been valid but with different meanings in Py1/2 versus Py3, was a factor on the cost side. We generally try to avoid such ambiguities. Except for this last point, I was in favor of the switch. -- Terry Jan Reedy From roy at panix.com Tue Mar 25 20:58:27 2014 From: roy at panix.com (Roy Smith) Date: Tue, 25 Mar 2014 20:58:27 -0400 Subject: YADTR (Yet Another DateTime Rant) Message-ID: One of my roles on this newsgroup is to periodically whine about stupidities in the Python datetime module. This is one of those times. I have some code which computes how long ago the sun set. Being a nice pythonista, I'm using a timedelta to represent this value. It would be difficult to imagine a less useful default way to print a timedelta: previous sunset: -1 day, 22:25:26.295993 The idea of str() is that it's supposed to return a human-friendly representation of a value. Humans do not say things like, "The sun set 1 day ago plus 22 hours and 25 minutes". From steve+comp.lang.python at pearwood.info Tue Mar 25 21:01:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2014 01:01:01 GMT Subject: Time we switched to unicode? References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <87ior2zosv.fsf@elektro.pacujo.net> Message-ID: <533226cd$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 25 Mar 2014 18:24:10 +0100, Chris ?Kwpolska? Warrick wrote: > Oh: and speaking of fancy Unicode characters that are worthless > ~duplicates, spot the difference here: > > ? ? I take exception to your description of them as *worthless* duplicates. "Unfortunate" would be a better choice of word. Unicode has (at least) two aims: - to include every "character" used in human language (please, no arguments about what defines a character); and - to losslessly represent every character available in the dozens of legacy code pages and character sets. It's that second requirement -- specifically the "lossless" part -- that leads to such annoyances as ? and ?. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ethan at stoneleaf.us Tue Mar 25 21:19:30 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 25 Mar 2014 18:19:30 -0700 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: Message-ID: <53322B22.6040100@stoneleaf.us> On 03/25/2014 05:58 PM, Roy Smith wrote: > One of my roles on this newsgroup is to periodically whine about > stupidities in the Python datetime module. This is one of those times. > > I have some code which computes how long ago the sun set. Being a nice > pythonista, I'm using a timedelta to represent this value. It would be > difficult to imagine a less useful default way to print a timedelta: > > previous sunset: -1 day, 22:25:26.295993 > > The idea of str() is that it's supposed to return a human-friendly > representation of a value. Humans do not say things like, "The sun set > 1 day ago plus 22 hours and 25 minutes". I'm not sure whether to admire you for your stick-to-it-iveness, or pity you for the plight you are in. Either the first or second time I hit a datetime WTF moment I wrote my own wrapper classes. -- ~Ethan~ From tjreedy at udel.edu Tue Mar 25 22:10:23 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Mar 2014 22:10:23 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/25/2014 9:36 AM, Steven D'Aprano wrote: > Yes, Python could have changed the meaning of {} to mean the empty set. > But you know what? The empty set is not that important. Sets are not > fundamental to Python. Python didn't even have sets until 2.3, and at > first they were just a standard library module, not even built-in. Leaving aside the fact that dicts are, conceptually, specialized sets of ordered pairs in which first members are both unique to equality and, in Python, hashable, this is all true. > Dicts, on the other hand, are fundamental to Python. > They are used everywhere. I would rather say that functions/mappings are fundamental to Python, and in programming in general. Dicts are functions implemented as sets. Lists and tuples are functions implemented as tables (ordered sets). Callables are functions implemented as rules. The fact that functions as sets (dicts) are both extremely useful and not built-in to most languages, makes their presence in Python a major differentiating feature. > Python is, in a very real sense, built on dicts, not sets. It is build on functions, but dicts are a differentiating features. The 'problem' with sets as sets is that they are purely featureless data structures. > You can implement sets starting from dicts, > but not the other way around: You should be more careful about claiming impossibility;-). Sets can be easily implemented from dicts because dicts are sets with an extra feature (the value associated with each key) that is easily ignored (or always set to the key or None). To implement a dict class starting with sets would be difficult because CPython sets and dicts are implemented in C and one cannot reach into their C internals from Python, or even (mostly) with the C API. One would have to implement or even simulate the C structures and code in Python and the result would be much slower. > dicts are more fundamental than sets. One can easily implement floats from complex numbers by making the .imag part always 0. It would be much harder to implement complex numbers from floats, for the same reasons that it would be hard to implements dicts from sets. But it must be possible. Would you say that complex numbers are, because of this implementation quirk, more fundamental than floats? > I'm sure it is awfully impressive that mathematicians can derive the laws > of integer maths starting only from the empty set ?, but as far as > programming goes that's not a very useful thing. I agree. Deriving counts and integers from 0 and an increment function is much more apropos to how we use then to describe and drive algorithms and prove things about them. -- Terry Jan Reedy From tjreedy at udel.edu Tue Mar 25 22:19:30 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Mar 2014 22:19:30 -0400 Subject: Have you ever wondered why there are so many flavors of python. This post answers all your queries. In-Reply-To: <9921c06f-c165-4e0a-8550-531aa5c01c01@googlegroups.com> References: <9921c06f-c165-4e0a-8550-531aa5c01c01@googlegroups.com> Message-ID: On 3/25/2014 6:52 AM, Amit Khomane wrote: > http://www.techdarting.com/2014/03/why-different-flavors-of-python.html This is about implementations: CPython, Jython, etc. I am not sure it actually answers Why? -- Terry Jan Reedy From rustompmody at gmail.com Tue Mar 25 22:16:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 19:16:25 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: <8c6c7b14-7f7a-4b71-987c-487e51becfed@googlegroups.com> References: <8c6c7b14-7f7a-4b71-987c-487e51becfed@googlegroups.com> Message-ID: <5b4b3af0-d9cb-4062-86c0-78fa6426d6cf@googlegroups.com> On Wednesday, March 26, 2014 12:22:40 AM UTC+5:30, wxjm... at gmail.com wrote: > Le mardi 25 mars 2014 19:30:34 UTC+1, Mark H. Harris a ?crit?: > > greetings, I would like to create a lamda as follows: > > ? = lambda n: sqrt(n) > > On my keyboard mapping the "problem" character is alt-v which produces > > the radical symbol. When trying to set the symbol as a name within the > > name-space gives a syntax error: > > >>> from math import sqrt > > >>> ? = lambda n: sqrt(n) > > SyntaxError: invalid character in identifier > > however this works: > > >>> ? = lambda n: sqrt(n) > > >>> ?(2) > > 1.4142135623730951 > > The question is which unicode(s) are capable of being proper name > > characters, and which ones are off-limits, and why? > > marcus > >>> '?'.isidentifier() > False > >>> '?'.isidentifier() > True > >>> '$'.isidentifier() > False > >>> '?'.isidentifier() > True > >>> 'a'.isidentifier() > True > >>> '?2z'.isidentifier() > True > >>> print(''.isidentifier.__doc__) > S.isidentifier() -> bool > Return True if S is a valid identifier according > to the language definition. Thanks jmf! You obviously have more unicode knowledge than many (most?) of us here. And when you contribute that knowledge in short-n-sweet form as above it is helpful to all. > cf "unicode.org" doc Ummm... Less helpful here. What/where do you expect someone to start reading? If a python beginner asks some basic question and someone here were to say "Go read up on http://python.org" who is helped? From tjreedy at udel.edu Tue Mar 25 22:26:57 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Mar 2014 22:26:57 -0400 Subject: unicode as valid naming symbols In-Reply-To: References: Message-ID: On 3/25/2014 2:30 PM, Mark H Harris wrote: > greetings, I would like to create a lamda as follows: A lambda is a function lacking a proper name. > ? = lambda n: sqrt(n) This is discouraged in PEP8. If the following worked, def ?(n): return sqrt(n) would have ? as its __name__ attribute -- Terry Jan Reedy From rosuav at gmail.com Tue Mar 25 22:39:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 13:39:01 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 26, 2014 at 1:10 PM, Terry Reedy wrote: >> dicts are more fundamental than sets. > > One can easily implement floats from complex numbers by making the .imag > part always 0. It would be much harder to implement complex numbers from > floats, for the same reasons that it would be hard to implements dicts from > sets. But it must be possible. Would you say that complex numbers are, > because of this implementation quirk, more fundamental than floats? I would say that this proves that dicts and complexes are more general, rather than more fundamental. The fundamentals of boolean logic are AND/OR/NOT, but it's common to build everything out of the more general NAND gates because they can do everything. (I may be sketchy on details there, I'm a software guy not a hardware designer.) ChrisA From python at mrabarnett.plus.com Tue Mar 25 22:56:00 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 26 Mar 2014 02:56:00 +0000 Subject: unicode as valid naming symbols In-Reply-To: <53320793.8070501@stoneleaf.us> References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> Message-ID: <533241C0.8020109@mrabarnett.plus.com> On 2014-03-25 22:47, Ethan Furman wrote: > On 03/25/2014 12:29 PM, Mark H Harris wrote: >> On 3/25/14 2:24 PM, MRAB wrote: >>> It's explained in PEP 3131. >>> >>> Basically, a name should to start with a letter (this has been extended >>> to include Chinese characters, etc) or an underscore. >>> >>> ? is a classified as Lowercase_Letter. >>> >>> ? is classified as Math_Symbol. >> >> Thanks much! I'll note that for improvements. Any unicode symbol (that is not a number) should be allowed as an >> identifier. > > No, it shouldn't. Doing so would mean we could not use ? as the square root operator in the future. > Or as a root operator, e.g. 3 ? x (the cube root of x). > Identifiers are made up of letters, numbers, and the underscore. Considering all the unicode letters and unicode > numbers out there, you shouldn't be lacking for names. > From rosuav at gmail.com Tue Mar 25 23:09:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 14:09:43 +1100 Subject: unicode as valid naming symbols In-Reply-To: <533241C0.8020109@mrabarnett.plus.com> References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> Message-ID: On Wed, Mar 26, 2014 at 1:56 PM, MRAB wrote: >> No, it shouldn't. Doing so would mean we could not use ? as the square >> root operator in the future. >> > Or as a root operator, e.g. 3 ? x (the cube root of x). Or both! It could be like unary negation and binary subtraction. ChrisA From tjreedy at udel.edu Wed Mar 26 00:30:21 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Mar 2014 00:30:21 -0400 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/25/2014 8:12 PM, Steven D'Aprano wrote: > On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote: > >> On 3/25/2014 11:18 AM, Steven D'Aprano wrote: >> >>> The thing is, we can't just create a ? function, because it doesn't >>> work the way the summation operator works. The problem is that we would >>> want syntactic support, so we could write something like this: >>> >>> p = 2 >>> ?(n, 1, 10, n**p) >> >> Of course we can. If we do not insist on separating the dummy name from >> the expression that contains it. this works. >> >> def sigma(low, high, func): >> sum = 0 >> for i in range(low, high+1): >> sum += func(i) >> return sum > > There is no expression there. There is a function. > > You cannot pass an expression to a function in Python, One passes an unquoted expression in code by quoting it with either lambda, paired quote marks (Lisp used a single '), or using it in a form that implicitly quotes it (that includes def statements). Unquoted expressions in statements ultimately get passed to an internal functions. > not in the sense I am talking about, well, if you eliminate all the possibilities ... > because expressions are not first-class objects. The concept is not a class, and the Python stdlib does not have an expression class. But people have written classes to represent the concept. I used existing classes instead. Expressions are not (normally) mathematical objects either. (An exception is rewriting theory, or other theories, where strings representing expressions or WFFs (well-formed formulas) are the only objects.) Mathematicians quote expression strings by context or positiion. The sigma form is one of many examples. -- Terry Jan Reedy From rustompmody at gmail.com Wed Mar 26 00:56:55 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 25 Mar 2014 21:56:55 -0700 (PDT) Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7ef4355d-ef12-4931-847e-95ad8358bdc7@googlegroups.com> On Wednesday, March 26, 2014 10:00:21 AM UTC+5:30, Terry Reedy wrote: > On 3/25/2014 8:12 PM, Steven D'Aprano wrote: > > On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote: > >> On 3/25/2014 11:18 AM, Steven D'Aprano wrote: > >>> The thing is, we can't just create a ? function, because it doesn't > >>> work the way the summation operator works. The problem is that we would > >>> want syntactic support, so we could write something like this: > >>> p = 2 > >>> ?(n, 1, 10, n**p) > >> Of course we can. If we do not insist on separating the dummy name from > >> the expression that contains it. this works. > >> def sigma(low, high, func): > >> sum = 0 > >> for i in range(low, high+1): > >> sum += func(i) > >> return sum > > There is no expression there. There is a function. > > You cannot pass an expression to a function in Python, > One passes an unquoted expression in code by quoting it with either > lambda, paired quote marks (Lisp used a single '), or using it in a form > that implicitly quotes it (that includes def statements). Unquoted > expressions in statements ultimately get passed to an internal functions. I wrote about the two styles of quoting here: (Yeah its under the scheme banner) http://blog.languager.org/2013/08/applying-si-on-sicp.html There was also a neat little tech report by David Gries from Cornell explaining that ? ? ? ? are all 'binding-constructs' in their own sphere's [No access to that any more though :-( ] From patil.jay2009 at gmail.com Wed Mar 26 01:04:26 2014 From: patil.jay2009 at gmail.com (Jaydeep Patil) Date: Tue, 25 Mar 2014 22:04:26 -0700 (PDT) Subject: Hold wxframe (GUI) Message-ID: <57d2dd3d-af3b-4678-ac11-ae911bfeda60@googlegroups.com> I constructed Two frames. One frame consist of GUI which consist of one Ok button. Afer click on OK button another GUI calls. But after Second gui calling, It wont stop further procesees. I need to stop futher proceeses. How can i hold second gui? Please reply Sample Code is: import wx class App(wx.App): ''' classdocs ''' def __init__(self,name=None): ''' Constructor ''' wx.App.__init__(self) self.d = Dashboard() self.d.Show() def _startMainLoop(self): self.MainLoop() pass def start(self): #self.d.Show() self._startMainLoop() pass class Dashboard(wx.Frame): ''' classdocs ''' def __init__(self,name=None): ''' Constructor ''' wx.Frame.__init__(self,None,wx.ID_ANY) print("Frame 1") self.btnOk = wx.Button(self,-1,"OK") self.btnOk.Bind(wx.EVT_BUTTON,self.test) def test(self,event): print("Before") self.f = Dashboard1(self) ## I need to Stop here only self.f.Show() self.f.MakeModal(True) print("AFter") class Dashboard1(wx.Frame): ''' classdocs ''' def __init__(self,parent): ''' Constructor ''' wx.Frame.__init__(self,parent,wx.ID_ANY) a = App() a.start() Output is : Frame 1 Before After From patil.jay2009 at gmail.com Wed Mar 26 02:03:55 2014 From: patil.jay2009 at gmail.com (Jaydeep Patil) Date: Tue, 25 Mar 2014 23:03:55 -0700 (PDT) Subject: Hold wxframe (GUI) In-Reply-To: <57d2dd3d-af3b-4678-ac11-ae911bfeda60@googlegroups.com> References: <57d2dd3d-af3b-4678-ac11-ae911bfeda60@googlegroups.com> Message-ID: On Wednesday, 26 March 2014 10:34:26 UTC+5:30, Jaydeep Patil wrote: > I constructed Two frames. > > One frame consist of GUI which consist of one Ok button. > > > > Afer click on OK button another GUI calls. But after Second gui calling, It wont stop further procesees. I need to stop futher proceeses. How can i hold second gui? > > > > > > Please reply > > > > > > > > Sample Code is: > > > > import wx > > class App(wx.App): > > ''' > > classdocs > > ''' > > def __init__(self,name=None): > > ''' > > Constructor > > ''' > > wx.App.__init__(self) > > self.d = Dashboard() > > self.d.Show() > > > > def _startMainLoop(self): > > self.MainLoop() > > pass > > > > def start(self): > > #self.d.Show() > > self._startMainLoop() > > pass > > > > > > class Dashboard(wx.Frame): > > ''' > > classdocs > > ''' > > def __init__(self,name=None): > > ''' > > Constructor > > ''' > > wx.Frame.__init__(self,None,wx.ID_ANY) > > print("Frame 1") > > > > self.btnOk = wx.Button(self,-1,"OK") > > > > self.btnOk.Bind(wx.EVT_BUTTON,self.test) > > > > def test(self,event): > > print("Before") > > self.f = Dashboard1(self) ## I need to Stop here only > > self.f.Show() > > self.f.MakeModal(True) > > print("AFter") > > > > > > > > class Dashboard1(wx.Frame): > > ''' > > classdocs > > ''' > > def __init__(self,parent): > > ''' > > Constructor > > ''' > > wx.Frame.__init__(self,parent,wx.ID_ANY) > > > > a = App() > > a.start() > > > > > > Output is : > > Frame 1 > > Before > > After Hi all, I need to hold the other execution part after next GUI calls? How can do that? Anybody can help me? Regards Jaydeep Patil From wuwei23 at gmail.com Wed Mar 26 02:35:51 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 26 Mar 2014 16:35:51 +1000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 25/03/2014 12:39 PM, Mark H Harris wrote: > my version semantically is "how it is perceived" by the user Could you please stop claiming to have insight into the comprehension of anyone other than yourself? Hasty generalisations don't help your argument. From dieter at handshake.de Wed Mar 26 03:10:23 2014 From: dieter at handshake.de (dieter) Date: Wed, 26 Mar 2014 08:10:23 +0100 Subject: gdb python how to output integer for examine memory References: <2aa794ce-7cc1-4d24-a30b-3fb17b89e33f@googlegroups.com> Message-ID: <87fvm5v3j4.fsf@handshake.de> Wesley writes: > ... > Actually, I can now see the varialbe names at Python level and C level. > I just want to verify x command to monitor the memory content. > So, in my origin post, I can get variable i's address, and see the value is 1, > then, I wanna have a try x command, the issue is, when use x/format i's address, the output is not 1, but other things:-( All Python objects start (at C level) with a header (containing the reference count, a pointer to the associated type and maybe other things); the "real" value starts behind this header. This means, to see the "1" in your example, you must skip the associated object header -- either in the output or by adding the size of the header to the initial address. From patil.jay2009 at gmail.com Wed Mar 26 04:10:09 2014 From: patil.jay2009 at gmail.com (Jaydeep Patil) Date: Wed, 26 Mar 2014 01:10:09 -0700 (PDT) Subject: Can we hold execution python programming till GUI event close on? Message-ID: <0a91887c-8d23-4dce-a4dc-65793489559a@googlegroups.com> Hi... I have one wxframe. after click on that frame another frame opens and rest part is executed. I need ti stop the next execution after secong gui calls up. please suggest. From antoon.pardon at rece.vub.ac.be Wed Mar 26 04:25:43 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 26 Mar 2014 09:25:43 +0100 Subject: unicode as valid naming symbols In-Reply-To: <53320793.8070501@stoneleaf.us> References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> Message-ID: <53328F07.20302@rece.vub.ac.be> On 25-03-14 23:47, Ethan Furman wrote: > On 03/25/2014 12:29 PM, Mark H Harris wrote: >> On 3/25/14 2:24 PM, MRAB wrote: >>> It's explained in PEP 3131. >>> >>> Basically, a name should to start with a letter (this has been extended >>> to include Chinese characters, etc) or an underscore. >>> >>> ? is a classified as Lowercase_Letter. >>> >>> ? is classified as Math_Symbol. >> >> Thanks much! I'll note that for improvements. Any unicode symbol >> (that is not a number) should be allowed as an >> identifier. > > No, it shouldn't. Doing so would mean we could not use ? as the > square root operator in the future. And what advantage would that bring over just using it as a function? -- Antoon Pardon From jeandubois314 at gmail.com Wed Mar 26 04:47:25 2014 From: jeandubois314 at gmail.com (Jean Dubois) Date: Wed, 26 Mar 2014 01:47:25 -0700 (PDT) Subject: [newbie] confusion concerning fetching an element in a 2d-array In-Reply-To: References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> <0cf3d503-8cd6-4702-9260-b0ef3f4cf561@googlegroups.com> Message-ID: Op dinsdag 25 maart 2014 20:58:10 UTC+1 schreef Dave Angel: > Jean Dubois Wrote in message: > > Op dinsdag 25 maart 2014 15:42:13 UTC+1 schreef Dave Angel: > > >> If your instructor wanted you to copy examples, he would have > >> given you one. > > please Dave leave that belittling tone behind, there's no instructor > > whatsoever involved here. > > It wasn't my intention to belittle you; I'm sorry. But we do get a > lot of people here asking for homework help, and not saying > that's what it is. And when it's homework we do better explaining > than just writing the code. > > In fact you only needed to add a line like > data= infile.read () > to Steven's original to get a complete working example. > > > I constructed this example myself as I know very > > well I have to start with little pieces of code first to be able to master > > larger problems later. I just wanted to figure this example out first, > > and as I now learned from Peter's marvellous explanation there _is_ an > > elegant solution in Python to this kind of problem. > > So if you are irritated by newbie-questions in the future, just neglect > > them > > Not irritated, just temporarily misguided. OK, no hard feelings kind regards, jean From jeandubois314 at gmail.com Wed Mar 26 04:48:32 2014 From: jeandubois314 at gmail.com (Jean Dubois) Date: Wed, 26 Mar 2014 01:48:32 -0700 (PDT) Subject: [newbie] confusion concerning fetching an element in a 2d-array In-Reply-To: References: <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> <0cf3d503-8cd6-4702-9260-b0ef3f4cf561@googlegroups.com> Message-ID: <75d2eaac-d014-40bb-8027-918d79398e6c@googlegroups.com> Op dinsdag 25 maart 2014 20:15:27 UTC+1 schreef Joel Goldstick: > Jean, be aware there is also python tutor list you might like.? This is sometimes a tough crowd here. Don't be discouraged. It can be a badge of honor sometimes thanks for the suggestions, I already subscribed to the python tutor list kind regards, jean From antoon.pardon at rece.vub.ac.be Wed Mar 26 04:52:25 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 26 Mar 2014 09:52:25 +0100 Subject: unicode as valid naming symbols In-Reply-To: <533241C0.8020109@mrabarnett.plus.com> References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> Message-ID: <53329549.1000208@rece.vub.ac.be> On 26-03-14 03:56, MRAB wrote: > On 2014-03-25 22:47, Ethan Furman wrote: >> On 03/25/2014 12:29 PM, Mark H Harris wrote: >>> On 3/25/14 2:24 PM, MRAB wrote: >>>> It's explained in PEP 3131. >>>> >>>> Basically, a name should to start with a letter (this has been >>>> extended >>>> to include Chinese characters, etc) or an underscore. >>>> >>>> ? is a classified as Lowercase_Letter. >>>> >>>> ? is classified as Math_Symbol. >>> >>> Thanks much! I'll note that for improvements. Any unicode >>> symbol (that is not a number) should be allowed as an >>> identifier. >> >> No, it shouldn't. Doing so would mean we could not use ? as the >> square root operator in the future. >> > Or as a root operator, e.g. 3 ? x (the cube root of x). > Personally I would think such an operator is too limited to include in a programming language. This kind of notation is only used with a constant to indicate what kind of root is taken and only with positive integers. Something like the equivallent of the following I have never seen. t = 2.5 x = 8.2 y = t ? x Of course we don't have to follow mathematical convention with python. However allowing any unicode symbol as an identifier doesn't prohibit from using ? as an operator. We do have "in" and "is" as operators now, even if they would otherwise be acceptable identifiers. So I wonder, would you consider to introduce log as an operator. 2 log x seems an interesting operation for a programmer. -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Wed Mar 26 05:22:22 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 26 Mar 2014 10:22:22 +0100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <5331595D.5020008@rece.vub.ac.be> <53317191.7050701@rece.vub.ac.be> Message-ID: <53329C4E.20107@rece.vub.ac.be> On 26-03-14 01:24, Terry Reedy wrote: > The other fact that Chris noted, that '{}' would have been valid but > with different meanings in Py1/2 versus Py3, was a factor on the cost > side. We generally try to avoid such ambiguities. > > Except for this last point, I was in favor of the switch. In my estimation the cost would have been bearable. But I understand this kind of things is always a judgement call and different people can legitimately come to different conclusions. -- Antoon Pardon From breamoreboy at yahoo.co.uk Wed Mar 26 05:27:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Mar 2014 09:27:51 +0000 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <53322B22.6040100@stoneleaf.us> References: <53322B22.6040100@stoneleaf.us> Message-ID: On 26/03/2014 01:19, Ethan Furman wrote: > On 03/25/2014 05:58 PM, Roy Smith wrote: >> One of my roles on this newsgroup is to periodically whine about >> stupidities in the Python datetime module. This is one of those times. >> >> I have some code which computes how long ago the sun set. Being a nice >> pythonista, I'm using a timedelta to represent this value. It would be >> difficult to imagine a less useful default way to print a timedelta: >> >> previous sunset: -1 day, 22:25:26.295993 >> >> The idea of str() is that it's supposed to return a human-friendly >> representation of a value. Humans do not say things like, "The sun set >> 1 day ago plus 22 hours and 25 minutes". > > I'm not sure whether to admire you for your stick-to-it-iveness, or pity > you for the plight you are in. Either the first or second time I hit a > datetime WTF moment I wrote my own wrapper classes. > dateutils for me. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Wed Mar 26 05:43:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 26 Mar 2014 09:43:06 +0000 Subject: Hold wxframe (GUI) In-Reply-To: References: <57d2dd3d-af3b-4678-ac11-ae911bfeda60@googlegroups.com> Message-ID: On 26/03/2014 06:03, Jaydeep Patil wrote: > > Hi all, > > I need to hold the other execution part after next GUI calls? > > How can do that? > > Anybody can help me? > I suggest you try a specific mailing list for wxpython, it's available at gmane.comp.python.wxpython amongst other places. Also would you please use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From landa.martin at gmail.com Wed Mar 26 05:40:13 2014 From: landa.martin at gmail.com (Martin Landa) Date: Wed, 26 Mar 2014 02:40:13 -0700 (PDT) Subject: calling Python script from another Python script (Windows, multiple installation problem) Message-ID: <4b100198-73d0-4562-89cf-8af9b9b87174@googlegroups.com> Hi all, I am trying to fix a bug in the project which I am working for. The program starts on Windows via bat file which calls a Python script to set up the environment including GUI and allow to launch program-specific tools. Some of the tools are written in C, some in Python. These commands are run via subprocess.Popen class. The Windows installer comes with its own bundled Python which is usually different from possible system-wide Python. This is source of the problems, Python scripts run via subprocess.Popen are launched via system-wide Python version, not desired bundled Python. Except hacks like `Popen(sys.executable, ...)` I am looking for a better solution. I checked virtualenv [1] or Pylauncher [2] but without success, speaking about Python2 not Python3 which comes from version 3.3 with intergrated pylauncher... Thanks in advance for any ideas, suggestions or pointers! Martin [1] http://www.virtualenv.org/en/latest/ [2] https://bitbucket.org/vinay.sajip/pylauncher From piotrhusiatynski at gmail.com Wed Mar 26 07:35:31 2014 From: piotrhusiatynski at gmail.com (=?UTF-8?Q?Piotr_Husiaty=C5=84ski?=) Date: Wed, 26 Mar 2014 12:35:31 +0100 Subject: Fwd: Basic asyncio usage In-Reply-To: References: Message-ID: Hi, I have posted the same question to python-tutor list *, but I'm trying my luck here as advised. I'm trying to get more familiar with asyncio library. Using python 3.4, I wrote simple echo server (see attachement for the code). I know that instead of using bare bone send/recv I could use some of the helper functions, but I want to start with the basics. Using attached code, I can connect from multiple sources, but echo won't work for all clients. Also, please look at the `sendall` mehtod - I have to manually remove write callback, otherwise it will be called all the time. Any tips on solving this problem? * https://mail.python.org/pipermail/tutor/2014-March/100679.html -------------- next part -------------- A non-text attachment was scrubbed... Name: asynciotest.py Type: text/x-python Size: 2065 bytes Desc: not available URL: From vlastimil.brom at gmail.com Wed Mar 26 07:40:47 2014 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 26 Mar 2014 12:40:47 +0100 Subject: calling Python script from another Python script (Windows, multiple installation problem) In-Reply-To: <4b100198-73d0-4562-89cf-8af9b9b87174@googlegroups.com> References: <4b100198-73d0-4562-89cf-8af9b9b87174@googlegroups.com> Message-ID: 2014-03-26 10:40 GMT+01:00 Martin Landa : > Hi all, > > I am trying to fix a bug in the project which I am working for. The program starts on Windows via bat file which calls a Python script to set up the environment including GUI and allow to launch program-specific tools. Some of the tools are written in C, some in Python. These commands are run via subprocess.Popen class. The Windows installer comes with its own bundled Python which is usually different from possible system-wide Python. This is source of the problems, Python scripts run via subprocess.Popen are launched via system-wide Python version, not desired bundled Python. Except hacks like `Popen(sys.executable, ...)` I am looking for a better solution. I checked virtualenv [1] or Pylauncher [2] but without success, speaking about Python2 not Python3 which comes from version 3.3 with intergrated pylauncher... > > Thanks in advance for any ideas, suggestions or pointers! Martin > > [1] http://www.virtualenv.org/en/latest/ > [2] https://bitbucket.org/vinay.sajip/pylauncher > -- > https://mail.python.org/mailman/listinfo/python-list Hi, I'm probably missing some requirement of your use case, but I guess, it should be possible to specify the path of the desired python interpreter along with the executed script as an argument to Popen(...). This should make the selection of the used python explicit. Or are there any other disadvantages of the current approach, which you are solving in parallel? hth, vbr From bmcollier at gmail.com Wed Mar 26 07:43:49 2014 From: bmcollier at gmail.com (Ben Collier) Date: Wed, 26 Mar 2014 04:43:49 -0700 (PDT) Subject: Dynamically reference member of array Message-ID: Hi all, I know that I can dynamically reference a variable with locals()["i"], for instance, but I'd like to know how to do this with a variable in an object. If I have an object called "device", with variables called attr1, attr2 .. attr50, how could I dynamically reference these? It's fairly academic, but I'd like to avoid code duplication. Thanks, Ben From bmcollier at gmail.com Wed Mar 26 07:44:41 2014 From: bmcollier at gmail.com (Ben Collier) Date: Wed, 26 Mar 2014 04:44:41 -0700 (PDT) Subject: Dynamically reference variable in object In-Reply-To: References: Message-ID: Sorry, subject was wrong. Please see below: On Wednesday, 26 March 2014 11:43:49 UTC, Ben Collier wrote: > Hi all, > > > > I know that I can dynamically reference a variable with locals()["i"], for instance, but I'd like to know how to do this with a variable in an object. > > > > If I have an object called "device", with variables called attr1, attr2 .. attr50, how could I dynamically reference these? > > > > It's fairly academic, but I'd like to avoid code duplication. > > > > Thanks, > > > > Ben From bmcollier at gmail.com Wed Mar 26 07:49:56 2014 From: bmcollier at gmail.com (Ben Collier) Date: Wed, 26 Mar 2014 04:49:56 -0700 (PDT) Subject: FIXED: Dynamically reference variables in object Message-ID: Hi all, I know that I can dynamically reference a variable with locals()["i"], for instance, but I'd like to know how to do this with a variable in an object. If I have an object called "device", with variables called attr1, attr2 .. attr50, how could I dynamically reference these? It's fairly academic, but I'd like to avoid code duplication. Thanks, Ben From antoon.pardon at rece.vub.ac.be Wed Mar 26 07:59:30 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 26 Mar 2014 12:59:30 +0100 Subject: FIXED: Dynamically reference variables in object In-Reply-To: References: Message-ID: <5332C122.9050902@rece.vub.ac.be> On 26-03-14 12:49, Ben Collier wrote: > Hi all, > > I know that I can dynamically reference a variable with locals()["i"], for instance, but I'd like to know how to do this with a variable in an object. > > If I have an object called "device", with variables called attr1, attr2 .. attr50, how could I dynamically reference these? > > It's fairly academic, but I'd like to avoid code duplication. > > Thanks, > > Ben It looks like you are asking for getattr. getattr(device, "attr1"). However unless you have specific reasons to use atrributes (what you seem to call variables here), it seems you are better of using a dictionary. So you could then use: device["attr1"]. -- Antoon Pardon From rosuav at gmail.com Wed Mar 26 08:04:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 23:04:00 +1100 Subject: FIXED: Dynamically reference variables in object In-Reply-To: References: Message-ID: On Wed, Mar 26, 2014 at 10:49 PM, Ben Collier wrote: > I know that I can dynamically reference a variable with locals()["i"], for instance, but I'd like to know how to do this with a variable in an object. > > If I have an object called "device", with variables called attr1, attr2 .. attr50, how could I dynamically reference these? > > It's fairly academic, but I'd like to avoid code duplication. > Check out the getattr function: http://docs.python.org/3.5/library/functions.html#getattr But if you're doing that sort of thing, you may want to consider using a dictionary instead. :) ChrisA From landa.martin at gmail.com Wed Mar 26 08:29:47 2014 From: landa.martin at gmail.com (Martin Landa) Date: Wed, 26 Mar 2014 05:29:47 -0700 (PDT) Subject: calling Python script from another Python script (Windows, multiple installation problem) In-Reply-To: References: <4b100198-73d0-4562-89cf-8af9b9b87174@googlegroups.com> Message-ID: Hi, > it should be possible to specify the path of the desired python > > interpreter along with the executed script as an argument to > > Popen(...). This should make the selection of the used python > > explicit. > > Or are there any other disadvantages of the current approach, which > > you are solving in parallel? not really, I am just searching for a better solution based on virtualenv or something similar... Thanks, Martin From landa.martin at gmail.com Wed Mar 26 08:49:33 2014 From: landa.martin at gmail.com (Martin Landa) Date: Wed, 26 Mar 2014 05:49:33 -0700 (PDT) Subject: calling Python script from another Python script (Windows, multiple installation problem) In-Reply-To: References: <4b100198-73d0-4562-89cf-8af9b9b87174@googlegroups.com> Message-ID: <6ba81449-5f4c-46be-ad4a-64ea8bc5b436@googlegroups.com> Dne st?eda, 26. b?ezna 2014 13:29:47 UTC+1 Martin Landa napsal(a): > not really, I am just searching for a better solution based on virtualenv or something similar... particularly I am using something like if sys.platform == "win32": # get full path including file extension for scripts fcmd = get_real_command(args[0]) if fcmd.endswith('.py'): args[0] = fcmd args.insert(0, sys.executable) where 'args' in subprocess.Popen's argument. I just wonder if there is a better or preferable solution over this kind of a hack. Martin From rosuav at gmail.com Wed Mar 26 08:54:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 26 Mar 2014 23:54:02 +1100 Subject: calling Python script from another Python script (Windows, multiple installation problem) In-Reply-To: <6ba81449-5f4c-46be-ad4a-64ea8bc5b436@googlegroups.com> References: <4b100198-73d0-4562-89cf-8af9b9b87174@googlegroups.com> <6ba81449-5f4c-46be-ad4a-64ea8bc5b436@googlegroups.com> Message-ID: On Wed, Mar 26, 2014 at 11:49 PM, Martin Landa wrote: > # get full path including file extension for scripts > fcmd = get_real_command(args[0]) What's that function do? ChrisA From landa.martin at gmail.com Wed Mar 26 09:11:15 2014 From: landa.martin at gmail.com (Martin Landa) Date: Wed, 26 Mar 2014 06:11:15 -0700 (PDT) Subject: calling Python script from another Python script (Windows, multiple installation problem) In-Reply-To: References: <4b100198-73d0-4562-89cf-8af9b9b87174@googlegroups.com> <6ba81449-5f4c-46be-ad4a-64ea8bc5b436@googlegroups.com> Message-ID: <5e22e138-be3b-4b91-8807-0025d5d77b92@googlegroups.com> Dne st?eda, 26. b?ezna 2014 13:54:02 UTC+1 Chris Angelico napsal(a): > On Wed, Mar 26, 2014 at 11:49 PM, Martin Landa wrote: > > > # get full path including file extension for scripts > > > fcmd = get_real_command(args[0]) this function returns a full path including file extension for scripts. If 'args[0]' is a binary file in the path, it returns 'args[0]'. If 'args[0]' is detected as a script (it finds in the search path file with such name and given extension, eg. `py`) it returns full path to the file, /path/to/file/args[0].py. From skip at pobox.com Wed Mar 26 09:37:06 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 26 Mar 2014 08:37:06 -0500 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: Message-ID: It's not clear to me what the correct str should be. I think the desired format changes depending on the relative magnitude of the timedelta object. For small values (less than a day), I agree, the behavior is, well, odd. You can get around that easily enough: >>> d = datetime.timedelta(seconds=-2) >>> str(d) '-1 day, 23:59:58' >>> "-%s" % -d '-0:00:02' The problem gets more challenging once you get into magnitudes > one day: >>> e = datetime.timedelta(days=-4, seconds=3605) >>> e datetime.timedelta(-4, 3605) >>> print e -4 days, 1:00:05 Hmmm... It's printing just what we said, negative four days, positive one hour, five minutes. Let's try the trick from above: >>> print -e 3 days, 22:59:55 >>> "-%s" % -e '-3 days, 22:59:55' Ehhh... not so much. The fundamental problem here is the scope of the minus sign. My trick assumes it applied to the entire string representation. It's clear that in the first case that it applies to the entire displayed value, as there are no spaces. In the second case, we know it only applies to the days, because it's spitting back exactly what I fed the constructor. So, that means the simple minus sign trick won't work in the third case. Complicating things are that timedelta objects are normalized internally so that the seconds field is always non-negative (explaining the weird "-1 day, 23:59:58" string representation of the first case). I'm not sure there's a one-size-fits-all solution to this problem. For offsets of less than a day, I suppose you could argue that the string representation shouldn't include the "-1 day" bit. Beyond that, I think you kind of have to live with what it gives you. Skip From d4n1h4ck at gmail.com Wed Mar 26 09:50:52 2014 From: d4n1h4ck at gmail.com (Daniel Pimentel (d4n1)) Date: Wed, 26 Mar 2014 10:50:52 -0300 Subject: [Python-Dev] [RELEASED] Python 3.4.0 In-Reply-To: References: <53269663.9050408@hastings.org> Message-ID: Good job men :D 2014-03-17 14:18 GMT-03:00 Alioune Dia : > yeah , asyncio is a great module, congrat for all jobs you are doing > --Ad | Dakar > > > 2014-03-17 18:11 GMT+01:00 Giampaolo Rodola' : > >> The what's new looks truly amazing, with pathlib and asyncio being my >> favourite additions. >> Thanks for all the hard work. >> >> >> On Mon, Mar 17, 2014 at 5:57 PM, Ryan Gonzalez wrote: >> >>> YES!!! +1 to the authors of the statistics and pathlib modules. >>> >>> >>> On Mon, Mar 17, 2014 at 1:29 AM, Larry Hastings wrote: >>> >>>> >>>> On behalf of the Python development team, I'm thrilled to announce >>>> the official release of Python 3.4. >>>> >>>> >>>> Python 3.4 includes a range of improvements of the 3.x series, including >>>> hundreds of small improvements and bug fixes. Major new features and >>>> changes in the 3.4 release series include: >>>> >>>> * PEP 428, a "pathlib" module providing object-oriented filesystem paths >>>> * PEP 435, a standardized "enum" module >>>> * PEP 436, a build enhancement that will help generate introspection >>>> information for builtins >>>> * PEP 442, improved semantics for object finalization >>>> * PEP 443, adding single-dispatch generic functions to the standard >>>> library >>>> * PEP 445, a new C API for implementing custom memory allocators >>>> * PEP 446, changing file descriptors to not be inherited by default >>>> in subprocesses >>>> * PEP 450, a new "statistics" module >>>> * PEP 451, standardizing module metadata for Python's module import >>>> system >>>> * PEP 453, a bundled installer for the *pip* package manager >>>> * PEP 454, a new "tracemalloc" module for tracing Python memory >>>> allocations >>>> * PEP 456, a new hash algorithm for Python strings and binary data >>>> * PEP 3154, a new and improved protocol for pickled objects >>>> * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O >>>> >>>> >>>> To download Python 3.4.0 visit: >>>> >>>> http://www.python.org/download/releases/3.4.0/ >>>> >>>> >>>> This is a production release. Please report any issues you notice to: >>>> >>>> http://bugs.python.org/ >>>> >>>> >>>> Enjoy! >>>> >>>> >>>> -- >>>> Larry Hastings, Release Manager >>>> larry at hastings.org >>>> (on behalf of the entire python-dev team and 3.4's contributors) >>>> _______________________________________________ >>>> Python-Dev mailing list >>>> Python-Dev at python.org >>>> https://mail.python.org/mailman/listinfo/python-dev >>>> Unsubscribe: https://mail.python.org/mailman/options/python-dev/ >>>> rymg19%40gmail.com >>>> >>> >>> >>> >>> -- >>> Ryan >>> If anybody ever asks me why I prefer C++ to C, my answer will be simple: >>> "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was >>> nul-terminated." >>> >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> >> -- >> Giampaolo - http://grodola.blogspot.com >> >> >> _______________________________________________ >> Python-Dev mailing list >> Python-Dev at python.org >> https://mail.python.org/mailman/listinfo/python-dev >> Unsubscribe: >> https://mail.python.org/mailman/options/python-dev/dia.aliounes%40gmail.com >> >> > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/d4n1h4ck%40gmail.com > > -- Msc. Daniel Pimentel (d4n1 ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoon.pardon at rece.vub.ac.be Wed Mar 26 10:02:15 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 26 Mar 2014 15:02:15 +0100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: Message-ID: <5332DDE7.2050202@rece.vub.ac.be> On 26-03-14 01:58, Roy Smith wrote: > One of my roles on this newsgroup is to periodically whine about > stupidities in the Python datetime module. This is one of those times. > > I have some code which computes how long ago the sun set. Being a nice > pythonista, I'm using a timedelta to represent this value. It would be > difficult to imagine a less useful default way to print a timedelta: > > previous sunset: -1 day, 22:25:26.295993 > > The idea of str() is that it's supposed to return a human-friendly > representation of a value. Humans do not say things like, "The sun set > 1 day ago plus 22 hours and 25 minutes". There is a difference between how people say things and what is useful. I remember when I was studying logarithms, a negative number like -5.73 was written down as ?6.27 (with a bar only over the six). That notation had the advantage that the part after the decimal point stayed the same if you added or subtracted whole numbers. Even if that would change the sign. I can't give an honest estimation of how useful this notation is because I don't use the datetime module often enough. But I can imagine that those who wrote the module and I expect used it often found it a useful representation. -- Antoon Pardon From rosuav at gmail.com Wed Mar 26 10:12:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 01:12:41 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <5332DDE7.2050202@rece.vub.ac.be> References: <5332DDE7.2050202@rece.vub.ac.be> Message-ID: On Thu, Mar 27, 2014 at 1:02 AM, Antoon Pardon wrote: > There is a difference between how people say things and what is useful. > I remember when I was studying logarithms, a negative number like -5.73 > was written down as ?6.27 (with a bar only over the six). That notation > had the advantage that the part after the decimal point stayed the same > if you added or subtracted whole numbers. Even if that would change the > sign. That's highly significant with logs, especially when you're working with base 10 logs. >>> math.log10(1234) 3.091315159697223 >>> math.log10(12340) 4.091315159697223 >>> math.log10(123400) 5.091315159697223 >>> math.log10(1234000) 6.091315159697223 >>> math.log10(12.34) 1.0913151596972228 >>> math.log10(1.234) 0.09131515969722287 >>> math.log10(.1234) -0.9086848403027772 >>> math.log10(.01234) -1.9086848403027772 By showing those last ones as 1?.091... and 2?.091..., you emphasize the floating-point nature of the data: everything after the decimal is the mantissa, and everything before the decimal is the exponent. I can't say for sure as I don't really use that, but I can imagine that there might be something similar with dates and times - it's three days ago at 2:51, not two days and 21:09 ago. Or maybe it's just "print it out in a way that more closely matches the internal representation, to simplify debugging" :) ChrisA From eneskristo at gmail.com Wed Mar 26 10:31:26 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Wed, 26 Mar 2014 07:31:26 -0700 (PDT) Subject: Errors on text.get() In-Reply-To: <7548537d-7aee-4404-98b3-8b5ce294d971@googlegroups.com> References: <7548537d-7aee-4404-98b3-8b5ce294d971@googlegroups.com> Message-ID: <7c3bb088-0b1d-4603-aa4c-3db680881a02@googlegroups.com> On Tuesday, March 25, 2014 2:15:11 PM UTC-7, enesk... at gmail.com wrote: > Exception in Tkinter callback > > Traceback (most recent call last): > > File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ > > return self.func(*args) > > File "C:/Users/User/PycharmProjects/Cesarian Codes/project.py", line 43, in gen_random > > string = text.get('1.0', 'end') > > File "C:\Python33\lib\tkinter\__init__.py", line 3104, in get > > return self.tk.call(self._w, 'get', index1, index2) > > _tkinter.TclError: invalid command name ".44500976.44544352" > > > > I'm having a strange error. I haven't found anything online so far. If I should supply parts of the code, please post here. Thank you in advance! Thank you bro! From marko at pacujo.net Wed Mar 26 10:43:04 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 26 Mar 2014 16:43:04 +0200 Subject: YADTR (Yet Another DateTime Rant) References: Message-ID: <87eh1pxbpj.fsf@elektro.pacujo.net> Antoon Pardon : > On 26-03-14 01:58, Roy Smith wrote: >> previous sunset: -1 day, 22:25:26.295993 >> >> The idea of str() is that it's supposed to return a human-friendly >> representation of a value. Humans do not say things like, "The sun set >> 1 day ago plus 22 hours and 25 minutes". > There is a difference between how people say things and what is useful. There is a standard timedelta representation: If timedelta() were created today, it really should use that one because it is the only standard one, even though few people would use that in a human interface. Thus: -P1DT22H25M26.295993S Marko From roy at panix.com Wed Mar 26 11:04:53 2014 From: roy at panix.com (Roy Smith) Date: Wed, 26 Mar 2014 08:04:53 -0700 (PDT) Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: Message-ID: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> On Wednesday, March 26, 2014 9:37:06 AM UTC-4, Skip Montanaro wrote: > The problem gets more challenging once you get into magnitudes > one > day: > > >>> e = datetime.timedelta(days=-4, seconds=3605) > >>> e > datetime.timedelta(-4, 3605) > >>> print e > -4 days, 1:00:05 > > Hmmm... It's printing just what we said, negative four days, positive > one hour, five minutes. Let's try the trick from above: No, what you said was "negative four days, positive 3605 seconds". Why does it make sense to normalize 3605 seconds to "1 hour, 5 seconds", but not extend that normalization to the days portion? > Complicating things are that timedelta objects are normalized internally so that > the seconds field is always non-negative The whole idea of datatypes is to hide the internal representation. If it's convenient on your platform, you can store timedeltas internally as fempto-years. That should not affect how it prints. From skip at pobox.com Wed Mar 26 11:39:50 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 26 Mar 2014 10:39:50 -0500 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> References: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> Message-ID: On Wed, Mar 26, 2014 at 10:04 AM, Roy Smith wrote: > No, what you said was "negative four days, positive 3605 seconds". My apologies for not showing all my work, professor. I use datetime and timedelta objects all the time. I did the arithmetic to go from 3605 to one hour, five minutes in my head. The point of my post was that there is no obvious one best way to present negative timedeltas in a human readable form. In my usage it's not generally a big deal, as most of the time I want to display datetime objects. In your case, it's obviously a problem. If Tim thought that timedelta objects would be presented to users as a regular course of doing business, maybe he would have given them a strftime() method. I suggest you write a function to format it the way you want and be done with it. You might consider taking a crack at a strftime() (and strptime?) implementation for timedelta objects that uses the ISO 8601 notation and submit it as a patch for datetimemodule.c. Note though, that the ISO8601 representation isn't without its own flaws (which might explain why Tim avoided it BITD): * It doesn't appear to provide a way to represent fractions of a second (though perhaps all the fields can be fractional) * How many days are in a month or a year? (It has format codes for both. Writing a useful strptime is probably impossible.) * It has other ambiguities ("M" represents both months and minutes - what were they thinking?) Skip From roy at panix.com Wed Mar 26 11:50:43 2014 From: roy at panix.com (Roy Smith) Date: Wed, 26 Mar 2014 11:50:43 -0400 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> Message-ID: <8AC2224E-B47B-45C5-998B-C4A3A624227E@panix.com> On Mar 26, 2014, at 11:39 AM, Skip Montanaro wrote: > The point of my post was that there is no obvious one best way to > present negative timedeltas in a human readable form. I agree that there are a number of possible representations which might make sense. But, using negative days and positive hours:minutes:seconds is just bizarre. I can't think of any possible application where that would be the desired format. --- Roy Smith roy at panix.com From marko at pacujo.net Wed Mar 26 11:58:30 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 26 Mar 2014 17:58:30 +0200 Subject: YADTR (Yet Another DateTime Rant) References: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> Message-ID: <87a9cdx87t.fsf@elektro.pacujo.net> Skip Montanaro : > Note though, that the ISO8601 representation isn't without its own > flaws (which might explain why Tim avoided it BITD): > > * It doesn't appear to provide a way to represent fractions of a > second (though perhaps all the fields can be fractional) > * How many days are in a month or a year? (It has format codes for > both. Writing a useful strptime is probably impossible.) > * It has other ambiguities ("M" represents both months and minutes - > what were they thinking?) I don't have the (nonfree) ISO 8601 at hand, but contains the practical answers -- xsd is one important use case for str(timedelta), after all. Fractions of seconds are supported -- the other fields can't be fractional. The letter "T" separates months and minutes so there's no ambiguity there. str(timedelta()), unfortunately probably can't use anything but seconds since PT1M can be 61 seconds and P1D can be 23 or 25 hours (DST). As you say, P1M really means one month and P1Y means one year. The ambiguity is intentional; if you mean to pay your employees monthly, the interval is one month. Marko From steve+comp.lang.python at pearwood.info Wed Mar 26 12:05:53 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2014 16:05:53 GMT Subject: Delayed evaluation of expressions [was Re: Time we switched to unicode?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Mar 2014 00:30:21 -0400, Terry Reedy wrote: > On 3/25/2014 8:12 PM, Steven D'Aprano wrote: >> On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote: >> >>> On 3/25/2014 11:18 AM, Steven D'Aprano wrote: >>> >>>> The thing is, we can't just create a ? function, because it doesn't >>>> work the way the summation operator works. The problem is that we >>>> would want syntactic support, so we could write something like this: >>>> >>>> p = 2 >>>> ?(n, 1, 10, n**p) >>> >>> Of course we can. If we do not insist on separating the dummy name >>> from the expression that contains it. this works. >>> >>> def sigma(low, high, func): >>> sum = 0 >>> for i in range(low, high+1): >>> sum += func(i) >>> return sum >> >> There is no expression there. There is a function. >> >> You cannot pass an expression to a function in Python, > > One passes an unquoted expression in code by quoting it with either > lambda, paired quote marks (Lisp used a single '), Passing *strings* and *functions* is not the same as having compiler support for delayed evaluation. At best its a second-class work-around. Contrast: def if_else(true_function, condition, false_function): if condition: return true_function() else: return false_function() if_else(lambda: x/0, x != 0, lambda: float("inf")) with this: x/0 if x != 0 else float("inf") Aside from the difference between the function form and operator form, the second case is much more direct and natural than the first. > or using it in a form > that implicitly quotes it (that includes def statements). Unquoted > expressions in statements ultimately get passed to an internal > functions. I think you are mistaken. Take the unquoted expression `x+1`. It doesn't get passed to anything, it gets compiled into byte code and evaluated: py> from dis import dis py> dis("x+1") 1 0 LOAD_NAME 0 (x) 3 LOAD_CONST 0 (1) 6 BINARY_ADD 7 RETURN_VALUE Perhaps you are thinking of one or two special cases, such as list comps: py> dis("[x+1 for x in spam]") 1 0 LOAD_CONST 0 ( at 0xb7af22a0, file "", line 1>) 3 LOAD_CONST 1 ('') 6 MAKE_FUNCTION 0 9 LOAD_NAME 0 (spam) 12 GET_ITER 13 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 16 RETURN_VALUE But that's an implementation detail, not a language requirement, and it doesn't apply to all delayed expressions: py> dis("1/x if x else y") 1 0 LOAD_NAME 0 (x) 3 POP_JUMP_IF_FALSE 14 6 LOAD_CONST 0 (1) 9 LOAD_NAME 0 (x) 12 BINARY_TRUE_DIVIDE 13 RETURN_VALUE >> 14 LOAD_NAME 1 (y) 17 RETURN_VALUE Some Python implementations may use internal functions under the hood to delay the evaluation of an expression, but you still need support from the interpreter to compile the expression as an internal function rather than evaluating it. > > not in the sense I am talking about, > > well, if you eliminate all the possibilities ... Obviously you can pass an expression to a function in the trivial sense that you can put an expression inside a function call. But that is not what I am talking about, since the expression is evaluated first, then the function is called: py> dis("function(spam + eggs*cheese)") 1 0 LOAD_NAME 0 (function) 3 LOAD_NAME 1 (spam) 6 LOAD_NAME 2 (eggs) 9 LOAD_NAME 3 (cheese) 12 BINARY_MULTIPLY 13 BINARY_ADD 14 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 17 RETURN_VALUE I'm referring to delaying execution of the expression until later. Coincidentally, the Sum function we were discussing is a notable example of Jensen's Device: https://en.wikipedia.org/wiki/Jensen%27s_device which is effectively what I'm referring to. > > because expressions are not first-class objects. > > The concept is not a class, and the Python stdlib does not have an > expression class. But people have written classes to represent the > concept. I used existing classes instead. > > Expressions are not (normally) mathematical objects either. (An > exception is rewriting theory, or other theories, where strings > representing expressions or WFFs (well-formed formulas) are the only > objects.) Mathematicians quote expression strings by context or > positiion. The sigma form is one of many examples. Hmmm. I think you are misunderstanding me, possibly because I wrote "first-class object" when I should have called it a "first-class value". Sorry. I'm not necessarily referring to creating something like an "arithmetic expression class" with methods and attributes. For example, sympy has things like that, so you can perform symbolic operations on the expression. That's not what I mean. What I mean is that you, the programmer, writes down an ordinary Python expression, using ordinary expression syntax, and the compiler treats it as a value in and of itself, rather than evaluating it to find out what value it has. In Python this will probably be some sort of object, but that's not the important part. The important part is that it is a *value*. (Compare to languages where functions are not first-class values. You cannot pass a function to another function, or stick them in a list, or create them on the fly. You can only call them, evaluating them immediately.) In Algol60, the compiler used thunks, which are a type of closure; in CPython, list comps use a hidden function object; the ternary if compiles byte code for a test and jump. In case you haven't read the article on Jensen's Device above, in Algol60 you can write a Sum function that behaves as a mathematician would expect. For example, to sum the entries of an array V for indexes 1 through 100, a mathematician might write it something like this: 10 ? V[i] i=1 which we can rearrange to function-call syntax like this: Sum(i, 1, 100, V[i]) In Algol60, this function call would: - pass the name "i" (not a string!) as the first argument; - pass 1 as the second argument; - pass 100 as the third argument; - pass the expression "V[i]" (not a string!) as the fourth argument and then *inside* the function Sum the expressions "i" and "V[i]" can be evaluated or assigned to as needed. Using Python syntax rather than Algol syntax: def Sum(name, lower, upper, expression): total = 0 for name in range(lower, upper+1): total += expression return total This doesn't work in Python! Python lacks call-by-name semantics, so the function call would: - evaluate the expression i, and pass that value as the first argument; - pass 1 as the second argument; - pass 100 as the third argument; - evaluate V[i] and pass that value as the fourth argument and then inside the function Sum "name" refers to the local variable name, not the caller's variable i. Likewise "expression" refers to a local variable, and not the caller's expression V[i]. Python has no general way of doing this. There are a few ad-hoc special cases, like list comps, the ternary if operator, etc. which are hard- coded in the compiler to delay execution of expressions. For the rest, you have a choice: - give up on delayed evaluation, and redesign your API; or - manually manage the delayed evaluation yourself, using some combination of functions, eval or exec. -- Steven D'Aprano http://import-that.dreamwidth.org/ From skip at pobox.com Wed Mar 26 12:34:37 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 26 Mar 2014 11:34:37 -0500 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <87a9cdx87t.fsf@elektro.pacujo.net> References: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> <87a9cdx87t.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 26, 2014 at 10:58 AM, Marko Rauhamaa wrote: > Fractions of seconds are supported -- the other fields can't be > fractional. Actually, it appears that whatever the last value you give can be fractionated. From the Wikipedia page you referenced: "The smallest value used may also have a decimal fraction, as in "P0.5Y" to indicate half a year." > As you say, P1M really means one month and P1Y means one year. The > ambiguity is intentional; if you mean to pay your employees monthly, > the interval is one month. True. Your comment about monthly intervals makes me realize that you probably can't map timedelta objects onto this ISO8601 duration stuff. It seems like if you want to specify "pay my employees on the first of every month", then timedelta objects are the wrong thing. You want a recurrence relation, which is a more complex beast. For that, you want something like dateutil.rrule. There is a good reason that the internal units of timedelta objects are days, seconds, and microseconds. They are well-defined outside of a calendar context. So, I guess Roy is back to square one. He can always roll his own timedelta subclass and give it a __str__ implementation... S From ian.g.kelly at gmail.com Wed Mar 26 12:37:19 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 26 Mar 2014 10:37:19 -0600 Subject: unicode as valid naming symbols In-Reply-To: <53329549.1000208@rece.vub.ac.be> References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> Message-ID: On Wed, Mar 26, 2014 at 2:52 AM, Antoon Pardon wrote: > On 26-03-14 03:56, MRAB wrote: >> Or as a root operator, e.g. 3 ? x (the cube root of x). >> > Personally I would think such an operator is too limited to include in a programming language. > This kind of notation is only used with a constant to indicate what kind of root is taken and > only with positive integers. Something like the equivallent of the following I have never seen. > > t = 2.5 > x = 8.2 > y = t ? x An example is taking the geometric mean of an arbitrary number of values: product = functools.reduce(operator.mul, values, 1) n = len(values) geometric_mean = n ? product I might argue though for the inverted syntax (product ? n) to more closely parallel division. > Of course we don't have to follow mathematical convention with python. However allowing any > unicode symbol as an identifier doesn't prohibit from using ? as an operator. We do have > "in" and "is" as operators now, even if they would otherwise be acceptable identifiers. > So I wonder, would you consider to introduce log as an operator. 2 log x seems an interesting > operation for a programmer. If it's going to become an operator, then it has to be a keyword. Changing a token that is currently allowed to be an identifier into a keyword is generally avoided as much as possible, because it breaks backward compatibility. "in" and "is" have both been keywords for a very long time, perhaps since the initial release of Python. From marko at pacujo.net Wed Mar 26 13:13:44 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 26 Mar 2014 19:13:44 +0200 Subject: YADTR (Yet Another DateTime Rant) References: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> <87a9cdx87t.fsf@elektro.pacujo.net> Message-ID: <87a9ccopbr.fsf@elektro.pacujo.net> Skip Montanaro : > There is a good reason that the internal units of timedelta objects > are days, seconds, and microseconds. They are well-defined outside of > a calendar context. > > So, I guess Roy is back to square one. He can always roll his own > timedelta subclass and give it a __str__ implementation... If you don't want to mix the intricacies of calendars to datetime and timedelta, why use them? (Epoch) seconds do everything for you unambiguously. Yes, yes. The physicists ought to stop fricking around with leap seconds. They should declare a 3000-year moratorium on leap seconds. Marko From rustompmody at gmail.com Wed Mar 26 13:32:04 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 26 Mar 2014 10:32:04 -0700 (PDT) Subject: Delayed evaluation of expressions [was Re: Time we switched to unicode?] In-Reply-To: <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> On Wednesday, March 26, 2014 9:35:53 PM UTC+5:30, Steven D'Aprano wrote: > On Wed, 26 Mar 2014 00:30:21 -0400, Terry Reedy wrote: > > On 3/25/2014 8:12 PM, Steven D'Aprano wrote: > >> On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote: > >>> On 3/25/2014 11:18 AM, Steven D'Aprano wrote: > >>>> The thing is, we can't just create a ? function, because it doesn't > >>>> work the way the summation operator works. The problem is that we > >>>> would want syntactic support, so we could write something like this: > >>>> p = 2 > >>>> ?(n, 1, 10, n**p) > >>> Of course we can. If we do not insist on separating the dummy name > >>> from the expression that contains it. this works. > >>> def sigma(low, high, func): > >>> sum = 0 > >>> for i in range(low, high+1): > >>> sum += func(i) > >>> return sum > >> There is no expression there. There is a function. > >> You cannot pass an expression to a function in Python, > > One passes an unquoted expression in code by quoting it with either > > lambda, paired quote marks (Lisp used a single '), > Passing *strings* and *functions* is not the same as having compiler > support for delayed evaluation. At best its a second-class work-around. > Contrast: Once the language has lambda, most else can be fashioned See the classic papers lambda the ultimate imperative lambda the ultimate declarative lambda the ultimate goto at here http://library.readscheme.org/page1.html > Coincidentally, the Sum function we were discussing is a notable example > of Jensen's Device: > https://en.wikipedia.org/wiki/Jensen%27s_device > which is effectively what I'm referring to. > > > because expressions are not first-class objects. > > The concept is not a class, and the Python stdlib does not have an > > expression class. But people have written classes to represent the > > concept. I used existing classes instead. > > Expressions are not (normally) mathematical objects either. (An > > exception is rewriting theory, or other theories, where strings > > representing expressions or WFFs (well-formed formulas) are the only > > objects.) Mathematicians quote expression strings by context or > > positiion. The sigma form is one of many examples. > Hmmm. I think you are misunderstanding me, possibly because I wrote > "first-class object" when I should have called it a "first-class value". > Sorry. > I'm not necessarily referring to creating something like an "arithmetic > expression class" with methods and attributes. For example, sympy has > things like that, so you can perform symbolic operations on the > expression. That's not what I mean. > What I mean is that you, the programmer, writes down an ordinary Python > expression, using ordinary expression syntax, and the compiler treats it > as a value in and of itself, rather than evaluating it to find out what > value it has. In Python this will probably be some sort of object, but > that's not the important part. The important part is that it is a *value*. > (Compare to languages where functions are not first-class values. You > cannot pass a function to another function, or stick them in a list, or > create them on the fly. You can only call them, evaluating them > immediately.) > In Algol60, the compiler used thunks, which are a type of closure; in > CPython, list comps use a hidden function object; the ternary if compiles > byte code for a test and jump. > In case you haven't read the article on Jensen's Device above, in Algol60 > you can write a Sum function that behaves as a mathematician would > expect. For example, to sum the entries of an array V for indexes 1 > through 100, a mathematician might write it something like this: > 10 > ? V[i] > i=1 > which we can rearrange to function-call syntax like this: > Sum(i, 1, 100, V[i]) > In Algol60, this function call would: > - pass the name "i" (not a string!) as the first argument; > - pass 1 as the second argument; > - pass 100 as the third argument; > - pass the expression "V[i]" (not a string!) as the fourth argument > and then *inside* the function Sum the expressions "i" and "V[i]" can be > evaluated or assigned to as needed. Using Python syntax rather than Algol > syntax: > def Sum(name, lower, upper, expression): > total = 0 > for name in range(lower, upper+1): > total += expression > return total > This doesn't work in Python! Python lacks call-by-name semantics, so the > function call would: > - evaluate the expression i, and pass that value as the first argument; > - pass 1 as the second argument; > - pass 100 as the third argument; > - evaluate V[i] and pass that value as the fourth argument > and then inside the function Sum "name" refers to the local variable > name, not the caller's variable i. Likewise "expression" refers to a > local variable, and not the caller's expression V[i]. > Python has no general way of doing this. There are a few ad-hoc special > cases, like list comps, the ternary if operator, etc. which are hard- > coded in the compiler to delay execution of expressions. For the rest, > you have a choice: > - give up on delayed evaluation, and redesign your API; or > - manually manage the delayed evaluation yourself, using > some combination of functions, eval or exec. Heres Jensen device in python First your pseudo algol version with python frills like range removed def sumjensen(i,lower,upper,exp): # i and exp by name # i get and set, exp only get required tot = 0 i = lower while i <= upper: tot += exp i = i + 1 return tot Now actual python def sumjensen(i_get, i_set,lower,upper,exp): tot = 0 i_set(lower) while i_get() <= upper: tot += exp_get() i_set(i_get() + 1) return tot i=0 a=[3,4,5] i_get = lambda : i def i_set(val): global i i = val exp_get = lambda : a[i_get()] call as sumjensen(i_get, i_set, lower, upper, exp_get) [Note that because of lambda's restriction to being only an expression I have to make it a def because of need for global] From rustompmody at gmail.com Wed Mar 26 13:57:52 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 26 Mar 2014 10:57:52 -0700 (PDT) Subject: Delayed evaluation of expressions [was Re: Time we switched to unicode?] In-Reply-To: <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> Message-ID: On Wednesday, March 26, 2014 11:02:04 PM UTC+5:30, Rustom Mody wrote: > On Wednesday, March 26, 2014 9:35:53 PM UTC+5:30, Steven D'Aprano wrote: > > On Wed, 26 Mar 2014 00:30:21 -0400, Terry Reedy wrote: > > > One passes an unquoted expression in code by quoting it with either > > > lambda, paired quote marks (Lisp used a single '), > > Passing *strings* and *functions* is not the same as having compiler > > support for delayed evaluation. At best its a second-class work-around. > > Contrast: > Once the language has lambda, most else can be fashioned > See the classic papers > lambda the ultimate imperative > lambda the ultimate declarative > lambda the ultimate goto > at here http://library.readscheme.org/page1.html
Which I should have summarized as: lambda is the essential Delay operator. So much so that in scheme thaw and freeze are defined as (using pseudo-python syntax) def thaw(x) : return x() freeze(x) is a 'special-form' (aka macro) such that freeze(x) ? lambda : x From invalid at invalid.invalid Wed Mar 26 15:12:26 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 26 Mar 2014 19:12:26 +0000 (UTC) Subject: YADTR (Yet Another DateTime Rant) References: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> <87a9cdx87t.fsf@elektro.pacujo.net> Message-ID: On 2014-03-26, Skip Montanaro wrote: > On Wed, Mar 26, 2014 at 10:58 AM, Marko Rauhamaa wrote: >> Fractions of seconds are supported -- the other fields can't be >> fractional. > > Actually, it appears that whatever the last value you give can be > fractionated. From the Wikipedia page you referenced: We're still just papering-over the basic problem: the entire time/calendar system use by "western civilization" is a mess. I don't know a lot about other systems in use, but from what I have seen they were all pretty much just as bad. We should fix the basic problem first, then I bet the Python library problems will sort themselves out pretty easily. Of course to simplify matters, we're going to have to stop worrying so much about seasons and whether it's light or dark outside... -- Grant Edwards grant.b.edwards Yow! Hey, wait at a minute!! I want a gmail.com divorce!! ... you're not Clint Eastwood!! From ben+python at benfinney.id.au Wed Mar 26 16:06:17 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 27 Mar 2014 07:06:17 +1100 Subject: YADTR (Yet Another DateTime Rant) References: <1102ec6b-6205-40f4-bb7c-d40f9d13115b@googlegroups.com> <87a9cdx87t.fsf@elektro.pacujo.net> Message-ID: <85a9ccrah2.fsf@benfinney.id.au> Grant Edwards writes: > We're still just papering-over the basic problem: the entire > time/calendar system use by "western civilization" is a mess. I don't > know a lot about other systems in use, but from what I have seen they > were all pretty much just as bad. We should fix the basic problem > first, then I bet the Python library problems will sort themselves out > pretty easily. I see from my calendar that 1 April is still several days away. So I wonder how serious you are: we should forestall dealing with the reality of calendars, until the world fixes our difficulties for us? > Of course to simplify matters, we're going to have to stop worrying so > much about seasons and whether it's light or dark outside... Not too serious, I suppose. So what *do* you recommend we do? It's easy to point at the real world and say it's messy and distasteful to deal with, but that's a big part of the job we take on as programmers. -- \ ?? Nature ? is seen to do all things Herself and through | `\ herself of own accord, rid of all gods.? ?Titus Lucretius | _o__) Carus, c. 40 BCE | Ben Finney From ian.g.kelly at gmail.com Wed Mar 26 17:19:03 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 26 Mar 2014 15:19:03 -0600 Subject: Dynamically reference variable in object In-Reply-To: References: Message-ID: On Mar 26, 2014 5:48 AM, "Ben Collier" wrote: > > Sorry, subject was wrong. Please see below: > > On Wednesday, 26 March 2014 11:43:49 UTC, Ben Collier wrote: > > Hi all, > > I know that I can dynamically reference a variable with locals()["i"], for instance, but I'd like to know how to do this with a variable in an object. > > If I have an object called "device", with variables called attr1, attr2 .. attr50, how could I dynamically reference these? > > It's fairly academic, but I'd like to avoid code duplication. You want to access object "attributes", not "variables". You can do this using the functions getattr and setattr like so: >>> class Foo(object): pass ... >>> obj = Foo() >>> setattr(obj, "x", 42) >>> print(obj.x) 42 >>> print(getattr(obj, "x")) 42 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed Mar 26 05:53:16 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 26 Mar 2014 10:53:16 +0100 (CET) Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: Message-ID: <52552396.9136436.1395827596260.JavaMail.root@sequans.com> ----- Original Message ----- > One of my roles on this newsgroup is to periodically whine about > stupidities in the Python datetime module. This is one of those > times. > > I have some code which computes how long ago the sun set. Being a > nice > pythonista, I'm using a timedelta to represent this value. It would > be > difficult to imagine a less useful default way to print a timedelta: > > previous sunset: -1 day, 22:25:26.295993 > > The idea of str() is that it's supposed to return a human-friendly > representation of a value. Humans do not say things like, "The sun > set > 1 day ago plus 22 hours and 25 minutes". I can think of a less useful default way: previous sunset: 1 sunset ago This is how humans have been saying things for thousands of years before inventing the clock. Beside that, I think datetime has all the formatters required to do pretty much anything. Note : I don't see what's wrong in your example, however I have the feeling the term "stupiditie" is a little bit strong ;) JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From victor.engle at gmail.com Wed Mar 26 11:46:35 2014 From: victor.engle at gmail.com (Victor Engle) Date: Wed, 26 Mar 2014 11:46:35 -0400 Subject: datetime Message-ID: I want to keep a collection of data organized by collection date and I'll use datetime like this... >>> datetime.date.today() datetime.date(2014, 3, 26) I'll format the date and create directories like /mydata/yyyy-mm-dd When I create a directory for today, I need to know the directory name for yesterday and tomorrow. In perl I could get seconds since the epoch using time and then add or subtract from that number for tomorrow or yesterday and feed that into localtime to get the date string. It would be convenient if datetime.date.today() accepted an argument as an offset from today, like datetime.date.today(-1). Is there an easy way to do this with datetime? -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Wed Mar 26 17:27:32 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 27 Mar 2014 08:27:32 +1100 Subject: calling Python script from another Python script (Windows, multiple installation problem) In-Reply-To: <6ba81449-5f4c-46be-ad4a-64ea8bc5b436@googlegroups.com> References: <6ba81449-5f4c-46be-ad4a-64ea8bc5b436@googlegroups.com> Message-ID: <20140326212732.GA33967@cskk.homeip.net> On 26Mar2014 05:49, Martin Landa wrote: > Dne st?eda, 26. b?ezna 2014 13:29:47 UTC+1 Martin Landa napsal(a): > > not really, I am just searching for a better solution based on virtualenv or something similar... > > particularly I am using something like > > if sys.platform == "win32": > # get full path including file extension for scripts > fcmd = get_real_command(args[0]) > if fcmd.endswith('.py'): > args[0] = fcmd > args.insert(0, sys.executable) > > where 'args' in subprocess.Popen's argument. I just wonder if > there is a better or preferable solution over this kind of a hack. Personally, the above is what I would do in your situation. Any solution involving virtualenv or the like will still need to point at the right python executable. Provided your code above is in a handy function, I wouldn't modify it. What virtualenv (presumably a virtualenv bundled in your package) _will_ give you is a stable and predictable collection of library files to go with your python interpreter. That could well be a significant benefit, especially in the face or an unknown target machine. So you may have a good case for putting a virtualenv in your bundle, but still using the _same_ code above to invoke stuff - the python in the virtualenv will set its sys.path, so the easy way is to use your existing code to access the virtualenv python executable. The only catch is that I do not know how mobile a virtualenv is; if your bundle is unpacked in an unknown temporary location, maybe virtualenv won't work correctly. Needs testing. Disclaimer: I'm a UNIX guy. Just my 2c. Hope it is helpful, -- Cameron Simpson Carpe Datum - John Sloan From __peter__ at web.de Wed Mar 26 17:33:32 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 26 Mar 2014 22:33:32 +0100 Subject: datetime References: Message-ID: Victor Engle wrote: > I want to keep a collection of data organized by collection date and I'll > use datetime like this... > >>>> datetime.date.today() > > datetime.date(2014, 3, 26) > > > I'll format the date and create directories like /mydata/yyyy-mm-dd > > > When I create a directory for today, I need to know the directory name for > yesterday and tomorrow. In perl I could get seconds since the epoch using > time and then add or subtract from that number for tomorrow or yesterday > and feed that into localtime to get the date string. > > > It would be convenient if datetime.date.today() accepted an argument as > an offset from today, like datetime.date.today(-1). Is there an easy way > to do this with datetime? >>> import datetime >>> ONE_DAY = datetime.timedelta(days=1) >>> today = datetime.date.today() >>> today datetime.date(2014, 3, 26) >>> today - ONE_DAY datetime.date(2014, 3, 25) >>> today + ONE_DAY datetime.date(2014, 3, 27) From ben+python at benfinney.id.au Wed Mar 26 17:36:42 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 27 Mar 2014 08:36:42 +1100 Subject: datetime References: Message-ID: <851txor6ad.fsf@benfinney.id.au> Victor Engle writes: > It would be convenient if datetime.date.today() accepted an argument > as an offset from today, like datetime.date.today(-1). Is there an > easy way to do this with datetime? The types defined in ?datetime? can perform calendar arithmetic:: import datetime today = datetime.date.today() one_day = datetime.timedelta(days=1) yesterday = today - one_day tomorrow = today + one_day -- \ ?Most people, I think, don't even know what a rootkit is, so | `\ why should they care about it?? ?Thomas Hesse, Sony BMG, 2006 | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Wed Mar 26 18:08:47 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 27 Mar 2014 11:08:47 +1300 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <5332DDE7.2050202@rece.vub.ac.be> Message-ID: Chris Angelico wrote: > By showing those last ones as 1?.091... and 2?.091..., you emphasize > the floating-point nature of the data: everything after the decimal is > the mantissa, and everything before the decimal is the exponent. The reason for writing them that way is so that you can look the last part up in your log tables to find the antilog. I can't think of any corresponding justification for timedeltas. -- Greg From rosuav at gmail.com Wed Mar 26 18:24:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 09:24:49 +1100 Subject: Delayed evaluation of expressions [was Re: Time we switched to unicode?] In-Reply-To: <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> Message-ID: On Thu, Mar 27, 2014 at 4:32 AM, Rustom Mody wrote: > Now actual python > > def sumjensen(i_get, i_set,lower,upper,exp): > tot = 0 > i_set(lower) > while i_get() <= upper: > tot += exp_get() > i_set(i_get() + 1) > return tot > > > i=0 > a=[3,4,5] > i_get = lambda : i > def i_set(val): > global i > i = val > > exp_get = lambda : a[i_get()] > > > call as sumjensen(i_get, i_set, lower, upper, exp_get) > > [Note that because of lambda's restriction to being only an expression > I have to make it a def because of need for global] You prove here that Python has first-class expressions in the same way that 80x86 assembly language has garbage collection. Sure, you can implement it using the primitives you have, but that's not support. ChrisA From marko at pacujo.net Wed Mar 26 18:45:19 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 27 Mar 2014 00:45:19 +0200 Subject: Delayed evaluation of expressions References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> Message-ID: <871txok29s.fsf@elektro.pacujo.net> Chris Angelico : > You prove here that Python has first-class expressions in the same way > that 80x86 assembly language has garbage collection. Sure, you can > implement it using the primitives you have, but that's not support. I was more reminded of STL and Boost. For example: std::for_each(v.begin(), v.end(), ( switch_statement( _1, case_statement<0>(std::cout << constant("zero")), case_statement<1>(std::cout << constant("one")), default_statement(cout << constant("other: ") << _1) ), cout << constant("\n") ) ); () Marko From steve+comp.lang.python at pearwood.info Wed Mar 26 19:42:22 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2014 23:42:22 GMT Subject: Dynamically reference variable in object References: Message-ID: <533365de$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Mar 2014 15:19:03 -0600, Ian Kelly wrote: > You want to access object "attributes", not "variables". In fairness to the OP, the terminology "instance variables" meaning attributes or members of an instance is (sadly, in my opinion) common in some other languages, such as Java, and occasionally creeps into even the Python docs. I've often ranted about this, and won't repeat it now, only point out that the preferred and most common terminology in Python circles is "attribute", or "instance attribute" if you need to distinguish it from "class attribute". -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Wed Mar 26 19:43:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2014 23:43:21 GMT Subject: Delayed evaluation of expressions [was Re: Time we switched to unicode?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> Message-ID: <53336618$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Mar 2014 09:24:49 +1100, Chris Angelico wrote: > On Thu, Mar 27, 2014 at 4:32 AM, Rustom Mody > wrote: >> Now actual python >> >> def sumjensen(i_get, i_set,lower,upper,exp): >> tot = 0 >> i_set(lower) >> while i_get() <= upper: >> tot += exp_get() >> i_set(i_get() + 1) >> return tot >> >> >> i=0 >> a=[3,4,5] >> i_get = lambda : i >> def i_set(val): >> global i >> i = val >> >> exp_get = lambda : a[i_get()] >> >> >> call as sumjensen(i_get, i_set, lower, upper, exp_get) >> >> [Note that because of lambda's restriction to being only an expression >> I have to make it a def because of need for global] > > You prove here that Python has first-class expressions in the same way > that 80x86 assembly language has garbage collection. Sure, you can > implement it using the primitives you have, but that's not support. +1 Any language can work around the lack of a language feature by sufficient layers of indirection, but that's not the same as having that language feature. Beyond a certain minimum feature set, all languages are Turing complete, and so in one sense are of equivalent power. But they're not all of equal expressiveness. Python is awesome, it is very expressive, but there are certain things you can't write directly in Python, and have to resort to circumlocutions instead. See also Paul Graham's "Blub language" essay: http://paulgraham.com/avg.html -- Steven D'Aprano http://import-that.dreamwidth.org/ From ethan at stoneleaf.us Wed Mar 26 19:33:50 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 26 Mar 2014 16:33:50 -0700 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: Message-ID: <533363DE.2020604@stoneleaf.us> On 03/26/2014 04:25 PM, Dennis Lee Bieber wrote: > On Tue, 25 Mar 2014 20:58:27 -0400, Roy Smith declaimed the > following: > >> One of my roles on this newsgroup is to periodically whine about >> stupidities in the Python datetime module. This is one of those times. >> >> I have some code which computes how long ago the sun set. Being a nice >> pythonista, I'm using a timedelta to represent this value. It would be >> difficult to imagine a less useful default way to print a timedelta: >> >> previous sunset: -1 day, 22:25:26.295993 >> >> The idea of str() is that it's supposed to return a human-friendly >> representation of a value. Humans do not say things like, "The sun set >> 1 day ago plus 22 hours and 25 minutes". > > Makes sense to me -- the key being time DELTA... IE, a difference from > some (unspecified) instance in time... > > If you want an instance of time, you need to add some known instance > and the delta value. Making sense is not the same as user friendly... "Hey, when did Bob get here?" "About 15 minutes ago." vs "About an hour ago, plus 45 minutes." -- ~Ethan~ From steve+comp.lang.python at pearwood.info Wed Mar 26 20:16:57 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Mar 2014 00:16:57 GMT Subject: YADTR (Yet Another DateTime Rant) References: Message-ID: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Mar 2014 19:25:45 -0400, Dennis Lee Bieber wrote: > On Tue, 25 Mar 2014 20:58:27 -0400, Roy Smith declaimed > the following: > >>One of my roles on this newsgroup is to periodically whine about >>stupidities in the Python datetime module. This is one of those times. >> >>I have some code which computes how long ago the sun set. Being a nice >>pythonista, I'm using a timedelta to represent this value. It would be >>difficult to imagine a less useful default way to print a timedelta: >> >>previous sunset: -1 day, 22:25:26.295993 >> >>The idea of str() is that it's supposed to return a human-friendly >>representation of a value. Humans do not say things like, "The sun set >>1 day ago plus 22 hours and 25 minutes". > > Makes sense to me -- the key being time DELTA... IE, a difference > from some (unspecified) instance in time... > > If you want an instance of time, you need to add some known > instance and the delta value. I think you have missed the point of the rant. Roy is not ranting that he has a timedelta. He wants a timedelta. He is ranting that the timedelta displays in a totally unintuitive fashion. Paraphrasing: "the previous sunset was (one day less 22 hours and 25 minutes) ago" instead of "the previous sunset was (1 hour and 35 minutes) ago" where the parts in the brackets come directly from the timedelta object. I think that you misread Roy's example as: "1 day plus 22 hours 25 minutes ago" instead of: "1 day ago plus 22 hours 25 minutes" (that is, 22 hours and 25 minutes after 1 day ago). The problem here, I believe, is that there are two ways of interpreting remainders for negative numbers. Dividing -5 by 2 can give either -2 with remainder -1, or -3 with remainder +1. Mathematically, it is *usually* more useful to go with the version with the positive remainder, and that's what Python does. But I think it's the wrong choice for timedelta. Let's take a simple example: a timedelta of 30 hours. What's that in days and hours? py> divmod(30, 24) (1, 6) That makes perfect intuitive sense: 30 hours is 1 day with 6 hours remaining. In human-speak, we'll say that regardless of whether the timedelta is positive or negative: we'll say "1 day and 6 hours from now" or "1 day and 6 hours ago". But when we specify the sign: py> divmod(-30, 24) (-2, 18) If an event happened 30 hours ago, it is correct to say that it occurred "18 hours after 2 days ago", but who talks that way? -- Steven D'Aprano http://import-that.dreamwidth.org/ From tjreedy at udel.edu Wed Mar 26 20:44:17 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Mar 2014 20:44:17 -0400 Subject: Delayed evaluation of expressions [was Re: Time we switched to unicode?] In-Reply-To: <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: I agree that we have not been understanding each other. From you original post that I responded to: >>>>> The thing is, we can't just create a ? function, because it doesn't >>>>> work the way the summation operator works. The problem is that we >>>>> would want syntactic support, so we could write something like this: >>>>> p = 2 >>>>> ?(n, 1, 10, n**p) The initial misunderstanding is that I interpreted 'something like this' more loosely than you meant it. So I wrote something that was 'something like the above' to me but not to you. I interpreted 'something like' semantically* whereas you apparently meant is syntactically. I added the one or the other little marks needed to make the above work in python as it is whereas your 'something like' excludes such marks or any other current possibility I can think of. So I actually agree that "can't" is correct in relation to what you meant, as opposed to what I understood. Changing "can't" to "can" would requires a major change to Python. That change is one I would strongly oppose and I will try to explain more clearly why. [*When I qualify doc suggestions on the tracker with 'something like', as I usually do, I mean something that conveys the same meaning. So I edited your call text to convey the intended meaning in Python.] Lets start with things we should agree on. The first two are mostly not specific to Python. 1. When a compiler encounters an expression in code, there are at least three things it can do: 1a. compile it so that it is immediately executed when encountered at runtime (let this be the default); 1b. compile it so that it is somehow saved for execution later or elsewhere (the alternative of concern here); 1c. compile it for a different alternative, such as turning an implied 'get' operation into a 'set' operation. 2. A code writer who wants an alternative treatment for a particular must somehow delineate the expresion with boundary markers that, in context at least, also indicate the alternative treatment. There are, broadly, two possibilities: 2a. Use a generic quotation mechanism that can be applied to any expression most any place. I call this explicit quoting. 2b. Use the expression in a special form that the compiler knows about. The special form must have begin-end markers of some sort. I call this implicit quoting. If human readers do not know that a particular form is a special form, they may have a problem understanding the code. Python has 2 pairs of generic explicit delimiters: open-close quote marks and lambda-, where is ',', ')', , or maybe something else. If these are not present, the default immediate execution mode is used for expressions in function calls that are not themselves marked for alternative treatment. Python's special forms are statements. Each has its own pair of delimiters. Assignments use and '='. 'For' loops use 'for' and 'in'. Other statements use 'as' and usually . Statements and functions call are syntactically very distinct, so there is little possibility of confusion. I consider this a major feature of python and I would oppose breaking it. Lisp, for instance, uses s-expressions for everything, including what would either function calls or statements in Python. Special functions implicitly quote some argument expressions, but not necessarily all, while normal functions do not quote any. The only way to know is to know, and I found it confusing and difficult to remember. > Sum(i, 1, 100, V[i]) > In Algol60, this function call would: > - pass the name "i" (not a string!) as the first argument; > - pass 1 as the second argument; > - pass 100 as the third argument; > - pass the expression "V[i]" (not a string!) as the fourth argument which depends for this operation on > https://en.wikipedia.org/wiki/Jensen%27s_device I read the whole article, including the criticisms and the fact that it was not widely adopted and has been more or less superceded by macros. It did not answer the obvious question: suppose the call is Sum(i, l, h, V[i]). How is the reader supposed to know that 'i' and 'V[i]' get quoted and the other args do not? The article included real procedure Sum(k, l, u, ak) value l, u; integer k, l, u; real ak; comment k and ak are passed by name; begin real s; s := 0; for k := l step 1 until u do s := s + ak; Sum := s end; If that is supposed to be real code that can be compiled, I see no way for the comment to be true. Or is the mechanism limited to builtin functions? -- Terry Jan Reedy From rhodri at wildebst.org.uk Wed Mar 26 21:01:52 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 27 Mar 2014 01:01:52 -0000 Subject: python installation on windows References: <04f1a2d3-4d34-4871-a845-1301cda1c19c@googlegroups.com> <96fa02bf-7c6d-4b12-8791-d640d5910173@googlegroups.com> Message-ID: On Tue, 25 Mar 2014 18:17:30 -0000, wrote: >> Thanks for your comment but i also edited httpd.conf file then my wamp >> not running >> >> LoadModule php5_module "c:/wamp/bin/php/php5.3.0/php5apache2_2.dll" >> >> This line i added on line 128 but nothing. Wampserver showing yellow. >> >> I'm not getting what happening. I'm doing as per suggested in >> documentation >> > > And again if i'm removing this line then wampserver works properly I'm totally confused. You started out asking about problems getting mod_wsgi to load, and now without any indication that you've actually got mod_wsgi to load you are asking a Python group about a PHP module. Slow down, do one thing at a time and please don't assume that we can read your mind. Also please read https://wiki.python.org/moin/GoogleGroupsPython and take appropriate action. This post was unreadable when it got to me, and I nearly didn't bother putting in the effort to make it readable. -- Rhodri James *-* Wildebeest Herder to the Masses From nispray at gmail.com Wed Mar 26 21:04:33 2014 From: nispray at gmail.com (Wesley) Date: Wed, 26 Mar 2014 18:04:33 -0700 (PDT) Subject: gdb python how to output integer for examine memory In-Reply-To: References: <2aa794ce-7cc1-4d24-a30b-3fb17b89e33f@googlegroups.com> Message-ID: <241236ba-029a-4206-b5a1-f60bd19e56c9@googlegroups.com> ? 2014?3?26????UTC+8??3?10?23??dieter??? > Wesley writes: > > > ... > > > Actually, I can now see the varialbe names at Python level and C level. > > > I just want to verify x command to monitor the memory content. > > > So, in my origin post, I can get variable i's address, and see the value is 1, > > > then, I wanna have a try x command, the issue is, when use x/format i's address, the output is not 1, but other things:-( > > > > All Python objects start (at C level) with a header (containing > > the reference count, a pointer to the associated type and > > maybe other things); the "real" value starts behind this header. > > > > This means, to see the "1" in your example, you must skip the > > associated object header -- either in the output or by adding > > the size of the header to the initial address. Most like this. I will try later. From rhodri at wildebst.org.uk Wed Mar 26 21:16:48 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Thu, 27 Mar 2014 01:16:48 -0000 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, 25 Mar 2014 06:12:50 -0000, Chris Angelico wrote: > Because the shorter symbols lend themselves better to the > "super-tokenization" where you don't read the individual parts but the > whole. The difference between "40" and "forty" is minimal, but the > difference between "86400" and "eighty-six thousand [and] four > hundred" is significant; the first is a single token, which you could > then instantly recognize as the number of seconds in a day (leap > seconds aside), but the second is a lengthy expression. It's not quite that simple, sadly (for me). I have mild dyscalculia, which in my case is another way of saying that collections of digits *aren't* tokens to me unless I ascribe a specific meaning to them. I don't work with day-level time differences a lot, so 86400 is just a string of digits to me. Powers of two and one less than powers of two I use a lot, so 65535 for example is a token. The more digits there are in the number, the harder it is for me to take in in a way that doesn't happen with letters. Even "forty" is better than "40" if you want me to recall it! -- Rhodri James *-* Wildebeest Herder to the Masses From rosuav at gmail.com Wed Mar 26 21:26:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 12:26:21 +1100 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53311887$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Mar 27, 2014 at 12:16 PM, Rhodri James wrote: > It's not quite that simple, sadly (for me). I have mild dyscalculia, which > in my case is another way of saying that collections of digits *aren't* > tokens to me unless I ascribe a specific meaning to them. I don't work with > day-level time differences a lot, so 86400 is just a string of digits to me. > Powers of two and one less than powers of two I use a lot, so 65535 for > example is a token. The more digits there are in the number, the harder it > is for me to take in in a way that doesn't happen with letters. Even > "forty" is better than "40" if you want me to recall it! Interesting. This suggests that your brain works happily with words (since you can recall "forty" more easily), but not with digits. But even in the normal case, that will be true to some extent. It's common to break up long numbers into groups of three or four digits - look at credit cards and phone numbers, for two very common examples. Treating 86400 as a single token comes more easily when you know it's the number of seconds in a day, and recognizing 604800 as the number of seconds in a week is pretty much essential to seeing it as a single token. ChrisA From rosuav at gmail.com Wed Mar 26 21:28:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 12:28:43 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 27, 2014 at 11:16 AM, Steven D'Aprano wrote: > If an event happened 30 hours ago, it is correct to say that it occurred > "18 hours after 2 days ago", but who talks that way? That response demonstrates real genius. Rue the datetime? Who talks like that? ChrisA From roy at panix.com Wed Mar 26 21:38:32 2014 From: roy at panix.com (Roy Smith) Date: Wed, 26 Mar 2014 21:38:32 -0400 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Thu, Mar 27, 2014 at 11:16 AM, Steven D'Aprano > wrote: > > If an event happened 30 hours ago, it is correct to say that it occurred > > "18 hours after 2 days ago", but who talks that way? > > That response demonstrates real genius. Rue the datetime? Who talks like that? "I had a dangling pointer error, and blew my stack to half past last wednesday" From rustompmody at gmail.com Wed Mar 26 21:59:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 26 Mar 2014 18:59:33 -0700 (PDT) Subject: Delayed evaluation of expressions [was Re: Time we switched to unicode?] In-Reply-To: <53336618$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> <53336618$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <169b5e45-f911-47c2-996b-0507d78dd7d1@googlegroups.com> On Thursday, March 27, 2014 5:13:21 AM UTC+5:30, Steven D'Aprano wrote: > On Thu, 27 Mar 2014 09:24:49 +1100, Chris Angelico wrote: > > wrote: > >> Now actual python > >> def sumjensen(i_get, i_set,lower,upper,exp): > >> tot = 0 > >> i_set(lower) > >> while i_get() <= upper: > >> tot += exp_get() > >> i_set(i_get() + 1) > >> return tot > >> i=0 > >> a=[3,4,5] > >> i_get = lambda : i > >> def i_set(val): > >> global i > >> i = val > >> exp_get = lambda : a[i_get()] > >> call as sumjensen(i_get, i_set, lower, upper, exp_get) > >> [Note that because of lambda's restriction to being only an expression > >> I have to make it a def because of need for global] > > You prove here that Python has first-class expressions in the same way > > that 80x86 assembly language has garbage collection. Sure, you can > > implement it using the primitives you have, but that's not support. > +1 > Any language can work around the lack of a language feature by sufficient > layers of indirection, but that's not the same as having that language > feature. > Beyond a certain minimum feature set, all languages are Turing complete, > and so in one sense are of equivalent power. But they're not all of equal > expressiveness. Python is awesome, it is very expressive, but there are > certain things you can't write directly in Python, and have to resort to > circumlocutions instead. Of course. And there are different grades of circumlocution -- of 'coding-up' -- a missing feature. Terry said: > One passes an unquoted expression in code by quoting it with either > lambda, paired quote marks (Lisp used a single '), Steven responded: > Passing *strings* and *functions* is not the same as having compiler > support for delayed evaluation. At best its a second-class work-around. I was merely pointing out that 'passing strings' and 'passing functions' as 'coding-up' of some desirable but unavailable feature are very different levels of work-around. In fact there are actually 3 styles and levels of circumlocution 1. You dont have a certain language -- blub?? -- feature set. So... code it up and write its interpreter as eval_blub. 2. You dont have a feature-set but can see similarity in some obtuse host-language (in this case python). So you code up a mini-translator for your feature-set neatly written to obtuse hostly written and then eval (note python eval not blub eval) 3. You dont go outside the language framework and into any eval-ish mode at all. Good ol subroutine libraries to classes for abstraction to first-class functional abstraction -- all fall into this category From steve+comp.lang.python at pearwood.info Wed Mar 26 22:16:14 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Mar 2014 02:16:14 GMT Subject: Delayed evaluation of expressions [was Re: Time we switched to unicode?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <281c8ce1-4f03-4e93-b5cd-d45b85e89e7e@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533389ed$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 26 Mar 2014 20:44:17 -0400, Terry Reedy wrote: > I agree that we have not been understanding each other. > > From you original post that I responded to: >>>>>> The thing is, we can't just create a ? function, because it doesn't >>>>>> work the way the summation operator works. The problem is that we >>>>>> would want syntactic support, so we could write something like >>>>>> this: > >>>>> p = 2 > >>>>> ?(n, 1, 10, n**p) > > The initial misunderstanding is that I interpreted 'something like this' > more loosely than you meant it. So I wrote something that was 'something > like the above' to me but not to you. I interpreted 'something like' > semantically* whereas you apparently meant is syntactically. I added the > one or the other little marks needed to make the above work in python as > it is whereas your 'something like' excludes such marks or any other > current possibility I can think of. So I actually agree that "can't" is > correct in relation to what you meant, as opposed to what I understood. > > Changing "can't" to "can" would requires a major change to Python. That > change is one I would strongly oppose and I will try to explain more > clearly why. I'm not making a serious proposal to change Python's behaviour. In context, this came up because I said that allowing arbitrary maths symbols in Python wouldn't work, because you can't get the behaviour right, and used the example of ?(n, 1, 10, n**p) as something where the behaviour would be different from what a mathematician would like. Given that the semantics would be so different, there's little point in trying to match the symbol ? too. Just write it as sum() in the Pythonic style. Python is not Mathematica. (However, you could, perhaps, write Mathematica in Python.) That was the context of introducing delayed evaluation to the discussion. But having raised it, I do think it is an important and useful feature. Python already has it in various ad hoc places, such as list comps and generator expressions, ternary if, and/or, and it came up again recently in the PEP for try...except expressions. It doesn't happen every day, but there is a steady trickle of requests (some successful, some not) for compiler support for something that includes delaying the evaluation of some expression until later. Some day, if all the pieces come into place, I may make a serious proposal for a generic mechanism for delaying execution of expressions. But that is not this day. [...] > Lets start with things we should agree on. The first two are mostly not > specific to Python. > > 1. When a compiler encounters an expression in code, there are at least > three things it can do: > 1a. compile it so that it is immediately executed when encountered at > runtime (let this be the default); > 1b. compile it so that it is somehow saved for execution later or > elsewhere (the alternative of concern here); > 1c. compile it for a different alternative, such as turning an implied > 'get' operation into a 'set' operation. I don't actually understand what 1c is, or rather I understand what you mean, I don't understand why a compiler would do that. But I don't think it is important, so carry on. > 2. A code writer who wants an alternative treatment for a particular > must somehow delineate the expresion with boundary markers that, in > context at least, also indicate the alternative treatment. Not necessarily. That's not how it works in Pascal and Algol. In the case of Algol, argument passing is pass-by-name unless declared otherwise. In the case of Pascal, expressions are always evaluated first (pass-by- value), except for one special case: if the expression consists of a single name, AND the function declares the parameter to be a "var" parameter, Pascal uses pass-by-reference, which you can think of as conceptually like a cut-down restricted version of pass-by-name. But the point is that the decision whether to evaluate the expression immediately or not could be up to the compiler, not the caller. In fact, that's what Python already does: mylist and mylist[0] always delays evaluation of the second clause, the caller doesn't have to do anything special except to ensure she writes them in the right order. The problem with the Pascal approach, where the function declares what calling mechanism to use, is that this needs the function to be known at compile time so that the compiler knows what mechanism to use to pass the argument into the function. As far as I know, the languages which offer a choice of calling convention (Pascal, Basic?) have static function declarations known at compile-time. I'm not sure about Perl. Anyway, the point is that in principle there is another mechanism: the compiler knows whether to delay evaluation or not, and the caller has no say in it. > There are, broadly, two possibilities: > 2a. Use a generic quotation mechanism that can be applied to any > expression most any place. I call this explicit quoting. Skipping ahead: > Python has 2 pairs of generic explicit delimiters: open-close quote > marks and lambda-, where is ',', ')', > , or maybe something else. If these are not present, the > default immediate execution mode is used for expressions in function > calls that are not themselves marked for alternative treatment. I think that's a misuse of terminology and badly missing the point. If you have to *manually* manage this process yourself, by writing a function, or calling eval() on a string, it's not a feature of the language. Saying that Python has a generic mechanism for delaying execution of an expression ("put it in a function, or use a string and eval() the string later") is like saying that C has garbage collection ("just keep track of which pointers you are or aren't using yourself"). Given the lack of such delayed execution, a reasonable work-around may sometimes be to use a function. But it's not the same. If language features weren't important, we'd all be using FORTRAN I exactly as it was in the 1950s. > 2b. Use the > expression in a special form that the compiler knows about. The special > form must have begin-end markers of some sort. That's incorrect, unless you think "Start Of Expression" and "End Of Expression" are markers. > I call this implicit > quoting. If human readers do not know that a particular form is a > special form, they may have a problem understanding the code. Um, yes? If you don't know the semantics of the language you are reading, any language, you're going to have trouble understanding it. If I see: mylist = [1, 2, 3, 4, 5]*10000000 for i in range(30): print function(mylist, i) and I don't know how Python works, I might say "ZOMG! That has to walk a fifty-million item linked list thirty times, copying it each time it is passed to the function! How inefficient!". And I would be wrong. We're allowed to suppose that Python programmers are aware that lists aren't linked-lists, and that passing a list to a function does not copy it. We're allowed to suppose that Python programmers know that the 1/x expression in `1/x if x != 0 else y` is not evaluated unless x is non- zero. If there is a syntactic form that delays evaluation, like and/or delay evaluation, we're allowed to presume the programmer knows that this is what it does. > Python's special forms are statements. Each has its own pair of > delimiters. Assignments use and '='. 'For' loops use > 'for' and 'in'. Other statements use 'as' and usually . Not always. You've missed ternary if, and, or, list comprehensions and generator expressions, all of which are expressions, not statements. Python can delay execution of an expression within another expression. It's just that so far, they have to be specially treated by the compiler. There's no generic mechanism for this. > Statements and functions call are syntactically very distinct, so there > is little possibility of confusion. I consider this a major feature of > python and I would oppose breaking it. I'm not sure if this is relevant or not. > Lisp, for instance, uses s-expressions for everything, including what > would either function calls or statements in Python. Special functions > implicitly quote some argument expressions, but not necessarily all, > while normal functions do not quote any. The only way to know is to > know, and I found it confusing and difficult to remember. > > > Sum(i, 1, 100, V[i]) > > In Algol60, this function call would: > > > - pass the name "i" (not a string!) as the first argument; - pass 1 > > as the second argument; > > - pass 100 as the third argument; > > - pass the expression "V[i]" (not a string!) as the fourth argument > > which depends for this operation on > > > https://en.wikipedia.org/wiki/Jensen%27s_device > > I read the whole article, including the criticisms and the fact that it > was not widely adopted and has been more or less superceded by macros. > It did not answer the obvious question: suppose the call is Sum(i, l, h, > V[i]). How is the reader supposed to know that 'i' and 'V[i]' get quoted > and the other args do not? They infer it from the usage. (Python example: given that you can write "mylist and mylist[0]", and it does not raise IndexError when mylist is empty, so we can infer that the second term "mylist[0]" is not evaluated unless the first is true.) Or they read the docs of the Sum function. Or both. > The article included > > real procedure Sum(k, l, u, ak) > value l, u; > integer k, l, u; > real ak; > comment k and ak are passed by name; > begin > real s; > s := 0; > for k := l step 1 until u do > s := s + ak; > Sum := s > end; > > If that is supposed to be real code that can be compiled, I see no way > for the comment to be true. Or is the mechanism limited to builtin > functions? Pass-by-name is the default argument passing mechanism in Algol 60. The middle two parameters, l and u, are declared as pass-by-value in the second line. That means that k and ak use the default mechanism, which is pass by name. Because functions in Algol 60 are statically determined at compile time, the compiler now knows how to pass arguments into the Sum function. I don't know how you would do that in a language like Python where the function is not statically known at compile time. -- Steven D'Aprano http://import-that.dreamwidth.org/ From bjlockie at lockie.ca Wed Mar 26 23:23:29 2014 From: bjlockie at lockie.ca (James Smith) Date: Wed, 26 Mar 2014 20:23:29 -0700 (PDT) Subject: regex line by line over file Message-ID: I can't get this to work. It runs but there is no output when I try it on a file. #!/usr/bin/python import os import sys import re from datetime import datetime #logDir = '/nfs/projects/equinox/platformTools/RTLG/RTLG_logs'; #os.chdir( logDir ); programName = sys.argv[0] fileName = sys.argv[1] #pattern = re.compile('\s*\\"SHELF-.*,SC,.*,:\\"Log Collection In Progress\\"') re.M p = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"') l = ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"' # this works :-) m = p.match( l ) if m: print( l ) # this doesn't match anything (or the if doesn't work) :-( with open(fileName) as f: for line in f: # debug code (print the line without adding a linefeed) # sys.stdout.write( line ) if p.match(line): print(line) The test file just has one line: "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE" From rosuav at gmail.com Wed Mar 26 23:42:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 14:42:39 +1100 Subject: regex line by line over file In-Reply-To: References: Message-ID: On Thu, Mar 27, 2014 at 2:23 PM, James Smith wrote: > re.M > p = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"') If you're expecting this to be parsed as a multiline regex, it won't be. Probing re.M doesn't do anything on its own; you have to pass it as an argument to compile. Not sure if that's your problem or not, though. ChrisA From dan at tombstonezero.net Wed Mar 26 23:56:39 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 27 Mar 2014 03:56:39 +0000 (UTC) Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 27 Mar 2014 00:16:57 +0000, Steven D'Aprano wrote: > py> divmod(-30, 24) > (-2, 18) > > If an event happened 30 hours ago, it is correct to say that it > occurred "18 hours after 2 days ago", but who talks that way? Well, not *exactly*, but: If today happens to be Wednesday, and an event occurred last Friday, I might say "a week ago Friday." Similarly, today, I could also say "it'll be two years at my new job next month." For an event that occurred approximately 310 days ago, I might say "less than a year ago," and for an event that occurred approximately 350 days ago, I might say "a little less than a year ago." Or did you forget to put the winky there, and I fell for it? 11 years, 2 months, 26 days, 9 hours, 3 minutes, 27.4 seconds'ly yours, Dan From bjlockie at lockie.ca Thu Mar 27 00:14:03 2014 From: bjlockie at lockie.ca (James Smith) Date: Wed, 26 Mar 2014 21:14:03 -0700 (PDT) Subject: regex line by line over file In-Reply-To: References: Message-ID: On Wednesday, March 26, 2014 11:23:29 PM UTC-4, James Smith wrote: > I can't get this to work. > > It runs but there is no output when I try it on a file. > > > > > > #!/usr/bin/python > > > > import os > > import sys > > import re > > from datetime import datetime > > > > #logDir = '/nfs/projects/equinox/platformTools/RTLG/RTLG_logs'; > > #os.chdir( logDir ); > > > > programName = sys.argv[0] > > fileName = sys.argv[1] > > > > #pattern = re.compile('\s*\\"SHELF-.*,SC,.*,:\\"Log Collection In Progress\\"') > > re.M > > p = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"') > > l = ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"' > > > > # this works :-) > > m = p.match( l ) > > if m: > > print( l ) > > > > # this doesn't match anything (or the if doesn't work) :-( > > with open(fileName) as f: > > for line in f: > > # debug code (print the line without adding a linefeed) > > # sys.stdout.write( line ) > > if p.match(line): > > print(line) > > > > > > The test file just has one line: > > "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE" I tried the re.M in the compile and that didn't help. From rustompmody at gmail.com Thu Mar 27 00:37:35 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 26 Mar 2014 21:37:35 -0700 (PDT) Subject: regex line by line over file In-Reply-To: References: Message-ID: <3e8e2912-91a9-4762-aec6-fd89a77cc484@googlegroups.com> On Thursday, March 27, 2014 8:53:29 AM UTC+5:30, James Smith wrote: > I can't get this to work. > It runs but there is no output when I try it on a file. > #!/usr/bin/python > import os > import sys > import re > from datetime import datetime > #logDir = '/nfs/projects/equinox/platformTools/RTLG/RTLG_logs'; > #os.chdir( logDir ); > programName = sys.argv[0] > fileName = sys.argv[1] > #pattern = re.compile('\s*\\"SHELF-.*,SC,.*,:\\"Log Collection In Progress\\"') > re.M > p = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"') > l = ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"' > # this works :-) > m = p.match( l ) > if m: > print( l ) > # this doesn't match anything (or the if doesn't work) :-( > with open(fileName) as f: > for line in f: > # debug code (print the line without adding a linefeed) > # sys.stdout.write( line ) > if p.match(line): > print(line) > The test file just has one line: > "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE" Some suggestions (Im far from an re expert!) 1. Use raw strings for re's 2. You probably need non-greedy '*' (among other things) 3. Better to hack out your re in the interpreter For that 4. Avoid compile (at least while hacking) 5. Findall will show you whats happening better than match Heres a 'hack-session' from re import findall >>> l = ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"' # Start simple >>> findall(r'^\s',l) [' '] >>> findall(r'^\s*',l) [' '] >>> findall(r'^\s*"',l) [' "'] >>> findall(r'^\s*"SHELF-',l) [' "SHELF-'] >>> findall(r'^\s*"SHELF-.*',l) [' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:"Log Collection In Progress",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"'] >>> findall('^\s*"SHELF-.*',l) [' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:"Log Collection In Progress",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"'] >>> findall('^\s*"SHELF-.SC*',l) [] >>> findall('^\s*"SHELF-.*SC',l) [' "SHELF-17:LOG_COLN_IP,SC'] >>> findall('^\s*"SHELF-.*?SC',l) [' "SHELF-17:LOG_COLN_IP,SC'] >>> findall('^\s*"SHELF-.*?,SC',l) [' "SHELF-17:LOG_COLN_IP,SC'] >>> findall('(^\s*)"SHELF-.*?,SC',l) [' '] >>> findall('\(^\s*\)"SHELF-.*?,SC',l) [] >>> findall('(^\s*)"SHELF-.*?,SC',l) [' '] >>> findall('(^\s*)("SHELF-.*?,SC)',l) [(' ', '"SHELF-17:LOG_COLN_IP,SC')] From rosuav at gmail.com Thu Mar 27 00:41:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 15:41:31 +1100 Subject: regex line by line over file In-Reply-To: References: Message-ID: On Thu, Mar 27, 2014 at 3:14 PM, James Smith wrote: > I tried the re.M in the compile and that didn't help. Okay. Try printing out the repr of the line at the point where you have the commented-out write to stdout. That might tell you if there's some other difference. At that point, you'll know if the issue is with reading it from the file. Also, please either stop using Google Groups, or clean up its messes. I don't like having to read through piles of double-spaced junk in the quoted text. Thanks! ChrisA From rustompmody at gmail.com Thu Mar 27 01:02:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 26 Mar 2014 22:02:06 -0700 (PDT) Subject: Delayed evaluation of expressions In-Reply-To: <871txok29s.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <53314FC1.2010603@rece.vub.ac.be> <5331652c$0$29994$c3e8da3$5496439d@news.astraweb.com> <53319e60$0$29994$c3e8da3$5496439d@news.astraweb.com> <53321b7e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5332fae0$0$29994$c3e8da3$5496439d@news.astraweb.com> <9ad6730a-f2d9-42fe-a822-88db2916972b@googlegroups.com> <871txok29s.fsf@elektro.pacujo.net> Message-ID: <3dcf41ad-a036-4f51-af23-9672b7e71e40@googlegroups.com> On Thursday, March 27, 2014 4:15:19 AM UTC+5:30, Marko Rauhamaa wrote: > Chris Angelico : > > You prove here that Python has first-class expressions in the same way > > that 80x86 assembly language has garbage collection. Sure, you can > > implement it using the primitives you have, but that's not support. > I was more reminded of STL and Boost. For example: > std::for_each(v.begin(), v.end(), > ( > switch_statement( > _1, > case_statement<0>(std::cout << constant("zero")), > case_statement<1>(std::cout << constant("one")), > default_statement(cout << constant("other: ") << _1) > ), > cout << constant("\n") > ) > ); > ( le_in_details.html#lambda.switch_statement>) I must admit I have a hard time reading C++! However that link seems to be saying more or less what I am -- viz. lambda is a delay operator From steve at pearwood.info Thu Mar 27 01:32:03 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 27 Mar 2014 05:32:03 GMT Subject: regex line by line over file References: Message-ID: <5333b7d2$0$2756$c3e8da3$76491128@news.astraweb.com> On Wed, 26 Mar 2014 20:23:29 -0700, James Smith wrote: > I can't get this to work. > It runs but there is no output when I try it on a file. Simplify, simplify, simplify. Either you will find the problem, or you will find the simplest example that demonstrates the problem. In this case, the problem is that your regex is not matching what you expect it to match. So eliminate all the irrelevant cruft that is just noise, complicating the problem. Start with the simplest thing that works and add complexity until the problem returns. Eliminate the file. You can embed your data in a string, and try to match the regex against the string. Eliminate all the old commented-out code, that's just irrelevant. Eliminate reading from sys.argv, that has nothing to do with the problem. So we get down to this: import re pat = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"') line1 = ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"' print(pat.match(line1)) which matches. Now let's get rid of those leaning toothpicks. We can use print to see the repr() of the pattern, and a raw string to clean it up. At the interactive interpreter: py> print(pat.pattern) ^\s*"SHELF-.*,SC,.*,:\"Log Collection In Progress\" Similarly for line1. I'll also use implicit concatenation to split it over multiple source lines. Raw strings, r'' or r"", don't need to escape the backslashes. Implicit concatenation means that two strings with no operator between them is implicitly concatenated into a single string: 'abc' "def" becomes 'abcdef'. By putting the pieces inside parentheses, I can put each piece on a separate line, which makes it easier to read compared to one giant long line. pat = re.compile( r'^\s*"SHELF-.*,SC,.*,:\"Log Collection In Progress\"' ) line1 = ( ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:"' 'Log Collection In Progress",NONE:1700000035-6364-1048,:' 'YEAR=2014,MODE=NONE"' ) And at the interactive interpreter, I get a match: py> pat.match(line1) <_sre.SRE_Match object at 0xb721ad78> So now we move on to the content of the one-line file. I don't have access to the file, so all I have to go by is what you state it contains: [quote] The test file just has one line: "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE" [end quote] which I interpret like this: line2 = ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"\n' (note the newline at the end), or if you prefer: line2 = ( ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:"' 'Log Collection In Progress",NONE:1700000035-6364-1048,:' 'YEAR=2014,MODE=NONE"\n' ) Except for the newline, it equals line1, and it also matches the pattern: py> pat.match(line2) <_sre.SRE_Match object at 0xb721ab48> So now we know that the regex matches the data you think you have. The next questions are: - are you reading the right file? - are you mistaken about the content of the file? I can't help you with the first. But the second: try running this: # line2 and pat as defined above filename = sys.argv[1] with open(filename) as f: for line in f: print(len(line), line==line2, repr(line)) print(repr(pat.match(line))) which will show you what you have and whether or not it matches what you think it has. I expect that the file contents is not what you think it is, because the regex is matching the sample line. Good luck! -- Steven From ian.g.kelly at gmail.com Thu Mar 27 03:32:36 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 27 Mar 2014 01:32:36 -0600 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 25, 2014 at 7:36 AM, Steven D'Aprano wrote: > Yes, Python could have changed the meaning of {} to mean the empty set. > But you know what? The empty set is not that important. Sets are not > fundamental to Python. Python didn't even have sets until 2.3, and at > first they were just a standard library module, not even built-in. Dicts, > on the other hand, are fundamental to Python. They are used everywhere. > Python is, in a very real sense, built on dicts, not sets. You can > implement sets starting from dicts, but not the other way around: dicts > are more fundamental than sets. Challenge accepted! The _lookup method in the following is based on a recipe from Raymond Hettinger. from collections.abc import MutableMapping class SetBasedDict(MutableMapping): def __init__(self, initial, **kwargs): self._contents = set() self.update(initial, **kwargs) def clear(self): self._contents.clear() def __iter__(self): for item in self._contents: yield item.key def __len__(self): return len(self._contents) def __getitem__(self, key): item = self._lookup(key) if item is None: raise KeyError(key) return item.value def __setitem__(self, key, value): item = self._lookup(key) if item is not None: item.value = value else: item = _DictItem(key, value) self._contents.add(item) def __delitem__(self, key): self._contents.remove(_DictItem(key, None)) def _lookup(self, key): p = _DictSearchProxy(key) if p in self._contents: return p.match return None class _DictItem: def __init__(self, key, value): self.key = key self.value = value def __hash__(self): return hash(self.key) def __eq__(self, other): if not isinstance(other, _DictItem): return NotImplemented return self.key == other.key class _DictSearchProxy: def __init__(self, obj): self.obj = obj self.match = obj def __eq__(self, other): if not isinstance(other, _DictItem): return NotImplemented result = (self.obj == other.key) if result: self.match = other return result def __hash__(self): return hash(self.obj) From ian.g.kelly at gmail.com Thu Mar 27 03:43:41 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 27 Mar 2014 01:43:41 -0600 Subject: Time we switched to unicode? (was Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <0b78649a-16b3-4410-8258-e859578d62be@googlegroups.com> <53060a97-44fb-4e53-a7a7-d5eeed416f62@googlegroups.com> <53318664$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 27, 2014 at 1:32 AM, Ian Kelly wrote: > On Tue, Mar 25, 2014 at 7:36 AM, Steven D'Aprano > wrote: >> Yes, Python could have changed the meaning of {} to mean the empty set. >> But you know what? The empty set is not that important. Sets are not >> fundamental to Python. Python didn't even have sets until 2.3, and at >> first they were just a standard library module, not even built-in. Dicts, >> on the other hand, are fundamental to Python. They are used everywhere. >> Python is, in a very real sense, built on dicts, not sets. You can >> implement sets starting from dicts, but not the other way around: dicts >> are more fundamental than sets. > > Challenge accepted! Oops, I forgot to allow for a 0-argument constructor. Please revise the SetBasedDict.__init__ method to: def __init__(self, initial=(), **kwargs): self._contents = set() if initial or kwargs: self.update(initial, **kwargs) From breamoreboy at yahoo.co.uk Thu Mar 27 04:40:25 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 27 Mar 2014 08:40:25 +0000 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27/03/2014 01:38, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Thu, Mar 27, 2014 at 11:16 AM, Steven D'Aprano >> wrote: >>> If an event happened 30 hours ago, it is correct to say that it occurred >>> "18 hours after 2 days ago", but who talks that way? >> >> That response demonstrates real genius. Rue the datetime? Who talks like that? > > "I had a dangling pointer error, and blew my stack to half past last > wednesday" > IIRC the Germans (possibly amongst others) would say that as half to last thursday, or is that thurstag? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From antoon.pardon at rece.vub.ac.be Thu Mar 27 05:36:02 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 27 Mar 2014 10:36:02 +0100 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> Message-ID: <5333F102.1030309@rece.vub.ac.be> On 26-03-14 17:37, Ian Kelly wrote: > On Wed, Mar 26, 2014 at 2:52 AM, Antoon Pardon > wrote: >> Of course we don't have to follow mathematical convention with python. However allowing any >> unicode symbol as an identifier doesn't prohibit from using ? as an operator. We do have >> "in" and "is" as operators now, even if they would otherwise be acceptable identifiers. >> So I wonder, would you consider to introduce log as an operator. 2 log x seems an interesting >> operation for a programmer. > If it's going to become an operator, then it has to be a keyword. > Changing a token that is currently allowed to be an identifier into a > keyword is generally avoided as much as possible, because it breaks > backward compatibility. "in" and "is" have both been keywords for a > very long time, perhaps since the initial release of Python. I know, for such a reason I would love it if keywords would have been written like this: ??? (using mathematical bold) instead of just like this: def (using plain latin letters). It would mean among other things we could just write operator.not instead of having to write operator.not_ -- Antoon Pardon From michael at stroeder.com Mon Mar 24 06:26:14 2014 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Mon, 24 Mar 2014 11:26:14 +0100 Subject: ANN: python-ldap 2.4.15 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.15 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.15 2014-03-24 Changes since 2.4.14: Lib/ * Added missing modules ldap.controls.openldap and ldap.controls.pwdpolicy to setup.py * Added missing imports to ldap.controls.pwdpolicy * Fixed ldap.controls.pwdpolicy.decodeControlValue() to decode string of digits * Support for X-SUBST in schema element class LDAPSyntax * Support for X-ORDERED and X-ORIGIN in schema element class AttributeType * ldapurl: New scope 'subordinates' defined in draft-sermersheim-ldap-subordinate-scope Modules/ * New constant ldap.SCOPE_SUBORDINATE derived from ldap.h for draft-sermersheim-ldap-subordinate-scope * Fixed constant ldap.sasl.CB_GETREALM (thanks to Martin Pfeifer) From dfnsonfsduifb at gmx.de Thu Mar 27 06:09:13 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 27 Mar 2014 11:09:13 +0100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: Message-ID: On 26.03.2014 10:53, Jean-Michel Pichavant wrote: > Note : I don't see what's wrong in your example, however I have the feeling the term "stupiditie" is a little bit strong ;) The problem is that for a given timedelta t with t > 0 it is intuitive to think that its string representation str(t) would follow the rule "-" + str(t) == str(-t) But it doesn't. > -- IMPORTANT NOTICE: > > The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. I hereby inform you that I - probably by accident received your very confidential and privileged message! All hardware has already been thrown into the incinerator, is that good enough for you? Or do I have to fulfill some ISO-9001 certified privileged mail destruction procedure? Please advise on how I shall continue my life. Cheers, Johannes IMPORTANT NOTICE: If you write mails to newsgroups with a ridiculous confidentiality footer, you are obliged under section 14.9a of the Imbecile Act to take a blunt object of no less than 12 kg weight and hit yourself repeatedly in the head until the email footer disappears. Failure to comply might lead to criminal prosecution and/or permanent constipation! Thank you. -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From dfnsonfsduifb at gmx.de Thu Mar 27 06:22:27 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 27 Mar 2014 11:22:27 +0100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27.03.2014 01:16, Steven D'Aprano wrote: > py> divmod(30, 24) > (1, 6) > > That makes perfect intuitive sense: 30 hours is 1 day with 6 hours > remaining. In human-speak, we'll say that regardless of whether the > timedelta is positive or negative: we'll say "1 day and 6 hours from now" > or "1 day and 6 hours ago". But when we specify the sign: > > py> divmod(-30, 24) > (-2, 18) > > If an event happened 30 hours ago, it is correct to say that it occurred > "18 hours after 2 days ago", but who talks that way? Well, no matter how timedeltas internal representation is and if they use modular division or (they probably do, I agree) this shouldn't affect the display at all. Internally they can use any arbitrary representation, but for the external representation I think a very sane requirement should be that for a given timedelta t with t > 0 it is its string representation str(t) would satisfy: "-" + str(t) == str(-t) Besides, there's an infinite amount of (braindead) timedelta string representations. For your -30 hours, it is perfectly legal to say 123 days, -2982 hours Yet Python doesn't (but chooses an equally braindead representation). Where can I enter a PIP that proposes that all timedelta strings are fixed at 123 days (for positive, non-prime amount of seconds) and fixed at -234 days (for all negative or positive prime amount of seconds)? Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From rosuav at gmail.com Thu Mar 27 06:44:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 21:44:09 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 27, 2014 at 9:22 PM, Johannes Bauer wrote: > Besides, there's an infinite amount of (braindead) timedelta string > representations. For your -30 hours, it is perfectly legal to say > > 123 days, -2982 hours > > Yet Python doesn't (but chooses an equally braindead representation). It's not "equally braindead", it follows a simple and logical rule: Only the day portion is negative. That might not be perfectly suited to all situations, but it does mean that adding and subtracting whole days will never change the representation of the time. That's a reasonable promise. What you propose is completely arbitrary, and yes it WOULD be braindead to have str() return that (although of course this should be accepted as input). > Where can I enter a PIP that proposes that all timedelta strings are > fixed at 123 days (for positive, non-prime amount of seconds) and fixed > at -234 days (for all negative or positive prime amount of seconds)? > Doesn't need a PEP. Just subclass it or monkey-patch it and use it as you will. :) ChrisA From dfnsonfsduifb at gmx.de Thu Mar 27 07:05:09 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 27 Mar 2014 12:05:09 +0100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27.03.2014 11:44, Chris Angelico wrote: > On Thu, Mar 27, 2014 at 9:22 PM, Johannes Bauer wrote: >> Besides, there's an infinite amount of (braindead) timedelta string >> representations. For your -30 hours, it is perfectly legal to say >> >> 123 days, -2982 hours >> >> Yet Python doesn't (but chooses an equally braindead representation). > > It's not "equally braindead", it follows a simple and logical rule: > Only the day portion is negative. That might not be perfectly suited > to all situations, but it does mean that adding and subtracting whole > days will never change the representation of the time. That's a > reasonable promise. Why would the stability of the *string* output of the time representation be of any interest whatsoever? Do you have any even halfways reasonable usecase for that? > What you propose is completely arbitrary, No. What I propose is that for t > 0 this holds: "-" + str(t) == str(-t) Which is far from arbitrary. It follows "natural" rules of inverting something (-abs(x) == -x), and it yields a (truly) human-readable form of showing a timedelta. Please don't mix this up with the very apparent braindead proposal of mine. In case you didn't notice, this was irony at work. The word "braindead" I chose to describe the format should have tipped you off to that. >> Where can I enter a PIP that proposes that all timedelta strings are >> fixed at 123 days (for positive, non-prime amount of seconds) and fixed >> at -234 days (for all negative or positive prime amount of seconds)? > > Doesn't need a PEP. Just subclass it or monkey-patch it and use it as > you will. :) Nonono, you misunderstand: I want everyone to suffer under the braindead representation, just as it is now! Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From dfnsonfsduifb at gmx.de Thu Mar 27 07:25:56 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 27 Mar 2014 12:25:56 +0100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27.03.2014 11:44, Chris Angelico wrote: > It's not "equally braindead", it follows a simple and logical rule: > Only the day portion is negative. The more I think about it, the sillier this rule seems to me. A timedelta is a *whole* object. Either the whole delta is negative or it is not. It doesn't make sense to split it up in two parts and arbitrarily define one to be always nonnegative and the other to have no restrictions. The only locical reasoning behind this could be to argue that "-2 days" makes more sense than "-15 minutes". Which it doesn't. Worse: Negating a timedelta (which I would argue is a fairly common operation) makes the whole thing unstable representation-wise: >>> str(datetime.timedelta(2, 30)) '2 days, 0:00:30' >>> str(-datetime.timedelta(2, 30)) '-3 days, 23:59:30' And it makes it extremely error-prone to the reader: >>> str(datetime.timedelta(0, -1)) '-1 day, 23:59:59' This looks MUCH more like "almost two days ago" than '-00:00:01' does. In any case, the str() function is *only* about the representation that can be read by humans. Therefore its highest priority should be to output something that can, in fact, be easily parsed by humans. The current format is nothing of the sort. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From rosuav at gmail.com Thu Mar 27 07:33:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 22:33:55 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 27, 2014 at 10:05 PM, Johannes Bauer wrote: > On 27.03.2014 11:44, Chris Angelico wrote: >> On Thu, Mar 27, 2014 at 9:22 PM, Johannes Bauer wrote: >>> Besides, there's an infinite amount of (braindead) timedelta string >>> representations. For your -30 hours, it is perfectly legal to say >>> >>> 123 days, -2982 hours >>> >>> Yet Python doesn't (but chooses an equally braindead representation). >> >> It's not "equally braindead", it follows a simple and logical rule: >> Only the day portion is negative. That might not be perfectly suited >> to all situations, but it does mean that adding and subtracting whole >> days will never change the representation of the time. That's a >> reasonable promise. > > Why would the stability of the *string* output of the time > representation be of any interest whatsoever? Do you have any even > halfways reasonable usecase for that? > >> What you propose is completely arbitrary, > > No. What I propose is that for t > 0 this holds: > > "-" + str(t) == str(-t) > > Which is far from arbitrary. When you said "equally braindead", I took that as indicating that the current representation is as braindead as "123 days, -2982 hours". My point is that it's not as arbitrary as that. Your "real proposal", if you like, is arguably better; but I'm just saying that the current one isn't arbitrary. > It follows "natural" rules of inverting > something (-abs(x) == -x), and it yields a (truly) human-readable form > of showing a timedelta. > > Please don't mix this up with the very apparent braindead proposal of > mine. In case you didn't notice, this was irony at work. The word > "braindead" I chose to describe the format should have tipped you off to > that. Yes, I knew that that was irony. I was taking argument with your declaration that the current form is just as bad. Taking it to a different type: The repr() of a string tries to be short, where possible, by using either single or double quotes, but won't use a raw representation, nor triple-quoted: >>> ' \' ' " ' " >>> " \" " ' " ' >>> ' \"\'\"\'\"\'\"\' ' ' "\'"\'"\'"\' ' >>> " \"\'\"\'\"\'\"\' " ' "\'"\'"\'"\' ' >>> ''' "'"'"'"' ''' ' "\'"\'"\'"\' ' >>> r' \\\\\\\\\\\\\\ ' ' \\\\\\\\\\\\\\\\\\\\\\\\\\\\ ' You could argue that representing a string as raw or triple-quoted would be "more correct", and yet the current repr is not arbitrary. The current form is not actively bad, even if it would be possible to find something better. >>> Where can I enter a PIP that proposes that all timedelta strings are >>> fixed at 123 days (for positive, non-prime amount of seconds) and fixed >>> at -234 days (for all negative or positive prime amount of seconds)? >> >> Doesn't need a PEP. Just subclass it or monkey-patch it and use it as >> you will. :) > > Nonono, you misunderstand: I want everyone to suffer under the braindead > representation, just as it is now! Oh, absolutely! In that case, just slip a patch into the next point release; people won't mind that changing in 3.4.1! ChrisA From rosuav at gmail.com Thu Mar 27 07:42:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 22:42:26 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 27, 2014 at 10:25 PM, Johannes Bauer wrote: > And it makes it extremely error-prone to the reader: > >>>> str(datetime.timedelta(0, -1)) > '-1 day, 23:59:59' > > This looks MUCH more like "almost two days ago" than > > '-00:00:01' > > does. It's easy when the timedelta is >-1 day. Is it as clear when it's further negative? In any case... what I'd suggest would be opening a tracker issue, or discussing this on python-ideas, and seeing what core devs think of the matter. I think that, on balance, it's probably better to show the whole thing with the same sign; but should it be: >>> str(datetime.timedelta(-1, -1)) '-1 day, 00:00:01' or should the hyphen be repeated: >>> str(datetime.timedelta(-1, -1)) '-1 day, -00:00:01' ? How does it read in a larger expression? All this bikeshedding, and more, available gratis on python-ideas. :) ChrisA From skip at pobox.com Thu Mar 27 07:56:34 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 27 Mar 2014 06:56:34 -0500 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: I took a moment to scan the datetime documentation. The behavior of str() on timedelta objects is very consistent, and matches the internal representation. From the docs: str(t) Returns a string in the form [D day[s], ][H]H:MM:SS[.UUUUUU], where D is negative for negative t. (5) Note (5) reads: String representations of timedelta objects are normalized similarly to their internal representation. This leads to somewhat unusual results for negative timedeltas. Feel free to submit a patch to improve str(t), where t is negative, though as Chris suggested, hashing this out on python-ideas would be a good idea. I suggest you start with some concrete examples. There are, as I see it, two common cases where t is negative: -1 day < t < 0 and t <= -1 day Skip From rosuav at gmail.com Thu Mar 27 08:20:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Mar 2014 23:20:30 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 27, 2014 at 10:56 PM, Skip Montanaro wrote: > There are, > as I see it, two common cases where t is negative: > > -1 day < t < 0 > > and > > t <= -1 day There are two types of negative numbers: Those closer to zero than -1, and those not closer to zero than -1. Yeah, I think those are the most common cases. :) ChrisA From roy at panix.com Thu Mar 27 08:52:24 2014 From: roy at panix.com (Roy Smith) Date: Thu, 27 Mar 2014 08:52:24 -0400 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On Thu, Mar 27, 2014 at 9:22 PM, Johannes Bauer wrote: > > Besides, there's an infinite amount of (braindead) timedelta string > > representations. For your -30 hours, it is perfectly legal to say > > > > 123 days, -2982 hours > > > > Yet Python doesn't (but chooses an equally braindead representation). In article , Chris Angelico wrote: > It's not "equally braindead", it follows a simple and logical rule: > Only the day portion is negative. Simple and logical, yes. But also entirely braindead. > That might not be perfectly suited to all situations Give ma a real-life situation where you would want such behavior. > What you propose is completely arbitrary, and yes > it WOULD be braindead to have str() return that Chris, I believe you need to have your sarcasm detection circuitry recalibrated :-) From skip at pobox.com Thu Mar 27 09:01:39 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 27 Mar 2014 08:01:39 -0500 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> There are, >> as I see it, two common cases where t is negative: >> >> -1 day < t < 0 >> >> and >> >> t <= -1 day > > There are two types of negative numbers: Those closer to zero than -1, > and those not closer to zero than -1. Yeah, I think those are the most > common cases. :) Sorry I wasn't clear. I see two cases w.r.t. *display*, those where you need to display the number of days back (possibly accounting for even larger time intervals to make it more human readable), those where you don't. Yes, as you observed, they completely cover the negative timedelta space with two non-overlapping intervals. Roy's original rant was about how a negative timedelta was stringified, when what he seemed to care about was mostly the time interval between now and the previous sunset (which will be less than a day, unless your day length is advancing -- between the winter and summer solstices -- and you compute that interval a few seconds before sunset). The common "how long ago was sunset?" (|delta| < 1 day) case is handled just fine by my little negate-the-timedelta hack, e.g.: >>> "-%s" % (-datetime.timedelta(hours=-17, minutes=-12, seconds=-25.234)) '-17:12:25.234000' Negative timedeltas with a magnitude of one day or more require something else, perhaps like the ISO8601 duration stuff (which I personally find distasteful, but that might be the best you can do in the absence of an anchor datetime). Skip From bjlockie at lockie.ca Thu Mar 27 09:41:55 2014 From: bjlockie at lockie.ca (James Smith) Date: Thu, 27 Mar 2014 06:41:55 -0700 (PDT) Subject: regex line by line over file In-Reply-To: <5333b7d2$0$2756$c3e8da3$76491128@news.astraweb.com> References: <5333b7d2$0$2756$c3e8da3$76491128@news.astraweb.com> Message-ID: <87d43f6b-8b16-4b20-8ab0-d665acac9da6@googlegroups.com> On Thursday, March 27, 2014 1:32:03 AM UTC-4, Steven D'Aprano wrote: > - are you mistaken about the content of the file? > > I can't help you with the first. But the second: try running this: > > # line2 and pat as defined above > filename = sys.argv[1] > with open(filename) as f: > for line in f: > print(len(line), line==line2, repr(line)) > print(repr(pat.match(line))) > > which will show you what you have and whether or not it matches > what you think it has. I expect that the file contents is not what > you think it is, because the regex is matching the sample line. > > Good luck! > > -- > > Steven It should match this: (134, False, '\' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\\\\"Log Collection In Progress\\\\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"\\r\\n\'') Is the \r\n on the end of the line screwing it up? From marko at pacujo.net Thu Mar 27 10:04:04 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 27 Mar 2014 16:04:04 +0200 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87txajwxez.fsf@elektro.pacujo.net> Skip Montanaro : > Feel free to submit a patch to improve str(t), where t is negative, The cat's out of the bag already, isn't it? Marko From antoon.pardon at rece.vub.ac.be Thu Mar 27 10:12:31 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 27 Mar 2014 15:12:31 +0100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533431CF.6020102@rece.vub.ac.be> On 27-03-14 13:52, Roy Smith wrote: >> On Thu, Mar 27, 2014 at 9:22 PM, Johannes Bauer wrote: >>> Besides, there's an infinite amount of (braindead) timedelta string >>> representations. For your -30 hours, it is perfectly legal to say >>> >>> 123 days, -2982 hours >>> >>> Yet Python doesn't (but chooses an equally braindead representation). > > In article , > Chris Angelico wrote: >> It's not "equally braindead", it follows a simple and logical rule: >> Only the day portion is negative. > Simple and logical, yes. But also entirely braindead. That you don't have a use for it and don't like it doesn't make it brain dead. >> That might not be perfectly suited to all situations > Give ma a real-life situation where you would want such behavior. What good would that do? The fact that someone else could give a real-life situation where they wanted that, wouldn't mean that you would recognize it as a situation where you wanted it, and so you could still call it brain dead. I don't recall specifics, but I do remember multiple times where I was working with a structure that consisted of a whole part and a fracture part where I found it useful to have the fracture part always positive and displayed as such. Your background is obviously different and you don't like it. Fine, that doesn't make it brain dead. -- Antoon Pardon From rosuav at gmail.com Thu Mar 27 10:15:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 01:15:19 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <533431CF.6020102@rece.vub.ac.be> References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <533431CF.6020102@rece.vub.ac.be> Message-ID: On Fri, Mar 28, 2014 at 1:12 AM, Antoon Pardon wrote: > I don't recall specifics, but I do remember multiple times > where I was working with a structure that consisted of > a whole part and a fracture part where I found it useful > to have the fracture part always positive and displayed > as such. One has already been shared in this thread: Logarithms, where the part before the decimal is the scale and the part after the decimal is the mantissa. Makes very good sense to negate the first without changing the second. ChrisA From rustompmody at gmail.com Thu Mar 27 11:10:08 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 27 Mar 2014 08:10:08 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> Message-ID: On Thursday, March 27, 2014 3:06:02 PM UTC+5:30, Antoon Pardon wrote: > On 26-03-14 17:37, Ian Kelly wrote: > > On Wed, Mar 26, 2014 at 2:52 AM, Antoon Pardon > >> Of course we don't have to follow mathematical convention with python. However allowing any > >> unicode symbol as an identifier doesn't prohibit from using ? as an operator. We do have > >> "in" and "is" as operators now, even if they would otherwise be acceptable identifiers. > >> So I wonder, would you consider to introduce log as an operator. 2 log x seems an interesting > >> operation for a programmer. > > If it's going to become an operator, then it has to be a keyword. > > Changing a token that is currently allowed to be an identifier into a > > keyword is generally avoided as much as possible, because it breaks > > backward compatibility. "in" and "is" have both been keywords for a > > very long time, perhaps since the initial release of Python. > I know, for such a reason I would love it if keywords would have been > written like this: ??? (using mathematical bold) instead of just like > this: def (using plain latin letters). It would mean among other things > we could just write operator.not instead of having to write operator.not_ Just out of curiosity how do/did you type that? When I see an exotic denizen from the unicode-universe I paste it into emacs and ask "Who are you?" But with your 'def' my emacs is going a bit crazy! From python.list at tim.thechases.com Thu Mar 27 11:34:04 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 27 Mar 2014 10:34:04 -0500 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> Message-ID: <20140327103404.3fd45743@bigbox.christie.dr> On 2014-03-27 08:10, Rustom Mody wrote: > > I know, for such a reason I would love it if keywords would have > > been written like this: ??? (using mathematical bold) instead of > > just like this: def (using plain latin letters). It would mean > > among other things we could just write operator.not instead of > > having to write operator.not_ > > Just out of curiosity how do/did you type that? > When I see an exotic denizen from the unicode-universe I paste it > into emacs and ask "Who are you?" > > But with your 'def' my emacs is going a bit crazy! I have the following in a file, which I can then open with Vim. I just type the text I want above the corresponding row of capital letters and execute the statement on the first line. Vim then populates the system clipboard with the corresponding letters in the Unicode font. I'm sure there are font-translator pages that would make it a little easier, but I'd already done this. Just adjust for Emacs ;-) -tkc let @+=join(map(split(getline('.'), '\zs'), 'matchstr(getline(line(".")+((v:val >= "A" && v:val <= "Z")?1:2)), ".\\{".(char2nr(tolower(v:val))-char2nr("a"))."}\\zs.")'),'') ABCDEFGHIJKLMNOPQRSTUVWXYZ ASCII upper abcdefghijklmnopqrstuvwxyz ASCII lower ?????????????????????????? bold serif upper ?????????????????????????? bold serif lower ?????????????????????????? italic serif upper ?????????????????????????? italic serif lower ?????????????????????????? bold italic serif upper ?????????????????????????? bold italic serif lower ?????????????????????????? script upper ?????????????????????????? script lower ?????????????????????????? fraktur upper ?????????????????????????? fraktur lower ?????????????????????????? fraktur bold upper ?????????????????????????? fraktur bold lower ?????????????????????????? hollow upper ?????????????????????????? hollow lower ?????????????????????????? sans upper ?????????????????????????? sans lower ?????????????????????????? bold sans upper ?????????????????????????? bold sans lower ?????????????????????????? italic sans upper ?????????????????????????? italic sans lower ?????????????????????????? bold italic sans upper ?????????????????????????? bold italic sans lower ?????????????????????????? mono upper ?????????????????????????? mono lower ?????????? bold serif ?????????? hollow ?????????? sans ?????????? sans bold ?????????? mono From harrismh777 at gmail.com Thu Mar 27 11:28:51 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 10:28:51 -0500 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/25/14 6:58 PM, Steven D'Aprano wrote: > To quote a great Spaniard: > > ?You keep using that word, I do not think it means what you > think it means.? In~con~theveable ! My name is Inigo Montoya, you killed my father, prepare to die... > Do you think that the ability to write this would be an improvement? > > import ? > ? = ?.?? > ? = 5*?.?? > ? = ? - 1 > ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] > ?.??????(???) Steven, you're killing me here; argument by analogy does not work! ? = lambda n: sqrt(n) <===== but this should work... In point of fact, it should be built-in ! OK, IMHO. > Of course, it's not even necessary to be that exotic. "Any unicode symbol > that is not a number"... that means things like these: No, any unicode character (except numerals) should be able to begin a name identifier. alt-l ? and alt-v ? should be valid first character name identifier symbols. > There are languages that can allow arbitrary symbols as identifiers, like > Lisp and Forth. You will note that they have a certain reputation for > being, um, different, and although both went through periods of > considerable popularity, both have faded in popularity since. Actually, there is a recent resurgence of popularity in both common lisp and scheme these days. But, again, that has nothing to do with my argument. No modern language should limit the use of certain symbols to say, only math ? . The radical symbol is more often than not going to be useful only with math (which , by the way is why it should be built-in as ? = squre-rooot) but why limit its use elsewhere. Whether this can work in python is also beside the point, because I'm not demanding anything here either, at this point. have a good day! marcus From bjlockie at lockie.ca Thu Mar 27 11:44:44 2014 From: bjlockie at lockie.ca (James Smith) Date: Thu, 27 Mar 2014 08:44:44 -0700 (PDT) Subject: regex line by line over file In-Reply-To: <87d43f6b-8b16-4b20-8ab0-d665acac9da6@googlegroups.com> References: <5333b7d2$0$2756$c3e8da3$76491128@news.astraweb.com> <87d43f6b-8b16-4b20-8ab0-d665acac9da6@googlegroups.com> Message-ID: <681ec23b-beb4-4191-8605-8be377afb07f@googlegroups.com> On Thursday, March 27, 2014 9:41:55 AM UTC-4, James Smith wrote: > (134, False, '\' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\\\\"Log Collection In Progress\\\\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"\\r\\n\'') > > > > Is the \r\n on the end of the line screwing it up? Got it. I needed an extra \ where I had 3 in the compile. It's kinda weird it didn't need the extra \ when I ran it manually from the shell. From harrismh777 at gmail.com Thu Mar 27 11:44:49 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 10:44:49 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/26/14 1:35 AM, alex23 wrote: > On 25/03/2014 12:39 PM, Mark H Harris wrote: >> my version semantically is "how it is perceived" by the user > > Could you please stop claiming to have insight into the comprehension of > anyone other than yourself? Hasty generalisations don't help your argument. hi alex23, please don't be silly. Who is being hasty? How do you know its a generalization? My comments here are not in the least hasty, nor are they generalizations. They are based on long years of experience with "normal" users, personal programming experience for almost 40 years, and insight into student perception from reader comment forms, evaluations, personal discussions. (sometimes from this list mind you) It is *always* pertinent to ask, "how will this be perceived by the user," ehem, going all the why back to Immanuel Kant who was the first person (philosopher) to suggest that perception is reality. Frankly, most of the time when I "claim" to have comprehension from someone other than myself its coming up with the answer to that stellar question (often in context with community discussion). This all amounts to a value add (intelligence) for community, and for comp sci. Thinking out-loud about community perception is always valid. marcus From ppearson at nowhere.invalid Thu Mar 27 11:49:02 2014 From: ppearson at nowhere.invalid (Peter Pearson) Date: 27 Mar 2014 15:49:02 GMT Subject: regex line by line over file References: <5333b7d2$0$2756$c3e8da3$76491128@news.astraweb.com> <87d43f6b-8b16-4b20-8ab0-d665acac9da6@googlegroups.com> Message-ID: On Thu, 27 Mar 2014 06:41:55 -0700 (PDT), James Smith wrote: > On Thursday, March 27, 2014 1:32:03 AM UTC-4, Steven D'Aprano wrote: > >> - are you mistaken about the content of the file? >> >> I can't help you with the first. But the second: try running this: >> >> # line2 and pat as defined above >> filename = sys.argv[1] >> with open(filename) as f: >> for line in f: >> print(len(line), line==line2, repr(line)) >> print(repr(pat.match(line))) >> >> which will show you what you have and whether or not it matches >> what you think it has. I expect that the file contents is not what >> you think it is, because the regex is matching the sample line. >> >> Good luck! >> >> -- >> >> Steven > > It should match this: > (134, False, '\' "SHELF-17:LOG[snip]MODE=NONE"\\r\\n\'') > > Is the \r\n on the end of the line screwing it up? Dude, you've gotten a lot of excellent advice from some extraordinarily capable (and patient) people, and you appear to be ignoring it. -- To email me, substitute nowhere->spamcop, invalid->net. From rustompmody at gmail.com Thu Mar 27 11:51:39 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 27 Mar 2014 08:51:39 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e0ffd3a-8c50-4726-b214-f7b44d4e01ae@googlegroups.com> On Thursday, March 27, 2014 8:58:51 PM UTC+5:30, Mark H. Harris wrote: > On 3/25/14 6:58 PM, Steven D'Aprano wrote: > > To quote a great Spaniard: > > ?You keep using that word, I do not think it means what you > > think it means.? > In~con~theveable ! My name is Inigo Montoya, you killed my > father, prepare to die... > > Do you think that the ability to write this would be an improvement? > > import ? > > ? = ?.?? > > ? = 5*?.?? > > ? = ? - 1 > > ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] > > ?.??????(???) > Steven, you're killing me here; argument by analogy does not work! > ? = lambda n: sqrt(n) <===== but this should work... > In point of fact, it should be built-in ! OK, IMHO. > > Of course, it's not even necessary to be that exotic. "Any unicode symbol > > that is not a number"... that means things like these: > No, any unicode character (except numerals) should be able to begin a > name identifier. alt-l ? and alt-v ? should be valid first > character name identifier symbols. > > There are languages that can allow arbitrary symbols as identifiers, like > > Lisp and Forth. You will note that they have a certain reputation for > > being, um, different, and although both went through periods of > > considerable popularity, both have faded in popularity since. > Actually, there is a recent resurgence of popularity in both common > lisp and scheme these days. But, again, that has nothing to do with my > argument. No modern language should limit the use of certain symbols to > say, only math ? . The radical symbol is more often than not going > to be useful only with math (which , by the way is why it should be > built-in as ? = squre-rooot) but why limit its use elsewhere. > Whether this can work in python is also beside the point, because > I'm not demanding anything here either, at this point. > have a good day! The problem is that mathematicians invent notations in a completely laissez-faire manner. Language implementers having to unrestrainedly keep up would go mad. And then us vanilla users (aka programmers) would have to deal with maddened implementers. Observe: Good ol infix -- x+y.. prefix (with paren) -- foo(x) prefix without -- ? x In case you thought alphanumerics had parens -- sin x Then theres postfix -- n! Inside fix -- nCr (Or if you prefer ?C? ??) And outside fix -- mod -- |x| And Ive probably forgotten 2 dozen other common ones From harrismh777 at gmail.com Thu Mar 27 12:03:30 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 11:03:30 -0500 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <4e0ffd3a-8c50-4726-b214-f7b44d4e01ae@googlegroups.com> Message-ID: On 3/27/14 10:51 AM, Rustom Mody wrote: > > Observe: > Good ol infix -- x+y.. > prefix (with paren) -- foo(x) > prefix without -- ? x > In case you thought alphanumerics had parens -- sin x > Then theres postfix -- n! > Inside fix -- nCr (Or if you prefer ?C? ??) > And outside fix -- mod -- |x| > > And Ive probably forgotten 2 dozen other common ones > Oh, I know... that's why I'm not demanding anything (what a head-ache). From python.list at tim.thechases.com Thu Mar 27 12:08:56 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 27 Mar 2014 11:08:56 -0500 Subject: Python language hack for C-style programmers [DO NOT USE!] :-) Message-ID: <20140327110856.14991bb0@bigbox.christie.dr> Multiple times, I've seen someone want something like what C-style languages offer where assignment is done in a test, something like if (m = re.match(some_string)): do_something(m) So when I stumbled upon this horrific atrocity of language abuse and scope leakage, I thought I'd share it. if [m for m in [regex.match(some_string)] if m]: do_something(m) And presto, assignment in an if-statement. It even "works" in while-statements too: while [m for m in [regex.match(some_string)] if m]: some_string = do_something(m) That said, it's ugly, far more opaque/inefficient than the traditional m = regex.match(some_string) if m: do_something(m) and if I ever caught someone on my dev teams doing this in production code, their backside would receive a stern conversation with my footwear. Friends don't let friends program C in Python. ;-) -tkc From rosuav at gmail.com Thu Mar 27 12:10:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 03:10:00 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 28, 2014 at 2:44 AM, Mark H Harris wrote: > My comments here are not in the least hasty, nor are they generalizations. > They are based on long years of experience with "normal" users, personal > programming experience for almost 40 years, and insight into student > perception from reader comment forms, evaluations, personal discussions. > (sometimes from this list mind you) There is no such thing as a normal user, especially not of a programming language. When you're writing something for a particular class of person, you might be able to talk about the "normal user"; for instance, a word processor is most likely to be used by people who have documents to edit, but who are not trying to do major manipulation of a photo. Adding a caption to a photo and printing it, maybe, but for heavy manipulation, you should be turning to something like Gimp, so that's not part of what a normal user will be doing. You can expect that the "normal user" of Star/Open/Libre Office's word processor is going to be broadly familiar with page layout terms like "header" and "footer" (or can learn such terms), and will quite possibly understand the concept of "widows", but won't necessarily understand, for instance, the difference between a bitmapped font and a vector font. But with programming languages, who's the "normal user"? Maybe there are a few really REALLY specific-purpose languages that have the same expectations on their users as the above example, but a general-purpose language like Python is used by many sorts of people. There are expert programmers who've used the language since pre 2.0 (hi Steven!); there are experienced programmers who, while not having decades of experience with Python, do at least have an extremely solid understanding of programming (that's where I'd put myself), with any of several backgrounds; some have strong non-programming backgrounds (maybe mathematical or scientific), and understand the rigors but not necessarily the syntax (look at the recent discussion threads on python-ideas about introducing an @ operator); there are business people who just want to get things done; there are sysadmins or network admins who usually use other people's tools but dabble in a bit of scripting themselves; there are students who've just come out of a basic Comp Sci class; and this is hardly an exhaustive list. Every one of those people has a different set of preconceptions about what something "ought to do". Who is a "normal user"? ChrisA From rosuav at gmail.com Thu Mar 27 12:12:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 03:12:25 +1100 Subject: Python language hack for C-style programmers [DO NOT USE!] :-) In-Reply-To: <20140327110856.14991bb0@bigbox.christie.dr> References: <20140327110856.14991bb0@bigbox.christie.dr> Message-ID: On Fri, Mar 28, 2014 at 3:08 AM, Tim Chase wrote: > So when I stumbled upon this horrific atrocity of language abuse and > scope leakage, I thought I'd share it. > > if [m for m in [regex.match(some_string)] if m]: > do_something(m) > > And presto, assignment in an if-statement. And presto, it doesn't work in Python 3: >>> if [m for m in [5] if m]: print(m) Traceback (most recent call last): File "", line 2, in print(m) NameError: name 'm' is not defined So definitely don't do it. :) ChrisA From rosuav at gmail.com Thu Mar 27 12:19:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 03:19:40 +1100 Subject: Python language hack for C-style programmers [DO NOT USE!] :-) In-Reply-To: <20140327110856.14991bb0@bigbox.christie.dr> References: <20140327110856.14991bb0@bigbox.christie.dr> Message-ID: On Fri, Mar 28, 2014 at 3:08 AM, Tim Chase wrote: > Multiple times, I've seen someone want something like what C-style > languages offer where assignment is done in a test, something like > > if (m = re.match(some_string)): > do_something(m) If you want a language where you can do this sort of thing, but the semantics are like Python's (first-class complex objects, garbage collection, references instead of pointers, pass-by-object, etc), check out Pike. Its syntax is very much C's, or C++'s or Java's if you prefer, but it functions very much the way Python does. You can even - and you can't do this in C or, to my knowledge, C++ - declare a variable inside an if, which is valid only in the body of that if: if (array m = Regexp.split2(some_pattern, some_string)) do_something(m); (Minor difference: Regexp.match() just returns boolean true or false, but .split2() is more like Python's .match(). I'm not sure why there's the difference.) ChrisA From ian.g.kelly at gmail.com Thu Mar 27 12:22:40 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 27 Mar 2014 10:22:40 -0600 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 27, 2014 at 9:28 AM, Mark H Harris wrote: >> Do you think that the ability to write this would be an improvement? >> >> import ? >> ? = ?.?? >> ? = 5*?.?? >> ? = ? - 1 >> ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] >> ?.??????(???) > > > Steven, you're killing me here; argument by analogy does not work! That's not an analogy. That's an example of valid Python code if arbitrary Unicode characters could be used to name identifiers. > No, any unicode character (except numerals) should be able to begin a name > identifier. alt-l ? and alt-v ? should be valid first character > name identifier symbols. What's a numeral? The circled numbers in the example above are categorized as No ("Number, Other"). Currently Python only allows the ASCII digits in numeric literals, but who's to say that ?? -- categorized as Nd ("Number, Decimal Digit") shouldn't be a valid way to write 42? ? seems a bit excessive for a literal, though, so should that be permitted to start an identifier? >> There are languages that can allow arbitrary symbols as identifiers, like >> Lisp and Forth. You will note that they have a certain reputation for >> being, um, different, and although both went through periods of >> considerable popularity, both have faded in popularity since. > > > Actually, there is a recent resurgence of popularity in both common lisp > and scheme these days. But, again, that has nothing to do with my argument. > No modern language should limit the use of certain symbols to say, only math > ? . The radical symbol is more often than not going to be useful only > with math (which , by the way is why it should be built-in as ? = > squre-rooot) but why limit its use elsewhere. > > Whether this can work in python is also beside the point, because I'm not > demanding anything here either, at this point. One of the things that Python is widely known for is its readability. Allowing symbols such as ? to denote identifiers may be quite expressive and appreciable to the person writing the code. However it damages readability considerably, as seen in Steven's example above. Personally I'm not interested in having to maintain another programmer's code that arbitrarily uses ? as a timer function, ? as intersection or ? as a matrix constructor. From rosuav at gmail.com Thu Mar 27 12:23:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 03:23:28 +1100 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 28, 2014 at 2:28 AM, Mark H Harris wrote: > No, any unicode character (except numerals) should be able to begin a name > identifier. alt-l ? and alt-v ? should be valid first character > name identifier symbols. > What, even whitespace?? ChrisA From harrismh777 at gmail.com Thu Mar 27 12:24:24 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 11:24:24 -0500 Subject: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary) In-Reply-To: References: <532f9a6b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533450B8.3040309@gmail.com> On 3/25/14 6:38 PM, Dennis Lee Bieber wrote: >> > A couple of us managed to "steal" the school login/password (don't > think we ever used it, but...)... The teaching assistant didn't notice the > paper tape punch was active when persuaded to login to let us run a short > program (high school BASIC class, with a dial-up teletype). Playing back > the tape and manually spinning the platen during the password > obscuration/input phase gave us the plain text. > I still have one of my old BASIC tapes from way back in the day; I wanted to get the code back, or just remember why I had saved the tape? One of my linux user group buddies locally rigged up an optical reader (IF) to a single board micro controller... we pulled the tape by hand using the center drive holes (sprocket holes) as a strobe and after a couple of false attempts read the entire tape into a text file. That tape still have the caster oil smell of the tty that produced it; smell has a very strong memory association / I can still hear that thing running in my head. ... haven't seen one physically in years. marcus From harrismh777 at gmail.com Thu Mar 27 12:24:24 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 11:24:24 -0500 Subject: Reading in cooked mode (was Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary) References: <532f9a6b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533450B8.3040309@gmail.com> On 3/25/14 6:38 PM, Dennis Lee Bieber wrote: >> > A couple of us managed to "steal" the school login/password (don't > think we ever used it, but...)... The teaching assistant didn't notice the > paper tape punch was active when persuaded to login to let us run a short > program (high school BASIC class, with a dial-up teletype). Playing back > the tape and manually spinning the platen during the password > obscuration/input phase gave us the plain text. > I still have one of my old BASIC tapes from way back in the day; I wanted to get the code back, or just remember why I had saved the tape? One of my linux user group buddies locally rigged up an optical reader (IF) to a single board micro controller... we pulled the tape by hand using the center drive holes (sprocket holes) as a strobe and after a couple of false attempts read the entire tape into a text file. That tape still have the caster oil smell of the tty that produced it; smell has a very strong memory association / I can still hear that thing running in my head. ... haven't seen one physically in years. marcus From harrismh777 at gmail.com Thu Mar 27 12:37:36 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 11:37:36 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/27/14 11:10 AM, Chris Angelico wrote: > On Fri, Mar 28, 2014 at 2:44 AM, Mark H Harris wrote: >> My comments here are not in the least hasty, nor are they generalizations. >> They are based on long years of experience with "normal" users, {snip} > Who is a "normal user"? For the purposes of this list, a "normal" user is a reasonably intelligent college educated non "computer professional" non "computer scientist" non "expert" who for the moment has an interest in leveraging computer science and|or programming to solve everyday or other scientific problems (without) having to first become a computer professional, computer scientist, or expert. Yes, there are many many of them. There are hundreds of millions of them in the world today. There are only a handful of "experts" world-wide. This "normal" set excludes power users, expert users, special purpose users and computer scientists. The "normal" users are those folks who want to get real answers to real problems *without* having to spend eons of time learning how to use the system. Enter python, SimplyPy, short tutorial (and on-line python docs) and whalla. Now for Immanuel Kant (perception is reality); what do "normal" users expect? Its the ten-million ?uro question. marcus From tade.ankur at gmail.com Thu Mar 27 12:40:52 2014 From: tade.ankur at gmail.com (tade.ankur at gmail.com) Date: Thu, 27 Mar 2014 09:40:52 -0700 (PDT) Subject: SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC Message-ID: <94cfb444-8c5d-4b2c-b08c-29170991d02b@googlegroups.com> hei , I am a newcome to Python. I am trying to create a python script which will connect to an SSL URL and using the HEAD request will get the status of URL. For one the link I am getting following error [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:589) I am using python on windows. Following is the code snippet def checkURLStatusSecure(testhostname,urlsinatest): global conn, url, res for url in urlsinatest: conn = HTTPSConnection(testhostname,'443') conn.request('HEAD', url) res = conn.getresponse() print('|***https://' + testhostname + url + '| %s | %s |' % (res.status, res.reason)) res.close() conn.close() Any idea why I am gtting the above mentioned error. Any help will be appreciable Python version in 3.4 From rosuav at gmail.com Thu Mar 27 12:48:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 03:48:44 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 28, 2014 at 3:37 AM, Mark H Harris wrote: > For the purposes of this list, a "normal" user is a reasonably intelligent > college educated non "computer professional" non "computer scientist" non > "expert" who for the moment has an interest in leveraging computer science > and|or programming to solve everyday or other scientific problems (without) > having to first become a computer professional, computer scientist, or > expert. Now you have to justify: Why is this person considered normal? ChrisA From python at mrabarnett.plus.com Thu Mar 27 13:17:04 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 27 Mar 2014 17:17:04 +0000 Subject: unicode as valid naming symbols In-Reply-To: <4e0ffd3a-8c50-4726-b214-f7b44d4e01ae@googlegroups.com> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <4e0ffd3a-8c50-4726-b214-f7b44d4e01ae@googlegroups.com> Message-ID: <53345D10.8060303@mrabarnett.plus.com> On 2014-03-27 15:51, Rustom Mody wrote: > On Thursday, March 27, 2014 8:58:51 PM UTC+5:30, Mark H. Harris wrote: >> On 3/25/14 6:58 PM, Steven D'Aprano wrote: > >> > To quote a great Spaniard: >> > ?You keep using that word, I do not think it means what you >> > think it means.? > >> In~con~theveable ! My name is Inigo Montoya, you killed my >> father, prepare to die... > >> > Do you think that the ability to write this would be an improvement? >> > import ? >> > ? = ?.?? >> > ? = 5*?.?? >> > ? = ? - 1 >> > ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] >> > ?.??????(???) > >> Steven, you're killing me here; argument by analogy does not work! > >> ? = lambda n: sqrt(n) <===== but this should work... > >> In point of fact, it should be built-in ! OK, IMHO. > >> > Of course, it's not even necessary to be that exotic. "Any unicode symbol >> > that is not a number"... that means things like these: > >> No, any unicode character (except numerals) should be able to begin a >> name identifier. alt-l ? and alt-v ? should be valid first >> character name identifier symbols. > >> > There are languages that can allow arbitrary symbols as identifiers, like >> > Lisp and Forth. You will note that they have a certain reputation for >> > being, um, different, and although both went through periods of >> > considerable popularity, both have faded in popularity since. > >> Actually, there is a recent resurgence of popularity in both common >> lisp and scheme these days. But, again, that has nothing to do with my >> argument. No modern language should limit the use of certain symbols to >> say, only math ? . The radical symbol is more often than not going >> to be useful only with math (which , by the way is why it should be >> built-in as ? = squre-rooot) but why limit its use elsewhere. > >> Whether this can work in python is also beside the point, because >> I'm not demanding anything here either, at this point. > >> have a good day! > > The problem is that mathematicians invent notations in a completely > laissez-faire manner. > > Language implementers having to unrestrainedly keep up would go mad. > And then us vanilla users (aka programmers) would have to deal with maddened > implementers. > > Observe: > Good ol infix -- x+y.. > prefix (with paren) -- foo(x) > prefix without -- ? x > In case you thought alphanumerics had parens -- sin x > Then theres postfix -- n! > Inside fix -- nCr (Or if you prefer ?C? ??) > And outside fix -- mod -- |x| > > And Ive probably forgotten 2 dozen other common ones > You haven't mentioned implicit multiplication: xy Then there's raising to a power sin?(x), except that what looks like raising to -1 actually means the inverse function (arcsin). From rustompmody at gmail.com Thu Mar 27 13:41:54 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 27 Mar 2014 10:41:54 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1c37ed11-32fd-4670-b364-df117c3a0aa5@googlegroups.com> On Thursday, March 27, 2014 9:52:40 PM UTC+5:30, Ian wrote: > On Thu, Mar 27, 2014 at 9:28 AM, Mark H Harris wrote: > >> Do you think that the ability to write this would be an improvement? > >> import ? > >> ? = ?.?? > >> ? = 5*?.?? > >> ? = ? - 1 > >> ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] > >> ?.??????(???) > > Steven, you're killing me here; argument by analogy does not work! > That's not an analogy. That's an example of valid Python code if > arbitrary Unicode characters could be used to name identifiers. Python has other lexical categories than identifier-chars eg operators. Enriching that set is a somewhat different direction from enriching the identifier charset. Note both these directions are valid bit different This table http://www.unicode.org/charts/PDF/U2200.pdf looks unpleasantly overfilled. However good deal is stylistic differences ? vs ? and sometimes even indistinguishable ? vs ?. If we accept that python is more readable than Cobol, having a good selection from the above makes for a programming language more readable in an analogous manner. From rustompmody at gmail.com Thu Mar 27 13:53:40 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 27 Mar 2014 10:53:40 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <4e0ffd3a-8c50-4726-b214-f7b44d4e01ae@googlegroups.com> Message-ID: <8606888e-4819-4440-a652-7127c0056934@googlegroups.com> On Thursday, March 27, 2014 10:47:04 PM UTC+5:30, MRAB wrote: > On 2014-03-27 15:51, Rustom Mody wrote: > > On Thursday, March 27, 2014 8:58:51 PM UTC+5:30, Mark H. Harris wrote: > >> On 3/25/14 6:58 PM, Steven D'Aprano wrote: > >> > To quote a great Spaniard: > >> > ?You keep using that word, I do not think it means what you > >> > think it means.? > >> In~con~theveable ! My name is Inigo Montoya, you killed my > >> father, prepare to die... > >> > Do you think that the ability to write this would be an improvement? > >> > import ? > >> > ? = ?.?? > >> > ? = 5*?.?? > >> > ? = ? - 1 > >> > ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] > >> > ?.??????(???) > >> Steven, you're killing me here; argument by analogy does not work! > >> ? = lambda n: sqrt(n) <===== but this should work... > >> In point of fact, it should be built-in ! OK, IMHO. > >> > Of course, it's not even necessary to be that exotic. "Any unicode symbol > >> > that is not a number"... that means things like these: > >> No, any unicode character (except numerals) should be able to begin a > >> name identifier. alt-l ? and alt-v ? should be valid first > >> character name identifier symbols. > >> > There are languages that can allow arbitrary symbols as identifiers, like > >> > Lisp and Forth. You will note that they have a certain reputation for > >> > being, um, different, and although both went through periods of > >> > considerable popularity, both have faded in popularity since. > >> Actually, there is a recent resurgence of popularity in both common > >> lisp and scheme these days. But, again, that has nothing to do with my > >> argument. No modern language should limit the use of certain symbols to > >> say, only math ? . The radical symbol is more often than not going > >> to be useful only with math (which , by the way is why it should be > >> built-in as ? = squre-rooot) but why limit its use elsewhere. > >> Whether this can work in python is also beside the point, because > >> I'm not demanding anything here either, at this point. > >> have a good day! > > The problem is that mathematicians invent notations in a completely > > laissez-faire manner. > > Language implementers having to unrestrainedly keep up would go mad. > > And then us vanilla users (aka programmers) would have to deal with maddened > > implementers. > > Observe: > > Good ol infix -- x+y.. > > prefix (with paren) -- foo(x) > > prefix without -- ? x > > In case you thought alphanumerics had parens -- sin x > > Then theres postfix -- n! > > Inside fix -- nCr (Or if you prefer ?C? ??) > > And outside fix -- mod -- |x| > > And Ive probably forgotten 2 dozen other common ones > You haven't mentioned implicit multiplication: xy Yeah -- thats a bad one! Can mean - ordinary multiply (if you are in school) - overloaded (scalar-field or scalar-vector) multiply in linear algebra - function application (tensors??) - concatenation (awk, snobol (with space)) - a 2 char variable (for 'normal' (whatever that means) programmer) > Then there's raising to a power sin?(x), except that what looks like > raising to -1 actually means the inverse function (arcsin). Non-linear notations is another can (barrel?) of worms Matrices/Determinants anyone? Yeah... Copying the *notations* of mathematicians is not such a great idea. And yet doing away with it too summarily leads to Cobol, Sql etc. The math remains willy-nilly... just under a steaming pile of alphanumeriage. From delldudedevin at gmail.com Thu Mar 27 16:02:49 2014 From: delldudedevin at gmail.com (Devin) Date: Thu, 27 Mar 2014 13:02:49 -0700 Subject: CentOS 6.5 / SPEC file Message-ID: I have been trying to compile an RPM manually using the SPEC file that is contained in the source tarball from Python.org's website. I have tried multiple versions and they all seem to fail. I have tried the latest 3.4.0 release, 3.3.5 release, and 3.2.5 release. It appears the SPEC file contained in the Misc/RPM directory is broken. I am seeing the error: + '[' '!' -z 2.6 ']' + cd /builddir/build/BUILDROOT/python2.6-3.3.5-1pydotorg.x86_64/usr/bin + mv pydoc pydoc.old mv: cannot stat `pydoc': No such file or directory RPM build errors: error: Bad exit status from /var/tmp/rpm-tmp.yqWO6C (%install) line 71: buildprereq is deprecated: BuildPrereq: expat-devel line 72: buildprereq is deprecated: BuildPrereq: db4-devel line 73: buildprereq is deprecated: BuildPrereq: gdbm-devel line 74: buildprereq is deprecated: BuildPrereq: sqlite-devel line 91: prereq is deprecated: Prereq: python2.6 = %{PACKAGE_VERSION} line 122: prereq is deprecated: Prereq: python2.6 = %{PACKAGE_VERSION}-1pydotorg Bad exit status from /var/tmp/rpm-tmp.yqWO6C (%install) It seems to give me this error regardless of what version of Python I am trying. Is there a good website that contains maybe a more correct version of the SPEC file for CentOS 6.x? Any help would be greatly appreciated. Devin Acosta -------------- next part -------------- An HTML attachment was scrubbed... URL: From harrismh777 at gmail.com Thu Mar 27 16:54:40 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 15:54:40 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On 3/27/14 11:48 AM, Chris Angelico wrote: > On Fri, Mar 28, 2014 at 3:37 AM, Mark H Harris wrote: >> For the purposes of this list, a "normal" user is a reasonably intelligent >> college educated non "computer professional" non "computer scientist" non >> "expert" who for the moment has an interest in leveraging computer science >> and|or programming to solve everyday or other scientific problems (without) >> having to first become a computer professional, computer scientist, or >> expert. > > Now you have to justify: Why is this person considered normal? > Do not think "normal" vs. "abnormal". That would be missing the mark. "Normal" are the folks that fall (more or less) within two standard deviations from the mean on a normal distribution of reasonably intelligent, college educated scientists, and other problem solvers, who have not been trained in the liberal art of programming (software engineering) and who have an aptitude for problem solving but for whatever reason (including time and interest) have not been inclined so far towards the practical art of coding within the giant sphere of computer science. Of course you eliminate from the set out-lyres and almost all +|- outside two standard deviations of the mean (maybe a little more). The set includes most human beings on the planet. These are non computer language experts, non computer scientists generally, non data processing professionals, &c. These folks called "normal" are comprised of everyone else who is smart enough to use a computer but does not have eons to be initiated in the fine nuances of language design nor software engineering. They just want to push their problem in, and get their result out--- relatively quickly, with minimal hassle. Jeane, on the list this week, is an example of this kind of person. Yes, its possible. Dartmouth proved it (graduate students before computer science was invented) in 1963-1964. Gates proved it again with his BASICA, visual BASIC, and GWBASIC. There has been a resurgence of interest in this area on tablets with Mintoris BASIC. On the PC and MAC with Chipmunk BASIC... and others. I am going to give this a shot with python. I honestly believe that the python language can be leveraged in a minimal way (without being minimalist) and at the same time in a sophisticated nuanced way (without harming the flexibility of the language) for expert users and developers. Some people equate developer with programmer with software engineer. This ought not be done, in my view. There are *many* programmers out there who suck at software engineering (and they are not computer scientists). They also do not qualify as developers. But they are problem solvers, and they can leverage the power of python in a minimal way to solve their problems (fast, efficient) in a modern sense. We have the web now. We use databases now. Problem solvers need sockets now (server side, client side) that are *easy*. Mathematica is too complicated. Matlab the same. My idea is to unify, simplify and give access to the underlying language essentials system and interpreter (like they did in 1964) to make things easier to pick up and go. ------- When I started at this gig someone pointed to the O'Reilly book (about 1590) pages) and python.org. Give me a break! No. We need a quick starter subset, a tiny book, and even tinier tutorial, that gets people ("normal" ones) a fast boot to productive work, yes, with pointers into more extensive reading and experimenting. One day, they will be at least general-users, if not super-users or experts. They may never be python developers and that's ok. Philosophy by me marcus From fred.sells at adventistcare.org Thu Mar 27 16:56:56 2014 From: fred.sells at adventistcare.org (Sells, Fred) Date: Thu, 27 Mar 2014 20:56:56 +0000 Subject: meta language to define forms Message-ID: I'm trying to use python classes and members to define complex data entry forms as a meta language The idea is to use a nice clean syntax like Python to define form content, then render it as HTML but only as a review tool for users, The actual rendering would go into a database to let a vendor's tool generate the form in a totally non-standard syntax that's really clunky. I don't have a lot of time or management support to do something elegant like XML and then parse it, I'm thinking more like Class FyFormNumber001(GeneralForm): Section1 = Section(title="Enter Patient Vital Signs") Question1 = NumberQuestion(title="Enter pulse rate", format="%d3") Question2 = Dropdown(title="Enter current status") Question2.choices = [ (1, "Alive and Kicking"), (2, "Comatose"), (3, "Dead"), ...] Of course this is not quite legal python and I have a lot of flexibility in my "meta" language. The basic model is that a single file would define a form which would have one or more sections, each section would have one or more questions of various types (i.e. checkbox, radio button, text, etc). Sections cannot be nested. I don't have to have a perfect layout, just close enough to get the end users to focus on what they are asking for before we generate the actual code. I tried an HTML WYSIWYG editor but that was too slow and I lost information that I need to retain when the actual form is generated. The biggest problem (to me) is that I have to maintain the order; i.e. the order in which they are coded should be the order in which they are displayed. I'm looking to do about 200 forms, so it is reasonable to invest some time up front to make the process work; meanwhile management wants results yesterday, so I have a trade-off to make. Is there anything out there that would be close or do you have any suggestions. Thanks. From tjreedy at udel.edu Thu Mar 27 17:10:30 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 27 Mar 2014 17:10:30 -0400 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/27/2014 7:42 AM, Chris Angelico wrote: > In any case... what I'd suggest would be opening a tracker issue, or > discussing this on python-ideas, and seeing what core devs think of > the matter. I think that, on balance, it's probably better to show the > whole thing with the same sign; but should it be: Before doing so, I suggest looking for the design discussion either on the tracker or in python-ideas or py-dev lists. >>>> str(datetime.timedelta(-1, -1)) > '-1 day, 00:00:01' > > or should the hyphen be repeated: > >>>> str(datetime.timedelta(-1, -1)) > '-1 day, -00:00:01' '-(1 day, 00:00:01)' should be unambiguous. -- Terry Jan Reedy From torriem at gmail.com Thu Mar 27 17:26:31 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 27 Mar 2014 15:26:31 -0600 Subject: CentOS 6.5 / SPEC file In-Reply-To: References: Message-ID: <53349787.3080301@gmail.com> On 03/27/2014 02:02 PM, Devin wrote: > RPM build errors: > error: Bad exit status from /var/tmp/rpm-tmp.yqWO6C (%install) > line 71: buildprereq is deprecated: BuildPrereq: expat-devel > line 72: buildprereq is deprecated: BuildPrereq: db4-devel > line 73: buildprereq is deprecated: BuildPrereq: gdbm-devel > line 74: buildprereq is deprecated: BuildPrereq: sqlite-devel > line 91: prereq is deprecated: Prereq: python2.6 = %{PACKAGE_VERSION} > line 122: prereq is deprecated: Prereq: python2.6 = > %{PACKAGE_VERSION}-1pydotorg > Bad exit status from /var/tmp/rpm-tmp.yqWO6C (%install) > > It seems to give me this error regardless of what version of Python I am > trying. Is there a good website that contains maybe a more correct version > of the SPEC file for CentOS 6.x? Any help would be greatly appreciated. Try changing BuildPrereq to BuildRequires. Also what I'd do is grab a SRPM for python3 from, say Fedora 18 or 19, and drop in the newer tarball and see how it goes. From rosuav at gmail.com Thu Mar 27 17:42:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 08:42:50 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: On Fri, Mar 28, 2014 at 7:54 AM, Mark H Harris wrote: > Some people equate developer with programmer with software engineer. This > ought not be done, in my view. There are *many* programmers out there who > suck at software engineering (and they are not computer scientists). They > also do not qualify as developers. And this is the bit where, I think, we disagree. I think that programming is for programmers, in the same way that music is for musicians and the giving of legal advice is for lawyers. Yes, there are armchair lawyers, and plenty of people can pick up a hymn book and sing; but laws and operas aren't designed with them in mind. Why should programming languages be designed for the people who don't want to learn them? ChrisA From torriem at gmail.com Thu Mar 27 17:45:29 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 27 Mar 2014 15:45:29 -0600 Subject: CentOS 6.5 / SPEC file In-Reply-To: <53349787.3080301@gmail.com> References: <53349787.3080301@gmail.com> Message-ID: <53349BF9.2020400@gmail.com> On 03/27/2014 03:26 PM, Michael Torrie wrote: > On 03/27/2014 02:02 PM, Devin wrote: >> RPM build errors: >> error: Bad exit status from /var/tmp/rpm-tmp.yqWO6C (%install) >> line 71: buildprereq is deprecated: BuildPrereq: expat-devel >> line 72: buildprereq is deprecated: BuildPrereq: db4-devel >> line 73: buildprereq is deprecated: BuildPrereq: gdbm-devel >> line 74: buildprereq is deprecated: BuildPrereq: sqlite-devel >> line 91: prereq is deprecated: Prereq: python2.6 = %{PACKAGE_VERSION} >> line 122: prereq is deprecated: Prereq: python2.6 = >> %{PACKAGE_VERSION}-1pydotorg >> Bad exit status from /var/tmp/rpm-tmp.yqWO6C (%install) >> >> It seems to give me this error regardless of what version of Python I am >> trying. Is there a good website that contains maybe a more correct version >> of the SPEC file for CentOS 6.x? Any help would be greatly appreciated. > > Try changing BuildPrereq to BuildRequires. > > Also what I'd do is grab a SRPM for python3 from, say Fedora 18 or 19, > and drop in the newer tarball and see how it goes. I should add, that the only correct way to package Python 3 on RHEL 6 is by making the package called "python3" or something that won't collide with the system Python 2.x package. Python (2.x) is a required package on RHEL and if you replace it with Python 3 you'll see just about everything cease to function. From harrismh777 at gmail.com Thu Mar 27 18:14:09 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 17:14:09 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: <5334A2B1.20006@gmail.com> On 3/27/14 4:42 PM, Chris Angelico wrote: > And this is the bit where, I think, we disagree. I think that > programming is for programmers, in the same way that music is for > musicians and the giving of legal advice is for lawyers. Yes, there > are armchair lawyers, and plenty of people can pick up a hymn book and > sing; ------------------------------------ > but laws and operas aren't designed with them in mind. Why > should programming languages be designed for the people who don't want > to learn them? Actually we agree quite a bit on this--I agree with everything above the line----- and some of the sentiment with everything below the line. Your question has a somewhat false premise. They *really do* want to learn them, and they are frustrated with the time and attention it takes. The argument is also from analogy, which in this case is almost similar but not quite. Now, there is no royal road to geometry, opera, the violin, and the piano (I'm a pianist, and flutist--and an amateur composer). All of these fine arts take time, there is just no getting around it. However, there are now "computer based" piano courses that speed the process (with 44 key keyboard) by factors of 10. In other words, its easier now because of computers, to learn to play the piano on ones own time than ever before. To be really good at it, you're going to need to get a good instructor and work. Opera, the violin, pole vaulting, are all in another category requiring talent! ... not just will, and brains. Here in the states we file a little thing on or around April 15 called a tax return. Well most of us these days file electronically, and most of us doing that use some kind of tax software that takes in all the data, organizes it, and gives it to the Internal Revenue Service in a format that is legal, is accurate, and leads to no audit; because its just right. That is more of what I'm talking about. I have no interest in becoming a tax accountant, nor making money doing taxes for others, but, I do want to submit my correct return on time with no errors, and from my own keyboard (fast, efficient, error free, and with no driving, stamping, mailing, &c). People want to use their computer. They want to solve problems with it... and frankly, they would like to know how to program it, if there where some royal road, or fast track, or short and easy tutorial. I know lots of people that will sit down and try (with a cup of Java) and hack it out if they have a good short book. Python IMHO is the perfect language to give this a shot with--- powerful, elegant, easy once initiated, fast, and most important extensible and flexible. "normal" people deserve this. Well, I'll know if nobody buys the book, nor downloads the package, nor submits bug reports. But, I've got an inkling that there is a need, all over the place. Just look on the list: Fred Sells meta language request. He proves my point entirely. I have not responded yet... thought I would wait a bit... but look what he is after. Go read it. But, I don't disagree with you Chris, and I have myself some of the same concerns really. I'm finding the path harder than I thought it would be. Well, its hard enough just getting other people who are experts to buy into it. Its going to be an uphill climb, for sure. marcus From harrismh777 at gmail.com Thu Mar 27 18:14:09 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Thu, 27 Mar 2014 17:14:09 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: <5334A2B1.20006@gmail.com> On 3/27/14 4:42 PM, Chris Angelico wrote: > And this is the bit where, I think, we disagree. I think that > programming is for programmers, in the same way that music is for > musicians and the giving of legal advice is for lawyers. Yes, there > are armchair lawyers, and plenty of people can pick up a hymn book and > sing; ------------------------------------ > but laws and operas aren't designed with them in mind. Why > should programming languages be designed for the people who don't want > to learn them? Actually we agree quite a bit on this--I agree with everything above the line----- and some of the sentiment with everything below the line. Your question has a somewhat false premise. They *really do* want to learn them, and they are frustrated with the time and attention it takes. The argument is also from analogy, which in this case is almost similar but not quite. Now, there is no royal road to geometry, opera, the violin, and the piano (I'm a pianist, and flutist--and an amateur composer). All of these fine arts take time, there is just no getting around it. However, there are now "computer based" piano courses that speed the process (with 44 key keyboard) by factors of 10. In other words, its easier now because of computers, to learn to play the piano on ones own time than ever before. To be really good at it, you're going to need to get a good instructor and work. Opera, the violin, pole vaulting, are all in another category requiring talent! ... not just will, and brains. Here in the states we file a little thing on or around April 15 called a tax return. Well most of us these days file electronically, and most of us doing that use some kind of tax software that takes in all the data, organizes it, and gives it to the Internal Revenue Service in a format that is legal, is accurate, and leads to no audit; because its just right. That is more of what I'm talking about. I have no interest in becoming a tax accountant, nor making money doing taxes for others, but, I do want to submit my correct return on time with no errors, and from my own keyboard (fast, efficient, error free, and with no driving, stamping, mailing, &c). People want to use their computer. They want to solve problems with it... and frankly, they would like to know how to program it, if there where some royal road, or fast track, or short and easy tutorial. I know lots of people that will sit down and try (with a cup of Java) and hack it out if they have a good short book. Python IMHO is the perfect language to give this a shot with--- powerful, elegant, easy once initiated, fast, and most important extensible and flexible. "normal" people deserve this. Well, I'll know if nobody buys the book, nor downloads the package, nor submits bug reports. But, I've got an inkling that there is a need, all over the place. Just look on the list: Fred Sells meta language request. He proves my point entirely. I have not responded yet... thought I would wait a bit... but look what he is after. Go read it. But, I don't disagree with you Chris, and I have myself some of the same concerns really. I'm finding the path harder than I thought it would be. Well, its hard enough just getting other people who are experts to buy into it. Its going to be an uphill climb, for sure. marcus From steve+comp.lang.python at pearwood.info Thu Mar 27 19:41:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Mar 2014 23:41:59 GMT Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Mar 2014 08:52:24 -0400, Roy Smith wrote: > In article , > Chris Angelico wrote: >> It's not "equally braindead", it follows a simple and logical rule: >> Only the day portion is negative. > > Simple and logical, yes. But also entirely braindead. Do you think it is "braindead" for __str__ to return something which follows the internal representation of the object? Note that I'm not asking if that is the best choice for every object, or even the best choice for any object. You've made an extremely strong claim, by calling something "braindead" you're essentially arguing that this is an *utterly irredeemable choice whatsoever* with absolutely no redeeming features. Hyperbole is fun, that's why we do it. It allows us to build up a nice feeling of righteous indignation over something utterly outrageous and indefensible, without having to worry about inconvenient distractions like other points of view :-) >> That might not be perfectly suited to all situations > > Give ma a real-life situation where you would want such behavior. Easy -- I'm debugging timedelta routines, and I want to easily see that the timedeltas calculated match what I expect them to be when I print them. The quickest, easiest and simplest way is for str(timedelta) to follow the internal representation. Oh look, that's exactly what the docs say: "String representations of timedelta objects are normalized similarly to their internal representation. This leads to somewhat unusual results for negative timedeltas." as Skip has already pointed out. Is this the *best* choice for a timedelta? Probably not. But it's a simple, logical, *reasonable* choice. It only fails the "reasonable" test if you insist that timedelta objects *must* match the time-keeping conventions of native English speakers, and any other convention is unspeakable. For all we know, maybe (say) Koreans or Egyptians or Gaelic Scots do say something like "It was a day ago, less four hours" meaning twenty hours ago. Stranger things happen in natural language, and we ought to be cautious about insisting that English conventions are universal. (Given Johannes Bauer's reaction, we can be fairly certain that German speakers follow a similar convention to English speakers. Which shouldn't be terribly surprising, since English is a Germanic language.) A few seconds searching the bug tracker shows that this is not, in fact, a bug in timedelta but probably a deliberate feature: http://bugs.python.org/issue9430 This one is also relevant: http://bugs.python.org/issue1569623 Alas, the discussion appears to have been on #python-dev, which (probably) means it is not archived anywhere. -- Steven D'Aprano http://import-that.dreamwidth.org/ From drsalists at gmail.com Thu Mar 27 19:45:19 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 27 Mar 2014 16:45:19 -0700 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Message-ID: On Fri, Mar 21, 2014 at 1:42 PM, vasudevram wrote: > Can anyone - maybe one of the Python language core team, or someone with knowledge of the internals of Python - can explain why this code works, and whether the different occurrences of the name x in the expression, are in different scopes or not? : > > x = [[1,2], [3,4], [5,6]] > [x for x in x for x in x] I'll give this +1 for playfulness, and -2 for lack of clarity. I hope no one thinks this sort of thing is good to do in real-life code. From greg.ewing at canterbury.ac.nz Thu Mar 27 19:45:57 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 28 Mar 2014 12:45:57 +1300 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <4e0ffd3a-8c50-4726-b214-f7b44d4e01ae@googlegroups.com> Message-ID: Mark H Harris wrote: >> Good ol infix -- x+y.. >> prefix (with paren) -- foo(x) >> prefix without -- ? x >> In case you thought alphanumerics had parens -- sin x >> Then theres postfix -- n! >> Inside fix -- nCr (Or if you prefer ?C? ??) >> And outside fix -- mod -- |x| And mismatched delimiters: [5, 7) |x> -- Greg From ethan at stoneleaf.us Thu Mar 27 20:04:00 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 27 Mar 2014 17:04:00 -0700 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5334BC70.8000905@stoneleaf.us> On 03/27/2014 02:10 PM, Terry Reedy wrote: > On 3/27/2014 7:42 AM, Chris Angelico wrote: > >> In any case... what I'd suggest would be opening a tracker issue, or >> discussing this on python-ideas, and seeing what core devs think of >> the matter. I think that, on balance, it's probably better to show the >> whole thing with the same sign; but should it be: > > Before doing so, I suggest looking for the design discussion either on the tracker or in python-ideas or py-dev lists. > >>--> str(datetime.timedelta(-1, -1)) >> '-1 day, 00:00:01' >> >> or should the hyphen be repeated: >> >>--> str(datetime.timedelta(-1, -1)) >> '-1 day, -00:00:01' > > '-(1 day, 00:00:01)' should be unambiguous. Or change the comma to an and: '-1 day and 00:00:01' -- ~Ethan~ From roy at panix.com Thu Mar 27 20:29:17 2014 From: roy at panix.com (Roy Smith) Date: Thu, 27 Mar 2014 20:29:17 -0400 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5334b747$0$29994$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 27 Mar 2014 08:52:24 -0400, Roy Smith wrote: > > > In article , > > Chris Angelico wrote: > >> It's not "equally braindead", it follows a simple and logical rule: > >> Only the day portion is negative. > > > > Simple and logical, yes. But also entirely braindead. > > Do you think it is "braindead" for __str__ to return something which > follows the internal representation of the object? Yes. The whole idea of OOD is to decouple internal representation from external behavior. > > Give ma a real-life situation where you would want such behavior. > > Easy -- I'm debugging timedelta routines, and I want to easily see that > the timedeltas calculated match what I expect them to be when I print > them. The quickest, easiest and simplest way is for str(timedelta) to > follow the internal representation. That's what __repr__() is for. > Oh look, that's exactly what the docs say: > > "String representations of timedelta objects are normalized similarly to > their internal representation. This leads to somewhat unusual results for > negative timedeltas." Yes, I know that's what the docs say. That's why it's not an implementation bug. It's a design bug :-) From steve+comp.lang.python at pearwood.info Thu Mar 27 20:34:23 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2014 00:34:23 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Mar 2014 10:44:49 -0500, Mark H Harris wrote: > On 3/26/14 1:35 AM, alex23 wrote: >> On 25/03/2014 12:39 PM, Mark H Harris wrote: >>> my version semantically is "how it is perceived" by the user >> >> Could you please stop claiming to have insight into the comprehension >> of anyone other than yourself? Hasty generalisations don't help your >> argument. > > hi alex23, please don't be silly. > > Who is being hasty? How do you know its a generalization? When you claim to speak for "the user" (your words, not mine), as in the quote above, what else could it be than a generalisation? Unless you believe that there actually is *one single person* using Python, you are generalising the millions of users (note plural) into one idealised user who speaks for all. > My comments here are not in the least hasty, nor are they > generalizations. Of course they are. Unless you claim that there is literally only one person using Python -- which is obviously absurd -- you are making a statement about the huge variety of Python users as if they all agreed on this matter. That is a generalisation. It might even be a valid generalisation, although I doubt it. You have a pattern of discounting or rejecting the needs and desires of *most* programmers in favour of what you perceive as the needs and wants of a *tiny* subset of inexperienced programmers -- those who aren't interested in becoming experienced, but want to continue programming -- as if they were all users of Python. They are not. Not even close. And they are certainly not the people who keep Python alive and well -- if anything, they are users in the sense that they *use* Python and the resources of the Python community, but they will never, ever give back. Maybe your generalisation about *users* is more apt than either of us realised. Your generalisation doesn't even apply to *all* inexperienced beginners. If you wanted to turn Python into a teaching language, that would be an interesting proposal, but you don't. Consider your recent comments that ? should be allowed as an identifier, and that it should be a built-in. Screw the people who know and understand Unicode rules, your suggestion would break their expectations, but those users don't count for you. Presumably, anyone who knows Unicode must be an expert, and experts don't matter to you. Screw the people who have no interest in mathematics, and wouldn't know a square root symbol from a kick to the head. Those users don't count either. As for enormous number of users who will have difficulty typing ? in their source code, they certainly don't count! It's good enough that *you* have a solution to that problem, you can type alt-v, and anyone who can't simply doesn't matter. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ben+python at benfinney.id.au Thu Mar 27 20:43:17 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 28 Mar 2014 11:43:17 +1100 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8538i3p2ze.fsf@benfinney.id.au> Roy Smith writes: > In article <5334b747$0$29994$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > > > On Thu, 27 Mar 2014 08:52:24 -0400, Roy Smith wrote: > > > Give ma a real-life situation where you would want such behavior > > > [the ?datetime.timedelta.__str__? method returning a string > > > showing some portions negative and others positive]. > > > > Easy -- I'm debugging timedelta routines, and I want to easily see > > that the timedeltas calculated match what I expect them to be when I > > print them. The quickest, easiest and simplest way is for > > str(timedelta) to follow the internal representation. > > That's what __repr__() is for. Indeed, that is why Python's data model defines separate ?__str__? and ?__repr__? methods. object.__repr__(self) [?] If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment). If this is not possible, a string of the form <...some useful description...> should be returned. object.__str__(self) [?] compute the ?informal? or nicely printable string representation of an object. [?] a more convenient or concise representation can be used. If you're a programmer wanting to know about the internal representation of an object, call its ?__repr__? method (by calling ?repr(foo)?). If you're wanting to see a string representation that follows the *semantics* of the object, call its ?__str__? method (by calling ?str(foo)?). If the ?__str__? method follows the internal representation at the expense of the user's conceptual model, that's terrible (which I think is what Roy means by ?braindead?). I wouldn't go as far as that insult, because it could be mere omission: The default implementation [of ?__str__?] defined by the built-in type object calls object.__repr__(). So, where ?str(foo)? is returning an unhelpful representation that follows the implementation, it could simply be that there is no ?__str__? defined for that type. > > Oh look, that's exactly what the docs say: > > > > "String representations of timedelta objects are normalized > > similarly to their internal representation. This leads to somewhat > > unusual results for negative timedeltas." > > Yes, I know that's what the docs say. That's why it's not an > implementation bug. It's a design bug :-) One which to some extent violates the defined data model for Python objects, and hence should be fixed. -- \ ?I don't know half of you half as well as I should like, and I | `\ like less than half of you half as well as you deserve.? ?Bilbo | _o__) Baggins | Ben Finney From tjreedy at udel.edu Thu Mar 27 21:32:14 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 27 Mar 2014 21:32:14 -0400 Subject: meta language to define forms In-Reply-To: References: Message-ID: On 3/27/2014 4:56 PM, Sells, Fred wrote: > I'm trying to use python classes and members to define complex data > entry forms as a meta language > > The idea is to use a nice clean syntax like Python to define form > content, then render it as HTML but only as a review tool for users, > The actual rendering would go into a database to let a vendor's tool > generate the form in a totally non-standard syntax that's really > clunky. > > I don't have a lot of time or management support to do something > elegant like XML and then parse it, I'm thinking more like > > Class FyFormNumber001(GeneralForm): > Section1 = Section(title="Enter Patient Vital Signs") > Question1 = NumberQuestion(title="Enter pulse rate", format="%d3") > Question2 = Dropdown(title="Enter current> status") > Question2.choices = [ (1, "Alive and Kicking"), (2, > "Comatose"), (3, "Dead"), ...] > > Of course this is not quite legal python and I have a lot of > flexibility in my "meta" language. The basic model is that a single > file would define a form which would have one or more sections, each > section would have one or more questions of various types (i.e. > checkbox, radio button, text, etc). Sections cannot be nested. > > I don't have to have a perfect layout, just close enough to get the > end users to focus on what they are asking for before we generate the > actual code. I tried an HTML WYSIWYG editor but that was too slow > and I lost information that I need to retain when the actual form is > generated. > > The biggest problem (to me) is that I have to maintain the order; > i.e. the order in which they are coded should be the order in which > they are displayed. > > I'm looking to do about 200 forms, so it is reasonable to invest some > time up front to make the process work; meanwhile management wants > results yesterday, so I have a trade-off to make. > > Is there anything out there that would be close or do you have any > suggestions. Have you searched the python-list archives? PyPI? or the web? There was a thread on this topic perhaps a month ago but I barely followed it. -- Terry Jan Reedy From tanmay.kansara at gmail.com Thu Mar 27 21:34:02 2014 From: tanmay.kansara at gmail.com (tanmay.kansara at gmail.com) Date: Thu, 27 Mar 2014 18:34:02 -0700 (PDT) Subject: implementing download using a url call Message-ID: Hey Guys, here is what I am trying to solve. I have a URL - somesite.com/server/pattern.x?some_more_stuff This URl is out there as an href tag on users website. Is there a way in which I can serve a file(not from my server) while ensuring that the users remain on the third party website. I am currently using this : myfile = "http://download.someothersite.com/somefile.exe" meta_tag = "" % myfile return HttpResponse(meta_tag, content_type='force-download') The above works, however the user gets redirected to a blank page. Would downloading and serving the file from my server be a better option? If so, some pointers please. Do let me know what would be an elegant solution. The file sizes should be about 500kb(stub files). Thanks From davea at davea.name Thu Mar 27 21:44:51 2014 From: davea at davea.name (Dave Angel) Date: Thu, 27 Mar 2014 21:44:51 -0400 (EDT) Subject: Python language hack for C-style programmers [DO NOT USE!] :-) References: <20140327110856.14991bb0@bigbox.christie.dr> Message-ID: Chris Angelico Wrote in message: > On Fri, Mar 28, 2014 at 3:08 AM, Tim Chase > wrote: >> Multiple times, I've seen someone want something like what C-style >> languages offer where assignment is done in a test, something like >> >> if (m = re.match(some_string)): >> do_something(m) > > If you want a language where you can do this sort of thing, but the > semantics are like Python's (first-class complex objects, garbage > collection, references instead of pointers, pass-by-object, etc), > check out Pike. Its syntax is very much C's, or C++'s or Java's if you > prefer, but it functions very much the way Python does. You can even - > and you can't do this in C or, to my knowledge, C++ - declare a > variable inside an if, which is valid only in the body of that if: > > if (array m = Regexp.split2(some_pattern, some_string)) > do_something(m); > I don't know for certain about if, but you can declare (in C++) a new variable in for, which is a superset of if. Scope ends when the for does. -- DaveA From davea at davea.name Thu Mar 27 21:47:48 2014 From: davea at davea.name (Dave Angel) Date: Thu, 27 Mar 2014 21:47:48 -0400 (EDT) Subject: SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC References: <94cfb444-8c5d-4b2c-b08c-29170991d02b@googlegroups.com> Message-ID: tade.ankur at gmail.com Wrote in message: > > hei , > > I am a newcome to Python. > > I am trying to create a python script which will connect to an SSL URL and using the HEAD request will get the status of URL. > > For one the link I am getting following error > > [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:589) And why do you omit the rest of the error? > > -- DaveA From tjreedy at udel.edu Thu Mar 27 21:46:25 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 27 Mar 2014 21:46:25 -0400 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/27/2014 5:10 PM, Terry Reedy wrote: > On 3/27/2014 7:42 AM, Chris Angelico wrote: > >> In any case... what I'd suggest would be opening a tracker issue, or >> discussing this on python-ideas, and seeing what core devs think of >> the matter. I think that, on balance, it's probably better to show the >> whole thing with the same sign; but should it be: > > Before doing so, I suggest looking for the design discussion either on > the tracker or in python-ideas or py-dev lists. And skip the troll word 'braindead'. Terry Jan Reedy From rosuav at gmail.com Thu Mar 27 21:52:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 12:52:04 +1100 Subject: Python language hack for C-style programmers [DO NOT USE!] :-) In-Reply-To: References: <20140327110856.14991bb0@bigbox.christie.dr> Message-ID: On Fri, Mar 28, 2014 at 12:44 PM, Dave Angel wrote: >> if (array m = Regexp.split2(some_pattern, some_string)) >> do_something(m); >> > > I don't know for certain about if, but you can declare (in C++) a > new variable in for, which is a superset of if. Scope ends when > the for does. Yeah, but only a for, AFAIK. Not an if or a while. ChrisA From roy at panix.com Thu Mar 27 21:59:55 2014 From: roy at panix.com (Roy Smith) Date: Thu, 27 Mar 2014 21:59:55 -0400 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Terry Reedy wrote: > On 3/27/2014 5:10 PM, Terry Reedy wrote: > > On 3/27/2014 7:42 AM, Chris Angelico wrote: > > > >> In any case... what I'd suggest would be opening a tracker issue, or > >> discussing this on python-ideas, and seeing what core devs think of > >> the matter. I think that, on balance, it's probably better to show the > >> whole thing with the same sign; but should it be: > > > > Before doing so, I suggest looking for the design discussion either on > > the tracker or in python-ideas or py-dev lists. > > And skip the troll word 'braindead'. > > Terry Jan Reedy I apologize for my poor choice of vocabulary. From rosuav at gmail.com Thu Mar 27 22:24:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 13:24:15 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <5334A2B1.20006@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334A2B1.20006@gmail.com> Message-ID: On Fri, Mar 28, 2014 at 9:14 AM, Mark H Harris wrote: > Your question has a somewhat false premise. They *really do* want to learn > them, and they are frustrated with the time and attention it takes. The > argument is also from analogy, which in this case is almost similar but not > quite. > > Now, there is no royal road to geometry, opera, the violin, and the piano > (I'm a pianist, and flutist--and an amateur composer). All of these fine > arts take time, there is just no getting around it. How many hours of practice have you put into musical study? The usual estimate is ten thousand hours to achieve mastery. If you're an amateur composer, you've probably put in rather a lot of hours. (I am one also, and I'm pretty sure I've put in rather a lot more than 10K hours in various musical fields.) But if you just want to sing hymns in church, you don't need *or want* to put in that much practice. Why should that sort of person want to learn/master opera? I used opera as an example because I'm about to dive into another one - this Tuesday is bump-in (getting all our scenery into the theatre), and we open before a real audience on April 5th. [1] In that production are a number of really REALLY awesome people (Ron Pidcock, Jenny Wakefield, Lydia Kovesi, Andrea Tappe...) who've put in huge numbers of hours to master the singing, dancing, etc required for the roles. Me? I'm able to sing, but I don't have the time (or the money) to get *that* good, so I don't audition for roles. I'm content to work lighting instead. Conversely, I'm a master of networking. I've put in plenty of hours to achieve mastery, and continue to do so. One of our sopranos was having trouble with her home network, and I swung by and gave her a hand. She doesn't want or need to understand what's going on, yet she uses and appreciates her wireless network. She *really does not* want to learn networking, or programming, just as I do not want to learn operatic singing, or how to build a death ray. Python can come in handy for her, but she is NOT the "normal user" for Python - and yet she fits into your description, below. > People want to use their computer. They want to solve problems with it... > and frankly, they would like to know how to program it, if there where some > royal road, or fast track, or short and easy tutorial. I know lots of people > that will sit down and try (with a cup of Java) and hack it out if they have > a good short book. There might be a short and easy tutorial "Python for people who already know Pike" (except that there won't be much call for it). There could possibly be "Python for mathematicians", because maths requires a similar vigor. There might even be "Python for brain surgeons". But there won't be "Python for people who know nothing" as a simple tutorial. It takes skill and mastery to become a programmer, and that doesn't come from nowhere. Transferring that skill from another area is easier than conjuring it (and easier still if the two areas are similar), but if someone has a similar skill already, s/he's probably already a programmer, and so isn't part of your description. Most people want to *use* a computer, and most certainly do *not* want to *program* it. I know this from personal experience; plenty of people will use electronica that they can't fiddle with - just look at the popularity of the iphone. There might well be an app for that, but if there isn't, well, you're going to need to go through a lot of hoops to create it. There's no way a typical iphone user can program his/her phone. > Just look on the list: Fred Sells meta language request. He proves my > point entirely. I have not responded yet... thought I would wait a bit... > but look what he is after. Go read it. I've read it (although not Terry's response, yet). He wants to create a DSL. I didn't respond because I know someone else will do so better (also, it was 8AM and I'd been up most of the night learning about systemd - making the jump now that Debian's settling on it, so it's time to port my Upstart jobs and knowledge), but my guess would be that he's not really looking for a *programming* language, but a *page description* language. Something in the same field as HTML, not Python. > But, I don't disagree with you Chris, and I have myself some of the same > concerns really. I'm finding the path harder than I thought it would be. > Well, its hard enough just getting other people who are experts to buy into > it. Its going to be an uphill climb, for sure. Programming forces you to understand programming. Even if you just use Python as a super-calculator (which, incidentally, I often do), you're still going to end up running into edge cases that force you to comprehend what you're doing: >>> 1e16+3-1e16 4.0 Common sense says it ought to be 3.0, but it ain't. IEEE floating point explains why this happens, but that's getting technical. If you don't want to write code, get a calculator. If you want to write code, learn at least something of programming, and understand that Python's syntax is not aimed at the person who knows nothing. A car's engine usually isn't tuned for 10km/h running; you have to get up a bit of speed before it becomes more efficient. Why is it so wrong for Python to expect the same? ChrisA [1] http://gilbertandsullivan.org.au/ - come see us if you're in Melbourne! From tjreedy at udel.edu Thu Mar 27 22:24:45 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 27 Mar 2014 22:24:45 -0400 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/27/2014 9:59 PM, Roy Smith wrote: > In article , > Terry Reedy wrote: > >> On 3/27/2014 5:10 PM, Terry Reedy wrote: >>> On 3/27/2014 7:42 AM, Chris Angelico wrote: >>> >>>> In any case... what I'd suggest would be opening a tracker issue, or >>>> discussing this on python-ideas, and seeing what core devs think of >>>> the matter. I think that, on balance, it's probably better to show the >>>> whole thing with the same sign; but should it be: >>> >>> Before doing so, I suggest looking for the design discussion either on >>> the tracker or in python-ideas or py-dev lists. >> >> And skip the troll word 'braindead'. > I apologize for my poor choice of vocabulary. I actually meant if you post on the tracker or python-ideas. There is a little more leeway here. But as you maybe noticed. even here a trollish word can divert discussion from you main point. Back to your main point: the current output looks strange to me also. But I did not follow the datetime development discussion. I do know that the people responsible are not normally braindead ;-). -- Terry Jan Reedy From rosuav at gmail.com Thu Mar 27 22:26:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 13:26:51 +1100 Subject: implementing download using a url call In-Reply-To: References: Message-ID: On Fri, Mar 28, 2014 at 12:34 PM, wrote: > Hey Guys, > > here is what I am trying to solve. > > I have a URL - somesite.com/server/pattern.x?some_more_stuff > > This URl is out there as an href tag on users website. Is there a way in which I can serve a file(not from my server) while ensuring that the users remain on the third party website. I am currently using this : > > myfile = "http://download.someothersite.com/somefile.exe" > > meta_tag = "" % myfile > return HttpResponse(meta_tag, content_type='force-download') > > The above works, however the user gets redirected to a blank page. Would downloading and serving the file from my server be a better option? If so, some pointers please. So what you want is for the user to go to a page which both downloads a file *and* displays content, is that it? This is fairly common on the web today; have a look at how places like Sourceforge do it. ChrisA From rustompmody at gmail.com Thu Mar 27 22:46:07 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 27 Mar 2014 19:46:07 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334A2B1.20006@gmail.com> Message-ID: <76663d88-45d7-49f1-a2a4-b35120e7f963@googlegroups.com> On Friday, March 28, 2014 3:44:09 AM UTC+5:30, Mark H. Harris wrote: > On 3/27/14 4:42 PM, Chris Angelico wrote: > > And this is the bit where, I think, we disagree. I think that > > programming is for programmers, in the same way that music is for > > musicians and the giving of legal advice is for lawyers. Yes, there > > are armchair lawyers, and plenty of people can pick up a hymn book and > > sing; As for programming its just too much in-our-face (to most of us reading this at least) to discuss it from the pov of 'the* layman' for the same reason that if I try to show you something and stick it ? inch from your nose, you wont be able to see it. Your other examples fire quite differently than you (perhaps) realize As for laws, I am reminded of the Tao te Ching: Therefore the Master says: I let go of the law, and people become honest. I let go of economics, and people become prosperous. I let go of religion, and people become serene. I let go of all desire for the common good, and the good becomes common as grass. http://acc6.its.brooklyn.cuny.edu/~phalsall/texts/taote-v3.html#57 As for music I find (as Mark does) that technology allows for a 10-fold leap in learning: When I learnt the piano, 10 years to perform anything reasonably and 10 months to make head-or-tail of staff notation were fair estimates. Today, spend 10 days browsing your favourite genre at http://musescore.com/ with a little guidance and staff notation stops being difficult. A couple of weeks more and one and start entering music into the computer (or phone) > ------------------------------------ > > but laws and operas aren't designed with them in mind. Why > > should programming languages be designed for the people who don't want > > to learn them? > Actually we agree quite a bit on this--I agree with everything above the > line----- and some of the sentiment with everything below the line. > Your question has a somewhat false premise. They *really do* want to > learn them, and they are frustrated with the time and attention it > takes. The argument is also from analogy, which in this case is almost > similar but not quite. Well if you see http://cultureandempire.com/cande.html there is this interesting insight: > Moore?s Law isn?t a mythical beast that magically materialized in 1965 > and threatens to unpredictably vanish at any moment. In fact, it?s > part of a broader ancient mechanism that has no intention of > stopping. This mechanism, which I call cost gravity, pulls down the > price of technology by about half every two years. Add to that the fact that cost=money ultimately comes from money=effort eg currencies like http://en.wikipedia.org/wiki/Ithaca_Hours (maybe even dolour ? dollar though thats not the official etymology) and its clear that there is a ripple effect of technology breaking down old castles. Pleasant to the* layman, unpleasant to those professionals whose fiefdoms are threatened. > A car's engine usually isn't tuned for 10km/h running; you have to get > up a bit of speed before it becomes more efficient. Why is it so wrong > for Python to expect the same? Lets (temporarily) invert your example: 100 years ago, cobbled streets and horse-carriages were not meant for 100 kmph speeds. Today's roads are. Likewise technology: Like the natural speed of roads has changed, the natural accessibility of technology has also. A big part of python's success was that 20 years ago it worked out way more accessible than C. This peaked around 10 years ago. Nowadays I am not so sure what its direction is... ------------ * And I'll leave it to Steven to cudgel the 'the' From rosuav at gmail.com Thu Mar 27 23:02:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 14:02:08 +1100 Subject: meta language to define forms In-Reply-To: References: Message-ID: On Fri, Mar 28, 2014 at 7:56 AM, Sells, Fred wrote: > I don't have a lot of time or management support to do something elegant like XML and then parse it, I'm thinking more like > > Class FyFormNumber001(GeneralForm): > Section1 = Section(title="Enter Patient Vital Signs") > Question1 = NumberQuestion(title="Enter pulse rate", format="%d3") > Question2 = Dropdown(title="Enter current status") > Question2.choices = [ (1, "Alive and Kicking"), (2, "Comatose"), (3, "Dead"), ...] Rule of Python: XML is not the answer. XML is the question, and "NO!" is the answer :) Your syntax there looks reasonable already. I'd recommend you make it a flat data file, though, don't try to make it a programming language - unless you actively need it to be one. Here are a couple of ways you could format this. Any would be fairly easy to code a parser for. (I'm guessing your format there should probably be "%3d", if you mean printf notation. But I'll keep your "%d3" example in the below.) 1) Using indentation for nesting, and a "command, space, args" model: GeneralForm FyFormNumber001 Section "Enter Patient Vital Signs" NumberQuestion "Enter pulse rate" format="%d3" Dropdown "Enter current status" Choice 1 "Alive and Kicking" Choice 2 "Comatose" Choice 3 "Dead" ... This would be parsed with an algorithm like this: * Maintain an indentation stack, which starts with a top level entry. * Read one line. Parse it into three parts: leading indentation, command, args. * Remove from the indentation stack everything equal to or greater than this line's indent. * Send the command to the last entry on your indentation stack, with its args. * Capture the result of that command and put it on the indentation stack. * Iterate until end of file. You'd then have a top-level object that understands a "GeneralForm" command and returns a form object; the form object understands the "Section" command and returns a section object; the "Dropdown" object understands "Choice"; and so on. 2) Rendering the whole thing as JSON: {"type": "GeneralForm", "FormName": "FyFormNumber001", "children": [ {"type":"Section", "Title": "Enter Patient Vital Signs", "children": [ {"type": "NumberQuestion", "title":"Enter pulse rate", "format":"%d3"}, {"type": "Dropdown", "title":"Enter current status", "children": [ {"type":"Choice", "value":1, "name":"Alive and Kicking"}, {"type":"Choice", "value":2, "name":"Comatose"}, {"type":"Choice", "value":3, "name":"Dead"}, ... ]} ]} ]} This would be parsed by first converting the JSON into a tree of dicts and lists, and then at each step, checking the type, and processing its children. The bulk of the work could be done generically, and it's easy to add attributes to anything. The cost, though, is that you need to be a bit verbose about the common attributes. 3) Actual Python code: FyFormNumber001 = GeneralForm( Sections = [Section("Enter Patient Vital Signs", Questions=[ NumberQuestion("Enter pulse rate", format="%d3"), Dropdown("Enter current status", choices=[ (1, "Alive and Kicking"), (2, "Comatose"), (3, "Dead"), ...] ), ]), ]) This would be parsed by creating functions or classes named GeneralForm, Section, NumberQuestion, etc, and having them handle positional arguments for the obvious things, and keyword args for the less obvious. (I may have misjudged which is which, but you should make a design decision about that.) I've used keyword args for everything that's a list, but that could be done differently if you choose. 4) Actual Pike code. This came up in the thread Terry's referring to. Its primary advantage was that it *already existed* (we were talking about GTK2), where all the above options do require code. It would look something like this: object FyFormNumber001=GeneralForm() ->add(Section("Enter Patient Vital Signs") ->add(NumberQuestion("Enter pulse rate", "%d3")) ->add(Dropdown("Enter current status") ->add_choice(1, "Alive and Kicking") ->add_choice(2, "Comatose") ->add_choice(3, "Dead") ... ) ) ; I don't recommend this above the options listed above; but I'd say it's at least 95% as good as the others, and if you find a way to get something that looks like this with practically zero effort, I would strongly advise going with it. (Another advantage of the Pike GTK2 system is that you often want to manipulate the objects post-creation and pre-insertion into the tree. I don't think you need that flexibility here, so again, this one is just for comparison.) If you can, try to go for the first option. It's clean, and it's not terribly hard to parse. Failing that, the third option isn't too bad, but I'd advise against going with JSON; one misplaced comma or bracket and you have a tough debugging problem to solve. You might get that problem with the Python-code version too, but you have a bit of a better chance at a readable traceback there. ChrisA From rosuav at gmail.com Thu Mar 27 23:03:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 14:03:15 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 28, 2014 at 1:24 PM, Terry Reedy wrote: > I do know that the people responsible are not normally braindead ;-). Yeah, anyone who develops Python is clearly abnormally braindead... *dives for cover* ChrisA From rosuav at gmail.com Thu Mar 27 23:06:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 14:06:26 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <76663d88-45d7-49f1-a2a4-b35120e7f963@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334A2B1.20006@gmail.com> <76663d88-45d7-49f1-a2a4-b35120e7f963@googlegroups.com> Message-ID: On Fri, Mar 28, 2014 at 1:46 PM, Rustom Mody wrote: >> Moore?s Law isn?t a mythical beast that magically materialized in 1965 >> and threatens to unpredictably vanish at any moment. In fact, it?s >> part of a broader ancient mechanism that has no intention of >> stopping. This mechanism, which I call cost gravity, pulls down the >> price of technology by about half every two years. > > Add to that the fact that cost=money ultimately comes from money=effort > eg currencies like http://en.wikipedia.org/wiki/Ithaca_Hours > (maybe even dolour ? dollar though thats not the official etymology) > and its clear that there is a ripple effect of technology breaking down > old castles. Pleasant to the* layman, unpleasant to those professionals whose > fiefdoms are threatened. The price of technology to the end user, yes. Anyone can go out and buy a computer that's powerful enough to do everything the typical person needs, and it's cheap enough to fit inside the typical person's budget. (Compare early IBM estimates of maybe half a dozen computer sales worldwide.) That has nothing to do with whether or not that person can create that computer. Same goes for software. ChrisA From roy at panix.com Thu Mar 27 23:13:21 2014 From: roy at panix.com (Roy Smith) Date: Thu, 27 Mar 2014 23:13:21 -0400 Subject: meta language to define forms References: Message-ID: In article , Chris Angelico wrote: > On Fri, Mar 28, 2014 at 7:56 AM, Sells, Fred > wrote: > > I don't have a lot of time or management support to do something elegant > > like XML and then parse it, I'm thinking more like > > > > Class FyFormNumber001(GeneralForm): > > Section1 = Section(title="Enter Patient Vital Signs") > > Question1 = NumberQuestion(title="Enter pulse rate", > > format="%d3") > > Question2 = Dropdown(title="Enter current status") > > Question2.choices = [ (1, "Alive and Kicking"), (2, > > "Comatose"), (3, "Dead"), ...] > > Rule of Python: XML is not the answer. XML is the question, and "NO!" > is the answer :) The nice thing about that rule is that it ports easily to so many other programming languages. Except possibly Java. Java and XML seem to be made for each other. > Your syntax there looks reasonable already. I'd recommend you make it > a flat data file, though, don't try to make it a programming language > - unless you actively need it to be one. Here are a couple of ways you > could format this. Any would be fairly easy to code a parser for. My first impression here is that YAML might work here. From rustompmody at gmail.com Thu Mar 27 23:20:34 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 27 Mar 2014 20:20:34 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334A2B1.20006@gmail.com> <76663d88-45d7-49f1-a2a4-b35120e7f963@googlegroups.com> Message-ID: <69b6b39a-d76b-42ee-85bd-1084559cffc0@googlegroups.com> On Friday, March 28, 2014 8:36:26 AM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 28, 2014 at 1:46 PM, Rustom Mody wrote: > >> Moore?s Law isn?t a mythical beast that magically materialized in 1965 > >> and threatens to unpredictably vanish at any moment. In fact, it?s > >> part of a broader ancient mechanism that has no intention of > >> stopping. This mechanism, which I call cost gravity, pulls down the > >> price of technology by about half every two years. > > Add to that the fact that cost=money ultimately comes from money=effort > > eg currencies like http://en.wikipedia.org/wiki/Ithaca_Hours > > (maybe even dolour ? dollar though thats not the official etymology) > > and its clear that there is a ripple effect of technology breaking down > > old castles. Pleasant to the* layman, unpleasant to those professionals whose > > fiefdoms are threatened. > The price of technology to the end user, yes. Anyone can go out and > buy a computer that's powerful enough to do everything the typical > person needs, and it's cheap enough to fit inside the typical person's > budget. (Compare early IBM estimates of maybe half a dozen computer > sales worldwide.) That has nothing to do with whether or not that > person can create that computer. Same goes for software. This is the continuum fallacy: http://en.wikipedia.org/wiki/Continuum_fallacy The Aunt Tillies (or your soprano)dont need to master networking as good as you do but they need to be better at it than they are. To continue the example of music: I said that using something like musescore a layman learns faster with a little guidance. And heres the catch -- most musicians who can guide in the traditional way are frightened of technology. From rosuav at gmail.com Thu Mar 27 23:30:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 14:30:36 +1100 Subject: meta language to define forms In-Reply-To: References: Message-ID: On Fri, Mar 28, 2014 at 2:13 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: >> Rule of Python: XML is not the answer. XML is the question, and "NO!" >> is the answer :) > > The nice thing about that rule is that it ports easily to so many other > programming languages. Except possibly Java. Java and XML seem to be > made for each other. The only times I have *ever* used XML, in my whole life, were when I needed to communicate with some other end that stipulated XML. (Most commonly XML payload in HTTP requests and responses, eg SOAP.) In most of those cases, some simpler structure would have sufficed; and in a number of them, XML is simply wrong for the job. >> Your syntax there looks reasonable already. I'd recommend you make it >> a flat data file, though, don't try to make it a programming language >> - unless you actively need it to be one. Here are a couple of ways you >> could format this. Any would be fairly easy to code a parser for. > > My first impression here is that YAML might work here. Good point. Add it as a fifth option! That section was already turning into a cardinal's weaponry statement. I said "a couple" and ended up with four... now five. :) ChrisA From rustompmody at gmail.com Thu Mar 27 23:44:39 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 27 Mar 2014 20:44:39 -0700 (PDT) Subject: meta language to define forms In-Reply-To: References: Message-ID: <1c5b68d5-aab1-4ed6-8306-d4dc199d7e14@googlegroups.com> On Friday, March 28, 2014 8:43:21 AM UTC+5:30, Roy Smith wrote: > Chris Angelico wrote: > > Your syntax there looks reasonable already. I'd recommend you make it > > a flat data file, though, don't try to make it a programming language > > - unless you actively need it to be one. Here are a couple of ways you > > could format this. Any would be fairly easy to code a parser for. > My first impression here is that YAML might work here. Was going to say yaml would be my first choice. The only question here is whether to use the full-featured load or safe_load which only allows builtin types. In general load allowing calling of arbitrary code is a gaping security hole. Here it may be the best choice... dunno Personally I dont like mixing code and data. Yeah lisp is fun and all that but when it starts getting at all serious its a bloody mess. [BTW I consider the windows registry cleaner than the linux /etc for the same reason] From rosuav at gmail.com Thu Mar 27 23:57:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 14:57:11 +1100 Subject: meta language to define forms In-Reply-To: <1c5b68d5-aab1-4ed6-8306-d4dc199d7e14@googlegroups.com> References: <1c5b68d5-aab1-4ed6-8306-d4dc199d7e14@googlegroups.com> Message-ID: On Fri, Mar 28, 2014 at 2:44 PM, Rustom Mody wrote: > [BTW I consider the windows registry cleaner than the linux /etc for > the same reason] And if I felt like trolling, I'd point out that there are a lot more search engine hits for "windows registry cleaner" than "linux etc cleaner". :) ChrisA From rustompmody at gmail.com Fri Mar 28 00:19:46 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 27 Mar 2014 21:19:46 -0700 (PDT) Subject: meta language to define forms In-Reply-To: References: <1c5b68d5-aab1-4ed6-8306-d4dc199d7e14@googlegroups.com> Message-ID: On Friday, March 28, 2014 9:27:11 AM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 28, 2014 at 2:44 PM, Rustom Mody wrote: > > [BTW I consider the windows registry cleaner than the linux /etc for > > the same reason] > And if I felt like trolling, I'd point out that there are a lot more > search engine hits for "windows registry cleaner" than "linux etc > cleaner". :) Probably(!) follows from the fact that one is more possible than the other. Because of http://www.w3.org/2001/tag/doc/leastPower.html From steve+comp.lang.python at pearwood.info Fri Mar 28 00:45:37 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2014 04:45:37 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> Message-ID: <5334fe71$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Mar 2014 17:14:09 -0500, Mark H Harris wrote: > People want to use their computer. They want to solve problems with > it... and frankly, they would like to know how to program it, if there > where some royal road, or fast track, or short and easy tutorial. Most people want to program their computer in the same way they want to crawl around under their car changing the grease and oil. People want to use their computer, but they would prefer the computer already have an app to solve their problem. Some will program only if that is the only way to get the computer to do what they want. Most won't even do that. If you ask the average Python-using biologist if they want to be a programmer, they will say something like "If I wanted to be a programmer, I would have done a comp sci degree. I want to be a biologist, and unfortunately having to program comes with the territory, like the other tedious jobs I have to do. I didn't do six years of college to wash test tubes or write code, but that's part of the job." > I know > lots of people that will sit down and try (with a cup of Java) and hack > it out if they have a good short book. There are seven billion people on planet Earth. If only one in ten thousand wants to program, that's still "lots of people". But in any case, we're not talking about people who want to program and are willing to read a book to learn. We are talking about this subset of people who want to program without learning to program, and in particular your insistence that they count for more than programmers who want to learn to program. [...] > Just look on the list: Fred Sells meta language request. He proves my > point entirely. If I were Fred, I'd probably be insulted by that. He clearly knows programming jargon, and can use it correctly, and he is talking about being pressed for time and short on management support, which most programmers can relate to. What reason do you have to conclude from *one* post that he's one of your non-expert non-programmer programmers? Apart from wishful thinking, of course. -- Steven D'Aprano http://import-that.dreamwidth.org/ From wuwei23 at gmail.com Fri Mar 28 02:37:18 2014 From: wuwei23 at gmail.com (alex23) Date: Fri, 28 Mar 2014 16:37:18 +1000 Subject: meta language to define forms In-Reply-To: References: Message-ID: On 28/03/2014 6:56 AM, Sells, Fred wrote: > The idea is to use a nice clean syntax like Python to define form content, then render it as HTML but only as a review tool for users, The actual rendering would go into a database to let a vendor's tool generate the form in a totally non-standard syntax that's really clunky. > > Class FyFormNumber001(GeneralForm): > Section1 = Section(title="Enter Patient Vital Signs") > Question1 = NumberQuestion(title="Enter pulse rate", format="%d3") > Question2 = Dropdown(title="Enter current status") > Question2.choices = [ (1, "Alive and Kicking"), (2, "Comatose"), (3, "Dead"), ...] > > Is there anything out there that would be close or do you have any suggestions. Are you familiar with z3c.form? https://pypi.python.org/pypi/z3c.form Given that it's part of the Zope web framework, it's fairly heavily geared towards working with HTTP requests, but it's quite possible to only use the parts that want. For your requirement, you could probably get a long way with using zope.schema for defining the forms, and then customising some of the templates to render them appropriately. The provided widgets are easily extensible, so adding support for the vendor form syntax - possibly as additional templates alongside the HTML ones - should be doable. From __peter__ at web.de Fri Mar 28 03:46:29 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 28 Mar 2014 08:46:29 +0100 Subject: Python language hack for C-style programmers [DO NOT USE!] :-) References: <20140327110856.14991bb0@bigbox.christie.dr> Message-ID: Chris Angelico wrote: > On Fri, Mar 28, 2014 at 12:44 PM, Dave Angel wrote: >>> if (array m = Regexp.split2(some_pattern, some_string)) >>> do_something(m); >>> >> >> I don't know for certain about if, but you can declare (in C++) a >> new variable in for, which is a superset of if. Scope ends when >> the for does. > > Yeah, but only a for, AFAIK. Not an if or a while. Why would you guess if you can check? Just fire up the interactive interpreter^W^W compiler: $ cat ifdecl.c #include int main() { if(int i=42) printf("%d\n", i); } $ gcc ifdecl.c ifdecl.c: In function ?main?: ifdecl.c:5:6: error: expected expression before ?int? if(int i=42) ^ ifdecl.c:6:20: error: ?i? undeclared (first use in this function) printf("%d\n", i); ^ ifdecl.c:6:20: note: each undeclared identifier is reported only once for each function it appears in $ g++ ifdecl.c $ ./a.out 42 From rosuav at gmail.com Fri Mar 28 03:51:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 18:51:13 +1100 Subject: Python language hack for C-style programmers [DO NOT USE!] :-) In-Reply-To: References: <20140327110856.14991bb0@bigbox.christie.dr> Message-ID: On Fri, Mar 28, 2014 at 6:46 PM, Peter Otten <__peter__ at web.de> wrote: > Why would you guess if you can check? Just fire up the interactive > interpreter^W^W compiler: Partly because there's a difference between valid C++ and valid input to the G++ compiler :) Knowing that it works with g++ doesn't tell me that it's actually valid, and I don't feel like digging into the specs to find out where you're guaranteed to be allowed to do that. (I could probably test it with one of the language spec options, but then it still depends on the exact version of GCC and the exact spec chosen.) ChrisA From __peter__ at web.de Fri Mar 28 04:26:05 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 28 Mar 2014 09:26:05 +0100 Subject: Python language hack for C-style programmers [DO NOT USE!] :-) References: <20140327110856.14991bb0@bigbox.christie.dr> Message-ID: Chris Angelico wrote: > On Fri, Mar 28, 2014 at 6:46 PM, Peter Otten <__peter__ at web.de> wrote: >> Why would you guess if you can check? Just fire up the interactive >> interpreter^W^W compiler: > > Partly because there's a difference between valid C++ and valid input > to the G++ compiler :) Knowing that it works with g++ doesn't tell me > that it's actually valid, and I don't feel like digging into the specs > to find out where you're guaranteed to be allowed to do that. (I could > probably test it with one of the language spec options, but then it > still depends on the exact version of GCC and the exact spec chosen.) I don't have the spec handy, only an old copy of "The C++ Programming Language" which has """ To avoid accidental misuse of a variable, it is usually a good idea to introduce the variable into the smallest scope possible [and] to delay the definition of a local variable until one can give it an initial value. [...] One of the most elegant applications of these two principles is to declare a variable in a condition. Consider: if (double d = prim(true)) { left /= d; break; } """ From rosuav at gmail.com Fri Mar 28 04:38:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Mar 2014 19:38:52 +1100 Subject: Python language hack for C-style programmers [DO NOT USE!] :-) In-Reply-To: References: <20140327110856.14991bb0@bigbox.christie.dr> Message-ID: On Fri, Mar 28, 2014 at 7:26 PM, Peter Otten <__peter__ at web.de> wrote: > One of the most elegant applications of these two principles is to > declare a variable in a condition. Consider: > > if (double d = prim(true)) { > left /= d; > break; > } Okay! Then I withdraw the "or, to my knowledge, C++" part of my original statement. It's a useful feature, if not a unique one. ChrisA From guru at digitalfantasy.it Fri Mar 28 04:44:43 2014 From: guru at digitalfantasy.it (Daniele Forghieri) Date: Fri, 28 Mar 2014 09:44:43 +0100 Subject: Using query parameters subtitution outside of execute() Message-ID: <5335367B.2090604@digitalfantasy.it> Hi to all. I'm using sqlite3 with python 2.7 on windows. I use the query substitution parameters in my query but I need to pass part of the query to a function, something like (it's not the real examples, just to clarify the question): def loadAll(cursor, id, queryAdd = None): if queryAdd is None: qry = 'select * from files where catalog = ?' else: qry = 'select * from files where catalog = ? and %s' % (queryAdd)) cursor.execute(qry, (id, )) ... I would like to use the query substitution even when I create, in another piece of code, the queryAdd part, something like: queryAdd = cursor.querySubst('enabled = ? and hide = ? and data > ?', (enabled, hidden, min_date, )) when the function take care of the date format, quoting the parameter and so on It's possible or not ? Thanks in advance Daniele Forghieri From alister.nospam.ware at ntlworld.com Fri Mar 28 05:04:07 2014 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 28 Mar 2014 09:04:07 GMT Subject: meta language to define forms Message-ID: On Fri, 28 Mar 2014 14:57:11 +1100, Chris Angelico wrote: > On Fri, Mar 28, 2014 at 2:44 PM, Rustom Mody > wrote: >> [BTW I consider the windows registry cleaner than the linux /etc for >> the same reason] > > And if I felt like trolling, I'd point out that there are a lot more > search engine hits for "windows registry cleaner" than "linux etc > cleaner". :) > > ChrisA Not to mention that the windows registry is a Single Point of failure. if it gets corrupt (by 1 minor program crashing whilst writing to it)the chances are your OS is broken to the point of being unfixable. at least with the Linux system (& the multiple config files of windows 3 & earlier) it can normaly be fixed with a simple text editor. From __peter__ at web.de Fri Mar 28 05:16:07 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 28 Mar 2014 10:16:07 +0100 Subject: Using query parameters subtitution outside of execute() References: <5335367B.2090604@digitalfantasy.it> Message-ID: Daniele Forghieri wrote: > Hi to all. I'm using sqlite3 with python 2.7 on windows. > > I use the query substitution parameters in my query but I need to pass > part of the query to a function, something like (it's not the real > examples, just to clarify the question): > > def loadAll(cursor, id, queryAdd = None): > if queryAdd is None: > qry = 'select * from files where catalog = ?' > else: > qry = 'select * from files where catalog = ? and %s' % > (queryAdd)) > > cursor.execute(qry, (id, )) > ... > > I would like to use the query substitution even when I create, in > another piece of code, the queryAdd part, something like: > > queryAdd = cursor.querySubst('enabled = ? and hide = ? and data > ?', > (enabled, hidden, min_date, )) > > when the function take care of the date format, quoting the parameter > and so on > > It's possible or not ? You can use named parameters http://docs.python.org/dev/library/sqlite3.html#cursor-objects Your function might become (untested) def load_all(cursor, parameters, condition="catalog = :id"): query = 'select * from files where ' + condition cursor.execute(query, parameters) ... load_all( cursor, dict(id=42, fromdate=datetime.date.today()), condition="catalog = :id and date >= :fromdate") From steve+comp.lang.python at pearwood.info Fri Mar 28 07:11:54 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2014 11:11:54 GMT Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> On Thu, 27 Mar 2014 20:29:17 -0400, Roy Smith wrote: > In article <5334b747$0$29994$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> On Thu, 27 Mar 2014 08:52:24 -0400, Roy Smith wrote: >> >> > In article , >> > Chris Angelico wrote: >> >> It's not "equally braindead", it follows a simple and logical rule: >> >> Only the day portion is negative. >> > >> > Simple and logical, yes. But also entirely braindead. >> >> Do you think it is "braindead" for __str__ to return something which >> follows the internal representation of the object? > > Yes. The whole idea of OOD is to decouple internal representation from > external behavior. The *whole* idea? You don't think that encapsulation and inheritance might also be involved? *wink* Besides, there's a difference between internal _representation_ and internal _implementation_. I don't always choose my words carefully, but this was one of those times :-) A timedelta object *represents* a delta as (days + seconds + microseconds). That is part of the interface, not implementation. How it is actually implemented is irrelevant. (If I were to take a wild guess, I'd predict that timedeltas record the total number of seconds.) >> > Give ma a real-life situation where you would want such behavior. >> >> Easy -- I'm debugging timedelta routines, and I want to easily see that >> the timedeltas calculated match what I expect them to be when I print >> them. The quickest, easiest and simplest way is for str(timedelta) to >> follow the internal representation. > > That's what __repr__() is for. Actually, __repr__ should, if practical, match the constructor for the object: py> import datetime py> t = datetime.timedelta(2, 3) py> eval(repr(t)) == t True >> Oh look, that's exactly what the docs say: >> >> "String representations of timedelta objects are normalized similarly >> to their internal representation. This leads to somewhat unusual >> results for negative timedeltas." > > Yes, I know that's what the docs say. That's why it's not an > implementation bug. It's a design bug :-) I don't think it is. Given a timedelta object with D days, S seconds and M microseconds, I think that it is a very useful property if the string also says it has D days, S seconds and M microseconds. Would you not agree? I think that this would be silly: str(timedelta(1, 0, 0)) => '0 day, 24:01:-5184000.0' even though it would be correct. So we can dismiss the idea that the str of a timedelta should be free to arbitrarily vary from the internal representation. I consider this to be a useful constraint on timedelta's internal representation (not implementation): the seconds and microseconds should be normalised to the half-open intervals, 0 to 86400 for seconds and 0 to 1000000 for microseconds. Given that constraint, and the previous constraint that strings should show the same number of days etc., and we have the current behaviour. Both constraints are reasonable. You have to weaken one, or the other, in order to get the result you want. That's not necessarily unreasonable, but neither is it a given. Python-Dev is not normally "braindead", so at least given them the benefit of the doubt that *maybe* there's some good reason we haven't thought of. -- Steven D'Aprano http://import-that.dreamwidth.org/ From guru at digitalfantasy.it Fri Mar 28 07:54:11 2014 From: guru at digitalfantasy.it (Daniele Forghieri) Date: Fri, 28 Mar 2014 12:54:11 +0100 Subject: Using query parameters subtitution outside of execute() In-Reply-To: References: <5335367B.2090604@digitalfantasy.it> Message-ID: <533562E3.1000400@digitalfantasy.it> Il 28/03/2014 10:16, Peter Otten ha scritto: > Daniele Forghieri wrote: > >> Hi to all. I'm using sqlite3 with python 2.7 on windows. >> >> I use the query substitution parameters in my query but I need to pass >> part of the query to a function, something like (it's not the real >> examples, just to clarify the question): >> >> def loadAll(cursor, id, queryAdd = None): >> if queryAdd is None: >> qry = 'select * from files where catalog = ?' >> else: >> qry = 'select * from files where catalog = ? and %s' % >> (queryAdd)) >> >> cursor.execute(qry, (id, )) >> ... >> >> I would like to use the query substitution even when I create, in >> another piece of code, the queryAdd part, something like: >> >> queryAdd = cursor.querySubst('enabled = ? and hide = ? and data > ?', >> (enabled, hidden, min_date, )) >> >> when the function take care of the date format, quoting the parameter >> and so on >> >> It's possible or not ? > You can use named parameters > > http://docs.python.org/dev/library/sqlite3.html#cursor-objects > > Your function might become (untested) > > def load_all(cursor, parameters, condition="catalog = :id"): > query = 'select * from files where ' + condition > cursor.execute(query, parameters) > ... > > load_all( > cursor, dict(id=42, fromdate=datetime.date.today()), > condition="catalog = :id and date >= :fromdate") > Thank. With this I can solve the problem but I have to specify the query twice and if I have to change something I need to made it everywhere I use the function and is something I would like to avoid. I also don't like very mush to pass or create a dict for a function call but that's probably me coming from old plain C ;) Daniele Forghieri From rustompmody at gmail.com Fri Mar 28 08:11:41 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 28 Mar 2014 05:11:41 -0700 (PDT) Subject: meta language to define forms In-Reply-To: References: Message-ID: On Friday, March 28, 2014 2:34:07 PM UTC+5:30, alister wrote: > On Fri, 28 Mar 2014 14:57:11 +1100, Chris Angelico wrote: > > wrote: > >> [BTW I consider the windows registry cleaner than the linux /etc for > >> the same reason] > > And if I felt like trolling, I'd point out that there are a lot more > > search engine hits for "windows registry cleaner" than "linux etc > > cleaner". :) > > ChrisA > Not to mention that the windows registry is a Single Point of failure. > if it gets corrupt (by 1 minor program crashing whilst writing to it)the > chances are your OS is broken to the point of being unfixable. > at least with the Linux system (& the multiple config files of windows 3 > & earlier) it can normaly be fixed with a simple text editor. This sure used to be true in the windows 95-98 era. I dont believe its been this way for more than a decade. XP onwards there's enough redundancy+fallback+checkpointing so that we rarely really hear of this any more [But Im not a windows guy :-)] On the other hand in linux I find that when something is upgraded and needs to upgrade *its own* config files in /etc it can often have trouble. I trace this to the fact that what is needed is mostly a simple key-value store holding some config parameters. What is stored is usually a general script. As a result http://www.w3.org/2001/tag/doc/leastPower.html kicks in. From marko at pacujo.net Fri Mar 28 08:14:48 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 28 Mar 2014 14:14:48 +0200 Subject: meta language to define forms References: Message-ID: <87a9cawmdj.fsf@elektro.pacujo.net> Rustom Mody : > On the other hand in linux I find that when something is upgraded and > needs to upgrade *its own* config files in /etc it can often have > trouble. Linux (service) configuration has given me a lot of grief as well. However, I don't thing anything should need to upgrade config files. The packaging tools leave the old config file in place, which is the right thing. The service had better support the old config file format with no interpretation changes. Marko From rustompmody at gmail.com Fri Mar 28 08:25:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 28 Mar 2014 05:25:26 -0700 (PDT) Subject: meta language to define forms In-Reply-To: <87a9cawmdj.fsf@elektro.pacujo.net> References: <87a9cawmdj.fsf@elektro.pacujo.net> Message-ID: <71797ba5-23f4-499e-aabd-e3d64c22064f@googlegroups.com> On Friday, March 28, 2014 5:44:48 PM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody wrote: > > On the other hand in linux I find that when something is upgraded and > > needs to upgrade *its own* config files in /etc it can often have > > trouble. > Linux (service) configuration has given me a lot of grief as well. > However, I don't thing anything should need to upgrade config files. Strange thing to say. There may be new config options. The defaults may be altered with good reason. This needs a new file OTOH the user may have his own old altered defaults. So integrating the two is not exactly an easy problem. And what apt does in this case is to drop you into some half-assed interactive (so-called) mode saying some file has changed -- Do you want to keep old, choose new, drop into a shell, or some other half-baked options > The packaging tools leave the old config file in place, which is the > right thing. They dont exactly do that -- see above From roy at panix.com Fri Mar 28 08:30:11 2014 From: roy at panix.com (Roy Smith) Date: Fri, 28 Mar 2014 08:30:11 -0400 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <533558fa$0$29994$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > > Yes. The whole idea of OOD is to decouple internal representation from > > external behavior. > > The *whole* idea? You don't think that encapsulation and inheritance > might also be involved? *wink* I'm not sure how "decoupling internal representation from external behavior" is substantially different from encapsulation. And, no, I don't think inheritance is a fundamental characteristic of OOD, nudge nudge. From esj at harvee.org Fri Mar 28 08:11:11 2014 From: esj at harvee.org (Eric S. Johansson) Date: Fri, 28 Mar 2014 08:11:11 -0400 Subject: meta language to define forms In-Reply-To: References: Message-ID: <533566DF.5020402@harvee.org> On 3/27/2014 4:56 PM, Sells, Fred wrote: > I'm trying to use python classes and members to define complex data entry forms as a meta language > > The idea is to use a nice clean syntax like Python to define form content, then render it as HTML but only as a review tool for users, The actual rendering would go into a database to let a vendor's tool generate the form in a totally non-standard syntax that's really clunky. I've run into a similar problem when building a framework for programming by speech and web application development. Although, my goals were different. I want to something you can create with speech recognition without too much of a vocal load or requiring extensive/specialized editor changes. One could say I was trying to make it possible to develop web apps in Microsoft Word. :-) The first attempt was a bracketed notation that was in effect a very high level domain specific notation. The next attempt is trying to eliminate the use of bracketing notation to specify scope and said use indentation. Like you, the environment consists of little bits of Python that takes what you want in the form/user interface and generates the HTML and JavaScript for presentation in action. To use your example, my notation would look something like this : Form uses section_title; Enter Patient Vital Signs uses number_question; 3, Enter pulse rate : drop_down_list uses title; Enter current status uses choices; 1, alive and kicking uses choices; 2, comatose uses choices; 3, there's another dead Bishop on the landing The: names refer to the methods that generate the code using the arguments provided by the statements within the: name definition. as refine what is your trying to do, you can make the: names more and more meta-and less and less implementation details. For example, one of the experiences that told me the bracketed notation was not going to fly was when I created a storefront for telescope shop. I created notation that expressed the work of the store not the display of the store information. Obviously the output of the notation was the display data but it operated in a way that the storekeeper understood and could take care of himself which was impossible with ordinary HTML and completely impossible if you added something like bootstrap. And before somebody kicks up a fuss About the notation, let me say that this was aimed at disabled developers who cannot type anymore or who want to listen because they cannot see. What I have created is far more productive and speakable than any of the other systems out there. --- eric From marko at pacujo.net Fri Mar 28 09:04:50 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 28 Mar 2014 15:04:50 +0200 Subject: meta language to define forms References: <87a9cawmdj.fsf@elektro.pacujo.net> <71797ba5-23f4-499e-aabd-e3d64c22064f@googlegroups.com> Message-ID: <8761mywk25.fsf@elektro.pacujo.net> Rustom Mody : > On Friday, March 28, 2014 5:44:48 PM UTC+5:30, Marko Rauhamaa wrote: >> I don't thing anything should need to upgrade config files. > > Strange thing to say. > There may be new config options. The missing options should default to the old behavior. > The defaults may be altered with good reason. Occasionally, but the reason had better be *really* good. It is like changing a programming API. You live with your bad decisions. > And what apt does in this case is to drop you into some half-assed > interactive (so-called) mode saying some file has changed -- Do you > want to keep old, choose new, drop into a shell, or some other > half-baked options RPM won't overwrite modified config files but just places the new version there next to the old one under a different name (and gives a warning). RPM isn't perfect, but that is the sane thing to do. Marko From marko at pacujo.net Fri Mar 28 09:10:15 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 28 Mar 2014 15:10:15 +0200 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871txmwjt4.fsf@elektro.pacujo.net> Roy Smith : > I'm not sure how "decoupling internal representation from external > behavior" is substantially different from encapsulation. Yes, that's encapsulation. The idea of encapsulation is older than OO. > And, no, I don't think inheritance is a fundamental characteristic of > OOD, nudge nudge. Inheritance was there with Simula so I think it's high up there with OO. If encapsulation exists outside OO and inheritance is not key to it, what is OO then, a marketing term? (It's a different thing, then, that encapsulation and inheritance are mutually exclusive principles.) Marko From rosuav at gmail.com Fri Mar 28 09:19:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 00:19:38 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <871txmwjt4.fsf@elektro.pacujo.net> References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> <871txmwjt4.fsf@elektro.pacujo.net> Message-ID: On Sat, Mar 29, 2014 at 12:10 AM, Marko Rauhamaa wrote: > If encapsulation exists outside OO and inheritance is not key to it, > what is OO then, a marketing term? > Yep, OO is a marketing term. So's programming - after all, it's just flipping bits in memory... we only pretend it means anything. Do I really exist, or do I just think I do? ChrisA From roy at panix.com Fri Mar 28 09:20:18 2014 From: roy at panix.com (Roy Smith) Date: Fri, 28 Mar 2014 09:20:18 -0400 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> <871txmwjt4.fsf@elektro.pacujo.net> Message-ID: In article <871txmwjt4.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > what is OO then, a marketing term? Sometimes, I think it must be :-) > (It's a different thing, then, that encapsulation and inheritance are > mutually exclusive principles.) There're certainly not mutually exclusive. Mutually exclusive means if you have one, you can't have the other. I think the phrase you're looking for is "orthogonal concepts". You can have either, or both, or neither, and the existence of one doesn't imply anything about the existence of the other. From roy at panix.com Fri Mar 28 09:22:15 2014 From: roy at panix.com (Roy Smith) Date: Fri, 28 Mar 2014 09:22:15 -0400 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> <871txmwjt4.fsf@elektro.pacujo.net> Message-ID: In article , Chris Angelico wrote: > On Sat, Mar 29, 2014 at 12:10 AM, Marko Rauhamaa wrote: > > If encapsulation exists outside OO and inheritance is not key to it, > > what is OO then, a marketing term? > > > > Yep, OO is a marketing term. So's programming - after all, it's just > flipping bits in memory... we only pretend it means anything. Do I > really exist, or do I just think I do? > > ChrisA The real question is, what does this print: c1 = ChrisA() c2 = ChrisA() print c1 == c2 print c2 is c2 From tanmay.kansara at gmail.com Fri Mar 28 09:27:44 2014 From: tanmay.kansara at gmail.com (tanmay.kansara at gmail.com) Date: Fri, 28 Mar 2014 06:27:44 -0700 (PDT) Subject: implementing download using a url call In-Reply-To: References: Message-ID: <31de94dd-2ed7-431b-acb8-4771fe352031@googlegroups.com> Hey Sorry, I should make it more clear. We had a 3rd party that was serving stub builds and they have their URLs on various pages(random sites). We control the sub-domain, so i can send that traffic to wherever I want. I am looking to create logic that takes that incoming parameter and serves an exe file. With the logic I posted, the user gets the file, but also gets a new blank page. I would like to keep the user on the 3rd part website. Hope this clarifies. Thanks From rosuav at gmail.com Fri Mar 28 09:32:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 00:32:48 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> <871txmwjt4.fsf@elektro.pacujo.net> Message-ID: On Sat, Mar 29, 2014 at 12:22 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Sat, Mar 29, 2014 at 12:10 AM, Marko Rauhamaa wrote: >> > If encapsulation exists outside OO and inheritance is not key to it, >> > what is OO then, a marketing term? >> > >> >> Yep, OO is a marketing term. So's programming - after all, it's just >> flipping bits in memory... we only pretend it means anything. Do I >> really exist, or do I just think I do? >> >> ChrisA > > The real question is, what does this print: > > c1 = ChrisA() > c2 = ChrisA() > print c1 == c2 > print c2 is c2 And if you could answer that, you would know whether my mother was right when, in exasperation, she would say "Your design follows the singleton principle!". Okay, so she actually was more likely to say "You are one of a kind!", but it comes to the same thing... ChrisA From rustompmody at gmail.com Fri Mar 28 09:30:17 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 28 Mar 2014 06:30:17 -0700 (PDT) Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> <871txmwjt4.fsf@elektro.pacujo.net> Message-ID: <5533a78f-c1e0-4d83-81c0-d790106ec9bd@googlegroups.com> On Friday, March 28, 2014 6:52:15 PM UTC+5:30, Roy Smith wrote: > Chris Angelico wrote: > > On Sat, Mar 29, 2014 at 12:10 AM, Marko Rauhamaa wrote: > > > If encapsulation exists outside OO and inheritance is not key to it, > > > what is OO then, a marketing term? > > Yep, OO is a marketing term. So's programming - after all, it's just > > flipping bits in memory... we only pretend it means anything. Do I > > really exist, or do I just think I do? > > ChrisA > The real question is, what does this print: > c1 = ChrisA() > c2 = ChrisA() > print c1 == c2 > print c2 is c2 OO is of course a marketing term Unicode OTOH is the real cure for all diseases Proof by example: Replace the last with print c2 ? c2 or even better print c2 ? c2 No confusion any more... See? We all know now who (what?) Chris is! From __peter__ at web.de Fri Mar 28 09:53:06 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 28 Mar 2014 14:53:06 +0100 Subject: Using query parameters subtitution outside of execute() References: <5335367B.2090604@digitalfantasy.it> <533562E3.1000400@digitalfantasy.it> Message-ID: Daniele Forghieri wrote: > Il 28/03/2014 10:16, Peter Otten ha scritto: >> Daniele Forghieri wrote: >> >>> Hi to all. I'm using sqlite3 with python 2.7 on windows. >>> >>> I use the query substitution parameters in my query but I need to pass >>> part of the query to a function, something like (it's not the real >>> examples, just to clarify the question): >>> >>> def loadAll(cursor, id, queryAdd = None): >>> if queryAdd is None: >>> qry = 'select * from files where catalog = ?' >>> else: >>> qry = 'select * from files where catalog = ? and %s' % >>> (queryAdd)) >>> >>> cursor.execute(qry, (id, )) >>> ... >>> >>> I would like to use the query substitution even when I create, in >>> another piece of code, the queryAdd part, something like: >>> >>> queryAdd = cursor.querySubst('enabled = ? and hide = ? and data > ?', >>> (enabled, hidden, min_date, )) >>> >>> when the function take care of the date format, quoting the parameter >>> and so on >>> >>> It's possible or not ? >> You can use named parameters >> >> http://docs.python.org/dev/library/sqlite3.html#cursor-objects >> >> Your function might become (untested) >> >> def load_all(cursor, parameters, condition="catalog = :id"): >> query = 'select * from files where ' + condition >> cursor.execute(query, parameters) >> ... >> >> load_all( >> cursor, dict(id=42, fromdate=datetime.date.today()), >> condition="catalog = :id and date >= :fromdate") >> > > Thank. With this I can solve the problem but I have to specify the > query twice and if I have to change something I need to made it > everywhere I use the function and is something I would like to avoid. How about that one: def query_subst(sql, parameters): return sql, parameters def load_all(cursor, id, query_add=None): query = 'select * from files where catalog = ?' parameters = (id,) if query_add is not None: query += " and " + query_add[0] parameters += query_add[1] cursor.execute(query, parameters) ... enabled = True hidden = False min_date = datetime.date.today() query_add = query_subst( 'enabled = ? and hide = ? and date > ?', (enabled, hidden, min_date)) load_all(cs, 42, query_add) > I also don't like very mush to pass or create a dict for a function > call but that's probably me coming from old plain C ;) Get over it ;) From guru at digitalfantasy.it Fri Mar 28 10:16:05 2014 From: guru at digitalfantasy.it (Daniele Forghieri) Date: Fri, 28 Mar 2014 15:16:05 +0100 Subject: Using query parameters subtitution outside of execute() In-Reply-To: References: <5335367B.2090604@digitalfantasy.it> <533562E3.1000400@digitalfantasy.it> Message-ID: <53358425.5020109@digitalfantasy.it> Il 28/03/2014 14:53, Peter Otten ha scritto: > Daniele Forghieri wrote: > >> Il 28/03/2014 10:16, Peter Otten ha scritto: >>> Daniele Forghieri wrote: >>> >>>> Hi to all. I'm using sqlite3 with python 2.7 on windows. >>>> >>>> I use the query substitution parameters in my query but I need to pass >>>> part of the query to a function, something like (it's not the real >>>> examples, just to clarify the question): >>>> >>>> def loadAll(cursor, id, queryAdd = None): >>>> if queryAdd is None: >>>> qry = 'select * from files where catalog = ?' >>>> else: >>>> qry = 'select * from files where catalog = ? and %s' % >>>> (queryAdd)) >>>> >>>> cursor.execute(qry, (id, )) >>>> ... >>>> >>>> I would like to use the query substitution even when I create, in >>>> another piece of code, the queryAdd part, something like: >>>> >>>> queryAdd = cursor.querySubst('enabled = ? and hide = ? and data > ?', >>>> (enabled, hidden, min_date, )) >>>> >>>> when the function take care of the date format, quoting the parameter >>>> and so on >>>> >>>> It's possible or not ? >>> You can use named parameters >>> >>> http://docs.python.org/dev/library/sqlite3.html#cursor-objects >>> >>> Your function might become (untested) >>> >>> def load_all(cursor, parameters, condition="catalog = :id"): >>> query = 'select * from files where ' + condition >>> cursor.execute(query, parameters) >>> ... >>> >>> load_all( >>> cursor, dict(id=42, fromdate=datetime.date.today()), >>> condition="catalog = :id and date >= :fromdate") >>> >> Thank. With this I can solve the problem but I have to specify the >> query twice and if I have to change something I need to made it >> everywhere I use the function and is something I would like to avoid. > How about that one: > > def query_subst(sql, parameters): > return sql, parameters > > def load_all(cursor, id, query_add=None): > query = 'select * from files where catalog = ?' > parameters = (id,) > if query_add is not None: > query += " and " + query_add[0] > parameters += query_add[1] > cursor.execute(query, parameters) > ... > > enabled = True > hidden = False > min_date = datetime.date.today() > > query_add = query_subst( > 'enabled = ? and hide = ? and date > ?', > (enabled, hidden, min_date)) > > load_all(cs, 42, query_add) This one is, IMHO, cleaner and more manageable! Thank you very very much, I really appreciate your help. >> I also don't like very mush to pass or create a dict for a function >> call but that's probably me coming from old plain C ;) > Get over it ;) > > I'm trying but the old habits comes out, the first time I need to parse a string I do it like in C, looking at every single char using a couple of help function: the performance were really horrible, the memory used was huge than I change the way I do things (and start to use sqlite3 to store my data instead of using text files, parsed by a proprietary lib). The worse is the contrary, when I must use C and I think 'Here I use a dictionary, at the end convert it in a list that I sort with that key ...' only to realize that I don't have dictionary and the list I can use are very less manageable that the ones I used in Python ... It seems to me that going from C to Python you start writing inefficient code or write more lines than an average Python programmer but 'something moves' and the result happens. Moving from Python to C I always feel like I missed something and the first approach, good for Python, is simply not working in C ;( Thanks again Daniele Forghieri From marko at pacujo.net Fri Mar 28 10:34:36 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 28 Mar 2014 16:34:36 +0200 Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> <871txmwjt4.fsf@elektro.pacujo.net> Message-ID: <87ob0qv1c3.fsf@elektro.pacujo.net> Roy Smith : > There're certainly not mutually exclusive. Mutually exclusive means if > you have one, you can't have the other. Correct. The classic inheritance diamond: class A(B, C): def add_bean(self): ??? # how to implement class B(D): pass class C(D): pass class D: def __init__(self): self.beans = 0 def add_bean(self): self.beans += 1 def bean_count(self): return self.beans cannot be dealt with without A addressing the common base class D. And once it deals with it, A can be broken by reimplementing C without inheriting it from D: class C: def __init__(self): self.beans = "" def add_bean(self): self.beans += "o" def bean_count(self): return len(self.beans) thus violating encapsulation. Marko From steve+comp.lang.python at pearwood.info Fri Mar 28 10:35:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2014 14:35:15 GMT Subject: YADTR (Yet Another DateTime Rant) References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533588a3$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Mar 2014 08:30:11 -0400, Roy Smith wrote: > In article <533558fa$0$29994$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> > Yes. The whole idea of OOD is to decouple internal representation >> > from external behavior. >> >> The *whole* idea? You don't think that encapsulation and inheritance >> might also be involved? *wink* > > I'm not sure how "decoupling internal representation from external > behavior" is substantially different from encapsulation. They are mostly unrelated. In the first, you're talking about information hiding. The second, encapsulation, relates to the bundling of code and data, optionally in such a way as to restrict or control access to some or all of the encapsulated data. Encapsulation can be used as a mechanism for information hiding, but need not be. https://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29 > And, no, I > don't think inheritance is a fundamental characteristic of OOD, nudge > nudge. That's not representative of what most people, and specifically most computer scientists, consider fundamental to OOP. https://en.wikipedia.org/wiki/Object-oriented_programming#Fundamental_features_and_concepts It's difficult to pin-point exactly what characteristics of OOP are fundamental, but inheritance is surely one of them. -- Steven D'Aprano http://import-that.dreamwidth.org/ From neilc at norwich.edu Fri Mar 28 11:00:38 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Fri, 28 Mar 2014 15:00:38 +0000 (UTC) Subject: Using query parameters subtitution outside of execute() References: <5335367B.2090604@digitalfantasy.it> <533562E3.1000400@digitalfantasy.it> <53358425.5020109@digitalfantasy.it> Message-ID: On 2014-03-28, Daniele Forghieri wrote: > The worse is the contrary, when I must use C and I think 'Here > I use a dictionary, at the end convert it in a list that I sort > with that key ...' only to realize that I don't have dictionary > and the list I can use are very less manageable that the ones I > used in Python ... C could provide more friendly general purpose containers in its library, but doesn't. There are some good free ones: glib, for example. Cython provides a really nice in-between level. -- Neil Cerutti From rosuav at gmail.com Fri Mar 28 11:25:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 02:25:44 +1100 Subject: YADTR (Yet Another DateTime Rant) In-Reply-To: <533588a3$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <53336df8$0$29994$c3e8da3$5496439d@news.astraweb.com> <5334b747$0$29994$c3e8da3$5496439d@news.astraweb.com> <533558fa$0$29994$c3e8da3$5496439d@news.astraweb.com> <533588a3$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 29, 2014 at 1:35 AM, Steven D'Aprano wrote: > It's difficult to pin-point exactly what characteristics of OOP are > fundamental, but inheritance is surely one of them. I've always understood OOP to be all about binding code and data together (methods as part of an object, rather than functions operating on data) - ie polymorphism, such that you say "do this" and the object knows how its "do this" should be done. That's at least as important as inheritance IMO. But yes, it is very hard to pin it down. ChrisA From Bernd-Waterkamp at web.de Fri Mar 28 14:21:21 2014 From: Bernd-Waterkamp at web.de (Bernd Waterkamp) Date: Fri, 28 Mar 2014 19:21:21 +0100 Subject: CentOS 6.5 / SPEC file References: <53349787.3080301@gmail.com> Message-ID: Michael Torrie schrieb: > I should add, that the only correct way to package Python 3 on RHEL 6 is > by making the package called "python3" or something that won't collide > with the system Python 2.x package. Another option for Fedora and RHEL6: Software Collections http://developerblog.redhat.com/2014/02/18/migrate-to-python3-w-rhscl/ https://fedorahosted.org/SoftwareCollections/ From random832 at fastmail.us Fri Mar 28 14:55:45 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 28 Mar 2014 14:55:45 -0400 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> Message-ID: <1396032945.6439.100149669.161EB9FB@webmail.messagingengine.com> On Thu, Mar 27, 2014, at 11:10, Rustom Mody wrote: > Just out of curiosity how do/did you type that? > When I see an exotic denizen from the unicode-universe I paste it into > emacs and ask "Who are you?" > > But with your 'def' my emacs is going a bit crazy! Your emacs probably is using UCS-2 or UTF-16. The former can't handle characters above 65535 at all, the latter stores them as if they were two characters [so code that's not expecting them will handle them incorrectly] From harrismh777 at gmail.com Fri Mar 28 17:18:25 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 16:18:25 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/27/14 7:34 PM, Steven D'Aprano wrote: > As for enormous number of users who will have > difficulty typing ? in their source code, they certainly don't count! > It's good enough that *you* have a solution to that problem, you can type > alt-v, and anyone who can't simply doesn't matter. You have an interesting point here; more interesting perhaps than you know. We have a unicode system [1] capable of zillions of characters, and most of [us] have some qwerty system keyboard [104 keys?] with meta key mappings for a few more. Talk about the cart before the horse. We need a standard input system not controlled by Microsoft where-by everyone in the entire world can enter unicode (with customization) easily and inexpensively. A unicode keyboard would be nice. Why must everyone in the world be stuck with a U.S. Royal typewriter keyboard for two or three hundred years? Dvorak had the right idea; but it didn't stick (although I have a Dvorak key mapping I use (with emacs) just for fun). I do care, Steven. You'll never ever hear me say "screw" somebody, not because I'm holier than thou, but because everyone counts--everyone. Your point about the biologist is fabulous (my point as well), "I didn't study biology for six years to wash test tubes and program computers, but it comes with the territory". Steven, dude, you proved my point with that. Most biologists (academics particularly) are studying systems that require computers these days--- and the scientists in that field DO want to program computers (I didn't say love) and the "want" is powerful. I didn't say that they "liked it" either. Somehow a biologist needs to be able to talk to that goofy machine (which they hate) and be able to do so efficiently and I dare say rapidly. There needs to be a system for them; general, easy, elegant yet comprehensible, flexible yet unified, discrete, simplified (without being oversimplified). wow. Talk development requirements. marcus [1] http://www.unicode.org/standard/where/ From harrismh777 at gmail.com Fri Mar 28 17:56:37 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 16:56:37 -0500 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) Message-ID: On Fri, Mar 21, 2014 at 1:42 PM, vasudevram wrote: >> Can anyone - maybe one of the Python language core team, or someone >> with knowledge of the internals of Python - can explain why this >> code works, and whether the different occurrences of the name x in >> the expression, are in different scopes or not? : >> >> x = [[1,2], [3,4], [5,6]] >> [x for x in x for x in x] > I'll give this +1 for playfulness, and -2 for lack of clarity. > I hope no one thinks this sort of thing is good to do in real-life code. No. This has to be a better way to flatten lists: >>> from functools import reduce >>> import operator as ? >>> reduce(?.add, l) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> marcus From harrismh777 at gmail.com Fri Mar 28 18:00:27 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 17:00:27 -0500 Subject: How to flatten a list of lists was (Explanation of this Python language feature?) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Message-ID: <5335F0FB.3040904@gmail.com> On 3/27/14 6:45 PM, Dan Stromberg wrote: > On Fri, Mar 21, 2014 at 1:42 PM, vasudevram wrote: >> Can anyone - maybe one of the Python language core team, >>or someone with knowledge of the internals of Python - can >>explain why this code works, and whether the different >>occurrences of the name x in the expression, are in >>different scopes or not? : >> >> x = [[1,2], [3,4], [5,6]] >> [x for x in x for x in x] > > I'll give this +1 for playfulness, and -2 for lack of clarity. > > I hope no one thinks this sort of thing is good to do in real-life code. > You might try this to flatten a list of lists: >>> from functools import reduce >>> import operator >>> import operator as ? >>> reduce(?.add, l) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> marcus From harrismh777 at gmail.com Fri Mar 28 18:00:27 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 17:00:27 -0500 Subject: How to flatten a list of lists was (Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Message-ID: <5335F0FB.3040904@gmail.com> On 3/27/14 6:45 PM, Dan Stromberg wrote: > On Fri, Mar 21, 2014 at 1:42 PM, vasudevram wrote: >> Can anyone - maybe one of the Python language core team, >>or someone with knowledge of the internals of Python - can >>explain why this code works, and whether the different >>occurrences of the name x in the expression, are in >>different scopes or not? : >> >> x = [[1,2], [3,4], [5,6]] >> [x for x in x for x in x] > > I'll give this +1 for playfulness, and -2 for lack of clarity. > > I hope no one thinks this sort of thing is good to do in real-life code. > You might try this to flatten a list of lists: >>> from functools import reduce >>> import operator >>> import operator as ? >>> reduce(?.add, l) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> marcus From harrismh777 at gmail.com Fri Mar 28 18:05:15 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 17:05:15 -0500 Subject: To flatten a nested list was (Explanation of this Python language feature? [x for x in x for x in x] In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Message-ID: <5335F21B.1060702@gmail.com> On 3/27/14 6:45 PM, Dan Stromberg wrote: >> >> x = [[1,2], [3,4], [5,6]] >> [x for x in x for x in x] > > I'll give this +1 for playfulness, and -2 for lack of clarity. > > I hope no one thinks this sort of thing is good to do in real-life code. > You might try this to flatten a list of lists: >>> from functools import reduce >>> L = [[1,2,3],[4,5,6],[7],[8,9]] >>> import operator as ? >>> reduce(?.add, L) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> marcus From harrismh777 at gmail.com Fri Mar 28 18:05:15 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 17:05:15 -0500 Subject: To flatten a nested list was (Explanation of this Python language feature? [x for x in x for x in x] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Message-ID: <5335F21B.1060702@gmail.com> On 3/27/14 6:45 PM, Dan Stromberg wrote: >> >> x = [[1,2], [3,4], [5,6]] >> [x for x in x for x in x] > > I'll give this +1 for playfulness, and -2 for lack of clarity. > > I hope no one thinks this sort of thing is good to do in real-life code. > You might try this to flatten a list of lists: >>> from functools import reduce >>> L = [[1,2,3],[4,5,6],[7],[8,9]] >>> import operator as ? >>> reduce(?.add, L) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> marcus From breamoreboy at yahoo.co.uk Fri Mar 28 18:12:33 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 28 Mar 2014 22:12:33 +0000 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) In-Reply-To: References: Message-ID: On 28/03/2014 21:56, Mark H Harris wrote: > On Fri, Mar 21, 2014 at 1:42 PM, vasudevram wrote: > >> Can anyone - maybe one of the Python language core team, or someone > >> with knowledge of the internals of Python - can explain why this >> > code works, and whether the different occurrences of the name x in >> > the expression, are in different scopes or not? : > >> > >> x = [[1,2], [3,4], [5,6]] > >> [x for x in x for x in x] > > > I'll give this +1 for playfulness, and -2 for lack of clarity. > > > I hope no one thinks this sort of thing is good to do in real-life code. Strange, I thought Dan Stromberg wrote the above. > > No. This has to be a better way to flatten lists: > > >>> from functools import reduce > > >>> import operator as ? > > >>> reduce(?.add, l) > [1, 2, 3, 4, 5, 6, 7, 8, 9] > Why reinvent yet another way of flattening lists, particulary one that doesn't use the far more sensible:- from operator import add As for the stupid symbol that you're using, real programmers don't give a damn about such things, they prefer writing plain, simple, boring code that is easy to read. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From harrismh777 at gmail.com Fri Mar 28 18:23:51 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 17:23:51 -0500 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) In-Reply-To: References: Message-ID: <5335F677.20605@gmail.com> On 3/28/14 5:12 PM, Mark Lawrence wrote: >> >> No. This has to be a better way to flatten lists: >> >> >>> from functools import reduce >> >> >>> import operator as ? >> >> >>> reduce(?.add, l) >> [1, 2, 3, 4, 5, 6, 7, 8, 9] >> > > Why reinvent yet another way of flattening lists, particulary one that > doesn't use the far more sensible:- { particularly } > > from operator import add > > As for the stupid symbol that you're using, real programmers don't give > a damn about such things, they prefer writing plain, simple, boring code > that is easy to read. :-)) as RMS would say, "playful hacking, dude, playful hacking..." From harrismh777 at gmail.com Fri Mar 28 18:23:51 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 17:23:51 -0500 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) References: Message-ID: <5335F677.20605@gmail.com> On 3/28/14 5:12 PM, Mark Lawrence wrote: >> >> No. This has to be a better way to flatten lists: >> >> >>> from functools import reduce >> >> >>> import operator as ? >> >> >>> reduce(?.add, l) >> [1, 2, 3, 4, 5, 6, 7, 8, 9] >> > > Why reinvent yet another way of flattening lists, particulary one that > doesn't use the far more sensible:- { particularly } > > from operator import add > > As for the stupid symbol that you're using, real programmers don't give > a damn about such things, they prefer writing plain, simple, boring code > that is easy to read. :-)) as RMS would say, "playful hacking, dude, playful hacking..." From steve+comp.lang.python at pearwood.info Fri Mar 28 22:31:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2014 02:31:36 GMT Subject: To flatten a nested list was (Explanation of this Python language feature? [x for x in x for x in x] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5335F21B.1060702@gmail.com> Message-ID: <53363088$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Mar 2014 17:05:15 -0500, Mark H Harris wrote: > You might try this to flatten a list of lists: We got that the first four times you posted it. No need for a fifth. > >>> from functools import reduce > >>> L = [[1,2,3],[4,5,6],[7],[8,9]] > >>> import operator as ? Why would you name the operator module the Greek letter l? Why not the Armenian letter ? (yiwn)? That's pure obfuscation. The operator module has nothing to do with "l", and nothing to do with Greek lambda. This is exactly the sort of foolish obfuscation that opponents warned about when Python first introduced support for non-ASCII identifiers. > >>> reduce(?.add, L) > [1, 2, 3, 4, 5, 6, 7, 8, 9] Furthermore, this is a very inefficient way of flattening a nested list. Doubling the size of the list quadruples the time taken; increasing the size by a factor of 10 increases the time by a factor of more than 100: py> from operator import add py> from functools import reduce py> L = [[1]]*10000 py> with Stopwatch(): # code for this available on request ... x = reduce(add, L) ... time taken: 0.348851 seconds py> L = [[1]]*100000 py> with Stopwatch(): ... x = reduce(add, L) ... time taken: 41.344467 seconds -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Fri Mar 28 22:33:06 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2014 02:33:06 GMT Subject: Howto flaten a list of lists was (Explanation of this Python language feature) References: <5335F677.20605@gmail.com> Message-ID: <533630e2$0$29994$c3e8da3$5496439d@news.astraweb.com> Mark, please stop posting to the newsgroup comp.lang.python AND the mailing list python-list at python.org. They mirror each other. Your posts are not so important that we need to see everything twice. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Fri Mar 28 22:45:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 13:45:12 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 29, 2014 at 8:18 AM, Mark H Harris wrote: > We have a unicode system [1] capable of zillions of characters, and most of > [us] have some qwerty system keyboard [104 keys?] with meta key mappings for > a few more. Talk about the cart before the horse. > > We need a standard input system not controlled by Microsoft... ... uhh... how does the QWERTY system demonstrate Microsoft's control?? There's more than a hundred years of gap between them, and in the wrong order. By the way, thanks for telling me what a zillion is. It must be 65536, because that's the biggest thing Unicode gives us plural of in number of characters. :) Considering that we have ten fingers, having 1114112 keys would be quite impractical. The smallest number of keys to render that many characters would probably be 21, but it'd be toggling data into a computer, rather than typing; *every* character would require holding down a good number of keys. (Or you could go the other way and have exactly two keys: 1 and 0. Press either 21 times to enter a single character.) You'd probably need a minimum of several hundred keys to get something reasonably logical. Do you really want a keyboard that takes up that much space? Most people can't efficiently use F1 through F12, much less another hundred or two hundred keys. ChrisA From harrismh777 at gmail.com Fri Mar 28 23:04:19 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 22:04:19 -0500 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) References: <5335F677.20605@gmail.com> <533630e2$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 9:33 PM, Steven D'Aprano wrote: > Mark, please stop posting to the newsgroup comp.lang.python AND the > mailing list python-list at python.org. They mirror each other. Your posts > are not so important that we need to see everything twice. Its not my fault, Steven. Something goofy is going on. My address says only comp.lang.python I have no idea why some of these messages are being duplicated on the mailing list. I only post to the news group. Anyways, sorry. I'll keep checking this. regards, From steve+comp.lang.python at pearwood.info Fri Mar 28 23:08:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2014 03:08:15 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5336391f$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Mar 2014 13:45:12 +1100, Chris Angelico wrote: > Considering that we have ten fingers, having 1114112 keys would be quite > impractical. The smallest number of keys to render that many characters > would probably be 21, but it'd be toggling data into a computer, rather > than typing; *every* character would require holding down a good number > of keys. (Or you could go the other way and have exactly two keys: 1 and > 0. Press either 21 times to enter a single character.) http://like-a-boss.org/wp-content/uploads/2011/10/supercoder.jpg -- Steven D'Aprano http://import-that.dreamwidth.org/ From harrismh777 at gmail.com Fri Mar 28 23:18:36 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 22:18:36 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 9:45 PM, Chris Angelico wrote: > On Sat, Mar 29, 2014 at 8:18 AM, Mark H Harris wrote: >> We have a unicode system [1] capable of zillions of characters, and most of >> [us] have some qwerty system keyboard [104 keys?] with meta key mappings for >> a few more. Talk about the cart before the horse. >> >> We need a standard input system not controlled by Microsoft... > > ... uhh... how does the QWERTY system demonstrate Microsoft's > control?? There's more than a hundred years of gap between them, and > in the wrong order. You know the answer to this question. Does your keyboard have the "Windows" emblem|logo on the meta key(s) on lower right, lower left? On a standard keyboard its the meta key between ctrl and alt. Microsoft has controlled that meta section of the keyboard for years, effectively preventing those keys from being used for unicode meta control keys (ironical considering the fact the Microsoft is a major player at the unicode consortium). The meta keyboard on the mac is much more of what I have in mind, but that's mac only for now. > By the way, thanks for telling me what a zillion is. It must be 65536, > because that's the biggest thing Unicode gives us plural of in number > of characters. :) ha! :-)) A zillion is 65536 x(several thousand languages). Actually I used a zillion because the consortium doesn't even put a number on it... because there is a difference between script and language, and there are many languages that use Latin. The point is its a huge number greater than 128 or 256. (or 104) > > Considering that we have ten fingers, having 1114112 keys would be > quite impractical. don't be literal, think meta pages (key mappings) over the actual keyboard, but think "standards". > Do you really want a keyboard that takes up that much space? Most > people can't efficiently use F1 through F12, much less another hundred > or two hundred keys. No, I want a standard unicode keyboard (a standard specification for a unicode keyboard) that facilitates unicode typing with minimal actual keys and standard key maps for alternate sets that may be easily selected without a mouse and without moving the hands from the home row. The mac does a pretty good job of this now, but the mapping editor is not built-in; otherwise, the key mappings are very good, quite easy, and very fast. But, like Steven pointed out, everyone needs to be on the same unicode input device (as standard) before language specs could relay on certain code points for tokens | identifiers. marcus From rosuav at gmail.com Fri Mar 28 23:21:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 14:21:46 +1100 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) In-Reply-To: References: <5335F677.20605@gmail.com> <533630e2$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 29, 2014 at 2:04 PM, Mark H Harris wrote: > Its not my fault, Steven. Something goofy is going on. My address says only > comp.lang.python Well, something's causing your messages to come out multiple times and with different subject lines :) ChrisA From rustompmody at gmail.com Fri Mar 28 23:21:36 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 28 Mar 2014 20:21:36 -0700 (PDT) Subject: Howto flaten a list of lists was (Explanation of this Python language feature) In-Reply-To: References: <5335F677.20605@gmail.com> <533630e2$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <95aa5148-497a-49a1-9e78-2c019c36cf25@googlegroups.com> On Saturday, March 29, 2014 8:34:19 AM UTC+5:30, Mark H. Harris wrote: > On 3/28/14 9:33 PM, Steven D'Aprano wrote: > > Mark, please stop posting to the newsgroup comp.lang.python AND the > > mailing list (...). They mirror each other. Your posts > > are not so important that we need to see everything twice. > Its not my fault, Steven. Something goofy is going on. My address says > only comp.lang.python > I have no idea why some of these messages are being duplicated on the > mailing list. I only post to the news group. > Anyways, sorry. I'll keep checking this. > regards, Just use the amazing, fool-safe, fail-proof google-groups. And enjoy bliss. [Uh... And now I need to run... Out of sprinting practice...] From harrismh777 at gmail.com Fri Mar 28 23:33:59 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 22:33:59 -0500 Subject: To flatten a nested list was (Explanation of this Python language feature? [x for x in x for x in x] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <5335F21B.1060702@gmail.com> <53363088$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 9:31 PM, Steven D'Aprano wrote: > On Fri, 28 Mar 2014 17:05:15 -0500, Mark H Harris wrote: >> >>> from functools import reduce >> >>> L = [[1,2,3],[4,5,6],[7],[8,9]] >> >>> import operator as ? >> >>> reduce(?.add, L) >> [1, 2, 3, 4, 5, 6, 7, 8, 9] > > Furthermore, this is a very inefficient way of flattening a nested list. Again, its just another way. Its just playful hacking. The serious point behind it ( I am able to do anything I want with the language ), I mean that is kinda the whole point. For anyone to actually use my little hack they need to know that reduce is in functools (right) then they need to understand 'reduce' which is a nightmare, and then they need to know why chose the symbol ? (which was for no other reason than fun. Lastly, they would want to flatten a list without [x for x in x for x in x] :) The following is a strawman; YOU build it up, to tear it down/ > py> from operator import add > py> from functools import reduce > py> L = [[1]]*10000 <=================== my list didn't have ten thousand items > py> with Stopwatch(): # code for this available on request > ... x = reduce(add, L) > ... > time taken: 0.348851 seconds > py> L = [[1]]*100000 <============= much less one hundred thousand items > py> with Stopwatch(): > ... x = reduce(add, L) > ... > time taken: 41.344467 seconds <==== time is an illusion, ask Einstein/ (Steven, it was all tongue in cheek, just for fun... ) From harrismh777 at gmail.com Fri Mar 28 23:39:01 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 22:39:01 -0500 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) References: <5335F677.20605@gmail.com> <533630e2$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 10:21 PM, Chris Angelico wrote: > Well, something's causing your messages to come out multiple times and > with different subject lines :) I changed the subject line ( which I did twice because the first post said it had an error and did not post; which apparently was a lie). Then I posted again (this time it went without error, but came back duplicated. In any case ONLY the news group was in the to: field. Very strange. All of this crap started happening a couple of days back when Thunderbird updated their client (I should know better than to accept that). Anyway, things were supposed to be better once I switched from gg. uh, huh. Well, at least the line wrapping thing is fixed. marcus From rosuav at gmail.com Fri Mar 28 23:45:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 14:45:29 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 29, 2014 at 2:18 PM, Mark H Harris wrote: > On 3/28/14 9:45 PM, Chris Angelico wrote: >> ... uhh... how does the QWERTY system demonstrate Microsoft's >> control?? There's more than a hundred years of gap between them, and >> in the wrong order. > > > You know the answer to this question. Does your keyboard have the > "Windows" emblem|logo on the meta key(s) on lower right, lower left? On a > standard keyboard its the meta key between ctrl and alt. Microsoft has > controlled that meta section of the keyboard for years, effectively > preventing those keys from being used for unicode meta control keys > (ironical considering the fact the Microsoft is a major player at the > unicode consortium). The meta keyboard on the mac is much more of what I > have in mind, but that's mac only for now. No, actually. A lot of my keyboards don't have those, and even those that do aren't controlled by Microsoft. We've been using those for other purposes since they first came out. To claim that they indicate MS control is just as ridiculous as claiming that the Backspace key indicates control from the Remington Typewriter Company. >> By the way, thanks for telling me what a zillion is. It must be 65536, >> because that's the biggest thing Unicode gives us plural of in number >> of characters. :) > > > ha! :-)) A zillion is 65536 x(several thousand languages). Actually I > used a zillion because the consortium doesn't even put a number on it... > because there is a difference between script and language, and there are > many languages that use Latin. The point is its a huge number greater than > 128 or 256. (or 104) > >> >> Considering that we have ten fingers, having 1114112 keys would be >> quite impractical. > > > don't be literal, think meta pages (key mappings) over the actual > keyboard, but think "standards". The Unicode standard specifies only 1114112 possible codepoints, of which only roughly 200K are currently allocated. (And those figures include non-character codepoints, like the U+D800 to U+DFFF range used to encode non-BMP codepoints into UTF-16.) So you can't possibly need any more than that - just over a million - for full Unicode support. That's standards for you. >> Do you really want a keyboard that takes up that much space? Most >> people can't efficiently use F1 through F12, much less another hundred >> or two hundred keys. > > No, I want a standard unicode keyboard (a standard specification for a > unicode keyboard) that facilitates unicode typing with minimal actual keys > and standard key maps for alternate sets that may be easily selected without > a mouse and without moving the hands from the home row. Minimal actual keys. Steven almost got it with the link he posted above, but I can cut one more key off it: if you always press exactly 21 keys to enter one codepoint, you don't need a "Done" key. (But the "Done" key would allow you to type some characters much more quickly. You can send a spew of U+0000 just by holding Done, for instance; and what an accomplishment THAT is in a family man! [1]) > The mac does a pretty good job of this now, but the mapping editor is not > built-in; otherwise, the key mappings are very good, quite easy, and very > fast. But, like Steven pointed out, everyone needs to be on the same unicode > input device (as standard) before language specs could relay on certain code > points for tokens | identifiers. If that idealized Unicode keyboard were worth doing, it would have been done by now. There are myriad keyboard designs to choose from, like these: http://www.thinkgeek.com/brain/whereisit.cgi?t=keyboard None has the hundreds of keys needed for rapid entry of arbitrary Unicode codepoints or characters (in theory you could have a key that creates a full CCS). Why? Because there's no demand for it. ChrisA [1] Look up Gilbert & Sullivan's "Ruddigore" for a very similar line of argument regarding a sailor. From steve+comp.lang.python at pearwood.info Fri Mar 28 23:51:04 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2014 03:51:04 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Mar 2014 16:18:25 -0500, Mark H Harris wrote: > We need a standard input system not controlled by Microsoft where-by > everyone in the entire world can enter unicode (with customization) > easily and inexpensively. A unicode keyboard would be nice. Under what circumstances do you see yourself needing a keyboard capable of typing Hindi? I don't wish to pay for a keyboard for entering Arabic when I'm never going to enter more than two or three Arabic characters at a time. If I need to enter an Arabic character, I can use one of many existing virtual keyboards. If I decide to learn Arabic, I will use my current keyboard (perhaps with new keycaps) and switch to a different keyboard layout. I don't think that an English-speaker who needs to occasionally enter a few characters like ? ? or ?, a mathematician who knows TeX, a Russian wanting to type in Cyrillic, and a Japanese writer who needs to swap between four different writing systems (Kanji, Hiragana, Katakana, and R?maji) are all going to be well-suited by any one system. I expect that it will end up being one-size-fits-none. > Why must > everyone in the world be stuck with a U.S. Royal typewriter keyboard for > two or three hundred years? You are being patronising to the 94% of the world that is not from the USA. Do you honestly think that people all over the world have been using computers for 30 or 40 years without any way to enter their native language? Before trying to speak for everyone in the world, it would be a good idea to learn something about their situation first. People are not stuck with the US Royal typewriter keyboard. Keyboards are localised all over the world. I'm not just talking about European keyboards mostly similar to US keyboards but with a few customizations. I'm talking about keyboards for entering Chinese and Japanese: http://www.keysourcechina.com/chinese-keyboard.html http://www.stanford.edu/class/cs140/projects/pintos/specs/kbd/jp106.jpg although I'm pretty sure this is a joke: http://propelsteps.boards.net/thread/27/creative-chinese-keyboard-2000-symbols When you install Linux, one of the first things the installer asks you to do is choose a keyboard layout. The choices are *not* just: US Qwerty US Dvorak but one of a large variety of keyboard layouts. On my system, there are a least 95: [root at ando ~]# ls /usr/share/X11/xkb/symbols | wc -l 95 Likely many more, as most of the files contain more than one layout; e.g. the ru file contains 5, the fr file contains 7. On Mac and Windows, locally-bought systems will come pre-configured for the local national language. You can even buy keycaps for some pretty niche use-cases: http://www.maxkeyboard.com/r4-1x1-cherry-mx-chinese-astrology-animal-sign-keycap-set.html although I expect that's more for novelty reasons than anything else. Most languages work quite well with the standard keyboard layout of four rows of keys, plus modifiers and special keys. Japanese and Chinese are probably the two hardest cases (apart from languages that don't even have a writing system!), and even they have solutions to the problem of computer input. (In Japan, many people don't even use Unicode, at least not yet, so your hypothetical solution wouldn't help them one bit.) Virtually all keyboards today have standardized on a similar layout, one with at least three modifier keys (and more commonly four). People with specialized needs can configure their keyboard the way it suits them. There's no need for some dictator or committee to declare that everyone will use this system or that. Historians who need to enter Phoenician characters can do so, the rest of us don't need to worry about them. Relevant: https://en.wikipedia.org/wiki/Space-cadet_keyboard > Dvorak had the right idea; but it didn't > stick (although I have a Dvorak key mapping I use (with emacs) just for > fun). Dvorak is an American English system. There are modified versions to suit other languages with additional characters, but it is essentially *identical* to Qwerty except for the order that the keys appear. Shuffling the order that Latin letters ABC...Z appear on the keyboard is not in any way "the right idea" for entering non-Latin languages, nor does a Dvorak language help enter arbitrary Unicode characters. -- Steven D'Aprano http://import-that.dreamwidth.org/ From harrismh777 at gmail.com Sat Mar 29 00:07:43 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 23:07:43 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 10:51 PM, Steven D'Aprano wrote: >> Why must >> everyone in the world be stuck with a U.S. Royal typewriter keyboard for >> two or three hundred years? > > You are being patronising to the 94% of the world that is not from the > USA. Do you honestly think that people all over the world have been using > computers for 30 or 40 years without any way to enter their native > language? You think ~sooo three dimensionally. Picture this ~a unicode keyboard with morphing keytops (digital ink, light emitting); a standard layout of keys that are touch sensitive, are meta operative, and are able to input *every* language on earth (as well any symbol). The keyboard may emit light, but not necessarily. The keys may be raised, but not necessarily; they have a glassy feel, soft, sensual, and completely programmable. Code point pages (key top mappings literally) are selectable on|off screen. The keyboard is obviously wireless, and the entire keytopsection is mouse-able; the whole keyboard is a pinting device, with diff sections for scrolling &c. This keyboard will be standard in about 25 years... none exist today. One of the things I do is biblical and classical language support and translation (Latin, Hebrew, and Greek). I do translation work as well as papers, research, &c; I need four full keyboards. I'm getting by fairly well with the macs key mappings, but what I'm really after is the 21st century keyboard I'm dreaming about above. Think, virtual keyboard, on a keytoplayout... but separate from any touchable screen. And, think mac keytops (or flatter) not the plastic IBM typewriter like keyboards of today. Think beyond. marcus From ben+python at benfinney.id.au Sat Mar 29 00:18:30 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 29 Mar 2014 15:18:30 +1100 Subject: Keyboard standards (was: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85txahocx5.fsf_-_@benfinney.id.au> Mark H Harris writes: > > On Sat, Mar 29, 2014 at 8:18 AM, Mark H Harris wrote: > >> We need a standard input system not controlled by Microsoft... > > [?] Does your keyboard have the "Windows" emblem|logo on the meta > key(s) on lower right, lower left? No, mine has a Tux logo, because it was shipped that way from Think Penguin and the key you're referring to operates as the ?Super? key in GNU+Linux. Quite useful. My desktop keyboard is constructed from the Model M buckling-spring design . That means, among other advantages, that the key caps are designed to be easily replaceable with parts from different manufacturers. Model M keyboards are now manufactured in Lexington, USA by Unicomp . They ship internationally, which is how I got mine. Unicomp will happily sell you one in various layouts without the Windows logo. They can even do a key set with the Ctrl and Caps Lock keys swapped to where they should be, and the Super key printed with a ?Tux? logo . On the inexpensive end, Think Penguin will also happily ship Tux logo stickers to go on top of the Super key . (I have no affiliation with Think Penguin nor Unicomp, except as a happy repeat customer.) > No, I want a standard unicode keyboard (a standard specification > for a unicode keyboard) that facilitates unicode typing with minimal > actual keys and standard key maps for alternate sets that may be > easily selected without a mouse and without moving the hands from the > home row. I can't help you with that, exactly. However, I type unicode characters with an Input Method engine called IBus , which is now in Gnome as a standard part of the interface. I can select various IBus input methods depending on the purpose or language for which I'm writing, and they make it predictable and memorable to get the right characters. -- \ ?I have yet to see any problem, however complicated, which, | `\ when you looked at it in the right way, did not become still | _o__) more complicated.? ?Paul Anderson | Ben Finney From harrismh777 at gmail.com Sat Mar 29 00:16:00 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 23:16:00 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 11:07 PM, Mark H Harris wrote: > Think, virtual keyboard, on a keytoplayout... but separate from any > touchable screen. And, think mac keytops (or flatter) not the plastic > IBM typewriter like keyboards of today. Think beyond. What if~ when I select my UK standard keytop mappings (from my US custom keytop mappings) what if the actual keytops on the keyboard "morphed" into UK tops? Better yes, what if the whole keytopsection could morph into Greek tops? I am able to type in Greek, well I've been doing it for about 12 years, but it would be soooo much better if the keytopsection actually morphed. marcus From harrismh777 at gmail.com Sat Mar 29 00:21:42 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 23:21:42 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 11:16 PM, Mark H Harris wrote: > I am able to type in Greek, well I've been doing it for about 12 years, > but it would be soooo much better if the keytopsection actually morphed. What if, when you opened your new computer in Botswana, and you selected your language in gnu/linux lang setup, and your standard unicode keyboard morphed into your favorite Tswana or Setswana { whatever } and only ONE keyboard needed to be manufactured ? re THINK From harrismh777 at gmail.com Sat Mar 29 00:26:25 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 23:26:25 -0500 Subject: Keyboard standards References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 11:18 PM, Ben Finney wrote: > On the inexpensive end, Think Penguin will also happily ship Tux logo > stickers to go on top of the Super key > . That's ~cool. I can now remove that nasty M$ meta key. Actually, I got so sick of looking at that goofy little warped window that I grabbed myself a magic marker and blacked it out. :) marcus PS Thunderbird puts *both* the list and the news group addys in the to: header field on reply-to-list. ~nice, huh. From harrismh777 at gmail.com Sat Mar 29 00:40:01 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Fri, 28 Mar 2014 23:40:01 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/14 10:51 PM, Steven D'Aprano wrote: > You are being patronising to the 94% of the world that is not from the > USA. Do you honestly think that people all over the world have been using > computers for 30 or 40 years without any way to enter their native > language? uh, pretty much. That's why they called it ASCII American Standard Code for Information Interchange... yup, pretty much. Worked pretty well too, for many many years, because so many languages derive from Latin, and most non third world countries use Latin derived character sets; yes, although missing dieresis and grave and acute accents, &c. Specialized keytops are made now, but what if... Dream From rosuav at gmail.com Sat Mar 29 00:48:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 15:48:42 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 29, 2014 at 3:07 PM, Mark H Harris wrote: > You think ~sooo three dimensionally. Yeah Doc, I have a real problem with that. -- Marty McFly > Picture this ~a unicode keyboard with morphing keytops (digital ink, light > emitting); a standard layout of keys that are touch sensitive, are meta > operative, and are able to input *every* language on earth (as well any > symbol). The keyboard may emit light, but not necessarily. The keys may be > raised, but not necessarily; they have a glassy feel, soft, sensual, and > completely programmable. Code point pages (key top mappings literally) are > selectable on|off screen. The keyboard is obviously wireless, and the entire > keytopsection is mouse-able; the whole keyboard is a pinting device, with > diff sections for scrolling &c. > > This keyboard will be standard in about 25 years... none exist today. Wrong. You just have to be willing to pay for it. http://www.thinkgeek.com/product/181d/?srp=14 Or you could just get a blank keytops keyboard and reprogram it how you like. But hey, have you noticed something? NOT ONE of these ideas actually makes it easy to write Python code with occasional non-ASCII characters in it. Switching keyboard mode for a single character is horribly inefficient, especially if you have to remember a whole lot of different modes for different characters ("lambda is meta-butterfly-greek L meta-ctrl-space, and equality is meta-mathematics 5 meta-ctrl-space"). Putting everything onto a single keyboard is unworkable. Requiring you to press long key sequences to generate single characters is useless. (You may as well just press L-A-M-B-D-A and have it come out as "lambda".) Even with an ideal keyboard, the creature of your fancies, you won't get past that, for the same reason that we have keyboards that type letters rather than English words. ChrisA From rustompmody at gmail.com Sat Mar 29 01:00:49 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 28 Mar 2014 22:00:49 -0700 (PDT) Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> Message-ID: On Saturday, March 29, 2014 12:25:45 AM UTC+5:30, rand... at fastmail.us wrote: > On Thu, Mar 27, 2014, at 11:10, Rustom Mody wrote: > > Just out of curiosity how do/did you type that? > > When I see an exotic denizen from the unicode-universe I paste it into > > emacs and ask "Who are you?" > > But with your 'def' my emacs is going a bit crazy! > Your emacs probably is using UCS-2 or UTF-16. The former can't handle > characters above 65535 at all, the latter stores them as if they were > two characters [so code that's not expecting them will handle them > incorrectly] My current diagnosis (with the help of more knowledgeable folks than myself) is that its a font problem. There simply doesn't exist a font (or more likely I dont know of) that - is readable - is scaleable - spans the whole 17*65536 unicode space At least out here: - gnu-unifont does not cover things outside BMP - dejavu seems to have some bugs From rosuav at gmail.com Sat Mar 29 01:08:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 16:08:47 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 29, 2014 at 3:40 PM, Mark H Harris wrote: > On 3/28/14 10:51 PM, Steven D'Aprano wrote: >> >> You are being patronising to the 94% of the world that is not from the >> USA. Do you honestly think that people all over the world have been using >> computers for 30 or 40 years without any way to enter their native >> language? > > > uh, pretty much. That's why they called it ASCII American Standard Code > for Information Interchange... yup, pretty much. Worked pretty well too, > for many many years, because so many languages derive from Latin, and most > non third world countries use Latin derived character sets; yes, although > missing dieresis and grave and acute accents, &c. ... wow. Okay. History lesson time. http://nedbatchelder.com/text/unipain.html http://en.wikipedia.org/wiki/Code_page Back before I was born, people were using computers to write messages that weren't in English. And they managed it, somehow. Can't imagine how, if all computers work exclusively with seven-bit Latin-derived character sets. "Most non-third-world countries use Latin-derived character sets". Hmm. Let's see. Greece, Russia, China, Japan, Israel, and Egypt are either third-world or just so insignificant that you can ignore them and say "most". Yeah, okay, we'll take that as read. Names are notoriously inaccurate when it comes to internationality. Ever heard of a place called IHOP? I hadn't, until I started talking to Americans. What's the difference between "global" and "universal"? We're clearly taking no notice of Martian languages here, much less anything outside our solar system. (If humans had non-FTL space travel five thousand years ago, there could now be colonies all over the universe, and we wouldn't necessarily even know about them. Those people would speak languages that can't possibly be Latin-derived; most likely they'd be derived from Hebrew or Arabic. In the event that they make contact, we're going to have to allocate some Unicode planes to them.) "Extended ASCII" is as international as Unicode, just less standardized. ChrisA From rosuav at gmail.com Sat Mar 29 01:12:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 16:12:28 +1100 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> Message-ID: On Sat, Mar 29, 2014 at 4:00 PM, Rustom Mody wrote: > My current diagnosis (with the help of more knowledgeable folks than myself) > is that its a font problem. > > There simply doesn't exist a font (or more likely I dont know of) that > - is readable > - is scaleable > - spans the whole 17*65536 unicode space For my MUDding, I use a font imaginatively named "Monospace", which does most of what I want. There are a handful of characters that come out as the "square with digits inside", but not huge blocks (certainly not "everything non-BMP" or anything like that). It's fairly readable, although I don't know about scaling - I run it at 14pt and nowhere else. Comes with Debian. ChrisA From rosuav at gmail.com Sat Mar 29 01:13:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 16:13:42 +1100 Subject: Keyboard standards In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 29, 2014 at 3:26 PM, Mark H Harris wrote: > On 3/28/14 11:18 PM, Ben Finney wrote: > >> On the inexpensive end, Think Penguin will also happily ship Tux logo >> stickers to go on top of the Super key >> >> . > > > That's ~cool. I can now remove that nasty M$ meta key. Actually, I got so > sick of looking at that goofy little warped window that I grabbed myself a > magic marker and blacked it out. :) If Sharpie can oust Microsoft's dominance over your keyboard, it can't have been very strong dominance to start with... When I first met Windows keys, I just popped 'em off and left a gap. Worked fine. ChrisA From rustompmody at gmail.com Sat Mar 29 01:21:50 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 28 Mar 2014 22:21:50 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <706187e9-0df4-45fa-9f06-c3a1ddd1ae76@googlegroups.com> On Saturday, March 29, 2014 10:38:47 AM UTC+5:30, Chris Angelico wrote: > On Sat, Mar 29, 2014 at 3:40 PM, Mark H Harris wrote: > > On 3/28/14 10:51 PM, Steven D'Aprano wrote: > >> You are being patronising to the 94% of the world that is not from the > >> USA. Do you honestly think that people all over the world have been using > >> computers for 30 or 40 years without any way to enter their native > >> language? > > uh, pretty much. That's why they called it ASCII American Standard Code > > for Information Interchange... yup, pretty much. Worked pretty well too, > > for many many years, because so many languages derive from Latin, and most > > non third world countries use Latin derived character sets; yes, although > > missing dieresis and grave and acute accents, &c. > ... wow. > Okay. History lesson time. > http://nedbatchelder.com/text/unipain.html > http://en.wikipedia.org/wiki/Code_page > Back before I was born, people were using computers to write messages > that weren't in English. And they managed it, somehow. Can't imagine > how, if all computers work exclusively with seven-bit Latin-derived > character sets. > "Most non-third-world countries use Latin-derived character sets". > Hmm. Let's see. Greece, Russia, China, Japan, Israel, and Egypt are > either third-world or just so insignificant that you can ignore them > and say "most". Yeah, okay, we'll take that as read. > Names are notoriously inaccurate when it comes to internationality. > Ever heard of a place called IHOP? I hadn't, until I started talking > to Americans. What's the difference between "global" and "universal"? > We're clearly taking no notice of Martian languages here, much less > anything outside our solar system. (If humans had non-FTL space travel > five thousand years ago, there could now be colonies all over the > universe, and we wouldn't necessarily even know about them. Those > people would speak languages that can't possibly be Latin-derived; > most likely they'd be derived from Hebrew or Arabic. In the event that > they make contact, we're going to have to allocate some Unicode planes > to them.) "Extended ASCII" is as international as Unicode, just less > standardized. > ChrisA For Indian languages there is usually a specific fully localized layout and a latin-derived one. In particular for devanagari, which is directly used (Hindi, Marathi) or close relative used (Gujarati, Bengali) there is inscript and itrans https://fedoraproject.org/wiki/I18N/Indic/HindiKeyboardLayouts itrans is the latin-derived layout, inscript is the fully-localized, no-relation-to-US-104 one. I would not be able to use the inscript if I tried and this is true for most of the people I know even though in some theoretically ergonomic sense its more efficient. So in the sphere I am familiar with Mark seems to be right that ASCII == US-104 rules the planet. To go from this small-sample data to vast generalizations... I'll leave to others From ben+python at benfinney.id.au Sat Mar 29 01:32:07 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 29 Mar 2014 16:32:07 +1100 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> Message-ID: <85ppl5o9ig.fsf@benfinney.id.au> Rustom Mody writes: > At least out here: > - gnu-unifont does not cover things outside BMP That implies the GNU Unifont contains no characters from outside the BMP, which is untrue. Rather, the GNU Unifont's claim to fame is that it covers all characters in the BMP. But it does contain many characters outside the BMP. So, I'd re-phrase the above caution more accurately as: The GNU Unifont has complete coverage of the BMP, and incomplete coverage outside the BMP. -- \ ?People always ask me, ?Where were you when Kennedy was shot?? | `\ Well, I don't have an alibi.? ?Emo Philips | _o__) | Ben Finney From harrismh777 at gmail.com Sat Mar 29 01:40:43 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 29 Mar 2014 00:40:43 -0500 Subject: Keyboard standards References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/29/14 12:13 AM, Chris Angelico wrote: > > When I first met Windows keys, I just popped 'em off and left a gap. > Worked fine. ha! see.. it popped you off too! :-)) I found it arrogant to the max to place their stupid logo on (my) keyboard. What if every company out there wanted "their" own keytop too? geeze :) From harrismh777 at gmail.com Sat Mar 29 01:51:17 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 29 Mar 2014 00:51:17 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53365F55.2040302@gmail.com> On 3/29/14 12:08 AM, Chris Angelico wrote: > > Okay. History lesson time. > Tell me what is the lingua franka today? Is it, E n g l i s h ? For many many many years people all over the earth were using English and ASCII to communicate with early computers... they still are. Almost every post on every site is English, and nearly every post on every site is a Latin character derivative. Kanji and Cyrillic , and Arabic are obvious exceptions to that today, mostly because of unicode; NOT extend ASCII. > Back before I was born, people were using computers to write messages > that weren't in English. No, they weren't... not most... some. > And they managed it, somehow. Can't imagine > how, if all computers work exclusively with seven-bit Latin-derived > character sets. Unicode. Shoot, most of the world didn't even have computers until just a few years ago; none of the third world did, back in the day, and the ones who did communicated in ASCII and English (or some broken variant of it). > "Most non-third-world countries use Latin-derived character sets". See this quote from the consortium FAQ: > So, for example, there is only one set of Latin characters > defined, despite the fact that the Latin script > is used for the alphabets of thousands of different languages. http://www.unicode.org/faq/basic_q.html#3 marcus From harrismh777 at gmail.com Sat Mar 29 01:51:17 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 29 Mar 2014 00:51:17 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53365F55.2040302@gmail.com> On 3/29/14 12:08 AM, Chris Angelico wrote: > > Okay. History lesson time. > Tell me what is the lingua franka today? Is it, E n g l i s h ? For many many many years people all over the earth were using English and ASCII to communicate with early computers... they still are. Almost every post on every site is English, and nearly every post on every site is a Latin character derivative. Kanji and Cyrillic , and Arabic are obvious exceptions to that today, mostly because of unicode; NOT extend ASCII. > Back before I was born, people were using computers to write messages > that weren't in English. No, they weren't... not most... some. > And they managed it, somehow. Can't imagine > how, if all computers work exclusively with seven-bit Latin-derived > character sets. Unicode. Shoot, most of the world didn't even have computers until just a few years ago; none of the third world did, back in the day, and the ones who did communicated in ASCII and English (or some broken variant of it). > "Most non-third-world countries use Latin-derived character sets". See this quote from the consortium FAQ: > So, for example, there is only one set of Latin characters > defined, despite the fact that the Latin script > is used for the alphabets of thousands of different languages. http://www.unicode.org/faq/basic_q.html#3 marcus From rosuav at gmail.com Sat Mar 29 02:03:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Mar 2014 17:03:38 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <53365F55.2040302@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: On Sat, Mar 29, 2014 at 4:51 PM, Mark H Harris wrote: > On 3/29/14 12:08 AM, Chris Angelico wrote: > >> >> Okay. History lesson time. >> > > Tell me what is the lingua franka today? > > Is it, E n g l i s h ? > > For many many many years people all over the earth were using English and > ASCII to communicate with early computers... they still are. Almost every > post on every site is English, and nearly every post on every site is a > Latin character derivative. http://forum.ecomstation.ru/ Prominent discussion forum, although that strives to be at least partially bilingual in deference to those of us who are so backward as to speak only English. > Kanji and Cyrillic , and Arabic are obvious exceptions to that today, > mostly because of unicode; NOT extend ASCII. > >> Back before I was born, people were using computers to write messages >> that weren't in English. > > > No, they weren't... not most... some. So, pre-Unicode, people didn't use any of those languages or writing systems with computers, is that what you're saying? That code pages 86x are a total myth? >> And they managed it, somehow. Can't imagine >> how, if all computers work exclusively with seven-bit Latin-derived >> character sets. > > > Unicode. Shoot, most of the world didn't even have computers until just a > few years ago; none of the third world did, back in the day, and the ones > who did communicated in ASCII and English (or some broken variant of it). Unicode didn't even begin to exist until 1987, and the first version of the standard wasn't published until 1991. You're seriously saying that until 1991 (plus however long it took to get implementations into people's hands) everyone spoke English with computers?!? >> "Most non-third-world countries use Latin-derived character sets". > > > See this quote from the consortium FAQ: > > > So, for example, there is only one set of Latin characters > > defined, despite the fact that the Latin script > > is used for the alphabets of thousands of different languages. > > http://www.unicode.org/faq/basic_q.html#3 Huh? I'm not sure whether you're trolling or genuinely ignorant of all history and other languages. Please clarify. If you really are just trolling, say so, and I'll start ignoring all your posts. You'll make yourself look less of a fool that way. ChrisA From rustompmody at gmail.com Sat Mar 29 02:10:07 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 28 Mar 2014 23:10:07 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <53365F55.2040302@gmail.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: On Saturday, March 29, 2014 11:21:17 AM UTC+5:30, Mark H. Harris wrote: > On 3/29/14 12:08 AM, Chris Angelico wrote: > > Okay. History lesson time. > Tell me what is the lingua franka today? > Is it, E n g l i s h ? I wonder Mark, if because you are communicating with your mailing software in ??????? and its expecting unicode (or Kanji)... you are posting once and we are seeing it twice, thrice... From metaliobovinus at gmail.com Sat Mar 29 03:26:12 2014 From: metaliobovinus at gmail.com (Metallicow) Date: Sat, 29 Mar 2014 00:26:12 -0700 (PDT) Subject: Embroidermodder2 Kickstarter for Python also! Message-ID: Dear Pythoneers, Just letting you know we got a Kickstarter going on for Embroidermodder2 finally. We are going to need all the support we can get. https://www.kickstarter.com/projects/redteam316/embroidermodder-2-for-windows-mac-linux-pi-and-ard What is the program for you may ask...? It is for making designs and stuff that can be embroidered on just about any fabric. It is the first real decent open-source embroidery software that handles many formats that would meet standard business/artists needs. https://en.wikipedia.org/wiki/Comparison_of_embroidery_software As an unofficial developer at this point my involvement hinders in the pure python side of things, but only upon project success. So what that means for everyone is that if the project IS successful, then I will be doing a pure python port of the application also(In PySide/PyQt first, then possibly a wxPy port) working closely with the two lead developers whom of which I know both well and respect and can attest to the level of devotion to quality being put into it. I already have the majority of the GUI code ported at alpha stage ATM so am off to a good start, but what is needed is at least initial funding before more work on the python side can continue, because we can't sustain self-funding this forever. Python bindings is a stretch goal also that was initially set. I don't recall exactly who it was here that joked about wanting the "Guido Van Rossum World Tour" Shirt, but it can be possible for anyone now with some basic skills and a machine(or you could take it to a local embroidery shop). The program aims to make the designer clothing side of the industry affordable and introducable for not only a small fry just starting a business, it also applies to shops that already exist as it provides open tools easily customizable to meet the jobs special purpose needs. So what we need is for the project to succeed by being funded and custom clothing design will then be finally open to the masses and so everyone can profit from it. There are many other rewards to consider also for your pledge. The campaign is going on until April 20th(Easter), so I encourage everyone interested in cheaper quality tools and clothes/etc to pledge what you can. Lets help these guys out. Thanks. Pic to python port WIPz http://i861.photobucket.com/albums/ab180/metallicow/Python/PySide-PyQt_Port.png From harrismh777 at gmail.com Sat Mar 29 04:21:29 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sat, 29 Mar 2014 03:21:29 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: On 3/29/14 1:03 AM, Chris Angelico wrote: > > http://forum.ecomstation.ru/ > > Prominent discussion forum, although that strives to be at least > partially bilingual in deference to those of us who are so backward as > to speak only English. Yes. Well, as the joke goes, if you're trilingual you speak three languages, if you're bilingual you speak two languages, if you're monolingual you're an American (well, that might go for Australia too, maybe). When whole continents speak the same language that tends to happen. > > So, pre-Unicode, people didn't use any of those languages or writing > systems with computers, is that what you're saying? That code pages > 86x are a total myth? No, no, no... don't over-read my post please. Think in orders of magnitudes. In computer history very little is even mentioned outside the U.S. This is, of course, not fair. The folks in the U.K. played a huge role (the Alan Turing story, The Baby, Blakeley &c). The entire world used ASCII, like, forever. Heck, its still being used! Code pages are not a myth, but they were not prominent, either. And of course prejudice is relatively spoken; I don't want to define it. What I can tell you in my own experience, as an amateur radio operator (W0MHH, general class) who has communicated all over the earth (even to Soviet Russia), all my computer|radio comm was in English using Morse code sets, Latin characters, and ASCII. No one ever asked me to comm in Russian, or French, nor Italian, nor Tswana... > Unicode didn't even begin to exist until 1987, and the first version > of the standard wasn't published until 1991. You're seriously saying > that until 1991 (plus however long it took to get implementations into > people's hands) everyone spoke English with computers?!? No. see above. I'm saying that (for the most part) international communication has been Latin code pages and ASCII all over the earth, until very recently (as you point out).. By the way, in my view, 1991 is very recently; from a computer historical standpoint too. I mean, think about it, computers have only existed since late 1940s and only in their modern context since about 1989. I didn't really start using unicode until about 5 years ago; python has only really used it since python3. right? >> See this quote from the consortium FAQ: >> >> > So, for example, there is only one set of Latin characters >> > defined, despite the fact that the Latin script >> > is used for the alphabets of thousands of different languages. >> >> http://www.unicode.org/faq/basic_q.html#3 > > Huh? The consortium designates scripts vs. languages. When folks ask them about how many languages they support its a difficult answer. Do you mean scripts ( of which there is only one Latin script ) or are you referring to the *thousands* of different languages that are scripted in Latin characters? Latin script is used in thousands of languages world-wide; true story. (that's what the quote is above) > I'm not sure whether you're trolling or genuinely ignorant of all > history and other languages. Neither. I never troll, and I'm not ignorant. We are only getting cross-ways on this point more because of overlapping time frames I'm guessing, and numbers. I know that people groups and various languages were being used around the world in pockets for various purposes. I was part of the support group at IBM, for instance, that helped with the debugging process when we started supporting Kanji on the system36 system38. I know that kind of stuff was happening. But when it came to communicating world-wide for business (or in my case with radiography) it was always ASCII, Latin character sets, and in my case English Morse or international Morse code sets (derived from English). > Please clarify. If you really are just > trolling, say so, and I'll start ignoring all your posts. No, Chris. I never troll. (that would make my fingers itch) :) From ian.g.kelly at gmail.com Sat Mar 29 06:02:04 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 29 Mar 2014 04:02:04 -0600 Subject: Keyboard standards In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 28, 2014 at 11:40 PM, Mark H Harris wrote: > On 3/29/14 12:13 AM, Chris Angelico wrote: >> >> When I first met Windows keys, I just popped 'em off and left a gap. >> Worked fine. > > ha! see.. it popped you off too! :-)) I found it arrogant to the max to > place their stupid logo on (my) keyboard. What if every company out there > wanted "their" own keytop too? geeze It's interesting to note that the Command key on Apple keyboards was originally designed with the Apple logo, but Steve Jobs felt that the logo was overused by having it plastered all over menu shortcuts, so they replaced it prior to release with the cloverleaf symbol it now bears. From marko at pacujo.net Sat Mar 29 07:39:08 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 29 Mar 2014 13:39:08 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87txahi68z.fsf@elektro.pacujo.net> Steven D'Aprano : > Under what circumstances do you see yourself needing a keyboard capable > of typing Hindi? > > I don't wish to pay for a keyboard for entering Arabic Everybody should be able to have a keyboard for their needs. If I should need an APL keyboard, I would have it in a jiffy. At the moment, I have a keyboard that is optimized for Python, Finnish, English, Hebrew and Esperanto. I use it at home and at the office. The magic is called .Xmodmap. (But no, I wouldn't name my variables in Hebrew because the next maintainer might not have a keyboard like mine.) Marko From roy at panix.com Sat Mar 29 07:53:42 2014 From: roy at panix.com (Roy Smith) Date: Sat, 29 Mar 2014 07:53:42 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <87txahi68z.fsf@elektro.pacujo.net> Message-ID: In article <87txahi68z.fsf at elektro.pacujo.net>, Marko Rauhamaa wrote: > (But no, I wouldn't name my variables in Hebrew because the next > maintainer might not have a keyboard like mine.) Have you ever done any work in PHP? Many of the error messages are Hebrew, transliterated into English. I've gotten many a T_PAAMAYIM_NEKUDOTAYIM error. From marko at pacujo.net Sat Mar 29 07:59:39 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 29 Mar 2014 13:59:39 +0200 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <87txahi68z.fsf@elektro.pacujo.net> Message-ID: <87lhvti5as.fsf@elektro.pacujo.net> Roy Smith : > Have you ever done any work in PHP? Many of the error messages are > Hebrew, transliterated into English. I've gotten many a > T_PAAMAYIM_NEKUDOTAYIM error. I hate localization. You get a error message in Finnish from "make" or "grep" and then you try to google it. So mine is en_US, but I know people who do fi_FI. Marko From breamoreboy at yahoo.co.uk Sat Mar 29 11:45:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 29 Mar 2014 15:45:39 +0000 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: On 29/03/2014 08:21, Mark H Harris wrote: > > Yes. Well, as the joke goes, if you're trilingual you speak three > languages, if you're bilingual you speak two languages, if you're > monolingual you're an American (well, that might go for Australia too, > maybe). When whole continents speak the same language that tends to happen. You mean like the USA, where I saw an ad in a shop for a bilingual shop assistant? Or is Spanish so like US English it doesn't count as a separate language? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From breamoreboy at yahoo.co.uk Sat Mar 29 11:46:43 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 29 Mar 2014 15:46:43 +0000 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) In-Reply-To: <95aa5148-497a-49a1-9e78-2c019c36cf25@googlegroups.com> References: <5335F677.20605@gmail.com> <533630e2$0$29994$c3e8da3$5496439d@news.astraweb.com> <95aa5148-497a-49a1-9e78-2c019c36cf25@googlegroups.com> Message-ID: On 29/03/2014 03:21, Rustom Mody wrote: > On Saturday, March 29, 2014 8:34:19 AM UTC+5:30, Mark H. Harris wrote: >> On 3/28/14 9:33 PM, Steven D'Aprano wrote: >>> Mark, please stop posting to the newsgroup comp.lang.python AND the >>> mailing list (...). They mirror each other. Your posts >>> are not so important that we need to see everything twice. > >> Its not my fault, Steven. Something goofy is going on. My address says >> only comp.lang.python > >> I have no idea why some of these messages are being duplicated on the >> mailing list. I only post to the news group. > >> Anyways, sorry. I'll keep checking this. > >> regards, > > Just use the amazing, fool-safe, fail-proof google-groups. > And enjoy bliss. > > [Uh... And now I need to run... Out of sprinting practice...] > Blast, you beat me to it, and I never could sprint :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From none at mailinator.com Sat Mar 29 11:59:50 2014 From: none at mailinator.com (mm0fmf) Date: Sat, 29 Mar 2014 15:59:50 +0000 Subject: Howto flaten a list of lists was (Explanation of this Python language feature) In-Reply-To: References: Message-ID: <36CZu.66087$o%7.5864@fx29.am4> On 28/03/2014 22:12, Mark Lawrence wrote: > As for the stupid symbol that you're using, real programmers don't give > a damn about such things, they prefer writing plain, simple, boring code > that is easy to read What he said. From steve+comp.lang.python at pearwood.info Sat Mar 29 12:03:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2014 16:03:11 GMT Subject: Keyboard standards References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5336eebe$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Mar 2014 00:40:43 -0500, Mark H Harris wrote: > On 3/29/14 12:13 AM, Chris Angelico wrote: >> >> When I first met Windows keys, I just popped 'em off and left a gap. >> Worked fine. > > ha! see.. it popped you off too! :-)) I found it arrogant to the > max to place their stupid logo on (my) keyboard. My keyboard has IBM's logo on it. My keyboard at work has Dell's logo on it. In the cupboard, I have a Mac with Apple's logo on it. Do you have a problem with that? > What if every company > out there wanted "their" own keytop too? geeze They're welcome to try. Without support from the operating system, what good do you think it will do? Apple used to have an Apple key. Later they changed it to ? (Command), but everyone knows that ? is only available on Apple keyboards. -- Steven D'Aprano http://import-that.dreamwidth.org/ From gheskett at wdtv.com Sat Mar 29 13:48:34 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Sat, 29 Mar 2014 13:48:34 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <87lhvti5as.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87lhvti5as.fsf@elektro.pacujo.net> Message-ID: <201403291348.34617.gheskett@wdtv.com> On Saturday 29 March 2014 13:47:13 Marko Rauhamaa did opine: > Roy Smith : > > Have you ever done any work in PHP? Many of the error messages are > > Hebrew, transliterated into English. I've gotten many a > > T_PAAMAYIM_NEKUDOTAYIM error. > > I hate localization. You get a error message in Finnish from "make" or > "grep" and then you try to google it. > > So mine is en_US, but I know people who do fi_FI. > > > Marko I don't hate it at all. If, by reporting the error in the persons 1st language, he learns faster, that is a huge plus to me. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From gheskett at wdtv.com Sat Mar 29 13:46:12 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Sat, 29 Mar 2014 13:46:12 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87txahi68z.fsf@elektro.pacujo.net> Message-ID: <201403291346.12731.gheskett@wdtv.com> On Saturday 29 March 2014 13:12:06 Roy Smith did opine: > In article <87txahi68z.fsf at elektro.pacujo.net>, > > Marko Rauhamaa wrote: > > (But no, I wouldn't name my variables in Hebrew because the next > > maintainer might not have a keyboard like mine.) > > Have you ever done any work in PHP? Many of the error messages are > Hebrew, transliterated into English. I've gotten many a > T_PAAMAYIM_NEKUDOTAYIM error. Ok, I'll bite, does that have an American English translation? We did the majority of our web page at WDTV in the earlier years from a server we wrote in ARexx running PHP scripts on a souped up Amiga, (we farmed it out about the time we made the digital switch because Jim no longer had the time to do it full time, and of course the farmed out version sucks) but while that wasn't my forte, I don't recall Jim ever mentioning PHP error messages as being in Hebrew. I recall from a mailing list discussion about why English was the dominant language, probably a decade or more back up the log so it is not in my email corpus now, and a Turkish professor of one of the other latin languages nailed it at the time. In terms of the language moving to keep up with the state of the art, English moves, rapidly and smoothly and our dictionaries are updated to add the new words at many times the pace of the older languages. Some progress is being made of course, we now have what, 18 language linux can speak, I'd assume with a certain amount of kicking and screaming, but it seems to me that it is still pretty true. Engrish, as exported from Japan in their tech manuals doesn't count, we can usually figure out what the Sony engineers were trying to say. Not that it will be appreciated by those younger English speakers here, who, because their schools failed them, never got any phonetic tutoring. I did, and as I approach my 80th birthday, I truly feel like the last of a dying breed because they dropped that from the elementary school curriculum a year later. That loss, to the language as a whole, is very telling in what one hears being spoken on the streets of small town America today, much of which would have earned me an F back in the 1940's. Today, saying that the language has been butchered, gives the skilled butcher a bad reputation. But we muddle along, somehow managing to survive all those legal warnings on a bottle of aspirin. :) Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From steve+comp.lang.python at pearwood.info Sat Mar 29 13:53:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2014 17:53:28 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53370898$0$29994$c3e8da3$5496439d@news.astraweb.com> On Fri, 28 Mar 2014 23:40:01 -0500, Mark H Harris wrote: > On 3/28/14 10:51 PM, Steven D'Aprano wrote: >> You are being patronising to the 94% of the world that is not from the >> USA. Do you honestly think that people all over the world have been >> using computers for 30 or 40 years without any way to enter their >> native language? > > uh, pretty much. Then be educated. That is not the case. People have had localised code pages, and localised keyboards to enter characters in those code pages, for up to 30 years, if not longer. In some of those cases, the localisation was done by companies like IBM, Microsoft and Apple, realising that if they wanted to sell computers outside of the US, they needed to supply computers that were localised to their market. In other cases, it was the national governments of the nations which set up their own standards, then insisted that computer vendors supported them. This code page system actually worked pretty well, so long as you only exchange documents with people using the same code page. Until the Internet, that was mostly the case. > That's why they called it ASCII American Standard > Code for Information Interchange... Yes. So what? Just because ASCII exists doesn't mean everyone uses it *exclusively*. With the demise of EBCDIC as the standard character encoding (actually plural encodings, because EBCDIC has code pages too), ASCII has become the lowest common denominator for most (but not all) character sets. Pre- Unicode, most (but definitely not all!) code pages were based on ASCII, either with a few changes, or extending it to a full 8 bits. But that's the point: most people with access to computing in the first place, also had access to input methods and code pages for their native language. Your idea that they were forced to use ASCII exclusively, with no way of entering their own language, is simply wrong. -- Steven D'Aprano http://import-that.dreamwidth.org/ From contact.trigon at gmail.com Sat Mar 29 14:56:50 2014 From: contact.trigon at gmail.com (contact.trigon at gmail.com) Date: Sat, 29 Mar 2014 11:56:50 -0700 (PDT) Subject: checking if two things do not equal None Message-ID: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> if (a, b) != (None, None): or if a != None != b: Preference? Pros? Cons? Alternatives? :D From steve+comp.lang.python at pearwood.info Sat Mar 29 15:05:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2014 19:05:03 GMT Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> Message-ID: <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: > if (a, b) != (None, None): > or > if a != None != b: > > Preference? Pros? Cons? Alternatives? Do you actually want to check for arbitrary objects which may claim to equal None, or do you want to check for objects which are None? Nearly always when people test for == to None, they don't really mean it. They actually want to use an identity test. I'm going to assume the same holds here. if not (a is b is None): ... Or if you prefer: if a is not b is not None: ... -- Steven D'Aprano http://import-that.dreamwidth.org/ From lele at metapensiero.it Sat Mar 29 15:24:32 2014 From: lele at metapensiero.it (Lele Gaifax) Date: Sat, 29 Mar 2014 20:24:32 +0100 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mwg8yfin.fsf@nautilus.nautilus> Steven D'Aprano writes: > if not (a is b is None): ... > > Or if you prefer: > > if a is not b is not None: ... >>> 1 is not 1 is not None False So definitely the former! ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From contact.trigon at gmail.com Sat Mar 29 15:23:25 2014 From: contact.trigon at gmail.com (contact.trigon at gmail.com) Date: Sat, 29 Mar 2014 12:23:25 -0700 (PDT) Subject: checking if two things do not equal None In-Reply-To: <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <54f5af7c-a069-4452-b49d-881de94ec1cf@googlegroups.com> > Do you actually want to check for arbitrary objects which may claim to > equal None, or do you want to check for objects which are None? Arbitrary objects are not a concern. > if not (a is b is None): ... > > if a is not b is not None: ... Thanks for the examples. From orgnut at yahoo.com Sat Mar 29 15:27:12 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Sat, 29 Mar 2014 12:27:12 -0700 Subject: Keyboard standards In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/28/2014 09:26 PM, Mark H Harris wrote: > > PS Thunderbird puts *both* the list and the news group addys in the to: header field on > reply-to-list. ~nice, huh. Must be the way YOU set it up. MY Thunderbird (currently version 24.4.0 on Mint Linux 16) doesn't do any such thing. Besides, "Reply" sends private e-mail to the poster -- "Followup" sends to the newsgroup. -=- Larry -=- From torriem at gmail.com Sat Mar 29 15:41:30 2014 From: torriem at gmail.com (Michael Torrie) Date: Sat, 29 Mar 2014 13:41:30 -0600 Subject: Keyboard standards In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533721EA.4090903@gmail.com> On 03/29/2014 01:27 PM, Larry Hudson wrote: > On 03/28/2014 09:26 PM, Mark H Harris wrote: >> >> PS Thunderbird puts *both* the list and the news group addys in the to: header field on >> reply-to-list. ~nice, huh. > > Must be the way YOU set it up. MY Thunderbird (currently version 24.4.0 on Mint Linux 16) > doesn't do any such thing. Besides, "Reply" sends private e-mail to the poster -- "Followup" > sends to the newsgroup. No, Mark describes the standard way Thunderbird works. Reply-to-List does what he says it does. Not sure why your installation works differently. I guess maybe you are talking about something different. The mailing list vs the NNTP list. From dfnsonfsduifb at gmx.de Sat Mar 29 17:01:24 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 29 Mar 2014 22:01:24 +0100 Subject: checking if two things do not equal None In-Reply-To: <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29.03.2014 20:05, Steven D'Aprano wrote: > On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: > >> if (a, b) != (None, None): >> or >> if a != None != b: >> >> Preference? Pros? Cons? Alternatives? > > if not (a is b is None): ... > > Or if you prefer: > > if a is not b is not None: ... Is this an obfuscated coding contest? Why do you opt for a solution that one has to at least think 2 seconds about when the simplest solution: if (a is not None) or (b is not None): is immediately understandable by everyone? Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From roy at panix.com Sat Mar 29 17:07:20 2014 From: roy at panix.com (Roy Smith) Date: Sat, 29 Mar 2014 17:07:20 -0400 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Johannes Bauer wrote: > On 29.03.2014 20:05, Steven D'Aprano wrote: > > On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: > > > >> if (a, b) != (None, None): > >> or > >> if a != None != b: > >> > >> Preference? Pros? Cons? Alternatives? > > > > if not (a is b is None): ... > > > > Or if you prefer: > > > > if a is not b is not None: ... > > Is this an obfuscated coding contest? Why do you opt for a solution that > one has to at least think 2 seconds about when the simplest solution: > > if (a is not None) or (b is not None): > > is immediately understandable by everyone? I agree with that. But > if (a, b) != (None, None): seems pretty straight-forward to me too. In fact, if anything, it seems easier to understand than > if (a is not None) or (b is not None): I certainly agree that things like > if a is not b is not None: ... belong in an obfuscated coding contest. Code gets read a lot more often than it get written. Make it dead-ass simple to understand, and future generations of programmers who inherit your code will thank you for it. From davea at davea.name Sat Mar 29 17:26:57 2014 From: davea at davea.name (Dave Angel) Date: Sat, 29 Mar 2014 17:26:57 -0400 (EDT) Subject: Keyboard standards References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Larry Hudson Wrote in message: > On 03/28/2014 09:26 PM, Mark H Harris wrote: >> >> PS Thunderbird puts *both* the list and the news group addys in the to: header field on >> reply-to-list. ~nice, huh. > > Must be the way YOU set it up. MY Thunderbird (currently version 24.4.0 on Mint Linux 16) > doesn't do any such thing. Besides, "Reply" sends private e-mail to the poster -- "Followup" > sends to the newsgroup. > > -=- Larry -=- > > That depends on whether you're using Thunderbird as a newsreader, or Thunderbird with the mailing list. Mark Harris is apparently doing the latter. -- DaveA From davea at davea.name Sat Mar 29 18:01:03 2014 From: davea at davea.name (Dave Angel) Date: Sat, 29 Mar 2014 18:01:03 -0400 (EDT) Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Roy Smith Wrote in message: > In article , > Johannes Bauer wrote: > >> On 29.03.2014 20:05, Steven D'Aprano wrote: >> > On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: >> > >> >> if (a, b) != (None, None): >> >> or >> >> if a != None != b: >> >> >> >> Preference? Pros? Cons? Alternatives? >> > >> > if not (a is b is None): ... >> > >> > Or if you prefer: >> > >> > if a is not b is not None: ... >> >> Is this an obfuscated coding contest? Why do you opt for a solution that >> one has to at least think 2 seconds about when the simplest solution: >> >> if (a is not None) or (b is not None): >> >> is immediately understandable by everyone? > > I agree with that. But > >> if (a, b) != (None, None): > > seems pretty straight-forward to me too. In fact, if anything, it seems > easier to understand than > >> if (a is not None) or (b is not None): > > I certainly agree that things like > >> if a is not b is not None: ... > > belong in an obfuscated coding contest. Code gets read a lot more often > than it get written. Make it dead-ass simple to understand, and future > generations of programmers who inherit your code will thank you for it. > The other advantage to keeping it simple is it's more than likely to be right. If we take the original form as the spec, we'll find that two of the alternatives are not even equivalent. def trigon1(a, b): return (a,b) != (None, None) #master def trigon2(a, b): return a != None != b. # different def steven1(a, b): return not(a is b is None) def steven2(a, b): return a is not b is not None #different def johannes(a, b): return (a is not None) or (b is not None) table = [ trigon1, trigon2, steven1, steven2, johannes ] for func in table: print func.__name__ print func(None, None), func(None, 42), func(42, None), func(42, 42), func(42, "never") -- DaveA From dfnsonfsduifb at gmx.de Sat Mar 29 17:55:12 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 29 Mar 2014 22:55:12 +0100 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29.03.2014 22:07, Roy Smith wrote: > I agree with that. But > >> if (a, b) != (None, None): > > seems pretty straight-forward to me too. In fact, if anything, it seems > easier to understand than > >> if (a is not None) or (b is not None): Yes, probably. I liked the original, too. If I were writing the code, I'd probably try to aim to invert the condition though and simply do if (a is None) and (b is None) Which is pretty easy to understand for even a rookie programmer. > I certainly agree that things like > >> if a is not b is not None: ... > > belong in an obfuscated coding contest. Code gets read a lot more often > than it get written. Make it dead-ass simple to understand, and future > generations of programmers who inherit your code will thank you for it. Absolutely. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From rosuav at gmail.com Sat Mar 29 18:01:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Mar 2014 09:01:57 +1100 Subject: unicode as valid naming symbols In-Reply-To: <6d2ej9hve7v7m3jfbre1jn9v1loacfr8lo@4ax.com> References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> <6d2ej9hve7v7m3jfbre1jn9v1loacfr8lo@4ax.com> Message-ID: On Sun, Mar 30, 2014 at 5:11 AM, Dennis Lee Bieber wrote: > Considering that a 5x8 bitmap font (which is unlikely to even have > enough pixels to produce even 65536 unique glyphs) would take 5.6MB for > your (17*65536), I wouldn't want to see what an algorithmic description > would require. > > Looking at some of my collection of fonts, TTF and some PS, seem to be > running around 100kB per font, and those fonts likely have around 128-192 > glyphs. > > For 1114112 glyphs (17*65536) at, say 164 glyphs pre 100kB gives 680MB > per FONT. Assume the standards: normal, bold, italic, bold-italic -- one is > now up to 2.7GB per typeface. 5.4GB to support just one serif and one sans > serif typeface. Most fonts these days are vector, not bitmap, but a 5x8 bitmap has forty pixels, any of which can be either on or off - that gives roughly twice as much data space as the 21-bit Unicode spec. Plenty of room for 17*65536 unique glyphs. But you're right that it'd then take ~5-6MB to store that, minimum. ChrisA From dfnsonfsduifb at gmx.de Sat Mar 29 18:02:29 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sat, 29 Mar 2014 23:02:29 +0100 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29.03.2014 22:55, Johannes Bauer wrote: >>> if (a is not None) or (b is not None): > > Yes, probably. I liked the original, too. If I were writing the code, > I'd probably try to aim to invert the condition though and simply do > > if (a is None) and (b is None) > > Which is pretty easy to understand for even a rookie programmer. Let me expand on that thought one or two more sentences: Although it may seem really trivial, inversions ("not") in my opinion can really make code unreadable. One thing that I regularly see when peer-reviewing code is something like: if not feature_disabled: or one that I've seen in-field (modulo the programming language and the variable names): if (not no_delayed_commit) and (not data_unchanged): instead of: if immediate_commit and data_changed: Enough of my two cents for today :-) Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From python.list at tim.thechases.com Sat Mar 29 18:36:55 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 29 Mar 2014 17:36:55 -0500 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140329173655.4022d715@bigbox.christie.dr> On 2014-03-29 17:07, Roy Smith wrote: > > if (a is not None) or (b is not None): > > > > is immediately understandable by everyone? > > I agree with that. But > > > if (a, b) != (None, None): > > seems pretty straight-forward to me too. In fact, if anything, it > seems easier to understand than And for cases where you have more than one or two things to test for None-itude, you could use if all(x is None for x in [a, b, c, d]): do_something_if_theyre_all_None() or if all(x is not None for x in [a, b, c, d]): do_something_if_no_Nones() or if not any(x is None for x in [a, b, c, d]): do_something_if_no_Nones() which I find *much* more readable from a maintenance point of view. -tkc From roy at panix.com Sat Mar 29 18:41:03 2014 From: roy at panix.com (Roy Smith) Date: Sat, 29 Mar 2014 18:41:03 -0400 Subject: checking if two things do not equal None In-Reply-To: <20140329173655.4022d715@bigbox.christie.dr> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <20140329173655.4022d715@bigbox.christie.dr> Message-ID: On Mar 29, 2014, at 6:36 PM, Tim Chase wrote: > And for cases where you have more than one or two things to test for > None-itude, you could use > > if all(x is None for x in [a, b, c, d]): > do_something_if_theyre_all_None() I might have written that as: if set([a, b, c, d]) == set(None) That's even clearer if you happen to already have the items in an iterable: if set(conditions) == set(None) -- Roy Smith roy at panix.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at thechases.com Sat Mar 29 18:46:53 2014 From: tim at thechases.com (Tim Chase) Date: Sat, 29 Mar 2014 17:46:53 -0500 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <20140329173655.4022d715@bigbox.christie.dr> Message-ID: <20140329174653.4969807f@bigbox.christie.dr> On 2014-03-29 18:41, Roy Smith wrote: > On Mar 29, 2014, at 6:36 PM, Tim Chase wrote: > > > And for cases where you have more than one or two things to test > > for None-itude, you could use > > > > if all(x is None for x in [a, b, c, d]): > > do_something_if_theyre_all_None() > > I might have written that as: > > if set([a, b, c, d]) == set(None) > > That's even clearer if you happen to already have the items in an > iterable: > > if set(conditions) == set(None) Though am I correct that your iteration tests for equality, while mine tests for identity? Also, my version bails early in the event quitting early is possible. That's particularly useful in the case of doing something like if all(x() is None for x in [func1, func2, func3, costly_func]): do_something() -tkc From roy at panix.com Sat Mar 29 18:51:43 2014 From: roy at panix.com (Roy Smith) Date: Sat, 29 Mar 2014 18:51:43 -0400 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <20140329173655.4022d715@bigbox.christie.dr> Message-ID: In article , Tim Chase wrote: > On 2014-03-29 18:41, Roy Smith wrote: > > On Mar 29, 2014, at 6:36 PM, Tim Chase wrote: > > > > > And for cases where you have more than one or two things to test > > > for None-itude, you could use > > > > > > if all(x is None for x in [a, b, c, d]): > > > do_something_if_theyre_all_None() > > > > I might have written that as: > > > > if set([a, b, c, d]) == set(None) > > > > That's even clearer if you happen to already have the items in an > > iterable: > > > > if set(conditions) == set(None) > > Though am I correct that your iteration tests for equality, while > mine tests for identity? Hmmm, you're almost certainly correct on that, but you would have to have a perversely designed class for that to make a difference. I'll take the increased readability. > Also, my version bails early in the event > quitting early is possible. That's particularly useful in the case > of doing something like > > if all(x() is None for x in [func1, func2, func3, costly_func]): > do_something() Again, you're correct. But, I'll take the increased readability over the premature optimization :-) From tjreedy at udel.edu Sat Mar 29 19:02:08 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 29 Mar 2014 19:02:08 -0400 Subject: checking if two things do not equal None In-Reply-To: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> Message-ID: On 3/29/2014 2:56 PM, contact.trigon at gmail.com wrote: > if (a, b) != (None, None): > or > if a != None != b: > > Preference? Pros? Cons? Alternatives? if a is not None is not b == if a is not None and None is not b == if a is not None and b is not None which is what I would write if not trying to be cute. a < x < b is more readable as a chained comparison than the double is not. -- Terry Jan Reedy From rosuav at gmail.com Sat Mar 29 19:17:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Mar 2014 10:17:49 +1100 Subject: checking if two things do not equal None In-Reply-To: <20140329174653.4969807f@bigbox.christie.dr> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <20140329173655.4022d715@bigbox.christie.dr> <20140329174653.4969807f@bigbox.christie.dr> Message-ID: On Sun, Mar 30, 2014 at 9:46 AM, Tim Chase wrote: > Though am I correct that your iteration tests for equality, while > mine tests for identity? Also, my version bails early in the event > quitting early is possible. That's particularly useful in the case > of doing something like > > if all(x() is None for x in [func1, func2, func3, costly_func]): > do_something() Presumably you mean to actually call those functions, as checking the identity of a costly function is still cheap :) ChrisA From contact.trigon at gmail.com Sat Mar 29 19:20:09 2014 From: contact.trigon at gmail.com (contact.trigon at gmail.com) Date: Sat, 29 Mar 2014 16:20:09 -0700 (PDT) Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <41055822-39c5-4783-ae95-018032cac952@googlegroups.com> Thanks everyone; it has been very educational. > Dave Angel: > ...we'll find that two of the alternatives are not even equivalent. That helped me realize (a,b) != (None, None) is not correct for the function. It's a case where two parameters have None as the default argument. What I want is to make sure that both are not None. I am now considering: if None not in (a,b): or if (a is not None) and (b is not None): From ethan at stoneleaf.us Sat Mar 29 19:20:40 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 29 Mar 2014 16:20:40 -0700 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53375548.9040807@stoneleaf.us> On 03/29/2014 02:01 PM, Johannes Bauer wrote: > On 29.03.2014 20:05, Steven D'Aprano wrote: >> On Sat, 29 Mar 2014 11:56:50 -0700, contact.trigon wrote: >> >>> if (a, b) != (None, None): >>> or >>> if a != None != b: >>> >>> Preference? Pros? Cons? Alternatives? >> >> if not (a is b is None): ... >> >> Or if you prefer: >> >> if a is not b is not None: ... > > Is this an obfuscated coding contest? Why do you opt for a solution that > one has to at least think 2 seconds about when the simplest solution: > > if (a is not None) or (b is not None): > > is immediately understandable by everyone? +1 -- ~Ethan~ From python.list at tim.thechases.com Sat Mar 29 21:19:06 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 29 Mar 2014 20:19:06 -0500 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <20140329173655.4022d715@bigbox.christie.dr> <20140329174653.4969807f@bigbox.christie.dr> Message-ID: <20140329201906.4beab393@bigbox.christie.dr> On 2014-03-30 10:17, Chris Angelico wrote: > On Sun, Mar 30, 2014 at 9:46 AM, Tim Chase > wrote: >> Though am I correct that your iteration tests for equality, while >> mine tests for identity? Also, my version bails early in the >> event quitting early is possible. That's particularly useful in >> the case of doing something like >> >> if all(x() is None for x in [func1, func2, func3, costly_func]): ^^^ >> do_something() > > Presumably you mean to actually call those functions, as checking > the identity of a costly function is still cheap :) Which is what I do...calling only those necessary until the all/any condition has been met. :-) If you create the list of things to iterate over by calling them as you create the list, then you don't save much of anything. If you only call until one of them breaks the any/all construct, you save all the subsequent function calls. -tkc From rosuav at gmail.com Sat Mar 29 21:37:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Mar 2014 12:37:28 +1100 Subject: checking if two things do not equal None In-Reply-To: <20140329201906.4beab393@bigbox.christie.dr> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <20140329173655.4022d715@bigbox.christie.dr> <20140329174653.4969807f@bigbox.christie.dr> <20140329201906.4beab393@bigbox.christie.dr> Message-ID: On Sun, Mar 30, 2014 at 12:19 PM, Tim Chase wrote: > On 2014-03-30 10:17, Chris Angelico wrote: >> On Sun, Mar 30, 2014 at 9:46 AM, Tim Chase >> wrote: >>> Though am I correct that your iteration tests for equality, while >>> mine tests for identity? Also, my version bails early in the >>> event quitting early is possible. That's particularly useful in >>> the case of doing something like >>> >>> if all(x() is None for x in [func1, func2, func3, costly_func]): > ^^^ >>> do_something() >> >> Presumably you mean to actually call those functions, as checking >> the identity of a costly function is still cheap :) > > Which is what I do...calling only those necessary until the all/any > condition has been met. :-) > > If you create the list of things to iterate over by calling them as > you create the list, then you don't save much of anything. If you > only call until one of them breaks the any/all construct, you save > all the subsequent function calls. *facepalm* Yep, you do indeed. My bad! Take no notice of the man behind the curtain... ChrisA From steve+comp.lang.python at pearwood.info Sat Mar 29 22:04:14 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 02:04:14 GMT Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Mar 2014 17:07:20 -0400, Roy Smith wrote: > I certainly agree that things like > >> if a is not b is not None: ... > > belong in an obfuscated coding contest. Apart from the fact that I got it wrong (that's what happens when I post at 6am after being up all night, thanks for the correction Lele), if you consider chained comparisons to be "obfuscated", I think you're not really fluent at Python. The OP even suggested `a != None != b` so I think that (s)he at least understands chained comparisons. However, I agree with Johannes that inverted conditions (using "not") are sometimes harder to reason about than "regular" conditions. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sat Mar 29 22:15:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Mar 2014 13:15:18 +1100 Subject: checking if two things do not equal None In-Reply-To: <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 30, 2014 at 1:04 PM, Steven D'Aprano wrote: > On Sat, 29 Mar 2014 17:07:20 -0400, Roy Smith wrote: > >> I certainly agree that things like >> >>> if a is not b is not None: ... >> >> belong in an obfuscated coding contest. > > Apart from the fact that I got it wrong (that's what happens when I post > at 6am after being up all night, thanks for the correction Lele), if you > consider chained comparisons to be "obfuscated", I think you're not > really fluent at Python. The OP even suggested `a != None != b` so I > think that (s)he at least understands chained comparisons. > > However, I agree with Johannes that inverted conditions (using "not") are > sometimes harder to reason about than "regular" conditions. Chained comparisons where you're checking a single variable against two constants make perfect sense: 2 < x < 5 Chained comparisons where you check a single constant against two variables don't, so much: x < 2 < y What exactly does that mean, and why is it written that way? We can figure out how the interpreter will parse that, but does that correspond to the programmer's intention? It'd be more useful but less clear if one of the conditions points the other way: x < 2 > y which checks that they're both less than two, but IMO in a less-than-clear way. ChrisA From steve+comp.lang.python at pearwood.info Sat Mar 29 22:24:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 02:24:59 GMT Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5337807b$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Mar 2014 17:36:55 -0500, Tim Chase wrote: > And for cases where you have more than one or two things to test for > None-itude, you could use > > if all(x is None for x in [a, b, c, d]): > do_something_if_theyre_all_None() > > or > > if all(x is not None for x in [a, b, c, d]): > do_something_if_no_Nones() > > or > > if not any(x is None for x in [a, b, c, d]): > do_something_if_no_Nones() > > which I find *much* more readable from a maintenance point of view. With one or two things, I would stick to a regular comparison (skipping the "not"): a is None a is b is None With three, I would consider either idiom: a is b is c is None all(x is None for x in (a, b, c)) but lean towards the use of all(). From four onwards I would definitely use all(), and of course if there is an arbitrary number of items, I would definitely use all(). -- Steven D'Aprano http://import-that.dreamwidth.org/ From roy at panix.com Sat Mar 29 22:39:45 2014 From: roy at panix.com (Roy Smith) Date: Sat, 29 Mar 2014 22:39:45 -0400 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > Chained comparisons where you're checking a single variable against > two constants make perfect sense: > > 2 < x < 5 > > Chained comparisons where you check a single constant against two > variables don't, so much: > > x < 2 < y To me, chained comparisons make intuitive sense when they're all "<" (or "<="). I just think back to junior high school algebra class, with the big number line above the blackboard. Thus, a < b < c means if you put a, b, and c on the number line, a is to the left of b, which is to the left of c. I have no problem extending that to more than three values: a < b < c < d < e still makes intuitive sense. I have no particular problem with x < 2 < y because it fits the same pattern. But, if you show me a != None != b: my brain just goes into overload. Honestly, I don't even know what that means. My brain keeps trying to stick a, None, and b on Mrs. Albaum's number line and keeps walking into the wall. If you (the editorial you) tell me that my failure to grok that expression means I'm not fluent in Python, well then, guilty as charged. From roy at panix.com Sat Mar 29 22:43:00 2014 From: roy at panix.com (Roy Smith) Date: Sat, 29 Mar 2014 22:43:00 -0400 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337807b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5337807b$0$29994$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > a is b is c is None And we are all together. See how they run like pigs from a gun, see how they fly. From michael.weylandt at gmail.com Sat Mar 29 22:50:31 2014 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Sat, 29 Mar 2014 22:50:31 -0400 Subject: Dynamically reference member of array In-Reply-To: References: Message-ID: On Wed, Mar 26, 2014 at 7:43 AM, Ben Collier wrote: > Hi all, > > I know that I can dynamically reference a variable with locals()["i"], for instance, but I'd like to know how to do this with a variable in an object. > > If I have an object called "device", with variables called attr1, attr2 .. attr50, how could I dynamically reference these? > I think the pythonic term you're looking for is "attribute". See getattr() and setattr() Cheers, Michael From rustompmody at gmail.com Sat Mar 29 22:54:09 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 29 Mar 2014 19:54:09 -0700 (PDT) Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <308493ad-d904-4897-8d7d-6f7780a6bb7d@googlegroups.com> On Sunday, March 30, 2014 8:09:45 AM UTC+5:30, Roy Smith wrote: > I have no particular problem with > x < 2 < y > because it fits the same pattern. But, if you show me > a != None != b: > my brain just goes into overload. Honestly, I don't even know what that > means. My brain keeps trying to stick a, None, and b on Mrs. Albaum's > number line and keeps walking into the wall. If you (the editorial you) > tell me that my failure to grok that expression means I'm not fluent in > Python, well then, guilty as charged. A relation that is reflexive antisymmetric and transitive is a partial order Strict order: Irreflexive asymmetric and transitive Both are strongly related For general R (partial) S (strict) S from R xSy = xRy ? x ? y R from S xRy = xSy ? x=y For both these chained comparisons are natural != is not transitive: 2 != 3 and 3 != 2 ? 2 == 2 So for != chained comparisons are not natural (or IMHO appropriate) From zachary.ware+pylist at gmail.com Sat Mar 29 23:04:39 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Sat, 29 Mar 2014 22:04:39 -0500 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337807b$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2f7e07e3-4db6-467d-b662-a3db18f69889@email.android.com> On March 29, 2014 9:43:00 PM CDT, Roy Smith wrote: >In article <5337807b$0$29994$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> a is b is c is None > >And we are all together. See how they run like pigs from a gun, see >how >they fly. I'm cryin'. (Really, that was terrible.) Walrus-ly y'rs, Zach From harrismh777 at gmail.com Sun Mar 30 01:52:20 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 30 Mar 2014 00:52:20 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: On 3/29/14 10:45 AM, Mark Lawrence wrote: > On 29/03/2014 08:21, Mark H Harris wrote: >> >> Yes. Well, as the joke goes, if you're trilingual you speak three >> languages, if you're bilingual you speak two languages, if you're >> monolingual you're an American (well, that might go for Australia too, >> maybe). When whole continents speak the same language that tends to >> happen. > > You mean like the USA, where I saw an ad in a shop for a bilingual shop > assistant? Or is Spanish so like US English it doesn't count as a > separate language? I'm not sure what point you are trying to make. We have people here from all over the earth, and enough illegal immigrants speaking Spanish to account for a population about the size of Ohio. But, Americans are mostly monolingual. ...point of fact. The people of the United States are in a smallish battle over whether the official language of the United States should be English? In other words, no special signs, if you're going to live here you're going to learn English (end of the story, for some people). I'm not in that camp. I am preparing to start French studies soon. My son and daughter are fifth year fluent in Spanish (my daughter is minoring in Spanish, and plans study abroad for that purpose as she prepares for medical school. There is no nice way to say this... we have a lot of pin-headed bigots living here that have to intention nor inclination to learn another language. Some of them even think that if English was good enough for Jesus , its got to be good enough for them (I'm not kidding). Sadly, true. But then, more than half of our population is not aware that the earth revolves around the sun, either. :-} Cheers From steve+comp.lang.python at pearwood.info Sun Mar 30 01:54:11 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 05:54:11 GMT Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5337b182$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Mar 2014 13:15:18 +1100, Chris Angelico wrote: > On Sun, Mar 30, 2014 at 1:04 PM, Steven D'Aprano > wrote: >> On Sat, 29 Mar 2014 17:07:20 -0400, Roy Smith wrote: >> >>> I certainly agree that things like >>> >>>> if a is not b is not None: ... >>> >>> belong in an obfuscated coding contest. >> >> Apart from the fact that I got it wrong (that's what happens when I >> post at 6am after being up all night, thanks for the correction Lele), >> if you consider chained comparisons to be "obfuscated", I think you're >> not really fluent at Python. The OP even suggested `a != None != b` so >> I think that (s)he at least understands chained comparisons. >> >> However, I agree with Johannes that inverted conditions (using "not") >> are sometimes harder to reason about than "regular" conditions. > > Chained comparisons where you're checking a single variable against two > constants make perfect sense: > > 2 < x < 5 > > Chained comparisons where you check a single constant against two > variables don't, so much: > > x < 2 < y > > What exactly does that mean, and why is it written that way? It checks that 2 is strictly bounded between x on the left and y on the right, i.e. that 2 is inside the open interval x...y. I don't know why you think that's unclear. But then I do have a maths background and I'm used to chaining comparisons. Write it like this: low = x high = y a = 2 low < a < high Does that make more sense? Well-chosen names are good. The fact that a is a constant rather than a variable is no big deal: low < 2 < high > We can > figure out how the interpreter will parse that, but does that correspond > to the programmer's intention? That applies to just about anything: (x % 2 == 1) or (x > 0) What that my intention, or did I intend to write (x % 2 == 0) and (x < 0) At some point you just have to accept that, in the absence of clearly nonsensical code or a contradiction between the documentation and the behaviour (i.e. a bug), the programmer will have written what she intended to write. > It'd be more useful but less clear if one of the conditions points the > other way: > > x < 2 > y > > which checks that they're both less than two, which is quite different from what you wrote the first time. > but IMO in a less-than-clear way. That's an understatement. If I saw code chaining comparisons in that fashion, I would assume the second operator > was a typo. Chaining less-than and greater than operators should, for clarity, always be written in a single order. E.g. a <= b < c < d, not a <= b < d > c. (The second contains a subtle bug too.) -- Steven D'Aprano http://import-that.dreamwidth.org/ From harrismh777 at gmail.com Sun Mar 30 01:57:41 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 30 Mar 2014 00:57:41 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <87txahi68z.fsf@elektro.pacujo.net> <87lhvti5as.fsf@elektro.pacujo.net> Message-ID: On 3/29/14 6:59 AM, Marko Rauhamaa wrote: > I hate localization. You get a error message in Finnish from "make" or > "grep" and then you try to google it. > > So mine is en_US, but I know people who do fi_FI. ... this is my point precisely. From steve+comp.lang.python at pearwood.info Sun Mar 30 02:08:37 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 06:08:37 GMT Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> <308493ad-d904-4897-8d7d-6f7780a6bb7d@googlegroups.com> Message-ID: <5337b4e4$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Mar 2014 19:54:09 -0700, Rustom Mody wrote: > On Sunday, March 30, 2014 8:09:45 AM UTC+5:30, Roy Smith wrote: >> I have no particular problem with > >> x < 2 < y > >> because it fits the same pattern. But, if you show me > >> a != None != b: > >> my brain just goes into overload. Honestly, I don't even know what >> that means. My brain keeps trying to stick a, None, and b on Mrs. >> Albaum's number line and keeps walking into the wall. If you (the >> editorial you) tell me that my failure to grok that expression means >> I'm not fluent in Python, well then, guilty as charged. > > [...] > So for != chained comparisons are not natural (or IMHO appropriate) I tend to agree they're "not natural", although appropriate is another thing. The problem is that we tend to read something like: a != b != c as "all of a, b and c are unequal", corresponding to: a == b == c as "all of a, b and c are equal". But that's not what it means. It means that a != b and b != c, but it says nothing about a and c. And that was my mistake. The OP actually got it right in their first post, but sticking None in the middle to ensure it partakes of both comparisons. a is not None is not b Still, that's not easily extended to a third item, this would be wrong: a is not None is not b is not c since c only gets compared against b, not None. Better is to factor the "not" out: not (a is b is c is None) which now should be clear: you're testing whether or not *all* of a, b and c are None. If you prefer: not all(x is None for x in (a, b, c)) Which is more readable is a matter of personal preference. I think Johannes got it right: boolean logic is easier to reason about when there is a minimum of "not"s. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sun Mar 30 02:17:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Mar 2014 17:17:34 +1100 Subject: checking if two things do not equal None In-Reply-To: <5337b182$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337b182$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 30, 2014 at 4:54 PM, Steven D'Aprano wrote: > On Sun, 30 Mar 2014 13:15:18 +1100, Chris Angelico wrote: > >> Chained comparisons where you're checking a single variable against two >> constants make perfect sense: >> >> 2 < x < 5 >> >> Chained comparisons where you check a single constant against two >> variables don't, so much: >> >> x < 2 < y >> >> What exactly does that mean, and why is it written that way? > > It checks that 2 is strictly bounded between x on the left and y on the > right, i.e. that 2 is inside the open interval x...y. I don't know why > you think that's unclear. But then I do have a maths background and I'm > used to chaining comparisons. > > Write it like this: > > low = x > high = y > a = 2 > > low < a < high > > Does that make more sense? Well-chosen names are good. The fact that a is > a constant rather than a variable is no big deal: > > low < 2 < high The problem isn't that I can't see what the comparisons are. It makes very good sense to bound a variable within constants; but you already know exactly where 2 is on the number line, so asking "Is 2 between these two variables" seems a bit odd. Maybe it's less so with the strong mathematical background, but it seems odd to me. >> It'd be more useful but less clear if one of the conditions points the >> other way: >> >> x < 2 > y >> >> which checks that they're both less than two, > > which is quite different from what you wrote the first time. > > >> but IMO in a less-than-clear way. > > That's an understatement. If I saw code chaining comparisons in that > fashion, I would assume the second operator > was a typo. > > Chaining less-than and greater than operators should, for clarity, always > be written in a single order. E.g. a <= b < c < d, not a <= b < d > c. > > (The second contains a subtle bug too.) Agreed. ChrisA From greg.ewing at canterbury.ac.nz Sun Mar 30 02:16:47 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 30 Mar 2014 19:16:47 +1300 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53320793.8070501@stoneleaf.us> <533241C0.8020109@mrabarnett.plus.com> <53329549.1000208@rece.vub.ac.be> <6d2ej9hve7v7m3jfbre1jn9v1loacfr8lo@4ax.com> Message-ID: Chris Angelico wrote: > a 5x8 bitmap has > forty pixels, any of which can be either on or off - that gives > roughly twice as much data space as the 21-bit Unicode spec. We don't need a font, then -- just map the pixels straight onto bits in the character code! Might require some user re-education, but that's a small price to pay for saving so much memory space. -- Greg From harrismh777 at gmail.com Sun Mar 30 02:22:55 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 30 Mar 2014 01:22:55 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53370898$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/29/14 12:53 PM, Steven D'Aprano wrote: > People have had localised code pages, and localised keyboards to enter > characters in those code pages, for up to 30 years, if not longer. Nobody is arguing otherwise, Steven. Having a code page for a local language is not the same thing as having software that supports your local language code page! Software and code pages improved over time, but international communication (which is what I'm talking about) has always been done in English, using ASCII. Well except when Guido brought the ABC stuff to the states back in the day and had no way to do that except to fly himself (and the tape) personally. > > In some of those cases, the localisation was done by companies like IBM, > Microsoft and Apple, realising that if they wanted to sell computers > outside of the US, they needed to supply computers that were localised to > their market. Unfortunately that happened way late. And even then, international communication was still done (and is still done) in English. Only until very recently (see my post to Chris) has unicode improved to the point where international comm can occur reliably enough (input, font, code points) to allow comm in languages other than English. And yet, although Kanji has been around for a while, most international comm is still handled in English because its the lingua franca. > This code page system actually worked pretty well, so long as you only > exchange documents with people using the same code page. Until the > Internet, that was mostly the case. My point exactly. With the advent of the Internet, almost *all* comm is English with minor notable exceptions in today's environment. Just look around, you need not argue with me. You can find places for local comm, but they are sparse. > >> That's why they called it ASCII American Standard >> Code for Information Interchange... > > Yes. So what? Just because ASCII exists doesn't mean everyone uses it > *exclusively*. Yeah, well, that's exactly what happened; its still happening. Only today its UTF-8, a Latin script (there is only one) and thousands of people all over the earth on the Internet speaking English around the globe. Yeah, I know, there are localized pockets and people using their computer in their heart language, but for international communication you're going to find (primarily) people communicating in English. > With the demise of EBCDIC as the standard character encoding (actually > plural encodings, because EBCDIC has code pages too), Ha! That's funny. EBCIDIC is | was standard only at IBM. Those stubborn people (I used to be one of them) stuck with EBCIDIC and SNA/SDLC until they realized that they could not communicate with the rest of the world using ASCII and TCP/IP. ... just hilarious! > ASCII has become > the lowest common denominator for most (but not all) character sets. Pre- > Unicode, most (but definitely not all!) code pages were based on ASCII, > either with a few changes, or extending it to a full 8 bits. Yup. > But that's the point: Yes it is. > most people with access to computing in the first > place, also had access to input methods and code pages for their native > language. Your idea that they were forced to use ASCII exclusively, with > no way of entering their own language, is simply wrong. I'm not arguing that, Steven. You're just being silly. I'm talking about be forced to communicate around the world when most of the people communicating are speaking English and using ASCII. Look, I can unplug my computer from the Internet and use it to translate biblical Greek and O.T. Hebrew and be happy as a clam that I'm locally doing my own thing in my own language (so what)? The moment I want to communicate outside my local space I better know English, and I better have a code page that supports it. If you live in Israel, and only communicate with people in Israel, you can use your modern Hebrew font and code page and be happy as a clam; but if you want to communicate with somebody in IOWA, perhaps Iowa State for some reason, you better know English. Just say'n. On the other hand, just look around the Internet. 98% of all communication is English using UTF-8 today. Yes, you can find pockets where this is not true, but primarily, the world is using a modern lingua franca. I am very interested with the intense interest in this topic. marcus From steve+comp.lang.python at pearwood.info Sun Mar 30 02:31:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 06:31:36 GMT Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Mar 2014 00:52:20 -0500, Mark H Harris wrote: > On 3/29/14 10:45 AM, Mark Lawrence wrote: >> On 29/03/2014 08:21, Mark H Harris wrote: >>> >>> Yes. Well, as the joke goes, if you're trilingual you speak three >>> languages, if you're bilingual you speak two languages, if you're >>> monolingual you're an American (well, that might go for Australia too, >>> maybe). When whole continents speak the same language that tends to >>> happen. >> >> You mean like the USA, where I saw an ad in a shop for a bilingual shop >> assistant? Or is Spanish so like US English it doesn't count as a >> separate language? > > I'm not sure what point you are trying to make. We have people here from > all over the earth, and enough illegal immigrants speaking Spanish to > account for a population about the size of Ohio. *raises eyebrow* Did you intend to imply that it is only illegal immigrants who speak Spanish in the USA? The most recent US census found there are 38.5 million people in the US who primarily speak Spanish, and 45 million who speak it as their first or second language. In comparison, there are only an estimated 11 million illegal immigrants (of which only 7 million is from Mexico). https://en.wikipedia.org/wiki/Spanish_language_in_the_United_States -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sun Mar 30 02:43:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Mar 2014 17:43:31 +1100 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] In-Reply-To: <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 30, 2014 at 5:31 PM, Steven D'Aprano wrote: > Did you intend to imply that it is only illegal immigrants who speak > Spanish in the USA? I think he's correct there. After all, anyone who doesn't fit the white-skinned monolingual (barely-one-language, really) middle-class stereotype *MUST* be an illegal immigrant - right? That's how you recognize who to be rude to. http://notalwaysright.com/pepperoni-extremism/3163 http://notalwaysright.com/no-obamacare-for-you/17102 http://notalwaysworking.com/they-are-rotten-to-the-corps-part-2/32108 ... and plenty more stories besides. ChrisA From greg.ewing at canterbury.ac.nz Sun Mar 30 02:41:36 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 30 Mar 2014 19:41:36 +1300 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Roy Smith wrote: > But, if you show me > > a != None != b: > > my brain just goes into overload. Chained comparisons get weird with not-equal operators. If you see a == b == c then it implies that a == c, but a != b != c does *not* imply that a != c. At least it doesn't in Python; I've never seen any mathematicians write that, so I don't know what they would make of it. -- Greg From harrismh777 at gmail.com Sun Mar 30 02:48:27 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 30 Mar 2014 01:48:27 -0500 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/30/14 1:31 AM, Steven D'Aprano wrote: >> I'm not sure what point you are trying to make. We have people here from >> all over the earth, and enough illegal immigrants speaking Spanish to >> account for a population about the size of Ohio. > > *raises eyebrow* > > Did you intend to imply that it is only illegal immigrants who speak > Spanish in the USA? Don't be silly, Steven, it doesn't become you. > The most recent US census found there are 38.5 million people in the US > who primarily speak Spanish, and 45 million who speak it as their first > or second language. In comparison, there are only an estimated 11 million > illegal immigrants (of which only 7 million is from Mexico). > > https://en.wikipedia.org/wiki/Spanish_language_in_the_United_States Hilarious! That's part of the problem, um, its because they are *illegal* that the census bureau does not know about them in terms of exact numbers; its a nice effort though. America is a melting pot (always has been). We have thousands of ethnic groups living here and thousands of languages spoken here. All of them are in some place on the continuum of English as a second language; its the only way to survive here. marcus From ben+python at benfinney.id.au Sun Mar 30 02:52:07 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 30 Mar 2014 17:52:07 +1100 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337b182$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85wqfcmb54.fsf@benfinney.id.au> Chris Angelico writes: > The problem isn't that I can't see what the comparisons are. It makes > very good sense to bound a variable within constants; but you already > know exactly where 2 is on the number line, so asking "Is 2 between > these two variables" seems a bit odd. Maybe it's less so with the > strong mathematical background, but it seems odd to me. I don't feel odd about asking the question ?Is 2 between these two values??. It's straightforward and concise. Can you explain better why you find it odd? -- \ ?You are welcome to visit the cemetery where famous Russian and | `\ Soviet composers, artists, and writers are buried daily except | _o__) Thursday.? ?Russian orthodox monastery, Moscow | Ben Finney From orgnut at yahoo.com Sun Mar 30 02:53:46 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Sat, 29 Mar 2014 23:53:46 -0700 Subject: Keyboard standards In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/29/2014 12:41 PM, Michael Torrie wrote: > On 03/29/2014 01:27 PM, Larry Hudson wrote: >> On 03/28/2014 09:26 PM, Mark H Harris wrote: >>> >>> PS Thunderbird puts *both* the list and the news group addys in the to: header field on >>> reply-to-list. ~nice, huh. >> >> Must be the way YOU set it up. MY Thunderbird (currently version 24.4.0 on Mint Linux 16) >> doesn't do any such thing. Besides, "Reply" sends private e-mail to the poster -- "Followup" >> sends to the newsgroup. > > No, Mark describes the standard way Thunderbird works. Reply-to-List > does what he says it does. Not sure why your installation works > differently. I guess maybe you are talking about something different. > The mailing list vs the NNTP list. > You're right -- I use the NNTP list only. I've never looked at the Python mailing list. The very few mailing lists I subscribe to, I only read--never reply to. Come to think of it, currently there's only one, and I rarely do more than skim it briefly--and frequently not even that. I should drop it altogether, just haven't bothered to do so. -=- Larry -=- From orgnut at yahoo.com Sun Mar 30 03:32:58 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Sun, 30 Mar 2014 00:32:58 -0700 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: On 03/29/2014 10:52 PM, Mark H Harris wrote: > On 3/29/14 10:45 AM, Mark Lawrence wrote: >> On 29/03/2014 08:21, Mark H Harris wrote: >>> >>> Yes. Well, as the joke goes, if you're trilingual you speak three >>> languages, if you're bilingual you speak two languages, if you're >>> monolingual you're an American (well, that might go for Australia too, >>> maybe). When whole continents speak the same language that tends to >>> happen. >> >> You mean like the USA, where I saw an ad in a shop for a bilingual shop >> assistant? Or is Spanish so like US English it doesn't count as a >> separate language? > > I'm not sure what point you are trying to make. We have people here from all over the earth, and > enough illegal immigrants speaking Spanish to account for a population about the size of Ohio. > But, Americans are mostly monolingual. ...point of fact. > I believe the point is your generalized use of "American". After all, Mexicans are Americans too, as well as Canadians, Peruvians and ... Unfortunately, there is no good word for "USA-ian". "United States Citizen" is too long and awkward and "United Statesian" is ridiculous. The common usage of "American" for this is at best ambiguous, and definitely inaccurate (as well as chauvinistic, and rather insulting to other North and South Americans outside the US). -=- Larry -=- From rosuav at gmail.com Sun Mar 30 03:36:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Mar 2014 18:36:49 +1100 Subject: checking if two things do not equal None In-Reply-To: <85wqfcmb54.fsf@benfinney.id.au> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337b182$0$29994$c3e8da3$5496439d@news.astraweb.com> <85wqfcmb54.fsf@benfinney.id.au> Message-ID: On Sun, Mar 30, 2014 at 5:52 PM, Ben Finney wrote: > Chris Angelico writes: > >> The problem isn't that I can't see what the comparisons are. It makes >> very good sense to bound a variable within constants; but you already >> know exactly where 2 is on the number line, so asking "Is 2 between >> these two variables" seems a bit odd. Maybe it's less so with the >> strong mathematical background, but it seems odd to me. > > I don't feel odd about asking the question ?Is 2 between these two > values??. It's straightforward and concise. Can you explain better why > you find it odd? Possibly because the "variable between two constants" is something I've done often (usually in the more explicit form of "x > min && x < max" in a language without chained comparisons), usually bounds-checking some value. I've never had to ask whether a single constant has two variables, one on either side. But that's just that I've personally never done it; it doesn't mean nobody does it, by any means. ChrisA From marko at pacujo.net Sun Mar 30 03:37:45 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 30 Mar 2014 10:37:45 +0300 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y4zsf86u.fsf@elektro.pacujo.net> Gregory Ewing : > a != b != c > > does *not* imply that a != c. At least it doesn't in Python; I've > never seen any mathematicians write that, so I don't know what they > would make of it. Any resemblance between mathematics notation and Python is purely coincidental. I must admit I had missed Python's chained comparisons until this discussion, but now I looked up the definition: comparison ::= or_expr ( comp_operator or_expr )* comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!=" | "is" ["not"] | ["not"] "in" [...] Formally, if a, b, c, ..., y, z are expressions and op1, op2, ..., opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once. That means, in my opinion, that you should feel free to use chaining any way you see fit. Also, the rule is crystal-clear and easy to grasp: there's an implicit "and" there. It's another thing, then, if it was a good idea to include chaining there in the first place, but I trust the idea was properly vetted and double checked against possible parsing ambiguities. Even without chaining "is not" is a bit suspect: >>> False is not 0 True >>> False is (not 0) False >>> False is not not not 0 File "", line 1 False is not not not 0 ^ SyntaxError: invalid syntax Marko From steve+comp.lang.python at pearwood.info Sun Mar 30 06:35:48 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 10:35:48 GMT Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5337f383$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Mar 2014 01:48:27 -0500, Mark H Harris wrote: > On 3/30/14 1:31 AM, Steven D'Aprano wrote: >>> I'm not sure what point you are trying to make. We have people here >>> from all over the earth, and enough illegal immigrants speaking >>> Spanish to account for a population about the size of Ohio. >> >> *raises eyebrow* >> >> Did you intend to imply that it is only illegal immigrants who speak >> Spanish in the USA? > > Don't be silly, Steven, it doesn't become you. Given the sorts of patronising, condescending things you insist are true about non-Americans, such as their supposed inability to communicate in their own language on the Internet, I wasn't sure. >> The most recent US census found there are 38.5 million people in the US >> who primarily speak Spanish, and 45 million who speak it as their first >> or second language. In comparison, there are only an estimated 11 >> million illegal immigrants (of which only 7 million is from Mexico). >> >> https://en.wikipedia.org/wiki/Spanish_language_in_the_United_States > > Hilarious! That's part of the problem, um, its because they are > *illegal* that the census bureau does not know about them in terms of > exact numbers; its a nice effort though. The number of illegal immigrants is not estimated from the Census numbers directly. It's not like they have a tick box "Are you in this country illegally?". Just because *you* don't know how illegal immigrant numbers are estimated, or what margin of error those estimates might have, don't make the mistake of imagining that any such effort is "hilarious", a joke, or otherwise useless. Naturally the figure is *estimated*, I even said it was estimated, and gave it as a round number. If I had said there were 11,205,971 illegal immigrants in the USA as of last Tuesday, then you would have a good excuse to mock my spurious precision. Otherwise, not so much. > America is a melting pot (always has been). We have thousands of > ethnic groups living here and thousands of languages spoken here. Not really. There are under 350 languages spoken in the USA. Over 92% of the population speaking just two of them, English and Spanish, with Chinese a *very* distant third. Only eight languages are spoken by more than 1 million people. Even if you double that figure, to capture "that one guy who speaks Gunwinyguan" and other outliers, you still end up well under even a single thousand. The surprising thing to me about this is not that the number of languages is so low (there are about 6000-7000 languages in the world), but that it is so high. I would have predicted well under 100. After all, spoken language popularity is an excellent example of network effects: the more people who speak a language, the more valuable it is to speak the same language. Network effects explain why, out of the six or seven thousand languages in the world, just thirteen account for more than half the world's population: 1) Mandarin 2) Spanish 3) English 4) Hindi 5) Arabic 6) Portuguese 7) Bengali 8) Russian 9) Japanese 10) Punjabi 11) German 12) Javanese 13) Wu adding up to 51%. The next thirteen bring the total to 64%. (Figures are, naturally, approximate and subject to change.) > All of > them are in some place on the continuum of English as a second language; > its the only way to survive here. Approximately 5% of the US population either do not speak English at all, or speak it poorly. That includes approximately half a million ASL speakers (American Sign Language, which is not a manual representation of English but an independent language in it's own right), the majority of whom are unable to speak or understand spoken English. Be careful of making sweeping generalisations like "the only way to survive". Especially when they're so judgemental. It's not like there are gangs of armed militia hunting down deaf children and foreign grannies who only speak the language of their homeland. Well, maybe in Arizona. *wink* -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Sun Mar 30 06:44:13 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 10:44:13 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: <5337f57d$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Mar 2014 00:32:58 -0700, Larry Hudson wrote: > Unfortunately, there is no good word for "USA-ian". "United States > Citizen" is too long and awkward and "United Statesian" is ridiculous. > The common usage of "American" for this is at best ambiguous, and > definitely inaccurate (as well as chauvinistic, and rather insulting to > other North and South Americans outside the US). Among fans of the British writer Terry Pratchett, the usual term is Merkins. Including among Merkin fans. -- Steven D'Aprano http://import-that.dreamwidth.org/ From rosuav at gmail.com Sun Mar 30 08:03:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Mar 2014 23:03:26 +1100 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] In-Reply-To: <5337f383$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337f383$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 30, 2014 at 9:35 PM, Steven D'Aprano wrote: > Network effects explain why, out of the six or seven thousand languages > in the world, just thirteen account for more than half the world's > population: > > 1) Mandarin > 2) Spanish > 3) English > 4) Hindi > 5) Arabic > 6) Portuguese > 7) Bengali > 8) Russian > 9) Japanese > 10) Punjabi > 11) German > 12) Javanese > 13) Wu > > adding up to 51%. The next thirteen bring the total to 64%. Where did that info come from? And more importantly, what does it count? Is that people's first language, or all languages known, or what? A bit of Googling brought me to a Wikipedia page [1] which quotes a similar figure of thirteen languages; that's talking about native speakers, and is talking about native speakers. But that may not be the most useful definition here. An alternative useful definition is "accessibility": if you communicate a message in Mandarin and English, a large proportion of humans will be capable of understanding that message. Does it take the above thirteen to exceed 50% of the world by that definition? Or wording it another way, is there no set of twelve or less languages which will reach 50% of the world? There's another Wikipedia page [2] that tries to estimate total number of speakers, but it's nearly impossible to get any sort of accurate figure; it puts Mandarin at somewhere over a billion people, and English as another billion or so; that's coming up toward 50% right there (say, 1.5b each is 3b, out of a world population of 7b). Ball-park figures, those two plus Spanish (another half billion or so) would pretty much hit your half mark. I've no idea what point I'm trying to make here. Just poking around with numbers. :) ChrisA [1] https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers [2] https://en.wikipedia.org/wiki/List_of_languages_by_total_number_of_speakers From roy at panix.com Sun Mar 30 08:08:52 2014 From: roy at panix.com (Roy Smith) Date: Sun, 30 Mar 2014 08:08:52 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: In article , Larry Hudson wrote: > I believe the point is your generalized use of "American". After all, > Mexicans are Americans too, as well as Canadians, Peruvians and ... > > Unfortunately, there is no good word for "USA-ian". I believe Mexicans refer to us as "norteamericanos" in polite company. That's a little long for daily use, so more typically it's shortened to "gringo". From roy at panix.com Sun Mar 30 08:21:25 2014 From: roy at panix.com (Roy Smith) Date: Sun, 30 Mar 2014 08:21:25 -0400 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> <308493ad-d904-4897-8d7d-6f7780a6bb7d@googlegroups.com> <5337b4e4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5337b4e4$0$29994$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I think Johannes got it right: boolean logic is easier to reason about > when there is a minimum of "not"s. I used to do a lot of digital logic design. In certain logic families, it's easier to build a NAND gate than an AND gate (and similarly, NOR is easier than OR). This leads to lots of inverted logic. Adding to the confusion, many designs would use "active low" logic, which means a 1 was represented by a low voltage, and a 0 by a high voltage. So, you quickly end up with gibberish like, "not active low clear nand not active low enable clock". I'm glad I don't do that stuff any more. From python at mrabarnett.plus.com Sun Mar 30 09:58:11 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 30 Mar 2014 14:58:11 +0100 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> <308493ad-d904-4897-8d7d-6f7780a6bb7d@googlegroups.com> <5337b4e4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533822F3.5070407@mrabarnett.plus.com> On 2014-03-30 13:21, Roy Smith wrote: > In article <5337b4e4$0$29994$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> I think Johannes got it right: boolean logic is easier to reason about >> when there is a minimum of "not"s. > > I used to do a lot of digital logic design. In certain logic families, > it's easier to build a NAND gate than an AND gate (and similarly, NOR is > easier than OR). This leads to lots of inverted logic. Adding to the > confusion, many designs would use "active low" logic, which means a 1 > was represented by a low voltage, and a 0 by a high voltage. So, you > quickly end up with gibberish like, "not active low clear nand not > active low enable clock". I'm glad I don't do that stuff any more. > When you're building with discrete logic chips, NAND gates are useful because you can use them as inverters too, which helps to keep the chip count down. From steve+comp.lang.python at pearwood.info Sun Mar 30 11:22:45 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 15:22:45 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> Message-ID: <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sat, 29 Mar 2014 03:21:29 -0500, Mark H Harris wrote: > On 3/29/14 1:03 AM, Chris Angelico wrote: >> >> http://forum.ecomstation.ru/ >> >> Prominent discussion forum, although that strives to be at least >> partially bilingual in deference to those of us who are so backward as >> to speak only English. > > Yes. Well, as the joke goes, if you're trilingual you speak three > languages, if you're bilingual you speak two languages, if you're > monolingual you're an American (well, that might go for Australia too, > maybe). When whole continents speak the same language that tends to > happen. I think that the Qu?b?cois and Mexicans might object to your characterisation of North America as speaking a single language. English is the primary lingua franca in various fields, such as aviation, diplomacy, trade and, yes, computing. But it's not the only lingua franca in common use: French and Spanish are the second and third most common languages used in international trade, and Arabic, Mandarin, Cantonese, Russian, and many others remain important regional and international lingua francas: https://en.wikipedia.org/wiki/List_of_lingua_francas English currently is the dominant international language, but it is not the only such language, and it's dominance is not so complete that other languages are second-class. One need only look at your spam folder, and see how much spam is sent in Chinese, Russian and other languages to realise that English hasn't even come close to taking over the planet yet. But none of which is really relevant to the question on hand. When people from France, Germany, Russia, Brazil and Japan get together on the Internet, they probably write English. When they are writing for themselves, they typically write in French, Germany, Russian, Brazilian Portuguese, and Japan. http://blog.gmane.org/gmane.comp.python.brasil http://blog.gmane.org/gmane.comp.accessibility.tanaguru http://blog.gmane.org/gmane.comp.apache.discussion.russian etc. [...] > What I can tell you in my own experience, as an amateur radio > operator (W0MHH, general class) who has communicated all over the earth > (even to Soviet Russia), all my computer|radio comm was in English using > Morse code sets, Latin characters, and ASCII. No one ever asked me to > comm in Russian, or French, nor Italian, nor Tswana... Are you aware that the astronauts on the International Space Station have to be fluent in Russian? Hardly surprising, since the Soyuz rockets used to get to the ISS are made by Russians, maintained by Russians, and launched by Russians. All the controls and manuals are written in Russian. One might almost say that the lingua franca of space travel is Russian. You're experience suggests that the lingua franca of the amateur radio community is English. If you wanted to be an astronaut, you'd need to learn Russian. (Although I wonder whether the Chinese agree about that.) Whenever you have people from a broad range of languages getting together and needing to communicate, they need to agree on a common tongue. Often that's English. Often it is not. http://www.arabo.com/ (I searched for "python", and got three hits: one in English and two in French.) > By the way, in my view, 1991 is very recently; In 1991, there was no wireless, no mobile computing, hardly any public Internet outside of the universities. It was before the Eternal September, and only a few years after the Great Renaming. Python had just been released for the first time, and Windows 3.1 hadn't been (although 3.0 had). There was no Netscape, no Mosaic graphical web browsers. Steve Jobs hadn't returned to Apple yet, Apple was still losing money and mind- share, and Google didn't even exist. It was a different era. 1991 is 23 years ago. In "computer years", I consider that almost eight generations, about the same as 160 years in human terms. > from a computer historical standpoint too. I mean, think > about it, computers have only existed since late 1940s and only in their > modern context since about 1989. I didn't really start using unicode > until about 5 years ago; python has only really used it since python3. > right? No. Python 2.2 introduced Unicode. -- Steven D'Aprano http://import-that.dreamwidth.org/ From ian.g.kelly at gmail.com Sun Mar 30 12:03:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 30 Mar 2014 10:03:47 -0600 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 30, 2014 9:26 AM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > > On Sat, 29 Mar 2014 03:21:29 -0500, Mark H Harris wrote: > > from a computer historical standpoint too. I mean, think > > about it, computers have only existed since late 1940s and only in their > > modern context since about 1989. I didn't really start using unicode > > until about 5 years ago; python has only really used it since python3. > > right? > > No. Python 2.2 introduced Unicode. Python 2.0 if the PEP 100 metadata is accurate. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Mar 30 12:22:45 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2014 16:22:45 GMT Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53370898$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <533844d5$0$29994$c3e8da3$5496439d@news.astraweb.com> On Sun, 30 Mar 2014 01:22:55 -0500, Mark H Harris wrote: > On 3/29/14 12:53 PM, Steven D'Aprano wrote: >> People have had localised code pages, and localised keyboards to enter >> characters in those code pages, for up to 30 years, if not longer. > > Nobody is arguing otherwise, Steven. It certainly seemed like you were. > Having a code page for a local > language is not the same thing as having software that supports your > local language code page! Of course they're not the same, but localised software does exist. You're making the mistake of thinking that because you only see English-language software, no other software exists. But you are an English-speaker in an English-speaking country, of course nearly all the software you see is written for English speakers. But if you were in Spain, the software you buy would be in Spanish: http://www.sevenforums.com/general-discussion/123741-changing-language- localization.html More about localisation: http://blogs.msdn.com/b/oldnewthing/archive/2012/07/26/10333558.aspx http://support.apple.com/kb/HT4239?viewlocale=fr_FR&locale=fr_FR Software and code pages improved over time, > but international communication (which is what I'm talking about) has > always been done in English, using ASCII. That's simply not correct. Even if we limit "always" to mean "since World War Two", it's still wrong. IBM was localising their computers for non- English markets before ASCII even existed, "code pages" was an IBM technology invented for EBCDIC-using mainframes before there were ASCII- using PCs. What is true is that English is the primary lingua franca on the Internet. But it's not the only one, and there are plenty of places on the Internet where people discuss things in their own language. > Well except when Guido brought > the ABC stuff to the states back in the day and had no way to do that > except to fly himself (and the tape) personally. >> >> In some of those cases, the localisation was done by companies like >> IBM, Microsoft and Apple, realising that if they wanted to sell >> computers outside of the US, they needed to supply computers that were >> localised to their market. > > Unfortunately that happened way late. And even then, international > communication was still done (and is still done) in English. And French. And Spanish. And Chinese. If you trade with most of Africa, knowing Arabic or French will probably be more useful than knowing English. > Only until > very recently (see my post to Chris) has unicode improved to the point > where international comm can occur reliably enough (input, font, code > points) to allow comm in languages other than English. Unicode has little to do with the ability to communicate in languages other than English. If you want to communicate in Greek, you don't need Unicode, you just need both parties to agree to use ISO-8859-7. If you want to communicate in Japanese, you could use Shift-JIS, or various others. Where Unicode comes into it is when you want to manage *mixed* communication. There's no way for me to include your ISO-8859-7 Greek text in my Shift-JIS Japanese document. I can use one, or the other, but not both. But with Unicode, I can use them both. [...] > My point exactly. With the advent of the Internet, almost *all* comm > is English with minor notable exceptions in today's environment. Not even close to "almost all". Barely half of the Internet is English. If you only look in the English-speaking corners of the Internet, it is hardly surprising that you only see people speaking English. Even at the high-point, English was only 80% of the Internet, 20% (that's *one in five* websites) was non-English: http://www.theatlantic.com/past/docs/issues/2000/11/wallraff3.htm That was a decade ago, and as predicted, the percentage of the Internet which uses English has plummeted as more non-English speakers have got on the 'net. Today, only 56% of the Internet is English: http://w3techs.com/technologies/overview/content_language/all That figure is based on the one million most popular websites. If you include *all* websites, you'll find the English percentage is even lower, and quite likely under 50%. https://en.wikipedia.org/wiki/Languages_used_on_the_Internet Some other points to consider: 44% of WordPress sites are non-English: http://venturebeat.com/2013/07/27/19-percent-of-the-web-runs-on-wordpress/ which is representative of the broader Internet. And since 2001, while the use of English on the Internet grew by 281%, other languages have grown much faster: - Spanish (743%) - Chinese (1,277%) - Russian (1,826%) - Arabic (2,501%) -- Steven D'Aprano http://import-that.dreamwidth.org/ From mtcplumb at googlemail.com Sun Mar 30 15:05:18 2014 From: mtcplumb at googlemail.com (mtcplumb at googlemail.com) Date: Sun, 30 Mar 2014 12:05:18 -0700 (PDT) Subject: writing reading from a csv or txt file Message-ID: <9023eae9-f814-40ac-9b84-043214e6b28f@googlegroups.com> Hi I have 3 csv files with a list of 5 items in each. rainfall in mm, duration time,time of day,wind speed, date. I am trying to compare the files. cutting out items in list list. ie:- first file (rainfall2012.csv)rainfall, duration,time of day,wind speed,date. first file (rainfall2013.csv)rainfall, duration,time of day,wind speed,date. I would like to pick out maybe rainfalls and duration's and measure against say years. I would like to very the items from the rows. could you please advise me where i can find such information. or book, textbook. From jsf80238 at gmail.com Sun Mar 30 16:19:48 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 30 Mar 2014 14:19:48 -0600 Subject: writing reading from a csv or txt file In-Reply-To: <9023eae9-f814-40ac-9b84-043214e6b28f@googlegroups.com> References: <9023eae9-f814-40ac-9b84-043214e6b28f@googlegroups.com> Message-ID: > > I am trying to compare the files. cutting out items in list list. ie:- > first file (rainfall2012.csv)rainfall, duration,time of day,wind > speed,date. > first file (rainfall2013.csv)rainfall, duration,time of day,wind > speed,date. > I would like to pick out maybe rainfalls and duration's and measure > against say years. > > Could you show us the first, say, three rows from each file, plus what you would like the first three or six lines of output to be? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcasale at activenetwerx.com Sun Mar 30 16:21:32 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 30 Mar 2014 20:21:32 +0000 Subject: writing reading from a csv or txt file In-Reply-To: <9023eae9-f814-40ac-9b84-043214e6b28f@googlegroups.com> References: <9023eae9-f814-40ac-9b84-043214e6b28f@googlegroups.com> Message-ID: <2230b359aade4572b3f4b3214373d7e7@exch.activenetwerx.com> > Hi I have 3 csv files with a list of 5 items in each. > rainfall in mm, duration time,time of day,wind speed, date. > I am trying to compare the files. cutting out items in list list. ie:- > first file (rainfall2012.csv)rainfall, duration,time of day,wind speed,date. > first file (rainfall2013.csv)rainfall, duration,time of day,wind speed,date. > I would like to pick out maybe rainfalls and duration's and measure against > say years. > I would like to very the items from the rows. > could you please advise me where i can find such information. or book, > textbook. How about we help you here.. So if you want to compare by year, you want to read all the rows in and perform some math, because I can't help myself, I push this into sqlite at least but that's probably overkill for you (besides the limitless benefits:)). You want to store some state while you iterate over each row in the csv, appending data, then finally performing some statistical math on the collection. You will do this for each file, then finally aggregate your results. jlc From gary.herron at islandtraining.com Sun Mar 30 16:26:55 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 30 Mar 2014 13:26:55 -0700 Subject: writing reading from a csv or txt file In-Reply-To: <9023eae9-f814-40ac-9b84-043214e6b28f@googlegroups.com> References: <9023eae9-f814-40ac-9b84-043214e6b28f@googlegroups.com> Message-ID: <53387E0F.3010409@islandtraining.com> On 03/30/2014 12:05 PM, mtcplumb at googlemail.com wrote: > Hi I have 3 csv files with a list of 5 items in each. > rainfall in mm, duration time,time of day,wind speed, date. > I am trying to compare the files. cutting out items in list list. ie:- > first file (rainfall2012.csv)rainfall, duration,time of day,wind speed,date. > first file (rainfall2013.csv)rainfall, duration,time of day,wind speed,date. > I would like to pick out maybe rainfalls and duration's and measure against say years. > I would like to very the items from the rows. > could you please advise me where i can find such information. or book, textbook. > How is this a Python question? There is a standard module included with Python for reading CSV files. Would you like to know how to use that? You can find documentation on it here: http://docs.python.org/3/library/csv.html Gary Herron From greg.ewing at canterbury.ac.nz Sun Mar 30 18:48:21 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 31 Mar 2014 11:48:21 +1300 Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> <308493ad-d904-4897-8d7d-6f7780a6bb7d@googlegroups.com> <5337b4e4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Roy Smith wrote: > Adding to the > confusion, many designs would use "active low" logic, which means a 1 > was represented by a low voltage, and a 0 by a high voltage. So, you > quickly end up with gibberish like, "not active low clear nand not > active low enable clock". There are ways of dealing with that in schematic diagrams. For exammple, if you have two active-low signals A and B and want to express "A is active or B is active", you draw an OR gate symbol with inversion circles on the inputs. That's equivalent to a NAND gate, but makes the intention clear. Schematics drawn that way are much easier to follow than ones that only use the inverted-output versions of the symbols. -- Greg From rhodri at wildebst.org.uk Sun Mar 30 18:57:30 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Sun, 30 Mar 2014 23:57:30 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337f57d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 30 Mar 2014 11:44:13 +0100, Steven D'Aprano wrote: > On Sun, 30 Mar 2014 00:32:58 -0700, Larry Hudson wrote: > >> Unfortunately, there is no good word for "USA-ian". "United States >> Citizen" is too long and awkward and "United Statesian" is ridiculous. >> The common usage of "American" for this is at best ambiguous, and >> definitely inaccurate (as well as chauvinistic, and rather insulting to >> other North and South Americans outside the US). > > Among fans of the British writer Terry Pratchett, the usual term is > Merkins. Including among Merkin fans. Many of whom even know what a merkin is, and use the term anyway. -- Rhodri James *-* Wildebeest Herder to the Masses From gouzounakis at hotmail.com Sun Mar 30 19:16:07 2014 From: gouzounakis at hotmail.com (D. Xenakis) Date: Sun, 30 Mar 2014 16:16:07 -0700 (PDT) Subject: Examples of modern GUI python programms Message-ID: Id like to ask.. do you know any modern looking GUI examples of windows software written in python? Something like this maybe: http://techreport.com/r.x/asus-x79deluxe/software-oc.jpg (or hopefully something like this android look: http://chromloop.com/wp-content/uploads/2013/07/Skype-4.0-Android-screenshot.jpg). What i need is to develop an android looking program (entirelly in python) for windows, but dunno if this is possible (most propably is), and which tool between those would help me most: tkinter - wxpython - pyqt - pygtk . Any examples and suggestions are most welcome. From python at mrabarnett.plus.com Sun Mar 30 19:20:24 2014 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 31 Mar 2014 00:20:24 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337f57d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5338A6B8.2070304@mrabarnett.plus.com> On 2014-03-30 23:57, Rhodri James wrote: > On Sun, 30 Mar 2014 11:44:13 +0100, Steven D'Aprano > wrote: > >> On Sun, 30 Mar 2014 00:32:58 -0700, Larry Hudson wrote: >> >>> Unfortunately, there is no good word for "USA-ian". "United States >>> Citizen" is too long and awkward and "United Statesian" is ridiculous. >>> The common usage of "American" for this is at best ambiguous, and >>> definitely inaccurate (as well as chauvinistic, and rather insulting to >>> other North and South Americans outside the US). >> >> Among fans of the British writer Terry Pratchett, the usual term is >> Merkins. Including among Merkin fans. > > Many of whom even know what a merkin is, and use the term anyway. > Isn't that what some said it sounded like when George W Bush said it? "My fellow 'mercns, ..." From walterhurry at gmail.com Sun Mar 30 20:39:24 2014 From: walterhurry at gmail.com (Walter Hurry) Date: Mon, 31 Mar 2014 00:39:24 +0000 (UTC) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337f57d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 30 Mar 2014 00:32:58 -0700, Larry Hudson wrote: > >> Unfortunately, there is no good word for "USA-ian". "United States >> Citizen" is too long and awkward and "United Statesian" is ridiculous. >> The common usage of "American" for this is at best ambiguous, and >> definitely inaccurate (as well as chauvinistic, and rather insulting to >> other North and South Americans outside the US). > > Among fans of the British writer Terry Pratchett, the usual term is > Merkins. Including among Merkin fans. > Tom Sharpe was there first, I think. By the way, his books are hilarious. From torriem at gmail.com Sun Mar 30 22:16:06 2014 From: torriem at gmail.com (Michael Torrie) Date: Sun, 30 Mar 2014 20:16:06 -0600 Subject: Examples of modern GUI python programms In-Reply-To: References: Message-ID: <5338CFE6.6050102@gmail.com> On 03/30/2014 05:16 PM, D. Xenakis wrote: > What i need is to develop an android looking program (entirelly in > python) for windows, but dunno if this is possible (most propably > is), and which tool between those would help me most: tkinter - > wxpython - pyqt - pygtk . > > Any examples and suggestions are most welcome. Your best bet is to use PyQt. I bet you can make some android-looking UIs using QtQuick (Javascript) with a bit of Python glue. From harrismh777 at gmail.com Mon Mar 31 00:29:13 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 30 Mar 2014 23:29:13 -0500 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337f383$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/30/14 5:35 AM, Steven D'Aprano wrote: > On Sun, 30 Mar 2014 01:48:27 -0500, Mark H Harris wrote: >> Don't be silly, Steven, it doesn't become you. > > Given the sorts of patronising, condescending things you insist are true > about non-Americans, such as their supposed inability to communicate in > their own language on the Internet, I wasn't sure. You just crossed the boundary from silly to asinine. > 1) Mandarin > 2) Spanish > 3) English > 4) Hindi > 5) Arabic > 6) Portuguese > 7) Bengali > 8) Russian > 9) Japanese > 10) Punjabi > 11) German > 12) Javanese > 13) Wu > > adding up to 51%. The next thirteen bring the total to 64%. Where the heck did you get that!?! ...wow. > (Figures are, naturally, approximate and subject to change.) no doubt. *wink* From harrismh777 at gmail.com Mon Mar 31 00:57:43 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Sun, 30 Mar 2014 23:57:43 -0500 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337f383$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/30/14 5:35 AM, Steven D'Aprano wrote: > Approximately 5% of the US population either do not speak English at all, > or speak it poorly. That includes approximately half a million ASL > speakers (American Sign Language, which is not a manual representation of > English but an independent language in it's own right), the majority of > whom are unable to speak or understand spoken English. Steven, you have trolled us over to the left edge of outer left field all the way back at the fence, dude, seriously--- and then you dropped the ball. Geeeze... error. My point at the beginning was that we need a universal unicode input device. Its time to think past US_104 and en_US. Come in out of left field. As long as I'm passing along my dreams to everyone, we also need a universal translator on the uptake. In other words, everyone inputs from a universal encoder, and every browser has the option of on-demand translation (or not). Its a little like google translate, but on-demand, and its standard, and it works everywhere with every language. Everyone keys input in their own heart language (first, primary language) and then the internet browser allows for display of first language (if the coding is the same) and translates if the coding is different (all configurable of course). Yes, the apps are in the cloud. What say you? We all type in our own language, and everyone else gets to read it in their own language. Its kinda like the day of Pentecost (except that its print instead of audio). marcus From rosuav at gmail.com Mon Mar 31 01:05:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 31 Mar 2014 16:05:25 +1100 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337f383$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 31, 2014 at 3:57 PM, Mark H Harris wrote: > As long as I'm passing along my dreams to everyone, we also need a universal > translator on the uptake. In other words, everyone inputs from a universal > encoder, and every browser has the option of on-demand translation (or not). > Its a little like google translate, but on-demand, and its standard, and it > works everywhere with every language. > > Everyone keys input in their own heart language (first, primary language) > and then the internet browser allows for display of first language (if the > coding is the same) and translates if the coding is different (all > configurable of course). Yes, the apps are in the cloud. > > What say you? We all type in our own language, and everyone else gets to > read it in their own language. Its kinda like the day of Pentecost (except > that its print instead of audio). And Pentecost required direct intervention of the all-powerful God of the universe. Any less, and you'll run into translation difficulties. It certainly cannot be automated; even done manually by people expert in both the source and target languages, translation is imperfect. ChrisA From harrismh777 at gmail.com Mon Mar 31 01:23:46 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 31 Mar 2014 00:23:46 -0500 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/30/14 1:31 AM, Steven D'Aprano wrote: > The most recent US census found there are 38.5 million people in the US > who primarily speak Spanish, and 45 million who speak it as their first > or second language. In comparison, there are only an estimated 11 million > illegal immigrants (of which only 7 million is from Mexico). The following link shows plenty of language stats (most of them differ from yours markedly; the estimates are just guesses really). The main point of the link is the status on English as an official language. 28 out of 50 states have legislated English as the official language; meaning, that you either speak and write English, or you're going to have a really tough time participating in culture, business, government, and recreation. http://en.wikipedia.org/wiki/Languages_of_the_United_States#Official_language_status marcus From harrismh777 at gmail.com Mon Mar 31 01:33:01 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 31 Mar 2014 00:33:01 -0500 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337f383$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/31/14 12:05 AM, Chris Angelico wrote: >> What say you? We all type in our own language, and everyone else gets to >> read it in their own language. Its kinda like the day of Pentecost (except >> that its print instead of audio). > > And Pentecost required direct intervention of the all-powerful God of > the universe. Any less, and you'll run into translation difficulties. > It certainly cannot be automated; even done manually by people expert > in both the source and target languages, translation is imperfect. Truth. Well, like I said, its a dream. And, we are finally at that point in time &space (fast computers, elegant programming languages, network, cloud apps, desire) where I think we could tackle universal translation. On the other hand, would it be easier to simply move everyone to a neutral lingua franca? For instance, lets say, biblical Greek. In other words, the entire world learns a new (dead) language. Then, we all move forward speaking ONE language and we forget the translation thing altogether? The reason that won't work is that everyone needs their heart language (as what it means to be human, and as what it means to be 'them'). How we speak is how we think, and feel. Its a conundrum for sure. marcus From rosuav at gmail.com Mon Mar 31 01:44:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 31 Mar 2014 16:44:56 +1100 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 31, 2014 at 4:23 PM, Mark H Harris wrote: > > The main point of the link is the status on English as an official language. > 28 out of 50 states have legislated English as the official language; > meaning, that you either speak and write English, or you're going to have a > really tough time participating in culture, business, government, and > recreation. > > http://en.wikipedia.org/wiki/Languages_of_the_United_States#Official_language_status Considering how much is done to ensure that illiterate people can still comprehend critical information (important signage, warnings, traffic directions, etc, etc, etc), I think we can assume that someone who speaks some language other than English will still manage to do a lot of things. Plus, plenty of official documents are available in many languages; the legislated "official language" just means that the English version is the only one that is guaranteed to be there. Go to any one of the states you've mentioned, where English is the sole official language, and pick up any government form - something fairly important, like applying for a passport or something. How many languages is it available in? They might all be on the same form, or maybe you have to explicitly request it in Spanish, but I expect it'll be translated into several non-official languages for the convenience of those whose English isn't as good as their (switch to GLaDOS voice) Insert Subject Native Language Here (switch voice back). But none of this has anything to do with the original point, namely that there are people who communicate in other languages. Even if you have to learn English for the sake of official documents, you won't necessarily want to chat with your friends in English. If you pick up the phone and talk to someone, you can use whatever language you want; if you switch to email, chances are you still can. And that's something that's been true since the dawn of email, which predates Unicode by a slight margin... of a decade or so. ChrisA From metaliobovinus at gmail.com Mon Mar 31 01:47:32 2014 From: metaliobovinus at gmail.com (Metallicow) Date: Sun, 30 Mar 2014 22:47:32 -0700 (PDT) Subject: Examples of modern GUI python programms In-Reply-To: References: Message-ID: On Sunday, March 30, 2014 9:16:06 PM UTC-5, Michael Torrie wrote: > On 03/30/2014 05:16 PM, D. Xenakis wrote: > > > What i need is to develop an android looking program (entirelly in > > python) for windows, but dunno if this is possible (most propably > > is), and which tool between those would help me most: tkinter - > > > wxpython - pyqt - pygtk . > > > > Any examples and suggestions are most welcome. > > Your best bet is to use PyQt. I bet you can make some android-looking > UIs using QtQuick (Javascript) with a bit of Python glue. Well, I wouldn't exactly say that Qt is the way to go just yet... The author needs to weigh the benefits of each toolkit and make a decision for themselves. As far as Qt is concerned, it is a bit more geared towards mobile apps at this point in its python life. It is a bit nicer with the animated stuff also. wxPython on the other hand has way better community support than QT side and has been around longer, so that may be a consideration. Tk is alright and bundled with python but requires more work than the others and isn't always native looking without a bit of extra work. Overall if you are fine with using a GUI builder for the GUI framework, then QT has a nice put-it-all-together IDE. If you are looking for a really customized(hand-tweakable) GUI with relative hassle, then I would recommend wxPython or if you know Tk this would be ok for the majority of stuff, but requires a bit more work. Another thing to consider is that if you are actually wanting this to work on a android or mobile device QT would be a better choice. Especially if touch support is an option. If you are only wanting it to look like android themed app, the other choices provide better long term benefits. As far as pygtk, that fairs better with linux, and in my opinion could use some updates platform-wise rounding the bugs out overall. My opinion would be wxPython if not actually using for a mobile, or PySide if you are. Both of these have acceptable licenses if you want to go commercial also without having to pay for commercial library usage. From harrismh777 at gmail.com Mon Mar 31 02:08:24 2014 From: harrismh777 at gmail.com (Mark H Harris) Date: Mon, 31 Mar 2014 01:08:24 -0500 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/30/14 10:22 AM, Steven D'Aprano wrote: > In 1991, there was no wireless, no mobile computing, hardly any public > Internet outside of the universities. It was before the Eternal > September, and only a few years after the Great Renaming. I was using arpanet since the late 1970s. > Python had just > been released for the first time, and Windows 3.1 hadn't been (although > 3.0 had). There was no Netscape, no Mosaic graphical web browsers. Steve > Jobs hadn't returned to Apple yet, Apple was still losing money and mind- > share, and Google didn't even exist. It was a different era. Command line all the way babe... uuencode uudecode base64 whoohoo. ftp, and all the rest... > 1991 is 23 years ago. In "computer years", I consider that almost eight > generations, about the same as 160 years in human terms. Bologna, Oscar Meyer Bologna, USDA Prime. That's just plain silly. Yes, a lot of things have happened since 1991, but 1991 was yesterday; and in the big scheme of things, not much really has happened (oh, yeah, smaller and faster; Moores law moves forward, so what?) We're still using von Nuemann processors, we're still using all the same stupid programming tricks; the only thing that has changed is that computers use a fraction of the power they did, they are very tiny, and they are very fast. so what? We have unicode! yeahhhh. ASCII is dead. Microsoft is dying. Gun/Linux rules. I still program in BASIC at least once a week, and we all still have trouble communicating around the globe. >> I didn't really start using unicode >> until about 5 years ago; python has only really used it since python3. >> right? > > No. Python 2.2 introduced Unicode. I didn't ask when it was introduced, I asked when it became useful? Python was experimenting with unicode in version 2. It became more fully useful in version 3. I didn't use it in version 2--- way too frustrating. Unicode in python3.x is (mostly) working correctly. Congratulations to all who worked on it, hat is off. The problem with unicode is that it is just a specification. The consortium cannot force or code anything. They control the scripts and make the specifications. It is left to *everyone* else to implement. And not everyone is taking on that task with the same gusto, if you follow my meaning. marcus From rosuav at gmail.com Mon Mar 31 02:47:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 31 Mar 2014 17:47:20 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 31, 2014 at 5:08 PM, Mark H Harris wrote: > Unicode in python3.x is (mostly) working correctly. Congratulations to all > who worked on it, hat is off. The problem with unicode is that it is just a > specification. The consortium cannot force or code anything. They control > the scripts and make the specifications. It is left to *everyone* else to > implement. And not everyone is taking on that task with the same gusto, if > you follow my meaning. Considering that Pike's native double-quoted string type stored true Unicode (not UTF-16, not eight-bit, the full Unicode range) back in 1998, you're quite correct in saying that some take on that task with more enthusiasm than others. Of course, that exact same fact does tell against your other and more important point, namely that people were unable to speak non-English to each other until very recently. Good luck. ChrisA From ben+python at benfinney.id.au Mon Mar 31 02:53:55 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 31 Mar 2014 17:53:55 +1100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85a9c6n9j0.fsf@benfinney.id.au> Mark, you are demonstrating a habit of making sweeping pronouncements and assertions; and then, when those statements are challenged, you act as though you never said them. Here's a characteristic example: Mark H Harris writes: > On 3/30/14 10:22 AM, Steven D'Aprano wrote: > > Mark H Harris writes: > >> I didn't really start using unicode until about 5 years ago; python > >> has only really used it since python3. right? > > > > No. Python 2.2 introduced Unicode. > > I didn't ask when it was introduced, I asked when it became useful? That's clearly not what you asked, in the material you quoted above; and Steven's answer to your actual false assertion is entirely appropriate. There are many other examples in this thread, but I'm not seeking to catalogue them; merely to show an example of what I'm observing. I hope you can see that this behaviour quickly leads many people to quite reasonably disregard your assertions in general, and even to ignore you altogether. Do you think you can tone down the rhetoric and perhaps stand by the statements you actually make? -- \ ?Injustice is relatively easy to bear; what stings is justice.? | `\ ?Henry L. Mencken | _o__) | Ben Finney From rustompmody at gmail.com Mon Mar 31 03:36:17 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 31 Mar 2014 00:36:17 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, March 31, 2014 12:23:55 PM UTC+5:30, Ben Finney wrote: > Mark, you are demonstrating a habit of making sweeping pronouncements > and assertions; and then, when those statements are challenged, you > act as though you never said them. > Here's a characteristic example: > Mark H Harris writes: > > On 3/30/14 10:22 AM, Steven D'Aprano wrote: > > > Mark H Harris writes: > > >> I didn't really start using unicode until about 5 years ago; python > > >> has only really used it since python3. right? > > > No. Python 2.2 introduced Unicode. > > I didn't ask when it was introduced, I asked when it became useful? > That's clearly not what you asked, in the material you quoted above; and > Steven's answer to your actual false assertion is entirely appropriate. > There are many other examples in this thread, but I'm not seeking to > catalogue them; merely to show an example of what I'm observing. > I hope you can see that this behaviour quickly leads many people to > quite reasonably disregard your assertions in general, and even to > ignore you altogether. Do you think you can tone down the rhetoric and > perhaps stand by the statements you actually make? I wonder... Is there some Unicode-corollary to Godwin's law? Something like: "Whenever people discuss unicode long enough they start talking rubbish." Not very surprising given that unicode is related to human languages and human languages willy-nilly are connected to politics. It would be neat if we could stick to the 'uni(versal)' (aka math, music etc) aspect of unicode more and the 'needs localization' aspect less. From jeremy at jeremysanders.net Mon Mar 31 03:56:59 2014 From: jeremy at jeremysanders.net (Jeremy Sanders) Date: Mon, 31 Mar 2014 09:56:59 +0200 Subject: checking if two things do not equal None References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> Message-ID: contact.trigon at gmail.com wrote: > if (a, b) != (None, None): > or > if a != None != b: > > Preference? Pros? Cons? Alternatives? I couldn't see anyone else give this, but I like if None not in (a, b): pass Jeremy From breamoreboy at yahoo.co.uk Mon Mar 31 04:31:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 31 Mar 2014 09:31:00 +0100 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> <5337f383$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 31/03/2014 05:57, Mark H Harris wrote: > On 3/30/14 5:35 AM, Steven D'Aprano wrote: > >> Approximately 5% of the US population either do not speak English at all, >> or speak it poorly. That includes approximately half a million ASL >> speakers (American Sign Language, which is not a manual representation of >> English but an independent language in it's own right), the majority of >> whom are unable to speak or understand spoken English. > > Steven, you have trolled us over to the left edge of outer left field > all the way back at the fence, dude, seriously--- and then you dropped > the ball. Geeeze... error. > Is it safe to assume that's a reference from a sport that essentially only gets played in the USA so you have a World Series? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com From wxjmfauth at gmail.com Mon Mar 31 04:32:42 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 31 Mar 2014 01:32:42 -0700 (PDT) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1d9cec81-2548-49aa-be4a-4857fdccb9e7@googlegroups.com> Unicode... Interesting reading. jmf From marko at pacujo.net Mon Mar 31 04:39:12 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 31 Mar 2014 11:39:12 +0300 Subject: OFF TOPIC Spanish in the USA References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87a9c6vk27.fsf@elektro.pacujo.net> Mark H Harris : > The main point of the link is the status on English as an official > language. 28 out of 50 states have legislated English as the official > language; meaning, that you either speak and write English, or you're > going to have a really tough time participating in culture, business, > government, and recreation. What does "official language" mean? Finland has two official languages: Finnish and Swedish. It means you are guaranteed to get state services in both languages. At municipal level, you might get guarantees in one or both of the languages depending on census data. In California, OTOH, it's the other way around: English being official means you are guaranteed *not* to get services in languages other than English. If a government social worker speaks Spanish and the customer only knows Spanish, the social worker is not legally allowed to use Spanish to conduct their business. In Finland, no government worker is disallowed from using any language they deem useful in their work. Marko From sturla.molden at gmail.com Mon Mar 31 04:48:33 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Mon, 31 Mar 2014 08:48:33 +0000 (UTC) Subject: Examples of modern GUI python programms References: Message-ID: <1536365056417947084.883654sturla.molden-gmail.com@news.gmane.org> Metallicow wrote: > My opinion would be wxPython if not actually using for a mobile, or > PySide if you are. Both of these have acceptable licenses if you want to > go commercial also without having to pay for commercial library usage. If you are to distribute a program using LGPL software on AppStore or Gopgle Play, then remember that the user must be allowed to relink the program with anpther version of the library. That is an LGPL requirement. I don't see how this requirement can be satisfied in this case. Thus, LGPL on AppStore or Google Play is probably put of the question. At least on iOS, the user cannot change what you put in an App bundle. This excludes wxPython and PySide. Thus, the only viable cross-platform choices are commercial PyQt + commercial Qt or tkinter. In case of iOS, PyObjC is also an option. py2app will also be useful for creating App bundles on iOS. Sturla From metaliobovinus at gmail.com Mon Mar 31 05:33:11 2014 From: metaliobovinus at gmail.com (Metallicow) Date: Mon, 31 Mar 2014 02:33:11 -0700 (PDT) Subject: Examples of modern GUI python programms In-Reply-To: References: Message-ID: On Monday, March 31, 2014 3:48:33 AM UTC-5, Sturla Molden wrote: > If you are to distribute a program using LGPL software on AppStore or > Gopgle Play, then remember that the user must be allowed to relink the > program with anpther version of the library. That is an LGPL requirement. I > don't see how this requirement can be satisfied in this case. Thus, LGPL on > AppStore or Google Play is probably put of the question. At least on iOS, > the user cannot change what you put in an App bundle. This excludes > wxPython and PySide. Thus, the only viable cross-platform choices are > commercial PyQt + commercial Qt or tkinter. In case of iOS, PyObjC is also > an option. py2app will also be useful for creating App bundles on iOS. > > Sturla The OP didn't exactly detail what exactly was being looked for just "python on windows" basically. So that part still hasn't been answered... As far as wxPython, that is not LGPL, it is wxPython/wxWidgets which is fine for licensing your compiled app as however you want. Modifications to the library stuff for example is good in the fact with this that most all improvements(to the library-stuff) eventually work their way back in or have to be released GPL v2. One would have to tool through the PySide agreement for their specifics, but as I recall it is exactly the same as Qt is, which makes sense. Riverbank/PyQt is not Qt, they are a separate entity, just to make that clear. The reason PySide was made was because Riverbank didn't want to license their bindings that same as Qt basically. A lot depends on what you intend to do with "the" app and how many hoops you are willing to jump through license wise. Just because a library is LGPL doesn't mean the authors code has to be depending on the circumstances. That just means usually you have to be able to provide the library code(and your mods to it) used. If the author doesn't care about releasing his/her own source code, then just about any toolkit would be at the same level of "python on windows" for the most part. It all depends on what the target for the app is. "Windows desktop?", "Windows Phone?", "MSW XBox?", etc... From antoon.pardon at rece.vub.ac.be Mon Mar 31 05:55:48 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 31 Mar 2014 11:55:48 +0200 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <53393BA4.2080305@rece.vub.ac.be> On 27-03-14 17:22, Ian Kelly wrote: > On Thu, Mar 27, 2014 at 9:28 AM, Mark H Harris wrote: >>> Do you think that the ability to write this would be an improvement? >>> >>> import ? >>> ? = ?.?? >>> ? = 5*?.?? >>> ? = ? - 1 >>> ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] >>> ?.??????(???) >> >> Steven, you're killing me here; argument by analogy does not work! > [ ------ 8< ---------- ] > One of the things that Python is widely known for is its readability. > Allowing symbols such as ? to denote identifiers may be quite > expressive and appreciable to the person writing the code. However it > damages readability considerably, as seen in Steven's example above. > Personally I'm not interested in having to maintain another > programmer's code that arbitrarily uses ? as a timer function, ? as > intersection or ? as a matrix constructor. I don't find Steven's example convincing. Sure it can be used in a way that damages readability considerably however lots of things in python can be abused in a way that damages readability considerably. That you are not interested in having to maintain someone's code who would use such symbols is irrelevant. IIRC people have used the exact same kind of argument against decorators and the if-else operator. It seems we are all consenting adults until someone doesn't like the idea how it might influence his job. In that case it shouldn't be allowed. -- Antoon Pardon From nispray at gmail.com Mon Mar 31 07:03:55 2014 From: nispray at gmail.com (Wesley) Date: Mon, 31 Mar 2014 04:03:55 -0700 (PDT) Subject: Python IM server Message-ID: Hi all, I want to develop a instant message server, simply has user and group entity. Is there any better existing open-source one? Thus I can download and have a look. Thanks. Wesley From jamiemitchell1604 at gmail.com Mon Mar 31 07:29:15 2014 From: jamiemitchell1604 at gmail.com (Jamie Mitchell) Date: Mon, 31 Mar 2014 04:29:15 -0700 (PDT) Subject: Line of best fit Message-ID: <0fb15100-15e8-46d6-a38f-b187c7012e62@googlegroups.com> I am new to python so apologies for the ignorance with this question. How would I apply a line of best fit to a plot? My data are netCDF4 data files and this is essentially what I have done so far: swh1=netCDF4.Dataset('filename','r') hs1=swh1.variables['hs'] swh2=netCDF4.Dataset('filename'.'r') hs2=swh2.variables['hs'] plt.plot(hs1,hs2,'.') Cheers, Jamie From ned at nedbatchelder.com Mon Mar 31 07:33:11 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 31 Mar 2014 07:33:11 -0400 Subject: OFF TOPIC Spanish in the USA In-Reply-To: <87a9c6vk27.fsf@elektro.pacujo.net> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> <87a9c6vk27.fsf@elektro.pacujo.net> Message-ID: On 3/31/14 4:39 AM, Marko Rauhamaa wrote: > Mark H Harris : > >> The main point of the link is the status on English as an official >> language. 28 out of 50 states have legislated English as the official >> language; meaning, that you either speak and write English, or you're >> going to have a really tough time participating in culture, business, >> government, and recreation. > > What does "official language" mean? > > Finland has two official languages: Finnish and Swedish. It means you > are guaranteed to get state services in both languages. At municipal > level, you might get guarantees in one or both of the languages > depending on census data. > > In California, OTOH, it's the other way around: English being official > means you are guaranteed *not* to get services in languages other than > English. If a government social worker speaks Spanish and the customer > only knows Spanish, the social worker is not legally allowed to use > Spanish to conduct their business. In Finland, no government worker is > disallowed from using any language they deem useful in their work. Can I politely suggest that we just end this discussion? The thread has been properly marked as OFF TOPIC, and it is now squarely in areas that are 1) politically contentious, 2) wildly subjective, 3) none of our areas of expertise. No good can come from continuing. --Ned. > > > Marko > -- Ned Batchelder, http://nedbatchelder.com From roy at panix.com Mon Mar 31 08:16:30 2014 From: roy at panix.com (Roy Smith) Date: Mon, 31 Mar 2014 08:16:30 -0400 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Mark H Harris wrote: > On 3/30/14 10:22 AM, Steven D'Aprano wrote: > > In 1991, there was no wireless, no mobile computing, hardly any public > > Internet outside of the universities. It was before the Eternal > > September, and only a few years after the Great Renaming. > > I was using arpanet since the late 1970s. > > > Python had just > > been released for the first time, and Windows 3.1 hadn't been (although > > 3.0 had). There was no Netscape, no Mosaic graphical web browsers. Steve > > Jobs hadn't returned to Apple yet, Apple was still losing money and mind- > > share, and Google didn't even exist. It was a different era. > > Command line all the way babe... uuencode uudecode base64 whoohoo. Remember when btoa/atob came out? You got 32 bits of data in just 5 characters. Win! Waiting for btou :-) > Unicode in python3.x is (mostly) working correctly. Congratulations to > all who worked on it, hat is off. The problem with unicode is that it > is just a specification. The consortium cannot force or code anything. > They control the scripts and make the specifications. It is left to > *everyone* else to implement. My first introduction to unicode was a monster i18n makeover on a large C++ codebase. For reasons I no longer remember, we ended up settling on utf-8 for "native" strings (with, of course, our own string class), but we were also using some library which was utf-16 internally (ICU4C, I think?). So, we were constantly transcoding all over the place. What a mess. From roy at panix.com Mon Mar 31 08:21:48 2014 From: roy at panix.com (Roy Smith) Date: Mon, 31 Mar 2014 08:21:48 -0400 Subject: Line of best fit References: <0fb15100-15e8-46d6-a38f-b187c7012e62@googlegroups.com> Message-ID: In article <0fb15100-15e8-46d6-a38f-b187c7012e62 at googlegroups.com>, Jamie Mitchell wrote: > I am new to python so apologies for the ignorance with this question. > > How would I apply a line of best fit to a plot? Python has nothing built-in which does that, but there are plenty of add-on modules which do those sorts of things. One popular one is statsmodels (http://statsmodels.sourceforge.net/) > plt.plot(hs1,hs2,'.') Please tell us more about the environment you're working in. I'm guessing from the fact that you're calling plt.plot(), that you've already got some add-on modules loaded. Pandas, maybe? From rosuav at gmail.com Mon Mar 31 09:04:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 00:04:11 +1100 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] In-Reply-To: References: <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 31, 2014 at 11:41 PM, Dennis Lee Bieber wrote: > On Mon, 31 Mar 2014 16:44:56 +1100, Chris Angelico > declaimed the following: > >>official language, and pick up any government form - something fairly >>important, like applying for a passport or something. How many > > Passport is a Federal form, not under State control. Ehh, sorry, bad example then. (I'm not a Merkin, so I don't know what you suffer under.) Pick something that is state-controlled instead. ChrisA From jfharden at gmail.com Mon Mar 31 05:14:09 2014 From: jfharden at gmail.com (Jonathan Harden) Date: Mon, 31 Mar 2014 10:14:09 +0100 Subject: Examples of modern GUI python programms In-Reply-To: References: Message-ID: On 31 Mar 2014 00:21, "D. Xenakis" wrote: > ... Snip ... > What i need is to develop an android looking program (entirelly in python) for windows, but dunno if this is possible (most propably is), and which tool between those would help me most: tkinter - wxpython - pyqt - pygtk . > > Any examples and suggestions are most welcome. While I've not used it much Kivy could be useful if you want it to look Android like, with the added benefit that you can build for android as well. -------------- next part -------------- An HTML attachment was scrubbed... URL: From moritz.beber at gmail.com Mon Mar 31 07:50:53 2014 From: moritz.beber at gmail.com (Moritz Beber) Date: Mon, 31 Mar 2014 13:50:53 +0200 Subject: Line of best fit In-Reply-To: <0fb15100-15e8-46d6-a38f-b187c7012e62@googlegroups.com> References: <0fb15100-15e8-46d6-a38f-b187c7012e62@googlegroups.com> Message-ID: None of these are in the standard library but why re-invent the wheel? Using numpy: http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html scipy: http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.stats.linregress.html statsmodels: http://statsmodels.sourceforge.net/devel/examples/notebooks/generated/ols.html On Mon, Mar 31, 2014 at 1:29 PM, Jamie Mitchell wrote: > I am new to python so apologies for the ignorance with this question. > > How would I apply a line of best fit to a plot? > > My data are netCDF4 data files and this is essentially what I have done so > far: > > swh1=netCDF4.Dataset('filename','r') > hs1=swh1.variables['hs'] > > swh2=netCDF4.Dataset('filename'.'r') > hs2=swh2.variables['hs'] > > plt.plot(hs1,hs2,'.') > > Cheers, > > Jamie > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lutz.horn at posteo.de Mon Mar 31 08:37:32 2014 From: lutz.horn at posteo.de (Lutz Horn) Date: Mon, 31 Mar 2014 14:37:32 +0200 Subject: Python IM server In-Reply-To: References: Message-ID: Hi, > I want to develop a instant message server, simply has user and > group entity. > > Is there any better existing open-source one? Take a look at XMPP[0]. There are some Python libraries[1]. [0] https://en.wikipedia.org/wiki/XMPP [1] http://xmpp.org/xmpp-software/libraries/ -- Opt out of global data surveillance programs like PRISM, XKeyscore and Tempora. https://prism-break.org From invalid at invalid.invalid Mon Mar 31 10:14:39 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 31 Mar 2014 14:14:39 +0000 (UTC) Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337f57d$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-03-30, Rhodri James wrote: > On Sun, 30 Mar 2014 11:44:13 +0100, Steven D'Aprano > >> Among fans of the British writer Terry Pratchett, the usual term is >> Merkins. Including among Merkin fans. > > Many of whom even know what a merkin is, and use the term anyway. As much as I'd rather not be called a Merkin, one can't really get mad at Terry Pratchett fans... -- Grant Edwards grant.b.edwards Yow! I'm also against at BODY-SURFING!! gmail.com From rosuav at gmail.com Mon Mar 31 10:33:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 01:33:09 +1100 Subject: Code style query: multiple assignments in if/elif tree Message-ID: Call this a code review request, if you like. I'm wondering how you'd go about coding something like this. Imagine you're in a train, and the brakes don't apply instantly. The definition, in the interests of passenger comfort, is that the first second of brake application has an acceleration of 0.2 m/s/s, the next second has 0.425 m/s/s, and thereafter full effect of 0.85 m/s/s. You have a state variable that says whether the brakes have just been applied, have already been applied for at least two seconds, or haven't yet been applied at all. Problem: Work out how far you'll go before the brakes reach full power, and how fast you'll be going at that point. Here's how I currently have the code. The variable names are a tad long, as this was also part of me teaching my brother Python. # Already got the brakes fully on if mode=="Brake2": distance_to_full_braking_power, speed_full_brake = 0.0, curspeed # The brakes went on one second ago, they're nearly full elif mode=="Brake1": distance_to_full_braking_power, speed_full_brake = curspeed - 0.2125, curspeed - 0.425 # Brakes aren't on. else: distance_to_full_braking_power, speed_full_brake = (curspeed - 0.1) + (curspeed - 0.4125), curspeed - 0.625 # If we hit the brakes now (or already have hit them), we'll go another d meters and be going at s m/s before reaching full braking power. But I don't like the layout. I could change it to a single assignment with expression-if, but that feels awkward too. How would you lay this out? (Note that the "else" case could have any of several modes in it, so I can't so easily use a dict.) ChrisA From marko at pacujo.net Mon Mar 31 11:40:42 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 31 Mar 2014 18:40:42 +0300 Subject: Code style query: multiple assignments in if/elif tree References: Message-ID: <874n2ecr5x.fsf@elektro.pacujo.net> Chris Angelico : > Call this a code review request, if you like. I'm wondering how you'd > go about coding something like this. As a simple layout question, I'd do it like this: ======================================================================== if mode == "Brake2": # Already got the brakes fully on distance_to_full_braking_power = 0.0 speed_full_brake = curspeed elif mode == "Brake1": # The brakes went on one second ago, they're nearly full distance_to_full_braking_power = curspeed - 0.2125 speed_full_brake = curspeed - 0.425 else: # Brakes aren't on. distance_to_full_braking_power = (curspeed - 0.1) + (curspeed - 0.4125) speed_full_brake = curspeed - 0.625 # If we hit the brakes now (or already have hit them), we'll go another # d meters and be going at s m/s before reaching full braking power. ======================================================================== Marko From rosuav at gmail.com Mon Mar 31 12:03:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 03:03:54 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <874n2ecr5x.fsf@elektro.pacujo.net> References: <874n2ecr5x.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 1, 2014 at 2:40 AM, Marko Rauhamaa wrote: > As a simple layout question, I'd do it like this: > > ======================================================================== > if mode == "Brake2": > # Already got the brakes fully on > distance_to_full_braking_power = 0.0 > speed_full_brake = curspeed > elif mode == "Brake1": > # The brakes went on one second ago, they're nearly full > distance_to_full_braking_power = curspeed - 0.2125 > speed_full_brake = curspeed - 0.425 > else: > # Brakes aren't on. > distance_to_full_braking_power = (curspeed - 0.1) + (curspeed - 0.4125) > speed_full_brake = curspeed - 0.625 > > # If we hit the brakes now (or already have hit them), we'll go another > # d meters and be going at s m/s before reaching full braking power. > ======================================================================== No particular advantage over the current version - it doesn't simplify it any, all you've done is break it across more lines. (The unpacking may not be ideal; as I said, this was a vehicle for teaching oddments of Python, so I used multiple assignment partly for the sake of using it.) Incidentally, if you want to see the code in context, it's here: https://github.com/Rosuav/runningtime/blob/master/runningtime.py ChrisA From rustompmody at gmail.com Mon Mar 31 12:20:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 31 Mar 2014 09:20:27 -0700 (PDT) Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <874n2ecr5x.fsf@elektro.pacujo.net> Message-ID: <6775d115-a592-4082-a427-5789e1dd2875@googlegroups.com> On Monday, March 31, 2014 9:33:54 PM UTC+5:30, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 2:40 AM, Marko Rauhamaa wrote: > > As a simple layout question, I'd do it like this: > > ======================================================================== > > if mode == "Brake2": > > # Already got the brakes fully on > > distance_to_full_braking_power = 0.0 > > speed_full_brake = curspeed > > elif mode == "Brake1": > > # The brakes went on one second ago, they're nearly full > > distance_to_full_braking_power = curspeed - 0.2125 > > speed_full_brake = curspeed - 0.425 > > else: > > # Brakes aren't on. > > distance_to_full_braking_power = (curspeed - 0.1) + (curspeed - 0.4125) > > speed_full_brake = curspeed - 0.625 > > # If we hit the brakes now (or already have hit them), we'll go another > > # d meters and be going at s m/s before reaching full braking power. > > ======================================================================== > No particular advantage over the current version - it doesn't simplify > it any, all you've done is break it across more lines. Not answering your original question but the above comment Your version was sufficiently garbled indentation-wise (it may give you sweet pleasure to know my 'client' is GG) that I gave up on reading it. Marko's version was clear enough that it seems to match your spec [Ive not really verified it word for word... Just sayin'] On the whole I prefer multiple assignments. Maybe in this case use small variable names with separate(d) explanatory comments?? From rosuav at gmail.com Mon Mar 31 12:29:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 03:29:54 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <6775d115-a592-4082-a427-5789e1dd2875@googlegroups.com> References: <874n2ecr5x.fsf@elektro.pacujo.net> <6775d115-a592-4082-a427-5789e1dd2875@googlegroups.com> Message-ID: On Tue, Apr 1, 2014 at 3:20 AM, Rustom Mody wrote: > On the whole I prefer multiple assignments. > Maybe in this case use small variable names with > separate(d) explanatory comments?? Shorter variable names would certainly be the more normal, heh. I let my brother do that part of the typing, picking names and so on. Better for teaching to let the victi-- err, the student have the power to choose. :) ChrisA From contact.trigon at gmail.com Mon Mar 31 13:28:00 2014 From: contact.trigon at gmail.com (Abe) Date: Mon, 31 Mar 2014 10:28:00 -0700 (PDT) Subject: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> Message-ID: <4e22f311-cd65-4d1a-9696-6c00127d67ec@googlegroups.com> > I couldn't see anyone else give this, but I like > if None not in (a, b): I did. > I am now considering: > if None not in (a,b): > or > if (a is not None) and (b is not None): However, I decided to just turn the two parameters into one (sequence), since they were logically grouped anyhow. From ian.g.kelly at gmail.com Mon Mar 31 13:40:54 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 31 Mar 2014 11:40:54 -0600 Subject: unicode as valid naming symbols In-Reply-To: <53393BA4.2080305@rece.vub.ac.be> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> Message-ID: On Mon, Mar 31, 2014 at 3:55 AM, Antoon Pardon wrote: > On 27-03-14 17:22, Ian Kelly wrote: >> On Thu, Mar 27, 2014 at 9:28 AM, Mark H Harris wrote: >>>> Do you think that the ability to write this would be an improvement? >>>> >>>> import ? >>>> ? = ?.?? >>>> ? = 5*?.?? >>>> ? = ? - 1 >>>> ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] >>>> ?.??????(???) >>> >>> Steven, you're killing me here; argument by analogy does not work! >> [ ------ 8< ---------- ] >> One of the things that Python is widely known for is its readability. >> Allowing symbols such as ? to denote identifiers may be quite >> expressive and appreciable to the person writing the code. However it >> damages readability considerably, as seen in Steven's example above. >> Personally I'm not interested in having to maintain another >> programmer's code that arbitrarily uses ? as a timer function, ? as >> intersection or ? as a matrix constructor. > > I don't find Steven's example convincing. Sure it can be used in a way > that damages readability considerably however lots of things in python > can be abused in a way that damages readability considerably. > > That you are not interested in having to maintain someone's code who > would use such symbols is irrelevant. IIRC people have used the exact > same kind of argument against decorators and the if-else operator. > > It seems we are all consenting adults until someone doesn't like the > idea how it might influence his job. In that case it shouldn't be > allowed. That was an exaggeration on my part. It wouldn't affect my job, as I wouldn't expect to ever actually have to maintain anything like the above. My greater point though is that it damages Python's readability for no actual gain in my view. There is nothing useful you can do with a name that is the U+1F4A9 character that you can't do just as easily with alphanumeric identifiers like pile_of_poo (or ????_??????? if one prefers; that's auto-translated, so don't blame me if it's a poor translation). The kinds of symbols that we're talking about here aren't part of any writing systems, and so to incorporate them in *names* as if they were is an abuse of Unicode. I don't think the comparisons to decorators and the if-else operator are apt. First, because while those may degrade readability, they do so in a constrained way. A decorator application is just the @ symbol and an identifier. The if-else is just three expressions separated by keywords. In the case of arbitrary Unicode identifiers, we're talking about approximately doubling the number of different characters (out of a continuously growing set) that could be used, many of which are easily confused with other characters. Of course the potential for confusion already exists, but that's no justification for aggravating it. Second, at least in the case of decorators, while I don't dispute that they can harm readability, I think that in the majority of cases they actually help it. That's because the @ syntax placed before a function or class clearly denotes that the construct is being decorated by something. The alternative to the syntax is to place an assignment like "f = decorate(f)" *after* the definition, where it is much less prominent. That the reader then potentially has to go figure out what the decorator does is true regardless of whether the @ syntax is used or not. I'm unable to imagine any case where an arbitrary Unicode identifier would actually improve readability. Finally, in my experience the "consenting adults" line is usually used in the context of program or library design. I don't believe it's appropriate when discussing the design of the language itself, which should be kept as clean as possible. The logical conclusion of that would be Lisp-like macros where every user ends up with their own unique and incompatible version of the language, because we're all consenting adults here, right? From python.list at tim.thechases.com Mon Mar 31 14:02:57 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 31 Mar 2014 13:02:57 -0500 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> Message-ID: <20140331130257.2c90f07e@bigbox.christie.dr> On 2014-03-31 11:40, Ian Kelly wrote: > There is nothing useful > you can do with a name that is the U+1F4A9 character that you can't > do just as easily with alphanumeric identifiers like pile_of_poo (or > ????_??????? if one prefers; that's auto-translated, so don't blame > me if it's a poor translation). The kinds of symbols that we're > talking about here aren't part of any writing systems, and so to > incorporate them in *names* as if they were is an abuse of Unicode. It does get more complex though, when you could have things like ??? = "\U0001f4a9" Like you, I don't expect to ever encounter something like this in the wild, but they are indeed symbols used in a writing system. :-) -tkc From ian.g.kelly at gmail.com Mon Mar 31 14:10:44 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 31 Mar 2014 12:10:44 -0600 Subject: unicode as valid naming symbols In-Reply-To: <20140331130257.2c90f07e@bigbox.christie.dr> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <20140331130257.2c90f07e@bigbox.christie.dr> Message-ID: On Mon, Mar 31, 2014 at 12:02 PM, Tim Chase wrote: > On 2014-03-31 11:40, Ian Kelly wrote: >> There is nothing useful >> you can do with a name that is the U+1F4A9 character that you can't >> do just as easily with alphanumeric identifiers like pile_of_poo (or >> ????_??????? if one prefers; that's auto-translated, so don't blame >> me if it's a poor translation). The kinds of symbols that we're >> talking about here aren't part of any writing systems, and so to >> incorporate them in *names* as if they were is an abuse of Unicode. > > It does get more complex though, when you could have things like > > ??? = "\U0001f4a9" > > Like you, I don't expect to ever encounter something like this in the > wild, but they are indeed symbols used in a writing system. :-) That's already a legal identifier, though. The constituent ideographs are categorized as "Letter, Other", not symbols. From moritz.beber at gmail.com Mon Mar 31 15:22:24 2014 From: moritz.beber at gmail.com (Moritz Emanuel Beber) Date: Mon, 31 Mar 2014 21:22:24 +0200 Subject: checking if two things do not equal None In-Reply-To: <4e22f311-cd65-4d1a-9696-6c00127d67ec@googlegroups.com> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <4e22f311-cd65-4d1a-9696-6c00127d67ec@googlegroups.com> Message-ID: <5339C070.3030707@gmail.com> On 31/03/14 19:28, Abe wrote: >> I couldn't see anyone else give this, but I like >> if None not in (a, b): > I did. > >> I am now considering: >> if None not in (a,b): >> or >> if (a is not None) and (b is not None): That's just if not (a is None or b is None): but you seem to have found your way. > However, I decided to just turn the two parameters into one (sequence), since they were logically grouped anyhow. > > From antoon.pardon at rece.vub.ac.be Mon Mar 31 15:31:13 2014 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 31 Mar 2014 21:31:13 +0200 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> Message-ID: <5339C281.7080300@rece.vub.ac.be> Op 31-03-14 19:40, Ian Kelly schreef: > On Mon, Mar 31, 2014 at 3:55 AM, Antoon Pardon > wrote: >> On 27-03-14 17:22, Ian Kelly wrote: >>> On Thu, Mar 27, 2014 at 9:28 AM, Mark H Harris wrote: >>>>> Do you think that the ability to write this would be an improvement? >>>>> >>>>> import ? >>>>> ? = ?.?? >>>>> ? = 5*?.?? >>>>> ? = ? - 1 >>>>> ??? = [?.??**?.?*?{?|?.?} for ? in ?.?] >>>>> ?.??????(???) >>>> >>>> Steven, you're killing me here; argument by analogy does not work! >>> [ ------ 8< ---------- ] >>> One of the things that Python is widely known for is its readability. >>> Allowing symbols such as ? to denote identifiers may be quite >>> expressive and appreciable to the person writing the code. However it >>> damages readability considerably, as seen in Steven's example above. >>> Personally I'm not interested in having to maintain another >>> programmer's code that arbitrarily uses ? as a timer function, ? as >>> intersection or ? as a matrix constructor. >> >> I don't find Steven's example convincing. Sure it can be used in a way >> that damages readability considerably however lots of things in python >> can be abused in a way that damages readability considerably. >> >> That you are not interested in having to maintain someone's code who >> would use such symbols is irrelevant. IIRC people have used the exact >> same kind of argument against decorators and the if-else operator. >> >> It seems we are all consenting adults until someone doesn't like the >> idea how it might influence his job. In that case it shouldn't be >> allowed. > > That was an exaggeration on my part. It wouldn't affect my job, as I > wouldn't expect to ever actually have to maintain anything like the > above. My greater point though is that it damages Python's > readability for no actual gain in my view. There is nothing useful > you can do with a name that is the U+1F4A9 character that you can't do > just as easily with alphanumeric identifiers like pile_of_poo (or > ????_??????? if one prefers; that's auto-translated, so don't blame me > if it's a poor translation). The kinds of symbols that we're talking > about here aren't part of any writing systems, and so to incorporate > them in *names* as if they were is an abuse of Unicode. Your argument doesn't has much weight. First of all it can be used for just restricting names to the ascii range. Second of all I think a good chosen symbolic name can be more readable than a name in a character set you are not familiar with. A good chosen symbol will evoke a meaning with a lot of people. A name in a character set you are not familiar with is just gibberish to you. > I don't think the comparisons to decorators and the if-else operator > are apt. I didn't make such a comparison. I just noted the arguments against were similar. > First, because while those may degrade readability, they do > so in a constrained way. A decorator application is just the @ symbol > and an identifier. And if abused, can totally change the working of your function. There is no guarantee that the function returned, has any relation with the original function. If that can't be a night mare for readability, I don't know what is. > The if-else is just three expressions separated by > keywords. Yes but if used unrestrained in arbitrary expressions will make those expressions hard to understand. > In the case of arbitrary Unicode identifiers, we're talking > about approximately doubling the number of different characters (out > of a continuously growing set) that could be used, many of which are > easily confused with other characters. Of course the potential for > confusion already exists, but that's no justification for aggravating > it. So what if we double the number of different characters? I don't care about the number of them, I care about how meaningful they are. And as you say confusion is already possible. A good programmer knows how to deal with such a possible confusion, that the number of cases increases, doesn't need to be a problem for those that care about this. > Second, at least in the case of decorators, while I don't dispute that > they can harm readability, I think that in the majority of cases they > actually help it. But that is not a fair comparison now, is it. What you are doing here is comparing actual use, to a worst case doom scenario. -- Antoon Pardon From tjreedy at udel.edu Mon Mar 31 16:12:08 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 31 Mar 2014 16:12:08 -0400 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> Message-ID: On 3/31/2014 1:40 PM, Ian Kelly wrote: > Second, at least in the case of decorators, while I don't dispute that > they can harm readability, I think that in the majority of cases they > actually help it. That's because the @ syntax placed before a > function or class clearly denotes that the construct is being > decorated by something. The alternative to the syntax is to place an > assignment like "f = decorate(f)" *after* the definition, where it is > much less prominent. Plus, it means writing and reading the name 3 times instead of 1. This is not much of an issue for 'f', but it is for names like 'modify_x07_with_qz46pt'. Names like this occur when interfacing to external systems that dictate the names needed (as when interfacing Python to Objective-C on Macs). -- Terry Jan Reedy From sturla.molden at gmail.com Mon Mar 31 16:16:16 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Mon, 31 Mar 2014 20:16:16 +0000 (UTC) Subject: Examples of modern GUI python programms References: Message-ID: <140398123417988155.262097sturla.molden-gmail.com@news.gmane.org> Metallicow wrote: > One would have to tool through the PySide agreement for their specifics, > but as I recall it is exactly the same as Qt is, which makes sense. According to their web page, PySide is only LGPL. Qt is LGPL or commercial. > Just because a library is LGPL doesn't mean the authors code has to be > depending on the circumstances. That just means usually you have to be > able to provide the library code(and your mods to it) used. No, that would be MPL (Mozilla Public License). Many believe LGPL implies the same freedom as MPL. It does not. LGPL also means you also have to give the user a means to "relink the program with a different version of the library". That is a less known restriction of LGPL. Usually this is done by providing the LGPL library as a DLL. But a DLL is actually not sufficient, in case a different version of the library breaks the application binary interface (ABI). In case of ABI breakage, LGPL means the user be given access to the program source code to recompile and relink the program. Because of the closed nature of app bundles on iOS, the user cannot do anything with an .so or .dylib file. Thus, the DLL solution to LGPL infestation is not possible on iOS, even if it were sufficient. MPL is basically a version og LGPL that has removed the requirement to make relinkage possible. That is e.g. why a library like Eigen is released as MPL instead of LGPL. Sturla From tjreedy at udel.edu Mon Mar 31 16:15:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 31 Mar 2014 16:15:16 -0400 Subject: unicode as valid naming symbols In-Reply-To: <5339C281.7080300@rece.vub.ac.be> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> Message-ID: On 3/31/2014 3:31 PM, Antoon Pardon wrote: > Op 31-03-14 19:40, Ian Kelly schreef: >> First, because while those may degrade readability, they do >> so in a constrained way. A decorator application is just the @ symbol >> and an identifier. > > And if abused, can totally change the working of your function. There > is no guarantee that the function returned, has any relation with the > original function. If that can't be a night mare for readability, > I don't know what is. This is a matter of the wrapping function, not the decorator syntax abbreviation. @twist_the_function_meaning def f: return clear_expression is no worse in this regard than the written out form def f: return clear_expression f = twist_the_function_meaning(f) -- Terry Jan Reedy From rhodri at wildebst.org.uk Mon Mar 31 16:31:59 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Mon, 31 Mar 2014 21:31:59 +0100 Subject: Code style query: multiple assignments in if/elif tree References: <874n2ecr5x.fsf@elektro.pacujo.net> <6775d115-a592-4082-a427-5789e1dd2875@googlegroups.com> Message-ID: On Mon, 31 Mar 2014 17:29:54 +0100, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 3:20 AM, Rustom Mody > wrote: >> On the whole I prefer multiple assignments. >> Maybe in this case use small variable names with >> separate(d) explanatory comments?? > > Shorter variable names would certainly be the more normal, heh. I let > my brother do that part of the typing, picking names and so on. Better > for teaching to let the victi-- err, the student have the power to > choose. :) Not just more normal, but more readable too. The trouble with your original example was that the lines were too long (even ignoring the trouble line-wrapping caused in your post) to take in with only a couple of eye movements along the line. That makes a really quite surprising difference to the comprehensibility of the whole thing. -- Rhodri James *-* Wildebeest Herder to the Masses From marko at pacujo.net Mon Mar 31 16:34:41 2014 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 31 Mar 2014 23:34:41 +0300 Subject: unicode as valid naming symbols References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> Message-ID: <871txiayzi.fsf@elektro.pacujo.net> Terry Reedy : > @twist_the_function_meaning > def f: return clear_expression > > is no worse in this regard than the written out form > > def f: return clear_expression > f = twist_the_function_meaning(f) I don't remember feeling the need for either. I have written wrappers of all sorts, but somehow that pattern just feels alien to me so far. Marko From rhodri at wildebst.org.uk Mon Mar 31 16:46:21 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Mon, 31 Mar 2014 21:46:21 +0100 Subject: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 31 Mar 2014 07:08:24 +0100, Mark H Harris wrote: > On 3/30/14 10:22 AM, Steven D'Aprano wrote: >> In 1991, there was no wireless, no mobile computing, hardly any public >> Internet outside of the universities. It was before the Eternal >> September, and only a few years after the Great Renaming. > > I was using arpanet since the late 1970s. I was using JANet since the early 80s, and I'm by no means the oldest person here. I should stop playing that card if I were you. >>> I didn't really start using unicode >>> until about 5 years ago; python has only really used it since python3. >>> right? >> No. Python 2.2 introduced Unicode. > I didn't ask when it was introduced, I asked when it became useful? No you didn't. You even quoted yourself as not saying it, just in case you weren't clear about that. And since you're so experienced, you should recognise this sound: *plonk* -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.org.uk Mon Mar 31 16:47:15 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Mon, 31 Mar 2014 21:47:15 +0100 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 31 Mar 2014 06:23:46 +0100, Mark H Harris wrote: > The main point of the link is the status on English as an official > language. 28 out of 50 states have legislated English as the official > language; meaning, that you either speak and write English, or you're > going to have a really tough time participating in culture, business, > government, and recreation. That few? I'm surprised. Presumably the other states don't have any contention for the status of "official language"? I'm also surprised that you aren't surprised that over half the states feel the need to specify an official language. One might wonder why... -- Rhodri James *-* Wildebeest Herder to the Masses From ned at nedbatchelder.com Mon Mar 31 17:42:33 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 31 Mar 2014 17:42:33 -0400 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <874n2ecr5x.fsf@elektro.pacujo.net> Message-ID: On 3/31/14 12:03 PM, Chris Angelico wrote: > Incidentally, if you want to see the code in context, it's here: > > https://github.com/Rosuav/runningtime/blob/master/runningtime.py > > ChrisA I know you didn't ask about these aspects, but they jumped out at me: tabs for indentation instead of spaces, and docstring-style comments in places that aren't docstrings. These seem like unusual choices. -- Ned Batchelder, http://nedbatchelder.com From tjreedy at udel.edu Mon Mar 31 18:06:37 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 31 Mar 2014 18:06:37 -0400 Subject: OFF TOPIC Spanish in the USA [was Re: Explanation of this Python language feature?] In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <5337ba48$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/31/2014 4:47 PM, Rhodri James wrote: > On Mon, 31 Mar 2014 06:23:46 +0100, Mark H Harris > wrote: > >> The main point of the link is the status on English as an official >> language. 28 out of 50 states have legislated English as the official >> language; meaning, that you either speak and write English, or you're >> going to have a really tough time participating in culture, business, >> government, and recreation. Perhaps the link was https://en.wikipedia.org/wiki/Languages_of_the_United_States#Official_language_status > That few? I'm surprised. Presumably the other states don't have any > contention for the status of "official language"? The modern 'English primary' movement, with its first state success in 1981, was a reaction to the 'Spanish co-equal' movement of the 1970s. Without state-by-state data on the push for legislation, I see no clear pattern in the list of which states have such a law. -- Terry Jan Reedy From rosuav at gmail.com Mon Mar 31 18:50:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 09:50:36 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <874n2ecr5x.fsf@elektro.pacujo.net> Message-ID: On Tue, Apr 1, 2014 at 8:42 AM, Ned Batchelder wrote: > On 3/31/14 12:03 PM, Chris Angelico wrote: >> >> Incidentally, if you want to see the code in context, it's here: >> >> https://github.com/Rosuav/runningtime/blob/master/runningtime.py >> >> ChrisA > > > I know you didn't ask about these aspects, but they jumped out at me: tabs > for indentation instead of spaces, and docstring-style comments in places > that aren't docstrings. These seem like unusual choices. Tabs instead of spaces? They're plenty common enough, but I am *not* getting into that debate now. The file's perfectly consistent - aside from inside strings, all indentation is done with tabs, one per level. How do you go about doing multi-line comments? I know I've seen other code using triple-quoted strings for long comments before. ChrisA From ben+python at benfinney.id.au Mon Mar 31 18:57:31 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Apr 2014 09:57:31 +1100 Subject: Code style query: multiple assignments in if/elif tree References: <874n2ecr5x.fsf@elektro.pacujo.net> Message-ID: <85y4zqkmck.fsf@benfinney.id.au> Chris Angelico writes: > How do you go about doing multi-line comments? I know I've seen other > code using triple-quoted strings for long comments before. Just use a sequence of one-line comments:: # Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a # sapien tempor, suscipit orci sed, elementum nisl. Suspendisse at # lacus ut diam dignissim lobortis ac vitae augue. # # Phasellus bibendum neque a justo vulputate, quis accumsan quam # egestas. Etiam aliquet blandit ante sit amet cursus. A decent code editor (e.g. Emacs, Vim) will allow manipulation of a sequence of one-line comments in Python's comment style, and allow treating it as a paragraphs for purposes such as re-wrapping the lines. I agree with others that triple-quoted strings are best reserved for string literals (including docstrings), not comments. -- \ ?Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.? ?Victor J. Stenger, 2001-11-05 | Ben Finney From rosuav at gmail.com Mon Mar 31 19:12:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Apr 2014 10:12:38 +1100 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: <85y4zqkmck.fsf@benfinney.id.au> References: <874n2ecr5x.fsf@elektro.pacujo.net> <85y4zqkmck.fsf@benfinney.id.au> Message-ID: On Tue, Apr 1, 2014 at 9:57 AM, Ben Finney wrote: > Chris Angelico writes: > >> How do you go about doing multi-line comments? I know I've seen other >> code using triple-quoted strings for long comments before. > > Just use a sequence of one-line comments:: > > # Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a > # sapien tempor, suscipit orci sed, elementum nisl. Suspendisse at > # lacus ut diam dignissim lobortis ac vitae augue. > # > # Phasellus bibendum neque a justo vulputate, quis accumsan quam > # egestas. Etiam aliquet blandit ante sit amet cursus. > > A decent code editor (e.g. Emacs, Vim) will allow manipulation of > a sequence of one-line comments in Python's comment style, and allow > treating it as a paragraphs for purposes such as re-wrapping the lines. > > I agree with others that triple-quoted strings are best reserved for > string literals (including docstrings), not comments. Fair enough. I can't remember where (or when!) it was that I learned triple-quoted strings were appropriately abused as comments, so I've just done a quick re-layout into hash comments. ChrisA From sturla.molden at gmail.com Mon Mar 31 20:44:33 2014 From: sturla.molden at gmail.com (Sturla Molden) Date: Tue, 1 Apr 2014 00:44:33 +0000 (UTC) Subject: Line of best fit References: <0fb15100-15e8-46d6-a38f-b187c7012e62@googlegroups.com> Message-ID: <1359723961418005824.044550sturla.molden-gmail.com@news.gmane.org> Roy Smith wrote: > Please tell us more about the environment you're working in. I'm > guessing from the fact that you're calling plt.plot(), that you've > already got some add-on modules loaded. Pandas, maybe? Probably matplotlib.pyplot From ian.g.kelly at gmail.com Mon Mar 31 20:47:48 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 31 Mar 2014 18:47:48 -0600 Subject: unicode as valid naming symbols In-Reply-To: <5339C281.7080300@rece.vub.ac.be> References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> Message-ID: On Mon, Mar 31, 2014 at 1:31 PM, Antoon Pardon wrote: > Op 31-03-14 19:40, Ian Kelly schreef: >> That was an exaggeration on my part. It wouldn't affect my job, as I >> wouldn't expect to ever actually have to maintain anything like the >> above. My greater point though is that it damages Python's >> readability for no actual gain in my view. There is nothing useful >> you can do with a name that is the U+1F4A9 character that you can't do >> just as easily with alphanumeric identifiers like pile_of_poo (or >> ????_??????? if one prefers; that's auto-translated, so don't blame me >> if it's a poor translation). The kinds of symbols that we're talking >> about here aren't part of any writing systems, and so to incorporate >> them in *names* as if they were is an abuse of Unicode. > > Your argument doesn't has much weight. First of all it can be used > for just restricting names to the ascii range. I disagree. Non-ASCII written names are useful to anybody who prefers not to do all their programming in English. > Second of all I > think a good chosen symbolic name can be more readable than a > name in a character set you are not familiar with. A good chosen > symbol will evoke a meaning with a lot of people. A name in a > character set you are not familiar with is just gibberish to > you. Well, this is the path taken by APL. It has its supporters. It's not known for being readable. >> I don't think the comparisons to decorators and the if-else operator >> are apt. > > I didn't make such a comparison. I just noted the arguments against > were similar. That's the comparison to which I was referring. >> First, because while those may degrade readability, they do >> so in a constrained way. A decorator application is just the @ symbol >> and an identifier. > > And if abused, can totally change the working of your function. There > is no guarantee that the function returned, has any relation with the > original function. If that can't be a night mare for readability, > I don't know what is. As Terry Reedy noted, this has nothing to do with the decorator syntax, so it isn't much of an argument against having such syntax. >> The if-else is just three expressions separated by >> keywords. > > Yes but if used unrestrained in arbitrary expressions will make those > expressions hard to understand. I don't disagree. I hardly ever use it myself, certainly only if it can fit comfortably into one line, which is rare. But it's still quite limited in syntactic scope. >> In the case of arbitrary Unicode identifiers, we're talking >> about approximately doubling the number of different characters (out >> of a continuously growing set) that could be used, many of which are >> easily confused with other characters. Of course the potential for >> confusion already exists, but that's no justification for aggravating >> it. > > So what if we double the number of different characters? I don't care > about the number of them, I care about how meaningful they are. And > as you say confusion is already possible. A good programmer knows > how to deal with such a possible confusion, that the number of > cases increases, doesn't need to be a problem for those that care > about this. So tell me then, how would you deal with it? In the case of script identifiers, it's often not hard to discern from context whether a particular character is e.g. a Latin h or a Cyrillic ?. Assuming the original author wasn't being intentionally obfuscatory, if the rest of the identifier is Cyrillic then the character is probably also Cyrillic. If it's a one-character identifier, then hopefully the rest of the module is consistent and you can guess from that. If the identifier in question is just one symbol though, then you have a lot less context. > >> Second, at least in the case of decorators, while I don't dispute that >> they can harm readability, I think that in the majority of cases they >> actually help it. > > But that is not a fair comparison now, is it. What you are doing here > is comparing actual use, to a worst case doom scenario. I contend that there is no scenario with arbitrary Unicode identifiers where readability is improved. From ethan at stoneleaf.us Mon Mar 31 20:30:35 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 31 Mar 2014 17:30:35 -0700 Subject: Code style query: multiple assignments in if/elif tree In-Reply-To: References: <874n2ecr5x.fsf@elektro.pacujo.net> <85y4zqkmck.fsf@benfinney.id.au> Message-ID: <533A08AB.8060208@stoneleaf.us> On 03/31/2014 04:12 PM, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 9:57 AM, Ben Finney wrote: >> Chris Angelico writes: >> >>> How do you go about doing multi-line comments? I know I've seen other >>> code using triple-quoted strings for long comments before. >> >> Just use a sequence of one-line comments:: >> >> # Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a >> # sapien tempor, suscipit orci sed, elementum nisl. Suspendisse at >> # lacus ut diam dignissim lobortis ac vitae augue. >> # >> # Phasellus bibendum neque a justo vulputate, quis accumsan quam >> # egestas. Etiam aliquet blandit ante sit amet cursus. >> >> A decent code editor (e.g. Emacs, Vim) will allow manipulation of >> a sequence of one-line comments in Python's comment style, and allow >> treating it as a paragraphs for purposes such as re-wrapping the lines. >> >> I agree with others that triple-quoted strings are best reserved for >> string literals (including docstrings), not comments. > > Fair enough. I can't remember where (or when!) it was that I learned > triple-quoted strings were appropriately abused as comments, so I've > just done a quick re-layout into hash comments. Personally, I use the sequence of one-line comments. But, hey, Guido [1] himself likes the triple-quoted string as comment feature [2], so feel free to use it yourself if you like. -- ~Ethan~ [1] https://mail.python.org/pipermail/python-dev/2013-March/124947.html [2] https://mail.python.org/pipermail/python-ideas/2009-October/006204.html From steve+comp.lang.python at pearwood.info Mon Mar 31 20:57:01 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2014 00:57:01 GMT Subject: Code style query: multiple assignments in if/elif tree References: <874n2ecr5x.fsf@elektro.pacujo.net> <85y4zqkmck.fsf@benfinney.id.au> Message-ID: <533a0edd$0$29994$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Apr 2014 10:12:38 +1100, Chris Angelico wrote: [...] >> I agree with others that triple-quoted strings are best reserved for >> string literals (including docstrings), not comments. > > Fair enough. I can't remember where (or when!) it was that I learned > triple-quoted strings were appropriately abused as comments, so I've > just done a quick re-layout into hash comments. Probably here :-) But note the emphasis on "abused". The only time I would use triple- quoted strings as comments is if I wanted to quickly comment out a section of code: do_this() do_that() ''' def do_something_else(): """Docstring""" pass do_something_else() ''' do_more() do_less() sort of thing. (Note the cunning use of ''' instead of """.) But I wouldn't leave it like that in production code. It's *tempting* to use """ to mark out a large block of text, and I wouldn't say that doing so was wrong, but it's a bit different, and programmers are very like cats: they don't like different. -- Steven D'Aprano http://import-that.dreamwidth.org/ From steve+comp.lang.python at pearwood.info Mon Mar 31 21:00:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2014 01:00:52 GMT Subject: Line of best fit References: <0fb15100-15e8-46d6-a38f-b187c7012e62@googlegroups.com> Message-ID: <533a0fc3$0$29994$c3e8da3$5496439d@news.astraweb.com> On Mon, 31 Mar 2014 04:29:15 -0700, Jamie Mitchell wrote: > I am new to python so apologies for the ignorance with this question. > > How would I apply a line of best fit to a plot? That depends on what software you are using to generate the plot. I see you have this line of code: > plt.plot(hs1,hs2,'.') but you haven't told us what plt is, where it comes from, or anything needed for us to answer your question. So, start by telling us what plt is, and we may be able to tell you whether or not it supports lines of best fit. -- Steven D'Aprano http://import-that.dreamwidth.org/ From nispray at gmail.com Mon Mar 31 22:38:12 2014 From: nispray at gmail.com (Wesley) Date: Mon, 31 Mar 2014 19:38:12 -0700 (PDT) Subject: Python IM server In-Reply-To: References: Message-ID: <5956f54e-4db3-4fcb-b0b1-c81651392fc2@googlegroups.com> ? 2014?3?31????UTC+8??8?37?32??Lutz Horn??? > Hi, > > > > > I want to develop a instant message server, simply has user and > > > group entity. > > > > > > Is there any better existing open-source one? > > > > Take a look at XMPP[0]. There are some Python libraries[1]. > > > > [0] https://en.wikipedia.org/wiki/XMPP > > [1] http://xmpp.org/xmpp-software/libraries/ > > > > -- > > Opt out of global data surveillance programs like PRISM, XKeyscore and > > Tempora. > > https://prism-break.org I am looking at telepathy, empathy. Currently instant message is urgent, but needs voice/video call in the future. For instant message, I have user-to-user and user-to-group cases. Don't know if it suits well. From metaliobovinus at gmail.com Mon Mar 31 23:47:46 2014 From: metaliobovinus at gmail.com (Metallicow) Date: Mon, 31 Mar 2014 20:47:46 -0700 (PDT) Subject: Examples of modern GUI python programms In-Reply-To: References: Message-ID: <7731beae-7309-4fbc-b706-d4dd4983f535@googlegroups.com> On Monday, March 31, 2014 3:16:16 PM UTC-5, Sturla Molden wrote: > > According to their web page, PySide is only LGPL. Qt is LGPL or commercial. """ Licensing PySide has been published as a response to the lack of suitably licensed Qt bindings for Python. PySide is licensed under the LGPL version 2.1 license, allowing both Free/Open source software and proprietary software development. """ Read the legal definition of/and proprietary, then go consult a lawyer. That is caught as an exception/addition to the LGPL in the wording. I don't think anyone pressing the issue would get very far at all, unless there is a real good reason your own non-library source should be disclosed. Are there any legal precedents yet?.... If you didn't pay for it, or don't have a class action suit, or is of national security, then good luck. So, yes, PySide is acceptable also in certain situations you don't have to disclose own source. May need to consult with Qt personally on the matter if a Qt license is actually needed for your particular project, but in plain legal wording of the LGPL/Qts/PySides agreements, no, it is not but there are a few rules that have been layed out you will need to follow if you don't have a Qt license. Anywho, here is some infos detailing a bit more commonly asked situations on their forums regarding PySide. http://qt-project.org/wiki/About-PySide http://qt-project.org/forums/viewthread/34770 If you do have a Qt license, then the rules change a bit more in your favor at levels of what you can ignore, that others can't legally. A couple of our team members has a license to cover the stuff we do, so I don't worry about it much. The majority of it is open anyway, but pity those who expect everything for free. *I can hear it now* boo hoo pdf format is finally "free and open" after all these years of adobe's money*grubbin*making. geez... Lesson is: Any software/hardware dev should be familiar with the licensing terms of the toolkits they intend to use. There are always hoops to jump through for "Free-Types". Everyone needs to eat also, because as of this writing "Money" has yet to be abolished in this needy world of ours. And also it seems to fuel development in certain cases also. I often find the writings on the GPL pages about stuff related similarly to sound like a Richard being a crybaby at times, even tho I do respect him for his views he tries to emboss on everyone to create a "not-exactly-freeier-but-just-more-open" overall software society. If everyone had a flat wallet, then this idea would work out nicely. If I ever write a printer driver, I will make sure I license it GPL and personally send him a copy to inspect, believe me. Maybe when the next raspberry pi revision comes out he'll send 1000's of them out for free also to his supporters and developers also, but I somehow doubt it. http://www.gnu.org/philosophy/proprietary.html Anyhow, this should hopefully be enough infos for the OP to get a general idea of what toolkit would be needed for whatever project is in mind. As I say ",If not satisfied, contact sales. They are always reassuring to sound the least." From dwightdhutto at gmail.com Mon Mar 31 23:58:40 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Mon, 31 Mar 2014 23:58:40 -0400 Subject: unicode as valid naming symbols In-Reply-To: References: <5331D902.3030902@gmail.com> <53321819$0$29994$c3e8da3$5496439d@news.astraweb.com> <53393BA4.2080305@rece.vub.ac.be> <5339C281.7080300@rece.vub.ac.be> Message-ID: I personally believe that it becomes hard to have even a programming language overcome cultural learning styles, and programmatic differences, because of nurture vs nature. We can all program something which results in a similar return value, but overcoming the nurturing the internet provides, becomes an imperative. I'll just offer a reference to avoid personal mistakes in explaining something that relates to how programmers/computer scientists/electrical engineers approach their end results, and why those end results may still differ in the mentality of the individual, or group, outcome of developing A.I. systems: http://en.wikipedia.org/wiki/Ethnolinguistics http://en.wikipedia.org/wiki/Cognitive_anthropology http://en.wikipedia.org/wiki/Cognitive_science The latter probably explains what I mean in more depth than the two formers. On Mon, Mar 31, 2014 at 8:47 PM, Ian Kelly wrote: > On Mon, Mar 31, 2014 at 1:31 PM, Antoon Pardon > wrote: > > Op 31-03-14 19:40, Ian Kelly schreef: > >> That was an exaggeration on my part. It wouldn't affect my job, as I > >> wouldn't expect to ever actually have to maintain anything like the > >> above. My greater point though is that it damages Python's > >> readability for no actual gain in my view. There is nothing useful > >> you can do with a name that is the U+1F4A9 character that you can't do > >> just as easily with alphanumeric identifiers like pile_of_poo (or > >> ????_??????? if one prefers; that's auto-translated, so don't blame me > >> if it's a poor translation). The kinds of symbols that we're talking > >> about here aren't part of any writing systems, and so to incorporate > >> them in *names* as if they were is an abuse of Unicode. > > > > Your argument doesn't has much weight. First of all it can be used > > for just restricting names to the ascii range. > > I disagree. Non-ASCII written names are useful to anybody who prefers > not to do all their programming in English. > > > Second of all I > > think a good chosen symbolic name can be more readable than a > > name in a character set you are not familiar with. A good chosen > > symbol will evoke a meaning with a lot of people. A name in a > > character set you are not familiar with is just gibberish to > > you. > > Well, this is the path taken by APL. It has its supporters. It's not > known for being readable. > > >> I don't think the comparisons to decorators and the if-else operator > >> are apt. > > > > I didn't make such a comparison. I just noted the arguments against > > were similar. > > That's the comparison to which I was referring. > > >> First, because while those may degrade readability, they do > >> so in a constrained way. A decorator application is just the @ symbol > >> and an identifier. > > > > And if abused, can totally change the working of your function. There > > is no guarantee that the function returned, has any relation with the > > original function. If that can't be a night mare for readability, > > I don't know what is. > > As Terry Reedy noted, this has nothing to do with the decorator > syntax, so it isn't much of an argument against having such syntax. > > >> The if-else is just three expressions separated by > >> keywords. > > > > Yes but if used unrestrained in arbitrary expressions will make those > > expressions hard to understand. > > I don't disagree. I hardly ever use it myself, certainly only if it > can fit comfortably into one line, which is rare. But it's still > quite limited in syntactic scope. > > >> In the case of arbitrary Unicode identifiers, we're talking > >> about approximately doubling the number of different characters (out > >> of a continuously growing set) that could be used, many of which are > >> easily confused with other characters. Of course the potential for > >> confusion already exists, but that's no justification for aggravating > >> it. > > > > So what if we double the number of different characters? I don't care > > about the number of them, I care about how meaningful they are. And > > as you say confusion is already possible. A good programmer knows > > how to deal with such a possible confusion, that the number of > > cases increases, doesn't need to be a problem for those that care > > about this. > > So tell me then, how would you deal with it? In the case of script > identifiers, it's often not hard to discern from context whether a > particular character is e.g. a Latin h or a Cyrillic ?. Assuming the > original author wasn't being intentionally obfuscatory, if the rest of > the identifier is Cyrillic then the character is probably also > Cyrillic. If it's a one-character identifier, then hopefully the rest > of the module is consistent and you can guess from that. If the > identifier in question is just one symbol though, then you have a lot > less context. > > > > >> Second, at least in the case of decorators, while I don't dispute that > >> they can harm readability, I think that in the majority of cases they > >> actually help it. > > > > But that is not a fair comparison now, is it. What you are doing here > > is comparing actual use, to a worst case doom scenario. > > I contend that there is no scenario with arbitrary Unicode identifiers > where readability is improved. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: