SoFunction
Updated on 2024-11-20

Misunderstandings of python

Do you see anything wrong with the following statements?

for file in (path):
    if (file) and (file)[1] == '.txt':
      #show (a ticket)txtfile,and extract data

Meditating on this, yes, why does (file) return false.

>>> (path)
['.', '.', '.', '.', '.', 'cg.
A.', '.', '.', '.', '.', '.
t', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.1
', '.', '.', '.', '.', '.
', '.', '.', '.', '.', '.', '
.', '.', '.', '.']
>>> files = (path)
>>> (files[1])
False

Tried it many times and it's still False, holy shit what the hell .....

Started googling and saw some catalog manipulation, to no avail ....

So I checked python's own help and finally found the answer,tears ....

(path)
Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.

Attention:path is the path .....

And I passed a file name.

The solution is:

>>> ((path,files[1]))
True

Done!

Above this python the use of misunderstandings explained is all I have shared with you, I hope to give you a reference, and I hope you support me more.