input = open(filepath,mode)
| 模式 | 作用 |
|---|---|
| r | 读取模式 |
| w | 写入模式 |
| a | 追加模式 |
| rb | 读取二进制数据模式打开文件 |
| wb | 写入二进制数据模式打开文件 |
input = open("/Users/sherlockblaze/Documents/pythonworkspace/Test.txt","r")
input = open("Test.txt","r")
input = open(r"d:\pythonworkspace\Test.txt","r")
input = open("d:\\pythonworkspace\\Test.txt","r")
def main():
input = open("Test.txt","w")
input.write("SherlockBlaze")
input.write("\t is the most handsome guy!\n")
input.close()
main()
import os.path
is os.paht.isfile("Test.txt"):
print("Test.txt exists")
else:
print("Test.txt doesn't exists")
def main():
filename = input("Enter a filename: ").strip()
infile = open(filename,"r")
counts = 26 * [0]
for line in infile:
countLetters(line.lower(),counts)
for i in range(len(counts)):
if counts[i] != 0:
print(chr(ord('a') + i) + "appears " + str(counts[i])
+ (" time" if counts[i] == 1 else " times"))
infile.close()
def countLetters(line,counts):
for ch in line:
if ch.isalpha():
counts[ord(ch) - ord('a')] += 1
main()
import sys
import urllib
import urllib.request
import os.path
def download(url,num_retries = 2):
print ('Downloading:',url)
try:
html = urllib.request.urlopen(url).read()
except urllib.URLError as e:
print ('Download error:',e.reason)
html = None
if num_retries > 0:
if hasattr(e,'code') and 500 <= e.code <600:
return download(url,num_retries-1)
return html
def main():
url = input("Enter a url:\n").strip()
f2 = input("Enter a target file:\n").strip()
if os.path.isfile(f2):
print(f2 + " already exists")
sys.exit()
html = download(url)
target = open(f2,"w")
content = html.decode(encoding="utf-8")
target.write(content)
target.close()
main()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有