python

python pyrad problem

Hi all, I setup some RADIUS backend to allow AD authentication via the 'admin' of django. Alltough i got a problem with some dictionaries, i really don't know what i'm doing wrong. This is the error i got: IOError at /admin/ Errno 2] No such file or directory: '/home/pl/dictionary.compat' I installed pyrad, so it should be there and i...

Get filename when using urllib.urlopen

I'm using urllib.urlopen to read a file from a URL. What is the best way to get the filename? Do servers always return the Content-Disposition header? Thanks. ...

How to load .bmp file into BitmapImage class Tkinter python

I'm unable to find any way to load .bmp file into Tkinter() so that I can use it in a canvas widget!Plz help me! from Tkinter import * from PIL import Image import ImageTk import tkFileDialog import tkMessageBox root=Tk() class lapp: def __init__(self,master): w=Canvas(root,width=300,height=300) w.pack() p=Image.ope...

What are Python namespaces all about

I have just started learning Python & have come across "namespaces" concept in Python. While I got the jist of what it is, but am unable to appreciate the gravity of this concept. Some browsing on the net revealed that one of the reasons going against PHP is that it has no native support for namespaces. Could someone explain how to us...

Django - ManyToManyField in a model, setting it to null?

I have a django model (A) which has a ManyToManyField (types) to another model (B). Conceptually the field in A is an 'optionally limit this object to these values'. I have set blank=null and null=True on the ManyToManyField. I have created an object from this model, and set types to some values. All is good. I want to set it to 'null',...

Python: read user-input directly from the prompt

Hi! I have to validate user-input from stdin that is not going to be entered by hitting the Enter-key. So readline() and other Enter-dependent functions are of no use to me. Practically the promt will be filled, and each keystroke has to be handled as an event. How do I get access to the promt buffer's contents? ...

about textarea \r\n or \n in python

i have tested code in firefox under ubuntu: the frontend is a textarea,in textarea press the key ENTER,then submit to the server, on the backend you'll get find \r\n string r=request.POST.get("t") r.find("\r\n")>-1: print "has \r\n" my question is when we will get \r\n ,when we'll get \n?is this platform independent? this is im...

Length of arguments of Python function?

Possible Duplicate: How to find out the arity of a method in Python For example I have declared a function: def sum(a,b,c): return a + b + c I want to get length of arguments of "sum" function. somethig like this: some_function(sum) to returned 3 How can it be done in Python? Update: I asked this question because I wa...

Python relative import causes syntaxerror: invalid syntax

Hi all, I'm trying to install this great python module Python-Chrono to my python environment, but it fails at least with python 2.4.3 and 2.6.6 with the following error message: Traceback (most recent call last): File "setup.py", line 30, in ? import chrono File "/home/janne/python-chrono-0.3.0/chrono/__init__.py", line 22 ...

Deploy a sub package with distutils and pip

I am wanting to create a suite of interrelated packages in Python. I would like them all to be under the same package but installable as separate components. So, for example, installing the base package would provide the mypackage but there would be nothing in mypackage.subpackage until I install it separately. Is this possible with di...

Developing and using the same Python on the same computer

I'm developing a Python utility module to help with file downloads, archives, etc. I have a project set up in a virtual environment along with my unit tests. When I want to use this module on the same computer (essentially as "Production"), I move the files to the mymodule directory in the ~/dev/modules/mymodule I keep all 3rd-party mod...

Implementing a text-based fallback for pygtk applications

I have a pygtk application and would like to provide a text-based fallback mode for it. When mporting gtk without a X display available I see only a GtkWarning on stderr but no exception I could take advantage of and checking for DISPLAY seems like an ugly hack. How can I implement this? ...

open a string in notepad at runtime in python

I have a string called 's' and I want to open it in notepad at runtime without saving it in/as a file. Is there any way to achieve this in python? ...

Python: How to loop through blocks of lines

How to go through blocks of lines separated by an empty line? The file looks like the following: ID: 1 Name: X FamilyN: Y Age: 20 ID: 2 Name: H FamilyN: F Age: 23 ID: 3 Name: S FamilyN: Y Age: 13 ID: 4 Name: M FamilyN: Z Age: 25 I want to loop through the blocks and grab the fields Name, Family name and Age in a list of 3 columns: ...

Split up python packets ?

Is there a way python can distinguish between packets being sent ? e.g. python receives data it process data clients sends first packet client sends second packet python receives data, can i receive the first packet rather then all info in the buffer I know i can set it up up so it sends data i confirm and the client wont send more...

Advice on which language to use

I'm trying to create a web application which will get input from system. What this application should do is to listen what happens when some shell scripts are executing and reporting the status trough web. An example : I'm copying thousands of records with shell script, and while this is still executing I'd like pass the current stat...

Split a string in python

a="aaaa#b:c:" >>> for i in a.split(":"): ... print i ... if ("#" in i): //i=aaaa#b ... print only b In the if loop if i=aaaa#b how to get the value after the hash.should we use rsplit to get the value? ...

Python: False or None vs. None or False

In [20]: print None or False -------> print(None or False) False In [21]: print False or None -------> print(False or None) None This behaviour confuses me. Could someone explain to me why is this happening like this? I expected them to both behave the same. ...

How to turn a float number like 293.4662543 into 293.47 in python?

How to shorten the float result I got? I only need 2 digits after the dot. Sorry I really don't know how to explain this better in English... Thanks ...

How to decode string to use with Google Language Detection API?

Hi. I want to use Google Language Detection API in my app to detect language of url parameter. For example user requests url http://myapp.com/q?Это тест and gets message "Russian". I do it this way: def get(self): url = "http://ajax.googleapis.com/ajax/services/language/detect?v...