Opening a text file from a private folder in web2py

I need to open a database (in .txt format) for my search engine script in web2py.

I cannot access the online database because I am using the free version of pythonanywhere.

import urllib infile=urllib.urlopen('http://database.net') for line in infile: 

Now I have uploaded the database to the folder with the "private" file, and I am wondering how to access it. This seems like a simple question, but I can't handle it.

I need something like this:

 infile = open('searchapp/private/database.txt') for line in infile: 

What a good solution?

+4
source share
1 answer

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://docs.python.org/2/library/os.path.html#os.path.join

+7
source

Source: https://habr.com/ru/post/1480478/


All Articles