Skip to main content

Write text to a file with `spit` and read from a file with `slurp`.

Project description

Write text to a file with spit and read from a file with slurp.

By default files are assumed to be encoded in UTF-8. You can specify an alternative encoding via the encoding keyword argument. For a full list of encodings see Standard Encodings.


pip install spitslurp


from spitslurp import spit, slurp

txt = u'Hello\nWorld'

# Write a unicode string to a file, by default encoded as UTF-8 and
# truncating the file prior to writing
spit('path/to/file.txt', txt)

txt = u'Hello\nLatin1'

# Append to a file (if it exists) and specify encoding as Latin 1
spit('path/to/file.txt', txt, append=True, encoding='latin1')

# Read the entire contents of a file into a unicode string. Assumes the
# file is in UTF-8 by default
txt = slurp('path/to/file.txt')

# Specify an encoding
txt = slurp('path/to/file.txt', encoding='latin1')


  • Moar tests

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for spitslurp, version 0.4
Filename, size File type Python version Upload date Hashes
Filename, size spitslurp-0.4.tar.gz (1.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page