Python Forum
Automating to run python script 100 times by changing parameters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automating to run python script 100 times by changing parameters
#2
I'm sure you have it sorted by now, but in case anyone else is looking:
Many ways to do this - I am often using pandas or numpy when these kind of circumstances arise but the easiest is:
#add following two lines:
x = 0
while x <= 100:
#indent all that follows:
#add following line:
    fn = 'test-automate'+str(x)+'.csv'
#edit following line:
    filename = open(fn, 'w')
    sys.stdout = filename
    with open('test-100.csv') as f:
#edit following line:
        firstColumn = [line.split(',')[x] for line in f]
        results = [float(i) for i in firstColumn]
        int_result = [round(i) for i in results]
        print(int_result)

    filename.close()
        # reattach stdout to console
    sys.stdout = sys.__stdout__
#edit following line:
    with open(fn) as file:
        data = file.read()
        print(data)
#add following line:
    x+=1
[/quote]
Reply


Messages In This Thread
RE: Automating to run python script 100 times by changing parameters - by andydoc - Dec-29-2020, 10:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to receive two passed cmdline parameters and access them inside a Python script? pstein 2 339 Feb-17-2024, 12:29 PM
Last Post: deanhystad
  Virtual Env changing mysql connection string in python Fredesetes 0 370 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,181 Jun-29-2023, 11:57 AM
Last Post: gologica
Question Is there a python program for automating this invoicing workflow? PG_Archipelago 3 1,076 Feb-02-2023, 11:01 PM
Last Post: Larz60+
  Saving the times a script is run to a file or ... 3Pinter 7 1,388 Oct-19-2022, 05:38 PM
Last Post: 3Pinter
  Changing a string value to a numerical value using python code and a lamda function Led_Zeppelin 6 1,598 Jul-05-2022, 11:29 PM
Last Post: deanhystad
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,589 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  changing Python files to .exe alok 2 2,231 Jul-20-2021, 02:49 PM
Last Post: alok
  Changing Index of 2 List in python giddyhead 0 1,659 Mar-05-2021, 05:45 PM
Last Post: giddyhead
  Help with Creating a Script for Automating Reports SunWers 1 1,915 Dec-29-2020, 10:21 PM
Last Post: jjc385

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020