String comparision in Jython script class exceptions.NameError exceptions.NameError instance

I Started recently working on jython/python, and come across the following problems and here are the solutions for those
  • How to compare strings in the jython/python script
norm = "6.0.2.35"
if cmp(wsadminVers, norm) == -1:
     print "quote_required"
else:
    print "quote_not_required"
    quote = 0
    print quote
In the above code snippet cmp(wsadminVers, norm) will compare two string values in wsadminVers and norm. If wsadminVers less than norm it return -1. If both are equal it returns 0. If wsadminVers is greater than norm it return 1. So cmp method is very easy string comparison method in jython.
  • How to resolve this exceptions or errors
2010-02-25 03:14:40 CDSUpdateAPP.py checkWASVersion Entry ()
2010-02-25 03:14:40 CDSUpdateAPP.py main ERROR ('Update of application failed:', <class exceptions.NameError at 664938402>, <exceptions.NameError instance at 97256908>)
The above exception can be arise while running jythin scripts which has usage of undeclared variables. see example below.
 print super
The above is one of the code line in our jython script, in this case super is treated as variable and if it is not declared the above exceptions will results as super varibale is not initiated.
we can do some thing like
print "super" which will treat super as string and prints it on console.
P.S : Line spaces and alignment are very much important in python scripts 


2 comments to "String comparision in Jython script class exceptions.NameError exceptions.NameError instance"

  • Here i had one question..Genrally when would we prefer Jython/Python Scripting,on what kind of application u have started of using this scipting..

    i follow your blog frequently..i wonder how you get the time to put all these..good work..

  • @ Anonymous : Hi, Glad to know that people follow my blog frequently. just want to help others as much as possible, this is the only motto which moves me daily. and coming to you question I got a chance to work with jython while Im working with Websphere. Our products installation which is deploying into Websphere.
    See this link for Difference between Jython and python - http://www.krishnababug.com/2010/04/difference-between-jython-and-python.html

Post a Comment

Who ever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs u can at least use Name/URL option which don’t even require any sign-in, good thing is that it can accept your lovely nick name also and URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")
వీలయితే నాల్గు పోస్టులు ...కుదురితే ఒక కామెంటూ ...

Translate

Enter your email address:

Buffs ...

Visitors


hits counter
View My StatsCheck Google Page Rank

Add to Google Reader or Homepage

Bookmark and Share

Tags


Powered by WidgetsForFree

Archives