Using Python I need to delete all charaters in a multiline string up to the first occurrence of a given pattern. In Perl this can be done using regular expressions with something like:
#remove all chars up to first occurrence of cat or dog or rat
$pattern = 'cat|dog|rat'
$pagetext =~ s/(.*?)($pattern)/$2/xms;
What's the best way to ...
EDIT2: model.hasChildren(parentIndex) returns True, but model.rowCount(parentIndex) returns 0. Is QFileSystemModel just fubar in PyQt?
EDIT: With a bit of adaptation this all works exactly as it should if I use QDirModel. This is deprecated, but maybe QFileSystemModel hasn't been fully implemented in PyQt?
I'm learning the Qt Model/V...
I'm trying to use Emacs as a python editor and it works fine when I evaluate(C-c C-c) only single files but when I evaluate a file that imports another file in the same directory, I get an error saying that the file could not be imported.
Does anyone know of a workaround?
Thanks in advance
edit: Btw, i'm using Emacs23 on a Ubuntu mac...
I have a script which reads data from a csv file. I need to store the data into a database which has already been created as
$ python manage.py syncdb
so, that automated data entry is possible in an easier manner, as available in the django shell.
...
Hi
I have a python file that has functions and classes. now I am writting another program (in another file). and I want to start the new file with running the old file (with the function and classes). I have tried using exec(path_2_oldFile.pyw) but it didn't work.
thanks for any help
Ariel
...
So, i have this :
"( ABC,2004 )"
And I would need to extract ABC in a variable and 2004 in another.
So what I have for now is this:
In: re.compile(r'([^)]*,').findall("(
ABC,2004 )")
Out: ['( ABC,']
...
hi, i am having issues with my django templating system, i have a base.html file, which contains the content which will be common on all the web pages of the web site, the base.html file fetches some dynamic content, like the categories and the archives, which are passed to it by a python file, which fetches the categories and the archiv...
I want to write something in a file.
for example,
fo=open('C:\\Python\\readline_test.txt','a')
for i in range(3):
st='abc'+'\n'
fo.write(st)
fo.close
then I open this python file in IDLE, and click "Run Module".
There is no error message but I find the writing is not complete if I didn't quit IDLE.
How can I complete the file writin...
I installed PyScript to try it out but it just wont start. It only gives me the error:
"Error126: Could not open Dll "python26.dll" followed by:
"Python could not be properly initialized. We must quit."
I think this may have something to do with the PYTHONPATH but since I'm a newbie and dont know what it is or exactly what to put in the...
I set up a virtualenv, which is working, but for some reason I need to use sudo for commands as simple as mkdir. Obviously I did something incorrectly. Any idea what it might be?
Thanks
...
Hi
i'm creating a program that has to make a request and then obtain some info. For doing that the website had done some API that i will use.
There is an how-to about these API but every example is made using PHP.
But my app is done using Python so i need to convert the code.
here is the how-to:
The request string is sealed with Ope...
I'm trying to find an efficient way to find the rank of an object in the database related to it's score. My naive solution looks like this:
rank = 0
for q in Model.objects.all().order_by('score'):
if q.name == 'searching_for_this'
return rank
rank += 1
It should be possible to get the database to do the filtering, using order_...
I have created an array thusly:
import numpy as np
data = np.zeros( (512,512,3), dtype=np.uint8)
data[256,256] = [255,0,0]
What I want this to do is display a single red dot in the center of a 512x512 image. (At least to begin with... I think I can figure out the rest from there)
...
I'd like to list the items in a tuple in Python starting with the back and go to front.
Similar to:
foo_t = tuple(int(f) for f in foo)
print foo, foo_t[len(foo_t)-1] ...
I believe this should be possible without Try ...-4, except ...-3.
Thoughts? suggestions?
...
I have a list of starting data. I want to apply a function to the starting data that creates a few pieces of new data for each element in the starting data. Some pieces of the new data are the same and I want to remove them.
The sequential version is essentially:
def create_new_data_for(datum):
"""make a list of new data from some...
Possible Duplicate:
Calling MATLAB functions from python
Hi
I wrote a matlab code (that easily could be implimented as a function) that convert a series of BMPs to avi. I want a python program to call to this program/function. how do I do it?
thanks
...
Hi, I've set django filebrowser's debug to True and wrote the extension restrictions in the model.
pdf = FileBrowseField("PDF", max_length=200, directory="documents/", extensions=['.pdf', '.doc', '.txt'], format='Document', blank=True, null=True)
In django admin it shows correctly with debug info.
Directory documents/
Extensions ['.pdf...
I'm looking for a fast, clean, pythonic way to divide a list into exactly n nearly-equal partitions.
partition([1,2,3,4,5],5)->[[1],[2],[3],[4],[5]]
partition([1,2,3,4,5],2)->[[1,2],[3,4,5]] (or [[1,2,3],[4,5]])
partition([1,2,3,4,5],3)->[[1,2],[3,4],[5]] (there are other ways to slice this one too)
There are several answers in here h...
If I convert a UTC datetime to swedish format, summertime is included (CEST). However, while creating a datetime with sweden as the timezone, it gets CET instead of CEST. Why is this?
>>> # Modified for readability
>>> import pytz
>>> import datetime
>>> sweden = pytz.timezone('Europe/Stockholm')
>>>
>>> datetime.datetime(2010, 4, 20, 1...
I read a question earlier asking if there was a times method in Python, that would allow a function to be called n times in a row.
Everyone suggested for _ in range(n): foo() but I wanted to try and code a different solution using a function decorator.
Here's what I have:
def times(self, n, *args, **kwargs):
for _ in range(n):
...