python

How to use .pem file with Python M2Crypto

To generate an RSA key pair I used openssl: openssl genrsa -out my_key.private.pem 1024 openssl rsa -in my_key.private.pem -pubout -out my_key.public.pem Now I want to use this my_key.public.pem file in a function of another .py file: import M2Crypto from M2Crypto import RSA,SSL def encrypt(): pk = open( 'my_key.public.pem', 'rb...

Convert string to Python class object?

Given a string as user input to a python function, I'd like to get a class object out of it if there's a class with that name in the currently defined namespace. Essentially, I want the implementation for a function which will produce this kind of result: class Foo: pass str_to_class("Foo") ==> <class __main__.Foo at 0x69ba0> Is ...

Python equivalent of PropertyUtilsBean

Hi everyone! I was wondering, is there a Python equivalent to Apache commons' PropertyUtilsBean? Edit: For example, I'd like to be able to make this assignment x.y[2].z = v given "y[2].z" as a string. Please note, I'm asking just because I'd like to not reinvent the wheel :) ...

How to generate pdf with epydoc?

I am considering epydoc for the documentation of one module. It looks ok to me and is working fine when I am generating html document. I would like to try to generate the documenation in the pdf format. I've just modified the 'output' setting in my config file. Unfortunately, epydoc fails when generating the pdf file. The error is "Er...

How to filter files (with known type) from os.walk?

I have list from os.walk. But I want to exclude some directories and files. I know how to do it with directories: for root, dirs, files in os.walk('C:/My_files/test'): if "Update" in dirs: dirs.remove("Update") But how can I do it with files, which type I know. because this doesn't work: if "*.dat" in files: files.rem...

IO completion port key confusion

I'm writing an IO completion port based server (source code here) using the Windows DLL API in Python using the ctypes module. But this is a pretty direct usage of the API and this question is directed at those who have a knowledge of IOCP, not Python. As I understand the documentation for CreateIoCompletionPort, you specify your "user...

Using ADODBAPI-Python

Hi, Can you list some resources that explain using ADODBAPI in python.? ...

Return files only from specific folder

Hello. I wrote a function in Python, that must return file from specific folder and all subfolders. File name taken from function parameter: def ReturnFile(fileName) return open("C:\\folder\\" + fileName,"r") But as fileName you can pass for example: "..\\Windows\\passwords.txt" or some unicode symbols for dots. How to fix it? So...

How do I add items to a gtk.ComboBox created through glade at runtime?

I'm using Glade 3 to create a GtkBuilder file for a PyGTK app I'm working on. It's for managing bandwidth, so I have a gtk.ComboBox for selecting the network interface to track. How do I add strings to the ComboBox at runtime? This is what I have so far: self.tracked_interface = builder.get_object("tracked_interface") self.iface_list...

Python file read problem

file_read = open("/var/www/rajaneesh/file/_config.php", "r") contents = file_read.read() print contents file_read.close() The output is empty, but in that file all contents are there. Please help me how to do read and replace a string in __conifg.php. ...

What can be done in R that can't be done with Python/Numpy/SciPy

I've been recently wondering about the over-proliferation of DSLs like R - and thinking whether this is good or bad. Specifically, I wonder what right has R as a stand-alone language and environment? Wouldn't it be much better to build it as an internal DSL/library on some popular language (like Python)? What can R do that Python with s...

How to do scheduled sending of email with django-mailer

Hi, I'm making a django app that needs to be able to make emails and then send these out at a given time. I was thinking i could use django-mailer to put things in que and then send it of. But even though theire sample case list, lists that this is a feature, I cant seem to find out how. What I need is to be able to set a 'when_to_send...

Python- about file-handle limits on OS

HI i wrote a program by python , and when i open too many tempfile, i will got an exception: Too many open files ... Then i figure out that windows OS or C runtime has the file-handle limits, so, i alter my program using StringIO(), but still don`t know whether StringIO also is limited?? ...

Decoding double encoded utf8 in Python

Hi, I've got a problem with strings that I get from one of my clients over xmlrpc. He sends me utf8 strings that are encoded twice :( so when I get them in python I have an unicode object that has to be decoded one more time, but obviously python doesn't allow that. I've noticed my client however I need to do quick workaround for now be...

Why is there module search path instead of typing the directory name + typing the file name?

Is there an advantage? What is it? ...

change current process environment

Is it possible to change current process environment variable? More specifically in a python script I want to change LD_LIBRARY_PATH so that on import of a module 'x' which depends on some xyz.so, xyz.so is taken from my given path in LD_LIBRARY_PATH is there any other way to dynamically change path from where library is loaded? Edi...

In Python 2.4, how can I strip out characters after ';'?

Hi, Let's say I'm parsing a file, which uses ; as the comment character. I don't want to parse comments. So if I a line looks like this: example.com. 600 IN MX 8 s1b9.example.net ; hello! Is there an easier/more-elegant way to strip chars out other than this: rtr = '' for line in file: trig = False ...

How can I create bound methods with type()?

I am dynamically generating a function and assigning it to a class. This is a simple/minimal example of what I am trying to achieve: def echo(obj): print obj.hello class Foo(object): hello = "Hello World" spam = type("Spam", (Foo, ), {"echo":echo}) spam.echo() Results in this error Traceback (most recent call last): File "<...

How to store arbitrary number of fields in django model?

I'm new to python/django. I need to store an arbitrary number of fields in a django model. I'm wondering if django has something that takes care of this. Typically, I would store some XML in a column to do this. Does django offer some classes that makes this easy to do whether it be XML or some other(better) method? Thanks, Pete ...

Whats the best way to duplicate data in a django template?

<html> <head> <title>{% block title %}{% endblock %}</title> </head> <body> <h1>{% block title %}{% endblock %}</h1> </body> </html> This is my template, more or less. The h1 heading is always the same as the title tag. The above snippet of code is not valid because there can't be two blocks with the sa...