Create A List Out Of File Contents With Item Per Line In Python

1. instructions

def client_list():
with open("clients.txt", mode="rt", encoding="utf-8") as client_file:
return [line.strip() for line in client_file.readlines()]
  • 2 new string-object methods to memorize
  1. <file>.readlines() reads lines from a file and passes them into a list
  2. <str>.string() strips the string from special character such as \n

2. sources

--

--

--

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Useful Python Tips + Tricks

Exclude approver from FYI mails

Legacy Modernization- Process of creating an easy-to-use UI and Integrating with API in a Mendix…

Legacy Modernization- Process of creating an easy to use UI and Integrating with API in a Mendix Application

A Front-end’s Mentoring Diary

Mindfulness App: How to Analyse User Behaviour Using Google Firebase Events Data

GSoC 2019 — Community Bonding Period

Real-time BGP Data Processing [1]: BMP and OpenBMP

How Kubernetes is used in Industries and what all use cases are solved by Kubernetes?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

More from Medium

The Parameters And Usage Of Ranges In Python

Reverse-Engineered “Wordle” with 10 lines of Python

6 Ways You Can Get Keys From a Python Dictionary

10 Useful String Operations in Python