create new python file

Gary Herron gherron at digipen.edu
Tue Jun 4 13:44:32 EDT 2013


On 06/04/2013 09:07 AM, kakararunachalservice at gmail.com wrote:
> Hi,
> Can anyone please tell me how to dynamically create a new python file within a program???

What do you mean by a "python file"?   If you mean a text file 
containing python code, then create it like any other text file. For 
instance:

     with open("Hello.py", "w") as f:
         print("print('Hello world')\n", file=f)

will create a file containing a simple one-line Python program.

If you meant something else, then please take the time to provide more 
detail.

Gary Herron


-- 
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418




More information about the Python-list mailing list