Re: Lies in education [was Re: The "loop and a half"]

2017-10-12 Thread Steve D'Aprano
the factory.) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: unorderable types: list() > int()

2017-10-12 Thread Steve D'Aprano
:, cl_pos apparently is still a list. Though the run in a > python console has no issues and report cl_pos as int. It isn't a list. What makes you think it is? py> pos = {"CLown":10,"BArbie":20} py> cl_ = [v for k, v in pos.items() if k.startswith('CL')

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
On Fri, 13 Oct 2017 05:16 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> On Fri, 13 Oct 2017 03:37 pm, Gregory Ewing wrote: >> >>>If the compiler can tell where p is initially pointing, it could >>>put the pointer in read-only memory. >> >>

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
On Fri, 13 Oct 2017 11:48 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> I wasn't questioning where the data came from, but how the compiler can >> write to READ ONLY MEMORY which might not even be in the same continent as >> the compiler that generated the c

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
be nicer. I don't know if either of these (actual immutable pure-Python objects, and un-rebindable names) count as quite the same thing you are asking Neil about. But I trust they're related. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
#x27;re using a text-only interface with no way to visually distinguish items) then you should provide some other feedback, like a beep or flashing the screen, or better (since audible feedback is annoying) display an informational status message that doesn't require explicit acknowledgement from

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
in any case, a seg fault is a pretty crude and dangerous way to report errors. It isn't so much an error report as the *consequences* of the error, a bit like your car engine seizing up because you forgot to put oil in it. -- Steve “Cheer up,” they said, “things could be worse.” So

Re: Python-list Digest, Vol 169, Issue 23

2017-10-13 Thread Steve D'Aprano
x27;s only because you did so first :-) On Fri, 13 Oct 2017 02:53 am, ROGER GRAYDON CHRISTMAN wrote: > On Thu, Oct 12, 2017 08:05 AM, Steve D'Aprano wrote:> [...] > This seems like a veritable straw man if any. > I am fairly sure that "one entry, one exit" > does not

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
On Sat, 14 Oct 2017 07:15 am, Peter J. Holzer wrote: > On 2017-10-13 15:11, alister wrote: >> On Sat, 14 Oct 2017 01:48:44 +1300, Gregory Ewing wrote: >>> Steve D'Aprano wrote: >>>> I wasn't questioning where the data came from, but how the compiler can &g

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
On Sat, 14 Oct 2017 01:51 am, Chris Angelico wrote: > On Sat, Oct 14, 2017 at 1:32 AM, Steve D'Aprano > wrote: >> It seems to me that you're not talking about ROM at all, but ordinary RAM. >> Then what do you mean by "read only"? A block of memory with a fla

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
On Sat, 14 Oct 2017 07:04 am, Peter J. Holzer wrote: > On 2017-10-13 15:28, Steve D'Aprano wrote: >> On Sat, 14 Oct 2017 01:30 am, Chris Angelico wrote: >>>> It's just a technique, like greying out certain menu options - clicking >>>> them will do noth

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread Steve D'Aprano
acter"... >> >> True. > > Well, it does, in my universe. That was cast in stone 10**-32 seconds > after the Big Bang. You've never had char-grilled peppers? *wink* -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Lies in education [was Re: The "loop and a half"]

2017-10-14 Thread Steve D'Aprano
On Sat, 14 Oct 2017 08:26 pm, Peter J. Holzer wrote: > On 2017-10-14 01:05, Steve D'Aprano wrote: >> In context, we are talking about a computer program (the compiler) writing >> data to memory. > > No, I don't think so. You keep talking about that, even tho

Re: An endless loop

2017-10-14 Thread Steve D'Aprano
rime, 11 is prime..." The computer programmer says "Listen you guys, you're all doing it wrong. I've written a program to check for primes, it says: 1 is prime, 1 is prime, 1 is prime, 1 is prime ..." -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: An endless loop

2017-10-15 Thread Steve D'Aprano
ment tail recursion optimization so that we can forgo iteration altogether? *wicked grin* -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Searching For Old Posts On Python

2017-10-16 Thread Steve D'Aprano
y. You received good answers. Yes, but he can't find the answers because he can't search for his old posts :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Searching For Old Posts On Python

