Re: Not found in the documentation
On Thu, Apr 29, 2021 at 4:56 PM elas tica wrote: > > Le mercredi 28 avril 2021 à 17:36:32 UTC+2, Chris Angelico a écrit : > > > In what sense of the word "token" are you asking? The parser? You can > > play around with the low-level tokenizer with the aptly-named > > tokenizer module. > > It was a good suggestion, and the PLR doesn't mention the tokeniser module. > It should, this goes very well with the conversional style it has. > > > > # -- > from tokenize import tokenize > from io import BytesIO > > s="""42 not\ > in [42]""" > g = tokenize(BytesIO(s.encode('utf-8')).readline) > print(*(g), sep='\n') > # -- > > outputting: > > > .. > TokenInfo(type=57 (ENCODING), string='utf-8', start=(0, 0), end=(0, 0), > line='') > TokenInfo(type=2 (NUMBER), string='42', start=(1, 0), end=(1, 2), line='42 > not in [42]') > TokenInfo(type=1 (NAME), string='not', start=(1, 3), end=(1, 6), line='42 not > in [42]') > TokenInfo(type=1 (NAME), string='in', start=(1, 7), end=(1, 9), line='42 not > in [42]') > TokenInfo(type=53 (OP), string='[', start=(1, 10), end=(1, 11), line='42 not > in [42]') > TokenInfo(type=2 (NUMBER), string='42', start=(1, 11), end=(1, 13), line='42 > not in [42]') > TokenInfo(type=53 (OP), string=']', start=(1, 13), end=(1, 14), line='42 not > in [42]') > TokenInfo(type=4 (NEWLINE), string='', start=(1, 14), end=(1, 15), line='') > TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='') > .. > > > So "not in" is not a token and the docs are wrong when they say: > > .. > using a backslash). A backslash is illegal elsewhere on a line outside a > string literal. > .. > Are they really? Need more context here. The backslash escapes the newline, and then you have an additional space character after that, so it still ends the word. What's the bug here? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Not found in the documentation
On Wed, 28 Apr 2021 at 22:18, Dennis Lee Bieber wrote: > The old range() returned a list, and said list could (in your example) > contain 42. The current range() (equivalent to former xrange() ) is not a > container as retrieving values consumes them from the range. A nitpick -- retrieving values from a range doesn't consume them: ``` >>> r = range(10) >>> r range(0, 10) >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> r[0] 0 >>> r[3] 3 >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ``` range objects are iterables, not iterators. We can see the consuming behaviour I think you are referring to by calling iter(): ``` >>> i = iter(r) >>> next(i) 0 >>> list(i) [1, 2, 3, 4, 5, 6, 7, 8, 9] ``` -- Matt Wheeler http://funkyh.at -- https://mail.python.org/mailman/listinfo/python-list
Re: c-types Structure and equality with bytes/bytearray
On 4/26/21, Michael Hull wrote: > > my understanding was that `bytes` and `bytearray` would normally > be expected to work quite interchangeably with each other? bytearray.__eq__() is more flexible: >>> i = Int16(first=65, second=66) >>> bytearray(i).__eq__(i) True >>> i.__eq__(bytearray(i)) NotImplemented >>> i.__eq__(bytes(i)) NotImplemented >>> bytes(i).__eq__(i) NotImplemented When in doubt, read the source code. In bytearray_richcompare() in Objects/bytearrayobject.c, the comparison begins by using the buffer protocol to get comparable byte strings. ctypes data types support the buffer protocol, so this works well. On the other hand, bytes_richcompare() in Objects/bytesobject.c does not use the buffer protocol but instead requires the other object to be a bytes object. In Python 3.3+, you can force the comparison to use the buffer protocol via memoryview(). For example: >>> memoryview(i).cast('B') == bytes(i) True >>> memoryview(i).cast('B') == bytearray(i) True The cast() to "B" (unsigned char) is required because views of ctypes data objects include their format: >>> memoryview(i).format 'T{>> memoryview(i).cast('B').format 'B' -- https://mail.python.org/mailman/listinfo/python-list
uninstall
I’m trying to uninstall Python 3.8.5 on Windows 10 Pro 20H2 as I had multiple environments and as a result corrupted them. When I uninstall from control panel, it takes less than a second and says it uninstalled successfully but I can still access python through the command prompt by typing python. Is there a different way to uninstall that isn’t through the control panel? I would have thought I would do that and then clean out the registry separately and the %localappdata%\pip folder. Any thoughts? Thanks in advance Sian Doherty Sent from Mail for Windows 10 -- https://mail.python.org/mailman/listinfo/python-list
Re: Not found in the documentation
Am 29.04.21 um 08:54 schrieb elas tica: Le mercredi 28 avril 2021 à 17:36:32 UTC+2, Chris Angelico a écrit : In what sense of the word "token" are you asking? The parser? You can play around with the low-level tokenizer with the aptly-named tokenizer module. It was a good suggestion, and the PLR doesn't mention the tokeniser module. It should, this goes very well with the conversional style it has. # -- from tokenize import tokenize from io import BytesIO s="""42 not\ in [42]""" g = tokenize(BytesIO(s.encode('utf-8')).readline) print(*(g), sep='\n') # -- the docs are wrong when they say: .. using a backslash). A backslash is illegal elsewhere on a line outside a string literal. .. You're not passing a backslash. Try print(s). It would be different with a raw string s=r"""42 not\ in [42]""" Christian -- https://mail.python.org/mailman/listinfo/python-list