The document discusses various methods for reading from and writing to files in Python. It explains how to open files in different modes, write strings and lists to files, read from files, and perform operations on the file contents such as finding the largest or sum of numbers. It also covers using seek() to move the file cursor and working with binary files by serializing and deserializing data.
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.
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.
In this chapter we will review how to work with text files in C#. We will explain what a stream is, what its purpose is, and how to use it. We will explain what a text file is and how can you read and write data to a text file and how to deal with different character encodings. We will demonstrate and explain the good practices for exception handling when working with files. All of this will be demonstrated with many examples in this chapter
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
In this chapter we will review how to work with text files in C#. We will explain what a stream is, what its purpose is, and how to use it. We will explain what a text file is and how can you read and write data to a text file and how to deal with different character encodings. We will demonstrate and explain the good practices for exception handling when working with files. All of this will be demonstrated with many examples in this chapter
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Welcome to the first live UiPath Community Day Dubai! Join us for this unique occasion to meet our local and global UiPath Community and leaders. You will get a full view of the MEA region's automation landscape and the AI Powered automation technology capabilities of UiPath. Also, hosted by our local partners Marc Ellis, you will enjoy a half-day packed with industry insights and automation peers networking.
📕 Curious on our agenda? Wait no more!
10:00 Welcome note - UiPath Community in Dubai
Lovely Sinha, UiPath Community Chapter Leader, UiPath MVPx3, Hyper-automation Consultant, First Abu Dhabi Bank
10:20 A UiPath cross-region MEA overview
Ashraf El Zarka, VP and Managing Director MEA, UiPath
10:35: Customer Success Journey
Deepthi Deepak, Head of Intelligent Automation CoE, First Abu Dhabi Bank
11:15 The UiPath approach to GenAI with our three principles: improve accuracy, supercharge productivity, and automate more
Boris Krumrey, Global VP, Automation Innovation, UiPath
12:15 To discover how Marc Ellis leverages tech-driven solutions in recruitment and managed services.
Brendan Lingam, Director of Sales and Business Development, Marc Ellis
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Climate Impact of Software Testing at Nordic Testing DaysKari Kakkonen
My slides at Nordic Testing Days 6.6.2024
Climate impact / sustainability of software testing discussed on the talk. ICT and testing must carry their part of global responsibility to help with the climat warming. We can minimize the carbon footprint but we can also have a carbon handprint, a positive impact on the climate. Quality characteristics can be added with sustainability, and then measured continuously. Test environments can be used less, and in smaller scale and on demand. Test techniques can be used in optimizing or minimizing number of tests. Test automation can be used to speed up testing.
In his public lecture, Christian Timmerer provides insights into the fascinating history of video streaming, starting from its humble beginnings before YouTube to the groundbreaking technologies that now dominate platforms like Netflix and ORF ON. Timmerer also presents provocative contributions of his own that have significantly influenced the industry. He concludes by looking at future challenges and invites the audience to join in a discussion.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
Enhancing Performance with Globus and the Science DMZGlobus
ESnet has led the way in helping national facilities—and many other institutions in the research community—configure Science DMZs and troubleshoot network issues to maximize data transfer performance. In this talk we will present a summary of approaches and tips for getting the most out of your network infrastructure using Globus Connect Server.
2. x=open(“Smahi.txt”,
“w”)
A file memory x created in RAM, and get
connected to a file called “Smahi.txt” in
overwrite mode, which is available in
same folder, if the file not found, it will be
created automatically.
3. x=open(“Smahi.txt”,“w”)
x.write(“Debanshi ” )
A file memory x created in RAM, and get
connected to a file called “Smahi.txt”, in
overwrite mode, which is available in
same folder, if the file not found, it will be
created automatically. A string called
“Debanshi ” is written in file memory.
4. x=open(“Smahi.txt”, “w”)
x.write(“Debanshi ” )
x.close()
A file memory x created in RAM, and get
connected to a file called “Smahi.txt”,
which is available in same folder, if the file
not found, it will be created automatically.
A string called “Debanshi ” is written in
file memory. Now to transfer the contents
of the file memory to the file “Smahi.txt”
we have to disconnect the file memory x
with “Smahi.txt” using the close()
5. x=open(“Smahi.txt”, “w”)
y=“Debanshi ”
x.write(y)
x.close()
A string variable y is created and
initialized with “Debanshi ”, after
that the same is written in file
memory x from which the contents is
transferred to the file “Smahi.txt”
using the function close()
16. write() is used to
write string,
whereas writelines()
is used to write list
or string
17. x=open("Smahi.txt","w")
for y in range(4):
x.write(input("Enter name "))
x.close()
Program will accept 4
names and store in a
file called “Smahi.txt”
18. x=open("Smahi.txt","w")
for y in range(4):
x.write(input("Enter name
")+‘n’)
x.close()
Program will accept 4
names and store in a file
in separate lines, called
“Smahi.txt”
19. x=open("Smahi.txt","w")
for y in range(4):
x.write(input("Enter name
")+‘n’)
x.close()
Program will accept 4
names and store in a file
in separate lines, called
“Smahi.txt”
20. x=open("Smahi.txt","w")
z=[]
for y in range(4):
z.append(input("Enter name
")+'n')
x.writelines(z)
x.close()
Program will accept 4 names
and store in a file in separate
lines, called “Smahi.txt”
21. x=open("Smahi.txt","w")
z=[]
for y in range(4):
z[y].append(input("Enter name ")+'n')
x.writelines(z)
x.close()
Error:
Instead of z[y], we have to
write z
22. x=open("Smahi.txt","w")
z=[]
for y in range(4):
z.append(input("Enter name ")+'n')
x.write(z)
x.close()
Error:
write() is used to input string
not the list
23. w is used to create
the file in overwrite
mode, whereas a is
used to create the
file in append mode
24. x=open("Smahi.txt","a")
z=[]
for y in range(4):
z.append(input("Enter name
")+'n')
x.writelines(z)
x.close()
Initially if the file contains
Amit
Sumit
New names will be added after
Sumit
25. x=open("Smahi.txt","a")
z=[]
for y in range(4):
z.append(input("Enter name
")+'n')
x.writelines(z)
x.close()
Initially if the file contains
nothing, New names will be
added from beginning of the
file
58. In Binary files 1st the
data are serialized
and then stored.
59. Serialization is the
process in which the list,
tuples and the
dictionaries are
converted into byte
stream and then stored in
the file
60. Pickling converts an
object in byte stream in
such a way that it can be
reconstructed in original
form when un - pickled or
de - serialized
61. In order to work with
pickle module, we
must 1st import it
using syntax
import pickle
62. In pickle module there
are two functions
dump() and load(), 1st
one is used to store the
data in file and the 2nd
is used to access data
from the file
63. Storing data in binary file
import pickle
emp1={'name':"amit", "age":23}
emp2={'name':"sumit", "age":38}
emp3={'name':"ajay", "age":18}
em=open("emp.dat","wb")
pickle.dump(emp1,em)
pickle.dump(emp2,em)
pickle.dump(emp3,em)
print("Data dumped-written in file....
")
em.close()
64. Accessing data from binary file
import pickle
emp={}
em=open("emp.dat","rb")
try:
while True:
emp=pickle.load(em)
print(emp)
except EOFError:
em.close()
65. Accessing data from binary file
import pickle
emp={}
em=open("emp.dat","rb")
print("Name Age")
try:
while True:
emp=pickle.load(em)
print(emp['name'],'t',emp['age'])
except EOFError:
em.close()
66. Accessing selected data from binary file
import pickle
emp={ }
em=open("emp.dat","rb")
m=0
print("Name Age")
try:
while True:
emp=pickle.load(em)
if emp['age']>m:
m=emp['age']
n=emp['name']
except EOFError:
em.close()
print(n, m)
67.
68. Let the content of the file Smahi.txt is : -
Ram
Shyam
Ajay
Manoj
Rajeev
x=open("Smahi.txt")
y=x.tell()
print(y) Output
0
69. Let the content of the file Smahi.txt is : -
Ram
Shyam
Ajay
Manoj
Rajeev
x=open("Smahi.txt") Output
y=x.tell()
print(y) 0
z=x.read(2)
y=x.tell()
print(y) 2
72. Let the content of the file Smahi.txt is :
-
Ram
Shyam
Ajay
Manoj
Rajeev
x=open("Smahi.txt")
z=x.readline()
z=x.readline()
y=x.tell() OUTPUT
print(y) 12
73. Let the content of the file Smahi.txt is :
-
Ram
Shyam
Ajay
Manoj
Rajeev
x=open("Smahi.txt")
z=x.readline()
z=x.readline()
y=x.tell() OUTPUT
print(y) 12
75. Let the content of the file Smahi.txt is :
-
Ram
Shyam
Ajay
Manoj
Rajeev
x=open("Smahi.txt") OUTPUT
y=x.tell() 0
print(y) 2
x.seek(2)
y=x.tell()
print(y)
76. Let the content of the file Smahi.txt is :
-
Ram
Shyam
Ajay
x=open("Smahi.txt") Manoj
y=x.tell() Rajeev
print(y)
x.seek(12) OUTPUT
z=x.read(5) 0
print(z) Ajay
y=x.tell()
print(y) 18
77. Let the content of the Ram
file Smahi.txt is : - Shyam
Ajay
x=open("Smahi.txt") Manoj
y=x.tell() OUTPUT Rajeev
print(y) 0
x.seek(12)
z=x.read(6)
print(z) Ajay
y=x.tell()
print(y) 19
78. Let the content of the file Smahi.txt is :
-
Ram
Shyam
Ajay
x=open("Smahi.txt") Manoj
y=x.tell() Rajeev
print(y)
m=x.read(8) OUTPUT
print(m) ERROR
x.seek(-5) indexing is
y=x.tell() always
print(y) positive
81. Let the content of the file Smahi.txt is :
-
Ram
x=open("Smahi.txt", "rb") Shyam
x.seek(12) Ajay
print(x.tell()) Manoj
x.seek(-5,2) Rajeev
print(x.tell())
x.close()
Okay: - Cursor movement is allowed
from any where in “BINARY FILE”
82. Let the content of the file Smahi.txt is :
-
Ram
em=open("Smahi.txt","rb") Shyam
z=em.read() Ajay
print(em.tell()) Manoj
em.seek(0,2) Rajeev
print(em.tell())
em.close() OUTPUT
33
33
83. 0 moves from beginning
1 moves from current
position
2 moves from end
88. Let the content of the file Smahi.txt is : -
Ram
em=open(“Smahi.txt","rb+")Shyam
x=em.read() Ajay
print(em.tell()) Manoj
em.seek(100,0) Rajeev
print(em.tell()) OUTPUT
em.seek(0,0) 33
print(em.tell()) 100
y=em.read() 0
print(len(x)) 33
print(len(y)) 33
em.close() BUT……….
89. If we move the file
pointer beyond the
limit and tried to write
anything, REMEMBER
the same will be written
at that point and the
size of the file will
expand.
92. Storing data in binary file
import pickle
emp1={'name':"amit", "age":23}
emp2={'name':"sumit", "age":38}
emp3={'name':"ajay", "age":18}
em=open("emp.dat","wb")
pickle.dump(emp1,em)
pickle.dump(emp2,em)
pickle.dump(emp3,em)
print("Data dumped-written in file....
")
em.close()
93. Seek and Tell on Binary files
import pickle
emp={ }
em=open("emp.dat","rb")
print(em.tell())
try:
while True:
OUTPUT
emp=pickle.load(em) 0
print(em.tell()) 42
except EOFError: 85
em.close() 127
94. Seek and Tell on Binary files
import pickle
emp={}
bmp=[]
em=open("emp.dat",'rb')
try:
while True:
emp=pickle.load(em)
bmp.append(em.tell())
except EOFError:
em.close()
print(bmp) [42, 85,
127]
95. Seek and Tell on Binary files
import pickle z=0
emp={} em=open("emp.dat",'rb')
bmp=[] emp=pickle.load(em)
em=open("emp.dat",'rb') print(emp)
try: while z<len(bmp)-1:
while True:
em.seek(bmp[z])
emp=pickle.load(em)
emp=pickle.load(em)
bmp.append(em.tell()) print(emp)
except EOFError: z=z+1
em.close() em.close()
96. Modifying the contents of a binary file
import pickle
x=input("Please enter name to be modified ")
y=open("emp.dat","rb+")
a={ }
try:
while True:
z=y.tell()
a=pickle.load(y)
if a['name']==x:
print(a['name'],' ',a['age'])
a['age']+=5
y.seek(z)
pickle.dump(a,y)
except EOFError:
y.close()
98. Modifying the contents of a binary file (Page 2)
x=input("nnPlease enter name to be modified ")
y=open("emp.dat","rb+")
a={ }
k=0
try:
while True:
z=y.tell()
a=pickle.load(y)
if a['name']==x:
print("Name found ")
a['age']=int(input("Enter new age "))
y.seek(z)
pickle.dump(a,y)
k=1
except EOFError:
y.close()
if k==0:
print("Sorry ",x," not found ") continued ……… go to next
slide
99. Modifying the contents of a binary file (Page 3)
y=open("emp.dat","rb+")
a={}
try:
while True:
a=pickle.load(y)
print(a['name'],' ',a['age'])
except EOFError:
y.close()
101. Deleting records from a binary file (Slide
1)
import os
import pickle
y=open("emp.dat","rb+")
a={}
try:
while True:
a=pickle.load(y)
print(a['name'],' ',a['age'])
except EOFError:
y.close()
Continued………... Goto Next
Slide
102. Deleting records from a binary file (Slide 2)
x=input("nnEnter name to be deleted ")
y=open("emp.dat","rb+")
z=open("bmp.dat","wb+")
a={}
b=0
try:
while True:
a=pickle.load(y)
if a['name']!=x:
pickle.dump(a,z)
else:
b=1
except EOFError:
y.close()
z.close()
if b==1:
print("Data found, and deleted ")
else:
print("Deletion not possible ")
os.remove("emp.dat")
os.rename("bmp.dat","emp.dat") Continued………...
Goto Next Slide
103. Deleting records from a binary file (Slide
3)
y=open("emp.dat","rb+")
a={}
try:
while True:
a=pickle.load(y)
print(a['name'],' ',a['age'])
except EOFError:
y.close()
104. def enter():
import pickle
emp={}
em=open("stud.dat","wb")
x=1
for xx in range(25):
print("n")
emp['name']=input("Please enter name ")
emp['roll']=int(input("Please enter roll "))
emp['marks']=int(input("Please enter marks
"))
pickle.dump(emp,em)
print("Data dumped-written in file.... ")
em.close()
106. def modify():
import pickle
for xx in range(25):
print("n")
x=input("Please enter name to be modified ")
y=open("stud.dat","rb+")
a={}
try:
while True:
z=y.tell()
a=pickle.load(y)
if a['name']==x:
print("Data found ")
print(a['name'],' ',a['marks'], ' ',a['roll'])
print(".......and modified ")
a['marks']+=5
y.seek(z)
pickle.dump(a,y)
except EOFError:
y.close()
107. def adding():
import pickle
emp={}
em=open("stud.dat","ab")
x=1
for xx in range(25):
print("n")
emp['name']=input("Please enter name ")
emp['roll']=int(input("Please enter roll "))
emp['marks']=int(input("Please enter marks
"))
pickle.dump(emp,em)
print("Data dumped-written in file.... ")
em.close()