Error confusing a newbie
Wayne Topa
wtopa at dmcom.net
Fri Dec 10 10:03:20 EST 1999
Hello
I seem to have run into an error that I can't figure out. I have
written a python program to replace a somewhat unintelligable perl
script I wrote about a year ago. The python replacement (improvement)
is 1/4 the size and I can understand it!
The problem is that when run with #> python net_time.py it works
and does what I want. But - see below.
mtntop:~# ls -l net_time.py
-rwxr-xr-x 1 root root 835 Dec 10 09:52 net_time.py
mtntop:~# python net_time.py
Current Totals
013 Hours 0 Minutes 42 Seconds
mtntop:~# net_time.py
import: Unable to connect to X server () [No such file or directory].
from: can't read /var/spool/mail/DateTime.
./net_time.py: line 7: syntax error near unexpected token `open(''
./net_time.py: line 7: `input = open('/var/log/totalppp', 'r')'
Here is the script
---------------------------------------------
#!/usr/bin/env python
import string,sys
from DateTime import *
input = open('/var/log/totalppp', 'r')
times=input.readlines()
input.close()
diff=y=z=0
test=0
while (1):
on = DateTimeFrom(times[z])
out = DateTimeFrom(times[z+1])
diff = diff + TimeDeltaFrom(out - on)
if test:
print 'Time on was %s' % on
print 'Time off was %s ' % out
this = TimeDeltaFrom(out - on)
print ' This connection - %2i:%2i:%2i' %(this.hour, this.minute, this.second)
print 'Current total = %s\n' %diff
z = z + 2
if z > (len(times)-1):
break
print '\nCurrent Totals \n%03d Hours %2i Minutes %2i Seconds \n' % (diff.hour, diff.minute, diff.second)
---------------------------------------
I must be missing something. Why does the X server error occur in
a script that uses the console? Why (What) is looking for
/var/spool/mail/DateTime? What is causing the open to fail when run as
an excutable script?
I am suspect that I must not be doing something required by
DateTime, but I can't find and solution in the docs.
Any pointers to 'required' reading would be appreciated.
TIA
Wayne
--
Computers can never replace human stupidity.
_______________________________________________________
More information about the Python-list
mailing list