What about Perl's require statement in Python?

Asked 2 years ago, Updated 2 years ago, 75 views

Hi, I've been studying Perl for about five years, and I've decided to start studying Python. I'm a beginner.
I'm currently thinking of creating a web application in Python, but Perl was able to load a library called foo.cgi in the same directory by writing it like require"foo.cgi". Is there anything else in Python other than import?

Note: I wondered if Python had a function of loading that would be evaluated when running a script, not when compiling.

python perl

2022-09-29 20:25

1 Answers

Does python have something like require for use in perl?
They want to import it from the file path instead of the package name at runtime.

import imp
your_module=imp.load_source('your_module','./path/to/your_module.py')

your_module.your_function()
importimportlib.util
spec=importlib.util.spec_from_file_location('your_module','./path/to/your_module.py')
your_module=importlib.util.module_from_spec(spec)
spec.loader.exec_module(your_module)

your_module.your_function()

It's a little hard to think about the scene where the cgi file in the questionnaire is required as a library.
I think it's a .pl file, not a .cgi.


2022-09-29 20:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.