SERVING THE QUANTITATIVE FINANCE COMMUNITY

FaridMoussaoui
Posts: 456
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

### Re: Python tricks

that's python IDE is easier

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

### Re: Python tricks

that's python IDE is easier
I sugested pyCharm. My student loves it! No looking back, goodbye VS and parallels for her. We keep the infrastructure threshold low. The rest is plain sailing.
Merci, Farid.
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: 60501
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Is this a bug in Python?
import pandas as pd
from pandas import datetime, period_range

#compiles
#myRange = pd.period_range('2000-01-01', periods=12, freq='T')
#ts  = pd.Series(range(12), index=myRange)

#NOT compile
range = pd.period_range('2000-01-01', periods=12, freq='T')
ts  = pd.Series(range(12), index=range)

ts.index = ts.index.astype('datetime64[ns]')
data_higher_freq = ts.resample('5T').sum()
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

FaridMoussaoui
Posts: 456
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

### Re: Python tricks

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....

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

### Re: Python tricks

Even more interesting I accidentally had a range() function and this is the one that resample() sees. Ouch
Very bad.I am accidentally or deliberately overriding what is in essence an (undocumented) Python keyword 'range'.

Q: The ability to override core Python functions with impunity,feature or bug?

Code:

def range(i):
print ("range")
return 1/0

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: 60501
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....
range is a function, not an object
?
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

tagoma
Topic Author
Posts: 18280
Joined: February 21st, 2010, 12:58 pm

### Re: Python tricks

Is this a bug in Python?
Isn't python, it is the developer. What about using a square bracket instead of a parenthese .....
range is a function, not an object
?
Python allows built-in functions overloading. Bad or good is mental masturbation. That's just the way it is. Programmer is supposed to have come through the list of these built-in functions at some point, and understands it is usually bad practice to use those name to create object/functions/etc. To somewhat circumvent the issue, programmer can use scope/namespace tricks.

import builtins
builtins.range(10)
#range(0, 10)

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

### Re: Python tricks

Nice. So, one can put functions and so on in modules which is good practice. System decomposition into independent and loosely coupled modules is recommended before jumping head first into coding marathons.
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: 2206
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

tagoma
Topic Author
Posts: 18280
Joined: February 21st, 2010, 12:58 pm

### Re: Python tricks

Python 3.8 introduced the Walrus operator.
What are the cons according to you Wilmotters?