def download(source_url):
socket.setdefaulttimeout(10)
agents = ['Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)','Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)','Microsoft Internet Explorer/4.0b1 (Windows 95)','Opera/8.00 (Windows NT 5.1; U; en)']
ree = urllib2.Request(source_url)
ree.add_header('User-Agent',ra...
Hey everyone,
I'm currently playing around with tipfy on Google's Appengine and just recently ran into a problem: I can't for the life of me find any documentation on how to use GET variables in my application, I've tried sifting through both tipfy and Werkzeug's documentations with no success. I know that I can use request.form.get('va...
Say I have a model object 'Person' defined, which has a field called 'Name'. And I have a list of people:
l = ['Bob','Dave','Jane']
I would like to return a list of all Person records where the first name is not in the list of names defined in l.
What is the most pythonic way of doing this?
EDIT: After thinking about it, what I real...
Hi,
I'm creating a game, and am quite new to Python generally.
I created a function 'descriptionGenerator()' which generates a description for characters and objects either randomly or using variables passed to it.
It seemed to be working, but every now and then it wouldn't work correctly. So i placed it in a loop, and it never seems ...
Hi, all.
I'm writing a twitter-like note-taking web app.
In a page the latest 20 notes of the user will be listed,
and when the user scroll to the bottom of the browser window more items will be loaded and rendered.
The initial 20 notes are part of the generated html of my django template, but the other dynamically loaded items are i...
Is there any alternatives to the print statement for output in Python.
Also, how can I format my output text to be color-coded?
I'm a beginner programmer, pretty new to it.
Thanks
...
I'm pretty new to programming, and I'm creating a simple text-based game.>
I'm wondering if there is a simple way to create my own terminal-type window with which I can place coloured input etc.
Is there a graphics module well suited to this?
I'm using Mac, but I would like it to work on Windows as well
Thanks
...
I need to upload multiple files from directory to the server via FTP and SFTP.
I've solved this task for SFTP with python, paramiko and threading. But I have problem with doing it for FTP. I tried to use ftplib for python, but it seems that it doesn't support threading and I upload all files one by one, which is very slow.
I'm wonderin...
Hi -
I'm a bit at a loss as to how to find a clean algorithm for doing the following:
Suppose I have a dict k:
>>> k = {'A': 68, 'B': 62, 'C': 47, 'D': 16, 'E': 81}
I now want to randomly select one of these keys, based on the 'weight' they have in the total (i.e. sum) amount of keys.
>>> sum(k.values())
>>> 274
So that there's...
Hi,
I'm working on a sudoko solver (python). my method is using a game tree and explore possible permutations for each set of digits by DFS Algorithm.
in order to analyzing problem, i want to know what is the count of possible valid and invalid sudoko tables?
-> a 9*9 table that have 9 one, 9 two, ... , 9 nine.
(this isn't exact dupl...
I'm trying to urlencode an dictionary in python with urllib.urlencode. The problem is, I have to encode an array.
The result needs to be:
criterias%5B%5D=member&criterias%5B%5D=issue
#unquoted: criterias[]=member&criterias[]=issue
But the result I get is:
criterias=%5B%27member%27%2C+%27issue%27%5D
#unquoted: criterias=['member',+'i...
maps = (maps.filter(name__icontains=search_terms) |
maps.filter(description__icontains=search_terms))
i can't find this filter .
thanks
...
I'm using gtk.combo_box_new_text() to make combobox list, this uses a gtk.ListStore to store only strings, so there are some way to add a separator between items without use a complex gtk.TreeModel?
If this is not possible, what is the simplest way to use a gtk.TreeModel to able secuential widget addition?
...
Hi
I have this code that fetches some text from a page using BeautifulSoup
soup= BeautifulSoup(html)
body = soup.find('div' , {'id':'body'})
print body
I would like to make this as a reusable function that takes in some htmltext and the tags to match it like the following
def parse(html, atrs):
soup= BeautifulSoup(html)
body = s...
I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't show up in the model:
Ca...
I'm a newbie to regular expressions and I have the following string:
sequence = '["{\"First\":\"Belyuen,NT,0801\",\"Second\":\"Belyuen,NT,0801\"}","{\"First\":\"Larrakeyah,NT,0801\",\"Second\":\"Larrakeyah,NT,0801\"}"]'
I am trying to extract the text Belyuen,NT,0801 and Larrakeyah,NT,0801 in python. I have the following code which is...
Hello,
I have a datetime.datetime property var.
I would like to know if it is less than one hour of the current time.
Something like
var.hour<datetime.datetime.today().hour - 1
Problem with the above syntax is that
datetime.datetime.today().hour
returns a number such as "10" and it is not really a date comparation but more of a n...
Hello everybody,
I've been trying to find a python code that would log in to my mail box on yahoo.com from "Google App Engine"
.
Here (click here to see that page) I was given this code:
import urllib, urllib2, cookielib
url = "https://login.yahoo.com/config/login?"
form_data = {'login' : 'my-login-here', 'passwd' : 'my-password-here'...
I'm having a bit of trouble with ReferencePropertys in App Engine (Python).
For a bit of fun, I'm trying to model a folder/file system, but having trouble getting folders to reference folders.
My first attempt was this:
class Folder(db.Model):
id = db.StringProperty()
name = db.StringProperty()
created = db.DateTimeProper...
I am trying to call Python's time.strftime() function using a Unicode format string:
u'%d\u200f/%m\u200f/%Y %H:%M:%S'
(\u200f is the "Right-To-Left Mark" (RLM).)
However, I am getting an exception that the RLM character cannot be encoded into ascii:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u200f' in position 2:...