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
0
votes
1 answer

Linecache in python is not caching the lines specified

I am using linecache to get the lines before the occurrence of a string. But it is not working. I cannot understand what the problem is? with open(fileName, 'r') as inFile: between = False for num, line in enumerate(inFile, 1): …
mash
  • 35
  • 10
0
votes
2 answers

select specific lines with specific condition from a large text file with python

I have a text file which has 5 columns and more than 2 million lines as follows, 134 1 2 6 3.45388e-06 135 1 2 7 3.04626e-06 136 1 2 8 4.69364e-06 137 1 2 9 4.21627e-06 138 1 2 10 2.38822e-06 139 1 2 …
poya_89
  • 1
  • 2
0
votes
1 answer

linecache doesn't work in an if statement?

import linecache for i in range (4): file = open("looptestofreceivingquestions.txt", "r") lineq = i+1 print(linecache.getline("looptestofreceivingquestions.txt", lineq))#gets line q depending on iteration question = input("what is…
0
votes
1 answer

Linecache getline does not work after my application was installed

I am creating a tool that gives an overview of hundredths of test results. This tool access a log file, checks for Pass and Fail verdicts. When it is a fail, I need to go back to previous lines of the log to capture the cause of failure. The…
matdg
  • 33
  • 4
0
votes
1 answer

Error in reading a file using line number in python

I was trying to read data from a xml file into python, My file looks like this, 1. 2. 3. 1.0144E+05 296.34 24.34 2.36E-02 9.18E-09 4. 1.0132E+05…
caty
  • 81
  • 2
  • 13
0
votes
1 answer

Python: linecache.getline not working as intended

I have a directory with numerous subdirectories. At the bottom of the directories there are some .txt files i need to extract line 2 from. import os import os.path import linecache for dirpath, dirnames, filenames in os.walk("."): for filename…
cc6g11
  • 477
  • 2
  • 10
  • 24
0
votes
1 answer

Concatenate input from two different files into a separate file

I want to generate the following line(s) 1 & {\QPCSymbols\XeTeXglyph 2} & \textarabic{الحمدلله} & \texttt{!} & \verb$\XeTeXglyph 2$ \\ \hline Let's say the first number is n and the second one is n+1, the contents of \textarabic is obtained from…
Khalid Hussain
  • 345
  • 4
  • 16
0
votes
1 answer

Py2exe unable to use linecache

I have the following section of code that works perfectly when I run it as a .py file. When I convert it to a .exe using py2exe it appears that the linecache.getline() function is not working properly. I am able to create and write the .txt file…
jarograv
  • 1
  • 1
0
votes
2 answers

How to get three integers from a specific line in a file with Python?

I have a (ASCII) file, foo.txt, which has a lot of stuff in it but I only care about the three numbers on line 2 (separated by white space). For your information (I don't know if it will be relevant) the number of columns on the lines before and…
NeutronStar
  • 2,057
  • 7
  • 31
  • 49
0
votes
1 answer

Can't handle 1.9.x error when trying to install linecache with Ruby 2.1.1

I am trying to install linecache with RVM on Ruby 2.1.1. $ ruby --version ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] I run bundle install $ bundle install It blows saying it isn't compatible with 1.9.x when I run bundle…
Geremy
  • 2,415
  • 1
  • 23
  • 27
0
votes
1 answer

Extracting specific variables of a line with linecache

I'm currently using the python linecache module to grab specific lines from a given text document and create a new file with said line. For example, part of the code looks like: cs = linecache.getline('variables.txt', 7) cs_1 = open("lo_cs",…
user2068783
  • 1
  • 1
  • 4
0
votes
0 answers

Python executable cannot read file

Given below is the code that I am using to read values form a file import linecache line_number=line_number+1 linecache.getline("write.txt", line_number) I am using py2exe to convert the file into an executable. The problem is after conversion to…
praxmon
  • 5,009
  • 22
  • 74
  • 121
0
votes
1 answer

Python keeps refering to outdated variables

I have a kinda weird problem, here is my attempt at an explanation: I'm currently making a program which opens a txt file and then reads a line for that file, using the following command linecache.getline(path,number), after the function is done I…
user3481433
0
votes
1 answer

Memory error while parsing files in a folder

I'm using python 2.7 Here is my code to parse files in a folder import linecache import glob path = r"G:\test\folder1" Key = '''testresult="NOK"''' Files = glob.glob(path+'\*.xml') for FileName in Files: Loop_Count = 1 while Loop_Count!=…
user19911303
  • 449
  • 2
  • 9
  • 34
0
votes
1 answer

intalling linecache-0.46 gem(I am using rbenv)

While bundle install the error: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /home/launchpad/.rbenv/versions/1.9.3-p448/bin/ruby extconf.rb Can't handle 1.9.x yet * extconf.rb failed * Could not create…