python

Find the newest folder in a directory in Python

Hello, I am trying to have an automated script that enters into the most recently created folder. I have some code below import datetime, os, shutil today = datetime.datetime.now().isoformat() file_time = datetime.datetime.fromtimestamp(os.path.getmtime('/folders*')) if file_time < today: changedirectory('/folders*') I am...

Forcing tuples within tuples?

I've got a python function that should loop through a tuple of coordinates and print their contents: def do(coordList): for element in coordList: print element y=((5,5),(4,4)) x=((5,5)) When y is run through the function, it outputs (5,5) and (4,4), the desired result. However, running x through the function outputs 5 and ...

Word Wrap in PyGTK TreeView

How can I word wrap text inside a PyGTK TreeView? ...

How does one do async ajax calls using cherrypy?

I'm using cherrypy's standalone server (cherrypy.quickstart()) and sqlite3 for a database. I was wondering how one would do ajax/jquery asynchronous calls to the database while using cherrypy? ...

How does this formatting code work?

I always have to know why, rather than just how, so here I go: How does this work: '{0:01.2f}'.format(5.555) #returns '5.55' '{0:01.1f}'.format(5.555) #returns '5.5' '{0:1.2f}'.format(5.555) #returns '5.55' again '{0:1.1f}'.format(5.555) #returns '5.5' again Why does this not add zero padding by returning '05.5' instead of j...

How to create class instance inside that class method?

I want to create class instance inside itself. I tried to it by this way: class matrix: (...) def det(self): (...) m = self(sz-1, sz-1) (...) (...) but I got error: m = self(sz-1, sz-1) AttributeError: matrix instance has no __call__ method So, I tried to do it by this way: class matrix: ...

What's the difference between quantize() and str.format()?

I don't mean what's the technical difference, but rather, what's the faster/more logical or Pythonic, etc. way to do this: def __quantized_price(self): TWOPLACES = Decimal(10) ** -2 return self.price.quantize(TWOPLACES) or def __formatted_price(self): TWOPLACES = Decimal(10) ** -2 return '{0:.2...

Using a list objects to look up items in a dictionary in Python

I have a a wxPython checklist box that returns a list of integers. I want to use the integers to look up items in a dictionary. I am not really sure the best way to do this. Any suggestions? ...

Custom Django template tag to look up a string username and return it as a user object.

I use some third-party template tags in my Django Application (maintained elsewhere) that return a username as a string I can access in my templates like this. {% for user in gr.user.foll.list %} {{user}} Trouble is because {{user}} is returned as a string - I need to convert into a Django User Object, if it exists in the Django DB,...

wxpython systray icon menu

I'm designing an application that I want to run in the background. There isn't any user interaction necessary, so I want the app to run invisibly save for a systray icon. I want that icon to have a menu that just opens the config/help files in notepad. Could someone point me in the right direction or provide an example? ...

Search a file for strings from a second file

I have two files. The first file contains a list of 6 character keys (SA0001, SA1001, etc.). The second file contains a list of dates and amounts where the first six positions will match the key in the first file. I want to verify that every key in the first file has at least one match in the second file. There may be more than one match...

Trick code completion with PyDev like with PDT?

Is there a way to help PyDev code completion by telling it the type of a variable? With PDT, you can use PHPDoc-like syntax for such purpose: /* @var $my_var MyClass */ $my_var = myFunction(); // PDT is able to figure out that $my_var is a MyClass object. But till now, I cannot figure out how to do the same in python. ...

Python/Django: If 5 and 5.00 are different values (when expressed in Decimal), then...

If 5 and 5.00 and 5.000 are all different, then why does Django's decimal field save without the .00 even when I have decimal_places=2 ? More importantly, how can I save a value 5.00 as 5.00 in Django without using String. ...

Tips for Teaching Python to a Business Audience

In an effort to continue to hone my teaching abilities, I am taking an opportunity to give a couple presentations at work to a mixed technical and non-technical audience on business automation. I've chosen Python as my language of choice, mostly for its friendly syntax, the rich standard library and wealth of 3rd party libraries, and my ...

Creating several profile classes in django

I'm getting started with django and I'd like to extend the basic django.contrib.auth.models.User class to create my own site profile(s). Here is described how to do it, got that. As far as I've understood it, you can only specify a single class as AUTH_PROFILE_MODULE in your settings.py. Now, if I create an extension class of my profil...

python imaplib ssl error using celeryd queue

I'm having a problem using imaplib on python 2.6 with the latest django svn. I want to download imap emails in a queue (using celeryd). I'm able to connect/download emails from the command line, but when i offload the task through django to celeryd i get this error: "SSLError: [Errno 1] _ssl.c:1325: error:1408F10B:SSL routines:SSL3_GET_R...

What programs are used to build standalone desktop widgets that interact with online php and mysql?

I have seen mention of Java and Python. I need something that can be installed on a users desktop without them having to also install Java or anything else. User simplicity is a must. This widget will log into an online php based calendar that accesses mySQL. Any pointers on what I should be reading up on? Python? Thanks! Joel Up...

Problem while building a PyQt script with py2exe (QtCore)

Hi, I'm trying to make a simple hello-world executable python gui app in windows using pyqt. So I've made the pyqt.py file import sys from PyQt4.QtGui import * app = QApplication(sys.argv) button = QPushButton("Hello World", None) button.show() app.exec_() I tried to use py2exe with the following setup.py script: from py2exe.build_ex...

Have writen a program to extract text from a PDF in python, and now need to make it run for every PDF in the folder and save as a text file.

So far here is the code I have (it is working and extracting text as it should.) import pyPdf def getPDFContent(path): content = "" # Load PDF into pyPDF pdf = pyPdf.PdfFileReader(file(path, "rb")) # Iterate pages for i in range(0, pdf.getNumPages()): # Extract text from page and add to content conte...

Selecting indices for a 2d array in numpy

Hi Folks, This works quite well in 1 dimension: # This will sort bar by the order of the values in foo (Pdb) bar = np.array([1,2,3]) (Pdb) foo = np.array([5,4,6]) (Pdb) bar[np.argsort(foo)] array([2, 1, 3]) But how do I do that in two dimensions? Argsort works nicely, but the select no longer works: (Pdb) foo = np.array([[5,4,6], [...