29 Oct 2022

Python Tip: Get Filename, Extension, Parent Folder, File Existence, and More

收藏到CSDN网摘




From time to time, a very common task might be to get the file name, extension, parent folder, or checking the exitance of a file or file list. In Python, this can be done by the in-built os.path library. Here is how!

27 Oct 2022

Python Tip: Get Variable Name in Python (type of reflection?)

收藏到CSDN网摘




Sometimes, you may want to get the variable name itself as a string while writing Python code. For instance, if you are going to write 'a = 2', is there a convenient way of getting the variable name '"a"' by calling a function using 'a' as the parameter? The short answer is YES.

21 Oct 2022

Get Date and Time String in Python

收藏到CSDN网摘

It's a very common task that you may need the current date and time as a string, which can then be assigned as a timestamp for logging, intermidiate input deck generation, etc. In Python, there are several modules available to achieve this, such as date, time, datetime - well, it looks redudent here! The easierest way might be using the time module.