如何更改python脚本的执行(执行=读取和打印):python script.py file.txt到python script.py

时间:2017-11-15 02:27:27

标签: python

我设法写了一个脚本(script2.py),它给出了一个很好的结果,(输出= -553.75)。 [问题的答案: how to read a specific position in the last line using python

#!/usr/bin/env python

import sys, os
import datetime
import time as t
# Define Variables 
omega = 0
numBasisLst = []
numBasis = []
oTE_list = []
oTE = []





# Open File
fileName = sys.argv[1]
outputFile = open(fileName, 'r')

# Sort Input Into Lists
for line in outputFile:
  line = line.split() # split lines into lists
  if not line: # skip empty lines
    continue
  if len(line) >= 3:
    if line[0] == 'word1' and line[1] == 'word2' and line[2] == 'word3' and line[3] == 'word4':
      oTE_list.append(line[4])




# Change Lists To Number Format
for item in oTE_list:
  oTE.append(float(item))



for idx, item in enumerate(oTE):      
    if idx == len(oTE) - 1:
        print(item)

但执行如下: python script2.py file.txt

我的问题是;如何更改script2.py以执行如下操作:$ python script2.py

enter image description here

0 个答案:

没有答案