我一直在尝试将一些列表写入工作簿上的某个工作表,但没有运气。我的代码是:
import xlwings as xw
from xlwings import Range
from xlwings import Book
wkb = xw.Book('Master_v3.xlsm')
sht = wkb.sheets['Control']
sht.Range('A1').value = some_list
Run Code Online (Sandbox Code Playgroud)
这给了我错误:
*** AttributeError: 'Sheet' object has no attribute 'Range'
Run Code Online (Sandbox Code Playgroud)
当我使用“0”而不是指定工作表名称(即“Control”)时,这似乎有效。我这里哪里出错了?
谢谢
我有一个 python 脚本,用于解析 XML 并将某些感兴趣的元素导出到 csv 文件中。我现在尝试更改脚本以允许根据条件过滤 XML 文件,等效的 XPath 查询将是:
\DC\Events\Confirmation[contains(TransactionId,"GTEREVIEW")]
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 lxml 这样做时,我的代码是:
xml_file = lxml.etree.parse(xml_file_path)
namespace = "{" + xml_file.getroot().nsmap[None] + "}"
node_list = xml_file.findall(namespace + "Events/" + namespace + "Confirmation[TransactionId='*GTEREVIEW*']")
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。任何人都可以帮忙吗?XML 文件示例:
<Events>
<Confirmation>
<TransactionId>GTEREVIEW2012</TransactionId>
</Confirmation>
<Confirmation>
<TransactionId>GTEDEF2012</TransactionId>
</Confirmation>
</Events>
Run Code Online (Sandbox Code Playgroud)
所以我想要所有包含交易 ID 的“确认”节点,其中包含字符串“GTEREVIEW”。谢谢
我在我的一个脚本中使用以下检查:
if os.path.exists(FolderPath) == False:
print FolderPath, 'Path does not exist, ending script.'
quit()
if os.path.isfile(os.path.join(FolderPath,GILTS)) == False:
print os.path.join(FolderPath,GILTS), ' file does not exist, ending script.'
quit()
df_gilts = pd.read_csv(os.path.join(FolderPath,GILTS))
Run Code Online (Sandbox Code Playgroud)
足够严格,当路径/文件不存在时,我获得以下打印:
IOError: File G:\On-shoring Project\mCPPI\Reconciliation Tool\Reconciliation Tool Project\3. Python\BootStrap\BBG\2017-07-16\RAW_gilts.csv does not exist
Run Code Online (Sandbox Code Playgroud)
告诉我,即使我添加了一个退出(),它仍继续使用该脚本.谁能告诉我为什么?
谢谢