繁体   English   中英

Python #define等效

[英]Python #define equivalent

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

#define if אם

在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)

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']

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

如果你添加#define的东西然后运行c预处理器(但不是编译器),它会给你一个python源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM