title: Python Argparse Cant Split string
body: <p>This should be simple.  But it is really getting to me now.  I have setup a simple argparse and want to be able to split a string if it has a minus symbol.  Sounds simple but when items are parsed into argparse it comes up blank.  So I will show you what I want to do and why it is puzzling me.  Note: I have hard specified it as a string. The dir and type functions come up blank.</p>
  
  <pre><code>        import argparse
          import sys
          portlist = []
  
          #Parser Arguments and Usage
          parser = argparse.ArgumentParser(description='This script performs a Syn scan on a specific host with the ports that are specified by you.', usage='Specify Ports with the -p switch. Port range -p 80-200, specific port -p 80, multiple ports -p 80,443,25,22', add_help=True) 
          parser.add_argument('-p', action='store', dest='argPorts', help='Type ports in like follows.  For a range -p 80-200, for a group of ports -p 443,80,25,22 or single port -p 80', required=True, type=str) 
          parser.add_argument('-d', action='store', dest='destIP', help='Type dest IP in this field.  i.e. 192.168.0.5', required=True)
          parser.add_argument('-t', action='store', dest='threadCount', help='Type the amount of threads to use as an integer', type=int, required=True)
  
          if len(sys.argv)&lt;3:
              parser.print_help()
                  sys.exit(0)
          opts = vars(parser.parse_args())
  
          options = parser.parse_args()
          argPorts = options.argPorts
          destIP = options.destIP
          threadCount = options.threadCount
  
          if argPorts.find(','):
              print "comma"
              for p in argPorts.split(','):
                  portlist.append(p)
  
          elif argPorts.find('-'):
              print "range"
              portlist.append(argPorts.split('-')[0])
              portlist.append(argPorts.split('-')[1])
  
          else:
              print "no"
  
  
          print portlist
  </code></pre>
  
  <p>I am using the command line as follows.
  python test.py -t 10 -p "80-100" -d "192.168.136.131"</p>
  
  <p>I am wanting to be able to split 80 and 100 to separate variables. But it doesnt work :(</p>
  
  <p>Answer below is great.</p>
  
  <p>Here is a good explanation for other people like me <a href="http://www.pythoncentral.io/how-to-see-if-a-string-contains-another-string-in-python/" rel="nofollow">http://www.pythoncentral.io/how-to-see-if-a-string-contains-another-string-in-python/</a></p>