FAQ Database Discussion Community


Adding stripped line to string/array in Python

python,strip,readlines,startswith
I am a fairly new programmer. I am currently trying to find data from .txt files and add them to a string or array, which will then eventually be added to a .csv file. The data I am looking at are currently present in this form, numerous times at random...

Python list of lists no loops

python,list,python-3.x,readlines
So full disclosure, this is hw, but I am having a lot of difficulty figuring this out. My professor has a rather particular challenge in this one portion of the assignment that I can't quite seem to figure out. Basically I'm trying to read a very very large file and...

how to adding new tab in readline python

python,readlines
I have a problem can't adding a new tab in reading file. I've tried readline, but I am confused.. f = open('data.txt', 'r') count = 0 for i in f.readlines(): count += 1 if count == 3: #adding new tab print i, In here, I have data.txt which contains data...

Read lines from Multiple files

python,multiple-files,readlines
I have two files: A: John Kevin Richard B: Manager Salesperson Doctor I am trying to read lines from both the files simultaneously and print the following: Output: John is a Manager Kevin is a Salesperson Richard is a Doctor I tried using contextlib.izip package but it's not working. Code:...

Python Consecutive Reads From File

python,input,readlines
I have a Python script that is reading from a file. The first command counts the lines. The second one prints the second line although the second one is not working. lv_file = open("filename.txt", "rw+") # count the number of lines ================================= lv_cnt = 0 for row in lv_file.xreadlines(): lv_cnt...

Python pandas : dataframe read rows (readlines)

pandas,dataframes,readlines
I have a dataframe that was produced by pandas, for example: d = {'one':[1,1],'two':[2,2], 'three':[3,3]} i = ['a','b','c'] df = pd.DataFrame(data = d, index = i) df one two three a 1 2 3 b 1 2 3 c 1 2 3 I now need to read each row with...

== comparisons against lines from readlines() fail

python,anagram,readlines
I am currently working on a small anagram program that takes all possible permutations of a word and compare them with a dictionary. However, I am unable to get the results to print. The culprit appears to be the == operator, if I put ''.join(words[i]) == compare[j] nothing prints, however,...

Simple login function in Python

python,function,login,readlines
def login(): user = raw_input("Username: ") passw = raw_input("Password: ") f = open("users.txt", "r") for line in f.readlines(): us, pw = line.strip().split("|") if (user in us) and (passw in pw): print "Login successful!" return True print "Wrong username/password" return False def menu(): #here's a menu that the user can access...

how to read a list of tuples in Python

python,list,readlines
all, I am learning Python, and I am wondering how to read a list of tuples, which stored in a txt file, as in the following case: I have a txt file called scores.txt with the following format: ('name1', 8) ('name2', 2) ('name3', 4) ... Now I want to read...