argv

Problem with sys.argv[1] when unittest module is in a script

孤人 提交于 2019-11-29 01:53:40
I have a script that does various things and access paramenters using sys.argv but when the script gets to the unittest part of the code it says there is no module for this. The script that I have is: class MyScript(): def __init__(self): self.value = sys.argv[1] def hello(self): print self.value def suite(self): modules_to_test = ('external_sanity_onvif', 'starttest') alltests = unittest.TestSuite() for module in map(__import__, modules_to_test): alltests.addTest(unittest.findTestCases(module)) return alltests if __name__ == '__main__': Run = MyScript() Run.hello() log_file = 'log_file.txt'

What is the type of command-line argument `argv` in C?

我的未来我决定 提交于 2019-11-29 01:12:05
问题 I'm reading a section from C Primer Plus about command-line argument argv and I'm having difficulty understanding this sentence. It says that, The program stores the command line strings in memory and stores the address of each string in an array of pointers. The address of this array is stored in the second argument. By convention, this pointer to pointers is called argv , for argument values . Does this mean that the command line strings are stored in memory as an array of pointers to array

Python, how to parse strings to look like sys.argv

最后都变了- 提交于 2019-11-28 18:11:38
I would like to parse a string like this: -o 1 --long "Some long string" into this: ["-o", "1", "--long", 'Some long string'] or similar. This is different than either getopt, or optparse, which start with sys.argv parsed input (like the output I have above). Is there a standard way to do this? Basically, this is "splitting" while keeping quoted strings together. My best function so far: import csv def split_quote(string,quotechar='"'): ''' >>> split_quote('--blah "Some argument" here') ['--blah', 'Some argument', 'here'] >>> split_quote("--blah 'Some argument' here", quotechar="'") ['--blah',

Numbers passed as command line arguments in python not interpreted as integers

女生的网名这么多〃 提交于 2019-11-28 10:44:31
I am familiar with C, and have started experimenting in python. My question is regarding the sys.argv command. I've read it is used for a command line interpreter, but when trying to execute a simple program I don't get the results I expect. Code: import sys a = sys.argv[1] b = sys.argv[2] print a, b print a+b Input: python mySum.py 100 200 Output: 100 200 100200 When I add the two arguments they are concatenated instead of the two values being added together. It seems that the values are being taken as strings. How can I interpret them as numerics? You can convert the arguments to integers

Are char * argv[] arguments in main null terminated?

こ雲淡風輕ζ 提交于 2019-11-28 09:35:33
So I'm wondering if command line parameters are always null terminated? Google seems to say yes, and compiling on GCC indicates this is the case, but can I guarantee this to always be true? int main(int argc, char** argv) { char *p; for(int cnt=1; cnt < argc; ++cnt) { p = argv[cnt]; printf("%d = [%s]\n", cnt, p); } return 0; } $ MyProgram -arg1 -arg2 -arg3 1 = -arg1 2 = -arg2 3 = -arg3 James McNellis Yes. The non-null pointers in the argv array point to C strings, which are by definition null terminated. The C Language Standard simply states that the array members "shall contain pointers to

Python: Which encoding is used for processing sys.argv?

白昼怎懂夜的黑 提交于 2019-11-28 08:09:19
In what encoding are the elements of sys.argv , in Python? are they encoded with the sys.getdefaultencoding() encoding? sys.getdefaultencoding(): Return the name of the current default string encoding used by the Unicode implementation. PS : As pointed out in some of the answers, sys.stdin.encoding would indeed be a better guess . I would love to see a definitive answer to this question, though, with pointers to solid sources! PPS : As Wim pointed out, Python 3 solves this issue by putting str objects in sys.argv (if I understand correctly). The question remains open for Python 2.x, though.

What does 'sys.argv' mean?

社会主义新天地 提交于 2019-11-28 07:51:24
I am learning from code, and I am get confused by one of its lines which is: things = [float(arg) for arg in sys.argv[1:]] Omega_a, Omega_b, Delta_a, Delta_b, \ init_pop_a, init_pop_b, tstep, tfinal = things I have searched online and tried to understand what sys.arg means, and here is my understanding: So sys.argv[0] is the file name, and sys.argv[1:] is the rest of the parameters which should given by users. I am not sure am I understood it right, and if it is, then I don't understand why cant it be like: Omega_a = input() Omega_b = input() etc... What's the difference between these two ways

How to change argv0 in bash so command shows up with different name in ps?

萝らか妹 提交于 2019-11-28 06:51:18
In a C program I can write argv[0] and the new name shows up in a ps listing. How can I do this in bash? You can do it when running a new program via exec -a <newname> . I've had a chance to go through the source for bash and it does not look like there is any support for writing to argv[0]. Just for the record, even though it does not exactly answer the original poster's question, this is something trivial to do with zsh : ARGV0=emacs nethack ( exec -a foo bash -c 'echo $0' ) I'm assuming you've got a shell script that you wish to execute such that the script process itself has a new argv[0]

python: sys.argv[0] meaning in official documentation

蓝咒 提交于 2019-11-28 04:53:59
问题 Quoting from docs.python.org: " sys.argv The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c' . If no script name was passed to the Python interpreter, argv[0] is the empty string." Am I missing something, or sys.argv[0] always returns the script name, and to get '-c' I

Difference between char *argv[] and char **argv for the second argument to main()

坚强是说给别人听的谎言 提交于 2019-11-28 04:11:59
CODE 1 #include<stdio.h> int main(int argc, char *argv[]) { int j; printf("%d", argv[1][0]); return 0; } CODE 2 #include<stdio.h> int main(int argc, char **argv) { int j; printf("%d", argv[1][0]); return 0; } CODE 1 and CODE 2 both give same output. but argument 2 of main function in CODE 1 and CODE 2 are different. Array of pointers are created above data section at compile time. argv is array of pointers. Then we should declare argument in main function as pointer to pointer to character i.e., **argv. How it is correct to declare as in CODE 1? Basically, char* argv[] means array of char