python

Any ideas on optimizing this script? (Python)

I'm working on a little script to help me learn the Japanese Kana (Hiragana/Katakana). In total, there are probably 100+ (+||-). Basically, all it would do is take in the english version and convert it to the character. ie. a = 'あ' which is 12354 in decimal What I have so far is this: hiraDict = { "a" : 12354, "i" : 12356 ...} if ...

Learn Go Or Improve My Python/Ruby Knowledge

I was reading about Go, and I can see that it's very good and can be a language used by many developers in some months, but I want to decide a simple thing: Learn Go or improve my Python or Ruby knowledge? Years developing with Python: 1 Years developing with Ruby: 0.3 ...

How to Speed Up Python's urllib2 when doing multiple requests

I am making several http requests to a particular host using python's urllib2 library. Each time a request is made a new tcp and http connection is created which takes a noticeable amount of time. Is there any way to keep the tcp/http connection alive using urllib2? ...

Python multiprocessing: Permission denied

Hi guys, I'm getting an error when trying to execute python program that uses multiprocessing package: File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line 178, in RLock return RLock() File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line 142, in __init__ SemLock.__init__(self, RECURSIVE_MUTEX, 1,...

Interpolate Question

import re from decimal import * import numpy from scipy.signal import cspline1d, cspline1d_eval import scipy.interpolate import scipy import math import numpy from scipy import interpolate Y1 =[0.48960000000000004, 0.52736099999999997, 0.56413900000000006, 0.60200199999999993, 0.64071400000000001, 0.67668...

Read/Write Python Closures

Closures are an incredibly useful language feature. They let us do clever things that would otherwise take a lot of code, and often enable us to write code that is more elegant and more clear. In Python, closures are read-only affairs; that is, a function defined inside another lexical scope cannot change variables outside of its local...

Delayed execution in python for big data

I'm trying to think about how a Python API might look for large datastores like Cassandra. R, Matlab, and NumPy tend to use the "everything is a matrix" formulation and execute each operation separately. This model has proven itself effective for data that can fit in memory. However, one of the benefits of SAS for big data is that it ...

Ruby equivalent to Python's help()?

When working in interactive python, I tend to rely on the builtin help() function to tell me what something expects and/or returns, and print out any documentation that might help me. Is there a ruby equivalent to this function? EDIT I'm looking for something I could use in irb. For example in interactive python I could type >>> help(1...

Accessing py2exe program over network in Windows 98 throws ImportErrors

I'm running a py2exe-compiled python program from one server machine on a number of client machines (mapped to a network drive on every machine, say W:). For Windows XP and later machines, have so far had zero problems with Python picking up W:\python23.dll (yes, I'm using Python 2.3.5 for W98 compatibility and all that). It will then ...

Please help me find the official name of this programming approach.

I [surely re] invented this [wheel] when I wanted to compute the union and the intersection and diff of two sets (stored as lists) at the same time. Initial code (not the tightest): dct = {} for a in lst1: dct[a] = 1 for b in lst2: if b in dct: dct[b] -= 1 else: dct[b] = -1 union = [k for k in dct] inter = [k for k in dct...

Speeding up the python "import" loader

Hi Folks, I'm getting seriously frustrated at how slow python startup is. Just importing more or less basic modules takes a second, since python runs down the sys.path looking for matching files (and generating 4 stat() calls - ["foo", "foo.py", "foo.pyc", "foo.so"] - for each check). For a complicated project environment, with tons o...

Cannot decode/encode in UTF-8.

I have a text-box which allows users to enter a word. The user enters: über In the backend, I get the word like this: def form_process(request): word = request.GET.get('the_word') word = word.encode('utf-8') #word = word.decode('utf-8') print word For some reason, I cannot decode or encode this!! It gives me the err...

where is the 'itertools' file.

import itertools print itertools#ok the code is ok but i can't find the itertools file. who can tell me where is the 'itertools file' my code is run python2.5 import itertools print itertools.__file__ Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in <module> print itertools.__file__ A...

Python halts while iteratively processing my 1GB csv file

I have two files: metadata.csv: contains an ID, followed by vendor name, a filename, etc hashes.csv: contains an ID, followed by a hash The ID is essentially a foreign key of sorts, relating file metadata to its hash. I wrote this script to quickly extract out all hashes associated with a particular vendor. It craps out before it fin...

SQLAlchemy filter query by related object

Using SQLAlchemy, I have a one to many relation with two tables - users and scores. I am trying to query the top 10 users sorted by their aggregate score over the past X amount of days. users: id user_name score scores: user score_amount created My current query is: top_users = DBSession.query(User).opt...

How do you get all the rows from a particular table using BeautifulSoup?

Hi all, I know this is really basic, but I am really trying to learn Python and want to learn it to scrape data from the web. It may be basic, but I really am trying to learn how to read a HTML table. I can read it into Open Office and it says that it is Table #11. It seems like BeautifulSoup is the preferred choice, but can anyone...

Python: why aren't variables updating?

A python program that I'm debugging has the following code (including print statements for debugging): print "BEFORE..." print "oup[\"0\"] = " + str(oup["0"]) print "oup[\"2008\"] = " + str(oup["2008"]) print "oup[\"2009\"] = " + str(oup["2009"]) oup0 = oup["0"] oup2008 = oup["2008"] oup2009 = oup["2009"] ouptotal = oup2008 + oup2009 p...

python crypto high level wrapper

I'm using PyCrypto (on google app engine) for AES encryption. PyCrypto gives I guess a raw interface to AES--i need to pad my keys and my inputs to 16 byte multiples. Is there a higher level library which takes care of this stuff for me? ...

What does "mro()" do in Python?

in django.utils.funcitonal.py: for t in type(res).mro():#<-----this if t in self.__dispatch: return self.__dispatch[t][funcname](res, *args, **kw) i don't understand mro i search by google,and saw much english Article,but i still can't anderstand it, who can give me a simple example ,thanks...

What's the suggested way of importing modules within a django project

This has always bothered me, and I've never really come up with my own preferred way of doing this. When importing something from one of your own applications in a django project, do you import with: from myproject.mymodule.model import SomeModel from myproject.anotherone.model import AnotherModel or, do you do: from mymodule.model ...