我有一点问题,我想把" dir> " C:\用户\ MYNAME \桌面\ A.TXT"" 进入Txtdokument。但是,如果我运行代码它只是疯狂。
import pandas as pd
import pandas.io.data as web
import datetime
#Grabs tickers from html
exchList = pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies', infer_types=False)
sp500 = []
for ticker in exchList[0][0][1:]:
sp500.append(ticker)
sp500 = [w.replace('.','-') for w in sp500]
#sets date for data fetch
start = datetime.datetime(2000,1,1)
end = datetime.date.today()
#fetches data from yahoo and prints to csv
p = web.DataReader(sp500, "yahoo", start, end)
main_df = p.to_frame()
noIndex = main_df.reset_index()
noIndex.columns.values[1]= 'Name'
indexed = noIndex.set_index('Date')
csv = indexed.to_csv('edata.csv')
我不知道我做错了什么。
答案 0 :(得分:0)
阅读并关注Escape Characters, Delimiters and Quotes文章。使用REM
评论解释:
@echo off
REM ↓ ↓ all in double quotes is taken literally
set "va=dir ^> "c:\users\myname\desktop\a.txt""
REM ↑ the caret escapes > used in following echo
echo.%va%> txt.txt
pause
答案 1 :(得分:0)
我认为这是一种利用延迟扩张的替代方案。
@Echo Off
Set "va=dir > "c:\users\myname\desktop\a.txt""
SetLocal EnableDelayedExpansion
(Echo(!va!)>txt.txt
EndLocal