python-2.6

Can Python's list comprehensions (ideally) do the equivalent of 'count(*)...group by...' in SQL?

I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count? (I've defined an __eq__ to define uniqueness on my object definition). So in RDBMS-land, something like this: CREATE TABLE x(n NUMBER(1)); INSERT INTO x VALUES(1...

Python win32com: Excel set chart type to Line

This VBA macro works: Sub Draw_Graph() Columns("A:B").Select ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=ActiveSheet.Range("$A:$B") ActiveChart.ChartType = xlLine End Sub This Python (near) Equivalent almost works: from win32com import client excel=client.Dispatch("Excel.Application") excel.V...

How do I prevent my Python 2.6 application from automatically closing once reaching the end of code?

Hello. I'm new to programming, especially Python. I'm trying to make an application that convert Fahrenheit to Celsius, but I don't know how to make the program stay open. Whenever it reaches the end of the code, it automatically closes before the user can see his or her results. Help, please? I'm using Python 2.6. ...

importing files in python

I have that file structure- Blog\DataObjects\User.py Blog\index.py I want to import the function(say_hello) at User.py from index.py. I am trying this code - from Blog.DataObjects.User import say_hello say_hello() And I have that error - Traceback (most recent call last): File "index.py", line 1, in <module> from Blog.Da...

Python try...except comma vs 'as' in except

What is the difference between ',' and 'as' in except statements, eg: try: pass except Exception, exception: pass and: try: pass except Exception as exception: pass Is the second syntax legal in 2.6? It works in CPython 2.6 on Windows but the 2.5 interpreter in cygwin complains that it is invalid. If they are both...

How can get Python isidentifer() functionality in Python 2.6?

Python 3 has a string method called str.isidentifier How can I get similar functionality in Python 2.6, short of rewriting my own regex, etc.? ...

How to install python2.6-devel package under CentOs 5

I need to install mysql-python under python2.6. mysql-python package needs python2.6-devel package that depends on the libpython2.6.so.1.0(64bit) I found on the net some python2.6-devel packages, but can't find libpython2.6 Server architecture is x86_64. Maybe someone have this lib, or know where i can find it. Thanks for help) ...

fd.seek() IOError: [Errno 22] Invalid argument

My Python Interpreter (v2.6.5) raises the above error in the following codepart: fd = open("some_filename", "r") fd.seek(-2, os.SEEK_END) #same happens if you exchange the second arg. w/ 2 data=fd.read(2); last call is fd.seek() Traceback (most recent call last): File "bot.py", line 250, in <module> fd.seek(iterator, os.S...

Is there a way to accept '%' as part of input that works both in python 2.6 & 3.0?

In 2.6, if I needed to accept input that allowed a percent sign (such as "foo % bar"), I used raw_input() which worked as expected. In 3.0, input() accomplishes that same (with raw_input() having left the building). As an exercise, I'm hoping that I can have a backward-compatible version that will work with both 2.6 and 3.0. When I us...

Help with cPickle in Python 2.6

I tried the following code I python. This is my first attempt at pickling. import Tkinter import cPickle root = Tkinter.Tk() root.sclX = Tkinter.Scale(root, from_=0, to=1500, orient='horizontal', resolution=1) root.sclX.pack(ipadx=75) root.resizable(False,False) root.title('Scale') with open('myconfig.pk', 'wb') as f: cPick...

inspect.getmembers in order?

inspect.getmembers(object[, predicate]) Return all the members of an object in a list of (name, value) pairs sorted by name. I want to use this method, but I don't want the members to be sorted. I want them returned in the same order they were defined. Is there an alternative to this method? Use case: Creating a form like so: ...

Dynamically add base class?

Let's say I have a base class defined as follows: class Form(object): class Meta: model = None method = 'POST' Now a developer comes a long and defines his subclass like: class SubForm(Form): class Meta: model = 'User' Now suddenly the method attribute is lost. How can I "get it back" without forcing...

Is it possible, and/or advisable to develop Django web applications on OS X (10.6.4 and 10.5.8) using Python 2.6.5 64-bit? Why?

I'm trying to decide on which architecture to choose for developing Django 1.0.x through Django 1.2.1. I've managed to get MySQL, MySQLdb, PIL, and Python 2.65 installed on Snow Leopard using x86 64-bit builds, but I'm curious as to whether or not there is a definitive answer to this question at the moment, and if so, why? Thank you! Mi...

Edit .RAR file comments from python

Ok, I need to be able to edit the file comments in .rar files from python. I can already view the comments using UnRAR. However, I need to embed metadata in the files in a way that is preserved over multiple file systems (e.g. alternate datastreams are out), so I can't really think of any other alternatives. rarfile seems like it might...

Handling large dense matrices in python.

Basically, what is the best way to go about storing and using dense matrices in python? I have a project that generates similarity metrics between every item in an array. Each item is a custom class, and stores a pointer to the other class and a number representing it's "closeness" to that class. Right now, it works brilliantly up to ...

Python 2.6: containment hierarchy issue: Same Values :S

Hey Everyone, If you've seen my previous post you'll know im working on an airline program using Python. Another issue that poped up was that after I launch one flight, it calculates the duration of the flight and replaces the button which is used to launch the flight. But when I buy another aircraft, it changes both flight statuses to ...

Remove whitespaces in XML string

How can I remove the whitespaces and line breaks in an XML string in Python 2.6? I tried the following packages: etree: This snippet keeps the original whitespaces: xmlStr = '''<root> <head></head> <content></content> </root>''' xmlElement = xml.etree.ElementTree.XML(xmlStr) xmlStr = xml.etree.ElementTree.tostring(xmlElement, ...

How to validate an xml file against an XSD Schema using Amara library in Python?

High bounty for the following Q: Hello, Here is what I tried on Ubuntu 9.10 using Python 2.6, Amara2 (by the way, test.xsd was created using xml2xsd tool): g@spot:~$ cat test.xml; echo =====o=====; cat test.xsd; echo ==== o=====; cat test.py; echo =====o=====; ./test.py; echo =====o===== <?xml version="1.0" encoding="utf-8"?>==; ....

How can I replace a Python 2.65 UCS-2 build with one built using UCS-4 without losing everything in my site-packages?

I downloaded the Python 2.6.5 source, built it for OS 10.6.4 64-bit, and installed numerous dependencies. I opened a big project our team has been working on recently, ran the unit tests, and one of the tests failed because I had installed Python built using UCS-2 (I didn't know this was the default of OS X!) In a nutshell: I didn't sup...

is there a difference between class(): and class(object): in python 2.6-3.x?

Before py2.6 it's been answered here. http://stackoverflow.com/questions/332255/difference-between-class-foo-and-class-fooobject-in-python But for python2.6+ and python3.x, is the first one wrong? class Foo(): pass vs class Foo(object): pass ...