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
8 views
how can I get the token instead of string?
I have following syntax:
kv = Word(alphanums + '_') | QuotedString('"', escQuote="\\") | QuotedString("'", escQuote="\\")
kv = kv.setResultsName('literal', listAllMatches=True)
cskv = kv + ...
0
votes
0answers
4 views
Julia performance compared to Python+Numba
The performance benchmarks for Julia I have seen so far, such as at http://julialang.org/, compare Julia to pure Python or Python+NumPy. Unlike NumPy, SciPy uses the BLAS and LAPACK libraries, where ...
0
votes
0answers
3 views
error 400 - bad request when trying to set q search parameter in Soundcloud with Scrapy item
Im trying to search soundcloud for a track related to an artists name. It works perfectly if i just type an artist name in the q search parameter, however i want it to use an item ['artist'] variable. ...
0
votes
0answers
18 views
Creating a truth table for any expression in Python
I am attempting to create a program that when run will ask for the boolean expression, the variables and then create a truth table for whatever is entered. I need to use a class and this is what I ...
0
votes
0answers
8 views
python natsort sort strings recursively
I find that with natsort.natsorted the sorting order changes part-way through a string:
In [31]: import natsort as ns
In [32]: ns.natsorted(["01-08", "02-07", "01-06", "02-09"])
Out[32]: ['01-08', ...
0
votes
0answers
8 views
Get IO Wait time as % in python
I am writing a python script to get some basic system stats. I am using psutil for most of it and it is working fine except for one thing that I need.
I'd like to log the average cpu wait time at ...
0
votes
1answer
12 views
how to preserve leading zeros in Flask routing
I'm building URLs that look like this, routing with Flask:
http://hostname/nris/resource/00001234
http://hostname/nris/resource/99000025
The last segment is an 8 digit integer that will match a ...
0
votes
0answers
3 views
Matplotlib Pyplot logo/image in Plot
I'm struggling to achieve a simple goal in matplotlib: I want to put a small logo or indicator in the bottom right of my graph, without altering the axis or the real data that is being displayed. Here ...
0
votes
0answers
12 views
How to perform this type of data aggregation in pandas
-------+--------------------------------+----------------------------+--------------------------------------+---------------------------------------+--------------------------+-----------------------+
...
0
votes
0answers
9 views
Can't write dataframe to excel after using groupby function in pandas
Import Excel File as Dataframe:
import pandas as pd
ImportExcelAllDataFlow =pd.read_excel("TmeSpatialFromCenter.xlsx")
aa=ImportExcelAllDataFlow.groupby(['Source', 'TimeFlowContext']).size()
I ...
0
votes
1answer
25 views
How do you extend a project in Python the right way? [on hold]
I have a large robotics project in Python that was based on a 2D robot (so all values, such as its x-y pose, are two-dimensional). This is spread across 20+ files.
I want to find an elegant way to ...
2
votes
0answers
12 views
import fails when running python as script, but not in iPython?
I have a project structured as such:
folder1
|
folder2
|
tests
I have __init__.py in each folder. When I am in the parent directory of folder1, I run iPython ...
0
votes
0answers
2 views
How to validate Google reCAPTCHA v2 in django
I have been trying to use the Google reCAPTCHA on a website that I've been making. The captcha loads on the webpage but I've been unable to validate it using several methods. I've tried the recaptcha ...
1
vote
2answers
20 views
'TypeError: list indices must be integers, not str' Python 3
I need a bit of help with this assignment (first time posting on SE so please excuse my lack of posting etiquette if any)
So for this code I had to write a spell checker. Basically what it is ...
5
votes
2answers
50 views
Equivalent of Python's list sort with key / Schwartzian transform
In Python, given a list, I can sort it by a key function, e.g.:
>>> def get_value(k):
... print "heavy computation for", k
... return {"a": 100, "b": 30, "c": 50, "d": 0}[k]
...
...
0
votes
0answers
3 views
Get all ips in PCAP file
I have a set of PCAP files and I need to retrieve all the ips. I found this link and have currently been using this command.
tshark_path + " -r " + infile + " -T fields -e ip.dst | sort | uniq
The ...
2
votes
2answers
20 views
Calculate derivative for provided function, using finite difference, Python
I should probably start by saying that I am relatively new to python, but I have coded in java and Matlab before.
In python, the code
def func(f):
return f
g = func(cos)
print(g(0))
gives the ...
-1
votes
0answers
16 views
Textwrapping fail [on hold]
I am new to programming and trying making a simple text based video game using python.
My first goal was to make an introduction which was just my coding input('..') after input, making a plot ...
0
votes
0answers
2 views
Flask-restless endpoints with user resolution and filtration
How would correctly should look API that returns only objects belonging to the user who asks for them?
api/version/items/<items_id>
or
api/version/user/<user_id>/items/<items_id>
...
0
votes
1answer
12 views
How group by date in Django
I have two dates.
start_date = '2015/01/01'
end_date = '2015/04/01'
My query return all orders between this two dates, but i need group by month.
So:
data1: 2015/01/01 #start_date
data2: 2015/02/01
...
-2
votes
0answers
10 views
Finding Local Mimima(s) of 1D Weighted Gaussian Kernel Density Estimation (KDE) in Python
The problem I work on requires me to find the local minima(s) of 1D Weighted Gaussian Kernel Density Estimation (KDE) function with automatic bandwidth determination.
Can someone please tell me how I ...
0
votes
1answer
14 views
Time Series Plot Python
I am using pandas and I want to make a time series plot. I have this dataframe, and I want to plot the date on the x-axis with the number of units on the y-axis. I am assuming I need to convert my ...
3
votes
2answers
31 views
how to get a defautdict(set) like this form : {str : { str : int } }
I got a dictionary like this
{('a','b'):3, ('b','c'): 2, ('a','c'): 5}
I want to convert it to this form :
{'b': {'c': 2}, 'a': {'c': 5, 'b': 3}}
That means I have to build a dictionary like ...
-1
votes
4answers
25 views
Python3 - getting the sum of a particular row from all the files
I have many files in my directory of the below format:
name,sex,count
xyz,M,231
abc,F,654
...
i am trying to get the sum of count(3rd coloumn) for all files and store them in a list.
total = []
...
0
votes
1answer
34 views
How to remove None when iterating through a list in python
I have this two unequal lists and i'm using itertools to loop through them and i'm trying to use the filter function to remove the None generated in List1 so that at the end of the day a contains ...
-6
votes
0answers
23 views
How can I collect online data using keyword analysis [on hold]
I am looking to collect data that is trending in real time by analyzing the internet for keywords and it relates to time searched or posted...
Is this even possible, if so what language may work best ...
1
vote
0answers
10 views
Python read pdf in sections
I'm trying to read a pdf file where each page is divided into 3x3 blocks of information of the form
A | B | C
D | E | F
G | H | I
Each of the entries is broken into multiple lines. A simplified ...
0
votes
1answer
14 views
Python: Trying to use polymorphism with pygame
I'm trying to use polymorphism in my pygame project but I keep getting errors.
I have a Moveable class and a Objects class that inherits from Moveable and I get an AttributeError: 'NoneType' object ...
2
votes
1answer
23 views
How to delay blits being iterated from a list
I'm trying to create a typewriter effect for text being blitted. By typewriter effect, I simply mean that Im trying to avoid the entirety of the text being blitted on screen at once. Instead, im ...
0
votes
4answers
35 views
How do I collapse categorical data into a single record in R or Python?
I have a data set structured in this fashion:
ID Code
1 A
1 B
1 C
2 A
2 C
3 B
3 C
However, I would like it to look like:
ID Codes
1 A B C
2 A C
3 B C
Is ...
0
votes
0answers
19 views
Permission denied: '/usr/local/lib/python2.7/dist-packages/pip'
Everytime I try to use pip, I get the following error -
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 246, in main
...
-1
votes
0answers
4 views
slumber 0.6 vs requests 2.6 (compatibility)
The version 0.6.0 of slumber is compatible with the module requests 2.6.0?
There was any change in requests since version 1.2 , which does not work with slumber 0.6?
-9
votes
1answer
37 views
Removing list from a list
In the following list, remove the duplicated reversed list if values are matched when reversed.
[[1,2], [2,1], [3, 4], [4, 3], [5 ,6]]
Would return
[[1,2], [3,4],[5,6]]
What is the fastest way?
2
votes
3answers
29 views
Multi-mapping a value while saving intermediate values
I'd like to map a value through a dictionary multiple times, and record the intermediate values. Since list.append() doesn't return a value, below is the best I've been able to come up with. Is there ...
0
votes
1answer
14 views
Program called from within Python detects opened serial port
I open the serial port, read some parameters from the modem (Omited here for simplicity), close the serial port and call sakis3g, a script to connect to Internet through a serial or USB modem.
I can ...
0
votes
0answers
7 views
How to return “already exists” error in Flask-restless?
I would like to do some handler for exception. I'm using a combination of Flask-restless and SQLAlchemy in python.
My problem:
When I send request to api with object that already exists in DB, ...
0
votes
0answers
4 views
Celery: access all previous results in a chain
So basically I have quite a complex workflow, which looks kinda similar to this:
>>> res = (add.si(2, 2) | add.s(4) | add.s(8))()
>>> res.get()
16
Afterwards its rather ...
0
votes
1answer
6 views
matplotlib 3d surface plots not showing
I am trying to make a simple 3D surface plot with matplotlib but the plot does not show at the end. I only get an empty 3D axes.
Here is what I did
from mpl_toolkits.mplot3d import Axes3D
x= ...
0
votes
0answers
10 views
BFS for pacman find expanded nodes correctly, but failed to get the path
I implemented a BFS for Pacman. I am getting correct list for nodes expanded. But, I couldn't find the path between Pacman and food. For simplicity, I reversed the stack into queue in the following ...
0
votes
0answers
14 views
Set keyboard state python
I am trying to send CTRL+S, to notepad which isnt working I am guessing its checking the key state to see if control is being held down. I am wondering how in python I can set the keystate of ...
1
vote
2answers
22 views
Dict comprehension produces seemingly unwarranted NameError
I'm using brian2 to run neural-network simulations. In order to record data during each simulation, I'm creating several instantiations of brian2's SpikeMonitor class. I want to store these monitors ...
1
vote
0answers
11 views
How to change record of object in Django's model instantly?
I have a class and its objects, I want when I save new record, Django checks if "is_it_true" is False or True, if it was True then it change the default value of "number" to a new value which is ...
0
votes
0answers
12 views
Python Pandas to_pickle cannot pickle large dataframes
I have a dataframe "DF" with with 500,000 rows. Here are the data types per column:
ID int64
time datetime64[ns]
data object
each entry in the "data" column is an array with size = ...
0
votes
2answers
24 views
How to read output from subprocess Popen correctly?
I'm trying to redirect stderr to stdout and read the output of a command. It looks like the code works, but when it reaches the end of the output, it throws an exception
Code:
with Popen(["bash", ...
0
votes
0answers
6 views
Configure Blaze and start Bokeh server from Pyramid web-application
I have a Pyramid web-application on which the customer would like the ability to plot large data sets interactively.
The application currently displays a sub-set of the customer's selected data with ...
0
votes
0answers
18 views
How can I make my Bottle web server run forever?
I've successfully created a little webserver using Bottle. But after it runs for a little while, it disconnects/stops listening. I have to run "python hello.py" from the terminal to get it up and ...
0
votes
2answers
30 views
How do I retrieve a list within dictionary within a list?
How do I retrieve a list value, within a dictionary, that's within a list?
x = [{'name': 'joe', 'items': ['hat','scarf','boots']},
{'name': 'john', 'items': ['jeans','shirt','jacket']}]
x is ...
0
votes
0answers
6 views
socket.error: [Errno 10061] while login
I am trying to access google spreadsheets through gspread api in python. I have imported gspread. I am getting socket. error: [Errno 10061] No connection could be made because the target machine ...
-2
votes
0answers
13 views
Error: 'Maximum template recursion' while running python script
I am running a python script on English Wikipedia xml dump file to extract text for the Wikipedia articles. I am doing everything as told on this page. It seems a fairly straightforward task.
The ...
0
votes
1answer
8 views
Comparing scikit learn clusterings using a decision tree
I am doing a project for a class where I take some data from LIBSVM and run it through 2 different clustering algorithms. I have my kmeans generating 8 clusters, while my agglomerative is grouping ...