Python compile() လုပ်ဆောင်ချက်
ဥပမာ
စာသားကို ကုဒ်အဖြစ် စုစည်းပြီး ၎င်းကို လုပ်ဆောင်ပါ-
x = compile('print(55)', 'test', 'eval')
exec(x)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
compile()
လုပ်ဆောင်ချက်သည် သတ်မှတ်ထားသော အရင်းအမြစ်ကို ကုဒ်အရာဝတ္တုအဖြစ် ပြန်ပေးသည်၊ လုပ်ဆောင်ရန် အသင့်ဖြစ်နေပါပြီ ။
အထားအသို
compile(source,
filename, mode, flag, dont_inherit,
optimize)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
source | Required. The source to compile, can be a String, a Bytes object, or an AST object |
filename | Required. The name of the file that the source comes from. If the source does not come from a file, you can write whatever you like |
mode | Required. Legal values: eval - if the source is a single expression exec - if the source is a block of statements single - if the source is a single interactive statement |
flags | Optional. How to compile the source. Default 0 |
dont-inherit | Optional. How to compile the source. Default False |
optimize | Optional. Defines the optimization level of the compiler. Default -1 |
နောက်ထပ် ဥပမာများ
ဥပမာ
ကြေညာချက်တစ်ခုထက်ပို၍ စုစည်းပြီး ၎င်းကို လုပ်ဆောင်ပါ-
x = compile('print(55)\nprint(88)', 'test', 'exec')
exec(x)