首页 技术 正文
技术 2022年11月10日
0 收藏 613 点赞 2,925 浏览 635 个字
 # coding=utf-8 # !/usr/bin/python # -*- coding: UTF-8 -*- import io import os def file_chance():                    #修改文件内某一行的内容     f = open('text1', 'r')     w = open('text2', 'w')     n = 0     for i in f:         n += 1         if n == 3:             i = "yes,i am\n"         w.write(i)     f.close()     w.close()     os.remove('text1')     os.rename('text2', 'text1') def file_del():                       #删除文件内容     f = open('text1','w')     f.close() def file_write():                     #文件写入20行you are a winner     f = open('text1', 'w')     for i in range(20):         f.write('you are a winner\n')     f.close() file_del() file_write() file_chance() ''' 总结: "i=' '.join(['123456'])" = "i+‘123456’" f.tell() 指针的位置 f.read(*) 读取*个字符,中文占3个位置,英文占一共位置 f.seek(*) 改变指针的位置 r+模式 tell在最末尾的位置 w+模式 tell在第一位置且对象内容为空 a+模式 tell在末尾位置 写/删:w/w+/a/a+ 改:读取一个文件,写入另一个文件,将读取文件删除,将写入文件重新命名为读取文件 '''
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295