Bingo! You found that reason which costs me hours of time. T_T Thanks!
On Nov15, 11:22pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > because the file stream has already been read by accept and the you > are pointing at the bottom of the file. Try > > request.vars.backup.file.seek(0) > request.form.vars.backup.file.read() > > if it does not work, then the file stream can only be read > sequentially and you need to re-open the file and read from there > > Massimo > > On Nov 15, 7:59 am, Iceberg <iceb...@21cn.com> wrote: > > > > > Hi folks, > > > How to read an uploaded file object line by line? This seemingly easy > > task stumps me. Now I am totally lost. :-/ > > > def restore(): > > form = SQLFORM.factory(Field > > ('backup','upload',requires=IS_UPLOAD_FILENAME())) > > if form.accepts(request.vars,keepvalues=True,session=None): > > > # response.flash = type(form.vars.backup.file) > > # It says it is an instance (of what?) > > > # response.flash = type(form.vars.backup.file.file) > > # It says it is a file object. Good, but "file.file" is wired enough. > > > # response.flash = form.vars.backup.file.read() > > # response.flash = form.vars.backup.file.file.read() > > # The above two lines all return an empty string, ALWAYS. > > > response.flash = [l for l in form.vars.backup.file.file] > > # And the above line does not read any data either. > > # Please help. > > # Actually I gonna use import_from_csv_file() for a restore. > > # But now the import_from_csv_file() can not detect any data. > > > return form > > > # Thanks in advance! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---