Re: Pip Version Confusion

2018-03-24 Thread Steven D'Aprano
On Sat, 24 Mar 2018 07:40:17 -0800, Tim Johnson wrote: > I'm on Ubuntu 16.04. > > I'm getting the following message from pip: > > You are using pip version 8.1.1, however version 9.0.3 is available. You > should consider upgrading via the 'pip install --upgrade pip' command. [...] > Not sure how

Re: Accessing parent objects

2018-03-24 Thread Steven D'Aprano
On Sat, 24 Mar 2018 13:31:13 -0700, Rick Johnson wrote: > On Saturday, March 24, 2018 at 1:20:24 PM UTC-5, D'Arcy Cain wrote: [...] >> I tried various forms of super() but that didn't seem to work. Define "doesn't see to work". > Python's super (at least <= 2.x) is notoriously blinkered. I avoi

Re: Entering a very large number

2018-03-24 Thread Steven D'Aprano
On Sun, 25 Mar 2018 00:05:56 +0100, Peter J. Holzer wrote: [...] >> yes, good idea > > Not if you want to avoid that string to int conversion (as you stated). > > That is still there, but in addition you now split the string into a > list and then join the list into a different string. I'm glad

Re: Accessing parent objects

2018-03-24 Thread Steven D'Aprano
On Sat, 24 Mar 2018 20:08:47 -0700, Rick Johnson wrote: > After sending my response to Steven, i began to ponder why i had > rejected Python's super (because, after all, it's been a few years now, > and frankly, i forgot), and i realized it was more a matter of > con

Re: Accessing parent objects

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 21:17:59 +1100, Chris Angelico wrote: > On Sun, Mar 25, 2018 at 8:37 PM, Jugurtha Hadjar > wrote: [...] >> I prefer to *feed* the child to the parent or vice versa. > > Congrats, this ranks on my list of "creative people who sound like > psycho murderers". Digital artists and

Re: Accessing parent objects

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 06:11:53 -0500, D'Arcy Cain wrote: > On 03/24/2018 06:54 PM, Steven D'Aprano wrote: >>> On Saturday, March 24, 2018 at 1:20:24 PM UTC-5, D'Arcy Cain wrote: >>>> I tried various forms of super() but that didn't seem to work. >>

Re: Accessing parent objects

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 05:57:40 -0500, D'Arcy Cain wrote: > That was my original solution but it seems clumsy. > > O2 = O1.C2(O1) Are you intentionally trying to melt my brain with horribly obfuscated, meaningless names? If so, you've succeeded admirably millennium hand and shrimp buggarit. :-)

Ruby parens-free function calls [was Re: Accessing parent objects]

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 04:49:21 -0700, Rick Johnson wrote: >> - with no arguments, using the parenthesis-free syntax, >> Ruby automagically forwards the same arguments to the (single) >> parent; > > Which is merely a natural result of Ruby's function/method call syntax. > Not allowing a parenthe

Multiple Inheritance [was Re: Accessing parent objects]

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 04:49:21 -0700, Rick Johnson wrote: [...] > Ruby is fundamentally _opposed_ to the idea of multiple inheritance -- > as MI is rife with issues (technical, practical, and intuitive in > nature) and thus, not a wise solution -- but you would have known that > St

Re: Accessing parent objects

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 08:09:02 -0600, Ian Kelly wrote: > On Sun, Mar 25, 2018 at 5:46 AM, Steven D'Aprano > wrote: >> On Sun, 25 Mar 2018 06:11:53 -0500, D'Arcy Cain wrote: >>> It accesses the parent class. I want to access the parent object. >> >>

Re: Accessing parent objects

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 04:49:21 -0700, Rick Johnson wrote: > On Saturday, March 24, 2018 at 11:31:38 PM UTC-5, Steven D'Aprano wrote: [...] >> "A foolish consistency is the hobgoblin of little minds, adored by >> little statesmen and philosophers and divines." >

