A warm Welcome to my jython4wsadmin blog!!
Variables in programming languages we need to declare on the top of the function or program. When we declare it we need to tell about what type of data we would like to store in the variable. Where as in Scripting languages you don't need to do so. Jython is a scripting language so you don't need to declare the variable.
Like any programming language Jython also support variables but these variables looks like scripting variables, they are dynamic.
The value that assigned to a variable is going to have an id and label internally it is one of the Python Object type as well.
Let me experiment with my simple Jython script to understand more how the variables can be created and used in multi variants. Here the values can be integer, float, long types in numeric data types.
The value that assigned to a variable is going to have an id and label internally it is one of the Python Object type as well.
Let me experiment with my simple Jython script to understand more how the variables can be created and used in multi variants. Here the values can be integer, float, long types in numeric data types.
Jython Variable inside wsadmin |
# This program will illustrate the variables of jython. # Integer variable x=5 print 'x=', x, type(x), id(x) # Multiple Variables can be assigned with multiple values respectively y, z=10, 30 print 'y=',y, 'z=',z # Float number f=10.45 print "f=", f, type(f), id(f) # Boolean value b=10<40 and="" assert="" b=",b, type(b), id(b) # String value cellName=" cellname:="" cellname="" democell="" pre="" print="" t=""> 40>The script execution can be done using execfile function that takes the path for the Jython script.<br /> Better to have the all Jython scripts at one common place, I"> Output of the above script looks like this...
Best practice: Avoid the keyword in the namespaces
How do I know what all the keywords available in Jython? It is easy to determine that, from the keyword module you can get keyword list as shown below:wsadmin>import keyword wsadmin>keyword.kwlist ['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while']Note: Don't use any of these keywords in the function names, class name or variable names.
How the type Casting works in Jython?
Unlike any other programming languages we have typecasting allowed in Jython script. What do you mean by casting? It is simple converting from one type of data to another type. Following illustrates a float value casting to int type.wsadmin>f=10/3.0 wsadmin>print f 3.3333333333333335 wsadmin>cast2int = int(f) wsadmin>print cast2int 3Casting a int value to str type
wsadmin>str(cast2int) '3'Converting a int value to chr type
wsadmin>chr(65) 'A'Hope you enjoyed this post please write your comment where did you use the post. Information is wealth!! keep sharing this knowledge article.
No comments:
Post a Comment