Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
string = "Karma police, arrest this man, he talks in maths"
byte_string = string.encode("utf-8")
hex_string = byte_string.hex()
print("Hex: ".format(hex_string))
I am trying to print out the hexadecimal value of the string, but the output is empty
ouput-> Hex:
What should I change in order to print out the hexadecimal value?
You forgot placeholder for .format()
string = "Karma police, arrest this man, he talks in maths"
byte_string = string.encode("utf-8")
hex_string = byte_string.hex()
print("Hex: {}".format(hex_string))
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
def ShowData(data = (x)):
for r in data:
print (“{:}, {:.2f}”.format(x, x))
keep getting this error:
File "<ipython-input-10-9963f96f39ca>", line 8
print (“{:}, {:.2f}”.format(x, x))
^
SyntaxError: invalid character in identifier
Replace the “ charachter with this " ?
# data is a list of lists
def ShowData(data = (x)):
for r in data:
print ("{:}, {:.2f}".format(x, x))
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have this string:
m = 'Film/6702-BRINGING-UP-BABY" da'
and the following regax, that tries to find words that start with 'd':
movie = re.findall(r'^d.*', m)
print(movie)
the result is:
[]
and I can not understand why - there is a match in the string('da'), so why wont it find it?
I an working with pycharm, python 3.6
Using \b as boundary character we can find the words starting with specific character
import re
m = 'Film/6702-BRINGING-UP-BABY" da'
movie = re.findall(r'\bd.*', m)
print(movie)
output
['da']
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
In my code below, the times variable prints data in calendar and business time. Some of the data have numbers and others print the value 'None'. I would like to only print data that does not have the value 'None'. When I run my code I still get all of the data printed.
for ticket1 in ticket_list1:
for ticket2 in ticket_list2:
times = ticket2['reply_time_in_minutes']
ticket_id = ticket2['ticket_id']
assignee = ticket1['assignee_id']
priority = ticket1['priority']
if ticket1['assignee_id'] != ticket1['requester_id']:
if times['calendar'] != 'None':
print("%s %20s %20s %20s" % (times, ticket_id,
assignee, priority))
Remove the quotes around none. None is actually a value - of <type 'NoneType'>. So it cannot be compared to a string.
if times['calendar'] != None:
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I thought that the following would return True but that was not the case.
"Hey guys"[:4] == "Hey"
Printing both "Hey guys"[:4] and "Hey" prints out Hey. So I don't understand why would it be False under the == operator.
"Hey guys"[:4] means you want the first 4 characters of "Hey guys" which includes the space. You only want the first 3 characters so it should be "Hey guys"[:3].
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
In Python 2.7, the function bytearray.fromhex(string) gives:
ValueError: non-hexadecimal number found in fromhex() arg at position x
when the string has '16' in it, like in for example:
0200FF001603000E30D03, 0200FF001603004401A03
It's like failing if it was decimal and was '84102' just for having '10', the base, in it.
How can I avoid that error?
There is no problem with 16 existed in the string, the problem is that you try to encode odd length strings - try any valid string with even length and you will see that it is works.