[英]Opening a text file from the private folder in web2py
我需要在web2py中为我的搜索引擎脚本打开一个数据库(.txt格式)。
我无法访问在线数据库,因为我使用的是pythonanywhere的免费版本。
import urllib
infile=urllib.urlopen('http://database.net')
for line in infile:
现在我将数据库上传到“私有”文件夹,我想知道如何访问它。 这看起来像一个简单的问题,但我似乎无法工作。
我需要这样的东西:
infile = open('searchapp/private/database.txt')
for line in infile:
什么是好的解决方案?
这应该做:
import os
infile = open(os.path.join(request.folder, 'private', 'database.txt'))
for line in infile:
http://www.web2py.com/books/default/chapter/29/04/the-core#request
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.