Python-Create array from txt
<p>I'm trying to create an array of stock tickers in Python 2.7 from a txt file. The txt file simply has 1 ticker per line like:</p>

<pre><code>SRCE
ABTX
AMBC
ATAX
</code></pre>

<p>The code I'm using looks like:</p>

<pre><code>FinTick= []

    def parseRus():
        try:
        readFile=open(r'filename.txt','r').read()
        splitFile=readFile.split('\n')
        FinTick.append(splitFile)
        print FinTick



        except Exception, e:
        print str(e)
</code></pre>

<p>When I call 'parseRus()' I get an output that looks like:</p>

<pre><code>'\xff\xfeS\x00R\x00C\x00E\x00\r\x00', '\x00A\x00B\x00T\x00X\x00\r\x00', '\x00A\x00M\x00B\x00C\x00\r\x00', '\x00A\x00T\x00A\x00X\x00\r\x00'
</code></pre>

<p>The correct letters are present but not printing in plane text. I've used a couple other logic methods to populate the array but still get the same output format.</p>

<p>I finally figured a fix.</p>

<p>I had to modify the text file from 1 column to 1 row then saved as a .csv and modified the code to:</p>

<pre><code>FinTick= []

def parseRus():
    try:
        readFile=open(r'filename.csv','r').read()
        splitFile=readFile.split(',')
        for eachLine in splitFile:
            splitLine=eachLine.split(',')
            ticker=splitLine[0]
            FinTick.append(ticker.strip())



    except Exception, e:
    print str(e)
</code></pre>

python arrays python-2.7