Re: passing vars to py scipts in cron jobs

2007-08-08 Thread Noud Aldenhoven
On 8/7/07, Will Maier <[EMAIL PROTECTED]> wrote:
>
> On Tue, Aug 07, 2007 at 05:45:46PM -0400, brad wrote:
> > What's the proper way to call a py script and pass in variables
> > while doing cron jobs? I can run the scripts fine from idle,
> > python, etc using raw_input() to prompt users. The scripts have
> > classes with methods that need arguments.
>
> This is commonly done with either sys.argv (a list of arguments
> passed when invoking the script) or os.environ (a dictionary of
> environment variables and values). Use either to instantiate your
> classes or run functions.



You might also want to look at the function getopt <
http://docs.python.org/lib/module-getopt.html>.
It's used to parse the variables in sys.argv which makes it (in my opinion)
more user friendly.

-- 
<:3 )~
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Rational Numbers

2007-01-12 Thread Noud Aldenhoven

On 1/12/07, Facundo Batista <[EMAIL PROTECTED]> wrote:


Noud Aldenhoven wrote:

> There are a (small) couple of other issues where rational numbers could
be
> handy. That's because rational numbers are exact, irrational numbers (in
> python) aren't. But these issues are probably too mathematical to be
used in

For the sake of me being less ignorant, could you please point me a
language where irrational numbers are exact?



I'm not sure, but I tought MAPLE could do it. This language has been
designed for solving mathimatical equotations (and other simulair stuf) and
could handle irrational numbers.
But ofcourse irrational numbers could never be exact when printed in an
g-notation (g > 1) system.

But now I mention that sentense is wrong... it should be: "That's because
rational numbers are exact, but in python they aren't most of the time."

To make irrational numbers exact in python should be, I think, more
unefficient than making rational numbers. But they could be very handy too
for calculating maths or physics equotations.

Regards,

Noud

--
<:3 )~
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Rational Numbers

2007-01-11 Thread Noud Aldenhoven

On 1/11/07, Facundo Batista <[EMAIL PROTECTED]> wrote:


Python does not have rational numbers.



Ah, oke. Thank you, it seems I have enough information why they aren't
included in the core.

Question: Why do you say that it's a problem?


Well... Perhaps I word it wrong. It's not really a problem and if I need
rational numbers I'm smart enough to make an other algorithm that doesn't
need a build-in function for rational numbers.

I'm a mathematician (in learning, with a bad feeling for English) and don't
trust irrational numbers in programming languages.
It's, for example, in some cases it could be more efficient to compute an
irrational number with a rational numbers then using an advanced algorithm
of Euclides to compute the same.

To give a small example:

pi ~ 355/113
pi ~ 3.1415926

In my opinion the first one is better. But now I realise it's also the
slowest of the two implemented in python.

There are a (small) couple of other issues where rational numbers could be
handy. That's because rational numbers are exact, irrational numbers (in
python) aren't. But these issues are probably too mathematical to be used in
a programming language like python.

Regards,

Noud Aldenhoven

--
<:3 )~
-- 
http://mail.python.org/mailman/listinfo/python-list

Rational Numbers

2007-01-11 Thread Noud Aldenhoven

Hello,

When I was programming in a mathematical project I began to wonder if python
supports rational numbers[1]. In a language like magma[2] it's not such a
problem. Does python supports something simular?

Greetings,

Noud Aldenhoven

--
<:3 )~

[1] http://en.wikipedia.org/wiki/Rational_number
[2] http://www.math.uiuc.edu/Software/magma/text283.html
-- 
http://mail.python.org/mailman/listinfo/python-list

blabla

2005-05-22 Thread Noud Aldenhoven
Python rulz and sorry for this spam...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removing comments form a file

2005-01-03 Thread Noud Aldenhoven
Ah, 

Thank you, I never thaught about the re module. Now I can do some cool stuf.

Greetings,
Noud Aldenhoven

ps. Zal ik een keer langs komen? ;-P

[EMAIL PROTECTED] wrote:

