Will python never intend to support private, protected and public?

2005-09-28 Thread could ildg
Python is wonderful except that it has no real private and protected properties and methods.Every py object has dict so that you can easily find what fields and methods an obj has,this is very convenient, but because of this, py is very hard to support real private and 
protected?If private and protected is supported, python will be perfect.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Will python never intend to support private, protected and public?

2005-09-29 Thread could ildg
**Encapsulation** is one of the 3 basic characteristics of OOP.When I firstly turned to python, it was my first script language.That time I found that python has not real private properties,I felt weird. If an oop language can't encapsulate something I want,
is it really an oop language? I asked myself. And after thinking forsome days, I answered myself that python is just a script language,it has no private stuff just want to keep python easy. An easy language
is hard to do difficult works, surely. But when I came to know *Ruby* some days ago, I found that not allscript languages have no private functionalities. Ruby has everythingthat encapsulation should has. In ruby there is a very popular web
framework named Ruby On Rails. Many programmers are studyat rails these days, And some people think that rails is even betterthan J2EE. So I asked myself, why is rails written in Ruby but notPython since python is such a good language? Why did the author
choose ruby other than python?On the comparison between py and ruby, the encapsulation of Ruby**beats** Python.Why does oop languages need encapsulation?Because it make programming easier.
Now I give some examples where real private is very very needed.The counter of a list-like object is very comman in our programms.This kind of variables can only be modified by the functions of theclass itself. We can't let others has the opportunity to modify it.
If it's modified outside the class directly, the programm will becomevery diffict to maintain and understand. At this time, python is not betterthan C.Sometimes I don't want a variable to be changed directly,
It can only be changed through a method. Because I want to do some extra works when it's changed. e.g:___class a:    i=0    def setI(iii):    if self.i!=iii:
    self.i=iii    #do some extra works here, e.g, notify the observers that    #this property is changed, or do some logging things.___In the class "a" above, when "i" is changed, I will do some extra works,
the extra works could be very import, so I want to keep i invisibleto some others, they can only change i by the method setI. But pythoncan't ensure i to be invisible, everyone can change it whenever theywant! This is dangerous.
Some guys will say that they will pay very much attention when theychange the variable i. But, I just want to say that this is only the easiestsituation because there is only **one** class and only **one** variable 
which should be visited cautiously. But what will you do when there arehundreds of classes and each class has dozens of such variables? I thinkeverybody can imagine how difficult it will be when he faces this
situation.Every programmer is  just a human being, but not God. Our life is limited,our time is limited, so we need to use convenient tools to save time.Private variables guarantee that we will never make stupid mistakes
to change them incautiously and it will tell us that "YOU ARE WRONG" whenyou try to change or visit them. They save energy for us, they save timefor us, they make us to be God!I don't want to give any more examples where private variables should be
used. If you think it's not needed, that's not import for me. I just want to saythat encapsulation is  very very needed, just as one's cock, it's his, and it'sonly his. He can't unconditionally let anyboy else tough it. Because it's
dangerous. So he should hide it, but not to expose it and tell everybody elseverytime "Don't tough my cock, it's my private stuff!".I use python for more than a year and I can't leave it because I am familiar
with my everyday necessary libs. And it's so convenient to interact withpython from Delphi or C or C++. I like pyton, so I like python to be perfect,I wish everyone of us could have a perfect python, so it is with you, isn't it?

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

Re: New Python chess module

