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
• 15,310 points
34 views

1 answer to this question.

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,160 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
985 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
31 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,060 points
65 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
• 67,120 points
18 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 121 views
+4 votes
6 answers
+1 vote
1 answer

How to create plots using python matplotlib in IPython notebook?

I think you should try: I used %matplotlib inline in ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 56,160 points
102 views
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
43 views