2

Say there is the following function in a file called fb_auth_token.py

def get_fb_access_token(email, password): ... return ... 

How would I run this from bash? python fb_auth_token.py get_fb_access?. How do I call just the one specific function?

1
  • It depends on what exactly you want to do. You could for example just call it in your Python file: print(get_fb_access_token(email, password)). And then run python fb_auth_token.py Commented Aug 15, 2017 at 17:48

3 Answers 3

11

You could either call python with the command option:

python -c "from file_name import function;function()" 

or if you want this function to be called every time you execute the script you could add the line

if __name__ == "__main__": function() 

This will then only execute this function if the file is executed directly (i.e. you can still import it into another script without "function" being called).

Sign up to request clarification or add additional context in comments.

Comments

1

I figured it out:

python -c 'import fb_auth_token; print fb_auth_token.get_fb_access_token("email", "password")'

Comments

1

You can use the -c command line argument. For example:

python -c 'import fb_auth_token; fb_auth_token.get_fb_access_token("email", "password")' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.