473,473 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to pass an object

39 New Member
hi,

could you please help me in passing object to memcache set() function
actuallly i want to pass my class object as a key to memcache set(key,value) function,
i have tried str() function but i doesn't work
if you can provide a sample code that will be good for me
i am using python 2.5 on my ubuntu machine.
Oct 14 '07 #1
2 1274
bartonc
6,596 Recognized Expert Expert
hi,

could you please help me in passing object to memcache set() function
actuallly i want to pass my class object as a key to memcache set(key,value) function,
i have tried str() function but i doesn't work
if you can provide a sample code that will be good for me
i am using python 2.5 on my ubuntu machine.
If you will provide a snippet, we'll be glad to take a look at it.
Oct 14 '07 #2
diwakar09
39 New Member
If you will provide a snippet, we'll be glad to take a look at it.
Expand|Select|Wrap|Line Numbers
  1. import os
  2. import memcache
  3. import helper
  4. import time
  5. from dThread import dThread
  6. import cPickle as pickle
  7. CClientArray = []
  8. Objectke = []
  9. #j = 1
  10. def to_s(val):
  11.     """
  12.     Convert val to string.
  13.     """
  14.     if not isinstance(val, str):
  15.         return "%s (%s)" % (val, type(val))
  16.     return val
  17. class CClient(dThread):
  18.     mc = None
  19.     newval = None
  20.     #ival = None
  21.     ObjectKey = None
  22.     def __init__(self):
  23.         try:
  24.             dThread.__init__(self)
  25.             self.mc = memcache.Client(['192.168.1.68:11211'], debug=0)
  26.             self.newval = None
  27.            # self.ival = i
  28.             self.Objectkey = None
  29.             #self.ival = i
  30.            # self.logfile = file(filename, 'w')
  31.         except:
  32.             print "in constructor"
  33.  
  34.     #def __init__(self, value, filename):
  35.  
  36.  
  37.  
  38.     def setValue(self, ivalue):
  39.         try:
  40.             #temp = Objectke[ivalue]
  41.  
  42.             #key = str(ivalue)
  43.  
  44.             value = "CClientclass for new test" #+ str(j)
  45.             # j = j+1
  46.             self.mc.set(ivalue, value)
  47.  
  48.         except:
  49.             print "in setvalue"
  50.  
  51.     def showVal(self):
  52.         print self.newval
  53.  
  54.     def getValue(self,ivalue):
  55.         try:
  56.             temp = Objectke[ivalue]
  57.             #print temp
  58.             #i = str(temp)
  59.             #print self.mc.get(temp)
  60.             #showVal();
  61.         except:
  62.             print "in getvalue"
  63.  
  64.     def setObjectValue(self, key):
  65.         self.Objectkey = key
  66.  
  67.     def getObjectValue(self ):
  68.         return self.Objectkey 
  69.  
  70.  
  71. def startClient():
  72.     mc = memcache.Client(['192.168.1.68:11211'], debug=0)
  73.     mc.flush_all()
  74.     for i in range(1, 10):
  75.         obj = CClient()
  76.         CClientArray.append(obj)
  77.         try:
  78.            temp = pickle.dumps(obj)
  79.            obj.setValue(temp)
  80.         except:
  81.             print "error in appending"
  82.  
  83.     print "after set the value  "
  84. """    
  85.     for i in range(1, 10):
  86.         obj = CClientArray[i]
  87.         obj.getValue(i)
  88.  
  89.     print "after getting the value"
  90. """
  91.  
Thanx for replying me,
i just want to pass object of CClient class int memcache set function as a key,

if you can make this code work this will be good for me.
Thanx
Oct 14 '07 #3

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

Similar topics

110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
3
by: Andrew Mueller | last post by:
Hello, I tried this question prior and got no response, so thought I would try to explain differently.. I am not sure which type of object to pass between a VB 6.0 ActiveX dll and C#. I am...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
10
by: John Bailo | last post by:
I want to pass a SqlCommand object as a input parameter to a method. I want to pass the SqlCommand "by value" so that any updates to the original object are *not* reflected in the object within...
4
by: Jon Slaughter | last post by:
I'm reading a book on C# and it says there are 4 ways of passing types: 1. Pass value type by value 2. Pass value type by reference 3. Pass reference by value 4. Pass reference by reference. ...
13
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
9
by: raylopez99 | last post by:
I'm posting this fragment from another thread to frame the issue clearer. How to pass an object to a function/method call in C# that will guarantee not to change the object?* In C++, as seen...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
Oralloy
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,...
0
jinu1996
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.