I want to return all values from my function as string. The return value is now coming as example:
('EVENTS', ['test'], [], ['Alcohol'])
The code that returns the tuple is:
def convert(fname, pages=None,encoding='utf-8'):
if not pages:
pagenums = set()
else:
pagenums = set(pages)
output = StringIO()
manager = PDFResourceManager()
converter = TextConverter(manager, output, laparams=LAParams())
interpreter = PDFPageInterpreter(manager, converter)
infile = open(fname, 'rb')
for page in PDFPage.get_pages(infile, pagenums):
interpreter.process_page(page)
infile.close()
converter.close()
text = output.getvalue()
if len(text)>=500:
regex3=re.search(r"\d+(?:[.-]\w+)*\s*(General Information|Process validation|Justification of Specification(s)|Specification|Analytical Procedures|Validation of Analytical Procedures|Batch Analyses|Justification of Specification|Reference Standards or Materials|Container Closure Systems|Stability Summary and Conclusions|Post Approval Stability Protocol and Stability Commitment)",text,re.IGNORECASE)
if regex3:
org = []
with open('C:\\Users\\Ak\\.spyder-py3\\org.csv', newline='', encoding ='latin1') as myFile:
reader = csv.reader(myFile)
for row in reader:
if len(row[1])>=4:
v = re.search(r'\b' + re.escape(row[1]) + r'\b', text, re.IGNORECASE)
if v:
a = v.group(0)
org.append(a)
break
dosage = []
with open('C:\\Users\\Ak\\.spyder-py3\\do.csv', newline='', encoding ='latin1') as myFile:
reader = csv.reader(myFile)
for row in reader:
if len(row[1])>=4:
w = re.search(r'\b' + re.escape(row[1]) + r'\b', text, re.IGNORECASE)
if w:
b = w.group(0)
dosage.append(b)
break
substances = []
with open('C:\\Users\\Ak\\.spyder-py3\\sub.csv', newline='', encoding ='latin1') as myFile:
reader = csv.reader(myFile)
for row in reader:
if len(row[1])>=4:
z = re.search(r'\b' + re.escape(row[1]) + r'\b', text, re.IGNORECASE)
if z:
c=z.group(0)
substances.append(c)
break
o = regex3.group(1), org, dosage, substances
return o
From here I want to return the values as:
EVENTS,test, [], Alcohol
OR
EVENTS,test,,Alcohol
How can I format the return values as string