我当前有一个文本文件,如下所示:
101, Liberia, Monrovia, 111000, 3200000, Africa, English, Liberia Dollar;
102, Uganda, Kampala, 236000, 34000000, Africa, English and Swahili, Ugandan Shilling;
103, Madagascar, Antananarivo, 587000, 21000000, Africa, Magalasy and Frances, Malagasy Ariary;
我当前正在使用以下代码打印文件:
^{pr2}$我想知道的是,我如何修改一行使用他们的id号(例如101),并保持他们的格式,并根据他们的id号添加或删除行?在
如果您试图保留原始文件顺序,并且能够引用文件中的行进行修改/添加/删除,则将此文件读入
OrderedDict
中可能会有所帮助。在下面的示例中,有很多关于文件完整格式的假设,但它将适用于您的测试用例:^{} 是解决您的需求的强大工具。它提供了轻松处理CSV文件的工具。您可以在
DataFrames
中管理数据。在^{pr2}$
{a4}
我理解你问如何修改一行中的一个词,然后将修改后的行重新插入文件。在
在文件中更改一个单词
为了使用此函数将
^{pr2}$line 3, word 2
设置为Not_Madasgascar
,请按如下方式调用:因为第一行/字是
0
,所以您必须将1
添加到行号/字号中向文件添加新行
为了使用此函数,在末尾添加一行包含单词
this
line
is
at
the
end
,如下所示:有关打开文件的详细信息,请参见here。在
有关读取和修改文件的详细信息,请参阅here。在
相关问题 更多 >
编程相关推荐