python-2.7

ctypes struct returned from library

倾然丶 夕夏残阳落幕 提交于 2021-02-16 08:41:38
问题 Given a simple C file: #include <stdio.h> typedef struct point { int x; int y; } POINT; POINT get_point() { POINT p = {1, 2}; return p; } And I have a simple python file: from ctypes import * import os lib_name = '/testlib.so' test_lib = CDLL(os.getcwd() + lib_name) class POINT(Structure): _fields_ = [('x', c_int), ('y', c_int)] # Sets p1 to the integer 1 p1 = test_lib.get_point() # Sets p2 to the struct POINT with values {1, 0} p2 = POINT(test_lib.get_point()) How can I set my returned value

ImportError: MagickWand shared library not found[windows]

只谈情不闲聊 提交于 2021-02-16 05:36:41
问题 Good morning, After a lot of attemps running from wand.image import Image I get the following error: Traceback (most recent call last): File "C:\Users\XXXXX\PycharmProjects\PDF_convert\venv\lib\site-packages\wand\api.py", line 180, in <module> libraries = load_library() File "C:\Users\XXXXX\PycharmProjects\PDF_convert\venv\lib\site-packages\wand\api.py", line 135, in load_library raise IOError('cannot find library; tried paths: ' + repr(tried_paths)) OSError: cannot find library; tried paths:

ImportError: MagickWand shared library not found[windows]

房东的猫 提交于 2021-02-16 05:33:47
问题 Good morning, After a lot of attemps running from wand.image import Image I get the following error: Traceback (most recent call last): File "C:\Users\XXXXX\PycharmProjects\PDF_convert\venv\lib\site-packages\wand\api.py", line 180, in <module> libraries = load_library() File "C:\Users\XXXXX\PycharmProjects\PDF_convert\venv\lib\site-packages\wand\api.py", line 135, in load_library raise IOError('cannot find library; tried paths: ' + repr(tried_paths)) OSError: cannot find library; tried paths:

How to Use a Wildcard (%) in Pandas read_sql()

只谈情不闲聊 提交于 2021-02-16 05:17:38
问题 I am trying to run a MySQL query that has a text wildcard in as demonstrated below: import sqlalchemy import pandas as pd #connect to mysql database engine = sqlalchemy.create_engine('mysql://user:@localhost/db?charset=utf8') conn = engine.connect() #read sql into pandas dataframe mysql_statement = """SELECT * FROM table WHERE field LIKE '%part%'; """ df = pd.read_sql(mysql_statement, con=conn) When run I get the error as shown below related to formatting. TypeError: not enough arguments for

ModuleNotFoundError: No module named 'googleapiclient

隐身守侯 提交于 2021-02-15 07:42:33
问题 Apologies if this is a silly question. I searched in stackoverflow. But did not find the solution. I am working on migration from Python 2.7 to Python 3.8. I am getting the below error for one program. Please help me. Traceback (most recent call last): File " <Path>\main.py", line 17, in <module> import script1 File " <Path>\script1.py", line 9, in <module> import script2 File " <Path>\script2.py", line 10, in <module> from googleapiclient import discovery ModuleNotFoundError: No module named

PyGame press two buttons at the same time

人走茶凉 提交于 2021-02-13 17:40:57
问题 I wrote this: import pygame finish = False while not finish: for event in pygame.event.get(): if event.type == pygame.QUIT: finish = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: print "A" if event.key == pygame.K_RIGHT: print "B" if event.key == pygame.K_LEFT: print "C" Why can't I press two buttons at the same time? 回答1: The keyboard events (e.g. pygame.KEYDOWN ) occure only once when a button is pressed. Use pygame.key.get_pressed() to continuously evaluate the states

PyGame press two buttons at the same time

允我心安 提交于 2021-02-13 17:38:14
问题 I wrote this: import pygame finish = False while not finish: for event in pygame.event.get(): if event.type == pygame.QUIT: finish = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: print "A" if event.key == pygame.K_RIGHT: print "B" if event.key == pygame.K_LEFT: print "C" Why can't I press two buttons at the same time? 回答1: The keyboard events (e.g. pygame.KEYDOWN ) occure only once when a button is pressed. Use pygame.key.get_pressed() to continuously evaluate the states

Show an image with omxiv direct from memory on RPI

亡梦爱人 提交于 2021-02-13 17:29:31
问题 I want to create an image in PILLOW and show it on the screen on the Raspberry Pi with for example omxiv direct from memory without saving it to the memory card, something like this: Python 2.7: from PIL import Image import os img = Image.new('RGB', size=(150, 50), color=(0, 0, 255)) .... im_file = ???? os.system('omxiv im_file') Can anybody tell me how to do this? 回答1: I did some experiments with the framebuffer on my Raspberry Pi 4. Here is what I managed to work out... You can get the

Show an image with omxiv direct from memory on RPI

喜欢而已 提交于 2021-02-13 17:27:03
问题 I want to create an image in PILLOW and show it on the screen on the Raspberry Pi with for example omxiv direct from memory without saving it to the memory card, something like this: Python 2.7: from PIL import Image import os img = Image.new('RGB', size=(150, 50), color=(0, 0, 255)) .... im_file = ???? os.system('omxiv im_file') Can anybody tell me how to do this? 回答1: I did some experiments with the framebuffer on my Raspberry Pi 4. Here is what I managed to work out... You can get the

Plotly legend next to each subplot, Python

点点圈 提交于 2021-02-13 07:52:31
问题 After noticing that there was no answer to this question at the moment, I would like to know if anyone has an idea how to: Have a legends for each subplot. Group legends by name. (Ex: for different subplots, all have the same two curves but with different values). Here's my Plotly script: from plotly import tools import plotly.plotly as py import plotly.graph_objs as go import plotly nom_plot=[] trace1 = go.Scatter(x=[1, 2, 3], y=[4, 5, 6],name='1',showlegend=True) nom_plot.append('GRAPH 1')