# Ignition python scripting help

**URL:** <https://forum.inductiveautomation.com/t/ignition-python-scripting-help/4348>\
**Category:** Ignition\
**Created:** [April 25, 2012, 1:56pm UTC](https://forum.inductiveautomation.com/t/ignition-python-scripting-help/4348 "2012-04-25T13:56:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [April 25, 2012, 1:56pm UTC](https://forum.inductiveautomation.com/t/ignition-python-scripting-help/4348/1 "2012-04-25T13:56:25Z")

</div>

I am attempting to test this system in order to determine if I am able to log information to a log file which I’d like to be a txt file.  
I am eventually going to be using this as an event handler for scan information and time stamps but for the time being I am just using the even script and the script playground to input my code.

sandtype = ‘coarse’  
target = ‘concenation?’  
for i in range(5):  
print (‘open seasame\n’)  
print i  
filename = system.file.saveFile(“C:\Users\AJ\MyDownloadedFile.txt”)  
if filename != None:  
system.file.writeFile(filename, ‘\r\nIT’S’ + ’ %s’ %(sandtype) + ’ ’ + target, 1)

This is the sample code i’ve written into the playground in order to see if I can log information.  
It prompts me to save the file at every iteration of the for loop, I will need this to work without prompting me.  
Additionally, when I put this code into a timer event script, it does not even create a file and I’m pretty sure there is something wrong with the code recognition by the software.  
Is this something that can be done and how can I debug my code in Ignition?

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [April 25, 2012, 2:06pm UTC](https://forum.inductiveautomation.com/t/ignition-python-scripting-help/4348/2 "2012-04-25T14:06:26Z")

</div>

OK, now my code looks like this:  
sandtype = ‘coarse’  
target = ‘concenation?’  
for i in range(5):  
print (‘open seasame\n’)  
print i  
filename = “c://Users//AJ//hotpotato.txt”  
if filename != None:  
system.file.writeFile(filename, ‘\r\nIT’S’ + ’ %s’ %(sandtype) + ’ ’ + target, 1)

now how to I make this as an event timer script in my application to keep repeating this code?

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [April 25, 2012, 2:36pm UTC](https://forum.inductiveautomation.com/t/ignition-python-scripting-help/4348/3 "2012-04-25T14:36:25Z")

</div>

ok now my code kind of works, but now I am in a place where I will need to create a timestamp and save this into my file, but when I 'm using the code

timeStamp = datetime.datetime.today()  
timeStamp = str(timeStamp)  
print (timeStamp)

This seems to do nothing in jython.  
How should this look?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [April 25, 2012, 3:15pm UTC](https://forum.inductiveautomation.com/t/ignition-python-scripting-help/4348/4 "2012-04-25T15:15:27Z")

</div>

Are you importing datetime? It should be:`import datetime
timeStamp = datetime.datetime.today()
timeStamp = str(timeStamp)
print (timeStamp)`That prints out:`2012-04-25 08:14:18.519999`

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [April 25, 2012, 4:01pm UTC](https://forum.inductiveautomation.com/t/ignition-python-scripting-help/4348/5 "2012-04-25T16:01:44Z")

</div>

I pretty much got it the way I wanted it by using this

from java.util import Date  
sandtype = ‘number’  
target = system.db.dateFormat(Date(), “yyyy-MM-dd HH:mm:ss”)  
katty = 'plush ’  
filename = “c://Users//AJ//hotpotato.txt”  
system.file.writeFile(filename, '\r\nIT’S ’ + target, 1)  
for i in range(5):  
print (‘open seasame\n’)  
print i  
system.file.writeFile(filename, ’ WATCH ’ + sandtype + str(i), 1)  
I think this is all I needed for now.  
Thanks for your help in another thread 😛
