python

cx_Oracle problem trying to import python

I am trying to run python in an Apache WS in a linux RHEL x86_64. After Install and configure Python2.5 and Apache, I install Oracle Instant Client (basic and sdk) in a by an .rpm file withou any problem. oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm I set the envoirment variables ...

Why use pip over easy_install?

A tweet reads: Don't use easy_install, unless you like stabbing yourself in the face. Use pip. Why use pip over easy_install? Doesn't the fault lie with PyPI and package authors mostly? If an author uploads crap source tarball (eg: missing files, no setup.py) to PyPI, then both pip and easy_install will fail. Other than cosmet...

Management form error while using modelformsets ('ManagementForm data is missing or has been tampered with')

I have a models.py class as below class Educational_Qualification(models.Model): user = models.ForeignKey(User) exam = models.CharField(max_length=40) pass_month = models.CharField(max_length=40) I have a views.py as below def create_qualification(request): QFormSet = modelformset_factory(Educational_Qualification, extra=3,...

How to optimize a recursive algorithm to not repeat itself?

After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my needs, a generic "diff"-ing module was written to solve a problem space. After having several months to think more about what it is doing, the recursive algorithm appears to be searching more than in needs to by re-searching the same area...

As of July 2010, compare and contrast the various Windows Python distributions ideally with a recommendation of your favourite.

As of July 2010, compare and contrast the various Windows Python distributions ideally with a recommendation of your personal favourite. ...

how to scroll a page inside a qwebview?

I guess this should be a simple task: change a QWebView's content (it always contains several pages of stuff) then scroll the page back in the previous position: y = self.webView.page().mainFrame().scrollPosition().y() self.webView.setHtml(looong_html_text) if y != 0: self.webView.scroll(0, y) self.webView.page().mainFrame().scr...

websocket handshake problem

I'm using python to implement a simple websocket server. The handshake I'm using comes from http://en.wikipedia.org/w/index.php?title=WebSockets&amp;oldid=372387414. The handshake itself seems to work, but when I hit send, I get a javascript error: Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 Here's the html: <!doctype htm...

How can memoization be applied to this algorithm?

After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my needs, a generic "diff"-ing module was written to solve a problem space. After having several months to think more about what it is doing, the recursive algorithm appears to be searching more than in needs to by re-searching the same area...

Read all the contents in ini file into dictionary with Python

Normally, I code as follows for getting a particular item in a variable as follows try: config = ConfigParser.ConfigParser() config.read(self.iniPathName) except ConfigParser.MissingSectionHeaderError, e: raise WrongIniFormatError(`e`) try: self.makeDB = config.get("DB","makeDB") except ConfigParser.NoOptionError: s...

how to find the target file's full(absolute path) of the symbolic link or soft link in python

when i give ls -l /etc/fonts/conf.d/70-yes-bitmaps.conf lrwxrwxrwx <snip> /etc/fonts/conf.d/70-yes-bitmaps.conf -> ../conf.avail/70-yes-bitmaps.conf so for a symbolic link or soft link, how to find the target file's full(absolute path) in python, If i use os.readlink('/etc/fonts/conf.d/70-yes-bitmaps.conf') it outputs ../conf....

GAE datastore export_transform

Bulkload automatic configuration bulkload.yaml. How to export reference property for key reference field back to datastore from csv. - property: datacenter external_name: datacenter # Type: Key Stats: 2 properties of this type in this kind. import_transform: transform.create_foreign_key('DataCenter') export_transform: transform....

Process closing

Hello, can I use Popen from python subprocess to close started process? For example, from popen I run some application. In some part of my code I have to close that ran app. For example, from console in Linux I do: ./some_bin ... It works and logs stdout here ... Ctrl + C and it breaks I need something like Ctrl + C but in my program ...

Python UTF8 string confusion

Been banging my head on this for a while and I've read a bunch of articles and the issue isn't any clearer. I have a bunch of strings stored in my database, imagine the following: x = '\xd0\xa4' y = '\x92' At the Python shell I get the following: print x Ф print y ? Which is exactly what I want to see. However then there is the fol...

Difference between LoopingCall and callInThread in Python's Twisted.

I'm trying to figure out the differences between a task.LoopingCall and a reactor.callInThread in Twisted. All my self.sendLine's in the LoopingCall are performed immediately. The ones in the callInThread are not. They're only sent after the one in the LoopingCall has finished. Even though I'm sending the right delimiter. Why is that? ...

Django iterating problem - calculating a sum

i;m trying to iterate through some values, and calculate a rank. i have a calculate_rank function where i calculate a sum of values. The problem is at the second function. I want that a user's rank to be the sum of all the user that in a follow relation with him. I am doing an iteration in the second function here where i try to add the...

python form handle

How can I handle html form input (array) like the one below in Python: <input type='hidden' name='a[]' value='some_value'> The following doesn't work: a_value = form["a"].value Please help. Many thanks in advance. ...

asynchronous programming in python

Is there a generic notion of asynchronous programming in python? Could I assign a callback to a function, execute it and return to the main program flow immediately, no matter how long the execution of that function would take? ...

Python timezones - pytz.common_timezones has too many

There are way too many overlapping timezones in pytz's common list. Has anyone pared this down? For example there are 5 or 6 duplicate Canadian timezones and 15 or so duplicate US time zones. China is 1 timezone no DST, but has 5 entries.. By duplicate I mean GMT offset and DST are exactly the same. Getting rid of the timezones in pytz...

How to copy last X bits?

Let's say I have two integers with the following binary representations: 01101010 00110101 And now I want to copy the last 3 bits from the first integer over the second one so that it becomes 00110010 What's the easiest way to do that? (Actually, my goal is to shift the all the X+1 bits to the right one, essentially deleting the X...

Transforming deeply nested dictionary to 1D dictionary with Python

I have some deeply randomly nested dictionary as follows. {'CompilationStatistics': {'CodeGeneration': {'EndTime': '2010-04-21T14:03:11', 'StartTime': '2010-04-21T14:03:11', 'StepList': {'EliminatingDuplicates': {'EndTime': '2010-04-21T14:03:11...