Can you help me???

2013-02-09 Thread MoneyMaker
Are you traveling abroad on holiday??? Does the resort have enough information 
on the internet??? Would you like to ask local people information about 
attractions, good places to eat, nice places, that is, just about anything??? 
For this site, I have asked people around the world to join and tell the 
tourists information about their own country / city. Similarly, when they 
themselves are traveling somewhere, they can get here also interesting 
information about the destination. A similar service has not to my knowledge 
found on the internet and I would hope that you decide to join as a free member 
and you will help other people to make their holiday a successful :)
And I also hope that if you are a self-help / information requirements, 
hopefully my site will also help you

http://theworldismy.webs.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Coercing one object to type of another

2013-02-09 Thread Vijay Shanker
Hi
Inside a function i get a two arguments, say arg1 and arg2, how can i convert 
arg2 to same type as arg1 ?
I dont know type of arg1 or arg2 for that matter, I just want to convert arg2 
to type of arg1 if possible and handle the exception if raised.
Also:
>>> int('2')
2
>>> float('2.0')
2.0
>>> coerce(2,2.0)
(2.0,2.0)
but coerce('2',2) fails.If int('2') equals 2, why should it fail ?


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


Re: Coercing one object to type of another

2013-02-09 Thread Chris Angelico
On Sat, Feb 9, 2013 at 9:29 PM, Vijay Shanker  wrote:
> Hi
> Inside a function i get a two arguments, say arg1 and arg2, how can i convert 
> arg2 to same type as arg1 ?
> I dont know type of arg1 or arg2 for that matter, I just want to convert arg2 
> to type of arg1 if possible and handle the exception if raised.
> Also:
 int('2')
> 2
 float('2.0')
> 2.0
 coerce(2,2.0)
> (2.0,2.0)
> but coerce('2',2) fails.If int('2') equals 2, why should it fail ?

You can get the type of any object, and call that:

def coerce(changeme,tothis):
return type(tothis)(changeme)

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


python3 binascii.hexlify ...

2013-02-09 Thread Cameron Simpson
This seems to return a bytes object in Python 3.3.0. I was expecting a
string. The documentation here:

  http://docs.python.org/3/library/binascii.html#binascii.hexlify

also keeps me expecting a string. Am I missing something?

Example:

  [hg/css-venti-bytes+utf8]fleet*2> python3
  Python 3.3.0 (default, Nov 11 2012, 08:47:42) 
  [GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))]
  on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import binascii
  >>> binascii.hexlify(b'abc')
  b'616263'
  >>> 

I'm on a Mac but am hoping that is irrelevant.

Cheers,
-- 
Cameron Simpson 

You can fool too many of the people too much of the time. - James Thurber
-- 
http://mail.python.org/mailman/listinfo/python-list


string.replace doesn't removes ":"

2013-02-09 Thread Joshua Robinson
Hi *Monte-Pythons*,

x = "this is a simple : text: that has colon"
s = x.replace(string.punctuation, "");  OR
s = x.replace(string.punctuation, "");
print x   # 'this is a simple : text: that has colon'
# The colon is still in the text 

Is this a bug or am I doing something wrong ?

Py.Version: 2.7
OS: Ubuntu 12.10 (64 bits)

Cheers,
-Joshua
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3 binascii.hexlify ...

2013-02-09 Thread Peter Otten
Cameron Simpson wrote:

> This seems to return a bytes object in Python 3.3.0. I was expecting a
> string. The documentation here:
> 
>   http://docs.python.org/3/library/binascii.html#binascii.hexlify
> 
> also keeps me expecting a string. Am I missing something?

"""Return the hexadecimal representation of the binary data. Every byte of 
data is converted into the corresponding 2-digit hex representation.
"""

makes it pretty clear that the function is operating on bytes, not str.

The following sentence "The resulting string..." is likely a leftover from 
Python 2 and should be fixed.

If you need str instead of bytes it's easy enough to do the 
encoding/decoding yourself:

>>> import binascii as ba
>>> ba.hexlify("äöü".encode())
b'c3a4c3b6c3bc'
>>> ba.unhexlify(_).decode()
'äöü'


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


Re: string.replace doesn't removes ":"

2013-02-09 Thread Chris Angelico
On Sat, Feb 9, 2013 at 10:04 PM, Joshua Robinson
 wrote:
> Hi Monte-Pythons,
>
> x = "this is a simple : text: that has colon"
> s = x.replace(string.punctuation, "");  OR
> s = x.replace(string.punctuation, "");
> print x   # 'this is a simple : text: that has colon'
> # The colon is still in the text 
>
> Is this a bug or am I doing something wrong ?

str.replace() replaces whole strings, not the individual characters.
You probably want str.translate():

s = x.translate(string.maketrans("",""),string.punctuation)

You'll then want to print s, rather than x, to see the difference.

Note that it's a little different in Python 3, and you would instead use:
s = x.translate(str.maketrans("","",string.punctuation))

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


Python3 curses behavior

2013-02-09 Thread Vlasov Vitaly
Hello.

I found strange behavior of curses module, that i can't understand. I 
initialize screen with curses.initscr(), then i create subwin of screen with 
screen.subwin(my_subwin_sizes). After that i fill subwin with my_char in 
for-loop. On last char in last line subwin.addch() raises exception.

This is my problem. Why? How to fix it?

(If i will ignore exception, then last char will be displayed)

Here simple example:
http://pastebin.com/SjyMsHZB

Thank You!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coercing one object to type of another

2013-02-09 Thread Vijay Shanker
On Saturday, February 9, 2013 4:13:28 PM UTC+5:30, Chris Angelico wrote:
> On Sat, Feb 9, 2013 at 9:29 PM, Vijay Shanker  wrote:
> 
> > Hi
> 
> > Inside a function i get a two arguments, say arg1 and arg2, how can i 
> > convert arg2 to same type as arg1 ?
> 
> > I dont know type of arg1 or arg2 for that matter, I just want to convert 
> > arg2 to type of arg1 if possible and handle the exception if raised.
> 
> > Also:
> 
>  int('2')
> 
> > 2
> 
>  float('2.0')
> 
> > 2.0
> 
>  coerce(2,2.0)
> 
> > (2.0,2.0)
> 
> > but coerce('2',2) fails.If int('2') equals 2, why should it fail ?
> 
> 
> 
> You can get the type of any object, and call that:
> 
> 
> 
> def coerce(changeme,tothis):
> 
> return type(tothis)(changeme)
> 
> 
> 
> ChrisA

well it will always return me this:


what i want is if i know arg1 is of string type(and it can be of any type, say 
list, int,float) and arg2 is of any type, how can i convert it to type of arg1,
if arg1='hello world', type(arg1).__name__ will give me 'str', can i use this 
to convert my arg2 to this type, w/o resorting to if-elif conditions as there 
will be too many if-elif-else and it doesn really sounds a great idea ! 
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3 binascii.hexlify ...

2013-02-09 Thread Chris Angelico
On Sat, Feb 9, 2013 at 10:10 PM, Peter Otten <__pete...@web.de> wrote:
> """Return the hexadecimal representation of the binary data. Every byte of
> data is converted into the corresponding 2-digit hex representation.
> """
>
> makes it pretty clear that the function is operating on bytes, not str.

That doesn't necessarily mean it has to return bytes, though. It's
taking binary data and producing something that's plausibly either
bytes or str. It's human-readable and would definitely make sense to
be str (for instance, hex() returns a str), so imo this should be made
very clear in the docs. Maybe:

"""Return the hexadecimal representation of the binary data. Every byte of
data is converted into two bytes with the corresponding hex
representation in ASCII.
"""

or somesuch?

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


Re: Python3 curses behavior

2013-02-09 Thread Chris Angelico
On Sat, Feb 9, 2013 at 10:23 PM, Vlasov Vitaly  wrote:
> Hello.
>
> I found strange behavior of curses module, that i can't understand. I 
> initialize screen with curses.initscr(), then i create subwin of screen with 
> screen.subwin(my_subwin_sizes). After that i fill subwin with my_char in 
> for-loop. On last char in last line subwin.addch() raises exception.
>
> This is my problem. Why? How to fix it?
>
> (If i will ignore exception, then last char will be displayed)
>
> Here simple example:
> http://pastebin.com/SjyMsHZB

What exception is being raised? That's kinda the most important part here :)

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


Re: Coercing one object to type of another

2013-02-09 Thread Chris Angelico
On Sat, Feb 9, 2013 at 10:23 PM, Vijay Shanker  wrote:
> well it will always return me this:
> 
>
> what i want is if i know arg1 is of string type(and it can be of any type, 
> say list, int,float) and arg2 is of any type, how can i convert it to type of 
> arg1,
> if arg1='hello world', type(arg1).__name__ will give me 'str', can i use this 
> to convert my arg2 to this type, w/o resorting to if-elif conditions as there 
> will be too many if-elif-else and it doesn really sounds a great idea !

Oh, okay. Then switch the order of the arguments in what I posted:

def coerce(target,convertme):
return type(target)(convertme)

You don't need to worry about the actual name of the type. It's
telling you that it's ; that's an actual callable object
(the same as the builtin name str, in this case). You can then call
that to coerce the other argument to that type.

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


Alternatives to Splunk?

2013-02-09 Thread sssdevelop
Are there any opensource alternatives to Splunk? 
Need tool to analyze the log files..

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


Re: Python3 curses behavior

2013-02-09 Thread Vlasov Vitaly
суббота, 9 февраля 2013 г., 15:28:51 UTC+4 пользователь Chris Angelico написал:
> On Sat, Feb 9, 2013 at 10:23 PM, Vlasov Vitaly  wrote:
> 
> > Hello.
> 
> >
> 
> > I found strange behavior of curses module, that i can't understand. I 
> > initialize screen with curses.initscr(), then i create subwin of screen 
> > with screen.subwin(my_subwin_sizes). After that i fill subwin with my_char 
> > in for-loop. On last char in last line subwin.addch() raises exception.
> 
> >
> 
> > This is my problem. Why? How to fix it?
> 
> >
> 
> > (If i will ignore exception, then last char will be displayed)
> 
> >
> 
> > Here simple example:
> 
> > http://pastebin.com/SjyMsHZB
> 
> 
> 
> What exception is being raised? That's kinda the most important part here :)
> 
> 
> 
> ChrisA

curses.error <-- all curses-related exception
Exception text: curses.error: 'addch() returned ERR'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jinja2 installation help

2013-02-09 Thread Robert Iulian
Here is the fucked up thing that I learned from all the hours of reading from 
different websites and documentation.

To install Pip I need to install Easy_Install--> To install Easy_install I need 
to install Setup Tools whitch is NOT compatible with Python 3.XX ... If PIP is 
a replacement for Easy-install why does it require IT? What is going on?

PS: I am a Windows 7 user.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jinja2 installation help

