I am learning PyQt from this site. The tutorial is building a widget that colours a square.
In this, they are using CSS to colour the square, rather than give it some sort of concrete property of colour. Why is this? Is there another way to do this without CSS or is this the preferred method? It seems awfully strange..
...
for example, how to I enter this in Python so that it is indented correctly?
if 1 + 2 == 2:
print "true"
print "this is my second line of the block"
print "this is the third line of the block"
...
I need to check if I can write a file to a directory that user point to with Python.
Is there an way to check it in advance? I may be using try .. catch for this purpose, but I expect something better in the sense that I can check in advance.
...
I'm having trouble getting the following simple example to work with SWIG 1.3.40 (and I also tried 1.3.31). The Foo structure comes through as a Python module as long as I don't wrap it in a namespace, but as soon as I do I get a compilation error in the generated test_wrap.c.
test.h:
#ifndef __TEST_H__
#define __TEST_H__
#define USE...
I have a simple program that blits a background image onto the display area, and then puts a sprite in the upper left corner. The sprite uses colorkey transparency, but when I blit the sprite, the areas that should be transparent are black, instead. The color used for the colorkey is a greenish color, so the colorkey is doing something...
I would like to change PATH from Python 2.6.1 to 3.1.2. I have both versions installed on my computer but when I type python --version in the terminal I get Python 2.6.1 so thats the current version its "pointing" to. Now if I type Python3.1 it changes the current version to the one I want to use, though the PATH is still 2.6.1. Download...
How can I get the request body passed on to my views?
class RestHTTPMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
request = Request(environ)
environ['wsgi.input'] = StringIO.StringIO(request.body)
method = webapp.Request(environ).get('_method')
if meth...
Often when I install .exe files made from python files I get an installation manager that is blue and has the logo "python powered". What is the name of this manager? I'd like to use it to make some installable python files.
...
Let's say that I have a python script a.py in /A/B/a.py, and it's in the PATH environment variable. The current working directory is /X/Y/, and it's the directory where I call the /A/B/a.py.
In a.py, how to detect /X/Y/? I mean, how to know in which directory the python call is made?
...
i think there was some directive i could enter in the test that would allow me to run some commands interactively at the point of the directive and then continue the example, but i dont remember what it was...
...
I'm trying to wean myself from BeautifulSoup, which I love but seems to be (aggressively) unsupported. I'm trying to work with html5lib and lxml, but I can't seem to figure out how to use the "find" and "findall" operators.
By looking at the docs for html5lib, I came up with this for a test program:
import cStringIO
f = cStringIO.S...
Is there a way to print string in colorful way with python?
For example, can I print some part of string red or something to a console? I use Mac OS X.
...
I tried all the steps in this tutorial.
Yet I keep geting this ouput
'python' is not recognized as an internal or external command operable program or batch file.
when I run
python setup.py py2exe
in command prompt
What am I doing wrong?
...
I'm trying to practice some django basics by implementing my own sortable table in Django and I've run into a couple of snags.
Here's the code that I'm working with in my view:
def __table_view_helper__(request):
if not request.session.__contains__('filters'):
filters = {'filterA':'',
'filterB':'',
...
I am having an issue deploying a flask app on apache2 using wsgi. I have posted the error logs and config files below. I have tried moving things around, renaming them, etc, but all give me an internal server error. Not sure why I'm getting the import error. Any input / suggestions are appreciated, thanks!
Here is my apache error.log
[...
Hello:
I'm trying to extract the date/time when a picture was taken from the CR2 (Canon format for raw pictures).
I know the CR2 specification, and I know I can use Python struct module to extract pieces from a binary buffer.
Briefly, the specification says that in Tag 0x0132 / 306 I can find an string of length 20 - the date and tim...
I have list MC below:
MC = [('GGP', '4.653B'), ('JPM', '157.7B'), ('AIG', '24.316B'), ('RX', 'N/A'), ('PFE', '136.6B'), ('GGP', '4.653B'), ('MNKD', '672.3M'), ('ECLP', 'N/A'), ('WYE', 'N/A')]
def fn(number):
divisors = {'B': 1, 'M': 1000}
if number[-1] in divisors:
return ((float(number[:-1]) / divisors[number[-1]])
...
let's say I have the following code:
for a in object.a_really_huge_function():
print a
In order to prevent a_really_huge_function from running multiple times, I am used to doing this in other languages:
a_list = object.a_really_huge_function()
for a in a_list:
print a
Is that necessary in Python? Will the part after in run ...
How can I get the base URI in a Google AppEngine app written in Python? I'm using the webapp framework.
e.g.
http://example.appspot.com/
...
which one of the following is considered better a design and why ?.
i have 2 classes , one for the gui components and the other is for it's events.
please put in mind that the eventClass will be implemented so many times, (sometimes to get data from an oracle databases and sometimes mysql databases )
class MainWindow:
def __ini...