将文件名及创建时间以字典形式加入到列表3 深拷贝

本文介绍了一个使用Flask框架创建的简单应用案例,该应用展示了一组电影信息,并从指定路径读取文件列表及其最后访问时间,将这些信息整合到一个列表中供前端展示。
from flask import Flask, render_template
import time
import os

app = Flask(__name__)
    
movies = [
    {'title': 'My Neighbor Totoro', 'year': '1988'},
    {'title': 'Dead Poets Society', 'year': '1989'},
    {'title': 'A Perfect World', 'year': '1993'},
    {'title': 'Leon', 'year': '1994'},
    {'title': 'Mahjong', 'year': '1996'},
    {'title': 'Swallowtail Butterfly', 'year': '1996'},
    {'title': 'King of Comedy', 'year': '1999'},
    {'title': 'Devils on the Doorstep', 'year': '1999'},
    {'title': 'WALL-E', 'year': '2008'},
    {'title': 'The Pork of Music', 'year': '2012'},
]

fileDict={'title': 'The Pork of Music', 'year': '2012'}
fileList=[]
fileList.append(fileDict)
print(fileList)
num=0

path = "F:\\PythonWebPYCode\\mma"
listS = os.listdir(path)
print(listS)
print("*************************")

for i in listS:
    #print(i)      os.path.join(path, name)
    #i = os.path.join(path, i)
    fileDict['title']=i
    fileDict['year']=time.ctime(os.path.getatime(i))
    print(fileDict)
    fileList.append(fileDict.copy())
    #fileList[num]=fileList[num]+fileD
    

print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&")    
print(fileList)

@app.route('/')
def index():
    return render_template('index.html', name=name, movies=fileList)


if __name__ == '__main__':
    app.run()







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值