By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Carl wrote:
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)"

Jul 18 '05 #2

P: n/a
Peter Hansen wrote:
Carl wrote:
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)"


Thanks, that was incredibly simple!

Carl

Jul 18 '05 #3

P: n/a
Peter Hansen wrote:
Carl wrote:
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)"


Or, from the command prompt, 'import modulename'

Jul 18 '05 #4

P: n/a
Chris wrote:
Peter Hansen wrote:

Carl wrote:

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)"


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
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.