Tagged Questions
Python is a dynamically and strongly typed programming language whose design philosophy emphasizes code readability. Two significantly different versions of Python (2 and 3) are in use. Please mention the version that you are using when asking a question about Python.
0
votes
0answers
5 views
Python - Implement iteration over certain class attributes on given order
I have a Position class, and it has two attributes, Lat and Lon.
I would like the following API by implementing iterator protocol (but some googling just confused me more):
pos = Position(30, 50)
...
0
votes
0answers
3 views
pandas timeseries with relative time
I am new to pandas and I am struggling to figure out how to convert my data to a timeseries object. I have sensor data, in which there is a relative time index with reference to the beginning of the ...
0
votes
0answers
3 views
Does closing a GUI in PyQt4 destroy its children Qobjects by default
I'm trying to make a GUI that used QTimer to create a state machine, but when ever I I close the GUI window the timer continues. I think I'm properly making the object that creates my Qtimer a child ...
-1
votes
2answers
19 views
What is the purpose of app.py in django apps?
In Django 1.4 and above :
There is a new file called app.py in every django application. It defines the scope of the app and some initials required when loaded.
Why don't they use __init__.py ...
2
votes
1answer
15 views
Add a text after pattern in python
Is there a way to add some text after pattern in python string?
For example I can do it easily with sed:
sed 's/my [a-z]\+ pattern/& lost_text/'
where & means the whole matched pattern.
...
0
votes
2answers
16 views
custom output when control-c is used to exit python script
I would like the user to use control-c to close a script, but when control-c is pressed it shows the error and reason for close (which make sense). Is there a way to have my own custom output to the ...
1
vote
0answers
5 views
psycopg2 windows install missing file?
I am trying to work with psycopg2 but cannot get it to work.
I have tried to install from the site http://www.stickpeople.com/projects/python/win-psycopg/.
I tried the basic install and also as ...
1
vote
2answers
34 views
Removing duplicate rows?
Does anyone know how I might go about removing duplicate rows in the following data, where the duplicate rows are those with the same name? The catch is that I want to keep the phone numbers, emails, ...
0
votes
1answer
25 views
Error: can only concatenate list (not “int”) to list
I am getting this error when I try to populate users First_Name in a csv file. Can someone show me what I am doing wrong
import csv
# Define users
valid_input = False
while not valid_input:
...
0
votes
1answer
10 views
Python write (iPhone) Emoji to a file
I have been trying to write a simple script that can save user input (originating from an iPhone) to a text file. The issue I'm having is that when a user uses an Emoji icon, it breaks the whole ...
0
votes
1answer
16 views
Fetching the output of a command executed through os.system() command
I am using a script where I issue a shell command to a remote server (ssh) using os.system() command. I need to collect the output of the command I executed on the remote server. The problem is the ...
0
votes
0answers
4 views
Externalizing and controlling python application internals
When programming Java I used JMX for externalizing and editing application internals, like allowing to monitor a database connection pool internals, changing the logging level, and so on
Now that I ...
0
votes
3answers
47 views
Restarting a program after exception
I have a program that queries an API every few seconds. Each response triggers a few functions which themselves make some calls to websites and such -- calls that I don't want to blindly trust to ...
0
votes
1answer
8 views
Installing a package to Canopy
I'm really new to coding, programming, Python, and just computers in general, so I need some help with Canopy. I've been having pretty consistent troubles installing any packages to Canopy; some stuff ...
1
vote
2answers
31 views
Convert date to json date string in python
I have a list of dates (mm-yyyy), having only the fields of months and years:
d = ['09-2007', '10-2007', '03-2011', '05-2011']
And I need to convert them into JSON date strings..like ...
1
vote
1answer
8 views
How to set Selenium Python WebDriver default timeout?
Trying to find a good way to set a maximum time limit for command execution latency in Selenium Python WebDriver. Ideally, something like:
my_driver = get_my_driver()
my_driver.set_timeout(30) # ...
0
votes
1answer
25 views
How to correctly work with derived immutable class ?
I got some difficulties in writing a simple unit converter using derived class of build-in type float.
attempt 1:
I try to return a new copy of the instance, instead of change the state of it. ...
0
votes
2answers
21 views
Python regex endline
I am trying to search a string, which I know is always a sentence, to find the three words that come before and three words that come after a comma. Is regex the right way to do this AND how do you ...
0
votes
0answers
7 views
multipart/form-data File upload request from Flash to GAE misses data
I have a google app engine request handler that processes multipart/form-data request from file uploads. It works fine with a html form but with the flash uploader it seems that no parameters are ...
1
vote
1answer
16 views
How to implement a lazy setdefault?
One minor annoyance with dict.setdefault is that it always evaluates its second argument (when given, of course), even when the first the first argument is already a key in the dictionary.
For ...
1
vote
2answers
32 views
Python - generate array of returns from function that changes its return value
What is a good pythonic way to generate an array of results from multiple function calls with a function that changes what it returns after each call? For example, say I have a function foo that ...
-1
votes
2answers
34 views
Conversion of shell script to python script
Say I have the following HTML script:
<head>$name</head>
And I have the following shell script which replaces the variable in the HTML script with a name
#/bin/bash
report=$(cat ...
0
votes
1answer
14 views
Django login failing after registration
I have a simple registration form that feeds this function in views.py
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
def registerNewUser(request):
...
0
votes
1answer
16 views
Django users can only login if Boolean is set to true
I currently have a Poster model which is a ForeignKey to the Django user model.
class Poster(models.Model):
user = models.OneToOneField(User, primary_key = True)
bio = ...
0
votes
0answers
10 views
Django utf8 problems in different machines
So, I'm building a website which I'm programming in my machine (Mac).
When I have a new version of it, I send it to the server (from webfraction, Django 1.5.1 (mod_wsgi 3.4/Python 2.7), CloudLinux ...
0
votes
0answers
30 views
Flagging Entries with the Same Names?
I'm working with data where people have entered their names and some contact information. However, since they were unable to enter multiple entries for some of the fields, some people entered their ...
0
votes
0answers
22 views
Send data from php to python and back
I have been searching for a while in how to successfully exec a Python script through PHP, just for a test thats all.
I've never actually worked with Python and a while since I programmed in PHP ...
-2
votes
3answers
47 views
Using a loop with counters
Here's my program. There are seven employees for which I am creating a paystub. I am trying to achieve a loop where it starts at num = 1 and go all the way through num = 7. When I run the program, ...
-1
votes
1answer
10 views
Migrating to Twitter API version 1.1 (?) [duplicated]
I am quite new to Twitter API. I have updated Tweepy. I don't know what is wrong with this code and how to fix it to make it work for new version of Twitter API:
import oauth, tweepy
from time ...
3
votes
4answers
29 views
Storing Python function parameters as a variable to call later
I have a function where, based on different case, I'm changing the parameters sent to a function whose result I'm returning. I would like to just decide parameters in the middle of the method, and ...
1
vote
1answer
16 views
Difficulty opening pylab image from buffer object
Working within web2py, using python 2.7, I've got something like this going on:
import matplotlib
matplotlib.use('Agg')
import pylab
import Image
import io
temp_data = {'x':[1,2,3],'y':[2,4,5]}
...
0
votes
1answer
13 views
import error:cannot import name socket,Using Tornadoio2
from os import path as op
import tornado
import tornado.web
import tornado.httpserver
import tornadio2
import tornadio2.router
import tornadio2.server
import tornadio2.conn
ROOT = ...
1
vote
0answers
27 views
PyImport_Import fails (returns NULL)
I am a newbie in python, so may be this is a silly question. I want to write simple c program with embedded python script. I have two files:
call-function.c:
#include <Python.h>
int ...
-1
votes
0answers
14 views
fetch documents from mongodb collection by querying nested dictionary in mongo
I have a collection having schema
{user_id:user id, user_details: {name: {age: {profession: {salary: amount}}}}}
sample entry is:
{user_id:001, user_details: {
...
0
votes
1answer
26 views
how to read write check and edit a csv file
how to check particular data from a csv file and then add data to it, if the data does not exist. i am trying to create a dictionary, it will check the data in the file and if it does not exist it ...
0
votes
0answers
19 views
how to display a image in django template using for loop
I am trying to display a image in the django template
html file
{% for imge in q_i %}
<img src="{{ MEDIA_URL }}/{{ imge.0 }}" width="80" height="80" />
{% endfor %}
view.py
#...#
Q_I = []
...
0
votes
0answers
16 views
What does “Cannot have more than on screen object” error mean?
I'm working on a timer template for use in my games that I create. This is the code I have for a timer module (haven't put it into a class yet)
import time
import math
import pygame
from livewires ...
0
votes
1answer
12 views
python Assertion Error during nltk.ConditionalFreqDistribution
I am receiving an error I don't understand while trying to execute some python code. I am attempting to learn to use the Natural Language Toolkit via the excellent NLTK text book. While trying the ...
-1
votes
0answers
13 views
Django ORM: select_related with subquery
Is it possible to perform such select_related query on LineIdentification model:
SELECT bli."id", bli."basket_id", [...]
FROM (
SELECT * FROM "line_identification" as b
ORDER BY ...
0
votes
1answer
18 views
3D plotting: why are coordinate arguments input as 2D arrays?
The mplot3d function plot_surface requires that the coordinates of the points defining the surface be input as three 2D arrays, X,Y,Z. Here is a working example that demonstrates the construction of ...
1
vote
2answers
23 views
Trouble indexing lists of NUMPY arrays properly
I have a list of large arrays. Each array contains data. I also have another average array where each row contains the average of the each data array. For every row in the data array I want to ...
0
votes
0answers
29 views
FloatingPointError only shows up in a specific program
I have the same piece of code written in two programs. However I only get the error while running it one program.
Here is the file that is works with:
#!/usr/bin/env python
#FileName: test.py
...
0
votes
0answers
7 views
How to monitor queue health in celery
I have the following set-up:
Generic worker pool with 100 workers
High priority worker pool with 50 workers
I used such large numbers because most of the time my tasks spend waiting for I/O with ...
0
votes
0answers
4 views
cx_Freeze or pyinstaller with twisted/zope (namespace package)
I was using pyinstaller before to try and get my app with twisted as an executable, but I got this error when executing:
Traceback (most recent call last):
File ...
0
votes
3answers
35 views
Python 3 code gives different result than Python 2.7.5
I have this piece of code:
def gc_content(base_seq):
"""Return the percentage of G and C characters in base_seq"""
seq = base_seq.upper()
return (seq.count('G') + seq.count('C')) / ...
3
votes
4answers
57 views
Find the dimensions of a multidimensional Python array
In Python, is it possible to write a function that returns the dimensions of a multidimensional array (given the assumption that the array's dimensions are not jagged)?
For example, the dimensions of ...
0
votes
3answers
26 views
n-grams in python, four, five, six grams?
I'm looking for a way to split a text into n-grams.
Normally I would do something like:
import nltk
from nltk import bigrams
string = "I really like python, it's pretty awesome."
string_bigrams = ...
0
votes
1answer
17 views
Profiling Django views line-by-line
I have a Django application with views which I hope to profile with line_profiler or similar line-by-line profiling methods. I have successfully tested line_profiler on other python scripts, but have ...
0
votes
2answers
17 views
Issue with python module importing
In dir tree looks like this
PyPong
+ Main.py
+ Rectangle.py
Now, I have imported Rectangle.py like this in Main.py
import pygame, sys, Rectangle
However, whenever I try making an instance of ...
0
votes
1answer
53 views
the neccessary I don't understand about install python2.7
I found the answers from Building Python and more on missing modules.
Also the problem I meet is that. But something I didn't understand eg to how to install these
modules.
Python build ...