python 3.4.2 urlib no attribute 'pathname2url'

Question:

Why is the next code not working? I cant find why.

import mimetypes
import glob, urllib

for file in glob.glob("C:\Users\joey\Desktop\school\ICOMMH"):
    url = urllib.pathname2url(file)
    print(file, mimetypes.guess_type(url))

The error message I get is:

AttributeError: 'module' object has no attribute 'pathname2url'

I am trying display all file typs of a directory. Is this a good way? Or is there a better way. I dont want to use the module magic.

Asked By: joey

||

Answers:

This function’s location has changed in Python 3. It is now urllib.request.pathname2url.

Answered By: MattDMo
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.