Symbol names in python
syntax - What does the "at" (@) symbol do in Python? - Stack Overflow
Is there a .issymbol() function in Python?
I think I wasted my damn time on W3Schools.
Can Python operators be used with custom objects?
Are all operators in Python evaluated left to right?
Can bitwise operators be used with booleans?
Videos
I'm writing a script that edits a kml, (kmls are written in a very similar format to html) and it opens and reads and writes the enter key as '\n', but I need to know what it reads and writes the tab key as. Also, is there a list of these characters that I can access when I need another one?
An @ symbol at the beginning of a line is used for class and function decorators:
PEP 318: Decorators
Python Decorators - Python Wiki
The most common Python decorators are:
@property@classmethod@staticmethod
An @ in the middle of a line is probably matrix multiplication:
@as a binary operator.
Example
class Pizza(object):
def __init__(self):
self.toppings = []
def __call__(self, topping):
# When using '@instance_of_pizza' before a function definition
# the function gets passed onto 'topping'.
self.toppings.append(topping())
def __repr__(self):
return str(self.toppings)
pizza = Pizza()
@pizza
def cheese():
return 'cheese'
@pizza
def sauce():
return 'sauce'
print pizza
# ['cheese', 'sauce']
This shows that the function/method/class you're defining after a decorator is just basically passed on as an argument to the function/method immediately after the @ sign.
First sighting
The microframework Flask introduces decorators from the very beginning in the following format:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
This in turn translates to:
rule = "/"
view_func = hello
# They go as arguments here in 'flask/app.py'
def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
pass
Realizing this finally allowed me to feel at peace with Flask.
Dumb question but I was wondering if there is a function similar to islower(), isupper(), or even isnumeric() but for symbols (like โ,โ , โ.โ, โ/โ, etc.)?
Thanks!