Trying to Open Multiple Notepad Files with Python Script - python-3.x

I am trying to open multiple notepad files using Python script. I was successful with opening one using import subprocess and subprocess.call method and specifying the file path. However, this doesn't work for opening multiple notepad files. The second notepad opens only after I close the first notepad.
Script that I use for opening One Notepad (this works well):
import subprocess
subprocess.call(['cmd.exe','/c','D:\Folder1\Notepad1.txt'])
Script that I use for opening Two Notepads (this doesn't work):
import subprocess
subprocess.call(['cmd.exe','/c','D:\Folder1\Notepad1.txt'])
subprocess.call(['cmd.exe','/c','D:\Folder1\Notepad2.txt'])
I was expecting to see both the notepad files getting opened in multiple windows, but the second one opens only after I close the first notepad.

Related

Excel files automatically opening

I am working on a selenium testng frame work where I am downloading the Excel file, but as it is opening automatically I am not able to execute further script, is there any way where this file does not open automatically or opens in background?

Using Octave to "Edit" notepad file instead of "Open" in Windows

I use Windows 10 and an .exe program (in-house code written by a colleague) that imports data from .txt files. Since 99% of my use of .txt files are for this program, I've changed the default Windows program so that this .exe file is run automatically when opening a .txt file. If I need to access the .txt file directly, or use it for another purpose, I right-click and choose "edit."
I'm now writing a program of my own (using Octave 4.4.1), which also uses .txt files that sometimes need to be opened/edited, but if I use "open(filename)" in my Octave script, of course it just opens the .exe file. I can open the .txt file from there, but I'd like to skip this middle step, since the aforementioned .exe program is not intended to be used in this process, and there are other users of my code that don't have the .exe program installed.
Is there a way to duplicate the right-click/edit feature in Windows within Octave code? "edit(filename)" opens the file in the native Octave editor, which is technically viable, but not exactly a desirable scenario. I've also tried changing the default Octave editor to Notepad, and I've tried Notepad++ as well, but I have had absolutely no luck, even with significant effort, of making Octave use an external default editor of any kind (even when I remove the .exe program as the default for .txt files). Thanks in advance for any advice you can offer.
You can send command-line commands from Octave using the system() function.
For example, to open the file in notepad, you could do
[status, output] = system("notepad <path_to_text_file>.txt");
If notepad isn't in your system path, you will have to add it to or use the full path to the notepad executable
Or, if you want to use Notepad++, add it to your system path and then do
[status, output] = system("notepad++ <path_to_text_file>.txt");

I can't get pythons output viewer to run

I just downloaded python on a new pc and now whenever I try to create a script the output viewer just closes down immediately when I launch it as a python file.
My original script was
import secrets
secrets.token_hex(32)
but it just closes down immediately. I thought that it was something with my code so I tried to just make the simple "hello world" script.
(print) "I hope this work"
and I had the same result as the first script, the output window opened up then immediately closed down.
I can get it to work using the python shell but I prefer doing all my coding using notepad++ and it would a real pain in the behind if I can't get that to work.
This is expected behavior if you run your scripts as you described, by opening them in Explorer. Your script completes execution in a terminal window, then closes immediately.
If you absolutely insist on running them on double click and still want to see your console, I suggest you create a .bat file at your python path with contents like this:
python -i %1
and them bind your double-click handler to use that file on .py extension. That way, Python will execute your file and go into CLI mode, preserving your terminal window and allowing you to type further commands.
My other guess would be that you want a console plugin to work right within Notepad++, in that case use nppexec: https://sourceforge.net/projects/npp-plugins/files/NppExec/

Is it possible to run datanitro without opening excel

While it is possible to run a datanitro script via VBA, this still requires excel to be open. Is it possible to have a .py file that executes datanitro (like opening and closing an excel file) without a human needing to be present to open excel and execute the script?
If it isn't possible yet is it in the works?
DataNitro needs to have Excel open before you can run it, but you can have a script start automatically when a workbook is opened (https://datanitro.com/docs/scripts.html#autostart).
You can combine that with a Python script (outside of DataNitro) or other script to open and close the Excel file and launch the process automatically.

Opening Excel and PDf files with Tcl Tk

I am having problems opening an existing Excel file with Tcl Tk. I am able to open an existing MS Word file with no problems. The code that I am using is as follows, also my test application has "package require tcom" included:
proc OpenFile {} {
#Path to file
set app [::tcom::ref getobject "C:\\Users\\Me\\Desktop\\Test.doc"]
#Change path to application
set this [$app Application]
#Open application
$this Visible 1
}
This code is executed by a button. Basically, Test.doc gets opened after the button is pressed.
I tried changing the file to an existing Excel file, and when I press the button the file opens for a split second, and then closes. This also happens with MS Access files, as well.
Does anyone know how to open an existing Excel file with Tcl Tk, and make it stay open? Additionally, for PDFs and text files, I understand that I cannot use Tcom to open these files. Does anyone know how to open PDFs, text, and other non-MS files with Tcl Tk?
I really appreciate your help!
Thank you,
DFM
Assuming you're on Windows and you just want to open a file (.xls, .pdf, ...) with its usual application (ie. not modifying the file from your script) you can just use "start" like this:
set TestDoc "My Test.xls"
eval exec [auto_execok start \"\" [list $TestDoc]

Resources