Re: I need a starter ptr writing python embedded in html.

2010-08-07 Thread Eknath Venkataramani
BeautifulSoup On Sun, Aug 8, 2010 at 8:12 AM, Steven W. Orr wrote: > I'm ok in python but I haven't done too much with web pages. I have a web > page > that is hand written in html that has about 1000 entries in a table and I > want > to convert the table from entries like this > > > S

Re: Nice way to cast a homogeneous tuple

2010-08-07 Thread Carl Banks
On Aug 7, 8:18 pm, Dennis Lee Bieber wrote: > On Sat, 7 Aug 2010 13:02:56 -0700 (PDT), Carl Banks > declaimed the following in > gmane.comp.python.general: > > > > > Not really.  Very few people call int(), float(), and company "type > > casts".  They aren't type casts at all, they are constructo

Re: I need a starter ptr writing python embedded in html.

2010-08-07 Thread Miki
On Aug 7, 7:42 pm, "Steven W. Orr" wrote: > I'm ok in python but I haven't done too much with web pages. I have a web page > that is hand written in html that has about 1000 entries in a table and I want > to convert the table from entries like this > >     >       Some Date String >       Som

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
On 8 Αύγ, 05:56, John S wrote: >"How can I use RE string replacement to find PHP tags and convert them >to Django template tags?" No, not at all John, at least not yet! I have only 1 week that i'm learnign python(changing from php & perl) so i'm very fresh at this beautifull and straighforwrd la

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
On 8 Αύγ, 05:42, John S wrote: > If the 500 web pages are PHP only in the sense that there is only one > pair of tags in each file, surrounding the entire content, then > what you ask for is doable. First of all, thank you very much John for your BIG effort to help me(i'm still readign your post

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread John S
Even though I just replied above, in reading over the OP's message, I think the OP might be asking: "How can I use RE string replacement to find PHP tags and convert them to Django template tags?" Instead of saying source_contents = source_contents.replace(...) say this instead: import re de

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread rantingrick
On Aug 7, 8:42 pm, MRAB wrote: > That should be: > >    data = data.replace('    data = data.replace('?>', '') Yes, Thanks MRAB. I did forget that important detail. > Strings don't have an 'insert' method! *facepalm*! I really must stop Usenet-ing whilst consuming large volumes of alcoholic be

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread John S
On Aug 7, 8:20 pm, Νίκος wrote: > Hello dear Pythoneers, > > I have over 500 .php web pages in various subfolders under 'data' > folder that i have to rename to .html and and ditch the '' > tages from within and also insert a very first line of > where id must be an identification unique number o

I need a starter ptr writing python embedded in html.

2010-08-07 Thread Steven W. Orr
I'm ok in python but I haven't done too much with web pages. I have a web page that is hand written in html that has about 1000 entries in a table and I want to convert the table from entries like this Some Date String SomeTag A Title htt

Re: Python "why" questions

2010-08-07 Thread Roy Smith
In article <7f3c505c-4002-427e-a969-6d735307e...@z10g2000yqb.googlegroups.com>, CM wrote: > > Apparently, the Japanese used to (before they started adopting western > > conventions). I.e. ages were given as "in his tenth year" (meaning nine > > years old). With apologies to Paul Simon... One

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
# rename ALL php files to html in every subfolder of the folder 'data' os.rename('*.php', '*.html') # how to tell python to rename ALL php files to html to ALL subfolder under 'data' ? # current path of the file to be processed path = './data' # this must be somehow in a

Re: Python "why" questions

2010-08-07 Thread Ian Kelly
On Sat, Aug 7, 2010 at 1:14 PM, John Nagle wrote: >   FORTRAN, MATLAB, and Octave all use 1-based subscripts. > >   The languages which have real multidimensional arrays, rather > than arrays of arrays, tend to use 1-based subscripts.  That > reflects standard practice in mathematics. I propose t

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread MRAB
rantingrick wrote: On Aug 7, 7:20 pm, Νίκος wrote: Hello dear Pythoneers, I prefer Pythonista, but anywho.. I have over 500 .php web pages in various subfolders under 'data' folder that i have to rename to .html import os os.rename(old, new) and and ditch the '' tages from within path

Re: Python "why" questions

2010-08-07 Thread CM
> Apparently, the Japanese used to (before they started adopting western > conventions). I.e. ages were given as "in his tenth year" (meaning nine > years old). Koreans still do this. The day a child is born it is "one". Even odder to me, the next birthday is not on the next anniversary of the

Re: Python Portability

2010-08-07 Thread W. eWatson
On 8/7/2010 4:45 PM, Martin v. Loewis wrote: To add to the msg I just sent to M. Torrie. We are given the msi programs for Python, PIL,matplotlib, and numpy. The question of how to uninstall and re-install a different version remains. I'd claim that this is not the real question. The real quest

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread rantingrick
On Aug 7, 7:20 pm, Νίκος wrote: > Hello dear Pythoneers, I prefer Pythonista, but anywho.. > I have over 500 .php web pages in various subfolders under 'data' > folder that i have to rename to .html import os os.rename(old, new) > and and ditch the '' tages from within path = 'some/valid/path

Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
Hello dear Pythoneers, I have over 500 .php web pages in various subfolders under 'data' folder that i have to rename to .html and and ditch the '' tages from within and also insert a very first line of where id must be an identification unique number of every page for counter tracking purposes.

Re: Sequential Object Store

2010-08-07 Thread Alex Willmer
On Aug 7, 5:26 pm, GZ wrote: > I am wondering if there is a module that can persist a stream of > objects without having to load everything into memory. (For this > reason, I think Pickle is out, too, because it needs everything to be > in memory.) >From the pickle docs it looks like you could do

Re: Python Portability

2010-08-07 Thread Martin v. Loewis
> To add to the msg I just sent to M. Torrie. We are given the msi > programs for Python, PIL,matplotlib, and numpy. The question of how to > uninstall and re-install a different version remains. I'd claim that this is not the real question. The real question is, instead: "What specific error did

Re: Python Portability--Not very portable?

2010-08-07 Thread Ben Finney
"W. eWatson" writes: > Yes, code reversal programs have been around for many, many decades. > Try one on MS Word or Adobe Acrobat. :-) Interesting examples. What “important stuff” from those programs has not been “ripped off”, to use your terms? Is there anything remaining in those programs whi

Re: cscope like source code navigation for python code

2010-08-07 Thread Tim Harig
On 2010-08-07, Gelonida wrote: > I'm using g?vim and its c-scope plugin for browsing C-code. > What would be a good way of navigating larger python projects with vim? ctags: http://ctags.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Python "why" questions

2010-08-07 Thread Ben Finney
"D'Arcy J.M. Cain" writes: > No. You are giving me math and logic but the subject was common > sense. Common sense is often unhelpful, and in such cases the best way to teach something is to plainly contradict that common sense. Common sense, for example, would have the Earth as a flat surface

Re: Python Portability

2010-08-07 Thread W. eWatson
On 8/7/2010 2:26 PM, Martin v. Loewis wrote: Am 07.08.2010 23:01, schrieb Michael Torrie: On 08/07/2010 01:17 PM, W. eWatson wrote: Presumably I have him somehow delete the numpy site-package, the numpy 1.2.0 package? Just drill his way dow from the .../lib/site_packages? Then install 1.2.0. He

Re: Python "why" questions

2010-08-07 Thread Ben Finney
Steven D'Aprano writes: > It didn't take me long to get used to thinking in zero-based indexes, > but years later, I still find it hard to *talk* in zero-based indexes. > It's bad enough saying that the first element in a list in the zeroth > element, but that the second element is the first make

Re: Python Portability

2010-08-07 Thread W. eWatson
On 8/7/2010 2:01 PM, Michael Torrie wrote: On 08/07/2010 01:17 PM, W. eWatson wrote: Presumably I have him somehow delete the numpy site-package, the numpy 1.2.0 package? Just drill his way dow from the .../lib/site_packages? Then install 1.2.0. He's missed the boat on that before by not followi

Re: Python "why" questions

2010-08-07 Thread geremy condra
On Sat, Aug 7, 2010 at 4:06 PM, Hexamorph wrote: > rantingrick wrote: > >> Well not if you are referring to how people "say" things. But what >> people "say" and the facts of reality are some times two different >> things. Heck we even have a few folks in this group who overuse the >> expression "

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Ben Finney
Peter Pearson writes: > Hey, that's a cute example, but . . . what a trap! Is it possible to > document the use-the-object-not-the-string requirement loudly enough > that people won't get caught? Don't use strings for such values. The data isn't going to be used, so there's no sense using a sema

Re: Python "why" questions

2010-08-07 Thread Hexamorph
rantingrick wrote: Well not if you are referring to how people "say" things. But what people "say" and the facts of reality are some times two different things. Heck we even have a few folks in this group who overuse the expression "used to" quite frequently in place of the more correct term "pr

Re: Python "why" questions

2010-08-07 Thread MRAB
rantingrick wrote: On Aug 7, 9:10 am, Steven D'Aprano wrote: On Sat, 07 Aug 2010 08:54:28 -0400, D'Arcy J.M. Cain wrote: On Sat, 07 Aug 2010 13:48:32 +0200 News123 wrote: It makes sense in assembly language and even in many byte code languages. It makes sense if you look at the internal repr

Re: Why is python not written in C++ ?

2010-08-07 Thread Paul Rubin
Albert van der Horst writes: > We had a similar discussion on comp.lang.forth. Heh, fancy meeting you here ;-) > The bottom line is that to implement a programming language > you want to use a simpler programming language, not a more > complicated one. Nah, gas is written in C, and nobody impl

