- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 python 的 openpyxl 加载 xlsm 文件,然后在将一些数据添加到特定工作表中的特定 7 个单元格后保存/关闭它时,我收到警告。问题是我收到了一个“FutureWarning”,我不知道它是什么。我已经搜索这个有一段时间了,但一直无法破译。
我怀疑 wb.save() 方法是触发此警告的原因,因为当我评论此特定行时它没有显示。
有人知道这是什么吗?
代码
wb = openpyxl.load_workbook(filename=directory_path.xlsm, keep_vba=True)
ws = wb['sheetname']
ws.cell(row1, col1).value = ### (some number)
ws.cell(row2, col2).value = ### (some number)
ws.cell(row3, col3).value = ### (some number)
ws.cell(row4, col4).value = ### (some number)
ws.cell(row5, col5).value = ### (some number)
ws.cell(row6, col6).value = ### (some number)
ws.cell(row7, col7).value = ### (some number)
wb.save(directory_path.xlsm)
wb.close()
警告消息
C:\Users\...\Anaconda3\lib\site-packages\openpyxl\comments\shape_writer.py:75: FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
if not shape_types:
最佳答案
Openpyxl
似乎使用的是旧版本的 lxml
。这是您的 lxml
版本中的警告。
shape_writer
的第 73-76 行源代码为:
# check whether comments shape type already exists
shape_types = root.find("{%s}shapetype[@id='_x0000_t202']" % vmlns)
if not shape_types:
self.add_comment_shapetype(root)
问题在于如果不是shape_types:
。 root.find()
是对 lxml
的调用。 documentation for lxml
说:
Prior to ElementTree 1.3 and lxml 2.0, you could also check the truth value of an Element to see if it has children, i.e. if the list of children is empty:
if root: # this no longer works!
print("The root element has children")
This is no longer supported as people tend to expect that a "something" evaluates to True and expect Elements to be "something", may they have children or not. So, many users find it surprising that any Element would evaluate to False in an if-statement like the above. Instead, use len(element), which is both more explicit and less error prone.
关于python - openpyxl - FutureWarning : The behavior of this method will change in future versions. 使用特定的 'len(elem)' 或 'elem is not None' 测试代替,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51645361/
我是一名优秀的程序员,十分优秀!