Re: [Tutor] how to reference a function itself when accessing its private functions?

2009-05-05 Thread spir
Le Mon, 04 May 2009 16:08:38 -0700, Emile van Sebille s'exprima ainsi: > On 5/4/2009 3:37 PM Tim Michelsen said... > > Dear Tutors and fellow pythonistas, > > I would like to get access to the private methods of my function. > > > > For instance: > > Who can I reference the docstring of a functi

Re: [Tutor] Conversion question

2009-05-05 Thread spir
Le Tue, 5 May 2009 00:52:11 +0100, "Alan Gauld" s'exprima ainsi: > > Is there a way in Python to say this is a string of HEX characters like > > Perl's pack? Right now I have to take the string and add a \x to every > > two > > values i.e. \x41\x42... > > Assuming you actually want to send t

Re: [Tutor] Conversion question

2009-05-05 Thread Alan Gauld
"Emile van Sebille" wrote "414243440d0a" Is there a way in Python to say this is a string of HEX characters like Perl's pack? Right now I have to take the string and add a \x to every two values i.e. \x41\x42... import binascii binascii.a2b_hex('41424344') I hadn't come across binascii

Re: [Tutor] Replacing fields in lines of various lengths

2009-05-05 Thread Alan Gauld
"Dan Liang" wrote And I put together the code below based on your suggestions, with minor changes and it does work. Good, now your question is? -Begin code #!usr/bin/python tags = { 'noun-prop': 'noun_prop null null'.split(), 'case_def_gen': 'case_d

Re: [Tutor] Tutor Digest, Vol 63, Issue 8

2009-05-05 Thread Alan Gauld
Please use a sensible subject and don;t reporst the whole digest. "Dan Liang" wrote in message Thank you for your help. I have been working on the file, but I still have a problem doing what I wanted. As a reminder, Can you tell us what exactly the problem is? It's easier than us trying to

Re: [Tutor] Replacing fields in lines of various lengths

2009-05-05 Thread Alan Gauld
My turn to apologise for premature sending of email... For some reason I didn't notice the section of mail after the code snippet! Alan G "Dan Liang" wrote in message Now since I have to work on different data format as follows: -Begin data w1\t

Re: [Tutor] Replacing fields in lines of various lengths

2009-05-05 Thread spir
Le Tue, 5 May 2009 00:22:45 -0400, Dan Liang s'exprima ainsi: > -Begin data > > w1\t case_def_acc \t yes > w2‬\t noun_prop \t no > ‭w3‬\t case_def_gen \t > w4\t dem_pron_f \t no > w3‬\t

Re: [Tutor] Conversion question

2009-05-05 Thread Tom Green
Thanks everyone for your replies. This reason for the long string is sometimes I have to pass a 32 byte key (MD5 hash value) to the socket. The data I am sending is the hex values i.e. 41=A. I believe the binascii will work. Mike On Mon, May 4, 2009 at 7:52 PM, Alan Gauld wrote: > > "Tom Gree

Re: [Tutor] Encode problem

2009-05-05 Thread Kent Johnson
On Tue, May 5, 2009 at 1:14 AM, Mark Tolonen wrote: > The below works.  ConfigParser isn't written to support Unicode correctly. I > was able to get Unicode sections to write out, but it was just luck. Unicode > keys and values break as the OP discovered.  So treat everything as byte > strings:

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread spir
Le Tue, 5 May 2009 00:41:39 +0100, "Alan Gauld" s'exprima ainsi: > > Backwards compatibility. The file type was introduced in python 2.2, > > before which there was open. > > And file has been removed again in Python v3 > In fact open is now an alias for io.open and no longer simply retu

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread W W
On Tue, May 5, 2009 at 5:41 AM, spir wrote: > Le Tue, 5 May 2009 00:41:39 +0100, > "Alan Gauld" s'exprima ainsi: > > > > Backwards compatibility. The file type was introduced in python 2.2, > > > before which there was open. > > > > And file has been removed again in Python v3 > > In fact o

Re: [Tutor] Advanced String Search using operators AND, OR etc..

2009-05-05 Thread Lie Ryan
Alex Feddor wrote: Hi I am looking for method enables advanced text string search. Method string.find() or re module seems no supporting what I am looking for. The idea is as follows: Text ="FDA meeting was successful. New drug is approved for whole sale distribution!" I would like to sc

Re: [Tutor] Advanced String Search using operators AND, OR etc..

2009-05-05 Thread Kent Johnson
On Tue, May 5, 2009 at 8:11 AM, Lie Ryan wrote: > Bring on your hardest searches... Nice! > The Suite class is only there to turn the NotFound sentinel from len(text) > to -1 (used len(text) since it simplifies the code a lot...) How does this simplify the code? Why not use the 'in' operator a

Re: [Tutor] Advanced String Search using operators AND, OR etc..

