argv

Using command line arguments in Python: Understanding sys.argv

送分小仙女□ 提交于 2019-12-19 07:31:10
问题 I'm currently going through Learn Python The Hard Way. I think this example might be out dated so I wanted to get feedback here on it. I'm using Python 3.1 from sys import argv script, first, second, third = argv print("the script is called:", (script)) print("your first variable is:", (first)) print("your second variable is:", (second)) print("your third variable is:", (third)) I'm getting this error: Traceback (most recent call last): File "/path/ch13.py", line 3, in <module> script, first,

Using command line arguments in Python: Understanding sys.argv

余生颓废 提交于 2019-12-19 07:30:27
问题 I'm currently going through Learn Python The Hard Way. I think this example might be out dated so I wanted to get feedback here on it. I'm using Python 3.1 from sys import argv script, first, second, third = argv print("the script is called:", (script)) print("your first variable is:", (first)) print("your second variable is:", (second)) print("your third variable is:", (third)) I'm getting this error: Traceback (most recent call last): File "/path/ch13.py", line 3, in <module> script, first,

Setting argv[0] in Haskell?

て烟熏妆下的殇ゞ 提交于 2019-12-19 05:44:56
问题 Is there a way to set argv[0] in a Haskell program (say, one compiled with ghc)? I found the getProgName and withProgName functions in System.Environment, but it doesn't seem to change what ps reports (Ubuntu). import System.Environment main = do name <- getProgName putStrLn $ "Hello, my name is " ++ name withProgName "other" $ do newname <- getProgName putStrLn $ "Name now set to " ++ newname putStrLn "What is your name: " -- allow time to run ps ans <- getLine putStrLn $ "Pleased to meet

python command line arguments in main, skip script name

拈花ヽ惹草 提交于 2019-12-19 05:18:26
问题 This is my script def main(argv): if len(sys.argv)>1: for x in sys.argv: build(x) if __name__ == "__main__": main(sys.argv) so from the command line I write python myscript.py commandlineargument I want it to skip myscript.py and simply run commandlineargument through commandlineargument(n) so I understand that my for loop doesn't account for this, but how do I make it do that? 回答1: Since sys.argv is a list, you can use slicing sys.argv[1:] : def main(argv): for x in argv[1:]: build(x) if _

Too many values to unpack

北城以北 提交于 2019-12-19 04:38:27
问题 I'm reading learn python the hard way, and on chapter 15 I'm suppose to use import argv to assign variables and raw input to gain user input. The script is: from sys import argv script, filename, = argv txt = open(filename) print " Here's your file %r :" % filename print txt.read() print " I'll also ask you to type it again: " file_again = raw_input ("> ") txt_again = open (file_again) print txt_again.read () After running this script I get the error, too many values to unpack. File "ex15.py"

from sys import argv - what is the function of “script”

流过昼夜 提交于 2019-12-18 11:48:17
问题 I am reading "Learn Python the Hard Way" and was confused by the "script" part of the second line. from sys import argv script, filename = argv From what I understand, the second line says: script and filename comprise argv . I tried running my code without the "script" part and it worked just fine. I'm not sure what the purpose of it is. 回答1: Generally, the first argument to a command-line executable is the script name, and the rest are the expected arguments. Here, argv is a list that is

Convert char to TCHAR* argv[]

北城余情 提交于 2019-12-18 08:56:21
问题 How can I input text into TCHAR* argv[] ? OR: How can I convert from char to TCHAR* argv[] ? char randcount[] = "Hello world"; TCHAR* argv[]; argv = convert(randcount); 回答1: One way to do is: char a[] = "Hello world"; USES_CONVERSION; TCHAR* b = A2T(a); 回答2: /*This code did TCHAR in my project without A2T or any other converters. Char text is a some kind of array. So we can take letters one by one and put them to TCHAR. */ #include <iostream> TCHAR* Converter(char* cha) { int aa = strlen(cha)

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

半腔热情 提交于 2019-12-17 21:59:04
问题 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') ['-

Argv - String into Integer

不问归期 提交于 2019-12-17 19:49:06
问题 I'm pretty new at python and I've been playing with argv. I wrote this simple program here and getting an error that says : TypeError: %d format: a number is required, not str from sys import argv file_name, num1, num2 = argv int(argv[1]) int(argv[2]) def addfunc(num1, num2): print "This function adds %d and %d" % (num1, num2) return num1 + num2 addsum = addfunc(num1, num2) print "The final sum of addfunc is: " + str(addsum) When I run filename.py 2 2, does argv put 2 2 into strings? If so,

Using argv in C?

那年仲夏 提交于 2019-12-17 14:44:33
问题 For an assignment, I am required to have command line arguments for my C program. I've used argc/argv before (in C++) without trouble, but I'm unsure if C style strings are affecting how this works. Here is the start of my main: int main(int argc, char *argv[]){ if(argc>1){ printf("0 is %s, 1 is %s\n",argv[0],argv[1]); if(argv[1]=="-e"){ // Do some stuff with argv[2] system("PAUSE"); } else{ printf("Error: Incorrect usage - first argument must be -e"); return 0; } } So I am calling my program