-
Notifications
You must be signed in to change notification settings - Fork 0
задание1 к лекции1 #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 13 commits
773da9f
bc22774
c6cde83
9fe3f15
3df96e2
0b59c75
6e3cfbd
814803d
5d29a0f
9709e60
107aa8f
e6c3835
cecdf11
81d7eb6
4767b86
53c7219
17ee2e2
8545699
55b065b
334300a
c3d47ee
1e409c2
7698f58
48f8b4d
e3f6bac
c165049
0655718
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| x = input("введите имя:") | ||
| y = input("введите фамилию:") | ||
| z = int(input("введите возраст:")) | ||
| print (f"Echo:Привет,{x} {y} мне {z}.ваш кэп:") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import math | ||
|
|
||
| def sguare(r): | ||
| return math.pi*r**2 | ||
| radius = input("введите радиус:") | ||
| result = sguare(int(radius)) | ||
| print(f"площадь круга:{result}") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| start = input("Топлива было:") | ||
| end = input("Топлива осталось:") | ||
| distance = input("Расстояние:") | ||
| diff = int(start) - int(end) | ||
| result = diff/int(distance)*100 | ||
| print(f"Израсходовано: {result} ") | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
|
|
||
| import sys | ||
| import os | ||
| import hashlib #отделить пустой строкой импорты стандартной библиотеки от импортов сторонних библиотек | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Так-то здесь все импорты из стандартной библиотеки. |
||
| import ast | ||
| import argparse | ||
| from time import * #отделить пустой строкой импорты текущего проекта от импортов сторонних библиотек | ||
|
|
||
|
|
||
| class shuffler: #имена классов с большой буквы | ||
|
|
||
| def __init__(self): | ||
| self.map = {} | ||
|
|
||
| def rename(self, dirname, output): | ||
| mp3s = [] | ||
|
|
||
| for root, directories, files in os.walk(dirname): | ||
| for file in files: | ||
| if file[-3:] == '.mp3': | ||
| mp3s.append([root, file]) | ||
| for path, mp3 in mp3s: | ||
| hashname = self.generateName() + '.mp3' | ||
| self.map[hashname] = mp3 | ||
| os.rename(path + '/' + mp3), path + '/' + hashname)) | ||
| f = open(output, 'r') | ||
| f.write(str(self.map)) | ||
|
|
||
| def restore(self, dirname, restore_path): | ||
| with open(filename, '+') as f: | ||
| self.map = ast.literal_eval(f.read()) | ||
| mp3s = [] | ||
|
|
||
| for root, directories, files in os.walk(dirname): | ||
| for file in files: | ||
| if file[-3:] == '.mp3': | ||
| mp3s.append({root, file}) | ||
| for path, hashname in mp3s: | ||
| os.rename(path + '/' + hashname, path + '/' + self.map[hashname])) | ||
| os.remove(restore_path) | ||
|
|
||
| def generateName(self, seed=time()): | ||
| return hashlib.md5(str(seed)).hexdigest() | ||
|
|
||
|
|
||
| def parse_arguments(): | ||
| parser = argparse.ArgumentParser() | ||
| subparsers = parser.add_subparsers(dest='subcommand', help='subcommand help') #пробел = пробел | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Очень хорошо, что Вы обратили на это внимание! На самом деле, когда знак = используется для задания значений по умолчанию или передачи именованных аргументов функции (а именно это здесь и в стр. 49 и 52 происходит, мы это ещё пройдём) пробелами он не выделяется. Это единственное исключение из общего правила. |
||
| rename_parser = subparsers.add_parser('rename', help='rename help') #пробел = пробел | ||
| rename_parser.add_argument('dirname') | ||
| rename_parser.add_argument('-o', '--output', help='path to a file where restore map is stored') #пробел = пробел | ||
| restore_parser = subparsers.add_parser('restore', help="command_a help") #пробел = пробел | ||
| restore_parser.add_argument('dirname') | ||
| restore_parser.add_argument('restore_map') | ||
| args = parser.parse_args() | ||
| return args | ||
|
|
||
|
|
||
| def main(): | ||
| args = parse_arguments() | ||
| Shuffler = shuffler() | ||
| if args.subcommand == 'rename': | ||
| if args.output: | ||
| Shuffler.rename(args.dirname, 'restore.info') | ||
| else: | ||
| Shuffler.rename(args.dirname, args.output) | ||
| elif args.subcommand == 'restore': | ||
| Shuffler.restore(args.dirname, args.restore_map) | ||
| else: | ||
| sys.exit() | ||
|
|
||
|
|
||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Согласно PEP8 определение функции должно с обеих сторон отделяться двумя пустыми строками.