forked from USTC-Resource/USTC-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct python typo for data structure
- Loading branch information
Showing
34 changed files
with
2,491 additions
and
1,805 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
# coding: utf-8 | ||
import os | ||
import sys | ||
|
||
|
||
def formatSize(size): | ||
s = 'BKMGTP' | ||
ct = 0 | ||
while size>=(1<<ct): | ||
ct+=10 | ||
if ct>=10: ct-=10 | ||
return '{sz:.2f}{a}'.format(sz=size/(1<<ct),a=s[ct//10]) | ||
while size >= (1 << ct): | ||
ct += 10 | ||
if ct >= 10: ct -= 10 | ||
return '{sz:.2f}{a}'.format(sz=size / (1 << ct), a=s[ct // 10]) | ||
|
||
|
||
def getSize(path='.'): | ||
if os.path.isdir(path): | ||
gen = os.walk(path) | ||
li = [] | ||
li = [] | ||
for root, dirs, files in gen: | ||
for f in files: | ||
sz = os.path.getsize(os.path.join(root ,f)) | ||
sz = os.path.getsize(os.path.join(root, f)) | ||
li.append(sz) | ||
#li.insert(('.',sum(i[1] for i in li)),0) | ||
#size = [f'{i[0]}: {formatSize(i[1])}' for i in li] | ||
return formatSize(sum(li)) | ||
else: | ||
return formatSize(os.path.getsize(path)) | ||
|
||
|
||
if __name__ == "__main__": | ||
items = sys.argv[1:] | ||
for i in items: | ||
print('{i}: {sz}'.format(i=i,sz =getSize(i))) | ||
print('{i}: {sz}'.format(i=i, sz=getSize(i))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import os | ||
|
||
def mywalk(dire,valid=lambda x:True): | ||
|
||
def mywalk(dire, valid=lambda x: True): | ||
if not os.path.isdir(dire): | ||
raise Exception('[Error]: directory excepted') | ||
dirs = [] | ||
files = [] | ||
for i in os.listdir(dire): | ||
i = os.path.join(dire,i) | ||
i = os.path.join(dire, i) | ||
if valid(i): | ||
if os.path.isdir(i): | ||
dirs.append(i) | ||
else: | ||
files.append(i) | ||
yield dire,dirs,files | ||
yield dire, dirs, files | ||
for d in dirs: | ||
yield from mywalk(os.path.join(dire,d),valid) | ||
yield from mywalk(os.path.join(dire, d), valid) |
Oops, something went wrong.