25 पॉइंट द्वारा xguru 2024-06-05 | 2 टिप्पणियां | WhatsApp पर शेयर करें
  • Python के modules को command-line tools के रूप में इस्तेमाल किया जा सकता है
    • उदाहरण के लिए, webbrowser module को command line से चलाने पर दिए गए URL को default web browser में खोला जा सकता है
    • Python standard library में ऐसे कई module-script hybrid शामिल हैं
  • -m option के साथ Python चलाने पर दिया गया Python module script की तरह execute होता है
    • कुछ modules import के समय कुछ action करते हैं; उदाहरण के लिए, antigravity module 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 का उपयोग करते हैं

उपयोगी सामान्य-उद्देश्य 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: uuidgen CLI utility जैसा
  • python3.12 -m sqlite3: sqlite3 CLI utility जैसा
  • python -m zipfile: zip और unzip CLI utility जैसा
  • python -m gzip: gzip और gunzip CLI utility जैसा
  • python -m tarfile: tar CLI 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: unittest tests चलाता है
  • python -m pydoc: documentation दिखाता है
  • python -m doctest: दी गई file के doctest चलाता है
  • python -m ensurepip: pip install करता है
  • 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: turtle module से बनाए जा सकने वाले अलग-अलग चित्रों का 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 टिप्पणियां

 
han905 2024-06-11

वाह, उम्मीद से ज़्यादा अच्छे फीचर्स हैं, बढ़िया

 
dhy0613 2024-06-05

मुझे याद है कि एक बार बंद नेटवर्क वाले Linux server में zip फ़ाइल लेकर गया था, लेकिन unzip कमांड नहीं था, इसलिए python -m zipfile मॉड्यूल से extract करके काम आगे बढ़ाया था।