My File:
Offices 10
MedicalOffice 15
PostOffice 30
Mall 200
How do I make the python to read only the second column. Like get:
10
15
30
200
I have tried possibly ways to make it only read, 10, 15, 30, etc... Instead of the names. I tried this without the names, it works fine. But I need to include the names in the textfile. Any help? Thanks
def something(file1):
with file1 as f:
nums = [int(line) for line in f]
print("Read from File: ", nums)
textFileName = input("Enter the filename: ")
file1 = open(textFileName)
something(file1)
Thank you.
MedicalOffice 15.openat the top level, and thewithinside the function. That does basically work, as long as you only ever callsomethingin this one case, but it's strange. Normally you want theopendirectly in thewithstatement. Eitherwith open(textFileName) as file1: something(file1)and thensomethingdoesn't have awith, or justsomething(textFileName)and insidesomethingit opens the file in awith. (This is very hard to explain in a comment; hopefully you get the idea?)