I am trying to run a script though a tcl ware command and cannot get it to run. I used to eclipse to write the script and was able to run it through eclipse.
running a python script with tcl
Collapse
X
-
Tags: None
-
Originally posted by ironmonkey69I am trying to run a script though a tcl ware command and cannot get it to run. I used to eclipse to write the script and was able to run it through eclipse. -
actually I figured out the problem. I am running python 2.5 when the code that I am writing is for a machine that uses python 2.0. Can you help me do the same with this code in python 2.0?
Code:... def nthzero(dataList, nth, n): ''' Replace the nth element of each list in the data list with 'n' ''' for item in dataList: item[nth] = n return dataList fn = 'outfile.db' f = open(fn) s = f.next() prefix = s while s.strip() != '#Data': s = f.next() prefix += s lineList = [line.strip().split() for line in f] f.close() elem = 1 repl = '0' lineList = nthzero(lineList, elem, repl) fn1 = 'outfile.db' f = open(fn1, 'w') outList = [] for line in lineList: outList.append(' '.join(line)) f.write('%s%s' % (prefix, '\n'.join(outList))) f.close() ...
Comment
-
this code takes a text file with numbers that are separated by columns and zeroes out a colum. this is what the text file looks like:
#Number of Bits
12
#Data
0 0 0 0 0 0 0 0 0 0 0 0
12 5 3 4 6 4 5 4 7 5 5 10
24 9 7 7 13 7 9 9 14 10 10 20
and this is what it does:
#Number of Bits
12
#Data
0 0 0 0 0 0 0 0 0 0 0 0
12 0 3 4 6 4 5 4 7 5 5 10
24 0 7 7 13 7 9 9 14 10 10 20
in the python code the 'elem=' statement is what chooses the columnComment
-
Originally posted by ironmonkey69actually I figured out the problem. I am running python 2.5 when the code that I am writing is for a machine that uses python 2.0. Can you help me do the same with this code in python 2.0?
Code:... def nthzero(dataList, nth, n): ''' Replace the nth element of each list in the data list with 'n' ''' for item in dataList: item[nth] = n return dataList fn = 'outfile.db' f = open(fn) s = f.next() prefix = s while s.strip() != '#Data': s = f.next() prefix += s lineList = [line.strip().split() for line in f] f.close() elem = 1 repl = '0' lineList = nthzero(lineList, elem, repl) fn1 = 'outfile.db' f = open(fn1, 'w') outList = [] for line in lineList: outList.append(' '.join(line)) f.write('%s%s' % (prefix, '\n'.join(outList))) f.close() ...
Comment
-
I'm calling the file 'monkey2.py. This is the error I have been getting:
File "monkey2.py ", line 11, in ?
f = open(fn)
IOError: [Errno 2] No such file or directory: 'outfile.txt's = f.KEY_NEXT
AttributeError: 'file' object has no attribute 'KEY_NEXT'
This is the code I have been playing with:
Code:... def nthzero(dataList, nth, n): ''' Replace the nth element of each list in the data list with 'n' ''' for item in dataList: item[nth] = n return dataList fn = 'outfile.txt' f = open(fn) s = f.next() prefix = s while s.strip() != '#Data': s = f.next() prefix += s lineList = [line.strip().split() for line in f] f.close() elem = 1 repl = '0' lineList = nthzero(lineList, elem, repl) fn1 = 'outfile.txt' f = open(fn1, 'w') outList = [] for line in lineList: outList.append(' '.join(line)) f.write('%s%s' % (prefix, '\n'.join(outList))) f.close() ...
Comment
-
-
Here is the error
Traceback (most recent call last):
File "monkey.py" , line 13, in ?
s = f.next()
AttributeError: nextComment
-
Originally posted by ironmonkey69actually that's the wrong error. I was getting attributrerror: next()
prefix = s
while s.strip() != '#Data':
s = f.readline()
prefix += s[/code]Comment
-
now I am getting an error:
File "monkey.py" , line 19, in ?
lineList = [line.strip().sp lit() for line in f]
TypeError: loop over non-sequenceComment
-
Originally posted by ironmonkey69now I am getting an error:
File "monkey.py" , line 19, in ?
lineList = [line.strip().sp lit() for line in f]
TypeError: loop over non-sequence
for line in f:
lineList.append (line.strip().s plit())[/code]Comment
-
Now I am getting this error:
Traceback (most recent call last):
File "monkey.py" , line 20, in ?
for line in f:
TypeError: loop over non-sequenceComment
-
Originally posted by ironmonkey69Now I am getting this error:
Traceback (most recent call last):
File "monkey.py" , line 20, in ?
for line in f:
TypeError: loop over non-sequenceComment
-
I'm still getting the sam error:
Traceback (most recent call last):
File "testing.py ", line 20, in ?
for line in f:
TypeError: loop over non-sequenceComment
Comment