You're getting this issue because csv.reader's first argument takes an
object that supports the iterator interface, as documented here:

http://docs.python.org/library/csv.html

The call to open() in that document returns a file, not a String instance:
http://docs.python.org/library/functions.html#open

The call self.request.get('csv') returns a String. When you iterate over a
string, you iterate over the characters, not the lines. You can see the
difference here:

class ProcessUpload(webapp.RequestHandler):
   def post(self):
     self.response.out.write(self.request.get('csv'))
     file = open(os.path.join(os.path.dirname(__file__), 'sample.csv'))
     self.response.out.write(file)

     # Iterating over a file
     fileReader = csv.reader(file)
     for row in fileReader:
       self.response.out.write(row)

     # Iterating over a string
     fileReader = csv.reader(self.request.get('csv'))
     for row in fileReader:
       self.response.out.write(row)


On Fri, Dec 4, 2009 at 12:23 PM, Elvin <[email protected]> wrote:

> Hello, All!
> Please help me with this issue!!!
> I'm new to GAE and Python and I'm trying to make function to upload
> CSV files using the Web form rather that bulkuploader.
> I'm try to utilize csv.reader to parse the CSV but I get an incorrect
> result, instead of reading each row individually, it treats each
> character as an row:
> ['0'] ['.'] ['0'] ['5']['', ''] ['0'] ['.'] ['2'] etc etc... where
> each item between the square bracket is actually from one row (ie. a
> newline)
>
> Here us my Python code:
> class importEvents (webapp.RequestHandler):
>    def post(self):
>         fileReader = csv.reader(self.request.get('csv'),
> dialect='excel')
>         for row in fileReader:
>              self.response.out.write(row)
>
>
> And HTML code:
> <form name="importFile" action="/importFile/importData"
> enctype="multipart/form-data" method="post">
>      <div>CSV File(Comma Separated Value) File*: <input type="file"
> name="csv"/></div>
>      <div><input type="submit" value="Upload"></div>
> </form>
>
>
> Please tell me what am I doing wrong here?
> Thank you!
>
>
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>
>


-- 
Ikai Lan
Developer Programs Engineer, Google App Engine

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.


Reply via email to