open 只能打开.txt文件
with open('/Users/guohao/Desktop/hello.txt','r') as f: print(f.read())
mac显示桌面快捷键 command+F3
https://jingyan.baidu.com/article/915fc414f232e651394b202c.html
笔记:新买了一本爬虫书,前面是python的基础知识,复习了下,发现还有好多不会呀,IO编程,进程和线程,今天复习了这么多
#!/usr/bin/env python3 # -*-coding:utf-8 -*- # Author:Uncle_guo # IO 编程 # with open('/Users/guohao/Desktop/hello.txt',mode='r',encoding='utf-8') as f: # print(f.read()) # try: # f=open('/Users/guohao/Desktop/hello.txt','r') # print(f.read()) # finally: # if f: # f.close() # with open('/Users/guohao/Desktop/hello.txt','r') as f: # for line in f.readlines(): # print(line.strip().split()) # 序列化 # # try: # import cPickle as pickle # except ImportError: # import pickle # d={'url':'index.html','http':'首页','content':'首页'} # with open(r'/Users/guohao/Desktop/hello.txt','wb') as f: # pickle.dump(d,f) # print(pickle.dumps(d)) # with open(r'/Users/guohao/Desktop/hello.txt','rb') as f: # d=pickle.load(f) # print(d) # 多进程 # fork multiprocessing # fork:getpid ,gettpid # print(os.getpid()) #print(os.fork())#调用一次返回两次,子进程始终返回0,父进程返回子进程的ID #getpid 获取当前进程ID,gettpid 获取父进程ID # import os # if __name__=='__main__': # print('父进程(%s)开始启动。。。'%(os.getpid())) # pid=os.fork() # if pid<0: # print('Error') # elif pid==0: # print('我是子进程(%s),我的父进程是(%s)'%(os.getpid(),os.getppid())) # else: # print('我(%s)是(%s)的父进程'%(os.getpid(),pid)) # #%s # name='Uncle_Guo' # age=22 # study1='易语言' # study2='Html' # study3='Python' # print('我的名字是(%s),今年(%s)岁,我学过(%s)、(%s)、(%s)'%(name,age,study1,study2,study3))