I'm fairly new to Python, I've wrote a function that reads a file and that strips odd symbols out of the file.
def clean_string(x):
return x.strip().strip('"').strip("'").lower()
and to read the file
with open(fileName, 'r', errors='replace', encoding='utf-8') as f:
data = f.readlines()
urls = []
for line in data:
cleanName = clean_string(line.split(',')[0])
cleanServer = clean_string(line.split(',')[1])
name = request.quote(cleanName.encode('utf-8'))
server = request.quote(cleanServer.encode('utf-8'))
url = baseUrl.replace('<name>', name).replace('<server>', server)
urls.append(url)
While cleanName works perfectly, I'm getting list index out of range for cleanServer, when I print the line with [1] index, it also prints the output, which means the index exists, what am I doing wrong?
Example data:
"Bicmex"
,"ravencrest"
"Fleshcraft"
,"archimonde"
"Satanå"
,"stormscale"
"Jàgër"
Your data contains a line without server. You need to check for that and f.e. print that line:
Fix:
This would work for files like:
To handle files that have alternating lines, use: