Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

difference between "main" script and sourced script

5 views
Skip to first unread message

Glenn Jackman

unread,
May 1, 2009, 3:45:04 PM5/1/09
to
Apologies if this has been answered recently. wiki.tcl.tk is currently
down.

I'm looking for the equivalent of python's
if __name__ == "__main__":

Would it be
if {[info frame] == 1} {...

?

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous

Glenn Jackman

unread,
May 1, 2009, 4:14:51 PM5/1/09
to
At 2009-05-01 03:45PM, "Glenn Jackman" wrote:
> Apologies if this has been answered recently. wiki.tcl.tk is currently
> down.
>
> I'm looking for the equivalent of python's
> if __name__ == "__main__":
>
> Would it be
> if {[info frame] == 1} {...

To answer my own question, that is incorrect.

The correct answer:
if {[info script] eq $::argv0} ...

Also, it seems that [info frame] returns 2 when inside the if condition

$ cat frame.tcl
set f1 [info frame]
if {[set f2 [info frame]] == 1} {
puts "in frame 1"
} else {
puts "f1=$f1"
puts "f2=$f2"
}

$ tclsh85 frame.tcl
f1=1
f2=2

0 new messages