Hi ,
The below snippet of the code is returing the empty dict,but I would like to get the values in the dict as {1:200,2:300,3:400}.
Could anybody suggest what method I have to use to return the dict values as function argument. - Sample.py
-
-
class Sample:
-
def __init__(self):
-
pass
-
def Func2(self):
-
dataDict2 = {1:200,2:300,3:400}
-
return dataDict2
-
-
def Func1(self,dataDict):
-
dataDict = self.Func2()
-
if __name__ == '__main__':
-
-
dataDict = {}
-
objSample = Sample()
-
objSample.Func1(dataDict)
-
print dataDict
-
-
Thanks
PSB
4 1578
Hi ,
The below snippet of the code is returing the empty dict,but I would like to get the values in the dict as {1:200,2:300,3:400}.
Could anybody suggest what method I have to use to return the dict values as function argument. - Sample.py
-
-
class Sample:
-
def __init__(self):
-
pass
-
def Func2(self):
-
dataDict2 = {1:200,2:300,3:400}
-
return dataDict2
-
-
def Func1(self,dataDict):
-
dataDict = self.Func2()
-
if __name__ == '__main__':
-
-
dataDict = {}
-
objSample = Sample()
-
objSample.Func1(dataDict)
-
print dataDict
-
-
Thanks
PSB
Try something like this: -
class Sample:
-
def __init__(self):
-
self.dd = {}
-
-
def func2(self):
-
self.dd = {1 : 200, 2 : 300, 3 : 400}
-
-
def func1(self):
-
return self.dd
-
-
obj = Sample();
-
obj.func2()
-
dd = obj.func1()
-
Update the dict rather than reassign (much like aList.append()): - class Sample:
-
def __init__(self):
-
pass
-
def Func2(self):
-
dataDict2 = {1:200,2:300,3:400}
-
return dataDict2
-
-
def Func1(self, dd):
-
dd.update(self.Func2())
-
if __name__ == '__main__':
-
-
dataDict = {}
-
objSample = Sample()
-
objSample.Func1(dataDict)
-
print dataDict
Update the dict rather than reassign (much like aList.append()): - class Sample:
-
def __init__(self):
-
pass
-
def Func2(self):
-
dataDict2 = {1:200,2:300,3:400}
-
return dataDict2
-
-
def Func1(self, dd):
-
dd.update(self.Func2())
-
if __name__ == '__main__':
-
-
dataDict = {}
-
objSample = Sample()
-
objSample.Func1(dataDict)
-
print dataDict
Thanks for the idea.But I need to pass the dict variable as argument for different methods of a class/classes.So it possible to send the dict variable as argument and get it back with the modified or filled elements in the dict variable
Thanks
PSB
Thanks for the idea.But I need to pass the dict variable as argument for different methods of a class/classes.So it possible to send the dict variable as argument and get it back with the modified or filled elements in the dict variable
Thanks
PSB
It's pass-by-reference so the update thing work the same as
and vise versa. I was simply trying to keep your structure in tact.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Russ Chinoy |
last post by:
Hi,
This may be a totally newbie question, but I'm stumped.
If I have a function such as:
function DoSomething(strVarName) {
.....
}
|
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c...
|
by: David Bear |
last post by:
I have a dictionary that contains a row of data intended for a data base.
The dictionary keys are the field names. The values are the values to be
inserted.
I am looking for a good pythonic...
|
by: Martin Chen |
last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main
frame. The contents frame has a menu bar written with with javascript (in
the context of a table). In IE6.1 everything...
|
by: RubenDV |
last post by:
I am writing code for a dictionary type in c, but i have some problems
allocating the memory for it. The dictionary type itself is a struct
with the following contents:
typedef struct {
char **...
|
by: Martin Jørgensen |
last post by:
Hi,
I'm relatively new with C-programming and even though I've read about
pointers and arrays many times, it's a topic that is a little confusing
to me - at least at this moment:
----
1)...
|
by: H J van Rooyen |
last post by:
Hi,
I am struggling to get the pack method to do what I intend.
I am trying to display user input in a seperate window, along with
a little description of the field, something like this:
...
|
by: Betina Andersen |
last post by:
I have a dictionary object, then I create a new dictionary object and sets
it equal to my original, then I pass the new dictionary object to a function
that changes some of my values - but then my...
|
by: Kev |
last post by:
Hello,
I have an Access 2003 database running on an XP network.
I have a datasheet subform containing a 28 day roster - shift1 to
shift28.
Each record has 1 RosterEmpID, 1 EmployeeNumber, 28...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| | |