'Ignore case in Python script [duplicate]
In my Python script, I'm working with JSON files but in some files I have an input "racecards" and in some files I have "raceCards".
How can I ask to Python to use the two cases?
My script:
for file1 in FILE:
with open(path + '%s' %file1,encoding='utf-8') as f1:
INPUT1 = json.load(f1)
DATA = INPUT1["pageProps"]["initialState"]["raceCards"]["races"]
X = list(DATA.values())
for x in X[0]:
ENTRY = []
for h1 in header1.split(','):
ENTRY.append(x[h1])
Entry = [str(i) for i in ENTRY]
towrite = ','.join(Entry)
print(towrite,file=output1)
Solution 1:[1]
One way is that you can simply use a try & except to implement it.
instead of:
DATA = INPUT1["pageProps"]["initialState"]["raceCards"]["races"]
Replace with:
try:
DATA = INPUT1["pageProps"]["initialState"]["raceCards"]["races"]
except Exception ignored:
DATA = INPUT1["pageProps"]["initialState"]["racecards"]["races"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Amir Shamsi |
