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.

Installation

pip install spitslurp

Usage

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')

TODO

  • 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.

Source Distribution

spitslurp-0.4.tar.gz (1.7 kB view details)

Uploaded Source

File details

Details for the file spitslurp-0.4.tar.gz.

File metadata

  • Download URL: spitslurp-0.4.tar.gz
  • Upload date:
  • Size: 1.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for spitslurp-0.4.tar.gz
Algorithm Hash digest
SHA256 1249fc66a4ffc2da15b11bc4c9e41c45519f7fdcbcddf4c0c3137d31d1415103
MD5 462e75a4c0e9ca28ce73bf9bb05b5c3a
BLAKE2b-256 ae6572b918c2672b0ddc048cad6260bca463fc1cff99175913769f9a17251c77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page