Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:while': 0.07; 'python': 0.08; 'csv': 0.09; 'given,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:Problem': 0.09; 'skip:f 30': 0.13; 'subject:file': 0.13; '"\\n")': 0.16; '"w")': 0.16; '>can': 0.16; 'bieber': 0.16; 'email addr:ix.netcom.com': 0.16; 'email name:wlfraed': 0.16; 'fin.close()': 0.16; 'fout': 0.16; 'fout.close()': 0.16; 'from:addr:ix.netcom.com': 0.16; 'from:addr:wlfraed': 0.16; 'from:name:dennis lee bieber': 0.16; 'message-id:@4ax.com': 0.16; 'received:wlfraed': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'wulfraed': 0.16; 'wrote:': 0.16; 'converted': 0.18; 'this?': 0.19; 'jan': 0.19; 'suggest': 0.20; 'url:home': 0.21; 'received:166': 0.23; 'module': 0.26; 'import': 0.27; 'fix': 0.27; 'lee': 0.28; 'pass': 0.28; 'problem': 0.29; 'print': 0.29; 'seem': 0.29; 'lines': 0.30; '>and': 0.30; 'sun,': 0.30; 'anyone': 0.31; 'to:addr:python-list': 0.33; 'it?': 0.33; 'header:X-Complaints-To:1': 0.34; 'question': 0.35; 'file': 0.35; 'charset:us-ascii': 0.36; 'but': 0.37; 'received:org': 0.37; 'subject:with': 0.38; 'open': 0.38; 'clearly': 0.39; 'why': 0.39; 'doing': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'data': 0.40; 'collect': 0.61; 'you.': 0.64; 'ali': 0.67; 'dennis': 0.73; 'hand,': 0.76; "'f',": 0.84; '-0800': 0.84; 'phenomenon': 0.84; 'saqib': 0.84; 'spaces.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Problem while doing a cat on a tabbed file with pexpect Date: Sun, 15 Jan 2012 14:24:41 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: mobile-166-147-101-093.mycingular.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326655502 news.xs4all.nl 6943 [2001:888:2000:d::a6]:58993 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19015 On Sun, 15 Jan 2012 09:51:44 -0800 (PST), Saqib Ali wrote: >Now, clearly the file contains tabs. But when I cat it through expect, >and collect cat's output, those tabs have been converted to spaces. >But I need the tabs! > >Can anyone explain this phenomenon or suggest how I can fix it? My question is: WHY are you doing this? Based upon the problem discription, as given, the solution would seem to be to just open the file IN Python -- whether you read the lines and use split() by hand, or pass the open file to the csv module for reading/parsing is up to you. -=-=-=-=-=-=- import csv import os TESTFILE = "Test.tsv" #create data file fout = open(TESTFILE, "w") for ln in [ "abc", "defg", "hijA" ]: fout.write("\t".join(list(ln)) + "\n") fout.close() #process tab-separated data fin = open(TESTFILE, "rb") rdr = csv.reader(fin, dialect="excel-tab") for rw in rdr: print rw fin.close() del rdr os.remove(TESTFILE) -=-=-=-=-=-=- ['a', 'b', 'c'] ['d', 'e', 'f', 'g'] ['h', 'i', 'j', 'A'] -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/