я хочу получить это Текст представлен в виде образца, подобного этому
Этот:
hello all my name nora
так:
nora name my all hello
Конечно, важным моментом является то, что это не только для одного текста, мне нужно, чтобы несколько текстов появлялись таким образом одновременно, спасибо.
если это возможно с помощью Regex в блокноте++ или инструменте, буду благодарен. Спасибо 🙏🙏
🤔 А знаете ли вы, что...
Python является интерпретируемым языком программирования.
Я не слышал о таком инструменте. Однако я создал эту простую программу. Его можно запускать в разных ОС. Просто введите имена файлов, строки из которых вы хотите перевернуть, и весь файл (каждая строка своя) будет перевернут.
например
файл.txt
consequat quis nostrud exercitation ullamco laboris nisi ut aliquip
sunt in culpa qui officia deserunt mollit anim id est laborum
eu fugiat nulla pariatur Excepteur sint occaecat cupidatat non proident
например (после запуска программы)
файл.txt
aliquip ut nisi laboris ullamco exercitation nostrud quis consequat
laborum est id anim mollit deserunt officia qui culpa in sunt
proident non cupidatat occaecat sint Excepteur pariatur nulla fugiat eu
исходный код программы и использование:
Сохраните этот фрагмент программы в файле .py (например, script.py). Затем на вашем терминале:
import argparse
import os
def reverse_sentences_in_file(input_file):
# Read the file
with open(input_file, 'r') as file:
lines = file.readlines()
# Process each line
reversed_lines = []
for line in lines:
# Strip newline characters and split the line into words
words = line.strip().split()
# Reverse the order of words
reversed_words = words[::-1]
# Join the reversed words back into a sentence
reversed_line = ' '.join(reversed_words)
# Append the reversed sentence to the list
reversed_lines.append(reversed_line)
# Write the reversed sentences back to the same file
with open(input_file, 'w') as file:
for reversed_line in reversed_lines:
file.write(reversed_line + '\n')
def main():
# Setup argument parser
parser = argparse.ArgumentParser(description = "Reverse sentences in multiple files.")
parser.add_argument('files', metavar='F', type=str, nargs='+', help='a list of files to process')
# Parse arguments
args = parser.parse_args()
# Reverse sentences in each file
for input_file in args.files:
if os.path.isfile(input_file):
reverse_sentences_in_file(input_file)
print(f"Reversed sentences have been written to {input_file}.")
else:
print(f"File {input_file} does not exist.")
if __name__ == '__main__':
main()
использование приложения:
python script.py name_of_the_file_you_want_to_reverse.txt