Tag:python asset information
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2017/10/24 0024 11:31# @Author : mingimport jsonimport copylocation = "r00l00" # default location dict = {} #定义一个空字典, Store the contents of each scan list = [] # define a list that stores all the scanned content File = raw_input ("Please enter a filename: ") # input file name filename = (file + ". txt ") # file name flag = true # used to jump out of the loop using while flag: assets = raw_input ("please enter the asset number[press q To quit]: ") # user input if assets.startswith (" R "): # Determine if it is a location location = Assets continue # if it is a position, the next cycle elif assets.lower () == "Q": # decide whether to exit print "\nexit successfully. asset saved current directory: %s " % file break # Exit Programs else: for i in list: # Judging whether to repeat if i["Name"] == assets: # Cycle Total List print ">>> %s Asset information repetition, Save OLD <<< " % i[" name "] flag = false break if flag == False: flag = True continue # repeat and then jump out of the parent loop asset = assets dict["Name"] = asset # asset Copy to empty dictionary dict["Weizhi"] = location # location Copy to empty dictionary dict_deep = copy.deepcopy (dict) # Deep copy list.append (dict_deep) # scanned content added to the list f = open (filename, ' a ') # open newly created file line = json.dumps (dict_deep["name"]) + ": " + json.dumps (dict_deep[" Weizhi ") # contents of the current scan f.writelines (line + "\ r \ n") # Write File print ("Success to add assets: %s locat: %s " % (dict_deep[" name "], dict_ deep["Weizhi")) # print Success f.close () #关闭文件if assets.lower ( ) == "Q": raw_input ("\ninput [enter] exit")
This article is from the "Lifelong Learning" blog, please be sure to keep this source http://20120809.blog.51cto.com/10893237/1975662
Python "Exercise 1" Asset information scan