Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37504 > unrolled thread

Re: Any algorithm to preserve whitespaces?

Started byMichael Torrie <torriem@gmail.com>
First post2013-01-23 14:34 -0700
Last post2013-01-23 14:34 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Any algorithm to preserve whitespaces? Michael Torrie <torriem@gmail.com> - 2013-01-23 14:34 -0700

#37504 — Re: Any algorithm to preserve whitespaces?

FromMichael Torrie <torriem@gmail.com>
Date2013-01-23 14:34 -0700
SubjectRe: Any algorithm to preserve whitespaces?
Message-ID<mailman.921.1358976887.2939.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web