Re: Writing a chess-playing AI like Alphago in Python

2017-12-23 Thread Steve D'Aprano
On Sun, 24 Dec 2017 12:20 pm, Cai Gengyang wrote: > How many lines of code in Python would it take to create a Go-playing AI > like AlphaGo ? Estimates ? Somewhere between 1 and 1 billion. How about you start by telling us: - do you mean AlphaGo or AlphaGo Zero? - how many lines of code

Re: What is the meaning of @@?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 04:38 pm, Peng Yu wrote: > Hi, I only can find the doc for @. What does @@ mean in python? I don't think that @@ means anything yet. There was a proposal to use @@ for matrix exponentiation in Numpy, as @ is used for matrix multiplication, but that was left on hold to see

Re: Why are both locals() and globals() set?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 03:01 pm, Peng Yu wrote: > Hi, The following example shows that both locals() and globals() are > updated when x and f are defined. Shouldn't they be considered and > global variable and functions only? Why does it make sense to set > locals() as well? Thanks. There are three

Re: Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 03:50 pm, Peng Yu wrote: > Where is it documented that __xor__ and ^ is the same as > symmetric_difference? Thanks. You read https://docs.python.org/2/library/stdtypes.html#set to learn that ^ is the same as symmetric difference, and then read:

Re: Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 02:35 pm, Peng Yu wrote: > Hi, I see the following two lines are the same. But I'd like to find > where ^ is documented via the help() function (I am not looking for > the document in html)? Does anybody know? Thanks. > > s.symmetric_difference(t) > s ^ t You can call:

Re: Why "flat is better than nested"?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 01:48 am, andrewpat...@gmail.com wrote: > On Monday, October 25, 2010 at 11:07:42 AM UTC+1, kj wrote: >> In "The Zen of Python", one of the "maxims" is "flat is better than >> nested"? Why? Can anyone give me a concrete example that illustrates >> this point? >> >> TIA! >>

Re: How to edit a function in an interactive python session?

2017-12-20 Thread Steve D'Aprano
On Thu, 21 Dec 2017 12:42 pm, Peng Yu wrote: > Hi, > > R has the function edit() which allows the editing of the definition > of a function. Does python have something similar so that users can > edit python functions on the fly? Thanks. > >

Re: correctness proof for alpha-beta algorithm

2017-12-20 Thread Steve D'Aprano
On Thu, 21 Dec 2017 08:37 am, Bill wrote: > namenobodywa...@gmail.com wrote: >> On Tuesday, December 19, 2017 at 3:28:39 PM UTC-8, Steve D'Aprano wrote: >> >>> Does this have anything specifically to do with Python programming? >> i'm working on a game-playing

[META] Are the list admins honouring Posting Prohibited demands?

2017-12-19 Thread Steve D'Aprano
This is possibly a question for the list admins... I notice that Lawrence D’Oliveiro has taken up labelling his posts with a demand that his posts are not to be posted to the Python-List mailing list. I also see that his posts are not showing up on the mailing list archive. Is this a coincidence

Re: correctness proof for alpha-beta algorithm

2017-12-19 Thread Steve D'Aprano
On Wed, 20 Dec 2017 07:23 am, namenobodywa...@gmail.com wrote: > On Monday, December 18, 2017 at 10:16:07 PM UTC-8, Terry Reedy wrote: > >> Where or how have you looked so far? How formal do you want? > > i want full-on formal with lots of rigor and every possible detail spelled > out; i've

Re: Problem with timeit

2017-12-19 Thread Steve D'Aprano
On Tue, 19 Dec 2017 02:27 am, ast wrote: > I discovered that log functions from math module > works with integers, whatever their size, there is > no conversion to float. > >> import math >> x = 123456**123456 >> math.log10(x) > 628577.7303641582 (instantaneous) > > so 628578 digits Nice!

Re: Problem with timeit

2017-12-15 Thread Steve D'Aprano
On Sat, 16 Dec 2017 12:25 am, ast wrote: > > "Thomas Jollans" a écrit dans le message de > news:mailman.74.1513341235.14074.python-l...@python.org... >> On 2017-12-15 11:36, ast wrote: > > >> No, this is right. The calculation takes practically no time; on my >> system, it takes

Re: Problem with timeit

2017-12-15 Thread Steve D'Aprano
On Fri, 15 Dec 2017 10:47 pm, Thomas Jollans wrote: > On 2017-12-15 11:36, ast wrote: >> Hi >> >> Time measurment with module timeit seems to work with some statements >> but not with some other statements on my computer. >> >> Python version 3.6.3 >> >> from timeit import Timer >> >

Re: Problem with timeit

2017-12-15 Thread Steve D'Aprano
On Fri, 15 Dec 2017 09:36 pm, ast wrote: [...] > It's OK, with 10 more loops I get 10 more execution time. > > But with exponentiation, it's a mess > Timer("x=123456**123456").timeit(1) > 6.076191311876755e-06 Timer("x=123456**123456").timeit(10) > 3.841270313387213e-06 > > All

Re: Please tell me how to execute python file in Ubuntu by double

2017-12-15 Thread Steve D'Aprano
On Fri, 15 Dec 2017 09:48 am, Gregory Ewing wrote: > Rhodri James wrote: >> Even then there was RiscOS, which divorced file names from file types >> entirely. > > As did classic MacOS. Classic MacOS associated two such pieces of metadata with each file: the creator and type. Regardless of the

Re: unabe to import /pyd file.

2017-12-15 Thread Steve D'Aprano
On Fri, 15 Dec 2017 09:09 pm, Tim Golden wrote: > Apart from anything else these need to be raw strings: > > sys.path.append(r'C:\Python27\Lib\lib-tk') Don't use raw strings for paths. It's a trap: r'C:\Python27' # okay r'C:\Python27\' # fails Windows supports / as directory separator.

Re: write your replace function in python

2017-12-14 Thread Steve D'Aprano
On Thu, 14 Dec 2017 09:08 pm, ayaskant.mantu...@gmail.com wrote: > Hi, > > I want to replace the spaces in a sting with hyphen with my own replace > function or with using the pre-defined replace function. Can anybody help me > with this issue??? new_string = "string with spaces".replace(" ",

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

2017-12-10 Thread Steve D'Aprano
On Mon, 11 Dec 2017 11:29 am, Chris Angelico wrote: > On Mon, Dec 11, 2017 at 10:10 AM, Rick Johnson > wrote: >> And it's not like we can just pick file up and shake >> it, in a crude attempt to intuit the contents. > > No, but fortunately we have magic. And magic

Re: Save and load initialized class

2017-12-10 Thread Steve D'Aprano
On Sun, 10 Dec 2017 04:52 am, MRAB wrote: > Try updating __dict__: > > Opts.__dict__.update(json.load(open("mybuffer"))) __dict__ is implementation, vars() is the public interface: vars(Opts).update(json.load(open("mybuffer"))) Looks nicer too :-) -- Steve “Cheer up,” they said,

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

2017-12-09 Thread Steve D'Aprano
On Sun, 10 Dec 2017 02:01 pm, Chris Angelico wrote: > On Sun, Dec 10, 2017 at 12:56 PM, Steve D'Aprano > <steve+pyt...@pearwood.info> wrote: >> Remember the context here: we're replying to a thread discussing somebody >> who is running Ubuntu with a GUI deskto

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

2017-12-09 Thread Steve D'Aprano
On Fri, 8 Dec 2017 12:08 pm, Python wrote: > But more importantly, practically speaking, it still doesn't really > provide much more help to the OP than Lawrence's answer. I wasn't responding to the OP, I was responding to Lawrence. If I had a solution for the OP beyond what others have already

