python 2.7 - Web2py application: How to reference .yaml file in controller? -
i have app running online under web2py
. now, adding names.yml
file need call in controller file (default.py)
on web2py server. should keep .yml/.yaml
files. have kept them in views default/names.yml
when call in default.py like:
dicttagger = dictionarytagger([ 'default/names.yml', 'default/surname.yml'])
i no such file error. tried below:
dicttagger = dictionarytagger([ 'views/default/names.yml', 'views/default/surname.yml'])
same error
class snapshot under:
class dictionarytagger(object): def __init__(self, dictionary_paths): files = [open(path, 'r') path in dictionary_paths] dictionaries = [yaml.load(dict_file) dict_file in files] map(lambda x: x.close(), files)
any suggestions how or making mistake of using yaml/yml file in we2py , doesn't work in web2py app hosted online?
question 2
thank you. resolved error not sure how add nltk.download() hosted app. keep getting below error. can pls have look: traceback 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. traceback (most recent call last): file "/home/prakashsukhwal/web2py/gluon/restricted.py", line 220, in restricted exec ccode in environment file "/home/prakashsukhwal/web2py/applications/sensiva/controllers/default.py", line 4, in nltk.download() file "/usr/local/lib/python2.7/dist-packages/nltk/downloader.py", line 644, in download self._interactive_download() file "/usr/local/lib/python2.7/dist-packages/nltk/downloader.py", line 958, in _interactive_download downloadershell(self).run() file "/usr/local/lib/python2.7/dist-packages/nltk/downloader.py", line 981, in run user_input = raw_input('downloader> ').strip() eoferror: eof when reading line error snapshot (eof when reading line)
inspect attributes
frames
file /home/prakashsukhwal/web2py/gluon/restricted.py in restricted @ line 220 code arguments variables
file /home/prakashsukhwal/web2py/applications/sensiva/controllers/default.py in @ line 4 code arguments variables
file /usr/local/lib/python2.7/dist-packages/nltk/downloader.py in download @ line 644 code arguments variables
file /usr/local/lib/python2.7/dist-packages/nltk/downloader.py in _interactive_download @ line 958 code arguments variables
file /usr/local/lib/python2.7/dist-packages/nltk/downloader.py in run @ line 981 code arguments variables
function argument list
(self=)
code listing
def run(self): print 'nltk downloader' while true: self._simple_interactive_menu( 'd) download', 'l) list', ' u) update', 'c) config', 'h) help', 'q) quit') user_input = raw_input('downloader> ').strip() if not user_input: print; continue command = user_input.lower().split()[0] args = user_input.split()[1:] try:
variables
user_input undefined builtinraw_input ).strip undefined context
you can store files wherever want, if you're using python open
function, you'll need give full paths, not paths relative web2py application folder. instead, try:
import os dicttagger = dictionarytagger([os.path.join(request.folder, 'views', 'default', 'names.yml'), ...])
Comments
Post a Comment