在读取python缓冲区时丢弃文件的某些部分

时间:2019-02-18 06:31:30

标签: python file

我想读取一个不需要此信息的文件

REGRESS_OPTIONS {
-directed=1
-rocket_run_args =+ " +QDSP6_AXIM2_PRESENT=1 +AXIM2_LOWER_ADDR=0x30000000 +AXIM2_UPPER_ADDR=0x40000000"
-rocket_run_args =+ " +maxTime=1000000 +disableAllIntDrivers=1 +disableL2DirtyEntryCheck=1"
-rocket_run_args =+ " +enableVregPreload=2 +enableQregPreload=2"
-rocket_run_args =+ " +clkRandomEnable=0 +clkTypPeriod_CORE_CLK=1000 +clkTypPeriod_AXIM_CLK=1000 +clkTypPeriod_AXIS_CLK=1000 +clkTypPeriod_AHBM_CLK=1000"
-rocket_run_args =+ " +clkTypPeriod_VPE_ASYNC_CLK=1000"
-rocket_run_args =+ " +randomizeSTID=0"
# Adding option to allow NMI exception 
-rocket_run_args =+ " +allow_nmi_exception=1 "
# Adding option to true sharing limited to a single register
-rocket_run_args =+ "+enableReferenceCheckTrust=T0:R2,T1:R2,T2:R2,T3:R2,T4:R2,T5:R2" 
-rocket_run_args =+ " +pktidMonitor=1 +schedStallMonitor=1 +set_log_level=trace +max_error=5"
-postgen = "echo QDSP6_WS_TAG=$QDSP6_WS_TAG; $WORKSPACE/verif/core/sim/scripts/perf/get_wave_args.py wave_start 1 wave_stop 1"
-prereport = "$WORKSPACE/verif/core/sim/scripts/perf/get_perf_result.py"
}

我要在丢弃此部分后读取要缓冲的文件

我的想法是这样

with open (file_path,'r') as file:

    next(file) for 16 times 
    lines=file.readlines()        

我知道这是个坏主意。所以请建议我一个更好的方法

1 个答案:

答案 0 :(得分:1)

您可以使用Slicing

with open (file_path,'r') as file:
   content = file.readlines()

   # you may also want to remove empty lines
   content = [l.strip() for l in content if l.strip()]

   # slice through first 16 lines    
   for line in content[16:]: 
        print(line)