用 Python 合并 300 个变量
Merging 300 variables with Python
五行是正确的:
GO #Fixed
EXEC sys.sp_cdc_enable_table #Fixed
@source_schema = N'RWAW3', #Fixed
@source_name=N'TUY1 #Variable
@role_name = NTEDULL #Fixed
我有 300 个代码,其中 100 个缺少一些固定行
我的程序识别包含变量值的行,我想将它们与固定行组合 300 次
mylines = []
fname = input("Enter file name: ")
with open (fname) as myfile:
for myline in myfile:
mylines.append(myline)
l1 = mylines[0]
l2 = mylines[1]
l3 = mylines[2]
l4 = mylines[3]
l5 = mylines[4]
tl1 = mylines.count(l1)
tl2 = mylines.count(l2)
tl3 = mylines.count(l3)
tl4 = mylines.count(l4)
tl5 = mylines.count(l5)
print(l1.strip () , tl1)
print(l2.strip () , tl2)
print(l3.strip () , tl3)
print(l4.strip () , tl4)
print(l5.strip () , tl5)
al = len(mylines)
t = [tl1,tl2,tl3,tl4,tl5]
t.remove(1)
cn= min(t)
cocm = max(t)
cncm = cocm - cn
tl = cn * 5
print('\nMissing lines:' , cncm)
print('Salting, Go to code:' , tl)
lst = list()
for line in fh:
word= line.rstrip().split()
for element in word:
if element in lst:
continue
else :
lst.append(element)
必填 1- :
cocm=312
print(l1\n,l2\n,l3\n,lst[0}\n,l5)
重复312(cocm)次
由于 lst() 中的值按升序变化
必填 2-:
tl4 = mylines.count(l4)
print(tl4)
>>> 1
程序将 l4 行识别为变量,因此将其添加到 lst() 菜单中
我想知道打印时的位置
我得到了答案
mylines = []
mmm=[]
fname = input("Enter file name: ")
#with open (fname) as myfile:
myfile = open (fname)
for myline in myfile:
mylines.append(myline)
if myline in mmm :
continue
else:
mmm.append(myline)
mm=mmm[5:]
l1 = mylines[0]
l2 = mylines[1]
l3 = mylines[2]
l4 = mylines[3]
l5 = mylines[4]
tl1 = mylines.count(l1)
tl2 = mylines.count(l2)
tl3 = mylines.count(l3)
tl4 = mylines.count(l4)
tl5 = mylines.count(l5)
print(l1,l2,l3,l4,l5.strip ())
x = len(mm)
while x > 0 :
if tl1 == 1 : print(mm[0].strip ())
else : print(l1.strip ())
if tl2 == 1 : print(mm[0].strip ())
else : print(l2.strip ())
if tl3 == 1 : print(mm[0].strip ())
else : print(l3.strip ())
if tl4 == 1 : print(mm[0].strip ())
else: print(l4.strip ())
if tl5 == 1 : print(mm[0].strip ())
else : print(l5.strip ())
del mm[0]
x = x-1
else:
quit()
五行是正确的:
GO #Fixed
EXEC sys.sp_cdc_enable_table #Fixed
@source_schema = N'RWAW3', #Fixed
@source_name=N'TUY1 #Variable
@role_name = NTEDULL #Fixed
我有 300 个代码,其中 100 个缺少一些固定行 我的程序识别包含变量值的行,我想将它们与固定行组合 300 次
mylines = []
fname = input("Enter file name: ")
with open (fname) as myfile:
for myline in myfile:
mylines.append(myline)
l1 = mylines[0]
l2 = mylines[1]
l3 = mylines[2]
l4 = mylines[3]
l5 = mylines[4]
tl1 = mylines.count(l1)
tl2 = mylines.count(l2)
tl3 = mylines.count(l3)
tl4 = mylines.count(l4)
tl5 = mylines.count(l5)
print(l1.strip () , tl1)
print(l2.strip () , tl2)
print(l3.strip () , tl3)
print(l4.strip () , tl4)
print(l5.strip () , tl5)
al = len(mylines)
t = [tl1,tl2,tl3,tl4,tl5]
t.remove(1)
cn= min(t)
cocm = max(t)
cncm = cocm - cn
tl = cn * 5
print('\nMissing lines:' , cncm)
print('Salting, Go to code:' , tl)
lst = list()
for line in fh:
word= line.rstrip().split()
for element in word:
if element in lst:
continue
else :
lst.append(element)
必填 1- :
cocm=312
print(l1\n,l2\n,l3\n,lst[0}\n,l5)
重复312(cocm)次 由于 lst() 中的值按升序变化
必填 2-:
tl4 = mylines.count(l4)
print(tl4)
>>> 1
程序将 l4 行识别为变量,因此将其添加到 lst() 菜单中 我想知道打印时的位置
我得到了答案
mylines = []
mmm=[]
fname = input("Enter file name: ")
#with open (fname) as myfile:
myfile = open (fname)
for myline in myfile:
mylines.append(myline)
if myline in mmm :
continue
else:
mmm.append(myline)
mm=mmm[5:]
l1 = mylines[0]
l2 = mylines[1]
l3 = mylines[2]
l4 = mylines[3]
l5 = mylines[4]
tl1 = mylines.count(l1)
tl2 = mylines.count(l2)
tl3 = mylines.count(l3)
tl4 = mylines.count(l4)
tl5 = mylines.count(l5)
print(l1,l2,l3,l4,l5.strip ())
x = len(mm)
while x > 0 :
if tl1 == 1 : print(mm[0].strip ())
else : print(l1.strip ())
if tl2 == 1 : print(mm[0].strip ())
else : print(l2.strip ())
if tl3 == 1 : print(mm[0].strip ())
else : print(l3.strip ())
if tl4 == 1 : print(mm[0].strip ())
else: print(l4.strip ())
if tl5 == 1 : print(mm[0].strip ())
else : print(l5.strip ())
del mm[0]
x = x-1
else:
quit()