2017-10-16 Thread Steve D'Aprano
rg/pipermail/python-list/ Or download the archives onto your computer and search them locally. https://mail.python.org/pipermail/python-list/ (download the Gzipped archives). Or try googling: https://duckduckgo.com/html/?q=%22Cai%20Gengyang%22%20python -- Steve “Cheer up,” they said, “thi

Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
of expression that can appear on the left hand side of assignment: 123 = 1+1 # illegal del 123 # also illegal -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: right list for SIGABRT python binary question ?

2017-10-16 Thread Steve D'Aprano
you read and follow this first: http://sscce.org/ and post a *minimum* example of your code. (Sorry for the redundant instructions if you already know this, but you would be surprised how many people don't.) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and

Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
o x and makes x a local variable. Note that the rules for this are deliberately very, very simple, so this will make x a local: def f(): print(x) # x is local x = 123 and even this will too: def f(): if False: x = 123 # dead code print(x) # but enough to make x a local

Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 01:12 pm, Ned Batchelder wrote: > On 10/16/17 9:06 PM, bartc wrote: >> On 17/10/2017 01:53, Steve D'Aprano wrote: [...] >>> `del` is kind of like an "anti-assignment" in that the argument to >>> `del` must >>> be exactly the

Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
e is no generally supported way to do that. So in other words, it would require significant compiler magic. In general, Python prefers to put the compiler magic in statements, not functions. > that could have been a viable solution. True. It would have been an ugly, inelegant solution, but it

Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 02:40 pm, Ben Finney wrote: > Steve D'Aprano writes: >> `del` cannot be a method or a function, because the argument to `del` >> is the name of the variable, not the contents of the variable. > > Since a Python “variable” does not have con

Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 04:07 pm, Steve D'Aprano wrote: > [1] Except in the loosest sense that any use of words to refer to a concept > is a reference, e.g. the words "Queen Elizabeth" is a reference to the > current monarch of the UK, Elizabeth Windsor. Oops, ignore this fo

Re: Logging module stopped working

2017-10-17 Thread Steve D'Aprano
w I'm really clutching at straws, because if that were the case, I'd expect there to be an exception, not just logging failing to work. I'm intrigued by this error, and would love to hear what caused it when you find out. Please respond back on the list with your diagnosis. By the wa

Re: Efficient counting of results

2017-10-19 Thread Steve D'Aprano
cket) If you want the total record amount, you say: sum(record.total for record in bucket) (assuming your records also have a "total" field, if they're invoices say). I hope that's even vaguely helpful. > Maybe that will help clear things up. Or not. :-) Not even a tiny bit :-( -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Compression of random binary data

2017-10-22 Thread Steve D'Aprano
compress random (uniformly distributed) data. > (If other combinations than ( 0, 0 ) were extremely > rare, one could even improve the compression more.) What you say is true, but it has nothing to do with Danceswithnumbers' ignorant and ludicrous claim that he can compress random

Re: Compression of random binary data

2017-10-22 Thread Steve D'Aprano
o.uk/other/compression.php but as people point out, the information in the file, plus the information in the file system, ends up being *larger* than the original. Well done to Patrick Craig for finding a clever loophole to "win" the challenge, but he did so without actually compressing the

Re: grapheme cluster library

2017-10-23 Thread Steve D'Aprano
| extended Latin alphabets > | (including Azeri, Estonian, Hungarian and Turkish), but as the letter U > | with an umlaut/diaeresis in others such as Catalan, French, Galician, > | German, Occitan and Spanish. Indeed: sometimes the same grapheme is considered a letter in one language and a

Re: Compression of random binary data

2017-10-23 Thread Steve D'Aprano
attachments/million-digit-challenge/AMillionRandomDigits.bin to less than 415241 bytes, and you can win $100. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Compression of random binary data

2017-10-23 Thread Steve D'Aprano
On Tue, 24 Oct 2017 03:13 pm, danceswithnumb...@gmail.com wrote: > I did that quite a while ago. 352,954 kb. Sure you did. Let's see the code you used. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.py

Re: Compression of random binary data

2017-10-24 Thread Steve D'Aprano
mpressing the digits in text form is not impressive in the least. As Ben Bacarisse pointed out, most of us will probably already have half a dozen programs that do that. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Compression of random binary data

2017-10-24 Thread Steve D'Aprano
le file is if the compression is lossy. > Then you publish in a major journal. Post the link to the journal > article when you are done. These days there are plenty of predatory journals which will be happy to take Dancerswithnumber's money in return for publishing it in a junk journa

Re: Compression of random binary data

2017-10-24 Thread Steve D'Aprano
compress any random > file. Talk is cheap. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Compression of random binary data

2017-10-24 Thread Steve D'Aprano
On Wed, 25 Oct 2017 02:40 am, Lele Gaifax wrote: > Steve D'Aprano writes: > >> But given an empty file, how do you distinguish the empty file you get >> from 'music.mp3' and the identical empty file you get from 'movie.avi'? > > That&#

Re: Compression of random binary data

2017-10-24 Thread Steve D'Aprano
On Wed, 25 Oct 2017 07:09 am, Peter J. Holzer wrote: > On 2017-10-23 04:21, Steve D'Aprano wrote: >> On Mon, 23 Oct 2017 02:29 pm, Stefan Ram wrote: >>> >> If the probability of certain codes (either single codes, or sequences of >> codes) are non-equal, the

Re: Compression of random binary data

2017-10-25 Thread Steve D'Aprano
On Thu, 26 Oct 2017 08:22 am, danceswithnumb...@gmail.com wrote: > with each pass you can compress untill the entropy is so random it can no > longer be comressed. Which is another way of saying that you cannot compress random binary data. -- Steve “Cheer up,” they said, “things co

Re: Determine the container class of an object in Python 3

2017-10-25 Thread Steve D'Aprano
n use a weakref. But seriously, don't worry about it unless you need to. Another solution is to make Class1 a mixin, and then rely on inheritence: class MyMixin: def myDef(self): return self.a class Class2(MyMixin): def __init__(self): self.a = 0 -- Steve “Cheer up,”

Re: Speed Race between old and new version 'working with files'

2017-10-27 Thread Steve D'Aprano
avg) That *adds* the time of the second test to the original timing, so your last line should be: print('Execute time with NEW version plus time with OLD version : ', avg) to be accurate. But I don't think that's what you intended. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Compression of random binary data

2017-10-28 Thread Steve D'Aprano
On Fri, 27 Oct 2017 09:53 am, Ben Bacarisse wrote: > A source of random can be defined but "random data" is much more > illusive. Random data = any set of data generated by "a source of random". -- Steve “Cheer up,” they said, “things could be worse.” So I c

Re: Compression of random binary data

2017-10-28 Thread Steve D'Aprano
s not very surprising. If your data source is a pair of fair, independent dice, then the self-information of receiving a two and a four is 5.170 bits. Its a logarithmic scale, not linear: if the probability of a message or event is p, the self-information of that event is log_2 (1/p) bits. -- S

Re: Compression of random binary data

2017-10-29 Thread Steve D'Aprano
On Sun, 29 Oct 2017 02:31 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> I don't think that's right. The entropy of a single message is a >> well-defined quantity, formally called the self-information. >> >> https://en.wikipedia.org/wiki/Self-info

Re: Compression of random binary data

2017-10-29 Thread Steve D'Aprano
ile, exercise to try to guess what the various PMs would have said. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Compression of random binary data

2017-10-29 Thread Steve D'Aprano
/263197/is-information-entropy-the-same-as-thermodynamic-entropy -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Invoking return through a function?

2017-10-29 Thread Steve D'Aprano
would be. It is bad enough that any function could raise an exception, but at least exceptions halt the normal execution of code (unless explicitly caught). They don't silently continue normal execution. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Invoking return through a function?

2017-10-29 Thread Steve D'Aprano
On Mon, 30 Oct 2017 03:35 am, Alberto Riva wrote: > On 10/29/2017 10:35 AM, Steve D'Aprano wrote: [...] >> You mean *less* explicit. "checkKey" gives absolutely no hint that it >> causes the current function to return. > > That's just because I used a n

Re: Invoking return through a function?

2017-10-29 Thread Steve D'Aprano
On Mon, 30 Oct 2017 02:35 am, Stefan Ram wrote: > So, I guess, we then must accept that sometimes - under > extraordinary circumstances - it should be tolerated to > write a function that is as long as six lines. An entire six lines... you cowboy! *wink* -- Steve “Cheer up,”

Re: Invoking return through a function?

2017-10-29 Thread Steve D'Aprano
, less rewarding and simply less fun than writing code in the first place. [2] There are only two hard problems in computer science: cache invalidation, and naming things. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: ValueError: Error 3 while encrypting in ECB mode

2017-10-29 Thread Steve D'Aprano
+encrypting+in+ECB+mode which gives me this: https://stackoverflow.com/questions/14179784/python-encrypting-with-pycrypto-aes among other possible answers. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Invoking return through a function?

2017-10-30 Thread Steve D'Aprano
it is caught. [1] There's no doubt that exception handling, except in the simplest forms, is more complex than code without exception handling. And this is why Rob Pike designed Go without exceptions. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Invoking return through a function?

2017-10-30 Thread Steve D'Aprano
On Tue, 31 Oct 2017 02:34 pm, Chris Angelico wrote: > On Tue, Oct 31, 2017 at 2:00 PM, Steve D'Aprano > wrote: >> Python has no GOTO, fortunately, but C has at least two, GOTO and LONGJMP. >> A C macro could, if I understand correctly, jump into the middle of anothe

Re: Invoking return through a function?

2017-10-30 Thread Steve D'Aprano
to define your own control-structures, even the structure of the code can be unfamiliar. Another way to put it might be that any sufficiently complex Lisp program doesn't look like Lisp any more. Except perhaps for the myriad parentheses *wink* -- Steve “Cheer up,” they said, “things c

Re: How to join elements at the beginning and end of the list

2017-10-31 Thread Steve D'Aprano
orary list, its actually faster to join a list comp than a generator expression. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Performance of map vs starmap.

2017-10-31 Thread Steve D'Aprano
a new `tuple` that is passed to the mapped function every > time a `__next__` call is made. > > Why can not `map` use the same approach as `zip`? It possibly could, if somebody could be bothered to make that micro-optimization. -- Steve “Cheer up,” they said, “things could be worse.

Re: Code Snippets

2017-11-01 Thread Steve D'Aprano
numbers = [__import__( "random" ).random() for i in range(1000)] Do I need to explain how terrible that code is? Code snippets are not an alternative to actually thinking about your code and writing the best code you can. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Thread safety issue (I think) with defaultdict

2017-11-01 Thread Steve D'Aprano
-) "Some people, when confronted with a problem, think, 'I know, I'll use threads. Nothew y htwo probave lems." :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: replacing `else` with `then` in `for` and `try`

2017-11-01 Thread Steve D'Aprano
tainly not going to happen. It would require adding a new keyword, and unless Guido changes his mind, he doesn't think this change is worthwhile. If I were the BDFL, this would be the first change I make :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Code Snippets

2017-11-01 Thread Steve D'Aprano
the cache, its not free, and `__import__("spam")` is even less cheap (more costly). Its a function call, not a statement, so it requires a runtime name lookup and a function call on top of the same process of checking the cache and importing the module. -- Steve “Cheer up,” they said, “th

Re: Code Snippets

2017-11-01 Thread Steve D'Aprano
ere we don't care too much about best practices. But this isn't so much less-than-best practices as worst-practices: optimizing to save a few seconds during the initial editing run, by using the copy-and-paste anti-pattern. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: replacing `else` with `then` in `for` and `try`

2017-11-01 Thread Steve D'Aprano
minutes before rinsing." "Boil the pasta until it is soft, ELSE drain it and mix in the sauce." -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: replacing `else` with `then` in `for` and `try`

2017-11-01 Thread Steve D'Aprano
choice of keyword is so poor. If somebody of your experience can misread it, I don't feel so bad about how long it too me to understand it when I was a newbie. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: replacing `else` with `then` in `for` and `try`

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 12:50 pm, Ben Bacarisse wrote: > Steve D'Aprano writes: > >> On Thu, 2 Nov 2017 08:12 am, Alexey Muranov wrote: >> >>> what do you think about the idea of replacing "`else`" with "`then`" in >>> the contexts of `

Re: what exactly does type.__call__ do?

2017-11-01 Thread Steve D'Aprano
t I can emulate it, And then if type.__call__ changes, your emulation will be wrong. > but I wasn't able to find any docs explicitly > detailing what that method does. If someone knows where this info is that > would be great too. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: replacing `else` with `then` in `for` and `try`

2017-11-02 Thread Steve D'Aprano
nglish interpretation of for...else, namely that the `else` clause runs if the for sequence was empty: for x in L: pass else: # This is wrong! print("L is empty") and similar for while. That lead me astray for the longest time! And I'm not the only one. > English an

A use-case for for...else with no break

2017-11-02 Thread Steve D'Aprano
;: ... print(x, end='') ... py> efghpy> "For ... else" to the rescue! py> for char in "abcdefgh": ... print(char, end='') ... else: ... print() ... abcdefgh py> -- Steve “Cheer up,” they said, “things could be worse.” So I cheered

Re: replacing `else` with `then` in `for` and `try`

2017-11-02 Thread Steve D'Aprano
On Thu, 2 Nov 2017 09:04 pm, Steve D'Aprano wrote: > then (with special case) of `pass` That should read "then except for the special case of `pass`". Sorry. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got

Re: replacing `else` with `then` in `for` and `try`

2017-11-02 Thread Steve D'Aprano
an argument about whether "yellow" or "purple" is closer in meaning to the word we actually want, "spicy" :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: A use-case for for...else with no break

2017-11-02 Thread Steve D'Aprano
On Thu, 2 Nov 2017 10:45 pm, Alberto Berti wrote: >>>>>> "Steve" == Steve D'Aprano writes: > > py> for x in "abcdefgh": > Steve> ... print(x, end='') > Steve> ... > py> efghpy> > > &g

Re: replacing `else` with `then` in `for` and `try`

2017-11-02 Thread Steve D'Aprano
; Maybe the change should be that it is a syntax error to use a > 'for/while...else' with no 'break'. Only if you want to make the experience of using Python in the interactive interpreter worse. See my recent post: "A use-case for for...else with no break" -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: A use-case for for...else with no break

2017-11-02 Thread Steve D'Aprano
a blank: py> for x in seq: ... do_this() ... py> do_that() the output of "do_this()" is separated from the output of "do_that()", which may be inconvenient. Another work around is: if True: for x in seq: do_this() do_that() -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Thread safety issue (I think) with defaultdict

2017-11-02 Thread Steve D'Aprano
r: - async: shared data, but fully deterministic task switching; - multiprocessing: non-deterministic task switching, but by default fully isolated data. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: replacing `else` with `then` in `for` and `try`

2017-11-02 Thread Steve D'Aprano
On Fri, 3 Nov 2017 03:31 am, Jon Ribbens wrote: > On 2017-11-02, Steve D'Aprano wrote: >> On Fri, 3 Nov 2017 12:39 am, Jon Ribbens wrote: >>> Why would we want to make the language worse? It is fairly obvious >>> what 'else' means, >> >>

Re: Thread safety issue (I think) with defaultdict

2017-11-02 Thread Steve D'Aprano
On Fri, 3 Nov 2017 02:19 pm, Rustom Mody wrote: > «The world is concurrent» [Joe Armstrong creator of Erlang] And the world is extremely complex, complicated and hard to understand. The point of programming is to simplify the world, not emulate it in its full complexity. -- Steve “Cheer

Re: Thread safety issue (I think) with defaultdict

2017-11-02 Thread Steve D'Aprano
; No problems were observed until the code deadlocked > on April 26, 2004, four years later. That is a fantastic anecdote, thank you. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: A use-case for for...else with no break

2017-11-03 Thread Steve D'Aprano
On Fri, 3 Nov 2017 04:22 pm, Paul Rubin wrote: > Steve D'Aprano writes: >> for x in something(): >> print(x, end='') > > print(''.join(something())) I hoped that people would recognise a simplified, toy example used only to illustrate a tec

Re: A use-case for for...else with no break

