Popular python problems and solutions

Tags: ,

Python is a popular programming language that can be used to conduct almost any project. When you learn python, you may come up with different questions regarding various tasks such as file processing, list, dict usage, database, time, url, et al.  In this tutorial, we give clean solutions to some of the most frequently problems you may encounter when you learn python.

  1. File related questions

    How to check whether a file exists using Python?

    How to check whether a path is a file?

    How to make sure an directory exist?

    How to list all files of a directory in Python?

    How to read a file line by line into a list with Python?

    How to append a line to file in Python?

    How to remove a file in Python?

  2. Dictionary Related Questions

    How to create a dictionary?

    How to add key to a dictionary in Python?

    Check if a given key already exists in a dictionary

    Sort a Python dictionary by value

    Use operator

    Use Lambda

    how to merge two dictionaries in Python?

  3. List Related Questions:

    How to check if a list is empty?

      

    What’s the difference between the list methods append() and extend()?

    So append: Appends object at end.

    However, extend: Extends list by appending elements from the iterable.

  4. Time related Questions

    How to get current time in python?

    How to convert String to time object?

     
  5. Database Related questions

    How do I connect to a MySQL Database in Python?

    Install MySQLdb from http://www.kitebird.com/articles/pydbapi.html, then 

    Use MySQL Connector/Python from MySQL: http://dev.mysql.com/downloads/connector/python/.