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
GObject.idle_add(), thread.join() and my program hangs
I've a problem: my main thread should start and join a thread that has a to run about 10-15 seconds.
So:
my main thread starts a child thread, whom has to run about 10-15 seconds
my main thread ...
0
votes
0answers
9 views
Dynamically importing constants from a module
I have a module which declares some constants like this:
FOO = "foo"
BAR = "bar"
and I want to access those global variables dynamically (i.e., by name) from another module
...
0
votes
1answer
18 views
Deciphering My Cipher: Python Wizardry
I'm trying to write a function decipher(s) that takes an enciphered string where the characters have been rotated, and returns the original English string. An example:
>>> decipher('Bzdrzq ...
-1
votes
1answer
11 views
How would i create two lists and add items to that list in python 3.2?
alright so im wanting to make a statistical file and i want to creat two lists... Player Names, and High scores, after having these two list i want to add items to it such as names and ...
0
votes
0answers
4 views
Python Django: Pass json from view to javascript in template
I am new to django.
From my findings, I tried this way, but didn't work.
<script type="text/javascript" >
var data = {{json}}
</script>
I am trying to use data table from this ...
0
votes
0answers
9 views
Java ProcessBuilder not able to run Python script in Java
null from bfr.readLine()
however there is no problem if I run the python file directly on terminal by firing:
python C:/Machine_Learning/Text_Analysis/Ontology_based.py
The last line in my Python ...
0
votes
0answers
10 views
Sign on results of fft
I am attempting to calculate the MTF from a test target. I calculate the spread function easily enough, but the FFT results do not quite make sense to me. To summarize,the values seem to alternate ...
0
votes
0answers
3 views
Why does my linear SVM take longer to train with scaled features than normalised or original features?
I trained my SVM as is, without scaling or normalising the features. Then, I trained it with normalised features and finally with standardised features. I think, it takes MUCH longer to train the SVM ...
0
votes
1answer
13 views
Unit test in Python not running
I'm trying to test my code with unit tests, but when I try to run it it just says
"
Finding files... done.
Importing test modules ... done.
Ran 0 tests in 0.000s
OK
"
Why isn't it working?
...
0
votes
1answer
12 views
Elegant way to perform column-wise operations on two dataframe
I need to find all-pair column-wise operation on a dataframe. I came up with a naive solution but wondering if any elegant way is available.
The following script counts the number rows having one ...
0
votes
0answers
7 views
Using Websockets with Linux VPS
I'm fairly new to the area of both websockets and servers. I've found a demo file which shows something like this:
try {
var host = "ws://localhost:4545/";
...
0
votes
1answer
9 views
How to modify XML as text in lxml
I have an XML file generated by an IDE; however, it unfortunately outputs code with newlines as BRs and seems to randomly decide where to place newlines. Example:
if test = true
foo;
bar;
...
0
votes
1answer
16 views
How to open a video file in python 2.7?
I am new to python, and I am trying to open a video file "This is the file.mp4" and then read the bytes from that file. I know I should be using open(filename, "rb"), however I am not clear about the ...
0
votes
0answers
10 views
Format datetime in seaborn faceted scatter plot
I am learning python pandas + matplotlib + seaborn plotting and data visualization from a "R Lattice" perspective. I am still getting my legs. Here is a basic question that I could not get to work ...
-6
votes
2answers
25 views
Need Help on Python homework — Iteration and Lists
Write a function sum_of_squares(xs) that computes the sum of the squares of the numbers in the list xs. For example, sum_of_squares([2, 3, 4]) should return 4+9+16 which is 29:
0
votes
1answer
26 views
If then statement not detecting classes in Python
I'm making this program so I can better understand how to use python, but enter code hereI'm stuck at what I currently have. I'm trying to make an if then statement that detects my classes and ...
1
vote
3answers
16 views
multiply Python Quad integration by float
Hello I'm quite new to python and I'm trying to work through a set of equations. I'm trying to multiple the result of the quad integration by a float my code is:
from __future__ import division
...
1
vote
2answers
18 views
python: how can I read elements of 2d dynamic lists?
I have following data
['1', '4', '4', '244', '263', '704', '952']
['2', '4', '4', '215', '172', '305', '33']
['3', '4', '4', '344', '279', '377', '1945']
['4', '4', '4', '66', '79', '169', '150']
...
-1
votes
0answers
15 views
'NoneType' object has no attribute 'update'
I've got this bit of Python that is giving me some major headaches, hopefully someone can help me out.
import Queue
import threading
import subprocess as subp
from pymongo import MongoClient
import ...
1
vote
0answers
14 views
How can I find the indices in a numpy array that meet multiple conditions?
I have an array in Python like so:
Example:
>>> scores = numpy.asarray([[8,5,6,2], [9,4,1,4], [2,5,3,8]])
>>> scores
array([[8, 5, 6, 2],
[9, 4, 1, 4],
[2, 5, 3, 8]])
I ...
1
vote
1answer
16 views
How to check if first list appear in the same order somewhere in the second list
Write a function called sublist. The function takes 2 lists as parameters, and returns True if the items in the first list appear in the same order somewhere in the second list (and False if they ...
0
votes
2answers
17 views
Existance of array in list of arrays
I'm trying to check the existence of an array in a list of arrays. My problem can be boiled down to the example below:
>>> import numpy as np
>>> a = np.array([1,2,3])
>>> ...
0
votes
1answer
6 views
PRNG Error (Python)
So I'm trying to make a PRNG:
import math;
import datetime;
print("Please input the seed number.")
seed = input()
systime = datetime.datetime.now().time()
int result = seed + 24252561651525166 - ...
0
votes
0answers
5 views
Starting a local instance of Mosquitto
I am starting to learn about MQTT, and at the moment I am trying to setup a local instance on my laptop.
This afternoon I installed mosquito on my mac using "brew install mosquitto".
After the ...
-2
votes
1answer
19 views
Python error: 'NoneType' object has no attribute 'split'
if x=="recibidos":
whatsintro_gui.borrar_lista_mensajes()
nr=whatsintro_msg.cantidad_recibidos()
k=0
while k<=nr:
...
0
votes
2answers
8 views
csv.reader () - How can I extract columns from a csv.reader object?
I have the following records below in a csv file and need to be able to access specific columns in order to extract, set and compare relationships. How would I go about doing this? I've tried list() ...
2
votes
2answers
33 views
Find the biggest prime of a number [Python]
def f(num):
return num
number = f(13195)
list = [ x for x in range(number) if ((x!= 0 and x!=1) and number%x ==0)] #x (the multiplication factor) should not be 0 or 1
max = max(list)
for num in ...
0
votes
1answer
8 views
Why does my SVM's performance drop after scaling the training and test data?
I am using scikit-learn to carry out Sentiment Analysis of text. My features right now are just word frequency counts.
When I do the following, the averaged F-measure is around 59%:
from sklearn ...
0
votes
0answers
12 views
Sublime plug-in works only if I don't restart Sublime Text 3
I'm trying to fix a reported bug for a Plug-in I've wrote named ThemeAutomator but I'm not sure I get what's the problem.
if I print my loaded plug-in's sublime settings it works only on first run ...
0
votes
0answers
6 views
Matplotlib / Seaborn barplot--strings in x axis
Maybe I am too used to R's wonderful ggplot-idiom when doing faceted charts (it takes numeric and string variables without protest) but the ideal way outside ggplot has certainly eluded me for some ...
3
votes
1answer
33 views
os.walk stuck in an infinite loop
I am trying to write a script that navigates through a directory and identifies DICOM files with a specified piece of header information. After I have found a file that meets the criteria, I want to ...
0
votes
0answers
4 views
Will pycharm work with the wtframework
I am setting up the wtframework for creating selenium webdriver tests in python but do not want to use the bulky eclipse ide. Has anyone had success using the pycharm ide with wtframework?
0
votes
0answers
5 views
glpk not found by cvxopt on redhat linux
I am working on a redhat 4.4.7-3 system where I do not have admin permissions. I need to use glpk for a linear programming problem and I am doing this in python. I asked the admin to install cvxopt ...
0
votes
0answers
11 views
Convert string to ndarray in python
I am reading a stream of data from an A-D converter via a socket from Python; the data come in as raw bytes. I want to format these bytes as int32 and place them into an ndarray. The read process ...
0
votes
1answer
20 views
Convert a list into a dictionary of list in Python
I need to convert a list into a dictionary in Python.
The list is:
list = [['a','aa','aaa'],['b','bb','bbb']]
And I want to convert it to a dictionary such that:
dictionary = {'aaa': ...
2
votes
3answers
18 views
parsing a path based on regex - Python
I'm trying to scan an Amazon S3 bucket, in order to search if a new version of our installer has been posted:
The bucket scan returns me something like:
versions/
versions/4.4.1.2/
...
0
votes
1answer
14 views
Using ctypes to grab a pointer from a nullary function (segfault) x64
I've reduced my problem to the following toy file and command:
// a.c --> a.out, compiled with `gcc -fPIC -shared a.c`
void* r2() {
return NULL; // <-- could be anything
}
python -i -c
...
-1
votes
1answer
18 views
Joining dataframes with different datetime frequencies
I have some sparse higher frequency data (unevenly spaced) and some low frequency data (daily).
How can I join this data and append corresponding low frequency data columns to the higher frequency ...
-2
votes
0answers
8 views
Making a timer in Kivy that counts up from 0
I am trying to create a timer in my Kivy project that counts up from 00:00:00, up to a specified number of seconds (in the HH:MM:SS format). I would like to display the timer in a label by ...
-3
votes
1answer
24 views
Count Consonants Before First Vowel in a String
I'm creating a simple pig Latin translator. Here's what I have so far:
while True:
phrase = input('Translate > ').lower().split()
for word in phrase:
if word[0] in 'aeiou': #if the ...
-5
votes
3answers
51 views
Please give me an explanation of what this means (Basic) [on hold]
Just starting python, the book tells me I can create a this matrix diagonal if I use this following code, someone please explain what it means? The for i in, the Matrix[i][i] and why it's [0,1,2]
...
0
votes
0answers
5 views
ImportError: No module named Qsci while running ninja-ide
I am trying to install and run ninja-ide http://ninja-ide.org/home/
However when i try to run ninja-ide I am facing this error
ImportError: No module named Qsci
I have been trying to install ...
1
vote
0answers
7 views
Sharing a txpostgres connection pool
We have a RESTful(-ish) twisted application that uses txpostgres to access a postgres db. Currently, we generate new txpostgres.Connection instances every time a client pings the server for a db call. ...
0
votes
1answer
21 views
numpy won't work in IDLE
I'm running python 2.7.3 on window 8. I'm writing some code that requires me to use the numpy.add() function. I downloaded numpy 1.6.0 for win32 py 2.7 from sourceforge. I have no idea how to "build" ...
0
votes
0answers
25 views
Assign topic to small text in Pythom
Do we have any Python library that can help us to find on what topic the text might belong? I searched a lot but most of the libraries do document tagging, considering document has huge amount of text ...
0
votes
0answers
11 views
Efficient calendar drawing in PyQT with GraphicsView
I am trying to implement a weekview calendar in python and PyQt, as seen in this picture:
In the last two days i found out that I should use QGraphicsView, QGraphicsScene and a SceneRect. Here is ...
3
votes
1answer
42 views
Best (pythonic) way to interrupt and cancel a function call in progress?
I want a function foo() to do a number of things in one thread, with waiting periods during which it periodically checks if another thread (the main script) has set a please_stop variable to True, in ...
0
votes
2answers
27 views
how do i make two new lists based on what the index is in a list?
So I think it is much easier to explain if I show an example:
things = ["black", 7, "red', 10, "white", 15]
two new lists based on whether the index was even or odd.
color = ["black", ...
2
votes
1answer
20 views
How to get the mode for string variable when resampling with pandas
I am trying to resample a pandas data frame with a timestamp index to an hourly occurrence. I am interested in obtaining the most frequent value for a column with string values . However the built in ...
0
votes
1answer
13 views
How to handle Redis connection across multiple modules?
I'm building an application that uses Redis as a datastore. Accordingly, I have many functions that interact with Redis, usually as wrappers for a group of Redis commands.
As the application grows ...