2005-09-29 Thread could ildg
Very good~On 9/29/05, Will McGugan <[EMAIL PROTECTED]> wrote:
Hi folks,I've written a Python chess module that does the following.* Reads / Writes PGN files* Write FEN files* Validates moves* Lists legal moves* Detects check / mate / stalemate / 50 move rule / threefold repetition
Its still rough around the edges and not fully tested. I'll eventualyrelease a more polished version and possibly put it on Sourceforge. Inthe meantime I would be grateful for any feedback..
http://www.willmcgugan.com/chess.zipI am aware of the chess module by Erik Max Francis. It may have beenmore sensible to work on his version, but I did this mainly for the funof it. I wrote a chess game in C++ a while back
(http://www.chesscommander.com) and I thought it would be interesting tore-implement the chess library part in Python.Regards,Will McGugan--
http://www.willmcgugan.com--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Will python never intend to support private, protected and public?

2005-09-29 Thread could ildg
Thank you skip.Encapsulation or information hiding or whatever, that's what I'm looking forward to.On 9/30/05, [EMAIL PROTECTED]
 <[EMAIL PROTECTED]> wrote:>> **Encapsulation** is one of the 3 basic characteristics of OOP.
This isn't an encapsulation issue.  From the first hit on Google for theword:In programming, the process of combining elements to create a newentity.  For example, a procedure is a type of encapsulation because it
combines a series of computer instructions.  Likewise, a complex datatype, such as a record or class, relies on encapsulation.  Object-oriented programming languages rely heavily on encapsulation to create
high-level objects.  Encapsulation is closely related to abstraction andinformation hiding.Python does encapsulation just fine.  Your beef is with its informationhiding.Skip

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

Re: py2exe 0.6.3 released

2005-10-07 Thread could ildg
Nice job~Thank you.On 10/7/05, Jimmy Retzlaff <[EMAIL PROTECTED]> wrote:
py2exe 0.6.3 released=py2exe is a Python distutils extension which converts Python scriptsinto executable Windows programs, able to run without requiring aPython installation. Console and Windows (GUI) applications, Windows
NT services, exe and dll COM servers are supported.Changes in 0.6.3:* First release assembled by py2exe's new maintainer, Jimmy  Retzlaff. Code changes in this release are from Thomas Heller
  and Gordon Scott.* The dll-excludes option is now available on the command line.  It was only possible to specify that in the options argument to  the setup function before.  The dll-excludes option can now be used to filter out dlls like
  msvcr71.dll or even w9xpopen.exe.* Fix from Gordon Scott: py2exe crashed copying extension modules  in packages.Changes in 0.6.2:* Several important bugfixes:  - bundled extensions in packages did not work correctly, this
made the wxPython single-file sample fail with newer wxPythonversions.  - occasionally dlls/pyds were loaded twice, with very strangeeffects.  - the source distribution was not complete.
  - it is now possible to build a debug version of py2exe.Changes in 0.6.1:* py2exe can now bundle binary extensions and dlls into the  library-archive or the executable itself.  This allows to
  finally build real single-file executables.  The bundled dlls and pyds are loaded at runtime by some special  code that emulates the Windows LoadLibrary function - they are  never unpacked to the file system.
  This part of the code is distributed under the MPL 1.1, so this  license is now pulled in by py2exe.* By default py2exe now includes the codecs module and the  encodings package.
* Several other fixes.Homepage:Download from the usual location:<
http://sourceforge.net/project/showfiles.php?group_id=15583>Enjoy,Jimmy--http://mail.python.org/mailman/listinfo/python-list

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

hello, I want to change n bytes of a binary file

2005-11-01 Thread could ildg
I want to encrypt a very large birany file,but if to change the whole file, it will take very long time,so I just want to change n(n is an int) bytes of the file.but when I turned to the file I/O of python, I found that file object can only read and write strings,
so how can I do the binary stuff?I want a encrypt function like below:def encrypt(filename,n):    f=open(filename,"rb")    a=f.read(n)    //encrypt the n byte bit by bit and then write back to the beginning of the file
    //assume I only want every bit change from 0->1 and 1->0, how to do it than?Thank you so much!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: hello, I want to change n bytes of a binary file

2005-11-01 Thread could ildg
On 11/1/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
"could ildg" wrote:> I want to encrypt a very large birany file,> but if to change the whole file, it will take very long time,> so I just want to change n(n is an int) bytes of the file.
> but when I turned to the file I/O of python, I found that file object can> only read and write strings,> so how can I do the binary stuff?8-bit strings contain bytes.> I want a encrypt function like below:
> def encrypt(filename,n):f = open(filename,"rb+")> a=f.read(n)b = encrypt(a)          Thank you~~,but where is the encrypt defined?
f.seek(0) # rewindf.write(b)f.close()--http://mail.python.org/mailman/listinfo/python-list

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

Re: hello, I want to change n bytes of a binary file

2005-11-02 Thread could ildg
Thanks to Fredrik Lundh,It works~On 11/2/05, Fredrik Lundh <[EMAIL PROTECTED]
> wrote:"could ildg" wrote:> > so how can I do the binary stuff?
>> 8-bit strings contain bytes.>> > I want a encrypt function like below:> > def encrypt(filename,n):>> f = open(filename,"rb+")>> > a=f.read
(n)>> b = encrypt(a)Thank you~~,but where is the encrypt defined?oh, I though you asked how to update the first n bytes of abinary file.if you want to XOR the bytes, you can do something like:
import arrayb = array.array("B", a)for i in range(len(b)):b[i] = b[i] ^ 255b = b.tostring()orb = "".join([chr(ord(c) ^ 255) for c in a])
or some variation thereof.--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Which blog do you use?

2005-11-11 Thread could ildg
I want to to get a free blog sapce these days,
which has category for my posts.
What blog do you use?
I'll apprecaite your recommendation.
-- 
http://mail.python.org/mailman/listinfo/python-list

How to paste python code on wordpress?

2005-11-21 Thread could ildg
Wordpress.com blog will eat up the spaces before a line,
just as it will trim every line of my article. So I can't paste python code indentedly.
Does any one use wordpress blog here?
Please tell me how to leave the sapces as they are when publishing ariticles on the blog,
Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to paste python code on wordpress?

2005-11-21 Thread could ildg
Thank you~It works!but how can paste "<" and ">", please?these 2 symbols will also confuse wordpress and I can't publish what I want.On 11/22/05, 
Dan Lowe <[EMAIL PROTECTED]> wrote:
On Nov 21, 2005, at 8:17 PM, could ildg wrote:> Wordpress.com blog will eat up the spaces before a line,> just as it will trim every line of my article. So I can't paste
> python code indentedly.> Does any one use wordpress blog here?> Please tell me how to leave the sapces as they are when publishing> ariticles on the blog,You can enclose the code in a PRE block, like this:
def foobar(): print "abc" if x == 3: print "def" print "ghi"If you don't care for how it renders in a browser, hack your CSS to
make PRE render in a way you like.  -dan--Well sure the government lies, and the press lies, but in a democracythey aren't the same lies.-Alexis A. Gilliland

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

Re: How to paste python code on wordpress?

2005-11-21 Thread could ildg
Thank you very much Dan.I settle the problem according to you tips.On 11/22/05, Dan Lowe <[EMAIL PROTECTED]
> wrote:On Nov 22, 2005, at 12:30 AM, could ildg wrote:> Thank you~
> It works!> but how can paste "<" and ">", please?> these 2 symbols will also confuse wordpress and I can't publish> what I want.Replace < with <
Replace > with >(where those abbreviations stand for "less than" and "greater than")Before: if x < 5:After: if x < 5:Another common character in code that you "should" do similarly is
the double quote ("). For that, use "Before: if x == "foo":After: if x == "foo":  -dan--Any society that needs disclaimers has too many lawyers.  -Erik Pepke

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

How could I ask Thread B to call B().Method() from inside Thread A's run?

2005-11-30 Thread could ildg
I have 2 thead instances,
A and B,
In A's run method, if I call B.Method(), it will be executed in thead A,
but I want B.Method() to be executed in B's thread.
That's to say, I want to tell Thead B to do B's stuff in B's thread,
kinda like PostMessage in win32.
Can I do it in python?
How?
Thank you in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How could I ask Thread B to call B().Method() from inside Thread A's run?

2005-11-30 Thread could ildg
Thank you.On 30 Nov 2005 09:30:23 -0800, NavyJay <[EMAIL PROTECTED]> wrote:
I agree with jmj's solution, you would want to send a signal of somesort to Thread B from A when some event occurs in A.  A queue is oneway to do it, but keep in mind that there are numerous ways tocommunicate between threads/processes (queue, pipe, exit status,
TCP/UDP message, etc.).  I believe one of the first couple chapters inO'Reilly's "Programming Python" book discusses most of these methods.Choose the simplest one that meets your needs.--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Is Python string immutable?

2005-11-30 Thread could ildg
In java and C# String is immutable, str=str+"some more" will return a new string and leave some gargabe. 
so in java and C# if there are some frequent string operation, StringBuilder/StringBuffer is recommanded.
 
Will string operation in python also leave some garbage? I implemented a net-spider in python which includes many html string procession. After it running for sometime, the python exe eats up over 300M memory. Is this because the string garbages? 

 
If String in python is immutable, what class should I use to avoid too much garbages when processing strings frequently?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: delphi to python converter

2005-06-27 Thread could ildg
The only thing you can do at present is to convert by yourself
with hand, recode them line by line.

On 6/27/05, Thys Meintjes <[EMAIL PROTECTED]> wrote:
> Greets,
> 
> I have need of a Delphi/pascal to python converter. Googling didn't
> suggest any obvious leads so I'm trying here...
> 
> Thanks
> Thys
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How to compress a folder and all of its sub directories and files into a zip file?

2005-06-27 Thread could ildg
I want to compress a folder and all of its sub files including empty folders
into a zip file. what's the pythonic way to do this?

Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to compress a folder and all of its sub directories and files into a zip file?

2005-06-28 Thread could ildg
Thank you,
it works~~

On 6/29/05, Peter Szinek <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> What about this:
> 
> import os,zipfile
> from os.path import join
> 
> 
> zip = zipfile.ZipFile("myzipfile.zip", 'w')
> for root, dirs, files in os.walk('.'):
>  for fileName in files:
>  zip.write(join(root,fileName))
> zip.close()
> 
> Maybe it zips also the myzipfile.zip ;-)
> Probably this is not needed, so an additional test (something like
> fileName != 'myfile.zip' would be needed.
> 
> HTH,
> Peter
> 
> could ildg wrote:
> > I want to compress a folder and all of its sub files including empty folders
> > into a zip file. what's the pythonic way to do this?
> >
> > Thanks in advance.
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to compress a folder and all of its sub directories and files into a zip file?

2005-06-28 Thread could ildg
but the file is just stored,
and not compressed.

On 6/28/05, could ildg <[EMAIL PROTECTED]> wrote:
> Thank you,
> it works~~
> 
> On 6/29/05, Peter Szinek <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > What about this:
> >
> > import os,zipfile
> > from os.path import join
> >
> >
> > zip = zipfile.ZipFile("myzipfile.zip", 'w')
> > for root, dirs, files in os.walk('.'):
> >  for fileName in files:
> >  zip.write(join(root,fileName))
> > zip.close()
> >
> > Maybe it zips also the myzipfile.zip ;-)
> > Probably this is not needed, so an additional test (something like
> > fileName != 'myfile.zip' would be needed.
> >
> > HTH,
> > Peter
> >
> > could ildg wrote:
> > > I want to compress a folder and all of its sub files including empty 
> > > folders
> > > into a zip file. what's the pythonic way to do this?
> > >
> > > Thanks in advance.
> >
> >
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to compress a folder and all of its sub directories and files into a zip file?

2005-06-28 Thread could ildg
Thanks to Brian van den Broek ,
I've just reached the doc, too.
I'm now very clear.

On 6/28/05, Brian van den Broek <[EMAIL PROTECTED]> wrote:
> could ildg said unto the world upon 28/06/2005 03:29:
> > but the file is just stored,
> > and not compressed.
> >
> > On 6/28/05, could ildg <[EMAIL PROTECTED]> wrote:
> >
> >>Thank you,
> >>it works~~
> >>
> >>On 6/29/05, Peter Szinek <[EMAIL PROTECTED]> wrote:
> >>
> >>>Hi,
> >>>
> >>>What about this:
> >>>
> >>>import os,zipfile
> >>>from os.path import join
> >>>
> >>>
> >>>zip = zipfile.ZipFile("myzipfile.zip", 'w')
> >>>for root, dirs, files in os.walk('.'):
> >>> for fileName in files:
> >>> zip.write(join(root,fileName))
> >>>zip.close()
> >>>
> >>>Maybe it zips also the myzipfile.zip ;-)
> >>>Probably this is not needed, so an additional test (something like
> >>>fileName != 'myfile.zip' would be needed.
> >>>
> >>>HTH,
> >>>Peter
> >>>
> >>>could ildg wrote:
> >>>
> >>>>I want to compress a folder and all of its sub files including empty 
> >>>>folders
> >>>>into a zip file. what's the pythonic way to do this?
> >>>>
> >>>>Thanks in advance.
> >>>
> >>>
> 
> This thread got me to read the relevant docs:
> 
> 7.18.1 ZipFile Objects
> "class ZipFile( file[, mode[, compression]])
>  Open a ZIP file, where file can be either a path to a file (a
> string) or a file-like object. The mode parameter should be 'r' to
> read an existing file, 'w' to truncate and write a new file, or 'a' to
> append to an existing file. For mode is 'a' and file refers to an
> existing ZIP file, then additional files are added to it. If file does
> not refer to a ZIP file, then a new ZIP archive is appended to the
> file. This is meant for adding a ZIP archive to another file, such as
> python.exe. Using
> 
> cat myzip.zip >> python.exe
> 
>  also works, and at least WinZip can read such files. compression
> is the ZIP compression method to use when writing the archive, and
> should be ZIP_STORED or ZIP_DEFLATED; unrecognized values will cause
> RuntimeError to be raised. If ZIP_DEFLATED is specified but the zlib
> module is not available, RuntimeError is also raised. The default is
> ZIP_STORED."
> http://docs.python.org/lib/zipfile-objects.html
> 
> So, it would appear that compression requires a 3rd party module, not
> included in Python (and not present on my Windows box).
> 
> I'm presently filing a bug suggesting this be made a touch more
> explicit in the zlib docs.
> 
> Best to all,
> 
> Brian vdB
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How to compare two directories?

2005-06-28 Thread could ildg
I want to compare 2 directories,
and find If all of theire sub-folders and files and sub-files are identical.
If not the same, I want know which files or folders are not the same.
I know filecmp moudle has cmpfiles function and a class named dircmp,
they may help, but I wonder if there is a ready-to-use function in python libs?
If not, would somebody like to give me some propositions?

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


Re: How to compare two directories?

2005-06-30 Thread could ildg
I found dircmp compare only the direct dirs and files,
and it will not do anything to the sub-directories.

On 6/29/05, Michael Hoffman <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > I want to compare 2 directories,
> > and find If all of theire sub-folders and files and sub-files are identical.
> > If not the same, I want know which files or folders are not the same.
> > I know filecmp moudle has cmpfiles function and a class named dircmp,
> > they may help, but I wonder if there is a ready-to-use function in python 
> > libs?
> 
> That's a good start. Why doesn't dircmp work for you?
> --
> Michael Hoffman
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to compare two directories?

2005-06-30 Thread could ildg
Thank you~
I get it.

On 6/30/05, Michael Hoffman <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > I found dircmp compare only the direct dirs and files,
> > and it will not do anything to the sub-directories.
> 
> The documentation for dircmp.report_full_closure() disagrees with you.
> --
> Michael Hoffman
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


It seems that ZipFile().write() can only write files, how can empty directories be put into it?

2005-06-30 Thread could ildg
I want to "create" a empty folder in a zipfile,
Can ZipFile do it?
If not, any other approachs?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: It seems that ZipFile().write() can only write files, how can empty directories be put into it?

2005-07-02 Thread could ildg
Thank you.

On 7/1/05, Jeff Epler <[EMAIL PROTECTED]> wrote:
> This has been discussed before.  One thread I found was
> http://mail.python.org/pipermail/python-list/2003-June/170526.html
> The advice in that message might work for you.
> 
> Jeff
> 
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How can I import a py script by its absolute path name?

2005-07-14 Thread could ildg
I want to import c:\xxx\yyy\zzz.py into my programme,
What should I do?
Thank you~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread could ildg
for f in os.listdir(os.path.abspath(libdir)):
   module_name = f.strip('.py')
   __import__(module_name, globals(), locals(), [])

On 7/14/05, Jesse Noller <[EMAIL PROTECTED]> wrote:
> A question in a similiar vein:
> 
> I have appended 2 different directories to my path (via
> sys.path.append) now - without knowing the names of the files in those
> directories, I want to force an import of the libraries ala:
> 
> for f in os.listdir(os.path.abspath(libdir)):
> module_name = f.strip('.py')
> import module_name
> 
> Obviously, this throws:
> 
> ImportError: No module named module_name
> 
> Is there some way to do this?
> 
> thanks
> -jesse
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I import a py script by its absolute path name?

2005-07-14 Thread could ildg
You are quite right~

On 7/15/05, Peter Hansen <[EMAIL PROTECTED]> wrote:
> Jesse Noller wrote:
> > A question in a similiar vein:
> >
> > I have appended 2 different directories to my path (viaY
> > sys.path.append) now - without knowing the names of the files in those
> > directories, I want to force an import of the libraries ala:
> >
> > for f in os.listdir(os.path.abspath(libdir)):
> > module_name = f.strip('.py')
> 
> This doesn't do what you think it does:
> 
>  >>> 'pyoopsyp.py'.strip('.py')
> 'oops'
> 
> Read the docs on strip(), and then the docs on os.path.splitext() and
> friends, and/or download and use Jasen Orendorrf's "path" module which
> will make all your path-related code half the size and twice as easy to
> read and write.
> 
> -Peter
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I import a py script by its absolute path name?

2005-07-15 Thread could ildg
Thank you for your help.
It's really useful for me.

On 7/14/05, Chris Lambacher <[EMAIL PROTECTED]> wrote:
> You probably actually want:
> 
> import sys
> sys.path.instert(0, r'c:\xxx\yyy')
> m = __import__('zzz', globals(),  locals(), [])
> del sys.path[0]
> 
> Because if another module named zzz exists in your path.  Appending will pick
> those versions up first.  Then you delete the path you just added so that you
> don't have any problems importing other modules that may have the same names a
> python files in the path you just added.
> 
> -Chris
> On Thu, Jul 14, 2005 at 02:52:31PM +0300, Edvard Majakari wrote:
> > could ildg <[EMAIL PROTECTED]> writes:
> >
> > > I want to import c:\xxx\yyy\zzz.py into my programme,
> > > What should I do?
> > > Thank you~
> >
> > import sys
> > sys.path.append('c:\xxx\yyy')
> > import zzz
> >
> > (Untested, similar idiom would work in *nix systems, never programmed in
> > Windows)
> >
> > However, I guess it is not very usual you should need to import stuff from
> > arbitrary locations. Consider publishing those modules in normal Python
> > include path (just see what ''print sys.path'' produces)
> >
> > --
> > # Edvard Majakari Software Engineer
> > # PGP PUBLIC KEY availableSoli Deo Gloria!
> >
> > $_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
> > join('',map{chr hex}(split/(\w{2})/)),uc 
> > substr(crypt(60281449,'es'),2,4),"\n";
> > --
> > 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: Python s60

2005-07-18 Thread could ildg
you can reference http://www.bigbold.com/snippets/tags/series60?page=2


On 18 Jul 2005 03:32:01 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi, I have looked around for any type of example of script that claims
> to read the contacts database from an s60 phone, but i cant figure how
> to use that examples. All i want is a simple, CLEAR, script that show
> how to open contact database of an s60 phone and load all contacts
> present into a listbox, nothing else. This will be easy for the
> experts! please help me! Thanks in advance!
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


What does "::" mean?

2005-07-19 Thread could ildg
I know that ":" can do slice works.
But I saw "::" today and it puzzled me much,
I can't find it in the python doc,
so I raise this question here.
The code is as below:
--
Jython 2.2a1 on java1.5.0_03 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> live='live';print live
live
>>> live=live[::-1];print live
evil
>>>

"[::-1]" can reverse a string magicly, how did it do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python s60 Contact DB

2005-07-19 Thread could ildg
You should raise this question at Nokia python for series60 forum,
I'm sure you can the answer there.
http://discussion.forum.nokia.com/forum/forumdisplay.php?s=85e4c1acee330fddde6b47a7b2feae73&forumid=102


On 19 Jul 2005 06:47:10 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi, i hope the expert can help me!
> I have a little problem:
> 
> This piece of code, in python console s60, before compiling will work
> great:
> 
> try:
> ..db = contacts.open()
> ..names = []
> ..numbers = []
> 
> The problem is that, if i compile it with py2sis (pyrsc_template.tmp
> replaced with the original to solve the submenus bug) it doesnt work,
> when that piece of code is executed, i receive error -50 and nothing
> happen! hope u can help me! 10ks a lot in advance
> 
> Regards.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Does pyparsing support UNICODE strings?

2005-08-04 Thread could ildg
pyparsing is very convenient to use. But I want to find some a py tool
to parse non-English strings. Does pyparsing support UNICODE strings?
If not, can someone tell me what py tool can do it? Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does pyparsing support UNICODE strings?

2005-08-04 Thread could ildg
I want to parse some Chinese words.
It seems that pyparsing doesn't work for me.
Thank you.
I have to use re directly, although it's harder, but it'll always work.

On 8/4/05, Robert Kern <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > pyparsing is very convenient to use. But I want to find some a py tool
> > to parse non-English strings. Does pyparsing support UNICODE strings?
> > If not, can someone tell me what py tool can do it? Thanks in advance.
> 
> Try it!
> 
> # vim:fileencoding=utf-8
> 
> from pyparsing import Word
> 
> text = "Καλημέρα, κόσμε!".decode('utf-8')
> alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce))
> 
> greet = Word(alphas) + u',' + Word(alphas) + u'!'
> greeting = greet.parseString(text)
> print greeting
> 
> --
> Robert Kern
> [EMAIL PROTECTED]
> 
> "In the fields of hell where the grass grows high
>   Are the graves of dreams allowed to die."
>-- Richard Harter
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Does pyparsing support UNICODE strings?

