0

I'm running Python 3.6.3 on Windows 10 and installed Requests via pip.

#!python
import requests
print('Hello')

Results in "Hello" printing twice on PowerShell as well as Command Prompt. When I don't import requests, print works as expected.

Launching Python and importing from the prompt however causes no issue.

Anthony
  • 722
  • 1
  • 9
  • 25

2 Answers2

4

What is happening is the requests library is importing a file named html. Since your file is also named html.py and is on the import path it is loaded twice.

Use the convention

if __name__ == '__main__':
    print("HI")

to avoid this.

See this question for more details: What does if __name__ == "__main__": do?

Sam
  • 2,939
  • 19
  • 17
  • Thanks! As you can see I'm new to Python so i'm fumbling a bit. – Anthony Nov 14 '17 at 16:59
  • Happy to. You might have to rename your file anyway if the `requests` module claims something under `html` is missing. But that's another error for later on. Happy hacking. – Sam Nov 14 '17 at 17:01
  • never use "smart" & generic names like that. You may stumble on already existing module names. – Jean-François Fabre Nov 14 '17 at 17:18
0

There must be something in the requests library that hiccups on a filename named "html.py".

enter image description here

Anthony
  • 722
  • 1
  • 9
  • 25