# Timer Script - Python

**URL:** <https://forum.inductiveautomation.com/t/timer-script-python/20466>\
**Category:** Ignition\
**Created:** [October 31, 2018, 12:58pm UTC](https://forum.inductiveautomation.com/t/timer-script-python/20466 "2018-10-31T12:58:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [October 31, 2018, 12:58pm UTC](https://forum.inductiveautomation.com/t/timer-script-python/20466/1 "2018-10-31T12:58:43Z")

</div>

Hello everyone,  
I am trying to read a file and then put the data at appropriate location.  
Here is the code,

```auto
import time
import threading
import os	
import glob

def ReadFile():		
	contents = "C:\\Users\\kshah2\\Desktop\\MDR1.asc"
	if system.file.fileExists(contents):			
		File = system.file.readFileAsString(contents)
 		line_num2 = 0
 		Read = open(contents, "r")
 		for line in Read.readlines():
 			line_num2 += 1
 			if line.find("DATAPOINT") >= 0:
 				CheckData(line_num2 - 1)
	elif event.source.value == 19:
		system.gui.messageBox("No File Exists")

def CheckData(line_num2):
	contents = open("C:\\Users\\kshah2\\Desktop\\MDR1.asc", "r")
	Result = {}
	caption = []
	values = []
	Curve1data = []
	pointer = 0
	curves = 0
	curve_number = 0
	curve_pointer = 0
	for line in contents.readlines():
		if pointer == 0 and line.find("DATAPOINT") >= 0:
			pointer = 1
				
		elif pointer == 1 and line.find("Variable.Caption") >= 0:
			pointer = 2
			C_data = line.split("=")
			C_data = C_data[1].strip()
			caption.append(str(C_data))
				
		elif pointer == 2 and line.find("Variable.Value") >= 0:
			pointer = 0
			C_data = line.split("=")
			C_data = C_data[1].strip()							
			values.append(str(C_data))
		
		elif pointer == 0 and line.find("[CURVE") >= 0 :
			curves = 1
			curve_number += 1
			curve_pointer = 0
				
		elif curves == 1:
				if curve_number == 1:
				
					if line.find("Variable.Caption") >= 0 and curve_pointer == 0:
						curve_pointer = 1
						C_data = line.split("=")
						C_data = C_data[1].strip()
						Curve1name = str(C_data)
						
					elif curve_pointer == 2 and line.find("D"):
						C_data = line.split("=")
						C_data = C_data[1].strip()
						Curve1data.append(str(C_data))
					
					elif line.find("D0") >= 0 and curve_pointer == 1:
						curve_pointer = 2
						C_data = line.split("=")
						C_data = C_data[1].strip()
						Curve1data.append(str(C_data))
						print C_data
						
						
	Result = dict(zip(caption, values))	
	print Result
	print Curve1data
	print Curve1name

ReadFile()

```

For the captions and values, I am getting expected results, but, I am getting index out of range error for ,

```auto
elif line.find("D0") >= 0 and curve_pointer == 1:
						curve_pointer = 2
						C_data = line.split("=")
						C_data = C_data[1].strip()
						Curve1data.append(str(C_data))
										

```

I think the problem is it remembers the value of C\_data from previous line and then somehow doesn’t overwrite it.

Please let me know if you understand the problem and have some solution.

Help is always appreciated.

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [November 1, 2018, 10:07pm UTC](https://forum.inductiveautomation.com/t/timer-script-python/20466/2 "2018-11-01T22:07:18Z")

</div>

Which line of code are you getting the error on?  
Could you post the error you are getting?  
You could insert a try…except around the line causing the error and print the line, maybe there is no “=” to split on?  
E.g.

```auto
					elif line.find("D0") >= 0 and curve_pointer == 1:
						curve_pointer = 2
						C_data = line.split("=")
						try:
							C_data = C_data[1].strip()
						except:
							print 'Error with C_data: ', C_data
						Curve1data.append(str(C_data))
						print C_data

```
