python

Using beautifulSoup, trying to get all table rows that have a string in them.

I need to get all table rows on a page that contain a specific string 'abc123123' in them. The string is inside a TD, but I need the entire TR if it contains the 'abc123123' anywhere inside. I tried this: userrows = s.findAll('tr', contents = re.compile('abc123123')) I'm not sure if contents is the write property. My html looks som...

issue with Python Gtk+

I can't nail exactly when/what update I did on my Lucid box but now I get: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import gtk /usr/lib/pymodules/python2.6/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display warnings.wa...

source code trees: wide or deep

After writing a few python appengine apps I find myself torn between two approaches to organizing my source code tree: wide or deep. For concreteness, consider an internal application for a small consulting shop to manage business operations like contact management, project tracking & reporting, and employee management. The applicati...

django 'module' object has no attribute 'call_command'

def cmd_run(host="localhost", port="8000"): """Run server at given host port (or localhost 8000)""" from django.core import management host_port = '%s:%s' % (host, port) management.call_command('runserver', host_port) I wrote a command like this. When I execute it. Exception was thrown: Traceback (most recent call last...

Why does this provided regular expression return true?

I would like to know why following regular expression returns true: reg = re.compile (r'[0-9]%') reg.search ("50%") [0-9] would match any single digit, in this case 5. But then 0 doesn't match %, so it should return false, but it returns true. My code might have syntax errors, but you get the gist of it. ...

Does python have a string contains method?

I'm looking for a string.contains or string.indexof method in Python. I want to do: if not somestring.contains("blah"): continue ...

escaping characters in a regex

The regular expression below: [a-z]+[\\.\\?] Why is \\ slash used twice instead of once? ...

python read last line !

My problem is in this code: try: PassL = open(sys.argv[3], "r").readlines() print "[+] Passwords:",len(PassL),"\n" except(IOError): print "[-] Error: Check your wordlist path\n" sys.exit(1) for word in PassL: word = word.replace("\r","").replace("\n","") login_form_seq = [ ('log', sys.argv[2]), (...

Python PySerial read-line timeout

Hi all I'm using pyserial to communicate with a embedded devise. ser = serial.Serial(PORT, BAUD, timeout = TOUT) ser.write(CMD) z = ser.readline(eol='\n') So we send CMD to the device and it replies with an string of varing length ending in a '\n' if the devise cant replay then readline() times-out and z='' if the devise is interr...

Lingering Django Database

I had to remove my Django Database (drop all the tables). Now when I try to run "manage.py syncdb" to recreate those tables I get the message "Table 'user_database.engine.city' doesn't exist" Is there a file lingering that is telling djnago these tables still exist? EDITED QUESTION: I had to remove my Django Database (drop all the tab...

How do I disable a button after it's clicked in wxpython?

There are two buttons in my little program, start and stop. And what I want is to disable the start button after I click it, and when I hit the stop button it should return to normal. How can I do this? I googled for a while and couldn't find the answer, hope you guys can help me out. Thanks! ...

How do you have python scripts display how much time it takes to execut each process?

It was something like cMessage I think? I can;t remember, could someone help me? ...

Finding the correlation matrix

Hi, I have a matrix which is fairly large (around 50K rows), and I want to print the correlation coefficient between each row in the matrix. I have written Python code like this: for i in xrange(rows): # rows are the number of rows in the matrix. for j in xrange(i, rows): r = scipy.stats.pearsonr(data[i,:], data[j,:]) ...

Reading file using python and and see if a particular string is there inthe file.

I have a file in the following format Summary;None;Description;Emails\nDarlene\nGregory Murphy\nDr. Ingram\n;DateStart;20100615T111500;DateEnd;20100615T121500;Time;20100805T084547Z Summary;Presence tech in smart energy management;Description;;DateStart;20100628T130000;DateEnd;20100628T133000;Time;20100628T055408Z Summary;meeting;Descrip...

Creating a Key Command in Python

I'm writing my own simple key logger based on a script I found online. However, I'm trying to write a key command so that the logger program will close when this command is typed. How should I go about this? (Also I know it's not secure at all, however that's not a concern with this program) For example Ctrl + 'exit' would close the pro...

python dictionary

>>> d2 {'egg': 3, 'ham': {'grill': 4, 'fry': 6, 'bake': 5}, 'spam': 2} >>> d2.get('spamx',99) 99 >>> d2.get('ham')['fry'] 6 I want to get value of fry inside of ham, if not, get value, 99 or 88 as the 2nd example. But how? ...

Create directory while upload using django

After uploading a file from the UI, how to create the a new directory with the current timestamp in /opt/files/ and copy the uploaded zip file to this directory, and unzip the zip file in the new directory and maintain the new directory name in a variable def upload_info(request): if request.method == 'POST': fi...

Django model inheritance and type check

class Machine(models.Model): name= models.CharField( max_length=120) class Meta: abstract = True class Car(Machine): speed = models.IntegerField() class Computer(Machine) ram = models.IntegerField() My question is, how can I understand what type is the Machine model. For instamce I know the incoming query is a...

Python: date formatted with %x (locale) is not as expected

I have a datetime object, for which I want to create a date string according to the OS locale settings (as specified e.g. in Windows'7 region and language settings). Following Python's datetime formatting documentation, I used the %x format code which is supposed to output "Locale’s appropriate date representation.". I expect this "repr...

How to create the union of many sets using a generator expression?

Suppose I have a list of sets and I want to get the union over all sets in that list. Is there any way to do this using a generator expression? In other words, how can I create the union over all sets in that list directly as a frozenset? ...