2005-08-04 Thread could ildg
OK, I make it.
It's right, it can work fine with unicode.
pyparsing is great.
Thanks.

On 8/4/05, could ildg <[EMAIL PROTECTED]> wrote:
> I want to parse some Chinese words.
> It seems that pyparsing doesn't work for me.
> Thank you.
> I have to use re directly, although it's harder, but it'll always work.
> 
> On 8/4/05, Robert Kern <[EMAIL PROTECTED]> wrote:
> > could ildg wrote:
> > > pyparsing is very convenient to use. But I want to find some a py tool
> > > to parse non-English strings. Does pyparsing support UNICODE strings?
> > > If not, can someone tell me what py tool can do it? Thanks in advance.
> >
> > Try it!
> >
> > # vim:fileencoding=utf-8
> >
> > from pyparsing import Word
> >
> > text = "Καλημέρα, κόσμε!".decode('utf-8')
> > alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce))
> >
> > greet = Word(alphas) + u',' + Word(alphas) + u'!'
> > greeting = greet.parseString(text)
> > print greeting
> >
> > --
> > Robert Kern
> > [EMAIL PROTECTED]
> >
> > "In the fields of hell where the grass grows high
> >   Are the graves of dreams allowed to die."
> >-- Richard Harter
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Does pyparsing support UNICODE strings?

2005-08-04 Thread could ildg
So what's you code?
and what's you system default encoding?

On 8/4/05, saddle <[EMAIL PROTECTED]> wrote:
> hello, but i can't run the script. could u told me what's the trick pls?
> here is the error output.
> 
> D:\python\test>pyp
> sys:1: DeprecationWarning: Non-ASCII character '\xce' in file 
> D:\python\test\py
> .py on line 3, but no encoding declared; see 
> http://www.python.org/peps/pep-026
> .html for details
> Traceback (most recent call last):
>   File "D:\python\test\pyp.py", line 9, in ?
> greeting = greet.parseString(text)
>   File "C:\Python24\Lib\site-packages\pyparsing.py", line 616, in parseString
> loc, tokens = self.parse( instring.expandtabs(), 0 )
>   File "C:\Python24\Lib\site-packages\pyparsing.py", line 558, in parse
> loc,tokens = self.parseImpl( instring, loc, doActions )
>   File "C:\Python24\Lib\site-packages\pyparsing.py", line 1387, in parseImpl
> loc, exprtokens = e.parse( instring, loc, doActions )
>   File "C:\Python24\Lib\site-packages\pyparsing.py", line 562, in parse
> loc,tokens = self.parseImpl( instring, loc, doActions )
>   File "C:\Python24\Lib\site-packages\pyparsing.py", line 873, in parseImpl
> raise exc
> pyparsing.ParseException: Expected "," (at char 5), (line:1, col:6)
> On Thu, 4 Aug 2005 17:24:23 +0800
> could ildg <[EMAIL PROTECTED]> Χ«Π΄ΣΪ:
> 
> could.net> OK, I make it.
> could.net> It's right, it can work fine with unicode.
> could.net> pyparsing is great.
> could.net> Thanks.
> could.net>
> could.net> On 8/4/05, could ildg <[EMAIL PROTECTED]> wrote:
> could.net> > I want to parse some Chinese words.
> could.net> > It seems that pyparsing doesn't work for me.
> could.net> > Thank you.
> could.net> > I have to use re directly, although it's harder, but it'll 
> always work.
> could.net> >
> could.net> > On 8/4/05, Robert Kern <[EMAIL PROTECTED]> wrote:
> could.net> > > could ildg wrote:
> could.net> > > > pyparsing is very convenient to use. But I want to find some 
> a py tool
> could.net> > > > to parse non-English strings. Does pyparsing support UNICODE 
> strings?
> could.net> > > > If not, can someone tell me what py tool can do it? Thanks 
> in advance.
> could.net> > >
> could.net> > > Try it!
> could.net> > >
> could.net> > > # vim:fileencoding=utf-8
> could.net> > >
> could.net> > > from pyparsing import Word
> could.net> > >
> could.net> > > text = "Καλημέρα, κόσμε!".decode('utf-8')
> could.net> > > alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce))
> could.net> > >
> could.net> > > greet = Word(alphas) + u',' + Word(alphas) + u'!'
> could.net> > > greeting = greet.parseString(text)
> could.net> > > print greeting
> could.net> > >
> could.net> > > --
> could.net> > > Robert Kern
> could.net> > > [EMAIL PROTECTED]
> could.net> > >
> could.net> > > "In the fields of hell where the grass grows high
> could.net> > >   Are the graves of dreams allowed to die."
> could.net> > >-- Richard Harter
> could.net> > >
> could.net> > > --
> could.net> > > http://mail.python.org/mailman/listinfo/python-list
> could.net> >
> could.net> --
> could.net> http://mail.python.org/mailman/listinfo/python-list
> 
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Does pyparsing support UNICODE strings?

2005-08-04 Thread could ildg
I tested his code in a file test2.py:

# -*- coding: UTF-8 -*-

from pyparsing import Word

text = "Καλημέρα, κόσμε!".decode('utf-8')
alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce))

greet = Word(alphas) + u',' + Word(alphas) + u'!'
greeting = greet.parseString(text)
print greeting

After run this, I got the following result:
[u'\u039a\u03b1\u03bb\u03b7\u03bc\u03ad\u03c1\u03b1', u',',
u'\u03ba\u03cc\u03c3\u03bc\u03b5', u'!']

I use windows xp sp2 simple Chinese,
python 2.41,my code is as below:
# -*- coding: UTF-8 -*-

from pyparsing import CharsNotIn

