我对python还比较陌生,但我最近遇到了一个bug。在Anaconda Python 3.9(运行Python 3.9.7(上,以下snippit运行良好,并达到预期效果。然而,当我使用Vanilla Python 3.9的任何其他版本时,我会收到错误消息:
(<class'TypeError'>,TypeError("模块"对象不可调用(,<0x000002CBC415B140>处的回溯对象(在每一行上;复制";
这是导致问题的代码:
def callwebCombine(self):
dir_containing_files = self.folder_plaintext
project = self.ProjNameInput_Plaintext
dest_wb = Workbook()
for root, dir, filenames in os.walk(dir_containing_files):
for file in filenames:
print("Combining")
file_name = file.split('.')[0]
# Absolute Path for Excel files
file_path = os.path.abspath(os.path.join(root, file))
# Create new sheet in destination Workbook
dest_wb.create_sheet(file_name)
dest_ws = dest_wb[file_name]
# Read source data
source_wb = load_workbook(file_path, read_only=False)
source_sheet = source_wb.active
row_count = 4
for row in dest_ws.iter_rows(min_row=5, max_row=100, min_col=1, max_col=1):
for cell in row:
if cell.value is not None:
row_count += 1
for row in source_sheet.rows:
for cell in row:
dest_ws[cell.coordinate] = cell.value
dest_ws.sheet_format = copy(source_sheet.sheet_format)
dest_ws.sheet_properties = copy(source_sheet.sheet_properties)
dest_ws.merged_cells = copy(source_sheet.merged_cells)
dest_ws.page_margins = copy(source_sheet.page_margins)
dest_ws.conditional_formatting = copy(source_sheet.conditional_formatting)
for rn in range(len(source_sheet.row_dimensions)):
dest_ws.row_dimensions[rn] = copy(source_sheet.row_dimensions[rn])
哦,我确实有从copy
导入的copy
。将其更改为仅import copy
并没有什么区别。
copy
是一个模块。模块是不可调用的。
例如
import copy
copy() # error
CCD_ 5是该模块的函数。
要导入函数,您需要
from copy import copy
copy() # works