w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
float object has no attribute __getitem__
self.target has become a float somehow. Perhaps something like self.target = self.target[0] happened somewhere in your code? Either that, or self.target = some_variable_that_is_a_float

Categories : Python

Numpy AttributeError: 'float' object has no attribute 'exp'
Probably there's something wrong with the input values for X and/or T. The function from the question works ok: import numpy as np from math import e def sigmoid(X, T): return 1.0 / (1.0 + np.exp(-1.0 * np.dot(X, T))) X = np.array([[1, 2, 3], [5, 0, 0]]) T = np.array([[1, 2], [1, 1], [4, 4]]) print X.dot(T) print # Just to see if values are ok print [1. / (1. + e ** el) for el in [-5, -10, -15, -16]] print print sigmoid(X, T) Result: [[15 16] [ 5 10]] [0.9933071490757153, 0.9999546021312976, 0.999999694097773, 0.9999998874648379] [[ 0.99999969 0.99999989] [ 0.99330715 0.9999546 ]] Probably it's the dtype of your input arrays. Changing X to: X = np.array([[1, 2, 3], [5, 0, 0]], dtype=object) Gives: Traceback (most recent call last): File "/[...]/stackoverflow_sigmoid.

Categories : Python

Attribute error: function object has no attribute in python
Just to get this answered: def datapaths(ipaddress, testlogfile): # Unecessary code reomved (code, val) = datapaths.listDatapaths(mylib) # Unecessary code reomved You are trying to access an attribute of a function you've defined, but most likely not set. I think you need to rexamine your code.

Categories : Python

python/flask TypeError: 'float' object is not callable
You assigned range to a float in your code, don't do that otherwise you can't access the range() built-in then: if (lng != None) and (lat != None): range = 0.1 ########### Demo: >>> range = 0.1 >>> range() Traceback (most recent call last): File "<ipython-input-39-7b0c968826c1>", line 1, in <module> range() TypeError: 'float' object is not callable

Categories : Python

why float is not working in this example when one of the
Because floated elements are taken out of the normal flow (not entirely like absolutely positioned elements) - the third div in your HTML is actually sitting behind the first two floated divs, although the line box (div3) is sitting below them, as line-boxes are the only elements that floats respect. A line box is an element that belongs in the inline formatting context From the 2.1 Spec Since a float is not in the flow, non-positioned block boxes created before and after the float box flow vertically as if the float did not exist. However, the current and subsequent line boxes created next to the float are shortened as necessary to make room for the margin box of the float. http://jsfiddle.net/Adv2v/

Categories : HTML

Convert IEEE float to TI TMS320C30 32bits float in python
The following code passes your tests: def float_to_ti( f ): m, e = math.frexp(f) m *= 2 e -= 1 sign = (math.copysign(1.0, f) < 0) if f == 0.0: return (128 << 24) | (sign << 23) if sign: m += 2.0 if m == 1.0: m = 0.0 e -= 1 else: m -= 1.0 assert 0.0 <= m < 1.0 return ((e & 0xff) << 24) | (sign << 23) | int(m * (1 << 23) + 0.5) Note the different order (exponent, sign, mantissa). Note also that math.frexp() doesn't return anything in the IEEE format, so this code doesn't worry about any IEEE details: the (e & 0xff) converts the exponent (as a signed char) to an unsigned number. Finally, note that the C30 format doesn't support denormals, which means

Categories : Python

get attribute with getattr from a object in python
The parentheses are almost certainly not part of the attribute name. Get rid of them when calling getattr(). Then you need to call the method: attr_name = pattr[letter] if not attr_name.endswith("()"): print getattr(p, attr_name) else: print getattr(p, attr_name[:-2])()

Categories : Python

