426 ):
427 return
428 try:
429 from userbot.database.mutedb import mute430 except AttributeError:
431 await eventMute.edit("`Running on Non-SQL mode!`")
432 return
479 await eventUnMute.edit("`I am not an admin!`")
480 return
481 try:
482 from userbot.database.mutedb import unmute483 except AttributeError:
484 await eventUnMute.edit("`Running on Non-SQL mode!`")
485 return
557 await eventGmute.edit("`I am not an admin!`")
558 return
559 try:
560 from userbot.database.gmutedb import gmute561 except AttributeError:
562 await eventGmute.edit("`Running on Non-SQL mode!`")
563 return
75 return events.NewMessage(**args)
76
77
78async def is_read(bot, entity, message, is_out=None): 79 """
80 Returns True if the given message (or id) has been read
81 if a id is given, is_out needs to be a bool
145@bot.on(admin_cmd(pattern="logs"))
146async def _(dyno):
147 try:
148 Heroku = heroku3.from_key(Config.HEROKU_API_KEY)149 app = Heroku.app(Config.HEROKU_APP_NAME)
150 except BaseException:
151 return await dyno.reply(" Please make sure your Heroku API Key, Your App name are configured correctly in the heroku var")
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()