Python equivalent #define

I am developing a Hebrew python library for my kid who does not yet speak English. So far, I managed to get it to work (function names and variables work fine). The problem is with the if, while, for statements, etc. if it was C ++, for example, I would use

#define if אם 

Are there any alternatives to #define in Python?

**** EDIT ***** So far, a quick and dirty solution has been working for me; instead of running the program, I run this code:

 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) 
+6
source share
2 answers

Python 3 has 33 keywords, of which only a few are used by beginners:

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

Given that Python does not support keyword renaming, it may be easier to teach several of these keywords along with instructional programming.

+6
source

How about if you add #define stuff, then run the c preprocessor (but not the compiler), which will give you the python source.

+1
source

Source: https://habr.com/ru/post/981518/


All Articles