[英]Hello, I would like to know how to use Enum in python
I made an enum file and tried to import in the file showing next code (another file) But showing this error following : 我做了一个枚举文件,并试图导入显示下一个代码的文件(另一个文件),但是在下面显示此错误:
File "C:/Users/1/PycharmProjects/assignment3/Program.py", line 61, in Program
NN.TrainByBackProp(100000, 0.1, GradDescType.STOCHASTIC)
NameError: name 'GradDescType' is not defined
and this host file seems not recognize import when I imported like import Myenum which is belonged enum file. 当我像属于枚举文件的导入Myenum一样导入时,此主机文件似乎无法识别导入。 What should I correct to deal with this issue?
我该如何解决这个问题? Thank you for your response in advance.
感谢您的提前答复。 If you need more information, let me know I will respond as soon as possible.
如果您需要更多信息,请告诉我,我会尽快回复。
enum file 枚举文件
import enum
class GradDescType(enum.Enum):
BATCH=1
STOCHASTIC=2
MINIBATCH=2
class ActivationFunction(enum.Enum):
SIGMOID=1
SOFTMAX=2
another file 另一个文件
NN.TrainByBackProp(100000, 0.1, GradDescType.STOCHASTIC)
在“另一个文件”中,您需要导入已定义的两个枚举:
from <enum_file> import GradDescType, ActivationFunction
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.