python: 'str' object has no attribute 'iteritems'
open('1.txt', 'r').read() returns a string not dict. >>> print file.read.__doc__ read([size]) -> read at most size bytes, returned as a string. If 1.txt contains: 'alba':'barba', 'raim':'uva' then you can use ast.literal_eval to get a dict: >>> from ast import literal_eval >>> with open("1.txt") as f: dic = literal_eval('{' + f.read() +'}') print dic ... {'alba': 'barba', 'raim': 'uva'} Instead of using str.replace you should use regex, as str.replace('alba','barba') will also replace words like 'albaa', 'balba', etc: import re def replace_all(text, dic): for i, j in dic.iteritems(): text = re.sub(r"'{}'".format(i), "'{}'".format(j), text) return text

Categories : Python

python - AttributeError: 'module' object has no attribute
Edit After reading the stacktrace again, you can see that urllib3 tries to import something from the http module. Your file is called http.py and is thus imported instead of the expected one. The actual error happens because of the circular nature of the import. Since requests hasn't finished importing completely yet. The get function in requests isn't defined yet when the http import reaches import requests again. Note: You will also want to always guard your entry point with the if __name__ == '__main__' construct. This will often avoid nasty errors for unsuspecting future developers (including yourself).

Categories : Python

Python 2.7 assertin gets error object has no attribute
There seems to be an issue with assertIn in some versions of Python. Here's an alternative that should work: a = 'a' apple = 'apple' self.assertTrue(a in apple, '{} not in {}'.format(a, apple))

Categories : Misc

how to get or set object's attribute from a list in maya python?
Unless there is a Maya specific issue that I don't know about, there are a couple of ways to do this in Python: for myObject in myList: # directly getting and setting attribute myObject.translateY = 30.0 # set a = myObject.translateY # get # alternatively, via setattr and getattr built-in functions. setattr(myObject, "translateY", 40.0) # getter which Raises exception if myObject has no "translateY" attr: a = getattr(myObject, "translateY") # getter which supplies defaultVal if myObject has no "translateY" attr a = getattr(myObject, "translateY", defaultVal) As an aside, it is bad form to call your variable "list", as this name will shadow Python's built-in list function. Better to use something like "myList" instead.

Categories : Python

Python import behaviour and 'NoneType' object has no attribute
The line "UMD has deleted ..." is the hint. You are likely using the Spyder IDE, and this non-standard behavior is described here: Spyder - UMD has deleted: module Now the additional issue is that the module untitled0.py has been unloaded (and reloaded). However, your pre-existing instance a has a class that is the one that existed in the old copy of the module. So its method f() invokes the old version of the code. The problem here is that the old copy of the module was garbage-collected: this means (strangely enough) that Python has replaced all global names with None. This is why you end up with looking up np.diag() --- but crashing because np is None at this point. Why does it replace all global variables with None??? It's a very old reason: because it creates cycles of referen

Categories : Python

Determine if given class attribute is a property or not, Python object
I once asked a similar question. The trouble you'll run into, of course, is that you can't access the property through the instance to determine its type without calling the getter, which gets you the type of whatever the getter returns. So you have to access the property through its class rather than through the instance. property is already a type, so you can just compare directly to that. (I originally had some superfluous code here that got the property type out of a class that had a property. I thought this was necessary due to a typo when I was testing things.) obj_type = type(obj) for attr in dir(obj): if isinstance(getattr(type(obj), attr, None), property): print attr, "is a property" Don't worry about having an instance attribute with the same name. It's ignored

Categories : Python

Python - AttributeError: 'NoneType' object has no attribute 'findAll'
There is no table with id datatable_main in the page that the script read. Try printing the returned page to the terminal - perhaps your script is failing to contact the web server? Sometimes hosting services prevent outgoing HTTP connections.

Categories : Python

