Add command to auto-generate csv parsing code for different languages and libraries
Closed this issue · 1 comments
mechatroner commented
Since Rainbow CSV knows the dialect of the file and its path, it can effectively pre-generate CSV parsing code for different languages and libraries.
The code generation interface can be interactive, so the user can choose Language, library, iterative VS whole file read, header vs no header.
Example:
The current dialect is a pipe-separated file.
The user runs the Generate parsing code
command.
Rainbow CSV generates:
import csv
with open('/path/to/file.csv') as f:
reader = csv.reader(f, delimiter='|', quoting=csv.QUOTE_NONE)
for row in reader:
print(row)
or
csv_data = pandas.read_csv('/path/to/file.csv', sep='|')
or
#include <sstream>
#include <string>
#include <stream>
vector<string> split_string(const string& src, char delim = '|') {
vector<string> tokens;
stringstream mySstream(src);
string word;
while (getline(mySstream, word, delim)) {
tokens.push_back(word);
}
return tokens;
}
std::ifstream infile("/path/to/file.csv");
std::string line;
while (std::getline(infile, line))
{
auto fields = split_string(line);
// process fields
}
or
....
mechatroner commented
I am not sure if this feature is worth implementing and maintaining, so please upvote if you think that this feature will be useful for you!