Re: Benefits of unicode identifiers (was: Allow additional

2017-12-09 Thread Steve D'Aprano
On Sat, 9 Dec 2017 09:57 am, Gilmeh Serda wrote: > And next demands to allow Unicode as keywords in a translated version of > Python > will make open source go away. For good. Do you seriously think that because *one* project forks their code base and introduces non-English keywords, the tens

Re: Benefits of unicode identifiers (was: Allow additional separator in identifiers)

2017-12-09 Thread Steve D'Aprano
On Sun, 10 Dec 2017 09:20 am, Terry Reedy wrote: > On 12/9/2017 5:57 AM, Gilmeh Serda wrote: > >> And next demands to allow Unicode as keywords in a translated version of >> Python > > Python's liberal open source license allows people to revise and > distribute their own python or python-like

Re: f-string

2017-12-08 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,â Ø they said, â £things could be worse.â Ø So I

Re: f-string

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > On Wed, Dec 6, 2017 at 11:54 AM, John Pote <johnp...@jptechnical.co.uk> > wrote: >> >> On 06/12/2017 00:16, Steve D'Aprano wrote: >>> >>> Anyone got a handy copy of Python 3.6 available to test some

Re: we want python software

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 03:45 pm, Abhiram R wrote: > On Wed, Dec 6, 2017 at 10:08 AM, km wrote: > >> I dont know how these students are selected into b tech stream in India. >> they are so dumb. All they know is a to open a program we need to double >> click it and it runs.

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

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 04:20 am, Jason wrote: > I ran into this: > https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-empty -lines > > # unlike the basic reader, we prefer not to return blanks, > # because we will typically wind up with a dict full of None > # values > > while

Re: Please tell me how to execute python file in Ubuntu by double click

2017-12-08 Thread Steve D'Aprano
On Tue, 5 Dec 2017 07:58 pm, Lawrence Dâ ÖOliveiro wrote: > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: >> >> Sounds like your OS file associations are all botched-up ... > > Linux doesnâ Öt do â £OS file associationsâ Ø. Then how does my Linux box know that when I

f-string

2017-12-08 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. Thanks in advance. -- Steve â £Cheer up,â Ø they

Re: Round to 2 decimal places

2017-12-06 Thread Steve D'Aprano
On Thu, 7 Dec 2017 01:31 pm, nick martinez wrote: > interesting, what version of python are you using? Tried it multiple times > and it still isn't working. Please launch a terminal window, copy this command exactly into the terminal and hit ENTER. You should have a $ or maybe % prompt for this

Re: Round to 2 decimal places

2017-12-06 Thread Steve D'Aprano
On Thu, 7 Dec 2017 11:58 am, nick martinez wrote: > I'm stuck. I need my program to round the end solution to 2 decimal places > but cant figure it out. Can someone help? I've been trying between printf > and round() but cant seem to get either to work. It might help if you show exactly what

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

2017-12-06 Thread Steve D'Aprano
On Thu, 7 Dec 2017 08:22 am, Python wrote: > On Wed, Dec 06, 2017 at 10:35:58AM +1100, Steve D'Aprano wrote: >> On Tue, 5 Dec 2017 07:58 pm, Lawrence D’Oliveiro wrote: >> >> > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: >> >

Re: Module _socket not found in python3.6 "No module named _socket"

2017-12-06 Thread Steve D'Aprano
On Thu, 7 Dec 2017 07:59 am, Bryan Zimmer wrote: > I have been getting this message, "No module named '_socket'", since I > installed python 3.6, about two months ago. > > My platform is Slackware Linux (14.2). I compiled python3.6 from source, > because binary python packages aren't distributed

Re: we want python software

2017-12-06 Thread Steve D'Aprano
On Wed, 6 Dec 2017 04:54 pm, Chris Angelico wrote: > On Wed, Dec 6, 2017 at 4:27 PM, km wrote: >> Remember that you are wasting time of lakhs of python subscribers by >> asking such dumb questions being tech students. You people can Google and >> watch movies / songs

Re: Politeness (was: we want python software)

2017-12-06 Thread Steve D'Aprano
On Wed, 6 Dec 2017 11:25 pm, Rustom Mody wrote: > On Wednesday, December 6, 2017 at 4:05:43 PM UTC+5:30, Steve D'Aprano wrote: >> On Wed, 6 Dec 2017 02:49 pm, Rustom Mody wrote: >> >> > You are assuming that the strangeness of the request is about 'tech' >> > [e

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

2017-12-06 Thread Steve D'Aprano
On Thu, 7 Dec 2017 02:33 am, Dennis Lee Bieber wrote: > On Wed, 06 Dec 2017 11:06:39 +1100, Steve D'Aprano > <steve+pyt...@pearwood.info> declaimed the following: > > >>I wouldn't want to guess your mental health based just on this isolated >>incident, but if I ha

Re: we want python software

2017-12-06 Thread Steve D'Aprano
On Wed, 6 Dec 2017 02:49 pm, Rustom Mody wrote: > You are assuming that the strangeness of the request is about 'tech' > [engineering/tech existed centuries before computers] > > Do remember one can be a tech-{student,professional} without > - ever having encountered free-software > -

Re: we want python software

2017-12-06 Thread Steve D'Aprano
On Wed, 6 Dec 2017 03:45 pm, Abhiram R wrote: > On Wed, Dec 6, 2017 at 10:08 AM, km wrote: > >> I dont know how these students are selected into b tech stream in India. >> they are so dumb. All they know is a to open a program we need to double >> click it and it

Re: f-string

2017-12-06 Thread Steve D'Aprano
On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > On Wed, Dec 6, 2017 at 11:54 AM, John Pote <johnp...@jptechnical.co.uk> > wrote: >> >> On 06/12/2017 00:16, Steve D'Aprano wrote: >>> >>> Anyone got a handy copy of Python 3.6 available to test some

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

2017-12-05 Thread Steve D'Aprano
On Wed, 6 Dec 2017 11:43 am, MRAB wrote: > A blank line could be a record if there's only one field and it's empty. That's technically correct, but if you have only one field, its barely a CSV file at all. Given that CSV technically requires at least two fields (in order to have a separator

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,” they said, “things could be worse.” So I

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. Thanks in advance. -- Steve “Cheer up,” they

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

2017-12-05 Thread Steve D'Aprano
On Wed, 6 Dec 2017 04:20 am, Jason wrote: > I ran into this: > https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-empty-lines > > # unlike the basic reader, we prefer not to return blanks, > # because we will typically wind up with a dict full of None > # values > > while

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
On Tue, 5 Dec 2017 07:58 pm, Lawrence D’Oliveiro wrote: > On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote: >> >> Sounds like your OS file associations are all botched-up ... > > Linux doesn’t do “OS file associations”. Then how does my Linux box know that when I

Re: why won't slicing lists raise IndexError?

2017-12-05 Thread Steve D'Aprano
On Tue, 5 Dec 2017 11:31 pm, Rick Johnson wrote: > Ned Batchelder wrote: > [...] >> Your original statement sounded like, "The else clause can >> never be executed," > > No. Of course not. Note that i mentioned _pragmatism_. My > complaint about the else-clause was not that it could > _never_ be

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

2017-11-07 Thread Steve D'Aprano
On Wed, 8 Nov 2017 04:28 am, Ian Kelly wrote: > Steve's manufactured interactive example ("manufactured" because > who really uses for-else interactively? If I really care that much > about output formatting I'm going to put it in a script). Me. As I have said. I really don't appreciate you

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 <steve+pyt...@pearwood.info> > 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 Pytho

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 <torr...@gmail.com> wrote: >>> On 11/03/2017 07:09 PM, Steve D'Aprano wrote: >>>> On Sat, 4 Nov

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 <steve+pyt...@pearwood.info> 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'

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

