Package: pyli
Better scripting with pythonHaven’t you ever missed writing perl one liners? Or maybe you’re more
familiar with python than all the options offind, but like the text
interaction paradigm?pyliaims to make it easier to use python and
all it’s batteries in conjunction with your favorite hangout: the shell.Installpyliis available viapip:pip install pyliOr directly viagitandsetup.py:git clone https://github.com/thenoviceoof/pyli.git

cd pyli

sudo python setup.pyExamplesLet’s do some warmups:pyli "2+2" # bc

cat file.txt | pyli "line if 'string' in line else None" # grep

cat file.txt | pyli "sum(len(l) + 1 for l in lines)" # wc -mAnd now something more complicated:log | pyli "str(time.time()) + ' ' + line" # time stamping a line

cat file.txt | pyli "set(w for s in nltk.sent_tokenize(contents) for w in nltk.word_tokenize)" # bag of words a file

cat file.json | pyli "pickle.dumps(json.loads(conts))" >file.pickle

cat space_sep.dat | pyli "json.dumps(dict(parts))" >file.jsonMaybe it makes sense to separate commands:cat index.html | pyli "for l in [a.get('href') for a in bs4.BeautifulSoup(cs).find_all('a')]: print l" | pyli --text='something' "r = requests.get(li); li if text in r.text else None"

cat index.html | pyli "hashlib.sha1(cs).hexdigest()" | pyli "encryptedfile.EncryptedFile(stdout, getpass.getpass()).write(cs)"Perhaps you want to keep it a one liner, but Python is too opinionated
to let you do that:pyli -f "`ls -a`" "for l in f.split('\n'):" "    if '.git' == l: print 'git'"pyliFeatures:Automatically import referred packagesPopulate special CLI oriented variablesline(li,l) - Gives you access to each linelines(lis,ls) - Access to thelinegeneratorcontents(cont,cs) - Gives you access to all of stdin
in one stringpart, (p) - Gives you access to the different fields of a
space-separated lineparts, (ps) - Access to thepartgeneratorstdin,stdout,stderr- A shortcut tosys.std*streamsAccept arbitrary GNU style arguments (-c, –blah), and make them availablePrint last statement; if an assignment, print the value assigned
to variable(s)If we are usingline/part, then print the last statement
for each lineDo note that you should only access one of these special variables at
a time: no work has been put into combining these into something that
makes sense, so if you want multiple variables, you’ll have to do the
legwork yourself.TODOMove the engine to the nice-lookingastlibraryMake sure it works in more snakes than just 2.7.3 / 2.6.9Also see theissue trackerRelated ProjectsIn alphabetical order:funcpyOnelinerPylepypLICENSECopyright (c) <2014> <thenoviceoof>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.