title: how to save the output of a python file that has been looped in another python file?
body: <p>this code send generates a random json file of user ids provided and btw range is also given..</p>
  
  <p>so this code outputs 50 jsons for each user.</p>
  
  <p>Lets name this code as first.py </p>
  
  <p>this code generates the json randomly and by using grpcul i ll send the data .  </p>
  
  <p>so first.py code : </p>
  
  <pre><code>import faker
  import json
  from faker import Faker
  import random
  from random import randint
  import subprocess
  import json
  import os
  #subprocess.call([""])
  from pprint import pprint
  
  ids= ('5cda','6cda')
  
  fake = Faker('en_US')
  
  for ind in ids:
      cont = []
      #Overall dictionary with first and user_ids
      dct = {}
      for idx in range(50):
  
          sms =  {
              "id":"AB-asfgw",
              "body": fake.text(),
              "mime": fake.ean(),
              "hashed": fake.ean(),
              "pid": fake.ean(),
              "user_id": ind,
              "text": fake.sentence()
          }
          cont.append(sms)
  
      dct['messages'] = cont
      dct['user_id'] = ind
      #print(dct)
      f_name = '{}.json'.format(ind)
      with open(f_name, 'w') as fp:
          #Save the dictionary
          json.dump(dct, fp, indent=4)
          print('saved {}'.format(f_name))    
  
  auth = "authorization: token 1324"
  file = "5cda.json"
  fd=open("5cda.json")
  json_content = fd.read()
  fd.close()
  
  
  subprocess.run(["grpcurl", "-plaintext","-H", auth,"-d",json_content,"-format","json","100.20.20.1:5000","api.Service/Method"])
  
  
  </code></pre>
  
  <p>using subprocess to run this code and <code>subprocess.run(["grpcurl", "-plaintext","-H", auth,"-d",json_content,"-format","json","100.20.20.1:5000","api.Service/Method"])</code> </p>
  
  <p>So I am trying to loop the program in another program... so i need the saving part to be done in loop.py so that i can limit the first program</p>
  
  <p>so i wrote a another small code to loop the first code. But the problem i faced is to store the data im sending as i am using faker library and it generates random data.</p>
  
  <p>So my second code lets call it as second.py </p>
  
  <p>code : </p>
  
  <p>this second.py code loops the first code 20 times </p>
  
  <pre><code>from datetime import datetime
  import faker
  import json
  from faker import Faker
  import random
  from random import randint
  import subprocess
  import json
  import os
  #subprocess.call([""])
  from pprint import pprint
  import subprocess
  import sys
  
  
  
  for i in range(20):
      subprocess.call(['python','grploop1.py'])
  
  </code></pre>
  
  <p>this above code will run and sends the data and data is geting invoked sussecfully. What is need is to store the data i m sending as it is from faker it is randomly sent. </p>
  
  <p>So <em>OUTPUT</em> i need is in my second.py code i need to somehow store the json file i am looping and sending. I need to store the data. Read subprocess.output does that but couldn't figure out..   I need the implementation should be done in second.py and first.py doesnt change....</p>