Re: Python "why" questions

2010-08-07 Thread rantingrick
On Aug 7, 9:10 am, Steven D'Aprano wrote: > On Sat, 07 Aug 2010 08:54:28 -0400, D'Arcy J.M. Cain wrote: > > On Sat, 07 Aug 2010 13:48:32 +0200 > > News123 wrote: > >> It makes sense in assembly language and even in many byte code > >> languages. It makes sense if you look at the internal represen

Re: distutils question - building universal modules on OS X?

2010-08-07 Thread Aahz
In article , Louis Theran wrote: > >Is there a standard recipe for getting distutils to built universal .so >files for modules that have C/C++ source? You should check the archives of http://mail.python.org/mailman/listinfo/pythonmac-sig -- Aahz (a...@pythoncraft.com) <*> http

Re: Problem with Elementtree and XMLSchem instance type

2010-08-07 Thread Stefan Behnel
Roland Hedberg, 30.07.2010 15:21: I have the following XML snippet: http://www.w3.org/2001/XMLSchema-instance"; xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706"; xsi:type="fed:SecurityTokenServiceType"> This part after parsing with Elementtree gives me an Elem

Re: Python Portability

2010-08-07 Thread Martin v. Loewis
Am 07.08.2010 23:01, schrieb Michael Torrie: > On 08/07/2010 01:17 PM, W. eWatson wrote: >> Presumably I have him somehow delete the numpy site-package, the numpy >> 1.2.0 package? Just drill his way dow from the .../lib/site_packages? >> Then install 1.2.0. He's missed the boat on that before by

