# Python and ruby together?

**URL:** <https://www.ruby-forum.com/t/python-and-ruby-together/173186>\
**Category:** Ruby\
**Created:** [August 4, 2009, 5:30pm UTC](https://www.ruby-forum.com/t/python-and-ruby-together/173186 "2009-08-04T17:30:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gwen\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/59ef9b/32.png) [@Gwen\_M](https://www.ruby-forum.com/u/Gwen_M)\
**Post date:** [August 4, 2009, 5:30pm UTC](https://www.ruby-forum.com/t/python-and-ruby-together/173186/1 "2009-08-04T17:30:31Z")

</div>

Is it possible to set up python scripts in such a way that they can  
parse ruby files?

ie: I have a script written in ruby.

I have 3rd party program that reads python scripts but not ruby  
scripts. I want the 3rd party program to read my ruby script.

Can I load some sort of ruby library via python or do I need to hit  
the python books and start studying?

Gwen

---

<div class="post-metadata">

**Author:** ![Gwen\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/59ef9b/32.png) [@Gwen\_M](https://www.ruby-forum.com/u/Gwen_M)\
**Post date:** [August 4, 2009, 6:08pm UTC](https://www.ruby-forum.com/t/python-and-ruby-together/173186/2 "2009-08-04T18:08:34Z")

</div>

On Tue, Aug 4, 2009 at 11:30 AM, Gwen M.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Is it possible to set up python scripts in such a way that they can  
> parse ruby files?
> 
> ie: I have a script written in ruby.
> 
> I have 3rd party program that reads python scripts but not ruby  
> scripts. I want the 3rd party program to read my ruby script.

Does that program allow shell access? Easiest might be to just call  
your ruby script from within the python one.  
(If it indeed makes sense to do that at all 😉

---

<div class="post-metadata">

**Author:** ![Gwen\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/59ef9b/32.png) [@Gwen\_M](https://www.ruby-forum.com/u/Gwen_M)\
**Post date:** [August 4, 2009, 11:28pm UTC](https://www.ruby-forum.com/t/python-and-ruby-together/173186/3 "2009-08-04T23:28:56Z")

</div>

Gwen M. wrote:

> Is it possible to set up python scripts in such a way that they can  
> parse ruby files?

## r1test.rb:

puts “hello”  
puts “world”

## python\_prog.py:

f = open(“r1test.rb”)

for line in f:  
line = line.strip() #chop newline off  
pieces = line.split()

```
print line
print pieces[-1]
print

```

–output:–  
puts “hello”  
“hello”

puts “world”  
“world”

---

<div class="post-metadata">

**Author:** ![Gwen\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/59ef9b/32.png) [@Gwen\_M](https://www.ruby-forum.com/u/Gwen_M)\
**Post date:** [August 4, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/python-and-ruby-together/173186/4 "2009-08-04T23:47:34Z")

</div>

On 8/4/09, Gwen M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is it possible to set up python scripts in such a way that they can  
> parse ruby files?

Parsing ruby is very complex, and there are very few complete (or  
nearly complete) ruby parsers out there. It’s possible that some  
python library exists that can parse ruby, but unlikely. Your best bet  
is to use one of the existing ruby parsers from a ruby interpreter  
running in a separate process, serialize the tree it outputs and  
figure out how to unserialize that into python data.

The ruby parsers I know of are:

RedParse (disclaimer: I wrote this one)  
ParseTree (+JParseTree for jruby)  
ruby\_parser  
RubyNode  
ruby 1.9 + Ripper (which I only discovered today can output a tree)

---

<div class="post-metadata">

**Author:** ![Gwen\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/59ef9b/32.png) [@Gwen\_M](https://www.ruby-forum.com/u/Gwen_M)\
**Post date:** [August 5, 2009, 12:43am UTC](https://www.ruby-forum.com/t/python-and-ruby-together/173186/5 "2009-08-05T00:43:11Z")

</div>

Does this do what you want?  
[http://github.com/why/unholy/tree/master](http://github.com/why/unholy/tree/master)

-chris

---

<div class="post-metadata">

**Author:** ![Gwen\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/59ef9b/32.png) [@Gwen\_M](https://www.ruby-forum.com/u/Gwen_M)\
**Post date:** [August 4, 2009, 11:44pm UTC](https://www.ruby-forum.com/t/python-and-ruby-together/173186/6 "2009-08-04T23:44:05Z")

</div>

7stud – wrote:

> Gwen M. wrote:
> 
> > Is it possible to set up python scripts in such a way that they can  
> > parse ruby files?

Hmm…now I wonder if you understand the difference between ‘read’ or  
‘parse’ and ‘execute’.
