Asked  6 Months ago    Answers:  5   Viewed   40 times

I want to create a Python program which takes in multiple lines of user input. For example:

This is a multilined input.
It has multiple sentences.
Each sentence is on a newline.

How can I take in multiple lines of raw input?

 Answers

33
sentinel = '' # ends when this string is seen
for line in iter(raw_input, sentinel):
    pass # do things here

To get every line as a string you can do:

'n'.join(iter(raw_input, sentinel))

Python 3:

'n'.join(iter(input, sentinel))
Tuesday, June 1, 2021
 
Rocket
answered 6 Months ago
62

The following works for Python 3:

from PIL import Image
import requests

im = Image.open(requests.get(url, stream=True).raw)

References:

  • https://github.com/python-pillow/Pillow/pull/1151
  • https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst#280-2015-04-01
Tuesday, June 1, 2021
 
vuliad
answered 6 Months ago
17

You can use xlrd.

From its documentation, you can read that dates are always stored as numbers; however, you can use xldate_as_tuple to convert it to a python date.

Note: the version on the PyPI seems more up-to-date than the one available on xlrd's website.

Tuesday, June 8, 2021
 
NewPHP
answered 6 Months ago
69

You can use str.isdigit and str.isalpha:

if a.isalpha():
   #do something
elif a.isdigit():
   #do something

help on str.isdigit:

>>> print str.isdigit.__doc__
S.isdigit() -> bool

Return True if all characters in S are digits
and there is at least one character in S, False otherwise.

help on str.isalpha:

>>> print str.isalpha.__doc__
S.isalpha() -> bool

Return True if all characters in S are alphabetic
and there is at least one character in S, False otherwise.
Thursday, July 29, 2021
 
treeface
answered 4 Months ago
79

You need to use

return getNum(numList)

instead of

getNum(numList)

in the getNum function. The reason is that you call the getNum function recursively, thus you have to return the accepted value back through all recursions you made. Additionally, you must pass the arguments to each call.

Saturday, August 7, 2021
 
Sugrue
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share