I'm using python 2.6 and matplotlib. If I run the sample histogram_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
---------------
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_sub...
I have a module named module.py, which checks a global variable in context.
module.py:
----------
if 'FOO' in globals():
print 'FOO in globals'
else:
print 'nah'
in python shell:
----------------
In [1]: FOO = True
In [2]: import module
nah
how can i import modules with existing context?
...
I'm reading in a file with Python's csv module, and have Yet Another Encoding Question (sorry, there are so many on here).
In the CSV file, there are £ signs. After reading the row in and printing it, they have become \xa3.
Trying to encode them as Unicode produces a UnicodeDecodeError:
row = [unicode(x.strip()) for x in row]
Unicod...
Is there a reasonable pattern for handling an object that exists as a Django model within the context of a particular Django application and as a non-Django class outside of that particular application?
For example, let's say that I have a Post model within Django application Blog. I want to be able to interact with a class representing...
hi there.
Im doing som route(geo) calculations.
I need to sort out some routes going in the "wrong" direction...
all rides have "routes" and all routes consist of a lot of steps on the route.... each step has a lat. and a lng. pair.
I hope this makes sense?
This is the way i do it now, and it works... however... im performing this...
Hello everyone.
I have been surfing around on google, googling away in order to find the source of a Python HTTP proxy server, because i wish to write my own. Good news is: I found lots! Bad news is: I think they are too complicated. At least for me to properly grasp. I have seen python do stuff like this before in very simple and compac...
I think 'unpack' might be the wrong vocabulary here - apologies because I'm sure this is a duplicate question.
My question is pretty simple: in a function that expects a list of items, how can I pass a Python list item without getting an error?
my_list = ['red', 'blue', 'orange']
function_that_needs_strings('red', 'blue', 'orange') # w...
This is not a duplicate of this question.
I am already aware of virtualenv and virtualenvwrapper and pip but they don't quite seem to have exactly what I want.
I'm looking for a way that I can not only have multiple versions of Python installed but also multiple versions of Django (for example) and mix and match the "active" versio...
Hi all -
Quick question about ctypes syntax, as documentation for Unions isn't clear for a beginner like me.
Say I want to implement an INPUT structure (see here):
typedef struct tagINPUT {
DWORD type;
union {
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
} ;
} INPUT, *PINPUT;
Should I or do I need to chang...
Hello,
in my python app, I print some stuff during a cycle.
After the cycle, I want to close the stdout/stderr window that the prints produced using python code.
How can I do that?
Thanks in advance
...
I have built a gameboard that consists of a grid, the grid is then randomly assigned, "Walls" to a cell. Once the cells are built, how can I check to see if a certain cell is 'locked in' so that I don't place a player there.
I have thought about this and the first ago I came up with check all sides for four walls, but obviously, a ce...
I'm writing a REST web service on twisted and I want to use OAuth 2.0 for authorization. Is there a tutorial out there to help me write the OAuth server without having to read the entire spec? I know it's in draft, but even Facebook is using it.
...
So far I have been using Twisted to simultaneously serve a lot of mobile clients (Android, iPhone) with their HTTP requests exchanging JSON messages.
For my next project I'd like to try out Google App Engine, but I'm wondering if it is capable of doing the same or if I should rather go with a custom built solution again.
...
I'm trying to create a "Product" object in SQLAlchemy and so far I have gotten everything working accept the Product's "accessories". What I have is a Product with a list of field/value pairs (ie. Capacity : 12 L etc.), and integer ID and a catalog number. I would like to be able to associate certain "accessories" with a given product wh...
In this code:
soup=BeautifulSoup(program.Description.encode('utf-8'))
name=soup.find('div',{'class':'head'})
print name.string.decode('utf-8')
error happening when i'm trying to print or save to database.
dosnt metter what i'm doing:
print name.string.encode('utf-8')
or just
print name.string
Traceback (most recent ca...
I am really confused as to why Python acts in a particular way.
Here is an example: I have a dictionary called "copy". (It is a copy of an HttpRequest.POST in django.)
Here is a debug session (with added line numbers):
1 (Pdb) copy
2 <QueryDict: {u'text': [u'test'], u'otherId': [u'60002'], u'cmd': [u'cA'], u'id':
3 [u'15']}>
4 (Pdb) ...
I have a computational intensive project that is highly parallelizable: basically, I have a function that I need to run on each observation in a large table (Postgresql). The function itself is a stored python procedure.
Amazon EC2 seems like an excellent fit for the project.
My question is this: Should I make a custom image (AMI)...
I am maintaining a Python script that uses xlrd to retrieve values from Excel spreadsheets, and then do various things with them. Some of the cells in the spreadsheet are high-precision numbers, and they must remain as such. When retrieving the values of one of these cells, xlrd gives me a float such as 0.38288746115497402.
However, I n...
What Python web framework (Django?, Pylons?, ...) suitable for building ad serving application (like AdSense)?
...
I know how to pass 1 attribute, but how do I pass 2?
e.g.
somerows = soup.findAll('a', target="blank")
what if I want all links that have target="blank" and class="blah" ?
...