Re: Accessing parent objects

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 13:30:14 -0700, Rick Johnson wrote: [...] >> Especially since by your own admission, you are *giving up correctness* >> in order to buy "consistency": > > "sacrificing correctness" only in a purely ideological sense. > > Explicit inheritance (aka: hard-coding the superclass s

Re: [OT] multicore/cpu history

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 23:29:07 +0200, Peter J. Holzer wrote: [...] >> >> By the way, multiple CPU machines are different from CPUs with >> >> multiple cores: >> >> >> >> http://smallbusiness.chron.com/multiple-cpu-vs-multicore-33195.html >> > >> > Yeah, it was always "multiple CPUs", not "multiple

Re: Ruby parens-free function calls [was Re: Accessing parent objects]

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 10:33:49 -0700, Rick Johnson wrote: > On Sunday, March 25, 2018 at 9:11:35 AM UTC-5, Steven D'Aprano wrote: >> On Sun, 25 Mar 2018 04:49:21 -0700, Rick Johnson wrote: > [...] >> I never said anything about not allowing it. But since you've gone on

Re: Accessing parent objects

2018-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2018 21:50:27 +0200, Peter J. Holzer wrote: > On 2018-03-25 14:49:44 +0000, Steven D'Aprano wrote: >> The moniker "Python X-thousand" (Python 3000, 4000, 5000...) is usually >> understood to mean a backwards-compatibility breaking version. Since &g

Re: Entering a very large number

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 02:37:44 +0100, bartc wrote: > Calling a function that sets up C using 'C = 288714...' on one line, and > that then calculates D=C+C, takes 0.12 seconds to call 100 times. > > To do D=C*C, takes 2.2 seconds (I've subtracted the function call > overhead of 0.25 seconds; the

Re: Accessing parent objects

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 10:02:23 +0200, Antoon Pardon wrote: >> The trick is to use new-style classes that inherit from object, and >> avoid the old-style classes that don't: >> >> # Good >> class Spam(object): >> ... >> >> # Not so good >> class Spam: >> ... > > How good is that when almost

Re: [OT] multicore/cpu history

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 10:03:43 +1100, Chris Angelico wrote: > At what point does it change from being two CPUs to being one CPU and > one auxiliary processing unit? When someone writes an OS that will run on the "auxiliary processing unit" alone, then it's probably time to start calling it a CPU :

Re: Accessing parent objects

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 10:43:25 +0200, Antoon Pardon wrote: > But did they start up cleaning the standard library yet? I'll confess > I'm only using 3.5 but when I go through the standard library I see a > lot of classes still using the old style of calling the parant method, > which makes it more di

Re: Ruby parens-free function calls [was Re: Accessing parent objects]

2018-03-26 Thread Steven D'Aprano
On Sun, 25 Mar 2018 19:16:12 -0700, Rick Johnson wrote: > On Sunday, March 25, 2018 at 5:57:28 PM UTC-5, Steven D'Aprano wrote: > >> [supposed "fix" to the sample script snipped] >> >> You know Rick, every time I start to think that talking to you like a

Re: Entering a very large number

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 11:31:22 +0100, bartc wrote: > On 26/03/2018 10:34, Steven D'Aprano wrote: >> So what exactly did you do? > > I'm not sure why you think the language C came into it. My misunderstanding. Sorry. -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: Getting "LazyImporter' object is not callable" error when trying to send email using python smtplib

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 16:47:26 +0530, Sum wrote: > Hi, > > Getting "LazyImporter' object is not callable" error. I have enabled > allow less secure app setting in sender gmail. > > Code : The code you show is not the same as the code you are actually running. The error message you give says: Fi

Re: Entering a very large number

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 11:45:33 +0100, bartc wrote: > Similar overheads occur when you use string=>int even on small numbers: > > This code: > > C = int("12345") > D = C+C # or C*C; about the same results > > takes 5 times as long (using my CPython 3.6.x on Windows) as: > > C

Re: Using object as a class

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 07:31:06 -0500, D'Arcy Cain wrote: > Is this behaviour (object not quite like a class) documented anywhere? It's exactly like a class. It's an immutable class. You are making assumptions about what classes must be able to do. > Does anyone know the rationale for this if any

Re: Ruby parens-free function calls [was Re: Accessing parent objects]

2018-03-27 Thread Steven D'Aprano
On Mon, 26 Mar 2018 11:37:35 -0700, Rick Johnson wrote: > On Monday, March 26, 2018 at 5:46:03 AM UTC-5, Steven D'Aprano wrote: >> Rick, you're supposedly familiar with Ruby. And yet, you didn't notice >> that your supposed "fix" didn't touch any

Re: please test the new PyPI (now in beta)

2018-03-27 Thread Steven D'Aprano
On Mon, 26 Mar 2018 18:16:26 -0400, Sumana Harihareswara wrote: > The new Python Package Index at https://pypi.org is now in beta. > > This means the site is robust, but we anticipate needing more user > testing and changes before it is "production-ready" and can fully > replace https://pypi.pyth

Re: Entering a very large number

2018-03-27 Thread Steven D'Aprano
On Mon, 26 Mar 2018 23:49:07 -0400, Richard Damon wrote: > The bigger issue is that these sort of micro-measurements aren't > actually that good at measuring real quantitative performance costs. > They can often give qualitative indications, but the way modern > computers work, processing environm

Re: please test the new PyPI (now in beta)

2018-03-27 Thread Steven D'Aprano
On Tue, 27 Mar 2018 10:48:15 +0100, Paul Moore wrote: >> By the way, on the search page: >> >> https://pypi.org/search/ >> >> >> it says "Enter a search query above, or select a filter from the list >> of classifiers on the left" but there is no such filter or list of >> classifiers. > > Do you n

Re: please test the new PyPI (now in beta)

2018-03-27 Thread Steven D'Aprano
On Tue, 27 Mar 2018 11:03:00 +0100, Paul Moore wrote: > Digging into this further, the design work on the Warehouse site has > been ongoing since late 2015, and there was an extensive user testing > phase, Oh? What did they test the user for? Whatever it was, it was a pity they didn't test them

Re: please test the new PyPI (now in beta)

2018-03-27 Thread Steven D'Aprano
On Tue, 27 Mar 2018 22:25:44 +1100, Chris Angelico wrote: > On Tue, Mar 27, 2018 at 9:49 PM, Steven D'Aprano > wrote: >> As an extra bonus, even when searching is not reliant on Javascript, >> mangling the text in the search box often is, so unless I'm extra >>

Re: To super or not to super (Re: Accessing parent objects)

2018-03-27 Thread Steven D'Aprano
On Tue, 27 Mar 2018 19:21:38 +1300, Gregory Ewing wrote: > The idea that super() is *always* the right way to call inherited > methods in a multiple inheritance environment seems to have been raised > by some people to the level of religous dogma. "Always"? Well, you could always avoid super() b

Re: Ruby parens-free function calls [was Re: Accessing parent objects]

2018-03-27 Thread Steven D'Aprano
On Tue, 27 Mar 2018 09:28:34 -0700, Rick Johnson wrote: > On Tuesday, March 27, 2018 at 8:46:54 AM UTC-5, Chris Angelico wrote: [...] > > Cool, so Greg was right: you can't get a reference to a method or > > function. You need magic to simulate it. > > Since when did utilizing a method to request a

Re: Ruby parens-free function calls [was Re: Accessing parent objects]

2018-03-28 Thread Steven D'Aprano
On Tue, 27 Mar 2018 11:34:17 +1100, Chris Angelico wrote: > Question: How do you get a reference to a Ruby function? Or are they not > first-class objects? https://stackoverflow.com/questions/4294485/how-do-i-reference-a-function- in-ruby Especially this answer, which is worth reading: https://

Re: Python Developer Survey: Python 3 usage overtakes Python 2 usage

2018-03-30 Thread Steven D'Aprano
On Fri, 30 Mar 2018 11:45:10 -0400, Terry Reedy wrote: > https://www.jetbrains.com/research/python-developers-survey-2017/ “Which > version of Python do you use the most?” > 2014 80% 2.x, 20% 3.x > 2016 60% 2.x, 40% 3.x > 2017 25% 2.x, 75% 3.x > > This is a bigger jump than I anticipated. Thank

Re: Python Developer Survey: Python 3 usage overtakes Python 2 usage

2018-03-30 Thread Steven D'Aprano
On Sat, 31 Mar 2018 00:42:31 +0300, Marko Rauhamaa wrote: > Paul Rubin : >> Terry Reedy writes: >>> 2017 25% 2.x, 75% 3.x >>> This is a bigger jump than I anticipated. >> >> It's interesting and surprising. I still have not encountered anyone >> using Python 3 in real life. The main Linux distros

Re: Python Developer Survey: Python 3 usage overtakes Python 2 usage

2018-03-30 Thread Steven D'Aprano
On Fri, 30 Mar 2018 16:18:57 -0700, Rick Johnson wrote: > My suspicion is that not only are the overall numbers of Python > programmers on the decline Python's popularity went up from #5 to #4 between March 2017 and 2018 on TIOBE: https://www.tiobe.com/tiobe-index/ But of course Rick knows this

Re: Python Developer Survey: Python 3 usage overtakes Python 2 usage

2018-03-30 Thread Steven D'Aprano
On Fri, 30 Mar 2018 20:51:22 -0600, Ian Kelly wrote: > On Fri, Mar 30, 2018 at 8:43 PM, Ian Kelly > wrote: >> You really think that 90% of the active users are trolls? And yet the >> subreddit remains usable despite that allegedly terrible >> signal-to-noise ratio. > > I'm now laughing at the im

Re: Python Developer Survey: Python 3 usage overtakes Python 2 usage

2018-03-31 Thread Steven D'Aprano
On Sat, 31 Mar 2018 12:32:31 +0300, Marko Rauhamaa wrote: > Paul Rubin : > >> Marko Rauhamaa writes: >>> Yes, RHEL, CentOS and OracleLinux still only support Python2. It may >>> be another year before Python3 becomes available on them. >> >> Debian's default Python is also Python2. I don't say i

Re: Python Developer Survey: Python 3 usage overtakes Python 2 usage

2018-03-31 Thread Steven D'Aprano
On Sat, 31 Mar 2018 12:39:48 +0300, Marko Rauhamaa wrote: > Paul Rubin : >> All the scripts that say #!/usr/bin/python at the top will still use >> python2. > > Which is how it should be till the end of times. Don't be silly -- they should use Python 1, of course, as nature intended. In 20 year

Re: Python Developer Survey: Python 3 usage overtakes Python 2 usage

2018-03-31 Thread Steven D'Aprano
On Sat, 31 Mar 2018 10:58:51 -0400, Etienne Robillard wrote: > Hi, > > I was just wondering, could the fact that the Python community is > willing to discontinue using and developing Python 2 softwares, does > that mean we are stopping to support standard computers and laptops as > well? That se

Re: Python Developer Survey: Python 3 usage overtakes Python 2 usage

2018-03-31 Thread Steven D'Aprano
On Sat, 31 Mar 2018 14:07:37 -0400, Terry Reedy wrote: > On 3/31/2018 11:58 AM, Etienne Robillard wrote: > >> Do you really think people in Somalia can afford theses things like in >> the US? > > No, many cannot afford $600 Caddilac-style phones to take 10 megapixel > pictures and watch UTube vi

Re: Beta release of pip version 10

2018-03-31 Thread Steven D'Aprano
On Sun, 01 Apr 2018 03:17:51 +0300, Mikhail V wrote: > PS: was looking forward to PIP improvements on Windows, on 9.0.3 still > some issues. E.g. trying to redirect output from 'pip search ... > > a.txt' gives a wall of errors. it's on Windows 10. Don't be shy, tell us what those errors are. -

Re: check if bytes is all nulls

2018-04-01 Thread Steven D'Aprano
On Sun, 01 Apr 2018 19:14:05 +, Arkadiusz Bulski wrote: > Thanks, > timeit gives `not any(key)` same performance as `sum(key)==0`. Have you considered what happens when the key is *not* all zeroes? key = b'\x11'*100 any(key) bails out on the first byte. sum(key) has to add a million v

Re: Why is the use of an undefined name not a syntax error?

2018-04-01 Thread Steven D'Aprano
On Sun, 01 Apr 2018 14:24:38 -0700, David Foster wrote: > My understanding is that the Python interpreter already has enough > information when bytecode-compiling a .py file to determine which names > correspond to local variables in functions. That suggests it has enough > information to identify

Re: How to fill in a dictionary with key and value from a string?

2018-04-01 Thread Steven D'Aprano
On Sun, 01 Apr 2018 20:52:35 -0400, C W wrote: > Thank you all for the response. > > What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the > values are shift by one position. > > key:abcdefghijklmnopqrstuvwxyz > value: BCDEFGHIJKLMNOPQRSTUVWXYZA > > Can I fill in a key and

Re: How to fill in a dictionary with key and value from a string?

2018-04-01 Thread Steven D'Aprano
On Sun, 01 Apr 2018 22:24:31 -0400, C W wrote: > Thank you Steven. I am frustrated that I can't enumerate a dictionary by > position index. Why do you care about position index? > Maybe I want to shift by 2 positions, 5 positions... Sounds like you are trying to program the Caesa

Re: In asyncio, does the event_loop still running after run_until_complete returned?

2018-04-03 Thread Steven D'Aprano
On Mon, 02 Apr 2018 23:37:51 -0600, Ian Kelly wrote: > If it helps to demystify things, here is a simplified version of what > run_until_complete actually does: > > def run_until_complete(self, future): > """Run until the Future is done. > > If the argument is a coroutine, it

Asynchronous processing is more efficient -- surely not?

2018-04-04 Thread Steven D'Aprano
So, I'm, still trying to wrap my brain around async processing, and I started reading this tutorial: http://stackabuse.com/python-async-await-tutorial/ and the very first paragraph broke my brain. "Asynchronous programming has been gaining a lot of traction in the past few years, and for good

Re: RegEx to match set of lines

2018-04-05 Thread Steven D'Aprano
On Thu, 05 Apr 2018 14:09:23 +0530, Prahallad Achar wrote: > Hello, > I would like to match set of lines from the below data. this data comes > from one of the network Good grief! You don't need to post your entire data set! We don't need or want to see hundreds of lines. Cut your data down to

Re: try-except syntax

2018-04-05 Thread Steven D'Aprano
On Thu, 05 Apr 2018 23:04:18 +0200, ElChino wrote: > I'm trying to simplify a try-except construct. E.g. how come this: >try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) imp.find_module is deprecated and should not be used in new code. Putting th

Re: # of Months between two dates

2018-04-05 Thread Steven D'Aprano
On Thu, 05 Apr 2018 22:03:07 -0600, Jason Friedman wrote: >> > > I've written a function to return the months between date1 and >> > > date2 >> but >> > > I'd like to know if anyone is aware of anything in the standard >> > > library to do the same? For bonus points, does anyone know if >> > > p

Re: # of Months between two dates

2018-04-06 Thread Steven D'Aprano
On Fri, 06 Apr 2018 10:56:21 +0100, bartc wrote: > Agree with the messiness of dealing with months, but I think it's one of > those quirks that make life more interesting, like imperial measure. I > don't think we really want metric applied to time and to dates. (10-day > weeks? I don't think so.)

A bit of Python history

2018-04-06 Thread Steven D'Aprano
I stumbled across this post from the Timbot, Tim Peters, back in 2000, where he correctly predicted that Python would get generators and iterators in Python 2: https://mail.python.org/pipermail/python-list/2000-January/033955.html as well as list comprehensions. -- Steve -- https://mail.py

Re: Compression of random binary data

2018-04-11 Thread Steven D'Aprano
On Tue, 10 Apr 2018 23:36:27 -0700, cuddlycaveman wrote: [snip a number of carefully chosen, non-random numbers shown in binary] > Don’t know if that helps Helps what? With no context, we don't know who you are replying to, what they asked, or why you think this is helpful. According to my a

Re: Python Import Impossibility

2018-04-13 Thread Steven D'Aprano
On Fri, 13 Apr 2018 12:48:55 +, ?? ?? wrote: > Hello, > > Could you tell me how to import the installed modules ? > > I have successfully installed openpyxl, How do you know it was successful? What did you do to install it? How many different Python installations do you have on your syst

Re: Instance variables question

2018-04-16 Thread Steven D'Aprano
On Mon, 16 Apr 2018 09:03:47 -0700, Irv Kalb wrote: > I have been writing OOP code for many years in other languages and for > the past few years in Python. I am writing new curriculum for a course > on OOP in Python. If you're going to be teaching Python, please don't teach terminology which

Re: RE newbie question

2018-04-18 Thread Steven D'Aprano
On Wed, 18 Apr 2018 12:37:29 -0700, TUA wrote: > My intention is to implement a max. length of 8 for an input string. The > above works well in all other respects, but does allow for strings that > are too long. if len(input_string) > 8: raise ValueError('string is too long') -- Steve --

Re: python 3 creating hard links on ntfs

2018-04-18 Thread Steven D'Aprano
On Wed, 18 Apr 2018 13:06:37 -0700, zljubisic wrote: > Is it possible to create hard links on windows with ntfs? On linux I can > use os.link, but how about windows? According to the documentation, creating hard links on Windows has worked since version 3.2: https://docs.python.org/3/library/os

Re: Open (txt) editor and get its content

2018-04-19 Thread Steven D'Aprano
On Thu, 19 Apr 2018 00:39:40 -0700, zljubisic wrote: > Is it possible to run python script that will open editor and let me > paste sql query in the editor, and than after closing editor, get > editor's content in python script? Try this recipe: it will work for many, but not all editors. https:

Re: Understanding pdb result

2018-04-27 Thread Steven D'Aprano
On Fri, 27 Apr 2018 10:34:27 -0700, Rich Shepard wrote: > Running python3-3.6.5 and wxPython-4.0.1 on Slackware-14.2. > >The module begins this way: > > #!/usr/bin/env python3 > > import sys, os > import pdb > import wx [...] >Please pass me a pointer to a resource that teaches me how

Re: Weird side effect of default parameter

2018-05-04 Thread Steven D'Aprano
On Thu, 03 May 2018 19:47:37 +, Robert Latest via Python-list wrote: > Hello, > > I don't understand the behavior of the code below. Why does the dict > property "a" of both objects contain the same keys? This is only if > "a=dict" is in the initializer. If I put self.a = dict() into the init

itemgetter with default arguments

2018-05-04 Thread Steven D'Aprano
A re-occurring feature request is to add a default to itemgetter and attrgetter. For example, we might say: from operator import itemgetter f = itemgetter(1, 6, default="spam") # proposed feature f("Hello World!") # returns ('e', 'W') f("Hello") # returns ('e', 'spam') Two senior deve

Re: itemgetter with default arguments

2018-05-04 Thread Steven D'Aprano
On Fri, 04 May 2018 09:17:14 -0600, Ian Kelly wrote: > On Fri, May 4, 2018 at 7:01 AM, Steven D'Aprano > wrote: >> Here are the specifications: >> >> * you must use lambda, not def; > > Why? This seems like an arbitrary constraint. You'll have to ask th

Re: itemgetter with default arguments

2018-05-04 Thread Steven D'Aprano
On Fri, 04 May 2018 15:27:16 +0200, Antoon Pardon wrote: >> I might be slow today, but I cannot see how to write a clear, obvious, >> efficient lambda that provides functionality equivalent to itemgetter >> with a default value. [...] > This seems to work: > > f = (lambda seq: (list(seq) + 3 * [

Re: itemgetter with default arguments

2018-05-04 Thread Steven D'Aprano
On Fri, 04 May 2018 15:27:02 +0200, Thomas Jollans wrote: spamgetter = (lambda seq, i=2, fallback="spam": > ... seq[i] if abs(i) < len(seq) or i == -len(seq) > ... else fallback) spamgetter("abcd", i=-4) > 'a' spamgetter("abcd") > 'c' spamgett

Re: itemgetter with default arguments

2018-05-04 Thread Steven D'Aprano
On Fri, 04 May 2018 14:38:54 -0600, Ian Kelly wrote: > On Fri, May 4, 2018 at 11:04 AM, Steven D'Aprano > wrote: [...] >> My guess is that they were thinking that there's no need to complicate >> itemgetter for this use-case when it is just as easy to write up a &

Re: itemgetter with default arguments

2018-05-05 Thread Steven D'Aprano
On Sat, 05 May 2018 09:33:37 +0200, Peter Otten wrote: > I think you have established that there is no straight-forward way to > write this as a lambda. What I *mostly* established was that I was having a "cannot brain, I have the dumb" day, because the solution with ternary if was obvious in h

Re: ipython install

2018-05-05 Thread Steven D'Aprano
On Sat, 05 May 2018 00:20:26 -0700, Sharan Basappa wrote: > After this, when I type ipython on command prompt, I don't get anything > on my windows. You don't get *anything*? Not even an error? -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: itemgetter with default arguments

2018-05-05 Thread Steven D'Aprano
On Sat, 05 May 2018 10:31:17 +0300, Serhiy Storchaka wrote: > Consider a concrete example. You need to sort a list of 2- or 3- element > tuples by the first and third items (third items are strings if > presented). itemgetter(0, 2) doesn't work because some tuples has only 2 > items. But you can u

Re: write to file

2018-05-05 Thread Steven D'Aprano
On Sat, 05 May 2018 04:25:50 -0700, Sharan Basappa wrote: > In my program, I have print statements for debugging. However, these are > cluttering the display. So, I am trying to save these to a file but > somehow I cant seem to get it correct. There are lots of way to solve this problem. The bes

Why is calling eval so slow?

2018-05-05 Thread Steven D'Aprano
I understand that calling eval() on a string is going to be slow, since the string has to be parsed, compiled, and then executed. But why is it so slow when called on function __code__ objects and pre- compiled byte-code? Here are the tests I ran: # calling a regular function python3.5 -m time

Re: write to file

2018-05-05 Thread Steven D'Aprano
On Sat, 05 May 2018 08:45:39 -0700, Sharan Basappa wrote: > Thanks a lot. I have actually tried print with file handle as a > parameter (the last option). I see that the file is created but nothing > is logged. That could be a file buffer issue. Nothing will actually be written to the disk until

Re: Why is calling eval so slow?

2018-05-05 Thread Steven D'Aprano
On Sat, 05 May 2018 20:11:28 +0300, Serhiy Storchaka wrote: >> Why so slow? > > 1. Add an overhead of calling eval(), not just looking up its name. It > is comparable with a time of calling a simple lambda. 2. Add an overhead > of getting the globals dict and creating a locals dict. [...] Ah, th

Re: Tracebacks for exceptions in interactively entered code.

2018-05-07 Thread Steven D'Aprano
On Mon, 07 May 2018 15:59:10 -0400, Terry Reedy wrote: > I intend to improve the IDLE doc section on IDLE-console differences. > > The following is from standard interactive mode (PSF CPython 3.7.0a4) on > Windows (Win 10, Command Prompt) > > >>> def f(): > ... return 1/0 > ... > >>> f() >

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-07 Thread Steven D'Aprano
On Mon, 07 May 2018 22:27:22 +0200, all-lists wrote: > Hi, > > I was wondering (and have asked on StackOverflow [1] in a more elaborate > way) whether there is a deeper reason to not allow assignments in lambda > expressions. Currently, the real reason is that lambda expressions are limited to a

Re: Suggestion for a "data" object syntax

2018-05-08 Thread Steven D'Aprano
On Tue, 08 May 2018 06:45:05 +0300, Mikhail V wrote: > *Example 3. Two-dimensional tuple.* > > data === T/T : > 123"hello" > ab c + de f > > is a synonym for: > > data = ( > (1, 2, 3, "hello") , > (a, b, c + d, e, f ) ) Last time you brought up this

Re: Module, Package

2018-05-08 Thread Steven D'Aprano
On Mon, 07 May 2018 09:53:45 -0700, Sharan Basappa wrote: > I am a bit confused between module and package in Python. Does a module > contain package or vice versa? When we import something in Python, do we > import a module or a package? The term "module" in Python has multiple meanings: - a pa

Re: Suggestion for a "data" object syntax

2018-05-08 Thread Steven D'Aprano
On Tue, 08 May 2018 15:52:12 +0300, Mikhail V wrote: >> Last time you brought up this idea, you were told that it is ambiguous. >> Using whitespace alone, it is impossible to distinguish between >> >> a + b >> >> and >> >> a + b >> >> >> Can you see the difference? Of course not. That's th

Re: Suggestion for a "data" object syntax

2018-05-08 Thread Steven D'Aprano
On Tue, 08 May 2018 23:16:23 +0300, Mikhail V wrote: > I don't propose to remove spaces, And that is why the syntax will be ambiguous. So long as whitespace is *allowed* but not *required* around operators, there will be ambiguity between a - b and a - b with no way to tell whether they are in

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-08 Thread Steven D'Aprano
On Tue, 08 May 2018 22:48:52 -0500, Python wrote: > On Tue, May 08, 2018 at 12:45:29AM +0000, Steven D'Aprano wrote: >> Currently, the real reason is that lambda expressions are limited to a >> single expression as the body of the function, and binding operations >>

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-09 Thread Steven D'Aprano
On Wed, 09 May 2018 22:48:42 +0100, bartc wrote: > On 09/05/2018 06:44, Steven D'Aprano wrote: >> On Tue, 08 May 2018 22:48:52 -0500, Python wrote: >> >> >> But by the time 1.4 came around, Guido had settled on a clean >> separation between statemen

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread Steven D'Aprano
On Thu, 10 May 2018 12:43:33 +0200, Virgil Stokes wrote: > Why does the datetime.date  module (both built-in and site-package) not > accept leading 0's? This has nothing to do with the datetime module. Syntax Error means it it prohibited by the language, not the module. In Python 2, leading ze

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread Steven D'Aprano
On Thu, 10 May 2018 17:36:39 +0100, bartc wrote: > I wonder why someone would take a feature generally agreed to be a > poorly designed feature of C, and incorporate it into a new language. Because in 1991 or thereabouts, when Guido was designing the language for the first time, he thought it wa

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread Steven D'Aprano
On Thu, 10 May 2018 11:03:54 -0600, Ian Kelly wrote about proposed prefixes for octal: > Personally I would have preferred the "t". "t" for octal, hey? That would be annoying if we ever get trinary literals. n for binary t for octal i for trinary or should that be r for ternary? o for duodecim

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-10 Thread Steven D'Aprano
On Thu, 10 May 2018 22:59:03 +0300, Marko Rauhamaa wrote: > It turns out "while True" is the most natural choice in > about half of the while loops. YMMV. In my case, it is more like about one in ten. -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-10 Thread Steven D'Aprano
On Fri, 11 May 2018 03:29:57 +0300, Marko Rauhamaa wrote: >> Now do you understand what I mean about putting the condition into the >> loop header? > > Thanks, but no thanks. The "while True" idiom beats that one hands down. Why do you think it is better to lie to the reader and tell them they a

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-10 Thread Steven D'Aprano
On Fri, 11 May 2018 01:51:47 +0300, Marko Rauhamaa wrote: > Paul Rubin : > >> Marko Rauhamaa writes: >>> It turns out "while True" is the most natural choice in about half of >>> the while loops. >> >> Maybe the rest would be "repeat until" if Python had that? > > No. "Repeat until" is a relati

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-10 Thread Steven D'Aprano
On Fri, 11 May 2018 05:17:59 +, Steven D'Aprano wrote: > On Fri, 11 May 2018 03:29:57 +0300, Marko Rauhamaa wrote: [...] > To answer your question from a later post: > > In what way does "while True" in the general case pretend to be an > infinite lo

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-10 Thread Steven D'Aprano
On Thu, 10 May 2018 20:38:39 -0600, Ian Kelly wrote: > Would you also contend that generator functions are wrong because they > pretend to be normal functions? You're going to need to be more specific. In what way are they not normal functions? You call them like normal functions, providing argu

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread Steven D'Aprano
On Thu, 10 May 2018 23:23:33 -0600, Ian Kelly wrote: > On Thu, May 10, 2018 at 9:21 PM, Steven D'Aprano > wrote: >> On Thu, 10 May 2018 11:03:54 -0600, Ian Kelly wrote about proposed >> prefixes for octal: >> >>> Personally I would have preferred the &qu

Re: Meaning of abbreviated terms

2018-05-10 Thread Steven D'Aprano
On Fri, 11 May 2018 07:20:36 +, Bob Martin wrote: > in 793605 20180511 044309 T Berger wrote: >>On Saturday, May 5, 2018 at 6:45:46 PM UTC-4, MRAB wrote: >>> On 2018-05-05 17:57, T Berger wrote: >>> > What does the "p" in "plist" stand for? Is there a python glossary >>> > that spells out the

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-11 Thread Steven D'Aprano
On Fri, 11 May 2018 21:55:17 +1200, Gregory Ewing wrote: > Hex came into vogue in the DEC world with the VAX, which was both > byte-addressed and had a hex-oriented instruction encoding. Indeed. In 2018 when nearly all computers (aside from some DSPs) have standardised on the same number of bit

Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-11 Thread Steven D'Aprano
On Fri, 11 May 2018 16:56:09 +0100, bartc wrote: > 0100, if not intended as octal, is > an undetectable error in C and Python 2. How fortunate then that Python 2 is history (soon to be ancient history) and people can use Python 3 where that error of judgement has been rectified. -- Steve -

Re: issue runing ipython

2018-05-11 Thread Steven D'Aprano
On Fri, 11 May 2018 20:13:08 -0700, Sharan Basappa wrote: > I see an issue while running ipython. Can anyone help please. Is the error message not clear enough? It tells you what the problem is ("ipython notebook" is deprecated) and tells you how to fix it (use "jupyter notebook" instead). >

Re: Suggestion for a "data" object syntax

2018-05-11 Thread Steven D'Aprano
On Sat, 12 May 2018 02:26:05 +0300, Mikhail V wrote: > it is just not a trivial task to find an optimal solution to this We already have an optimal solution to this. * It works with any editor, including simple ones. * It is safe for transmit over email, or on web forums, so long as you av

Re: seeking deeper (language theory) reason behind Python design choice

2018-05-13 Thread Steven D'Aprano
On Sat, 12 May 2018 21:42:13 -0500, Python wrote: > Responding to this further would essentially just require me to > reiterate what I already wrote--I won't do that. I'll simply maintain > that in my rather lenghty experience, this mistake has actually been > rather rare and has to my knowledge

Re: random.choices() Suggest that the code confirm that cum_weights sequence is in ascending order

2018-05-14 Thread Steven D'Aprano
Hi Paul, and welcome! On Sun, 13 May 2018 17:48:47 -0700, Paul wrote: > Hi, > I just learned how to use random.choices(). [...] > Consequently, I specified 'cum_weights' with a sequence which wasn't in > ascending order. I got back k results but I determined that they > weren't correct (eg,

Re: object types, mutable or not?

2018-05-14 Thread Steven D'Aprano
On Sun, 13 May 2018 13:02:01 -0700, Mike McClain wrote: [...] > It appears to me as if an object's type is totally mutable and solely > dependant on assignment. > obj = 'a1b2' type (obj) > obj = list(obj) type (obj) > > At what level does my understanding break down?

Re: random.choices() Suggest that the code confirm that cum_weights sequence is in ascending order

2018-05-14 Thread Steven D'Aprano
On Mon, 14 May 2018 22:27:24 +1000, Chris Angelico wrote: > On Mon, May 14, 2018 at 9:59 PM, Paul Moore wrote: >> The problem is that supplying cum_weights allows the code to run in >> O(log n) by using bisection. This is significantly faster on large >> populations. Adding a test that the cumula

Re: random.choices() Suggest that the code confirm that cum_weights sequence is in ascending order

2018-05-14 Thread Steven D'Aprano
On Mon, 14 May 2018 12:59:28 +0100, Paul Moore wrote: > The problem is that supplying cum_weights allows the code to run in > O(log n) by using bisection. This is significantly faster on large > populations. Adding a test that the cumulative weights are nondecreasing > would add an O(n) step to th

<    22   23   24   25   26   27   28   29   30   31   >