python

Read python dictionary using c++

Hi I have a python dictionary stored in a file which I need to access from a c++ program. What is the best way of doing this? Thanks ...

TkInter, slider: how to trigger the event only when the iteraction is complete ?

I'm using the slider to update my visualization, but the command updateValue is sent everytime I move the slider thumb, even for intermediate values. Instead I want to trigger it only when I release the mouse button and the interaction is complete. self.slider = tk.Scale(self.leftFrame, from_=0, to=256, orient=tk.HORIZONTAL, command=up...

TKInter, geometryManagers: grid() and pack()

What's the main difference between the 2 GeometryManagers in TKinter, grid() and pack() what do you use for your projects ? If grid is better to align object, what the main purpose of pack? thanks ...

TKinter: AttributeError: 'NoneType' object has no attribute 'tk' !?

What does this error message mean ? AttributeError: 'NoneType' object has no attribute 'tk' thanks ...

django-piston : Overriding default serialization in emitters

Hi ! I am currently writing an API for a django project, and using django-piston for this. However, I need to customize the way certain base types are serialized. More precisely, my models are subclassed from a special Model class, which inherits from django.db.models.base.ModelBase, but cannot be serialized as regular django models .....

Web interface to a Python script, with "streaming text"

I have a Python command-line script that can take some time to run (from 5 seconds to 5 minutes), depending on the checks it does. The script uses many command-line arguments, some mandatory, most optional. I'd like to "webify" this script, making it possible to access it from a Web browser, but without changing the core python script, ...

How to simulate POST arguments in python

I'm trying to simulate some data in to the datastore to emulate POSTs. What I'm looking for is a way to post named arguments but as one argument. So I can use the same method as a normal POST would do. The method I want to invoke get params in two ways. def HandlePost(params): params.get('name') params.get_all('collection') ...

cp -r from_dir/* to_dir with python

Is there an easy way to emulate the command cp -r from_dir/* to_dir with python? shutil.copytree is not suitable because to_dir exists. ...

How to determine when input is alphabetic?

I been trying to solve this one for a while and can't seem to make it work right.. here is my current work while True: guess = int(raw_input('What is your number?')) if 100 < guess or guess < 1: print '\ninvalid' else: .....continue on Right now I have made it so when a user input a number higher than 1...

Cycling a binary file in Python - Remove from beginning add to end

Could anyone point me towards a method of cycling a binary file in Python? I have a file full of 4 byte integers basically and when the file reaches a certain size, i.e. a certain number of values have been written, I want to start removing one from the start and adding one at the end. I'm still reasonably new to Python, so just trying ...

How to add text below gif image in python using PIL or image magick?

Hello Friends, I have one gif image. I want to add text(IMAGE NAME) to below image and save as new one. f = open("c://temp.gif", 'a') s = f.write(imagename) f.close() Above code work for text file but not for gif Can you help me for this? Thanks, manu ...

python regex question

I want to match certain symbols only when they are not prefixed by specific characters. For instance, match "))))))))))" when it is not preceded by "x". Need some advices. My current expession is (?<!x|X|:|=|\\1)([\|()\[\]])+ which does not work. [EDIT] Rephrase my question ...

What's the meaning of '_' in python?

When reading source code of Django, I find some statements: class Field(object): """Base class for all field types""" __metaclass__ = LegacyConnection # Generic field type description, usually overriden by subclasses def _description(self): return _(u'Field of type: %(field_type)s') % { 'fiel...

download a folder of files given the http url of the files directory with python

Possible Duplicate: Looping through a directory on the web and displaying its contents (files and other directories) via Python hi, Guys, If I have code files under http://AAA/BBB/tags/revision/ how can I download these files in python? and If they have 600M in total, is there some efficient way to do it? ...

Reading text from an image.

Hi all, Is there a way we can read the alphabets from an image, some kind of text recognition method using python. What I have to do is, read some images to get the text written on them. Please suggest. ...

How to optimize operations on large (75,000 items) sets of booleans in Python?

There's this script called svnmerge.py that I'm trying to tweak and optimize a bit. I'm completely new to Python though, so it's not easy. The current problem seems to be related to a class called RevisionSet in the script. In essence what it does is create a large hashtable(?) of integer-keyed boolean values. In the worst case - one fo...

Django Order By Generic Foreign Key

Hey, this is a quick one. I have two models, Post and Term and I'd like to be able to tag and categorize (taxonomy) posts as well as other (future) models. My Post model has the following fields: title, content, published (date) and my Term is declared like this: class Term(models.Model): taxonomy = models.CharField(max_length=255) ...

How to pass empty argument to Popen (with shell=False)?

I have external script (sh), i would like to do something like this: arg1 = 'some string' arg2 = 'some string2' arg3 = '' cmd = ['/usr/local/bin/myscript', 'arg1', 'arg2', 'arg3'] Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE) I seems, that if "arg3" is empty, my script i called only with two arguments, how can I pass ...

TKinter: how to change Frame width dynamically

how can I set width to a tk.Frame (post-initialization ?) In other words, is there a member function to do it ? Sometheing like frame.setWidth() thanks ...

How can I move my Python2.6 site-packeges into Python2.7?

I just ran an update on ArchLinux which gave me Python3 and Python2.7. Before this update, I was using Python2.6. The modules I have installed reside in /usr/lib/python2.6/site-package. I now want to use Python2.7 and remove Python2.6. How can I move my Python2.6 modules into Python2.7 ? Is it as simple as doing mv /usr/lib/python2.6/...