So I’m trying to get this working, where I remove the week’s stats (weeklydict) from this second’s stats (instantdict) so I have an accurate weekly progress for all keys of instantdict (keys being members). It works fine and dandy, but when a new member joins (adding to the keys in instantdict), shit hits the fan, so I use try/except, and
Tag: python-3.10
New union shorthand giving “unsupported operand type(s) for |: ‘str’ and ‘type'”
Before 3.10, I was using Union to create union parameter annotations: Now, when I use the new union shorthand syntax: I get the error: TypeError: unsupported operand type(s) for |: ‘str’ and ‘type’ Is this not supported? Answer The fact that it’s being used as a type hint doesn’t really matter; fundamentally the expression “Vector” | float is a type
Using the “in” operator in Python 3.10 Match Case
Is there a “in” operator in python 3.10 Match Case like with if else statements if “n” in message: the in operator doesn’t work in match case This doesn’t work. How to have something like the “in” operator in Match-Case. Answer In match-case we can use the split() method on the message string. Example: Here, the string can be split
How to limit a Python module to expose specific parts
I just made a module in python but I don’t want people to do this: and this then shows all methods and variables I added to the module. I just want them to see specified ones because I have many additional ones that are only for internal use. Answer If this is your module mymodule.py: Importing it directly like this:
I want to distinguish between true digit and a string digit
I want to check a ‘x’ string whether it is a digit or not in advance. ‘1’ is naturally a digit. But and I will use ① what is calld a string number very much. I don’t know the range of string numbers IDE judges as a digit. ‘①’.isdigit() returns True. ‘⑴’.isdigit() returns True. ‘ⅰ’ or ‘Ⅰ’ returns False. ‘㈠’
How to access the matched value in the default case of structural pattern matching?
With Python 3.10’s match statement, is it possible to use the value met in the default case? Or does this need to be assigned a variable before match so it can be used in the default case? Answer You can use an as pattern:
How use instead of comma in mapped list
My code– this map function makes this format– [ord(‘1’), ord(‘2’), ord(‘3’), …] from 1 to 9 But want like [ord(‘1’) | ord(‘2’) | …] How can i do that? Answer Try: Note: instead of double map use a comprehension: