python - 在文本文件的行中查找位置
问题描述
我试图在某个字符串的文件中找到位置。我知道如何找到行,但我需要找到字符串行中的确切位置。
curzt2 = open("C:\\Users\\User\\Desktop\\world\\program\\maps\\default\\world"+str(i)+".ZT2", "r+")
content = curzt2.read()
#find the line in the file
curzt2line = content.index('terrFile="terrain.dat"')
curzt2.seek(curzt2line, 0)
curzt2.write(str(i))
curzt2.close()
例如在这个文件中我想读到这一行
<ZTWorldMgr version="0" environment="world/environments/env1wetlands_medium.xml" tankenv="" terrFile="terrain.dat" camPitch="-0.000000" camYaw="-2.233864" camRoll="-0.000000" loadCount="1453" safehandledobjid="3">
并将terrain.dat 更改为terrai+str(i)+.dat
解决方案
推荐阅读
- list - Prolog中类似于Transpose的谓词的实现
- python - 何时在 Python 中使用线程本地内存?
- android - 拦截 ConnectivityManger requestNetwork 新对话框上的取消按钮按下,API 29
- html - div 如何在网格布局中保持其最小高度?
- sftp - pscp 可以传输到临时文件并在完成后重命名吗?
- javascript - 如何从反应的下拉列表中获取价值?
- mysql - 带有secure_file_priv问题的MySQL数据导入
- javascript - 在 React JS 中显示 Firebase 数组对象的问题
- php - 使用 OpenSSL 的 EC 公钥加密
- reactjs - AgGrid 未填充所有列