Opening a file in python for reading is easy:
f = open('example.txt', 'r')
To get everything in the file, just use read()
file_contents = f.read()
And to print the contents, just do:
print (file_contents)
Don’t forget to close the file when you’re done.
f.close()
More Related Contents:
- How to install python3 version of package via pip on Ubuntu?
- error: command ‘gcc’ failed with exit status 1 while installing eventlet
- using pip3: module “importlib._bootstrap” has no attribute “SourceFileLoader”
- How to tell if tensorflow is using gpu acceleration from inside python shell?
- How to install lxml on Ubuntu
- Renaming a virtualenv folder without breaking it
- Error while importing Tensorflow in Python 2.7 in Ubuntu 12.04. ‘GLIBC_2.17 not found’
- Unable to set default python version to python3 in ubuntu
- How to Run Python Code on SublimeREPL
- How would I build python myself from source code on Ubuntu?
- Python: Unable to Render Tex in Matplotlib
- Unable to install Python packages using pip in Ubuntu Linux: InsecurePlatformWarning, SSLError, tlsv1 alert protocol version
- WARNING: Running pip as the ‘root’ user
- How do I ‘lock the keyboard’ to prevent any more keypresses being sent on X11/Linux/Gnome?
- Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding, when trying to start uwsgi
- I have Python on my Ubuntu system, but gcc can’t find Python.h
- Uninstall python built from source?
- Flask broken pipe with requests
- Installing OpenCV for Python on Ubuntu, getting ImportError: No module named cv2.cv
- ImportError: No module named bz2 for Python 2.7.2
- How to find which version of TensorFlow is installed in my system?
- Cannot open new Jupyter Notebook [Permission Denied]
- Could not find a version that satisfies the requirement for select requirements
- No plot window in matplotlib
- No module named ‘openpyxl’ – Python 3.4 – Ubuntu
- Python 2.7 on Ubuntu
- How to Copy/Clone a Virtual Environment from Server to Local Machine
- downloading error using nltk.download()
- what is the codec for mp4 videos in python OpenCV
- Execute a command on Remote Machine in Python