Python is a dynamic and strongly typed programming language designed to emphasize usability. Two similar but mostly incompatible versions of Python are in widespread use (2 and 3). If you have a version-specific Python question consider using the [python-2.7] or [python-3.x] tags in addition to the [...

learn more… | top users | synonyms (3) | python jobs

0
votes
1answer
17 views

What is the alternative to str.translate in python 3?

I am using the following function to remove numbers from filenames. import os def rename_files(): file_list = os.listdir(r"C:\Users\X\Downloads\Compressed\prank\prank") ## print(file_list) ...
0
votes
0answers
7 views

Updating csv file Integer Values into point shape file String Values using dictionaries

I am having some trouble converting a CSV file field values (Integers: 0 or 1 values) into string values (No Pickle Shots Pickle Shot Bar) after converting the CSV file into a point shapefile. I think ...
0
votes
1answer
9 views

TypeError: unbound method mult() must be called with calculadora instance as first argument (got int instance instead)

I get a TypeError: unbound method mult() must be called with calculadora instance as first argument (got int instance instead) when running my python file : from __future__ import ...
0
votes
0answers
10 views

How to build an advanced website crawler in python?

I'm trying to build a website crawler that collects unique links on this site, runs through a list of these collected links, detects a specific logo and iterates through these unique collected links ...
1
vote
0answers
7 views

Properties Format on Geojson to MongoDB/Mongoengine

I would like to find a solution on what DataField I should give to a geojson with a properties column. Currently a geojson format below would not have any issues since it it would only need the ...
1
vote
1answer
13 views

Python referencing counting: Why isn't Py_REFCNT(o) = 1?

I'm trying to track down a memory leak in a Python C extension, and am having trouble understanding why my code is giving the reference counts that it is. Referring to the code example that follows, ...
0
votes
0answers
9 views

How to reuse setup code of Django tests?

Writing setUp function of test case is a challenging work. Since code lines increasing. I have to write some similar code in different test case. How to improve the reusability?
0
votes
4answers
20 views

Iterate over python dictionary to retreive only required rows

I am getting the data in HTML table format from external source - from xml.etree import ElementTree as ET s = """<table> <tr><th>Release</th><th>REFDB</th><...
0
votes
1answer
13 views

Django : combine variable and HTML id in template

I'm looking for a way to "concatene" a django object list (get via the get_queryset in the views.py) with a Javascript variable. then concatene them to a field of a model object. My model is a blog ...
0
votes
0answers
10 views

Pandas Dataframe - find max between two columns

I have a very dumb question: Suppose I have a pandas dataframe which list students's score on several classes. What's the best way to find out which students had the biggest difference between their ...
0
votes
0answers
6 views

Error while scraping data from twitter using tweepy

I am trying to Scrape tweets from twitter into a DB and then Convert the DB to a CSV file. import settings import tweepy import dataset from textblob import TextBlob from sqlalchemy.exc import ...
1
vote
1answer
15 views

How can I make two differents login forms in Django?

How can I log in and redirect to his "Dashboard" and a login form for the admin site and redirect to his "Admin Panel" I have been looking for and read that it can be done by creating a ModelBackend ...
1
vote
0answers
11 views

How to inject csrf token into request before POSTing from a python function?

I am doing a POST request from a python function. Is there a helper to add csrf to the POST body? I tried the csrf_protect decorator but that does not seem to work in this case. I think it works for ...
0
votes
0answers
15 views

Python / Kivy - TypeError: 'int' object is not iterable

I'm trying to put a label in the screen, when I just do this works, but when I try to format the text, with Label's "text_size" I get this error: "TypeError: 'int' object is not iterable" Here is the ...
0
votes
0answers
6 views

nodebox -python simple animation doesn't work

here's my code using nodebox 1.9 and python3. when I try to draw the still image it works, however, whenI'm try to animate it using this template https://www.nodebox.net/code/index.php/Animation it ...
0
votes
0answers
7 views

Is there a way to subclass the zoom() function from the NavigationToolbar backends and modify its mouse motion definition?

First of all, I have to say the predefined functions from matplotlib is wonderful. For historical reasons, however, I need to modify the mouse motion for the zoom() function to do the following, ...
0
votes
0answers
10 views

show the point value on mouse hover

I have the following plot. How can I show the point value on mouse hover. Could anybody help me. import matplotlib.pyplot as plt plt.plot([1,2,3,4], [1,4,9,16], 'ro') plt.axis([0, 6, 0, 20]) plt.show(...
0
votes
1answer
12 views

What does replacement mean in numpy.random.choice?

Here explains the function numpy.random.choice. However, I am confused about the third parameter replace. What is it? And in which case will it be useful? Thanks!
0
votes
0answers
6 views

python threaded port scanner

When my app has gone through all the ports it should print "done." But it's not. This is what I have: import time import socket import threading from queue import Queue printLock = threading.Lock() ...
0
votes
1answer
11 views

Django TypeError from Ajax action

I'm using DjangoTables to display records. I want to use Ajax on a Delete link to delete the relevant Site record (and the Deal records linked to it) without having to refresh the table page. ...
0
votes
2answers
27 views

Using .strip() to remove spaces in every element of a 2D list and removing the last element and the second from each list

First question I would like to know how you can use .strip() function in a 2D list so that in each element of each list inside a list, you can remove the useless spaces inside the strings. Here's my ...
1
vote
2answers
27 views

Printing correct message

I use voice recognition and check a list for a colour, if what I said isn't in the list then it displays 'Colour not found' if it is found it displays 'Colour Found' I only want it to display each ...
0
votes
0answers
5 views

import xlwings, missing files from numexpr package

I'm trying to get started with xlwings, but am recieving a few errors when I go to import it. I pulled up my OSX terminal, ran pip install xlwings no problem there. Fired up python $ python ...
1
vote
0answers
8 views

gstreamer 1.0 + python: dynamic link and unlink queues from a PLAYING pipeline

Pipeline architecture I'm trying to implement the script works well when both the queues are linked together before setting the pipeline to PLAYING, but I'm having a hard time understanding gstreamer ...
0
votes
0answers
12 views

Creating a readfile function with PPMImage

Super new at Python let alone coding. I am stuck on this assignment dealing with PPMImage and creating a readfile function. Our professor gave us these hints for the function: "Create a PPMImage ...
-1
votes
0answers
16 views

Retrieve comments from Huffington Post Article

I am aiming to retrieve comments from a HuffingtonPost article, and I am looking if there is an existing way of doing it or if there is a specific API that would help me implementing it.
0
votes
1answer
15 views

What is the function doing in the python list? [duplicate]

char_set = [False for _ in range(128)] for char in string: val = ord(char) if char_set[val]: # Char already found in string return False char_set[val] = ...
0
votes
1answer
11 views

Check for values in data frame columns, return one.

Probably a quick and easy task for most of the people here. Though, for me starter in python in gave some problems. Lets say we have: DATA. g=pd.DataFrame({'AGGRESSION':[0,1,0,0,1], 'DECEPTIVENESS':[...
0
votes
1answer
5 views

Python Multiplexed server using select.select won't accept clients simulaneously

All this program should do is accept inputs from 2 clients simultaneously and print them out, but instead it accepts 1 input from the first client to connect, then starts accepting inputs infinitely ...
0
votes
1answer
16 views

Indexing issue that doesn't make sense when trying to scrape using BeautifulSoup

I'm trying to use the script below to go through a list of urls, find the date of each race per url and find the location of each race per url. I am getting an IndexError for out of range, but I know ...
0
votes
2answers
23 views

consistent formatting of strings from a dictionary with labels in a python print statement

I have a dictionary that looks something like this: d = { 'last_price': '760.54', 'change': 'N/A', 'days_range': '760.00 - 775.00', 'previous_close': '771.23', 'change_percent': '-...
0
votes
0answers
8 views

Get specific bytes in payload from a pcap file

I have a PCAP file which I am parsing using Scapy, I have managed to dump the payload to a hexdump by using the code bellow pkts = rdpcap('Sink.pcap') print hexdump(pkts[0][2].load) I get the ...
0
votes
1answer
12 views

How to parallelize functions that return values in python?

I have two functions,core_ensembling and sampling.core ensembling return values.I need to parallelize the core_ensebling function inside sampling function.that is i need to parallely compute set1,...
-1
votes
2answers
44 views

Rolling 5 dice in python

I was given: def rollDice(dice, toRoll=[0,1,2,3,4]): """Rolls specified dice. If no dice are specified, all dice are rolled.""" for i in toRoll: dice[i] = random....
-4
votes
2answers
24 views

How can I roundup the number in this special kind of situation in Python?

I was trying to figure out how to roundup. Exmaple: 3.1049 -> 3.11 how can I roundup this? Thanks! EDIT: num = 3.1049 print (round(a, 2)) >>> 3.1 but I want: >>>3.11 #as ...
0
votes
1answer
11 views

Installing theano on Windows 7 x64 (cannot import name gof)

I am trying to install Theano on my Windows 7 x64 machine. I have followed about 5 different tutorials trying to get it installed properly. Some of them are in these links: http://deeplearning.net/...
0
votes
0answers
9 views

SMTPlib Attachments not received

I've been using code based on the snippet at http://datamakessense.com/easy-scheduled-emailing-with-python-for-typical-bi-needs/ to send PDF attachments to customers through my company's email. We ...
0
votes
1answer
17 views

Exception while printing inside a try block

I am trying to print the user ID (int type) and name(varchar type) inside a try block. After enterint details on UID and name, while trying to print the entered value the except block is getting hit. ...
0
votes
0answers
20 views

Function evaluations stuck when using multiprocessing

I need to evaluate a function many times. To do it faster I want to use multiprocessing. The function I need to evaluate basically does these steps (see detailed code below): Reads data from file for ...
0
votes
1answer
18 views

More efficiently computing probabilities

I'm struggling with some coding-inexperience. The code I've written below, is extremely inconvenient and ugly to look at. My question to you is: How can this be done more efficiently? The way I've ...
0
votes
2answers
33 views

Python: I am trying to use a function returned by another function

I am learning Python for scientific computing, and there is an exercise where I create a polynomial using its roots: Exercise 3.5 from sympy import symbols, expand def poly(roots): #...
3
votes
0answers
11 views

Python SVM TypeError: __init__() got an unexpected keyword argument 'probability'

I'm trying to view the probabilities of each prediction from most probable class to least probable class, using this: results = grid_svm.predict_proba(title_test)[0] probability_class_dict = dict(...
1
vote
1answer
15 views

Why isn't go build finding Py_None?

I'm wrapping a Go library for Python. I need to be able to return None, but it's not finding it at compile time: /* #cgo pkg-config: python3 #define Py_LIMITED_API #include <Python.h> */ import ...
0
votes
1answer
24 views

Inserting value into a list of int just before the rightmost item greater than the value?

def insert(lst, v): """ (list of int, int) -> NoneType Insert v into lst just before the rightmost item greater than v, or at index 0 if no items are greater than v. >>> my_list = [3, 10,...
0
votes
1answer
16 views

Python :unit test throws <Response streamed [200 OK]> instead of actual output

from flask import jsonify @app.route('/urlinfo/1/<path:URL>', methods=['GET']) def search(URL): if something: a=dict(message="everything is good" resp=jsonify(a) return resp ...
-1
votes
0answers
9 views

Matplotlib works but matplotlib.pyplot doesn't [duplicate]

import matplotlib as plt works fine. import matplotlib.pyplot as plt gives error. IOError: [Errno 13] Permission denied: u'C:\\Users\\.......\\.matplotlib\\fontList.cache' I'm on Python 2.7 and ...
0
votes
0answers
37 views

Returning items as they come in Python

I am not quite sure I am using the correct terminology but I would like to have access to items being returned by my function before the function finishes. For example, I am working on a Django ...
0
votes
1answer
22 views

How to avoid lazy property evaluation on passing as argument in python

I have the following code for lazily calculating a value in python 3.5. I have also tried the @cached_property decorator with the same result, so I will use this for simplicity. class Foo: @...
0
votes
0answers
8 views

Python sqlite can't seem to count bind parameters?

I've got a little module doing some sqlite operations, and python/sqlite can't seem to count the number of arguments it's passing (thinks there's 7 parameters instead of 1)? sql = 'select * ...
0
votes
1answer
14 views

Python 3 files are assigned to wrong filename which I specify

This is a script that downloads an image from the web by first specifying its url. It then downloads it and stores it in my Downloads directory. The name the image is assigned is a random line from ...