Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Python equivalent to R's invisible() function

Tags:

python

r

ipython

I'm new to Python and wondering if Python (or IPython) has an equivalent to the invisible() function in R. The invisible() function returns values, but doesn't display them if run interactively, instead it just makes them available for assignment. For example:

doStuff <- function(x) {
   // blah blah 
   return(invisible(retValue))
}

z = doStuff(x) // z has the return value
doStuff(x) // retValue doesn't get displayed
like image 470
user4270027 Avatar asked Feb 15 '26 12:02

user4270027


1 Answers

There does not seem to be a proper function in Python that is the same as R's invisible() function. However, you can simply use a variable set to a boolean value and then use an if statement to check if the boolean is set to True then you return the output of the function. Below is a simple version of what the code could look like, you can make this more complex and improve it (if this does not help you then I suggest that you put some research into function outputs in python):

def function(INPUTS):
  # function code to get ouput
  return_value = False
  if return_value == True:
    return ouput
like image 96
Charlie Cook Avatar answered Feb 17 '26 02:02

Charlie Cook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!