这个是用 excel里面的 去掉空格最后导出的一个list:

原本是有空格的

后面是抵消了中间的空格。

然后 这里侧重说一下什么是split()函数

语法:str.split(str="",num=string.count(str))[n]

参数说明:

str:表示为分隔符,默认为空格,但是不能为空(‘’)。若字符串没有分隔符,则把整个字符串作为列表的一个元素。

num:表示分割次数。如果参在参数num, 则仅分隔成num+1个字符串,并且每一个字符串可以赋给新的变量。

[n]:表示选取第n个分片

举个栗子:

str = "Line1-abcdef \nLine2-abc \nLine4-abcd"

print(str.split())

然后导出来的就是分隔符

后面可以写数字 1,意思是分隔成两个参数

还有一个栗子:

就是以#号为分隔符,指定第二个参数为1,其实就是分隔成两个参数列表。

当前目录;

import os
import xlwt
a = os.getcwd() #获取当前目录
print(a)#打印当前目录
os.chdir(r'C:\Users\yjiang3\Documents\YANNI JIANG')
print(a)
with open('11.txt','r') as raw:
for line in raw:
print(line)
with open('11.txt','r',encoding = 'utf-8') as fr, open('10.txt','w',encoding='utf-8') as fd:
for text in fr.readlines():
if text.split():
fd.write(text)
print('success') book = xlwt.Workbook(encoding='utf-8',style_compression=0)
sheet = book.add_sheet('10', cell_overwrite_ok=True) sheet.write(0, 0, 'x')
sheet.write(0, 1, 'Y') n=1
with open('10.txt','r+') as fd:
for text in fd.readlines():
x=text.split()[0]
y=text.split()[0] print(x.split('w'))
print(y.split('w')) sheet.write(n,0,x.split('w')[0])
sheet.write(n,1,y.split('w')[0]) n = n+1 book.save(r'C:\Users\yjiang3\Documents\YANNI JIANG\10.xls')

最新文章

  1. Android Weekly Notes Issue #233
  2. bzoj2141 树状数组套Treap树
  3. C#并行编程-线程同步原语
  4. 找到SQL Server数据库历史增长信息
  5. ASP.NET MVCでResponse Headerのサーバーバージョンをどうやって隠しますか?
  6. Object C学习笔记13-Dictionary字典
  7. 利用URLRewriter.dll 实现ASP.NET实现伪静态
  8. javascript form验证、完善 第24节
  9. 一步步学习ASP.NET MVC3 (6)——@helper,@functions
  10. 知识点整理之Java的Cookie操作
  11. 我和ASP.NET MVC有个约会
  12. TWRP-recovery中文界面安装方法[转]
  13. tomcat------https单向认证和双向认证
  14. 实现简答LinkedList
  15. 单例模式 GetInstance()
  16. CSipSimple最新版本号
  17. C++ enum用法小技巧
  18. 实验吧 deeeeeeaaaaaadbeeeeeeeeeef-20
  19. iOS webview 获取html中的图片地址
  20. [工作积累] UE4 并行渲染的同步 - Sync between FParallelCommandListSet & FRHICommandListImmediate calls

热门文章

  1. yolov5查看训练日志图片和直方图(包括稀疏训练bn直方图)
  2. python exec_command 命令无效的原因
  3. Shiro 身份认证绕过漏洞 CVE-2022-32532
  4. c++ 引用 指针。
  5. Vue3学习笔记
  6. yii框架中 不能正确正常使用phpredis 路径安装好后还是报 Class yii\redis\Connection does not exist!
  7. 87、linux root 密码忘记了
  8. vue中标签的替换以及scoped实现css对当前文件起作用的原理
  9. git stash (pycharm/vscode的gui演示)
  10. 三种将list转换为map的方法