python - 使用 python 编写文本文件

标签 python python-2.7 python-3.x

如何使用 python 将下面的测试准确地写入文本文件?当我必须编写多个具有不同参数的文本文件时,这是必需的。

MY_FILE = E:\test.jpg

BAND_SUBSET = ( 1 0 0 )

SPATIAL_SUBSET1 = ( 25.0 50.0 )
SPATIAL_SUBSET2 = ( 25.0 50.0 )

PARA1 = (
 0.0 0.0 0.0
 0.0 0.0 0.0 )

END = END

最佳答案

with open('somefile.txt', 'w') as fp:
  fp.write('''MY_FILE = E:\test.jpg

BAND_SUBSET = ( 1 0 0 )

SPATIAL_SUBSET1 = ( 25.0 50.0 )
SPATIAL_SUBSET2 = ( 25.0 50.0 )

PARA1 = (
 0.0 0.0 0.0
 0.0 0.0 0.0 )

END = END''')

关于python - 使用 python 编写文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17828487/

相关文章:

python - 为什么coverage.py 不能正确测量Django 的runserver 命令?

python - 如何比较hdfs文件和unix文件?

Python提示_工具包: Pick best fuzzy match when the user presses enter

python - Python 3.4'无法分配给函数调用

python - 了解 python 2.7 email.feedparser Feedparser __init__ 函数

python-3.x - 使用 livy 向 AWS EMR 提交具有虚拟环境的 pyspark 作业

python - DLL 加载失败 : The specified procedure could not be found. win32api、sys、os

python - 使用内置文件表单上传 web.py 文件

python - pytesseract-没有这样的文件或目录错误

python - Dask:为什么CPU使用率突然下降?