Re: Python Portability

2010-08-07 Thread Michael Torrie
On 08/07/2010 01:17 PM, W. eWatson wrote: > Presumably I have him somehow delete the numpy site-package, the numpy > 1.2.0 package? Just drill his way dow from the .../lib/site_packages? > Then install 1.2.0. He's missed the boat on that before by not following > instructions. Wait. I'm confus

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 22:52, Thomas Jollans wrote: > On 08/07/2010 09:36 PM, Νίκος wrote: > > > cookie.has_key('visitor') != 'nikos' > > This is always True. has_key returns a bool, which is never equal to any > string, even 'nikos'. if cookie.has_key('visitor') or re.search('cyta', host) is None: adresses

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Thomas Jollans wrote: On 08/07/2010 09:36 PM, Νίκος wrote: cookie.has_key('visitor') != 'nikos' This is always True. has_key returns a bool, which is never equal to any string, even 'nikos'. I missed that bit! :-) Anyway, the OP said "the 'stuff' never gets executed". Kinda puzzling... -- h

Re: Nice way to cast a homogeneous tuple

2010-08-07 Thread Carl Banks
On Aug 7, 6:54 am, Albert van der Horst wrote: > In article <1pm7i7-473@satorlaser.homedns.org>, > Ulrich Eckhardt   wrote: > > > > >Steven D'Aprano wrote: > >> Perhaps I have been misinformed, but my understanding of C type-casts is > >> that (where possible), a cast like `int(var)` merely te

Re: Python Portability--Not very portable?

