The document discusses files in Python. It defines a file as an object that stores data, information, settings or commands used with a computer program. There are two main types of files - text files which store data as strings, and binary files which store data as bytes. The document outlines how to open, read, write, append, close and manipulate files in Python using functions like open(), read(), write(), close() etc. It also discusses pickling and unpickling objects to binary files for serialization. Finally, it covers working with directories and running other programs from Python.
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaEdureka!
YouTube Link: https://youtu.be/JnFfp81VbOs
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on 'Multithreading in Python'' will help you understand the concept of threading in python. Below are the topics covered in this live PPT:
What is multitasking in Python?
Types of multitasking
What is a thread?
How to achieve multithreading in Python?
When to use multithreading?
How to create threads in Python?
Advantages of multithreading
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Command-line arguments are given after the name of the program in command-line shell of Operating Systems.
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.
An object is created using the constructor of the class. This object will then be called the instance of the class.
All data values in Python are encapsulated in relevant object classes. Everything in Python is an object and every object has an identity, a type, and a value. Like another object-oriented language such as Java or C++, there are several data types which are built into Python. Extension modules which are written in C, Java, or other languages can define additional types.
To determine a variable's type in Python you can use the type() function. The value of some objects can be changed. Objects whose value can be changed are called mutable and objects whose value is unchangeable (once they are created) are called immutable.
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on File Handling with Python covers all the important aspects of using files in Python right from the introduction to what fields are, all the way till checking out the major aspects of working with files and using the code-first approach to understand them better.
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
2D array in C++ language ,define the concept of c++ Two-Dimensional array .with example .and also Accessing Array Components concept.and Processing Two-Dimensional Arrays.
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaEdureka!
YouTube Link: https://youtu.be/JnFfp81VbOs
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on 'Multithreading in Python'' will help you understand the concept of threading in python. Below are the topics covered in this live PPT:
What is multitasking in Python?
Types of multitasking
What is a thread?
How to achieve multithreading in Python?
When to use multithreading?
How to create threads in Python?
Advantages of multithreading
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Command-line arguments are given after the name of the program in command-line shell of Operating Systems.
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.
An object is created using the constructor of the class. This object will then be called the instance of the class.
All data values in Python are encapsulated in relevant object classes. Everything in Python is an object and every object has an identity, a type, and a value. Like another object-oriented language such as Java or C++, there are several data types which are built into Python. Extension modules which are written in C, Java, or other languages can define additional types.
To determine a variable's type in Python you can use the type() function. The value of some objects can be changed. Objects whose value can be changed are called mutable and objects whose value is unchangeable (once they are created) are called immutable.
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on File Handling with Python covers all the important aspects of using files in Python right from the introduction to what fields are, all the way till checking out the major aspects of working with files and using the code-first approach to understand them better.
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
2D array in C++ language ,define the concept of c++ Two-Dimensional array .with example .and also Accessing Array Components concept.and Processing Two-Dimensional Arrays.
Text Input / Output: Files, Streams, Standard Library Input / Output Functions, Formatting Input / Output Functions, Character Input / Output Functions, Binary Input / Output: Text versus Binary Streams, Standard Library, Functions for Files, Converting File Type
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.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
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.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
3. Introduction
A file is an object on a computer that stores data, information, settings, or commands used
with a computer program
Advantages of files
- Data is stored permanently
- Updation becomes easy
- Data can be shared among various programs
- Huge amount of data can be stored
4. Files
Types
Text Binary
Stores the data in the form of strings Stores data in the form of bytes
Example:
“Ram” is stored as 3 characters
890.45 is stored as 6 characters
Example:
“Ram” is stored as 3 bytes
89000.45 is stored as 8 bytes
Examples:
.txt, .c, .cpp
Examples:
.jpg, .gif or .png
5. Files
Opening a file
Name open()
Syntax file_handler = open("file_name", "open_mode", "buffering")
filename : Name of the file to be opened
open_mode: Purpose of opening the file
buffering: Used to stored the data temporarily
Opening Modes
w - To write the data
- If file already exist, the data will be lost
r - To read the data
- The file pointer is positioned at the begining of the file
a - To append data to the file
- The file pointer is placed at the end of the file
w+ - To write and read data
- The previous data will be deleted
r+ - To read and write
- The previous data will not be deleted
- The file pointer is placed at the begining of the file
a+ - To append and read data
- The file pointer will be at the end of the file
x - To open the file in exclusive creation mode
- The file creation fails, if already file exist
Example
f = open("myfile.txt", "w")
Here, buffer is optional, if omitted 4096 / 8192 bytes will be considered.
6. Files
Closing a file
Name close()
Syntax f.close()
Example #Open the file
f = open("myfile.txt", "w")
#Read the string
str = input("Enter the string: ")
#Write the string into the file
f.write(str)
#Close the file
f.close()
7. Files
Working with text files containing strings
To read the content from files,
f.read() : Reads all lines, displays line by line
f.readlines() : Displays all strings as elements in a list
f.read().splitlines(): To suppress the "n" in the list
Program
#To create a text file to store strings
#Open the file
f = open("myfile.txt", "r")
#Read the data from a file
str = f.read() #Reads all data
#Display the data
print(str)
#Close the file
f.close()
Note:
"""
f.read(n): Will read 'n' bytes from the file
"""
8. Files
Working with text files containing strings
f.seek(offset, fromwhere)
- offset : No. of bytes to move
- fromwhere : Begining, Current, End
- Example : f.seek(10, 0), move file handler from Beg forward 10 bytes.
# Appending and then reading strings, Open the file for reading data
f = open('myfile.txt', 'a+')
print('Enter text to append(@ at end): ')
while str != '@':
str = input() # accept string into str
# Write the string into file
if (str != '@'):
f.write(str+"n")
# Put the file pointer to the beginning of the file
f.seek(0,0)
# Read strings from the file
print('The file cotents are: ')
str = f.read()
print(str)
# Closing the file
f.close()
9. Files
Knowing If file exists or not
Sample:
if os.path.isfile(fname):
f = open(fname, "r")
else:
print(fname + "Does not exist")
sys.exit() #Terminate the program
# Checking if file exists and then reading data
import os, sys
# open the file for reading data
fname = input('Enter filename : ')
if os.path.isfile(fname):
f = open(fname, 'r')
else:
print(fname+' does not exist')
sys.exit()
# Read strings from the file
print('The file contents are: ')
str = f.read()
print(str)
# Closing the file
f.close()
10. Files
Exercise
Problem- 1
To count number of lines, words and characters in a text file
Problem- 2
To copy an image from one file to another
11. Files
The with statement
1. Can be used while opening the file
2. It will take care of closing the file, without using close() explicitly
3. Syntax: with open("file_name", "openmode") as fileObj:
Program -1
# With statement to open a file
with open('sample.txt', 'w') as f:
f.write('I am a learnern')
f.write('Python is attactiven')
Program -2
# Using with statement to open a file
with open('sample.txt', 'r') as f:
for line in f:
print(line)
12. Files
The pickle + Unpickle
1. To store the data of different types, we need to create the class for it.
2. Pickle/Serialization:
- Storing Object into a binary file in the form of bytes.
- Done by a method dump() of pickle module
- pickle.dump(object, file)
3. Unpickle/Deserialization
- Process where byte stream is converted back into the object.
- Object = pickle.load(file)
13. Files
The pickle: Program
# A python program to create an Emp class witg employee details as instance variables.
# Emp class - save this as Emp.py
class Emp:
def_init_(self, id, name, sal):
self.id = id
self.name = name
self.sal = sal
def display(self):
print("{:5d} {:20s} {:10.2f}".format(self.id, self.name,self.sal))
# pickle - store Emp class object into emp.dat file
import Emp, pickle
# Open emp.dat file as a binary file for writing
f = open('emp.dat', 'wb')
n = int(input('How many employees? '))
for i in range(n):
id = int(input('Enter id: '))
name = input('Enter name: ')
sal = float(input('Enter salary: '))
for i in range(n):
id = int(input('Enter id: '))
name = input('Enter name: ')
sal = float(input('Enter salary: '))
# Create Emp class object
e = Emp.Emp(id, name, sal)
# Store the object e into the file f
pickle.dump(e, f)
#close the file
f.close()
14. Files
The unpickle: Program
# A python program to create an Emp class witg employee details as instance variables.
# Emp class - save this as Emp.py
class Emp:
def_init_(self, id, name, sal):
self.id = id
self.name = name
self.sal = sal
def display(self):
print("{:5d} {:20s} {:10.2f}".format(self.id, self.name,self.sal))
# unpickle or object de-serialization
import Emp, pickle
# Open the file to read objects
f = open('emp.dat', 'rb')
print('Employees details: ')
while True:
try:
#Read object from file f
obj = pickle.load(f)
# Display the contents of employee obj
obj.display()
except EOFError:
print('End of file reached....')
break
#Close the file
f.close()
15. Random Binary File Access
using mmap
1. Using mmap, binary data can be viewed as strings
mm = mmap.mmap(f.fileno(), 0)
2. Reading the data using read() and readline()
print(mm.read())
print(mm.readline())
3. We can also retrieve the data using teh slicing operator
print(mm[5: ])
print(mm[5: 10])
4. To modify / replace the data
mm[5: 10] = str
5. To find the first occurrance of the string in the file
n = mm.find(name)
6. To convert name from string to binary string
name = name.encode()
7. To convert bytes into a string
ph = ph.decode()
Demonstrate the code
16. Zip & Unzip
Zip:
- The file contents are compressed and hence the size will be reduced
- The format of data will be changed making it unreadable
Original
File
Compressed
File
Zipping
Unzipping
17. Zip & Unzip
Programs
# Zipping the contents of files
from zipfile import *
# create zip file
f = zipfile('test.zip', 'w', 'ZIP_DEFLATED')
# add some files. these are zipped
f.write('file1.txt')
f.write('file2.txt')
f.write('file3.txt')
# close the zip file
print('test.zip file created....')
f.close()
# A Python program to unzip the contents of the files
# that are available in a zip file.
# To view contents of zipped files
from zipfile import*
# open the zip file
z = Zipfile('test.zip', 'r')
# Extract all the file names which are int he zip file
z.extractall()
18. Working With Directories
Program-1
# A Python program to know the currently working directory.
import os
# get current working directory
current = os.getcwd()
print('Current sirectory= ', current)
19. Working With Directories
Program-2
# A Python program to create a sub directory and then sub-sun directory in the current
directory.
import os
# create a sub directory by the name mysub
os.mkdir('mysub')
# create a sub-sub directory by the same mysub2
os.mkdir('mysub/mysub2')
20. Working With Directories
Program-3
# A Python program to use the makedirs() function to create sub and sub-sub directories.
import os
# create sub and sub-sub directories
os.mkdirs('newsub/newsub2')
21. Working With Directories
Program-4
# A Python program to remove a sub directory that is inside another directory.
import os
# to remove newsub2 directory
os.rmdir('newsub/newsub2')
22. Working With Directories
Program-5
# A Python program to remove a group of directories in the path
import os
# to remove mysub3, mysub2 and then mysub.
os.removedirs('mysub/mysub2/mysub3')
24. Working With Directories
Program-7
# A Python program to display all contents of the current directory.
import os
for dirpath, dirnames, filenames in os.walk('.'):
print('Current path: ', dirpath)
print('Directories: ', dirnames)
print('Files: ', filenames)
print()
25. Running other programs
Program-7
The OS module has the system() method that is useful to run an executableprogram from our
Python program
Example-1
os.system(‘dir’) Display contents of current working DIR
Example-2 os.system(‘python demo.py’) Runs the demo.py code