2013-02-09 Thread Kwpolska
On Sat, Feb 9, 2013 at 1:55 PM, Robert Iulian  wrote:
> Here is the fucked up thing that I learned from all the hours of reading from 
> different websites and documentation.
>
> To install Pip I need to install Easy_Install--> To install Easy_install I 
> need to install Setup Tools whitch is NOT compatible with Python 3.XX ... If 
> PIP is a replacement for Easy-install why does it require IT? What is going 
> on?
>
> PS: I am a Windows 7 user.
> --
> http://mail.python.org/mailman/listinfo/python-list

It doesn’t require easy_install, nor setuptools (only distribute).
http://www.pip-installer.org/en/latest/installing.html#using-get-pip

-- 
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jinja2 installation help

2013-02-09 Thread Robert Iulian
Ah...Must have slipped that. It worked!

Thank you all for the support ! Be well !

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


Re: Alternatives to Splunk?

2013-02-09 Thread Rodrick Brown
On Sat, Feb 9, 2013 at 7:27 AM, sssdevelop  wrote:

> Are there any opensource alternatives to Splunk?
> Need tool to analyze the log files..
>
>
This is highly off topic, however I'm using logstash + kibana for my log
analysis.


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


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread Dave Angel

On 02/09/2013 09:27 AM, Morten Engvoldsen wrote:

Hi Team,
I Have saved my output in .doc file and want to format the output with

*Start the File 

Some data here


***End of File*

Can you let me know how can i do that using Python?





Just add an output statement right after creating the file, and another 
just before closing it.


This is assuming that this is a text file.  By explicitly telling us it 
has a .doc extension, you may be trying to tell us it's in some 
proprietary file format whose type we have to guess.


BTW, if you actually wanted *code*, you might have considered including 
some more information about your environment.  For example a print 
statement is an output statement in Python 2.x, while the print function 
in Python 3.x looks quite different, at least when directed to a file.


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


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread D'Arcy J.M. Cain
On Sat, 9 Feb 2013 15:27:16 +0100
Morten Engvoldsen  wrote:
> I Have saved my output in .doc file and want to format the output with
> 
> *Start the File 
> 
> Some data here
> 
> 
> ***End of File*
> 
> Can you let me know how can i do that using Python?

Seems pretty simple.  Open the file, read it into a variable, print the
header, print the data and then print the footer.  Which part are you
struggling with? Show us your code so far.

Or is the issue with the .doc file?  Is it a Word document or simple
text?

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net, VOIP: sip:da...@vex.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread Morten Engvoldsen
Hi Cain,
Thanks for your reply. I am stroning all the contents in "batchdate" and
then,

data = base64.encodestring(batchdata)

and then writing "data" in doc file.

I know i can append  "***Start file***" in the
batchdata, but is there a better python code like multiply * into 10 times
-- any python code i can add the formatting in dynamic way instead of
hardcoding with "***Start file***" line.

Thanks for your reply again.




On Sat, Feb 9, 2013 at 3:38 PM, D'Arcy J.M. Cain  wrote:

> On Sat, 9 Feb 2013 15:27:16 +0100
> Morten Engvoldsen  wrote:
> > I Have saved my output in .doc file and want to format the output with
> >
> > *Start the File 
> >
> > Some data here
> >
> >
> > ***End of File*
> >
> > Can you let me know how can i do that using Python?
>
> Seems pretty simple.  Open the file, read it into a variable, print the
> header, print the data and then print the footer.  Which part are you
> struggling with? Show us your code so far.
>
> Or is the issue with the .doc file?  Is it a Word document or simple
> text?
>
> --
> D'Arcy J.M. Cain  |  Democracy is three wolves
> http://www.druid.net/darcy/|  and a sheep voting on
> +1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
> IM: da...@vex.net, VOIP: sip:da...@vex.net
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread Peter Otten
Morten Engvoldsen wrote:

> I know i can append  "***Start file***" in the
> batchdata, but is there a better python code like multiply * into 10 times
> -- any python code i can add the formatting in dynamic way instead of
> hardcoding with "***Start file***" line.

>>> print " Start file ".center(40, "*")
** Start file **


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


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread Morten Engvoldsen
Hi Davea,
I am using Python 2.7.
-- 
http://mail.python.org/mailman/listinfo/python-list


Logwatch python

2013-02-09 Thread Cleuson Alves
Hello, I am trying to run this code, but I get an answer incorrect arguments 
numbers. someone could put an example of arguments for me to use in the / var / 
log?

Thank you.



import os, sys
from optparse import OptionParser

def main():
usage = "%prog [options] args"
parser = OptionParser(usage)
parser.add_option("-l", "--logfile", dest="logfile", help="Logfile to read 
data")
parser.add_option("-p", "--logpos", dest="logpos", help="File to store last 
log line read position")
parser.add_option("-f", "--find", dest="findstring", help="String to find 
in Logfile")
(options, args) = parser.parse_args()
if options.logfile is None or options.findstring is None or options.logpos 
is None:
print("Incorrect arguments numbers.\n")
parser.print_help()
sys.exit(-1)
else:
logfile = options.logfile
tofind = options.findstring
logpos = options.logpos

pos = 0
count = 0
if os.path.isfile(logpos):
pos = int(open(logpos).readline() or 0)
file = open(logfile)
file.seek(pos)
for line in file:
if line.find(tofind) != -1:
count += 1
pos = file.tell()
file.close()
file = open(logpos, 'w')
file.write(str(pos))
file.close()
print count

if __name__ == '__main__':

main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logwatch python

2013-02-09 Thread Roy Smith
In article <1de56e5b-4f9b-477d-a1d4-71e7222a2...@googlegroups.com>,
 Cleuson Alves  wrote:

> Hello, I am trying to run this code, but I get an answer incorrect arguments 
> numbers. someone could put an example of arguments for me to use in the / var 
> / log?

Since the first cave man tried to sort his rock collection into 
descending order of mastodon kills, people have been inventing really 
awesome debugging tools.  One of the earliest, and still near the top of 
most people's toolkits is the print statement.

You've got:

> if options.logfile is None or options.findstring is None or 
> options.logpos is None:
> print("Incorrect arguments numbers.\n")

Start by printing out the values of options.logfile, options.findstring, 
and options.logpos.  Then at least you will know which of those three is 
causing the problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread rusi
On Feb 9, 7:27 pm, Morten Engvoldsen  wrote:
> Hi Team,
> I Have saved my output in .doc file and want to format the output with
>
> *Start the File 
>
> Some data here
>
> ***End of File*
>
> Can you let me know how can i do that using Python?

If it were not for the doc file type, its a couple of lines of code to
do what you are asking.

With doc files however its a bit of a headache.
MSOffice doesn't script with python (as far as I know).
Best to use whatever it allows -- VBA I guess
Libreoffice allows a number of different scripting options including
python -- all poorly documented and obsolete.
eg http://www.openoffice.org/udk/python/scriptingframework/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread Dave Angel

On 02/09/2013 10:01 AM, Morten Engvoldsen wrote:

Hi Davea,
I am using Python 2.7.



Sorry, I should have noticed the python version in the subject line, but 
didn't until this reply.


How about  print >> outfile, "Start the File".center(55, "*")
after creating the file, and

print >> outfile, "Start the File".center(55, "*")
just before closing it ?

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


Re: Alternatives to Splunk?

2013-02-09 Thread sssdevelop
Yup - its off topic. I was triggered to write here because Splunk is written in 
Python. And Python is good at Parsing/Regex. 

Thank you for your response about logstash, kibana. I was looking for such 
tools only - thank you so much. 

---sss


On Saturday, February 9, 2013 7:05:57 PM UTC+5:30, Rodrick Brown wrote:
> On Sat, Feb 9, 2013 at 7:27 AM, sssdevelop  wrote:
> 
> 
> 
> Are there any opensource alternatives to Splunk?
> 
> Need tool to analyze the log files..
> 
> 
> 
> 
> 
> This is highly off topic, however I'm using logstash + kibana for my log 
> analysis. 
>  
> 
> 
> --
> 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Alternatives to Splunk?

2013-02-09 Thread Matty Sarro
Look up any nosql database. At it's heart that is what splunk is built on.
Or, if you're working with less than 500mb of data a day, just use the free
version of splunk.


On Sat, Feb 9, 2013 at 12:09 PM, sssdevelop  wrote:

> Yup - its off topic. I was triggered to write here because Splunk is
> written in Python. And Python is good at Parsing/Regex.
>
> Thank you for your response about logstash, kibana. I was looking for such
> tools only - thank you so much.
>
> ---sss
>
>
> On Saturday, February 9, 2013 7:05:57 PM UTC+5:30, Rodrick Brown wrote:
> > On Sat, Feb 9, 2013 at 7:27 AM, sssdevelop  wrote:
> >
> >
> >
> > Are there any opensource alternatives to Splunk?
> >
> > Need tool to analyze the log files..
> >
> >
> >
> >
> >
> > This is highly off topic, however I'm using logstash + kibana for my log
> analysis.
> >
> >
> >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread Mark Lawrence

On 09/02/2013 14:27, Morten Engvoldsen wrote:

Hi Team,
I Have saved my output in .doc file and want to format the output with
*Start the File 
Some data here
***End of File*
Can you let me know how can i do that using Python?




Assuming the .doc file is MS Word see here
http://sourceforge.net/projects/pywin32/ as a starter?  If you're 
talking plain text others have already replied.


--
Cheers.

Mark Lawrence

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


Re: Python3 curses behavior

2013-02-09 Thread Terry Reedy

On 2/9/2013 6:23 AM, Vlasov Vitaly wrote:

Hello.

I found strange behavior of curses module, that i can't understand. I
initialize screen with curses.initscr(), then i create subwin of
screen with screen.subwin(my_subwin_sizes). After that i fill subwin
with my_char in for-loop. On last char in last line subwin.addch()
raises exception.


I have never used curses but I have used text screens. I suspect that 
addch moves the cursor to the position beyond where the character is 
added, but there is no such position. I remember having problems writing 
to the last char of a 24x80 screen without getting either a scroll or 
beep if scrolling was disabled.



This is my problem. Why? How to fix it?


Perhaps this will help:
window.leaveok(yes)
If yes is 1, cursor is left where it is on update, instead of being at 
“cursor position.” This reduces cursor movement where possible. If 
possible the cursor will be made invisible.



(If i will ignore exception, then last char will be displayed)


Otherwise, just catch the exception, as you already discovered.


Here simple example: http://pastebin.com/SjyMsHZB


--
Terry Jan Reedy


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


Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread Terry Reedy

On 2/9/2013 11:21 AM, rusi wrote:

On Feb 9, 7:27 pm, Morten Engvoldsen  wrote:

Hi Team,
I Have saved my output in .doc file and want to format the output with

*Start the File 

Some data here

***End of File*

Can you let me know how can i do that using Python?


If it were not for the doc file type, its a couple of lines of code to
do what you are asking.

With doc files however its a bit of a headache.
MSOffice doesn't script with python (as far as I know).


It can be with the pythonwin extensions.


Best to use whatever it allows -- VBA I guess
Libreoffice allows a number of different scripting options including
python -- all poorly documented and obsolete.
eg http://www.openoffice.org/udk/python/scriptingframework/


LibreOffice 4.0.0, released 2 days ago, upgrades the bundled Python from 
2.6 (itself an upgrade) to 3.3!

https://www.libreoffice.org/download/4-0-new-features-and-fixes/

One new addition, also from the above
'''
"LibreLogo" vector graphics language: Logo toolbar and interpreter

Logoposter en.jpg   Turtlegraphics.png  Logochessboard.png

The lightweight implementation (1400 lines in Python-PyUNO) uses the 
embedded Python to give a simplified programming interface to the 
excellent vector graphics of LibreOffice for graphic design and 
education (including teaching of word processing). ...

'''
I am hoping the PyUNO doc will see improvement.


--
Terry Jan Reedy

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


Re: python3 binascii.hexlify ...

2013-02-09 Thread Cameron Simpson
On 09Feb2013 22:26, Chris Angelico  wrote:
| On Sat, Feb 9, 2013 at 10:10 PM, Peter Otten <__pete...@web.de> wrote:
| > """Return the hexadecimal representation of the binary data. Every byte of
| > data is converted into the corresponding 2-digit hex representation.
| > """
| >
| > makes it pretty clear that the function is operating on bytes, not str.

Well of course. I want a hexadecimal string representation of a chunk of
bytes. It should be producing a string.

| That doesn't necessarily mean it has to return bytes, though. It's
| taking binary data and producing something that's plausibly either
| bytes or str. It's human-readable and would definitely make sense to
| be str (for instance, hex() returns a str), so imo this should be made
| very clear in the docs. Maybe:
| 
| """Return the hexadecimal representation of the binary data. Every byte of
| data is converted into two bytes with the corresponding hex
| representation in ASCII.
| """
| 
| or somesuch?

Only if returning a string would break something relying on hexlify
returning bytes. The natural way to write this function is to have it
return a string.

_If_ there's some dependency in the stdlib, maybe a doc fix would do.
But otherwise IMO the function should be returning a string.

What is the use case for returning bytes that just _look_ like a string?
It is returning a textual representation; without a good reason, that
should be a string.
-- 
Cameron Simpson 

Because of its special customs, crossposting between alt.peeves and normal
newsgroups is discouraged.  - Cameron Spitzer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Alternatives to Splunk?

2013-02-09 Thread Steven D'Aprano
sssdevelop wrote:

> Are there any opensource alternatives to Splunk?
> Need tool to analyze the log files..


Is Google blocked where you are?

How about other search engines like DuckDuckGo, Bling, Yahoo, etc? Surely
*some* search engine must work.

If not, I suggest asking on a mailing list for system administration, not
programming languages.


-- 
Steven

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


Re: Coercing one object to type of another

2013-02-09 Thread Steven D'Aprano
Vijay Shanker wrote:

> Hi
> Inside a function i get a two arguments, say arg1 and arg2, how can i
> convert arg2 to same type as arg1 ? I dont know type of arg1 or arg2 for 
> that matter, I just want to convert arg2 to type of arg1 if possible and
> handle the exception if raised. 

How do you propose to handle the exception?

If arg1 is a dict, and arg2 is an int, what do you think should happen?

convert({}, 45)
=> returns what?


If arg1 is a HTTP connection object, and arg2 is a function object, what do
you think should happen?

import urllib2
conn = urllib2.urlopen("http://www.python.com/";)
convert(conn, lambda x: len(x) + 1)
=> returns what?


You cannot convert arbitrary objects of one type into some other arbitrary
type, it simply doesn't make sense. So first of all you need to decide:

- what kinds of objects do you care about?

- when given some other kind of object, how do you propose to deal with it?

The usual answer to the second question is "raise an exception".



> Also:
> >>> int('2')
> 2
> >>> float('2.0')
> 2.0
> >>> coerce(2,2.0)
> (2.0,2.0)
> but coerce('2',2) fails.If int('2') equals 2, why should it fail ?

Because '2' is a string, not a number, and coerce only operates on numbers.
What would you expect coerce("three", 2) to return? How about
coerce("apple", 2)?


Why do you think you need coerce? What are you actually trying to
accomplish? If you have two numbers, normally you would just do arithmetic
on them and let Python do any coercion needed. And if you have a number and
something else, you can't magically turn non-numbers into numbers.



-- 
Steven

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


Re: Is Python programming language?

2013-02-09 Thread Tim Roberts
Grant Edwards  wrote:
>
>IMO, a "scripting language" is used to automate tasks that would
>otherwise be done by a human sitting at a keyboard typing commands.
>[Perhaps that definition should be extended to include tasks that
>would otherwise by done by a human sitting and clicking on a GUI.]

I think that definition is a little too neat and clean.  

Most people would call bash a "scripting language", but it is also clearly
a programming language.  It has syntax, variables and expressions.  I
suspect it is Turing-complete, although I haven't seen a proof of that.

I would assert that scripting languages are a proper subset of programming
languages, not a separate category.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python programming language?

2013-02-09 Thread Michael Torrie
On 02/09/2013 04:26 PM, Tim Roberts wrote:
> Most people would call bash a "scripting language", but it is also clearly
> a programming language.  It has syntax, variables and expressions.  I
> suspect it is Turing-complete, although I haven't seen a proof of that.
> 
> I would assert that scripting languages are a proper subset of programming
> languages, not a separate category.

I'm pretty sure Bash is turing complete.  I know it's been shown that
sed is turing complete, and awk probably is too!  If I recall, the way
to show a language is turing complete is to implement a turing machine
in it.  I'm pretty sure bash could handle that, though maybe with help
from a standard set of unix tools one always finds used in conjunction
with the shell.  Here's one implementation:

https://github.com/thulsadum/bash-turing-machine/blob/master/turing.sh

I would say that "scripting language" isn't a definition of a type of
language, but rather a description of how a language is put to use in a
particular case.  For example, when embedded in a game, lua is used as a
scripting language to automate and extend the game in certain ways, by
exposing game objects to the lua engine and allowing interpreted lua
code to manipulate (script) them.  Javascript is the same thing in other
programs.  But whether you call javascript a scripting language in
firefox, or something much more (as it's actualy required for firefox to
function at all), is a matter of personal preference really.

I've seen python embedded in apps to act as a scripting language before.
 I've also seen full-blown apps written in python.

So yes, the distinction, as made by the original poster, isn't really
necessary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python programming language?

2013-02-09 Thread Terry Reedy

On 2/9/2013 6:53 PM, Michael Torrie wrote:

On 02/09/2013 04:26 PM, Tim Roberts wrote:

Most people would call bash a "scripting language", but it is also clearly
a programming language.  It has syntax, variables and expressions.  I
suspect it is Turing-complete, although I haven't seen a proof of that.

I would assert that scripting languages are a proper subset of programming
languages, not a separate category.


I'm pretty sure Bash is turing complete.  I know it's been shown that
sed is turing complete, and awk probably is too!  If I recall, the way
to show a language is turing complete is to implement a turing machine


If the language has arrays, conditional execution, and explicit (while) 
loops or recursion, you can be pretty sure it is Turing complete. I 
presume this covers awk and bash. Something like the game of Life, where 
the looping in implicit in the operation, is much harder to show Turing 
complete. I suspect sed is non-trivial also.


--
Terry Jan Reedy

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


Re: Is Python programming language?

2013-02-09 Thread Terry Reedy

On 2/9/2013 6:26 PM, Tim Roberts wrote:

Grant Edwards  wrote:


IMO, a "scripting language" is used to automate tasks that would
otherwise be done by a human sitting at a keyboard typing commands.
[Perhaps that definition should be extended to include tasks that
would otherwise by done by a human sitting and clicking on a GUI.]


I think that definition is a little too neat and clean.

Most people would call bash a "scripting language", but it is also clearly
a programming language.  It has syntax, variables and expressions.  I
suspect it is Turing-complete, although I haven't seen a proof of that.

I would assert that scripting languages are a proper subset of programming
languages, not a separate category.


To me, 'scripting languages' include some non-Turing-complete languages 
and I would not call those 'programming languages'.



--
Terry Jan Reedy

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


Re: Is Python programming language?

2013-02-09 Thread Michael Torrie
On 02/09/2013 07:40 PM, Terry Reedy wrote:
> If the language has arrays, conditional execution, and explicit (while) 
> loops or recursion, you can be pretty sure it is Turing complete. I 
> presume this covers awk and bash. Something like the game of Life, where 
> the looping in implicit in the operation, is much harder to show Turing 
> complete. I suspect sed is non-trivial also.

All you have to do to show a language is turing complete is to implement
a turing machine in it.  Here's one in sed that I found:
http://www.catonmat.net/blog/proof-that-sed-is-turing-complete/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spawn a process, then exit, whilst leaving process running?

2013-02-09 Thread Nobody
On Fri, 08 Feb 2013 21:04:33 -0800, Victor Hooi wrote:

> I have a Python script that I'd like to spawn a separate process (SSH
> client, in this case), and then have the script exit whilst the process
> continues to run.
> 
> I looked at Subprocess, however, that leaves the script running, and it's
> more for spawning processes and then dealing with their output.
> 
> Somebody mentioned multiprocessing, however, I'm not sure quite sure how
> that would work here.
> 
> What's the most Pythontic way of achieving this purpose?

On Unix, the os.exec* functions might be appropriate, depending upon
whether the script needs to do anything afterwards. Otherwise, use
subprocess.Popen().

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


Re: LangWart: Method congestion from mutate multiplicty

2013-02-09 Thread Rick Johnson
On Friday, February 8, 2013 9:36:52 PM UTC-6, Steven D'Aprano wrote:
> Rick Johnson wrote:
> 
> > The solution is simple. Do not offer the "copy-mutate" methods and force
> > all mutation to happen in-place:
> > 
> > py> l = [1,2,3]
> > py> l.reverse
> > py> l
> > [3,2,1]
> > 
> > If the user wants a "mutated copy" he should explicitly create a new
> > object and then apply the correct mutator method:
> > 
> > py> a1 = [1,2,3]
> > py> a2 = list(a1).reverse()
> 
> Oh wow, Rick has re-discovered programming in Python during the mid to late
> 1990s!
> 
> [...snip: long-winded, rambling, and sarcastic response simply to convey 
> that Python lists have had a "reversed" method for some time...]

Steven, i am quite aware of the Python list method "reversed" --which returns a 
copy of the current list object in reversed order--, my point is that these 
types of "copy-mutate" methods superfluously pollute the object namespace. Do 
you really want "method pairs" like these:

 sort, sorted
 reverse, reversed

Hell, why stop there:

 append, appended
 flatten, flattened
 insert, inserted
 map, mapped
 filter, filtered
 reduce, reduced
 extend, extended
 freeze, frozen
 set, sat|setted
 unique, uniqued

Is this really what you prefer? Where does the madness end Steven? At what 
point do you say enough is enough? And what happens if you fail to catch the 
infection early enough? Steven, this is a /real/ problem which has the 
potential to go viral!

My point was this: All mutate methods should mutate "in-place", if the 
programmer wishes to create a mutated copy of the object, then the programmer 
should /explicitly/ create a copy of the object and then apply the correct 
mutator method to the copy. 

 NO: reversed = lst.reversed() # Python
YES: reversed = list(lst).reverse() # Python

 NO: reversed = a.reverse() # Ruby
YES: reversed = Array.new(a).reverse!() # Ruby

This is about consistency and keeping the number of methods from spiraling out 
of control because we feel the need to automate /every/ task for the 
programmer, when in actuality, we are doing more harm than good.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LangWart: Method congestion from mutate multiplicty

2013-02-09 Thread Chris Angelico
On Sun, Feb 10, 2013 at 2:54 PM, Rick Johnson
 wrote:
> My point was this: All mutate methods should mutate "in-place", if the 
> programmer wishes to create a mutated copy of the object, then the programmer 
> should /explicitly/ create a copy of the object and then apply the correct 
> mutator method to the copy.

I agree. And we can go further and declare that there is only one data
type, the simple integer; you have an infinite number of them, and all
you can do is mutate them in place. You don't need variable names
either; just have one single array that represents your whole
namespace, and work with positions in that array. And don't bother
with actual positions, even - with a single pointer, you could manage
everything.

Forget this silly mess of data types, methods, global functions, and
so on. Let's simplify things massively!

Ook. Ook!

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


Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Rick Johnson
On Friday, February 8, 2013 11:01:00 PM UTC-6, Chris Angelico wrote:
> [...]
> Another advantage of using two characters: There's no conflict between
> set and dict literals. How do you notate an empty set in Python? {}
> means an empty dict.

What makes you believe that a language must provide literal syntax for EACH and 
EVERY type? And BTW, if you don't already know, this is how you notate an empty 
set in Python:

py> set([])
set([])

IMO "Set Types" should only exists as a concequence of "freezing" an array, and 
should have NO literal syntax avaiable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Chris Angelico
On Sun, Feb 10, 2013 at 3:26 PM, Rick Johnson
 wrote:
> On Friday, February 8, 2013 11:01:00 PM UTC-6, Chris Angelico wrote:
>> [...]
>> Another advantage of using two characters: There's no conflict between
>> set and dict literals. How do you notate an empty set in Python? {}
>> means an empty dict.
>
> What makes you believe that a language must provide literal syntax for EACH 
> and EVERY type? And BTW, if you don't already know, this is how you notate an 
> empty set in Python:
>
> py> set([])
> set([])

Or omit the argument, to avoid working with a pointless empty list.
But what happens if you first execute:

set = tuple

? This is not a set literal, it's an expression that usually returns a set.

> IMO "Set Types" should only exists as a concequence of "freezing" an array, 
> and should have NO literal syntax avaiable.

I don't understand. Wouldn't freezing an array (list) result in a
tuple? And, why should there be no literal syntax for them?

Having a convenient literal notation for every basic type is extremely
handy. You can work with integers 1, 2, 3, or floats 1.0, 2.0, 3.0. C
gives you those. In Python, you can work with lists, too, and C
doesn't give you those (you have array *initializer* syntax, but
that's not the same thing). It's perfectly plausible to dereference a
literal:

dow = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][day%7]

Of course, it's perfectly plausible to do that with a function, too.
You could define something like this:

def agg(*args): return args
dow = agg("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")[day%7]

But the question is, why? Why call a function when the interpreter can
do the work directly at compile stage? There's absolutely no value in
forcing things to be done at run-time.

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


Re: LangWart: Method congestion from mutate multiplicty

2013-02-09 Thread Mark Janssen
On Sat, Feb 9, 2013 at 8:20 PM, Chris Angelico  wrote:
> On Sun, Feb 10, 2013 at 2:54 PM, Rick Johnson
>  wrote:
>> My point was this: All mutate methods should mutate "in-place", if the 
>> programmer wishes to create a mutated copy of the object, then the 
>> programmer should /explicitly/ create a copy of the object and then apply 
>> the correct mutator method to the copy.
>
> I agree. And we can go further and declare that there is only one data
> [sarcasm]

I have to agree with Rick, I think requiring the user to explicitly
create a new object, which is already a good and widely-used practice,
should be the Only One Way to Do It.  Guessing method names is far
suboptimal to this simple, easy idiom.  As for the point Chris was
making as to making all types one, I actually agree there too, it's
just that in order to do that, python would need a unified object
model and it doesn't have one yet.

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


Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Rick Johnson
On Friday, February 8, 2013 7:17:26 PM UTC-6, Chris Angelico wrote:
> On Sat, Feb 9, 2013 at 11:49 AM, Rick Johnson
> >  nested_list = array(array(string))
> 
> Actually, that's not a declaration, that's an assignment; and in Pike,
> a 'type' is a thing, same as it is in Python (though not quite). If I
> were to declare it in Pike, it would be:
> 
> array(array(string)) nested_list;
> 
> Though the part inside the parens can be omitted, in which case the
> array can contain anything, rather than being restricted to strings.
> In actual fact, Rick, despite your complaints about the syntax, it's
> able to achieve exactly what you were thinking Python should do:
> declare an array/list that contains only numbers.

Well Chris i have wonderful news for you! Python /does/ have "homogenous 
arrays", and they're called, wait for it. arrays! Imagine that!

py> import array
py> intSeq = array.array('i')
py> intSeq.append(1)
py> intSeq.append(2)
py> intSeq.append(5000)
py> intSeq.append(5000.333)
TypeError: integer argument expected, got float
py> intSeq.append('5000.333')
TypeError: an integer is required
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Chris Angelico
On Sun, Feb 10, 2013 at 3:54 PM, Rick Johnson
 wrote:
> Well Chris i have wonderful news for you! Python /does/ have "homogenous 
> arrays", and they're called, wait for it. arrays! Imagine that!

That's not a built-in. But you were the one who complained about the
way sum() could be applied to a list that contains a non-integer;
maybe your solution is simply to ignore sum() and work with
array.array?

Nice how you can complain about Python for not having something, then
heap scorn on me for not being aware that it's there in the stdlib.
(Which, by the way, I freely admit to being less than fully familiar
with. Even less familiar with what's on PyPI.)

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


Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Rick Johnson
On Friday, February 8, 2013 7:06:34 PM UTC-6, Ian wrote:
> On Fri, Feb 8, 2013 at 12:58 PM, Rick Johnson
>  wrote:
> > I'm a bit unnerved by the sum function. Summing a
> > sequence only makes sense if the sequence in question
> > contains /only/ numeric types. For that reason i decided
> > to create a special type for holding Numerics.
> > [...]
> > Of course someone could
> > probably find a legitimate reason to apply a sum method
> > to non-numeric values; if so, then inherit from
> > NumericSequence and create your custom type!
>
> Are you aware that the approach you're advocating here is bad OOP
> design?  If you declare a class NumericSequence with the property that
> it contains only numeric types, and then you declare a subclass
> NonnumericSequence that does not share that property, then guess what?
> You've just violated the Liskov Substitution Principle.

I totally agree! Really, no sarcasm here O:-)

Not only because we would be attempting to bend a numeric type into something 
it is not, but even more foolishly because the very method we hope to gain 
(sum) would need to be completely re-written anyway. I must have lost myself in 
the rant because that was a foolish thing to say. Thanks for pointing this out.

> The goal you're trying to achieve here is nonsensical anyway.  Ask
> yourself what the semantic meaning of the sum() function is, what
> purpose it is meant to serve.  My answer: it is the reduction of the
> addition operator.

I think that for Numeric Types your answer is spot on! And i'll bet if we 
ruminated long enough we could probably find a few more transformations of the 
word "sum" into unique contexts. But i digress, we'll have to save that synergy 
for a time when you are buying the beer! ;-)

> The implication of this is that the input type of
> the sum() function is not "numbers", but rather "things that can be
> added".

Indeed. Contrary to what a few folks have stated in this thread, if two 
different objects have methods named "sum", that does NOT mean that we have 
broken the fine principles of "code reuse", no. Why? Because two methods named 
"sum" can contain completely different code! Yes, i know that's difficult for 
some to believe, but it's the truth!

Consider a sum method of a "Numeric Type" compared to the sum method of a 
"Sequence Type". Not only is the algorithm different, but the result is 
different. Summing N numerics requires utilizing the strict rules of 
mathematical addition, keeping a running total, and returning a type (Integer) 
that is different from the input type, whereas summing sequences requires 
expanding the first sequence with the values of the second sequence (all whilst 
maintaining linear order) and returning a new instance of the same type (f.e. 
list). 

Of course you could write a single monolithic function that can operate on 
multiple types transparently (*cough* saum!) however:

 * Nobody can predict the future (at least not yet) so you
   will eventually encounter a new type that breaks the
   god @#$% function.

 * Your language will rely on "magic", thereby confusing
   it's users, with well, magic!

 * But most disappointing of all: you will break the accepted
   OOP convention of encapsulation, whereby the object
   /itself/ should operate on the data, not some outside god
   @#$% function!

