Python Forum
newbie questions about objects properties...
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
newbie questions about objects properties...
#1
Hi everyone,
Still confused between objects and properties..

When I run this:

from datetime import date
from datetime import time
from datetime import datetime

  
today = datetime.now()
f = today.time()
print f

print datetime.time(datetime.now())
 
Questions: When I'm running f = today.time() does this mean I'm calling the time method from the object "today" ? Or am I calling the time method from the datetime module and use today variable as "data input" ?

Why datetime.time(datetime.now()) is equivalent ? what is the "datetime.time()" ? a method straight from the datetime module ?

How should I code ? Do I need initialise objects by assigning a variable or can I call them straight like in the print datetime.time example ?


Also on the same lines..

import os 
print os.name;
Why above I can't do the below instead ? (this to understand properties...)

import os 
a = os.name
print a.name
Reply
#2
you have already used name in a = os.name

import os 
a = os.name
print (a)
Reply
#3
In a python script, when you see the expression
spam.eggs
it means that the object 'spam' has an attribute 'eggs'. The result of the expression is another object, the value of the attribute 'eggs' of the 'spam' object.

Often, this value is a callable object, which means that it can be used in a call expression such as in
spam.eggs(4)
It may happen, but this is not necessarily the case, that 'eggs' is a method of the class of the object 'spam'. In that case, the value of spam.eggs is a special callable object named an instancemethod.

Typically, when 'spam' is a module and 'eggs' is a function defined in this module, the expression spam.eggs() is an example of the same syntax, but eggs is not a method of the ModuleType. This illustrates the fact that this expression may have different semantics.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I need help writing this code for string properties and methods hannah71605 4 3,059 Mar-22-2021, 12:36 PM
Last Post: menator01
  Sort objects by protected properties. Sigriddenfeta 1 1,856 Mar-17-2020, 04:11 AM
Last Post: Larz60+
  Newbie to CS and Python, 2 questions johneven 2 2,193 Feb-01-2019, 03:00 AM
Last Post: johneven
  Creating a script with a class have specific properties dvldgs05 13 5,708 Oct-15-2018, 08:54 PM
Last Post: dvldgs05

Forum Jump:

User Panel Messages

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