Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Any algorithm to preserve whitespaces?

Reply
Thread Tools

Re: Any algorithm to preserve whitespaces?

 
 
Michael Torrie
Guest
Posts: n/a
 
      01-23-2013
On 01/23/2013 07:56 AM, Santosh Kumar wrote:
> Yes, Peter got it right.
>
> Now, how can I replace:
>
> script, givenfile = argv
>
> with something better that takes argv[1] as input file as well as
> reads input from stdin.
>
> By input from stdin, I mean that currently when I do `cat foo.txt |
> capitalizr` it throws a ValueError error:
>
> Traceback (most recent call last):
> File "/home/santosh/bin/capitalizr", line 16, in <module>
> script, givenfile = argv
> ValueError: need more than 1 value to unpack
>
> I want both input methods.


That's up to your program logic to do. Check to see if the arguments
have been provided, and if not, open sys.stdin. It's quite common for
command-line utilities to do this, but most of them use an explicit
parameter '-' to indicate that you want the command to use standard-in.
Again, you can code this any way you want. Personally I use one of the
standard library command-line argument parsing modules, like optparse,
but there are others that may be better.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Any algorithm to preserve whitespaces? Santosh Kumar Python 0 01-23-2013 09:20 AM
Re: Any algorithm to preserve whitespaces? Mitya Sirenef Python 0 01-19-2013 07:04 PM
Re: Any algorithm to preserve whitespaces? Lie Ryan Python 0 01-19-2013 10:26 AM
Any algorithm to preserve whitespaces? Santosh Kumar Python 0 01-19-2013 10:13 AM
FileUtils - :preserve does not preserve mtime of directories on Windoze Grzegorz Chrupala Ruby 2 06-30-2003 07:38 AM



Advertisments