# This program reads numbers from a file into a list.
def main():
# Open a file for reading.
infile = open('text.txt', 'r')
sentences = infile.readlines() # Read the contents of the file into a list.
infile.close() # Close the file.
index = 0 # Convert each element to an int.
while index < len(sentences):
print (sentences[index], index) #PRINT EACH ELEMENT
index += 1
# Print the contents of the list.
print (index)
# Call the main function.
main()
elbert.leach 0 Newbie Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Ene Uran 638 Posting Virtuoso
Gribouillis commented: interesting idea +13
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.