python-3.6

How to route tasks to different queues with Celery and Django

Deadly 提交于 2019-12-21 16:57:53
问题 I am using the following stack: Python 3.6 Celery v4.2.1 (Broker: RabbitMQ v3.6.0 ) Django v2.0.4 . According Celery's documentation, running scheduled tasks on different queues should be as easy as defining the corresponding queues for the tasks on CELERY_ROUTES , nonetheless all tasks seem to be executed on Celery's default queue. This is the configuration on my_app/settings.py : CELERY_BROKER_URL = "amqp://guest:guest@localhost:5672//" CELERY_ROUTES = { 'app1.tasks.*': {'queue': 'queue1'},

How to compare a string with a python enum?

我只是一个虾纸丫 提交于 2019-12-21 03:12:49
问题 I just discovered the existence of an Enum base class in python and I'm trying to imagine how it could be useful to me. Let's say I define a traffic light status: from enum import Enum, auto class Signal(Enum): red = auto() green = auto() orange = auto() Let's say I receive information from some subsystem in my program, in the form of a string representing a colour name, for instance brain_detected_colour = "red" . How do I compare this string to my traffic light signals? Obviously, brain

How to install cvxopt on on windows 10 on python 3.6

坚强是说给别人听的谎言 提交于 2019-12-20 10:45:05
问题 How do I install cvxopt on windows 10 on python 3.6? When running conda install cvxopt Fetching package metadata ........... Solving package specifications: . UnsatisfiableError: The following specifications were found to be in conflict: - cvxopt -> python 3.5* - python 3.6* Use "conda info <package>" to see the dependencies for each package. I apologize i am on windows... Any ideas? 回答1: After much trial and error, I found that we need to install both the numpy+mkl package and the

Understanding __init_subclass__

江枫思渺然 提交于 2019-12-20 09:09:29
问题 I finally upgraded my python version and I was discovering the new features added. Among other things, I was scratching my head around the new __init_subclass__ method. From the docs: This method is called whenever the containing class is subclassed. cls is then the new subclass. If defined as a normal instance method, this method is implicitly converted to a class method. So I started to playing around with it a little bit, following the example in the docs: class Philosopher: def __init

Why does the **kwargs mapping compare equal with a differently ordered OrderedDict?

我的未来我决定 提交于 2019-12-19 15:46:31
问题 According to PEP 468: Starting in version 3.6 Python will preserve the order of keyword arguments as passed to a function. To accomplish this the collected kwargs will now be an ordered mapping . Note that this does not necessarily mean OrderedDict . In that case, why does this ordered mapping fail to respect equality comparison with Python's canonical ordered mapping type, the collections.OrderedDict : >>> from collections import OrderedDict >>> data = OrderedDict(zip('xy', 'xy')) >>> def

How can I adjust pip3 using python3.6 not python3.4 on Ubuntu 14.04?

a 夏天 提交于 2019-12-19 09:07:45
问题 Default python3 on Ubuntu 14.04 is of 3.4.3 but I want to use 3.6.3 instead. I followed commands below to install 3.6.3 : $ sudo apt-get update $ sudo apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev $ sudo apt-get install python3-pip python3-dev $ sudo add-apt-repository ppa:jonathonf/python-3.6 $ sudo apt-get update $ sudo apt-get install python3.6 3.6.3 was then available on my Ubuntu: $ which python3.6 /usr/bin/python3.6 For sure, python3 was still

Generic NamedTuple in Python 3.6

喜欢而已 提交于 2019-12-19 03:40:10
问题 I'm trying to create a generic version of a NamedTuple, as follows: T1 = TypeVar("T1") T2 = TypeVar("T2") class Group(NamedTuple, Generic[T1, T2]): key: T1 group: List[T2] g = Group(1, [""]) # expecting type to be Group[int, str] However, I get the following error: TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases I'm not sure how else to achieve what I'm trying to do here, or if this might be a bug in the

Tkinter code runs without mainloop, update, or after

旧巷老猫 提交于 2019-12-18 09:56:07
问题 I have been trying to use tkinter to make a gui to select some excel files and sheets from those files. I have a lot of experience in python, but I'd probably say a novice at tkinter. The code I have written to select the files is shown below (typos are likely because I cannot access the internet on the machine these files are on, so I am typing it up here). My question is about mainloop() , the update functions, and after() . I had mainloop() at the end of my code, but my program wouldn't

Python 3 Boto 3, AWS S3: Get object URL

跟風遠走 提交于 2019-12-18 08:47:27
问题 I need to retrieve an public object URL directly after uploading a file, this to be able to store it in a database. This is my upload code: s3 = boto3.resource('s3') s3bucket.upload_file(filepath, objectname, ExtraArgs={'StorageClass': 'STANDARD_IA'}) I am not looking for a presigned URL, just the URL that always will be publicly accessable over https. Any help appreciated. 回答1: There's no simple way but you can construct the URL from the region where the bucket is located ( get_bucket

Custom Evaluation Function based on F1 for use in xgboost - Python API

偶尔善良 提交于 2019-12-18 07:23:01
问题 I have written the following custom evaluation function to use with xgboost, in order to optimize F1. Umfortuantely it returns an exception when run with xgboost. The evaluation function is the following: def F1_eval(preds, labels): t = np.arange(0, 1, 0.005) f = np.repeat(0, 200) Results = np.vstack([t, f]).T P = sum(labels == 1) for i in range(200): m = (preds >= Results[i, 0]) TP = sum(labels[m] == 1) FP = sum(labels[m] == 0) if (FP + TP) > 0: Precision = TP/(FP + TP) Recall = TP/P if