Skip to content
Advertisement

Passing two variables between functions

EDIT I have made huge mess! I’m sincerely sorry! Issue is not about last 2 print statement. Those were added when I run out of idea. Whole issue is about passing title and final_price form check_price to send_email and use them in body and subject.

I’ve just hit brick wall and don’t know here to find answer. I have tried to create web scraper according to some guide on YT. However due to my lack in knowledge and experience im stuck on issue how to pass 2 variable title and final_price from function check_price() to function send_mail()

Everything will work if I’ll try to send email without those variables using just plain text.

JavaScript

EDIT Issue was solved. I,m r thankful for all assistance.

Below fixed and cleaned code.

JavaScript

Later i’ve hit wall where Send_email() generated error that ValueError: Header values may not contain linefeed or carriage return characters Which was caused by variable title (it was not striped from all empty lines above and below.

One more time big thank’s you to all.

Advertisement

Answer

I believe your way of getting the variables title and final_price is just fine, it should work.

However, the last two prints shouldn’t work as they are outside of the send_email() function and therefore title and final_price are unknown. Have you tried putting the print inside the function and calling it?

Update:

I see the error now, you are calling send_email() inside check_price(), and check_price() inside send_email(), which can lead to a neverending loop.

To solve this, if the function you wish to call is check_price(), you could make send_email() accept two parameters and pass them when you call it. So, in check_price() you would do:

JavaScript

and then send_email would be as follows:

JavaScript

Update 2:

You are also using an apostrophe inside a single quote string in:

JavaScript

you should do:

JavaScript
Advertisement