<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Cli on cassiobotaro</title><link>https://cassiobotaro.dev/en/tags/cli/</link><description>Recent content in Cli on cassiobotaro</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sat, 25 Jul 2026 13:06:19 -0300</lastBuildDate><atom:link href="https://cassiobotaro.dev/en/tags/cli/index.xml" rel="self" type="application/rss+xml"/><item><title>Invoking modules with python -m</title><link>https://cassiobotaro.dev/en/posts/python-m-module/</link><pubDate>Mon, 06 Jul 2026 00:00:00 +0000</pubDate><guid>https://cassiobotaro.dev/en/posts/python-m-module/</guid><description>&lt;p&gt;Python has the &lt;code&gt;-m&lt;/code&gt; flag, which locates a module and runs it as a script. And the standard library is full of modules that turn into command line utilities ready to use, with nothing to install.&lt;/p&gt;
&lt;p&gt;Serve the current folder over HTTP:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;python -m http.server
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Format (and validate) a JSON:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;cassio&amp;#34;, &amp;#34;language&amp;#34;: &amp;#34;python&amp;#34;}&amp;#39;&lt;/span&gt; | python -m json.tool
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;See the calendar for the year in your terminal:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;python -m calendar &lt;span style="color:#ae81ff"&gt;2026&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You have probably already used the flag without noticing, in commands like &lt;code&gt;python -m venv .venv&lt;/code&gt; or &lt;code&gt;python -m pip install&lt;/code&gt;. It is the same mechanism: &lt;code&gt;-m&lt;/code&gt; locates the module on the import path and executes it as the main program, with &lt;code&gt;__name__&lt;/code&gt; set to &lt;code&gt;&amp;quot;__main__&amp;quot;&lt;/code&gt; (when the target is a package, what runs is its &lt;code&gt;__main__.py&lt;/code&gt;).&lt;/p&gt;</description></item></channel></rss>