آشنایی با تابع ()compile - مقدمه ای بر JiT - بخش دوم یکی دیگر از ویژگی های هیجان انگیز تابع ()compile ، امکان توزیع برنامه بدون در اختیار گذاشتن سورس کد برنامه در اختیار استفاده کننده نهایی است. در حالت عادی مجبور بودیم که کل سورس برنامه را در اختیار استفاده کننده نهایی قرار دهیم که این موضوع باعث ایجاد نگرانی در دسترسی به کدها را داشت. به کمک تابع ()compile و ماژول marshal به راحتی می توان برنامه های پایتون را کامپایل کرد که علاوه بر سرعت بالاتر اجرای برنامه، امنیت فایل ها هم تا حدودی حفظ شود.
یک مثال
#code by @python4finance
import marshal
source_code = """ a=5 for i in range(a): print(i) if i==3: print("*") """ compiled_code = compile(source_code, '<string>', 'exec')
with open('compiled_code.pyc', 'wb') as file: marshal.dump(compiled_code, file)
برای خواندن فایل کامپایل شده هم به صورت زیر عمل می کنیم:
import marshal
with open('compiled_code.pyc', 'rb') as file: compiled_code = marshal.load(file)
آشنایی با تابع ()compile - مقدمه ای بر JiT - بخش دوم یکی دیگر از ویژگی های هیجان انگیز تابع ()compile ، امکان توزیع برنامه بدون در اختیار گذاشتن سورس کد برنامه در اختیار استفاده کننده نهایی است. در حالت عادی مجبور بودیم که کل سورس برنامه را در اختیار استفاده کننده نهایی قرار دهیم که این موضوع باعث ایجاد نگرانی در دسترسی به کدها را داشت. به کمک تابع ()compile و ماژول marshal به راحتی می توان برنامه های پایتون را کامپایل کرد که علاوه بر سرعت بالاتر اجرای برنامه، امنیت فایل ها هم تا حدودی حفظ شود.
یک مثال
#code by @python4finance
import marshal
source_code = """ a=5 for i in range(a): print(i) if i==3: print("*") """ compiled_code = compile(source_code, '<string>', 'exec')
with open('compiled_code.pyc', 'wb') as file: marshal.dump(compiled_code, file)
برای خواندن فایل کامپایل شده هم به صورت زیر عمل می کنیم:
import marshal
with open('compiled_code.pyc', 'rb') as file: compiled_code = marshal.load(file)
For some time, Mr. Durov and a few dozen staffers had no fixed headquarters, but rather traveled the world, setting up shop in one city after another, he told the Journal in 2016. The company now has its operational base in Dubai, though it says it doesn’t keep servers there.Mr. Durov maintains a yearslong friendship from his VK days with actor and tech investor Jared Leto, with whom he shares an ascetic lifestyle that eschews meat and alcohol.
Telegram Be The Next Best SPAC
I have no inside knowledge of a potential stock listing of the popular anti-Whatsapp messaging app, Telegram. But I know this much, judging by most people I talk to, especially crypto investors, if Telegram ever went public, people would gobble it up. I know I would. I’m waiting for it. So is Sergei Sergienko, who claims he owns $800,000 of Telegram’s pre-initial coin offering (ICO) tokens. “If Telegram does a SPAC IPO, there would be demand for this issue. It would probably outstrip the interest we saw during the ICO. Why? Because as of right now Telegram looks like a liberal application that can accept anyone - right after WhatsApp and others have turn on the censorship,” he says.