回答編集履歴
1
追記
test
CHANGED
@@ -7,3 +7,43 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
それだけの修正だと期待通りの動作にはならないと思いますが。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
#追記
|
14
|
+
|
15
|
+
おそらく、こういうことがやりたいのでしょう。
|
16
|
+
|
17
|
+
```Python
|
18
|
+
|
19
|
+
file_name = "Parts_Inventory3.txt"
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
with open(file_name) as f:
|
24
|
+
|
25
|
+
data = f.read()
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
SID = input("enter partID:")
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
for data_line in data.splitlines():
|
34
|
+
|
35
|
+
if data_line.find(SID) >= 0:
|
36
|
+
|
37
|
+
print(data_line)
|
38
|
+
|
39
|
+
new = input ("enter new quantity:")
|
40
|
+
|
41
|
+
data = data.replace(data_line, SID +" : "+ new)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
with open(file_name ,"w") as f:
|
46
|
+
|
47
|
+
f.write(data)
|
48
|
+
|
49
|
+
```
|