Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26238
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <tokauf@googlemail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'filename': 0.07; 'ok.': 0.07; 'subject:file': 0.07; 'python': 0.09; "'w')": 0.09; 'fp:': 0.09; 'loop.': 0.09; 'overwrite': 0.09; 'to:addr:comp.lang.python': 0.09; 'unexpected': 0.09; 'cc:addr :python-list': 0.10; 'receives': 0.13; 'bytes).': 0.16; 'codec': 0.16; 'decode': 0.16; 'incomplete': 0.16; 'iteration': 0.16; 'sonntag,': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'byte': 0.17; 'bytes': 0.17; '>>>': 0.18; 'file.': 0.20; 'do.': 0.21; '"",': 0.22; 'exists.': 0.22; 'tells': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'leave': 0.26; '(most': 0.27; '(as': 0.27; 'probably': 0.29; 'problem.': 0.32; 'file': 0.32; 'good.': 0.32; 'traceback': 0.33; 'code:': 0.33; 'skip:d 20': 0.34; "can't": 0.34; 'skip:b 20': 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'server': 0.35; 'from:addr:googlemail.com': 0.35; 'open': 0.35; 'too.': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'client': 0.36; 'subject: (': 0.36; 'received:209': 0.37; 'far': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'subject:-': 0.40; 'end': 0.40; 'skip:u 10': 0.60; 'first': 0.61; 'thomas': 0.62; 'ever': 0.63; 'receive': 0.71; '29.': 0.84; 'subject:content': 0.84; 'subject:write': 0.84 |
| Newsgroups | comp.lang.python |
| Date | Mon, 30 Jul 2012 02:50:12 -0700 (PDT) |
| In-Reply-To | <mailman.2692.1343574970.4697.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=88.73.121.54; posting-account=fVeGmgoAAACSXJJZA2P7ITa2D-cVKHno |
| References | <98f9b4a6-b797-40f3-a919-89c2d4fb4496@googlegroups.com> <mailman.2692.1343574970.4697.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 88.73.121.54 |
| MIME-Version | 1.0 |
| Subject | Re: newbie: write content in a file (server-side) |
| From | Thomas Kaufmann <tokauf@googlemail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.2721.1343641814.4697.python-list@python.org> (permalink) |
| Lines | 92 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1343641814 news.xs4all.nl 6968 [2001:888:2000:d::a6]:33504 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:26238 |
Show key headers only | View raw
Am Sonntag, 29. Juli 2012 17:16:11 UTC+2 schrieb Peter Otten:
> Thomas Kaufmann wrote:
>
>
>
> > I send from a client file content to my server (as bytes). So far so good.
>
> > The server receives this content complete. Ok. Then I want to write this
>
> > content to a new file. It works too. But in the new file are only the
>
> > first part of the whole content.
>
> >
>
> > What's the problem.
>
>
>
> > Here's my server code:
>
>
>
> > while True:
>
> > bytes = self.request.recv(4096)
>
> > if bytes:
>
> > s = bytes.decode("utf8")
>
> > print(s)
>
> > li = s.split("~")
>
> > with open(li[0], 'w') as fp:
>
> > fp.write(li[1])
>
>
>
> - Do you ever want to leave the loop?
>
>
>
> - You calculate a new filename on every iteration of the while loop --
>
> probably not what you intended to do.
>
>
>
> - The "w" argument tells Python to overwrite the file if it exists. You
>
> either need to keep the file open (move the with... out of the loop) or open
>
> it with "a".
>
>
>
> - You may not receive the complete file name on the first iteration of the
>
> while loop.
>
>
>
> - The bytes buffer can contain incomplete characters, e. g.:
>
>
>
> >>> data = b"\xc3\xa4"
>
> >>> data.decode("utf-8")
>
> 'รค'
>
> >>> data[:1].decode("utf-8")
>
> Traceback (most recent call last):
>
> File "<stdin>", line 1, in <module>
>
> UnicodeDecodeError: 'utf8' codec can't decode byte 0xc3 in position 0:
>
> unexpected end of data
Thanks Peter. It helps;-).
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
newbie: write content in a file (server-side) Thomas Kaufmann <tokauf@googlemail.com> - 2012-07-29 07:16 -0700
Re: newbie: write content in a file (server-side) Peter Otten <__peter__@web.de> - 2012-07-29 17:16 +0200
Re: newbie: write content in a file (server-side) Thomas Kaufmann <tokauf@googlemail.com> - 2012-07-30 02:50 -0700
Re: newbie: write content in a file (server-side) Thomas Kaufmann <tokauf@googlemail.com> - 2012-07-30 02:50 -0700
Re: newbie: write content in a file (server-side) Thomas Kaufmann <tokauf@googlemail.com> - 2012-07-30 02:51 -0700
csiph-web