Python Forum
Including classes from folder issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Including classes from folder issue
#1
Hi Guys,

What i'm trying to do is execute a few actions on a few websites using selenium, i was going to have my structure like:

sites
--site1.py
--site2.py
--site3.py

Each file in the "sites" folder would be a class, in the main file:

import sys
sys.path.append('/sites')
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

#options = Options()                                                                    
#options.headless = False                                                              
#options.add_argument('start-maximized')                                                
#options.add_argument('disable-infobars')                                               
#options.add_argument("--disable-extensions")                                          
#driver = webdriver.Chrome("chromedriver.exe", chrome_options=options)                

print(sys.path.append('/sites'))
I'm trying to include the "sites" folder, and access the classes inside, in a class i have a basic test message:

def testing():
    print('hello testing!')
To check if it's working or not, i cannot seem to see the best way to include the classes from the folder, any help would be appreciated.

cheers guys

Graham
Reply
#2
A python file is not a class. You could simply import the submodules one by one
from importlib import import_module
import sites
mods = {}
for name in ('site1', 'site2', 'site3'):
    mods[name] = import_module('.' + name, 'sites')
mods['site1'].testing()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 466 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Function to count words in a list up to and including Sam Oldman45 15 6,414 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,391 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Including data files in a package ChrisOfBristol 4 2,465 Oct-27-2021, 04:14 PM
Last Post: ChrisOfBristol
  Not including a constructor __init__ in the class definition... bytecrunch 3 11,525 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,438 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  how to create pythonic codes including for loop and if statement? aupres 1 1,888 Jan-02-2021, 06:10 AM
Last Post: Gribouillis
  Including modules in Python using sys.path.append JoeDainton123 1 2,851 Aug-24-2020, 04:51 AM
Last Post: millpond
  Python Cut/Copy paste file from folder to another folder rdDrp 4 4,945 Aug-19-2020, 12:40 PM
Last Post: rdDrp
  Including a Variable In the HTML Tags When Sending An Email JoeDainton123 0 1,847 Aug-08-2020, 03:11 AM
Last Post: JoeDainton123

Forum Jump:

User Panel Messages

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