简体   繁体   English

如何在机器人文件中使用python函数的多个返回值?

[英]How to use multiple returned value from a python function in a robot file?

I have written a python function for fetching database credentials for different environments 我已经编写了一个python函数来获取不同环境的数据库凭据

def database_creds(env):
    if env == 'staging' or env == 'qa':
        hostname = 'host1'
        username = 'user1'
        password = 'pass11'
        database = 'TestDb'
    elif env == 'production':
        hostname = 'host2'
        username = 'user2'
        password = 'pass22'
        database = 'ProdDb'
    return hostname, username, password, database

My doubt is how we can use each returned values in robot file? 我的疑问是如何使用机器人文件中的每个返回值?

If we are returning only one value from a python function 如果我们仅从python函数返回一个值

def getApiFullUrl(env):
    if env== 'production':
        url = 'production url'
    else:
        url = 'other environment url'
    return url

we can use like this in robot file: 我们可以在机器人文件中这样使用:

${url}  ${getApiFullUrl('${env}')}

Either assign them to the same number of variables (that's "automatic unpacking"): 将它们分配给相同数量的变量(即“自动拆包”):

${hostname}   ${username}   ${password}   ${database}     database_creds    production

, or assign it to a single variable and treat it as a list: ,或将其分配给单个变量并将其视为列表:

${data}     database_creds    qa
Log    This is the hostname - ${data}[0], and this the database - ${data}[3]

暂无
暂无

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

相关问题 python 将另一个 function 的返回值设置为在 header 中使用的变量 - python set returned value from another function as a variable to use in header 无法使用 Python 中另一个文件的返回值 - Unable to use returned value from another file in Python 在 Airflow/ 上使用 PythonOperator 时如何使用 Python 函数的返回值 - How to use the returned value of a Python Function when using a PythonOperator on Airflow/ 如何在python的另一个应用程序中使用函数返回的值? - How can I use a value returned by a function in another application in python? 如何使用函数返回的列表,作为 Python 中的函数参数 - How to use returned list from function, as function args in Python 如何在另一个 function 中使用前一个 function 返回的变量? (Python) - How to use a returned variable from a previous function in another function? (python) 如何跳过初始化函数的第一个返回值? -Python - How to skip initializing the 1st returned value from a function? - Python 如何将返回的值(从先前的函数中)读取到pandas,python中? - How to read the returned value (from previous function) into pandas, python? 如何使用新 function 中一个 function 的返回值(列表)在用户所需的文件路径中将列表打印为 csv - How to Use the Returned Value (a list) from one function in a new function to print the list as a csv at the user's desired file path 如何在 python 文件中的其他地方分配从烧瓶返回的值? - How to assign a value returned from flask somewhere else in python file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM