Q:

Python -- Quotations around filenames

I'm not quite sure when I need to put quotations around the filenames in Python.
For example, when I set
f = open(file)

I can run something like
len(f.read())

and it will run fine.
However, when I do it directly, it only works with
len(open("file").read())

Likewise, in terminal when running from Python I always have to use quotations.
What is the 'rule' when using quotations?   
Thank you.

A:

In python you can always use the name of a variable or function outside quotations, but the name of a file is usually not a variable.  
If file is the name of a string variable you can always do open(file).read(), however if it is literally the filename you must always do open("file").read().

