Re: Verifiably better, validated Enum for Python

2017-05-24 Thread Steve D'Aprano
On Wed, 24 May 2017 01:47 pm, breamore...@gmail.com wrote: > Well that's what is says here https://github.com/ofek/venum so it must be > true. Please move over Ethan, your time is up :-) The page says: venum provides an Enum that is actually just a namedtuple, but easier to create. Thi

Re: Verifiably better, validated Enum for Python

2017-05-24 Thread Steve D'Aprano
On Wed, 24 May 2017 10:07 pm, Chris Angelico wrote: > On Wed, May 24, 2017 at 7:10 PM, Steve D'Aprano > wrote: >> Although I wonder: >> >> - maybe the enumeration (the class ContentTypes) could have a nicer repr >> than >> >> >> >> -

Re: Top Python Interview Questions

2017-05-26 Thread Steve D'Aprano
On Fri, 26 May 2017 03:32 pm, Terry Reedy wrote: >> Python files are compiled to bytecode. > > CPython compiles to cpython bytecode. > Jython compiles to Java. > Iron Python compiles to C#. Technically, they compile to the JVM byte code and the .Net Common Runtime (I forget the three letter acro

Re: Verifiably better, validated Enum for Python

2017-05-26 Thread Steve D'Aprano
On Thu, 25 May 2017 11:26 am, Chris Angelico wrote: > On Thu, May 25, 2017 at 9:34 AM, bartc wrote: >> That was quite likely with older Fortrans, where subroutines only used >> pass-by-reference, but which didn't stop you passing references to >> constants that the subroutine could then modify. >

Re: adding type hints to one of my projects, things learned

2017-05-26 Thread Steve D'Aprano
On Thu, 25 May 2017 08:37 am, Irmen de Jong wrote: > Hi, > > I wanted to share my experience with adding type hints to one of my > projects. Thanks for the write-up! [...] > Right now, I am not really sure if I want to continue to use type hints. > In Tale I probably will because it now has the

Re: Verifiably better, validated Enum for Python

2017-05-26 Thread Steve D'Aprano
On Fri, 26 May 2017 10:56 pm, Rhodri James wrote: > On 26/05/17 12:46, Steve D'Aprano wrote: >> On Thu, 25 May 2017 11:26 am, Chris Angelico wrote: >> >>> On Thu, May 25, 2017 at 9:34 AM, bartc wrote: >>>> That was quite likely with older Fortrans,

Re: Verifiably better, validated Enum for Python

2017-05-26 Thread Steve D'Aprano
On Fri, 26 May 2017 10:01 pm, Chris Angelico wrote: >> That's not how the C standard defines "undefined behaviour", or the >> implication of such. > > Can you explain to me how it's different? Either way, the > implementation is allowed to do what it likes, because you shouldn't > be doing that.

Re: Verifiably better, validated Enum for Python

2017-05-26 Thread Steve D'Aprano
On Sat, 27 May 2017 09:36 am, Chris Angelico wrote: > On Sat, May 27, 2017 at 8:48 AM, Steve D'Aprano > wrote: >> I don't actually believe that any real compiler will *literally* contain >> code that looks like this: >> >> >> if phase_of_moon(now())

Re: Top Python Interview Questions