> You cold do something like this:
> 
>>>> import re
>>>> commentpattern = re.compile('.*(?=//)|.*(?!//)')
>>>> stringwithcomment = 'Blah di blah // some comment'
>>>> match = commentpattern.match(stringwithcomment)
>>>> match.group()
> 'Blah di blah '
>>>> stringwithoutcomment = 'Blah di blah'
>>>> match = commentpattern.match(stringwithoutcomment)
>>>> match.group()
> 'Blah di blah'
>>>> blankline = '\n'
>>>> match = commentpattern.match(blankline)
>>>> match.group()
> ''
>>>>
> 
> and put this in a loop where you iterate over your file.
> Martin (The Netherlands, Amsterdam, bij Diemen)
> 
> Noud Aldenhoven wrote:
>> Hello everyone,
>>
>> I was wondering how to remove comments away form a file.
>> So that's why I made this script.
>>
>> ===
>> #!/usr/bin/env python
>>
>> import sys
>> import string
>> import time
>>
>> helptext = "usage: python rmcomment [oldfile] [newfile] [comment]"
>>
>> def rmcomment(oldfile, newfile, comment):
>> oldfile = open(oldfile, 'r')
>> newfile = open(newfile, 'w')
>> ccount = 0
>> lcount = 0
>> for line in oldfile.readlines():
>> splitline = string.split(line)
>> pstest = 0
>> fileline = ""
>> for word in splitline:
>> if word[:2] == comment:
>> pstest = -1
>> ccount += 1
>> pass
>> elif pstest == -1:
>> pass
>> else:
>> fileline += word + " "
>> if len(fileline) == 0:
>> pass
>> else:
>> newfile.write(fileline + "\n")
>> lcount += 1
>> print "Done... in %s seconds\nRemoved comment from %s
> lines\nWrote %
>> lines to %s" % (time.time()-start , ccount, lcount, newfile)
>> raw_input("Push the enter button to quit>")
>>
>> if __name__ == "__main__":
>> if sys.argv[1] == "-h" or sys.argv[1] == "-help":
>> print helptext
>> else:
>> start = time.time()
>> oldfile = sys.argv[1]
>> newfile = sys.argv[2]
>> comment = sys.argv[3]
>> rmcomment(oldfile, newfile, comment)
>>
>>
>> 
>>
>> This script works fine with standard text files. An example is this
> one:
>>
>> example.txt:
>>
>> Hello Fuckin' World //how are you doing today
>> //I think it delete this sentence and the next sentence too!
>>
>> But this one not! #Even not this comment
>>
>> end example.txt
>>
>> If I use my script, named rmcomment.py I get this:
>>
>> [EMAIL PROTECTED]:~/programmeren/python/rmcomment$ cat example.txt
>> Hello Fuckin' World //how are you doing today
>> //I think it delete this sentence and the next sentence too!
>>
>> But this one not! #Even not this comment's
>> [EMAIL PROTECTED]:~/programmeren/python/rmcomment$ python rmcomment.py
>> example.txt newexample.txt //
>> Done... in 0.00104999542236 seconds
>> Removed comment from 2 lines
>> Wrote  2nes to 
>> Push the enter button to quit>
>> [EMAIL PROTECTED]:~/programmeren/python/rmcomment$ cat newexample.txt
>> Hello Fuckin' World
>> But this one not! #Even not this comment
>> [EMAIL PROTECTED]:~/programmeren/python/rmcomment$
>>
>> works fine... but here's my problem. If I use rmcomment.py also the
>> whitelines will be removed. And I don't want that to happen. Here's
> another
>> example:
>>
>> [EMAIL PROTECTED]:~/programmeren/python/rmcomment$ cat otherexample.txt
>> //This shows what whitelines are doing here
>>left from me is a nice white line tabs
>> and here left are at least 3 white line tabs
>>
>> //and ofcourse, comments will be deleted
>> [EMAIL PROTECTED]:~/programmeren/python/rmcomment$ python rmcomment.py
>> otherexample.txt newotherexample.txt //
>> Done... in 0.0011351108551 seconds
>> Removed comment form 2 lines
>> Wrote  2nes to  0x403e1c60>
>> Push the enter button to quit>
>> [EMAIL PROTECTED]:~/programmeren/python/rmcomment$ cat newotherexample.txt
>> left from me is a nice white line tabs
>> and here left are at least 3 white line tabs
>> [EMAIL PROTECTED]:~/programmeren/python/rmcomment$
>>
>> My beautiful whitelines are gone! And I don't want that!
>> I've thaught how to fix this for a time, but I can't make it on my
> own. Too
>> less programming experiance, I'm afraid.
>> Could someone help me with this problem? Or fix the script or give a
> hint or
>> something?
>>
>> Thank you at least for reading this post,
>>
>> Noud Aldenhoven
>> The Netherlands (In de beurt bij Nijmegen, voor de nieuwschierigen)
>>
>> ps. Yes, I'm a Dyslextion and can't write correct english. I'm sorry
> for
>> that.

