Questions tagged [linecache]

This tag refers to the Python linecache unit, which allows random access to the lines of a text file.

This tag refers to the Python linecache unit, which allows random access to the lines of a text file. See https://docs.python.org/2/library/linecache.html

54 questions
1
vote
2 answers

Python: linecache file size limit?

I have a pretty big .txt file. Each entry is on a new line. I am trying to access the file and iterate through each line to grab the entry. However when I use linecache.getline('file_path', 1), I am getting an empty string. Which from the Python…
tjblue
  • 33
  • 1
  • 5
1
vote
2 answers

Replacing numbers in a list of lists with corresponding lines from a text file

I have a big text file like this (without the blank space in between words but every word in each line): this is my text and it should be awesome . And I have also a list like this: index_list = [[1,2,3,4,5],[6,7,8][9,10]] Now I want to…
Lightsaber
  • 13
  • 2
1
vote
1 answer

Why does linecache check for the length of the tuple elements in the cache?

In https://github.com/python/cpython/blob/3.6/Lib/linecache.py there are 3 instances of this In getines def getlines(filename, module_globals=None): if filename in cache: entry = cache[filename] if len(entry) != 1: …
Palash Nigam
  • 1,653
  • 3
  • 14
  • 26
1
vote
2 answers

Comparing 2 variables when one is retrieved from text file

I am trying to write code that compares variable b with value retrieved from text file using linecache.getline The problem is it will never print our "ITS WORKING" because the values never match, even if they do :-( THE TEXT FILE: In the text file…
Bob
  • 347
  • 2
  • 3
  • 12
1
vote
2 answers

Concatenate 2 strings from 2 different lines (From text file) - Using linecache

I am trying to concatenate 2 string from two different lines using linecache but when i try, the output is always on 2 lines not on 1 line. Text in the file: hello world Code: import linecache import…
Bob
  • 347
  • 2
  • 3
  • 12
1
vote
1 answer

Catch line and modify it with python

I'm a newbie in python. I'm currently trying to modify a line in a file, this after catching this line by using linecache. Exemple: run_D = open('toto.dat','r') lines = run_D.readlines() print "Name of the file: ",…
Licia
  • 55
  • 4
1
vote
4 answers

Python : select a specific line from text

i'm trying to make a code that : open a text file go to the lines that start with "Start" go to line 3 from the lines that start with "start" (previously selected) check if that line contain " contain" word if yes = print " ok " : str1 =…
Mehdi ouahabi
  • 67
  • 1
  • 2
  • 11
1
vote
2 answers

Optimizing python file search?

I'm having some trouble optimizing this part of code. It works, but seems unnecessary slow. The function searches after a searchString in a file starting on line line_nr and returns the line number for first hit. import linecache def…
user2987193
  • 133
  • 1
  • 1
  • 7
1
vote
1 answer

ValueError when converting to int lines retrieved via getline.linecache

this is my first message here, I hope I will not commit any mistake. I am writing a python 2.7 script which performs comparisons between lines from a long list of lines provided as an external input file. Some of these lines contain just numbers,…
1
vote
2 answers

Error in "bundle install"

I get this error when I run "bundle install" Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /var/lib/jenkins/.rvm/rubies/ruby-1.9.2-p318/bin/ruby extconf.rb checking for vm_core.h... no checking for…
Shahrzad
  • 207
  • 2
  • 5
  • 14
0
votes
0 answers

How can I check if there is a Specific Word in a fileline?

How can i fix my problem? I want to check if there is a specific word in a Textfile line and then run some code. Can someone please help me? Thanks alot. if key == Key.left: mouse.move(901, 350, absolute=True, duration=0.02) …
0
votes
0 answers

Read GB2312 encoding file with linecache.getline

I need to read specified lines in a GB2312 encoding file with given line numbers. Many people mentioned linecache.getline(file_path,line_no) is the right answer. But it raised UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 72:…
0
votes
0 answers

Python - getline() method not printing "newlines"

I am relatively new to python and I am making a small game that involves importing each line of the text from a .txt file, so that it can be printed to the user. To do this, I'm using linecache.getline() to get the specific line of the file that I…
0
votes
0 answers

Skipping first line of a file when using linecache

I've created a lazy dataloader in Pytorch using linecache. It pulls from a tsv file that I also use to building the vocabulary with Pytorch's build_vocab, so I need to have a header line of titles for each of the columns. For the dataset I'm using…
ebelle
  • 1
  • 2
0
votes
1 answer

linecache-0.43 gem installation issue

I am trying to do a bundle install which includes ruby-debug gem. However the installation fails with the error linecache-0.43 has an invalid value for @cert_chain I ma using rails 2.3.8, ruby 1.8.7 and RubyGems 1.7.1 Any help would be greatly…
Satyam
  • 645
  • 2
  • 7
  • 20