Python Forum
Handling exception from a module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling exception from a module
#11
Thank you for your continued assistance. I see now that the whole issue is due to me stupidly editing the module. I commented out a section of the run() function in pdftitle.py as I could not otherwise work out how to pass a file name to it.

This was on a previous night while I was somewhat intoxicated...

Now however, if I go to the original pdftitle.py, I cannot determine how to pass the argument correctly?

PdfTitle = pdftitle.run(pdf=FilePath)
def run():
    try:
        parser = argparse.ArgumentParser(
            prog='pdftitle',
            description='Extracts the title of a PDF article',
            epilog='')
        parser.add_argument('-p', '--pdf',
                            help='pdf file', required=True)
        parser.add_argument('--replace-missing-char',
                            help='replace missing char with the one specified')
        parser.add_argument('-v', '--verbose',
                            action='store_true',
                            help='enable verbose logging')
        args = parser.parse_args()
        global VERBOSE, MISSING_CHAR
        VERBOSE = args.verbose
        MISSING_CHAR = args.replace_missing_char
        title = get_title_from_file(args.pdf)
        if title is None:
            return 1
        else:
            print(title)
            return 0
    except Exception as e:
        if VERBOSE:
            traceback.print_exc()
        return 1


if __name__ == '__main__':
    sys.exit(run())
Error:
Traceback (most recent call last): File "rename_post.py", line 40, in <module> pdf_recurse(args.path) File "rename_post.py", line 19, in pdf_recurse PdfTitle = pdftitle.run(pdf=FilePath) TypeError: run() got an unexpected keyword argument 'pdf'
Very sorry for the false path.
Reply


Messages In This Thread
Handling exception from a module - by dchi2 - Nov-23-2019, 09:18 AM
RE: Handling exception from a module - by Larz60+ - Nov-23-2019, 09:23 AM
RE: Handling exception from a module - by dchi2 - Nov-23-2019, 10:51 PM
RE: Handling exception from a module - by Larz60+ - Nov-23-2019, 11:12 PM
RE: Handling exception from a module - by dchi2 - Nov-23-2019, 11:35 PM
RE: Handling exception from a module - by Larz60+ - Nov-23-2019, 11:50 PM
RE: Handling exception from a module - by dchi2 - Nov-23-2019, 11:58 PM
RE: Handling exception from a module - by Larz60+ - Nov-24-2019, 03:32 AM
RE: Handling exception from a module - by dchi2 - Nov-24-2019, 05:23 AM
RE: Handling exception from a module - by Larz60+ - Nov-24-2019, 08:31 AM
RE: Handling exception from a module - by dchi2 - Nov-24-2019, 09:40 AM
RE: Handling exception from a module - by dchi2 - Nov-25-2019, 08:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,289 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  TicTacToe Game Add Exception Handling and Warning Function ShaikhShaikh 5 2,433 Nov-03-2021, 05:02 PM
Last Post: deanhystad
  Error handling using cmd module leifeng 3 2,905 Jun-06-2020, 06:25 PM
Last Post: leifeng
  Exception handling in regex using python ShruthiLS 1 2,374 May-04-2020, 08:12 AM
Last Post: anbu23
  Exception handling Calli 2 2,477 Apr-20-2020, 06:13 PM
Last Post: Calli
  problem using custom exception handling in python srm 3 3,076 Jul-03-2019, 09:10 PM
Last Post: ichabod801
  an easy way to disable exception handling Skaperen 6 5,481 Jun-02-2019, 10:38 PM
Last Post: Gribouillis
  exception handling KyawMyo 3 2,871 May-07-2019, 07:53 AM
Last Post: buran
  Database operation exception handling LostInCode 1 2,499 Jan-03-2019, 07:50 PM
Last Post: jeanMichelBain
  During handling of the above exception, another exception occurred Skaperen 7 26,933 Dec-21-2018, 10:58 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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