DEV Community 👩‍💻👨‍💻

Sérgio Araújo
Sérgio Araújo

Posted on

Print A Random Phrase Using Python

Some days ago I shared a little shell script to chose a random paragraph
from a study text I have. Now let's see its version using python

#!/usr/bin/env python3
#  -*- coding: utf-8 -*-
#         vim: ai ts=4 sts=4 et sw=4
#    Filename:
#      Author: Sergio Araujo
#     Purpose: read a random paragraph from a file
# Last Change: mai 31 2019 19:02
#     Created: sex 31 mai 2019 18:47:16 -03
#       email: <voyeg3r ✉>
#      Github:
#     twitter: @voyeg3r
# sources: 

import random
import os

# clear the screen (I have used the os module just for the sake of cleaning the screen)
def cls():
    if == 'posix':


file = "/home/sergio/.dotfiles/nvim/wiki/"

par = open(file).read().split('\n\n')

# here I pick up a random paragraph (avoiding the two first paragraphs because they 
# are explanatory for the file and the last one wich contains tags)

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

🌚 Life is too short to browse without dark mode