446,281 Members | 2,201 Online Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

# How to save python codes in files?

 P: n/a Im working with Python 2.2 on my red hat linux system. Is there any way to write python codes in separate files and save them so that i can view/edit them in the future? Actually I've just started with python and would be grateful for a response. Thanx! Jun 13 '07 #1
8 Replies

 P: n/a On 6/12/07, why? Jun 13 '07 #2

 P: n/a Evan Klitzke wrote: On 6/12/07, why? >def sum(x,y): return x+y .... >>> Jun 13 '07 #3

 P: n/a On 6/13/07, why? Evan Klitzke wrote: On 6/12/07, why? def sum(x,y): return x+y ... >> If you want to write a program, you need to have some code that actually does something (rather than just containing definitions of functions). Here's a trivial example of a file using your sum function: #!/usr/bin/env python def sum(x, y): return x+y print 'Enter two numbers:' x = int(raw_input()) y = int(raw_input()) print 'The sum is equal to %s + %s = %s' % (x, y, sum(x,y)) -- Evan Klitzke Jun 13 '07 #4

 P: n/a On 13 Cze, 10:06, why? def sum(x,y): return x+y ... :D You should try some basic manual on linux :D Copy and paste the code (do not include >>and ...) to the editor, save. Then run as advised above. Good luck. Cheers, Marek Jun 13 '07 #5

 P: n/a I tried but its not working. Here's a code for sum of two numbers. Now how do i save it? >> #! /usr/bin/env python .... >>def sum(x,y): .... return x+y .... >>x=int(raw_input('Enter a number: ')) Enter a number: 35 >>y=int(raw_input('Enter a number: ')) Enter a number: 7 >>print 'sum is', sum(x,y) sum is 42 Jun 14 '07 #6

 P: n/a Also, how can i save a file using text editor in linux? Jun 14 '07 #7 