text = u"简体中文测试, 繁體中文測試!"
greet = CharsNotIn(u',!') + u',' + CharsNotIn(u',!') + u'!'
greeting = greet.parseString(text)
for x in greeting:
print x.encode("cp936") #or x.encode("gbk")

And the result is as below:
简体中文测试
,
 繁體中文測試
!

Everything works just correctly.

On 8/4/05, saddle <[EMAIL PROTECTED]> wrote:
> the code what posted by Rober Kern
> 
> from pyparsing import Word
> text = "Καλημ?ρα, κ?σμε!".decode('utf-8')
> alphas = u''.join(unichr(x) for x in xrange(0x386, 0x3ce))
> greet = Word(alphas) + u',' + Word(alphas) + u'!'
> greeting = greet.parseString(text)
> print greeting
> 
> 
> my system default is cp936, Simp Chinese.
> 
> On Thu, 4 Aug 2005 17:33:16 +0800
> could ildg <[EMAIL PROTECTED]> ׫д��:
> 
> could.net> So what's you code?
> could.net> and what's you system default encoding?
> could.net>
> could.net> On 8/4/05, saddle <[EMAIL PROTECTED]> wrote:
> could.net> > hello, but i can't run the script. could u told me what's the 
> trick pls?
> could.net> > here is the error output.
> could.net> >
> could.net> > D:\python\test>pyp
> could.net> > sys:1: DeprecationWarning: Non-ASCII character '\xce' in file 
> D:\python\test\py
> could.net> > .py on line 3, but no encoding declared; see 
> http://www.python.org/peps/pep-026
> could.net> > .html for details
> could.net> > Traceback (most recent call last):
> could.net> >   File "D:\python\test\pyp.py", line 9, in ?
> could.net> > greeting = greet.parseString(text)
> could.net> >   File "C:\Python24\Lib\site-packages\pyparsing.py", line 616, 
> in parseString
> could.net> > loc, tokens = self.parse( instring.expandtabs(), 0 )
> could.net> >   File "C:\Python24\Lib\site-packages\pyparsing.py", line 558, 
> in parse
> could.net> > loc,tokens = self.parseImpl( instring, loc, doActions )
> could.net> >   File "C:\Python24\Lib\site-packages\pyparsing.py", line 1387, 
> in parseImpl
> could.net> > loc, exprtokens = e.parse( instring, loc, doActions )
> could.net> >   File "C:\Python24\Lib\site-packages\pyparsing.py", line 562, 
> in parse
> could.net> > loc,tokens = self.parseImpl( instring, loc, doActions )
> could.net> >   File "C:\Python24\Lib\site-packages\pyparsing.py", line 873, 
> in parseImpl
> could.net> > raise exc
> could.net> > pyparsing.ParseException: Expected "," (at char 5), (line:1, 
> col:6)
> could.net> > On Thu, 4 Aug 2005 17:24:23 +0800
> could.net> > could ildg <[EMAIL PROTECTED]> ׫д��:
> could.net> >
> could.net> > could.net> OK, I make it.
> could.net> > could.net> It's right, it can work fine with unicode.
> could.net> > could.net> pyparsing is great.
> could.net> > could.net> Thanks.
> could.net> > could.net>
> could.net> > could.net> On 8/4/05, could ildg <[EMAIL PROTECTED]> wrote:
> could.net> > could.net> > I want to parse some Chinese words.
> could.net> > could.net> > It seems that pyparsing doesn't work for me.
> could.net> > could.net> > Thank you.
> could.net> > could.net> > I have to use re directly, although it's harder, 
> but it'll always work.
> could.net> > could.net> >
> could.net> > could.net> > On 8/4/05, Robert Kern <[EMAIL PROTECTED]> wrote:
> could.net> > could.net> > > could ildg wrote:
> could.net> > could.net> > > > pyparsing is very convenient to use. But I want 
> to find some a py tool
> could.net> > could.net> > > > to parse non-English strings. Does pyparsing 
> support UNICODE strings?
> could.net> > could.net> > > > If not, can someone tell me what py tool can do 
> it? Thanks in a

Re: IronPython 0.9 Released

2005-08-05 Thread could ildg
Why is iron python runs so fast but jython runs so slow while C# and
java seem very much the same?

On 8/5/05, EP <[EMAIL PROTECTED]> wrote:
> Oops.  Nevermind.
> 
> [like the old Saturday Night Live]
> 
> 
> 
> > Original Message
> > From: "EP" <[EMAIL PROTECTED]>
> > To: python-list@python.org
> > Date: Thu, Aug-4-2005 10:09 PM
> > Subject: Re: IronPython 0.9 Released
> >
> > "Luis M. Gonzalez" Announced:
> >
> > > IronPython 0.9 Released(8/2/2005 10:28:41 AM)
> > >
> > >
> > http://www.microsoft.com/downloads/details.aspx?familyid=cf5ae627-5df1-4f8a-ba8b-d64f0676f43f&displaylang=en
> > >
> >
> > MS website says:
> >
> > """System Requirements
> >
> > *  Supported Operating Systems: Windows Server 2003; Windows XP
> >
> > You must install the .NET Framework Version 2.0 Redistributable Package
> > Beta 2 prior to installing IronPython."""
> >
> >
> > And
> >
> >
> > """Important: You cannot install two different language versions of the
> > .NET Framework on the same machine. Attempting to install a second
> > language version of the .NET Framework will cause the following error to
> > appear: "Setup cannot install Microsoft .NET Framework because another
> > version of the product is already installed." If you are targeting a
> > non-English platform or if you wish to view .NET Framework resources in a
> > different language, you must download the appropriate language version
> > of the .NET Framework language pack."""
> >
> >
> > So, one has to uninstall their stable .NET Framework to install a beta
> > .NET Framework to try out a beta release of a new Python?  Would this
> > not be of concern to folks who actually build ontop of .NET (and want to
> > be sure their current code / applications / tools work)?
> >
> > It is really all or none with MS, isn't it?  If the
> > language/application is not ready for prime time, why would someone commit 
> > to beta code
> > and a beta framework upon which other applications depend?
> >
> >
> > I may have the wrong perspective on all this, but it really befuddles
> > me.
> >
> >
> > [Bring on PyPy]
> >
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> >
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How to determine that if a folder is empty?

2005-08-07 Thread could ildg
I want to check if a folder named "foldername" is empty.
I use os.listdir(foldername)==[] to do this,
but it will be very slow if the folder has a lot of sub-files.
Is there any efficient ways to do this?
Thanks~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine that if a folder is empty?

2005-08-07 Thread could ildg
Thank you .
so you mean that this is not platform-independent?

On 8/8/05, Neil Hodgson <[EMAIL PROTECTED]> wrote:
> could ildg:
> 
> > I want to check if a folder named "foldername" is empty.
> > I use os.listdir(foldername)==[] to do this,
> > but it will be very slow if the folder has a lot of sub-files.
> > Is there any efficient ways to do this?
> 
> The first thing to do is measure the performance of this operation
> in the context of your application to see if it is really worth extra
> effort.
> Tweaking this will depend on the platform. On Windows you can use
> ctypes and the system functions FindFirstFile/FindNextFile/FindClose,
> finishing once you see a single file. Directories always contain "." and
> ".." entries so they should be ignored. On other platforms there will be
> similar low level functions.
> 
> Neil
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine that if a folder is empty?

2005-08-08 Thread could ildg
On 8/8/05, Peter Hansen <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > I want to check if a folder named "foldername" is empty.
> > I use os.listdir(foldername)==[] to do this,
> > but it will be very slow if the folder has a lot of sub-files.
> > Is there any efficient ways to do this?
> 
> I'm just curious to know under what circumstances where it's important
> to know whether a directory is empty it's also important that the
> operation occur with lightning speed...
I want to know this because I want to zip a directory and all of its
sub-files and sub-directories to a zip file. zipfile module of python
will not automatically include the empty directories, so I have to
check if a dir is empty and do this manually. I did this with java,
it's very fast, but when I do this with python. I use the code to
backup a directory every morning after I get up. It is not import if
it's fast or not. I just want to know whether their is better
solutions.

import os,zipfile
from os.path import join
from datetime import date

def zipfolder(foldername,filename):
"""
  zip folder foldername and all its subfiles and folders into a
  zipfile named filename.
"""
zip=zipfile.ZipFile(filename,"w",zipfile.ZIP_DEFLATED)
for root,dirs,files in os.walk(foldername):
for dir in dirs:
#now I don't check any more whether a dir is empty
zif=zipfile.ZipInfo(join(root,dir)+"/")
zip.writestr(zif,"")
for filename in files:
print "compressing ",join(root,filename)
zip.write(join(root,filename))
zip.close()
print "Finished compressing."


> 
> Reinhold's suggestion to delete the folder was interesting in this
> respect... isn't that (prior to deleting a folder) just about the only
> time one cares if it's empty, normally?  And in this case you don't need
> to do the check, as Reinhard shows, so performance isn't an issue.
> 
> -Peter
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Project (sigh with Java)

2005-08-08 Thread could ildg
Good job~
I also like both java and py so I always focus on jython,
but now it's being moved forward kinda slow.
I'm looking forward to jython 2.4.

You're right, swing is great. wxpy is also wonderfu but it's so lack
of docs. I mainly work on windows so I use p4d(python for delphi), I
use delphi for UI and use py for some other works. p4d is magic, I
like it. And I recommend it to everyone who is familiar with both py
and delphi.

On 8/9/05, Ramza Brown <[EMAIL PROTECTED]> wrote:
> I know you may frown at my use at java, but this is a pretty simple way
> to create GUIs quickly, using Java's swing.  I have some code for an
> approach for integrating the swing GUI components and python.  I threw
> the project together in a couple of days, so it is not some massive
> application.  And, I have some little models(hehe).  Anyway, if you want
> to check out an approach for working with Jython, here it is.
> 
> Some questions, I do get asked, how do you us python code in java.  I
> normally don't like using my python objects in the java code.
> Basically, there is never the *.java files.  You can do everything in
> python, it is a lot simpler, short of language constructs you can only
> do in java.
> 
> This is a HTML code generator, you only need a java runtime.
> 
> http://www.newspiritcompany.com/phoenixproj.html
> 
> --
> Ramza from Atlanta
> http://www.newspiritcompany.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Project (sigh with Java)

2005-08-08 Thread could ildg
But the function is also too limited. What I want to do is to run much
of my py scripts in jython as good as possible.

