How function is getting called without defining in python
Question: Here is the program:

    
    
    import sys
    
    def IndexSearchString():
        '''
    
        This function search a string in a password file through index and gives the result.
    
        :return: none
        :return type: none 
        :author: Neeraj    
    
        '''
        fieldindex = int(sys.argv[1])-1
        stringsrch = sys.argv[2]
    
        file_name = open("passwd", "r")
    
        for store_file in file_name:
            temp = store_file.split(":")
            search = temp[fieldindex]
            #print search 
    
            if stringsrch in search:
                print store_file
                #print sys.stdout.write(store_file)   
                return
    
    #IndexSearchString() 
    


Answer: Make sure your code is exactly as it is now in the question (including the
edit by @Haidro)

The code, as you pasted it in the question, suggests your indentation was
something like this:

    
    
    def my_function():
        '''
        docstring
        '''
    code_intended_for_my_function()
    
    #my_function()
    

This would cause `code_intended_for_my_function` to be executed. This is
"valid" because the `docstring` makes the definition for `my_fuction` valid
(it just does nothing), then immediately executes
`code_intended_for_my_function`. To test this, in the code you have, remove
the `docstring` and check if you get an `IndentationError`, or just copy the
code as it is currently from the question and see if it works as you expect.

