python

Programming language for simple dynamic web site development?

I only know the basics of HTML/CSS. The only experience with web development I have is whatever I learned in Web Development 101 at my university, aka "OMG - CSS u guise, 101". I'm mainly interested in building simple dynamic sites. That's the whole reason I got into this in the first place. I'm at the point now where I realize that it...

Converting specific time format with strptime

I'm trying to convert [16/Jan/2010:18:11:06 +0100] (common log format) to a timestamp. How can I use strptime to convert this? time zone can be different from +0100 ...

Python: Simple file formating problem

I'm using the code below to to write to a file but at the moment it writes everything onto a new line. import csv antigens = csv.reader(open('PAD_n1372.csv'), delimiter=',') lista = [] pad_file = open('pad.txt','w') for i in antigens: lista.append(i[16]) lista.append(i[21]) lista.append(i[0]) for k in lista: pad_file...

What's the difference of ContentType and MimeType

As far as i know, they are absolute equal. However, browsing some django docs, i've found this piece of code: HttpResponse.__init__(content='', mimetype=None, status=200, content_type='text/html') wich surprise me the two getting along each other. The official docs was able to solve the issue in a pratical manner: content_type is a...

Running CGI outside of cgi-bin. Good idea?

I'm considering moving from PHP to Python (for personal projects), and I really don't like seeing /cgi-bin/ in my URL. I got the Python to execute outside of cgi-bin, but I just wanted to make sure there were no possible security issues that could pop up, and that there were no major impacts on the speed. So are there any major issues ...

wxPython: How do I find out which widget has the focus?

How do I find out which widget in my wx.Frame has the focus? ...

Boost Python (Suse and Ubuntu)

Hi, I created a simple .so library containing definition of a C++ class which should be accessed from Python and used for this purpose boost python library. When I'm testing this library using x64 Ubuntu it is enough to set LD_LIBRARY_PATH with the path to boost libs before running python. It doesn't work, however, when I'm using x64 Sus...

Custom class instance copying

Hi, I'm new to programming and Python. The problem I have is with removing list elements that are instances of custom class. import copy class some_class: pass x = some_class() x.attr1 = 5 y = some_class() y.attr1 = 5 z = [x,y] zcopy = copy.deepcopy(z) z.remove(zcopy[0]) This returns: ValueError: list.remove(x): x not in list ...

How does Python stack up to other scripting languages?

I'm learning Python (and it's my first programming language so don't be too intense with your reasons) and I wanted to know how it stacks up to other scripting languages, like Perl and Ruby. What is Python better in comparison to other scripting languages, and what is it worse for? ...

Rename config.ini section using ConfigParser in python

Is there an easy way to rename a section in a config file using ConfigParser in python? I'd prefer not to have to delete the section and recreate it, but that is my only answer right now. ...

Remove duplicate rows from a large file in Python

I've a csv file that I want to remove duplicate rows from, but it's too large to fit into memory. I found a way to get it done, but my guess is that it's not the best way. Each row contains 15 fields and several hundred characters, and all fields are needed to determine uniqueness. Instead of comparing the entire row to find a duplicat...

How to run all test-cases from several modules?

I have several modules full of test-cases and would like to create one module that runs them all. I tried loading the tests in each of the modules using TestLoader.loadTestFromModule, but it always returns empty test-suites. What is the easiest way to achieve this? ...

Apply raw string to function return value

I'm not sure if I've phrased it correctly, but hopefully the example will clear it up: re.search(fileMask.replace('*','.*?'),fileName): For the first parameter in the re.search() call, how can I ensure that I will pass the value returned by the fileMask.replace() call as a raw string? Something to the effect of: re.search(r'fileMask...

How to customize wx.ProgressDialog?

Is it possible to customize ProgressDialog in wxPython? For instance, I would like to make the progressbar slimmer, and the window size wider. SetSize() method doesn't appear to have any effect! ...

How to programmatically add bindings to the current class scope in Python?

Though the question is very specific, I'd also really appreciate general advice and other approaches that would make my question moot. I'm building a collection of AI programs, and many of the functions and classes need to deal with a lot of different states and actions that cause transitions between states, so I need a way to represent ...

What is :: (double colon) in Python?

I know I can use something like string[3:4] to get a substring in Python, but what is the is something[::3]? Sorry but it's hard to search for this on Google. ...

Convert Python datetime to rfc 2822

I want to convert a Python datetime to a an RFC 2822 datetime. I've tried these methods to no avail: >>> from email.Utils import formatdate >>> import datetime >>> formatdate(datetime.datetime.now()) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/System/Library/Frameworks/Python.framework/Versions/2.6...

Overriding __cmp__, __eq__, and __hash__ for SQLAlchemy Declarative Base

I want to override __cmp__, __eq__, and __hash__ so I can do set operations on a SQLAlchemy Declarative Base model. Will this cause any conflicts with the Declarative Base Implementation? ...

Matplotlib: display plot on a remote machine

Hi, I have a python code doing some calculation on a remote machine, named A. I connect on A via ssh from a machine named B. Is there a way to display the figure on machine B? ...

How to dynamically create directories and output files into them python

I have a python script that is trying to create a directory tree dynamically depending on the user input. This is what my code looks like so far. if make_directories: os.makedirs(outer_dir) os.chdir(outer_dir) for car in cars: os.makedirs(car) os.chdir(car) #create a bunch of text files and do other stuff,...