python-3.6

Sqlite3 cursors live updating?

孤者浪人 提交于 2019-12-02 01:04:46
Can someone please explain this to me: import sqlite3 db = sqlite3.connect(':memory:') db.execute('create table t1 (id integer primary key, val text)') db.execute('create table t2 (id integer primary key, val text)') c = db.cursor() c.execute('insert into t1 values (?, ?)', (1, 'a')) c.execute('insert into t2 values (?, ?)', (1, 'b')) c.execute('insert into t1 values (?, ?)', (2, 'c')) c.execute('insert into t2 values (?, ?)', (2, 'd')) c.execute('''select t1.id, t1.val, t2.val from t1 left join t2 using (id) where t1.id is not null union all select t2.id, t1.val, t2.val from t2 left join t1

Retrieving python 3.6 handling of re.sub() with zero length matches in python 3.7

痞子三分冷 提交于 2019-12-01 17:54:09
handling of zero length matches has changed with python 3.7. Consider the following with python 3.6 (and previous): >>> import re >>> print(re.sub('a*', 'x', 'bac')) xbxcx >>> print(re.sub('.*', 'x', 'bac')) x We get the following with python 3.7: >>> import re >>> print(re.sub('a*', 'x', 'bac')) xbxxcx >>> print(re.sub('.*', 'x', 'bac')) xx I understand this is the standard behavior of PCRE. Furthermore, re.finditer() seems to have always detected the additional match: >>> for m in re.finditer('a*', 'bac'): ... print(m.start(0), m.end(0), m.group(0)) ... 0 0 1 2 a 2 2 3 3 That said, I'm

Making a discord bot change playing status every 10 seconds

我怕爱的太早我们不能终老 提交于 2019-12-01 16:51:57
I'm trying to make the status for a test discord bot change between two messages every ten seconds. I need the rest of the script to execute while the status message changes, but an error keeps popping up whenever I try to make it work. There's threading in my script, but I'm not entirely sure how to use it in this circumstance. @test_bot.event async def on_ready(): print('Logged in as') print(test_bot.user.name) print(test_bot.user.id) print('------') await change_playing() @test_bot.event async def change_playing(): threading.Timer(10, change_playing).start() await test_bot.change_presence

Retrieving python 3.6 handling of re.sub() with zero length matches in python 3.7

耗尽温柔 提交于 2019-12-01 16:14:05
问题 handling of zero length matches has changed with python 3.7. Consider the following with python 3.6 (and previous): >>> import re >>> print(re.sub('a*', 'x', 'bac')) xbxcx >>> print(re.sub('.*', 'x', 'bac')) x We get the following with python 3.7: >>> import re >>> print(re.sub('a*', 'x', 'bac')) xbxxcx >>> print(re.sub('.*', 'x', 'bac')) xx I understand this is the standard behavior of PCRE. Furthermore, re.finditer() seems to have always detected the additional match: >>> for m in re

Making a discord bot change playing status every 10 seconds

若如初见. 提交于 2019-12-01 15:35:51
问题 I'm trying to make the status for a test discord bot change between two messages every ten seconds. I need the rest of the script to execute while the status message changes, but an error keeps popping up whenever I try to make it work. There's threading in my script, but I'm not entirely sure how to use it in this circumstance. @test_bot.event async def on_ready(): print('Logged in as') print(test_bot.user.name) print(test_bot.user.id) print('------') await change_playing() @test_bot.event

Why does the **kwargs mapping compare equal with a differently ordered OrderedDict?

倖福魔咒の 提交于 2019-12-01 15:23:10
According to PEP 468 : Starting in version 3.6 Python will preserve the order of keyword arguments as passed to a function. To accomplish this the collected kwargs will now be an ordered mapping . Note that this does not necessarily mean OrderedDict . In that case, why does this ordered mapping fail to respect equality comparison with Python's canonical ordered mapping type, the collections.OrderedDict : >>> from collections import OrderedDict >>> data = OrderedDict(zip('xy', 'xy')) >>> def foo(**kwargs): ... return kwargs == data ... >>> foo(x='x', y='y') # expected result: True True >>> foo

Dynamic plot works in IDLE, but not jupyter notebook

我只是一个虾纸丫 提交于 2019-12-01 12:22:42
The code below works fine when running through idle (Python 3.6 idle) import matplotlib.pyplot as plt import time import random #%matplotlib inline ysample = random.sample(range(-50, 50), 100) xdata = [] ydata = [] plt.show() axes = plt.gca() axes.set_xlim(0, 100) axes.set_ylim(-50, +50) line, = axes.plot(xdata, ydata, 'r-') for i in range(100): xdata.append(i) ydata.append(ysample[i]) line.set_xdata(xdata) line.set_ydata(ydata) plt.draw() plt.pause(1e-17) time.sleep(0.1) # add this if you don't want the window to disappear at the end plt.show() When transferring this code to jupyter notebook,

Dynamic plot works in IDLE, but not jupyter notebook

久未见 提交于 2019-12-01 10:16:50
问题 The code below works fine when running through idle (Python 3.6 idle) import matplotlib.pyplot as plt import time import random #%matplotlib inline ysample = random.sample(range(-50, 50), 100) xdata = [] ydata = [] plt.show() axes = plt.gca() axes.set_xlim(0, 100) axes.set_ylim(-50, +50) line, = axes.plot(xdata, ydata, 'r-') for i in range(100): xdata.append(i) ydata.append(ysample[i]) line.set_xdata(xdata) line.set_ydata(ydata) plt.draw() plt.pause(1e-17) time.sleep(0.1) # add this if you

How to create image from a list of pixel values in Python3?

落爺英雄遲暮 提交于 2019-12-01 08:42:53
If I have a list of pixel rows from an image in the following format, how would get the image? [ [(54, 54, 54), (232, 23, 93), (71, 71, 71), (168, 167, 167)], [(204, 82, 122), (54, 54, 54), (168, 167, 167), (232, 23, 93)], [(71, 71, 71), (168, 167, 167), (54, 54, 54), (204, 82, 122)], [(168, 167, 167), (204, 82, 122), (232, 23, 93), (54, 54, 54)] ] PIL and numpy are your friends here: from PIL import Image import numpy as np pixels = [ [(54, 54, 54), (232, 23, 93), (71, 71, 71), (168, 167, 167)], [(204, 82, 122), (54, 54, 54), (168, 167, 167), (232, 23, 93)], [(71, 71, 71), (168, 167, 167),

What are the differences between the purposes of generator functions and asynchronous generator functions

余生颓废 提交于 2019-12-01 06:47:23
In Python, asynchronous generator functions are coroutines, and generator functions are also coroutines. What are the differences between the purposes of generator functions and asynchronous generator functions? Thanks. The purpose of PEP 525 -- Asynchronous Generators is pretty much similar to PEP 255 -- Simple Generators which introduced generators. It is mainly intented to make things easier to implement, only in a different domain (asynchronous one). From PEP 525: Essentially, the goals and rationale for PEP 255, applied to the asynchronous execution case, hold true for this proposal as