Showing posts with label module. Show all posts
Showing posts with label module. Show all posts

Wednesday, November 7, 2012

python url parse

Python got awesome module called urlparse. When you want different values from url, you might think of doing substring. Which is very risky and bad practice.

Here is the simple and easy way to do it in python -


>>> str = "http://demo.myapp.com/api/v1/items/26/"
>>> from urlparse import urlparse
>>> o = urlparse(str)
>>> o
ParseResult(scheme='http', netloc='demo.myapp.com', path='/api/v1/items/26/', params='', query='', fragment='')

>>> o.path
'/api/v1/items/26/'


That was easy!

You can do much more using this module, please checkout the more details on this Reference link.