On 8/9/05, Ramza Brown <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > Good job~
> > I also like both java and py so I always focus on jython,
> > but now it's being moved forward kinda slow.
> > I'm looking forward to jython 2.4.
> >
> > You're right, swing is great. wxpy is also wonderfu but it's so lack
> > of docs. I mainly work on windows so I use p4d(python for delphi), I
> > use delphi for UI and use py for some other works. p4d is magic, I
> > like it. And I recommend it to everyone who is familiar with both py
> > and delphi.
> >
> > On 8/9/05, Ramza Brown <[EMAIL PROTECTED]> wrote:
> >
> >>I know you may frown at my use at java, but this is a pretty simple way
> >>to create GUIs quickly, using Java's swing.  I have some code for an
> >>approach for integrating the swing GUI components and python.  I threw
> >>the project together in a couple of days, so it is not some massive
> >>application.  And, I have some little models(hehe).  Anyway, if you want
> >>to check out an approach for working with Jython, here it is.
> >>
> >>Some questions, I do get asked, how do you us python code in java.  I
> >>normally don't like using my python objects in the java code.
> >>Basically, there is never the *.java files.  You can do everything in
> >>python, it is a lot simpler, short of language constructs you can only
> >>do in java.
> >>
> >>This is a HTML code generator, you only need a java runtime.
> >>
> >>http://www.newspiritcompany.com/phoenixproj.html
> >>
> >>--
> >>Ramza from Atlanta
> >>http://www.newspiritcompany.com
> >>--
> >>http://mail.python.org/mailman/listinfo/python-list
> >>
> 
> And I normally don't take the entire python library with me.  I just
> take 'jython.jar' so I can distribute it easier.
> 
> 
> 
> --
> Ramza from Atlanta
> http://www.newspiritcompany.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Challenge on BBC

2005-08-11 Thread could ildg
But when I can't find a way for a long time, I'll be upset.

