Вторая по частоте future-функция, которую я использовал, это абсолютный импорт
from __future__ import absolute_import
Что она делает?
Изменения, которые вносит эта инъекция описаны в PEP328
Покажу простой пример.
Допустим, есть такой пакет:
/my_package
/__init__.py
/main.py
/string.py
Смотрим код в my_package/main.py
# main.py
import string
Простой пример готов) Вопрос в том, какой модуль импортируется в данном случае? Есть два варианта:
1. модуль в моём пакете my_package.string
2. стандартный модуль string
И вот тут вступает в дело приоритет импортов. В Python2 порядок следующий: помимо иных источников, раньше ищется модуль внутри текущего пакета, а потом в стандартных библиотеках. Таким образом мы импортнём my_package.string.
Но в Python3 это поведение изменилось. Если мы указываем просто имя пакета, то ищется именно такой модуль, игнорируя имена в текущем пакете. Если мы хотим импортнуть именно подмодуль из нашего пакета то, мы должны теперь явно это указывать.
from my_package import string
или относительный импорт, но с указанием пути относительно текущего модуля main
from . import string
Еще одной неоднозначностью меньше 😎
Подробней про импорты здесь:
https://docs.python.org/3/tutorial/modules.html
#2to3#pep#basic
Updated @RulesRulesBot:
Bringing you some much requested features:
- It is now possible to get the last set rules or welcome text with /getgreeting and /getrules. That way you don't have to recreate all the HTML formatting, but can copy, paste and edit.
- It will delete old messages (greetings and rules) after more than 5 minutes. Not always exactly 5 minutes, as the cleanup job might not run every minute.
- If you grant admin rights to delete messages to the bot, it will also clean up any /rules and /greet command messages when deleting the sent message that.
#update#RulesRulesBot
Updated@RulesRulesBot:
Will now check for syntax error regarding variable usage when you set new rules or greeting text.
If you have an error there, it is most likely because you wanted to use "{" or "}" in your text. It will now tell you that you can use {{ or }} to display those.
Note that HTML errors where Telegram doesn't accept the message still can't be checked as the bot doesn't send the text immediately.
#update#RulesRulesBot
Updated @BanWarnBot, added {user_id}, {user_url} and {user_link} variables. This way you can link the user. This is also the new default replacing the bold text, in case you did't set any greeting.
#RulesRulesBot#update
New beta feature for @RulesRulesBot:
Read-the-Rules Highscores.
When enabled with /enable_highscores@RulesRulesBot,
the bot will send a game message to your chat which allows the bot to send highscores if somebody reads the rules, who hasn't before or hasn't after a change in the rules.
This might engage reading the rules more, and provide an overview for admins if joined users clicked the rules links.
If you don't like it, just send /disable_highscores@RulesRulesBot, and delete the game message.
Note, the game message is needed for telegram to notify about changed highscores. If the message got accidentially deleted, it can be recreated with /enable_highscore@RulesRulesBot command, which will also restore the scores.
Screenshot: https://t.me/luckydonaldsbots/146
#RulesRulesBot#beta#update
It was brought to attention that with some bots admin commands were no longer working.
That was happining for the bots migrated yesterday, because of the new bot API version.
This is #fixed now.
Thanks for letting me know, A. A.!
#BanWarnBot#RulesRulesBot#JoinCaptchaBot
I will soon migrage some services onto a new server.
Therefore those services will be unavailable for the next two hours:
@JoinCaptchaBot@BanWarnBot@RulesRulesBot and @ForwardWhitelistBot.
#downtime
#JoinCaptchaBot#BanWarnBot#RulesRulesBot#ForwardWhitelistBot
I will definitely work hard to keep the most important group management services stable, including:
@JoinCaptchaBot, @RulesRulesBot, @BanWarnBot, and @HeyAdminBot. And for now also the less important @NoServiceBot.
#PermalinkBot#NoServiceBot#RulesRulesBot, #BanWarnBot#HeyAdminBot
#ongoing#issue