python

Image color detection using python

Hi, After downloading an image from the site i need to detect the color of the downloaded image.I successfully downloaded the image but i need to detect the color of the corresponding image and to be save it in the name of the corresponding color.Code used is given below.Tell me how can i achieve it from the current position. imageur...

how to login to multiple website accounts concurrently with Python

I am using urllib2 and HTTPCookieProcessor to login to a website. I want to login to multiple accounts concurrently and store the cookies to be reused later. Can you recommend an approach or library to achieve this? ...

Encode East Asian languages using Python

This may not really be a Python related question, but pertains to language encoding in general. I'm mining tweets from Twitter, and it appears that there is a large Japanese user community (with messages in Japanese). When I tried encoding the tweets for an XML file I used utf-8. e.g tweet=tweet.encode('utf-8') and none of the Japanese t...

eagerly evaluating boolean expressions in Python

Hi! Is there a way (using eval or whatever) to evaluate eagerly boolean expressions in python? Let's see this: >>> x = 3 >>> 5 < x < y False Yikes! That's very nice, because this will be false regardless of y's value. The thing is, y can be even undefined, and I'd like to get that exception. How can I get python to evaluate all expre...

django calendar free/busy/availabilitty

I am trying to implement a calendar system with the ability to schedule other people for appointments. The system has to be able to prevent scheduling a person during another appointment or during their unavailable time. I have looked at all the existing django calendar projects I have found on the internet and none of them seem to have...

Problem with replacing a word in a file, using Python

I have a .txt file containing data like this: 1,Rent1,Expense,16/02/2010,1,4000,4000 1,Car Loan1,Expense,16/02/2010,2,4500,9000 1,Flat Loan1,Expense,16/02/2010,2,4000,8000 0,Rent2,Expense,16/02/2010,1,4000,4000 0,Car Loan2,Expense,16/02/2010,2,4500,9000 0,Flat Loan2,Expense,16/02/2010,2,4000,8000 I want to replace the first...

How to access string value from new class that inherit string type

I want to define a new class that inherit the build in str type, and create a method that duplicates the string contents. How do I get access to the string value assigned to the object of my new class ? class str_usr(str): def __new__(cls, arg): return str.__new__(cls, arg) def dub(self): # H...

Is there any limitation in python when handling long file paths?

I am writing a file copying utility in Python. But I am getting some error messages when processing files with very long file paths. I suspect Python has some limitations when handling very long file paths. ...

python : file deletion using rm command

I want to make sure that I delete required files. I have code something like dir="/some/path/" file = "somefile.txt" cmd_rm= "rm -rf "+dir + file os.system(cmd_rm) The dir and file values are fetched from a database. How can I make sure I never end up running rm -rf /? What things should I check before doing rm -rf? ...

How to use numpy with cygwin

Hi I have a bash shell script which calls some python scripts. I am running windows with cygwin which has python in /usr/bin/python. I also have python and numpy installed as a windows package. When I execute the script from cygwin , I get an ImportError - no module named numpy. I have tried running from windows shell but the bash scri...

Psycopg2, Postgresql, Python: Fastest way to bulk-insert

Hi, I'm looking for the most efficient way to bulk-insert some millions of tuples into a database. I'm using Python, PostgreSQL and psycopg2. I have created a long list of tulpes that should be inserted to the database, sometimes with modifiers like geometric Simplify. The naïve way to do it would be string-formatting a list of INSERT...

Why are these lists the same?

I can't understand how x and y are the same list. I've been trying to debug it using print statements and import code; code.interact(local=locals()) to drop into various points, but I can't figure out what on earth is going on :-( from collections import namedtuple, OrderedDict coordinates_2d=["x","y"] def virtual_container(virtual_co...

Round to 5(or other number) in python

Is there a build-in function that can round like this: 10 -> 10 12 -> 10 13 -> 15 14 -> 15 16 -> 15 18 -> 20 ...

uncompressing tar.Z file with python ?

I need to write a python script that retrieves tar.Z files from an FTP server, and uncompress them on a windows machine. tar.Z, if I understood correctly is the result of a compress command in Unix. Python doesn't seem to know how to handle these, it's not gz, nor bz2 or zip. Does anyone know a library that would handle these ? Thanks ...

[pygtk] change tab-label in gtk.NoteBook

Hi to all. I have notebook on my form and on each notebook's tab i have gtk.TextView. textview adding automaticaly when new notebook's tab add. Let's say I want to open a file in 3 textview into 3 tabs and when i open file i want that in tab-label will be file path. Tab add: def new_tab(self): scrolled_window = gtk.ScrolledWindow(...

Class Inheritance through Multiple Classes

Hello, I have 3 classes and I run the first class and declare a variable in the second class and want the 3rd class to be able to print out this variable. I have code below to explain this more clearly. from class2 import Class2 class Class1(Class2): def __init__(self): self.value1 = 10 self.value2 = 20 def a...

Python issue:Unable to find vcvarsall.bat

I'm trying to install MySql interface for python,but I got an error(mentioned below).And I know the solution,install the Microsoft Visual C++.So what my question is there any alternative solution apart from installing Microsoft Visual C++,I mean it's really hurt me,why should I install Microsoft Visual C++ just because to build this sing...

Python: sort a part of a list, in place

Let's say we have a list: a = [4, 8, 1, 7, 3, 0, 5, 2, 6, 9] Now, a.sort() will sort the list in place. What if we want to sort only a part of the list, still in place? In C++ we could write: int array = { 4, 8, 1, 7, 3, 0, 5, 2, 6, 9 }; int * ptr = array; std::sort( ptr + 1, ptr + 4 ); Is there a similar way in Python? ...

Python: select function

With this code: import scipy from scipy import * x = r_[1:15] print x a = select([x > 7, x >= 4],[x,x+10]) print a I get this answer: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14] [ 0 0 0 14 15 16 17 8 9 10 11 12 13 14] But why do I have zeros in the beginning and not in the end? Thanks in advance. ...

Is it possible to define a wx.Panel as a class in Python?

I want to define several plugins. They all inherit from the superclass Plugin. Each plugin consists on a wx.Panel that have a more specific method called "draw". How can I define a class as a Panel and afterwards call that class in my frame? I've tried like this: class Panel(wx.Panel): def __init__(self, parent): wx.Panel...