0

I am using Jython for wsadmin scripting for one of my tasks.

-c "test = 'project' " + -c "edit = test[1:]" + -c "print edit"

However when I execute the piece of code , I get the following error

Traceback (innermost last): (no code object) at line 0 File "<input>", line 1 edit = test[1:] ¬ SyntaxError: Lexical error at line 1, column 12. Encountered: "\u00dd" (221),after : ""

Looks like the square brackets are not being accepted are there any other ways to obtain a substring for a string in Jython?

ssdimmanuel
  • 448
  • 10
  • 29
  • I have made regular script from your code and it prints `roject` from Jython 2.5.3. Can you run it as regular script? What happens when you change it into one-liner: `test = 'project';edit = test[1:];print edit;`? Can you show us what version of Jython you use? – Michał Niklas Apr 17 '14 at 06:37
  • I am not sure about the version of Jython but I am using it with WAS 7.0 – ssdimmanuel Apr 24 '14 at 00:26

2 Answers2

0

In Jython slicing works very well and your code in one liner produces roject output. I suggest using it as one liner with semicolons instead of line separators:

-c "test = 'project';edit = test[1:];print edit;"

PS It often helps if you show us your environment: Jython version, OS version etc.

I have tested it on Jython 2.5 and 2.2 and it works:

[mn@test ~]# jython -c "import sys; print sys.version; test = 'project';edit = test[1:];print edit;"
2.2.1
roject
Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
  • Still shows error in same position . I am using Jython for wsadmin in WAS 7.0 running on ZOS – ssdimmanuel Apr 24 '14 at 14:13
  • Can you run Jython as in my edited response and show us results? – Michał Niklas Apr 25 '14 at 08:13
  • I ran the following `-c "print (sys.version); test='project';edit = test[1:];print edit;"`. but sill the same error `Traceback (innermost last): (no code object) at line 0 File "", line 1 .print (sys.version); test='project';edit = test.1:.;print edit; . ¬ SyntaxError: Lexical error at line 1, column 48. Encountered: "\u00dd" (221),` – ssdimmanuel Apr 25 '14 at 12:22
  • One thing I am noticing is that the square bracket is not being recognised by the script processor. Note that in my job log the square brackets are shown as two dots `edit = test.1:.;` – ssdimmanuel Apr 25 '14 at 12:24
0

I would try using a script file by using the '-f' switch of wsadmin. It could potentially solve the problem or at least make it much easier to debug. It seems like it might be a character encoding issue judging that \u00dd is a non-standard English character.

See: http://www.charbase.com/00dd-unicode-latin-capital-letter-y-with-acute

Just to be safe, ensure your script file is encoded in UTF-8.

Threadicide
  • 126
  • 7