I am having a for
-loop which takes rows within a pandas dataframe df_drinks
and uses them as parameters to call another function order()
. order()
is imported from the module restaurant.py
.
Together with the row in df_drinks
, I want to submit a comment
to the order()
, which is specified outside the for-loop.
from restaurant import order
statement = "Lets order"
df_drinks = ["1 drink", "2 drink"] # simplified, 1 item per row, many columns
for index, row in df_drinks.iterrows():
print ("%s, %s" % (statement, row))
item = row
response = order(statement, item)
...
The module looks like this:
# restaurant.py
def order(statement, item):
listen(statement)
statement = "order received"
ready_drinks = prepare(item)
...
return ready_drinks
For the first run/row everything is fine since a print
yields:
Lets order 1 drink
However, for the second run/row, print
yields:
order received 2 drinks instead of Lets order 2 drinks.
I understand that I have the same variable name statement
for two different things. Still, I am confused since order()
in restaurant.py
does only return ready_drinks
and not statement
.
How to correctly assign local variables to a for-loop in python?