在B站自学Python
站主:Python_子木
授课:杨淑娟
平台: 马士兵教育
python: 3.9.9
#安装PyInstaller
pip install PyInstaller
#-F打包exe文件,stusystem\stusystem.py到py的路径,可以是绝对路径,可以是相对路径
pyinstaller -F stusystem\stusystem.py
import os.path
filename='student.txt'
def main():
while True:
menu()
choice = int(input('请选择'))
if choice in range(8):
if choice==0:
answer=input('您确定要退出系统吗?y/n')
if answer.lower()=='y':
print('谢谢您的使用!')
break #退出系统
else:
continue
if choice==1:
insert()
if choice==2:
search()
if choice==3:
delete()
if choice==4:
modify()
if choice==5:
sort()
if choice==6:
total()
if choice==7:
show()
else:
print('无此功能,请按菜单重新选择')
def menu():
print('=========================学生信息管理系统============================')
print('-----------------------------功能菜单------------------------------')
print('\t\t\t\t\t\t1.录入学生信息')
print('\t\t\t\t\t\t2.查找学生信息')
print('\t\t\t\t\t\t3.删除学生信息')
print('\t\t\t\t\t\t4.修改学生信息')
print('\t\t\t\t\t\t5.排序')
print('\t\t\t\t\t\t6.统计学生总人数')
print('\t\t\t\t\t\t7.显示所有学生信息')
print('\t\t\t\t\t\t0.退出')
print('------------------------------------------------------------------')
def insert():
student_list=[]
while True:
id=input('请输入ID(如1001):')
if not id:
break
name=input('请输入姓名:')
if not name:
break
try:
english=int(input('请输入英语成绩:'))
python=int(input('请输入Python成绩:'))
java=int(input('请输入Java成绩:'))
except:
print('输入无效,不是整数类型,请重新输入')
continue
#将录入的学生保存到字典中
student={'id':id,'name':name,'english':english,'python':python,'java':java}
#将学生信息添加到列表中
student_list.append(student)
answer=input('是否继续添加?y/n')
if answer.lower()=='y':
continue
else:
break
#调用save()函数
save(student_list)
print('学生信息录入完毕!!!')
def save(lst):
try:
stu_txt=open(filename,'a',encoding='utf-8')
except:
stu_txt=open(filename,'w',encoding='utf-8')
for item in lst:
stu_txt.write(str(item)+'\n')
stu_txt.close()
def search():
student_query=[]
while True:
id=''
name=''
if os.path.exists(filename):
mode=input('按ID查找请输入1,按姓名查找请输入2:')
if mode=='1':
id=input('请输入学生ID:')
elif mode=='2':
name=input('请输入学生姓名:')
else:
print('您输入有误,请重新输入')
continue
with open(filename,'r',encoding='utf-8') as rfile:
student=rfile.readlines()
for item in student:
d=dict(eval(item))
if id!='':
if d['id']==id:
student_query.append(d)
elif name!='':
if d['name']==name:
student_query.append(d)
#显示查询结果
show_student(student_query)
#清空列表
student_query.clear()
answer=input('是否要继续查询?y/n\n')
if answer.lower()=='y':
continue
else:
break
else:
print('暂未保存学生信息')
return
def show_student(lst):
if len(lst)==0:
print('没有查询到学生信息,无数据显示!!!')
return
#定义标题显示格式
format_title='{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}\t'
print(format_title.format('ID','姓名','英语成绩','Python成绩','Java成绩','总成绩'))
#定义内容显示格式
format_data='{:^6}\t{:^12}\t{:^8}\t{:^8}\t{:^8}\t{:^8}\t'
for item in lst:
print(format_data.format(item.get('id'),
item.get('name'),
item.get('english'),
item.get('python'),
item.get('java'),
int(item.get('english'))+int(item.get('python'))+int(item.get('java'))
))
def delete():
while True:
student_id=input('请输入要删除的学生的ID:')
if student_id!='':
if os.path.exists(filename):
with open(filename,'r',encoding='utf-8') as file:
student_old=file.readlines()
else:
student_old=[]
flag=False #删除标记
if student_old:
with open(filename,'w',encoding='utf-8') as wfile:
d={}
for item in student_old:
d=dict(eval(item)) #将字符串转字典
if d['id']!=student_id:
wfile.write(str(d)+'\n')
else:
flag=True
if flag:
print(f'id为{student_id}的学生信息已被删除')
else:
print(f'没有找到ID为{student_id}的学生信息')
else:
print('无学生信息')
break
show() #删除之后要重新显示所有学生信息
answer=input('是否继续删除?y/n')
if answer.lower()=='y':
continue
else:
break
def modify():
show()
if os.path.exists(filename):
with open(filename,'r',encoding='utf-8') as rfile:
student_old=rfile.readlines()
else:
return
student_id=input('请输入要修改的学员的ID:')
with open(filename,'w',encoding='utf-8') as wfile:
for item in student_old:
d=dict(eval(item))
if d['id']==student_id:
print('找到学生信息,可以修改他的相关信息了!')
while True:
try:
d['name']=input('请输入姓名:')
d['english']=input('请输入英语成绩:')
d['python']=input('请输入python成绩:')
d['java']=input('请输入java成绩:')
except:
print('您的输入有误,请重新输入!!!')
else:
break
wfile.write(str(d)+'\n')
print('修改成功!')
show()
else:
print(f'未找到ID为{student_id}的学生信息')
wfile.write(str(d)+'\n')
answer=input('是否继续修改其他学生信息?y/n\n')
if answer.lower()=='y':
modify()
def sort():
show()
if os.path.exists(filename):
with open(filename,'r',encoding='utf-8') as rfile:
student_list=rfile.readlines()
student_new=[]
for item in student_list:
d=dict(eval(item))
student_new.append(d)
else:
return
asc_or_desc=input('请选择(0.升序,1.降序):')
if asc_or_desc=='0':
asc_or_desc_bool=False
elif asc_or_desc=='1':
asc_or_desc_bool=True
else:
print('您的输入有误,请重新输入')
sort()
mode=input('请选择排序方式(1.按英语成绩排序 2.按Python成绩排序 3.按Java成绩排序 4.按总成绩排序)')
if mode=='1':
student_new.sort(key=lambda x:int(x['english']),reverse=asc_or_desc_bool)
elif mode=='2':
student_new.sort(key=lambda x:int(x['python']),reverse=asc_or_desc_bool)
elif mode=='3':
student_new.sort(key=lambda x:int(x['java']),reverse=asc_or_desc_bool)
elif mode=='4':
student_new.sort(key=lambda x:int(x['english'])+int(x['python'])+int(x['java']),reverse=asc_or_desc_bool)
else:
print('您的输入有误,请重新输入')
sort()
show_student(student_new)
def total():
if os.path.exists(filename):
with open(filename,'r',encoding='utf-8') as rfile:
students=rfile.readlines()
if students:
print(f'一共有{len(students)}名学生')
else:
print('还没有录入学生信息')
else:
print('暂未保存数据信息...')
def show():
student_list = []
if os.path.exists(filename):
# 定义标题显示格式
format_title = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}\t'
print(format_title.format('ID', '姓名', '英语成绩', 'Python成绩', 'Java成绩', '总成绩'))
with open(filename,'r',encoding='utf-8') as rfile:
student = rfile.readlines()
for item in student:
d = dict(eval(item))
student_list.append(d)
if len(student_list)==0:
format_nodata = '{:^6}'
print(format_nodata.format('无数据'))
# 定义内容显示格式
format_data = '{:^6}\t{:^12}\t{:^8}\t{:^8}\t{:^8}\t{:^8}\t'
for item in student_list:
print(format_data.format(item.get('id'),
item.get('name'),
item.get('english'),
item.get('python'),
item.get('java'),
int(item.get('english')) + int(item.get('python')) + int(item.get('java'))
))
student_list.clear()
else:
print('暂未保存过数据!!!')
if __name__ == '__main__':
main()
我正在使用i18n从头开始构建一个多语言网络应用程序,虽然我自己可以处理一大堆yml文件,但我说的语言(非常)有限,最终我想寻求外部帮助帮助。我想知道这里是否有人在使用UI插件/gem(与django上的django-rosetta不同)来处理多个翻译器,其中一些翻译器不愿意或无法处理存储库中的100多个文件,处理语言数据。谢谢&问候,安德拉斯(如果您已经在rubyonrails-talk上遇到了这个问题,我们深表歉意) 最佳答案 有一个rails3branchofthetolkgem在github上。您可以通过在Gemfi
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我安装了ruby版本管理器,并将RVM安装的ruby实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby。有没有办法让emacs像shell一样尊重ruby的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Pythonconditionalassignmentoperator对于这样一个简单的问题表示歉意,但是谷歌搜索||=并不是很有帮助;)Python中是否有与Ruby和Perl中的||=语句等效的语句?例如:foo="hey"foo||="what"#assignfooifit'sundefined#fooisstill"hey"bar||="yeah"#baris"yeah"另外,类似这样的东西的通用术语是什么?条件分配是我的第一个猜测,但Wikipediapage跟我想的不太一样。
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
是否有简单的方法来更改默认ISO格式(yyyy-mm-dd)的ActiveAdmin日期过滤器显示格式? 最佳答案 您可以像这样为日期选择器提供额外的选项,而不是覆盖js:=f.input:my_date,as::datepicker,datepicker_options:{dateFormat:"mm/dd/yy"} 关于ruby-on-rails-事件管理员日期过滤器日期格式自定义,我们在StackOverflow上找到一个类似的问题: https://s
电脑0x0000001A蓝屏错误怎么U盘重装系统教学分享。有用户电脑开机之后遇到了系统蓝屏的情况。系统蓝屏问题很多时候都是系统bug,只有通过重装系统来进行解决。那么蓝屏问题如何通过U盘重装新系统来解决呢?来看看以下的详细操作方法教学吧。 准备工作: 1、U盘一个(尽量使用8G以上的U盘)。 2、一台正常联网可使用的电脑。 3、ghost或ISO系统镜像文件(Win10系统下载_Win10专业版_windows10正式版下载-系统之家)。 4、在本页面下载U盘启动盘制作工具:系统之家U盘启动工具。 U盘启动盘制作步骤: 注意:制作期间,U盘会被格式化,因此U盘中的重要文件请注