Path: csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail 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; 'subject:Python': 0.06; '(b)': 0.07; 'column': 0.07; 'method.': 0.07; 'subject:file': 0.07; 'string': 0.09; 'arguments': 0.09; 'f.close()': 0.09; 'newline': 0.09; 'repeated': 0.09; 'variables.': 0.09; 'python': 0.11; 'assume': 0.14; '2.7': 0.14; '.txt': 0.16; 'columns': 0.16; 'expecting': 0.16; 'guess.': 0.16; 'i.e': 0.16; 'matters,': 0.16; 'program?': 0.16; 'subject:writing': 0.16; 'thread,': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'written': 0.21; 'input': 0.22; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; '(a)': 0.24; 'questions:': 0.24; 'specify': 0.24; 'file.': 0.24; 'subject: : ': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; '(c)': 0.29; 'am,': 0.29; 'start,': 0.30; 'skip:( 20': 0.30; 'inspect': 0.31; 'linux.': 0.31; 'file': 0.32; 'run': 0.32; 'open': 0.33; 'everyone': 0.33; 'minimal': 0.33; 'skip:# 10': 0.33; "i'd": 0.34; 'but': 0.35; 'add': 0.35; 'version': 0.36; 'ubuntu': 0.36; "i'll": 0.36; 'should': 0.36; 'minimum': 0.38; 'easiest': 0.38; 'to:addr:python- list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'new': 0.61; "you're": 0.61; 'provide': 0.64; 'frequently': 0.68; 'received:74.208': 0.68; 'saturday': 0.68; 'day': 0.76; 'end.': 0.84; 'obvious,': 0.91 Date: Sat, 10 Jan 2015 10:37:55 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python : writing to a file References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:7LoZ5ucTRjNB2KpSUaznUB3nmiOITKwoqKoguKYU1/K 6QiTY8+TFysfVwq5WW1zQA3kaCieBKNtJdP+N/gxPIgiynfCZZ U4D2/iOobAdCInzsR9ShHcVMOtrGDex7Fc162UOGIHltV+V0Qs Qd8updusTovWmUiVD2EUS5GI+NykLsBHBs4F375KK5Ru43jRQf Tru3pVbsD/rtRLMix8tloBfjxMEaGbNtybsL0mzga64HXsQIs/ B34UCQ+gvL79qyUKhfsweVXZn1p6Lq5BkpV4lAzg4GNdAPfhqW s0i56vq64zR8B5m4VAv/6VTssLw5YaaltWqIqzU5jQLOH9kCk8 ADZCDfgTfBf5XTL993Xc= X-UI-Out-Filterresults: notjunk:1; X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420904295 news.xs4all.nl 2896 [2001:888:2000:d::a6]:38289 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83505 On 01/10/2015 10:14 AM, Ganesh Pal wrote: > Please provide you input on the below questions: > For each new thread, you should specify at a minimum your Python version and OS. it frequently matters, and it's better to specify than to have everyone try to guess. I'll assume Python 2.7 and Linux. > > (a) I was expecting the string i.e day of week , example Saturday to be > written in the file. what Iam I missing in the below program ? > > Program: > > #!/usr/bin/python > > import time > f = open ('test_2.txt','w+b') > DAY = time.strftime("%A") > f.write(DAY) > f.close() > > Throttling-1# cat test_2.txt Not to belabor the obvious, but did you run the program? I'd add at least one print to a minimal program to make sure you ran the same program as you show, and you can also use that to inspect the contents of variables. Works for me on ubuntu Python 2.7 Incidentally, I'd avoid using w+b. Just use wb if you're creating a file. > > (b) Iam trying to generate a file in the below format , > > cluster1# cat test_2.txt > > Saturday 0:05 0:10 > Saturday 0:10 0:20 > Saturday 0:20 0:30 > Saturday 0:40 0:50 > Saturday 0:60 0:70 > > (a) what is the easiest way to generate the above file fprmat ? > > (b) how will I take care that the below format is repeated in the .txt file > ( i.e column and row spacing) > > DAY OF THE WEEK [SPACE] START TIME [ SPACE] ENDTIME{SPACE] > > > (c) how do I add START TIME [ SPACE] ENDTIME{SPACE] columns > The use the str.format method. line = "{} {} {}\n".format(day, start, end) The curlies specify where the various arguments will be placed, and the "\n" generates a newline at the end. -- DaveA