How can I print out an attribute or a series of attributes of a class object from a dictionary? The Next CEO of Stack OverflowHow to sort a list of objects based on an attribute of the objects?How to know if an object has an attribute in PythonHow to print objects of class using print()?How can I create an object and add attributes to it?How to pretty print nested dictionaries?Extract subset of key-value pairs from Python dictionary object?How can I print literal curly-brace characters in python string and also use .format on it?How can I sort a dictionary by key?How to remove a key from a Python dictionary?How to print a dictionary line by line in Python?

How to implement Comparable so it is consistent with identity-equality

The sum of any ten consecutive numbers from a fibonacci sequence is divisible by 11

How seriously should I take size and weight limits of hand luggage?

Is a linearly independent set whose span is dense a Schauder basis?

Strange use of "whether ... than ..." in official text

Find a path from s to t using as few red nodes as possible

Does Germany produce more waste than the US?

MT "will strike" & LXX "will watch carefully" (Gen 3:15)?

Why was Sir Cadogan fired?

Calculate the Mean mean of two numbers

What is the difference between 'contrib' and 'non-free' packages repositories?

Planeswalker Ability and Death Timing

Is it possible to make a 9x9 table fit within the default margins?

Simplify trigonometric expression using trigonometric identities

That's an odd coin - I wonder why

Creating a script with console commands

Cannot restore registry to default in Windows 10?

What steps are necessary to read a Modern SSD in Medieval Europe?

Are British MPs missing the point, with these 'Indicative Votes'?

Why doesn't Shulchan Aruch include the laws of destroying fruit trees?

Finitely generated matrix groups whose eigenvalues are all algebraic

Create custom note boxes

Prodigo = pro + ago?

Compensation for working overtime on Saturdays



How can I print out an attribute or a series of attributes of a class object from a dictionary?



The Next CEO of Stack OverflowHow to sort a list of objects based on an attribute of the objects?How to know if an object has an attribute in PythonHow to print objects of class using print()?How can I create an object and add attributes to it?How to pretty print nested dictionaries?Extract subset of key-value pairs from Python dictionary object?How can I print literal curly-brace characters in python string and also use .format on it?How can I sort a dictionary by key?How to remove a key from a Python dictionary?How to print a dictionary line by line in Python?










0















I am making a to do list manager. Each item on the list is an object belonging to the class "Task", which has the attributes shown. Each time the user calls the function "taskmaker", the Task object is added to a dictionary taskDict with a key (count) that incrementally increases by one for every task created.



The program then prints me a list of the tasks created, and their respective keys using print(taskDict).



Currently, I get the object's generated name, and key. I would like to display just attributes of each object, such as "taskname" and "duedate" which the user defines.



import datetime


class Task:
def __init__(self, taskname, datecreated, iscomplete, datecomplete, duedate, duetime, importance, isproject, projectname, category, repeat, timetodo, scheduledate):
self.taskname = taskname
self.datecreated = datecreated
self.iscomplete = iscomplete
self.datecomplete = datecomplete
self.duedate = duedate
self.duetime = duetime
self.importance = importance
self.isproject = isproject
self.projectname = projectname
self.category = category
self.repeat = repeat
self.timetodo = timetodo
self.scheduledate = scheduledate


taskDict =
count = 0 # This is the key

decide: str = input("If you would like to add a task, type anything except 0. : ")


def taskmaker():
global decide
while decide != "0":
namer = input("Enter your task: ")
datecreateder = datetime.datetime.now()
duedater = input("When would you like this due? : ")
duetimer = input("At what time would you like this due? : ")
task = Task(namer, datecreateder, False, "", duedater, duetimer, 0, False, "", "", False, 1, "")
global count
taskDict[count] = task
count = count + 1
decide = input("If you would like to add a task, type anything except 0. : ")


taskmaker()

print(taskDict)


I have had no luck finding resources that point to how this is done that weren't severely downvoted.



Here is the console input and output.



If you would like to add a task, type anything except 0. : 1
Enter your task: Chemistry homework
When would you like this due? : Tomorrow
At what time would you like this due? : Noon
If you would like to add a task, type anything except 0. : 2
Enter your task: History Essay
When would you like this due? : Wednesday
At what time would you like this due? : Midnight
If you would like to add a task, type anything except 0. : 0
0: <__main__.Task object at 0x000001AFBADCCEB8>, 1: <__main__.Task object at 0x000001AFBADCCE48>









