简体   繁体   English

您好,我想知道如何在python中使用Enum

[英]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.

相关问题 我想知道如何在python中将ISO日期更改为UTC - I would like to know how to change an ISO date to UTC in python 我想知道如何 select 所有文件与 selenium python - I would like to know how to select all files with selenium python Python我想知道如何使用for循环编写(DictWriter) - Python i would like to know how to writerow with a for loop (DictWriter) 我想知道这在python中是否可行 - I would like to know if this is possible in python 如何将此列表转换为数据框? 我想知道如何在python中做到这一点? - How to turn this list into a data frame? I would like to know how to do this in python? 我想知道如何使用 Bot 框架 SDK 为 python 设置自适应卡的主机配置 - I would like to know how to set the host config of the adaptive card using Bot framework SDK for python 我想知道如何制作while循环? - I would like to know how can I make while loop? C ++类:如何使用dict [“ hello”] = 20; 像Python - C++ class: How to use dict[“hello”]=20; like Python 我想知道如何将 map 字典的值列表设为 dataframe - I would like to know how to map dictionary with list of value to dataframe 我想知道如何在 Pytorch 中处理 LSTM - I would like to know how to handle LSTM in Pytorch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM