Re: [Python-ideas] More user-friendly version for string.translate()

2016-10-24 Thread Chris Barker - NOAA Federal
>> > re.sub('[^0-9]', '', 'ab0c2m3g5') >> '0235' >> >> Possibly because there's a lot of good Python builtins that allow you >> to avoid the re module when *not* needed, it's easy to forget it in >> the cases where it does pretty much exactly what you want, There is a LOT of overhead to figuri

Re: [Python-ideas] More user-friendly version for string.translate()

2016-10-24 Thread Chris Barker - NOAA Federal
> Just a pair of usage cases which I was facing in my practice: > So I just define a table like: > { > 1072: 97 > 1073: 98 > 1074: 99 > ... > [which localizes Cyrillic into ASCII] > ... > 97:97 > 98:98 > 99:99 > ... > [those chars that are OK, leave them] > } > > Then I use os.walk() and os.rename

Re: [Python-ideas] Easily remove characters from a string.

2016-10-24 Thread Chris Barker - NOAA Federal
> On Oct 24, 2016, at 3:54 PM, Chris Angelico wrote: > . But in any case, > this is a question you can't even ask until replace() accepts multiple > arguments. Hence I'm +1 on the notion of simultaneous replacements > being supported. Agreed -- there are a lot of edge cases to work out, and ther

Re: [Python-ideas] How we think about change [was: Reverse assignment operators...]

2016-11-15 Thread Chris Barker - NOAA Federal
> Because "+" and "+=" are operators which may be defined for any > objects. Paul explained *why* he chose to to do that elsewhere. My > point is that the semantics "a += b" *is* "type(a).__iadd__(a, b)" is > true for all objects. Well, yes. But it is defined in particular ways in the built in t

Re: [Python-ideas] PEP 540: Add a new UTF-8 mode

2017-01-10 Thread Chris Barker - NOAA Federal
>> How common is this problem? > > Last 2 or 3 years, I don't recall having be bitten by such issue. We just got bitten by this on our CI server. Granted, we could fix it by properly configuring docker, but it would have been nice if it " just worked" -CHB

Re: [Python-ideas] Python reviewed

2017-01-11 Thread Chris Barker - NOAA Federal
for range(1,1): means executing once to me. The indexing/slicing approach was designed for indexing and slicing. Then it made sense to have range() match. But range() is not part of the for construction. It is a convenience function for providing an iterable of integers. And you are welcome to wr

Re: [Python-ideas] How to respond to trolling

2017-01-11 Thread Chris Barker - NOAA Federal
> the effect was dozens of messages with people falling over each other trying to engage the OP, Sure -- but all in one thread > The respondents should have known better. But we like to kibitz-- that's why (many of us) are on this list. Anyway, all (most anyway) of the points brought up are :

Re: [Python-ideas] OS related file operations (copy, move, delete, rename...) should be placed into one module

2017-01-12 Thread Chris Barker - NOAA Federal
I agree that this has been a bit of a wart for a long time. While the old “let’s treat strings as paths” modules are split up like you said, pathlib can do what they do and more: https://docs.python.org/3/library/pathlib.html Exactly -- this is The Solution. It combines paths themselves with thi

Re: [Python-ideas] Settable defaulting to decimal instead of float

2017-01-12 Thread Chris Barker - NOAA Federal
While I think some variation of: from __optional__ import decimal_literal Might be reasonable, I'd probably rather see something like: X = 1.1D However: (thank you Chris and Stephen) -- Decimal is NOT a panacea, nor any more "accurate" than binary floating point. It is still floating point, i

Re: [Python-ideas] OS related file operations (copy, move, delete, rename...) should be placed into one module

2017-01-12 Thread Chris Barker - NOAA Federal
> On Jan 12, 2017, at 2:26 PM, Terry Reedy wrote: > > > Start a new thread for 'Add x to pathlib'. > And do take some time to see if a given suggestion has already been discussed first. -CHB ___ Python-ideas mailing list Python-ideas@python.org https://

Re: [Python-ideas] Things that won't change (proposed PEP)

2017-01-12 Thread Chris Barker - NOAA Federal
> By saying that "these are things that will not change", I agree -- these are not exactly " things that will not change" as they are: "Things that have been discussed (often ad nausium) and considered and definitively rejected" And many of them are: "Part of what makes Python Python" I think

Re: [Python-ideas] math.nextafter

2017-02-24 Thread Chris Barker - NOAA Federal
On Feb 24, 2017, at 10:28 AM, Mahmoud Hashemi wrote: By the way, it looks like math doesn't have machine epsilon either: > > > https://en.wikipedia.org/wiki/Machine_epsilon > > Pretty sure machine epsilon is in the sys module's float_info object. Ahh, thanks! I though I remembered it was somewh

Re: [Python-ideas] Extension of python/json syntax to support explicitly sets and ordered dict.

2017-09-07 Thread Chris Barker - NOAA Federal
a json-like format (pyson maybe ?). I gonna pyson is a fine idea. But don't call it extended JSON ;-) For me, the point would be to capture Python' s richer data types. But would you need an OrderedDict? As pointed out, in recent cPython ( and pypy) dicts are ordered by default, but it's not p

Re: [Python-ideas] A PEP to define basical metric which allows to guarantee minimal code quality

2017-09-20 Thread Chris Barker - NOAA Federal
> How do we handle different organizational requirements? > By keeping linting out of the code ( and certainly out of "official" python), and in the organization's development process where it belongs. > @pylint([34]) > @pep([8,20]) > def f(a): > return math.sqrt(a) Yeach! But that's just my op

Re: [Python-ideas] A PEP to define basical metric which allows to guarantee minimal code quality

2017-09-20 Thread Chris Barker - NOAA Federal
> You can define metrics. But as to what they mean? Well that is the question. One big problem with metrics is that we tend to measure what we know how to measure -- generally really not the most useful metric... As for some kind of PEP or PEP-like document: I think we'd have to see a draft befo

Re: [Python-ideas] Hexadecimal floating literals

2017-09-20 Thread Chris Barker - NOAA Federal
> And that's one of the reasons why the hexadecimal floating-point > representation exist: I suspect no one here thinks floathex representation is unimportant... > > To sum up: > - In some specific context, hexadecimal floating-point constants make it > easy for the programmers to reproduce t

Re: [Python-ideas] install pip packages from Python prompt

2017-10-30 Thread Chris Barker - NOAA Federal
It's not 100% clear to me how my proposal below would work within a > Jupyter Notebook, so that would also be an angle worth looking into. > I'm -1 on this as I view it as a tooling issue, not a language issue. Agreed. And for the tool at hand, the notebook already controls the python interprete

Re: [Python-ideas] install pip packages from Python prompt

2017-10-31 Thread Chris Barker - NOAA Federal
> Nope. I totally get that they don’t know what a shell or command prompt > is. THEY. NEED. TO. LEARN. Hiding it is not a good idea for anyone. I actually take this approach myself in my classes. However, I also have as prerequisites for my classes: Some Experience in some programming languag

Re: [Python-ideas] Any chance on (slowly) deprecating `eval` and `exec` as builtins?

2017-11-07 Thread Chris Barker - NOAA Federal
But the point is that the compiler is recursive, and processing nested constructs consumes the C stack. There are some guards against too deep recursion (2.7 has less guards and more vulnerable), but it is hard to prove that all vulnerabilities are fixed. Your method (limiting the size of the inpu

Re: [Python-ideas] Looking for input to help with the pip situation

2017-11-14 Thread Chris Barker - NOAA Federal
On Nov 13, 2017, at 1:53 PM, Paul Moore wrote: In principle, I agree with the ideas here, but there are some practical issues that make them somewhat less straightforward than we might like. And practically beats principally ;-) But yeah. 1) Add python2.exe and python3.exe files to the Windo

Re: [Python-ideas] Consider (one day) adding an inheritance order class precedence mechanism

2017-11-16 Thread Chris Barker - NOAA Federal
It doesn't -- that's the point. Currently it's assumed that the order base classes appear in a class statement is the order that they must appear in the MRO. It’s not assumed — it’s how order is specified by the coder... But that's not always true. Isn’t it true by definition? I'm suggesting

Re: [Python-ideas] a sorting protocol dunder method?

2017-12-08 Thread Chris Barker - NOAA Federal
If by no brainer you mean the performance of __sort-key__ is always better of __lt__ No. By no-brainer I meant that IF there is a __sort_key__ defined, then it should be used for sorting, regardless of whether __lt__ is also defined. (min and max should probably prefer __lt__) I will wask for a

Re: [Python-ideas] Non-intrusive debug logging

2018-01-25 Thread Chris Barker - NOAA Federal
This strikes me as something a debugger should do, rather than the regular interpreter. And using comment-based syntax means that they would get ignored by the regular interpreter— which is exactly what you want. As for a decoration approach— that wouldn’t let you do anything on a line by line ba

Re: [Python-ideas] Why CPython is still behind in performance for some widely used patterns ?

