Re: Regular expressions
Steven D'Aprano <st...@pearwood.info> writes: >On Wed, 4 Nov 2015 07:57 pm, Peter Otten wrote: >> I tried Tim's example >> >> $ seq 5 | grep '1*' >> 1 >> 2 >> 3 >> 4 >> 5 >> $ >I don't understand this. What on earth is grep matching? How does "4" >match "1*"? >> which surprised me because I remembered that there usually weren't any >> matching lines when I invoked grep instead of egrep by mistake. So I tried >> another one >> >> $ seq 5 | grep '[1-3]+' >> $ >> >> and then headed for the man page. Apparently there is a subset called >> "basic regular expressions": >> >> """ >> Basic vs Extended Regular Expressions >>In basic regular expressions the meta-characters ?, +, {, |, (, >>and ) lose their special meaning; instead use the backslashed >>versions \?, \+, \{, \|, \(, and \). >> """ >None of this appears relevant, as the metacharacter * is not listed. So >what's going on? * is so fundamental that it never looses it special meaning. Same for [ . * means zero more of the preceeding char. This makes + superfluous (a mere convenience) as [1-3]+ can be expressed as [1-3][1-3]* Note that [1-3]* matches the empty string. This happens a lot. Groetjes Albert >-- >Steven -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe &=n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Rule of order for dot operators?
In article mailman.118.1431989304.17265.python-l...@python.org, Cameron Simpson c...@zip.com.au wrote: On 16May2015 12:20, C.D. Reimer ch...@cdreimer.com wrote: title = slug.replace('-',' ').title() This line also works if I switched the dot operators around. title = slug.title().replace('-',' ') I'm reading the first example as character replacement first and title capitalization second, and the second example as title capitalization first and character replacement second. Does python perform the dot operators from left to right or according to a rule of order (i.e., multiplication/division before add/subtract)? I've been thinking about the mindset that asks this question. I think the reason you needed to ask it was that you were thinking in terms of each .foo() operation acting on the original slug. They do not. slug is an expression returning, of course, itself. slug.title() is an expression returning a new string which is a titlecased version of slug. Why is slug.title a valid decomposition of the total string (Or is it?) What is the ()-brackets doing? Does it force the execution of title, which gives something to be dotted onto slug etc. See below. slug.title().replace(...) is an expression which _operates on_ that new string, _not_ on slug. In particular, each .foo() need not return a string - it might return anything, and the following .bah() will work on that anything. I interpreted the question as about the associative of the dot operator. title = slug.title().replace('-',' ') Does that mean title = slug.( title().replace('-',' ') ) or title = ( slug.( title()) .replace('-',' ') or is it evenslot.slot.slot a ternary operator with special syntax like we have in slot = slot = slot lately. It seems to me that you presuppose the answer. Cheers, Cameron Simpson c...@zip.com.au -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Boolean Operator Confusion
In article 553a5ded$0$12978$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sat, 25 Apr 2015 12:50 am, subhabrata.bane...@gmail.com wrote: Dear Group, I am trying to understand the use of Boolean operator in Python. I am trying to write small piece of script, as follows, def input_test(): str1=raw_input(PRINT QUERY:) if AND or OR or NOT in str1: print It is a Boolean Query elif AND or OR or NOT not in str1: print It is not a Boolean Query else: print None First problem: why do you sometimes return None? You have two possible answers: either something is a boolean query, or it is not. There is no third choice. (It's a boolean query, but only on Wednesdays.) In the context of testcode where the OP is not knowing what is going on it is absolutely useful, and legit. His problem is that it is Wednesday and weird things happen. Steven -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Bitten by my C/Java experience
In article mailman.96.1430761253.12865.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Tue, May 5, 2015 at 3:32 AM, Irmen de Jong irmen.nos...@xs4all.nl wrote: That is a broad question, but one thing that comes to mind is the current (python 3) behavior of integer division. It gives the exact result and doesn't truncate to integers: 5/4 1.25 Using the word exact around non-integer values can be a little ambiguous, since floats are often inexact. But yes, int/int - float, and yes, it WILL bite C programmers. This should not be presented as a somewhat arbitrary decision. Formerly we had 3e0/4e0 0.75 and 3/4 0 So the / operator worked on reals giving reals and integers giving integers. Great if you're used to it, but sometimes a pitfall. Also in practice it sometimes leads to rounding in unexpected places. The greatest disadvantage is when you have i and j and want their ratio. You have to do something like (real)i/j which feels unnatural. So we need two different division operators on the integers. Solution: introduce // for integer by integer given integer, giving the quotient (with a possible remainder). Now / is free to be used for the more rational i/j gives a ratio, i.e. a real number. Bottom line 3e0/4e0 and 3/4 gives the same result. It is nice to no longer have to be very careful in floating point calculation to avoid integer constants. On the other hand integer division is still available to solve the familiar egg-farm problems: I have 103 eggs. 12 eggs go in a box. How many boxes can I fill? (Similar problems crop up in graphics all the time.) ChrisA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python - block grouping (spaces)
In article d7f4c401-253a-4826-b018-7e84abb08...@googlegroups.com, Rustom Mody rustompm...@gmail.com wrote: On Monday, April 20, 2015 at 4:00:16 PM UTC+5:30, Steven D'Aprano wrote: On Monday 20 April 2015 12:43, Rustom Mody wrote: You've a 10-file python project in which you want to replace function 'f' by function 'longname' How easy is it? About a thousand times easier than the corresponding situation: You have ten PDF files in which you want to replace the word f with the word longname. To paraphrase Pauli's This is not even wrong this is not even a strawman On the contrary it is the last word in this discussion. At least the last word I need or will read. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Best search algorithm to find condition within a range
In article 5533a77d$0$12993$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 19 Apr 2015 04:08 am, Albert van der Horst wrote: Fire up a lowlevel interpreter like Forth. (e.g. gforth) Yay! I'm not the only one who uses or likes Forth! I'm an author of half a dozen implementations, brand is called ciforth. Just last Thursday an elaborate test session in Apple. Expect release 5.2 for Linux Windows and Apple in a few weeks. I've also published a minimalistic system called yourforth. Have you tried Factor? I'm wondering if it is worth looking at, as a more modern and less low-level version of Forth. Chuck Moore has build a 100+ processor chip. I've experimented with a parallel sieve for primes on the chip. Later Leon Konings and I have run the same program on a simulator for the greenarray's chip with 144 processors. Leon has written the simulator in Factor, it is called Arrayforth. So I've seen some Factor from close up. I think the system is practical and reliable. The runtime environment however is a bit unwieldy. Leon is enthusiastic (but he always is) about the documentation and general working. Factor has a lot of protection, It is nothing like ciforth however, most faulty ciforth programs end in segmentation fault. For 60K (+ 300K library) ciforth buys you an interpreter, a scripter and a compiler. Unlike most Forth's you can do lina -c hello.frt and then ship the hello program. ( And yes, hello.frt is a one liner with just one definition, no boilerplate.) I've solved hundreds of Euler project problems with it, but if you need really abstract things (like representing situations and counting them using a dict) I generally use Python. ciforth arrayforth and yourforth are googleable. -- Steven Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: generator/coroutine terminology
In article 551e2cfd$0$11123$c3e8...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wednesday 01 April 2015 00:18, Albert van der Horst wrote: In article 55062bda$0$12998$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The biggest difference is syntactic. Here's an iterator which returns a never-ending sequence of squared numbers 1, 4, 9, 16, ... class Squares: def __init__(self): self.i = 0 def __next__(self): self.i += 1 return self.i**2 def __iter__(self): return self You should give an example of usage. As a newby I'm not up to figuring out the specification from source for something built of the mysterious __ internal thingies. (I did experiment with Squares interactively. But I didn't get further than creating a Squares object.) Ah, sorry about that! Usage is: it = Squares() # create an iterator print(next(it)) # print the first value x = next(it) # extract the second while x 100: print(x) x = next(it) Beware of doing this: for x in Squares(): print(x) since Squares is an *infinite* generator, it will continue for ever if you let it. Fortunately you can hit Ctrl-C to interrupt the for loop at any point. In Python 2, you will need to rename __next__ to just next without the double-leading-and-trailing underscores. Here's the same thing written as a generator: def squares(): i = 1 while True: yield i**2 i += 1 And for this one: it = squares() # create the iterator print(next(it)) # print the first value x = next(it) # extract the second while x 100: print(x) x = next(it) Usage is pretty much exactly the same. Thanks, I get it now. next and yield are more or less switching between coroutines. -- Steve -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Best search algorithm to find condition within a range
In article fd544688-5e9c-418e-9ca9-11b9bcb83...@googlegroups.com, jonas.thornv...@gmail.com wrote: Den tisdag 7 april 2015 kl. 16:30:15 UTC+2 skrev Denis McMahon: On Tue, 07 Apr 2015 09:29:59 -0400, Dave Angel wrote: On 04/07/2015 05:44 AM, jonas.thornv...@gmail.com wrote: I want todo faster baseconversion for very big bases like base 1 000 000, so instead of adding up digits i search it. How do you know the baseconversion is the bottleneck, if you haven't written any Python code yet? He doesn't. He doesn't comprehend that as far as a computer is concerned an integer has no specific 'base', it's only when presented in a form for humans to read that it gets base information added in the representation. He's making these and other similar errors in the javascript groups too. I suspect he's one of those people that spends his time thinking up elaborate solutions that he has no idea how to implement as a response to dreamt up non existent problems. -- Denis McMahon, denismfmcma...@gmail.com Bullshit declare two integers in any language one 7 and one 4 and then write x=7+4; if you find a programming language where that does not yield 11 tell me. Integers are internally assumed to be base 10 otherwise you could not calculate without giving the base. All operations on integers addition, subtraction, multiplication and division assume base 10. Fire up a lowlevel interpreter like Forth. (e.g. gforth) 7 CONSTANT A4 CONSTANT B A B + PAD ! PAD now contains the sum of A and B. Now inspect the actual computer memory: PAD 100 DUMP You will see the bytes, represented in base 16, but PAD just contains 11 PAD ? 11 OK In forth you can change the number base. That doesn't affect PAD but the output is different HEX PAD ? B OK DECIMAL Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Sudoku solver
In article 87iodoakft@elektro.pacujo.net, Marko Rauhamaa ma...@pacujo.net wrote: Ian Kelly ian.g.ke...@gmail.com: The test puzzle that you posted has 23 values already filled in. How does it perform on harder puzzles with only 17 clues (the proven minimum)? One would expect it to be around a million times slower. Just try it. The example had a minimum of clues (drop one clue and you'll get multiple solutions). URL: http://www.telegraph.co.uk/news/science/science-news/9359579/W orlds-hardest-sudoku-can-you-crack-it.html mentions this puzzle: 8 . . . . . . . . . . 3 6 . . . . . . 7 . . 9 . 2 . . . 5 . . . 7 . . . . . . . 4 5 7 . . . . . 1 . . . 3 . . . 1 . . . . 6 8 . . 8 5 . . . 1 . . 9 . . . . 4 . . It takes about 2 seconds for my Python program to find the answer but it spends a total of 110 seconds to exhaust the problem space. The analogous C program finished the whole thing in 200 milliseconds. That is a more reasonable time for a realistic algorithm. This puzzle takes 255 ms in a program that I wrote in 2008 in Forth. Marko Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: generator/coroutine terminology
In article 83d579c1-ab61-4a3d-a834-e65d28eac...@googlegroups.com, Rustom Mody rustompm...@gmail.com wrote: On Saturday, March 14, 2015 at 8:59:22 PM UTC+5:30, Rustom Mody wrote: On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano wrote: A generator (function) may be a function which returns an iterator,... I find generator-function misleading in the same way that pineapple misleadingly suggests apple that grows on pines A builtin function is a function in the builtin (or builtins -- can never remember) module A pure function is function that does not assign or mutate non-locals A Steven-function is a function that presumably Steven wrote However a generator function is a weird sort of function (at best). Not regarding it as a function is IMO more reasonable. Another analogy somewhat closer home than pineapples. In Pascal there are procedures and functions. Even in the venerable Fortran there are subroutine-subprogram and (sub)function-subprogram. The Algol 68 designers considered it a defect in the design. They created a situation like in Python, where a def-thingy need not return a value. C took the stupid approach of just throwing out one of these. A decade of troubles was enough to convince people that it was needed and the mysterious 'void-returning' function was introduced to simulate procedures The mistake this was intended to fix, was the rule that by default a function returns int in C. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: generator/coroutine terminology
In article mailman.372.1427809109.10327.python-l...@python.org, Dave Angel da...@davea.name wrote: On 03/31/2015 09:18 AM, Albert van der Horst wrote: In article 55062bda$0$12998$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The biggest difference is syntactic. Here's an iterator which returns a never-ending sequence of squared numbers 1, 4, 9, 16, ... class Squares: def __init__(self): self.i = 0 def __next__(self): self.i += 1 return self.i**2 def __iter__(self): return self You should give an example of usage. As a newby I'm not up to figuring out the specification from source for something built of the mysterious __ internal thingies. (I did experiment with Squares interactively. But I didn't get further than creating a Squares object.) He did say it was an iterator. So for a first try, write a for loop: class Squares: def __init__(self): self.i = 0 def __next__(self): self.i += 1 return self.i**2 def __iter__(self): return self for i in Squares(): print(i) if i 50: break This is what I get: / -- albert@cherry:/tmp$ more aap.py class Squares: def __init__(self): self.i = 0 def __next__(self): self.i += 1 return self.i**2 def __iter__(self): return self albert@cherry:/tmp$ python Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type help, copyright, credits or license for more information. from aap import * for i in Squares(): ... print i ... if i50: break ... Traceback (most recent call last): File stdin, line 1, in module TypeError: instance has no next() method / -- Probably not what is intended. Last minute note: renaming __next__() into next() did the job. -- DaveA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: generator/coroutine terminology
In article 55062bda$0$12998$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Marko Rauhamaa wrote: Chris Angelico ros...@gmail.com: On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa ma...@pacujo.net wrote: Is it necessary/useful for a Python application programmer to be conscious of the different types of iterator? What mistaken usage could arise if the application just treated all iterators as, well, iterators? If you treat them all as iterators, then you're safe, because that's the lowest common denominator. But there are a number of other iterators that have more features, including files, generators, etc. What features do generator iterators provide on top of generic iterators? The biggest difference is syntactic. Here's an iterator which returns a never-ending sequence of squared numbers 1, 4, 9, 16, ... class Squares: def __init__(self): self.i = 0 def __next__(self): self.i += 1 return self.i**2 def __iter__(self): return self You should give an example of usage. As a newby I'm not up to figuring out the specification from source for something built of the mysterious __ internal thingies. (I did experiment with Squares interactively. But I didn't get further than creating a Squares object.) Here's the same thing written as a generator: def squares(): i = 1 while True: yield i**2 i += 1 Four lines, versus eight. The iterator version has a lot of boilerplate (although some of it, the two-line __iter__ method, could be eliminated if there was a standard Iterator builtin to inherit from). Here's a more complicated example: class Randoms: def __init__(self): self.finished = False def __next__(self): x = random.random() if x 0.5: self.finished = True if self.finished: raise StopIteration else: return x def __iter__(self): return self def randoms(): x = random.random() while x 0.5: yield x x = random.random() Generators, as a rule, are significantly easier to write, understand, and debug. There's nothing they can do that can't be done with an iterator class, but the fiddly, unexciting bits related to halting and resuming and saving state are all handled for you, allowing you to concentrate on the behaviour you want, not the boilerplate. This is illuminating. Thanks. -- Steven Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Alternative to multi-line lambdas: Assign-anywhere def statements
In article mailman.18121.1422151185.18130.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: -=-=-=-=-=- On 01/24/2015 11:55 AM, Chris Angelico wrote: On Sun, Jan 25, 2015 at 5:56 AM, Ethan Furman et...@stoneleaf.us wrote: If the non-generic is what you're concerned about: # not tested dispatch_table_a = {} dispatch_table_b = {} dispatch_table_c = {} class dispatch: def __init__(self, dispatch_table): self.dispatch = dispatch_table def __call__(self, func): self.dispatch[func.__name__] = func return func @dispatch(dispatch_table_a) def foo(...): pass That's still only able to assign to a key of a dictionary, using the function name. This is a Good Thing. The def statement populates a few items, __name__ being one of them. One of the reasons lambda is not encouraged is because its name is always 'lambda', which just ain't helpful when the smelly becomes air borne! ;) That's the reason why my ideal Python doesn't attach a name to a lambda denotation: x - x**2 is a function object, not something that has a name. It is not until we assign the object to a name (which becomes thereby a function) that the __name__ thingy comes into play, like so. f = x-x**2 or f = x- return x**2 for those who don't like Algol68 I've heard arguments that with - the __name__ is not filled in correctly. I can't see why the parser would understand more easily def f(x): return x**2 than f = x- return x**2 [I'm striving for simplification, doing away with both the lambda and the def keywords. This is not a proposal for a language change, I'm trying to explore possibilities here. ] -- ~Ethan~ Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: What killed Smalltalk could kill Python
In article mailman.17920.1421864740.18130.python-l...@python.org, Tim Chase python.l...@tim.thechases.com wrote: On 2015-01-22 03:34, Steven D'Aprano wrote: In 2009, Robert Martin gave a talk at RailsConf titled What Killed Smalltalk Could Kill Ruby. Holy pacing, Batman. Watching it at 2x leaves me wondering how much of the stage was worn off during the presentation. And now it's all but dead. Why did it die, and how can Python (or Ruby for that matter) avoid the same fate? In my experience, most Python has a particularly low WTF-per-minute score. But mostly Michael's reply addresses my biggest pain points the last couple times I tried Smalltalk: The whole images thing impeded me from easily using my development preferred environment. With Python, I can just install it and then either fire up the REPL, or type some code into a file and run it (same I suppose would go for Ruby). I fought for over an hour trying to figure out how to just get ANYTHING to run in Smalltalk. I installed Squeak on Debian and yet I couldn't get any code examples to run. I had to go find some environments on the web, download them, modify them, and eventually something ran. Eventually I just gave up and returned to a world where everything made sense. This is the introductory chapter of my Forth: 4 Manual 4.1 Getting started === 4.1.1 Hello world! -- Type `lina64' to get into your interactive Forth system. You will see a signon message. While sitting in your interactive Forth doing a hello world is easy: Hello world! TYPE Hello world! OK Note that the computer ends its output with `OK' to indicate that it has completed the command. Making it into an interactively usable program is also easy: : HELLO Hello world! TYPE CR ; OK HELLO Hello world! OK This means you type the command `HELLO' while you are in lina64. As soon as you leave lina64, the new command is gone. If you want to use the program a second time, you can put it in a file `hello.frt'. It just contains the definition we typed earlier: : HELLO Hello world! TYPE CR ; This file can be `INCLUDED' inorder to add the command `HELLO' to your Forth environment, like so: hello.frt INCLUDED OK HELLO Hello world! OK During development you probably have started with `lina64 -e', so you need just type INCLUDE hello.frt In order to make a stand alone program to say hello you can use that same source file, again `hello.frt'. Now build the program by lina64 -c hello.frt (That is `c' for compile.) The result is a file `hello' . This file can be run from your command interpreter, or shell. It is a single file that you can pass to some one else to run on their computer, without the need for them to install Forth. For the compiler to run you must have the library correctly installed. Seems like I did it slightly better. (Mind you, this is chapter 4, for beginners there is chapter 2, e.g. if the `` : '' word puzzles you.) Groetjes Albert -tkc -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Python is DOOMED! Again!
In article mailman.17951.1421906568.18130.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: -=-=-=-=-=- On 01/21/2015 08:30 PM, Steven D'Aprano wrote: So what is this unspeakable, nightmarish, cryptic abomination going to look like? Here's an example from PEP 484: def greeting(name: str) - str: return 'Hello ' + name I don't know about you, but I think anyone who cannot read that and intuit that argument `name` is a string and the return result is also a string There is nothing inherently intuitive about that syntax. The : makes it look like a dictionary (but it isn't) and the - looks like a pointer to something (but it isn't). It is too bad `` - '' as a token is now taken. I wanted to propose to replace the ternary syntax lambda .. : .. by a regular operator .. - .. then we could have x - x**2 instead of lambda x : x**2 Moreover the value of a function would be a lambda not def square(x): x**2 but square = x-x**2 or mult = x,y - result = 0 for i in range(x): result +=y return result doing away with the ternary operator def def .. ( .. ) : .. replacing it by two binary operators, one of them (=) being thoroughly familiar. It is horrifying to see that def is now becoming a quaternary operator def .. ( .. ) -- .. : .. Also name:str is the wrong order. I would propose to use :: to prevent confusion. Then I would allow type:: in front of all objects everywhere to trigger a warning if at that point the objects is not of the right type. I think it is quite natural that float: sets the expectation that a float is coming. float:: x = get_some_crap_from_an obscure_windows_box( a, B, c, a_lighter, some_list, REAL_ISB_MASK ) is probably going to have bigger troubles with Python than just type-hinting. Yup, true -- I do find writing meta-classes takes extra work. ;) -- ~Ethan~ -=-=-=-=-=- [Attachment type=application/pgp-signature, name=signature.asc] -=-=-=-=-=- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: What killed Smalltalk could kill Python
In article mailman.17939.1421895565.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Thu, Jan 22, 2015 at 1:53 PM, Paul Rubin no.email@nospam.invalid wrote: If someone's unfazed by the it'll take you years before you can actually write a saleable game consideration, Wanting to write games is a completely different topic than wanting to sell them. It's just like any other creative outlet. Most people who teach themselves to juggle do it because juggling is fun, not because they want to join the circus. True, but even a playable game is a long way beyond a first-day programmer. (By playable I mean something that someone other than its author would play and enjoy.) It's fine as a goal, but needs to be viewed with a perspective of that's where I'm trying to get to, not now I'm going to start writing games. Not to mention that mostly a game is understood, not as something like chess, but an FPS (first person shooter) game. But that is real time programming, one league beyond beginners procedural (sequential) or functional programming. The result is either a disappointment or the illusion of having created something while in fact one used a frame work where all the hard work has been done. ChrisA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Hello World
In article mailman.17471.1420721626.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: SNIP But sure. If you want to cut out complication, dispense with user accounts altogether and run everything as root. That's WAY simpler! I didn't except this strawman argument from you. Of course you need a distinction between doing system things as root, and working as a normal user. You just don't need sudo. ChrisA -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Hello World
In article mailman.17481.1420737102.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Fri, Jan 9, 2015 at 4:02 AM, Steve Hayes hayes...@telkomsa.net wrote: On 08 Jan 2015 12:43:33 GMT, alb...@spenarnc.xs4all.nl (Albert van der Horst) wrote: I don't trust sudo because it is too complicated. (To the point that I removed it from my machine.) I do How do you do that? I avoided Ubuntu because it had sudo, and then discovered that Fedora had it as well. Uhh, 'apt-get remove sudo'? That ought to work on any Debian-based That works. That is exactly what I did. system. With Debian itself, you get the option during installation of setting a root password, in which case it won't install sudo by default. ChrisA -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Why do the URLs of posts here change?
In article mailman.17551.1420862015.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Sat, Jan 10, 2015 at 2:21 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Skip Montanaro wrote: The way this is done, is that the message is removed from the underlying mbox file, and the archive regenerated. That changes the counter for every message after that point Would it help to replace the message with a stub instead of deleting it altogether? I had the same thought, but apparently not, according to the page Peter Otten linked to: http://wiki.list.org/display/DEV/Stable+URLs Knowing that the source is an mbox file, I don't need to follow that link to conclude that one is not very inventive. It suffices to replace the content of the message by a repetition of '\n'. Maybe also the sender and the subject. ChrisA -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: recursive function: use a global or pass a parameter?
In article 5e4ccec6-7a00-467d-8cf6-258ab0421...@googlegroups.com, Tim jtim.arn...@gmail.com wrote: I have this type of situation and wonder if I should use a global variable outside the recursive function instead of passing the updated parameter through. I want to get a union of all the values that any 'things' key may have, even in a nested dictionary (and I do not know beforehand how deep the nesting might go): d = {'things':1, 'two':{'things':2}} def walk(obj, res): if not hasattr(obj, 'keys'): return set(), set() if 'things' in obj: res.add(obj['things']) for k in obj: walk(obj[k], res) return res walk(d, set()) # returns {1, 2} Is it better to use a global to keep track of the values or does it even matter? Neither. You shouldn't pass superfluous parameters, and you shouldn't abuse globals. The proper technique is make the global local to the normal subroutine, then make the subroutine with those parameters you don't want to see also local to that subroutine. E.g. def fib(n): ' return the n-th Fibonacci number ' a,b = 0,1 def fib1(ap,bp): ' for f_n,f_n+1, return f_n+1,f_n+2 ' return bp,ap+b for i in xrange(n): a,b = fib1(a,b) return a thanks, --Tim Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Hello World
In article h9gqob-c3e@esprimo.zbmc.eu, c...@isbd.net wrote: Michael Torrie torr...@gmail.com wrote: On 01/17/2015 07:51 AM, Albert van der Horst wrote: In article mailman.17471.1420721626.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: SNIP But sure. If you want to cut out complication, dispense with user accounts altogether and run everything as root. That's WAY simpler! I didn't except this strawman argument from you. Of course you need a distinction between doing system things as root, and working as a normal user. You just don't need sudo. I just don't see the distinction. What's the difference between having to type in a root password and having to type in your own administrative user password? Guess we're all just struggling to understand your logic here. One big distinction is that you need to know two passwords to get root access if there's a real root account as opposed to using sudo. This only applies of course if direct root login isn't allowed (via ssh or whatever). The other is that if a dozen users have sudo possibility, one compromised password compromises the whole system. The same administrators that like sudo will force the users into a safe password of at least 8 characters a special sign a number and a capital, instead of educating them to use a strong password like the_horse_eats_yellow_stones. 1] Chances are that one of the users has a password like ! (first special sign) 1 (first number) Q (first capital) followed by a weak 5 letter word (or even a guessable one). Compare that to Dear administrator, I've to do this. Can I have the root password. Sure here it is Looks over users shoulder. Are you ready? Make sure he's logged out. Uses random generator for a new password. If there is something, anything, change the root password and check the disk for suid-root files. There is no such thing as automatic security. Security requires one thing: attention. And effort. So two things: attention and effort. And simplicity. So three things: attention, effort and simplicity. sudo makes administrators careless, lazy and it is not simple at all. -- Chris Green Groetjes Albert 1] I don't claim this is *very* strong, just strong. -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Hello World
In article mailman.17077.1419144290.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Sun, Dec 21, 2014 at 5:31 PM, Terry Reedy tjre...@udel.edu wrote: Just to be clear, writing to sys.stdout works fine in Idle. import sys; sys.stdout.write('hello ') hello #2.7 In 3.4, the number of chars? bytes? is returned and written also. Whether you mean something different by 'stdout' or not, I am not sure. The error is from writing to a non-existent file descriptor. That's because sys.stdout is replaced. But stdout itself, file descriptor 1, is not available: os.fdopen(1,w).write(Hello, world\n) Traceback (most recent call last): File pyshell#4, line 1, in module os.fdopen(1,w).write(Hello, world\n) OSError: [Errno 9] Bad file descriptor I don't trust sudo because it is too complicated. (To the point that I removed it from my machine.) I do su .. # su nobody Who needs sudo? It's like instead of telling a 4-year old to stay on the side walk, learning him to read and then give him a 8-page brochure about safety in traffic. This works fine in command-line Python, just not in IDLE. It's not Windows vs Unix, it's Idle vs terminal. ChrisA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: How do I remove/unlink wildcarded files
In article f69874c8-48f6-4696-8678-c2a761f2f...@googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: On Saturday, January 3, 2015 4:39:25 AM UTC-6, Mark Lawrence wrote: I used to get very confused watching the old westerns. The child when talking about more and paw wasn't referring to possibly an adjective, noun or adverb and a part of an animal, but what we would refer to in the UK as mum and dad :) Early Americans are easy to satirize since most were schooled at home by illiterate parents. I believe the redneck vernacular substituted mother and father for maw and paw respectively. Which is not surprising since most uneducated folks tend to favor single syllable simplifications of words over their multi-syllable counterparts. Widespread centralized free schooling did not exists until almost the 1900's. Heck, looking back at American history, the world *SHOULD* be in awe. To go from a rag-tag illiterate bunch of cowboys, to the worlds most powerful and technically advanced society (in roughly one hundred years!) has to be the most amazing transformation in the history of the human society. It isn't. The Russian transformation under Stalin from a feodalist society with wooden plows to atomic bombs and space travel is. Most capitalist politicians are reluctant to admit this, but e.g. Churchill recognized this. A comboy on horse back who has ever seen a revolver is a far cry in backwardness from a feodalist peasant who *expects* to be flogged by a knut. Feodalism goes to the brain, like slavery does. (It took generations for the US negroes to shed of their slavery inheritance. ) Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Hello World
In article mailman.17471.1420721626.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Thu, Jan 8, 2015 at 11:43 PM, Albert van der Horst alb...@spenarnc.xs4all.nl wrote: I don't trust sudo because it is too complicated. (To the point that I removed it from my machine.) I do su .. # su nobody Who needs sudo? With sudo, you get MUCH finer control. I can grant some user the power to run sudo eject sr0, but no other commands. I can permit someone to execute any of a large number of commands, all individually logged. I can allow sudo to other users than root, without having to reveal those accounts' passwords (chances are they don't even have passwords). You've answered it. sudo works for a system with a very knowledgeable system administrator and at least one other user. Not for an electronic engineer who uses Python on his Raspberry Pi. But sure. If you want to cut out complication, dispense with user accounts altogether and run everything as root. That's WAY simpler! I've no problem explaining to an electronic engineer not to do this, while not offering him to do the system administration for him. Having a separate account for system things is a useful distinction that he can grasp and handle easily. Beyond that he is indeed inclined to do everything as root, because what he wants is to make a turnkey to feed his gold fish. So a separate root account is the best protection for a single user system. For quite a considerable part of the systems around, sudo is over the top and stimulates no protection at all, i.e. what I'd call counter productive. I can save a 4-years olds life by imprinting on him to stay on the side walk. ChrisA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: ** in python
In article mailman.16217.1416793733.18130.python-l...@python.org, Skip Montanaro skip.montan...@gmail.com wrote: -=-=-=-=-=- I want to add one more thing to the other responses. People new to Python often seem unaware that being an interpreted language, often the best way to figure something out is to simply try it at the interpreter prompt. The OP saw var ** 2 in done code. The most obvious thing to me would have been to type var = 42 var ** 2 and see what happened. It's unlikely to trigger a nuclear meltdown, or even crash the interpreter. Skip -=-=-=-=-=- [Alternative: text/html] -=-=-=-=-=- With some perseverance, you can ask the interpreter what `` ** '' does: help(**) syntax error maybe so? help('**') Indeed, a whole description. help(var) help(42) also work. Come on, guys and dolls! Your advice to a newbies is soso, if in this kind of answer, the help facilitiy is not mentionned. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
In article 546d7505$0$12899$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano st...@pearwood.info wrote: And the award for the most gratuitous comments before an import goes to one of my (former) workmates, who wrote this piece of code: # Used for base64-decoding. import base64 # Used for ungzipping. import gzip The comment lines contain genuine information. The program is decoding or gunzipping. (And apparently not doing the encoding part) This information may have been better conveyed by from base64 import base64-decode from gzip import gunzip but anyway. Also the comment may be misleading, but I think not. If there are mysterious names for packages, the comment may be actually useful. # Auxiliary for the reverse recursion to calculate # Chebychev coefficients. import courseware-2014-ch11 A professor who demands from students that every import is documented is IMO not to blame. In a company's coding convention ... I've seen a lot of things there that make a lot less sense. -- Steven -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: How is max supposed to work, especially key.
In article mailman.16378.1417111312.18130.python-l...@python.org, Peter Otten __pete...@web.de wrote: Albert van der Horst wrote: In the Rosetta code I come across this part of LU-decomposition. def pivotize(m): Creates the pivoting matrix for m. n = len(m) ID = [[float(i == j) for i in xrange(n)] for j in xrange(n)] for j in xrange(n): row = max(xrange(j, n), key=lambda i: abs(m[i][j])) if j != row: ID[j], ID[row] = ID[row], ID[j] return ID That it's using a cast from boolean to float and using at the other moment a float as a boolean, suggest that this code is a bit too clever for its own good, but anyway. My problem is with the max. I never saw a max with a key. In my python help(max) doesn't explain the key. It says that max can handle an iterator (I didn't know that), and you can pass and optional key=func, but that's all. I expect it to be something like elements in the iterator are taken into account only if the key applied to the iterator evaluates to a True value. However that doesn't pan out: max(xrange(100,200), key=lambda i: i%17==0 ) 102 I expect the maximum number that is divisible by 17 in the range, not the minimum. Can anyone shed light on this? Given a function f() max(items, key=f) returns the element of the `items` sequence with the greatest f(element), e. g. for max([a, bcd, ef], key=len) the values 1, 3, 2 are calculated and the longest string in the list is returned: max([a, bcd, ef], key=len) 'bcd' If there is more than one item with the maximum calculated the first is given, so for your attempt max(xrange(100,200), key=lambda i: i%17==0 ) the values False, False, True, False, ... are calculated and because True False True the first one with a True result is returned. So in that case max doesn't return the maximum (True), but instead something else. Useful as that function may be, it shouldn't have been called max. I don't blame myself for being misled. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
In article mailman.16030.1416502295.18130.python-l...@python.org, Joel Goldstick joel.goldst...@gmail.com wrote: SNIP Or just WOW!. Programming is hard, and people have just started to do it. Fifty years isn't that long. It has only been 20 years or so that the web has been around. That makes it easier to find information from a variety or sources -- the official docs, tutorials, articles. If you feel the docs are awful, write a tutorial based on your knowledge level and experience. Improve the situation. That doesn't help. I'm a very experienced programmer and work in routinely a dozen languages. Sometimes I do python. I want to do numeric work. I remember the name numpy. It is important, everybody knows it, it is all over the place. So I want to find its docs, or some lead, whatever. I go to the official Python site, http://docs.python.org and type in numpy in the search machine. It is embarassing, try it! Plain google is far superior in finding information. And you tell me that writing yet another tutorial would improve that? No, there is just one way. The powers that be should look critically at their website, and test it with a beginners hat on. I'm trying to wrap my mind around DOCUMENTION being STUPID. -- Joel Goldstick http://joelgoldstick.com Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: How is max supposed to work, especially key.
In article mailman.16552.1417688329.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Thu, Dec 4, 2014 at 9:09 PM, Albert van der Horst alb...@spenarnc.xs4all.nl wrote: If there is more than one item with the maximum calculated the first is given, so for your attempt max(xrange(100,200), key=lambda i: i%17==0 ) the values False, False, True, False, ... are calculated and because True False True the first one with a True result is returned. So in that case max doesn't return the maximum (True), but instead something else. Useful as that function may be, it shouldn't have been called max. I don't blame myself for being misled. If lots of them are equally the largest, by whatever definition of largest you have, it has to do one of three things: 1) Raise an exception 2) Return multiple items (either as a tuple, or a generator, or something) 3) Pick one of them and return it. Python's max() does the third, and for the picking part, uses the first one it comes across - a decent way to do it. If there's no clear maximum, it can't do any better than that. It's still returning something for which there is no greater. I agree that it is a useful function and that it is doing the right thing. What is wrong is the name. I refer to the fact that it is not returning the maximum. It returns the iterator value that leads to the maximum. A function that doesn't return a maximum shouldn't be called maximum. ChrisA -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: I love assert
In article 87a93tl07u@elektro.pacujo.net, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: On Sat, Nov 15, 2014 at 11:12 AM, Marko Rauhamaa ma...@pacujo.net wrote: Most importantly, assertion failures are not supposed to be recovered from (within the program). Assertion failures can result in the loss of life and limb. They can result in database corruption. They can result in monetary losses. They can result in smoke coming out of the monitor. Or, in theory, AssertionError just prevented any of the above from happening. I'd advice against catching AssertionError and trying to recover from it within the program. You could catch it, log it and reraise it, but since the failure modes could be completely unexpected (really, by definition), I would move fault-tolerance outside the failing process and try to restore a coherent reality from there. Assertion errors are in the same class with CPython bugs, external signals (say, SIGKILL), security breaches, hardware failures and the like. For expected failure modes, other exceptions are a suitable facility. I agree with you (also with your other posts) and I hate that disabling asserts is considered a kind of optimising. Wasn't Dijkstra who said that while the ship is on the dock, we have life vests on, and while we are at sea, the life vests stay on shore. It is a defect in python that asserts are automatically removed with a -O option. Maybe if there are six levels of optimization -O7 at last would remove the asserts. Then in the programmers manual of my company I would have: Programs are only allowed to use -O7 if there is a test that doing so results in a substantial benefit in running time, and documented as such. And no: AssertionError is no exception to be thrown (such that an irresponsible person might catch, or even ignore them.) Indeed it should be treated like a parity fault in the memory of a computer: don't drive because the brakes don't work. And then Ben Finney wants us to remove the asserts as soon as they are committed to source control. Please! It is a fallacy that there are untested and tested, hence correct, programs. There are just more or less tested, and more or less correct programs. If I deliver a program to source control it may not be solid. If I give it a tag it is solid... until the company sets a junior on it to add a feature. Then the assert may turn out to be life saver, even literally. Marko -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
How is max supposed to work, especially key.
In the Rosetta code I come across this part of LU-decomposition. def pivotize(m): Creates the pivoting matrix for m. n = len(m) ID = [[float(i == j) for i in xrange(n)] for j in xrange(n)] for j in xrange(n): row = max(xrange(j, n), key=lambda i: abs(m[i][j])) if j != row: ID[j], ID[row] = ID[row], ID[j] return ID That it's using a cast from boolean to float and using at the other moment a float as a boolean, suggest that this code is a bit too clever for its own good, but anyway. My problem is with the max. I never saw a max with a key. In my python help(max) doesn't explain the key. It says that max can handle an iterator (I didn't know that), and you can pass and optional key=func, but that's all. I expect it to be something like elements in the iterator are taken into account only if the key applied to the iterator evaluates to a True value. However that doesn't pan out: max(xrange(100,200), key=lambda i: i%17==0 ) 102 I expect the maximum number that is divisible by 17 in the range, not the minimum. Can anyone shed light on this? Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: (-1)**1000
In article mailman.15076.1413990100.18130.python-l...@python.org, Ned Batchelder n...@nedbatchelder.com wrote: On 10/22/14 5:27 AM, ast wrote: Chris Angelico ros...@gmail.com a écrit dans le message de news:mailman.15058.1413968065.18130.python-l...@python.org... On Wed, Oct 22, 2014 at 7:27 PM, ast nom...@invalid.com wrote: If i am writing (-1)**1000 on a python program, will the interpreter do (-1)*(-1)*...*(-1) or something clever ? In fact i have (-1)**N with N an integer potentially big. Exponentiation is far more efficient than the naive implementation of iterated multiplication. In the very particular case of (-1)**N, I belive that Python check the odd or even parity of N and provides the result accordingly. I tried: (-1)**10 1 (-1)**11 -1 and it is instantaneous Keep in mind that actually calculating the exponentiation wouldn't do 10 multiplications anyway: the clever way to do integer powers is by squaring based on the binary representation of the exponent. It's explained here: http://stackoverflow.com/a/101613/14343 So even if Python is actually calculating the value, it's only doing 75 multiplications or so. I'm pretty sure that if we replace -1 by 2 , it never gets at its 75-th multiplication. -- Ned Batchelder, http://nedbatchelder.com Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Global indent
In article mailman.13359.1408831344.18130.python-l...@python.org, Anders Wegge Keller we...@wegge.dk wrote: On Sun, 24 Aug 2014 00:56:11 +1000 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Despite my comments, I don't actually have any objection to people who choose to use Emacs, or Vim, or edit their text files by poking the hard drive platter with a magnetised needle if they prefer :-) But I do think it's silly of them to claim that Emacs has no learning curve, or to fail to recognise how unfamiliar and different the UIs are compared to nearly everything else a computer user is likely to be familiar with in 2014. Really, they don't! At least not for the people, for whom they are necessary tools. When I started in my present job, remote access was a dial-up modem, that could do 2400 baud, if you were lucky[1]. With such a shitty connection, a text-only editor is indisputably the right thing. Curiously enough, even today the same lousy kind of connections prevail. We still have a sizeable modem bank at my job. We still do our remote support over a telnet/ssh session. And we still are unable to reliable get the connection speeds[2], that would make anything with a GUI remotely pleasant. So emacs and vim still have their niches. Those of us, who are old enough to have started our first job in a glorified teletype, OR have to support systems that are only reachable over RFC-1149 quality datalinks, belong there. The rest of you would probably be better off with something nicer. 1. Meaning a real switched landline all the way from Denmark to Tokyo. Ending up with two satellite up/down-links was a killer. 2. We have an installation in the Philippines, where we ended up installing a satellite uplink. It feels like we have doubled the connectivity of the entire Manilla area by doing so. And it's still painfully slow. Right. I remember having a 300 baud dial up line. Edwin's editor (ee), the editor I'm using right now, was optimised for screen access, and I could do cursor based full screen editing, quite passably, doing a vt100 emulation on my Osborne CP/M machine. (I've a non transferable license and ee is not for sale.) -- //Wegge Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: OT: This Swift thing
In article mailman.11028.1402548495.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Thu, Jun 12, 2014 at 12:08 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I'm just pointing out that our computational technology uses over a million times more energy than the theoretical minimum, and therefore there is a lot of room for efficiency gains without sacrificing computer power. I never imagined that such viewpoint would turn out to be so controversial. The way I understand it, you're citing an extremely theoretical minimum, in the same way that one can point out that we're a long way from maximum entropy in a flash memory chip, so it ought to be possible to pack a lot more data onto a USB stick. The laws of physics tend to put boundaries that are ridiculously far from where we actually work - I think most roads have speed limits that run a fairly long way short of c. As a physicist I'm well aware that houses need no heating. With a suitable isolation and top-notch heat-exchangers in the ventilation system, our bodies generate enough heat to keep our houses at a comfortable 21 degrees. (Well, and there is the disk washer.) In the same vain cars need very little fuel, we just must accept that cars move slightly slower than we could walk. ChrisA -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Fortran (Was: The does Python have variables? debate)
In article lkoi5v$vfj$1...@speranza.aioe.org, Mark H Harris harrismh...@gmail.com wrote: On 5/11/14 1:59 PM, Chris Angelico wrote: julia prec=524288 524288 julia with_bigfloat_precision(prec) do println(atan(BigFloat(1)/5)*16 - atan(BigFloat(1)/239)*4) end Would it be quicker (and no less accurate) to represent pi as atan(BigFloat(1))*4 instead? That's how I originally met a pi-calculation (as opposed to PI = 3.14 extended to however much accuracy someone cared to do). No. Simple experiment will show you. The atan(x=1) will converge faster. For 524288 bits atan(1) formula converged in 3 seconds, and Machin's formula atan(x1) converged in 2 seconds. Where it becomes very apparent is 10K and 100K or above. Also, the difference is much more noticeable in Python than in Julia, but it is there no-the-less. But here is the cool part: what if your Ï function could be broken down into three very fast converging atan(x1) functions like this one: pi = 24*atan(1/8) + 8*atan(1/57) + 4*atan(1/239)(Shanks used this) ... and then, you have julia send each piece to a separate processor|core (it does this at its center) and they converge together, then julia pieces them together at the end. Then things get incredibly faster. I know now how to interpret your posts. Using incredible for a mere factor of at most 3. Balanced views are more convincing. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Fortran
In article 8761l9pi3n@elektro.pacujo.net, Marko Rauhamaa ma...@pacujo.net wrote: SNIP Producing an effective JIT for Python seems like a formidable challenge but not impossible in principle. After all, the developer *could* provide that static typing information in, like, 99.9% of the code. That would be feat worthy of a Millennium Technology Prize. It would be like having the cake and eating it, too. I'm totally flabbergasted by comments like this. I always thought that the real point of JIT was that it can take advantage of type information that is not available until runtime. If it can infer that something is an integer, just before entering a loop to be executed millions of times, that should be a big win, not? Marko -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP 8 : Maximum line Length :
In article mailman.10041.1400164039.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Fri, May 16, 2014 at 12:17 AM, wxjmfa...@gmail.com wrote: One another trick is to drop spaces around keywords 9and 12345or 99if 'a'in'a' else or 77 12345 and pray, the tools from those who are wasting their time in writing code analyzers or syntax colorizers or doc strings collectors or ... are finally working. Depending of the tools the interpretation may vary, but definitely all are producing erroneous results. Yes. Another very effective way to get your code below 80 characters is to shorten all names to a single letter. Since you don't need to restrict yourself to monocase Roman letters (as I had to in my earliest programming days, in BASIC), it's actually quite practical to uniquely name everything in a single character; you could save enormous amounts of horizontal space. Then, aggressively import as to do the same with remote symbols (you might need two characters for those), and you'll be able to write everything in just a few tight symbols! That may be tong-in-cheek but mathematicians do exactly that. We use roman, greek and hebrew alphabets in normal italics and boldface and then some special characters for element-of, logical-or, integral signs, triangles and what not. Underbarred and upper twiggled, as a suffix a prefix or a superfix. All in the name of avoiding names longer than one character. When we run out then there are creative ways to combine known characters into Jacobi symbols and choose functions. There are even conventions that allow to leave out characters, like juxtaposition means multiplication and the Einstein summation convention. You have to invest but terseness pays off. Now translate E=mc^2 into Java. ChrisA -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Help with changes in traceback stack from Python 2.7 to Python 3.x
In article mailman.9537.1398635527.18130.python-l...@python.org, Andrew Konstantaras akon...@icloud.com wrote: -=-=-=-=-=- I guess I am missing something big as I am looking for a shorthand way of doing the following: dctA = dict(x=x, y=y, ... n=n) This is, as I understand it a very natural way of using a dictionary. It seems that this syntax is unnecessarily redundant and hence my goal of writing something more compact. Perhaps the way I am doing it is a little unorthodox, but the ultimate use of a dictionary is, as I understand it, completely in line with how dictionaries were designed to be used. In my other code, I often use these dictionaries to pass arguments to functions and return results. It allows me great flexibility without breaking existing code. I pack a dictionary before passing and unpack when retrieving. Okay very well. I suggest you use the m4 preprocessor. This will allow you to get a maximum of compactness without compromising the Python language. Implementations of it are available on MS-Windows too. I will give the locals approach a try, it seems a little more clumsy than simply passing the variables to the function. Thanks again for your input. ---Andrew SNIP Was that top posting? Too late I snipped it already Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Values and objects
In article 536decca$0$29980$c3e8da3$54964...@news.astraweb.com, SNIP Personally, I don't imagine that there ever could be a language where variables were first class values *exactly* the same as ints, strings, floats etc. Otherwise, how could you tell the difference between a function which operated on the variable itself, and one which operated on the value contained by the value? The best you can do is for variables to be second class -- you can do these things to them, but you need special syntax or declarations to tell the compiler you're operating on the variable rather than the variable's value. E.g. Pascal and Algol have syntax for instructing the compiler when to pass a variable as a value, and when to pass the value. C gives you nothing. You're talking about Algol, but there is a great distinction between Algol60 and Algol68. Algol68 through the ref keyword goes a long way towards making variables first class citizens. E.g. although `` int i'' in Algol68 means practically the same as in C, it is defined as being an abbreviation of 'ref' 'int' i = 'loc' 'int'; This means so much that i is a reference to an otherwise unnamed int that is allocated locally. Furthermore you can't break the tie between i and that int (because you use =, you could have used := ) Because I refers to that location you can change it by i:=1; Note that the left side *must* be a reference. You can't change an int, you can only change the content of a memory place you can refer to. Now you can define 'ref' 'int' pi; pi := i; van Wijngaarden and crue pretty much nailed it, IMO. SNIP -- Steven D'Aprano http://import-that.dreamwidth.org/ Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP 8 : Maximum line Length :
In article a3253d6a-ef89-49d5-b866-8c06a7462...@googlegroups.com, Rustom Mody rustompm...@gmail.com wrote: On Tuesday, May 13, 2014 12:37:24 PM UTC+5:30, Ganesh Pal wrote: Hi Team , what would be the best way to intent the below line . I have few lines in my program exceeding the allowed maximum line Length of 79./80 characters Example 1 : p = Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) First rule of python-list: Pay careful attention to Peter Otten. That said... 80-character limit?! Sheesh! A relic of the days when terminals were ASCII and 80x24 80 character was the hard limit. The soft limit for readability is 60..65 characters. Think about it. Just that a language accepts #define MASK_SEPIA_INTERNAL_BLEEDING_WASHINGTON_DC_BLACK 0x147800fa means that it is a good idea to do so. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: How can this assert() ever trigger?
In article mailman.9917.1399914607.18130.python-l...@python.org, Joseph Martinot-Lagarde joseph.martinot-laga...@m4x.org wrote: Le 10/05/2014 17:24, Albert van der Horst a écrit : I have the following code for calculating the determinant of a matrix. It works inasfar that it gives the same result as an octave program on a same matrix. / def determinant( mat ): .. result = lastr[jx] assert(result0.) ... assert(result0.) nom *= result # Compenstate for multiplying a row. ... assert(nom0.) .. /- Now on some matrices the assert triggers, meaning that nom is zero. How can that ever happen? mon start out as 1. and gets multiplied with a number that is asserted to be not zero. Any hints appreciated. Groetjes Albert I know it's not the question, but if you want a replacement for octave did you try numpy (and scipy) ? The determinant would be computer faster and with less memory than with your function. I'm using several programming languages in a mix to solve Euler problems. This is about learning how octave compares to python for a certain kind of problem as anything. The determinant program I had lying around, but it was infinite precision with integer only arithmetic. Then I made a simple modification and got mad because I didn't understand why it didn't work. I have used numpy and its det before, but I find it difficult to remember how to create a matrix in numpy. This is the kind of thing that is hard to find in the docs. Now I looked it up in my old programs: you start a matrix with the zeroes() function. I expect the built in determinant of octave to be on a par with corresponding python libraries. --- Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
How can this assert() ever trigger?
I have the following code for calculating the determinant of a matrix. It works inasfar that it gives the same result as an octave program on a same matrix. / def determinant( mat ): ''' Return the determinant of the n by n matrix mat i row j column Destroys mat ! ''' #print getting determinat of, mat n=len(mat) nom = 1. if n == 1: return mat[0][0] lastr = mat.pop() jx=-1 for j in xrange(n): if lastr[j]: jx=j break if jx==-1: return 0. result = lastr[jx] assert(result0.) # Make column jx zero by subtracting a multiple of the last row. for i in xrange(n-1): pivot = mat[i][jx] if 0. == pivot: continue assert(result0.) nom *= result # Compenstate for multiplying a row. for j in xrange(n): mat[i][j] *= result for j in xrange(n): mat[i][j] -= pivot*lastr[j] # Remove colunm jx for i in xrange(n-1): x= mat[i].pop(jx) assert( x==0 ) if (n-1+jx)%20: result = -result det = determinant( mat ) assert(nom0.) return result*det/nom /- Now on some matrices the assert triggers, meaning that nom is zero. How can that ever happen? mon start out as 1. and gets multiplied with a number that is asserted to be not zero. Any hints appreciated. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: How can this assert() ever trigger?
In article 874n0xvd85@dpt-info.u-strasbg.fr, Alain Ketterlin al...@dpt-info.u-strasbg.fr wrote: alb...@spenarnc.xs4all.nl (Albert van der Horst) writes: [...] Now on some matrices the assert triggers, meaning that nom is zero. How can that ever happen? mon start out as 1. and gets multiplied [several times] with a number that is asserted to be not zero. Finite precision. Try: 1.*1e-162*1e-162. Equals zero. -- Alain. Thanks you Alan and all others to point this out. That was indeed the problem. Somehow I expected that floating underflow would raise an exception, so I had a blind spot there. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about Source Control
In article mailman.8270.1395195147.18130.python-l...@python.org, Tim Chase python.l...@tim.thechases.com 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about Source Control
In article bp17s6fbs1...@mid.individual.net, Gregory Ewing greg.ew...@canterbury.ac.nz 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: intersection, union, difference, symmetric difference for dictionaries
In article G57Pu.24239$th2.4...@tornado.fastwebnet.it, mauro ma...@gmail.com 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Can global variable be passed into Python function?
In article 87sir2et1d@elektro.pacujo.net, Marko Rauhamaa ma...@pacujo.net wrote: Mark Lawrence breamore...@yahoo.co.uk: 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Import order question
In article le108a$oip$1...@dont-email.me, Rotwang sg...@hotmail.co.uk 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 Ctrl-fclass seqReturndef edit(Return 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Python programming
In article roy-a94c1b.22041912022...@news.panix.com, Roy Smith r...@panix.com wrote: In article ldhcau$d9v$1...@reader1.panix.com, Grant Edwards invalid@invalid.invalid wrote: On 2014-02-13, Dennis Lee Bieber wlfr...@ix.netcom.com 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with the set of real numbers (was: Finding size of Variable)
In article mailman.7702.1393932047.18130.python-l...@python.org, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Mar 3, 2014 at 11:35 PM, Chris Angelico ros...@gmail.com 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with the set of real numbers (was: Finding size of Variable)
In article mailman.7687.1393902132.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Tue, Mar 4, 2014 at 1:45 PM, Albert van der Horst alb...@spenarnc.xs4all.nl 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with the set of real numbers
In article 87fvnm7q1n@elektro.pacujo.net, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: On Fri, Feb 14, 2014 at 1:00 AM, Marko Rauhamaa ma...@pacujo.net 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with the set of real numbers (was: Finding size of Variable)
In article mailman.6735.1392194885.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Wed, Feb 12, 2014 at 7:17 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: Chris Angelico ros...@gmail.com 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 pyshell#1, line 1, in module float(pi) ValueError: could not convert string to float: 'pi' float(Ï) Traceback (most recent call last): File pyshell#2, line 1, in module 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 URL:http://docs.python.org/2/library/numbers.html#numbers.Real 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@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Sharing Python installation between architectures
In article mailman.2687.1384556852.18130.python-l...@python.org, Paul Smith p...@mad-scientist.net wrote: One thing I always liked about Perl was the way you can create a single installation directory which can be shared between archictures. Say what you will about the language: the Porters have an enormous amount of experience and expertise producing portable and flexible interpreter installations. By this I mean, basically, multiple architectures (Linux, Solaris, MacOSX, even Windows) sharing the same $prefix/lib/python2.7 directory. The large majority of the contents there are completely portable across architectures (aren't they?) so why should I have to duplicate many megabytes worth of files? The solution is of course to replace all duplicates by hard links. A tool for this is useful in a lot of other circumstances too. In a re-installation of the whole or parts, the hard links will be removed, and the actual files are only removed if they aren't needed for any of the installations, so this is transparent for reinstallation. After a lot of reinstallation you want to run the tool again. This is of course only possible on real file systems (probably not on FAT), but your files reside on a server, so chances are they are on a real file system. (The above is partly in jest. It is a real solution to storage problems, but storage problems are unheard of in these days of Tera byte disks. It doesn't help with the clutter, which was probably the main motivation.) Symbolic links are not as transparent, but they may work very well too. Have the common part set apart and replace everything else by symbolic links. There is always one more way to skin a cat. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Unlimited canvas painting program
In article mailman.1477.1382644948.18130.python-l...@python.org, MRAB python-list@python.org wrote: On 24/10/2013 20:32, markot...@gmail.com wrote: So, i`ll take the canvas, somekind of mouse tracker, for each mouse location il draw a dot or 2X2 square or something. Main thing i have never understood, is how can i get the backround to move. Lets say ia hve 200X200 window. In the middle of it is the cursor that draws. If i move the mouse the cursor doesent move, but the canvas moves. So if i move mouse to the left, i get a line that goes to the left. So i probably must invert the canvas movement. If mouse goes left, canvas goes right. And if possible i would like to save my piece of art aswell :D I think it'll be confusing because it goes against how every other program does it! In a painting program you can point to other things, such as tools, but if the cursor never moves... It would be simpler, IMHO, if you just moved the canvas and stopped the cursor going off the canvas when the user is drawing near the edge, so that the user doesn't need to stop drawing in order to expose more of the canvas. A trick that is used in the editor I'm currently using is to do normal cursor movement, until you are within a certain range from the border. At that point you move the window over the canvas in order to keep the cursor in the middle part of the canvas. This can be done in discrete steps, and is not too disruptive. Even if you do it continuously, it is more intuitive (but functionally equivalent to) keeping the cursor in the middle. A problem that remains is that a mouse is not intended for an infinite canvas. At some point you will have to lift it and place it back on the pad. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Front-end to GCC
In article mailman.1362.1382460759.18130.python-l...@python.org, Chris Kaynor ckay...@zindagigames.com wrote: -=-=-=-=-=- SNIP Global: int arr[10]; int main() { int i; for (i = 0; i 10; i++) { printf(arr[%d] = %d\n, i, arr[i]); } printf(\n); return 0; } As for a reference: http://stackoverflow.com/questions/1831290/static-variable-initialization and http://stackoverflow.com/questions/3373108/why-are-static-variables-auto-initialized-to-zero, both of which then reference the C++ standard. Or even better: #includestdio.h int arr[] = {1,2,3,4,5,6,7,8}; int main() { int i; for (i = 0; i sizeof(arr)/sizeof(int); i++) { printf(arr[%d] = %d\n, i, arr[i]); } printf(\n); return 0; } Output: albert@cherry:/tmp$ a.out arr[0] = 1 arr[1] = 2 arr[2] = 3 arr[3] = 4 arr[4] = 5 arr[5] = 6 arr[6] = 7 arr[7] = 8 This is the output of objdump -x a.out (after stripping) a.out: file format elf64-x86-64 a.out architecture: i386:x86-64, flags 0x0112: EXEC_P, HAS_SYMS, D_PAGED start address 0x00400450 Lots of segments. 23 .got.plt 0030 00600900 00600900 0900 2**3 CONTENTS, ALLOC, LOAD, DATA 24 .data 0040 00600940 00600940 0940 2**5 CONTENTS, ALLOC, LOAD, DATA 25 .bss 0010 00600980 00600980 0980 2**3 ALLOC 26 .comment 001c 0980 2**0 CONTENTS, READONLY SYMBOL TABLE: no symbols Look at .data It is CONTENTS LOAD DATA, i.e. it has content in the executable binary and this is loaded as such into memory at startup. You can also ask to dump the content of the sections: objdump -s a.out a.out: file format elf64-x86-64 ... Contents of section .data: 600940 600950 600960 0100 0200 0300 0400 600970 0500 0600 0700 0800 Contents of section .comment: 4743433a 20284465 6269616e 20342e34 GCC: (Debian 4.4 0010 2e352d38 2920342e 342e3500 .5-8) 4.4.5. -- Steven -- https://mail.python.org/mailman/listinfo/python-list -=-=-=-=-=- [Alternative: text/html] -=-=-=-=-=- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Error Testing
In article mailman.1272.1382221693.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Sun, Oct 20, 2013 at 3:22 AM, rusi rustompm...@gmail.com wrote: The problem is that python is an imperative language and uses the '=' sign for assignment. In math of course '=' stands for equality. Pascal tried to create a new operator, := to be read becomes, to deal with the whole equality-vs-assignment issue. Did it really help anything? I don't think so. Just syntactic salt. Even the comparison isn't really mathematical - in maths, x = y is a statement of truth, whereas in programming, it's a question (is x equal to y). This suggests that Pascal went against established practice. This is false. FORTRAN used = and that was a mistake caused by the language being hacked together haphazardly. Langages that where designed (ALGOL60 SIMULA ALGOL68 Pascal ADA) all use :=. C C++ Java C# use = for assignment because of the inertia caused by FORTRAN. Pascal was created in a culture where it using = would be unexpected. Knuth uses k-n exactly because k=n would cause confusion. The equivalent of the dreaded if ( x=getch()) { } is possible in ALGOL68 too. It is not likely to be misunderstood because of the use of :=. By the way, it is about the only thing that I think is wrong in Python. ChrisA Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list
Re: Prime number generator
In article mailman.4522.1373464867.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: And now for something completely different. I knocked together a prime number generator, just for the fun of it, that works like a Sieve of Eratosthenes but unbounded. It keeps track of all known primes and the next composite that it will produce - for instance, after yielding 13, the prime map will be {2: 20, 3: 18, 5: 20, 7: 21, 11: 22, 13: 26}, each one mapped to the first multiple greater than 13. Notable in the algorithm is an entire lack of division, or even multiplication. Everything is done with addition. So, a few questions. Firstly, is there a stdlib way to find the key with the lowest corresponding value? In the above map, it would return 3, because 18 is the lowest value in the list. I want to do this with a single pass over the dictionary. Secondly, can the while ismallest... i+=1 loop become a for...range? It's almost asking for it, but not quite there. Thirdly, is there any sort of half-sane benchmark that I can compare this code to? And finally, whose wheel did I reinvent here? What name would this algorithm have? Notice that all values from i on are possibly present. So you are better off with a list indexed by forthcoming i's and each item containing a list of primes. What you do then, more or less, is keep track of all dividers of primes to be. This promises to be reasonable efficient. I've done a similar thing in Forth. I've also done a slightly different but related parallel program on a multi-processor Forth machine where each processor takes care of one prime. There is an unpleasant fact about this kind of generators. If you want to go unbounded, you've no choice but remember all primes. If you go bounded, you need to remember 168 up til 1M, say sqrt(limit)/log(limit). This dramatic difference (and the lack of processors) leads one quickly to decide for some upper bound. Code tested on Python 3.3, would probably run fine on pretty much any Python that supports yield, though I don't have a Py2.2 to test from __future__ import generators on! I had problems with the print statement on a 2 version, fixed easy enough. ChrisA # -- start -- def primes(): Generate an infinite series of prime numbers. i=2 yield 2 prime={2:2} # Map a prime number to its next composite (but bootstrap with 2:2) while True: # Find the smallest value in prime[] and its key. # Is there a standard library way to do this?? # (If two values are equal smallest, either can be returned.) prm=None for p,val in prime.items(): if prm is None or valsmallest: prm,smallest=p,val prime[prm]+=prm while ismallest: yield i prime[i]=i+i i+=1 if i==smallest: i+=1 gen=primes() for i in range(30): print(next(gen),end=\t) # Star Trek? print() # -- end -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Understanding other people's code
In article b023f6e6-a11d-4d05-a126-e3cc49cb3...@googlegroups.com, Azureaus lo0...@my.bristol.ac.uk wrote: On Friday, 12 July 2013 15:22:59 UTC+1, Azureaus wrote: SNIP To be fair to who programmed it, most functions are commented and I can't complain about the messiness of the code, It's actually very tidy. (I suppose Python forcing it's formatting is another reason it's an easily readable language!) Luckily not blanked import * were used otherwise I really would be up the creek without a paddle. If the code is really tidy, it is possible to understand a function using only the *documentation* (not the code itself) of any function or data it uses. In oo you also need a context about what an object is supposed to do. The next step is to proof for yourself that the function exactly does what is promised in its own documentation. And you get nowhere without domain knowledge. If you're in railways and don't know the difference between a normal and an English whathaveyou, then you're lost, plain and simple. Don't treat the original comment as sacred. Any time it is unclear rewrite it. You may get it wrong, but that's wat source control systems are for. If at all possible, if you add a statement about a function, try to add a test that proves that statement. Anytime you come across something that is unsufficiently documented, you document it tentatively yourself, keeping in mind that what you write down may be wrong. This does no harm! Because you must keep in mind that everything written by the original programmer may be wrong, there is actually no difference! Now study the places where it is called and check whether it makes sense. This an infinite process. After one round of improvements you have to go through everything again. I've got pretty bad stuff under control this way. You'll find bugs this way. They may or may not let you fix them. There is however not much point in working in by reading through the code. Time is probably better spent by running and studying, maybe creating test cases. Trying to understand any substantial code body in detail is a waste of time. For example: I once had to change the call code of the gcc compiler to be able to use a 68000 assembler library (regarding which register contain what data passed to the function). There is absolutely no point in studying the gcc compiler. You must have an overview then zoom in on the relevant part. In the end maybe only a couple of lines need change. A couple of days, and a pretty hairy problem was solved. (The assembler library was totally undocumented. Nobody even tried to study it. ). There is an indication that the original programmer made it all very easy and maybe you go about it not quite the right way. If you have a tower of abstractions, then you must *not* go down all the way to find out eactly what happens. You must pick a level in the middle and understand it in terms of usage, then understand what is on top of that in terms of that usage. That is how good programmers build there programs. Once there is a certain level they don't think about what's underneath, but concentrate on how to use it. If it is done really well, each source module can be understood on its own. All this is of course general, not just for Python. Thanks! -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Homework help requested (not what you think!)
In article mailman.4786.1374021635.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Wed, Jul 17, 2013 at 8:43 AM, John Ladasky john_lada...@sbcglobal.net wrote: I think that they're disappointed when I show them how much they have to understand just to write a program that plays Tic Tac Toe. The disillusionment of every novice programmer, I think. It starts out as I want to learn programming and make a game. Real programming is more like I can automate mundane tasks, which doesn't sound half as exciting. But this is why I'm dubious of programming courses that actually try to hold onto the let's make a game concept, because the students are likely to get a bit of a let-down on realizing that it really doesn't work that easily (this is a two-week course, at the end of it I should have written the next insert name of popular game for all my friends). Now comes the Forth experience. I did the following experiment with a psychology student, who had never been exposed to computers and had no prior experience. He aquired a Jupiter Ace, which has Forth as a built in language. So his only exposure was to Forth. Now I started to teach him programming, using the cartoon book starting Forth. Once in a weeek we sat together and worked through some exercises. After 6 weeks he surprised me. He had programmed the game pong which is a simple table tennis like game, where you have to keep a ball in play. He never gave me a a chance to prevent him having a traumatic experience of failure by telling him that was not a task a novice should start. Or for that matter that such any real time programming requires considerable up front planning and design. [This was an adult, and at the time university students in the Netherlands were certified intelligent and skilled and disciplined in learning.] The lesson that is in there for you is to not hold your students back. They may surprise you! Groetjes Albert ChrisA -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Making safe file names
In article lvydneajg7lxnhtmnz2dnuvz_rkdn...@westnet.com.au, Neil Hodgson nhodg...@iinet.net.au wrote: Andrew Berg: This is not a Unicode issue since (modern) file systems will happily accept it. The issue is that certain characters (which are ASCII) are not allowed on some file systems: \ / : * ? | @ and the NUL character The first 9 are not allowed on NTFS, the @ is not allowed on ext3cow, and NUL and / are not allowed on pretty much any file system. Locale settings and encodings aside, these 11 characters will need to be escaped. There's also the Windows device name hole. There may be trouble with artists named 'COM4', 'CLOCK$', 'Con', or similar. http://support.microsoft.com/kb/74496 That applies to MS-DOS names. God forbid that this still holds on more modern Microsoft operating systems? http://en.wikipedia.org/wiki/Nul_%28band%29 Neil -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: The usage of -m option of python
In article mailman.3484.1363662214.2939.python-l...@python.org, Terry Reedy tjre...@udel.edu wrote: On 3/18/2013 5:17 PM, Peng Yu wrote: Hi, I don't quite understand how -m option is used. And it is difficult to search for -m in google. Could anybody provide me with an example on how to use this option? python -m test at a command line runs the regression tests in the test package python -m test -v test_difflib runs test.test_difflib in verbose mode. I get for both : /usr/bin/python: test is a package and cannot be directly executed. What gives? (Official stable Debian distribution. Python 2.7) -- Terry Jan Reedy Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: how to detect the character encoding in a web page ?
In article roy-df05da.11460324122...@news.panix.com, Roy Smith r...@panix.com wrote: In article rn%Bs.693798$nB6.605938@fx21.am4, Alister alister.w...@ntlworld.com wrote: Indeed due to the poor quality of most websites it is not possible to be 100% accurate for all sites. personally I would start by checking the doc type then the meta data as these should be quick correct, I then use chardectect only if these fail to provide any result. I agree that checking the metadata is the right thing to do. But, I wouldn't go so far as to assume it will always be correct. There's a lot of crap out there with perfectly formed metadata which just happens to be wrong. Although it pains me greatly to quote Ronald Reagan as a source of wisdom, I have to admit he got it right with Trust, but verify. It's Not surprisingly, as an actor, Reagan was as good as his script. This one he got from Stalin. the only way to survive in the unicode world. Write defensive code. Wrap try blocks around calls that might raise exceptions if the external data is borked w/r/t what the metadata claims it should be. The way to go, of course. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
In article 5006b48a$0$29978$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: SNIP. Even with a break, why bother continuing through the body of the function when you already have the result? When your calculation is done, it's done, just return for goodness sake. You wouldn't write a search that keeps going after you've found the value that you want, out of some misplaced sense that you have to look at every value. Why write code with unnecessary guard values and temporary variables out of a misplaced sense that functions must only have one exit? Example from recipee's: Stirr until the egg white is stiff. Alternative: Stirr egg white for half an hour, but if the egg white is stiff keep your spoon still. (Cooking is not my field of expertise, so the wording may not be quite appropriate. ) -- Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
In article oc-dnuqkg91pgpbnnz2dnuvz5vgdn...@giganews.com, Erik Max Francis m...@alcyone.com wrote: SNIP Anything's trivial to write down. Just say the number such that ... and you've written it down. Even numbers that aren't really numbers, such as transfinite cardinals! Now it isn't trivial to write down. It has been proven (of course in an anti-intuitionistic 1] , Cantor-universe) that there is always a larger cardinal, and that there is no consistent way to write them down. In other ways, you have to keep inventing new notations, hardly a trivial matter. See also Hofstaedter: Goedel, Escher, Bach. -- Erik Max Francis m...@alcyone.com http://www.alcyone.com/max/ Groetjes Albert 1] The likes of Brouwer found these silly exercises.) -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: code review
In article XnsA0927750022F4duncanbooth@127.0.0.1, Duncan Booth duncan.bo...@suttoncourtenay.org.uk wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Fri, 13 Jul 2012 12:30:47 +, Albert van der Horst wrote: The worst of is, of course, = for assignment instead of := . This is a convention that Python follows, to my dismay. *shrug* The worst is to use = for both equality and assignment, like some BASICs. At least Python does not allow assignment as an expression, so you can't make the typical C error of: if x = y: do_something() # oops meant x == y Technically of course Python doesn't have assignment, it just binds names. Albert raised the subject of Algol 68 which if I remember correctly used := for assignment and = to bind names (although unlike Python you couldn't then re-bind the name to another object in the same scope). Algol 68 is very particular about this indeed. For instance they have a whole theory behind real x; x := 17.; This is considered an abbreviation of ref real x = loc real; x:= 17; So x is a reference bound to a freshly generated local real. You see = and that means you can't ever break that relationship. On the left side of a := it is required to have a ref something. Because that generates a pretty clear context, you have considerable leeway on the right side, that is cast into the something. real x= 18.; x := 15.; is right out. If you want to rebind something you need a ref which is really a ref ref. Then you can only switch bindings between different types. So it is totally different from Python. I never thought about = in python to mean binding to set it apart from the Pascal := , instead of being a c-ism. Still my mathematical mind is bothered about the sequence ( legal in FORTRAN , C Python ) X = 1 separator X = 2 Groetjes Albert -- Duncan Booth http://kupuguy.blogspot.com Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
In article b2971c4d-0769-4d03-a7b6-c527629a8...@x39g2000yqx.googlegroups.com, Ranting Rick rantingrickjohn...@gmail.com wrote: We DON'T want Python to silently convert cost to a string. What we DO want is to force the author to use the str function thereby making the conversion explicit. We do want Python to silently convert cost to a string in the proper context. cost= 3.75 print( cost ) Same with converting objects to bools. I think if is sufficient context to convert something to a boolean. It now is a matter of good taste and what fits best in Python as a whole. Nothing to be dogmatic about. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Implicit conversion to boolean in if and while statements
In article 50038364$0$29995$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 15 Jul 2012 18:21:06 -0700, Ranting Rick wrote: If HOWEVER we want to truth test an object (as in: if obj) we should be FORCED to use the bool! Why? Because explicit is better than implicit And this is why Rick always writes code like: integer_value_three = int(1) + int(2) assert (int(integer_value_three) == \ int(3) is True) is True, str(arithmetic failed) list_containing_three_values_which_are_all_integers_but_might_later_have_more_or_fewer_values_or_other_types = list([1, 2, integer_value_three]) because you can never have too much explicitness. Who wouldn't want to read code like that? Java programmers? (Couldn't resist ;-) ) -- Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: code review
In article 4ff0f8e0$0$29988$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 01 Jul 2012 05:55:24 -0400, Terry Reedy wrote: On 7/1/2012 2:54 AM, Steven D'Aprano wrote: So no, Python has always included chained comparisons, and yes, it is shameful that a language would force you to unlearn standard notation in favour of a foolish consistency with other operators. Comparisons aren't special because they return bools. They are special because of the way they are used. C treats comparison operators as if they were arithmetic operators, and so the behaviour of a chained comparison is the same as the behaviour as a sequence of arithmetic operators: a foolish consistency. Python treats comparison operators as comparison operators, and gives them behaviour appropriate to comparisons. I considered this a great feature of Python when I first learned it. Reading about how rare it is among programming languages to treat comparisons in the standard way in mathematics reinforces that. Apart from Python, Mathematica, Perl 6, CoffeeScript, Cobra and Clay give chained comparisons the standard meaning. It is, or was, a feature request for Boo, but I can't tell whether it has been implemented or not. Algol 68 does not. It has promoted operator symbols to first class citizens. In that context chained comparison operators cannot be made to work. Both Mathematica and Perl are ad-hoc-ish languages. I would hate Python go that way. From now on, for each operator I would have to remember wether it is a supposedly comparison operator or not. Comparison operations on booleans make sense. I remember a FORTRAN compiler complaining about me comparing LOGICALS. The lack of abstraction! C-like semantics are next to useless, except perhaps for obfuscation: http://stackoverflow.com/questions/4089284/why-does-0-5-3-return-true/ And surprising: http://answers.yahoo.com/question/index?qid=20090923172909AA4O9Hx C-like semantics are a clear case of purity of implementation overruling functional usefulness. The worst of is, of course, = for assignment instead of := . This is a convention that Python follows, to my dismay. -- Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Using a CMS for small site?
In article pu28v7t3nstsamp9emp1781utck1mei...@4ax.com, Gilles nos...@nospam.com wrote: Hello Someone I know with no computer knowledge has a studio appartment to rent in Paris and spent four months building a small site in Joomla to find short-time renters. The site is just... - a few web pages that include text (in four languages) and pictures displayed in a Flash slide show - a calendar to show availability - a form to send e-mail with anti-SPAM support - (ASAP) online payment Out of curiosity, are there CMS/frameworks in Python that can do this? Django? Other? Is a full-fledged CMS even needed for something like that? Good old rcs would be fine. It is oldfashioned, so you need only 4 commands, compared to a bewildering display of icons. mkdir RCS ci * rcs -NSTABLE1: RCS/* Backup by tar cf /media/MYSTICK/project.tar RCS Thank you. -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)
In article jr4pcc$fl3$1...@dont-email.me, Kevin Walzer k...@codebykevin.com wrote: On 6/11/12 8:01 AM, Wolfgang Keller wrote: Tkinter is imho honestly the very best argument if you want to make potential new users turn their backs away from Python for good. Just show them one GUI implemented with it and, hey, wait, where are you running to... Yes, Tkinter GUI's are very ugly. http://www.codebykevin.com/phynchronicity-running.png I looked it up. What you find ugly, I find unconfusing and clear. If I compare it to usual on the web, it is the difference between a waterfall side and an airport where the personell is on strike. (Oh the noise, the noise is unbearable!). I have not, nor intend to write gui things in Python, I just give an impression. [ I want my gui's to be functional, not beautiful. ] http://www.codebykevin.com/quickwho-main.png -- Kevin Walzer Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: usenet reading
In article jqfjjc$f5s$1...@dont-email.me, Colin Higwell colinh@somewhere.invalid wrote: On Fri, 25 May 2012 15:38:55 -0700, Jon Clements wrote: Is there a server out there where I can get my news groups? I use to be with an ISP that hosted usenet servers, but alas, it's no longer around... I use Albasani.net (free and very reliable), as well as gmane.org. Google Groups is an abomination IMHO, and I find it much easier to read mailing lists via a newsreader. I highly recommend Pan, by the way. I still use UUCP. This machine is a UUCP node (spenarnc.xs4all.nl). I fetch my mail and news using a UUCP-feed (login over the internet with ADSL to a machine of xs4all). From that moment on it is a newsserver. I can access it from other machines on my network or I could make it available to friends over the internet. (Not that I plan to do that.) I can use any newsreader, and it is fast/instantaneous. Set this stuff up in 1994 with Coherent. Upgraded to Linux, and upgraded the hardware a couple of times. Running on a Pentium 120 Mhz now. I take it for granted but last time I heard, UUCP was down to less than a dozen users with this service. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
In article 7xwr3fjff8@ruckus.brouhaha.com, Paul Rubin no.email@nospam.invalid wrote: Matej Cepl mc...@redhat.com writes: The point is that you are never interested in learning *a language*, everybody who has at least some touch with programming can learn most languages in one session in the afternoon. Really, that's only if the new language is pretty much the same as the old ones, in which case you haven't really learned much of anything. Languages that use interesting new concepts are challenges in their own right. Here is an interesting exercise for statically typed languages, unsuitable for Python but not too hard in Haskell: http://blog.tmorris.net/understanding-practical-api-design-static-typing-and-functional-programming/ When I'm satisfied with a program, it has this ethereal property that if the problem is slightly altered, the program is only slightly altered. Case in point:going to incorporate the extra 8 register from 64 bit pentium into a pre-existing 32 bit Pentium assembler. (Which is a in fact a somewhat large messy change that would trigger a rewrite in most assemblers.) I much doubt if e.g. the whowonordraw gives a compile time error on a non-finished board, that the program can be robust against a small change of the rules. Say strikes going through the lower left square are not counted as a win. It is sooo bloody artifical. A normal requirement would be an API that gives on any tic-tac-toe board one of: Iwin, youwin, draw, not-finished. Then there are static typed languages like Forth where the programmer is the judge whether there is a type error, and type errors are not generated by the compiler. A much more natural api is where a board is an object. You can send a move message - accepted or nor You can send an inspect message - won lost draw or not-finished. I can make that totally robust without storing lost or draw information using the type system. He requires that on several calls, if the data is wrong, you get a compile time error. How could that be a reasonable demand from a language like Python where the call can be made interpretively? Of course it is an exercise. But I think that it went this way: 1. solve it in Haskell 2. require incidental and non-useful features of the solution to work in other languages the same way. If he is bashing Scrum, I'm bashing staic typing. It doesn't require the use of any libraries, standards, style, or culture. I can tell you as a fairly strong Python programemr who got interested in Haskell a few years ago, it took me much longer than an afternoon to get to the point of being able to solve a problem like the above. It required absorbing new concepts that Python simply does not contain. But it gave me the ability to do things I couldn't do before. That's a main reason studying new languages is challenging and worthwhile. I give you that. Mastering a functional language is a real step, but I don't think this tic-tac-toe exercise will entice me to do that. Maybe the solutions to http://projecteuler.net that are published in Haskell sometimes condensing a few pages of my sequential code in a few lines, will inspire me to take up Haskell. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: serial module
In article jp6gcj$1rij$1...@adenine.netfront.net, Ron Eggler rondotegg...@tscheemail.com wrote: Hoi, I'm trying to connect to a serial port and always get the error serial.serialutil.SerialException: Port is already open. whcih is untrue. I have no serial port open yet, my code looks like this: #!/usr/bin/python import time import serial # configure the serial connections (the parameters differs on the device # you are connecting to) ser = serial.Serial( port='/dev/ttyUSB0', baudrate=19200, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_TWO, bytesize=serial.SEVENBITS ) ser.open() Why do I get this error? You realize that these parameters relate to RS232 ports? It is anybody's guess what they do in USB. The best answers is probably that it depends on the whim of whoever implements the usb device. Certainly this stuff is system dependant, so please start with stating which version kernel etc. of Linux you run, and the output of lsusb --verbose. Thank you, Ron Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: why () is () and [] is [] work in other way?
In article 7xvckq4c2j@ruckus.brouhaha.com, Paul Rubin no.email@nospam.invalid wrote: Kiuhnm kiuhnm03.4t.yahoo.it writes: I can't think of a single case where 'is' is ill-defined. If I can't predict the output of print (20+30 is 30+20) # check whether addition is commutative print (20*30 is 30*20) # check whether multiplication is commutative by just reading the language definition and the code, I'd have to say is is ill-defined. The output depends whether the compiler is clever enough to realise that the outcome of the expressions is the same, such that only one object needs to be created. What is ill here is the users understanding of when it is appropriate to use is. Asking about identity of temporary objects fully under control of the compiler is just sick. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Gotcha's?
In article 4f7de152$0$29983$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 05 Apr 2012 08:32:10 -0400, Roy Smith wrote: In article 4f7d896f$0$29983$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: You mean JSON expects a string with valid JSON? Quelle surprise. No. The surprise is that there exists a tool invented in the 21st century that makes a distinction between strings quoted with and those quoted with '. Being used to a sensible language like Python, it boggled my brain the first time I tried to write some JSON and naturally treated the choice of quote mark as arbitrary. Your brain has a low boggle threshold. There's absolutely no reason why JSON should follow Python syntax rules. Except for the most important reason of all: Python's use of alternate string delimiters is an excellent design, one which Javascript itself follows. http://www.javascripter.net/faq/quotesin.htm I'm not the only one who has had trouble with JSON's poor design choice: http://stackoverflow.com/a/4612914 For a 21st century programming language or data format to accept only one type of quotation mark as string delimiter is rather like having a 21st century automobile with a hand crank to start the engine instead of an ignition. Even if there's a good reason for it (which I doubt), it's still surprising. Making it support either kind of quotes would have complicated every JSON library in the world, for no added value. Ooooh, such complication. I wish my software was that complicated. The added value includes: * semantic simplicity -- a string is a string, regardless of which quotes are used for delimiters; * reducing the number of escaped quotes needed; * compatibility with Javascript; * robustness. As it stands, JSON fails to live up to the Robustness principle and Postel's law: Be liberal in what you accept, and conservative in what you send. http://en.wikipedia.org/wiki/Robustness_principle Nobody should ever be hand-writing JSON So you say, but it is a fact that people do. And even if they don't hand- write it, people do *read* it, and allowing both quotation marks aids readability: \Help me Obiwan,\ she said, \You're my only hope!\ Blah. You can cut the number of escapes needed to one: 'Help me Obiwan, she said, You\'re my only hope!' I still think the doubling convention of Algol68 is superior: Help me Obiwan, she said, You're my only hope! No special treatment of any other symbol than the quote itself. A quoting symbol is such a devious syntactic element that I rather not have two ( ' ) or even three ( ' \ ) -- Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
In article mailman.896.1332440814.3037.python-l...@python.org, Nathan Rice nathan.alexander.r...@gmail.com wrote: http://www.joelonsoftware.com/articles/fog18.html I read that article a long time ago, it was bullshit then, it is bullshit now. The only thing he gets right is that the Shannon information of a uniquely specified program is proportional to the code that would be required to generate it. Never mind that if a Thank you for drawing my attention to that article. It attacks the humbug software architects. Are you one of them? I really liked that article. program meets a specification, you shouldn't care about any of the values used for unspecified parts of the program. If you care about the values, they should be specified. So, if Joel had said that the program was uniquely specified, or that none of the things that weren't specified require values in the programming language, he might have been kinda, sorta right. Of course, nobody cares enough to specify every last bit of minutiae in a program, and specifications change, so it is pretty much impossible to imagine either case ever actually occurring. I wonder if you're not talking about a different article. SNIP Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is readable
In article mailman.795.1332131633.3037.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Mon, Mar 19, 2012 at 12:23 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 19 Mar 2012 09:02:06 +1100, Chris Angelico wrote: On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky lada...@my-deja.com wrote: What I would say is that, when PROGRAMMERS look at Python code for the first time, they will understand what it does more readily than they would understand other unfamiliar programming languages. =A0That has value. This is something that's never truly defined. I'm sorry, I don't understand what part of John's sentence you mean by this. Programmers? Value? Understand? I should have rewritten that into the next paragraph. Anyhow. Further explanation below. Everyone talks of how this language or that language is readable, but if you mean that you can look at a line of code and know what *that line* does then Python suffers badly and assembly language wins out; This is at least the second time you've alleged that assembly language is more readable than Python. I think you're a raving nutter, no offence Chris :-) None taken; guilty as charged. And unashamedly so. With that dealt with, though: My calling assembly readable is a form of argument by drawing to logical, but absurd, conclusion - by the given definition of readability, assembly is readable, ergo the definition sucks. (That's a term all logicians use, you know. Proper and formal jargon.) Assignment (name binding) is close to the absolute simplest thing you can do in a programming language. In Python, the syntax is intuitive to anyone who has gone through high school, or possibly even primary school, and been introduced to the equals sign. x =3D 1234 y =3D Hello Not quite. In mathematics, x =3D 1234 is either a declaration of fact, or a statement that can be either true or false. In mathematics, x =3D x + 1 is absurd and/or simply false. That's why Pascal has its :=3D operator, supposed to be read as becomes and not equals. IMHO this is simply proof of one of the differences between programming and mathematics. I don't know about anyone else, but I wouldn't have guessed that the way to get x=3D1234 was with x dw 1234. Except that it's not quite the same thing. That 8086 Assembly statement is more like the C statement: int x=3D1234; The nearest equivalent of assignment is: mov x,1234 I tried to mentally translate that to my ciasdis assembler syntax and discovered that there is no instruction in the 8086 for that. It would require using a scratch register like AX. In my very precise ciasdis assembler syntax it would be 1] XX: DL 0 MOVI, X| R| AX| 1234 IL, MOV, X| F| R| [AX] XX L, If you were restricted to the 8086, (not 80386 or better) you could not have chosen AX, and you would have used BX instead. [ The first MOVI, could be replaced by a LEA, instruction LEA, AX'| MEM| XX L, (Go figure!) ] So a realistic fragment could have been PUSH|X BX, MOVI, X| R| BX| 1234 IL,, MOV, X| F| R| [BX] XX L, POP|X BX, The real unreadability comes from the fact that the novice would ask herself why on earth the BX register was freed while the AX register was free to use. And she is lucky, because no flags were harmed in this sequence, another pitfall. You can't blame me for the unreadibility of the ciasdis-syntax. It merely reflects the abomination that the 8086/80386/Pentium is. Bottom line. A comparison between a HLL where the goal is abstraction and assembly where the goal is precision and control, is unproductive. And if you insist to do it, you better be a real expert. SNIP And that's where the nub of the question is. How well is sufficiently well? Clearly you do not require your code to be comprehensible to a non-programmer, or you would not write code at all. If you don't demand that the reader learn basic keywords of the language, then it's equally impossible to expect them to comprehend your code. If you're writing production code, I see no reason to avoid language features like Python's list comps, Pike's %{ %} sprintf codes, or C's pointer arithmetic, just because they can confuse people. Learn the language, THEN start hacking on the code. Can we just agree, that it is a compromise? ChrisA 1] ciasdis.html on the site in my sig. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct
In article 4f654042$0$29981$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sat, 17 Mar 2012 17:28:38 -0600, Michael Torrie wrote: Thank you. Your example makes more clear your assertion about labels and how really A1 and A5 were the only real labels in the example. Though I still do not really see why states is not a good equivalence for labels in this case. Program labels are states. You can treat every line of code as being invisibly labelled with the line number. (Or visibly, if you are using BASIC back in 1975.) Clearly the interpreter is executing at line 42 is a state distinct from the interpreter is executing line 23, but that state *alone* is not sufficient to know the overall state of the program. This is the idea of the original (not universal, hard coded) Turing machine with cards. Of course you then still need the infinite tape to store calculation input and output. Adding an explicit GOTO label does not change this. But this refers to the state of the interpreter, not the state of the program being executed, and either way, is not a state in the sense of a finite state machine. I hope the reference to the Turing machine makes this clearer. Turing Machines and Finite State Machines are different constructions in automaton theory. Remember those definitions are like A Turing machine is a set S, T, F, G, Q S the set of symbols blank, 0, 1 T a mapping of S onto IZ (natural numbers) ... F is a mapping from SxT into G .. Some such. (A FSM is just different A,B,C..Z with different mappings ) The memory of the Turing machine is T , the tape, time dependant. The program of the Turing is e.g. F, to be thought of as hard wiring. A Turing machine is *not* a stored program computer! The universal Turing machine is, it contains a hardwired program to execute a stored program on the tape. -- Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct
In article gR09r.22645$i33.16...@uutiset.elisa.fi, Antti J Ylikoski antti.yliko...@tkk.fi wrote: In his legendary book series The Art of Computer Programming, Professor Donald E. Knuth presents many of his algorithms in the form that they have been divided in several individual phases, with instructions to GOTO to another phase interspersed in the text of the individual phases. I. e. they look like the following, purely invented, example: (Knuth is being clearer than me below.) A1. (Do the work of Phase A1.) If zap then go to Phase A5, otherwise continue. A2. (Do some work.) If zorp go to Phase A4. A3. (Some more work.) A4. (Do something.) If condition ZZZ go to Phase A1. A5. (Something more). If foobar then go to Phase A2, otherwise end. I can rewrite this into Python in my sleep, without resorting to formal techniques. Instead try one of the harder algorithms like T (Toom Cook) that must be translated to recursive functions that pass data down. That took me quite a wile. The correct answer is, it is just labour. Deal with it. Note that if you want to translate it to assembler, it is relatively easy. SNIP kind regards, Antti J Ylikoski Helsinki, Finland, the EU Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: are int, float, long, double, side-effects of computer engineering?
In article 5aaded58-af09-41dc-9afd-56d7b7ced...@d7g2000pbl.googlegroups.com, Xah Lee xah...@gmail.com wrote: SNIP what i meant to point out is that Mathematica deals with numbers at a high-level human way. That is, one doesn't think in terms of float, long, int, double. These words are never mentioned. Instead, you have concepts of machine precision, accuracy. The lang automatically handle the translation to hardware, and invoking exact value or infinite precision as required or requested. With e.g. a vanderMonde matrix you can easily make Mathematica fail. If you don't understand what a condition number is, you can't use Mathematica. And yes condition numbers are fully in the realm of concepts of machine precisions and accuracy. Infinite precision takes infinite time. Approaching infinite precious may take exponentional time. Xah Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!
In article 0078bbfb-5dfc-48fc-af1a-69de3cf15...@b1g2000yqb.googlegroups.com, Xah Lee xah...@gmail.com wrote: New Science Discovery: Perl Idiots Remain Idiots After A Decade! A excerpt from the new book =E3=80=88Modern Perl=E3=80=89, just published, = chapter 4 on =E2=80=9COperators=E2=80=9D. Quote: =C2=ABThe associativity of an operator governs whether it evaluates from left to right or right to left. Addition is left associative, such that 2 + 3 + 4 evaluates 2 + 3 first, then adds 4 to the result. Exponentiation is right associative, such that 2 ** 3 ** 4 evaluates 3 ** 4 first, then raises 2 to the 81st power. =C2=BB LOL. Looks like the perl folks haven't changed. Fundamentals of serious math got botched so badly. You're confused. Associativity of operators is defined in mathematics. (The same concept may be used in programming). left-associativity and right-associativity are computer languages concept and their definitions are not from mathematics. Interestingly in mathematics associative means that it doesn't matter whether you use (a.b).c or a.(b.c). Using xxx-associativity to indicate that it *does* matter is a bit perverse, but the Perl people are not to blame if they use a term in their usual sense. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!
In article 4f5df4b3$0$1375$4fafb...@reader1.news.tin.it, Kiuhnm kiuhnm03.4t.yahoo.it wrote: On 3/12/2012 12:27, Albert van der Horst wrote: Interestingly in mathematics associative means that it doesn't matter whether you use (a.b).c or a.(b.c). Using xxx-associativity to indicate that it *does* matter is a bit perverse, but the Perl people are not to blame if they use a term in their usual sense. You may see it this way: Def1. An operator +:SxS-S is left-associative iff a+b+c = (a+b)+c for all a,b,c in S. Def2. An operator +:SxS-S is right-associative iff a+b+c = a+(b+c) for all a,b,c in S. Def3. An operator +:SxS-S is associative iff it is both left and right-associative. I know, but what the mathematicians do make so much more sense: (a+b)+c = a+(b+c)definition of associative. Henceforth we may leave out the brackets. Don't leave out the brackets if the operators if the operators is not associative. P.S. There is no need for the operators to be SxS-S. For example a b c may be m by n, n by l, l by k matrices respectively. Kiuhnm Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Numerical Linear Algebra in arbitrary precision
In article e6ca88fb-3fc7-47b6-b2f5-3c7ee8b65...@tc8g2000pbc.googlegroups.com, Ken ken.al...@sbcglobal.net wrote: Brand new Python user and a bit overwhelmed with the variety of packages available. Any recommendation for performing numerical linear algebra (specifically least squares and generalized least squares using QR or SVD) in arbitrary precision? I've been looking at mpmath but can't seem to find much info on built in functions except for LU decomposition/solve. Arbitrary precision? As in automatically increasing precision to stay exact? You will find this impractical as the number of decimals will explode, or you will find it not at all. If you mean that you want to be able to select something with larger precision than single or double floats, numpy is the starting point. Appreciate any comments. Ken Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: generate Windows exe on Linux
In article mailman.55.1329949521.3037.python-l...@python.org, Gelonida N gelon...@gmail.com wrote: On 02/22/2012 07:05 PM, Alec Taylor wrote: http://www.pyinstaller.org/ or http://cx-freeze.sourceforge.net/ You can also run py2exe in WINE You want to say, that I could install python 2.6 some packages like win32api PyQt and tand py2exe under Wine and then compile it. Did you try this? I didn't even think about trying this out, but I know very little about the limits of Wine, so perhaps I underestimate it. As a case in point I have this example of another language: colorforth. It was made by a genius inventor (Chuck Moore), and only runs from a boot-floppy and writes pixels to the screen. Someone made an environment in MS-Windows to emulate the booting process and all. This actually runs colorforth. Now about Wine, how good is it? Actually it is good enough to run the above emulator! (We run a third emulator, of the GA144, on top at a decent speed.) Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
In article c52c1114-647a-4887-926b-8856c939f...@b23g2000yqn.googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: On Feb 18, 1:28=A0am, Ian Kelly ian.g.ke...@gmail.com wrote: On Fri, Feb 17, 2012 at 6:13 PM, Rick Johnson If I were to [sum my tax burden], it would probably come to around 30%, which still doesn't bother me, in part because I know that it comes back to benefit the society I live in, and by extension me, in one way or another.. But do you think you'll get a higher return for your investment? Is it possible to get a higher return on your investment in this type of system? NO! You better off just paying for your own damn healthcare. Well actually, there is a way to get a higher return by taking more than your fair share. Any intelligent person would realize that public healthcare is advocated by degenerates or the bleeding heart degenerate eugenics supporters. Fine, YOU want to subsidize degeneracy? Then give to charity. The more you give the better you'll feel. BTW: How much money do you give to charity? This is technically wrong. It is much cheaper for you to pay a few euro's to combat TBC, then live in a TBC-infected society where you must take great care not to be infected yourself. Paying to rid the society of TBC is not charity, it is is common sense. Your ideas only work for the anti-social few, in an otherwise social society. Education is another case in point. It is in you best interest to allow a getto-genius into Harvard. Otherwise they will become the master-minds of crime. And you will be too stupid to beat them. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Entitlements [was Re: Python usage numbers]
In article 40af8461-1583-4496-9d81-d52d6905d...@b23g2000yqn.googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: Because the Jews allowed themselves to be subjected. Sad, but true. Actually Jew stands for (relative) coward. Let me explain. Jew comes from Juda, one of the 12 tribes. At some time Israel was subjected and 11 tribes resisted to the death and are eradicated since. Only the Juda tribe gave in and their land was called Judea since. (So the name Israel for the current state is a propagandistic lie, to claim the land once occupied by the 12 tribes.) I don't blame them for the attitude of live to fight another day or even for plain survival. If the Jews hadn't allow themselves to be subjected, there would be no Jews. Slaves only exist because they allow themselves to exist. When people Never been a slave, were you? Try to imagine what it is to be born a slave. Freedmmm! Live free, or die! From my cold dead hand! Over my dead body! Freedom is never voluntarily given by the oppressor; it must be demanded by the oppressed. Those who deny freedom to others deserve it not for themselves. Man is free at the moment he wishes to be. Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one. Black Panther comes to mind. The USA just killed them. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
In article c04d134f-5f90-4fe8-b3e6-b08c6a123...@d18g2000yql.googlegroups.com, DevPlayer devpla...@gmail.com wrote: I still assert that contradiction is caused by narrow perspective. By that I mean: just because an objects scope may not see a certain condition, doesn't mean that condition is non-existant. I also propose that just because something seems to contradict doesn't mean it is false. Take for instance: Look out your window. Is it daylight or night time? You may say it is daylight or you may say it is night time. I would disagree that only one of those conditions are true. Both conditions are true. Always. It is only day (or night) for YOU. But the opposite DOES in fact exist on the other side of the world at the same time. This is a far cry from the bible stating that someone is his own grand father. Or going to great length to prove that Jezus (through Jozef) is a descendant of David. Then declaring it a dogma that Jozef has nothing to do with it. (It being ... well ... you know ...) (I have this book, it is called the amusing bible with all flippant and contradictory stuff pointed out by a French 1930 communist. Cartoons too. ) Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Usefulness of the not in operator
In article qotr52nlji7@ruuvi.it.helsinki.fi, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: Mel writes: Steven D'Aprano wrote: candide wrote: So what is the usefulness of the not in operator ? Recall what Zen of Python tells There should be one-- and preferably only one --obvious way to do it. And not in is the obvious way to do it. If the key is not in the ignition, you won't be able to start the car. If not the key is in the ignition, you won't be able to start the car. Who like that second one speaks? :) If the key is not in the ignition, you will be able to start the car, not. Oh, be consistent. If not the key is in the ignition, not you will be able to start the car. But both negations can be avoided by modus tollens. If you are able to start the car, the key is in the ignition. This is not normal speach. The connotation of an if sentence is that the condition is something you have more control over than over the result. I sometime write if 0 == i : and get complaints, as if both sides of an identity are not equivalent. OTOH if i == j : and nobody cares it I wrote if j == i : And one could express x not in s as (x in s) implies False without making the not explicit if implies was in the language. (I know about = but I also witnessed an unpleasant thread in another newsgroup where people insisted that = should not be defined for truth values at all, and I also happen to like Python's not in.) Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article mailman.1286.1304760534.9059.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Sat, May 7, 2011 at 7:21 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Hans Georg Schaathun wrote: You cannot reference nor manipulate a reference in python, and that IMHO makes them more abstract. You can manipulate them just fine by moving them from one place to another: I think manipulate here means things like pointer arithmetic, which are perfectly normal and common in C and assembly, but not in languages where they're references. Adding an integer to a reference to an array element could have been perfectly well-defined in Algol: ref real operator+(ref real, int) That is called overloading of the plus operator not pointer arithmetic. It is a misconception that these manipulation are dirty or ill-defined or unsafe. A similar extension would be possible in Python. Allusion to assembler where one adds a number to a register and can't tell whether the register contains an address or data are misleading. [This is not to say that I think it is advisable]. Chris Angelico Groetjes Albert. -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: What other languages use the same data model as Python?
In article 4dc7fa2f$0$29991$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 09 May 2011 12:52:27 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: Since you haven't explained what you think is happening, I can only guess. Let me save you from guessing. I'm thinking of a piece of paper with a little box on it and the name 'a' written beside it. There is an arrow from that box to a bigger box. +-+ +---+ | | a | --+| | +---+ | | +-+ There is another little box labelled 'b'. After executing 'a = b', both little boxes have arrows pointing to the same big box. [...] In this model, a reference is an arrow. Manipulating references consists of rubbing out the arrows and redrawing them differently. All very good, but that's not what takes place at the level of Python code. It's all implementation. I think Hans Georg Schaathun made a good objection to the idea that Python has references: In Pascal a pointer is a distinct data type, and you can have variables of a given type or of type pointer to that given type. That makes the pointer a concrete concept defined by the language. The same can't be said of references in Python. It's not part of Python the language, although it might be part of Python's implementation. Also in this model, a variable is a little box. It's *not* the same thing as a name; a name is a label for a variable, not the variable itself. That's essentially the same model used when dealing with pointers. I've used it myself, programming in Pascal. The little box named a or b is the pointer variable, and the big box is the data that the pointer points to. It's not an awful model for Python: a name binding a = obj is equivalent to sticking a reference (a pointer?) in box a that points to obj. Certainly there are advantages to it. But one problem is, the model is ambiguous with b = a. You've drawn little boxes a and b both pointing to the big box (which I deleted for brevity). But surely, if a = 1234 creates a reference from a to the big box 1234, then b = a should create a reference from b to the box a? There are cleaner languages. Algol 68 , Forth. This is Forth. VARIABLE A VARIABLE B 1234 ( anonymous object created by the language ) A ! A @ B !( Copy the content, equivalent of B=A). Algol 68 B:=A compiler : THINK ! THINK ! A is a ref int so it can't be stored into b which is a ref int which is the name of a place where an int can be stored (not where a ref int could be stored.) Solution: Algol dereferences A into an int, by getting its content. But it is a rule, very explicitly explained in the language definition. (If you are that clean you can handle ref ref int q where q is the name of a place where a ref int can be stored.) real a is in fact an abbreviation of ref real a=loc real meaning a is a reference to a local real, that is anonymous. The = means that the connection between a and that real is an identity, i.e. the connection can't be broken. (Forget about C++, casting away const, yuck! ) In Forth and in Algol 68 storing a constant into a variable is very different from copying the content of a variable to some other variable. SNIP -- Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Python IDE/text-editor
In article mailman.511.1303137613.9059.python-l...@python.org, Alec Taylor alec.tayl...@gmail.com wrote: Geany I've tried in the past, it's really buggy on my home computer and at Uni... however from my phone it works wonderfully! (Use it for C++ projects on Rhobuntu) Eric 4 was suggested to me on the #python channel on Freenode... however I've never been able to get it compiled/working. Too many dependencies I'm guessing... PTK looks great, and does everything I want (from screenshots). Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1 x64, WxPython 2.8 x64. Install ran as admin. Emacs and vim still seem like good alternatives, when I get the time. However, currently have 3 assignments to start and finish so would like a simple Notepad2 with python interpreter attached (and keyboard shortcut to run script) type program. Please continue recommending Thanks, Alec Taylor You will never be satisfied, until you've written something yourself. Start writing now. A friend of mine started writing in 1983, and since 1985 I'm a happy user. The only language that is a candidate to write in is C, however. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Equivalent code to the bool() built-in function
In article iok5tg$svv$1...@reader1.panix.com, Grant Edwards invalid@invalid.invalid wrote: On Tue, Apr 19, 2011 at 7:09 AM, Christian Heimes li...@cheimes.de wrote: Am 18.04.2011 21:58, schrieb John Nagle: ?? ?? This is typical for languages which backed into a bool type, rather than having one designed in. ??The usual result is a boolean type with numerical semantics, like ?? True + True 2 I find the behavior rather useful. It allows multi-xor tests like: if a + b + c + d != 1: ?? ??raise ValueError(Exactly one of a, b, c or d must be true.) I guess I never thought about it, but there isn't an 'xor' operator to go along with 'or' and 'and'. Must not be something I need very often. There is. applied to booleans is xor. -- Grant Edwards grant.b.edwardsYow! I am having FUN... at I wonder if it's NET FUN or gmail.comGROSS FUN? -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Equivalent code to the bool() built-in function
In article 9142usf51...@mid.individual.net, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Chris Angelico wrote: Remind me some day to finish work on my ultimate programming language, which starts out with a clean slate and lets the programmer define his own operators and everything. Didn't someone already do that and call it lisp? :-) Lisp is betrayed by its brackets. He wants Forth. -- Greg Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Fun python 3.2 one-liner
In article mailman.46.1302010711.9059.python-l...@python.org, Daniel Fetchinson fetchin...@googlemail.com wrote: what is the character limit on a one liner :P. For PEP 8 compliance, 80 characters. :-) Yeah, but we don't live in the 80's or 90's anymore and our screens can support xterms (or let alone IDE widows) much wider than 80 characters. I'm using 140 for python these days. Seriously, who would want to limit him/herself to 80 characters in 2011? I want to limit myself to 72 char's for readability. 80 char's is over the top. Cheers, Daniel Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems of Symbol Congestion in Computer Languages
In article mailman.487.1298918378.1189.python-l...@python.org, Dotan Cohen dotanco...@gmail.com wrote: You miss the canonical bad character reuse case: = vs ==. Had there been more meta keys, it might be nice to have a symbol for each key on the keyboard. I personally have experimented with putting the symbols as regular keys and the numbers as the Shifted versions. It's great for programming. People might be interested in the colorforth solution: This goes the other way: characters are limited (lowercase and few special chars) to what is needed for programming. So the fingers never need to leave the home position, reaching about 30 chars at most. Different uses (defining a function versus using a function) are indicated by color, so don't use up char's. http://www.colorforth.com I was forced to use it (a development environment required it) and it is not as bad as it sounds. -- Dotan Cohen Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: examples of realistic multiprocessing usage?
In article mailman.859.1295270976.6505.python-l...@python.org, Adam Tauno Williams awill...@whitemice.org wrote: On Mon, 2011-01-17 at 13:55 +, Albert van der Horst wrote: In article mailman.842.1295212943.6505.python-l...@python.org, Philip Semanchuk phi...@semanchuk.com wrote: SNIP I grepped through the code to see that it's using = multiprocessing.Listener. I didn't go any further than that because our = project is BSD licensed and the license for Gluino is unclear. Until I = find out whether or not its under an equally permissive license, I can't = borrow ideas and/or code from it. You have been brain washed by the Intellectual Properties congsy. Of course you can read through code to borrow idea's from it. I wouldn't; and there is no brain-washing. It is very unwise to look at GPL'd code if you are working on a non-GPL project; the GPL is specifically and intentionally viral. The distinction between reading-through-code-and-borrowing-ideas and copying-code is thin and best left to lawyers. This is what some people want you to believe. Arm twisting by GPL-ers when you borrow their ideas? That is really unheard of. GPL-ers are not keen on getting the most monetary award by setting lawyers on you and go to court only reluctantly to enforce the license. Aside: Comments to the contrary often stand-on-their-head to make such cases. For example: You do have a choice under the GPL license: you can stop using the stolen code and write your own, or you can decide you'd rather release under the GPL. But the choice is yours. If you say, I choose neither, then the court can impose an injunction to stop you from further distribution, but it won't order your code released under the GPL. ... Of course, you could avoid all such troubles in the first place by not stealing GPL code to begin with http://www.groklaw.net/article.php?story=20031214210634851 Stealing code means just that, verbatim copies. When you read this carefully, you can see that reimplementing the stolen code is an option. Exactly what you say is legally impossible. It doesn't say: you can stop using the stolen code, and now you're forever banned from writing your own, since you have seen our code Seriously? What that basically means is you can't use GPL'd code in a non-GPL'd product/project. Saying if you do it is OK, but you'll be required to replace the code or change your license is standing-on-ones-head. Risking a forced reimplementation of a core component of an existing application is 'just nuts'. GPL-code is protected under *copyright law*, not patents or some such. That means that reimplementing idea's is okay. That is one of the things GPL tries to protect. Also we recognize the fact that the wheel is reinvented all the time and that there are a limited number of solutions to a problem. You could easily have come up with the same idea as me. Then you overlook another possibility. I have a lot of GPL-ed code on my site. If you want to use some of it commercially, you could contact me and negotiate a non-GPL license. You might be surprised how easy I'm on you, as long as you recognize where the code comes from. If you want to use it BSD-licensed, I would be even more lenient (unless strategic issues are at stake.) So pardon me, but not even looking at code you might learn from is pretty hysteric. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter: The good, the bad, and the ugly!
In article d9703f77-31a4-42af-aa1d-a4acedbcf...@d7g2000vbv.googlegroups.com, Adam Skutt ask...@gmail.com wrote: On Jan 14, 5:17=A0pm, Albert van der Horst alb...@spenarnc.xs4all.nl wrote: I really don't follow that. You need a tremendous set to write gimp. Obviously you won't write gimp in Python. You need a tremendous set to write /the majority of the applications on your computer/. On my desktop right now, I have running: * Google Chrome * TweetDeck * PuTTY * Pidgin * Game for Windows Launcher * Free Download Manager * Steam Client * A Windows Control Panel Window None of those applications could be written with his proposed widget set, he's literally 0/7 on running applications. If the situation isn't the same on your computer then your application usage is highly unusual or you don't understand what widgets are used to construct your applications. You've just told me that Python would no longer be suitable for constructing the majority of GUI applications on the planet. We are not talking about running applications, but about writing applications. I count 4000+ .py files in my /usr/share alone on Ubuntu. Your set is totally unrepresentative for those scripts. Adam Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter: The good, the bad, and the ugly!
In article 4d337983$0$29983$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 16 Jan 2011 07:18:16 -0800, Adam Skutt wrote: [...] I'm afraid I found most of your post hard to interpret, because you didn't give sufficient context for me to understand it. You refer to his proposed widget set, but with no clue as to who he is, or what the widget set is, or what essential widgets you continue missing. I can guess he is rantingrick, but am not sure -- there's only so much of his time-wasting I can read before reaching for the killfile. Rantingrick believes he is doing us a service by haranguing us incessantly into scratching *his* poorly thought-out itches, regardless of practicality or actual need. But putting that aside, I'd like to comment on a few points: [...] If the situation isn't the same on your computer then your application usage is highly unusual or you don't understand what widgets are used to construct your applications. You've just told me that Python would no longer be suitable for constructing the majority of GUI applications on the planet. No, that does not follow. Unless he (I'll assume it is rantingrick) has proposed hunting down and destroying all third-party GUI tool sets, what you've been told is that *one specific* tool set is unsuitable for constructing the majority of GUI apps. Actually it was me. Those guys don't even know how to attribute or quote. [...] Really, if you believe the case to be otherwise, I truly believe you aren't paying attention to your own computer(s), or don't understand how the applications you use are constructed. What's out there isn't interesting, it's what people use that's interesting, and people tend to use GUIs that are moderately to highly complicated. Well, true, but people tend to *use* the parts of the GUIs that are simple and basic. Not only do the big complicated apps get all the press even when they are actually a niche product (everyone knows about Photoshop, but more people use MS Paint) but it's a truism that most people use something like 20% of the functionality of big, complicated GUI apps. Most people use Microsoft Word or OpenOffice for little more than text editing with formatting. It's easy for power users to overestimate how much of their complicated GUIs are actually used by the average user. Or even the *above* average user. Or even for the support of other packages, I gave the bluetooth example. I think the use of Python for e.g. configuration of packages is quite common. I suspect that a variation of Zipf's Law probably holds for GUI complexity -- if you rank the widgets in order of most to least commonly used, I expect that you'll see actual use drop away rapidly and at an accelerated rate. E.g. the widget in second place might be used roughly half as often as the widget in first place place, the widget in third place one third as often, the widget in fourth place one quarter as often, and so forth. That is the point I wanted to make. -- Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: examples of realistic multiprocessing usage?
In article mailman.842.1295212943.6505.python-l...@python.org, Philip Semanchuk phi...@semanchuk.com wrote: SNIP I grepped through the code to see that it's using = multiprocessing.Listener. I didn't go any further than that because our = project is BSD licensed and the license for Gluino is unclear. Until I = find out whether or not its under an equally permissive license, I can't = borrow ideas and/or code from it. You have been brain washed by the Intellectual Properties congsy. Of course you can read through code to borrow idea's from it. Hope it's of some help to you, though. Cheers Philip= -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list