passing argument to python exexutable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • askalottaqs
    New Member
    • Jun 2007
    • 75

    passing argument to python exexutable

    Hello ppl,

    I have created a small code that i need it as an exe so i could distribute it over to other users, i used the py2exe, worked fine and gave me the exe, this is when i have all the code lying there (no defined functions)

    So when i try to define it as a function, so that i could pass arguments to, it would run with no errors, but does nothing!

    in other words, how do i pass arguments to this exe properly?

    Thanks a lot
  • elcron
    New Member
    • Sep 2007
    • 43

    #2
    Originally posted by askalottaqs
    Hello ppl,

    I have created a small code that i need it as an exe so i could distribute it over to other users, i used the py2exe, worked fine and gave me the exe, this is when i have all the code lying there (no defined functions)

    So when i try to define it as a function, so that i could pass arguments to, it would run with no errors, but does nothing!

    in other words, how do i pass arguments to this exe properly?

    Thanks a lot
    Since the format for a script is "python test.py function arg1 arg2 .. .argx"(without quotes) an exe would probably be somthing like "test[.exe] function arg1 arg2 .. .argx"(also without quotes)

    Comment

    • askalottaqs
      New Member
      • Jun 2007
      • 75

      #3
      i just tried to run the python code, through python through the command line:

      python c:\mycommand.ex e function arg1

      and it does absolutely nothing,

      within the code, i have one function defined as "function" and it takes one parameter called arg1


      before so, i had it without the function, just code lying there, and it was working perfectly, so could someone plz tell me what am i missin???

      i guess what i want to say is, how do i pass parameters properly to a python code,

      thanks a lot in advance

      Comment

      • askalottaqs
        New Member
        • Jun 2007
        • 75

        #4
        to be more precise, i have read the documentation, done my homework right, but it talks about inner functions and how to call them internally, but to call the finction with arguments from the command line, or even through python from outside the editor, i could not find anything,

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          I have never compiled a Python script, so I don't know if this will work, but have you tried accessing the argument(s) from the sys.argv variable list?

          Comment

          • jackinoob
            New Member
            • Mar 2008
            • 3

            #6
            askalottaqs:

            I am having the exact same problem currently. Please let me know if you've found a solution.

            Thanks,

            Comment

            • elcron
              New Member
              • Sep 2007
              • 43

              #7
              Django seems to accomplish this although it may do it this way.

              [code=python]
              import sys

              def sayHello(name):
              print "Hello, %s!"%name

              def main():
              if len(sys.argv) >= 2:
              if sys.argv[1] == "sayHello" and len(sys.argv) == 3:
              sayHello(sys.ar gv[2])

              main()

              # output in command prompt
              python test.py sayHello elcron
              Hello, elcron!
              [/code]

              Comment

              • askalottaqs
                New Member
                • Jun 2007
                • 75

                #8
                Originally posted by elcron
                Django seems to accomplish this although it may do it this way.

                [code=python]
                import sys

                def sayHello(name):
                print "Hello, %s!"%name

                def main():
                if len(sys.argv) >= 2:
                if sys.argv[1] == "sayHello" and len(sys.argv) == 3:
                sayHello(sys.ar gv[2])

                main()

                # output in command prompt
                python test.py sayHello elcron
                Hello, elcron!
                [/code]
                thank you just so much! you saved me mate :) cheers

                Comment

                • elcron
                  New Member
                  • Sep 2007
                  • 43

                  #9
                  Originally posted by askalottaqs
                  thank you just so much! you saved me mate :) cheers
                  np always glad to help :)

                  Comment

                  Working...