python-3.4

Converting Unicode sequences to a string in Python 3

ε祈祈猫儿з 提交于 2019-12-08 08:01:41
问题 In parsing an HTML response to extract data with Python 3.4 on Kubuntu 15.10 in the Bash CLI, using print() I am getting output that looks like this: \u05ea\u05d4 \u05e0\u05e9\u05de\u05e2 \u05de\u05e6\u05d5\u05d9\u05df How would I output the actual text itself in my application? This is the code generating the string: response = requests.get(url) messages = json.loads( extract_json(response.text) ) for k,v in messages.items(): for message in v['foo']['bar']: print("\nFoobar: %s" % (message[

Python, save as mht

送分小仙女□ 提交于 2019-12-08 04:13:34
问题 I can bring up a web page, no problem. I can save the webpage...as html, no problem. I need to save the webpage as mht so I can can get all the html that gets hidden without saving as mht. In researching I'm coming up with absolutely nothing as to how to save as mht using python. Like I said above I can try to save it as a mht file, using the standard coded for saving as html but that simply doesn't work...not surprised it doesn't work either, but it was worth a shot. url = 'https://www

Get all results from NLTK concordance

萝らか妹 提交于 2019-12-08 03:30:32
问题 I'm using NLTK to find the concordance of a word, but I don't know how to get all the results and put them in a list or set . For example: text.concordance(word) prints just the first 25 results. 回答1: TL;DR text.concordance(lines=100) From the code, https://github.com/nltk/nltk/blob/develop/nltk/text.py#L323: def concordance(self, word, width=79, lines=25): """ Print a concordance for ``word`` with the specified context window. Word matching is not case-sensitive. :seealso: ``ConcordanceIndex

How do you change the value of one attribute by changing the value of another? (dependent attributes)

倾然丶 夕夏残阳落幕 提交于 2019-12-07 22:25:42
问题 So I've recently dived into OOP, and so far everything is going smooth. Whilst I have no issues per se, there's an amazing feature which I hope exists, though I cannot find any documentation on said feature. When assigning attributes to objects, I often find that I have to change attribues that are dependent upon others, say, light and darkness. Here's an example: class shade: def __init__(self, light): self.light=light self.darkness=100-light def __str__(self): return (str(self.light) + ','

Django Call Stored Procedure on Second Database

若如初见. 提交于 2019-12-07 19:46:13
问题 I'm trying to call a stored procedure on a multi-db Django installation, but am not having any luck getting results. The stored procedure (which is on the secondary database) always returns an empty array in Django, but the expected result does appear when executed in a mysql client. My view.py file from SomeDBModel import models from django.db import connection def index(request, someid): #Some related django-style query that works here loc = getLocationPath(someid, 1) print(loc) def

Porting to Python3: PyPDF2 mergePage() gives TypeError

↘锁芯ラ 提交于 2019-12-07 16:29:29
问题 I'm using Python 3.4.2 and PyPDF2 1.24 (also using reportlab 3.1.44 in case that helps) on windows 7. I recently upgraded from Python 2.7 to 3.4, and am in the process of porting my code. This code is used to create a blank pdf page with links embedded in it (using reportlab) and merge it (using PyPDF2) with an existing pdf page. I had an issue with reportlab in that saving the canvas used StringIO which needed to be changed to BytesIO, but after doing that I ran into this error: Traceback

Grab any exception in PyQt

时光总嘲笑我的痴心妄想 提交于 2019-12-07 11:40:55
问题 I've created an GUI app in PyQt, which I want to share with many people. Sometimes I get unexpected exceptions and I take it for granted - after every exception I improve my code and it gets better and better. I use a logger for recording these exceptions and special hook for PyQt silenced exceptions. My code looks like this: Logger def setLogger(level=logging.DEBUG, name="my_logger", file=join("src", "log.out")): logger = logging.getLogger(name) logger.setLevel(level) # console logger ch =

How to override python's distutils gcc linker with icc?

爱⌒轻易说出口 提交于 2019-12-07 08:47:49
问题 I was able to successfully build cython on Ubuntu 14.04 from source as explained in this SE question/answer Compiling cython From source with icc and I downloaded the source code from here - Cython source code download. The command to compile cython is CC=icc LINKCC=icc python3.4 setup.py build I am enclosing the build log. It is STILL using gcc for linking. Here is a sample of build log. It appears CC=icc LINKCC=icc does NOT seem to change the linker to icc. It is still using x86_64-linux

Couldn't create working virtual environment for Python 3.4

冷暖自知 提交于 2019-12-07 08:37:15
问题 I installed Python 3.4.2 and Virtualenv 12.0.5 in my Linux Mint 17.1 Then I tried creating: $ virtualenv venv And also using --clear and/or -p /usr/bin/python3.4, always getting the messages: Using base prefix '/usr' New python executable in venv/bin/python3 Also creating executable in venv/bin/python ERROR: The executable venv/bin/python3 could not be run: [Errno 13] Permission denied Another try was: $ pyvenv-3.4 venv It gave no errors on creation, but in the venv/bin file the python3.4 is

taking webcam photos in python 3 and windows

僤鯓⒐⒋嵵緔 提交于 2019-12-07 08:15:07
问题 I want to be able to take a photo from a webcam in python 3 and Windows. Are there any modules that support it? I have tried pygame, but it is only linux and python 2, and VideoCapture is only python 2. 回答1: 07/08/14 Pygame 3.4 Ver. is released http://www.youtube.com/watch?v=SqmSpJfN7OE http://www.lfd.uci.edu/~gohlke/pythonlibs/ You can download "pygame‑1.9.2a0.win32‑py3.4.exe" take a photo from a webcam in python 3.4 (testing on window 7) code [1] import pygame import pygame.camera pygame