我需要将以下行添加到配置文件的末尾:include"/configs/projectname.conf"到一个名为lighttpd.conf的文件我正在考虑使用sed来执行此操作,但我不知道如何操作。如果该行不存在,我将如何只插入它? 最佳答案 保持简单:)grep+echo就足够了:grep-qxF'include"/configs/projectname.conf"'foo.bar||echo'include"/configs/projectname.conf"'>>foo.bar-q安静-x匹配整行-F模式是纯字符串https
如何在现代Python中将一行写入文件?我听说这已被弃用:print>>f,"hithere"另外,"\n"是否适用于所有平台,或者我应该在Windows上使用"\r\n"吗? 最佳答案 这应该很简单:withopen('somefile.txt','a')asthe_file:the_file.write('Hello\n')来自文档:Donotuseos.linesepasalineterminatorwhenwritingfilesopenedintextmode(thedefault);useasingle'\n'inste
如何在现代Python中将一行写入文件?我听说这已被弃用:print>>f,"hithere"另外,"\n"是否适用于所有平台,或者我应该在Windows上使用"\r\n"吗? 最佳答案 这应该很简单:withopen('somefile.txt','a')asthe_file:the_file.write('Hello\n')来自文档:Donotuseos.linesepasalineterminatorwhenwritingfilesopenedintextmode(thedefault);useasingle'\n'inste