#!/usr/bin/python print "Python is really a great language,", "isn't it?";
Python is really a great language, isn't it?
#!/usr/bin/python
str = raw_input("Enter your input: ");
print "Received input is : ", str
Enter your input: Hello Python Received input is : Hello Python
#!/usr/bin/python
str = input("Enter your input: ");
print "Received input is : ", str
Enter your input: [x*5 for x in range(2,10,2)] Recieved input is : [10, 20, 30, 40]
file object = open(file_name [, access_mode][, buffering])
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
print "Closed or not : ", fo.closed
print "Opening mode : ", fo.mode
print "Softspace flag : ", fo.softspace
Name of the file: foo.txt Closed or not : False Opening mode : wb Softspace flag : 0
fileObject.close();
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
# Close opend file
fo.close()
Name of the file: foo.txt
fileObject.write(string);
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "wb")
fo.write( "Python is a great language.\nYeah its great!!\n");
# Close opend file
fo.close()
Python is a great language. Yeah its great!!
fileObject.read([count]);
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "r+")
str = fo.read(10);
print "Read String is : ", str
# Close opend file
fo.close()
Read String is : Python is
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "r+")
str = fo.read(10);
print "Read String is : ", str
# Check current position
position = fo.tell();
print "Current file position : ", position
# Reposition pointer at the beginning once again
position = fo.seek(0, 0);
str = fo.read(10);
print "Again read String is : ", str
# Close opend file
fo.close()
Read String is : Python is Current file position : 10 Again read String is : Python is
os.rename(current_file_name, new_file_name)
#!/usr/bin/python import os # Rename a file from test1.txt to test2.txt os.rename( "test1.txt", "test2.txt" )
os.remove(file_name)
#!/usr/bin/python
import os
# Delete file test2.txt
os.remove("text2.txt")
os.mkdir("newdir")
#!/usr/bin/python
import os
# Create a directory "test"
os.mkdir("test")
os.chdir("newdir")
#!/usr/bin/python
import os
# Changing a directory to "/home/newdir"
os.chdir("/home/newdir")
os.getcwd()
#!/usr/bin/python import os # This would give location of the current directory os.getcwd()
os.rmdir('dirname')
#!/usr/bin/python import os # This would remove "/tmp/test" directory. os.rmdir( "/tmp/test" )
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有