Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Both os.listdir and str.startswith throw a TypeError for me.
Python rarely silently casts types.
By the way, path.os.listdir is just a fancy way to call os.listdir. You probably want .iterdir() of a Path object. -
mr-user13525y@sbiewald For me it silently cast when the type is <class 'numpy.int64'> , I just have to cast it to string with str() method before passing it to function.
-
mr-user13525yI use type hint as much as possible but it's hard to determine the return type of library.
I know it's a python (dynamic typing langue) feature but the function should only return 1 specific type.
The function may return the bool if fail and when success.
def divide(a:int ,b:int):
if b==0:
return False
return a/b -
SomeNone7135y> cast it to string with str() method
@mr-user It's converting, not casting. I guess the lines are blurred in Python (that's what you get from a dynamic-only language) but please try and not mix up these two concepts. -
mr-user13525y@SomeNone
What is the line between casting and converting in python? Since inheritance are rarely used in python.
Casting : Changing based on the inheritance. Male inheritance from Person so we can cast a male object to person object.Think polymorphism.
Converting: Convert the one type to another type.Doesn't need to have relationship between each other.For example every object can be converted to and from json/string. -
**pulls out cigar**
What if I told you...
**lights lighter**
That there are...
**lights up the cigar and takes a puff**
Strong typed languages out there? -
mr-user13525y@DubbaThony I would tell "I invent Strongly typed languages"
Joke aside I mainly code in the strongly typed language and the transaction to dynamically typed language has been uncomfortable to me. -
@mr-user
This sounds like story of younger Dubbs who switched from c++ to php 5.
Than php 7.0 went out and life got better -
@DubbaThony You mean statically types languages?
Static: Variables have a declared type and you cannot change the type of the variable. (E.g. C, Rust, ...)
Strong: There are types and they are different (Rust, Python; C, ...)
Dynamic: Variables have no declared type, a variable can be reassigned with a different type. (JavaScript, Python)
Weak: Types? What are types? (JavaScript) -
@sbiewald
I started my programming in statically typed language.
Than I switched to PHP 5 where its dynamic, than php 7.0 with dynamic strong typing came out and it was the perfection of having best of both worlds for me :D
Anyway, i ment all in all in my orig comment statically typed languages ;)
Thank python. Thank you , you just waste a hour of my life. The function is silently fail and spend a hour trying of to debug it.After a hour you know what a problem is? The parameter type.
The function expect a string but I am putting non-string type in the parameter and it just silently fail with no exception thrown. Great!
rant