title: How to print a list of things in columns?
body: <p>Currently I am working on some <code>selenium</code> code and I wrote a code to simply go to some website, search for a few products and then list them. Everything works good except one thing. I want to print the products in this format:</p>
  
  <pre><code> 1. &lt;name&gt;\t&lt;price&gt;
   2. &lt;name&gt;\t&lt;price&gt; ...
  </code></pre>
  
  <p>The problem is that some of the products (in my particular case one of them) names are longer than the other, which produces output like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>1. Nóż Benchmade 62 Balisong    1 275,00 zł
  2. Nóż Benchmade 63 Balisong Bowie      1 290,00 zł
  3. Nóż Benchmade 67 Balisong    1 295,00 zł
  4. Nóż Benchmade 87 Ti Balisong 2 235,00 zł
  </code></pre>
  
  <p>As you can see, if I just add one or two <code>\t</code>s, it would be okay, but I don't think it's a particularly good way to do this. </p>
  
  <p>So the question is: How do I align text in column-way without manually calculating the size of the longest record in the column? (Maybe there is a standard lib-way to do this, or maybe 3rd party lib?)</p>
  
  <p>Edit: I've added the code:</p>
  
  <pre><code>from selenium import webdriver
  
  class Product:
      def __init__(self, name, price):
          self.name = name
          self.price = price
  
      def __str__(self):
          return f'{self.name}\t{self.price}'
  
      def __repr__(self):
          return f'Product({self.name})'        
  
  def search_for(driver, input_name, query):
      search_field = driver.find_element_by_name(input_name)
      search_field.clear()
      search_field.send_keys(query)
      search_field.submit()
  
  
  def create_products(driver):
      found_elements = driver.find_elements_by_xpath("//div[@class='wrapper']")
      names = [
          fe.find_element_by_xpath(".//img[@alt]").get_attribute("alt")
          for fe in found_elements
      ]
      products = []
      int_parts = driver.find_elements_by_xpath(
          "//span[@class='price']/span[@class='price-integer-part']")
      decimal_parts = driver.find_elements_by_xpath(
          "//span[@class='price']/span[@class='price-decimal-part']")
      currencies = driver.find_elements_by_xpath(
          "//span[@class='price-currency']")
      for info in zip(names, int_parts, decimal_parts, currencies):
          name, int_part, decimal_part, currency = info
          price = f'{int_part.text},{decimal_part.text} {currency.text}'
          products.append(Product(name, price))
      return products
  
  
  def main():
      driver = webdriver.Chrome()
      driver.implicitly_wait(30)
      driver.maximize_window()
  
      driver.get('https://kolba.pl')
      search_for(driver, 'query', 'benchmade balisong')
      products = create_products(driver)
      print(f'Found {len(products)} products:\n')
      for i, product in enumerate(products):
          print(f'{i+1}. {product}')
  
  
  if __name__ == '__main__':
      main()
  </code></pre>