从上传的文本文件中读取文件内容 [英] Reading file content from uploaded text file

查看:28
本文介绍了从上传的文本文件中读取文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在uploads文件夹中有一个上传的文件,我需要在控制器中读取它的内容以进一步处理它.我对 web2py 有非常基本的了解,但不知道该怎么做.

I have an uploaded file in uploads folder and i need to read the contents from it in the controller for processing it further. I have very basic knowledge of web2py and couldn't understand how to do it.

推荐答案

您可以执行以下操作:

import os
filename = db.mytable(record_id).myfile
content = open(os.path.join(request.folder, 'uploads', filename), 'rb').read()

更新:这里是一种更简单的方法.

UPDATE: Here is a somewhat simpler approach.

这篇关于从上传的文本文件中读取文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