[英]Opening a text file from the private folder in web2py
I need to open a database (in .txt format) for my search engine script in web2py. 我需要在web2py中为我的搜索引擎脚本打开一个数据库(.txt格式)。
I can not access the online database, because I use the free version of pythonanywhere. 我无法访问在线数据库,因为我使用的是pythonanywhere的免费版本。
import urllib
infile=urllib.urlopen('http://database.net')
for line in infile:
Now I uploaded the database to the "private" file folder and I wonder how get access it. 现在我将数据库上传到“私有”文件夹,我想知道如何访问它。 It looks like a simple question, but I can't seem to work it.
这看起来像一个简单的问题,但我似乎无法工作。
I need something like this: 我需要这样的东西:
infile = open('searchapp/private/database.txt')
for line in infile:
What is a good solution? 什么是好的解决方案?
This should do: 这应该做:
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 http://www.web2py.com/books/default/chapter/29/04/the-core#request
http://docs.python.org/2/library/os.path.html#os.path.join http://docs.python.org/2/library/os.path.html#os.path.join
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.