share|improve this question






















  • Put the user-defined data in a dictionary, then loop over the dictionary elements and print the keys and values.

    – Barmar
    Mar 7 at 19:43











  • @Barmar That sounds like a temporary fix? I am pretty new to this so I cant be sure though. If I am totally wrong, please extrapolate and I will try to do that.Later in this program, I need to go in and change some of these attributes, so the program needs to be able to read them straight from the objects. I am only using a dictionary to make it easier to point to those objects using the key.

    – Andrew Buhrow
    Mar 7 at 19:54











  • Why is it a temporary fix? Class attributes are normally attributes that are known about by the class methods. Dynamic properties should not be class attributes, since they're just arbitrary name-to-value mappings. And that's what a dictionary is good for.

    – Barmar
    Mar 7 at 19:57











  • Ah. Should I be using dictionaries for each task then? Currently every instance of the class is a task, and all its attributes are writable so the user dictates what each of its attribute values are. Again I am quite new to coding, so if there is a better way of going about this I am all ears.

    – Andrew Buhrow
    Mar 7 at 20:06











  • You can use a class for everything that's common to all tasks, and known about by the application. Use a dictionary for the user-defined data. That dictionary should be in a class attribute.

    – Barmar
    Mar 7 at 20:09
















0















I am making a to do list manager. Each item on the list is an object belonging to the class "Task", which has the attributes shown. Each time the user calls the function "taskmaker", the Task object is added to a dictionary taskDict with a key (count) that incrementally increases by one for every task created.



The program then prints me a list of the tasks created, and their respective keys using print(taskDict).



Currently, I get the object's generated name, and key. I would like to display just attributes of each object, such as "taskname" and "duedate" which the user defines.



import datetime


class Task:
def __init__(self, taskname, datecreated, iscomplete, datecomplete, duedate, duetime, importance, isproject, projectname, category, repeat, timetodo, scheduledate):
self.taskname = taskname
self.datecreated = datecreated
self.iscomplete = iscomplete
self.datecomplete = datecomplete
self.duedate = duedate
self.duetime = duetime
self.importance = importance
self.isproject = isproject
self.projectname = projectname
self.category = category
self.repeat = repeat
self.timetodo = timetodo
self.scheduledate = scheduledate


taskDict =
count = 0 # This is the key

decide: str = input("If you would like to add a task, type anything except 0. : ")


def taskmaker():
global decide
while decide != "0":
namer = input("Enter your task: ")
datecreateder = datetime.datetime.now()
duedater = input("When would you like this due? : ")
duetimer = input("At what time would you like this due? : ")
task = Task(namer, datecreateder, False, "", duedater, duetimer, 0, False, "", "", False, 1, "")
global count
taskDict[count] = task
count = count + 1
decide = input("If you would like to add a task, type anything except 0. : ")


taskmaker()

print(taskDict)


I have had no luck finding resources that point to how this is done that weren't severely downvoted.



Here is the console input and output.



If you would like to add a task, type anything except 0. : 1
Enter your task: Chemistry homework
When would you like this due? : Tomorrow
At what time would you like this due? : Noon
If you would like to add a task, type anything except 0. : 2
Enter your task: History Essay
When would you like this due? : Wednesday
At what time would you like this due? : Midnight
If you would like to add a task, type anything except 0. : 0
0: <__main__.Task object at 0x000001AFBADCCEB8>, 1: <__main__.Task object at 0x000001AFBADCCE48>









share|improve this question






















  • Put the user-defined data in a dictionary, then loop over the dictionary elements and print the keys and values.

    – Barmar
    Mar 7 at 19:43











  • @Barmar That sounds like a temporary fix? I am pretty new to this so I cant be sure though. If I am totally wrong, please extrapolate and I will try to do that.Later in this program, I need to go in and change some of these attributes, so the program needs to be able to read them straight from the objects. I am only using a dictionary to make it easier to point to those objects using the key.

    – Andrew Buhrow
    Mar 7 at 19:54











  • Why is it a temporary fix? Class attributes are normally attributes that are known about by the class methods. Dynamic properties should not be class attributes, since they're just arbitrary name-to-value mappings. And that's what a dictionary is good for.

    – Barmar
    Mar 7 at 19:57











  • Ah. Should I be using dictionaries for each task then? Currently every instance of the class is a task, and all its attributes are writable so the user dictates what each of its attribute values are. Again I am quite new to coding, so if there is a better way of going about this I am all ears.

    – Andrew Buhrow
    Mar 7 at 20:06











  • You can use a class for everything that's common to all tasks, and known about by the application. Use a dictionary for the user-defined data. That dictionary should be in a class attribute.

    – Barmar
    Mar 7 at 20:09














0












0








0








I am making a to do list manager. Each item on the list is an object belonging to the class "Task", which has the attributes shown. Each time the user calls the function "taskmaker", the Task object is added to a dictionary taskDict with a key (count) that incrementally increases by one for every task created.



