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/br/Python4Finance/com.python4finance
🆔 ble.ir/br/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/br/Python4Finance/com.python4finance
🆔 ble.ir/br/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: |

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 announces Search Filters

With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.

Python4Finance from br


Telegram Python4Finance
FROM USA