python

What other Language synergizes well with Python? Need Advice

Ok so I know the basics of programming languages, I've studied python and liked it a lot. I'm studying now the intermediate parts of python and I'm catching the concepts already. I'm working with a project and at the same time solving computer problems that practices algorithm use. I've learned that python has limitations and wants to co...

Using python to provide application services

My company's web architecture has essentially got an extra layer due to client security requirements, which complicates the process of developing applications a bit. I'd like to get some input and suggestions on the best way to do so. First, an overview: presentation layer - this is mostly PHP, with some flex applications as well. We ...

How to convert bytes in a string to integers? Python

I want to get a list of ints representing the bytes in a string. ...

Importing python modules in jython

I'm having some issues importing scapy under jython. I've been doing java forever, but python for only a day or two. The simple case to reproduce the problem is: $jython >>> import sys >>> sys.path ['', '/usr/share/jython/Lib', '/usr/lib/site-python', '__classpath__'] >>> from scapy.all import * Traceback (innermost last): File "<cons...

what is the most efficent Python script to the below question?

Possible Duplicate: What is your solution to the FizzBuzz problem? Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Here is what I have right...

Django-Haystack + Whoosh - Are misspelling suggestions possible?

Hi folks, I'm using Whoosh and Django-Haystack. I would like to make use of query suggestions for when users mistype words. e.g. Maybe you meant "unicorn" Is it necessary to use another search engine? Or can I successfully achieve this with Whoosh? ...

Python Deque appendleft with list

Hi, I am currently creating my deque object using the following, self.CommandList = deque((['S', False, 60],['c'],['g16'],['i50'],['r30', True],['u320'],['o5000'],['b1'],['B4500'],['W1'],['l5154'],['!10'],['p2', True, 10],['e1'],['K20'],['U0'],['Y0'])) But I wish to add a similar list to the queue later but using appendleft, so it ca...

Catching http errors

Hello, how can I catch the 404 and 403 errors for pages in python and urllib(2), for example? Are there any fast ways without big class-wrappers? Added info (stack trace): Traceback (most recent call last): File "test.py", line 3, in <module> page = urllib2.urlopen("http://localhost:4444") File "/usr/lib/python2.6/urllib2.py",...

How do I redirect different domain names requests to the same ip in django

Hi Django newbie here, I have one ip for two domain name, e.g. "www.example.com" and "example.info", and I want each of them to be handled as a different domain (e.g. www.example.com/photos and example.info/photos will be ahndled each by its corresponding function). Is there an elegant way to do this in django? ...

Problem With Python Bindings on a Widget That uses GStreamer

First, some background information: I'm currently developing a program for the Nokia N900 using Python and PyQt4. The program accesses the phone's camera. I have figured out how to use GStreamer in a Qt widget to capture the video. It turns out that I need access to a somewhat obscure gstreamer interface which I don't believe I can ac...

Tweepy API: how to get a user's id from a status SearchResult object?

I'm trying to write a script to follow people on twitter. The tweepy API seems pretty good, but I'm running into some unintuitive behavior related to the mapping from user's ids to their screen names. In [1]: import tweepy In [2]: api = tweepy.API() # get an arbitrary tweet In [3]: tweet = api.search("anything")[0] In [5]: tweet.text...

Call back in Python

Hi, Could some explain how call back methods work, and if possible, give me an example in Python? So as far as I understand them, they are methods which are provided by the user of an API, to the API, so that the user doesn't have to wait till that particular API function completes. So does the user program continue executing, and once ...

access memory mapped file created on .net via python

I made a memory mapped file using MemoryMappedFile.CreateNew(mapName, capacity) of .net 4 Can i access this mmf by the mapName from cpython ? I tried like below. import mmap map = mmap.mmap(-1, 0, mapName, 1) but it returns WindowsError [error 87] saying the parameter is incorrect. I'm using windows vista. ...

Access native windows icons for custom wxDialogs

I want to subclass wx.Dialog to get a little more functionality than is provided by the wx.MessageDialog class but I would still like to be able to use the native windows icons (ie the ones used in the wx.MessageDialog that can be set by the flags such as wx.ICON_ERROR etc.. ) Is there anyway to access these? Update: Thanks to steven ...

Copying files with Python under Windows

I'm trying to copy files inside a Python script using the following code: inf,outf = open(ifn,"r"), open(ofn,"w") outf.write(inf.read()) inf.close() outf.close() This works perfectly unedr OSX (and other UNIX flavors I suspect) but fails under Windows. Basically, the read() call returns far less bytes than the actual file size (which ...

how to define following operator/function in python ?

i am new to programming need to define operator/function s^m such that s^m(a^g^n+b^g^o+c^g^p*d^g^q)+a^g^f=a^g^(n+m)+b^g^(o+m)+c^g^(p+m)*d^g^(q+m)+a^g^f a b c d g ..all symbols ^=power ,in simple language operator which will transform all 'g's in bracket to g^m while keeping those out of bracket as it is . i am working on solving ...

mod_wsgi problem with MAMP

I make mod_wsgi is like following $./configure --with-python=/Library/Frameworks/Python.framework/Versions/2.7/bin/python --with-apxs=/usr/local/apache2/bin/apxs checking Apache version... 2.0.63 configure: creating ./config.status config.status: creating Makefile $sudo make $sudo make install and then I cop...

Numpy interconversion between multidimensional and linear indexing

I'm looking for a fast way to interconvert between linear and multidimensional indexing in Numpy. To make my usage concrete, I have a large collection of N particles, each assigned 5 float values (dimensions) giving an Nx5 array. I then bin each dimension using numpy.digitize with an appropriate choice of bin boundaries to assign each...

defining variable from string

I'm trying to define variable inside function. vars() shows variable is created, but gives me NameError: exception. What am I doing wrong? def a(str1): vars() [str1] = 1 print vars() print b a('b') output: {'str1': 'b', 'b': 1} exception: NameError: global name 'b' is not defined ...

How do I do threading in python?

I am trying to learn how to use threads with python. this is the code I have been studying: import time from threading import Thread def myfunc(i): print "sleeping 5 sec from thread %d" % i time.sleep(5) print "finished sleeping from thread %d" % i for i in range(10): t = Thread(target=myfunc, args=(i,)) t.start() ...