将Google Web Fonts包含在页面中的首选方法是什么?
通过链接标签?
<link href='http://fonts.googleapis.com/css?family=Judson:400,400italic,700' rel='stylesheet' type='text/css'>
通过样式表中的导入?
@import url(http://fonts.googleapis.com/css?family=Kameron:400,700);
或使用网络字体加载器
我正在使用OpenCV(2.4)和Python(2.7.3)以及Thorlabs的USB摄像头(DC1545M).
我正在对视频流进行一些图像分析,我希望能够从我的视频流中更改一些摄像机参数.令人困惑的是,我能够改变一些相机属性而不是所有相机属性,我不确定我做错了什么.
这是代码,使用Python中的cv2绑定,我可以确认它运行:
import cv2
#capture from camera at location 0
cap = cv2.VideoCapture(0)
#set the width and height, and UNSUCCESSFULLY set the exposure time
cap.set(3,1280)
cap.set(4,1024)
cap.set(15, 0.1)
while True:
ret, img = cap.read()
cv2.imshow("input", img)
#cv2.imshow("thresholded", imgray*thresh2)
key = cv2.waitKey(10)
if key == 27:
break
cv2.destroyAllWindows()
cv2.VideoCapture(0).release()
Run Code Online (Sandbox Code Playgroud)
作为参考,cap.set()命令中的第一个参数引用了相机属性的枚举,如下所示:
0. CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
1. CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
2. CV_CAP_PROP_POS_AVI_RATIO Relative position of the video …Run Code Online (Sandbox Code Playgroud) 我一直在试图找出一种在Python中加载JSON对象的好方法.我发送这个json数据:
{'http://example.org/about': {'http://purl.org/dc/terms/title': [{'type': 'literal', 'value': "Anna's Homepage"}]}}
Run Code Online (Sandbox Code Playgroud)
到后端它将作为字符串接收,然后我用来json.loads(data)解析它.
但每次我得到同样的例外:
ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索它,但除了这个解决方案似乎没有什么工作,这个解决方案json.loads(json.dumps(data))对我来说并不那么有效,因为它接受任何类型的数据,即使是那些不是json格式的数据.
任何建议将不胜感激.
我想知道如何将pygame项目中图像的大小缩放到屏幕的分辨率.例如,设想以下场景假设当前窗口显示模式; 我假设全屏将是相同的:
我有一个1600x900背景图像,当然在1600x900窗口中本地显示
在一个1280x720窗口中,我显然可以将这个图像缩放到1280x720
然而,如果我需要添加,请说一个尺寸适合原始背景的300x300 px图像x,y 1440,860(示例尺寸)会发生什么1600x900?当然,对于1600x900我当然可以原生使用图像,但是较小/较大的窗口大小呢?
基本上,如何将图像缩放到窗口大小然后相应地定位?我想必须有一个非常简单的自动化方法,但现在我无法弄清楚,坦率地说没有时间去搜索它...
提前谢谢,Ilmiont
"Dunder"(定义d ouble 下得分):http://www.urbandictionary.com/define.php?term=Dunder
我有根据的模块级"dunders"(如放置的问题__all__,__version__,__author__在Python代码等).
这个问题向我走来,通过阅读而PEP8,看到这个堆栈溢出问题.
接受的答案是:
__author__是一个全局"变量",因此应该出现在导入之下.
但是在PEP8部分模块级别的dunder名称中我读了以下内容:
模块级"dunders"(即名称具有两个前缘和两个纵下划线),例如
__all__,__author__,__version__等应被放置在模块文档字符串之后,但在除了从任何导入语句__future__进口.Python要求future-imports必须在除docstrings之外的任何其他代码之前出现在模块中.
作者还给出了一个代码示例:
"""This is the example module.
This module does stuff.
"""
from __future__ import barry_as_FLUFL
__all__ = ['a', 'b', 'c']
__version__ = '0.1'
__author__ = 'Cardinal Biggles'
import os
import sys
Run Code Online (Sandbox Code Playgroud)
但是当我将上述内容放入PyCharm时,我看到了这个警告(也见截图):
PEP8:模块级别导入不在文件顶部
问题:使用双下划线存储这些变量的正确方法/位置是什么?
我正在学习单元测试,我偶然发现了一个奇怪的错误:
如果我从PyCharm内部运行我的脚本,一切都很完美.如果我从我cmd.exe(作为管理员)运行它,我收到以下错误:
这是我的代码:
import unittest
class TutorialUnittest(unittest.TestCase):
def test_add(self):
self.assertEqual(23,23)
self.assertNotEqual(11,12)
# function for raising errors.
def test_raise(self):
with self.assertRaises(Exception):
raise Exception`
Run Code Online (Sandbox Code Playgroud) 我在Cython中构建一个包.我使用以下作为结构setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy
import scipy
extensions = [
Extension("xxxxx",["xxxx/xxxxx.pyx"],
include_dirs=[numpy.get_include(),"."]),
Extension("nnls",["xxxxx/xxxxx.pyx"],
include_dirs=[numpy.get_include(),"."]),
]
setup(
name='xxxxxx',
version='0.0.0',
description='''********''',
url='xxxxxxx',
author='xxxxx',
author_email='xxxxx',
packages=[
'xxxxx',
],
install_requires=[
'cython',
'numpy',
'scipy',
],
ext_modules=cythonize(extensions),
)
Run Code Online (Sandbox Code Playgroud)
但是,我在Python 3中安装时遇到错误.它在Python 2中工作,但它在Python 3中没有编译,但有以下错误:
动态模块没有定义模块导出功能
我怎么解决这个问题?结构setup.py的原因是这不是编译的原因吗?
我正在尝试将多个数据帧作为电子邮件中的表格发送.使用df.to_html()我能够为我作为电子邮件正文的一部分附加的表呈现HTML字符串.我成功地能够在电子邮件中获取表格.
html.append(table.to_html(na_rep = " ",index = False))
body = '\r\n\n<br>'.join('%s'%item for item in html)
msg.attach(MIMEText(body, 'html'))
Run Code Online (Sandbox Code Playgroud)
但是如何在这些表的标题中添加背景颜色?
导入时出现以下错误ctypes,但仅在我的虚拟环境中(Python 3.4).
>>> import ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ImportError: /home/user/Code/Python/venvs/main/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: _PyTraceback_Add
Run Code Online (Sandbox Code Playgroud)
pip冻结了virtualenv:
beautifulsoup4==4.4.0
blessings==1.6
Django==1.8.4
image==1.4.1
Pillow==2.9.0
wheel==0.24.0
Run Code Online (Sandbox Code Playgroud)
我该如何解决?它适用于主要的python 3.4解释器......
我目前正在使用Python.我有一个start-function,它从消息中获取一个字符串.我想为每条消息启动线程.
此刻的帖子应该像这样打印我的消息:
def startSuggestworker(message):
print(message)
def start():
while True:
response = queue.receive_messages()
try:
message = response.pop()
start_keyword = message.body
t = threading.Thread(target=startSuggestworker, args = (start_keyword))
t.start()
message.delete()
except IndexError:
print("Messages empty")
sleep(150)
start()
Run Code Online (Sandbox Code Playgroud)
目前我得到了一个TypeError并且不明白为什么.Exception消息是这样的:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
TypeError: startSuggestworker() takes 1 positional argument but y were given
Run Code Online (Sandbox Code Playgroud)
*y =我的字符串的长度
我究竟做错了什么?
python ×9
background ×1
camera ×1
cmd ×1
ctypes ×1
cython ×1
fonts ×1
image ×1
importerror ×1
json ×1
numpy ×1
opencv ×1
pandas ×1
parsing ×1
pep ×1
pep8 ×1
pycharm ×1
pygame ×1
python-2.7 ×1
python-3.x ×1
scaling ×1
unit-testing ×1
virtualenv ×1
webfonts ×1