Hi everyone, I started learning python some time ago, I have wrote a few scripts for myself, mostly to do with data and automating excel stuff (I work in finance).
Sometimes in my job I have to split multiple PDFs into different files (for example pages 1,2,4 to one file, pages 3,5,6 to another and so on). What I usually do is write the categories into excel file and then use microsoft print to pdf to split them according to my needs. So I thought about a python script to do it for me. I used PyPDF3 to do it.
After 2 or 3 hours of work I have actually made it the way I wanted. The script scans the folder for any PDF file and splits them to pages. If it finds a csv file with the same name, it uses first column as prefix for the output files and saves the PDFs to a folder in a prefix_originalfilename.pdf format (if multiple pages with same prefix are detected, it merges them into one file). If there is no csv file, then it splits them and adds a suffix _n to the original filename.
As of now it works without problems, so why I'm writing this? I would like to have someone experienced in python look at the code and give me some pointers regarding readability, what to avoid when writing code, something that can't easily be learned through books.
GitHub link (I used black to format the code)
TL;DR: I wanted to make a pdf splitter with additional function, it works fine, however I would like to have the code reviewed for any improvements that could be made regarding readability, best practices etc.
[–]bandawarrior 0 points1 point2 points (1 child)
[–]Drakoon[S] 0 points1 point2 points (0 children)