Pass a file as a parameter in two Python Scripts
Question: New Python'er has a question _"hand raised"_.

I have two Python Scripts and a XML file. "mysecondpython.py" needs to call
"myfirstpython.py" with a parameter of "data.xml" so that it can write
something in, which then returns a file.

From command-line, I should type `python mysecondpython.py` and it should be
viola! But I got no cigars. What is this new python'er doing wrong?

**myfirstpython.py**

    
    
    import xml.etreeElementTree as et
    
    def allmytrees(file):
        dest_tree = et.parse(file)
        dest_root = dest_tree.getroot()
    
    def inserter():
        dest_root.insert(0, "hello world")
    
    def printer():
        dest_tree.write('out.xml', xml_declaration=True, encoding='utf-8')
    
    if __name__ == "__main__":
        allmytrees(file)
        inserter()
        printer()
    

**mysecondpython.py**

    
    
    import myfirstpython
    
    def callingscripts(file)
        callpython = myfirstpython(file)
    
    if __name__ == "__main__":
        file = "data.xml"
        callingscripts(file)
    

**data.xml**

    
    
    <root>
        <nothing-here>123</nothing-here>
    </root>
    

_I'm in tears._


Answer: When you import a file, it's `__name__` does not `== "__main__"`.

In fact, the statement `if __name__ == "__main__":` is specifically designed
to say "am I the program that is running, or am I being imported (in which
case don't do this stuff)"

You need to write a function in myfirstpython.py, and call it from
mysecondpython.py

