Ser1ousSAM

cut_str

Jul 9th, 2023
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. file_path = '1.txt'
  2. with open(file_path, 'r', encoding="utf8") as file, open('1_NEW.txt', 'w', encoding="utf8") as new_file:
  3. for line in file:
  4. line = line.strip()
  5. if line and len(line) <= 50:
  6. new_file.write(line + '\n')
  7. elif len(line) > 50:
  8. new_line = line[:50]
  9. new_file.write(new_line + '\n')
  10.  
  11. print("Nice")
Advertisement
Add Comment
Please, Sign In to add comment