Skip to content

Commit f05aada

Browse files
committed
Added the code to avoid operating on the script call in sys.argv[0]
1 parent 1c594c3 commit f05aada

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

IMAGES & PHOTO SCRIPTS/Image-Inverter/inverter.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
import sys, os
66

77
def main():
8+
# if the script is called with no input
89
if len(sys.argv) == 1:
910
print("Please provide files to operate on!")
1011
sys.exit(1)
1112

12-
for file in sys.argv: # TODO: remove the sys.argv[0] from the loop! use index i and start from 1
13-
# TODO: add a check that the files are jpg
13+
i = 0
14+
for file in sys.argv:
15+
# ignore the first parameter -> the script call
16+
if i == 0:
17+
i = i + 1
18+
continue
19+
1420
file_name = os.path.splitext(file)
1521
with Image.open(file) as image:
16-
inverted_image = ImageOps.invert(image)
17-
inverted_image.save(filename + "_inverted", "JPEG")
18-
19-
sys.exit(0)
22+
ImageOps.invert(image).save(filename + "_inverted", "JPEG")
23+
i = i + 1
2024

2125
if __name__ == '__main__':
2226
main()

0 commit comments

Comments
 (0)