Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python class
#1
Hi everyone,

my question maybe is very simple but I am beginner with Python. What does this line do ?
return Post(self, message)

because I am confused: class Post is an object with two args (author and message) et just one arg is used !
Thanks in advance.

import crypt
import datetime
 
class User:
    def __init__(self, id, name, password):
        self.id = id
        self.name = name
        self._salt = crypt.mksalt()
        self._password = self._crypt_pwd(password)
 
    def _crypt_pwd(self, password):
        return crypt.crypt(password, self._salt)
 
    def check_pwd(self, password):
        return self._password == self._crypt_pwd(password)
 
    def post(self, message):
        return Post(self, message)
 
class Post:
    def __init__(self, author, message):
        self.author = author
        self.message = message
        self.date = datetime.datetime.now()
 
    def format(self):
        date = self.date.strftime('le %d/%m/%Y à %H:%M:%S')
        return '<div><span>Par {} {}</span><p>{}</p></div>'.format(self.author.name, date, self.message)
Reply


Messages In This Thread
python class - by chris_thibault - Aug-18-2018, 07:39 AM
RE: python class - by Gribouillis - Aug-18-2018, 08:39 AM
RE: python class - by chris_thibault - Aug-18-2018, 09:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting c++ class to python class panoss 12 11,973 Jul-23-2017, 01:16 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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