2017-05-26 Thread Steve D'Aprano
On Sat, 27 May 2017 09:37 am, Chris Angelico wrote: > On Sat, May 27, 2017 at 8:56 AM, Larry Martell > wrote: >> If they write a loop with range(1,10) they are going in the 'no' pile. >> If they write a loop with range(1,11) they go in the maybe pile >> If the write sum([i*i for i in range(1,11)]

Re: Verifiably better, validated Enum for Python

2017-05-26 Thread Steve D'Aprano
On Sat, 27 May 2017 02:20 pm, Chris Angelico wrote: > On Sat, May 27, 2017 at 12:59 PM, Steve D'Aprano > wrote: >>> What is a standards-compliant Python interpreter allowed to do? >> >> There's no such thing, so your question is moot. >> >> Ther

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-27 Thread Steve D'Aprano
On Sun, 28 May 2017 10:51 am, Bill Deegan wrote: > Greetings, > > As a follow up to a discussion on IRC #python channel today. > > Assuming the same order of insertions of the same items to a dictionary > would the iteration of a dictionary be the same (not as the order of > insertion, just from

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-28 Thread Steve D'Aprano
On Sun, 28 May 2017 11:12 pm, Jon Ribbens wrote: > On 2017-05-28, Bill Deegan wrote: >> As a follow up to a discussion on IRC #python channel today. >> >> Assuming the same order of insertions of the same items to a dictionary >> would the iteration of a dictionary be the same (not as the order o

Re: Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

2017-05-28 Thread Steve D'Aprano
On Mon, 29 May 2017 12:15 am, Jon Ribbens wrote: > On 2017-05-28, Steve D'Aprano wrote: >> What exactly did you think I got wrong? > > 3.6 does preserve the dict order. It isn't a guarantee so may change > in future versions, but it is what 3.6 actually does. Did

Re: How to `eval` code with `def`?

2017-05-28 Thread Steve D'Aprano
On Mon, 29 May 2017 11:03 am, Peng Yu wrote: > Hi, > > I got the following error when I try to eval the following code with > def. Does anybody know what is the correct way to evaluation python > code that contains `def`? Thanks. > > $ cat ./main.py > #!/usr/bin/env python > # vim: set noexpandt

Three good posts on speeding up CPython

2017-05-29 Thread Steve D'Aprano
http://www.corsix.org/content/micro-optimisations-can-speed-up-cpython https://www.corsix.org/content/compilers-cpython-interpreter-main-loop https://www.corsix.org/content/why-are-slots-so-slow -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things

Re: Overriding methods on a per instance basis

2017-05-30 Thread Steve D'Aprano
On Tue, 30 May 2017 12:00 pm, Kunal Jamdade wrote: > I tried to understand overriding methods on per instance class. But i am > not getting it. Can you help me in getting the mail. Or can u suggest me at > least what should i read before reading "this topic"? > > Can you explain me with one more

Re: zeep, infinite recursion

2017-05-31 Thread Steve D'Aprano
On Tue, 30 May 2017 05:58 pm, Nagy Lc3a1szlc3b3 Zsolt wrote: >> It was easier than I thought. It seems that zeep has a problem >> processing a basic WS-Security STS (Security Token Service, plain >> username+password authentication) document. I have changed the endpoint >> URL to example.com. Tota

Re: Working with dictionaries and keys help please!

2017-06-01 Thread Steve D'Aprano
On Thu, 1 Jun 2017 10:29 am, David D wrote: > I have a dictionary with a 10 people, the key being a number (0-10) and the > value being the people's name. I am in the processing of Insert, Adding and > deleting from the dictionary. All seems well until I delete a person and add > a new one. The

Re: [OT] How to improve my programming skills?

2017-06-01 Thread Steve D'Aprano
On Fri, 2 Jun 2017 01:26 am, Mirko wrote: > TLDR: Sorry for OT. Long-time Linux geek and hobby programmer wants > to improve his coding skills. What's most important: project > planing, algorithms and data structures, contributing to FOSS, web > development, learning other languages or something e

Re: Is An Element of a Sequence an Object?

2017-06-03 Thread Steve D'Aprano
On Sun, 4 Jun 2017 05:10 am, Jon Forrest wrote: > I'm learning about Python. A book I'm reading about it > says "... a string in Python is a sequence. A sequence is an ordered > collection of objects". This implies that each character in a string > is itself an object. Which book is this? Because

Re: Is An Element of a Sequence an Object?

2017-06-04 Thread Steve D'Aprano
On Sun, 4 Jun 2017 05:48 pm, Larry Hudson wrote: > On 06/03/2017 09:39 PM, Chris Angelico wrote: >> That's a tricky thing to pin down. Since it's possible for a sequence >> to contain itself, or to contain something which contains it, > > Like a Tardis? > > [Sorry, couldn't resist...] ;-) Exa

Re: Is An Element of a Sequence an Object?

2017-06-04 Thread Steve D'Aprano
On Sun, 4 Jun 2017 04:50 pm, Peter Otten wrote: > Steven D'Aprano wrote: >> In Python 3, for example: >> >> > import sys > sys.getsizeof("abcde") # actual memory consumption >> 54 > sum(sys.getsizeof(c) for c in "acbde") # theoretical >> 250 >> >> >> So we can tell the two imple

Re: Bug or intended behavior?

2017-06-06 Thread Steve D'Aprano
On Wed, 7 Jun 2017 03:16 am, Terry Reedy wrote: >> Personally I prefer a less compact but more explicit alternative: >> >> "foo {}".format(1-2) > > More compact: > >>> f'foo {1-2}' > 'foo -1' Also more mysterious and magical, and not backwards compatible. "Good news everybody! We have

Re: Generator and return value

2017-06-07 Thread Steve D'Aprano
On Wed, 7 Jun 2017 05:09 pm, Jussi Piitulainen wrote: > Frank Millman writes: > >> It would be nice to write a generator in such a way that, in addition >> to 'yielding' each value, it performs some additional work and then >> 'returns' a final result at the end. >> >>> From Python 3.3, anything

Re: Hello from a super noob!

2017-06-07 Thread Steve D'Aprano
On Thu, 8 Jun 2017 09:56 am, CB wrote: > Can anyone try to run it? Yes, you can. Doctor to patient: "So, what seems to be the problem?" Patient: "You're the doctor, you tell me." -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse.

Re: Bug or intended behavior? (Posting On Python-List Prohibited)

2017-06-09 Thread Steve D'Aprano
On Fri, 9 Jun 2017 02:23 pm, Lawrence D’Oliveiro wrote: > The indentation itself doesn’t provide enough grouping, cf > . Your argument is: "Now, what happens if these pieces of code get posted online somewhere,

Re: Bug or intended behavior? (Posting On Python-List Prohibited)

2017-06-09 Thread Steve D'Aprano
On Fri, 9 Jun 2017 02:13 pm, Lawrence D’Oliveiro wrote: > On Sunday, June 4, 2017 at 9:59:11 AM UTC+12, Sean DiZazzo wrote: >> Looking at operator precedence, I only see the % operator in regards to >> modulus. Nothing in regards to string formatting. > > Operators in Python have no intrinsic me

Re: Is An Element of a Sequence an Object?

2017-06-09 Thread Steve D'Aprano
On Fri, 9 Jun 2017 02:04 pm, Lawrence D’Oliveiro wrote: > I generally have very little use for “is” in my code. I do try it out for > testing sometimes, to ensure consistency of semantic behaviour in library > bindings for example, but I don’t think I have ever written an “is”-construct > in produ

Python Language Summit: Keeping Python competitive

2017-06-10 Thread Steve D'Aprano
Python 3.7 (unstable) is now as fast as Python 2.7, but some of the core developers are hoping to improve matters, aiming for a 2 x speed improvement to keep Python competitive with other languages. https://lwn.net/Articles/723949/ -- Steve “Cheer up,” they said, “things could be worse.” So I

Progress on the Gilectomy

2017-06-10 Thread Steve D'Aprano
Larry Hastings is working on removing the GIL from CPython: https://lwn.net/Articles/723949/ For those who don't know the background: - The GIL (Global Interpreter Lock) is used to ensure that only one piece of code can update references to an object at a time. - The downside of the GIL is tha

Re: Progress on the Gilectomy

2017-06-10 Thread Steve D'Aprano
On Sun, 11 Jun 2017 04:21 pm, Stefan Behnel wrote: > Serhiy Storchaka schrieb am 11.06.2017 um 07:11: >> And also GIL is used for guaranteeing atomicity of many operations and >> consistencity of internal structures without using additional locks. Many >> parts of the core and the stdlib would j

Re: Generate PDF with Tamil font problem

2017-06-12 Thread Steve D'Aprano
On Mon, 12 Jun 2017 05:51 pm, ccubed...@gmail.com wrote: > On Saturday, 5 March 2011 10:50:25 UTC+5:30, sath...@e-ndicus.com wrote: >> Hi All, >> >>I am using python's reportlab to print some unicode Tamil characters >> 'பே'. I added necessary unicode font to reportlab. But It >> prints the

Re: Developers Who Use Spaces Make More Money!

2017-06-15 Thread Steve D'Aprano
On Fri, 16 Jun 2017 08:42 am, Chris Angelico wrote: > On Fri, Jun 16, 2017 at 8:24 AM, wrote: >> This is hilarious, I have to share: >> >> https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/ >> >> Thanks to Guido for making us all richer! > > Bah, that's just noise.

Re: Progress on the Gilectomy

2017-06-21 Thread Steve D'Aprano
On Thu, 22 Jun 2017 08:23 am, breamore...@gmail.com wrote: > Don't you know that Lawrence D’Oliveiro has been banned from the mailing list > as he hasn't got a clue what he's talking about, That's not why he was given a ban. Being ignorant is not a crime -- if it were, a lot more of us would be

Re: Progress on the Gilectomy (Posting On Python-List Prohibited)

2017-06-21 Thread Steve D'Aprano
On Thu, 22 Jun 2017 10:30 am, Lawrence D’Oliveiro wrote: > Once again: The trouble with GC is, it doesn’t know when to kick in: it just > keeps on allocating memory until it runs out. Once again: no it doesn't. Are you aware that CPython has a GC? (Or rather, a *second* GC, apart from the refer

Re: Instagram: 40% Py3 to 99% Py3 in 10 months (Posting On Python-List Prohibited)

2017-06-22 Thread Steve D'Aprano
On Wed, 21 Jun 2017 09:23 am, Lawrence D’Oliveiro wrote: > Though the Perl 6 folks claim their approach (encoding “characters” rather > than “code points”) is superior. Can you explain what you are referring to precisely? According to the Perl 6 docs, they do encode code points, not "characters"

Re: Best way to ensure user calls methods in correct order?

2017-06-22 Thread Steve D'Aprano
On Thu, 22 Jun 2017 11:53 pm, Thomas Nyberg wrote: > I have a situation in which I want a user to call methods in a certain > order and to force the re-calling of methods "down-stream" if upstream > methods are called again. Don't do that. It's fragile and an anti-pattern. Your methods have too m

Re: Instagram: 40% Py3 to 99% Py3 in 10 months (Posting On Python-List Prohibited)

2017-06-22 Thread Steve D'Aprano
On Thu, 22 Jun 2017 11:57 pm, Chris Angelico wrote: > On Thu, Jun 22, 2017 at 11:33 PM, Steve D'Aprano > wrote: >> and besides some Unicode code points are not >> characters at all). >> >> http://www.unicode.org/faq/private_use.html#noncharacters > >

Re: Progress on the Gilectomy

2017-06-22 Thread Steve D'Aprano
On Fri, 23 Jun 2017 01:07 am, breamore...@gmail.com wrote: > 11 comments on the thread "Instagram: 40% Py3 to 99% Py3 in 10 months" showing > that he knows as much about Unicode as LDO knows about garabge collection. Who cares? Every time he opens his mouth to write absolute rubbish he just make

Re: Deleting An Optional Dict Entry (Posting On Python-List Prohibited)

2017-06-23 Thread Steve D'Aprano
On Fri, 23 Jun 2017 07:19 pm, Lawrence D’Oliveiro wrote: > The construct > > del «dict»[«key»] > > deletes the entry with key «key» from the dictionary «dict», provided it > exists. If it does not, you get a KeyError. > > To delete an entry which might or might not exist, the simplest way i

Checking for an exception

2017-06-24 Thread Steve D'Aprano
What's the right/best way to test whether an object is an exception ahead of time? (That is, without trying to raise from it.) I have: return (isinstance(obj, type) and issubclass(obj, BaseException) or isinstance(obj, BaseException)) Any better ideas? -- Steve “Cheer up,” they said

Re: Checking for an exception

2017-06-24 Thread Steve D'Aprano
On Sat, 24 Jun 2017 09:23 pm, mbyrne...@gmail.com wrote: > On Saturday, June 24, 2017 at 11:31:11 AM UTC+1, Steve D'Aprano wrote: >> What's the right/best way to test whether an object is an exception ahead of >> time? (That is, without trying to raise from it.) >

Re: os.walk the apostrophe and unicode

2017-06-24 Thread Steve D'Aprano
On Sun, 25 Jun 2017 07:17 am, Peter Otten wrote: > Then I'd fix the name manually... The file name isn't broken. What's broken is parts of the OP's code which assumes that non-ASCII file names are broken... -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure e

Re: environment variable

2017-06-24 Thread Steve D'Aprano
On Sun, 25 Jun 2017 08:39 am, Gene Heskett wrote: > On Saturday 24 June 2017 16:49:25 Smith wrote: > >> Hello to all, >> I wanted to ask you how I could delete a line of an environment >> variable (PATH) [...] > export PATH= > > but be prepared to type the full path to anything you want to run.

Re: Checking for an exception

2017-06-24 Thread Steve D'Aprano
On Sun, 25 Jun 2017 09:37 am, Cameron Simpson wrote: > On 24Jun2017 20:31, Steve D'Aprano wrote: >>What's the right/best way to test whether an object is an exception ahead of >>time? (That is, without trying to raise from it.) >> >>I have: >> >>

Re: Checking for an exception

2017-06-24 Thread Steve D'Aprano
On Sun, 25 Jun 2017 10:49 am, Ben Finney wrote: > Steve D'Aprano writes: > >> What's the right/best way to test whether an object is an exception >> ahead of time? (That is, without trying to raise from it.) > > This being Python, it is Easier to Ask for

Re: os.walk the apostrophe and unicode

2017-06-25 Thread Steve D'Aprano
On Sun, 25 Jun 2017 04:57 pm, Peter Otten wrote: > Steve D'Aprano wrote: > >> On Sun, 25 Jun 2017 07:17 am, Peter Otten wrote: >> >>> Then I'd fix the name manually... >> >> The file name isn't broken. >> >> >> W

Re: Checking for an exception

2017-06-25 Thread Steve D'Aprano
On Sun, 25 Jun 2017 05:50 pm, Paul Rubin wrote: > Steve D'Aprano writes: >> What's the right/best way to test whether an object is an exception >> ahead of time? (That is, without trying to raise from it.) > > Maybe I'm missing something but >isinstanc

exception_guard context manager and decorator

2017-06-25 Thread Steve D'Aprano
As discussed in the Python-Ideas mailing list, sometimes we want to suppress a particular kind of exception and replace it with another. For that reason, I'd like to announce exception_guard, a context manager and decorator which catches specified exceptions and replaces them with a given exceptio

Re: Checking for an exception

2017-06-25 Thread Steve D'Aprano
On Mon, 26 Jun 2017 02:40 am, Skip Montanaro wrote: >> py> isinstance(KeyboardInterrupt(), Exception) >> False >> py> isinstance(ValueError, Exception) >> False >> > > I might have missed something, but don't you want to be using BaseException > as your class/type? Yes I do, which is why I was

Re: comments and the continuation prompt

2017-06-25 Thread Steve D'Aprano
On Mon, 26 Jun 2017 08:44 am, Stefan Ram wrote: > When I enter »12\«, I get a continuation prompt in the > Python 3.6 console: > 12\ > ... > > . I thought that this might indicate that the logical line > is not terminated yet. No. You get the level 2 prompt (sys.ps2) for a number o

Re: comments and the continuation prompt

2017-06-26 Thread Steve D'Aprano
On Mon, 26 Jun 2017 01:32 pm, Ben Finney wrote: > Steve D'Aprano writes: > >> On Mon, 26 Jun 2017 08:44 am, Stefan Ram wrote: >> >> > According to The Python Language Reference Release 3.6.0, 2.1.3 >> > Comments, »A comment signifies the end of th

Re: Syntax error for simple script

2017-06-26 Thread Steve D'Aprano
On Tue, 27 Jun 2017 01:16 am, Ben S. wrote: > print mm + "/" + dd + "/" + + " " + hour + ":" + mi + ":" + ss > ^ > SyntaxError: Missing parentheses in call to 'print' > > Whats wrong? Did you read the error message? Missing parentheses in call to 'print' Is the message not clear enoug

Re: Syntax error for simple script

2017-06-26 Thread Steve D'Aprano
On Tue, 27 Jun 2017 09:21 am, Stefan Ram wrote: > Erik writes:Using 'print' as a >>statement is obsolete syntax in Python 3. > > »print« never was a statement. Of course it could be a statement, just like "y = x + 1" is a statement. > »print« was a keyword (2.7.6 2.3.1). It can b

Re: Syntax error for simple script

2017-06-27 Thread Steve D'Aprano
On Tue, 27 Jun 2017 03:00 am, mm0fmf wrote: > Sorry to victim blame but why can't people copy the error message into a > search engine, such as Google, and see what the problem is themselves? You're not victim blaming. There's no *victim* here, syntax errors are a part of programming and one has

Re: Syntax error for simple script

2017-06-27 Thread Steve D'Aprano
On Tue, 27 Jun 2017 08:34 am, Erik wrote about the print function error message: py> print x File "", line 1 print x ^ SyntaxError: Missing parentheses in call to 'print' > To be fair, this already seems to be a special case: [...] > >>> len "bar" >File "", line 1 > len

Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 02:23 am, Sam Chats wrote: > https://medium.com/technology-invention-and-more/how-to-build-a-simple-neural-network-in-9-lines-of-python-code-cc8f23647ca1 The derivative of the sigmoid curve given is completely wrong. def __sigmoid(self, x): return 1 / (1 + exp(-x

Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 06:19 am, Marko Rauhamaa wrote: > alister : > >> On Tue, 27 Jun 2017 22:34:18 +0300, Marko Rauhamaa wrote: >> >>> John Ladasky : OK, that's cheating a bit, using Numpy. It's a nice little program, but it leverages a huge, powerful library. >>> >>> What would *not* b

Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 05:34 am, Marko Rauhamaa wrote: > John Ladasky : >> OK, that's cheating a bit, using Numpy. It's a nice little program, >> but it leverages a huge, powerful library. > > What would *not* be cheating? A language without a library would be > dead. Its not really nine lines of P

Re: How to build a simple neural network in 9 lines of Python code

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 06:22 am, Marko Rauhamaa wrote: > You saw the APL example, right? APL's standard runtime/library contains > most of Numpy functionality because that's what APL has been designed > for. > > Is that cheating? Of course not. That demonstrates beautifully (or perhaps "unreadably

Re: Syntax error for simple script

2017-06-27 Thread Steve D'Aprano
On Wed, 28 Jun 2017 05:38 am, Erik wrote: [...] > So I don't understand the resistance to making the error be a bit more > explicit about why it is being generated to help those users - it > doesn't explain (the obvious reason) _why_ their tutorial/example gives > them an error when it doesn't to

Re: A Good Tutorial on Python Decorators

2017-06-28 Thread Steve D'Aprano
On Thu, 29 Jun 2017 01:56 am, Peter Pearson wrote: > (Blushing) Thanks. Life is getting difficult for us JavaScript paranoids. Its not paranoia if they're really out to get you. https://www.cnet.com/news/javascript-opens-doors-to-browser-based-attacks/ https://www.proofpoint.com/us/corporate-b

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Steve D'Aprano
Hello Irv, and welcome! Good to have a teacher of Python here! On Fri, 30 Jun 2017 06:57 am, Irv Kalb wrote: [...] > Now I am looking at the change in the range function. I completely understand > the differences between, and the reasons for, how range works differently in > Python 2 vs Python

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Steve D'Aprano
On Fri, 30 Jun 2017 09:17 am, Stefan Ram wrote: b = a.__iter__() Don't do that. Dunder ("Double UNDERscore") methods like __iter__ should only be called by the Python interpreter, not by the programmer. The right way to create an iterator is to call the built-in function iter: b = iter(a)

Re: Teaching

2017-07-02 Thread Steve D'Aprano
On Mon, 3 Jul 2017 03:45 am, Mark- wrote: > ad...@python.org wrote: > >> Irv Kalb: >> > I teach Python at two colleges in Silicon Valley. >> >> >> and I don't give a fuck about that. > > Wow, some of you folks are so civilized. It's one person, a troll who is sending abusive and racist messag

Re: Spammy spam spam spam spam

2017-07-04 Thread Steve D'Aprano
On Tue, 4 Jul 2017 10:55 pm, Case Solution & Analysis wrote: > Our e-mail address is CASESOLUTIONSCENTRE (AT) GMAIL (DOT) COM. Please replace > (at) by @ and (dot) by . Since we don't yet have a protocol for transmitting a punch to the face over TCP/IP, is it be wrong of me to wish that some whit

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Thu, 6 Jul 2017 06:51 pm, Dan Wissme wrote: > So what 'del L[i]' do exactly in memory ? Same as L.pop(i) ? with > complexity O(n-i) ? It depends on what L is and what the value of i is. If L is a list, and i is the last index of the list, then deleting it is quick. If i is 0, then Python has t

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Thu, 6 Jul 2017 07:24 pm, Marko Rauhamaa wrote: > While talking about addresses might or might not be constructive, let me > just point out that there is no outwardly visible distinction between > "address" or "identity". Er, yes there is. Address refers to a position in space. Identity refer

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Fri, 7 Jul 2017 01:21 am, Marko Rauhamaa wrote: > Steve D'Aprano : > >> On Thu, 6 Jul 2017 07:24 pm, Marko Rauhamaa wrote: >> >>> While talking about addresses might or might not be constructive, let >>> me just point out that there is no outwardly vis

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Fri, 7 Jul 2017 07:46 am, Chris Angelico wrote: > A simple name lookup cannot, I believe, be messed with. Nor can a literal. In principle, you could replace builtins or globals with a custom namespace that performed some computation on name lookup. You might even be able to insert some additio

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Fri, 7 Jul 2017 08:56 am, Marko Rauhamaa wrote: > Google finds a Dutch master's thesis from 2009 that gives formal > semantics to a subset of Python. I was interested in seeing how it > treated identity. Lo and behold: > >The is operator determines whether its operands are the same object.

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Fri, 7 Jul 2017 10:34 am, Gregory Ewing wrote: > Steve D'Aprano wrote: >> Address refers to a position in space. > > Not always. A PO Box number can remain the same when its owner's > location in space changes. But the PO box itself does not change. Pedantically

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Fri, 7 Jul 2017 01:41 am, Marko Rauhamaa wrote: > Here's how identity is dealt with in First-Order Logic: > >https://en.wikipedia.org/wiki/First-order_logic#Semantics> > > In other words, identity is mapped to the "sameness" in a domain of > discourse. Define "sameness". > In Second-

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Fri, 7 Jul 2017 03:05 am, Marko Rauhamaa wrote: > I believe the concept of an object is among the more difficult things > for novice programmers to get. True, but that has nothing to do with object identity. Inheritance, "is-a" versus "has-a" relationships, when to write len(x) versus x.len()

Re: About the implementation of del in Python 3

2017-07-06 Thread Steve D'Aprano
On Fri, 7 Jul 2017 03:38 am, Marko Rauhamaa wrote: > Notice that Scheme refers directory to conventional RAM: > > Variables and objects such as pairs, vectors, and strings implicitly > denote locations That implies that it is impossible to implement Scheme: - using a programming language where

Re: About the implementation of del in Python 3

2017-07-07 Thread Steve D'Aprano
On Fri, 7 Jul 2017 07:10 am, Marko Rauhamaa wrote: > Steve D'Aprano : > >> An address is a concrete location or place, in other words a physical >> position in some space, while identity is the abstract state or >> quality of being identical (sameness), in ot

Re: About the implementation of del in Python 3

2017-07-07 Thread Steve D'Aprano
On Fri, 7 Jul 2017 07:10 am, Marko Rauhamaa wrote: > I believe identity can be defined much better, in numerous isomorphic > ways in fact. > > For example, we could equate each object with a sequence number > (unrelated with its id()). You can define that the "None" object is in > fact the natura

Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Steve D'Aprano
On Fri, 7 Jul 2017 04:30 pm, Ben S. wrote: > Can I somehow check from inside a Python script if the executing Python engine > is major version v2 or v3? Yes you can, but generally speaking you shouldn't. import sys if sys.version_info >= (3,): # the comma is important print("version 3") el

Re: About the implementation of del in Python 3

2017-07-07 Thread Steve D'Aprano
On Fri, 7 Jul 2017 05:29 pm, Dan Wissme wrote: > Strange behavior in Python 3.6.0 > >>> i = 3000 > >>> j = 3000 > >>> i is j > False > >>> n = 4000 ; m = 4000 ; n is m > True The Python interpreter is allowed to cache integers and reuse them. The interactive interpreter sometimes does so: if you

Re: About the implementation of del in Python 3

2017-07-07 Thread Steve D'Aprano
On Fri, 7 Jul 2017 05:45 pm, Chris Angelico wrote: > On Fri, Jul 7, 2017 at 4:43 PM, Steve D'Aprano > wrote: >> On Fri, 7 Jul 2017 01:41 am, Marko Rauhamaa wrote: >>> In Second-Order Logic, you can define identity directly: >>> >>> ∀x ∀y x = y ↔ ∀

Re: About the implementation of del in Python 3

2017-07-07 Thread Steve D'Aprano
On Fri, 7 Jul 2017 06:05 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> In practice, identity is hardly important in Python, except for a few limited >> cases, and the prohibition against using `is` when you mean `==`. > > On the contrary, it's a very i

Re: About the implementation of del in Python 3

2017-07-07 Thread Steve D'Aprano
On Fri, 7 Jul 2017 06:12 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> That implies that it is impossible to implement Scheme: >> >> - using a programming language where variables and objects may move during >> their lifetime; >> >> - or u

Re: poplib's POP3_SSL not downloading latest email

2017-07-08 Thread Steve D'Aprano
On Sat, 8 Jul 2017 06:48 pm, Sm Chats wrote: > I have a small script which checks whether a mail sent by me to myself(i.e > delivered to myself) has the same body as the sent message. The problem is > that the sent message (sent by SMTP) isn't received by the POP3_SSL object I'm > using. It shows

Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-09 Thread Steve D'Aprano
On Mon, 10 Jul 2017 11:41 am, voteswithf...@gmail.com wrote: > On Sunday, July 9, 2017 at 7:59:45 PM UTC-5, timetowalk wrote: >> I will need to read about filtering messages locally. >> Can the admin simply ban the user? > > There is no admin, you idiot. This is Usenet! That's unnecessarily rud

Re: AUCPR of individual features using Random Forest (Error: unhashable Type)

2017-07-10 Thread Steve D'Aprano
Hi mscs15059 and welcome! (If you'd rather be known with a more friendly name, you can either sign your messages at the end, or configure your email or news software to show your name.) On Mon, 10 Jul 2017 09:47 pm, mscs15...@itu.edu.pk wrote: > I have a data set of 19 features (v1---v19) and on

Re: Test 0 and false since false is 0

2017-07-11 Thread Steve D'Aprano
On Tue, 11 Jul 2017 11:16 pm, Albert-Jan Roskam wrote: > >>> False == 0 > True > >>> False is 0 > False > > > => Just wondering: Is this 'is' test depending on an implementation detail > of cPython (small ints, I forgot how small 0-255 maybe, are singletons)? No. But the test 0 is 0 will b

Re: Write this accumuator in a functional style

2017-07-11 Thread Steve D'Aprano
On Tue, 11 Jul 2017 04:58 pm, Chris Angelico wrote: > On Tue, Jul 11, 2017 at 4:11 PM, Steven D'Aprano wrote: [...] >> accumulator = {'blue': [], 'green': [], 'red': []} >> for parrot in parrots: >> accumulator[parrot.colour].append(parrot) [...] > It's a partitioning filter. (Three way, not

Re: python 3.5 raiaing an error when import the class Manager in this module sayning name Manager is not define

2017-07-12 Thread Steve D'Aprano
Please COPY AND PASTE the FULL error, starting with the line "Traceback". The code you show below looks fine, and you don't need an import, so I don't know what error you are getting. On Wed, 12 Jul 2017 10:31 pm, lunkamba...@gmail.com wrote: > class Person: > def __init__(self, name, job=N

Re: Write this accumuator in a functional style

2017-07-13 Thread Steve D'Aprano
On Thu, 13 Jul 2017 10:10 pm, Rustom Mody wrote: > Yeah I know append method is supposedly O(1). > I find that surprising... > More so when the article > https://wiki.python.org/moin/TimeComplexity > talks of average case Vs amortized-worst case(!) Whatever does that mean? "Average case" refers

Re: Write this accumuator in a functional style

2017-07-13 Thread Steve D'Aprano
On Fri, 14 Jul 2017 01:09 am, Rustom Mody wrote: > Couple that with the fact that space-time are not unrelated on any modern VM > based OS + cache based hw. Doubly so for "managed" languages where gc buys > space for time. I don't understand that comment. Space/time have *never* been unrelated.

Re: Write this accumuator in a functional style

2017-07-13 Thread Steve D'Aprano
On Fri, 14 Jul 2017 12:59 am, Pavol Lisy wrote: > On 7/13/17, Steve D'Aprano wrote: > >> [1] Actually, CPython's lists initially quadruple the size of the array, up >> to a >> certain point, and then switch to doubling. This ensures that small lists >>

Grapheme clusters, a.k.a.real characters

2017-07-13 Thread Steve D'Aprano
From time to time, people discover that Python's string algorithms work on code points rather than "real characters", which can lead to anomalies like the following: s = 'xäex' s = unicodedata.normalize('NFD', s) print(s) print(s[::-1]) which results in: xäex xëax If you're interested in this

Re: Grapheme clusters, a.k.a.real characters

2017-07-14 Thread Steve D'Aprano
On Fri, 14 Jul 2017 04:30 pm, Marko Rauhamaa wrote: > Unicode was supposed to get us out of the 8-bit locale hole. Which it has done. Apart from use for backwards compatibility, there is no good reason to use to use the masses of legacy extensions to ASCII or the technical fragile non-Unicode mul

Re: Write this accumuator in a functional style

2017-07-14 Thread Steve D'Aprano
On Fri, 14 Jul 2017 09:06 am, Ned Batchelder wrote: > Steve's summary is qualitatively right, but a little off on the quantitative > details. Lists don't resize to 2*N, they resize to ~1.125*N: > > new_allocated = (size_t)newsize + (newsize >> 3) + (newsize < 9 ? 3 : 6); > > (https://github

Re: Grapheme clusters, a.k.a.real characters

2017-07-14 Thread Steve D'Aprano
On Fri, 14 Jul 2017 11:31 pm, Marko Rauhamaa wrote: > Steve D'Aprano : > >> These are only a *few* of the *easy* questions that need to be >> answered before we can even consider your question: >> >>> So the question is, should we have a third type fo

Re: Grapheme clusters, a.k.a.real characters

2017-07-14 Thread Steve D'Aprano
On Sat, 15 Jul 2017 07:12 am, Terry Reedy wrote: > Does go use bytes for text, like most people did in Python 2, a separate > text string class, that hides the internal encoding format and > implementation? In other words, if you do the equivalent of print(s) > where s is a text string with a mix

Re: Grapheme clusters, a.k.a.real characters

2017-07-14 Thread Steve D'Aprano
On Sat, 15 Jul 2017 04:10 am, Marko Rauhamaa wrote: > Steve D'Aprano : >> On Fri, 14 Jul 2017 11:31 pm, Marko Rauhamaa wrote: [...] >>> As it stands, we have >>> >>>è --[encode>-- Unicode --[reencode>-- UTF-8 >> >> I can't ev

Re: Grapheme clusters, a.k.a.real characters

2017-07-15 Thread Steve D'Aprano
On Sat, 15 Jul 2017 05:50 pm, Marko Rauhamaa wrote: > Steve D'Aprano : > >> On Sat, 15 Jul 2017 04:10 am, Marko Rauhamaa wrote: >>> Python3's strings don't give me any better random access than UTF-8. >> >> Say what? Of course they do. >> >

Re: Grapheme clusters, a.k.a.real characters

2017-07-15 Thread Steve D'Aprano
On Sun, 16 Jul 2017 12:01 am, Marko Rauhamaa wrote: > It does seem to me UTF-8 is a better waiting position than strings. > Strings give you more trouble while not truly solving any problems. /face-palm Okay, that's it, this conversation is over. You have no clue what you are talking about. ht

Re: Grapheme clusters, a.k.a.real characters

2017-07-15 Thread Steve D'Aprano
On Sun, 16 Jul 2017 12:31 am, Rick Johnson wrote: > I never hear Chinese or eastern Europeans > bellyaching Do you speak much to Chinese and Eastern Europeans who don't speak or write English? How would you know what they say? "All toupées are bad. I've never seen a good one that looked real."

<    5   6   7   8   9   10   11   12   >