tags:

views:

240

answers:

1

hi i am trying to get the extension of the file called in a url (eg"/wp-includes/js/jquery/jquery.js?ver=1.3.2 HTTP/1.1") and get the query perimeters passed to the file too what would be the best way to the extension?

+4  A: 

urlparse.urlparse() and os.path.splitext().

Ignacio Vazquez-Abrams
You should probably just rsplit on `.` rather than use `os.path` in this case, as a URL and a filepath are different things. Using `os.path.splitext` would go wrong on an operating system where the file extension separator isn't `.`. Admittedly there are vanishingly few of those today.
bobince
wouldn't rsplit mathc the ver=1.3.2 path too ?
nashr rafeeg
You would use it on the results of `urlparse()`.
Ignacio Vazquez-Abrams
As a rule URL path manipulations should probably be done with posixpath.
Devin Jeanpierre