python

Problem with encoding in Django templates

I'm having problems using {% ifequal s1 "some text" %} to compare strings with extended characters in Django templates. When string s1 contains ascii characters >127, I get exceptions in the template rendering. What am I doing wrong? I'm using UTF-8 coding throughout the rest of application in both the data, templates and Python code wit...

StaticText items disappear in wx.StaticBox

I'm creating a staticbox and a staticboxsizer in a vertical sizer. Everything works fine for me, but not on the customer's environment. Everything in the staticbox is displayed, but labels. snippet below shows how i construct the staticboxsizer. sbox2 = wx.StaticBox(self, wx.ID_ANY, 'CH1 Only') sboxsizer2 = wx.StaticBoxSizer(...

How would you determine where each property and method of a Python class is defined?

Given an instance of some class in Python, it would be useful to be able to determine which line of source code defined each method and property (e.g. to implement [1]). For example, given a module ab.py class A(object): z = 1 q = 2 def y(self): pass def x(self): pass class B(A): q = 4 def x(self): pass def ...

Does anyone have example code of using scipy.stats.distributions?

I am strggling to figure out how to use the scipy.distributions package and wondered if anyone can post some example code for me. It appears to do everything I need, I just can't figure out how to use it. I need to generate two distributions, one log-normal and one poisson. I know the variance and lambda for each. Links to resources ...

Why aren't all the names in dir(x) valid for attribute access?

Why would a coder stuff things into __dict__ that can't be used for attribute access? For example, in my Plone instance, dir(portal) includes index_html, but portal.index_html raises AttributeError. This is also true for the __class__ attribute of Products.ZCatalog.Catalog.mybrains. Is there a good reason why dir() can't be trusted? Pok...

TypeError: can't multiply sequence by non-int of type 'float' - Need help.

salesAmount = raw_input (["Insert sale amount here \n"]) ['Insert sale amount here \n']20.99 >>> salesTax = 0.08 >>> totalAmount = salesAmount * salesTax Traceback (most recent call last): File "<pyshell#57>", line 1, in <module> totalAmount = salesAmount * salesTax TypeError: can't multiply sequence by non-int of type 'float' I...

Python shelve module question

Does the Python shelve module have any protection built in to make sure two processes aren't writing to a file at the same time? ...

Ruby equivalent of virtualenv?

Is there something similar to the Python utility virtualenv? Basically it allows you to install Python packages into a sandboxed environment, so easy_install django doesn't go in your system-wide site-packages directory, it would go in the virtualenv-created directory. For example: $ virtualenv test New python executable in test/bin/p...

How do I specify input and output data types in python comments?

I have seen several standards for writing comments about the kind of data a function expects and returns in Python. Is there a consensus on which one is best-practice? Is the new functionality in http://www.python.org/dev/peps/pep-3107/ something I should start using for this? ...

Reducing Django Memory Usage. Low hanging fruit?

My memory usage increases over time and restarting Django is not kind to users. I am unsure how to go about profiling the memory usage but some tips on how to start measuring would be useful. I have a feeling that there are some simple steps that could produce big gains. Ensuring 'debug' is set to 'False' is an obvious biggie. Can any...

Client Server programming in python?

Here is source code for multithreaed server and client in python. PROBLEM: In the code client and server closes connection after the job is finished. I want to keep the connections alive and send more data over the same connections to avoid overhead of closing and opening sockets everytime. What is the best way to do this? I am new to...

pyqt import problem

Hi, I am having some trouble doing this in Python: from PyQt4 import QtCore, QtGui from dcopext import DCOPClient, DCOPApp The traceback I get is from dcopext import DCOPClient, DCOPApp File "/usr/lib/python2.5/site-packages/dcopext.py", line 35, in <module> from dcop import DCOPClient RuntimeError: the qt and PyQt4.QtCore module...

Transfering object through Pyro

I'm using Pyro in a project, and can't seem to understand how to transfer a complete object over the wire. The object is not distributed (my distributed objects works perfectly fine), but should function as an argument to an already available distributed object. My object is a derived from a custom class containing some methods and som...

Inventory Control Across Multiple Servers .. Ideas?

Hi there, We currently have an inventory management system that was built in-house. It works great, and we are constantly innovating it. This past Fall, we began selling products directly on one of our websites via a Shopping Cart checkout. Our inventory management system runs off a server in the office, while the three websites we c...

How can I get interactive Python to avoid using readline while allowing utf-8 input?

I use a terminal (9term) that does command-line editing itself - programs that use readline just get in its way. It's fully utf-8 aware. How can I make an interactive python session disable readline while retaining utf-8 input and output? Currently I use: LANG=en_GB.UTF-8 export LANG cat | python -i however this causes sys.stdin.enco...

Is there a standard way to list names of Python modules in a package?

Is there a straightforward way to list the names of all modules in a package, without using __all__? For example, given this package: /testpkg /testpkg/__init__.py /testpkg/modulea.py /testpkg/moduleb.py I'm wondering if there is a standard or built-in way to do something like this: >>> package_contents("testpkg") ['modulea', 'modul...

Django: ModelMultipleChoiceField doesn't select initial choices

ModelMultipleChoiceField doesn't select initial choices and I can't make the following fix (link below) work in my example: http://code.djangoproject.com/ticket/5247#comment:6 My models and form: class Company(models.Model): company_name = models.CharField(max_length=200) class Contact(models.Model): company = models.ForeignK...

ZipFile complains, is there a way around using the zipfile module?

Hi, I am trying to decompress some MMS messages sent to me zipped. The problem is that sometimes it works, and others not. And when it doesnt work, the python zipfile module complains and says that it is a bad zip file. But the zipfile decompresses fine using the unix unzip command. This is what ive got zippedfile = open('%stemp/tempf...

How do I make environment variable changes stick in Python?

From what I've read, any changes to the environment variables in a Python instance are only available within that instance, and disappear once the instance is closed. Is there any way to make them stick by committing them to the system? The reason I need to do this is because at the studio where I work, tools like Maya rely heavily on ...

Can a python script persistently change a Windows environment variable? (elegantly)

Following on from my previous question, is it possible to make a Python script which persistently changes a Windows environment variable? Changes to os.environ do not persist once the python interpreter terminates. If I were scripting this on UNIX, I might do something like: set foo=`myscript.py` But alas, cmd.exe does not have anyt...