- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 40 Articles
Manogna
141 Views
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
Manogna
231 Views
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
Manogna
10K+ Views
For a pure python module you can find the location of the source files by looking at the module.__file__. For example, >>> import mymodule >>> mymodule.__file__ C:/Users/Ayush/mymodule.py Many built in modules, however, are written in C, and therefore module.__file__ points to a .so file (there is no module.__file__ on Windows), and ... Read More
Manogna
1K+ Views
For a pure python module you can find the location of the source files by looking at the module.__file__. For example, >>> import mymodule >>> mymodule.__file__ C:/Users/Ayush/mymodule.py Many built-in modules, however, are written in C, and therefore module.__file__ points to a .so file (there is no module.__file__ on Windows), and therefore, ... Read More
Manogna
426 Views
The function reload(moduleName) reloads a previously loaded module (assuming you loaded it with the syntax "importmoduleName" without exiting the script. It is intended for conversational use, where you have edited the source file for a module and want to test it without leaving Python and starting it again. For example, ... Read More
Manogna
3K+ Views
This problem can be solved by reversing the string, reversing the string to be replaced, replacing the string with reverse of string to be replaced with and finally reversing the string to get the result. You can reverse strings by simple slicing notation - [::-1]. To replace the string you can ... Read More
Manogna
2K+ Views
This type of sort in which you want to sort on the basis of numbers within string is called natural sort or human sort. For example, if you have the text:['Hello1', 'Hello12', 'Hello29', 'Hello2', 'Hello17', 'Hello25'] Then you want the sorted list to be:['Hello1', 'Hello2', 'Hello12', 'Hello17', 'Hello25', 'Hello29'] and not:['Hello1', 'Hello12', ... Read More
Manogna
6K+ Views
You can use regexes to remove the ANSI escape sequences from a string in Python. Simply substitute the escape sequences with an empty string using re.sub(). The regex you can use for removing ANSI escape sequences is: '(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]'.For example, import re def escape_ansi(line): ansi_escape =re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]') ... Read More
Manogna
132 Views
It is a general thumb rule that though you can catch all exceptions using code like below, you shouldn’t:try: #do_something() except: print "Exception Caught!"However, this will also catch exceptions like KeyboardInterrupt we may not be interested in. Unless you re-raise the exception right away – we ... Read More
Manogna
200 Views
Only a single except clause in a try block is invoked. If you want the exception to be caught higher up then you will need to use nested try blocks.Let us write 2 try...except blocks like this:try: try: 1/0 except ArithmeticError as e: if str(e) == "Zero division": print ("thumbs ... Read More