SERVING THE QUANTITATIVE FINANCE COMMUNITY

ISayMoo
Posts: 2246
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

Thanks!

Cuchulainn
Posts: 60753
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Duck typing harmful?
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik

ISayMoo
Posts: 2246
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

There is no Python API for Unity.

Cuchulainn
Posts: 60753
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

There is no Python API for Unity.
like this Unity??

https://code.visualstudio.com/docs/other/unity
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik

ISayMoo
Posts: 2246
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

Yes, the game engine.

Cuchulainn
Posts: 60753
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

I have not seen much written on the topic of robustness and reliability of Python code and 'interaction' with (external) libraries. Some thoughts.

1. Defining contracts
2. Exception handling
3. Exception handling in a multi-language application (e.g. Calling C++ from Python).
4. Standardisation in the Python library developer community (is my domain error the same as your domain error?)
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik

ISayMoo
Posts: 2246
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

1. Docstrings, type annotations (relatively new thing), assertions and explicit checks in conditional statements. The standard way of handling violations of contracts by the caller is to throw an exception (usually TypeError or ValueError).
2. I find Python exceptions very easy to use. The standard exception class hierarchy is convenient to use. I rarely have the dilemma "which type should I throw?"
3. I don't know, but probably not easy. Is it easy in any other language not running in a common VM?
4. Python has a lot of "idioms" which people standardise on: https://en.wikibooks.org/wiki/Python_Programming/Idioms

ISayMoo
Posts: 2246
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

PS. But I think I'm teaching the grandmother to suck eggs. You're selling a course on Python. Surely you know all this already?

Cuchulainn
Posts: 60753
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

With the possible exception of 3, things become interesting when you write a non-trivial application using multiple libraries.

// I am also thinking out loud.
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik

ISayMoo
Posts: 2246
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

I am working on a very large Python codebase at work. Things are fine, because we are strict about code consistency, dependency management and having a single version of everything (no "DLL hell").

Cuchulainn
Posts: 60753
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

I am working on a very large Python codebase at work. Things are fine, because we are strict about code consistency, dependency management and having a single version of everything (no "DLL hell").
An issue with large systems is managing the dependency graph, e.g. when a well-known public data structure change how does it impact the modules etc.?

I really like how easy modules and packages are in comparison to C/C++ (which does not support modules). But how good are they with Information Hiding?
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik

Cuchulainn
Posts: 60753
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

I am working on a very large Python codebase at work. Things are fine, because we are strict about code consistency, dependency management and having a single version of everything (no "DLL hell").
An issue with large systems is managing the dependency graph, e.g. when a well-known public data structure change how does it impact the modules etc.?

I really like how easy modules and packages are in comparison to C/C++ (which does not support modules). But how good are they with Information Hiding? (no private data in Python).
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik

ISayMoo
Posts: 2246
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

I really like how easy modules and packages are in comparison to C/C++ (which does not support modules). But how good are they with Information Hiding? (no private data in Python).
There are private data in Python. They are denoted by convention by an underscore in front of variable name. Any linter can catch this.

ISayMoo
Posts: 2246
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

I am working on a very large Python codebase at work. Things are fine, because we are strict about code consistency, dependency management and having a single version of everything (no "DLL hell").
An issue with large systems is managing the dependency graph, e.g. when a well-known public data structure change how does it impact the modules etc.?
You scan the build files, find all build units affected by the changes in the build unit(s) the module belongs to, rebuild them, and run test build units (i.e. unit tests) which depend on them.

Cuchulainn
Posts: 60753
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

class PointTest:
# Counterexample: class with "private" attributes
def __init__(self,x=-10, y=0): #default values
self.move(x,y)

def move(self, x, y):
self._x = x
self._y = y
self.__x = x
self.__y = y

def printI(self):
print (self._x, self._y)

def printII(self):
print (self.__x, self.__y)

pp = PointTest(1,2)
pp._x = -1; pp._y = -2
print("Private in name only? (PINO)")
print(pp._x); print(pp._y); #-1, -2
#print(pp.__x); print(pp.__y); #AttributeError

pp.printI() #(-1,-2)
pp.printII() #(1,2)


ISayMoo:
I really like how easy modules and packages are in comparison to C/C++ (which does not support modules). But how good are they with Information Hiding? (no private data in Python).
There are private data in Python. They are denoted by convention by an underscore in front of variable name. Any linter can catch this.
Single underscore is still public; seems double underscore is needed.
http://www.datasimfinancial.com
http://www.datasim.nl

Approach your problem from the right end and begin with the answers. Then one day, perhaps you will find the final question..
R. van Gulik