text stringlengths 226 34.5k |
|---|
Python error with debugging
Question: I am very new with Python and I have just received this message while trying
to use Visual Studio plugin for Python:
try:
import boinc # getting the exception here
_BOINC_ENABLED = True
except:
_BOINC_ENABLED = False
and this is the ... |
python: from modules import abc.py does not work
Question: I have recently switched from python 2.7 to python 3.2
considering following folder structure:
~/my_program
~/my_program/modules
where *my_program* is the root of the application, containing main script
called _main.py_
... |
Setting properties from CSV file using eval (Python)
Question: I have CSV files that contain numerous values that I want to reference. I
wanted to parse them succinctly using `eval`. Here's what I tried:
line = fileHandle.readline()
while line != "":
if line != "\n":
parameter = line.sp... |
modifying familyName and givenName
Question: I'm having an issue renaming a user account's familyName and givenName. I'm
using the GData API for Python. After running the program no errors are shown.
When I print the entryObject it does not show any difference from the
original. What am I doing wrong? Thank you!
... |
Sorting a Python list by third element, then by first element, etc?
Question: Say I have a list in the form [[x,y,z], [x,y,z] etc...] etc where each
grouping represents a random point.
I want to order my points by the z coordinate, then within each grouping of
z's, sort them by x coordinate. Is this possible?
Answer... |
Get recarray attributes/columns python
Question: I'm trying to retrieve the column titles of a recarray, and running into
considerable trouble. If I read in a .csv file using pylab's csv2rec function,
I am able to access column titles in the following manner:
from pylab import csv2rec
x = csv2rec(fil... |
What are the downsides to defining a C macro that works like the Python "with" statement?
Question: After playing around a bit with C preprocessors, I thought of a way to have
something similar to a Pythonian with control structure, defined like this:
#define with(var) for(int i##__LINE__=0;i##__LINE__<1... |
Searching and writing
Question: I need to write a program which looks for words with the same three middle
characters(each word is 5 characters long) in a list, then writes them into a
file like this :
wasdy
casde
tasdf
gsadk
csade
hsadi
Between the similar words i need to ... |
OpenGL ES source files
Question: I am trying to build the OpenGL SO lib from android sources (libGLESv2.so) and
i would like a little bit more understanding of the internal mechanism of
Android OpenGL ES and the flow.
Please correct me where i am wrong: I know that in windows a developer
includes gl.h and static link ... |
Why does "pip install" raise a SyntaxError?
Question: I'm trying to use pip to install a package. I try to run `pip install` from
the Python shell, but I get a `SyntaxError`. Why do I get this error? How do I
use pip to install the package?
>>> pip install selenium
^
SyntaxError: in... |
Compare List Similarity Python
Question:
S = ['hom']
L = ['home','honda','Hammer','Elephant']
I want to get output to show similarity
hom = home
and
print home
How I can do this? I want to use approximate matching to change "hom" to
"home".
Answer: For somethi... |
payload of an email in string format, python
Question: I got payload as a string instance using `get_payload()` method. But I want my
payload in a way where I could access it word by word I tried several things
like `as_string() method, flatten() method, get_charset() method` , but every
time there is some problem.
I ... |
Python callback working with functions but not methods
Question: I have a third-party Python library that allows me to register a callback
function that it called later.
While the code works okay with functions, when I tried to pass a method it
fails, the callback is never called.
I have no control over the third par... |
Python - Append to CSV
Question: I am trying to append to a CSV file with the following code
import csv
cat_options = [row for row in csv.reader(open('catOptions.csv', 'r'), delimiter =',')]
print cat_options
new_cat = raw_input("\nEnter the new category: ")
cat_options = csv.writer(open(... |
Converting IBM DB2 IXF file to CSV or XML
Question: How do I convert an exported IXF file (using `db2 export`) to a human-readable
format, like CSV or XML? I am comfortable with doing it in Python or .NET C#.
Answer: The PC/IXF format is fairly complex, and is practically unknown to programs
outside of DB2. Writing y... |
Python : Display a Dict of Dicts using a UI Tree for the keys and any other widget for the values
Question: I have three dicts, one providing a list of all the available options, and two
providing a subset of choices (one set for defaults and one for user choices).
I get the three dicts using python's built in JSON par... |
how to run python script from shell
Question: I have a noob question.
I got a python script path1/path2/file.py
The script has a function:
def run (datetime = None):
In the shell I call
import path1.path2.file
import datetime
path1.path2.file.run(datetime = datetime(2011,12... |
Python subprocess call with arguments having multiple quotations
Question: I use the following command in bash to execute a Python script.
python myfile.py -c "'USA'" -g "'CA'" -0 "'2011-10-13'" -1 "'2011-10-27'"
I'm writing a Python script to wrap around this one. I'm currently having to
use os.sy... |
Sending JSON using the django test client
Question: I'm working on a django a project that will serve as the endpoint for a
webhook. The webhook will POST some JSON data to my endpoint, which will then
parse that data. I'm trying to write unit tests for it, but I'm not sure if
I'm sending the JSON properly.
I keep get... |
How to receive/get C struct from Python
Question: I have a standalone Python module used to perform analysis on some raw data.
The module is working great.
Now I need the output generated by the Python module in C source that will do
further processing on output.
Here is the rough idea of flow:
1. C source will ca... |
Writing complex custom metadata on images through python
Question: I'm looking to write custom metadata on to images(mostly jpegs, but could be
others too). So far I haven't been able to do that through PIL preferably (I'm
on centos 5 & I couldn't get pyexiv installed) I understand that I can update
some pre-defined ta... |
How to do POS tagging using the NLTK POS tagger in Python?
Question: I just started using a part-of-speech tagger, and I am facing many problems.
I started POS tagging with the following:
import nltk
text=nltk.word_tokenize("We are going out.Just you and me.")
When I want to print `'text'`, th... |
How to fill a textArea in an online form automatically using Python?
Question: I am wondering how I can fill an online form automatically. I have researched
it and it tuned out that, one can uses Python ( I am more interested to know
how to do it with Python because it is a scripting language I know) but
documentation ... |
How to use python NLP POS tagger in C# code?
Question: I came across and successfully used a python NLP POS tagger.The problem is
that my code was in c# and I used a python pos tagger because I could not find
a good c# pos tagger.Now,I don't know how to use this python NLP POS tagger in
my c# code.Could anyone guide me... |
How to put device context (wx.DC) into a sizer? -wxpython
Question: Hello I would like to put device context into a sizer, however when I try to
do this, python returns an error.
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(pa... |
load pyd files from a zip from embedded python
Question: I can load Python modules (.py, .pyc, .pyd) from a zip file by calling "import
some_module" from a Python interpreter only after sys.path has been extended
to include the zip file and only after I have run
import zipextimporter
zipextimporter.i... |
Get point IDs after clustering, using python
Question: > **Possible Duplicate:**
> [Python k-means
> algorithm](http://stackoverflow.com/questions/1545606/python-k-means-
> algorithm)
I want to **cluster** 10000 indexed points based on their feature vectors and
**get their ids** after clustering i.e. cluster1:[p1, ... |
How to tell what python version libboost_python.so is using?
Question: I'd like to know what version of python boost_python.so is expecting. This is
on a computer with multiple python versions and I did not build/install boost
myself (nor do i have root access).
How can i tell what version of python boost_python.so is... |
Using matplotlib: ImportError: No module named animation?
Question: I've tried using the EPD installation on Mac OS X, the apt-get install process
on Ubuntu, and the EPD installation on Ubuntu.
In the python interactive interpretor:
>>> import matplotlib.animation as animation
Traceback (most recent... |
How to pass value to a function
Question: I am new to python and doing this homework. I need to create a small program
with menu. I was very good 'til now. I am a little bit lost. How can I pass a
value to the function? Can you please check if there are any other faults in
my code.
import turtle as t
... |
Using Voice instead of 'raw_input' in python for Mac OS X
Question: I'm in the process of making a Python-based personal assistant/question
answerer, which, in my wildest dreams, will rival the inevitable "Siri For
Mac". However, as of now, it requires you type text into an infinite loop of
raw_inputs, and processes th... |
Initializing a static variable in Python
Question: ## Context
Say, we want to use the Box-Muller algorithm. Starting from a couple of random
numbers U1 and U2, we can generate G1 and G2. Now, for any call, we just want
to output either G1 or G2. In other languages, we could use static variables
to be able to know if w... |
Python logging with multiple modules
Question: I have got various modules in which I use Python logging heavily. When I
import them into the main module like in the Python documentation and try to
run it, I don't get any output from the logging. Has anyone got any idea what
is happening?
Logging is called in the modul... |
Removing cocos2d-python from Mac
Question: I installed cocos2d today on OS X Lion, but whenever I try to import **cocos**
in the Python interpreter, I get a bunch of import errors.
> File "", line 1, in File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/ python2.7/site-
> packages/cocos2d-0.5.0-py2.7.egg/co... |
I clear try clearing the surface in python, then it still draws the button?
Question: I clear try filling the screen with white then importing an image, but when I
use display.flip() the buttons are still there and it still detects collision?
How do I fix this??
def stagesel():
screen.fill(WHITE)
... |
Python, os.system fails when script not in same folder
Question: I have a bat.bat file containing the following command: **'setup.py build'**
I have a script that executes this bat command using:
`os.system('E:/bla/FPtest/retryURL/Temp_installed/bat.bat'`
If i run the script from the same folder as the bat.bat ... |
Unexpected: flufl.enum prints integer value
Question: Using Python 3, I unpackaged the flufl.enum code into my application source
tree just to try it. Sample code:
from taurine.flufl.enum import Enum
class Colors(Enum):
red = 1
green = 2
blue = 3
print(Colors.red... |
Click the javascript popup through webdriver
Question: I am scraping a webpage using Selenium webdriver in Python
The webpage I am working on, has a form. I am able to fill the form and then I
click on the Submit button.
It generates an popup window( Javascript Alert). I am not sure, how to click
the popup through we... |
Why do I keep getting this title match error with my Python program?
Question: When I run the following code, I keep getting this error:
Traceback (most recent call last):
File "C:\Users\Robert\Documents\j-a-c-o-b\newlc.py", line 94, in <module>
main()
File "C:\Users\Robert\Documents\... |
More pythonic way to iterate in Numpy
Question: I am an engineering student and I'm accustomed to write code in Fortran, but
now I'm trying to get more into Python for my numerical recipes using Numpy.
If I needed to perform a calculation repeatedly using elements from several
arrays, the immediate translation from wh... |
Python tkinter grid manager?
Question: I just learned how to use tkinter in Python (3.2.2), and I'm having some
problem using the grid manager. When I put button.grid(sticky=SE), for
example, the button is not being put in the bottom-right and is just being put
in the upper-left, ignoring the sticky value. What am I do... |
What is wrong with my regex Pattern to find recurring cycles in Python?
Question: I want to match any string that has a recurring cycle. Like in this data:
3333333333333333333333333333333333333333 / 1 digit cycle(3)
1666666666666666666666666666666666666666 / 1 digit cycle(6)
142857142857142857142... |
Why does the code : os.popen('move *.bin tmp) only move one file?
Question: all,
Currently, I write a python code in WIN, i'd like to run the command line code
move *.bin tmp
but only one file was removed.
How can I make popen to finish this task?
Best wish!
Answer: I suggest using Pythons own... |
Extract Text from a Binary File (using Python 2.7 on Windows 7)
Question: I have a binary file of size about 5MB.. which has lots of interspersed text..
and control characters..
This is actually an equivalent of an outlook .pst file for SITATEX Application
(from SITA).
The file contains all the TEXT MESSAGES sent and... |
Why are my Amazon S3 key permissions not sticking?
Question: I'm using the Python library `boto` to connect to Amazon S3 and create buckets
and keys for a static website. My keys and values are dynamically generated,
hence why I am doing this programmatically and not through the web interface
(it works using the web in... |
multiprocessing Listeners and Clients between python and pypy
Question: Is it possible to have a [Listener server process and a Client
process](http://docs.python.org/library/multiprocessing.html#module-
multiprocessing.connection) where one of them uses a python interpreter and
the other a [pypy](http://pypy.org/) int... |
TaggedCorpusReader and UnigramTagger in nltk (python)
Question: I'm trying to use nltk to auto-categorize news articles in a very lo-fi way.
I've created a custom corpus of word/tag pairs correlating to my categories
(ie. teacher/EDU, computer/TECH, etc.) I've been reading around and [this
question](http://stackoverflo... |
gai error at /home [Errno -2] Name or service not known
Question: per the example in the httplib docs:
>>> import httplib, urllib
>>> params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
... ... |
Pprint module works slowly with Django in 32bits system
Question: I use Django on a 32 bits Ubuntu machine with Python 2.7. My development
server has been slow all the time, taking about 15 seconds to render any page.
I ran a cProfile test to see what works so slowly.
Seems that it's the pprint module.
Here's my stat... |
Conversion of unix epoch time to windows epoch time in python
Question: Quick question: Is there a pythonic (whether in the standard libraries or not)
way to convert unix 32-bit epoch time to windows 64-bit epoch time and back
again?
Answer: You can convert a POSIX timestamp to a `datetime` with
>>> ts... |
pythonic way to iterate over part of a list
Question: I want to iterate over everything in a list except the first few elements,
e.g.:
for line in lines[2:]:
foo(line)
This is concise, but copies the whole list, which is unnecessary. I could do:
del lines[0:2]
for line in... |
Error: Could not import settings 'mysite.settings' after setting up virtualenv for Django
Question: I am doing this on Fedora
**Problem:**
(sandbox)[root@localhost mysite]# django-admin.py runserver
Error: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.setti... |
imp.load_source() in Python
Question: When is it useful to use `imp.load_source()`
[method](http://docs.python.org/library/imp.html) for importing Python module?
Has it some advantage in some scenario in opposite to normal importing with
`import` keyword?
Answer: `import` always looks in the following
[order](http://... |
including additional static xml with python
Question: I need my current script to include additional xml. This is the script in its
current form:
import csv
import sys
from xml.etree import ElementTree
from xml.dom import minidom
video_data = ((256, 336000),
(5... |
Eclipse PyDev auto-import malfunctioning
Question: I've been trying to get used to pydev for a couple of days now, and I really
like it, but if I keep the auto-import option on, it keeps importing for
example `from test.test_iterlen import len` (and many others) whenever I want
a `len(something)` even though it's not n... |
do not understand this use of sys module
Question: Here is code from a tutorial in A Byte of Python:
import sys
filename = 'poem.txt'
def readfile(filename):
#Print a file to standard output
f = file(filename)
while True:
line = f.readline()
... |
Why does Django make Python look ugly?
Question: I took up the Python programming language because of its design philosophies,
its great community and most importantly for me its beautiful syntax. However,
recently I've been a left a little disheartend. In my attempts to customise
Django I've come across code that I th... |
Unescaping filenames generated by ls -R
Question: I have a text file containing the output of a recursive directory listing that
generally looks like this:
./subfolder/something with spaces:
something\ with\ spaces.txt*
something\ with\ spaces.dat*
./subfolder/yet another thing:
yet\... |
Unusual Math with incorrect results?
Question: My python interpreter is acting funky when I use the math.cos() and math.sin()
function. For example, if I do this on my calculator:
cos(35)*15+9 = 21.28728066
sin(35)*15+9 = 17.60364655
But when I do this on python (both 3.2 and 2.7)
... |
Roundrobin over changing set
Question: I'd like to implement a simple round robin over a Python list or set that may
be changed at runtime. The Problem is that I have a set of tasks that are to
be executed in a round robin fashion, which should be simple enough to
implement with a list and a modular increment of the in... |
Mac OS X 10.6, Mysql, Mysql-Python, Django
Question: # UPDATE:
I came across this post: [Python mysqldb on Mac OSX 10.6 not
working](http://stackoverflow.com/questions/5072066/python-mysqldb-on-mac-
osx-10-6-not-working) saw two options:
1. Add MySQL client libraries to the LD_LIBRARY_PATH
mysql_config --libs -L/u... |
Python SUDS SOAP request to https service 401
Question: I am trying use SUDS and am stuck trying to figure out why I can't get
authentication to work (or https).
The service I am trying to access is over https with basic digest
authentication. Based on the debugs it seems to be using http instead of
https. But not rea... |
How can I use Python to pipe stdin/stdout to Perl script
Question: This Python code pipes data through Perl script fine.
import subprocess
kw = {}
kw['executable'] = None
kw['shell'] = True
kw['stdin'] = None
kw['stdout'] = subprocess.PIPE
kw['stderr'] = subprocess.PIPE
args =... |
Python: How to import, from two modules, Classes that have same names?
Question: I'm writing a python programm to do granular syncs between different DB.
I'm using SQLAlchemy and a module named sqlautocode for DB inspecting and
Schema Classes production.
Having two DB to sync, with same tables name, the Classes writt... |
Python catch any exception, and print or log traceback with variable values
Question: When I catch unexpected error with sys.excepthook
import sys
import traceback
def handleException(excType, excValue, trace):
print 'error'
traceback.print_exception(excType, excValue, trace)... |
wxpython capture keyboard events in a wx.Frame
Question: I'm trying to capture keyboard events that happen inside a wx.Frame, and I
would expect the following code to capture those events. However, the handler
OnKeyDown is never called when I run the code:
import logging as log
import wx
cla... |
Application of the dynamic/functional features of Python
Question: I'm learning Python and it seems to be too dynamic to me. Application of some
of the dynamic/functional features I understand. For example, you can use
dynamic typing to write functions that behave the same for complex and real
numbers. But application ... |
Python IP Check
Question: Given the range xxx.xxx.xxx.(195-223) Is that correct to write it in
xxx.xxx.xxx.196/29 and check whether an IP is in the given network by doing
from ipaddr import IP, CIDR
#if IP('xxx.xxx.xxx.xxx') in IP('xxx.xxx.xxx.196/29') or
#if IP('xxx.xxx.xxx.xxx') in CIDR('xxx.x... |
Error while using urllib.request.urlopen in Python
Question: What's wrong with this code?
>>> from urllib.request import urlopen
>>> for line in urlopen("http://google.com/"):
print(line.decode("utf-8"))
<!doctype html><html><head><meta http-equiv="content-type" content="text... |
matlab subsref: {} with string argument fails, why?
Question: There are a few implementations of a hash or dictionary class in the Mathworks
File Exchange repository. All that I have looked at use parentheses
overloading for key referencing, e.g.
d = Dict;
d('foo') = 'bar';
y = d('foo');
wh... |
Python variables naming convention
Question: So I am trying to switch to PEP8 notation (from a rather personal CamelCase
notation) and I was wondering how you guys are tackling the cases where
existing functions/variables would be overwritten?
e.g. having something like:
open, high, low, close, sum = ro... |
python: how to tell if file executed as import vs. main script?
Question: I'm writing a python file `mylib.py`
I'd like mylib.py to do something based on `sys.argv` if it's being executed
as a script. But if it's imported from some other script, I don't want it to
do that.
How can I tell if my python file is being im... |
Python UTF-8 XML parsing (SUDS): Removing 'invalid token'
Question: Here's a common error when dealing with UTF-8 - 'invalid tokens'
In my example, It comes from dealing with a SOAP service provider that had no
respect for unicode characters, simply truncating values to 100 bytes and
neglecting that the 100'th byte ma... |
How to append to PYTHONPATH in Tornado so Handlers can use other libraries?
Question: I am attempting to start a Tornado web server, but I need the Handlers to be
able to import libraries from a custom path. I cannot simply add
sys.path.append('..') when launching Tornado, so how do I do it?
Answer:
import sys
... |
Passing in arguments to a called script
Question: I'm running `nosetests` on my project with `--with-snort` for Growl
notifications.
The problem is that I have some lib files that I put on the path, so I have a
custom python script at `bin/python`.
I have no issues running nose via my `bin/python` by doing `which nos... |
PYTHON 2.6 XML.ETREE to output single quote for attributes instead of double quote
Question: i got the following code :
#!/usr/bin/python2.6
from lxml import etree
n = etree.Element('test')
n.set('id','1234')
print etree.tostring(n)
the output generate is `<tes... |
AES Encryption in Google App Engine (Python) and Decryption on iOS (Objective-C)
Question: I'm trying to encrypt some data from python (Google App Engine) and then
decrypt it on iOS.
There are several issues surrounding this based on the fact that there are so
many options with AES Encryption and the different formats... |
Best way to implement 2-D array of series elements in Python
Question: I have a dynamic set consisting of a data series on the order of hundreds of
objects, where each series must be identified (by integer) and consists of
elements, also identified by an integer. Each element is a custom class.
I used a defaultdict to... |
Google App Engine static pages Python 2.5 directories etc
Question: I am new at this and am planning to move my stuff from a paid web service to
GAE (nothing dynamic just static pages). Believe me I have spent countless
hours trying to make this work but am at an impasse whereby I achieve one
result at the exclusion of... |
how to extract certain text from file?
Question: i want to extract certain section of the text file. my input file:
-- num cell port function safe [ccell disval rslt]
"17 (BC_1, CLK, input, X)," &
"16 (BC_1, OC_NEG, input, X), " &-- Merged input/
" 8 (BC_1, D(8), input, X)," & -- ce... |
Python's pretty printing of matrix
Question: I have to print several rows of data and do it good. I can do it with C++
changing parameters of std::cout, but I can't understand how I can do it with
Python. For example, I have this:
row1 = [1, 'arc1.tgz', 'First', '15.02.1992']
row2 = [16, 'arc2modifie... |
Change from re.findall(regex, text) to nltk.Text.findall(regex)
Question: Using Python and the NLTK I have written a regex to find words with start with
a capital letter in a body of text but aren't at the beginning of a sentence.
Initially I was using it as follow:
[w for w in text if re.findall(r'(?<!... |
Linear interpolation using pycuda (lerp)
Question: I am a recreational pythonista who just got into pyCUDA. I am trying to figure
out how to implement a linear interpolation (lerp) using pyCUDA. The CUDA CG
function is: <http://http.developer.nvidia.com/Cg/lerp.html>
My ultimate goal is a bilinear interpolation in pyc... |
Python CGI not executing on Mac OSX 10.6.7
Question: Recently I started reading Mark Lutz's "Programming Python - Fourth Edition".
I am a mac user, using ActivePython and OSX 10.6.7. Anyways, everything was
going fine until the first instance of CGI in the book. The code example
creates a form, and uses a POST method f... |
Python - Multiple choice markup parsing
Question: Consider this text:
> Would you like to have responses to your questions sent to you via email ?
I'm going to propose multiple choices for several words by marking up them
like that:
> Would you like [to get]|[having]|g[to have] responses to your questions sent
> [up... |
heatmap using scatter dataset python matplotlib
Question: I am writing a script to make a heatmap for scatter data on two dimensionS.
The following is a toy example of what I am trying to do:
import numpy as np
from matplotlib.pyplot import*
x = [1,2,3,4,5]
y = [1,2,3,4,5]
heatmap, xedges... |
Gunicorn + Subprocesses raises exception [Errno 10]
Question: I've stumbled across a weird exception I haven't been able to resolve... can
anyone suggest what is wrong or a new design? I'm running a Gunicorn/Flask
application. In the configuration file, I specify some work to do with an
`on_starting` hook [1]. Inside t... |
How to create a query for matching keys?
Question: I use the key of another User, the sponsor, to indicate who is the sponsor of
a User and it creates a link in the datastore for those Users that have a
sponsor and it can be at most one but a sponsor can sponsor many users like in
this case ID 2002 who sponsored three ... |
Unresolved import csv Pydev Eclipse
Question: I have a love-hate relationship with Pydev on Eclipse. For some reason it is
now telling me that it has an unresolved import on the code:
import csv
Traceback (most recent call last):
File "/Users/peterstannett/Documents/Programming/python/ecli... |
wxpython: Multiple panels
Question: I'm new to wxpython so bare with me.
I'm having two problems with my program. The code below generates two panels
when it should generate 3. It generates `panel1` and `panel2` no problem but
`panel3` should be to the right of `panel2` is no where to be seen. `Panel1`
and `panel2` ar... |
using Mysql and SqlAlchemy in Pyramid Framework
Question: Pyramid Framework comes with a sample tutorial of sql alchemy that uses
sqlite. The problem is that i want to use mysql so i change this
sqlalchemy.url = sqlite:///%(here)s/tutorial.db
Into this
sqlalchemy.url = mysql://root:2... |
How do you make a sprite appear in pygame/python?
Question: I'm trying to make a basic (Mario style) game but my sprite(plumber) doesn't
appear, it could be hidden behind background? i'm not exactly sure, i am not
getting any errors either.
import pygame
import sys
import itertools
import pyg... |
Python: Using itertools to get previous, current, and next item in list from text file
Question: I have setup my code as outlined in [this
answer](http://stackoverflow.com/a/1012089/571600) (shown below):
from itertools import tee, islice, chain, izip
def previous_and_next(some_iterable):
... |
Draw simple shapes and save to file (pdf)
Question: I am looking for a python library that I can use to draw simple shapes and
characters and then save to a file (in a format convertible to pdf). I would
prefer if I did not need an X-server running.
E.g. could look something like this
import drawing_lib... |
Internal Python ID for first field in database
Question: The following is part of my python script:
gp.CalculateField_management("parcs", "Apn", "[oldApnfield]")
The problem is that the field I am calculating from is going to be named
something different in each shapefile, so I can't use the field ... |
Neighbourhood of Scipy Labels
Question: I've got an array of objects labeled with `scipy.ndimage.measurements.label`
called `Labels`. I've got other array `Data` containing stuff related to
`Labels`. How can I make a third array `Neighbourhoods` which could serve to
map **the nearest label to _x,y_ is _L_**
Given `Lab... |
Algorithm to extract network info from ifconfig (ubuntu)
Question: Im trying to parse info from ifconfig (ubuntu). Normally, I would split a
chunk of data like this down into words, and then search for substrings to get
what I want. For example, given `line = "inet addr:192.168.98.157
Bcast:192.168.98.255 Mask:255.255.... |
Control loop for a number-guessing game in Python
Question: I'm trying to write a program which generates a pseudo-random number and
allows the user to guess it. When the user guesses the number wrong, as is
most likely, I would like the function to return to the beginning of the
conditional loop, not the very beginnin... |
Optimizing matplotlib pyplot: plotting for many small plots
Question: I want to make a movie of some plotted points moving around for a rudimentary
traffic simulation. Plotting takes forever, though--~10 frames takes 7s!!
What's up with that?
Python code:
import numpy as np
import matplotlib.pyplot ... |
Python unittest issue
Question: I have a unittest script in a 'tests' directory which I execute like: $
python3 -m unittest mainmodule.tests,
the entire class is a super simple one, has an assertEquals(1, 1), the script
runs, but it says: 0 tests ran in 0.000 seconds .... OK.
No matter how I run the script (from cons... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.