1

I want to use my own function in different code,every time i have to copy function and paste in new code,So i want to save function permanently,then i can access my own function in different code with single line function access.like we are using sum(),mean() function in same way want to use my own function.please help

def get_dataframe(list2):
    wpr_day=[]
    for i in range(len(list2)):
       with open(list2[i], 'r') as csvfile:
            reader = csv.reader(csvfile, delimiter='\t')  
            for row in reader:
               if len(row) == 0:
                      continue
               wpr_day.append(row)
    for row1 in aa:
    cols1=row1.split()
    if(cols1[0]=='Date'):
        date8.append(a[0])
        for i in range(int(bins)):
            dlist.append(aa[line_no])           
    elif(cols1[0]=='Time'):
        time8.append(aa[line_no][7:15])
        for i in range(int(bins)):
            tlist.append(aa[line_no][7:15])       
    elif(cols1[0]=='Height(mtr)'):
        blist.append((wpr_day))
        fd=fd.append(wpr_day.iloc[(line_no+1):(line_no+(int(bins)+1)),:])
    elif(cols1[0]=='Height'):
        for v in range(line_no+1,line_no+(int(bins)+1)):
            df_ht.append(aa[v])
            df_snr.append(bb[v])
    line_no=line_no+1   

return result_df,dtime_uvw,date8,blist,df_ht,df_snr

i want to use my own function in different code with single line access example, result_df_slp,dtime_uvw_slp,date8_slp,blist_slp,xx,yy=get_dataframe(list_uvw1)

1 Answer 1

1

Well you can just put it in a file, like gd.py, and then in the program that wants it put at the top:

from gd.py import get_dataframe

You may have to change this depending on where you locate the file. There is a lot of good information about that here.

Sign up to request clarification or add additional context in comments.

2 Comments

can u explain more about gd.py,
What I was saying was that you can create gd.py containing your python code for the function get_dataframe, then import that function from that file into any other python program.

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.