Python Forum
importing same python library in multiple custom module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
importing same python library in multiple custom module
#1
Hi All,

Scenario 01:

module:

import time


def printtime():
    print(time.time())
master program:

import module


module.printtime()

print(list(module.time.gmtime()))
Output will be:
Output:
1589049932.1866198 [2020, 5, 9, 19, 7, 41, 5, 130, 0]
Scenario 02:

module:

def printtime():
    print(time.time())
master program:

import time

import module


module.printtime()
Output will be:
Output:
NameError: name 'time' is not defined
I can import library in module and use it in master program but importing library in master program and use it in module functions won't work. I want to import python library in my master script and use it in python module functions directly. In other words, Scenario 02 to work.

I found a long way as below:

Scenario 03:

module:

def printtime(time):
    print(time.time())
master program:

import time

import module


module.printtime(time)
Output will be:
Output:
1589049932.1866198
But I want some more direct way like:

Scenario 04:

module:

def printtime():
    print(SOMETHING.time.time())
master program:

import time

import module


module.printtime()
Output will be:
Output:
1589049932.1866198
Is there any way? Please help me out.

Linux Mint
python3.6
IDLE3
Reply


Messages In This Thread
importing same python library in multiple custom module - by escape_freedom13 - May-09-2020, 07:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,683 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  Pyinstaller and a custom python script mentat 0 1,213 Sep-27-2024, 04:42 PM
Last Post: mentat
  importing variables from module 8376459 1 1,053 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  no module named 'docx' when importing docx MaartenRo 1 6,257 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  python convert multiple files to multiple lists MCL169 6 3,512 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  I want to create custom charts in Python. js1152410 1 1,250 Nov-13-2023, 05:45 PM
Last Post: gulshan212
  python standard way of importing library mg24 1 1,623 Nov-15-2022, 01:41 AM
Last Post: deanhystad
  Problem with importing python-telegram library into the project gandonio 1 3,916 Nov-01-2022, 02:19 AM
Last Post: deanhystad
  My code displays too much output when importing class from a module lil_e 4 2,357 Oct-22-2022, 12:56 AM
Last Post: Larz60+
Question How to move a class to a custom module? python300 4 2,594 Mar-08-2022, 09:19 PM
Last Post: python300

Forum Jump:

User Panel Messages

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