python-3.4

Why is hash() slower under python3.4 vs python2.7

安稳与你 提交于 2019-12-01 04:08:18
问题 I was doing some performance evaluation using timeit and discovered a performance degredation between python 2.7.10 and python 3.4.3. I narrowed it down to the hash() function: python 2.7.10: >>> import timeit >>> timeit.timeit('for x in xrange(100): hash(x)', number=100000) 0.4529099464416504 >>> timeit.timeit('hash(1000)') 0.044638872146606445 python 3.4.3: >>> import timeit >>> timeit.timeit('for x in range(100): hash(x)', number=100000) 0.6459149940637872 >>> timeit.timeit('hash(1000)') 0

Python doesn't find MagickWand Libraries (despite correct location?)

谁都会走 提交于 2019-12-01 03:39:27
I wanted to install the Python ImageMagick API wand and followed this site: http://docs.wand-py.org/en/latest/guide/install.html#install-imagemagick-on-windows However, when running a very simple test: from wand.image import Image I get the following output: Traceback (most recent call last): File "F:\PATHTO\Python34\lib\site-packages\wand\api.py", line 137, in libraries = load_library() File "F:\PATHTO\Python34\lib\site-packages\wand\api.py", line 107, in load_library raise IOError('cannot find library; tried paths: ' + repr(tried_paths)) OSError: cannot find library; tried paths: ['F:\PATHTO

No module named 'openpyxl' - Python 3.4 - Ubuntu

守給你的承諾、 提交于 2019-12-01 02:19:00
I installed openpyxl with $ pip install openpyxl when I try the command from openpyxl import Workbook I get Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> from openpyxl import Workbook ImportError: No module named 'openpyxl' I am using Python 3.4 and Ubuntu 14.04, 32-bit OS type @zetysz and @Manish already fixed the problem. I am just putting this in an answer for future reference: pip refers to Python 2 as a default in Ubuntu, this means that pip install x will install the module for Python 2 and not for 3 pip3 refers to Python 3 , it will install the module for

SSL error using Python Requests to access Shibboleth authenticated server

半腔热情 提交于 2019-12-01 01:01:52
I'm trying to access a journal article hosted by an academic service provider (SP), using a Python script. The server authenticates using a Shibboleth login. I read Logging into SAML/Shibboleth authenticated server using python and tried to implement a login with Python Requests. The script starts by querying the SP for the link leading to my IDP institution, and is supposed then to authenticate automatically with the IDP. The first part works, but when following the link to the IDP, it chokes on an SSL error. Here is what I used: import requests import lxml.html LOGINLINK = 'https://www.jsave

How to get text from span tag in BeautifulSoup

扶醉桌前 提交于 2019-12-01 00:25:55
问题 I have links looks like this <div class="systemRequirementsMainBox"> <div class="systemRequirementsRamContent"> <span title="000 Plus Minimum RAM Requirement">1 GB</span> </div> I'm trying to get 1 GB from there. I tried tt = [a['title'] for a in soup.select(".systemRequirementsRamContent span")] for ram in tt: if "RAM" in ram.split(): print (soup.string) It outputs None . I tried a['text'] but it gives me KeyError. How can I fix this and what is my mistake? 回答1: You can use a css selector,

Python for loop decrementing index

荒凉一梦 提交于 2019-11-30 22:28:45
So I wrote a for loop like this: for i in range(size): if(.....) .... i-=1 else: .... I try to decrease the index by 1 if it is inside the if statement, but apparently I can't do that. Is there any other way that I can decrease i in a for loop? I would like to go over the range() function yet again through the documentation as provided here: Python 3.4.1 Documentation for range(start, stop[, step]) As shown in the documentation above, you may enter three parameters for the range function 'start', 'stop', and 'step', and in the end it will give you an immutable sequence . The 'start' parameter

How can I overcome this key word error?

混江龙づ霸主 提交于 2019-11-30 20:44:52
enter code here # -*- coding: utf-8 -*- import math import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import matplotlib.animation as animation fig1=plt.figure() ax=plt.axes(xlim=(-10,10), ylim=(-10,10)) line,=ax.plot([],[],lw=1) """def init (): line.set_data([],[]) return line,""" dt=0.001 X=[] Y=[] r=float(input("Enter the radius :: ")) w=float(input("Enter angular frequency :: ")) def run(data): t=0 while w*t<=2*math.pi: x=r*math.cos(w*t) y=r*math.sin(w*t) X.append(x) Y.append(y) t=t+dt line.set_data(X,Y) return line, line,=ax.plot(X,Y,lw=2) FFMpegWriter = animation

SSL error using Python Requests to access Shibboleth authenticated server

冷暖自知 提交于 2019-11-30 19:24:07
问题 I'm trying to access a journal article hosted by an academic service provider (SP), using a Python script. The server authenticates using a Shibboleth login. I read Logging into SAML/Shibboleth authenticated server using python and tried to implement a login with Python Requests. The script starts by querying the SP for the link leading to my IDP institution, and is supposed then to authenticate automatically with the IDP. The first part works, but when following the link to the IDP, it

Python asyncio: reader callback and coroutine communication

为君一笑 提交于 2019-11-30 18:35:13
I am trying to implement a simple idea of passing a data from stdin to a coroutine: import asyncio import sys event = asyncio.Event() def handle_stdin(): data = sys.stdin.readline() event.data = data # NOTE: data assigned to the event object event.set() @asyncio.coroutine def tick(): while 1: print('Tick') yield from asyncio.sleep(1) if event.is_set(): data = event.data # NOTE: data read from the event object print('Data received: {}'.format(data)) event.clear() def main(): loop = asyncio.get_event_loop() loop.add_reader(sys.stdin, handle_stdin) loop.run_until_complete(tick()) if __name__ == '

What File Descriptor object does Python AsyncIO's loop.add_reader() expect?

北战南征 提交于 2019-11-30 14:13:49
I'm trying to understand how to use the new AsyncIO functionality in Python 3.4 and I'm struggling with how to use the event_loop.add_reader() . From the limited discussions that I've found it looks like its for reading the standard out of a separate process as opposed to the contents of an open file. Is that true? If so it appears that there's no AsyncIO specific way to integrate standard file IO, is this also true? I've been playing with the following code. The output of the following gives the exception PermissionError: [Errno 1] Operation not permitted from line 399 of /python3.4/selectors