从web2py中的私人文件夹打开文本文件

use*_*757 4 python web2py

我需要在web2py中为我的搜索引擎脚本打开一个数据库(.txt格式).

我无法访问在线数据库,因为我使用的是pythonanywhere的免费版本.

import urllib
infile=urllib.urlopen('http://database.net')
for line in infile:
Run Code Online (Sandbox Code Playgroud)

现在我将数据库上传到"私有"文件夹,我想知道如何访问它.这看起来像一个简单的问题,但我似乎无法工作.

我需要这样的东西:

infile = open('searchapp/private/database.txt')
for line in infile:
Run Code Online (Sandbox Code Playgroud)

什么是好的解决方案?

Fab*_*ano 8

这应该做:

import os
infile = open(os.path.join(request.folder, 'private', 'database.txt'))
for line in infile:
Run Code Online (Sandbox Code Playgroud)

http://www.web2py.com/books/default/chapter/29/04/the-core#request

http://docs.python.org/2/library/os.path.html#os.path.join