You can’t index (__getitem__
) a _io.TextIOWrapper
object. What you can do is work with a list
of lines. Try this in your code:
lst = open(input("Input file name: "), "r").readlines()
Also, you aren’t closing the file
object, this would be better:
with open(input("Input file name: ", "r") as lst: print(medianStrat(lst.readlines()))
with
ensures that file get closed, see docs
Related Posts:
- TypeError: not all arguments converted during string formatting python
- WinError 2 The system cannot find the file specified (Python)
- Could not find a version that satisfies the requirement tensorflow
- Could not find a version that satisfies the requirement tensorflow
- Local variable referenced before assignment?
- TypeError: write() argument must be str, not bytes (Python 3 vs Python 2 )
- Change figure size and figure format in matplotlib
- TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Type error Unhashable type:set
- What is the meaning of “int(a[::-1])” in Python?
- dump() missing 1 required positional argument: ‘fp’ in python json
- TypeError: module.__init__() takes at most 2 arguments (3 given)
- Python cant convert ‘list’ object to str error [closed]
- Does python have header files like C/C++?
- SyntaxError: unexpected EOF while parsing
- How to use filter, map, and reduce in Python 3
- Use Gif Logo For Loading Screen In Kivy
- Praw & Discord.py: The bot keep sending the same meme. I want the bot to send different meme whenever it is asked
- How can I make a time delay in Python? [duplicate]
- Python – TypeError: ‘int’ object is not iterable
- TypeError: ‘int’ object is not subscriptable
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How to open a file using the open with statement
- Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
- How to install pip with Python 3?
- What is the difference between rw+ and r+
- Python – TypeError: ‘int’ object is not iterable
- Import Error: No module named numpy
- Python: ‘ModuleNotFoundError’ when trying to import module from imported package
- Relative imports – ModuleNotFoundError: No module named x
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- How to uninstall a package installed with pip install –user
- not all arguments converted during string formatting.. NO % variables
- Python Variable Declaration
- Relative imports in Python 3
- TypeError: ‘int’ object is not callable
- TypeError: ‘int’ object is not callable
- working of \n in python [duplicate]
- Pip freeze vs. pip list
- TypeError: ‘int’ object is not callable
- Best way to convert string to bytes in Python 3?
- Best way to convert string to bytes in Python 3?
- What does the list() function do in Python?
- PermissionError: [Errno 13] Permission denied
- Cannot find module cv2 when using OpenCV
- What is setup.py?
- How is Anaconda related to Python?
- Cannot find module cv2 when using OpenCV
- Python ‘If not’ syntax [duplicate]
- FileNotFoundError: [WinError 2] The system cannot find the file specified:
- RuntimeWarning: invalid value encountered in divide
- Converting dictionary to JSON
- Invalid character in identifier
- Using Python 3 in virtualenv
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- “Series objects are mutable and cannot be hashed” error
- How to remove EOFError: EOF when reading a line?
- IndexError: tuple index out of range —– Python
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- hashlib.md5() TypeError: Unicode-objects must be encoded before hashing
- TypeError: cannot unpack non-iterable NoneType object
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- Is there a ‘foreach’ function in Python 3?
- Python inline if statement
- How to install python3 version of package via pip on Ubuntu?
- Updating a dictionary in python
- django: TypeError: ‘tuple’ object is not callable
- TypeError: cannot perform reduce with flexible type
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- Convert bytes to a string
- How to copy a dictionary and only edit the copy
- How to print like printf in Python3?
- I keep getting this error for my simple python program: “TypeError: ‘float’ object cannot be interpreted as an integer”
- ln (Natural Log) in Python
- AttributeError: ‘module’ object has no attribute ‘urlopen’
- ImportError: numpy.core.multiarray failed to import
- Python Error: AttributeError: __enter__ [duplicate]
- Can’t fix “zipimport.ZipImportError: can’t decompress data; zlib not available” when I type in “python3.6 get-pip.py”
- Python Traceback (most recent call last)
- TypeError: ‘float’ object not iterable
- TypeError: ‘type’ object is not subscriptable when indexing in to a dictionary
- Unable to plot Double Bar, Bar plot using pyplot for ndarray
- How to pip or easy_install tkinter on Windows
- TypeError: ‘list’ object cannot be interpreted as an integer
- ‘method’ object is not subscriptable. Don’t know what’s wrong
- Cannot find module cv2 when using OpenCV
- Invalid character in identifier
- Importing class from another file [duplicate]
- filedialog, tkinter and opening files
- pip or pip3 to install packages for Python 3?
- Convert list to tuple in Python
- ImportError: numpy.core.multiarray failed to import
- error UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte
- Error in Python script “Expected 2D array, got 1D array instead:”?
- csv.Error: iterator should return strings, not bytes
- NameError: global name ‘xrange’ is not defined in Python 3
- Error: ” ‘dict’ object has no attribute ‘iteritems’ “
- What does “SyntaxError: Missing parentheses in call to ‘print'” mean in Python?