Re: What is different with Python ?
On Thu, 16 Jun 2005 07:36:18 -0400, Roy Smith <[EMAIL PROTECTED]> wrote: >Andrea Griffini <[EMAIL PROTECTED]> wrote: >> That strings in python are immutable it's surely >> just a detail, and it's implementation specific, >> but this doesn't means it's not something you can >> ignore for a while. > >I disagree. It is indeed something you can ignore for a while. The first >program you teach somebody to write is going to be: > >print "Hello, world" I mean that the fact that strings are immutable is one key aspect that cannot be worked around. Python is this way and in this very fact is different from e.g. C++. The ripple effect that this very little "detail" can have is not local. There are design based on strings that just do not make sense in python for this fact. It's not something you can "fix" later... if you need mutability you must simply not use strings for that (and this can have a serious impact on the source code). Of course there are programs in which that strings are immutable or not is irrelevant. But if you don't know what are the implications (e.g. how "is" works for strings in python) and you still don't run into problems it's just pure luck. The normal reaction I observed is that when they find a problem the result is a "python is buggy" idea. >It would be a mistake to mention now that "Hello, world" is an immutable >object. That's just not important at this point in the learning process. >Eventually, you're going to have to introduce the concept of immutability. >That point may not be much beyond lesson 2 or so, but it doesn't have to be >lesson 1. I must agree *if* you're teaching python first. I also *completely* agree if you're doing this just to get the appetite. What I don't agree is that starting from this level and going up is a good approach (with lously placed bricks you'll just not be able to hold the construction). To be able to build you'll need to memorize without a rationalization too many "details" that just do not make sense if you start from an ideal python world. I also must note that I, as a fourteen, found terribly interesting the idea of programming a computer even if the only things I could do were for example turning on and off pixels (blocks?) on a screen with resolution 40x50. Probably nowdays unless you show them an antialiased texture mapped 3D floating torus with their name and face on it in live video they'll prefer exchanging stupid messages with the mobile phone instead. Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound names in __del__
Hallöchen! "Terry Reedy" <[EMAIL PROTECTED]> writes: > "Torsten Bronger" <[EMAIL PROTECTED]> wrote: > >> Is there a way to detect whether the program is being terminated? > > See atexit module to register cleanup functions that run *before* > the interpreter starts haphazardly deleting stuff. So I could register a function that sets a global variable called "shutdown_has_begun" to "True". Then I say def __del__(self): if shutdown_has_begun: return ... Alternatively, I could enclose every __del__ contents block with a "try" whithout catching anything, just to suppress the error messages. However, all of this is not pretty pythonic in my opinion. Is it that exotic to want to call functions from within __del__? Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
ANN: pkpgcounter v1.50 is out
Hi there, I'm very pleased to announce the immediate availability of pkpgcounter v1.50 pkpgcounter is a 100% Python generic Page Description Language parser which can count the number of pages in documents. pkpgcounter currently recognizes the following PDLs : - PostScript (DSC compliant and binary) - PDF - PCLXL (aka PCL6) - PCL3/4/5 - ESC/P2 pkpgcounter is distributed under the terms of the GNU General Public License of the Free Software Foundation, and can be downloaded freely from : http://www.librelogiciel.com/software/pkpgcounter/action_Presentation summary of changes : - big modifications to the code to split the utility into a command line tool and a Python library. - several improvements to the PDL parsers. - the --debug command line option demonstrate the beginning of what will be available in the future. if any of you have the specifications of other Page Description Languages that you'd like to see recognized by pkpgcounter, please let me know. comments and contributions are more than welcome. thank you for reading Jerome Alet -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple instances of a python program
Most of the Python interpreter is a shared library, at least on Windows. The only duplication is in loaded Python code, which includes only your bot and the libraries it uses. If you have memory problems, try to do without some libraries or to edit unused parts out of them. Lorenzo Gatti -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound names in __del__
Torsten Bronger wrote: > When my __del__ methods are called because the program is being > terminated, I experience difficulties in calling functions that I > need for a clean shutdown of my instances. So far, there has been > only one of these functions, and a class-local alias solved the > problem. However, now there are many of them. __del__ is messy and I avoid it whenever possible. Make sure you read all the caveats and warnings on these pages: http://www.python.org/doc/ref/customization.html http://www.python.org/doc/lib/module-gc.html Most importantly, "It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits." > Or do you know a cleaner solution? For example, if I have > > import vpp43 > > would it help to say > > def __init__(self): >__vpp43 = vpp43 >... > > to guarantee that I can access all the routines in vpp43 in the > __del__ method? A similar idiom is found in the standard library (e.g. tempfile.py): # Cache the unlinker so we don't get spurious errors at # shutdown when the module-level "os" is None'd out. Note # that this must be referenced as self.unlink, because the # name TemporaryFileWrapper may also get None'd out before # __del__ is called. unlink = _os.unlink def close(self): if not self.close_called: self.close_called = True self.file.close() self.unlink(self.name) def __del__(self): self.close() -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
pyrex problem
hi everyone i'm newbie i try to compile the pyrex module: def controlla(char *test): cdef int limitem,lunghezz,li,l2,f,ii,kk cdef char *t1 cdef char *t2 limitem=4 lunghezz=len(test) l1=lunghezz-limitem+1 l2=lunghezz-limitem+1 f=0 for ii from 0 <= ii < l1-1: for kk from 0 <= kk < l2-1: t1=test[ii:ii+limitem] t2=test[kk:kk+limitem] if (ii<>kk): if t1==t2: f=1 if f==1: break if f==0: return test else: return 'no' but i receive the error: obtaining char * from temporary python value what happens? thanx everyone sorry for silly question. giorgio borghi -- http://mail.python.org/mailman/listinfo/python-list
Re: Set of Dictionary
See the frozendict recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414283 It was written exactly for this purpose: a dictionary that can be a member in a set. Oren -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 304 "Controlling Generation of Bytecode Files" - patch updated
Skip Montanaro <[EMAIL PROTECTED]> writes: > I updated the patch that supports PEP 304, "Controlling Generation of > Bytecode Files" to apply cleanly against current CVS. I've tested it on Mac > OS X (straight Unix build only). I'd appreciate it if some Linux, Windows > and Mac framework folks could apply the patch, rebuild, then run the tests > (there is a "testbcb" target in the Makefile that should give Windows people > an idea what to do). The patch is attached to > > http://python.org/sf/677103 > There's no patch attached. Thoas -- http://mail.python.org/mailman/listinfo/python-list
Re: 1980's Home Computer-style Package.
http://tothink.com/python/progman/ This module implements BASIC-like NEW, LOAD, RUN (sorry, no SAVE...). Oren -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
Andrea Griffini: > I also must note that I, as a fourteen, found terribly > interesting the idea of programming a computer even > if the only things I could do were for example turning > on and off pixels (blocks?) on a screen with resolution > 40x50. Probably nowdays unless you show them an antialiased > texture mapped 3D floating torus with their name and > face on it in live video they'll prefer exchanging > stupid messages with the mobile phone instead. Well, on one hand I think that even 20 years ago 99% of people preferred talking about football than programming; on the other hand, I think that even now there is a 1% of people extremely interested in turning on or off a pixel. I don't think anything significant changed in the percentages. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
> I always thought about our intellect being something "superior" > to this world made of fragile bones and stinking flesh. > However I realized that there's probably no real magic in > it... knowing there are pills to make you happy is sort of > shocking from a philosophical point of view :-) Yes it is, but it doesn't mean, that this well known insight has an effect on what people think about themselves, the religion and the Universe. For an example of what I try to say here, see the "What Deep Blue showed was that chess is not a game of true intelligence" discussion thread in rec.games.chess.computer and track what meaning people assign to the concept of Artificial Intelligence since the term was coined. As long as a machine can't replicate itself and defend its own existance, its intelligence will be questioned. And even if such a machine can fight its enemies the final answer to the question if "true intelligence" is unique to humans can be only given in a fight, but even then the evidence of existance of superior AI can't be given, because only dead people are forced to agree, but it doesn't matter to them anymore ... Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple instances of a python program
Rahul wrote: > Hi. > I am part of a group in my univ where we organize a programming > contest. In this contest we have a UDP based server. The server > simulates a game and each contestant is to develop a team of virtual > players. Each team is composed of 75 similar bots...i.e. governed by > the same logic. Thus the contestant submits a single copy of the client > and we instantiate the same program 75 times at the same time. > The problem is that while executables from C source files are small and > we can make 75 processes but we dont know what to do with python. > > If you have a python script and you want that 75 copies of the script > be run simultaneously how will you do it? Is there anyway to do so > without running 75 copies of the python interpreter simultaneously? > The technical way would be to use threads. Of course it could be that the rules of the game explicitly forbid that bots of a group communicate other than through the server. And it is easier to cheat there when you have only one Python program running. Daniel -- http://mail.python.org/mailman/listinfo/python-list
strxfrm works with unicode string ?
I am trying to use strxfm with unicode strings, but it does not work. This is what I did: >>> import locale >>> s=u'\u00e9' >>> print s é >>> locale.setlocale(locale.LC_ALL, '') 'French_Switzerland.1252' >>> locale.strxfrm(s) Traceback (most recent call last): File "", line 1, in -toplevel- locale.strxfrm(s) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128) >>> Someone sees what I did wrong ? -- http://mail.python.org/mailman/listinfo/python-list
How to right align IPaddress?
Dear all, Is it possible to right align the Ipaddress? Normally we can right align the list of numbers by %3u or %7u. How we can right align the Ipaddress? I expects below format output eg 203.199.200.0 203.33.20.0 with regards, Prabahar ___ Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE! http://in.mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: strxfrm works with unicode string ?
How about: import locale s=u'\u00e9' print s locale.setlocale(locale.LC_ALL, '') locale.strxfrm( s.encode( "latin-1" ) ) --- HTH, Gerald [EMAIL PROTECTED] schrieb: > I am trying to use strxfm with unicode strings, but it does not work. > This is what I did: > > import locale s=u'\u00e9' print s > > é > locale.setlocale(locale.LC_ALL, '') > > 'French_Switzerland.1252' > locale.strxfrm(s) > > > Traceback (most recent call last): > File "", line 1, in -toplevel- > locale.strxfrm(s) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in > position 0: ordinal not in range(128) > > > Someone sees what I did wrong ? > -- GPG-Key: http://keyserver.veridis.com:11371/search?q=0xA140D634 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to right align IPaddress?
IPnumber.rjust(15) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to right align IPaddress?
On Fri, 17 Jun 2005 09:46:52 +0100 (BST) praba kar <[EMAIL PROTECTED]> wrote: > Is it possible to right align > the Ipaddress? Normally we can > right align the list of numbers > by %3u or %7u. How we can right > align the Ipaddress? > > I expects below format output > eg 203.199.200.0 > 203.33.20.0 >>> for ip in ('203.199.200.0', '203.33.20.0'): ... print '%15s' % ip ... 203.199.200.0 203.33.20.0 >>> for ip in ('203.199.200.0', '203.33.20.0'): ... print ip.rjust(15) ... 203.199.200.0 203.33.20.0 -- Denis S. Otkidach http://www.python.ru/ [ru] -- http://mail.python.org/mailman/listinfo/python-list
Re: pyrex problem
On Fri, Jun 17, 2005 at 01:03:14AM -0700, [EMAIL PROTECTED] wrote: > hi everyone > i'm newbie > > i try to compile the pyrex module: > def controlla(char *test): You cannot have a C datatype in a Python like that. Much better to use def controlla(test): Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 and ftplib
On Thu, 16 Jun 2005 12:06:50 -0600, "John Roth" <[EMAIL PROTECTED]> said: > "Richard Lewis" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Hi there, > > > > I'm having a problem with unicode files and ftplib (using Python 2.3.5). > > > > I've got this code: > > > > xml_source = codecs.open("foo.xml", 'w+b', "utf8") > > #xml_source = file("foo.xml", 'w+b') > > > > ftp.retrbinary("RETR foo.xml", xml_source.write) > > #ftp.retrlines("RETR foo.xml", xml_source.write) > > > > It looks like there are at least two problems here. The major one > is that you seem to have a misconception about utf-8 encoding. > Who doesn't? ;-) > > Whatever program you are using to read it has to then decode > it from utf-8 into unicode. Failure to do this is what is causing > the extra characters on output. > > > Amusingly, this would have worked: > > xml_source = codecs.EncodedFile("foo.xml", "utf-8", "utf-8") > > It is, of course, an expensive way of doing nothing, but > it at least has the virtue of being good documentation. > OK, I've fiddled around a bit more but I still haven't managed to get it to work. I get the fact that its not the FTP operation thats causing the problem so it must be either the xml.minidom.parse() function (and whatever sort of file I give that) or the way that I write my results to output files after I've done my DOM processing. I'll post some more detailed code: def open_file(file_name): ftp = ftplib.FTP(self.host) ftp.login(self.login, self.passwd) content_file = file(file_name, 'w+b') ftp.retrbinary("RETR " + self.path, content_file.write) ftp.quit() content_file.close() ## Case 1: #self.document = parse(file_name) ## Case 2: #self.document = parse(codecs.open(file_name, 'r+b', "utf-8")) # Case 3: content_file = codecs.open(file_name, 'r', "utf-8") self.document = parse(codecs.EncodedFile(content_file, "utf-8", "utf-8")) content_file.close() In Case1 I get the incorrectly encoded characters. In Case 2 I get the exception: "UnicodeEncodeError: 'ascii' codec can't encode character u'\xe6' in position 5208: ordinal not in range(128)" when it calls the xml.minidom.parse() function. In Case 3 I get the exception: "UnicodeEncodeError: 'ascii' codec can't encode character u'\xe6' in position 5208: ordinal not in range(128)" when it calls the xml.minidom.parse() function. The character at position 5208 is an 'a' (assuming Emacs' goto-char function has the same idea about file positions as xml.minidom.parse()?). When I first tried these two new cases it came up with an unencodable character at another position. By replacing the large dash at this position with an ordinary minus sign I stopped it from raising the exception at that point in the file. I checked the character xe6 and (assuming I know what I'm doing) its a small ae ligature. Anyway, later on in the program I create a *very* large unicode string after doing some playing with the DOM tree. I then write this to a file using: html_file = codecs.open(file_name, "w+b", "utf8") html_file.write(very_large_unicode_string) The problem could be here? Cheers, Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: How to right align IPaddress?
Hi, the solution is a little more involved, if you want to "right justify" each of the four components of IP number: import sys try: .sIPnumber=sys.argv[1] except: . sys.exit(-1) list_lPcomponents=sIPnumber.split('.') sRJ=''" for n in list_IPcomponents: . sRJ+=n.rjust(3)+'.' print sRJ[:-1] Bye. -- http://mail.python.org/mailman/listinfo/python-list
Re: strxfrm works with unicode string ?
Gruëzi, Gerald ;-) Well, ok, but I don't understand why I should first convert a pure unicode string into a byte string. The encoding ( here, latin-1) seems an arbitrary choice. Your solution works, but is it a workaround or the real way to use strxfrm ? It seems a little artificial to me, but perhaps I haven't understood something ... Does this mean that you cannot pass a unicode string to strxfrm ? Bonne journée ! -- http://mail.python.org/mailman/listinfo/python-list
Re: whos -- a function listing objects
> [EMAIL PROTECTED] (b) wrote: >b> I have been a long time Matlab user. I Python, I miss Matlab's whos >b> command. >b> So I have written a little utility whos.py, which can be downloaded >b> here: >b> http://beluga.eos.ubc.ca/~tang/softwares/python/ >b> Here is the doc string: >b> # Before using whos, do: >b> execfile('whos.py') >>> execfile('whos.py') >>> whos() Traceback (most recent call last): File "", line 1, in ? File "whos.py", line 142, in whos iType1 = string.split(str(iType), "'")[1] NameError: global name 'string' is not defined Using execfile is a bad way to get the function definition. Import is the way to go. Just add a line: import string to the beginning of whos.py, and the the usage should be: from whos import whos whos() or import whos whos.whos() -- Piet van Oostrum <[EMAIL PROTECTED]> URL: http://www.cs.uu.nl/~piet [PGP] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to right align IPaddress?
> praba kar <[EMAIL PROTECTED]> (pk) wrote: >pk> Dear all, >pk> Is it possible to right align >pk> the Ipaddress? Normally we can >pk> right align the list of numbers >pk> by %3u or %7u. How we can right >pk> align the Ipaddress? >pk> I expects below format output >pk> eg 203.199.200.0 >pk> 203.33.20.0 "%15s" % ip -- Piet van Oostrum <[EMAIL PROTECTED]> URL: http://www.cs.uu.nl/~piet [PGP] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python & firewall control (Win32)
On Thu, 16 Jun 2005, Tim Williams wrote: > Does anyone know of (personal/desktop) firewall that can be controlled > via Python, or a Python Firewall package, or even something like DAXFi > but not dormant ? http://wipfw.sourceforge.net/ import os def deny(src, dst, proto="all"): cmd = "ipfw add deny " + proto + " from " + src + " to " + dst os.system(cmd) ipfw for Windows is technically in beta, but ipfw itself is rock solid. tom -- Tom, many thanks for that. I'm actually looking for a firewall (packet filter) I can control in realtime from a Python application, or even a Win32 equivalent of http://woozle.org/~neale/src/ipqueue/ . Though if I can stop & restart ipfw in a fraction of a second from within a Python app then the result would be the same I guess. I will have a play with it. Any other suggestions gratefully received too Cheers Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: log in to a website
[EMAIL PROTECTED] wrote: > I'm learning python, and my goal is to write a script that will log > into a website for me. The site uses HTTPS, the form uses the "POST" > method. > > >From what I've been able to find so far, it looks like i need to use > the urllib2 module...does anyone know where I can find some good sample > code to read up on how to do this? > > -Thx Is it just BASIC authentication ? (http error code 401). Clientform is still worth investigating - but if you want help on BASIC authentication then checkout http://www.voidspace.org.uk/python/articles/authentication.shtml Best Regards, Fuzzyman http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 304 "Controlling Generation of Bytecode Files" - patch updated
Skip> http://python.org/sf/677103 Thomas> There's no patch attached. *sigh* Thanks for noticing the problem. Apparently, since I last updated the patch, SF implemented a 250kbyte limit on file uploads. This one is big because it includes a suitably modified configure script that was generated with a slightly different version of autoconf than what's in the current Python distro so people don't need to have autoconf installed to work with the patch. I've attached a gzipped version of the patch (bcb.diffs.gz). Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Using httplib to read a file online
Why are you using httplib rather than urllib2 ? Best Regards, Fuzzy http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
On 17 Jun 2005 01:25:29 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >I don't think anything significant changed in the percentages. Then why starting from print "Hello world" that can't be explained (to say better it can't be *really* understood) without introducing a huge amount of magic and not from a simple 8 bit CPU instead ? What are the pluses of the start-from-high-level approach ? If one is to avoid bordeom I don't agree as assembler is all but boring (when you start), or at least this was what *I* experienced. If it's about the time it will take to get a rotating 3d torus with live video on it I know for sure that most of the programmers I know that started from high level will probably *never* reach that point. Surely if you start say from pull-down menus they'll be able to do pull down menus. And IMO there are good chances they'll stay there lifetime. So is python the good first programming language ? IMO not at all if you wanna become a programmer; it hides too much and that hidden stuff will bite back badly. Unless you know what is behind python it will be almost impossible for you to remember and avoid all the traps. Buf if you need to know what is behind it then it's better to learn that stuff first, because it's more concrete and simpler from a logical point of view; the constructions are complex but (because) the bricks are simpler. But it probably all boils down to what is a programmer. Is C++ a good first programming language ? BWHAHAHAHAHAHAHAHA :D But apparently some guru I greatly respect thinks so (I'm not kidding, http://www.spellen.org/youcandoit/). Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: strxfrm works with unicode string ?
Sali Nicolas :)), please see below for my answers. [EMAIL PROTECTED] schrieb: > Gruëzi, Gerald ;-) > > Well, ok, but I don't understand why I should first convert a pure > unicode string into a byte string. > The encoding ( here, latin-1) seems an arbitrary choice. Well "latin-1" is only encoding, about which I know that it works on my xterm and which I can type without spelling errors :) > > Your solution works, but is it a workaround or the real way to use > strxfrm ? > It seems a little artificial to me, but perhaps I haven't understood > something ... In Python 2.3.4 I had some strange encounters with the locale module, In the end I considered it broken, at least when it came to currency formating. > > Does this mean that you cannot pass a unicode string to strxfrm ? This works here for my home-grown python 2.4 on Jurrasic Debian Woody: import locale s=u'\u00e9' print s print locale.setlocale(locale.LC_ALL, '') print repr( locale.strxfrm( s.encode( "latin-1" ) ) ) print repr( locale.strxfrm( s.encode( "utf-8" ) ) ) The output is rather strange: é de_DE "\x10\x01\x05\x01\x02\x01'@/locale" "\x0c\x01\x0c\x01\x04\x01'@/locale" Another (not so) weird thing happens when I unset LANG. [EMAIL PROTECTED]:~ > unset LANG [EMAIL PROTECTED]:~ > python2.4 ttt.py Traceback (most recent call last): File "ttt.py", line 3, in ? print s UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128) Acually it's more weird, that printing works with LANG=de_DE. Back to your question. A quick glance at the C-sources of the _localemodule.c reveals: if (!PyArg_ParseTuple(args, "s:strxfrm", &s)) So yes, strxfrm does not accept unicode! I am inclined to consider this a bug. A least it is not consistent with strcoll. Strcoll accepts either 2 strings or 2 unicode strings, at least when HAVE_WCSCOLL was defined when python was compiled on your plattform. BTW: Which platform do you use? HTH, Gerald PS: If you have access to irc, you can also ask at irc://irc.freenode.net#python.de. -- GPG-Key: http://keyserver.veridis.com:11371/search?q=0xA140D634 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python & firewall control (Win32)
On Fri, 17 Jun 2005, Tim Williams wrote: > On Thu, 16 Jun 2005, Tom Anderson wrote: > > > On Thu, 16 Jun 2005, Tim Williams wrote: > > > > > Does anyone know of (personal/desktop) firewall that can be > > > controlled via Python > > > > http://wipfw.sourceforge.net/ > > Tom, many thanks for that. I'm actually looking for a firewall (packet > filter) I can control in realtime from a Python application, I think you should be able to do that with wipfw ... > or even a Win32 equivalent of http://woozle.org/~neale/src/ipqueue/ . ... but i'm not sure about that! However, i'm not any sort of firewall or network expert, so it's possible that ipfw has some way to call out to external code to get decisions made (a sort of packet version of procmail's filter system) and that i don't know about it. > Though if I can stop & restart ipfw in a fraction of a second from > within a Python app then the result would be the same I guess. I will > have a play with it. AIUI, you won't be stopping and restarting ipfw - the ipfw command just modifies the ruleset being used by a continuously-running instance of the ipfw kernel module or daemon or whatever. How long it takes from starting the os.system call to the changes taking effect in the firewall, though, i have no idea - it might not be fast enough for you. I'd be surprised if it was more than a few hundred milliseconds, though, and really ought to be much, much faster than that. tom -- so if you hear a chaffinch out on the pull attempting a severely off-key version of "Sabotage" by the Beastie Boys then you're not actually going mad. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
I fail to see the relationship between your reply and my original message. I was complaining about the illusion that in the old time people were more interested in programming than now. Instead your reply is about low level languages being more suitable for beginners than high level languages. I don't see the connection. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Python & firewall control (Win32)
- Original Message - From: "Tom Anderson" <[EMAIL PROTECTED]> > On Fri, 17 Jun 2005, Tim Williams wrote: > > > On Thu, 16 Jun 2005, Tom Anderson wrote: > > > > > On Thu, 16 Jun 2005, Tim Williams wrote: > > > > > > > Does anyone know of (personal/desktop) firewall that can be > > > > controlled via Python > > > > > > http://wipfw.sourceforge.net/ > > > > Tom, many thanks for that. I'm actually looking for a firewall (packet > > filter) I can control in realtime from a Python application, > > I think you should be able to do that with wipfw ... > > > or even a Win32 equivalent of http://woozle.org/~neale/src/ipqueue/ . > > but i'm not sure about that! However, i'm not any sort of firewall or > network expert, so it's possible that ipfw has some way to call out to > external code to get decisions made (a sort of packet version of > procmail's filter system) and that i don't know about it. > > > Though if I can stop & restart ipfw in a fraction of a second from > > within a Python app then the result would be the same I guess. I will > > have a play with it. > > AIUI, you won't be stopping and restarting ipfw - the ipfw command just > modifies the ruleset being used by a continuously-running instance of the > ipfw kernel module or daemon or whatever. How long it takes from starting > the os.system call to the changes taking effect in the firewall, though, i > have no idea - it might not be fast enough for you. I'd be surprised if it > was more than a few hundred milliseconds, though, and really ought to be > much, much faster than that. Thanks Tom Again, I will give it a go and post back with my findings -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree Namespace Prefixes
Jarek Zgoda wrote: [snip] >> It's a shame the default ns behavior in Elementtree is in such a poort >> staten. I'm surprised no one's forked Elementtree solely to fix this >> issue. > > There is at least one ElementTree API implementation that retains > prefixes, lxml.ETree. Go google for it. Just to make it explicitly clear, lxml is not a fork of ElementTree fork, but a reimplementation of the API on top of libxml2. ElementTree indeed retains prefixes, and since version 0.7 released earlier this way, it's also possible to get some control over generation of prefixes during element construction. You can find it here: http://codespeak.net/lxml Regards, Martijn -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
Andrea Griffini wrote: > Is C++ a good first programming language ? > > BWHAHAHAHAHAHAHAHA :D > > But apparently some guru I greatly respect thinks so > (I'm not kidding, http://www.spellen.org/youcandoit/). With respect to the author, and an understanding that there is probably much that didn't go into his self-description (add "about.htm" to the above URL), it sounds as though he knows primarily, perhaps solely, C and C++, and has done relatively little serious development since he seems to have spent most of his time either teaching or writing (words, not source code). Does he even *know* any real high level languages such as Python? And the fact that he's teaching C++ instead of just C seems to go against your own theories anyway... (though I realize you weren't necessarily putting him forth as a support for your position). -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound names in __del__
Torsten Bronger wrote: > However, all of this is not pretty pythonic in my opinion. Is it > that exotic to want to call functions from within __del__? Yes, I think it probably is. In the few hundred thousand lines of Python code I've played a role in developing, we've used __del__ once, to my knowledge, and I believe it was not a critical use, just an expedient one. And I don't recall the last time I saw a __del__ in third-party code I was examining. What's your use case for del? -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python Suitable for Large Find & Replace Operations?
On Fri, 2005-06-17 at 12:33 +1000, John Machin wrote: > OK then, let's ignore the fact that the data is in a collection of Word > & Excel files, and let's ignore the scale for the moment. Let's assume > there are only 100 very plain text files to process, and only 1000 SSNs > in your map, so it doesn't have to be very efficient. > > Can you please write a few lines of Python that would define your task > -- assume you have a line of text from an input file, show how you would > determine that it needed to be changed, and how you would change it. The script is too long to post in its entirety. In short, I open the files, do a binary read (in 1MB chunks for ease of memory usage) on them before placing that read into a variable and that in turn into a list that I then apply the following re to ss = re.compile(r'\b\d{3}-\d{2}-\d{4}\b') like this: for chunk in whole_file: search = ss.findall(chunk) if search: validate(search) The validate function makes sure the string found is indeed in the range of a legitimate SSN. You may read about this range here: http://www.ssa.gov/history/ssn/geocard.html That is as far as I have gotten. And I hope you can tell that I have placed some small amount of thought into the matter. I've tested the find a lot and it is rather accurate in finding SSNs in files. I have not yet started replacing anything. I've only posted here for advice before beginning. > > > > > > >>(4) Under what circumstances will it not be possible to replace *ALL* > >>the SSNs? > > > > > > I do not understand this question. > > Can you determine from the data, without reference to the map, that a > particular string of characters is an SSN? See above. > > If so, and it is not in the map, why can it not be *added* to the map > with a new generated ID? It is not my responsibility to do this. I do not have that authority within the organization. Have you never worked for a real-world business and dealt with office politics and territory ;) > >>And what is the source of the SSNs in this file??? Have they been > >>extracted from the data? How? > > > > > > That is irrelevant. > > Quite the contrary. If they had been extracted from the data, They have not. They are generated by a higher authority and then used by lower authorities such as me. Again though, I think this is irrelevant to the task at hand... I have a map, I have access to the data and that is all I need to have, no? I do appreciate your input though. If you would like to have a further exchange of ideas, perhaps we should do so off list? -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
>> there is a 1% of people extremely interested in turning >> on or off a pixel I taught "adults" aged from 16 to 86 for some years a course "Introduction to data processing", where I had tried to teach the basics beginning with switching light on and off. Having around twenty participants I experienced from time to time one or two who found it fascinating, so the 1% is in my eyes a good guess. > 40x50. Probably nowdays unless you show them an antialiased > texture mapped 3D floating torus with their name and > face on it in live video they'll prefer exchanging > stupid messages with the mobile phone instead. The ability of making a video (I currently experience a run towards "equipping" videos from camcorders showing the involved teenager fighting using ordinary sticks with StarWars laser sword effects) when equipped with appropriate software tool is given now even to the not gifted 99%. After the videos are done by the a little bit smarter ones of the entire group, it doesn't whetting the apetite for more programming skills - it creates traffic on ICQ and Internet by exchanging the videos and the opinions if they are cool or not. > If it's about the time it will take to get a rotating > 3d torus with live video on it I know for sure that most > of the programmers I know that started from high level > will probably *never* reach that point. Many consider such skills as not worth to achieve, looking for a solution to eventually raising problems in a better computer hardware and new software tools in case of timing problems. Generally it appears to me, that it is true that many of current teenagers look for authorities not for own experience (this is nothing new) and that they perceive the world around them through the window of the Internet browser not through the window of the room (this is what makes the difference compared to past time). But the current world they experience is so different from what it was twenty years ago, that it is today sure possible to start on a very high level and stay there all the life never beeing able to go down to the details without having therefore serious disadvantages as a programmer. I experienced beeing very surprised myself, that it is even possible to be hired as a programmer having an IQ below the level of around 80. I am personally biased towards trying to understand anything as deep as possible and in the past was quite certain, that one can not achieve good results without a deep insight into the underlying details. I have now to admit, that I was just wrong. From my overall experience I infer, that it is not only possible but has sometimes even better chances for success, because one is not overloaded with the ballast of deep understanding which can not only be useful but also hinder from fast progress. Claudio "Andrea Griffini" <[EMAIL PROTECTED]> schrieb im Newsbeitrag news:[EMAIL PROTECTED] > On 17 Jun 2005 01:25:29 -0700, "Michele Simionato" > <[EMAIL PROTECTED]> wrote: > > >I don't think anything significant changed in the percentages. > > Then why starting from > > print "Hello world" > > that can't be explained (to say better it can't be > *really* understood) without introducing a huge > amount of magic and not from a simple 8 bit CPU > instead ? What are the pluses of the start-from-high-level > approach ? If one is to avoid bordeom I don't agree > as assembler is all but boring (when you start), > or at least this was what *I* experienced. > > If it's about the time it will take to get a rotating > 3d torus with live video on it I know for sure that most > of the programmers I know that started from high level > will probably *never* reach that point. Surely if > you start say from pull-down menus they'll be able to > do pull down menus. And IMO there are good chances > they'll stay there lifetime. > > So is python the good first programming language ? > IMO not at all if you wanna become a programmer; it > hides too much and that hidden stuff will bite back > badly. Unless you know what is behind python it will > be almost impossible for you to remember and avoid > all the traps. Buf if you need to know what is behind > it then it's better to learn that stuff first, because > it's more concrete and simpler from a logical point > of view; the constructions are complex but (because) > the bricks are simpler. > > But it probably all boils down to what is a programmer. > > Is C++ a good first programming language ? > > BWHAHAHAHAHAHAHAHA :D > > But apparently some guru I greatly respect thinks so > (I'm not kidding, http://www.spellen.org/youcandoit/). > > Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: New WYSIWYG Python IDE in the works
Steve Holden wrote: > Cappy2112 wrote: > >> This is great, but it might be worth finding out what the other IDE's >> can do first, as well as their weaknesses. >> >> Eric3 seems to be the most popular & powerfull. Uop until recentluy, it >> onluy works on Linux, but has been compiled & runnin on Windows, to >> some degree of success. >> >> QTDesigner is pretty good. >> >> There's also Boa Constructor, and a handfull of other IDE's. >> > I's suggest the Boa Constructor be classed with [wx?]Glade and > PythonCard as GUI builders, though I must confess I am not fully up to > date on Boa developments. It is true that Boa has a heavy GUI development component but it is also analogous to PythonWin with the benefit that it works with Linux and has some other useful features. One minor weakness is that when debugging the interactive actions are not in the local context. Colin W. > > must-look-at-eric-sometime-ly y'rs - steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python Suitable for Large Find & Replace Operations?
rbt wrote: > The script is too long to post in its entirety. In short, I open the > files, do a binary read (in 1MB chunks for ease of memory usage) on them > before placing that read into a variable and that in turn into a list > that I then apply the following re to > > ss = re.compile(r'\b\d{3}-\d{2}-\d{4}\b') > > like this: > > for chunk in whole_file: > search = ss.findall(chunk) > if search: > validate(search) This seems so obvious that I hesitate to ask, but is the above really a simplification of the real code, which actually handles the case of SSNs that lie over the boundary between chunks? In other words, what happens if the first chunk has only the first four digits of the SSN, and the rest lies in the second chunk? -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: thread.start_new_thread question
On 6/17/05, Brian <[EMAIL PROTECTED]> wrote: > Hi KV, > > Here's a site that provides an easy, beginners example of how to do > threading. You might find this useful too... :-) > > http://www.codesampler.com/python.htm > (Look for the "Spawning Threads" section.) Thank you, but that doesn't answer my question. I was asking if there is a reason that "args" is not optional. Oftentimes functions I use to start_new_thread have no arguments (they may get data from bound instance or from closure), but still I have to pass empty "args", always wondering, why? Python lib generally has a very nice and convenient interface and tries to supply sensible defaults when possible. That "args" is a required argument is a mystery to me :) - kv A. No. Q. Is top posting OK? -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound names in __del__
Hallöchen! Peter Hansen <[EMAIL PROTECTED]> writes: > [...] > > What's your use case for del? Every instance represents a "session" to a measurement instrument. After the instance is deleted, the session should be closed to free resources. If the program exists, this is actually not necessary, because then all resources are freed anyway. __del__ is called nevertheless. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Back to the future - python to C++ advice wanted
During the last 18 months or so I have indulged in the joy of learning and using python for almost everything, but I may have to go back to C/C++ at work. Suddenly I found myself transliterating (or translating at least) common python idioms and patterns, looking for libraries to replace python's "included batteries" or writing my own from scratch, (over)using templates in an attempt to mimic duck typing, and so on. Still, I am not sure if this is a good idea in general since every language has its own idiosyncrasies, and this is obvious when one sees python code looking like C or Java. OTOH, bringing python's higher level of expressiveness to C/C++ might actually be a good thing, leading to cleaner, safer code. So, I wonder what have others who have gone the same path done and learned in similar situations. How one can avoid the frustration of having to work with a low level language once he has seen the Light ? George -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
Claudio Grondi: >I am personally biased towards trying to understand >anything as deep as possible and in the past was quite >certain, that one can not achieve good results >without a deep insight into the underlying details. >I have now to admit, that I was just wrong. From my >overall experience I infer, that it is not only possible >but has sometimes even better chances for success, >because one is not overloaded with the ballast of deep >understanding which can not only be useful but also >hinder from fast progress. FWIW, this is also my experience. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 and ftplib
"Richard Lewis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > On Thu, 16 Jun 2005 12:06:50 -0600, "John Roth" > <[EMAIL PROTECTED]> said: >> "Richard Lewis" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> > Hi there, >> > >> > I'm having a problem with unicode files and ftplib (using Python >> > 2.3.5). >> > >> > I've got this code: >> > >> > xml_source = codecs.open("foo.xml", 'w+b', "utf8") >> > #xml_source = file("foo.xml", 'w+b') >> > >> > ftp.retrbinary("RETR foo.xml", xml_source.write) >> > #ftp.retrlines("RETR foo.xml", xml_source.write) >> > >> >> It looks like there are at least two problems here. The major one >> is that you seem to have a misconception about utf-8 encoding. >> > Who doesn't? ;-) Lots of people. It's not difficult to understand, it just takes a bit of attention to the messy details. The basic concept is that Unicode is _always_ processed using a unicode string _in the program_. On disk or across the internet, it's _always_ stored in an encoded form, frequently but not always utf-8. A regular string _never_ stores raw unicode; it's always some encoding. When you read text data from the internet, it's _always_ in some encoding. If that encoding is one of the utf- encodings, it needs to be converted to unicode to be processed, but it does not need to be changed at all to write it to disk. >> Whatever program you are using to read it has to then decode >> it from utf-8 into unicode. Failure to do this is what is causing >> the extra characters on output. >> > >> >> Amusingly, this would have worked: >> >> xml_source = codecs.EncodedFile("foo.xml", "utf-8", "utf-8") >> >> It is, of course, an expensive way of doing nothing, but >> it at least has the virtue of being good documentation. >> > OK, I've fiddled around a bit more but I still haven't managed to get it > to work. I get the fact that its not the FTP operation thats causing the > problem so it must be either the xml.minidom.parse() function (and > whatever sort of file I give that) or the way that I write my results to > output files after I've done my DOM processing. I'll post some more > detailed code: Please post _all_ of the relevant code. It wastes people's time when you post incomplete examples. The critical issue is frequently in the part that you didn't post. > > def open_file(file_name): >ftp = ftplib.FTP(self.host) >ftp.login(self.login, self.passwd) > >content_file = file(file_name, 'w+b') >ftp.retrbinary("RETR " + self.path, content_file.write) >ftp.quit() >content_file.close() > >## Case 1: >#self.document = parse(file_name) > >## Case 2: >#self.document = parse(codecs.open(file_name, 'r+b', "utf-8")) > ># Case 3: >content_file = codecs.open(file_name, 'r', "utf-8") >self.document = parse(codecs.EncodedFile(content_file, "utf-8", >"utf-8")) >content_file.close() > > In Case1 I get the incorrectly encoded characters. > > In Case 2 I get the exception: > "UnicodeEncodeError: 'ascii' codec can't encode character u'\xe6' in > position 5208: ordinal not in range(128)" > when it calls the xml.minidom.parse() function. > > In Case 3 I get the exception: > "UnicodeEncodeError: 'ascii' codec can't encode character u'\xe6' in > position 5208: ordinal not in range(128)" > when it calls the xml.minidom.parse() function. That's exactly what you should expect. In the first case, the file on disk is encoded as utf-8, and this is aparently what mini-dom is expecting. The documentation shows a simple read, it does not show any kind of encoding or decoding. > Anyway, later on in the program I create a *very* large unicode string > after doing some playing with the DOM tree. I then write this to a file > using: > html_file = codecs.open(file_name, "w+b", "utf8") > html_file.write(very_large_unicode_string) > > The problem could be here? That should work. The problem, as I said in the first post, is that whatever program you are using to render the file to screen or print is _not_ treating the file as utf-8 encoded. It either needs to be told that the file is in utf-8 encoding, or you need to get a better rendering program. Many renderers, including most renderers inside of programming tools like file inspectors and debuggers, assume that the encoding is latin-1 or windows-1252. This will throw up funny characters if you try to read a utf-8 (or any multi-byte encoded) file using them. One trick that sometimes works is to insure that the first character is the BOM (byte order mark, or unicode signature). Properly written Windows programs will use this as an encoding signature. Unixoid programs frequently won't, but that's arguably a violation of the Unicode standard. This is a single unicode character which is three characters in utf-8 encoding. John Roth > > Cheers, > Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python Suitable for Large Find & Replace Operations?
On Fri, 2005-06-17 at 09:18 -0400, Peter Hansen wrote: > rbt wrote: > > The script is too long to post in its entirety. In short, I open the > > files, do a binary read (in 1MB chunks for ease of memory usage) on them > > before placing that read into a variable and that in turn into a list > > that I then apply the following re to > > > > ss = re.compile(r'\b\d{3}-\d{2}-\d{4}\b') > > > > like this: > > > > for chunk in whole_file: > > search = ss.findall(chunk) > > if search: > > validate(search) > > This seems so obvious that I hesitate to ask, but is the above really a > simplification of the real code, which actually handles the case of SSNs > that lie over the boundary between chunks? In other words, what happens > if the first chunk has only the first four digits of the SSN, and the > rest lies in the second chunk? > > -Peter No, that's a good question. As of now, there is nothing to handle the scenario that you bring up. I have considered this possibility (rare but possible). I have not written a solution for it. It's a very good point though. Is that not why proper software is engineered? Anyone can build a go cart (write a program), but it takes a team of engineers and much testing to build a car, no? Which woulu you rather be riding in during a crash? I wish upper mgt had a better understanding of this ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python & firewall control (Win32)
> - Original Message - > From: "Tom Anderson" <[EMAIL PROTECTED]> > > > > > AIUI, you won't be stopping and restarting ipfw - the ipfw command just > > modifies the ruleset being used by a continuously-running instance of the > > ipfw kernel module or daemon or whatever. How long it takes from starting > > the os.system call to the changes taking effect in the firewall, though, i > > have no idea - it might not be fast enough for you. I'd be surprised if it > > was more than a few hundred milliseconds, though, and really ought to be > > much, much faster than that. > > Thanks Tom Again, I will give it a go and post back with my findings re: http://wipfw.sourceforge.net/?page=home Tom, this looks good. I had it downloaded, installed and running some custom rules in under 5 minutes. Very simple and straightforward. > AIUI, you won't be stopping and restarting ipfw This is correct, the service doesn't appear to restart,the rule updates are actioned very quickly (instantaneous) I haven't had chance to try it integrated into a Python app, but it looks very promising,. Thanks again -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple instances of a python program
Daniel Dittmar wrote: > Rahul wrote: > > Hi. > > I am part of a group in my univ where we organize a programming > > contest. In this contest we have a UDP based server. The server > > simulates a game and each contestant is to develop a team of virtual > > players. Each team is composed of 75 similar bots...i.e. governed by > > the same logic. Thus the contestant submits a single copy of the client > > and we instantiate the same program 75 times at the same time. > > The problem is that while executables from C source files are small and > > we can make 75 processes but we dont know what to do with python. > > > > If you have a python script and you want that 75 copies of the script > > be run simultaneously how will you do it? Is there anyway to do so > > without running 75 copies of the python interpreter simultaneously? > > > > The technical way would be to use threads. > > Of course it could be that the rules of the game explicitly forbid that > bots of a group communicate other than through the server. And it is > easier to cheat there when you have only one Python program running. yup...its not allowed to communicate through other means. well we do realise that its not easy to catch cheating but we require the source code of the participants too. and we dont want to provide simple loopholes. rahul -- http://mail.python.org/mailman/listinfo/python-list
Re: How should threads be terminated? (related to 'Help with thread related tracebacks')
On Thu, 16 Jun 2005 16:20:23 -0400, Peter Hansen wrote: > Maxwell Hammer wrote: >> This is related to an earlier post 'Help with thread related >> tracebacks'...for which I have had no feedback yet :-( > > If the question was well formulated, and it's been more than a couple of > days, you should consider reposting. It's very unusual for a post with > such a subject (if it was a clear question) to get _no_ feedback around > here. Fair enough. The question is not expressed clearly for others. Do you have any suggestions as to how to describe the problem clearer? I can think of no other way but to say I have an app that when I terminate it, completes ok, However the last thing that happens before the shell prompt returns is that there is a traceback *within* python. (The actual post goes into more details of course.) I just took a guess that it is *thread* related from the output of the traceback. I'm still learning python, so how could one pose the problem *clearer*? And thanks for the feedback regarding threads, by the way. Max -- http://mail.python.org/mailman/listinfo/python-list
Embedding Python
Hi, Imagine that you have a PyObject pointer 'object' pointing to a Python integer ... let's say 42. How would do you attach the variable "answer" to it so that the code PyRun_SimpleString("print answer"); works as expected ? My current solution is: __main__ = PyImport_ImportModule("__main__"); PyObject_SetAttrString(__main__, "answer", object); Anything better ? SB -- http://mail.python.org/mailman/listinfo/python-list
Re: How should threads be terminated? (related to 'Help with thread related tracebacks')
Thanks Brian & Martin for the links. I actually found another good one: http://linuxgazette.net/107/pai.html Cheers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Back to the future - python to C++ advice wanted
George Sakkis wrote: > During the last 18 months or so I have indulged in the joy of learning > and using python for almost everything, but I may have to go back to > C/C++ at work. (snip) > So, I wonder what have others who have gone the same path done and > learned in similar situations. How one can avoid the frustration of > having to work with a low level language once he has seen the Light ? > Well, I'm lucky enough to not to have to use C++ again, so I can't answer directly. But I think this might interest you: http://www.boost.org/ (NB : never tried it myself, but seems to be a nice job) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Help implementing an idea
Well, I'm a total python n00b, but I was playing around with exception handling yesterday, and was stricken by how incredibly easy it is to use the op system to create nice scripts... I did the following: import sys lines = sys.stdin.readlines() lines.sort() for stuff in lines: print stuff , just to copy stuff from one file to another, and was quite impressed with the results. Now, I was thinking today, I'd really like to create a program that can go to a specific directory and upload all the files in the directory to a specific url for backup purposes, and I have the feeling that the python implementation would be ruthlessly small and efficient, like the aboveanyone who could point me in the right direction as to how to actually do it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Dealing with marketing types...
In article <[EMAIL PROTECTED]>, Kay Schluehr <[EMAIL PROTECTED]> wrote: >Sorry, Cameron, if I twist meanings. > >Thomas argues that Python programmers are more expensive than Java >ones. But if one needs more Java programmers to fit into the project >plan one needs probably more managenment/admistration staff ( ~ ratio = >1/3) >and managers are usually more expensive than programmers. > >I concede that this is hard to measure but for a similar issue one >should remember that the OPs project did not incorporate the role of a >"software architect" up to now - it did not have to be reified. > >Kay > No apologies, please. You're making perfect sense, and I have no argument with what you write here. The density of pronouns earlier in the thread passed my threshold, and I simply overflowed. Thanks for the clarification. -- http://mail.python.org/mailman/listinfo/python-list
Overcoming herpetophobia (or what's up w/ Python scopes)?
I'm a Perlhead (there, I said it). Years ago I made a genuine attempt to learn Python, but my intense disappointed with the way Python deals with scopes ultimately sapped my enthusiasm. I couldn't live without closures and without the fine control over scopes that Perl provides. I've been wanting to make another attempt to (re)learn Python for a while, but this scopes business remained a major damper. What's pushing me over my reluctance is having to work with a large in-house package developed in Python. I am hoping that it may be better this time around. For one thing, like Perl, Python was then (and maybe still is) a "work in progress." So I figure that Python scoping may have improved since then. Even if not, I think that Python is mature enough by now that adequate alternatives must have been devised for the Perlish features that I missed during my first attempt. My question is: is there any tutorial on Python scoping aimed at diehard Perlheads? Thanks! kj -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list
Re: UML to Python/Java code generation
"Grigoris Tsolakidis" <[EMAIL PROTECTED]> writes: > There is tool to generate UML from Python Code... The best is human brain. -- http://mail.python.org/mailman/listinfo/python-list
RE: Overcoming herpetophobia (or what's up w/ Python scopes)?
I am very familiar with Python, but I don't know Pearl. In order to answer your question, you will have to tell me about your statement, "I couldn't live without closures and without the fine control over scopes that Pearl provides." I don't know what these things are to Pearl. If you tell me what these features are in Pearl and what you use them for, I can tell you if Python has them as well. Chad -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of kj Sent: Friday, June 17, 2005 9:20 AM To: python-list@python.org Subject: Overcoming herpetophobia (or what's up w/ Python scopes)? I'm a Perlhead (there, I said it). Years ago I made a genuine attempt to learn Python, but my intense disappointed with the way Python deals with scopes ultimately sapped my enthusiasm. I couldn't live without closures and without the fine control over scopes that Perl provides. I've been wanting to make another attempt to (re)learn Python for a while, but this scopes business remained a major damper. What's pushing me over my reluctance is having to work with a large in-house package developed in Python. I am hoping that it may be better this time around. For one thing, like Perl, Python was then (and maybe still is) a "work in progress." So I figure that Python scoping may have improved since then. Even if not, I think that Python is mature enough by now that adequate alternatives must have been devised for the Perlish features that I missed during my first attempt. My question is: is there any tutorial on Python scoping aimed at diehard Perlheads? Thanks! kj -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple instances of a python program
On Thu, 16 Jun 2005 11:47:10 -0700, Rahul wrote: > Hi. > I am part of a group in my univ where we organize a programming > contest. In this contest we have a UDP based server. The server > simulates a game and each contestant is to develop a team of virtual > players. Each team is composed of 75 similar bots...i.e. governed by > the same logic. Thus the contestant submits a single copy of the client > and we instantiate the same program 75 times at the same time. > The problem is that while executables from C source files are small and > we can make 75 processes but we dont know what to do with python. > > If you have a python script and you want that 75 copies of the script > be run simultaneously how will you do it? Is there anyway to do so > without running 75 copies of the python interpreter simultaneously? Have you actually tested the performance of 75 instances of Python running? Do you know that it will be too slow for your server, or are you trying to optimize before testing? I wrote a short Python script, then launched 115 instances of Python executing the script. There was no detectable slowdown of my system, which is far from a high-end PC. The details of the script aren't important. It may even be that what I tested is not even close to the load your server needs to deal with. But you may be surprised at just how easily even a low-end PC copes 75 instances of Python. Or perhaps not -- but the only way to tell is to try. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple instances of a python program
On Thu, 16 Jun 2005 11:47:10 -0700, Rahul wrote: > If you have a python script and you want that 75 copies of the script be > run simultaneously how will you do it? Is there anyway to do so without > running 75 copies of the python interpreter simultaneously? If you're running on Linux (and other Unixes perhaps), you could use the os.fork() function to create independent child processes from a single python process. I believe Linux forked processes share memory until a section of memory is written to (copy on write functionality). If most of python is in a shared library, then this probably won't make much difference. Jeremy -- http://mail.python.org/mailman/listinfo/python-list
RE: Overcoming herpetophobia (or what's up w/ Python scopes)?
On Fri, 17 Jun 2005 09:36:55 -0700, Hughes, Chad O wrote: > I am very familiar with Python, but I don't know Pearl. The language is *always* spelt without the "a", and usually all in lower-case: perl. Now that I've taught you everything I know about perl, you can be an expert like me -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Overcoming herpetophobia (or what's up w/ Python scopes)?
kj wrote: > I'm a Perlhead (there, I said it). Years ago I made a genuine > attempt to learn Python, but my intense disappointed with the way > Python deals with scopes ultimately sapped my enthusiasm. I couldn't > live without closures and without the fine control over scopes that > Perl provides. Python has supported nested (lexical) scopes and closures since version 2.1, maybe this gives you enough control; see http://www.amk.ca/python/2.1/index.html#SECTION00030 Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Back to the future - python to C++ advice wanted
In article <[EMAIL PROTECTED]>, bruno modulix <[EMAIL PROTECTED]> wrote: >George Sakkis wrote: . . . >> learned in similar situations. How one can avoid the frustration of >> having to work with a low level language once he has seen the Light ? >> >Well, I'm lucky enough to not to have to use C++ again, so I can't >answer directly. But I think this might interest you: >http://www.boost.org/ >(NB : never tried it myself, but seems to be a nice job) . . . That's one approach. Here's another: read Scott Meyer's latest *Effective C++*, follow his advice, and become familiar with idioms (and libraries, to the extent they're available!) that make C++ a rather high-level language. -- http://mail.python.org/mailman/listinfo/python-list
pysqlite - Checking the existance of a table
Hi all, I am starting to play with pysqlite, and would like to know if there is a function to determine if a table exists or not. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Programmatically bring a window to front
Hi, I wonder if anyone knows how to programmatically make a python window get focus and bring it to front. Here a python window means the Tkinter Toplevel widget. Thanks. Zhen -- http://mail.python.org/mailman/listinfo/python-list
RE: Overcoming herpetophobia (or what's up w/ Python scopes)?
Are you sure about the lower-case thing. The original post states "Perlhead" and there are many instances at www.Perl.com where O'REILLY spells perl as Perl. Chad -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steven D'Aprano Sent: Friday, June 17, 2005 10:02 AM To: python-list@python.org Subject: RE: Overcoming herpetophobia (or what's up w/ Python scopes)? On Fri, 17 Jun 2005 09:36:55 -0700, Hughes, Chad O wrote: > I am very familiar with Python, but I don't know Pearl. The language is *always* spelt without the "a", and usually all in lower-case: perl. Now that I've taught you everything I know about perl, you can be an expert like me -- Steven -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Help implementing an idea
Take a look at: http://dirssync.sourceforge.net/ See if that gives you any direction. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help implementing an idea
Try this.. #!/usr/bin/env python # Upload a file to a FTP server from sys import argv, exit from ftplib import FTP if len(argv) != 6: print 'Incorrect number of parameters' print 'USAGE: upload.py ' exit(0) server = argv[1] username = argv[2] password = argv[3] upfile = argv[5] downfile = argv[4] try: print 'Connecting to %s' % server ftp = FTP(server) ftp.login(username, password) print 'Connection to %s opened' % server #send file in binary mode to server (STOR command sets remote filename) ftp.storbinary('STOR %s' % upfile, open(downfile,'r')) ftp.quit() print 'File %s uploaded' % upfile except Exception, err: print 'Error uploading file. Error: %s' % err -- http://mail.python.org/mailman/listinfo/python-list
RE: Overcoming herpetophobia (or what's up w/ Python scopes)?
On Fri, 17 Jun 2005 10:22:05 -0700, Hughes, Chad O wrote: > Are you sure about the lower-case thing. The original post states > "Perlhead" and there are many instances at www.Perl.com where O'REILLY > spells perl as Perl. I did say "usually" :-) But in fact it seems that the creator of Perl/perl, Larry Wall, now distinguishes between the two spellings. From the FAQs: Q: What's the difference between "perl" and "Perl"? A: One bit. Oh, you weren't talking ASCII? :-) Larry now uses "Perl" to signify the language proper and "perl" the implementation of it, i.e. the current interpreter. Hence Tom's quip that "Nothing but perl can parse Perl." You may or may not choose to follow this usage. For example, parallelism means "awk and perl" and "Python and Perl" look OK, while "awk and Perl" and "Python and perl" do not. But never write "PERL", because perl is not an acronym, apocryphal folklore and post-facto expansions notwithstanding. http://faq.perl.org/perlfaq1.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: whos -- a function listing objects
[EMAIL PROTECTED] wrote: > I have been a long time Matlab user. I Python, I miss Matlab's whos > command. you might want to look at ipython. whos, and a bit more come for free: planck[~]> ipython -pylab Python 2.3.4 (#1, Feb 2 2005, 12:11:53) Type "copyright", "credits" or "license" for more information. IPython 0.6.16_cvs -- An enhanced Interactive Python. ? -> Introduction to IPython's features. %magic -> Information about IPython's 'magic' % functions. help-> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. Welcome to pylab, a matplotlib-based Python environment. For more information, type 'help(pylab)'. In [1]: def foo(): pass ...: In [2]: a=rand(128,128) In [3]: x=3.14 In [4]: import code In [5]: whos Variable TypeData/Info a array 128x128: 16384 elems, type `d`, 131072 bytes (128 kb) code module /lib/python2.3/code.pyc'> foofunction x float 3.14 In [6]: whos array Variable Type Data/Info - a array128x128: 16384 elems, type `d`, 131072 bytes (128 kb) In [7]: whos function Variable TypeData/Info foofunction Cheers, f -- http://mail.python.org/mailman/listinfo/python-list
RE: Overcoming herpetophobia (or what's up w/ Python scopes)?
Thanks, I will keep that in mind. Chad -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steven D'Aprano Sent: Friday, June 17, 2005 11:06 AM To: python-list@python.org Subject: RE: Overcoming herpetophobia (or what's up w/ Python scopes)? On Fri, 17 Jun 2005 10:22:05 -0700, Hughes, Chad O wrote: > Are you sure about the lower-case thing. The original post states > "Perlhead" and there are many instances at www.Perl.com where O'REILLY > spells perl as Perl. I did say "usually" :-) But in fact it seems that the creator of Perl/perl, Larry Wall, now distinguishes between the two spellings. From the FAQs: Q: What's the difference between "perl" and "Perl"? A: One bit. Oh, you weren't talking ASCII? :-) Larry now uses "Perl" to signify the language proper and "perl" the implementation of it, i.e. the current interpreter. Hence Tom's quip that "Nothing but perl can parse Perl." You may or may not choose to follow this usage. For example, parallelism means "awk and perl" and "Python and Perl" look OK, while "awk and Perl" and "Python and perl" do not. But never write "PERL", because perl is not an acronym, apocryphal folklore and post-facto expansions notwithstanding. http://faq.perl.org/perlfaq1.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Overcoming herpetophobia (or what's up w/ Python scopes)?
This link seems to be about Closures in Python, but I am not feeling sharp enough at the moment to evaluate the correctness of the discussion. http://en.wikipedia.org/wiki/Python_programming_language#Closures As others have said, you might get more useful responses if you can elaborate upon what exactly you worry are shortcomings of Python compared to Perl. -- http://mail.python.org/mailman/listinfo/python-list
Shortcut to initialize variables
Newb here... For one of my programs I want to initialize a variable for each letter of the alphabet. For example, a,b,c = 0,0,0. I don't think this works, but I'm wondering if I can do something similar to this: from string import ascii_lowercase class Blah: def __init__(self): for letter in ascii_lowercase: setattr(self,letter,0) Is there a way I can do something like this without using classes? Thanks -- http://mail.python.org/mailman/listinfo/python-list
how to operate the excel by python?
Question please: In the post, "How to operate the excel by python," where did you find the codes for HorizontalAlignment and VerticalAlignment (Center = -4108 and Bottom = -4107)? I need the code for HorizontalAlignment = xlRight. Is there a table somewhere that shows these codes? Thanks kevin.coffey at ism-corp.us -- http://mail.python.org/mailman/listinfo/python-list
add new modules?
This is a total newb question, you have been warned... I've been all over the www.python.org site and googled, but I've not found just how to add new modules. I've tried setting PYTHONPATH, I've tried putting the new module directories into the site-packages directory, I've tried creating the .pth files, I've even done all three of these things at the same time and still my python script refuses to import. What is the cannonical way to add new modules to python? I am running on OS X 10.4 (Macintosh obviously) on basically freeBSD, os I'm doing UNIX type stuff at the console. thanks for any help, DLC -- * Dennis Clark [EMAIL PROTECTED]www.techtoystoday.com * * "Programming and Customizing the OOPic Microcontroller" Mcgraw-Hill 2003 * -- http://mail.python.org/mailman/listinfo/python-list
Re: Shortcut to initialize variables
Andrew wrote: > Newb here... For one of my programs I want to initialize a variable for > each letter of the alphabet. For example, a,b,c = 0,0,0. I don't think > this works, but I'm wondering if I can do something similar to this: > > from string import ascii_lowercase > > class Blah: > def __init__(self): > for letter in ascii_lowercase: > setattr(self,letter,0) > > Is there a way I can do something like this without using classes? This is a very common request on this list. The usual advice is to use a dictionary rather than defining variables, e.g. letters = {} for letter in ascii_lowercase: letters[letter] = 0 But I'm becoming curious about why this is so commonly requested. What is your background that you (and others) would think of this as a solution? Is there a language where it is easy to do this sort of thing, and where the resulting variables are easily used? Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list
RE: how to operate the excel by python?
Title: Message I have posed a more complete answer to your question, however, it is quite a large and It is awaiting approval. For now, xlRight = -4152. You can find this out by opening up Excel and typing the ALT-F11 combination. From there use the ObjectBrowser. For example if you type in the word "xlRight" you will see that it is equal to -4152. Chad -Original Message-From: Kevin P. Coffey [mailto:[EMAIL PROTECTED] Sent: Friday, June 17, 2005 11:28 AMTo: python-list@python.orgSubject: how to operate the excel by python? Question please: In the post, "How to operate the excel by python," where did you find the codes for HorizontalAlignment and VerticalAlignment (Center = -4108 and Bottom = -4107)? I need the code for HorizontalAlignment = xlRight. Is there a table somewhere that shows these codes? Thanks kevin.coffey at ism-corp.us -- http://mail.python.org/mailman/listinfo/python-list
Re: add new modules?
Dennis Clark wrote: > This is a total newb question, you have been warned... > > I've been all over the www.python.org site and googled, but I've not > found just how to add new modules. I've tried setting PYTHONPATH, > I've tried putting the new module directories into the site-packages > directory, I've tried creating the .pth files, I've even done all > three of these things at the same time and still my python script > refuses to import. What is the cannonical way to add new modules > to python? I am running on OS X 10.4 (Macintosh obviously) on basically > freeBSD, os I'm doing UNIX type stuff at the console. If you have a single file that you want to make available, put it directly in site-packages. For example put mymodule.py in site-packages, then in code you can say from mymodule import MyClass If you have a directory of files that you consider related, that is a package. Put the directory in site-packages, add a file named __init__.py to the directory, and import qualified with the directory name. For example if you have site-packages/ mystuff/ __init__.py mymodule.py then in code you say from mystuff.mymodule import MyClass where in both cases MyClass is defined in mymodule.py. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Shortcut to initialize variables
Andrew wrote: > Newb here... For one of my programs I want to initialize a variable for > each letter of the alphabet. For example, a,b,c = 0,0,0. Why do you want to do this? This looks like a particularly bad idea to me. Can't you just use a dict of the "variables", e.g.: py> d = dict.fromkeys(string.ascii_lowercase, 0) py> d['a'] 0 py> d['x'] 0 py> d['q'] 0 If you insist on updating the module globals, you can do something like: py> globals().update(dict.fromkeys(string.ascii_lowercase, 0)) py> a 0 py> x 0 py> q 0 but I find that just about every use of globals() has a bad code smell. STeVe -- http://mail.python.org/mailman/listinfo/python-list
smtplib and TLS
Hi! After getting a @gmail.com address, I recognized I had to use TLS in my python scripts using smtplib in order to get mail to the smtp.gmail.com server. Things work well so far, apart from an unexpected error. Here's my sample code: import smtplib server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.ehlo() server.login('[EMAIL PROTECTED]', password) server.sendmail("[EMAIL PROTECTED]", toaddress, message) server.quit() The server accepts and delivers my messages, but the last command raises socket.sslerror: (8, 'EOF occurred in violation of protocol') Did I miss something? Any hint is welcome. Regards, Matthias -- http://mail.python.org/mailman/listinfo/python-list
Re: add new modules?
Dennis Clark wrote: > This is a total newb question, you have been warned... > > I've been all over the www.python.org site and googled, but I've not > found just how to add new modules. I've tried setting PYTHONPATH, > I've tried putting the new module directories into the site-packages > directory, I've tried creating the .pth files, I've even done all > three of these things at the same time and still my python script > refuses to import. What is the cannonical way to add new modules > to python? I am running on OS X 10.4 (Macintosh obviously) on basically > freeBSD, os I'm doing UNIX type stuff at the console. If you are using the Apple-supplied Python 2.3.5, put the modules in /Library/Python/2.3/site-packages/ . If you are using Bob Ippolito's Python 2.4.1, then it's /Library/Frameworks/Python.framework/Versions/Current/lib/python2.4/site-packages . -- 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
Re: Shortcut to initialize variables
Oops, I probably should have tried searching the list first. My background is strictly academic. I was switching languages so often I never got really familiar with any of them. Maybe C for a while, but I've forgotten alot. I'm hoping python will be the last language I ever need. :) I don't know why I didn't turn to dictionaries first. It does seem to be the obvious solution. I'm writing a program that will take substitution and transposition cipher texts and spit out plain text with no human input. So I suppose I'll have dictionaries of digraphs and trigraphs too; for frequency analysis. Do you think this is to heavy of a project to learn the language? Thanks for the quick feedback -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite - Checking the existance of a table
Simply use the internal table SQLite_Master: select name from SQLite_Master will return all existing tables. Regards, Matthias -- http://mail.python.org/mailman/listinfo/python-list
Please help me understand this code....
Hello, I am a programmer, but not a python guy. So I am a little confused with the following python code. Specifically what does the ":" do in the array arithmetic? new_page = map[opage] old_page = map[opage^1] center = new_page[1:-1,1:-1] origcenter = array(center) center[:] = old_page[2:,2:] center += old_page[1:-1,2:] center += old_page[:-2,2:] center += old_page[2:,1:-1] center += old_page[:-2,1:-1] center += old_page[2:,:-2] center += old_page[1:-1,:-2] center += old_page[:-2,:-2] center >>= 2 center -= origcenter center -= (center>>density) Thanks!! Randy -- http://mail.python.org/mailman/listinfo/python-list
Re: add new modules?
Thanks all, My problem came when I set PYTHONHOME, apparently that is a bad thing (in this case). I know that I set it to the directory that python was in, but something about that was "bad". now everything works. DLC Robert Kern <[EMAIL PROTECTED]> wrote: : Dennis Clark wrote: : > This is a total newb question, you have been warned... : > : > I've been all over the www.python.org site and googled, but I've not : > found just how to add new modules. I've tried setting PYTHONPATH, : > I've tried putting the new module directories into the site-packages : > directory, I've tried creating the .pth files, I've even done all : > three of these things at the same time and still my python script : > refuses to import. What is the cannonical way to add new modules : > to python? I am running on OS X 10.4 (Macintosh obviously) on basically : > freeBSD, os I'm doing UNIX type stuff at the console. : If you are using the Apple-supplied Python 2.3.5, put the modules in : /Library/Python/2.3/site-packages/ . If you are using Bob Ippolito's : Python 2.4.1, then it's : /Library/Frameworks/Python.framework/Versions/Current/lib/python2.4/site-packages : . : -- : Robert Kern : [EMAIL PROTECTED] : "In the fields of hell where the grass grows high : Are the graves of dreams allowed to die." :-- Richard Harter -- * Dennis Clark [EMAIL PROTECTED]www.techtoystoday.com * * "Programming and Customizing the OOPic Microcontroller" Mcgraw-Hill 2003 * -- http://mail.python.org/mailman/listinfo/python-list
Re: smtplib and TLS
"Matthias Kluwe" <[EMAIL PROTECTED]> writes: > The server accepts and delivers my messages, but the last command > raises > > socket.sslerror: (8, 'EOF occurred in violation of protocol') > > Did I miss something? Any hint is welcome. Looks like the module didn't send an TLS Close Notify message before closing the socket. I don't see anything in the docs about how to send one from smtplib or socket, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: case/switch statement?
Peter Hansen wrote: > D H wrote: > >> Peter Hansen wrote: >> >>> With a case statement, on the other hand, you *know* that it must be >>> just simple conditionals (a series of x == some_constant tests), so >>> you don't need to look at all the cases, just the one that interests >>> you. >> >> >> Since you and Steve Holden agree that a case statement is useful, why >> don't you propose it for python, or add it to the wiki page for Python >> 3000. > > > Two simple reasons. > > 1. You forgot my previous comment that "in current Python the equivalent > approach is, of course, a dictionary of some kind, though it's arguable > whether this is as clean in many cases as a case statement would be." I didn't forget that. I never read it, and I don't see the relevance to my suggestion. Now that I've read it, I would hardly call using a dictionary as a switch statement, the "equivalent". The fact that people use a dictionary as a conditional is a python wart. > 2. Just because something is "useful" doesn't mean it should be added to > Python. The bar should be set much higher, and should include at least > "and significantly better than any existing alternative way of doing the > same thing." Now go read point 1 again... ;-) Now go read my message again. I made a suggestion to you. I didn't say that a switch statement should be added myself. I would never propose that because the chances of it being added are microscopic. > My point was not to suggest that I want a case statement in Python, nor Neither was the MY point, which you seem to have inferred. > even that a case statement is a good thing to have in a language (though > it might be... it's not my place to say). My point was simply to point > out that performance is not the only reason to use a case statement. I don't think you could have misread my simple suggestion to you any more completely than you did. -- http://mail.python.org/mailman/listinfo/python-list
Re: Back to the future - python to C++ advice wanted
On 2005-06-17, George Sakkis <[EMAIL PROTECTED]> wrote: > So, I wonder what have others who have gone the same path done and > learned in similar situations. How one can avoid the frustration of > having to work with a low level language once he has seen the Light ? This project: http://astrolabe.sourceforge.net/ ...is implemented in both Python and C++. I do the Python version first and then translate to C++ as directly as possible, using namespaces, exception handling, the standard string type and STL library. Let me second the recommendation of the Scott Meyers books. And another which I no longer have -- something like "The C++ Memory Model" -- was very instructive. -Bill -- Sattre PressIn the Quarter http://sattre-press.com/ by Robert W. Chambers [EMAIL PROTECTED] http://sattre-press.com/itq.html -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
Peter Hansen wrote: >> But apparently some guru I greatly respect thinks so >> (I'm not kidding, http://www.spellen.org/youcandoit/). > > > With respect to the author, and an understanding that there is probably > much that didn't go into his self-description (add "about.htm" to the > above URL), it sounds as though he knows primarily, perhaps solely, C > and C++, and has done relatively little serious development since he > seems to have spent most of his time either teaching or writing (words, > not source code). > > Does he even *know* any real high level languages such as Python? So you say he "has done relatively little serious development" and that he may not even know about Python. I didn't see any evidence from those pages to draw either conclusion. In fact the 4th paragraph quite contradicts them both. -- http://mail.python.org/mailman/listinfo/python-list
ANN: IssueTrackerProduct 0.6.9 with AJAX and Reports
(I don't know if this is the right place to make an announcement but I've seen other projects doing it so I thought why not?) I've now released version 0.6.9 of the IssueTrackerProduct http://www.issuetrackerproduct.com/News/0.6.9 It's a issue/bug tracker built on top of Zope (Python) that is known for being simple but powerful. Homepage: www.issuetrackerproduct.com -- http://mail.python.org/mailman/listinfo/python-list
Re: whos -- a function listing objects
whos.py as a module would not work for global scope, as it hides the function whos in the module scope. I have fixed the string bug. -- http://mail.python.org/mailman/listinfo/python-list
Re: Back to the future - python to C++ advice wanted
George Sakkis wrote: > During the last 18 months or so I have indulged in the joy of learning > and using python for almost everything, but I may have to go back to > C/C++ at work. Suddenly I found myself transliterating (or translating > at least) common python idioms and patterns, looking for libraries to > replace python's "included batteries" or writing my own from scratch, > (over)using templates in an attempt to mimic duck typing, and so on. > Still, I am not sure if this is a good idea in general since every > language has its own idiosyncrasies, and this is obvious when one sees > python code looking like C or Java. OTOH, bringing python's higher > level of expressiveness to C/C++ might actually be a good thing, > leading to cleaner, safer code. > > So, I wonder what have others who have gone the same path done and > learned in similar situations. How one can avoid the frustration of > having to work with a low level language once he has seen the Light ? That's why so many people have switched to Java or C# (or Python and other langugages of course). You might talk to them about using Python, since Python and C/C++ fit together very nicely (with tools like BOOST, SWIG, Pyrex,...). But me personally I like to avoid C++ altogether when possible, and use Java or C# instead, both of which also can be combined with python or python-like languages such as jython, groovy, or boo. -- http://mail.python.org/mailman/listinfo/python-list
Why is there no instancemethod builtin?
Why hello there ha ha. I have got in the habit of testing the types of variables with isinstance and the builtin type names instead of using the types module, as was the style back around Python 2.1. That is, rather than if type(x) == types.ListType: I now do: if isinstance(x, list): It is my understanding that this is what people do nowadays. One problem I have, though, is that not all type names are available as builtins. Just looking through the types declared in types, the following are builtins: bool, buffer, complex, dict, file, float, list, long, object, slice, str, tuple, type, unicode, xrange, NoneType, NotImplementedType And the following are not: dictproxy, ellipsis, frame, function, instancemethod, module, traceback, instancemethod, NoneType, NotImplementedType So for any in the latter batch, I have to import types after all. I assume the dividing line is whether the name is useful as a constructor. Still, I feel there's some inconsistencies in the usefulness of the new type system. Why do str and unicode derive from basestring, while list and tuple are independent types? list and tuple support most of the same operations... it seems like either they should also have an abstract base class or str and unicode shouldn't, because duck typing doesn't really require that. It also seems like types may be on the way out, because I don't see constants for set or frozenset. I'm not sure I have a question here, just pointing out what I see as some flaws in the new type system. -- http://mail.python.org/mailman/listinfo/python-list
Re: whos -- a function listing objects
That is nice. I didn't know iPython can do whos. Will try it. iPython seems to infinitely configurable. Hope it will not suck too much of my time into it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python
Sébastien Boisgérault wrote: > Hi, > > Imagine that you have a PyObject pointer 'object' > pointing to a Python integer ... let's say 42. > > How would do you attach the variable "answer" to > it so that the code > > PyRun_SimpleString("print answer"); > > works as expected ? > > My current solution is: > > __main__ = PyImport_ImportModule("__main__"); > PyObject_SetAttrString(__main__, "answer", object); > > Anything better ? You could use PyRun_String instead, which lets you pass global and local dictionaries as context. That may provide more fine-grained control, depending on what you want. Regards, Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple instances of a python program
Hi. I will look into it..thanks rahul Jeremy Sanders wrote: > On Thu, 16 Jun 2005 11:47:10 -0700, Rahul wrote: > > > If you have a python script and you want that 75 copies of the script be > > run simultaneously how will you do it? Is there anyway to do so without > > running 75 copies of the python interpreter simultaneously? > > If you're running on Linux (and other Unixes perhaps), you could use the > os.fork() function to create independent child processes from a single > python process. I believe Linux forked processes share memory until a > section of memory is written to (copy on write functionality). > > If most of python is in a shared library, then this probably won't make > much difference. > > Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help me understand this code....
The : is used in Python for slice notation, which is explained pretty thoroughly in the Python tutorial, specifically at: http://www.python.org/doc/2.4/tut/node5.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple instances of a python program
Steven D'Aprano wrote: > On Thu, 16 Jun 2005 11:47:10 -0700, Rahul wrote: > > > Hi. > > I am part of a group in my univ where we organize a programming > > contest. In this contest we have a UDP based server. The server > > simulates a game and each contestant is to develop a team of virtual > > players. Each team is composed of 75 similar bots...i.e. governed by > > the same logic. Thus the contestant submits a single copy of the client > > and we instantiate the same program 75 times at the same time. > > The problem is that while executables from C source files are small and > > we can make 75 processes but we dont know what to do with python. > > > > If you have a python script and you want that 75 copies of the script > > be run simultaneously how will you do it? Is there anyway to do so > > without running 75 copies of the python interpreter simultaneously? > > Have you actually tested the performance of 75 instances of Python > running? Do you know that it will be too slow for your server, or are you > trying to optimize before testing? > > I wrote a short Python script, then launched 115 instances of Python > executing the script. There was no detectable slowdown of my system, which > is far from a high-end PC. > > The details of the script aren't important. It may even be that what I > tested is not even close to the load your server needs to deal with. But > you may be surprised at just how easily even a low-end PC copes 75 > instances of Python. Or perhaps not -- but the only way to tell is to try. Well...i havent tried (yes i hear "Premature optimization is evil evil evil i say") but the point was that if we can find a solution consuming less memory than we can even increase the number from 75 to lets say 200. as for hardware we have machines with 1.7 Ghz P4 and 128 mb ram. and i cant run them right now...since i am currently not in my univ...but asked now since we are planning right now and wanted to see which languages we can support. Probably c,c++,python and lisp using clisp...and java if we can find a way to avoid running 75 jvms...this year we supported c,c++,java and actually ran 75 jvms using 3 machines and it was horrible so we are looking for better ways for the 2006 contest. And we may port our server from java to python too but it seems not many people had python installed but most had java installed. rahul -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
On 17 Jun 2005 05:30:25 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >I fail to see the relationship between your reply and my original >message. >I was complaining about the illusion that in the old time people were >more >interested in programming than now. Instead your reply is about low >level >languages being more suitable for beginners than high level languages. >I don't see the connection. I've been told in the past that one reason for which is good to start from high-level languages is that you can do more with less. In other words I've been told that showing a nice image and may be some music is more interesting than just making a led blinking. But if this is not the case (because just 1% is interested in those things no matter what) then why starting from high level first then ? I would say (indeed I would *hope*) that 1% is a low estimate, but probably I'm wrong as others with more experience than me in teaching agree with you. Having more experience than me in teaching programming is a very easy shot... I never taught anyone excluding myself. About the 1%, I've two brothers, and one of them got hooked to programming before me... the other never got interested in computers and now he's just a basic (no macros) ms office user. So in my case it was about 66%, and all started with a programmable pocket RPN calculator ... but there were no teachers involved; may be this is a big difference. Andrea -- http://mail.python.org/mailman/listinfo/python-list
ISO authoritative Python ref
I have to learn Python in a hurry. I learn fastest by reading the specs/reference manual, or something like it (e.g. "C: A Reference Manual", by Harbison and Steel). Is there a Python book that fits this description? Many thanks in advance, bill P.S. I avoid tutorials like the plague, and I loathe the typical O'Reilly "learn-through-examples" approach. I know a lot of people like this style of learning, but I find it to be a waste of time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python Suitable for Large Find & Replace Operations?
rbt wrote: > On Fri, 2005-06-17 at 09:18 -0400, Peter Hansen wrote: > >>rbt wrote: >> >>>The script is too long to post in its entirety. In short, I open the >>>files, do a binary read (in 1MB chunks for ease of memory usage) on them *ONE* MB? What are the higher-ups constraining you to run this on? My reference points: (1) An off-the-shelf office desktop PC from HP/Dell/whoever with 512MB of memory is standard fare. Motherboards with 4 memory slots (supporting up to 4GB) are common. (2) Reading files in 1MB chunks seemed appropriate when I was running an 8Mb 486 using Win 3.11. Are you able to run your script on the network server itself? And what is the server setup? Windows/Novell/Samba/??? What version of Python are you running? Have you considered mmap? >>>before placing that read into a variable and that in turn into a list >>>that I then apply the following re to In the following code, which is "variable" (chunk?) and which is the "list" to which you apply the re? The only list I see is the confusingly named "search" which is the *result* of applying re.findall. >>> >>>ss = re.compile(r'\b\d{3}-\d{2}-\d{4}\b') Users never use spaces or other punctuation (or no punctuation) instead of dashes? False positives? E.g. """ Dear X, Pls rush us qty 20 heart pacemaker alarm trigger circuits, part number 123-456-78-9012, as discussed. """ >>> >>>like this: >>> >>>for chunk in whole_file: >>>search = ss.findall(chunk) You will need the offset to update, so better get used to using something like finditer now. You may well find that "validate" may want to check some context on either side, even if it's just one character -- \b may turn out to be inappropriate. >>>if search: >>>validate(search) >> >>This seems so obvious that I hesitate to ask, but is the above really a >>simplification of the real code, which actually handles the case of SSNs >>that lie over the boundary between chunks? In other words, what happens >>if the first chunk has only the first four digits of the SSN, and the >>rest lies in the second chunk? >> >>-Peter > > > No, that's a good question. As of now, there is nothing to handle the > scenario that you bring up. I have considered this possibility (rare but > possible). I have not written a solution for it. It's a very good point > though. How rare? What is the average size of file? What is the average frequency of SSNs per file? What is the maximum file size (you did mention mostly MS Word and Excel, so can't be very big)? N.B. Using mmap just blows this problem away. Using bigger memory chunks diminishes it. And what percentage of files contain no SSNs at all? Are you updating in-situ, or must your script copy the files, changing SSNs as it goes? Do you have a choice between the two methods? Are you allowed to constrain the list of input files so that you don't update binaries (e.g.) exe files? > > Is that not why proper software is engineered? Anyone can build a go > cart (write a program), but it takes a team of engineers and much > testing to build a car, no? Which woulu you rather be riding in during a > crash? I wish upper mgt had a better understanding of this ;) > Don't we all so wish? Meanwhile, back in the real world, ... -- http://mail.python.org/mailman/listinfo/python-list
Re: ISO authoritative Python ref
bill <[EMAIL PROTECTED]> writes: > I have to learn Python in a hurry. I learn fastest by reading the > specs/reference manual, or something like it (e.g. "C: A Reference > Manual", by Harbison and Steel). > > Is there a Python book that fits this description? The official reference manual is at: http://docs.python.org/ref/ref.html Like most of the other Python docs, it has serious gaps. -- http://mail.python.org/mailman/listinfo/python-list