Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def writeListName(fileName,createFunction,functionLocalVar,listName,*args):
- 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(createFunction+functionLocalVar+str(var_name(listName)+" = "))
- listName.append((args))
- 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 file_delete_bracket:
- file_delete_bracket.seek(-1, os.SEEK_END)
- file_delete_bracket.truncate()
- file_delete_bracket.close()
- File = open(fileName,"a")
- File.write("\n\t")
- listName.append((args))
- list_str = str(listName)
- list_str = list_str.replace("[","")
- list_str = list_str.replace("]","")
- File.write(","+str(list_str)+"]")
- File.close()
- listx = []
- location_file = "loc.py"
- create_function = "def location():\n\t"
- function_local_var = "location."
- writeListName(location_file,create_function,function_local_var,listx, "Name",2000,1)
Advertisement
Add Comment
Please, Sign In to add comment