stop executing

Discussion in 'Python' started by Andreas Lobinger, Oct 5, 2004.

  1. 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
     
    Andreas Lobinger, Oct 5, 2004
    #1
    1. Advertising

  2. Andreas Lobinger <> 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@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
     
    Michael Hudson, Oct 5, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Sheen
    Replies:
    3
    Views:
    365
    Lloyd Sheen
    Mar 7, 2004
  2. Nick
    Replies:
    4
    Views:
    148
    C. Olive
    Sep 23, 2003
  3. Replies:
    5
    Views:
    141
    Dr John Stockton
    Mar 2, 2005
  4. Tom
    Replies:
    3
    Views:
    147
  5. mak
    Replies:
    4
    Views:
    102
    Evertjan.
    Mar 8, 2008
Loading...

Share This Page