"Andreas Volz" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Am Mon, 06 Dec 2004 20:36:36 GMT schrieb Paul McGuire: > > > Check out the urlparse module (in std distribution). For images, you > > can provide a default addressing scheme, so you can expand > > "images/marine.jpg" relative to the current location. > > Ok, this looks good. But I'm a really newbie to python and not able to > create a minimum example. Could you please give me a very small example > how to use urlparse? Or point me to an example in the web? > > regards > Andreas
No problem. Googling for 'python urlparse' gets us immediately to: http://www.python.org/doc/current/lib/module-urlparse.html. This online doc has some examples built into it. But as a newbie, it would also be good to get comfortable with dir() and help() and trying simple commands at the >>> Python prompt. If I type the following at the Python prompt: >>> import urlparse >>> help(urlparse) I get almost the same output straight from the Python source. dir(urlparse) gives me just a list of the global symbol names from the module, but sometimes that's enough of a clue without reading the whole doc. Now is where the intrepid Pythonista-to-be uses the Python interactive prompt and the tried-and-true Python methodology known as "Just Trying Stuff Out". >>> url = "http://www.example.com/dir/example.html" # from your example >>> urlparse(url) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: 'module' object is not callable (Damn! forgot to prefix with urlparse.) >>> urlparse.urlparse(url) ('http', 'www.example.com', '/dir/example.html', '', '', '') >>> img = "images/marine.jpeg" # also from your example >>> urlparse.urlparse(img) ('', '', 'images/marine.jpeg', '', '', '') Now you can start to predict what kind of tuples you'll get back from urlparse, you can visualize how you might merge the data from the img fragment and the url fragment. Wait, I didn't read all of the doc - let's try urljoin! >>> urljoin(url,img) Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'urljoin' is not defined (Damn! forgot to prefix with urlparse AGAIN!) >>> urlparse.urljoin(url,img) 'http://www.example.com/dir/images/marine.jpeg' Is this in the ballpark of where you are trying to go? -- Paul Give a man a fish and you feed him for a day; give a man a fish every day and you feed him for the rest of his life. -- http://mail.python.org/mailman/listinfo/python-list