python

Windows impersonation for WMI calls via python?

I'm using PyWin32 to make WMI calls to the system in python from my django web application. My goal is to allow users to add printers to the system via a web interface. To do this, I'm using win32print.AddPrinterConnection. This works well running the development server under my user account. I can add all the printers I want. However, ...

How can I print only every third index in Perl or Python?

How can I do a for() or foreach() loop in Python and Perl, respectively, that only prints every third index? I need to move every third index to a new array. ...

How to clone a key in Amazon S3 using Python (and boto)?

I have a file contained in a key in my S3 bucket. I want to create a new key, which will contain the same file. Is it possible to do without downloading that file? I'm looking for a solution in Python (and preferably boto library). ...

Install python 2.6 in CentOS

I have a shell that runs CentOS For a project I'm doing I need python 2.5+ but centOS is pretty dependent on 2.4 From what I've read a number of things will break if you upgrade to 2.5 I wan't to install 2.5 separately from 2.4 but I'm not sure how to do it. So far I've downloaded the source tarball, untarred it and did a ./configure --p...

How do you determine a processing time in Python?

I'm new to Python, and confused by the date/time documentation. I want to compute the time that it takes to perform a computation. In java, I would write: long timeBefore = System.currentTimeMillis(); doStuff(); long timeAfter = System.currentTimeMillis(); elapsed time = timeAfter - timeBefore; I'm sure it's even easier in Python. C...

vim syntax highlighting for jinja2?

How do you do jinja2 aware syntax highlighting for vim? ...

Trouble with positive look behind assertion in python regex.

Hi, Trying to use a reasonably long regex and it comes down to this small section that doesn't match how I'd expect it to. >>> re.search(r'(foo)((?<==)bar)?', 'foo').groups() ('foo', None) >>> re.search(r'(foo)((?<==)bar)?', 'foo=bar').groups() ('foo', None) The first one is what I'm after, the second should be returning ('foo', 'b...

jinja2: get lengths of list

How do I get the number of elements in a list in jinja2 template. For example, in python: print template.render(products=[???]) and in jinja2 <span>You have {{what goes here?}} products</span> ...

What is involved in adding to the standard Python API?

What steps would be necessary, and what kind of maintenance would be expected if I wanted to contribute a module to the Python standard API? For example I have a module that encapsulates automated update functionality similar to Java's JNLP. ...

mod_python interpreter's cache not getting reset on script change?

I use mod_python.publisher to run Python code and discovered a problem: When I update a script the update doesn't always work right away and I get the same error I fixed with the update until I restart Apache. Sometimes it works right away, but sometimes not...but restarting Apache definitely always catches it up. It's a pain to have to...

How can I implement decrease-key functionality in Python's heapq?

I know it is possible to realize decrease-key functionality in O(log n) but I don't know how? ...

Limiting results returned fromquery in django, python

I've just started to learn how to do queries in my Django application, and I have a query that gets me the list of new users filtered by the date joined: newUsers = User.objects.filter(is_active=True).order_by("-date_joined") This as I understand it gives me ALL the users, sorted by date joined. How would I best limit it to get me the...

appengine and no-ip.org

Hi folks! :) I'd like to run an appengine app on a subdomain like something.no-ip.org instead of something.appspot.com is this doable? If so, can you please help me understand? :) Thank you so much for your help! ...

Install mysqldb on snow leopard

I am trying to get started on working with Python on Django I am by profession a PHP developer and have been told to set up django and python on my current apache and mysql setup however I am having trouble getting the Mysqldb module for python to work, I must of followed about 6 different set of instructions, I am running snow leopard a...

python open built-in function: difference between modes a, a+, w, w+

In the python built-in open function, what is the exact difference between the modes w, a, w+, a+? ...

multiline checkbox in wxpython

Dear all, I'm working with wxpython (2.8) with python 2.5. is it possible to force a wx.CheckBox to display its label on multiple lines? I'd like to be able to do the same as wx.StaticText.Wrap(width) See the attached example: the wx.CheckBox is 200 px wide, but it's label does not fit in this space. Any help is really appreciated! Th...

how to rewrite this loop in a more efficient way in python

I have a loop of the following type: a = range(10) b = [something] for i in range(len(a)-1): b.append(someFunction(b[-1], a[i], a[i+1])) However the for-loop is killing a lot of performance. I have try to write a windows generator to give me 2 elements everything time but it still require explicit for-loop in the end. Is there a w...

Python gzip folder structure when zipping single file.

I'm using Python's gzip module to gzip content for a single file, using code similar to the example in the docs: import gzip content = "Lots of content here" f = gzip.open('/home/joe/file.txt.gz', 'wb') f.write(content) f.close() If I open the gz file in 7-zip, I see a folder hierarchy matching the path I wrote the gz to and my conten...

Problem when getting the content of a listbox with python and ctypes on win32

I would like to get the content of a list box thanks to python and ctypes. item_count = ctypes.windll.user32.SendMessageA(hwnd, win32con.LB_GETCOUNT, 0, 0) items = [] for i in xrange(item_count): text_len = ctypes.windll.user32.SendMessageA(hwnd, win32con.LB_GETTEXTLEN, i, 0) buffer = ctypes.create_string_buffer("", text_len+1)...

Create a wrapper class to call a pre and post function around existing functions?

I want to create a class that wraps another class so that when a function is run through the wrapper class a pre and post function is run as well. I want the wrapper class to work with any class without modification. For example if i have this class. class Simple(object): def one(self): print "one" def two(self,two): ...