Python Forum
Call and execute methods from a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call and execute methods from a list
#2
I have almost reached a solution.
class TestSuites(unittest.TestCase):

    def firstHagerTest(self):
        argumentsList = [] #creates empty list
        for i in sys.argv: #iterates trough arguments and adds them to list
            argumentsList.append(i) 
        argumentsList.pop(0) #remove first argument because it's the path to the script by default
        HagercadLogger.Logger.Log(HagercadLogger.LEVEL_WARNING, "PRINT MY ARGS LIST: " + ', '.join(argumentsList)) #prints the list     
        #map(str, argumentsList)
        #results = [f() for f in argumentsList]
        try:
            func_to_run = globals()[argumentsList] #i have to find a way to make this line work as the line func_to_run2 somehow, and of course no matter the no. of elements
            #func_to_run2 = globals()[HagercadUtilities.Utilities.startApp(), HagercadSteps.Steps.createNewProject()] #this work ok 
        except KeyError:
           pass
If I execute the script with func_to_run2 where the steps are harcoded it works. But if I run with my list inside wich also contains the same steps i get and error like this:
TypeError: unhashable type: 'list'

What could be the problem?
Reply


Messages In This Thread
Call and execute methods from a list - by asheru93 - Jan-16-2019, 08:22 AM
RE: Call and execute methods from a list - by asheru93 - Jan-16-2019, 02:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  for loops break when I call the list I'm looping through Radical 4 1,074 Sep-18-2023, 07:52 AM
Last Post: buran
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 991 May-02-2023, 08:40 AM
Last Post: Gribouillis
  How to create a linked list and call it? loves 12 4,978 Nov-22-2020, 03:50 PM
Last Post: loves
  list call problem in generator function using iteration and recursive calls postta 1 2,047 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,195 Jul-27-2020, 04:19 PM
Last Post: buran
  API call returning list value of 'None' jimbone30 5 2,778 Jun-14-2019, 07:42 PM
Last Post: jimbone30

Forum Jump:

User Panel Messages

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