I currently have
".".join(str(z) for z in [int(x, 16) for x in (re.sub(r'(.{2})(?!$)', r'\1.', "00112233")).split('.')])
'xx.xx.xx.xx'
which works but when i try to use it via the python -c switch it fails ?
[root@monty ~]# python -c "import re ; ".".join(str(z) for z in [int(x, 16) for x in (re.sub(r'(.{2})(?!$)', r'\1.', "00112233")).split('.')])"
python -c "import re ; ".".join(str(z) for z in [int(x, 16) for x in (re.sub(r'(.{2})(?"import re ; ".".join(str(z) for z in [int(x, 16) for x in (re.sub(r'(.{2})(?python)', r'\1.', "00112233")).split('.')])")', r'\1.', "00112233")).split('.')])"
-bash: syntax error near unexpected token `str'
Any ideas ?
Well, the answer to this question is NO. Unlike any other programming language, python language does not have switch statement functionality.
Switch-case statement is a powerful programming feature that allows you control the flow of your program based on the value of a variable or an expression. You can use it to execute different blocks of code, depending on the variable value during runtime.
From version 3.10 upwards, Python has implemented a switch case feature called “structural pattern matching”. You can implement this feature with the match and case keywords.
getattr() in Python is used to invoke a function call. The lambda keyword in Python is used to define an anonymous function. In case the user gives an invalid input, lambda will invoke the default function.
Looks like a quoting issue on the command line.
Try wrapping the Python string in single quotes instead, and not using single quotes inside it.
You can also escape the quotes that collide with the shell's interpretation, using \"
.
$ python -c 'import re;print ".".join(str(z) for z in [int(x, 16) for x in (re.sub(r"(.{2})(?!$)", r"\1.", "00112233")).split(".")])'
0.17.34.51
Note: as your not running the python interpretor any more you need to explicitly print the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With