python

Python: obtain & manipulate (as integers) bit patterns of floats

In Python V.2.5.4, I have a float, and I'd like to obtain and manipulate (as an integer) the bit pattern of that float. For example, suppose I have x = 173.3125 In IEEE 754 format, x's bit pattern (in hexadecimal) is 432D5000 . How can I obtain & manipulate (e.g., perform bitwise operations) on that bit pattern? ...

Boolean Query..

if: x = 0 b = x==0 and i print be it would print 'true' but if i did: x = 0 b = x ==3 and i printed be it would be false. In stead of it printing false how would i take the boolean value 'b' to print what text i wanted? let me explain further: bool = all(n > 0 for n in list) if bool != 'True': print 'a value is not gr...

Convert string / character to integer in python

I want to convert a single character of a string into an integer, add 2 to it, and then convert it back to a string. Hence, A becomes C, K becomes M, etc. ...

monolithic inheritance vs modular member based OOP design

I'm having a hard time making a design decision I have a class in python, that processing form data, this data is very similar to other form data, and so I'm refactoring it into it's own object so it can be reused by the other classes. The delima is weather to make this formprocessor a member of the classes or a parent of the classes. ...

Get class object __dict__ without special attributes

For getting all the defined class attributes I try to go with TheClass.__dict__ but that also gives me the special attributes. Is there a way to get only the self-defined attributes or do I have to "clean" the dict myself? ...

Eric4 dark theme stylesheet

Does anyone use Eric4 and has taken the time to create a dark themed stylesheet (.qss or .css)? Surely, not everyone uses the default theme. I wish Eric4 made this easier to configure through their preferences settings. Thanks! ...

How should I build this Django model to do what I want

This is what I had before (but realized that you can't obviously do it in this order: class MasterAdmin(models.Model): """ A permanent admin (one per Account) that shouldn't be deleted. """ admin = models.OneToOneField(AccountAdmin) class Account(models.Model): """ A top-level account in the system. """ ...

How do I customize formish error messages?

I'm using formish to handle web forms but I don't like the automatically generated error messages when validation fails. Where do I customize those error messages? ...

Multiprocessing launching too many instances of Python VM

I am writing some multiprocessing code (Python 2.6.4, WinXP) that spawns processes to run background tasks. In playing around with some trivial examples, I am running into an issue where my code just continuously spawns new processes, even though I only tell it to spawn a fixed number. The program itself runs fine, but if I look in Win...

How to make paramiko wait for transfer to finish?

I've tried various ways to upload a file locally to a FTP, ncftpput was really slow compared to lftp so I switched. but what I've noticed is my python script waits for ncftpput to finish but when using lftp, it just uploads the file to the FTP and it continues on with the script.. I am using paramiko to SSH into my web server and uploa...

Django: How do I validate unique_together from within the model

I have the following: class AccountAdmin(models.Model): account = models.ForeignKey(Account) is_master = models.BooleanField() name = models.CharField(max_length=255) email = models.EmailField() class Meta: unique_together = (('Account', 'is_master'), ('Account', 'username'),) If I then create a new Accou...

suggestion required related to rewriting and string manipulation

Hi everyone , I had to read from a file and for each data between delimiter i need to remove the white space and i have written the following program in jython When i am trying to rewrite ,its rewriting at the end of source file. filesrc = open('c:/FILE/split_doc.txt','r+') for list in filesrc.readlines(): #split the records by...

Python lambdas and scoping

Given this snippet of code: funcs = [] for x in range(3): funcs.append(lambda: x) print [f() for f in funcs] I would expect it to print [0, 1, 2], but instead it prints [2, 2, 2]. Is there something fundamental I'm missing about how lambdas work with scope? ...

Couple of matplotlib newbie doubts

I am just starting to use 'matplotlib' and I have hit upon 2 major roadblocks, which I can't seem to work around from the docs/examples,etc: Here is Python source: #!/usr/bin/python import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt for i in range(0,301): print "Plotting",i # Reading a single column data ...

hedge funds / financial services: caml. why?

speaking to a number of quants / hedgies, i came to the conclusion that a large number of them seem to be using their a homebrew or caml (for the most part). what many of them couldnt answer was why. i can certainly understand why they wouldnt want to use c++ for the most part, but why is caml superior for these uses compared to other s...

Inheritable custom exceptions in python

Hi, I want to create some custom exceptions for my class. I am trying to figure out the best way to make these exception classes inheritable in derived classes. The tutorial shows how to create the Exception classes. So I did that like this: I created a baseclass.py: class Error(Exception): """Base class for exceptions in BaseC...

define a list with type

Hi, I come from Java and I wanna do some Data Transfer Objects like this: class ErrorDefinition(): code = '' message = '' exception = '' class ResponseDTO(): sucess = True errors = list() # how to say it that is directly of ErrorDefinition() type, to not import it every time that im going to append a Error def. or...

Linux USB Mapping Question

Hi, I'm working on a utility that will auto mount an inserted USB stick on linux. I have tied into D-Bus to receive notification of when a device is inserted, and that works great. However, I need to determine which device in /dev is mapped to the inserted USB stick. I am getting the D-Bus notification and then scanning the USB system w...

Use <optgroup> with form.fields.queryset?

Is it possible to set a form's ForeignKey field's queryset so that it will take separate queryset's and output them in <optgroup>'s? Here is what I have: views.py form = TemplateFormBasic(initial={'template': digest.template.id}) form.fields['template'].queryset = Template.objects.filter(Q(default=1) | Q(user=request.user)).order_by('...

get datatype length in python by parsing a string

I have strings like uint8_t char[5] int[3] How can I write a short function to get the type and length separately in an elegant way for eg uint8_t // return 'uint8_t', '1' char[5] // return 'char', '5' ... ...