-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_bom.py
35 lines (24 loc) · 965 Bytes
/
remove_bom.py
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
# @ -0,0 +1,34 @@
# Open the JSON file with BOM and remove BOM if present
with open('user_fixture.json', 'rb') as f:
content = f.read()
# If BOM is detected (0xEF, 0xBB, 0xBF), remove it
if content.startswith(b'\xef\xbb\xbf'):
content = content[3:]
# Save the cleaned content to a new JSON file
with open('user_fixture_no_bom.json', 'wb') as f:
f.write(content)
# print("BOM Removed. Saved as 'user_fixture_no_bom.json'.")
# # Re-encode the file to UTF-8 without BOM
# with open('user_fixture.json', 'rb') as f:
# content = f.read()
# # Write the content back to the file as UTF-8 without BOM
# with open('user_fixture_fixed.json', 'wb') as f:
# f.write(content)
# import chardet
# # Read the file in binary mode
# with open('user_fixture.json', 'rb') as f:
# raw_data = f.read()
# # Detect the file encoding
# result = chardet.detect(raw_data)
# print(f"Detected encoding: {result['encoding']}")