我正在构建一个python3.8脚本,将googlecloud存储桶中的csv文件加载到googlecloud项目的一个数据集中的给定表中。命令块是:
commandtobq = "bq load --source_format=CSV --skip_leading_rows=1 --field_delimiter=\"^|\" "
commandtobq += " " + gcptrendtable
commandtobq += " " + gsincomingfolder + filetrendoutputname
commandtobq += " \"" + filetrendschema + "\""
print(commandtobq)
os.system(commandtobq)
这将生成以下命令:
bq load --source_format=CSV --skip_leading_rows=1 --field_delimiter="^|" AvgPDHrsAssoc.avgpdhrsassoc_trend_x
gs://thd_tr_incoming/AvgPDHrsAssoc-Retail-Trend-GCP-Output-2019-10-23.csv
"P:\Delivery Team\Execution Reports\Reports-Python\THD-TR-AvgPDHrsAssoc-Retail\SQLs\AvgPDHrsAssoc-Retail-LSR-Extract-v01-Trend-Schema.json"
将此命令复制/粘贴到命令提示窗口中时,它将完美执行。当我使用os.system(commandtobq)
通过python执行它时,它会失败,并出现以下错误:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\..\bin\bootstrapping\bq.py", line 10, in <module>
import os
File "C:\Python38-32\lib\os.py", line 411
yield from walk(new_path, topdown, onerror, followlinks)
^
SyntaxError: invalid syntax
如何解决此错误?请注意,我之前在机器上安装了python2.7和3.6,但是为了新安装3.8,我将这两个版本都删除了。你知道吗
任何想法都会有帮助!谢谢您!你知道吗
添加了以下内容: 我使用Eclipse.3a版本(4.7.3a)作为IDE,以防影响问题或解决方案
有你的程序吗
看起来您是添加
yield from
之前的Python版本,而不是使用yield from
的库的较新版本。你知道吗计算您拥有的
Python*.exe
文件数。你没有使用生活在C:\Python38-32
的那个。你知道吗用于Windows的
google-cloud-sdk
可以选择拥有自己的绑定python2.7。安装3.8可能会导致此Python尝试使用3.8附带的库。你知道吗相关问题 更多 >
编程相关推荐