2018-01-30 Thread Chris Barker - NOAA Federal
> > It's easier to make a good language fast than it is to make a fast language > good. It's easier to hack a compiler or an interpreter to run slow code > faster than it is to hack the human brain to understand confusing code more > easily. So I think the smart move is to take the languages

Re: [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

2018-02-14 Thread Chris Barker - NOAA Federal
> > So as long as you are not expecting to ever need mypy you should be fine -- > however if you're sharing code at some point someone is probably going to > want to point mypy at it. mypy isn’t an “official” tool, but PEP484 is — and mypy is more or less a reference implimentation, yes? mypy s

Re: [Python-ideas] Temporary variables in comprehensions

2018-02-15 Thread Chris Barker - NOAA Federal
I’d like to clarify that f(x) was indeed meant to be a sequence. As per monad law: *do* { y *<-* *do* { x *<-* m; f x } g y } === *do* { x *<-* m; y *<-* f x; g y } I think you might have misunderstood the types of things; f: Function[

Re: [Python-ideas] Temporary variables in comprehensions

2018-02-15 Thread Chris Barker - NOAA Federal
> Setting a new comprehension variable is not likely to be free, and may even be > more costly than calling f(x) twice if f() is a cheap expression: > >[x+1 + some_func(x+1) for x in range(10)] > > could be faster than > >[y + some_func(y) for x in range(10) let y = x + 1] A bit of a nit —

Re: [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

2018-02-16 Thread Chris Barker - NOAA Federal
Sent from my iPhone > A thought just occurred to me. Maybe we should just add a Boolean class to > numbers? This makes lots of sense to me. Bool is a subclass of int — might as well embrace that fact. -CHB ___ Python-ideas mailing list Python-ideas@py

Re: [Python-ideas] New PEP proposal -- Pathlib Module ShouldContain All File Operations -- version 2

2018-03-23 Thread Chris Barker - NOAA Federal
On Mar 23, 2018, at 7:26 AM, Steve Dower wrote: I had a colleague complaining to me the other day about having to search multiple packages for the right function to move a file (implying: with the same semantics as drag-drop). Thanks Steve — I know there isn’t any kind of consensus about exactl

Re: [Python-ideas] Sets, Dictionaries

2018-03-29 Thread Chris Barker - NOAA Federal
> There are two chances of this happening, zero or none. That would be the empty set, yes? ;-) -CHB ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeo

Re: [Python-ideas] Fix default encodings on Windows

2016-08-15 Thread Chris Barker - NOAA Federal
> Given that, I'm proposing adding support for using byte strings encoded with > UTF-8 in file system functions on Windows. This allows Python users to omit > switching code like: > > if os.name == 'nt': >f = os.stat(os.listdir('.')[-1]) > else: >f = os.stat(os.listdir(b'.')[-1]) REALLY?

Re: [Python-ideas] Fix default encodings on Windows

2016-08-16 Thread Chris Barker - NOAA Federal
> There also seems to be an undercurrent in the discussions we're having > now that using bytes paths and not unicode paths is somehow The Right > Thing for unix-like OSes, Almost -- from my perusing of discussions from the last few years, there do seem to be some library developers and *nix affec

Re: [Python-ideas] Syntactic sugar to declare partial functions

2018-08-14 Thread Chris Barker - NOAA Federal via Python-ideas
> > Do we often call functools.partial on arbitrary callable objects that we > don't know in advance? For my part, I don’t think I’ve ever used partial in production code. It just seems easier to simply fo it by hand with a closure ( Am I using that term right? I still don’t quite get the terminol

Re: [Python-ideas] Python docs: page: In what ways in None special

2018-08-15 Thread Chris Barker - NOAA Federal via Python-ideas
> None is keyword, and just like any other keyword, it can't be re-bound. >> it's only a keyword because Python doesn't otherwise have a way of creating >> non-rebindable names. It's purpose is to represent the singular object of >> NoneType, and in that sense it's a literal as much as [] or "

Re: [Python-ideas] Jump to function as an an alternative to call function

2018-08-17 Thread Chris Barker - NOAA Federal via Python-ideas
By the way— really kludgy, doesn’t exec() do what you want here: Note The default *locals* act as described for function locals() below: modifications to the default *locals* dictionary should not be attempted. Pass an explicit *locals*di

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Chris Barker - NOAA Federal via Python-ideas
while True: button, (a,b) = form.Read() try: answer = int(a) + int(b) output.Update(answer) except: pass Whoa! You really want people to write their own event loop? That seems like a bad idea to me. If you want people to not have to think about events much, maybe lo

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Chris Barker - NOAA Federal via Python-ideas
> If you're talking about my PyGUI project, using it with > wPython doesn't really make sense. Now that you say that, I think I’m mingling memories — there was another project that attempted to wrap TKInter, wxPython, QT .. I always thought that was ill advised. > The goal is to provide exactly o

Re: [Python-ideas] support toml for pyproject support

2018-10-09 Thread Chris Barker - NOAA Federal via Python-ideas
If I had the energy to argue it I would also argue against using TOML > in those PEPs. I partook in that discussion, and I still have no idea why TOML was chosen, over, say, a defined subset of YAML, or a slightly extended JSON. But the folks that were highly invested and putting the work in ma

Re: [Python-ideas] Revisiting Immutable Mappings

2018-10-11 Thread Chris Barker - NOAA Federal via Python-ideas
> This violates the Liskov Substitution Principle. If we REALLY had a time machine, then dict would subclass frozendict, and we’d be all set. But to what extent do we need to support ALL the ways to check for an interface? Personally, I think EAFTP is the most “Pythonic”, but if folks want to ch

Re: [Python-ideas] Relative Imports

2018-11-13 Thread Chris Barker - NOAA Federal via Python-ideas
This is somewhat unpleasant to me, especially while developing something and trying to test it quickly. I just want to be able to use same relative imports and run single file with `python3 test_main.py` for example. I had the same frustration when I first tried to use relative imports. Then I d

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-11 Thread Chris Barker - NOAA Federal via Python-ideas
Perhaps I got confused by the early part of this discussion. My point was that there is no “map-like” object at the Python level. (That is no Map abc). Py2’s map produced a sequence. Py3’s map produced an iterable. So any API that was expecting a sequence could accept the result of a py2 map, bu

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-12 Thread Chris Barker - NOAA Federal via Python-ideas
>>> and the test for an iterator is: >>> >>> obj is iter(obj) Is that a hard and fast rule? I know it’s the vast majority of cases, but I imagine you could make an object that behaved exactly like an iterator, but returned some proxy object rather that itself. Not sure why one would do that, bu

Re: [Python-ideas] Add list.join() please

2019-01-29 Thread Chris Barker - NOAA Federal via Python-ideas
> Alex Shafer via Python-ideas wrote: >> 1) I'm in favor of adding a stringify method to all collections > > Are you volunteering to update all the collection > classes in the world written in Python? :-) To be fair, we could add an implementation to the sequence ABC, and get pretty far. Not that

Re: [Python-ideas] Attribute-Getter Syntax Proposal

2019-03-08 Thread Chris Barker - NOAA Federal via Python-ideas
> > Rather than using map in this way, I would recommend a list comprehension: Exactly! I really don’t get why folks want to use map() so much when the comprehension syntax is often cleaner and easier. It was added for a reason :-) -CHB ___ Python-ideas

