title: python argparse subparser assign value to variable
body: <p>i want to assign the subparser values to a variable like 'rport' so when the user call argument with value like </p>
  
  <pre><code>python example.py -sock connectmode -rport 10000 
  </code></pre>
  
  <p>the rport variable take the 10000 int value but that code return error in the last line in 'rport = '</p>
  
  <pre><code>AttributeError: 'Namespace' object has no attribute 'rport'
  </code></pre>
  
  <p>notes : the subparsers is for a function is called 'socketfunc'
  i wanted them to be a subargs for '-sock' argument
  when i execute : 'python example.py -sock connectmode -h
  return the secondary_parser args
  [!]another note : the rport and rhost variables is global to make their values available to all functions</p>
  
  <p>any help ! and thanks.</p>
  
  <p>the code is : </p>
  
  <pre><code>import argparse
  import socket
  parser = argparse.ArgumentParser(epilog='\tExample: \r\npython ' + sys.argv[0])
  parser.error = parser_error
  parser._optionals.title = "OPTIONS"
  subparsers = parser.add_subparsers(help='Specify secondary options')
  global rport , rhost
  secondary_parser = subparsers.add_parser('connectmode', help='sock argument connectmode')
  listenmode_parser = subparsers.add_parser('listenmode',help='sock argument listenmode')
  parser.add_argument('-sock','--socket',help="tcp socket functions [!] support only ipv4 for now",action="store_true")
  secondary_parser.add_argument('-rport','--remoteport',help="destination port to connect to",required=True,action='store')
  secondary_parser.add_argument("-rhost",'--destination',help="destination host ip addr",required=True,action='store')
  secondary_parser.set_defaults(func=socketfunc)
  listenmode_parser.set_defaults(func=socketfunc)
  args = parser.parse_args()
  rport = args.rport
  </code></pre>