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

from_csv should should take delimiter as kwarg #31

Closed
GoogleCodeExporter opened this issue Aug 11, 2015 · 1 comment
Closed

from_csv should should take delimiter as kwarg #31

GoogleCodeExporter opened this issue Aug 11, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Hi,

I'm currently using this lib to generate pretty ascii tables.

I get my data from a csv file where the delimiter is set to ;.

So I think thwe from_csv should take an optional delimiter arg, so it does not 
need to guess the dialect. I looked at the code and here is a corrected 
function to do this. (Only the first lines of the from_csv function)

def from_csv(fp, field_names = None, delimiter=None,**kwargs):                  


    if delimiter is None:                                                           
        dialect = csv.Sniffer().sniff(fp.read(1024))                                
        fp.seek(0)                                                                  
        reader = csv.reader(fp, dialiect)                                           
    else:                                                                           
        reader = csv.reader(fp, delimiter=delimiter)

the rest is the same


Original issue reported on code.google.com by wunio.zi...@gmail.com on 10 Jun 2013 at 8:43

@GoogleCodeExporter
Copy link
Author

Hello.  Sorry for my very slow action on this.  I've just made a commit to 
trunk in the SVN repo implementing this.  Not only can you specifie a 
delimiter, you can pass any of the format parameters that csv.Reader accepts 
(delimiter, doublequote, escapechar, etc.).  It would be wonderful if you could 
give the new code a quick test on your scenario.

Btw, how was PrettyTable failing for you with ";" delimiters?  I tried using 
the old code on a file with ";" delims, and it worked just fine.

Original comment by luke@maurits.id.au on 5 Oct 2013 at 10:17

  • Changed state: Fixed

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

No branches or pull requests

1 participant