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. Advertisements

  2. Carl

    Peter Hansen Guest

    Use the -c option.

    python -c "import modulename; modulename.hello_msg('test', 5)"
     
    Peter Hansen, May 20, 2004
    #2
    1. Advertisements

  3. Carl

    Carl Guest

    Thanks, that was incredibly simple!

    Carl
     
    Carl, May 20, 2004
    #3
  4. Carl

    Chris Guest

    Or, from the command prompt, 'import modulename'
     
    Chris, May 21, 2004
    #4
  5. Carl

    Peter Hansen Guest

    ??

    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. Advertisements

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 (here). After that, you can post your question and our members will help you out.