亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

返回我打開程序的 2 次之間的時間(以秒為單位)

返回我打開程序的 2 次之間的時間(以秒為單位)

溫溫醬 2023-05-23 16:28:34
y我想收到我在 python shell 中鍵入的兩次運行之間的時間(以秒為單位) 。很抱歉之前我沒有具體說明我想要它是什么?;旧线@是我正在測試在另一個大程序(比這個大)中實現的程序。這是我想要的輸出:首先,我將運行該程序,它會詢問我是否要借用,然后單擊y。之后,我將再次運行該程序,它會要求我返回,我將再次單擊y,它應該以秒為單位返回我借用的時間。循環將繼續。這是我需要的圖書館管理系統程序。import timeimport csvdata_backup1=[]f=open("a1.csv",'r')csvr=csv.reader(f)for line in csvr:    #copying data into a temporary storage area from csv file    print(line)    data_backup1.append(line)print(csvr,"this is csvr")    f.close()l=[]if len(data_backup1)==0:    f=open("a1.csv",'w')    csvw=csv.writer(f)    a=input("Enter y to borrow")    if a=="y":        m="borrowing"        l.append(m)        print(l)        print("this is l")        n=time.time()        l.append(n)        print(l)        print("this is l")        csvw.writerow(l)        f.close()    f.close()        f=open("a1.csv",'r')    csvr=csv.reader(f)    for line in csvr:        print(line)        else:    a=input("Enter y to return")    if a=="y":        c=[]        f=open("a1.csv",'r')        csvr=csv.reader(f)        c=csvr[1]        print(c,"this is c")            b=c[1]        print(b,"this is b")        b=int(b)        print(time.time()-b)        f.close()        f=open("a1.csv",'w')        f.close()我想得到一些建議。這是我在兩次運行之間實際得到的。請注意,我已經創建了a1.csv.
查看完整描述

1 回答

?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

試試下面。對于問題 1:您需要在打開文件進行寫入時添加 - newline=''。對于第二個問題:reader 對象需要先轉換為列表,然后才能與下標一起使用。


import csv

import os

import time

data_backup1=[]

l=[]

file_exists = os.path.exists('a1.csv')

if file_exists:

    f=open("a1.csv",'r')

    csvr=csv.reader(f)

    for line in csvr:

        #copying data into a temporary storage area from csv file

        print(line)

        data_backup1.append(line)

    print(csvr,"this is csvr")

    f.close()


if len(data_backup1)==0:

    f=open("a1.csv",'w',newline='')

    csvw=csv.writer(f)

    a=input("Enter y to borrow")

    if a=="y":

        m="borrowing"

        l.append(m)

        print(l)

        print("this is l")

        n=round(time.time())

        l.append(n)

        print(l)

        print("this is l")

        csvw.writerow(l)

        f.close()

    f.close()

    f=open("a1.csv",'r')

    csvr=csv.reader(f)

    for line in csvr:

        print(line)

else:

    a=input("Enter y to return")

    if a=="y":

        c=[]

        f=open("a1.csv",'r')

        csvr=csv.reader(f)

        line=list(csvr)

        c=line[0]

        print(c,"this is c")

        b=c[1]

        print(b,"this is b")

        b=int(b)

        print(round(time.time())-b)

        f.close()

        f=open("a1.csv",'w')

        f.close()


查看完整回答
反對 回復 2023-05-23
  • 1 回答
  • 0 關注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號