Automatically open files with python

Today I have an idea: to
process emails.
Collect emails from the mailbox, save them to a file, and then automatically open the file. Fill it out and give the receipt.

I came from C before (my undergraduate C), so I only know the file stream for reading files.
But some files need to be opened instead of file streaming.

What I want to do: You click on an EXCEL file, and then the program automatically opens EXCEL with software such as EXCEL 2016.
The file stream can only read the file content invisibly.
So I have been thinking about using a mouse emulator... I have used UIBOT before, and I feel that the performance is extremely poor.

Then check the Internet and found that the system() of the os module can be used directly.
TIP: I used system() as a CMD command before. I really didn't know that I could open the file visually.

Write a command for everyone to see:

file=open('1.sql','w+','encoding='gbk')
file.write('select * from d1;')
file.close()

This is the file flow I am used to.

open a file:

import os
os.system('1.sql')

You can use your SQL management software to generate SQL. Insert picture description here
Successfully opened.

Of course, because the system() program needs feedback, there is a possibility that the main process will be stuck when the opening fails, so I want to change it to a child process.

If an external mouse emulator is connected, the corresponding SQL command can be executed automatically (for example, click ALT+X to visually execute the script)
.

SQL, txt, INI, CSV, SML, dat and other files can all be defined in this way (because it is a text save command). These are the ones I often use.

I have done XXX operation and maintenance for more than a year. I don’t know this... I didn’t even understand the OS library...
Ashamed of the senior...
—————————————————————— ——————

Then today I saw the problem of system stuck.
Open the file, the file has been opened, but the CMD window is still displayed.

Then use popen to package out and execute the problem (test execution, not executed after packaging)

Then I thought about it and checked it online. Checked another function of os: startfile.

Instead of system, there is no problem.

Guess you like

Origin blog.csdn.net/weixin_45642669/article/details/113925587