I'm a beginner with Python and would appreciate some help. I'm having trouble with the code below as I can't split a file. In my text file I have Gem11 and Gem12 on separate lines and would like to know how to display it in Python in the same format without the quotation marks.
with open ("testpractice01.txt" , "r") as f:
f_contents = f.readlines()
Quotation marks are how python demarcates strings. The actual object string does not contain the quotations marks. Try printing each string with
The other thing to note is the trailing newline in your lines, because file lines are read in with the trailing newline by default, so you'll need to call
str.strip() to get rid of it. I'd recommend iterating over
f, the file object, so doing this becomes easier.
f_contents =  with open ("testpractice01.txt" , "r") as f: for line in f: f_contents.append(line.strip()) for line in f_contents: print(line)