2010-08-07 Thread Martin v. Loewis
> As an example, my inexperienced Python partner 30 miles away has gotten > out of step somehow. I think by installing a different version of numpy > than I use. I gave him a program we both use months ago, and he had no > trouble. (We both use IDLE on 2.5). I made a one character change to it > an

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Thomas Jollans
On 08/07/2010 09:36 PM, Νίκος wrote: > cookie.has_key('visitor') != 'nikos' This is always True. has_key returns a bool, which is never equal to any string, even 'nikos'. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 22:17, MRAB wrote: > Νίκος wrote: > > On 7 Αύγ, 21:24, MRAB wrote: > > >> Use group capture: > > >>      found = re.match(r'', firstline).group(1) > >>      print(page_id) > > > Worked like a charm! Thanks a lot! > > > So match method here not only searched for the string representation

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 22:07, MRAB wrote: > re.search('cyta', host) will return None if there's no match, but you > said "Yes it does contain it", so there _is_ a match, therefore: > >      hostmatch is None > > is False. The code block inside the if structure must be executes ONLY if the 'visitor' cookie is

Re: Python Portability

2010-08-07 Thread W. eWatson
On 8/6/2010 2:23 AM, Lawrence D'Oliveiro wrote: In message, W. eWatson wrote: I made a one character change to it and sent him the new py file. He can't execute it. What exactly was the problem? I put a minus sign in front of a variable. I had him use the shell to check his version numpy, w

Re: Python "why" questions

2010-08-07 Thread John Nagle
On 8/7/2010 5:00 AM, Thomas Jollans wrote: On 08/07/2010 05:05 AM, Default User wrote: > From "the emperor's new clothes" department: 1) Why do Python lists start with element [0], instead of element [1]? "Common sense" would seem to suggest that lists should start with [1]. As others have p

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Νίκος wrote: On 7 Αύγ, 21:24, MRAB wrote: Use group capture: found = re.match(r'', firstline).group(1) print(page_id) Worked like a charm! Thanks a lot! So match method here not only searched for the string representation of the number but also convert it to integer as well? r s

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Νίκος wrote: On 7 Αύγ, 21:27, MRAB wrote: Νίκος wrote: i also dont know what wrong with this line: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] hostmatch = re.search('cyta', host) if cookie.has_key('visitor') != 'nikos' or hostmatch is None: # do stuff the 'stuff' never get

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Thomas Jollans
On 08/07/2010 08:51 PM, Νίκος wrote: > On 7 Αύγ, 21:24, MRAB wrote: > >> Use group capture: >> >> found = re.match(r'', firstline).group(1) >> print(page_id) > > Worked like a charm! Thanks a lot! > > So match method here not only searched for the string representation > of the number

Re: Need Translation library

2010-08-07 Thread Chris Rebert
On Sat, Aug 7, 2010 at 5:04 AM, siva moorthy wrote: > hi all, > i wish to code for translation in python > > i want to parse a python program itself and make some keyword changes > (replacement) > tell me any library to parse python source code Depending on you needs, one of: http://docs.python.o

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 21:24, MRAB wrote: > Use group capture: > >      found = re.match(r'', firstline).group(1) >      print(page_id) Worked like a charm! Thanks a lot! So match method here not only searched for the string representation of the number but also convert it to integer as well? r stand for r

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
On 7 Αύγ, 21:27, MRAB wrote: > Νίκος wrote: > > i also dont know what wrong with this line: > > > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > > > hostmatch = re.search('cyta', host) > > > if cookie.has_key('visitor') != 'nikos' or hostmatch is None: > >      # do stuff > > > the

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Νίκος wrote: i also dont know what wrong with this line: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] hostmatch = re.search('cyta', host) if cookie.has_key('visitor') != 'nikos' or hostmatch is None: # do stuff the 'stuff' never gets executed, while i ant them to be as lon

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread MRAB
Νίκος wrote: Hello guys! Need your precious help again! In every html file i have in the very first line a page_id fro counetr countign purpsoes like in a format of a comment like this: and so on. every html file has its one page_id How can i grab that string representaion of a number from

Re: How to match patterns like XX YY XX YY? (regex)

2010-08-07 Thread MRAB
Peng Yu wrote: Hi, Suppose that I have strings like the following test(a b)a b test(xy uv)xy uv ... I want to change them to test(a)a test(b)b test(xy)xy test(uv)uv ... The problem is that I don't know how to capture pattern that repeat itself (like 'a' and 'xy' in the example). I could use

Re: iterators and continuing after a StopIteration

