python

PyFacebook Infinite Session

I am trying to set a cron task to read updates for a Facebook application. I have prompted the user to grant Offline Access permissions and i have store the session_key in the db. I am crearing a new Facebook object and besides api and secret key I also use the session_key (previously stored in db) and the fb uid. When i am trying to cr...

Ignoring modules other than own in testoob coverage reporting

I use testoob in the following way: def suite(): import unittest return unittest.TestLoader().loadTestsFromNames([ 'my_module.my_unittest_class', 'my_module.my_other_unittest_class', ]) if __name__ == '__main__': import testoob testoob.main(defaultTest="suite") And then run the unittest suite wit...

Reformatting code with Regular Expressions

We have an ArrayList of items in several classes which are giving me trouble every time I'd like to insert a new item into the list. It was a mistake on my part to have designed the classes in the way I did but changing the design now would be more headache than it's worth (bureaucratic waterfall model.) I should have anticipated forma...

How to require login for django generic views ?

I want to restrict access to urls serves by django generic views. For my views i know that login_required decorator does the job. Also Create/update/delete generic views takes login_requied argument but I couldn't find a way to do this for other generic views. ...

Python eval error suppression

First off, I'm aware of eval's disadvantages and it will be used in an experiment I want to make only. I'm creating a script that works just like a Brute-Force algorithm but it won't break passwords but find the solution to a special form of an equation (more details are unnecessary). There will be lots of strings filled with (often sy...

How can you search Github project Network for unmerged commits to a particular file?

I'm working on a project that is hosted @ Github.com It seems that forum/models.py has some errors in it that are preventing me from syncdb. I was curious if there was a way to search through the network to find all the changes that had been made in the entire Branch Network to forum/models.py to see if someone had fixed the errors alre...

PyQt 4.7 - ImportError after installing on Windows.

I've been trying to install PyQt 4.7 on Vista, but I am getting an ImportError when I try to do: from PyQt4 import QtCore, QtGui. ImportError: DLL load failed: The specified module could not be found. I've checked my System Path, and C:\Python31\Lib\site-packages\PyQt4\bin is on there. I can't run any of the examples, but the Des...

using the symbol font for Greek symbols in TeX via matplotlib

To annotate my figures with Greek letters in the matplotlib package of Python, I use the following: import matplotlib matplotlib.use('PDF') import matplotlib.pyplot as plt from matplotlib import rc rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) plt.rcParams['ps.useafm'] = True rc('font',**{'family':'sans-serif','sans-se...

Python (2.6) , List Comprehension: why is this a syntax error ?

Why is print(x) here not valid (SyntaxError) in the following list-comprehension? my_list=[1,2,3] [print(my_item) for my_item in my_list] To contrast - the following doesn't give a syntax error: def my_func(x): print(x) [my_func(my_item) for my_item in my_list] ...

pygame saving audio files

hi How can I convert a .wav file to some other format such as .mp3 in pygame? Update: Why not Gstreamer or Pygame: I want to use native Windows environment to install a package that can do this (i.e. don't want to install cygwin). I am searching for a package which has a binary installer available for windows (with Python 2.6) or at...

Adressing part of a string via the array syntax in Python

Is it, in Python, possible to adress a specific character in a string by the standard array syntax? Example, PHP: $foo = 'bar'; echo $foo[1]; // Output: a It didn't work like in PHP so I wanted to know if it is possible using some other way ...

Convert datetime fields in Chrome history file (sqlite) to readable format

Working on a script to collect users browser history with time stamps ( educational setting). Firefox 3 history is kept in a sqlite file, and stamps are in UNIX epoch time... getting them and converting to readable format via a SQL command in python is pretty straightforward: sql_select = """ SELECT datetime(moz_historyvisits.visit_date...

python gstreamer for windows

I want to use Python bindings for GStreamer on windows. But looking at the INSTALL file, the gstreamer does it in the unix way. (make make install) . I don't want to install cygwin or other windowsunix environments. Is there a GPL binary distribution of GStreamer available somewhere? (or a script that can just install it using python s...

Stored Procedures in Python for PostgreSQL

Hello, we are still pretty new to Postgres and came from Microsoft Sql Server. We are wanting to write some stored procedures now. Well, after struggling to get something more complicated than a hello world to work in pl/pgsql, we decided it's better if we are going to learn a new language we might as well learn Python because we got th...

Pymedia installation on Windows with Python 2.6

hi, I am trying to install latest version of Pymedia from sources. I have Python2.6 and there is no binary available. Started with: python setup.py build and got the following messages: Using WINDOWS configuration... Path for OGG not found. Path for VORBIS not found. Path for FAAD not found. Path for MP3LAME not found. Path ...

Python: Prevent argument array being globally modified

I have a problem with python here. If I pass an array through a recursive function that adds something to the array each time it is called, the array is modified in each instance Code: def test(n,myList): if n>0: myList.append("Test") print ( "BEFORE CALL Instance ", n, myList ) test(n-1,myList) pri...

Fastest Way to Update a bunch of records in queryset in Django

I have a queryset with a few million records. I need to update a Boolean Value, fundamentally toggle it, so that in the database table the values are reset. What's the fastest way to do that? I tried traversing the queryset and updating and saving each record, that obviously takes ages? We need to do this very fast, any suggestions? ...

Retrieving text from password field [python][pyqt4]

def welcomeStage (self): self.test = QtGui.QLineEdit (self) self.test.move (50, 150) QtCore.QObject.connect (self.test, QtCore.SIGNAL ('returnPressed()'), self.passwordStage) def passwordStage (self): self.email = self.test.text() self.test.clear() self.test.setEchoMode (QtGui.QLineEdit.Password) QtC...

Using Python to program MS Office macros?

I've recently taken it as a project to teach myself how to program in Python. Overall, I must say that I'm impressed with it. In the past I've typically stuck to programming in VBA mostly for MS Excel (but also a bit in MS Access and Word) and have struggled to find ways to make it do things that Python can easily do with a single comm...

Ranking within Django ORM or SQL?

Hi, so... I have a huge list ranked by various values (eg. scores) So I grab the list ordered by these values: players = Player.objects.order_by('-score', '-karma') I would like to: Grab a player and get the neighbouring players P1 score:123 P2 score:122 YOU! score:110 P3 score:90 P2 score:89 Grab the...