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.
15 3365
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.
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? - ...
-
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()
-
...
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
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? - ...
-
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()
-
...
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?
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: - ...
-
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()
-
...
I was playing with the file with a .db extension since I can't use the 'next()' in 2.0
actually that's the wrong error. I was getting attributrerror:next()
Here is the error
Traceback (most recent call last):
File "monkey.py", line 13, in ?
s = f.next()
AttributeError: next
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: - s = f.readline()
-
prefix = s
-
while s.strip() != '#Data':
-
s = f.readline()
-
prefix += s
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
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: - lineList = []
-
for line in f:
-
lineList.append(line.strip().split())
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
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
?? - 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).
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
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():
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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=()=>{
|
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...
|
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...
|
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...
|
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...
|
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 :...
|
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...
|
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...
|
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...
| |