stop executing

Michael Hudson mwh at python.net
Tue Oct 5 09:29:00 EDT 2004


Andreas Lobinger <andreas.lobinger at netsurf.de> writes:

> Aloha,
> 
> i want to put a short script and additional data together in
> an shellexecutable, like this
> 
> --begin-file--
> #!/usr/bin/env python
> import sys
> print sys.argv
> sys.exit()
> 
> other data following, strictly not in python syntax...
> --end-file--
> 
> I would expect the interpreter to stop after the sys.exit, but of
> course the parser tries to read on.
> lobingera at scylla: b.py
>    File "b.py", line 7
>      other data
>               ^
> SyntaxError: invalid syntax
> 
> I have now a somehow working solution by putting the data in a
> multiline string, but that raises the subquestion:
> How much data can be put in a multiline string

Well, you'll get into real trouble around the 2 gig mark on most
machines, though I guess memory consumption will hurt you first.

> and how do i escape the tripple-" ?

backslashes?

Another option, instead of having 'python' in your hash-bang line
would be to have a program that preprocessed the file before handing
it to Python.

Cheers,
mwh

-- 
  If you don't use emacs, you're a pathetic, mewling, masochistic
  weakling and I can't be bothered to convert you.    -- Ron Echeverri



More information about the Python-list mailing list