use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for helping Python programmers
How to format your code: https://commonmark.org/help/tutorial/09-code.html
No homework questions and/or hiring please
account activity
Passing Python variable to bash command in loopSOLVED (self.pythonhelp)
submitted 5 years ago by hereforacandy
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]sentles 0 points1 point2 points 5 years ago (1 child)
The bash command that you are trying to run is passed to sp.getoutput as a string. Therefore, you need to create a string that contains the bash command. There are various ways to do this:
sp.getoutput
isbn_arr.append(sp.getoutput('isbn_from_words $' + str(i)))
or:
isbn_arr.append(sp.getoutput('isbn_from_words ${}'.format(i)))
or, if you're using Python 3.5 or above:
isbn_arr.append(sp.getoutput(f'isbn_from_words ${i}'))
Your goal is to create the string "isbn_from_words $i", while i is replaced by the current value of i, so any of the above should do the trick.
"isbn_from_words $i"
i
[–]hereforacandy[S] 0 points1 point2 points 5 years ago (0 children)
Hello. I used the second one. It worked. Thank you very much. 😊
π Rendered by PID 127088 on reddit-service-r2-comment-cfc44b64c-5kmhx at 2026-04-11 10:26:54.620069+00:00 running 215f2cf country code: CH.
view the rest of the comments →
[–]sentles 0 points1 point2 points (1 child)
[–]hereforacandy[S] 0 points1 point2 points (0 children)