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

做网站的策划书网站地址和网页地址区别

做网站的策划书,网站地址和网页地址区别,西安企业建站,北京公司注册地址出租目录 1.从文件中读取数据 2.写入文件 3.存储数据 3.1使用json.dump()和json.load() 3.2保存和读取用户生成的数据 3.3重构 1.从文件中读取数据 读取整个文件 with open(data.txt) as file_object: contents file_object.read()print(contents)print(contents.rstrip…目录 1.从文件中读取数据 2.写入文件 3.存储数据 3.1使用json.dump()和json.load() 3.2保存和读取用户生成的数据 3.3重构 1.从文件中读取数据 读取整个文件 with open(data.txt) as file_object:    contents file_object.read()print(contents)print(contents.rstrip()) #删除字符串末尾空白 文件路径 with open(text_files//data.txt) as file_object: file_path /home/eh/data.txywith open(file_path) as file_object: 逐行读取 with open(file_path) as file_object:     for line in file_path:        print(line.rstrip()) 创建一个包含 文件各行内容的列表 filename data.txtwith open(filename) as file_object:    lines file_object.readlines()for line in lines:    print(line.rstrip()) 使用文件内容 data_string for line in lines:    data_string line.rstrip() #循环加入data_stringprint(data_string) 打印圆周率小数点后10位数 3.1415926535… print(f{data_string[:12]}…) 数列中是否包含这个字段 …… my_data input(输入数字,字符串是否有这个数)if my_data in data_string:    print(你的数字在这个字符串中)else:    print(你的数字不在这个字符串中) 2.写入文件 写入空文件 file abc.txtwith open(file) as file_object:    file_object.write(我是一个蘑菇。) 写入多行open(file, w) with open(file, w) as file_object:     file_object.write(我是一个蘑菇。\n)    file_object.write(我不是一个蘑菇。\n) 附加到文件open(file, a) with open(file, a) as file_object:     file_object.write(我是一个蘑菇。\n) 3.存储数据 json能够将简单的python数据结构转储到文件中 3.1使用json.dump()和json.load() json.dump() 可以接受两个实参 import jsonnumber [2,3,5]filename number.jsonwith open(filename, w) as f:    json.dump(number, f) number.json文件中 [2, 3, 5] json.load() 将列表 读取到内存中 with open(filename, w) as f:    numbers  json.load(f)print(numbers) 3.2保存和读取用户生成的数据 代码 输出 username.json文件 存储用户 import jsonusername input(你的名字)filename username.jsonwith open(filename, w) as f:    json.dump(username, f)    print(fHello,{username}!) 你的名字Ann Hello,Ann! Ann 向已存储的用户 发出问候 import jsonfilename username.jsonwith open(filename) as f:    username json.load(f)    print(f欢迎回来{username}!) 欢迎回来Ann! 如用户已存储加载他。如果没有则提示用户输入并存储。 import jsonfilename username.jsontry:     with open(filename) as f:    #尝试打开username.json        username json.load(f)    #如果username.json存在except FileNotFoundError:    #username.json不存在    username input(你的名字)     with open(username, w) as f:        json.dump(username, f)    #存储        print(fHello,{username}!)else:    print(f欢迎回来{username}!) 3.3重构 重构代码能够正常运行但通过将其划分为一系列完成具体工作的函数还可以进行改进。 作用让代码更清晰、更利于理解、更容易扩展。
http://www.zqtcl.cn/news/93787/

相关文章:

  • 金华专业做网站公司湖南网站建设服务
  • 企业网站设计沈阳苏宁电器网站建设特点分析
  • 建设工程类公司网站易语言可以做api网站对接吗
  • 青岛做网站皆赴青岛博wordpress 数据库 备份
  • 外贸公司网站空间哈尔滨seo优化专注
  • 建筑行业综合查询平台优化推广联盟
  • 北京管庄网站建设公司开平网站制作
  • 如何做销售直播网站最专业网站建设
  • 太原市住房和城乡建设局的网站首页网络推广服务外包公司
  • 湘icp备 网站建设 农业 湖南稿定设计免费版
  • 公司网站推广方法陕西省住房建设厅官网
  • 网站关键词排名突然没了无锡企业网站建设报价
  • 找做网站的人网站改版 301跳转
  • 网站备案一次就可以了吧营销管理培训课程
  • 怎么做网站背景专做民宿预定的网站
  • wordpress安装谷歌分析代码建网站seo
  • 百度外卖网站建设与维护方法建设 银行网网站
  • 小程序开发定制开发上海优化价格
  • 来宾住房和城乡建设局网站做外贸推广要做哪些平台
  • 无锡建设网站制作wordpress 知乎
  • 动漫网站源码免费怎么怎么做网站
  • 和两个黑人同时做网站中工互联网站建设
  • windows10PHP 网站建设app应用分发平台开发
  • 中唯建设工程有限公司网站做网站页面对PS切图
  • 个人网页制作成品欣赏seo网站沙盒期
  • 亚马逊站外推广网站怎么做制作营销网站模板免费下载
  • 加拿大网站后缀设计师互联网
  • 做物流的网站有哪些内容共同建设网站心得
  • 主题资源网站建设什么网站做污水处理药剂的好
  • 河北建设厅网站修改密码在哪58同城宿迁二手房