I am writing a script in python and I need to know how many milliseconds are between two points in my code.
I have a global variable when the program starts like this:
from datetime import datetime
a=datetime.now()
When I need to know how many milliseconds have passed, I execute this:
b=datetime.now()
print (b.microseconds-a.microseconds)*1000
However I get this error:
AttributeError: 'datetime.datetime' object has no attribute 'microseconds'
What's wrong? How can I fix this?
It is microsecond, without an "s" at the end
A useful function is dir. You can do dir(object) to find out its properties. In this case, you want a.microsecond.
Related
import mains
print(mains.hi())
import parsogv2
print(parsogv2.gets())
priliv = mains()/parsogv2()
I have this trouble 'module' object is not callable. I want to split the values I get in modules How to do it better ? Combine them into one module or can I do as I wanted in the code ?
If what you've been trying to do is divide the return values of mains.hi() and parsogv2.gets(), then what you should be doing is:
priliv = mains.hi()/parsogv2.gets()
The error you've been receiving, informing you that a module is not callable, is a result of your attempt to call the actual modules (mains and parsogv2) instead of the functions they contain (mains.hi and parsogv2.gets), which I assume is what you were going for.
I'm using Python to work with networkx and draw some graphs.
I ran into a problem raising:
TypeError: 'dict' object is not callable
on this line of code:
set_node_color(num, list(Graph.node()))
I searched to find that this error is raised when I'm using a variable name dict.
The problem is, I'm not using any variables with the name dict, nor am I using any dictionary types anywhere in the code.
In case it's necessary, printing the type of Graph gives <class 'networkx.classes.digraph.Digraph'>.
I also tried printing the type for Graph.node() only to receive the same error, telling me 'dict' object is not callable.
So I suspect Graph.node() to be a dict type variable, but using (Graph.node()).items() raises the same TypeError.
Any help or advices would be nice. Thanks.
Maybe Graph.node is a dict object, so Graph.node() is not callable.
When I execute my Python script using mininet-wifi, I am getting the following error, and I don't know why?
error:'Mininet' object has no attribute 'addBaseStation'
Should I change addBaseStation into addAcessPoint? If so, what is the difference between these?
Try out addAccessPoint() instead.
I have a set of modules, and I want to be able to call one of them within a function based on an argument given to that function. I tried this, but it doesn't work:
from my.set import modules
def get_modules(sub_mod):
variable = sub_mod
mod_object = modules.variable
function(mod_object)
I get:
AttributeError: 'module' object has no attribute 'variable'
It's not taking the argument I give it, which would be the name of a module that exists under my.set.modules. so if I called the function get_modules(name_of_mod_under_modules), I would like the line modules.variable to be "modules.name_of_mod_under_modules" which I could then have as an object passed to mod_object.
In your current code, you're looking for modules.variable which doesn't exist, hence the error! That's not how you get an attribute of an object.
To achieve what you wanted, use the getattr function.
mod_object = getattr(modules, variable)
from Bio.PDB import *
parser=PDBParser()
structure=parser.get_structure('cal1','3CLN.pdb')
model=structure[0]
chain=model["A"]
hse=HSExposure()
expca=hse.calc_hs_exposure(model,option='CA3')
print expca[chain[40]]
When I execute this code, I'm getting this error:
File "D:\python\Core\pdb_2.py", line 6, in <module>
hse=HSExposure()
TypeError: 'module' object is not callable
What's wrong with it?
For anyone like me still looking for the answer:
Most tutorials seem to have this wrong. What worked for me was
exp_ca = HSExposureCA(model)
res_id = residue.get_id()
print(exp_ca[(chain.get_id(), res_id)])
Please note that HSEalpha is undefined for the first and last residues of a chain.
HSExposure is a module, not a class, so you can't instantiate it. There's a bunch of classes in that module, so I assume you want one of them.