TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Pythonpy – Command-line Kung Fu with Python

158 pointsby Russell91over 10 years ago

14 comments

sametmaxover 10 years ago
Note that :<p>- sony did a project like this : power at prompt (<a href="https://code.google.com/p/pyp/" rel="nofollow">https:&#x2F;&#x2F;code.google.com&#x2F;p&#x2F;pyp&#x2F;</a>).<p>- an alternative exists to both : pyped (<a href="https://pypi.python.org/pypi/Pyped/1.4" rel="nofollow">https:&#x2F;&#x2F;pypi.python.org&#x2F;pypi&#x2F;Pyped&#x2F;1.4</a>) I like it better because it packs many utilities, but that&#x27;s a matter of taste.<p>- other projects like that existed prior this one doing the same thing. The author choose to reinvent the wheel instead of contributing. I tend to dislike this behavior.<p>- both alternatives uses the &quot;pyp&quot; command, instead of the &quot;py&quot; command. The reason is that the &quot;py&quot; command is now an official command in Python on Windows. Installing pythonpy will cause a conflict.
评论 #8849308 未加载
评论 #8850458 未加载
评论 #8849104 未加载
评论 #8849731 未加载
评论 #8849130 未加载
a3nover 10 years ago
Very nice.<p>However, division behavior was unexpected in Python 2. It looks like it imports division from __future__ without asking.<p><pre><code> python -V Python 2.7.8 python -c &#x27;print(4 &#x2F; 3)&#x27; 1 In [1]: 4 &#x2F; 3 Out[1]: 1 py &#x27;4 &#x2F; 3&#x27; 1.33333333333 </code></pre> EDIT: Yes, it does do that import, and others from __future__.<p>Unless these imports are essential to the <i>operation</i> of pythonpy, I suggest making these optional&#x2F;configurable, and default to Python 2 defaults, i.e. don&#x27;t import.
评论 #8848768 未加载
评论 #8848025 未加载
tucifover 10 years ago
I had used a very similar one for a while <a href="https://github.com/ksamuel/Pyped" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ksamuel&#x2F;Pyped</a> and found it quite useful. In that other utility they mention &quot;&#x27;py&#x27; has been renamed to &#x27;pyp&#x27; to avoid conflict with the new tool in the Python stdlib named &#x27;py&#x27;&quot; I wonder if such a problem would arise for your project.
评论 #8848108 未加载
评论 #8847637 未加载
jkgeytiover 10 years ago
I&#x27;ve reinvented the wheel myself and made &quot;pype&quot; (link below).<p>I&#x27;ve been using python on the command line for quite a while, but I found that I tend to use it when I&#x27;m doing something a little more advanced than what can easily be done with standard Linux tools - and command line python would often fail me, because I couldn&#x27;t easily do conditions or loops, because of the requirement for whitespace indenting. So pype contains a simple parser that&#x27;ll convert bracket indented code to regular whitespace indented code, besides supporting all the stuff you want on the command line.<p><a href="https://github.com/ircflagship2/pype" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ircflagship2&#x2F;pype</a>
mijoharasover 10 years ago
I didn&#x27;t think I&#x27;d need something like this but it actually seems like it could be quite useful.<p>I think the &quot;killer&quot; feature is the -x modifer to apply the scriptlet to every line of input. it seems like a nice way of sticking a quick python function into a pipe of commands for when you want that little bit more than the shell (or sed) is offering you.
dansoover 10 years ago
This is awesome...Right now I&#x27;m teaching a class that starts off with bash and doing everything from the command line, and then moving into Python...the more that I can have students do from the command-line, the easier it is to get the concept of functional programming&#x2F;pipes&#x2F;filters across.
geophileover 10 years ago
Along the same lines: <a href="https://github.com/geophile/osh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;geophile&#x2F;osh</a><p>* Python expressions on the command line<p>* That are connected by piping<p>* But in a single python process<p>* And adding distribution<p>* And database access
sea6earover 10 years ago
I like this, Perl has been my goto choice for scripty style commands that I run directly from the command line.<p>While Python has the -c option, that doesn&#x27;t compete with the implicit loop capability that Perl and Ruby have with the -n and -p options.<p>This utility seems to give a lot of that same power to Python.
unclesaammover 10 years ago
I&#x27;ve been looking for this since I last saw it. Thanks for posting it!<p>To me, the auto import is such a game changer compared to every other implementation (including my own: <a href="http://github.com/samzhang111/pit" rel="nofollow">http:&#x2F;&#x2F;github.com&#x2F;samzhang111&#x2F;pit</a>).
评论 #8848442 未加载
mankydover 10 years ago
Neat. I&#x27;m curious why the quotes around the commands are necessary. Why &quot;py &#x27;3 * 1.5&#x27;&quot; instead of just &quot;py 3 * 1.5&quot;?
评论 #8848160 未加载
评论 #8847345 未加载
zeeshanmover 10 years ago
This is good stuff. Finally I don&#x27;t need to hack together shell scripts with Python for adhoc text processing.
haulethover 10 years ago
`ruby -pae` in Python. It could be nice if we doesn&#x27;t have awk, sed and bc already.
评论 #8849786 未加载
puddumsover 10 years ago
This is kind of awesome.<p>&quot;Sys admin&quot; type usage definitely drives adoption&#x2F;popularity&#x2F;usage of a language (e.g., see perl; and people <i>like</i> doing sysadmin stuff with ruby). I would love, love to have something close to pythonpy in the python core. The absence of being able to cleanly fit into standard UNIX pipe &#x2F; &#x27;filter&#x27; type workflows is a real downer for python for me and for others trying to do &quot;sys admin&quot; workflows.<p>If you were to invent a time machine and put something close to this (pythonpy) in core python ~15 years ago, then I literally think python would be more popular today (and even maybe chef and&#x2F;or puppet might have been written in python. That said, rewinding time and playing it forward is a bit challenging, so I suppose we&#x27;ll never know. ;-)<p>One-liners play a big role in sysadmin type usage. I&#x27;m not a sysadmin, but I have to frequently hop on different boxes to see what the heck is going on. Typical use might be something like &quot;whoa, lot of files here... how many the heck files are there?&quot;, which is answered with a simple &#x27;wc -l&#x27;, but then you start asking other question like &quot;how many big files&quot; and &quot;what&#x27;s the average file size&quot;, etc., etc., and you start putting together longer one liners chaining together sed and awk and gawk and sh and bash and perl (including to pick up a convenient modern regex engine, which awk is not), etc., and doing it all in an extremely fast iterative run&#x2F;press up arrow a few times&#x2F;edit&#x2F;run cycle... but for me, even though I like python, only very rarely do I use a python one-liner.<p>In general, some one liners sometimes grow, and then grow some more, and then some graduate to a script that then graduates to a full-fledged project. Python sometimes effectively gets eliminated from the running for a project at step 0.<p>I like using the right language for the job, and have no problem using multiple languages on a large or medium sized project... but it slows me down and causes me some mental agita to use 2-3 languages on a <i>tiny</i> project like a one liner (where I&#x27;m counting mini-languages like awk&#x2F;sed here).<p>I&#x27;d love to use python as my default &quot;go to language&quot; for one liners... This project (pythonpy) and other projects help, but really for me good support for python one liners needs to be in the <i>core</i> default python so that when I hop on some random box to troubleshoot something for one of many teams, that capability is there waiting for me (and the absence of that &quot;just being there waiting&quot; is what killed my usage of my own version of a simple &quot;improved one-liner support for python&quot; package; our environment was too diverse and too often in practice it ended up being faster for me to use perl or ___, rather than going through the hurdle of installing a python module, which in some cases is more or less frowned upon for production boxes).<p>Based on a quick initial review, pythonpy looks better than some of the alternative efforts. Love the tab completion!
评论 #8849541 未加载
rnhmjojover 10 years ago
Python 2 :(
评论 #8847309 未加载
评论 #8847299 未加载
评论 #8848021 未加载