错误消息:
TypeError: rndm_json_data_gen() missing 1 required positional argument: 'rangenum'
我看不出少了什么。我已经查看了stackoverflow上的许多类似线程,但看不出任何东西如何适用于我的情况。
这段代码首先在终端Python上运行
handler.py
:
#########################################################
## HANDLER.PY ##
#########################################################
import psycopg2
from lib.feeder import Feeder
from lib.tle import TLE
from lib.import_data import IMPORTDATA
from lib.random_json import DATA_GEN
##TECHNICALLY THIS COMES PRE-LOADED
conn_string = "database connection"
# print the connection string we will use to connect
#print("Connecting to database\n ->%s" % (conn_string))
# get a connection, if a connect cannot be made an exception will be raised here
conn = psycopg2.connect(conn_string)
##THIS IS THE PART THAT IâM TRYING TO GET TO WORK
TypeProcessor = IMPORTDATA()
num_json_items = 5
#####Error happens with last item here######
Feeder(conn).insertOrUpdateItem("database_table", TypeProcessor.getDictionary(),
TypeProcessor.getIds(), TypeProcessor.getModifiedKey(), TypeProcessor.getUpdateOnConflict(),
DATA_GEN.rndm_json_data_gen(num_json_items))
print("Import Data complete")
'''
## Below was what was in the last spot, where the problem is occurring,
## before I started changing it to a method
{"uuid": "UUID1", "column1": "data1", "column2": data2, "column3": "data3", \
"column4": "data4", "file_name": "filename", "load_date": "2020-12-09"}
#########################################################
## IMPORT_DATA.PY ##
#########################################################
modified_key = "load_date"
update_on_conflict = True
ids = ["uuid"]
dictionary = {
"uuid": {"input_field": "uid", "update_on_conflict": False},
"column1": {"input_field": "column1", "update_on_conflict": True},
"column2": {"input_field": "column2", "update_on_conflict": True},
"column3": {"input_field": "column3", "update_on_conflict": True},
"column4": {"input_field": "column4", "update_on_conflict": True},
"load_date": {"input_field": "load_date", "update_on_conflict": True}
};
class IMPORTDATA():
def getDictionary(self):
return dictionary;
def getIds(self):
return ids;
def getModifiedKey(self):
return modified_key;
def getUpdateOnConflict(self):
return modified_key;
###############################################
## RANDOM_JSON.PY ##
###############################################
import json
from faker import Faker
import random
from random import randint
from datetime import datetime
class DATA_GEN():
def rndm_json_data_gen(self,rangenum):
fake = Faker()
Faker.seed(0)
for _ in range(rangenum):
import_data={
"uuid": fake.bothify(text='UUUID##########'),\
"column1": fake.bothify(text='Data##'), \
"column2": fake.bothify(text='##'), \
"column3": fake.bothify(text='##'), \
"file_nm": fake.file_name(), \
âimport_dateâ: datetime.today().strftime('%Y-%m-%d-%H:%M:%S')
}
return import_data;