2017-11-03 Thread Steve D'Aprano
and os.environ['TERM'] in ['xterm', 'vt100']): # Make the prompt bold in Python 3. sys.ps1 = '\001\x1b[1m\002py> \001\x1b[0m\002' sys.ps2 = '\001\x1b[1m\002... \001\x1b[0m\002' else: sys.ps1 = 'py> ' -- Steve “Cheer

Re: Thread safety issue (I think) with defaultdict

2017-11-03 Thread Steve D'Aprano
to me, too confusing, for me to have an opinion on yet, but I lean slightly towards the position that deterministic task-switching is probably better than non-deterministic.) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: replacing `else` with `then` in `for` and `try`

2017-11-03 Thread Steve D'Aprano
On Fri, 3 Nov 2017 10:49 pm, Jon Ribbens wrote: > On 2017-11-03, Steve D'Aprano wrote: >> On Fri, 3 Nov 2017 03:31 am, Jon Ribbens wrote: >>> No, it's an obvious bug. You have a 'for...else' with no 'break'. >>> Like I said, that should p

Re: replacing `else` with `then` in `for` and `try`

2017-11-03 Thread Steve D'Aprano
is only one. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Thread safety issue (I think) with defaultdict

2017-11-03 Thread Steve D'Aprano
s, that's not the tool's fault. If anything, we can say that the ultimate error was that you decided to write in a threaded style without actually using threads: the error was your (dangerous?) choice to write non-deterministic code using shared data. -- Steve “Cheer up,” they said, “th

Re: Try: Except: evaluates to True every time

2017-11-04 Thread Steve D'Aprano
bug. Just because you can connect to the host *now*, when you call check_udp, doesn't mean it will still respond two seconds later (or even two milliseconds later) when you attempt to connect again. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Read Firefox sqlite files with Python

2017-11-04 Thread Steve D'Aprano
format 3 and although I can see a few human readable words, the bulk of the file looks like noise. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Aw: Try: Except: evaluates to True every time

2017-11-04 Thread Steve D'Aprano
On Sun, 5 Nov 2017 03:07 am, Karsten Hilbert wrote: > Try in an interactive interpreter: > >python> "a string" is True Did you try that yourself? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- h

Re: [TSBOAPOOOWTDI]using names from modules

2017-11-04 Thread Steve D'Aprano
or the name is very well known - or you're only using a single name from the module (or at most a few) - especially if it repeats the module name (e.g. fractions.Fraction) it is acceptable to use the "from module import name" version: from math import cos y = cos(x) Which yo

Re: Read Firefox sqlite files with Python

2017-11-04 Thread Steve D'Aprano
On Sun, 5 Nov 2017 04:32 am, Steve D'Aprano wrote: > I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. > > > import sqlite3 > con = sqlite3.connect('foo.sqlite') > with open('dump.sql', 'w') as f: > for l

Re: replacing `else` with `then` in `for` and `try`

2017-11-04 Thread Steve D'Aprano
On Sat, 4 Nov 2017 04:44 am, Jon Ribbens wrote: > On 2017-11-03, Steve D'Aprano wrote: >> The for loop does not necessarily perform a search: >> >> count = 1 >> for obj in sequence: >> if count > MAX_OBJECTS: >> print("too many ob

Re: Zen of Python “obvious way to do it” (was: [TSBOAPOOOWTDI]using names from modules)

2017-11-05 Thread Steve D'Aprano
On Sun, 5 Nov 2017 12:49 pm, Ben Finney wrote: > Steve D'Aprano writes: > >> On Sun, 5 Nov 2017 06:42 am, Stefan Ram wrote: >> >> > What is the one way to do it? >> >> There is no philosophy of "one way to do it" in Python, that is a >&g

Re: Aw: Try: Except: evaluates to True every time

2017-11-05 Thread Steve D'Aprano
On Sun, 5 Nov 2017 09:53 pm, Karsten Hilbert wrote: > On Sun, Nov 05, 2017 at 11:28:44AM +1100, Steve D'Aprano wrote: > >> > Try in an interactive interpreter: >> > >> >python> "a string" is True >> >> Did you try that

Re: [TSBOAPOOOWTDI]using names from modules