2010-08-07 Thread MRAB
Roald de Vries wrote: Hi all, I have a list that I'm iterating over, and during the iteration items are appended. Moreover, it is iterated over in two nested loops. If the inner loop comes to the end, I want the outer loop to append an item. Is there a way to do this? Because once an iterato

cscope like source code navigation for python code

2010-08-07 Thread Gelonida
Hi, I'm using g?vim and its c-scope plugin for browsing C-code. What would be a good way of navigating larger python projects with vim? thanks for any suggestions -- http://mail.python.org/mailman/listinfo/python-list

Re: Smith-Waterman Algorithm in Python

2010-08-07 Thread Daniel Fetchinson
>>> Does any one about any implementation of classical Smith Waterman >>> local alignment algorithm and it's variants for aligning natural >>> language text? >>> >> >> Please see http://tinyurl.com/2wy43fh >> >> > Every one of the first 20 entries is either the OP questions or your reply. And you

Re: How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
i also dont know what wrong with this line: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] hostmatch = re.search('cyta', host) if cookie.has_key('visitor') != 'nikos' or hostmatch is None: # do stuff the 'stuff' never gets executed, while i ant them to be as long as i dont hav

How to grab a number from inside a .html file using regex

2010-08-07 Thread Νίκος
Hello guys! Need your precious help again! In every html file i have in the very first line a page_id fro counetr countign purpsoes like in a format of a comment like this: and so on. every html file has its one page_id How can i grab that string representaion of a number from inside the .ht

Re: Struggling to convert a mysql datetime object to a python string of a different format

2010-08-07 Thread Tim Chase
On 08/07/10 01:45, Νικόλαος Κούρας wrote: # variant B for row in dataset: host, hits, dt = row # rest of your code here So, row is a tuple comprising of 3 fields, and host, hist, dt are variables assigned each one of row's tuple values by breaking it to it's elements. But what

Re: measuring a function time

2010-08-07 Thread Albert van der Horst
In article <4c5178ae$0$11091$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: >On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: > >> This should be enough >> >import time >tic = time.time() >function() >toc = time.time() >print toc - tic > >You're typing that in the i

Sequential Object Store

2010-08-07 Thread GZ
Hi All, I need to store a large number of large objects to file and then access them sequentially. I am talking about a few thousands of objects and each with size of a few hundred kilobytes, and total file size a few gigabytes. I tried shelve, but it is not good at sequentially accessing the dat

Re: How to match patterns like XX YY XX YY? (regex)

2010-08-07 Thread Alex Willmer
On Aug 7, 4:48 pm, Peng Yu wrote: > The problem is that I don't know how to capture pattern that repeat > itself (like 'a' and 'xy' in the example). I could use 'test\((\w+) > (\w+)\)(\w) (\w)', but it will capture something like 'test(a b)x y', > which I don't want to. > > I'm wondering if there

Re: [Tutor] Finding the version # of a module, and py module problem

2010-08-07 Thread W. eWatson
On 8/6/2010 7:18 PM, Philip Semanchuk wrote: On Aug 6, 2010, at 3:14 PM, W. eWatson wrote: I must be missing something. I tried this. (Windows, IDLE, Python 2.5) Yes, as Benjamin Kaplan pointed out and as I said in the email where I posted this code snippet, "dependencies is a list of custom

How to match patterns like XX YY XX YY? (regex)

