title: use string as regular text in code
body: <p>the code reads a txt file with numbers divided as </p>
  
  <pre><code>537, 487, 1115, 652\n
  1265, 395, 1629, 693\n
  </code></pre>
  
  <p>the code reads the txt file and divides "\n" leaving a list like:</p>
  
  <pre><code>['537, 487, 1115, 652','1265,395,1629,693']
  </code></pre>
  
  <p>I need to use each string as a regular text in my code to crop an image using PIL
  so I'd like to know if there is a way to get rid of the 'string' so in code it would look like that:</p>
  
  <pre><code>img2 = img.crop((537, 487, 1115, 652))
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>img2 = img.crop(('537, 487, 1115, 652'))
  </code></pre>
  
  <p>the code looks like this:</p>
  
  <pre><code>import os, sys
  from PIL import Image
  import PIL.ImageOps
  
  lines = [line.rstrip('\n') for line in open('file.txt')]
  
  for i in range(0, len(lines)):
  
      img = Image.open("data\\image.jpg")
      img2 = img.crop((int(lines[i])))
      inimg = PIL.ImageOps.invert(img2)
      inimg.save("data\\orcropinverted.jpg")
  </code></pre>
  
  <p><em>I know I could use a different approach and convert each number into an int but I'd like to know if it could be done that way.</em></p>
  
  <p>EDIT:</p>
  
  <p>I figured something out with <a href="https://docs.python.org/3.4/howto/regex.html" rel="nofollow noreferrer">re</a> but it is not what I am looking for, anyway works...</p>
  
  <pre><code>import os, sys
  import re
  from PIL import Image
  import PIL.ImageOps
  
  lines = [line.rstrip('\n') for line in open('file.txt')]
  
  for i in range(0, len(lines)):
  
      p = re.compile('\d+')
      sgline = p.findall(lines[i])
  
      img = Image.open("data\\image.jpg")
      img2 = img.crop((int(sgline[0]),int(sgline[1]),int(sgline[2]),int(sgline[3])))
      inimg = PIL.ImageOps.invert(img2)
      inimg.save("data\\orcropinverted.jpg")
  </code></pre>