python

How can I group a large dataset

I have simple text file containing two columns, both integers 1 5 1 12 2 5 2 341 2 12 and so on.. I need to group the dataset by second value, such that the output will be. 5 1 2 12 1 2 341 2 Now the problem is that the file is very big around 34 Gb in size, I tried writing a python script to group them into a dictionary with val...

Comparing strings using '==' and 'is'

Possible Duplicates: Types for which is keyword may be equivalent to equality operator in Python Python is operator behaves unexpectedly with integers Hi. I have a question which perhaps might enlighten me on more than what I am asking. Consider this: >>> x = 'Hello' >>> y = 'Hello' >>> x == y True >>> x is y True I hav...

Fast replacement of values in a numpy array

I have a very large numpy array (containing up to a million elements) like the one below: [ 0 1 6 5 1 2 7 6 2 3 8 7 3 4 9 8 5 6 11 10 6 7 12 11 7 8 13 12 8 9 14 13 10 11 16 15 11 12 17 16 12 13 18 17 13 14 19 18 15 16 21 20 16 17 22 21 17 18 23 22 18 19 24 23] and a small dictionary map for replacing some of t...

urllib.urlopen to open page on same port just hangs

I am trying to use urllib.urlopen to open a web page running on the same host and port as the page I am loading it from and it is just hanging. For example I have a page at: "http://mydevserver.com:8001/readpage.html" and I have the following code in it: data = urllib.urlopen("http://mydevserver.com:8001/testpage.html") When I try an...

djangoproject access fields of object dynamically

Hello, Can anyone help me? I have list of fields called 'allowed_fields' and I have object called 'individual'. allowed_fields is sub set of individual. Now I want to run loop like this for field in allowed_fields: obj.field = individual.field obj have same fields like individual. Do you have solution of my problem? I w...

How to unittest a BaseHTTPRequestHandler subclass?

Since python normally takes care of instantiating these objects I'm not entirely sure how get a standalone instance of this so I can test the do_GET, do_POST, etc. methods. Any suggestions are welcome. ...

How to tell if item in list contains certain characters.

I have a script that creates a list of numbers, and i want to remove all numbers from the list that are not whole numbers (i.e have anything other than zero after the decimal point) however python creates lists where even whole numbers get .0 put on the end, and as a result i cant tell them apart from numbers with anything else. I can't ...

Python performance: search large list vs sqlite

Lets say I have a database table which consists of three columns: id, field1 and field2. This table may have anywhere between 100 and 100,000 rows in it. I have a python script that should insert 10-1,000 new rows into this table. However, if the new field1 already exists in the table, it should do an UPDATE, not an INSERT. Which of ...

Reading and comparing lines in a file using Python.

I have a file of the following format. 15/07/2010 14:14:13 changed_status_from_Offline_to_Available 15/07/2010 15:01:09 changed_status_from_Available_to_Offline 15/07/2010 15:15:35 changed_status_from_Offline_to_Away became_idle 15/07/2010 15:16:29 changed_status_from_Away_to_Available became_unidle 15/07/2010 15:45:40 changed_status_f...

Changing the encoding of a table with django+south migrations

Hi Guys, Django and south newbie here I need to change the encoding of a table I created, does anyone know a way to do so using a migration? ...

Finding the user who uses my django web application

I have developed a small django web application. It still runs in the django development web server. It has been decided that if more than 'n' number of users like the application, it will be approved. I want to find out all the users who view my application. How can find the user who views my application? Since I was the user who ran ...

Django - Limit users who view the items

My Models: class PromoNotification(models.Model): title = models.CharField(_('Title'), max_length=200) content = models.TextField(_('Content')) users = models.ManyToManyField(User, blank=True, null=True) groups = models.ManyToManyField(Group, blank=True, null=True) I want to publish there items to templates with some p...

Generating python dict keys on the fly

Working with deeply nested python dicts, I would like to be able to assign values in such a data structure like this: mydict[key][subkey][subkey2]="value" without having to check that mydict[key] etc. are actually set to be a dict, e.g. using if not key in mydict: mydict[key]={} The creation of subdictionaries should happen on ...

Execute raw SQL after connect to database

How can I execute raw SQL after connect to database? I need to run script once, after connect to DB. Thanks. UPD: question is not how to run raw SQL. ...

Python modules for visualization of C++ code

I'm looking for python modules that can help with grepping C++ code. I have a large code base that I would like to do some analysis on. Ultimately I would like to come up with a graphical map of the software. There is lots of message passing going on amongst apps so I would like to be able to capture that information and present it vi...

python multiprocessing does not work

I don't understand why this simple code # file: mp.py from multiprocessing import Process import sys def func(x): print 'works ', x + 2 sys.stdout.flush() p = Process(target= func, args= (2, )) p.start() p.join() p.terminate() print 'done' sys.stdout.flush() creates "pythonw.exe" processes continuously and it doesn't print a...

Soaplib exceptions

Hi! What's the best way to return an http error or throw an exception using the soaplib? Thanks! ...

How to run an application with the foreground privilege on windows?

I have a python program that is controlled via a web interface on localhost. This program needs to start applications and bring them to foreground - which is easy (using AttachThreadInput / SetForegroundWindow) until the app in question requires an UAC dialog. Since I cannot use the AttachThreadInput/SetForegroundWindow trick on the UA...

Django from Java developer perspective

Hey, I'm a long time Java programmer and I'm digging into Django recently to see what it offers. It looks to me that Django doesn't fit Java web developers taste. I mean in MVC Java web frameworks we have usually a controller class that receives the request, do the logic and then forwards the request to another destination. Rails als...

Demonstrating instruction level parallelism at work

I'm trying to show instruction level parallelism at work. What I was originally doing was using python (willing to change) and doing the following: def test(): for i in range(5000): j = 0 k = 0 l = 0 def test2(): for i in range(5000): j = i * i k = j * 2 l = k * i if __name__=='_...