2010-08-07 Thread Peng Yu
Hi, Suppose that I have strings like the following test(a b)a b test(xy uv)xy uv ... I want to change them to test(a)a test(b)b test(xy)xy test(uv)uv ... The problem is that I don't know how to capture pattern that repeat itself (like 'a' and 'xy' in the example). I could use 'test\((\w+) (\w

Re: Python "why" questions

2010-08-07 Thread Roald de Vries
On Aug 7, 2010, at 5:24 PM, Nobody wrote: On Sat, 07 Aug 2010 13:48:32 +0200, News123 wrote: "Common sense" is wrong. There are many compelling advantages to numbering from zero instead of one: http://lambda-the-ultimate.org/node/1950 It makes sense in assembly language and even in many by

Re: Python "why" questions

2010-08-07 Thread Nobody
On Sat, 07 Aug 2010 13:48:32 +0200, News123 wrote: >> "Common sense" is wrong. There are many compelling advantages to >> numbering from zero instead of one: >> >> http://lambda-the-ultimate.org/node/1950 > > It makes sense in assembly language and even in many byte code languages. > It makes

Re: Python "why" questions

2010-08-07 Thread Nobody
On Sat, 07 Aug 2010 09:53:48 -0400, D'Arcy J.M. Cain wrote: >> A new born baby is in his/her first year. It's year 1 of his/her life. >> For this reason, also "the year 0" doesn't exist. From the fact that a >> baby can be half a year old, you derive that arrays should have floats >> as indi

Re: Is there any way to minimize str()/unicode() objects memory usage [Python 2.6.4] ?

2010-08-07 Thread Nobody
On Fri, 06 Aug 2010 18:39:27 -0700, dmtr wrote: > Steven, thank you for answering. See my comments inline. Perhaps I > should have formulated my question a bit differently: Are there any > *compact* high performance containers for unicode()/str() objects in > Python? By *compact* I don't mean comp

Re: Unicode error

2010-08-07 Thread kj
In <4c5d4ad9$0$28666$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Sat, 07 Aug 2010 19:28:56 +1200, Gregory Ewing wrote: >> Steven D'Aprano wrote: >>> "No memory? No disk space? No problem! Just a flesh wound!" What's >>> the point of that? >> >> +1 QOTW >While I'm always happy to

Re: Python "why" questions

2010-08-07 Thread Thomas Jollans
On 08/07/2010 03:38 PM, Steven D'Aprano wrote: > On Sat, 07 Aug 2010 14:00:59 +0200, Thomas Jollans wrote: > >> On 08/07/2010 05:05 AM, Default User wrote: >>> >From "the emperor's new clothes" department: >>> >>> 1) Why do Python lists start with element [0], instead of element [1]? >>> "Common

Re: Python "why" questions

2010-08-07 Thread Steven D'Aprano
On Sat, 07 Aug 2010 08:54:28 -0400, D'Arcy J.M. Cain wrote: > On Sat, 07 Aug 2010 13:48:32 +0200 > News123 wrote: >> It makes sense in assembly language and even in many byte code >> languages. It makes sense if you look at the internal representation of >> unsigned numbers (which might become an

Re: Why is python not written in C++ ?

2010-08-07 Thread Albert van der Horst
In article , Roy Smith wrote: >In article , > Lawrence D'Oliveiro wrote: > >> In message , Roy Smith wrote: >> >> > C++, for all its flaws, had one powerful feature which made it very >> > popular. It is a superset of C. >> >> Actually, it never was. > >Yes, there are a few corner cases where v

Re: Why is python not written in C++ ?

2010-08-07 Thread Albert van der Horst
In article , Roy Smith wrote: >In article <4c55fe82$0$9111$426a3...@news.free.fr>, > candide wrote: > >> Python is an object oriented langage (OOL). The Python main >> implementation is written in pure and "old" C90. Is it for historical >> reasons? >> >> C is not an OOL and C++ strongly is. I w

Re: Python "why" questions

2010-08-07 Thread Roald de Vries
On Aug 7, 2010, at 3:53 PM, D'Arcy J.M. Cain wrote: On Sat, 7 Aug 2010 15:37:23 +0200 Roald de Vries wrote: Would said beginner also be surprised that a newborn baby is zero years old or would it be more natural to call them a one year old? Zero based counting is perfectly natural. A new bor

iterators and continuing after a StopIteration

2010-08-07 Thread Roald de Vries
Hi all, I have a list that I'm iterating over, and during the iteration items are appended. Moreover, it is iterated over in two nested loops. If the inner loop comes to the end, I want the outer loop to append an item. Is there a way to do this? Because once an iterator has raised a Sto

Re: Python "why" questions

2010-08-07 Thread D'Arcy J.M. Cain
On Sat, 7 Aug 2010 15:37:23 +0200 Roald de Vries wrote: > > Would said beginner also be surprised that a newborn baby is zero > > years > > old or would it be more natural to call them a one year old? Zero > > based counting is perfectly natural. > > A new born baby is in his/her first year. I

Re: Python "why" questions

2010-08-07 Thread Steven D'Aprano
On Sat, 07 Aug 2010 14:00:59 +0200, Thomas Jollans wrote: > On 08/07/2010 05:05 AM, Default User wrote: >>>From "the emperor's new clothes" department: >> >> 1) Why do Python lists start with element [0], instead of element [1]? >> "Common sense" would seem to suggest that lists should start wit

Re: Python "why" questions

2010-08-07 Thread Roald de Vries
On Aug 7, 2010, at 2:54 PM, D'Arcy J.M. Cain wrote: On Sat, 07 Aug 2010 13:48:32 +0200 News123 wrote: It makes sense in assembly language and even in many byte code languages. It makes sense if you look at the internal representation of unsigned numbers (which might become an index) For a co

Re: Nice way to cast a homogeneous tuple

2010-08-07 Thread Albert van der Horst
In article <1pm7i7-473@satorlaser.homedns.org>, Ulrich Eckhardt wrote: >Steven D'Aprano wrote: >> Perhaps I have been misinformed, but my understanding of C type-casts is >> that (where possible), a cast like `int(var)` merely tells the compiler >> to temporarily disregard the type of var and

Re: Smith-Waterman Algorithm in Python

2010-08-07 Thread Peter Otten
Ian wrote: > On 06/08/2010 17:54, Daniel Fetchinson wrote: >>> Does any one about any implementation of classical Smith Waterman >>> local alignment algorithm and it's variants for aligning natural >>> language text? >>> >> >> Please see http://tinyurl.com/2wy43fh >> >> > Every one of th

Re: Python "why" questions

2010-08-07 Thread D'Arcy J.M. Cain
On Sat, 07 Aug 2010 13:48:32 +0200 News123 wrote: > It makes sense in assembly language and even in many byte code languages. > It makes sense if you look at the internal representation of unsigned > numbers (which might become an index) > > For a complete beginner common sense dictates different

Re: Smith-Waterman Algorithm in Python

2010-08-07 Thread Ian
On 06/08/2010 17:54, Daniel Fetchinson wrote: Does any one about any implementation of classical Smith Waterman local alignment algorithm and it's variants for aligning natural language text? Please see http://tinyurl.com/2wy43fh Every one of the first 20 entries is either the OP qu

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Thomas Jollans
On 08/07/2010 09:44 AM, Gabriel Genellina wrote: > En Sat, 07 Aug 2010 04:04:06 -0300, Stefan Schwarzer > escribió: >> On 2010-08-07 00:28, Steven D'Aprano wrote: > >>> Actually, yes, equality is implemented with a short-cut > that checks for >>> identity first. That makes something like: >>> [..

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Steven D'Aprano
On Sat, 07 Aug 2010 14:28:19 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote: >> >> > P.S. Sorry for the top-post -- is there a way to not do top posts >> > from gmail? I haven't used usenet since tin. >> >> Er, surely you can

Need Translation library

2010-08-07 Thread siva moorthy
hi all, i wish to code for translation in python i want to parse a python program itself and make some keyword changes (replacement) tell me any library to parse python source code and another library to change some words phonetically to other language thanks in advance Siva -- http://mail.py

Re: Python "why" questions

2010-08-07 Thread Thomas Jollans
On 08/07/2010 05:05 AM, Default User wrote: >>From "the emperor's new clothes" department: > > 1) Why do Python lists start with element [0], instead of element [1]? > "Common sense" would seem to suggest that lists should start with [1]. As others have pointed out, there is a nice argument to

