python

why class creation throws error

Just playin around class def func(*args, **kwargs): print args, kwargs class Klass(func): pass it throws error TypeError: Error when calling the metaclass bases function() argument 1 must be code, not str What does it mean, i am passing no str nowhere? and yes I should be passing class in bases but why didn't error ...

IMEI number of a mobile phone using python

Hi, How can I get the IMEI number of a mobile phone using Python? Thanks in advance. Nimmy ...

Get class in Python decorator

In this code: def online_only(func, self): def f(*args, **kwargs): if self.running: return func(*args, **kwargs) else: return False return f class VM(object): @property def running(self): return True @property @online_only def diskinfo(self): return True I wa...

Inserting an item in a Tuple

Yes, I understand tuples are immutable but the situation is such that I need to insert an extra value into each tuple. So one of the items is the amount, I need to add a new item next to it in a different currency, like so: ('Product', '500.00', '1200.00') Possible? Thanks! ...

Python equivalent of std::set and std::multimap

I'm porting a C++ program to Python. There are some places where it uses std::set to store objects that define their own comparison operators. Since the Python standard library has no equivalent of std::set (a sorted key-value mapping data structure) I tried using a normal dictionary and then sorting it when iterating, like this: def __...

In Python, how do I print out what arguments the function requires/allows?

Suppose I have a function. I just want to print out what arguments are available. ...

How to Include xml file as .py source file

I am having a xml file and i am reading the data from that xml file. But the problem is that i am making an exe file from all the available .py files (using py2exe). i dont want to distribute my xml file along with my exe ( because of securiy reasons) as standalone xml file.I want my xml file should be part of exe as all other remaining...

Get rid of leading zeros for date strings in Python?

Is there a nimble way to get rid of leading zeros for date strings in Python? In the example below I'd like to get 12/1/2009 in return instead of 12/01/2009. I guess I could use regular expressions. But to me that seems like overkill. Is there a better solution? >>> time.strftime('%m/%d/%Y',time.strptime('12/1/2009', '%m/%d/%Y')) '12/0...

Downloading Image

Hi all, I used urllib2.build_opener() to download an image from a corresponding url.But for a particular url i am getting error.When i checked that url i came to know that there is no image.How can i check whether there is image or not.This is my code opener1 = urllib2.build_opener() page1=opener1.open(orginal) my_picture=page1.read()...

Modifying the `clear` attribute of an image with TinyMCE

I'm using TinyMCE with the tinymce-django app in my Django website. I am using it in the admin interface to edit HTML fields. (Something like a flatpage.) When adding images with TinyMCE, how can I change their clear style attribute? ...

Redirect stderr to stdout on exec-ed process from python?

In a bash script, I can write: exec 2>&1 exec someprog And the stderr output of someprog would be redirected to stdout. Is there any way to do a similar thing using python's os.exec* functions? This doesn't have to be portable, just work on Linux. ...

Integer comparison in python slows everything down to a crawl

The following code is causing me enormous headaches: def extract_by_letters(letters, dictionary): for word in dictionary: for letter in letters: if word.count(letter) != letters.count(letter): if word in dictionary: #I cant leave this line out dictionary.remove(word) return d...

django error:Invalid block tag: 'endblock'

why?? thanks ...

file manipulation and find a word and tricky replace

I have file something like this hostname ser1-xyz myuser name passwd secret group 1234 hostname ser2-xyz myuser name passwd secret group 2345 I need to find the line first appearance of host named "ser1-xyz" and modify it as "ser1" and increment it's the group value by 1 So that final file looks like : hostname ser1...

Reading file from concatinated ( tar ) file directly without untarring the tar file

Hi i am having a one xml file and some image files, i am making my one concatenate file (ie as like tar file) from all these file (i am having my own scripts for tarring and untarring). before i describe what exactly i want you have to look the current situation. As of now i have to untar the all files into a directory then i am able ...

How to write GUI in Python?

I would like to try to write a GUI application in Python. I found out that there are a lot of ways to do it (different toolkits). And, in this context, I have several basic (and I think simple) question? Is it, in general, a good idea to write a GUI application in Python? What is the standard (easiest and most stable) way to create a G...

urlfetch.fetch got missed content within script tag of html in app engine

in my app, when I use urlfetch.fetch function to fetch a specified url, I found the content I got is empty for some special html codes. for example, the url: http://www.club.cn.sodexo.com/node/5071 in real html source, the codes including: <div class="content"> <div style="width: 219px; height: 262px;" id="gmap-auto3map-gmap0" class="...

When I use httplib for my OAUTH in Python, I always get "CannotSendRequest" and then "

Traceback: File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response 92. response = callback(request, *callback_args, **callback_kwargs) File "/home/ea/ea/hell/life/views.py" in linkedin_auth 274. token = oauth_linkedin.get_unauthorised_request_token() File "/home/ea/ea/hell/life/o...

running a .py by double-clicking is not working

I'm using Windows XP. When I double click the Launch_PyDemos.pyw from the book Programming Python, nothing happens. When I try to run Launch_PyDemos.pyw from command-line, I get the error message: Traceback (most recent call last): File "PyDemos2.pyw", line 41, in <module> from PP3E.Gui.Tools.windows import MainWindow # a Tk w...

What encryption algorithm would be best for data transfer between Python and Php?

Hi all, I am writing a client / server based program, Server side is with Php and Client is with Python, and I need to make sure the transfer data is safe both way. So, My question is What encryption algorithm would be best for data transfer between Python and Php? I couldn't use Https Need to decrypt/encrypt with key on both Pytho...