2017-11-05 Thread Steve D'Aprano
On Mon, 6 Nov 2017 10:06 am, Jon Ribbens wrote: > On 2017-11-05, Ben Finney wrote: >> Jon Ribbens writes: >>> I've provided you with a way of thinking about 'for...else' that makes >>> its purpose and meaning intuitively obvious. >> >> I've

Re: [TSBOAPOOOWTDI]using names from modules

2017-11-05 Thread Steve D'Aprano
On Mon, 6 Nov 2017 12:54 am, Stefan Ram wrote: > Paul Moore writes: >>But regardless, the Zen isn't intended to be taken quite as literally >>as the OP was trying to do. It's a statement of principles, not a set >>of rules. > > What I am looking for is a default notation

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 yours

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 <steve+pyt...@pearwood.info> 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&q

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 <steve+pyt...@pearwood.info> wrote: >> The for loop does not necessarily perform a search: >> >> count = 1 >> for obj in sequence: >> if count > MAX_OBJECTS: &

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 line in con.iterdump(): > f.wr

Re: [TSBOAPOOOWTDI]using names from modules

2017-11-04 Thread Steve D'Aprano
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 misunderstanding (possibly deliberate...) spread about by Perl users, to contrast Python from Perl's "more than one way to do it". The Zen of Python

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. --

