# Question about converting Python to Ruby - getopt

**URL:** <https://www.ruby-forum.com/t/question-about-converting-python-to-ruby-getopt/104152>\
**Category:** Ruby\
**Created:** [May 14, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/question-about-converting-python-to-ruby-getopt/104152 "2007-05-14T20:25:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [May 14, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/question-about-converting-python-to-ruby-getopt/104152/1 "2007-05-14T20:25:45Z")

</div>

Is there an equivalent in Ruby of Python’s getopt (it parses  
command-line  
arguments)?

Mike S.

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [May 14, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/question-about-converting-python-to-ruby-getopt/104152/2 "2007-05-14T20:39:48Z")

</div>

quoth the Mike S.:

> Is there an equivalent in Ruby of Python’s getopt (it parses command-line  
> arguments)?
> 
> Mike S.

There are two: GetOptLong and OptionParser. Both are in the Standard  
Library.  
I believe GetOptLong is closer to the Python implementation.

-d

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [May 14, 2007, 8:40pm UTC](https://www.ruby-forum.com/t/question-about-converting-python-to-ruby-getopt/104152/3 "2007-05-14T20:40:48Z")

</div>

On 5/14/07, Mike S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there an equivalent in Ruby of Python’s getopt (it parses command-line  
> arguments)?

Look into the GetoptLong and optparse libraries. They are both part  
of the Ruby standard library.
