#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    10
    Rep Power
    0

    Unhappy I can't execute function from PowerShell?!?!?!?!?


    I just started learning python and coding functions and up to yesterday, everything was going fine, but now whenever I try to run any function from PowerShell I get an error message.
    NO FUNCTIONS WILL WORK FOR SOME REASON

    E.G
    This is the "a5.py" file I wrote in Notepad++:
    -----------------------------------------------------
    def random_func():
    print "Hello."

    random_func()
    -----------------------------------------------------
    and this is what I got in PowerShell:
    -----------------------------------------------------
    PS C:\Users\samsung\Documents> python a5.py
    Hello
    -----------------------------------------------------
    Perfect so far.... but when I comment out the function call (random_func()) in the "a5.py" file and try to call the function using PowerShell, this happens:
    -----------------------------------------------------
    PS C:\Users\samsung\Documents> python a5.py
    PS C:\Users\samsung\Documents> random_func()
    At line:1 char:13
    + random_func()
    + ~
    An expression was expected after '('.
    + CategoryInfo : ParserError: ( [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedExpression
    -----------------------------------------------------
    ALL I DID WAS TAKE OUT THE FUNCTION CALL IN THE NOTEPAD FILE.
    WHY CAN'T I EXECUTE THE FUNCTION FROM POWERSHELL???
    Sorry but this is super frustrating I can't execute a single function, any idea what the problem may be?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,931
    Rep Power
    481
    Try this in your power shell:

    Code:
    PS C:\Users\samsung\Documents> python
    >>> import a5
    >>> a5.random_function()
    Hello.
    >>> exit(0)
    PS C:\Users\samsung\Documents>
    Your python program worked, that is it created a definition for random_function and then quit. It did not export the name and definition back to power shell. Start python. Use python. exit from python back to power shell. As I don't actually have power shell to test, I'm guessing and hoping this works as shown.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo