World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITian's, only for AI Learners.
Designed by IITian's, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Sulochana Kamshetty
a year ago
Import os
Print(os.name)
Output :- nt
fd = "AIML.txt"
popen() is similar to open()
import os
file = open(fd, 'w')
file.write("Hello")
file.close()
file = open(fd, 'r')
text = file.read()
print(text)
# popen()
provides a pipe/gateway and accesses the file directly
file = os.popen(fd, 'w')
file.write("insideaiml")
Hello
import os
fd = "AIML.txt"
file = open(fd, 'r')
text = file.read()
print(text)
os.close(file)
Output:
Traceback (most recent call last):
File "C:\Users\system\Desktop\insideaiml
content.py", line 6, in
os.close(file)
import os
fd = "AIML.txt"
os.rename(fd, insideaiml.txt')
Output: new text document with insideaiml will be created in place of aiml.txt
File "C:\Users\smithika\Desktop\insideaiml.
contentpy", line 3, in
os.rename(fd,'New.txt')
FileNotFoundError: [WinError 2] The system cannot find the
file specified: AIML.txt' -> 'New.txt'
import sys
sys.argv : A list of
strings which is the command line used to execute the script separated by
spaces.
sys.exit() : Exit Python
cleanly
sys.version : The Python
version string
import sys
x = 42
def my_display(x):
sys.displayhook = my_display
print x
output = 42