Skip to content

Instantly share code, notes, and snippets.

@UlvacMoscow
Created March 21, 2019 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UlvacMoscow/d85d5335b40d021632280dd93af94768 to your computer and use it in GitHub Desktop.
Save UlvacMoscow/d85d5335b40d021632280dd93af94768 to your computer and use it in GitHub Desktop.
Ulvac created by Ulvac - https://repl.it/@Ulvac/Ulvac
import os
from datetime import datetime as dt
import time
#примеры с переводо времени в дату и обратно
#http://kamedov.ru/preobrazovanie-daty-v-python-iz-datetime-v-time/
files = 'files'
current_dir = os.path.dirname(os.path.abspath(__file__))
folder_files_way = os.path.join(current_dir, files)
files_list = os.listdir(folder_files_way)
print(current_dir)
print(folder_files_way)
print(files_list)
for file in files_list:
temp = os.path.join(folder_files_way, file)
timestamp = os.stat(temp).st_ctime
print('--------------------------------')
print(temp)
print(os.stat(temp))
print(timestamp)
# print(date(os.stat(temp).st_ctime))
print(dt.fromtimestamp(os.stat(temp).st_ctime).strftime("%Y %m, %d"))
print('--------------------------------')
dt_obj = dt.fromtimestamp(timestamp)
print(dt_obj)
print(repr(dt_obj))
print('--------------------------------')
time_tuple = time.gmtime(timestamp)
print(time_tuple)
print(repr(time_tuple))
print('--------------------------------')
with open(os.path.join(folder_files_way, file), encoding='utf8') as info:
# print(info.read())
text = info.read()
# print(text)
from datetime import datetime
# декораторы
def timeit(arg):
print(arg)
def outer(func):
def wrapper(*args, **kwargs):
start = datetime.now()
result = func(*args, **kwargs)
print(datetime.now() - start)
return result
return wrapper
return outer
@timeit('name')
def one(n):
lst = []
for i in range(n):
if i % 2 == 0:
lst.append(i)
return lst
@timeit('name')
def two(m):
lst = [x for x in range(m) if x % 2 == 0]
return lst
li = timeit('name')(one)(10)
# shops_in_city = 1
def city(shops_in_city):
if shops_in_city > 10 and shops_in_city < 15:
print("{}.салонов".format(shops_in_city))
shops_plural=2
elif shops_in_city % 10 == 1:
#1 салон, 21 салон
print("{}.салон".format(shops_in_city))
elif shops_in_city % 10 in [2,3,4]:
#2 салона, 3 салона, 4 салона,
print("{}.салона".format(shops_in_city))
else: #5 5-20 саловнов
print("{}.салонов".format(shops_in_city))
for x in range(50):
city(x)
# print(range(50))
# print(3%10 in [2,3,4])
@UlvacMoscow
Copy link
Author

simple examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment