[Tutor] Problem recognizing '{' character?

Ben Hunter bjameshunter at gmail.com
Tue Mar 29 18:13:28 CEST 2011


Thanks a ton. For the record I did read the 'command' module help page, but
must have skipped over the 'Platforms: Unix' and 'Deprecated' parts. I
successfully got it to work with the subprocess module, but I really
appreciate you filling out the rest with the sys.stderr.write(stderrdata). I
certainly would have stumbled over that.

-BJH


On Mon, Mar 28, 2011 at 8:12 PM, Ben Hunter <bjameshunter at gmail.com> wrote:

> Hi,
>
> I'm completing the Python lessons on YouTube that Google posted. At the end
> of section 2 of day 2, there is a task to identify files then put them in a
> zip file in any directory. The code is from the 'solution' folder, so it's
> not something I wrote. I suspect I have a problem with PATHS or environment
> variables. I'm new to programming in something as advanced as Python, but I
> do okay with VBA - so I just feel like there's a setting up issue somewhere.
> I'm on Windows 7, tried running this in Idle and from the command line.
>
> These two work perfectly.
>
> def get_special_paths(dirname):
>   result = []
>   paths = os.listdir(dirname)  # list of paths in that dir
>   for fname in paths:
>     match = re.search(r'__(\w+)__', fname)
>     if match:
>       result.append(os.path.abspath(os.path.join(dirname, fname)))
>   return result
>
>
> def copy_to(paths, to_dir):
>   if not os.path.exists(to_dir):
>     os.mkdir(to_dir)
>   for path in paths:
>     fname = os.path.basename(path)
>     shutil.copy(path, os.path.join(to_dir, fname))
>
> This third one does not.
>
> def zip_to(paths, zipfile):
>   """Zip up all of the given files into a new zip file with the given
> name."""
>   cmd = 'zip -j ' + zipfile + ' ' + ' '.join(paths)
>   print "Command I'm going to do:" + cmd
>   (status, output) = commands.getstatusoutput(cmd)
>   # If command had a problem (status is non-zero),
>   # print its output to stderr and exit.
>   if status:
>     sys.stderr.write(output)
>     sys.exit(1)
>
> My command is this: >>> copyspecial.zip_to(paths, 'zippy')
>
> But something goes wrong and it spits this out:
> '{' is not recognized as an internal or external command,
> operable program or batch file.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110329/758f2813/attachment.html>


More information about the Tutor mailing list