简体   繁体   English

导入修饰函数

[英]Importing decorated functions

I have a number of functions in separate files with pynodered decorators, which pynodered will import one by one.我在带有 pynodered 装饰器的单独文件中有许多函数,pynodered 将一一导入。

so I call from the command line.所以我从命令行调用。

pynodered file1.py file2.py 

these file1.py etc. look like this这些 file1.py 等看起来像这样

from pynodered import node_red

@node_red(name="Unblock user",
              title="Unblock User in AD",
    def unblock_user(node, msg):

However I would like to have one big file to import them all (basically because it is easier to manage which nodes to load)但是我想要一个大文件来导入它们(基本上是因为更容易管理要加载的节点)

import file1
import file2

and then start pynodered like然后像 pynodered 一样开始

pynodered bigfile.py

But apparently this doesn't work as it cannot register the functions Exception: Zero function or class to register to Node-RED has been found.但显然这不起作用,因为它无法注册功能 Exception: Zero function 或 class 已找到注册到 Node-RED。 Check your python files检查您的 python 文件

Any ideas how to fix this?任何想法如何解决这一问题?

hmm.唔。 that is interesting.这太有趣了。 i was tryign to break up my one single bigfile to do opposite of you.我试图分解我的一个大文件来与你相反。 my current big file has the decorators for around 5 or 6 functions intwo different categories.我当前的大文件有两个不同类别的大约 5 或 6 个函数的装饰器。 they all show up fine.他们都表现得很好。

The following description from pynodered will be useful for you pynodered 的以下描述将对您有用

"""
def node_red(name=None, title=None, category="default", description=None,
             join=None, baseclass=RNBaseNode, properties=None, icon=None, color=None, outputs=1, output_labels=None):
    decorator to make a python function available in node-red. The function must take two arguments, node and msg.
    msg is a dictionary with all the pairs of keys and value sent by node-red. Most interesting keys are 'payload', 
    'topic' and 'msgid_'.
    The node argument is an instance of the underlying class created by this decorator. It can be useful when you 
    have a defined a common subclass
    of RNBaseNode that provided specific features for your application (usually database connection and similar).

""" """

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM