python-3.5

How to install Scrapy on Ubuntu 16.04?

岁酱吖の 提交于 2019-12-24 04:57:35
问题 I followed the official guide, but got this error message: The following packages have unmet dependencies: scrapy : Depends: python-support (>= 0.90.0) but it is not installable Recommends: python-setuptools but it is not going to be installed E: Unable to correct problems, you have held broken packages. I then tried sudo apt-get python-support , but found ubuntu 16.04 removed python-support . Lastly, I tried to install python-setuptools , but seems it only would install python2 instead. The

How to print a value with double quotes and spaces in YAML?

廉价感情. 提交于 2019-12-24 04:31:45
问题 I am trying to dump a Python dictionary to YAML which has some strings as value fields. import yaml str1 = "hello" str2 = "world" mystr = "\"" + str1 + str(" ") + str2 + "\"" mydict = {"a" : mystr} f = open("temp.yaml", "w") yaml.dump(mydict, f, default_flow_style = False, \ explicit_start = "---", explicit_end = "...", encoding = 'UTF-8') f.close() the YAML I get is: a: '"hello world"' Notice, the value "hello world" is spilling to the next line. I am using python 3.5 and YAML module version

Python3 tkinter.Canvas.move() method makes artifacts on screen

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 04:05:41
问题 I'm trying to execute the code found in one of the Stackoverflow answers. It's a single window application with 2 circles which can be moved with the mouse. When I move circles - I see artifacts. See Sample Program code: import tkinter as tk TOKENWIDTH = 10 class Example(tk.Frame): '''Illustrate how to drag items on a Tkinter canvas''' def __init__(self, parent): tk.Frame.__init__(self, parent) # create a canvas self.canvas = tk.Canvas(width=400, height=400, bg="white") self.canvas.pack(fill=

How to limit the Scope of element extraction between the start and end tag of a particular xml element using XPath in Python?

烈酒焚心 提交于 2019-12-24 02:42:47
问题 I have an RDF/XML Element and would like to find out all the elements between the start and end of a particular tag. How could I do that? for example : <cim:BaseVoltage rdf:ID="_0526B48408F744919E7C03672FCD0D71"> <cim:BaseVoltage.isDC>false</cim:BaseVoltage.isDC> <cim:BaseVoltage.nominalVoltage>400.000000000</cim:BaseVoltage.nominalVoltage> </cim:BaseVoltage> I would like to extract the values BaseVoltage.isDC and BaseVoltage.nominalVoltage, since they are between the start and end tag of .

tkinter.Listbox scrolbar yview

五迷三道 提交于 2019-12-24 01:59:16
问题 I again encounter some problems in writing Python and would like to seek my help. I continue to build my Listbox widget but cannot setup a scrollbar. I can put the Scrollbar in the right position, however, the up and down just don't work out and pop up an error saying "Object() takes no parameter". Could anyone advise how to fix it? I attached the code below for reference. import tkinter from tkinter import * def test(): root = tkinter.Tk() lst = ['1', '2', ' 3', '4', '5', ' 6', '7', '8', ' 9

Asyncio worker that handles N jobs at a time?

ε祈祈猫儿з 提交于 2019-12-24 01:19:55
问题 I'm trying to make an asyncio worker class that will consume jobs from a job queue and process up to N jobs in parallel. Some jobs may queue additional jobs. When the job queue is empty and the worker finishes all of its current jobs, it should end. I'm still struggling with asyncio conceptually. Here is one of my attempts, where N=3 : import asyncio, logging, random async def do_work(id_): await asyncio.sleep(random.random()) return id_ class JobQueue: ''' Maintains a list of all pendings

Simultaneously create attributes and edges (if same attr. exists) in NetworkX

爱⌒轻易说出口 提交于 2019-12-23 22:02:19
问题 After creating nodes in NetworkX, I would like add edges between nodes if both nodes have (at least) one overlapping same attribute. It seems to be a problem that not all nodes contain the same number of attributes - could this be the case, and if so, how should I solve it? import networkx as nx from itertools import product # Mothernodes M = [('E_%d' % h, {'a': i, 'b': j, 'c': k, 'd': l}) for h, (i, j, k, l) in enumerate(product(range(2), repeat=4), start=1)] # children nodes a = [ ( 'a_%d'

Setting cumulative values to constant after it reaches threshold

六眼飞鱼酱① 提交于 2019-12-23 21:44:47
问题 I have a pandas time series which contains cumulative monthly values. If in a month on a certain date, the value becomes a certain number, I need to set rest of the days to 1000. E.g. df: Date cummulative_value 1/8/2017 -3 1/9/2017 -6 1/10/2017 -72 1/11/2017 500 1/26/2017 575 2/7/2017 -5 2/14/2017 -6 2/21/2017 -6 My cutoff value is -71 so in above example I need to achieve the following: Date cummulative_value 1/8/2017 -3 1/9/2017 -6 1/10/2017 1000 1/11/2017 1000 1/26/2017 1000 2/7/2017 -5 2

How to print out specific rows/lines in a text file based on a condition (greater than or less than)

回眸只為那壹抹淺笑 提交于 2019-12-23 19:46:44
问题 I am trying to code a program that prints out the specific rows/lines where one value exceeds the other one in that line. For example ,this is a small part of the text file: 01,test1,202,290,A,290 02,test2,303,730,A,0 03,test3,404,180,N,180 The program that I am trying to code would select all lines that have 'A' in them but also select the lines where the 4th column (290 for the first line) is greater then the 6th column (290 in the first line)and then print them.So the program should only

Numpy dot operation is not using all cpu cores

末鹿安然 提交于 2019-12-23 19:13:14
问题 I am doing numpy dot product on two matrices (Let us assume a and b are two matrices). When the shape of a is (10000, 10000) and shape of b is (1, 10000) then the numpy.dot(a, b.T) is using all the CPU cores. But when the shape of a is (10000, 10000) and shape of b is (2, 10000) then the numpy.dot(a, b.T) is not using all the CPU cores (Only using one). This is happening when the row size of b is from 2 to 15 (i.e from (2, 10000) to (15, 10000)). Example: import numpy as np a = np.random.rand