Hi everyone.
This question is in continuation to my previous question, in which I asked about passing around an ElementTree.
I need to read the XML files only and to solve this, I decided to create a global ElementTree and then parse it wherever required.
My question is:
Is this an acceptable practice? I heard global variables are ba...
Given two vectors X and Y, I have to find their correlation, i.e. their linear dependence/independence. Both vectors have equal dimension. The result should be a floating point number from [-1.0 .. 1.0].
Example:
X=[-1, 2, 0]
Y=[ 4, 2, -0.3]
Find y = cor(X,Y) such that y belongs to [-1.0 .. 1.0].
It should be a simple construct...
Hello,
In brief, I am trying to call into a shared library from python, more specifically, from numpy. The shared library is implemented in C using sse2 instructions. Enabling optimisation, i.e. building the library with -O2 or –O1, I am facing strange segfaults when calling into the shared library via ctypes. Disabling optimisation (-O...
I wanted to make my own encryption algorithm and decryption algorithm , encryption algorithm works fine and converts ascii value of the characters into alternate hexadecimal and octal representations. But when I tried decryption, problem occured as it return int('0671') = 671, as 0671 is string type in the following code. Is there a meth...
Can someone explain why Python does the following?
>>> class Foo(object):
... bar = []
...
>>> a = Foo()
>>> b = Foo()
>>> a.bar.append(1)
>>> b.bar
[1]
>>> a.bar = 1
>>> a.bar
1
>>> b.bar
[1]
>>> a.bar = []
>>> a.bar
[]
>>> b.bar
[1]
>>> del a.bar
>>> a.bar
[1]
It's rather confusing!
...
I need to replace all the white(ish) pixels in a PNG image with alpha transparency.
I'm using Python in AppEngine and so do not have access to libraries like PIL, imagemagick etc. AppEngine does have an image library, but is pitched mainly at image resizing.
I found the excellent little pyPNG module and managed to knock up a little fun...
i want to how to profile my code...
i have gone through the docs , but as there were no example codes given i could not get anything from it.
i have a large code and it is taking so much time hence want to profile and increase its speed.
i havent written my code in method , there are few in between but not completely.
i dont have any mai...
I have a python program that imports pythoncom (and uses pythoncom.CoCreateInstance from it). I want to create a unittest for the program logic without it importing pythoncom (so I can run the test on Linux as well).
What options are there? Can I do it without modifying the system under test?
What I found so far:
sys.modules["pythonco...
Possible Duplicate:
Python Ternary Operator
If Python would support the (x ? a : b) syntax from C/C++, I would write:
print paid ? ("paid: " + str(paid) + " €") : "not paid"
I really don't want to have an if-check and two independent prints here (because that is only an example above, in my code, it looks much more complica...
Possible Duplicate:
Learning Java?
Hi,
I'm basically a Python programmer and I want to develop a java based application.
What basic requirements do I need to develop?
...
When you write an application using Qt, it can be run in different operating systems. And - correct me if I'm wrong - you don't need to have Qt already installed in all of the plataforms you execute your application.
How exactly this approach works? Does Qt compiles to the desired platform, does it bundle some "dlls" (libs), how does it...
The following script will take a screenshot on a Gnome desktop.
import gtk.gdk
w = gtk.gdk.get_default_root_window()
sz = w.get_size()
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False, 8, sz[0], sz[1])
pb = pb.get_from_drawable(w, w.get_colormap(), 0, 0, 0, 0, sz[0], sz[1])
if (pb != None):
pb.save("screenshot.png", "png")
prin...
Hi..
I have a hex string and i want to convert it utf8 to insert mysql. (my database is utf8)
hex_string = 'kitap ara\xfet\xfdrmas\xfd'
..
..
..
result='kitap araştırması'
How can i do that?
Best regards.
...
Hi,
I need to create an application for the company where I can create sites dynamically. For example, I need an admin interface (Django's admin is enough) where I can setup a new site and add some settings to it.
Each site must hold a domain (domains can be manually added to apache conf, but if Django can handle it too would be awesome...
Below works on Python 2.6 but on Python 3.x it doesn't:
old_file_write = file.write
class file():
def write(self, d):
if isinstance(d, types.bytes):
self.buffer.write(d)
else:
old_file_write(d)
# ... some code I cannot change or do not want to change
f = open("x")
f.write("...")
f.write(b"....
i understand that the code given below will not be compltely understood unless i explain my whole of previous and next lines of code.
But this is part of the code which is causing so much of delay in my project and want to optimize this.
i want to know which code part is faulty and how could this be replaced.
i guess,few can say that use...
When I enter in python in Terminal it loads up Python 2.6.2. However there are folders by the name of Python 2.6 in different places on my drive. I'm not sure if that's because Python 2.6 has been installed in different places or because Python just likes to have lots of folers in different places.
If there are multiple installations, I...
Possible Duplicate:
Flatten (an irregular) list of lists in Python
Hay All.
I have a list which consists of many lists, here is an example
[
[Obj, Obj, Obj, Obj],
[Obj],
[Obj],
[
[Obj,Obj],
[Obj,Obj,Obj]
]
]
Is there a way to join all these items together as 1 list, so the output will be...
Hi,
I have a number of C functions, and I would like to call them from python. cython seems to be the way to go, but I can't really find an example of how exactly this is done. My C function looks like this:
void calculate_daily ( char *db_name, int grid_id, int year,
double *dtmp, double *dtmn, double *dtmx,
...
I am writing an autoconf script for a library that has some Python-based test programs. I am trying to add a conditional in the script that tests for Python devel stuff and turns these tests off or on.
I'm trying to use autoconf archive's AC_PYTHON_DEVEL macro to test for python. I'm calling it like this:
AC_PYTHON_DEVEL([>='2.3'])
...