Python के विविध command-line tools
(pythonmorsels.com)- Python के modules को command-line tools के रूप में इस्तेमाल किया जा सकता है
- उदाहरण के लिए,
webbrowsermodule को command line से चलाने पर दिए गए URL को default web browser में खोला जा सकता है - Python standard library में ऐसे कई module-script hybrid शामिल हैं
- उदाहरण के लिए,
-moption के साथ Python चलाने पर दिया गया Python module script की तरह execute होता है- कुछ modules import के समय कुछ action करते हैं; उदाहरण के लिए,
antigravitymodule web browser में XKCD comic खोल देता है। इसे command line से चलाने पर module को import करने जैसा ही effect होता है - इसे "import side effect" कहा जाता है, और ज़्यादातर modules इससे बचते हैं।
antigravityजैसे easter egg modules इसका अपवाद हैं - जो modules import side effect से बचते हैं, वे module के रूप में import होने और script के रूप में execute होने पर अलग behavior देने के लिए
__name__variable का उपयोग करते हैं
- कुछ modules import के समय कुछ action करते हैं; उदाहरण के लिए,
उपयोगी सामान्य-उद्देश्य command-line tools
python -m http.server: एक simple web server शुरू करता हैpython -m webbrowser: web browser चलाता हैpython -m json.tool: JSON data को सुंदर format में दिखाता हैpython -m calendar: command line calendar दिखाता है
Windows पर खास तौर पर उपयोगी tools
python3.12 -m uuid:uuidgenCLI utility जैसाpython3.12 -m sqlite3:sqlite3CLI utility जैसाpython -m zipfile:zipऔरunzipCLI utility जैसाpython -m gzip:gzipऔरgunzipCLI utility जैसाpython -m tarfile:tarCLI utility जैसा
Python code पर काम करते समय उपयोगी tools
python -m pip: third-party Python packages install करता हैpython -m venv: virtual environment बनाता हैpython -m pdb: Python debugger चलाता हैpython -m unittest:unittesttests चलाता हैpython -m pydoc: documentation दिखाता हैpython -m doctest: दी गई file केdoctestचलाता हैpython -m ensurepip:pipinstall करता हैpython -m idlelib: IDLE graphical REPL चलाता हैpython -m zipapp: Python module को executable ZIP में बदलता हैpython -m compileall: Python files को पहले से bytecode में compile करता है
Python code analysis tools
python -m tokenize: Python module को tokens में तोड़ता हैpython -m ast: code का abstract syntax tree दिखाता हैpython -m dis: Python code को bytecode में disassemble करता हैpython -m inspect: Python objects के source code की जाँच करता हैpython -m pyclbr: module के objects का overview दिखाता है
Python easter egg की तरह काम करने वाली मज़ेदार scripts
python -m __hello__: "Hello world!" प्रिंट करता हैpython -m this: Python का Zen (The Zen of Python, PEP 20) प्रिंट करता हैpython -m antigravity: web browser में Python से जुड़ा XKCD comic #353 खोलता हैpython -m turtledemo:turtlemodule से बनाए जा सकने वाले अलग-अलग चित्रों का demo दिखाता है
अन्य Python-संबंधित tools
python -m asyncio: asyncio support वाला Python REPL चलाता हैpython -m cProfile: Python programs की profiling करता हैpython -m pstats:cProfileसे बनी profile statistics दिखाता हैpython -m pickle: pickle file की contents दिखाता है (high-level)python -m pickletools: pickle file को तोड़कर दिखाता है (low-level)
कम उपयोगी tools
python -m timeit: Python expressions के execution time को मापता हैpython -m site: Python कीsiteजानकारी दिखाता हैpython -m sysconfig: Python configuration details दिखाता हैpython -m platform: मौजूदा platform की जानकारी दिखाता हैpython -m mimetypes: file mimetype/extension जानकारी दिखाता हैpython -m quopri: raw email data encode/decode करता हैpython -m filecmp: दो directories की contents की तुलना करता हैpython -m tabnanny: Python files में tab और spaces के mixed use की जाँच करता है
2 टिप्पणियां
वाह, उम्मीद से ज़्यादा अच्छे फीचर्स हैं, बढ़िया
मुझे याद है कि एक बार बंद नेटवर्क वाले Linux server में zip फ़ाइल लेकर गया था, लेकिन
unzipकमांड नहीं था, इसलिएpython -m zipfileमॉड्यूल से extract करके काम आगे बढ़ाया था।