python

Display gaps in dates with Python and Django

I'm building an application that requires each user to make a post on a daily basis. I'd like to display the gaps in dates where users haven't made posts. Since it doesn't seem like a good idea to insert empty database rows for empty posts, I'm only inserting a record when the user adds a post. The model contains a field named log_date....

How can I translate this XPath expression to BeautifulSoup?

In answer to a previous question, several people suggested that I use BeautifulSoup for my project. I've been struggling with their documentation and I just cannot parse it. Can somebody point me to the section where I should be able to translate this expression to a BeautifulSoup expression? hxs.select('//td[@class="altRow"][2]/a/@href...

Python: Extract HTML from an XML file

My XML file looks like this: <strings> <string>Bla <b>One &amp; Two</b> Foo</string> </strings> I want to extract the content of each <string> while maintaining the inner tags. That is, I would like to see the following Python string: u"Bla <b>One & Two</b> Foo". Alternatively, I guess I could settle on u"Bla <b>One & Two</b> ...

What is wrong with my "digit finder" in python?

I am learning python through the Project Euler problems. For problem 40 I wrote this code: import math i = 1 counter = 0 while counter <= 1000000: MMM = int(math.log(i, 10)) + 1 counter = counter + MMM V = math.log(i, 10) print(i, counter, MMM, V) i += 1 It is supposed to return the number containing the Nth dig...

List view is not refreshed if setTabText() is called

Yes, I know this sounds crazy. But here's the situation. I composed a minimal code reproducing the bug. The code creates main window with QTabWidget, which, in turn, has one tab with QListView and a button. List view is connected to QAbstractListModel. Initially, list model contains empty list. If user clicks on a button, it is populate...

Draw bold/italic text with PIL?

How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only. ...

How do I check the index of a an element in a list? (Python)

list = [('ba',4), ('hh',5), ('gg', 25)] How do I do: list.index('hh') ...and returns 1? Then, how do I sort it by the 25, 5, 4? What if I have 2 lists: list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] how do I do a for each? for item in l1: if item[0] in l2[0 of the tuple]: ...

Why can't I join this tuple in Python?

e = ('ham', 5, 1, 'bird') logfile.write(','.join(e)) I have to join it so that I can write it into a text file. ...

How to pass an unicode char argument to ImageMagick?

Suppose the char of "▣" is in somefont.ttf's glyph table. char = unichr(9635) subprocess.call(['convert', '-font', 'somefont.ttf', '-size', '50x50', '-label:%s' % char, 'output.png']) subprocess.call(['convert', '-font', 'somefont.ttf', '-size', '50x50', ('-label:%s' % char).encode('utf-8'), 'output.png']) Both create an blank imag...

Why can't I sort this list?

statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working. ...

Compile IP2Location Python extension for Windows 7

I want to compile / install the IP2Location Python extension found here: www.ip2location.com/python.aspx I tried following the instructions at these sites: eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/ boodebr.org/main/python/build-windows-extensions But I am getting no where. The pr...

What is the preferred technique to convert an object's properties to a sorted list of tuples?

I'm working with an open-source library and they define a class like so: class Provider(object): """ Defines for each of the supported providers """ DUMMY = 0 EC2 = 1 EC2_EU = 2 RACKSPACE = 3 SLICEHOST = 4 GOGRID = 5 VPSNET = 6 LINODE = 7 VCLOUD = 8 RIMUHOSTING = 9 I need to take the propert...

Get process argument info in windows with python/pywin32?

In linux, I know with 'ps' you can get the arguments that a command was run with. I need the equivalent in windows Right now in python I'm doing Process[i] = subprocess.Popen(cmd + " --daemon --config " + str(i) + ".conf", shell=False) But I'm doing this in a daemon that is meant to be up all (or most) of the time. Since I'm having t...

What's an easy way to implement a --quiet option in a python script

Am working on a command line python script - throughout the script, I have a lot of information I am print-ing to the terminal window so that I may follow along with what is happening. Using OptionParser I want to add a --quiet option so I can silence all the output. I am looking for a pythonic way to go about implementing this through...

How to create a generator/iterator with the Python C API?

How do I replicate the following Python code with the Python C API? class Sequence(): def __init__(self, max): self.max = max def data(self): i = 0 while i < self.max: yield i i += 1 So far, I have this: #include <Python/Python.h> #include <Python/structmember.h> /* Define a ne...

Why does PIP install of python-couchdb experimental branch from SVN fail?

I'm setting up a Fabric/virtualenv/pip automated deployment for a project and I need to install the latest experimental branch of python-couchdb. Naturally, I stick it in my pip requirements file, like so: -e svn+http://couchdb-python.googlecode.com/svn/branches/experimental/httplib@195#egg=CouchDB-dev_r195 However, when I run my dep...

want to develop a app in python which interacts with the web and posts on facebook , twitter and gtalk?

i want to develop a python desktop app which interacts and posts its content on facebook , twitter or gtalk as a message . is it possible?... tutorials and ideas will help ...

How to convert seconds to hh:mm:ss with the Django's date template tag ?

Hello, Edit : is there a way to easily convert {{ value|date:"Z" }} to one of the +hh:mm or -hh:mm formats (because date:"Z" returns xxxx or -xxxx seconds). Show this for more explanations about the needed format. Thank you and sorry for my ugly english. ;) ...

How to get the html source of a specific element with selenium?

Hi, The page I'm looking at contains : <div id='1'> <p> text 1 <h1> text 2 </h1> text 3 <p> text 4 </p> </p> </div> I want to get all the text in the div, except for the text that is in the <h>. (I want to get "text 1","text 3" and "text 4") There may be a few <h> elements, or none at all. And there may be a few <p> elements, even one...

Getting value of TextCtrl from a different wxPanel

I was trying to get my first wxWindow application to work and I ran into following difficulty: I create wxPanel and add a wxNotebook object to it. Then I add a page to notebook created from another wxPanel object. How do I access a value of TextCtrl from first wxPanel in the second one? import wx class BasicApp(wx.App): def OnInit(se...