pycharm lee archivos chi760e y exporta datos
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:
# Date:2020.10.13 23:31
# Description: open a txt including unrelvant characters(titles) and exiperiment raw data(f(x) two-column data like
import tkinter as tk
from tkinter.filedialog import askopenfilename
from itertools import islice
import sys
import fileinput
import matplotlib.pylab as pylab
# import numpy as np
# import matplotlib.pyplot as plt
data_file_path = askopenfilename(title='Select a data', filetypes=[('TXT', '*.txt')],
initialdir='D:\\OneDrive\\桌面\\')
print(data_file_path)
# f1 = open(data_file_path,'r')
# E:\00 Experiment\20201013
# islice(seq[, start], stop[, step]);
from itertools import islice
# with open(r'E:\\xx\\movie2.txt', encoding='utf-8', ) as txtfile:
data = []
with open(data_file_path) as txtfile:
line = txtfile.readlines()
for i, rows in enumerate(line):
if i in range(24, len(line) - 1): # 指定数据行
# print(rows)
data.append(rows)
print("length", len(data))
txtfile.close()
# 写入txt
#with open('D:\\OneDrive\\桌面\\data.dat', "w", ) as f:
with open('D:\\OneDrive\\桌面\\data.dat', "w", ) as f:
for i in range(len(data)):
f.writelines(data[i])
f.close()
# Reference http://www.360doc.com/content/19/0828/10/47812380_857519286.shtml
# Say thanks to the author of the docment.