python: open file with no extension

Started by
4 comments, last by gnomer 15 years, 2 months ago
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.
Advertisement
This works for me:
f = open("fred")
You can use os.rename() for renaming files. The Python documentation is always useful to have around - be sure to bookmark it!
Create-ivity - a game development blog Mouseover for more information.
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!
Just changing the pattern from *.* to * should do the trick.
Quote:Original post by let_bound
Just changing the pattern from *.* to * should do the trick.


ah, can't believe i missed that. Thanks that works! :)

This topic is closed to new replies.

Advertisement