python-3.4

import urllib.parse fails when Python run from command line

本秂侑毒 提交于 2019-12-01 18:27:08
问题 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

Why does a set of numbers appear to be sorted? [duplicate]

落花浮王杯 提交于 2019-12-01 18:21:22
This question already has an answer here: Are the integer keys in a Python dictionary sorted and sorted with priority? 2 answers Running this code multiple times t = {'a', 'b', 'c', 'd'} print(t) could print something like: {'c', 'b', 'a', 'd'} {'d', 'b', 'c', 'a'} # different {'d', 'b', 'c', 'a'} # same {'a', 'd', 'b', 'c'} # different {'a', 'b', 'c', 'd'} # different # etc (If you are using the console to replicate it, make sure you click Rerun every time before you re-paste the code and execute it. If you still can't replicate, perhaps you have hash randomization not equal to random . On

difference between python2 and python3 - int() and input()

坚强是说给别人听的谎言 提交于 2019-12-01 18:01:26
I wrote below python code. And I found that python2 and python3 has totally difference running result for input of 1.1. Why is there such difference between python2 and python3? For me, int(1.1) should be 1, then position is valid index 1 within range 0,1,2. So can you please explain why python3 has such result? s=[1,2,3] while True: value=input() print('value:',value) try: position=int(value) print('position',position) print('result',s[position]) except IndexError as err: print('out of index') except Exception as other: print('sth else broke',other) $ python temp.py 1.1 ('value:', 1.1) (

Why does a set of numbers appear to be sorted? [duplicate]

偶尔善良 提交于 2019-12-01 17:37:51
问题 This question already has answers here : Are the integer keys in a Python dictionary sorted and sorted with priority? (2 answers) Closed 4 years ago . Running this code multiple times t = {'a', 'b', 'c', 'd'} print(t) could print something like: {'c', 'b', 'a', 'd'} {'d', 'b', 'c', 'a'} # different {'d', 'b', 'c', 'a'} # same {'a', 'd', 'b', 'c'} # different {'a', 'b', 'c', 'd'} # different # etc (If you are using the console to replicate it, make sure you click Rerun every time before you re

Indexing a PIL image

孤者浪人 提交于 2019-12-01 17:35:50
问题 Is PIL's image coordinate indexing reversed? Is it indexed as image[column, row]? I have an image which I open using PIL (pillow) img = Image.open('picture.png').load() and when I try to print the pixel value of the first row, second column print(img[0,1]) I get the pixel value of the 2nd row's first column Can anyone clear this out? 回答1: PIL indexes images in Cartesian co-ordinates. So it is indexed as img[col, row] . 来源: https://stackoverflow.com/questions/44967819/indexing-a-pil-image

Unable to install logging module (Python)

不羁岁月 提交于 2019-12-01 15:48:22
I'm trying to install the logging module for Python 3.4. I'm using pip3 install logging. Both times I run into a SyntaxError at line 618 of the init method: "raise NotImplementedError, 'emit must be implemented '\". Someone posted the same question as me, and solved their problem by deleting an interfering third party library called logging: Logging module not working with Python3 . But I have no such library already installed in my site-packages directory. Thanks! logging is part of the Python standard library. It's available as soon as you install Python. You don't need to pip install

How PyQt5 keyPressEvent works

▼魔方 西西 提交于 2019-12-01 11:20:19
I create a UI from PyQt GPL v5.4 and use pyuic5 convert *.ui file to *.py But I do not know how keyPressEvent work in this code!! It should work for QWidget, but how to let it works. Please help! from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QWidget class Ui_MainWindow(QWidget,object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(200, 200) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.pushButton = QtWidgets.QPushButton(self.centralwidget)

Project Setup with Django 1.10, mongodb and Python 3.4.3

我只是一个虾纸丫 提交于 2019-12-01 08:42:19
问题 Initially I have built projects with Django 1.5, django-mongoengine, python 2.7.8. I have started a project with an idea came up to my mind. I want to make it using latest versions of technologies therefore I stick with: Django 1.10, python 3.4.3 I want to use mongodb as my database. To run my project I am facing an error when I tried to connect mongodb with Django. Code in the settings.py is given as follow to connect database (The only change I made yet in file): DATABASES = { 'default': {

BeautifulSoup invalid syntax in Python 3.4 (after 2to3.py)

孤街醉人 提交于 2019-12-01 08:40:17
I am trying to install Beautiful Soup 4 in Python 3.4. I installed it from the command line, (got the invalid syntax error because I had not converted it), ran the 2to3.py conversion script to bs4 and now I get a new invalid syntax error. >>> from bs4 import BeautifulSoup Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> from bs4 import BeautifulSoup File "C:\Python34\bs4\__init__.py", line 30, in <module> from .builder import builder_registry, ParserRejectedMarkup File "C:\Python34\bs4\builder\__init__.py", line 4, in <module> from bs4.element import ( File "C:

How PyQt5 keyPressEvent works

左心房为你撑大大i 提交于 2019-12-01 08:36:08
问题 I create a UI from PyQt GPL v5.4 and use pyuic5 convert *.ui file to *.py But I do not know how keyPressEvent work in this code!! It should work for QWidget, but how to let it works. Please help! from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QWidget class Ui_MainWindow(QWidget,object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(200, 200) self.centralwidget = QtWidgets.QWidget(MainWindow) self