Is it possible to run a function in Python using the command line

0 votes
I have recently started learning Python. I want to know whether it is possible to run a function using the command line. Please suggest how to do it.
Jun 26, 2019 in Python by Arvind
• 3,050 points
1,045 views

1 answer to this question.

0 votes

Suppose your file name is demo.py and it contains the following code

def my_func():

     return "Hello, World!"

Now you can run it from command line using following line

$ python -c 'from demo import my_func; print my_func()'
answered Jun 26, 2019 by Neel
• 3,020 points

so I was following a class and we were focusing on birthdays and how the computer could get ur age and I wrote

birth_year = input(‘birth year: ‘) 

And I said keyboardInterrupt can someone help I don’t know what to do

Hey, @Ella,

Could you please mention particularly which class you were focusing on? Is that any Youtube video or anything else?

Now, regarding your query, you can change:

birth_year = input(‘birth year: ‘) 

To

birth_year = input("birth year: ") 

I hope this will work.

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

I have trained a model using machine learning algorithm in python , now i want to create a browser extension of that saved model , Is it possible ??

Hi@Shubham, It may possible. When you saved your ML ...READ MORE

answered Jun 13, 2020 in Python by MD
• 95,460 points
1,128 views
0 votes
1 answer

Is it possible to break a long line to multiple lines in Python?

Example of implicit line continuation: a = some_function( ...READ MORE

answered Jan 4, 2021 in Python by Gitika
• 65,770 points
1,233 views
0 votes
1 answer

Is there a foreach function in python and is there a way to implement it if there isnt any

Every occurence of "foreach" I've seen (PHP, ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
1,153 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,070 views
0 votes
1 answer

Is it possible to print all the modules imported in a python script?

Since I am using Python 3.6, I ...READ MORE

answered Jul 3, 2019 in Python by Neel
• 3,020 points
3,417 views
+1 vote
1 answer

is it possible to compare a values to a backslash in Python?

The backslash "\" character is used to ...READ MORE

answered Jun 28, 2019 in Python by Neel
• 3,020 points
1,748 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP