Hi,
Is it possible to send a non-string object from a Python program to
another? I particularly need to send a dictionary over to the other
program. However, this is not possible using the socket object's send()
function.
Help?
Buhi 12 2996
mumebuhi wrote:
Hi,
Is it possible to send a non-string object from a Python program to
another? I particularly need to send a dictionary over to the other
program. However, this is not possible using the socket object's send()
function.
Help?
Buhi
You will need to pickle it first and unpickle it on the other
end. Other than that, you should be able to send it just fine.
-Larry
mumebuhi a écrit :
Hi,
Is it possible to send a non-string object from a Python program to
another? I particularly need to send a dictionary over to the other
program. However, this is not possible using the socket object's send()
function.
Help?
>>d = dict(one=1, two="three", question="life, universe, and everything") import simplejson s = simplejson.dumps(d) s
'{"question": "life, universe, and everything", "two": "three", "one": 1}'
>>simplejson.loads(s) == d
True http://cheeseshop.python.org/pypi/simplejson
If you *really* want to "share" objects between programs, there are way
to do so (pyro comes to mind). But this gets more complicated...
Thank you very much for the reply.
Can pickle work directly with socket? The way I am doing right now is
to pickle the object to a file then send the file content through the
socket.
The simplejson module is really cool and simple to use. This is great!
For others who are just starting to use Python (like myself), simply
download and decompress the source bundle then copy the simplejson
directory to your sys.path (e.g. /usr/lib/python2.4/).
Thanks so much, Bruno.
Buhi
Bruno Desthuilliers wrote:
mumebuhi a écrit :
Hi,
Is it possible to send a non-string object from a Python program to
another? I particularly need to send a dictionary over to the other
program. However, this is not possible using the socket object's send()
function.
Help?
>d = dict(one=1, two="three", question="life, universe, and everything")
>>import simplejson
>>s = simplejson.dumps(d)
>>s
'{"question": "life, universe, and everything", "two": "three", "one": 1}'
>>simplejson.loads(s) == d
True
http://cheeseshop.python.org/pypi/simplejson
If you *really* want to "share" objects between programs, there are way
to do so (pyro comes to mind). But this gets more complicated...
Larry Bates <la*********@websafe.comwrites:
mumebuhi wrote:
Is it possible to send a non-string object from a Python program
to another? I particularly need to send a dictionary over to the
other program. However, this is not possible using the socket
object's send() function.
You want what is called "serialisation": turning a data structure in
Python into a predictable sequence of (usually text) bytes, to turn it
back into an identical data structure at some other point in time.
<URL:http://en.wikipedia.org/wiki/Serialization>
You will need to pickle it first and unpickle it on the other end.
There are many serialisation schemes possible; 'pickle' is just one
(and may be the right one in this case).
Others include JSON, marshal, some XML schema, etc.
--
\ "A child of five could understand this. Fetch me a child of |
`\ five." -- Groucho Marx |
_o__) |
Ben Finney
mumebuhi wrote:
Thank you very much for the reply.
Can pickle work directly with socket? The way I am doing right now is
to pickle the object to a file then send the file content through the
socket.
Pickle aso has dumps() and loads() to work with strings rather than
files.
Peace,
~Simon
mumebuhi wrote:
The simplejson module is really cool and simple to use. This is great!
For others who are just starting to use Python (like myself), simply
download and decompress the source bundle then copy the simplejson
directory to your sys.path (e.g. /usr/lib/python2.4/).
Alternatively, if you want a complete installation,
EITHER go to http://cheeseshop.python.org/pypi/simplejson
download and extract the source then run
python setup.py install
in the extracted directory.
OR if you have easy_install, just run
easy_install simplejson
If you don't have easy_install, get it!
Thanks so much, Bruno.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
"mumebuhi" <mu******@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
The simplejson module is really cool and simple to use. This is great!
JUST what I need for some configuration files!!
Thanks for the link (die, configparse, dieee).
Frithiof Andreas Jensen wrote:
>"mumebuhi" <mu******@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
>The simplejson module is really cool and simple to use. This is great!
JUST what I need for some configuration files!!
Thanks for the link (die, configparse, dieee).
I would personally use YAML for configuration files instead of JSON,
because it's more human-readable. But it's a matter of personal preference.
On 24 Oct 2006 16:56:43 -0700, Simon Forman <ro*********@yahoo.comwrote:
>
mumebuhi wrote:
Thank you very much for the reply.
Can pickle work directly with socket? The way I am doing right now is
to pickle the object to a file then send the file content through the
socket.
Pickle aso has dumps() and loads() to work with strings rather than
files.
I would recommend against using pickle if you're going to push it over
a network - there are signifigant dangers in unpickling anything
untrusted.
"Leif K-Brooks" <eu*****@ecritters.bizwrote in message
news:45***********************@news.sover.net...
Frithiof Andreas Jensen wrote:
"mumebuhi" <mu******@gmail.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
The simplejson module is really cool and simple to use. This is great!
JUST what I need for some configuration files!!
Thanks for the link (die, configparse, dieee).
I would personally use YAML for configuration files instead of JSON,
because it's more human-readable. But it's a matter of personal preference.
Hehe: I am using YAML now. I find it readable - human ... hmm ;-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: james |
last post by:
Hello,
I have an Access 2K application that several users on a network will be
working with. They will each have a copy of the "front-end" and will
link to a common "back-end" database located on...
|
by: Stephan Steiner |
last post by:
Hi
I'm trying to get some control over the speed I'm sending out packets in a
networking application. Using UDP sockets, if I send at full speed, I
eventually have packets that never make it on...
|
by: Alan Pretre |
last post by:
I have an application installed at a customer site that has been getting a
general network error for a couple of years. I was hoping that .NET 2.0
would clear it up, but unfortunately it didn't. ...
|
by: John Bailo |
last post by:
I wrote a c# web service that sends an XmlDocument as a return type.
When I run it on a w2k iis machine, it takes 35s to 45s to send the data
to a client (I wrote a smart client c# app to consume...
|
by: Jenny |
last post by:
Hello All!
I have a long XML file that I should transmit to other computer using http.
Problem is that the whole XML Document is too large for one
transmitting.
What is the nicest way to...
|
by: mfleet1973 |
last post by:
Hello Again.
I have a program that sends e-mails as follows:
Try
Dim mail As New MailMessage
mail.To = "me@comp.com"
mail.From = "me@comp.com
mail.Subject = "Test"
mail.Body = "Testing123"
|
by: david |
last post by:
hello,
I have a client/server application. the server capture picture from
webcam and send it to every client connected to it.the network part
works good and the capture from webcam too. I...
|
by: sachin2 |
last post by:
I am using 3 types of dictionaries.
1) Dictionary<string, string > d = new Dictionary<string, string>();
2) Dictionary<string, List<string>> d = new Dictionary<string, List<string>>();
3)...
|
by: Ivan Dewolf |
last post by:
I saw this thread:
http://bytes.com/topic/python/answers/553952-sending-dictionary-via-network
which works nicely for tiny dictionaries, but my sample pickled dictionary is about 500,000...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: 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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |