我正在为我的孩子开发一个希伯来蟒蛇图书馆,他还不会说英语.到目前为止,我已设法使其工作(函数名称和变量工作正常).问题在于"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)