Problem while doing a cat on a tabbed file with pexpect
Cameron Simpson
cs at zip.com.au
Sun Jan 15 18:40:08 EST 2012
On 15Jan2012 23:04, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
| On Sun, 15 Jan 2012 09:51:44 -0800, Saqib Ali wrote:
| > I am using Solaris 10, python 2.6.2, pexpect 2.4
| >
| > I create a file called me.txt which contains the letters "A", "B", "C"
| > on the same line separated by tabs.
| [...]
| > Now, clearly the file contains tabs.
|
| That is not clear at all. How do you know it contains tabs? How was the
| file created in the first place?
|
| Try this:
|
| text = open('me.txt', 'r').read()
| print '\t' in text
|
| My guess is that it will print False and that the file does not contain
| tabs. Check your editor used to create the file.
I was going to post an alternative theory but on more thought I think
Steven is right here.
What does:
od -c me.txt
show you? TABs or multiple spaces?
What does:
ls -ld me.txt
tell you about the file size? Is it 6 bytes long (three letters, two
TABs, one newline)?
Steven hasn't been explicit about it, but some editors will write spaces when
you type a TAB. I have configured mine to do so - it makes indentation more
reliable for others. If I really need a TAB character I have a special
finger contortion to get one, but the actual need is rare.
So first check that the file really does contain TABs.
Cheers,
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
Yes Officer, yes Officer, I will Officer. Thank you.
More information about the Python-list
mailing list