Reputation: 2787
Is there any way to list possible values of an argument as I call function inside PyCharm editor or console ?
Here's a basic function example:
def func(x='foo'):
if x=='foo':
print('foo')
if x=='bar':
print('bar')
When I type func(x=
, I want to get suggestions for parameter or at least the default value.
EDIT 1: How can I make the autocomplete print usage of particular function?
EDIT 2: how can I replicate this behavior from Keras LSTM
?
Upvotes: 2
Views: 1686
Reputation: 6061
Modified example you provided:
def func(x='foo'):
"""My awesome function.
This function receives parameter `x` which
can be set to 'foo' or 'bar'.
"""
if x=='foo':
print('foo')
if x=='bar':
print('bar')
To get parameter info, use Ctrl+P shortcut between the parenthesis when calling a function. It will display list of arguments, along with the default ones for specific argument (both default values are set in your function and in Keras function).
However, to display function help(docstring of a function), use Ctrl+Q shortcut while anywhere inside function name when invoking it.
BONUS:
Python supports Type Annotations using a typing module. You can create enumeration and set it as parameter type as following:
import enum
class State(enum.Enum): # Possible values
STANDING = 1
SITTING = 2
LAYING = 3
def get_person_state(state: State):
if isinstance(state, State): # Restrict possible values passed to state.
print("Valid state:{}".format(state))
else:
print("Invalid state passed")
get_person_state(State.SITTING)
Upvotes: 1