我是 Python 新手,遇到以下脚本问题:
#modules
import time
import os
import xlsxwriter
#the path for where all the things the progrem these should happen
PATH = r"C:\status\status"
#gives you the date and time used for the name of the mother file
DATE = time.strftime('%d,%m')
#creatss a file for xls
def xl():
xl = cyberboad = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "XL")
#creatss the file tree for cyberboard with one file for ech opration and xl workbooks in ech file with oprations file
def cyberboad():
cyberboad = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD")
#operations
operation1010 = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "1010")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "1010")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
operation90247 = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "90247")
#creates the xl workbook for ech file and writes in it get file,dir at the top of colum A,C
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "90247")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
operation9969 = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "9969")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "9969")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
operation90665 = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "90665")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "90665")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
operationmatchupzone = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "matchupzone")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "CYBERBOARD" + '\\' + "matchupzone")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
#creatss the file tree for allrivers with one file for ech opration and xl workbooks in ech file with oprations file
def allrivers():
allrivers = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS")
#operations
operation5553 = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "5553")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "5553")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
operation8256 = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "8256")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "8256")
workbook = xlsxwriter.Workbook(' mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
operationeberkiss = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "emberkiss")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "emberkiss")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
operationlaguardia = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "laguardia")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "laguardia")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
operation1024 = os.makedirs(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "1024")
os.chdir(r"C:\status\status" + '\\' + DATE + '\\' + "ALLRIVERS" + '\\' + "1024")
workbook = xlsxwriter.Workbook('mazehim.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'getfile', bold)
worksheet.write('C1', 'dir', bold)
#calling the fenctions set above
cyberboad()
allrivers()
xl()
我知道这不是一个非常干净的脚本,它的作用是创建一个文件夹,然后在该文件夹中使用 module 创建一个 Excel 文件xlsxwriter
。
它工作正常,但有时不能。我究竟做错了什么?
谢谢你。