Python - Templates

From Torben's Wiki

Measurement Script

# -*- coding: utf-8 -*-

# no more integer division!!!
from __future__ import division

import sys
sys.path.append("c:/MessSoftware/MyPyLibs") # here we find ipHelp.py and Devices.py
from ipHelp import IPS, ip_syshook
#from Devices import *
#from myMath import *
#smu = SMU236(gpibaddress=16,devicename="SMU 236", simulation=False)
import random

import time
tStartTime = time.time()
import datetime
d=datetime.datetime.today().strftime("%y%m%d-%H%M")
logfile=""+d+"IV"+".dat"
FILE = open(logfile,"a")
header = "# " + str (time.ctime()) + ", Timestamp %d\n" % (tStartTime)
from sys import argv
header += "# Scriptfile: " + str(argv[0]) + "\n"
header += "# Operator: Torben Menke\n"
FILE.write(header)

tOffset = time.time()
try:
  i=0
  while 1 :
    i+=1
    time.sleep(1)
    t = time.time() - tOffset
    x = random.random()
    s = "%d\t%.3f" % (t,x) # rounding
    print s
    FILE.write(s+"\n")
    if i % 10 ==0 : FILE.flush()
    #raise Exception('KeyboardInterrupt')#
    
except KeyboardInterrupt :  
#  smu.off()
#  smu.setV(0)
#  smu.disconnect()
  FILE.close()