I am trying to convert string date to timestamp in Python as described in the post here. When I run the code examples in the post, I encounter an error. For e.g.:
>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
File "C:\Python34\lib\_strptime.py", line 15, in <module>
import calendar
File "C:\Python34\calendar.py", line 9, in <module>
calendar = wckCalendar.Calendar(root, command=echo)
NameError: name 'wckCalendar' is not defined
>>>
It looks like at runtime the code implicitly tries to import calendar and throws the error in the process. When I import calendar directly, I get the same error:
>>> import calendar
Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
import calendar
File "C:\Python34\calendar.py", line 9, in <module>
calendar = wckCalendar.Calendar(root, command=echo)
NameError: name 'wckCalendar' is not defined
>>>
I just want to be able to do the following:
>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
Any ideas?
Python 3.4.1 on Windows 7 32 bit*
Thanks to #J.F. Sebastian. I was caught in the name shadowing trap. I made the stupid mistake of naming one of my modules calendar.py. Once I removed this file, everything ran fine. I hope this post is not a waste and that someone may someday find it useful.
Related
python g.V('test_red1').valueMap().toList()
works fine but when I pass true to request ids and labels I get this error. Anything I am missing?
g.V('test_red1').valueMap(True).toList()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ec2-user/environment/merchantGraph/gremlin_python/process/traversal.py", line 52, in toList
return list(iter(self))
File "/home/ec2-user/environment/merchantGraph/gremlin_python/process/traversal.py", line 43, in __next__
...
Am I missing something. I am using AWS Neptune ...
I am adding extra import statements
and traceback
import time
import requests
import json
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
import boto3
from os import environ
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection(environ['gremlinNeptuneConnection'],'g'))
# this works
g.V('test_red1').valueMap().toList()
# this fails
g.V('test_red1').valueMap(True).toList()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ec2-user/environment/merchantGraph/gremlin_python/process/traversal.py", line 52, in toList
return list(iter(self))
....
File "/home/ec2-user/environment/merchantGraph/gremlin_python/structure/io/graphsonV3d0.py", line 455, in objectify
new_dict[reader.toObject(l[x])] = reader.toObject(l[x + 1])
TypeError: unhashable type: 'dict'
My guess is that you are running into trouble with this recently reported bug with valueMap(true):
https://issues.apache.org/jira/browse/TINKERPOP-1860
it is patched and will be fixed with release of 3.3.2. Until then you will have to work around the issue as there really is no fix short of reverting to GraphSON 2.0 (which comes with it's own set of downsides). One workaround would be to project() your results:
gremlin> g.V().project('props','id','label').
......1> by(valueMap()).
......2> by(id).
......3> by(label)
==>[props:[name:[marko],age:[29]],id:1,label:person]
==>[props:[name:[vadas],age:[27]],id:2,label:person]
==>[props:[name:[lop],lang:[java]],id:3,label:software]
==>[props:[name:[josh],age:[32]],id:4,label:person]
==>[props:[name:[ripple],lang:[java]],id:5,label:software]
==>[props:[name:[peter],age:[35]],id:6,label:person]
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 5 years ago.
When I go to run
from datetime import *; from dateutil.relativedelta import *
from a python script I get a error which to me seems to indicate a problem with the module itself.
Traceback (most recent call last):
File "C:\Users\Tom\Documents\datetime.py", line 1, in <module>
from datetime import *
File "C:\Users\Tom\Documents\datetime.py", line 2, in <module>
from dateutil.relativedelta import *
File "C:\Users\Tom\AppData\Local\Programs\Python\Python35\lib\site-packages\python_dateutil-2.0-py3.5.egg\dateutil\relativedelta.py", line 11, in <module>
import calendar
File "C:\Users\Tom\AppData\Local\Programs\Python\Python35\lib\calendar.py", line 47, in <module>
class _localized_month:
File "C:\Users\Tom\AppData\Local\Programs\Python\Python35\lib\calendar.py", line 49, in _localized_month
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
File "C:\Users\Tom\AppData\Local\Programs\Python\Python35\lib\calendar.py", line 49, in <listcomp>
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
AttributeError: module 'datetime' has no attribute 'date'
This however, does not happen when I use the exact same statement in the python shell, if used in the shell it works perfectly.
I did find that it directly related to relativedelta part of dateutil, as
from dateutil import *
works fine.
I have tried reinstalling dateutil but thats pretty much it.
Running python 3.5.1 with dateutil 2.0 if it matters.
EDIT: SORRY I'M AN IDIOT, my file was called datetime.py which was what caused the problem.
I believe it's the source file name. I am guessing when python interpreter tries to find datetime module it would search the local directory first and the datetime module would be your source file than the datetime global package. this post explains more
Once you would rename your file to say dd.py instead of "C:\Users\Tom\Documents\datetime.py" it should work out.
I have a file that gets generated by :
excerpt:
group0 = ['ParentPom']
group1 = ['Commons','http', 'availability','ingestPom','abcCommons','solrIndex','123Service']
...
group10=['totalCommons','Generator']
How can I include this in my python script, tried import but no luck
>>> import dependencies_custom
>>> print (group2[0])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'group2' is not defined
In the import form you're using, you should be able to access the groups by
dependencies_custom.group2[0]
type notation. If you want just use just group2[0] notation, try using:
from dependencies_custom import *
When I start boa-constructor(boa-constructor-0.6.1.src.win32.exe) from the command line by starting the script "Boa.py", I got the message says
My python version is "python-2.7.7.msi" and I download wxPyton "wxPython3.0-win32-3.0.0.0-py27.exe"
O searched for files that contains the string "NO_3D " but I didn't get any can you help me pleaze and thanks
Actually you will require wxPython 2.8.12.1 to not get this error.
>>> import wx
>>> wx.__version__
'2.8.12.1'
>>> wx.NO_3D
0
This is a pity, because the operation …|wx.NO_3D is actually a No-Op. So you could fix this particular issue by defining wx.NO_3D somewhere.
On 2.9.5:
>>> import wx
>>> wx.__version__
'2.9.5.0'
>>> wx.NO_3D
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'NO_3D'
How do you print doc strings in python 3.1.x?
I tried with the re and sys modules as a test and I keep getting errors. Thanks
import re
print(re._doc_)
Traceback (most recent call last):
File "<pyshell#91>", line 1, in <module>
print(re._doc_)
AttributeError: 'module' object has no attribute '_doc_'
It's called __doc__, not _doc_.
import re
print(re.__doc__)
Works just fine.