473,287 Members | 1,800 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,287 software developers and data experts.

how to pass an object

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 1269
bartonc
6,596 Expert 4TB
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
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....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.