0

i have written two modules in python "Sample.py" and "GenericFunctions.py" from "Sample.py", iam calling a function

present in "GenericFunctions.py" but i am not able to call that function getting error as "AttributeError: 'module' object has no attribute 'fn_ElseLog'"

Code in Sample.py:

import GenericFunctions

def sampleee():
    g_TCaseID="SD1233"
    g_TCDescription="Login"
    g_TestData="hi"
    g_Result="Fail"

    g_Remarks="testing"
    g_TargetEnvironment="S1"
    g_TargetSystem="Legacy"
    g_TargetRegion="EU"
    x = GenericFunctions.fn_ElseLog(g_TCaseID, g_TCDescription, g_TestData, g_Result, g_Remarks)


sampleee()

Code in GenericFunctions.py:

def fn_ElseLog(g_TCaseID, g_TCDescription, g_TestData, g_Result, g_Remarks):

    print "entered in ElseLog Function"
    Output= fn_Output(g_TCaseID, g_TCDescription, g_TestData, g_Result , g_Remarks)
    print ("Testcase"+"'"+g_TCDescription+"'"+"execution completed"+"'"+g_TargetEnvironment+"-"+g_TargetRegion)

def fn_Output(p_TCaseID, p_TCDescription, p_TestData, p_Result , p_Remarks):
    OutputSheet=""
    OutputSheet="\Test"+"_"+g_TargetEnvironment+"_"+g_TargetSystem+"_"+g_TargetRegion+".xlsx" 
    OutputPath=r"C:\Users\u304080\Desktop\PlayAround\Shakedowns\OutputResultFiles"

    #objExcel1 = win32.gencache.EnsureDispatch('Excel.Application')
    Outputfile=os.path.exists(OutputPath+OutputSheet)

    if Outputfile==True :
       print('Output file is present')
    else:
       print('Output file is not present')
       return

    objExceloutput = win32.gencache.EnsureDispatch('Excel.Application')
     #excel.DisplayAlerts = False
    objoutputworkbook = objExceloutput.Workbooks.Open(OutputPath+OutputSheet)
    objSheetOutput = objoutputworkbook.Sheets(1)
    OutputRowCount =objSheetOutput.UsedRange.Rows.Count
    print "OutputRowcount" , OutputRowCount
    objSheetOutput.Cells(OutputRowCount+1,1).Value=p_TCaseID
    objSheetOutput.Cells(OutputRowCount+1,2).Value=p_TCDescription
    objSheetOutput.Cells(OutputRowCount+1,3).Value=p_TestData
    objSheetOutput.Cells(OutputRowCount+1,4).Value=p_Result
    objSheetOutput.Cells(OutputRowCount+1,4).Font.Bold = True

    if p_Result=="Pass":
       objSheetOutput.Cells(OutputRowCount+1,1).Font.ColorIndex = 10 
    else:
       objSheetOutput.Cells(OutputRowCount+1,1).Font.ColorIndex = 3

    objoutputworkbook.SaveAs(OutputPath)
    objSheetOutput=None
    objoutputworkbook=None
    objExceloutput.Quit()
    objExceloutput=None   

Can you guys show me a solution for this?

2
  • 1
    are they in the same directory? Commented Nov 4, 2013 at 8:24
  • @samrap how to know that they are in the same directory or not !!! Commented Nov 4, 2013 at 10:13

2 Answers 2

1

Try:

  1. delete all pyc files in your directory. (to ensure it is not in cached)
  2. print(dir(GenericFunctions)) and print(GenericFunctions.__file__) in Sample.py, to see if you are importing the file you think you are importing.
  3. see if there are other files called GenericFunctions somewhere on your PYTHONPATH (echo $PYTHONPATH).
Sign up to request clarification or add additional context in comments.

8 Comments

@RickeyA as u suggested i tried with print(GenericFunctions.__file__) in the output it is printing two files with the same name as "C:\workspace\sample\GenericFunctions.pyc C:\workspace\sample\GenericFunctions.pyc" then what i have to do now
there are two files in my workspace one is compiled python file and python file ...is it correct to have two files like that ??
@somesh: Yes, the .py holds your code, and when you run that a .pyc file is created by the interpreter that holds the intermediate bytecode. You can delete the .pyc file to see if that solves your problem.
@somesh: it is strange the filename is printed twice. Are you including sample.py in another module?
yes...i included in GenericFunctions.py ..is it correct or not ??
|
1

present in "GenericFunctions.py" but i am not able to call that function getting error as "AttributeError: 'module' object has no attribute 'fn_ElseLog'"

As presented, your code looks correct.

Check to make sure both files are in the same directory, then either restart your python or do a reload(GenericFunctions) to make sure you don't have an out-of-date version in the sys.modules cache.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.