Print a modified system time

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1996 Views - Last Post: 19 November 2015 - 10:35 PM Rate Topic: -----

#16 Jorge-052   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 18-November 15

Re: Print a modified system time

Posted 19 November 2015 - 09:54 PM

I'm looking at other clocks that people have made in Python, and one of the examples put forth:

import time
 
while True != False:
    print(time.strftime("%H"+":"+"%M"+":"+"%S"))
    time.sleep(1)



Required importing the time module in order to use strftime, as they explicitly mention; Why didn't we have to import the time module in our case? Did we implicitly import it or something by the other things we chose to import, or what?
Was This Post Helpful? 0
  • +
  • -

#17 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 1064
  • View blog
  • Posts: 4,105
  • Joined: 13-June 14

Re: Print a modified system time

Posted 19 November 2015 - 10:04 PM

These are two different functions (and they take different arguments). The one in time is just a "free function" (for want of a better term. I mean one that's not part of a class) and the one you're using is a method of the datetime class. Remember that you can always look up things in the standard library documentation (the link is for Python 2).
Was This Post Helpful? 0
  • +
  • -

#18 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 1064
  • View blog
  • Posts: 4,105
  • Joined: 13-June 14

Re: Print a modified system time

Posted 19 November 2015 - 10:13 PM

Also, for what it's worth, you can combine imports from the same module with commas, e.g.

from datetime import date, datetime, timedelta

Was This Post Helpful? 0
  • +
  • -

#19 Jorge-052   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 18-November 15

Re: Print a modified system time

Posted 19 November 2015 - 10:19 PM

View Postndc85430, on 19 November 2015 - 10:13 PM, said:

Also, for what it's worth, you can combine imports from the same module with commas


That's a godsend, thank you, heh. I'm still pretty much totally unclear (I haven't made a strong attempt since I started learning 2 days ago tbh) on the conceptual differences between all of these things, so at the moment looking at the documentation isn't useful to me until I figure out what that functionally means, differences between classes/functions/methods, etc., so I just need to do that.

I've had trouble learning programming before (made very feeble attempts, but never gotten even to where I am now)-mainly because I failed to understand in reading intro. texts what these differences were, and viewed them at that point to almost be semantic.
Was This Post Helpful? 0
  • +
  • -

#20 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 1064
  • View blog
  • Posts: 4,105
  • Joined: 13-June 14

Re: Print a modified system time

Posted 19 November 2015 - 10:24 PM

Then yes, go back and learn the stuff you're having difficulty with and ask questions when you still don't understand. Out of interest, how are you learning Python (e.g. which book are you using)?
Was This Post Helpful? 0
  • +
  • -

#21 Jorge-052   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 18-November 15

Re: Print a modified system time

Posted 19 November 2015 - 10:35 PM

View Postndc85430, on 19 November 2015 - 10:24 PM, said:

Then yes, go back and learn the stuff you're having difficulty with and ask questions when you still don't understand. Out of interest, how are you learning Python (e.g. which book are you using)?


I'm not actually on my home PC, so I don't have the stuff I've been using to heart. What I do know I've been doing is using the Codeacademy course for Python; additionally, it's not Learn Python The Hard Way, but I'm reading some free web-based book that I found in a resources section somewhere for Python learning tools, but I can't find it again upon a cursory search. Don't remember what it's called. I've *looked* at Learn Python The Hard Way, but haven't been using it on a chapter-by-chapter basis. Otherwise for the clock just scanning random snippets on the web of related tasks people have done in Python.

Ah, found it, here: https://automatetheboringstuff.com/
Was This Post Helpful? 0
  • +
  • -

#22 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 1064
  • View blog
  • Posts: 4,105
  • Joined: 13-June 14

Re: Print a modified system time

Posted 19 November 2015 - 10:35 PM

I'm under the impression that Codecademy isn't very good - it doesn't really explain stuff too well and holds your hand quite a lot. Definitely find a decent book if you're interested in learning to program. Another free web based book that you may consider (if it isn't the one you're reading, of course) is Think Python.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2