Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
106 views

PythonPackagesandData Accesss

The os module in Python provides important functions for interacting with the operating system, including getting the OS name, opening and closing files, creating and removing directories, and changing the current working directory. It allows creating, reading, writing, and modifying files and folders on the file system. Functions like os.name, os.close(), os.popen(), os.mknod(), os.chdir(), and os.rmdir() are used to perform common operations with files and directories.

Uploaded by

roy.scar2196
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

PythonPackagesandData Accesss

The os module in Python provides important functions for interacting with the operating system, including getting the OS name, opening and closing files, creating and removing directories, and changing the current working directory. It allows creating, reading, writing, and modifying files and folders on the file system. Functions like os.name, os.close(), os.popen(), os.mknod(), os.chdir(), and os.rmdir() are used to perform common operations with files and directories.

Uploaded by

roy.scar2196
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Python - OS

The important functions present in the os module are:

Function Description
os.name Provides the name of the operating system. Examples of registered
names are 'posix', 'nt', 'os2', 'ce', 'java'.
os.close() To close a file.
os.popen() Provides a pipe or gateway through which files can be accessed
directly. Contains two modes; 'r' to read, and 'w' to write. If nothing is
specified, the default mode is 'r'.
os.mknod() To create a file. For example, os.mknod ("file_name.txt") will create a
file.
os.error() Raises an OSError when an invalid path or file name is given.
os.chdir() To change a directory to a specified path. For example, os.chdir ('New
directory path').

import sys
import os
import io

def func1(a):
sys.stdout.write(a)
s = 1
return s

if __name__ == "__main__":
try:
data=input()
b=func1(data)
except ValueError as error:
print(False)

import os, sys


import time
#Write your code here

s = os.getcwd()

os.mkdir("New Folder")
time.sleep(6)
os.chdir("/projects/challenge/New Folder")
time.sleep(6)

q = os.getcwd()

os.chdir("/projects/challenge/")
os.rename("New Folder", "New Folder2")
time.sleep(6)
os.chdir("/projects/challenge/New Folder2")
time.sleep(6)

p = os.getcwd()

os.chdir("/projects/challenge/")
os.rmdir('New Folder2')
time.sleep(6)

w = os.getcwd()

with open('.hidden.txt','w') as outfile:


outfile.write(s)
with open('.hidden1.txt', 'w') as outfile:
outfile.write(q)
with open('.hidden2.txt', 'w') as outfile:
outfile.write(p)
with open('.hidden3.txt', 'w') as outfile:
outfile.write(w)

import os
import datetime

def func1(y,m,d,ms,se,da,mi):

input_date = datetime.date(y, m, d)
input_date1 = datetime.datetime.combine(input_date,datetime.time(ms, se, da,
mi))
t = input_date1 - datetime.timedelta(microseconds = 1, seconds = 2, days = 3,
minutes = 2 )
day = t.day
year= t.year
month = t.month
minute= datetime.datetime.strptime(t.strftime("%Y-%m-%d %H:%M:%S.%f"), "%Y-%m-
%d %H:%M:%S.%f").minute
second= datetime.datetime.strptime(t.strftime("%Y-%m-%d %H:%M:%S.%f"), "%Y-%m-
%d %H:%M:%S.%f").second
return input_date,input_date1,t,day,year,month,minute,second
def func2(y,m,d,ms,se,da,mi):
s = "%a %B %d %H %M: %S %Y"
x = datetime.datetime (y,m,d,ms,se,da,mi)
q = x.strftime(s)
z = datetime.datetime.strptime(q,s)
return x,q,z

if __name__ == "__main__":
y,m,d,ms,se,da,mi = map(int, input().split())
inputs=func1(y,m,d,ms,se,da,mi)
inputs5=func2(y,m,d,ms,se,da,mi)
print(inputs[0])
print(inputs[1])
print(inputs[2])
print(inputs[3])
print(inputs[4])
print(inputs[5])
print(inputs[6])
print(inputs[7])
print(inputs5[0])
print(inputs5[1])
print(inputs5[2])

Input (stdin)
2020 5 9 1 2 3 4
Your Output (stdout)
2020-05-09
2020-05-12
2020-05-09
9
2020
5
0
0
2020-05-09 01:04:02.000003
Sat May 09 01 04:02 2020
2020-05-09 01:04:02

Expected Output
2020-05-09
2020-05-09 01:02:03.000004
2020-05-06 01:00:01.000003
6
2020
5
0
1
2020-05-09 01:02:03.000004
Sat May 09 01 02: 03 2020
2020-05-09 01:02:03

import os
import shutil
# Source path
source = "/projects/challenge/New Dir/newww.txt"

# Destination path
destination = "/projects/challenge/"

# Copy the content of


# source to destination
dest = destination + "newww.txt"
shutil.copyfile(source, dest)

# Print path of newly


# created file
print("Destination path:", dest)
with open('.hidden.txt','w') as outfile:
outfile.write(dest)

You might also like