-- 
http://mail.python.org/mailman/listinfo/python-list


removing comments form a file

2005-01-03 Thread Noud Aldenhoven
Hello everyone,

I was wondering how to remove comments away form a file.
So that's why I made this script.

===
#!/usr/bin/env python

import sys
import string
import time

helptext = "usage: python rmcomment [oldfile] [newfile] [comment]"

def rmcomment(oldfile, newfile, comment):
oldfile = open(oldfile, 'r')
newfile = open(newfile, 'w')
ccount = 0
lcount = 0
for line in oldfile.readlines():
splitline = string.split(line)
pstest = 0
fileline = ""
for word in splitline:
if word[:2] == comment:
pstest = -1
ccount += 1
pass
elif pstest == -1:
pass
else:
fileline += word + " "
if len(fileline) == 0:
pass
else:
newfile.write(fileline + "\n")
lcount += 1
print "Done... in %s seconds\nRemoved comment from %s lines\nWrote %
lines to %s" % (time.time()-start , ccount, lcount, newfile)
raw_input("Push the enter button to quit>")

if __name__ == "__main__":
if sys.argv[1] == "-h" or sys.argv[1] == "-help":
print helptext
else:
start = time.time()
oldfile = sys.argv[1]
newfile = sys.argv[2]
comment = sys.argv[3]
rmcomment(oldfile, newfile, comment)




This script works fine with standard text files. An example is this one:

example.txt:

Hello Fuckin' World //how are you doing today
//I think it delete this sentence and the next sentence too!

But this one not! #Even not this comment

end example.txt

If I use my script, named rmcomment.py I get this:

[EMAIL PROTECTED]:~/programmeren/python/rmcomment$ cat example.txt
Hello Fuckin' World //how are you doing today
//I think it delete this sentence and the next sentence too!

But this one not! #Even not this comment's
[EMAIL PROTECTED]:~/programmeren/python/rmcomment$ python rmcomment.py
example.txt newexample.txt //
Done... in 0.00104999542236 seconds
Removed comment from 2 lines
Wrote  2nes to 
Push the enter button to quit>
[EMAIL PROTECTED]:~/programmeren/python/rmcomment$ cat newexample.txt
Hello Fuckin' World
But this one not! #Even not this comment
[EMAIL PROTECTED]:~/programmeren/python/rmcomment$

works fine... but here's my problem. If I use rmcomment.py also the
whitelines will be removed. And I don't want that to happen. Here's another
example:

[EMAIL PROTECTED]:~/programmeren/python/rmcomment$ cat otherexample.txt
//This shows what whitelines are doing here
   left from me is a nice white line tabs
and here left are at least 3 white line tabs

//and ofcourse, comments will be deleted
[EMAIL PROTECTED]:~/programmeren/python/rmcomment$ python rmcomment.py
otherexample.txt newotherexample.txt //
Done... in 0.0011351108551 seconds
Removed comment form 2 lines
Wrote  2nes to 
Push the enter button to quit>
[EMAIL PROTECTED]:~/programmeren/python/rmcomment$ cat newotherexample.txt
left from me is a nice white line tabs
and here left are at least 3 white line tabs
[EMAIL PROTECTED]:~/programmeren/python/rmcomment$

My beautiful whitelines are gone! And I don't want that!
I've thaught how to fix this for a time, but I can't make it on my own. Too
less programming experiance, I'm afraid.
Could someone help me with this problem? Or fix the script or give a hint or
something?

Thank you at least for reading this post,

Noud Aldenhoven
The Netherlands (In de beurt bij Nijmegen, voor de nieuwschierigen)

ps. Yes, I'm a Dyslextion and can't write correct english. I'm sorry for
that.






-- 
http://mail.python.org/mailman/listinfo/python-list