Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Tuesday, 19 January 2021

Python Function - Find the Next Business Days After n Days | Maximo

You have 15 business days (exclude weekends) to complete the task, what will be the 15thday?


from java.util import Calendar

#Function definition
def getNextBusinessDday(dn ):
    cal = Calendar.getInstance();
    cal.setTime(d)
    loop=1
    while(loop<=n) :
        cal.add(cal.DATE, +1)
        if (cal.get(cal.DAY_OF_WEEK)) not in [cal.FRIDAY,cal.SATURDAY] : 
            loop=loop+1
        vserial = loop
    calculatedetc = cal.getTime()
    return calculatedetc

#variables for input
d = mbo.getDate("changedate")
n = 15

#function call whereever you want in the same script
getNextBusinessDday(d,n)

Sunday, 14 June 2020

List of Items as Parameters of a Function, Map() | Python

Map isn't pythonic, use list instead. 

map(func, iterable)

func : It is a function to which map passes each element of given iterable.
iter : It is a list which is to be mapped( list of parameters to be passed to func).

lets say:
>>> func add(a):
>>>     return a+5;
>>> print add(2)    // 2 as parameter, it will return 2+5=77

//lets give a list of parameters instead of only 1 param

>>> myList = (2,6,7,1)

//first lets do the same with for loop.
>>> for i in number:
...     print add(i);...
96

// lets do the same with list.
func add(a):
    returnn a+5;
myList = (2,6,7,1);
// all items of list will be the parameter for the function add().
>>> print map(add, myList)
[610115]