There are several different errors in the code. The one that throws your exception is that your data function is written to a global variable and returns nothing, but your later code expects it to return something iterable, like a sequence or generator.
You can fix this by making top-level code repeat directly in the global dictionary, or you can get rid of the global one and create a dictionary in data and return it at the end. I suggest the latter, since global variables are difficult to cope with making your code more complex.
Here is a rough outline of how this should work (I leave the middle part sketchy, as I will discuss it later):
def data(file): objects = {}
Your next mistake is deleting lines. Currently, your code checks each line for inequality using its strip method. This is a bug in Python 3, because line and line.strip are incomparable types. But even if it worked, it would be pointless. I suspect that you tried to eliminate the empty lines by first removing them and rejecting everything that is empty. Here's how you can do it:
if not line.strip(): continue
This is an example of what some people in the Python community call the look-before-jump programming style (LBYL) as you test for something that might be a problem before it becomes one of them. An alternative is the “easier to ask forgiveness than permission” (EAFP) style, in which you simply wrap the area in which the problem may occur in the try block and catch the generated exceptions. The EAFP style is sometimes considered more "Pythonic", so I will show this style a bit.
The following error is logical, not what causes the error. You split your line, and you want to get its two parts into the variables key and value . However, you make two separate assignments for these variables, and in fact they end with the same value in each. This is the place where you can use the cool Python syntax function, unpacking. Instead of assigning each variable separately, you can assign a two-digit sequence (such as a list or tuple) for both of them together. Python will take care of providing the first value of the first variable, and the second to the second variable. Here's what it looks like:
key, value = line.split(":")
This will fail if there is no colon in the course, so it’s convenient for us to place a try block if we use the EAFP coding style. Here is one way to do this:
try: key, value = line.split(":") except ValueError: continue
Instead, you can put a try block around everything that remains in the loop, and then let the except block contain only pass (which does nothing but ignores the exception).
Finally, the last logical error you have is related to how you create your nested dictionaries. Your current approach is to first create one dictionary with all the keys and values from your file, and then divide them into separate parts, one per celestial object. However, this does not work if the keys for each object are the same. Since each object has an Orbital Radius key, for example, they are all going to write on top of each other, placing this key in a single dictionary.
@sudo_o's answer shows how to build an internal dictionary and populate it with values (it is almost identical to what I was going to write). I just wanted to post the rest of my explanations!