python Programming Glossary: functions
What is a metaclass in Python? http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python is an object in Python. That includes ints strings functions and classes. All of them are objects. And all of them have been.. class Why would you use metaclasses classes instead of functions Since __metaclass__ can accept any callable why would you use..
Fastest way to list all primes below N in python http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python pos prime lastadded stop 0 0 0 int ceil sqrt N # inner functions definition def del_mult tk start step for k in xrange start.. k in xrange start len tk step tk k False # end of inner functions definition cpos const pos while prime stop # 30k 7 if tk7 pos..
Flatten (an irregular) list of lists in Python http://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python list share improve this question Using generator functions can make your example a little easier to read and probably boost..
The Python yield keyword explained http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained your best friend The itertools module contains special functions to manipulate iterables. Ever wish to duplicate a generator..
Lexical closures in Python http://stackoverflow.com/questions/233673/lexical-closures-in-python Python is actually behaving as defined. Three separate functions are created but they each have the closure of the environment.. This will force different environments for each of the functions created with a different i in each one. flist for i in xrange..
Python 'self' explained http://stackoverflow.com/questions/2709821/python-self-explained is called on. That makes methods entirely the same as functions and leaves the actual name to use up to you although self is..
Short Description of Python Scoping Rules http://stackoverflow.com/questions/291978/short-description-of-python-scoping-rules function spam is passed somewhere else. And maybe lambda functions pass a bit differently There must be a simple reference or algorithm.. locals. Name in the local scope of any and all enclosing functions def or lambda form inner to outer. G. Global module . Names.. in the current def. E Enclosed function any enclosing functions if def spam was in another def G Global. Were there any declared..
Is there a simple, elegant way to define Singletons in Python? [closed] http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python question I don't really see the need as a module with functions and not a class would serve well as a singleton. All its variables..
What does ** (double star) and * (star) do for python parameters? http://stackoverflow.com/questions/36901/what-does-double-star-and-star-do-for-python-parameters a common idiom to allow arbitrary number of arguments to functions as described in the section more on defining functions in the.. to functions as described in the section more on defining functions in the Python documentation. The args will give you all function..
Python variable scope question http://stackoverflow.com/questions/370357/python-variable-scope-question share improve this question Python treats variables in functions differently depending on whether you assign values to them from..
What does `if __name__ == “__main__”:` do? http://stackoverflow.com/questions/419163/what-does-if-name-main-do someone just wants to import your module and call your functions themselves. See this page for some extra details. share improve..
Using global variables in a function other than the one that created them http://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them this question You can use a global variable in other functions by declaring it as global in each function that assigns to it..
Good Python modules for fuzzy string comparison? http://stackoverflow.com/questions/682367/good-python-modules-for-fuzzy-string-comparison The Levenshtein Python C extension module contains functions for fast computation of Levenshtein edit distance and edit operations..
Calling an external command in Python http://stackoverflow.com/questions/89228/calling-an-external-command-in-python docs.python.org library subprocess.html#replacing older functions with the subprocess module For quick dirty one time scripts..
Adding a Method to an Existing Object http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object this question In Python there is a difference between functions and bound methods. def foo ... print foo ... class A ... def..
Restricting Python's syntax to execute user code safely. Is this a safe approach? http://stackoverflow.com/questions/10661079/restricting-pythons-syntax-to-execute-user-code-safely-is-this-a-safe-approach syntax by traversing Python's abstract syntax tree. Functions and names get special treatment only explicitly whitelisted..
Sorting lists in python http://stackoverflow.com/questions/11732133/sorting-lists-in-python
Looking for File Traversal Functions in Python that are Like Java's http://stackoverflow.com/questions/140758/looking-for-file-traversal-functions-in-python-that-are-like-javas for File Traversal Functions in Python that are Like Java's In Java you can do File.listFiles..
What's the canonical way to check for type in python? http://stackoverflow.com/questions/152580/whats-the-canonical-way-to-check-for-type-in-python type o str type o in str str.__subclasses__ See Built in Functions in the Python Library Reference for relevant information. One..
How to share data between two classes http://stackoverflow.com/questions/15317637/how-to-share-data-between-two-classes the GUI class. I asked a similar question How to Access Functions from Methods in Python which was never satisfactorily answered...
Python optional parameters http://stackoverflow.com/questions/1585247/python-optional-parameters how default values work in order to use them effectively. Functions are objects. As such they have attributes. So if I create this..
calling dot products and linear algebra operations in Cython? http://stackoverflow.com/questions/16114100/calling-dot-products-and-linear-algebra-operations-in-cython operations that are available in numpy from Cython. Functions like numpy.linalg.inv inversion numpy.dot dot product X.t transpose..
Numerical Integration over a Matrix of Functions, SymPy and SciPy http://stackoverflow.com/questions/16295140/numerical-integration-over-a-matrix-of-functions-sympy-and-scipy Integration over a Matrix of Functions SymPy and SciPy From my SymPy output I have the matrix shown..
Python Script returns unintended “None” after execution of a function http://stackoverflow.com/questions/16974901/python-script-returns-unintended-none-after-execution-of-a-function The closest answer I was able to find said something like Functions in python return None unless explicitly instructed to do otherwise..
Solving non-linear equations in python http://stackoverflow.com/questions/19542801/solving-non-linear-equations-in-python Z_3 g Or F G m I'm a geophysist so we use G for Green's Functions and m for Model Parameters . Usually we'd use d for data instead..
In what order should the Python concepts be explained to absolute beginners? [closed] http://stackoverflow.com/questions/2439638/in-what-order-should-the-python-concepts-be-explained-to-absolute-beginners file and using it. One module only . Everything in it. Functions only with return no print . Forbid print in functions . Function..
What are “first class” objects? [closed] http://stackoverflow.com/questions/245192/what-are-first-class-objects class objects are referred to as second class objects. Functions in C are second class because they can't be dynamically created...
Why does python use 'magic methods'? http://stackoverflow.com/questions/2657627/why-does-python-use-magic-methods for other e.g. len list The major reason is history. Functions were used for those operations that were generic for a group..
Controlling the mouse from Python in OS X http://stackoverflow.com/questions/281133/controlling-the-mouse-from-python-in-os-x otherwise the Flash player never hides the mouse cursor. Functions like CGWarpMouseCursorPosition will not do this. from Quartz.CoreGraphics..
How i get the current language in django? http://stackoverflow.com/questions/3356964/how-i-get-the-current-language-in-django internationalization share improve this question Functions of particular interest are django.utils.translation.get_language..
Java -> Python? http://stackoverflow.com/questions/49824/java-python open somefile.txt if line.startswith nee is really nice. Functions are first class objects. They can be passed as parameters to.. And there's no way at all to say Student name Eli age 25 Functions can only return 1 thing. In Python you have tuple assignment..
Is it pythonic for a function to return multiple values? http://stackoverflow.com/questions/61605/is-it-pythonic-for-a-function-to-return-multiple-values A single item tuple must have a trailing comma such as d . Functions should serve single purpose Therefore they should return a single..
Static class variables in Python http://stackoverflow.com/questions/68645/static-class-variables-in-python regarding static methods also documented under Built in Functions in the Python Library Reference . class C @staticmethod def..
In Python, when should I use a function instead of a method? http://stackoverflow.com/questions/8108688/in-python-when-should-i-use-a-function-instead-of-a-method for other e.g. len list The major reason is history. Functions were used for those operations that were generic for a group..
|