This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: linecache.getline() Returning Error
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: Jordan.Meyer, ned.deily
Priority: normal Keywords:

Created on 2011-08-31 04:29 by Jordan.Meyer, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg143247 - (view) Author: Jordan Meyer (Jordan.Meyer) Date: 2011-08-31 04:29
In trying to use the linecache.getline() function to extra data from a plain-text database format that I'm building. Every time I make a call to it (even from the interpreter directly) I get an error like the one below. I believe the problem lies in the linecache module itself.

Traceback (most recent call last):
  File "/Users/jordanmeyer/Documents/Python/eFlashcard/alpha/0.1a2/eFlashcard_0.1a2.py", line 59, in <module>
    eFlashcard_main()
  File "/Users/jordanmeyer/Documents/Python/eFlashcard/alpha/0.1a2/eFlashcard_0.1a2.py", line 17, in eFlashcard_main
    eFlashcard_build()
  File "/Users/jordanmeyer/Documents/Python/eFlashcard/alpha/0.1a2/eFlashcard_0.1a2.py", line 31, in eFlashcard_build
    while str(linecache.getline(lib_file, lib_index, module_globals=None)) != '':
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/linecache.py", line 15, in getline
    lines = getlines(filename, module_globals)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/linecache.py", line 41, in getlines
    return updatecache(filename, module_globals)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/linecache.py", line 76, in updatecache
    if not filename or (filename.startswith('<') and filename.endswith('>')):
AttributeError: '_io.TextIOWrapper' object has no attribute 'startswith'
msg143250 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-08-31 07:21
The linecache module functions take a filename string as an argument, not a file object.  Try:

   linecache.getlines("/path/to/filename", lineno)

http://docs.python.org/py3k/library/linecache.html
History
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57076
2011-08-31 07:21:29ned.deilysetstatus: open -> closed

type: crash -> behavior

nosy: + ned.deily
messages: + msg143250
resolution: works for me
stage: resolved
2011-08-31 04:29:22Jordan.Meyercreate