Today I am learning reading file with python using with as : code block and some string manipulation. it is quite similiar to C# which I have spending many years coding with so I could have skipped this but I will finish learning it by the book.
Python’s saga continue
I have to agree that it is one of the powerful feature of this language. In C#, it has similiar feature but less power since you can only assign ‘same value’ to multiple variables within the same line. But with this powerful feature of python, you can assign multiple values to multiple variables within the same line. As of this writing, in C# it also now has this feature but still less powerful than this since we are required to use var keyword and install additional NuGet package called “System.ValueTuple”.
Anyways, I gave this powerful python’s feature a test and voila I like it:
Here is the practical example: we have a file name called fn which is assigned with string “Abi-10-50m-Back.txt” where Abi is the swimmer name, 10 is her age, 50m is her swimming distance and last but not least Back is her swimming style. Below example is to extract these information from the file name vairable fn into its own separate variable. I am happy with python as it can accomplish this task with mimal code than if using C# for the split string in C# items would be returned as an array. And to access each of them requires using arrary with its index and have to declare each of variable per arrary index for code readibility but with python, less code and it is easy to read.
Python’s saga continue
print dir combo mambo is very handy as other have said. We can see attributes/methods associated with any object in python. here now I can see all the methods I can use against my string object variable fn. And string in python is immutable which is the same thing in C#.
Now if I want to know; for instance, what the method zfill actually would do on the string object I can use print with help BIF which will print the documentation of zfill telling me all about zfill method’s fuctionality. (It might be equivalent C# String.padleft(…))
I just pick up python on my own time
I found it very intriguing.
Using Jupyter and VS code, I will continue to explore this programming language.