Just add b as a parameter of the function, if I understand you correctly.
Consider:
def function(user,b):
user.getApple().eatTheApple(b, 2000, 50, 1, 8663, 4444)
Then we could test with (assuming the class User is defined somewhere else):
import random
myUser = User()
b = random.choice([2309,1897,2307])
function( myUser , b )
We've made a function of two parameters, and passed them both in! An alternative would be:
def function(user):
user.getApple().eatTheApple( random.choice([2309,1897,2307], 2000, 50, 1, 8663, 4444)
I've assumed that User is a class somewhere, so there might be a prettier way to do this yet, if this is appropriate for your circumstances (it might not be). We have our class declaration:
class User:
def __init__( self ):
#this code is executed when the class is created
self.b = random.choice([2309,1897,2307])
def function( self ):
#this code is owned by each User object
user.getApple().eatTheApple(self.b, 2000, 50, 1, 8663, 4444)
That would be executed by:
myUser = User()
myUser.function()
Python likes object-oriented design, so this would be nice! However, it assumes that the "b" value is personal to the user, and doesn't change. I'll give you alternatives, if it does
user? Does the input tofunctionactually have agetApplemethod that returns a thing with aneatTheApplemethod?