python-3.4

What is the logic of this process

為{幸葍}努か 提交于 2019-12-02 13:03:09
问题 I was working on a problem in Project Euler; and I found a question in SO. The question and accepted answer says; n = 600851475143 i = 2 while i * i < n: while n%i == 0: n = n / i i = i + 1 print (n) It's just awesome. I still can't understand how this process is so fast and can find the largest prime factor of 600billion in 0.00001 seconds. I tried tons of methods and codes for that, processes took over than 1 hour.. Could anyone explain me the logic of this codes and why it's super-fast? is

Python `for` does not iterate over enumerate object

一世执手 提交于 2019-12-02 11:56:19
Why does this not iterate? import logging logging.basicConfig(level=logging.DEBUG) x = [] y = [[] for n in range(0, 1)] linedata = ["0","1","2"] x.append( linedata[0] ) d = linedata[1:] logging.debug( "d: {}".format(d) ) e = enumerate(d) logging.debug( list(e) ) for k, v in e: logging.debug( "k:{} v:{}".format( k, v ) ) y[int(k)].append( v ) #for d in [(0,1)]: #logging.debug( "k:{} v:{}".format( d[0], d[1] ) ) #y[d[0]].append( d[1] ) logging.debug( x ) logging.debug( y ) Output: DEBUG:root:d: ['1', '2'] DEBUG:root:[(0, '1'), (1, '2')] DEBUG:root:['0'] DEBUG:root:[[]] Docs: https://docs.python

Get rid of Mongo $ signs in JSON

蹲街弑〆低调 提交于 2019-12-02 03:05:47
问题 I am building python backend for SPA (Angular) using MongoDB. Here is what I use: Python 3.4 , MongoDB 3 , Flask , flask-mongoengine and flask-restful Now I receive the following JSON from my backend: [ { "_id": { "$oid": "55c737029380f82fbf52eec3" }, "created_at": { "$date": 1439129906376 }, "desc": "Description.....", "title": "This is title" }, etc... ] And I want to receive something like that : [ { "_id": "55c737029380f82fbf52eec3", "created_at": 1439129906376, "desc": "Description....."

Get rid of Mongo $ signs in JSON

拟墨画扇 提交于 2019-12-02 01:18:51
I am building python backend for SPA (Angular) using MongoDB. Here is what I use: Python 3.4 , MongoDB 3 , Flask , flask-mongoengine and flask-restful Now I receive the following JSON from my backend: [ { "_id": { "$oid": "55c737029380f82fbf52eec3" }, "created_at": { "$date": 1439129906376 }, "desc": "Description.....", "title": "This is title" }, etc... ] And I want to receive something like that : [ { "_id": "55c737029380f82fbf52eec3", "created_at": 1439129906376, "desc": "Description.....", "title": "This is title" }, etc... ] My code for now: from flask import json from vinnie import app

Python3 PIL Pillow Ubuntu Install

☆樱花仙子☆ 提交于 2019-12-01 23:47:40
I'm running Ubuntu 14.04 LTS. I have both Python 2.7 and Python 3.4 installed. I'm relatively novice when it comes to installing Python Packages in Linux. I'm just trying to install and get access to PIL's image library in Python 3.4. It is my understanding that this is achieved by installing Pillow, the modern fork of PIL. It seems in my floundering I managed to successfully get PIL working in Python 2.7, but I still cannot get it working in 3.4. I got pip and pip3 . When I enter sudo pip3 install Pillow I get the following error message, implying it is is installed: Requirement already

PermissionError: [Errno 1] Operation not permitted

[亡魂溺海] 提交于 2019-12-01 20:45:42
问题 I am completely new to python, linux RPI and scapy. I am trying to send some packets using scapy. On Command Line (only if super user privileges are given to scapy) send(IP(dst="1.2.3.4")/ICMP()) This works perfectly, while running on python script. from scapy.all import * p=send(IP(dst="1.2.3.4")/ICMP()) Throws an error Traceback (most recent call last): File "<pyshell#19>", line 1, in <module> send(IP(dst="1.2.3.4")/ICMP()) File "/usr/local/lib/python3.4/dist-packages/scapy/sendrecv.py"

Python 3.4 SSL error urlopen error EOF occurred in violation of protocol (_ssl.c:600)

匆匆过客 提交于 2019-12-01 20:20:35
问题 I use Arch Linux, python 3.4, openSSL 1.0.2d. When I make request to https://www.supercash.cz/ I get this error. It doesn't matter if I use requests or build in urllib there is always the same error. SSL certificate for this site seams to be OK in Chrome browser. File "/usr/lib64/python3.4/urllib/request.py", line 463, in open response = self._open(req, data) File "/usr/lib64/python3.4/urllib/request.py", line 481, in _open '_open', req) File "/usr/lib64/python3.4/urllib/request.py", line 441

Python 3.4 SSL error urlopen error EOF occurred in violation of protocol (_ssl.c:600)

吃可爱长大的小学妹 提交于 2019-12-01 19:21:16
I use Arch Linux, python 3.4, openSSL 1.0.2d. When I make request to https://www.supercash.cz/ I get this error. It doesn't matter if I use requests or build in urllib there is always the same error. SSL certificate for this site seams to be OK in Chrome browser. File "/usr/lib64/python3.4/urllib/request.py", line 463, in open response = self._open(req, data) File "/usr/lib64/python3.4/urllib/request.py", line 481, in _open '_open', req) File "/usr/lib64/python3.4/urllib/request.py", line 441, in _call_chain result = func(*args) File "/usr/lib64/python3.4/urllib/request.py", line 1225, in

How to import sqlite3 in my python3.4 successfully?

删除回忆录丶 提交于 2019-12-01 18:56:44
There are two python version in my debian7, one is python2.7 the system default version, the other is python3.4 which compiled to install this way. apt-get update apt-get upgrade apt-get install build-essential wget http://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz tar -zxvf Python-3.4.0.tgz cd Python-3.4.0 mkdir /usr/local/python3.4 ./configure --prefix=/usr/local/python3.4 make make install ln -s /usr/local/python3.4/bin/python3.4 /usr/bin/python3.4 ln -s /usr/local/python3.4/bin/pip3.4 /usr/bin/pip3.4 I have installed sqlite this way on my debian. sudo apt-get install sqlite3

import urllib.parse fails when Python run from command line

泪湿孤枕 提交于 2019-12-01 18:53:58
I have observed the following behavior in python 3.4.2, and I am unableto explain it. Hopefully someone could shed some light on the matter: In IPython: In [129]: import urllib In [130]: print(urllib.parse) <module 'urllib.parse' from '/Users/ashwin/.pyenv/versions/3.4.2/lib/python3.4/urllib/parse.py'> I've imported a module, and printed one of its attributes. Everything works as expected. So far, life is good. Now, I do the same thing from the command line: $ python -c 'import urllib; print(urllib.parse)' Traceback (most recent call last): File "<string>", line 1, in <module> AttributeError: