python数据的读写
Python数据的写入
写入txt文本文件
with…open…语句有自动的打开、关闭功能
1 2 3 4
| with open('test.txt', 'w') as f: length = len(x) for i in range(length): f.write(str(x[i])+'\n')
|
写入Excel文件
1 2 3 4 5 6 7 8
| book = xlwt.Workbook(encoding='utf-8', style_compression=0) sheet = book.add_sheet('test', cell_overwrite_ok=True) row = 0 col = 0 length = len(x) for i in range(length): sheet.write(i, col, x[i]) book.save(r'e:\test.xls')
|
python数据的读取
Python的txt文本文件的读取
1 2 3 4 5
| f = open('test.txt', 'r') for line in f: ls = line.strip('\n') ls = ls.split(' ') print(ls)
|
python读取excel的数据
1 2 3 4 5 6 7 8
| import xlrd data = xlrd.open_workbook(r'E:\数模比赛\2016美赛C\data1\problem1.xlsx') table = data.sheets()[0] nrows = table.nrows ncols = table.ncols for i in range(1,nrows): rowValues= table.row_values(i)
|
matlab数据的读取
matlab将数据读入excel
1
| xlswrite('test.xlsx', x, 1, 'A1:I1')
|
matlab读取excel中的数据
1 2
| [score head raw] = xlsread('score.xlsx')
|
matlab将数据写入text
1 2 3 4 5 6 7
| x = 0:pi/20:pi; u = sin(x); fid = fopen('data.txt','w'); for i = 1:21, fprintf(fid,'%5.3f %8.4f\r\n',x(i),u(i)); end; fclose(fid);
|
matlab将数据写入text文本文件
将c++数据读入读出txt
1 2 3
| freopen("data.in","r",stdin); freopen("data.out","w",stdout);
|
一些字符串的小技巧
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| first_name = 'tian'; second_name = 'baolin' strcat(first_name, second_name) strcat({first_name, second_name}, {'baby', 'dragon'}) sprintf('%s%s', first_name, second_name) str = [first_name, second_name]; str number = 23333; num2str(number)
|
未解决的问题