Skip to content

Commit

Permalink
Merge pull request geekcomputers#518 from Hong199/master
Browse files Browse the repository at this point in the history
Update fileinfo.py
  • Loading branch information
geekcomputers authored Aug 25, 2019
2 parents aa28162 + 86134a2 commit 18241e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
37 changes: 15 additions & 22 deletions fileinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,22 @@
if sys.version_info >= (3, 0):
raw_input = input

try_count = 16

while try_count:
file_name = raw_input("Enter a file name: ") # pick a file you have
fhand = open(file_name)
count = 0
for lines in fhand:
count = count + 1
fhand = open(file_name)
inp = fhand.read()
t_char = len(inp)
try_count >>= 1
try:
file_stats = os.stat(file_name)
print ("This is os.stat",file_stats)
break
except OSError:
print ("\nNameError : [%s] No such file or directory\n", file_name)

if try_count == 0:
print ("Trial limit exceeded \nExiting program")
file_name = raw_input("Enter a file name: ") # pick a file you have
count = 0
t_char = 0
try:
with open(file_name) as f:
line = f.readline()
t_char += len(line)
while line:
count += 1
line = f.readline()
t_char += len(line)
except FileNotFoundError as e:
print(e)
sys.exit()


file_stats = os.stat(file_name)
# create a dictionary to hold file info
file_info = {
'fname': file_name,
Expand Down
16 changes: 15 additions & 1 deletion scrap_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ def download(url):
f.close()
print("Succesfully Downloaded")

#Function is do same thing as method(download) do,but more strict
def download_2(url):
try:
response = requests.get(url)
except Exception:
print('Failed Download!')
else:
if response.status_code == 200:
with open('file_name.jpg','wb') as f:
f.write(requests.get(url).content)
print("Succesfully Downloaded")
else:
print('Failed Download!')

url='https://avatars0.githubusercontent.com/u/29729380?s=400&v=4' #URL from which we want to download

download(url)

0 comments on commit 18241e6

Please sign in to comment.