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
Drawing on a Panel within a Sizer
I'm attempting to make a wx.Panel derived class that will display rotated text. However, the moment this widget is added to a wx.Sizer, the text no longer displays. When it is added directly to a ...
0
votes
0answers
4 views
QLabel inside QMenu
I'm trying to add a QLabel to a QMenu because I need to have word-wrapped text. But it just add a blank line to the menu.
#!/usr/bin/env python3
import os
import sys
from PyQt4.QtCore import *
from ...
0
votes
0answers
5 views
Authorization headaches for Freebase API (Python)
I'm trying to get a very simple Python script to talk to Freebase.
All the examples I've found use the simple / api key authorization model. So I made a Google Developer account, made a project, and ...
1
vote
1answer
30 views
Python: replace single character in value of dictionary
How do I replace a single character in a string for Python dictionaries for a matched if condition?
Given:
if key[-1] == "d" and val[-1] == "t":
print key, val
versed v3rst
vexed vEkst
voiced ...
2
votes
0answers
12 views
Python defaultdict(list) de/serialization performance
I am working on a script which needs to process a rather large (620 000 words) lexicon on startup. The input lexicon is processed word-by-word into a defaultdict(list), with keys being letter bi and ...
0
votes
0answers
2 views
Using anaconda, getting [Errno 10054]: existing connection was forcibly closed by the remote host
I'm in the middle of running a image classification on Anaconda with Python 2.7, using scikit-learn and numpy.
The classifier ran for 6 hours and suddenly crashed saying:
Traceback (most recent call ...
10
votes
2answers
43 views
What happens if an object's __hash__ changes?
In Python, I know that the value __hash__ returns for a given object is supposed to be the same for the lifetime of that object. But, out of curiosity, what happens if it isn't? What sort of havoc ...
0
votes
1answer
10 views
In what way is fcntl.lockf() locking a file?
I'm currently attempting to lock a file via python so other processes cannot even read it.
So far i was testing behavior of fcntl.lockf() via python interpreter:
>>> file = ...
0
votes
0answers
20 views
python for loop to find and print names from blizzard api behaving erratically
I am working on a script to find and print the ilvls of my guild in python through the blizzard api. I realize that my code is ugly/horrible/not optimized. This is my first python project and I am ...
-5
votes
0answers
25 views
Chomp game- return if there's winning strategy (python) [on hold]
for those who don't know the game: http://en.wikipedia.org/wiki/Chomp
With a given matrix n X m and a list that represent the configuration of the game
;for example: [3,3,2,2]- P=poisoned
X X
X X X ...
0
votes
3answers
22 views
multiline regex pattern match
I have the following multiline(?) string that I get from the output of a process.
04/18@14:22 - RESPONSE from 192.68.10.1 :
04/18@14:22 - RESPONSE from 192.68.10.1 :
TSB1 File Name: ...
0
votes
1answer
40 views
Finding common elements in list in python
Finding common elements in list in python?
Imagine if i have a list like follows
[[a,b],[a,c],[b,c],[c,d],[e,f],[f,g]]
My output must be
[a,b,c,d]
[e,f,g]
How do i do it?
What i tired is like this
...
0
votes
2answers
16 views
Skipping over Error?
Hi I was wondering if anyone could help:
I have the code beneath that contacts Twitter's API in order to get retweet count from a Twitter ID no. I was wondering if anyone could point me in the right ...
0
votes
2answers
22 views
decoding comparing list to dictionary
I'm trying to compare to see if a word in a list is in a dictionary full or words. I'm writing a program that decode a txt file.
Say here is one the the lines:
['Now', 'we', 'are', 'engaged', 'in', ...
0
votes
2answers
7 views
plotting selecting pandas dataframe data using seborn
I have a pandas dataframe (al_df) that contains the population of Alabama from a recent US census. I created a cummulative function that I plot using seaborn, resulting in this chart:
The code that ...
0
votes
0answers
4 views
How do I reindex the result of a groupby.cumsum with the original df index?
I have a DataFrame which I'm trying to create a new column using groupby and cumsum. This has the correct dimensions. The command I'm using is df.newpers.groupby(df.personid).cumsum(). The problem ...
1
vote
2answers
40 views
add what was printed to a dictionary
I have two lists:
list1 = ['a', 'b', 'c', 'd']
list2 = ['A'. 'B', 'C', 'D']
I print out every time I called my function a random element of each list:
def whatever():
print 'Element of list ...
0
votes
1answer
4 views
Astropy Tables in Latex using data from text files?
I am not very familiar with latex. I have data in text files say like this:
subject year grade
maths 10 1
biology 12 1
I generate my data using python and it is saved as txt ...
0
votes
0answers
6 views
Tcl shell for python, using sendline to press enter while prompted
When I want to do a force-switchover, or just want to react when it asks save change or not.
I need to either press enter or type 'yes'/'no' and press enter.
I know in telnetlib it's pretty easy, ...
0
votes
1answer
34 views
Why are my references dynamic in Python? Why are objects being deleted from a list?
Stack Overflow is my Q&A bible, so first, a massive thanks to all of you contributes out there. You all make my life easier as a developer and save me so much time.
I want to preface my question ...
0
votes
3answers
22 views
Date validation boolean error in Python?
I decided to give Python a whirl and am building a fake data validator. Seems like my code is always outputting error, and I think it's because of my misuse of the boolean.
'''
...
0
votes
1answer
14 views
Python / Pygame TypeError: 'str' object is not callable
I want to display a font in the Top-left with an updateable Score. But there comes an error:
Traceback (most recent call last):
File "C:\Users\Mäse\workspace\Snake\src\snake_game\__init__.py", line ...
2
votes
1answer
26 views
Trying to rearrange two dimensional list into a different two dimensional list
Given an input of something like:
"Date 3" "Location A" "some data"
"Date 3" "Location B" "some data"
"Date 3" "Location C" "some data"
"Date 2" "Location A" "some data"
"Date 2" "Location B" ...
0
votes
2answers
25 views
Python: extract str value from list
If I have a list:
list = ['150', '200', '300']
how can I 'extract' the string value? (without getting a list)
If I slice list[0,2] i get a list.
Is list.pop(2) (for 2nd value in the list) the only ...
1
vote
0answers
8 views
Extract data from children of specific xml tag to csv using Python BeautifulSoup and/or Lxml
Foreword: I have browsed numerous threads on SO before posting this question. I learnt that my problem could be solved using lxml and/or beautifulsoup. I'm new to BeautifulSoup and Python as a whole. ...
0
votes
2answers
16 views
Cron task python script not working
I have a python script I want to fire off every night at midnight. I'm using cron scheduler right now to do so, however, I can't figure out why it's not working. For now, I've been using close times ...
0
votes
2answers
29 views
Python dict.update() with C++ std::map?
In Python, I can do this:
>>> foo = {1: 10, 2: 20}
>>> foo.update({1: 150, 5: 500})
>>> foo
{1: 150, 2: 20, 5: 500}
How to replicate the same in C++ with std::map or ...
0
votes
1answer
5 views
How do i open a class from within another class by selecting an item on ToolBar?? Python/PyQt
I am trying to run class AddTQuestions from a def in class AddTest but it wont work!! It opens the window AddTQuestions for a split-second then closes it straight away?!
The code is shown here:
...
0
votes
1answer
16 views
Django not applying default=0
I have the following model:
class Message(models.Model):
MS_DRAFT, MS_NEW, MS_WAIT, MS_SENT, MS_DELETED, MS_GEOMSG, MS_ERROR = range(7)
MS_CHOICES = (
(MS_DRAFT, "Draft"),
...
0
votes
1answer
7 views
GLIBC_2.15 required by python
python manage.py syncdb
python: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.15' not found (required by python)
python: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required ...
0
votes
2answers
19 views
Genshi and Python Generators (yield)
How do I create/call a python generator in Genshi? Is that even possible?
For example, (and no i'm not looking for an alternate solution to this problem, of which there are many, including enumerate ...
0
votes
0answers
14 views
Python getpass example where password is not echoed to the terminal
I am looking for an example of an instance where we import the Python getpass library, enter our password, and the password does not echo to the terminal.
Here is an example where it does echo the ...
0
votes
0answers
22 views
Smallest list containing all elements from two lists, while preserving order
I am unsure how to combine the items from two lists of integers such that the order of the items is preserved and the resultant list, if concatenated into one integer, is as small as possible.
...
0
votes
0answers
20 views
Pycharm Python Crashing
Python crashes a lot in the latest version of PyCharm on Windows 8. Does anyone have a fix?
Here is the Python build info.
PyCharm 3.1.2
Build #PY-133.1229, built on April 3, 2014
JRE: 1.70_40-b43 ...
2
votes
1answer
16 views
ODEINT Unable to Call on Function
so I am attempting to solve a system of three ODEs and developed the following code to solve them using ODEint. But when I run, ODEint has an issue calling on my function for the system of equations.
...
5
votes
2answers
34 views
Python argparse AssertionError
I just started using argparse module. I wrote the following reduced snippet to demonstrate an issue I'm having.
from argparse import ArgumentParser
if __name__ == '__main__':
parser = ...
0
votes
1answer
21 views
Python: pip cannot be called after installation
I am using Python27 on Windows 7. I have installed easy_install and tried to install pip. easy_install works. But, pip is not.
I keep getting an error saying:
'The term 'pip' is not recognized ...
2
votes
1answer
26 views
Find the indices of non-zero elements and group by values
I wrote a code in python that takes a numpy matrix as input and returns a list of indices grouped by the corresponding values (i.e. output[3] returns all indices with value of 3). However, I lack the ...
0
votes
0answers
9 views
Python and MYSQL have different encodings/charset
I have a large mysql database with the following charset variables:
character_set_client : cp850
character_set_connection : cp850
character_set_database : latin1
character_set_filesystem : ...
0
votes
2answers
36 views
Value updating to multiple dictionaries
I'm constructing part of a Turing Machine in Python 2.7.6. The method I'm using involves creating a state class and creating a new instance of the class for each state. Inside the states I have a ...
0
votes
0answers
8 views
ApScheduler ImportError: No module named redis
ImportError: No module named redis
!/usr/bin/python
"""
This example demonstrates the use of the Redis job store.
On each run, it adds a new alarm that fires after ten seconds.
You can exit the ...
0
votes
1answer
9 views
Non editable text in Kivy
I am creating a registration form using Kivy. I wants the text in textboxes, which is present when form loads as non-editable. As can be seen from below I can edit "Name" field as "Na". I want that ...
0
votes
1answer
6 views
Define the limits of my axes, but with an equal scale in both directions with matplotlib
How do I combine those statements:
pyplot.axis([1234.0, 1773.0, 497.0, 1362.0])
pyplot.axis('equal')
I just want to define the limits of my axes, but with an equal scale in both directions.
Ps.: I ...
-5
votes
0answers
42 views
shallow/deep copy in Python [on hold]
Does Python need to deal with copies similar to Java or other languages do? Before I print an object, I convert booleans to "Y" or "N", while converting ints to strings in the following manner:
def ...
2
votes
1answer
44 views
Generate list of n (strictly positive) values such that the list has predetermined mean x and std. dev. y
I would like to generate a list of n strictly positive values such that the list has a predetermined mean and standard deviation (can be close/not exact). I was using the uniform distribution's ...
0
votes
2answers
40 views
Insert Element in list during iteration
I need to insert element during iteration of list and did in following way. But I feel it can be written in better. Here B's dictionary which contain A element Length
_leftcell = leftcell[:]
index = ...
0
votes
1answer
19 views
Python Mock Multiple Calls with Different Results
I want to be able to have multiple calls to a particular attribute function return a different result for each successive call.
In the below example, I would like increment to return 5 on its first ...
0
votes
2answers
31 views
Python: slices of enumerate
I want to iterate within a slice of a list.
Also, I want to know the indexes of the element under my iteration.
I want to make something like
for i, elm in enumerate(test_list)[7:40]:
print i, ...
2
votes
2answers
25 views
Python split string with space unless a \ is in front
Sorry if this post is a bit confusing to read this is my first post on this site and this is a hard question to ask, I have tried my best. I have also tried googling and i can not find anything.
I am ...
2
votes
2answers
22 views
Python graph structure and surprising list handling
I'm implementing a graph structure (just for practicing purposes) and now I came to two behaviors I cannot explain to myself.
first, here the code
class Node:
data = None
def __init__(self, ...