stop executing

  • Thread starter Andreas Lobinger
  • Start date
A

Andreas Lobinger

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@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 and how do i
escape the tripple-" ?

Hoping for an answer and wishing a happy day
LOBI
 
M

Michael Hudson

Andreas Lobinger said:
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@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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top