我如何接受命令行参数? [英] How do I take in Command Line arguments?

查看:111
本文介绍了我如何接受命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我有这个python脚本,让我可以选择我可以清零的文本文件的哪一列。它们的列nubmer存储为变量elem。我还获得了一个接受命令行争论的样本。我想知道是否有人可以帮助我将其集成到代码中,以便从命令行我可以输入一个数字并将脚本清零。


开始文本文件:

#Bits of Bits

12

#Data

0 0 0 0 0 0 0 0 0 0 0 0

12 5 3 4 6 4 5 4 7 5 5 10

24 9 7 7 13 7 9 9 14 10 10 20

$ b脚本运行后的$ b文本文件:

#Bits of Bits

12

#Data

0 0 0 0 0 0 0 0 0 0 0 0

0 5 3 4 6 4 5 4 7 5 5 10

0 9 7 7 13 7 9 9 14 10 10 20

这就是它的作用:

展开 | 选择 | Wrap | 行号

解决方案

此代码在Python 2.0中。


/ usr / bin / python hello.py 1 2 4 6 9


我有几个我一直在分发的例子是我的dex跟踪器项目中的tracker8.py(底部是url)。我做的是使用主要功能。您正在编写的代码看起来对我正在做的事情非常有用,并且可能允许从文件到您正在调零的列中的一系列数字可能对我的项目有很好的贡献:) ... http ://www.stormpages.com/edexter/csound.html

Right now, I have this python script that lets me choose which column of a text file that I can zero out. Them column nubmer is stored as the variable ''elem''. I also was given a sample of taking in command line arguements. I was wondering if anyone could help me intergrate this into the code so that from the command line I can input a number and have the script zero out the column.

beginning text file:
#Number of Bits
12
#Data
0 0 0 0 0 0 0 0 0 0 0 0
12 5 3 4 6 4 5 4 7 5 5 10
24 9 7 7 13 7 9 9 14 10 10 20

text file after script has been run:
#Number of Bits
12
#Data
0 0 0 0 0 0 0 0 0 0 0 0
0 5 3 4 6 4 5 4 7 5 5 10
0 9 7 7 13 7 9 9 14 10 10 20
and this is what it does:

Expand|Select|Wrap|Line Numbers

解决方案

This code is in Python 2.0.


/usr/bin/python hello.py 1 2 4 6 9


I have a couple of examples that I have been distributing one is in tracker8.py available in my dex tracker project (url at bottom). What I did was use a main function. The code you are writing looks like it would be usefull for what I am doing and maybe something that would allow a series of numbers from a file into the column you are zeroing out might be a good contribution to my project :) ... http://www.stormpages.com/edexter/csound.html


这篇关于我如何接受命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