I am trying to match file names in the format filename-isodate.txt
>>> DATE_NAME_PATTERN = re.compile("((.*)(-[0-9]{8})?)\\.txt")
>>> DATE_NAME_PATTERN.match("myfile-20101019.txt").groups()
('myfile-20101019', 'myfile-20101019', None)
However I need to get the filename and -isodate parts in seperate groups.
Any suggestions and/or exp...
Hi folks,
the user needs to provide a list of field/values through a form
class FieldForm(forms.Form):
field_name = forms.CharField()
field_value = forms.CharField()
The problem is how do I get a user to pass multiple of these with one submit?
Also as a side question... any tips on implementing editing too?
Any ideas? ...
I have a txt file of repeating lines like this:
Host: http://de.wikipedia.org
Referer: http://www.wikipedia.org
Host: answers.yahoo.com/
Referer: http://www.yahoo.com
Host: http://de.wikipedia.org
Referer: http://www.wikipedia.org
Host: http://maps.yahoo.com/
Referer: http://www.yahoo.com
Host: http://pt.wikipedia.org
Referer: http://w...
Consider this function getPos() which returns a tuple. What is the difference between the two following assignments? Somewhere I saw an example where the first assignment was used but when I just tried the second one, I was surprised it also worked. So, is there really a difference, or does Python just figure out that the left-hand part ...
I want to calculate the center-of-mass using the map function. I don't want to use for loops. Help with bottom two lines?
class Obj():
def __init__(self, mass = 0., x = 0., y = 0.):
self.mass = mass
self.x = x
self.y = y
# Create List of Objects
objList = []
n = 0
for i in range(0...
In Python, how do I convert a list to *args?
I need to know because the function
scikits.timeseries.lib.reportlib.Report.__init__(*args)
wants several time_series objects passed as *args, whereas I have a list of timeseries objects.
Any help is greatly appreciated :)
...
i want execute a command need sudo in local machine,so as the doc say i use the local command,
but it will ask me input the password,how can i avoid this,is there some place can save my local machine password
local('sudo /etc/init.d/tomcat6 start',capture=True)
...
whenever i build python file to exe file from py2exe, it takes lots of space of minimum 25MB for small project also,it includes all the the python library file. Is there any other way that i can reduce the size.
...
Hi,
I'm working on my CouchDB with Python, cause I love python. The problem is: On my machine (it's a Seagate Dockstar) it's quite slow. How can I increase the speed?
a) I've tried to use psyco. It's not available for that plattform.
b) I've tried to put the imports outside my function-definitons. This doesn't work since the couchpy th...
Hi,
I have a class with an attribute I wish to turn into a property, but this attribute is set within __init__. Not sure how this should be done. Without setting the propert in __init__ this is easy and works well
import datetime
class STransaction(object):
"""A statement transaction"""
def __init__(self):
self._date =...
I need to create a 'container' object or class in Python, which keeps a record of other objects which I also define. One requirement of this container is that if two objects are deemed to be identical, one (either one) is removed. My first thought was to use a set([]) as the containing object, to complete this requirement.
However, the...
I've got a simulation model running in Python using NumPy and SciPy and it produces a 2D NumPy array as the output each iteration. I've been displaying this output as an image using matplotlib and the imshow function. However, I've found out about Glumpy, and on its documentation page it says:
Thanks to the IPython shell, glumpy can be ...
I'm just doing a bunch of Python exercises and there is an exercise where you should. given a directory name, iterate over the its 'special files' (containing the pattern _\w+_) and output their absolute paths.
Here's my code:
def get_special_paths(dir):
filenames = os.listdir(dir)
for filename in filenames:
if re.search(r'__\...
I have a python function that writes an output file to a disk.
I want to write a unit test for it using python unittest module.
How should I assert equality of files? I would like to get an error if the file content differs from the expected one + list of differences. As in the output of unix diff command.
Is there any official/recomm...
I have programmed in Python for a while, and just recently started using Ruby at work. The languages are very similar. However, I just came across a Ruby feature that I don't know how to replicate in Python. It's Ruby's freeze method.
irb(main):001:0> a = [1,2,3]
=> [1, 2, 3]
irb(main):002:0> a[1] = 'chicken'
=> "chicken"
irb(main):003:...
If you google for "pythonic" you will mostly find the same three examples. There are a lot of questions here on stackoverflow that ask for how this and that can be done in a pythonoic way, so a collection of some nice pythonic code examples would be nice!
...
What could be causing this error when I try to insert a foreign character into the database?
>>UnicodeEncodeError: 'latin-1' codec can't encode character u'\u201c' in position 0: ordinal not in range(256)
And how do I resolve it?
Thanks!
...
I have a website where i want to put a custom made captcha, can't use online captcha services due to layout needs. It runs on google appengine.
Does appengine API has a something for writing characters on a given image?
I went through appengine Python Image API but it doesnot seems to be of much help.
Any suggestions how to generate ca...
HI, guys
I am developing a GUI with wxPython. I draw a square which represents a CD object, inside another square (also with wxPanel class), which represents CD Container Object.
I want to have "delete this CD" in the right click menu of CDWindow, which will remove the CDwindow. enter code here`
Basically, my code looks like this (for ...
I have the following string:
schema(field1, field2, field3, field4 ... fieldn)
I need to transform the string to an object with name attribute as schema and the field names as another attribute which is a list.
How do I do this in Python with a regular expression?
...