I am teaching myself python. I am trying read an input file using:
import numpy as np
import matplotlib.pyplot as plt
import math
import sys
NEM_2D = []
NEM_zdim = []
NEMdataline = False
with open(sys.argv[1],'r') as file:
for line in file:
single=line.split()
if not line.startswith("!") and NEMdataline == True:
if single[0].isdigit:
NEM_X=[]
for i in range(0,NEM_X):
if int(single[i]) == 0:
NEM_X.append(0)
if int(single[i]) == 1:
NEM_X.append(1)
if int(single[i]) != 0 and int(single[i]) != 1:
NEM_X.append(2)
NEM_2D.append(2)
file.close()
When I run, I find the following error message: with open(sys.argv[1],'r') as file:
IndexError: list index out of range