I'm a newcomer to programming so i apologize for my lack of technical ability.
I'm trying to create a qrcode generator in python, however, when i try to increment the number on the filename save, i get this error.
Traceback (most recent call last):
File "/home/sam/Desktop/QR Code Gen/run.py", line 52, in <module>
purchase_code_fn()
File "/home/sam/Desktop/QR Code Gen/run.py", line 32, in purchase_code_fn
qr_code_fn()
File "/home/sam/Desktop/QR Code Gen/run.py", line 41, in qr_code_fn
im.save("filename"+ count + ".png")
AttributeError: 'function' object has no attribute 'save'
>>>
Is there anyway to rectify this?
(see below for my full code - it's still a WIP)
from qrcode import *
import csv
import time
active_csv = csv.writer(open("active_codes.csv", "wb"))
void_csv = csv.writer(open("void_codes.csv", "wb"))
active_csv.writerow([
('product_id'),
('code_id'),
('customer_name'),
('customer_email'),
('date_purchased'),
('date_expiry')])
void_csv.writerow([
('code_id'),
('customer_email'),
('date_expiry')])
count = 0
def purchase_code_fn():
global count
count =+ 1
customer_email = raw_input("Please enter your email: ")
product_id = raw_input("Which product would you like (1 - 5): ")
qr_code_fn()
def qr_code_fn():
qr = QRCode(version=5, error_correction=ERROR_CORRECT_M)
qr.add_data("asaasasa")
qr.make() # Generate the QRCode itself
# im contains a PIL.Image.Image object
im = qr.make_image
im.save("filename"+ count + ".png")
def restart_fn():
restart_prompt = raw_input("Would you like to purchase another code? : ").lower()
if restart_prompt == "yes" or restart_prompt == "y":
purchase_code_fn()
elif restart_prompt =="n" or restart_prompt == "no":
print("exit")
purchase_code_fn()
The error is here : im = qr.make_image
. You are storing into im
the function make_image
of object qr. As you can store functions in variables in Python, this is a valid syntax.
So, you are not calling the function make_image
, just storing it. It should be im = qr.make_image()
.