Python Forum
Merge htm files with shutil library (TypeError: 'module' object is not callable)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Merge htm files with shutil library (TypeError: 'module' object is not callable)
#1
why is my code not working?

import shutil

filenames = shutil('*.htm')  # list of all .htm files in the directory

with open('output_file.htm','wb') as wfd:
    for f in filenames:
        with open(f,'rb') as fd:
            shutil.copyfileobj(fd, wfd)
I get this error:

Error:
Traceback (most recent call last): File "E:\Carte\BB\17 - Site Leadership\alte\Ionel Balauta\Aryeht\Task 1 - Traduce tot site-ul\Doar Google Web\Andreea\Meditatii\Sedinta 31 august 2022\merge txt - versiune 2 .py", line 3, in <module> filenames = shutil('*.htm') # list of all .htm files in the directory TypeError: 'module' object is not callable
Reply
#2
Use
import glob
filenames = glob.glob('*.htm')
Reply
#3
(Aug-28-2022, 07:04 AM)Gribouillis Wrote: Use
import glob
filenames = glob.glob('*.htm')

yes, with globe works. But I still don't understand why does shutil is not working. ?!
Reply
#4
(Aug-28-2022, 07:07 AM)Melcu54 Wrote: But I still don't understand why does shutil is not working. ?!
Because shutil is a module. It is not a function that returns a list of files.
ndc85430 likes this post
Reply
#5
Line 3: why are you trying to call the shutil module as a function?
Reply
#6
(Aug-28-2022, 07:10 AM)ndc85430 Wrote: Line 3: why are you trying to call the shutil module as a function?

ok, now it works. Thanks a lot !

import shutil
import os
import glob

import glob
filenames = glob.glob('*.htm')

with open('output_file.htm','wb') as wfd:
    for f in filenames:
        with open(f,'rb') as fd:
            shutil.copyfileobj(fd, wfd)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 270 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 446 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  use of shutil.copytree with ENOTDIR exception yan 2 841 Nov-29-2023, 03:02 PM
Last Post: yan
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 679 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  merge all xlsb files into csv mg24 0 303 Nov-13-2023, 08:25 AM
Last Post: mg24
  TypeError: 'NoneType' object is not callable akbarza 4 920 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,262 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 777 Jul-23-2023, 02:25 PM
Last Post: Fare
  working with TLV module Object Jennifer_Jone 3 1,075 Mar-14-2023, 07:54 PM
Last Post: Jennifer_Jone
  shutil.move make data corrupt kucingkembar 0 744 Feb-01-2023, 01:30 PM
Last Post: kucingkembar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020