Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time module help
#1
When I try to run the code that contains the line below, it throws up a syntax error to do with the fist time. Any help? (I am on Python 3.5. Code is for a simple text based chat program)

print time.ctime(time.time()) + str(addr) + ":  :" + str(data)
         ^^
         That is the one Python identifies as a problem
Reply
#2
print in Python 3.* is a function - use it as print(....)
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#3
you need to use parenthesis in python 3
print (time.ctime(time.time()) + str(addr) + ":  :" + str(data))
A better way:
print ('{}{}::{}'.format(time.ctime(time.time()), str(addr), str(data)))
Reply
#4
(May-07-2017, 04:14 PM)volcano63 Wrote: print in Python 3.* is a function - use it as print(....)

(May-07-2017, 04:15 PM)Larz60+ Wrote: you need to use parenthesis in python 3
print (time.ctime(time.time()) + str(addr) + ":  :" + str(data))
Ooops!
I didn't see that right under my own nose!
Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with module time and leap seconds Pedroski55 3 1,230 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  Module 'time' has no attribute 'clock' Sophie 4 3,086 Jan-25-2022, 08:05 PM
Last Post: Sophie
  Installing time module Led_Zeppelin 2 11,845 Aug-31-2021, 02:16 PM
Last Post: Led_Zeppelin
  finding yesterday and tomorrrow without using date.time module apexman 10 5,497 Feb-25-2019, 05:33 AM
Last Post: samsonite
  selecting a module at run time Skaperen 1 2,329 Jun-23-2018, 01:37 PM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020