casting

Changing data types twice in one conditional statement (Python)

Changing data types twice in one conditional statement (Python) Question: Pretty basic question, but I am trying to write a simple while loop in which I first need an input as int. But in order to break out of said loop, I want to be able to write ‘quit’ which is a string. How do …

Total answers: 2

'numpy.float64' object does not support item assignment alignment sequences

'numpy.float64' object does not support item assignment alignment sequences Question: I am developing a program to calculate the sp scores of aligned sequences from the Percent Identity Matrix obtained on Clustal Omega. I have problems with element casting in python. I’m trying to store the values read from a text file in an array of …

Total answers: 1

Type conversion of custom class to float

Type conversion of custom class to float Question: I have a class customInt, which looks something like this: class customInt: def __init__(self, value): self.value=int(value) def __add__(self, other): return foo(self.value+other.value) # do some other stuff obj=foo(1.23) Is it possible to create an operator/attribute/property/… to cast the object obj to a float, so that it’s possible to …

Total answers: 1

pandas astype doesn't work as expected (fails silently and badly)

pandas astype doesn't work as expected (fails silently and badly) Question: I’ve encountered this strange behavior of pandas .astype() (I’m using version 1.5.2). When trying to cast a column as integer, and later requesting dtypes, all seems fine. Until you try to extract the values by row, when you get inconsistent types. Code: import pandas …

Total answers: 1

Split AttributeError, "'str' object has no attribute 'spilt'"

Split AttributeError, "'str' object has no attribute 'spilt'" Question: text is shown below, I’ve searched high and low for the solution, but can’t find anything. any help is appreciated import random from aiohttp import request from aiohttp import web from random import randint response = request.__get__(‘https://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text%2Fplain’) r = request.__get__(response) dootdoot = r indivial_words = str(dootdoot).spilt() …

Total answers: 1

How do I convert a string of a floating point decimal number into a float type?

How do I convert a string of a floating point decimal number into a float type? Question: I have a 32bit floating point decimal in sting format. I want to get it into float format. For exmaple, how do I convert this string: ‘01000010000000001110111010011000’ into this float: 32.233001709 Perhaps there is some intermediate step where …

Total answers: 1

Strange character added when decoding with urllib

Strange character added when decoding with urllib Question: I’m trying to parse a query string like this: filename=logo.txt\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01x&filename=.hidden.txt Since it mixes bytes and text, I tried to alter it such that it will produce the desired escaped url output like so: extended = ‘filename=logo.txt\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01x&filename=.hidden.txt’ fixbytes = bytes(extended, ‘utf-8’) fixbytes = fixbytes.decode("unicode_escape") algoext = ‘?’ + …

Total answers: 3

X is not defined

X is not defined Question: I’m going through basic pythonprinciples problems, and one of them lists the instructions as: Write a function named make_day_string that takes an integer named day and returns the string "it is day X of the month" where X is the value of the day parameter. For example, calling make_day_string(3) should …

Total answers: 1

How do I fix this error: TypeError: unsupported operand type(s) for *: 'float' and 'function' in python

How do I fix this error: TypeError: unsupported operand type(s) for *: 'float' and 'function' in python Question: How do I resolve this TypeError TypeError: unsupported operand type(s) for *: ‘float’ and ‘function’ Here is my code: #calculate overtime pay def overtime_pay(weekly_pay, regular_rate, overtime_hrs ): overtime_p = weekly_pay + ((regular_rate*1.5)*overtime_hrs) print(‘Overtime pay for ‘ + …

Total answers: 2