- 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
How to get signal names from numbers in Python?
There is no straightforward way of getting signal names from numbers in python. You can use the signal module to get all its attributes. Then use this dict to filter the variables that start with SIG and finally store them in a dice. For example,
Example
import signal sig_items = reversed(sorted(signal.__dict__.items())) final = dict((k, v) for v, k in sig_items if v.startswith('SIG') and not v.startswith('SIG_')) print(final)
Output
This will give the output:
{<Signals.SIGTERM: 15>: 'SIGTERM', <Signals.SIGSEGV: 11>: 'SIGSEGV', <Signals.SIGINT: 2>: 'SIGINT', <Signals.SIGILL: 4>: 'SIGILL', <Signals.SIGFPE: 8>: 'SIGFPE', <Signals.SIGBREAK: 21>: 'SIGBREAK', <Signals.SIGABRT: 22>: 'SIGABRT'}
Advertisements