Proposal: SimpleNamespace "recursive" parameter
It would be nice if you could do this to create a "nested" SimpleNamespace:
>>> d = {"_meta": {"fields": ({"name": "field0"}, {"name": "field1"})}}
>>> sns = SimpleNamespace(**d)
>>> print(sns._meta.fields[0].name) # This is what I wish you could do
'field0'
SimpleNamespace does this though:
>>> d = {"_meta": {"fields": ({"name": "field0"}, {"name": "field1"})}}
>>> sns = SimpleNamespace(**d)
>>> print(sns._meta) # Python 3.8
{"fields": ({"name": "field0"}, {"name": "field1"})}
I'd love to add a "recursive" parameter to SimpleNamespace to do as above i.e.,
>>> d = {"_meta": {"fields": ({"name": "field0"}, {"name": "field1"})}}
>>> sns = SimpleNamespace(recursive=True, **d)
>>> print(sns._meta.fields[0].name) # Proposal
'field0'
My current use case is to mock out a Django model in a more straightforward
fashion than using unittest.mock.Mock.
Does anyone else here think this is a good idea?
Refs:
https://gist.github.com/pandichef/d3cc137036a7be0c29e9afb27bfbf55e
https://stackoverflow.com/questions/38034377/object-like-attribute-access-for-nested-dictionary/63389458#63389458
https://greenash.net.au/thoughts/2017/08/using-pythons-namedtuple-for-mock-objects-in-tests/
--
https://mail.python.org/mailman/listinfo/python-list
EuroPython 2020: Live Stream Recordings available
We’re happy to announce the public availability of the live stream recordings from EuroPython 2020. They were already available to all conference attendees since the sprint days. * EuroPython YouTube Channel * http://europython.tv/ We have collected the videos in a EuroPython 2020 Live Stream playlist: https://www.youtube.com/playlist?list=PL8uoeex94UhG33fVP7GZEo06gOHlhb0hk Unedited Videos --- What we are releasing today are unedited videos recorded for the main track rooms and days. The poster track recordings will be added today or tomorrow. You can use the schedule to navigate the videos. Linking to a specific time in the videos can be done by right-clicking in the video to create a URL which points to the current position. Feel free to share interesting links on social media. Edited Videos - Our video editing company is already busy creating the cut videos. Those should be ready in a month or two. Help spread the word Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/626322517228961792/europython-2020-live-stream-recordings-available Tweet: https://twitter.com/europython/status/1293828734143864833 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track)
On 22.07.2020 15:00, Christian Heimes wrote: > Hi MAL, > > would it be possible to reduce the amount of EuroPython spam on > @python.org mailing lists to a sensible level? This mailing list is a > general discussion list for the Python programming language. It's not a > conference advertisement list. > > Something between 1 to 3 mails per conference and year (!) sounds > sensible to me. You have posted 21 new threads about EP 2020 since > January on this list, thereof 5 threads this month. In comparison I > could only find two ads for other conferences in the last 12 month > (FlaskCon, PyCon TZ). Hi Christian, as you probably know, EuroPython is a community effort, run entirely by volunteers with no commercial interests. Since c.l.p, as well as other general purpose Python community lists, are places where we can reach out to the community we're working for, it's a natural target for our conference communication. We are perfectly aware that our emails are not necessarily interesting for everyone, but then you have the same problem with many topics on these general purpose mailing lists. The standard way to approach this is to simply ignore the postings, filter them out or silence them. It's obvious from your emails and tweets that you don't like our emails and that's fair. Everyone is entitled to their own opinion. However, we are running the conference for a large community and so have to compromise between people such as you who don't like getting our emails and the thousands of people who do. When you run community events, you have to learn that you can never make everyone happy - even though we try hard and I believe we have a good track record of at least making most people happy :-) Regarding filtering, almost all of our emails carry "EuroPython" in their subject line and we usually use a europython.eu email address as sender. In fact, most emails are sent by me, since I the one in charge of preparing and sending them, so you can easily filter them out. In terms of volume, I don't regard the 24 messages I have sent this year anywhere near a level which can be considered spam based on volume, given that the list has received 3300+ messages this year. Again, you may have a different opinion and that's perfectly fine. We can agree to disagree on this. FWIW: I would like to see a lot more conference communication from the many Python events around the world go to this and other lists. People new to Python generally have a hard time finding out what's going on in Python land - one of the reasons I started the Python events calendar project, for example: https://www.python.org/events/ https://wiki.python.org/moin/PythonEventsCalendar The Python conferences and meetups are a central part of the Python community and should get more awareness rather than less. Thanks, -- Marc-Andre Lemburg EuroPython Society Chair http://www.europython-society.org/ http://www.malemburg.com/ -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] Universal set
assert(The set that contains everything is God) Compile with -OO On Mon, 10 Aug 2020 at 13:23, haael wrote: > > > Forgive me if this has already been discussed. > > > Could we add the idea of "negative" sets to Python? That means sets that > contain EVERYTHING EXCEPT certain elements. > > > First, let's have a universal set that contains everything. > > assert element in set.UNIVERSAL > > The universal set is a superset of every other set. > > assert set.UNIVERSAL >= any_set > > Adding anything to universal set doesn't change anything. > > assert set.UNIVERSAL | element == set.UNIVERSAL > > However REMOVING an element from the set puts it on "negative list". > > myset = set.UNIVERSAL > myset.remove(element) > assert element not in myset > > Intersection of a "negative set" with a normal set gives again a normal > set. Union of two negative sets, or a negative set with a normal set, > gives a negative set. > > The main issue: negative sets would not be iterable, but you can > intersect them with the desired subdomain and iterate over. > ___ > Python-ideas mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/[email protected]/message/MY77JS226XWLV7FGTS4KRSWPI45VB64I/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- https://mail.python.org/mailman/listinfo/python-list
RE: Support
Helo, I am already subscribed. I De: Alexa Oña Enviado: jueves, 13 de agosto de 2020 18:51 Para: [email protected] Asunto: Support Hello, I am Alexa I have tried to install PYTHON 3.8.5, but could not install it on my computer. I would like to receive help since always when installing and opening, it indicates the same page. Thank you. [cid:3ec428e5-972d-4111-852c-acb78f40d91d][cid:d848c116-7d18-47e8-9b58-3ff3530038e2][cid:2317bb77-b7d9-4a20-8aaa-20d3aed62d7b] -- https://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2020: Live Stream Recordings available
On 8/13/2020 9:44 AM, M.-A. Lemburg wrote: We’re happy to announce the public availability of the live stream recordings from EuroPython 2020. They were already available to all conference attendees since the sprint days. * EuroPython YouTube Channel * http://europython.tv/ This http url, blocked by HTTPS Anywhere, just forwards to https://www.youtube.com/c/EuroPythonConference We have collected the videos in a EuroPython 2020 Live Stream playlist: https://www.youtube.com/playlist?list=PL8uoeex94UhG33fVP7GZEo06gOHlhb0hk A better (more useful) version of the listing. Unedited Videos --- What we are releasing today are unedited videos recorded for the main track rooms and days. IE, each is a 2-12 hour recording with multiple sessions. So subtract session start time from talk time to get approximate time index, taking into account that cumulative overtimes increase actual start times. The poster track recordings will be added today or tomorrow. You can use the schedule to navigate the videos. https://ep2020.europython.eu/schedule/ I look forward to the edited videos sliced into individual talks. But I already found and watched a talk that interested me. Thank you for making them available. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Support
On 14/08/2020 08:31, Alexa Oña wrote: Helo, I am already subscribed. I De: Alexa Oña Enviado: jueves, 13 de agosto de 2020 18:51 Para: [email protected] Asunto: Support Hello, I am Alexa I have tried to install PYTHON 3.8.5, but could not install it on my computer. I would like to receive help since always when installing and opening, it indicates the same page. Holá, Yes, your message has been received. Please advise which operating system is used on your computer, and the download source you have been using. -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Support
Hi, On Thu, Aug 13, 2020 at 5:46 PM dn via Python-list wrote: > > On 14/08/2020 08:31, Alexa Oña wrote: > > Helo, I am already subscribed. > > > > I > > De: Alexa Oña > > Enviado: jueves, 13 de agosto de 2020 18:51 > > Para: [email protected] > > Asunto: Support > > > > Hello, I am Alexa > > I have tried to install PYTHON 3.8.5, but could not install it on my > > computer. I would like to receive help since always when installing and > > opening, it indicates the same page. Also, please include the exact error message you are receiving during the install. Thank you. > > > Holá, > > Yes, your message has been received. > > Please advise which operating system is used on your computer, and the > download source you have been using. > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Whitespace not/required
Although many new-comers are intrigued by the compulsory indentation rule, I have been surprised to discover that even though whitespace does not usually feature as a formatting-specification, nevertheless Python sometimes requires an absence of whitespace. Will this behavior/requirement continue when using (a pre-release version featuring) the new parser? Whitespace has meaning to us - when it comes to indentation defining (not merely illustrating) blocks of code. However, the rest of the time, it is ignored by Python. (yes, this discussion disdains comments!) For example, whitespace is no problem when it comes to defining a list: month_names = ['Januari', 'Februari', 'Maart', # These are the 'April', 'Mei', 'Juni', # Dutch names... Similarly, a totally blank line will be equally-totally ignored. As my eye-sight ages (it's older than my teeth!), I find code easier to read when there is more whitespace - and it becomes more difficult to parse when whitespace is omitted. For example, I receive regular comments/criticisms for writing an argument list with spaces inside the parentheses, eg def func( arg1, arg2, ): Whilst there are some 'standards' which decry such practice, I note that many IDEs will offer to add such spaces, auto-magically, as a config/option. So, apparently I'm not unique - just 'special'? I don't use 'back-slash continuity' very often (at the expense of more parens!), and was intrigued to discover in experiments; that not only is a space before the back-slash considered optional, but sometimes a space is not necessary at all, eg >>> if\ ... True: print( 'yes' ) ... yes >>> ifTrue: print( 'yes' ) yes although Python won't let me go-crazy: >>> if True andFalse: print( 'yes' ) File "", line 1 if True andFalse: print( 'yes' ) ^ SyntaxError: invalid syntax >>> if Tr\ ... ue: print( 'yes' ) File "", line 2 if Tr\ ue: print( 'yes' ) ^ SyntaxError: invalid syntax The legal statement: <<<2.1.9. Whitespace between tokens Except at the beginning of a logical line or in string literals, the whitespace characters space, tab and formfeed can be used interchangeably to separate tokens. Whitespace is needed between two tokens only if their concatenation could otherwise be interpreted as a different token (e.g., ab is one token, but a b is two tokens).>>> Thus, (a little later on the same page): <>> Thus, it must be expressed as "b'bytes'" and not "b 'bytes'". Admittedly, such separation hadn't occurred to me, in much the same way that "print ()" doesn't seem correct, but... When we break the language-elements into "tokens" the 'bytes' and the argument-list's parentheses are separate from the preceding "b" or function-name, albeit semantically inseparable. For f-strings/formatted string literals, the most usual form is: "{" f_expression ["="] ["!" conversion] [":" format_spec] "}" Remembering that this is BNF, see the space separating the closing-brace from anything preceding it - how else would we separate the components to comprehend? Returning to Python: >>> one = 1# is the loneliest number... >>> f'{ one }' '1' >>> f'{ one:03 }' Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code '\x20' for object of type 'int' >>> f'{ one:03}' '001' Notice the presence/absence of the final space. >>> pi = 3.14159 # better to import math >>> f'{ pi!r:10 }' Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code '\x20' for object of type 'str' >>> f'{ pi!r:10}' '3.14159 ' >>> f'{ pi!r }' File "", line 1 SyntaxError: f-string: expecting '}' >>> f'{ pi!r}' '3.14159' So, the f-string will work if the braces include only an expression surrounded by spaces. However, if one adds a conversion or format-specification, that final space becomes a no-no. Eh what! To be fair, the 'book of words' does say: "A replacement field ends with a closing curly bracket '}'.". No mention of whitespace. No mention that a replacement field consisting only of an f_expression, will be treated differently by allowing a space. Version 3.8 introduced the "=" short-cut: >>> f"{ foo = }" # preserves whitespace " foo = 'bar'" Note the comment! Yet, the manual's examples continue: >>> line = "The mill's closed" >>> f"{line = }" 'line = "The mill\'s closed"' >>> f"{line = :20}" "line = The mill's closed " Hey, why does this second example dispense with the braces-internal spaces? Sure enough, when I check it for myself: >>> line = "The mill's closed" >>> f'{line = :20 }' Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code '\x20' for object of type 'str' >>> f'{ line = :20}' " line = The mill's closed " >>> f'{line = :20}' "line = The mill's closed "
Re: Proposal: SimpleNamespace "recursive" parameter
This seems to work: from types import SimpleNamespace from collections.abc import Iterable def isIterableNotStr(arg): return isinstance(arg, Iterable) and not isinstance(arg, str) class DeepNamespace(SimpleNamespace): def namespacesFromIterable(self, arg): vals = [] changed = False for x in arg: not_iterable = True try: x.items value = type(self)(**x) changed = True not_iterable = False except AttributeError: if isIterableNotStr(x): value = self.namespacesFromIterable(x) changed = True not_iterable = False if not_iterable: value = x vals.append(value) if changed: return tuple(vals) return arg def __init__(self, **kwargs): super().__init__(**kwargs) for k, v in kwargs.items(): try: v.items except AttributeError: if isIterableNotStr(v): self.__setattr__(k, self.namespacesFromIterable(v)) else: self.__setattr__(k, type(self)(**v)) Notice that if the dict contains at any level an iterable that is not a string or a dict-like object, this is converted to a tuple. Probably there's a smarter way to maintain the original iterable type. -- https://mail.python.org/mailman/listinfo/python-list
