473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Mar 8 '08 #1
8 1476
elcron
43
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)
Mar 8 '08 #2
i just tried to run the python code, through python through the command line:

python c:\mycommand.exe 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
Mar 9 '08 #3
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,
Mar 9 '08 #4
bvdet
2,851 Expert Mod 2GB
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?
Mar 9 '08 #5
askalottaqs:

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

Thanks,
Mar 9 '08 #6
elcron
43
Django seems to accomplish this although it may do it this way.

Expand|Select|Wrap|Line Numbers
  1. import sys
  2.  
  3. def sayHello(name):
  4.     print "Hello, %s!"%name
  5.  
  6. def main():
  7.     if len(sys.argv) >= 2:
  8.         if sys.argv[1] == "sayHello" and len(sys.argv) == 3:
  9.             sayHello(sys.argv[2])
  10.  
  11. main()
  12.  
  13. # output in command prompt
  14. python test.py sayHello elcron
  15. Hello, elcron!
  16.  
Mar 9 '08 #7
Django seems to accomplish this although it may do it this way.

Expand|Select|Wrap|Line Numbers
  1. import sys
  2.  
  3. def sayHello(name):
  4.     print "Hello, %s!"%name
  5.  
  6. def main():
  7.     if len(sys.argv) >= 2:
  8.         if sys.argv[1] == "sayHello" and len(sys.argv) == 3:
  9.             sayHello(sys.argv[2])
  10.  
  11. main()
  12.  
  13. # output in command prompt
  14. python test.py sayHello elcron
  15. Hello, elcron!
  16.  
thank you just so much! you saved me mate :) cheers
Mar 10 '08 #8
elcron
43
thank you just so much! you saved me mate :) cheers
np always glad to help :)
Mar 10 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andrew Chalk | last post by:
I am a raw beginner to Python. I just read in "Learning Python" that assigning to a string argument inside a function does not change the string in the caller. I want an assignment in the function...
1
by: U-CDK_CHARLES\\Charles | last post by:
List: I've a Python COM server that keeps an event logs. I've been using it from VB6: logEvent "Message" The Python side of things looks like:
8
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
3
by: eight02645999 | last post by:
hi if i have a string like this "ABCE-123456 ABC_DEF_Suggest(abc def ghi).txt" that needs to be passed to a python script and i wanted to get the words inside the brackets after i passed...
14
by: Jack | last post by:
I like Python but I don't really like Python's installation. With PHP, I only need one file (on Linux) and maybe two files on Windows then I can run my PHP script. This means no installation is...
1
by: m2i3k | last post by:
Hi I have C code with requires me to register a python callback. I am able to get the callback working well using ctypes if I use global functions without any context argument for the callback. ...
5
by: kyosohma | last post by:
I have created what amounts to a simple GUI email sending program using Python + wxPython. I have modified the mailto registration in the Windows Registry so that it launches the script when...
0
by: Gabriel Genellina | last post by:
En Wed, 22 Oct 2008 19:10:27 -0200, Philip Semanchuk <philip@semanchuk.comescribió: Are you *really* sure you want to supply a specific address argument? Most of the time (if not always,...
1
by: Fizzics | last post by:
This is my first post here at Bytes. I have been trolling it, mostly with the help of Google searches, for some time now. I have done about all of the searching and reading that I really know how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.