Newest python Questions

Q&A for professional and enthusiast programmers

python ET.tostring(root, encoding='Unicode', method='xml') raise TypeError: a bytes-like object is required, not 'str'

Somebody knows why this code is ok: text='''<?xml version="1.0"?> <data> <country name="Liechtenstein"> <rank>1</rank> <year>2008</year> ...

How to generate an updating list with flask, mysql and jquery [duplicate]

Within my flask app I have table of data being displayed using data from mysql. At the top of this table I have a button Refresh Sources when this is clicked it invokes a function that scrapes more ...

Force reload on SimpleHTTP Server in Python

I have a very simple HTTPServer implemented in Python. The code is the following: import SimpleHTTPServer import SocketServer as socketserver import os import threading class MyHandler(...

Cannot navitage through a website after login with Requests, i.e. I always get the login webpage html code

Following the very nice explanations on this blog post about "Logging in With Requests" and the code snippet from this answer to a question on SO about 'How to “log in” to a website using Python's ...

Using nearest neighbour approach for clustering time series

Most of the time series clustering algorithms requires a distance matrix. DBSCAN doesn't require it but it doesn't guarantee that series in one cluster will be within some alpha distance with each ...

What is the “Best Practice” for invoice calculations in Django 1.10+?

If one has two models: class Invoice(models.Model): class Meta: ordering = ('-date_added', ) number = models.CharField(max_length=10,) comments = models.TextField(blank=True, ...

How to detect multiple people standing still using opencv and python?

I have been doing a project on turning webcam in to survilence camera that can detect certain kind of behavior in this case standing still using opencv and python. Here's a code from human detection ...

Difference between cross_val_score and cross_val_predict

I want to evaluate a regression-model build with scikitlearn using crossvalidation and getting confused, which of the two functions cross_val_score and cross_val_predict I should use. One option would ...

Setting index.max_result_window IBM Watson Discovery Service

I've researched Stack Overflow and found the method to increase this parameter if I have a .yml file for elastic search. However, if I am running a python script accessing the Watson Discovery REST ...

Nested generator object context

today I've played around with nested generator functions and found an interesting property / behavior which I can't explain to myself. Maybe this is associated with a lack of understanding of what ...

Use Dense layer directly

In this file there is a definition of a Dense layer, as well as its functional counterpart, dense. I get how to use dense; but in my case I need to apply the same dense layer several times to ...

Login to linux device connected on the UART port of BBB

I have a BBB and another linux based system which is connected on the UART4 of BBB i.e /dev/O4. I want to login to that device and execute some test scripts with an automated script. It should not be ...

pymysql - pymysql.err.InternalError: 1054, user input string used as column name

I am new to Python and MySQL so I am practicing with a readonly account. I am trying to create an executable script that basically asks for a first name, last name, then inserts them into the query ...

Sorting multiple numpy arrays

I have two numpy arrays in the same shape. np.array_one = ([[1,4],[3,1]]) np.array_two = ([['A','B'],['C','D']]) I can sort multiple lists in python using zip, is there an equivalent for numpy ...

Maya AbcExport with Python

I have the script to export an Alembic from Maya with MEL : AbcExport(-frameRange 31 41 -writeVisibility -dataFormat ogawa -root |myChar:char|myChar:GEOchar -file E:/test.abc) I would like to do the ...

How to add the host's public key file to a sftp connection using Python?

I have written a simple program which connects to the host's sftp site successfully and can retrieve files. import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = None srv = pysftp.Connection(...

Python Scrapy scrape nested webpage content

I am new to Scrapy and trying to learn scraping. i am practicing on a website that has nested content like after click 4 pages in browser then i get to the data page, but how do i return the item that ...

Python : using awk with multiple variables in subprocess.call

I'm working with a PDB file which contains multiple records. Here is an example file if you're not familiar with this type of format: HEADER GROWTH FACTOR 16-JAN-96 ...

Install mysqlclient for Django Python on Mac OS X Sierra

I have already installed Python 2.7.13 Django 1.11 MySQL 5.7.17 I want use MySQL with Django, but after install mysql connector I was try to install mysqlclient for Python on $ pip install ...

duplicate key value violates unique constraint “wagtailcore_page_path_key” DETAIL: Key (path)=(0001) already exists

I am working on a system that has been developed by someone else based on Django and wagtail. I managed to import data to postgresql but I believe not everything was imported since I get an error when ...

SparkContext Unsuccessfully Initialised in Eclipse Neon on Windows

PySpark works fine in my Windows CMD lines. However, when I executed the lines below in Eclipse (configured, with PyDev installed), Eclipse returns the error below. Can you please help? Lines ...

Python deleting a block of lines from a file

I'm struggling to figure out as to how I should go about deleting a block of lines from a file. Below is the code #!/usr/bin/python import argparse import re import string ##getting user inputs p = ...

Python Matplotlib Box Plot Two Data Sets Side by Side

I would like to make a boxplot using two data sets. Each set is a list of floats. A and B are examples of the two data sets A = [] B = [] for i in xrange(10): l = [random.random() for i in ...

pip install matplotlib fails on Raspbian Jessie 4.4

I'm trying to install matplotlib on a raspberry pi with a clean installation of Raspbian Jessie (4.4 at time of writing). I am trying to install matplotlib for Python 2.7. I keep getting the ...

Loop over list of lists and use ith iterator

So I have the following list of lists: test = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] I would like to loop over the ith element in the contained list. I can do this by using zip: for x, y, z in zip(test[...

How i can change phash in python?

I am a beginner in python and I am looking for a solution to change the phash of an image without making visible changes. thank you in advance.

How to modify the name of a file? [duplicate]

Let's suppose that this is the name of my numpy file: File1.npy File2.npy I need to modify the name of the file by adding an important information: File1_SV1. npy File2_SV2 I try by using this ...

What uwsgi caching framework cache key‘s content?

My Python web application starts with uwsgi --cache2 name=mycache,items=100000, I found it uses more RSS memory than starting with uwsgi --cache2 name=mycache,items=1. In the uwsgi log, I find a ...

Insert an array in postgresql

I use python to connect to my postgresql database. I parse a XML fill to populate my base, so I have an array[] of values for one line to insert. I have something like this: cur.execute("""INSERT ...

Using Scrapy to Post Form Data

My ultimate goal is to scrape the response of a web page that can only be reached after posting form data to previous pages-- in this case, I need to post to main_url to get to page_1 and then post ...

Python for university

In python, we pass a number by parameter and we have to return all possible combinations of positive integers that added give the initial number (e.g. give us the number 4 and we return ((1, 1, 1 , 1),...

how can i make a list from 1 to a certain number [duplicate]

how can i make a list of number form 1 to a certain number? i want to make a script that can do things like below: number=20 list=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] i don't know ...

Transferring a powershell script with PyWinRM from Linux to Windows

I am trying to transfer a powershell script written in Linux to a Windows machine hosted in Azure. The idea is to copy the script to the windows machine and execute it. I am using PyWinRM to ...

Automating a condition to check for an upper threshold

I have something known as constraint-matrix where each user(muid) can be sent a content(tactic) max N times. So I have represented it as a dataframe as: tactic max_times 100 50 101 35 ...

Serving Django CMS Admin Styles in Production with Apache

I made a simple site using Django CMS. Everything seems to work, except for the styles on the admin toolbar. They are not loading. What should I do to configure the app or server to serve them ...

Packing a Python web app for pip distribution

I'm running into an issue with my view directory that contains many subdirectories and non-python files (.html, .css, .ts, .js). Here is a diagram for you... - my_python_web_app - __init__.py ...

“{ }” appear around the output of a variable in python [duplicate]

I am building a file name using some values from a dictionary and changing some values based on the ones being pulled up and other criteria. This is then being passed to the file dialog function as ...

How to compare an empty list and a list of string in python?

data1= [('hello world', [])] data2= [('hello world', 'greetings')] I have two lists, data1 and data2. I want to compare the values at 2nd position of both the lists. I am using the following ...

Django: Bokeh.safely is not a function

I was trying to embed a bokeh plot into my django app. I followed the instructions given on Bokeh website and another question. I am getting the following error on my browser console and not getting ...

create site as alltop.com with django

way or package for create a site example site: www.alltop.com with framework django. for Implementation of these sites with Django framework, what measures should be taken? this site alltop use rss ...

ImportError: /usr/local/lib/libgnuradio-mapper.so: undefined symbol: _ZN2gr5blockC2ERKSsN5boost10shared_ptrINS_12io_signatureEEES6_

I try to import mapper,a gr-modle,which could be find here I have install the gr-mapper like: mkdir build cd build cmake .. make sudo make install sudo ldconfig under the usr/local/lib when i use ...

Removing backslash escape for bash script in python

I'm trying to run a bash expression in python but got really stuck at escape sequence. Bash expression: grep 'NODE_FW' /etc/config/node.py | cut -d ',' -f2,3 | tr ',' '.' | tr -d \'\" Python error:...

ERROR compile ATLAS before scipy

I'm trying to install scipy package to my local python folder on cluster. (Without root permission) ATLAS installation is proceed by this way: tar -jxvf atlas3.10.0.tar.bz2 cd ATLAS mkdir obj64 ../...

Chromedriver closing after test

So my understanding is that calling driver.quit or close is the the proper way to close the driver and associated window. However when running my tests, it seems that even without calling driver....

nginx ini file throwing error (Permission denied [core/socket.c line 230])

When we run .ini file with sudo it's working fine. But without sudo it throwing following error, /home/ubuntu/.local/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! your ...

Search for a text in text file stored as array

I have a text file where my data is stored as arrays; Example: {'id': '1', 'name': 'a', 'color': 'red'} {'id': '2', 'name': 'b', 'color': 'blue'} {'id': '3', 'name': 'c', 'color': 'yellow'} {'id': '...

How to execute a ruby/python script using HTML?

I want to execute a sample.rb/sample.py script from the command line using a button in my HTML page ... How is that possible?

Python: xgboost can import but unable to use due to no attributes existing?

The most similar question I found was here: AttributeError: module ‘xgboost’ has no attribute ‘XGBRegressor’ However it had no solution. I used these instructions to install it: https://www.ibm....

create a list of exponential decay with a predetermine half-life python

I am trying to create a list of exponential decay of fix length with a predetermine half-life as efficiently as possible. so assuming I want I half-life of 1 and a list length of 5 it would return :...

Delete and duplicate rows in numpy array

In Python, let's say I have a 1366x768 numpy array. And I want to delete each second row from it (0th row remains, 1st removed, 2nd remains, 3rd removed.. and so on), and replace the empty space with ...
Translating... 0%