How to run a bat file from Python 3.3.2
Question: I am developing a program in python, however I have a little problem because
the data that my program needs, it is from the result of a bat file, so I
would like to create something that I help me to run just my script in python
and not use the bat file directly.

Well, right now, I have to execute the following steps:

  1. I create a txt file where I enter the input data (For example: A.txt)
  2. I run the BAT file using the file A.txt
  3. It creates a new file txt which has the result of running the BAT file (For example: B.txt)
  4. I open the file B.txt and I copy all data and then I paste it in a new txt file, where it will serve as input data to my program in python
  5. I run my program in python
  6. it creates a new file txt where has the final results
  7. End

How can I improve this, I mean, Which scripts I need to run my program in
Python without to go to the Bat file and to do the steps that I describe
above?


Answer: I'm pretty sure whatever you're doing in the `bat` file you can doit in a
python module. So:

**Write a python module sustitute for your *.bat**

Write a python module containing a function for read the file `A.txt` and
return the results. Then use that module from your program.

For instance:

    
    
    # calculations.py, the bat substitute.
    
    def calculate_from_input(file_name):
        input_ = open(file_name, 'rb') # The mode you read the fike depends on your purposes.
        # .... Do your calculations
        return result   # Return a list of velocities, for example.
    

Then in your main program

    
    
    from calculations import calculate_from_input
    
    calculated_data = calculate_from_input("A.txt")  # Then, you have the data ready to use in your program.
    

