[英]Importing Subclasses from Modules in python
I'm Having an issue when Importing a series of modules and acessing classes within them. 我在导入一系列模块并在其中访问类时遇到问题。
This is my code: 这是我的代码:
import sys, os
for path, name, files in os.walk(os.getcwd()[:os.getcwd().rindex("Mario")+5]):
sys.path.insert(0, os.path.join(path))
from pygame.locals import *
import pygame, Screen
WIDTH, HEIGHT = SIZE = 1200, 675
running = True
screen = pygame.display.set_mode(SIZE, SRCALPHA)
current = None
screen_menu = Screen.Menu().add_widget(Widget.Button(WIDTH/2-25, HEIGHT/2-25, 50, 30))
When running I get: 跑步时我得到:
Traceback (most recent call last):
File "I:\Computing\Python\Mario\Global.py", line 5, in <module>
import pygame, Screen
File "I:\Computing\Python\Mario\screen\Screen.py", line 5, in <module>
import pygame, Global
File "I:\Computing\Python\Mario\Global.py", line 11, in <module>
screen_menu = Screen.Menu().add_widget(Widget.Button(WIDTH/2-25, HEIGHT/2-25, 50, 30))
AttributeError: 'module' object has no attribute 'Menu'
[Finished in 2.9s with exit code 1]
Does anyone have any idea on why this is happening, I have imported it and Menu is just a class within Screen, I can give you the Screen class if required! 有没有人知道为什么会发生这种情况,我已导入它,而Menu只是Screen中的一个类,如果需要,我可以给你Screen类!
You have a circular dependency-- Screen
uses Global
and Global
uses Screen
. 您有循环依赖关系 -
Screen
使用Global
和Global
使用Screen
。 Revise your code not to have any circular imports. 修改您的代码,不要进行任何循环导入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.