Purpose of “%matplotlib inline”

%matplotlib is a magic function in IPython. I’ll quote the relevant documentation here for you to read for convenience: IPython has a set of predefined ‘magic functions’ that you can call with a command line style syntax. There are two kinds of magics, line-oriented and cell-oriented. Line magics are prefixed with the % character and work much like … Read more

How do I check what version of Python is running my script?

This information is available in the sys.version string in the sys module: Human readable: For further processing, use sys.version_info or sys.hexversion: To ensure a script runs with a minimal version requirement of the Python interpreter add this to your code: This compares major and minor version information. Add micro (=0, 1, etc) and even releaselevel … Read more

Using global variables in a function

You can use a global variable within other functions by declaring it as global within each function that assigns a value to it: I imagine the reason for it is that, since global variables are so dangerous, Python wants to make sure that you really know that’s what you’re playing with by explicitly requiring the … Read more

Function for Factorial in Python

Easiest way is to use math.factorial (available in Python 2.6 and above): If you want/have to write it yourself, you can use an iterative approach: or a recursive approach: Note that the factorial function is only defined for positive integers so you should also check that n >= 0 and that isinstance(n, int). If it’s not, raise a ValueError or a TypeError respectively. math.factorial will take care of this for … Read more

ValueError: invalid literal for int() with base 10: ”

I am creating a program that reads a file and if the first line of the file is not blank, it reads the next four lines. Calculations are performed on those lines and then the next line is read. If that line is not empty it continues. However, I am getting this error: ValueError: invalid … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)