How to import other Python files?

0 votes

How do I import other files in Python?

  1. How exactly can I import a specific python file like import file.py?

  2. How can I import a folder instead of a specific file?

  3. I want to load a Python file dynamically at runtime, based on user input.

  4. I want to know how to load just one specific part from the file.

Jul 27, 2018 in Python by bug_seeker
• 14,970 points
27 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

importlib is recent addition in Python to programmatically import a module. 

It just a wrapper around __import__ 

See 

https://docs.python.org/3/library/importlib.html#module-importlib

import importlib moduleName = input('Enter module name:') importlib.import_module(moduleName)

answered Jul 27, 2018 by Priyaj
• 56,120 points

Related Questions In Python

+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,700 points
526 views
0 votes
0 answers

How to mix read() and write() on Python files in Windows

It appears that a write() immediately following a read() on a ...READ MORE

Oct 23, 2018 in Python by Aryya
• 500 points
23 views
0 votes
0 answers

How to read lines from compressed text files in Python

Is it easy to read a line ...READ MORE

Dec 27, 2018 in Python by Anirudh
• 2,050 points
54 views
0 votes
1 answer

How to list files/directories in python

You can use the os module to list the ...READ MORE

answered Feb 3 in Python by Omkar
• 65,850 points
11 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
27 views
+4 votes
6 answers
+1 vote
1 answer
0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8 in Python by rajesh
• 1,210 points
35 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.