Labels

_fuxi (75) _IV (146) _misc (5) {610610 (30) algo (1) automatedTrading (8) banking/economy (3) book (14) c++misc (125) c++real (15) c++STL/java_container (7) cppTemplate (1) db (13) DB_tuning (4) deepUnder (1) dotnet (69) eTip (17) excelVBA (12) finance+sys (34) financeMisc (24) financeRisk (2) financeTechMisc (4) financeVol (21) finmath (17) fixedIncome (25) forex (16) IDE (24) invest (1) java (43) latency (4) LinearAlgebra (3) math (30) matlab (24) memoryMgmt (11) metaPrograming (2) MOM (15) msfm (1) murex (4) nofx (11) nosql (3) OO_Design (1) original_content (4) scriptUnixAutosys (19) SOA (7) socket/stream (15) sticky (1) subquery+join (2) swing (32) sybase (6) tech_orphan (12) tech+fin_career (30) telco (11) thread (21) timeSaver (13) tune (10) US_imm (2) US_misc (2) windoz (20) z_algo+dataStructure (4) z_arch (2) z_c#GUI (30) z_career (10) z_career]US^Asia (2) z_careerBig20 (1) z_careerFinanceTech (11) z_FIX (6) z_forex (31) z_hib (2) z_ikm (7) z_inMemDB (3) z_j2ee (10) z_oq (14) z_php (1) z_py (26) z_quant (4) z_skillist (3) z_spr (5)
Showing posts with label z_py. Show all posts
Showing posts with label z_py. Show all posts

Thursday, January 22, 2015

Fwd: python ctor call syntax

In terms of ctor syntax, I think python is more flexible and less "clean" than java. More like c++.

        return riskgenerator.BasicDealValuationGenerator(envDetails)

Luckily I know BasicDealValuationGenerator is a class in the riskgenerator module, so I know this is likely be calling the ctor.

Tuesday, May 27, 2014

python exception handling, basics

Python adds exception handling, a missing feature in earlier
scripting languages.

A complete stack trace is available.

Error handlers can clean up or defuse a problem.

python performance, brief notes

Compared to java, Python is slower and less portable. Solution - Jython creates java bytecode.

In Quartz, python performance is considered a real issue.

Toa Payoh library has a book on Python performance...

Compiling to C ... cython. 

Saturday, April 26, 2014

list slicing operation - adoption in various languages

In my perl, java, c++, c#, php projects, few developers use list slicing. Many textbooks and tutorials cover the many slicing features, but I doubt they are needed for IV or projects.

String slicing i.e. substring is popular though.

Matlab coders like slicing!

python - write on windows; deploy to linux

I now feel the platform differences are relatively rare.

 

http://programmers.stackexchange.com/questions/199863/developing-python-on-windows-and-deploying-to-linux says Cygwin is a useful environment for this purpose

Tuesday, January 14, 2014

python - important details tested on IKM

Today I did some IKM python quiz. A few tough questions on practical (not obscure) and important language details. You would need to invest months to learn these. I feel a regular python coding job of 2 years may not provide enough exposure to reach this level.

Given the amount of effort (aka O2, laser) invested, I feel LROTI would be much higher in c++, java and WPF (slightly less in general c# and swing). One problem with LROTI on WPF is churn.

As we grow older and have less time to invest, LROTI is a rather serious consideration. I no longer feel like superman in terms of learning new languages.

Friday, February 15, 2013

immutability in python - fundamentals

Rule: immutability is on objects, not on variables. Actually, same as other languages.

Rule: An object's mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.

Examples of containers are tuples, lists and dictionaries. The value of an immutable container object (like a tuple instance) that contains a reference to a mutable object can change when the latter's value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable content, it is more subtle. See http://docs.python.org/2/reference/datamodel.html

In most cases, when we talk about the value of a container, we imply the values, not the identities of the contained objects; however, when we talk about the mutability of a container, only the identities of the immediately contained objects are implied.

I think for a custom MyClass that HAS-A object field myField, MyClass immutability means the content of myField is unchangeable. That's the strict definition of immutability.

Monday, May 21, 2012

string tasks(any lang) - IV/work

(Let's be imprecise here... Don't sweat the small stuff.)

We should be able to perform all of these using c-string, std::string (limited adoption since c++98), the standard string in java , c#, perl, python, php. This is a master list. Tolerate multiple names on Each task.

clone a string on stack
insert_by_pos
char* strstr()
int indexOf()
concat/append
split
compare
erase_by2pos
substr_by2pos
replace_by2pos
replace_a_substr
clearContent

--STL
use string iterator with STL algorithms
--the easy
RW access by index
substring_by_pos
equals
length
toUpper
--advanced
convert to vector<char> and apply vector tricks
convert to std::string and apply tricks
trim
equalsIgnoreCase
compareIgnoreCase
lastIndexOf
count how many times a substr occurs
sort content
endsWith

Thursday, March 29, 2012

simple script to count classes defined in a python project

Any time you have a sizeable python project with many *.py source files, you can use this script to count how many classes defined.

import re, sys
from os import walk

printed={}
for (path, dirs, files) in walk("c:\\py") :
       for filename in files :
               if not re.search("\.py$",filename) : continue
               if not printed.has_key(path):
                       print " path = " + path
                       printed[path] = True

               for line in open (path+'\\'+filename) :
                       #if re.search('^\s*def ', line) : print line,
                       #if re.search('^\s*class\s', line) : print filename + ':\t' + line,
                       if re.search('^\s*try\s', line) : print filename + ':\t' + line,
                       #if re.search('@', line) : print filename + ':\t' + line,

basic "chdir" in python

try:
       os.chdir(baseName)

except Exception as e:

       print e
       raw_input("...")

Thursday, March 22, 2012

python details to understand (put to use? later)

These are the features I feel likely to turn up in production source code or interviews, so you need to at least recognize what they mean but need not know how to use exactly. (A subset of these you need to Master for writing code but let's not worry about it.)

List of operators, keywords and expressions are important for this purpose

Most built-in Methods are self-explanatory.

list comprehension
back quote
triple quote
myDict.get(key, defaultVal)
Function decorators
reduce(), zip()
xrange()
keyword - "else" after loops and try/except
keyword - yield and generator expressions
keyword - pass
keyword - except
documentation string __doc__
environment variables
create empty dict
create empty list
defaultdict(list)
apply() vs ** arguments and * arguments

--- too advanced ---
......
--- too "mandatory" ---
interpolation vars into strings
process a given user input either as string or number

Thursday, March 15, 2012

process user input as string or as number

Perl makes is too easy ...

Strong-typed languages require explicit conversions between strings and numbers.

Python also requires conversion --

int(myStr)
float(myStr)

str(myNumber), repr(myNumber),  modulo (%) -- all equivalent

Monday, March 12, 2012

special methods to be customized in a python class

..., based on P45 [[py ref]]. Each one is non-trivial, and worth studying.

__init__(self). The static method __new__(self)  is obscure

__cmp__(self) and __hash__(self)

__str__(self) and __repr__(self)


Saturday, March 10, 2012

## elegant constructs in python

powerful, full-featured, yet simple, consistent ....

string class
dict class
tuple/list class
file class
for-loop and iterator
list comprehension

python object (de)serialization

There seem to be multiple solutions --

pickle / shelve modules

__repr__(self) -- any class including built-in data type classes can customize this method. This method is invoked by either
- backquote operator
- repr() built-in free function

Thursday, March 8, 2012

similarity python ^ c#

yield
dict
no first-class-citizen set
lamda anonymous function

Sunday, March 4, 2012

file/console input output ] python

Output typically uses "print".

print >> myFileObject , arguments
print >> sys.stderr , arguments...

Quiz: so, in that case, how do you print to stdout?

Input from file is very common, so that's another quiz

Input from std input --

aLine = sys.stdin.readline()
all_the_Lines = myFileObject.readlines()

Some prefer the object-oriented way to output

myFileObject.write(arguments....)

Saturday, March 3, 2012

most common python usage on Wall St

I believe the most common is a replacement for perl and shell scripts in unix system automation. For this purpose, you don't need OO inheritance, callable objects, threads

You do need modules, basic DTO classes, lamda,

Thursday, March 1, 2012

][ vs )( in python

Bracket [[[[ ]]]] is used for
- list initialization
- slicing -- for any sequence structure
- access a dict/tuple/str/list

Parenthesis (((( ))) is used for
* tuple initialization
* function call

Friday, February 24, 2012

colon ^ semi-colon ^ curly-braces ] python

Python uses both colon and semi-colon.

- Python doesn't use curly braces to create code-blocks. It uses indentation.

- Between an if/while/for "header" and "body", you put a colon

- You can also use semicolon, but rarely. P7 [[pyref]]