0
我可以避免重複每個屬性名稱嗎?我可以替換這個重複的2D列表嗎?如何使用並行變量簡化多變量循環?
test_list = (('PointValue', s_pt.PointValue, m_pt.PointValue),
('PointType', s_pt.PointType, m_pt.PointType),
('Group', s_pt.Group, m_pt.Group),
('TimeStamp', s_pt.TimeStamp, m_pt.TimeStamp),
('Tag', s_pt.Tag, m_pt.Tag),
('PointTime', s_pt.PointTime, m_pt.PointTime),
('PointNumber', s_pt.PointNumber, m_pt.PointNumber),
('Quality', s_pt.Quality, m_pt.Quality))
for var, s_var, m_var in test_list:
REPORT += 'Slave %s = %s ::: Master %s = %s\n' % (var, s_var, var, m_var)
你錯過了在字符串格式化第三''var''。我寧願使用''format''來避免重複 – 2012-03-28 22:58:43