python

What task can I automate in Python that's fun, simple, and useful?

I'm trying to learn Python. I'm going to eventually be using it at work, but I don't have an active project in it as of now. I've been reading through some documentation and would like to learn some basics, but I learn best when actually coding. So I'm thinking of attempting a small Python project just to sort of "get my feet wet" in Pyt...

Processing a log to fix a malformed IP address ?.?.?.x

I would like to replace the first character 'x' with the number '7' on every line of a log file using a shell script. Example of the log file: 216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/.... 74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/.... 222.168.17.x [01/Mar/2010:00:27:10 +0100] "GET /etc/.... My humble beginnings.....

Convert list in tuple to numpy array?

I have tuple of lists. One of these lists is a list of scores. I want to convert the list of scores to a numpy array to take advantage of the pre-built stats that scipy provides. In this case the tuple is called 'data' In [12]: type data[2] -------> type(data[2]) Out[12]: <type 'list'> In [13]: type data[2][1] -------> type(data[2][1]...

Why is my spawned process still causing IntelliJ to wait?

I'm trying to start a server as part of an Ant artifact. Here are the relevant lines: <exec dir="." executable="cmd.exe" spawn="true"> <arg line="/c c:\Java\james-2.3.2\bin\debug.bat" /> </exec> If I start it with ant from the command line, a process is spawned and I get a command prompt and everything seems fine. Ho...

Python - Initializing Multiple Lists/Line

This is terribly ugly: psData = [] nsData = [] msData = [] ckData = [] mAData = [] RData = [] pData = [] Is there a way to declare these variables on a single line? ...

django: caching passwords for custom authentication

I am authenticating users in ldap, but this happens only once, when user is logging in. Afterwards I need to keep username and password, because before every ldap operation I need to make bind on ldap server before every operation. What is the safe way to cache this password (I can't store in the database or cookies) for as long as sessi...

wanting to move up from ms access, thinking .net? visual studio?

So I wrote a project-management program for a small business using Microsoft Access 2007. Now they've requested lots of additional features (timekeeping, privileged data tiers ...) I personally use Linux, but the whole office uses Windows. I'm relatively new to programming but like to teach myself using projects like this. I'm right...

Python instances and attributes: is this a bug or i got it totally wrong?

Suppose you have something like this: class intlist: def __init__(self,l = []): self.l = l def add(self,a): self.l.append(a) def appender(a): obj = intlist() obj.add(a) print obj.l if __name__ == "__main__": for i in range(5): appender(i) ...

How do I create a set of image files from a PowerPoint file file?

I'm creating a "slideshow room" web page. The user will upload a PowerPoint file that my server will use to generate a set of .jpg image files representing the slides to present in a custom "gallery viewer". I'm an experienced Python developer but I cannot find anything useful. How can I do that? ...

doctest locally defined functions

Hi, is there any way to doctest locally defined functions? As an example I would want def foo(): """ >>> foo() testfoo""" def foo2(): """ >>> 1/0 """ print 'testfoo' foo2() to NOT pass the test. But still I would not want to make foo2 global for the entire module... ...

Node.js as a custom (streaming) upload handler for Django

I want to build an upload-centric app using Django. One way to do this is with nginx's upload module (nonblocking) but it has its problems. Node.js is supposed to be a good candidate for this type of application. But how can I make node.js act as an upload_handler() for Django? I'm not sure where to look for examples? ...

Python: Get values (objects) from a dictionary of objects in which one of the object's field matches a value (or condition)

Hello everybody! I have a python dictionary whose keys are strings and the values are objects. For instance, and object with one string and one int class DictItem: def __init__(self, field1, field2): self.field1 = str(field1) self.field2 = int(field2) and the dictionary: myDict = dict() myDict["sampleKey1"] = DictIte...

fastest calculation of largest prime factor of 512 bit number in python

dear all, i am simulating my crypto scheme in python, i am a new user to it. p = 512 bit number and i need to calculate largest prime factor for it, i am looking for two things: Fastest code to process this large prime factorization Code that can take 512 bit of number as input and can handle it. I have seen different implementatio...

What's a good pure-python, document-based and flat-file database engine?

Hi, for development i'd love to have a flat file database with the requirements up in the title, but I don't seem to be able to find a database with these requirements. I can't seem to get MetaKit to work. I only need it to work on the development machine, but in the real world my product will have more data and needs more room and will ...

How do I watch a folder for changes and when changes are done using Python?

i need to watch a folder for incoming files. i did that with the following help: http://stackoverflow.com/questions/182197/how-do-i-watch-a-file-for-changes-using-python the problem is that the files that are being moved are pretty big (10gb) and i want to be notified when all files are done moving. i tried comparing the size of the fold...

Applying style sheets in pyqt

Hello all, If i apply a property to a parent widget it is automatically applied for child widgets too.. Is there any way of preventing this?? For example if i set background color as white in a dialog the button,combo boxes and scroll bars looks white as it lacks it native look(have to say it's unpleasant & ugly).. Is there any way that...

Does filehandle get closed automatically in Python after it goes out of scope?

If I do the following, does filehandle get closed automatically as it goes out of scope in Python: def read_contents(file_path): return file(file_path).read() If it doesn't, how can I write this function to close the scope automatically? ...

Vectorization of index operation for a scipy.sparse matrix

The following code runs too slowly even though everything seems to be vectorized. from numpy import * from scipy.sparse import * n = 100000; i = xrange(n); j = xrange(n); data = ones(n); A=csr_matrix((data,(i,j))); x = A[i,j] The problem seems to be that the indexing operation is implemented as a python function, and invoking A[i,...

Macport Python with PyObj and XCode

How can I get the Macport Python version to work with XCode? Which Python.framework do I have to choose? ...

How can I turn off registry redirection on Python?

My program is trying to create an key on the HKLM\Software\Microsoft\Shared Tools\MSCONFIG\startupreg\test\ but instead the key is created on the HKLM\Wow6432node\Software\Microsoft\Shared Tools\MSCONFIG\startupreg\test\ and don't work properly... Why? How can I solve it? ...