Using the string split on CSV like this is bad in practice. Prefer using CSV manipulation library instead. Like, http://docs.python.org/library/csv.html
You can use the CSV reader module for your purpose. On Sat, Aug 6, 2011 at 1:13 AM, Vasu Nagalingam <nagalin...@gmail.com>wrote: > Hi - I am in implementing a batch file import function where the data file > is in CSV format. The data file is uploaded (InMemoryFileHandler) > successfully, but I am having trouble parsing the CSV data correctly. > > My code: > for line in imported_data: > line = line.split(',') > > My data is organized in this > format: <id>,<name>,<address1>,<city>,<province>,<postal> > 0001,"google","123 Main St","san francisco","CA",94000 > 0002,"microsoft","1 Main St, 9th Floor","Boston","MA",17000 > > The code works fine for the first row (google). Due to the extra comma in > the address 1 element for Microsoft, the import of row is mucked up. Is > there a way to indicate the text delimiter as well as data delimiter for the > split function? Or, any other options? > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/F0cKmlxJTW8J. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.