Accessing another script (2.58, Python)

Just a quick question:
Is it possible to access some code in another script from the current one, or is there another way to do what I’m looking to achieve?


def main():
    print("Attempting to access script2")

def main():
    print("Accessed script2")

Yes you can.
As long as you realise that when you import a script it executes the code within it.
for the script you want to access, name it (script is just the name, but must end in .py)
then use
import script
script_main = script.main()

I have the file formats labeled correctly (, but when I import the script and try to assign it to a variable (or just use “script.main()” by itself) it says the module does not have the attribute ‘main’, when main is clearly defined in the accessed script. These are just scripts in Blender’s text editor to be clear.

Also, I forgot to clarify in the title that I’m using 2.58 if it’s of any importance at this point.