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.
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 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 7 years ago.
Improve this question
I'm trying to sort each string inside a list. For example, if I have the list ['bca', 'fed'] then I want my function to return ['abc', 'def'].
Currently trying to do this like so:
lines = [''.join.(sorted(e)) for e in lines]
What's wrong with this syntax?
Just remove the redundant dot (.):
lines = [''.join(sorted(e)) for e in lines]
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 7 years ago.
Improve this question
I am trying to take 4 numbers as string and split them into 4 elements. and convert each of them into integer and save it in a list. What am I doing wrong here?
mask = "250.250.0.0"
string = mask.split(".")
toInt = [int[i] for i in string]
print(toInt)
error message says type object is not subscriptable
use int(i) instead of int[i], int is not subscriptable
int is a builtin-class that provides no implementation for subscription in array-like fashion.
To convert to an integer you should use int like this:
toInt = [int(i) for i in string]
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 8 years ago.
Improve this question
I am trying to convert strings (which I have in a list) to datetimes.
I tried this:
import datetime
list = [
'12-October-2014-18:30',
'12-October-2014-19:30',
'12-October-2014-20:00',
'12-October-2014-20:30',
'13-October-2014-00:30',
]
for item in list:
item_time = datetime.datetime.strptime(item, "%m-%B-%Y-%H-%M")
print item_time
but I get this error:
ValueError: time data '12-October-2014-18:30' does not match format '%m-%B-%Y-%H-%M'
I dont see the Error, can somebody help please?
There are two things wrong.
for '%m-%B-%Y-%H-%M', your date should be: '12-October-2014-18-30'
In some you have 12th where it should just be 12 and in all of them you have 18:30 but need it to be 18-30
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 9 years ago.
Improve this question
I am new to this and am receiving an error that says print (line 5) is an invalid syntax
from random import randint
r=randint
while True:
s=int(input('How many sides would you like on your die')
print (r(1,s))
The problem is not actually on line 5, but on line 4. You have two ( brackets but only one ). In search of the final ) the Python interpreter checks the following line, and only at that point does it raise the error.
s=int(input('How many sides would you like on your die')
^
There is a closing parenthesis missing.