check the xml & amp; add items with Python 3.4

I want to iterate through the child-elements of and element and check their attributes. If a certain attribute value is missing it should append an empty element with that attribute value. So to this: <app> <rdg wit="#W_1956">Im Rest

The text in the dictionary does not work

I have the following text file in the same folder as my Python Code. 78459581 Black Ballpoint Pen 12345670 Football 49585922 Perfume 83799715 Shampoo I have written this Python code. file = open("ProductDatabaseEdit.txt", "r") d = {} f

& ldquo; Fire and forget & quot; python async / wait

Sometimes there is some non-critical asynchronous operation that needs to happen but I don't want to wait for it to complete. In Tornado's coroutine implementation you can "fire & forget" an asynchronous function by simply ommitting the yiel

Python urllib2.urlopen returns an HTTP 503 error

Here you can see my code snippet. Since 3 days it does not work any longer. My python is running under Ubuntu 10.04.4 LTS. Python version is 2.6.5. #!/usr/bin/env python import urllib2 as ur ... webpage = [] site = "

Python 'NoneType' iterable in list operation

I am writing a function to remove duplication in one list. For specific: input : a list output: a list without any duplication this is my code: def remove_duplicate(s_list): for member in s_list: for other in s_list.remove(member): if other == member

How to load a single class from the module?

I have code: mod_file = '' mod_path = os.path.join('.', mod_file) mod_py = 'mymod' mod = imp.load_source(mod_py, mod_path) if hasattr(mod, 'MyClass'): instance = py_mod.MyClass() class MyClass(): def __init__(self): print 'Hello' [.

Error: list indexes must be non-floating integers

The code following should take the list of marks from the dictionary of a student and calculate the average marks of the student. I am getting the "TypeError: list indices must be integers, not float" error. alice = { "name": "Ali

best practice for graphical entities on appengine ndb

I'm designing a g+ application for a big international brand. the entities I need to create are pretty much in form of a graph, hence a lot of many-to-many relations (arcs) connecting nodes that can be traversed in both directions. I'm reading all th

Python extracting the body from the function to the execution

Given a function in Python defined as follows: a = 3 b = 4 c = 5 def add(): d = a+b+c is it possible to get a code object or similar that gives me: a = 3 b = 4 c = 5 d = a+b+c The function object has a code object associated with it; you can exec tha

How to map one range of values ​​to another in python

Want to do the equivalent of this, (and the inverse toByte) in python, how do you map in python? int toInt(byte b) { return map(b, 0, 255, -128, 127); } i would try int([representation],base)-128 but I don't know what representation and base areint([

Python class variable access performance

I wonder if there is any difference in performance when accessing a class variable (a dict) inside a method of the same class using: self.class_variable_dict.add(some_key, some_value) and ClassName.class_variable_dict.add(some_key, some_value) obviou

Django Ajax Jquery Call

This may be basic, but I've spent two days, read countless tutorials and I still can not get this to work. For simplicitly I tried to accomplish a basic task just to see it work. I want to send make an ajax call to my donate view. I see that it succe

WebSocket onmessage () not called when messages are sent

I'm using autobahn 0.4.10 ( as a WebSocket server to send messages to a Google Chrome Extension. I am able to open and close connections using WebSocket(), but when I call autobahn.websocket.WebSocketServerProtoco

Sending messages or data with bluetooth via python

How can i send messages over bluetooth via python without key authentification like type numbers ? i used pybluez but i got this error: File "./send", line 12, in <module> connect() File "./send", line 8, in connect sock.connect(

Generating HTML documents in python

In python, what is the most elegant way to generate HTML documents. I currently manually append all of the tags to a giant string, and write that to a file. Is there a more elegant way of doing this?I would suggest using one of the many template lang

Urllib and validation of the server certificate

I use python 2.6 and request Facebook API (https). I guess my service could be target of Man In The Middle attacks. I discovered this morning reading again urllib module documentation that : Citation: Warning : When opening HTTPS URLs, it is not atte

Django module already imported and python

Can anyone help me get rid of these warnings in Django please? /usr/lib/python2.6/site-packages/simplejson-2.1.5-py2.6-linux-x86_64.egg/simplejson/ UserWarning: Module taggit was already imported from /var/www/html/matilah/taggit/__ini

How to remove stdout lines in python?

I have a program that grabs some data through ssh using paramiko: ssh = paramiko.SSHClient() ssh.connect(main.Server_IP, username=main.Username, password=main.Password) ssh_stdin_host, ssh_stdout_host, ssh_stderr_host =ssh_session.exec_command(settin

Unable to install pyodbc on Linux

I am running Linux ( and trying to install pyodbc. I am doing pip install pyodbc and get a very long list of errors, which end in error: command 'gcc' failed with exit status 1 I looked in /root/.pip/pip.log and saw th

What is the best way to play audio through Qt?

I am building an application in pyQt4 and I want it to be able to play audio files. I was considering doing this through pyMedia as I could not get anywhere with the documentation, although the QAudio classes did initially look promising. It is impor

Simple way to simulate a slow python network

Scenario. I have a client with two network connections to a server. One connection uses a mobile phone, and the other is using a wlan connection. The way that I have solved this is by having the server listen at two ports. But, the mobile connection