472,975 Members | 1,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

running a python script with tcl

ironmonkey69
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.
Jul 26 '07 #1
15 3365
bartonc
6,596 Expert 4TB
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.
Help us help you by posting some of the relevant code. Instructions for using [ CODE ] tags are on the right hand side of the page when you reply to this. Thanks.
Jul 26 '07 #2
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?

Expand|Select|Wrap|Line Numbers
  1. ...
  2. def nthzero(dataList, nth, n):
  3.     '''
  4.     Replace the nth element of each list in the data list with 'n'
  5.     '''
  6.     for item in dataList:
  7.         item[nth] = n
  8.     return dataList
  9.  
  10.  
  11. fn = 'outfile.db'
  12. f = open(fn)
  13.  
  14. s = f.next()
  15. prefix = s
  16. while s.strip() != '#Data':
  17.     s = f.next()
  18.     prefix += s
  19.  
  20. lineList = [line.strip().split() for line in f]
  21.  
  22. f.close()
  23. elem = 1
  24. repl = '0'
  25. lineList = nthzero(lineList, elem, repl)
  26.  
  27. fn1 = 'outfile.db'
  28. f = open(fn1, 'w')
  29. outList = []
  30. for line in lineList:
  31.     outList.append(' '.join(line))
  32.  
  33. f.write('%s%s' % (prefix, '\n'.join(outList)))
  34. f.close()
  35. ...
Jul 27 '07 #3
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 column
Jul 27 '07 #4
bvdet
2,851 Expert Mod 2GB
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?

Expand|Select|Wrap|Line Numbers
  1. ...
  2. def nthzero(dataList, nth, n):
  3.     '''
  4.     Replace the nth element of each list in the data list with 'n'
  5.     '''
  6.     for item in dataList:
  7.         item[nth] = n
  8.     return dataList
  9.  
  10.  
  11. fn = 'outfile.db'
  12. f = open(fn)
  13.  
  14. s = f.next()
  15. prefix = s
  16. while s.strip() != '#Data':
  17.     s = f.next()
  18.     prefix += s
  19.  
  20. lineList = [line.strip().split() for line in f]
  21.  
  22. f.close()
  23. elem = 1
  24. repl = '0'
  25. lineList = nthzero(lineList, elem, repl)
  26.  
  27. fn1 = 'outfile.db'
  28. f = open(fn1, 'w')
  29. outList = []
  30. for line in lineList:
  31.     outList.append(' '.join(line))
  32.  
  33. f.write('%s%s' % (prefix, '\n'.join(outList)))
  34. f.close()
  35. ...
Initially I thought the list comprehension or string methods may fail in Python 2.0, but I believe both were added in 2.0. Can you post the error message?
Jul 27 '07 #5
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:

Expand|Select|Wrap|Line Numbers
  1. ...
  2. def nthzero(dataList, nth, n):
  3.     '''
  4.     Replace the nth element of each list in the data list with 'n'
  5.     '''
  6.     for item in dataList:
  7.         item[nth] = n
  8.     return dataList
  9.  
  10.  
  11. fn = 'outfile.txt'
  12. f = open(fn)
  13.  
  14. s = f.next()
  15. prefix = s
  16. while s.strip() != '#Data':
  17.     s = f.next()
  18.     prefix += s
  19.  
  20. lineList = [line.strip().split() for line in f]
  21.  
  22. f.close()
  23. elem = 1
  24. repl = '0'
  25. lineList = nthzero(lineList, elem, repl)
  26.  
  27. fn1 = 'outfile.txt'
  28. f = open(fn1, 'w')
  29. outList = []
  30. for line in lineList:
  31.     outList.append(' '.join(line))
  32.  
  33. f.write('%s%s' % (prefix, '\n'.join(outList)))
  34. f.close()
  35. ...
I was playing with the file with a .db extension since I can't use the 'next()' in 2.0
Jul 27 '07 #6
actually that's the wrong error. I was getting attributrerror:next()
Jul 27 '07 #7
Here is the error

Traceback (most recent call last):
File "monkey.py", line 13, in ?
s = f.next()
AttributeError: next
Jul 27 '07 #8
bvdet
2,851 Expert Mod 2GB
actually that's the wrong error. I was getting attributrerror:next()
I just checked. The file.next() method was added in 2.3. Try replacing that section of code with:
Expand|Select|Wrap|Line Numbers
  1. s = f.readline()
  2. prefix = s
  3. while s.strip() != '#Data':
  4.     s = f.readline()
  5.     prefix += s
Jul 27 '07 #9
now I am getting an error:
File "monkey.py", line 19, in ?
lineList = [line.strip().split() for line in f]
TypeError: loop over non-sequence
Jul 27 '07 #10
bvdet
2,851 Expert Mod 2GB
now I am getting an error:
File "monkey.py", line 19, in ?
lineList = [line.strip().split() for line in f]
TypeError: loop over non-sequence
Let's get rid of the comp:
Expand|Select|Wrap|Line Numbers
  1. lineList = []
  2. for line in f:
  3.     lineList.append(line.strip().split())
Jul 27 '07 #11
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-sequence
Jul 27 '07 #12
bvdet
2,851 Expert Mod 2GB
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-sequence
??
Expand|Select|Wrap|Line Numbers
  1. lineList = [line.strip().split() for line in f.readlines()]
Do you understand what is taking place here? Since there was no next() method in Python 2.0, this was the way to iterate on a file (I am concluding this by deduction).
Jul 27 '07 #13
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-sequence
Jul 27 '07 #14
bvdet
2,851 Expert Mod 2GB
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-sequence
Please read my last post!

for line in f.readlines():
Jul 27 '07 #15
can you help me make this take in a command line argument and have it loop the zero'ing out of the columns until all the numbers that were inputted through the command line.
Jul 27 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
7
by: Arun | last post by:
Hi, This is a scripting question, but since I am writing the script in python I am posting this question here: I have a python script that runs a simulator (that was written in c++, so I use...
9
by: Erik Geiger | last post by:
Hi, sorry, my english ist not that got but I'll try. I have a running python script (capisuit incoming.py). This script shall start a linux shell script. If I start this script like...
1
by: faxme | last post by:
Hi, I would like to know if it is possible to change code on the fly on a python interpreter. I want to have a python script running a multithread server and be able to connect to this python...
1
by: neha | last post by:
hi, i m trying to integrate python with apache on linux.For this i m using mod_python. I dont see any problem with the versions of python,apache and mod_python i m using. the versions i m using...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
2
by: Benjamin Rutt | last post by:
I often execute a long-running python script which is a "driver" for my application; it may run for several hours on a large input. Under CPython, is it safe for me to modify the Python script...
6
by: Guillermo | last post by:
Hi, I need a script to keep running in the background after it's loaded some data. It will make this data available to the main program in the form of a dictionary, but I don't want to reload...
0
by: eddiefisher41 | last post by:
Hey guys. Im having problems running a python cgi. Im using the example code from: http://www.python.org/doc/essays/ppt/sd99east/sld041.htm as writen by Van Rossum himself I can get the script...
5
by: Christopher Brewster | last post by:
I am running the same script on the same data on two different machines (the folder is synchronised with Dropbox). I get two different results. All the script does is count words in different...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.