Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Jianling Fan Newsgroups: comp.lang.python Subject: Re: about special characters Date: Sat, 30 Apr 2016 13:48:05 -0600 Lines: 130 Message-ID: References: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> <142f82f4-b266-3b85-f606-e1b6d3246021@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de NiScOQfSXC04UbHssAGwowU+G2HfruTBz3fNOljVOkeg== Return-Path: 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; 'else:': 0.03; 'win32': 0.03; 'mrab': 0.05; 'sys': 0.05; '__name__': 0.07; 'filename': 0.07; 'cc:addr:python-list': 0.09; "%s'": 0.09; 'filename,': 0.09; 'oh,': 0.09; 'skip:" 80': 0.09; 'src': 0.09; 'src,': 0.09; 'subject:characters': 0.09; 'received:209.85.218': 0.10; 'python': 0.10; '2.7': 0.13; 'def': 0.13; 'ignore': 0.14; 'encoding': 0.15; 'everyone,': 0.15; "'__main__':": 0.16; '2.7.2': 0.16; '2016': 0.16; '236,': 0.16; 'dest': 0.16; 'dest)': 0.16; 'range,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sync': 0.16; 'unicode.': 0.16; 'wrote:': 0.16; 'much!': 0.18; 'version.': 0.18; 'windows': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fix': 0.21; '"",': 0.22; 'ascii': 0.22; 'os,': 0.22; 'problem:': 0.22; 'cc:no real name:2**0': 0.22; 'bit': 0.23; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'script': 0.25; 'skip:" 20': 0.26; 'skip:# 10': 0.27; 'switch': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'skip:( 20': 0.28; '50,': 0.29; 'path,': 0.29; 'url:mailman': 0.30; 'code': 0.30; 'skip:[ 10': 0.31; 'post': 0.31; 'good.': 0.32; 'source': 0.33; 'url:python': 0.33; 'traceback': 0.33; 'url:listinfo': 0.34; "skip:' 20": 0.34; 'file': 0.34; 'skip:d 20': 0.34; 'received:google.com': 0.35; 'path': 0.35; 'step': 0.36; 'but': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'list.': 0.37; 'received:209': 0.38; 'delete': 0.38; 'names': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'skip:e 20': 0.39; 'url:mail': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'more': 0.63; 'different': 0.63; 'face': 0.64; 'between': 0.65; 'soon': 0.65; '20,': 0.66; '>>>>>': 0.66; 'here': 0.66; '[error': 0.84; 'using.': 0.84; 'works!': 0.91; '74,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-transfer-encoding; bh=Elylf6KsEnn59w6sNjk1cC0irDhrPmT7WIPVh24UUHQ=; b=ckWCjB0AqY5I4zQ9mEtpfVgFUwjnB65R7X6qOPED6EPgDIKvt+YkKRQjoA1EzieA5v 6Tcoim+RjJWSYnCDWbB0pKmV73AGgVe0OdcoM9cbBzhUfuKPxj0xipaB5tm0C6xvh8HV txQ4NBziE3ufOwSQP5kteQpA1RUN7jnsy0FRqaPvwE3rQLRjSe/hmay62/NXtkPM9Zun +69uX475TGOFcj0ro5txmHbqkuNifQwgdkuMumdet5PH56zSwPawXfomX+k3G+BdSiiN bszy6nUAkxVS8BF6yzdn9S+gpxQDGCxuQasg78CBh3FUv6RCHLzMMt0jy3F8rEE5+r75 v4ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-transfer-encoding; bh=Elylf6KsEnn59w6sNjk1cC0irDhrPmT7WIPVh24UUHQ=; b=AyyYy/na1CbY8Yq5anWKzHXwhnc4Z0ZC5CtTOXcpOvRC8e5/8R5UUofZ5m97zD9FRk dm44eMDyDXdncwaHhow7cG/fgMdDjFkv0d599P0H+lXBuZHkXdBx4YsYDN1K6wQbGohD z70MeoWWX9GrDrS4WH33yvHzsessPVIgBpxuAFt0M//ERwwVg+qkBrGKKl8g4L7NjTlX 72HR1Zm3ZSKwx3x6sZjJ/vwuVgWNL8L6i6AVEtGD/djMbeSiTZQXPhJidJJzwOyuBWns OIj+tUHcnqGlRohOvLsaSSUj9a0MNoBcxqq/8X1fG5at7TlFT+eXOmYYAJxQcvViV2x9 y7hA== X-Gm-Message-State: AOPr4FVtJ9qnIQf0yZsXv+eSR4r7dDTndnt4ITvIR1MIvNYCS/ywznF+3BiBr599jDEEGgrS9OEyyNqY04Q2lg== X-Received: by 10.157.1.120 with SMTP id 111mr11271857otu.172.1462045685690; Sat, 30 Apr 2016 12:48:05 -0700 (PDT) In-Reply-To: <142f82f4-b266-3b85-f606-e1b6d3246021@mrabarnett.plus.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> <142f82f4-b266-3b85-f606-e1b6d3246021@mrabarnett.plus.com> Xref: csiph.com comp.lang.python:107923 Oh, it works! This is the simplest and best way! Thanks very much! On 30 April 2016 at 13:42, MRAB wrote: > On 2016-04-30 19:13, Jianling Fan wrote: >> >> Hello everyone, >> >> Thanks very much for all your replies and sorry for the inconvience. >> This is my first time to post question in this list. >> >> I am using python 2.7 in Windows 7 Enterprise version. >> >> Here is the the filename that cause the problem: "Decock-2013-On the >> potential of =CE=B418O and =CE=B415N.pdf" >> When I delete the "=CE=B4" in the filename, the script works good. >> >> Here is the output: >> >> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> runfile('P:/sync.py', wdir=3D'P:') >> >> Traceback (most recent call last): >> File "", line 1, in >> File >> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecusto= mize.py", >> line 699, in runfile >> execfile(filename, namespace) >> File >> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecusto= mize.py", >> line 74, in execfile >> exec(compile(scripttext, filename, 'exec'), glob, loc) >> File "P:/sync.py", line 50, in >> sync_files(src, dest) >> File "P:/sync.py", line 43, in sync_files >> sync(dir_cmp) >> File "P:/sync.py", line 20, in sync >> shutil.rmtree(f_right) >> File "C:\Python27\lib\shutil.py", line 236, in rmtree >> onerror(os.listdir, path, sys.exc_info()) >> File "C:\Python27\lib\shutil.py", line 234, in rmtree >> names =3D os.listdir(path) >> WindowsError: [Error 3] The system cannot find the path specified: >> 'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*' >> >> >> Here is my code to do this work: I am using this script to sync my >> files between different disks. >> >> #coding=3Dutf-8 >> >> import filecmp, shutil, os, sys >> >> SRC =3D r'C:/Disk/mystuff' >> DEST =3D r'P:/mystuff' >> >> IGNORE =3D ['Thumbs.db'] >> >> def get_cmp_paths(dir_cmp, filenames): >> return ((os.path.join(dir_cmp.left, f), >> os.path.join(dir_cmp.right, f)) for f in filenames) >> >> def sync(dir_cmp): >> for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only): >> if os.path.isfile(f_right): >> os.remove(f_right) >> else: >> shutil.rmtree(f_right) >> print('delete %s' % f_right) >> for f_left, f_right in get_cmp_paths(dir_cmp, >> dir_cmp.left_only+dir_cmp.diff_files): >> if os.path.isfile(f_left): >> shutil.copy2(f_left, f_right) >> else: >> shutil.copytree(f_left, f_right) >> print('copy %s' % f_left) >> for sub_cmp_dir in dir_cmp.subdirs.values(): >> sync(sub_cmp_dir) >> >> def sync_files(src, dest, ignore=3DIGNORE): >> if not os.path.exists(src): >> print('=3D =3Db Please check the source directory was exist') >> print('- -b Sync file failure !!!') >> return >> if os.path.isfile(src): >> print('#_# We only support for sync directory but not a single >> file,one file please do it by yourself') >> print('- -b Sync file failure !!!') >> return >> if not os.path.exists(dest): >> os.makedirs(dest) >> dir_cmp =3D filecmp.dircmp(src, dest, ignore=3DIGNORE) >> sync(dir_cmp) >> print('^_^ Sync file finished!') >> >> if __name__ =3D=3D '__main__': >> src, dest =3D SRC, DEST >> if len(sys.argv) =3D=3D 3: >> src, dest =3D sys.argv[1:3] >> sync_files(src, dest) >> > [snip] > You're using bytestrings (str). As soon as you step out of the ASCII > range, you can face problems with which encoding it's using. > > The simplest fix is to switch to using Unicode. > > Start with this change: > > SRC =3D ur'C:/Disk/mystuff' > DEST =3D ur'P:/mystuff' > > -- > https://mail.python.org/mailman/listinfo/python-list --=20 Jianling Fan =E6=A8=8A=E5=BB=BA=E5=87=8C