python

How to draw this window ?

Can I create a window without this topbar? : I want a window like this: ...

How can I write a python script equivalent of mdfind using PyObjC bindings and NSMetadataQuery?

I want to write the python equivalent of mdfind. I want to use the .Spotlight-V100 metadata and I cannot find a description for the metadata db format used, but NSMetadataQuery seems to be what I need. I'd like to do this in python using the built in Obj-C bindings, but have not been able to figure out the correct incantation to get it t...

Python import module results in NameError

I'm having a module import issue. using python 2.6 on ubuntu 10.10 I have a class that subclasses the daemon at http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ . I created a python package with a module containing code that imports some models from a django project. The code works when used from a class, no...

string length without len function in python

hi can anyone tell me how can i get the length of a string if a user input it and we want to know the length of the string without sing len function or any string methods please anyone tell me as i m tapping me head madly for the answer..... thank you ...

Creating and returning a value from a custom dialog box in pyqt?

I've been building a small application in pyQT and I've run into a problem. I'd like to create a modal dialog box that appears on launching the application and collects some input from the user (probably a set of checkboxes that will be populated at runtime). I'm unsure of the best way to accomplish this. Should I subclass QDialog (and i...

Is there a way to resist unnecessary joins that are only checking id existence when using Django's orm?

In example. If I have a model Person who's got a mother field, which is a foreign key.. The following is getting to me: p = Person.object.get(id=1) if p.mother_id: print "I have a mother!" In the above example, we've issued one query. I've tricked Django into not fetching the mother by using the _id field instead of mother.id. But...

Longest increasing subsequence.

Given an input sequence, what is the best way to find the longest (not necessarily continuous) non-decreasing subsequence. 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 # sequence 1, 9, 13, 15 # non-decreasing subsequence 0, 2, 6, 9, 13, 15 # longest non-deceasing subsequence (not unique) I'm looking for the best algorithm. I...

Python generator that groups another iterable into groups of N.

I'm looking for a function that takes an iterable i and a size n and yields tuples of length n that are sequential values from i: x = [1,2,3,4,5,6,7,8,9,0] [z for z in TheFunc(x,3)] gives [(1,2,3),(4,5,6),(7,8,9),(0)] Does such a function exist in the standard library? If it exists as part of the standard library, I can't seem to ...

passing text through a dictionary in Python

I currently have python code that compares two texts using the cosine similarity measure. I got the code here. What I want to do is take the two texts and pass them through a dictionary (not a python dictionary, just a dictionary of words) first before calculating the similarity measure. The dictionary will just be a list of words, alt...

Print all variables in a class? - Python

I'm making a program that can access data stored inside a class. So for example I have this class: #!/usr/bin/env python import shelve cur_dir = '.' class Person: def __init__(self, name, score, age=None, yrclass=10): self.name = name self.firstname = name.split()[0] try: self.lastname = name.sp...

How to change Selection Colour for selected items in wxpython's CustomTreeCtrl

I am using wxpython's CustumTreeCtrl. Since some of the items in my tree-hierarchy are supposed to have different textcolours it would useful if these items also keep their textcolours when selected. However, when an item is selected the background colour is automatically changed to blue (that can be controlled with SetHilightFocusColour...

ImportError: No module named ***** in python

I am very new to python, about one month, and am trying to figure out how the importing works in python. I was told that I can import any 'module' that has Python code in it. So I am trying to import a module just to try it out, but I keep getting an 'ImportError: No module named redue'. This is an example of the python shell: >>> impor...

What does ... mean in numpy code?

And what is it called? I don't know how to search for it; I tried calling it ellipsis with the Google. I don't mean in interactive output when dots are used to indicate that the full array is not being shown, but as in the code I'm looking at, xTensor0[...] = xVTensor[..., 0] From my experimentation, it appears to function the simila...

python: class override "is" behavior

I'm writing a class which encapsulates any arbitrary object, including simple types. I want the "is" keyword to operate on the encapsulated value, such as this behavior: Wrapper(True) is True -> True Wrapper(False) is True -> False Wrapper(None) is None -> True Wrapper(1) is 1 -> True Is there any object method I can override to get t...

Pygtk VS Pyqt VS WxPython VS Tkinter

What is the most used of these library and why ? What are the differences ? ...

Python regular expression problem

Hi, I need to do something in regex but I'm really not good at it, long time didn't do that . /a/c/a.doc I need to change it to \\a\\c\\a.doc Please trying to do it by using regular expression in Python. ...

Facebook Permission request form for Crawling?

I have been Googling for sometime but I guess I am using the wrong set of keywords. Does anyone know this URI that lets me request permission from Facebook to let me crawl their network? Last time I was using Python to do this, someone suggested that I look at it but I couldn't find that post either. ...

Django: How to override unique_together error message?

In a model's Meta class, I define a unique_together. I have a ModelForm based on this model. When I call is_valid on this ModelForm, an error will automatically raised if unique_together validation fails. That's all good. Now my problem is that I'm not satisfied with the default unique_together error message. I want to override it. How ...

python running time question big o notation

In each code fragment given below, determine the number of steps and describe what the code accomplishes. i.e., what value of x has been output based on the value of the integer n. Assume the value of n has already been set. State your running times using the big-O notation. (Remember to throw away leading constants and lower-ordered te...

How do I access netstat data in Python?

I'm trying to need to access/parse all outgoing connections on a particular port number on a Linux machine using a Python script. The simplest implementation seems to be to open a subprocess for netstat and parse its stdout. I imagine someone somewhere has had this problem before, and am surprised not to find any netstat parsers online....