this is my code:
from whoosh.analysis import RegexAnalyzer
rex = RegexAnalyzer(re.compile(ur"([\u4e00-\u9fa5])|(\w+(\.?\w+)*)"))
a=[(token.text) for token in rex(u"hi 中 000 中文测试中文 there 3.141 big-time under_score")]
self.render_template('index.html',{'a':a})
and it show this on the web page:
[u'hi', u'\u4e2d', u'000', u'...
I am writing a tkinter program that is kind of a program that is like a portfolio and opens up other programs also writen in python. So for example i have FILE_1 and FILE_2 and i want to write a program that onced clicked on a certain button opens either FILE_1 or FILE_2. i dont need help with the look like with buttons just how to wir...
I have a complicated query built up based on a users profile, I start with
qset = Profile.objects
bunch of stuff that works to return me profile objects (it uses Q objects, and optionally ignores some fields if they were left blank)
I could grab the users with selected_related() but that still leaves me with a list of profiles, rath...
I deployed an app to Google App Engine. When I navigate to it, I get this:
Error: Server Error
The server
encountered an error and could not
complete your request.
If the problem persists, please report
your problem and mention this error
message and the query that caused it.
All the pages do this. appcfg.py uploa...
Looking through the Google App Engine source, I noticed that the tab depth is 2 spaces instead of the conventional 4. Is there some wisdom behind this, or is it just someone's preference?
(Maybe it's trivial, or maybe Google knows something that isn't immediately obvious.)
UPDATE I wasn't suggesting that it ran differently based on th...
Basically, I have a lot of audio files representing the same song. However, some of them are worse quality than the original, and some are edited to where they do not match the original song anymore. What I'd like to do is programmatically compare these audio files to the original and see which ones match up with that song, regardless of...
Possible Duplicate:
Flatten (an irregular) list of lists in Python
How would I go about flattening a list in Python that contains both iterables and noniterables, such as [1, [2, 3, 4], 5, [6]]? The result should be [1,2,3,4,5,6], and lists of lists of lists (etc.) are certain never to occur.
I have tried using itertools.chai...
I've recently started using a mac, and I'm curious about how to make a mac app that uses PyQt and is self-contained.
Can anyone give me any pointers on where to start and what I'll need?
...
In python, how do I move an item to a definite index in a list?
Thanks in advance for the reply.
...
In interactive python I'd like to import a module that is in, say,
C:\Modules\Module1\module.py
What I've been able to do is to create an empty
C:\Modules\Module1\__init__.py
and then do:
>>> import sys
>>> sys.path.append(r'C:\Modules\Module1')
>>> import module
And that works, but I'm having to append to sys.path, and if ther...
Is there a good way to do the following?
I wrote a simple console app to upload and download files from an FTP server using the ftplib.
Each time some data chunks are downloaded, I want to update a text progress bar, even if it's just a number.
But I don't want to erase all the text that's been printed to the console. (Doing a "clear"...
Hello,
like this question I want to pass a function with arguments. But I want to pass it to built-in functions.
Example:
files = [ 'hey.txt', 'hello.txt', 'goodbye.jpg', 'howdy.gif' ]
def filterex(path, ex):
pat = r'.+\.(' + ex + ')$'
match = re.search(pat, path)
return match and match.group(1) == ex)
I could use t...
I am attempting to implement automatic differentiation for a Python statistics package (the problem formulation is similar to optimization problem formulations).
The computational graph is generated using operator overloading and factory functions for operations like sum(), exp(), etc. I have implemented automatic differentiation for ...
I'm trying to reply to a mail in Mail.app with py-appscript.
I tried the code below,
from appscript import *
mailapp = app('Mail')
# get mail to be replied
msg = mailapp.accounts.first.mailboxes.first.messages.first
# create reply mail
reply_msg = mailapp.reply(msg)
# set mail (got error)
reply_msg.visible.set(True)
reply_msg.subje...
I can do this in c#, and the code is pretty long.
Would be cool if someone can show me how this would be done via python.
Pseudo code is:
url: www.example.com/somefolder/filename1.pdf
1. load file into an array (file contains a url on each line)
2. if file e.g. filename1.pdf doesn't exist, download file
The script can be in the f...
I'm completely new to python (and it's been a while since I've coded much).
I'm trying to call a method which acts as an event handler in a little "hello world" type game, but it's not working at all. I'm using the pygames 1.9.1 lib with python 2.6.1 on OSX 10.6.3.
So this is in a while loop:
self.exitCheck()
if sel...
currently I have a spider written in Java that logs into a supplier website and spiders the website. (using htmlunit)
It keeps the session (cookie) and even lets me enable/disable javascript etc.
I also use htmlparser (java) to help parse the html and extract the relevant information.
Does python have something similar to do this?
...
So I'm not sure what my problem is. Trying to configure a virtualenv this is the error I get:
20:59:51 $ virtualenv test -p /usr/local/bin/python
Running virtualenv with interpreter /usr/local/bin/python
New python executable in test/bin/python
Please make sure you remove any previous custom paths from your /Users/nlang/.pydistutils.cf...
This gives me a frequency of words in a text:
fullWords = re.findall(r'\w+', allText)
d = defaultdict(int)
for word in fullWords :
d[word] += 1
finalFreq = sorted(d.iteritems(), key = operator.itemgetter(1), reverse=True)
self.response.out.write(finalFreq)
This also gives me useless words like "the" "an" "a"
My qu...
I set my database to require ssl. I've confirmed I can connect to the db via command line by passing the public key [and have confirmed I can't connect if I do not pass public key]
I get the same error in my django app as when I do not pass a key. It seems I've not setup my settings.py correctly to pass the path to the public key.
Wha...