خرید بک لینک

Vote count: 0

I am dealing with a problem where I want to extract stock names from a text file to use in multiple python scripts, so that if I add one or more stocks I dont have to alter all the python files.

My stocks.txt file is:

AAPL
GOOG
TSLA

If I import this the script saves A.txt, A.txt, P.txt, L.txt, G.txt etc.

It takes every letter as seperate. How can I change my code so that it takes AAPL, GOOG and TSLA?

Thank you!

My reduced script:

import urllib2
import time
import datetime
import os

filePath = os.path.abspath('stocks.txt')
openFile = open(filePath, 'r')
stockToPull = str(openFile.read())

def pullData(stock):
    try:
        saveFileLine = "today_data\" +stock+".txt"

    except Exception, e:
        print 'main loop', str(e)

while True:
    for eachStock in stockToPull:
        pullData(eachStock)

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 26 فروردين 1395 ساعت: 3:34

صفحه بندی