Hello,
I receive a dictionary as input, and would like to to return a dictionary whose keys will be the input's values and whose value will be the corresponding input keys. Values are unique.
For example, say my input is:
a = dict()
a['one']=1
a['two']=2
I would like my output to be:
{1: 'one', 2: 'two'}
To clarify I would like m...
I have a wx.Frame, in which there is a main wx.Panel with several widgets inside of it. I want one button in there to cause a "help panel" to come up. This help panel would probably be a wx.Panel, and I want it to overlay the entire main wx.Panel (not including the menu bar of the wx.Frame). There should be some sort of close button on t...
Hello,
I receive a dictionary as input, and want to return a list of keys for which the dictionary values are unique in the scope of that dictionary.
I will clarify with an example. Say my input is dictionary a, constructed as follows:
a = dict()
a['cat'] = 1
a['fish'] = 1
a['dog'] = 2 # <-- unique
a['bat'] = 3
a['...
I was wondering if there exists a sort of Python beautifier like the gnu-indent command line tool for C code. Of course indentation is not the point in Python since it is programmer's responsibility but I wish to get my code written in a perfectly homogenous way, taking care particularly of having always identical blank space between ope...
I'm looking for a simple method to check if only one variable in a list of variables has a True value.
I've looked at this logical xor post and is trying to find a way to adapt to multiple variables and only one true.
Example
>>>TrueXor(1,0,0)
True
>>>TrueXor(0,0,1)
True
>>>TrueXor(1,1,0)
False
>>>TrueXor(0,0,0,0,0)
False
...
Hello, I have started to learn python recently and have a question about for loops that I was
hoping someone could answer. I want to be able to print all the possible products of two numbers from one to ten. so: 2 by 2, 2 by 3, 2 by 4...2 by 10, 3 by 2, 3 by 3...3 by 10, 4 by 2, 4 by 3 etc...I would have thought the easiest way to do so ...
Hey Guys,
I'm trying to dump a list of all active threads including the current stack of each. I can get a list of all threads using threading.enumerate(), but i can't figure out a way to get to the stack from there.
Background: A Zope/Plone app freaks out from time to time, consuming 100% of cpu and needs to be restarted. I have a fe...
Requirements:
I have a python project which parses data feeds from multiple sources in varying formats (Atom, valid XML, invalid XML, csv, almost-garbage, etc...) and inserts the resulting data into a database. The catch is the information required to parse each of the feeds must also be stored in the database.
Current solution:
My prev...
I want to create a decorator that allows me to refer back to the decorated object and grab another decorator from it, the same way you can use setter/deleter on properties:
@property
def x(self):
return self._x
@x.setter
def x(self, y):
self._x = y
Specifically, I'd like it to act basically the same as property, but emulate a...
I am having trouble building a Python function that launches TkInter objects, with commands bound to menu buttons, using button specifications held in a dictionary.
SITUATION
I am building a GUI in Python using TkInter. I have written a Display class (based on the GuiMaker class in Lutz, "Programming Python") that should provide a win...
Hey everyone,
I got a simple problem in SQLAlchemy. I have one model in a table, lets call it Model1 here.
I want to add a row in this table, and get the autoincremented key, so I can create another model with it, and use this key. This is not a flawed database design (1:1 relation etc). I simply need this key in another table, because ...
Which version of Python is recommended for Pylons, and why?
...
What is the most cross platform way of removing bad path characters (e.g. "\" or ":" on Windows) in Python?
Solution
Because there seems to be no ideal solution I decided to be relatively restrictive and did use the following code:
def remove(value, deletechars):
for c in deletechars:
value = value.replace(c,'')
return...
I am trying to save myself a bit of typing by writing the following code, but it seems I can't do this:
class lgrAdminObject(admin.ModelAdmin):
fields = ["title","owner"]
list_display = ["title","origin","approved", "sendToFrames"]
class Photos(lgrAdminObject):
fields.extend(["albums"])
why doesn't that work? Also since t...
How do I put off attribute access in Python?
Let's assume we have:
def foo():
...
class Bar:
...
bar = Bar()
Is it possible to implement Bar so that any time bar is accessed, a value returned by the callback foo() would be provided?
bar name already exists in the context. That's why it's access semantic...
There many levels for the customization of programs.
First of course is making it speak your language by creating i18n messages where tools like gettext and xgettext do a great job.
Another comes when you need to modify the meaning of some messages to suite the purpose of your project.
The question is: is it possible to keep customize...
The simplest way to deal with python package installations, so far, to me, has been to check out the source from the source control system and then add a symbolic link in the python dist-packages folder.
Clearly since source control provides the complete control to downgrade, upgrade to any branch, tag, it works very well.
Is there a w...
I'm making a Django web-app which allows a user to build up a set of changes over a series of GETs/POSTs before committing them to the database (or reverting) with a final POST. I have to keep the updates isolated from any concurrent database users until they are confirmed (this is a configuration front-end), ruling out committing after ...
I have a table that's created like this:
CREATE TABLE bin_test
(id INTEGER PRIMARY KEY, b BLOB)
Using Python and cx_Oracle, if I do this:
value = "\xff\x00\xff\x00" #The string represented in hex by ff00ff00
self.connection.execute("INSERT INTO bin_test (b) VALUES (rawtohex(?))",
(value,))
self.connection.exec...
Hello,
i have an issue i could use some help with, i have python list that looks like this:
fail = [
['da39a3ee5e6b4b0d3255bfef95601890afd80709', 'ron\\b\\include', 'Test.java']
['b5cc17d3a35877ca8b76f0b2e07497039c250696', 'ron\\c', 'apa1.txt']
['95d1543adea47e88923c3d4ad56e9f65c2b40c76', 'ron\\c', 'knark.txt']
['da39a3ee5e6b4b0d3255bf...