TroyGrosfield.com TroyGrosfield.com

Posts Tagged ‘python’

Headline

Making the Move to Python 3: Python3, Virtual Environments and pip

Author
by Troy Grosfield
Date
January 9th, 2014
Category
Developer
Story

I finally made the move to converting all my apps to python 3 and it wasn’t nearly as painful as I was expecting.  One main hurdle was to figure out how to correctly get a virtual environment created with python 3 using the correct version of pip. My initial attempt to create a virtual environment … read more

Tags
Comments
No Comments »
Headline

Python virtualenv and virtualenvwrapper Cheat Sheet

Author
by Troy Grosfield
Date
April 20th, 2013
Category
Developer
Story

Commands for working with virtualenv and virtualenvwrapper. Installation Assuming you already have pip installed: $ sudo pip install -U virtualenv Install virtualenvwrapper $ sudo pip install -U virtualenvwrapper Create virtualenv $ mkvirtualenv <env_name> $ mkvirtualenv my_env Create Virtualenv with a different python My current system python is version 2.7.2.  I want my virtualenv to use … read more

Tags
Comments
No Comments »
Headline

Python Cheat Sheet

Author
by Troy Grosfield
Date
October 17th, 2011
Category
Developer
Story

Frequently used methods I use in Python with examples. Date and Datetime Lists and Sets Finding Intersection of 2 Lists Working with Urls Date and Datetime Useful links: http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior http://labix.org/python-dateutil String to Datetime Convert a string into a datetime object. >>> from datetime import datetime >>> datetime.strptime(‘Jun 1 2005  1:33PM’, ‘%b %d %Y %I:%M%p’) datetime.datetime(2005, … read more

Tags
Comments
No Comments »
Headline

Parsing XML with Python using ElementTree

Author
by Troy Grosfield
Date
December 18th, 2010
Category
Developer
Story

There are many ways to parse XML in python. I will show you the basics on how to parse XML using ElementTree. While ElementTree 1.3 and higher is not needed for this example, it’s nice to have because it has better xpath support than the earlier version.  pip install elementtree if you don’t already have … read more

Tags
Comments
5 Comments »
Headline

Installing easy_install and pip for Python

Author
by Troy Grosfield
Date
December 18th, 2010
Category
Developer
Story

easy_install and pip are python package installers that will make your life a lot easier when developing in python. Installation These steps assume you already have python installed and that python is in your windows environment variables. Download setup-tools according to your python version.  I’m currently running python 2.7 and running on windows so I … read more

Tags
Comments
No Comments »
Headline

Python Context Manager and the With Statement

Author
by Troy Grosfield
Date
October 11th, 2010
Category
Developer
Story

Context managers are a great way to “loan” out objects. In conjunction with python’s “with” statement, this can be quite the powerful design pattern. You will see ways to automatically clean up entire objects or parts of objects once they are no longer needed. Below we create an object to be used temporarily, “loan” it … read more

Tags
Comments
No Comments »