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


Groups > comp.lang.python > #74255 > unrolled thread

Writing Python File at Specific Interval

Started bysubhabangalore@gmail.com
First post2014-07-09 07:36 -0700
Last post2014-07-20 12:46 +0100
Articles 7 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Writing Python File at Specific Interval subhabangalore@gmail.com - 2014-07-09 07:36 -0700
    Re:Writing Python File at Specific Interval Dave Angel <davea@davea.name> - 2014-07-09 14:55 -0400
    Re: Writing Python File at Specific Interval Shubham Tomar <tomarshubham24@gmail.com> - 2014-07-09 22:47 +0530
    Re: Writing Python File at Specific Interval Abhiram R <abhi.darkness@gmail.com> - 2014-07-09 23:09 +0530
    Re: Writing Python File at Specific Interval Denis McMahon <denismfmcmahon@gmail.com> - 2014-07-09 23:51 +0000
      Re: Writing Python File at Specific Interval subhabangalore@gmail.com - 2014-07-20 04:15 -0700
        Re: Writing Python File at Specific Interval Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-20 12:46 +0100

#74255 — Writing Python File at Specific Interval

Fromsubhabangalore@gmail.com
Date2014-07-09 07:36 -0700
SubjectWriting Python File at Specific Interval
Message-ID<33d2582e-06b6-4cb9-8d60-7f94aa32283c@googlegroups.com>
Dear Group,

I am trying to write a file, which would create a new file name 
as the code runs. 

The code (a basic crawler) would run every morning 
or evening, on a predefined time. [This part is fine]. 

In the next part, I am trying to store the daily 
results to a new file. 

As I researched I found some tips around time module,
logging module, pythoncom etc. But not getting any important
lead.

If any one of the esteemed members may kindly suggest.

Regards,
Subhabrata Banerjee. 

[toc] | [next] | [standalone]


#74273

FromDave Angel <davea@davea.name>
Date2014-07-09 14:55 -0400
Message-ID<mailman.11707.1404931993.18130.python-list@python.org>
In reply to#74255
subhabangalore@gmail.com Wrote in message:
> 
> 
> In the next part, I am trying to store the daily 
> results to a new file. 
> 
> As I researched I found some tips around time module,
> logging module, pythoncom etc. But not getting any important
> lead.
> 

What exactly is the problem? Perhaps you want the file name to
 encode the date, so that today's filename might be 2014-07-09.txt
 ?

So you need to look up the current date, make a string from it,
 and create that file. 

What have you tried,  and what went wrong? 


-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#74275

FromShubham Tomar <tomarshubham24@gmail.com>
Date2014-07-09 22:47 +0530
Message-ID<mailman.11709.1404933902.18130.python-list@python.org>
In reply to#74255

[Multipart message — attachments visible in raw view] — view raw

Hi Subhabrata,

You can use open(name, 'w'), which creates the file if the file does not
exist, but it will truncate the existing file. Alternatively, you can use
open(name, 'a'); this will create the file if the file does not exist, but
will not truncate the existing file.

Ref.: open() <https://docs.python.org/2/library/functions.html#open>

Regards,
Shubham


On Wed, Jul 9, 2014 at 8:06 PM, <subhabangalore@gmail.com> wrote:

> Dear Group,
>
> I am trying to write a file, which would create a new file name
> as the code runs.
>
> The code (a basic crawler) would run every morning
> or evening, on a predefined time. [This part is fine].
>
> In the next part, I am trying to store the daily
> results to a new file.
>
> As I researched I found some tips around time module,
> logging module, pythoncom etc. But not getting any important
> lead.
>
> If any one of the esteemed members may kindly suggest.
>
> Regards,
> Subhabrata Banerjee.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [next] | [standalone]


#74276

FromAbhiram R <abhi.darkness@gmail.com>
Date2014-07-09 23:09 +0530
Message-ID<mailman.11710.1404933902.18130.python-list@python.org>
In reply to#74255

[Multipart message — attachments visible in raw view] — view raw

Looping in the list to improve on my suggestion or suggest an alternative


On Wed, Jul 9, 2014 at 11:03 PM, Abhiram R <abhi.darkness@gmail.com> wrote:

> Hi Subha,
> What is the current methodology you're using? If your code is already
> being called every 24 hours or whatever, you can use a "touch" command
> inside an os.system() call and create a new file and append your results to
> it, right? Is that what your objective is?
>
>
> On Wed, Jul 9, 2014 at 8:06 PM, <subhabangalore@gmail.com> wrote:
>
>> Dear Group,
>>
>> I am trying to write a file, which would create a new file name
>> as the code runs.
>>
>> The code (a basic crawler) would run every morning
>> or evening, on a predefined time. [This part is fine].
>>
>> In the next part, I am trying to store the daily
>> results to a new file.
>>
>> As I researched I found some tips around time module,
>> logging module, pythoncom etc. But not getting any important
>> lead.
>>
>> If any one of the esteemed members may kindly suggest.
>>
>> Regards,
>> Subhabrata Banerjee.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> Abhiram.R
> M.Tech CSE (Sem 3)
> RVCE
> Bangalore
>



-- 
Abhiram.R
M.Tech CSE (Sem 3)
RVCE
Bangalore

[toc] | [prev] | [next] | [standalone]


#74286

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-07-09 23:51 +0000
Message-ID<lpkkh5$kj$1@dont-email.me>
In reply to#74255
On Wed, 09 Jul 2014 07:36:49 -0700, subhabangalore wrote:

> The code (a basic crawler) would run every morning or evening, on a
> predefined time. [This part is fine].
> 
> In the next part, I am trying to store the daily results to a new file.

So what you want to do is store each day's results in a new file, so 
probably you want to create a filename that looks something like an iso 
8601 date.

Luckily for you python has this functionality available:

https://docs.python.org/2/library/datetime.html#date-objects

$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import date
>>> fn = date.today().isoformat() + ".log"
>>> print fn
2014-07-10.log
>>> quit()
$

Once you have a string containing your filename, you might use:

fp = open( fn, "w" )
fp.write( data )
fp.close()

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#74876

Fromsubhabangalore@gmail.com
Date2014-07-20 04:15 -0700
Message-ID<2c676709-ac9d-4623-971a-f6d089818601@googlegroups.com>
In reply to#74286
On Thursday, July 10, 2014 5:21:01 AM UTC+5:30, Denis McMahon wrote:
> On Wed, 09 Jul 2014 07:36:49 -0700, subhabangalore wrote:
> 
> 
> 
> > The code (a basic crawler) would run every morning or evening, on a
> 
> > predefined time. [This part is fine].
> 
> > 
> 
> > In the next part, I am trying to store the daily results to a new file.
> 
> 
> 
> So what you want to do is store each day's results in a new file, so 
> 
> probably you want to create a filename that looks something like an iso 
> 
> 8601 date.
> 
> 
> 
> Luckily for you python has this functionality available:
> 
> 
> 
> https://docs.python.org/2/library/datetime.html#date-objects
> 
> 
> 
> $ python
> 
> Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
> 
> [GCC 4.6.3] on linux2
> 
> Type "help", "copyright", "credits" or "license" for more information.
> 
> >>> from datetime import date
> 
> >>> fn = date.today().isoformat() + ".log"
> 
> >>> print fn
> 
> 2014-07-10.log
> 
> >>> quit()
> 
> $
> 
> 
> 
> Once you have a string containing your filename, you might use:
> 
> 
> 
> fp = open( fn, "w" )
> 
> fp.write( data )
> 
> fp.close()
> 
> 
> 
> -- 
> 
> Denis McMahon, denismfmcmahon@gmail.com

Dear Group,
Thank you for your kind suggestion. It worked. 
Regards,
Subhabrata Banerjee.

[toc] | [prev] | [next] | [standalone]


#74878

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-07-20 12:46 +0100
Message-ID<mailman.12095.1405856776.18130.python-list@python.org>
In reply to#74876
On 20/07/2014 12:15, subhabangalore@gmail.com wrote:
>
> Dear Group,
> Thank you for your kind suggestion. It worked.
> Regards,
> Subhabrata Banerjee.
>

I'm pleased to see that you have a solution.  In return would you please 
use the mailing list 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web