A library adding new syntax into your Python. i.e. It is NOT Pythonic :)
- Python >=3.8
Install from PyPI:
$ pip install hdytto
This library cannot be used by import hdytto
as in other libraries, but the usage is simple. At first, make sitecustomize.py
:
from hdytto import register_hdytto
register_hdytto()
Set the environmental variable PYTHONPATH
the path to the directory containing the sitecustomize.py
(e.g. export PYTHONPATH=.
).
Then, run main.py
:
# coding: hdytto
a = 5
print(a++)
print(a)
The output will be
5
6
Additionally, make .pythonrc.py
:
import sys
import sitecustomize
sys.stdin.reconfigure(encoding='hdytto')
Set the environmental variable PYTHONSTARTUP
the path to this .pythonrc.py
(e.g. export PYTHONSTARTUP=.pythonrc.py
).
Then, type python
:
$ python
>>> a = 5
>>> a++
5
>>> do:
... b = ++a
... while b < 10
...
>>> b
10
x++
++x
x--
--x
# coding: hdytto
a = 5
print(a++)
print(++a)
b = 10 - --a
print(b--)
Output:
5
7
4
do:
statement
while condition
# coding: hdytto
do:
a = 5
while a < 3
do:
b = a * 2
while a++ < 10:
pass
while b <= 20
print(b)
Output:
22
/* */
# coding: hdytto
a = /* foo */ 10
print(a)
if a == 10:
b = 5
/*b = 10
print(a - 20)*/
print(b)
Output:
10
5
const name = value
# coding: hdytto
import time
def foo(x, const y):
y = 20
print(x + y)
print('long time process here.')
const a = 30
time.sleep(a) # a process requiring long time
foo(1, 2)
Output:
File "main.py", line 6
y = 20
^
SyntaxError: invalid assignment to const y
SyntaxError: encoding problem: hdytto
This is SyntaxError
, so does not require running the process requiring long time.
hdytto's const
only prohibits =
, +=
, -=
, *=
, /=
, %=
, &=
, |=
, ^=
, <<=
, >>=
, **=
, //=
, @=
, :=
, otherwise is allowed (e.g. const l = []
and l.append(5)
is allowed).