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

What is Secret Chats of Telegram

Secret Chats are one of the service’s additional security features; it allows messages to be sent with client-to-client encryption. This setup means that, unlike regular messages, these secret messages can only be accessed from the device’s that initiated and accepted the chat. Additionally, Telegram notes that secret chats leave no trace on the company’s services and offer a self-destruct timer.

How Does Bitcoin Mining Work?

Bitcoin mining is the process of adding new transactions to the Bitcoin blockchain. It’s a tough job. People who choose to mine Bitcoin use a process called proof of work, deploying computers in a race to solve mathematical puzzles that verify transactions.To entice miners to keep racing to solve the puzzles and support the overall system, the Bitcoin code rewards miners with new Bitcoins. “This is how new coins are created” and new transactions are added to the blockchain, says Okoro.

Python4Finance from jp


Telegram Python4Finance
FROM USA