2017-11-05 Thread Steve D'Aprano
local alias for math.cos; - then you can show that there's no particular reason why the names have to be the same: from math import cos as mycos is just sugar for import math mycos = math.cos But don't teach them this: > |from math import * There's no reason for beginners to u

Re: replacing `else` with `then` in `for` and `try`

2017-11-05 Thread Steve D'Aprano
lieve impossible things.' 'I daresay you haven't had much practice,' said the Queen. 'When I was your age, I always did it for half-an-hour a day. Why, sometimes I've believed as many as six impossible things before breakfast.' -- Steve “Cheer

Re: replacing `else` with `then` in `for` and `try`

2017-11-05 Thread Steve D'Aprano
On Mon, 6 Nov 2017 01:39 am, Jon Ribbens wrote: > On 2017-11-05, Steve D'Aprano wrote: >> On Sat, 4 Nov 2017 04:44 am, Jon Ribbens wrote: >>> That conforms to my model. It's searching for the condition >>> 'count > MAX_OBJECTS'. >> >&g

Re: replacing `else` with `then` in `for` and `try`

2017-11-05 Thread Steve D'Aprano
On Sat, 4 Nov 2017 03:57 pm, Michael Torrie wrote: > On 11/03/2017 09:06 PM, Chris Angelico wrote: >> On Sat, Nov 4, 2017 at 1:57 PM, Michael Torrie wrote: >>> On 11/03/2017 07:09 PM, Steve D'Aprano wrote: >>>> On Sat, 4 Nov 2017 06:15 am, Michael Torrie wrote

Re: Read Firefox sqlite files with Python

2017-11-05 Thread Steve D'Aprano
On Mon, 6 Nov 2017 12:39 am, Paul Moore wrote: > On 5 November 2017 at 01:22, Steve D'Aprano > wrote: >> On Sun, 5 Nov 2017 04:32 am, Steve D'Aprano wrote: >> >>> I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. >>&g

Re: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`)

2017-11-07 Thread Steve D'Aprano
quot;. In Jon's model, if we interpret else as "else no break", then we're also left with the mystery of what happened to the "if break" clause. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: why won't slicing lists raise IndexError?

2017-12-05 Thread Steve D'Aprano
s position 20, the line is extended to position 20. > Of course, in the realm of maths, a line is by > definition infinite. Not necessarily. Lines can be finite (e.g. a chord) or infinite, and if infinite, they can be defined as extending towards infinity in both directions, or in only one (a

Re: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited)

2017-12-05 Thread Steve D'Aprano
ociations, then you should have said so. But why do you care about the kernel? Would you think it even the *tiniest* useful to claim that "Linux doesn't do email" because it is sendmail or postfix (or similar) that sends email rather than the Linux kernel itself? -- Steve --

Re: csv.DictReader line skipping should be considered a bug?

2017-12-05 Thread Steve D'Aprano
tract the records* as a dict. Since blank lines aren't records, they should be skipped. > Does anyone agree, or am I crazy? I wouldn't want to guess your mental health based just on this isolated incident, but if I had to make a diagnosis, I'd say, yes, crazy as a loon. *wink* -- Steve -- https://mail.python.org/mailman/listinfo/python-list

f-string

2017-12-05 Thread Steve D'Aprano
Anyone got a handy copy of Python 3.6 available to test something for me? What does compile('f"{spam} {eggs}"', '', 'single') return? What does eval()'ing the above compiled object do? If necessary, you may have to define spam and eggs first. Th

Re: f-string

2017-12-05 Thread Steve D'Aprano
On Wed, 6 Dec 2017 11:54 am, John Pote wrote: [...] > Ran above test file and got, > >>python36 compiletest.py > at 0x02120E40, file "", line 1> > > > SPAM scrambled Thanks everyone, that's what I wanted to see. -- Steve “Cheer up,

Re: csv.DictReader line skipping should be considered a bug?

2017-12-05 Thread Steve D'Aprano
o have a separator between fields) I'm not too concerned by the inability to represent a record consisting of only a single blank field. If there was an actual CSV standard (rather than just a collection of implementations with slightly different behaviour) I'd be more concerned at this desi

<    2   3   4   5   6   7   8   9   10   11   >