title: How do I create a file like object that can return an arbitrarily large amount of repeating data?
body: <p>For use with subprocess.run's stdin argument, I am trying to create a file like object that will return the same sequence of either characters or bytes as many times as I like. I would like it to look something like this:</p>
  
  <pre><code>&gt;&gt;&gt;file_like3 = FileLike("Repeating sequence\n", 3)
  &gt;&gt;&gt;print(file_like3.read())
  Repeating sequence
  Repeating sequence
  Repeating sequence
  
  &gt;&gt;&gt;file_like5 = FileLike("print('print through subprocess')\n", 5)
  &gt;&gt;&gt;p = subprocess.run(["python"], stdin = file_like5, stdout = subprocess.PIPE)
  &gt;&gt;&gt;print(p.stdout)
  b'print through subprocess\nprint through subprocess\nprint through subprocess\nprint through subprocess\nprint through subprocess'
  </code></pre>
  
  <p>I would like to do this so that I can emulate a file of arbitrary length without actually creating or reading the file. Since I need this as an input to subprocess.run, I think doing something similar but extending bytearray instead of a file object would work for me as well. It seems like I would need to overwrite whichever methods subprocess.run uses from the file or bytearray object, but I have no idea how to figure out which methods those are.</p>