2017-10-30 mac_python_open

open 只能打開.txt文件html

with open('/Users/guohao/Desktop/hello.txt','r') as f:
    print(f.read())

 

 

mac顯示桌面快捷鍵 command+F3python

https://jingyan.baidu.com/article/915fc414f232e651394b202c.html編程

 

筆記:新買了一本爬蟲書,前面是python的基礎知識,複習了下,發現還有好多不會呀,IO編程,進程和線程,今天覆習了這麼多url

#!/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))
相關文章
相關標籤/搜索