Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 20th, 2004, 02:23 PM
cyberinder cyberinder is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 cyberinder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
fileupload in Python ?

hi,

i wrote a chat programm with SimpleXMLRPCServer. Now I've to write a code which uploads any kind of file to another client.
I got the tipp opening the file in binary mode, which I tried also and didn't work the way I wanted. It gave something in unicode, ascii code whatever back.
Actually it should open the file in " 0 1 " - format and than I've to send it to the server as an array.
So my question is how to open the file in 01 - format?
I searched the internet and found something with the cgi module , but I didn't understand how to use it.
Hope someone could help me out.

greets,

cyberinder


code which opens a file and saves it somewhere :

Code:
  
data=""
def save(path):
    global data
    f=open(path,'w')
    f.truncate()
    f.close()
    f=open(path,'ab')
    f.write(str(data[0]))                     
    f.close()

def open(path):
    global data
    f=open(path,"rb")
    data=f.readlines(),[]
  #  print data
    f.close()
    return data

Reply With Quote
  #2  
Old June 21st, 2004, 01:53 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 2 m 16 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
There is an unpload function in my Acticle on devshed, not sure if this will help though since it is CGI based and your using XMLRPC and creating a web service - or i assume, but worth a look.

http://www.devshed.com/c/a/Python/Python-on-the-Web/

As for opening the file in '01' mode, is this not binary since binary code consists of 0 and 1 bit values? Anyway i believe if you open an ASCII file in binary mode it still gets treated as ACSII - it doesn't convert it to binary; if you need that to happen then you could probably fo it manually with the XOR operator but i havn't tried this yet.

Hope this helps,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old June 21st, 2004, 06:24 PM
cyberinder cyberinder is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 cyberinder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi,

thanks for your help but somehow I didn't understand the part with the upload etc.

So far I tried my upper code and it worked .

Code:
data=""
def save(path):
    global data
    f=open(path,'wb')# instead of "w" , "wb"
    f.truncate()
    f.close()
    f=open(path,'ab')
    f.write(str(data[0]))                     
    f.close()

def open(path):
    global data
    f=open(path,"rb")
    data=f.readlines(),[]
  #  print data
    f.close()
    return data


With that code I can "copy" a file on my local computer. Now the problem with the xmlrpclib Protocol is that you can't send any exe, jpg, pdf etc files. It accepts only text files which do not have any unknown character like ü , ä , ö etc.
Hope someone knows a way out of that problem.

greetz,
Cyberinder

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > fileupload in Python ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway