Advertisement
koulin

files

Jul 11th, 2024
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. def task_1(name):
  2.     with open(name) as f:
  3.         return f.read()
  4.    
  5.    
  6. def task_2(name):
  7.     with open(name) as f:
  8.         return f.readline()
  9.  
  10. def task_3(name):
  11.     with open(name) as f:
  12.         return f.readlines()
  13.    
  14. def task_4(name):
  15.     with open(name) as f:
  16.         return [x.strip() for x in f]
  17.  
  18. def task_5(name):
  19.     with open(name) as f:
  20.         for x in f:
  21.             print(x,end = '')
  22.  
  23. def task_6(name):
  24.     with open(name) as f:
  25.         data = [x.strip() for x in f]
  26.     return ' '.join(data)
  27.  
  28. def task_7(string):
  29.     return string.strip()
  30.  
  31.  
  32. def task_8(string,symbols):
  33.     return string.rstrip(symbols)
  34.  
  35. def task_9(name, string):
  36.     with open(name,"w") as f:
  37.         f.write(string)
  38.     return f'строка {string} записана в файл'
  39.  
  40. def task_10(name, string):
  41.     with open(name, "w") as f:
  42.         f.write(string + '\n')
  43.     return f'строка {string} записана в файл'
  44.  
  45. def task_11(name, string_list):
  46.     with open(name, "w") as f:
  47.         [f.write(x) for x in string_list]
  48.     return f'строки записаны в файл'
  49.  
  50. def task_12(read_file, write_file):
  51.     with open(read_file, "r") as f:
  52.         with open(write_file, "w") as g:
  53.             for line in f:
  54.                 print(line,file = g)
  55.  
  56. def task_13(read_file, write_file, start_string, end_string):
  57.     with open(read_file, "r") as f:
  58.         with open(write_file, "w") as g:
  59.             for line in f:
  60.                 if line.startswith(start_string) and line.endswith(end_string):
  61.                     g.write(line)
  62.  
  63.  
  64. def task_14(name):  
  65.     dictionary = dict()
  66.     with open(name,'r',encoding= 'utf-8') as f:
  67.         data = f.readlines()
  68.         for line in data[1:]:
  69.             array = line.split()
  70.             dictionary[array[0]] = (array[1],array[2])
  71.     return dictionary
  72.  
  73.  
  74.            
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement