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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl

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

    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("Hell o 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("Hel lo no ", 3)

    Carl
  • Peter Hansen

    #2
    Re: python hello.py hello_msg(&quot ;Hello no", 3)??? Help, please!

    Carl wrote:
    [color=blue]
    > 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("Hell o 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("Hel lo no ", 3)[/color]

    Use the -c option.

    python -c "import modulename; modulename.hell o_msg('test', 5)"

    Comment

    • Carl

      #3
      Re: python hello.py hello_msg(&quot ;Hello no", 3)??? Help, please!

      Peter Hansen wrote:
      [color=blue]
      > Carl wrote:
      >[color=green]
      >> 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("Hell o 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("Hel lo no ", 3)[/color]
      >
      > Use the -c option.
      >
      > python -c "import modulename; modulename.hell o_msg('test', 5)"[/color]

      Thanks, that was incredibly simple!

      Carl

      Comment

      • Chris

        #4
        Re: python hello.py hello_msg(&quot ;Hello no", 3)??? Help, please!

        Peter Hansen wrote:
        [color=blue]
        > Carl wrote:
        >[color=green]
        >> 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("Hell o 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("Hel lo no ", 3)[/color]
        >
        > Use the -c option.
        >
        > python -c "import modulename; modulename.hell o_msg('test', 5)"[/color]

        Or, from the command prompt, 'import modulename'

        Comment

        • Peter Hansen

          #5
          Re: python hello.py hello_msg(&quot ;Hello no", 3)??? Help, please!

          Chris wrote:
          [color=blue]
          > Peter Hansen wrote:
          >
          >[color=green]
          >>Carl wrote:
          >>
          >>[color=darkred]
          >>>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("Hell o 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)[/color]
          >>
          >>Use the -c option.
          >>
          >>python -c "import modulename; modulename.hell o_msg('test', 5)"[/color]
          >
          > Or, from the command prompt, 'import modulename'[/color]

          ??

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

          -Peter

          Comment

          Working...