import http.client
import time
import csv
import json
import codecs
import uuid
import pandas as pd
cols = ['ICCID',"Status Code"]
lst = []
i=1
input_file ="1.txt"
output_file ="Output File_Test.csv"
file = open(output_file, "w")
csv_writer = csv.writer(file,dialect='excel')
with open('1.txt', 'r') as f1:
f1_read = csv.reader(f1)
for var in f1_read:
code = var[0]
def luhn_checksum(code):
length = len(code)
parity = length % 2
total_sum = 0
for i in range(length-1, -1, -1):
d = int(code[i])
if i % 2 == parity:
d *= 2
if d > 9:
d -= 9
total_sum += d
return total_sum % 10
def luhn_calculate(partcode):
checksum = luhn_checksum(partcode + "0")
return 0 if checksum == 0 else 10 - checksum
def luhn_validate(f1_read):
return luhn_checksum(f1_read) == 0
res = luhn_calculate(f1_read)
res1= luhn_validate(f1_read)
print(res.partcode)
data = res.read()
file = open ("out.txt", "a+")
file.write(data.decode("utf-8") + "\n")
lst.append([str(sub_id),res.code])
df1 = pd.DataFrame(lst, columns=cols)
df1.to_excel("Output_1397.xlsx")
print("DONE!")
在上面的程序中,由于错误而失败 类型错误:+ 不支持的操作数类型:“_csv.reader”和“str”
这里我们输入一个数字“893107032131149492”,不带校验位。我们需要输出作为校验位。 试图解决但仍然面临问题。
let
Source = Folder.Files("C:\Mobility_reports_inputs_files"),
#"Sorted Rows" = Table.Sort(Source,{{"Date modified", Order.Descending}}),
#"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each Text.StartsWith([Name], "Mob_repc", Comparer.OrdinalIgnoreCase) ),
#"Kept First Rows" = Table.FirstN(#"Filtered Rows",1),
Navigation1 = #"Kept First Rows"{0}[content]
in
Navigation1
最后一步你想做什么?以上是我猜的。