Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102742

There has to be a better way to split this string!

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Anthony Papillion <anthony@cajuntechie.org>
Newsgroups comp.lang.python
Subject There has to be a better way to split this string!
Date Tue, 9 Feb 2016 19:26:13 -0600
Lines 50
Message-ID <mailman.6.1455067587.7749.python-list@python.org> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de q+YgfIZ8a7B9FL0sO5eg5gzinKUXwvwHPkPdQwonChYA==
Return-Path <anthony@cajuntechie.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'skip:p 60': 0.05; 'ugly': 0.07; 'filename.': 0.09; 'pgp': 0.09; 'subject:string': 0.09; 'everyone,': 0.15; 'message-----': 0.15; '"-"': 0.16; '----- begin': 0.16; '-----end': 0.16; 'from:addr:anthony': 0.16; 'hash:': 0.16; 'help?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:6 60': 0.16; 'skip:f 60': 0.16; 'skip:j 60': 0.16; 'subject:There': 0.16; 'replacing': 0.23; 'signed': 0.24; 'header:User-Agent:1': 0.26; 'skip:m 30': 0.27; 'skip:u 20': 0.28; 'skip:i 60': 0.29; 'skip:y 60': 0.29; "i'm": 0.30; 'code': 0.30; 'anyone': 0.32; "can't": 0.32; 'returned': 0.32; 'thanks!': 0.34; 'file': 0.34; 'received:10.0': 0.34; 'skip:s 60': 0.35; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'received:10': 0.37; 'seem': 0.37; 'doing': 0.38; 'version': 0.38; 'to:addr:python.org': 0.40; 'skip:u 10': 0.61; 'here': 0.66; 'received:10.0.2': 0.84; 'ugly,': 0.84; 'subject:this': 0.85
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1
X-Zoho-Virus-Status 1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102742

Show key headers only | View raw


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hello Everyone,

I am using datetime.now() to create a unique version of a filename.
When the final file is named, it will look something like:

myfile-2015-02-09-19-08-45-4223

Notice I'm replacing all of the "."'s, " "'s, and ":"'s returned by
datetime.now() with "-"'s. I'm doing that using the following code but
it's freaking ugly and I KNOW there is a better way to do it. I just
can't seem to think of it right now. Can anyone help? What is the
"right", or at least, less ugly, way to do this task?

Here is the code I'm using:


    unprocessed_tag = str(datetime.datetime.now())
    removed_spaces = unprocessed_tag.split(" ")
    intermediate_string = removed_spaces[0] + "-" + removed_spaces[1]
    removed_colons = intermediate_string.split(":")
    intermediate_string = removed_colons[0] + "-" + removed_colons[1]
+ "-" + removed_colons[2]
    removed_dots = intermediate_string.split(".")
    final_string = removed.dots[0] + "-" + removed_dots[1]

    return final_string

Thanks!
Anthony

-----BEGIN PGP SIGNATURE-----

iQIcBAEBCgAGBQJWupG0AAoJEAKK33RTsEsVVJEQAKZEk5jolpxa4plDvW6rY9ux
YdXHxtBa3emLprVMJTAg6+NJLZaeBjulttWv2Vy1y2tE8j1prLqHVtzITdX5kVG5
z0VUZgLRYi9Ocfk5vz4lGsWEWwRtkUQrpodbXqCArerUkBqHEW/Bgs2PGq9FGbNP
6QCWLsNr1APkEl5q8P3QCM7x1z0nsQKsbVMdvNjfi2kzsvDIm6lXgl9uUFxOFesp
fUkuiLFHFpbIRnnMke2mLahXWyN14QNmw6OOkqG963gOjecfC+2dNozAOSf42ul+
s2p9h3BiwijMvU/nvc/6jR3uFmoE3dIcGWsyYFNPWnPvrHUy0qHIgcavWDEo3+cw
J+qOYSX3XlTIrGc5ZJKdJWs6FH7d1+WZ4GndSj316LAKq0XN46rq/ppJksStpUwU
I7Gmk9mAnRt9uZy25xsx93jY8IiiOKDmI1cTclo/UKAYvQk8ib/allLnVZrssmsc
2hgugwBe6R966wavdrYl/yt1VlfwRdImRUL6pTNnCDMYYcJS0F7ATJ/dWV9iRD0h
PiIiB6zB61EyKw1djBRQ0F8XqxNZK0qR0UMR5hPWJcHRp3y94bgl2tI0/aMXmFW+
jiwQ4ecNgqb9k2C6iok+9OXJ3YoqToVbXFS7/svXpS88giksS+Re+5RChxZGSWSd
gXhYvKEHs+2l3Vuyhdsr
=8uK+
-----END PGP SIGNATURE-----

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

There has to be a better way to split this string! Anthony Papillion <anthony@cajuntechie.org> - 2016-02-09 19:26 -0600

csiph-web