title: How to pass MongoDB collection name as a parameter to a DB connection function-Python
body: <p>I need to write a DB connection function as , </p>
  
  <pre><code>def func(col_name):
      conn = pymongo.MongoClient("localhost" , 27017)
      db   = conn.dbname.col_name
      return db
  </code></pre>
  
  <p>collection name should be passed as a parameter to the function. Above function is not working. it is working if I hard-coded the collection name in the code.
  Please help.  </p>