您可以使用Python的datetime模块来获取当前日期和时间,并使用strftime()方法将其格式化为星期字符串。
以下是一个示例代码:
import datetime
# 获取当前日期和时间
now = datetimedatetimenow()
# 将日期格式化为星期字符串
weekday = nowstrftime("%A")
print("今天是:", weekday)
输出:
今天是: Wednesday
在上面的代码中,%A是strftime()方法的格式化字符串,它表示星期的全名(例如Monday、Tuesday等)。您可以使用其他格式化字符串来获取不同的日期和时间格式。
这个用py容易,建议用一个包,pandas,直接下载一个就可以了,接下来就是 *** 作了
import pandas as pd
import os
path ='/file/' #此为包含文件的路径名称
files = oslistdir(path) # 获取该路径下的所有文件名称
#循环读取
for file in files:
if 'df' not in dir():
df = pdread_csv(path + file, sep='\t')
df = df[df[1] in ['Measure EstimatedTotalIntraCranialVol', 'bankssts ']]
else:
temp = pdread_csv(path+ file, sep='\t')
temp = temp[temp[1] in ['Measure EstimatedTotalIntraCranialVol', 'bankssts ']]
df = pdconcat([df, temp])
print dfhead()
df 即所筛选出来的行
from tkinter import
from tkinter import ttk
from tkinter import font
import os
import arrange
# 课程的字典
crslst = {}
crslst_in_num = {}
# GUI
root = Tk()
# frame2
# 右侧的内容
frame2 = ttkFrame(root, borderwidth=5, relief="sunken")
frame2grid(column=1, row=0)
# 将数字转换为汉字的字典
numtoch = {1: '一', 2: '二', 3: '三', 4: '四', 5: '五'}
# 设置课表周围周一至周五和1至13的标签
for num in list(range(1, 6)):
ttkLabel(frame2, text='周' + numtoch[num])grid(column=num, row=0)
emptylist = []
for num in list(range(1, 14)):
ttkLabel(frame2, text='第' + str(num) + '节')grid(column=0, row=num)
# 课表主体
schd1 = Listbox(frame2, height=13)
schd1grid(column=1, row=1, rowspan=13, sticky=(N, S, E, W))
schd2 = Listbox(frame2, height=13)
schd2grid(column=2, row=1, rowspan=13, sticky=(N, S, E, W))
schd3 = Listbox(frame2, height=13)
schd3grid(column=3, row=1, rowspan=13, sticky=(N, S, E, W))
schd4 = Listbox(frame2, height=13)
schd4grid(column=4, row=1, rowspan=13, sticky=(N, S, E, W))
schd5 = Listbox(frame2, height=13)
schd5grid(column=5, row=1, rowspan=13, sticky=(N, S, E, W))
# 设置字体
ft = fontFont(family='Microsoft YaHei', size=12, weight='normal')
# 为了便捷将五天的课表作为一list
daylist = (schd1, schd2, schd3, schd4, schd5)
# 设置课表
for day in daylist:
day['selectmode'] = 'extended'
day['exportselection'] = False
for num in range(1, 14):
dayinsert(0, '无课')
day['font'] = ft
day['width'] = 10
# 课表下四个按钮和一个combobox
# 改变颜色
def chcolor():
print("\033[1;42m\033[0m")
butdont = ttkButton(frame2, text='不上课', command=chcolor)grid(column=3, row=15)
# 清除选择
butusel = ttkButton(frame2, text='清除选择')grid(column=4, row=15)
Label(frame2, text='选择课表')grid(column=0, row=15, columnspan=2, sticky=W)
outputlist = ttkCombobox(frame2, textvariable=['待选', 'ok'])
outputlistgrid(column=1, row=15, columnspan=2, sticky=E)
# frame1
# 左侧的内容
frame1 = ttkFrame(root, borderwidth=5, relief="sunken")
frame1grid(column=0, row=0)
# 设置上方的label
Label(frame1, text='输入课程信息')grid(column=0, row=0, columnspan=2)
# 输入课程号的Label和entry
Label(frame1, text='课程号:')grid(column=0, row=1, sticky=W)
coursenum = StringVar()
inputcoursenum = ttkEntry(frame1, textvariable=coursenum, width=13)
inputcoursenumgrid(column=1, row=1, sticky=E)
# 已选课程的listbox
Label(frame1, text='已选课程')grid(column=0, row=3, sticky=W)
courselist = Listbox(frame1, height=8, width=13, exportselection=False)
courselistgrid(column=0, row=4, columnspan=2, rowspan=8, sticky=W)
def isrtcrs(): # 加入课程
k = 0
num = 0
print(num, courselistsize())
while num < courselistsize():
if inputcoursenumget() == courselistget(num):
k = 1
num += 1
if k == 0:
courselistinsert(0, inputcoursenumget())
crslst[inputcoursenumget()] = []
crslst_in_num[inputcoursenumget()] = []
print(crslst)
print(crslst_in_num)
return
def delcrs(): # 删除课程
# print(courselistcurselection())
# print(courselistget(courselistcurselection()))
crslst_in_numpop(courselistget(courselistcurselection()))
crslstpop(courselistget(courselistcurselection()))
courselistdelete(courselistcurselection())
print(crslst)
print(crslst_in_num)
return
def shwtm(args): # 当选中一门课程,时间listbox改为对应的时间
print('here')
timelistdelete(0, END)
tmlst = crslst[courselistget(courselistcurselection())]
if len(tmlst) != 0:
for time in tmlst:
timelistinsert(END, time)
return
# courselist的选中事件
courselistbind('<<ListboxSelect>>', shwtm)
# 加入课程和删除课程的按钮
addcourse = ttkButton(frame1, text='加入课程', command=isrtcrs)grid(column=0, row=2)
deletcourse = ttkButton(frame1, text='删除课程', command=delcrs)grid(column=0, row=12)
# 已选课程的时间listbox
Label(frame1, text='时间列表')grid(column=1, row=3, sticky=E)
timelist = Listbox(frame1, height=8, width=13, exportselection=False)
timelistgrid(column=1, row=4, columnspan=2, rowspan=8, sticky=E)
def isrttim(): # 加入时间
num = 1
time = []
time_in_num = []
strofod = ''
for day in daylist:
if len(daycurselection()) != 0:
strofod = numtoch[num]
temp = daycurselection()
for cls in temp:
strofod = strofod + ' ' + str(cls + 1)
time_in_numappend((num - 1) 13 + (cls + 1))
num += 1
if len(strofod) != 0:
timeappend(strofod)
strofod = []
if len(time) != 0:
timelistinsert(END, time)
crslst[courselistget(courselistcurselection())]append(time)
crslst_in_num[courselistget(courselistcurselection())]append(time_in_num)
print(crslst)
print(crslst_in_num)
return
def deltim(): # 删除时间
print(timelistcurselection())
for sel in timelistcurselection():
crslst[courselistget(courselistcurselection())]pop(sel)
crslst_in_num[courselistget(courselistcurselection())]pop(sel)
timelistdelete(timelistcurselection())
print(crslst)
print(crslst_in_num)
return
# 加入时间和删除时间的按钮
addtime = ttkButton(frame1, text='加入时间', command=isrttim)grid(column=1, row=2)
delelttime = ttkButton(frame1, text='删除时间', command=deltim)grid(column=1, row=12)
def creatcourselist(): # 建立课程列文本文档
with open('slisttxt', 'w') as slist:
slistwritelines(str(len(crslst_in_num)) + '\n') # 课程数
for crs, tlst in crslst_in_numitems():
slistwritelines(crs + '\n') # 课程名
slistwritelines(str(len(tlst)) + '\n') # 可选时间数
for time in tlst:
slistwritelines(str(len(time)) + '\n') # 某一可选时间的节数
for n in time:
slistwritelines(str(n) + '\n') # 第几节
return
def showoutput(): # 在右侧的选择课表combobox里显示可选课表
filename_list = []
for filename_e in oslistdir('output'):
filename_listappend(filename_e)
outputlist['values'] = filename_list
return
def arrg(): # 排课
print('here')
creatcourselist()
for filename_e in oslistdir('output'):
osremove('output/' + filename_e)
arrangearrangement_mod()
showoutput()
return
# 当用户选择某一可选课表时,展示课表
def showcrslist(args):
print(outputlistget())
for filename_e in oslistdir('output'): # 寻找所选项对应的文件
if filename_e == outputlistget():
with open('output/' + filename_e, 'r') as f_r: # 打开对应的文件
nr = f_rreadlines() # 按行读取内容
k = 0
for day in daylist:
daydelete(0, END) # 删除课表的原有内容
for num in range(1, 14):
# print(nr[k])
# 加入新的内容
if nr[k] == '0\n':
dayinsert(END, '')
else:
dayinsert(END, nr[k]strip())
k += 1
break # 完成之后退出循环
return
# 可选课表combobox选择事件
outputlistbind('<<ComboboxSelected>>', showcrslist)
# 排课的按钮
run = ttkButton(frame1, text='排课', command=arrg)grid(column=0, row=13, columnspan=2)
# frame_search
frame_s = ttkFrame(root, borderwidth=5, relief='sunken')
frame_sgrid(column=2, row=0)
ttkLabel(frame_s, text='搜索课程')grid(column=0, row=0, columnspan=2)
ttkLabel(frame_s, text='课程号:')grid(column=0, row=1, sticky=E)
crs_num = StringVar()
crs_search = ttkEntry(frame_s, textvariable=crs_num, width=12)grid(column=1, row=1, sticky=E)
search_crs = ttkButton(frame_s, text='搜索')grid(column=0, row=2)
addup = ttkButton(frame_s, text='加入')grid(column=1, row=2)
ttkLabel(frame_s, text='课程号:')grid(column=0, row=3, columnspan=2, sticky=W)
ttkLabel(frame_s, text='课程名:')grid(column=0, row=4, columnspan=2, sticky=W)
ttkLabel(frame_s, text='上课时间:')grid(column=0, row=5, columnspan=2, sticky=W)
rootmainloop()
以上就是关于pycharm如何获得星期字符串全部的内容,包括:pycharm如何获得星期字符串、如何批量提取多个文本文件中的某几行到表格(PY或MATLAB)(文件名不连续)(可有现金报酬)、python 搜索一个指定txt 的字符串 并输出其下面两行等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)