return-value

return statement is not working properly in for loop

return statement is not working properly in for loop Question: def chek(name): for i in range(3): print(name) print(i) if i == 1: chek(name=”name2″) elif name == ‘name2’: print(“changed name: “,name) return name s = chek(“name1”) print(“final name:”,s) In this code my expected output is : name1 0 name1 1 name2 0 changed name: name2 final …

Total answers: 1

How to get the return value of a function used in multiprocess in Python?

getting the return value of a function used in multiprocess Question: Say I have the below code, a function that does something, which is initiated in a Process, and returns a value. from multiprocessing import Process def my_func(arg): return ‘Hello, ‘ + arg p1 = Process(target=my_func, args=(‘John’,) p1.start() p1.join() How do I get the return …

Total answers: 2

Storing the returned values of calling a function in a loop in a list

Storing the returned values of calling a function in a loop in a list Question: I have two functions: SendMail(to, f_name, table ) – it sends a mail to the recipient using smtplib. Code snippet: def SendMail(to, f_name, table ) # … server = smtplib.SMTP_SSL(‘smtp.gmail.com’, 465) server.ehlo() server.login(gmail_user, gmail_password) print("Type ‘Y’ to send the mail! …

Total answers: 2

What is the use of a return statement?

What is the use of a return statement? Question: Let me clarify; Let us say that you have 2 functions in Python: def helloNot(): a = print(“Heya!”) helloNot() Which will print out Heya! without a return statement. But if we use a return statement in this function: def hello(): a = print(“Heya!”) return a hello() …

Total answers: 4

Python: How to get multiple return values from a threaded function

How to get multiple return values from a threaded function Question: Have called an external function which returns multiple values. def get_name(full_name): # you code return first_name, last_name In simple function call, I can get the results. from names import get_name first, last= get_name(full_name) But I need to use threading for the call to get …

Total answers: 2

Python returns nothing after recursive call

Python returns nothing after recursive call Question: I am working on a python script that calculates an individual’s tax based on their income. The system of taxation requires that people are taxed based on how rich they are or how much they earn. The first 1000 is not taxed, The next 9000 is taxed 10% …

Total answers: 2

How to return values without breaking the loop?

How to return values without breaking the loop? Question: I want to know how to return values without breaking a loop in Python. Here is an example: def myfunction(): list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’] print(list) total = 0 for i in list: if total < 6: return i #get first element …

Total answers: 4

Returning every element from a list (Python)

Returning every element from a list (Python) Question: I know that it is possible for a function to return multiple values in Python. What I would like to do is return each element in a list as a separate return value. This could be an arbitrary number of elements, depending on user input. I am …

Total answers: 6

How to obtain the results from a pool of threads in python?

How to obtain the results from a pool of threads in python? Question: I have searched here about how to do threading in python, but by far i haven’t been able to get the answer i need. I’m not very familiar with the Queue and Threading python classes and for that reason some of the …

Total answers: 1

Best way to return a value from a python script

Best way to return a value from a python script Question: I wrote a script in python that takes a few files, runs a few tests and counts the number of total_bugs while writing new files with information for each (bugs+more). To take a couple files from current working directory: myscript.py -i input_name1 input_name2 When …

Total answers: 1