AttributeError: 'NoneType' object has no attribute 'get' - Python - OpenErp
Try this: def desc_cert(self, cr, uid, ids, field_name, field_args, context=None): obj = self.pool.get('purchase.order') pids = obj.search(cr, uid, [('sel_cert', '=', 'si')]) if pids == 'si': val = self._get_product_available_func(('done')) return val Or this: def desc_cert(self, cr, uid, ids, field_name, field_args, context=None): if self.pool: obj = self.pool.get('purchase.order') pids = obj.search(cr, uid, [('sel_cert', '=', 'si')]) val = self._get_product_available_func(('done')) if pids == 'si': return val

Categories : Python

python-magic module' object has no attribute 'open'
There is no magic.open() function. If you check out the python-magic documentation you can see that it has magic.from_file() and magic.from_buffer() functions. Use magic.from_file() to test against a path name; the module opens that file for you and and determines the type. Use magic.from_buffer() to test a byte sequence (str in Python 2, bytes in Python 3). There is also a magic.Magic() class that you can instantiate (per thread!) to alter how it operates: Magic(mime=False, magic_file=None, mime_encoding=False) documented as: Create a new libmagic wrapper. mime - if True, mimetypes are returned instead of textual descriptions mime_encoding - if True, codec is returned magic_file - use a mime database other than the system default and according to the README, that is

Categories : Python

Python: AttributeError: 'NoneType' object has no attribute 'start'
Well, you're matching a different regex: html_post_start = re.search('<div class="articleline2"></div>', html) vs html_post_start = re.search('<div class="excerpt"></div>', html) One matches, the other doesn't (returning None).

Categories : Python

Python 2: AttributeError: 'list' object has no attribute 'strip'
strip() is a method for strings, you are calling it on a list, hence the error. >>> 'strip' in dir(str) True >>> 'strip' in dir(list) False To do what you want, just do >>> l = ['Facebook;Google+;MySpace', 'Apple;Android'] >>> l1 = [elem.strip().split(';') for elem in l] >>> print l1 [['Facebook', 'Google+', 'MySpace'], ['Apple', 'Android']] Since, you want the elements to be in a single list (and not a list of lists), you have two options. Create an empty list and append elements to it. Flatten the list. To do the first, follow the code: >>> l1 = [] >>> for elem in l: l1.extend(elem.strip().split(';')) >>> l1 ['Facebook', 'Google+', 'MySpace', 'Apple', 'Android'] To do the second, use itertools.

Categories : Python

Changing object attribute within a custom class (Python)
The lambda default value listbox.val is evaluated at definition-time. So if you use lambda myval=listbox.val: callback(myval) then myval's default value equals 2 forever. Instead, you could use b = Button(top, text="answer", command=lambda mybox=listbox: callback(mybox.val))

Categories : Python

Python: AttributeError: '_io.TextIOWrapper' object has no attribute 'split'
Try this: >>> f = open('goodlines.txt') >>> mylist = f.readlines() open() function returns a file object. And for file object, there is no method like splitlines() or split(). You could use dir(f) to see all the methods of file object.

Categories : Python

Python 2: AttributeError: 'file' object has no attribute 'strip'
First, you want to open the file in read mode (you have it in append mode) Then you want to read() the file: output = open('new_data.txt', 'r') # See the r output_list = output.read().strip().split('.') This will get the whole content of the file. Currently you are working with the file object (hence the error).

Categories : Python

