I have been playing with Google App engine a lot lately, from home on personal projects, and I have been really enjoying it. I've converted a few of my coworkers over and we are interested in using GAE for a few of our projects at work.
Our work has to be hosted locally on our own servers. I've done some searching around and I really ca...
Is there a consensus about the best place to put Python unittests?
Should the unittests be included within the same module as the functionality being tested (executed when the module is run on its own (if __name__ == '__main__', etc.)), or is it better to include the unittests within different modules?
Perhaps a combination of both app...
I need to change some custom properties values in many files. Here is an example of code - how I do it for a single file:
import win32com.client
MSWord = win32com.client.Dispatch("Word.Application")
MSWord.Visible = False
doc = MSWord.Documents.Open(file)
doc.CustomDocumentProperties('Some Property').Value = 'Some New Value'
doc.Save(...
I saw on the Google App Engine documentation that http://www.antlr.org/ Antlr3 is used as the parsing third party library.
But from what I know Pyparsing seems to be the easier to use and I am only aiming to parse some simple syntax.
Is there an alternative? Can I get pyparsing working on the App Engine?
...
I wrote a small python program to iterate over data file (*input_file*) and perform calculations. If calculation result reaches certain states (stateA or stateB), information (hits) are extracted from the results. The hits to extract depend on parameters from three parameter sets.
I used a dictionary of dictionaries to store my parameter...
I have a string that looks like so:
6Â 918Â 417Â 712
The clear cut way to trim this string (as I understand Python) is simply to
say the string is in a variable called s, we get:
s.replace('Â ', '')
That should do the trick. But of course it complains that the Non-ASCII character '\xc2' in file blabla.py is not encoded.
I never q...
Sorry for the generic title, will change it once I understand the source of my problem
I have the following structure:
foo/
foo/__init__.py
foo/bar/
foo/bar/__init__.py
foo/bar/some_module.py
When I try to import some_module by doing so:
from foo.bar import some_module
it works like a charm.
But this is no good for me, since I only...
I have a stock Pylons app created using paster create -t pylons with one controller and matched functional test, added using paster controller, and a SQLAlchemy table and mapped ORM class. The SQLAlchemy stuff is defined in the init_model() function rather than in module scope (and needs to be there).
Running python setup.py test raises...
I have a friend who I am trying to teach how to program. He comes from a very basic PHP background, and for some reason is ANTI C#, I guess because some of his PHP circles condemn anything that comes from Microsoft.
Anyways - I've told him its possible to use either Ruby or Python with the VS2008 IDE, because I've read somewhere that th...
Task:
I generate formated excel tables from csv-files by using the python package pyExcelerator (comparable with xlwt). I need to be able to write less-than-or-equal-to (≤) and greater-than-or-equal-to (≥) signs.
So far:
I can save my table as csv-files with UTF-8 encoding, so that I can view the special characters in my text editor, by...
I'm trying to match these kinds of strings
{@csm.foo.bar}
without matching any of these
{@[email protected]}
{@csm.foo.bar-42}
The regex I use is
r"\{@csm.((?:[a-zA-Z0-9_]+\.?)+)\}"
It gets dog slow if the string contains multiple matches. Why? It runs very fast if I take away the brace matching, like this
r"@csm.((?:...
I'm trying to get a queryset to issue its query over a different DB connection, using a different cursor class. Does anyone know if that's possible and if so how it might be done? In psuedo-code:
# setup a new db connection:
db = db_connect(cursorclass=AlternateCursor)
# setup a generic queryset
qset = blah.objects.all()
#...
I have a list in Python, and I want to check if any elements are negative. Specman has the has() method for lists which does:
x: list of uint;
if (x.has(it < 0)) {
// do something
};
Where it is a Specman keyword mapped to each element of the list in turn.
I find this rather elegant. I looked through the Python documentation an...
I would like to build a code library in IronPython and have another C# project reference it. Can I do this? How?
Is this just as simple as building the project and referencing the dll? Is there any conflict with the dynamic aspect of it?
...
Hi there,
I have a model that holds user address. This model has to have first_name and last_name fields since one would like to set address to a recipient (like his company etc.). What I'm trying to achieve is:
if the fist_name/last_name field in the address is filled - return simply that field
if the fist_name/last_name field in the...
You can skip to the bottom line if you don't care about the background:
I have the following code in Python:
ratio = (point.threshold - self.points[0].value) / (self.points[1].value - self.points[0].value)
Which is giving me wrong values. For instance, for:
threshold: 25.0
self.points[0].value: 46
self.points[1].value: 21
I go...
In C++, void somefunction(int) passes a value, while void somefunction(int&) passes a reference. In Java, primitives are passed by value, while objects are passed by reference. How does python make this decision?
Edit: Since everything is passed by reference, why does this:
def foo(num):
num *= 2
a = 4
foo(a)
print(a)
print '4'...
Ok, I think whatever I'm doing wrong, it's probably blindingly obvious, but I can't figure it out. I've read and re-read the tutorial section on packages and the only thing I can figure is that this won't work because I'm executing it directly. Here's the directory setup:
eulerproject/
__init__.py
euler1.py
euler2.py
...
euler...
I'm using Python's logging mechanism to print output to the screen. I could do this with print statements, but I want to allow a finer-tuned granularity for the user to disable certain types of output. I like the format printed for errors, but would prefer a simpler format when the output level is "info."
For example:
logger.error(...
How do I parse sentence case phrases from a passage.
For example from this passage
Conan Doyle said that the character of Holmes was inspired by Dr. Joseph Bell, for whom Doyle had worked as a clerk at the Edinburgh Royal Infirmary. Like Holmes, Bell was noted for drawing large conclusions from the smallest observations.[1] Michael Har...