2009-05-05 Thread spir
Le Tue, 05 May 2009 22:11:22 +1000, Lie Ryan s'exprima ainsi: > Idea: > Overrides the operator on Pattern class so we could write it like: > P("Hello") & P("World") instead of AND(P("Hello"), P("World")) You could also override directly all python logical ops to allow direct expression of logi

Re: [Tutor] Advanced String Search using operators AND, OR etc..

2009-05-05 Thread Lie Ryan
Kent Johnson wrote: On Tue, May 5, 2009 at 8:11 AM, Lie Ryan wrote: Bring on your hardest searches... Nice! The Suite class is only there to turn the NotFound sentinel from len(text) to -1 (used len(text) since it simplifies the code a lot...) How does this simplify the code? Why not use

Re: [Tutor] Encode problem

2009-05-05 Thread Mark Tolonen
"Kent Johnson" wrote in message news:1c2a2c590905050337j1afc177ene64f800dcc3a7...@mail.gmail.com... On Tue, May 5, 2009 at 1:14 AM, Mark Tolonen wrote: > The below works. ConfigParser isn't written to support Unicode > correctly. I > was able to get Unicode sections to write out, but it wa

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread Mark Tolonen
"W W" wrote in message news:333efb450905050408m48246dd8wc90b94880898e...@mail.gmail.com... On Tue, May 5, 2009 at 5:41 AM, spir wrote: Le Tue, 5 May 2009 00:41:39 +0100, "Alan Gauld" s'exprima ainsi: > > Backwards compatibility. The file type was introduced in python 2.2, > > before whic

[Tutor] Using read() before closing a file

2009-05-05 Thread Eduardo Vieira
Hello, I found interesting today, as I was playing with this code in the shell: >>> arq = open('c:/myscripts/simple2.ttt', 'w') >>> len(a) 9 >>> arq.write('The length is %d' % len(a)) >>> res = arq.read() >>> print res The print doesn't print the text I had written, but some thing else I c

Re: [Tutor] Using read() before closing a file

2009-05-05 Thread Alan Gauld
"Eduardo Vieira" wrote arq = open('c:/myscripts/simple2.ttt', 'w') arq.write('The length is %d' % len(a)) res = arq.read() print res The print doesn't print the text I had written, That's because of two things: a) You opened the file for write only not reading b) You had moved the file curs

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread wesley chun
> It seems that open(filename, 'r') and file(filename, 'r') are > used interchangeably, and I wonder what this is all about. as alan and others have pointed out, file() was added in 2.2. this was part of the unification of types and classes. every object now has a factory function, i.e., list() c

Re: [Tutor] how to reference a function itself when accessing its private functions?

2009-05-05 Thread Tim Michelsen
Thanks a lot! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread Larry Riedel
It may not be a good reason, but I like that "open" is preferred, because in Java a "File" object is not a stream for the content in the file, just its directory entry, and simply creating a File object does not open the file at all. Larry ___ Tutor mai

Re: [Tutor] returning the entire line when regex matches

2009-05-05 Thread Nick Burgess
for root, dirs, files in os.walk('./'): for f in files: if f.endswith('.txt'): allfiles.append(os.path.join(root, f)) This returns a list of the *.txt files. Of course now I am stuck on how to apply the delimiter and search function to the items in the list..? Any clues/ex

Re: [Tutor] returning the entire line when regex matches

2009-05-05 Thread Nick Burgess
forgot to add this at the top, allfiles = [] On Tue, May 5, 2009 at 6:15 PM, Nick Burgess wrote: > for root, dirs, files in os.walk('./'): >    for f in files: >        if f.endswith('.txt'): >            allfiles.append(os.path.join(root, f)) > > This returns a list of the *.txt files. Of cours

Re: [Tutor] returning the entire line when regex matches

2009-05-05 Thread Alan Gauld
"Nick Burgess" wrote for root, dirs, files in os.walk('./'): for f in files: if f.endswith('.txt'): allfiles.append(os.path.join(root, f)) myFunction( os.path.join(root,f) ) This returns a list of the *.txt files. Of course now I am stuck on how to appl

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread Alan Gauld
"wesley chun" wrote does anyone have the idiom for the above isinstance() check for 3.x? Test for io.stream (or a derivative) - which is what open now returns. files are no more... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.pyth

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread Alan Gauld
"Larry Riedel" wrote It may not be a good reason, but I like that "open" is preferred, because in Java a "File" object is not a stream for the content in the file, just its directory entry, and simply creating a File object does not open the file at all. I'm not sure citing anything Java does

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread Larry Riedel
> I'm not sure citing anything Java does is a good rationale in Python! I find the languages/platforms complementary, so I appreciate when they are not arbitrarily inconsistent with each other. Larry ___ Tutor maillist - Tutor@python.org http://mail.

[Tutor] Reset while loop

2009-05-05 Thread David
Hi, not even sure if I can ask this very smartly but we shall try: I was playing around with trying to create a python program like tail -f as discussed on the list. i came up with this; def tail_it(bufsize=8192, linesep=__import__('os').linesep): f = None if f == None: f = open