Python Forum
Make bash call my own Python modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make bash call my own Python modules
#4
What I have not seen before: You're modifying the sys.path list.
Don't do this. Put all your python files into a directory and put an empty __init__.py file into this directory.
Then you can do:

import directory_name.module_name
The module_name is in this case the python file, you want to access in this directory.
The .py extension is not used. Please read more about the import system, before you try
to invent your own stuff.


If you put the names (of the functions) in the list, the functions have to be imported or defined.

def function1():
    return 42

def function2():
    return 1337

# then you can create the list, with the function objects inside.
my_funcs = [function1, function2]

# iteratring over functions, print the name, call it

for func in my_funcs:
    name = func.__name__
    print('Calling function:', name)
    result = func()
    print('Result:', result)
If you put my_funcs from line 8 to line 1, you'll get a NameError. The function is not defined yet.
You can also import functions from other modules and put them afterwards in a list.
But the order is always: Assign an object to a name, then you can access with name the object.

You should refactor the names and the places.
For example you can make a module called make.
All functions inside the make module, does not contain the name make.

You should have something like this:
import make

# functions from make
make.br()
make.a()
make.img()
make.table()
make.tr()
make.td()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Make bash call my own Python modules - by DeaD_EyE - Apr-19-2019, 12:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 655 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  How to see the date of installation of python modules. newbieAuggie2019 4 1,799 Mar-31-2023, 12:40 PM
Last Post: newbieAuggie2019
  Python modules for accessing the configuration of relevant paths Imago 1 1,480 May-07-2022, 07:28 PM
Last Post: Larz60+
  Call a bash script from within a Python programme Pedroski55 6 2,577 Dec-06-2021, 01:53 PM
Last Post: DeaD_EyE
  Showing and saving the output of a python file run through bash Rim 3 2,617 Oct-06-2021, 10:48 AM
Last Post: gerpark
  Python modules to extract data from a graph? bigmit37 5 22,788 Apr-09-2021, 02:15 PM
Last Post: TysonL
  Where to add own python modules in WinPython? HinterhaeltigesSchlaengelchen 1 2,358 Jan-21-2021, 07:45 PM
Last Post: snippsat
  Including modules in Python using sys.path.append JoeDainton123 1 3,034 Aug-24-2020, 04:51 AM
Last Post: millpond
  How to kill a bash script running as root from a python script? jc_lafleur 4 6,122 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 3,157 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS

Forum Jump:

User Panel Messages

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