因此,我正在制作一个名为soar
的模块,该模块需要执行复杂的操作,使它们更容易(我认为)。我在尝试从soar.py
导入错误的内容时遇到问题。
错误:ImportError: cannot import name 'Soar' from 'soar'
soar.py:
versionNo = "0.4.2"
author = "AbyssWalker240"
#####
class Logger:
def __init__(self):
pass
@classmethod
def llog(cls, file, typeM, message):
with open(file, "a") as llog_f:
llog_f.write("\n" + typeM + ": " + message)
class Math:
def __init__(self):
pass
@classmethod
def add(cls, number1, number2):
try:
return number1 + number2
except:
print("Error: non-int variable detected. Please replace all strings/lists/floats or other with an int.")
def sub(cls, number1, number2):
try:
return number1 - number2
except:
print("Error: non-int variable detected. Please replace all strings/lists/floats or other with an int.")
def mul(cls, number1, number2):
try:
return number1 * number2
except:
print("Error: non-int variable detected. Please replace all strings/lists/floats or other with an int.")
def div(cls, number1, number2):
try:
return number1 / number2
except:
print("Error: non-int variable detected. Please replace all strings/lists/floats or other with an int.")
class Soar:
def __init__(self):
pass
@classmethod
def version(cls):
print(versionNo)
def author(cls):
print(author)
class Join:
def __init__(self):
pass
@classmethod
def sJoin(cls, str1, str2, spacedVal):
if(spacedVal == 1):
return str1, str2
elif(spacedVal == 0):
return str1 + str2
else:
print("Error: spacedVal should be either 1 (spaced) or 0 (not spaced)")
test.py: 从so壮的进口加入
joiner = Join()
str1 = "srting"
str2 = "gnitrs"
print(joiner.sJoin(str1, "hi man", 1))
print(joiner.sJoin("hi", str2, 0))
当我执行from soar import Logger
,from soar import Math
,from soar import Soar
和/或from soar import Join
时,会发生此问题。不管我做什么。添加“加入”后开始出现此问题。
这对我来说没有意义,因为在给定的任何代码中我都没有键入from soar import Soar
,即使我键入了,我也没有理由将其导入该模块。
我也知道没有限制,也没有任何东西会妨碍我拥有的课程数量,所以这不是问题。