Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60398
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <torriem+gmail@torriefamily.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'scripts': 0.03; 'subject:file': 0.07; 'sys': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'executable': 0.09; 'executed': 0.09; 'imported': 0.09; 'subject:script': 0.09; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'garg': 0.16; 'mean,': 0.16; 'sys.exit(0)': 0.16; 'prevent': 0.16; 'wrote:': 0.18; 'module': 0.19; 'command': 0.22; 'import': 0.22; 'header:User- Agent:1': 0.23; 'script': 0.25; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'run': 0.32; 'another': 0.32; 'linux': 0.33; 'totally': 0.33; 'subject:from': 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'like,': 0.36; 'doing': 0.36; 'should': 0.36; 'two': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| Date | Sun, 24 Nov 2013 19:58:31 -0700 |
| From | Michael Torrie <torriem@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Excute script only from another file |
| References | <989ee1b9-141a-4cb3-a9a2-f1527c0d0db3@googlegroups.com> |
| In-Reply-To | <989ee1b9-141a-4cb3-a9a2-f1527c0d0db3@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3158.1385349937.18130.python-list@python.org> (permalink) |
| Lines | 22 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1385349937 news.xs4all.nl 15986 [2001:888:2000:d::a6]:53194 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:60398 |
Show key headers only | View raw
On 11/24/2013 06:55 PM, Himanshu Garg wrote:
> I want that a script should only be executed when it is called from
> another script and should not be directly executable through linux
> command line.
>
> Like, I have two scripts "scrip1.py" and "script2.py" and there is a
> line in "script1.py" to call "script2.py" as
> subprocess.call(["python", "script2.py"]).
>
> Then this is should call script2 but I should not be able to directly
> call script2 as $python script2.py
I'm not totally sure what you mean, but if you want to prevent the
script from doing anything when run from the command line but have it do
something when imported as a module then just put this at the beginning:
if __name__ == "__main__":
import sys
sys.exit(0)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Excute script only from another file Himanshu Garg <hgarg.india@gmail.com> - 2013-11-24 17:55 -0800
Re: Excute script only from another file Chris Angelico <rosuav@gmail.com> - 2013-11-25 14:15 +1100
Re: Excute script only from another file Dave Angel <davea@davea.name> - 2013-11-24 22:20 -0500
Re: Excute script only from another file Larry Hudson <orgnut@yahoo.com> - 2013-11-26 00:10 -0800
Re: Excute script only from another file Michael Torrie <torriem@gmail.com> - 2013-11-24 19:58 -0700
Re: Excute script only from another file Peter Otten <__peter__@web.de> - 2013-11-25 09:12 +0100
Re: Excute script only from another file Himanshu Garg <hgarg.india@gmail.com> - 2013-11-25 02:52 -0800
Re: Excute script only from another file Dave Angel <davea@davea.name> - 2013-11-25 07:16 -0500
Re: Excute script only from another file Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-25 18:28 -0800
Re: Excute script only from another file Chris Angelico <rosuav@gmail.com> - 2013-11-26 13:41 +1100
Re: Excute script only from another file Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-25 19:45 -0800
Re: Excute script only from another file Steven D'Aprano <steve@pearwood.info> - 2013-11-26 03:09 +0000
Re: Excute script only from another file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-26 12:25 -0500
Re: Excute script only from another file Chris Angelico <rosuav@gmail.com> - 2013-11-27 10:09 +1100
Re: Excute script only from another file Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-26 17:56 -0800
Re: Excute script only from another file Chris Angelico <rosuav@gmail.com> - 2013-11-27 13:39 +1100
csiph-web