Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7855

Re: Embedding Python in a shell script

From Timo Lindemann <tlindemann@arcor.de>
Subject Re: Embedding Python in a shell script
Newsgroups comp.lang.python
References <mailman.50.1308272248.1164.python-list@python.org> <cpydncH6HOHbDmbQnZ2dnUVZ8uadnZ2d@powerusenet.com> <4dfbb5fd$0$49178$e4fe514c@news.xs4all.nl>
Message-ID <cpydncD6HOH8IWbQnZ2dnUVZ8uadnZ2d@powerusenet.com> (permalink)
Date 2011-06-17 15:43 -0500

Show all headers | View raw


On Fri, 17 Jun 2011 22:15:57 +0200, Hans Mulder said:

> On 17/06/11 19:47:50, Timo Lindemann wrote:
>> On Fri, 17 Jun 2011 00:57:25 +0000, Jason Friedman said:
>>
>>
>>
>>> but for various reasons I want a single script.  Any alternatives?
>>
>> you can use a here document like this:
> That does not solve the problem as stated.  The OP wants to call python
> inside a loop and he wants to indent things properly:

so, wrap it inside a bash function like this:

#! /bin/bash

call_python() {
/usr/bin/python2 << EOPYTHON
def hello():
	print("Hello, World $1");

if __name__ == "__main__":
	hello();

EOPYTHON
}

for i in 1 2 3 4 5 6
do
	call_python $i
done	

That way, the indentation on is nicer; passing parameters to the script 
inside the heredoc might be mean if the parameters are formed 
difficultly, like, causing syntax errors if it's something like '"' or 
somesuch. Probably beside the point though. 

> For some ideas that may work, read the earlier posts in this thread.

maybe my news server doesn't fetch the whole thread. I didnt see any 
replies, and still don't except yours. 

Nice evenin'
-T.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Embedding Python in a shell script Jason Friedman <jason@powerpull.net> - 2011-06-17 00:57 +0000
  Re: Embedding Python in a shell script Timo Lindemann <tlindemann@arcor.de> - 2011-06-17 12:47 -0500
    Re: Embedding Python in a shell script Hans Mulder <hansmu@xs4all.nl> - 2011-06-17 22:15 +0200
      Re: Embedding Python in a shell script Timo Lindemann <tlindemann@arcor.de> - 2011-06-17 15:43 -0500

csiph-web