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

Discussion in 'Python' started by Carl, May 20, 2004.

  1. Carl

    Carl Guest

    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
    Carl, May 20, 2004
    #1
    1. Advertising

  2. Carl

    Peter Hansen Guest

    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)"
    Peter Hansen, May 20, 2004
    #2
    1. Advertising

  3. Carl

    Carl Guest

    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
    Carl, May 20, 2004
    #3
  4. Carl

    Chris Guest

    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'
    Chris, May 21, 2004
    #4
  5. Carl

    Peter Hansen Guest

    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
    Peter Hansen, May 21, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    516
    Big Brian
    Oct 14, 2003
  2. Daniel Crespo
    Replies:
    5
    Views:
    393
    Amaury
    Nov 13, 2005
  3. vijay
    Replies:
    8
    Views:
    686
  4. Replies:
    10
    Views:
    620
  5. Roy
    Replies:
    6
    Views:
    577
    Roedy Green
    Jan 7, 2008
Loading...

Share This Page