Request for py program to insert space between two characters and saved as text?

r0g aioe.org at technicalbloke.com
Wed Dec 9 02:11:56 EST 2009


Dave Angel wrote:
> r0g wrote:
>> Dave Angel wrote:
>>  
>>> r0g wrote:
>>>    
>>>> Dennis Lee Bieber wrote:
>>>>  
>>>>      
>>>>> On Tue, 8 Dec 2009 08:26:58 +0530, 74yrs old <withblessings at gmail.com>
>>>>> declaimed the following in gmane.comp.python.general:
>>>>>
>>>>>           
>>>>>> For Kannada project .txt(not .doc) is used, my requirement is to
>>>>>> have one
>>>>>>                 
>>>> <snip>
>>>>  
>>>>      
>>>>>> In this context, I request you kindly for small python program - to
>>>>>> make or
>>>>>>                 
>>>>>     Excuse me -- you want one of US to supply you with a program that
>>>>> will be used for YOUR entry to some job site? (At least, that's what I
>>>>> seem to be finding for "Kannada project")
>>>>>
>>>>>             
>>>> Well it is only a 2 line program and he did ask nicely after all, if
>>>> you
>>>> begrudge him it then feel free to not answer, righteous indignation
>>>> rarely helps anyone.
>>>>
>>>> Dear OP...
>>>>
>>>> Put the following 2 lines into a file and save it as spacer.py
>>>>
>>>> import sys
>>>> print ' '.join([e for e in open(sys.argv[1], 'r').read()])
>>>>
>>>>
>>>> Then open a terminal window and 'cd' to the same folder you just saved
>>>> the spacer.py file in. Type...
>>>>
>>>> python spacer.py inputfile.txt > outputfile.txt
>>>>
>>>> This will run inputfile.txt through the space adding program we have
>>>> just saved and then 'pipe' the output of that into a new file
>>>> outputfile.txt
>>>>
>>>> Hope this helps,
>>>>
>>>>
>>>> Roger Heathcote.
>>>>
>>>>         
>>> That seems a bit dangerous to give to a beginner at Python, without
>>> discussing Unicode issues.  If he's in Python 3.x, and if the default
>>> encoder is ASCII, which it seems to be most places, then he'll quickly
>>> get a conversion error for some character.  And if it's some other 8 bit
>>> form, he might not get an error,  but find that a space is inserted
>>> between two of the bytes of a UTF-8 code.
>>>
>>> DaveA
>>>
>>>     
>>
>>
>>
>> He said he's running the latest python and fedora, AFAIK the default for
>> these systems is still the 2 series, not 3.
>>
>>
>> Roger.
>>
>>   
> That's even worse.  As far as I can tell, the code will never do what he
> wants in Python 2.x.   The Kannada text file is full of Unicode
> characters in some encoding, and if you ignore the encoding, you'll just
> get garbage.
> 
> 

Ah, fair enough. In my defence though I never saw the original post or
this kannada.txt file as my newsserver is not so much with the
reliability. I guess it's naive to assume an english .txt file is going
to be in ASCII these days eh?

I've yet to try python 3 yet either, this whole Unicode thing looks like
it could be a total nightmare! :(

Roger.



More information about the Python-list mailing list