简体   繁体   English

python提供带有单引号的函数参数

[英]python provide arguments to a function with single quotes

I have a function that provides the other functions its arguments 我有一个提供其他功能参数的函数

def errata_eus_repo(rhel_ver, cv_name):
    rhel_check = "Red Hat Enterprise Linux Extended Update Support" + " " + rhel_ver
    cv_name_errat = []
    for eus_repo in erra_eus_repo:
        errata = eus_repo[0]
        product = eus_repo[1]
        if product == rhel_check:
            cv_name_errat.extend([cv_name, errata])
            return cv_name_errat

def filter_ver(rhel_ver):
    regex = re.compile('\d{1}\.\d{1}')
    if not regex.match(rhel_ver):
        return False
    return True

for cv_rhel_ver in name_rhel:
    if not filter_ver(cv_rhel_ver):
        cv_name = str(cv_rhel_ver)
    if filter_ver(str(cv_rhel_ver)):
        rhel_ver = str(cv_rhel_ver)

    errata_eus_lst = errata_eus_repo(str(rhel_ver), str(cv_name))
    print(errata_eus_lst)

When I call errata_eus_repo , I don't get results 当我打电话给errata_eus_repo ,我没有得到结果

 errata_eus_lst = errata_eus_repo(str(rhel_ver), str(cv_name))

However, If I send the variables directly to the function I get the correct results. 但是,如果将变量直接发送到函数,则会得到正确的结果。

I thought that the issue might have been to provide double quotes to the arguments errata_eus_repo(str("rhel_ver"), str("cv_name")) , but I am still getting no results. 我认为问题可能是对参数errata_eus_repo(str("rhel_ver"), str("cv_name"))提供双引号,但我仍然没有结果。 Any ideas? 有任何想法吗?

Quotes will only serve to pass the literal variable name instead of the data that variable contains. 引号仅用于传递文字变量名称,而不是变量包含的数据。 Your problem is in how you're using variables in the iteration cycle. 您的问题在于如何在迭代周期中使用变量。

You are initializing only one variable on each iteration in the cycle, either rhel_ver or cv_name . 您只需要在循环的每次迭代中初始化一个变量rhel_vercv_name The for loop should be giving you an error. for循环应该给您一个错误。

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

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