Python "Exercise 1" Asset information scan

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.