iam trying to use the math.trunc in Blender 2.49b Python
but iam getting this error
AttributeError: 'module' object has no attribute 'trunc'
i also imported math
its on line
uv[i][0] = trunc(uv[i][0] * 100000) / 100000
i also tryied it via the int, like
uv[i][0] = int(uv[i][0] * 100000) / 100000
which gives me an error
TypeError: 'float' object is
unsubscriptable
so how should i trunc the value:(
thank you
The second error seems to imply that uv in your code is a float object and you are trying to subscript it uv[i]. Try to math.trunc(uv) and see. Also you can check if trunc is available by doing hasattr(math,'trunc')
It might depend what verson of Python is used by Blender (I imagine that would be Python 2.5).
Try this in Blender:
import math
help(math)
This will crash Blender, but you will be able to see the math to the library under FILE and you should be able to scroll down to see if the trunc function is available in the version of Python used by Blender. It might be not present, which would explain the error.
Related
I was going through a cheat sheet of NumPy and found the median() function. As I was trying it, an error was thrown. Here, you can find the cheat sheet. The code is:
import numpy as np
check = np.array([1, 2, 3])
check.median()
The error message is:
'numpy.ndarray' object has no attribute 'median'
In the official NumPy doc, I found that I should use median() as np.median(check). So, I was wondering if check.median() is an obsolete method or I was doing anything in a wrong way?
The NumPy version I was using was 1.19.5. Then I upgraded it to the latest version (1.21.2). Still, the same error persists.
I am a beginner in Python and I am practicing functions. I am trying to run the below reproducible code in Jupyter but fetching error `TypeError: 'module' object is not callable.
Below is the reproducible code creating the function gbp_to_usd:
def gbp_to_usd(gbp):
usd = float(gbp) * 1.5
return usd
gbp = input("Enter the gbp: ")
usd = gbp_to_usd(gbp)
print("The converted gbp amount in usd is: " + str(usd))
But when I run the same code in IDE, I do not get the error:
I tried running the same code in Python IDE and replicate the error, but to my surprise, it ran successfully. So this got me confused further. I researched online and found that a missing mathematical operator could cause this error but my function here is not missing any operator (function gbp_to_usd has a basic mathematical operation).
Does anyone have any idea what could be causing this error? why can't it call str() on a float variable?
Let me know
You have ran 164 cells before the one shown in the image. One of those cells has overwritten print or str functions with a module object since those are the only 2 functions on the line that are being called
On a fresh Python environment (or a reset Jupyter kernel), you shouldn't expect that error, and thus, that is the "fix"
I'm trying to make a Python script that connects me to a VPN Server 'number' (with this number as a variable)
I wrote:
import os
VPNServer = 0
VPNServer += 1
os.system("networksetup -connectpppoeservice 'VPNServer {servernumber}'").format(servernumber = str(VPNServer))
print("→ Successfully connected to", "VPNServer", VPNServer)
But everytime I try to run it, the console gives me an AttributeError
AttributeError: 'int' object has no attribute 'format'
I don't understand it because I took the string version of the variable
If someone could help, it would be super cool
I'm on macOS and I'm using Python 3.8.1
In the snippet you provided, you write
os.system('<some string>').format(args)
You are making the format call on the return value of os.system, which happens to be an integer. This is identical to writing e.g.
5.format(args)
Since int objects have no attribute format, you get the AttributeError you described.
What you want to write is
os.system('<some string>'.format(args))
In this specific case, your snippet should resemble
os.system(
"networksetup -connectpppoeservice 'VPNServer {servernumber}'"
.format(servernumber=VPNServer)
)
Note that the str(VPNServer) call is superfluous, since format will autmatically call the __str__ method of the object provided.
I am trying to learn my way around Cython, and I am following the official documentation. Recently, i tried to do the tutorial provided in "http://docs.cython.org/en/latest/src/tutorial/profiling_tutorial.html".
The objective here is to profile a Cython document.
This is where I got into trouble.
The function to be profiles is (file "calc_pi.py"):
def recip_square(i):
return 1./i**2
def approx_pi(n=10000000):
val = 0.
for k in range(1,n+1):
val += recip_square(k)
return (6 * val)**.5
The script to profile the functions (as posted in the document) is:
import pstats, cProfile
import calc_pi
cProfile.runctx("calc_pi.approx_pi()", globals(), locals(), "Profile.prof")
s = pstats.Stats("Profile.prof")
s.strip_dirs().sort_stats("time").print_stats()
I am not exactly sure which command to run, and if this is what raises the error. However, in their page, there is no reference to thisi. So I simply run "python3 profile.py", which yields the follwing error:
AttributeError: module 'cProfile' has no attribute 'runctx'
I know that probably my error is stupid and minimum, but after googleing and checking stackoverflow for a while, I could not find the answer.
Thank you for your help.
I faced the same issue here.
The problem was the name of the file profile.py.
Just use a different name (as suggested in here)
I tried to run following program of using python 3.5.1.
from scipy import optimize
optimize.anneal(f, input_vector0, lower = 0, upper = 2*np.pi)
I got the following error message:
AttributeError: module 'scipy.optimize' has no attribute 'anneal'.
Can anybody tell me what should I do to fix this? i really appreciate it !
The problem is that it is removed in 0.16 and higher.
Replace anneal with basinhopping.
refer to link