python

Remove empty strings from a list of strings

I want to remove all empty strings from a list of strings in python. My idea looks like this: while '' in str_list: str_list.remove('') Is there any more pythonic way to do this? ...

network programming in python

I established a TCP client server connection in python where the server sends code to the client and the client evaluates the code sent.The code is sent from a file in the server. While runnig the code, it works fine at times, but at times the client code doesn't work.. It gets stuck.. Is it some problem with the network connection or th...

Django: request.GET and KeyError

Code: # it's an ajax request, so parameters are passed via GET method def my_view(request): my_param = request.GET['param'] // should I check for KeyError exception? In PHP Frameworks I typically have to check for parameter to exists and redirect user somewhere if it does not. But in Django unexisted parameter results in 500 error...

Copy strings from multiple lineEdit slots as variable to one textEdit slot in PyQt4

to be more crystal clear, here how the things might work. in python, to create a variable, simply we use var1 = raw_input('your name?') so that when using print 'your name is ' +var1 it will print the string stored in var1. the question is how to make that using Pyqt4? I have 3 lineEdit symbolize as name, age and gender and on...

Mac OS X python 'import vigra' error

Hi guys, I want to use vigra under Mac OS X 10.6.4. So I installed all dependencies with Macpotrs. Everything compiled and I could install vigra too. But when I try to import vigra, then I get a 'Segmentation fault'. Do someone know how to solve this problem? Here the Mac OS X error report: Process: Python [784] Path: /o...

Precompose Unicode Character Sequences in Python

Hi, How can I convert decomposed unicode character sequences like "LATIN SMALL LETTER E" + "COMBINING ACUTE ACCENT" (or U+0075 + U+0301) so they become the precomposed form: "LATIN SMALL LETTER E WITH ACUTE" (or U+00E9) using native Python 2.5+ functions? If it matters, I am on Mac OS X (10.6.4) and I have seen the question Converting ...

Issues with implementing a network server with SocketServer

Dear Friends! I am beginner in socket programming and need your help. I have implemented simple echo server using ThreadedTCPServer example from the Python documentation. It works fine, but I have the following problems: 1) Server hangs (in socket.recv) when Client tries to send zero-length data. 2) Server hangs (in socket.recv) when th...

Django: TEMPLATE_DIRS vs INSTALLED_APPS

I am currently just add app to INSTALLED_APPS to be able to use templates from that app, but there is also TEMPLATE_DIRS setting. When have I to prefer TEMPLATE_DIRS over INSTALLED_APPS? ...

Multithread DNS Query against specific DNS, domain and recordtype supporting Library

Resolved, used adns with python bindings... I have a scenario in which i have to do the following: Load a domain Load what record type is to be queried Load list of DNS Perform query, fetch results and display them. I have tried this but its not multi threaded and even a single query takes about 3 seconds. I looked at ADNS, its pyth...

Calculating the shortest distance(perpendicular distance) between a point and a line

Possible Duplicate: Shortest distance between a point and a line segment Hi, I have a point A, and a Line with two endpoint B,C. I want to know how I can calculate the shortest distance between point A and the line formed within B and C. Pseudo-code is enough. Though, Python is preferred. Thanks ...

C++ vs Python precision

Trying out a problem of finding the first k digits of a num^num I wrote the same program in C++ and Python C++ long double intpart,num,f_digit,k; cin>>num>>k; f_digit= pow(10.0,modf(num*log10(num),&intpart)+k-1); cout<<f_digit; Python (a,b) = modf(num*log10(num)) f_digits = pow(10,b+k-1) print f_digits Input 19423474 9 Output...

Adding audio to video produced from OpenCV

I've been using OpenCV under python to record video from a capture device. Two output AVI's are written each hour, at the top of each hour the file names are changed. One of the files is the original capture and one uses some of OpenCV's detection functions. As always, things change and audio needs to be recorded which wasn't originally...

Print variable in python without space or newline

print a variable without newline or space python3 does it by print (x,end='') how to do it in python 2.5 ...

Why does Importing a dotted module name fail when upper level is matched by a module in current directory?

I was trying out one of the Python standard library modules, let's call it foo.bar.baz. So I wrote a little script starting with import foo.bar.baz and saved it as foo.py. When I executed the script I got an ImportError. It took me a while (I'm still learning Python), but I finally realized the problem was how I named the script. ...

Routes/Pylons Fails Before Touching My Code

I am very puzzled over this error. In a previously functional Pylons app (running on apache/mod_wsgi), Routes has exploded. When I attempt to access my application, no matter what URL I use, I get the Apache "Internal server error" page and the following traceback in /var/log/apache2/error.log. [Sat Oct 02 2010] WSGI Variables [Sat ...

Learning Twisted

How do I begin learning Twisted? What books, documentation or tutorial do you guys recommend? The reason I asked this question is that I think learning Twisted would help me otherwise also in learning concepts related to network programming (terminologies and how it works and stuff) I have heard that the documentation for Twisted is not...

handling manual user creation with get_current_user() (GAE)

I am using GAE's Python environment and Janrain in order to provide multiple ways to login in my service. Based on login information I receive from Janrain, I create a google.appengine.api.User object and store it to the datastore. Is there a way to handle this new object with the built-in get_current_user()? I need to be able to dete...

Codechef python runtime error

I always get a runtime error using python for submission on codechef. Can some one please help. Tried answering other questions too.. same error Works fine on my comp though!(I use python 2.6.5 on my comp. Answer is checked with python 2.5) This is an easy level question where i get Runtime error http://www.codechef.com/problems/FCTRL/ ...

parse html beautiful soup

Hi all. I have a html page <a email="[email protected]" href="http://www.max.ru/agent?message&amp;[email protected]" title="Click herе" class="mf_spIco spr-mrim-9"></a><a class="mf_t11" type="booster" href="http://max.ru/mail/corporate/"&gt; I neeed a parse email string soup = BeautifulSoup(data string = soup.find("a",{"ema...

Twitter library for App Engine Python?

I am looking for an Python library which is compatible with app engine and provides an interface to the Twitter API. I found the python-twitter project - has anyone has used it on app engine? ...