Форум сайта python.su
О боже, пора уже гдето закрепить(может в названии ветки?), что код нужно заключать в теги
[code python]
Тут пишем код
[/code]
[code python][/code]
Отредактировано PEHDOM (Июнь 14, 2017 09:58:05)
Офлайн
Доброго времени суток, форумчане!
Сейчас изучаю операции над множествами по книге Марка Саммерфилда и в процессе столкнулся с такой проблемкой, что фактический результат выполнения кода интерпретатором отличается от ожидаемого. Не пойму, в чем дело. Подскажите, где я накосячил.
set_1 = {'pecan'} set_2 = {'pie'} print(type(set_1)) print(type(set_2)) print('Исходное множество set_1: {0}'.format(set_1)) print('Исходное множество set_2: {0}'.format(set_2)) union = set_1 | set_2 # Объединение intersection = set_1 & set_2 # Пересечение difference = set_1 - set_2 # Разность symmetric_difference = set_1 ^ set_2 # Строгая дизъюнкция (исключающее ИЛИ) print('Объединение: ', union) print('Пересечение: ', intersection) print('Разность: ', difference) print('Исключающее ИЛИ: ', symmetric_difference) print(set_1.difference(set_2))
Отредактировано citizen404 (Июнь 15, 2017 13:07:45)
Офлайн
Попробуй так
set_1 = set('pecan') set_2 = set('pie')
Офлайн
krok64
Попробуй так
Офлайн
citizen404
Дело не в пустом множестве, а в том, что если вам нужно множество, состоящее из одного СЛОВА, вы делаете так
{"СЛОВО"}
set("abc") == set(["a", "b", "c"])
Офлайн
Всем привет!
import telebot TOKEN = 'пример токена' bot = telebot.TeleBot(TOKEN) @bot.message_handler(commands=['start']) def start(message): sent = bot.send_message(message.chat.id, 'Привет, как тебя зовут?') bot.register_next_step_handler(sent, hello) def hello(message): bot.send_message( message.chat.id, 'Привет, {name}. Как ты?'.format(name=message.text) bot.polling()
Отредактировано Lamptop (Июнь 18, 2017 23:09:43)
Офлайн
bot.send_message( message.chat.id, 'Привет, {name}. Как ты?'.format(name=message.text)
Офлайн
Все та же ошибка. SyntaxError: multiple statements found while compiling a single statement. После import telebot красная полоса в IDLE
Прикреплённый файлы: Безымянный.png (41,9 KБ)
Офлайн
Lamptop
Дайте догадаюсь. Вы взяли чей-то код, скопировали его и вставили в IDLE?
Тут только один совет может быть - не используйте IDLE, это не настоящая ИДЕ. На вопрос “а что же использовать?” - идите в гугл.
Офлайн
Попытался установить модуль, вылез вот-такой кульверштукас. Заранее спасибо за помощь
sudo pip install pyaudio
sudo: unable to resolve host hatifnat
password for ivan:
The directory ‘/home/ivan/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory ‘/home/ivan/.cache/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pyaudio
Downloading PyAudio-0.2.11.tar.gz
Installing collected packages: pyaudio
Running setup.py install for pyaudio … error
Complete output from command /usr/bin/python -u -c “import setuptools, tokenize;__file__='/tmp/pip-build-nqaQ2r/pyaudio/setup.py';f=getattr(tokenize, ‘open’, open)(__file__);code=f.read().replace('\r\n', ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record /tmp/pip-k_99RO-record/install-record.txt –single-version-externally-managed –compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying src/pyaudio.py -> build/lib.linux-x86_64-2.7
running build_ext
building ‘_portaudio’ extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
compilation terminated.
error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1
—————————————-
Command “/usr/bin/python -u -c ”import setuptools, tokenize;__file__='/tmp/pip-build-nqaQ2r/pyaudio/setup.py';f=getattr(tokenize, ‘open’, open)(__file__);code=f.read().replace('\r\n', ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))“ install –record /tmp/pip-k_99RO-record/install-record.txt –single-version-externally-managed –compile” failed with error code 1 in /tmp/pip-build-nqaQ2r/pyaudio/
ivan@hatifnat:~$
Офлайн