File handling in Python allows storing and retrieving data from files. There are two types of data - persistent data stored permanently in files, and transient temporary data. Files can contain text or binary data. The os module allows creating, renaming, removing directories and listing their contents. Files can be opened in different modes like read, write, append to perform operations like writing, reading, copying and retrieving metadata. Objects can also be serialized into files and deserialized later for storage. The with statement automatically closes files after operations.
Our lab planned a one-week lecture for bioinformatics beginners. I am right now the system administrator of Linux servers, NAS and Vms, so i want to teach the basics of linux system for new Linux users. And i wish to share my slide with you.
we need to have a good amount of basic or in-depth knowledge on Linux Basics. This will help one's job easy in resolving the issues and supporting the projects.
Are you a system admin or database admin? Or working on any other technology which is deployed or implemented on linux/UNIX machines? Then you should be good with Linux basic concepts and commands. We will cover this section very clearly.
Python too supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on files. The concept of file handling has stretched over various other languages, but the implementation is either complicated or lengthy, but alike other concepts of Python, this concept here is also easy and short. Python treats file differently as text or binary and this is important. Each line of code includes a sequence of characters and they form text file. Each line of a file is terminated with a special character, called the EOL or End of Line characters like comma {,} or newline character. It ends the current line and tells the interpreter a new one has begun. Let’s start with Reading and Writing files.
Our lab planned a one-week lecture for bioinformatics beginners. I am right now the system administrator of Linux servers, NAS and Vms, so i want to teach the basics of linux system for new Linux users. And i wish to share my slide with you.
we need to have a good amount of basic or in-depth knowledge on Linux Basics. This will help one's job easy in resolving the issues and supporting the projects.
Are you a system admin or database admin? Or working on any other technology which is deployed or implemented on linux/UNIX machines? Then you should be good with Linux basic concepts and commands. We will cover this section very clearly.
Python too supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on files. The concept of file handling has stretched over various other languages, but the implementation is either complicated or lengthy, but alike other concepts of Python, this concept here is also easy and short. Python treats file differently as text or binary and this is important. Each line of code includes a sequence of characters and they form text file. Each line of a file is terminated with a special character, called the EOL or End of Line characters like comma {,} or newline character. It ends the current line and tells the interpreter a new one has begun. Let’s start with Reading and Writing files.
ExplanationThe files into which we are writing the date area called.pdfaquacare2008
Explanation:The files into which we are writing the date area called as output files.If we want to
write the result of the program in the user required format we can write in these files.
2.2) When storing and retrieving data, a sequential access file is much like a VCR tapes
In floppy disks and hard disks data retrieval and storing will be done in Random wise.But this is
not possible in case of VCR tapes.this is the disadvante of this.That why now a days we are using
hard disks to store data.
3.3) If you want to add data to an new file, what is the correct operation to perform?
Ans) create a file
4.4) To create an output file object, you would use what kind of type?
Ans)ofstream
Syntax: ofstream myfile;
myfile.open (\"D:\\\\bankbal.txt\");
5.5) What do the following statements accomplish?
ofstream theFile;
theFile.open( myFile.txt , ios::app);
Ans) Opens myFile in append mode
ios::app – If we opened a file in this mode,If any content we are writing will be appended to the
end of the file.I.e the new content we are wrinting will be appended to the end of the already
existing content.
6.6) When a file is opened in output mode, the file pointer is positioned at the beginning of the
file.
For input file and output file the pointer will we positioned at the beginning of the file only.
7.7) The is_open function returns what kind of data type?
Ans)bool
If(myfile.is_open) we use this to check whether the file opened successfully or not.
8.8) In general, which of the following contains the least amount of data?
Ans)byte
We can store only a single character or single number or single symbol in this byte.like ‘a’,7,#
9.9) To use an output file, the program must include fstream
Explanation: If we want to use either an input file or an output file we have to include fstream.h
header file. Like #include
10.10) Which of the following is not true about files?
Ans) istream, ostream, and iostream are derived from ifstream, ofstream, and fstream,
respectively.
11.11) Compare and contrast the mode operators ios::in, ios::app, and ios::out. Provide a C++
code segment that illustrates the use of these mode operators.
Ans)
To open a file we have to use this member function.
As a first argument we have to supply the filename.
As a second argument we can supply the mode of opening the file.this is an optional parameter.
Syntax: open(filename,mode);
ios::in – if we want to read the data from the file we have to use this mode.This is used for input
operations.
Code:
ifstream file;
file.open(\"D:\\\\bank.txt\"); or file.open(\"D:\\\\bank.txt\",ios::in);
here we are trying to read the data from the file named bank.txt which is available in D
drive.Here we didn’t specify the mode here.By default the file will be opened in ios::in mode
ios::out - if we want to write the data from to a file we have to use this mode.This is used for
output operations.
Code:
ofstream myfile;
myfile.open (\"D:\\\\bankbal.txt\"); or myfile.open (\"D:\\\\bankbal.txt\", ios::out);
myfile <<”Hell.
Textbook Solutions refer https://pythonxiisolutions.blogspot.com/
Practical's Solutions refer https://prippython12.blogspot.com/
Computer program works with files. This is because files help in storing information permanently. A file is a bunch of bytes stored on some secondary storage devices.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
2. File Handling in Python
We have two types of data storage:
Persistent: permanent storage.
Transient: temporary storage.
We can store data permanently in a file with the help of
python.
We can read that data from a file later.
write read
2
3. Types of Data
Text Data:
Human Readable Data
For ex. .txt, .py files
Binary Data:
Not human readable
For ex. .mp3, .jpg, .png files
3
4. Create directories
We can create folders with the help of os module in
python.
If you are not providing path, than it will create the
folder in the current working directory.
import os
os.mkdir("D:/MyFolder")
Create Multiple directories:
os.makedirs("My/Python/Folder")
4
5. Rename folders
We can provide exact location where we want to save it
after renaming the folder.
os.rename("D:/MyFolder","D:/Folder")
OR we can give just new name of the folder, after that it
will create the folder in the same working directory.
os.rename("D:/folder","Myfolder")
MyFolder Folder
rename
5
6. Remove Folders
To remove a single Directory:
import os
os.rmdir("D:/MyFolder")
To remove multiple directories:
import os
os.removedirs("My/Python/Folder")
It will remove all, if all the directories are empty
If folders are not empty, than only empty folder will be
deleted not all.
6
7. List Files and Folders
We can list files and folders of a specified directory.
If you are not providing the directory path than it will return
list from the current working directory.
import os
list=os.listdir("D:/")
i=1
for e in list:
print("{} {}".format(i,e))
i+=1
7
8. To get path, sub Directories, and files
import os
for path,subFolder,files in os.walk("D:/MyDir"):
for name in files:
print(name)
8
9. File Operation
We can perform basic file operation in python.
Open() function is used to open the file object in different
mode.
When we are opening a file in writing mode , and file does
not exist, than it will create a new file in specified path.
And opens a file in writing mode.
file=open("Test.txt","w")
print("File is ready to write")
9
10. Rename and remove File
Rename the File
import os
os.rename("Test.txt","Demo.txt")
Remove The file
os.remove("Demo.txt")
10
11. Writing to the file
file=open("Test.txt","w")
print("File is ready to write")
#write 5 lines
for x in range(1,5):
file.write("Hello {}".format(x))
file.close()
print("File is closed")
11
12. Write line by line
file=open("Test.txt","w")
print("File is ready to write")
for x in range(1,5):
#file.write("Hello {}n".format(x))#or
file.writelines("Hello {}n".format(x))
file.close()
print("File is close")
12
13. Read Data from the file
file=open("Test.txt","r")
# read all file data at once
data=file.read()
# read only 5 characters
data=file.read(5)
# read a single line
data=file.readline()
# returns a list containing comma separated lines
data=file.readlines()
print(data)
file.close()
13
14. Read Data using for Loop
Read data line by line from a file.
file=open("Test.txt","r")
for line in file:
print(line)
14
15. Copy Image file
We can read and write binary data too.
source=open("Indore.jpg","rb")
dest=open("CopyIndore.jpg","wb")
data=source.read()
dest.write(data)
source.close()
dest.close()
print("File copied")
15
16. File Attribute
By default it will open in reading mode
file=open("Test.txt")
print("File Name:",file.name)
print("File mode:",file.mode)
print("File is closed:",file.closed)
16
17. File pointer’s Position
Tell(): tell method returns the file pointer location
Seek(int): we can reposition the file pointer
file=open("Test.txt","r")
print("File pointer Location ",file.tell())
#read all data, pointer will reach to the EOF
print(file.read())
#now repoistion to the 1st position
file.seek(0)
file.close()
17
19. Serialization
Serialization is the process to convert the object into
byte stream.
We can send the object to a file, network , Data base
after that.
pickle module is used to write the serialized object into
the file.
19
21. Write Object into a file
import pickle
file=open("Mobile.ser","wb")
pickle.dump(Mobile,file)
file.close()
print("Object state saved into a file")
21
23. Resource Management
Whenever we open a file we have to close it.
When we open a file using a with statement then we do
not need it close it by close method.
The file is automatically closed when the bock is finished.
The file will auto close when the with block will finish the
execution
with open("Test.txt") as file:
for lines in file:
print(lines)
print("Is file closed ?",file.closed)
23
24. File Operation Modes
r:
opens a file in reading mode. It is a default mode.
w:
if file exist open it in writing mode, if not then it will create it.
a:
open file in append mode.
rb:
open a binary file in reading mode.
wb:
open a binary file in writing mode.
ab:
open a binary file in appending mode.
r+:
reading writing both
w+:
reading writing both
24
25. Disclaimer
This is a educational Presentation to make
programming easier.
We have used images of different URLs to make
presentation better.
We respect the work of the owners of the URLs.
25