Python #define等效

mat*_*nso 6 python python-3.x

我正在为我的孩子开发一个希伯来蟒蛇图书馆,他还不会说英语.到目前为止,我已设法使其工作(函数名称和变量工作正常).问题在于"if","while","for"等语句.如果这是C++,例如,我会使用

#define if ??
Run Code Online (Sandbox Code Playgroud)

在Python中有#define的替代品吗?

****编辑*****现在,一个快速而肮脏的解决方案对我有用; 而不是运行程序我运行此代码:

def RunReady(Path):
    source = open(Path, 'rb')
    program = source.read().decode()
    output = open('curr.py', 'wb')

    program = program.replace('??_???', 'while')
    program = program.replace('????', 'for')
    program = program.replace('??', 'if')
    program = program.replace(' ? ', ' in ')
    program = program.replace('????', 'def')
    program = program.replace('????', 'else')
    program = program.replace('??', 'or')
    program = program.replace('???', 'and')
    output.write(program.encode('utf-8'))
    output.close()
    source.close()
    import curr

current_file = 'Sapir_1.py'
RunReady(current_file)
Run Code Online (Sandbox Code Playgroud)

Mar*_*ana 7

如果添加 #define 内容,然后运行 ​​c 预处理器(但不是编译器),这将为您提供 python 源代码,怎么样?


Sim*_*ser 6

Python 3有33个关键字,其中只有少数被初学者使用:

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Run Code Online (Sandbox Code Playgroud)

鉴于Python不支持重命名关键字,可能更容易教授其中一些关键字以及教学编程.