繞過.pyc檔的建立
執行Python程式碼時,通常會產生包含編譯後的位元組碼的.pyc檔。但是,某些情況下可能需要抑制這些文件。這個問題探討了阻止它們創建的方法。
解決方案
根據Python官方文件(「Python 2.6中的新功能 - 解釋器變更」),可以抑制 .pyc 或 .pyo 檔案使用 -B 開關產生。或者,在執行解釋器之前設定 PYTHONDONTWRITEBYTECODE 環境變數。 Python 程式也可以透過 sys.dont_write_bytecode 變數存取此設定。
要執行Python 程式碼而不產生.pyc 文件,請使用以下指令:
python -B prog.py
Python 3.2 增強
Python 3.2 引入了一項新功能:__pycache子資料夾。 .pyc 檔案現在儲存在此子資料夾中,而不是弄亂來源資料夾。 (有關更多詳細信息,請參閱“Python 3.2 中的新增功能- PYC 存儲庫目錄”。)
性能注意事項
需要注意的是,生成.pyc 文件是一種性能優化。透過快取編譯後的字節碼,可以減少後續執行程式碼所需的時間。停用 .pyc 檔案產生(透過設定 PYTHONDONTWRITEBYTECODE=1)會對效能產生負面影響。
其他資源
有關.pyc 檔案及其效能影響的更多信息,請參閱以下資源:
- 「PEP 0304 -- 最佳化編譯」( Python 2):https://www.python.org/dev/peps/pep-0304/
- 「PEP 3147 --最佳化編譯」(Python 3):https://www.python.org /dev/peps/pep-3147/
- 「Python 中的效能增強」(GitHub):https://github.com/ python/cpython
以上是如何在Python中抑制.pyc檔的生成?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

pythonisehybridmodeLofCompilation和interpretation:1)thepythoninterpretercompilesourcecececodeintoplatform- interpententbybytecode.2)thepythonvirtualmachine(pvm)thenexecutecutestestestestestesthisbytecode,ballancingEaseofuseEfuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允許fordingfordforderynamictynamictymictymictymictyandrapiddefupment,儘管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知識之際,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations則youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concatenateListSinpythonWithTheSamelements,使用:1)operatoTotakeEpduplicates,2)asettoremavelemavphicates,or3)listcompreanspherensionforcontroloverduplicates,每個methodhasdhasdifferentperferentperferentperforentperforentperforentperfornceandordorimplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允許ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)