简体   繁体   中英

instance is not matching with filename under if statment

I have got a list of instance id calling function: instance_ID = get_instance_id() . howver when i compare instanceid with file name it matching nothing though I can see it matching when i run: #print("{} - {}".format(instance,filename))

def main():
    instance_ID = get_instance_id()
    #print(instance_ID)
    os.chdir(f'{basedir}/../config/')
    config_dir = Path()
    
    for file in config_dir.glob(f"**/*.yaml"):
        for instance in instance_ID:
            filename = file.stem
            #print("{} - {}".format(instance,filename))
            if instance == filename:
                print(instance)            
                
if __name__ == '__main__':
    main()

But just found the issue.there was a space in the csv file from where I am taking those instance ID.That caused the issue.after i instance.strip() problem resolved

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