python: open file with no extension
Noob question: So I'm teaching myself python and I'm getting into some file parsing. I had a bunch of files I was going to test on but they have no extension. For the sake of learning I am wondering is there a way to open files with no extension or how can I programatically add extensions to files without them. I know I can manually add extension in windows but assuming I had thousands of these files and wouldn't want to do it manually.
You can use os.rename() for renaming files. The Python documentation is always useful to have around - be sure to bookmark it!
So I have file1.txt and a file called noext . I can open both with text editor so no problem with the files.
f = open("noext") works but I want to be able to get a list of these files in the dir and open them from that list but the problem is they don't show up when I list the contents of the folder.
When I do:
print glob.glob(".\\files\\*.*")
It lists only the .txt file. I'm going to try another way of listing the dir contents.
Thanks for help so far. :)
edit: this seems to work:
os.listdir(path)
Thanks again!
f = open("noext") works but I want to be able to get a list of these files in the dir and open them from that list but the problem is they don't show up when I list the contents of the folder.
When I do:
print glob.glob(".\\files\\*.*")
It lists only the .txt file. I'm going to try another way of listing the dir contents.
Thanks for help so far. :)
edit: this seems to work:
os.listdir(path)
Thanks again!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement