Tagged Questions
Python is a dynamic and strongly typed programming language that is designed to emphasize usability. Two similar but incompatible versions of Python are in widespread use (2 and 3). Please consider mentioning the version and implementation that you are using when asking a question about Python.
0
votes
0answers
3 views
Touchscreen signature field?
Is there an easy way to capture signature on an ipad with python?
I want to digitize an application form for work that needs a signature at the bottom. To make it simple I'd like to make it a webapp ...
0
votes
3answers
18 views
Treating string as a list object in python
I'm writing a python program that takes user input from the command line. The user is told to enter in values in a list format, i.e. the user might enter [1, 2], [2, 7], [4, 3], etc.
I'm splitting ...
0
votes
1answer
9 views
Python Minimization involving 2D List
I'm trying to perform the minimization of a function f(x)
periods = range(1,11+1)
friends = range(0,7)
i = 0.05
def f(x):
sum = 0
for period in periods:
sum += x[period-1] * ...
0
votes
1answer
11 views
Finding files in directories in Python
I've been doing some scripting where I need to access the os to name images (saving every subsequent zoom of the Mandelbrot set upon clicking) by counting all of the current files in the directory and ...
0
votes
0answers
6 views
Getting file input into Python script for praw script
So I have a simple reddit bot set up which I wrote using the praw framework. The code is as follows:
import praw
import time
import numpy
import pickle
r = praw.Reddit(user_agent = "Gets the Daily ...
-2
votes
0answers
20 views
Splitting an array of integers into n parts where difference between sum of integers in each sub array is minimal
I have an array, A of of integers say {100,800,200,500,400,1000} into n sub arrays. The sum of the values in the sub array should be closest possible to the mean of the integers. So say n is 3. The ...
0
votes
0answers
4 views
flask unit test AttributeError: 'Blueprint' object has no attribute
I have a Flask web app with following structure
main-app
python_package_1 (it has init.py and a module called module1.py)
tests (with only one file test_one.py)
init.py (it actually has two ...
0
votes
0answers
5 views
Django: split up batch work in groups, minimize DB hits
http://stackoverflow.com/a/21079734/433570 They do what I describe below with user_feed.
What I want to do is basically, divide the whole into list of lists (not python list, the conceptual list)
...
0
votes
0answers
5 views
intend error can anyone please correct the code for me
import socket
import MySQLdb
TCP_IP = (’10.10.4.222’)
TCP_PORT = 32000
BUFFER_SIZE = 40
# ClearDB. Deletes the entire tracking table
def ClearDB(curs,d ):
curs.execute ("""
INSERT INTO gmaptracker ...
0
votes
0answers
15 views
2-D integration in python
I have arrays tuple (x, y, hist_pop(x, y)), where hist_pop is a histogram population associated with (x, y), and all arrays are of equal length. I want to do integration, something like: ...
-2
votes
1answer
7 views
Is there any way to run my django project in two digit port?
Is there any way to run my django project in two digit port?
Eg: python manage.py runserver 80
I am already changed the DEFAULT_PORT="80" in ...
0
votes
0answers
5 views
Flask in uWSGI causing 500 Internal Server Error just from importing SQLAlchemy
Everything works fine when I run flask via source venv/bin/activate && python run.py.
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
...
2
votes
1answer
14 views
Python dt.replace(tzinfo=) doesn't change timezome
Why doesn't replace modify the tzinfo object when it recieves a valid timezone
object?
I'm attempting to add the local time to timestamps that didn't specify a
timezone.
if raw_datetime.tzinfo is ...
0
votes
0answers
5 views
Installing pygame module in anaconda mac
I have anaconda installed on my mac. And it has messed with my pygame module.
I tried following this tutorial and replacing pip3 install pygame with conda install pygame. I have tried conda install ...
0
votes
1answer
10 views
Make python talk to local Flask app via browser
This might be a simple architecture question but I can't figure it out.
What I have:
Basically I have two apps running locally on my Raspberry pi:
One C++ app (Voicecommand) that allows me to ...
0
votes
0answers
12 views
use socket and return with fake ip
I'm trying to use socket lib to show ip and I'm wondering if I can return it with fake ip
Code like this :
in start.py there is :
import socket
realip = socket.gethostbyname(socket.getfqdn())
print ...
0
votes
1answer
21 views
Card generator game printing in a column, not a row
#-*- coding: UTF-8 -*-
#spade=u"\u2660"
#heart=u"\u2665"
#diamond=u"\u2666"
#clubs=u"\u2663"
import random
print 'Welcome to SANDCRAB. This is your deck of cards.'
seg1='''_________'''
seg2='''| ...
-1
votes
0answers
27 views
Infinite Mario Bros with Python
I'm trying to use my Python script in the Mario AI competition API, which is in Java. This is supposedly possible, but I have not been able to figure it out (for over 2 days now!). The competition ...
0
votes
0answers
3 views
Default install of Python Locust throws exception
Operating System: CentOS 7.0 x64
Interpreter: Python 3.4.1 compiled from source with --enable-shared
Example command:
$ python3.4 -c "import locust"
Traceback:
Traceback (most recent call last):
...
-2
votes
0answers
18 views
Create class to read a text file and assign the data to variables in class
Say I have a .txt document called trees.txt, that contains data for the Block, Plot, Species, DBH categories, separated by spaces. Each line represents a different tree. I need to create a class in ...
0
votes
0answers
12 views
Numpy: multiplying with NaN values without using nan_to_num
I was able to optimise some operations in my program quite a bit using numpy. When I profile a run, I noticed that most of the time is spent in numpy.nan_to_num.
A calculation occurring is a ...
0
votes
0answers
11 views
How to create a working directory using mkdir command in Mac OS X?
I started learning python recently and I am very new to programming.
My book tells the following :
On Unix-based systems (including Mac OS X and Linux), your working directory might be in ...
1
vote
0answers
13 views
Glob returns back an empty list in Python
My code:
hi = glob.glob("hi/FEC[0-9][0-9][0-9][0-9][0-9]_[0-9].seq")
I'm using a glob module and I'm trying to get all the path file names but all it returns back is a empty list. I don't know why ...
0
votes
1answer
19 views
Perform searching on very large file programatically in Python
I have a text file of size 2.5 GB which contains hash values of some standard known files. My task is to find the hash of all files on my file system and compare it with the hashes stored in the text ...
0
votes
1answer
9 views
Mixed formats with NumPy column stack
I am trying to stack column wise a list A and array B as shown below:
Input
A = ['A', 'B', 'C']
B = [[ 1 2 3 4 5 6]
[ 6 7 8 9 10 11]
[11 12 13 14 15 16]]
Desired output
C = ...
0
votes
0answers
7 views
Looping through webpages when href does not exist for certain pages
I am collecting reviews from the web. Some products have multiple pages of reviews; others have only one page. With the help of a few people here, I have written a code that basically makes the ...
1
vote
2answers
17 views
How can I test that a method on an imported module is called during object construction
I'm working on a Reddit bot to learn TDD in python.
I have a module with a class that is something like this:
from praw import Reddit
class Bot():
def __init__(self):
self.reddit = ...
1
vote
1answer
19 views
Integrate chessbord.js with Flask
I'm working with Flask and I'm having problems using chessboard.js with it.
My static folder is something like this:
/static/
/css/
/img/
/js
where I put the files for chessboard.js.
...
0
votes
3answers
31 views
Strip extra quotes from python list
I'm retrieve some data from a web API, but the retrieved records comes with extra quotes I need to remove; result = ['"A1","Location1"', '"A2","Location2"'] What is the most efficient way to do this ...
0
votes
3answers
14 views
Dynamically Removing string with regex python
I am currently having trouble removing the end of strings using regex. I have tried using .partition with unsuccessful results. I am now trying to use regex unsuccessfully. All the strings follow the ...
0
votes
0answers
22 views
How to force pyparsing to parenthesize infix notation “9 + 2 + 3”
Let's take a look at the simplest arithmetic example in the pyparsing doc, here.
More specifically, I'm looking at the "+" operation that is defined as left associative and the first example test ...
1
vote
0answers
14 views
Simple Image Deconvolution issue
I'm working on some very simple image deconvolution for proof of concept.
The goal is to convolve an image with a kernel (I'm using a 5*5 gaussian matrix) and then deconvolve it in the fourier ...
2
votes
2answers
38 views
In Python, what is the easiest way to add a list consisting of keyword pairs to a dictionary?
I have a homework problem in Python.
I am using Python version 3.4.0 on Linux.
The design document states that I am to read a CSV file using built in functions, specified as names.dat, that is in the ...
2
votes
0answers
30 views
I can't find what's wrong with this circle bounce calculation in python
I have a a program where circles can bounce into one another. I followed the directions from here for rotating the vectors and scaling the magnitudes based on the collision angle: ...
0
votes
0answers
5 views
Determine Postgresql datatype for a variable in Ruby, Python, or C++?
I've been using Ruby-pg so far as my interface for Postgres. I have data that comes in on a socket to my Ruby program, which then needs to go into a Postgresql database. Based on that data, a new ...
0
votes
0answers
8 views
Z3 v4.3.2 example.py execution error on Mac OS X 10.10
I'm trying to build Z3 newest version (v4.3.2) on Mac OS X 10.10.2.
Downloading the latest source from http://download-codeplex.sec.s-msft.com/Download/SourceControlFileDownload.ashx?he ...
0
votes
0answers
3 views
How to execute python script include pygraphviz from Java
I wrote a python script named great.py to generate Graphviz flowchart, so inside the code i need import pygraphviz.
#!/usr/bin/env python
import pygraphviz as pgv
G=pgv.AGraph()
G.add_node('a') # ...
0
votes
0answers
21 views
How do I specify the root module directory in python?
I have code that restores a few small excel files in python using pandas, and performs some data analysis on them. I'm now trying to setup testing of my code, but I'm running into some trouble and I ...
0
votes
1answer
13 views
Plotting a Network Graph with all edges clearly visible
I have a graph network data (using adjacency matrix) of 30 nodes. The graph currently looks like this:
Each cluster has 15 nodes and each node is connected to other node within the same cluster. ...
0
votes
1answer
17 views
Trying to print out data from database
I am trying to print out data from my database in python using the mySQL connect library. I want to print out all of the tuples in a specific table, however, it is not coming out how I would like. ...
0
votes
3answers
23 views
After answering to a raw_input, nothing happens
I am trying to make a project where you make choices to defeat a dragon. Here is what I have:
import time
print "Hello"
time.sleep(1.5)
print "Welcome to Kill the Dragon."
time.sleep(2)
print "In ...
1
vote
1answer
12 views
Python, image compression and multiprocessing
I'm trying to wrap my head round MultiProcessing in Python, but I simply can't. Notice that I was, am and probably forever be a noob in everything-programming. Ah, anyways. Here it goes.
I'm writing ...
0
votes
2answers
25 views
End looping function on function return - Python
My question is a bit confusing so I will explain it by saying exactly what I am trying to do.
I just got a Raspberry Pi and am writing a Python project with it. I have a function that makes a light ...
0
votes
2answers
6 views
python3.4 pip ImportError: No Module named 'pkg_resources'
pip is not working in my python3.4
$ pip install django
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
...
0
votes
0answers
11 views
handler to generate global variables in tornado
I have a top bar in my web application that is common to all the pages. The code for that is in a separate html file, called,base.html that's included in all the other pages(ex. sample.html). Now, I ...
0
votes
0answers
10 views
Flask “Pick-List” Widget
I'm trying to create this widget in Flask, to build a pivot table interface:
http://www.richwidgets.io/select/pick-list.html
I'm absolutely hopeless at web programming, and I can't find a clone of ...
0
votes
1answer
11 views
Pandas dataframe row reduction/compression (for rows having the same value)
I have a df such as:
seed value
1 2
1 3
1 4
2 20
2 60
would like to get a shorter dataframe (df_short) with the average value for same seeds, such as
seed value
...
0
votes
0answers
8 views
how to optimize numpy code for Markovian path
Below is a python function to generate Markov path(the travelling salesman problem).
def generate_travel_path(markov_matrix, n):
assert markov_matrix.shape[0] == markov_matrix.shape[1]
assert ...
1
vote
1answer
26 views
Sorting a list of dictionary key objects with custom comparison function in Python
I'm porting some code from C++ to Python that relies upon the C++ ordering of keys in the map using custom compare functions. I has assumed I could simply use a Python dictionary and then use ...
0
votes
1answer
9 views
How to refork my current main file to follow an object-oriented style?
I'm writing an application with PyQt. Since I should stick to an object-oriented programming, my main file should be fixed to follow that. Also, because I would like to use Signals and Slots, and I ...