I want to open an application in the system (windows) & then use the "Save As" feature of that application to save the open file with a different extension.
For example:
Opening a text file using notepad application & saving the file as csv using the script.
Opening a PBIX file using PowerBI application & saving the file as a PBIT / PBIP file.
I tried searching a solution for this as I am a beginner in Python. However couldn't find it. Can somebody help me with this ?
Thanks for your help in advance.
Sachin SinghPosted Jan 4, 2024, 9:27 AM
This is what I got from chat GPT
Jayraj ChhayaPosted Jan 4, 2024, 9:14 AM
To open an application and use the "Save As" feature in Python, you can make use of the
subprocessmodule. This module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.Here's an example script that opens Notepad, types some text, and saves the file as a CSV:
In this script, we use the
subprocess.Popenfunction to open Notepad. We then use thetime.sleepfunction to wait for Notepad to open before sending keys to it using thepyautogui.typewritefunction. Finally, we use thepyautogui.hotkeyfunction to simulate the "Save As" action, followed by thepyautogui.typewritefunction to provide the desired filename and thepyautogui.pressfunction to press the Enter key.You can modify this script to suit your specific needs by replacing the application name and adjusting the key presses accordingly. Remember to install the
pyautoguimodule before running the script by executingpip install pyautoguiin your command prompt or terminal.Please note that this script relies on the graphical user interface (GUI) of the application and may not work if the application does not support automation or if the GUI elements change.