Learning a New Programming Language, with Life
For an upcoming course to help science students master the computer as a tool for their work, by learning to code, I need to learn Python. I reviewed discussions on Python 2 vs Python 3, and chose the latter.
To operate in a new language, I only need to learn and practice four things:
- Storage and Retrieval
My traditional project for learning a new language is to code Conway’s Game of Life.
After my first 2 hours in Python, with Python 3.4.3 installed, and Google for answering my questions, I’ve covered command line arguments (though still without argparse for user error handling), input from text file, output to console, line-by-line storage, and character-by-character retrieval from a Python list.
Here’s my code so far. Wish me luck as I continue learning!
#Import libraries needed
import sys #for command line argument support
#Get pathname of file to open from first command line argument
filenameToOpen = sys.argv
#Open the file
myFile = open(filenameToOpen)
print("Pathname was: ", filenameToOpen)
print("Result code for opening the file was: \n", myFile)
#Read and display entire file
#Also store it in a list
myList =  #declare list, initially empty
print("\nHere is the file as it's being read in: \n")
#Read from the file, line by line:
for line in myFile:
....print(line, end='') #display each line
....myList.append(line) #add the line to the list
#Close the file
print("\nFile should be closed now.\n")
print("Here's the contents of the list... \n")
#Display the contents of the list
for row in myList:
....print(row, end='') #entire rows
....for iCharacterIndex in range(len(row)):
........print(row[iCharacterIndex]) #character by character
p.s. I’ve put periods in to show the indentation, since it’s hard to get WordPress to preserve whitespace.