Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use two different comma type? #84

Open
odg0318 opened this issue Feb 22, 2018 · 5 comments
Open

How to use two different comma type? #84

odg0318 opened this issue Feb 22, 2018 · 5 comments

Comments

@odg0318
Copy link

odg0318 commented Feb 22, 2018

Hello.
I am trying to parse two csv files that have different comma type; ",", "\t", in a program.
I injected below code to change default separator.

        gocsv.SetCSVReader(func(in io.Reader) gocsv.CSVReader {
                r := csv.NewReader(in)
                r.Comma = '\t'
                return r
        })

It seems like working fine but doesn't.
The csv with tab could be parsed well but at the same time one with comma not.
In my opinion, the same reader is used in a program.

How can I use different reader on each csv file?

@pikanezi
Copy link
Member

Hello,

What you're doing setting the Comma to '\t' then you're setting it to ',' and it does not work, have I understood it right?

@odg0318
Copy link
Author

odg0318 commented Feb 24, 2018

In my program, two kinds of csv files using comma or tab are parsed at the same time.
But only one reader can be set via your library and so it is impossible tha gocsv parses both of them.

@luxalpa
Copy link

luxalpa commented Mar 1, 2018

Yes, this is also a problem that I have with this library :( Unfortunately when using two different readers in 2 goroutines it won't work because it's global.

@vk18vk
Copy link

vk18vk commented May 23, 2018

did anyone found how to change comma type while using this library
if err := gocsv.UnmarshalFile(csvFile, &clients); err != nil { // Load clients from file
reqlog.Println("error", err)
return
}

@luxalpa
Copy link

luxalpa commented May 23, 2018

The problem is the usage of global variables which is generally bad coding style. Someone should make a pull request to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants