AttributeError: partially initialized module 'socket' has no attribute 'gethostbyname' (most likely due to a circular import) - Python

AttributeError: partially initialized module 'socket' has no attribute 'gethostbyname' (most likely due to a circular import) - Python

我正在通过编写一些非常简单的代码来测试 Socket 模块,但是我遇到了错误!

按照下面的代码:

import socket

resp="Y"
while(resp=="Y"):
    url=input("URL: ")
    ip=socket.gethostbyname(url)
    print("IP: ", ip)
    resp=input("Type <y> to continue: ").upper()

您可能将文件命名为 socket.py,如果您这样做了,请更改它并重试。

原则上,始终post整个回溯