python datetime not working

Discussion in 'UDOO NEO' started by Tengoles, Dec 19, 2016.

  1. Tengoles

    Tengoles New Member

    Joined:
    Nov 23, 2016
    Messages:
    14
    Likes Received:
    3
    hello, I wanted to use the datetime python libraries but while doing this simple program:

    from datetime import datetime
    now=datetime.now()
    print now


    I run it from console and I get this:
    Traceback (most recent call last):
    File "test.py", line 1, in <module>
    from datetime import datetime
    File "/home/udooer/datetime.py", line 2, in <module>
    now=datetime.now()
    NameError: name 'datetime' is not defined

    any help?
     
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Does it work when you start a terminal window and do:

    python (Python starts in the terminal)
    >>>from datetime import datetime
    >>>now=datetime.now()
    >>> print now

    On my Neo it works.
    How did you create the test.py file? If you created it on Windows it be bad. Try creating the file from Linux with leafpad. I use Geany (preinstalled) fo r Editting Python files.
     
  3. Tengoles

    Tengoles New Member

    Joined:
    Nov 23, 2016
    Messages:
    14
    Likes Received:
    3
    I created the file on leafpad originally but now I'll start using Geany, thanks for that tip!

    Used the commands you said and got this:

    [​IMG]
     
  4. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    It looks like you have a datetime.py file in your home folder. Please rename or delete that and try again. Python loads from the first library file that is available.
     

Share This Page