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 simpler than many. They h

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 up,

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 observed

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
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', 'vt1

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 have a responsibility t

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
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: 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 di

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

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: 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. -- https://mail.python.org/mailm

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 sa

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
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 to use in my > begin

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 read that sentence several times, and I still can't mak

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

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: 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 double-cl

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

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 said

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 cheered

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 bet

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 > wrote: >> >> On 06/12/2017 00:16, Steve D'Aprano wrote: >>> >>> Anyone got a handy copy of Python 3.6 available to test something for me? >>> >

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 runs. >> >> We were all once "du

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 > - internet/US

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 > declaimed the following: > > >>I wouldn't want to guess your mental health based just on this isolated >>incident, but if I had to make a diagno

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' &

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 online and you can't find

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: 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: 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 valu

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

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 s

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 dou

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 i

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. >> >> We were all once "dum

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 > wrote: >> >> On 06/12/2017 00:16, Steve D'Aprano wrote: >>> >>> Anyone got a handy copy of Python 3.6 available to test something for me? >>> >

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 ch

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 i

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 o

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 s

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 > wrote: >> Remember the context here: we're replying to a thread discussing somebody >> who is running Ubuntu with a GUI desktop environment. Of course there are &

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, “th

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 can tell us a lot about > what

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(" ", "h

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

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 op

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 wrong,

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

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 some 10 ns. Th

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! I

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 loo

[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-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-p

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. > > https://www.rdocumentation.org/packages/utils/versions

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: 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: help

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: https://docs.python.org/2/re

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: 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 whe

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 AlphaG

Re: type lookuperror

2016-08-18 Thread Steve D'Aprano
On Fri, 19 Aug 2016 11:43 am, meInvent bbird wrote: > a company which write siri in iphone, has already wrote a program > which can write program itself after the program talks with users > > it seems possible, You are asking about self-modifying code, which is a terrible idea. Siri uses machin

Re: type lookuperror

2016-08-18 Thread Steve D'Aprano
On Fri, 19 Aug 2016 02:30 am, Chris Angelico wrote: > On Fri, Aug 19, 2016 at 2:21 AM, Marko Rauhamaa wrote: >> >> Yeah, I believe truly conscious machines will arise without being >> designed through technological evolution. First they'll develop >> electronics that can simulate brain cells; the

Re: integer's methods

2016-08-18 Thread Steve D'Aprano
On Thu, 18 Aug 2016 10:58 pm, ast wrote: > Hello > > I wonder why calling a method on an integer > doesn't work ? > 123.bit_length() > SyntaxError: invalid syntax Because Python thinks you are writing a float, and "b" is not a valid digit. Try: (123).bit_length() 123 .bit_length() i

Re: Nuitka Release 0.5.22

2016-08-19 Thread Steve D'Aprano
On Thu, 18 Aug 2016 06:58 am, breamore...@gmail.com wrote: > As Kay (him) is less than useless at sales and marketing, somebody has to > do it, so here you are folks > http://nuitka.net/posts/nuitka-release-0522.html Thanks for the link. -- Steve “Cheer up,” they said, “things could be worse.

Re: index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread Steve D'Aprano
On Fri, 19 Aug 2016 09:14 pm, iMath wrote: > > for > regex.search(string[, pos[, endpos]]) > The optional parameter endpos is the index into the string beyond which > the RE engine will not go, while this lead me to believe the RE engine > will still search on till the endpos position even after

Re: index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread Steve D'Aprano
On Fri, 19 Aug 2016 09:21 pm, Jon Ribbens wrote: > On 2016-08-19, iMath wrote: >> for >> regex.search(string[, pos[, endpos]]) >> The optional parameter endpos is the index into the string beyond >> which the RE engine will not go, while this lead me to believe the >> RE engine will still search

Re: saving octet-stream png file

2016-08-19 Thread Steve D'Aprano
On Sat, 20 Aug 2016 06:51 am, Lawrence D’Oliveiro wrote: > On Saturday, August 20, 2016 at 6:03:53 AM UTC+12, Terry Reedy wrote: >> >> An 'octet' is a byte of 8 bits. > > Is there any other size of byte? Depends what you mean by "byte", but the short answer is "Yes". In the C/C++ standard, byt

Re: Holding until next value change

2016-08-19 Thread Steve D'Aprano
On Sat, 20 Aug 2016 02:53 pm, Arshpreet Singh wrote: > I am writing a function as main_call() which is continuously producing > values. (+ve or -ve) I want to print on screen only for first +ve value > and hold until -ve value comes around. here is my code: > > > def main_call(): > while Tru

Re: Two-Dimensional Expression Layout

2016-08-20 Thread Steve D'Aprano
On Sun, 21 Aug 2016 08:22 am, Lawrence D’Oliveiro wrote: > Another example, from : the sequence of > values is laid out to allow easy additions/modifications in future. When replying, I normally try to trim unnecessary code snippets down to the critical line or two

Re: Two-Dimensional Expression Layout

2016-08-20 Thread Steve D'Aprano
On Sun, 21 Aug 2016 09:44 am, Lawrence D’Oliveiro wrote: > Why do you think I put in those “#end” lines? Do you really want us to answer that? I don't think you will like the answer. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse

Re: Two-Dimensional Expression Layout

2016-08-20 Thread Steve D'Aprano
On Sun, 21 Aug 2016 10:43 am, Michael Selik wrote: > On Sat, Aug 20, 2016 at 6:21 PM Lawrence D’Oliveiro > wrote: > >> > p0 = (0, 0) >> > p1 = (major_dim, 0) >> > colour_stops = (0, rect_1_colour), (1, complement(rect_1_colour)) >> > rect_1_pattern = qah.Pattern.create_linear(p0,

Re: Two-Dimensional Expression Layout

2016-08-20 Thread Steve D'Aprano
Oh wait! The penny drops! On Sun, 21 Aug 2016 10:43 am, Michael Selik wrote: > On Sat, Aug 20, 2016 at 6:21 PM Lawrence D’Oliveiro >> >> if ( >> >> not isinstance(src, Image) >> >> or >> >> mask != None and not isinstance(mask, Image) >> >> or >> >>

Re: Does This Scare You?

2016-08-21 Thread Steve D'Aprano
On Mon, 22 Aug 2016 10:38 am, eryk sun wrote: > To me it's scary that this check misses cases because it's trying to > be cross-platform instead of simply relying on GetFullPathName to do > the work. For example, it misses at least the following cases: Instead of shaking in your boots over a simp

Re: Does This Scare You?

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 08:33 pm, Jon Ribbens wrote: > On 2016-08-22, Steve D'Aprano wrote: >> On Mon, 22 Aug 2016 10:38 am, eryk sun wrote: >>> To me it's scary that this check misses cases because it's trying to >>> be cross-platform instead of simply rel

Re: PEP suggestion: Uniform way to indicate Python language version

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 08:32 pm, rocky wrote: > On Monday, August 22, 2016 at 1:36:07 AM UTC-4, Steven D'Aprano wrote: [...] >> But... I don't understand what this proposal actually is. We already have >> a uniform way to indicate the Python language version: check sys.version, >> or sys.version_info

Re: Does This Scare You?

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 09:50 pm, Jon Ribbens wrote: > On 2016-08-22, Chris Angelico wrote: >> On Mon, Aug 22, 2016 at 8:33 PM, Jon Ribbens >> wrote: >>> On 2016-08-22, Steve D'Aprano wrote: >>>> On Mon, 22 Aug 2016 10:38 am, eryk sun wrote: >>&g

Re: PEP suggestion: Uniform way to indicate Python language version

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 10:52 pm, Random832 wrote: > On Mon, Aug 22, 2016, at 08:44, Chris Angelico wrote: >> However, I don't think it's particularly necessary. Explicit version >> number checks should be very rare, and shouldn't be encouraged. >> Instead, encourage feature checks, as Steve gave some

Re: Does This Scare You?

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 10:56 pm, Random832 wrote: > On Mon, Aug 22, 2016, at 08:39, Chris Angelico wrote: >> Nope. On Windows, you would try/except it. > > No, you can't, because the failure mode often isn't "file refuses to > open" but "data is written to a serial port". Ah, that's a good point. I

Re: Does This Scare You?

2016-08-22 Thread Steve D'Aprano
On Tue, 23 Aug 2016 03:13 am, eryk sun wrote: > But if they open files > like "C:\Users\JoeUser\Documents\Nul.20160822.doc", I want to make > sure they know that they just asked to save to "\\.\NUL". It's not a > common problem. I just find the system's behavior abhorrent. I'd like > to have a man

Re: Python script for searching variable strings between two constant strings

2016-08-26 Thread Steve D'Aprano
On Sat, 27 Aug 2016 08:33 am, ddream.mercha...@gmail.com wrote: > My log file has several sections starting with START and ending > with END . Um. Is this relevant? Are you saying that you only wish to search the file between those lines, and ignore anything outside of them?

Re: What's the best way to minimize the need of run time checks?

2016-08-27 Thread Steve D'Aprano
On Sun, 28 Aug 2016 12:31 pm, Juan Pablo Romero Méndez wrote: > 2016-08-14 7:29 GMT-07:00 Steven D'Aprano : > >> On Thu, 11 Aug 2016 06:33 am, Juan Pablo Romero Méndez wrote: >> >> > I've been trying to find (without success so far) an example of a >> > situation where the dynamic features of a l

Re: What's the best way to minimize the need of run time checks?

2016-08-28 Thread Steve D'Aprano
On Sun, 28 Aug 2016 07:28 pm, Chris Angelico wrote: > On Sun, Aug 28, 2016 at 6:33 PM, Steven D'Aprano > wrote: >> On Sunday 28 August 2016 15:29, Chris Angelico wrote: >>> It might be a good way of thinking about points on a Cartesian plane, >>> though. Rectangular and polar coordinates truly ar

Re: Is duck-typing misnamed?

2016-08-28 Thread Steve D'Aprano
On Sun, 28 Aug 2016 08:34 am, Terry Reedy wrote: > On 8/26/2016 7:58 PM, ROGER GRAYDON CHRISTMAN wrote: >> "If it walks like a duck, quacks like a duck,... " >> >> so there is indeed precedence for this so-called 'duck typing' >> >> >> but wouldn't it be more Pythonic to call this 'witch typing'?

Re: What's the best way to minimize the need of run time checks?

2016-08-29 Thread Steve D'Aprano
On Mon, 29 Aug 2016 10:31 pm, Chris Angelico wrote: > On Mon, Aug 29, 2016 at 10:13 PM, BartC wrote: >> In C, you can write this: >> >> int x; >> >> x = 5; >> x = "hello"; >> >> With certain compilers (eg. gcc) you only get a warning. (And since I >> don't show warnings to avoid inundation, th

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-03 Thread Steve D'Aprano
On Sun, 4 Sep 2016 06:47 am, Thomas 'PointedEars' Lahn wrote: > Your posting is lacking a real name in the “From” header field. Thomas, if that is really your name, how do we know that: Thomas 'PointedEars' Lahn is a real name? Is sounds made up to me. I'm afraid that we're going to have

Re: Pythons for .Net

2016-09-03 Thread Steve D'Aprano
On Sat, 3 Sep 2016 12:34 pm, Denis Akhiyarov wrote: > Finally if anyone can contact Christian Heimes (Python Core Developer), > then please ask him to reply on request to update the license to MIT: > > https://github.com/pythonnet/pythonnet/issues/234 > > He is the only contributor that prevents

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-03 Thread Steve D'Aprano
On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: [...] >> Please either comply, or give up your stupid and pointless obsession with >> trying to be the Internet Police for something that isn't even a real >> rule. > > His posts aren't making it across the news->list gateway any more. > Killfile

Re: manually sorting images?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 06:53 pm, Ulli Horlacher wrote: > I need to sort images (*.jpg), visually, not by file name. I don't even understand this. What does it mean to sort images visually? Which comes first, a 400x500 image of a cat climbing a tree, or a 300x600 image of a toddler playing with a dog?

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 06:53 pm, Thomas 'PointedEars' Lahn wrote: >> Regarding the name (From field), my name *is* Veek.M […] > > Liar. *plonk* You have crossed a line now Thomas. That is absolutely uncalled for. You have absolutely no legitimate reason to believe that Veek is not his or her real

Why doesn't my finaliser run here?

2016-09-04 Thread Steve D'Aprano
Here's a finaliser that runs: class Spam(object): def __new__(cls): instance = object.__new__(cls) print("instance created successfully") return instance def __del__(self): print("deleting", repr(self)) An example: py> s = Spam(); del s instance created

Re: Why doesn't my finaliser run here?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 10:37 pm, Ben Finney wrote: > Steve D'Aprano writes: > >> Why doesn't __del__ run here? > > Short anser: because nothing has removed the reference to the instance. Hmmm. You're probably right, but not for the reason you think :-) >>

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