So i have structure like this
And i want to import userlist.py from server.py. Server py:
import socket
from server import userlist #<-- error here
class Server():
def __init__(self,port):
Other files in server don't have any refferences to userlist . It says cannot import name userlist
If i change import to
from server.userlist import Userlist
it says: 'server' is not a package
Try just
import userlist
When you are importing a file (module) in the same directory, all you need to do is import the name of that file without the .py
part.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.