Re: [Python-ideas] High Precision datetime

2018-05-14 Thread Chris Barker - NOAA Federal via Python-ideas
> > UTC and leap seconds aren't a problem. Of course they are a problem— why else would they not be implemented in datetime? But my point if that given datetimestamp or calculation could be off by a second or so depending on whether and how leap seconds are implemented. It just doesn’t seem like

Re: [Python-ideas] String and bytes bitwise operations

2018-05-18 Thread Chris Barker - NOAA Federal via Python-ideas
>> actually, bytes are, well, bytes ;-) -- that is, 8 bits. > > Grammatically, you appear to be disagreeing with the assertion that > bytes are numbers. Is that the case? Um, yes. Though I think for the rest of the conversation, it’s a distinction that doesn’t matter. > If you want to be extremel

Re: [Python-ideas] Add dict.append and dict.extend

2018-06-04 Thread Chris Barker - NOAA Federal via Python-ideas
> d.setdefault(key, value) I though the OP wanted an error if the key already existed. This is close, as it won’t change the dict if the key is already there, but it will add it if it’s not. @OP Maybe post those five lines so we know exactly what you want — maybe there is already a good solutio

Re: [Python-ideas] Making Path() a built in.

2018-06-05 Thread Chris Barker - NOAA Federal via Python-ideas
Sorry for the top-post — iPhone email sucks. But: in regard to the whole “what paths to use to find resource files” issue: The “current working directory” concept can be very helpful. You put your files in a directory tree somewhere— could be inside the package, could be anywhere else. Then all

Re: [Python-ideas] Making Path() a built in.

