The Most Effective Way to Slurp All STDINs to a String

I am writing an email parser for python 2.7 that will be called via sendmail using an alias, parsed using the email module, and then processed and stored in the oracle database:

From / etc / aliases:

myalias: | / my / python / script.py

I had the problem of "plundering" all stdin into a string object that I can use with the email module:

import email

# Slurp stdin and store into message
message =

msg = email.message_from_string(message)

# Do something with it
print msg['Subject']

What would be the most effective way to do this? I tried stdin.readlines (), but it gets on the list.

. (, noobish... perl python, script. "", - , , )

+4
1

sys.stdin.readlines() . () , sys.stdin.read().

+8

Source: https://habr.com/ru/post/1547483/


All Articles