python hello.py hello_msg("Hello no", 3)??? Help, please!

C

Carl

This is perhaps a very simple and stupid question!

How do you run a specific function (with actual values for the parameters)
within a module from the command prompt? That is, with "python ..."

For instance, how do I run hello_msg("Hello no ", 3), which is a function
within the module hello.py, from the console?

def hello_msg(msg, num):
print msg + str(num ** 3) +'!'
#hello_msg("Hello no ", 3)

Carl
 
P

Peter Hansen

Carl said:
This is perhaps a very simple and stupid question!

How do you run a specific function (with actual values for the parameters)
within a module from the command prompt? That is, with "python ..."

For instance, how do I run hello_msg("Hello no ", 3), which is a function
within the module hello.py, from the console?

def hello_msg(msg, num):
print msg + str(num ** 3) +'!'
#hello_msg("Hello no ", 3)

Use the -c option.

python -c "import modulename; modulename.hello_msg('test', 5)"
 
P

Peter Hansen

Chris said:
Peter Hansen wrote:



Or, from the command prompt, 'import modulename'

??

My example _was_ from the command prompt, and your approach
doesn't execute hello_msg() as the OP requested.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top