[Tutor] Re[2]: [Tutor] ksh and SAS questions

Corran Webster cwebster@math.tamu.edu
Fri, 4 Jun 1999 16:09:58 -0500 (CDT)


Hi,

>      Well, I can't see the error in the following script. Running 
>      SunOS 5.5.1. When I run my Python script, I get this error 
>      message:
>      
> Traceback (innermost last):
>   File "recheck.py", line 14, in ?
>     month = os.environ['CATI']
>   File "/usr/local/lib/python1.5/UserDict.py", line 12, in __getitem__
>     def __getitem__(self, key): return self.data[key]
> KeyError: CATI

It looks like the environment doesn't have 'CATI' defined.  I think I
might need to know a bit more about what the environment is, and what
the ksh script '/op/ctl/prod/scripts/setcm.ksh' does.  If it changes or
creates the 'CATI' environment variable, then this might be the
problem - any changes to the environment inside an os.system call do
not cause changes in the environment of the python program.

One solution (assuming you are using ksh as your shell) would be to
manually execute the ksh script, and then manually execute the python
program (but with the first os.system call removed).

A better solution might be to re-write the setcm.ksh script as part of
the python program - assuming that it's not very complex.

Unfortunately, I don't think I can give any more suggestions without
knowing what the first ksh script does.

>      The script is:
>      
>      1  #!/usr/local/bin/python
>      2  #PROGRAM: recheck.py
>      3  #FUNCTION: execute Barbara's RECHECK program
>      4  #INPUTS: rofr.txt
>      5  #OUTPUTS: rofr.sas, ccMail message
>      6  #CALLS TO: Python os, sys, and string modules, recheck.sas
>      7  #SPECIAL NOTES: Have not yet figured out how to automate input of the 
> rofr file
>      8  #AUTHOR: Adeline Wilcox         DATE: 05Apr99
>      9  #Written with the assistance of Andrew Kuchling and especially Tim 
> Peters
>     10  #UPDATED:                       DATE: 
>     11  import os, sys 
>     12  os.system('/op/ctl/prod/scripts/setcm.ksh')
>     13  #get CATI month from environment
>     14  month = os.environ['CATI']
>     15  import string
>     16  sys.stdin = open('/op/ctl/prod/data/ro' + month +'.txt','r')
>     17  lines = sys.stdin.readlines()
>     18  for i in range(len(lines)):
>     19      line = lines[i]
>     20      lines[i] = "'" + string.rstrip(line) + "'"
>     21  sys.stdout= open('/op/ctl/test/data/rofr.sas','w')
>     22  print "if rofr in (" + string.join(lines, ", ") + ") then output;"
>     23  #if I dont close the file, SAS does not get quotes around last value of 
> rofr
>     24  sys.stdout.close()
>     25  #os.system("$SASDIR/sas /op/ctl/prod/prgms/recheck.sas -sysparm " + 
> month + \ " -log /op/ctl/prod/logs/recheck.log." + month ")
>     26  #os.system("mailx -s 'Recheck " + month + " run for you \' 
> Adeline.J.Wilcox@ccmail.census.gov ")


Corran