Read Firefox sqlite files with Python

2017-11-04 Thread Steve D'Aprano
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 line in con.iterdump(): f.write(line + '\n') The error I get is: Traceback (most recent call last): File "", line 2,

Re: Try: Except: evaluates to True every time

2017-11-04 Thread Steve D'Aprano
On Sun, 5 Nov 2017 02:31 am, brandon wallace wrote: > > I have this code that tests a server to see if it is listening on port 123 > runs and evaluates to True every time. Even if the server does not exist but > it is not supposed to do that. I am getting no error message at all. What is > going

Re: Thread safety issue (I think) with defaultdict

2017-11-03 Thread Steve D'Aprano
On Sat, 4 Nov 2017 05:12 am, Israel Brewster wrote: [...] >> People generally understand how to move data around, and the mistakes are >> usually pretty obvious when they happen. > > I think the existence of this thread indicates otherwise :-) This mistake > was far from obvious, and clearly I

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

2017-11-03 Thread Steve D'Aprano
On Sat, 4 Nov 2017 06:15 am, Michael Torrie wrote: > In fact if you have no break you may as well drop the > else entirely, because the block will always execute. That's incorrect. There are multiple ways to exit a loop that will prevent the `else` block from executing, `break` is only one.

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 <steve+pyt...@pearwood.info> 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

Re: Thread safety issue (I think) with defaultdict

2017-11-03 Thread Steve D'Aprano
On Sat, 4 Nov 2017 01:50 am, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 10:26 PM, Rhodri James wrote: >> I'm with Steven. To be fair, the danger with threads is that most people >> don't understand thread-safety, and in particular don't understand either >> that they

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

