Global defining fails

I keep getting errors about global name ‘surShaderOut’ is not defined, otherwise it will be the 'texP
I append the info of the texPath I have obtained into a Dict but it does not seems to be working.

For the assignTex function, it is appending the converted file - texPath onto a attribute of a custom shader

Can someone kindly advise me?

def sur_shader_ls():
    
    surShader = cmds.ls(type = 'surfaceShader')
    texDict = {}
    surDict = {}
    
    for con in surShader:
        surShaderOut = cmds.listConnections('%s.outColor' % con)
        surShaderTex = cmds.getAttr("%s.fileTextureName" % surShaderOut[0])
        
        surDict.append(surShaderOut)

        """ getting the directory of where the texture file is """
        path = os.path.dirname(surShaderTex)
        
        """ Only grabbing the file name """
        f = surShaderTex.split("/")[-1]
        
        """ changing the file formats """
        tifName = os.path.splitexIt(f)[0] + ".tif"
        texName = os.path.splitext(f)[0] + ".tex"
        
        """ joining the file path with the new file format """
        tifPath = os.path.join(path, tifName)
        texPath = os.path.join(path, texName)

        """ Converts all the image files to .tif then .tex and place it in the directory they are source from  """
        convert_text(surShaderTex, tifPath, texPath)
        
        texDict.append(texPath)
        return texPath
        return surShaderOut
        
        
def assignTex():
    
    """ Grabs the geo that the surfaceShader is assigned to """
    #meshAssign = pm.listConnections(surShaderOut[1], type = "mesh")[0].longName()
    meshAssign = pm.listConnections(surShaderOut[1], type = "mesh")
        
    for geo in meshAssign:
        geoName = geo.longName()
            
        """ Creates new Generic Shader and assign it inidivually to the list of converted textures present """
        newTmp = cmds.duplicate("dnGenericV5_srf", ic = True)
        mm.eval("setAttr -type \"string\" " + newTmp[0] +  ".Input_Texture[0].inputTextures" "\"" + texPath + "\";")
        cmds.shdAssign(geoName, a = newTmp[0])

well you are using variables in assignTex that dosnt exist, i would recomend you pass in texPath and surShaderOut to it as arguments.

Than in sur_shader_ls you got a few problems you got 2 return statements, python stop executing a function when it hits a return statement, if you need to return multiple variables do this.

return texPath, surShaderOut

that will return the data as a tuple with texPath on index 0 and surShaderOut on index 1.

Dicts also dont have a .append() method and for what you are trying to accomplish there is no reason to use a dict over a list.

Also your return statements are breaking your loop early since a return statement stops execution of a function.
Also why are you mixing maya.cmds, pymel, and mel code? Nothing in that code that cant be done exclusively with one or the other.

also other recommendation would be to use # for comments over your triple " triple " or ’ are for docstrings not comments.