2018-06-06 Thread Chris Barker - NOAA Federal via Python-ideas
>>> For the startup time, you could keep it around as builtin but save the >>> import time until someone actually uses it. >> >> That would mean creating a system of lazy imports, which is an >> entirely separate proposal. > > It's that complicated ? I know it's not exactly properties on a class, >

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-23 Thread Chris Barker - NOAA Federal via Python-ideas
>> However -- if this is really such a good idea -- wouldn't someone have make >> a C lib that does it? Or has someone? Anyone looked? > > No, there's nothing magical about C. You can do it in pure Python. Sure, but there are a number of FP subtleties around the edge cases. So wrapping (or transl

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Chris Barker - NOAA Federal via Python-ideas
I don’t think anyone would argue that there would be use cases for __max__ and __min__ special methods. However, there is substantial overhead to adding new magic methods, so the question is not whether it would be useful in some special cases, but whether it would be useful enough in common enou

Re: [Python-ideas] Add a __cite__ method for scientific packages

2018-06-28 Thread Chris Barker - NOAA Federal via Python-ideas
I think this is a fine idea, but could be achieved by convention, like __version__, rather than by fiat. And it’s certainly not a language feature. So Nathaniel’s right — the thing to do now is work out the convention, and then advocate for it. -CHB __

Re: [Python-ideas] Allow a group by operation for dict comprehension

2018-06-28 Thread Chris Barker - NOAA Federal via Python-ideas
> I think you accidentally swapped variables there: > student_school_list > vs student_by_school Oops, yeah. That’s what I get for whipping out a message before catching a bus. (And on a phone now) But maybe you could wrap the defaultdict constructor around a generator expression that transforms

Re: [Python-ideas] Allow a group by operation for dict comprehension

2018-06-28 Thread Chris Barker - NOAA Federal via Python-ideas
> On Jun 28, 2018, at 5:30 PM, Chris Barker - NOAA Federal > wrote: > > So maybe a solution is an accumulator special case of defaultdict — it uses a > list be default and appends by default. > > Almost like counter... Which, of course, is pretty much what your proposa

Re: [Python-ideas] Where should grouping() live (was: grouping / dict of lists)

2018-07-06 Thread Chris Barker - NOAA Federal via Python-ideas
On Jul 6, 2018, at 2:10 AM, Steven D'Aprano wrote: I would consider statistics to have similarities - median, mean etc are aggregate functions. Not really, more like reduce, actually -/ you get a single result. Histograms are also doing something similar to grouping. .(Yes, a few statistic

Re: [Python-ideas] if we were to ever shorten `A if A else B` (was: PEP 505: None-aware operators)

2018-07-21 Thread Chris Barker - NOAA Federal via Python-ideas
> my vote would go to `A otherwise B` since it's unambiguous, the case you care > about the state of comes first, and it doesn't trip your brain up looking > for 'if'. :) And I’d hope “otherwise” is a rare variable name :-) - CHB > > ___ > Python-id

Re: [Python-ideas] Multi-core reference count garbage collection

2018-07-21 Thread Chris Barker - NOAA Federal via Python-ideas
> You wrote: > > I'd argue that the ref counts are not interesting at all, only a > > side effect of one possible solution to the object life time problem. > > I'm happy for you to regard multi-core reference counting (MCRC) as a toy > problem, which won't become part of useful software. Perhaps

Re: [Python-ideas] Performance improvements via static typing

2018-07-21 Thread Chris Barker - NOAA Federal via Python-ideas
A note here: Earlier in the conversation about standardizing type hinting, I (among others) was interested in applying it to C-level static typing (e.g. Cython). Guido made it very clear that that was NOT a goal of type hints — rather, they were to be used for dynamic, python style types — so a “

Re: [Python-ideas] Revisiting str.rreplace()

2018-07-21 Thread Chris Barker - NOAA Federal via Python-ideas
I starting g reading this thread in the middle, on a phone. But was very confused for a while because I didn’t notice that there were two ‘r’s at the beginning of .rreplace Just sayin’ -CHB Sent from my iPhone > On Jul 19, 2018, at 9:29 AM, Paul Moore wrote: > >> On 19 July 2018 at 16:25, Eri

Re: [Python-ideas] Python docs page: In what ways is None special

2018-07-23 Thread Chris Barker - NOAA Federal via Python-ideas
>lot. Actually, the ?. and ?[ > operators seem like they'd be much more useful if I did more JSON > processing - This has been mentioned a lot in this discussion— Maybe what we need is a smarter JSON processing package, rather than new operators. Granted, these operators would help the authors o

Re: [Python-ideas] Python docs page: In what ways is None special

2018-07-23 Thread Chris Barker - NOAA Federal via Python-ideas
I agree that some more docs on the specialness of None (and, to a lessor extent, True and False). A few comments: > None is a keyword > == None = 0 > SyntaxError: can't assign to keyword One of the implications of this is that “None” will always be the Singleton None object — so