0

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?

Abpostman1
  • 158
  • 1
  • 8

1 Answers1

1

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.

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103