当前位置: 首页 > news >正文

建一个免费网站的流程seddog站长之家

建一个免费网站的流程,seddog站长之家,系统软件开发,专业建网站的学校文件的读写#xff1a; with open(filename, a, encodingutf-8) as file:with #xff1a;后面不必写close文件 第二个参数#xff1a;‘a’ 追加#xff1b;‘w’ 写#xff1b;‘r’ 读 encoding ‘utf-8’ 编码格式#xff0c;中文的话一般写上 enter y while ent…文件的读写 with open(filename, a, encodingutf-8) as file:with 后面不必写close文件 第二个参数‘a’ 追加‘w’ 写‘r’ 读 encoding ‘utf-8’ 编码格式中文的话一般写上 enter y while enter y:name input(请输入你的名字)filename guest_record.txtif name ! :with open(filename, a, encodingutf-8) as file:file.write(name \n)print(hello, , name, !)conti ywhile conti y:reason input(你为什么喜欢python)with open(filename, a, encodingutf-8) as file:file.write(reason \n)conti input(继续输入原因吗y/n )enter input(继续访问吗y/n )file.readlines() 文件按行读取存在列表内 file.read() 整体读取 filename pi_digits.txt with open(filename) as pi_file: #with帮助我们适时关闭文件lines pi_file.readlines() #把文件按行存储 pi_str for line in lines:pi_str line.strip() #strip()行左右的空删除 print(pi_str[:7]...) print(len(pi_str)) birthday input(输入你的生日yyyymmdd ) if birthday in pi_str:print(你的生日出现在pi中。) else:print(你的生日不在pi中。)filename learning_python.txt with open(filename) as file:方法1:整个文件一次读取# print(file.read())方法2分行读取# for line in file.readlines():# print(line.strip())方法3line1 file.readlines()for l in line1:print(l.replace(Python, C).strip())tryexceptelsetry代码块出错后执行except部分未出错执行else 错误处理可以使程序不至于崩溃还可以继续运行 print(input 2 numbers to divide, enter q to quit.) while True:first input(\nfirst num: )if first q:breaksecond input(\nsecond num: )try:answer int(first) / int(second)except ZeroDivisionError:print(divide zero!!!)else:print(answer)breakfilename learning_python.txt try:with open(filename) as f_obj:contents f_obj.read() except FileNotFoundError:msg Sorry, the file filename does not exist.print(msg)# pass #一言不发跳过 else:words contents.split()print(the title , filename, has , str(len(words)), words.)while True:print(input 2 nums : )try:a int(input(first num: ))except ValueError:print(请输入数字)continuetry:b int(input(second num: ))except ValueError:print(请输入数字)continueprint(sum of two nums is , ab)json文件存储 json.dump(object, file) json.load(file)import json numbers [2, 3, 5, 7, 11, 13] filename numbers.json with open(filename,w) as file:json.dump(numbers,file)with open(filename) as file:numbers json.load(file) print(numbers)def get_stored_username():filename username.jsontry:with open(filename) as file:username json.load(file)except FileNotFoundError:return Noneelse:return usernamedef get_new_username():username input(What is your name? )filename username.jsonwith open(filename, a) as file:json.dump(username, file)return usernamedef greet_user():username get_stored_username()if username:print(Welcome back, , username, !)else:get_new_username()print(Well remember you when you come back, , username, !)greet_user()import json def get_num():try:global favor_numfavor_num int(input(输入你喜欢的数字))except ValueError:print(你输入的不是数字请重新输入)get_num()return favor_numdef store_num(num):filename user_favor_num.jsonwith open(filename, a) as file:json.dump(num, file)def getAndStore():store_num(get_num())def print_num():filename user_favor_num.jsontry:with open(filename) as file:num json.load(file)except FileNotFoundError:getAndStore()else:print(i know your favorite number! it is , num)print_num()
http://www.zqtcl.cn/news/491183/

相关文章:

  • 正规的网店平台有哪些北京公司排名seo
  • 网页制作素材库哪个网站上海门户网站开发
  • 做网站 分辨率应该是多少做阿里巴巴网站要多少钱
  • 有专业做外贸的网站吗千岛湖网站建设
  • 百度怎么做开锁网站中国咖啡网站建设方案
  • 新网站不被收录郑州网站建设培训学校
  • 网站群建设意见征集北京做网站报价
  • 网站建设开发费会计处理山东省住房和城乡建设厅二建查询
  • 市工商局网站建设情况襄阳网站seo诊断
  • 动漫做那个视频网站单网页网站如何做
  • 企业网站名是什么意思广州公共交易中心
  • 做网站那家好沈阳做网站公司哪家好
  • 现在做一个网站大概多少钱中国住房城乡建设部网站
  • 高端企业网站建设核心秦皇岛网站制作人才招聘
  • 网站制作花多少钱简历模板表格
  • 泰安专业网站开发公司网页设计师常逛网站
  • 百度收录万网空间的网站需要多久推广seo网站
  • 个体工商户可以做网站备案吗微信app下载安装官方版2023
  • 内贸在什么网站做做网站需要提供哪些信息
  • 物流网站怎么做推广网页程序开发语言
  • 静态网站跟动态网站开发的层次
  • 公司购买网站怎么做分录被k掉的网站怎么做才能有收录
  • 网页制作相关网站网络卖货平台有哪些
  • 国内网站都要备案吗快速做网站的软件
  • 遂宁市住房和城乡建设局网站自己的网站怎么做美工
  • 资阳网站建设公司中国菲律宾概念股
  • 网站优化报价wordpress 获取别名
  • 自适应网站如何做mip微信网站公司
  • 网站建设改版升级wordpress 艺术家
  • 百度怎么网站排名python做网站的开发