如何将特定值增加 1

How to increase a specific value by 1

我有一个值列表

(1, 90, 1, 0);
(1, 29, 1, 0);
(1, 220, 1, 0);
(1, 218, 1, 0);
(1, 312, 1, 0);
(1, 13, 1, 0);

我想使用 Notepad++ 创建这些值中的每一个的副本,并且每次都将第一个值增加一个。 例如文件应该是

(1, 90, 1, 0);
(1, 29, 1, 0);
(1, 220, 1, 0);
(1, 218, 1, 0);
(1, 312, 1, 0);
(1, 13, 1, 0);
(2, 90, 1, 0);
(2, 29, 1, 0);
(2, 220, 1, 0);
(2, 218, 1, 0);
(2, 312, 1, 0);
(2, 13, 1, 0);
(3, 90, 1, 0);
(3, 29, 1, 0);
(3, 220, 1, 0);
(3, 218, 1, 0);
(3, 312, 1, 0);
(3, 13, 1, 0);

以此类推,约13000次

有办法吗?

使用 Python 你可以试试:

filename = "yourFileName.txt"  # the file where you want to have the values
n = 13_000  # number of times each should be printed, you suggested 13,000
lists = [[1, 90, 1, 0],
         [1, 29, 1, 0],
         [1, 220, 1, 0],
         [1, 218, 1, 0],
         [1, 312, 1, 0],
         [1, 13, 1, 0]]

with open(filename, "w") as file:
    for _ in range(n)
        for l in lists:
            file.write("({});\n".format(', '.join(str(x) for x in l)))
            l[0] += 1

确保文件已经存在,否则你会得到一个错误。编辑:那不是真的,文件不必存在于追加 "a" 或写入 "w" 模式;感谢@DarrylG)

此外,我假设您希望在值和分号两边加上括号,因此它们也包含在文件中。

因此您的文件看起来完全像这样:

(1, 90, 1, 0);
(1, 29, 1, 0);
(1, 220, 1, 0);
(1, 218, 1, 0);
(1, 312, 1, 0);
(1, 13, 1, 0);
(2, 90, 1, 0);
(2, 29, 1, 0);
(2, 220, 1, 0);
(2, 218, 1, 0);
(2, 312, 1, 0);
(2, 13, 1, 0);
(3, 90, 1, 0);
(3, 29, 1, 0);
(3, 220, 1, 0);
(3, 218, 1, 0);
(3, 312, 1, 0);
(3, 13, 1, 0);
...