This script reads a text file and converts its contents into a Python list.
- Save the script
text_to_python_list.pyto your local machine. - Run the script using Python.
- When prompted, enter the path to the text file you want to read.
def text_file_to_list(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
return [line.strip() for line in lines]
if __name__ == "__main__":
file_path = input("Enter the path to the text file: ")
result = text_file_to_list(file_path)
print(result)- Open a terminal or command prompt.
- Navigate to the directory where
text_to_python_list.pyis saved. - Run the script using the following command:
python text_to_python_list.py- Enter the path to your text file when prompted.
- Python 3.x
This project is licensed under the MIT License.