There are plenty of predefined Python executables, symlinks, and aliases that come bundled with your operating system. These commands come in very handy because it saves you from typing out long commands or chain of scripts. However the downfall of operating system aliases is that they don’t always play nice with virtualenv (or venv if you’re on Python 3). Most predefined aliases use the system’s default Python as the interpreter, which is next to useless when your application runs in a virtual environment. Over the years, I’ve come up with my own Python aliases that play nice with virtual environments. For this post, I tried to stay as generic as possible such that any alias here can be used by every Pythonista. In other words, there will be no aliases for specific frameworks such as running a Django server or starting a Scrappy spider. The following is one of my bash scripts I source:
.py-aliases
#----- Pip -----#
alias pip-list="pip freeze | less"
alias pip-search="pip freeze | grep -i"
alias pip-remove="pip uninstall"
alias pip-upgrade="pip install -U"
alias pip-upgrade-all="pip freeze --local | grep -v '^\-e' | cut -d = -f 1|xargs -n1 pip install -U"
#----- Debugging -----#
alias pdb="python -m pdb"
alias ppjson="python -m json.tool"
alias module-locate="python -c 'from imp import find_module;from sys import argv;print(find_module(argv[1])[1])'"
#----- Documentation -----#
alias pydoc="python -m pydoc"
Pip
This set of commands is the most convenient because pip can be a bit awkward when installing, uninstalling, and upgrading modules. Astute dev-ops folks might notice that I took heavy inspiration from tools like apt-get
and yum
. These commands also imitate conda, so for those who are using Anaconda, checkout conda out.
pip-list
: List all installed modules then pipe to a cursor so that it’s easy to scroll.pip-search
: Search installed Python modulespip-remove
: Uninstall Python module(s)pip-upgrade
: Upgrade Python module(s)pip-upgrade-all
: My favorite for development. Upgrades all the Python packages without the need to specifying them individually.
Debugging
pdb
: This is self explanatory for veterans. Runs scripts in the environment’s Python debugger.ppjson
: Pretty print JSON from a file orcurl
output. If you work with JSON and RESTful web apps, then you need this!module-locate
: Locate the system file path to a particular Python module, which can be useful when debugging. This is actually a script on my machine, but to keep this post brief, I did a quick one-liner to capture the gist of my script.
Let's do a quick tutorial of ppjson
. I generally use this to test JSON responses from web apps in conjunction with curl
, treq
, and/or requests
. For example, lets get some Star Wars JSON from SWAPI and pipe it to our new ppjson
alias:
curl -L http://swapi.co/api/people/1 | ppjson
{ "name": "Luke Skywalker", "height": "1.72 m", "mass": "77 Kg", "hair_color": "Blond", "skin_color": "Caucasian", "eye_color": "Blue", "birth_year": "19 BBY", "gender": "Male", "homeworld": "http://swapi.co/api/planets/1/", "films": [ "http://swapi.co/api/films/1/", "http://swapi.co/api/films/2/", "http://swapi.co/api/films/3/" ], "species": [ "http://swapi.co/api/species/1/" ], "vehicles": [ "http://swapi.co/api/vehicles/14/", "http://swapi.co/api/vehicles/30/" ], "starships": [ "http://swapi.co/api/starships/12/", "http://swapi.co/api/starships/22/" ], "created": "2014-12-09T13:50:51.644000Z", "edited": "2014-12-10T13:52:43.172000Z", "url": "http://swapi.co/api/people/1/" }
ppjson
also works with files containing JSON.
Documentation
pydoc
: Reference the environment PyDocs. This is generally very helpful (despite the HTML pages looking very ugly) when you need to get documentation of a module in your virutalenv. I regularly start the web server so that I can quickly reference builtin and installed modules without the need to google. Example:pydoc -b -p 9001
For a simple version of module-locate:
ReplyDelete$ pip install e
$ python -me pytest
/home/tom/.virtualenvs/connect4/lib/python3.6/site-packages/pytest.py
Literally 'python me' this 'python me' that! https://pypi.python.org/pypi/e
That's really neat!
DeleteHere are some shortcuts, which I find extremely helpful:
ReplyDeletefunction pylib() {
"$BROWSER" "https://docs.python.org/3/library/$1.html"
}
function pylib2() {
"$BROWSER" "https://docs.python.org/2/library/$1.html"
}
function pypi() {
"$BROWSER" "https://pypi.python.org/pypi/$1"
}
(I usually have set BROWSER to "xdg-open".)
I really appreciate information shared above. It’s of great help.
ReplyDeletepython online training india
I was very much confused what to do next in my career, but after going through this article I got a clear version of undergoing Python Training in Chennai| Python Course in Chennai
ReplyDeleteGood information provided by thanks keep updating
ReplyDeletepython online training
Thanks for your efforts in sharing this effective tips to my vision. kindly keep doing more. Waiting for more updates.
ReplyDeleteIELTS Coaching in Mulund
IELTS Training in Mulund West
IELTS Courses in Mulund
Best IELTS Coaching Institute in Mulund
IELTS Classes in Mulund
Best IELTS Training Centres in Mulund East
IELTS Classes near me
Your post is really awesome. Your blog is really helpful for me to develop my skills in a right way. Thanks for sharing this unique information with us.
ReplyDelete- Learn Digital Academy
whatsapp group links
ReplyDeleteThis information really amazing thanks for share this article thank you..
ReplyDeletegood morning shayari
안전토토사이트
ReplyDelete
ReplyDeleteThanks for sharing this article. Really helpful for me.
Geo News
Free Forex Signals
Daily Bitcoin Predictions
my website
ReplyDeletemy website
my website
my website
my website
my website
The bright color makes it visible even from the high distance which is a plus point in case of emergency
ReplyDeleteTOP 10 Best SOTs
Sach janiye
ReplyDeleteMrinalini Sarabhai
Sandeep Maheshwari
dr sarvepalli radhakrishnan
Arun Gawli
Rani Padmini
Sushruta
Harshavardhana
Nanaji Deshmukh
Tansen
subrahmanyan chandrasekhar
ReplyDeleteMithali Raj
Durgabai Deshmukh
Sumitranandan Pant
Pandit Deendayal Upadhyay
Manya Surve
Philip Larkin
Razia Sultan
Gautam Adani
Surdas
Really i found this article more informative, thanks for sharing this article! Also Check here
ReplyDeleteDownload and install Vidmate App which is the best HD video downloader software available for Android. Get free latest HD movies, songs, and your favorite TV shows
Vidmate App Download
Vidmate apk for Android devices
Vidmate App
download Vidmate for Windows PC
download Vidmate for Windows PC Free
Vidmate Download for Windows 10
Download Vidmate for iOS
Download Vidmate for Blackberry
Vidmate For IOS and Blackberry OS
The Information Shared Is Very Valuable Please Keep Updating Us.
ReplyDeletePython Flask Training
Flask Framework
Python Flask Online Training
It takes less than 7 minutes to sign up for our Instagram bot and set up your first promotion. Automate your social media marketing by following 3 simple steps:
ReplyDeletefree instagram followers instant
Als u zelf uw kind wil gaan helpen, moet u natuurlijk wel weten wat redactiesommen eigenlijk zijn. Bij redactiesommen zit de som verwerkt in een verhaal. Het worden dan ook wel verhaaltjessommen genoemd. Waar deze verhaaltjes eerst nog vrij eenvoudig en kort zijn, worden de redactiesommen in groep 8 steeds ingewikkelder.
ReplyDeleteredactiesommen oefenen
Als je een partytent huurt is het belangrijk om ook aan de aankleding en inrichting te denken. Het is wel zo praktisch om dat ook bij Colors Events te regelen. Wij kunnen behalve jouw partytent ook zorgen voor meubilair zoals statafels, al dan niet voorzien van rokken, stoelen of gewone tafels. Ook feestverlichting mag niet ontbreken als je een feest in de avonduren organiseert
ReplyDeleteBezoek: colorsevents.nl
Webactueel schakel je in als je een maatwerk WordPress website laten maken wilt. Door een maatwerk website te ontwikkelen is het mogelijk om meer leads te genereren. Daarbij hebben we altijd oren voor de wensen en eisen die jij als ondernemer hebt als het om jouw website gaat. Bovendien gaat het om meer dan alleen een website. Ook het toepassen van de juist online marketingstrategie helpt hier in grote mate bij. Wij kunnen dit allemaal voor je verzorgen.
ReplyDeleteWebsite laten maken
Webactueel schakel je in als je een maatwerk WordPress website laten maken wilt. Door een maatwerk website te ontwikkelen is het mogelijk om meer leads te genereren. Daarbij hebben we altijd oren voor de wensen en eisen die jij als ondernemer hebt als het om jouw website gaat. Bovendien gaat het om meer dan alleen een website. Ook het toepassen van de juist online marketingstrategie helpt hier in grote mate bij. Wij kunnen dit allemaal voor je verzorgen.
ReplyDeleteLees meer
Zonder al te veel poespas gewoon een nieuwe, strakke en frisse wandafwerking? Dan is het spuiten van latex muurverf een goede uitkomst. En ook dan moet je bij Latex Spuiten XXL zijn. Het hanteren van de speciale spuiten voor latexverf hebben wij ons in de loop der jaren eigen gemaakt. Door de spuittechniek ontstaat er een egale structuur, die een stuk strakker is dan bij het sauswerk met een traditionele verfroller. Bovendien is de klus een stuk sneller geklaard – ondanks dat we de werkzaamheden minstens zo gepassioneerd als traditioneel binnenschilderwerk uitvoeren. Latex spuiten is daarom doorgaans voordeliger dan latexen met de verfroller. Disclaimer: dit is afhankelijk per situatie en oppervlakte.
ReplyDeletemuurverf spuiten
Your Website is very good, Your Website impressed us a lot, We have liked your website very much.
ReplyDeleteWe have also created a website of Android App that you can see it.
http://damodapk.com/
http://infotodaypk.com/
Blogs are very Nice.The Information's provided in the Articles about Python are useful.keep updating and visit to know more about python
ReplyDeletepython training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery
This information is impressive. I am inspired with your post writing style & how continuously you describe this topic. Eagerly waiting for your new blog keep doing more.
ReplyDeleteOracle Training in Chennai | Certification | Online Training Course | Oracle Training in Bangalore | Certification | Online Training Course | Oracle Training in Hyderabad | Certification | Online Training Course | Oracle Training in Online | Oracle Certification Online Training Course | Hadoop Training in Chennai | Certification | Big Data Online Training Course
Booty Calls Foxy Thunder Dating Most preferred trait Sexuality (red) Least preferred trait Charisma (Green) Facts Lovers Tip-friendly guests Masturbation Yes, ...
ReplyDeleteqnnit