The problem is that urllib using httplib is querying fro AAAA records what i would like to avoid. Is there a nice way to do that?
>>> import socket
>>> socket.gethostbyname('www.python.org')
'82.94.164.162'
21:52:37.302028 IP 192.168.0.9.44992 > 192.168.0.1.53: 27463+ A? www.python.org. (32)
21:52:37.312031 IP 192.168.0.1.53 > 192.168...
I wish to dump a multiprcoessing.Queue into a list. For that task I've written the following function:
import Queue
def dump_queue(queue):
"""
Empties all pending items in a queue and returns them in a list.
"""
result = []
# START DEBUG CODE
initial_size = queue.qsize()
print("Queue has %s items initially....
I'm rebuilding my blog at http://www.elmalabarista.com/blog/. I have use in my previous version markdown and now I remember why I have almost zero code samples. Doing code samples in markdown is very fragile.
I try to put some python there I can't make markdown mark it as code!. The main culprit? The syntax is markdown for code is out s...
The following code dies with Trace/BPT trap:
from tvdb_api import Tvdb
from threading import Thread
class GrabStuff(Thread):
def run(self):
t = Tvdb()
def main():
threads = [GrabStuff() for x in range(1)]
[x.start() for x in threads]
[x.join() for x in threads]
if __name__ == '__main__':
main()
The error...
In Python I can define a class 'foo' in the following ways:
class foo:
pass
or
class foo(object):
pass
What is the difference? I have tried to use the function issubclass(foo, object) to see if it returns True for both class definitions. It does not.
IDLE 2.6.3
>>> class foo:
pass
>>> issubclass(foo, obje...
For a mental exercise I decided to try and solve the bubble breaker game found on many cell phones as well as an example here:Bubble Break Game
The random (N,M,C) board consists N rows x M columns with C colors
The goal is to get the highest score by picking the sequence of bubble groups that ultimately leads to the highest score
A bu...
What is the difference, please explain them in laymen's terms with examples. Thanks!
...
I'm having a problem with Python's subprocess.Popen method.
Here's a test script which demonstrates the problem. It's being run on a Linux box.
#!/usr/bin/env python
import subprocess
import time
def run(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
return p
### START MAIN
# copy some rows from a source tab...
Hi all, a question about python regular expression.
I would like to match a div block like
<div class="leftTail"><ul class="hotnews">any news stuff</ul></div>
I was thinking a pattern like
p = re.compile(r'<div\s+class=\"leftTail\">[^(div)]+</div>')
but it seems not working properly
another pattern
p = re.compile(r'<div\s+class...
Suppose I have 2 models.
The 2nd model has a one-to-one relationship with the first model.
I'd like to select information from the first model, but ORDER BY the 2nd model. How can I do that?
class Content(models.Model):
link = models.TextField(blank=True)
title = models.TextField(blank=True)
is_channel = models.Boole...
This may be for most languages in general, but I'm not sure. I'm a beginner at Python and have always worked on copies of lists in C# and VB. But in Python whenever I pass a list as an argument and enumerate through using a "for i in range," and then change the value of the list argument, the input values actually changes the original ...
Does anyone know of a .net wrapper around either python or java Google App Engine services?
Any help appreciated // :)
...
I'd like to upgrade the default python installation (2.5.1) supplied with OS X Leopard to the latest version. Please let me know how I can achieve this.
Thanks
...
I'm trying to write a python program that checks every X seconds if the 'window title' for 'last.fm' (http://www.last.fm/download) changed, if it did (or it's the first time I run the program) it should use use the string captured from the window title to search for the song's lyrics and display them to the user.
I'm currently using KD...
example 1:
['one', 'two', 'one'] should return True.
example 2:
['one', 'two', 'three'] should return False.
...
Basically, i've created a view to populate my database with Serial models from 0000 to 9999. below is the code i'm using for the view.
def insert_serials(request):
for i in range(0,10000):
serial = Serial(i,False)
serial.save()
else:
print 'The for loop is over'
what is the right way to do this, and i'm getting an ...
Hi, I wonder if there is a good way to bind local variables in python. Most of my work involves cobbling together short data or text processing scripts with a series of expressions (when python permits), so defining object classes (to use as namespaces) and instantiating them seems a bit much.
So what I had in mind was something like i...
Hello,
I am currently using Django Users model.
Very simple. However, I'd like to add one feature: Adding friends!
I would like to create 2 columns in my table:
UID (the ID of the User)
friend_id (the ID of his friend! ...of course, this ID is also in Django's User model.
The UID-friend_id combination must be unique! For example, if ...
Have an example piece of (Python) code to check if a directory has changed:
import os
def watch(path, fdict):
"""Checks a directory and children for changes"""
changed = []
for root, dirs, files in os.walk(path):
for f in files:
abspath = os.path.abspath(os.path.join(root, f))
new_mtime = os.sta...
I'm trying to work my way through some frustrating encoding issues by going back to basics. In Dive Into Python example 9.14 (here) we have this:
>>> s = u'La Pe\xf1a'
>>> print s
Traceback (innermost last): File "<interactive input>", line 1, in ?
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>> print s.encode('latin-...