python - 在变量python中存储动态数据
问题描述
我的代码创建了一个生成pdf的函数。它可以在代码中调用超过 2 次,但在第一次它可以获取我的数据,但在第二次之后它们没有给我任何价值。我如何将我的数据存储在列表中。我正在使用 list.append 但是当第二次调用方法时,它可以给我空值 [存储在数据库中的默认值] 我的代码是:-
def GeneratePdf(request, type):
# data for testing
# global data
template = get_template("employeereport/appointment.html")
# real data
empid = request.GET.get('empid')
Date = request.GET.get('date')
a = []
a.append(Date)
print(a)
output:-
['07/13/2020']
[None]
expected output-
['07/13/2020',None]
解决方案
declare the list before using it
a = []
def function():
a.append(1)
function()
function()
print(a)
推荐阅读
- r - 管道内 n_distinct 的意外行为
- java - Java:从字符串数组中删除一个空元素
- erlang - 如何注册 Ejabberd pubsub 节点的自定义实现?
- android - 如何在android中创建类数组
- swift - Audiokit 4.9.3 中可靠的 midi 排序的哪条途径?
- c++ - 使用 imagemagick 在 Windows 上显示图像
- python - Keras LSTM:根据预测返回空数组
- c# - C# 反射:使用静态对象引用更改类的私有字段?
- android - 如何获得android设备旋转
- javascript - 如何通过网络应用程序从 Firebase 中删除数据?