Hack Forums
[Python] How can i edit a file without extension? [Python3] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] How can i edit a file without extension? [Python3] (/showthread.php?tid=5095365)



How can i edit a file without extension? [Python3] - ilikepython - Dec 15, 2015

this is what i've tried, seems the most simplest way to me:

Code
f = open ("C:\users\user\desktop\noextension","w+") #This shows no error
f.write("test") #This says that file is unwritable

Any suggestions?


* - bbbysmth - Dec 15, 2015

Quote:How can i edit a file without extension? [Python3]


I'm guessing you edit the same way you would edit a file with an extension.


* - RootBite - Dec 15, 2015

Hmm. well that means it has insufficient permissions probably. try just "w" not "w+".

If not, see if you can find the file extension


* - NON- - Dec 15, 2015

It shouldn't have a problem reading a file that doesn't have an extension. I just double checked it for myself.
Code
@pandora:~$ cat noext
nothing here
@pandora:~$ python
...
>>> f = open('/home/moi/noext', 'w')
>>> f.write('still nothing\n')
>>> f.close()
Ctrl-D
@pandora:~$ cat noext
still nothing

If you want to create the file using Python first, then I would recommend using...
Code
import os; os.mknod("newfile.txt")
It's a little naughty but it's usually gets the job done without over complicating things.


* - Pseudonym - Dec 16, 2015

I think that backslashes in path should be all escaped. Try it with ("C:\\users\\user\\desktop\\noextension","w+")