Python 从sketch中读取文件

=============================== RESTART: Shell ===============================
>>> import os
>>> os.getcwd()
‘C:\\Windows\\System32‘
>>> os.chdir(‘C:/Users/eric/Documents/Python‘)
>>> os.getcwd()
‘C:\\Users\\eric\\Documents\\Python‘
>>> data = open (‘sketch.txt‘)
>>> print (data.readline(),end=‘‘)
Man: Is this the right room for an argument?
>>> print (data.readline(),end=‘‘)
Other Man: I‘ve told you once.
>>> data.seek(0)
0
>>> for each_line in data:
	print(each_line, end=‘‘)

Man: Is this the right room for an argument?
Other Man: I‘ve told you once.
Man: No you haven‘t!
Other Man: Yes I have.
Man: When?
Other Man: Just now.
Man: No you didn‘t!
Other Man: Yes I did!
Man: You didn‘t!
Other Man: I‘m telling you, I did!
Man: You did not!
Other Man: Oh I‘m sorry, is this a five minute argument, or the full half hour?
Man: Ah! (taking out his wallet and paying) Just the five minutes.
Other Man: Just the five minutes. Thank you.
Other Man: Anyway, I did.
Man: You most certainly did not!
Other Man: Now let‘s get one thing quite clear: I most definitely told you!
Man: Oh no you didn‘t!
Other Man: Oh yes I did!
Man: Oh no you didn‘t!
Other Man: Oh yes I did!
Man: Oh look, this isn‘t an argument!
(pause)
Other Man: Yes it is!
Man: No it isn‘t!
(pause)
Man: It‘s just contradiction!
Other Man: No it isn‘t!
Man: It IS!
Other Man: It is NOT!
Man: You just contradicted me!
Other Man: No I didn‘t!
Man: You DID!
Other Man: No no no!
Man: You did just then!
Other Man: Nonsense!
Man: (exasperated) Oh, this is futile!!
(pause)
Other Man: No it isn‘t!
Man: Yes it is!
>>> data.close()
>>>
时间: 2024-08-02 14:48:12

Python 从sketch中读取文件的相关文章

python 按每行读取文件怎么去掉换行符

python按每行读取文件后,会在每行末尾带上换行符,这样非常不方便后续业务处理逻辑,需要去掉每行的换行符,怎么去掉呢?看下面的案例: >>> a = "hello world\n" >>> print a #可以看到hello world下面空了一格 hello world >>> a.split() #通过split方法将字符转换成列表 ['hello', 'world'] #从列表中取第一个字符 >>> a.

【Python】按行读取文件、IOError: [Errno 22] invalid mode ('a+') or filename,处理文件的换行符

Python一次性读取文件的所有内容在<[Python]文件读写操作>(点击打开链接)中已经说明过的,但有些时候,需要对文件中的每一行进行处理. 比如有一个f:\1.txt如下: 此时,如果要按行读取这个文件,可以直接利用Pyhon的for循环来读取,其中for的对象是这个文件指针,代码如下: file_path="f:\\a.txt" fp=open(file_path,"a+"); for eachline in fp: print eachline

文件_ _android从资源文件中读取文件流并显示的方法

======== 1   android从资源文件中读取文件流并显示的方法. 在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来,放到屏幕中显示,可以这样: private void doRaw(){ InputStream is = this.getResources().openRawResource(R.raw.ziliao); try{ doRead(is); }catch(IOException e){ e.printStackTrace(); } } pri

PHP中读取文件的几个方法

整理了一下PHP中读取文件的几个方法,方便以后查阅. 1.fread string fread ( int $handle , int $length ) fread() 从 handle 指向的文件中读取最多 length 个字节.该函数在读取完最多 length 个字节数,或到达 EOF 的时候,或(对于网络流)当一个包可用时,或(在打开用户空间流之后)已读取了 8192 个字节时就会停止读取文件,视乎先碰到哪种情况. fread() 返回所读取的字符串,如果出错返回 FALSE. <?ph

[笨木头Unity3D]杂记003&#183;Unity在Android中读取文件

这周被一个问题给折腾了几个晚上,那就是在Android中读取文件,这本是一件很简单的事情,可想象总是美好的. 笨木头花心贡献,啥?花心?不,是用心. 转载请注明,原文地址:http://www.benmutou.com/archives/2094 文章来源:笨木头与游戏开发 1.在电脑上读取文件 首先要解决的当然是在电脑上读取文件了,这个并不难,网上一堆资料. 比如: public static string LoadFile(string filePath) { string url = Ap

Java中读取文件

Java中读取文件,去除一些分隔符,保存在多维数组里面 1 public void readFile(String filePath) 2 { 3 File file=new File(filePath); 4 ArrayList<String[]> dataArray=new ArrayList<String[]>(); 5 try{ 6 String str=new String(); 7 BufferedReader in=new BufferedReader(new Fil

R中读取文件,找不到路径问题 No such file or directory

  R中读取文件,找不到路径问题 No such file or directory 近日,读取文件时.出现例如以下问题 > passenger = read.csv('international-airline-passengers.csv',sep=',') Error in file(file, "rt") : 无法打开链结 此外: Warning message: In file(file, "rt") : 无法打开文件'international-a

用adb pull命令从android系统中读取文件失败的原因及解决办法

问题:使用adb pull命令从android系统中读取文件失败.显示:Permission denied 原因:是由于文件权限原因引起. 使用ls -l命令查看android系统中的文件权限为: -rw-rw---- app_51   app_51 也就是说,该文件只有app_51用户以及app_51群组拥有读写权限,而adb shell的用户为shell,既不是app_51用户,也不在app_51群组中,所以没有权限读取这个文件.所以就出现了 Permission denied. 解决方法:

android 从assets和res中读取文件

11. assets文件夹资源的访问 assets文件夹里面的文件都是保持原始的文件格式,需要用AssetManager以字节流的形式读取文件. 1. 先在Activity里面调用getAssets()来获取AssetManager引用. 2. 再用AssetManager的open(String fileName, int accessMode)方法则指定读取的文件以及访问模式就能得到输入流InputStream. 3. 然后就是用已经open file 的inputStream读取文件,读取