how to run another file inside current file?
hi, I want to run a another file inside a ached.add_cron_job(..). how is it possible, please help me, I have a file otherFile.py for execution inside current file. I know it is very easy question but i m unable to get anything, please help me. example -- import otherFile from apscheduler.scheduler import Scheduler sched = Scheduler() sched.start() def job_function(): # Can I here add that file for execution, Or can i add that file directly inside cron? sched.add_cron_job(job_function, month='1-12', day='1-31', hour='0-23',minute='44-49') -- http://mail.python.org/mailman/listinfo/python-list
python script is not running
hi, i want to run python script which generating data into json fromat, I am using crontab, but it's not executing... my python code-- try.py -- import json import simplejson as json import sys def tryJson(): saved = sys.stdout correctFile = file('data.json', 'a+') sys.stdout = correctFile result = [] i = 1 for i in range(5): info = { 'a': i+1, 'b': i+2, 'c': i+3, } result.append(info) if result: print json.dumps(result, indent=6) sys.stdout = saved correctFile.close() tryJson() now i m doing ion terminal- avin@hp:~$ crontab -e then type - */2 * * * * python /home/avin/data/try.py and save but it's not executing. -- http://mail.python.org/mailman/listinfo/python-list
How to run a python script twice randomly in a day?
hi, How to run a python script twice randomly in a day? Actually I want to run my script randomly in a day and twice only. Please help me.. how is it possible. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run a python script twice randomly in a day?
Thanks a lot. I got it. On Tue, May 21, 2013 at 6:42 AM, Cameron Simpson wrote: > On 20May2013 15:05, Avnesh Shakya wrote: > | Thanks a lot. > > No worries, but ... > > AGAIN: > - please DO NOT top post. Post below, trimming the quoted material. > - please POST TO THE LIST, not just to me. This is a public discussion. > > Now... > > | I did something. > | I have created test.sh file in which i put- > | > | #!/bin/bash > | cd /home/avin/cronJob > | python try.py > > Ok, good. Some minor remarks: > > Personally, I always use: > > #!/bin/sh > > instead of requiring bash. All UNIX systems have sh, bash is only > common. And even when present, it may not be in /bin. /bin/sh is > always there, and unless you're doing something quite unusual, it > works just fine. > > | then i went on terminal - > | and run crontab -e > | and wrote- > | */2 * * * * bash /home/avin/cronJob/test.sh > | and saved it. > > IIRC, this runs every two minutes. Good for testing, but not your original > spec. > > Also, if you make the shell script (test.sh) executable you do not > need to specify the interpreter. Treat your script like any other > command! So: > > chmod +rx /home/avin/cronJob/test.sh > > and then your cron line can look like this: > > */2 * * * * /home/avin/cronJob/test.sh > > Also, treat your script the same way as your shell script, start > it with a #! like this: > > #!/usr/bin/python > > Make it executable: > > chmod +rx /home/avin/cronJob/try.py > > and then you don't need to say "python" in your shell script: > > ./try.py > > (You need the ./ because the current directory is not in your command > search path ($PATH).) > > | It's working fine. > | but when I m using like > | > | import random > | a = random.randrange(0, 59) > | */a * * * * bash /home/avin/cronJob/test.sh > | then it's showing error becose of varable 'a', so now how can i take > | variable? > > I take it that this is your python program intended to schedule the two > randomly timed runs? > > As a start, it must all be python. The first two lines are. The third line > is > a crontab line. > > So as a start, you need to look more like this: > > #!/usr/bin/python > import random > a = random.randrange(0, 59) > cronline = '*/%d * * * * /home/avin/cronJob/test.sh' % (a,) > print(cronline) > > At least then you can see the cron line you're making. It still > does not add it to a cron job. > > Some remarks: > > - randrange() is like other python ranges: it does not include the end > value. > So your call picks a number from 0..58, not 0..59. > Say randrange(0,60). Think "start, length". > > - My recollection is that you wanted to run a script twice a day at random > times. > Your cron line doesn't do that. > > - If you're picking random run times you want to schedule a once-off > job for each to run at a particular times. Cron schedules repeating > jobs. To run at a particular time you want an "at" job. > > - You need to do one of two things in the pick-a-time script: > - pick a time, then sleep until that time and then directly > invoke the try.py script > or > - pick a time, then use the "at" command to schedule the try.py > (or test.sh) script. > > The first approach would look a bit like this (totally untested): > > #!/usr/bin/python > import random > import subporcess > import time > # choose range time in the next 24 hours > when = random.randrange(0, 24 * 3600) > # sleep that many seconds > time.sleep(when) > subprocess.call(['/home/avin/cronJob/test.sh']) > > For two runs, pick two times. Swap them into order. Sleep twice, > once until the first time and then once until the second time. Etc. > > The second approach (using "at") would not sleep. instead, compute > (using the datetime module) the date and time each job should run, > and invoke "at" using the subprocess module, piping the text > "/home/avin/cronJob/test.sh\n" to it. > > Cheers, > -- > Cameron Simpson > > On a related topic, has anyone looked at doing a clean-room copy of CSS > a la RC2 and RC4 a few years back? I know one or two people have > looked at this in an informal manner, but we couldn't find anyone who > hadn't already seen the DeCSS code to act as the clean person (it says > a lot for the status of their "trade secret" that we couldn't actually > find anyone who didn't already know it). > - Peter Gutmann > -- http://mail.python.org/mailman/listinfo/python-list
how to compare two json file line by line using python?
hi, how to compare two json file line by line using python? Actually I am doing it in this way.. import simplejson as json def compare(): newJsonFile= open('newData.json') lastJsonFile= open('version1.json') newLines = newJsonFile.readlines() print newLines sortedNew = sorted([repr(x) for x in newJsonFile]) sortedLast = sorted([repr(x) for x in lastJsonFile]) print(sortedNew == sortedLast) compare() But I want to compare line by line and value by value. but i found that json data is unordered data, so how can i compare them without sorting it. please give me some idea about it. I am new for it. I want to check every value line by line. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: how to compare two json file line by line using python?
Actually, I am extracting data from other site in json format and I want to put it in my database and when I extract data again then I want to compare last json file, if these are same then no issue otherwise i will add new data in database, so here may be every time data can be changed or may be not so I think sorting is required, but if i compare line by line that will be good, I am thinking in this way... On Mon, May 27, 2013 at 10:21 AM, rusi wrote: > On May 27, 9:32 am, Avnesh Shakya wrote: > > hi, > >how to compare two json file line by line using python? Actually I am > doing it in this way.. > > > > import simplejson as json > > def compare(): > > newJsonFile= open('newData.json') > > lastJsonFile= open('version1.json') > > newLines = newJsonFile.readlines() > > print newLines > > sortedNew = sorted([repr(x) for x in newJsonFile]) > > sortedLast = sorted([repr(x) for x in lastJsonFile]) > > print(sortedNew == sortedLast) > > > > compare() > > > > But I want to compare line by line and value by value. but i found that > json data is unordered data, so how can i compare them without sorting it. > please give me some idea about it. I am new for it. > > I want to check every value line by line. > > > > Thanks > > It really depends on what is your notion that the two files are same > or not. > > For example does extra/deleted non-significant white-space matter? > > By and large there are two approaches: > 1. Treat json as serialized python data-structures, (and so) read in > the data-structures into python and compare there > > 2. Ignore the fact that the json file is a json file; just treat it as > text and use string compare operations > > Naturally there could be other considerations: the files could be huge > and so you might want some hybrid of json and text approaches > etc etc > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: how to compare two json file line by line using python?
Thanks a lot, I got it. On Mon, May 27, 2013 at 11:03 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Sun, 26 May 2013 21:32:40 -0700, Avnesh Shakya wrote: > > > But I want to compare line by line and value by value. but i found that > > json data is unordered data, so how can i compare them without sorting > > it. please give me some idea about it. I am new for it. I want to check > > every value line by line. > > Why do you care about checking every value line by line? As you say > yourself, JSON data is unordered, so "line by line" is the wrong way to > compare it. > > > The right way is to decode the JSON data, and then compare whether it > gives you the result you expect: > > a = json.load("file-a") > b = json.load("file-b") > if a == b: > print("file-a and file-b contain the same JSON data") > > If what you care about is the *data* stored in the JSON file, this is the > correct way to check it. > > On the other hand, if you don't care about the data, but you want to > detect changes to whitespace, blank lines, or other changes that make no > difference to the JSON data, then there is no need to care that this is > JSON data. Just treat it as text, and use the difflib library. > > http://docs.python.org/2/library/difflib.html > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
How to create new python file with increament number, if doesn't exist?
hi, I want to create a new python file like 'data0.0.5', but if it is already exist then it should create 'data0.0.6', if it's also exist then next like 'data0.0.7'. I have done, but with range, please give me suggestion so that I can do it with specifying range. I was trying this way and it's working also.. i = 0 for i in range(100): try: with open('Data%d.%d.%d.json'%(0,0,i,)): pass continue except IOError: edxCorrectDataFile = file('Data%d.%d.%d.json'%(0,0,i,), 'a+') break But here I have defined range 100, Is it possible without range it create many required files? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create new python file with increament number, if doesn't exist?
Thanks On Mon, May 27, 2013 at 4:19 PM, Denis McMahon wrote: > On Mon, 27 May 2013 02:27:59 -0700, Avnesh Shakya wrote: > > > I want to create a new python file like 'data0.0.5', but if it is > > already exist then it should create 'data0.0.6', if it's also exist > > then next like 'data0.0.7'. I have done, but with range, please give > > me suggestion so that I can do it with specifying range. > > Try and put your description into the sequence of instructions you want > the computer follow. > > For this problem, my sequence of instructions would be: > > 1) Find the highest numbered existing file that matches the filename > data0.0.[number] > > 2) Create a new file that is one number higher. > > Now the solution is easy. Find the list of filenames in the directory > that match a suitable regular expression, take the numeric value of a > substring of the filename for each file and find the highest, add one to > it, then create the new file name. > > Something like the following (untested) with the relevant imports etc: > > nfn="data0.0."+str(max([int(f[8:])for f in os.listdir(p)if re.match > ('^data0.0.[0-9]+$',f)])+1) > > -- > Denis McMahon, denismfmcma...@gmail.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Output is not coming with defined color
hi, I am trying to display my output with different colour on terminal, but it's coming with that colour code. Please help me how is it possible? my code is - from fabric.colors import green, red, blue def colorr(): a = red('This is red') b = green('This is green') c = blue('This is blue') d = {a, b, c} print d colorr() output - set(['\x1b[32mThis is green\x1b[0m', '\x1b[34mThis is blue\x1b[0m', '\x1b[31mThis is red\x1b[0m']) Thanks -- http://mail.python.org/mailman/listinfo/python-list
How to store a variable when a script is executing for next time execution?
hi, I am running a python script and it will create a file name like filename0.0.0 and If I run it again then new file will create one more like filename0.0.1.. my code is- i = 0 for i in range(1000): try: with open('filename%d.%d.%d.json'%(0,0,i,)): pass continue except IOError: dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+') break But It will take more time after creating many files, So i want to store value of last var "i" in a variable so that when i run my script again then I can use it. for example- my last created file is filename0.0.27 then it should store 27 in a variable and when i run again then new file should be created 0.0.28 according to last value "27", so that i could save time and it can create file fast.. Please give me suggestion for it.. How is it possible? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to store a variable when a script is executing for next time execution?
Thanks. On Thu, Jun 6, 2013 at 4:49 PM, Cameron Simpson wrote: > On 06Jun2013 03:50, Avnesh Shakya wrote: > | hi, > |I am running a python script and it will create a file name like > filename0.0.0 and If I run it again then new file will create one more like > filename0.0.1.. my code is- > | > | i = 0 > | for i in range(1000): > | try: > | with open('filename%d.%d.%d.json'%(0,0,i,)): pass > | continue > | except IOError: > | dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+') > | break > | But It will take more time after creating many files, So i want to store > value of last var "i" in a variable so that when i run my script again then > I can use it. for example- > | my last created file is filename0.0.27 then it should > store 27 in a variable and when i run again then new file should be created > 0.0.28 according to last value "27", so that i could save time and it can > create file fast.. > | > | Please give me suggestion for it.. How is it possible? > > Write it to a file? Read the file next time the script runs? > > BTW, trying to open zillions of files is slow. > But using listdir to read the directory you can see all the names. > Pick the next free one (and then test anyway). > -- > Cameron Simpson > > The mark must be robust enough to survive MP3 transmission over the > Internet, > but remain inaudible when played on the yet to be launched DVD-Audio > players. > - the SDMI audio watermarkers literally ask for the impossible, since all > audio compressors aim to pass _only_ human perceptible data > http://www.newscientist.com/news/news.jsp?id=ns224836 > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
how to install indico software?
please tell me someone, how to install indico software? I have link-- http://indico-software.org/wiki/Admin/Installation0.98 but i have problem, i have no sites-available folder inside apache, i m using window 7, please help me.. Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
trying to open index.py using Indico software......
hi, please help me... I have installed indico software and apache2,when i try to run it using http://indico/index.py,then it's downloading index.py, when i put http://indico, then it's showing all thing properly,but it's not showing index.py but downloading it it's not showing any error, even i have tried error.log.. Please help me, I m unable to get this thing Thanks -- http://mail.python.org/mailman/listinfo/python-list
Warning in python file when i m using pychecker.
hi, I am trying to run my file using pychecker, but it's showing warning. I am unable to get these warning. Please help me, how to remove these warning. I am using pychecker first time. avin@HP:~/github/UdacitySiteData$ pychecker udacity_to_jsonFinal.py Processing module udacity_to_jsonFinal (udacity_to_jsonFinal.py)... Warnings... [system path]/dist-packages/bs4/__init__.py:206: Parameter (successor) not used [system path]/dist-packages/bs4/__init__.py:209: Parameter (successor) not used [system path]/dist-packages/bs4/__init__.py:213: Local variable (tag) not used [system path]/dist-packages/bs4/element.py:306: Parameter (kwargs) not used [system path]/dist-packages/bs4/element.py:507: (id) shadows builtin [system path]/dist-packages/bs4/element.py:791: (next) shadows builtin [system path]/dist-packages/bs4/element.py:903: Invalid arguments to (__repr__), got 2, expected 1 Thanks. -- http://mail.python.org/mailman/listinfo/python-list