0

I need help for a Python Program I started this morning, I'm struggling with two errors, one when launching the program but that doesn't do anything, the program still continues to run, and another one when finishing the saving process.

Here is the entire code, just in case:

1 # not important (comments)
2 # not important (comments)
3 # not important (comments)
4
5 import qrcode
6 from os import listdir, remove, mkdir
7 from os.path import isdir, isfile
8 from pystyle import Anime, Colors, Colorate, System, Center, Write
9
10 banner = r"""
11 █▀▀▀▀▀█ ███ ▀▄▀▀█ █▀▀▀▀▀█
12 █ ███ █ █▄▀█ ▄▀ ▄ █ ███ █
13 █ ▀▀▀ █ ▄  ▄▄ ▀▀█ █ ▀▀▀ █
14 ▀▀▀▀▀▀▀ ▀▄▀ █ █ █ ▀▀▀▀▀▀▀
15 ▀█  ██▀  ▄▄▀██▄▄▄  ▀▄█▀█▀
16  ▄███ ▀██ ▄█ ▀▄▀▀▀▀█▀▀█▄ 
17 █▀█▄▄▄▀▄▀▄▀█ █▄█ █▀▀▄▀▀█▀
18   ▄▄▀▀▀▀▄ █▀█▀▄▀█▄ ██▀█▄ 
19 ▀▀▀▀ ▀▀▀█▄ █▀ ▄ █▀▀▀█▀▀  
20 █▀▀▀▀▀█ ▄ █▀▄▀█ █ ▀ █▄▄ ▄
21 █ ███ █ ▀ █ ▀ ▄▄▀███▀▀█▄▄
22 █ ▀▀▀ █ ▄▀▄█▄ ▀ ▀██▄▄█▄█ 
23 ▀▀▀▀▀▀▀ ▀   ▀  ▀  ▀   ▀▀▀"""
24
25 ascii_art = r"""
26
27  ___________   _____                           _             
28 |  _  | ___ \ |  __ \                         | |            
29 | | | | |_/ / | |  \/ ___ _ __   ___ _ __ __ _| |_ ___  _ __ 
30 | | | |    /  | | __ / _ \ '_ \ / _ \ '__/ _` | __/ _ \| '__|
31 \ \/' / |\ \  | |_\ \  __/ | | |  __/ | | (_| | || (_) | |   
32  \_/\_\_| \_|  \____/\___|_| |_|\___|_|  \__,_|\__\___/|_|"""[1:]
33
34 def init():
35     if not isdir('codes'):
36         mkdir('codes')
37     System.Clear()
38     System.Size(160, 50)
39     System.Title("QR Generator")
40     Anime.Fade(text=Center.Center(banner), color=Colors.white_to_green, mode=Colorate.Vertical, enter=True)
41
42 def main():
43     global qr_url
44     global qr_name
45     System.Clear()
46     print('\n'*2)
47     print(Colorate.Diagonal(color=Colors.white_to_green, text=Center.XCenter(ascii_art)))
48     print('\n'*3)
49    qr_url = Write.Input(text="Enter the link that will be opened when the QR Code will be scanned > ", color=Colors.white_to_green, interval=0.005)
50     print()
51     qr_name = Write.Input(text="Enter the name so the program can save the code with a custom name > ", color=Colors.white_to_green, interval=0.005)
52     print()
53     img = qrcode.make(qr_url)
54     img.save('codes/'(qr_name).jpg)
55 
56 if __name__ == '__main__':
57     init()
58     while True:
59         main()

First error (at launch)

Second error (at saving process)

2 Answers 2

2

Change your code in line 54 to this:

img.save('codes/{}.jpg'.format(qr_name))
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it worked!
1

You have an error at line 54
Use an f-string for variable to be set into your path
img.save(f'codes/{qr_name}.jpg')

1 Comment

Already answered, but I tried it and it worked too, so thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.