Re: python interview quuestions

2010-08-07 Thread Peter Otten
Tim Chase wrote: > On 08/06/10 15:37, James Mills wrote: >> On Sat, Aug 7, 2010 at 6:28 AM, geremy condra wrote: >>> If I had to wait 5 minutes while a candidate tried to solve this >>> problem I would not hire them. >> >> Yes you do raise a valid point. It should really only take >> you a mere f

Re: Python "why" questions

2010-08-07 Thread News123
On 08/07/2010 05:36 AM, Ryan Kelly wrote: > On Fri, 2010-08-06 at 22:05 -0500, Default User wrote: >> >From "the emperor's new clothes" department: >> >> 1) Why do Python lists start with element [0], instead of element >> [1]? "Common sense" would seem to suggest that lists should start >> with

Re: os.unlink on Windows

2010-08-07 Thread Thomas Jollans
On 08/07/2010 01:10 PM, Shambhu Sharma wrote: > Hi, > > I am new to Python. I was trying to use os.unlink function in > windows. But i am getting error: > OSError: [Errno 2] No such file or directory: > 'C:\\SHAMBHU\\tmp\\text_delete.txt' > > Input file to os.unlink is: 'C:\SHAMBHU\tmp\te

Re: sched() function questions

2010-08-07 Thread Chris Hare
On Aug 7, 2010, at 1:30 AM, Dennis Lee Bieber wrote: > On Fri, 06 Aug 2010 22:37:26 -0500, Chris Hare > declaimed the following in gmane.comp.python.general: > > >>print str(s.queue()) >> > I don't find a queue method defined for scheduler objects in the > documentation for my vers

