[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: converting Python to Ruby - question about main

Roland Crosby

4/20/2007 3:46:00 PM

On Apr 20, 2007, at 11:39 AM, Mike Steiner wrote:

> Some Python programs have a couple lines of code like this:
>
> if __main__ == "__main__"
> main()
>
> I think it's supposed to call the main function if the script is
> executed
> directly. Is there an equivalent in Ruby? Or is it even necessary
> in Ruby?
>
> (I'm new to Ruby, so excuse me if this is a stupid question.)
>
> Mike Steiner

I'm not entirely sure what that Python code means, but to do
something if the script is executed directly, you can try:

if __FILE__ == $0
(do something)
end

1 Answer

Greg Donald

4/20/2007 6:41:00 PM

0

On 4/20/07, Jason Roelofs <jameskilton@gmail.com> wrote:
> > > Some Python programs have a couple lines of code like this:
> > >
> > > if __main__ == "__main__"


I'm guessing the original poster probably meant this:

if __name__ == '__main__':



--
Greg Donald
http://des...