I tried to do that, and I found this errors:
>>> import re
>>> x = 'Ingl\xeas'
>>> x
'Ingl\xeas'
>>> print x
Ingl�s
>>> x.decode('utf8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(...
I'd like everything to function correctly, except when it's mobile, the entire site will used a set of specific templates.
Also, I'd like to autodetect if it's mobile. If so, then use that set of templates throughout the entire site.
...
I would like to know what is the best import strategy whithin django reusable applications.
Say I have an application called usefulapp. Inside my app, I will need to access, say, the models. Should I use an explicit import as:
import usefulapp.models
or simply, since I am inside this very app, I could use:
import models
Which one ...
I am trying to get some content in html documents. Some of the documents have a table of contents that very nicely indicates where in the document the content I want to strip out is located. That is either the value or text_content of the tag are easily identifiable and point to what I need. For example I might have two anchor tags in...
I'm beginning python and I'm trying to use a two-dimensional list, that I initially fill up with the same variable in every place. I came up with this:
def initialize_twodlist(foo):
twod_list = []
new = []
for i in range (0, 10):
for j in range (0, 10):
new.append(foo)
twod_list.append(new)
...
I just started to learn Python few days ago, which is also my first programming language, I'm so excited about it, just loving it, thinking about it any minute.
in order to spend more time practice my skills, get familiar with the syntax, I'm seeking if it's possible to setup python environment on my mobile, so that i can program while ...
I'm currently trying to scrape a website that has fairly poorly-formatted HTML (often missing closing tags, no use of classes or ids so it's incredibly difficult to go straight to the element you want, etc.). I've been using BeautifulSoup with some success so far but every once and a while (though quite rarely), I run into a page where ...
I am trying to create a template that will put items in a table.
Controller:
items = Item.all().order('name').fetch(10)
template_values = {'items': items,
'headers': ['Name', 'Price', 'Quantity']}
render('Views/table.html', self, template_values)
Template:
<table>
<tr>
{% for header in headers...
Hi
I'd like to get suggestions on the best way to serve python scripts up as web pages. Typically I'd like a way for me and my colleagues to write simple web pages with minimal effort ie we focus on the business logic eg creating simple forms etc. Possibly with some way to manage sessions but this is a nice-to-have. It doesn't have to b...
I've got multiple python processes (typically 1 per core) transforming large volumes of data that they are each reading from dedicated sources, and writing to a single output file that each opened in append mode.
Is this a safe way for these programs to work?
Because of the tight performance requirements and large data volumes I don't ...
I have a list of hex bytes strings like this
['BB', 'A7', 'F6', '9E']
(as read from a text file)
How do I convert that list to this format?
[0xBB, 0xA7, 0xF6, 0x9E]
...
I have a dictionary as follows:
{'A':0,'C':0,'G':0,'T':0}
I want to create an array with many dictionaries in it, as follows:
[{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},{'A':0,'C':0,'G':0,'T':0},...]
This is my code:
weightMatrix = []
for k in range(motifWidth):
weightMatrix[k] = {'A':0,'C':0,...
I am using jsonpickle to serialize an object to json. The object has certain fields that point to other objects. I'd like to selectively not include those in the serialization, so that the resulting json file is essentially pure human-readable text without any funny representations of objects. Is there a way to make jsonpickle ignore cer...
Say that I have two figures in matplotlib, with one plot per figure:
import matplotlib.pyplot as plt
f1 = plt.figure()
plt.plot(range(0,10))
f2 = plt.figure()
plt.plot(range(10,20))
Then I show both in one shot
plt.show()
Is there a way to show them separately, i.e. to show just f1?
Or better: how can I manage the figures separat...
Hi everyone,
i'm starting to learn Qt for python and as i was wondering after reading this post :
qt - pyqt QTableView not populating when changing databases. if there was a way to use SQLAlchemy sessions instead of (re-)opening a database connection as a Table Model with Qt's QTableView widget.
Something that would work a little bit l...
SOLVED: The problem was actually using time.time() every CPU cycle to see whether the next frame should be drawn or not. The time it takes to execute time.time() was having an impact on the FPS.
I made this function for drawing 2D textures as images in a 2D view in my OpenGL application. After doing some testing I found that it takes up...
I can use this verb in the Python Windows SDK. But not in production. Why? What am I doing wrong?
The error message includes (only seen via firebug or fiddler)
Malformed request
or something like that
My code looks like:
from google.appengine.ext import db
from google.appengine.ext import webapp
class Handler(webapp.RequestHand...
I have the following simple methods for writing a python object to a file using jsonpickle:
def json_serialize(obj, filename, use_jsonpickle=True):
f = open(filename, 'w')
if use_jsonpickle:
import jsonpickle
json_obj = jsonpickle.encode(obj)
f.write(json_obj)
else:
simplejson.dump(obj, f)
...
How do I get python to run sudo openvpn --cd /etc/openvpn --config client.ovpn
I'm trying the following at the minute without success
vpnfile2 = '/etc/init.d/openvpn'
cfgFile = 'client.ovpn'
os.system('sudo \"" + vpnFile2 + "\" --cd \"" + vpnpath + "\" --config \"" + cfgFile + "\"')
...
In some Python (v3) code I am creating lists of Decimals from user input, like this:
input = [] # later populated with strings by user with values like '1.45984000E+001'
decimals = [Decimal(c) for c in input]
However, sometimes the input list contains strings that cannot be parsed. How can I test if c can be represented as a decimal b...