关于sys.argv []的Noob问题 [英] Noob question regarding sys.argv[]

查看:59
本文介绍了关于sys.argv []的Noob问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python的新手,从未编写过C程序,但我用C ++编写。我从未使用过argv,但是一项任务要求我学习它并立即使用它。我正在使用Python 2.5,IDLE(用于编写代码),使用Win XP专业版环境(无法让我的Ubuntu看到我的无线网卡)。


我应该编写一个模块,它将从命令行中获取一个参数,该参数将读取文件并对其进行处理。我真的不知道该怎么做,并会欣赏勺子喂养版教程。


帮助,请?

解决方案


我完全没事了Python的新手,从来没有写过C程序,但我用C ++编写。我从未使用过argv,但是一项任务要求我学习它并立即使用它。我正在使用Python 2.5,IDLE(用于编写代码),使用Win XP专业版环境(无法让我的Ubuntu看到我的无线网卡)。


我应该编写一个模块,它将从命令行中获取一个参数,该参数将读取文件并对其进行处理。我真的不知道该怎么做,并会欣赏勺子喂养版教程。


帮助,好吗?

文件中的

(比如myModule.py)

展开 | 选择 | 换行 | 行号


< blockquote>好的,所以说我的文件名是file.txt(它的格式是不一样的,比如.py?)。那是我的arg,对吗?所以:


python myModule.py file.txt


应该调用模块调用文本文件,对吧?


我感谢您的耐心等待。我一直在努力解决这个问题,我知道它应该是显而易见的,但由于某种原因它不是。



ok,所以说我的文件名是file.txt(它的格式是不同的,比如.py?)。那是我的arg,对吗?所以:


python myModule.py file.txt


应该调用模块调用文本文件,对吧?


我感谢您的耐心等待。我一直在努力解决这个问题,我知道这应该是显而易见的,但由于某种原因,它不是。

展开 | 选择 < span class =codeDivider> | Wrap | 行号


I''m completely new to Python, never wrote a C program, but I have written in C++. I''ve never used argv, but an assignment is requiring me to learn it and use it now. I''m using Python 2.5, IDLE (for writing code), using Win XP pro environment (can''t get my Ubuntu to see my wireless card).

I''m supposed to write a module that will take an argument from the command line that will read a file and process it. I really don''t know how to do this and would appreciate a spoon fed version tutorial.

Help, Please?

解决方案

I''m completely new to Python, never wrote a C program, but I have written in C++. I''ve never used argv, but an assignment is requiring me to learn it and use it now. I''m using Python 2.5, IDLE (for writing code), using Win XP pro environment (can''t get my Ubuntu to see my wireless card).

I''m supposed to write a module that will take an argument from the command line that will read a file and process it. I really don''t know how to do this and would appreciate a spoon fed version tutorial.

Help, Please?

in a file (say myModule.py)

Expand|Select|Wrap|Line Numbers


ok, so say my file name is file.txt (should it be formatted differently, like .py?). That is my arg, right? so:

python myModule.py file.txt

should call the module to call the text file, right?

I appreciate your patience. I''ve been trying to work this out all day, and I know it should be obvious, but for some reason it isn''t.


ok, so say my file name is file.txt (should it be formatted differently, like .py?). That is my arg, right? so:

python myModule.py file.txt

should call the module to call the text file, right?

I appreciate your patience. I''ve been trying to work this out all day, and I know it should be obvious, but for some reason it isn''t.

Expand|Select|Wrap|Line Numbers


这篇关于关于sys.argv []的Noob问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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