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?
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
|
show 2 more comments
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
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
|
show 2 more comments
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
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
python class dictionary printing attributes
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
|
show 2 more comments
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
|
show 2 more comments
0
active
oldest
votes
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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