保存/加载字符串列表和文件的最佳方法将同时由两个Python脚本操作

时间:2021-10-25 11:49:21

I will create two Python scripts. One will generate strings and save them to a file. The other will traverse through the list of string from the top down, do operations on each string and then delete the string when done.

我将创建两个Python脚本。一个将生成字符串并将它们保存到文件中。另一个将从上到下遍历字符串列表,对每个字符串执行操作,然后在完成时删除该字符串。

I would like to know which file type can best satisfy this purpose (e.g. pickle, json, plain text, csv,..)?

我想知道哪种文件类型最能满足这个目的(例如pickle、json、plain text、csv…)?

1 个解决方案

#1


1  

If the first script just writes the file once and then at some point the second script has to read it, I would use csv (or just plain text and the elements separated by a coma).

如果第一个脚本只写一次文件,然后在某个时候第二个脚本必须读取它,我将使用csv(或者只是纯文本和元素之间的昏迷)。

If the second file has to read periodically the strings that the first writes I would use a socket to send it to the second script.

如果第二个文件必须定期读取第一个写入的字符串,我将使用套接字将其发送到第二个脚本。

#1


1  

If the first script just writes the file once and then at some point the second script has to read it, I would use csv (or just plain text and the elements separated by a coma).

如果第一个脚本只写一次文件,然后在某个时候第二个脚本必须读取它,我将使用csv(或者只是纯文本和元素之间的昏迷)。

If the second file has to read periodically the strings that the first writes I would use a socket to send it to the second script.

如果第二个文件必须定期读取第一个写入的字符串,我将使用套接字将其发送到第二个脚本。