create new python file

kakararunachalservice at gmail.com kakararunachalservice at gmail.com
Tue Jun 4 14:09:51 EDT 2013


On Tuesday, June 4, 2013 11:14:32 PM UTC+5:30, Gary Herron wrote:
> 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


Thank you so much! Why didn't i thought about that. So, can i program within just by the print statement? Or do i have to do something else. I'm sorry, i just learning python. Thanks again!



More information about the Python-list mailing list