Pickle file and send via socket

2012-08-06 Thread S.B
Hello friends

Does anyone know if it's possible to pickle and un-pickle a file across a 
network socket. i.e: 
First host pickles a file object and writes the pickled file object to a client 
socket.
Second host reads the pickled file object from the server socket and un-pickles 
it.

Can anyone provide a simple code example of the client and server sides?

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle file and send via socket

2012-08-07 Thread S.B
On Monday, August 6, 2012 4:32:13 PM UTC+3, S.B wrote:
> Hello friends
> 
> 
> 
> Does anyone know if it's possible to pickle and un-pickle a file across a 
> network socket. i.e: 
> 
> First host pickles a file object and writes the pickled file object to a 
> client socket.
> 
> Second host reads the pickled file object from the server socket and 
> un-pickles it.
> 
> 
> 
> Can anyone provide a simple code example of the client and server sides?
> 
> 
> 
> Thanks

Lot's of conflicting answers :-(

Can anyone provide a simple code example?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle file and send via socket

2012-08-08 Thread S.B
On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote:
> On 06/08/12 14:32, S.B wrote:
> 
> > Hello friends
> 
> >
> 
> > Does anyone know if it's possible to pickle and un-pickle a file across a 
> > network socket. i.e:
> 
> > First host pickles a file object and writes the pickled file object to a 
> > client socket.
> 
> > Second host reads the pickled file object from the server socket and 
> > un-pickles it.
> 
> >
> 
> > Can anyone provide a simple code example of the client and server sides?
> 
> >
> 
> > Thanks
> 
> >
> 
> 
> 
> Hi
> 
> 
> 
> Firstly I am a raw beginner at Python and I don't publish this code
> 
> as a good example of anything. It works for me on Ubuntu Linux 12.04 and 
> 
> Python3.2
> 
> 
> 
> As usual I welcome constructive comments but I will be working on this 
> 
> more to help me understand exactly what is going on
> 
> 
> 
> http://pastebin.com/iFzK7fuk SpaceTravellers.py
> 
> http://pastebin.com/TdqPwMGi NetworkPickler.py
> 
> http://pastebin.com/DF5DtYRZ NetworkUnpickler.py
> 
> 
> 
> lipska
> 
> 
> 
> -- 
> 
> Lipska the Kat: Troll hunter, sandbox destroyer
> 
> and farscape dreamer of Aeryn Sun

Thank you so much !
The examples are very helpful. 
What happens if I have a regular text file I want to send via the network.
Do I need to read the file and then dump it into the "stargate" file object?
-- 
http://mail.python.org/mailman/listinfo/python-list


finding a regular expression in a file

2012-04-24 Thread S.B
Hello friends.

Newb question here.
I'm trying to find an efficient way to "grep" a file with python.
The problem is that all the solutions I find on the web read a line at a time 
from the file with a "for line in" loop and check each line for the RE instead 
of sweeping through the entire file.
This looks terribly inefficient...

I can read the entire file like so:
open("/etc/passwd").read() 
and use that in an re.search - e.g:
re.search("root",open("/etc/passwd").read())
The above will work BUT it will not interpolate the "\n" as a newline and will 
just print the entire file as a long line.
So if I try to look for '^root' (line starting with root) instead of 'root' it 
will NOT work

any ideas on how to get around this?

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list