python-2.7

How to get data from pdf in Cyrillic?

孤街浪徒 提交于 2021-01-28 07:59:00
问题 I have error when I try to get data in cyrillic import codecs pdfFileObj = codecs.open('1.pdf', 'rb','utf-8') The error is 'utf8' codec can't decode byte 0x9c in position 1: invalid start byte 回答1: PDF is not a textfile PDF is not unicode, PDF is full of binary streams, with text, images and so on. Use some PDF library Take look at PyPDF2. To get text from first page do pdf = PdfFileReader(open('/tmp/russian.pdf', 'rb')) text = pdf.getPage(0).extractText() Though you might also need to

How to import all images from a user specified folder in python using pygame

对着背影说爱祢 提交于 2021-01-28 07:55:14
问题 I m new to python, and I'm working on pygame. For my project, i need to import all the images from a user specified folder. Is there any function in pygame to import only the image files from the folder? or guide me to filter only the image files among all files from the imported folder. Sorry, if the question is too basic. 回答1: I don't know about pygame but you with plain python is fairly simple to get all image files within a folder: import imghdr import os for dirpath, dirnames, filenames

Matplotlib axis text coordinates inconsistency?

筅森魡賤 提交于 2021-01-28 07:51:52
问题 I'm working on a piece of code to automatically align x-axis labels for a variable number of subplots. When I started having trouble setting label positions manually, I checked to be sure I could just transform from one set of coordinates to the other without changing anything, with a code snippet like this: # xaxes is a list of Axes objects textCoords = [ax.xaxis.get_label().get_position() for ax in xaxes] newCoords = [ax.transAxes.inverted().transform(ax.xaxis.get_label().\ get_transform()

Python regex: Bad character range

二次信任 提交于 2021-01-28 07:50:40
问题 I have the next regular expression to find emojis on a text: re.compile(u'([\U00002600-\U000027BF])|([\U0001F300-\U0001F64F])|([\U0001F680-\U0001F6FF])') It is working well in Python 3 but in Python 2.7 I get this: sre_constants.error: bad character range How can I fix it to support both, Python 2.7 and Python 3? 回答1: Use r'(... instead of u'(... like this: re.compile(r'([\U00002600-\U000027BF\U0001F300-\U0001F64F\U0001F680-\U0001F6FF])') Also note that you can specify multiple ranges inside

python 2.7 cannot import geocoder library

纵饮孤独 提交于 2021-01-28 07:50:02
问题 Python 2.7.10 on win32. windows 8.1 used pip to install geocoder library https://pypi.python.org/pypi/geocoder/1.8.0 get this error when I try and import the library >>> import geocoder Traceback (most recent call last): File "<interactive input>", line 1, in <module> File "C:\Python27\ArcGIS10.4\lib\site-packages\geocoder\__init__.py", line 36, in <module> from geocoder.api import get, yahoo, bing, geonames, mapquest, google, mapbox # noqa File "C:\Python27\ArcGIS10.4\lib\site-packages

Python ctypes dll load error 487

半腔热情 提交于 2021-01-28 07:44:51
问题 I am using Python 2.7 and trying to load a dll with ctypes: lib = ctypes.cdll.LoadLibrary("mylib.dll") It sometimes throws the following error, some other times it runs ok. Also with Python 3 always throws this error: libcrypto = ctypes.cdll.LoadLibrary("data\openvpn\libeay32") File "C:\Python27\lib\ctypes__init__.py", line 440, in LoadLibrary return self._dlltype(name) File "C:\Python27\lib\ctypes__init__.py", line 362, in init self._handle = _dlopen(self._name, mode) WindowsError: [Error

Python multiprocessing queue is empty although it is filled in a different thread

删除回忆录丶 提交于 2021-01-28 07:33:04
问题 I have now tried to resolve this issue for multiple hours but no matter what I do, I never get the thing to work. My project tracks live data and provides an endpoint for other services to get the latest(ish) measurement. But no matter what I do, the queue.get() always returns nothing. Here is my code: from collections import deque import numpy as np import argparse import imutils import cv2 from flask import Flask from multiprocessing import Queue import threading import Queue as Q app =

Pandas: Multiple rolling periods

你。 提交于 2021-01-28 07:27:55
问题 I would like to get multiple rolling period means and std for several columns simultaneously. This is the code I am using for rolling(5): def add_mean_std_cols(df): res = df.rolling(5).agg(['mean','std']) res.columns = res.columns.map('_'.join) cols = np.concatenate(list(zip(df.columns, res.columns[0::2], res.columns[1::2]))) final = res.join(df).loc[:, cols] return final I would like to the get rolling (5), (15), (30), (45) periods on the same operation. I thought about iterating over

python - sqlite InterfaceError: Error binding parameter 0 - probably unsupported type

烈酒焚心 提交于 2021-01-28 07:22:27
问题 i am using sqlite3 to store values into database, My problem is i have created lineedits through which i extract values and store it to variables and pass this variables to insert query but i am getting above error at line values(?,?,?,?,?)......if i hard quote the values directly to variables it gets saved into database what is the mistake am i doing? please help.......here is my code self.uname = self.le1.text() self.passwd = self.le2.text() self.permssn = self.le3.text() self.queryCurs

How to embed basic HTML page using Qt?

╄→尐↘猪︶ㄣ 提交于 2021-01-28 07:16:25
问题 I am using PySide2.QtWebEngineWidgets.QWebEngineView() to setHtml on it to show a basic page like below. This html file works fine in a browser because it has all the files in the same folder relative to the html file. Once I setHtml to the below file, I get this exception: Qt Error: Uncaught ReferenceError: require is not defined Is this related to Qt not finding the relative files unlike a regular browser? Or is there something else I should be doing? Or is QWebEngineView not advanced