python-3.x

Generator from function prints

蓝咒 提交于 2021-02-09 11:54:08
问题 At the moment I have a little flask project that calls another python file. I'm fully aware that this way is kinda awful, and so, I want to swap it for a function call while maintaining the prints getting yelded to the website . def get_Checks(): root = request.url_root def func(): yield ("Inicio <br>") with subprocess.Popen(r"python somefile.py", stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p: for line in p.stdout: yield (line + "<br>") return Response(func()) I've tryed to

How to view the whole table

烂漫一生 提交于 2021-02-09 11:12:50
问题 I am trying to get a table(dataset) using quandl. The table has 5rows X 12Columns but it is only showing 4 columns in the output and rest columns are replaced by 3 dots. I wrote the following piece of code using Python: import quandl df = quandl.get('WIKI/GOOGL') print(df.head()) for the output please refer to this image. P.S.: I tried using different IDEs for this code but the output was same. 回答1: I found the solution The following code will work perfectly: import pandas as pd import quandl

django - Unsupported lookup for JSONField or join on the field not permitted

爱⌒轻易说出口 提交于 2021-02-09 11:10:16
问题 I am having a Json field in my models as - class Product(models.Model): ... detailed_stock = JSONField(load_kwargs={'object_pairs_hook': collections.OrderedDict},default=dict) I am having values in my database like - { "total":0, "5[1]":0 } I am trying to filter objects with total = 0, for that I tried - Product.objects.filter(detailed_stock__total = 0) but it throws error - Unsupported lookup 'total' for JSONField or join on the field not permitted. as per the documentation the following

Drawing a png image on a tkinter canvas python

与世无争的帅哥 提交于 2021-02-09 10:58:30
问题 I am trying to create a simple game using tkinter in python 3.5 using the canvas widget. For this game I am need to be able to use a transparent (png) image. Here is my code: from PIL import ImageTk from tkinter import Tk, Canvas root = Tk() im = ImageTk.PhotoImage(file="test.png") canvas = Canvas(root, width=900, height=900) canvas.pack() canvasImage = canvas.create_image(0, 0, image=im, anchor="nw") root.mainloop() The problem is that, despite getting no errors i can't load an image with a

Drawing a png image on a tkinter canvas python

白昼怎懂夜的黑 提交于 2021-02-09 10:58:13
问题 I am trying to create a simple game using tkinter in python 3.5 using the canvas widget. For this game I am need to be able to use a transparent (png) image. Here is my code: from PIL import ImageTk from tkinter import Tk, Canvas root = Tk() im = ImageTk.PhotoImage(file="test.png") canvas = Canvas(root, width=900, height=900) canvas.pack() canvasImage = canvas.create_image(0, 0, image=im, anchor="nw") root.mainloop() The problem is that, despite getting no errors i can't load an image with a

How to make a bot join voice channels discord.py

怎甘沉沦 提交于 2021-02-09 10:58:09
问题 I'm using discord.py to create a music bot, but I'm having trouble connecting the bot to a voice channel. Im using a Cog to seperate the music features from the rest. @commands.command() async def join_voice(self, ctx): channel = ctx.author.voice.channel print(channel.id) await self.client.VoiceChannel.connect() But I get the error: AttributeError: 'NoneType' object has no attribute 'channel' I've looked all through the docs and all the similar questions on here and still no solutions! Could

How to make a bot join voice channels discord.py

可紊 提交于 2021-02-09 10:58:04
问题 I'm using discord.py to create a music bot, but I'm having trouble connecting the bot to a voice channel. Im using a Cog to seperate the music features from the rest. @commands.command() async def join_voice(self, ctx): channel = ctx.author.voice.channel print(channel.id) await self.client.VoiceChannel.connect() But I get the error: AttributeError: 'NoneType' object has no attribute 'channel' I've looked all through the docs and all the similar questions on here and still no solutions! Could

How to resize an image according to a reference point in another

百般思念 提交于 2021-02-09 10:34:34
问题 I currently have two images (im1 and im2) with pixel dimensions of (1725, 1580). im2 however possesses a large border around it that i had to create to ensure that the images were of the same size. im2 was originally (1152, 864). As such. when i overlay im2 ontop of im1 using PIL.Image.blend , im2 appears overlayed onto im1, but is a lot smaller. I have 2 distinct reference points on the images i think i could use (present on im1 and im2) to rescale im2 (zoom it in somehow?) to overlay im2

How to resize an image according to a reference point in another

人盡茶涼 提交于 2021-02-09 10:32:35
问题 I currently have two images (im1 and im2) with pixel dimensions of (1725, 1580). im2 however possesses a large border around it that i had to create to ensure that the images were of the same size. im2 was originally (1152, 864). As such. when i overlay im2 ontop of im1 using PIL.Image.blend , im2 appears overlayed onto im1, but is a lot smaller. I have 2 distinct reference points on the images i think i could use (present on im1 and im2) to rescale im2 (zoom it in somehow?) to overlay im2

concurrent.futures.ThreadPoolExecutor doesn't print errors

狂风中的少年 提交于 2021-02-09 09:37:25
问题 I am trying to use concurrent.futures.ThreadPoolExecutor module to run a class method in parallel, the simplified version of my code is pretty much the following: class TestClass: def __init__(self, secondsToSleepFor): self.secondsToSleepFor = secondsToSleepFor def testMethodToExecInParallel(self): print("ThreadName: " + threading.currentThread().getName()) print(threading.currentThread().getName() + " is sleeping for " + str(self.secondsToSleepFor) + " seconds") time.sleep(self