Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions razzl/0004/0004.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'''
It can caculate the words in the text file
'''

import re
def calculate_words(path):
f = open(path,'r')
lines = f.readlines()
count = 0
for line in lines:
count+=len(re.split('[,.! ?:]',line))#use the re module to split the txt file
return count-len(lines)#the txt file will inlcude the '\n' and '' so sub it

words = calculate_words("C:/Users/razzl/Desktop/1.txt")#in python the '/' can be the path separator in all system
print words
22 changes: 22 additions & 0 deletions razzl/0005/0005.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'''
It can resize the photos in a file
'''

import os
from PIL import Image

def resize_photo(source_dir,width,higth,destination_dir):
photos = os.listdir(source_dir)
for photo in photos:
photo_abspath = os.path.join(source_dir,photo)#if you use os.path.abspath,there may be some error
print photo_abspath
if(os.path.isfile(photo_abspath)):#os.path.isfile need a abspath
im = Image.open(photo_abspath)
#w,h = im.size
new_im = im.resize((width,higth))#note: the resize returns a resized copy of an image , so you need a new object to save it
destination_path = os.path.join(destination_dir,photo)
new_im.save(destination_path)
print destination_path
resize_photo('C:/Users/razzl/Desktop/1',800,800,'C:/Users/razzl/Desktop/2')