簡體   English   中英

無法將構造的 var inv 作為參數傳遞給同一 class 中的另一個 function

[英]Unable to pass constructed var inv as a parameter to another function in same class

團隊:需要澄清:無法將構造的 var inv作為參數傳遞給同一 class 中的另一個 function。 我將第 6 行的參數作為teamInventory.parse_inventory(inv)傳遞,但它沒有被 parse_inventory 攔截

誰能糾正我如何將 inv 傳遞給parse_inventory()

class teamInventory:
    def clone_repo(self):
        self.team_dev = "dev0"
        for team_cluster in self.preprod_clusters:
            inv=str(local_repo_path)+self.team_dev+"/hosts.ini"
            teamInventory.parse_inventory(inv)
        return self

    def repo_checkout(self):
        try:
            local_repo_path.exists() and local_repo_path.is_dir()
            teamInventory.clone_repo(self)
        except OSError as e:
            print("Error %s : %s" % (local_repo_path, e.strerror))
        return self

    def parse_inventory(self, cluster_inv):
        self.server = "team"
        cro = teamInventory().clone_repo()
        if cro.team_dev in cluster_inv:
            print("dev cluster inventory")
        return self
avi.repo_checkout()

output

TypeError: parse_inventory() missing 1 required positional argument: 'cluster_inv'

預期的

dev cluster inventory

我不得不使用 self 而不是通過 class 名稱進行引用,並且還刪除了其他不需要的函數的對象。

class teamInventory:
def clone_repo(self):
    self.team_dev = "dev0"
    for team_cluster in self.preprod_clusters:
        inv=str(local_repo_path)+self.team_dev+"/hosts.ini"
        self.parse_inventory(inv)
    return self

def repo_checkout(self):
    try:
        local_repo_path.exists() and local_repo_path.is_dir()
        teamInventory.clone_repo(self)
    except OSError as e:
        print("Error %s : %s" % (local_repo_path, e.strerror))
    return self

def parse_inventory(self, cluster_inv):
    self.server = "team"
    if self.team_dev in cluster_inv:
        print("dev cluster inventory")
    return self

avi.repo_checkout()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM