Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def writeit(fileName,listName,functionName,localVariable, loc_name,loc_id,loc_lvl):
- var_name = lambda x:[ n for n in globals() if id(globals()[n]) == id(x) ][0]
- if ( os.stat(fileName).st_size == 0 ):
- File = open(fileName,"w")
- File.write("def "+functionName+"():\n\t"+localVariable+"."+str(var_name(listName))+" = ")
- listName.append((loc_name,loc_id,loc_lvl))
- list_str = str(listName)
- index = list_str.index("]")
- cut_list = list_str[:index]+list_str[index+1:]
- result = cut_list
- File.write(str(result)+"]")
- File.close()
- elif ( os.stat(fileName).st_size > 0 ):
- with open(fileName, 'rb+') as filehandle:
- filehandle.seek(-1, os.SEEK_END)
- filehandle.truncate()
- filehandle.close()
- File = open(fileName,"a")
- File.write("\n\t")
- listName.append((loc_name,loc_id,loc_lvl))
- list_str = str(listName)
- list_str = list_str.replace("[","")
- list_str = list_str.replace("]","")
- File.write(","+str(list_str)+"]")
- File.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement