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 9 years ago.
Improve this question
Can some one suggest equivalent code in python for below line
UInt32.Parse(("000000" + hexfileln.Substring(1, 2)), NumberStyles.HexNumber);
It is pointless to prefix a hex number with zeros. Ignoring that, and noting that the int constructor accepts a string argument and the base, you can use int to parse a hexadecimal number:
int(hexfileln[1:3], 16)
Related
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 wrote what should show if 2 is called in the if command in Python, but it doesn't work.
if baslangic == 2:
print("meslekler:",meslekler)
When you're using input to read in the value of baslangic, it will be a string by default.
Comparing a string to a an integer will never be True ('2' vs 2 - one is a numeric value, the other is a sequence of characters), so you'll have to convert them to the same format.
Either use int(input('Foo? ')) to convert the input to an int when you read it (if the user is only expected to type in an integer), or compare it to a string:
if baslangic == '2':
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
eg-In this instead of using 21 (a value), I want to use a variable to generalize it
print("{:-^21}".format(".|."*(2*(i+1)-1)))
I want to use something like this
print("{:-^M}".format(".|."*(2*(i+1)-1)))
That can easily enough be done. For example:
M = 40
i = 3
print("{val:-^{width}}".format(width=M, val=".|."*(2*(i+1)-1)))
Outputs:
---------.|..|..|..|..|..|..|.----------
You could also do it with f-strings (note the outer ' because " is used on the inner expression):
print(f'{".|."*(2*(i+1)-1):-^{M}}')
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'd like to convert a number like 1323.67 to 1.323,67, how can I do that?
I've tried this
f'{1325.76:.,2f}'
but it prints out 1,325.76
I excpected f'{1325.76:.,2f}' to be 1.325,75 but it's 1,325.76
If you can use external modules, I would suggest you to use babel
>>> from babel.numbers import format_decimal
>>> format_decimal(1323.67, locale='de_DE')
'1.323,67'
The format is
f'{1325.76:,.2f}' and not
f'{1325.76:.,2f}'
:,.2f is what you want. Which means , as separator with 2 decimal positions.
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 4 years ago.
Improve this question
I am trying to convert a tuple:
('Cobra',)
to a string, which when printed yields:
Cobra
#Assuming you have a list of tuples
sample = [('cobra',),('Cat',),('Dog',),('hello',),('Cobra',)]
#For each tuple in the list, Get the first element of each tuple
x = [i[0] for i in sample]
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
How do I tell a script to compare a string with the names of all materials? This following code does not work:
for i in len(bpy.data.materials):
if str(color) == bpy.data.materials[i].name:
mat = bpy.data.materials[i]
mesh.materials.append(mat)
break
Error:
TypeError: 'int' object is not iterable (line 1)
Thanks.
That first line needs to be changed to for i in range(len(bpy.data.materials)):.
Alternatively, you could write the following instead:
for mat in bpy.data.materials:
if str(color) == mat.name:
mesh.materials.append(mat)
break