简体   繁体   中英

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_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. 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 . The for loop should be giving you an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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