Thread: Python Help

Results 1 to 4 of 4
  1. #1
    SentinelHawk's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0

    Question Python Help

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

    print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second)

    I cant find my fault. Can someone tell me the bug? It dosent work.

  2. #2
    WhiteBot's Avatar
    Join Date
    Jul 2016
    Gender
    male
    Posts
    44
    Reputation
    10
    Thanks
    2
    My Mood
    Busy
    Are you trying to create timestamp?

    In the print part you must use ()

    You need to import strftime() to get the actual data and declare the variables in the correct format. ('%d/%m/%Y/%H/%M/%S') and declare timetupple() to make the ts. #Day,Month[with minuscule 'm' to represent the month],Year,Hour,Minutes,Seconds.
    You will get a .float string something like ('37136381293.0') Then you need to regex the '.0' part. and convert it to INT via 'int()'.. User mktime with your date time and the date time that you need to create.

    Thanks in advanced.



    import time,datetime
    from time import strftime
    p = strftime('%d/%m/%Y/%H/%M/%S')
    i5 = str((time.mktime(datetime.datetime.strptime(p,'%d/%m/%Y/%H/%M/%S').timetuple())))
    i1 = '\d*'
    i2 = re.compile(i1)
    i3 = re.findall(i2,i5)
    i4 = i3[0]

  3. #3
    YT$W@Tgsef354's Avatar
    Join Date
    Aug 2014
    Gender
    male
    Posts
    7
    Reputation
    10
    Thanks
    7
    The problem in your code is with the import statements. I am assuming you are using Python 2, due to the lack of parentheses in your print statement. The two imports you are using conflict with each other because they have the same name, so python uses the one most recently imported.
    You just need to put "from datetime import datetime" after "import datetime", remove "import datetime", or change
    "now = datetime.now()" into "now = datetime.datetime.now()" and possibly remove "from datetime import datetime".
    Last edited by YT$W@Tgsef354; 07-14-2016 at 06:34 AM.

  4. #4
    egycnq's Avatar
    Join Date
    Sep 2018
    Gender
    male
    Posts
    202
    Reputation
    84
    Thanks
    34
    My Mood
    Amazed
    problem in your code

Similar Threads

  1. Python help
    By Turtle in forum General
    Replies: 4
    Last Post: 01-13-2016, 07:02 PM
  2. python help
    By thisisreal34 in forum General
    Replies: 16
    Last Post: 02-01-2015, 02:34 PM
  3. python help
    By thisisreal34 in forum General
    Replies: 7
    Last Post: 01-24-2015, 05:40 AM
  4. [Help Request] Any Expericanced C++ or Python Programmers Please Help.
    By 1loggerboy2 in forum C++/C Programming
    Replies: 4
    Last Post: 01-03-2013, 01:14 PM
  5. Game Bypass (.atpy and Python) help? xD
    By Felixmaster45 in forum Game Development
    Replies: 0
    Last Post: 11-08-2012, 10:39 PM