background preloader

Python Tips, Tricks, and Hacks

Related:  RiggingWiki, BlogpyNils

Syntax - Python ############################################################################## # name: main # purpose: entry point of the script ############################################################################## # sys.argv is a list of command line argument strings (pos 0 is script name) if __name__ == "__main__" : print "hello world" # if no comma (,) at end \n is auto included ############################################################################## # name: main # purpose: show the basic conditionals ############################################################################## # regular c style if statement if (value is not None ) and (value == 1): # is tests for same object print "value equals 1" , print " more can come in this block" # if-else block if (job == "millionaire" ) or (state != "dead" ): # !

Dobrando o Python Com Expressões Regulares - Mind Bending Dando continuidade no assunto de Expressões Regulares , hoje vou mostrar em que casos o uso de uma expressão regular supera (e muito) um trecho (relativamente complexo) de código Python. Expressões Regulares Respirem fundo e vamos lá… Contexto Para este exemplo vou usar um contexto simples: uma aplicação que valida endereços IPs. Abaixo irei mostrar diversos trechos de código, caso você queira testá-los, todos devem ser inseridos em um mesmo arquivo. Entendendo O Código Todo o código está bem comentado e documentado, mas mesmo assim vou explicar alguns trechos para facilitar o entendimento. Vamos ver o “cabeçalho” do nosso programa: #! Neste programa vou utilizar apenas os módulos er ( expressão regular ) e o timeit ( Medidor de tempo de execução ). Após os módulos temos a compilação de uma expressão regular utilizando o método compile do módulo re . Agora vamos ver duas funções utilizadas para decodificar os endereços IP: $ python valida_ip.py Python timing… valida_py : 0.481071233749 Uau!

Python Programming Language – Official Website Hidden features of Python 2.1. Process for Contributing Code — edX Developers Guide documentation Open edX is a massive project, and we would love you to help us build the best online education system in the world – we can’t do it alone! However, the core committers on the project are also developing features and creating pull requests, so we need to balance reviewing time with development time. To help manage our time and keep everyone as happy as possible, we’ve developed this document that explains what core committers and other contributors can expect from each other. The goals are: If you are a contributor submitting a pull request, expect that it will take a few weeks before it can be merged. Follow the guidelines in this document for a high-quality pull request: include a detailed description of your pull request when you open it on Github (we recommend using a pull request cover letter to guide your description), keep the code clear and readable, make sure the tests pass, be responsive to code review comments.

rigging Cartoony eyes in maya? To Iotrez: You say it works quite well most of the time f3rry. Are there any specific situations where this setup doesn't work so well? Yes, When you are streching the whole head up and still having (or going to do) your eyes squint (evil eyes) - squashed - then you are going to see some distortion Is it common to have the eyelids part of the head mesh and not seperate spheres? To do this could you create blendshape targets using the whole head for the blinking, by adjusting the vertices making up the eyelids. Depend what u want to do, for cartoony characters just stick the eyelid with the eyeballs. For realistic character, avoind this. With the BD setup for the eyelid, remember that BS works linear, so you could have some overlapping if the eyes are too buldgy. Creating lattice for the eyes are so common but create jaggy movement when u rotate the eyes around.

PyPy is faster than C, again: string formatting String formatting is probably something you do just about every day in Python, and never think about. It's so easy, just "%d %d" % (i, i) and you're done. No thinking about how to size your result buffer, whether your output has an appropriate NULL byte at the end, or any other details. A C equivalent might be: char x[44]; sprintf(x, "%d %d", i, i); Note that we had to stop for a second and consider how big numbers might get and overestimate the size (44 = length of the biggest number on 64bit (20) + 1 for the sign * 2 + 1 (for the space) + 1 (NUL byte)), it took the authors of this post, fijal and alex, 3 tries to get the math right on this :-) This is fine, except you can't even return x from this function, a more fair comparison might be: char *x = malloc(44 * sizeof(char)); sprintf(x, "%d %d", i, i); x is slightly overallocated in some situations, but that's fine. def main(): for i in xrange(10000000): "%d %d" % (i, i) main() and the C code: Benchmarking the C code: Summary of performance:

Python Python unterstützt mehrere Programmierparadigmen. So werden objektorientierte, aspektorientierte und funktionale Programmierung unterstützt. Wie andere dynamische Sprachen wird Python oft als Skriptsprache genutzt. Die Sprache hat ein offenes, gemeinschaftsbasiertes Entwicklungsmodell, gestützt durch die gemeinnützige Python Software Foundation, die de facto die Definition der Sprache in der Referenzumsetzung CPython pflegt. Python gilt als einfach zu erlernende Sprache, da sie über eine klare und übersichtliche Syntax verfügt. Guido van Rossum 2006 Python ist eine Multiparadigmensprache. Die Datentypen werden dynamisch verwaltet; eine statische Typprüfung (wie z. Python besitzt eine größere Anzahl von grundlegenden Datentypen. Der Zweck solcher Unveränderlichkeit hängt z. zwei Schleifenformen for zur Iteration über die Elemente einer Sequenzwhile zur Wiederholung einer Schleife, solange ein logischer Ausdruck wahr ist.Verzweigungen if … elif … else für Verzweigungen

Online Python Tutor

Related: