You can import modules but not text files. If you want to print the content do the following:
Open a text file for reading:
f = open('words.txt', 'r')
Store content in a variable:
content = f.read()
Print content of this file:
print(content)
After you’re done close a file:
f.close()
Related Posts:
- Call a function from another file?
- Importing variables from another file?
- How do I copy a file in Python?
- How do I copy a file in Python?
- How to open a file using the open with statement
- Using “with open() as file” method, how to write more than once? [duplicate]
- How to read a file line-by-line into a list?
- Import Error: No module named numpy
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Confused by python file mode “w+”
- File open and close in python
- Do I understand os.walk right?
- FileNotFoundError: [Errno 2] No such file or directory [duplicate]
- How to move a file in Python?
- beyond top level package error in relative import
- Python open() gives FileNotFoundError/IOError: Errno 2 No such file or directory
- FileNotFoundError: [Errno 2] No such file or directory
- How to move a file in Python?
- beyond top level package error in relative import
- How do you append to a file?
- `from … import` vs `import .` [duplicate]
- Writing a list to a file with Python
- Why do I get “Pickle – EOFError: Ran out of input” reading an empty file?
- beyond top level package error in relative import
- ImportError: No module named ‘pygame’
- How do I copy a file in Python?
- ImportError: No module named ‘pygame’
- Python – from . import
- How do I check whether a file exists without exceptions?
- Writing a list to a file with Python
- How can I check file size in Python?
- Python list directory, subdirectory, and files
- Where does this come from: -*- coding: utf-8 -*-
- Open file in a relative location in Python
- Why am I getting a FileNotFoundError?
- Python: Write array values into file
- How to copy files?
- Flask raises TemplateNotFound error even though template file exists
- Search and replace a line in a file in Python
- Can’t import my own modules in Python
- How to save a dictionary to a file?
- How to open a file for both reading and writing?
- How do you read a file into a list in Python?
- SSL error : routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
- What is the perfect counterpart in Python for “while not EOF”
- What does “Symbol not found / Expected in: flat namespace” actually mean?
- .write not working in Python
- Creating files and directories via Python
- How to convert a file into a dictionary?
- Purpose of python antigravity module
- How to delete a specific line in a file?
- Python read in string from file and split it into values
- Python name ‘os’ is not defined
- Difference between import tkinter as tk and from tkinter import
- Python 3.6 import requests
- How often does python flush to a file?
- How to open every file in a folder
- TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
- Loading and parsing a JSON file with multiple JSON objects
- How to find out whether a file is at its `eof`?
- Python IOError: File not open for reading
- How to import or include data structures (e.g. a dict) into a Python file from a separate file
- TypeError: only size-1 arrays can be converted to Python scalars (matplotlib)
- Why do I get TypeError: can’t multiply sequence by non-int of type ‘float’?
- Writing a pandas DataFrame to CSV file
- TypeError: ‘type’ object is not subscriptable when indexing in to a dictionary
- Error: all the input array dimensions except for the concatenation axis must match exactly
- Expected 2D array, got 1D array instead error
- How to prevent errno 32 broken pipe?
- The equivalent of a GOTO in python [duplicate]
- tkinter gui with progress bar
- Invalid character in identifier
- if else in a list comprehension
- How can I install Python’s pip3 on my Mac?
- convert json ipython notebook(.ipynb) to .py file
- how to update spyder on anaconda
- Django upgrading to 1.9 error “AppRegistryNotReady: Apps aren’t loaded yet.”
- Pygame Drawing a Rectangle
- Create a Pandas Dataframe by appending one row at a time
- ModuleNotFoundError: No module named ‘discord’
- No numeric types to aggregate – change in groupby() behaviour?
- Euclidean Algorithm / GCD in Python
- Pandas split DataFrame by column value
- Using numpy to build an array of all combinations of two arrays
- Get a random sample with replacement
- What is a “slug” in Django?
- Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll
- if else function in pandas dataframe
- Primality test in python [duplicate]
- Flask-SQLalchemy update a row’s information
- Inline for loop
- Read data (.dat file) with Pandas
- Sorting list of lists by the first element of each sub-list
- Install py2exe for python 2.7 over pip: this package requires Python 3.3 or later
- What is the correct format to write float value to file in Python
- How is Python’s List Implemented?
- Pip: could not find a version. No matching distribution found
- Compare two columns using pandas
- ValueError: total size of new array must be unchanged
- Shuffle an array with python, randomize array item order with python