Chris Angelico wrote:
> On Sat, Jul 15, 2017 at 11:05 PM, Peter Otten <[email protected]> wrote:
>> Matt Wheeler wrote:
>>
>>>> as the title says. has @ been used in projects?
>>
>> numpy, probably?
>>
>>> Strictly speaking, @ is not an operator.
>>
>> In other words it's not popular, not even widely known.
>>
>> Compare:
>>
>> $ python3.4 -c '[email protected]'
>> File "<string>", line 1
>> [email protected]
>> ^
>> SyntaxError: invalid syntax
>> $ python3.5 -c '[email protected]'
>> Traceback (most recent call last):
>> File "<string>", line 1, in <module>
>> NameError: name '__peter__' is not defined
>>
>> Starting with 3.5 my email address is valid Python syntax. Now I'm
>> waiting for the __peter__ builtin ;)
>
> And you'll have to 'import web' too.
>
> I've no idea what 'web.de' would be and what happens when you matmul it by
> you.
>
> ChrisA
This is getting more complex than expected. Here's a prototype:
import builtins
def __peter__():
class Provider:
def __init__(self, name):
self.name = name
def __getattr__(self, name):
return Provider(f"{self.name}.{name}")
def __rmatmul__(self, user):
assert user.email.endswith("@" + self.name)
return user
class User:
def __init__(self, email):
self.email = email
user, at, site = email.partition("@")
name = site.partition(".")[0]
setattr(builtins, name, Provider(name))
def __repr__(self):
return self.email
return User("[email protected]")
builtins.__peter__ = __peter__()
del __peter__
$ python3.7 -i web.py
>>> [email protected]
[email protected]
I'm sure you won't question the feature's usefulness after this. Future
versions may send me an email or wipe your hard disk at my discretion...
--
https://mail.python.org/mailman/listinfo/python-list