473,378 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Automatically generate Objects from Dcitionary

1
Hi All!

Programming newbie here. I was looking way to generate instances of a class of my creation from a dictionary (That is in turn created from a tuple and a list, but that part works as I would expect.) Is there a way to do this? So far, what I had is:

Expand|Select|Wrap|Line Numbers
  1. key = ("a", "b", "c")
  2. attribute = [
  3.     ["a", 1, 2, 3],
  4.     ["b", 2, 3, 4],
  5.     ["c", 3, 4, 5]
  6.     ]
  7. obj = dict(zip(key, attribute))
  8.  
  9. class Some_object:
  10.     def __init__(self, name, attr1, attr2, attr3):
  11.         self.name = name
  12.         self.attr1 = attr1
  13.         self.attr2 = attr2
  14.         self.attr3 = attr3
  15.  
  16. for i in obj.keys():
  17.     name = obj[i][0]
  18.     attr1 = obj[i][1]
  19.     attr2 = obj[i][2]
  20.     attr3 = obj[i][3]
  21.     i = Some_object (name,  attr1, attr2, attr3)
This does seem to create the objects, at least inside the loop, but outside the loop there is no way of calling on them.

Thanks!
Apr 21 '20 #1
0 1387

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: yongwei | last post by:
I have a user control that used to work fine. But after I moved the project to another folder, one of the user control won't generate a .resouce file after rebuild, and the form contains the user...
1
by: lis0122 | last post by:
I have a table of contacts that is related (one to many) to a table of activities. I want to store a field of "MaxDate" for each contact in the contacts table based on the maximum date of their...
2
by: jmpinto | last post by:
I have a field on a form that I would like to automatically generate a number, in sequential order, each time a new record is created, and be stored in a field. The problem is that I do not want...
111
by: Nate | last post by:
Hello, I am looking for a method to automatically declare variables in C. I'm not sure if there is a good way to do this, but I had something like this in mind... int i; for(i = 1; i < 4;...
6
by: Freddy | last post by:
Hi all, I use a C program to generate lots of data while changing many parameters sometimes. However, I am trying to find a way to let C generate the output file names dependent on a few...
0
by: tomerdr | last post by:
Hi, I am looking for a software like ( MyGeneration or CodeSmith) which can automatically generate a BLL for use with ObjectDataSource. I dont need O\R mapper just a template which generate...
5
by: waiming | last post by:
Hi, I am trying to create a bunch of hidden objects in a Form to hold values so that they can be sent out using Formmail. The values will be assigned to ABC1, ABC2, via other statements. Instead...
6
by: GLEberts | last post by:
Novice looking for some direction!! I am trying to have a text box autopopulate with a number added to it at the end and I am having a difficult time doing this. Example: (1) I have a combo...
2
by: vkk49 | last post by:
hii i am using vs 10 & access database 7.i develop a small application that store sr no and name.so i want to generate sr no automatically in textbox . main thing is if there are total 5 sr no...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.