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
4 views
parse colour from an image
if I have a heatmap like here
is there some way in R,python or VBA (or even in general) to parse the rgb colour codes of each cell of the heatmap from the image into an array/matrix? I know for ...
1
vote
0answers
12 views
Import object from module of same name using __import__
I have a directory structure as follows:
root/
__main__.py
files/
__init__.py
foo.py
bar.py
baz.py
each file has an object in it with the same name as the ...
0
votes
0answers
9 views
Tweepy: How to search for all tweets from a country
I am trying to get all tweets from a country, so I followed this answer to get the code below using the U.S. as an example:
api = tweepy.API(auth)
places = api.geo_search(query="USA", ...
0
votes
0answers
3 views
Python networkx graph appears jumbled when drawn in matplotlib
I am testing out how to create network graphs on networkx. My problem is that when I try plotting these graphs using matplotlib, the nodes, edges, and labels appear jumbled. I want to have the labels ...
0
votes
4answers
31 views
How can I close() a variable in Python
I have the following code:
from sys import argv
script, filename = argv
txt = open(filename)
print "Here's your file %r:" % filename
print txt.read()
print "Type the filename again:"
file_again = ...
0
votes
2answers
10 views
ffmpeg Python Subprocess Error returned non-zero exit status 1
So I have a line here that is meant to dump frames from a movie via python and ffmpeg.
subprocess.check_output([ffmpeg, "-i", self.moviefile, "-ss 00:01:00.000 -t 00:00:05 -vf scale=" + ...
0
votes
1answer
4 views
Python Tornado updating shared data between requests
I have a Python Tornado app. The app contains request handlers, for which I am passing data to like (the code below is not complete, and is just to illustrate what I want):
configs = {'some_data': 1, ...
0
votes
0answers
6 views
How to submit a form with a get action using Robobrowser
I am using the robobrowser library, I have come across a form with the following action:
<form id="search" action="/results"
My code:
search_form = browser.get_form(id='search')
search_form ...
0
votes
0answers
9 views
How to achieve @abstractstaticmethod and @abstractclassmethod in Python 2.7? [duplicate]
How to achieve @abstractstaticmethod and @abstractclassmethod in Python 2.7?
class Thing(object):
__metaclass__ = abc.ABCMeta
# works
@abstractmethod
def instanceMethod(self):
pass
# ...
0
votes
0answers
9 views
PythonInterpreter can't find my module
I would like to use my python code through the PythonInterpreter of jython. This is what I did.
public static void main(String[] args) {
String dataFolder, prepFolder;
PythonInterpreter py = ...
1
vote
0answers
6 views
Python OpenCV (cv2) VideoCapture.read() Unspecified error in NumpyAllocator::allocate
I am new to OpenCV and I am using the python version of it to read out the frames of a video so that I can do some analysis on them. I am reading an mp4 video file and looping through the frames to ...
3
votes
0answers
20 views
Create PyString without copy [duplicate]
I have a large buffer of strings (basically 12GB) from a C app.
I would like to create PyString objects in Python without copying the strings. Is this possible?
0
votes
0answers
17 views
Programmatically Compare Microsoft Office Files
I am looking for the easiest way to see if two Office files have the same content using Python. My first instinct is to use filecmp.cmp, but this approach logically fails, since two files do not ...
-5
votes
0answers
15 views
Suggestion on Architecture for a web app
I am planning to develop a web app where one can say anything as a comment and which would be stored in database and when anyone tries to search for specific keywords they can search and a page will ...
0
votes
0answers
21 views
How to split and store parts of HL7 message into array jython?
I receive an HL7 message file that looks like:
MSH|2131|321|dsaf|321|fdss|43242|gfdsg|
PID|432|gfdsgsd|342|grfg|343|
PV1|trwr|432423|gfgfds|4243|gfdsgfd|
ORC|||F|RE
OBR|20140707|fdsadf|423423|fdsas
...
0
votes
0answers
3 views
FB login mechanism with an anuglar client and flask server
I am writing a blogging site. I want to authenticate users using facebook.
What is the proper way to authenticate with Facebook if I am using these technologies as my stack ?
I just need a very high ...
0
votes
2answers
14 views
Passing web data into Beautiful Soup - Empty list
I've rechecked my code and looked at comparable operations on opening a URL to pass web data into Beautiful Soup, for some reason my code just doesn't return anything although it's in correct form:
...
0
votes
0answers
3 views
django-jenkins emits coverage for models only
I'm currently using 0.16.2 version of Django-jenkins in my Django application. Django version is 1.6.2
My django application structure looks like:
my-app
src
module1
models
tests
helper_modules
...
0
votes
1answer
17 views
Django Form Submission Failing
I'm working on a little app that allows you to save specific location information about places you've been. The issue I'm having is that clicking the submit button on the 'save new location' page ...
-5
votes
1answer
32 views
Convert Python List to JSON Separate Objects [on hold]
I have a list in Python
volumes = [Volume:vol-XXXXXXXX, Volume:vol-YYYYYYYY]
that I want to change to into JSON. The final result should be
{ volumes: ["Volume:vol-XXXXXXXX", ...
0
votes
0answers
5 views
How to make a MySQL Workbench plugin to modify result grid data? i.e. HEX(bin)
From what i understand MySQL Workbench uses Python plugins.
I want to write a plugin to apply a function to each row identified by a column name.
i.e. i have a column with pickled (serialized) data, ...
0
votes
0answers
3 views
Nova Fails nova-manage db sync command
I'm totally new to openstack and I'm trying to run a single-node service. While configuring nova By passing the command:
nova-manage db sync
I get this:
Command failed, please check log for ...
-1
votes
1answer
9 views
How to alter request handling?
Is it possible to alter request handling in Scrapy?
For example if I want that particular URL must be requested not by scrapys stanard machinery, but with Selenium, and make me able to operate with it ...
0
votes
0answers
8 views
IronPython returning duplicate values in C# callback function
In a file called test.py I have the following code:
def foo(callback):
callback(1, 2, 3)
def bar(x, y, z):
print x, y, z
When foo(bar) is executed in the IronPython console, it outputs:
...
0
votes
3answers
12 views
numpy array print index of certain value
Given a numpy array
A = np.array([[[29, 64, 83],
[17, 92, 38],
[67, 34, 20]],
[[73, 28, 45],
[19, 84, 61],
[22, 63, 49]],
...
1
vote
1answer
13 views
Using matplotlib for Gaussian
so I am trying to plot a histogram of my data and I seem to be a little confused here. I am using matplotlib in python. Here is the code from their website:
mu = 100 #mean
sigma = 15 #std deviation
...
0
votes
0answers
2 views
Django inspectdb on DB2 database
I'm trying to execute inspectdb Django command, on an existing DB2 database. This is my DATABASES appart on settings.py:
DATABASES = {
'default': {
'ENGINE': "django_pyodbc",
'USER': ...
0
votes
1answer
14 views
requests.post gives 204 but curl and os.system run just fine
I am trying to get the response of a http post request using python. I am using Python 2.7.3
I need to get the response of the http post request I make.
I tried using the requests module to do the ...
1
vote
2answers
20 views
unittest.TestCase gets `TypeError: Error when calling the metaclas bases __init__() takes exactly 2 arguments (4 given)`
I am trying to add attributes to a unittest TestCase, but I keep getting the following error.
TypeError: Error when calling the metaclas bases __init__() takes exactly 2 arguments (4 given) I am ...
-2
votes
3answers
32 views
IF Statement regarding tax (python/html)
My If statements wont give me any correct answers. Can someone have a look at them?
if total > 150 and b1 == "BC" or b1 == "bc" or b1 == "Bc" or b1 ==
"bC":
print"<p>Tax: ...
0
votes
1answer
46 views
Python string iteration issues [on hold]
I have just started learning python and I am a bit confused. Why does this code not work? When I call pie, it returns 1 instead of 5. What am I not understanding here?
score = {"a": 1, "c": 3, "b": ...
1
vote
2answers
17 views
Prevent a list of names from splitting in a line break in a Django template
I have a list of people's names that I'm passing to my django template, then displaying it as a comma-separated string within an HTML table cell:
{{ list_of_names|join:", " }}
which works well, but ...
0
votes
0answers
13 views
Python Tkinter / How to let OptionMenus share one item list?
i'm trying to build multiple option menus sharing the same "base item list". A multiple selection of one item in different menus should not be possible, so all menus have to be updated when an item is ...
0
votes
0answers
6 views
Flask-Social Twitter login fails with message - OAuthException: Failed to generate request token
I can't get either Facebook or Twitter login to work using Flask-Social (https://pythonhosted.org/Flask-Social/), following the example here: http://flask-social-example.herokuapp.com/
Focusing on ...
0
votes
1answer
14 views
Keymaps in Light Table are not working
I just started learning Python with "A Byte of Python". I'm currently learning Light Table, the editor that the tutorial suggested.
This may be very amateurish but I have no experience whatsoever and ...
0
votes
0answers
24 views
How to reduce “python …PATH…django-admin.py startproject myprojname” to “django-admin.py startproject myprojname”?
UPDATED: See the bottom
The first step of the Django tutorial instructs you to create a new project like this
django-admin.py startproject mysite2
When I do that, it fails:
...
0
votes
0answers
9 views
Python: How can I get all the content from a textbox in a form (cgi script)? form.getvalue(“textBoxName”) only gets me the first word/letter?
So my code looks something like this:
form = cgi.FieldStorage( )
question1= form.getvalue( "question1" )
print question1
The problem is, only the first word of question1 textbox is ...
-3
votes
1answer
12 views
Creating an API and then changing API [on hold]
I have outsourced the creation of an app in Drupal and would eventually like an API to offer 3rd party CMS integration (like Wordpress/Joomla/Drupal).
My question is, when it eventually comes time to ...
0
votes
0answers
2 views
Crop Cairo-Generated PDF
I have the following script which generates a number of circles in a box on top of a bigger circle. The output is to a PDF, which I would like to be tightly bounded to the ink extents.
#!/usr/bin/env ...
0
votes
3answers
48 views
How to match HTML with Regex
I'm trying to extract some urls in an html file using python. Here is what the text look like:
preabc!precde<preefg<
I want to extract "cde" and "efg". The pattern I've used:
pre(.*?)<
...
0
votes
2answers
23 views
Pandas dataframe merge and element-wide multiplication
I have a dataframe like
df1 = pd.DataFrame({'name':['al', 'ben', 'cary'], 'bin':[1.0, 1.0, 3.0], 'score':[40, 75, 15]})
bin name score
0 1 al 40
1 1 ben 75
2 3 cary 15
...
0
votes
1answer
16 views
Why is my pandas bar chart not symetrical
I'm running this code:
import pandas as pd
pd.Series([-0.049, 0.039, 0.002, -0.165]).plot(kind='bar')
and getting this:
Why are the bars not centered with the plot area?
-piR
Update:
import ...
0
votes
2answers
25 views
Calculate date variance based on common id
I have a large table that looks like the following:
+---+---------+----------+-------+---------+------------+
| | cust_id | order_id | quant | revenue | date |
...
0
votes
1answer
16 views
Python: Building a dependency graph from items in a List
I would like to b build a data dependency graph between items in a list (assembly instruction). Here is what i'm looking for:
I have to extract the operands from 3 consecutive assembly instructions ...
-1
votes
1answer
22 views
Split characters from a list of tuples?
Im new at python and i have the following list of n tuples:
[('Mi', 'dp1css'), ('colega', 'nccs000'), ('me', 'pp1cs000'), ('ayuda', 'ncfs000'), ('a', 'sps00'), ('programar', None), ('cosas<', ...
0
votes
0answers
8 views
django_tables2 reloading previous page when I press “next” or sort by column
I have a very simple Django app that asks the user to input an author and then queries a database and outputs a table. There is a search page and a table page. I am using django_tables2 to display ...
1
vote
2answers
24 views
Enforcing Python source encoding as UTF-8
I currently put this at the top of all my .py files:
# -*- coding: utf-8 -*-
I've been taught this for years as best practice. To me the idea of enforcing UTF-8 by default makes sense, especially ...
0
votes
0answers
6 views
Get entry point script file location in setuputils package?
So I have an entry point defined in my setup.py [console_scripts] section. The command is properly installed and works fine, but I need a way to programatically find out the path to the script (e.g. ...
1
vote
1answer
10 views
Is there a NUMSUB command for redis-py?
Is there some equivalent to the NUMSUB command in redis for the python client?
I've looked through the documentation and can't find anything other than the publish() method itself, which returns the ...
1
vote
2answers
29 views
regex to remove floating point values
I want to be able to remove numbers with decimal places from within a string of text using regex. See here
import re
obj = '''This is my #1 [email protected] <body/> 2 3 4 5 2345! 23542 312453 ...