The program then prints me a list of the tasks created, and their respective keys using print(taskDict).



Currently, I get the object's generated name, and key. I would like to display just attributes of each object, such as "taskname" and "duedate" which the user defines.



import datetime


class Task:
def __init__(self, taskname, datecreated, iscomplete, datecomplete, duedate, duetime, importance, isproject, projectname, category, repeat, timetodo, scheduledate):
self.taskname = taskname
self.datecreated = datecreated
self.iscomplete = iscomplete
self.datecomplete = datecomplete
self.duedate = duedate
self.duetime = duetime
self.importance = importance
self.isproject = isproject
self.projectname = projectname
self.category = category
self.repeat = repeat
self.timetodo = timetodo
self.scheduledate = scheduledate


taskDict =
count = 0 # This is the key

decide: str = input("If you would like to add a task, type anything except 0. : ")


def taskmaker():
global decide
while decide != "0":
namer = input("Enter your task: ")
datecreateder = datetime.datetime.now()
duedater = input("When would you like this due? : ")
duetimer = input("At what time would you like this due? : ")
task = Task(namer, datecreateder, False, "", duedater, duetimer, 0, False, "", "", False, 1, "")
global count
taskDict[count] = task
count = count + 1
decide = input("If you would like to add a task, type anything except 0. : ")


taskmaker()

print(taskDict)


I have had no luck finding resources that point to how this is done that weren't severely downvoted.



Here is the console input and output.



If you would like to add a task, type anything except 0. : 1
Enter your task: Chemistry homework
When would you like this due? : Tomorrow
At what time would you like this due? : Noon
If you would like to add a task, type anything except 0. : 2
Enter your task: History Essay
When would you like this due? : Wednesday
At what time would you like this due? : Midnight
If you would like to add a task, type anything except 0. : 0
0: <__main__.Task object at 0x000001AFBADCCEB8>, 1: <__main__.Task object at 0x000001AFBADCCE48>









share|improve this question














I am making a to do list manager. Each item on the list is an object belonging to the class "Task", which has the attributes shown. Each time the user calls the function "taskmaker", the Task object is added to a dictionary taskDict with a key (count) that incrementally increases by one for every task created.



The program then prints me a list of the tasks created, and their respective keys using print(taskDict).



Currently, I get the object's generated name, and key. I would like to display just attributes of each object, such as "taskname" and "duedate" which the user defines.



import datetime


class Task:
def __init__(self, taskname, datecreated, iscomplete, datecomplete, duedate, duetime, importance, isproject, projectname, category, repeat, timetodo, scheduledate):
self.taskname = taskname
self.datecreated = datecreated
self.iscomplete = iscomplete
self.datecomplete = datecomplete
self.duedate = duedate
self.duetime = duetime
self.importance = importance
self.isproject = isproject
self.projectname = projectname
self.category = category
self.repeat = repeat
self.timetodo = timetodo
self.scheduledate = scheduledate


taskDict =
count = 0 # This is the key

decide: str = input("If you would like to add a task, type anything except 0. : ")


def taskmaker():
global decide
while decide != "0":
namer = input("Enter your task: ")
datecreateder = datetime.datetime.now()
duedater = input("When would you like this due? : ")
duetimer = input("At what time would you like this due? : ")
task = Task(namer, datecreateder, False, "", duedater, duetimer, 0, False, "", "", False, 1, "")
global count
taskDict[count] = task
count = count + 1
decide = input("If you would like to add a task, type anything except 0. : ")


taskmaker()

print(taskDict)


I have had no luck finding resources that point to how this is done that weren't severely downvoted.



Here is the console input and output.



If you would like to add a task, type anything except 0. : 1
Enter your task: Chemistry homework
When would you like this due? : Tomorrow
At what time would you like this due? : Noon
If you would like to add a task, type anything except 0. : 2
Enter your task: History Essay
When would you like this due? : Wednesday
At what time would you like this due? : Midnight
If you would like to add a task, type anything except 0. : 0
0: <__main__.Task object at 0x000001AFBADCCEB8>, 1: <__main__.Task object at 0x000001AFBADCCE48>






python class dictionary printing attributes






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 19:38









Andrew BuhrowAndrew Buhrow

83




83












  • Put the user-defined data in a dictionary, then loop over the dictionary elements and print the keys and values.

    – Barmar
    Mar 7 at 19:43











  • @Barmar That sounds like a temporary fix? I am pretty new to this so I cant be sure though. If I am totally wrong, please extrapolate and I will try to do that.Later in this program, I need to go in and change some of these attributes, so the program needs to be able to read them straight from the objects. I am only using a dictionary to make it easier to point to those objects using the key.

    – Andrew Buhrow
    Mar 7 at 19:54











  • Why is it a temporary fix? Class attributes are normally attributes that are known about by the class methods. Dynamic properties should not be class attributes, since they're just arbitrary name-to-value mappings. And that's what a dictionary is good for.

    – Barmar
    Mar 7 at 19:57











  • Ah. Should I be using dictionaries for each task then? Currently every instance of the class is a task, and all its attributes are writable so the user dictates what each of its attribute values are. Again I am quite new to coding, so if there is a better way of going about this I am all ears.

    – Andrew Buhrow
    Mar 7 at 20:06











  • You can use a class for everything that's common to all tasks, and known about by the application. Use a dictionary for the user-defined data. That dictionary should be in a class attribute.

    – Barmar
    Mar 7 at 20:09


















  • Put the user-defined data in a dictionary, then loop over the dictionary elements and print the keys and values.

    – Barmar
    Mar 7 at 19:43











  • @Barmar That sounds like a temporary fix? I am pretty new to this so I cant be sure though. If I am totally wrong, please extrapolate and I will try to do that.Later in this program, I need to go in and change some of these attributes, so the program needs to be able to read them straight from the objects. I am only using a dictionary to make it easier to point to those objects using the key.

    – Andrew Buhrow
    Mar 7 at 19:54











  • Why is it a temporary fix? Class attributes are normally attributes that are known about by the class methods. Dynamic properties should not be class attributes, since they're just arbitrary name-to-value mappings. And that's what a dictionary is good for.

    – Barmar
    Mar 7 at 19:57











  • Ah. Should I be using dictionaries for each task then? Currently every instance of the class is a task, and all its attributes are writable so the user dictates what each of its attribute values are. Again I am quite new to coding, so if there is a better way of going about this I am all ears.

    – Andrew Buhrow
    Mar 7 at 20:06











  • You can use a class for everything that's common to all tasks, and known about by the application. Use a dictionary for the user-defined data. That dictionary should be in a class attribute.

    – Barmar
    Mar 7 at 20:09

















Put the user-defined data in a dictionary, then loop over the dictionary elements and print the keys and values.

– Barmar
Mar 7 at 19:43





Put the user-defined data in a dictionary, then loop over the dictionary elements and print the keys and values.

– Barmar
Mar 7 at 19:43













@Barmar That sounds like a temporary fix? I am pretty new to this so I cant be sure though. If I am totally wrong, please extrapolate and I will try to do that.Later in this program, I need to go in and change some of these attributes, so the program needs to be able to read them straight from the objects. I am only using a dictionary to make it easier to point to those objects using the key.

– Andrew Buhrow
Mar 7 at 19:54





@Barmar That sounds like a temporary fix? I am pretty new to this so I cant be sure though. If I am totally wrong, please extrapolate and I will try to do that.Later in this program, I need to go in and change some of these attributes, so the program needs to be able to read them straight from the objects. I am only using a dictionary to make it easier to point to those objects using the key.

– Andrew Buhrow
Mar 7 at 19:54













Why is it a temporary fix? Class attributes are normally attributes that are known about by the class methods. Dynamic properties should not be class attributes, since they're just arbitrary name-to-value mappings. And that's what a dictionary is good for.

– Barmar
Mar 7 at 19:57





Why is it a temporary fix? Class attributes are normally attributes that are known about by the class methods. Dynamic properties should not be class attributes, since they're just arbitrary name-to-value mappings. And that's what a dictionary is good for.

– Barmar
Mar 7 at 19:57













Ah. Should I be using dictionaries for each task then? Currently every instance of the class is a task, and all its attributes are writable so the user dictates what each of its attribute values are. Again I am quite new to coding, so if there is a better way of going about this I am all ears.

– Andrew Buhrow
Mar 7 at 20:06





Ah. Should I be using dictionaries for each task then? Currently every instance of the class is a task, and all its attributes are writable so the user dictates what each of its attribute values are. Again I am quite new to coding, so if there is a better way of going about this I am all ears.

– Andrew Buhrow
Mar 7 at 20:06













You can use a class for everything that's common to all tasks, and known about by the application. Use a dictionary for the user-defined data. That dictionary should be in a class attribute.

– Barmar
Mar 7 at 20:09






You can use a class for everything that's common to all tasks, and known about by the application. Use a dictionary for the user-defined data. That dictionary should be in a class attribute.

– Barmar
Mar 7 at 20:09













0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55051600%2fhow-can-i-print-out-an-attribute-or-a-series-of-attributes-of-a-class-object-fro%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55051600%2fhow-can-i-print-out-an-attribute-or-a-series-of-attributes-of-a-class-object-fro%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved