增加layer---待完成

博客介绍了Python在实际使用时的要点,包括判断添加layer的位置条件、读取标准文件以一次性添加多个layer、加入备份模块、添加使用说明等,还提及display文件格式处理、map.ev尾部添加及techlayer/techpurpose查找等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
 1 #! /usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 # Author Ian Ying
 4 # mail: kongqing.ying@yitu-inc.com
 5 
 6 import fileinput,sys,os,re
 7 
 8 def input_file_count(filename):
 9     '''fix last line is empty by checking last 4 lines'''
10     count_line = open("streamlayer.ev", "r")
11     #line_count = len(['' for line in count_line.readlines()])
12     line_count_arr = count_line.readlines()
13     total = len(line_count_arr)
14     for i in range(1,5):
15         print line_count_arr[-i].strip()
16         re_match = re.compile(r'^\)')
17         if re_match.search(line_count_arr[-i]):
18             line_count = total-i+1
19             print line_count_arr[-i].strip(),'in'
20             break
21         else:
22             line_count = total
23     print line_count
24     count_line.close()
25     # filename_bak = filename+'bak'
26     # filename_bak = str(filename_bak)
27     # os.rename(filename, filename_bak)
28     # old_file = open(filename_bak, 'r')
29     # with open(filename, 'w') as file_modify:
30     #     for line in old_file.readlines():
31     #         print line
32     #         file_modify.write(line)
33     return line_count
34 
35 def add_layer_streamLayer(layer,datatype,layer_num,layer_type):
36     line_count = input_file_count('streamlayer.ev')
37     print line_count
38     z = 0
39     for line in fileinput.input('streamlayer.ev',inplace=1):
40         if fileinput.lineno() == line_count and (')' in line):
41             z = 'right',fileinput.lineno()
42             print '('+ layer + ' '+datatype +' )'+ layer_num +' '+ layer_type
43             print ')'
44         elif fileinput.lineno() != line_count:
45             print line.strip()
46         else:
47             z =  'Wrong! And the total line is',fileinput.lineno()
48             print line.strip()
49             fileinput.close()
50             print " The input file structure is wrong!"
51     fileinput.close()
52     print z
53 
54 
55 if __name__ == "__main__":
56     add_layer_streamLayer('M1','drawing','3','0')

 

真实使用的时候

1.需要考虑判断添加layer的位置条件。

2.需要加入读取标准文件,可以方便一次性多加数个layer。

3. streamlayer,techdisplay等等其他的文件需要另外加入。

4.最好加入一个备份模块,防止出现意外情况;

5.加入使用说明;

6.display 文件是需要加入格式的,四种格式,需要全部拷贝出来,然后随机分配;

7.map.ev尾部是没有)作为结尾的,所以只需要添加就好了;

8.techlayer/techpurpose这两个需要查找是否有涵盖到。

 

转载于:https://www.cnblogs.com/Ian-learning/p/9314189.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值