Python Forum
Regarding import library in two different program file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regarding import library in two different program file
#1
Hi,
I wrote two Python programs. One program has a class definition and other program importing that class to access its attributes and methods. In both the programs I am importing sys in-built library and using it. Is there any way to import sys library in one program and use it in other program without importing?

Code is here:
#Program: program_1.py
import sys

class xmlFile:
    def sendXML(self, xmlFile):
        try:
            print("Processing XML file %s..." %xmlFile)
        except FileNotFoundError:
            print(os.path.basename(sys.argv[0])
                  + "->" + self.__class__.__name__
                  + "::"
                  + sys._getframe().f_code.co_name
                  + "(): File "
                  + xmlFile
                  + " does not exists!")
            exit(-2)

#Proram: program_2.py
import sys
import os.path
from program_1 import xmlFile

if (len(sys.argv) <= 1):
    print("usage: "+(os.path.basename(sys.argv[0]))+" <xml file>")
    exit

xmlFl = xmlFile()
dataList = xmlFl.sendXML(sys.argv[fl])
Thanks!
Reply


Messages In This Thread
Regarding import library in two different program file - by Rohit - Jan-22-2020, 04:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write variable in a python file then import it in another python file? tatahuft 4 1,167 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  import a function from another file using relative path paul18fr 6 3,967 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  Calling a function (which accesses a library) from another file mouse9095 4 5,022 Jun-07-2023, 08:55 PM
Last Post: deanhystad
Video doing data treatment on a file import-parsing a variable EmBeck87 15 6,175 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Import XML file directly into Excel spreadsheet demdej 0 1,688 Jan-24-2023, 02:48 PM
Last Post: demdej
  [Solved by deanhystad] Create a zip file using zipfile library DZ_Galaxy 2 6,890 Aug-17-2022, 04:57 PM
Last Post: DZ_Galaxy
  Install any library via pip get an error cannot import name 'SCHEME_KEYS' from 'pip. Anldra12 2 13,271 Jan-04-2022, 01:05 PM
Last Post: Anldra12
  How from sklearn.datasets import load_diabetes change to import to CSV file Anldra12 0 2,825 Dec-25-2021, 07:20 PM
Last Post: Anldra12
  How to import file and function in another folder SriRajesh 1 5,859 Dec-18-2021, 08:35 AM
Last Post: Gribouillis
  getting an import statement to work in my program barryjo 1 2,506 Dec-06-2021, 04:28 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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