Loading ...

写文件到研究环境

Author: 张超, Created: 2020-03-16 10:30:42, Updated: 2020-03-16 10:50:41

  1. 研究环境里不能连接外网,导致需要的csv的时候,没有办法上传文件到docker里,这里给出一个思路,利用python来写文件,把csv转成py代码来运行,再写到研究环境
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import binascii

filename = 'chart.csv'
with open(filename, 'rb') as f:
    content = f.read()
#csv转py
wFile = open(filename.split('.')[0] + '_hex.py', "w")
wFile.write("hexstr = bytearray.fromhex('" +
            bytes.decode(binascii.hexlify(content))
            + "').decode()\nwFile = open('" + filename + "', 'w')\nwFile.write(hexstr)\nwFile.close()")
wFile.close()
  1. 把转换后的py文件,放到研究环境运行
hexstr = bytearray.fromhex('efbbbf224461746554696d65222c22e6b5aee58aa8e79b88e4ba8f222c22e4ba8be4bbb6220a22323031382d30352d33312030303a30303a3030222c300a22323031382d30362d30312030303a30303a3030222c300a22323031382d30362d30322030303a30303a3030222c300a22323031382d30362d30332030303a30303a3030222c300a22323031382d30362d30342030303a30303a3030222c300a22323031382d30362d30352030303a30303a3030222c300a22323031382d30362d30362030303a30303a3030222c300a22323031382d30362d30372030303a30303a3030222c300a22323031382d30362d30382030303a30303a3030222c300a22323031382d30362d30392030303a30303a3030222c300a22323031382d30362d31302030303a30303a3030222c300a22323031382d30362d31312030303a30303a3030222c300a22323031382d30362d31322030303a30303a3030222c300a22323031382d30362d31332030303a30303a3030222c300a22323031382d30362d31342030303a30303a3030222c300a22323031382d30362d31352030303a30303a3030222c300a22323031382d30362d31362030303a30303a3030222c300a22323031382d30362d31372030303a30303a3030222c300a22323031382d30362d31382030303a30303a3030222c300a22323031382d30362d31392030303a30303a3030222c300a22323031382d30362d32302030303a30303a3030222c300a22323031382d30362d32312030303a30303a3030222c300a22323031382d30362d32322030303a30303a3030222c300a22323031382d30362d32332030303a30303a3030222c300a22323031382d30362d32342030303a30303a3030222c300a22323031382d30362d32352030303a30303a3030222c300a22323031382d30362d32362030303a30303a3030222c3131300a22323031382d30362d32372030303a30303a3030222c2d343430300a22323031382d30362d32382030303a30303a3030222c2d393638300a22323031382d30362d32392030303a30303a3030222c2d393638300a22323031382d30362d33302030303a30303a3030222c2d393638300a22323031382d30372d30312030303a30303a3030222c2d393638300a22323031382d30372d30322030303a30303a3030222c2d393638300a22323031382d30372d30332030303a30303a3030222c2d31323837300a22323031382d30372d30342030303a30303a3030222c2d31333937300a22323031382d30372d30352030303a30303a3030222c2d393838300a22323031382d30372d30362030303a30303a3030222c2d353035300a22323031382d30372d30372030303a30303a3030222c2d343334300a22323031382d30372d30382030303a30303a3030222c2d343334300a22323031382d30372d30392030303a30303a3030222c2d343334300a22323031382d30372d31302030303a30303a3030222c2d373232300a22323031382d30372d31312030303a30303a3030222c313130300a22323031382d30372d31322030303a30303a3030222c2d333036300a22323031382d30372d31332030303a30303a3030222c2d323432300a22323031382d30372d31342030303a30303a3030222c2d383138300a22323031382d30372d31352030303a30303a3030222c2d383138300a22323031382d30372d31362030303a30303a3030222c2d383138300a22323031382d30372d31372030303a30303a3030222c2d31343538300a22323031382d30372d31382030303a30303a3030222c2d31353534300a22323031382d30372d31392030303a30303a3030222c2d313738300a22323031382d30372d32302030303a30303a3030222c2d393134300a22323031382d30372d32312030303a30303a3030222c343330300a22323031382d30372d32322030303a30303a3030222c343330300a22323031382d30372d32332030303a30303a3030222c343330300a22323031382d30372d32342030303a30303a3030222c31373136300a22323031382d30372d32352030303a30303a3030222c31363339300a22323031382d30372d32362030303a30303a3030222c2d31303037300a22323031382d30372d32372030303a30303a3030222c3139300a22323031382d30372d32382030303a30303a3030222c333937300a22323031382d30372d32392030303a30303a3030222c333937300a22323031382d30372d33302030303a30303a3030222c333937300a22323031382d30372d33312030303a30303a3030222c32353033300a22323031382d30382d30312030303a30303a3030222c32363131300a22323031382d30382d30322030303a30303a3030222c31353835300a22323031382d30382d30332030303a30303a3030222c35363839300a22323031382d30382d30342030303a30303a3030222c3138393733300a22323031382d30382d30352030303a30303a3030222c3138393733300a22323031382d30382d30362030303a30303a3030222c3138393733300a22323031382d30382d30372030303a30303a3030222c3135363235300a22323031382d30382d30382030303a30303a3030222c3133313431300a22323031382d30382d30392030303a30303a3030222c3133333033300a22323031382d30382d31302030303a30303a3030222c3133303333300a22323031382d30382d31312030303a30303a3030222c3130313137300a22323031382d30382d31322030303a30303a3030222c3130313137300a22323031382d30382d31332030303a30303a3030222c3130313137300a22323031382d30382d31342030303a30303a3030222c3138353935300a22323031382d30382d31352030303a30303a3030222c3135393439300a22323031382d30382d31362030303a30303a3030222c3131373931300a22323031382d30382d31372030303a30303a3030222c3132313135300a22323031382d30382d31382030303a30303a3030222c3130333837300a22323031382d30382d31392030303a30303a3030222c3130333837300a22323031382d30382d32302030303a30303a3030222c3130333837300a22323031382d30382d32312030303a30303a3030222c3136393231300a22323031382d30382d32322030303a30303a3030222c3136373539300a22323031382d30382d32332030303a30303a3030222c3138343333300a22323031382d30382d32342030303a30303a3030222c3133363237300a22323031382d30382d32352030303a30303a3030222c3132333835300a22323031382d30382d32362030303a30303a3030222c3132333835300a22323031382d30382d32372030303a30303a3030222c3132333835300a22323031382d30382d32382030303a30303a3030222c3135353137300a22323031382d30382d32392030303a30303a3030222c3132323737300a22323031382d30382d33302030303a30303a3030222c3131373337300a22323031382d30382d33312030303a30303a3030222c3132303631300a22323031382d30392d30312030303a30303a3030222c3130363033300a22323031382d30392d30322030303a30303a3030222c3130363033300a22323031382d30392d30332030303a30303a3030222c3130363033300a22323031382d30392d30342030303a30303a3030222c37373935300a22323031382d30392d30352030303a30303a3030222c37373935300a22323031382d30392d30362030303a30303a3030222c37373935300a22323031382d30392d30372030303a30303a3030222c37373935300a22323031382d30392d30382030303a30303a3030222c37373935300a22323031382d30392d30392030303a30303a3030222c37373935300a22323031382d30392d31302030303a30303a3030222c37373935300a22323031382d30392d31312030303a30303a3030222c37373935300a22323031382d30392d31322030303a30303a3030222c37373935300a22323031382d30392d31332030303a30303a3030222c37373935300a22323031382d30392d31342030303a30303a3030222c37373935300a22323031382d30392d31352030303a30303a3030222c37373935300a22323031382d30392d31362030303a30303a3030222c37373935300a22323031382d30392d31372030303a30303a3030222c37373935300a22323031382d30392d31382030303a30303a3030222c37373935300a22323031382d30392d31392030303a30303a3030222c37373935300a22323031382d30392d32302030303a30303a3030222c37373935300a22323031382d30392d32312030303a30303a3030222c37373935300a22323031382d30392d32322030303a30303a3030222c37373935300a22323031382d30392d32332030303a30303a3030222c37373935300a22323031382d30392d32342030303a30303a3030222c37373935300a22323031382d30392d32352030303a30303a3030222c37373935300a22323031382d30392d32362030303a30303a3030222c37373935300a22323031382d30392d32372030303a30303a3030222c37373935300a22323031382d30392d32382030303a30303a3030222c37373935300a22323031382d30392d32392030303a30303a3030222c37373935300a22323031382d30392d33302030303a30303a3030222c37373935300a22323031382d31302d30312030303a30303a3030222c37373935300a22323031382d31302d30322030303a30303a3030222c37373935300a22323031382d31302d30332030303a30303a3030222c37373935300a22323031382d31302d30342030303a30303a3030222c37373935300a22323031382d31302d30352030303a30303a3030222c37373935300a22323031382d31302d30362030303a30303a3030222c37373935300a22323031382d31302d30372030303a30303a3030222c37373935300a22323031382d31302d30382030303a30303a3030222c37373935300a22323031382d31302d30392030303a30303a3030222c37373935300a22323031382d31302d31302030303a30303a3030222c37373935300a22323031382d31302d31312030303a30303a3030222c37373935300a22323031382d31302d31322030303a30303a3030222c37373935300a22323031382d31302d31332030303a30303a3030222c37373935300a22323031382d31302d31342030303a30303a3030222c37373935300a22323031382d31302d31352030303a30303a3030222c37373935300a22323031382d31302d31362030303a30303a3030222c37303339300a22323031382d31302d31372030303a30303a3030222c36363236302c36363236300a22323031382d31302d31382030303a30303a3030222c36363236300a22323031382d31302d31392030303a30303a3030222c36363236300a22323031382d31302d32302030303a30303a3030222c36363236300a22323031382d31302d32312030303a30303a3030222c36363236300a22323031382d31302d32322030303a30303a3030222c36363236300a22323031382d31302d32332030303a30303a3030222c36363236300a22323031382d31302d32342030303a30303a3030222c36363236300a22323031382d31302d32352030303a30303a3030222c36363236300a22323031382d31302d32362030303a30303a3030222c36363236300a22323031382d31302d32372030303a30303a3030222c36363236300a22323031382d31302d32382030303a30303a3030222c36363236300a22323031382d31302d32392030303a30303a3030222c36363236300a22323031382d31302d33302030303a30303a3030222c37323335300a22323031382d31302d33312030303a30303a3030222c38353538300a22323031382d31312d30312030303a30303a3030222c39303036300a22323031382d31312d30322030303a30303a3030222c3131303738300a22323031382d31312d30332030303a30303a3030222c39393836300a22323031382d31312d30342030303a30303a3030222c39393836300a22323031382d31312d30352030303a30303a3030222c39393836300a22323031382d31312d30362030303a30303a3030222c39343534300a22323031382d31312d30372030303a30303a3030222c3132303538300a22323031382d31312d30382030303a30303a3030222c3133363534300a22323031382d31312d30392030303a30303a3030222c3133333534300a22323031382d31312d31302030303a30303a3030222c3132373432300a22323031382d31312d31312030303a30303a3030222c3132373432300a22323031382d31312d31322030303a30303a3030222c3132373432300a22323031382d31312d31332030303a30303a3030222c3135303130300a22323031382d31312d31342030303a30303a3030222c3136323334300a22323031382d31312d31352030303a30303a3030222c3137333134300a22323031382d31312d31362030303a30303a3030222c3137303632300a22323031382d31312d31372030303a30303a3030222c3136333036300a22323031382d31312d31382030303a30303a3030222c3136333036300a22323031382d31312d31392030303a30303a3030222c3136333036300a22323031382d31312d32302030303a30303a3030222c3138353338300a22323031382d31312d32312030303a30303a3030222c3233353432302c323335343230').decode()
wFile = open('chart.csv', 'w')
wFile.write(hexstr)
wFile.close()
!ls -la
总用量 28
drwxr-xr-x 1 quant quant   92 3月  16 02:19 .
drwxr-xr-x 1 root  root    19 10月  9 10:18 ..
-rw-r--r-- 1 quant quant  220 4月   4  2018 .bash_logout
-rw-r--r-- 1 quant quant 3771 4月   4  2018 .bashrc
-rw-r--r-- 1 quant quant 4887 3月  16 02:19 chart.csv
-rw-r--r-- 1 quant quant 4887 3月  16 02:17 dechart_hex.csv
drwxr-xr-x 5 quant quant   67 3月  16 02:16 .ipython
drwxr-xr-x 1 quant quant   40 3月  16 02:16 .jupyter
drwx------ 3 quant quant   19 3月  16 02:16 .local
drwxr-xr-x 2 quant quant   22 10月 12 16:34 .pip
-rw-r--r-- 1 quant quant  807 4月   4  2018 .profile
cat dechart_hex.csv
"DateTime","浮动盈亏","事件"
"2018-05-31 00:00:00",0
"2018-06-01 00:00:00",0
"2018-06-02 00:00:00",0
"2018-06-03 00:00:00",0
"2018-06-04 00:00:00",0
"2018-06-05 00:00:00",0
"2018-06-06 00:00:00",0
"2018-06-07 00:00:00",0
"2018-06-08 00:00:00",0
"2018-06-09 00:00:00",0
"2018-06-10 00:00:00",0
"2018-06-11 00:00:00",0
"2018-06-12 00:00:00",0
"2018-06-13 00:00:00",0
"2018-06-14 00:00:00",0
"2018-06-15 00:00:00",0
"2018-06-16 00:00:00",0
"2018-06-17 00:00:00",0
"2018-06-18 00:00:00",0
"2018-06-19 00:00:00",0
"2018-06-20 00:00:00",0
"2018-06-21 00:00:00",0
"2018-06-22 00:00:00",0
"2018-06-23 00:00:00",0
"2018-06-24 00:00:00",0
"2018-06-25 00:00:00",0
"2018-06-26 00:00:00",110
"2018-06-27 00:00:00",-4400
"2018-06-28 00:00:00",-9680
"2018-06-29 00:00:00",-9680
"2018-06-30 00:00:00",-9680
"2018-07-01 00:00:00",-9680
"2018-07-02 00:00:00",-9680
"2018-07-03 00:00:00",-12870
"2018-07-04 00:00:00",-13970
"2018-07-05 00:00:00",-9880
"2018-07-06 00:00:00",-5050
"2018-07-07 00:00:00",-4340
"2018-07-08 00:00:00",-4340
"2018-07-09 00:00:00",-4340
"2018-07-10 00:00:00",-7220
"2018-07-11 00:00:00",1100
"2018-07-12 00:00:00",-3060
"2018-07-13 00:00:00",-2420
"2018-07-14 00:00:00",-8180
"2018-07-15 00:00:00",-8180
"2018-07-16 00:00:00",-8180
"2018-07-17 00:00:00",-14580
"2018-07-18 00:00:00",-15540
"2018-07-19 00:00:00",-1780
"2018-07-20 00:00:00",-9140
"2018-07-21 00:00:00",4300
"2018-07-22 00:00:00",4300
"2018-07-23 00:00:00",4300
"2018-07-24 00:00:00",17160
"2018-07-25 00:00:00",16390
"2018-07-26 00:00:00",-10070
"2018-07-27 00:00:00",190
"2018-07-28 00:00:00",3970
"2018-07-29 00:00:00",3970
"2018-07-30 00:00:00",3970
"2018-07-31 00:00:00",25030
"2018-08-01 00:00:00",26110
"2018-08-02 00:00:00",15850
"2018-08-03 00:00:00",56890
"2018-08-04 00:00:00",189730
"2018-08-05 00:00:00",189730
"2018-08-06 00:00:00",189730
"2018-08-07 00:00:00",156250
"2018-08-08 00:00:00",131410
"2018-08-09 00:00:00",133030
"2018-08-10 00:00:00",130330
"2018-08-11 00:00:00",101170
"2018-08-12 00:00:00",101170
"2018-08-13 00:00:00",101170
"2018-08-14 00:00:00",185950
"2018-08-15 00:00:00",159490
"2018-08-16 00:00:00",117910
"2018-08-17 00:00:00",121150
"2018-08-18 00:00:00",103870
"2018-08-19 00:00:00",103870
"2018-08-20 00:00:00",103870
"2018-08-21 00:00:00",169210
"2018-08-22 00:00:00",167590
"2018-08-23 00:00:00",184330
"2018-08-24 00:00:00",136270
"2018-08-25 00:00:00",123850
"2018-08-26 00:00:00",123850
"2018-08-27 00:00:00",123850
"2018-08-28 00:00:00",155170
"2018-08-29 00:00:00",122770
"2018-08-30 00:00:00",117370
"2018-08-31 00:00:00",120610
"2018-09-01 00:00:00",106030
"2018-09-02 00:00:00",106030
"2018-09-03 00:00:00",106030
"2018-09-04 00:00:00",77950
"2018-09-05 00:00:00",77950
"2018-09-06 00:00:00",77950
"2018-09-07 00:00:00",77950
"2018-09-08 00:00:00",77950
"2018-09-09 00:00:00",77950
"2018-09-10 00:00:00",77950
"2018-09-11 00:00:00",77950
"2018-09-12 00:00:00",77950
"2018-09-13 00:00:00",77950
"2018-09-14 00:00:00",77950
"2018-09-15 00:00:00",77950
"2018-09-16 00:00:00",77950
"2018-09-17 00:00:00",77950
"2018-09-18 00:00:00",77950
"2018-09-19 00:00:00",77950
"2018-09-20 00:00:00",77950
"2018-09-21 00:00:00",77950
"2018-09-22 00:00:00",77950
"2018-09-23 00:00:00",77950
"2018-09-24 00:00:00",77950
"2018-09-25 00:00:00",77950
"2018-09-26 00:00:00",77950
"2018-09-27 00:00:00",77950
"2018-09-28 00:00:00",77950
"2018-09-29 00:00:00",77950
"2018-09-30 00:00:00",77950
"2018-10-01 00:00:00",77950
"2018-10-02 00:00:00",77950
"2018-10-03 00:00:00",77950
"2018-10-04 00:00:00",77950
"2018-10-05 00:00:00",77950
"2018-10-06 00:00:00",77950
"2018-10-07 00:00:00",77950
"2018-10-08 00:00:00",77950
"2018-10-09 00:00:00",77950
"2018-10-10 00:00:00",77950
"2018-10-11 00:00:00",77950
"2018-10-12 00:00:00",77950
"2018-10-13 00:00:00",77950
"2018-10-14 00:00:00",77950
"2018-10-15 00:00:00",77950
"2018-10-16 00:00:00",70390
"2018-10-17 00:00:00",66260,66260
"2018-10-18 00:00:00",66260
"2018-10-19 00:00:00",66260
"2018-10-20 00:00:00",66260
"2018-10-21 00:00:00",66260
"2018-10-22 00:00:00",66260
"2018-10-23 00:00:00",66260
"2018-10-24 00:00:00",66260
"2018-10-25 00:00:00",66260
"2018-10-26 00:00:00",66260
"2018-10-27 00:00:00",66260
"2018-10-28 00:00:00",66260
"2018-10-29 00:00:00",66260
"2018-10-30 00:00:00",72350
"2018-10-31 00:00:00",85580
"2018-11-01 00:00:00",90060
"2018-11-02 00:00:00",110780
"2018-11-03 00:00:00",99860
"2018-11-04 00:00:00",99860
"2018-11-05 00:00:00",99860
"2018-11-06 00:00:00",94540
"2018-11-07 00:00:00",120580
"2018-11-08 00:00:00",136540
"2018-11-09 00:00:00",133540
"2018-11-10 00:00:00",127420
"2018-11-11 00:00:00",127420
"2018-11-12 00:00:00",127420
"2018-11-13 00:00:00",150100
"2018-11-14 00:00:00",162340
"2018-11-15 00:00:00",173140
"2018-11-16 00:00:00",170620
"2018-11-17 00:00:00",163060
"2018-11-18 00:00:00",163060
"2018-11-19 00:00:00",163060
"2018-11-20 00:00:00",185380
"2018-11-21 00:00:00",235420,235420
  1. 还有个思路就是用echo来写,换行可以用\n来替换,双引号加转换符
!echo "\"aaaa\"\nbbbb" >chart.txt
!cat chart.txt
"aaaa"
bbbb


More

小草 可以上传到论坛,让后可以下载到notebook