command-line-arguments

Python: pass arguments to a script

懵懂的女人 提交于 2021-02-20 04:12:44
问题 I have a working code to print random lines from a csv column. #!/usr/bin/python import csv import random **col**=2 with open('<filename>','r') as f: reader=csv.reader(f) data=[row[col] for row in reader] from random import shuffle shuffle(data) print '\n'.join(data[:**100**]) f.close(); I want to paramaterize this script. by passing , position (col) & sample (e.g. 100 values) I am unable to find a decent tutorial which would explain this. any thoughts ? 回答1: You can use the sys module like

Parsing command-line options in C# [duplicate]

喜夏-厌秋 提交于 2021-02-18 17:10:47
问题 This question already has answers here : Best way to parse command line arguments in C#? [closed] (20 answers) Closed 3 years ago . I've seen people write custom classes to more easily handle command line options in various languages. I wondered if .NET (3.5 or lower) has anything built in so that you don't have to custom-parse things like: myapp.exe file=text.txt 回答1: Here is another possible approach. Very simple but it has worked for me in the past. string[] args = {"/a:b", "/c:", "/d"};

Passing Variables from a Shell-Script to a Fortran 90 Program

大兔子大兔子 提交于 2021-02-17 02:56:11
问题 I'm stuck on this little problem. I was wondering if it is possible to pass a variable of a bash-shell script to a f90 code? 回答1: I am pretty sure it was discussed here before, but I cannot find an exact duplicate. You can pass arguments directly as arguments to the program ./program arg1 arg2 you can retrieve the values in the program as character strings in Fortran 2003 using subroutines GET_COMMAND ARGUMENT and COMMAND_ARGUMENT_COUNT. Click on the links to get useful examples. In older

How can I preserve command line spaces in a linux application?

微笑、不失礼 提交于 2021-02-15 07:46:37
问题 As per this question here, I'm deploying a linux application on some local servers using a shell script that looks like: #!/bin/sh export LD_LIBRARY_PATH=./libs:$LD_LIBRARY_PATH exec ./TheBinary $* When I run TheBinary without these wrappers (but after having modified LD_LIBRARY_PATH, which I want to do via the script post-deployment), I can preserve spaces in the command line arguments using double quotes ("). But the above script appears to sanitize them away; how can I modify this script

How to implement argparse in Python

南楼画角 提交于 2021-02-11 15:41:28
问题 I'm new to Python, I got a small script to upload files to S3, at the moment I only hard-code one single file in the script, the bucket name is also hard-coded. I wanted to merge argparse in this script so that I can add some arguements by myself and upload different files. For example, in the command line I can specify arguments to decide file_name x upload to bucket_name xxx . I've been reading documents about how to set argparse but I can only make small changes and don't know how to

With CommonsCli, how do I parse an Option which can occur several times and has a flexible number of values?

≯℡__Kan透↙ 提交于 2021-02-11 15:00:45
问题 In some legacy code I'm porting a diy-command-line parser to Apache CommonsCli. I can't break previously allowed+documented Options, and one of the Options is giving me trouble: The Option has either one or two args, and can be specified as many times as desired. Option: [-option arg1 [arg2]]+ I want the result as String[][] as following: cli -option a b -option c should result in [ [a, b], [c,] ] and cli -option a -option b c should result in [ [a,], [b, c] ] My code looks something like

With CommonsCli, how do I parse an Option which can occur several times and has a flexible number of values?

和自甴很熟 提交于 2021-02-11 14:58:18
问题 In some legacy code I'm porting a diy-command-line parser to Apache CommonsCli. I can't break previously allowed+documented Options, and one of the Options is giving me trouble: The Option has either one or two args, and can be specified as many times as desired. Option: [-option arg1 [arg2]]+ I want the result as String[][] as following: cli -option a b -option c should result in [ [a, b], [c,] ] and cli -option a -option b c should result in [ [a,], [b, c] ] My code looks something like

Automatically open files given as command line arguments in Python

自古美人都是妖i 提交于 2021-02-11 10:54:10
问题 I have a lot of Perl scripts that looks something like the following. What it does is that it will automatically open any file given as a command line argument and in this case print the content of that file. If no file is given it will instead read from standard input. while ( <> ) { print $_; } Is there a way to do something similar in Python without having to explicitly open each file? 回答1: The fileinput module in Python's standard library is designed exactly for this purpose, and I quote

How to get command line arguments in OpenVMS Fortran?

送分小仙女□ 提交于 2021-02-10 18:23:12
问题 I need to realize c-code in fortran 90 standard and stopped on next problem. How get and use command line arguments. I found GET_COMMAND_ARGUMENT getarg But it doesn't work in the openvms system with fortran 90 compiler. There is another way to get command line arguments in Fortran? Example in C int main(int argc, char **argv) { if (argc > 1) .... } Example (which doesn't work " ILINK-W-NUDFSYMS, 2 undefined symbols: %ILINK-I-UDFSYM, GETARG %ILINK-I-UDFSYM, IARGC %ILINK-W-USEUNDEF, undefined

How to get command line arguments in OpenVMS Fortran?

狂风中的少年 提交于 2021-02-10 18:19:53
问题 I need to realize c-code in fortran 90 standard and stopped on next problem. How get and use command line arguments. I found GET_COMMAND_ARGUMENT getarg But it doesn't work in the openvms system with fortran 90 compiler. There is another way to get command line arguments in Fortran? Example in C int main(int argc, char **argv) { if (argc > 1) .... } Example (which doesn't work " ILINK-W-NUDFSYMS, 2 undefined symbols: %ILINK-I-UDFSYM, GETARG %ILINK-I-UDFSYM, IARGC %ILINK-W-USEUNDEF, undefined