Skip to content

Error while trying to convert csv files separated by semicolons instead of commas #3

@r-mouta

Description

@r-mouta

In some cases, an IndexError: list index out of range error occurs when the input file is separated by semicolons instead of commas. It happens when the code fails to identify the delimiter correctly.

Currently, the strategy to spot the delimiter is first to parse the whole file to a single string named "characters" and then check its 310th character (i.e., characters[309]). However, the number of characters in the headlines vary from input to input, making this strategy flawed. Instead, the file should be read line by line, parsing them to a list of strings, where each element of the list matches a row in the input. Then, the delimiter can be determined from the last character in the 5th line.

The input file that trigged this error is attached below. Despite the extension, the file is csv-structured.
ZnFeO.txt

PS: Please rename the variable "row" as "file" or something like that. The name "row" has nothing to do with the variable content in this case. Also, probably there is no need to declare a "delimiters" variable. When using the "loadtxt", just give the "separator" variable.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions