remove hex value from string [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How do I remove the hex value from a string in Python 2.7? Here is the string,
\xffDSI\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x00\x08\x00\x00\x00\x00\x00\x00\x00#\x00\x00\x00#\x00\x00\x00\x01\x04\xb3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x04\x00\x02\x00\x01\x00\x01\x00\x02\x00\x06\x00\x06"\x00\x00\x00\x00c\x01,\x00\x00\x06&\x00\x00\x00\x01\x01,\x00\x00\x06\'\x00\x00\x11\x98\x00\x19\x00\x00\x00(\x00\x00\x00\x00\x00\x0011_w\x00\x00\x00\x00\x00\x006\x00A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01,\x00\x00\x17\xbf\x00\x00\x11\x98\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
#b4
,sudd5ly1
!
toddl]
0
able
to
use
a
comput]
to
play
games4
\x00$\x00\x00\x018\x00\x00\x00\x00\x00\x01\x00\x19\x00\x02\x00\x03\x00\x04\x00\x05\x00\x1d\x00\x1f\x00\x06\x00\x07\x00\x08\x00\t\x00'],
['\x00\x0b\x00\x0c\x00\r\x00\x1b\x00\x0e\x00\x0f\x00\x10\x00\x13\x00\x11\x00\x14\x00\x1c\x00\x18\x00
I want to display only #b4 to games4. All the hex values should be removed. Thank you.
What I am trying to do is to read in the file type *.dxb, which display braille font. I was able to read the file but the output showed me all those \xffDSI\x00... and then #b4 ,sudd5ly1
The #b4 ,sudd5ly1 is only the part that I want the output to show so that I can do a comparison with other file.
Thank you again.

You can use something like this:
import string
s = '\xffDSI....'
cleaned = ''.join(c for c in s if c in string.printable)
This uses printable as the definition of "not a hex value", though it does include \x0b and \x0c (both printable whitespace characters).

Related

Variable with " " in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
Trying to make a for loop work in Python I came across a variable declared with "".
i.e: res=""
What is the purpose of the quotes?
Want to know what happens in there.
res="" is an empty string. This can be used later to, for example:
Add another string to it: res += "ABC"
Check whether there is a result. An empty string returns False, while a string with at least 1 character returns True.
Check the length of the string by len(res).
I could go on but you get the point. It's a placeholder.

Convert a big table of value into string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
I have a table of value that i want to insert in my python code as a string :
I tried this but not working :
str(3.354219E-03 3.584506E-03 3.830603E-03 4.093597E-03 4.374646E-03
4.674992E-03 4.995957E-03 5.338959E-03 5.705510E-03 6.097227E-03
6.515837E-03 6.963188E-03 7.441252E-03 7.952137E-03 8.498098E-03
9.081543E-03 9.705044E-03 1.037135E-02 1.108341E-02 1.184435E-02
1.265753E-02 1.352655E-02 1.445522E-02 1.544766E-02 1.650823E-02
1.764162E-02 1.885282E-02 2.014718E-02 2.153040E-02 2.300859E-02
2.458826E-02 2.627639E-02 2.808042E-02 3.000831E-02 3.206855E-02
3.427025E-02 3.662310E-02 3.913749E-02 4.182451E-02 4.469601E-02
4.776465E-02 5.104398E-02 5.454845E-02 5.829352E-02 6.229571E-02
6.657268E-02 7.114329E-02 7.602769E-02 8.124744E-02 8.682555E-02)
Or another way would be to put quotation marks at the beggining and end of line but it's take too much time. If there are some options in Vim or Notepad i would be glad to here about it.
One way would of course to do it programmatically and immediately split your string so that you retrieve the desired table. If you read a multi-line string, you should use three quotation marks """.
If you are looking for a way to do it in a text editor, here are two solutions that work in VS Code (and many more editors)
Column-selection mode. Decently fast, because your inputs are all the same length. You can highlight all rows and then just add quotes accordingly.
Reg-ex replacement. You can use the following regex, see explanations here. Note that I highlighted the reg-ex mode (next to "1 of 200").
Regardless of the method, by using three quotation marks here as well, Python should be able to read your string including the "inner" quotation marks.

My strings contains " and ' how to deal with it in python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
In my code, I have a string that contains " and ' in between how to deal with it?
And it is randomly generated every time I generate a string at different positions and gives me an error when I try to print due to " or ' it marks as the end of some strings and the post characters of that string generate an error.
Edit 1:
An example for such type of string is:
85)p$85"5p9p1=p%#9>7p'81$#1
Thanks in advance
You need to escape it using the \. If your string starts with double quote, then escape \' and escape \" if starts with single one.

i want to write a python program that converts an integer to its corresponding month [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to add a error message if it exceeds 12 or if a character is entered without any if statements. here is what I have written so far:
import calender
def get_mont_name(month_number):
try:
return calender.month_name[month_number]
except IndexError:
print("'[]' is not a valid month number".format(month_number))
Your code is really close to working!
Firstly, you've spelt calendar wrong, but I assume this is just a typo.
You've slightly misused format() which is probably causing your issue. Replacing your print statement with the following should fix it:
print("{num} is not a valid month number".format(num = month_number))
The curly brackets allow the format() method to identify the parts of the string you'd like to modify.
I hope this helps!

Convert input letter to different letter [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am new to python (pardon my bad terminology). I cannot find a solution to my problem.
I am trying to make a simple encryption system. I want to convert the characters of user input to specific characters. For example: ABC would turn into ZYX.
Can anyone help me with this? Thanks.
assuming you just want a simple substitution cipher you can use the translate function:
# in python3:
# table = str.maketrans('ABC', 'ZYX')
# in python2:
from string import maketrans
table = maketrans('ABC', 'ZYX') # add the rest of the alphabet and the desired
# subsitutions
print('CBA'.translate(table))
# output: 'XYZ'

Categories