python-3.5

how to type hint collections.OrderedDict via python 3.5 typing module

删除回忆录丶 提交于 2019-12-04 22:34:29
I want to use an OrderedDict where the key is a Enum and where the item is a certain class. How do I use the typing module to hint this? What is the analog to this hinted namedtuple:: Move = typing.NamedTuple('Move', [('actor', Actor), ('location', Location)]) As noted in a comment by AChampion, you can use MutableMapping : class Actor(Enum): # ...Actor enum menbers... class Location: # ...Location class body... class MapActor2Location(OrderedDict, MutableMapping[Actor, Location]): pass Addendum for people like me who haven't used the typing module before: note that the type definitions use

AttributeError: module 'urllib' has no attribute 'parse'

我是研究僧i 提交于 2019-12-04 22:17:31
python 3.5.2 code 1 import urllib s = urllib.parse.quote('"') print(s) it gave this error: AttributeError: module 'urllib' has no attribute 'parse' code 2 from urllib.parse import quote # import urllib # s = urllib.parse.quote('"') s = quote('"') print(s) it works... code3 from flask import Flask # from urllib.parse import quote # s = quote('"') import urllib s = urllib.parse.quote('"') print(s) it works,too. because of flask? Why I don't have the error anymore? is it a bug ? The urllib package serves as a namespace only. There are other modules under urllib like request and parse . For

Package installation of Keras in Anaconda?

百般思念 提交于 2019-12-04 21:34:24
Python 3.5, I am trying to find command to install a Keras Deep Learning package for Anaconda. The command conda install -c keras does not work, can anyone answer Why it doesn't work? The specific answer to the question is that the -c option to the conda command specifies a channel to search for the package or packages you want to install. -c CHANNEL, --channel CHANNEL Additional channel to search for packages. These are URLs searched in the order they are given (including file:// for local directories). Then, the defaults or channels from .condarc are searched (unless --override-channels is

In-place custom object unpacking different behavior with __getitem__ python 3.5 vs python 3.6

对着背影说爱祢 提交于 2019-12-04 21:24:09
问题 a follow-up question on this question: i ran the code below on python 3.5 and python 3.6 - with very different results: class Container: KEYS = ('a', 'b', 'c') def __init__(self, a=None, b=None, c=None): self.a = a self.b = b self.c = c def keys(self): return Container.KEYS def __getitem__(self, key): if key not in Container.KEYS: raise KeyError(key) return getattr(self, key) def __str__(self): # python 3.6 # return f'{self.__class__.__name__}(a={self.a}, b={self.b}, c={self.c})' # python 3.5

Package : cx_Oracle for Python 3.5, windows64 bit. Oracle 11.2.0.1.0

ぃ、小莉子 提交于 2019-12-04 17:31:38
I am trying to install cx_Oracle on my windows PC. I ran following command in command prompt: pip install cx_Oracle This is giving me the following error: Collecting cx-Oracle Could not find a version that satisfies the requirement cx-Oracle (from versions: ) No matching distribution found for cx-Oracle I am using windows 64bit machine and Python 3.5(Anaconda3) . Intsalled Oracle vcersion on my PC is Oracle 11.2.0.1.0 and oracle-instantclient version oracle-instantclient-11.2.0.4.0-0 Please let me know what am I missing. Should I downgrade my python version to 3.4? If yes, than how to do it

Python printing function output multiple times

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:09:05
I'm making a program to accomplish a certain python challenge . I created the program, and it basically does everything I need it to do, except it's got one weird quirk; it prints the output I want multiple times. cmdname = input("Enter the name of your command.\n>") print("Enter options one by one. If the option has an argument, put a * at the end of the option. When done entering options, enter \"q\".") oplist = "" oplist += cmdname + " " def prgm(): global oplist while 2 + 2 == 4: user = input(">") if user[0] == "-": if "*" in user: oplist += user[0:len(user) - 1] + " " print("Now, enter

ImportError: No module named 'urllib2' Python 3 [duplicate]

房东的猫 提交于 2019-12-04 16:54:02
问题 This question already has answers here : Import error: No module name urllib2 (8 answers) Closed 3 years ago . The below code is working fine on Python 2 but on Python 3 I get the error: "ImportError: No module named 'urllib2'" import urllib2 peticion = 'I'm XML' url_test = 'I'm URL' req = urllib2.Request(url=url_test, data=peticion, headers={'Content-Type': 'application/xml'}) respuesta = urllib2.urlopen(req) print(respuesta) print(respuesta.read()) respuesta.open() Please suggest me the

Did something about `namedtuple` change in 3.5.1?

守給你的承諾、 提交于 2019-12-04 16:10:54
问题 On Python 3.5.0: >>> from collections import namedtuple >>> cluster = namedtuple('Cluster', ['a', 'b']) >>> c = cluster(a=4, b=9) >>> c Cluster(a=4, b=9) >>> vars(c) OrderedDict([('a', 4), ('b', 9)]) On Python 3.5.1: >>> from collections import namedtuple >>> cluster = namedtuple('Cluster', ['a', 'b']) >>> c = cluster(a=4, b=9) >>> c Cluster(a=4, b=9) >>> vars(c) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: vars() argument must have __dict__ attribute

Function That Receives and Rotates Character - Caesar Cipher

雨燕双飞 提交于 2019-12-04 15:27:03
I'm trying to create a function rotate_character(char, rot) that receives a character, "char" (a string with a length of 1), and an integer "rot". The function should return a new string with a length of 1, which is the result of rotating char by rot number of places to the right. So an input of "A" for char and "13" for rot would return N (with A having an initial value of 0, and B having an initial value of 1, etc). Capitalization should be maintained during rotation. I already created a function that returns the position of a letter in the alphabet by using a dictionary: letter = input(

cx_Freeze Exe Application closes as soon as opens

大憨熊 提交于 2019-12-04 09:41:32
I am trying to just convert my pygame python project to a .exe file using cx_Freeze. The setup file executes correctly and without error, but the issue is that when I run my .exe file the console window will open and close and my game window will not appear. The setup.py I am using: import os os.environ['TCL_LIBRARY'] = "C:\\Users\\MY_USERNAME\\AppData\\Local\\Programs\\Python\\Python35-32\\tcl\\tcl8.6" os.environ['TK_LIBRARY'] = "C:\\Users\\MY_USERNAME\\AppData\\Local\\Programs\\Python\\Python35-32\\tcl\\tk8.6" import cx_Freeze executables = [cx_Freeze.Executable("main.py")] cx_Freeze.setup(