title: Naming elements of a list with `with` statement
body: <p>I want to refer to an element (<code>mem[0]</code>) of a list (<code>mem</code>) with a different name (<code>fetch</code>):</p>
  
  <pre><code>mem = [0]
  f = open("File.lx", "rb").read()
  for b in f: mem += [b]
  size = len(mem)
  
  while mem[0] &lt; size:        #using mem[0]
      char = (mem[0]*2)+1
      source = mem[char]
      target = mem[char + 1]
  
      mem[0] += 1
      mem[target] = mem[source]
  </code></pre>
  
  <p>And I tried that with the <code>with</code> statement:</p>
  
  <pre><code>mem = [0]
  f = open("File.lx", "rb").read()
  for b in f: mem += [b]
  size = len(mem)
  
  with mem[0] as fetch:        #with statement
     while fetch &lt; size:       #using mem[0] as fetch
      char = (fetch*2)+1
      source = mem[char]
      target = mem[char + 1]
  
      fetch += 1
      mem[target] = mem[source]
  </code></pre>
  
  <p>But I got an error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\documents\test.py", line 6, in &lt;module&gt;
      with mem[0] as fetch:
  AttributeError: __enter__
  </code></pre>
  
  <p>I thought this would be the way because that's how it's done with file objects:</p>
  
  <pre><code>with open("File.lx", "rb") as file:
      fileBytes = file.read()
  </code></pre>
  
  <p>I read the <a href="https://docs.python.org/3/reference/compound_stmts.html#grammar-token-with-stmt" rel="nofollow noreferrer">docs</a> for the <code>with</code> statement and it says that the <code>__exit()__</code> and <code>__enter()__</code> methods are loaded. According to what I understood after reading that and from the <code>AttributeError</code>, my guess is that sequence elements (<code>mem[0]</code>) do not have an <code>__enter()__</code> method.</p>