python

Using win32service module with IronPython

Hey,so I'm trying to take an existing IronPython script I have and convert it into a windows service that runs on one of our servers at all times. Unfortunately I can't seem to get the modules I need. I downloaded the pywin32 extensions (http://sourceforge.net/projects/pywin32/) but I can't install them because I only have IronPython ins...

Mutagen's OggFileType producing 'Type Error: NoneType' exception

Ive just started using mutagen and have succefully used it with m4a, mp3, ape, afs, and flac. However Im having difficulty with the OggFileType class, when I try to create an instance of OggFileType Im presented with a "TypeError: 'NoneType' object is not callable" exception. Iv searched and searched for solutions but information and do...

Python: Help with new line character

I read in a text file that is tab delimited, i then have a list for each line, i then index out the first entry of each list, i then write this to a file. code below: import csv z = csv.reader(open('output.blast'), delimiter='\t') k = open('output.fasta', 'w') for row in z: print row[1:12] for i in row[1:12]: k.write(i+'...

Using IPMI inside a python script (OpenIPMI)

Hi, I'd like to use IPMI to set a machine to PXE boot (i.e. ipmitool -I lan -U username -P password -H ipaddress chassis bootdev pxe) and then power cycle it (i.e. ipmitool -I lan -U username -P password -H ipaddress chassis power cycle). However, I'd like to do this in a python script so I'm trying to use OpenIPMI and its python bindin...

Is there a way to get python's nose module to work the same in __main__ and on the command line?

Hello, I'm not sure of how to get the nose module's __main__ handler to work. I have this at the end of my test module: if __name__ == "__main__": import nose nose.main() Which gives me: ---------------------------------------------------------------------- Ran 0 tests in 0.002s OK but it I run the same thing via the comm...

Python regex confused by brackets ([])?

Is python confused, or is the programmer? I've got a lot of lines of this: some_dict[0x2a] = blah some_dict[0xab] = blah, blah What I'd like to do is to convert the hex codes into all uppercase to look like this: some_dict[0x2A] = blah some_dict[0xAB] = blah, blah So I decided to call in the regular expressions. Normally, I'd jus...

Python Progress Bar

Hi everyone! How do I use a progress bar when my script is doing some task that is likely to take time? For example, a function which takes some time to complete and returns True when done. How can I display a progress bar during the time the function is being executed? Note that I need this to be in real time, so I can't figure out w...

Removing backslashes from a string in Python

How do I remove all the backslashes from a string in Python? This is not working for me: result = result.replace("\\", result) Do I need to treat result as a raw string? ...

How to model this in django (inherited model, where each inherited model has a unique method)

How to model this in django: 1) have a base network of manufacturers 2) under each network their might be several distributors 3) a user of the system can access items through the distributor 4) if a user access the item through the distributor we want that item to be translated where each manufacturer will have their own translation...

string or list substitution in Python

hi all... how would I go about taking a string ("h1", "h2", "h3, "h4") And substituting these values with numbers 1, 2, 3, 4? Correspondingly, how I would I preform the same operation but on a list instead? Thanks in advance... ...

Django order_by sum of fields

Is it possible to use the django ORM to order a queryset by the sum of two different fields? For example, I have a model that looks like this: class Component(models.Model): material_cost = CostField() labor_cost = CostField() and I want to do something like this: component = Component.objects.order_by(F('material_cost') + F...

Accessing outer class methods from an inner class

I want a python class that has a nested class where the inner class can access the members of the outer class. I understand that normal nesting doesn't even require that the outer class has an instance. I have some code that seems to generate the results I desire and I want feedback on style and unforeseen complications Code: class A()...

None value returned

The code below is used in a function: def print_query(x): h = open('/home/rv/data.txt', 'r') read = h.readlines() for line in read: return line When the value "line" is retunred it should print but instead i get the value "None" ...

Running Python scripts on a server?

How would I run a python script on my site? I wrote a script that takes values (the values should come from a form that the end user fills out) and then returns a string. What would I need to add to the submit form to make the script run with the values? Is this possible or should I be using PHP? (The script involved web scraping, so ...

Python encoding function can't be decoded

I wrote this python code in an attempt to convert objects to a string of ones and zeros, but the decoding fails because the data can't be unpickled. This is the code: def encode(obj): 'convert an object to ones and zeros' def tobin(str): rstr = '' for f in str: if f == "0": rstr += "0000" ...

How do i print the script line number in IronPython?

I am running an IronPython script inside a c# application, i am catching exceptions within the script and i wish to find out the script line at which the exception is thrown. This has to be done while the script is running ie. i do not wish the script to terminate in order to print the exception. Is this even possible? ...

How to transform a key pressed into a different one in pygtk

I'm trying to make my pygtk application behave the way openoffice calc does, regarding the decimal point. This means that when receiving a KP_Decimal key (the dot in the keypad) I want my entries to show whatever the decimal point is in the current locale (dot or comma, appropriately). I've searched for a long while now, and I haven't ...

adding a trailing comma to a print command makes threads executions "serialized"

without dumping tones of code here is the symptom having a threads which all run various methods of the same type of object. within the methods i have a print line which reads: print self.args, self.foo everything works just fine. However, if i turn that line into: # remain in the same line print self.args, self.foo, execution is...

Retain formatting

Im using a function to return a text file that is tab delimited and read in, the format of the text file is: 1_0 NP_250397 100.00 140 0 0 1 140 1 140 6e-54 198 1_0 NP_250378 60.00 140 0 0 1 140 1 140 6e-54 198 1_0 NP_257777 ...

PyQt4 dropdownlist with actions

Hi, I want to create a drop down list in PyQt4, that executes an action when an element is selected. Also, some options may not be available at some time. They should still be in the list, but greyed out. I tried attaching a menu to a QToolButton, but I can not even see the menu. How is it done? Thanks! Nathan ...