python

Two arguments in one def?

Hello everybody First, here's my code: import poplib def con(pwd): M = poplib.POP3_SSL('pop3.live.com', 995) try: M.user(pwd) M.pass_('!@#$%^') except: print "[-]Not Found!:",pwd else: print '[+]Found password' exit() f = open("Str1k3r.txt", "r") for pwd in f.readlines(): co...

Checking for empty number as input

Hi all. Consider this code: >>> num = int(raw_input('Enter the number > ')) If the user types nothing and presses 'Enter', I want to capture that. (Capture an empty input) There are two ways of doing it: I do a simple num = raw_input(), then check whether num == ''. Afterwards, I can cast it to a int. I catch a ValueError. But in t...

How to make Django's devserver public ? Is it generaly possible ?

Hello, Experts I've got a question. I'm currently trying out the Django framework and I would share/present/show some stuff I've made to my workmate/friends. I work in Ubuntu under Win7 via VMware. So my wish/desire is to send my current pub-IP with port (e.g http://123.123.123.123:8181/django-app/) to my friends so they could test it....

how to remove '\xe2' from a list

Hi all! I am new to python and am using it to use nltk in my project.After word-tokenizing the raw data obtained from a webpage I got a list containing '\xe2' ,'\xe3','\x98' etc.However I do not need these and want to delete them. I simply tried if '\x' in a and if a.startswith('\xe') and it gives me an error saying invalid \x e...

Python library for monitoring /proc/diskstats?

Hi, I would like to monitor system IO load from a python program, accessing statistics similar to those provided in /proc/diskstats in linux (although obviously a cross-platform library would be great). Is there an existing python library that I could use to query disk IO statistics on linux? ...

Python: Something like `map` that works on threads

I was sure there was something like this in the standard library, but it seems I was wrong. I have a bunch of urls that I want to urlopen in parallel. I want something like the builtin map function, except the work is done in parallel by a bunch of threads. Is there a good module that does this? ...

Limit the number of sentences in a string

A beginner's Python question: I have a string with x number of sentences. How to I extract first 2 sentences (may end with . or ? or !) ...

File size representation (12M, 1.6K...)

Possible Duplicate: Reusable library to get human readable version of file size? Hi, How can I convert a number (file size in bytes) to a string like the --human-readable option does in some UNIX commands ? Examples : 42e5 => 4.2M 2000 => 2.0K Many thanks ! ...

Object_list always empty

Hi , the app is working this way. That i have a simple news adding model as below: class News(models.Model): title = models.CharField(max_length=100) publication_date = models.DateField(auto_now_add=True) content = models.TextField() the view def homepage(request): posts= News.objects.all() #.get(title="aaa") retu...

Making text bold with django

I have to send make some text bold in between plain text and send it to the template from the view. I do this: I save a string like this <b>TextPlaintext</b> in a variable and return it to the template. The "<b>" tags are not interpreted. How can make some text bold in a django view? ...

How to remove u'' from python script result?

Hello. I'm trying to wrote parsing script using python/scrapy. How can I remove [] and u' from strings in result file? Now I have text like this: from scrapy.spider import BaseSpider from scrapy.selector import HtmlXPathSelector from scrapy.utils.markup import remove_tags from googleparser.items import GoogleparserItem import sys clas...

Limit connection rate in Python Twisted?

Is there any way to limit connection rate in Python Twisted? I need to simulate the slow dataline, with timeouts and optionally data loss and use twisted framework. ...

What are the existing open-source Python WxWidgets designers?

What are the usable tools? I am aware of wxformbuilder and wxGlade, but none of them seems to be complete yet. ...

What does this stand for?

What does '\r' mean? What does it do? I have never seen it before and its giving me headaches. It doesnt seem to have any purpose, since 'a\ra' prints as 'aa', but its not the same as the string 'aa'. Im using python 2.6 ...

adjusting heights of individual subplots in matplotlib in Python

if I have a series of subplots with one column and many rows, i.e.: plt.subplot(4, 1, 1) # first subplot plt.subplot(4, 1, 2) # second subplot # ... how can I adjust the height of the first N subplots? For example, if I have 4 subplots, each on its own row, I want all of them to have the same width but the first 3 subplots to be short...

How to speed up multidimensional array access in scipy.weave?

Hi All: I'm weaving my c code in python to speed up the loop: from scipy import weave from numpy import * #1) create the array a=zeros((200,300,400),int) for i in range(200): for j in range(300): for k in range(400): a[i,j,k]=i*300*400+j*400+k #2) test on c code to access the array code=""" for(int i=0;i<20...

How to validate an xml file against an XSD Schema using Amara library in Python?

High bounty for the following Q: Hello, Here is what I tried on Ubuntu 9.10 using Python 2.6, Amara2 (by the way, test.xsd was created using xml2xsd tool): g@spot:~$ cat test.xml; echo =====o=====; cat test.xsd; echo ==== o=====; cat test.py; echo =====o=====; ./test.py; echo =====o===== <?xml version="1.0" encoding="utf-8"?>==; ....

How can I validate CSS within a script?

Is there a library out there which will validate CSS? The only tools I can find to do so are web sites. If one of these sites has an API, that would fit the bill, too. I have a script that serves as a CSS compiler. It sets various variables according to settings for a theme, and generates and writes a CSS file. Before committing to wri...

Various queries - MongoDB

Hi folks, This is my table: unicorns = {'name':'George', 'actions':[{'action':'jump', 'time':123123}, {'action':'run', 'time':345345}, ...]} How can I perform the following queries? Grab the time of all actions of all unicorns where action=='jump' ? Grab all actions of...

Can a process running a 32bit compiled binary use more than 4gb of memory?

Is it possible for a single process running a 32bit compiled version of python in Snow Leopard (64bit machine) to appear to consume > 4gb (say 5.4gb) of virtual memory as seen by the top command? I did a file ...python to see that the binary was not x86, yet it appeared to be consuming over 5gb of memory. My guess is that the librari...