title: python - Open filelike object by filename
body: <p>I want to create a filelike object that will later be opened by its filename. Is it possible to do that? I'm looking for something like this:</p>
  
  <pre><code>import io
  
  fileLikeObject = io.BytesIO()
  fileLikeObject.write((b"randomContent")
  fileLikeObject.name = "someFilename.txt"
  
  sameFileAsbefore = open("someFilename.txt", "rb")
  sameFileAsbefore.read()
  </code></pre>
  
  <p>I've looked at <a href="https://stackoverflow.com/questions/42809451/supply-a-filename-for-a-file-like-object-created-by-urlopen-or-requests-get">this thread</a>, but the file is not accessible by its name afterwards.</p>
  
  <p>For completeness, what I want to specifically do is to generate a sinusoidal waveform and play in an Android environment. Here is a code adapted from <a href="https://stackoverflow.com/questions/44089196/kivy-doesnt-play-sound-file-the-first-time-play-is-called">this answer</a>.</p>
  
  <pre><code>from kivy.core.audio import SoundLoader
  from kivy.base import runTouchApp
  from kivy.uix.button import Button
  import time
  
  
  # Wave parameters
  fs = 44100 # sampling frequency
  duration = 2 # seconds
  
  # Generating waveforms
  timePoints = np.linspace(0, duration, duration*fs)
  sineWave = np.sin(2 * np.pi * 440 * timePoints) # 440 Hz
  outdata = np.transpose(np.tile(volume*outputWave, (2,1)))
  
  class MyLabel(Button):
      def on_release(self):
          start_time = time.time()
          self.play_sound()
          print("--- %s seconds ---" % (time.time() - start_time))
  
      def play_sound(self):
  
          bytes_out = io.BytesIO()
          wavfile.write(bytes_out, fs, outdata)
          bytes_out.seek(0)
  
          sound = SoundLoader.load(bytes_out) # only loads by filename :/
          sound.seek(0)
  
          if sound:
              print("Sound found at %s" % sound.source)
              print("Sound is %.3f seconds" % sound.length)
              sound.play()
  
  runTouchApp(MyLabel(text="Press me for a sound"))
  </code></pre>
  
  <p>I'm also open to other solutions that allow me to play machine-generated sounds on Android. Thanks for helping!</p>