1

Good day.

Today i was trying to practice python and Im trying to make a script that reads the lines from a file containing only numbers and using said numbers as a parameter in another Python script.

Here at work i sometimes need to execute a python script called Suspend.py, ever time i excute this scripit i must type the following information:

Suspend.py suspend telefoneNumber

I have to do this procedure many times during the day and i have to do this for every number on the list, it is usually a very long list. SO i though on trying to make things a little bit faster and creat a Python script myself.

Thing is a just started learning Python on my own i kinda suck at it, so i have no idea on how to do this.

In one file i have the following numbers:

87475899
87727856
87781681
87794922
87824499
88063188
88179211
88196532
88244043
88280924
88319531
88421427
88491113

I want python to be able to read line by line and send this number to another file script together with the word "suspend" on the previously said python script.

6
  • You want to call the other script with arguments from the lines? Commented Sep 28, 2016 at 15:19
  • 1
    Would it not be better just to put/import your "reading" function into that script you are passing numbers into or is there some restrictions out of your hands? Commented Sep 28, 2016 at 15:20
  • @L3viathan Yes, each number would be a new argument together with the word "suspend" Commented Sep 28, 2016 at 15:25
  • @MooingRawr Well the "Suspend.py"script is not mine and i dont how it works and Im pretty sure i can`t change anything on it. Commented Sep 28, 2016 at 15:25
  • is that IPC? it seems strange to do this Commented Sep 28, 2016 at 15:31

1 Answer 1

2

If I understand you correctly:

import subprocess

with open("file_with_numbers.txt") as f:
    for line in f:
        subprocess.call(["python", "Suspend.py", "suspend", line.strip()])
Sign up to request clarification or add additional context in comments.

2 Comments

Another question before i try executing this: The Suspend script also has 2 outputs, he can output OK or error, if i execute this script will i be able to see these outputs?
Look into subprocess.check_output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.