CSV到Markdown生成器

# csv_to_markdown.py
#   This program imports a comma separated list of values
#   for clients of a gym. It then processes the information
#   into a markdown file.

def main():
    # Import client information.
    infile = open("LocationOfCSVFile.csv", "r")
    outfile = open("ExportLocationOfMarkdown.md", "w")

    # Convert the information to a markdown friendly format.
    # This modify header and variables as you see fit, but make sure it matches .csv
    print("First Name | Last Name | Birthday | City | State | Zipcode | Email | Phone", file=outfile)
    print("----- | ----- | ----- | ----- | ----- | ----- | ------ | -----", file=outfile)

    # Loop line by line extracting variables for the fields
    # Export the file as a markdown file.
    for line in infile.readlines():
        split_line = line.split(",")
        fname = split_line[0]
        lname = split_line[1]
        bday = split_line[2]
        city = split_line[3]
        state = split_line[4]
        zipcode = split_line[5]
        email = split_line[6]
        phone = split_line[7]
        print(f"{fname} | {lname} | {bday} | {city} | {state} | {zipcode} | {email} | {phone}",
              file=outfile, end="")

    infile.close()
    outfile.close()


main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

与AI共生

已有 237 位读者为技术火种

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值