×
Home
Jobs
Tools
Coding Ground
Current Affairs
UPSC Notes
Online Tutors
Whiteboard
Net Meeting
Tutorix
Login
Packages
Categories
Java
JSP
iOS
HTML
Android
Python
C Programming
C++ Programming
C#
PHP
CSS
Javascript
jQuery
SAP
SAP HANA
Data Structure
RDBMS
MySQL
Mathematics
8085 Microprocessor
Operating System
Digital Electronics
Analysis of Algorithms
Mobile Development
Front End
Web Development
Selenium
MongoDB
Computer Network
General Topics
Library
Videos
Q/A
eBooks
Login
Library
Videos
eBooks
Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Selected Reading
UPSC IAS Exams Notes
Developer's Best Practices
Questions and Answers
Effective Resume Writing
HR Interview Questions
Computer Glossary
Who is Who
Manogna
has Published
66
Answers
What does "print >>" do in python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:47:18
"print >>" is a syntax to extend the standard 'print' statement so that it can be used to print to any file-like object, instead of the default sys.stdout. So it can be used to print directly to files.ExampleFor example, you open a file called my_file, then you can write to ...
Read More
What does open() function do in Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:46:47
The function open() opens a file. You can use it like: f = open('my_file', 'r+') my_file_data = f.read() f.close() The above code opens 'my_file'in read mode then stores the data it reads from my_file in my_file_data and closes the file. The first argument of open is the name of the file and ...
Read More
What does close() function do in Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:46:16
The function close() closes an open file. For example: f = open('my_file', 'r+') my_file_data = f.read() f.close() The above code opens 'my_file'in read mode then stores the data it reads from my_file in my_file_data and closes the file. When you open a file, the operating system gives a file handle to read/write ...
Read More
What is difference between raw_input() and input() functions in Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:45:03
The function raw_input() presents a prompt to the user (the optional arg of raw_input([arg])), gets input from the user and returns the data input by the user in a string. For example, name = raw_input("What isyour name? ") print "Hello, %s." %nameThis differs from input() in that the latter tries ...
Read More
How to work with a text file in Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:44:25
A text file is any file containing only readable characters. The opposite of text files, "binary" files are any files where the format isn't made up of readable characters. Binary files can range from image files like JPEGs orGIFs, audio files like MP3s or binary document formats like Word or ...
Read More
How to read text file into a list or array with Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:43:19
f = open('my_file.txt', 'r+') my_file_data = f.read() f.close()The above code opens 'my_file.txt' in read mode then stores the data it reads from my_file.txt in my_file_data and closes the file. The read function reads the whole file at once. You can use the following to read the file line by line ...
Read More
How to open a file in binary mode with Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:42:28
"Binary" files are any files where the format isn't made up of readable characters. Binary files can range from image files like JPEGs or GIFs, audio files like MP3s or binary document formats like Word or PDF. In Python, files are opened in text mode by default. To open files ...
Read More
How to open a binary file in append mode with Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:41:50
"Binary" files are any files where the format isn't made up of readable characters. Binary files can range from image files like GIFs, audio files like MP3s or binary document formats like Word or PDF. To open files in binary append mode, when specifying a mode, add 'ab' to it.For ...
Read More
How to open a file in read and write mode with Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:41:17
To open files in read/write mode, specify 'w+' as the mode. For example, f = open('my_file.txt', 'w+') file_content = f.read() f.write('Hello World') f.close() Above code opens my_file.txt in write mode, stores the file content in file_content variable and rewrites the file to contain "Hello World". You can also use r+ mode ...
Read More
How to open a binary file in read and write mode with Python?
Python
Server Side Programming
Programming
Manogna
Published on 21-Dec-2017 17:40:24
To open binary files in binary read/write mode, specify 'w+b' as the mode(w=write, b=binary). For example, f = open('my_file.mp3', 'w+b') file_content = f.read() f.write(b'Hello') f.close()Above code opens my_file.mp3 in binary read/write mode, stores the file content in file_content variable and rewrites the file to contain "Hello" in binary. You can ...
Read More
1
2
3
4
5
6
7
Next
Advertisements
Print
Add Notes
Bookmark this page
Report Error
Suggestions
Save
Close
Dashboard
Logout