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

linux做网站方便吗免费seo工具汇总

linux做网站方便吗,免费seo工具汇总,wordpress文章添加,大型网站开发用的技术目录 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.txy'
with open(file_path) as file_object:

逐行读取

with open(file_path) as file_object:
    for line in file_path:
        print(line.rstrip())

创建一个包含

文件各行内容的列表

filename ='data.txt'
with 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_string
print(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.txt'
with 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 json

number =[2,3,5]
filename = 'number.json'
with 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 json

username = input("你的名字:")
filename = 'username.json'
with open(filename, 'w') as f:
    json.dump(username, f)
    print(f"Hello,{username}!")

你的名字:Ann

Hello,Ann!

"Ann"

向已存储的用户

发出问候

import json
filename = 'username.json'
with open(filename) as f:
    username = json.load(f)
    print(f"欢迎回来,{username}!")

欢迎回来,Ann!

如用户已存储,加载他。如果没有,则提示用户输入并存储。

import json

filename = 'username.json'
try:
    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(f"Hello,{username}!")
else:
    print(f"欢迎回来,{username}!")

3.3重构

重构:代码能够正常运行,但通过将其划分为一系列完成具体工作的函数,还可以进行改进。

作用:让代码更清晰、更利于理解、更容易扩展。

http://www.zhongyajixie.com/news/30791.html

相关文章:

  • 怎么样免费做自己的网站怎么查权重查询
  • 美食网站页面设计伊春seo
  • 北京多用户商城网站建设百度浏览器在线打开
  • 太原网站建设小程序cps广告联盟平台
  • 有没有公司做农副产品网站的百度收录规则2022
  • 做企业福利网站起名网站流量宝
  • 用php做美食网站有哪些seo关键词教程
  • 公司建设网站费用界首网站优化公司
  • 做水果为主的b2c网站有哪些百度百家
  • 南通网站推广知乎关键词排名工具
  • 项目外包合同搜狗搜索引擎优化论文
  • 有什么发布做投标报价的网站免费行情软件网站下载大全
  • 找人做网站需要什么长沙优化排名
  • wordpress上传图片慢上海做网络口碑优化的公司
  • 北京网站怎么建设北京网站外包
  • 高权重网站怎么做爱战网关键词挖掘
  • 网站建设好后为什么要维护方象科技的企业愿景
  • 网站怎么做背景谷歌搜索引擎在线
  • 武汉汉口做网站公司镇江网络
  • 做网站数据库网站搜索优化方法
  • 如何做微信付费视频网站广州专门做seo的公司
  • 顺德网站制作案例信息商业软文
  • 做网站是怎么赚钱吗今天新闻最新消息
  • 厦门软件园多客宝网站开发河南做网站的
  • 中山网站建设文化报价seo的方式有哪些
  • 自适应网站如何做移动适配百度收录怎么做
  • 营销网站的搭建什么是指数基金
  • wordpress 页面指向seo数据监控平台
  • 做网站需要的信息seo快速排名首页
  • 什么是网站维护中seo搜索推广费用多少