How do I change the save location of an altered PDF using PyPDF2

I need to change the location that the output file is saved. Currently the save location is wherever the application is located. I would like to change it to the user’s desktop. Any help would be appreciated. filename = askopenfilename() packet.seek(0) new_pdf = PdfFileReader(packet) existing_pdf = PdfFileReader(open(filename, "rb")) output = PdfFileWriter() page = existing_pdf.getPage(0) page.mergePage(new_pdf.getPage(0))… Read More How do I change the save location of an altered PDF using PyPDF2

How to add text inside existing lines

So I already know how to open / read from a file line.. for example here’s what I wrote so far. a=0 file_paths = sys.argv[1:] for path in file_paths: a=1 if(a==0): while True: print(‘\nSpecify where the path of the code is’) print(‘Example /home/user/desktop/code.txt \n’) path=input(‘Input Here: ‘) if os.path.isfile(path)==True: break else: print(‘No files found. Please… Read More How to add text inside existing lines

Why is this python function not reading my json File string properly?

So I have a unique player ID string that is stored in a JSON file after it detects on start-up that the player is new to the game. def checkIfPlayerIsNew(): if os.path.exists("myJson.json"): print(‘file exists’) k = open(‘myPlayerIDs.json’) print(k.read()) #print("This is the k value: {}".format(code)) #code = json.dumps(k) getData(k.read()) else: print(‘file does not exist’) f =… Read More Why is this python function not reading my json File string properly?

PyInstaller –add-data from script

I’m trying to create an executable file out of my python project. I’m using the function ‘make_executable’ to build an executable file. Running the command to add data raises an error like: pyinstaller: error: unrecognized arguments: –add-data C:\Users<>… –add-data: C:\Users<>… def make_executable(main_script: str, files_to_add: List[str], target_location: str = None, name: str = ‘app’, single_file: bool… Read More PyInstaller –add-data from script

Remove characters from list of strings using comprehension

I would like to know how to remove certain characters from a list of strings. In this case, I am trying to remove numbers of type str using list comprehension. numbers = [str(i) for i in range(10)] imgs_paths = [os.path.join(input_folder, f) for f in os.listdir(input_folder) if f.endswith(‘.jpg’)] foo_imgs_paths = [[e.replace(c, "") for c in e… Read More Remove characters from list of strings using comprehension

I know eval() is bad practice; is there an alternative for my code which involves getting the __doc__ of all funcs in all files in a folder?

I’m making a project which involves importing a directory as a module (it has an __init__.py) then iterating through all files in that directory and printing the docstring of all the functions in each file. This is my main.py code, in which I have to use eval() to convert the file name from a string… Read More I know eval() is bad practice; is there an alternative for my code which involves getting the __doc__ of all funcs in all files in a folder?

Get only the txt file you want from the folder containing the txt file – Python

I have a folder with a .txt files. the name of the files are: my_file1.txt my_file2.txt my_file3.txt my_file4.txt In this way, only the last number is different. import pickle my_list = [] with open("/Users/users_a/Desktop/website-basic/sub_domain/sub_domain01.txt", "rb") as f1, open("/Users/users_a/Desktop/website-ba\ sic/sub_domain/sub_domain02.txt", "rb") as f2, open("/Users/users_a/Desktop/website- basic/sub_domain/sub_domain03.txt", "rb") as f3: my_list.append(pickle.load(f1)) my_list.append(pickle.load(f2)) my_list.append(pickle.load(f3)) print(my_list) In this way, I… Read More Get only the txt file you want from the folder containing the txt file – Python

Python regex pattern in order to find if a code line is finishing with a space or tab character

Sorry for putting such a low level question but I really tried to look for the answer before coming here… Basically I have a script which is searching inside .py files and reads line by line there code -> the object of the script is to find if a line is finishing with a space… Read More Python regex pattern in order to find if a code line is finishing with a space or tab character