with open(C:\\\\Users\\\\Administrator\\\\Desktop\\\\23\\\\56.txt, a, encoding=utf-8) as g: g.write(name,,y,x,h) f= open (C:\\\\Users\\\\Administrator\\\\Desktop\\\\23\\\\sy.txt,r,encoding=utf-8) for line in f.readlines(): with open (C:\\\\Users\\\\Administrator\\\\Desktop\\\\23\\\\56.txt,a,encoding=utf-8) as g: g.write(\\n) g.write(line) g.close() 兴趣点 读写 r w 增加 a 获取所需格式的数据 与pandas 进行联动 写成函数
本文转载自: 使用文本文件(.txt)进行数据存取的技巧总结(相当的经典) http://www.ilovematlab.cn/thread-872-1-1.html (出处: MATLAB中文论坛) 特别说明:由于大家在 I/O 存取上以 txt 文件为主,且读取比存储更麻烦(存储的话 fwrite, fprintf 基本够用),因此下面的讨论主要集中在“txt 文件的读取”上。除了标注了“转”之外,其余心得均出于本人经验之结果,欢迎大家指正、补充。 一. 基本知识: --------------------------------------------------转---------------------------------------------------- 1. 二进制文件与文本文件的区别: 将文件看作是由一个一个字节(byte) 组成的, 那么文本文件中的每个字节的最高位都是0,也就是说文本文件使用了一个字节中的七位来表示所有的信息,而二进制文件则是将字节中的所有位都用上了。这就是两者的区别;接着,第二个问题就是文件按照文本方式或者二进制方式打开,两者会有什么不同呢?其实不管是二进制文件也好,还是文本文件也好,都是一连串的0和1,但是打开方式不同,对于这些0和1的处理也就不同。如果按照文本方式打开,在打开的时候会进行translate,将每个字节转换成ASCII码,而以按照二进制方式打开的话,则不会进行任何的translate;最后就是文本文件和二进制文件在编辑的时候,使用的方式也是不同的。譬如,你在记事本中进行文本编辑的时候,你进行编辑的最小单位是字节(byte);而对二进制文件进行编辑的话,最小单位则是位(bit),当然我们都不会直接通过手工的方式对二进制文件进行编辑了。 从文件编码的方式来看,文件可分为ASCII码文件和二进制码文件两种: ASCII文件也称为文本文件,这种文件在磁盘中存放时每个字符对应一个字节,用于存放对应的ASCII码。例如,数5678的存储形式为: ASCII码: 00110101 00110110 00110111 00111000 ↓ ↓ ↓ ↓ 十进制码: 5 6 7 8 共占用4个字节。ASCII码文件可在屏幕上按字符显示,例如源程序文件就是ASCII文件,用DOS命令TYPE可显示文件的内容。由于是按字符显示,因此能读懂文件内容。 二进制文件是按二进制的编码方式来存放文件的。例如,数5678的存储形式为:00010110 00101110 只占二个字节。二进制文件虽然也可在屏幕上显示,但其内容无法读懂。C系统在处理这些文件时,并不区分类型,都看成是字符流,按字节进行处理。输入输出字符流的开始和结束只由程序控制而不受物理符号(如回车符)的控制。因此也把这种文件称作“流式文件”。 2. 文本模式(textmode)和二进制模式(binarymode)有什么区别? 流可以分为两种类型:文本流和二进制流。文本流是解释性的,最长可达255个字符,其中回车/换行将被转换为换行符“\n”,(如果以文本方式打开一个文件,那么在读字符的时候,系统会把所有的\r\n序列转成\n,在写入时把\n转成\r\n )。二进制流是非解释性的,一次处理一个字符,并且不转换字符。 注: \n一般会操作系统被翻译成行的结束,即LF(Line-Feed) \r会被翻译成回车,即CR(Cariage-Return) 对于文本文件的新行,在UNIX上,一般用\n(LF)来表示,Mac上用\r(CR)来表示, Windows上是用\n\r(CR-LF)来表示。 通常,文本流用来读写标准的文本文件,或者将字符输出到屏幕或打印机,或者接受键盘的输入;而二进制流用来读写二进制文件(例如图形或字处理文档),或者读取鼠标输入,或者读写调制解调器。如果用文本方式打开二进制文件,会把“0D 0A”自动变换成“\n”来存在内存中。写入的时候反向处理。而二进制方式打开的话,就不会有这个过程。但是,Unicode/UTF/UCS格式的文件,必须用二进制方式打开和读写。 --------------------------------------------------------------------------------------------------------- 上述基础其实大可以略过,简言之,对用户来说:在 matlab 中存储成为二进制还是文本文件取决于fopen的方式,如果用wt,则存储为文本文件,这样用记事本打开就可以正常显示了;如果用w则存储为二进制文件,这样用记事本打开会出现小黑方块,要正常显示的话,可以用写字板或UltraEdit等工具打开。 二. Matlab的I/O文件操作使用技巧和总结: 1. Matlab 支持的I/O文件(对应“取/存”操作)类型:(所有文件I/O程序不需要特殊的工具箱) http://www.mathworks.com/support/tech-notes/1100/1102.html (注:从上表可以看到,matlab不支持doc格式的文档存取(因为doc文档包含很多格式控制符),请改用txt或者dat格式) 2. Matlab 的I/O文件指南: http://www.mathworks.com/support/tech-notes/1600/1602.html 以下是部分对应的中文译文: --------------------------------------------------------------转---------------------------------------- 本技术支持指南主要处理:ASCII, binary, and MAT files. 要得到MATLAB中可用来读写各种文件格式的完全函数列表,可以键入以下命令: help iofun MATLAB中有两种文件I/O程序:high level and low level. High level routines: 包括现成的函数,可以用来读写特殊格式的数据,并且只需要少量的编程。 Low level routines: 可以更加灵活的完成相对特殊的任务,需要较多的额外编程。 High level routines 包括现成的函数,可以用来读写特殊格式的数据,并且只需要少量的编程。 举个例子,如果你有一个包含数值和字母的文本文件(text file)想导入MATLAB,你可以调用一些low level routines自己写一个函数,或者是简单的用TEXTREAD函数。 使用high level routines的关键是:文件必须是相似的(homogeneous),换句话说,文件必须有一致的格式。下面的段落描述一些high level file I/O routines并给出一些例子帮助理解概念。 LOAD/SAVE 主要的high level file I/O routines 是LOAD 和 SAVE函数。LOAD 可以读MAT-file data或者用空格间隔的格式相似的ASCII data. SAVE可以将MATLAB变量写入MAT-file格式或者空格间隔的ASCII data。大多数情况下,语法相当简单。下面的例子用到数值由空格间隔的ASCII file sample_file.txt : 1 5 4 16 8 5 43 2 6 8 6 8 4 32 1 90 7 8 7 6 5 9 81 2 3 Example: 用 LOAD and SAVE 读写数据 CODE: % Load the file to the matrix, M : M = load('sample_file.txt') % Add 5 to M : M = M +5 % Save M to a .mat file called 'sample_file_plus5.mat': save sample_file_plus5 M % Save M to an ASCII .txt file called 'sample_file_plus5.txt' : save sample_file_plus5.txt M -ascii UIGETFILE/UIPUTFILE UIGETFILE/UIPUTFILE是基于图形用户界面(GUI)的。会弹出对话框,列出当前目录的文件和目录,提示你选择一个文件。UIGETFILE让你选择一个文件来写(类似Windows ‘另存为’选项?)。用UIGETFILE,可以选择已存在的文件改写,也可以输入新的文件名。两个函数的返回值是所选文件名和路径。 Example: 用 UIGETFILE 从当前目录选择一个 M-file CODE: % This command lists all the M-files in the current directory and % returns the name and path of the selected file = uigetfile('*.m','Sample Dialog Box') 注意: UIGETFILE 一次只能选择一个文件。 UIIMPORT/IMPORTDATA UIIMPORT是一个功能强大,易于使用的基于GUI的high level routine,用于读complex data files。文件也必须是homogeneous。 IMPORTDATA形成UIIMPORT的功能,不打开GUI。可以将IMPORTDATA用于函数或者脚本中,因为在函数或者脚本中基于GUI的文件导入机制并不理想。下面的例子用到包含几行文件头和文本、数值数据的文件'sample_file2.txt' : This is a file header. This is file is an example. col1 col2 col3 col4 A 1 4 612.000 B 1 4 613.000 C 1 4 614.000 D 1 4 615.000 Example: Using IMPORTDATA to read in a file with headers, text, and numeric data CODE: % This reads in the file 'sample_file2.txt' and creates a % structure D that contains both data and text data. % Note the IMPORTDATA command specifies a white space % as the delimiter of the file, but IMPORTDATA can usually % detect this on its own D = importdata('sample_file2.txt','') % 原文有误? D = importdata('sample_file2.txt') 可以通过访问结构D的数据和文本域,来看结构D中的真实值,例如输入: data = D.data text = D.textdata 可以用UIIMPORT读同一个文件并得到同样的结构. 注意: 对于 ASCII data, 你必须检验导入向导正确的识别了列分隔符。 TEXTREAD/STRREAD TEXTREAD 是一个强大的动态high level routine,设计用来读ASCII格式的文本和/或数值数据文件。STRREAD除是从字符串而不是文件读以外,类似于TEXTREAD。 两个函数可以用许多参数来改变其具体的工作方式,他们返回读入指定输出的数据。他们有效的提供给你一个 “两全其美”的方法,因为他们可以用一个命令读入混合的ASCII和数值数据(high level routines的做法),并且你可以改变他们以匹配你特定的应用(如同low level routines做到的)。例子: CODE: Example 1: Using TEXTREAD to read in an entire file into a cell array % This command reads in the file fft.m into the cell array, file file = textread('fft.m','%s','delimiter','\n','whitespace',''); CODE: Example 2: Using STRREAD to read the words in a line % This command uses the cell array created in Example 1 to % read in each word of line 28 in 'file' to a cell array, words words = strread(file{28},'%s','delimiter','') CODE: Example 3: Using TEXTREAD to read in text and numeric data from a file with headers % This command skips the 2 header lines at the top of the file % and reads in each column to the 4 specified outputs = textread('sample_file2.txt','%s %s %s %s','headerlines',2) CODE: Example 4: Using TEXTREAD to read in specific rows of text and numeric data from a file % This command reads in rows B and C of the file. The 'headerlines' % property is used to move down to the desired starting row and the % read operation is performed 2 times = textread('sample_file2.txt',... '%s %s %s %s',2,'headerlines',4) CODE: Example 5: Using TEXTREAD to read in only the numeric data from a file containing text and numbers % This command reads in only the numeric data in the file. The % 'headerlines' property is used to move down to the first row % of interest and the first column of text is ignored with the % '*' operator = textread('sample_file2.txt','%*s %d %d %f','headerlines',3) DLMREAD/DLMWRITE/CSVREAD DLMREAD 和 DLMWRITE函数能够读写分隔的ASCII data,而不是用low level routines。他们比low level routines容易使用,Low level routines用几行代码实现的功能可以用DLMREAD/DLMWRITE简化成一行。 CSVREAD用来读分隔符是逗号的文件,是DLMREAD的特殊情况。当读空格和Tab分隔的电子数据表文件时,DLMREAD特别有用。以'sample_file.txt'为例: CODE: Example 1: Using DLMREAD to read in a file with headers, text, and numeric data % This reads in the file 'sample_file2.txt' and creates a matrix, D, % with the numeric data this command specifies a white space as the % delimiter of the file D = dlmread('sample_file.txt','') CODE: Example 2: Using DLMREAD to extract the first 3 columns of the last 3 rows % This reads in the first 3 columns of the last 3 rows of % the data file 'sample_file.txt'into the matrix, D_partial. % 读文件 'sample_file.txt' 前3列后3行,到矩阵D_partial. D_partial = dlmread('sample_file.txt','', ) CODE: Example 3: Using DLMWRITE to write a comma delimited file % This creates a file called 'partialD.txt' that consists of % the first 3 columns of the last 3 rows of data where each % element is separated by a comma dlmwrite('partialD.txt',D_partial,',') 注意: 保证DLMREAD and DLMWRITE指定范围的指标从0开始,而不是从1开始。 WK1READ/WK1WRITE WK1READ 用来读Lotus123 电子数据表文件的数据;WK1WRITE用来写矩阵到Lotus123 电子数据表文件。 XLSREAD XLSREAD用来读Excel的数值和文本数据。 --------------------------------------------------------------------------------------------------------- 三. 具体例子分析: Matlab网站用两个例子非常详尽地介绍了各个命令的基本用法,实际中,面对手头上的数据,如何选用合适的命令呢?以下结合几个示例给出一些总结,大家举一反三就可以了: 1. 纯数据(列数相同): 源文件: CODE: 0 3866.162 2198.938 141.140 1 3741.139 2208.475 141.252 2 3866.200 2198.936 141.156 3 3678.048 2199.191 141.230 4 3685.453 2213.726 141.261 5 3728.769 2212.433 141.277 6 3738.785 2214.381 141.256 7 3728.759 2214.261 141.228 8 3748.886 2214.299 141.243 9 3748.935 2212.417 141.253 10 3733.612 2226.653 141.236 11 3733.583 2229.248 141.223 12 3729.229 2229.118 141.186 解答:对于这个txt文件,由于各行列数相同,故简单地使用load,importdata均可。 2.字段名(中、英文字段均可)+数据: 源文件: CODE: CH0 CH1 CH2 CH3 0.000123 0.000325 0.000378 0.000598 0.000986 0.000256 0.000245 0.000698 解答:由于是记录的形式,因此各行列数必相同(缺少部分列时请自行在文件中补上 Inf 或 NaN),故直接使用 importdata 便可。 3.注释(含有独立的数字串)+数据(列数相同): 问题:这个文件有4列,但前6行是文字说明,4列数字是从第8行开始的.现在我想把这个文件的前2列和文字说明提出来组成一个新的dat文件 源文件: CODE: Group 2 12.02.2006 Limei Samples of datas: 50000 CH0 CH1 CH2 CH3 0.000123 0.000325 0.000378 0.000598 0.000986 0.000256 0.000245 0.000698 目标文件: CODE: Group 2 12.02.2006 Limei Samples of datas: 50000 CH0 CH1 0.000123 0.000325 0.000986 0.000256 解答:由于注释中含有独立的数字串,且注释部分没有明显的格式,这时候用importdata, load等高级命令直接读取会失败,用 textread, dlmwrite 等格式化命令也不太合适,因此只能使用低级命令进行读取。(当然了,可以跳过注释部分直接用高级命令读取数据,即: = textread(filename,'%f %f %f %f','headerlines',4); )。一个简单的、非通用的包含注释的读取方法如下: -------------------------------------转 --------------------------------------------------------------------------------------- CODE: clc;clear; fid = fopen('exp.txt', 'r'); fid_n=fopen('ex.dat','w'); while ~feof(fid) tline=fgetl(fid); if ~isempty(tline) if double(tline(1))=48 double(tline(1))=57 %数值开始 a=strread(tline); a(3:4)= =strread(tline,'%s %s %s %s'); b= ; fprintf(fid_n,'%s\n',b); clear b b1 b2 b3 b4; else fprintf(fid_n,'%s\n',tline); end else fprintf(fid_n,'%s\n',tline); end end fclose(fid); fclose(fid_n); --------------------------------------------------------------------------------- 4. 注释(不含独立的数字串)+数据(列数相同): 源文件: CODE: 你好 abc 欢迎来到 我们 振动论坛 vib.hit.edu.cn 1 11 111 1111 2 22 222 2222 3 33 333 3333 4 44 444 4444 5 55 555 5555 解答:直接用 importdata 便可 注:有时候注释中含有独立的数字串也可以 importdata 成功,不过得到的结果有可能不正确,建议这时候使用第3种情形的读取方式。 5. 注释与数据混排: 对此当然只能自己编程,举例: 源文件: CODE: 1 11 111 1111 你好 2 22 222 2222 欢迎来到 3 33 333 3333 振动论坛 4 44 444 4444 vib.hit.edu.cn 5 55 555 5555 解答: --------------------------------------------转-------------------------------------- CODE: function =distilldata(infile) %功能说明: %将保存数据的原始文件中的数值数据读入到一个data变量中 %使用说明: % infile——原始数据文件名; % data=数据变量 tmpfile='tmp2.mat'; fidin=fopen(infile,'r'); % 打开原始数据文件(.list) fidtmp=fopen(tmpfile,'w'); % 创建保存数据文件(不含说明文字) while ~feof(fidin) % 判断是否为文件末尾 tline=fgetl(fidin); % 从文件读入一行文本(不含回车键) if ~isempty(tline) % 判断是否空行 =size(tline); flag=1; for i=1:n %判断一行中有没有字符(+-.Ee和空格键除外) if ~(tline(i)==' '|tline(i)=='-'|tline(i)=='.'|tline(i)=='E'... |tline(i)=='e'|tline(i)=='+'... |(double(tline(i))=48double(tline(i))=57)) flag=0; break; end end if flag==1 % 如果是数字行,把此行数据写入文件 fprintf(fidtmp,'%s\n',tline); end end end fclose(fidin); fclose(fidtmp); data=textread(tmpfile); delete(tmpfile); --------------------------------------------------------------------------------------------------------- 另外,如果要求不高,也可以使用 textread 函数跳过注释部分进行读取,不过前提是需要事先知道文件内容的结构(即哪行是数据、哪行是注释) 6.各列数据的分离: 源文件: CODE: 0 + 47038.7 1.05 09:26:07 C 2 + 46477.7 1.03 09:28:38 C 4 + 44865.7 1.04 09:28:48 C 6 + 41786.4 1.03 09:28:56 C 8 + 39896.0 0.97 09:29:03 C 10 + 37518.4 0.93 09:29:15 C 12 + 35858.5 0.92 09:29:30 C 14 + 46105.0 1.03 09:30:21 C 16 + 46168.6 6.89 09:30:30 C 18 + 48672.3 4.33 09:30:40 C 20 + 49565.7 0.49 09:30:48 C 22 + 49580.7 0.53 09:30:55 C 24 + 49602.3 0.84 09:31:03 C 26 + 49582.5 1.51 09:31:11 C 28 + 49577.0 1.39 09:31:19 C 30 + 49589.3 0.61 09:31:27 C 32 + 49578.3 1.06 09:31:29 C 34 + 49512.5 1.77 09:31:38 C 解答:直接用 =textread(yourfilename,'%d %c %f %f %s %c'); 便可 四. 注意事项: 1. 请在 matlab 中保持当前路径在该数据文件对应的目录下进行存取,否则,存取时请给出该数据文件的具体路径。 2. 存取时,请给出该数据文件的全称(包括后缀名,读取mat文件时可省略) 3. load data.txt和A=load(‘data.txt’)的区别请参阅精华贴: 写给学习 matlab 的新手们 4. 请根据读写需要来打开文件,即根据你的需要来指定 fopen 的 permission 属性为读或写。如果只用 a 进行写入,就不能用 fread 读取。此时应该写完关闭文件,然后用 r 打开读取,或者直接用 a+ 进行同时读写操作。否则,会产生莫名其妙的问题!以下代码是一个错误的例子: CODE: filename='e.dat'; fid=fopen(filename,'a'); if fid0 error('fopen error'); end s= ; fwrite(fid,s,'float32') =fread(fid,inf,'float32');%把t中的数据全部读出,即s矩阵。 fclose(fid); 此时得到的dd, ll 是错误且无意义的! 五. 其他相关问题: 1. 连续读取多个文件的数据,并存放在一个矩阵中: (1) 首先是如何读取文件名: 方法一: filename=dir(‘*.jpg’); 那么第i个文件的文件名就可以表示为 filename(i).name 文件数量为:length(filename) 方法二: 先在Windows的 MSDOS(命令行)中使用以下命令生成一个list.txt文件: dir path\folder /on /b /s path\list.txt 举例:dir d:\test /on /b /s d:\list.txt 然后在 matlab 中使用: filename = textread(sFileFullName,'%s'); 把所有文件名读取到list细胞矩阵中,最后对filename{i}便可得到各文件名。 (2) 然后是读取文件名的数据并存储: 假设每个文件对应的数据是m*n的,则: CODE: k = length(filename); Data = zeros(m,n,k); for ii = 1:k Data(:,:,ii) = yourreadstyle(filename{ii}); %yourreadstyle是对应的文件读取方式的函数 end 2. 连续读取多个文件的数据,并存放在多个矩阵(以文件名命名)中: 假设每个文件对应的数据是m*n的,则以上述第二种文件名读取方法为例: CODE: k = length(filename); for ii = 1:k D = yourreadstyle(filename{ii}); eval( ); end 3. 文件名命名问题: 文件名为 abc00001,abc00002,... abc00009,abc00010,... abc00099,abc00100,...abc00879. 准备把这些文件名给放到一个数组里面去。 解答: CODE: a=cell(879,1); for k=1:879 a{k} = sprintf('%.5d',k); end 4. 上述各种文件格式、类型自动识别问题:可以利用正则表达式来处理,使之通用性较强。例如使用以下代码可以自动处理上面提到了例1到例5各种情形,不过由于存在自动判断,对某些例子(如例1)效率自然要低一点,而对于另外的例子(如例3、例5)效率估计要高一点(少用了一个循环)。 CODE: function =distilldata_eight(infile) %功能说明: %将保存数据的原始文件中的数值数据读入到一个data变量中(自动判断数据行) %使用说明: % infile——原始数据文件名; % data=数据变量 tmpfile='tmp2.mat'; fidin=fopen(infile,'r'); % 打开原始数据文件(.list) fidtmp=fopen(tmpfile,'w'); % 创建保存数据文件(不含说明文字) while ~feof(fidin) % 判断是否为文件末尾 tline=fgetl(fidin); % 从文件读入一行文本(不含回车键) if ~isempty(tline) % 判断是否空行 str = ' '; %正则表达式为:该行中是否包含除 - . E e 数字 和 空白字符 外的其他字符 start = regexp(tline,str, 'once'); if isempty(start) fprintf(fidtmp,'%s\n',tline); end end end fclose(fidin); fclose(fidtmp); data=textread(tmpfile); delete(tmpfile) 5. 大量数据的读取问题: 可以考虑使用循环分批读取(特别是在各数据是独立的时候),或者使用稀疏矩阵来实现(对此可以参阅本版精华贴: 提高matlab运行速度和节省空间的一点心得(之三))。另外,也可参考《深入浅出MATLAB 7_X混合编程》一书第一章 6. 读取整个txt文件的内容(获得文件中的所有字符): CODE: f = fopen('yourfilename.txt','rt'); % t 属性根据需要可省略 x = fread(f,'*char'); fclose(f); 7. 把维数不同的矩阵及其变量名保存到一个 txt 文件中,例如 a1 = 123; a2 = ,希望得到的 txt 文件如下: QUOTE: a1: 123 a2: 1 2 3 4 5 6 如果写入的时候简单一点,则可以采用以下方式,不过读取的时候比较麻烦: CODE: a1=123; a2= ; fid = fopen('myfile.txt', 'wt'); for i=1:2 fprintf(fid, '%s: \n %s\n', , mat2str(eval( ))); end fclose(fid); 相反,如果写入的时候复杂一点,则读取的时候会简单一点: CODE: a1=123; a2= ; fid = fopen('myfile.txt', 'wt'); for i=1:2 fprintf(fid, '%s: \n', ); b = eval( ); fprintf(fid, , b'); end fclose(fid); Matlab中文论坛: www.iLoveMatlab.cn
import re import urllib from bs4 import BeautifulSoup url = http://journals.plos.org/plosone/article?id=info%3Adoi/10.1371/journal.pone.0162069 response = urllib.urlopen(url) page = response.read() soup = BeautifulSoup(page, lxml) # kill all script and style elements for script in soup( ): script.extract() # rip it out # get text text = soup.get_text() # break into lines and remove leading and trailing space on each lines = (line.strip() for line in text.splitlines()) # break multi-headlines into a line each chunks = (phrase.strip() for line in lines for phrase in line.split( )) # drop blank lines text = '\n'.join(chunk for chunk in chunks if chunk) #print(text) #This command will create the ouput.txt file for you. output = open(ouput.txt,a+) #The format of text is unicode. output.write(text.encode(utf-8)) output.close()
近段时间在读关于SFL(Systemic Functional Linguistics) 、CDA(Critical Discourse Analysis)、CL(Corpus-linguistics)及其与翻译相关的书籍,发现有很多定义不够明朗。 比如disourse一词,理解就很多种。 这里引述的是“ Key concepts in communication and cultural studies” (2nd edition) by: Montgomery, O’Sullivan, Hartley, Sauders, and Fiske (1994): discourse (adjective = discursive) * A term now quite widely used in a number of different disciplines and schools of thought, often with different purposes. Most uncontroversially, it is used in linguistics to refer to verbal utterances of greater magnitude than the sentence. * Discourse analysis is concerned not only with complex utterances by one speaker, but more frequently with the turn-taking interaction between two or more, and with the linguistic rules and conventions that are taken to be in play and governing such discourses in their given context. However, the concept of discourse has also developed, separately, out of post- structuralism and semiotics . Here it really represents an attempt to fix, within one term, some of the theoretical ground gained in the early days of the structuralist enterprise. To grasp its significance you have to remember that in this early period structuralism/semiotics was above all an oppositional intellectual force, whose proponents were attempting to criticize and transform the inherited habits of thought and analysis about the question of where meaning comes from. Traditionally, and even now most ‘obviously’, meaning was ascribed to objects ‘out there’ in the world, and to the inner essences and feelings of individuals. Structuralism took issue with these ideas, insisting that meaning is an effect of signification , and that signification is a property not of the world out there nor of individual people, but of language . It follows that both the world out there and individual consciousness are themselves comprehensible only as products, not sources, of language/signification. We are what we say, and the world is what we say it is. But the problem with this conclusion is that it is too free-floating and abstract; it gives the impression that – not only in principle but also in practice – the world and the word can mean whatever we like. Life isn’t so simple. The abstract concept of ‘language’ proved inadequate to account for the historical, political and cultural ‘fixing’ of certain meanings, and their constant reproduction and circulation via established kinds of speech, forms of representation, and in particular institutional settings. This is the point at which the concept of discourse began to supplant the now flabby and imprecise notion of ‘language’. Unlike ‘language’, the term discourse itself is both a noun and a verb. So it is easier to retain the sense of discourse as an act, where the noun ‘language’ often seems to refer to a thing. In its established usages, discourse referred both to the interactive process and the end result of thought and communication. Discourse is the social process of making and reproducing sense(s). Once taken up by structuralism, largely through the writings of Michel Foucault, the concept of discourse proved useful to represent both a very general theoretical notion and numbers of specific discourses. The general theoretical notion is that while meaning can be generated only from the langue or abstract system of language, and while we can apprehend the world only through language systems, the fact remains that the resources of language-in-general are and always have been subjected to the historical developments and conflicts of social relations in general. In short, although langue may be abstract, meaning never is. Discourses are the product of social, historical and institutional formations, and meanings are produced by these institutionalized discourses. It follows that the potentially infinite senses any language system is capable of producing are always limited and fixed by the structure of social relations which prevails in a given time and place, and which is itself represented through various discourses. Thus individuals don’t simply learn languages as abstract skills. On the contrary, everyone is predated by established discourses in which various subjectivities are represented already – for instance, those of class , gender , nation, ethnicity, age, family and individuality. We establish and experience our own individuality by ‘inhabiting’ numbers of such discursive subjectivities (some of which confirm each other; others however coexist far from peacefully). The theory of discourse proposes that individuality itself is the site, as it were, on which socially produced and historically established discourses are reproduced and regulated. Once the general theoretical notion of discourse has been achieved, attention turns to specific discourses in which socially established sense is encountered and contested. These range from media discourses like television and news, to institutionalized discourses like medicine, literature and science. Discourses are structured and interrelated; some are more prestigious, legitimated and hence ‘more obvious’ than others, while there are discourses that have an uphill struggle to win any recognition at all. Thus discourses are power relations. It follows that much of the social sense-making we’re subjected to – in the media, at school, in conversation –is the working through of ideological struggle between discourses: a good contemporary example is that between the discourses of (legitimated, naturalized) patriarchy and (emergent, marginalized) feminism. Textual analysis can be employed to follow the moves in this struggle, by showing how particular texts take up elements of different discourses and articulate them (that is, ‘knit them together’). However, though discourses may be traced in texts , and though texts may be the means by which discursive knowledges are circulated, established or suppressed, discourses are not themselves textual. Further reading For discourse analysis in linguistics see Coulthard and Montgomery (eds) (1981) 看来,对discourse的探讨,可以涉及到社会文化维度的分析。 Fowler把话语视为个人有意识进入意识形态、经验和社会组织的语言工具。 (待续)