質問編集履歴

4

aaa

2020/09/18 14:50

投稿

kananananana
kananananana

スコア6

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  そのままの形を保ち書き換えたいです。
4
4
 
5
- partID = BR00?
5
+ partID = BR001
6
6
 
7
7
 
8
8
 
@@ -58,6 +58,8 @@
58
58
 
59
59
  変化前
60
60
 
61
+ 下のpartIDのBR001はミスです。本当はBR003のつもりです。
62
+
61
63
  ![変化前](42eb7296b3b4dc809ffc9765d622559d.png)
62
64
 
63
65
  変化後

3

aaaa

2020/09/18 14:50

投稿

kananananana
kananananana

スコア6

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,9 @@
10
10
 
11
11
  Python
12
12
 
13
+ ```
14
+
13
- ```file_name = "Parts_Inventory3.txt"
15
+ file_name = "Parts_Inventory3.txt"
14
16
 
15
17
  data_line = []
16
18
 
@@ -28,23 +30,27 @@
28
30
 
29
31
  for data_line in data_lines :
30
32
 
31
- if data_line.find(SID) >= 0:
33
+ if data_line.find(SID) >= 0:
32
34
 
33
- print(data_line)
35
+ print(data_line)
34
36
 
35
- new = input ("enter new quantity:")
37
+ new = input ("enter new quantity:")
36
38
 
37
- data = "".join(data_line)
39
+ data = "".join(data_line)
38
40
 
39
- lines = "".join(data_lines)
41
+ lines = "".join(data_lines)
40
42
 
41
- lines = lines.replace(data, SID +" : "+ new)
43
+ lines = lines.replace(data, SID +" : "+ new)
42
44
 
43
-
45
+
44
46
 
45
47
  with open(file_name ,"w") as f:
46
48
 
47
- f.write(lines)
49
+ f.write(lines)
50
+
51
+
52
+
53
+
48
54
 
49
55
  ```
50
56
 

2

間違いのコード

2020/09/18 14:34

投稿

kananananana
kananananana

スコア6

test CHANGED
File without changes
test CHANGED
@@ -10,19 +10,19 @@
10
10
 
11
11
  Python
12
12
 
13
- ```
14
-
15
- file_name = "Parts_Inventory3.txt"
13
+ ```file_name = "Parts_Inventory3.txt"
16
14
 
17
15
  data_line = []
18
16
 
17
+
18
+
19
19
  with open(file_name) as f:
20
20
 
21
- data_lines = f.read().split("\n")
21
+ data_lines = f.read().splitlines()
22
22
 
23
- data_line.append(data_lines)
23
+ data_line.append(data_lines)
24
24
 
25
- SID = input("enter partID:")
25
+ SID = input("enter partID:")
26
26
 
27
27
 
28
28
 
@@ -32,13 +32,13 @@
32
32
 
33
33
  print(data_line)
34
34
 
35
- new = input ("enter new quantity:")
35
+ new = input ("enter new quantity:")
36
36
 
37
- data = "".join(data_line)
37
+ data = "".join(data_line)
38
38
 
39
- lines = "".join(data_lines)
39
+ lines = "".join(data_lines)
40
40
 
41
- lines = lines.replace(data, SID +" : "+ new)
41
+ lines = lines.replace(data, SID +" : "+ new)
42
42
 
43
43
 
44
44
 

1

書き忘れパート

2020/09/18 13:57

投稿

kananananana
kananananana

スコア6

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,10 @@
1
1
  このコードを利用してファイルの中の在庫を変化させたいのですが。変化させる前とさせた後とのファイルへの出力の形が変わってしまいます。
2
2
 
3
3
  そのままの形を保ち書き換えたいです。
4
+
5
+ partID = BR00?
6
+
7
+
4
8
 
5
9
 
6
10