dynamic

Python 3.6.1: How to dynamically print a docstring?

Python 3.6.1: How to dynamically print a docstring? Question: While reading some Python training books, I was tinkering a little bit with objects, like printing docstrings for common objects and attributes. Consider the list of strings returned by: dir(str) I am trying to iterate over the above in order to dynamically print the docstrings of …

Total answers: 2

sqlalchemy dynamic filtering

sqlalchemy dynamic filtering Question: I’m trying to implement dynamic filtering using SQLAlchemy ORM. I was looking through StackOverflow and found very similar question:SQLALchemy dynamic filter_by It’s useful for me, but not enough. So, here is some example of code, I’m trying to write: # engine – MySQL engine session_maker = sessionmaker(bind=engine) session = session_maker() # …

Total answers: 6

SQLAlchemy – "Dynamic Filter"

How to create a dynamic filter? Question: I have a table with equipment and each of them has dates for level of maintenance. The user can select the maintenance level. So, I should adjust my SQLAlchemy for each combination of maintenance level chosen. For example: SELECT * WHERE (equipment IN []) AND m_level1 = DATE …

Total answers: 5

conditional class inheritance in python

conditional class inheritance in python Question: I am trying to dynamically create classes in Python and am relatively new to classes and class inheritance. Basically I want my final object to have different types of history depending on different needs. I have a solution but I feel there must be a better way. I dreamed …

Total answers: 3

Python creating variables with names from range

Python creating variables with names from range Question: I want to use some code similar to what follows that actually works: P = 20 n = 1 for x in range(1, P+1): Ax = n #Hoping that you can name the variable from the current element in the range n = n+1 I want to …

Total answers: 3

Problems embedding IronPython in C# (Missing Compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'

Problems embedding IronPython in C# (Missing Compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember' Question: I’m trying to do a simple hello world to test out embedding IronPython within C# but can’t seem to resolve this problem.. This is my C# file; using System; using IronPython.Hosting; using Microsoft.Scripting; using Microsoft.Scripting.Hosting; using System.IO; public class dynamic_demo { static void Main() …

Total answers: 3

Pickling dynamically generated classes?

Pickling dynamically generated classes? Question: I’m using type() to dynamically generate classes that will ultimately be pickled. The problem is that the un-pickling process needs the definition of the class in order to re-construct the object that has been pickled. This is where I’m stuck. I don’t know how to somehow provide the unpickler a …

Total answers: 6

How to dynamically change base class of instances at runtime?

How to dynamically change base class of instances at runtime? Question: This article has a snippet showing usage of __bases__ to dynamically change the inheritance hierarchy of some Python code, by adding a class to an existing classes collection of classes from which it inherits. Ok, that’s hard to read, code is probably clearer: class …

Total answers: 7

Dynamically set local variable

Dynamically set local variable Question: How do you dynamically set local variable in Python (where the variable name is dynamic)? Asked By: Jonathan Livni || Source Answers: You could modify locals() directly: locals()[‘foo’] = ‘bar’ But a better way would be to have some dict that holds all your dynamic variable names as dictionary keys: …

Total answers: 7