1 Star 1 Fork 0

三体自动化技术协会/草稿本

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
file_split.tm 5.11 KB
一键复制 编辑 原始数据 按行查看 历史
zhangshenhua 提交于 2023-09-04 15:33 . new file: file_split.tm
<TeXmacs|2.1.1>
<style|<tuple|generic|chinese|framed-session|python>>
<\body>
<\session|python|default>
<\output>
Python 3.11.0 [c:\\python311\\python.exe]\
Python plugin for TeXmacs.
Please see the documentation in Help -\<gtr\> Plugins -\<gtr\> Python
</output>
<\input>
\<gtr\>\<gtr\>\<gtr\>\
<|input>
import math
</input>
<\input>
\<gtr\>\<gtr\>\<gtr\>\
<|input>
s=[x for x in range(100)]
</input>
<\unfolded-io>
\<gtr\>\<gtr\>\<gtr\>\
<|unfolded-io>
s
<|unfolded-io>
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99]
</unfolded-io>
<\unfolded-io>
\<gtr\>\<gtr\>\<gtr\>\
<|unfolded-io>
m,n=31,7;[[i for i in range(m) if (i+j) % n==0] for j in range(n)]
<|unfolded-io>
[[0, 7, 14, 21, 28], [6, 13, 20, 27], [5, 12, 19, 26], [4, 11, 18, 25],
[3, 10, 17, 24], [2, 9, 16, 23, 30], [1, 8, 15, 22, 29]]
</unfolded-io>
<\unfolded-io>
\<gtr\>\<gtr\>\<gtr\>\
<|unfolded-io>
m,n=31,7;[[i for i in range(m) if (i+j) % n ==0] for j in range(n)]
<|unfolded-io>
[[0, 7, 14, 21, 28], [6, 13, 20, 27], [5, 12, 19, 26], [4, 11, 18, 25],
[3, 10, 17, 24], [2, 9, 16, 23, 30], [1, 8, 15, 22, 29]]
</unfolded-io>
<\input>
\<gtr\>\<gtr\>\<gtr\>\
<|input>
import csv
</input>
<\unfolded-io>
\<gtr\>\<gtr\>\<gtr\>\
<|unfolded-io>
with open(r'C:\\Users\\zhang\\test.txt', newline='') as csvfile:
\ \ \ \ dialect = csv.Sniffer().sniff(csvfile.read(1024*1024))
\ \ \ \ csvfile.seek(0)
\ \ \ \ reader = csv.reader(csvfile, dialect)
\ \ \ \ # ... process CSV file contents here ...<text|>
\ \ \ \ for row in reader:
\ \ \ \ \ \ \ \ print(row)
\ \ \ \ print(reader.line_num)
<|unfolded-io>
\;
</unfolded-io>
<\unfolded-io>
\<gtr\>\<gtr\>\<gtr\>\
<|unfolded-io>
file_path = r'C:\\Users\\zhang\\test.txt' \
n = 7
with open(file_path, "r") as file:
\ \ \ \ lines = file.readlines()
\ \ \ \ lines = [line.strip() for line in lines]
\ \ \ \ m = len(lines);
\ \ \ \ print([[lines[i]\
\ \ \ \ \ \ \ \ \ \ \ \ for i in range(m) if (i+j) % n ==0]\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ for j in range(n)])
\ \ \ \ for j in range(n):
\ \ \ \ \ \ \ \ for i in range(m):
\ \ \ \ \ \ \ \ \ \ \ \ if (i+j) % n == 0:
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ print(lines[i])
\ \ \ \ \ \ \ \
#print(lines)
\;
\;
<|unfolded-io>
[['0,', '7,', '14,', '21,', '28,'], ['6,', '13,', '20,', '27,'], ['5,',
'12,', '19,', '26,'], ['4,', '11,', '18,', '25,'], ['3,', '10,', '17,',
'24,', ''], ['2,', '9,', '16,', '23,', '30,'], ['1,', '8,', '15,',
'22,', '29,']]
0,
7,
14,
21,
28,
6,
13,
20,
27,
5,
12,
19,
26,
4,
11,
18,
25,
3,
10,
17,
24,
\;
2,
9,
16,
23,
30,
1,
8,
15,
22,
29,
</unfolded-io>
<\textput>
\;
</textput>
<\unfolded-io>
\<gtr\>\<gtr\>\<gtr\>\
<|unfolded-io>
import os
work_dir = r'C:\\path\\to\\work\\dir'
file_name = r'input.txt' \
n = 7
\;
os.chdir(work_dir)
\;
with open(file_name, "r") as file:
\ \ \ \ lines = file.readlines()
\ \ \ \ lines = [line.strip() for line in lines]
\ \ \ \ m = len(lines);
\;
\ \ \ \ for j in range(n):
\ \ \ \ \ \ \ \ with open(os.path.join(work_dir, str(j)+'.txt'), "w")
as ofile:
\ \ \ \ \ \ \ \ \ \ \ \ for i in range(m):
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if (i+j) % n == 0:
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ print(lines[i])
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ofile.write(lines[i]+'\\n')
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
<|unfolded-io>
0,
7,
14,
21,
28,
6,
13,
20,
27,
5,
12,
19,
26,
4,
11,
18,
25,
3,
10,
17,
24,
\;
2,
9,
16,
23,
30,
1,
8,
15,
22,
29,
</unfolded-io>
<\input>
\<gtr\>\<gtr\>\<gtr\>\
<|input>
\;
</input>
</session>
</body>
<\initial>
<\collection>
<associate|indent-indentation|1tab>
<associate|page-medium|paper>
</collection>
</initial>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wu-org/draftbook.git
git@gitee.com:wu-org/draftbook.git
wu-org
draftbook
草稿本
master

搜索帮助