ValueError- what do I do?

When you run it, importlib throws a ValueError-

ValueError- Empty module name

This is the first time I’ve seen this error, can someone help?

code is in, line 63. Make sure to familiarise with the different functions as it can seem confusing!

Can you show us the actual error from python? Line 63 to me is just a comment.

1 Like

If you remix it, the full error will show- i can’t send a screenshot atm

Basically look below the comment and you see the code causing issues

You’re getting that error because this line

stri = stri.replace("use", "")

is setting stri to be an empty string so then when you call

script = importlib.import_module(stri, package=None)

you’re attempting to import a module named "" which of course doesn’t exist. Thus, you get a Value Error saying your module name is empty.


okay, so I need to remove the ‘use’ part or it won’t work. Is there any ideas there?

I.e- how can I remove JUST the word ‘use’ without clearing the entire string?

Let’s look at your code in context

The replace only happens if stri is exactly equal to ‘use’. Not containing it – equal to it.

So essentially stri = "use".replace("use", "") which will always return empty string.

So you need to rethink the logic upstream from here. Did you mean to use ‘contains’?

        elif stri == "use" and state == 0:
           state = 1
           stri = stri.replace("use", "")

Possibly- you see if I get rid of the replace statement then stri equals “use” and importlib throws errors like:

ModuleNotFoundError: No module named 'use'

So I use replace to get rid of the keyword and only leave the module name to be later imported by importlib.

Perhaps the logic could be re-written, but i’m trying to get it working in any way possible.