Open .exe file using python and trying to pass parameter in the same python script - python-3.x

I'm trying to open a .exe file from Python and give it some instructions. Because I have thousands of models to run I need to automatize the process.
Here on Stackoverflow, I found several options that I tried. I am able to open .exe file but not able to fill the information in that and run the .exe. the place is always empty. I'm writing one of these solutions. [I'm using Python3]:
import os
your_bat_file_address = r'"C:\D_drive\testing\SAR\1100_star3\exmple.bat"' # example
os.startfile(your_bat_file_address)
in the exmple.bat file
"C:/D_drive/tool/EXMPLE.exe" --input1 "C:/D_drive/file/1st_file" --input2 "C:/D_drive/file/2st_file" --input3 "C:/D_drive/file/3st_file"

Related

Unable to close/delete file from python or OS

I am trying to delete an excel file from my computer but it will not let me, and keeps saying that the file is open/in use by python. I have tried using f.close() methods and os.remove() with no luck. I can't find any temporary files in the Excel default local file location either. I really am at a loss as to why I am unable to close or delete this file through python or otherwise.

Sending Information from one Python file to another

I would like to know how to perform the below mentioned task
I want to upload a CSV file to a python script 1, then send file's path to another python script in file same folder which will perform the task and send the results to python script 1.
A working code will be very helpful or any suggestion is also helpful.
You can import the script editing the CSV to the python file and then do some sort of loop that edits the CSV file with your script 1 then does whatever else you want to do with script 2.
This is an advantage of OOP, makes these sorts of tasks very easy as you have functions set in a module python file and can create a main python file and run a bunch of functions editing CSV files this way.

How to save python code (part of the notebook) to file in GDrive from code

I am using Google Colabs for my research in machine learning.
I do many variations on a network and run them saving the results.
I have a part of my notebook that used to be separate file (network.py) At the start of a training session I used to save this file in a directory that has the results and logs etc. Now that this part of the code is in the notebook it is easier to edit etc, BUT I do not have a file to copy to the output directory that describes the model. how to i take a section of a google colab notebook and save the raw code as a python file?
Things I have tried:
%%writefile "my_file.py" - is able to write the file however the classes are not available to the runtime.

Download and rename a number of files simultaneously using Python

I have written a script in python3 that opens a website, logs into it, enter numbers by running through a list
list = [1,2,3,4,5,6,7,8,9,10,11]
for j in list:
enternum = driver.find_element_by_xpath('xxxx')
enternum.click()
enternum.send_keys(j)
and downloads a file after entering each number.
I want to rename the file the moment it is downloaded before downloading the next file. For example:- File downloaded for 1 will be renamed as 1, for 2 as 2 and so on. I have tried using shutil and os.rename but was not successful.
Is there a way I can do this using Python? Any help will be appreciated
I was able to change the file names after downloading them, by using os.path.join and then using os.rename

Importing files from different dir

I am working on a project where my python file (which is located in D:) will open the 'submissions' folder (in C:\user\desktop\). Now, submissions folder has sub-folders of students like student1, student2, etc. Now, each student submits the same file say my_math.py (which has add, sub, mul,. functions).
So, my program (test_math.py) tests each of their submissions one after another.
addr = r'C:\users\desktop\submissions\student1'
import importlib
module = importlib.import_module('test_math', package = addr)
This doesn't seem to work. I also have a __init__.py in submissions folder. I don't know where the problem is! I'm using python 3.6.3
There are two methods:
One, from command line: https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH . I think you should start a new python interpreter at every student.
or just inside python, before import, you manipulate sys.path https://docs.python.org/3/library/sys.html#sys.path
But when your studend know that you execute the code directly from your console, they will abuse the system (as they always did).

Resources