Abpostman1
Abpostman1

Reputation: 192

What difference between "urllib.request.urlopen" and simple "open" for CSV handling

I'm re-reading old code of mine and I wonder why I used several times :

file_2_test = urllib.request.urlopen('file://' + file).read()

when (to my mind)

open(file)

would have been sufficient.

I couldn't find explanation anywhere. I suppose at this time I had to do this for a good reason but can't remember why. The only clue I have is that each time, this line followed :

encoding = (chardet.detect(file_2_test))['encoding']

Could this line be a good reason I didn't use open?

Upvotes: 0

Views: 293

Answers (1)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

The two are different, open is a builtin python function and the urlopen is a method of request.urllib

open: Open the file and return a corresponding file object. If the file cannot be opened, an OSError is raised.

urlopen:: Open the URL, which can be either a string or a Request object.

Upvotes: 1

Related Questions