Telegram Group & Telegram Channel
آشنایی با تابع ()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)

exec(compiled_code)



#پایتون_پیشرفته
#JiT
#compile

پایتون برای مالی
🆔 www.tg-me.com/ua/Python4Finance/com.python4finance
🆔 ble.ir/ua/Python4Finance/com.python4finance



tg-me.com/python4finance/1082
Create:
Last Update:

آشنایی با تابع ()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)

exec(compiled_code)



#پایتون_پیشرفته
#JiT
#compile

پایتون برای مالی
🆔 www.tg-me.com/ua/Python4Finance/com.python4finance
🆔 ble.ir/ua/Python4Finance/com.python4finance

BY Python4Finance


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python4finance/1082

View MORE
Open in Telegram


Python4Finance Telegram | DID YOU KNOW?

Date: |

How To Find Channels On Telegram?

There are multiple ways you can search for Telegram channels. One of the methods is really logical and you should all know it by now. We’re talking about using Telegram’s native search option. Make sure to download Telegram from the official website or update it to the latest version, using this link. Once you’ve installed Telegram, you can simply open the app and use the search bar. Tap on the magnifier icon and search for a channel that might interest you (e.g. Marvel comics). Even though this is the easiest method for searching Telegram channels, it isn’t the best one. This method is limited because it shows you only a couple of results per search.

Mr. Durov launched Telegram in late 2013 with his brother, Nikolai, just months before he was pushed out of VK, the Russian social-media platform he founded. Mr. Durov pitched his new app—funded with the proceeds from the VK sale—less as a business than as a way for people to send messages while avoiding government surveillance and censorship.

Python4Finance from ua


Telegram Python4Finance
FROM USA