2017-03-08 5 views
0

이 그대로 작동하지만 .format는여러 줄 .format() 메소드는 3

내 질문에 좀 더 효율적으로 .format 방법을 사용할 수 있습니다 어떻게 요약 할 수있다. 나는 .format (switch)와 .format ([switch])를 시도했으나 오류가 발생했다. 아래 다시

구문을 모든 변수를 작성하는 피하기 위해 올바른 구문을 것입니다 무슨

..

switch = [SW_1, Int_1, Vlan_num, Des] #group of input variables 
config1 = """ 
interface GigabitEthernet {1} 
description {3} 
switchport 
switchport access vlan {2} 
""".format(SW_1, Int_1, Vlan_num, Des) 

print(config1) 

답변

1

시도 :

switch = [SW_1, Int_1, Vlan_num, Des] #group of input variables 
config1 = """ 
interface GigabitEthernet {1} 
description {3} 
switchport 
switchport access vlan {2} 
""".format(*switch) 

하나의 스타를 사용하는 방법에 대해 자세히 알아보기 https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists. 더 많이 연구하고 싶다면 "주장을 풀다"가 핵심 문구입니다.