But let's dig a little deeper here so we might understand /why/ encapsulation 
is /so/ gawd @#$%ed important to OOP. 

Why do we prefer objects to operate on their own data rather than some 
"magical-all-knowing-god-like-creature-from-another-planet-who-thinks-his-bowel-movements-smell-like-bakery-fresh-cinnamon-rolls?
 Is it because we want objects to feel a sense of "belonging" or "importance"? 
...OF COURSE NOT! Objects neither think nor feel!

We employ encapsulation because by doing so we keep all the relevant code under 
one class, one module, one package. By doing so we create a hierarchy; and 
since hierarchies are much easier to search than random sequences, we will 
thank ourselves later!

If you want a fine example of this consider a list and a dict object. If you 
want to find a value in a list you are forced to search the entire list 
"item-by-item" until you find a match; there are NO shortcuts here! However, 
when we have data in a dict all we need is a key, and voila!, we have a direct 
path to the item! Same applies to code.

RR: "GOOD paradigms solve problems when /writing/ code, GREAT paradigms solve 
problems when writing and /maintaining/ code!"

> That includes numbers, but since I see from your proposed
> class hierarchy that you are retaining the __add__ method on
> sequences, it also includes sequences.  Are you really going to tell
> the user that (1, 2, 3) + (4, 5, 6) is perfectly fine, but that the
> semantic equivalent sum([(1, 2, 3), (4, 5, 6)]) is nonsense?

Yes. Because if the user has a problem understanding /why/ adding two sequences 
together results in a new sequence and /not/ a number, he can simply o

Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7

2013-02-09 Thread Morten Engvoldsen
Hi Dave,
This sounds great, thanks for your help :)

On Sat, Feb 9, 2013 at 6:13 PM, Dave Angel  wrote:

> On 02/09/2013 10:01 AM, Morten Engvoldsen wrote:
>
>> Hi Davea,
>> I am using Python 2.7.
>>
>>
> Sorry, I should have noticed the python version in the subject line, but
> didn't until this reply.
>
> How about  print >> outfile, "Start the File".center(55, "*")
> after creating the file, and
>
> print >> outfile, "Start the File".center(55, "*")
> just before closing it ?
>
> --
> DaveA
>
-- 
http://mail.python.org/mailman/listinfo/python-list