Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27607
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <sntshkmr60@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'sys': 0.05; 'inserts': 0.07; 'lines.': 0.07; 'subject:help': 0.07; '(without': 0.09; 'received:mail-vc0-f174.google.com': 0.09; 'script,': 0.09; 'subject:script': 0.09; 'file,': 0.15; 'to:name :python-list': 0.15; 'bug:': 0.16; 'letters.': 0.16; 'string': 0.17; 'fix': 0.17; 'code,': 0.18; 'file.': 0.20; 'import': 0.21; 'file:': 0.22; 'split': 0.23; 'script': 0.24; 'pass': 0.25; 'bugs': 0.27; 'replace': 0.27; 'message-id:@mail.gmail.com': 0.27; 'lines': 0.28; 'received:209.85.220.174': 0.29; 'words': 0.29; "skip:' 10": 0.30; 'stuff': 0.30; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'subject:" ': 0.36; 'does': 0.37; 'received:209': 0.37; 'store': 0.38; 'skip:l 20': 0.38; 'to:addr:python.org': 0.39; 'notice': 0.39; 'header:Received:5': 0.40; 'first': 0.61; 'back': 0.62; 'improved': 0.62; 'leaving': 0.62; 'here': 0.65; 'cutting': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=EqtZhzfCtAwDZQGB2bI/LwcAdT5JnkAOtEP7/yBQykk=; b=fgSOyXOuM49KceQeNk15JXgvgOIeYrXoboBmE1NrDIzTyatrZT77iJEGjYtl0uwVA4 BVSmNTJcKXOe8p/TK7DT5T/un/iZRRThdEHOCWF58r6+397tkYl+jy8/fdoi7JeuT84w AtHS0Kk4F2QNSIJ7ycWqctF9ZiUPxoxlZTCE5ZAAHmIpKnt7FNR0wt6uzNbyULxnW9kh uewOxwxOhXfuQFqp9+k8yLkCfJUmvNn5yk6bfL45WBRfM/WUj95DpyFmrwVIaBoO1cVL 6Ka3zNgtVDfghRuk8AMfMUFh9n8v/hluVZvUMAou1oMWi6rabEMqY0wdlc55e9a85WkR mLpA== |
| MIME-Version | 1.0 |
| Date | Wed, 22 Aug 2012 11:51:47 +0530 |
| Subject | help me debug my "word capitalizer" script |
| From | Santosh Kumar <sntshkmr60@gmail.com> |
| To | python-list <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3631.1345616511.4697.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1345616511 news.xs4all.nl 6913 [2001:888:2000:d::a6]:51382 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:27607 |
Show key headers only | View raw
Here is the script I am using:
from os import linesep
from string import punctuation
from sys import argv
script, givenfile = argv
with open(givenfile) as file:
# List to store the capitalised lines.
lines = []
for line in file:
# Split words by spaces.
words = line.split(' ')
for i, word in enumerate(words):
if len(word.strip(punctuation)) > 3:
# Capitalise and replace words longer than 3 (without
punctuation)
words[i] = word.capitalize()
# Join the capitalised words with spaces.
lines.append(' '.join(words))
# Join the capitalised lines by the line separator
capitalised = linesep.join(lines)
# Optionally, write the capitalised words back to the file.
print(capitalised)
Purpose of the script:
To capitalize the first letter of any word in a given file, leaving
words which have 3 or less letters.
Bugs:
I know it has many bugs or/and it can be improved by cutting down the
code, but my current focus is to fix this bug:
1. When I pass it any file, it does it stuff but inserts a blank
line everytime it processes a new line. (Please notice that I don't
want the output in an another file, I want it on screen).
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
help me debug my "word capitalizer" script Santosh Kumar <sntshkmr60@gmail.com> - 2012-08-22 11:51 +0530
Re: help me debug my "word capitalizer" script Hans Mulder <hansmu@xs4all.nl> - 2012-08-22 10:20 +0200
Re: help me debug my "word capitalizer" script MRAB <python@mrabarnett.plus.com> - 2012-08-22 16:40 +0100
csiph-web