Re: for -- else: what was the motivation?

2022-10-16 Thread Antoon Pardon
Op 16/10/2022 om 13:03 schreef Chris Angelico: On Sun, 16 Oct 2022 at 21:19, Antoon Pardon wrote: My idea would be to reserve different unicode blocks for the keywords and the identifiers. e.g. We could reserve the mathematical alphanumeric block for keywords and all other letters and

Re: for -- else: what was the motivation?

2022-10-16 Thread Antoon Pardon
Op 16/10/2022 om 17:05 schreef Chris Angelico: On Sun, 16 Oct 2022 at 22:47, Antoon Pardon wrote: Why would I need good luck? I expressed an idea and you didn't like it. That won't affect my life in a meaningful way. Well, with that attitude, it's not going to affect any

Re: for -- else: what was the motivation?

2022-10-16 Thread Antoon Pardon
Op 16/10/2022 om 19:03 schreef Chris Angelico: On Mon, 17 Oct 2022 at 03:57, Antoon Pardon wrote: Op 16/10/2022 om 17:05 schreef Chris Angelico: On Sun, 16 Oct 2022 at 22:47, Antoon Pardon wrote: Why would I need good luck? I expressed an idea and you didn't like it. That won

Re: for -- else: what was the motivation?

2022-10-16 Thread Antoon Pardon
to and from a long list of reserved key words that may vary by locale? I think you are carrying my idea further than I intended. I was just thinking that instead of using U+0064 U+0065 U+0066 [beinf def] we could be using U+1D41D U+1D41E U+1D41F [being  𝐝𝐞𝐟]. -- Antoon Pardon. -- https

Re: for -- else: what was the motivation?

2022-10-16 Thread Antoon Pardon
Op 16/10/2022 om 19:01 schreef Peter J. Holzer: On 2022-10-16 12:17:39 +0200, Antoon Pardon wrote: Op 16/10/2022 om 00:50 schreefavi.e.gr...@gmail.com: That might not easily solve this problem. But I wonder if reserving some kind of prefix might help, so anything like extension.0nNoBreak

Re: for -- else: what was the motivation?

2022-10-16 Thread Antoon Pardon
gerent reaction. You made it clear you wanted a fight. I choose not to enter that fight. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: Optional arguments in a class behave like class attributes.

2022-10-17 Thread Antoon Pardon
You can use the following decorator for what you probably want. def copy_defaults(func): """ This decorator makes that defaults values are copied on a call. """ signature = inspect.signature(func) parameter_items = list(signature.parameters.items()) @wraps(func) def

Re: Does one have to use curses to read single characters from keyboard?

2022-12-11 Thread Antoon Pardon
t could possibly go wrong? Nothing that can't go wrong otherwise. It is my experience that when a [Return] is needed, people just type in a two key combination. They don't type one key, then check, then type [Return]. So in practice the same things go wrong, either way. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

How make your module substitute a python stdlib module.

2022-12-27 Thread Antoon Pardon
logging module to call the function from my module to get the current_thread, instead of it calling "current_thread" from the threading module. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: How make your module substitute a python stdlib module.

2022-12-27 Thread Antoon Pardon
Op 27/12/2022 om 11:37 schreef Chris Angelico: On Tue, 27 Dec 2022 at 21:29, Antoon Pardon wrote: OK, I am writing an alternative for the threading module. What I would like to know is how I can get some library modules call my alternative instead of the threading module. For instance there

Re: How make your module substitute a python stdlib module.

2022-12-27 Thread Antoon Pardon
Op 27/12/2022 om 12:28 schreef Chris Angelico: On Tue, 27 Dec 2022 at 22:13, Antoon Pardon wrote: Op 27/12/2022 om 11:37 schreef Chris Angelico: On Tue, 27 Dec 2022 at 21:29, Antoon Pardon wrote: OK, I am writing an alternative for the threading module. What I would like to know is how

Re: How make your module substitute a python stdlib module.

2022-12-27 Thread Antoon Pardon
Op 27/12/2022 om 13:09 schreef Chris Angelico: On Tue, 27 Dec 2022 at 23:06, Antoon Pardon wrote: How do you intend to distinguish one from the other? How should the logging module know which threading module to use? That is my question! How can I get the logging module to use my module.I

Re: How make your module substitute a python stdlib module.

2022-12-27 Thread Antoon Pardon
Op 27/12/2022 om 13:46 schreef Chris Angelico: On Tue, 27 Dec 2022 at 23:28, Antoon Pardon wrote: At the moment I am happy with a solution that once the programmer has imported from QYZlib.threaders that module will used as the threading module. Oh! If that's all you need, then y

Re: How make your module substitute a python stdlib module.

2022-12-28 Thread Antoon Pardon
Op 27/12/2022 om 16:49 schreef Thomas Passin: On 12/27/2022 8:25 AM, Antoon Pardon wrote: Op 27/12/2022 om 13:46 schreef Chris Angelico: On Tue, 27 Dec 2022 at 23:28, Antoon Pardon  wrote: At the moment I am happy with a solution that once the programmer has imported from QYZlib.threaders

Re: Evaluation of variable as f-string

2023-01-25 Thread Antoon Pardon
Op 23/01/2023 om 17:24 schreef Johannes Bauer: Hi there, is there an easy way to evaluate a string stored in a variable as if it were an f-string at runtime? I.e., what I want is to be able to do this: x = { "y": "z" } print(f"-> {x['y']}") This prints "-> z", as expected. But consider: x

Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Antoon Pardon
Op 27/01/21 om 05:17 schreef Dan Stromberg: On Tue, Jan 26, 2021 at 8:13 PM Dan Stromberg wrote: On Tue, Jan 26, 2021 at 4:01 PM C W wrote: Hello everyone, I'm a long time Matlab and R user working on data science. How do you troubleshooting/debugging in Python? I frequently read trac

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Antoon Pardon
Op 2/02/21 om 01:54 schreef Skip Montanaro: Here's the crux of the problem. Where does responsibility generally fall for low level exception handling? I don't mean to pick on IMAPClient. It's just a recent example and got me thinking about the problem. Is it (generally) the responsibility of the

Mutable defaults

