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...
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...
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.
...
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...
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...
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.?
...
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)
...
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...
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...
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(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:
...
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...
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...
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...
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 ...
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 ...
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, ...
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"?>==; ....
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...
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
...