Python Scripting - Week 10 Flashcards

1
Q

What are scripts?

A

Scripting refers to small programs that automate process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Abreviation of BASH ?

A

Born Again Shell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What we use for Client Side Web Script ?

A

JavaScript & VBScript, Front End Scripting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What we use for Servert Side Web Script

A

Python, .NET,ASP,JSP,PHP, Backend Scripting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which libraries we use for working with paths ?

A

pathlib , os

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to create a path object ?

A

from pathlib import Path
p=Path(“D:/PythonCoding”)
print(p)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to get path of current working directory ?

A

from pathlib import Path
p=Path.cwd()
print(p)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to change present path ?

A

from pathlib import Path
p=Path(“D:/PythonCoding”)
print(p)
os.chdir(“D:/PythonCoding/Amrita University”)
print(Path.cwd())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to print all files and directories in a given path ?

A

from pathlib import Path
p=Path(“D:/PythonCoding”)
for items in p.glob(“*”):
print(items)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to print all PDF files in a given path ?

A

from pathlib import Path
p=Path(“D:/PythonCoding”)
for items in p.glob(“*.pdf”):
print(items)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to print only files in a given path?

A

from pathlib import Path
p=Path(“D:/PythonCoding”)
for items in p.glob(“*”):
if items.is_file():
print(items) and exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to create a new directory in a given path ?

A

from pathlib import Path
dirPath = Path.cwd()
newDir=dirPath/”new”
newDir.mkdir()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write a function to print only files in a directory by using OS library ?

A

def listAllFiles(str_):
from pathlib import Path
import os
fileList=[]
os.chdir(Path(str_))
for item in os.listdir():
if Path(item).is_file():
fileList.append(item)
return fileList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write a function to print all directory in a directory by using OS library ?

A

def listAllFolders(str_):
from pathlib import Path
import os
folderList=[]
os.chdir(Path(str_))
for item in os.listdir():
if Path(item).is_dir():
folderList.append(item)
return folderList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to convert path string to raw string?

A

Convert the string to raw string, Add r before the string.
sourceFile=Path(r”C:\Users\cs1\Documents\MEGAsync\PythonCoding\A4\shoping_list.pdf”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to create an empty set ?

A

set1=set()