`li = [(1106257, (255, 255, 255)), (1, (16, 16, 118)), (1, (32, 32, 128)), (1, (48, 48, 122)), (9, (249, 249, 249)), (1, (64, 64, 126)), (406, (247, 247, 251))]`
I want to sort li depending on the first number in each element eg.1106257, 1, 1,1,9,1,406
How to do this fast? Thanks
...
Hi,
I have a file I read from that looks like:
1 value1
2 value2
3 value3
The file may or may not have a trailing \n in the last line.
The code I'm using works great, but if there is an trailing \n it fails.
Whats the best way to catch this?
My code for reference:
r=open(sys.argv[1], 'r');
for line in r.readlines():
ref...
Preferentially using the standard libraries.
...
How can I prevent OpenSSL (specifically, Python's ssl module) from using system certificate authorities?
In other words, I would like it to trust only the certificate authorities which I specify, and nothing else:
ssl_socket = ssl.wrap_socket(newsocket, server_side=True, certfile="my_cert.pem",
ca_certs=MY_...
Hi,
I'm using djapian as my search backend, and I'm looking to search for a range of values. For example:
query = 'comments:(0..10)'
Post.indexer.search(query)
would search for Posts with between 0 and 10 comments. I cannot find a way to do this in djapian, though I have found this issue, and patch to implement some kind of date rang...
# I have this class:
class Test(webapp.RequestHandler):
myList = []
def get(self):
s = [self.request.get('sentence')]
self.myList.append(s)
htmlcode1 = HTML.table(self.myList)
myListLen = len(self.myList)
lastItem = self.myList[myListLen-2]
# I want to add the following to delete the cont...
I'm using the following code to locate a div:
parser = etree.HTMLParser()
tree = etree.parse(StringIO(page), parser)
div = tree.xpath("//div[@class='content']")[0]
My only problem is, that after doing this I do not want to rely on lxml to extract the contents of said div: I just want to get back the raw XML the div contains. Is this ...
I have a clock I made and I'd like to make it an alarm clock.
...
I am working on a software installer for my current application. It needs to be installed to the System HDD. How owuld I detect the system drive and return the letter from Python?
Would the win32 extensions be useful? How about the os module pre packaged with Python?
...
I've got a python list
alist = [ [0, 4, 5, 5], [2, 2, 4, 5], [6, 7, 8,13]], [ [3, 4, 5, 5], [2, 2, 4, 5], [6, 7, 8,999] ]
I need the result is
alist = [[0,4,8,13], [3, 4, 8, 999]]
It means first two and last two numbers in each alist element.
I need a fast way to do this as the list could be huge.
...
Hello,
I have text which shows course numbers, names, grade and other information for courses taken by students. Specifically, the lines look like these:
0301 453 20071 LINEAR SYSTEMS I A 4 4 16.0
0301 481 20071 ELECTRONICS I WITH LAB A 4 4 16.0
0301 481 20084 ELECTRONICS II WITH LAB...
[Edit]
From the feedback/answers I have received, I gather there is some confusion regarding the original question. Consequently, I have reduced the problem to its most rudimentary form
Here are the relevant facts of the problem:
I have a sorted sequence: S
I have an item (denoted by i) that is GUARANTEED to be contained in S
I want ...
Hello, I'm trying to connect a very basic twisted "hello world" server with a basic Qt tcp client.
The client uses these Signals:
connect(&socket, SIGNAL(connected()), this, SLOT(startTransfer()));
connect(&socket, SIGNAL(readyRead()), this, SLOT(readServer()));
and then readServer() looks like this:
ui->resultLabel->setText("Readin...
I need to unzip a .ZIP archive. I already know how to unzip it, but it is a huge file and takes some time to extract. How would I print the percentage complete for the extraction? I would like something like this:
Extracting File
1% Complete
2% Complete
etc, etc
...
I listen to Python411 but is there any other great podcasts out there for Python and Django?
...
Working on a small web spider in python, using the lxml module I have a segment of code which does an xpath query of the document and places all the links from 'a href' tags into a list. what I'd like to do is check each link as it is being added to the list, and if it is needed, unescape it. I understand using the urllib.unquote() funct...
def by_this(self):
return super(MyModelManager, self).get_query_set().filter(this=True)
def by_that(self):
return super(MyModelManager, self).get_query_set().filter(that=True)
If i do MyModel.objects.by_this() or by_that() it works.
But i want to do: MyModel.objects.by_this().by_that()
...
I understand it's an inner joke that's meant to stay (just like “from __future__ import braces”), but what exactly does it do?
...
I'm experimenting with the new ttk Tile enhancements that ship with Python 2.7.
Windows 7: The code below demonstrates how the combobox dropdown shows up BEHIND our root window when the root window is configured as a topmost window ("always on top"). If you comment out the line """ root.attributes( '-topmost', 1 )""" then the combob...
I was going through http://web2py.com/book/default/chapter/02 and found this:
>>> print 'number is ' + str(3)
number is 3
>>> print 'number is %s' % (3)
number is 3
>>> print 'number is %(number)s' % dict(number=3)
number is 3
It has been given that The last notation is more explicit and less error prone, and is to be preferred.
I am...