importing CSV / NameError: global name 'request' is not defined"

550 views
Skip to first unread message

niknok

unread,
Apr 19, 2011, 4:56:51 AM4/19/11
to w2p
I am trying to call this module that contains a series of import_csv_file statement like so:

from my model, db_history.py I call up a module to import a series of csv files:
initialize=local_import('initialize')
initialize.fillup(db)

my modules/fillup.py looks like this:
import os

def fillup():
    try:
        db.question.import_from_csv_file(open(os.path.join(request.folder,'private/db_question.csv'),'r'))
    except Exception, e:
        print 'oops: %s' % e #XXX
        raise e

    ...

Then I get: "NameError: global name 'request' is not defined"

What's weird is that those import statements run from the shell.  They also work fine if I put them in the model that calls it. But, I'm hoping to database initialization by CSV from a single module file.

I'm pretty sure I'm missing something here. Anyone?



Stifan Kristi

unread,
Apr 19, 2011, 8:56:07 AM4/19/11
to web...@googlegroups.com
please add request variable as parameter on your modules and your function, because the modules can't pass global name like (response, request, db, t, crud, etc) so that you must add it:
(not tested)
e.g. 
initialize = local_import('initialize')
initialize.fillup(db, response)

please let me know if you still have this problem.

pbreit

unread,
Apr 19, 2011, 12:14:44 PM4/19/11
to web...@googlegroups.com
Modules have no access to models or the request. You have to pass in everything the module needs.

Anthony

unread,
Apr 19, 2011, 1:35:19 PM4/19/11
to web...@googlegroups.com
Also, you call 'initialize.fillup(db)' (i.e., you pass 'db' as an argument to 'fillup'), but your function definition for 'fillup' does not include any arguments.
Reply all
Reply to author
Forward
0 new messages