2017-11-03 Thread Steve D'Aprano
On Fri, 3 Nov 2017 09:13 pm, Serhiy Storchaka wrote: > What the interpreter or configuration do you use? The standard > interpreter uses '>>> ' as a prompt. I have this in my Python startup file: if (sys.version_info[0] >= 3 and os.name == 'posix' and os.environ['TERM'] in ['xterm',

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 <steve+pyt...@pearwood.info> writes: >> for x in something(): >> print(x, end='') > > print(''.join(something())) I hoped that people would recognise a simplified, toy example used only to illustra

Re: Thread safety issue (I think) with defaultdict

2017-11-02 Thread Steve D'Aprano
On Fri, 3 Nov 2017 02:32 pm, Stefan Ram wrote: > Here is an excerpt from a text from Edward E. Lee: > > A part of the Ptolemy Project experiment was to see > whether effective software engineering practices could be > developed for an academic research setting. [...] > No problems were

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: 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 <steve+pyt...@pearwood.info> 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' me

Re: Thread safety issue (I think) with defaultdict

2017-11-02 Thread Steve D'Aprano
On Fri, 3 Nov 2017 07:24 am, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 3:27 AM, Israel Brewster > wrote: >> >> Actually, that saying is about regular expressions, not threads :-) . In >> the end, threads are as good a way as handling concurrency as any other, >> and

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

2017-11-02 Thread Steve D'Aprano
On Fri, 3 Nov 2017 09:20 am, Terry Reedy wrote: > This seems like a bug in how Python interacts with your console. On > Windows, in Python started from an icon or in Command Prompt: > > >>> for c in 'abc': print(c, end='') > ... > abc>>> That's still unfortunate: the prompt is immediately

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

2017-11-02 Thread Steve D'Aprano
On Fri, 3 Nov 2017 12:39 am, Jon Ribbens wrote: > On 2017-11-01, Alexey Muranov wrote: >> what do you think about the idea of replacing "`else`" with "`then`" in >> the contexts of `for` and `try`? >> >> It seems clear that it should be rather "then" than "else."

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 <steve+pyt...@pearwood.info> writes: > > py> for x in "abcdefgh": > Steve> ... print(x, end='') > Steve> ... > py> efghpy&

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

2017-11-02 Thread Steve D'Aprano
On Thu, 2 Nov 2017 10:09 pm, Ben Bacarisse wrote: > Sure, but your argument seemed to that else has entirely the wrong > meaning (I certainly to a double take when I have to remember what it > means) and, in that context, finally has a meaning closer to what you > want. That's an argument about

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 wors

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

2017-11-02 Thread Steve D'Aprano
Occasionally it is useful to loop over a bunch of stuff in the interactive interpreter, printing them as you go on a single line: for x in something(): print(x, end='') If you do that, the prompt overwrites your output, and you get a mess: py> for x in "abcdefgh": ... print(x, end='')

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

2017-11-02 Thread Steve D'Aprano
On Thu, 2 Nov 2017 12:49 pm, Skip Montanaro wrote: > I don't know. The word "then" doesn't connote different ways of exiting a > loop to me ("else" doesn't really either, I will grant you that, but it's > what we have). Here's how I would read things: > >- *while* some condition holds,

Re: what exactly does type.__call__ do?

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 10:13 am, Jason Maldonis wrote: > Hi everyone, > > I want to use a metaclass to override how class instantiation works. I've > done something analogous to using the Singleton metaclass from the Python3 > Cookbook example. In my opinion, nine times out of ten, using a

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 <steve+pyt...@pearwood.info> 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

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

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 08:23 am, Ned Batchelder wrote: > Apart from the questions of backward compatibility etc (Python is > unlikely to ever go through another shift like the 2/3 breakage), are > you sure "then" is what you mean?  This won't print "end": > > for i in range(10): > print(i) >

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

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 08:21 am, Chris Angelico wrote: > With the 'for' loop, > it's a bit more arguable, but I've never seen anything more than a > weak argument in favour of 'then' Thhpptpt! "else" is an completely inappropriate term that doesn't describe the semantics of the statement even a

Re: Code Snippets

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 08:02 am, Ben Bacarisse wrote: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > >> Wolfgang Maier writes: >>>If you're worried bout having things on separate lines, you could write: >>>import os; os.getcwd() >>>,etc., which is actually

Re: Code Snippets

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 05:57 am, Stefan Ram wrote: > I also have heard that there was a module cache, so I > was hoping that a second import of the same module might > not be such an effort for the implementation. There is: sys.modules. Although `import spam` is cheap when spam is in the cache,

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

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 08:12 am, Alexey Muranov wrote: > Hello, > > what do you think about the idea of replacing "`else`" with "`then`" in > the contexts of `for` and `try`? Yes, this, exactly!!! (For while and for loops, but not try -- see below.) I have argued this for many years. The current

Re: Thread safety issue (I think) with defaultdict

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 05:53 am, Israel Brewster wrote: [...] > So the end result is that the thread that "updates" the dictionary, and the > thread that initially *populates* the dictionary are actually running in > different processes. If they are in different processes, that would explain why the

Re: Code Snippets

2017-11-01 Thread Steve D'Aprano
On Thu, 2 Nov 2017 04:25 am, Stefan Ram wrote: > I started to collect some code snippets: [...] > __import__( "random" ).random() > > And so on. You get the idea. > > However, reportedly, all those snippets are anti-patterns > because they use »__import__«. Correct. Nearly all dunder

Re: Performance of map vs starmap.

2017-10-31 Thread Steve D'Aprano
On Mon, 30 Oct 2017 09:10 pm, Kirill Balunov wrote: > Sometime ago I asked this question at SO [1], and among the responses > received was paragraph: > > - `zip` re-uses the returned `tuple` if it has a reference count of 1 when > the `__next__` call is made. > - `map` build a new `tuple` that

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

2017-10-31 Thread Steve D'Aprano
On Wed, 1 Nov 2017 02:29 am, Neil Cerutti wrote: > You can use the % operator instead of +, and a generator > expression instead of map. It's a pretty small improvement, > though. > > values = '||%s||' % ('||'.join(str(s) for s in value_list)) > > At least... I THINK you can use that generator

Re: Invoking return through a function?

2017-10-30 Thread Steve D'Aprano
On Tue, 31 Oct 2017 02:26 pm, Rustom Mody wrote: > My own feeling about lisp-macros is conflicted: > - They are likely the most unique feature of lisp, putting it at the top of > the blub-language tower > - They are the single reason Lisp can never succeed like mainstream > languages: Any

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 > <steve+pyt...@pearwood.info> wrote: >> Python has no GOTO, fortunately, but C has at least two, GOTO and LONGJMP. >> A C macro could, if I understand correctly, jump in

Re: Invoking return through a function?

2017-10-30 Thread Steve D'Aprano
On Tue, 31 Oct 2017 01:06 pm, Alberto Riva wrote: > On 10/30/2017 10:27 AM, Rhodri James wrote: [...] >> You can do the same in C.  I've had the displeasure of trying to >> maintain such code.  It was near-unreadable, because it constantly broke >> your expectations of what the code flow *could*

Re: ValueError: Error 3 while encrypting in ECB mode

2017-10-29 Thread Steve D'Aprano
On Mon, 30 Oct 2017 01:20 pm, Ho Yeung Lee wrote: from Crypto.Cipher import AES key = 'mysecretpassword' plaintext = 'Secret Message A' encobj = AES.new(key, AES.MODE_ECB) ciphertext = encobj.encrypt("hello") > Traceback (most recent call last): > File "", line 1,

Re: Invoking return through a function?

2017-10-29 Thread Steve D'Aprano
On Mon, 30 Oct 2017 06:09 am, Alberto Riva wrote: > But that's exactly why I would like to be able to use macros. I think > that being able to write "return if this happens" is much more explicit > than having to write the full if statement, every time. There have been proposals in the past for

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,” they

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 name that w

Re: Invoking return through a function?

2017-10-29 Thread Steve D'Aprano
On Mon, 30 Oct 2017 01:18 am, Alberto Riva wrote: > Hello, > > I'm wondering if there is a way of writing a function that causes a > return from the function that called it. To explain with an example, > let's say that I want to exit my function if a dict does not contain a > given key. I could

Re: Compression of random binary data

2017-10-29 Thread Steve D'Aprano
On Sun, 29 Oct 2017 01:56 pm, Stefan Ram wrote: > If the entropy of an individual message is not defined, > than it is still available to be defined. I define it > to be log2(1/p), where p is the probability of this > message. I also choose a unit for it, which I call "bit". That is

Re: Compression of random binary data

2017-10-29 Thread Steve D'Aprano
On Sun, 29 Oct 2017 06:03 pm, Chris Angelico wrote: > On Sun, Oct 29, 2017 at 6:00 PM, Ian Kelly wrote: >> On Oct 28, 2017 5:53 PM, "Chris Angelico" wrote: >>> One bit. It might send the message, or it might NOT send the message. >> >> Not sending the

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-information >

Re: Compression of random binary data

2017-10-28 Thread Steve D'Aprano
On Sun, 29 Oct 2017 07:03 am, Peter Pearson wrote: > On Thu, 26 Oct 2017 19:26:11 -0600, Ian Kelly wrote: >> >> . . . Shannon entropy is correctly calculated for a data source, >> not an individual message . . . > > Thank you; I was about to make the same observation.

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 cheered up, and sure enough,

  1   2   3   4   5   6   7   8   9   10   >