os.unlink on Windows

2010-08-07 Thread Shambhu Sharma
Hi, I am new to Python. I was trying to use os.unlink function in windows. But i am getting error: OSError: [Errno 2] No such file or directory: 'C:\\SHAMBHU\\tmp\\text_delete.txt' Input file to os.unlink is: 'C:\SHAMBHU\tmp\text_delete.txt'. But os.unlink is adding extra backslash with p

Re: ctypes: pointer to method

2010-08-07 Thread Martin Landa
Hi, On Aug 5, 9:32 pm, Nobody wrote: >         errtype = CFUNCTYPE(c_int, POINTER(c_char), POINTER(c_int)) >         errfunc = errtype(print_error) >         G_set_error_routine(errfunc) the problem occurs when restype is not None, but c_int. E.g. if hasattr(_libs['grass_gis'], 'G_set_error_rou

Re: default behavior

2010-08-07 Thread Stefan Schwarzer
On 2010-07-31 05:47, Steven D'Aprano wrote: > On Fri, 30 Jul 2010 08:34:52 -0400, wheres pythonmonks wrote: > It does re-use the same underlying data. > > >>> from collections import defaultdict as dd > >>> x = dd(list) > >>> x[1].append(1) > >>> x > defaultdict(, {1: [1]}) > >>> y = dict(x) > >>>

Re: Python library for Sequence Matching/Comparison

2010-08-07 Thread Eli Bendersky
On Sat, Aug 7, 2010 at 12:32, Sohail wrote: > Hi, > > Is there any sequence matching library in (apart from difflib) to > compare sequences of natural text? > > thanks > -- > http://mail.python.org/mailman/listinfo/python-list > Are you aware of NLTK? It has a lot of sub-libraries for almost any

Re: A useful, but painful, one-liner to edit money amounts

2010-08-07 Thread Chris Withers
DarkBlue wrote: On Aug 5, 7:06 pm, Chris Withers wrote: Peter Otten wrote: locale.setlocale(locale.LC_ALL, ("en_US", "UTF-8")) 'en_US.UTF8' print locale.currency(13535, grouping=True) $13,535.00 Okay, so if I'm writing a wsgi app, and I want to format depending on the choices of the curren

Re: Python "why" questions

2010-08-07 Thread Roald de Vries
On Aug 7, 2010, at 5:46 AM, Vito 'ZeD' De Tullio wrote: Default User wrote: From "the emperor's new clothes" department: 1) Why do Python lists start with element [0], instead of element [1]? "Common sense" would seem to suggest that lists should start with [1]. http://userweb.cs.utexa

Re: A useful, but painful, one-liner to edit money amounts

2010-08-07 Thread Rebel Lion
On Aug 5, 12:33 pm, John Nagle wrote: > There's got to be a better way to do this: > > def editmoney(n) : >      return((",".join(reduce(lambda lst, item : (lst + [item]) if >          item else lst, >          re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1]) > >  >>> editmoney(0) > '0' >  >>> edit

Python library for Sequence Matching/Comparison

2010-08-07 Thread Sohail
Hi, Is there any sequence matching library in (apart from difflib) to compare sequences of natural text? thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help from someone that have PIL installed

2010-08-07 Thread alejandro
> > Is the file, which you claim is UTF-8 encoded, actually UTF-8 encoded? > If you're not sure, explicitly tell your text editor to save the file as > UTF-8, and then try again. I feel like an idiot... haven't used Python for some time... my editor was set for utf-8 on PHP projects and other...

Re: Is there any way to minimize str()/unicode() objects memory usage [Python 2.6.4] ?

2010-08-07 Thread dmtr
I guess with the actual dataset I'll be able to improve the memory usage a bit, with BioPython::trie. That would probably be enough optimization to continue working with some comfort. On this test code BioPython::trie gives a bit of improvement in terms of memory. Not much though... >>> d = dict()

  1   2   >