Double clicking a py file cannot perform the operation of creating a new file. You can run it on the command line or in Python's own idle without an error.

CSDN Q & A 2022-01-15 02:18:23
The phenomenon and background of the problem

import os
fp=open('hello.txt','w')
fp.write('hello')
fp.close()
os.system('pause')

Operation results and error reporting contents

Double click runtime , The console window is waiting , But there is no new file .
Run or... On the command line idle Everything is normal in .

My solution ideas and tried methods

I have uninstalled the installation again python

What I want to achieve



Refer to the answer 1:

Check that you double-click the runtime path

import osprint(os.getcwd())

The file should be created . But based on the current path , It could be windows Under the default path of .




Refer to the answer 2:



Refer to the answer 3:

Run or... On the command line idle Run in , The running directory is actually in the current directory . Double-click on the run , Should also generate new files , It's just not in the current directory . But in the console Directory . I've often met before .




Refer to the answer 4:

thank
Similar articles

2022-01-15

2022-01-15