Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8211577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:28:19+00:00 2026-06-07T10:28:19+00:00

I have written a Python module which contains functions that return arrays. I want

  • 0

I have written a Python module which contains functions that return arrays. I want to be able to access the string arrays returned from the python module, and iterate over in a bash script, so I may iterate over the array elements.

For example:

Python module (mymod)

def foo():
    return ('String', 'Tuple', 'From', 'Python' )

def foo1(numargs):
    return [x for x in range(numargs)]

Bash script

foo_array  = .... # obtain array from mymod.foo()
for i in "${foo_array[@]}"
do
    echo $i
done


foo1_array = .... # obtain array from mymod.foo1(pass arg count from bash)
for j in "${foo1_array[@]}"
do
    echo $j
done

How can I implement this in bash?.

version Info:

Python 2.6.5
bash: 4.1.5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:28:21+00:00Added an answer on June 7, 2026 at 10:28 am

    Second try – this time shell takes the integration brunt.

    Given foo.py containing this:

    def foo():
            foo = ('String', 'Tuple', 'From', 'Python' )
            return foo
    

    Then write your bash script as follows:

    #!/bin/bash
    FOO=`python -c 'from foo import *; print " ".join(foo())'`
    for x in $FOO:
    do
            echo "This is foo.sh: $x"
    done
    

    The remainder is first answer that drives integration from the Python end.

    Python

    import os
    import subprocess
    
    foo = ('String', 'Tuple', 'From', 'Python' )
    
    os.putenv('FOO', ' '.join(foo))
    
    subprocess.call('./foo.sh')
    

    bash

    #!/bin/bash
    for x in $FOO
    do
            echo "This is foo.sh: $x"
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a module in python which performs some function. I then created
I have written a Python module that I'd like to make available for others.
I have a Python module written in C with a number of functions exposed.
I have written a Python module, and I have two versions: a pure Python
I have written a Python script that will generate a series of graphs and
I have written a python script which watches a directory for new subdirectories, and
I have written a python script with methods in it. Now I want to
Well, i have written a simple python program that parses HTML with HTMLParser. Here
I have written a class in python that implements __str__(self) but when I use
I have written a python package which consists of several .py files which contain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.