Telegram Group & Telegram Channel
Чтобы читать строки из stdin в Python до версии 3, использовалась функция raw_input вместо input. Проблема с использованием input заключалась в том, что она выполняла введённую строку как код:


$ echo '[x ** 2 for x in range(10)]' | python2 -c 'print input()'
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]


В Python 3 функция input просто читает строку, а raw_input больше не существует.

Если вы хотите поддерживать код, работающий как в Python 2, так и в Python 3, можно использовать следующий подход:


from contextlib import suppress

with suppress(NameError):
input = raw_input


Популярный модуль six уже реализует этот механизм для вас. Он предоставляет функцию input, которая просто читает строку, независимо от версии Python.

👉@BookPython



tg-me.com/BookPython/3470
Create:
Last Update:

Чтобы читать строки из stdin в Python до версии 3, использовалась функция raw_input вместо input. Проблема с использованием input заключалась в том, что она выполняла введённую строку как код:


$ echo '[x ** 2 for x in range(10)]' | python2 -c 'print input()'
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]


В Python 3 функция input просто читает строку, а raw_input больше не существует.

Если вы хотите поддерживать код, работающий как в Python 2, так и в Python 3, можно использовать следующий подход:


from contextlib import suppress

with suppress(NameError):
input = raw_input


Популярный модуль six уже реализует этот механизм для вас. Он предоставляет функцию input, которая просто читает строку, независимо от версии Python.

👉@BookPython

BY Библиотека Python разработчика | Книги по питону


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/BookPython/3470

View MORE
Open in Telegram


Библиотека Python разработчика Telegram | DID YOU KNOW?

Date: |

What is Telegram Possible Future Strategies?

Cryptoassets enthusiasts use this application for their trade activities, and they may make donations for this cause.If somehow Telegram do run out of money to sustain themselves they will probably introduce some features that will not hinder the rudimentary principle of Telegram but provide users with enhanced and enriched experience. This could be similar to features where characters can be customized in a game which directly do not affect the in-game strategies but add to the experience.

Telegram today rolling out an update which brings with it several new features.The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations.

Библиотека Python разработчика from us


Telegram Библиотека Python разработчика | Книги по питону
FROM USA