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


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

Re: Any algorithm to preserve whitespaces?

Started bySantosh Kumar <sntshkmr60@gmail.com>
First post2013-01-23 20:26 +0530
Last post2013-01-23 21:05 -0500
Articles 3 — 3 participants

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? Santosh Kumar <sntshkmr60@gmail.com> - 2013-01-23 20:26 +0530
    Re: Any algorithm to preserve whitespaces? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-24 11:49 +1100
      Re: Any algorithm to preserve whitespaces? Dave Angel <d@davea.name> - 2013-01-23 21:05 -0500

#37477 — Re: Any algorithm to preserve whitespaces?

FromSantosh Kumar <sntshkmr60@gmail.com>
Date2013-01-23 20:26 +0530
SubjectRe: Any algorithm to preserve whitespaces?
Message-ID<mailman.900.1358953018.2939.python-list@python.org>
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.

[toc] | [next] | [standalone]


#37526

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-01-24 11:49 +1100
Message-ID<51008538$0$29992$c3e8da3$5496439d@news.astraweb.com>
In reply to#37477
Santosh Kumar wrote:

> Yes, Peter got it right.

Peter? Which Peter? What's "it" that he got right?

You have deleted all context from your post, so I have no idea what you are
talking about. And whatever program you are using to post is stripping out
threading information, so I can't tell what post you are replying to.

Please take careful note of the posting conventions used by the experienced
regulars on this forum, and copy their style. That is for your benefit as
well as ours.


> 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.

The usual convention in Unix and Linux is that if the file name is "-", read
from stdin instead. Something like this, untested:


givenfile = sys.argv[1]
if givenfile == '-':
    data = sys.stdin.read()
else:
    data = open(givenfile).read()


Adding error checking etc. is left as an exercise.




-- 
Steven

[toc] | [prev] | [next] | [standalone]


#37529

FromDave Angel <d@davea.name>
Date2013-01-23 21:05 -0500
Message-ID<mailman.938.1358993181.2939.python-list@python.org>
In reply to#37526
On 01/23/2013 07:49 PM, Steven D'Aprano wrote:
> Santosh Kumar wrote:
>
>> Yes, Peter got it right.
>
> Peter? Which Peter? What's "it" that he got right?
>
> You have deleted all context from your post, so I have no idea what you are
> talking about.

Right.

> And whatever program you are using to post is stripping out
> threading information, so I can't tell what post you are replying to.

You're not entirely right here.  Santosh's message threads correctly to 
mine when I look with Thunderbird. And mine is parallel to one by Peter 
Otten, who suggested rstrip() to get rid of the extra newline.  About 
10% of your posts show up as top-level (starting new threads), even 
though I know you're careful.  So there seem to be more than one 
threading protocol, and the multiple protocols are fighting each other. 
  I'd love to see a spec that I could use to (manually?) check whether 
the threads are right or not.

the relevant timestamps (at least as seen from USA EST zone) are
     Santosh at 4:20 am
        Peter Otten at 4:46 am
        DaveA  at 5:34 am
           Santosh at 9:56 am
     Steven D'Aprano at 7:49 pm

But your message was a reply to Santosh's 9:56 am message.

(I'm deleting the rest, because I'm not responding to the commandline 
parsing question)




-- 
DaveA

[toc] | [prev] | [standalone]


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


csiph-web