Question: I am trying to call the function addPXT through argparse when type -a. Its not doing that. Read another issue, there addPXT was not in colons, tried that it says addPXT is not callable.

```
parser = argparse.ArgumentParser()
parser.add_argument('-a' ,action='store_const'  ,const='addPXT')
results = parser.parse_args()

def addPXT():
        print "hello"

```

---

```
    python script.py -a

```

Answer: 
`argparse` will call the `action` object during parsing but you need to supply something that looks like the `Action` class because the parser will use that object later. The [Action doc](https://docs.python.org/2.7/library/argparse.html#action) says

> 
> You may also specify an arbitrary action by passing an Action subclass
>  or other object that implements the same interface. The recommended
>  way to do this is to extend Action, overriding the **call** method and
>  optionally the **init** method.
> 
> 
> 

So, create an `Action` subclass and have it call your function

```
import argparse
import sys

def addPXT():
    print "hello"

class FooAction(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        addPXT()

parser = argparse.ArgumentParser()
parser.add_argument('-a', action=FooAction)
results = parser.parse_args(sys.argv[1:])

```
You're missing a `dest`option in the add\_argument to be able to reference the option.

You will then need to test if the `-a` option was passed as argument. If so, then call the function.

```
parser = argparse.ArgumentParser()
parser.add_argument('-a' ,dest="my_flag", action='store_const'  ,const=True)
results = parser.parse_args()

def addPXT():
    print "hello"

if results.my_flag:
    addPXT()

```