2021-02-09 Thread Antoon Pardon
Most of us know of the perils of mutable default values. So I came up with the following proof of concept: from inspect import signature as signature_of, Parameter from itertools import zip_longest from copy import copy def copy_defaults(f): signature = signature_of(f) def wrapper(*ar

python 2.6: Need some advise for installing modules on a legacy system

2021-02-24 Thread Antoon Pardon
I need to do some development on this legacy system. It only runs python2.6 and there is little hope of installing an other version. How can I best proceed to install modules for working with mysql and ldap? -- Antoon. -- https://mail.python.org/mailman/listinfo/python-list

Re: name for a mutually inclusive relationship

2021-02-26 Thread Antoon Pardon
Op 24/02/21 om 17:12 schreef Ethan Furman: I'm looking for a name for a group of options that, when one is specified, all of them must be specified. It seems you are looking at an equivalence. -- https://mail.python.org/mailman/listinfo/python-list

f-strings and internationalisation.

2021-05-24 Thread Antoon Pardon
languages. Can that be done with f-strings? -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Mailing list activity low

2021-10-12 Thread Antoon Pardon
Have I missed something and has the maillinglist been moved. Activity is very low here, about one message every five days. Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

importing a module from a file without the '.py' suffix

2021-10-22 Thread Antoon Pardon
I have a file with python code but the name doesn't end with the '.py' suffix. What is the easiest way to import this code as a module without changing its name? -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-25 Thread Antoon Pardon
ight the second code over the first. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-25 Thread Antoon Pardon
By putting limits on the walrus code, you are not reducing complexity, you are increasing it. You are increasing complexity because you can't just reuse the code that handles an ordinary assignment. You now need specific code to limit it's use. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-25 Thread Antoon Pardon
Op 25/10/2021 om 20:39 schreef Chris Angelico: > On Tue, Oct 26, 2021 at 5:35 AM Antoon Pardon wrote: >> By putting limits on the walrus code, you are not reducing complexity, you >> are increasing it. >> You are increasing complexity because you can't just reuse th

Re: New assignmens ...

2021-10-26 Thread Antoon Pardon
Op 25/10/2021 om 23:03 schreef Chris Angelico: > On Tue, Oct 26, 2021 at 7:18 AM Antoon Pardon wrote: >> Op 25/10/2021 om 20:39 schreef Chris Angelico: >>> On Tue, Oct 26, 2021 at 5:35 AM Antoon Pardon wrote: >>>> By putting limits on the walrus code, you ar

Re: New assignmens ...

2021-10-26 Thread Antoon Pardon
Op 25/10/2021 om 18:47 schreef Christman, Roger Graydon: Message: 8 Date: Mon, 25 Oct 2021 11:20:52 +0200 From: Antoon Pardon To: python-list@python.org Subject: Re: New assignmens ... Message-ID: <5761dd65-4e87-8b8c-1400-edb821204...@vub.be> Content-Type: text/plain; charset=utf-8;

Re: New assignmens ...

2021-10-26 Thread Antoon Pardon
se an assignment. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-27 Thread Antoon Pardon
that one use case or is that a use case for each kind of couple? And even if the benefits are little per case, they can add up with every occasion such a case pops up. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-27 Thread Antoon Pardon
Op 27/10/2021 om 10:05 schreef Chris Angelico: On Wed, Oct 27, 2021 at 6:00 PM Antoon Pardon wrote: Op 26/10/2021 om 00:24 schreef Chris Angelico: TBH, I don't think there's a lot of value in multiple-assignment, since it has a number of annoying conflicts of syntax and few

Re: New assignmens ...

2021-10-27 Thread Antoon Pardon
Op 27/10/2021 om 10:05 schreef Chris Angelico: On Wed, Oct 27, 2021 at 6:00 PM Antoon Pardon wrote: Op 26/10/2021 om 00:24 schreef Chris Angelico: TBH, I don't think there's a lot of value in multiple-assignment, since it has a number of annoying conflicts of syntax and few

Re: New assignmens ...

2021-10-27 Thread Antoon Pardon
walrus operator we should combine those two work variables into some kind of instance no matter how contrived. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-27 Thread Antoon Pardon
Op 27/10/2021 om 10:49 schreef Chris Angelico: On Wed, Oct 27, 2021 at 7:46 PM Antoon Pardon wrote: So if you want this added, show a use-case that makes it look way better than the alternatives (including a generator, a mid-loop break, etc). Way better according to which criteria? IMO to

Re: New assignmens ...

2021-10-27 Thread Antoon Pardon
s probably a whole let useful. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-27 Thread Antoon Pardon
Op 27/10/2021 om 18:16 schreef Christman, Roger Graydon: On 27/10/2021 at 12:45 Antoon Pardon wrote: However with the introduction of the walrus operator there is a way to simulate a significant number of one and a half loops. Consider the following: >do > a =

Re: New assignmens ...

2021-10-28 Thread Antoon Pardon
Op 27/10/2021 om 20:20 schreef Avi Gross: I think anyone who suggests we should separate costs from benefits belongs securely within the academic world and should remain there. Practical things need to be built considering costs. Theoretical things, sure, cost is not an issue. Seperating co

Re: New assignmens ...

2021-10-28 Thread Antoon Pardon
he loop that is initialized to True and then later assign that boolean the result of the test which you use to control this loop. Should I think it worth the trouble to rewrite your example, quod non, it would be like below, with that unneeded list. while [ play_game(), input("P

Re: New assignmens ...

2021-10-28 Thread Antoon Pardon
ying costs are not as issue. I then explain you misunderdood en now you come with the above. Maybe you should be more aware of the history of a thread before coming with this kind of statements. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-29 Thread Antoon Pardon
= 0 Did I get that right? -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: Negative subscripts

2021-11-26 Thread Antoon Pardon
ou may consider writing a reverse_view function, that takes a list as argument and produces something that behaves as the reversed list without actually reversing the list and then as in the first option use the [y:] slice on that. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: A problem with itertools.groupby

2021-12-17 Thread Antoon Pardon
nd the original iterator with an extra termination condition. So in order to start the next group-iterator the previous group-iterator is exhausted, because the original iterator has to be ready to produce values for the next group-iterator. -- Antoon Pardon. -- https://mail.python.org/mailman/

Re: Why operations between dict views return a set and not a frozenset?

2022-01-05 Thread Antoon Pardon
() - a.keys() {3} Why not frozenset({3})? My 2 cents worths: Because dictviews mutate with the directory. That makes them more like set than like frozenset. So operations on them produce a set. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: Why There Is No Python Compressed Archive or Binaries ?

2022-01-17 Thread Antoon Pardon
You could try miniconda. Op 17/01/2022 om 20:53 schreef Sina Mobasheri: Consider scenario that I want run python 3.10 in CentOS 8, I think last python version in CentOS repository is 3.6, if I use epel I can get 3.8 so ..., I think (correct me if I'm wrong 🙏🏻) the only way that I can run pytho

Re: Best way to check if there is internet?

2022-02-22 Thread Antoon Pardon
Op 22/02/2022 om 09:40 schreef Chris Angelico: On Tue, 22 Feb 2022 at 19:33, Abdur-Rahmaan Janhangeer wrote: As discussed here but, it would have been nevertheless great to have this tiny function instead of nothing Here's a function that determines whether or not you have an internet conn

Re: All permutations from 2 lists

2022-03-02 Thread Antoon Pardon
work? The result seems to be an empty list, which IMO is a perfectly valid result. All possible permutations over two collections where one collection is empty, should IMO give you an empty collection. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: All permutations from 2 lists

2022-03-02 Thread Antoon Pardon
Op 2/03/2022 om 14:44 schreef Larry Martell: On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon wrote: Op 2/03/2022 om 14:27 schreef Larry Martell: On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com> wrote: On 2022-03-01 at 19:12:10 -0500, Larry Martell wrote: If I

Re: All permutations from 2 lists

2022-03-02 Thread Antoon Pardon
Op 2/03/2022 om 15:29 schreef Larry Martell: On Wed, Mar 2, 2022 at 9:10 AM Antoon Pardon wrote: Op 2/03/2022 om 14:44 schreef Larry Martell: On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon wrote: Op 2/03/2022 om 14:27 schreef Larry Martell: On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwz

Re: All permutations from 2 lists

2022-03-02 Thread Antoon Pardon
Op 2/03/2022 om 15:58 schreef Larry Martell: On Wed, Mar 2, 2022 at 9:37 AM Antoon Pardon wrote: If one list is empty I want just the other list. What I am doing is building a list to pass to a mongodb query. If region is empty then I want to query for just the items in the os list. I

Re: Behavior of the for-else construct

2022-03-07 Thread Antoon Pardon
Op 4/03/2022 om 02:08 schreef Avi Gross via Python-list: If Python was being designed TODAY, I wonder if a larger set of key words would be marked as RESERVED for future expansion including ORELSE and even NEVERTHELESS. I think a better solution would be to have reserved words written lette

Re: Reducing "yield from" overhead in recursive generators

2022-03-18 Thread Antoon Pardon
ated functions. Maybe if you contact them they can be interested in making a similar decorating macro for use with such recursive decorators. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Comparing sequences with range objects

2022-04-07 Thread Antoon Pardon
. So what would be a relatively easy way to get the same result without wasting too much memory on entries that haven't any weeding done on them. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: Comparing sequences with range objects

2022-04-07 Thread Antoon Pardon
Op 7/04/2022 om 16:08 schreef Joel Goldstick: On Thu, Apr 7, 2022 at 7:19 AM Antoon Pardon wrote: I am working with a list of data from which I have to weed out duplicates. At the moment I keep for each entry a container with the other entries that are still possible duplicates. The problem

Re: Comparing sequences with range objects

2022-04-08 Thread Antoon Pardon
Op 8/04/2022 om 08:24 schreef Peter J. Holzer: On 2022-04-07 17:16:41 +0200, Antoon Pardon wrote: Op 7/04/2022 om 16:08 schreef Joel Goldstick: On Thu, Apr 7, 2022 at 7:19 AM Antoon Pardon wrote: I am working with a list of data from which I have to weed out duplicates. At the moment I

Re: Comparing sequences with range objects

2022-04-08 Thread Antoon Pardon
Op 8/04/2022 om 16:28 schreef duncan smith: On 08/04/2022 08:21, Antoon Pardon wrote: Yes I know all that. That is why I keep a bucket of possible duplicates per "identifying" field that is examined and use some heuristics at the end of all the comparing instead of starting to we

Re: Comparing sequences with range objects

2022-04-10 Thread Antoon Pardon
Op 9/04/2022 om 02:01 schreef duncan smith: On 08/04/2022 22:08, Antoon Pardon wrote: Well my first thought is that a bitset makes it less obvious to calulate the size of the set or to iterate over its elements. But it is an idea worth exploring. def popcount(n):     """

Re: Comparing sequences with range objects

2022-04-11 Thread Antoon Pardon
Op 11/04/2022 om 02:01 schreef duncan smith: On 10/04/2022 21:20, Antoon Pardon wrote: Op 9/04/2022 om 02:01 schreef duncan smith: On 08/04/2022 22:08, Antoon Pardon wrote: Well my first thought is that a bitset makes it less obvious to calulate the size of the set or to iterate over

Re: Comparing sequences with range objects

2022-04-11 Thread Antoon Pardon
Op 11/04/2022 om 02:31 schreef Dan Stromberg: It sounds a little like you're looking for interval arithmetic. Maybe https://pypi.org/project/python-intervals/1.5.3/ ? Not completely but it suggested an idea to explore. -- Antoon. -- https://mail.python.org/mailman/listinfo/python-list

Would like some thoughts on a grouped iterator.

2016-09-05 Thread Antoon Pardon
I need an interator that takes an already existing iterator and divides it into subiterators of items belonging together. For instance take the following class, wich would check whether the argument is greater or equal to the previous argument. class upchecker: def __init__(self): sel

Re: How to extend a tuple of tuples?

2016-09-13 Thread Antoon Pardon
Op 12-09-16 om 23:29 schreef Chris Angelico: > On Tue, Sep 13, 2016 at 7:19 AM, BartC wrote: >> By the same argument, then strings and ints are also mutable. >> >> Here, the original tuple that a refers to has been /replaced/ by a new one. >> The original is unchanged. (Unless, by some optimisatio

Re: How to extend a tuple of tuples?

2016-09-13 Thread Antoon Pardon
Op 13-09-16 om 11:27 schreef Chris Angelico: > On Tue, Sep 13, 2016 at 5:25 PM, Antoon Pardon > wrote: >> Op 12-09-16 om 23:29 schreef Chris Angelico: >>> On Tue, Sep 13, 2016 at 7:19 AM, BartC wrote: >>>> By the same argument, then strings and ints are also muta

Re: it looks strange

2016-09-27 Thread Antoon Pardon
Op 27-09-16 om 10:09 schreef cpx...@gmail.com: li=[lambda :x for x in range(10)] res=li[0]() print res > 9 > > why? Because there is no nested scope for the x variable.So your list looks like this: [lambda :x, lambda :x, lambda :x, lambda :x, lambda :x, lambda :x, lambda :x, lambda

Re: unintuitive for-loop behavior

2016-10-03 Thread Antoon Pardon
Op 02-10-16 om 07:59 schreef Rustom Mody: > > You are explaining the mechanism behind the bug. Thanks. The bug remains. > My new car goes in reverse when I put it in first gear but only on full-moon > nights with the tank on reserve when the left light is blinking > The engineer explains the inter

Re: How to use two threads (GUI and backend)

2016-10-26 Thread Antoon Pardon
Op 26-10-16 om 12:22 schreef pozz: > Il 26/10/2016 09:13, pozz ha scritto: > > [...] >> When the user press Start button (the pressed handler is in the GUI >> class): >> >> self.comm_active = True >> threading.Thread(target=self.comm_thread).start() >> >> The backend thread is: >> >> def comm

if iter(iterator) is iterator

2016-11-13 Thread Antoon Pardon
Some time ago I read a text or saw a video on iterators and one thing I remember from it, is that you should do something like the following when working with iterators, to avoid some pitt falls. def bar(iterator): if iter(iterator) is iterator: ... However I can't relocate it and ca

Re: Access to the caller's globals, not your own

2016-11-16 Thread Antoon Pardon
(arg) > > What a drag. What about how the random module solves this? The random module provides a factory class: Random. It also provides functions which are methods of a hidden instantiation. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-07 Thread Antoon Pardon
Op 07-12-16 om 19:02 schreef BartC: > On 07/12/2016 16:53, Michael Torrie wrote: >> On 12/07/2016 08:48 AM, BartC wrote: >>> I would prefer that the program "t" can be invoked exactly the same way >>> under both systems. I don't want different instructions for Linux, or >>> for the user (of my lang

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Antoon Pardon
up? Here you are no longer just talking about nested functions, you are talking about closures. A stack is no longer sufficient for implementing closures. The environment for the nested variables of the closure is often alloceted on the heap. -- Antoon Pardon. -- https://mail.python.org/mailma

Re: Cleaning up conditionals

2017-01-02 Thread Antoon Pardon
. So we are just eliminating the replacement of an empty field with an empty field. There is no harm in that and trying to eliminate it just makes your test unnecessarily complex. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Receiving a lot of double messages.

2017-01-06 Thread Antoon Pardon
Is there something going on with the mailinglist? Because I have receive a lot of double messages. One copy is fairly normal and is part of the discussion thread, the other is completely seperated. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Receiving a lot of double messages.

2017-01-06 Thread Antoon Pardon
Is there something going on with the mailinglist? Because I have receive a lot of double messages. One copy is fairly normal and is part of the discussion thread, the other is completely seperated. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Antoon Pardon
Op 09-01-17 om 07:58 schreef Deborah Swanson: > Peter Otten wrote, on January 08, 2017 5:21 AM >> Deborah Swanson wrote: >> >>> Peter Otten wrote, on January 08, 2017 3:01 AM >> >> Personally I would recommend against mixing data (an actual location) > and >> metadata (the column name,"Location"

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Antoon Pardon
ut the different ones for > deletion, and then resume processing the records after the last one? If I understand correctly you want something like: records.sort(key = lamda rec: rec.xx) AKA from operator import attrgetter records.sort(key = attrgetter('xx')) or maybe: records.sort(key = lambda rec: (rec.xx,) + tuple(rec)) -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: Temporary variables in list comprehensions

2017-01-09 Thread Antoon Pardon
Op 09-01-17 om 04:53 schreef Steven D'Aprano: > Suppose you have an expensive calculation that gets used two or more times in > a > loop. The obvious way to avoid calculating it twice in an ordinary loop is > with > a temporary variable: > > result = [] > for x in data: > tmp = expensive_ca

Re: Using namedtuples field names for column indices in a list of lists

2017-01-12 Thread Antoon Pardon
at sense is wrong. All the participants can do is take a clue from the question and then guess what respons would help this person best. Nobody can expect that this list will treat their questions in a way that suits their personal style. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: Emulating Final classes in Python

2017-01-17 Thread Antoon Pardon
will monkey-patch it. Something like: class MyLock: def __init__(self): self.lock = Lock() def __getattr__(self, attr): return getattr(self.lock, attr) So I wonder what reasons do you have prefering that your users monkey-patch your class instead of subclassing it? -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: How to create a socket.socket() object from a socket fd?

2017-01-23 Thread Antoon Pardon
> When you create a Python file object from a file descriptor using > os.fdopen(), does it dup the descriptor? No. Would a reasonable > person expect socket.fromfd() to duplicate the descriptor? No. > > Should it? > > No. The standard response to issues like this is: A f

socket: Did I find a bug?

2018-03-08 Thread Antoon Pardon
This is on a debian 9 box python 2.7.13 My interpretation is that a timeout exception is thrown and that the args attribute of such an exception is an empty tuple which then causes an IndexError in line 482 of module /usr/lib/python2.7/socket.py. Does that soundplausible? Here is the traceback:

Re: Enumerating all 3-tuples

2018-03-13 Thread Antoon Pardon
On 10-03-18 02:13, Steven D'Aprano wrote: > I am trying to enumerate all the three-tuples (x, y, z) where each of x, > y, z can range from 1 to ∞ (infinity). > > This is clearly unhelpful: > > for x in itertools.count(1): > for y in itertools.count(1): > for z in itertools.count(1): >

Re: Entering a very large number

2018-03-23 Thread Antoon Pardon
On 23-03-18 14:01, ast wrote: > Le 23/03/2018 à 13:43, Rustom Mody a écrit : >> On Friday, March 23, 2018 at 5:46:56 PM UTC+5:30, ast wrote: >>> Hi >>> >>> I found this way to put a large number in >>> a variable. >> >> What stops you from entering the number on one single (v long) line? > > > It i

Re: Entering a very large number

2018-03-23 Thread Antoon Pardon
On 23-03-18 14:35, ast wrote: > Le 23/03/2018 à 14:16, Antoon Pardon a écrit : >> On 23-03-18 14:01, ast wrote: >>> Le 23/03/2018 à 13:43, Rustom Mody a écrit : >>>> On Friday, March 23, 2018 at 5:46:56 PM UTC+5:30, ast wrote: > > >> What meaningful infor

Re: Accessing parent objects

2018-03-26 Thread Antoon Pardon
On 25-03-18 00:54, Steven D'Aprano wrote: > > There's nothing wrong with super() in Python 2. You just have to > understand what you're doing. It's still the right solution for doing > inheritance the right way. > > ... > > The trick is to use new-style classes that inherit from object, and avo

Re: Accessing parent objects

2018-03-26 Thread Antoon Pardon
On 25-03-18 06:29, Steven D'Aprano wrote: > Python 3 is now six point releases in (and very soon to have a seventh, > 3.7 being in beta as we speak). It is stable, feature-rich, and a joy to > work in. As well as a heap of great new features, there have been a > metric tonne of performance improv

Re: Accessing parent objects

2018-03-26 Thread Antoon Pardon
On 26-03-18 10:52, Ben Finney wrote: > Antoon Pardon writes: > >> 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

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

2018-03-27 Thread Antoon Pardon
On 27-03-18 08:21, 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. > > I don't buy it. In order for it to work, the following > two c

Re: Regex Doubts

2018-03-30 Thread Antoon Pardon
On 30-03-18 08:16, Iranna Mathapati wrote: > Hi Team, > > > how to achieve fallowing expected output? > > str_output= """ > > MOD1 memory : 2 valid1790 free > MOD2 memory : 128 valid 128 free > UDP Aware *MEMR*

Re: itemgetter with default arguments

2018-05-04 Thread Antoon Pardon
On 04-05-18 15:01, Steven D'Aprano wrote: > 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("He

Re: itemgetter with default arguments

2018-05-07 Thread Antoon Pardon
On 05-05-18 09:33, Peter Otten wrote: > I think you have established that there is no straight-forward way to write > this as a lambda. But is adding a default to itemgetter the right > conclusion? > > If there were an exception-catching decorator you could write > > f = catch(IndexError, "spam")

Re: itemgetter with default arguments

2018-05-08 Thread Antoon Pardon
On 07-05-18 17:45, Peter Otten wrote: > Antoon Pardon wrote: > >> On 05-05-18 09:33, Peter Otten wrote: >>> I think you have established that there is no straight-forward way to >>> write this as a lambda. But is adding a default to itemgetter the right >>&g

Re: what does := means simply?

2018-05-17 Thread Antoon Pardon
MO it would be nicer if it could be written as: while a := prepare_a(); b := prepare_b(); condition(a, b): Do other stuff -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list

Re: Why exception from os.path.exists()?

2018-06-07 Thread Antoon Pardon
On 07-06-18 05:55, Steven D'Aprano wrote: > Python strings are rich objects which support the Unicode code point \0 > in them. The limitation of the Linux kernel that it relies on NULL- > terminated byte strings is irrelevant to the question of what > os.path.exists ought to do when given a path

Re: Why exception from os.path.exists()?

2018-06-07 Thread Antoon Pardon
On 07-06-18 11:29, Marko Rauhamaa wrote: > Antoon Pardon : > >> On 07-06-18 05:55, Steven D'Aprano wrote: >>> As a Python programmer, how does treating NUL specially make our life >>> better? >> By treating possible path values differently from impossible

Re: Why exception from os.path.exists()?

2018-06-07 Thread Antoon Pardon
On 07-06-18 14:47, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 10:04:53 +0200, Antoon Pardon wrote: > >> On 07-06-18 05:55, Steven D'Aprano wrote: >>> Python strings are rich objects which support the Unicode code point \0 >>> in them. The limitation of

Re: Why exception from os.path.exists()?

2018-06-08 Thread Antoon Pardon
cessible to the user. Maybe some FS that is hooked up to my linux box does allow embedded NUL bytes. I won't be able to notice that because even if there are such files, they will need some remapping in order to make them accessible. To the user the actuale filenames are the remappe

Re: Why exception from os.path.exists()?

2018-06-08 Thread Antoon Pardon
On 08-06-18 04:19, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 17:45:06 +1000, Chris Angelico wrote: > >> So... an ASCIIZ string *can* contain that character, or >> at least a representation of it. Yet it cannot contain "\0". > You keep saying that as if it made one whit of difference to what > o

Re: Why exception from os.path.exists()?

2018-06-08 Thread Antoon Pardon
that mean the behaviour should be fixed or that the behaviour should be better documented? Either could be an answer and in trying to find the answer I don't think the actual FS is relevant because the doesn't access the FS directly but through the OS api. -- Antoon Pardon. -- https://

Re: Why exception from os.path.exists()?

2018-06-08 Thread Antoon Pardon
On 08-06-18 13:35, Steven D'Aprano wrote: > On Fri, 08 Jun 2018 09:27:17 +0200, Antoon Pardon wrote: > >> On 08-06-18 04:19, Steven D'Aprano wrote: >>> On Thu, 07 Jun 2018 17:45:06 +1000, Chris Angelico wrote: >>> >>>> So... an ASCII

Re: Why exception from os.path.exists()?

2018-06-11 Thread Antoon Pardon
still return False. > There is no requirement that different functions do the same thing with > the same bad input. The *whole point* of o.p.exists is to return False, > not raise an exception. And the price is that it will not always give the correct answer. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list

Re: Why exception from os.path.exists()?

2018-06-11 Thread Antoon Pardon
On 11-06-18 10:35, Marko Rauhamaa wrote: > Antoon Pardon : >> On 11-06-18 02:28, Steven D'Aprano wrote: >>> The *whole point* of o.p.exists is to return False, not raise an >>> exception. >> And the price is that it will not always give the correct answer. &g

Re: Why exception from os.path.exists()?

2018-06-11 Thread Antoon Pardon
On 11-06-18 13:59, Steven D'Aprano wrote: > On Mon, 11 Jun 2018 09:55:06 +0200, Antoon Pardon wrote: > >> On 11-06-18 02:28, Steven D'Aprano wrote: > [...] >>> open(foo) raises an exception if foo doesn't exist; >>> >>> os.path.exist

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