我有以下功能片段,用于计算每两个月的付款时间表。我需要能够准备将值作为单个数组元素插入到MYSQL数据库中。我该如何实现?
from PyPDF2 import PdfFileWriter, PdfFileReader
import csv
def readcsv(filename):
ifile = open(filename, "rU")
reader = csv.reader(ifile, delimiter=";")
rownum = 0
a = []
for row in reader:
a.append(row)
rownum += 1
ifile.close()
return a
filepath = input("Filepath: ")
filename = input("File name: ")
csv = readcsv(filepath + filename)
inputpdf = PdfFileReader(open("test.pdf", "rb"))
for i in range(inputpdf.numPages):
output = PdfFileWriter()
output.addPage(inputpdf.getPage(i))
with open(str(csv[i]).translate(str.maketrans('','',"[]'")) + ".pdf", "wb") as outputStream:
output.write(outputStream)
当前状态输出:
function calculatePaymentSchedule($d1, $months){
$date = new DateTime($d1);
// call second function to add the months
$newDate = $date->add(addMonths($months, $date));
//formats final date to Y-m-d form
$dateReturned = $newDate->format('Y-m-d');
return $dateReturned;
}
$startDate = '2018-5-15';
$duration = 12;
$paymentCount = $duration + 2;
for($i =0; $i < $paymentCount; $i++){
if($i % 2 == 0 && $i != 0){
$final = calculatePaymentSchedule($startDate, $i);
echo $final.'<br>';
}
}
答案 0 :(得分:1)
初始化数组顶部:
all_dates = array();
在for循环中:
$final = calculatePaymentSchedule($startDate, $i);
array_push($all_dates, $final);