'str' object has no attribute 'get' - How do I tell python that the string being returned is a dictionary?
color_data.get(chosen)[1] returns country_color, a string, as you have figured out. If you want to access the country_color dictionary, why not change the value in color_data :)? color_data = {'Country': ['col1', country_color] # Notice how it's not a string anymore

Categories : Python

Python / IronPython logging : 'NoneType' object has no attribute 'f_back'
It looks like you're trying to use the library from Python 2.6 with IronPython 2.7. You should use IronPython 2.7's standard library instead, which has a bunch of fixes and workarounds that make it work (not perfect, but a lot better). For example, I get the following on IronPython 2.7.3: >>> from collections import OrderedDict >>> od = OrderedDict() >>> od[1] = 2 >>> od[0] = 4 >>> od OrderedDict([(1, 2), (0, 4)]) >>> Most likely you set the IRONPYTHONPATH variable to have Python's Lib before IronPython's Lib. That used to be required (for IronPython < 2.6), but now it's not recommended.

Categories : Python

python: several functions in one file, AttributeError 'module' object has no attribute
Maybe this is not the thing that causes your error, but I see that you missed an indent in the most inner for loop in file2file(inf,outf) It should be: def file2file(inf,outf): with open(inf, "r") as fin: with open(outf, "w") as fout: for line in fin: s = line.split(" ") fout.write("t{0} {1} {2} ",s[0],s[1],s[2])

Categories : Python

Is it possible to get shelve database filename using file object attribute? (python)
I just found this answer, which suggests creating the shelve files in a temporary subdirectory, then deleting the whole directory. I think that this is the best solution available at this time.

Categories : Python

Using an ImageView transform matrix instead of canvas.scale(float, float, float, float)
What if you try? m.setScale(scaleFactor, scaleFactor); m.postTranslate(zoomCenter[0], zoomCenter[1]); I also believe child.setScaleType(ScaleType.MATRIX) is not needed. At least my coding works without it.

Categories : Android

Python - Pandas: AttributeError: 'numpy.ndarray' object has no attribute 'start'
It looks like it's important to include the 0: In [11]: df1['2010-7':'2010-10'] Out[11]: Empty DataFrame Columns: [value] Index: [] In [12]: df1['2010-07':'2010-10'] Out[12]: value date 2010-08-31 12:36:53 30.37 2010-08-31 12:45:08 28.03 2010-08-31 12:55:09 25.16 2010-08-31 13:00:09 23.28 ... Could be worth filing an issue...

Categories : Python

python dictionary error AttributeError: 'list' object has no attribute 'item'
result = sorted(result.iteritems(), key=operator.itemgetter(1)) result is not a dictionary anymore. If I am not mistaken, your problem can be solved this way (assuming lines comes from somewhere): result = sorted({(calculate_score(line), line) for line in lines}) print(result[:20]) Take a look at OrderedDict for making an ordered dictionary.

Categories : Python

Python / Flask form error - AttributeError: 'unicode' object has no attribute '__call__'
It's giving you that error because nickname is not a function but a string. I can only guess that the tutorial has a few errors. Try this instead: {{ form.nickname|truncate(60) }}

Categories : Python

Getting a Python error (AttributeError: 'dict' object has no attribute 'read') trying to update code for Twitter Oauth2
Your fetchsamples() method already returned a decoded value: def fetchsamples(): url = "https://api.twitter.com/1.1/search/tweets.json?q=microsoft" parameters = [] response = twitterreq(url, "GET", parameters) return json.load(response) But you then try to decode the result again: pyresponse = json.load(fetchsamples()) json.load() then complains that fetchsamples() returned a python dictionary. Just remove the json.load() call from that line: pyresponse = fetchsamples() print pyresponse.keys()

Categories : Python

Why width CSS attribute of label doesn't work without float?
The Label element is defaulted to inline display mode. Inline elements don't accept a width property, they will be rendered in the width of their content. Floated elements on the other hand, are like inline-blocks. they will accept a width property. By applying a float property to an element you are essentially changing it's display property to something like (but not exactly) inline-block.

Categories : HTML

Rails rendered object.attribute with spaces truncated in jquery data attribute
You need to give it as : <a class="comment" data-user_comment = "<%= comment.content %>" ><%= comment.updated_at %> - <%= comment.content %></a> Missing quotes. On missing quotes only the first word is taken and the remaining is taken as a different attrribute. So on using fire bug you can see that it your comment had : "Lorem Ipusem" the value of data-user_comment is "Lorem" and Ipusem itself becomes an attr with blank value (Ipusem = "").

Categories : Jquery

Django set up help in venv : Attribute error: 'module' object has no attribute 'get_version'
I think you are not using a virtualenv, or your venv has access to system packages, which somehow defeats one of the advantages of using them. To create a virtualenv use $ virtualenv --no-site-packages --distribute -p python2.4 ~/my_venv This will create a virtualenv in your home folder giving no access to system packages. The -p switch let you select your python version: if you have a more recent python version installed you should use it, or you will only be able to use Django 1.3. See here. Next you need to activate it $ source ~/my_venv/bin/activate (my_venv) $ That new prompt shows you that you are now using your virtualenv. You can then install Django (replace that version which one you need or can use) and everything you need $ pip install Django==1.3 Everytime you want t

Categories : Python

Attribute Error: '_BaseValue' object has no attribute 'value'
Apparently, user.orgs has been put() to the database. That "mutates" it into a _BaseValue, as described here: List items from repeated StringProperty get mutated to _BaseValue on put.

Categories : Google App Engine

Ruby Time object converted from float doesn't equal to orignial Time object
IEEE 754 double (which is returned by to_f) is not accurate enough to represent the exact time. t1 = Time.now f1 = t1.to_f t2 = Time.at(f1) # they look the same t1.inspect #=> '2013-09-09 23:46:08 +0200' t2.inspect #=> '2013-09-09 23:46:08 +0200' # but double does not have enough precision to be accurate to the nanosecond t1.nsec #=> 827938306 t2.nsec #=> 827938318 # ^^ # so they are different t1 == t2 #=> false Do the following, to preserve the exact time: t1 = Time.now r1 = t1.to_r # value of time as a rational number t2 = Time.at(r1) t1 == t2 #=> true Citation from Time.to_r: This methods is intended to be used to get an accurate value representing the nanoseconds since the Epoch. You can use this method to convert time to another Epoc

Categories : Ruby

float object is not callable
Don't use range as a variable name. It shadows builtin functionrange: >>> range = 0.1 >>> range(1) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'float' object is not callable

Categories : Python

Unable to read attribute in Linq to xml, error: Object reference not set to an instance of an object
Attributes/Elements names are case sensitive. Replace l_sMODID = addParam.Attribute("moduleId").Value, With l_sMODID = addParam.Attribute("moduleid").Value, That's because attributes in your input XML is moduleid="F0736590-84A2-4795-BC5D-0056606F2446", not moduleId. Working code: var doc = XDocument.Load("Input.txt"); Func<XElement, IEnumerable<Item>> query = e => e.Elements("item") .Select(x => new Item { Id = (string)x.Attribute("id"), ModuleId = (string)x.Attribute("moduleid"), View = (bool)x.Attribute("view"), Add = (bool)x.Attribute("add"), Edit = (bool)x.Attribute("edit"),

Categories : C#

Java: Change value of a Float object
You cannot change the value of a Float; all of the primitive wrapper classes are immutable. You could create your own (mutable) wrapper class if you want to add this functionality, or take a look at MutableFloat from the Apache Commons.

Categories : Java

int() conversion of float in python
When you do int(x), it ALWAYS rounds down, meaning if you do int(4.9999) you'll get 4. Consider using int(round(x)) instead EDIT: Wait...if you've multiplied by 100, why are you even using floats at all? What do you need the decimals for? Why not just turn cents into an int after you multiply by 100 and then get rid of all of this float nonsense?

Categories : Python

Python float __setformat__?
It is only of use to the Python test suite; help(float.__setformat__) prints: float.__setformat__(typestr, fmt) -> None You probably don't want to use this function. It exists mainly to be used in Python's test suite. typestr must be 'double' or 'float'. fmt must be one of 'unknown', 'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be one of the latter two if it appears to match the underlying C reality. Overrides the automatic determination of C-level floating point type. This affects how floats are converted to and from binary strings. There is a float.__getformat__() as well, the getter method for the same information, same purpose. See the float test suite for more details on its use. Use the decimal module to get more accurate d

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.