[英]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.