python

commit & push to remote git repo via webhook?

I want to commit to a git repo from app-engine via webhooks. I cannot install git on appengine. Possible? I think it should be on GitHub, because they have a browser based text editor which can commit via the browser. E.g. go here and click the edit button. GitHub api docs imply read-only operations which doesn't seem to be true. Also...

why my code error,I would like to print the parameters of two functions.

def c(*x,**y): print x,y def a(*x,**y): print x def b(*x1,**y1): c(*(x+x1),**dict(y,**y1)) b() a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')#error thanks ...

Call Method on Every Ancestor in Python

I have an object of class 'D' in python, and I want to sequentially execute the 'run' method as defined by 'D' and each of it's ancestors ('A', 'B' and 'C'). I'm able to accomplish this like this class A(object): def run_all(self): # I prefer to execute in revere MRO order for cls in reversed(self.__class__.__mro__)...

My own OCR-program in Python

Hello everybody! I am still a beginner but I want to write a character-recognition-program. This program isn't ready yet. And I edited a lot, therefor the comments may not match exactly. I will use the 8-connectivity for the connected component labeling. from PIL import Image import numpy as np im = Image.open("D:\\Python26\\PYTHON-PRO...

what is the 'self.__class__.__missing__' mean .

in pinax Userdict.py: def __getitem__(self, key): if key in self.data: return self.data[key] if hasattr(self.__class__, "__missing__"): return self.__class__.__missing__(self, key) why does it do this on self.__class__.__missing__. thanks ...

is '__all__' only for 'from some import *'.

a.py __all__=['b','c'] a='aaa' b='bbb' def c(): print 'ccc' def d(): print 'dddd' b.py from a import a print a from a import * print a print d#error Are there any other uses. thanks ...

What does this code from types.py do?

try: raise TypeError except TypeError: try: tb = sys.exc_info()[2] TracebackType = type(tb) FrameType = type(tb.tb_frame) except AttributeError: # In the restricted environment, exc_info returns (None, None, # None) Then, tb.tb_frame gives an attribute error pass tb = None; ...

[python] RSA encryption

I am doing on my project and there is about port knocking. I have 3 files that separated in server side and client. In the server contains : portknocking server as a daemon and configuration file [contains sequence of port that must be satisfied and many other configuration detail] In the client contains : portknocking client. Is there ...

Nesting 'WITH' statements in Python

Turns out with is a funny word to search for on the internet. Does anyone knows what the deal is with nesting with statements in python? I've been tracking down a very slippery bug in a script I've been writing and I suspect that it's because I'm doing this: with open(file1) as fsock1: with open(file2, 'a') as fsock2: fstri...

Django: signal when user logs in ?

In my Django app, I need to start running a few periodic background jobs when a user logs in and stop running them when the user logs out, so I am looking for an elegant way to get notified of a user login/logout query user login status From my perspective, the ideal solution would be a signal sent by each django.contrib.auth.views...

How can I schedule a Task to execute at a specific time using celery?

I've looked into PeriodicTask, but the examples only cover making it recur. I'm looking for something more like cron's ability to say "execute this task every Monday at 1 a.m." ...

Tkinter help viewer

I have a simple Tkinter app in Python. I'd like to add help document to it; what is the simplest way to integrate an help viewer to the app? Preferably cross-platform (although I primarily use Windows)? I can imagine writing the help in plain HTML. ...

How to get Python error as C string?

I have a C++ application that embeds the Python interpreter. It calls PyImport_Import to load scripts. I need a way of getting any syntax errors as C strings. For example, if the script uses a undefined function, I would like an error saying something like 'Function xxx is undefined.' How would I do this? ...

Why does this code return 'complex'?

# Example: provide pickling support for complex numbers. try: complex except NameError: pass else: def pickle_complex(c): return complex, (c.real, c.imag) # why return complex here? pickle(complex, pickle_complex, complex) Why? The following code is the pickle function being called: dispatch_table = {} def ...

Python Hierarchical QcomboBox: clean-up list

Hi Everybody, I have a hierarchical two combo-box. The first combo-box displays a list of customerNames, i.e. different companies from a MySQL db. Each customer has branches in different cities. Then, when a customer name is chosen from combo-box1 option list, e.g. {Aldi, Meyer, Carrefour, WalMart}, for that particular customer, a list...

In Python, what does dict.pop(a,b) mean?

class a(object): data={'a':'aaa','b':'bbb','c':'ccc'} def pop(self, key, *args): return self.data.pop(key, *args)#what is this mean. b=a() print b.pop('a',{'b':'bbb'}) print b.data self.data.pop(key, *args) ------ why is there a second argument? ...

Why does my class not have a 'keys' function?

class a(object): w='www' def __init__(self): for i in self.keys(): print i def __iter__(self): for k in self.keys(): yield k a() # why is there an error here? Thanks. Edit: The following class also doesn't extend any class; why it can use keys? class DictMixin: # Mi...

Abort HTMLParser processing in Python

When using the HTMLParser class in Python, is it possible to abort processing within a handle_* function? Early in the processing, I get all the data I need, so it seems like a waste to continue processing. There's an example below of extracting the meta description for a document. from HTMLParser import HTMLParser class MyParser(HTMLP...

Convert a curl POST request to Python only using standard libary

I would like to convert this curl command to something that I can use in Python for an existing script. curl -u 7898678:X -H 'Content-Type: application/json' \ -d '{"message":{"body":"TEXT"}}' http://sample.com/36576/speak.json TEXT is what i would like to replace with a message generated by the rest of the script.(Which is already w...

Sorting problem with the Google App Engine

I am using the following class to store some data: class NewsArticle(db.Model): score = db.FloatProperty(default=0.0) date_scored = db.DateTimeProperty() ... What I need to do is to get those NewsArticle entities that have the top score in some time frame (e.g. get the top scored data entities of today or of last week). I...