On 8/12/05, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> Magnus Lie Hetland wrote:
> > Just saw this on the BBC World program Click Online:
> >
> >   
> > http://bbcworld.com/content/template_clickonline.asp?pageid=665&co_pageid=6
> >
> > I must say, I think this is the first time I've heard Python discussed
> > on TV at all... Cool :)
> >
> > (Now maybe I'll have to finish the rest of those P.C. levels... ;)
> >
> 
> Boy, Python Challenge is addictive!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


What does the word "quiet" mean in this paragraph?

2005-08-14 Thread could ildg
The paragraph is as below, I mark the word quiet with *** ***.
___
One problem with distributed applications is that if no data arrives
over a long period of time, you need to wonder why. On one hand, it
could be that the other program just hasn't had any information to
send recently. On the other hand, the other program could have
crashed. TCP handles this problem by allowing you to send an "Are you
still alive?" message every so often to  ***quiet*** connections. The
way is to call setKeepAlive() with a value of true.
___
Please tell me what does the word "quiet" mean, Thank you~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does the word "quiet" mean in this paragraph?

2005-08-14 Thread could ildg
Thank you very much.
I am not a native English speeker so I have problem when understanding
this sentense. Now I know that the word  "quiet" is an adjective and
I'm totally catch it. Thank you~

On 8/14/05, Peter Decker <[EMAIL PROTECTED]> wrote:
> On 8/14/05, could ildg <[EMAIL PROTECTED]> wrote:
> > The paragraph is as below, I mark the word quiet with *** ***.
> > ___
> > One problem with distributed applications is that if no data arrives
> > over a long period of time, you need to wonder why. On one hand, it
> > could be that the other program just hasn't had any information to
> > send recently. On the other hand, the other program could have
> > crashed. TCP handles this problem by allowing you to send an "Are you
> > still alive?" message every so often to  ***quiet*** connections. The
> > way is to call setKeepAlive() with a value of true.
> > ___
> > Please tell me what does the word "quiet" mean, Thank you~
> 
> It means that the remote application has sent any data recently: 'if
> no data arrives over a long period of time'. We commonly say that two
> programs 'talk' to each other, or that one program 'tells' the other
> when it has received input. If these programs aren't 'saying'
> anything, they're considered to be 'quiet'. The paragraph you quoted
> is concerned with determining why the remote app hasn't 'said'
> anything in a while: has it crashed, or is it really not getting any
> data to relay.
> --
> 
> # p.d.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How can I exclude a word by using re?

2005-08-14 Thread could ildg
In re, the punctuation "^" can exclude a single character, but I want
to exclude a whole word now. for example I have a string "hi, how are
you. hello", I want to extract all the part before the world "hello",
I can't use ".*[^hello]" because "^" only exclude single char "h" or
"e" or "l" or "o". Will somebody tell me how to do it? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I exclude a word by using re?

2005-08-14 Thread could ildg
Thank you.
But what should I do if there are more than one hello and I only want
to extract what's before the first "hello". For example, the raw
string is "hi, how are you? hello I'm fine, thank you hello. that's it
hello", I want to extract all the stuff before the first hello?

On 14 Aug 2005 08:02:16 -0700, Christoph Rackwitz
<[EMAIL PROTECTED]> wrote:
> re.findall('(.*)hello|(.*)', 'hi, how are you. hello')
> re.findall('(.*)hello|(.*)', 'hi, how are you. ello')
> take a look at the outputs of these.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I exclude a word by using re?

2005-08-15 Thread could ildg
I want to use re because I want to extract something from a html. It
will be very complicated  without using re. But while using re, I
found that I must exlude a hole word "", certainly, there are
many many "" in this html.

My re is as below:
_
r=re.compile(ur'valign=top>(?P\d{1,2})]*>\s{0,2}'
ur''
ur'(?P.+)',re.UNICODE|re.IGNORECASE)
_
There should be over 30 matches in the html. But I find nothing by
re.finditer(html) because my last line of re is wrong. I can't use
"(?P.+)" because there are many many "" in the html
and I just want the ".*" to match what are before the firest "".
So I think if there is some idea I can exclude a word, this will be
done. Assume there is "NOT(WORD)" can do it, I just need to write the
last line of the re as "(?P(NOT())+)".
But I still have no idea after thinking and trying for a very long time.

In other words, I want the "" of "(?P.+)" to be
exactly the first "" in this match. And there is more than one
match in this html, so this must be done by using re.

And I can't use any of your idea because what I want I deal with is a
very complicated html, not just a single line of word.

I can copy part of the html up to here but it's kinda too lengthy.
On 8/15/05, John Machin <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > In re, the punctuation "^" can exclude a single character, but I want
> > to exclude a whole word now. for example I have a string "hi, how are
> > you. hello", I want to extract all the part before the world "hello",
> > I can't use ".*[^hello]" because "^" only exclude single char "h" or
> > "e" or "l" or "o". Will somebody tell me how to do it? Thanks.
> 
> (1) Why must you use re? It's often a good idea to use string methods
> where they can do the job you want.
> (2) What do you want to have happen if "hello" is not in the string?
> 
> Example:
> 
> C:\junk>type upto.py
> def upto(strg, what):
>  k = strg.find(what)
>  if k > -1:
>  return strg[:k]
>  return None # or raise an exception
> 
> helo = "hi, how are you? HELLO I'm fine, thank you hello hello hello.
> that's it"
> 
> print repr(upto(helo, "HELLO"))
> print repr(upto(helo, "hello"))
> print repr(upto(helo, "hi"))
> print repr(upto(helo, "goodbye"))
> print repr(upto("", "goodbye"))
> print repr(upto("", ""))
> 
> C:\junk>upto.py
> 'hi, how are you? '
> "hi, how are you? HELLO I'm fine, thank you "
> ''
> None
> None
> ''
> 
> HTH,
> John
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I exclude a word by using re?

2005-08-15 Thread could ildg
Thank you, 
you code using pyparsing works very well. Now I got the "number" and
the "url". But I still want to get the "name".
I'll turn to pyparsing and see how to get the "name" from the html.
But I hope you can enlighten me for one more time since I'm not
farmiliar with the pyparsing module.

On 15 Aug 2005 21:15:02 -0700, Paul McGuire <[EMAIL PROTECTED]> wrote:
> Given the example re that you've been trying to get working, here is a
> pyparsing approach that might be more, um, approachable.
> Unfortunately, since I don't have the URL of the page you are working
> with, I'm unable to test this before posting.
> 
> Good luck,
> -- Paul
> 
> # getMP3s.py
> # get pyparsing at http://pyparsing.sourceforge.net
> #
> 
> from pyparsing import *
> import urllib
> 
> #~
> r=re.compile(ur'valign=top>(?P­\d{1,2})]*>­\s{0,2}'
> 
> #~ ur''
> #~ ur'(?P.+)',re.UNICO­DE|re.IGNORECASE)
> 
> tdStart,tdEnd = makeHTMLTags("td")
> aStart,aEnd = makeHTMLTags("a")
> 
> number = Word(nums)
> valign = CaselessLiteral("valign=top>")
> 
> mp3Entry = valign + number.setResultsName("number") + tdEnd + \
> tdStart + SkipTo(aStart) + aStart + \
> SkipTo(tdEnd) + tdEnd
> 
> # get list of mp3's
> targetURL = "http://whatever";
> targetPage = urllib.urlopen( targetURL )
> targetHTML = targetPage.read()
> targetPage.close()
> 
> for toks,s,e in mp3Entry.scanString(targetHTML):
> print toks.number, toks.starta.href
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I exclude a word by using re?

2005-08-16 Thread could ildg
Thanks for all of you~
I made it.
Pyparsing is really nice.

On 16 Aug 2005 11:33:48 -0700, Paul McGuire <[EMAIL PROTECTED]> wrote:
> I just reviewed what the re "\s" signifies: whitespace.  This is easy,
> pyparsing ignores all intervening whitespace by default.  So mp3Entry
> simplfies to:
> 
> mp3entry = valign + number.setResultsName("number"限� + tdEnd + \
> tdStart + aStart + \
> SkipTo(tdEnd).setResultsName("要苔me") + tdEnd
> 
> which leads me to another question - isn't there a closing  in
> there somewhere, probably at the end of the name?  If so, then you
> might be better off with:
> 
> mp3entry = valign + number.setResultsName("number"限� + tdEnd + \
> tdStart + aStart + \
> SkipTo(aEnd).setResultsName("要苔me") + aEnd + tdEnd
> 
> -- Paul
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [Jython-users] Re: [Jython-dev] Parsing grammar for jython available (compatible with python 2.4)

2005-08-29 Thread could ildg
thanks.
pydev is very nice, I like it.
But sometimes the code completion will not work.On 8/30/05, Frank Wierzbicki <[EMAIL PROTECTED]> wrote:

The code, as well as the files for javacc and asdl (both were changed)

are available in the pydev cvs at sourceforge, in theorg.python.pydev.parser module (the packages should be the same jythonuses -- org.python.parser and org.python.parser.ast).The tests I used are available in the tests source folder
(org.python.pydev.parser.PyParserTest)Hey -- that's great!
Unfortunately we probably will not be able to integrate 2.4 features in
until after we get a 2.3 version stable... But I hope you can remind us
of this work (or I can remember it) when we do get to that point. 
If you want to leave a strong reminder you could submit your changes as
a patch -- but I mean this as only the gentlest of nudges since it will
likely be quite a while before we could really look at it.

Thanks,
Frank
 


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

Re: [Jython-users] ANN: PyDev 0.9.8.1 released

2005-09-06 Thread could ildg
Thanks.
pydev is so alive.On 9/7/05, Fabio Zadrozny <[EMAIL PROTECTED]> wrote:
Hi All,PyDev - Python IDE (Python Development Enviroment for Eclipse) version0.9.8.1 has been released.Check the homepage (http://pydev.sourceforge.net/
) for more details.Details for Release: 0.9.8.1Major highlights:---* Java 1.4 support reintroduced.* Styles added for syntax highlighting (bold and italic),
contributed by Gerhard Kalab.Others that are new and noteworthy:-* zombie process after exiting eclipse should not happen anymore* paths with '.' are accepted for the pythonpath (unless they start
with a '.', because it may not accept relative paths).* relative imports are added to code-completion* local imports are taken into consideration when doing code completion* debugger has 'change support', so, changed variables in a scope
appear redCheers,Fabio--Fabio Zadrozny--Software DeveloperESSS - Engineering Simulation and Scientific Software
www.esss.com.brPyDev - Python Development Enviroment for Eclipsepydev.sf.netpydev.blogspot.com---
SF.Net email is Sponsored by the Better Software Conference & EXPOSeptember 19-22, 2005 * San Francisco, CA * Development Lifecycle PracticesAgile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf___Jython-users mailing list
[EMAIL PROTECTED]https://lists.sourceforge.net/lists/listinfo/jython-users
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: SQL SERVER : how to access it from Python

2005-09-13 Thread could ildg
Use ADO.If you ever used vb, using ado in py is just the same.If you don't know about ado, you can refer to this url:http://www.mayukhbose.com/python/ado/what-is-ado.php
On 9/14/05, Chavez Gutierrez, Freddy <[EMAIL PROTECTED]> wrote:









Hi all. I like to access a SQL SERVER from a Python 2.4 script running on WinXP.
I need to run store procedures and to query some tables.
Where should I start to investigate this topic?
Thanks for your help.


Regards,
Freddy Chavez.




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

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

How can I find all the dependencies of a py?

2005-09-14 Thread could ildg
when  I run a.py, it uses b.py,c.py and a.py uses x.py,y.py
How could I find all the modules that a.py and all of its imported modules?
Is there any built in functions or any tools to do this?
Thank you~, I really want to know it.
-- 
http://mail.python.org/mailman/listinfo/python-list

how to add a string to the beginning of a large binary file?

2005-03-27 Thread could ildg
I want to add a string such as "I love you" to the beginning of a binary file,
How to? and how to delete the string if I want to get the original file?

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


Re: how to add a string to the beginning of a large binary file?

2005-03-28 Thread could ildg
I'm not going to,
I just want to know how to manipulate a large file and insert or
delete some stuff in it.

On Mon, 28 Mar 2005 09:43:41 +0200, Patrick Useldinger
<[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > I want to add a string such as "I love you" to the beginning of a binary 
> > file,
> > How to? and how to delete the string if I want to get the original file?
> 
> You shouldn't use Python to write a virus :-)
> 
> -pu
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How to use "__new__"?

2005-03-29 Thread could ildg
As there is already __init__, why need a __new__?
What can __new__ give us while __init__ can't?
In what situations we should use __new__?
And in what situations we must use __new__?
Can __new__ take the place of __init__?
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to use "__new__"?

2005-03-29 Thread could ildg
Thank you.
I'm clear after I read the doc:
If __new__() returns an instance of cls, then the new instance's
__init__() method will be invoked like "__init__(self[, ...])", where
self is the new instance and the remaining arguments are the same as
were passed to __new__().

If __new__() does not return an instance of cls, then the new
instance's __init__() method will not be invoked.

__new__() is intended mainly to allow subclasses of immutable types
(like int, str, or tuple) to customize instance creation.


On Tue, 29 Mar 2005 18:12:41 -0700, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > As there is already __init__, why need a __new__?
> > What can __new__ give us while __init__ can't?
> > In what situations we should use __new__?
> > And in what situations we must use __new__?
> > Can __new__ take the place of __init__?
> 
> I believe the current documentation will be updated when 2.4.1 is
> released, but documentation for __new__ is now available at:
> 
> http://www.python.org/dev/doc/devel/ref/customization.html
> 
> In short, you could use __new__ in place of __init__, but it's probably
> only useful to do so if you need to change an instance *before* it's
> created.  In general, if you aren't subclassing an immutable type, and
> you're not sure that you need __new__, you probably don't.
> 
> STeVe
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


what's the use of __repr__?when shall I use it?

2005-03-31 Thread could ildg
What's the difference between __repr__  and   __str__? 
When will __repr__ be useful?
-- 
http://mail.python.org/mailman/listinfo/python-list


How to merge two binary files into one?

2005-04-04 Thread could ildg
I want to merge file A and file B into a new file C,
All of them are binary.
How to do that?
thanks a lot.
-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to merge two binary files into one?

2005-04-04 Thread could ildg
Thank you!
Python is really magic, even merge file can use "+".

On Apr 5, 2005 9:20 AM, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2005-04-05, could ildg <[EMAIL PROTECTED]> wrote:
> 
> > I want to merge file A and file B into a new file C, All of
> > them are binary.
> 
> file('C','wb').write(file('A','rb').read()+file('B','rb').read())
> 
> --
> Grant Edwards   grante Yow!  ... or were you
>   at   driving the PONTIAC that
>visi.comHONKED at me in MIAMI last
>Tuesday?
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to merge two binary files into one?

2005-04-04 Thread could ildg
Thank Grant, it works well.

On Apr 5, 2005 10:54 AM, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2005-04-05, could ildg <[EMAIL PROTECTED]> wrote:
> >> > I want to merge file A and file B into a new file C, All of
> >> > them are binary.
> >>
> >> file('C','wb').write(file('A','rb').read()+file('B','rb').read())
> >
> > Python is really magic, even merge file can use "+".
> 
> You probably shouldn't use the above code for very large files,
> since it reads files A and B entirely into memory before
> writing the combined data to C.
> 
> For large files, something like this is probably a better idea:
> 
> fout = file('C','wb')
> for n in ['A','B']:
> fin  = file(n,'rb')
> while True:
> data = fin.read(65536)
> if not data:
> break
> fout.write(data)
> fin.close()
> fout.close()
> 
> --
> Grant Edwards   grante Yow!  I feel like a wet
>   at   parking meter on Darvon!
>visi.com
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to merge two binary files into one?

2005-04-05 Thread could ildg
I'm so glad that this this problem has so many recipes.

On Apr 5, 2005 1:57 PM, Andrew Dalke <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
> > For large files, something like this is probably a better idea:
> 
> Or with the little-used shutil module, and keeping your
> nomenclature and block size of 65536
> 
> import shutil
> fout = file('C', 'wb')
> for n in ['A', 'B']:
>   fin = file(n, 'rb')
>   shutil.copyfileobj(fin, fout, 65536)
>   fin.close()
> fout.close()
> 
> Andrew
> [EMAIL PROTECTED]
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
--
http://mail.python.org/mailman/listinfo/python-list


Is it possible to distinguish between system environment variables and the user ones?

2005-04-05 Thread could ildg
To a environment variable in Windows, can python know if it is a
system environment
variable or a current-user environment variable?
-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
--
http://mail.python.org/mailman/listinfo/python-list


how can I extract all urls in a string by using re.findall() ?

2005-04-06 Thread could ildg
I want to retrieve all urls in a string. When I use re.fiandall, I get
a list of tuples.
My code is like below:

[code]
url=unicode(r"((http|ftp)://)?[\d]+\.)+){3}[\d]+(/[\w./]+)?)|([a-z]\w*((\.\w+)+){2,})([/][\w.~]*)*)")
m=re.findall(url,html)
for i in m:
   print i
[/code]

html is a variable of string type which contains many urls in it.
the code will print many tuples, and each tuple seems not to represent
a url. e.g, one of them is as below:

(u'http://', u'http', u'image.zhongsou.com/image/netchina.gif', u'',
u'', u'', u'', u'image.zhongsou.com', u'.com', u'.com',
u'/netchina.gif')

Why is there two "http" in it? and why are there so many ampty strings
in the tupe above? It's obviously not a url. How can I get the urls
correctly?

Thanks in advance.
-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can I extract all urls in a string by using re.findall() ?

2005-04-07 Thread could ildg
That's it! Thank you~~

On Apr 7, 2005 11:29 AM, Sidharth Kuruvila <[EMAIL PROTECTED]> wrote:
> Reading the documentation on re might be helpfull here :-P
> 
> findall returns a tuple of all the groups in each match.
> 
> You might find finditer usefull.
> 
> for m in re.finditer(url, html) :
> print m.group()
> 
> or you could replace all your paranthesis with the non-grouping
> version. That is, all brackets (...) with (?:...)
> 
> 
> On Apr 7, 2005 7:35 AM, could ildg <[EMAIL PROTECTED]> wrote:
> > I want to retrieve all urls in a string. When I use re.fiandall, I get
> > a list of tuples.
> > My code is like below:
> >
> > [code]
> > url=unicode(r"((http|ftp)://)?[\d]+\.)+){3}[\d]+(/[\w./]+)?)|([a-z]\w*((\.\w+)+){2,})([/][\w.~]*)*)")
> > m=re.findall(url,html)
> > for i in m:
> >print i
> > [/code]
> >
> > html is a variable of string type which contains many urls in it.
> > the code will print many tuples, and each tuple seems not to represent
> > a url. e.g, one of them is as below:
> >
> > (u'http://', u'http', u'image.zhongsou.com/image/netchina.gif', u'',
> > u'', u'', u'', u'image.zhongsou.com', u'.com', u'.com',
> > u'/netchina.gif')
> >
> > Why is there two "http" in it? and why are there so many ampty strings
> > in the tupe above? It's obviously not a url. How can I get the urls
> > correctly?
> >
> > Thanks in advance.
> > --
> > 鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
> > 直到有一天,我才发觉,我是鹦鹉。
> > 我是翻墙的鹦鹉。
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> 
> --
> http://blogs.applibase.net/sidharth
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can I extract all urls in a string by using re.findall() ?

2005-04-07 Thread could ildg
I agree with Cappy2112.
I got more puzzled after I read the docs

On 7 Apr 2005 15:13:04 -0700, Cappy2112 <[EMAIL PROTECTED]> wrote:
> >>Reading the documentation on re might be helpfull here :-P
> Many times, the python docs can make the problem more complicated,
> espcecially with regexes.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
--
http://mail.python.org/mailman/listinfo/python-list


Why does python class have not private methods? Will this never changed?

2005-04-19 Thread could ildg
Python is an oop language,
but why does it hava not private methods?
And it even has not real private fields.
Will this never changed?
Private stuff always makes programming much easier.
-- 
鹦鹉聪明绝顶、搞笑之极,是人类的好朋友。
直到有一天,我才发觉,我是鹦鹉。
我是翻墙的鹦鹉。
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Parsing data from URL

2005-04-24 Thread could ildg
I think it depends on the server

On 24 Apr 2005 17:24:18 -0700, Harlin Seritt <[EMAIL PROTECTED]> wrote:
> I am trying to do the following:
> 
> 
> 
> import urllib
> 
> url = 'http://www.website.com/file.shtml'
> dat = urllib.urlopen(url, 'r').read()
> print dat
> 
> When I do so, I get the following data:
> 
> 
> 
> 405 Method Not Allowed
> 
> Method Not Allowed
> The requested method POST is not allowed for the URL 
> 
> Apache/1.3.27 Server at website.com Port 80
> 
> 
> How can I make sure that I get the actual html data instead of the data
> from redirected URL?
> 
> thanks,
> 
> Harlin
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


How to write this regular expression?

2005-05-03 Thread could ildg
I need a regular expression to check if a string matches it.
The string consists of one to there parts, each parts is a underline
followed by a number,
and the number of the first part should be 0~31, and numbers of other
parts should be
larger than 31.

The requested re should match the following strings:
_3
_5_33
_21
_29_50
_29_700_70

And the re shouldn't match the following strings:
_3_5   the number of part 2 is less than 31
_43the number of part 1 shouldn't be less than 31
_5_43_69_98  there shouldn't be more than 3 parts

How to write the re, please?
Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write this regular expression?

2005-05-04 Thread could ildg
Does it matter whether it is a homework?
Why do you look down upon homework?
Everyone can do his homework well without any problems in your logic?
It's a problem I met. I tried a lot and I can't work it out,
so I came here for help.
I saw someone complained that a question is too lengthy,
and I saw some questions were complained to be unclear,
but I never saw someone waste his time to judge if a question is a
homework. If this is natural, I'll pay attention from now on.

On 4 May 2005 01:31:48 -0700, George Sakkis <[EMAIL PROTECTED]> wrote:
> This newsgroup is in general very helpful, but there are some
> exceptions; one of them is when the problem appears blatantly to be a
> homework. Perhaps if you showed that you worked on it and made some
> progress, but it's not quite right, someone may help you.
> 
> George
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write this regular expression?

2005-05-04 Thread could ildg
I can tell you that this is not any homework at all,
I think it by myself.

I like this maillist, it helped me a lot. but some guys as you look 
weird.
On 4 May 2005 10:25:20 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> Op 2005-05-04, could ildg schreef <[EMAIL PROTECTED]>:
> > Does it matter whether it is a homework?
> 
> Yes, because if other do your homework for you, you wont
> have learned anything from it.
> 
> > Why do you look down upon homework?
> 
> Who says he does. That he is not willing to do your homework
> for you, doesn't imply he looks down on it.
> 
> > Everyone can do his homework well without any problems in your logic?
> 
> There is difference in asking for help on how to solve a
> problem yourself and asking for the solution.
I read the document about re on python tommorow, and when I want to
use it to settle a problem, I found it not so easy, so I raise the question
here. I didn't say how I thought about it, because I don't want the question
to be too long. But a short question doesn't mean that I am too lazy
and I didn't even think about it. If you think I'm a kind of person
you hate to help,
you needn't.
> 
> --
> Antoon Pardon
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write this regular expression?

2005-05-04 Thread could ildg
Thank you. 

I just learned how to use re, so I want to find a way to settle it by
using re. I know that split it into pieces will do it quickly.

On 5/4/05, Peter Hansen <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > I need a regular expression to check if a string matches it.
> 
> Why do you think you need a regular expression?
> 
> If another approach that involved no regular expressions worked much
> better, would you reject it for some reason?
> 
> -Peter
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write this regular expression?

2005-05-04 Thread could ildg
On 5/5/05, Jeremy Bowers <[EMAIL PROTECTED]> wrote:
> On Wed, 04 May 2005 20:24:51 +0800, could ildg wrote:
> 
> > Thank you.
> >
> > I just learned how to use re, so I want to find a way to settle it by
> > using re. I know that split it into pieces will do it quickly.
> 
> I'll say this; you have two problems, splitting out the numbers and
> verifying their conformance to some validity rule.
> 
> I strongly recommend treating those two problems separately. While I'm not
> willing to guarantee that an RE can't be written for something like ("[A
> number A]_[A number B]" such that A < B) in the general case, it won't be
> anywhere near as clean or as easy to follow if you just write an RE to
> extract the numbers, then verify the constraints in conventional Python.
> 
> In that case, if you know in advance that the numbers are guaranteed to be
> in that format, I'd just use the regular expression "\d+", and the
> "findall" method of the compile expression:
> 
> Python 2.3.5 (#1, Mar  3 2005, 17:32:12)
> [GCC 3.4.3  (Gentoo Linux 3.4.3, ssp-3.4.3-0, pie-8.7.6.6)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import re
> >>> m = re.compile("\d+")
> >>> m.findall("344mmm555m")
> ['344', '555', '']
> >>>
> 
> If you're checking general matching of the parameters you've given, I'd
> feel no shame in checking the string against r"^(_\d+){1,3}$" with .match
> and then using the above to get the numbers, if you prefer that. (Note
> that I believe .match implies the initial ^, but I tend to write it
> anyways as a good habit. Explicit better than implicit and all that.)
> 
> (I just tried to capture the three numbers by adding a parentheses set
> around the \d+ but it only gives me the first. I've never tried that
> before; is there a way to get it to give me all of them? I don't think so,
> so two REs may be required after all.)
You can capture each number by using group, each group can have a name.

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


Re: How to write this regular expression?

2005-05-04 Thread could ildg
Sorry to Jeremy, I send my email derectly to your mailbox just now.

Group is very useful.
On 5/5/05, Jeremy Bowers <[EMAIL PROTECTED]> wrote:
> On Thu, 05 May 2005 09:30:21 +0800, could ildg wrote:
> > Jeremy Bowers wrote:
> >> Python 2.3.5 (#1, Mar  3 2005, 17:32:12) [GCC 3.4.3  (Gentoo Linux
> >> 3.4.3, ssp-3.4.3-0, pie-8.7.6.6)] on linux2 Type "help", "copyright",
> >> "credits" or "license" for more information.
> >> >>> import re
> >> >>> m = re.compile("\d+")
> >> >>> m.findall("344mmm555m")
> >> ['344', '555', '']
> >>
> >> (I just tried to capture the three numbers by adding a parenthesesset
> >> around the \d+ but it only gives me the first. I've never tried that
> >> before; is there a way to get it to give me all of them? I don't think
> >> so, so two REs may be required after all.)
> 
> > You can capture each number by using group, each group can have a name.
> 
> I think you missed out on what I meant:
> 
> Python 2.3.5 (#1, Mar  3 2005, 17:32:12)
> [GCC 3.4.3  (Gentoo Linux 3.4.3, ssp-3.4.3-0, pie-8.7.6.6)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import re
> >>> m = re.compile(r"((?P\d+)_){1,3}")
> >>> match = m.match("12_34_56_")
> >>> match.groups("name")
> ('56_', '56')
> >>>
> 
> Can you also get 12 & 34 out of it? (Interesting, as the non-named groups

Yes, you can extract **anything** you want if you like, to get each number
is easy, the only thing you need to do is to give a name to the number.

import re
str=r"_2_544_4400"
r=re.compile(r'^(?P_(?P[1-3]?\d))'
'(?P_(?P(3[2-9])|([4-9]\d)|(\d{3,})))?'
'(?P_(?P(3[2-9])|([4-9]\d)|(\d{3,})))?$',re.VERBOSE)
mo=r.match(str)
if mo:
   print mo.groupdict()
else:
   print "doesn't matche"

The code above will get the following rusult:
{'slice1': '_2', 'slice2': '_544', 'slice3': '_4400', 'number2':
'544', 'number3': '4400', 'number1': '2'}

> give you the *first* match)
> 
> I guess I've never wanted this because I usually end up using "findall"
> instead, but I could still see this being useful... parsing a function
> call, for instance, and getting a tuple of the arguments instead of all of
> them at once to be broken up later could be useful.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Found python for delphi new web site

2005-05-06 Thread could ildg
http://mmm-experts.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Found python for delphi new web site

2005-05-06 Thread could ildg
I haven't compile the PyScripter IDE project yet.
Does it support code-insight?

On 6 May 2005 22:28:59 -0700, James <[EMAIL PROTECTED]> wrote:
> It has been around for a while now. But I am glad I visited it again.
> The new PyScripter IDE is great. They should really announce new
> software like these here.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How to learn OO of python?

2005-05-18 Thread could ildg
I have learned python for over a month.
I heard that it was very easy to learn, but when I tried to know OO of python,
I found it really weird, some expressions seem very hard to understand,
and I can't find enough doc to know any more about it.
So, I wonder how did you master python? And where to find some cool docs?

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


Re: How to learn OO of python?

2005-05-18 Thread could ildg
Thanks very much to Harlin Seritt.
Your example is really helpful to me.

I read some more docs on python oop and I am more clear
now. But when I try to understand Decorators for Functions and Methods
in PEP 318, I got puzzled. How do Decorators work? 

I think decorator is a function which return a function, is this right?
e.g. The decorator below if from http://www.python.org/peps/pep-0318.html#id1.

def accepts(*types):
def check_accepts(f):
assert len(types) == f.func_code.co_argcount
def new_f(*args, **kwds):
for (a, t) in zip(args, types):
assert isinstance(a, t), \
   "arg %r does not match %s" % (a,t)
return f(*args, **kwds)
new_f.func_name = f.func_name
return new_f
return check_accepts

After I saw all the examples, I concluded that every decorator must
define an inner function which takes only one argument, the
function to decorate. Is this right?

On 5/18/05, Harlin Seritt <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > I have learned python for over a month.
> > I heard that it was very easy to learn, but when I tried to know OO
> of python,
> > I found it really weird, some expressions seem very hard to
> understand,
> > and I can't find enough doc to know any more about it.
> > So, I wonder how did you master python? And where to find some cool
> docs?
> >
> > Thanks.
> 
> I think I know what you mean. When I first started trying to learn the
> OOP aspect of Python I thought it was strange since I had started with
> OOP on Java and C++. Nonetheless, once you get the hang of it, OOP will
> make way more sense than all of the complications of Java and C++ class
> implementations. Let me give you a quick example of what I'm talking
> about:
> 
> class Animal:
>def eats(self):
>   print 'The animal eats.'
>def walks(self):
>   print 'The animal walks.'
> 
> """Here the class Dog instantiates the class Animal. 'Dog' will 'do'
> whatever 'Animal' does plus some other things which we will describe in
> this class code."""
> class Dog(Animal):
>"""#the self keyword means that this function will be a class
> function"""
>def communicate(self):
>   print 'The dog barks.'
> 
>"""# __init__ function defines what # #will happen as soon as this
> class is instantiated. Also, the overloaded variable designators (color
> = None, fur = None) allow the instantiator to optionally define these
> variables when called from elsewhere."""
> 
>def __init__(self, color=None, fur=None):
>   """# this time self will designate the variable 'color' # as a
> class variable."""
>   self.color = color
>   self.fur = fur
> 
> if __name__ == '__main__':
>sparky = Dog(color="White", fur="Short")
>sparky.communicate()
>print sparky.color
>print sparky.fur
>print sparky.eats()   # Here sparky will access 'Animal' methods
> that 'Dog' inherited.
>print sparky.walks()  # Another method originating from the 'Animal'
> class.
> 
> What happens if you don't use 'self' inside your class code? You won't
> be able to access it within the class outside of the method where you
> initialized it. For instance, if you don't designate color with self
> then you can only use the 'color' variable within the __init__()
> method. This is useful whenever you want to use 'color' as a private
> variable.
> 
> The same also goes for methods. Hopefully, you see how useful this can
> be down the road. This way you won't have to use variable/method access
> modifiers like Public, Private, Protected and so forth. If this doesn't
> make sense or you want more clarity, please let me know.
> 
> Good luck,
> 
> Harlin Seritt
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


What's the use of changing func_name?

2005-05-18 Thread could ildg
def a(func):
def _inner(*args, **kwds):
print "decorating..."
return func(*args, **kwds)
_inner.func_name = func.func_name -->when I delete this line, the
rusult is the same. why?
return _inner

@a
def g(*args):
for x in args:
print x
print "this is in function g"

g(1,2,3,4,5)

func_name is writable in python 2.4. I wonder what's the use of
writing it. Consider the code above, to change the func_name or not
will get the completely same result. The result is as
below:

decorating...
1
2
3
4
5
this is in function g

Please tell me how does this happen, thank you~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the use of changing func_name?

2005-05-18 Thread could ildg
Thank you for your help.
I know the function g is changed after setting the func_name.
But I still can't call funciton g by using f(), when I try to do
this, error will occur:

>>> g.func_name="f"
>>> print g

>>> f()
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'f' is not defined

Since the name of g is changed into f, why can't I call it by using f()?
Should I call it using f through other ways? Please tell me. Thanks~


On 5/19/05, Robert Kern <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > def a(func):
> > def _inner(*args, **kwds):
> > print "decorating..."
> > return func(*args, **kwds)
> > _inner.func_name = func.func_name -->when I delete this line, the
> > rusult is the same. why?
> > return _inner
> >
> > @a
> > def g(*args):
> > for x in args:
> > print x
> > print "this is in function g"
> >
> > g(1,2,3,4,5)
> >
> > func_name is writable in python 2.4. I wonder what's the use of
> > writing it. Consider the code above, to change the func_name or not
> > will get the completely same result. The result is as
> > below:
> >
> > decorating...
> > 1
> > 2
> > 3
> > 4
> > 5
> > this is in function g
> >
> > Please tell me how does this happen, thank you~
> 
> Well, the function you posted certainly doesn't change the literal
> string you have inside when you change its func_name. However, the
> function object *does* change.
> 
> In [1]:def g(x):
> ...:pass
> ...:
> 
> In [2]:g
> Out[2]:
> 
> In [3]:g.func_name = 'f'
> 
> In [4]:g
> Out[4]:
> 
> --
> Robert Kern
> [EMAIL PROTECTED]
> 
> "In the fields of hell where the grass grows high
>   Are the graves of dreams allowed to die."
>-- Richard Harter
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to learn OO of python?

2005-05-19 Thread could ildg
Steven Bethard:
Thank you so much!
Your answer is very very helpful~

On 5/19/05, Steven Bethard <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > I think decorator is a function which return a function, is this right?
> > e.g. The decorator below if from 
> > http://www.python.org/peps/pep-0318.html#id1.
> >
> > def accepts(*types):
> > def check_accepts(f):
> > assert len(types) == f.func_code.co_argcount
> > def new_f(*args, **kwds):
> > for (a, t) in zip(args, types):
> > assert isinstance(a, t), \
> >"arg %r does not match %s" % (a,t)
> > return f(*args, **kwds)
> > new_f.func_name = f.func_name
> > return new_f
> > return check_accepts
> >
> > After I saw all the examples, I concluded that every decorator must
> > define an inner function which takes only one argument, the
> > function to decorate. Is this right?
> 
> It's close, but not quite right.  (I will use the word "function" for
> the moment, but see below for why this is inaccurate.)  Every
> *decorator* must take only one argument, the function to decorate. It is
> not at all necessary that a decorator define an inner function.
> Consider (from [1]):
> 
> def onexit(f):
>  import atexit
>  atexit.register(f)
>  return f
> 
> onexit is a decorator because it takes a function and returns a
> function.  In this case, it happens to be that the same function is
> accepted and returned.
> 
> Note that in the 'accepts' example above, *check_accepts* is the
> decorator, not accepts.  The accepts function is actually a function
> that *returns* decorators.
> 
> Now about that word "function".  Decorators are actually *callables*
> that accept a single *callable* and return a *callable*.  Why does the
> terminology matter?  Because I can construct decorators from classes too
> (from [2]):
> 
> class memoized(object):
> def __init__(self, func):
>self.func = func
>self.cache = {}
> def __call__(self, *args):
>try:
>   return self.cache[args]
>except KeyError:
>   self.cache[args] = value = self.func(*args)
>   return value
>except TypeError:
>   return self.func(*args)
> 
> Now the memoized decorator can be used just like any other decorator, e.g.:
> 
> @memoized
> def fibonacci(n):
> if n in (0, 1):
>return n
> return fibonacci(n-1) + fibonacci(n-2)
> 
> Note however that memoized is a *callable*, not a *function*.
> 
> STeVe
> 
> [1] http://www.python.org/peps/pep-0318.html
> [2] http://wiki.python.org/moin/PythonDecoratorLibrary
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the use of changing func_name?

2005-05-19 Thread could ildg
Thanks to Robert Kern.
You mean that though we can change the func_name of a function,
but we still can't call it by func_name, and the func_name is only
useful in some other circumstances?
I also think so now after I have tried so many times on this puzzled func_name
property.
On 5/19/05, Robert Kern <[EMAIL PROTECTED]> wrote:
> could ildg wrote:
> > Thank you for your help.
> > I know the function g is changed after setting the func_name.
> > But I still can't call funciton g by using f(), when I try to do
> > this, error will occur:
> > 
> >
> >>>>g.func_name="f"
> >>>>print g
> >
> > 
> >
> >>>>f()
> >
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > NameError: name 'f' is not defined
> > 
> > Since the name of g is changed into f, why can't I call it by using f()?
> > Should I call it using f through other ways? Please tell me. Thanks~
> 
> Others have answered this particular question, but you're probably still
> wondering what is the use of changing .func_name if it doesn't also
> change the name by which you call it. The answer is that there are tools
> that use the .func_name attribute for various purposes. For example, a
> documentation generating tool might look at the .func_name attribute to
> make the proper documentation. Actually, that's probably *the* biggest
> use case because I can't think of any more significant ones.
> 
> --
> Robert Kern
> [EMAIL PROTECTED]
> 
> "In the fields of hell where the grass grows high
>   Are the graves of dreams allowed to die."
>-- Richard Harter
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: new release of RUR-PLE available

2005-05-21 Thread could ildg
It's very interestring,
I like it.
On 5/20/05, André Roberge <[EMAIL PROTECTED]> wrote:
> Michael Hoffman wrote:
> > André Roberge wrote:
> >
> >>Version 0.8.6a is now available.
> >
> >
> > You might see a bit more interest if you briefly explain what RUR-PLE
> > is, and where to find it.
> Oops.. sorry about that.
> 
> RUR - a Python Learning Environment.
> Its purpose is to provide an environment where people with no prior
> experience can learn computer programming (using Python of course!).
> 
> RUR-PLE currently requires that both Python and wxPython be installed.
> More information can be found at http://rur-ple.sourceforge.net
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


A newbie metaclass question

2005-05-22 Thread could ildg
When I try to learn metaclass of python by article at this place:
http://www.python.org/2.2/descrintro.html#metaclasses,
I changed the autosuper example a little as below:

class autosuper(type):
def __init__(cls,name,bases,dict):
super(autosuper,cls).__init__(name,bases,dict)
setattr(cls,"_%s__super" % name, super(cls))
print "in metaclass: ", super(cls)

class A:
__metaclass__ = autosuper
def meth(self):
print "in class A: ", self.__super

a=A()
a.meth() 

The result is as below:
in metaclass:  , NULL>
in class A:  , >

The 2 line are not the same. Why? Is this because that instance a has not
been created when the __init__ of the metaclass is called? If the cls in the
__init__ method is not an instance of A, what is it?

The metaclass of python is kinda difficult for me. Thanks for your help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Is pyunit still usable?

2005-05-30 Thread could ildg
I want to know something about unittest these days,
and since I'm learning python, I want to touch it through
python. But when I found the newest pyunit is even so
old, I wonder if it is still usable for current python version
2.4. Will you please tell me? Thank you.

What are the advantages and disadvantages of unittest?
Can somebody give me a detailed listing?
-- 
http://mail.python.org/mailman/listinfo/python-list