First, I don't recommend naming your variable file because file() is a built-in alias to the open() function in Python. You can do this. But I recommend against it as many Python programmers will cringe when they see it.
Perhaps "in_filename" for the input filename and "inputfile" for the file() object.
More to the point once you have the open file you have to call methods on it (explicitly or implicitly) in order to use the contents of the file.
There are several ways to do this. (As others have pointed out you should use os.path.join() to portably combine a path to a base filename):
#!python
import os
path = '/some/path'
in_filename = 'somefile.txt'
inputfile = open(os.path.join(path, in_filename), 'r')
data = inputfile.read() # fetch all contents in one string
inputfile.seek(0) # reset file object point to beginning of file
data_lines = inputfile.readlines() # fetch all contents as list of lines
inputfile.seek(0) # rest file object again
while True:
line = inputfile.readline() # one line at a time (line is a string)
if not line:
break # length of line is zero at end of file
# Note: empty strings are "False" in Python; so this detects EOF
inputfile.close() # close inputfile
# alternatively using "context management" features
with open(os.path.join(path, in_filename), 'r') as infile:
for line in infile:
do_something(line)
# infile is implicitly closed on exit from the context management "suite"
# (indented block of code)
In this sample I'm showing how to slurp in the entire file as a single string; how to slurp it in as a list of lines, how to iterate over it line-by-line and how to use the "context manager" (with statement) to iterate over it line-by-line).
Notice that iterating over a file is implicitly calling the .readline() (singular) method. (That's actually orthogonal to the with context management we used to open it. with only guarantees that the file will be automatically closed after the end of our indented block of code ... even if some exception were raised by the open or any other operations we preformed on it. for ... in ...: creates and iterator and uses it; and many objects in Python define iteration semantics. For files that's based on calls to .readline())
I'm also showing how to .seek() back to the beginning of the file (which you might not do often but in this case it's a way to show all these alternative ways of reading the file without having to repeatedly .close() and re-open it).
Note that I'm explicitly use the access option in my open() call to declare that my file handler will be read-only. If I wanted to read from and write to the file I'd use 'w+' and so on).
I'm not showing the option to the .read() method which allows you to specify the amount of data you wish to read for each call. For normal text files this is generally not very useful because then you'd have to handle any partial lines yourself which is rather messy code. If you were to attempt to read some very large file using my examples then you might cause your system to page/swap and suffer some drastic performance and responsiveness issues with your system. (On a typical, modern, laptop you'll be fine so long as the file is less than a gigabyte or two in size).
Using .read(xxx) (with specific numbers of characters to be read for any call) can be useful if you have a file containing fixed length records (text or binary). However, it's rare these days for anyone to manipulation fixed length file structures using Python or other scripting languages. If you were dealing with non-text file (such as manipulating the headers of MP3 files, or images, etc, then you might use such methods (and you'd likely want to also use the struct module to "pack" data from its textual representation into the specific machine-native representation required by your binary file formats).
os.path.join(and possiblywithas a context manager for the file),machineorinputfileare not strings, but ints or some other type, in which case you should convert it to string usingstr(machine)orstr(inputfile)before concatenating them with+.