title: Assigning values from a text file into a variable that can be used for next step in python
body: <p>I am very new to python scripts. I wanted to create a script that can opened a text file, c_name.txt where the content of the text file would be list of cell names. After i opened, i need to assign all the cell names as a variable. This is because i need the cell name to open up the next directory which requires the cell name. What i did for now is to open the text file and print the cell names. I do not know on how to read the cell name and assign to a variable. Do i need to assign all the cell names into an array?</p>
  
  <p>I also need to classify if cell name starts with ce_, then the report files will be in ce_ directory whereas if the cell name starts with cell, then the report files will be in cell directory.</p>
  
  <p>Here is my c_name.txt:</p>
  
  <pre><code>ce_clk
  celladd
  ce_sum
  cellsub
  </code></pre>
  
  <p>Here is the updated code:</p>
  
  <pre><code>#!/usr/bin/python
  
  import os
  import os.path
  
  myPWD = os.getcwd()
  
  # Implement functions get_test_directory and get_library_directory
  # to retrieve correct directory paths
  def get_test_directory( str ):
      return str
  
  def get_library_directory (str ):
      os.chdir('..')
      str = os.getcwd()
      return str
  
  test_directory = get_test_directory(myPWD)
  library_directory = get_library_directory(myPWD)
  
  cell_names_file = os.path.join(test_directory, "c_name.txt")
  
  with open(cell_names_file, "r+") as f1:
      cell_names = f1.readlines()
  
  for cell_name in cell_names:
      cell_directory = "ce_" if cell_name.startswith("ce_") else "cell"
      floc2 = os.path.join(library_directory, cell_directory, "{0}.rpt".format(cell_name))
      with open(floc2, "r+") as f2:
          for line in f2:
                   print line
  </code></pre>
  
  <p>NEW EDITED:
  I am having another problem with line startswith  on making it more generic instead of using hardcoded like below:</p>
  
  <pre><code>for cell_name in cell_names:
          cell_directory = "ce_" if cell_name.startswith("ce_") else "cell"
          floc2 = os.path.join(library_directory, cell_directory,{0}.rpt".format(cell_name))
  </code></pre>
  
  <p>For now I am using "ce_" and "cell", is it possible to like ask the script to read the cell_name first 3 char, which is "ce_" and "cel" instead of defining it myself. I tried using this line but it seems not working as it shows error:</p>
  
  <pre><code>cell_directory = cell_name.startswith(cell_name,0,5)
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>AttributeError: 'bool' object has no attribute 'startswith'
  </code></pre>