Friday, November 11, 2016

Jython operators and sequences in wsadmin

Welcome back to Jython learning blog again. today I have explored different categories of operators how they can be used in Jython for wsadmin. prerequisites for this is you must have a Jython for WebSphere installed on your VM and you are on wsadmin prompt.

Types of operators (inherited from Python):
  • Arithmetic operators
  • Comparison operators
  • Relational operators 
These simple experiments would give you a base for building automation scripts in your projects.

Basic understanding of Jython Operators
Jython Operators on wsadmin


 

How can Jython deals with Arithmetic operators

Every language supports the Arthematic operators and in Jython same operators as in C or Python languages.

wsadmin>x,y = 10, 20
wsadmin>print x, y
10 20
wsadmin>x+y
30
wsadmin>x+y+30
60
wsadmin>y-x
10
wsadmin>x-y
-10
wsadmin>x*y
200
wsadmin>x**2
100
wsadmin>y/x
2
wsadmin>y%x
0

How to use Jython Comparison operators?

The comparing operators mostly used in the 'if-else' or 'while' blocks which returns either True or False value. For each data type it will be different so see the examples executed at the wsadmin prompt.

Numeric comparison in Jython
 wsadmin>10>1
1
wsadmin>20<34 1="" wsadmin="">20<2 0="" wsadmin="">10<10 0="" wsadmin="">10<=10
1



Tuple comparison in Jython
wsadmin>'app_server1' in ('app_server1','app_server2','ejb_server1','ejb_server2')
1
wsadmin>servers_list=('app_server1','app_server2','ejb_server1','ejb_server2')
wsadmin>'appserver1' in servers_list
0


String comparison in Jython
wsadmin>'dmgr'=='dmgr'
1




Char comparison in Jython
wsadmin>'t'=='t'
1
wsadmin>'t'=='T'
0



List comparison in Jython
wsadmin>['dev_cell01',20]==['dev_cell01',20]
1
wsadmin>['dev_cell01',20]==[20,'dev_cell01']
0


Dictionaries comparison in Jython
wsadmin>{'appserver1':8001}=={'appserver1':8001}
1
wsadmin>server_dict={'appserver1':8001}
wsadmin>{'appserver1':8001}==server_dict
1
wsadmin>server_dict=={'appserver2':8001}
0

How can Jython Relational operators simplify your scripts?

Here is the set of releational operators usage examples
wsadmin>x>=10
1
wsadmin>x>=10 and y==20
1
wsadmin>x>10 or y==20
1
wsadmin>x>10
0
wsadmin>not x>10
1
wsadmin>not x>=10
0


Hope you enjoyed this short learning about operators. Please share your experiance with your friends and teams. Comment your expectations we will keep updating this blog frequently.

No comments:

Post a Comment

Containerization with Docker

Containerization with Docker
Learn modern microservices containers grow