nginx - 如何使用 lua 在 python 中创建列表和附加值
问题描述
我正在尝试使用本地目录中的文件名创建一个列表,并使用 lua 将其添加到 nginx 中的 http 请求正文。像下面的东西
filelist = [] #a list variable to hold the filenames
for file in f:lines() do
#file i get my filename one by one
filelist.append(file)
end
request_payload = {"somedata":"its key", "files": filelist}
假设我有请求正文,我需要用新的 filelist 变量值更新那个 json。
我知道 lua 没有像列表对象这样的东西,而是它具有表结构。但是有什么简单的技巧可以完成这项工作
解决方案
我让它与 lua 数组一起使用
local filelist = {} #lua table object
for file in f:lines() do
#file i get my filename one by one
table.insert(filelist, file) #this will update the array
end
希望对某人有所帮助:)
推荐阅读
- python - 创建 apk 时 kivy 应用程序的 CPU 使用率是否下降
- javascript - 我正在使用单页应用程序,如何在一个功能中的 div 之间切换?
- mpi - How do I use hybrid OpenMP/OpenMPI parallelization together with GNU compilers?
- python - 安装了不再可识别的 pip3 模块。需要用pip重新安装
- android - java.lang.NoSuchMethodError:没有静态方法 isAtLeastR()Z
- api - POST Token 停止工作:我们如何生成一个将 grant_type 作为密码传递的令牌?超过 401 Unauthorized - invalid_grant
- c - 如何访问真正放入结构中的值?
- c++ - 嵌套映射 cpp 的时间复杂度
- python - 模板中未显示 Django 表单验证错误
- laravel - 使用actingAs的测试方法存在问题