In my previous note, some strange indentation
occurred. The example should have looked like the following:
<script>
f=open(configFile, 'r')
lines = f.readlines()
for l in lines:
l=l.strip()
</script>
--------------------------------------------------------------
Sharon Lucas
IBM Austin, lucass@us.ibm.com
(512) 838-8347 or Tieline 678-8347
----- Forwarded by Sharon
Lucas/Austin/IBM on 04/28/2006 12:58 PM -----
Sharon Lucas/Austin/IBM@IBMUS Sent by: staf-users-admin@lists.sourceforge.net
04/28/2006 12:55 PM
To
Kyle Girard <kyle.girard@klocwork.com>
cc
staf-users@lists.sourceforge.net
Subject
Re: [staf-users] Unable to open file
via python
The file is being opened fine. The error message says the problem
is in line 2, not line 1:
for l in f:
.
Variable f is
not a list (aka sequence), and thus it doesn't have a
__getitem__ attribute. The
open function returns a built-in object ready for I/O.
It seems like you're missing using the readlines() function on the file
object. The readlines() function reads from a file and returns a
list of the read lines as strings. For example:
<script>
f=open(configFile, 'r')
lines = f.readlines()
for l in lines:
l=l.strip()
</script>
Please see Python documentation for more information on how to read from
a file.
--------------------------------------------------------------
Sharon Lucas
IBM Austin, lucass@us.ibm.com
(512) 838-8347 or Tieline 678-8347
Kyle Girard <kyle.girard@klocwork.com>
Sent by: staf-users-admin@lists.sourceforge.net
04/28/2006 12:23 PM
To
staf-users@lists.sourceforge.net
cc
Subject
[staf-users] Unable to open file via
python
Hello,
I do not seem to be able to open a file for reading using python in a
<script> tag... I cut and paste the same code into a python script
and
it works no problem. Am I missing something?
<function name="PythonTest">
<function-single-arg>
<function-required-arg name="configFile"/>
</function-single-arg>
<sequence>
<script>
f=open(configFile, 'r')
for l in f:
l=l.strip()
</script>
</sequence>
</function>
<stax>
When I run this I get the follow error message:
com.ibm.staf.service.stax.STAXPythonEvaluationException: Trackback (innermost
last):
File "<pyExec string>", line 2, in ?
AttributeError: __getitem__
Anyone tell me what I'm missing? I know the file exists, because
otherwise the I get a different error
Thanks,
Kyle
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users