Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91013
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'operator': 0.03; 'importerror:': 0.05; '"__main__":': 0.07; '__name__': 0.07; 'wednesday,': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:create': 0.09; 'subject:files': 0.09; 'timestamp': 0.09; 'timestamps': 0.09; 'template': 0.11; 'def': 0.14; 'wed,': 0.15; 'everyone,': 0.15; '(say': 0.16; '1))': 0.16; 'itemgetter': 0.16; 'itertools': 0.16; 'mean,': 0.16; 'naming': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'seconds.': 0.16; 'specified.': 0.16; 'wrote:': 0.16; 'skip:" 40': 0.20; 'try:': 0.22; 'pass': 0.22; '2015': 0.23; 'normally': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:t 40': 0.27; 'hour.': 0.29; 'random': 0.29; 'skip:u 20': 0.30; 'folder': 0.31; 'seconds': 0.31; 'creating': 0.32; 'possibly': 0.32; 'combination': 0.33; 'this?': 0.34; 'file': 0.34; 'to:addr:python- list': 0.35; 'except': 0.36; 'there': 0.36; 'possible': 0.36; 'subject:: ': 0.37; 'received:org': 0.38; 'say': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'data': 0.40; 'received:de': 0.40; 'skip:t 20': 0.40; "you'll": 0.61; 'map': 0.61; 'within': 0.64; 'email addr:gmail.com': 0.64; '20,': 0.66; 'strategy': 0.69; 'serial': 0.70; 'million': 0.73; 'as:': 0.79; 'denis': 0.84; 'email name:denismfmcmahon': 0.84; 'mario': 0.84; 'mcmahon,': 0.84; 'utc-4,': 0.84; 'stamp': 0.91; 'subject:Best': 0.91; 'task,': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Best approach to create humongous amount of files |
| Date | Thu, 21 May 2015 18:28:19 +0200 |
| Organization | None |
| References | <mailman.166.1432123945.17265.python-list@python.org> <mjiij7$h2l$2@dont-email.me> <4a0e2c39-ff50-400f-b488-86a6cb37dbd6@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd81e7.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.202.1432225768.17265.python-list@python.org> (permalink) |
| Lines | 62 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1432225768 news.xs4all.nl 2838 [2001:888:2000:d::a6]:39923 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:91013 |
Show key headers only | View raw
Mario R. Osorio wrote:
> On Wednesday, May 20, 2015 at 2:09:59 PM UTC-4, Denis McMahon wrote:
>> On Wed, 20 May 2015 17:14:15 +0530, Parul Mogra wrote:
>>
>> > Hello everyone,
>> > My objective is to create large amount of data files (say a million
>> > *.json files), using a pre-existing template file (*.json). Each file
>> > would have a unique name, possibly by incorporating time stamp
>> > information. The files have to be generated in a folder specified.
>>
>> > What is the best strategy to achieve this task, so that the files will
>> > be generated in the shortest possible time? Say within an hour.
>>
>> timestamps are normally unixtime in seconds. There are 3600 seconds in an
>> hour. You'll have a hard job creating a million files with timestamp
>> based naming inside of an hour.
>>
>> --
>> Denis McMahon, denismfmcmahon@gmail.com
>
> I would use a combination of both, timestamp and a serial number, such as:
> 201505201425440000
> 201505201425440001
> 201505201425440002
> 201505201425440003
> 201505201425450000
> 201505201425450001
> 201505201425460000
> .. and so on ..
Like this?
import time
import itertools
from operator import itemgetter
try:
from itertools import imap as map
except ImportError:
pass
INDEX_TEMPLATE = "{}-{:02}-{:02}-{:02}-{:02}-{:02}-{i:03}"
def unique_names(template):
return (
template.format(INDEX_TEMPLATE.format(*t, i=i))
for g in map(itemgetter(1), itertools.groupby(iter(time.gmtime,
())))
for i, t in enumerate(g, 1))
if __name__ == "__main__":
import random
for name in unique_names("foo-{}.txt"):
print(name)
time.sleep(random.random())
I mean, readability counts...
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Best approach to create humongous amount of files Parul Mogra <scoria.799@gmail.com> - 2015-05-20 17:14 +0530
Re: Best approach to create humongous amount of files Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-20 18:08 +0000
Re: Best approach to create humongous amount of files "Mario R. Osorio" <nimbiotics@gmail.com> - 2015-05-21 08:54 -0700
Re: Best approach to create humongous amount of files Peter Otten <__peter__@web.de> - 2015-05-21 18:28 +0200
csiph-web