简体   繁体   English

Python3:在另一个文件中打印函数返回的值

[英]Python3 : Print returned values from the function in another file

I am working on a Jupyterhub project and beginner Python user. 我正在研究Jupyterhub项目和Python初学者。 I would like to print returned values from the function in another py file for dubug. 我想在dubug的另一个py文件中打印函数返回的值。

a.py : a.py

class TestSpawner(SlurmSpawner):
    def _options_form_default(self):
        return """
        <label for="queue">node type</label>
        <select name="queue">
          <option value="standard">standard</option>
          <option value="dev-test">TEST</option>
        </select>
        <label for="runtime">Job duration</label>
        <select name="runtime">
          <option value="1:00:00">1 hour</option>
          <option value="2:00:00">2 hours</option>
        </select>
        """
    def options_from_form(self, formdata):
        print ( formdata.get('queue', [''])[0].strip())
        options = {}
        options['queue'] = formdata.get('queue', [''])[0].strip()
        options['runtime'] = formdata.get('runtime', [''])[0].strip()
        print (options)
        return options

b.py : b.py

import sys
from a import *
print (options)
print (queue)

I can see the queue and options values using print (options) in a.py , but I am not sure how I can print the values in b.py and make sure it gets correct values from a.py . 我可以在a.py使用print (options)看到队列和选项的值,但是我不确定如何在b.py打印值并确保它从a.py获取正确的值。 Please help me and Thanks. 请帮助我,谢谢。

Import your module, make an instance, and call the method in b.py : 导入模块,创建一个实例,然后在b.py调用该方法:

import a

spawner = a.TestSpawner()

formdata = 'my form data'  # add your data here
print(options_from_form(formdata))

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

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